├── .gitignore ├── Clarinet.toml ├── audits ├── ClarityAlliance-2024-11.pdf ├── ClarityAlliance-2025-01.pdf ├── ClarityAlliance-2025-06.pdf └── CoinFabrik-2023-11.pdf ├── contracts ├── block-info-helper-v2.clar ├── block-info-nakamoto-ststx-ratio.clar ├── block-info-nakamoto-ststx-supply.clar ├── block-info-nakamoto-v1.clar ├── block-info-nakamoto-zest.clar ├── block-info-v10.clar ├── block-info-v11.clar ├── block-info-v17.clar ├── block-info-v20.clar ├── block-info-v5.clar ├── block-info-v6.clar ├── block-info-v8.clar ├── block-info-v9.clar ├── block-info-velar-nakamoto-v1.clar ├── core │ ├── dao.clar │ ├── ststx-token.clar │ ├── ststx-withdraw-nft-v2.clar │ ├── ststx-withdraw-nft.clar │ ├── ststxbtc-token-v2.clar │ ├── ststxbtc-token.clar │ ├── ststxbtc-tracking-data-v2.clar │ ├── ststxbtc-tracking-data.clar │ ├── ststxbtc-tracking-v2.clar │ ├── ststxbtc-tracking.clar │ └── ststxbtc-withdraw-nft.clar ├── genesis-nft │ ├── stacking-dao-cc-nft-minter.clar │ ├── stacking-dao-cc-nft.clar │ ├── stacking-dao-genesis-nft-minter-v2.clar │ ├── stacking-dao-genesis-nft-minter.clar │ └── stacking-dao-genesis-nft.clar ├── helpers │ ├── block-info-v1.clar │ ├── cc-redemption-v1.clar │ ├── commission-trait.clar │ ├── nft-trait.clar │ ├── sip-010-trait-ft-standard.clar │ ├── ststxbtc-helper-v2.clar │ └── token-metadata-update-notify.clar ├── keeper-jobs │ ├── return-stx-job-v1.clar │ ├── rewards-job-v1.clar │ └── tax-v1.clar ├── nakamoto │ ├── fomo-eoy.clar │ ├── fomo.clar │ ├── stacking-dao-fomo-eoy-nft.clar │ └── stacking-dao-fomo-nft.clar ├── tests │ ├── ccd012-redemption-nyc.clar │ ├── fake-protocol.clar │ ├── fake-reserve.clar │ ├── fake-staking.clar │ ├── governance-v0.clar │ ├── marketplace-commission.clar │ ├── position-mock.clar │ ├── pox-3-mock.clar │ ├── pox-4-mock.clar │ ├── pox-fast-pool-v2-mock.clar │ ├── protocol-arkadiko-mock.clar │ ├── protocol-zest-mock.clar │ ├── sbtc-registry.clar │ ├── sbtc-token.clar │ ├── swap-lp-token.clar │ ├── swap.clar │ └── wstx-token.clar ├── version-1 │ ├── commission-trait-v1.clar │ ├── commission-v1.clar │ ├── reserve-trait-v1.clar │ ├── reserve-v1.clar │ ├── stacker-1.clar │ ├── stacking-dao-core-v1.clar │ ├── staking-trait-v1.clar │ ├── staking-v0.clar │ └── strategy-v0.clar ├── version-2 │ ├── commission-v2.clar │ ├── data-core-v1.clar │ ├── data-direct-stacking-v1.clar │ ├── data-pools-v1.clar │ ├── delegates-handler-v1.clar │ ├── direct-helpers-trait-v1.clar │ ├── direct-helpers-v1.clar │ ├── direct-helpers-v2.clar │ ├── native-stacking-pool-v1.clar │ ├── protocol-arkadiko-v1.clar │ ├── protocol-bitflow-v1.clar │ ├── protocol-hermetica-v1.clar │ ├── protocol-trait-v1.clar │ ├── protocol-velar-v1.clar │ ├── protocol-zest-v1.clar │ ├── rewards-trait-v1.clar │ ├── rewards-v2.clar │ ├── stacking-dao-core-v2.clar │ ├── stacking-dao-core-v3.clar │ ├── stacking-delegate-1.clar │ ├── stacking-delegate-trait-v1.clar │ ├── stacking-pool-payout-v1.clar │ ├── stacking-pool-signer-v1.clar │ ├── stacking-pool-v1.clar │ ├── strategy-v3-algo-v1.clar │ ├── strategy-v3-delegates-v1.clar │ ├── strategy-v3-pools-v1.clar │ ├── strategy-v3.clar │ └── strategy-v4.clar ├── version-3 │ ├── commission-btc-v1.clar │ ├── data-core-v2.clar │ ├── data-core-v3.clar │ ├── direct-helpers-v3.clar │ ├── direct-helpers-v4.clar │ ├── position-trait-v1.clar │ ├── position-zest-v2.clar │ ├── rewards-v3.clar │ ├── rewards-v4.clar │ ├── rewards-v5.clar │ ├── stacking-dao-core-btc-v1.clar │ ├── stacking-dao-core-btc-v2.clar │ ├── stacking-dao-core-v4.clar │ ├── stacking-dao-core-v5.clar │ ├── ststxbtc-migration-v1.clar │ ├── swap-ststx-ststxbtc-v1.clar │ └── swap-ststx-ststxbtc-v2.clar └── version-x │ ├── sdao-token.clar │ ├── staking-v1.clar │ └── strategy-v3-wip.clar ├── deployments └── default.devnet-plan.yaml ├── settings └── Devnet.toml └── tests ├── core ├── dao_test.ts ├── ststx-token_test.ts ├── ststx-withdraw-nft_test.ts ├── ststxbtc-token_test.ts ├── ststxbtc-tracking-data_test.ts ├── ststxbtc-tracking_test.ts └── ststxbtc-withdraw-nft_test.ts ├── fomo └── fomo_test.ts ├── genesis-nft └── genesis-nft-minter_test.ts ├── helpers └── cc-redemption_test.ts ├── keeper-jobs ├── return-stx-job_test.ts ├── rewards-job_test.ts └── tax_test.ts ├── tests └── pox-fast-pool-v2-mock_test.ts ├── version-1 ├── commission_test.ts ├── reserve_test.ts ├── stacker-1_test.ts ├── stacking-dao-core_test.ts └── strategy-v0_test.ts ├── version-2 ├── data-direct-stacking_test.ts ├── data-pools_test.ts ├── stacking-pool-payout_test.ts ├── stacking-pool-signer_test.ts ├── stacking-pool_test.ts └── strategy-v4_test.ts ├── version-3 ├── commission-btc_test.ts ├── data-core_test.ts ├── direct-helpers_test.ts ├── rewards_test.ts ├── stacking-dao-core-btc_test.ts ├── stacking-dao-core_test.ts ├── ststxbtc-migration_test.ts └── swap-ststx-ststxbtc_test.ts ├── version-x ├── staking_test.ts └── stdao-token_test.ts └── wrappers ├── commission-btc-helpers.ts ├── commission-helpers.ts ├── dao-helpers.ts ├── data-core-helpers.ts ├── data-direct-stacking-helpers.ts ├── data-pools-helpers.ts ├── delegates-handler-helper.ts ├── direct-helpers-helpers.ts ├── fomo-helpers.ts ├── genesis-minter-helpers.ts ├── position-mock-helpers.ts ├── pox-fast-pool-v2-helpers.ts ├── pox-mock-helpers.ts ├── reserve-helpers.ts ├── return-stx-job-helpers.ts ├── rewards-helpers.ts ├── rewards-job-helpers.ts ├── sbtc-token-helpers.ts ├── sdao-token-helpers.ts ├── stacker-helpers.ts ├── stacking-dao-core-btc-helpers.ts ├── stacking-dao-core-helpers.ts ├── stacking-delegate-helpers.ts ├── stacking-pool-helpers.ts ├── stacking-pool-payout-helpers.ts ├── stacking-pool-signer-helpers.ts ├── staking-helpers.ts ├── strategy-helpers.ts ├── ststx-token-helpers.ts ├── ststx-withdraw-nft-helpers.ts ├── ststxbtc-token-helpers.ts ├── ststxbtc-tracking-data-helpers.ts ├── ststxbtc-tracking-helpers.ts ├── ststxbtc-withdraw-nft-helpers.ts ├── swap-ststx-ststxbtc-helpers.ts ├── tax-helpers.ts └── tests-utils.ts /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | **/settings/Mainnet.toml 3 | **/settings/Testnet.toml 4 | .cache/** 5 | history.txt 6 | 7 | /coverage/ 8 | coverage.lcov 9 | 10 | .vscode 11 | -------------------------------------------------------------------------------- /audits/ClarityAlliance-2024-11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackingDAO/contracts/29dc1e58774e2971497cffb40a5f4f1db653c64b/audits/ClarityAlliance-2024-11.pdf -------------------------------------------------------------------------------- /audits/ClarityAlliance-2025-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackingDAO/contracts/29dc1e58774e2971497cffb40a5f4f1db653c64b/audits/ClarityAlliance-2025-01.pdf -------------------------------------------------------------------------------- /audits/ClarityAlliance-2025-06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackingDAO/contracts/29dc1e58774e2971497cffb40a5f4f1db653c64b/audits/ClarityAlliance-2025-06.pdf -------------------------------------------------------------------------------- /audits/CoinFabrik-2023-11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StackingDAO/contracts/29dc1e58774e2971497cffb40a5f4f1db653c64b/audits/CoinFabrik-2023-11.pdf -------------------------------------------------------------------------------- /contracts/block-info-helper-v2.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-user-zest (account principal) (block uint)) 3 | (let ( 4 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 5 | ) 6 | (if (< block u140388) 7 | (ok u0) 8 | (ok (at-block block-hash (get-user-zest-helper account))) 9 | ) 10 | ) 11 | ) 12 | 13 | (define-read-only (get-user-zest-helper (account principal)) 14 | (let ( 15 | (user-index (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.pool-reserve-data get-user-index-read account .ststx-token)) 16 | ) 17 | (if (is-some user-index) 18 | ;; (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.pool-read-supply get-supplied-balance-user-ststx account) 19 | u0 20 | u0 21 | ) 22 | ) 23 | ) 24 | -------------------------------------------------------------------------------- /contracts/block-info-nakamoto-ststx-ratio.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info Nakamoto stSTX ratio 2 | ;; @version 1 3 | 4 | ;;------------------------------------- 5 | ;; Constants 6 | ;;------------------------------------- 7 | 8 | (define-constant ERR_BLOCK_INFO u42001) 9 | (define-constant DENOMINATOR_6 u1000000) 10 | 11 | ;;------------------------------------- 12 | ;; stSTX info 13 | ;;------------------------------------- 14 | 15 | (define-read-only (get-ststx-ratio) 16 | (let ( 17 | (total-stx-amount (unwrap! (contract-call? .reserve-v1 get-total-stx) (err ERR_BLOCK_INFO))) 18 | (ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply))) 19 | ) 20 | (ok 21 | (if (is-eq ststx-supply u0) 22 | DENOMINATOR_6 23 | (/ (* total-stx-amount DENOMINATOR_6) ststx-supply) 24 | ) 25 | ) 26 | ) 27 | ) 28 | 29 | (define-read-only (get-ststx-ratio-v2) 30 | (let ( 31 | (total-stx-amount (unwrap! (contract-call? .reserve-v1 get-total-stx) (err ERR_BLOCK_INFO))) 32 | (ststxbtc-supply (unwrap-panic (contract-call? .ststxbtc-token get-total-supply))) 33 | (stx-for-ststx (- total-stx-amount ststxbtc-supply)) 34 | (ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply))) 35 | ) 36 | (ok 37 | (if (is-eq ststx-supply u0) 38 | DENOMINATOR_6 39 | (/ (* stx-for-ststx DENOMINATOR_6) ststx-supply) 40 | ) 41 | ) 42 | ) 43 | ) 44 | 45 | (define-read-only (get-ststx-ratio-at-block (block uint)) 46 | (let ( 47 | (block-hash (unwrap! (get-stacks-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 48 | ) 49 | (if (> block u489238) ;; stSTXbtc release 50 | (at-block block-hash (get-ststx-ratio-v2)) 51 | (at-block block-hash (get-ststx-ratio)) 52 | ) 53 | ) 54 | ) 55 | -------------------------------------------------------------------------------- /contracts/block-info-nakamoto-ststx-supply.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info Nakamoto stSTX supply 2 | ;; @version 1 3 | ;; 4 | ;; Contract to get info at given block 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_BLOCK_INFO u42001) 11 | 12 | ;;------------------------------------- 13 | ;; stSTX info 14 | ;;------------------------------------- 15 | 16 | (define-read-only (get-ststx-supply-at-block (block uint)) 17 | (let ( 18 | (block-hash (unwrap! (get-stacks-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 19 | ) 20 | (at-block block-hash (contract-call? .ststx-token get-total-supply)) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /contracts/block-info-nakamoto-zest.clar: -------------------------------------------------------------------------------- 1 | ;;------------------------------------- 2 | ;; Zest 3 | ;;------------------------------------- 4 | 5 | (define-read-only (get-user-zest (account principal) (block uint)) 6 | (let ( 7 | (block-hash (unwrap! (get-stacks-block-info? id-header-hash block) (err u666))) 8 | ) 9 | (if (< block u140111) 10 | (ok u0) 11 | (if (< block u143343) 12 | (at-block block-hash (get-user-zest-helper-1 account)) 13 | (if (< block u149387) 14 | (at-block block-hash (get-user-zest-helper-2 account)) 15 | (if (< block u343280) 16 | (at-block block-hash (get-user-zest-helper-3 account)) 17 | (at-block block-hash (get-user-zest-helper-4 account)) 18 | ) 19 | ) 20 | ) 21 | ) 22 | ) 23 | ) 24 | 25 | (define-read-only (get-user-zest-helper-1 (account principal)) 26 | (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx get-balance account) 27 | ) 28 | 29 | (define-read-only (get-user-zest-helper-2 (account principal)) 30 | (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx-v1-0 get-balance account) 31 | ) 32 | 33 | (define-read-only (get-user-zest-helper-3 (account principal)) 34 | (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx-v1-2 get-balance account) 35 | ) 36 | 37 | (define-read-only (get-user-zest-helper-4 (account principal)) 38 | (ok (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx-token get-balance account)) 39 | ) 40 | -------------------------------------------------------------------------------- /contracts/block-info-v10.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info 2 | ;; @version 1 3 | ;; 4 | ;; Contract to get info at given block 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_BLOCK_INFO u42001) 11 | 12 | ;;------------------------------------- 13 | ;; Stacking Info 14 | ;;------------------------------------- 15 | 16 | (define-read-only (get-reserve-stacking-at-block (block uint)) 17 | (let ( 18 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 19 | ) 20 | (at-block block-hash (contract-call? .reserve-v1 get-stx-stacking)) 21 | ) 22 | ) 23 | 24 | (define-read-only (get-stx-account-at-block (account principal) (block uint)) 25 | (let ( 26 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 27 | ) 28 | (ok (at-block block-hash (stx-account account))) 29 | ) 30 | ) 31 | 32 | ;;------------------------------------- 33 | ;; User Info - Points 34 | ;;------------------------------------- 35 | 36 | (define-read-only (get-user-wallet (account principal) (block uint)) 37 | (let ( 38 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 39 | ) 40 | (at-block block-hash (get-wallet-balance account)) 41 | ) 42 | ) 43 | 44 | (define-read-only (get-wallet-balance (account principal)) 45 | (contract-call? .ststx-token get-balance account) 46 | ) 47 | 48 | ;;------------------------------------- 49 | ;; Bitflow 50 | ;;------------------------------------- 51 | 52 | 53 | (define-read-only (get-user-bitflow (account principal) (block uint)) 54 | (let ( 55 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 56 | ) 57 | (if (< block u132631) 58 | ;; Wallet only 59 | (ok u0) 60 | 61 | (if (< block u135640) 62 | ;; Wallet + BitFlow V1 63 | (at-block block-hash (get-bitflow-lp-1 account)) 64 | 65 | ;; Wallet + BitFlow V1 + Bitflow V2.1 66 | (let ( 67 | (balance-bitflow-1 (unwrap-panic (at-block block-hash (get-bitflow-lp-1 account)))) 68 | (balance-bitflow-2-1 (unwrap-panic (at-block block-hash (get-bitflow-lp-2-1 account)))) 69 | ) 70 | (ok (+ balance-bitflow-1 balance-bitflow-2-1)) 71 | ) 72 | ) 73 | ) 74 | ) 75 | ) 76 | 77 | ;; V1 78 | (define-read-only (get-bitflow-lp-1 (account principal)) 79 | (let ( 80 | ;; Wallet 81 | (balance (unwrap-panic (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-1 get-balance account))) 82 | 83 | ;; Staked 84 | (user-data (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.earn-stx-ststx-v-1-1 get-user-data 85 | .ststx-token 86 | 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-1 87 | account 88 | )) 89 | 90 | (staked (if (is-some user-data) 91 | (get total-currently-staked (unwrap-panic user-data)) 92 | u0 93 | )) 94 | ) 95 | (ok (+ balance staked)) 96 | ) 97 | ) 98 | 99 | ;; V2 100 | (define-read-only (get-bitflow-lp-2-1 (account principal)) 101 | (let ( 102 | ;; Wallet 103 | (balance (unwrap-panic (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-2 get-balance account))) 104 | 105 | ;; Staked 106 | (user-data (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.earn-stx-ststx-v-1-2 get-user-data 107 | .ststx-token 108 | 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-2 109 | account 110 | )) 111 | 112 | (staked (if (is-some user-data) 113 | (get total-currently-staked (unwrap-panic user-data)) 114 | u0 115 | )) 116 | ) 117 | (ok (+ balance staked)) 118 | ) 119 | ) 120 | -------------------------------------------------------------------------------- /contracts/block-info-v11.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-user-hermetica (account principal) (block uint)) 3 | (let ( 4 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 5 | ) 6 | (if (< block u146526) 7 | (ok u0) 8 | (ok (at-block block-hash (get-user-hermetica-helper account))) 9 | ) 10 | ) 11 | ) 12 | 13 | (define-read-only (get-user-hermetica-helper (account principal)) 14 | (let ( 15 | (token-balance (unwrap-panic (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.token-ststx-earn-v1 get-balance account))) 16 | (ratio (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-underlying-per-token)) 17 | ) 18 | (/ (* token-balance ratio) u1000000) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /contracts/block-info-v17.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-user-hermetica (account principal) (block uint)) 3 | (let ( 4 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 5 | ) 6 | (if (< block u146526) 7 | (ok u0) 8 | (ok (at-block block-hash (get-user-hermetica-helper account))) 9 | ) 10 | ) 11 | ) 12 | 13 | (define-read-only (get-user-hermetica-helper (account principal)) 14 | (let ( 15 | (token-balance (unwrap-panic (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.token-ststx-earn-v1 get-balance account))) 16 | (ratio (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-underlying-per-token)) 17 | (wallet-amount (/ (* token-balance ratio) u1000000)) 18 | 19 | (queued-amount (get-queued-hermetica-helper account)) 20 | ) 21 | (+ wallet-amount queued-amount) 22 | ) 23 | ) 24 | 25 | (define-read-only (get-queued-hermetica-helper (account principal)) 26 | (let ( 27 | (deposit-claims (get deposit-claims (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-claims-for-address account))) 28 | ) 29 | (fold + (map get-claim-iter deposit-claims) u0) 30 | ) 31 | ) 32 | 33 | (define-read-only (get-claim-iter (claim-id uint)) 34 | (let ( 35 | (claim (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-claim claim-id)) 36 | ) 37 | (get underlying-amount (unwrap-panic claim)) 38 | ) 39 | ) 40 | -------------------------------------------------------------------------------- /contracts/block-info-v20.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info 2 | ;; @version 20 3 | ;; 4 | ;; Contract to get info at given block 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_BLOCK_INFO u42001) 11 | 12 | ;;------------------------------------- 13 | ;; stSTX info 14 | ;;------------------------------------- 15 | 16 | (define-read-only (get-ststx-supply-at-block (block uint)) 17 | (let ( 18 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 19 | ) 20 | (at-block block-hash (contract-call? .ststx-token get-total-supply)) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /contracts/block-info-v6.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-user-arkadiko (account principal) (block uint)) 3 | (let ( 4 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 5 | ) 6 | (if (< block u142425) 7 | (ok u0) 8 | (ok (at-block block-hash (get-user-arkadiko-helper account))) 9 | ) 10 | ) 11 | ) 12 | 13 | (define-read-only (get-user-arkadiko-helper (account principal)) 14 | (let ( 15 | (vault-info (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-vaults-data-v1-1 get-vault account .ststx-token))) 16 | ) 17 | (get collateral vault-info) 18 | ) 19 | ) 20 | -------------------------------------------------------------------------------- /contracts/block-info-v8.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-user-velar (account principal) (block uint)) 3 | (let ( 4 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 5 | ) 6 | (if (< block u143650) 7 | (ok u0) 8 | (ok (at-block block-hash (get-user-velar-helper account))) 9 | ) 10 | ) 11 | ) 12 | 13 | (define-read-only (get-user-velar-helper (account principal)) 14 | (let ( 15 | (total-lp-supply (unwrap-panic (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.ststx-aeusdc get-total-supply))) 16 | (user-wallet (unwrap-panic (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.ststx-aeusdc get-balance account))) 17 | (user-staked (get end (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.farming-ststx-aeusdc-core get-user-staked account))) 18 | (user-total (+ user-wallet user-staked)) 19 | 20 | (pool-info (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-core do-get-pool u8)) 21 | ) 22 | 23 | (/ (* user-total (get reserve0 pool-info)) total-lp-supply) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /contracts/block-info-v9.clar: -------------------------------------------------------------------------------- 1 | (define-read-only (get-user-zest (account principal) (block uint)) 2 | (let ( 3 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 4 | ) 5 | (if (< block u143345) 6 | (ok u0) 7 | (ok (at-block block-hash (get-user-zest-helper account))) 8 | ) 9 | ) 10 | ) 11 | 12 | (define-read-only (get-user-zest-helper (account principal)) 13 | (let ( 14 | (user-wallet (unwrap-panic (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx-v1-0 get-balance account))) 15 | ) 16 | user-wallet 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /contracts/block-info-velar-nakamoto-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info Velar Nakamoto 2 | ;; @version 1 3 | ;; 4 | ;; Contract to get info stSTX/STX on Velar at given block 5 | 6 | (define-public (get-user-velar (account principal) (block uint)) 7 | (let ( 8 | (ratio (try! (contract-call? .data-core-v1 get-stx-per-ststx .reserve-v1))) 9 | (block-hash (unwrap! (get-stacks-block-info? id-header-hash block) (err u666))) 10 | ) 11 | (if (< block u243045) 12 | (ok u0) 13 | (ok (at-block block-hash (get-user-velar-helper account block ratio))) 14 | ) 15 | ) 16 | ) 17 | 18 | (define-read-only (get-user-velar-helper (account principal) (block uint) (ratio uint)) 19 | (let ( 20 | (total-lp-supply (unwrap-panic (contract-call? 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-lp-token-v1_0_0_ststx-0001 get-total-supply))) 21 | (user-wallet (unwrap-panic (contract-call? 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-lp-token-v1_0_0_ststx-0001 get-balance account))) 22 | (user-staked (if (< block u243045) 23 | u0 24 | (get end (contract-call? 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-farming-core-v1_1_1_ststx-0001 get-user-staked account)) 25 | )) 26 | (pool-info (contract-call? 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-pool-v1_0_0_ststx-0001 do-get-pool)) 27 | (reserve0 (get reserve0 pool-info)) 28 | (reserve0-ststx (/ (* reserve0 u1000000) ratio)) 29 | (reserve1 (get reserve1 pool-info)) 30 | (total-in-pool (+ reserve0-ststx reserve1)) 31 | 32 | (user-total (+ user-wallet user-staked)) 33 | ) 34 | (/ (* user-total total-in-pool) total-lp-supply) 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /contracts/core/ststx-token.clar: -------------------------------------------------------------------------------- 1 | (impl-trait .sip-010-trait-ft-standard.sip-010-trait) 2 | 3 | ;; Defines the Stacked STX according to the SIP010 Standard 4 | (define-fungible-token ststx) 5 | 6 | (define-constant ERR_NOT_AUTHORIZED u1401) 7 | 8 | ;;------------------------------------- 9 | ;; Variables 10 | ;;------------------------------------- 11 | 12 | (define-data-var token-uri (string-utf8 256) u"") 13 | 14 | ;;------------------------------------- 15 | ;; SIP-010 16 | ;;------------------------------------- 17 | 18 | (define-read-only (get-total-supply) 19 | (ok (ft-get-supply ststx)) 20 | ) 21 | 22 | (define-read-only (get-name) 23 | (ok "Stacked STX Token") 24 | ) 25 | 26 | (define-read-only (get-symbol) 27 | (ok "stSTX") 28 | ) 29 | 30 | (define-read-only (get-decimals) 31 | (ok u6) 32 | ) 33 | 34 | (define-read-only (get-balance (account principal)) 35 | (ok (ft-get-balance ststx account)) 36 | ) 37 | 38 | (define-read-only (get-token-uri) 39 | (ok (some (var-get token-uri))) 40 | ) 41 | 42 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 43 | (begin 44 | (asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED)) 45 | (try! (ft-transfer? ststx amount sender recipient)) 46 | 47 | (print memo) 48 | (print { action: "transfer", data: { sender: tx-sender, recipient: recipient, amount: amount, block-height: block-height } }) 49 | 50 | (ok true) 51 | ) 52 | ) 53 | 54 | ;;------------------------------------- 55 | ;; Admin 56 | ;;------------------------------------- 57 | 58 | (define-public (set-token-uri (value (string-utf8 256))) 59 | (begin 60 | (try! (contract-call? .dao check-is-protocol contract-caller)) 61 | (ok (var-set token-uri value)) 62 | ) 63 | ) 64 | 65 | ;;------------------------------------- 66 | ;; Mint / Burn 67 | ;;------------------------------------- 68 | 69 | ;; Mint method 70 | (define-public (mint-for-protocol (amount uint) (recipient principal)) 71 | (begin 72 | (try! (contract-call? .dao check-is-protocol contract-caller)) 73 | (ft-mint? ststx amount recipient) 74 | ) 75 | ) 76 | 77 | ;; Burn method 78 | (define-public (burn-for-protocol (amount uint) (sender principal)) 79 | (begin 80 | (try! (contract-call? .dao check-is-protocol contract-caller)) 81 | (ft-burn? ststx amount sender) 82 | ) 83 | ) 84 | 85 | ;; Burn external 86 | (define-public (burn (amount uint)) 87 | (begin 88 | (ft-burn? ststx amount tx-sender) 89 | ) 90 | ) 91 | -------------------------------------------------------------------------------- /contracts/core/ststxbtc-token-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract stSTXbtc token 2 | ;; @version 2 3 | ;; 4 | 5 | (impl-trait .sip-010-trait-ft-standard.sip-010-trait) 6 | 7 | ;; Defines the Stacked STX BTC token according to the SIP010 Standard 8 | (define-fungible-token ststxbtc) 9 | 10 | (define-constant ERR_NOT_AUTHORIZED u1401) 11 | 12 | ;;------------------------------------- 13 | ;; Variables 14 | ;;------------------------------------- 15 | 16 | (define-data-var token-uri (string-utf8 256) u"") 17 | 18 | ;;------------------------------------- 19 | ;; SIP-010 20 | ;;------------------------------------- 21 | 22 | (define-read-only (get-total-supply) 23 | (ok (ft-get-supply ststxbtc)) 24 | ) 25 | 26 | (define-read-only (get-name) 27 | (ok "Stacked STX BTC Token") 28 | ) 29 | 30 | (define-read-only (get-symbol) 31 | (ok "stSTXbtc") 32 | ) 33 | 34 | (define-read-only (get-decimals) 35 | (ok u6) 36 | ) 37 | 38 | (define-read-only (get-balance (account principal)) 39 | (ok (ft-get-balance ststxbtc account)) 40 | ) 41 | 42 | (define-read-only (get-token-uri) 43 | (ok (some (var-get token-uri))) 44 | ) 45 | 46 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 47 | (begin 48 | (asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED)) 49 | (try! (ft-transfer? ststxbtc amount sender recipient)) 50 | 51 | (try! (contract-call? .ststxbtc-tracking-v2 refresh-wallet sender (ft-get-balance ststxbtc sender))) 52 | (try! (contract-call? .ststxbtc-tracking-v2 refresh-wallet recipient (ft-get-balance ststxbtc recipient))) 53 | 54 | (print memo) 55 | (print { action: "transfer", data: { sender: tx-sender, recipient: recipient, amount: amount, block-height: block-height } }) 56 | 57 | (ok true) 58 | ) 59 | ) 60 | 61 | ;;------------------------------------- 62 | ;; Admin 63 | ;;------------------------------------- 64 | 65 | (define-public (set-token-uri (value (string-utf8 256))) 66 | (begin 67 | (try! (contract-call? .dao check-is-protocol contract-caller)) 68 | (ok (var-set token-uri value)) 69 | ) 70 | ) 71 | 72 | ;;------------------------------------- 73 | ;; Mint / Burn 74 | ;;------------------------------------- 75 | 76 | ;; Mint method 77 | (define-public (mint-for-protocol (amount uint) (recipient principal)) 78 | (let ( 79 | (result (ft-mint? ststxbtc amount recipient)) 80 | ) 81 | (try! (contract-call? .dao check-is-protocol contract-caller)) 82 | (try! (contract-call? .ststxbtc-tracking-data-v2 set-total-supply (ft-get-supply ststxbtc))) 83 | (try! (contract-call? .ststxbtc-tracking-v2 refresh-wallet recipient (ft-get-balance ststxbtc recipient))) 84 | result 85 | ) 86 | ) 87 | 88 | ;; Burn method 89 | (define-public (burn-for-protocol (amount uint) (sender principal)) 90 | (let ( 91 | (result (ft-burn? ststxbtc amount sender)) 92 | ) 93 | (try! (contract-call? .dao check-is-protocol contract-caller)) 94 | (try! (contract-call? .ststxbtc-tracking-data-v2 set-total-supply (ft-get-supply ststxbtc))) 95 | (try! (contract-call? .ststxbtc-tracking-v2 refresh-wallet sender (ft-get-balance ststxbtc sender))) 96 | result 97 | ) 98 | ) 99 | 100 | ;; Burn external 101 | (define-public (burn (amount uint)) 102 | (let ( 103 | (result (ft-burn? ststxbtc amount tx-sender)) 104 | ) 105 | (try! (contract-call? .ststxbtc-tracking-data-v2 set-total-supply (ft-get-supply ststxbtc))) 106 | (try! (contract-call? .ststxbtc-tracking-v2 refresh-wallet tx-sender (ft-get-balance ststxbtc tx-sender))) 107 | result 108 | ) 109 | ) 110 | -------------------------------------------------------------------------------- /contracts/core/ststxbtc-token.clar: -------------------------------------------------------------------------------- 1 | (impl-trait .sip-010-trait-ft-standard.sip-010-trait) 2 | 3 | ;; Defines the Stacked STX BTC token according to the SIP010 Standard 4 | (define-fungible-token ststxbtc) 5 | 6 | (define-constant ERR_NOT_AUTHORIZED u1401) 7 | 8 | ;;------------------------------------- 9 | ;; Variables 10 | ;;------------------------------------- 11 | 12 | (define-data-var token-uri (string-utf8 256) u"") 13 | 14 | ;;------------------------------------- 15 | ;; SIP-010 16 | ;;------------------------------------- 17 | 18 | (define-read-only (get-total-supply) 19 | (ok (ft-get-supply ststxbtc)) 20 | ) 21 | 22 | (define-read-only (get-name) 23 | (ok "Stacked STX BTC Token") 24 | ) 25 | 26 | (define-read-only (get-symbol) 27 | (ok "stSTXbtc") 28 | ) 29 | 30 | (define-read-only (get-decimals) 31 | (ok u6) 32 | ) 33 | 34 | (define-read-only (get-balance (account principal)) 35 | (ok (ft-get-balance ststxbtc account)) 36 | ) 37 | 38 | (define-read-only (get-token-uri) 39 | (ok (some (var-get token-uri))) 40 | ) 41 | 42 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 43 | (begin 44 | (asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED)) 45 | (try! (ft-transfer? ststxbtc amount sender recipient)) 46 | 47 | (try! (contract-call? .ststxbtc-tracking refresh-wallet sender (ft-get-balance ststxbtc sender))) 48 | (try! (contract-call? .ststxbtc-tracking refresh-wallet recipient (ft-get-balance ststxbtc recipient))) 49 | 50 | (print memo) 51 | (print { action: "transfer", data: { sender: tx-sender, recipient: recipient, amount: amount, block-height: block-height } }) 52 | 53 | (ok true) 54 | ) 55 | ) 56 | 57 | ;;------------------------------------- 58 | ;; Admin 59 | ;;------------------------------------- 60 | 61 | (define-public (set-token-uri (value (string-utf8 256))) 62 | (begin 63 | (try! (contract-call? .dao check-is-protocol contract-caller)) 64 | (ok (var-set token-uri value)) 65 | ) 66 | ) 67 | 68 | ;;------------------------------------- 69 | ;; Mint / Burn 70 | ;;------------------------------------- 71 | 72 | ;; Mint method 73 | (define-public (mint-for-protocol (amount uint) (recipient principal)) 74 | (let ( 75 | (result (ft-mint? ststxbtc amount recipient)) 76 | ) 77 | (try! (contract-call? .dao check-is-protocol contract-caller)) 78 | (try! (contract-call? .ststxbtc-tracking-data set-total-supply (ft-get-supply ststxbtc))) 79 | (try! (contract-call? .ststxbtc-tracking refresh-wallet recipient (ft-get-balance ststxbtc recipient))) 80 | result 81 | ) 82 | ) 83 | 84 | ;; Burn method 85 | (define-public (burn-for-protocol (amount uint) (sender principal)) 86 | (let ( 87 | (result (ft-burn? ststxbtc amount sender)) 88 | ) 89 | (try! (contract-call? .dao check-is-protocol contract-caller)) 90 | (try! (contract-call? .ststxbtc-tracking-data set-total-supply (ft-get-supply ststxbtc))) 91 | (try! (contract-call? .ststxbtc-tracking refresh-wallet sender (ft-get-balance ststxbtc sender))) 92 | result 93 | ) 94 | ) 95 | 96 | ;; Burn external 97 | (define-public (burn (amount uint)) 98 | (let ( 99 | (result (ft-burn? ststxbtc amount tx-sender)) 100 | ) 101 | (try! (contract-call? .ststxbtc-tracking-data set-total-supply (ft-get-supply ststxbtc))) 102 | (try! (contract-call? .ststxbtc-tracking refresh-wallet tx-sender (ft-get-balance ststxbtc tx-sender))) 103 | result 104 | ) 105 | ) 106 | -------------------------------------------------------------------------------- /contracts/genesis-nft/stacking-dao-cc-nft-minter.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Stacking DAO CC (NYC) NFT 2 | ;; @version 2 3 | ;; 4 | ;; Stacking DAO CC (NYC) NFT minter 5 | ;; 6 | 7 | ;;------------------------------------- 8 | ;; Constants 9 | ;;------------------------------------- 10 | 11 | (define-constant ERR_NOT_AUTHORIZED u1101) 12 | 13 | ;;------------------------------------- 14 | ;; Variables 15 | ;;------------------------------------- 16 | 17 | (define-data-var deployer principal tx-sender) 18 | 19 | ;;------------------------------------- 20 | ;; Set 21 | ;;------------------------------------- 22 | 23 | (define-public (set-deployer (new-deployer principal)) 24 | (begin 25 | (asserts! (is-eq tx-sender (var-get deployer)) (err ERR_NOT_AUTHORIZED)) 26 | 27 | (var-set deployer new-deployer) 28 | (ok true) 29 | ) 30 | ) 31 | 32 | ;;------------------------------------- 33 | ;; Airdrop 34 | ;;------------------------------------- 35 | 36 | (define-public (airdrop (info (tuple (recipient principal) (type uint)))) 37 | (let ( 38 | (recipient (get recipient info)) 39 | (type (get type info)) 40 | ) 41 | (asserts! (is-eq tx-sender (var-get deployer)) (err ERR_NOT_AUTHORIZED)) 42 | (try! (contract-call? .stacking-dao-cc-nft mint-for-protocol recipient type)) 43 | (ok true) 44 | ) 45 | ) 46 | 47 | (define-public (airdrop-many (recipients (list 25 (tuple (recipient principal) (type uint))))) 48 | (begin 49 | (asserts! (is-eq tx-sender (var-get deployer)) (err ERR_NOT_AUTHORIZED)) 50 | (ok (map airdrop recipients)) 51 | ) 52 | ) 53 | -------------------------------------------------------------------------------- /contracts/genesis-nft/stacking-dao-genesis-nft-minter-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Stacking DAO Genesis NFT 2 | ;; @version 2 3 | ;; 4 | ;; Stacking DAO Genesis NFT minter 5 | ;; 6 | 7 | ;;------------------------------------- 8 | ;; Constants 9 | ;;------------------------------------- 10 | 11 | (define-constant ERR_NOT_AUTHORIZED u1101) 12 | (define-constant ERR_CANNOT_CLAIM u1102) 13 | (define-constant ERR_ALREADY_CLAIMED u1103) 14 | (define-constant DEPLOYER tx-sender) 15 | 16 | ;;------------------------------------- 17 | ;; Maps 18 | ;;------------------------------------- 19 | 20 | (define-map claims principal bool) 21 | 22 | ;;------------------------------------- 23 | ;; Variables 24 | ;;------------------------------------- 25 | 26 | (define-data-var cycle-end-block uint u133737) 27 | 28 | ;;------------------------------------- 29 | ;; Getters 30 | ;;------------------------------------- 31 | 32 | ;; If people held at least 100 stSTX throughout cycle 74, they can claim a Stacking DAO Genesis NFT 33 | (define-read-only (can-claim (account principal)) 34 | (let ( 35 | (balances (contract-call? .block-info-v1 get-user-ststx-at-block account (var-get cycle-end-block))) 36 | (ststx-balance (get ststx-balance balances)) 37 | (lp-balance (get lp-balance balances)) 38 | ) 39 | (>= (+ ststx-balance lp-balance) u99000000) 40 | ) 41 | ) 42 | 43 | (define-read-only (has-claimed (account principal)) 44 | (default-to false (map-get? claims account)) 45 | ) 46 | 47 | (define-read-only (get-cycle-end-block) 48 | (var-get cycle-end-block) 49 | ) 50 | 51 | ;;------------------------------------- 52 | ;; Setters 53 | ;;------------------------------------- 54 | 55 | (define-public (set-cycle-end-block (end-block uint)) 56 | (begin 57 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 58 | 59 | (ok (var-set cycle-end-block end-block)) 60 | ) 61 | ) 62 | 63 | ;;------------------------------------- 64 | ;; Claim 65 | ;;------------------------------------- 66 | 67 | (define-public (claim) 68 | (begin 69 | (asserts! (can-claim tx-sender) (err ERR_CANNOT_CLAIM)) 70 | (asserts! (not (has-claimed tx-sender)) (err ERR_ALREADY_CLAIMED)) 71 | 72 | (try! (contract-call? .stacking-dao-genesis-nft mint-for-protocol tx-sender u0)) 73 | (map-set claims tx-sender true) 74 | (ok true) 75 | ) 76 | ) 77 | 78 | (define-public (airdrop (info (tuple (recipient principal) (type uint)))) 79 | (let ( 80 | (recipient (get recipient info)) 81 | (type (get type info)) 82 | ) 83 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 84 | (asserts! (can-claim recipient) (err ERR_CANNOT_CLAIM)) 85 | (asserts! (not (has-claimed recipient)) (err ERR_ALREADY_CLAIMED)) 86 | 87 | (try! (contract-call? .stacking-dao-genesis-nft mint-for-protocol recipient type)) 88 | (map-set claims recipient true) 89 | (ok true) 90 | ) 91 | ) 92 | 93 | (define-public (airdrop-many (recipients (list 25 (tuple (recipient principal) (type uint))))) 94 | (begin 95 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 96 | (ok (map airdrop recipients)) 97 | ) 98 | ) 99 | 100 | (map-set claims 'SP2N3KC4CR7CC0JP592S9RBA9GHVVD30WRA5GXE8G true) 101 | (map-set claims 'SP1DJWJNKREHT3YGRB09DRCYD1QKGK5DKF8V868VX true) 102 | (map-set claims 'SPF7FJ9VFSVKNWH7JWSNFTTCG3P5Z0429R38KV7S true) 103 | (map-set claims 'SP3VTC5TNYC9ZJ5NZ9DG4HHZP5Z21ZM5JRSF6M5MD true) 104 | (map-set claims 'SP3J0Z8YSJD20TGEBE6M992CWFDG18VB0PR599VY9 true) 105 | (map-set claims 'SP34455SJ4NJ7MCKV7CN64JJTVDP3VZPMVT54BH57 true) 106 | (map-set claims 'SP2EDRYCPGTS32HZAGWV54RAVA2GTW0WPBP4HGCXR true) 107 | (map-set claims 'SP3XD84X3PE79SHJAZCDW1V5E9EA8JSKRBPEKAEK7 true) 108 | (map-set claims 'SP1HHSDYJ0SGAM6K2W01ZF5K7AJFKWMJNH365ZWS9 true) 109 | (map-set claims 'SPM5BVEBYCN2Z1AR2E06A69HF1W70G7V5GZFDNPR true) 110 | (map-set claims 'SP331R3MQE82TBWV5R4WGZAD6FRDBN6S5ZN635CG2 true) 111 | (map-set claims 'SP3P1TCXN3FP3V79YWXC49F5X2HYKS39CMCP5FEHN true) 112 | (map-set claims 'SP1E8A3T3AW2HRFB5FXMYWB2DC0TSC6H1EGTHND1W true) 113 | (map-set claims 'SP25SF2MPZZS8Q20QA3VTYJXTHAHCRNM5MSZYDNB0 true) 114 | (map-set claims 'SP32ZYEZGWHHFQ5RX2WMFVDXR77C5WWQP4EK7E6HC true) 115 | (map-set claims 'SP2FA1H3K9FMY2CQ80WWT2JYMHZ5Z2B810AT41APW true) 116 | (map-set claims 'SP2855G3MZ3WFS5P0NRK098T1DKQ3QH5MVJ14P70P true) 117 | (map-set claims 'SP3XMSJSV1TYRP69PAC0751P483QZ3E17R5GTV4CX true) 118 | (map-set claims 'SP2ZNGJ85ENDY6QRHQ5P2D4FXKGZWCKTB2T0Z55KS true) 119 | (map-set claims 'SP19WSDJWTH4CW3YG554XS5CAXJJGAN83P8CFZ4K1 true) 120 | (map-set claims 'SP1XY983C1MEXM83MGNJC2JAAEGYVYZY5BYW5KS4K true) 121 | (map-set claims 'SP2VG7S0R4Z8PYNYCAQ04HCBX1MH75VT11VXCWQ6G true) 122 | (map-set claims 'SP3XYP0HYZHKHJ96THQX8AV7TQYJWMF8PP30K0RX5 true) 123 | (map-set claims 'SP18P831TBGKSGMJEMJM0V29CMKJP650ZT21YJ3XX true) 124 | -------------------------------------------------------------------------------- /contracts/genesis-nft/stacking-dao-genesis-nft-minter.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Stacking DAO Genesis NFT 2 | ;; @version 1 3 | ;; 4 | ;; Stacking DAO Genesis NFT minter 5 | ;; 6 | 7 | ;;------------------------------------- 8 | ;; Constants 9 | ;;------------------------------------- 10 | 11 | (define-constant ERR_NOT_AUTHORIZED u1101) 12 | (define-constant ERR_CANNOT_CLAIM u1102) 13 | (define-constant ERR_ALREADY_CLAIMED u1103) 14 | (define-constant DEPLOYER tx-sender) 15 | 16 | ;;------------------------------------- 17 | ;; Maps 18 | ;;------------------------------------- 19 | 20 | (define-map claims principal bool) 21 | 22 | ;;------------------------------------- 23 | ;; Variables 24 | ;;------------------------------------- 25 | 26 | (define-data-var cycle-end-block uint u135418) 27 | 28 | ;;------------------------------------- 29 | ;; Getters 30 | ;;------------------------------------- 31 | 32 | ;; If people held at least 100 stSTX throughout cycle 74/75, they can claim a Stacking DAO Genesis NFT 33 | (define-read-only (can-claim (account principal)) 34 | (let ( 35 | (balances (contract-call? .block-info-v1 get-user-ststx-at-block account (var-get cycle-end-block))) 36 | (ststx-balance (get ststx-balance balances)) 37 | (lp-balance (get lp-balance balances)) 38 | ) 39 | (>= (+ ststx-balance lp-balance) u99000000) 40 | ) 41 | ) 42 | 43 | (define-read-only (has-claimed (account principal)) 44 | (default-to false (map-get? claims account)) 45 | ) 46 | 47 | (define-read-only (get-cycle-end-block) 48 | (var-get cycle-end-block) 49 | ) 50 | 51 | ;;------------------------------------- 52 | ;; Setters 53 | ;;------------------------------------- 54 | 55 | (define-public (set-cycle-end-block (end-block uint)) 56 | (begin 57 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 58 | 59 | (ok (var-set cycle-end-block end-block)) 60 | ) 61 | ) 62 | 63 | ;;------------------------------------- 64 | ;; Claim 65 | ;;------------------------------------- 66 | 67 | (define-public (claim) 68 | (begin 69 | (asserts! (can-claim tx-sender) (err ERR_CANNOT_CLAIM)) 70 | (asserts! (not (has-claimed tx-sender)) (err ERR_ALREADY_CLAIMED)) 71 | 72 | (try! (contract-call? .stacking-dao-genesis-nft mint-for-protocol tx-sender u0)) 73 | (map-set claims tx-sender true) 74 | (ok true) 75 | ) 76 | ) 77 | 78 | (define-public (airdrop (info (tuple (recipient principal) (type uint)))) 79 | (let ( 80 | (recipient (get recipient info)) 81 | (type (get type info)) 82 | ) 83 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 84 | (asserts! (can-claim recipient) (err ERR_CANNOT_CLAIM)) 85 | (asserts! (not (has-claimed recipient)) (err ERR_ALREADY_CLAIMED)) 86 | 87 | (try! (contract-call? .stacking-dao-genesis-nft mint-for-protocol recipient type)) 88 | (map-set claims recipient true) 89 | (ok true) 90 | ) 91 | ) 92 | 93 | (define-public (airdrop-many (recipients (list 25 (tuple (recipient principal) (type uint))))) 94 | (begin 95 | (asserts! (is-eq tx-sender DEPLOYER) (err ERR_NOT_AUTHORIZED)) 96 | (ok (map airdrop recipients)) 97 | ) 98 | ) 99 | 100 | (map-set claims 'SP2N3KC4CR7CC0JP592S9RBA9GHVVD30WRA5GXE8G true) 101 | (map-set claims 'SP1DJWJNKREHT3YGRB09DRCYD1QKGK5DKF8V868VX true) 102 | (map-set claims 'SPF7FJ9VFSVKNWH7JWSNFTTCG3P5Z0429R38KV7S true) 103 | (map-set claims 'SP3VTC5TNYC9ZJ5NZ9DG4HHZP5Z21ZM5JRSF6M5MD true) 104 | (map-set claims 'SP3J0Z8YSJD20TGEBE6M992CWFDG18VB0PR599VY9 true) 105 | (map-set claims 'SP34455SJ4NJ7MCKV7CN64JJTVDP3VZPMVT54BH57 true) 106 | (map-set claims 'SP2EDRYCPGTS32HZAGWV54RAVA2GTW0WPBP4HGCXR true) 107 | (map-set claims 'SP3XD84X3PE79SHJAZCDW1V5E9EA8JSKRBPEKAEK7 true) 108 | (map-set claims 'SP1HHSDYJ0SGAM6K2W01ZF5K7AJFKWMJNH365ZWS9 true) 109 | (map-set claims 'SPM5BVEBYCN2Z1AR2E06A69HF1W70G7V5GZFDNPR true) 110 | (map-set claims 'SP331R3MQE82TBWV5R4WGZAD6FRDBN6S5ZN635CG2 true) 111 | (map-set claims 'SP3P1TCXN3FP3V79YWXC49F5X2HYKS39CMCP5FEHN true) 112 | (map-set claims 'SP1E8A3T3AW2HRFB5FXMYWB2DC0TSC6H1EGTHND1W true) 113 | (map-set claims 'SP25SF2MPZZS8Q20QA3VTYJXTHAHCRNM5MSZYDNB0 true) 114 | (map-set claims 'SP32ZYEZGWHHFQ5RX2WMFVDXR77C5WWQP4EK7E6HC true) 115 | (map-set claims 'SP2FA1H3K9FMY2CQ80WWT2JYMHZ5Z2B810AT41APW true) 116 | (map-set claims 'SP2855G3MZ3WFS5P0NRK098T1DKQ3QH5MVJ14P70P true) 117 | (map-set claims 'SP3XMSJSV1TYRP69PAC0751P483QZ3E17R5GTV4CX true) 118 | (map-set claims 'SP2ZNGJ85ENDY6QRHQ5P2D4FXKGZWCKTB2T0Z55KS true) 119 | (map-set claims 'SP19WSDJWTH4CW3YG554XS5CAXJJGAN83P8CFZ4K1 true) 120 | (map-set claims 'SP1XY983C1MEXM83MGNJC2JAAEGYVYZY5BYW5KS4K true) 121 | (map-set claims 'SP2VG7S0R4Z8PYNYCAQ04HCBX1MH75VT11VXCWQ6G true) 122 | (map-set claims 'SP3XYP0HYZHKHJ96THQX8AV7TQYJWMF8PP30K0RX5 true) 123 | (map-set claims 'SP18P831TBGKSGMJEMJM0V29CMKJP650ZT21YJ3XX true) 124 | -------------------------------------------------------------------------------- /contracts/helpers/block-info-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Block Info 2 | ;; @version 1 3 | ;; 4 | ;; Contract to get info at given block 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_BLOCK_INFO u42001) 11 | 12 | ;;------------------------------------- 13 | ;; Stacking Info 14 | ;;------------------------------------- 15 | 16 | (define-read-only (get-reserve-stacking-at-block (block uint)) 17 | (let ( 18 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 19 | ) 20 | (at-block block-hash (contract-call? .reserve-v1 get-stx-stacking)) 21 | ) 22 | ) 23 | 24 | (define-read-only (get-stx-account-at-block (account principal) (block uint)) 25 | (let ( 26 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 27 | ) 28 | (ok (at-block block-hash (stx-account account))) 29 | ) 30 | ) 31 | 32 | ;;------------------------------------- 33 | ;; User Info - Points 34 | ;;------------------------------------- 35 | 36 | (define-read-only (get-user-ststx-at-block (account principal) (block uint)) 37 | (let ( 38 | (ststx-balance (get-ststx-balance-at-block account block)) 39 | (lp-balance (get-lp-balance-at-block account block)) 40 | ) 41 | { 42 | ststx-balance: (unwrap-panic ststx-balance), 43 | lp-balance: (unwrap-panic lp-balance) 44 | } 45 | ) 46 | ) 47 | 48 | ;;------------------------------------- 49 | ;; User Info - Points - Helpers 50 | ;;------------------------------------- 51 | 52 | (define-read-only (get-ststx-balance-at-block (account principal) (block uint)) 53 | (let ( 54 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 55 | ) 56 | (at-block block-hash (contract-call? .ststx-token get-balance account)) 57 | ) 58 | ) 59 | 60 | (define-read-only (get-lp-balance-at-block (account principal) (block uint)) 61 | (let ( 62 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO))) 63 | 64 | ;; Wallet 65 | (balance (at-block block-hash (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-1 get-balance account))) 66 | 67 | ;; Staked 68 | (user-data (at-block block-hash (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.earn-stx-ststx-v-1-1 get-user-data 69 | .ststx-token 70 | 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-1 71 | account 72 | ))) 73 | ) 74 | (if (is-some user-data) 75 | ;; Has staked 76 | (ok (+ (unwrap-panic balance) (get total-currently-staked (unwrap-panic user-data)))) 77 | ;; Not staked 78 | balance 79 | ) 80 | ) 81 | ) 82 | -------------------------------------------------------------------------------- /contracts/helpers/cc-redemption-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract CityCoins Redemption 2 | ;; @version 1 3 | ;; 4 | 5 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 6 | (use-trait direct-helpers-trait .direct-helpers-trait-v1.direct-helpers-trait) 7 | (use-trait staking-trait .staking-trait-v1.staking-trait) 8 | (use-trait commission-trait .commission-trait-v1.commission-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Main 12 | ;;------------------------------------- 13 | 14 | (define-public (deposit 15 | (reserve ) 16 | (commission ) 17 | (staking ) 18 | (direct-helpers ) 19 | (referrer (optional principal)) 20 | (pool (optional principal)) 21 | ) 22 | (let ( 23 | ;; TODO: update for mainnet 24 | (redemption-stx (unwrap-panic (try! (contract-call? 'SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccd012-redemption-nyc redeem-nyc)))) 25 | ) 26 | (contract-call? .stacking-dao-core-v2 deposit reserve commission staking direct-helpers redemption-stx referrer pool) 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /contracts/helpers/commission-trait.clar: -------------------------------------------------------------------------------- 1 | (define-trait commission 2 | ((pay (uint uint) (response bool uint))) 3 | ) 4 | -------------------------------------------------------------------------------- /contracts/helpers/nft-trait.clar: -------------------------------------------------------------------------------- 1 | (define-trait nft-trait 2 | ( 3 | ;; Last token ID, limited to uint range 4 | (get-last-token-id () (response uint uint)) 5 | 6 | ;; URI for metadata associated with the token 7 | (get-token-uri (uint) (response (optional (string-ascii 256)) uint)) 8 | 9 | ;; Owner of a given token identifier 10 | (get-owner (uint) (response (optional principal) uint)) 11 | 12 | ;; Transfer from the sender to a new principal 13 | (transfer (uint principal principal) (response bool uint)) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /contracts/helpers/sip-010-trait-ft-standard.clar: -------------------------------------------------------------------------------- 1 | (define-trait sip-010-trait 2 | ( 3 | ;; Transfer from the caller to a new principal 4 | (transfer (uint principal principal (optional (buff 34))) (response bool uint)) 5 | 6 | ;; the human readable name of the token 7 | (get-name () (response (string-ascii 32) uint)) 8 | 9 | ;; the ticker symbol, or empty if none 10 | (get-symbol () (response (string-ascii 32) uint)) 11 | 12 | ;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token 13 | (get-decimals () (response uint uint)) 14 | 15 | ;; the balance of the passed principal 16 | (get-balance (principal) (response uint uint)) 17 | 18 | ;; the current total supply (which does not need to be a constant) 19 | (get-total-supply () (response uint uint)) 20 | 21 | ;; an optional URI that represents metadata of this token 22 | (get-token-uri () (response (optional (string-utf8 256)) uint)) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /contracts/helpers/ststxbtc-helper-v2.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-read-only (get-ststxbtc-total-supply (block uint)) 3 | (let ( 4 | ;; TODO: update for mainnet for mainnet 5 | ;; (block-hash (unwrap! (get-stacks-block-info? id-header-hash block) (err u666))) 6 | (block-hash (unwrap! (get-block-info? id-header-hash block) (err u666))) 7 | ) 8 | (ok (at-block block-hash (get-total-supply block))) 9 | ) 10 | ) 11 | 12 | (define-read-only (get-total-supply (block uint)) 13 | (let ( 14 | (supply-v1 (if (<= block u489222) 15 | u0 16 | (unwrap! (contract-call? .ststxbtc-token get-total-supply) u0)) 17 | ) 18 | ;; TODO: update block for mainnet 19 | (supply-v2 (if (<= block u489222) 20 | u0 21 | (unwrap! (contract-call? .ststxbtc-token-v2 get-total-supply) u0)) 22 | ) 23 | ) 24 | (+ supply-v1 supply-v2) 25 | ) 26 | ) 27 | 28 | (define-read-only (get-current-total-supply) 29 | (let ( 30 | (supply-v1 (unwrap! (contract-call? .ststxbtc-token get-total-supply) (ok u0))) 31 | (supply-v2 (unwrap! (contract-call? .ststxbtc-token-v2 get-total-supply) (ok u0))) 32 | ) 33 | (ok (+ supply-v1 supply-v2)) 34 | ) 35 | ) -------------------------------------------------------------------------------- /contracts/helpers/token-metadata-update-notify.clar: -------------------------------------------------------------------------------- 1 | ;; token-metadata-update-notify 2 | ;; 3 | ;; Use this contract to notify token metadata indexers that an NFT or FT needs its metadata 4 | ;; refreshed. 5 | 6 | (use-trait nft-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait) 7 | (use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) 8 | 9 | ;; Refresh the metadata for one or more NFTs from a specific contract. 10 | (define-public (nft-metadata-update-notify (contract ) (token-ids (list 100 uint))) 11 | (ok (print 12 | { 13 | notification: "token-metadata-update", 14 | payload: { 15 | contract-id: contract, 16 | token-class: "nft", 17 | token-ids: token-ids 18 | } 19 | }) 20 | ) 21 | ) 22 | 23 | ;; Refresh the metadata for a FT from a specific contract 24 | (define-public (ft-metadata-update-notify (contract )) 25 | (ok (print 26 | { 27 | notification: "token-metadata-update", 28 | payload: { 29 | contract-id: contract, 30 | token-class: "ft" 31 | } 32 | }) 33 | ) 34 | ) 35 | -------------------------------------------------------------------------------- /contracts/keeper-jobs/return-stx-job-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Return STX Job 2 | ;; @version 1 3 | ;; 4 | ;; When a stacker is stopped, the STX will be returned to the stacker contract. 5 | ;; This job makes sure the STX is transferred from the stacker contract to the reserve. 6 | 7 | (impl-trait 'SP3C0TCQS0C0YY8E0V3EJ7V4X9571885D44M8EFWF.arkadiko-automation-trait-v1.automation-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Variables 11 | ;;------------------------------------- 12 | 13 | (define-constant ERR_SHOULD_NOT_HANDLE u31001) 14 | 15 | ;;------------------------------------- 16 | ;; Arkadiko Keeper functions 17 | ;;------------------------------------- 18 | 19 | (define-public (initialize) 20 | (ok true) 21 | ) 22 | 23 | (define-read-only (check-job) 24 | (let ( 25 | (stackers (list .stacker-1 .stacker-2 .stacker-3 .stacker-4 .stacker-5 .stacker-6 .stacker-7 .stacker-8 .stacker-9 .stacker-10)) 26 | (stx-balance (fold + (map stx-get-balance stackers) u0)) 27 | ) 28 | (if (> stx-balance u0) 29 | (ok true) 30 | (ok false) 31 | ) 32 | ) 33 | ) 34 | 35 | (define-public (run-job) 36 | (begin 37 | (asserts! (unwrap-panic (check-job)) (err ERR_SHOULD_NOT_HANDLE)) 38 | 39 | (try! (contract-call? .stacker-1 return-stx .reserve-v1)) 40 | (try! (contract-call? .stacker-2 return-stx .reserve-v1)) 41 | (try! (contract-call? .stacker-3 return-stx .reserve-v1)) 42 | (try! (contract-call? .stacker-4 return-stx .reserve-v1)) 43 | (try! (contract-call? .stacker-5 return-stx .reserve-v1)) 44 | (try! (contract-call? .stacker-6 return-stx .reserve-v1)) 45 | (try! (contract-call? .stacker-7 return-stx .reserve-v1)) 46 | (try! (contract-call? .stacker-8 return-stx .reserve-v1)) 47 | (try! (contract-call? .stacker-9 return-stx .reserve-v1)) 48 | (try! (contract-call? .stacker-10 return-stx .reserve-v1)) 49 | 50 | (ok true) 51 | ) 52 | ) 53 | -------------------------------------------------------------------------------- /contracts/keeper-jobs/rewards-job-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Rewards Job 2 | ;; @version 1 3 | ;; 4 | ;; Stacking rewards are received after the cycle ends, and swapped to STX. 5 | ;; The STX is added to this contract. At the end of the current cycle, the STX will be added to the protocol. 6 | 7 | (impl-trait 'SP3C0TCQS0C0YY8E0V3EJ7V4X9571885D44M8EFWF.arkadiko-automation-trait-v1.automation-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Variables 11 | ;;------------------------------------- 12 | 13 | (define-constant ERR_SHOULD_NOT_HANDLE u31001) 14 | 15 | ;;------------------------------------- 16 | ;; Arkadiko Keeper functions 17 | ;;------------------------------------- 18 | 19 | (define-public (initialize) 20 | (ok true) 21 | ) 22 | 23 | (define-read-only (check-job) 24 | (let ( 25 | (stx-balance (stx-get-balance (as-contract tx-sender))) 26 | (current-cycle (contract-call? .stacking-dao-core-v1 get-pox-cycle)) 27 | (next-withdraw-cycle (contract-call? .stacking-dao-core-v1 get-next-withdraw-cycle)) 28 | 29 | (balance-not-zero (> stx-balance u0)) 30 | (end-of-cycle (> next-withdraw-cycle (+ current-cycle u1))) 31 | ) 32 | (if (and balance-not-zero end-of-cycle) 33 | (ok true) 34 | (ok false) 35 | ) 36 | ) 37 | ) 38 | 39 | (define-public (run-job) 40 | (let ( 41 | (stx-balance (stx-get-balance (as-contract tx-sender))) 42 | (current-cycle (contract-call? .stacking-dao-core-v1 get-pox-cycle)) 43 | ) 44 | (asserts! (unwrap-panic (check-job)) (err ERR_SHOULD_NOT_HANDLE)) 45 | 46 | (try! (as-contract (contract-call? .stacking-dao-core-v1 add-rewards .commission-v1 .staking-v1 .reserve-v1 stx-balance current-cycle))) 47 | 48 | (ok true) 49 | ) 50 | ) 51 | 52 | ;;------------------------------------- 53 | ;; Admin 54 | ;;------------------------------------- 55 | 56 | (define-public (retreive-stx-tokens (requested-stx uint) (receiver principal)) 57 | (begin 58 | (try! (contract-call? .dao check-is-protocol tx-sender)) 59 | 60 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 61 | (ok requested-stx) 62 | ) 63 | ) 64 | -------------------------------------------------------------------------------- /contracts/keeper-jobs/tax-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Tax 2 | ;; @version 1 3 | ;; 4 | ;; Liquidity will be added on Bitflow (https://www.bitflow.finance) 5 | ;; Bitflow will impose a purchase/sale tax in STX, and the proceeds will be directed to this contract. 6 | ;; 7 | ;; Once a sufficient amount of STX is accumulated, a portion of it will be exchanged for sDAO. 8 | ;; Both STX and sDAO will be added to the liquidity pool. 9 | ;; 10 | ;; The Arkadiko keepers network is leveraged to automate this process. 11 | ;; https://keepers.arkadiko.finance/ 12 | 13 | (impl-trait 'SP3C0TCQS0C0YY8E0V3EJ7V4X9571885D44M8EFWF.arkadiko-automation-trait-v1.automation-trait) 14 | (use-trait ft-trait .sip-010-trait-ft-standard.sip-010-trait) 15 | 16 | ;;------------------------------------- 17 | ;; Variables 18 | ;;------------------------------------- 19 | 20 | (define-constant ERR_SHOULD_NOT_HANDLE u21001) 21 | (define-constant ERR_COULD_NOT_SWAP u21002) 22 | (define-constant ERR_COULD_NOT_ADD_LIQ u21003) 23 | 24 | ;;------------------------------------- 25 | ;; Variables 26 | ;;------------------------------------- 27 | 28 | (define-data-var min-balance-to-handle uint u100000000) ;; 100 29 | (define-data-var percentage-to-swap uint u4000) ;; bps 30 | 31 | ;;------------------------------------- 32 | ;; Getters 33 | ;;------------------------------------- 34 | 35 | (define-read-only (get-min-balance-to-handle) 36 | (var-get min-balance-to-handle) 37 | ) 38 | 39 | (define-read-only (get-percentage-to-swap) 40 | (var-get percentage-to-swap) 41 | ) 42 | 43 | ;;------------------------------------- 44 | ;; Arkadiko Keeper functions 45 | ;;------------------------------------- 46 | 47 | (define-public (initialize) 48 | (ok true) 49 | ) 50 | 51 | (define-read-only (check-job) 52 | (ok (should-handle-tax)) 53 | ) 54 | 55 | (define-public (run-job) 56 | (handle-tax) 57 | ) 58 | 59 | ;;------------------------------------- 60 | ;; Handle tax 61 | ;;------------------------------------- 62 | 63 | ;; Once enough STX is gathered, this job contract can be executed. 64 | (define-read-only (should-handle-tax) 65 | (let ( 66 | (balance (stx-get-balance (as-contract tx-sender))) 67 | ) 68 | (if (>= balance (get-min-balance-to-handle)) 69 | true 70 | false 71 | ) 72 | ) 73 | ) 74 | 75 | ;; Swap STX to sDAO. Add both as liquidity. 76 | (define-public (handle-tax) 77 | (begin 78 | (asserts! (should-handle-tax) (err ERR_SHOULD_NOT_HANDLE)) 79 | 80 | (let ( 81 | (balance (stx-get-balance (as-contract tx-sender))) 82 | (to-swap (/ (* balance (var-get percentage-to-swap)) u10000)) 83 | ) 84 | ;; Swap STX for sDAO 85 | ;; TODO: update for mainnet 86 | (unwrap! (as-contract (contract-call? .swap swap-y-for-x 87 | .wstx-token 88 | .sdao-token 89 | .swap-lp-token 90 | to-swap 91 | u1 92 | )) (err ERR_COULD_NOT_SWAP)) 93 | 94 | ;; Add sDAO/STX liquidity 95 | ;; TODO: update for mainnet 96 | (let ( 97 | (new-balance-stx (stx-get-balance (as-contract tx-sender))) 98 | (new-balance-sdao (unwrap-panic (contract-call? .sdao-token get-balance (as-contract tx-sender)))) 99 | ) 100 | (unwrap! (as-contract (contract-call? .swap add-liquidity 101 | .sdao-token 102 | .wstx-token 103 | .swap-lp-token 104 | new-balance-sdao 105 | new-balance-stx 106 | u1 107 | )) (err ERR_COULD_NOT_ADD_LIQ)) 108 | ) 109 | 110 | (ok true) 111 | ) 112 | ) 113 | ) 114 | 115 | ;;------------------------------------- 116 | ;; Admin 117 | ;;------------------------------------- 118 | 119 | (define-public (retreive-stx-tokens (requested-stx uint) (receiver principal)) 120 | (begin 121 | (try! (contract-call? .dao check-is-protocol tx-sender)) 122 | 123 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 124 | (ok requested-stx) 125 | ) 126 | ) 127 | 128 | (define-public (retreive-tokens (token ) (requested-tokens uint) (receiver principal)) 129 | (begin 130 | (try! (contract-call? .dao check-is-protocol tx-sender)) 131 | 132 | (try! (as-contract (contract-call? token transfer requested-tokens tx-sender receiver none))) 133 | (ok requested-tokens) 134 | ) 135 | ) 136 | 137 | (define-public (set-min-balance-to-handle (min-balance uint)) 138 | (begin 139 | (try! (contract-call? .dao check-is-protocol tx-sender)) 140 | 141 | (var-set min-balance-to-handle min-balance) 142 | (ok true) 143 | ) 144 | ) 145 | 146 | (define-public (set-percentage-to-swap (new-percentage uint)) 147 | (begin 148 | (try! (contract-call? .dao check-is-protocol tx-sender)) 149 | 150 | (var-set percentage-to-swap new-percentage) 151 | (ok true) 152 | ) 153 | ) 154 | -------------------------------------------------------------------------------- /contracts/tests/ccd012-redemption-nyc.clar: -------------------------------------------------------------------------------- 1 | 2 | (define-public (redeem-nyc) 3 | (begin 4 | (if (is-eq true true) 5 | (ok u100) 6 | (err u123) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /contracts/tests/fake-protocol.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Fake 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;; Public method in case we can not use read-only 7 | (define-public (get-balance (user principal)) 8 | (ok u1000000000000) 9 | ) 10 | -------------------------------------------------------------------------------- /contracts/tests/fake-reserve.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Reserve 2 | ;; @version 1 3 | 4 | (impl-trait .reserve-trait-v1.reserve-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_SHUTDOWN u17002) 11 | 12 | ;;------------------------------------- 13 | ;; Variables 14 | ;;------------------------------------- 15 | 16 | (define-data-var stx-stacking uint u0) 17 | (define-data-var stx-for-withdrawals uint u0) 18 | 19 | ;;------------------------------------- 20 | ;; Getters 21 | ;;------------------------------------- 22 | 23 | ;; Amount of STX locked for withdrawals 24 | (define-read-only (get-stx-for-withdrawals) 25 | (ok (var-get stx-for-withdrawals)) 26 | ) 27 | 28 | ;; Amount of STX currently used in stacking 29 | (define-read-only (get-stx-stacking) 30 | (ok (var-get stx-stacking)) 31 | ) 32 | 33 | ;; Contract balance 34 | (define-read-only (get-stx-balance) 35 | (ok (stx-get-balance (as-contract tx-sender))) 36 | ) 37 | 38 | ;; Total STX = contract balance + used in stacking 39 | (define-read-only (get-total-stx) 40 | (ok (+ (unwrap-panic (get-stx-balance)) (unwrap-panic (get-stx-stacking)))) 41 | ) 42 | 43 | ;;------------------------------------- 44 | ;; Withdrawals 45 | ;;------------------------------------- 46 | 47 | (define-public (lock-stx-for-withdrawal (stx-amount uint)) 48 | (begin 49 | (try! (contract-call? .dao check-is-protocol contract-caller)) 50 | 51 | (var-set stx-for-withdrawals (+ (var-get stx-for-withdrawals) stx-amount)) 52 | (ok stx-amount) 53 | ) 54 | ) 55 | 56 | (define-public (request-stx-for-withdrawal (requested-stx uint) (receiver principal)) 57 | (begin 58 | (try! (contract-call? .dao check-is-protocol contract-caller)) 59 | 60 | (var-set stx-for-withdrawals (- (var-get stx-for-withdrawals) requested-stx)) 61 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 62 | (ok requested-stx) 63 | ) 64 | ) 65 | 66 | ;;------------------------------------- 67 | ;; Stacking 68 | ;;------------------------------------- 69 | 70 | (define-public (request-stx-to-stack (requested-stx uint)) 71 | (let ( 72 | (receiver contract-caller) 73 | ) 74 | (try! (contract-call? .dao check-is-protocol contract-caller)) 75 | (try! (contract-call? .dao check-is-enabled)) 76 | 77 | (var-set stx-stacking (+ (unwrap-panic (get-stx-stacking)) requested-stx)) 78 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 79 | (ok requested-stx) 80 | ) 81 | ) 82 | 83 | (define-public (return-stx-from-stacking (stx-amount uint)) 84 | (begin 85 | (try! (contract-call? .dao check-is-protocol contract-caller)) 86 | (try! (contract-call? .dao check-is-enabled)) 87 | 88 | (var-set stx-stacking (- (unwrap-panic (get-stx-stacking)) stx-amount)) 89 | (try! (stx-transfer? stx-amount tx-sender (as-contract tx-sender))) 90 | (ok stx-amount) 91 | ) 92 | ) 93 | 94 | ;;------------------------------------- 95 | ;; Get STX 96 | ;;------------------------------------- 97 | 98 | (define-public (get-stx (requested-stx uint) (receiver principal)) 99 | (begin 100 | (try! (contract-call? .dao check-is-protocol contract-caller)) 101 | 102 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 103 | (ok requested-stx) 104 | ) 105 | ) 106 | -------------------------------------------------------------------------------- /contracts/tests/fake-staking.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Staking 2 | ;; @version 0 3 | ;; 4 | ;; Placeholder for a potential staking contract 5 | ;; 6 | 7 | (impl-trait .staking-trait-v1.staking-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Rewards - Add 11 | ;;------------------------------------- 12 | 13 | ;; Used by the commission contract to add STX 14 | (define-public (add-rewards (amount uint) (end-block uint)) 15 | (begin 16 | (try! (contract-call? .dao check-is-protocol contract-caller)) 17 | 18 | (ok u0) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /contracts/tests/governance-v0.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Governance V0 2 | ;; @version 0 3 | 4 | ;;------------------------------------- 5 | ;; Core 6 | ;;------------------------------------- 7 | 8 | (define-public (set-commission (new-commission uint)) 9 | (begin 10 | (try! (contract-call? .dao check-is-protocol tx-sender)) 11 | (as-contract (contract-call? .stacking-dao-core-v1 set-commission new-commission)) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /contracts/tests/marketplace-commission.clar: -------------------------------------------------------------------------------- 1 | 2 | (impl-trait .commission-trait.commission) 3 | 4 | (define-public (pay (tokenId uint) (price uint)) 5 | (ok true) 6 | ) 7 | -------------------------------------------------------------------------------- /contracts/tests/position-mock.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Position - Mock 2 | ;; @version 1 3 | 4 | (impl-trait .position-trait-v1.position-trait) 5 | 6 | (define-data-var mock-amount-user uint u100000000) 7 | (define-data-var mock-amount-reserve uint u200000000) 8 | 9 | (define-read-only (get-holder-balance (user principal)) 10 | (ok (var-get mock-amount-user)) 11 | ) 12 | 13 | (define-read-only (get-reserve-balance) 14 | (ok (var-get mock-amount-reserve)) 15 | ) 16 | 17 | (define-public (set-mock-amount-user (amount uint)) 18 | (begin 19 | (var-set mock-amount-user amount) 20 | (ok true) 21 | ) 22 | ) 23 | 24 | (define-public (set-mock-amount-reserve (amount uint)) 25 | (begin 26 | (var-set mock-amount-reserve amount) 27 | (ok true) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /contracts/tests/protocol-arkadiko-mock.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Arkadiko 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (ok (get-user-balance user)) 12 | ) 13 | 14 | ;;------------------------------------- 15 | ;; For testing only 16 | ;;------------------------------------- 17 | 18 | (define-map user-balance principal uint) 19 | 20 | (define-read-only (get-user-balance (user principal)) 21 | (default-to 22 | u0 23 | (map-get? user-balance user) 24 | ) 25 | ) 26 | 27 | (define-public (add-user-balance (balance uint)) 28 | (begin 29 | (try! (contract-call? .ststx-token transfer balance tx-sender (as-contract tx-sender) none)) 30 | 31 | (map-set user-balance tx-sender balance) 32 | (ok true) 33 | ) 34 | ) 35 | 36 | (define-public (remove-user-balance (balance uint)) 37 | (let ( 38 | (user tx-sender) 39 | ) 40 | (try! (as-contract (contract-call? .ststx-token transfer balance tx-sender user none))) 41 | 42 | (map-set user-balance user balance) 43 | (ok true) 44 | ) 45 | ) 46 | -------------------------------------------------------------------------------- /contracts/tests/protocol-zest-mock.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Zest 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (ok (get-user-balance user)) 12 | ) 13 | 14 | ;;------------------------------------- 15 | ;; For testing only 16 | ;;------------------------------------- 17 | 18 | (define-map user-balance principal uint) 19 | 20 | (define-read-only (get-user-balance (user principal)) 21 | (default-to 22 | u0 23 | (map-get? user-balance user) 24 | ) 25 | ) 26 | 27 | (define-public (add-user-balance (balance uint)) 28 | (begin 29 | (try! (contract-call? .ststx-token transfer balance tx-sender (as-contract tx-sender) none)) 30 | 31 | (map-set user-balance tx-sender balance) 32 | (ok true) 33 | ) 34 | ) 35 | 36 | (define-public (remove-user-balance (balance uint)) 37 | (let ( 38 | (user tx-sender) 39 | ) 40 | (try! (as-contract (contract-call? .ststx-token transfer balance tx-sender user none))) 41 | 42 | (map-set user-balance user balance) 43 | (ok true) 44 | ) 45 | ) 46 | -------------------------------------------------------------------------------- /contracts/tests/sbtc-token.clar: -------------------------------------------------------------------------------- 1 | (define-constant ERR_NOT_OWNER (err u4)) ;; `tx-sender` or `contract-caller` tried to move a token it does not own. 2 | (define-constant ERR_NOT_AUTH (err u5)) ;; `tx-sender` or `contract-caller` is not the protocol caller 3 | 4 | (define-fungible-token sbtc-token) 5 | (define-fungible-token sbtc-token-locked) 6 | 7 | (define-data-var token-name (string-ascii 32) "sBTC") 8 | (define-data-var token-symbol (string-ascii 10) "sBTC") 9 | (define-data-var token-uri (optional (string-utf8 256)) none) 10 | (define-constant token-decimals u8) 11 | 12 | ;; --- Protocol functions 13 | 14 | ;; #[allow(unchecked_data)] 15 | (define-public (protocol-transfer (amount uint) (sender principal) (recipient principal)) 16 | (begin 17 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 18 | (ft-transfer? sbtc-token amount sender recipient) 19 | ) 20 | ) 21 | 22 | ;; #[allow(unchecked_data)] 23 | (define-public (protocol-lock (amount uint) (owner principal)) 24 | (begin 25 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 26 | (try! (ft-burn? sbtc-token amount owner)) 27 | (ft-mint? sbtc-token-locked amount owner) 28 | ) 29 | ) 30 | 31 | ;; #[allow(unchecked_data)] 32 | (define-public (protocol-unlock (amount uint) (owner principal)) 33 | (begin 34 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 35 | (try! (ft-burn? sbtc-token-locked amount owner)) 36 | (ft-mint? sbtc-token amount owner) 37 | ) 38 | ) 39 | 40 | ;; #[allow(unchecked_data)] 41 | (define-public (protocol-mint (amount uint) (recipient principal)) 42 | (begin 43 | ;; (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 44 | (ft-mint? sbtc-token amount recipient) 45 | ) 46 | ) 47 | 48 | ;; #[allow(unchecked_data)] 49 | (define-public (protocol-burn (amount uint) (owner principal)) 50 | (begin 51 | ;; (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 52 | (ft-burn? sbtc-token amount owner) 53 | ) 54 | ) 55 | 56 | ;; #[allow(unchecked_data)] 57 | (define-public (protocol-burn-locked (amount uint) (owner principal)) 58 | (begin 59 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 60 | (ft-burn? sbtc-token-locked amount owner) 61 | ) 62 | ) 63 | 64 | ;; #[allow(unchecked_data)] 65 | (define-public (protocol-set-name (new-name (string-ascii 32))) 66 | (begin 67 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 68 | (ok (var-set token-name new-name)) 69 | ) 70 | ) 71 | 72 | ;; #[allow(unchecked_data)] 73 | (define-public (protocol-set-symbol (new-symbol (string-ascii 10))) 74 | (begin 75 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 76 | (ok (var-set token-symbol new-symbol)) 77 | ) 78 | ) 79 | 80 | ;; #[allow(unchecked_data)] 81 | (define-public (protocol-set-token-uri (new-uri (optional (string-utf8 256)))) 82 | (begin 83 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 84 | (ok (var-set token-uri new-uri)) 85 | ) 86 | ) 87 | 88 | ;; #[allow(unchecked_data)] 89 | (define-private (protocol-mint-many-iter (item {amount: uint, recipient: principal})) 90 | (ft-mint? sbtc-token (get amount item) (get recipient item)) 91 | ) 92 | 93 | ;; #[allow(unchecked_data)] 94 | (define-public (protocol-mint-many (recipients (list 200 {amount: uint, recipient: principal}))) 95 | (begin 96 | (try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller)) 97 | (ok (map protocol-mint-many-iter recipients)) 98 | ) 99 | ) 100 | 101 | ;; --- Public functions 102 | 103 | ;; sip-010-trait 104 | 105 | ;; #[allow(unchecked_data)] 106 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 107 | (begin 108 | (asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_NOT_OWNER) 109 | (ft-transfer? sbtc-token amount sender recipient) 110 | ) 111 | ) 112 | 113 | (define-read-only (get-name) 114 | (ok (var-get token-name)) 115 | ) 116 | 117 | (define-read-only (get-symbol) 118 | (ok (var-get token-symbol)) 119 | ) 120 | 121 | (define-read-only (get-decimals) 122 | (ok token-decimals) 123 | ) 124 | 125 | (define-read-only (get-balance (who principal)) 126 | (ok (+ (ft-get-balance sbtc-token who) (ft-get-balance sbtc-token-locked who))) 127 | ) 128 | 129 | (define-read-only (get-balance-available (who principal)) 130 | (ok (ft-get-balance sbtc-token who)) 131 | ) 132 | 133 | (define-read-only (get-balance-locked (who principal)) 134 | (ok (ft-get-balance sbtc-token-locked who)) 135 | ) 136 | 137 | (define-read-only (get-total-supply) 138 | (ok (+ (ft-get-supply sbtc-token) (ft-get-supply sbtc-token-locked))) 139 | ) 140 | 141 | (define-read-only (get-token-uri) 142 | (ok (var-get token-uri)) 143 | ) -------------------------------------------------------------------------------- /contracts/tests/swap-lp-token.clar: -------------------------------------------------------------------------------- 1 | ;; Bitflow Finance 2 | 3 | ;;;;;;;;;;;;;;;;;;;;; SIP 010 ;;;;;;;;;;;;;;;;;;;;;; 4 | (impl-trait .sip-010-trait-ft-standard.sip-010-trait) 5 | (use-trait lp-trait 'SPRP7MYBHSMFH5EGN3HGX6KNQ7QBHVTBPCE2RJDH.lp-trait.lp-trait) 6 | 7 | 8 | (define-fungible-token swap-lp-token) 9 | 10 | 11 | (define-constant CONTRACT-OWNER tx-sender) 12 | (define-constant ERR-UNAUTHORIZED-MINT (err u100)) 13 | (define-constant ERR-NOT-AUTHORIZED (err u101)) 14 | 15 | ;;vars 16 | (define-data-var token-uri (string-utf8 256) u"") 17 | (define-data-var approved-minter principal .swap) 18 | 19 | 20 | ;; --------------------------------------------------------- 21 | ;; SIP-10 Functions 22 | ;; --------------------------------------------------------- 23 | (define-read-only (adheres-to-sip-010) 24 | (ok true) 25 | ) 26 | 27 | (define-read-only (get-name) 28 | (ok "Swap-LP-Token") 29 | ) 30 | 31 | (define-read-only (get-symbol) 32 | (ok "Swap-LP-Token") 33 | ) 34 | 35 | (define-read-only (get-decimals) 36 | (ok u8) 37 | ) 38 | 39 | (define-read-only (get-balance (account principal)) 40 | (ok (ft-get-balance swap-lp-token account)) 41 | ) 42 | 43 | (define-read-only (get-total-supply) 44 | (ok (ft-get-supply swap-lp-token)) 45 | ) 46 | 47 | 48 | (define-read-only (get-token-uri) 49 | (ok (some (var-get token-uri))) 50 | ) 51 | 52 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 53 | (begin 54 | (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) 55 | 56 | (match (ft-transfer? swap-lp-token amount sender recipient) 57 | response (begin 58 | (print memo) 59 | (ok response) 60 | ) 61 | error (err error) 62 | ) 63 | ) 64 | ) 65 | 66 | (define-public (mint (who principal) (amount uint)) 67 | (begin 68 | (asserts! (is-eq contract-caller (var-get approved-minter)) ERR-UNAUTHORIZED-MINT) 69 | ;; amount & who are unchecked, but we let the contract owner mint to whoever they like for convenience 70 | ;; #[allow(unchecked_data)] 71 | (ft-mint? swap-lp-token amount who) 72 | ) 73 | ) 74 | 75 | 76 | (define-public (burn (burner principal) (amount uint)) 77 | (begin 78 | (asserts! (is-eq tx-sender burner) ERR-NOT-AUTHORIZED) 79 | (ft-burn? swap-lp-token amount burner) 80 | ) 81 | ) 82 | 83 | ;; Change the minter to any other principal, can only be called the current minter 84 | (define-public (set-minter (who principal)) 85 | (begin 86 | (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED) 87 | (ok (var-set approved-minter who)) 88 | ) 89 | ) 90 | 91 | (define-public (set-token-uri (new-uri (string-utf8 256))) 92 | (begin 93 | (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED) 94 | (ok (var-set token-uri new-uri)) 95 | ) 96 | ) -------------------------------------------------------------------------------- /contracts/tests/wstx-token.clar: -------------------------------------------------------------------------------- 1 | ;; Wrapped STX token 2 | ;; To have a SIP-010 representation of STX 3 | ;; 4 | 5 | (use-trait ft-trait .sip-010-trait-ft-standard.sip-010-trait) 6 | 7 | (define-fungible-token wstx) 8 | 9 | ;; --------------------------------------------------------- 10 | ;; Constants 11 | ;; --------------------------------------------------------- 12 | 13 | (define-constant ERR_NOT_AUTHORIZED u990401) 14 | 15 | ;; --------------------------------------------------------- 16 | ;; Variables 17 | ;; --------------------------------------------------------- 18 | 19 | (define-data-var token-uri (string-utf8 256) u"") 20 | (define-data-var protocol-addresses (list 20 principal) (list )) 21 | 22 | ;; --------------------------------------------------------- 23 | ;; SIP-10 Functions 24 | ;; --------------------------------------------------------- 25 | 26 | (define-read-only (get-total-supply) 27 | (ok (ft-get-supply wstx)) 28 | ) 29 | 30 | (define-read-only (get-name) 31 | (ok "Wrapped Stacks Token") 32 | ) 33 | 34 | (define-read-only (get-symbol) 35 | (ok "wSTX") 36 | ) 37 | 38 | (define-read-only (get-decimals) 39 | (ok u6) 40 | ) 41 | 42 | (define-read-only (get-balance (account principal)) 43 | (ok (ft-get-balance wstx account)) 44 | ) 45 | 46 | (define-read-only (get-token-uri) 47 | (ok (some (var-get token-uri))) 48 | ) 49 | 50 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 51 | (let ( 52 | (sender-is-protocol (is-protocol-address sender)) 53 | (recipient-is-protocol (is-protocol-address recipient)) 54 | ) 55 | (asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED)) 56 | 57 | (if (and (not sender-is-protocol) recipient-is-protocol) 58 | ;; User to Protocol 59 | (begin 60 | (try! (stx-transfer? amount sender (as-contract tx-sender))) 61 | (try! (ft-mint? wstx amount sender)) 62 | (try! (ft-transfer? wstx amount sender recipient)) 63 | ) 64 | 65 | (if (and sender-is-protocol (not recipient-is-protocol)) 66 | ;; Protocol to User 67 | (begin 68 | (try! (ft-transfer? wstx amount sender recipient)) 69 | (try! (ft-burn? wstx amount recipient)) 70 | (try! (as-contract (stx-transfer? amount tx-sender recipient))) 71 | ) 72 | ;; Other 73 | (try! (ft-transfer? wstx amount sender recipient)) 74 | ) 75 | ) 76 | 77 | (ok true) 78 | ) 79 | ) 80 | 81 | ;; --------------------------------------------------------- 82 | ;; Protocol 83 | ;; --------------------------------------------------------- 84 | 85 | (define-read-only (get-stx-balance (account principal)) 86 | (stx-get-balance account) 87 | ) 88 | 89 | (define-read-only (is-protocol-address (address principal)) 90 | (is-some (index-of (var-get protocol-addresses) address)) 91 | ) 92 | 93 | (define-read-only (get-protocol-addresses) 94 | (var-get protocol-addresses) 95 | ) 96 | 97 | ;; --------------------------------------------------------- 98 | ;; Wrap / Unwrap 99 | ;; --------------------------------------------------------- 100 | 101 | (define-public (wrap (amount uint)) 102 | (begin 103 | (try! (stx-transfer? amount tx-sender (as-contract tx-sender))) 104 | (ft-mint? wstx amount tx-sender) 105 | ) 106 | ) 107 | 108 | (define-public (unwrap (amount uint)) 109 | (let ( 110 | (recipient tx-sender) 111 | ) 112 | (try! (as-contract (stx-transfer? amount (as-contract tx-sender) recipient))) 113 | (ft-burn? wstx amount recipient) 114 | ) 115 | ) 116 | 117 | ;; --------------------------------------------------------- 118 | ;; Init 119 | ;; --------------------------------------------------------- 120 | 121 | (begin 122 | (var-set protocol-addresses (list 123 | .swap 124 | 'SP3GDP77BDSZ4VN2QQP057C9T6DRDDB6WGES6K9CP 125 | )) 126 | 127 | (try! (ft-mint? wstx u100000000000 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM)) 128 | ) -------------------------------------------------------------------------------- /contracts/version-1/commission-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Commission Trait 2 | ;; @version 1 3 | 4 | (use-trait staking-trait .staking-trait-v1.staking-trait) 5 | 6 | (define-trait commission-trait 7 | ( 8 | (add-commission ( uint) (response uint uint)) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /contracts/version-1/commission-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Commission 2 | ;; @version 1 3 | ;; 4 | ;; Part of the stacking rewards are captured as commission. 5 | ;; The commission is split between the protocol and stakers. 6 | 7 | (impl-trait .commission-trait-v1.commission-trait) 8 | (use-trait staking-trait .staking-trait-v1.staking-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant ERR_MIN_STAKING_BASISPOINTS u29001) 15 | 16 | (define-constant MIN_STAKING_BASISPOINTS u7000) ;; 70% in basis points 17 | 18 | ;;------------------------------------- 19 | ;; Variables 20 | ;;------------------------------------- 21 | 22 | (define-data-var staking-basispoints uint u0) ;; 0% in basis points, set later 23 | 24 | ;;------------------------------------- 25 | ;; Getters 26 | ;;------------------------------------- 27 | 28 | (define-read-only (get-staking-basispoints) 29 | (var-get staking-basispoints) 30 | ) 31 | 32 | ;;------------------------------------- 33 | ;; Helpers 34 | ;;------------------------------------- 35 | 36 | ;; Adding rewards for cycle X happens at the end of cycle X+1 37 | ;; These rewards are distributed per block during cycle X+2, 38 | ;; and the distribution ends at the end of cycle X+2 plus pox-prepare-length 39 | (define-read-only (get-cycle-rewards-end-block) 40 | (let ( 41 | (current-cycle (contract-call? .pox-3-mock current-pox-reward-cycle)) 42 | (cycle-end-block (contract-call? .pox-3-mock reward-cycle-to-burn-height (+ current-cycle u2))) 43 | (pox-prepare-length (get prepare-cycle-length (unwrap-panic (contract-call? .pox-3-mock get-pox-info)))) 44 | ) 45 | (+ cycle-end-block pox-prepare-length) 46 | ) 47 | ) 48 | 49 | ;;------------------------------------- 50 | ;; Trait 51 | ;;------------------------------------- 52 | 53 | ;; Used by core contract 54 | ;; Commission is split between stakers and protocol 55 | (define-public (add-commission (staking-contract ) (stx-amount uint)) 56 | (let ( 57 | (amount-for-staking (/ (* stx-amount (get-staking-basispoints)) u10000)) 58 | (amount-to-keep (- stx-amount amount-for-staking)) 59 | ) 60 | (try! (contract-call? .dao check-is-protocol (contract-of staking-contract))) 61 | 62 | ;; Send to stakers 63 | (if (> amount-for-staking u0) 64 | (try! (contract-call? staking-contract add-rewards amount-for-staking (get-cycle-rewards-end-block))) 65 | u0 66 | ) 67 | 68 | ;; Keep in contract 69 | (if (> amount-to-keep u0) 70 | (try! (stx-transfer? amount-to-keep tx-sender (as-contract tx-sender))) 71 | false 72 | ) 73 | 74 | (ok stx-amount) 75 | ) 76 | ) 77 | 78 | ;;------------------------------------- 79 | ;; Get commission 80 | ;;------------------------------------- 81 | 82 | (define-public (withdraw-commission) 83 | (let ( 84 | (receiver tx-sender) 85 | (amount (stx-get-balance (as-contract tx-sender))) 86 | ) 87 | (try! (contract-call? .dao check-is-protocol tx-sender)) 88 | 89 | (try! (as-contract (stx-transfer? amount tx-sender receiver))) 90 | 91 | (ok amount) 92 | ) 93 | ) 94 | 95 | ;;------------------------------------- 96 | ;; Admin 97 | ;;------------------------------------- 98 | 99 | (define-public (set-staking-basispoints (new-basispoints uint)) 100 | (begin 101 | (try! (contract-call? .dao check-is-protocol tx-sender)) 102 | (asserts! (>= new-basispoints MIN_STAKING_BASISPOINTS) (err ERR_MIN_STAKING_BASISPOINTS)) 103 | 104 | (var-set staking-basispoints new-basispoints) 105 | (ok true) 106 | ) 107 | ) 108 | -------------------------------------------------------------------------------- /contracts/version-1/reserve-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Reserve Trait 2 | ;; @version 1 3 | 4 | (define-trait reserve-trait 5 | ( 6 | ;; Getters 7 | (get-stx-stacking () (response uint uint)) 8 | (get-stx-for-withdrawals () (response uint uint)) 9 | (get-stx-balance () (response uint uint)) 10 | (get-total-stx () (response uint uint)) 11 | 12 | ;; Withdrawals 13 | (lock-stx-for-withdrawal (uint) (response uint uint)) 14 | (request-stx-for-withdrawal (uint principal) (response uint uint)) 15 | 16 | ;; Stacking 17 | (request-stx-to-stack (uint) (response uint uint)) 18 | (return-stx-from-stacking (uint) (response uint uint)) 19 | 20 | ;; Get STX 21 | (get-stx (uint principal) (response uint uint)) 22 | ) 23 | ) 24 | -------------------------------------------------------------------------------- /contracts/version-1/reserve-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Reserve 2 | ;; @version 1 3 | ;; 4 | ;; This contract holds all STX that is not stacking. 5 | ;; It also tracks the STX that is currently stacking, 6 | ;; and the STX needed for withdrawals after the current cycle. 7 | 8 | (impl-trait .reserve-trait-v1.reserve-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant ERR_SHUTDOWN u17002) 15 | (define-constant ERR_BLOCK_INFO u17003) 16 | 17 | ;;------------------------------------- 18 | ;; Variables 19 | ;;------------------------------------- 20 | 21 | (define-data-var stx-stacking uint u0) 22 | (define-data-var stx-for-withdrawals uint u0) 23 | 24 | ;;------------------------------------- 25 | ;; Getters 26 | ;;------------------------------------- 27 | 28 | ;; Amount of STX locked for withdrawals 29 | (define-read-only (get-stx-for-withdrawals) 30 | (ok (var-get stx-for-withdrawals)) 31 | ) 32 | 33 | ;; Amount of STX currently used in stacking 34 | (define-read-only (get-stx-stacking) 35 | (ok (var-get stx-stacking)) 36 | ) 37 | 38 | ;; Amount of STX used in stacking at given block 39 | (define-read-only (get-stx-stacking-at-block (block uint)) 40 | (at-block 41 | (unwrap! (get-block-info? id-header-hash block) (err ERR_BLOCK_INFO)) 42 | (get-stx-stacking) 43 | ) 44 | ) 45 | 46 | ;; Contract balance 47 | (define-read-only (get-stx-balance) 48 | (ok (stx-get-balance (as-contract tx-sender))) 49 | ) 50 | 51 | ;; Total STX = contract balance + used in stacking 52 | (define-read-only (get-total-stx) 53 | (ok (+ (unwrap-panic (get-stx-balance)) (unwrap-panic (get-stx-stacking)))) 54 | ) 55 | 56 | ;;------------------------------------- 57 | ;; Withdrawals 58 | ;;------------------------------------- 59 | 60 | (define-public (lock-stx-for-withdrawal (stx-amount uint)) 61 | (begin 62 | (try! (contract-call? .dao check-is-protocol contract-caller)) 63 | 64 | (var-set stx-for-withdrawals (+ (var-get stx-for-withdrawals) stx-amount)) 65 | (ok stx-amount) 66 | ) 67 | ) 68 | 69 | (define-public (request-stx-for-withdrawal (requested-stx uint) (receiver principal)) 70 | (begin 71 | (try! (contract-call? .dao check-is-protocol contract-caller)) 72 | 73 | (var-set stx-for-withdrawals (- (var-get stx-for-withdrawals) requested-stx)) 74 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 75 | (ok requested-stx) 76 | ) 77 | ) 78 | 79 | ;;------------------------------------- 80 | ;; Stacking 81 | ;;------------------------------------- 82 | 83 | (define-public (request-stx-to-stack (requested-stx uint)) 84 | (let ( 85 | (receiver contract-caller) 86 | ) 87 | (try! (contract-call? .dao check-is-protocol contract-caller)) 88 | (try! (contract-call? .dao check-is-enabled)) 89 | 90 | (var-set stx-stacking (+ (unwrap-panic (get-stx-stacking)) requested-stx)) 91 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 92 | (ok requested-stx) 93 | ) 94 | ) 95 | 96 | (define-public (return-stx-from-stacking (stx-amount uint)) 97 | (begin 98 | (try! (contract-call? .dao check-is-protocol contract-caller)) 99 | (try! (contract-call? .dao check-is-enabled)) 100 | 101 | (var-set stx-stacking (- (unwrap-panic (get-stx-stacking)) stx-amount)) 102 | (try! (stx-transfer? stx-amount tx-sender (as-contract tx-sender))) 103 | (ok stx-amount) 104 | ) 105 | ) 106 | 107 | ;;------------------------------------- 108 | ;; Get STX 109 | ;;------------------------------------- 110 | 111 | (define-public (get-stx (requested-stx uint) (receiver principal)) 112 | (begin 113 | (try! (contract-call? .dao check-is-protocol contract-caller)) 114 | 115 | (try! (as-contract (stx-transfer? requested-stx tx-sender receiver))) 116 | (ok requested-stx) 117 | ) 118 | ) 119 | -------------------------------------------------------------------------------- /contracts/version-1/staking-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Staking Trait 2 | ;; @version 1 3 | 4 | (define-trait staking-trait 5 | ( 6 | (add-rewards (uint uint) (response uint uint)) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /contracts/version-1/staking-v0.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Staking 2 | ;; @version 0 3 | ;; 4 | ;; Placeholder for a potential staking contract 5 | ;; 6 | 7 | (impl-trait .staking-trait-v1.staking-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Rewards - Add 11 | ;;------------------------------------- 12 | 13 | ;; Used by the commission contract to add STX 14 | (define-public (add-rewards (amount uint) (end-block uint)) 15 | (begin 16 | (try! (contract-call? .dao check-is-protocol contract-caller)) 17 | 18 | (ok u0) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /contracts/version-2/commission-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Commission 2 | ;; @version 2 3 | ;; 4 | ;; Part of the stacking rewards are captured as commission. 5 | ;; The commission is split between the protocol and stakers. 6 | 7 | (impl-trait .commission-trait-v1.commission-trait) 8 | (use-trait staking-trait .staking-trait-v1.staking-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant ERR_MIN_STAKING_BASISPOINTS u29001) 15 | 16 | (define-constant MIN_STAKING_BASISPOINTS u7000) ;; 70% in basis points 17 | (define-constant DENOMINATOR_BPS u10000) 18 | 19 | ;;------------------------------------- 20 | ;; Variables 21 | ;;------------------------------------- 22 | 23 | (define-data-var staking-basispoints uint u0) ;; 0% in basis points, set later 24 | 25 | ;;------------------------------------- 26 | ;; Getters 27 | ;;------------------------------------- 28 | 29 | (define-read-only (get-staking-basispoints) 30 | (var-get staking-basispoints) 31 | ) 32 | 33 | ;;------------------------------------- 34 | ;; Helpers 35 | ;;------------------------------------- 36 | 37 | ;; Adding rewards for cycle X happens at the end of cycle X+1 38 | ;; These rewards are distributed per block during cycle X+2, 39 | ;; and the distribution ends at the end of cycle X+2 plus pox-prepare-length 40 | (define-read-only (get-cycle-rewards-end-block) 41 | (let ( 42 | (cycle-end-block (reward-cycle-to-burn-height (+ (get-pox-cycle) u2))) 43 | (pox-prepare-length (get-prepare-cycle-length)) 44 | ) 45 | (+ cycle-end-block pox-prepare-length) 46 | ) 47 | ) 48 | 49 | ;;------------------------------------- 50 | ;; Trait 51 | ;;------------------------------------- 52 | 53 | ;; Used by core contract 54 | ;; Commission is split between stakers and protocol 55 | (define-public (add-commission (staking-contract ) (stx-amount uint)) 56 | (let ( 57 | (amount-for-staking (/ (* stx-amount (get-staking-basispoints)) DENOMINATOR_BPS)) 58 | (amount-to-keep (- stx-amount amount-for-staking)) 59 | ) 60 | (try! (contract-call? .dao check-is-protocol (contract-of staking-contract))) 61 | 62 | ;; Send to stakers 63 | (if (> amount-for-staking u0) 64 | (try! (contract-call? staking-contract add-rewards amount-for-staking (get-cycle-rewards-end-block))) 65 | u0 66 | ) 67 | 68 | ;; Keep in contract 69 | (if (> amount-to-keep u0) 70 | (try! (stx-transfer? amount-to-keep tx-sender (as-contract tx-sender))) 71 | false 72 | ) 73 | 74 | (ok stx-amount) 75 | ) 76 | ) 77 | 78 | ;;------------------------------------- 79 | ;; Get commission 80 | ;;------------------------------------- 81 | 82 | (define-public (withdraw-commission) 83 | (let ( 84 | (receiver tx-sender) 85 | (amount (stx-get-balance (as-contract tx-sender))) 86 | ) 87 | (try! (contract-call? .dao check-is-protocol tx-sender)) 88 | 89 | (try! (as-contract (stx-transfer? amount tx-sender receiver))) 90 | 91 | (ok amount) 92 | ) 93 | ) 94 | 95 | ;;------------------------------------- 96 | ;; Admin 97 | ;;------------------------------------- 98 | 99 | (define-public (set-staking-basispoints (new-basispoints uint)) 100 | (begin 101 | (try! (contract-call? .dao check-is-protocol tx-sender)) 102 | (asserts! (>= new-basispoints MIN_STAKING_BASISPOINTS) (err ERR_MIN_STAKING_BASISPOINTS)) 103 | 104 | (var-set staking-basispoints new-basispoints) 105 | (ok true) 106 | ) 107 | ) 108 | 109 | ;;------------------------------------- 110 | ;; PoX Helpers 111 | ;;------------------------------------- 112 | 113 | (define-read-only (get-pox-cycle) 114 | (if is-in-mainnet 115 | (contract-call? 'SP000000000000000000002Q6VF78.pox-4 current-pox-reward-cycle) 116 | (contract-call? .pox-4-mock current-pox-reward-cycle) 117 | ) 118 | ) 119 | 120 | (define-read-only (reward-cycle-to-burn-height (cycle-id uint)) 121 | (if is-in-mainnet 122 | (contract-call? 'SP000000000000000000002Q6VF78.pox-4 reward-cycle-to-burn-height cycle-id) 123 | (contract-call? .pox-4-mock reward-cycle-to-burn-height cycle-id) 124 | ) 125 | ) 126 | 127 | (define-read-only (get-prepare-cycle-length) 128 | (if is-in-mainnet 129 | (get prepare-cycle-length (unwrap-panic (contract-call? 'SP000000000000000000002Q6VF78.pox-4 get-pox-info))) 130 | (get prepare-cycle-length (unwrap-panic (contract-call? .pox-4-mock get-pox-info))) 131 | ) 132 | ) -------------------------------------------------------------------------------- /contracts/version-2/data-core-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Data Core 2 | ;; @version 1 3 | ;; 4 | ;; Helper methods to get STX per stSTX. 5 | ;; Storing withdrawal offset & withdrawal NFT info. 6 | 7 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Constants 11 | ;;------------------------------------- 12 | 13 | (define-constant DENOMINATOR_6 u1000000) 14 | 15 | ;;------------------------------------- 16 | ;; STX per stSTX 17 | ;;------------------------------------- 18 | 19 | (define-public (get-stx-per-ststx (reserve-contract )) 20 | (let ( 21 | (stx-amount (try! (contract-call? reserve-contract get-total-stx))) 22 | ) 23 | (try! (contract-call? .dao check-is-protocol (contract-of reserve-contract))) 24 | (ok (get-stx-per-ststx-helper stx-amount)) 25 | ) 26 | ) 27 | 28 | (define-read-only (get-stx-per-ststx-helper (stx-amount uint)) 29 | (let ( 30 | (ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply))) 31 | ) 32 | (if (is-eq ststx-supply u0) 33 | DENOMINATOR_6 34 | (/ (* stx-amount DENOMINATOR_6) ststx-supply) 35 | ) 36 | ) 37 | ) 38 | 39 | ;;------------------------------------- 40 | ;; Cycle Withdraw Offset 41 | ;;------------------------------------- 42 | 43 | ;; In the last X blocks of the cycle 44 | (define-data-var cycle-withdraw-offset uint (if is-in-mainnet u288 u10)) ;; 2 days 45 | 46 | (define-read-only (get-cycle-withdraw-offset) 47 | (var-get cycle-withdraw-offset) 48 | ) 49 | 50 | (define-public (set-cycle-withdraw-offset (offset uint)) 51 | (begin 52 | (try! (contract-call? .dao check-is-protocol contract-caller)) 53 | 54 | (var-set cycle-withdraw-offset offset) 55 | (ok true) 56 | ) 57 | ) 58 | 59 | ;;------------------------------------- 60 | ;; Withdrawal NFT 61 | ;;------------------------------------- 62 | 63 | (define-map migrated-nfts uint bool) 64 | 65 | (define-map withdrawals-by-nft 66 | { 67 | nft-id: uint 68 | } 69 | { 70 | unlock-burn-height: uint, 71 | stx-amount: uint, 72 | ststx-amount: uint 73 | } 74 | ) 75 | 76 | (define-read-only (get-migrated-nft (nft-id uint)) 77 | (default-to 78 | false 79 | (map-get? migrated-nfts nft-id) 80 | ) 81 | ) 82 | 83 | (define-read-only (get-withdrawals-by-nft (nft-id uint)) 84 | (default-to 85 | (if (get-migrated-nft nft-id) 86 | ;; Already migrated 87 | { 88 | unlock-burn-height: u0, 89 | stx-amount: u0, 90 | ststx-amount: u0 91 | } 92 | 93 | ;; Default to info from stacking-dao-core-v1. 94 | (let ( 95 | (prev-info (contract-call? .stacking-dao-core-v1 get-withdrawals-by-nft nft-id)) 96 | (cycle-start-block (if (> (get cycle-id prev-info) u0) 97 | ;; Need to translate cycle-id into unlock-burn-height 98 | (reward-cycle-to-burn-height (get cycle-id prev-info)) 99 | u0 100 | )) 101 | ) 102 | { unlock-burn-height: cycle-start-block, stx-amount: (get stx-amount prev-info), ststx-amount: (get ststx-amount prev-info) } 103 | ) 104 | ) 105 | 106 | (map-get? withdrawals-by-nft { nft-id: nft-id }) 107 | ) 108 | ) 109 | 110 | (define-public (set-withdrawals-by-nft (nft-id uint) (stx-amount uint) (ststx-amount uint) (unlock-burn-height uint)) 111 | (begin 112 | (try! (contract-call? .dao check-is-protocol contract-caller)) 113 | 114 | (map-set migrated-nfts nft-id true) 115 | (map-set withdrawals-by-nft { nft-id: nft-id } { stx-amount: stx-amount, ststx-amount: ststx-amount, unlock-burn-height: unlock-burn-height }) 116 | 117 | (print { action: "set-withdrawals-by-nft", data: { nft-id: nft-id, stx-amount: stx-amount, ststx-amount: ststx-amount, unlock-burn-height: unlock-burn-height, block-height: block-height } }) 118 | (ok true) 119 | ) 120 | ) 121 | 122 | (define-public (delete-withdrawals-by-nft (nft-id uint)) 123 | (begin 124 | (try! (contract-call? .dao check-is-protocol contract-caller)) 125 | 126 | (map-set migrated-nfts nft-id true) 127 | (map-delete withdrawals-by-nft { nft-id: nft-id }) 128 | 129 | (print { action: "delete-withdrawals-by-nft", data: { nft-id: nft-id, block-height: block-height } }) 130 | (ok true) 131 | ) 132 | ) 133 | 134 | ;;------------------------------------- 135 | ;; PoX Helpers 136 | ;;------------------------------------- 137 | 138 | (define-read-only (reward-cycle-to-burn-height (cycle-id uint)) 139 | (if is-in-mainnet 140 | (contract-call? 'SP000000000000000000002Q6VF78.pox-4 reward-cycle-to-burn-height cycle-id) 141 | (contract-call? .pox-4-mock reward-cycle-to-burn-height cycle-id) 142 | ) 143 | ) 144 | -------------------------------------------------------------------------------- /contracts/version-2/data-direct-stacking-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Data Direct Stacking 2 | ;; @version 1 3 | ;; 4 | ;; Tracks direct stacking info for user and pools. 5 | ;; If user transfers stSTX to another wallet or unsupported protocol, 6 | ;; the direct stacking amount can be decrased. 7 | 8 | ;;------------------------------------- 9 | ;; Constants 10 | ;;------------------------------------- 11 | 12 | (define-constant ERR_DEPENDENCE_TOO_HIGH u243001) 13 | 14 | (define-constant DENOMINATOR_BPS u10000) 15 | 16 | ;;------------------------------------- 17 | ;; Init 18 | ;;------------------------------------- 19 | 20 | (begin 21 | (if is-in-mainnet 22 | (var-set supported-protocols (list 23 | .protocol-arkadiko-v1 24 | .protocol-bitflow-v1 25 | )) 26 | (var-set supported-protocols (list 27 | .protocol-arkadiko-mock 28 | )) 29 | ) 30 | ) 31 | 32 | ;;------------------------------------- 33 | ;; Direct Stacking 34 | ;;------------------------------------- 35 | 36 | ;; This % of normal stacking total will be divided according to direct stacking rates 37 | (define-data-var direct-stacking-dependence uint u2000) ;; 20% in bps 38 | 39 | (define-data-var total-direct-stacking uint u0) 40 | 41 | ;; Map pool to amount used for direct stacking 42 | (define-map direct-stacking-pool-amount principal uint) 43 | 44 | ;; User info 45 | (define-map direct-stacking-user 46 | principal 47 | { 48 | pool: principal, 49 | amount: uint, 50 | } 51 | ) 52 | 53 | (define-read-only (get-direct-stacking-dependence) 54 | (var-get direct-stacking-dependence) 55 | ) 56 | 57 | (define-read-only (get-total-direct-stacking) 58 | (var-get total-direct-stacking) 59 | ) 60 | 61 | (define-read-only (get-direct-stacking-pool-amount (pool principal)) 62 | (default-to 63 | u0 64 | (map-get? direct-stacking-pool-amount pool) 65 | ) 66 | ) 67 | 68 | (define-read-only (get-direct-stacking-user (user principal)) 69 | (map-get? direct-stacking-user user) 70 | ) 71 | 72 | (define-public (set-direct-stacking-dependence (dependence uint)) 73 | (begin 74 | (try! (contract-call? .dao check-is-protocol contract-caller)) 75 | (asserts! (<= dependence DENOMINATOR_BPS) (err ERR_DEPENDENCE_TOO_HIGH)) 76 | 77 | 78 | (var-set direct-stacking-dependence dependence) 79 | (ok true) 80 | ) 81 | ) 82 | 83 | (define-public (set-total-direct-stacking (amount uint)) 84 | (begin 85 | (try! (contract-call? .dao check-is-protocol contract-caller)) 86 | 87 | (var-set total-direct-stacking amount) 88 | 89 | (print { action: "set-total-direct-stacking", data: { amount: amount, block-height: block-height } }) 90 | (ok true) 91 | ) 92 | ) 93 | 94 | (define-public (set-direct-stacking-pool-amount (pool principal) (amount uint)) 95 | (begin 96 | (try! (contract-call? .dao check-is-protocol contract-caller)) 97 | 98 | (map-set direct-stacking-pool-amount pool amount) 99 | 100 | (print { action: "set-direct-stacking-pool-amount", data: { pool: pool, amount: amount, block-height: block-height } }) 101 | (ok true) 102 | ) 103 | ) 104 | 105 | (define-public (set-direct-stacking-user (user principal) (pool principal) (amount uint)) 106 | (begin 107 | (try! (contract-call? .dao check-is-protocol contract-caller)) 108 | 109 | (map-set direct-stacking-user user { pool: pool, amount: amount }) 110 | 111 | (print { action: "set-direct-stacking-user", data: { user: user, pool: pool, amount: amount, block-height: block-height } }) 112 | (ok true) 113 | ) 114 | ) 115 | 116 | (define-public (delete-direct-stacking-user (user principal)) 117 | (begin 118 | (try! (contract-call? .dao check-is-protocol contract-caller)) 119 | 120 | (map-delete direct-stacking-user user) 121 | 122 | (print { action: "delete-direct-stacking-user", data: { user: user, block-height: block-height } }) 123 | (ok true) 124 | ) 125 | ) 126 | 127 | ;;------------------------------------- 128 | ;; Supported Protocols 129 | ;;------------------------------------- 130 | 131 | (define-data-var supported-protocols (list 50 principal) (list)) 132 | 133 | (define-read-only (get-supported-protocols) 134 | (var-get supported-protocols) 135 | ) 136 | 137 | (define-public (set-supported-protocols (protocols (list 50 principal))) 138 | (begin 139 | (try! (contract-call? .dao check-is-protocol contract-caller)) 140 | 141 | (var-set supported-protocols protocols) 142 | (ok true) 143 | ) 144 | ) 145 | -------------------------------------------------------------------------------- /contracts/version-2/direct-helpers-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Direct STacking Helpers Trait 2 | ;; @version 1 3 | 4 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 5 | 6 | (define-trait direct-helpers-trait 7 | ( 8 | (add-direct-stacking (principal (optional principal) uint) (response bool uint)) 9 | (subtract-direct-stacking (principal uint) (response bool uint)) 10 | (stop-direct-stacking (principal) (response bool uint)) 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /contracts/version-2/protocol-arkadiko-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Arkadiko 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (let ( 12 | (vault (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-vaults-data-v1-1 get-vault user .ststx-token))) 13 | ) 14 | ;; Check status 15 | (if (is-eq (get status vault) u101) 16 | (ok (get collateral vault)) 17 | (ok u0) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /contracts/version-2/protocol-bitflow-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - BitFlow 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; BitFlow 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (let ( 12 | ;; Wallet 13 | (balance (unwrap-panic (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-2 get-balance user))) 14 | 15 | ;; Staked 16 | (user-data (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.earn-stx-ststx-v-1-2 get-user-data 17 | .ststx-token 18 | 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-2 19 | user 20 | )) 21 | (staked (if (is-some user-data) 22 | (get total-currently-staked (unwrap-panic user-data)) 23 | u0 24 | )) 25 | 26 | ;; Total user 27 | (user-total (+ balance staked)) 28 | 29 | ;; Total LP tokens 30 | (lp-total-supply (unwrap-panic (contract-call? 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stx-ststx-lp-token-v-1-2 get-total-supply))) 31 | 32 | ;; Pool balance stSTX 33 | (lp-balance-ststx (unwrap-panic (contract-call? .ststx-token get-balance 'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stableswap-stx-ststx-v-1-2))) 34 | 35 | ;; User share 36 | (user-lp-share (/ (* user-total u1000000000000) lp-total-supply)) 37 | ) 38 | (ok (/ (* user-lp-share lp-balance-ststx) u1000000000000)) 39 | ) 40 | ) 41 | -------------------------------------------------------------------------------- /contracts/version-2/protocol-hermetica-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Zest 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (let ( 12 | (token-balance (unwrap-panic (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.token-ststx-earn-v1 get-balance user))) 13 | (ratio (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-underlying-per-token)) 14 | (wallet-amount (/ (* token-balance ratio) u1000000)) 15 | 16 | (queued-amount (get-queued-hermetica-helper user)) 17 | ) 18 | (ok (+ wallet-amount queued-amount)) 19 | ) 20 | ) 21 | 22 | (define-read-only (get-queued-hermetica-helper (user principal)) 23 | (let ( 24 | (deposit-claims (get deposit-claims (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-claims-for-address user))) 25 | ) 26 | (fold + (map get-claim-iter deposit-claims) u0) 27 | ) 28 | ) 29 | 30 | (define-read-only (get-claim-iter (claim-id uint)) 31 | (let ( 32 | (claim (contract-call? 'SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.vault-ststx-earn-v1 get-claim claim-id)) 33 | ) 34 | (get underlying-amount (unwrap-panic claim)) 35 | ) 36 | ) -------------------------------------------------------------------------------- /contracts/version-2/protocol-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol Trait 2 | ;; @version 1 3 | 4 | (define-trait protocol-trait 5 | ( 6 | (get-balance (principal) (response uint uint)) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /contracts/version-2/protocol-velar-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Zest 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (let ( 12 | (total-lp-supply (unwrap-panic (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.ststx-aeusdc get-total-supply))) 13 | (user-wallet (unwrap-panic (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.ststx-aeusdc get-balance user))) 14 | (user-staked (get end (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.farming-ststx-aeusdc-core get-user-staked user))) 15 | (user-total (+ user-wallet user-staked)) 16 | 17 | (pool-info (contract-call? 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-core do-get-pool u8)) 18 | ) 19 | (ok (/ (* user-total (get reserve0 pool-info)) total-lp-supply)) 20 | ) 21 | ) 22 | -------------------------------------------------------------------------------- /contracts/version-2/protocol-zest-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Protocol - Zest 2 | ;; @version 1 3 | 4 | (impl-trait .protocol-trait-v1.protocol-trait) 5 | 6 | ;;------------------------------------- 7 | ;; Arkadiko 8 | ;;------------------------------------- 9 | 10 | (define-read-only (get-balance (user principal)) 11 | (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststx-v1-2 get-balance user) 12 | ) 13 | -------------------------------------------------------------------------------- /contracts/version-2/rewards-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Rewards Trait 2 | ;; @version 1 3 | 4 | (define-trait rewards-trait 5 | ( 6 | (add-rewards (principal uint) (response bool uint)) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /contracts/version-2/stacking-delegate-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Stacking Delegate Trait 2 | ;; @version 1 3 | 4 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 5 | (use-trait rewards-trait .rewards-trait-v1.rewards-trait) 6 | 7 | (define-trait stacking-delegate-trait 8 | ( 9 | (delegate-stx (uint principal (optional uint)) (response bool uint)) 10 | (revoke-delegate-stx () (response bool uint)) 11 | 12 | (request-stx-to-stack ( uint) (response uint uint)) 13 | (return-stx-from-stacking ( uint) (response uint uint)) 14 | 15 | (handle-rewards (principal uint ) (response uint uint)) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /contracts/version-2/strategy-v3-delegates-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Strategy V3 Delegates V1 2 | ;; @version 1 3 | ;; 4 | ;; Calculate delegation amounts for given pool. 5 | ;; If there is an inflow, use the reach-target algorithm to calculate stacking amounts per delegate. 6 | ;; If there is an outflow, use lowest-combination algorithm to calculate which delegates to stop 7 | 8 | ;;------------------------------------- 9 | ;; Constants 10 | ;;------------------------------------- 11 | 12 | (define-constant DENOMINATOR_BPS u10000) 13 | 14 | ;;------------------------------------- 15 | ;; Core 16 | ;;------------------------------------- 17 | 18 | (define-read-only (calculate-stacking-per-delegate (pool principal) (total-to-stack uint)) 19 | (let ( 20 | (locked (calculate-locked-for-pool pool)) 21 | ) 22 | (if (>= total-to-stack locked) 23 | (calculate-inflow pool total-to-stack) 24 | (calculate-outflow pool total-to-stack (- locked total-to-stack)) 25 | ) 26 | ) 27 | ) 28 | 29 | (define-read-only (map-delegate-stacking-amount (delegate principal) (stacking-amount uint)) 30 | { delegate: delegate, stacking-amount: stacking-amount } 31 | ) 32 | 33 | ;;------------------------------------- 34 | ;; Inflow 35 | ;;------------------------------------- 36 | 37 | (define-read-only (calculate-inflow (pool principal) (total-to-stack uint)) 38 | (let ( 39 | (delegates (contract-call? .data-pools-v1 get-pool-delegates pool)) 40 | (targets (map calculate-stacking-target-for-delegate delegates (list-30-uint total-to-stack))) 41 | (locked (map get-locked-stx delegates)) 42 | (stacking-amounts (contract-call? .strategy-v3-algo-v1 calculate-reach-target targets locked)) 43 | ) 44 | (map map-delegate-stacking-amount delegates stacking-amounts) 45 | ) 46 | ) 47 | 48 | (define-read-only (calculate-stacking-target-for-delegate (delegate principal) (total-to-stack uint)) 49 | (let ( 50 | (delegate-share (contract-call? .data-pools-v1 get-delegate-share delegate)) 51 | ) 52 | (/ (* total-to-stack delegate-share) DENOMINATOR_BPS) 53 | ) 54 | ) 55 | 56 | ;;------------------------------------- 57 | ;; Outflow 58 | ;;------------------------------------- 59 | 60 | (define-read-only (calculate-outflow (pool principal) (total-to-stack uint) (outflow uint)) 61 | (let ( 62 | (delegates (contract-call? .data-pools-v1 get-pool-delegates pool)) 63 | (locked (map get-locked-stx delegates)) 64 | (stacking-amounts (contract-call? .strategy-v3-algo-v1 calculate-lowest-combination outflow locked)) 65 | ) 66 | (map map-delegate-stacking-amount delegates stacking-amounts) 67 | ) 68 | ) 69 | 70 | ;;------------------------------------- 71 | ;; Locked 72 | ;;------------------------------------- 73 | 74 | (define-read-only (calculate-locked-for-pool (pool principal)) 75 | (let ( 76 | (delegates (contract-call? .data-pools-v1 get-pool-delegates pool)) 77 | ) 78 | (fold + (map get-locked-stx delegates) u0) 79 | ) 80 | ) 81 | 82 | ;;------------------------------------- 83 | ;; Helpers 84 | ;;------------------------------------- 85 | 86 | (define-read-only (list-30-uint (item uint)) 87 | (list item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item) 88 | ) 89 | 90 | (define-read-only (get-locked-stx (account principal)) 91 | (get locked (get-stx-account account)) 92 | ) 93 | 94 | (define-read-only (get-stx-account (account principal)) 95 | (if is-in-mainnet 96 | (stx-account account) 97 | (contract-call? .pox-4-mock stx-account-mock account) 98 | ) 99 | ) 100 | -------------------------------------------------------------------------------- /contracts/version-3/commission-btc-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Commission stSTXbtc 2 | ;; @version 1 3 | ;; 4 | ;; Part of the stacking rewards are captured as commission. 5 | ;; The commission can be split between the protocol and stakers. 6 | 7 | (impl-trait .commission-trait-v1.commission-trait) 8 | (use-trait staking-trait .staking-trait-v1.staking-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant DENOMINATOR_BPS u10000) 15 | 16 | ;;------------------------------------- 17 | ;; Variables 18 | ;;------------------------------------- 19 | 20 | (define-data-var staking-basispoints uint u0) ;; 0% in basis points, set later 21 | 22 | ;;------------------------------------- 23 | ;; Getters 24 | ;;------------------------------------- 25 | 26 | (define-read-only (get-staking-basispoints) 27 | (var-get staking-basispoints) 28 | ) 29 | 30 | ;;------------------------------------- 31 | ;; Helpers 32 | ;;------------------------------------- 33 | 34 | ;; Adding rewards for cycle X happens at the end of cycle X+1 35 | ;; These rewards are distributed per block during cycle X+2, 36 | ;; and the distribution ends at the end of cycle X+2 plus pox-prepare-length 37 | (define-read-only (get-cycle-rewards-end-block) 38 | (let ( 39 | (cycle-end-block (reward-cycle-to-burn-height (+ (get-pox-cycle) u2))) 40 | (pox-prepare-length (get-prepare-cycle-length)) 41 | ) 42 | (+ cycle-end-block pox-prepare-length) 43 | ) 44 | ) 45 | 46 | ;;------------------------------------- 47 | ;; Trait 48 | ;;------------------------------------- 49 | 50 | ;; Used by core contract 51 | ;; Commission is split between stakers and protocol 52 | (define-public (add-commission (staking-contract ) (sbtc-amount uint)) 53 | (let ( 54 | (amount-for-staking (/ (* sbtc-amount (get-staking-basispoints)) DENOMINATOR_BPS)) 55 | (amount-to-keep (- sbtc-amount amount-for-staking)) 56 | ) 57 | (try! (contract-call? .dao check-is-protocol (contract-of staking-contract))) 58 | 59 | ;; Send to stakers 60 | (if (> amount-for-staking u0) 61 | (try! (contract-call? staking-contract add-rewards amount-for-staking (get-cycle-rewards-end-block))) 62 | u0 63 | ) 64 | 65 | ;; Keep in contract 66 | (if (> amount-to-keep u0) 67 | ;; TODO: update with mainnet sbtc token 68 | (try! (contract-call? .sbtc-token transfer amount-to-keep contract-caller (as-contract tx-sender) none)) 69 | false 70 | ) 71 | 72 | (ok sbtc-amount) 73 | ) 74 | ) 75 | 76 | ;;------------------------------------- 77 | ;; Get commission 78 | ;;------------------------------------- 79 | 80 | (define-public (withdraw-commission (amount uint) (receiver principal)) 81 | (begin 82 | (try! (contract-call? .dao check-is-protocol contract-caller)) 83 | 84 | ;; TODO: update with mainnet sbtc token 85 | (try! (as-contract (contract-call? .sbtc-token transfer amount tx-sender receiver none))) 86 | 87 | (ok amount) 88 | ) 89 | ) 90 | 91 | ;;------------------------------------- 92 | ;; Admin 93 | ;;------------------------------------- 94 | 95 | (define-public (set-staking-basispoints (new-basispoints uint)) 96 | (begin 97 | (try! (contract-call? .dao check-is-protocol tx-sender)) 98 | 99 | (var-set staking-basispoints new-basispoints) 100 | (ok true) 101 | ) 102 | ) 103 | 104 | ;;------------------------------------- 105 | ;; PoX Helpers 106 | ;;------------------------------------- 107 | 108 | (define-read-only (get-pox-cycle) 109 | (if is-in-mainnet 110 | (contract-call? 'SP000000000000000000002Q6VF78.pox-4 current-pox-reward-cycle) 111 | (contract-call? .pox-4-mock current-pox-reward-cycle) 112 | ) 113 | ) 114 | 115 | (define-read-only (reward-cycle-to-burn-height (cycle-id uint)) 116 | (if is-in-mainnet 117 | (contract-call? 'SP000000000000000000002Q6VF78.pox-4 reward-cycle-to-burn-height cycle-id) 118 | (contract-call? .pox-4-mock reward-cycle-to-burn-height cycle-id) 119 | ) 120 | ) 121 | 122 | (define-read-only (get-prepare-cycle-length) 123 | (if is-in-mainnet 124 | (get prepare-cycle-length (unwrap-panic (contract-call? 'SP000000000000000000002Q6VF78.pox-4 get-pox-info))) 125 | (get prepare-cycle-length (unwrap-panic (contract-call? .pox-4-mock get-pox-info))) 126 | ) 127 | ) -------------------------------------------------------------------------------- /contracts/version-3/data-core-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Data Core 2 | ;; @version 2 3 | ;; 4 | ;; Helper methods to get STX per stSTX. 5 | ;; Storing stSTXbtc withdrawal NFT info. 6 | 7 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Constants 11 | ;;------------------------------------- 12 | 13 | (define-constant DENOMINATOR_6 u1000000) 14 | 15 | ;;------------------------------------- 16 | ;; STX per stSTX 17 | ;;------------------------------------- 18 | 19 | (define-public (get-stx-per-ststx (reserve-contract )) 20 | (let ( 21 | (total-stx-amount (try! (contract-call? reserve-contract get-total-stx))) 22 | (ststxbtc-supply (unwrap-panic (contract-call? .ststxbtc-token get-total-supply))) 23 | (stx-for-ststx (- total-stx-amount ststxbtc-supply)) 24 | ) 25 | (try! (contract-call? .dao check-is-protocol (contract-of reserve-contract))) 26 | (ok (get-stx-per-ststx-helper stx-for-ststx)) 27 | ) 28 | ) 29 | 30 | (define-read-only (get-stx-per-ststx-helper (stx-amount uint)) 31 | (let ( 32 | (ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply))) 33 | ) 34 | (if (is-eq ststx-supply u0) 35 | DENOMINATOR_6 36 | (/ (* stx-amount DENOMINATOR_6) ststx-supply) 37 | ) 38 | ) 39 | ) 40 | 41 | ;;------------------------------------- 42 | ;; Cycle Withdraw Offset 43 | ;;------------------------------------- 44 | 45 | ;; Use data-core-v1 46 | 47 | ;;------------------------------------- 48 | ;; Withdrawal NFT (stSTX) 49 | ;;------------------------------------- 50 | 51 | ;; Use data-core-v1 52 | 53 | ;;------------------------------------- 54 | ;; Cycle Withdraw Inset 55 | ;;------------------------------------- 56 | 57 | ;; In the last X blocks of the cycle 58 | (define-data-var cycle-withdraw-inset uint (if is-in-mainnet u50 u3)) 59 | 60 | (define-read-only (get-cycle-withdraw-inset) 61 | (var-get cycle-withdraw-inset) 62 | ) 63 | 64 | (define-public (set-cycle-withdraw-inset (inset uint)) 65 | (begin 66 | (try! (contract-call? .dao check-is-protocol contract-caller)) 67 | 68 | (var-set cycle-withdraw-inset inset) 69 | (ok true) 70 | ) 71 | ) 72 | 73 | ;;------------------------------------- 74 | ;; Withdrawal NFT (stSTXbtc) 75 | ;;------------------------------------- 76 | 77 | (define-map ststxbtc-withdrawals-by-nft 78 | { 79 | nft-id: uint 80 | } 81 | { 82 | unlock-burn-height: uint, 83 | stx-amount: uint 84 | } 85 | ) 86 | 87 | (define-read-only (get-ststxbtc-withdrawals-by-nft (nft-id uint)) 88 | (default-to 89 | { 90 | unlock-burn-height: u0, 91 | stx-amount: u0, 92 | } 93 | (map-get? ststxbtc-withdrawals-by-nft { nft-id: nft-id }) 94 | ) 95 | ) 96 | 97 | (define-public (set-ststxbtc-withdrawals-by-nft (nft-id uint) (stx-amount uint) (unlock-burn-height uint)) 98 | (begin 99 | (try! (contract-call? .dao check-is-protocol contract-caller)) 100 | 101 | (map-set ststxbtc-withdrawals-by-nft { nft-id: nft-id } { stx-amount: stx-amount, unlock-burn-height: unlock-burn-height }) 102 | 103 | (print { action: "set-ststxbtc-withdrawals-by-nft", data: { nft-id: nft-id, stx-amount: stx-amount, unlock-burn-height: unlock-burn-height, block-height: block-height } }) 104 | (ok true) 105 | ) 106 | ) 107 | 108 | (define-public (delete-ststxbtc-withdrawals-by-nft (nft-id uint)) 109 | (begin 110 | (try! (contract-call? .dao check-is-protocol contract-caller)) 111 | 112 | (map-delete ststxbtc-withdrawals-by-nft { nft-id: nft-id }) 113 | 114 | (print { action: "delete-ststxbtc-withdrawals-by-nft", data: { nft-id: nft-id, block-height: block-height } }) 115 | (ok true) 116 | ) 117 | ) 118 | 119 | ;;------------------------------------- 120 | ;; Idle 121 | ;;------------------------------------- 122 | 123 | ;; Cycle to STX amount 124 | (define-map stx-idle uint uint) 125 | 126 | (define-read-only (get-stx-idle (cycle uint)) 127 | (default-to 128 | u0 129 | (map-get? stx-idle cycle) 130 | ) 131 | ) 132 | 133 | (define-public (set-stx-idle (cycle uint) (amount uint)) 134 | (begin 135 | (try! (contract-call? .dao check-is-protocol contract-caller)) 136 | 137 | (map-set stx-idle cycle amount) 138 | (ok true) 139 | ) 140 | ) 141 | 142 | (define-public (increase-stx-idle (cycle uint) (amount uint)) 143 | (let ( 144 | (current-amount (get-stx-idle cycle)) 145 | ) 146 | (try! (contract-call? .dao check-is-protocol contract-caller)) 147 | 148 | (map-set stx-idle cycle (+ current-amount amount)) 149 | (ok true) 150 | ) 151 | ) 152 | 153 | (define-public (decrease-stx-idle (cycle uint) (amount uint)) 154 | (let ( 155 | (current-amount (get-stx-idle cycle)) 156 | ) 157 | (try! (contract-call? .dao check-is-protocol contract-caller)) 158 | 159 | (map-set stx-idle cycle (- current-amount amount)) 160 | (ok true) 161 | ) 162 | ) -------------------------------------------------------------------------------- /contracts/version-3/data-core-v3.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Data Core 2 | ;; @version 2 3 | ;; 4 | ;; Helper methods to get STX per stSTX. 5 | ;; Storing stSTXbtc withdrawal NFT info. 6 | 7 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 8 | 9 | ;;------------------------------------- 10 | ;; Constants 11 | ;;------------------------------------- 12 | 13 | (define-constant DENOMINATOR_6 u1000000) 14 | 15 | ;;------------------------------------- 16 | ;; STX per stSTX 17 | ;;------------------------------------- 18 | 19 | (define-public (get-stx-per-ststx (reserve-contract )) 20 | (let ( 21 | (total-stx-amount (try! (contract-call? reserve-contract get-total-stx))) 22 | (ststxbtc-supply (unwrap-panic (contract-call? .ststxbtc-token get-total-supply))) 23 | (ststxbtc-supply-v2 (unwrap-panic (contract-call? .ststxbtc-token-v2 get-total-supply))) 24 | (stx-for-ststx (- total-stx-amount ststxbtc-supply ststxbtc-supply-v2)) 25 | ) 26 | (try! (contract-call? .dao check-is-protocol (contract-of reserve-contract))) 27 | (ok (get-stx-per-ststx-helper stx-for-ststx)) 28 | ) 29 | ) 30 | 31 | (define-read-only (get-stx-per-ststx-helper (stx-amount uint)) 32 | (let ( 33 | (ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply))) 34 | ) 35 | (if (is-eq ststx-supply u0) 36 | DENOMINATOR_6 37 | (/ (* stx-amount DENOMINATOR_6) ststx-supply) 38 | ) 39 | ) 40 | ) 41 | -------------------------------------------------------------------------------- /contracts/version-3/position-trait-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Position Trait 2 | ;; @version 1 3 | 4 | (define-trait position-trait 5 | ( 6 | (get-holder-balance (principal) (response uint uint)) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /contracts/version-3/position-zest-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Supported Position - Zest 2 | ;; @version 1 3 | 4 | (impl-trait .position-trait-v1.position-trait) 5 | 6 | (define-read-only (get-holder-balance (user principal)) 7 | ;; TODO: Update for new token 8 | (ok (contract-call? 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zststxbtc-token get-balance user)) 9 | ) -------------------------------------------------------------------------------- /contracts/version-3/ststxbtc-migration-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract stSTXbtc Migration 2 | ;; @version 1 3 | ;; 4 | ;; Migrates stSTXbtc tokens from v1 to v2 5 | 6 | ;;------------------------------------- 7 | ;; Constants 8 | ;;------------------------------------- 9 | 10 | (define-constant ERR_UNSUPPORTED_POSITION u10401) 11 | 12 | ;;------------------------------------- 13 | ;; Migration 14 | ;;------------------------------------- 15 | 16 | (define-public (migrate-ststxbtc (addresses (list 200 principal))) 17 | (begin 18 | (try! (contract-call? .dao check-is-protocol contract-caller)) 19 | 20 | (ok (map migrate-address addresses)) 21 | ) 22 | ) 23 | 24 | (define-private (migrate-address (address principal)) 25 | (let ( 26 | (balance (unwrap-panic (contract-call? .ststxbtc-token get-balance address))) 27 | (supported-position (contract-call? .ststxbtc-tracking-data get-supported-positions address)) 28 | ) 29 | (asserts! (not (get active supported-position)) (err ERR_UNSUPPORTED_POSITION)) 30 | (if (> balance u0) 31 | (begin 32 | (try! (contract-call? .ststxbtc-token burn-for-protocol balance address)) 33 | (try! (contract-call? .ststxbtc-token-v2 mint-for-protocol balance address)) 34 | (ok true) 35 | ) 36 | (ok true) 37 | ) 38 | ) 39 | ) 40 | 41 | (define-public (migrate-self) 42 | (let ( 43 | (balance (unwrap-panic (contract-call? .ststxbtc-token get-balance contract-caller))) 44 | ) 45 | (if (> balance u0) 46 | (begin 47 | (try! (contract-call? .ststxbtc-token burn-for-protocol balance contract-caller)) 48 | (try! (contract-call? .ststxbtc-token-v2 mint-for-protocol balance contract-caller)) 49 | (ok true) 50 | ) 51 | (ok true) 52 | ) 53 | ) 54 | ) 55 | -------------------------------------------------------------------------------- /contracts/version-3/swap-ststx-ststxbtc-v1.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Swap stSTX / stSTXbtc 2 | ;; @version 1 3 | ;; 4 | ;; User can swap stSTX for stSTXbtc and vice versa. 5 | ;; Original tokens are burned and new tokens are minted. 6 | ;; Underlying STX remains the same. 7 | 8 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant ERR_LOW_SUPPLY u903001) 15 | 16 | (define-constant DENOMINATOR_6 u1000000) 17 | 18 | ;;------------------------------------- 19 | ;; Swaps 20 | ;;------------------------------------- 21 | 22 | (define-public (swap-ststx-for-ststxbtc (ststx-amount uint) (reserve ) ) 23 | (let ( 24 | (stx-ststx (try! (contract-call? .data-core-v2 get-stx-per-ststx reserve))) 25 | (stx-amount (/ (* ststx-amount stx-ststx) DENOMINATOR_6)) 26 | ) 27 | (try! (contract-call? .dao check-is-protocol (contract-of reserve))) 28 | 29 | (try! (contract-call? .ststxbtc-token mint-for-protocol stx-amount tx-sender)) 30 | (try! (contract-call? .ststx-token burn-for-protocol ststx-amount tx-sender)) 31 | 32 | (asserts! (>= (unwrap-panic (contract-call? .ststx-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 33 | (asserts! (>= (unwrap-panic (contract-call? .ststxbtc-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 34 | 35 | (ok stx-amount) 36 | ) 37 | ) 38 | 39 | (define-public (swap-ststxbtc-for-ststx (ststxbtc-amount uint) (reserve ) ) 40 | (let ( 41 | (stx-ststx (try! (contract-call? .data-core-v2 get-stx-per-ststx reserve))) 42 | (ststx-amount (/ (* ststxbtc-amount DENOMINATOR_6) stx-ststx)) 43 | ) 44 | (try! (contract-call? .dao check-is-protocol (contract-of reserve))) 45 | 46 | (try! (contract-call? .ststx-token mint-for-protocol ststx-amount tx-sender)) 47 | (try! (contract-call? .ststxbtc-token burn-for-protocol ststxbtc-amount tx-sender)) 48 | 49 | (asserts! (>= (unwrap-panic (contract-call? .ststx-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 50 | (asserts! (>= (unwrap-panic (contract-call? .ststxbtc-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 51 | 52 | (ok ststx-amount) 53 | ) 54 | ) 55 | -------------------------------------------------------------------------------- /contracts/version-3/swap-ststx-ststxbtc-v2.clar: -------------------------------------------------------------------------------- 1 | ;; @contract Swap stSTX / stSTXbtc 2 | ;; @version 2 3 | ;; 4 | ;; User can swap stSTX for stSTXbtc and vice versa. 5 | ;; Original tokens are burned and new tokens are minted. 6 | ;; Underlying STX remains the same. 7 | 8 | (use-trait reserve-trait .reserve-trait-v1.reserve-trait) 9 | 10 | ;;------------------------------------- 11 | ;; Constants 12 | ;;------------------------------------- 13 | 14 | (define-constant ERR_LOW_SUPPLY u903001) 15 | 16 | (define-constant DENOMINATOR_6 u1000000) 17 | 18 | ;;------------------------------------- 19 | ;; Swaps 20 | ;;------------------------------------- 21 | 22 | (define-public (swap-ststx-for-ststxbtc (ststx-amount uint) (reserve ) ) 23 | (let ( 24 | (stx-ststx (try! (contract-call? .data-core-v3 get-stx-per-ststx reserve))) 25 | (stx-amount (/ (* ststx-amount stx-ststx) DENOMINATOR_6)) 26 | ) 27 | (try! (contract-call? .dao check-is-protocol (contract-of reserve))) 28 | 29 | (try! (contract-call? .ststxbtc-token-v2 mint-for-protocol stx-amount tx-sender)) 30 | (try! (contract-call? .ststx-token burn-for-protocol ststx-amount tx-sender)) 31 | 32 | (asserts! (>= (unwrap-panic (contract-call? .ststx-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 33 | (asserts! (>= (unwrap-panic (contract-call? .ststxbtc-token-v2 get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 34 | 35 | (ok stx-amount) 36 | ) 37 | ) 38 | 39 | (define-public (swap-ststxbtc-for-ststx (ststxbtc-amount uint) (reserve ) ) 40 | (let ( 41 | (stx-ststx (try! (contract-call? .data-core-v3 get-stx-per-ststx reserve))) 42 | (ststx-amount (/ (* ststxbtc-amount DENOMINATOR_6) stx-ststx)) 43 | ) 44 | (try! (contract-call? .dao check-is-protocol (contract-of reserve))) 45 | 46 | (try! (contract-call? .ststx-token mint-for-protocol ststx-amount tx-sender)) 47 | (try! (contract-call? .ststxbtc-token-v2 burn-for-protocol ststxbtc-amount tx-sender)) 48 | 49 | (asserts! (>= (unwrap-panic (contract-call? .ststx-token get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 50 | (asserts! (>= (unwrap-panic (contract-call? .ststxbtc-token-v2 get-total-supply)) u1000000) (err ERR_LOW_SUPPLY)) 51 | 52 | (ok ststx-amount) 53 | ) 54 | ) 55 | -------------------------------------------------------------------------------- /contracts/version-x/sdao-token.clar: -------------------------------------------------------------------------------- 1 | (impl-trait .sip-010-trait-ft-standard.sip-010-trait) 2 | 3 | ;; Defines the sDAO token according to the SIP010 Standard 4 | (define-fungible-token sdao) 5 | 6 | (define-constant ERR_NOT_AUTHORIZED u1401) 7 | 8 | ;;------------------------------------- 9 | ;; Variables 10 | ;;------------------------------------- 11 | 12 | (define-data-var token-uri (string-utf8 256) u"") 13 | 14 | ;;------------------------------------- 15 | ;; SIP-010 16 | ;;------------------------------------- 17 | 18 | (define-read-only (get-total-supply) 19 | (ok (ft-get-supply sdao)) 20 | ) 21 | 22 | (define-read-only (get-name) 23 | (ok "StackingDAO Token") 24 | ) 25 | 26 | (define-read-only (get-symbol) 27 | (ok "sDAO") 28 | ) 29 | 30 | (define-read-only (get-decimals) 31 | (ok u6) 32 | ) 33 | 34 | (define-read-only (get-balance (account principal)) 35 | (ok (ft-get-balance sdao account)) 36 | ) 37 | 38 | (define-read-only (get-token-uri) 39 | (ok (some (var-get token-uri))) 40 | ) 41 | 42 | (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) 43 | (begin 44 | (asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED)) 45 | 46 | (match (ft-transfer? sdao amount sender recipient) 47 | response (begin 48 | (print memo) 49 | (ok response) 50 | ) 51 | error (err error) 52 | ) 53 | ) 54 | ) 55 | 56 | ;;------------------------------------- 57 | ;; Admin 58 | ;;------------------------------------- 59 | 60 | (define-public (set-token-uri (value (string-utf8 256))) 61 | (begin 62 | (try! (contract-call? .dao check-is-protocol tx-sender)) 63 | (ok (var-set token-uri value)) 64 | ) 65 | ) 66 | 67 | ;;------------------------------------- 68 | ;; Mint / Burn 69 | ;;------------------------------------- 70 | 71 | ;; Mint method 72 | (define-public (mint-for-protocol (amount uint) (recipient principal)) 73 | (begin 74 | (try! (contract-call? .dao check-is-protocol contract-caller)) 75 | (ft-mint? sdao amount recipient) 76 | ) 77 | ) 78 | 79 | ;; Burn method 80 | (define-public (burn-for-protocol (amount uint) (sender principal)) 81 | (begin 82 | (try! (contract-call? .dao check-is-protocol contract-caller)) 83 | (ft-burn? sdao amount sender) 84 | ) 85 | ) 86 | 87 | ;; Burn external 88 | (define-public (burn (amount uint)) 89 | (begin 90 | (ft-burn? sdao amount tx-sender) 91 | ) 92 | ) 93 | -------------------------------------------------------------------------------- /tests/helpers/cc-redemption_test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Account, 3 | Chain, 4 | Clarinet, 5 | Tx, 6 | types, 7 | } from "https://deno.land/x/clarinet/index.ts"; 8 | import { qualifiedName } from "../wrappers/tests-utils.ts"; 9 | 10 | import { Reserve } from "../wrappers/reserve-helpers.ts"; 11 | 12 | //------------------------------------- 13 | // Core 14 | //------------------------------------- 15 | 16 | Clarinet.test({ 17 | name: "cc-redemption: deposit and withdraw for normal stacking", 18 | async fn(chain: Chain, accounts: Map) { 19 | let deployer = accounts.get("deployer")!; 20 | 21 | let reserve = new Reserve(chain, deployer); 22 | 23 | let call = await reserve.getTotalStx(); 24 | call.result.expectOk().expectUintWithDecimals(0); 25 | 26 | let block = chain.mineBlock([ 27 | Tx.contractCall( 28 | "stacking-dao-core-v2", 29 | "deposit", 30 | [ 31 | types.principal(qualifiedName("reserve-v1")), 32 | types.principal(qualifiedName("commission-v2")), 33 | types.principal(qualifiedName("staking-v1")), 34 | types.principal(qualifiedName("direct-helpers-v2")), 35 | types.uint(100 * 1000000), 36 | types.none(), 37 | types.none(), 38 | ], 39 | deployer.address 40 | ), 41 | ]); 42 | block.receipts[0].result.expectOk().expectUintWithDecimals(100); 43 | 44 | call = await reserve.getTotalStx(); 45 | call.result.expectOk().expectUintWithDecimals(100); 46 | }, 47 | }); 48 | -------------------------------------------------------------------------------- /tests/keeper-jobs/return-stx-job_test.ts: -------------------------------------------------------------------------------- 1 | import { Account, Chain, Clarinet, Tx, types } from "https://deno.land/x/clarinet/index.ts"; 2 | import { qualifiedName } from '../wrappers/tests-utils.ts'; 3 | qualifiedName("") 4 | 5 | import { CoreV1 as Core } from '../wrappers/stacking-dao-core-helpers.ts'; 6 | import { ReturnStxJob } from '../wrappers/return-stx-job-helpers.ts'; 7 | import { Reserve } from '../wrappers/reserve-helpers.ts'; 8 | 9 | //------------------------------------- 10 | // Return STX Job 11 | //------------------------------------- 12 | 13 | Clarinet.test({ 14 | name: "return-stx-job: run job", 15 | async fn(chain: Chain, accounts: Map) { 16 | let deployer = accounts.get("deployer")!; 17 | 18 | let returnStxJob = new ReturnStxJob(chain, deployer); 19 | let core = new Core(chain, deployer); 20 | let reserve = new Reserve(chain, deployer); 21 | 22 | // Transfer 200 STX to reserve 23 | let block = chain.mineBlock([ 24 | Tx.transferSTX(200 * 1000000, qualifiedName("reserve-v1"), deployer.address) 25 | ]); 26 | block.receipts[0].result.expectOk().expectBool(true); 27 | 28 | // Request 200 STX to stack 29 | // Needed so we can actually return in later in the test 30 | let result = await reserve.requestStxToStack(deployer, 200); 31 | result.expectOk().expectUintWithDecimals(200); 32 | 33 | // 200 STX stacking 34 | let call:any = await reserve.getStxStacking(); 35 | call.result.expectOk().expectUintWithDecimals(200); 36 | 37 | // Stacker does not have STX 38 | call = returnStxJob.checkJob(); 39 | call.result.expectOk().expectBool(false); 40 | 41 | // Reserve has no STX left 42 | call = core.getStxBalance(qualifiedName("reserve-v1")); 43 | call.result.expectUintWithDecimals(0); 44 | 45 | // Transfer 10 STX to stacker-1 46 | block = chain.mineBlock([ 47 | Tx.transferSTX(10 * 1000000, qualifiedName("stacker-1"), deployer.address) 48 | ]); 49 | block.receipts[0].result.expectOk().expectBool(true); 50 | 51 | // Stacker has STX, can return to reserve 52 | call = returnStxJob.checkJob(); 53 | call.result.expectOk().expectBool(true); 54 | 55 | // Run job to return STX to reserve 56 | result = await returnStxJob.runJob(deployer); 57 | result.expectOk().expectBool(true); 58 | 59 | // Should not run again 60 | call = returnStxJob.checkJob(); 61 | call.result.expectOk().expectBool(false); 62 | 63 | // 10 STX back in reserve 64 | call = core.getStxBalance(qualifiedName("reserve-v1")); 65 | call.result.expectUintWithDecimals(10); 66 | 67 | // 10 STX returned 68 | call = await reserve.getStxStacking(); 69 | call.result.expectOk().expectUintWithDecimals(200 - 10); 70 | } 71 | }); 72 | -------------------------------------------------------------------------------- /tests/keeper-jobs/rewards-job_test.ts: -------------------------------------------------------------------------------- 1 | import { Account, Chain, Clarinet, Tx, types } from "https://deno.land/x/clarinet/index.ts"; 2 | import { qualifiedName, REWARD_CYCLE_LENGTH } from '../wrappers/tests-utils.ts'; 3 | qualifiedName("") 4 | 5 | import { CoreV1 as Core } from '../wrappers/stacking-dao-core-helpers.ts'; 6 | import { RewardsJob } from '../wrappers/rewards-job-helpers.ts'; 7 | 8 | //------------------------------------- 9 | // Rewards Job 10 | //------------------------------------- 11 | 12 | Clarinet.test({ 13 | name: "rewards-job: run job", 14 | async fn(chain: Chain, accounts: Map) { 15 | let deployer = accounts.get("deployer")!; 16 | 17 | let rewardsJob = new RewardsJob(chain, deployer); 18 | let core = new Core(chain, deployer); 19 | 20 | let call:any = rewardsJob.checkJob(); 21 | call.result.expectOk().expectBool(false); 22 | 23 | // Transfer 100 STX to contract 24 | let block = chain.mineBlock([ 25 | Tx.transferSTX(100 * 1000000, qualifiedName("rewards-job-v1"), deployer.address) 26 | ]); 27 | block.receipts[0].result.expectOk().expectBool(true); 28 | 29 | // 30 | // Advance to cycle 1 31 | // 32 | 33 | chain.mineEmptyBlockUntil(REWARD_CYCLE_LENGTH+1); 34 | 35 | // 36 | // At beginning of PoX cycle 37 | // 38 | call = core.getPoxCycle(); 39 | call.result.expectUint(1); 40 | 41 | call = core.getNextWithdrawCycle(); 42 | call.result.expectUint(2); 43 | 44 | call = rewardsJob.checkJob(); 45 | call.result.expectOk().expectBool(false); 46 | 47 | // 48 | // At end of PoX cycle 49 | // 50 | 51 | chain.mineEmptyBlockUntil(REWARD_CYCLE_LENGTH + REWARD_CYCLE_LENGTH-1); 52 | 53 | call = core.getPoxCycle(); 54 | call.result.expectUint(1); 55 | 56 | call = core.getNextWithdrawCycle(); 57 | call.result.expectUint(3); 58 | 59 | call = rewardsJob.checkJob(); 60 | call.result.expectOk().expectBool(true); 61 | 62 | // 63 | // Run job 64 | // 65 | 66 | call = core.getStxBalance(qualifiedName("rewards-job-v1")); 67 | call.result.expectUintWithDecimals(100); 68 | 69 | call = core.getStxBalance(qualifiedName("reserve-v1")); 70 | call.result.expectUintWithDecimals(0); 71 | 72 | call = core.getStxBalance(qualifiedName("commission-v1")); 73 | call.result.expectUintWithDecimals(0); 74 | 75 | call = core.getCycleInfo(0) 76 | call.result.expectTuple()["commission"].expectUintWithDecimals(0); 77 | call.result.expectTuple()["rewards"].expectUintWithDecimals(0); 78 | 79 | let result = await rewardsJob.runJob(deployer); 80 | result.expectOk().expectBool(true); 81 | 82 | call = core.getStxBalance(qualifiedName("rewards-job-v1")); 83 | call.result.expectUintWithDecimals(0); 84 | 85 | call = core.getStxBalance(qualifiedName("reserve-v1")); 86 | call.result.expectUintWithDecimals(95); 87 | 88 | call = core.getStxBalance(qualifiedName("commission-v1")); 89 | call.result.expectUintWithDecimals(5); 90 | 91 | call = core.getCycleInfo(1) 92 | call.result.expectTuple()["commission"].expectUintWithDecimals(5); 93 | call.result.expectTuple()["rewards"].expectUintWithDecimals(95); 94 | 95 | } 96 | }); 97 | 98 | //------------------------------------- 99 | // Admin 100 | //------------------------------------- 101 | 102 | Clarinet.test({ 103 | name: "rewards-job: protocol can retreive tokens", 104 | async fn(chain: Chain, accounts: Map) { 105 | let deployer = accounts.get("deployer")!; 106 | 107 | let rewardsJob = new RewardsJob(chain, deployer); 108 | let core = new Core(chain, deployer); 109 | 110 | // Transfer 100 STX to contract 111 | let block = chain.mineBlock([ 112 | Tx.transferSTX(100 * 1000000, qualifiedName("rewards-job-v1"), deployer.address) 113 | ]); 114 | block.receipts[0].result.expectOk().expectBool(true); 115 | 116 | // Contract balances 117 | let call = core.getStxBalance(qualifiedName("rewards-job-v1")); 118 | call.result.expectUintWithDecimals(100); 119 | 120 | // Retreive tokens 121 | let result = await rewardsJob.retreiveStxTokens(deployer, 10, deployer.address); 122 | result.expectOk().expectUintWithDecimals(10); 123 | 124 | // Contract balances 125 | call = core.getStxBalance(qualifiedName("rewards-job-v1")); 126 | call.result.expectUintWithDecimals(90); 127 | 128 | } 129 | }); 130 | 131 | //------------------------------------- 132 | // Access 133 | //------------------------------------- 134 | 135 | Clarinet.test({ 136 | name: "rewards-job: only protocol can retreive tokens", 137 | async fn(chain: Chain, accounts: Map) { 138 | let deployer = accounts.get("deployer")!; 139 | let wallet_1 = accounts.get("wallet_1")!; 140 | 141 | let rewardsJob = new RewardsJob(chain, deployer); 142 | 143 | let result = await rewardsJob.retreiveStxTokens(wallet_1, 10, wallet_1.address); 144 | result.expectErr().expectUint(20003); 145 | } 146 | }); 147 | -------------------------------------------------------------------------------- /tests/version-1/commission_test.ts: -------------------------------------------------------------------------------- 1 | import { Account, Chain, Clarinet, Tx, types } from "https://deno.land/x/clarinet/index.ts"; 2 | 3 | import { CoreV1 as Core } from '../wrappers/stacking-dao-core-helpers.ts'; 4 | import { Commission } from '../wrappers/commission-helpers.ts'; 5 | 6 | //------------------------------------- 7 | // Core 8 | //------------------------------------- 9 | 10 | Clarinet.test({ 11 | name: "commission: can add and withdraw commission", 12 | async fn(chain: Chain, accounts: Map) { 13 | let deployer = accounts.get("deployer")!; 14 | let wallet_1 = accounts.get("wallet_1")!; 15 | 16 | let core = new Core(chain, deployer); 17 | let commission = new Commission(chain, deployer); 18 | 19 | let result = await commission.setStakingBasisPoints(deployer, 0.8); 20 | result.expectOk().expectBool(true); 21 | 22 | let call = await core.getStxBalance(wallet_1.address); 23 | call.result.expectUintWithDecimals(100000000); 24 | 25 | result = await commission.addCommission(wallet_1, 5000); 26 | result.expectOk().expectUintWithDecimals(5000); 27 | 28 | call = await core.getStxBalance(wallet_1.address); 29 | call.result.expectUintWithDecimals(99995000); 30 | 31 | call = await core.getStxBalance(deployer.address); 32 | call.result.expectUintWithDecimals(100000000); 33 | 34 | // Can withdraw 20% of total commission 35 | // 20% of 5000 STX = 1000 STX 36 | result = await commission.withdrawCommission(deployer); 37 | result.expectOk().expectUintWithDecimals(1000); 38 | 39 | call = await core.getStxBalance(deployer.address); 40 | call.result.expectUintWithDecimals(100001000); 41 | } 42 | }); 43 | 44 | Clarinet.test({ 45 | name: "commission: can set staking percentage", 46 | async fn(chain: Chain, accounts: Map) { 47 | let deployer = accounts.get("deployer")!; 48 | let wallet_1 = accounts.get("wallet_1")!; 49 | 50 | let core = new Core(chain, deployer); 51 | let commission = new Commission(chain, deployer); 52 | 53 | let result = await commission.setStakingBasisPoints(deployer, 0.8); 54 | result.expectOk().expectBool(true); 55 | 56 | result = await commission.addCommission(wallet_1, 5000); 57 | result.expectOk().expectUintWithDecimals(5000); 58 | 59 | // Can withdraw 20% of total commission 60 | // 20% of 5000 STX = 1000 STX 61 | result = await commission.withdrawCommission(deployer); 62 | result.expectOk().expectUintWithDecimals(1000); 63 | 64 | result = await commission.setStakingBasisPoints(deployer, 0.7); 65 | result.expectOk().expectBool(true); 66 | 67 | result = await commission.addCommission(wallet_1, 5000); 68 | result.expectOk().expectUintWithDecimals(5000); 69 | 70 | // Can withdraw 30% of total commission 71 | // 30% of 5000 STX = 1500 STX 72 | result = await commission.withdrawCommission(deployer); 73 | result.expectOk().expectUintWithDecimals(1500); 74 | } 75 | }); 76 | 77 | //------------------------------------- 78 | // Errors 79 | //------------------------------------- 80 | 81 | Clarinet.test({ 82 | name: "commission: can not set staking percentage below minimum", 83 | async fn(chain: Chain, accounts: Map) { 84 | let deployer = accounts.get("deployer")!; 85 | 86 | let commission = new Commission(chain, deployer); 87 | 88 | let result = await commission.setStakingBasisPoints(deployer, 0.6); 89 | result.expectErr().expectUint(29001); 90 | } 91 | }); 92 | 93 | //------------------------------------- 94 | // Access 95 | //------------------------------------- 96 | 97 | Clarinet.test({ 98 | name: "commission: only protocol can withdraw commission", 99 | async fn(chain: Chain, accounts: Map) { 100 | let deployer = accounts.get("deployer")!; 101 | let wallet_1 = accounts.get("wallet_1")!; 102 | 103 | let commission = new Commission(chain, deployer); 104 | 105 | let result = await commission.withdrawCommission(wallet_1); 106 | result.expectErr().expectUint(20003); 107 | } 108 | }); 109 | 110 | Clarinet.test({ 111 | name: "commission: only protocol can set staking percentage", 112 | async fn(chain: Chain, accounts: Map) { 113 | let deployer = accounts.get("deployer")!; 114 | let wallet_1 = accounts.get("wallet_1")!; 115 | 116 | let commission = new Commission(chain, deployer); 117 | 118 | let result = await commission.setStakingBasisPoints(wallet_1, 10); 119 | result.expectErr().expectUint(20003); 120 | } 121 | }); 122 | -------------------------------------------------------------------------------- /tests/wrappers/commission-btc-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // Commission BTC 11 | // --------------------------------------------------------- 12 | 13 | class CommissionBtc { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | getStakingBasisPoints() { 23 | return this.chain.callReadOnlyFn( 24 | "commission-btc-v1", 25 | "get-staking-basispoints", 26 | [], 27 | this.deployer.address 28 | ); 29 | } 30 | 31 | getCycleRewardsEndBlock() { 32 | return this.chain.callReadOnlyFn( 33 | "commission-btc-v1", 34 | "get-cycle-rewards-end-block", 35 | [], 36 | this.deployer.address 37 | ); 38 | } 39 | 40 | addCommission(caller: Account, amount: number) { 41 | let block = this.chain.mineBlock([ 42 | Tx.contractCall( 43 | "commission-btc-v1", 44 | "add-commission", 45 | [ 46 | types.principal(qualifiedName("staking-v1")), 47 | types.uint(amount * 100000000), 48 | ], 49 | caller.address 50 | ), 51 | ]); 52 | return block.receipts[0].result; 53 | } 54 | 55 | withdrawCommission(caller: Account, amount: number, receiver: string) { 56 | let block = this.chain.mineBlock([ 57 | Tx.contractCall( 58 | "commission-btc-v1", 59 | "withdraw-commission", 60 | [types.uint(amount * 100000000), types.principal(receiver)], 61 | caller.address 62 | ), 63 | ]); 64 | return block.receipts[0].result; 65 | } 66 | 67 | setStakingBasisPoints(caller: Account, percentage: number) { 68 | let block = this.chain.mineBlock([ 69 | Tx.contractCall( 70 | "commission-btc-v1", 71 | "set-staking-basispoints", 72 | [types.uint(percentage * 10000)], 73 | caller.address 74 | ), 75 | ]); 76 | return block.receipts[0].result; 77 | } 78 | } 79 | export { CommissionBtc }; 80 | -------------------------------------------------------------------------------- /tests/wrappers/commission-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Commission 6 | // --------------------------------------------------------- 7 | 8 | class Commission { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStakingBasisPoints() { 18 | return this.chain.callReadOnlyFn("commission-v2", "get-staking-basispoints", [ 19 | ], this.deployer.address); 20 | } 21 | 22 | getCycleRewardsEndBlock() { 23 | return this.chain.callReadOnlyFn("commission-v2", "get-cycle-rewards-end-block", [ 24 | ], this.deployer.address); 25 | } 26 | 27 | addCommission(caller: Account, amount: number) { 28 | let block = this.chain.mineBlock([ 29 | Tx.contractCall("commission-v2", "add-commission", [ 30 | types.principal(qualifiedName("staking-v1")), 31 | types.uint(amount * 1000000) 32 | ], caller.address) 33 | ]); 34 | return block.receipts[0].result; 35 | } 36 | 37 | withdrawCommission(caller: Account) { 38 | let block = this.chain.mineBlock([ 39 | Tx.contractCall("commission-v2", "withdraw-commission", [ 40 | ], caller.address) 41 | ]); 42 | return block.receipts[0].result; 43 | } 44 | 45 | setStakingBasisPoints(caller: Account, percentage: number) { 46 | let block = this.chain.mineBlock([ 47 | Tx.contractCall("commission-v2", "set-staking-basispoints", [ 48 | types.uint(percentage * 10000) 49 | ], caller.address) 50 | ]); 51 | return block.receipts[0].result; 52 | } 53 | 54 | } 55 | export { Commission }; 56 | -------------------------------------------------------------------------------- /tests/wrappers/dao-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // DAO 6 | // --------------------------------------------------------- 7 | 8 | class DAO { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getContractsEnabled() { 18 | return this.chain.callReadOnlyFn("dao", "get-contracts-enabled", [ 19 | ], this.deployer.address); 20 | } 21 | 22 | getContractActive(address: string) { 23 | return this.chain.callReadOnlyFn("dao", "get-contract-active", [ 24 | types.principal(address) 25 | ], this.deployer.address); 26 | } 27 | 28 | getAdmin(address: string) { 29 | return this.chain.callReadOnlyFn("dao", "get-admin", [ 30 | types.principal(address) 31 | ], this.deployer.address); 32 | } 33 | 34 | checkIsEnabled(caller: Account) { 35 | let block = this.chain.mineBlock([ 36 | Tx.contractCall("dao", "check-is-enabled", [ 37 | ], caller.address) 38 | ]); 39 | return block.receipts[0].result; 40 | } 41 | 42 | checkIsProtocol(caller: Account, address: string) { 43 | let block = this.chain.mineBlock([ 44 | Tx.contractCall("dao", "check-is-protocol", [ 45 | types.principal(address), 46 | ], caller.address) 47 | ]); 48 | return block.receipts[0].result; 49 | } 50 | 51 | checkIsAdmin(caller: Account, address: string) { 52 | let block = this.chain.mineBlock([ 53 | Tx.contractCall("dao", "check-is-admin", [ 54 | types.principal(address), 55 | ], caller.address) 56 | ]); 57 | return block.receipts[0].result; 58 | } 59 | 60 | setContractsEnabled(caller: Account, enabled: boolean) { 61 | let block = this.chain.mineBlock([ 62 | Tx.contractCall("dao", "set-contracts-enabled", [ 63 | types.bool(enabled), 64 | ], caller.address) 65 | ]); 66 | return block.receipts[0].result; 67 | } 68 | 69 | setContractActive(caller: Account, address: string, active: boolean) { 70 | let block = this.chain.mineBlock([ 71 | Tx.contractCall("dao", "set-contract-active", [ 72 | types.principal(address), 73 | types.bool(active), 74 | ], caller.address) 75 | ]); 76 | return block.receipts[0].result; 77 | } 78 | 79 | setAdmin(caller: Account, address: string, active: boolean) { 80 | let block = this.chain.mineBlock([ 81 | Tx.contractCall("dao", "set-admin", [ 82 | types.principal(address), 83 | types.bool(active), 84 | ], caller.address) 85 | ]); 86 | return block.receipts[0].result; 87 | } 88 | 89 | } 90 | export { DAO }; 91 | -------------------------------------------------------------------------------- /tests/wrappers/data-direct-stacking-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Data Direct Stacking 6 | // --------------------------------------------------------- 7 | 8 | class DataDirectStacking { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getDirectStackingDependence() { 18 | return this.chain.callReadOnlyFn("data-direct-stacking-v1", "get-direct-stacking-dependence", [], this.deployer.address); 19 | } 20 | 21 | getTotalDirectStacking() { 22 | return this.chain.callReadOnlyFn("data-direct-stacking-v1", "get-total-direct-stacking", [], this.deployer.address); 23 | } 24 | 25 | getDirectStackingPoolAmount(pool: string) { 26 | return this.chain.callReadOnlyFn("data-direct-stacking-v1", "get-direct-stacking-pool-amount", [ 27 | types.principal(pool) 28 | ], this.deployer.address); 29 | } 30 | 31 | getDirectStackingUser(user: string) { 32 | return this.chain.callReadOnlyFn("data-direct-stacking-v1", "get-direct-stacking-user", [ 33 | types.principal(user) 34 | ], this.deployer.address); 35 | } 36 | 37 | setDirectStackingDependence(caller: Account, dependence: number) { 38 | let block = this.chain.mineBlock([ 39 | Tx.contractCall("data-direct-stacking-v1", "set-direct-stacking-dependence", [ 40 | types.uint(dependence), 41 | ], caller.address) 42 | ]); 43 | return block.receipts[0].result; 44 | } 45 | 46 | setTotalDirectStacking(caller: Account, amount: number) { 47 | let block = this.chain.mineBlock([ 48 | Tx.contractCall("data-direct-stacking-v1", "set-total-direct-stacking", [ 49 | types.uint(amount * 1000000), 50 | ], caller.address) 51 | ]); 52 | return block.receipts[0].result; 53 | } 54 | 55 | setDirectStackingPoolAmount(caller: Account, pool: string, amount: number) { 56 | let block = this.chain.mineBlock([ 57 | Tx.contractCall("data-direct-stacking-v1", "set-direct-stacking-pool-amount", [ 58 | types.principal(pool), 59 | types.uint(amount * 1000000), 60 | ], caller.address) 61 | ]); 62 | return block.receipts[0].result; 63 | } 64 | 65 | setDirectStackingUser(caller: Account, user: string, pool: string, amount: number) { 66 | let block = this.chain.mineBlock([ 67 | Tx.contractCall("data-direct-stacking-v1", "set-direct-stacking-user", [ 68 | types.principal(user), 69 | types.principal(pool), 70 | types.uint(amount * 1000000), 71 | ], caller.address) 72 | ]); 73 | return block.receipts[0].result; 74 | } 75 | 76 | deleteDirectStackingUser(caller: Account, user: string) { 77 | let block = this.chain.mineBlock([ 78 | Tx.contractCall("data-direct-stacking-v1", "delete-direct-stacking-user", [ 79 | types.principal(user), 80 | ], caller.address) 81 | ]); 82 | return block.receipts[0].result; 83 | } 84 | 85 | getSupportedProtocols() { 86 | return this.chain.callReadOnlyFn("data-direct-stacking-v1", "get-supported-protocols", [ 87 | ], this.deployer.address); 88 | } 89 | 90 | setSupportedProtocols(caller: Account, protocols: string[]) { 91 | let block = this.chain.mineBlock([ 92 | Tx.contractCall("data-direct-stacking-v1", "set-supported-protocols", [ 93 | types.list(protocols.map(protocol => types.principal(protocol))), 94 | ], caller.address) 95 | ]); 96 | return block.receipts[0].result; 97 | } 98 | 99 | } 100 | export { DataDirectStacking }; 101 | -------------------------------------------------------------------------------- /tests/wrappers/data-pools-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Data Pools 6 | // --------------------------------------------------------- 7 | 8 | class DataPools { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStandardCommission() { 18 | return this.chain.callReadOnlyFn("data-pools-v1", "get-standard-commission", [ 19 | ], this.deployer.address); 20 | } 21 | 22 | getPoolCommission(pool: string) { 23 | return this.chain.callReadOnlyFn("data-pools-v1", "get-pool-commission", [ 24 | types.principal(pool) 25 | ], this.deployer.address); 26 | } 27 | 28 | getPoolOwnerCommission(pool: string) { 29 | return this.chain.callReadOnlyFn("data-pools-v1", "get-pool-owner-commission", [ 30 | types.principal(pool) 31 | ], this.deployer.address); 32 | } 33 | 34 | setStandardCommission(caller: Account, commission: number) { 35 | let block = this.chain.mineBlock([ 36 | Tx.contractCall("data-pools-v1", "set-standard-commission", [ 37 | types.uint(commission) 38 | ], caller.address) 39 | ]); 40 | return block.receipts[0].result; 41 | } 42 | 43 | setPoolCommission(caller: Account, pool: string, commission: number) { 44 | let block = this.chain.mineBlock([ 45 | Tx.contractCall("data-pools-v1", "set-pool-commission", [ 46 | types.principal(pool), 47 | types.uint(commission) 48 | ], caller.address) 49 | ]); 50 | return block.receipts[0].result; 51 | } 52 | 53 | setPoolOwnerCommission(caller: Account, pool: string, receiver: string, share: number) { 54 | let block = this.chain.mineBlock([ 55 | Tx.contractCall("data-pools-v1", "set-pool-owner-commission", [ 56 | types.principal(pool), 57 | types.principal(receiver), 58 | types.uint(share * 10000) 59 | ], caller.address) 60 | ]); 61 | return block.receipts[0].result; 62 | } 63 | 64 | getActivePools() { 65 | return this.chain.callReadOnlyFn("data-pools-v1", "get-active-pools", [ 66 | ], this.deployer.address); 67 | } 68 | 69 | getPoolShare(pool: string) { 70 | return this.chain.callReadOnlyFn("data-pools-v1", "get-pool-share", [ 71 | types.principal(pool), 72 | ], this.deployer.address); 73 | } 74 | 75 | getPoolDelegates(pool: string) { 76 | return this.chain.callReadOnlyFn("data-pools-v1", "get-pool-delegates", [ 77 | types.principal(pool), 78 | ], this.deployer.address); 79 | } 80 | 81 | getDelegateShare(delegate: string) { 82 | return this.chain.callReadOnlyFn("data-pools-v1", "get-delegate-share", [ 83 | types.principal(delegate), 84 | ], this.deployer.address); 85 | } 86 | 87 | setActivePools(caller: Account, pools: string[]) { 88 | let block = this.chain.mineBlock([ 89 | Tx.contractCall("data-pools-v1", "set-active-pools", [ 90 | types.list(pools.map(pool => types.principal(pool))), 91 | ], caller.address) 92 | ]); 93 | return block.receipts[0].result; 94 | } 95 | 96 | setPoolShare(caller: Account, pool: string, share: number) { 97 | let block = this.chain.mineBlock([ 98 | Tx.contractCall("data-pools-v1", "set-pool-share", [ 99 | types.principal(pool), 100 | types.uint(share) 101 | ], caller.address) 102 | ]); 103 | return block.receipts[0].result; 104 | } 105 | 106 | setPoolDelegates(caller: Account, pool: string, delegates: string[]) { 107 | let block = this.chain.mineBlock([ 108 | Tx.contractCall("data-pools-v1", "set-pool-delegates", [ 109 | types.principal(pool), 110 | types.list(delegates.map(delegate => types.principal(delegate))), 111 | ], caller.address) 112 | ]); 113 | return block.receipts[0].result; 114 | } 115 | 116 | setDelegateShare(caller: Account, delegate: string, share: number) { 117 | let block = this.chain.mineBlock([ 118 | Tx.contractCall("data-pools-v1", "set-delegate-share", [ 119 | types.principal(delegate), 120 | types.uint(share) 121 | ], caller.address) 122 | ]); 123 | return block.receipts[0].result; 124 | } 125 | 126 | } 127 | export { DataPools }; 128 | -------------------------------------------------------------------------------- /tests/wrappers/direct-helpers-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // Direct Helpers 11 | // --------------------------------------------------------- 12 | 13 | class DirectHelpers { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | addDirectStacking( 23 | caller: Account, 24 | user: string, 25 | pool: string | undefined, 26 | amount: number 27 | ) { 28 | let block = this.chain.mineBlock([ 29 | Tx.contractCall( 30 | "direct-helpers-v4", 31 | "add-direct-stacking", 32 | [ 33 | types.principal(user), 34 | pool == undefined ? types.none() : types.some(types.principal(pool)), 35 | types.uint(amount * 1000000), 36 | ], 37 | caller.address 38 | ), 39 | ]); 40 | return block.receipts[0].result; 41 | } 42 | 43 | subtractDirectStacking(caller: Account, user: string, amount: number) { 44 | let block = this.chain.mineBlock([ 45 | Tx.contractCall( 46 | "direct-helpers-v4", 47 | "subtract-direct-stacking", 48 | [types.principal(user), types.uint(amount * 1000000)], 49 | caller.address 50 | ), 51 | ]); 52 | return block.receipts[0].result; 53 | } 54 | 55 | stopDirectStacking(caller: Account, user: string) { 56 | let block = this.chain.mineBlock([ 57 | Tx.contractCall( 58 | "direct-helpers-v4", 59 | "stop-direct-stacking", 60 | [types.principal(user)], 61 | caller.address 62 | ), 63 | ]); 64 | return block.receipts[0].result; 65 | } 66 | 67 | subtractDirectStackingUser(caller: Account, amount: number) { 68 | let block = this.chain.mineBlock([ 69 | Tx.contractCall( 70 | "direct-helpers-v4", 71 | "subtract-direct-stacking-user", 72 | [types.uint(amount * 1000000)], 73 | caller.address 74 | ), 75 | ]); 76 | return block.receipts[0].result; 77 | } 78 | 79 | stopDirectStackingUser(caller: Account) { 80 | let block = this.chain.mineBlock([ 81 | Tx.contractCall( 82 | "direct-helpers-v4", 83 | "stop-direct-stacking-user", 84 | [], 85 | caller.address 86 | ), 87 | ]); 88 | return block.receipts[0].result; 89 | } 90 | 91 | calculateDirectStackingInfo(protocols: string[], user: string) { 92 | return this.chain.callReadOnlyFn( 93 | "direct-helpers-v4", 94 | "calculate-direct-stacking-info", 95 | [ 96 | types.principal(qualifiedName("reserve-v1")), 97 | types.list(protocols.map((protocol) => types.principal(protocol))), 98 | types.principal(user), 99 | ], 100 | this.deployer.address 101 | ); 102 | } 103 | 104 | updateDirectStacking(caller: Account, protocols: string[], user: string) { 105 | let block = this.chain.mineBlock([ 106 | Tx.contractCall( 107 | "direct-helpers-v4", 108 | "update-direct-stacking", 109 | [ 110 | types.principal(qualifiedName("reserve-v1")), 111 | types.list(protocols.map((protocol) => types.principal(protocol))), 112 | types.principal(user), 113 | ], 114 | caller.address 115 | ), 116 | ]); 117 | return block.receipts[0].result; 118 | } 119 | } 120 | export { DirectHelpers }; 121 | -------------------------------------------------------------------------------- /tests/wrappers/fomo-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Fomo 6 | // --------------------------------------------------------- 7 | 8 | class Fomo { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getCurrentWinner() { 18 | return this.chain.callReadOnlyFn("fomo", "get-current-winner", [], this.deployer.address); 19 | } 20 | 21 | getClaimCost() { 22 | return this.chain.callReadOnlyFn("fomo", "get-claim-cost", [], this.deployer.address); 23 | } 24 | 25 | getIncrement() { 26 | return this.chain.callReadOnlyFn("fomo", "get-increment", [], this.deployer.address); 27 | } 28 | 29 | hasGameEnded() { 30 | return this.chain.callReadOnlyFn("fomo", "has-game-ended", [], this.deployer.address); 31 | } 32 | 33 | setClaimCost(caller: Account, amount: number) { 34 | let block = this.chain.mineBlock([ 35 | Tx.contractCall("fomo", "set-claim-cost", [ 36 | types.uint(amount * 1000000) 37 | ], caller.address) 38 | ]); 39 | return block.receipts[0].result; 40 | } 41 | 42 | setIncrement(caller: Account, amount: number) { 43 | let block = this.chain.mineBlock([ 44 | Tx.contractCall("fomo", "set-increment", [ 45 | types.uint(amount * 1000000) 46 | ], caller.address) 47 | ]); 48 | return block.receipts[0].result; 49 | } 50 | 51 | buyClaim(caller: Account) { 52 | let block = this.chain.mineBlock([ 53 | Tx.contractCall("fomo", "buy-claim", [], caller.address) 54 | ]); 55 | return block.receipts[0].result; 56 | } 57 | 58 | retrieveWinner(caller: Account, nftId: number) { 59 | let block = this.chain.mineBlock([ 60 | Tx.contractCall("fomo", "retrieve-winner", [ 61 | types.uint(nftId) 62 | ], caller.address) 63 | ]); 64 | return block.receipts[0].result; 65 | } 66 | 67 | retrieveLoser(caller: Account, nftId: number) { 68 | let block = this.chain.mineBlock([ 69 | Tx.contractCall("fomo", "retrieve-loser", [ 70 | types.uint(nftId) 71 | ], caller.address) 72 | ]); 73 | return block.receipts[0].result; 74 | } 75 | 76 | retrieveFees(caller: Account) { 77 | let block = this.chain.mineBlock([ 78 | Tx.contractCall("fomo", "retrieve-fees", [], caller.address) 79 | ]); 80 | return block.receipts[0].result; 81 | } 82 | 83 | rescueFunds(caller: Account) { 84 | let block = this.chain.mineBlock([ 85 | Tx.contractCall("fomo", "rescue-funds", [], caller.address) 86 | ]); 87 | return block.receipts[0].result; 88 | } 89 | 90 | startGame(caller: Account) { 91 | let block = this.chain.mineBlock([ 92 | Tx.contractCall("fomo", "start-game", [], caller.address) 93 | ]); 94 | return block.receipts[0].result; 95 | } 96 | } 97 | 98 | export { Fomo }; 99 | -------------------------------------------------------------------------------- /tests/wrappers/genesis-minter-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Stacking DAO Genesis Minter 6 | // --------------------------------------------------------- 7 | 8 | class GenesisMinter { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getCycleEndBlock() { 18 | return this.chain.callReadOnlyFn("stacking-dao-genesis-nft-minter", "get-cycle-end-block", [], this.deployer.address); 19 | } 20 | 21 | canClaim(recipient: Account) { 22 | return this.chain.callReadOnlyFn("stacking-dao-genesis-nft-minter", "can-claim", [types.principal(recipient.address)], this.deployer.address); 23 | } 24 | 25 | setCycleEndBlock(blockHeight: number) { 26 | let block = this.chain.mineBlock([ 27 | Tx.contractCall("stacking-dao-genesis-nft-minter", "set-cycle-end-block", [ 28 | types.uint(blockHeight) 29 | ], this.deployer.address) 30 | ]); 31 | return block.receipts[0].result; 32 | } 33 | 34 | airdrop(recipient: Account, type: number) { 35 | let block = this.chain.mineBlock([ 36 | Tx.contractCall("stacking-dao-genesis-nft-minter", "airdrop", [ 37 | types.tuple({ 38 | 'recipient': types.principal(recipient.address), 39 | 'type': types.uint(type) 40 | }) 41 | ], this.deployer.address) 42 | ]); 43 | return block.receipts[0].result; 44 | } 45 | 46 | airdropMany(info: any) { 47 | let recipients = []; 48 | info.forEach((data) => { 49 | recipients.push(types.tuple({ 50 | 'recipient': types.principal(data.recipient), 51 | 'type': types.uint(data.type) 52 | })) 53 | }); 54 | 55 | let block = this.chain.mineBlock([ 56 | Tx.contractCall("stacking-dao-genesis-nft-minter", "airdrop-many", [ 57 | types.list(recipients) 58 | ], this.deployer.address) 59 | ]); 60 | return block.receipts[0].result; 61 | } 62 | 63 | claim(sender: Account) { 64 | let block = this.chain.mineBlock([ 65 | Tx.contractCall("stacking-dao-genesis-nft-minter", "claim", [], sender.address) 66 | ]); 67 | return block.receipts[0].result; 68 | } 69 | } 70 | 71 | class GenesisNFT { 72 | chain: Chain; 73 | deployer: Account; 74 | 75 | constructor(chain: Chain, deployer: Account) { 76 | this.chain = chain; 77 | this.deployer = deployer; 78 | } 79 | 80 | getOwner(id: number) { 81 | return this.chain.callReadOnlyFn("stacking-dao-genesis-nft", "get-owner", [types.uint(id)], this.deployer.address); 82 | } 83 | 84 | getGenesisType(id: number) { 85 | return this.chain.callReadOnlyFn("stacking-dao-genesis-nft", "get-genesis-type", [types.uint(id)], this.deployer.address); 86 | } 87 | 88 | getTokenUri(id: number) { 89 | return this.chain.callReadOnlyFn("stacking-dao-genesis-nft", "get-token-uri", [types.uint(id)], this.deployer.address); 90 | } 91 | 92 | transfer(id: number, sender: Account, recipient: Account) { 93 | let block = this.chain.mineBlock([ 94 | Tx.contractCall("stacking-dao-genesis-nft", "transfer", [ 95 | types.uint(id), 96 | types.principal(sender.address), 97 | types.principal(recipient.address) 98 | ], sender.address) 99 | ]); 100 | return block.receipts[0].result; 101 | } 102 | 103 | setBaseTokenUri(newUri: string) { 104 | let block = this.chain.mineBlock([ 105 | Tx.contractCall("stacking-dao-genesis-nft", "set-base-token-uri", [ 106 | types.ascii(newUri) 107 | ], this.deployer.address) 108 | ]); 109 | return block.receipts[0].result; 110 | } 111 | } 112 | 113 | export { GenesisMinter, GenesisNFT }; 114 | -------------------------------------------------------------------------------- /tests/wrappers/position-mock-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | 8 | // --------------------------------------------------------- 9 | // Position Mock 10 | // --------------------------------------------------------- 11 | 12 | class PositionMock { 13 | chain: Chain; 14 | deployer: Account; 15 | 16 | constructor(chain: Chain, deployer: Account) { 17 | this.chain = chain; 18 | this.deployer = deployer; 19 | } 20 | 21 | getBalance(user: string) { 22 | return this.chain.callReadOnlyFn( 23 | "position-mock", 24 | "get-balance", 25 | [types.principal(user)], 26 | this.deployer.address 27 | ); 28 | } 29 | 30 | setBalance(caller: Account, amount: number) { 31 | let block = this.chain.mineBlock([ 32 | Tx.contractCall( 33 | "position-mock", 34 | "set-balance", 35 | [types.uint(amount * 1000000)], 36 | caller.address 37 | ), 38 | ]); 39 | return block.receipts[0].result; 40 | } 41 | } 42 | export { PositionMock }; 43 | -------------------------------------------------------------------------------- /tests/wrappers/pox-fast-pool-v2-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Fast Pool V2 6 | // --------------------------------------------------------- 7 | 8 | class FastPoolV2 { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStxAccount(user: string) { 18 | return this.chain.callReadOnlyFn("pox-fast-pool-v2-mock", "get-stx-account", [ 19 | types.principal(user) 20 | ], this.deployer.address); 21 | } 22 | 23 | getLockedInfoUser(user: string) { 24 | return this.chain.callReadOnlyFn("pox-fast-pool-v2-mock", "get-locked-info-user", [ 25 | types.principal(user), 26 | ], this.deployer.address); 27 | } 28 | 29 | notLockedForCycle(unlockBurnHeight: number, cycle: number) { 30 | return this.chain.callReadOnlyFn("pox-fast-pool-v2-mock", "not-locked-for-cycle", [ 31 | types.uint(unlockBurnHeight), 32 | types.uint(cycle) 33 | ], this.deployer.address); 34 | } 35 | 36 | delegateStx(caller: Account, amount: number) { 37 | let block = this.chain.mineBlock([ 38 | Tx.contractCall("pox-fast-pool-v2-mock", "delegate-stx", [ 39 | types.uint(amount * 1000000), 40 | ], caller.address) 41 | ]); 42 | return block.receipts[0].result; 43 | } 44 | 45 | delegateStackStx(caller: Account, user: string) { 46 | let block = this.chain.mineBlock([ 47 | Tx.contractCall("pox-fast-pool-v2-mock", "delegate-stack-stx", [ 48 | types.principal(user), 49 | ], caller.address) 50 | ]); 51 | return block.receipts[0].result; 52 | } 53 | 54 | delegateStackStxMany(caller: Account, users: string[]) { 55 | let block = this.chain.mineBlock([ 56 | Tx.contractCall("pox-fast-pool-v2-mock", "delegate-stack-stx-many", [ 57 | types.list(users.map(user => types.principal(user))), 58 | ], caller.address) 59 | ]); 60 | return block.receipts[0].result; 61 | } 62 | 63 | } 64 | export { FastPoolV2 }; 65 | -------------------------------------------------------------------------------- /tests/wrappers/pox-mock-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { hexDecode } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // PoX-3 Mock 6 | // --------------------------------------------------------- 7 | 8 | class Pox3Mock { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | burnHeightForRewardCycle(height: number) { 18 | return this.chain.callReadOnlyFn("pox-3-mock", "burn-height-to-reward-cycle", [ 19 | types.uint(height), 20 | ], this.deployer.address); 21 | } 22 | 23 | getStackerInfo(stacker: string) { 24 | return this.chain.callReadOnlyFn("pox-3-mock", "get-stacker-info", [ 25 | types.principal(stacker), 26 | ], this.deployer.address); 27 | } 28 | 29 | unlock(caller: Account, account: string) { 30 | let block = this.chain.mineBlock([ 31 | Tx.contractCall("pox-3-mock", "unlock-mock", [ 32 | types.principal(account), 33 | ], caller.address) 34 | ]); 35 | return block.receipts[0].result; 36 | } 37 | 38 | } 39 | export { Pox3Mock }; 40 | 41 | // --------------------------------------------------------- 42 | // PoX-4 Mock 43 | // --------------------------------------------------------- 44 | 45 | class Pox4Mock { 46 | chain: Chain; 47 | deployer: Account; 48 | 49 | constructor(chain: Chain, deployer: Account) { 50 | this.chain = chain; 51 | this.deployer = deployer; 52 | } 53 | 54 | getPoxInfo() { 55 | return this.chain.callReadOnlyFn("pox-4-mock", "get-pox-info", [], this.deployer.address); 56 | } 57 | 58 | 59 | burnHeightForRewardCycle(height: number) { 60 | return this.chain.callReadOnlyFn("pox-4-mock", "burn-height-to-reward-cycle", [ 61 | types.uint(height), 62 | ], this.deployer.address); 63 | } 64 | 65 | getStackerInfo(stacker: string) { 66 | return this.chain.callReadOnlyFn("pox-4-mock", "get-stacker-info", [ 67 | types.principal(stacker), 68 | ], this.deployer.address); 69 | } 70 | 71 | getCheckDelegation(stacker: string) { 72 | return this.chain.callReadOnlyFn("pox-4-mock", "get-check-delegation", [ 73 | types.principal(stacker), 74 | ], this.deployer.address); 75 | } 76 | 77 | getPartialStackedByCycle(rewardCycle: number, pool: string) { 78 | return this.chain.callReadOnlyFn("pox-4-mock", "get-partial-stacked-by-cycle", [ 79 | types.tuple({ 'version': '0x04', 'hashbytes': '0x2fffa9a09bb7fa7dced44834d77ee81c49c5f0cc'}), 80 | types.uint(rewardCycle), 81 | types.principal(pool), 82 | ], this.deployer.address); 83 | } 84 | 85 | getSignerKeyMessageHash(rewardCycle: number, topic: string, authId: number) { 86 | return this.chain.callReadOnlyFn("pox-4-mock", "get-signer-key-message-hash", [ 87 | types.tuple({ 'version': '0x04', 'hashbytes': '0x2fffa9a09bb7fa7dced44834d77ee81c49c5f0cc'}), 88 | types.uint(rewardCycle), 89 | types.ascii(topic), 90 | types.uint(1), 91 | types.uint(999999999 * 1000000), 92 | types.uint(authId), 93 | ], this.deployer.address); 94 | } 95 | 96 | verifySignerKeySig(rewardCycle: number, topic: string, signerSig: string, signerKey: string, authId: number) { 97 | return this.chain.callReadOnlyFn("pox-4-mock", "verify-signer-key-sig", [ 98 | types.tuple({ 'version': '0x04', 'hashbytes': '0x2fffa9a09bb7fa7dced44834d77ee81c49c5f0cc'}), 99 | types.uint(rewardCycle), 100 | types.ascii(topic), 101 | types.uint(1), 102 | types.some(types.buff(hexDecode(signerSig))), 103 | types.buff(hexDecode(signerKey)), 104 | types.uint(999999999 * 1000000), 105 | types.uint(999999999 * 1000000), 106 | types.uint(authId), 107 | ], this.deployer.address); 108 | } 109 | 110 | unlock(caller: Account, account: string) { 111 | let block = this.chain.mineBlock([ 112 | Tx.contractCall("pox-4-mock", "unlock-mock", [ 113 | types.principal(account), 114 | ], caller.address) 115 | ]); 116 | return block.receipts[0].result; 117 | } 118 | 119 | allowContractCaller(caller: Account, contract: string) { 120 | let block = this.chain.mineBlock([ 121 | Tx.contractCall("pox-4-mock", "allow-contract-caller", [ 122 | types.principal(contract), 123 | types.none() 124 | ], caller.address) 125 | ]); 126 | return block.receipts[0].result; 127 | } 128 | 129 | 130 | } 131 | export { Pox4Mock }; 132 | -------------------------------------------------------------------------------- /tests/wrappers/reserve-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Reserve 6 | // --------------------------------------------------------- 7 | 8 | class Reserve { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStxForWithdrawals() { 18 | return this.chain.callReadOnlyFn("reserve-v1", "get-stx-for-withdrawals", [], this.deployer.address); 19 | } 20 | 21 | getStxStacking() { 22 | return this.chain.callReadOnlyFn("reserve-v1", "get-stx-stacking", [], this.deployer.address); 23 | } 24 | 25 | getStxStackingAtBlock(blockHeight: number) { 26 | return this.chain.callReadOnlyFn("reserve-v1", "get-stx-stacking-at-block", [ 27 | types.uint(blockHeight) 28 | ], this.deployer.address); 29 | } 30 | 31 | getStxBalance() { 32 | return this.chain.callReadOnlyFn("reserve-v1", "get-stx-balance", [], this.deployer.address); 33 | } 34 | 35 | getTotalStx() { 36 | return this.chain.callReadOnlyFn("reserve-v1", "get-total-stx", [], this.deployer.address); 37 | } 38 | 39 | getShutdownEnabled() { 40 | return this.chain.callReadOnlyFn("reserve-v1", "get-shutdown-enabled", [], this.deployer.address); 41 | } 42 | 43 | lockStxForWithdrawal(caller: Account, amount: number) { 44 | let block = this.chain.mineBlock([ 45 | Tx.contractCall("reserve-v1", "lock-stx-for-withdrawal", [ 46 | types.uint(amount * 1000000) 47 | ], caller.address) 48 | ]); 49 | return block.receipts[0].result; 50 | } 51 | 52 | requestStxForWithdrawal(caller: Account, amount: number, receiver: string) { 53 | let block = this.chain.mineBlock([ 54 | Tx.contractCall("reserve-v1", "request-stx-for-withdrawal", [ 55 | types.uint(amount * 1000000), 56 | types.principal(receiver) 57 | ], caller.address) 58 | ]); 59 | return block.receipts[0].result; 60 | } 61 | 62 | requestStxToStack(caller: Account, amount: number) { 63 | let block = this.chain.mineBlock([ 64 | Tx.contractCall("reserve-v1", "request-stx-to-stack", [ 65 | types.uint(amount * 1000000), 66 | ], caller.address) 67 | ]); 68 | return block.receipts[0].result; 69 | } 70 | 71 | returnStxFromStacking(caller: Account, amount: number) { 72 | let block = this.chain.mineBlock([ 73 | Tx.contractCall("reserve-v1", "return-stx-from-stacking", [ 74 | types.uint(amount * 1000000), 75 | ], caller.address) 76 | ]); 77 | return block.receipts[0].result; 78 | } 79 | 80 | getStx(caller: Account, amount: number, receiver: string) { 81 | let block = this.chain.mineBlock([ 82 | Tx.contractCall("reserve-v1", "get-stx", [ 83 | types.uint(amount * 1000000), 84 | types.principal(receiver) 85 | ], caller.address) 86 | ]); 87 | return block.receipts[0].result; 88 | } 89 | } 90 | export { Reserve }; 91 | -------------------------------------------------------------------------------- /tests/wrappers/return-stx-job-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Return STX Job 6 | // --------------------------------------------------------- 7 | 8 | class ReturnStxJob { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | checkJob() { 18 | return this.chain.callReadOnlyFn("return-stx-job-v1", "check-job", [], this.deployer.address); 19 | } 20 | 21 | runJob(caller: Account) { 22 | let block = this.chain.mineBlock([ 23 | Tx.contractCall("return-stx-job-v1", "run-job", [ 24 | ], caller.address) 25 | ]); 26 | return block.receipts[0].result; 27 | } 28 | 29 | } 30 | export { ReturnStxJob }; 31 | -------------------------------------------------------------------------------- /tests/wrappers/rewards-job-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Stacking Rewards Job 6 | // --------------------------------------------------------- 7 | 8 | class RewardsJob { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | checkJob() { 18 | return this.chain.callReadOnlyFn("rewards-job-v1", "check-job", [], this.deployer.address); 19 | } 20 | 21 | runJob(caller: Account) { 22 | let block = this.chain.mineBlock([ 23 | Tx.contractCall("rewards-job-v1", "run-job", [ 24 | ], caller.address) 25 | ]); 26 | return block.receipts[0].result; 27 | } 28 | 29 | retreiveStxTokens(caller: Account, amount: number, receiver: string) { 30 | let block = this.chain.mineBlock([ 31 | Tx.contractCall("rewards-job-v1", "retreive-stx-tokens", [ 32 | types.uint(amount * 1000000), 33 | types.principal(receiver) 34 | ], caller.address) 35 | ]); 36 | return block.receipts[0].result; 37 | } 38 | } 39 | export { RewardsJob }; 40 | -------------------------------------------------------------------------------- /tests/wrappers/sbtc-token-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // sBTC token 11 | // --------------------------------------------------------- 12 | 13 | class SBtcToken { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | getTotalSupply() { 23 | return this.chain.callReadOnlyFn( 24 | "sbtc-token", 25 | "get-total-supply", 26 | [], 27 | this.deployer.address 28 | ); 29 | } 30 | 31 | getName() { 32 | return this.chain.callReadOnlyFn( 33 | "sbtc-token", 34 | "get-name", 35 | [], 36 | this.deployer.address 37 | ); 38 | } 39 | 40 | getSymbol() { 41 | return this.chain.callReadOnlyFn( 42 | "sbtc-token", 43 | "get-symbol", 44 | [], 45 | this.deployer.address 46 | ); 47 | } 48 | 49 | getDecimals() { 50 | return this.chain.callReadOnlyFn( 51 | "sbtc-token", 52 | "get-decimals", 53 | [], 54 | this.deployer.address 55 | ); 56 | } 57 | 58 | getBalance(account: string) { 59 | return this.chain.callReadOnlyFn( 60 | "sbtc-token", 61 | "get-balance", 62 | [types.principal(account)], 63 | this.deployer.address 64 | ); 65 | } 66 | 67 | getTokenUri() { 68 | return this.chain.callReadOnlyFn( 69 | "sbtc-token", 70 | "get-token-uri", 71 | [], 72 | this.deployer.address 73 | ); 74 | } 75 | 76 | transfer(caller: Account, amount: number, receiver: string) { 77 | let block = this.chain.mineBlock([ 78 | Tx.contractCall( 79 | "sbtc-token", 80 | "transfer", 81 | [ 82 | types.uint(amount * 100000000), 83 | types.principal(caller.address), 84 | types.principal(receiver), 85 | types.none(), 86 | ], 87 | caller.address 88 | ), 89 | ]); 90 | return block.receipts[0].result; 91 | } 92 | 93 | protocolMint(caller: Account, amount: number, receiver: string) { 94 | let block = this.chain.mineBlock([ 95 | Tx.contractCall( 96 | "sbtc-token", 97 | "protocol-mint", 98 | [types.uint(amount * 100000000), types.principal(receiver)], 99 | caller.address 100 | ), 101 | ]); 102 | return block.receipts[0].result; 103 | } 104 | 105 | protocolBurn(caller: Account, amount: number, receiver: string) { 106 | let block = this.chain.mineBlock([ 107 | Tx.contractCall( 108 | "sbtc-token", 109 | "protocol-burn", 110 | [types.uint(amount * 100000000), types.principal(receiver)], 111 | caller.address 112 | ), 113 | ]); 114 | return block.receipts[0].result; 115 | } 116 | } 117 | export { SBtcToken }; 118 | -------------------------------------------------------------------------------- /tests/wrappers/sdao-token-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // sDAO token 6 | // --------------------------------------------------------- 7 | 8 | class SDAOToken { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getTotalSupply() { 18 | return this.chain.callReadOnlyFn("sdao-token", "get-total-supply", [], this.deployer.address); 19 | } 20 | 21 | getName() { 22 | return this.chain.callReadOnlyFn("sdao-token", "get-name", [], this.deployer.address); 23 | } 24 | 25 | getSymbol() { 26 | return this.chain.callReadOnlyFn("sdao-token", "get-symbol", [], this.deployer.address); 27 | } 28 | 29 | getDecimals() { 30 | return this.chain.callReadOnlyFn("sdao-token", "get-decimals", [], this.deployer.address); 31 | } 32 | 33 | getBalance(account: string) { 34 | return this.chain.callReadOnlyFn("sdao-token", "get-balance", [ 35 | types.principal(account) 36 | ], this.deployer.address); 37 | } 38 | 39 | getTokenUri() { 40 | return this.chain.callReadOnlyFn("sdao-token", "get-token-uri", [], this.deployer.address); 41 | } 42 | 43 | transfer(caller: Account, amount: number, receiver: string) { 44 | let block = this.chain.mineBlock([ 45 | Tx.contractCall("sdao-token", "transfer", [ 46 | types.uint(amount * 1000000), 47 | types.principal(caller.address), 48 | types.principal(receiver), 49 | types.none() 50 | ], caller.address) 51 | ]); 52 | return block.receipts[0].result; 53 | } 54 | 55 | setTokenUri(caller: Account, uri: string) { 56 | let block = this.chain.mineBlock([ 57 | Tx.contractCall("sdao-token", "set-token-uri", [ 58 | types.utf8(uri), 59 | ], caller.address) 60 | ]); 61 | return block.receipts[0].result; 62 | } 63 | 64 | mintForProtocol(caller: Account, amount: number, receiver: string) { 65 | let block = this.chain.mineBlock([ 66 | Tx.contractCall("sdao-token", "mint-for-protocol", [ 67 | types.uint(amount * 1000000), 68 | types.principal(receiver), 69 | ], caller.address) 70 | ]); 71 | return block.receipts[0].result; 72 | } 73 | 74 | burnForProtocol(caller: Account, amount: number, receiver: string) { 75 | let block = this.chain.mineBlock([ 76 | Tx.contractCall("sdao-token", "burn-for-protocol", [ 77 | types.uint(amount * 1000000), 78 | types.principal(receiver), 79 | ], caller.address) 80 | ]); 81 | return block.receipts[0].result; 82 | } 83 | 84 | burn(caller: Account, amount: number) { 85 | let block = this.chain.mineBlock([ 86 | Tx.contractCall("sdao-token", "burn", [ 87 | types.uint(amount * 1000000), 88 | ], caller.address) 89 | ]); 90 | return block.receipts[0].result; 91 | } 92 | 93 | } 94 | export { SDAOToken }; 95 | -------------------------------------------------------------------------------- /tests/wrappers/stacker-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Stacker 6 | // --------------------------------------------------------- 7 | 8 | class Stacker { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStackingUnlockBurnHeight(stackerId: number) { 18 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stacking-unlock-burn-height", [], this.deployer.address); 19 | } 20 | 21 | getStackingStxStacked(stackerId: number) { 22 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stacking-stx-stacked", [], this.deployer.address); 23 | } 24 | 25 | getStxBalance(stackerId: number) { 26 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stx-balance", [], this.deployer.address); 27 | } 28 | 29 | getStxStacked(stackerId: number) { 30 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stx-stacked", [], this.deployer.address); 31 | } 32 | 33 | getStackerInfo(stackerId: number) { 34 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stacker-info", [], this.deployer.address); 35 | } 36 | 37 | getStxAccount(stackerId: number) { 38 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-stx-account", [], this.deployer.address); 39 | } 40 | 41 | getPoxInfo(stackerId: number) { 42 | return this.chain.callReadOnlyFn("stacker-" + stackerId, "get-pox-info", [], this.deployer.address); 43 | } 44 | 45 | initiateStacking(stackerId: number, caller: Account, amount: number, startBurnHeight: number, lockPeriod: number) { 46 | let block = this.chain.mineBlock([ 47 | Tx.contractCall("stacker-" + stackerId, "initiate-stacking", [ 48 | types.principal(qualifiedName("reserve-v1")), 49 | types.tuple({ 'version': '0x00', 'hashbytes': '0xf632e6f9d29bfb07bc8948ca6e0dd09358f003ac'}), 50 | types.uint(amount * 1000000), 51 | types.uint(startBurnHeight), 52 | types.uint(lockPeriod) 53 | ], caller.address) 54 | ]); 55 | return block.receipts[0].result; 56 | } 57 | 58 | stackIncrease(stackerId: number, caller: Account, amount: number) { 59 | let block = this.chain.mineBlock([ 60 | Tx.contractCall("stacker-" + stackerId, "stack-increase", [ 61 | types.principal(qualifiedName("reserve-v1")), 62 | types.uint(amount * 1000000) 63 | ], caller.address) 64 | ]); 65 | return block.receipts[0].result; 66 | } 67 | 68 | stackExtend(stackerId: number, caller: Account, extendCount: number) { 69 | let block = this.chain.mineBlock([ 70 | Tx.contractCall("stacker-" + stackerId, "stack-extend", [ 71 | types.uint(extendCount), 72 | types.tuple({ 'version': '0x00', 'hashbytes': '0xf632e6f9d29bfb07bc8948ca6e0dd09358f003ac'}), 73 | ], caller.address) 74 | ]); 75 | return block.receipts[0].result; 76 | } 77 | 78 | returnStx(stackerId: number, caller: Account) { 79 | let block = this.chain.mineBlock([ 80 | Tx.contractCall("stacker-" + stackerId, "return-stx", [ 81 | types.principal(qualifiedName("reserve-v1")), 82 | ], caller.address) 83 | ]); 84 | return block.receipts[0].result; 85 | } 86 | } 87 | export { Stacker }; 88 | -------------------------------------------------------------------------------- /tests/wrappers/stacking-delegate-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // Stacking Delegate Helpers 11 | // --------------------------------------------------------- 12 | 13 | class StackingDelegate { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | getStxAccount(user: string) { 23 | return this.chain.callReadOnlyFn( 24 | "stacking-delegate-1-1", 25 | "get-stx-account", 26 | [types.principal(user)], 27 | this.deployer.address 28 | ); 29 | } 30 | 31 | delegateStx( 32 | caller: Account, 33 | delegate: string, 34 | amount: number, 35 | delegateTo: string, 36 | untilBurnHeight: number 37 | ) { 38 | let block = this.chain.mineBlock([ 39 | Tx.contractCall( 40 | delegate, 41 | "delegate-stx", 42 | [ 43 | types.uint(amount * 1000000), 44 | types.principal(delegateTo), 45 | types.some(types.uint(untilBurnHeight)), 46 | ], 47 | caller.address 48 | ), 49 | ]); 50 | return block.receipts[0].result; 51 | } 52 | 53 | revokeDelegateStx(caller: Account, delegate: string) { 54 | let block = this.chain.mineBlock([ 55 | Tx.contractCall(delegate, "revoke-delegate-stx", [], caller.address), 56 | ]); 57 | return block.receipts[0].result; 58 | } 59 | 60 | requestStxToStack(caller: Account, delegate: string, amount: number) { 61 | let block = this.chain.mineBlock([ 62 | Tx.contractCall( 63 | delegate, 64 | "request-stx-to-stack", 65 | [ 66 | types.principal(qualifiedName("reserve-v1")), 67 | types.uint(amount * 1000000), 68 | ], 69 | caller.address 70 | ), 71 | ]); 72 | return block.receipts[0].result; 73 | } 74 | 75 | returnStxFromStacking(caller: Account, delegate: string, amount: number) { 76 | let block = this.chain.mineBlock([ 77 | Tx.contractCall( 78 | delegate, 79 | "return-stx-from-stacking", 80 | [ 81 | types.principal(qualifiedName("reserve-v1")), 82 | types.uint(amount * 1000000), 83 | ], 84 | caller.address 85 | ), 86 | ]); 87 | return block.receipts[0].result; 88 | } 89 | 90 | handleRewards( 91 | caller: Account, 92 | delegate: string, 93 | pool: string, 94 | rewards: number 95 | ) { 96 | let block = this.chain.mineBlock([ 97 | Tx.contractCall( 98 | delegate, 99 | "handle-rewards", 100 | [ 101 | types.principal(pool), 102 | types.uint(rewards * 1000000), 103 | types.principal(qualifiedName("rewards-v3")), 104 | ], 105 | caller.address 106 | ), 107 | ]); 108 | return block.receipts[0].result; 109 | } 110 | 111 | returnStx(caller: Account, delegate: string) { 112 | let block = this.chain.mineBlock([ 113 | Tx.contractCall( 114 | delegate, 115 | "return-stx", 116 | [types.principal(qualifiedName("reserve-v1"))], 117 | caller.address 118 | ), 119 | ]); 120 | return block.receipts[0].result; 121 | } 122 | } 123 | export { StackingDelegate }; 124 | -------------------------------------------------------------------------------- /tests/wrappers/stacking-pool-payout-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | 3 | // --------------------------------------------------------- 4 | // Stacking Pool Payout Helpers 5 | // --------------------------------------------------------- 6 | 7 | class StackingPoolPayout { 8 | chain: Chain; 9 | deployer: Account; 10 | 11 | constructor(chain: Chain, deployer: Account) { 12 | this.chain = chain; 13 | this.deployer = deployer; 14 | } 15 | 16 | getLastRewardId() { 17 | return this.chain.callReadOnlyFn("stacking-pool-payout-v1", "get-last-reward-id", [], this.deployer.address); 18 | } 19 | 20 | getRewardsInfo(rewardsId: number) { 21 | return this.chain.callReadOnlyFn("stacking-pool-payout-v1", "get-rewards-info", [ 22 | types.uint(rewardsId), 23 | ], this.deployer.address); 24 | } 25 | 26 | getTotalStacked(cycle: number) { 27 | return this.chain.callReadOnlyFn("stacking-pool-payout-v1", "get-total-stacked", [ 28 | types.uint(cycle), 29 | ], this.deployer.address); 30 | } 31 | 32 | getUserStacked(user: string, cycle: number) { 33 | return this.chain.callReadOnlyFn("stacking-pool-payout-v1", "get-user-stacked", [ 34 | types.principal(user), 35 | types.uint(cycle), 36 | ], this.deployer.address); 37 | } 38 | 39 | depositRewards(caller: Account, amount: number, cycle: number) { 40 | let block = this.chain.mineBlock([ 41 | Tx.contractCall("stacking-pool-payout-v1", "deposit-rewards", [ 42 | types.uint(amount * 1000000), 43 | types.uint(cycle) 44 | ], caller.address) 45 | ]); 46 | return block.receipts[0].result; 47 | } 48 | 49 | distributeRewards(caller: Account, users: string[], rewardId: number) { 50 | let block = this.chain.mineBlock([ 51 | Tx.contractCall("stacking-pool-payout-v1", "distribute-rewards", [ 52 | types.list(users.map(user => types.principal(user))), 53 | types.uint(rewardId) 54 | ], caller.address) 55 | ]); 56 | return block.receipts[0].result; 57 | } 58 | 59 | getStx(caller: Account, amount: number, receiver: string) { 60 | let block = this.chain.mineBlock([ 61 | Tx.contractCall("stacking-pool-payout-v1", "get-stx", [ 62 | types.uint(amount * 1000000), 63 | types.principal(receiver), 64 | ], caller.address) 65 | ]); 66 | return block.receipts[0].result; 67 | } 68 | 69 | } 70 | export { StackingPoolPayout }; 71 | -------------------------------------------------------------------------------- /tests/wrappers/staking-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // Staking 6 | // --------------------------------------------------------- 7 | 8 | class Staking { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getStakeOf(staker: string) { 18 | return this.chain.callReadOnlyFn("staking-v1", "get-stake-of", [ 19 | types.principal(staker), 20 | ], this.deployer.address); 21 | } 22 | 23 | getStakeAmountOf(staker: string) { 24 | return this.chain.callReadOnlyFn("staking-v1", "get-stake-amount-of", [ 25 | types.principal(staker), 26 | ], this.deployer.address); 27 | } 28 | 29 | getStakeCummRewardPerStakeOf(staker: string) { 30 | return this.chain.callReadOnlyFn("staking-v1", "get-stake-cumm-reward-per-stake-of", [ 31 | types.principal(staker), 32 | ], this.deployer.address); 33 | } 34 | 35 | getTotalStaked() { 36 | return this.chain.callReadOnlyFn("staking-v1", "get-total-staked", [ 37 | ], this.deployer.address); 38 | } 39 | 40 | getCummRewardPerStake() { 41 | return this.chain.callReadOnlyFn("staking-v1", "get-cumm-reward-per-stake", [ 42 | ], this.deployer.address); 43 | } 44 | 45 | getLastRewardIncreaseBlock() { 46 | return this.chain.callReadOnlyFn("staking-v1", "get-last-reward-increase-block", [ 47 | ], this.deployer.address); 48 | } 49 | 50 | getRewardsPerBlock() { 51 | return this.chain.callReadOnlyFn("staking-v1", "get-rewards-per-block", [ 52 | ], this.deployer.address); 53 | } 54 | 55 | getRewardsEndBlock() { 56 | return this.chain.callReadOnlyFn("staking-v1", "get-rewards-end-block", [ 57 | ], this.deployer.address); 58 | } 59 | 60 | stake(caller: Account, amount: number) { 61 | let block = this.chain.mineBlock([ 62 | Tx.contractCall("staking-v1", "stake", [ 63 | types.principal(qualifiedName("sdao-token")), 64 | types.uint(amount * 1000000), 65 | ], caller.address) 66 | ]); 67 | return block.receipts[0].result; 68 | } 69 | 70 | unstake(caller: Account, amount: number) { 71 | let block = this.chain.mineBlock([ 72 | Tx.contractCall("staking-v1", "unstake", [ 73 | types.principal(qualifiedName("sdao-token")), 74 | types.uint(amount * 1000000), 75 | ], caller.address) 76 | ]); 77 | return block.receipts[0].result; 78 | } 79 | 80 | getPendingRewards(staker: string) { 81 | return this.chain.callReadOnlyFn("staking-v1", "get-pending-rewards", [ 82 | types.principal(staker), 83 | ], this.deployer.address); 84 | } 85 | 86 | claimPendingRewards(caller: Account) { 87 | let block = this.chain.mineBlock([ 88 | Tx.contractCall("staking-v1", "claim-pending-rewards", [ 89 | ], caller.address) 90 | ]); 91 | return block.receipts[0].result; 92 | } 93 | 94 | increaseCummRewardPerStake(caller: Account) { 95 | let block = this.chain.mineBlock([ 96 | Tx.contractCall("staking-v1", "increase-cumm-reward-per-stake", [ 97 | ], caller.address) 98 | ]); 99 | return block.receipts[0].result; 100 | } 101 | 102 | calculateCummRewardPerStake(caller: Account) { 103 | let block = this.chain.mineBlock([ 104 | Tx.contractCall("staking-v1", "calculate-cumm-reward-per-stake", [ 105 | ], caller.address) 106 | ]); 107 | return block.receipts[0].result; 108 | } 109 | 110 | addRewards(caller: Account, amount: number, endBlock: number) { 111 | let block = this.chain.mineBlock([ 112 | Tx.contractCall("staking-v1", "add-rewards", [ 113 | types.uint(amount * 1000000), 114 | types.uint(endBlock), 115 | ], caller.address) 116 | ]); 117 | return block.receipts[0].result; 118 | } 119 | 120 | } 121 | export { Staking }; 122 | -------------------------------------------------------------------------------- /tests/wrappers/ststx-token-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // stSTX token 6 | // --------------------------------------------------------- 7 | 8 | class StStxToken { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | getTotalSupply() { 18 | return this.chain.callReadOnlyFn("ststx-token", "get-total-supply", [], this.deployer.address); 19 | } 20 | 21 | getName() { 22 | return this.chain.callReadOnlyFn("ststx-token", "get-name", [], this.deployer.address); 23 | } 24 | 25 | getSymbol() { 26 | return this.chain.callReadOnlyFn("ststx-token", "get-symbol", [], this.deployer.address); 27 | } 28 | 29 | getDecimals() { 30 | return this.chain.callReadOnlyFn("ststx-token", "get-decimals", [], this.deployer.address); 31 | } 32 | 33 | getBalance(account: string) { 34 | return this.chain.callReadOnlyFn("ststx-token", "get-balance", [ 35 | types.principal(account) 36 | ], this.deployer.address); 37 | } 38 | 39 | getTokenUri() { 40 | return this.chain.callReadOnlyFn("ststx-token", "get-token-uri", [], this.deployer.address); 41 | } 42 | 43 | transfer(caller: Account, amount: number, receiver: string) { 44 | let block = this.chain.mineBlock([ 45 | Tx.contractCall("ststx-token", "transfer", [ 46 | types.uint(amount * 1000000), 47 | types.principal(caller.address), 48 | types.principal(receiver), 49 | types.none() 50 | ], caller.address) 51 | ]); 52 | return block.receipts[0].result; 53 | } 54 | 55 | setTokenUri(caller: Account, uri: string) { 56 | let block = this.chain.mineBlock([ 57 | Tx.contractCall("ststx-token", "set-token-uri", [ 58 | types.utf8(uri), 59 | ], caller.address) 60 | ]); 61 | return block.receipts[0].result; 62 | } 63 | 64 | mintForProtocol(caller: Account, amount: number, receiver: string) { 65 | let block = this.chain.mineBlock([ 66 | Tx.contractCall("ststx-token", "mint-for-protocol", [ 67 | types.uint(amount * 1000000), 68 | types.principal(receiver), 69 | ], caller.address) 70 | ]); 71 | return block.receipts[0].result; 72 | } 73 | 74 | burnForProtocol(caller: Account, amount: number, receiver: string) { 75 | let block = this.chain.mineBlock([ 76 | Tx.contractCall("ststx-token", "burn-for-protocol", [ 77 | types.uint(amount * 1000000), 78 | types.principal(receiver), 79 | ], caller.address) 80 | ]); 81 | return block.receipts[0].result; 82 | } 83 | 84 | burn(caller: Account, amount: number) { 85 | let block = this.chain.mineBlock([ 86 | Tx.contractCall("ststx-token", "burn", [ 87 | types.uint(amount * 1000000), 88 | ], caller.address) 89 | ]); 90 | return block.receipts[0].result; 91 | } 92 | 93 | } 94 | export { StStxToken }; 95 | -------------------------------------------------------------------------------- /tests/wrappers/ststx-withdraw-nft-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // stSTX withdraw NFT 11 | // --------------------------------------------------------- 12 | 13 | class StStxWithdrawNft { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | getBaseUri() { 23 | return this.chain.callReadOnlyFn( 24 | "ststx-withdraw-nft-v2", 25 | "get-base-token-uri", 26 | [], 27 | this.deployer.address 28 | ); 29 | } 30 | 31 | getBalance(account: string) { 32 | return this.chain.callReadOnlyFn( 33 | "ststx-withdraw-nft-v2", 34 | "get-balance", 35 | [types.principal(account)], 36 | this.deployer.address 37 | ); 38 | } 39 | 40 | getListingInUstx(tokenId: number) { 41 | return this.chain.callReadOnlyFn( 42 | "ststx-withdraw-nft-v2", 43 | "get-listing-in-ustx", 44 | [types.uint(tokenId)], 45 | this.deployer.address 46 | ); 47 | } 48 | 49 | getLastTokenId() { 50 | return this.chain.callReadOnlyFn( 51 | "ststx-withdraw-nft-v2", 52 | "get-last-token-id", 53 | [], 54 | this.deployer.address 55 | ); 56 | } 57 | 58 | uintToString() { 59 | return this.chain.callReadOnlyFn( 60 | "ststx-withdraw-nft-v2", 61 | "uint-to-string", 62 | [], 63 | this.deployer.address 64 | ); 65 | } 66 | 67 | getTokenUri(tokenId: number) { 68 | return this.chain.callReadOnlyFn( 69 | "ststx-withdraw-nft-v2", 70 | "get-token-uri", 71 | [types.uint(tokenId)], 72 | this.deployer.address 73 | ); 74 | } 75 | 76 | getOwner(tokenId: number) { 77 | return this.chain.callReadOnlyFn( 78 | "ststx-withdraw-nft-v2", 79 | "get-owner", 80 | [types.uint(tokenId)], 81 | this.deployer.address 82 | ); 83 | } 84 | 85 | setBaseUri(caller: Account, root: string) { 86 | let block = this.chain.mineBlock([ 87 | Tx.contractCall( 88 | "ststx-withdraw-nft-v2", 89 | "set-base-token-uri", 90 | [types.ascii(root)], 91 | caller.address 92 | ), 93 | ]); 94 | return block.receipts[0].result; 95 | } 96 | 97 | transfer(caller: Account, tokenId: number, receiver: string) { 98 | let block = this.chain.mineBlock([ 99 | Tx.contractCall( 100 | "ststx-withdraw-nft-v2", 101 | "transfer", 102 | [ 103 | types.uint(tokenId), 104 | types.principal(caller.address), 105 | types.principal(receiver), 106 | ], 107 | caller.address 108 | ), 109 | ]); 110 | return block.receipts[0].result; 111 | } 112 | 113 | mintForProtocol(caller: Account, receiver: string) { 114 | let block = this.chain.mineBlock([ 115 | Tx.contractCall( 116 | "ststx-withdraw-nft-v2", 117 | "mint-for-protocol", 118 | [types.principal(receiver)], 119 | caller.address 120 | ), 121 | ]); 122 | return block.receipts[0].result; 123 | } 124 | 125 | burnForProtocol(caller: Account, tokenId: number) { 126 | let block = this.chain.mineBlock([ 127 | Tx.contractCall( 128 | "ststx-withdraw-nft-v2", 129 | "burn-for-protocol", 130 | [types.uint(tokenId)], 131 | caller.address 132 | ), 133 | ]); 134 | return block.receipts[0].result; 135 | } 136 | 137 | listInUstx(caller: Account, tokenId: number, price: number) { 138 | let block = this.chain.mineBlock([ 139 | Tx.contractCall( 140 | "ststx-withdraw-nft-v2", 141 | "list-in-ustx", 142 | [ 143 | types.uint(tokenId), 144 | types.uint(price * 1000000), 145 | types.principal(qualifiedName("marketplace-commission")), 146 | ], 147 | caller.address 148 | ), 149 | ]); 150 | return block.receipts[0].result; 151 | } 152 | 153 | unlistInUstx(caller: Account, tokenId: number) { 154 | let block = this.chain.mineBlock([ 155 | Tx.contractCall( 156 | "ststx-withdraw-nft-v2", 157 | "unlist-in-ustx", 158 | [types.uint(tokenId)], 159 | caller.address 160 | ), 161 | ]); 162 | return block.receipts[0].result; 163 | } 164 | 165 | buyInUstx(caller: Account, tokenId: number) { 166 | let block = this.chain.mineBlock([ 167 | Tx.contractCall( 168 | "ststx-withdraw-nft-v2", 169 | "buy-in-ustx", 170 | [ 171 | types.uint(tokenId), 172 | types.principal(qualifiedName("marketplace-commission")), 173 | ], 174 | caller.address 175 | ), 176 | ]); 177 | return block.receipts[0].result; 178 | } 179 | } 180 | export { StStxWithdrawNft }; 181 | -------------------------------------------------------------------------------- /tests/wrappers/ststxbtc-withdraw-nft-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // stSTXbtc withdraw NFT 11 | // --------------------------------------------------------- 12 | 13 | class StStxBtcWithdrawNft { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | getBaseUri() { 23 | return this.chain.callReadOnlyFn( 24 | "ststxbtc-withdraw-nft", 25 | "get-base-token-uri", 26 | [], 27 | this.deployer.address 28 | ); 29 | } 30 | 31 | getBalance(account: string) { 32 | return this.chain.callReadOnlyFn( 33 | "ststxbtc-withdraw-nft", 34 | "get-balance", 35 | [types.principal(account)], 36 | this.deployer.address 37 | ); 38 | } 39 | 40 | getListingInUstx(tokenId: number) { 41 | return this.chain.callReadOnlyFn( 42 | "ststxbtc-withdraw-nft", 43 | "get-listing-in-ustx", 44 | [types.uint(tokenId)], 45 | this.deployer.address 46 | ); 47 | } 48 | 49 | getLastTokenId() { 50 | return this.chain.callReadOnlyFn( 51 | "ststxbtc-withdraw-nft", 52 | "get-last-token-id", 53 | [], 54 | this.deployer.address 55 | ); 56 | } 57 | 58 | uintToString() { 59 | return this.chain.callReadOnlyFn( 60 | "ststxbtc-withdraw-nft", 61 | "uint-to-string", 62 | [], 63 | this.deployer.address 64 | ); 65 | } 66 | 67 | getTokenUri(tokenId: number) { 68 | return this.chain.callReadOnlyFn( 69 | "ststxbtc-withdraw-nft", 70 | "get-token-uri", 71 | [types.uint(tokenId)], 72 | this.deployer.address 73 | ); 74 | } 75 | 76 | getOwner(tokenId: number) { 77 | return this.chain.callReadOnlyFn( 78 | "ststxbtc-withdraw-nft", 79 | "get-owner", 80 | [types.uint(tokenId)], 81 | this.deployer.address 82 | ); 83 | } 84 | 85 | setBaseUri(caller: Account, root: string) { 86 | let block = this.chain.mineBlock([ 87 | Tx.contractCall( 88 | "ststxbtc-withdraw-nft", 89 | "set-base-token-uri", 90 | [types.ascii(root)], 91 | caller.address 92 | ), 93 | ]); 94 | return block.receipts[0].result; 95 | } 96 | 97 | transfer(caller: Account, tokenId: number, receiver: string) { 98 | let block = this.chain.mineBlock([ 99 | Tx.contractCall( 100 | "ststxbtc-withdraw-nft", 101 | "transfer", 102 | [ 103 | types.uint(tokenId), 104 | types.principal(caller.address), 105 | types.principal(receiver), 106 | ], 107 | caller.address 108 | ), 109 | ]); 110 | return block.receipts[0].result; 111 | } 112 | 113 | mintForProtocol(caller: Account, receiver: string) { 114 | let block = this.chain.mineBlock([ 115 | Tx.contractCall( 116 | "ststxbtc-withdraw-nft", 117 | "mint-for-protocol", 118 | [types.principal(receiver)], 119 | caller.address 120 | ), 121 | ]); 122 | return block.receipts[0].result; 123 | } 124 | 125 | burnForProtocol(caller: Account, tokenId: number) { 126 | let block = this.chain.mineBlock([ 127 | Tx.contractCall( 128 | "ststxbtc-withdraw-nft", 129 | "burn-for-protocol", 130 | [types.uint(tokenId)], 131 | caller.address 132 | ), 133 | ]); 134 | return block.receipts[0].result; 135 | } 136 | 137 | listInUstx(caller: Account, tokenId: number, price: number) { 138 | let block = this.chain.mineBlock([ 139 | Tx.contractCall( 140 | "ststxbtc-withdraw-nft", 141 | "list-in-ustx", 142 | [ 143 | types.uint(tokenId), 144 | types.uint(price * 1000000), 145 | types.principal(qualifiedName("marketplace-commission")), 146 | ], 147 | caller.address 148 | ), 149 | ]); 150 | return block.receipts[0].result; 151 | } 152 | 153 | unlistInUstx(caller: Account, tokenId: number) { 154 | let block = this.chain.mineBlock([ 155 | Tx.contractCall( 156 | "ststxbtc-withdraw-nft", 157 | "unlist-in-ustx", 158 | [types.uint(tokenId)], 159 | caller.address 160 | ), 161 | ]); 162 | return block.receipts[0].result; 163 | } 164 | 165 | buyInUstx(caller: Account, tokenId: number) { 166 | let block = this.chain.mineBlock([ 167 | Tx.contractCall( 168 | "ststxbtc-withdraw-nft", 169 | "buy-in-ustx", 170 | [ 171 | types.uint(tokenId), 172 | types.principal(qualifiedName("marketplace-commission")), 173 | ], 174 | caller.address 175 | ), 176 | ]); 177 | return block.receipts[0].result; 178 | } 179 | } 180 | export { StStxBtcWithdrawNft }; 181 | -------------------------------------------------------------------------------- /tests/wrappers/swap-ststx-ststxbtc-helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Tx, 3 | Chain, 4 | Account, 5 | types, 6 | } from "https://deno.land/x/clarinet/index.ts"; 7 | import { qualifiedName } from "./tests-utils.ts"; 8 | 9 | // --------------------------------------------------------- 10 | // Swap stSTX / stSTXbtc 11 | // --------------------------------------------------------- 12 | 13 | class SwapStStxBtc { 14 | chain: Chain; 15 | deployer: Account; 16 | 17 | constructor(chain: Chain, deployer: Account) { 18 | this.chain = chain; 19 | this.deployer = deployer; 20 | } 21 | 22 | swapStStxForStStxBtc(caller: Account, amount: number) { 23 | let block = this.chain.mineBlock([ 24 | Tx.contractCall( 25 | "swap-ststx-ststxbtc-v2", 26 | "swap-ststx-for-ststxbtc", 27 | [ 28 | types.uint(amount * 1000000), 29 | types.principal(qualifiedName("reserve-v1")), 30 | ], 31 | caller.address 32 | ), 33 | ]); 34 | return block.receipts[0].result; 35 | } 36 | 37 | swapStStxBtcForStStx(caller: Account, amount: number) { 38 | let block = this.chain.mineBlock([ 39 | Tx.contractCall( 40 | "swap-ststx-ststxbtc-v2", 41 | "swap-ststxbtc-for-ststx", 42 | [ 43 | types.uint(amount * 1000000), 44 | types.principal(qualifiedName("reserve-v1")), 45 | ], 46 | caller.address 47 | ), 48 | ]); 49 | return block.receipts[0].result; 50 | } 51 | } 52 | export { SwapStStxBtc }; 53 | -------------------------------------------------------------------------------- /tests/wrappers/tax-helpers.ts: -------------------------------------------------------------------------------- 1 | import { Tx, Chain, Account, types } from 'https://deno.land/x/clarinet/index.ts'; 2 | import { qualifiedName } from './tests-utils.ts'; 3 | 4 | // --------------------------------------------------------- 5 | // sDAO Tax 6 | // --------------------------------------------------------- 7 | 8 | class Tax { 9 | chain: Chain; 10 | deployer: Account; 11 | 12 | constructor(chain: Chain, deployer: Account) { 13 | this.chain = chain; 14 | this.deployer = deployer; 15 | } 16 | 17 | shouldHandleTax() { 18 | return this.chain.callReadOnlyFn("tax-v1", "should-handle-tax", [], this.deployer.address); 19 | } 20 | 21 | getMinBalanceToHandle() { 22 | return this.chain.callReadOnlyFn("tax-v1", "get-min-balance-to-handle", [], this.deployer.address); 23 | } 24 | 25 | getPercentageToSwap() { 26 | return this.chain.callReadOnlyFn("tax-v1", "get-percentage-to-swap", [], this.deployer.address); 27 | } 28 | 29 | checkJob() { 30 | return this.chain.callReadOnlyFn("tax-v1", "check-job", [], this.deployer.address); 31 | } 32 | 33 | initialize(caller: Account) { 34 | let block = this.chain.mineBlock([ 35 | Tx.contractCall("tax-v1", "initialize", [ 36 | ], caller.address) 37 | ]); 38 | return block.receipts[0].result; 39 | } 40 | 41 | runJob(caller: Account) { 42 | let block = this.chain.mineBlock([ 43 | Tx.contractCall("tax-v1", "run-job", [ 44 | ], caller.address) 45 | ]); 46 | return block.receipts[0].result; 47 | } 48 | 49 | handleTax(caller: Account) { 50 | let block = this.chain.mineBlock([ 51 | Tx.contractCall("tax-v1", "handle-tax", [ 52 | ], caller.address) 53 | ]); 54 | return block.receipts[0].result; 55 | } 56 | 57 | retreiveStxTokens(caller: Account, amount: number, receiver: string) { 58 | let block = this.chain.mineBlock([ 59 | Tx.contractCall("tax-v1", "retreive-stx-tokens", [ 60 | types.uint(amount * 1000000), 61 | types.principal(receiver) 62 | ], caller.address) 63 | ]); 64 | return block.receipts[0].result; 65 | } 66 | 67 | retreiveTokens(caller: Account, token: string, amount: number, receiver: string) { 68 | let block = this.chain.mineBlock([ 69 | Tx.contractCall("tax-v1", "retreive-tokens", [ 70 | types.principal(qualifiedName(token)), 71 | types.uint(amount * 1000000), 72 | types.principal(receiver) 73 | ], caller.address) 74 | ]); 75 | return block.receipts[0].result; 76 | } 77 | 78 | setMinBalanceToHandle(caller: Account, minBalance: number) { 79 | let block = this.chain.mineBlock([ 80 | Tx.contractCall("tax-v1", "set-min-balance-to-handle ", [ 81 | types.uint(minBalance * 1000000) 82 | ], caller.address) 83 | ]); 84 | return block.receipts[0].result; 85 | } 86 | 87 | setPercentageToSwap(caller: Account, percentage: number) { 88 | let block = this.chain.mineBlock([ 89 | Tx.contractCall("tax-v1", "set-percentage-to-swap", [ 90 | types.uint(percentage * 10000) 91 | ], caller.address) 92 | ]); 93 | return block.receipts[0].result; 94 | } 95 | } 96 | export { Tax }; 97 | -------------------------------------------------------------------------------- /tests/wrappers/tests-utils.ts: -------------------------------------------------------------------------------- 1 | // Get full qualified name based on contract name 2 | export function qualifiedName(contractName: string) { 3 | return "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM." + contractName; 4 | } 5 | 6 | // Extra methods on String type 7 | declare global { 8 | interface String { 9 | expectUintWithDecimals(value: number | bigint): bigint; 10 | } 11 | } 12 | 13 | // Expect Uint with 6 decimals 14 | String.prototype.expectUintWithDecimals = function ( 15 | value: number, 16 | decimals: number = 6 17 | ): bigint { 18 | return this.expectUint(Math.round(value * Math.pow(10, decimals))); 19 | }; 20 | 21 | export function hexDecode(hex: string) { 22 | let bytes = []; 23 | hex.replace(/../g, function (pair) { 24 | bytes.push(parseInt(pair, 16)); 25 | }); 26 | return new Uint8Array(bytes).buffer; 27 | } 28 | 29 | // Convert hex to bytes 30 | export function hexToBytes(hex: string) { 31 | return hexToBytesHelper( 32 | hex.substring(0, 2) === "0x" ? hex.substring(2) : hex 33 | ); 34 | } 35 | 36 | export const REWARD_CYCLE_LENGTH = 21; // pox-3 is 2100 37 | export const PREPARE_PHASE_LENGTH = 3; // pox-3 is 100 38 | 39 | function hexToBytesHelper(hex: string) { 40 | if (typeof hex !== "string") 41 | throw new TypeError("hexToBytes: expected string, got " + typeof hex); 42 | if (hex.length % 2) 43 | throw new Error( 44 | `hexToBytes: received invalid unpadded hex, got: ${hex.length}` 45 | ); 46 | const array = new Uint8Array(hex.length / 2); 47 | for (let i = 0; i < array.length; i++) { 48 | const j = i * 2; 49 | array[i] = Number.parseInt(hex.slice(j, j + 2), 16); 50 | } 51 | return array; 52 | } 53 | --------------------------------------------------------------------------------