diff --git a/clarity/Clarinet.toml b/clarity/Clarinet.toml index a5a9368d..bdd5437d 100644 --- a/clarity/Clarinet.toml +++ b/clarity/Clarinet.toml @@ -184,3 +184,11 @@ depends_on = ["ytp-yield-usda-23040-usda", "trait-yield-token", "trait-sip-010", [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.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"] + +[contracts.multisig-lbp-alex-usda-90-10] +path = "contracts/multisig/multisig-lbp-alex-usda-90-10.clar" +depends_on = [] diff --git a/clarity/contracts/alex-vault.clar b/clarity/contracts/alex-vault.clar index 8ce7ed58..becec40b 100644 --- a/clarity/contracts/alex-vault.clar +++ b/clarity/contracts/alex-vault.clar @@ -45,7 +45,6 @@ (ok (asserts! (default-to false (map-get? approved-contracts sender)) ERR-NOT-AUTHORIZED)) ) -;; TODO: multisig (define-public (set-flash-loan-fee-rate (fee uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) diff --git a/clarity/contracts/equations/weighted-equation.clar b/clarity/contracts/equations/weighted-equation.clar index e1627765..d0fd62d7 100644 --- a/clarity/contracts/equations/weighted-equation.clar +++ b/clarity/contracts/equations/weighted-equation.clar @@ -1,5 +1,5 @@ ;; weighted-equation -;; implementation of Balancer WeightedMath (https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/pool-weighted/contracts/WeightedMath.sol) +;; implementation of Balancer WeightedMath (https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/pool-weighted/contracts/WeightedMath.sol) ;; constants ;; @@ -77,7 +77,7 @@ ( (denominator (if (<= balance-y dy) u0 (- balance-y dy))) (base (div-down balance-y denominator)) - (uncapped-exponent (div-down weight-x weight-y)) + (uncapped-exponent (div-down weight-y weight-x)) (bound (unwrap-panic (get-exp-bound))) (exponent (if (< uncapped-exponent bound) uncapped-exponent bound)) (power (pow-down base exponent)) @@ -187,9 +187,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol - -;; TODO: overflow causes runtime error, should handle before operation rather than after +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; constants ;; @@ -279,7 +277,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/equations/yield-token-equation.clar b/clarity/contracts/equations/yield-token-equation.clar index b43aedf5..1e893252 100644 --- a/clarity/contracts/equations/yield-token-equation.clar +++ b/clarity/contracts/equations/yield-token-equation.clar @@ -213,7 +213,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; TODO: overflow causes runtime error, should handle before operation rather than after @@ -305,7 +305,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar similarity index 78% rename from clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar rename to clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar index fd9cd055..94bec467 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-34560.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-11520.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-34560 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-34560))) + (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-34560 .key-wbtc-34560-usda gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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 }) + (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 index 272972e6..096cac2c 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-121195.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-121195.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar index de6a36c7..afbf6cb5 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-161515.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar index c19f26a2..d3e1127e 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar index 61a646e4..6cd967ee 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-40555.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar similarity index 78% rename from clarity/contracts/flash-loan-user-margin-usda-wbtc-40555.clar rename to clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar index e0a110a4..2b1c4a7b 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-40555.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-51840.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-40555 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-40555))) + (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-40555 .key-wbtc-40555-usda gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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-40555", action: "execute", data: gross-amount }) + (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 index f1be6047..b2459e92 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar index dd910024..e5a05c08 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-usda-wbtc-5760.clar b/clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar similarity index 73% rename from clarity/contracts/flash-loan-user-margin-usda-wbtc-5760.clar rename to clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar index 4d314b77..7f3bea33 100644 --- a/clarity/contracts/flash-loan-user-margin-usda-wbtc-5760.clar +++ b/clarity/contracts/flash-loan-user-margin-usda-wbtc-92160.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-wbtc-5760 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-5760))) + (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-5760 .key-wbtc-5760-usda gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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-5760", action: "execute", data: gross-amount }) + (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-wbtc-usda-40555.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar similarity index 78% rename from clarity/contracts/flash-loan-user-margin-wbtc-usda-40555.clar rename to clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar index 7f67e614..2f02a734 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-40555.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-11520.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-40555 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-40555))) + (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-40555 .key-usda-40555-wbtc gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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-40555", action: "execute", data: gross-amount }) + (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 index 411b178b..748e8160 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-121195.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-121195.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar index 5d9eda17..42a6620a 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-161515.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar index 4c34f4a1..c9b6d214 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-23040.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar similarity index 78% rename from clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar rename to clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar index 8c618c9b..923f2059 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-34560.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-51840.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-34560 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-34560))) + (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-34560 .key-usda-34560-wbtc gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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 }) + (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 index eeae4ead..1ed8ea08 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-80875.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-80875.clar @@ -19,8 +19,8 @@ ) ;; 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)) + (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 }) diff --git a/clarity/contracts/flash-loan-user-margin-wbtc-usda-5760.clar b/clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar similarity index 73% rename from clarity/contracts/flash-loan-user-margin-wbtc-usda-5760.clar rename to clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar index 6bd8b660..d0a10f53 100644 --- a/clarity/contracts/flash-loan-user-margin-wbtc-usda-5760.clar +++ b/clarity/contracts/flash-loan-user-margin-wbtc-usda-92160.clar @@ -11,19 +11,19 @@ ( ;; gross amount * ltv / price = amount ;; gross amount = amount * price / ltv - (expiry (unwrap! (contract-call? .yield-usda-5760 get-expiry) ERR-GET-EXPIRY-FAIL-ERR)) + (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-5760))) + (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-5760 .key-usda-5760-wbtc gross-amount)))) + (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)) - (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda .token-wbtc u50000000 u50000000 swapped-token)) + (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-5760", action: "execute", data: gross-amount }) + (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/key-token/key-usda-34560-wbtc.clar b/clarity/contracts/key-token/key-usda-11520-wbtc.clar similarity index 83% rename from clarity/contracts/key-token/key-usda-34560-wbtc.clar rename to clarity/contracts/key-token/key-usda-11520-wbtc.clar index 5e68ca58..7c5bd59b 100644 --- a/clarity/contracts/key-token/key-usda-34560-wbtc.clar +++ b/clarity/contracts/key-token/key-usda-11520-wbtc.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-usda-34560-wbtc) +(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 u3456000000000) +(define-data-var token-expiry uint u1152000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-34560-wbtc))) + (ok (decimals-to-fixed (ft-get-supply key-usda-11520-wbtc))) ) (define-read-only (get-name) - (ok "key-usda-34560-wbtc") + (ok "key-usda-11520-wbtc") ) (define-read-only (get-symbol) - (ok "key-usda-34560-wbtc") + (ok "key-usda-11520-wbtc") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-34560-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance key-usda-11520-wbtc account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-usda-34560-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-usda-11520-wbtc (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (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) + (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-34560-wbtc (fixed-to-decimals amount) sender) + (ft-burn? key-usda-11520-wbtc (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/key-token/key-usda-40555-wbtc.clar b/clarity/contracts/key-token/key-usda-51840-wbtc.clar similarity index 83% rename from clarity/contracts/key-token/key-usda-40555-wbtc.clar rename to clarity/contracts/key-token/key-usda-51840-wbtc.clar index 07c6e9e4..f3df36ba 100644 --- a/clarity/contracts/key-token/key-usda-40555-wbtc.clar +++ b/clarity/contracts/key-token/key-usda-51840-wbtc.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-usda-40555-wbtc) +(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 u4055500000000) +(define-data-var token-expiry uint u5184000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-40555-wbtc))) + (ok (decimals-to-fixed (ft-get-supply key-usda-51840-wbtc))) ) (define-read-only (get-name) - (ok "key-usda-40555-wbtc") + (ok "key-usda-51840-wbtc") ) (define-read-only (get-symbol) - (ok "key-usda-40555-wbtc") + (ok "key-usda-51840-wbtc") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-40555-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance key-usda-51840-wbtc account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-usda-40555-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-usda-51840-wbtc (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-40555-wbtc (fixed-to-decimals amount) recipient) + (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-40555-wbtc (fixed-to-decimals amount) sender) + (ft-burn? key-usda-51840-wbtc (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/key-token/key-usda-5760-wbtc.clar b/clarity/contracts/key-token/key-usda-92160-wbtc.clar similarity index 81% rename from clarity/contracts/key-token/key-usda-5760-wbtc.clar rename to clarity/contracts/key-token/key-usda-92160-wbtc.clar index 7931c332..6a62781e 100644 --- a/clarity/contracts/key-token/key-usda-5760-wbtc.clar +++ b/clarity/contracts/key-token/key-usda-92160-wbtc.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-usda-5760-wbtc) +(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 u576000000000) +(define-data-var token-expiry uint u9216000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-usda-5760-wbtc))) + (ok (decimals-to-fixed (ft-get-supply key-usda-92160-wbtc))) ) (define-read-only (get-name) - (ok "key-usda-5760-wbtc") + (ok "key-usda-92160-wbtc") ) (define-read-only (get-symbol) - (ok "key-usda-5760-wbtc") + (ok "key-usda-92160-wbtc") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-usda-5760-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance key-usda-92160-wbtc account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-usda-5760-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-usda-92160-wbtc (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-usda-5760-wbtc (fixed-to-decimals amount) recipient) + (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-5760-wbtc (fixed-to-decimals amount) sender) + (ft-burn? key-usda-92160-wbtc (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/key-token/key-wbtc-40555-usda.clar b/clarity/contracts/key-token/key-wbtc-11520-usda.clar similarity index 83% rename from clarity/contracts/key-token/key-wbtc-40555-usda.clar rename to clarity/contracts/key-token/key-wbtc-11520-usda.clar index a3bb803b..8978a862 100644 --- a/clarity/contracts/key-token/key-wbtc-40555-usda.clar +++ b/clarity/contracts/key-token/key-wbtc-11520-usda.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-wbtc-40555-usda) +(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 u4055500000000) +(define-data-var token-expiry uint u1152000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-40555-usda))) + (ok (decimals-to-fixed (ft-get-supply key-wbtc-11520-usda))) ) (define-read-only (get-name) - (ok "key-wbtc-40555-usda") + (ok "key-wbtc-11520-usda") ) (define-read-only (get-symbol) - (ok "key-wbtc-40555-usda") + (ok "key-wbtc-11520-usda") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-40555-usda account))) + (ok (decimals-to-fixed (ft-get-balance key-wbtc-11520-usda account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-wbtc-40555-usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-wbtc-11520-usda (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-40555-usda (fixed-to-decimals amount) recipient) + (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-40555-usda (fixed-to-decimals amount) sender) + (ft-burn? key-wbtc-11520-usda (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/key-token/key-wbtc-34560-usda.clar b/clarity/contracts/key-token/key-wbtc-51840-usda.clar similarity index 83% rename from clarity/contracts/key-token/key-wbtc-34560-usda.clar rename to clarity/contracts/key-token/key-wbtc-51840-usda.clar index ff7ba9b1..b64da3ef 100644 --- a/clarity/contracts/key-token/key-wbtc-34560-usda.clar +++ b/clarity/contracts/key-token/key-wbtc-51840-usda.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-wbtc-34560-usda) +(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 u3456000000000) +(define-data-var token-expiry uint u5184000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-34560-usda))) + (ok (decimals-to-fixed (ft-get-supply key-wbtc-51840-usda))) ) (define-read-only (get-name) - (ok "key-wbtc-34560-usda") + (ok "key-wbtc-51840-usda") ) (define-read-only (get-symbol) - (ok "key-wbtc-34560-usda") + (ok "key-wbtc-51840-usda") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-34560-usda account))) + (ok (decimals-to-fixed (ft-get-balance key-wbtc-51840-usda account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-wbtc-34560-usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-wbtc-51840-usda (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (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) + (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-34560-usda (fixed-to-decimals amount) sender) + (ft-burn? key-wbtc-51840-usda (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/key-token/key-wbtc-5760-usda.clar b/clarity/contracts/key-token/key-wbtc-92160-usda.clar similarity index 81% rename from clarity/contracts/key-token/key-wbtc-5760-usda.clar rename to clarity/contracts/key-token/key-wbtc-92160-usda.clar index d76dba3a..b670a5a3 100644 --- a/clarity/contracts/key-token/key-wbtc-5760-usda.clar +++ b/clarity/contracts/key-token/key-wbtc-92160-usda.clar @@ -1,11 +1,11 @@ (impl-trait .trait-yield-token.yield-token-trait) (impl-trait .trait-ownable.ownable-trait) -(define-fungible-token key-wbtc-5760-usda) +(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 u576000000000) +(define-data-var token-expiry uint u9216000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply key-wbtc-5760-usda))) + (ok (decimals-to-fixed (ft-get-supply key-wbtc-92160-usda))) ) (define-read-only (get-name) - (ok "key-wbtc-5760-usda") + (ok "key-wbtc-92160-usda") ) (define-read-only (get-symbol) - (ok "key-wbtc-5760-usda") + (ok "key-wbtc-92160-usda") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance key-wbtc-5760-usda account))) + (ok (decimals-to-fixed (ft-get-balance key-wbtc-92160-usda account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? key-wbtc-5760-usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? key-wbtc-92160-usda (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? key-wbtc-5760-usda (fixed-to-decimals amount) recipient) + (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-5760-usda (fixed-to-decimals amount) sender) + (ft-burn? key-wbtc-92160-usda (fixed-to-decimals amount) sender) ) ) diff --git a/clarity/contracts/lib/math-fixed-point.clar b/clarity/contracts/lib/math-fixed-point.clar index c619824d..90bd18c9 100644 --- a/clarity/contracts/lib/math-fixed-point.clar +++ b/clarity/contracts/lib/math-fixed-point.clar @@ -1,9 +1,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol - -;; TODO: overflow causes runtime error, should handle before operation rather than after +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; constants ;; diff --git a/clarity/contracts/lib/math-log-exp.clar b/clarity/contracts/lib/math-log-exp.clar index f8b48c8a..aa90ffcc 100644 --- a/clarity/contracts/lib/math-log-exp.clar +++ b/clarity/contracts/lib/math-log-exp.clar @@ -3,7 +3,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar rename to clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar index bc39e8b0..2c10a530 100644 --- a/clarity/contracts/multisig/multisig-crp-usda-34560-wbtc.clar +++ b/clarity/contracts/multisig/multisig-crp-usda-11520-wbtc.clar @@ -102,7 +102,7 @@ ;; 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)) + (or (is-eq (contract-of token) .yield-usda-11520) (is-eq (contract-of token) .key-usda-11520-wbtc)) ) @@ -118,11 +118,11 @@ ) (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-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-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-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)) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -221,8 +221,8 @@ (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-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)) @@ -269,8 +269,8 @@ (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)) + (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)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-crp-usda-40555-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-usda-40555-wbtc.clar rename to clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar index 984fa8ef..6f856cbd 100644 --- a/clarity/contracts/multisig/multisig-crp-usda-40555-wbtc.clar +++ b/clarity/contracts/multisig/multisig-crp-usda-51840-wbtc.clar @@ -102,7 +102,7 @@ ;; 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-40555) (is-eq (contract-of token) .key-usda-40555-wbtc)) + (or (is-eq (contract-of token) .yield-usda-51840) (is-eq (contract-of token) .key-usda-51840-wbtc)) ) @@ -118,11 +118,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-40555 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-40555-wbtc get-balance tx-sender))) + (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-40555 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-40555-wbtc get-total-supply))) + (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))) ) @@ -221,8 +221,8 @@ (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-40555 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-40555-wbtc get-total-supply))) + (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)) @@ -269,8 +269,8 @@ (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u4055500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u4055500000000 new-fee-rate-y)) + (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-5760-wbtc.clar b/clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-usda-5760-wbtc.clar rename to clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar index 5c5037aa..f163b5da 100644 --- a/clarity/contracts/multisig/multisig-crp-usda-5760-wbtc.clar +++ b/clarity/contracts/multisig/multisig-crp-usda-92160-wbtc.clar @@ -102,7 +102,7 @@ ;; 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-5760) (is-eq (contract-of token) .key-usda-5760-wbtc)) + (or (is-eq (contract-of token) .yield-usda-92160) (is-eq (contract-of token) .key-usda-92160-wbtc)) ) @@ -118,11 +118,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-usda-5760 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-usda-5760-wbtc get-balance tx-sender))) + (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-5760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-5760-wbtc get-total-supply))) + (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))) ) @@ -221,8 +221,8 @@ (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-5760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-usda-5760-wbtc get-total-supply))) + (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)) @@ -269,8 +269,8 @@ (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-usda .token-wbtc u576000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-usda .token-wbtc u576000000000 new-fee-rate-y)) + (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-wbtc-40555-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-wbtc-40555-usda.clar rename to clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar index ffa7b8bb..fe576151 100644 --- a/clarity/contracts/multisig/multisig-crp-wbtc-40555-usda.clar +++ b/clarity/contracts/multisig/multisig-crp-wbtc-11520-usda.clar @@ -102,7 +102,7 @@ ;; 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-40555) (is-eq (contract-of token) .key-wbtc-40555-usda)) + (or (is-eq (contract-of token) .yield-wbtc-11520) (is-eq (contract-of token) .key-wbtc-11520-usda)) ) @@ -118,11 +118,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-40555 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-40555-usda get-balance tx-sender))) + (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-balance (+ proposer-yield-balance proposer-key-balance)) - (total-yield-supply (unwrap-panic (contract-call? .yield-wbtc-40555 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-40555-usda get-total-supply))) + (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)) (proposal-id (+ u1 (var-get proposal-count))) ) @@ -221,8 +221,8 @@ (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-40555 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-40555-usda get-total-supply))) + (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)) @@ -269,8 +269,8 @@ (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u4055500000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u4055500000000 new-fee-rate-y)) + (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)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-crp-wbtc-5760-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-wbtc-5760-usda.clar rename to clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar index 9d086b16..e89b42cb 100644 --- a/clarity/contracts/multisig/multisig-crp-wbtc-5760-usda.clar +++ b/clarity/contracts/multisig/multisig-crp-wbtc-51840-usda.clar @@ -102,7 +102,7 @@ ;; 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-5760) (is-eq (contract-of token) .key-wbtc-5760-usda)) + (or (is-eq (contract-of token) .yield-wbtc-51840) (is-eq (contract-of token) .key-wbtc-51840-usda)) ) @@ -118,11 +118,11 @@ ) (let ( - (proposer-yield-balance (unwrap-panic (contract-call? .yield-wbtc-5760 get-balance tx-sender))) - (proposer-key-balance (unwrap-panic (contract-call? .key-wbtc-5760-usda get-balance tx-sender))) + (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-5760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-5760-usda get-total-supply))) + (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))) ) @@ -221,8 +221,8 @@ (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-5760 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-5760-usda get-total-supply))) + (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)) @@ -269,8 +269,8 @@ (new-fee-rate-y (get new-fee-rate-y proposal)) ) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-x .token-wbtc .token-usda u576000000000 new-fee-rate-x)) - (try! (contract-call? .collateral-rebalancing-pool set-fee-rate-y .token-wbtc .token-usda u576000000000 new-fee-rate-y)) + (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-34560-usda.clar b/clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar similarity index 95% rename from clarity/contracts/multisig/multisig-crp-wbtc-34560-usda.clar rename to clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar index 57376d9f..25a90fef 100644 --- a/clarity/contracts/multisig/multisig-crp-wbtc-34560-usda.clar +++ b/clarity/contracts/multisig/multisig-crp-wbtc-92160-usda.clar @@ -102,7 +102,7 @@ ;; 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)) + (or (is-eq (contract-of token) .yield-wbtc-92160) (is-eq (contract-of token) .key-wbtc-92160-usda)) ) @@ -118,11 +118,11 @@ ) (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-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-34560 get-total-supply))) - (total-key-supply (unwrap-panic (contract-call? .key-wbtc-34560-usda get-total-supply))) + (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))) ) @@ -221,8 +221,8 @@ (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-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)) @@ -269,8 +269,8 @@ (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)) + (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-lbp-alex-usda-90-10.clar b/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar new file mode 100644 index 00000000..54d2dd4f --- /dev/null +++ b/clarity/contracts/multisig/multisig-lbp-alex-usda-90-10.clar @@ -0,0 +1,253 @@ +(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) .lbp-alex-usda-90-10) +) + + +;; 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? .lbp-alex-usda-90-10 get-balance tx-sender))) + (total-supply (unwrap-panic (contract-call? .lbp-alex-usda-90-10 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: u0, + new-fee-rate-y: u0 + } + ) + (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? .lbp-alex-usda-90-10 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) + ) +) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-5760-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-usda-5760-usda.clar rename to clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar index 28a492ca..ba05dfce 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-5760-usda.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-usda-11520-usda.clar @@ -104,7 +104,7 @@ ;; 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-5760-usda) + (is-eq (contract-of token) .ytp-yield-usda-11520-usda) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-5760-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-5760-usda get-total-supply)) ONE_8)) + (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))) ) @@ -218,7 +218,7 @@ (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-5760-usda get-total-supply)) ONE_8)) + (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)) ) @@ -264,8 +264,8 @@ ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-5760 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-usda-5760 new-fee-rate-aytoken)) + (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-aytoken .yield-usda-11520 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar rename to clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar index 7b346d7a..a49052ff 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-34560-usda.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-usda-51840-usda.clar @@ -104,7 +104,7 @@ ;; 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) + (is-eq (contract-of token) .ytp-yield-usda-51840-usda) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken 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)) + (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))) ) @@ -218,7 +218,7 @@ (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)) + (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)) ) @@ -264,8 +264,8 @@ ) ;; 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-aytoken .yield-usda-34560 new-fee-rate-aytoken)) + (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-aytoken .yield-usda-51840 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-usda-40555-usda.clar b/clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-usda-40555-usda.clar rename to clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar index dd569b38..0e54fc05 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-usda-40555-usda.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-usda-92160-usda.clar @@ -104,7 +104,7 @@ ;; 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-40555-usda) + (is-eq (contract-of token) .ytp-yield-usda-92160-usda) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-usda-40555-usda get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-usda-40555-usda get-total-supply)) ONE_8)) + (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))) ) @@ -218,7 +218,7 @@ (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-40555-usda get-total-supply)) ONE_8)) + (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)) ) @@ -264,8 +264,8 @@ ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-usda-40555 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-usda-40555 new-fee-rate-aytoken)) + (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-aytoken .yield-usda-92160 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-40555-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-wbtc-40555-wbtc.clar rename to clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar index 0935f96d..8c346261 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-40555-wbtc.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar @@ -104,7 +104,7 @@ ;; 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-40555-wbtc) + (is-eq (contract-of token) .ytp-yield-wbtc-11520-wbtc) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-40555-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-40555-wbtc get-total-supply)) ONE_8)) + (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))) ) @@ -218,7 +218,7 @@ (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-40555-wbtc get-total-supply)) ONE_8)) + (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-11520-wbtc get-total-supply)) ONE_8)) (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) (yes-votes (get yes-votes proposal)) ) @@ -264,8 +264,8 @@ ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-40555 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-wbtc-40555 new-fee-rate-aytoken)) + (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-aytoken .yield-wbtc-11520 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-5760-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-wbtc-5760-wbtc.clar rename to clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar index ba5ce550..0e172f55 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-5760-wbtc.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar @@ -104,7 +104,7 @@ ;; 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-5760-wbtc) + (is-eq (contract-of token) .ytp-yield-wbtc-51840-wbtc) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken uint) ) (let ( - (proposer-balance (* (unwrap-panic (contract-call? .ytp-yield-wbtc-5760-wbtc get-balance tx-sender)) ONE_8)) - (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-5760-wbtc get-total-supply)) ONE_8)) + (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))) ) @@ -218,7 +218,7 @@ (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-5760-wbtc get-total-supply)) ONE_8)) + (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-51840-wbtc get-total-supply)) ONE_8)) (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) (yes-votes (get yes-votes proposal)) ) @@ -264,8 +264,8 @@ ) ;; Setting for Yield Token Pool - (try! (contract-call? .yield-token-pool set-fee-rate-token .yield-wbtc-5760 new-fee-rate-token)) - (try! (contract-call? .yield-token-pool set-fee-rate-aytoken .yield-wbtc-5760 new-fee-rate-aytoken)) + (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-aytoken .yield-wbtc-51840 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar similarity index 97% rename from clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar rename to clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar index d0cdfe78..3f7d0226 100644 --- a/clarity/contracts/multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar +++ b/clarity/contracts/multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar @@ -104,7 +104,7 @@ ;; 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) + (is-eq (contract-of token) .ytp-yield-wbtc-92160-wbtc) ) @@ -119,8 +119,8 @@ (new-fee-rate-aytoken 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)) + (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))) ) @@ -218,7 +218,7 @@ (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)) ONE_8)) + (total-supply (* (unwrap-panic (contract-call? .ytp-yield-wbtc-92160-wbtc get-total-supply)) ONE_8)) (threshold-count (contract-call? .math-fixed-point mul-up total-supply threshold-percent)) (yes-votes (get yes-votes proposal)) ) @@ -264,8 +264,8 @@ ) ;; 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-aytoken .yield-wbtc-34560 new-fee-rate-aytoken)) + (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-aytoken .yield-wbtc-92160 new-fee-rate-aytoken)) (ok true) ) diff --git a/clarity/contracts/new-lib/math-new-fixed-point.clar b/clarity/contracts/new-lib/math-new-fixed-point.clar index c137bd47..4e73cdf4 100644 --- a/clarity/contracts/new-lib/math-new-fixed-point.clar +++ b/clarity/contracts/new-lib/math-new-fixed-point.clar @@ -1,9 +1,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol - -;; TODO: overflow causes runtime error, should handle before operation rather than after +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; constants ;; diff --git a/clarity/contracts/new-lib/math-new-log-exp.clar b/clarity/contracts/new-lib/math-new-log-exp.clar index 466aff63..9afc5795 100644 --- a/clarity/contracts/new-lib/math-new-log-exp.clar +++ b/clarity/contracts/new-lib/math-new-log-exp.clar @@ -3,7 +3,7 @@ ;; Exponentiation and logarithm functions for 10 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/pool-token/ytp-yield-wbtc-5760-wbtc.clar b/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar similarity index 77% rename from clarity/contracts/pool-token/ytp-yield-wbtc-5760-wbtc.clar rename to clarity/contracts/pool-token/lbp-alex-usda-90-10.clar index 6fd44327..4c44de57 100644 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-5760-wbtc.clar +++ b/clarity/contracts/pool-token/lbp-alex-usda-90-10.clar @@ -1,10 +1,10 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-pool-token.pool-token-trait) -(define-fungible-token ytp-yield-wbtc-5760-wbtc) +(define-fungible-token lbp-alex-usda-90-10) (define-data-var token-uri (string-utf8 256) u"") -(define-data-var contract-owner principal .yield-token-pool) +(define-data-var contract-owner principal .liquidity-bootstrapping-pool) ;; errors (define-constant ERR-NOT-AUTHORIZED (err u1000)) @@ -39,15 +39,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-5760-wbtc))) + (ok (decimals-to-fixed (ft-get-supply lbp-alex-usda-90-10))) ) (define-read-only (get-name) - (ok "ytp-yield-wbtc-5760-wbtc") + (ok "lbp-alex-usda-90-10") ) (define-read-only (get-symbol) - (ok "ytp-yield-wbtc-5760-wbtc") + (ok "lbp-alex-usda-90-10") ) (define-read-only (get-decimals) @@ -55,7 +55,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-5760-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance lbp-alex-usda-90-10 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -72,7 +72,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? ytp-yield-wbtc-5760-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? lbp-alex-usda-90-10 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -85,13 +85,13 @@ (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-5760-wbtc (fixed-to-decimals amount) recipient) + (ft-mint? lbp-alex-usda-90-10 (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-5760-wbtc (fixed-to-decimals amount) sender) + (ft-burn? lbp-alex-usda-90-10 (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-11520-usda.clar similarity index 82% rename from clarity/contracts/pool-token/ytp-yield-usda-34560-usda.clar rename to clarity/contracts/pool-token/ytp-yield-usda-11520-usda.clar index b137c16a..245f2084 100644 --- a/clarity/contracts/pool-token/ytp-yield-usda-34560-usda.clar +++ b/clarity/contracts/pool-token/ytp-yield-usda-11520-usda.clar @@ -1,7 +1,7 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-pool-token.pool-token-trait) -(define-fungible-token ytp-yield-usda-34560-usda) +(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) @@ -39,15 +39,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-34560-usda))) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-11520-usda))) ) (define-read-only (get-name) - (ok "ytp-yield-usda-34560-usda") + (ok "ytp-yield-usda-11520-usda") ) (define-read-only (get-symbol) - (ok "ytp-yield-usda-34560-usda") + (ok "ytp-yield-usda-11520-usda") ) (define-read-only (get-decimals) @@ -55,7 +55,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-34560-usda account))) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-11520-usda account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -72,7 +72,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? ytp-yield-usda-34560-usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? ytp-yield-usda-11520-usda (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -85,13 +85,13 @@ (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) + (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-34560-usda (fixed-to-decimals amount) sender) + (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-40555-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar similarity index 82% rename from clarity/contracts/pool-token/ytp-yield-usda-40555-usda.clar rename to clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar index ae2d9fa2..d8d762f7 100644 --- a/clarity/contracts/pool-token/ytp-yield-usda-40555-usda.clar +++ b/clarity/contracts/pool-token/ytp-yield-usda-51840-usda.clar @@ -1,7 +1,7 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-pool-token.pool-token-trait) -(define-fungible-token ytp-yield-usda-40555-usda) +(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) @@ -39,15 +39,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-40555-usda))) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-usda-51840-usda))) ) (define-read-only (get-name) - (ok "ytp-yield-usda-40555-usda") + (ok "ytp-yield-usda-51840-usda") ) (define-read-only (get-symbol) - (ok "ytp-yield-usda-40555-usda") + (ok "ytp-yield-usda-51840-usda") ) (define-read-only (get-decimals) @@ -55,7 +55,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-40555-usda account))) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-usda-51840-usda account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -72,7 +72,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? ytp-yield-usda-40555-usda (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? ytp-yield-usda-51840-usda (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -85,13 +85,13 @@ (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-40555-usda (fixed-to-decimals amount) recipient) + (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-40555-usda (fixed-to-decimals amount) sender) + (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-5760-usda.clar b/clarity/contracts/pool-token/ytp-yield-usda-5760-usda.clar deleted file mode 100644 index 9d3a88a7..00000000 --- a/clarity/contracts/pool-token/ytp-yield-usda-5760-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-5760-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-5760-usda))) -) - -(define-read-only (get-name) - (ok "ytp-yield-usda-5760-usda") -) - -(define-read-only (get-symbol) - (ok "ytp-yield-usda-5760-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-5760-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-5760-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-5760-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-5760-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 new file mode 100644 index 00000000..88f2a015 --- /dev/null +++ b/clarity/contracts/pool-token/ytp-yield-usda-92160-usda.clar @@ -0,0 +1,97 @@ +(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-wbtc-40555-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar similarity index 82% rename from clarity/contracts/pool-token/ytp-yield-wbtc-40555-wbtc.clar rename to clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar index 61b043d5..a1ab5ea2 100644 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-40555-wbtc.clar +++ b/clarity/contracts/pool-token/ytp-yield-wbtc-11520-wbtc.clar @@ -1,7 +1,7 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-pool-token.pool-token-trait) -(define-fungible-token ytp-yield-wbtc-40555-wbtc) +(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) @@ -39,15 +39,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-40555-wbtc))) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-11520-wbtc))) ) (define-read-only (get-name) - (ok "ytp-yield-wbtc-40555-wbtc") + (ok "ytp-yield-wbtc-11520-wbtc") ) (define-read-only (get-symbol) - (ok "ytp-yield-wbtc-40555-wbtc") + (ok "ytp-yield-wbtc-11520-wbtc") ) (define-read-only (get-decimals) @@ -55,7 +55,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-40555-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-11520-wbtc account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -72,7 +72,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? ytp-yield-wbtc-40555-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? ytp-yield-wbtc-11520-wbtc (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -85,13 +85,13 @@ (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-40555-wbtc (fixed-to-decimals amount) recipient) + (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-40555-wbtc (fixed-to-decimals amount) sender) + (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-34560-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar similarity index 82% rename from clarity/contracts/pool-token/ytp-yield-wbtc-34560-wbtc.clar rename to clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar index bad105cb..8a6e523e 100644 --- a/clarity/contracts/pool-token/ytp-yield-wbtc-34560-wbtc.clar +++ b/clarity/contracts/pool-token/ytp-yield-wbtc-51840-wbtc.clar @@ -1,7 +1,7 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-pool-token.pool-token-trait) -(define-fungible-token ytp-yield-wbtc-34560-wbtc) +(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) @@ -39,15 +39,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-34560-wbtc))) + (ok (decimals-to-fixed (ft-get-supply ytp-yield-wbtc-51840-wbtc))) ) (define-read-only (get-name) - (ok "ytp-yield-wbtc-34560-wbtc") + (ok "ytp-yield-wbtc-51840-wbtc") ) (define-read-only (get-symbol) - (ok "ytp-yield-wbtc-34560-wbtc") + (ok "ytp-yield-wbtc-51840-wbtc") ) (define-read-only (get-decimals) @@ -55,7 +55,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-34560-wbtc account))) + (ok (decimals-to-fixed (ft-get-balance ytp-yield-wbtc-51840-wbtc account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -72,7 +72,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? ytp-yield-wbtc-34560-wbtc (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? ytp-yield-wbtc-51840-wbtc (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -85,13 +85,13 @@ (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) + (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-34560-wbtc (fixed-to-decimals amount) sender) + (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-92160-wbtc.clar b/clarity/contracts/pool-token/ytp-yield-wbtc-92160-wbtc.clar new file mode 100644 index 00000000..5df22005 --- /dev/null +++ b/clarity/contracts/pool-token/ytp-yield-wbtc-92160-wbtc.clar @@ -0,0 +1,97 @@ +(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/alex-reserve-pool.clar b/clarity/contracts/pool/alex-reserve-pool.clar index 4ac6c944..21ec4c6b 100644 --- a/clarity/contracts/pool/alex-reserve-pool.clar +++ b/clarity/contracts/pool/alex-reserve-pool.clar @@ -106,9 +106,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol - -;; TODO: overflow causes runtime error, should handle before operation rather than after +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; constants ;; @@ -198,7 +196,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/pool/collateral-rebalancing-pool.clar b/clarity/contracts/pool/collateral-rebalancing-pool.clar index b4321c11..76d18df8 100644 --- a/clarity/contracts/pool/collateral-rebalancing-pool.clar +++ b/clarity/contracts/pool/collateral-rebalancing-pool.clar @@ -32,6 +32,7 @@ (define-constant ERR-GET-BALANCE-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)) (define-constant a1 u27839300) @@ -39,7 +40,6 @@ (define-constant a3 u97200) (define-constant a4 u7810800) -;; TODO: need to be defined properly (define-data-var contract-owner principal tx-sender) (define-data-var oracle-src (string-ascii 32) "coingecko") ;; data maps and vars @@ -353,7 +353,7 @@ ( (minted-yield-token (get yield-token (try! (add-to-position token collateral the-yield-token the-key-token dx)))) ) - (contract-call? .yield-token-pool swap-y-for-x the-yield-token token minted-yield-token) + (contract-call? .yield-token-pool swap-y-for-x the-yield-token token minted-yield-token none) ) ) @@ -390,8 +390,8 @@ (dy-weighted (if (is-eq token-x token-y) dx-to-dy (if (is-some (contract-call? .fixed-weight-pool get-pool-exists token collateral u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x token collateral u50000000 u50000000 dx-to-dy))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral token u50000000 u50000000 dx-to-dy))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x token collateral u50000000 u50000000 dx-to-dy none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral token u50000000 u50000000 dx-to-dy none))) ) ) ) @@ -444,8 +444,8 @@ (begin (as-contract (try! (contract-call? .alex-vault transfer-ft collateral balance-x tx-sender tx-sender))) (if (is-some (contract-call? .fixed-weight-pool get-pool-exists collateral token u50000000 u50000000)) - (get dy (as-contract (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral token u50000000 u50000000 balance-x)))) - (get dx (as-contract (try! (contract-call? .fixed-weight-pool swap-y-for-x token collateral u50000000 u50000000 balance-x)))) + (get dy (as-contract (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral token u50000000 u50000000 balance-x none)))) + (get dx (as-contract (try! (contract-call? .fixed-weight-pool swap-y-for-x token collateral u50000000 u50000000 balance-x none)))) ) ) ) @@ -495,8 +495,8 @@ (as-contract (unwrap! (contract-call? token transfer (if (is-eq token-y .token-usda) amount-to-swap (if (is-some (contract-call? .fixed-weight-pool get-pool-exists token .token-usda u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x token .token-usda u50000000 u50000000 amount-to-swap))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda token u50000000 u50000000 amount-to-swap))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x token .token-usda u50000000 u50000000 amount-to-swap none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y .token-usda token u50000000 u50000000 amount-to-swap none))) ) ) tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED)) ) @@ -556,7 +556,7 @@ ) ;; split of balance to yield and key is transparent to traders -(define-public (swap-x-for-y (token ) (collateral ) (expiry uint) (dx uint)) +(define-public (swap-x-for-y (token ) (collateral ) (expiry uint) (dx uint) (min-dy (optional uint))) (begin ;; TODO : Check whether dy or dx value is valid @@ -599,6 +599,8 @@ ) ) + (asserts! (< (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE) + (unwrap! (contract-call? collateral transfer dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED) (try! (contract-call? .alex-vault transfer-ft token dy (as-contract tx-sender) tx-sender)) @@ -610,10 +612,9 @@ ) ) -(define-public (swap-y-for-x (token ) (collateral ) (expiry uint) (dy uint)) +;; split of balance to yield and key is transparent to traders +(define-public (swap-y-for-x (token ) (collateral ) (expiry uint) (dy uint) (min-dx (optional uint))) (begin - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) ;; (asserts! (<= (* block-height ONE_8) expiry) ERR-EXPIRY) ;; swap is supported only if token /= collateral @@ -651,6 +652,8 @@ ) ) + (asserts! (< (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) + (try! (contract-call? .alex-vault transfer-ft collateral dx (as-contract tx-sender) tx-sender)) (unwrap! (contract-call? token transfer dy tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED) @@ -662,40 +665,24 @@ ) ) -(define-read-only (get-fee-rate-x (token ) (collateral ) (expiry uint)) - (let - ( - (token-x (contract-of collateral)) - (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)) - ) - (ok (get fee-rate-x pool)) - ) +(define-read-only (get-fee-rate-x (token ) (collateral ) (expiry uint)) + (ok (get fee-rate-x (try! (get-pool-details token collateral expiry)))) ) -(define-read-only (get-fee-rate-y (token ) (collateral ) (expiry uint)) - (let - ( - (token-x (contract-of collateral)) - (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)) - ) - (ok (get fee-rate-y pool)) - ) +(define-read-only (get-fee-rate-y (token ) (collateral ) (expiry uint)) + (ok (get fee-rate-y (try! (get-pool-details token collateral expiry)))) ) (define-public (set-fee-rate-x (token ) (collateral ) (expiry uint) (fee-rate-x uint)) (let ( - (token-x (contract-of collateral)) - (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)) + (pool (try! (get-pool-details token collateral expiry))) ) (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) (map-set pools-data-map { - token-x: token-x, token-y: token-y, expiry: expiry + token-x: (contract-of collateral), token-y: (contract-of token), expiry: expiry } (merge pool { fee-rate-x: fee-rate-x }) ) @@ -705,16 +692,14 @@ (define-public (set-fee-rate-y (token ) (collateral ) (expiry uint) (fee-rate-y uint)) (let - ( - (token-x (contract-of collateral)) - (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)) + ( + (pool (try! (get-pool-details token collateral expiry))) ) (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) (map-set pools-data-map { - token-x: token-x, token-y: token-y, expiry: expiry + token-x: (contract-of collateral), token-y: (contract-of token), expiry: expiry } (merge pool { fee-rate-y: fee-rate-y }) ) @@ -766,8 +751,8 @@ (if (is-eq token-x .token-usda) fee-x (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda collateral u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda collateral u50000000 u50000000 fee-x))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral .token-usda u50000000 u50000000 fee-x))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda collateral u50000000 u50000000 fee-x none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y collateral .token-usda u50000000 u50000000 fee-x none))) ) ) ) @@ -785,8 +770,8 @@ (if (is-eq token-y .token-usda) fee-y (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda token u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda token u50000000 u50000000 fee-y))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y token .token-usda u50000000 u50000000 fee-y))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda token u50000000 u50000000 fee-y none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y token .token-usda u50000000 u50000000 fee-y none))) ) ) ) @@ -960,7 +945,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; TODO: overflow causes runtime error, should handle before operation rather than after @@ -1052,7 +1037,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/pool/fixed-weight-pool.clar b/clarity/contracts/pool/fixed-weight-pool.clar index 4e984421..e0fae837 100644 --- a/clarity/contracts/pool/fixed-weight-pool.clar +++ b/clarity/contracts/pool/fixed-weight-pool.clar @@ -24,11 +24,12 @@ (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)) +(define-constant ERR-ORACLE-AVERAGE-BIGGER-THAN-ONE (err u7004)) -(define-constant alex-symbol "alex") -(define-constant reserve-usdc-symbol "usdc") (define-data-var contract-owner principal tx-sender) -(define-data-var oracle-src (string-ascii 32) "coingecko") ;; data maps and vars (define-map pools-map @@ -59,7 +60,10 @@ fee-rate-x: uint, fee-rate-y: uint, token-x-symbol: (string-ascii 32), - token-y-symbol: (string-ascii 32) + token-y-symbol: (string-ascii 32), + oracle-enabled: bool, + oracle-average: uint, + oracle-resilient: uint } ) @@ -113,15 +117,68 @@ ) ) -(define-read-only (get-oracle-src) - (ok (var-get oracle-src)) +(define-read-only (get-oracle-enabled (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) + (ok (get + oracle-enabled + (unwrap! (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 }) ERR-INVALID-POOL-ERR))) ) -(define-public (set-oracle-src (new-oracle-src (string-ascii 32))) - (begin - (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ok (var-set oracle-src new-oracle-src)) - ) +;; oracle can only be enabled +(define-public (set-oracle-enabled (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) + (let + ( + (pool (unwrap! (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 }) 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 { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), weight-x: weight-x, weight-y: weight-y } pool-updated) + (ok true) + ) +) + +(define-read-only (get-oracle-average (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) + (ok (get + oracle-average + (unwrap! (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 }) ERR-INVALID-POOL-ERR))) +) + +(define-public (set-oracle-average (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (new-oracle-average uint)) + (let + ( + (pool (unwrap! (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 }) ERR-INVALID-POOL-ERR)) + (pool-updated (merge pool { + oracle-average: new-oracle-average, + oracle-resilient: (try! (get-oracle-instant token-x-trait token-y-trait weight-x weight-y)) + })) + ) + (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 { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), weight-x: weight-x, weight-y: weight-y } pool-updated) + (ok true) + ) +) + +(define-read-only (get-oracle-resilient (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) + (let + ( + (pool (unwrap! (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 }) 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 token-x-trait token-y-trait weight-x weight-y))) + (mul-down (get oracle-average pool) (get oracle-resilient pool)))) + ) +) + +(define-read-only (get-oracle-instant (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint)) + (let + ( + (pool (unwrap! (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 }) ERR-INVALID-POOL-ERR)) + ) + (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED) + (ok (div-down (mul-down (get balance-y pool) weight-x) (mul-down (get balance-x pool) weight-y))) + ) ) (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)) @@ -141,7 +198,10 @@ fee-rate-x: u0, fee-rate-y: u0, token-x-symbol: (try! (contract-call? token-x-trait get-symbol)), - token-y-symbol: (try! (contract-call? token-y-trait get-symbol)) + token-y-symbol: (try! (contract-call? token-y-trait get-symbol)), + oracle-enabled: false, + oracle-average: u0, + oracle-resilient: u0 }) ) (asserts! @@ -236,11 +296,9 @@ ) ) -(define-public (swap-x-for-y (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (dx uint)) +(define-public (swap-x-for-y (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (dx uint) (min-dy (optional uint))) (begin - (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) + (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) (let ( (token-x (contract-of token-x-trait)) @@ -261,11 +319,17 @@ { balance-x: (+ balance-x dx-net-fees), balance-y: (if (<= balance-y dy) u0 (- balance-y dy)), - fee-balance-x: (+ fee (get fee-balance-x pool)) + fee-balance-x: (+ fee (get fee-balance-x pool)), + oracle-resilient: (if (get oracle-enabled pool) + (try! (get-oracle-resilient token-x-trait token-y-trait weight-x weight-y)) + u0 + ) } ) ) ) + + (asserts! (< (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE) (unwrap! (contract-call? token-x-trait transfer dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED) (try! (contract-call? .alex-vault transfer-ft token-y-trait dy (as-contract tx-sender) tx-sender)) @@ -278,10 +342,8 @@ ) ) -(define-public (swap-y-for-x (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (dy uint)) +(define-public (swap-y-for-x (token-x-trait ) (token-y-trait ) (weight-x uint) (weight-y uint) (dy uint) (min-dx (optional uint))) (begin - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) (let ( @@ -304,11 +366,17 @@ { balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), balance-y: (+ balance-y dy-net-fees), - fee-balance-y: (+ fee fee-balance-y) + fee-balance-y: (+ fee fee-balance-y), + oracle-resilient: (if (get oracle-enabled pool) + (try! (get-oracle-resilient token-x-trait token-y-trait weight-x weight-y)) + u0 + ) } ) ) ) + + (asserts! (< (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) (try! (contract-call? .alex-vault transfer-ft token-x-trait dx (as-contract tx-sender) tx-sender)) (unwrap! (contract-call? token-y-trait transfer dy tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED) @@ -427,7 +495,7 @@ (contract-call? .alex-reserve-pool transfer-to-mint (if (is-eq token-x .token-usda) fee-x - (get dx (try! (swap-y-for-x .token-usda token-x-trait u50000000 u50000000 fee-x))) + (get dx (try! (swap-y-for-x .token-usda token-x-trait u50000000 u50000000 fee-x none))) ) ) ) @@ -443,7 +511,7 @@ (contract-call? .alex-reserve-pool transfer-to-mint (if (is-eq token-y .token-usda) fee-y - (get dx (try! (swap-y-for-x .token-usda token-y-trait u50000000 u50000000 fee-y))) + (get dx (try! (swap-y-for-x .token-usda token-y-trait u50000000 u50000000 fee-y none))) ) ) ) @@ -553,7 +621,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; TODO: overflow causes runtime error, should handle before operation rather than after @@ -645,7 +713,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/pool/liquidity-bootstrapping-pool.clar b/clarity/contracts/pool/liquidity-bootstrapping-pool.clar index 19523a9d..5fb24ff7 100644 --- a/clarity/contracts/pool/liquidity-bootstrapping-pool.clar +++ b/clarity/contracts/pool/liquidity-bootstrapping-pool.clar @@ -10,20 +10,19 @@ (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-NO-FEE (err u2005)) -(define-constant ERR-NO-FEE-Y (err u2006)) -(define-constant already-ERR-EXPIRY (err u2010)) -(define-constant ERR-WEIGHTED-EQUATION-CALL (err u2009)) +(define-constant ERR-ALREADY-EXPIRED (err u2011)) (define-constant ERR-MATH-CALL (err u2010)) -(define-constant internal-get-weight-err (err u2012)) +(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)) +(define-constant CONTRACT-OWNER tx-sender) ;; data maps and vars ;; @@ -46,16 +45,14 @@ total-supply: uint, balance-x: uint, balance-y: uint, - fee-balance-x: uint, - fee-balance-y: uint, - fee-to-address: principal, + pool-multisig: principal, pool-token: principal, listed: uint, weight-x-0: uint, weight-x-1: uint, weight-x-t: uint, - fee-rate-x: uint, - fee-rate-y: uint + price-x-min: uint, + price-x-max: uint } ) @@ -97,7 +94,7 @@ (ok true) ) ) -) +) ;; public functions ;; @@ -107,13 +104,7 @@ ) (define-read-only (get-pool-contracts (pool-id uint)) - (let - ( - (pool (map-get? pools-map {pool-id: pool-id})) - ) - (asserts! (is-some pool) ERR-INVALID-POOL-ERR) - (ok pool) - ) + (ok (map-get? pools-map {pool-id: pool-id})) ) (define-read-only (get-pools) @@ -121,20 +112,12 @@ ) (define-read-only (get-pool-details (token-x-trait ) (token-y-trait ) (expiry uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry })) - ) - (asserts! (is-some pool) ERR-INVALID-POOL-ERR) - (ok pool) - ) + (ok (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)) ) (define-read-only (get-weight-x (token-x-trait ) (token-y-trait ) (expiry uint)) (begin - (asserts! (< (* block-height ONE_8) expiry) already-ERR-EXPIRY) + (asserts! (<= (* block-height ONE_8) expiry) ERR-ALREADY-EXPIRED) (let ( (token-x (contract-of token-x-trait)) @@ -151,22 +134,42 @@ (expiry-to-listed (- expiry listed)) (weight-diff (- weight-x-0 weight-x-1)) (time-ratio (div-down now-to-listed expiry-to-listed)) - (weight-change (mul-down weight-diff time-ratio)) - (weight-t (- weight-x-0 weight-change)) + (weight-change (mul-down weight-diff time-ratio)) ) - - (ok weight-t) + (ok (- weight-x-0 weight-change)) ) ) ) +(define-read-only (get-price-range (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)) + ) + (ok {min-price: (get price-x-min pool), max-price: (get price-x-max pool)}) + ) +) + +(define-public (set-price-range (token-x-trait ) (token-y-trait ) (expiry uint) (min-price uint) (max-price 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)) + (pool-updated (merge pool { + price-x-min: min-price, + price-x-max: max-price + })) + ) + (asserts! (is-eq contract-caller (get pool-multisig pool)) ERR-NOT-AUTHORIZED) + (map-set pools-data-map { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), expiry: expiry } pool-updated) + (ok true) + ) +) + ;; get overall balances for the pair (define-read-only (get-balances (token-x-trait ) (token-y-trait ) (expiry uint)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) (err ERR-INVALID-POOL-ERR))) + (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)) ) (ok {balance-x: (get balance-x pool), balance-y: (get balance-y pool)}) ) @@ -182,25 +185,17 @@ total-supply: u0, balance-x: u0, balance-y: u0, - fee-balance-x: u0, - fee-balance-y: u0, - fee-to-address: (contract-of multisig-vote), + pool-multisig: (contract-of multisig-vote), pool-token: (contract-of the-pool-token), listed: (* block-height ONE_8), weight-x-0: weight-x-0, weight-x-1: weight-x-1, weight-x-t: weight-x-0, - fee-rate-x: u0, - fee-rate-y: u0 + price-x-min: u0, + price-x-max: (* ONE_8 ONE_8) ;; something big }) ) - (asserts! - (and - (is-none (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry })) - (is-none (map-get? pools-data-map { token-x: token-y, token-y: token-x, expiry: expiry })) - ) - ERR-POOL-ALREADY-EXISTS - ) + (asserts! (is-none (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry })) ERR-POOL-ALREADY-EXISTS) (map-set pools-map { pool-id: pool-id } { token-x: token-x, token-y: token-y, expiry: expiry }) (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-data) @@ -232,7 +227,7 @@ (pool-updated (merge pool { total-supply: (if (<= total-supply shares) u0 (- total-supply shares)), balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), - balance-y: (if (<= balance-y dx) u0 (- balance-y dy)) + balance-y: (if (<= balance-y dy) u0 (- balance-y dy)) }) ) ) @@ -247,12 +242,10 @@ ) ) -(define-public (swap-x-for-y (token-x-trait ) (token-y-trait ) (expiry uint) (dx uint)) +(define-public (swap-x-for-y (token-x-trait ) (token-y-trait ) (expiry uint) (dx uint) (min-dy (optional uint))) (begin ;; swap is allowed only until expiry - (asserts! (< (* block-height ONE_8) expiry) already-ERR-EXPIRY) - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) + (asserts! (<= (* block-height ONE_8) expiry) ERR-ALREADY-EXPIRED) (let ( (token-x (contract-of token-x-trait)) @@ -260,45 +253,36 @@ (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)) - (fee-rate-x (get fee-rate-x pool)) - - ;; fee = dx * fee-rate-x - (fee (mul-up dx fee-rate-x)) - (dx-net-fees (if (<= dx fee) u0 (- dx fee))) ;; swap triggers update of weight (weight-x (try! (get-weight-x token-x-trait token-y-trait expiry))) (weight-y (- ONE_8 weight-x)) - (dy (try! (contract-call? .weighted-equation get-y-given-x balance-x balance-y weight-x weight-y dx-net-fees))) - - (pool-updated - (merge pool - { - balance-x: (+ balance-x dx-net-fees), - balance-y: (if (<= balance-y dy) u0 (- balance-y dy)), - fee-balance-x: (+ fee (get fee-balance-x pool)), - weight-x-t: weight-x - } - ) - ) + (dy (try! (get-y-given-x token-x-trait token-y-trait expiry dx))) + + (pool-updated (merge pool { + balance-x: (+ balance-x dx), + balance-y: (if (<= balance-y dy) u0 (- balance-y dy)), + weight-x-t: weight-x })) ) + + (asserts! (< (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE) + (asserts! (<= (get price-x-min pool) (div-down dy dx)) ERR-PRICE-LOWER-THAN-MIN) + (asserts! (>= (get price-x-max pool) (div-down dy dx)) ERR-PRICE-GREATER-THAN-MAX) + (unwrap! (contract-call? token-x-trait transfer dx tx-sender .alex-vault none) ERR-TRANSFER-X-FAILED) (try! (contract-call? .alex-vault transfer-ft token-y-trait dy (as-contract tx-sender) tx-sender)) ;; post setting (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) (print { object: "pool", action: "swap-x-for-y", data: pool-updated }) - (ok {dx: dx-net-fees, dy: dy}) + (ok {dx: dx, dy: dy}) ) ) ) -(define-public (swap-y-for-x (token-x-trait ) (token-y-trait ) (expiry uint) (dy uint)) +(define-public (swap-y-for-x (token-x-trait ) (token-y-trait ) (expiry uint) (dy uint) (min-dx (optional uint))) (begin ;; swap is allowed only until expiry - (asserts! (< (* block-height ONE_8) expiry) already-ERR-EXPIRY) - - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) + (asserts! (<= (* block-height ONE_8) expiry) ERR-ALREADY-EXPIRED) (let ( (token-x (contract-of token-x-trait)) @@ -306,178 +290,48 @@ (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)) - (fee-rate-y (get fee-rate-y pool)) - - ;; fee = dy * fee-rate-y - (fee (mul-up dy fee-rate-y)) - (dy-net-fees (if (<= dy fee) u0 (- dy fee))) ;; swap triggers update of weight (weight-x (try! (get-weight-x token-x-trait token-y-trait expiry))) (weight-y (- ONE_8 weight-x)) - (dx (try! (contract-call? .weighted-equation get-x-given-y balance-x balance-y weight-x weight-y dy-net-fees))) - - (pool-updated - (merge pool - { - balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), - balance-y: (+ balance-y dy-net-fees), - fee-balance-y: (+ fee (get fee-balance-y pool)), - weight-x-t: weight-x - } - ) - ) + (dx (try! (get-x-given-y token-x-trait token-y-trait expiry dy))) + + (pool-updated (merge pool { + balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), + balance-y: (+ balance-y dy), + weight-x-t: weight-x})) ) + + (asserts! (< (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) + (asserts! (<= (get price-x-min pool) (div-down dy dx)) ERR-PRICE-LOWER-THAN-MIN) + (asserts! (>= (get price-x-max pool) (div-down dy dx)) ERR-PRICE-GREATER-THAN-MAX) + (try! (contract-call? .alex-vault transfer-ft token-x-trait dx (as-contract tx-sender) tx-sender)) (unwrap! (contract-call? token-y-trait transfer dy tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED) ;; post setting (map-set pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry } pool-updated) (print { object: "pool", action: "swap-y-for-x", data: pool-updated }) - (ok {dx: dx, dy: dy-net-fees}) - ) - ) -) - - -(define-read-only (get-fee-rate-x (token-x-trait ) (token-y-trait ) (expiry uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) - ) - (ok (get fee-rate-x pool)) - ) -) - -(define-read-only (get-fee-rate-y (token-x-trait ) (token-y-trait ) (expiry uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) - ) - (ok (get fee-rate-y pool)) - ) -) - -(define-public (set-fee-rate-x (token-x-trait ) (token-y-trait ) (expiry uint) (fee-rate-x uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) - ) - (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) - - (map-set pools-data-map - { - token-x: token-x, token-y: token-y, expiry: expiry - } - (merge pool { fee-rate-x: fee-rate-x }) - ) - (ok true) - ) -) - -(define-public (set-fee-rate-y (token-x-trait ) (token-y-trait ) (expiry uint) (fee-rate-y uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) - ) - (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) - - (map-set pools-data-map - { - token-x: token-x, token-y: token-y, expiry: expiry - } - (merge pool { fee-rate-y: fee-rate-y }) - ) - (ok true) - ) -) - -(define-read-only (get-fee-to-address (token-x-trait ) (token-y-trait ) (expiry uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) (err ERR-INVALID-POOL-ERR))) + (ok {dx: dx, dy: dy}) ) - (ok (get fee-to-address pool)) ) ) -(define-read-only (get-fees (token-x-trait ) (token-y-trait ) (expiry uint)) - (let - ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) (err ERR-INVALID-POOL-ERR))) - ) - (ok {fee-balance-x: (get fee-balance-x pool), fee-balance-y: (get fee-balance-y pool)}) - ) +(define-read-only (get-pool-multisig (token-x-trait ) (token-y-trait ) (expiry uint)) + (ok (get pool-multisig (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))) ) -;; TODO: implement reserve pool logic -(define-public (collect-fees (token-x-trait ) (token-y-trait ) (expiry uint)) +;; testing only +(define-public (set-pool-multisig (token-x-trait ) (token-y-trait ) (expiry uint) (new-multisig principal)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) - (address (get fee-to-address pool)) - (fee-x (get fee-balance-x pool)) - (fee-y (get fee-balance-y pool)) - (rebate-rate (unwrap-panic (contract-call? .alex-reserve-pool get-rebate-rate))) - ) - (asserts! (is-eq contract-caller (get fee-to-address pool)) ERR-NOT-AUTHORIZED) - (and (> fee-x u0) - (and - ;; first transfer fee-x to tx-sender - (try! (contract-call? .alex-vault transfer-ft token-x-trait fee-x (as-contract tx-sender) tx-sender)) - ;; send fee-x to reserve-pool to mint alex - (try! - (contract-call? .alex-reserve-pool transfer-to-mint - (if (is-eq token-x .token-usda) - fee-x - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda token-x-trait u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda token-x-trait u50000000 u50000000 fee-x))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y token-x-trait .token-usda u50000000 u50000000 fee-x))) - ) - ) - ) - ) - ) - ) - - (and (> fee-y u0) - (and - ;; first transfer fee-y to tx-sender - ;; (unwrap! (contract-call? token-y-trait transfer fee-y .alex-vault tx-sender none) ERR-TRANSFER-Y-FAILED) - (try! (contract-call? .alex-vault transfer-ft token-y-trait fee-y (as-contract tx-sender) tx-sender)) - ;; send fee-y to reserve-pool to mint alex - (try! - (contract-call? .alex-reserve-pool transfer-to-mint - (if (is-eq token-y .token-usda) - fee-y - (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda token-y-trait u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda token-y-trait u50000000 u50000000 fee-y))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y token-y-trait .token-usda u50000000 u50000000 fee-y))) - ) - ) - ) - ) - ) - ) - - (map-set pools-data-map - { token-x: token-x, token-y: token-y, expiry: expiry} - (merge pool { fee-balance-x: u0, fee-balance-y: u0 }) + (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)) + (pool-updated (merge pool { + pool-multisig: new-multisig + })) ) - (ok {fee-x: fee-x, fee-y: fee-y}) + (asserts! (is-eq contract-caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED) + (map-set pools-data-map { token-x: (contract-of token-x-trait), token-y: (contract-of token-y-trait), expiry: expiry } pool-updated) + (ok true) ) ) @@ -504,9 +358,7 @@ (define-read-only (get-x-given-price (token-x-trait ) (token-y-trait ) (expiry uint) (price uint)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) + (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)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (weight-x (get weight-x-t pool)) @@ -519,9 +371,7 @@ (define-read-only (get-token-given-position (token-x-trait ) (token-y-trait ) (expiry uint) (dx uint) (dy uint)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) + (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)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (total-supply (get total-supply pool)) @@ -535,9 +385,7 @@ (define-read-only (get-position-given-mint (token-x-trait ) (token-y-trait ) (expiry uint) (shares uint)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) + (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)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (total-supply (get total-supply pool)) @@ -551,9 +399,7 @@ (define-read-only (get-position-given-burn (token-x-trait ) (token-y-trait ) (expiry uint) (shares uint)) (let ( - (token-x (contract-of token-x-trait)) - (token-y (contract-of token-y-trait)) - (pool (unwrap! (map-get? pools-data-map { token-x: token-x, token-y: token-y, expiry: expiry }) ERR-INVALID-POOL-ERR)) + (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)) (balance-x (get balance-x pool)) (balance-y (get balance-y pool)) (total-supply (get total-supply pool)) @@ -567,7 +413,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; TODO: overflow causes runtime error, should handle before operation rather than after @@ -659,7 +505,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/pool/yield-token-pool.clar b/clarity/contracts/pool/yield-token-pool.clar index bf7e0a2f..1b6c1612 100644 --- a/clarity/contracts/pool/yield-token-pool.clar +++ b/clarity/contracts/pool/yield-token-pool.clar @@ -26,6 +26,7 @@ (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)) ;; TODO: need to be defined properly (define-data-var contract-owner principal tx-sender) @@ -291,7 +292,7 @@ ) ) -(define-public (swap-x-for-y (the-aytoken ) (the-token ) (dx uint)) +(define-public (swap-x-for-y (the-aytoken ) (the-token ) (dx uint) (min-dy (optional uint))) (begin (asserts! (> dx u0) ERR-INVALID-LIQUIDITY) (let @@ -323,8 +324,9 @@ ) ) ) - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) + + (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-aytoken dy (as-contract tx-sender) tx-sender))) @@ -336,7 +338,7 @@ ) ) -(define-public (swap-y-for-x (the-aytoken ) (the-token ) (dy uint)) +(define-public (swap-y-for-x (the-aytoken ) (the-token ) (dy uint) (min-dx (optional uint))) (begin (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) (let @@ -366,8 +368,7 @@ ) ) ) - ;; TODO : Check whether dy or dx value is valid - ;; (asserts! (< min-dy dy) too-much-slippage-err) + (asserts! (< (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) (and (> dx u0) (try! (contract-call? .alex-vault transfer-ft the-token dx (as-contract tx-sender) tx-sender))) (and (> dy u0) (unwrap! (contract-call? the-aytoken transfer dy tx-sender .alex-vault none) ERR-TRANSFER-Y-FAILED)) @@ -474,8 +475,8 @@ (if (is-eq aytoken .token-usda) fee-x (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda the-aytoken u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda the-aytoken u50000000 u50000000 fee-x))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y the-aytoken .token-usda u50000000 u50000000 fee-x))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda the-aytoken u50000000 u50000000 fee-x none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y the-aytoken .token-usda u50000000 u50000000 fee-x none))) ) ) ) @@ -493,8 +494,8 @@ (if (is-eq token .token-usda) fee-y (if (is-some (contract-call? .fixed-weight-pool get-pool-exists .token-usda the-token u50000000 u50000000)) - (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda the-token u50000000 u50000000 fee-y))) - (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y the-token .token-usda u50000000 u50000000 fee-y))) + (get dx (try! (contract-call? .fixed-weight-pool swap-y-for-x .token-usda the-token u50000000 u50000000 fee-y none))) + (get dy (try! (contract-call? .fixed-weight-pool swap-x-for-y the-token .token-usda u50000000 u50000000 fee-y none))) ) ) ) @@ -676,7 +677,7 @@ ;; math-fixed-point ;; Fixed Point Math -;; following https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol +;; following https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/FixedPoint.sol ;; TODO: overflow causes runtime error, should handle before operation rather than after @@ -768,7 +769,7 @@ ;; 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 ;; exponentiation and logarithm (where the base is Euler's number). -;; Reference: https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol +;; Reference: https://github.com/balancer-labs/balancer-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol ;; MODIFIED: because we use only 128 bits instead of 256, we cannot do 20 decimal or 36 decimal accuracy like in Balancer. ;; constants diff --git a/clarity/contracts/yield-token/yield-usda-40555.clar b/clarity/contracts/yield-token/yield-usda-11520.clar similarity index 82% rename from clarity/contracts/yield-token/yield-usda-40555.clar rename to clarity/contracts/yield-token/yield-usda-11520.clar index 66707fec..359e3b45 100644 --- a/clarity/contracts/yield-token/yield-usda-40555.clar +++ b/clarity/contracts/yield-token/yield-usda-11520.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-usda-40555) +(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 u4055500000000) +(define-data-var token-expiry uint u1152000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-40555))) + (ok (decimals-to-fixed (ft-get-supply yield-usda-11520))) ) (define-read-only (get-name) - (ok "yield-usda-40555") + (ok "yield-usda-11520") ) (define-read-only (get-symbol) - (ok "yield-usda-40555") + (ok "yield-usda-11520") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-40555 account))) + (ok (decimals-to-fixed (ft-get-balance yield-usda-11520 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-usda-40555 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-usda-11520 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-40555 (fixed-to-decimals amount) recipient) + (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-40555 (fixed-to-decimals amount) sender) + (ft-burn? yield-usda-11520 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-usda-40555 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (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-34560.clar b/clarity/contracts/yield-token/yield-usda-51840.clar similarity index 82% rename from clarity/contracts/yield-token/yield-usda-34560.clar rename to clarity/contracts/yield-token/yield-usda-51840.clar index 33dc6a13..c6089134 100644 --- a/clarity/contracts/yield-token/yield-usda-34560.clar +++ b/clarity/contracts/yield-token/yield-usda-51840.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-usda-34560) +(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 u3456000000000) +(define-data-var token-expiry uint u5184000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-34560))) + (ok (decimals-to-fixed (ft-get-supply yield-usda-51840))) ) (define-read-only (get-name) - (ok "yield-usda-34560") + (ok "yield-usda-51840") ) (define-read-only (get-symbol) - (ok "yield-usda-34560") + (ok "yield-usda-51840") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-34560 account))) + (ok (decimals-to-fixed (ft-get-balance yield-usda-51840 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-usda-34560 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-usda-51840 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (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) + (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-34560 (fixed-to-decimals amount) sender) + (ft-burn? yield-usda-51840 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-usda-34560 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (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-5760.clar b/clarity/contracts/yield-token/yield-usda-92160.clar similarity index 79% rename from clarity/contracts/yield-token/yield-usda-5760.clar rename to clarity/contracts/yield-token/yield-usda-92160.clar index b696c0b0..f59d1c54 100644 --- a/clarity/contracts/yield-token/yield-usda-5760.clar +++ b/clarity/contracts/yield-token/yield-usda-92160.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-usda-5760) +(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 u576000000000) +(define-data-var token-expiry uint u9216000000000) (define-data-var underlying-token principal .token-usda) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-usda-5760))) + (ok (decimals-to-fixed (ft-get-supply yield-usda-92160))) ) (define-read-only (get-name) - (ok "yield-usda-5760") + (ok "yield-usda-92160") ) (define-read-only (get-symbol) - (ok "yield-usda-5760") + (ok "yield-usda-92160") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-usda-5760 account))) + (ok (decimals-to-fixed (ft-get-balance yield-usda-92160 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-usda-5760 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-usda-92160 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-usda-5760 (fixed-to-decimals amount) recipient) + (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-5760 (fixed-to-decimals amount) sender) + (ft-burn? yield-usda-92160 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-usda-5760 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (try! (ft-mint? yield-usda-92160 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-11520.clar similarity index 82% rename from clarity/contracts/yield-token/yield-wbtc-34560.clar rename to clarity/contracts/yield-token/yield-wbtc-11520.clar index b0ac7876..66bed7a0 100644 --- a/clarity/contracts/yield-token/yield-wbtc-34560.clar +++ b/clarity/contracts/yield-token/yield-wbtc-11520.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-wbtc-34560) +(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 u3456000000000) +(define-data-var token-expiry uint u1152000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-34560))) + (ok (decimals-to-fixed (ft-get-supply yield-wbtc-11520))) ) (define-read-only (get-name) - (ok "yield-wbtc-34560") + (ok "yield-wbtc-11520") ) (define-read-only (get-symbol) - (ok "yield-wbtc-34560") + (ok "yield-wbtc-11520") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-34560 account))) + (ok (decimals-to-fixed (ft-get-balance yield-wbtc-11520 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-wbtc-34560 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-wbtc-11520 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (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) + (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-34560 (fixed-to-decimals amount) sender) + (ft-burn? yield-wbtc-11520 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-wbtc-34560 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (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-40555.clar b/clarity/contracts/yield-token/yield-wbtc-51840.clar similarity index 82% rename from clarity/contracts/yield-token/yield-wbtc-40555.clar rename to clarity/contracts/yield-token/yield-wbtc-51840.clar index e7939648..9e4a2336 100644 --- a/clarity/contracts/yield-token/yield-wbtc-40555.clar +++ b/clarity/contracts/yield-token/yield-wbtc-51840.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-wbtc-40555) +(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 u4055500000000) +(define-data-var token-expiry uint u5184000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-40555))) + (ok (decimals-to-fixed (ft-get-supply yield-wbtc-51840))) ) (define-read-only (get-name) - (ok "yield-wbtc-40555") + (ok "yield-wbtc-51840") ) (define-read-only (get-symbol) - (ok "yield-wbtc-40555") + (ok "yield-wbtc-51840") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-40555 account))) + (ok (decimals-to-fixed (ft-get-balance yield-wbtc-51840 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-wbtc-40555 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-wbtc-51840 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-40555 (fixed-to-decimals amount) recipient) + (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-40555 (fixed-to-decimals amount) sender) + (ft-burn? yield-wbtc-51840 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-wbtc-40555 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (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-5760.clar b/clarity/contracts/yield-token/yield-wbtc-92160.clar similarity index 79% rename from clarity/contracts/yield-token/yield-wbtc-5760.clar rename to clarity/contracts/yield-token/yield-wbtc-92160.clar index c8d1b274..eada6850 100644 --- a/clarity/contracts/yield-token/yield-wbtc-5760.clar +++ b/clarity/contracts/yield-token/yield-wbtc-92160.clar @@ -1,11 +1,11 @@ (impl-trait .trait-ownable.ownable-trait) (impl-trait .trait-yield-token.yield-token-trait) -(define-fungible-token yield-wbtc-5760) +(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 u576000000000) +(define-data-var token-expiry uint u9216000000000) (define-data-var underlying-token principal .token-wbtc) ;; errors @@ -41,15 +41,15 @@ ;; --------------------------------------------------------- (define-read-only (get-total-supply) - (ok (decimals-to-fixed (ft-get-supply yield-wbtc-5760))) + (ok (decimals-to-fixed (ft-get-supply yield-wbtc-92160))) ) (define-read-only (get-name) - (ok "yield-wbtc-5760") + (ok "yield-wbtc-92160") ) (define-read-only (get-symbol) - (ok "yield-wbtc-5760") + (ok "yield-wbtc-92160") ) (define-read-only (get-decimals) @@ -57,7 +57,7 @@ ) (define-read-only (get-balance (account principal)) - (ok (decimals-to-fixed (ft-get-balance yield-wbtc-5760 account))) + (ok (decimals-to-fixed (ft-get-balance yield-wbtc-92160 account))) ) (define-public (set-token-uri (value (string-utf8 256))) @@ -74,7 +74,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? yield-wbtc-5760 (fixed-to-decimals amount) sender recipient) + (match (ft-transfer? yield-wbtc-92160 (fixed-to-decimals amount) sender recipient) response (begin (print memo) (ok response) @@ -87,14 +87,14 @@ (define-public (mint (recipient principal) (amount uint)) (begin (asserts! (is-eq contract-caller (var-get contract-owner)) ERR-NOT-AUTHORIZED) - (ft-mint? yield-wbtc-5760 (fixed-to-decimals amount) recipient) + (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-5760 (fixed-to-decimals amount) sender) + (ft-burn? yield-wbtc-92160 (fixed-to-decimals amount) sender) ) ) @@ -108,5 +108,5 @@ ;; Initialize the contract for Testing. (begin - (try! (ft-mint? yield-wbtc-5760 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 + (try! (ft-mint? yield-wbtc-92160 u2000000000000 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)) ;;wallet_1 ) \ No newline at end of file diff --git a/clarity/tests/collateral-rebalancing-pool_test.ts b/clarity/tests/collateral-rebalancing-pool_test.ts index 65018401..67b27eb5 100644 --- a/clarity/tests/collateral-rebalancing-pool_test.ts +++ b/clarity/tests/collateral-rebalancing-pool_test.ts @@ -102,38 +102,38 @@ Clarinet.test({ position['moving-average'].expectUint(moving_average); // arbtrageur selling 100 usda for wbtc - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(100 * ONE_8); position['dy'].expectUint(199764); // arbtrageur selling 0.002 wbtc for usda - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.002 * ONE_8); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.002 * ONE_8, 0); position = result.expectOk().expectTuple(); - position['dx'].expectUint(22007078006); + position['dx'].expectUint(18384661200); position['dy'].expectUint(0.002 * ONE_8); // 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); position = result.expectOk().expectTuple(); - position['dy'].expectUint(8044367); - position['dx'].expectUint(8044549); + position['dy'].expectUint(8038536); + position['dx'].expectUint(8038686); // supply increased call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['balance-x'].expectUint(3575918101994); + position['balance-x'].expectUint(3579540518800); position['balance-y'].expectUint(38322648); - position['yield-supply'].expectUint(88851727); - position['key-supply'].expectUint(88851727); + position['yield-supply'].expectUint(88845896); + position['key-supply'].expectUint(88845896); // pool value increases after adding positions call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(109841010); + call.result.expectOk().expectUint(109913458); call = await CRPTest.getPoolValueInCollateral(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(5492050501994) + call.result.expectOk().expectUint(5495672918800) // let's check what is the weight to wbtc (token) call = await CRPTest.getWeightY(wbtcAddress, usdaAddress, expiry, 50000 * ONE_8, bs_vol); @@ -151,18 +151,18 @@ Clarinet.test({ call.result.expectOk().expectUint(10056633); // arbtrageur selling 100 usda for wbtc - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(100 * ONE_8); - position['dy'].expectUint(116875); + position['dy'].expectUint(116756); // swap triggers weight change call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); position['weight-y'].expectUint(10056633); position['weight-x'].expectUint(ONE_8 - 10056633); - position['yield-supply'].expectUint(88851727); - position['key-supply'].expectUint(88851727); + position['yield-supply'].expectUint(88845896); + position['key-supply'].expectUint(88845896); // simulate to half way to expiry chain.mineEmptyBlockUntil((expiry / ONE_8) / 2) @@ -176,17 +176,17 @@ Clarinet.test({ call.result.expectOk().expectUint(92358839); // arbtrageur selling 100 usda for wbtc - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(100 * ONE_8); - position['dy'].expectUint(939812); + position['dy'].expectUint(938875); call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); position['weight-y'].expectUint(92358839); position['weight-x'].expectUint(ONE_8 - 92358839); - position['yield-supply'].expectUint(88851727); - position['key-supply'].expectUint(88851727); + position['yield-supply'].expectUint(88845896); + position['key-supply'].expectUint(88845896); // simulate to 3 / 4 to expiry chain.mineEmptyBlockUntil((expiry / ONE_8) * 3 / 4) @@ -197,31 +197,31 @@ Clarinet.test({ // we hold over 60% in usda, so pool value in wbtc goes down call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(91749568); + call.result.expectOk().expectUint(91805509); // and ltv crossed conversion_ltv call = await CRPTest.getLtv(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(96841575); + call.result.expectOk().expectUint(96776214); // crossing convertion_ltv triggers 100% allocation to collateral call = await CRPTest.getWeightY(wbtcAddress, usdaAddress, expiry, 50000 * ONE_8, bs_vol); call.result.expectOk().expectUint(99900000); // arbtrageur selling 100 usda for wbtc - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 100 * ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(100 * ONE_8); - position['dy'].expectUint(8558); + position['dy'].expectUint(8550); // swap triggers weight change - once crossed conversion_ltv, all in token call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); position['weight-y'].expectUint(99900000); position['weight-x'].expectUint(ONE_8 - 99900000); - position['yield-supply'].expectUint(88851727); - position['key-supply'].expectUint(88851727); - position['balance-x'].expectUint(3605918101994); - position['balance-y'].expectUint(37257403); + position['yield-supply'].expectUint(88845896); + position['key-supply'].expectUint(88845896); + position['balance-x'].expectUint(3609540518800); + position['balance-y'].expectUint(37258467); // simulate to expiry chain.mineEmptyBlockUntil((expiry / ONE_8)) @@ -242,16 +242,16 @@ Clarinet.test({ call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['balance-x'].expectUint(3605918101994); - position['balance-y'].expectUint(37257403); - position['yield-supply'].expectUint(88851727); - position['key-supply'].expectUint(88851727); + position['balance-x'].expectUint(3609540518800); + position['balance-y'].expectUint(37258467); + position['yield-supply'].expectUint(88845896); + position['key-supply'].expectUint(88845896); call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(91892525); + call.result.expectOk().expectUint(91948474); call = await CRPTest.getLtv(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(96690919); + call.result.expectOk().expectUint(96625742); // deployer holds less than total supply because he sold some yield-wbtc for wbtc result = CRPTest.reducePositionYield(deployer, wbtcAddress, usdaAddress, yieldwbtc59760Address, ONE_8); @@ -263,39 +263,39 @@ Clarinet.test({ call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); position['balance-x'].expectUint(0); - position['balance-y'].expectUint(9899567); - position['yield-supply'].expectUint(8044367); - position['key-supply'].expectUint(88851727); + position['balance-y'].expectUint(9899726); + position['yield-supply'].expectUint(8038536); + position['key-supply'].expectUint(88845896); call = await CRPTest.getPoolValueInToken(wbtcAddress, usdaAddress, expiry); - call.result.expectOk().expectUint(9899567); + call.result.expectOk().expectUint(9899726); call = await CRPTest.getPositionGivenBurnKey(wbtcAddress, usdaAddress, expiry, ONE_8); position = call.result.expectOk().expectTuple(); position['dx'].expectUint(0); - position['dy'].expectUint(2087972); + position['dy'].expectUint(2094851); call = chain.callReadOnlyFn("key-wbtc-59760-usda", "get-balance", [types.principal(deployer.address) ], deployer.address); - call.result.expectOk().expectUint(88851727); + call.result.expectOk().expectUint(88845896); call = chain.callReadOnlyFn("key-wbtc-59760-usda", "get-total-supply", [], deployer.address); - call.result.expectOk().expectUint(88851727); + call.result.expectOk().expectUint(88845896); // also remove all key tokens result = CRPTest.reducePositionKey(deployer, wbtcAddress, usdaAddress, keywbtc59760Address, ONE_8); position = result.expectOk().expectTuple(); position['dx'].expectUint(0); - position['dy'].expectUint(1855199); + position['dy'].expectUint(1861189); call = await CRPTest.getPoolDetails(wbtcAddress, usdaAddress, expiry); position = call.result.expectOk().expectTuple(); - position['yield-supply'].expectUint(8044367); + position['yield-supply'].expectUint(8038536); position['key-supply'].expectUint(0); position['balance-x'].expectUint(0); - position['balance-y'].expectUint(8044368); + position['balance-y'].expectUint(8038537); }, }); @@ -414,10 +414,10 @@ Clarinet.test({ // let's do some arb call = await FWPTest.getYgivenPrice(wbtcAddress, usdaAddress, weightX, weightY, Math.round(wbtcPrice * 1.25)); call.result.expectOk().expectUint(52654365137886); - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 52654365137886) + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 52654365137886, 0) call = await FWPTest.getYgivenPrice(wbtcAddress, usdaAddress, weightX, weightY, Math.round(wbtcPrice * 1.25 * 1.2)); call.result.expectOk().expectUint(47460820304103); - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 47460820304103) + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 47460820304103, 0) // simulate to expiry + 1 chain.mineEmptyBlockUntil((expiry / ONE_8) + 1) @@ -554,7 +554,7 @@ Clarinet.test({ call = await CRPTest.getXgivenPrice(wbtcAddress, usdaAddress, expiry, Math.round( ONE_8 / (wbtcPrice * 1.1 / ONE_8))); call.result.expectOk().expectUint(111379129197); - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 111379129197); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 111379129197, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(111379129197); position['dy'].expectUint(2127973); @@ -566,9 +566,9 @@ Clarinet.test({ call = await CRPTest.getYgivenPrice(wbtcAddress, usdaAddress, expiry, Math.round( ONE_8 / (wbtcPrice * 1.1 * 0.98/ ONE_8))); call.result.expectOk().expectUint(1223378); - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 1223378); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 1223378, 0); position = result.expectOk().expectTuple(); - position['dx'].expectUint(256645012356); + position['dx'].expectUint(76010081782); position['dy'].expectUint(1223378); }, }); @@ -590,7 +590,7 @@ Clarinet.test({ result.expectOk().expectBool(true); // sell some yield-token to create a positive yield - result = YTPTest.swapYForX(wallet_1, yieldwbtc59760Address, wbtcAddress, 5*ONE_8); + result = YTPTest.swapYForX(wallet_1, yieldwbtc59760Address, wbtcAddress, 5*ONE_8, 0); let position:any = result.expectOk().expectTuple(); let call = await YTPTest.getPrice(yieldwbtc59760Address); @@ -634,7 +634,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(9516775442); - result = CRPTest.swapXForY(wallet_1, wbtcAddress, wbtcAddress, expiry, 9516775442); + result = CRPTest.swapXForY(wallet_1, wbtcAddress, wbtcAddress, expiry, 9516775442, 0); position = result.expectErr().expectUint(2001); }, }); @@ -704,37 +704,37 @@ Clarinet.test({ position = result.expectErr().expectUint(4002) // arbtrageur attepmts to swap zero value - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 0); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 0, 0); position = result.expectErr().expectUint(2003) // arbtrageur attepmts to swap small value - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 0.1* ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, 0.1* ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(0.1* ONE_8); position['dy'].expectUint(198); // arbtrageur attepmts to swap in full value - result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, ONE_8 * ONE_8); + result = CRPTest.swapXForY(deployer, wbtcAddress, usdaAddress, expiry, ONE_8 * ONE_8, 0); position = result.expectErr().expectUint(4001) // arbtrageur attepmts to swap zero value - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0, 0); position = result.expectErr().expectUint(2003) // arbtrageur attepmts to swap small value - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.000001 * ONE_8); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.000001 * ONE_8, 0); position = result.expectOk().expectTuple(); - position['dx'].expectUint(10545754); + position['dx'].expectUint(8782583); position['dy'].expectUint(0.000001 * ONE_8); // arbtrageur attepmts to swap in full value - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, ONE_8 * ONE_8); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, ONE_8 * ONE_8, 0); position = result.expectErr().expectUint(4002) // arbtrageur selling 0.01 wbtc for usda - result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.01 * ONE_8); + result = CRPTest.swapYForX(deployer, wbtcAddress, usdaAddress, expiry, 0.01 * ONE_8, 0); position = result.expectOk().expectTuple(); - position['dx'].expectUint(111855897259); + position['dx'].expectUint(93241485590); position['dy'].expectUint(0.01 * ONE_8); // simulate to expiry + 1 @@ -785,7 +785,7 @@ Clarinet.test({ result.expectErr().expectUint(2001); result = await CRPTest.getXgivenY(deployer, wbtcAddress, usdaAddress, expiry, 500); - result.expectOk().expectUint(98205150); + result.expectOk().expectUint(24684357); result = await CRPTest.getXgivenY(deployer, wbtcAddress, usdaAddress, expiry, 0); result.expectOk().expectUint(0); diff --git a/clarity/tests/fixed-weight-pool_test.ts b/clarity/tests/fixed-weight-pool_test.ts index 1880d356..2c23daab 100644 --- a/clarity/tests/fixed-weight-pool_test.ts +++ b/clarity/tests/fixed-weight-pool_test.ts @@ -81,25 +81,25 @@ Clarinet.test({ position['dy'].expectUint(500000000000000); // attempt to trade too much (> 90%) will be rejected - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 91*ONE_8); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 91*ONE_8, 0); position = result.expectErr().expectUint(4001); // swap some wbtc into usda - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(ONE_8); position['dy'].expectUint(4950465000000); // swap some usda into wbtc - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, wbtcPrice*ONE_8); + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, wbtcPrice*ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(103049997); position['dy'].expectUint(wbtcPrice*ONE_8); // attempt to swap zero throws an error - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0); + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0, 0); result.expectErr().expectUint(2003); - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0, 0); result.expectErr().expectUint(2003); }, }); @@ -168,13 +168,13 @@ Clarinet.test({ result.expectOk().expectUint(5000000) // Swapping - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(95000000); // 5% Fee Charged on ONE_8 position['dy'].expectUint(4714125000000); // Corresponding dy value // Swapping - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8*wbtcPrice); + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8*wbtcPrice, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(97192466); // Corresponding dx value position['dy'].expectUint(4750000000000); // 5% Fee Charged on ONE_8*wbtcPrice @@ -232,17 +232,17 @@ Clarinet.test({ result.expectErr().expectUint(3000); // Swapping - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8, 0); position = result.expectOk().expectTuple(); position['dx'].expectUint(ONE_8); position['dy'].expectUint(4960262500000); // Attempts to trade more than limit - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8*ONE_8); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, ONE_8*ONE_8, 0); result.expectErr().expectUint(4001); // Zero swapping - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0); + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 0, 0); result.expectErr().expectUint(2003); // Fee Setting @@ -321,7 +321,7 @@ Clarinet.test({ // let's do some arb call = await FWPTest.getYgivenPrice(wbtcAddress, usdaAddress, weightX, weightY, wbtcPrice*ONE_8*1.1); call.result.expectOk().expectUint(23268715000000); - result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 23268715000000) + result = FWPTest.swapYForX(deployer, wbtcAddress, usdaAddress, weightX, weightY, 23268715000000, 0) position = result.expectOk().expectTuple(); position['dy'].expectUint(23268715000000); position['dx'].expectUint(488087600); @@ -344,7 +344,7 @@ Clarinet.test({ // we need to call get-x-given-price call = await FWPTest.getXgivenPrice(wbtcAddress, usdaAddress, weightX, weightY, wbtcPrice*ONE_8*1.1 *0.95); call.result.expectOk().expectUint(248161895); - result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 248161895) + result = FWPTest.swapXForY(deployer, wbtcAddress, usdaAddress, weightX, weightY, 248161895, 0) position = result.expectOk().expectTuple(); position['dx'].expectUint(248161895); position['dy'].expectUint(13304708837897); diff --git a/clarity/tests/flash-loan_test.ts b/clarity/tests/flash-loan_test.ts index 51b0579b..3c6a040c 100644 --- a/clarity/tests/flash-loan_test.ts +++ b/clarity/tests/flash-loan_test.ts @@ -87,7 +87,7 @@ Clarinet.test({ call.result.expectOk().expectUint(74520874); // sell some yield-token - result = YTPTest.swapYForX(wallet_1, yieldusda23040Address, usdaAddress, 10000*ONE_8); + result = YTPTest.swapYForX(wallet_1, yieldusda23040Address, usdaAddress, 10000*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(1000041600834); position['dy'].expectUint(10000*ONE_8); diff --git a/clarity/tests/liquidity-bootstrapping-pool_test.ts b/clarity/tests/liquidity-bootstrapping-pool_test.ts new file mode 100644 index 00000000..d867fff7 --- /dev/null +++ b/clarity/tests/liquidity-bootstrapping-pool_test.ts @@ -0,0 +1,162 @@ + +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'; + +// Deployer Address Constants +const usdaAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-usda" +const alexAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.token-alex" +const poolTokenAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.lbp-alex-usda-90-10" +const multisigAddress = "ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.multisig-lbp-alex-usda-90-10" + +const ONE_8 = 1e+8; + +const weightX1 = 0.9 * ONE_8; +const weightX2 = 0.1 * ONE_8; +const expiry = 1000 * ONE_8; + +const priceMax = 1.5 * ONE_8; +const priceMin = 0.1 * ONE_8; +const price0 = 1 * ONE_8; + +const alexQty = 1000 * ONE_8; +const usdaQty = Math.round(price0 * alexQty * (ONE_8 - weightX1) / weightX1 / ONE_8); + + +Clarinet.test({ + name: "LBP : Pool creation, adding values and reducing values", + + async fn(chain: Chain, accounts: Map) { + let deployer = accounts.get("deployer")!; + let LBPTest = new LBPTestAgent(chain, deployer); + + let call = chain.callReadOnlyFn("token-alex", "get-balance", + [types.principal(deployer.address) + ], deployer.address); + call.result.expectOk().expectUint(10000 * 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 position:any = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(80274141756); + position['balance-x'].expectUint(alexQty); + position['balance-y'].expectUint(usdaQty); + position['weight-x-t'].expectUint(90000000); + + result = LBPTest.setPoolMultisig(deployer, alexAddress, usdaAddress, expiry, deployer.address); + result.expectOk(); + + result = LBPTest.setPriceRange(deployer, alexAddress, usdaAddress, expiry, priceMin, priceMax); + result.expectOk(); + + call = await LBPTest.getPriceRange(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['min-price'].expectUint(priceMin); + position['max-price'].expectUint(priceMax); + + // implied price is 0.995064480178316 + result = LBPTest.swapYForX(deployer, alexAddress, usdaAddress, expiry, ONE_8, 0); + position = result.expectOk().expectTuple(); + position['dy'].expectUint(ONE_8); + position['dx'].expectUint(100496000); + + // swap triggers change in weight + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['weight-x-t'].expectUint(89759760); + + // half time passed + chain.mineEmptyBlockUntil(500); + + // no swaps, so weight shouldn't have changed. + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['weight-x-t'].expectUint(89759760); + + // buy some alex so it doesn't fall below min-price. + result = LBPTest.swapYForX(deployer, alexAddress, usdaAddress, expiry, 30 * ONE_8, 0); + position = result.expectOk().expectTuple(); + position['dy'].expectUint(30 * ONE_8); + position['dx'].expectUint(3613023403); + + // after swap, weight now halves. + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['weight-x-t'].expectUint(50040041); + + // implied price is now 0.14679128195479 + result = LBPTest.swapYForX(deployer, alexAddress, usdaAddress, expiry, ONE_8, 0); + position = result.expectOk().expectTuple(); + position['dy'].expectUint(ONE_8); + position['dx'].expectUint(681239367); + + // Check pool details and print + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(80274141756); + position['balance-x'].expectUint(95605241230); + position['balance-y'].expectUint(14311111111); + + // launch not going well, so withdraw liquidity + result = LBPTest.reducePosition(deployer, alexAddress, usdaAddress, expiry, poolTokenAddress, 0.5 * ONE_8); + position = result.expectOk().expectTuple(); + position['dx'].expectUint(47802620615); + position['dy'].expectUint(7155555555); + + // Check pool details and print + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(40137070878); + position['balance-x'].expectUint(47802620615); + position['balance-y'].expectUint(7155555556); + + chain.mineEmptyBlockUntil(998); + + // no trades between blocks 500 and 998, so weight doesn't change, price doesn't change + // until swap occurs. + result = LBPTest.swapYForX(deployer, alexAddress, usdaAddress, expiry, ONE_8, 0); + position = result.expectOk().expectTuple(); + position['dy'].expectUint(ONE_8); + position['dx'].expectUint(678606002); + + // and weight now is at min. + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['weight-x-t'].expectUint(10160161); + + // resulting in alex price falling below min-price, throwing error + result = LBPTest.swapYForX(deployer, alexAddress, usdaAddress, expiry, ONE_8, 0); + position = result.expectErr().expectUint(2021); + + // all time passed + chain.mineEmptyBlockUntil(1001); + + // already expired + call = await LBPTest.getWeightX(alexAddress, usdaAddress, expiry); + call.result.expectErr().expectUint(2011); + + // Check pool details and print + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(40137070878); + position['balance-x'].expectUint(47124014613); + position['balance-y'].expectUint(7255555556); + + // withdraw all remaining liquidity + result = LBPTest.reducePosition(deployer, alexAddress, usdaAddress, expiry, poolTokenAddress, ONE_8); + position = result.expectOk().expectTuple(); + position['dx'].expectUint(47124014613); + position['dy'].expectUint(7255555556); + + // Check pool details and print + call = await LBPTest.getPoolDetails(alexAddress, usdaAddress, expiry); + position = call.result.expectOk().expectTuple(); + position['total-supply'].expectUint(0); + position['balance-x'].expectUint(0); + position['balance-y'].expectUint(0); + }, +}); + diff --git a/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts b/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts index d4c80ca3..b30aff44 100644 --- a/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts +++ b/clarity/tests/models/alex-tests-collateral-rebalancing-pool.ts @@ -134,25 +134,27 @@ import { return block.receipts[0].result; } - swapXForY(user: Account, token: string, collateral: string, expiry: number, dX: number) { + swapXForY(user: Account, token: string, collateral: string, expiry: number, dX: number, dy_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "swap-x-for-y", [ types.principal(token), types.principal(collateral), types.uint(expiry), - types.uint(dX) + types.uint(dX), + types.some(types.uint(dy_min)) ], user.address), ]); return block.receipts[0].result; } - swapYForX(user: Account, token: string, collateral: string, expiry: number, dY: number) { + swapYForX(user: Account, token: string, collateral: string, expiry: number, dY: number, min_dx: number) { let block = this.chain.mineBlock([ Tx.contractCall("collateral-rebalancing-pool", "swap-y-for-x", [ types.principal(token), types.principal(collateral), types.uint(expiry), - types.uint(dY) + types.uint(dY), + types.some(types.uint(min_dx)) ], user.address), ]); return block.receipts[0].result; diff --git a/clarity/tests/models/alex-tests-fixed-weight-pool.ts b/clarity/tests/models/alex-tests-fixed-weight-pool.ts index d21434a6..7c12d52d 100644 --- a/clarity/tests/models/alex-tests-fixed-weight-pool.ts +++ b/clarity/tests/models/alex-tests-fixed-weight-pool.ts @@ -69,27 +69,29 @@ import { return block.receipts[0].result; } - swapXForY(user: Account, tokenX: string, tokenY: string, weightX: number, weightY: number, dx: number) { + swapXForY(user: Account, tokenX: string, tokenY: string, weightX: number, weightY: number, dx: number, dy_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("fixed-weight-pool", "swap-x-for-y", [ types.principal(tokenX), types.principal(tokenY), types.uint(weightX), types.uint(weightY), - types.uint(dx) + types.uint(dx), + types.some(types.uint(dy_min)) ], user.address), ]); return block.receipts[0].result; } - swapYForX(user: Account, tokenX: string, tokenY: string, weightX: number, weightY: number, dy: number) { + swapYForX(user: Account, tokenX: string, tokenY: string, weightX: number, weightY: number, dy: number, dx_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("fixed-weight-pool", "swap-y-for-x", [ types.principal(tokenX), types.principal(tokenY), types.uint(weightX), types.uint(weightY), - types.uint(dy) + types.uint(dy), + types.some(types.uint(dx_min)) ], user.address), ]); return block.receipts[0].result; diff --git a/clarity/tests/models/alex-tests-liquidity-bootstrapping-pool.ts b/clarity/tests/models/alex-tests-liquidity-bootstrapping-pool.ts new file mode 100644 index 00000000..b6a1bf62 --- /dev/null +++ b/clarity/tests/models/alex-tests-liquidity-bootstrapping-pool.ts @@ -0,0 +1,130 @@ +import { + Account, + Chain, + Clarinet, + Tx, + types, + } from "https://deno.land/x/clarinet@v0.14.0/index.ts"; + + class LBPTestAgent { + chain: Chain; + deployer: Account; + + constructor(chain: Chain, deployer: Account) { + this.chain = chain; + this.deployer = deployer; + } + + getPoolDetails(tokenX: string, tokenY: string, expiry: number) { + return this.chain.callReadOnlyFn("liquidity-bootstrapping-pool", "get-pool-details", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + ], this.deployer.address); + } + + createPool(user: Account, tokenX: string, tokenY: string, weightX1: number, weightX2: number, expiry :number, pooltoken: string, multisig: string, dX: number, dY: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("liquidity-bootstrapping-pool", "create-pool", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(weightX1), + types.uint(weightX2), + types.uint(expiry), + types.principal(pooltoken), + types.principal(multisig), + types.uint(dX), + types.uint(dY), + ], user.address), + ]); + return block.receipts[0].result; + } + + setPriceRange(user: Account, tokenX: string, tokenY: string, expiry :number, min_price: number, max_price: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("liquidity-bootstrapping-pool", "set-price-range", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.uint(min_price), + types.uint(max_price) + ], user.address), + ]); + return block.receipts[0].result; + } + + getPriceRange(tokenX: string, tokenY: string, expiry: number) { + return this.chain.callReadOnlyFn("liquidity-bootstrapping-pool", "get-price-range", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry) + ], this.deployer.address); + } + + getWeightX(tokenX: string, tokenY: string, expiry: number) { + return this.chain.callReadOnlyFn("liquidity-bootstrapping-pool", "get-weight-x", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry) + ], this.deployer.address); + } + + setPoolMultisig(user: Account, tokenX: string, tokenY: string, expiry :number, new_multisig: string) { + let block = this.chain.mineBlock([ + Tx.contractCall("liquidity-bootstrapping-pool", "set-pool-multisig", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.principal(new_multisig) + ], user.address), + ]); + return block.receipts[0].result; + } + + reducePosition(user: Account, tokenX: string, tokenY: string, expiry :number, pooltoken: string, percentage: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("liquidity-bootstrapping-pool", "reduce-position", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.principal(pooltoken), + types.uint(percentage), + ], user.address), + ]); + return block.receipts[0].result; + } + + swapYForX(user: Account, tokenX: string, tokenY: string, expiry: number, dy: number, min_dx: number) { + let block = this.chain.mineBlock([ + Tx.contractCall("liquidity-bootstrapping-pool", "swap-y-for-x", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.uint(dy), + types.some(types.uint(min_dx)) + ], user.address), + ]); + return block.receipts[0].result; + } + + getXgivenY(tokenX: string, tokenY: string, expiry: number, dy: number) { + return this.chain.callReadOnlyFn("liquidity-bootstrapping-pool", "get-x-given-y", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.uint(dy) + ], this.deployer.address); + } + + getYgivenX(tokenX: string, tokenY: string, expiry: number, dx: number) { + return this.chain.callReadOnlyFn("liquidity-bootstrapping-pool", "get-y-given-x", [ + types.principal(tokenX), + types.principal(tokenY), + types.uint(expiry), + types.uint(dx) + ], this.deployer.address); + } + + } + + export { LBPTestAgent }; \ No newline at end of file diff --git a/clarity/tests/models/alex-tests-yield-token-pool.ts b/clarity/tests/models/alex-tests-yield-token-pool.ts index c1d33ff2..7b5fcb1e 100644 --- a/clarity/tests/models/alex-tests-yield-token-pool.ts +++ b/clarity/tests/models/alex-tests-yield-token-pool.ts @@ -78,23 +78,25 @@ import { return block.receipts[0].result; } - swapXForY(user: Account, aytoken: string, token: string, dX: number) { + swapXForY(user: Account, aytoken: string, token: string, dX: number, dy_min: number) { let block = this.chain.mineBlock([ Tx.contractCall("yield-token-pool", "swap-x-for-y", [ types.principal(aytoken), types.principal(token), - types.uint(dX) + types.uint(dX), + types.some(types.uint(dy_min)) ], user.address), ]); return block.receipts[0].result; } - swapYForX(user: Account, aytoken: string, token: string, dY: number) { + swapYForX(user: Account, 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.principal(token), - types.uint(dY) + types.uint(dY), + types.some(types.uint(dx_min)) ], user.address), ]); return block.receipts[0].result; diff --git a/clarity/tests/token-alex-src/Clarinet.toml b/clarity/tests/token-alex-src/Clarinet.toml deleted file mode 100644 index 42d85e59..00000000 --- a/clarity/tests/token-alex-src/Clarinet.toml +++ /dev/null @@ -1,264 +0,0 @@ -[project] -name = "alex-v1" -requirements = [] -[contracts.alex-reserve-pool] -path = "contracts/pool/alex-reserve-pool.clar" -depends_on = ["token-alex", "token-usda", "open-oracle", "math-fixed-point", "trait-ownable"] - -[contracts.alex-vault] -path = "contracts/alex-vault.clar" -depends_on = ["trait-vault", "trait-sip-010", "trait-flash-loan-user", "math-fixed-point", "trait-ownable"] - -[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", "open-oracle", "fixed-weight-pool", "token-usda", "token-alex", "alex-reserve-pool", "yield-token-pool"] - -[contracts.faucet] -path = "contracts/faucet.clar" -depends_on = ["token-wbtc", "token-usda"] - -[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", "open-oracle", "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"] - -[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", "open-oracle", "alex-reserve-pool", "token-usda", "fixed-weight-pool", "trait-multisig-vote"] - -[contracts.math-fixed-point] -path = "contracts/lib/math-fixed-point.clar" -depends_on = ["math-log-exp"] - -[contracts.math-log-exp] -path = "contracts/lib/math-log-exp.clar" -depends_on = [] - -[contracts.math-new-fixed-point] -path = "contracts/new-lib/math-new-fixed-point.clar" -depends_on = ["math-new-log-exp"] - -[contracts.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.open-oracle] -path = "contracts/open-oracle.clar" -depends_on = ["trait-yield-token", "trait-oracle", "trait-sip-010"] - -[contracts.token-usda] -path = "contracts/token/token-usda.clar" -depends_on = ["trait-pool-token", "trait-ownable"] - -[contracts.token-wbtc] -path = "contracts/token/token-wbtc.clar" -depends_on = ["trait-pool-token", "trait-ownable"] - -[contracts.trait-flash-loan-user] -path = "contracts/traits/trait-flash-loan-user.clar" -depends_on = ["trait-sip-010"] - -[contracts.trait-multisig-vote] -path = "contracts/traits/trait-multisig-vote.clar" -depends_on = ["trait-sip-010"] - -[contracts.trait-oracle] -path = "contracts/traits/trait-oracle.clar" -depends_on = [] - -[contracts.trait-ownable] -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 = [] - -[contracts.trait-vault] -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"] - -[contracts.yield-token-equation] -path = "contracts/equations/yield-token-equation.clar" -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", "open-oracle", "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.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"] - -[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-59760-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-74880] -path = "contracts/yield-token/yield-usda-74880.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] - -[contract.multisig-fwp-usda-23040-usda-74880-50-50] -path = "contracts/multisig/multisig-fwp-usda-23040-usda-74880-50-50.clar" -depends_on = ["yield-usda-23040", "yield-usda-74880", "fwp-usda-23040-usda-74880", "trait-yield-token", "trait-sip-010", "yield-token-pool"] - -[contract.fwp-usda-23040-usda-74880-50-50] -path = "contracts/pool-token/fwp-usda-23040-usda-74880-50-50.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.yield-wbtc-240] -path = "contracts/yield-token/yield-wbtc-240.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.yield-usda-240] -path = "contracts/yield-token/yield-usda-240.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] - -[contracts.multisig-ytp-yield-wbtc-240-wbtc] -path = "contracts/multisig/multisig-ytp-yield-wbtc-240-wbtc.clar" -depends_on = ["ytp-yield-wbtc-240-wbtc", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-wbtc-240"] - -[contracts.multisig-ytp-yield-usda-240-usda] -path = "contracts/multisig/multisig-ytp-yield-usda-240-usda.clar" -depends_on = ["ytp-yield-usda-240-usda", "trait-yield-token", "trait-sip-010", "yield-token-pool", "yield-usda-240"] - -[contracts.flash-loan-user-margin-usda-wbtc-240] -path = "contracts/flash-loan-user-margin-usda-wbtc-240.clar" -depends_on = ["token-usda", "token-wbtc", "yield-wbtc-240", "key-wbtc-240-usda", "trait-sip-010"] - -[contracts.flash-loan-user-margin-wbtc-usda-240] -path = "contracts/flash-loan-user-margin-wbtc-usda-240.clar" -depends_on = ["token-usda", "token-wbtc", "yield-usda-240", "key-usda-240-wbtc", "trait-sip-010"] - -[contracts.multisig-crp-wbtc-240-usda] -path = "contracts/multisig/multisig-crp-wbtc-240-usda.clar" -depends_on = ["yield-wbtc-240", "key-wbtc-240-usda", "token-wbtc", "token-usda", "trait-sip-010"] - -[contracts.multisig-crp-usda-240-wbtc] -path = "contracts/multisig/multisig-crp-usda-240-wbtc.clar" -depends_on = ["yield-usda-240", "key-usda-240-wbtc", "token-usda", "token-wbtc", "trait-sip-010"] - -[contracts.stacked-poxl-pool] -path = "contracts/pool/stacked-poxl-pool.clar" -depends_on = [] - -[contracts.token-alex-vrf] -path = "contracts/token/token-alex-vrf.clar" -depends_on = [] - -[contracts.token-alex-core-trait] -path = "contracts/token/token-alex-core-trait.clar" -depends_on = [] - -[contracts.token-alex] -path = "contracts/token/token-alex.clar" -depends_on = ["trait-ownable", "trait-sip-010", "token-alex-auth", "token-alex-trait"] - -[contracts.token-alex-core-v1] -path = "contracts/token/token-alex-core-v1.clar" -depends_on = ["token-alex-auth", "token-alex", "token-alex-vrf", "token-alex-core-trait"] - - -[contracts.key-wbtc-240-usda] -path = "contracts/key-token/key-wbtc-240-usda.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-wbtc", "trait-ownable"] - -[contracts.key-usda-240-wbtc] -path = "contracts/key-token/key-usda-240-wbtc.clar" -depends_on = ["trait-sip-010", "trait-yield-token", "token-usda", "trait-ownable"] - -[contracts.ytp-yield-wbtc-240-wbtc] -path = "contracts/pool-token/ytp-yield-wbtc-240-wbtc.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] - -[contracts.ytp-yield-usda-240-usda] -path = "contracts/pool-token/ytp-yield-usda-240-usda.clar" -depends_on = ["trait-sip-010", "trait-pool-token", "trait-ownable"] diff --git a/clarity/tests/yield-token-pool_test.ts b/clarity/tests/yield-token-pool_test.ts index 08f63769..2b30dbfe 100644 --- a/clarity/tests/yield-token-pool_test.ts +++ b/clarity/tests/yield-token-pool_test.ts @@ -111,7 +111,7 @@ Clarinet.test({ call.result.expectOk().expectUint(199975237) // sell some yield-token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 2*ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 2*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(199975237); position['dy'].expectUint(2*ONE_8); @@ -132,13 +132,13 @@ Clarinet.test({ call.result.expectOk().expectUint(2847); // buy back some yield token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, 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 must throw an error - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 501*ONE_8); + // 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); position =result.expectErr().expectUint(4002) call = chain.callReadOnlyFn("yield-token-pool", "get-pool-details", @@ -156,7 +156,7 @@ Clarinet.test({ call.result.expectOk().expectUint(1426); // we sell close to maximum allowed of yield token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 29*ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 29*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(2900524394); position['dy'].expectUint(29*ONE_8); @@ -184,7 +184,7 @@ Clarinet.test({ call.result.expectOk().expectUint(21334); // sell some (a lot of) yield-token - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(10001386469); position['dy'].expectUint(100*ONE_8); @@ -196,7 +196,7 @@ Clarinet.test({ call.result.expectOk().expectUint(92959); //buy back some yield token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(100*ONE_8); position['dy'].expectUint(10005727560); @@ -259,7 +259,7 @@ Clarinet.test({ call.result.expectOk().expectUint(5); // buy some yield-token - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 19*ONE_8); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 19*ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(19*ONE_8); position['dy'].expectUint(1900033901); @@ -335,7 +335,7 @@ Clarinet.test({ call = await YTPTest.getYgivenYield(yieldwbtc59760Address, 0.001*ONE_8); call.result.expectOk().expectUint(7019668000); - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 7019668000); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 7019668000, 0); position = result.expectOk().expectTuple(); position['dy'].expectUint(7019668000); position['dx'].expectUint(7023140005); @@ -349,7 +349,7 @@ Clarinet.test({ call = await YTPTest.getXgivenYield(yieldwbtc59760Address, 0.0005*ONE_8); call.result.expectOk().expectUint(3504368516); - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 3504368516); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 3504368516, 0); position = result.expectOk().expectTuple(); position['dy'].expectUint(3507017732); position['dx'].expectUint(3504368516); @@ -398,7 +398,7 @@ Clarinet.test({ position['balance-aytoken'].expectUint(0); position['balance-virtual'].expectUint(10*ONE_8); - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(99972419); position['dy'].expectUint(ONE_8); @@ -517,43 +517,38 @@ Clarinet.test({ position =result.expectErr().expectUint(1) // False swap value -- Filter added - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0, 0); position =result.expectErr().expectUint(2003) - // False swap value -- Filter added - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.0000001 * ONE_8); - //position =result.expectErr().expectUint(2003) - position =result.expectOk().expectTuple(); - position['dx'].expectUint(0); - position['dy'].expectUint(0.0000001 * ONE_8); - // call = await YTPTest.getPoolDetails(yieldwbtc59760Address); - // position = call.result.expectErr(); + // Too small => < max-slippage + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.0000001 * ONE_8, 0); + position =result.expectErr().expectUint(2020); // Fixed - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.001 * ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, 0.001 * ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(36251); position['dy'].expectUint(0.001 * ONE_8); // Attempt for Swapping - result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8); + result = YTPTest.swapYForX(deployer, yieldwbtc59760Address, wbtcAddress, ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(99944571); position['dy'].expectUint(ONE_8); // Attempts for zero value swapping - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 0); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, 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); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 100*ONE_8, 0); position =result.expectErr().expectUint(2016) // Swap - result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 0.1 * ONE_8); + result = YTPTest.swapXForY(deployer, yieldwbtc59760Address, wbtcAddress, 0.1 * ONE_8, 0); position =result.expectOk().expectTuple(); position['dx'].expectUint(0.1 * ONE_8); - position['dy'].expectUint(10043979); + position['dy'].expectUint(10043969); }, }); \ No newline at end of file diff --git a/init-js-tool/deploy.js b/init-js-tool/deploy.js index 7fcd57ce..60c12651 100644 --- a/init-js-tool/deploy.js +++ b/init-js-tool/deploy.js @@ -11,149 +11,71 @@ const { exit } = require('process'); let contract_records = {"Contracts":[]} let VERSION; let contract_paths = [ - // "lib/math-log-exp.clar", - // "lib/math-fixed-point.clar", - // "traits/trait-sip-010.clar", - // "traits/trait-flash-loan-user.clar", - // "traits/trait-oracle.clar", - // "traits/trait-pool-token.clar", - // "traits/trait-yield-token.clar", - // "traits/trait-ownable.clar", - // "traits/trait-vault.clar", - // "traits/trait-multisig-vote.clar", - // "equations/weighted-equation.clar", - // "equations/yield-token-equation.clar", - // "token/token-alex.clar", - // "token/token-usda.clar", - // "token/token-wbtc.clar", - // "alex-vault.clar", - // "open-oracle.clar", - // "pool/alex-reserve-pool.clar", - // "pool/fixed-weight-pool.clar", - // "pool/liquidity-bootstrapping-pool.clar", - // "pool/yield-token-pool.clar", - // "pool/collateral-rebalancing-pool.clar", - // "faucet.clar", - // "pool-token/fwp-wbtc-usda-50-50.clar", - // "multisig/multisig-fwp-wbtc-usda-50-50.clar", + "lib/math-log-exp.clar", + "lib/math-fixed-point.clar", + "traits/trait-sip-010.clar", + "traits/trait-flash-loan-user.clar", + "traits/trait-oracle.clar", + "traits/trait-pool-token.clar", + "traits/trait-yield-token.clar", + "traits/trait-ownable.clar", + "traits/trait-vault.clar", + "traits/trait-multisig-vote.clar", + "equations/weighted-equation.clar", + "equations/yield-token-equation.clar", + "token/token-alex.clar", + "token/token-usda.clar", + "token/token-wbtc.clar", + "alex-vault.clar", + "open-oracle.clar", + "pool/alex-reserve-pool.clar", + "pool/fixed-weight-pool.clar", + "pool/liquidity-bootstrapping-pool.clar", + "pool/yield-token-pool.clar", + "pool/collateral-rebalancing-pool.clar", + "faucet.clar", + "pool-token/fwp-wbtc-usda-50-50.clar", + "multisig/multisig-fwp-wbtc-usda-50-50.clar", - // "yield-token/yield-wbtc-40555.clar", - // "yield-token/yield-usda-40555.clar", - // "key-token/key-usda-40555-wbtc.clar", - // "key-token/key-wbtc-40555-usda.clar", - // "pool-token/ytp-yield-wbtc-40555-wbtc.clar", - // "pool-token/ytp-yield-usda-40555-usda.clar", - // "multisig/multisig-crp-wbtc-40555-usda.clar", - // "multisig/multisig-crp-usda-40555-wbtc.clar", - // "multisig/multisig-ytp-yield-wbtc-40555-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-40555-usda.clar", - // "flash-loan-user-margin-usda-wbtc-40555.clar", - // "flash-loan-user-margin-wbtc-usda-40555.clar", + "yield-token/yield-wbtc-11520.clar", + "yield-token/yield-usda-11520.clar", + "key-token/key-usda-11520-wbtc.clar", + "key-token/key-wbtc-11520-usda.clar", + "pool-token/ytp-yield-wbtc-11520-wbtc.clar", + "pool-token/ytp-yield-usda-11520-usda.clar", + "multisig/multisig-crp-wbtc-11520-usda.clar", + "multisig/multisig-crp-usda-11520-wbtc.clar", + "multisig/multisig-ytp-yield-wbtc-11520-wbtc.clar", + "multisig/multisig-ytp-yield-usda-11520-usda.clar", + "flash-loan-user-margin-usda-wbtc-11520.clar", + "flash-loan-user-margin-wbtc-usda-11520.clar", - // "yield-token/yield-wbtc-5760.clar", - // "yield-token/yield-usda-5760.clar", - // "key-token/key-usda-5760-wbtc.clar", - // "key-token/key-wbtc-5760-usda.clar", - // "pool-token/ytp-yield-wbtc-5760-wbtc.clar", - // "pool-token/ytp-yield-usda-5760-usda.clar", - // "multisig/multisig-crp-wbtc-5760-usda.clar", - // "multisig/multisig-crp-usda-5760-wbtc.clar", - // "multisig/multisig-ytp-yield-wbtc-5760-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-5760-usda.clar", - // "flash-loan-user-margin-usda-wbtc-5760.clar", - // "flash-loan-user-margin-wbtc-usda-5760.clar", + "yield-token/yield-wbtc-51840.clar", + "yield-token/yield-usda-51840.clar", + "key-token/key-usda-51840-wbtc.clar", + "key-token/key-wbtc-51840-usda.clar", + "pool-token/ytp-yield-wbtc-51840-wbtc.clar", + "pool-token/ytp-yield-usda-51840-usda.clar", + "multisig/multisig-crp-wbtc-51840-usda.clar", + "multisig/multisig-crp-usda-51840-wbtc.clar", + "multisig/multisig-ytp-yield-wbtc-51840-wbtc.clar", + "multisig/multisig-ytp-yield-usda-51840-usda.clar", + "flash-loan-user-margin-usda-wbtc-51840.clar", + "flash-loan-user-margin-wbtc-usda-51840.clar", - // "yield-token/yield-wbtc-80875.clar", - // "yield-token/yield-usda-80875.clar", - // "key-token/key-usda-80875-wbtc.clar", - // "key-token/key-wbtc-80875-usda.clar", - // "pool-token/ytp-yield-wbtc-80875-wbtc.clar", - // "pool-token/ytp-yield-usda-80875-usda.clar", - // "multisig/multisig-crp-wbtc-80875-usda.clar", - // "multisig/multisig-crp-usda-80875-wbtc.clar", - // "multisig/multisig-ytp-yield-wbtc-80875-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-80875-usda.clar", - // "flash-loan-user-margin-usda-wbtc-80875.clar", - // "flash-loan-user-margin-wbtc-usda-80875.clar", - - // "pool-token/ytp-yield-wbtc-23040-wbtc.clar", - // "yield-token/yield-wbtc-23040.clar", - // "key-token/key-wbtc-23040-usda.clar", - // "multisig/multisig-crp-wbtc-23040-usda.clar", - // "multisig/multisig-ytp-yield-wbtc-23040-wbtc.clar", - // "flash-loan-user-margin-usda-wbtc-23040.clar", - // "pool-token/ytp-yield-usda-23040-usda.clar", - // "yield-token/yield-usda-23040.clar", - // "key-token/key-usda-23040-wbtc.clar", - // "multisig/multisig-crp-usda-23040-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-23040-usda.clar", - // "flash-loan-user-margin-wbtc-usda-23040.clar", - - // "pool-token/ytp-yield-wbtc-34560-wbtc.clar", - // "yield-token/yield-wbtc-34560.clar", - // "key-token/key-wbtc-34560-usda.clar", - // "multisig/multisig-crp-wbtc-34560-usda.clar", - // "multisig/multisig-ytp-yield-wbtc-34560-wbtc.clar", - // "flash-loan-user-margin-usda-wbtc-34560.clar", - // "pool-token/ytp-yield-usda-34560-usda.clar", - // "yield-token/yield-usda-34560.clar", - // "key-token/key-usda-34560-wbtc.clar", - // "multisig/multisig-crp-usda-34560-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-34560-usda.clar", - // "flash-loan-user-margin-wbtc-usda-34560.clar", - - // "pool-token/ytp-yield-wbtc-121195-wbtc.clar", - // "yield-token/yield-wbtc-121195.clar", - // "key-token/key-wbtc-121195-usda.clar", - // "multisig/multisig-crp-wbtc-121195-usda.clar", - // "multisig/multisig-ytp-yield-wbtc-121195-wbtc.clar", - // "flash-loan-user-margin-usda-wbtc-121195.clar", - // "pool-token/ytp-yield-usda-121195-usda.clar", - // "key-token/key-usda-121195-wbtc.clar", - // "yield-token/yield-usda-121195.clar", - // "multisig/multisig-crp-usda-121195-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-121195-usda.clar", - // "flash-loan-user-margin-wbtc-usda-121195.clar", - - // "pool-token/ytp-yield-wbtc-161515-wbtc.clar", - // "yield-token/yield-wbtc-161515.clar", - // "key-token/key-wbtc-161515-usda.clar", - // "multisig/multisig-crp-wbtc-161515-usda.clar", - // "multisig/multisig-ytp-yield-wbtc-161515-wbtc.clar", - // "flash-loan-user-margin-usda-wbtc-161515.clar", - // "pool-token/ytp-yield-usda-161515-usda.clar", - // "key-token/key-usda-161515-wbtc.clar", - // "yield-token/yield-usda-161515.clar", - // "multisig/multisig-crp-usda-161515-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-161515-usda.clar", - // "flash-loan-user-margin-wbtc-usda-161515.clar", - - // "pool-token/ytp-yield-wbtc-200335-wbtc.clar", - // "yield-token/yield-wbtc-200335.clar", - // "key-token/key-wbtc-200335-usda.clar", - // "multisig/multisig-crp-wbtc-200335-usda.clar", - // "multisig/multisig-ytp-yield-wbtc-200335-wbtc.clar", - // "flash-loan-user-margin-usda-wbtc-200335.clar", - // "pool-token/ytp-yield-usda-200335-usda.clar", - // "key-token/key-usda-200335-wbtc.clar", - // "yield-token/yield-usda-200335.clar", - // "multisig/multisig-crp-usda-200335-wbtc.clar", - // "multisig/multisig-ytp-yield-usda-200335-usda.clar", - // "flash-loan-user-margin-wbtc-usda-200335.clar", - - "pool-token/ytp-yield-wbtc-240655-wbtc.clar", - "yield-token/yield-wbtc-240655.clar", - "key-token/key-wbtc-240655-usda.clar", - "multisig/multisig-crp-wbtc-240655-usda.clar", - "multisig/multisig-ytp-yield-wbtc-240655-wbtc.clar", - "flash-loan-user-margin-usda-wbtc-240655.clar", - "pool-token/ytp-yield-usda-240655-usda.clar", - "key-token/key-usda-240655-wbtc.clar", - "yield-token/yield-usda-240655.clar", - "multisig/multisig-crp-usda-240655-wbtc.clar", - "multisig/multisig-ytp-yield-usda-240655-usda.clar", - "flash-loan-user-margin-wbtc-usda-240655.clar", + "yield-token/yield-wbtc-92160.clar", + "yield-token/yield-usda-92160.clar", + "key-token/key-usda-92160-wbtc.clar", + "key-token/key-wbtc-92160-usda.clar", + "pool-token/ytp-yield-wbtc-92160-wbtc.clar", + "pool-token/ytp-yield-usda-92160-usda.clar", + "multisig/multisig-crp-wbtc-92160-usda.clar", + "multisig/multisig-crp-usda-92160-wbtc.clar", + "multisig/multisig-ytp-yield-wbtc-92160-wbtc.clar", + "multisig/multisig-ytp-yield-usda-92160-usda.clar", + "flash-loan-user-margin-usda-wbtc-92160.clar", + "flash-loan-user-margin-wbtc-usda-92160.clar" ] async function get_version(){ diff --git a/init-js-tool/index.js b/init-js-tool/index.js index f86886a3..a5a391ed 100644 --- a/init-js-tool/index.js +++ b/init-js-tool/index.js @@ -62,175 +62,90 @@ const { const _deploy = { 0: {token: 'token-wbtc', collateral: 'token-usda', - yield_token: 'yield-wbtc-40555', - key_token: 'key-wbtc-40555-usda', - pool_token: 'ytp-yield-wbtc-40555-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-40555-wbtc', - multisig_crp: 'multisig-crp-wbtc-40555-usda', + yield_token: 'yield-wbtc-11520', + key_token: 'key-wbtc-11520-usda', + pool_token: 'ytp-yield-wbtc-11520-wbtc', + multisig_ytp: 'multisig-ytp-yield-wbtc-11520-wbtc', + multisig_crp: 'multisig-crp-wbtc-11520-usda', liquidity_ytp: 100e+8, collateral_crp: 1500000e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, - target_apy: 0.08354, - expiry: 40555e+8, + target_apy: 0.06354, + expiry: 11520e+8, }, 1: {token: 'token-usda', collateral: 'token-wbtc', - yield_token: 'yield-usda-40555', - key_token: 'key-usda-40555-wbtc', - pool_token: 'ytp-yield-usda-40555-usda', - multisig_ytp: 'multisig-ytp-yield-usda-40555-usda', - multisig_crp: 'multisig-crp-usda-40555-wbtc', + yield_token: 'yield-usda-11520', + key_token: 'key-usda-11520-wbtc', + pool_token: 'ytp-yield-usda-11520-usda', + multisig_ytp: 'multisig-ytp-yield-usda-11520-usda', + multisig_crp: 'multisig-crp-usda-11520-wbtc', liquidity_ytp: 6000000e+8, collateral_crp: 25e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, - target_apy: 0.136475, - expiry: 40555e+8, + target_apy: 0.086475, + expiry: 11520e+8, }, 2: { token: 'token-wbtc', collateral: 'token-usda', - yield_token: 'yield-wbtc-80875', - key_token: 'key-wbtc-80875-usda', - pool_token: 'ytp-yield-wbtc-80875-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-80875-wbtc', - multisig_crp: 'multisig-crp-wbtc-80875-usda', + yield_token: 'yield-wbtc-51840', + key_token: 'key-wbtc-51840-usda', + pool_token: 'ytp-yield-wbtc-51840-wbtc', + multisig_ytp: 'multisig-ytp-yield-wbtc-51840-wbtc', + multisig_crp: 'multisig-crp-wbtc-51840-usda', liquidity_ytp: 100e+8, collateral_crp: 1500000e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, - target_apy: 0.113486, - expiry: 80875e+8, + target_apy: 0.093486, + expiry: 51840e+8, }, 3: { token: 'token-usda', collateral: 'token-wbtc', - yield_token: 'yield-usda-80875', - key_token: 'key-usda-80875-wbtc', - pool_token: 'ytp-yield-usda-80875-usda', - multisig_ytp: 'multisig-ytp-yield-usda-80875-usda', - multisig_crp: 'multisig-crp-usda-80875-wbtc', + yield_token: 'yield-usda-51840', + key_token: 'key-usda-51840-wbtc', + pool_token: 'ytp-yield-usda-51840-usda', + multisig_ytp: 'multisig-ytp-yield-usda-51840-usda', + multisig_crp: 'multisig-crp-usda-51840-wbtc', liquidity_ytp: 6000000e+8, collateral_crp: 25e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, - target_apy: 0.135768, - expiry: 80875e+8, + target_apy: 0.10768, + expiry: 51840e+8, }, 4: {token: 'token-wbtc', collateral: 'token-usda', - yield_token: 'yield-wbtc-121195', - key_token: 'key-wbtc-121195-usda', - pool_token: 'ytp-yield-wbtc-121195-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-121195-wbtc', - multisig_crp: 'multisig-crp-wbtc-121195-usda', + yield_token: 'yield-wbtc-92160', + key_token: 'key-wbtc-92160-usda', + pool_token: 'ytp-yield-wbtc-92160-wbtc', + multisig_ytp: 'multisig-ytp-yield-wbtc-92160-wbtc', + multisig_crp: 'multisig-crp-wbtc-92160-usda', liquidity_ytp: 100e+8, collateral_crp: 1500000e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, target_apy: 0.18469, - expiry: 121195e+8, + expiry: 92160e+8, }, 5: {token: 'token-usda', collateral: 'token-wbtc', - yield_token: 'yield-usda-121195', - key_token: 'key-usda-121195-wbtc', - pool_token: 'ytp-yield-usda-121195-usda', - multisig_ytp: 'multisig-ytp-yield-usda-121195-usda', - multisig_crp: 'multisig-crp-usda-121195-wbtc', + yield_token: 'yield-usda-92160', + key_token: 'key-usda-92160-wbtc', + pool_token: 'ytp-yield-usda-92160-usda', + multisig_ytp: 'multisig-ytp-yield-usda-92160-usda', + multisig_crp: 'multisig-crp-usda-92160-wbtc', liquidity_ytp: 6000000e+8, collateral_crp: 25e+8, ltv_0: 0.7e+8, bs_vol: 0.8e+8, target_apy: 0.16950, - expiry: 121195e+8, - }, - 6: {token: 'token-wbtc', - collateral: 'token-usda', - yield_token: 'yield-wbtc-161515', - key_token: 'key-wbtc-161515-usda', - pool_token: 'ytp-yield-wbtc-161515-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-161515-wbtc', - multisig_crp: 'multisig-crp-wbtc-161515-usda', - liquidity_ytp: 100e+8, - collateral_crp: 1500000e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.24469, - expiry: 161515e+8, - }, - 7: {token: 'token-usda', - collateral: 'token-wbtc', - yield_token: 'yield-usda-161515', - key_token: 'key-usda-161515-wbtc', - pool_token: 'ytp-yield-usda-161515-usda', - multisig_ytp: 'multisig-ytp-yield-usda-161515-usda', - multisig_crp: 'multisig-crp-usda-161515-wbtc', - liquidity_ytp: 6000000e+8, - collateral_crp: 25e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.22950, - expiry: 161515e+8, - }, - 8: {token: 'token-wbtc', - collateral: 'token-usda', - yield_token: 'yield-wbtc-200335', - key_token: 'key-wbtc-200335-usda', - pool_token: 'ytp-yield-wbtc-200335-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-200335-wbtc', - multisig_crp: 'multisig-crp-wbtc-200335-usda', - liquidity_ytp: 100e+8, - collateral_crp: 1500000e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.08469, - expiry: 200335e+8, - }, - 9: {token: 'token-usda', - collateral: 'token-wbtc', - yield_token: 'yield-usda-200335', - key_token: 'key-usda-200335-wbtc', - pool_token: 'ytp-yield-usda-200335-usda', - multisig_ytp: 'multisig-ytp-yield-usda-200335-usda', - multisig_crp: 'multisig-crp-usda-200335-wbtc', - liquidity_ytp: 6000000e+8, - collateral_crp: 25e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.10950, - expiry: 200335e+8, - }, - 10: {token: 'token-wbtc', - collateral: 'token-usda', - yield_token: 'yield-wbtc-240655', - key_token: 'key-wbtc-240655-usda', - pool_token: 'ytp-yield-wbtc-240655-wbtc', - multisig_ytp: 'multisig-ytp-yield-wbtc-240655-wbtc', - multisig_crp: 'multisig-crp-wbtc-240655-usda', - liquidity_ytp: 100e+8, - collateral_crp: 1500000e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.08469, - expiry: 240655e+8, - }, - 11: {token: 'token-usda', - collateral: 'token-wbtc', - yield_token: 'yield-usda-240655', - key_token: 'key-usda-240655-wbtc', - pool_token: 'ytp-yield-usda-240655-usda', - multisig_ytp: 'multisig-ytp-yield-usda-240655-usda', - multisig_crp: 'multisig-crp-usda-240655-wbtc', - liquidity_ytp: 6000000e+8, - collateral_crp: 25e+8, - ltv_0: 0.7e+8, - bs_vol: 0.8e+8, - target_apy: 0.10950, - expiry: 240655e+8, - }, - + expiry: 92160e+8, + }, } const ONE_8 = 100000000 @@ -383,14 +298,14 @@ async function arbitrage_fwp(dry_run = true) { if (dx.type === 7 && dx.value.value > 0n) { let dy = await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx.value.value); if (dy.type == 7) { - await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx.value.value); + await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx.value.value, 0); } else { console.log('error: ', dy.value.value); let dx_i = Math.round(Number(dx.value.value) / 4); for (let i = 0; i < 4; i++) { let dy_i = await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx_i); if (dy_i.type == 7) { - await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx_i); + await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dx_i, 0); } } } @@ -403,14 +318,14 @@ async function arbitrage_fwp(dry_run = true) { if (dy.type === 7 && dy.value.value > 0n) { let dx = await fwpGetXgivenY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy.value.value); if (dx.type == 7) { - await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy.value.value); + await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy.value.value, 0); } else { console.log('error: ', dx.value.value); let dy_i = Math.round(Number(dy.value.value) / 4); for (let i = 0; i < 4; i++) { let dx_i = await fwpGetXgivenY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy_i); if (dx_i.type == 7) { - await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy_i); + await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, dy_i, 0); } } } @@ -465,14 +380,14 @@ async function arbitrage_crp(dry_run = true, _subset=_deploy) { if (dx.type === 7 && dx.value.value > 0n) { let dy = await crpGetYgivenX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx.value.value); if (dy.type == 7) { - await crpSwapXforY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx.value.value); + await crpSwapXforY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx.value.value, 0); } else { console.log('error: ', dy.value.value); let dx_i = Math.round(Number(dx.value.value) / 4); for (let i = 0; i < 4; i++) { let dy_i = await crpGetYgivenX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx_i); if (dy_i.type == 7) { - await crpSwapXforY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx_i); + await crpSwapXforY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dx_i, 0); } else { console.log('error: ', dy_i.value.value); break; @@ -488,14 +403,14 @@ async function arbitrage_crp(dry_run = true, _subset=_deploy) { if (dy.type === 7 && dy.value.value > 0n) { let dx = await crpGetXgivenY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy.value.value); if (dx.type == 7) { - await crpSwapYforX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy.value.value); + await crpSwapYforX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy.value.value, 0); } else { console.log('error: ', dx.value.value); let dy_i = Math.round(Number(dy.value.value) / 4); for (let i = 0; i < 4; i++) { let dx_i = await crpGetXgivenY(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy_i); if (dx_i.type == 7) { - await crpSwapYforX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy_i); + await crpSwapYforX(_subset[key]['token'], _subset[key]['collateral'], _subset[key]['expiry'], dy_i, 0); } else { console.log('error: ', dx_i.value.value); break; @@ -546,14 +461,14 @@ async function arbitrage_ytp(dry_run = true, _subset=_deploy) { if (dx.type === 7 && dx.value.value > 0n) { let dy = await ytpGetYgivenX(_subset[key]['yield_token'], dx.value.value); if (dy.type == 7) { - await ytpSwapXforY(_subset[key]['yield_token'], _subset[key]['token'], dx.value.value); + await ytpSwapXforY(_subset[key]['yield_token'], _subset[key]['token'], dx.value.value, 0); } else { console.log('error: ', dy.value.value); dx_i = Math.round(Number(dx.value.value) / 10); for (let i = 0; i < 10; i++) { let dy_i = await ytpGetYgivenX(_subset[key]['yield_token'], dx_i); if (dy_i.type == 7) { - await ytpSwapXforY(_subset[key]['yield_token'], _subset[key]['token'], dx_i); + await ytpSwapXforY(_subset[key]['yield_token'], _subset[key]['token'], dx_i, 0); } else { console.log('error: ', dy_i.value.value); break; @@ -625,13 +540,13 @@ async function test_spot_trading() { let from_amount = ONE_8; let to_amount = parseInt((await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount)).value.value); let exchange_rate = parseInt((await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, ONE_8))); - await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount); + await fwpSwapXforY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount, 0); from_amount = Number(wbtcPrice); to_amount = (await fwpGetXgivenY('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount)); exchange_rate = parseInt((await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, ONE_8))); if (to_amount.type === 7) { - await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount); + await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, from_amount, 0); } else { console.log('error: ', to_amount.value.value); } @@ -643,35 +558,35 @@ async function test_margin_trading() { let wbtcPrice = (await getOpenOracle('coingecko', 'WBTC')).value.value; let usdaPrice = (await getOpenOracle('coingecko', 'USDA')).value.value; - let expiry_0 = 40555e+8 + let expiry_0 = 11520e+8 let amount = 1 * ONE_8; //gross exposure of 1 BTC let trade_price = Number((await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, amount)).value.value); // in USD let trade_amount = amount; // in BTC let ltv = Number((await crpGetLtv('token-usda', 'token-wbtc', expiry_0)).value.value); - ltv /= Number((await ytpGetPrice("yield-usda-40555")).value.value); + ltv /= Number((await ytpGetPrice("yield-usda-11520")).value.value); let margin = Math.round(amount * (1 - ltv)); // in BTC let leverage = 1 / (1 - ltv); console.log("ltv: ", format_number(ltv, 2), "; amount (BTC): ", format_number(amount, 8), "; margin (BTC): ", format_number(margin, 8)); console.log("leverage: ", format_number(leverage, 2), "; trade_price (USD): ", format_number(trade_price, 2)); - await flashloan('flash-loan-user-margin-wbtc-usda-40555', 'token-wbtc', (amount - margin)); + await flashloan('flash-loan-user-margin-wbtc-usda-11520', 'token-wbtc', (amount - margin)); console.log("------ Testing Margin Trading (Short BTC vs USD) ------"); console.log(timestamp()); - expiry_0 = 40555e+8 + expiry_0 = 11520e+8 amount = 1 * ONE_8; //gross exposure of 1 BTC trade_price = Number((await fwpGetYgivenX('token-wbtc', 'token-usda', 0.5e+8, 0.5e+8, amount)).value.value); // in USD trade_amount = amount; // in BTC ltv = Number((await crpGetLtv('token-wbtc', 'token-usda', expiry_0)).value.value); - ltv /= Number((await ytpGetPrice("yield-wbtc-40555")).value.value); + ltv /= Number((await ytpGetPrice("yield-wbtc-11520")).value.value); margin = Math.round(amount * (1 - ltv) * Number(wbtcPrice) / ONE_8); // in USD leverage = 1 / (1 - ltv); console.log("ltv: ", format_number(ltv, 2), "; amount (BTC): ", format_number(amount, 8), "; margin (USD): ", format_number(margin, 2)); console.log("leverage: ", format_number(leverage, 2), "; trade_price (USD): ", format_number(trade_price, 2)) - await flashloan('flash-loan-user-margin-usda-wbtc-40555', 'token-usda', (trade_price - margin)); + await flashloan('flash-loan-user-margin-usda-wbtc-11520', 'token-usda', (trade_price - margin)); } function format_number(number, fixed = 2) { @@ -809,19 +724,19 @@ async function run() { // await mint_some_tokens(process.env.USER_ACCOUNT_ADDRESS); // await get_some_token(process.env.USER_ACCOUNT_ADDRESS); - const _pools = { 0:_deploy[2], - 1:_deploy[3], - 2:_deploy[4], - 3:_deploy[5], - 4:_deploy[6], - 5:_deploy[7], - 6:_deploy[8], - 7:_deploy[9], - 8:_deploy[10], - 9:_deploy[11] - }; - // const _pools = { 0:_deploy[10], 1:_deploy[11] }; - // const _pools = _deploy; + // const _pools = { 0:_deploy[2], + // 1:_deploy[3], + // 2:_deploy[4], + // 3:_deploy[5], + // 4:_deploy[6], + // 5:_deploy[7], + // 6:_deploy[8], + // 7:_deploy[9], + // 8:_deploy[10], + // 9:_deploy[11] + // }; + // const _pools = { 0:_deploy[4], 1:_deploy[5] }; + const _pools = _deploy; // await create_fwp(add_only=false); // await create_ytp(add_only=false, _pools); @@ -829,8 +744,8 @@ async function run() { await arbitrage_fwp(dry_run = false); await arbitrage_crp(dry_run = false, _pools); - // await arbitrage_ytp(dry_run = false, _pools); - // await arbitrage_fwp(dry_run = false); + await arbitrage_ytp(dry_run = false, _pools); + await arbitrage_fwp(dry_run = false); // await test_spot_trading(); // await test_margin_trading(); @@ -865,12 +780,12 @@ async function run() { // await burn('token-wbtc', 'STZP1114C4EA044RE54M6G5ZC2NYK9SAHB5QVE1', 9995719169074); // await burn('token-usda', 'STZP1114C4EA044RE54M6G5ZC2NYK9SAHB5QVE1', 399709145833000000); - // result = await ytpGetYgivenX('yield-wbtc-80875', 1e8); + // result = await ytpGetYgivenX('yield-wbtc-51840', 1e8); // console.log(result); // result = await fwpGetXgivenY('token-wbtc', 'token-usda', 0.5e8, 0.5e8, 500000000e8); // console.log(result); - // await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e8, 0.5e8, 500000000e8); + // await fwpSwapYforX('token-wbtc', 'token-usda', 0.5e8, 0.5e8, 500000000e8, 0); // await arbitrage_fwp(dry_run = false); // await mint_some_wbtc(process.env.USER_ACCOUNT_ADDRESS); // await see_balance(process.env.USER_ACCOUNT_ADDRESS); diff --git a/init-js-tool/pools-crp.js b/init-js-tool/pools-crp.js index 614f6677..525392e3 100644 --- a/init-js-tool/pools-crp.js +++ b/init-js-tool/pools-crp.js @@ -7,6 +7,7 @@ const { AnchorMode, PostConditionMode, uintCV, + someCV, contractPrincipalCV, broadcastTransaction, ClarityType @@ -173,7 +174,7 @@ const {wait_until_confirmation } = require('./utils'); } } - const crpSwapXforY = async (token, collateral, expiry, dx) => { + const crpSwapXforY = async (token, collateral, expiry, dx, min_dy) => { console.log('--------------------------------------------------------------------------'); console.log('[CRP] swap-x-for-y...', token, collateral, expiry, dx); const privateKey = await getUserPK(); @@ -186,6 +187,7 @@ const {wait_until_confirmation } = require('./utils'); contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, collateral), uintCV(expiry), uintCV(dx), + someCV(uintCV(min_dy)) ], senderKey: privateKey, validateWithAbi: true, @@ -203,7 +205,7 @@ const {wait_until_confirmation } = require('./utils'); } } - const crpSwapYforX = async (token, collateral, expiry, dy) => { + const crpSwapYforX = async (token, collateral, expiry, dy, min_dx) => { console.log('--------------------------------------------------------------------------'); console.log('[CRP] swap-y-for-x...', token, collateral, expiry, dy); const privateKey = await getUserPK(); @@ -216,6 +218,7 @@ const {wait_until_confirmation } = require('./utils'); contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, collateral), uintCV(expiry), uintCV(dy), + someCV(uintCV(min_dx)) ], senderKey: privateKey, validateWithAbi: true, diff --git a/init-js-tool/pools-fwp.js b/init-js-tool/pools-fwp.js index e38ce96b..6d9bc9f5 100644 --- a/init-js-tool/pools-fwp.js +++ b/init-js-tool/pools-fwp.js @@ -7,6 +7,7 @@ const { AnchorMode, PostConditionMode, uintCV, + someCV, contractPrincipalCV, broadcastTransaction, ClarityType @@ -178,7 +179,7 @@ const fwpGetYgivenX = async (tokenX, tokenY, weightX, weightY, dx) => { } }; -const fwpSwapXforY = async (tokenX, tokenY, weightX, weightY, dx) => { +const fwpSwapXforY = async (tokenX, tokenY, weightX, weightY, dx, min_dy) => { console.log('--------------------------------------------------------------------------'); console.log('[FWP] swap-x-for-y...', tokenX, tokenY, weightX, weightY, dx); const privateKey = await getUserPK(); @@ -191,7 +192,8 @@ const fwpSwapXforY = async (tokenX, tokenY, weightX, weightY, dx) => { contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, tokenY), uintCV(weightX), uintCV(weightY), - uintCV(dx) + uintCV(dx), + someCV(uintCV(min_dy)) ], senderKey: privateKey, validateWithAbi: true, @@ -210,7 +212,7 @@ const fwpSwapXforY = async (tokenX, tokenY, weightX, weightY, dx) => { } } -const fwpSwapYforX = async (tokenX, tokenY, weightX, weightY, dy) => { +const fwpSwapYforX = async (tokenX, tokenY, weightX, weightY, dy, min_dx) => { console.log('--------------------------------------------------------------------------'); console.log('[FWP] swap-y-for-x...', tokenX, tokenY, weightX, weightY, dy); const privateKey = await getUserPK(); @@ -223,7 +225,8 @@ const fwpSwapYforX = async (tokenX, tokenY, weightX, weightY, dy) => { contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, tokenY), uintCV(weightX), uintCV(weightY), - uintCV(dy) + uintCV(dy), + someCV(uintCV(min_dx)) ], senderKey: privateKey, validateWithAbi: true, diff --git a/init-js-tool/pools-ytp.js b/init-js-tool/pools-ytp.js index 0738143b..1f085ef6 100644 --- a/init-js-tool/pools-ytp.js +++ b/init-js-tool/pools-ytp.js @@ -7,6 +7,7 @@ const { AnchorMode, PostConditionMode, uintCV, + someCV, contractPrincipalCV, broadcastTransaction, ClarityType @@ -150,7 +151,7 @@ const { } } - const ytpSwapXforY = async (yiedToken, token, dx) => { + const ytpSwapXforY = async (yiedToken, token, dx, min_dy) => { console.log('--------------------------------------------------------------------------'); console.log('[YTP] swap-x-for-y...', yiedToken, token, dx); const privateKey = await getUserPK(); @@ -161,7 +162,8 @@ const { functionArgs: [ contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, yiedToken), contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, token), - uintCV(dx) + uintCV(dx), + someCV(uintCV(min_dy)) ], senderKey: privateKey, validateWithAbi: true, @@ -179,7 +181,7 @@ const { } } - const ytpSwapYforX = async (yiedToken, token, dy) => { + const ytpSwapYforX = async (yiedToken, token, dy, min_dx) => { console.log('--------------------------------------------------------------------------'); console.log('[YTP] swap-y-for-x...', yiedToken, token, dy); const privateKey = await getUserPK(); @@ -190,7 +192,8 @@ const { functionArgs: [ contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, yiedToken), contractPrincipalCV(process.env.DEPLOYER_ACCOUNT_ADDRESS, token), - uintCV(dy) + uintCV(dy), + someCV(uintCV(min_dx)) ], senderKey: privateKey, validateWithAbi: true,