Skip to content

Commit

Permalink
conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
noumanahmads committed Nov 1, 2021
2 parents fba974a + 42ced44 commit 40d479a
Show file tree
Hide file tree
Showing 77 changed files with 1,552 additions and 1,428 deletions.
8 changes: 8 additions & 0 deletions clarity/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
1 change: 0 additions & 1 deletion clarity/contracts/alex-vault.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions clarity/contracts/equations/weighted-equation.clar
Original file line number Diff line number Diff line change
@@ -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
;;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clarity/contracts/equations/yield-token-equation.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions clarity/contracts/flash-loan-user-margin-usda-wbtc-23040.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions clarity/contracts/flash-loan-user-margin-usda-wbtc-23670.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
4 changes: 2 additions & 2 deletions clarity/contracts/flash-loan-user-margin-usda-wbtc-59760.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions clarity/contracts/flash-loan-user-margin-usda-wbtc-80875.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Loading

0 comments on commit 40d479a

Please sign in to comment.