diff --git a/clarity/Clarinet.toml b/clarity/Clarinet.toml index b2d47e58..b525f95e 100644 --- a/clarity/Clarinet.toml +++ b/clarity/Clarinet.toml @@ -2,9 +2,13 @@ name = "alex-v1" requirements = [] +[contracts.trait-semi-fungible-token] +path = "contracts/traits/trait-semi-fungible-token.clar" +depends_on = [] + [contracts.margin-helper] path = "contracts/helpers/margin-helper.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "trait-flash-loan-user"] +depends_on = ["trait-sip-010", "trait-flash-loan-user"] [contracts.alex-staking-helper] path = "contracts/helpers/alex-staking-helper.clar" @@ -12,15 +16,19 @@ depends_on = ["alex-reserve-pool"] [contracts.alex-reserve-pool] path = "contracts/pool/alex-reserve-pool.clar" -depends_on = ["trait-ownable", "trait-pool-token", "alex-vault"] +depends_on = ["trait-ownable", "trait-sip-010", "alex-vault"] + +[contracts.alex-futures-pool] +path = "contracts/pool/alex-futures-pool.clar" +depends_on = ["trait-ownable", "token-alex", "trait-semi-fungible-token", "trait-multisig-vote", "alex-reserve-pool"] [contracts.alex-vault] path = "contracts/alex-vault.clar" -depends_on = ["trait-vault", "trait-sip-010", "trait-flash-loan-user", "math-fixed-point", "trait-ownable", "trait-yield-token"] +depends_on = ["trait-vault", "trait-sip-010", "trait-flash-loan-user", "math-fixed-point", "trait-ownable", "trait-semi-fungible-token"] [contracts.collateral-rebalancing-pool] path = "contracts/pool/collateral-rebalancing-pool.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "trait-vault", "math-fixed-point", "weighted-equation", "fixed-weight-pool", "token-usda", "token-alex", "alex-reserve-pool", "yield-token-pool"] +depends_on = ["trait-sip-010", "trait-vault", "math-fixed-point", "weighted-equation", "fixed-weight-pool", "token-usda", "token-alex", "alex-reserve-pool", "yield-token-pool"] [contracts.faucet] path = "contracts/faucet.clar" @@ -28,15 +36,11 @@ depends_on = ["token-wbtc", "token-usda", "token-t-alex", "token-wstx"] [contracts.fixed-weight-pool] path = "contracts/pool/fixed-weight-pool.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-vault", "math-fixed-point", "weighted-equation", "token-alex", "alex-reserve-pool", "token-usda", "trait-multisig-vote"] - -[contracts.fwp-wbtc-usda-50-50] -path = "contracts/pool-token/fwp-wbtc-usda-50-50.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] +depends_on = ["trait-sip-010", "trait-vault", "math-fixed-point", "weighted-equation", "token-alex", "alex-reserve-pool", "token-usda", "trait-multisig-vote"] [contracts.liquidity-bootstrapping-pool] path = "contracts/pool/liquidity-bootstrapping-pool.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-vault", "math-fixed-point", "weighted-equation", "token-alex", "alex-reserve-pool", "token-usda", "fixed-weight-pool", "trait-multisig-vote"] +depends_on = ["trait-sip-010", "trait-vault", "math-fixed-point", "weighted-equation", "token-alex", "alex-reserve-pool", "token-usda", "fixed-weight-pool", "trait-multisig-vote"] [contracts.math-fixed-point] path = "contracts/lib/math-fixed-point.clar" @@ -54,29 +58,25 @@ depends_on = ["math-new-log-exp"] path = "contracts/new-lib/math-new-log-exp.clar" depends_on = [] -[contracts.multisig-fwp-wbtc-usda-50-50] -path = "contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar" -depends_on = [] - [contracts.token-alex] path = "contracts/token/token-alex.clar" -depends_on = ["trait-pool-token", "trait-ownable"] +depends_on = ["trait-ownable", "trait-sip-010"] [contracts.token-t-alex] path = "contracts/token/token-t-alex.clar" -depends_on = ["trait-pool-token", "trait-ownable"] +depends_on = ["trait-ownable", "trait-sip-010"] [contracts.token-usda] path = "contracts/token/token-usda.clar" -depends_on = ["trait-pool-token", "trait-ownable"] +depends_on = ["trait-ownable", "trait-sip-010"] [contracts.token-wbtc] path = "contracts/token/token-wbtc.clar" -depends_on = ["trait-pool-token", "trait-ownable"] +depends_on = ["trait-ownable", "trait-sip-010"] [contracts.token-wstx] path = "contracts/token/token-wstx.clar" -depends_on = ["trait-pool-token", "trait-ownable", "alex-vault"] +depends_on = ["trait-ownable", "alex-vault", "trait-sip-010"] [contracts.trait-flash-loan-user] path = "contracts/traits/trait-flash-loan-user.clar" @@ -94,10 +94,6 @@ depends_on = [] path = "contracts/traits/trait-ownable.clar" depends_on = [] -[contracts.trait-pool-token] -path = "contracts/traits/trait-pool-token.clar" -depends_on = [] - [contracts.trait-sip-010] path = "contracts/traits/trait-sip-010.clar" depends_on = [] @@ -106,10 +102,6 @@ depends_on = [] path = "contracts/traits/trait-vault.clar" depends_on = ["trait-sip-010", "trait-flash-loan-user"] -[contracts.trait-yield-token] -path = "contracts/traits/trait-yield-token.clar" -depends_on = [] - [contracts.weighted-equation] path = "contracts/equations/weighted-equation.clar" depends_on = ["math-fixed-point"] @@ -120,128 +112,72 @@ depends_on = ["math-fixed-point"] [contracts.yield-token-pool] path = "contracts/pool/yield-token-pool.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-vault", "trait-flash-loan-user", "math-fixed-point", "yield-token-equation", "trait-yield-token", "token-alex", "token-usda", "fixed-weight-pool", "alex-reserve-pool", "trait-multisig-vote"] - -[contracts.yield-wbtc-59760] -path = "contracts/yield-token/yield-wbtc-59760.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.yield-usda-59760] -path = "contracts/yield-token/yield-usda-59760.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] - -[contracts.multisig-ytp-yield-wbtc-59760-wbtc] -path = "contracts/multisig/multisig-ytp-yield-wbtc-59760-wbtc.clar" -depends_on = ["ytp-yield-wbtc-59760-wbtc", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-wbtc-59760"] - -[contracts.flash-loan-user-margin-usda-wbtc-59760] -path = "contracts/flash-loan-user-margin-usda-wbtc-59760.clar" -depends_on = ["token-usda", "token-wbtc", "yield-wbtc-59760", "key-wbtc-59760-usda", "trait-sip-010"] - -[contracts.multisig-crp-wbtc-59760-usda] -path = "contracts/multisig/multisig-crp-wbtc-59760-usda.clar" -depends_on = ["yield-wbtc-59760", "key-wbtc-59760-usda", "token-wbtc", "token-usda", "trait-sip-010"] - -[contracts.multisig-crp-wbtc-59760-wbtc] -path = "contracts/multisig/multisig-crp-wbtc-59760-wbtc.clar" -depends_on = ["yield-wbtc-59760", "key-wbtc-59760-wbtc", "token-wbtc", "trait-sip-010"] - -[contracts.key-wbtc-59760-usda] -path = "contracts/key-token/key-wbtc-59760-usda.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] +depends_on = ["trait-sip-010", "trait-vault", "trait-flash-loan-user", "math-fixed-point", "yield-token-equation", "trait-semi-fungible-token", "token-alex", "token-usda", "fixed-weight-pool", "alex-reserve-pool", "trait-multisig-vote"] -[contracts.key-wbtc-59760-wbtc] -path = "contracts/key-token/key-wbtc-59760-wbtc.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.ytp-yield-wbtc-59760-wbtc] -path = "contracts/pool-token/ytp-yield-wbtc-59760-wbtc.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] - -[contracts.multisig-crp-wbtc-79760-usda] -path = "contracts/multisig/multisig-crp-wbtc-79760-usda.clar" -depends_on = ["yield-wbtc-79760", "key-wbtc-79760-usda", "token-wbtc", "token-usda", "trait-sip-010"] - -[contracts.yield-wbtc-79760] -path = "contracts/yield-token/yield-wbtc-79760.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.multisig-ytp-yield-wbtc-79760-wbtc] -path = "contracts/multisig/multisig-ytp-yield-wbtc-79760-wbtc.clar" -depends_on = ["ytp-yield-wbtc-79760-wbtc", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-wbtc-79760"] - -[contracts.key-wbtc-79760-usda] -path = "contracts/key-token/key-wbtc-79760-usda.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.ytp-yield-wbtc-79760-wbtc] -path = "contracts/pool-token/ytp-yield-wbtc-79760-wbtc.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] - -[contracts.yield-usda-23040] -path = "contracts/yield-token/yield-usda-23040.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] - -[contracts.flash-loan-user-margin-wbtc-usda-23040] -path = "contracts/flash-loan-user-margin-wbtc-usda-23040.clar" -depends_on = ["token-usda", "token-wbtc", "yield-usda-23040", "key-usda-23040-wbtc", "trait-sip-010"] - -[contracts.key-usda-23040-wbtc] -path = "contracts/key-token/key-usda-23040-wbtc.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.ytp-yield-usda-23040-usda] -path = "contracts/pool-token/ytp-yield-usda-23040-usda.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] - -[contracts.multisig-ytp-yield-usda-23040-usda] -path = "contracts/multisig/multisig-ytp-yield-usda-23040-usda.clar" -depends_on = ["ytp-yield-usda-23040-usda", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-usda-23040"] - -[contracts.multisig-crp-usda-23040-wbtc] -path = "contracts/multisig/multisig-crp-usda-23040-wbtc.clar" -depends_on = ["yield-usda-23040", "key-usda-23040-wbtc", "token-wbtc", "token-usda", "trait-sip-010"] +[contracts.fwp-wbtc-usda-50-50] +path = "contracts/pool-token/fwp-wbtc-usda-50-50.clar" +depends_on = ["trait-sip-010", "trait-ownable"] [contracts.lbp-alex-usda-90-10] path = "contracts/pool-token/lbp-alex-usda-90-10.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] +depends_on = ["trait-sip-010", "trait-ownable"] + +[contracts.ytp-yield-usda] +path = "contracts/pool-token/ytp-yield-usda.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] + +[contracts.multisig-fwp-wbtc-usda-50-50] +path = "contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar" +depends_on = [] [contracts.multisig-lbp-alex-usda-90-10] path = "contracts/multisig/multisig-lbp-alex-usda-90-10.clar" depends_on = [] -[contracts.yield-wbtc-80875] -path = "contracts/yield-token/yield-wbtc-80875.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] +[contracts.multisig-crp-usda-wbtc] +path = "contracts/multisig/multisig-crp-usda-wbtc.clar" +depends_on = ["yield-usda", "key-usda-wbtc"] + +[contracts.multisig-crp-wbtc-wbtc] +path = "contracts/multisig/multisig-crp-wbtc-wbtc.clar" +depends_on = ["yield-wbtc", "key-wbtc-wbtc"] + +[contracts.multisig-crp-wbtc-usda] +path = "contracts/multisig/multisig-crp-wbtc-usda.clar" +depends_on = ["yield-wbtc", "key-wbtc-usda"] + +[contracts.multisig-ytp-yield-usda] +path = "contracts/multisig/multisig-ytp-yield-usda.clar" +depends_on = ["ytp-yield-usda", "yield-usda"] -[contracts.multisig-ytp-yield-wbtc-80875-wbtc] -path = "contracts/multisig/multisig-ytp-yield-wbtc-80875-wbtc.clar" -depends_on = ["ytp-yield-wbtc-80875-wbtc", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-wbtc-80875"] +[contracts.key-usda-wbtc] +path = "contracts/key-token/key-usda-wbtc.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.ytp-yield-wbtc-80875-wbtc] -path = "contracts/pool-token/ytp-yield-wbtc-80875-wbtc.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] +[contracts.key-wbtc-usda] +path = "contracts/key-token/key-wbtc-usda.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.yield-usda-51840] -path = "contracts/yield-token/yield-usda-51840.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] +[contracts.key-wbtc-wbtc] +path = "contracts/key-token/key-wbtc-wbtc.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.flash-loan-user-margin-wbtc-usda-51840] -path = "contracts/flash-loan-user-margin-wbtc-usda-51840.clar" -depends_on = ["token-usda", "token-wbtc", "yield-usda-51840", "key-usda-51840-wbtc", "trait-sip-010"] +[contracts.yield-usda] +path = "contracts/yield-token/yield-usda.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.key-usda-51840-wbtc] -path = "contracts/key-token/key-usda-51840-wbtc.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] +[contracts.yield-wbtc] +path = "contracts/yield-token/yield-wbtc.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.ytp-yield-usda-51840-usda] -path = "contracts/pool-token/ytp-yield-usda-51840-usda.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] +[contracts.multisig-ytp-yield-wbtc] +path = "contracts/multisig/multisig-ytp-yield-wbtc.clar" +depends_on = ["ytp-yield-wbtc", "yield-wbtc"] -[contracts.multisig-ytp-yield-usda-51840-usda] -path = "contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar" -depends_on = ["ytp-yield-usda-51840-usda", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-usda-51840"] +[contracts.ytp-yield-wbtc] +path = "contracts/pool-token/ytp-yield-wbtc.clar" +depends_on = ["trait-ownable", "trait-semi-fungible-token"] -[contracts.multisig-crp-usda-51840-wbtc] -path = "contracts/multisig/multisig-crp-usda-51840-wbtc.clar" -depends_on = ["yield-usda-51840", "key-usda-51840-wbtc", "token-wbtc", "token-usda", "trait-sip-010"] +[contracts.flash-loan-user-margin-usda-wbtc] +path = "contracts/flash-loan-user-margin-usda-wbtc.clar" +depends_on = ["trait-sip-010", "trait-flash-loan-user", "yield-usda", "key-usda-wbtc"] \ No newline at end of file diff --git a/clarity/contracts/alex-vault.clar b/clarity/contracts/alex-vault.clar index 2afc5ec6..6aa40ebb 100644 --- a/clarity/contracts/alex-vault.clar +++ b/clarity/contracts/alex-vault.clar @@ -1,24 +1,18 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-vault.vault-trait) (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait pool-token-trait .trait-pool-token.pool-token-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) (use-trait flash-loan-user-trait .trait-flash-loan-user.flash-loan-user-trait) (define-constant ONE_8 (pow u10 u8)) ;; 8 decimal places (define-constant ERR-NOT-AUTHORIZED (err u1000)) (define-constant ERR-INSUFFICIENT-FLASH-LOAN-BALANCE (err u3003)) -(define-constant ERR-INVALID-POST-LOAN-BALANCE (err u3004)) -(define-constant ERR-USER-EXECUTE (err u3005)) (define-constant ERR-TRANSFER-FAILED (err u3000)) -(define-constant ERR-STX-TRANSFER-FAILED (err u3001)) +(define-constant ERR-STX-TRANSFER-FAILED (err u9003)) (define-constant ERR-LOAN-TRANSFER-FAILED (err u3006)) (define-constant ERR-POST-LOAN-TRANSFER-FAILED (err u3007)) (define-constant ERR-INVALID-FLASH-LOAN (err u3008)) -(define-constant ERR-INVALID-BALANCE (err u3011)) -(define-constant ERR-MATH-CALL (err u2010)) -(define-constant ERR-INTERNAL-FUNCTION-CALL (err u1001)) (define-data-var CONTRACT-OWNER principal tx-sender) @@ -55,14 +49,14 @@ ;; return token balance held by vault (define-public (get-balance (token )) - (contract-call? token get-balance (as-contract tx-sender)) + (contract-call? token get-balance-fixed (as-contract tx-sender)) ) ;; if sender is an approved contract, then transfer requested amount :qfrom vault to recipient (define-public (transfer-ft (token ) (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (as-contract (unwrap! (contract-call? token transfer amount tx-sender recipient none) ERR-TRANSFER-FAILED)) + (as-contract (unwrap! (contract-call? token transfer-fixed amount tx-sender recipient none) ERR-TRANSFER-FAILED)) (ok true) ) ) @@ -75,30 +69,21 @@ ) ) -(define-public (transfer-yield (token ) (amount uint) (recipient principal)) +(define-public (transfer-sft (token ) (token-id uint) (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (as-contract (unwrap! (contract-call? token transfer amount tx-sender recipient none) ERR-TRANSFER-FAILED)) - (ok true) - ) -) - -(define-public (transfer-pool (token ) (amount uint) (recipient principal)) - (begin - (try! (check-is-approved contract-caller)) - (as-contract (unwrap! (contract-call? token transfer amount tx-sender recipient none) ERR-TRANSFER-FAILED)) + (as-contract (unwrap! (contract-call? token transfer-fixed token-id amount tx-sender recipient) ERR-TRANSFER-FAILED)) (ok true) ) ) ;; perform flash loan -;; (define-public (flash-loan (flash-loan-user ) (token ) (amount uint) (memo (optional (string-utf8 256)))) -(define-public (flash-loan (flash-loan-user ) (token ) (amount uint)) +(define-public (flash-loan (flash-loan-user ) (token ) (amount uint) (memo (optional uint))) (let ( (pre-bal (unwrap! (get-balance token) ERR-INVALID-FLASH-LOAN)) (fee-with-principal (+ ONE_8 (var-get flash-loan-fee-rate))) - (amount-with-fee (contract-call? .math-fixed-point mul-up amount fee-with-principal)) + (amount-with-fee (mul-up amount fee-with-principal)) (recipient tx-sender) ) @@ -106,11 +91,10 @@ (asserts! (> pre-bal amount) ERR-INSUFFICIENT-FLASH-LOAN-BALANCE) ;; transfer loan to flash-loan-user - (as-contract (unwrap! (contract-call? token transfer amount tx-sender recipient none) ERR-LOAN-TRANSFER-FAILED)) + (as-contract (unwrap! (contract-call? token transfer-fixed amount tx-sender recipient none) ERR-LOAN-TRANSFER-FAILED)) ;; flash-loan-user executes with loan received - ;; (try! (contract-call? flash-loan-user execute token amount memo)) - (try! (contract-call? flash-loan-user execute token amount)) + (try! (contract-call? flash-loan-user execute token amount memo)) ;; return the loan + fee (unwrap! (contract-call? token transfer amount-with-fee tx-sender (as-contract tx-sender) none) ERR-POST-LOAN-TRANSFER-FAILED) @@ -126,6 +110,22 @@ ) ) +(define-read-only (mul-down (a uint) (b uint)) + (/ (* a b) ONE_8) +) + +(define-read-only (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) + ;; contract initialisation (begin (map-set approved-contracts .alex-reserve-pool true) diff --git a/clarity/contracts/equations/weighted-equation.clar b/clarity/contracts/equations/weighted-equation.clar index d4bfb98e..6f6dbd9c 100644 --- a/clarity/contracts/equations/weighted-equation.clar +++ b/clarity/contracts/equations/weighted-equation.clar @@ -286,16 +286,6 @@ ;; Fixed Point Math ;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -304,18 +294,6 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - -(define-read-only (scale-up (a uint)) - (* a ONE_8) -) - -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -415,11 +393,10 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) ;; private functions ;; @@ -484,14 +461,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -552,10 +529,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -571,7 +548,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -580,30 +557,4 @@ (exp-pos x) ) ) -) - -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - -;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. -(define-read-only (ln-fixed (a int)) - (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) - (if (< a iONE_8) - ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). - ;; If a is less than one, 1/a will be greater than one. - ;; Fixed point division requires multiplying by iONE_8. - (ok (- 0 (unwrap-panic (ln-priv (/ (* iONE_8 iONE_8) a))))) - (ln-priv a) - ) - ) ) \ No newline at end of file diff --git a/clarity/contracts/equations/yield-token-equation.clar b/clarity/contracts/equations/yield-token-equation.clar index 1f492194..14d617d4 100644 --- a/clarity/contracts/equations/yield-token-equation.clar +++ b/clarity/contracts/equations/yield-token-equation.clar @@ -9,11 +9,10 @@ (define-constant ERR-NOT-AUTHORIZED (err u1000)) (define-constant ERR-NO-LIQUIDITY (err u2002)) -(define-constant ERR-WEIGHT-SUM (err u4000)) (define-constant ERR-MAX-IN-RATIO (err u4001)) (define-constant ERR-MAX-OUT-RATIO (err u4002)) -(define-constant ERR-INSUFFICIENT-BAL (err u4004)) -(define-constant ERR-INVALID-BAL (err u2008)) +(define-constant ERR-INSUFFICIENT-BALANCE (err u4004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) (define-data-var CONTRACT-OWNER principal tx-sender) @@ -82,7 +81,7 @@ ;; @returns (response uint uint) (define-read-only (get-price (balance-x uint) (balance-y uint) (t uint)) (begin - (asserts! (>= balance-y balance-x) ERR-INVALID-BAL) + (asserts! (>= balance-y balance-x) ERR-INVALID-BALANCE) (ok (pow-up (div-down balance-y balance-x) t)) ) ) @@ -114,7 +113,7 @@ ;; @returns (response uint uint) (define-read-only (get-y-given-x (balance-x uint) (balance-y uint) (t uint) (dx uint)) (begin - (asserts! (>= balance-x dx) ERR-INSUFFICIENT-BAL) + (asserts! (>= balance-x dx) ERR-INSUFFICIENT-BALANCE) (asserts! (< dx (mul-down balance-x (var-get MAX-IN-RATIO))) ERR-MAX-IN-RATIO) (let ( @@ -149,7 +148,7 @@ ;; @returns (response uint uint) (define-read-only (get-x-given-y (balance-x uint) (balance-y uint) (t uint) (dy uint)) (begin - (asserts! (>= balance-y dy) ERR-INSUFFICIENT-BAL) + (asserts! (>= balance-y dy) ERR-INSUFFICIENT-BALANCE) (asserts! (< dy (mul-down balance-y (var-get MAX-OUT-RATIO))) ERR-MAX-OUT-RATIO) (let ( @@ -314,16 +313,6 @@ ;; Fixed Point Math ;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -332,18 +321,6 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - -(define-read-only (scale-up (a uint)) - (* a ONE_8) -) - -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -368,13 +345,6 @@ ) ) -(define-read-only (div-up (a uint) (b uint)) - (if (is-eq a u0) - u0 - (+ u1 (/ (- (* a ONE_8) u1) b)) - ) -) - (define-read-only (pow-down (a uint) (b uint)) (let ( @@ -443,11 +413,11 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) +(define-constant ERR_OUT_OF_BOUNDS (err u5013)) ;; private functions ;; @@ -512,14 +482,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -580,10 +550,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -599,7 +569,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -610,22 +580,10 @@ ) ) -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - ;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. (define-read-only (ln-fixed (a int)) (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) + (asserts! (> a 0) ERR_OUT_OF_BOUNDS) (if (< a iONE_8) ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). ;; If a is less than one, 1/a will be greater than one. @@ -635,24 +593,3 @@ ) ) ) - -(define-read-only (test) - (let - ( - (x (* u7 (pow u10 u6))) - (y (* u233 (pow u10 u6))) - (x-int (to-int x)) - (y-int (to-int y)) - (lnx (unwrap-panic (ln-priv x-int))) - (logx-times-y (/ (* lnx y-int) iONE_8)) - ;;(r (exp-pos (* -1 logx-times-y))) - - ;;(arg (* 69 iONE_8)) - ;;(r (exp-pos arg)) - ;;(x_product (fold accumulate_product x_a_list {x: arg, product: iONE_8})) - ) - ;;(ok logx-times-y) - ;;x_product - (ok (pow-fixed x y)) - ) -) diff --git a/clarity/contracts/faucet.clar b/clarity/contracts/faucet.clar index edfbfcbc..66da7363 100644 --- a/clarity/contracts/faucet.clar +++ b/clarity/contracts/faucet.clar @@ -118,16 +118,16 @@ ) (map-set users recipient u1) ) - (and (> (var-get wbtc-amount) u0) (unwrap! (contract-call? .token-wbtc mint recipient (var-get wbtc-amount)) ERR-WBTC-TRANSFER-FAILED)) - (and (> (var-get usda-amount) u0) (unwrap! (contract-call? .token-usda mint recipient (var-get usda-amount)) ERR-USDA-TRANSFER-FAILED)) - (and (> (var-get alex-amount) u0) (unwrap! (contract-call? .token-t-alex mint recipient (var-get alex-amount)) ERR-ALEX-TRANSFER-FAILED)) + (and (> (var-get wbtc-amount) u0) (unwrap! (contract-call? .token-wbtc mint (var-get wbtc-amount) recipient) ERR-WBTC-TRANSFER-FAILED)) + (and (> (var-get usda-amount) u0) (unwrap! (contract-call? .token-usda mint (var-get usda-amount) recipient) ERR-USDA-TRANSFER-FAILED)) + (and (> (var-get alex-amount) u0) (unwrap! (contract-call? .token-t-alex mint (var-get alex-amount) recipient) ERR-ALEX-TRANSFER-FAILED)) (and (> (var-get stx-amount) u0) (unwrap! (stx-transfer? (/ (* (var-get stx-amount) (pow u10 u6)) ONE_8) tx-sender recipient) ERR-STX-TRANSFER-FAILED)) (ok true) ) ) (define-public (get-some-wstx-tokens) - (contract-call? .token-wstx mint tx-sender (var-get wstx-amount)) + (contract-call? .token-wstx mint (var-get wstx-amount) tx-sender) ) ;; SEND-MANY @@ -147,7 +147,7 @@ ) (define-private (mint-alex (recipient { to: principal, amount: uint })) - (ok (and (> (get amount recipient) u0) (unwrap! (contract-call? .token-t-alex mint (get to recipient) (get amount recipient)) ERR-ALEX-TRANSFER-FAILED))) + (ok (and (> (get amount recipient) u0) (unwrap! (contract-call? .token-t-alex mint (get amount recipient) (get to recipient)) ERR-ALEX-TRANSFER-FAILED))) ) (define-public (mint-alex-many (recipients (list 200 { to: principal, amount: uint }))) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar deleted file mode 100644 index 94bec467..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-11520 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-11520))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-11520 .key-wbtc-11520-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-11520", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-121195.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-121195.clar deleted file mode 100644 index 096cac2c..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-121195.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-121195 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-121195))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-121195 .key-wbtc-121195-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-121195", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-132481.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-132481.clar deleted file mode 100644 index 00cdd2b0..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-132481.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-132481 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-132481))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-132481 .key-wbtc-132481-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-132481", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar deleted file mode 100644 index afbf6cb5..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-161515 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-161515))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-161515 .key-wbtc-161515-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-161515", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-200335.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-200335.clar deleted file mode 100644 index 3a6a48da..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-200335.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-200335 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-200335))) - (gross-amount (unwrap! (contract-call? .math-fixed-point mul-up amount (unwrap! (contract-call? .math-fixed-point div-down price ltv) math-call-err)) math-call-err)) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-200335 .key-wbtc-200335-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-200335", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar deleted file mode 100644 index d3e1127e..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-23040 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-23040))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-23040 .key-wbtc-23040-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-23040", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar deleted file mode 100644 index 6cd967ee..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-59760 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-59760))) - (gross-amount (unwrap! (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv) math-call-err))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-59760 .key-wbtc-59760-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-59760", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-240655.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-240655.clar deleted file mode 100644 index 206e17c6..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-240655.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-240655 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-240655))) - (gross-amount (unwrap! (contract-call? .math-fixed-point mul-up amount (unwrap! (contract-call? .math-fixed-point div-down price ltv) math-call-err)) math-call-err)) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-240655 .key-wbtc-240655-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-240655", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar deleted file mode 100644 index d629094a..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-34560 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-34560))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-34560 .key-wbtc-34560-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-34560", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar deleted file mode 100644 index 2b1c4a7b..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-51840 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-51840))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-51840 .key-wbtc-51840-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-51840", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar deleted file mode 100644 index b2459e92..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-59760 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-59760))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-59760 .key-wbtc-59760-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-59760", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar deleted file mode 100644 index e5a05c08..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-80875 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-80875))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-80875 .key-wbtc-80875-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-80875", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar deleted file mode 100644 index 7f3bea33..00000000 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-92160 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-wbtc .token-usda expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-wbtc-92160))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-wbtc .token-usda .yield-wbtc-92160 .key-wbtc-92160-usda gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-92160", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc.clar new file mode 100644 index 00000000..bf64b5dd --- /dev/null +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc.clar @@ -0,0 +1,40 @@ +(impl-trait .trait-flash-loan-user.flash-loan-user-trait) +(use-trait ft-trait .trait-sip-010.sip-010-trait) + +(define-constant ONE_8 (pow u10 u8)) + +(define-public (execute (collateral ) (amount uint) (memo (optional uint))) + (let + ( + ;; gross amount * ltv / price = amount + ;; gross amount = amount * price / ltv + (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc (default-to u0 memo)))) + (price (try! (contract-call? .yield-token-pool get-price (default-to u0 memo) .yield-usda))) + (gross-amount (mul-up amount (div-down price ltv))) + (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc (default-to u0 memo) .yield-usda .key-usda-wbtc gross-amount)))) + ) + ;; swap token to collateral so we can return flash-loan + (try! (contract-call? .fixed-weight-pool swap .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) + (print { object: "flash-loan-user-margin-usda-wbtc", action: "execute", data: gross-amount }) + (ok true) + ) +) + +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) + +(define-private (div-down (a uint) (b uint)) + (if (is-eq a u0) + u0 + (/ (* a ONE_8) b) + ) +) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar deleted file mode 100644 index 2f02a734..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-11520 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-11520))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-11520 .key-usda-11520-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-11520", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-121195.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-121195.clar deleted file mode 100644 index 748e8160..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-121195.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-121195 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-121195))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-121195 .key-usda-121195-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-121195", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-132481.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-132481.clar deleted file mode 100644 index 0f5a881f..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-132481.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-132481 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-132481))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-132481 .key-usda-132481-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-132481", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar deleted file mode 100644 index 42a6620a..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-161515 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-161515))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-161515 .key-usda-161515-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-161515", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-200335.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-200335.clar deleted file mode 100644 index 6c007c09..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-200335.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-200335 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-200335))) - (gross-amount (unwrap! (contract-call? .math-fixed-point mul-up amount (unwrap! (contract-call? .math-fixed-point div-down price ltv) math-call-err)) math-call-err)) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-200335 .key-usda-200335-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-200335", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar deleted file mode 100644 index c9b6d214..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-23040 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-23040))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-23040 .key-usda-23040-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-23040", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-240655.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-240655.clar deleted file mode 100644 index 02f44a00..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-240655.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-240655 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-240655))) - (gross-amount (unwrap! (contract-call? .math-fixed-point mul-up amount (unwrap! (contract-call? .math-fixed-point div-down price ltv) math-call-err)) math-call-err)) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-240655 .key-usda-240655-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-240655", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar deleted file mode 100644 index 395ada19..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-34560 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-34560))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-34560 .key-usda-34560-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-34560", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar deleted file mode 100644 index 923f2059..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-51840 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-51840))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-51840 .key-usda-51840-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-51840", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-80875.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-80875.clar deleted file mode 100644 index 1ed8ea08..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-80875.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-80875 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-80875))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-80875 .key-usda-80875-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-80875", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar deleted file mode 100644 index d0a10f53..00000000 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar +++ /dev/null @@ -1,29 +0,0 @@ -(impl-trait .trait-flash-loan-user.flash-loan-user-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - -(define-constant math-call-err (err u2010)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-public (execute (token ) (amount uint)) - (let - ( - ;; gross amount * ltv / price = amount - ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-92160 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (ltv (try! (contract-call? .collateral-rebalancing-pool get-ltv .token-usda .token-wbtc expiry))) - (price (try! (contract-call? .yield-token-pool get-price .yield-usda-92160))) - (gross-amount (contract-call? .math-fixed-point mul-up amount (contract-call? .math-fixed-point div-down price ltv))) - (swapped-token (get dx (try! (contract-call? .collateral-rebalancing-pool add-to-position-and-switch .token-usda .token-wbtc .yield-usda-92160 .key-usda-92160-wbtc gross-amount)))) - ) - ;; swap token to collateral so we can return flash-loan - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-wbtc .token-usda u50000000 u50000000)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-wbtc .token-usda u50000000 u50000000 swapped-token none)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token none)) - ) - - (print { object: "flash-loan-user-margin-usda-wbtc-92160", action: "execute", data: gross-amount }) - (ok true) - ) -) \ No newline at end of file diff --git a/clarity/contracts/helpers/margin-helper.clar b/clarity/contracts/helpers/margin-helper.clar index 31d04f87..d09c3f43 100644 --- a/clarity/contracts/helpers/margin-helper.clar +++ b/clarity/contracts/helpers/margin-helper.clar @@ -1,13 +1,13 @@ (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) (use-trait flash-loan-user-trait .trait-flash-loan-user.flash-loan-user-trait) (define-constant ONE_8 (pow u10 u8)) -(define-public (roll-position (token ) (collateral ) (the-key-token ) (next-flash-loan-user )) +(define-public (roll-position (token ) (collateral ) (the-key-token ) (flash-loan-user ) (expiry uint) (expiry-to-roll uint)) (let ( - (reduce-data (try! (contract-call? .collateral-rebalancing-pool reduce-position-key token collateral the-key-token ONE_8))) + (reduce-data (try! (contract-call? .collateral-rebalancing-pool reduce-position-key token collateral expiry the-key-token ONE_8))) (collateral-amount (get dx reduce-data)) (token-amount (get dy reduce-data)) (token-to-collateral @@ -17,6 +17,6 @@ ) ) ) - (contract-call? .alex-vault flash-loan next-flash-loan-user collateral (+ collateral-amount token-to-collateral)) + (contract-call? .alex-vault flash-loan flash-loan-user collateral (+ collateral-amount token-to-collateral) (some expiry-to-roll)) ) ) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-11520-wbtc.clar b/clarity/contracts/key-token/key-usda-11520-wbtc.clar deleted file mode 100644 index 7c5bd59b..00000000 --- a/clarity/contracts/key-token/key-usda-11520-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-11520-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u1152000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-11520-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-11520-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-11520-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-11520-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-11520-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-11520-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-11520-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-121195-wbtc.clar b/clarity/contracts/key-token/key-usda-121195-wbtc.clar deleted file mode 100644 index fa5e81ef..00000000 --- a/clarity/contracts/key-token/key-usda-121195-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-121195-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u12119500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-121195-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-121195-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-121195-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-121195-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-121195-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-121195-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-121195-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-132481-wbtc.clar b/clarity/contracts/key-token/key-usda-132481-wbtc.clar deleted file mode 100644 index 5eb6d88d..00000000 --- a/clarity/contracts/key-token/key-usda-132481-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-132481-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u13248100000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-132481-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-132481-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-132481-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-132481-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-132481-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-132481-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-132481-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-161515-wbtc.clar b/clarity/contracts/key-token/key-usda-161515-wbtc.clar deleted file mode 100644 index 03ffecd6..00000000 --- a/clarity/contracts/key-token/key-usda-161515-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-161515-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u16151500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-161515-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-161515-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-161515-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-161515-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-161515-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-161515-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-161515-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-200335-wbtc.clar b/clarity/contracts/key-token/key-usda-200335-wbtc.clar deleted file mode 100644 index 12d7bd1d..00000000 --- a/clarity/contracts/key-token/key-usda-200335-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-200335-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u20033500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-200335-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-200335-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-200335-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-200335-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-200335-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-200335-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-200335-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-23040-wbtc.clar b/clarity/contracts/key-token/key-usda-23040-wbtc.clar deleted file mode 100644 index f47610c4..00000000 --- a/clarity/contracts/key-token/key-usda-23040-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-23040-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2304000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-23040-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-23040-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-23040-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-23040-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-23040-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-23040-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-23040-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-23040-yield-usda-74880.clar b/clarity/contracts/key-token/key-usda-23040-yield-usda-74880.clar deleted file mode 100644 index da5d39e4..00000000 --- a/clarity/contracts/key-token/key-usda-23040-yield-usda-74880.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-23040-yield-usda-74880) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2304000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-23040-yield-usda-74880))) -) - -(define-read-only (get-name) - (ok "key-usda-23040-yield-usda-74880") -) - -(define-read-only (get-symbol) - (ok "key-usda-23040-yield-usda-74880") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .yield-usda-23040 get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-23040-yield-usda-74880 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-23040-yield-usda-74880 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-23040-yield-usda-74880 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-23040-yield-usda-74880 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-240655-wbtc.clar b/clarity/contracts/key-token/key-usda-240655-wbtc.clar deleted file mode 100644 index 3d76cda8..00000000 --- a/clarity/contracts/key-token/key-usda-240655-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-240655-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u24065500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-240655-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-240655-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-240655-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-240655-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-240655-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-240655-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-240655-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-34560-wbtc.clar b/clarity/contracts/key-token/key-usda-34560-wbtc.clar deleted file mode 100644 index 5e68ca58..00000000 --- a/clarity/contracts/key-token/key-usda-34560-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-34560-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u3456000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-34560-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-34560-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-34560-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-34560-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-34560-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-34560-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-34560-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-51840-wbtc.clar b/clarity/contracts/key-token/key-usda-51840-wbtc.clar deleted file mode 100644 index f3df36ba..00000000 --- a/clarity/contracts/key-token/key-usda-51840-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-51840-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5184000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-51840-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-51840-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-51840-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-51840-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-51840-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-51840-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-51840-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-80875-wbtc.clar b/clarity/contracts/key-token/key-usda-80875-wbtc.clar deleted file mode 100644 index 24e25976..00000000 --- a/clarity/contracts/key-token/key-usda-80875-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-80875-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u8087500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-80875-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-80875-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-80875-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-80875-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-80875-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-80875-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-80875-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-92160-wbtc.clar b/clarity/contracts/key-token/key-usda-92160-wbtc.clar deleted file mode 100644 index 6a62781e..00000000 --- a/clarity/contracts/key-token/key-usda-92160-wbtc.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-usda-92160-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u9216000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-92160-wbtc))) -) - -(define-read-only (get-name) - (ok "key-usda-92160-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-usda-92160-wbtc") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-92160-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-usda-92160-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-92160-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-usda-92160-wbtc (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-usda-wbtc.clar b/clarity/contracts/key-token/key-usda-wbtc.clar new file mode 100644 index 00000000..3b9a515d --- /dev/null +++ b/clarity/contracts/key-token/key-usda-wbtc.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token key-usda-wbtc) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance key-usda-wbtc who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply key-usda-wbtc)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-usda-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-usda-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? key-usda-wbtc amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? key-usda-wbtc amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply key-usda-wbtc))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance key-usda-wbtc who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .collateral-rebalancing-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-11520-usda.clar b/clarity/contracts/key-token/key-wbtc-11520-usda.clar deleted file mode 100644 index 8978a862..00000000 --- a/clarity/contracts/key-token/key-wbtc-11520-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-11520-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u1152000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-11520-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-11520-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-11520-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-11520-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-11520-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-11520-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-11520-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-121195-usda.clar b/clarity/contracts/key-token/key-wbtc-121195-usda.clar deleted file mode 100644 index be64f2d7..00000000 --- a/clarity/contracts/key-token/key-wbtc-121195-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-121195-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u12119500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-121195-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-121195-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-121195-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-121195-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-121195-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-121195-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-121195-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-132481-usda.clar b/clarity/contracts/key-token/key-wbtc-132481-usda.clar deleted file mode 100644 index f0f0cfcd..00000000 --- a/clarity/contracts/key-token/key-wbtc-132481-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-132481-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u13248100000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-132481-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-132481-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-132481-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-132481-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-132481-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-132481-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-132481-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-161515-usda.clar b/clarity/contracts/key-token/key-wbtc-161515-usda.clar deleted file mode 100644 index 8eeda19d..00000000 --- a/clarity/contracts/key-token/key-wbtc-161515-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-161515-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u16151500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-161515-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-161515-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-161515-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-161515-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-161515-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-161515-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-161515-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-200335-usda.clar b/clarity/contracts/key-token/key-wbtc-200335-usda.clar deleted file mode 100644 index dbcd8b41..00000000 --- a/clarity/contracts/key-token/key-wbtc-200335-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-200335-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u20033500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-200335-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-200335-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-200335-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-200335-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-200335-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-200335-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-200335-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-23040-usda.clar b/clarity/contracts/key-token/key-wbtc-23040-usda.clar deleted file mode 100644 index d2f07647..00000000 --- a/clarity/contracts/key-token/key-wbtc-23040-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-23040-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2304000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-23040-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-23040-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-23040-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-23040-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-23040-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-23040-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-23040-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-23670-usda.clar b/clarity/contracts/key-token/key-wbtc-23670-usda.clar deleted file mode 100644 index d92f6873..00000000 --- a/clarity/contracts/key-token/key-wbtc-23670-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-23670-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2367000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-23670-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-23670-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-23670-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-23670-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-23670-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-23670-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-23670-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-240655-usda.clar b/clarity/contracts/key-token/key-wbtc-240655-usda.clar deleted file mode 100644 index f7ba940a..00000000 --- a/clarity/contracts/key-token/key-wbtc-240655-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-240655-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u24065500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-240655-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-240655-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-240655-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-240655-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-240655-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-240655-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-240655-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-34560-usda.clar b/clarity/contracts/key-token/key-wbtc-34560-usda.clar deleted file mode 100644 index ff7ba9b1..00000000 --- a/clarity/contracts/key-token/key-wbtc-34560-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-34560-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u3456000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-34560-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-34560-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-34560-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-34560-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-34560-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-34560-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-34560-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-51840-usda.clar b/clarity/contracts/key-token/key-wbtc-51840-usda.clar deleted file mode 100644 index b64da3ef..00000000 --- a/clarity/contracts/key-token/key-wbtc-51840-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-51840-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5184000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-51840-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-51840-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-51840-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-51840-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-51840-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-51840-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-51840-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-59760-usda.clar b/clarity/contracts/key-token/key-wbtc-59760-usda.clar deleted file mode 100644 index 1abac997..00000000 --- a/clarity/contracts/key-token/key-wbtc-59760-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-59760-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5976000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-59760-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-59760-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-59760-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-59760-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-59760-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-59760-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-59760-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-59760-wbtc.clar b/clarity/contracts/key-token/key-wbtc-59760-wbtc.clar deleted file mode 100644 index 303d549e..00000000 --- a/clarity/contracts/key-token/key-wbtc-59760-wbtc.clar +++ /dev/null @@ -1,93 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-59760-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5976000000000) -(define-data-var underlying-token principal .token-key-wbtc-59760-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (ft-get-supply key-wbtc-59760-wbtc)) -) - -(define-read-only (get-name) - (ok "key-wbtc-59760-wbtc") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-59760-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (ft-get-balance key-wbtc-59760-wbtc account)) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-59760-wbtc amount sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-59760-wbtc amount recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-59760-wbtc amount sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-79760-usda.clar b/clarity/contracts/key-token/key-wbtc-79760-usda.clar deleted file mode 100644 index 478159f2..00000000 --- a/clarity/contracts/key-token/key-wbtc-79760-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-79760-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u7976000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-79760-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-79760-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-79760-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-79760-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-79760-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-79760-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-79760-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-80875-usda.clar b/clarity/contracts/key-token/key-wbtc-80875-usda.clar deleted file mode 100644 index 6e239c9a..00000000 --- a/clarity/contracts/key-token/key-wbtc-80875-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-80875-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u8087500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-80875-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-80875-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-80875-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-80875-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-80875-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-80875-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-80875-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-92160-usda.clar b/clarity/contracts/key-token/key-wbtc-92160-usda.clar deleted file mode 100644 index b670a5a3..00000000 --- a/clarity/contracts/key-token/key-wbtc-92160-usda.clar +++ /dev/null @@ -1,107 +0,0 @@ -(impl-trait .trait-yield-token.yield-token-trait) -(impl-trait .trait-ownable.ownable-trait) - -(define-fungible-token key-wbtc-92160-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u9216000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-92160-usda))) -) - -(define-read-only (get-name) - (ok "key-wbtc-92160-usda") -) - -(define-read-only (get-symbol) - (ok "key-wbtc-92160-usda") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-92160-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? key-wbtc-92160-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-92160-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? key-wbtc-92160-usda (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-usda.clar b/clarity/contracts/key-token/key-wbtc-usda.clar new file mode 100644 index 00000000..4ae2103e --- /dev/null +++ b/clarity/contracts/key-token/key-wbtc-usda.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token key-wbtc-usda) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance key-wbtc-usda who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply key-wbtc-usda)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-wbtc-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-wbtc-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? key-wbtc-usda amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? key-wbtc-usda amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply key-wbtc-usda))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance key-wbtc-usda who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .collateral-rebalancing-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/key-token/key-wbtc-wbtc.clar b/clarity/contracts/key-token/key-wbtc-wbtc.clar new file mode 100644 index 00000000..5ec1faba --- /dev/null +++ b/clarity/contracts/key-token/key-wbtc-wbtc.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token key-wbtc-wbtc) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance key-wbtc-wbtc who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply key-wbtc-wbtc)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-wbtc-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? key-wbtc-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? key-wbtc-wbtc amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? key-wbtc-wbtc amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply key-wbtc-wbtc))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance key-wbtc-wbtc who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .collateral-rebalancing-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/lib/math-fixed-point.clar b/clarity/contracts/lib/math-fixed-point.clar index 90bd18c9..ebb1f264 100644 --- a/clarity/contracts/lib/math-fixed-point.clar +++ b/clarity/contracts/lib/math-fixed-point.clar @@ -6,13 +6,6 @@ ;; constants ;; (define-constant ONE_8 (pow u10 u8)) ;; 8 decimal places -(define-constant ERR-SCALE-UP-OVERFLOW (err u5001)) -(define-constant ERR-SCALE-DOWN-OVERFLOW (err u5002)) -(define-constant ERR-ADD-OVERFLOW (err u5003)) -(define-constant ERR-SUB-OVERFLOW (err u5004)) -(define-constant ERR-MUL-OVERFLOW (err u5005)) -(define-constant ERR-DIV-OVERFLOW (err u5006)) -(define-constant ERR-POW-OVERFLOW (err u5007)) ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error diff --git a/clarity/contracts/multisig/multisig-crp-usda-121195-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-121195-wbtc.clar deleted file mode 100644 index 55093188..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-121195-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-121195) (is-eq (contract-of token) .key-usda-121195-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-121195 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-121195-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-121195 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-121195-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-121195 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-121195-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u12119500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u12119500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-132481-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-132481-wbtc.clar deleted file mode 100644 index af40bc0e..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-132481-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-132481) (is-eq (contract-of token) .key-usda-132481-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-132481 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-132481-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-132481 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-132481-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-132481 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-132481-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u13248100000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u13248100000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-161515-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-161515-wbtc.clar deleted file mode 100644 index 42448dbc..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-161515-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-161515) (is-eq (contract-of token) .key-usda-161515-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-161515 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-161515-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-161515 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-161515-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-161515 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-161515-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u16151500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u16151500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-200335-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-200335-wbtc.clar deleted file mode 100644 index d3fc0dac..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-200335-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-200335) (is-eq (contract-of token) .key-usda-200335-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-200335 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-200335-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-200335 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-200335-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-200335 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-200335-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u20033500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u20033500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-23040-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-23040-wbtc.clar deleted file mode 100644 index e4f467e2..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-23040-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-23040) (is-eq (contract-of token) .key-usda-23040-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-23040 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-23040-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-23040-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-23040-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u2304000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u2304000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-23040-yield-usda-74880.clar b/clarity/contracts/multisig/multisig-crp-usda-23040-yield-usda-74880.clar deleted file mode 100644 index 7303fe69..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-23040-yield-usda-74880.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayyield-usda-74880-yield-usda-74880 pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-23040) (is-eq (contract-of token) .key-usda-23040-yield-usda-74880)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-23040 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-23040-yield-usda-74880 get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-23040-yield-usda-74880 get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-23040-yield-usda-74880 get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .yield-usda-74880 u2304000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .yield-usda-74880 u2304000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-240655-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-240655-wbtc.clar deleted file mode 100644 index 863cfdcf..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-240655-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-240655) (is-eq (contract-of token) .key-usda-240655-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-240655 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-240655-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-240655 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-240655-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-240655 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-240655-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u24065500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u24065500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar deleted file mode 100644 index bae32692..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-34560) (is-eq (contract-of token) .key-usda-34560-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-34560 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-34560-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-34560 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-34560-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-34560 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-34560-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u3456000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u3456000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar deleted file mode 100644 index 1ae24ffb..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-51840) (is-eq (contract-of token) .key-usda-51840-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-51840 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-51840-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-51840 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-51840-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-51840 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-51840-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u5184000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u5184000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-80875-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-80875-wbtc.clar deleted file mode 100644 index 0dec17b1..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-80875-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-80875) (is-eq (contract-of token) .key-usda-80875-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-80875 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-80875-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-80875 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-80875-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-80875 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-80875-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u8087500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u8087500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar deleted file mode 100644 index 0d5fce30..00000000 --- a/clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-92160) (is-eq (contract-of token) .key-usda-92160-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-92160 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-92160-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-92160 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-92160-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-92160 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-92160-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u9216000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u9216000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-wbtc.clar similarity index 76% rename from clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar rename to clarity/contracts/multisig/multisig-crp-usda-wbtc.clar index 08ddb288..e648038f 100644 --- a/clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar +++ b/clarity/contracts/multisig/multisig-crp-usda-wbtc.clar @@ -1,5 +1,5 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) +(impl-trait .trait-multisig-vote.multisig-vote-sft-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) ;; Alex voting for MultiSig DAO @@ -14,11 +14,9 @@ ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) ;; Constants @@ -33,6 +31,7 @@ { id: uint, proposer: principal, + expiry: uint, title: (string-utf8 256), url: (string-utf8 256), is-open: bool, @@ -53,7 +52,7 @@ (define-data-var threshold-percentage uint u0) (define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) +(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal, expiry: uint } { amount: uint }) ;; Get all proposals in detail (define-read-only (get-proposals) @@ -73,10 +72,10 @@ ) ) -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) +(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token ) (expiry uint)) (default-to { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) + (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token), expiry: expiry }) ) ) @@ -86,6 +85,7 @@ { id: u0, proposer: DEFAULT_OWNER, + expiry: u0, title: u"", url: u"", is-open: false, @@ -101,15 +101,16 @@ ) ;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-usda-11520) (is-eq (contract-of token) .key-usda-11520-wbtc)) +(define-read-only (is-token-accepted (token )) + (or (is-eq (contract-of token) .yield-usda) (is-eq (contract-of token) .key-usda-wbtc)) ) ;; Start a proposal ;; Requires 10% of the supply in your wallet ;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose +(define-public (propose + (expiry uint) (start-block-height uint) (title (string-utf8 256)) (url (string-utf8 256)) @@ -118,11 +119,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-11520 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-11520-wbtc get-balance tx-sender))) + (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda get-balance-fixed expiry tx-sender))) + (proposer-key-balance (unwrap-panic (contract-call? .key-usda-wbtc get-balance-fixed expiry tx-sender))) (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-11520 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-11520-wbtc get-total-supply))) + (total-yield-supply (unwrap-panic (contract-call? .yield-usda get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-usda-wbtc get-total-supply-fixed expiry))) (total-supply (+ total-yield-supply total-key-supply)) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -135,6 +136,7 @@ { id: proposal-id, proposer: tx-sender, + expiry: expiry, title: title, url: url, is-open: true, @@ -152,12 +154,12 @@ ) ) -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) +(define-public (vote-for (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token @@ -168,7 +170,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals { id: proposal-id } @@ -177,7 +179,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) @@ -185,14 +187,12 @@ ) ) - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) +(define-public (vote-against (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -201,7 +201,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals @@ -211,7 +211,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) , expiry: expiry } { amount: (+ amount token-count)}) (ok amount) ) @@ -219,14 +219,17 @@ ) (define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-usda-11520 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-11520-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) + (let + ( + (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (threshold-percent (var-get threshold)) + (total-yield-supply (unwrap-panic (contract-call? .yield-usda get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-usda-wbtc get-total-supply-fixed expiry))) + (total-supply (+ total-yield-supply total-key-supply)) + (threshold-count (mul-up total-supply threshold-percent)) + (yes-votes (get yes-votes proposal)) + ) (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) @@ -243,11 +246,12 @@ ;; Return votes to voter(member) ;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) +(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) (let ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (token-count (get amount (get-tokens-by-member-by-id proposal-id member token expiry))) ) (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -255,7 +259,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed expiry token-count (as-contract tx-sender) member))) (ok true) ) ) @@ -265,13 +269,25 @@ (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (new-fee-rate-x (get new-fee-rate-x proposal)) (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u1152000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u1152000000000 new-fee-rate-y)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc expiry new-fee-rate-x)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc expiry new-fee-rate-y)) (ok true) ) ) +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) \ No newline at end of file diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-132481-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-132481-usda.clar deleted file mode 100644 index 8a67d8b0..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-132481-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-132481) (is-eq (contract-of token) .key-wbtc-132481-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-132481 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-132481-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-132481 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-132481-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-132481 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-132481-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u13248100000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u13248100000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-161515-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-161515-usda.clar deleted file mode 100644 index a92e04f9..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-161515-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-161515) (is-eq (contract-of token) .key-wbtc-161515-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-161515 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-161515-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-161515 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-161515-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-161515 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-161515-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u16151500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u16151500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-200335-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-200335-usda.clar deleted file mode 100644 index cf2a33a1..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-200335-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-200335) (is-eq (contract-of token) .key-wbtc-200335-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-200335 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-200335-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-200335 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-200335-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-200335 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-200335-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u20033500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u20033500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-23040-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-23040-usda.clar deleted file mode 100644 index 2f622c2b..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-23040-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-23040) (is-eq (contract-of token) .key-wbtc-23040-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-23040 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-23040-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-23040-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-23040 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-23040-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u2304000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u2304000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-23670-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-23670-usda.clar deleted file mode 100644 index 02183bce..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-23670-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-23670) (is-eq (contract-of token) .key-wbtc-23670-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-23670 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-23670-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-23670 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-23670-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-23670 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-23670-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u2367000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u2367000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-240655-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-240655-usda.clar deleted file mode 100644 index fbd233bd..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-240655-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-240655) (is-eq (contract-of token) .key-wbtc-240655-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-240655 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-240655-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-240655 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-240655-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-240655 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-240655-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u24065500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u24065500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-34560-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-34560-usda.clar deleted file mode 100644 index 60bb269f..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-34560-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-34560) (is-eq (contract-of token) .key-wbtc-34560-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-34560 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-34560-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-34560 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-34560-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-34560 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-34560-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u3456000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u3456000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar deleted file mode 100644 index c16852dd..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-51840) (is-eq (contract-of token) .key-wbtc-51840-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-51840 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-51840-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-51840 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-51840-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-51840 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-51840-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u5184000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u5184000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-59760-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-59760-usda.clar deleted file mode 100644 index 1287c127..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-59760-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-59760) (is-eq (contract-of token) .key-wbtc-59760-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-59760 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-59760-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-59760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-59760-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-59760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-59760-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u5976000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u5976000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-59760-wbtc.clar b/clarity/contracts/multisig/multisig-crp-wbtc-59760-wbtc.clar deleted file mode 100644 index e26b545e..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-59760-wbtc.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for aywbtc-wbtc pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-59760) (is-eq (contract-of token) .key-wbtc-59760-wbtc)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-59760 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-59760-wbtc get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-59760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-59760-wbtc get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-59760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-59760-wbtc get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-wbtc u5976000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-wbtc u5976000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-79760-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-79760-usda.clar deleted file mode 100644 index 8316e165..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-79760-usda.clar +++ /dev/null @@ -1,279 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-CONTRACT-CHANGES (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant status-ok u10000) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-79760) (is-eq (contract-of token) .key-wbtc-79760-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-79760 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-79760-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-79760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-79760-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-79760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-79760-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u5976000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u5976000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-80875-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-80875-usda.clar deleted file mode 100644 index 3a409098..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-80875-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-80875) (is-eq (contract-of token) .key-wbtc-80875-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-80875 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-80875-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-80875 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-80875-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-80875 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-80875-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u8087500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u8087500000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar deleted file mode 100644 index 9a3c2c99..00000000 --- a/clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar +++ /dev/null @@ -1,277 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, ;; Default token feerate - new-fee-rate-y: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-92160) (is-eq (contract-of token) .key-wbtc-92160-usda)) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let - ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-92160 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-92160-usda get-balance tx-sender))) - (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-92160 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-92160-usda get-total-supply))) - (total-supply (+ total-yield-supply total-key-supply)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-92160 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-92160-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let - ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u9216000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u9216000000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-usda.clar similarity index 76% rename from clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar rename to clarity/contracts/multisig/multisig-crp-wbtc-usda.clar index 03cd0876..bf563f17 100644 --- a/clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar +++ b/clarity/contracts/multisig/multisig-crp-wbtc-usda.clar @@ -1,5 +1,5 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) +(impl-trait .trait-multisig-vote.multisig-vote-sft-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) ;; Alex voting for MultiSig DAO @@ -14,11 +14,9 @@ ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) ;; Constants @@ -33,6 +31,7 @@ { id: uint, proposer: principal, + expiry: uint, title: (string-utf8 256), url: (string-utf8 256), is-open: bool, @@ -53,7 +52,7 @@ (define-data-var threshold-percentage uint u0) (define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) +(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal, expiry: uint } { amount: uint }) ;; Get all proposals in detail (define-read-only (get-proposals) @@ -73,10 +72,10 @@ ) ) -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) +(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token ) (expiry uint)) (default-to { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) + (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token), expiry: expiry }) ) ) @@ -86,6 +85,7 @@ { id: u0, proposer: DEFAULT_OWNER, + expiry: u0, title: u"", url: u"", is-open: false, @@ -101,15 +101,16 @@ ) ;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-11520) (is-eq (contract-of token) .key-wbtc-11520-usda)) +(define-read-only (is-token-accepted (token )) + (or (is-eq (contract-of token) .yield-wbtc) (is-eq (contract-of token) .key-wbtc-usda)) ) ;; Start a proposal ;; Requires 10% of the supply in your wallet ;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose +(define-public (propose + (expiry uint) (start-block-height uint) (title (string-utf8 256)) (url (string-utf8 256)) @@ -118,11 +119,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-11520 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-11520-usda get-balance tx-sender))) + (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc get-balance-fixed expiry tx-sender))) + (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-usda get-balance-fixed expiry tx-sender))) (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-11520 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-11520-usda get-total-supply))) + (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-wbtc-usda get-total-supply-fixed expiry))) (total-supply (+ total-yield-supply total-key-supply)) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -135,6 +136,7 @@ { id: proposal-id, proposer: tx-sender, + expiry: expiry, title: title, url: url, is-open: true, @@ -152,12 +154,12 @@ ) ) -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) +(define-public (vote-for (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token @@ -168,7 +170,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals { id: proposal-id } @@ -177,7 +179,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) @@ -185,14 +187,12 @@ ) ) - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) +(define-public (vote-against (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -201,7 +201,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals @@ -211,7 +211,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) , expiry: expiry } { amount: (+ amount token-count)}) (ok amount) ) @@ -219,14 +219,17 @@ ) (define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-11520 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-11520-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) + (let + ( + (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (threshold-percent (var-get threshold)) + (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-wbtc-usda get-total-supply-fixed expiry))) + (total-supply (+ total-yield-supply total-key-supply)) + (threshold-count (mul-up total-supply threshold-percent)) + (yes-votes (get yes-votes proposal)) + ) (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) @@ -243,11 +246,12 @@ ;; Return votes to voter(member) ;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) +(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) (let ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (token-count (get amount (get-tokens-by-member-by-id proposal-id member token expiry))) ) (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -255,7 +259,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed expiry token-count (as-contract tx-sender) member))) (ok true) ) ) @@ -265,13 +269,25 @@ (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (new-fee-rate-x (get new-fee-rate-x proposal)) (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u1152000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u1152000000000 new-fee-rate-y)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda expiry new-fee-rate-x)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda expiry new-fee-rate-y)) (ok true) ) ) +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) \ No newline at end of file diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-121195-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-wbtc.clar similarity index 76% rename from clarity/contracts/multisig/multisig-crp-wbtc-121195-usda.clar rename to clarity/contracts/multisig/multisig-crp-wbtc-wbtc.clar index d1998dc6..4d6ab64b 100644 --- a/clarity/contracts/multisig/multisig-crp-wbtc-121195-usda.clar +++ b/clarity/contracts/multisig/multisig-crp-wbtc-wbtc.clar @@ -1,5 +1,5 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) +(impl-trait .trait-multisig-vote.multisig-vote-sft-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) ;; Alex voting for MultiSig DAO @@ -14,11 +14,9 @@ ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) ;; Constants @@ -33,6 +31,7 @@ { id: uint, proposer: principal, + expiry: uint, title: (string-utf8 256), url: (string-utf8 256), is-open: bool, @@ -53,7 +52,7 @@ (define-data-var threshold-percentage uint u0) (define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) +(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal, expiry: uint } { amount: uint }) ;; Get all proposals in detail (define-read-only (get-proposals) @@ -73,10 +72,10 @@ ) ) -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) +(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token ) (expiry uint)) (default-to { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) + (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token), expiry: expiry }) ) ) @@ -86,6 +85,7 @@ { id: u0, proposer: DEFAULT_OWNER, + expiry: u0, title: u"", url: u"", is-open: false, @@ -101,15 +101,16 @@ ) ;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (or (is-eq (contract-of token) .yield-wbtc-121195) (is-eq (contract-of token) .key-wbtc-121195-usda)) +(define-read-only (is-token-accepted (token )) + (or (is-eq (contract-of token) .yield-wbtc) (is-eq (contract-of token) .key-wbtc-wbtc)) ) ;; Start a proposal ;; Requires 10% of the supply in your wallet ;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose +(define-public (propose + (expiry uint) (start-block-height uint) (title (string-utf8 256)) (url (string-utf8 256)) @@ -118,11 +119,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-121195 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-121195-usda get-balance tx-sender))) + (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc get-balance-fixed expiry tx-sender))) + (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-wbtc get-balance-fixed expiry tx-sender))) (proposer-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-121195 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-121195-usda get-total-supply))) + (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-wbtc-wbtc get-total-supply-fixed expiry))) (total-supply (+ total-yield-supply total-key-supply)) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -135,6 +136,7 @@ { id: proposal-id, proposer: tx-sender, + expiry: expiry, title: title, url: url, is-open: true, @@ -152,12 +154,12 @@ ) ) -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) +(define-public (vote-for (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token @@ -168,7 +170,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals { id: proposal-id } @@ -177,7 +179,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) @@ -185,14 +187,12 @@ ) ) - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) +(define-public (vote-against (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -201,7 +201,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals @@ -211,7 +211,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) , expiry: expiry } { amount: (+ amount token-count)}) (ok amount) ) @@ -219,14 +219,17 @@ ) (define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-121195 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-121195-usda get-total-supply))) - (total-supply (* (+ total-yield-supply total-key-supply) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) + (let + ( + (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (threshold-percent (var-get threshold)) + (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc get-total-supply-fixed expiry))) + (total-key-supply (unwrap-panic (contract-call? .key-wbtc-wbtc get-total-supply-fixed expiry))) + (total-supply (+ total-yield-supply total-key-supply)) + (threshold-count (mul-up total-supply threshold-percent)) + (yes-votes (get yes-votes proposal)) + ) (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) @@ -243,11 +246,12 @@ ;; Return votes to voter(member) ;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) +(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) (let ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (token-count (get amount (get-tokens-by-member-by-id proposal-id member token expiry))) ) (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -255,7 +259,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed expiry token-count (as-contract tx-sender) member))) (ok true) ) ) @@ -265,13 +269,25 @@ (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (new-fee-rate-x (get new-fee-rate-x proposal)) (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u12119500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u12119500000000 new-fee-rate-y)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-wbtc expiry new-fee-rate-x)) + (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-wbtc expiry new-fee-rate-y)) (ok true) ) ) +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) \ No newline at end of file diff --git a/clarity/contracts/multisig/multisig-fwp-usda-23040-usda-74880-50-50.clar b/clarity/contracts/multisig/multisig-fwp-usda-23040-usda-74880-50-50.clar deleted file mode 100644 index 9f58666f..00000000 --- a/clarity/contracts/multisig/multisig-fwp-usda-23040-usda-74880-50-50.clar +++ /dev/null @@ -1,269 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-x: uint, - new-fee-rate-y: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: u0, - new-fee-rate-y: u0 - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .fwp-usda-23040-usda-74880-50-50) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-x uint) - (new-fee-rate-y uint) - ) - (let ( - (proposer-balance (unwrap-panic (contract-call? .fwp-usda-23040-usda-74880-50-50 get-balance tx-sender))) - (total-supply (unwrap-panic (contract-call? .fwp-usda-23040-usda-74880-50-50 get-total-supply))) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-x: new-fee-rate-x, - new-fee-rate-y: new-fee-rate-y - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .fwp-usda-23040-usda-74880-50-50 get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true) - ) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (get amount (get-tokens-by-member-by-id proposal-id member token))) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-x (get new-fee-rate-x proposal)) - (new-fee-rate-y (get new-fee-rate-y proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .fixed-weight-pool set-fee-rate-x .yield-usda-23040 .yield-usda-74880 u50000000 u50000000 new-fee-rate-x)) - (try! (contract-call? .fixed-weight-pool set-fee-rate-y .yield-usda-23040 .yield-usda-74880 u50000000 u50000000 new-fee-rate-y)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar b/clarity/contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar index 55226d7d..d56f8d7c 100644 --- a/clarity/contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar +++ b/clarity/contracts/multisig/multisig-fwp-wbtc-usda-50-50.clar @@ -14,11 +14,9 @@ ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) ;; Constants @@ -117,8 +115,8 @@ (new-fee-rate-y uint) ) (let ( - (proposer-balance (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-balance tx-sender))) - (total-supply (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-total-supply))) + (proposer-balance (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-balance-fixed tx-sender))) + (total-supply (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-total-supply-fixed))) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -163,7 +161,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed amount tx-sender (as-contract tx-sender) none)) ;; Mutate (map-set proposals { id: proposal-id } @@ -193,7 +191,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed amount tx-sender (as-contract tx-sender) none)) ;; Mutate (map-set proposals @@ -214,8 +212,8 @@ (define-public (end-proposal (proposal-id uint)) (let ((proposal (get-proposal-by-id proposal-id)) (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) + (total-supply (unwrap-panic (contract-call? .fwp-wbtc-usda-50-50 get-total-supply-fixed))) + (threshold-count (mul-up total-supply threshold-percent)) (yes-votes (get yes-votes proposal)) ) @@ -247,7 +245,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed token-count (as-contract tx-sender) member none))) (ok true) ) ) @@ -267,3 +265,15 @@ (ok true) ) ) + +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) diff --git a/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar b/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar index 54d2dd4f..1d05f4ac 100644 --- a/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar +++ b/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar @@ -14,11 +14,9 @@ ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) ;; Constants @@ -114,11 +112,11 @@ (title (string-utf8 256)) (url (string-utf8 256)) (new-fee-rate-x uint) - (new-fee-rate-y uint) + (new-fee-rate-y uint) ) (let ( - (proposer-balance (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-balance tx-sender))) - (total-supply (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-total-supply))) + (proposer-balance (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-balance-fixed tx-sender))) + (total-supply (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-total-supply-fixed))) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -153,8 +151,7 @@ (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - + ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) ;; Proposal should be open for voting @@ -163,7 +160,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed amount tx-sender (as-contract tx-sender) none)) ;; Mutate (map-set proposals { id: proposal-id } @@ -193,7 +190,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed amount tx-sender (as-contract tx-sender) none)) ;; Mutate (map-set proposals @@ -214,8 +211,8 @@ (define-public (end-proposal (proposal-id uint)) (let ((proposal (get-proposal-by-id proposal-id)) (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) + (total-supply (unwrap-panic (contract-call? .lbp-alex-usda-90-10 get-total-supply-fixed))) + (threshold-count (mul-up total-supply threshold-percent)) (yes-votes (get yes-votes proposal)) ) @@ -247,7 +244,19 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed token-count (as-contract tx-sender) member none))) (ok true) ) ) + +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar deleted file mode 100644 index 810f371a..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-11520-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-11520-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-11520-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-11520-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-11520 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-11520 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-121195-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-121195-usda.clar deleted file mode 100644 index cfd6cc4b..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-121195-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-121195-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-121195-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-121195-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-121195-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-121195 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-121195 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-172802-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-172802-usda.clar deleted file mode 100644 index ee39601c..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-172802-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-172802-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-172802-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-172802-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-172802-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-172802 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-usda-172802 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-200335-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-200335-usda.clar deleted file mode 100644 index 31768a4d..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-200335-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-200335-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-200335-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-200335-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-200335-usda get-total-supply)) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-200335 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-200335 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-23040-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-23040-usda.clar deleted file mode 100644 index 91d2bdc3..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-23040-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-23040-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-23040-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-23040-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-23040-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-23040 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-23040 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-240655-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-240655-usda.clar deleted file mode 100644 index ad2dd4e2..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-240655-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-240655-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-240655-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-240655-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-240655-usda get-total-supply)) ONE_8)) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-240655 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-240655 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar deleted file mode 100644 index 0b44730e..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-34560-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-34560-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-34560-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-34560-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-34560 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-34560 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar deleted file mode 100644 index fa8e6eb1..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-51840-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-51840-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-51840-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-51840-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-51840 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-51840 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-80875-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-80875-usda.clar deleted file mode 100644 index 351d8ad6..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-80875-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-80875-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-80875-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-80875-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-80875-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-80875 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-80875 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar deleted file mode 100644 index 5e59a8a5..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-92160-usda) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-92160-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-92160-usda get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-92160-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-92160 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-92160 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-161515-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda.clar similarity index 75% rename from clarity/contracts/multisig/multisig-ytp-yield-usda-161515-usda.clar rename to clarity/contracts/multisig/multisig-ytp-yield-usda.clar index eb6ebd79..f6b72ab0 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-161515-usda.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-usda.clar @@ -1,6 +1,5 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) +(impl-trait .trait-multisig-vote.multisig-vote-sft-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) ;; Alex voting for MultiSig DAO @@ -9,17 +8,15 @@ ;; A proposal will just update the DAO with new contracts. ;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. +;; This prototype is for aywbtc-wbtc pool token. ;; Common Trait and for each pool, implementation is required. ;; ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) @@ -35,6 +32,7 @@ { id: uint, proposer: principal, + expiry: uint, title: (string-utf8 256), url: (string-utf8 256), is-open: bool, @@ -55,7 +53,7 @@ (define-data-var threshold-percentage uint u0) (define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) +(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal, expiry: uint } { amount: uint }) ;; Get all proposals in detail (define-read-only (get-proposals) @@ -75,10 +73,10 @@ ) ) -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) +(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token ) (expiry uint)) (default-to { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) + (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token), expiry: expiry }) ) ) @@ -88,6 +86,7 @@ { id: u0, proposer: DEFAULT_OWNER, + expiry: u0, title: u"", url: u"", is-open: false, @@ -103,8 +102,8 @@ ) ;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-161515-usda) +(define-read-only (is-token-accepted (token )) + (is-eq (contract-of token) .ytp-yield-usda) ) @@ -112,6 +111,7 @@ ;; Requires 10% of the supply in your wallet ;; Default voting period is 10 days (144 * 10 blocks) (define-public (propose + (expiry uint) (start-block-height uint) (title (string-utf8 256)) (url (string-utf8 256)) @@ -119,8 +119,8 @@ (new-fee-rate-yield-token uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-161515-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-161515-usda get-total-supply)) ONE_8)) + (proposer-balance (unwrap-panic (contract-call? .ytp-yield-usda get-balance-fixed expiry tx-sender))) + (total-supply (unwrap-panic (contract-call? .ytp-yield-usda get-total-supply-fixed expiry))) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -132,6 +132,7 @@ { id: proposal-id, proposer: tx-sender, + expiry: expiry, title: title, url: url, is-open: true, @@ -149,12 +150,12 @@ ) ) -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) +(define-public (vote-for (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token @@ -165,7 +166,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals { id: proposal-id } @@ -174,7 +175,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) @@ -185,11 +186,12 @@ -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) +(define-public (vote-against (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -198,7 +200,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals @@ -208,7 +210,7 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) ) @@ -216,12 +218,15 @@ ) (define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-161515-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) + (let + ( + (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (threshold-percent (var-get threshold)) + (total-supply (unwrap-panic (contract-call? .ytp-yield-usda get-total-supply-fixed expiry))) + (threshold-count (mul-up total-supply threshold-percent)) + (yes-votes (get yes-votes proposal)) + ) (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) @@ -233,16 +238,18 @@ ;; Execute the proposal when the yes-vote passes threshold-count. (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) + (ok true) + ) ) ;; Return votes to voter(member) ;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) +(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) (let ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token expiry)) ONE_8)) ) (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -250,7 +257,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed expiry token-count (as-contract tx-sender) member))) (ok true) ) ) @@ -259,14 +266,27 @@ (define-private (execute-proposal (proposal-id uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (new-fee-rate-token (get new-fee-rate-token proposal)) (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-161515 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-161515 new-fee-rate-yield-token)) + (try! (contract-call? .yield-token-pool set-fee-rate-token expiry .yield-usda new-fee-rate-token)) + (try! (contract-call? .yield-token-pool set-fee-rate-yield-token expiry .yield-usda new-fee-rate-yield-token)) (ok true) ) ) + +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) \ No newline at end of file diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar deleted file mode 100644 index 154f9eba..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-11520-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-11520-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-11520-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-11520-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-11520 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-11520 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-121195-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-121195-wbtc.clar deleted file mode 100644 index bda22c9a..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-121195-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-121195-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-121195-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-121195-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-121195-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-121195 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-121195 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-132481-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-132481-wbtc.clar deleted file mode 100644 index 0e1b6b4f..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-132481-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-132481-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-132481-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-132481-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-132481-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-132481 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-132481 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-161515-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-161515-wbtc.clar deleted file mode 100644 index 24ba8039..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-161515-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-161515-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-161515-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-161515-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-161515-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-161515 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-161515 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-172802-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-172802-wbtc.clar deleted file mode 100644 index f4f6d98d..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-172802-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-172802-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-172802-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-172802-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-172802-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-172802 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-wbtc-172802 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-200335-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-200335-wbtc.clar deleted file mode 100644 index 2af5505e..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-200335-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-200335-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-200335-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-200335-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-200335-wbtc get-total-supply))) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-200335 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-200335 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23040-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23040-wbtc.clar deleted file mode 100644 index 9e39887b..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23040-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-23040-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-23040-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-23040-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-23040-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-23040 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-23040 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23670-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23670-wbtc.clar deleted file mode 100644 index f9c47551..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-23670-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-23670-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-23670-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-23670-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-23670-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-23670 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-23670 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-240655-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-240655-wbtc.clar deleted file mode 100644 index 8efd78d5..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-240655-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-240655-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-240655-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-240655-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-240655-wbtc get-total-supply))) - (threshold-count (unwrap-panic (contract-call? .math-fixed-point mul-up total-supply threshold-percent))) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-240655 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-240655 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar deleted file mode 100644 index e1218abd..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-34560-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-34560-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-34560-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-34560-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-34560 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-34560 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar deleted file mode 100644 index 9939b8eb..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-51840-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-51840-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-51840-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-51840-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-51840 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-51840 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-59760-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-59760-wbtc.clar deleted file mode 100644 index 3cbf8071..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-59760-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-59760-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-59760-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-59760-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-59760-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-59760 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-59760 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-79760-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-79760-wbtc.clar deleted file mode 100644 index fef14ef5..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-79760-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-79760-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-79760-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-79760-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-79760-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-79760 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-79760 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-80875-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-80875-wbtc.clar deleted file mode 100644 index e6d96fdf..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-80875-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-80875-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-80875-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-80875-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-80875-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-80875 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-80875 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar deleted file mode 100644 index c1189f10..00000000 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar +++ /dev/null @@ -1,272 +0,0 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) - - -;; Alex voting for MultiSig DAO -;; -;; Voting and proposing the proposals -;; A proposal will just update the DAO with new contracts. - -;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. -;; Common Trait and for each pool, implementation is required. -;; - -;; Errors -(define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) -(define-constant ERR-INVALID-POOL-TOKEN (err u8002)) -(define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) -(define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) - -(define-constant ONE_8 u100000000) - -;; Constants -(define-constant DEFAULT_OWNER tx-sender) - -;; Proposal variables -;; With Vote, we can set : -;; 1. contract to have right to mint/burn token -;; 2. Set Feerate / Fee address / Collect Fees -(define-map proposals - { id: uint } - { - id: uint, - proposer: principal, - title: (string-utf8 256), - url: (string-utf8 256), - is-open: bool, - start-block-height: uint, - end-block-height: uint, - yes-votes: uint, - no-votes: uint, - new-fee-rate-token: uint, - new-fee-rate-yield-token: uint - } -) - -(define-data-var proposal-count uint u0) -(define-data-var proposal-ids (list 100 uint) (list u0)) -(define-data-var threshold uint u75000000) ;; 75% - -(define-data-var total-supply-of-token uint u0) -(define-data-var threshold-percentage uint u0) - -(define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) - -;; Get all proposals in detail -(define-read-only (get-proposals) - (ok (map get-proposal-by-id (var-get proposal-ids))) -) - -;; Get all proposal ID in list -(define-read-only (get-proposal-ids) - (ok (var-get proposal-ids)) -) - -;; Get votes for a member on proposal -(define-read-only (get-votes-by-member-by-id (proposal-id uint) (member principal)) - (default-to - { vote-count: u0 } - (map-get? votes-by-member { proposal-id: proposal-id, member: member }) - ) -) - -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) - (default-to - { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) - ) -) - -;; Get proposal -(define-read-only (get-proposal-by-id (proposal-id uint)) - (default-to - { - id: u0, - proposer: DEFAULT_OWNER, - title: u"", - url: u"", - is-open: false, - start-block-height: u0, - end-block-height: u0, - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: u0, ;; Default token feerate - new-fee-rate-yield-token: u0 ;; default yield-token feerate - } - (map-get? proposals { id: proposal-id }) - ) -) - -;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-wbtc-92160-wbtc) -) - - -;; Start a proposal -;; Requires 10% of the supply in your wallet -;; Default voting period is 10 days (144 * 10 blocks) -(define-public (propose - (start-block-height uint) - (title (string-utf8 256)) - (url (string-utf8 256)) - (new-fee-rate-token uint) - (new-fee-rate-yield-token uint) - ) - (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-92160-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-92160-wbtc get-total-supply)) ONE_8)) - (proposal-id (+ u1 (var-get proposal-count))) - ) - - ;; Requires 10% of the supply - (asserts! (>= (* proposer-balance u10) total-supply) ERR-NOT-ENOUGH-BALANCE) - ;; Mutate - (map-set proposals - { id: proposal-id } - { - id: proposal-id, - proposer: tx-sender, - title: title, - url: url, - is-open: true, - start-block-height: start-block-height, - end-block-height: (+ start-block-height u1440), - yes-votes: u0, - no-votes: u0, - new-fee-rate-token: new-fee-rate-token, - new-fee-rate-yield-token: new-fee-rate-yield-token - } - ) - (var-set proposal-count proposal-id) - (var-set proposal-ids (unwrap-panic (as-max-len? (append (var-get proposal-ids) proposal-id) u100))) - (ok proposal-id) - ) -) - -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - - ) - - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { yes-votes: (+ amount (get yes-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - - (ok amount) - - ) - ) - - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - ) - ;; Can vote with corresponding pool token - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - ;; Proposal should be open for voting - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - ;; Vote should be casted after the start-block-height - (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) - ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) - - ;; Mutate - (map-set proposals - { id: proposal-id } - (merge proposal { no-votes: (+ amount (get no-votes proposal)) })) - (map-set votes-by-member - { proposal-id: proposal-id, member: tx-sender } - { vote-count: (+ amount vote-count) }) - (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } - { amount: (+ amount token-count)}) - (ok amount) - ) - - ) - -(define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc-92160-wbtc get-total-supply))) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) - - (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id - (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-BLOCK-HEIGHT-NOT-REACHED) - - (map-set proposals - { id: proposal-id } - (merge proposal { is-open: false })) - - ;; Execute the proposal when the yes-vote passes threshold-count. - (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) -) - -;; Return votes to voter(member) -;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) - (let - ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) - (proposal (get-proposal-by-id proposal-id)) - ) - - (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) - (asserts! (not (get is-open proposal)) ERR-NOT-AUTHORIZED) - (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) - - ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) - (ok true) - ) -) - -;; Make needed contract changes on DAO -(define-private (execute-proposal (proposal-id uint)) - (let ( - (proposal (get-proposal-by-id proposal-id)) - (new-fee-rate-token (get new-fee-rate-token proposal)) - (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) - ) - - ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-92160 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-wbtc-92160 new-fee-rate-yield-token)) - - (ok true) - ) -) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-132481-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc.clar similarity index 75% rename from clarity/contracts/multisig/multisig-ytp-yield-usda-132481-usda.clar rename to clarity/contracts/multisig/multisig-ytp-yield-wbtc.clar index cad91b0a..a13abf91 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-132481-usda.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-wbtc.clar @@ -1,6 +1,5 @@ -(impl-trait .trait-multisig-vote.multisig-vote-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait ft-trait .trait-sip-010.sip-010-trait) +(impl-trait .trait-multisig-vote.multisig-vote-sft-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) ;; Alex voting for MultiSig DAO @@ -9,17 +8,15 @@ ;; A proposal will just update the DAO with new contracts. ;; Voting can be done by locking up the corresponding pool token. -;; This prototype is for ayusda-usda pool token. +;; This prototype is for aywbtc-wbtc pool token. ;; Common Trait and for each pool, implementation is required. ;; ;; Errors (define-constant ERR-NOT-ENOUGH-BALANCE (err u8000)) -(define-constant ERR-NO-FEE-CHANGE (err u8001)) (define-constant ERR-INVALID-POOL-TOKEN (err u8002)) (define-constant ERR-BLOCK-HEIGHT-NOT-REACHED (err u8003)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ONE_8 u100000000) @@ -35,6 +32,7 @@ { id: uint, proposer: principal, + expiry: uint, title: (string-utf8 256), url: (string-utf8 256), is-open: bool, @@ -55,7 +53,7 @@ (define-data-var threshold-percentage uint u0) (define-map votes-by-member { proposal-id: uint, member: principal } { vote-count: uint }) -(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal } { amount: uint }) +(define-map tokens-by-member { proposal-id: uint, member: principal, token: principal, expiry: uint } { amount: uint }) ;; Get all proposals in detail (define-read-only (get-proposals) @@ -75,10 +73,10 @@ ) ) -(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token )) +(define-read-only (get-tokens-by-member-by-id (proposal-id uint) (member principal) (token ) (expiry uint)) (default-to { amount: u0 } - (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token) }) + (map-get? tokens-by-member { proposal-id: proposal-id, member: member, token: (contract-of token), expiry: expiry }) ) ) @@ -88,6 +86,7 @@ { id: u0, proposer: DEFAULT_OWNER, + expiry: u0, title: u"", url: u"", is-open: false, @@ -103,15 +102,15 @@ ) ;; To check which tokens are accepted as votes, Only by staking Pool Token is allowed. -(define-read-only (is-token-accepted (token )) - (is-eq (contract-of token) .ytp-yield-usda-132481-usda) +(define-read-only (is-token-accepted (token )) + (is-eq (contract-of token) .ytp-yield-wbtc) ) - ;; Start a proposal ;; Requires 10% of the supply in your wallet ;; Default voting period is 10 days (144 * 10 blocks) (define-public (propose + (expiry uint) (start-block-height uint) (title (string-utf8 256)) (url (string-utf8 256)) @@ -119,8 +118,8 @@ (new-fee-rate-yield-token uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-132481-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-132481-usda get-total-supply)) ONE_8)) + (proposer-balance (unwrap-panic (contract-call? .ytp-yield-wbtc get-balance-fixed expiry tx-sender))) + (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc get-total-supply-fixed expiry))) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -132,6 +131,7 @@ { id: proposal-id, proposer: tx-sender, + expiry: expiry, title: title, url: url, is-open: true, @@ -149,12 +149,12 @@ ) ) -(define-public (vote-for (token ) (proposal-id uint) (amount uint)) +(define-public (vote-for (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) - + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token @@ -165,7 +165,7 @@ (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals { id: proposal-id } @@ -174,22 +174,19 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) - - ) ) +) - - - -(define-public (vote-against (token ) (proposal-id uint) (amount uint)) +(define-public (vote-against (token ) (proposal-id uint) (amount uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (vote-count (get vote-count (get-votes-by-member-by-id proposal-id tx-sender))) - (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token))) + (token-count (get amount (get-tokens-by-member-by-id proposal-id tx-sender token expiry))) ) ;; Can vote with corresponding pool token (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -198,7 +195,7 @@ ;; Vote should be casted after the start-block-height (asserts! (>= block-height (get start-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Voter should stake the corresponding pool token to the vote contract. - (try! (contract-call? token transfer amount tx-sender (as-contract tx-sender) none)) + (try! (contract-call? token transfer-fixed expiry amount tx-sender (as-contract tx-sender))) ;; Mutate (map-set proposals @@ -208,20 +205,22 @@ { proposal-id: proposal-id, member: tx-sender } { vote-count: (+ amount vote-count) }) (map-set tokens-by-member - { proposal-id: proposal-id, member: tx-sender, token: (contract-of token) } + { proposal-id: proposal-id, member: tx-sender, token: (contract-of token), expiry: expiry } { amount: (+ amount token-count)}) (ok amount) - ) - - ) + ) +) (define-public (end-proposal (proposal-id uint)) - (let ((proposal (get-proposal-by-id proposal-id)) - (threshold-percent (var-get threshold)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-132481-usda get-total-supply)) ONE_8)) - (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) - (yes-votes (get yes-votes proposal)) - ) + (let + ( + (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (threshold-percent (var-get threshold)) + (total-supply (unwrap-panic (contract-call? .ytp-yield-wbtc get-total-supply-fixed expiry))) + (threshold-count (mul-up total-supply threshold-percent)) + (yes-votes (get yes-votes proposal)) + ) (asserts! (not (is-eq (get id proposal) u0)) ERR-NOT-AUTHORIZED) ;; Default id (asserts! (get is-open proposal) ERR-NOT-AUTHORIZED) @@ -233,16 +232,18 @@ ;; Execute the proposal when the yes-vote passes threshold-count. (and (> yes-votes threshold-count) (try! (execute-proposal proposal-id))) - (ok true)) + (ok true) + ) ) ;; Return votes to voter(member) ;; This function needs to be called for all members -(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) +(define-public (return-votes-to-member (token ) (proposal-id uint) (member principal)) (let ( - (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token)) ONE_8)) (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) + (token-count (/ (get amount (get-tokens-by-member-by-id proposal-id member token expiry)) ONE_8)) ) (asserts! (is-token-accepted token) ERR-INVALID-POOL-TOKEN) @@ -250,7 +251,7 @@ (asserts! (>= block-height (get end-block-height proposal)) ERR-NOT-AUTHORIZED) ;; Return the pool token - (try! (as-contract (contract-call? token transfer token-count (as-contract tx-sender) member none))) + (try! (as-contract (contract-call? token transfer-fixed expiry token-count (as-contract tx-sender) member))) (ok true) ) ) @@ -259,14 +260,27 @@ (define-private (execute-proposal (proposal-id uint)) (let ( (proposal (get-proposal-by-id proposal-id)) + (expiry (get expiry proposal)) (new-fee-rate-token (get new-fee-rate-token proposal)) (new-fee-rate-yield-token (get new-fee-rate-yield-token proposal)) ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-132481 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-yield-token .yield-usda-132481 new-fee-rate-yield-token)) + (try! (contract-call? .yield-token-pool set-fee-rate-token expiry .yield-wbtc new-fee-rate-token)) + (try! (contract-call? .yield-token-pool set-fee-rate-yield-token expiry .yield-wbtc new-fee-rate-yield-token)) (ok true) ) ) + +(define-private (mul-up (a uint) (b uint)) + (let + ( + (product (* a b)) + ) + (if (is-eq product u0) + u0 + (+ u1 (/ (- product u1) ONE_8)) + ) + ) +) diff --git a/clarity/contracts/new-lib/math-new-fixed-point.clar b/clarity/contracts/new-lib/math-new-fixed-point.clar index 4e73cdf4..35e35467 100644 --- a/clarity/contracts/new-lib/math-new-fixed-point.clar +++ b/clarity/contracts/new-lib/math-new-fixed-point.clar @@ -6,13 +6,6 @@ ;; constants ;; (define-constant ONE_10 (pow u10 u10)) ;; 10 decimal places -(define-constant ERR-SCALE-UP-OVERFLOW (err u5001)) -(define-constant ERR-SCALE-DOWN-OVERFLOW (err u5002)) -(define-constant ERR-ADD-OVERFLOW (err u5003)) -(define-constant ERR-SUB-OVERFLOW (err u5004)) -(define-constant ERR-MUL-OVERFLOW (err u5005)) -(define-constant ERR-DIV-OVERFLOW (err u5006)) -(define-constant ERR-POW-OVERFLOW (err u5007)) ;; With 10 fixed digits you would have a maximum error of 0.5 * 10^-10 in each entry, ;; which could aggregate to about 10 x 0.5 * 10^-10 = 4 * 10^-10 relative error diff --git a/clarity/contracts/pool-token/fwp-usda-23040-usda-74880-50-50.clar b/clarity/contracts/pool-token/fwp-usda-23040-usda-74880-50-50.clar deleted file mode 100644 index f113e104..00000000 --- a/clarity/contracts/pool-token/fwp-usda-23040-usda-74880-50-50.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token fwp-usda-23040-usda-74880) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .fixed-weight-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply fwp-usda-23040-usda-74880))) -) - -(define-read-only (get-name) - (ok "fwp-usda-23040-usda-74880") -) - -(define-read-only (get-symbol) - (ok "fwp-usda-23040-usda-74880") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance fwp-usda-23040-usda-74880 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? fwp-usda-23040-usda-74880 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? fwp-usda-23040-usda-74880 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? fwp-usda-23040-usda-74880 (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/fwp-wbtc-usda-50-50.clar b/clarity/contracts/pool-token/fwp-wbtc-usda-50-50.clar index 0b9095a9..8bb1af26 100644 --- a/clarity/contracts/pool-token/fwp-wbtc-usda-50-50.clar +++ b/clarity/contracts/pool-token/fwp-wbtc-usda-50-50.clar @@ -1,45 +1,36 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token fwp-wbtc-usda-50-50) (define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .fixed-weight-pool) +(define-data-var CONTRACT-OWNER principal tx-sender) +(define-map approved-contracts principal bool) ;; errors (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-read-only (get-owner) - (ok (var-get contract-owner)) + (ok (var-get CONTRACT-OWNER)) ) (define-public (set-owner (owner principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + (ok (var-set CONTRACT-OWNER owner)) ) ) +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get CONTRACT-OWNER))) ERR-NOT-AUTHORIZED)) +) + ;; --------------------------------------------------------- ;; SIP-10 Functions ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply fwp-wbtc-usda-50-50))) + (ok (ft-get-supply fwp-wbtc-usda-50-50)) ) (define-read-only (get-name) @@ -51,16 +42,16 @@ ) (define-read-only (get-decimals) - (ok u8) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance fwp-wbtc-usda-50-50 account))) + (ok (ft-get-balance fwp-wbtc-usda-50-50 account)) ) (define-public (set-token-uri (value (string-utf8 256))) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) (ok (var-set token-uri value)) ) ) @@ -72,7 +63,7 @@ (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? fwp-wbtc-usda-50-50 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? fwp-wbtc-usda-50-50 amount sender recipient) response (begin (print memo) (ok response) @@ -82,16 +73,56 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? fwp-wbtc-usda-50-50 (fixed-to-decimals amount) recipient) + (try! (check-is-approved contract-caller)) + (ft-mint? fwp-wbtc-usda-50-50 amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? fwp-wbtc-usda-50-50 (fixed-to-decimals amount) sender) + (try! (check-is-approved contract-caller)) + (ft-burn? fwp-wbtc-usda-50-50 amount sender) ) -) \ No newline at end of file +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply fwp-wbtc-usda-50-50))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance fwp-wbtc-usda-50-50 account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .fixed-weight-pool true) +) + + diff --git a/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar b/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar index 4c44de57..31177772 100644 --- a/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar +++ b/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar @@ -1,45 +1,36 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token lbp-alex-usda-90-10) (define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .liquidity-bootstrapping-pool) +(define-data-var CONTRACT-OWNER principal tx-sender) +(define-map approved-contracts principal bool) ;; errors (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-read-only (get-owner) - (ok (var-get contract-owner)) + (ok (var-get CONTRACT-OWNER)) ) (define-public (set-owner (owner principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + (ok (var-set CONTRACT-OWNER owner)) ) ) +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get CONTRACT-OWNER))) ERR-NOT-AUTHORIZED)) +) + ;; --------------------------------------------------------- ;; SIP-10 Functions ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply lbp-alex-usda-90-10))) + (ok (ft-get-supply lbp-alex-usda-90-10)) ) (define-read-only (get-name) @@ -51,16 +42,16 @@ ) (define-read-only (get-decimals) - (ok u8) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance lbp-alex-usda-90-10 account))) + (ok (ft-get-balance lbp-alex-usda-90-10 account)) ) (define-public (set-token-uri (value (string-utf8 256))) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) (ok (var-set token-uri value)) ) ) @@ -72,7 +63,7 @@ (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? lbp-alex-usda-90-10 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? lbp-alex-usda-90-10 amount sender recipient) response (begin (print memo) (ok response) @@ -82,16 +73,56 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? lbp-alex-usda-90-10 (fixed-to-decimals amount) recipient) + (try! (check-is-approved contract-caller)) + (ft-mint? lbp-alex-usda-90-10 amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? lbp-alex-usda-90-10 (fixed-to-decimals amount) sender) + (try! (check-is-approved contract-caller)) + (ft-burn? lbp-alex-usda-90-10 amount sender) ) -) \ No newline at end of file +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply lbp-alex-usda-90-10))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance lbp-alex-usda-90-10 account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .liquidity-bootstrapping-pool true) +) + + diff --git a/clarity/contracts/pool-token/ytp-yield-usda-11520-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-11520-usda.clar deleted file mode 100644 index 245f2084..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-11520-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-11520-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-11520-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-11520-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-11520-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-11520-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-11520-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-11520-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-11520-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-121195-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-121195-usda.clar deleted file mode 100644 index 4144b946..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-121195-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-121195-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-121195-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-121195-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-121195-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-121195-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-121195-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-121195-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-121195-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-132481-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-132481-usda.clar deleted file mode 100644 index 3e6631dc..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-132481-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-132481-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-132481-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-132481-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-132481-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-132481-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-132481-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-132481-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-132481-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-161515-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-161515-usda.clar deleted file mode 100644 index ba5f83a5..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-161515-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-161515-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-161515-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-161515-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-161515-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-161515-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-161515-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-161515-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-161515-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-200335-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-200335-usda.clar deleted file mode 100644 index 33bb18d3..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-200335-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-200335-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-200335-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-200335-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-200335-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-200335-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-200335-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-200335-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-200335-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-23040-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-23040-usda.clar deleted file mode 100644 index 362f3084..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-23040-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-23040-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-23040-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-23040-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-23040-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-23040-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-23040-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-23040-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-23040-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-240655-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-240655-usda.clar deleted file mode 100644 index f2b3357f..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-240655-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-240655-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-240655-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-240655-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-240655-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-240655-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-240655-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-240655-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-240655-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-34560-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-34560-usda.clar deleted file mode 100644 index b137c16a..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-34560-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-34560-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-34560-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-34560-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-34560-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-34560-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-34560-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-34560-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-34560-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar deleted file mode 100644 index d8d762f7..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-51840-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-51840-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-51840-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-51840-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-51840-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-51840-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-51840-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-51840-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-80875-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-80875-usda.clar deleted file mode 100644 index 66356b54..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-80875-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-80875-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-80875-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-80875-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-80875-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-80875-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-80875-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-80875-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-80875-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda-92160-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-92160-usda.clar deleted file mode 100644 index 88f2a015..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-92160-usda.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-usda-92160-usda) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-92160-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-92160-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-92160-usda") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-92160-usda account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-usda-92160-usda (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-usda-92160-usda (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-usda-92160-usda (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda.clar new file mode 100644 index 00000000..70fe9997 --- /dev/null +++ b/clarity/contracts/pool-token/ytp-yield-usda.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token ytp-yield-usda) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance ytp-yield-usda who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply ytp-yield-usda)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? ytp-yield-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? ytp-yield-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? ytp-yield-usda amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? ytp-yield-usda amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .yield-token-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar deleted file mode 100644 index a1ab5ea2..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-11520-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-11520-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-11520-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-11520-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-11520-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-11520-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-11520-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-11520-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-121195-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-121195-wbtc.clar deleted file mode 100644 index 7c7aa88d..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-121195-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-121195-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-121195-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-121195-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-121195-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-121195-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-121195-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-121195-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-121195-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-132481-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-132481-wbtc.clar deleted file mode 100644 index c756650b..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-132481-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-132481-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-132481-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-132481-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-132481-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-132481-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-132481-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-132481-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-132481-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-161515-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-161515-wbtc.clar deleted file mode 100644 index 63200e6f..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-161515-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-161515-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-161515-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-161515-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-161515-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-161515-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-161515-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-161515-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-161515-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-200335-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-200335-wbtc.clar deleted file mode 100644 index d5751aca..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-200335-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-200335-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-200335-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-200335-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-200335-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-200335-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-200335-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-200335-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-200335-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-23040-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-23040-wbtc.clar deleted file mode 100644 index 69522189..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-23040-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-23040-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-23040-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-23040-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-23040-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-23040-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-23040-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-23040-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-23040-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-23670-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-23670-wbtc.clar deleted file mode 100644 index 3189e92c..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-23670-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-23670-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-23670-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-23670-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-23670-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-23670-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-23670-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-23670-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-23670-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-240655-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-240655-wbtc.clar deleted file mode 100644 index da6c6d27..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-240655-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-240655-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-240655-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-240655-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-240655-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-240655-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-240655-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-240655-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-240655-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-34560-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-34560-wbtc.clar deleted file mode 100644 index bad105cb..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-34560-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-34560-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-34560-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-34560-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-34560-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-34560-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-34560-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-34560-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-34560-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar deleted file mode 100644 index 8a6e523e..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-51840-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-51840-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-51840-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-51840-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-51840-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-51840-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-51840-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-51840-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-59760-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-59760-wbtc.clar deleted file mode 100644 index ecc1b43f..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-59760-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-59760-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-59760-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-59760-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-59760-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-59760-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-59760-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-59760-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-59760-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-79760-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-79760-wbtc.clar deleted file mode 100644 index 3855af07..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-79760-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-79760-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-79760-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-79760-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-79760-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-79760-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-79760-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-79760-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-79760-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-80875-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-80875-wbtc.clar deleted file mode 100644 index ae7fd6b2..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-80875-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-80875-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-80875-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-80875-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-80875-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-80875-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-80875-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-80875-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-80875-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-92160-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-92160-wbtc.clar deleted file mode 100644 index 5df22005..00000000 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-92160-wbtc.clar +++ /dev/null @@ -1,97 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) - -(define-fungible-token ytp-yield-wbtc-92160-wbtc) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-92160-wbtc))) -) - -(define-read-only (get-name) - (ok "ytp-yield-wbtc-92160-wbtc") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-wbtc-92160-wbtc") -) - -(define-read-only (get-decimals) - (ok u8) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-92160-wbtc account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? ytp-yield-wbtc-92160-wbtc (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? ytp-yield-wbtc-92160-wbtc (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? ytp-yield-wbtc-92160-wbtc (fixed-to-decimals amount) sender) - ) -) \ No newline at end of file diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc.clar new file mode 100644 index 00000000..9f20c8aa --- /dev/null +++ b/clarity/contracts/pool-token/ytp-yield-wbtc.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token ytp-yield-wbtc) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance ytp-yield-wbtc who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply ytp-yield-wbtc)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? ytp-yield-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? ytp-yield-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? ytp-yield-wbtc amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? ytp-yield-wbtc amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .yield-token-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/pool/alex-futures-pool.clar b/clarity/contracts/pool/alex-futures-pool.clar new file mode 100644 index 00000000..7f3246d2 --- /dev/null +++ b/clarity/contracts/pool/alex-futures-pool.clar @@ -0,0 +1,195 @@ +(impl-trait .trait-ownable.ownable-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) +(use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) + +;; alex-futures-pool +;; ideally we want to make this a "generic" pool, but there is an issue with iterating over trait (claim-staking-rewards) +;; + +;; constants +;; +(define-constant ONE_8 u100000000) ;; 8 decimal places + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-INVALID-POOL (err u2001)) +(define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-staking-IN-PROGRESS (err u2018)) +(define-constant ERR-staking-NOT-AVAILABLE (err u2027)) + +(define-data-var CONTRACT-OWNER principal tx-sender) + +(define-constant REWARD-CYCLE-INDEXES (list u0 u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 u12 u13 u14 u15 u16 u17 u18 u19 u20 u21 u22 u23 u24 u25 u26 u27 u28 u29 u30 u31)) + +(define-read-only (get-owner) + (ok (var-get CONTRACT-OWNER)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + (ok (var-set CONTRACT-OWNER owner)) + ) +) + +;; data maps and vars +;; +;; pools-map = pool-id, start-cycle +(define-map pools-map uint uint) + +(define-map pools-data-map + uint + { + total-supply: uint, + fee-to-address: principal, + pool-token: principal, + reward-cycles: (list 32 uint) + } +) + +(define-data-var pool-count uint u0) +(define-data-var pools-list (list 2000 uint) (list)) + +;; private functions +;; +(define-private (sum-staking-reward (reward-cycle uint) (sum-so-far uint)) + (+ sum-so-far (get-staking-reward reward-cycle)) +) +(define-private (get-staking-reward (reward-cycle uint)) + (contract-call? .alex-reserve-pool get-staking-reward .token-alex (get-user-id) reward-cycle) +) +(define-private (register-user) + (as-contract (contract-call? .alex-reserve-pool register-user .token-alex none)) +) +(define-private (get-user-id) + (default-to u0 (contract-call? .alex-reserve-pool get-user-id .token-alex (as-contract tx-sender))) +) +(define-private (get-reward-cycle (stack-height uint)) + (contract-call? .alex-reserve-pool get-reward-cycle .token-alex stack-height) +) +(define-private (stake-tokens (amount-tokens uint) (lock-period uint)) + (as-contract (contract-call? .alex-reserve-pool stake-tokens .token-alex amount-tokens lock-period)) +) +(define-private (get-first-stacks-block-in-reward-cycle (reward-cycle uint)) + (contract-call? .alex-reserve-pool get-first-stacks-block-in-reward-cycle .token-alex reward-cycle) +) +(define-private (claim-staking-reward (reward-cycle uint)) + (as-contract (contract-call? .alex-reserve-pool claim-staking-reward .token-alex reward-cycle)) +) + +;; public functions +;; +(define-read-only (get-pool-count) + (ok (var-get pool-count)) +) + +(define-read-only (get-pool-contracts (pool-id uint)) + (ok (unwrap! (map-get? pools-map pool-id) ERR-INVALID-POOL)) +) + +(define-read-only (get-pools) + (ok (map get-pool-contracts (var-get pools-list))) +) + +(define-read-only (get-pool-details (start-cycle uint)) + (ok (unwrap! (map-get? pools-data-map start-cycle) ERR-INVALID-POOL)) +) + +(define-read-only (get-balance (start-cycle uint)) + (ok (get total-supply (unwrap! (map-get? pools-data-map start-cycle) ERR-INVALID-POOL))) +) + +(define-public (create-pool (reward-cycles (list 32 uint)) (futures-token ) (multisig )) + (let + ( + (pool-id (+ (var-get pool-count) u1)) + (pool-data { + total-supply: u0, + fee-to-address: (contract-of multisig), + pool-token: (contract-of futures-token), + reward-cycles: reward-cycles + }) + (start-cycle (default-to u0 (element-at reward-cycles u0))) + ) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + + ;; register if not registered + (try! (register-user)) + + (asserts! (is-none (map-get? pools-data-map start-cycle)) ERR-POOL-ALREADY-EXISTS) + + (map-set pools-map pool-id start-cycle) + (map-set pools-data-map start-cycle pool-data) + + (var-set pools-list (unwrap! (as-max-len? (append (var-get pools-list) pool-id) u2000) ERR-TOO-MANY-POOLS)) + (var-set pool-count pool-id) + (print { object: "pool", action: "created", pool-data: pool-data }) + (ok true) + ) +) + +(define-public (add-to-position (start-cycle uint) (futures-token ) (dx uint)) + (let + ( + (pool (unwrap! (map-get? pools-data-map start-cycle) ERR-INVALID-POOL)) + (total-supply (get total-supply pool)) + (pool-updated (merge pool { + total-supply: (+ dx total-supply) + })) + (current-cycle (unwrap! (get-reward-cycle block-height) ERR-staking-NOT-AVAILABLE)) + ) + ;; check if staking already started + (asserts! (> start-cycle current-cycle) ERR-staking-IN-PROGRESS) + + ;; transfer dx to contract and send to stake + (try! (contract-call? .token-alex transfer-fixed dx tx-sender (as-contract tx-sender) none)) + (try! (stake-tokens dx u32)) + + ;; mint pool token and send to tx-sender + (map-set pools-data-map start-cycle pool-updated) + (try! (contract-call? futures-token mint-fixed start-cycle dx tx-sender)) + (print { object: "pool", action: "liquidity-added", data: pool-updated }) + (ok true) + ) +) + +(define-public (reduce-position (start-cycle uint) (futures-token ) (percent uint)) + (let + ( + (pool (unwrap! (map-get? pools-data-map start-cycle) ERR-INVALID-POOL)) + (shares (mul-down (unwrap-panic (contract-call? futures-token get-balance-fixed start-cycle tx-sender)) percent)) + (total-supply (get total-supply pool)) + (pool-updated (merge pool { + total-supply: (- total-supply shares) + }) + ) + (reward-cycles (get reward-cycles pool)) + (shares-to-supply (div-down shares total-supply)) + (total-rewards (fold sum-staking-reward reward-cycles u0)) + (portioned-rewards (mul-down total-rewards shares-to-supply)) + ) + + (asserts! (> block-height (+ (get-first-stacks-block-in-reward-cycle (+ start-cycle u32)) (contract-call? .alex-reserve-pool get-reward-cycle-length))) ERR-staking-IN-PROGRESS) + + ;; the first call claims rewards + (map claim-staking-reward reward-cycles) + + (try! (contract-call? .token-alex transfer-fixed (+ shares portioned-rewards) (as-contract tx-sender) tx-sender none)) + + (map-set pools-data-map start-cycle pool-updated) + (try! (contract-call? futures-token burn-fixed start-cycle shares tx-sender)) + (print { object: "pool", action: "liquidity-removed", data: pool-updated }) + (ok {staked: shares, rewards: portioned-rewards}) + ) +) + +(define-read-only (mul-down (a uint) (b uint)) + (/ (* a b) ONE_8) +) + +(define-read-only (div-down (a uint) (b uint)) + (if (is-eq a u0) + u0 + (/ (* a ONE_8) b) + ) +) \ No newline at end of file diff --git a/clarity/contracts/pool/alex-reserve-pool.clar b/clarity/contracts/pool/alex-reserve-pool.clar index f10c75bb..57080d1e 100644 --- a/clarity/contracts/pool/alex-reserve-pool.clar +++ b/clarity/contracts/pool/alex-reserve-pool.clar @@ -1,42 +1,19 @@ (impl-trait .trait-ownable.ownable-trait) -(use-trait pool-token-trait .trait-pool-token.pool-token-trait) +(use-trait ft-trait .trait-sip-010.sip-010-trait) ;; alex-reserve-pool -(define-constant ERR-INVALID-POOL-ERR (err u2001)) -(define-constant ERR-NO-LIQUIDITY (err u2002)) -(define-constant ERR-INVALID-LIQUIDITY (err u2003)) -(define-constant ERR-TRANSFER-X-FAILED (err u3001)) -(define-constant ERR-TRANSFER-Y-FAILED (err u3002)) -(define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) -(define-constant ERR-TOO-MANY-POOLS (err u2004)) -(define-constant ERR-PERCENT-GREATER-THAN-ONE (err u5000)) -(define-constant ERR-NO-FEE (err u2005)) -(define-constant ERR-NO-FEE-Y (err u2006)) -(define-constant ERR-WEIGHTED-EQUATION-CALL (err u2009)) -(define-constant ERR-MATH-CALL (err u2010)) -(define-constant ERR-INTERNAL-FUNCTION-CALL (err u1001)) -(define-constant ERR-GET-WEIGHT-FAIL (err u2012)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) -(define-constant ERR-GET-PRICE-FAIL (err u2015)) -(define-constant ERR-GET-SYMBOL-FAIL (err u6000)) -(define-constant ERR-GET-ORACLE-PRICE-FAIL (err u7000)) -(define-constant ERR-EXPIRY (err u2017)) -(define-constant ERR-GET-BALANCE-FAIL (err u6001)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) (define-constant ERR-TRANSFER-FAILED (err u3000)) (define-constant ERR-USER-ALREADY-REGISTERED (err u10001)) -(define-constant ERR-USER-NOT-FOUND (err u10002)) (define-constant ERR-USER-ID-NOT-FOUND (err u10003)) (define-constant ERR-ACTIVATION-THRESHOLD-REACHED (err u10004)) -(define-constant ERR-UNABLE-TO-SET-THRESHOLD (err u10021)) (define-constant ERR-CONTRACT-NOT-ACTIVATED (err u10005)) (define-constant ERR-STAKING-NOT-AVAILABLE (err u10015)) (define-constant ERR-CANNOT-STAKE (err u10016)) (define-constant ERR-REWARD-CYCLE-NOT-COMPLETED (err u10017)) (define-constant ERR-NOTHING-TO-REDEEM (err u10018)) (define-constant ERR-AMOUNT-EXCEED-RESERVE (err u2024)) -(define-constant ERR-TOO-MANY-TOKENS (err u2025)) (define-constant ERR-INVALID-TOKEN (err u2026)) (define-constant ONE_8 (pow u10 u8)) ;; 8 decimal places @@ -135,6 +112,10 @@ uint ) +(define-read-only (get-reward-cycle-length) + (var-get reward-cycle-length) +) + (define-read-only (is-token-approved (token principal)) (is-some (map-get? approved-tokens token)) ) @@ -301,7 +282,7 @@ (if (or (<= current-cycle target-cycle) (is-eq u0 user-staked-this-cycle)) ;; this cycle hasn't finished, or staker contributed nothing u0 - (mul-down (get-coinbase-amount-or-default token target-cycle) (div-down user-staked-this-cycle total-staked-this-cycle)) + (mul-down (get-coinbase-amount-or-default token target-cycle) (div-down user-staked-this-cycle total-staked-this-cycle)) ) ;; before first reward cycle u0 @@ -311,14 +292,14 @@ ;; STAKING ACTIONS -(define-public (stake-tokens (token-trait ) (amount-token uint) (lock-period uint)) +(define-public (stake-tokens (token-trait ) (amount-token uint) (lock-period uint)) (begin (asserts! (default-to false (map-get? approved-tokens (contract-of token-trait))) ERR-INVALID-TOKEN) (stake-tokens-at-cycle token-trait tx-sender (get-or-create-user-id (contract-of token-trait) tx-sender) amount-token block-height lock-period) ) ) -(define-private (stake-tokens-at-cycle (token-trait ) (user principal) (user-id uint) (amount-token uint) (start-height uint) (lock-period uint)) +(define-private (stake-tokens-at-cycle (token-trait ) (user principal) (user-id uint) (amount-token uint) (start-height uint) (lock-period uint)) (let ( (token (contract-of token-trait)) @@ -335,7 +316,7 @@ (asserts! (>= block-height (get-activation-block-or-default token)) ERR-CONTRACT-NOT-ACTIVATED) (asserts! (and (> lock-period u0) (<= lock-period MAX-REWARD-CYCLES)) ERR-CANNOT-STAKE) (asserts! (> amount-token u0) ERR-CANNOT-STAKE) - (unwrap! (contract-call? token-trait transfer amount-token tx-sender .alex-vault none) ERR-TRANSFER-FAILED) + (unwrap! (contract-call? token-trait transfer-fixed amount-token tx-sender .alex-vault none) ERR-TRANSFER-FAILED) (try! (as-contract (add-to-balance token amount-token))) (match (fold stake-tokens-closure REWARD-CYCLE-INDEXES (ok commitment)) ok-value (ok true) @@ -411,14 +392,14 @@ ;; STAKING REWARD CLAIMS ;; calls function to claim staking reward in active logic contract -(define-public (claim-staking-reward (token-trait ) (target-cycle uint)) +(define-public (claim-staking-reward (token-trait ) (target-cycle uint)) (begin (asserts! (default-to false (map-get? approved-tokens (contract-of token-trait))) ERR-INVALID-TOKEN) (claim-staking-reward-at-cycle token-trait tx-sender block-height target-cycle) ) ) -(define-private (claim-staking-reward-at-cycle (token-trait ) (user principal) (stacks-height uint) (target-cycle uint)) +(define-private (claim-staking-reward-at-cycle (token-trait ) (user principal) (stacks-height uint) (target-cycle uint)) (let ( (token (contract-of token-trait)) @@ -442,11 +423,11 @@ } ) ;; send back tokens if user was eligible - (and (> to-return u0) (try! (contract-call? .alex-vault transfer-pool token-trait to-return user))) + (and (> to-return u0) (try! (contract-call? .alex-vault transfer-ft token-trait to-return user))) (and (> to-return u0) (try! (as-contract (remove-from-balance (contract-of token-trait) to-return)))) ;; send back rewards if user was eligible - (and (> entitled-token u0) (as-contract (try! (contract-call? token-trait mint user entitled-token)))) - (ok true) + (and (> entitled-token u0) (as-contract (try! (contract-call? token-trait mint-fixed entitled-token user)))) + (ok { to-return: to-return, entitled-token: entitled-token }) ) ) diff --git a/clarity/contracts/pool/collateral-rebalancing-pool.clar b/clarity/contracts/pool/collateral-rebalancing-pool.clar index e5cf288b..65963ccc 100644 --- a/clarity/contracts/pool/collateral-rebalancing-pool.clar +++ b/clarity/contracts/pool/collateral-rebalancing-pool.clar @@ -1,7 +1,7 @@ (impl-trait .trait-ownable.ownable-trait) (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) +(use-trait multisig-trait .trait-multisig-vote.multisig-vote-sft-trait) ;; collateral-rebalancing-pool ;; @@ -11,24 +11,16 @@ (define-constant ONE_8 u100000000) ;; 8 decimal places (define-constant ERR-INVALID-POOL-ERR (err u2001)) -(define-constant ERR-NO-LIQUIDITY (err u2002)) (define-constant ERR-INVALID-LIQUIDITY (err u2003)) (define-constant ERR-TRANSFER-X-FAILED (err u3001)) (define-constant ERR-TRANSFER-Y-FAILED (err u3002)) (define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) (define-constant ERR-TOO-MANY-POOLS (err u2004)) (define-constant ERR-PERCENT_GREATER_THAN_ONE (err u5000)) -(define-constant ERR-NO-FEE (err u2005)) -(define-constant ERR-NO-FEE-Y (err u2006)) (define-constant ERR-WEIGHTED-EQUATION-CALL (err u2009)) -(define-constant ERR-INTERNAL-FUNCTION-CALL (err u1001)) (define-constant ERR-GET-WEIGHT-FAIL (err u2012)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) -(define-constant ERR-GET-PRICE-FAIL (err u2015)) -(define-constant ERR-GET-SYMBOL-FAIL (err u6000)) -(define-constant ERR-GET-ORACLE-PRICE-FAIL (err u7000)) (define-constant ERR-EXPIRY (err u2017)) -(define-constant ERR-GET-BALANCE-FAIL (err u6001)) +(define-constant ERR-GET-BALANCE-FIXED-FAIL (err u6001)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) (define-constant ERR-LTV-GREATER-THAN-ONE (err u2019)) (define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2020)) @@ -283,11 +275,11 @@ ;; @param moving-average; weighting smoothing factor ;; @param dx; amount of collateral token being added ;; @returns (response bool uint) -(define-public (create-pool (token ) (collateral ) (the-yield-token ) (the-key-token ) (multisig-vote ) (ltv-0 uint) (conversion-ltv uint) (bs-vol uint) (moving-average uint) (dx uint)) +(define-public (create-pool (token ) (collateral ) (expiry uint) (the-yield-token ) (the-key-token ) (multisig-vote ) (ltv-0 uint) (conversion-ltv uint) (bs-vol uint) (moving-average uint) (dx uint)) (begin (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) (asserts! - (is-none (map-get? pools-data-map { token-x: (contract-of collateral), token-y: (contract-of token), expiry: (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR) })) + (is-none (map-get? pools-data-map { token-x: (contract-of collateral), token-y: (contract-of token), expiry: expiry })) ERR-POOL-ALREADY-EXISTS ) (let @@ -295,7 +287,6 @@ (pool-id (+ (var-get pool-count) u1)) (token-x (contract-of collateral)) (token-y (contract-of token)) - (expiry (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) (now (* block-height ONE_8)) ;; assume 10mins per block @@ -343,7 +334,7 @@ (var-set pools-list (unwrap! (as-max-len? (append (var-get pools-list) pool-id) u2000) ERR-TOO-MANY-POOLS)) (var-set pool-count pool-id) - (try! (add-to-position token collateral the-yield-token the-key-token dx)) + (try! (add-to-position token collateral expiry the-yield-token the-key-token dx)) (print { object: "pool", action: "created", data: pool-data }) (ok true) ) @@ -360,12 +351,12 @@ ;; @post yield-token; sender transfers > 0 to alex-vault ;; @post token; alex-vault transfers >0 to sender ;; @returns (response (tuple uint uint) uint) -(define-public (add-to-position-and-switch (token ) (collateral ) (the-yield-token ) (the-key-token ) (dx uint)) +(define-public (add-to-position-and-switch (token ) (collateral ) (expiry uint) (the-yield-token ) (the-key-token ) (dx uint)) (let ( - (minted-yield-token (get yield-token (try! (add-to-position token collateral the-yield-token the-key-token dx)))) + (minted-yield-token (get yield-token (try! (add-to-position token collateral expiry the-yield-token the-key-token dx)))) ) - (contract-call? .yield-token-pool swap-y-for-x the-yield-token token minted-yield-token none) + (contract-call? .yield-token-pool swap-y-for-x expiry the-yield-token token minted-yield-token none) ) ) @@ -377,13 +368,12 @@ ;; @param dx; amount of collateral added ;; @post collateral; sender transfer exactly dx to alex-vault ;; @returns (response (tuple uint uint) uint) -(define-public (add-to-position (token ) (collateral ) (the-yield-token ) (the-key-token ) (dx uint)) +(define-public (add-to-position (token ) (collateral ) (expiry uint) (the-yield-token ) (the-key-token ) (dx uint)) (let ( (token-x (contract-of collateral)) - (token-y (contract-of token)) - (expiry (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) + (token-y (contract-of token)) + (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) (conversion-ltv (get conversion-ltv pool)) (ltv (try! (get-ltv token collateral expiry))) ) @@ -425,8 +415,8 @@ (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) ;; mint pool token and send to tx-sender - (try! (contract-call? the-yield-token mint tx-sender yield-new-supply)) - (try! (contract-call? the-key-token mint tx-sender key-new-supply)) + (try! (contract-call? the-yield-token mint expiry yield-new-supply tx-sender)) + (try! (contract-call? the-key-token mint expiry key-new-supply tx-sender)) (print { object: "pool", action: "liquidity-added", data: pool-updated }) (ok {yield-token: yield-new-supply, key-token: key-new-supply}) ) @@ -440,22 +430,21 @@ ;; @param percent; % of yield-token held to be burnt ;; @post yield-token; alex-vault transfer exactly uints of token equal to (percent * yield-token held) to sender ;; @returns (response (tuple uint uint) uint) -(define-public (reduce-position-yield (token ) (collateral ) (the-yield-token ) (percent uint)) +(define-public (reduce-position-yield (token ) (collateral ) (expiry uint) (the-yield-token ) (percent uint)) (begin (asserts! (<= percent ONE_8) ERR-PERCENT_GREATER_THAN_ONE) ;; burn supported only at maturity - (asserts! (> (* block-height ONE_8) (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) ERR-EXPIRY) + (asserts! (> (* block-height ONE_8) expiry) ERR-EXPIRY) (let ( (token-x (contract-of collateral)) (token-y (contract-of token)) - (expiry (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (yield-supply (get yield-supply pool)) - (total-shares (unwrap! (contract-call? the-yield-token get-balance tx-sender) ERR-GET-BALANCE-FAIL)) + (total-shares (unwrap! (contract-call? the-yield-token get-balance-fixed expiry tx-sender) ERR-GET-BALANCE-FIXED-FAIL)) (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent))) (shares-to-yield (div-down shares yield-supply)) @@ -499,7 +488,7 @@ (try! (contract-call? .alex-vault transfer-ft token shares tx-sender)) (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) - (try! (contract-call? the-yield-token burn tx-sender shares)) + (try! (contract-call? the-yield-token burn expiry shares tx-sender)) (print { object: "pool", action: "liquidity-removed", data: pool-updated }) (ok {dx: u0, dy: shares}) @@ -515,21 +504,20 @@ ;; @post token; alex-vault transfers > 0 token to sender ;; @post collateral; alex-vault transfers > 0 collateral to sender ;; @returns (response (tuple uint uint) uint) -(define-public (reduce-position-key (token ) (collateral ) (the-key-token ) (percent uint)) +(define-public (reduce-position-key (token ) (collateral ) (expiry uint) (the-key-token ) (percent uint)) (begin (asserts! (<= percent ONE_8) ERR-PERCENT_GREATER_THAN_ONE) ;; burn supported only at maturity - (asserts! (> (* block-height ONE_8) (unwrap! (contract-call? the-key-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) ERR-EXPIRY) + (asserts! (> (* block-height ONE_8) expiry) ERR-EXPIRY) (let ( (token-x (contract-of collateral)) (token-y (contract-of token)) - (expiry (unwrap! (contract-call? the-key-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (key-supply (get key-supply pool)) - (total-shares (unwrap! (contract-call? the-key-token get-balance tx-sender) ERR-GET-BALANCE-FAIL)) + (total-shares (unwrap! (contract-call? the-key-token get-balance-fixed expiry tx-sender) ERR-GET-BALANCE-FIXED-FAIL)) (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent))) (reduce-data (try! (get-position-given-burn-key token collateral expiry shares))) (dx-weighted (get dx reduce-data)) @@ -549,7 +537,7 @@ (and (> dy-weighted u0) (try! (contract-call? .alex-vault transfer-ft token dy-weighted tx-sender))) (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) - (try! (contract-call? the-key-token burn tx-sender shares)) + (try! (contract-call? the-key-token burn expiry shares tx-sender)) (print { object: "pool", action: "liquidity-removed", data: pool-updated }) (ok {dx: dx-weighted, dy: dy-weighted}) ) @@ -986,16 +974,6 @@ ;; TODO: overflow causes runtime error, should handle before operation rather than after -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -1004,18 +982,6 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - -(define-read-only (scale-up (a uint)) - (* a ONE_8) -) - -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -1060,16 +1026,6 @@ ) ) -(define-read-only (pow-up (a uint) (b uint)) - (let - ( - (raw (unwrap-panic (pow-fixed a b))) - (max-error (+ u1 (mul-up raw MAX_POW_RELATIVE_ERROR))) - ) - (+ raw max-error) - ) -) - ;; math-log-exp ;; Exponentiation and logarithm functions for 8 decimal fixed point numbers (both base and exponent/argument). ;; Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural @@ -1115,11 +1071,11 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) +(define-constant ERR_OUT_OF_BOUNDS (err u5013)) ;; private functions ;; @@ -1184,14 +1140,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -1252,10 +1208,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -1271,7 +1227,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -1282,22 +1238,10 @@ ) ) -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - ;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. (define-read-only (ln-fixed (a int)) (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) + (asserts! (> a 0) ERR_OUT_OF_BOUNDS) (if (< a iONE_8) ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). ;; If a is less than one, 1/a will be greater than one. diff --git a/clarity/contracts/pool/fixed-weight-pool.clar b/clarity/contracts/pool/fixed-weight-pool.clar index 045163b9..15121136 100644 --- a/clarity/contracts/pool/fixed-weight-pool.clar +++ b/clarity/contracts/pool/fixed-weight-pool.clar @@ -1,6 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait pool-token-trait .trait-pool-token.pool-token-trait) (use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) ;; fixed-weight-pool @@ -11,20 +10,12 @@ (define-constant ERR-NOT-AUTHORIZED (err u1000)) (define-constant ERR-INVALID-POOL-ERR (err u2001)) -(define-constant ERR-NO-LIQUIDITY (err u2002)) (define-constant ERR-INVALID-LIQUIDITY (err u2003)) (define-constant ERR-TRANSFER-X-FAILED (err u3001)) (define-constant ERR-TRANSFER-Y-FAILED (err u3002)) (define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) (define-constant ERR-TOO-MANY-POOLS (err u2004)) (define-constant ERR-PERCENT_GREATER_THAN_ONE (err u5000)) -(define-constant ERR-INVALID-BALANCE (err u2008)) -(define-constant ERR-INVALID-TOKEN (err u2007)) -(define-constant ERR-NO-FEE (err u2005)) -(define-constant ERR-NO-FEE-Y (err u2006)) -(define-constant ERR-WEIGHTED-EQUATION-CALL (err u2009)) -(define-constant ERR-MATH-CALL (err u2010)) -(define-constant ERR-GET-ORACLE-PRICE-FAIL (err u7000)) (define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2020)) (define-constant ERR-ORACLE-NOT-ENABLED (err u7002)) (define-constant ERR-ORACLE-ALREADY-ENABLED (err u7003)) @@ -119,13 +110,13 @@ (map-get? pools-data-map { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), weight-x: weight-x, weight-y: weight-y }) ) -;; @desc get-balances ({balance-x, balance-y}) +;; @desc get-balance-fixeds ({balance-x, balance-y}) ;; @param token-x-trait; token-x ;; @param token-y-trait; token-y ;; @param weight-x; weight of token-x ;; @param weight-y; weight of token-y ;; @returns (response (tuple uint uint) uint) -(define-read-only (get-balances (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) +(define-read-only (get-balance-fixeds (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) (let ( (token-x (contract-of token-x-trait)) @@ -275,7 +266,7 @@ ;; @param dx; amount of token-x added ;; @param dy; amount of token-y added ;; @returns (response bool uint) -(define-public (create-pool (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) +(define-public (create-pool (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) (let ( (token-x (contract-of token-x-trait)) @@ -328,7 +319,7 @@ ;; @param dx; amount of token-x added ;; @param dy; amount of token-y added ;; @returns (response (tuple uint uint uint) uint) -(define-public (add-to-position (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (dx uint) (dy uint)) +(define-public (add-to-position (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (dx uint) (dy uint)) (begin (asserts! (and (> dx u0) (> dy u0)) ERR-INVALID-LIQUIDITY) @@ -357,7 +348,7 @@ ;; mint pool token and send to tx-sender (map-set pools-data-map { token-x: token-x, token-y: token-y, weight-x: weight-x, weight-y: weight-y } pool-updated) - (try! (contract-call? the-pool-token mint tx-sender new-supply)) + (try! (contract-call? the-pool-token mint new-supply tx-sender)) (print { object: "pool", action: "liquidity-added", data: pool-updated }) (ok {supply: new-supply, dx: dx, dy: new-dy}) @@ -374,7 +365,7 @@ ;; @param pool-token; pool token representing ownership of the pool ;; @param percent; percentage of pool token held to reduce ;; @returns (response (tuple uint uint) uint) -(define-public (reduce-position (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (percent uint)) +(define-public (reduce-position (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (the-pool-token ) (percent uint)) (begin (asserts! (<= percent ONE_8) ERR-PERCENT_GREATER_THAN_ONE) (let @@ -384,7 +375,7 @@ (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, weight-x: weight-x, weight-y: weight-y }) ERR-INVALID-POOL-ERR)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) - (total-shares (unwrap-panic (contract-call? the-pool-token get-balance tx-sender))) + (total-shares (unwrap-panic (contract-call? the-pool-token get-balance-fixed tx-sender))) (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent))) (total-supply (get total-supply pool)) (reduce-data (try! (get-position-given-burn token-x-trait token-y-trait weight-x weight-y shares))) @@ -405,7 +396,7 @@ (map-set pools-data-map { token-x: token-x, token-y: token-y, weight-x: weight-x, weight-y: weight-y } pool-updated) - (try! (contract-call? the-pool-token burn tx-sender shares)) + (try! (contract-call? the-pool-token burn shares tx-sender)) (print { object: "pool", action: "liquidity-removed", data: pool-updated }) (ok {dx: dx, dy: dy}) @@ -803,16 +794,6 @@ ;; Fixed Point Math ;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -821,18 +802,6 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - -(define-read-only (scale-up (a uint)) - (* a ONE_8) -) - -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -932,11 +901,11 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) +(define-constant ERR_OUT_OF_BOUNDS (err u5013)) ;; private functions ;; @@ -1001,14 +970,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -1069,10 +1038,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -1088,7 +1057,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -1099,22 +1068,10 @@ ) ) -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - ;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. (define-read-only (ln-fixed (a int)) (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) + (asserts! (> a 0) ERR_OUT_OF_BOUNDS) (if (< a iONE_8) ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). ;; If a is less than one, 1/a will be greater than one. diff --git a/clarity/contracts/pool/liquidity-bootstrapping-pool.clar b/clarity/contracts/pool/liquidity-bootstrapping-pool.clar index 66864335..43984beb 100644 --- a/clarity/contracts/pool/liquidity-bootstrapping-pool.clar +++ b/clarity/contracts/pool/liquidity-bootstrapping-pool.clar @@ -1,6 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait pool-token-trait .trait-pool-token.pool-token-trait) (use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) ;; liquidity-bootstrapping-pool @@ -18,7 +17,6 @@ (define-constant ERR-TOO-MANY-POOLS (err u2004)) (define-constant ERR-PERCENT_GREATER_THAN_ONE (err u5000)) (define-constant ERR-ALREADY-EXPIRED (err u2011)) -(define-constant ERR-MATH-CALL (err u2010)) (define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2020)) (define-constant ERR-PRICE-LOWER-THAN-MIN (err u2021)) (define-constant ERR-PRICE-GREATER-THAN-MAX (err u2022)) @@ -76,7 +74,7 @@ ;; ;; liquidity injection is allowed at the pool creation only -(define-private (add-to-position (token-x-trait ) (token-y-trait ) (expiry uint) (the-pool-token ) (dx uint) (dy uint)) +(define-private (add-to-position (token-x-trait ) (token-y-trait ) (expiry uint) (the-pool-token ) (dx uint) (dy uint)) (begin (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) (let @@ -105,7 +103,7 @@ ;; mint pool token-x and send to tx-sender (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) - (try! (contract-call? the-pool-token mint tx-sender new-supply)) + (try! (contract-call? the-pool-token mint new-supply tx-sender)) (print { object: "pool", action: "liquidity-added", data: pool-updated }) (ok true) ) @@ -211,12 +209,12 @@ ) ) -;; @desc get-balances ({balance-x, balance-y}) +;; @desc get-balance-fixeds ({balance-x, balance-y}) ;; @param token-x-trait; token-x ;; @param token-y-trait; token-y ;; @param expiry; expiry ;; @returns (response (tuple uint uint) uint) -(define-read-only (get-balances (token-x-trait ) (token-y-trait ) (expiry uint)) +(define-read-only (get-balance-fixeds (token-x-trait ) (token-y-trait ) (expiry uint)) (let ( (pool (unwrap! (map-get? pools-data-map { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), expiry: expiry }) ERR-INVALID-POOL-ERR)) @@ -237,7 +235,7 @@ ;; @param dx; amount of token-x added ;; @param dy; amount of token-y added ;; @returns (response bool uint) -(define-public (create-pool (token-x-trait ) (token-y-trait ) (weight-x-0 uint) (weight-x-1 uint) (expiry uint) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) +(define-public (create-pool (token-x-trait ) (token-y-trait ) (weight-x-0 uint) (weight-x-1 uint) (expiry uint) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) (let ( (pool-id (+ (var-get pool-count) u1)) @@ -280,7 +278,7 @@ ;; @param pool-token; pool token representing ownership of the pool ;; @param percent; percentage of pool token held to reduce ;; @returns (response (tuple uint uint) uint) -(define-public (reduce-position (token-x-trait ) (token-y-trait ) (expiry uint) (the-pool-token ) (percent uint)) +(define-public (reduce-position (token-x-trait ) (token-y-trait ) (expiry uint) (the-pool-token ) (percent uint)) (begin (asserts! (<= percent ONE_8) ERR-PERCENT_GREATER_THAN_ONE) (let @@ -290,7 +288,7 @@ (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) - (total-shares (unwrap-panic (contract-call? the-pool-token get-balance tx-sender))) + (total-shares (unwrap-panic (contract-call? the-pool-token get-balance-fixed tx-sender))) (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent))) (total-supply (get total-supply pool)) (reduce-data (try! (get-position-given-burn token-x-trait token-y-trait expiry shares))) @@ -309,7 +307,7 @@ (try! (contract-call? .alex-vault ft-transfer-multi token-x-trait dx token-y-trait dy tx-sender)) (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) - (try! (contract-call? the-pool-token burn tx-sender shares)) + (try! (contract-call? the-pool-token burn shares tx-sender)) (print { object: "pool", action: "liquidity-removed", data: pool-updated }) (ok {dx: dx, dy: dy}) ) @@ -564,16 +562,6 @@ ;; Fixed Point Math ;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -582,18 +570,6 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - -(define-read-only (scale-up (a uint)) - (* a ONE_8) -) - -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -693,11 +669,11 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) +(define-constant ERR_OUT_OF_BOUNDS (err u5013)) ;; private functions ;; @@ -762,14 +738,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -830,10 +806,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -849,7 +825,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -860,22 +836,10 @@ ) ) -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - ;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. (define-read-only (ln-fixed (a int)) (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) + (asserts! (> a 0) ERR_OUT_OF_BOUNDS) (if (< a iONE_8) ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). ;; If a is less than one, 1/a will be greater than one. diff --git a/clarity/contracts/pool/stacking-pool.clar b/clarity/contracts/pool/stacking-pool.clar new file mode 100644 index 00000000..9904870d --- /dev/null +++ b/clarity/contracts/pool/stacking-pool.clar @@ -0,0 +1,218 @@ +(impl-trait .trait-ownable.ownable-trait) +(use-trait ft-trait .trait-sip-010.sip-010-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) +(use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) + +;; stacked-poxl-pool +;; + +;; constants +;; +(define-constant ONE_8 u100000000) ;; 8 decimal places + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-INVALID-POOL (err u2001)) +(define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-STACKING-IN-PROGRESS (err u2018)) +(define-constant ERR-STACKING-NOT-AVAILABLE (err u2027)) + +(define-data-var CONTRACT-OWNER principal tx-sender) + +(define-read-only (get-owner) + (ok (var-get CONTRACT-OWNER)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + (ok (var-set CONTRACT-OWNER owner)) + ) +) + +;; data maps and vars +;; +(define-map pools-map + { pool-id: uint } + { + poxl-token: principal, ;; token to be stacked + reward-token: principal, ;; reward token + start-cycle: uint + } +) + +(define-map pools-data-map + { + poxl-token: principal, + reward-token: principal, + start-cycle: uint + } + { + total-supply: uint, + fee-to-address: principal, + pool-token: principal, + reward-cycles: (list 32 uint) + } +) + +(define-data-var pool-count uint u0) +(define-data-var pools-list (list 2000 uint) (list)) + +;; private functions +;; +(define-private (sum-stacking-reward (reward-cycle uint) (token-reward { token: principal, sum-so-far: uint })) + { + token: (get token token-reward), + sum-so-far: (+ (get sum-so-far token-reward) (get-stacking-reward (get token token-reward) reward-cycle)) + } +) +(define-private (get-stacking-reward (token principal) (reward-cycle uint)) + (contract-call? .alex-reserve-pool get-staking-reward token (get-user-id) reward-cycle) +) +(define-private (register-user (token principal)) + (as-contract (contract-call? .alex-reserve-pool register-user token none)) +) +(define-private (get-user-id (token principal)) + (default-to u0 (contract-call? .alex-reserve-pool get-user-id token (as-contract tx-sender))) +) +(define-private (get-reward-cycle (token principal) (stack-height uint)) + (contract-call? .alex-reserve-pool get-reward-cycle token stack-height) +) +(define-private (stack-tokens (token-trait ) (amount-tokens uint) (lock-period uint)) + (as-contract (contract-call? .alex-reserve-pool stake-tokens token-trait amount-tokens lock-period)) +) +(define-private (get-first-stacks-block-in-reward-cycle (token principal) (reward-cycle uint)) + (contract-call? .alex-reserve-pool get-first-stacks-block-in-reward-cycle token reward-cycle) +) +(define-private (claim-stacking-reward (reward-cycle uint) (token-trait )) + (as-contract (contract-call? .alex-reserve-pool claim-staking-reward token-trait reward-cycle)) +) + +;; public functions +;; +(define-read-only (get-pool-count) + (ok (var-get pool-count)) +) + +(define-read-only (get-pool-contracts (pool-id uint)) + (ok (unwrap! (map-get? pools-map {pool-id: pool-id}) ERR-INVALID-POOL)) +) + +(define-read-only (get-pools) + (ok (map get-pool-contracts (var-get pools-list))) +) + +(define-read-only (get-pool-details (poxl-token-trait ) (reward-token-trait ) (start-cycle uint)) + (ok (unwrap! (map-get? pools-data-map { poxl-token: (contract-of poxl-token-trait), reward-token: (contract-of reward-token-trait), start-cycle: start-cycle }) ERR-INVALID-POOL)) +) + +(define-read-only (get-balance (poxl-token-trait ) (reward-token-trait ) (start-cycle uint)) + (ok (get total-supply (unwrap! (map-get? pools-data-map { poxl-token: (contract-of poxl-token-trait), reward-token: (contract-of reward-token-trait), start-cycle: start-cycle }) ERR-INVALID-POOL))) +) + +(define-public (create-pool (poxl-token-trait ) (reward-token-trait ) (reward-cycles (list 32 uint)) (yield-token ) (multisig )) + (let + ( + (pool-id (+ (var-get pool-count) u1)) + (poxl-token (contract-of poxl-token-trait)) + (reward-token (contract-of reward-token-trait)) + (pool-data { + total-supply: u0, + fee-to-address: (contract-of multisig), + pool-token: (contract-of yield-token), + reward-cycles: reward-cycles + }) + (start-cycle (default-to u0 (element-at reward-cycles u0))) + ) + (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) + + ;; register if not registered + (try! (register-user)) + + (asserts! (is-none (map-get? pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle })) ERR-POOL-ALREADY-EXISTS) + + (map-set pools-map { pool-id: pool-id } { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle }) + (map-set pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle } pool-data) + + (var-set pools-list (unwrap! (as-max-len? (append (var-get pools-list) pool-id) u2000) ERR-TOO-MANY-POOLS)) + (var-set pool-count pool-id) + (print { object: "pool", action: "created", pool-data: pool-data }) + (ok true) + ) +) + +(define-public (add-to-position (poxl-token-trait ) (reward-token-trait ) (start-cycle uint) (yield-token ) (dx uint)) + (let + ( + (poxl-token (contract-of poxl-token-trait)) + (reward-token (contract-of reward-token-trait)) + (pool (unwrap! (map-get? pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle }) ERR-INVALID-POOL)) + (total-supply (get total-supply pool)) + (pool-updated (merge pool { + total-supply: (+ dx total-supply) + })) + (current-cycle (unwrap! (get-reward-cycle poxl-token block-height) ERR-STACKING-NOT-AVAILABLE)) + ) + ;; check if stacking already started + (asserts! (> start-cycle current-cycle) ERR-STACKING-IN-PROGRESS) + + ;; transfer dx to contract and send to stack + (try! (contract-call? poxl-token-trait transfer-fixed dx tx-sender (as-contract tx-sender) none)) + (try! (stack-tokens poxl-token-trait dx u32)) + + ;; mint pool token and send to tx-sender + (map-set pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle } pool-updated) + (try! (contract-call? yield-token mint-fixed start-cycle dx tx-sender)) + (print { object: "pool", action: "liquidity-added", data: pool-updated }) + (ok true) + ) +) + +(define-private (create-tuple (token principal) (reward-cycle uint)) + {token: token, reward-cycle: reward-cycle} +) + +(define-public (reduce-position (poxl-token-trait ) (reward-token-trait ) (start-cycle uint) (yield-token ) (percent uint)) + (let + ( + (poxl-token (contract-of poxl-token-trait)) + (reward-token (contract-of reward-token-trait)) + (pool (unwrap! (map-get? pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle }) ERR-INVALID-POOL)) + (shares (mul-down (unwrap-panic (contract-call? yield-token get-balance-fixed start-cycle tx-sender)) percent)) + (total-supply (get total-supply pool)) + (pool-updated (merge pool { + total-supply: (- total-supply shares) + }) + ) + (reward-cycles (get reward-cycles pool)) + (shares-to-supply (div-down shares total-supply)) + (total-rewards (get sum-so-far (fold sum-stacking-reward reward-cycles { token: poxl-token, sum-so-far: u0 }))) + (portioned-rewards (mul-down total-rewards shares-to-supply)) + ) + + (asserts! (> block-height (+ (get-first-stacks-block-in-reward-cycle poxl-token (+ start-cycle u32)) (contract-call? .alex-reserve-pool get-reward-cycle-length))) ERR-STACKING-IN-PROGRESS) + + ;; the first call claims rewards + ;; TODO: how can we pass trait to fold? + (map claim-stacking-reward reward-cycles poxl-token-trait) + + (try! (contract-call? poxl-token-trait transfer-fixed shares (as-contract tx-sender) tx-sender none)) + (try! (contract-call? reward-token-trait transfer-fixed portioned-rewards (as-contract tx-sender) tx-sender none)) + + (map-set pools-data-map { poxl-token: poxl-token, reward-token: reward-token, start-cycle: start-cycle } pool-updated) + (try! (contract-call? yield-token burn-fixed start-cycle tx-sender shares)) + (print { object: "pool", action: "liquidity-removed", data: pool-updated }) + (ok {poxl-token: shares, reward-token: portioned-rewards}) + ) +) + +(define-read-only (mul-down (a uint) (b uint)) + (/ (* a b) ONE_8) +) + +(define-read-only (div-down (a uint) (b uint)) + (if (is-eq a u0) + u0 + (/ (* a ONE_8) b) + ) +) \ No newline at end of file diff --git a/clarity/contracts/pool/yield-token-pool.clar b/clarity/contracts/pool/yield-token-pool.clar index 17d8577a..fbfe3fb1 100644 --- a/clarity/contracts/pool/yield-token-pool.clar +++ b/clarity/contracts/pool/yield-token-pool.clar @@ -1,32 +1,22 @@ (impl-trait .trait-ownable.ownable-trait) (use-trait ft-trait .trait-sip-010.sip-010-trait) -(use-trait pool-token-trait .trait-pool-token.pool-token-trait) -(use-trait yield-token-trait .trait-yield-token.yield-token-trait) -(use-trait multisig-trait .trait-multisig-vote.multisig-vote-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) +(use-trait multisig-trait .trait-multisig-vote.multisig-vote-sft-trait) ;; yield-token-pool (define-constant ONE_8 (pow u10 u8)) ;; 8 decimal places (define-constant MAX_T u85000000) (define-constant ERR-INVALID-POOL-ERR (err u2001)) -(define-constant ERR-NO-LIQUIDITY (err u2002)) (define-constant ERR-INVALID-LIQUIDITY (err u2003)) (define-constant ERR-TRANSFER-X-FAILED (err u3001)) (define-constant ERR-TRANSFER-Y-FAILED (err u3002)) (define-constant ERR-POOL-ALREADY-EXISTS (err u2000)) (define-constant ERR-TOO-MANY-POOLS (err u2004)) (define-constant ERR-PERCENT_GREATER_THAN_ONE (err u5000)) -(define-constant invalid-token-err (err u2007)) -(define-constant ERR-NO-FEE (err u2005)) -(define-constant ERR-NO-FEE-Y (err u2006)) -(define-constant invalid-ERR-EXPIRY (err u2009)) -(define-constant fixed-point-err (err 5014)) -(define-constant ERR-MATH-CALL (err u4003)) -(define-constant ERR-GET-EXPIRY-FAIL-ERR (err u2013)) -(define-constant dy-bigger-than-available-err (err u2016)) +(define-constant ERR-INVALID-EXPIRY (err u2009)) +(define-constant ERR-DY-BIGGER-THAN-AVAILABLE (err u2016)) (define-constant ERR-NOT-AUTHORIZED (err u1000)) -(define-constant ERR-GET-ORACLE-PRICE-FAIL (err u7000)) -(define-constant ERR-GET-SYMBOL-FAIL (err u6000)) (define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2020)) (define-constant ERR-INVALID-POOL-TOKEN (err u2023)) (define-constant ERR-ORACLE-NOT-ENABLED (err u7002)) @@ -51,12 +41,14 @@ { pool-id: uint } { yield-token: principal, ;; yield-token, dy + expiry: uint } ) (define-map pools-data-map { - yield-token: principal + yield-token: principal, + expiry: uint } { total-supply: uint, @@ -68,7 +60,6 @@ fee-rate-token: uint, fee-rate-yield-token: uint, fee-rebate: uint, - expiry: uint, listed: uint, oracle-enabled: bool, oracle-average: uint, @@ -106,8 +97,8 @@ ;; @returns (response uint uint) (define-read-only (get-t (expiry uint) (listed uint)) (begin - (asserts! (> (var-get max-expiry) expiry) invalid-ERR-EXPIRY) - (asserts! (> (var-get max-expiry) (* block-height ONE_8)) invalid-ERR-EXPIRY) + (asserts! (> (var-get max-expiry) expiry) ERR-INVALID-EXPIRY) + (asserts! (> (var-get max-expiry) (* block-height ONE_8)) ERR-INVALID-EXPIRY) (let ( (t (div-down @@ -141,20 +132,19 @@ ;; @desc get-pool-details ;; @param the-yield-token; yield-token ;; @returns (response (tuple) uint) -(define-read-only (get-pool-details (the-yield-token )) - (ok (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) +(define-read-only (get-pool-details (expiry uint) (the-yield-token )) + (ok (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) ) ;; @desc get-yield ;; @desc note yield is not annualised ;; @param the-yield-token; yield-token ;; @returns (response uint uint) -(define-read-only (get-yield (the-yield-token )) +(define-read-only (get-yield (expiry uint) (the-yield-token )) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry}) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (balance-token (get balance-token pool)) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -167,12 +157,11 @@ ;; @desc get-price ;; @param the-yield-token; yield-token ;; @returns (response uint uint) -(define-read-only (get-price (the-yield-token )) +(define-read-only (get-price (expiry uint) (the-yield-token )) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (balance-token (get balance-token pool)) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -185,8 +174,8 @@ ;; @desc get-oracle-enabled ;; @param the-yield-token; yield-token ;; @returns (response bool uint) -(define-read-only (get-oracle-enabled (the-yield-token )) - (ok (get oracle-enabled (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR))) +(define-read-only (get-oracle-enabled (expiry uint) (the-yield-token )) + (ok (get oracle-enabled (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR))) ) ;; @desc set-oracle-enabled @@ -194,15 +183,15 @@ ;; @restricted CONTRACT-OWNER ;; @param the-yield-token; yield-token ;; @returns (response bool uint) -(define-public (set-oracle-enabled (the-yield-token )) +(define-public (set-oracle-enabled (expiry uint) (the-yield-token )) (let ( - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) (pool-updated (merge pool {oracle-enabled: true})) ) (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) (asserts! (not (get oracle-enabled pool)) ERR-ORACLE-ALREADY-ENABLED) - (map-set pools-data-map { yield-token: (contract-of the-yield-token) } pool-updated) + (map-set pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry } pool-updated) (ok true) ) ) @@ -211,27 +200,27 @@ ;; @desc returns the moving average used to determine oracle price ;; @param the-yield-token; yield-token ;; @returns (response uint uint) -(define-read-only (get-oracle-average (the-yield-token )) - (ok (get oracle-average (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR))) +(define-read-only (get-oracle-average (expiry uint) (the-yield-token )) + (ok (get oracle-average (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR))) ) ;; @desc set-oracle-average ;; @restricted CONTRACT-OWNER ;; @param the-yield-token; yield-token ;; @returns (response bool uint) -(define-public (set-oracle-average (the-yield-token ) (new-oracle-average uint)) +(define-public (set-oracle-average (expiry uint) (the-yield-token ) (new-oracle-average uint)) (let ( - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) (pool-updated (merge pool { oracle-average: new-oracle-average, - oracle-resilient: (try! (get-oracle-instant the-yield-token)) + oracle-resilient: (try! (get-oracle-instant expiry the-yield-token)) })) ) (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED) (asserts! (< new-oracle-average ONE_8) ERR-ORACLE-AVERAGE-BIGGER-THAN-ONE) - (map-set pools-data-map { yield-token: (contract-of the-yield-token) } pool-updated) + (map-set pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry } pool-updated) (ok true) ) ) @@ -240,13 +229,13 @@ ;; @desc price-oracle that is less up to date but more resilient to manipulation ;; @param the-yield-token; yield-token ;; @returns (response uint uint) -(define-read-only (get-oracle-resilient (the-yield-token )) +(define-read-only (get-oracle-resilient (expiry uint) (the-yield-token )) (let ( - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED) - (ok (+ (mul-down (- ONE_8 (get oracle-average pool)) (try! (get-oracle-instant the-yield-token))) + (ok (+ (mul-down (- ONE_8 (get oracle-average pool)) (try! (get-oracle-instant expiry the-yield-token))) (mul-down (get oracle-average pool) (get oracle-resilient pool)))) ) ) @@ -255,8 +244,8 @@ ;; @desc price-oracle that is more up to date but less resilient to manipulation ;; @param the-yield-token; yield-token ;; @returns (response uint uint) -(define-read-only (get-oracle-instant (the-yield-token )) - (ok (div-down ONE_8 (try! (get-price the-yield-token)))) +(define-read-only (get-oracle-instant (expiry uint) (the-yield-token )) + (ok (div-down ONE_8 (try! (get-price expiry the-yield-token)))) ) ;; @desc create-pool @@ -268,17 +257,16 @@ ;; @param dx; amount of token added ;; @param dy; amount of yield-token added ;; @returns (response bool uint) -(define-public (create-pool (the-yield-token ) (the-token ) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) +(define-public (create-pool (expiry uint) (the-yield-token ) (the-token ) (the-pool-token ) (multisig-vote ) (dx uint) (dy uint)) (begin (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) - ;; create pool only if the correct pair - (asserts! (is-eq (try! (contract-call? the-yield-token get-token)) (contract-of the-token)) ERR-INVALID-POOL-ERR) - (asserts! (is-none (map-get? pools-data-map { yield-token: (contract-of the-yield-token) })) ERR-POOL-ALREADY-EXISTS) + ;; ;; create pool only if the correct pair + ;; (asserts! (is-eq (try! (contract-call? the-yield-token get-token)) (contract-of the-token)) ERR-INVALID-POOL-ERR) + (asserts! (is-none (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry })) ERR-POOL-ALREADY-EXISTS) (let ( (yield-token (contract-of the-yield-token)) (pool-id (+ (var-get pool-count) u1)) - (expiry (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) (pool-data { total-supply: u0, balance-token: u0, @@ -289,7 +277,6 @@ fee-rate-yield-token: u0, fee-rate-token: u0, fee-rebate: u0, - expiry: (unwrap! (contract-call? the-yield-token get-expiry) ERR-GET-EXPIRY-FAIL-ERR), listed: (* block-height ONE_8), oracle-enabled: false, oracle-average: u0, @@ -297,15 +284,15 @@ }) ) - (map-set pools-map { pool-id: pool-id } { yield-token: yield-token }) - (map-set pools-data-map { yield-token: yield-token } pool-data) + (map-set pools-map { pool-id: pool-id } { yield-token: yield-token, expiry: expiry }) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } pool-data) (var-set pools-list (unwrap! (as-max-len? (append (var-get pools-list) pool-id) u2000) ERR-TOO-MANY-POOLS)) (var-set pool-count pool-id) ;; ;; if yield-token added has a longer expiry than current max-expiry, update max-expiry (to expiry + one block). ;; (var-set max-expiry (if (< (var-get max-expiry) expiry) (+ expiry ONE_8) (var-get max-expiry))) - (try! (add-to-position the-yield-token the-token the-pool-token dx)) + (try! (add-to-position expiry the-yield-token the-token the-pool-token dx)) (print { object: "pool", action: "created", data: pool-data }) (ok true) @@ -321,15 +308,15 @@ ;; @param pool-token; pool token representing ownership of the pool ;; @param dx; amount of token added (part of which will be used to buy yield-token) ;; @returns (response (tuple uint uint uint uint) uint) -(define-public (buy-and-add-to-position (the-yield-token ) (the-token ) (the-pool-token ) (dx uint)) +(define-public (buy-and-add-to-position (expiry uint) (the-yield-token ) (the-token ) (the-pool-token ) (dx uint)) (let ( - (dy-act (get dy-act (try! (get-token-given-position the-yield-token dx)))) - (dx-adjusted (- dx (div-down dx (+ dx (try! (get-x-given-y the-yield-token dy-act)))))) + (dy-act (get dy-act (try! (get-token-given-position expiry the-yield-token dx)))) + (dx-adjusted (- dx (div-down dx (+ dx (try! (get-x-given-y expiry the-yield-token dy-act)))))) (dx-to-buy-dy-adjusted (- dx dx-adjusted)) ) - (and (> dy-act u0) (is-ok (swap-x-for-y the-yield-token the-token dx-to-buy-dy-adjusted none))) - (add-to-position the-yield-token the-token the-pool-token dx-adjusted) + (and (> dy-act u0) (is-ok (swap-x-for-y expiry the-yield-token the-token dx-to-buy-dy-adjusted none))) + (add-to-position expiry the-yield-token the-token the-pool-token dx-adjusted) ) ) @@ -340,19 +327,19 @@ ;; @param pool-token; pool token representing ownership of the pool ;; @param dx; amount of token added ;; @returns (response (tuple uint uint uint uint) uint) -(define-public (add-to-position (the-yield-token ) (the-token ) (the-pool-token ) (dx uint)) +(define-public (add-to-position (expiry uint) (the-yield-token ) (the-token ) (the-pool-token ) (dx uint)) (begin ;; dx must be greater than zero (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-token (get balance-token pool)) (balance-yield-token (get balance-yield-token pool)) (balance-virtual (get balance-virtual pool)) (total-supply (get total-supply pool)) - (add-data (try! (get-token-given-position the-yield-token dx))) + (add-data (try! (get-token-given-position expiry the-yield-token dx))) (new-supply (get token add-data)) (new-dy-act (get dy-act add-data)) (new-dy-vir (get dy-vir add-data)) @@ -369,13 +356,13 @@ ;; at least one of dy must be greater than zero (asserts! (or (> new-dy-act u0) (> new-dy-vir u0)) ERR-INVALID-LIQUIDITY) ;; send x to vault - (unwrap! (contract-call? the-token transfer dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED) + (unwrap! (contract-call? the-token transfer-fixed dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED) ;; send y to vault - (and (> new-dy-act u0) (unwrap! (contract-call? the-yield-token transfer new-dy-act tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED)) + (and (> new-dy-act u0) (unwrap! (contract-call? the-yield-token transfer-fixed expiry new-dy-act tx-sender .alex-vault) ERR-TRANSFER-Y-FAILED)) ;; mint pool token and send to tx-sender - (map-set pools-data-map { yield-token: yield-token } pool-updated) - (try! (contract-call? the-pool-token mint tx-sender new-supply)) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } pool-updated) + (try! (contract-call? the-pool-token mint-fixed expiry new-supply tx-sender)) (print { object: "pool", action: "liquidity-added", data: pool-updated }) (ok {supply: new-supply, balance-token: dx, balance-yield-token: new-dy-act, balance-virtual: new-dy-vir}) ) @@ -389,20 +376,20 @@ ;; @param pool-token; pool token representing ownership of the pool ;; @param percent; percentage of pool token held to reduce ;; @returns (response (tuple uint uint) uint) -(define-public (reduce-position (the-yield-token ) (the-token ) (the-pool-token ) (percent uint)) +(define-public (reduce-position (expiry uint) (the-yield-token ) (the-token ) (the-pool-token ) (percent uint)) (begin (asserts! (<= percent ONE_8) ERR-PERCENT_GREATER_THAN_ONE) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-token (get balance-token pool)) (balance-yield-token (get balance-yield-token pool)) (balance-virtual (get balance-virtual pool)) (total-supply (get total-supply pool)) - (total-shares (unwrap-panic (contract-call? the-pool-token get-balance tx-sender))) + (total-shares (unwrap-panic (contract-call? the-pool-token get-balance-fixed expiry tx-sender))) (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent))) - (reduce-data (try! (get-position-given-burn the-yield-token shares))) + (reduce-data (try! (get-position-given-burn expiry the-yield-token shares))) (dx (get dx reduce-data)) (dy-act (get dy-act reduce-data)) (dy-vir (get dy-vir reduce-data)) @@ -418,10 +405,10 @@ (asserts! (is-eq (get pool-token pool) (contract-of the-pool-token)) ERR-INVALID-POOL-TOKEN) (and (> dx u0) (try! (contract-call? .alex-vault transfer-ft the-token dx tx-sender))) - (and (> dy-act u0) (try! (contract-call? .alex-vault transfer-yield the-yield-token dy-act tx-sender))) + (and (> dy-act u0) (try! (contract-call? .alex-vault transfer-sft the-yield-token expiry dy-act tx-sender))) - (map-set pools-data-map { yield-token: yield-token } pool-updated) - (try! (contract-call? the-pool-token burn tx-sender shares)) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } pool-updated) + (try! (contract-call? the-pool-token burn-fixed expiry shares tx-sender)) (print { object: "pool", action: "liquidity-removed", data: pool-updated }) (ok {dx: dx, dy: dy-act}) ) @@ -438,14 +425,14 @@ ;; @param the-pool-token-to-roll; pool token representing ownership of the pool to roll to ;; @returns (response (tuple uint uint) uint) (define-public (roll-position - (the-yield-token ) (the-token ) (the-pool-token ) (percent uint) - (the-yield-token-to-roll ) (the-pool-token-to-roll )) + (expiry uint) (the-yield-token ) (the-token ) (the-pool-token ) (percent uint) + (expiry-to-roll uint)) (let ( - (reduce-data (unwrap! (reduce-position the-yield-token the-token the-pool-token percent) (err u11111))) - (dy-to-dx (get dx (unwrap! (swap-y-for-x the-yield-token the-token (get dy reduce-data) none) (err u22222)))) + (reduce-data (unwrap! (reduce-position expiry the-yield-token the-token the-pool-token percent) (err u11111))) + (dy-to-dx (get dx (unwrap! (swap-y-for-x expiry the-yield-token the-token (get dy reduce-data) none) (err u22222)))) ) - (buy-and-add-to-position the-yield-token-to-roll the-token the-pool-token-to-roll (+ (get dx reduce-data) dy-to-dx)) + (buy-and-add-to-position expiry-to-roll the-yield-token the-token the-pool-token (+ (get dx reduce-data) dy-to-dx)) ) ) @@ -455,32 +442,32 @@ ;; @param dx; amount of token to swap ;; @param min-dy; optional, min amount of yield-token to receive ;; @returns (response (tuple uint uint) uint) -(define-public (swap-x-for-y (the-yield-token ) (the-token ) (dx uint) (min-dy (optional uint))) +(define-public (swap-x-for-y (expiry uint) (the-yield-token ) (the-token ) (dx uint) (min-dy (optional uint))) (begin (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-token (get balance-token pool)) (balance-yield-token (get balance-yield-token pool)) ;; lambda ~= 1 - fee-rate-yield-token * yield - (yield (try! (get-yield the-yield-token))) + (yield (try! (get-yield expiry the-yield-token))) (fee-yield (mul-down yield (get fee-rate-yield-token pool))) (lambda (if (<= ONE_8 fee-yield) u0 (- ONE_8 fee-yield))) (dx-net-fees (mul-down dx lambda)) (fee (if (<= dx dx-net-fees) u0 (- dx dx-net-fees))) (fee-rebate (mul-down fee (get fee-rebate pool))) - (dy (try! (get-y-given-x the-yield-token dx-net-fees))) + (dy (try! (get-y-given-x expiry the-yield-token dx-net-fees))) (pool-updated (merge pool { balance-token: (+ balance-token dx-net-fees fee-rebate), balance-yield-token: (if (<= balance-yield-token dy) u0 (- balance-yield-token dy)), - oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient the-yield-token)) u0) + oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient expiry the-yield-token)) u0) } ) ) @@ -488,12 +475,12 @@ (asserts! (< (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE) - (and (> dx u0) (unwrap! (contract-call? the-token transfer dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED)) - (and (> dy u0) (try! (contract-call? .alex-vault transfer-yield the-yield-token dy tx-sender))) + (and (> dx u0) (unwrap! (contract-call? the-token transfer-fixed dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED)) + (and (> dy u0) (try! (contract-call? .alex-vault transfer-sft the-yield-token expiry dy tx-sender))) (try! (contract-call? .alex-reserve-pool add-to-balance (contract-of the-token) (- fee fee-rebate))) ;; post setting - (map-set pools-data-map { yield-token: yield-token } pool-updated) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } pool-updated) (print { object: "pool", action: "swap-x-for-y", data: pool-updated }) (ok {dx: dx-net-fees, dy: dy}) ) @@ -506,32 +493,32 @@ ;; @param dy; amount of yield token to swap ;; @param min-dx; optional, min amount of token to receive ;; @returns (response (tuple uint uint) uint) -(define-public (swap-y-for-x (the-yield-token ) (the-token ) (dy uint) (min-dx (optional uint))) +(define-public (swap-y-for-x (expiry uint) (the-yield-token ) (the-token ) (dy uint) (min-dx (optional uint))) (begin (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (balance-token (get balance-token pool)) (balance-yield-token (get balance-yield-token pool)) ;; lambda ~= 1 - fee-rate-token * yield - (yield (try! (get-yield the-yield-token))) + (yield (try! (get-yield expiry the-yield-token))) (fee-yield (mul-down yield (get fee-rate-token pool))) (lambda (if (<= ONE_8 fee-yield) u0 (- ONE_8 fee-yield))) (dy-net-fees (mul-down dy lambda)) (fee (if (<= dy dy-net-fees) u0 (- dy dy-net-fees))) (fee-rebate (mul-down fee (get fee-rebate pool))) - (dx (try! (get-x-given-y the-yield-token dy-net-fees))) + (dx (try! (get-x-given-y expiry the-yield-token dy-net-fees))) (pool-updated (merge pool { balance-token: (if (<= balance-token dx) u0 (- balance-token dx)), balance-yield-token: (+ balance-yield-token dy-net-fees fee-rebate), - oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient the-yield-token)) u0) + oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient expiry the-yield-token)) u0) } ) ) @@ -539,11 +526,11 @@ (asserts! (< (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) (and (> dx u0) (try! (contract-call? .alex-vault transfer-ft the-token dx tx-sender))) - (and (> dy u0) (unwrap! (contract-call? the-yield-token transfer dy tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED)) + (and (> dy u0) (unwrap! (contract-call? the-yield-token transfer-fixed expiry dy tx-sender .alex-vault) ERR-TRANSFER-Y-FAILED)) (try! (contract-call? .alex-reserve-pool add-to-balance yield-token (- fee fee-rebate))) ;; post setting - (map-set pools-data-map { yield-token: yield-token } pool-updated) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } pool-updated) (print { object: "pool", action: "swap-y-for-x", data: pool-updated }) (ok {dx: dx, dy: dy-net-fees}) ) @@ -553,8 +540,8 @@ ;; @desc get-fee-rebate ;; @param the-yield-token; yield token ;; @returns (response uint uint) -(define-read-only (get-fee-rebate (the-yield-token )) - (ok (get fee-rebate (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR))) +(define-read-only (get-fee-rebate (expiry uint) (the-yield-token )) + (ok (get fee-rebate (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR))) ) ;; @desc set-fee-rebate @@ -562,15 +549,15 @@ ;; @param the-yield-token; yield token ;; @param fee-rebate; new fee-rebate ;; @returns (response bool uint) -(define-public (set-fee-rebate (the-yield-token ) (fee-rebate uint)) +(define-public (set-fee-rebate (expiry uint) (the-yield-token ) (fee-rebate uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (asserts! (is-eq contract-caller (var-get CONTRACT-OWNER)) ERR-NOT-AUTHORIZED) - (map-set pools-data-map { yield-token: yield-token } (merge pool { fee-rebate: fee-rebate })) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } (merge pool { fee-rebate: fee-rebate })) (ok true) ) ) @@ -578,11 +565,11 @@ ;; @desc get-fee-rate-yield-token ;; @param the-yield-token; yield token ;; @returns (response uint uint) -(define-read-only (get-fee-rate-yield-token (the-yield-token )) +(define-read-only (get-fee-rate-yield-token (expiry uint) (the-yield-token )) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (ok (get fee-rate-yield-token pool)) ) @@ -591,11 +578,11 @@ ;; @desc get-fee-rate-token ;; @param the-yield-token; yield token ;; @returns (response uint uint) -(define-read-only (get-fee-rate-token (the-yield-token )) +(define-read-only (get-fee-rate-token (expiry uint) (the-yield-token )) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (ok (get fee-rate-token pool)) ) @@ -606,15 +593,15 @@ ;; @param the-yield-token; yield token ;; @param fee-rate-yield-token; new fee-rate-yield-token ;; @returns (response bool uint) -(define-public (set-fee-rate-yield-token (the-yield-token ) (fee-rate-yield-token uint)) +(define-public (set-fee-rate-yield-token (expiry uint) (the-yield-token ) (fee-rate-yield-token uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) - (map-set pools-data-map { yield-token: yield-token } (merge pool { fee-rate-yield-token: fee-rate-yield-token })) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } (merge pool { fee-rate-yield-token: fee-rate-yield-token })) (ok true) ) @@ -625,15 +612,15 @@ ;; @param the-yield-token; yield token ;; @param fee-rate-token; new fee-rate-token ;; @returns (response bool uint) -(define-public (set-fee-rate-token (the-yield-token ) (fee-rate-token uint)) +(define-public (set-fee-rate-token (expiry uint) (the-yield-token ) (fee-rate-token uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) - (map-set pools-data-map { yield-token: yield-token } (merge pool { fee-rate-token: fee-rate-token })) + (map-set pools-data-map { yield-token: yield-token, expiry: expiry } (merge pool { fee-rate-token: fee-rate-token })) (ok true) ) ) @@ -641,11 +628,11 @@ ;; @desc get-fee-to-address ;; @param the-yield-token; yield token ;; @returns (response principal uint) -(define-read-only (get-fee-to-address (the-yield-token )) +(define-read-only (get-fee-to-address (expiry uint) (the-yield-token )) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) ) (ok (get fee-to-address pool)) ) @@ -655,14 +642,14 @@ ;; @param the-yield-token; yield token ;; @param dx; amount of token being added ;; @returns (response uint uint) -(define-read-only (get-y-given-x (the-yield-token ) (dx uint)) +(define-read-only (get-y-given-x (expiry uint) (the-yield-token ) (dx uint)) (let ( - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) - (normalized-expiry (try! (get-t (get expiry pool) (get listed pool)))) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) + (normalized-expiry (try! (get-t expiry (get listed pool)))) (dy (try! (contract-call? .yield-token-equation get-y-given-x (get balance-token pool) (+ (get balance-yield-token pool) (get balance-virtual pool)) normalized-expiry dx))) ) - (asserts! (> (get balance-yield-token pool) dy) dy-bigger-than-available-err) + (asserts! (> (get balance-yield-token pool) dy) ERR-DY-BIGGER-THAN-AVAILABLE) (ok dy) ) ) @@ -671,12 +658,12 @@ ;; @param the-yield-token; yield token ;; @param dy; amount of yield token being added ;; @returns (response uint uint) -(define-read-only (get-x-given-y (the-yield-token ) (dy uint)) +(define-read-only (get-x-given-y (expiry uint) (the-yield-token ) (dy uint)) (let ( - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) - (normalized-expiry (try! (get-t (get expiry pool) (get listed pool)))) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) + (normalized-expiry (try! (get-t expiry (get listed pool)))) ) (contract-call? .yield-token-equation get-x-given-y (get balance-token pool) (+ (get balance-yield-token pool) (get balance-virtual pool)) normalized-expiry dy) ) @@ -686,13 +673,12 @@ ;; @param the-yield-token; yield token ;; @param price; target price ;; @returns (response uint uint) -(define-read-only (get-x-given-price (the-yield-token ) (price uint)) +(define-read-only (get-x-given-price (expiry uint) (the-yield-token ) (price uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token) }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: (contract-of the-yield-token), expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -706,13 +692,12 @@ ;; @param the-yield-token; yield token ;; @param price; target price ;; @returns (response uint uint) -(define-read-only (get-y-given-price (the-yield-token ) (price uint)) +(define-read-only (get-y-given-price (expiry uint) (the-yield-token ) (price uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -726,13 +711,12 @@ ;; @param the-yield-token; yield token ;; @param yield; target yield ;; @returns (response uint uint) -(define-read-only (get-x-given-yield (the-yield-token ) (yield uint)) +(define-read-only (get-x-given-yield (expiry uint) (the-yield-token ) (yield uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -746,13 +730,12 @@ ;; @param the-yield-token; yield token ;; @param yield; target yield ;; @returns (response uint uint) -(define-read-only (get-y-given-yield (the-yield-token ) (yield uint)) +(define-read-only (get-y-given-yield (expiry uint) (the-yield-token ) (yield uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-yield-token (+ (get balance-yield-token pool) (get balance-virtual pool))) @@ -766,13 +749,12 @@ ;; @param the-yield-token; yield token ;; @param dx; amount of token added ;; @returns (response (tuple uint uint uint) uint) -(define-read-only (get-token-given-position (the-yield-token ) (dx uint)) +(define-read-only (get-token-given-position (expiry uint) (the-yield-token ) (dx uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-actual (get balance-yield-token pool)) @@ -796,13 +778,12 @@ ;; @param the-yield-token; yield token ;; @param token; units of pool token to be minted ;; @returns (response (tuple uint uint uint) uint) -(define-read-only (get-position-given-mint (the-yield-token ) (token uint)) +(define-read-only (get-position-given-mint (expiry uint) (the-yield-token ) (token uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-actual (get balance-yield-token pool)) @@ -825,13 +806,12 @@ ;; @param the-yield-token; yield token ;; @param token; units of pool token to be burnt ;; @returns (response (tuple uint uint uint) uint) -(define-read-only (get-position-given-burn (the-yield-token ) (token uint)) +(define-read-only (get-position-given-burn (expiry uint) (the-yield-token ) (token uint)) (let ( (yield-token (contract-of the-yield-token)) - (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token }) ERR-INVALID-POOL-ERR)) - (expiry (get expiry pool)) + (pool (unwrap! (map-get? pools-data-map { yield-token: yield-token, expiry: expiry }) ERR-INVALID-POOL-ERR)) (listed (get listed pool)) (normalized-expiry (try! (get-t expiry listed))) (balance-actual (get balance-yield-token pool)) @@ -855,16 +835,6 @@ ;; Fixed Point Math ;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol -;; constants -;; -(define-constant SCALE_UP_OVERFLOW (err u5001)) -(define-constant SCALE_DOWN_OVERFLOW (err u5002)) -(define-constant ADD_OVERFLOW (err u5003)) -(define-constant SUB_OVERFLOW (err u5004)) -(define-constant MUL_OVERFLOW (err u5005)) -(define-constant DIV_OVERFLOW (err u5006)) -(define-constant POW_OVERFLOW (err u5007)) - ;; With 8 fixed digits you would have a maximum error of 0.5 * 10^-8 in each entry, ;; which could aggregate to about 8 x 0.5 * 10^-8 = 4 * 10^-8 relative error ;; (i.e. the last digit of the result may be completely lost to this error). @@ -873,18 +843,10 @@ ;; public functions ;; -(define-read-only (get_one) - (ok ONE_8) -) - (define-read-only (scale-up (a uint)) (* a ONE_8) ) -(define-read-only (scale-down (a uint)) - (/ a ONE_8) -) - (define-read-only (mul-down (a uint) (b uint)) (/ (* a b) ONE_8) ) @@ -984,11 +946,11 @@ {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11) )) -(define-constant X_OUT_OF_BOUNDS (err u5009)) -(define-constant Y_OUT_OF_BOUNDS (err u5010)) -(define-constant PRODUCT_OUT_OF_BOUNDS (err u5011)) -(define-constant INVALID_EXPONENT (err u5012)) -(define-constant OUT_OF_BOUNDS (err u5013)) +(define-constant ERR_X_OUT_OF_BOUNDS (err u5009)) +(define-constant ERR_Y_OUT_OF_BOUNDS (err u5010)) +(define-constant ERR_PRODUCT_OUT_OF_BOUNDS (err u5011)) +(define-constant ERR_INVALID_EXPONENT (err u5012)) +(define-constant ERR_OUT_OF_BOUNDS (err u5013)) ;; private functions ;; @@ -1053,14 +1015,14 @@ (lnx (unwrap-panic (ln-priv x-int))) (logx-times-y (/ (* lnx y-int) iONE_8)) ) - (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) PRODUCT_OUT_OF_BOUNDS) + (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR_PRODUCT_OUT_OF_BOUNDS) (ok (to-uint (unwrap-panic (exp-fixed logx-times-y)))) ) ) (define-private (exp-pos (x int)) (begin - (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (let ( ;; For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct @@ -1121,10 +1083,10 @@ (define-read-only (pow-fixed (x uint) (y uint)) (begin ;; The ln function takes a signed value, so we need to make sure x fits in the signed 128 bit range. - (asserts! (< x (pow u2 u127)) X_OUT_OF_BOUNDS) + (asserts! (< x (pow u2 u127)) ERR_X_OUT_OF_BOUNDS) ;; This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 128 bit range. - (asserts! (< y MILD_EXPONENT_BOUND) Y_OUT_OF_BOUNDS) + (asserts! (< y MILD_EXPONENT_BOUND) ERR_Y_OUT_OF_BOUNDS) (if (is-eq y u0) (ok (to-uint iONE_8)) @@ -1140,7 +1102,7 @@ ;; Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. (define-read-only (exp-fixed (x int)) (begin - (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) (err INVALID_EXPONENT)) + (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR_INVALID_EXPONENT) (if (< x 0) ;; We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it ;; fits in the signed 128 bit range (as it is larger than MIN_NATURAL_EXPONENT). @@ -1151,22 +1113,10 @@ ) ) -;; Logarithm (log(arg, base), with signed 8 decimal fixed point base and argument. -(define-read-only (log-fixed (arg int) (base int)) - ;; This performs a simple base change: log(arg, base) = ln(arg) / ln(base). - (let - ( - (logBase (* (unwrap-panic (ln-priv base)) iONE_8)) - (logArg (* (unwrap-panic (ln-priv arg)) iONE_8)) - ) - (ok (/ (* logArg iONE_8) logBase)) - ) -) - ;; Natural logarithm (ln(a)) with signed 8 decimal fixed point argument. (define-read-only (ln-fixed (a int)) (begin - (asserts! (> a 0) (err OUT_OF_BOUNDS)) + (asserts! (> a 0) ERR_OUT_OF_BOUNDS) (if (< a iONE_8) ;; Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). ;; If a is less than one, 1/a will be greater than one. diff --git a/clarity/contracts/token/token-alex.clar b/clarity/contracts/token/token-alex.clar index 2e2322aa..09ab397e 100644 --- a/clarity/contracts/token/token-alex.clar +++ b/clarity/contracts/token/token-alex.clar @@ -1,5 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token alex) @@ -30,7 +30,7 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply alex))) + (ok (ft-get-supply alex)) ) (define-read-only (get-name) @@ -42,11 +42,11 @@ ) (define-read-only (get-decimals) - (ok u0) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance alex account))) + (ok (ft-get-balance alex account)) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -60,24 +60,10 @@ (ok (some (var-get token-uri))) ) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? alex (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? alex amount sender recipient) response (begin (print memo) (ok response) @@ -87,28 +73,57 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (ft-mint? alex (fixed-to-decimals amount) recipient) + (ft-mint? alex amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin (try! (check-is-approved contract-caller)) - (ft-burn? alex (fixed-to-decimals amount) sender) + (ft-burn? alex amount sender) ) ) -(begin - (map-set approved-contracts .alex-reserve-pool true) - (map-set approved-contracts .faucet true) +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply alex))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance alex account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) ) -;; Initialize the contract for Testing. (begin - (try! (ft-mint? alex u1000000000 tx-sender)) + (map-set approved-contracts .alex-reserve-pool true) + (map-set approved-contracts .faucet true) ) diff --git a/clarity/contracts/token/token-t-alex.clar b/clarity/contracts/token/token-t-alex.clar index 3d789cc5..bceda2ab 100644 --- a/clarity/contracts/token/token-t-alex.clar +++ b/clarity/contracts/token/token-t-alex.clar @@ -1,5 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token t-alex) @@ -30,7 +30,7 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply t-alex))) + (ok (ft-get-supply t-alex)) ) (define-read-only (get-name) @@ -42,11 +42,11 @@ ) (define-read-only (get-decimals) - (ok u0) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance t-alex account))) + (ok (ft-get-balance t-alex account)) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -60,24 +60,10 @@ (ok (some (var-get token-uri))) ) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? t-alex (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? t-alex amount sender recipient) response (begin (print memo) (ok response) @@ -87,20 +73,54 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (ft-mint? t-alex (fixed-to-decimals amount) recipient) + (ft-mint? t-alex amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin (try! (check-is-approved contract-caller)) - (ft-burn? t-alex (fixed-to-decimals amount) sender) + (ft-burn? t-alex amount sender) ) ) +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply t-alex))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance t-alex account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) +) + (begin (map-set approved-contracts .alex-reserve-pool true) (map-set approved-contracts .faucet true) diff --git a/clarity/contracts/token/token-usda.clar b/clarity/contracts/token/token-usda.clar index 1945957f..ae6eafcf 100644 --- a/clarity/contracts/token/token-usda.clar +++ b/clarity/contracts/token/token-usda.clar @@ -1,5 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token usda) @@ -30,23 +30,23 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply usda))) + (ok (ft-get-supply usda)) ) (define-read-only (get-name) - (ok "USDA") + (ok "usda") ) (define-read-only (get-symbol) - (ok "USDA") + (ok "usda") ) (define-read-only (get-decimals) - (ok u2) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance usda account))) + (ok (ft-get-balance usda account)) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -60,24 +60,10 @@ (ok (some (var-get token-uri))) ) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? usda amount sender recipient) response (begin (print memo) (ok response) @@ -87,27 +73,54 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (ft-mint? usda (fixed-to-decimals amount) recipient) + (ft-mint? usda amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin (try! (check-is-approved contract-caller)) - (ft-burn? usda (fixed-to-decimals amount) sender) + (ft-burn? usda amount sender) ) ) -(begin - (map-set approved-contracts .faucet true) +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply usda))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance usda account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) ) -;; Initialize the contract for Testing. (begin - (try! (ft-mint? usda u1000000000 tx-sender)) - (try! (ft-mint? usda u10000000 .alex-reserve-pool)) - (try! (ft-mint? usda u200000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (map-set approved-contracts .faucet true) ) diff --git a/clarity/contracts/token/token-wbtc.clar b/clarity/contracts/token/token-wbtc.clar index 60b870cc..c8a9afff 100644 --- a/clarity/contracts/token/token-wbtc.clar +++ b/clarity/contracts/token/token-wbtc.clar @@ -1,5 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token wbtc) @@ -30,23 +30,23 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply wbtc))) + (ok (ft-get-supply wbtc)) ) (define-read-only (get-name) - (ok "WBTC") + (ok "wbtc") ) (define-read-only (get-symbol) - (ok "WBTC") + (ok "wbtc") ) (define-read-only (get-decimals) - (ok u8) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance wbtc account))) + (ok (ft-get-balance wbtc account)) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -60,24 +60,10 @@ (ok (some (var-get token-uri))) ) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? wbtc amount sender recipient) response (begin (print memo) (ok response) @@ -87,26 +73,54 @@ ) ) -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin (try! (check-is-approved contract-caller)) - (ft-mint? wbtc (fixed-to-decimals amount) recipient) + (ft-mint? wbtc amount recipient) ) ) -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin (try! (check-is-approved contract-caller)) - (ft-burn? wbtc (fixed-to-decimals amount) sender) + (ft-burn? wbtc amount sender) ) ) -(begin - (map-set approved-contracts .faucet true) +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply wbtc))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance wbtc account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) ) -;; Initialize the contract for Testing. (begin - (try! (ft-mint? wbtc u2000000000000 tx-sender)) - (try! (ft-mint? wbtc u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (map-set approved-contracts .faucet true) ) diff --git a/clarity/contracts/token/token-wstx.clar b/clarity/contracts/token/token-wstx.clar index 057187ea..b8026d52 100644 --- a/clarity/contracts/token/token-wstx.clar +++ b/clarity/contracts/token/token-wstx.clar @@ -1,5 +1,5 @@ (impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-pool-token.pool-token-trait) +(impl-trait .trait-sip-010.sip-010-trait) (define-fungible-token wstx) @@ -26,7 +26,7 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply wstx))) + (ok (ft-get-supply wstx)) ) (define-read-only (get-name) @@ -38,11 +38,11 @@ ) (define-read-only (get-decimals) - (ok u0) + (ok u8) ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance wstx account))) + (ok (ft-get-balance wstx account)) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -56,24 +56,10 @@ (ok (some (var-get token-uri))) ) -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? wstx (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? wstx amount sender recipient) response (begin (print memo) (ok response) @@ -84,25 +70,53 @@ ) ;; This can only be called by recipient since stx-transfer is involved ;; tx-sender -> .alex-vault -(define-public (mint (recipient principal) (amount uint)) +(define-public (mint (amount uint) (recipient principal)) (begin (asserts! (is-eq tx-sender recipient) ERR-NOT-TOKEN-OWNER) - (try! (stx-transfer? (/ (* amount (pow u10 u6)) ONE_8) recipient .alex-vault)) - (ft-mint? wstx (fixed-to-decimals amount) recipient) + (try! (stx-transfer? amount recipient .alex-vault)) + (ft-mint? wstx amount recipient) ) ) ;; This can only be called by sender since ft-burn is involved -(define-public (burn (sender principal) (amount uint)) +(define-public (burn (amount uint) (sender principal)) (begin (asserts! (is-eq tx-sender sender) ERR-NOT-TOKEN-OWNER) (as-contract (try! (contract-call? .alex-vault transfer-stx amount tx-sender sender))) - (ft-burn? wstx (fixed-to-decimals amount) sender) + (ft-burn? wstx amount sender) ) ) -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? wstx u2000000000000 tx-sender)) - (try! (ft-mint? wstx u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply wstx))) +) + +(define-read-only (get-balance-fixed (account principal)) + (ok (decimals-to-fixed (ft-get-balance wstx account))) +) + +(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) + (transfer (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (amount uint) (recipient principal)) + (mint (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (amount uint) (sender principal)) + (burn (fixed-to-decimals amount) sender) ) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-flash-loan-user.clar b/clarity/contracts/traits/trait-flash-loan-user.clar index bef19611..b2de11ff 100644 --- a/clarity/contracts/traits/trait-flash-loan-user.clar +++ b/clarity/contracts/traits/trait-flash-loan-user.clar @@ -5,6 +5,6 @@ ;; no need for params, as whoever implements this trait should know what he/she is doing ;; see test-flash-loan-user ;; (execute ( uint) (response bool uint) (optional (string-utf8 256))) - (execute ( uint) (response bool uint)) + (execute ( uint (optional uint)) (response bool uint)) ) ) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-multisig-vote.clar b/clarity/contracts/traits/trait-multisig-vote.clar index c11249f1..397f86c5 100644 --- a/clarity/contracts/traits/trait-multisig-vote.clar +++ b/clarity/contracts/traits/trait-multisig-vote.clar @@ -1,15 +1,22 @@ (use-trait ft-trait .trait-sip-010.sip-010-trait) +(use-trait sft-trait .trait-semi-fungible-token.semi-fungible-token-trait) (define-trait multisig-vote-trait ( (propose (uint (string-utf8 256) (string-utf8 256) uint uint) (response uint uint)) - (vote-for ( uint uint) (response uint uint)) - (vote-against ( uint uint) (response uint uint)) - (end-proposal (uint) (response bool uint)) - (return-votes-to-member ( uint principal) (response bool uint)) + ) +) -)) \ No newline at end of file +(define-trait multisig-vote-sft-trait + ( + (propose (uint uint (string-utf8 256) (string-utf8 256) uint uint) (response uint uint)) + (vote-for ( uint uint) (response uint uint)) + (vote-against ( uint uint) (response uint uint)) + (end-proposal (uint) (response bool uint)) + (return-votes-to-member ( uint principal) (response bool uint)) + ) +) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-pool-token.clar b/clarity/contracts/traits/trait-pool-token.clar deleted file mode 100644 index 0a027f17..00000000 --- a/clarity/contracts/traits/trait-pool-token.clar +++ /dev/null @@ -1,34 +0,0 @@ -(define-trait pool-token-trait - ( - ;; sip-010 - - ;; Transfer from the caller to a new principal - (transfer (uint principal principal (optional (buff 34))) (response bool uint)) - - ;; the human readable name of the token - (get-name () (response (string-ascii 32) uint)) - - ;; the ticker symbol, or empty if none - (get-symbol () (response (string-ascii 32) uint)) - - ;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token - (get-decimals () (response uint uint)) - - ;; the balance of the passed principal - (get-balance (principal) (response uint uint)) - - ;; the current total supply (which does not need to be a constant) - (get-total-supply () (response uint uint)) - - ;; an optional URI that represents metadata of this token - (get-token-uri () (response (optional (string-utf8 256)) uint)) - - ;; additional functions - - ;;mint(principal uint):bool - (mint (principal uint) (response bool uint)) - - ;;burn(principal uint):bool - (burn (principal uint) (response bool uint)) - ) -) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-semi-fungible-token.clar b/clarity/contracts/traits/trait-semi-fungible-token.clar new file mode 100644 index 00000000..9710357a --- /dev/null +++ b/clarity/contracts/traits/trait-semi-fungible-token.clar @@ -0,0 +1,44 @@ +(define-trait semi-fungible-token-trait + ( + ;; (get-token-owned (principal) (list)) + + ;; Get a token type balance of the passed principal. + (get-balance (uint principal) (response uint uint)) + + ;; Get the total SFT balance of the passed principal. + (get-overall-balance (principal) (response uint uint)) + + ;; Get the current total supply of a token type. + (get-total-supply (uint) (response uint uint)) + + ;; Get the overall SFT supply. + (get-overall-supply () (response uint uint)) + + ;; Get the number of decimal places of a token type. + (get-decimals (uint) (response uint uint)) + + ;; Get an optional token URI that represents metadata for a specific token. + (get-token-uri (uint) (response (optional (string-utf8 256)) uint)) + + ;; Transfer from one principal to another. + (transfer (uint uint principal principal) (response bool uint)) + + ;; Transfer from one principal to another with a memo. + (transfer-memo (uint uint principal principal (buff 34)) (response bool uint)) + + ;; Other functions + (mint (uint uint principal) (response bool uint)) + (burn (uint uint principal) (response bool uint)) + + ;; helper functions for 8-digit fixed notation + (transfer-fixed (uint uint principal principal) (response bool uint)) + (transfer-memo-fixed (uint uint principal principal (buff 34)) (response bool uint)) + (get-balance-fixed (uint principal) (response uint uint)) + (get-total-supply-fixed (uint) (response uint uint)) + (get-total-supply-fixed (uint) (response uint uint)) + (get-overall-balance-fixed (principal) (response uint uint)) + (get-overall-supply-fixed () (response uint uint)) + (mint-fixed (uint uint principal) (response bool uint)) + (burn-fixed (uint uint principal) (response bool uint)) + ) +) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-sip-010.clar b/clarity/contracts/traits/trait-sip-010.clar index cc331ee8..9e0940c2 100644 --- a/clarity/contracts/traits/trait-sip-010.clar +++ b/clarity/contracts/traits/trait-sip-010.clar @@ -2,7 +2,7 @@ ;; trait-sip-010 ;; -;; sip-010-trait must implement fixed point - see get-decimals() +;; sip-010-trait (define-trait sip-010-trait ( ;; Transfer from the caller to a new principal @@ -25,5 +25,17 @@ ;; an optional URI that represents metadata of this token (get-token-uri () (response (optional (string-utf8 256)) uint)) + + ;; additional functions + + (mint (uint principal) (response bool uint)) + (burn (uint principal) (response bool uint)) + + ;; helper functions for 8-digit fixed notation + (transfer-fixed (uint principal principal (optional (buff 34))) (response bool uint)) + (get-balance-fixed (principal) (response uint uint)) + (get-total-supply-fixed () (response uint uint)) + (mint-fixed (uint principal) (response bool uint)) + (burn-fixed (uint principal) (response bool uint)) ) ) \ No newline at end of file diff --git a/clarity/contracts/traits/trait-vault.clar b/clarity/contracts/traits/trait-vault.clar index abaa2736..d67e6658 100644 --- a/clarity/contracts/traits/trait-vault.clar +++ b/clarity/contracts/traits/trait-vault.clar @@ -8,7 +8,7 @@ (get-balance () (response uint uint)) ;; flash loan currently supports single token loan - (flash-loan ( uint) (response uint uint)) + (flash-loan ( uint (optional uint)) (response uint uint)) ) ) diff --git a/clarity/contracts/traits/trait-yield-token.clar b/clarity/contracts/traits/trait-yield-token.clar deleted file mode 100644 index 6917a389..00000000 --- a/clarity/contracts/traits/trait-yield-token.clar +++ /dev/null @@ -1,42 +0,0 @@ - - -(define-trait yield-token-trait - ( - ;; sip-010 - - ;; Transfer from the caller to a new principal - (transfer (uint principal principal (optional (buff 34))) (response bool uint)) - - ;; the human readable name of the token - (get-name () (response (string-ascii 32) uint)) - - ;; the ticker symbol, or empty if none - (get-symbol () (response (string-ascii 32) uint)) - - ;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token - (get-decimals () (response uint uint)) - - ;; the balance of the passed principal - (get-balance (principal) (response uint uint)) - - ;; the current total supply (which does not need to be a constant) - (get-total-supply () (response uint uint)) - - ;; an optional URI that represents metadata of this token - (get-token-uri () (response (optional (string-utf8 256)) uint)) - - ;; additional functions - - ;; mint(principal uint):bool - (mint (principal uint) (response bool uint)) - - ;; burn(principal uint):bool - (burn (principal uint) (response bool uint)) - - ;; the underlying token - (get-token () (response principal uint)) - - ;; the expiry - (get-expiry () (response uint uint)) - ) -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-11520.clar b/clarity/contracts/yield-token/yield-usda-11520.clar deleted file mode 100644 index 359e3b45..00000000 --- a/clarity/contracts/yield-token/yield-usda-11520.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-11520) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u1152000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-11520))) -) - -(define-read-only (get-name) - (ok "yield-usda-11520") -) - -(define-read-only (get-symbol) - (ok "yield-usda-11520") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-11520 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-11520 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-11520 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-11520 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-11520 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-121195.clar b/clarity/contracts/yield-token/yield-usda-121195.clar deleted file mode 100644 index 205a6b85..00000000 --- a/clarity/contracts/yield-token/yield-usda-121195.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-121195) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u12119500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-121195))) -) - -(define-read-only (get-name) - (ok "yield-usda-121195") -) - -(define-read-only (get-symbol) - (ok "yield-usda-121195") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-121195 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-121195 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-121195 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-121195 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-121195 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-132481.clar b/clarity/contracts/yield-token/yield-usda-132481.clar deleted file mode 100644 index ecf1d92b..00000000 --- a/clarity/contracts/yield-token/yield-usda-132481.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-132481) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u13248100000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-132481))) -) - -(define-read-only (get-name) - (ok "yield-usda-132481") -) - -(define-read-only (get-symbol) - (ok "yield-usda-132481") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-132481 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-132481 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-132481 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-132481 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-132481 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-161515.clar b/clarity/contracts/yield-token/yield-usda-161515.clar deleted file mode 100644 index 193bd68e..00000000 --- a/clarity/contracts/yield-token/yield-usda-161515.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-161515) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u16151500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-161515))) -) - -(define-read-only (get-name) - (ok "yield-usda-161515") -) - -(define-read-only (get-symbol) - (ok "yield-usda-161515") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-161515 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-161515 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-161515 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-161515 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-161515 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-200335.clar b/clarity/contracts/yield-token/yield-usda-200335.clar deleted file mode 100644 index abfddc1c..00000000 --- a/clarity/contracts/yield-token/yield-usda-200335.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-200335) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u20033500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-200335))) -) - -(define-read-only (get-name) - (ok "yield-usda-200335") -) - -(define-read-only (get-symbol) - (ok "yield-usda-200335") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-200335 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-200335 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-200335 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-200335 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-200335 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-23040.clar b/clarity/contracts/yield-token/yield-usda-23040.clar deleted file mode 100644 index f6643c65..00000000 --- a/clarity/contracts/yield-token/yield-usda-23040.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-23040) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2304000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-23040))) -) - -(define-read-only (get-name) - (ok "yield-usda-23040") -) - -(define-read-only (get-symbol) - (ok "yield-usda-23040") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-23040 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-23040 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-23040 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-23040 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-23040 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-240655.clar b/clarity/contracts/yield-token/yield-usda-240655.clar deleted file mode 100644 index fe429da0..00000000 --- a/clarity/contracts/yield-token/yield-usda-240655.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-240655) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u24065500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-240655))) -) - -(define-read-only (get-name) - (ok "yield-usda-240655") -) - -(define-read-only (get-symbol) - (ok "yield-usda-240655") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-240655 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-240655 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-240655 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-240655 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-240655 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-34560.clar b/clarity/contracts/yield-token/yield-usda-34560.clar deleted file mode 100644 index 33dc6a13..00000000 --- a/clarity/contracts/yield-token/yield-usda-34560.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-34560) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u3456000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-34560))) -) - -(define-read-only (get-name) - (ok "yield-usda-34560") -) - -(define-read-only (get-symbol) - (ok "yield-usda-34560") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-34560 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-34560 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-34560 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-34560 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-34560 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-51840.clar b/clarity/contracts/yield-token/yield-usda-51840.clar deleted file mode 100644 index c6089134..00000000 --- a/clarity/contracts/yield-token/yield-usda-51840.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-51840) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5184000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-51840))) -) - -(define-read-only (get-name) - (ok "yield-usda-51840") -) - -(define-read-only (get-symbol) - (ok "yield-usda-51840") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-51840 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-51840 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-51840 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-51840 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-51840 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-59760.clar b/clarity/contracts/yield-token/yield-usda-59760.clar deleted file mode 100644 index 76b5f7de..00000000 --- a/clarity/contracts/yield-token/yield-usda-59760.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-59760) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5976000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-59760))) -) - -(define-read-only (get-name) - (ok "yield-usda-59760") -) - -(define-read-only (get-symbol) - (ok "yield-usda-59760") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-59760 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-59760 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-59760 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-59760 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-59760 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-80875.clar b/clarity/contracts/yield-token/yield-usda-80875.clar deleted file mode 100644 index 562cf448..00000000 --- a/clarity/contracts/yield-token/yield-usda-80875.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-80875) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u8087500000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-80875))) -) - -(define-read-only (get-name) - (ok "yield-usda-80875") -) - -(define-read-only (get-symbol) - (ok "yield-usda-80875") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-80875 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-80875 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-80875 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-80875 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-80875 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda-92160.clar b/clarity/contracts/yield-token/yield-usda-92160.clar deleted file mode 100644 index f59d1c54..00000000 --- a/clarity/contracts/yield-token/yield-usda-92160.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-usda-92160) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u9216000000000) -(define-data-var underlying-token principal .token-usda) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-92160))) -) - -(define-read-only (get-name) - (ok "yield-usda-92160") -) - -(define-read-only (get-symbol) - (ok "yield-usda-92160") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-usda get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-92160 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-usda-92160 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-92160 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-usda-92160 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-usda-92160 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-usda.clar b/clarity/contracts/yield-token/yield-usda.clar new file mode 100644 index 00000000..971f6828 --- /dev/null +++ b/clarity/contracts/yield-token/yield-usda.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token yield-usda) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance yield-usda who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply yield-usda)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? yield-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? yield-usda amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? yield-usda amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? yield-usda amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply yield-usda))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance yield-usda who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .collateral-rebalancing-pool true) +) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-11520.clar b/clarity/contracts/yield-token/yield-wbtc-11520.clar deleted file mode 100644 index 66bed7a0..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-11520.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-11520) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u1152000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-11520))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-11520") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-11520") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-11520 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-11520 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-11520 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-11520 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-11520 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-121195.clar b/clarity/contracts/yield-token/yield-wbtc-121195.clar deleted file mode 100644 index 822f4b7e..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-121195.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-121195) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u12119500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-121195))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-121195") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-121195") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-121195 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-121195 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-121195 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-121195 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-121195 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-132481.clar b/clarity/contracts/yield-token/yield-wbtc-132481.clar deleted file mode 100644 index baed1517..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-132481.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-132481) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u13248100000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-132481))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-132481") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-132481") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-132481 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-132481 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-132481 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-132481 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-132481 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-161515.clar b/clarity/contracts/yield-token/yield-wbtc-161515.clar deleted file mode 100644 index d45f5b05..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-161515.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-161515) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u16151500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-161515))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-161515") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-161515") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-161515 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-161515 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-161515 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-161515 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-161515 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-200335.clar b/clarity/contracts/yield-token/yield-wbtc-200335.clar deleted file mode 100644 index 7d39b858..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-200335.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-200335) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u20033500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-200335))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-200335") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-200335") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-200335 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-200335 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-200335 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-200335 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-200335 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-23040.clar b/clarity/contracts/yield-token/yield-wbtc-23040.clar deleted file mode 100644 index 6335989d..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-23040.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-23040) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2304000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-23040))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-23040") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-23040") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-23040 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-23040 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-23040 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-23040 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-23040 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-23670.clar b/clarity/contracts/yield-token/yield-wbtc-23670.clar deleted file mode 100644 index aea75e62..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-23670.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-23670) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u2367000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-23670))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-23670") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-23670") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-23670 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-23670 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-23670 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-23670 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-23670 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-240655.clar b/clarity/contracts/yield-token/yield-wbtc-240655.clar deleted file mode 100644 index 423ecb92..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-240655.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-240655) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u24065500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-240655))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-240655") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-240655") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-240655 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-240655 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-240655 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-240655 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-240655 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-34560.clar b/clarity/contracts/yield-token/yield-wbtc-34560.clar deleted file mode 100644 index b0ac7876..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-34560.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-34560) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u3456000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-34560))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-34560") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-34560") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-34560 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-34560 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-34560 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-34560 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-34560 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-51840.clar b/clarity/contracts/yield-token/yield-wbtc-51840.clar deleted file mode 100644 index 9e4a2336..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-51840.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-51840) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5184000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-51840))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-51840") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-51840") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-51840 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-51840 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-51840 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-51840 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-51840 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-59760.clar b/clarity/contracts/yield-token/yield-wbtc-59760.clar deleted file mode 100644 index 25d04d5e..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-59760.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-59760) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u5976000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-59760))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-59760") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-59760") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-59760 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-59760 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-59760 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-59760 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-59760 u2000000000000 tx-sender)) -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-79760.clar b/clarity/contracts/yield-token/yield-wbtc-79760.clar deleted file mode 100644 index 503d2c91..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-79760.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-79760) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u7976000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-79760))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-79760") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-79760") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-79760 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-79760 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-79760 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-79760 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-79760 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-80875.clar b/clarity/contracts/yield-token/yield-wbtc-80875.clar deleted file mode 100644 index 96e2ccee..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-80875.clar +++ /dev/null @@ -1,113 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-80875) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u8087500000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-80875))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-80875") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-80875") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-80875 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-80875 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-80875 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-80875 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - ;; (try! (ft-mint? yield-wbtc-80875 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 - (try! (ft-mint? yield-wbtc-80875 u2000000000000 tx-sender)) -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc-92160.clar b/clarity/contracts/yield-token/yield-wbtc-92160.clar deleted file mode 100644 index eada6850..00000000 --- a/clarity/contracts/yield-token/yield-wbtc-92160.clar +++ /dev/null @@ -1,112 +0,0 @@ -(impl-trait .trait-ownable.ownable-trait) -(impl-trait .trait-yield-token.yield-token-trait) - -(define-fungible-token yield-wbtc-92160) - -(define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .collateral-rebalancing-pool) -(define-data-var token-expiry uint u9216000000000) -(define-data-var underlying-token principal .token-wbtc) - -;; errors -(define-constant ERR-NOT-AUTHORIZED (err u1000)) - -(define-constant ONE_8 (pow u10 u8)) - -(define-private (pow-decimals) - (pow u10 (unwrap-panic (get-decimals))) -) - -(define-read-only (fixed-to-decimals (amount uint)) - (/ (* amount (pow-decimals)) ONE_8) -) - -(define-private (decimals-to-fixed (amount uint)) - (/ (* amount ONE_8) (pow-decimals)) -) - -(define-read-only (get-owner) - (ok (var-get contract-owner)) -) - -(define-public (set-owner (owner principal)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set contract-owner owner)) - ) -) - -;; --------------------------------------------------------- -;; SIP-10 Functions -;; --------------------------------------------------------- - -(define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-92160))) -) - -(define-read-only (get-name) - (ok "yield-wbtc-92160") -) - -(define-read-only (get-symbol) - (ok "yield-wbtc-92160") -) - -(define-read-only (get-decimals) - (ok (unwrap-panic (contract-call? .token-wbtc get-decimals))) -) - -(define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-92160 account))) -) - -(define-public (set-token-uri (value (string-utf8 256))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set token-uri value)) - ) -) - -(define-read-only (get-token-uri) - (ok (some (var-get token-uri))) -) - -(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) - (begin - (asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) - (match (ft-transfer? yield-wbtc-92160 (fixed-to-decimals amount) sender recipient) - response (begin - (print memo) - (ok response) - ) - error (err error) - ) - ) -) - -(define-public (mint (recipient principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-92160 (fixed-to-decimals amount) recipient) - ) -) - -(define-public (burn (sender principal) (amount uint)) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-burn? yield-wbtc-92160 (fixed-to-decimals amount) sender) - ) -) - -(define-public (get-token) - (ok (var-get underlying-token)) -) - -(define-public (get-expiry) - (ok (var-get token-expiry)) -) - -;; Initialize the contract for Testing. -(begin - (try! (ft-mint? yield-wbtc-92160 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 -) \ No newline at end of file diff --git a/clarity/contracts/yield-token/yield-wbtc.clar b/clarity/contracts/yield-token/yield-wbtc.clar new file mode 100644 index 00000000..93a83ac6 --- /dev/null +++ b/clarity/contracts/yield-token/yield-wbtc.clar @@ -0,0 +1,171 @@ +(impl-trait .trait-ownable.ownable-trait) +(impl-trait .trait-semi-fungible-token.semi-fungible-token-trait) + +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-TOO-MANY-POOLS (err u2004)) +(define-constant ERR-INVALID-BALANCE (err u2008)) + +(define-fungible-token yield-wbtc) +(define-map token-balances {token-id: uint, owner: principal} uint) +(define-map token-supplies uint uint) +(define-map token-owned principal (list 2000 uint)) + +(define-data-var contract-owner principal tx-sender) +(define-map approved-contracts principal bool) + +(define-read-only (get-owner) + (ok (var-get contract-owner)) +) + +(define-public (set-owner (owner principal)) + (begin + (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) + (ok (var-set contract-owner owner)) + ) +) + +(define-private (check-is-approved (sender principal)) + (ok (asserts! (or (default-to false (map-get? approved-contracts sender)) (is-eq sender (var-get contract-owner))) ERR-NOT-AUTHORIZED)) +) + +(define-read-only (get-token-owned (owner principal)) + (default-to (list) (map-get? token-owned owner)) +) + +(define-private (set-balance (token-id uint) (balance uint) (owner principal)) + (begin + (map-set token-balances {token-id: token-id, owner: owner} balance) + (map-set token-owned owner (unwrap! (as-max-len? (append (get-token-owned owner) token-id) u2000) ERR-TOO-MANY-POOLS)) + (ok true) + ) +) + +(define-private (get-balance-or-default (token-id uint) (who principal)) + (default-to u0 (map-get? token-balances {token-id: token-id, owner: who})) +) + +(define-read-only (get-balance (token-id uint) (who principal)) + (ok (get-balance-or-default token-id who)) +) + +(define-read-only (get-overall-balance (who principal)) + (ok (ft-get-balance yield-wbtc who)) +) + +(define-read-only (get-total-supply (token-id uint)) + (ok (default-to u0 (map-get? token-supplies token-id))) +) + +(define-read-only (get-overall-supply) + (ok (ft-get-supply yield-wbtc)) +) + +(define-read-only (get-decimals (token-id uint)) + (ok u8) +) + +(define-read-only (get-token-uri (token-id uint)) + (ok none) +) + +(define-public (transfer (token-id uint) (amount uint) (sender principal) (recipient principal)) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? yield-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient}) + (ok true) + ) +) + +(define-public (transfer-memo (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (let + ( + (sender-balance (get-balance-or-default token-id sender)) + ) + (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED) + (asserts! (<= amount sender-balance) ERR-INVALID-BALANCE) + (try! (ft-transfer? yield-wbtc amount sender recipient)) + (try! (set-balance token-id (- sender-balance amount) sender)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (print {type: "sft_transfer_event", token-id: token-id, amount: amount, sender: sender, recipient: recipient, memo: memo}) + (ok true) + ) +) + +(define-public (mint (token-id uint) (amount uint) (recipient principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-mint? yield-wbtc amount recipient)) + (try! (set-balance token-id (+ (get-balance-or-default token-id recipient) amount) recipient)) + (map-set token-supplies token-id (+ (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_mint_event", token-id: token-id, amount: amount, recipient: recipient}) + (ok true) + ) +) + +(define-public (burn (token-id uint) (amount uint) (sender principal)) + (begin + (try! (check-is-approved contract-caller)) + (try! (ft-burn? yield-wbtc amount sender)) + (try! (set-balance token-id (- (get-balance-or-default token-id sender) amount) sender)) + (map-set token-supplies token-id (- (unwrap-panic (get-total-supply token-id)) amount)) + (print {type: "sft_burn_event", token-id: token-id, amount: amount, sender: sender}) + (ok true) + ) +) + +(define-constant ONE_8 (pow u10 u8)) + +(define-private (pow-decimals) + (pow u10 (unwrap-panic (get-decimals u0))) +) + +(define-read-only (fixed-to-decimals (amount uint)) + (/ (* amount (pow-decimals)) ONE_8) +) + +(define-private (decimals-to-fixed (amount uint)) + (/ (* amount ONE_8) (pow-decimals)) +) + +(define-read-only (get-total-supply-fixed (token-id uint)) + (ok (decimals-to-fixed (default-to u0 (map-get? token-supplies token-id)))) +) + +(define-read-only (get-balance-fixed (token-id uint) (who principal)) + (ok (decimals-to-fixed (get-balance-or-default token-id who))) +) + +(define-read-only (get-overall-supply-fixed) + (ok (decimals-to-fixed (ft-get-supply yield-wbtc))) +) + +(define-read-only (get-overall-balance-fixed (who principal)) + (ok (decimals-to-fixed (ft-get-balance yield-wbtc who))) +) + +(define-public (transfer-fixed (token-id uint) (amount uint) (sender principal) (recipient principal)) + (transfer token-id (fixed-to-decimals amount) sender recipient) +) + +(define-public (transfer-memo-fixed (token-id uint) (amount uint) (sender principal) (recipient principal) (memo (buff 34))) + (transfer token-id (fixed-to-decimals amount) sender recipient memo) +) + +(define-public (mint-fixed (token-id uint) (amount uint) (recipient principal)) + (mint token-id (fixed-to-decimals amount) recipient) +) + +(define-public (burn-fixed (token-id uint) (amount uint) (sender principal)) + (burn token-id (fixed-to-decimals amount) sender) +) + +(begin + (map-set approved-contracts .collateral-rebalancing-pool true) +) \ No newline at end of file diff --git a/clarity/tests/alex-reserve-pool_test.ts b/clarity/tests/alex-reserve-pool_test.ts index 897fadab..b8433955 100644 --- a/clarity/tests/alex-reserve-pool_test.ts +++ b/clarity/tests/alex-reserve-pool_test.ts @@ -341,10 +341,9 @@ describe("STAKING :", () => { // assert receipt.result.expectOk().expectBool(true); - assertEquals(receipt.events.length, 2); receipt.events.expectFungibleTokenTransferEvent( - amountTokens / ONE_8, + amountTokens, staker.address, clients.core.getVaultAddress(), "alex" @@ -387,7 +386,7 @@ describe("STAKING :", () => { assertEquals(receipt.events.length, 2); receipt.events.expectFungibleTokenTransferEvent( - amountTokens / ONE_8, + amountTokens, staker.address, clients.core.getVaultAddress(), "alex" @@ -732,11 +731,14 @@ describe("STAKING :", () => { ]).receipts; // assert - receipts[1].result.expectOk().expectBool(true); + let result:any = receipts[1].result.expectOk().expectTuple(); + result['entitled-token'].expectUint(ONE_8); + result['to-return'].expectUint(amountTokens); + assertEquals(receipts[1].events.length, 3); receipts[1].events.expectFungibleTokenTransferEvent( - amountTokens / ONE_8, + amountTokens, clients.core.getVaultAddress(), staker.address, "alex" @@ -832,14 +834,17 @@ describe("STAKING :", () => { receipt.result.expectErr(); } else if (toReturn === 0) { // only mints entitled tokens - receipt.result.expectOk().expectBool(true); + let result:any = receipt.result.expectOk().expectTuple(); + result['entitled-token'].expectUint(ONE_8); + result['to-return'].expectUint(0); assertEquals(receipt.events.length, 1); } else { - receipt.result.expectOk().expectBool(true); + let result:any = receipt.result.expectOk().expectTuple(); + result['entitled-token'].expectUint(ONE_8); assertEquals(receipt.events.length, 3); receipt.events.expectFungibleTokenTransferEvent( - toReturn / ONE_8, + toReturn, clients.core.getVaultAddress(), staker.address, "alex" diff --git a/clarity/tests/collateral-rebalancing-pool_test.ts b/clarity/tests/collateral-rebalancing-pool_test.ts index 8e6c2b49..26dc1adc 100644 --- a/clarity/tests/collateral-rebalancing-pool_test.ts +++ b/clarity/tests/collateral-rebalancing-pool_test.ts @@ -6,29 +6,24 @@ import { assertEquals } from 'https://deno.land/std@0.90.0/testing/asserts.ts'; import { CRPTestAgent1 } from './models/alex-tests-collateral-rebalancing-pool.ts'; import { FWPTestAgent1 } from './models/alex-tests-fixed-weight-pool.ts'; import { YTPTestAgent1 } from './models/alex-tests-yield-token-pool.ts'; -import { MS_CRP_WBTC_USDA_59760} from './models/alex-tests-multisigs.ts'; -import { USDAToken,WBTCToken,YIELD_WBTC_59760,KEY_WBTC_59760_USDA } from './models/alex-tests-tokens.ts'; +import { MS_CRP_USDA_WBTC, MS_CRP_WBTC_USDA } from './models/alex-tests-multisigs.ts'; +import { USDAToken, WBTCToken, YIELD_WBTC, KEY_WBTC_USDA } from './models/alex-tests-tokens.ts'; // Deployer Address Constants const wbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-wbtc" const usdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-usda" const fwpwbtcusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.fwp-wbtc-usda-50-50" const multisigfwpAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-fwp-wbtc-usda-50-50" -const yieldwbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc-59760" -const keywbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-wbtc-59760-usda" -const ytpyieldwbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc-59760-wbtc" -const multisigncrpwbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-wbtc-59760-usda" -const multisigytpyieldwbtc59760 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc-59760-wbtc" -const yieldwbtc79760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc-79760" -const keywbtc79760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-wbtc-79760-usda" -const ytpyieldwbtc79760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc-79760-wbtc" -const multisigncrpwbtc79760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-wbtc-79760-usda" -const multisigytpyieldwbtc79760 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc-79760-wbtc" +const yieldwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc" +const keywbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-wbtc-usda" +const ytpyieldwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc" +const multisigncrpwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-wbtc-usda" +const multisigytpyieldwbtc = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc" const vaultAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.alex-vault" const reserveAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.alex-reserve-pool" -const keywbtc59760wbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-wbtc-59760-wbtc" -const multisigncrpwbtc59760wbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-wbtc-59760-wbtc" -const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-usda-59760" +const keywbtcwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-wbtc-wbtc" +const multisigncrpwbtcwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-wbtc-wbtc" +const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-usda" const ONE_8 = 100000000 const expiry = 59760 * ONE_8 @@ -60,6 +55,14 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000 * ONE_8) let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -74,11 +77,11 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); @@ -117,7 +120,7 @@ Clarinet.test({ // borrow $5,000 more and convert to wbtc // remember, the first sell creates profit to LP - result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, 5000 * ONE_8); + result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, 5000 * ONE_8); position = result.expectOk().expectTuple(); position['dy'].expectUint(8046279); position['dx'].expectUint(8046447); @@ -145,7 +148,7 @@ Clarinet.test({ chain.mineEmptyBlockUntil((expiry / ONE_8)) // but lender cannot yet redeem - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, 0.5 * ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, 0.5 * ONE_8); result.expectErr().expectUint(2017); // simulate to expiry + 1 @@ -154,19 +157,8 @@ Clarinet.test({ call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); call.result.expectOk().expectUint(109786643); - // take away what was minted for testing to another address - let block = chain.mineBlock([ - Tx.contractCall("yield-wbtc-59760", "transfer", [ - types.uint(2000000000000), - types.principal(deployer.address), - types.principal(wallet_1.address), - types.some(types.buff(new ArrayBuffer(10))) - ], deployer.address), - ]); - block.receipts[0].result.expectOk(); - // deployer holds less than total supply because he sold some yield-wbtc for wbtc - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, ONE_8); position = result.expectOk().expectTuple(); position['dx'].expectUint(0); position['dy'].expectUint(80807360); @@ -180,7 +172,7 @@ Clarinet.test({ position['key-supply'].expectUint(88853639); // also remove all key tokens - result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, keywbtc59760Address, ONE_8); + result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, expiry, keywbtcAddress, ONE_8); position = result.expectOk().expectTuple(); position['dx'].expectUint(0); position['dy'].expectUint(1895950); @@ -203,6 +195,14 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000 * ONE_8) let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -212,50 +212,39 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); // non-deployer creating a pool will throw an error - result = CRPTest.createPool(wallet_1, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(wallet_1, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectErr().expectUint(1000); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); // supplying a wrong pool-token throws an error - result = CRPTest.addToPositionAndSwitch(wallet_1, wbtcAddress, usdaAddress, wrongPooltokenAddress, keywbtc59760Address, 5000 * ONE_8); + result = CRPTest.addToPositionAndSwitch(wallet_1, wbtcAddress, usdaAddress, expiry, wrongPooltokenAddress, keywbtcAddress, 5000 * ONE_8); result.expectErr().expectUint(2023); // same for key-token - result = CRPTest.addToPositionAndSwitch(wallet_1, wbtcAddress, usdaAddress, yieldwbtc59760Address, wrongPooltokenAddress, 5000 * ONE_8); + result = CRPTest.addToPositionAndSwitch(wallet_1, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, wrongPooltokenAddress, 5000 * ONE_8); result.expectErr().expectUint(2023); // simulate to expiry + 1 chain.mineEmptyBlockUntil((expiry / ONE_8) + 1) // supplying a wrong pool-token throws an error - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, wrongPooltokenAddress, ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, wrongPooltokenAddress, ONE_8); result.expectErr().expectUint(2023); // same for key-token - result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, wrongPooltokenAddress, ONE_8); + result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, expiry, wrongPooltokenAddress, ONE_8); result.expectErr().expectUint(2023); - - // take away what was minted for testing to another address - let block = chain.mineBlock([ - Tx.contractCall("yield-wbtc-59760", "transfer", [ - types.uint(2000000000000), - types.principal(deployer.address), - types.principal(wallet_1.address), - types.some(types.buff(new ArrayBuffer(10))) - ], deployer.address), - ]); - block.receipts[0].result.expectOk(); // remove all liquidity - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, ONE_8); result.expectOk(); - result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, keywbtc59760Address, ONE_8); + result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, expiry, keywbtcAddress, ONE_8); result.expectOk(); } }); @@ -268,6 +257,12 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -281,20 +276,20 @@ Clarinet.test({ position['balance-x'].expectUint(wbtcQ); position['balance-y'].expectUint(Math.round(wbtcQ * wbtcPrice / ONE_8)); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); // simulate to half way to expiry chain.mineEmptyBlockUntil((expiry / ONE_8) / 2) - result = YTPTest.createPool(deployer, yieldwbtc79760Address, wbtcAddress, ytpyieldwbtc79760Address, multisigytpyieldwbtc79760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry79760, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc79760Address, keywbtc79760Address, multisigncrpwbtc79760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry79760, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); @@ -309,6 +304,12 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -322,12 +323,12 @@ Clarinet.test({ position['balance-x'].expectUint(wbtcQ); position['balance-y'].expectUint(Math.round(wbtcQ * wbtcPrice / ONE_8)); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); let moving_average_0 = 0.95e+8 //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average_0, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average_0, 50000 * ONE_8); result.expectOk().expectBool(true); call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); @@ -376,6 +377,14 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); + yieldWBTC.mintFixed(expiry, 100 * ONE_8, deployer.address); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -384,23 +393,24 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ, wbtcQ); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ, wbtcQ); result.expectOk().expectBool(true); // sell some yield-token to create a positive yield - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 5*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 5*ONE_8, 0); let position:any = result.expectOk().expectTuple(); - let call = await YTPTest.getPrice(yieldwbtc59760Address); - call.result.expectOk().expectUint(100071157); + let call = await YTPTest.getPrice(expiry, yieldwbtcAddress); + call.result.expectOk().expectUint(100071156); let ltv_00 = Math.round(ONE_8 * ONE_8 / 109095981); let conversion_ltv_0 = 0.98e+8; let bs_vol_0 = 0.1e+8; let collateral = ONE_8; let moving_average_0 = 0.95e+8 + //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, wbtcAddress, yieldwbtc59760Address, keywbtc59760wbtcAddress, multisigncrpwbtc59760wbtcAddress, ltv_00, conversion_ltv_0, bs_vol_0, moving_average_0, collateral); + result = CRPTest.createPool(deployer, wbtcAddress, wbtcAddress, expiry, yieldwbtcAddress, keywbtcwbtcAddress, multisigncrpwbtcwbtcAddress, ltv_00, conversion_ltv_0, bs_vol_0, moving_average_0, collateral); result.expectOk().expectBool(true); call = await CRPTest.getPoolValueInToken(wbtcAddress, wbtcAddress, expiry); @@ -415,10 +425,10 @@ Clarinet.test({ position = call.result.expectOk().expectTuple(); position['yield-supply'].expectUint(91662405); //about 1 / 1.09 position['key-supply'].expectUint(91662405); - position['weight-x'].expectUint(52269439); - position['weight-y'].expectUint(ONE_8 - 52269439); - position['balance-x'].expectUint(52269439); - position['balance-y'].expectUint(ONE_8 - 52269439); + position['weight-x'].expectUint(52269424); + position['weight-y'].expectUint(ONE_8 - 52269424); + position['balance-x'].expectUint(52269424); + position['balance-y'].expectUint(ONE_8 - 52269424); position['strike'].expectUint(ONE_8); position['ltv-0'].expectUint(ltv_00); position['bs-vol'].expectUint(bs_vol_0); @@ -427,7 +437,7 @@ Clarinet.test({ // pegged CRP throws error if someone tries to swap call = await CRPTest.getXgivenPrice(wbtcAddress, wbtcAddress, expiry, Math.round( ONE_8 / (wbtcPrice * 1.1 / ONE_8))); - call.result.expectOk().expectUint(9516811587); + call.result.expectOk().expectUint(9516824576); result = CRPTest.swapXForY(deployer, wbtcAddress, wbtcAddress, expiry, 9516811587, 0); position = result.expectErr().expectUint(2001); }, @@ -442,6 +452,12 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -450,17 +466,17 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); - result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, 0); + result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, 0); result.expectErr().expectUint(2003) - result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, ONE_8 * ONE_8); + result = CRPTest.addToPositionAndSwitch(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, ONE_8 * ONE_8); result.expectErr().expectUint(4002) // arbtrageur attepmts to swap zero value @@ -475,15 +491,15 @@ Clarinet.test({ chain.mineEmptyBlockUntil((expiry / ONE_8) + 1) // arbtrageur attepmts to retreive back with zero value - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, 0); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, 0); result.expectErr().expectUint(3000) // arbitrageur attempts to retreuve back with small value - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, 0.001 * ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, 0.001 * ONE_8); result.expectOk().expectTuple(); // arbtrageur attepmts to retreive back with full value - result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, 101*ONE_8); + result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, 101*ONE_8); result.expectErr().expectUint(5000) }, }); @@ -494,6 +510,12 @@ Clarinet.test({ let deployer = accounts.get("deployer")!; let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -502,7 +524,7 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); result = await CRPTest.getYgivenX(deployer, wbtcAddress, usdaAddress, expiry, ONE_8); @@ -536,12 +558,22 @@ Clarinet.test({ let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); - let MultiSigTest = new MS_CRP_WBTC_USDA_59760(chain, deployer); - let YieldToken = new YIELD_WBTC_59760(chain, deployer); - let KeyToken = new KEY_WBTC_59760_USDA(chain, deployer); + let MultiSigTest = new MS_CRP_WBTC_USDA(chain, deployer); + let YieldToken = new YIELD_WBTC(chain, deployer); + let KeyToken = new KEY_WBTC_USDA(chain, deployer); const feeRateX = 0.1*ONE_8; // 10% const feeRateY = 0.1*ONE_8; const feeRebate = 0.5*ONE_8; + + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); + wbtcToken.mintFixed(wallet_1.address, 10000 * ONE_8); + YieldToken.mintFixed(expiry, 20000 * ONE_8, wallet_1.address); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, wbtcQ, Math.round(wbtcPrice * wbtcQ / ONE_8)); result.expectOk().expectBool(true); @@ -555,47 +587,36 @@ Clarinet.test({ position['balance-x'].expectUint(wbtcQ); position['balance-y'].expectUint(Math.round(wbtcQ * wbtcPrice / ONE_8)); - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, wbtcQ / 10, wbtcQ / 10); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, wbtcQ / 10, wbtcQ / 10); result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, keywbtc59760Address, multisigncrpwbtc59760Address, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); + result = CRPTest.createPool(deployer, wbtcAddress, usdaAddress, expiry, yieldwbtcAddress, keywbtcAddress, multisigncrpwbtcAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 50000 * ONE_8); result.expectOk().expectBool(true); - let ROresult:any = YieldToken.totalSupply() + let ROresult:any = YieldToken.totalSupply(expiry) ROresult.result.expectOk().expectUint(2000080807360); - // take away what was minted for testing to another address - let block = chain.mineBlock([ - Tx.contractCall("yield-wbtc-59760", "transfer", [ - types.uint(2000000000000), - types.principal(deployer.address), - types.principal(wallet_1.address), - types.some(types.buff(new ArrayBuffer(10))) - ], deployer.address), - ]); - block.receipts[0].result.expectOk(); - - ROresult = YieldToken.balanceOf(deployer.address) + ROresult = YieldToken.balanceOf(expiry, deployer.address) ROresult.result.expectOk().expectUint(80807360); - ROresult = KeyToken.totalSupply() + ROresult = KeyToken.totalSupply(expiry) ROresult.result.expectOk().expectUint(80807360); - ROresult = KeyToken.balanceOf(deployer.address) + ROresult = KeyToken.balanceOf(expiry, deployer.address) ROresult.result.expectOk().expectUint(80807360); // Fee rate Setting Proposal of Multisig - result = MultiSigTest.propose(wallet_1,1000, " Fee Rate Setting to 10%", " https://docs.alexgo.io", feeRateX, feeRateY) + result = MultiSigTest.propose(wallet_1, expiry, 1000, " Fee Rate Setting to 10%", " https://docs.alexgo.io", feeRateX, feeRateY) result.expectOk().expectUint(1) // First Proposal // Block 1000 mining chain.mineEmptyBlock(1000); // deployer and wallet_1 votes for 90 % of his token - result = MultiSigTest.voteFor(wallet_1, yieldwbtc59760Address, 1, 2000000000000 * 9 / 10 ) + result = MultiSigTest.voteFor(wallet_1, yieldwbtcAddress, 1, 2000000000000 * 9 / 10 ) result.expectOk().expectUint(1800000000000) - result = MultiSigTest.voteFor(deployer, yieldwbtc59760Address, 1, 80807360 * 9 / 10 ) + result = MultiSigTest.voteFor(deployer, yieldwbtcAddress, 1, 80807360 * 9 / 10 ) result.expectOk().expectUint(72726624) // Block 1440 mining for ending proposal @@ -610,8 +631,8 @@ Clarinet.test({ call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['balance-x'].expectUint(3326726300000); - position['balance-y'].expectUint(33576900); + position['balance-x'].expectUint(3326719750000); + position['balance-y'].expectUint(33577100); position['yield-supply'].expectUint(80807360); position['key-supply'].expectUint(80807360); position['fee-rate-x'].expectUint(0.1*ONE_8); @@ -628,17 +649,17 @@ Clarinet.test({ // fee-rebate : 0.5 * ONE_8 call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['balance-x'].expectUint(3336226300000); // 3326726300000 + 0.95 * 100* ONE_8 - position['balance-y'].expectUint(33397031); + position['balance-x'].expectUint(3336219750000); // 3326726300000 + 0.95 * 100* ONE_8 + position['balance-y'].expectUint(33397231); result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.001 * ONE_8, 0); position = result.expectOk().expectTuple(); - position['dx'].expectUint(9866889282); + position['dx'].expectUint(9866803186); position['dy'].expectUint(0.0009 * ONE_8); call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['balance-x'].expectUint(3326359410718); - position['balance-y'].expectUint(33492031); // 33397031 + 0.95 * 0.001* ONE_8 + position['balance-x'].expectUint(3336219750000 - 9866803186); + position['balance-y'].expectUint(33397231 + 0.95 * 0.001 * ONE_8); // 33397031 + 0.95 * 0.001* ONE_8 } }) \ No newline at end of file diff --git a/clarity/tests/fixed-weight-pool_test.ts b/clarity/tests/fixed-weight-pool_test.ts index 0ff1d418..302bc602 100644 --- a/clarity/tests/fixed-weight-pool_test.ts +++ b/clarity/tests/fixed-weight-pool_test.ts @@ -7,7 +7,7 @@ import { MS_FWP_WBTC_USDA_5050 } from './models/alex-tests-multisigs.ts'; import { USDAToken, WBTCToken, - POOLTOKEN_FWP_WBTC_USDA_5050 + FWP_WBTC_USDA_5050 } from './models/alex-tests-tokens.ts'; // Deployer Address Constants @@ -16,7 +16,8 @@ const usdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-usda" const fwpwbtcusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.fwp-wbtc-usda-50-50" const multisigAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-fwp-wbtc-usda-50-50" const fwpAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.fixed-weight-pool" -const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda-23040-usda" +const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.lbp-alex-usda-90-10" +const alexReservePoolAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.alex-reserve-pool" const ONE_8 = 100000000 @@ -34,7 +35,16 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let FWPTest = new FWPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 100000 * ONE_8); + wbtcToken.mintFixed(wallet_1.address, 100000 * ONE_8); // Deployer creating a pool, initial tokens injected to the pool let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigAddress, wbtcQ, wbtcQ*wbtcPrice); @@ -105,6 +115,14 @@ Clarinet.test({ let deployer = accounts.get("deployer")!; let wallet_1 = accounts.get("wallet_1")!; let FWPTest = new FWPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 100000 * ONE_8); + wbtcToken.mintFixed(wallet_1.address, 100000 * ONE_8); // non-deployer attempting to create a pool will throw an error let result = FWPTest.createPool(wallet_1, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigAddress, wbtcQ, wbtcQ*wbtcPrice); @@ -140,17 +158,21 @@ Clarinet.test({ Clarinet.test({ - name: "FWP : fee Setting using multisig ", + name: "FWP : fee setting using multisig ", async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; - let contractOwner = deployer + let contractOwner = deployer; + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 100000 * ONE_8); let FWPTest = new FWPTestAgent1(chain, deployer); let MultiSigTest = new MS_FWP_WBTC_USDA_5050(chain, deployer); - let usdaToken = new USDAToken(chain, deployer); - let wbtcToken = new WBTCToken(chain, deployer); - let fwpPoolToken = new POOLTOKEN_FWP_WBTC_USDA_5050(chain, deployer); + let fwpPoolToken = new FWP_WBTC_USDA_5050(chain, deployer); const feeRateX = 0.1*ONE_8; // 10% const feeRateY = 0.1*ONE_8; @@ -249,11 +271,16 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; - let wallet_1 = accounts.get("wallet_1")!; let FWPTest = new FWPTestAgent1(chain, deployer); let MultiSigTest = new MS_FWP_WBTC_USDA_5050(chain, deployer); const feeRateX = 5000000; // 5% const feeRateY = 5000000; + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 100000 * ONE_8); // Deployer creating a pool, initial tokens injected to the pool let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigAddress, wbtcQ, wbtcQ*wbtcPrice); @@ -340,7 +367,13 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; - let FWPTest = new FWPTestAgent1(chain, deployer); + let FWPTest = new FWPTestAgent1(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 100000 * ONE_8); // Deployer creating a pool, initial tokens injected to the pool let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigAddress, wbtcQ, wbtcQ*wbtcPrice); diff --git a/clarity/tests/flash-loan_test.ts b/clarity/tests/flash-loan_test.ts index ce75d446..961f4a67 100644 --- a/clarity/tests/flash-loan_test.ts +++ b/clarity/tests/flash-loan_test.ts @@ -7,28 +7,24 @@ import { CRPTestAgent1 } from './models/alex-tests-collateral-rebalancing-pool.t import { FWPTestAgent1 } from './models/alex-tests-fixed-weight-pool.ts'; import { YTPTestAgent1 } from './models/alex-tests-yield-token-pool.ts'; import { FLTestAgent1 } from './models/alex-tests-flash-loan.ts'; -import { WBTCToken } from './models/alex-tests-tokens.ts'; +import { WBTCToken, USDAToken } from './models/alex-tests-tokens.ts'; // Deployer Address Constants const usdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-usda" const wbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-wbtc" const fwpwbtcusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.fwp-wbtc-usda-50-50" const multisigfwpAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-fwp-wbtc-usda-50-50" -const yieldusda23040Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-usda-23040" -const keyusda23040Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-usda-23040-wbtc" -const ytpyieldusda23040Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda-23040-usda" -const multisigncrpusda23040Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-usda-23040-wbtc" -const multisigytpyieldusda23040 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-usda-23040-usda" -const loanuser23040Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.flash-loan-user-margin-wbtc-usda-23040" -const yieldusda51840Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-usda-51840" -const keyusda51840Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-usda-51840-wbtc" -const ytpyieldusda51840Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda-51840-usda" -const multisigncrpusda51840Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-usda-51840-wbtc" -const multisigytpyieldusda51840 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-usda-51840-usda" -const loanuser51840Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.flash-loan-user-margin-wbtc-usda-51840" +const yieldusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-usda" +const keyusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.key-usda-wbtc" +const ytpyieldusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda" +const multisigncrpusdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-crp-usda-wbtc" +const multisigytpyieldusda = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-usda" +const loanuserAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.flash-loan-user-margin-usda-wbtc" +const alexReservePoolAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.alex-reserve-pool" const ONE_8 = 100000000 const expiry = 23040e+8 +const nextExpiry = 51840e+8 const ltv_0 = 0.8e+8 const conversion_ltv = 0.95e+8 const bs_vol = 0.8e+8 @@ -50,17 +46,25 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let wallet_5 = accounts.get("wallet_5")!; let CRPTest = new CRPTestAgent1(chain, deployer); let FWPTest = new FWPTestAgent1(chain, deployer); let YTPTest = new YTPTestAgent1(chain, deployer); let FLTest = new FLTestAgent1(chain, deployer); - let wbtcToken = new WBTCToken(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + usdaToken.mintFixed(wallet_1.address, 200000 * ONE_8); + wbtcToken.mintFixed(deployer.address, 10000 * ONE_8); + wbtcToken.mintFixed(wallet_1.address, 10000 * ONE_8); - wbtcToken.transferToken(ONE_8,deployer.address, wallet_5.address, new ArrayBuffer(30)); + wbtcToken.transferToken(ONE_8, deployer.address, wallet_5.address, new ArrayBuffer(30)); let call = await FLTest.getBalance(wbtcAddress, wallet_5.address); - let position:any = call.result.expectOk().expectUint(ONE_8); + let position:any = call.result.expectOk().expectUint(100000000); let result = FWPTest.createPool(deployer, wbtcAddress, usdaAddress, weightX, weightY, fwpwbtcusdaAddress, multisigfwpAddress, Math.round(500000e+8 * ONE_8 / wbtcPrice), 500000e+8); result.expectOk().expectBool(true); @@ -69,18 +73,18 @@ Clarinet.test({ result = FWPTest.setOracleAverage(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0.95e8); result.expectOk().expectBool(true); - result = YTPTest.createPool(deployer, yieldusda23040Address, usdaAddress, ytpyieldusda23040Address, multisigytpyieldusda23040, 500000e+8, 500000e+8); + result = YTPTest.createPool(deployer, expiry, yieldusdaAddress, usdaAddress, ytpyieldusdaAddress, multisigytpyieldusda, 500000e+8, 500000e+8); result.expectOk().expectBool(true); - result = CRPTest.createPool(deployer, usdaAddress, wbtcAddress, yieldusda23040Address, keyusda23040Address, multisigncrpusda23040Address, ltv_0, conversion_ltv, bs_vol, moving_average, 1e+8); + result = CRPTest.createPool(deployer, usdaAddress, wbtcAddress, expiry, yieldusdaAddress, keyusdaAddress, multisigncrpusdaAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 1e+8); result.expectOk().expectBool(true); - call = await FLTest.getBalance(keyusda23040Address, wallet_5.address); + call = await FLTest.getBalanceSFT(keyusdaAddress, expiry, wallet_5.address); position = call.result.expectOk().expectUint(0); - call = await FLTest.getBalance(yieldusda23040Address, wallet_5.address); + call = await FLTest.getBalanceSFT(yieldusdaAddress, expiry, wallet_5.address); position = call.result.expectOk().expectUint(0); // Let's borrow 1 BTC to lever up - result = FLTest.flashLoan(wallet_5, loanuser23040Address, wbtcAddress, ONE_8); + result = FLTest.flashLoan(wallet_5, loanuserAddress, wbtcAddress, ONE_8, expiry); result.expectOk(); // spent ~$231 to buy levered position (0.02 uints) @@ -89,37 +93,37 @@ Clarinet.test({ call = await FLTest.getBalance(usdaAddress, wallet_5.address); position = call.result.expectOk().expectUint(0); // should see change in key token - call = await FLTest.getBalance(keyusda23040Address, wallet_5.address); - position = call.result.expectOk().expectUint(4094610000000); + call = await FLTest.getBalanceSFT(keyusdaAddress, expiry, wallet_5.address); + position = call.result.expectOk().expectUint(4094610276984); // but nothing with yield token - call = await FLTest.getBalance(yieldusda23040Address, wallet_5.address); + call = await FLTest.getBalanceSFT(yieldusdaAddress, expiry, wallet_5.address); position = call.result.expectOk().expectUint(0); // let's test roll-position from margin-helper chain.mineEmptyBlockUntil(10000); // trying to roll before maturity throws error - result = FLTest.rollPosition(wallet_5, usdaAddress, wbtcAddress, keyusda23040Address, loanuser51840Address); + result = FLTest.rollPosition(wallet_5, usdaAddress, wbtcAddress, keyusdaAddress, loanuserAddress, expiry, nextExpiry); result.expectErr().expectUint(2017); // but let's set up new pools - result = YTPTest.createPool(deployer, yieldusda51840Address, usdaAddress, ytpyieldusda51840Address, multisigytpyieldusda51840, 500000e+8, 500000e+8); + result = YTPTest.createPool(deployer, nextExpiry, yieldusdaAddress, usdaAddress, ytpyieldusdaAddress, multisigytpyieldusda, 500000e+8, 500000e+8); result.expectOk().expectBool(true); - result = CRPTest.createPool(deployer, usdaAddress, wbtcAddress, yieldusda51840Address, keyusda51840Address, multisigncrpusda51840Address, ltv_0, conversion_ltv, bs_vol, moving_average, 1e+8); + result = CRPTest.createPool(deployer, usdaAddress, wbtcAddress, nextExpiry, yieldusdaAddress, keyusdaAddress, multisigncrpusdaAddress, ltv_0, conversion_ltv, bs_vol, moving_average, 1e+8); result.expectOk().expectBool(true); chain.mineEmptyBlockUntil((expiry / ONE_8) + 1); // roll right after expiry succeeds. - result = FLTest.rollPosition(wallet_5, usdaAddress, wbtcAddress, keyusda23040Address, loanuser51840Address); + result = FLTest.rollPosition(wallet_5, usdaAddress, wbtcAddress, keyusdaAddress, loanuserAddress, expiry, nextExpiry); result.expectOk(); - // key-usda-23040-wbtc should be zero, with non-zero positions in key-usda-51840 - call = await FLTest.getBalance(keyusda23040Address, wallet_5.address); + // key-usda--wbtc should be zero, with non-zero positions in key-usda-51840 + call = await FLTest.getBalanceSFT(keyusdaAddress, expiry, wallet_5.address); position = call.result.expectOk().expectUint(0); - call = await FLTest.getBalance(keyusda51840Address, wallet_5.address); - position = call.result.expectOk().expectUint(1793499000000); + call = await FLTest.getBalanceSFT(keyusdaAddress, nextExpiry, wallet_5.address); + position = call.result.expectOk().expectUint(1793499970806); // but nothing with yield-usda-51840 - call = await FLTest.getBalance(yieldusda51840Address, wallet_5.address); + call = await FLTest.getBalanceSFT(yieldusdaAddress, nextExpiry, wallet_5.address); position = call.result.expectOk().expectUint(0); }, diff --git a/clarity/tests/liquidity-bootstrapping-pool_test.ts b/clarity/tests/liquidity-bootstrapping-pool_test.ts index 176aa96b..3bdc2a5b 100644 --- a/clarity/tests/liquidity-bootstrapping-pool_test.ts +++ b/clarity/tests/liquidity-bootstrapping-pool_test.ts @@ -1,6 +1,7 @@ import { Clarinet, Tx, Chain, Account, types } from 'https://deno.land/x/clarinet@v0.14.0/index.ts'; import { LBPTestAgent } from './models/alex-tests-liquidity-bootstrapping-pool.ts'; +import { USDAToken, ALEXToken } from './models/alex-tests-tokens.ts'; // Deployer Address Constants const usdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-usda" @@ -29,18 +30,19 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; let LBPTest = new LBPTestAgent(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let alexToken = new ALEXToken(chain, deployer); - let call = chain.callReadOnlyFn("token-alex", "get-balance", - [types.principal(deployer.address) - ], deployer.address); - call.result.expectOk().expectUint(100000000000000000); + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + alexToken.mintFixed(deployer.address, 1000000000 * ONE_8); // Deployer creating a pool, initial tokens injected to the pool let result = LBPTest.createPool(deployer, alexAddress, usdaAddress, weightX1, weightX2, expiry, poolTokenAddress, multisigAddress, alexQty, usdaQty); result.expectOk().expectBool(true); // Check pool details and print - call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + let call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); let position:any = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(80274141756); position['balance-x'].expectUint(alexQty); @@ -168,6 +170,12 @@ Clarinet.test({ let deployer = accounts.get("deployer")!; let wallet_1 = accounts.get("wallet_1")!; let LBPTest = new LBPTestAgent(chain, deployer); + let usdaToken = new USDAToken(chain, deployer); + let alexToken = new ALEXToken(chain, deployer); + + // Deployer minting initial tokens + usdaToken.mintFixed(deployer.address, 1000000000 * ONE_8); + alexToken.mintFixed(deployer.address, 1000000000 * ONE_8); // non-deployer creating a pool will throw an error let result = LBPTest.createPool(wallet_1, alexAddress, usdaAddress, weightX1, weightX2, expiry, poolTokenAddress, multisigAddress, alexQty, usdaQty); diff --git a/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts b/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts index 4e0f294c..bcec48ba 100644 --- a/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts +++ b/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts @@ -73,11 +73,12 @@ import { ], this.deployer.address); } - createPool(user: Account, token: string, collateral: string, yieldToken: string, keyToken: string, multiSig: string, ltv_0: number, conversion_ltv: number, bs_vol: number, moving_average: number, dX: number) { + createPool(user: Account, token: string, collateral: string, expiry: number, yieldToken: string, keyToken: string, multiSig: string, ltv_0: number, conversion_ltv: number, bs_vol: number, moving_average: number, dX: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "create-pool", [ types.principal(token), types.principal(collateral), + types.uint(expiry), types.principal(yieldToken), types.principal(keyToken), types.principal(multiSig), @@ -91,11 +92,12 @@ import { return block.receipts[0].result; } - addToPosition(user: Account, token: string, collateral: string, yieldToken: string, keyToken:string, dX: number) { + addToPosition(user: Account, token: string, collateral: string, expiry: number, yieldToken: string, keyToken:string, dX: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "add-to-position", [ types.principal(token), types.principal(collateral), + types.uint(expiry), types.principal(yieldToken), types.principal(keyToken), types.uint(dX) @@ -104,11 +106,12 @@ import { return block.receipts[0].result; } - addToPositionAndSwitch(user: Account, token: string, collateral: string, yieldToken: string, keyToken: string, dX: number) { + addToPositionAndSwitch(user: Account, token: string, collateral: string, expiry: number, yieldToken: string, keyToken: string, dX: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "add-to-position-and-switch", [ types.principal(token), types.principal(collateral), + types.uint(expiry), types.principal(yieldToken), types.principal(keyToken), types.uint(dX) @@ -117,11 +120,12 @@ import { return block.receipts[0].result; } - reducePositionYield(user: Account, token: string, collateral: string, yieldToken: string, percent: number) { + reducePositionYield(user: Account, token: string, collateral: string, expiry: number, yieldToken: string, percent: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "reduce-position-yield", [ types.principal(token), types.principal(collateral), + types.uint(expiry), types.principal(yieldToken), types.uint(percent) ], user.address), @@ -129,11 +133,12 @@ import { return block.receipts[0].result; } - reducePositionKey(user: Account, token: string, collateral: string, keyToken: string, percent: number) { + reducePositionKey(user: Account, token: string, collateral: string, expiry: number, keyToken: string, percent: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "reduce-position-key", [ types.principal(token), types.principal(collateral), + types.uint(expiry), types.principal(keyToken), types.uint(percent) ], user.address), @@ -268,28 +273,30 @@ import { ], this.deployer.address); } - burnKeyToken(user: Account, amount: number) { - let block = this.chain.mineBlock([Tx.contractCall("key-wbtc-59760-usda", "burn", [ - types.principal(user.address), - types.uint(amount) + burnKeyToken(user: Account, expiry: number, amount: number) { + let block = this.chain.mineBlock([Tx.contractCall("key-wbtc-usda", "burn-fixed", [ + types.uint(expiry), + types.uint(amount), + types.principal(user.address) ], user.address), ]); return block.receipts[0].result; } - transfer(user: Account, token: string, amount: number, sender: string, recipient: string, memo: ArrayBuffer) { + transfer(user: Account, token: string, expiry: number, amount: number, sender: string, recipient: string) { let block = this.chain.mineBlock([Tx.contractCall(token, "transfer-fixed", [ + types.uint(expiry), types.uint(amount), types.principal(sender), types.principal(recipient), - types.some(types.buff(memo)) ], user.address), ]); return block.receipts[0].result; } - getBalance(token: string, owner: string) { - return this.chain.callReadOnlyFn(token, "get-balance", [ + getBalance(token: string, expiry: number, owner: string) { + return this.chain.callReadOnlyFn(token, "get-balance-fixed", [ + types.uint(expiry), types.principal(owner) ], this.deployer.address); } diff --git a/clarity/tests/models/alex-tests-flash-loan.ts b/clarity/tests/models/alex-tests-flash-loan.ts index f8dd6930..7cc43415 100644 --- a/clarity/tests/models/alex-tests-flash-loan.ts +++ b/clarity/tests/models/alex-tests-flash-loan.ts @@ -16,34 +16,44 @@ import { this.deployer = deployer; } - flashLoan(user: Account, loanuser:string, token:string, amount: number) { + flashLoan(user: Account, loanuser:string, token:string, amount: number, memo: number) { let block = this.chain.mineBlock([ Tx.contractCall("alex-vault", "flash-loan", [ types.principal(loanuser), types.principal(token), types.uint(amount), + types.some(types.uint(memo)) ], user.address), ]); return block.receipts[0].result; } - rollPosition(user: Account, token: string, collateral: string, keyToken: string, loanuser:string) { + rollPosition(user: Account, token: string, collateral: string, keyToken: string, loanuser:string, expiry: number, expiry_to_roll: number) { let block = this.chain.mineBlock([ Tx.contractCall("margin-helper", "roll-position", [ types.principal(token), types.principal(collateral), types.principal(keyToken), - types.principal(loanuser) + types.principal(loanuser), + types.uint(expiry), + types.uint(expiry_to_roll) ], user.address), ]); return block.receipts[0].result; } getBalance(token: string, owner: string) { - return this.chain.callReadOnlyFn(token, "get-balance", [ + return this.chain.callReadOnlyFn(token, "get-balance-fixed", [ + types.principal(owner) + ], this.deployer.address); + } + + getBalanceSFT(token: string, expiry: number, owner: string) { + return this.chain.callReadOnlyFn(token, "get-balance-fixed", [ + types.uint(expiry), types.principal(owner) ], this.deployer.address); - } + } } export { FLTestAgent1 }; diff --git a/clarity/tests/models/alex-tests-multisigs.ts b/clarity/tests/models/alex-tests-multisigs.ts index ded487ab..d722fb8c 100644 --- a/clarity/tests/models/alex-tests-multisigs.ts +++ b/clarity/tests/models/alex-tests-multisigs.ts @@ -66,7 +66,7 @@ export { MS_FWP_WBTC_USDA_5050 }; -class MS_YTP_WBT_59760 { +class MS_YTP_YIELD_WBTC { chain: Chain; deployer: Account; @@ -75,9 +75,10 @@ constructor(chain: Chain, deployer: Account) { this.deployer = deployer; } -propose(startBlockHeight: number, proposeTitle: string, proposeURL: string, feeRateX: number, feeRateY: number) { +propose(expiry: number, startBlockHeight: number, proposeTitle: string, proposeURL: string, feeRateX: number, feeRateY: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-ytp-yield-wbtc-59760-wbtc", "propose", [ + Tx.contractCall("multisig-ytp-yield-wbtc", "propose", [ + types.uint(expiry), types.uint(startBlockHeight), types.utf8(proposeTitle), types.utf8(proposeURL), @@ -90,7 +91,7 @@ propose(startBlockHeight: number, proposeTitle: string, proposeURL: string, feeR voteFor(contractCaller: Account, token: string, proposalID: number, amount: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-ytp-yield-wbtc-59760-wbtc", "vote-for", [ + Tx.contractCall("multisig-ytp-yield-wbtc", "vote-for", [ types.principal(token), types.uint(proposalID), types.uint(amount) @@ -101,7 +102,7 @@ voteFor(contractCaller: Account, token: string, proposalID: number, amount: numb voteAgainst(contractCaller: Account, token: string, proposalID: number, amount: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-ytp-yield-wbtc-59760-wbtc", "vote-against", [ + Tx.contractCall("multisig-ytp-yield-wbtc", "vote-against", [ types.principal(token), types.uint(proposalID), types.uint(amount) @@ -112,17 +113,17 @@ voteAgainst(contractCaller: Account, token: string, proposalID: number, amount: endProposal(proposalID: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-ytp-yield-wbtc-59760-wbtc", "end-proposal", [ + Tx.contractCall("multisig-ytp-yield-wbtc", "end-proposal", [ types.uint(proposalID), ], this.deployer.address), ]); return block.receipts[0].result; } } -export { MS_YTP_WBT_59760 }; +export { MS_YTP_YIELD_WBTC }; -class MS_CRP_WBTC_USDA_59760 { +class MS_CRP_USDA_WBTC { chain: Chain; deployer: Account; @@ -131,9 +132,10 @@ constructor(chain: Chain, deployer: Account) { this.deployer = deployer; } -propose(contractCaller: Account, startBlockHeight: number, proposeTitle: string, proposeURL: string, feeRateX: number, feeRateY: number) { +propose(contractCaller: Account, expiry: number, startBlockHeight: number, proposeTitle: string, proposeURL: string, feeRateX: number, feeRateY: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-crp-wbtc-59760-usda", "propose", [ + Tx.contractCall("multisig-crp-usda-wbtc", "propose", [ + types.uint(expiry), types.uint(startBlockHeight), types.utf8(proposeTitle), types.utf8(proposeURL), @@ -146,7 +148,7 @@ propose(contractCaller: Account, startBlockHeight: number, proposeTitle: string, voteFor(contractCaller: Account, token: string, proposalID: number, amount: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-crp-wbtc-59760-usda", "vote-for", [ + Tx.contractCall("multisig-crp-usda-wbtc", "vote-for", [ types.principal(token), types.uint(proposalID), types.uint(amount) @@ -157,7 +159,7 @@ voteFor(contractCaller: Account, token: string, proposalID: number, amount: numb voteAgainst(contractCaller: Account, token: string, proposalID: number, amount: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-crp-wbtc-59760-usda", "vote-against", [ + Tx.contractCall("multisig-crp-usda-wbtc", "vote-against", [ types.principal(token), types.uint(proposalID), types.uint(amount) @@ -168,11 +170,67 @@ voteAgainst(contractCaller: Account, token: string, proposalID: number, amount: endProposal(proposalID: number) { let block = this.chain.mineBlock([ - Tx.contractCall("multisig-crp-wbtc-59760-usda", "end-proposal", [ + Tx.contractCall("multisig-crp-usda-wbtc", "end-proposal", [ types.uint(proposalID), ], this.deployer.address), ]); return block.receipts[0].result; } } -export { MS_CRP_WBTC_USDA_59760 }; \ No newline at end of file +export { MS_CRP_USDA_WBTC }; + +class MS_CRP_WBTC_USDA { + chain: Chain; + deployer: Account; + + constructor(chain: Chain, deployer: Account) { + this.chain = chain; + this.deployer = deployer; + } + + propose(contractCaller: Account, expiry: number, startBlockHeight: number, proposeTitle: string, proposeURL: string, feeRateX: number, feeRateY: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("multisig-crp-wbtc-usda", "propose", [ + types.uint(expiry), + types.uint(startBlockHeight), + types.utf8(proposeTitle), + types.utf8(proposeURL), + types.uint(feeRateX), + types.uint(feeRateY), + ], contractCaller.address), + ]); + return block.receipts[0].result; + } + + voteFor(contractCaller: Account, token: string, proposalID: number, amount: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("multisig-crp-wbtc-usda", "vote-for", [ + types.principal(token), + types.uint(proposalID), + types.uint(amount) + ], contractCaller.address), + ]); + return block.receipts[0].result; + } + + voteAgainst(contractCaller: Account, token: string, proposalID: number, amount: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("multisig-crp-wbtc-usda", "vote-against", [ + types.principal(token), + types.uint(proposalID), + types.uint(amount) + ], contractCaller.address), + ]); + return block.receipts[0].result; + } + + endProposal(proposalID: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("multisig-crp-wbtc-usda", "end-proposal", [ + types.uint(proposalID), + ], this.deployer.address), + ]); + return block.receipts[0].result; + } + } + export { MS_CRP_WBTC_USDA }; \ No newline at end of file diff --git a/clarity/tests/models/alex-tests-tokens.ts b/clarity/tests/models/alex-tests-tokens.ts index 05981538..c3c9d8d0 100644 --- a/clarity/tests/models/alex-tests-tokens.ts +++ b/clarity/tests/models/alex-tests-tokens.ts @@ -7,6 +7,60 @@ import { } from "https://deno.land/x/clarinet@v0.13.0/index.ts"; +class ALEXToken { + chain: Chain; + deployer: Account; + + constructor(chain: Chain, deployer: Account) { + this.chain = chain; + this.deployer = deployer; + } + + balanceOf(wallet: string) { + return this.chain.callReadOnlyFn("token-alex", "get-balance-fixed", [ + types.principal(wallet), + ], this.deployer.address); + } + + getBalance(account: string) { + return this.chain.callReadOnlyFn("token-alex", "get-balance", [ + types.principal(account), + ], this.deployer.address); + } + + // Always need to called by deployer + mint(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-alex", "mint", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + mintFixed(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-alex", "mint-fixed", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + transferToken(amount: number, sender: string, receiver: string, memo:ArrayBuffer) { + let block = this.chain.mineBlock([ + Tx.contractCall("token-alex", "transfer-fixed", [ + types.uint(amount), + types.principal(sender), + types.principal(receiver), + types.some(types.buff(memo)) + ], this.deployer.address), + ]); + return block.receipts[0].result; + } + + totalSupply() { + return this.chain.callReadOnlyFn("token-alex", "get-total-supply-fixed", [], this.deployer.address); + } +} +export { ALEXToken }; + class USDAToken { chain: Chain; deployer: Account; @@ -17,14 +71,35 @@ class USDAToken { } balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("token-usda", "get-balance", [ + return this.chain.callReadOnlyFn("token-usda", "get-balance-fixed", [ types.principal(wallet), ], this.deployer.address); } + getBalance(account: string) { + return this.chain.callReadOnlyFn("token-usda", "get-balance", [ + types.principal(account), + ], this.deployer.address); + } + + // Always need to called by deployer + mint(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-usda", "mint", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + mintFixed(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-usda", "mint-fixed", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + transferToken(amount: number, sender: string, receiver: string, memo:ArrayBuffer) { let block = this.chain.mineBlock([ - Tx.contractCall("token-usda", "transfer", [ + Tx.contractCall("token-usda", "transfer-fixed", [ types.uint(amount), types.principal(sender), types.principal(receiver), @@ -36,7 +111,7 @@ class USDAToken { totalSupply() { - return this.chain.callReadOnlyFn("token-usda", "get-total-supply", [], this.deployer.address); + return this.chain.callReadOnlyFn("token-usda", "get-total-supply-fixed", [], this.deployer.address); } } export { USDAToken }; @@ -52,14 +127,35 @@ class WBTCToken { } balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("token-wbtc", "get-balance", [ + return this.chain.callReadOnlyFn("token-wbtc", "get-balance-fixed", [ types.principal(wallet), ], this.deployer.address); } + + getBalance(account: string) { + return this.chain.callReadOnlyFn("token-wbtc", "get-balance", [ + types.principal(account), + ], this.deployer.address); + } + + // Always need to called by deployer + mint(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-wbtc", "mint", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + mintFixed(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-wbtc", "mint-fixed", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } transferToken(amount: number, sender: string, receiver: string, memo:ArrayBuffer) { let block = this.chain.mineBlock([ - Tx.contractCall("token-wbtc", "transfer", [ + Tx.contractCall("token-wbtc", "transfer-fixed", [ types.uint(amount), types.principal(sender), types.principal(receiver), @@ -70,14 +166,12 @@ class WBTCToken { } totalSupply() { - return this.chain.callReadOnlyFn("token-wbtc", "get-total-supply", [], this.deployer.address); + return this.chain.callReadOnlyFn("token-wbtc", "get-total-supply-fixed", [], this.deployer.address); } } export { WBTCToken }; - - -class POOLTOKEN_FWP_WBTC_USDA_5050 { +class WSTXToken { chain: Chain; deployer: Account; @@ -87,18 +181,52 @@ class POOLTOKEN_FWP_WBTC_USDA_5050 { } balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("fwp-wbtc-usda-50-50", "get-balance", [ + return this.chain.callReadOnlyFn("token-wstx", "get-balance-fixed", [ types.principal(wallet), ], this.deployer.address); } + + getBalance(account: string) { + return this.chain.callReadOnlyFn("token-wstx", "get-balance", [ + types.principal(account), + ], this.deployer.address); + } + + // Always need to called by deployer + mint(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-wstx", "mint", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + mintFixed(recipient: string, amount : number) { + return this.chain.callReadOnlyFn("token-wstx", "mint-fixed", [ + types.uint(amount), + types.principal(recipient), + ], this.deployer.address); + } + + transferToken(amount: number, sender: string, receiver: string, memo:ArrayBuffer) { + let block = this.chain.mineBlock([ + Tx.contractCall("token-wstx", "transfer-fixed", [ + types.uint(amount), + types.principal(sender), + types.principal(receiver), + types.some(types.buff(memo)) + ], this.deployer.address), + ]); + return block.receipts[0].result; + } + totalSupply() { - return this.chain.callReadOnlyFn("fwp-wbtc-usda-50-50", "get-total-supply", [], this.deployer.address); + return this.chain.callReadOnlyFn("token-wstx", "get-total-supply-fixed", [], this.deployer.address); } } -export { POOLTOKEN_FWP_WBTC_USDA_5050 }; +export { WSTXToken }; -class POOLTOKEN_YTP_WBTC_WBTC_59760 { +class FWP_WBTC_USDA_5050 { chain: Chain; deployer: Account; @@ -108,18 +236,18 @@ class POOLTOKEN_YTP_WBTC_WBTC_59760 { } balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("ytp-yield-wbtc-59760-wbtc", "get-balance", [ + return this.chain.callReadOnlyFn("fwp-wbtc-usda-50-50", "get-balance-fixed", [ types.principal(wallet), ], this.deployer.address); } totalSupply() { - return this.chain.callReadOnlyFn("ytp-yield-wbtc-59760-wbtc", "get-total-supply", [], this.deployer.address); + return this.chain.callReadOnlyFn("fwp-wbtc-usda-50-50", "get-total-supply-fixed", [], this.deployer.address); } } -export { POOLTOKEN_YTP_WBTC_WBTC_59760 }; +export { FWP_WBTC_USDA_5050 }; -class YIELD_WBTC_59760 { +class YTP_YIELD_WBTC { chain: Chain; deployer: Account; @@ -128,20 +256,45 @@ class YIELD_WBTC_59760 { this.deployer = deployer; } - balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("yield-wbtc-59760", "get-balance", [ - types.principal(wallet), + balanceOf(expiry: number, wallet: string) { + return this.chain.callReadOnlyFn("ytp-yield-wbtc", "get-balance-fixed", [ + types.uint(expiry), types.principal(wallet), ], this.deployer.address); } - totalSupply() { - return this.chain.callReadOnlyFn("yield-wbtc-59760", "get-total-supply", [], this.deployer.address); + totalSupply(expiry: number) { + return this.chain.callReadOnlyFn("ytp-yield-wbtc", "get-total-supply-fixed", [ + types.uint(expiry) + ], this.deployer.address); } +} +export { YTP_YIELD_WBTC }; +class KEY_USDA_WBTC { + chain: Chain; + deployer: Account; + + constructor(chain: Chain, deployer: Account) { + this.chain = chain; + this.deployer = deployer; + } + + balanceOf(expiry: number, wallet: string) { + return this.chain.callReadOnlyFn("key-usda-wbtc", "get-balance-fixed", [ + types.uint(expiry), + types.principal(wallet), + ], this.deployer.address); + } + + totalSupply(expiry: number) { + return this.chain.callReadOnlyFn("key-usda-wbtc", "get-total-supply-fixed", [ + types.uint(expiry) + ], this.deployer.address); + } } -export { YIELD_WBTC_59760 }; +export { KEY_USDA_WBTC }; -class KEY_WBTC_59760_USDA { +class KEY_WBTC_USDA { chain: Chain; deployer: Account; @@ -150,14 +303,51 @@ class KEY_WBTC_59760_USDA { this.deployer = deployer; } - balanceOf(wallet: string) { - return this.chain.callReadOnlyFn("key-wbtc-59760-usda", "get-balance", [ + balanceOf(expiry: number, wallet: string) { + return this.chain.callReadOnlyFn("key-wbtc-usda", "get-balance-fixed", [ + types.uint(expiry), types.principal(wallet), ], this.deployer.address); } - totalSupply() { - return this.chain.callReadOnlyFn("key-wbtc-59760-usda", "get-total-supply", [], this.deployer.address); + totalSupply(expiry: number) { + return this.chain.callReadOnlyFn("key-wbtc-usda", "get-total-supply-fixed", [ + types.uint(expiry) + ], this.deployer.address); + } +} +export { KEY_WBTC_USDA }; + +class YIELD_WBTC { + chain: Chain; + deployer: Account; + + constructor(chain: Chain, deployer: Account) { + this.chain = chain; + this.deployer = deployer; + } + + balanceOf(expiry: number, wallet: string) { + return this.chain.callReadOnlyFn("yield-wbtc", "get-balance-fixed", [ + types.uint(expiry), types.principal(wallet), + ], this.deployer.address); + } + + totalSupply(expiry: number) { + return this.chain.callReadOnlyFn("yield-wbtc", "get-total-supply-fixed", [ + types.uint(expiry) + ], this.deployer.address); + } + + mintFixed(expiry: number, amount: number, recipient: string) { + let block = this.chain.mineBlock([ + Tx.contractCall("yield-wbtc", "mint-fixed", [ + types.uint(expiry), + types.uint(amount), + types.principal(recipient) + ], this.deployer.address), + ]); + return block.receipts[0].result; } } -export { KEY_WBTC_59760_USDA }; +export { YIELD_WBTC }; diff --git a/clarity/tests/models/alex-tests-yield-token-pool.ts b/clarity/tests/models/alex-tests-yield-token-pool.ts index 556fd428..61eadabd 100644 --- a/clarity/tests/models/alex-tests-yield-token-pool.ts +++ b/clarity/tests/models/alex-tests-yield-token-pool.ts @@ -22,27 +22,31 @@ import { ], this.deployer.address); } - getYield(aytoken: string) { + getYield(expiry: number, aytoken: string) { return this.chain.callReadOnlyFn("yield-token-pool", "get-yield", [ + types.uint(expiry), types.principal(aytoken) ], this.deployer.address); } - getPrice(aytoken: string) { + getPrice(expiry: number, aytoken: string) { return this.chain.callReadOnlyFn("yield-token-pool", "get-price", [ + types.uint(expiry), types.principal(aytoken) ], this.deployer.address); } - getPoolDetails(aytoken: string) { + getPoolDetails(expiry: number, aytoken: string) { return this.chain.callReadOnlyFn("yield-token-pool", "get-pool-details", [ + types.uint(expiry), types.principal(aytoken) ], this.deployer.address); } - createPool(user: Account, aytoken: string, token: string, pooltoken: string, multiSig: string, dX: number, dY: number) { + createPool(user: Account, expiry: number, aytoken: string, token: string, pooltoken: string, multiSig: string, dX: number, dY: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "create-pool", [ + types.uint(expiry), types.principal(aytoken), types.principal(token), types.principal(pooltoken), @@ -54,10 +58,11 @@ import { return block.receipts[0].result; } - addToPosition(user: Account, aytoken: string, token: string, pooltoken: string, dX: number) { + addToPosition(user: Account, expiry: number, aytoken: string, token: string, pooltoken: string, dX: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "add-to-position", [ - types.principal(aytoken), + types.uint(expiry), + types.principal(aytoken), types.principal(token), types.principal(pooltoken), types.uint(dX), @@ -66,10 +71,11 @@ import { return block.receipts[0].result; } - buyAndAddToPosition(user: Account, aytoken: string, token: string, pooltoken: string, dX: number) { + buyAndAddToPosition(user: Account, expiry: number, aytoken: string, token: string, pooltoken: string, dX: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "buy-and-add-to-position", [ - types.principal(aytoken), + types.uint(expiry), + types.principal(aytoken), types.principal(token), types.principal(pooltoken), types.uint(dX), @@ -78,23 +84,24 @@ import { return block.receipts[0].result; } - rollPosition(user: Account, aytoken: string, token: string, pooltoken: string, percent: number, aytoken2: string, pooltoken2: string) { + rollPosition(user: Account, expiry: number, aytoken: string, token: string, pooltoken: string, percent: number, expiry_to_roll: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "roll-position", [ - types.principal(aytoken), + types.uint(expiry), + types.principal(aytoken), types.principal(token), types.principal(pooltoken), types.uint(percent), - types.principal(aytoken2), - types.principal(pooltoken2) + types.uint(expiry_to_roll) ], user.address), ]); return block.receipts[0].result; } - reducePosition(user: Account, aytoken: string, token: string, pooltoken: string, percent: number) { + reducePosition(user: Account, expiry: number, aytoken: string, token: string, pooltoken: string, percent: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "reduce-position", [ + types.uint(expiry), types.principal(aytoken), types.principal(token), types.principal(pooltoken), @@ -104,9 +111,10 @@ import { return block.receipts[0].result; } - swapXForY(user: Account, aytoken: string, token: string, dX: number, dy_min: number) { + swapXForY(user: Account, expiry: number, aytoken: string, token: string, dX: number, dy_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "swap-x-for-y", [ + types.uint(expiry), types.principal(aytoken), types.principal(token), types.uint(dX), @@ -116,10 +124,11 @@ import { return block.receipts[0].result; } - swapYForX(user: Account, aytoken: string, token: string, dY: number, dx_min: number) { + swapYForX(user: Account, expiry: number, aytoken: string, token: string, dY: number, dx_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "swap-y-for-x", [ - types.principal(aytoken), + types.uint(expiry), + types.principal(aytoken), types.principal(token), types.uint(dY), types.some(types.uint(dx_min)) @@ -128,70 +137,79 @@ import { return block.receipts[0].result; } - getYgivenX(aytoken: string, dx: number) { + getYgivenX(expiry: number, aytoken: string, dx: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-y-given-x", [ + types.uint(expiry), types.principal(aytoken), types.uint(dx) ], this.deployer.address); } - getXgivenY(aytoken: string, dy: number) { + getXgivenY(expiry: number, aytoken: string, dy: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-x-given-y", [ + types.uint(expiry), types.principal(aytoken), types.uint(dy) ], this.deployer.address); } - getYgivenPrice(aytoken: string, price: number) { + getYgivenPrice(expiry: number, aytoken: string, price: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-y-given-price", [ + types.uint(expiry), types.principal(aytoken), types.uint(price) ], this.deployer.address); } - getXgivenPrice(aytoken: string, price: number) { + getXgivenPrice(expiry: number, aytoken: string, price: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-x-given-price", [ + types.uint(expiry), types.principal(aytoken), types.uint(price) ], this.deployer.address); } - getYgivenYield(aytoken: string, yied: number) { + getYgivenYield(expiry: number, aytoken: string, yied: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-y-given-yield", [ + types.uint(expiry), types.principal(aytoken), types.uint(yied) ], this.deployer.address); } - getXgivenYield(aytoken: string, yied: number) { + getXgivenYield(expiry: number, aytoken: string, yied: number) { return this.chain.callReadOnlyFn("yield-token-pool", "get-x-given-yield", [ + types.uint(expiry), types.principal(aytoken), types.uint(yied) ], this.deployer.address); } - getFeetoAddress(user: Account, aytoken: string) { + getFeetoAddress(user: Account, expiry: number, aytoken: string) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "get-fee-to-address", [ + types.uint(expiry), types.principal(aytoken) ], user.address), ]); return block.receipts[0].result; } - collectFees(user: Account, aytoken: string, token: string) { + collectFees(user: Account, expiry: number, aytoken: string, token: string) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "collect-fees", [ - types.principal(aytoken), + types.uint(expiry), + types.principal(aytoken), types.principal(token), ], user.address), ]); return block.receipts[0].result; } - setFeeRateToken(user: Account, aytoken: string, feerate:number) { + setFeeRateToken(user: Account, expiry: number, aytoken: string, feerate:number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "set-fee-rate-token", [ + types.uint(expiry), types.principal(aytoken), types.uint(feerate) ], user.address), @@ -199,9 +217,10 @@ import { return block.receipts[0].result; } - setFeeRateayToken(user: Account, aytoken: string, feerate:number) { + setFeeRateayToken(user: Account, expiry: number, aytoken: string, feerate:number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "set-fee-rate-aytoken", [ + types.uint(expiry), types.principal(aytoken), types.uint(feerate) ], user.address), @@ -209,27 +228,30 @@ import { return block.receipts[0].result; } - getFeeRateToken(user: Account, aytoken: string) { + getFeeRateToken(user: Account, expiry: number, aytoken: string) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "get-fee-rate-token", [ + types.uint(expiry), types.principal(aytoken) ], user.address), ]); return block.receipts[0].result; } - getFeeRateayToken(user: Account, aytoken: string) { + getFeeRateayToken(user: Account, expiry: number, aytoken: string) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "get-fee-rate-aytoken", [ + types.uint(expiry), types.principal(aytoken) ], user.address), ]); return block.receipts[0].result; } - setFeeRebate(user: Account, aytoken: string, rebate : number) { + setFeeRebate(user: Account, expiry: number, aytoken: string, rebate : number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "set-fee-rebate", [ + types.uint(expiry), types.principal(aytoken), types.uint(rebate) ], user.address), @@ -237,8 +259,9 @@ import { return block.receipts[0].result; } - getFeeRebate(aytoken: string) { + getFeeRebate(expiry: number, aytoken: string) { return this.chain.callReadOnlyFn("yield-token-pool", "get-fee-rebate", [ + types.uint(expiry), types.principal(aytoken), ], this.deployer.address); } diff --git a/clarity/tests/token-alex-src/token-client.ts b/clarity/tests/token-alex-src/token-client.ts index 18b4fbcd..a83f80b3 100644 --- a/clarity/tests/token-alex-src/token-client.ts +++ b/clarity/tests/token-alex-src/token-client.ts @@ -24,7 +24,7 @@ export class TokenClient extends Client { return Tx.contractCall( this.contractName, - "transfer", + "transfer-fixed", [ types.uint(amount), types.principal(from.address), @@ -38,7 +38,7 @@ export class TokenClient extends Client { burn(amount: number, sender: Account): Tx { return Tx.contractCall( this.contractName, - "burn", + "burn-fixed", [types.uint(amount), types.principal(sender.address)], sender.address ); @@ -92,8 +92,8 @@ export class TokenClient extends Client { mint(amount: number, recipient: Account, sender: Account): Tx { return Tx.contractCall( this.contractName, - "mint", - [types.principal(recipient.address), types.uint(amount)], + "mint-fixed", + [types.uint(amount), types.principal(recipient.address)], sender.address ); } diff --git a/clarity/tests/yield-token-pool_test.ts b/clarity/tests/yield-token-pool_test.ts index 5ea3f416..f253e0e1 100644 --- a/clarity/tests/yield-token-pool_test.ts +++ b/clarity/tests/yield-token-pool_test.ts @@ -3,33 +3,24 @@ import { Clarinet, Tx, Chain, Account, types } from 'https://deno.land/x/clarinet@v0.14.0/index.ts'; import { assertEquals } from 'https://deno.land/std@0.90.0/testing/asserts.ts'; -import { - YTPTestAgent1, - } from './models/alex-tests-yield-token-pool.ts'; +import { YTPTestAgent1, } from './models/alex-tests-yield-token-pool.ts'; -import { - MS_YTP_WBT_59760, -} from './models/alex-tests-multisigs.ts'; +import { MS_YTP_YIELD_WBTC } from './models/alex-tests-multisigs.ts'; -import { - USDAToken, - WBTCToken, - POOLTOKEN_YTP_WBTC_WBTC_59760 - } from './models/alex-tests-tokens.ts'; +import { USDAToken, WBTCToken, YIELD_WBTC, YTP_YIELD_WBTC } from './models/alex-tests-tokens.ts'; // Deployer Address Constants const wbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-wbtc" -const yieldwbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc-59760" -const ytpyieldwbtc59760Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc-59760-wbtc" -const multisigytpyieldwbtc59760 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc-59760-wbtc" -const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda-23040-usda" -const yieldwbtc80875Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc-80875" -const ytpyieldwbtc80875Address = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc-80875-wbtc" -const multisigytpyieldwbtc80875 = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc-80875-wbtc" +const yieldwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.yield-wbtc" +const ytpyieldwbtcAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-wbtc" +const multisigytpyieldwbtc = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-ytp-yield-wbtc" +const wrongPooltokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.ytp-yield-usda" const ONE_8 = 100000000 const expiry = 59760 * ONE_8 +const wrongExpiry = 70000 * ONE_8 +const anotherExpiry = 80875 * ONE_8 /** * Yield Token Pool Test Cases @@ -37,18 +28,27 @@ const expiry = 59760 * ONE_8 */ Clarinet.test({ - name: "YTP : Pool creation, adding values and reducing values", + name: "YTP : pool creation, adding values and reducing values", async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let YTPTest = new YTPTestAgent1(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 10000 * ONE_8, deployer.address); + result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); @@ -57,7 +57,7 @@ Clarinet.test({ let listed = 100000000; //Add extra liquidity - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 10*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 10*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(10*ONE_8); position['balance-token'].expectUint(10*ONE_8); @@ -65,7 +65,7 @@ Clarinet.test({ position['balance-virtual'].expectUint(10*ONE_8); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(1010*ONE_8); position['balance-token'].expectUint(1010*ONE_8); @@ -73,13 +73,13 @@ Clarinet.test({ position['balance-virtual'].expectUint(1010*ONE_8); // Remove all liquidlity - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, ONE_8); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, ONE_8); position =result.expectOk().expectTuple(); position['dx'].expectUint(1010*ONE_8); position['dy'].expectUint(0); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(0); position['balance-token'].expectUint(0); @@ -87,7 +87,7 @@ Clarinet.test({ position['balance-virtual'].expectUint(0); // Add back some liquidity - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 1000*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 1000*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(1000*ONE_8); position['balance-token'].expectUint(1000*ONE_8); @@ -99,76 +99,76 @@ Clarinet.test({ [types.uint(expiry), types.uint(listed) ], deployer.address); - call.result.expectOk().expectUint(710557) + call.result.expectOk().expectUint(710545) // zero actual yield-token, so must throw an error - call = await YTPTest.getYgivenX(yieldwbtc59760Address, 1*ONE_8); + call = await YTPTest.getYgivenX(expiry, yieldwbtcAddress, 1*ONE_8); call.result.expectErr().expectUint(2016) // zero actual yield-token, so yield must be zero call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(5) // zero rate environment, so yield-token and token are at parity. - call = await YTPTest.getXgivenY(yieldwbtc59760Address, 2*ONE_8); - call.result.expectOk().expectUint(199975237) + call = await YTPTest.getXgivenY(expiry, yieldwbtcAddress, 2*ONE_8); + call.result.expectOk().expectUint(199970398) // sell some yield-token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 2*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 2*ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(199975237); + position['dx'].expectUint(199970398); position['dy'].expectUint(2*ONE_8); // yield-token now has "actual" balance call = chain.callReadOnlyFn("yield-token-pool", "get-pool-details", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); position = call.result.expectOk().expectTuple(); - position['balance-token'].expectUint(99800024763); + position['balance-token'].expectUint(99800029602); position['balance-yield-token'].expectUint(2*ONE_8); position['balance-virtual'].expectUint(1000*ONE_8); // now that yield token supply > token supply, yield is positive. call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(2847); // buy back some yield token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, ONE_8, 0); position = result.expectOk().expectTuple() position['dx'].expectUint(ONE_8); position['dy'].expectUint(100028858); // attempt to sell more than max allowed yield token (50% of pool) must throw an error - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 501*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 501*ONE_8, 0); position =result.expectErr().expectUint(4002) call = chain.callReadOnlyFn("yield-token-pool", "get-pool-details", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); position = call.result.expectOk().expectTuple(); - position['balance-token'].expectUint(99900024763); + position['balance-token'].expectUint(99900029602); position['balance-yield-token'].expectUint(99971142); position['balance-virtual'].expectUint(1000*ONE_8); // after buying back some yield token, yield decreases. call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(1426); // we sell close to maximum allowed of yield token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 29*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 29*ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(2900524394); + position['dx'].expectUint(2900525361); position['dy'].expectUint(29*ONE_8); // which moves yield substantially into the positive territory. call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(42661); @@ -184,68 +184,73 @@ Clarinet.test({ // about half way, so yield should halve, just like zero coupon bond gets closer to par call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(21334); // sell some (a lot of) yield-token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 100*ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(10001386469); + position['dx'].expectUint(10001387748); position['dy'].expectUint(100*ONE_8); // and see how it pushes the yield pretty high call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(92959); //buy back some yield token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 100*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(100*ONE_8); position['dy'].expectUint(10005727560); - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(100000000000); - call = chain.callReadOnlyFn(ytpyieldwbtc59760Address, "get-balance", - [types.principal(deployer.address) + call = chain.callReadOnlyFn(ytpyieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) ], deployer.address); call.result.expectOk().expectUint(100000000000); // Remove some liquidlity - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 0.5*ONE_8); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 0.5*ONE_8); position = result.expectOk().expectTuple(); - position['dx'].expectUint(48499056950); + position['dx'].expectUint(48499058246); position['dy'].expectUint(1497121749); - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(50000000000); - call = chain.callReadOnlyFn(ytpyieldwbtc59760Address, "get-balance", - [types.principal(deployer.address) + call = chain.callReadOnlyFn(ytpyieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) ], deployer.address); - call.result.expectOk().expectUint(50000000000); + call.result.expectOk().expectUint(50000000000); + + call = chain.callReadOnlyFn(yieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) + ], deployer.address); + call.result.expectOk().expectUint(998502878167); // Add back some liquidity - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 1000*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 1000*ONE_8); position = result.expectOk().expectTuple(); - position['supply'].expectUint(103094788000); + position['supply'].expectUint(103094785000); position['balance-token'].expectUint(1000*ONE_8); - position['balance-yield-token'].expectUint(3086908988); - position['balance-virtual'].expectUint(103094788085); + position['balance-yield-token'].expectUint(3086908898); + position['balance-virtual'].expectUint(103094785085); - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); - position['total-supply'].expectUint(50000000000 + 103094788000); + position['total-supply'].expectUint(50000000000 + 103094785000); - call = chain.callReadOnlyFn(ytpyieldwbtc59760Address, "get-balance", - [types.principal(deployer.address) + call = chain.callReadOnlyFn(ytpyieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) ], deployer.address); - call.result.expectOk().expectUint(50000000000 + 103094788000); + call.result.expectOk().expectUint(50000000000 + 103094785000); // simulate to right before expiry chain.mineEmptyBlockUntil((expiry / ONE_8) - 1); @@ -259,19 +264,19 @@ Clarinet.test({ // nearly maturity, so yield should be close to zero. call = chain.callReadOnlyFn("yield-token-pool", "get-yield", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(5); // buy some yield-token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 19*ONE_8, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 19*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(19*ONE_8); - position['dy'].expectUint(1900033901); + position['dy'].expectUint(1900033809); // on expiry, the prices are back to parity. call = chain.callReadOnlyFn("yield-token-pool", "get-price", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(100000005); // par @@ -280,65 +285,69 @@ Clarinet.test({ // on expiry, the prices are back to parity. call = chain.callReadOnlyFn("yield-token-pool", "get-price", - [types.principal(yieldwbtc59760Address) + [types.uint(expiry), types.principal(yieldwbtcAddress) ], deployer.address); call.result.expectOk().expectUint(100000005); // par // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); - position['total-supply'].expectUint(153094788000); - position['balance-token'].expectUint(150399056950); - position['balance-yield-token'].expectUint(2683996920); - position['balance-virtual'].expectUint(153094788043); + position['total-supply'].expectUint(153094785000); + position['balance-token'].expectUint(150399058247); + position['balance-yield-token'].expectUint(2683996922); + position['balance-virtual'].expectUint(153094785043); - call = chain.callReadOnlyFn(ytpyieldwbtc59760Address, "get-balance", - [types.principal(deployer.address) + call = chain.callReadOnlyFn(ytpyieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) ], deployer.address); - call.result.expectOk().expectUint(153094788000); + call.result.expectOk().expectUint(153094785000); // Remove all liquidlity - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, ONE_8); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, ONE_8); position =result.expectOk().expectTuple(); - position['dx'].expectUint(150399056950); - position['dy'].expectUint(2683996806); + position['dx'].expectUint(150399058247); + position['dy'].expectUint(2683996755); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(0); position['balance-token'].expectUint(0); - position['balance-yield-token'].expectUint(114); + position['balance-yield-token'].expectUint(167); position['balance-virtual'].expectUint(0); }, }); Clarinet.test({ - name: "YTP : Trait check", + name: "YTP : trait check", async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; let wallet_1 = accounts.get("wallet_1")!; let YTPTest = new YTPTestAgent1(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) //if non-deployer attempts to create a pool, throw an error. - let result = YTPTest.createPool(wallet_1, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + let result = YTPTest.createPool(wallet_1, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectErr().expectUint(1000); //Deployer creating a pool, initial tokens injected to the pool - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); //if wrong pool token is supplied, then throw an error - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, wrongPooltokenAddress, 10*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, wrongPooltokenAddress, 10*ONE_8); result.expectErr().expectUint(2023); // non-deployer can add liquidity - result = YTPTest.addToPosition(wallet_1, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 10*ONE_8); + result = YTPTest.addToPosition(wallet_1, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 10*ONE_8); result.expectOk(); //if wrong pool token is supplied, throw an error - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, wrongPooltokenAddress, ONE_8); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, wrongPooltokenAddress, ONE_8); result.expectErr().expectUint(2023); } @@ -349,65 +358,83 @@ Clarinet.test({ async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let YTPTest = new YTPTestAgent1(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 10000 * ONE_8, deployer.address); + result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(1000*ONE_8); - call = await YTPTest.getYield(yieldwbtc59760Address); + call = await YTPTest.getYield(expiry, yieldwbtcAddress); call.result.expectOk().expectUint(5); // if current yield < target yield, then supply of yield-token needs to increase - call = await YTPTest.getXgivenYield(yieldwbtc59760Address, 0.001*ONE_8); + call = await YTPTest.getXgivenYield(expiry, yieldwbtcAddress, 0.001*ONE_8); call.result.expectErr().expectUint(2002); - call = await YTPTest.getYgivenYield(yieldwbtc59760Address, 0.001*ONE_8); - call.result.expectOk().expectUint(7019668000); + call = await YTPTest.getYgivenYield(expiry, yieldwbtcAddress, 0.001*ONE_8); + call.result.expectOk().expectUint(7019786000); - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 7019668000, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 7019786000, 0); position = result.expectOk().expectTuple(); - position['dy'].expectUint(7019668000); - position['dx'].expectUint(7023140005); + position['dy'].expectUint(7019786000); + position['dx'].expectUint(7023258477); - call = await YTPTest.getYield(yieldwbtc59760Address); + call = await YTPTest.getYield(expiry, yieldwbtcAddress); call.result.expectOk().expectUint(100006); // now let's try to reduce the yield - call = await YTPTest.getYgivenYield(yieldwbtc59760Address, 0.0005*ONE_8); + call = await YTPTest.getYgivenYield(expiry, yieldwbtcAddress, 0.0005*ONE_8); call.result.expectErr().expectUint(2002); - call = await YTPTest.getXgivenYield(yieldwbtc59760Address, 0.0005*ONE_8); - call.result.expectOk().expectUint(3504368516); + call = await YTPTest.getXgivenYield(expiry, yieldwbtcAddress, 0.0005*ONE_8); + call.result.expectOk().expectUint(3504433783); - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 3504368516, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 3504433783, 0); position = result.expectOk().expectTuple(); - position['dy'].expectUint(3507017732); - position['dx'].expectUint(3504368516); + position['dy'].expectUint(3507080102); + position['dx'].expectUint(3504433783); - call = await YTPTest.getYield(yieldwbtc59760Address); + call = await YTPTest.getYield(expiry, yieldwbtcAddress); call.result.expectOk().expectUint(50003); }, }); Clarinet.test({ - name: "YTP : Fee Setting using Multisig ", + name: "YTP : fee setting using multisig ", async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let wallet_2 = accounts.get("wallet_2")!; let contractOwner = accounts.get("deployer")!; let YTPTest = new YTPTestAgent1(chain, deployer); - let MultiSigTest = new MS_YTP_WBT_59760(chain, deployer); - let ytpPoolToken = new POOLTOKEN_YTP_WBTC_WBTC_59760(chain, deployer); + let MultiSigTest = new MS_YTP_YIELD_WBTC(chain, deployer); + let ytpPoolToken = new YTP_YIELD_WBTC(chain, deployer); let usdaToken = new USDAToken(chain, deployer); let wbtcToken = new WBTCToken(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 10000 * ONE_8, deployer.address); + result.expectOk().expectBool(true); + const buffer = new ArrayBuffer(34) const feeRateX = 0.1*ONE_8; // 10% const feeRateY = 0.1*ONE_8; @@ -418,57 +445,71 @@ Clarinet.test({ money.expectOk() //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(1000*ONE_8); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(1000*ONE_8); - result = YTPTest.addToPosition(wallet_2, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 10*ONE_8); + result = YTPTest.addToPosition(wallet_2, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 10*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(10*ONE_8); position['balance-token'].expectUint(10*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(10*ONE_8); - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8, 0); + call = chain.callReadOnlyFn(yieldwbtcAddress, "get-balance-fixed", + [types.uint(expiry), types.principal(deployer.address) + ], deployer.address); + call.result.expectOk().expectUint(1000000000000); + call = chain.callReadOnlyFn(wbtcAddress, "get-balance-fixed", + [types.principal(deployer.address) + ], deployer.address); + call.result.expectOk().expectUint(899000000000); //1899000000000 + call = chain.callReadOnlyFn(wbtcAddress, "get-balance-fixed", + [types.principal(deployer.address + ".alex-vault") + ], deployer.address); + call.result.expectOk().expectUint(101000000000); + + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(99972419); + position['dx'].expectUint(99970483); position['dy'].expectUint(ONE_8); - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); - position['balance-token'].expectUint(100900027581); // u99900045311 + position['balance-token'].expectUint(100900029517); position['balance-yield-token'].expectUint(ONE_8); position['balance-virtual'].expectUint(1010*ONE_8); - call = await ytpPoolToken.balanceOf(deployer.address); - call.result.expectOk().expectUint(100000000000); // u100000000000 + call = await ytpPoolToken.balanceOf(expiry, deployer.address); + call.result.expectOk().expectUint(1000*ONE_8); // u100000000000 - call = await ytpPoolToken.balanceOf(wallet_2.address); - call.result.expectOk().expectUint(1000000000); + call = await ytpPoolToken.balanceOf(expiry, wallet_2.address); + call.result.expectOk().expectUint(10*ONE_8); // Fee rate Setting Proposal of Multisig - result = MultiSigTest.propose(1000, " Fee Rate Setting to 10%", " https://docs.alexgo.io", feeRateX, feeRateY) + result = MultiSigTest.propose(expiry, 1000, " Fee Rate Setting to 10%", " https://docs.alexgo.io", feeRateX, feeRateY) result.expectOk().expectUint(1) // First Proposal // Block 1000 mining chain.mineEmptyBlock(1000); // Deployer has 99 % of pool token - let ROresult:any = ytpPoolToken.balanceOf(deployer.address); - ROresult.result.expectOk().expectUint(100000000000); + let ROresult:any = ytpPoolToken.balanceOf(expiry, deployer.address); + ROresult.result.expectOk().expectUint(1000*ONE_8); // Wallet_2 votes his 90% asset - result = MultiSigTest.voteFor(wallet_2, ytpyieldwbtc59760Address, 1, 1000000000 * 9 / 10 ) + result = MultiSigTest.voteFor(wallet_2, ytpyieldwbtcAddress, 1, 1000000000 * 9 / 10 ) result.expectOk().expectUint(900000000) // 90 % of existing tokens are voted for the proposal - result = MultiSigTest.voteFor(deployer, ytpyieldwbtc59760Address, 1, 100000000000 * 9 / 10 ) + result = MultiSigTest.voteFor(deployer, ytpyieldwbtcAddress, 1, 100000000000 * 9 / 10 ) result.expectOk().expectUint(90000000000) chain.mineEmptyBlock(1440); @@ -478,20 +519,20 @@ Clarinet.test({ result.expectOk().expectBool(true) // Success // deployer (Contract owner) sets rebate rate - result = YTPTest.setFeeRebate(contractOwner, yieldwbtc59760Address, feeRebate); + result = YTPTest.setFeeRebate(contractOwner, expiry, yieldwbtcAddress, feeRebate); result.expectOk().expectBool(true) // Fee checking - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['balance-yield-token'].expectUint(100000000); - position['balance-token'].expectUint(100900027581); + position['balance-token'].expectUint(100900029517); position['balance-virtual'].expectUint(101000000000); position['fee-rate-yield-token'].expectUint(0.1*ONE_8); position['fee-rate-token'].expectUint(0.1*ONE_8); position['fee-rebate'].expectUint(0.5*ONE_8); - call = await YTPTest.getYield(yieldwbtc59760Address); + call = await YTPTest.getYield(expiry, yieldwbtcAddress); call.result.expectOk().expectUint(1355); // fee-yield = yield * fee-rate-token = 1355 * 0.1*ONE_8 = 135 (round-down) // (contract-call? .math-fixed-point mul-down 1335 u10000000) @@ -501,30 +542,39 @@ Clarinet.test({ // fee-rebate = 270 * 0.5 = 135 // sell some yield-token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 2*ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 2*ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(199967096); + position['dx'].expectUint(199969031); position['dy'].expectUint(199999730); - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['balance-yield-token'].expectUint(100000000 + 199999730 + 135); //before + after + fee-rebate - position['balance-token'].expectUint(100900027581 - 199967096); + position['balance-token'].expectUint(100900029517 - 199969031); position['balance-virtual'].expectUint(101000000000); }, }); Clarinet.test({ - name: "YTP : Error Test Cases ", + name: "YTP : error test cases ", async fn(chain: Chain, accounts: Map) { let deployer = accounts.get("deployer")!; + let wallet_1 = accounts.get("wallet_1")!; let wallet_2 = accounts.get("wallet_2")!; let YTPTest = new YTPTestAgent1(chain, deployer); - let MultiSigTest = new MS_YTP_WBT_59760(chain, deployer); - let ytpPoolToken = new POOLTOKEN_YTP_WBTC_WBTC_59760(chain, deployer); + let MultiSigTest = new MS_YTP_YIELD_WBTC(chain, deployer); + let ytpPoolToken = new YTP_YIELD_WBTC(chain, deployer); let usdaToken = new USDAToken(chain, deployer); let wbtcToken = new WBTCToken(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 100 * ONE_8, deployer.address); + result.expectOk().expectBool(true); + const buffer = new ArrayBuffer(0) // Optional memo let money = usdaToken.transferToken(10*ONE_8,deployer.address,wallet_2.address, buffer); @@ -532,42 +582,42 @@ Clarinet.test({ money.expectOk() //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Duplicated Pool - result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectErr().expectUint(2000); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(1000*ONE_8); // Attempts to inject zero liquidity - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 0); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 0); position = result.expectErr().expectUint(2003) //Attempt to add extra liquidity but not enough balance - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 1000000*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 1000000*ONE_8); position = result.expectErr().expectUint(3001) // Attempts for trivial reducing - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 0); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 0); position =result.expectErr().expectUint(1) // Attempts for trivial reduce more than 100% - result = YTPTest.reducePosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 101*ONE_8); + result = YTPTest.reducePosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 101*ONE_8); position =result.expectErr().expectUint(5000) // Another user attempts to reduce liquidity with not enough pool token - result = YTPTest.reducePosition(wallet_2, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 1*ONE_8); + result = YTPTest.reducePosition(wallet_2, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 1*ONE_8); position =result.expectErr().expectUint(1) // Deployer adds liquidity - result = YTPTest.addToPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 1000*ONE_8); + result = YTPTest.addToPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 1000*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(1000*ONE_8); position['balance-token'].expectUint(1000*ONE_8); @@ -575,7 +625,7 @@ Clarinet.test({ position['balance-virtual'].expectUint(1000*ONE_8); // Another User adds liquidity - result = YTPTest.addToPosition(wallet_2, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 10*ONE_8); + result = YTPTest.addToPosition(wallet_2, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 10*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(10*ONE_8); position['balance-token'].expectUint(10*ONE_8); @@ -583,42 +633,42 @@ Clarinet.test({ position['balance-virtual'].expectUint(10*ONE_8); // Another user attempts to reduce liquidity with zero value - result = YTPTest.reducePosition(wallet_2, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 0); + result = YTPTest.reducePosition(wallet_2, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 0); position =result.expectErr().expectUint(1) // False swap value -- Filter added - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 0, 0); position =result.expectErr().expectUint(2003) // Too small => < max-slippage - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.0000001 * ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 0.0000001 * ONE_8, 0); position =result.expectErr().expectUint(2020); // Fixed - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.001 * ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 0.001 * ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(36251); + position['dx'].expectUint(40101); position['dy'].expectUint(0.001 * ONE_8); // Attempt for Swapping - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(99944571); + position['dx'].expectUint(99938798); position['dy'].expectUint(ONE_8); // Attempts for zero value swapping - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 0, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 0, 0); position =result.expectErr().expectUint(2003) // Attempts to swap more than available balance in the pool - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 100*ONE_8, 0); position =result.expectErr().expectUint(2016) // Swap - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 0.1 * ONE_8, 0); + result = YTPTest.swapXForY(deployer, expiry, yieldwbtcAddress, wbtcAddress, 0.1 * ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(0.1 * ONE_8); - position['dy'].expectUint(10043969); + position['dy'].expectUint(10047818); }, }); @@ -630,45 +680,53 @@ Clarinet.test({ let deployer = accounts.get("deployer")!; let wallet_1 = accounts.get("wallet_1")!; let YTPTest = new YTPTestAgent1(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 100 * ONE_8, deployer.address); + result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(1000*ONE_8); // inject some yield-token to pool - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 10 * ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 10 * ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(1000039937); + position['dx'].expectUint(1000040905); position['dy'].expectUint(10 * ONE_8); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(1000*ONE_8); - position['balance-token'].expectUint(1000*ONE_8 - 1000039937); + position['balance-token'].expectUint(1000*ONE_8 - 1000040905); position['balance-yield-token'].expectUint(10 * ONE_8); position['balance-virtual'].expectUint(1000*ONE_8); // make sure wallet_1 does not have any yield-token - call = chain.callReadOnlyFn(yieldwbtc59760Address, "get-balance", - [types.principal(wallet_1.address) + call = chain.callReadOnlyFn(yieldwbtcAddress, "get-balance", + [types.uint(expiry), types.principal(wallet_1.address) ], wallet_1.address); call.result.expectOk().expectUint(0); //Add extra liquidity with secondary buying of yield-token - result = YTPTest.buyAndAddToPosition(wallet_1, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 10*ONE_8); + result = YTPTest.buyAndAddToPosition(wallet_1, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 10*ONE_8); position = result.expectOk().expectTuple(); position['supply'].expectUint(909189000); position['balance-token'].expectUint(900997112); - position['balance-yield-token'].expectUint(8191445); - position['balance-virtual'].expectUint(909189002); + position['balance-yield-token'].expectUint(8191455); + position['balance-virtual'].expectUint(909189001); } }); @@ -679,70 +737,80 @@ Clarinet.test({ let deployer = accounts.get("deployer")!; let wallet_1 = accounts.get("wallet_1")!; let YTPTest = new YTPTestAgent1(chain, deployer); + let yieldWBTC = new YIELD_WBTC(chain, deployer); + let wbtcToken = new WBTCToken(chain, deployer); + + wbtcToken.mintFixed(deployer.address, 10000*ONE_8) + wbtcToken.mintFixed(wallet_1.address, 10000*ONE_8) + + let result = yieldWBTC.mintFixed(expiry, 100 * ONE_8, deployer.address); + result.expectOk().expectBool(true); + result = yieldWBTC.mintFixed(anotherExpiry, 100 * ONE_8, deployer.address); + result.expectOk().expectBool(true); //Deployer creating a pool, initial tokens injected to the pool - let result = YTPTest.createPool(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, multisigytpyieldwbtc59760, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // Check pool details and print - let call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + let call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); let position:any = call.result.expectOk().expectTuple(); position['balance-token'].expectUint(1000*ONE_8); position['balance-yield-token'].expectUint(0); position['balance-virtual'].expectUint(1000*ONE_8); // inject some yield-token to pool - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 10 * ONE_8, 0); + result = YTPTest.swapYForX(deployer, expiry, yieldwbtcAddress, wbtcAddress, 10 * ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(1000039937); + position['dx'].expectUint(1000041873); position['dy'].expectUint(10 * ONE_8); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc59760Address); + call = await YTPTest.getPoolDetails(expiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(1000*ONE_8); - position['balance-token'].expectUint(1000*ONE_8 - 1000039937); + position['balance-token'].expectUint(1000*ONE_8 - 1000041873); position['balance-yield-token'].expectUint(10 * ONE_8); position['balance-virtual'].expectUint(1000*ONE_8); // make sure wallet_1 does not have any yield-token - call = chain.callReadOnlyFn(yieldwbtc59760Address, "get-balance", - [types.principal(wallet_1.address) + call = chain.callReadOnlyFn(yieldwbtcAddress, "get-balance", + [types.uint(expiry), types.principal(wallet_1.address) ], wallet_1.address); call.result.expectOk().expectUint(0); // create another ytp - result = YTPTest.createPool(deployer, yieldwbtc80875Address, wbtcAddress, ytpyieldwbtc80875Address, multisigytpyieldwbtc80875, 1000*ONE_8, 1000*ONE_8); + result = YTPTest.createPool(deployer, anotherExpiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, multisigytpyieldwbtc, 1000*ONE_8, 1000*ONE_8); result.expectOk().expectBool(true); // inject some yield-token to pool - result = YTPTest.swapYForX(deployer, yieldwbtc80875Address, wbtcAddress, 10 * ONE_8, 0); + result = YTPTest.swapYForX(deployer, anotherExpiry, yieldwbtcAddress, wbtcAddress, 10 * ONE_8, 0); position =result.expectOk().expectTuple(); - position['dx'].expectUint(1000067035); + position['dx'].expectUint(1000068003); position['dy'].expectUint(10 * ONE_8); - call = await YTPTest.getPoolDetails(yieldwbtc80875Address); + call = await YTPTest.getPoolDetails(anotherExpiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); position['total-supply'].expectUint(1000*ONE_8); - position['balance-token'].expectUint(1000*ONE_8 - 1000067035); + position['balance-token'].expectUint(1000*ONE_8 - 1000068003); position['balance-yield-token'].expectUint(10 * ONE_8); position['balance-virtual'].expectUint(1000*ONE_8); //Add extra liquidity with secondary buying of yield-token - result = YTPTest.rollPosition(deployer, yieldwbtc59760Address, wbtcAddress, ytpyieldwbtc59760Address, 0.5*ONE_8, yieldwbtc80875Address, ytpyieldwbtc80875Address); + result = YTPTest.rollPosition(deployer, expiry, yieldwbtcAddress, wbtcAddress, ytpyieldwbtcAddress, 0.5*ONE_8, anotherExpiry); position = result.expectOk().expectTuple(); - position['supply'].expectUint(50354658000); - position['balance-token'].expectUint(49900929799); - position['balance-yield-token'].expectUint(453675742); - position['balance-virtual'].expectUint(50354658105); + position['supply'].expectUint(50354656000); + position['balance-token'].expectUint(49900926876); + position['balance-yield-token'].expectUint(453674699); + position['balance-virtual'].expectUint(50354656156); // Check pool details and print - call = await YTPTest.getPoolDetails(yieldwbtc80875Address); + call = await YTPTest.getPoolDetails(anotherExpiry, yieldwbtcAddress); position = call.result.expectOk().expectTuple(); - position['total-supply'].expectUint(1000*ONE_8 + 50354658000); - // a bit more than 148900862764 = 1000*ONE_8 - 1000067035 + 49900929799, due to buy-and-add-to-position - position['balance-token'].expectUint(148999862966); - // a bit less then 1453675742 = 0 + 10 * ONE_8 + 453675742, due to buy-and-add-to-position - position['balance-yield-token'].expectUint(1354636777); - position['balance-virtual'].expectUint(1000*ONE_8 + 50354658105); + position['total-supply'].expectUint(1000*ONE_8 + 50354656000); + // a bit more than 148900862764 = 1000*ONE_8 - 1000067035 + 49900926876, due to buy-and-add-to-position + position['balance-token'].expectUint(148999859079); + // a bit less then 1453675742 = 0 + 10 * ONE_8 + 453674699, due to buy-and-add-to-position + position['balance-yield-token'].expectUint(1354633799); + position['balance-virtual'].expectUint(1000*ONE_8 + 50354656156); } }); \ No newline at end of file diff --git a/init-js-tool/deploy.js b/init-js-tool/deploy.js index 36b11cd7..0e53e56a 100644 --- a/init-js-tool/deploy.js +++ b/init-js-tool/deploy.js @@ -51,7 +51,6 @@ let contract_paths = [ // "multisig/multisig-ytp-yield-usda-34560-usda.clar", // "flash-loan-user-margin-usda-wbtc-34560.clar", // "flash-loan-user-margin-wbtc-usda-34560.clar" - ] async function get_version(){ diff --git a/init-js-tool/index.js b/init-js-tool/index.js index 28b089f7..f7b13d33 100644 --- a/init-js-tool/index.js +++ b/init-js-tool/index.js @@ -15,7 +15,8 @@ const { fwpSwapYforX, fwpGetPoolDetails, fwpSetOracleAverage, - fwpSetOracleEnbled + fwpSetOracleEnbled, + fwpGetPositionGivenBurn } = require('./pools-fwp') const { crpCreate, @@ -726,8 +727,11 @@ async function run() { // await arbitrage_fwp(dry_run = false); // await mint_some_wbtc('ST32AK70FP7VNAD68KVDQF3K8XSFG99WKVEHVAPFA'); // await see_balance(process.env.USER_ACCOUNT_ADDRESS); - // result = await ytpGetPositionGivenBurn('yield-wbtc-200335', 625000000000, deployer=true); - // console.log(result); + + result = await fwpGetPositionGivenBurn('token-wbtc', 'token-usda', 0.5e8, 0.5e8, 325.48 * 1e3 * 1e8); + printResult(result); + result = await ytpGetPositionGivenBurn('yield-wbtc-92160', 0.5 * 1e8); + printResult(result); // result = await balance('key-usda-34560-wbtc', process.env.USER_ACCOUNT_ADDRESS); // console.log(result); diff --git a/init-js-tool/pools-fwp.js b/init-js-tool/pools-fwp.js index b1148f18..7a2884df 100644 --- a/init-js-tool/pools-fwp.js +++ b/init-js-tool/pools-fwp.js @@ -356,6 +356,32 @@ const fwpGetYGivenPrice = async (tokenX, tokenY, weightX, weightY, price) => { } }; +const fwpGetPositionGivenBurn = async (tokenX, tokenY, weightX, weightY, token) => { + console.log('--------------------------------------------------------------------------'); + console.log('[FWP] get-position-given-burn...', tokenX, tokenY, weightX, weightY, token); + + const options = { + contractAddress: process.env.DEPLOYER_ACCOUNT_ADDRESS, + contractName: 'fixed-weight-pool', + functionName: 'get-position-given-burn', + functionArgs: [ + contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, tokenX), + contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, tokenY), + uintCV(weightX), + uintCV(weightY), + uintCV(token) + ], + network: network, + senderAddress: process.env.USER_ACCOUNT_ADDRESS, + }; + try { + return callReadOnlyFunction(options); + + } catch (error) { + console.log(error); + } +}; + const fwpGetPoolDetails = async (tokenX, tokenY, weightX, weightY) => { console.log('--------------------------------------------------------------------------'); console.log('[FWP] get-pool-details...]', tokenX, tokenY, weightX, weightY); @@ -392,3 +418,4 @@ exports.fwpSwapXforY = fwpSwapXforY; exports.fwpSwapYforX = fwpSwapYforX; exports.fwpSetOracleEnbled = fwpSetOracleEnbled; exports.fwpSetOracleAverage = fwpSetOracleAverage; +exports.fwpGetPositionGivenBurn = fwpGetPositionGivenBurn;