Skip to content

Commit

Permalink
withdrawals: builtin fee return
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Oct 29, 2024
1 parent 5bad701 commit f6e1eaa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/common/sdpay.eas
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;;; payment via selfdestruct

calldataload
selfdestruct
31 changes: 28 additions & 3 deletions src/withdrawals/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,31 @@
push MIN_FEE ;; [min_fee, excess, update_fraction]
#include "../common/fake_expo.eas"

;; Determine if the fee provided is enough to cover the withdrawal request fee.
callvalue ;; [callvalue, req_fee]
;; Revert if too little fee is given.
dup1 ;; [req_fee, req_fee]
callvalue ;; [callvalue, req_fee, req_fee]
lt ;; [callvalue < req_fee]
jumpi @revert ;; [req_fee]

;; If the fee is correct, insert.
dup1 ;; [req_fee, req_fee]
callvalue ;; [callvalue, req_fee, req_fee]
eq ;; [callvalue==req_fee, req_fee]
jumpi @insert_request ;; [req_fee]

;; Otherwise return the extra amount back to the caller before continuing.
callvalue ;; [callvalue, req_fee]
sub ;; [extra_fee]
push @.sdpay_start ;; [offset, extra_fee]
push sdpay_size ;; [size, offset, extra_fee]
swap2 ;; [extra_fee, offset, size]
create ;; [addr]
iszero ;; [ok]
jumpi @revert ;; []

insert_request:
;; The request can pay, increment withdrawal request count.
push SLOT_COUNT
push SLOT_COUNT ;; [slot]
sload ;; [req_count]
push 1 ;; [1, req_count]
add ;; [req_count+1]
Expand Down Expand Up @@ -435,10 +453,17 @@ revert:
push 0
revert

.sdpay_start:
#assemble "../common/sdpay.eas"
.sdpay_end:

;; ----------------------------------------------------------------------------
;; MACROS ---------------------------------------------------------------------
;; ----------------------------------------------------------------------------

;; Size of the sdpay contract code.
#define sdpay_size @.sdpay_end - @.sdpay_start

;; This defines a mask for accessing the top 16 bytes of a number.
#define pk2_mask 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000

Expand Down

0 comments on commit f6e1eaa

Please sign in to comment.