|
316 | 316 | (some delegation-info))))
|
317 | 317 |
|
318 | 318 | ;; Get the size of the reward set for a reward cycle.
|
319 |
| -;; Note that this does _not_ return duplicate PoX addresses. |
320 | 319 | ;; Note that this also _will_ return PoX addresses that are beneath
|
321 | 320 | ;; the minimum threshold -- i.e. the threshold can increase after insertion.
|
322 | 321 | ;; Used internally by the Stacks node, which filters out the entries
|
|
665 | 664 | (err ERR_STACKING_INVALID_POX_ADDRESS))
|
666 | 665 | true)
|
667 | 666 |
|
| 667 | + (match pox-addr |
| 668 | + pox-tuple |
| 669 | + (asserts! (check-pox-addr-hashbytes (get version pox-tuple) (get hashbytes pox-tuple)) |
| 670 | + (err ERR_STACKING_INVALID_POX_ADDRESS)) |
| 671 | + true) |
| 672 | + |
668 | 673 | ;; tx-sender must not be delegating
|
669 | 674 | (asserts! (is-none (get-check-delegation tx-sender))
|
670 | 675 | (err ERR_STACKING_ALREADY_DELEGATED))
|
|
873 | 878 | ;;
|
874 | 879 | (define-public (stack-aggregation-increase (pox-addr { version: (buff 1), hashbytes: (buff 32) })
|
875 | 880 | (reward-cycle uint)
|
876 |
| - (reward-cycle-index uint)) |
| 881 | + (reward-cycle-index uint) |
| 882 | + (signer-sig (optional (buff 65))) |
| 883 | + (signer-key (buff 33)) |
| 884 | + (max-amount uint) |
| 885 | + (auth-id uint)) |
877 | 886 | (let ((partial-stacked
|
878 | 887 | ;; fetch the partial commitments
|
879 | 888 | (unwrap! (map-get? partial-stacked-by-cycle { pox-addr: pox-addr, sender: tx-sender, reward-cycle: reward-cycle })
|
|
887 | 896 | (asserts! (> reward-cycle (current-pox-reward-cycle))
|
888 | 897 | (err ERR_STACKING_INVALID_LOCK_PERIOD))
|
889 | 898 |
|
890 |
| - (let ((amount-ustx (get stacked-amount partial-stacked)) |
| 899 | + (let ((partial-amount-ustx (get stacked-amount partial-stacked)) |
891 | 900 | ;; reward-cycle must point to an existing record in reward-cycle-total-stacked
|
892 | 901 | ;; infallible; getting something from partial-stacked-by-cycle succeeded so this must succeed
|
893 |
| - (existing-total (unwrap-panic (map-get? reward-cycle-total-stacked { reward-cycle: reward-cycle }))) |
| 902 | + (existing-cycle (unwrap-panic (map-get? reward-cycle-total-stacked { reward-cycle: reward-cycle }))) |
894 | 903 | ;; reward-cycle and reward-cycle-index must point to an existing record in reward-cycle-pox-address-list
|
895 | 904 | (existing-entry (unwrap! (map-get? reward-cycle-pox-address-list { reward-cycle: reward-cycle, index: reward-cycle-index })
|
896 | 905 | (err ERR_DELEGATION_NO_REWARD_SLOT)))
|
897 |
| - (increased-ustx (+ (get total-ustx existing-entry) amount-ustx)) |
898 |
| - (total-ustx (+ (get total-ustx existing-total) amount-ustx))) |
| 906 | + (increased-entry-total (+ (get total-ustx existing-entry) partial-amount-ustx)) |
| 907 | + (increased-cycle-total (+ (get total-ustx existing-cycle) partial-amount-ustx)) |
| 908 | + (existing-signer-key (get signer existing-entry))) |
899 | 909 |
|
900 | 910 | ;; must be stackable
|
901 |
| - (try! (minimal-can-stack-stx pox-addr total-ustx reward-cycle u1)) |
| 911 | + (try! (minimal-can-stack-stx pox-addr increased-entry-total reward-cycle u1)) |
902 | 912 |
|
903 | 913 | ;; new total must exceed the stacking minimum
|
904 |
| - (asserts! (<= (get-stacking-minimum) total-ustx) |
| 914 | + (asserts! (<= (get-stacking-minimum) increased-entry-total) |
905 | 915 | (err ERR_STACKING_THRESHOLD_NOT_MET))
|
906 | 916 |
|
907 | 917 | ;; there must *not* be a stacker entry (since this is a delegator)
|
|
912 | 922 | (asserts! (is-eq pox-addr (get pox-addr existing-entry))
|
913 | 923 | (err ERR_DELEGATION_WRONG_REWARD_SLOT))
|
914 | 924 |
|
| 925 | + ;; Validate that amount is less than or equal to `max-amount` |
| 926 | + (asserts! (>= max-amount increased-entry-total) (err ERR_SIGNER_AUTH_AMOUNT_TOO_HIGH)) |
| 927 | + |
| 928 | + ;; Validate that signer-key matches the existing signer-key |
| 929 | + (asserts! (is-eq existing-signer-key signer-key) (err ERR_INVALID_SIGNER_KEY)) |
| 930 | + |
| 931 | + ;; Verify signature from delegate that allows this sender for this cycle |
| 932 | + ;; 'lock-period' param set to one period, same as aggregation-commit-indexed |
| 933 | + (try! (consume-signer-key-authorization pox-addr reward-cycle "agg-increase" u1 signer-sig signer-key increased-entry-total max-amount auth-id)) |
| 934 | + |
915 | 935 | ;; update the pox-address list -- bump the total-ustx
|
916 | 936 | (map-set reward-cycle-pox-address-list
|
917 | 937 | { reward-cycle: reward-cycle, index: reward-cycle-index }
|
918 | 938 | { pox-addr: pox-addr,
|
919 |
| - total-ustx: increased-ustx, |
| 939 | + total-ustx: increased-entry-total, |
920 | 940 | stacker: none,
|
921 |
| - ;; TODO: this must be authorized with a signature, or tx-sender allowance! |
922 |
| - signer: (get signer existing-entry) }) |
| 941 | + signer: signer-key }) |
923 | 942 |
|
924 | 943 | ;; update the total ustx in this cycle
|
925 | 944 | (map-set reward-cycle-total-stacked
|
926 | 945 | { reward-cycle: reward-cycle }
|
927 |
| - { total-ustx: total-ustx }) |
| 946 | + { total-ustx: increased-cycle-total }) |
928 | 947 |
|
929 | 948 | ;; don't update the stacking-state map,
|
930 | 949 | ;; because it _already has_ this stacker's state
|
|
1161 | 1180 | ;; Verify signature from delegate that allows this sender for this cycle
|
1162 | 1181 | (try! (consume-signer-key-authorization pox-addr cur-cycle "stack-extend" extend-count signer-sig signer-key u0 max-amount auth-id))
|
1163 | 1182 |
|
1164 |
| - ;; TODO: add more assertions to sanity check the `stacker-info` values with |
1165 |
| - ;; the `stacker-state` values |
1166 |
| - |
1167 | 1183 | (let ((last-extend-cycle (- (+ first-extend-cycle extend-count) u1))
|
1168 | 1184 | (lock-period (+ u1 (- last-extend-cycle first-reward-cycle)))
|
1169 | 1185 | (new-unlock-ht (reward-cycle-to-burn-height (+ u1 last-extend-cycle))))
|
|
1421 | 1437 | (max-amount uint)
|
1422 | 1438 | (auth-id uint))
|
1423 | 1439 | (begin
|
| 1440 | + ;; must be called directly by the tx-sender or by an allowed contract-caller |
| 1441 | + (asserts! (check-caller-allowed) |
| 1442 | + (err ERR_NOT_ALLOWED)) |
1424 | 1443 | ;; Validate that `tx-sender` has the same pubkey hash as `signer-key`
|
1425 | 1444 | (asserts! (is-eq
|
1426 | 1445 | (unwrap! (principal-construct? (if is-in-mainnet STACKS_ADDR_VERSION_MAINNET STACKS_ADDR_VERSION_TESTNET) (hash160 signer-key)) (err ERR_INVALID_SIGNER_KEY))
|
|
0 commit comments