@clober/v2-sdk 0.0.9 → 0.0.10-9.dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/cjs/abis/core/book-manager-abi.js +112 -0
- package/dist/cjs/abis/core/book-manager-abi.js.map +1 -0
- package/dist/cjs/abis/core/book-viewer-abi.js +137 -5
- package/dist/cjs/abis/core/book-viewer-abi.js.map +1 -1
- package/dist/cjs/abis/core/controller-abi.js +29 -24
- package/dist/cjs/abis/core/controller-abi.js.map +1 -1
- package/dist/cjs/abis/governance/election-governor-abi.js +838 -0
- package/dist/cjs/abis/governance/election-governor-abi.js.map +1 -0
- package/dist/cjs/abis/governance/keepers-registry-abi.js +546 -0
- package/dist/cjs/abis/governance/keepers-registry-abi.js.map +1 -0
- package/dist/cjs/abis/governance/vclob-abi.js +743 -0
- package/dist/cjs/abis/governance/vclob-abi.js.map +1 -0
- package/dist/cjs/abis/rebalancer/minter-abi.js +262 -0
- package/dist/cjs/abis/rebalancer/minter-abi.js.map +1 -0
- package/dist/cjs/abis/rebalancer/mock-swap-abi.js +95 -0
- package/dist/cjs/abis/rebalancer/mock-swap-abi.js.map +1 -0
- package/dist/cjs/abis/rebalancer/operator-abi.js +401 -0
- package/dist/cjs/abis/rebalancer/operator-abi.js.map +1 -0
- package/dist/cjs/abis/rebalancer/rebalancer-abi.js +1326 -0
- package/dist/cjs/abis/rebalancer/rebalancer-abi.js.map +1 -0
- package/dist/cjs/abis/rebalancer/strategy-abi.js +895 -0
- package/dist/cjs/abis/rebalancer/strategy-abi.js.map +1 -0
- package/dist/cjs/apis/chart-logs.js +30 -13
- package/dist/cjs/apis/chart-logs.js.map +1 -1
- package/dist/cjs/apis/market.js +45 -22
- package/dist/cjs/apis/market.js.map +1 -1
- package/dist/cjs/apis/odos.js +100 -0
- package/dist/cjs/apis/odos.js.map +1 -0
- package/dist/cjs/apis/open-order.js +61 -36
- package/dist/cjs/apis/open-order.js.map +1 -1
- package/dist/cjs/apis/pool.js +96 -0
- package/dist/cjs/apis/pool.js.map +1 -0
- package/dist/cjs/apis/strategy.js +53 -0
- package/dist/cjs/apis/strategy.js.map +1 -0
- package/dist/cjs/apis/vclob.js +47 -0
- package/dist/cjs/apis/vclob.js.map +1 -0
- package/dist/cjs/approval.js +83 -26
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/call.js +908 -156
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/addresses.js +104 -1
- package/dist/cjs/constants/addresses.js.map +1 -1
- package/dist/cjs/constants/bera-bartio-chain.js +30 -0
- package/dist/cjs/constants/bera-bartio-chain.js.map +1 -0
- package/dist/cjs/constants/chain.js +29 -2
- package/dist/cjs/constants/chain.js.map +1 -1
- package/dist/cjs/constants/currency.js +99 -3
- package/dist/cjs/constants/currency.js.map +1 -1
- package/dist/cjs/constants/fee.js +23 -2
- package/dist/cjs/constants/fee.js.map +1 -1
- package/dist/cjs/constants/mitosis-testnet-chain.js +30 -0
- package/dist/cjs/constants/mitosis-testnet-chain.js.map +1 -0
- package/dist/cjs/constants/monad-testnet-chain.js +40 -0
- package/dist/cjs/constants/monad-testnet-chain.js.map +1 -0
- package/dist/cjs/constants/permit.js +14 -0
- package/dist/cjs/constants/permit.js.map +1 -0
- package/dist/cjs/constants/price.js +2 -1
- package/dist/cjs/constants/price.js.map +1 -1
- package/dist/cjs/constants/sonic-mainnet-chain.js +30 -0
- package/dist/cjs/constants/sonic-mainnet-chain.js.map +1 -0
- package/dist/cjs/constants/subgraph.js +38 -0
- package/dist/cjs/constants/subgraph.js.map +1 -0
- package/dist/cjs/constants/test-chain.js +50 -0
- package/dist/cjs/constants/test-chain.js.map +1 -0
- package/dist/cjs/constants/tick.js +6 -0
- package/dist/cjs/constants/tick.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/book.js +62 -35
- package/dist/cjs/model/book.js.map +1 -1
- package/dist/cjs/model/market.js +61 -26
- package/dist/cjs/model/market.js.map +1 -1
- package/dist/cjs/model/pool.js +240 -0
- package/dist/cjs/model/pool.js.map +1 -0
- package/dist/cjs/model/vclob.js +3 -0
- package/dist/cjs/model/vclob.js.map +1 -0
- package/dist/cjs/type.js +8 -1
- package/dist/cjs/type.js.map +1 -1
- package/dist/cjs/utils/allowance.js +39 -0
- package/dist/cjs/utils/allowance.js.map +1 -0
- package/dist/cjs/utils/approval.js +2 -3
- package/dist/cjs/utils/approval.js.map +1 -1
- package/dist/cjs/utils/bigint.js +5 -1
- package/dist/cjs/utils/bigint.js.map +1 -1
- package/dist/cjs/utils/book-id.js +7 -7
- package/dist/cjs/utils/book-id.js.map +1 -1
- package/dist/cjs/utils/build-transaction.js +9 -9
- package/dist/cjs/utils/build-transaction.js.map +1 -1
- package/dist/cjs/utils/currency.js +61 -27
- package/dist/cjs/utils/currency.js.map +1 -1
- package/dist/cjs/utils/market.js +1 -1
- package/dist/cjs/utils/market.js.map +1 -1
- package/dist/cjs/utils/math.js +3 -1
- package/dist/cjs/utils/math.js.map +1 -1
- package/dist/cjs/utils/open.js +35 -25
- package/dist/cjs/utils/open.js.map +1 -1
- package/dist/cjs/utils/order.js +68 -126
- package/dist/cjs/utils/order.js.map +1 -1
- package/dist/cjs/utils/pool-key.js +17 -0
- package/dist/cjs/utils/pool-key.js.map +1 -0
- package/dist/cjs/utils/pool.js +88 -0
- package/dist/cjs/utils/pool.js.map +1 -0
- package/dist/cjs/utils/prices.js +40 -5
- package/dist/cjs/utils/prices.js.map +1 -1
- package/dist/cjs/utils/tick.js +12 -1
- package/dist/cjs/utils/tick.js.map +1 -1
- package/dist/cjs/utils/time-series.js +31 -0
- package/dist/cjs/utils/time-series.js.map +1 -0
- package/dist/cjs/utils/unit-size.js +48 -0
- package/dist/cjs/utils/unit-size.js.map +1 -0
- package/dist/cjs/utils.js +18 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/view.js +463 -44
- package/dist/cjs/view.js.map +1 -1
- package/dist/esm/abis/core/book-manager-abi.js +109 -0
- package/dist/esm/abis/core/book-manager-abi.js.map +1 -0
- package/dist/esm/abis/core/book-viewer-abi.js +137 -5
- package/dist/esm/abis/core/book-viewer-abi.js.map +1 -1
- package/dist/esm/abis/core/controller-abi.js +29 -24
- package/dist/esm/abis/core/controller-abi.js.map +1 -1
- package/dist/esm/abis/governance/election-governor-abi.js +835 -0
- package/dist/esm/abis/governance/election-governor-abi.js.map +1 -0
- package/dist/esm/abis/governance/keepers-registry-abi.js +543 -0
- package/dist/esm/abis/governance/keepers-registry-abi.js.map +1 -0
- package/dist/esm/abis/governance/vclob-abi.js +740 -0
- package/dist/esm/abis/governance/vclob-abi.js.map +1 -0
- package/dist/esm/abis/rebalancer/minter-abi.js +259 -0
- package/dist/esm/abis/rebalancer/minter-abi.js.map +1 -0
- package/dist/esm/abis/rebalancer/mock-swap-abi.js +92 -0
- package/dist/esm/abis/rebalancer/mock-swap-abi.js.map +1 -0
- package/dist/esm/abis/rebalancer/operator-abi.js +398 -0
- package/dist/esm/abis/rebalancer/operator-abi.js.map +1 -0
- package/dist/esm/abis/rebalancer/rebalancer-abi.js +1323 -0
- package/dist/esm/abis/rebalancer/rebalancer-abi.js.map +1 -0
- package/dist/esm/abis/rebalancer/strategy-abi.js +892 -0
- package/dist/esm/abis/rebalancer/strategy-abi.js.map +1 -0
- package/dist/esm/apis/chart-logs.js +29 -12
- package/dist/esm/apis/chart-logs.js.map +1 -1
- package/dist/esm/apis/market.js +47 -24
- package/dist/esm/apis/market.js.map +1 -1
- package/dist/esm/apis/odos.js +94 -0
- package/dist/esm/apis/odos.js.map +1 -0
- package/dist/esm/apis/open-order.js +63 -37
- package/dist/esm/apis/open-order.js.map +1 -1
- package/dist/esm/apis/pool.js +91 -0
- package/dist/esm/apis/pool.js.map +1 -0
- package/dist/esm/apis/strategy.js +48 -0
- package/dist/esm/apis/strategy.js.map +1 -0
- package/dist/esm/apis/vclob.js +43 -0
- package/dist/esm/apis/vclob.js.map +1 -0
- package/dist/esm/approval.js +109 -36
- package/dist/esm/approval.js.map +1 -1
- package/dist/esm/call.js +947 -210
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/constants/addresses.js +105 -2
- package/dist/esm/constants/addresses.js.map +1 -1
- package/dist/esm/constants/bera-bartio-chain.js +27 -0
- package/dist/esm/constants/bera-bartio-chain.js.map +1 -0
- package/dist/esm/constants/chain.js +28 -2
- package/dist/esm/constants/chain.js.map +1 -1
- package/dist/esm/constants/currency.js +100 -2
- package/dist/esm/constants/currency.js.map +1 -1
- package/dist/esm/constants/fee.js +23 -2
- package/dist/esm/constants/fee.js.map +1 -1
- package/dist/esm/constants/mitosis-testnet-chain.js +27 -0
- package/dist/esm/constants/mitosis-testnet-chain.js.map +1 -0
- package/dist/esm/constants/monad-testnet-chain.js +37 -0
- package/dist/esm/constants/monad-testnet-chain.js.map +1 -0
- package/dist/esm/constants/permit.js +11 -0
- package/dist/esm/constants/permit.js.map +1 -0
- package/dist/esm/constants/price.js +1 -0
- package/dist/esm/constants/price.js.map +1 -1
- package/dist/esm/constants/sonic-mainnet-chain.js +27 -0
- package/dist/esm/constants/sonic-mainnet-chain.js.map +1 -0
- package/dist/esm/constants/subgraph.js +34 -0
- package/dist/esm/constants/subgraph.js.map +1 -0
- package/dist/esm/constants/test-chain.js +47 -0
- package/dist/esm/constants/test-chain.js.map +1 -0
- package/dist/esm/constants/tick.js +3 -0
- package/dist/esm/constants/tick.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/book.js +62 -35
- package/dist/esm/model/book.js.map +1 -1
- package/dist/esm/model/market.js +63 -28
- package/dist/esm/model/market.js.map +1 -1
- package/dist/esm/model/pool.js +237 -0
- package/dist/esm/model/pool.js.map +1 -0
- package/dist/esm/model/vclob.js +2 -0
- package/dist/esm/model/vclob.js.map +1 -0
- package/dist/esm/type.js +7 -0
- package/dist/esm/type.js.map +1 -1
- package/dist/esm/utils/allowance.js +35 -0
- package/dist/esm/utils/allowance.js.map +1 -0
- package/dist/esm/utils/approval.js +2 -3
- package/dist/esm/utils/approval.js.map +1 -1
- package/dist/esm/utils/bigint.js +2 -0
- package/dist/esm/utils/bigint.js.map +1 -1
- package/dist/esm/utils/book-id.js +7 -7
- package/dist/esm/utils/book-id.js.map +1 -1
- package/dist/esm/utils/build-transaction.js +9 -9
- package/dist/esm/utils/build-transaction.js.map +1 -1
- package/dist/esm/utils/currency.js +59 -25
- package/dist/esm/utils/currency.js.map +1 -1
- package/dist/esm/utils/market.js +1 -1
- package/dist/esm/utils/market.js.map +1 -1
- package/dist/esm/utils/math.js +1 -0
- package/dist/esm/utils/math.js.map +1 -1
- package/dist/esm/utils/open.js +33 -23
- package/dist/esm/utils/open.js.map +1 -1
- package/dist/esm/utils/order.js +67 -125
- package/dist/esm/utils/order.js.map +1 -1
- package/dist/esm/utils/pool-key.js +12 -0
- package/dist/esm/utils/pool-key.js.map +1 -0
- package/dist/esm/utils/pool.js +84 -0
- package/dist/esm/utils/pool.js.map +1 -0
- package/dist/esm/utils/prices.js +39 -5
- package/dist/esm/utils/prices.js.map +1 -1
- package/dist/esm/utils/tick.js +11 -1
- package/dist/esm/utils/tick.js.map +1 -1
- package/dist/esm/utils/time-series.js +27 -0
- package/dist/esm/utils/time-series.js.map +1 -0
- package/dist/esm/utils/unit-size.js +44 -0
- package/dist/esm/utils/unit-size.js.map +1 -0
- package/dist/esm/utils.js +5 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/view.js +520 -61
- package/dist/esm/view.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/abis/core/book-manager-abi.d.ts +82 -0
- package/dist/types/abis/core/book-manager-abi.d.ts.map +1 -0
- package/dist/types/abis/core/book-viewer-abi.d.ts +107 -5
- package/dist/types/abis/core/book-viewer-abi.d.ts.map +1 -1
- package/dist/types/abis/core/controller-abi.d.ts +23 -19
- package/dist/types/abis/core/controller-abi.d.ts.map +1 -1
- package/dist/types/abis/governance/election-governor-abi.d.ts +648 -0
- package/dist/types/abis/governance/election-governor-abi.d.ts.map +1 -0
- package/dist/types/abis/governance/keepers-registry-abi.d.ts +417 -0
- package/dist/types/abis/governance/keepers-registry-abi.d.ts.map +1 -0
- package/dist/types/abis/governance/vclob-abi.d.ts +568 -0
- package/dist/types/abis/governance/vclob-abi.d.ts.map +1 -0
- package/dist/types/abis/rebalancer/minter-abi.d.ts +198 -0
- package/dist/types/abis/rebalancer/minter-abi.d.ts.map +1 -0
- package/dist/types/abis/rebalancer/mock-swap-abi.d.ts +70 -0
- package/dist/types/abis/rebalancer/mock-swap-abi.d.ts.map +1 -0
- package/dist/types/abis/rebalancer/operator-abi.d.ts +308 -0
- package/dist/types/abis/rebalancer/operator-abi.d.ts.map +1 -0
- package/dist/types/abis/rebalancer/rebalancer-abi.d.ts +1023 -0
- package/dist/types/abis/rebalancer/rebalancer-abi.d.ts.map +1 -0
- package/dist/types/abis/rebalancer/strategy-abi.d.ts +690 -0
- package/dist/types/abis/rebalancer/strategy-abi.d.ts.map +1 -0
- package/dist/types/apis/chart-logs.d.ts +3 -0
- package/dist/types/apis/chart-logs.d.ts.map +1 -1
- package/dist/types/apis/market.d.ts +2 -1
- package/dist/types/apis/market.d.ts.map +1 -1
- package/dist/types/apis/odos.d.ts +28 -0
- package/dist/types/apis/odos.d.ts.map +1 -0
- package/dist/types/apis/open-order.d.ts +4 -2
- package/dist/types/apis/open-order.d.ts.map +1 -1
- package/dist/types/apis/pool.d.ts +11 -0
- package/dist/types/apis/pool.d.ts.map +1 -0
- package/dist/types/apis/strategy.d.ts +6 -0
- package/dist/types/apis/strategy.d.ts.map +1 -0
- package/dist/types/apis/vclob.d.ts +5 -0
- package/dist/types/apis/vclob.d.ts.map +1 -0
- package/dist/types/approval.d.ts +35 -10
- package/dist/types/approval.d.ts.map +1 -1
- package/dist/types/call.d.ts +288 -71
- package/dist/types/call.d.ts.map +1 -1
- package/dist/types/constants/addresses.d.ts +7 -0
- package/dist/types/constants/addresses.d.ts.map +1 -1
- package/dist/types/constants/bera-bartio-chain.d.ts +33 -0
- package/dist/types/constants/bera-bartio-chain.d.ts.map +1 -0
- package/dist/types/constants/chain.d.ts +10 -2
- package/dist/types/constants/chain.d.ts.map +1 -1
- package/dist/types/constants/currency.d.ts +9 -0
- package/dist/types/constants/currency.d.ts.map +1 -1
- package/dist/types/constants/fee.d.ts +7 -2
- package/dist/types/constants/fee.d.ts.map +1 -1
- package/dist/types/constants/mitosis-testnet-chain.d.ts +33 -0
- package/dist/types/constants/mitosis-testnet-chain.d.ts.map +1 -0
- package/dist/types/constants/monad-testnet-chain.d.ts +37 -0
- package/dist/types/constants/monad-testnet-chain.d.ts.map +1 -0
- package/dist/types/constants/permit.d.ts +10 -0
- package/dist/types/constants/permit.d.ts.map +1 -0
- package/dist/types/constants/price.d.ts +1 -0
- package/dist/types/constants/price.d.ts.map +1 -1
- package/dist/types/constants/sonic-mainnet-chain.d.ts +33 -0
- package/dist/types/constants/sonic-mainnet-chain.d.ts.map +1 -0
- package/dist/types/constants/subgraph.d.ts +5 -0
- package/dist/types/constants/subgraph.d.ts.map +1 -0
- package/dist/types/constants/test-chain.d.ts +4 -0
- package/dist/types/constants/test-chain.d.ts.map +1 -0
- package/dist/types/constants/tick.d.ts +3 -0
- package/dist/types/constants/tick.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/model/book.d.ts +25 -33
- package/dist/types/model/book.d.ts.map +1 -1
- package/dist/types/model/currency.d.ts +7 -0
- package/dist/types/model/currency.d.ts.map +1 -1
- package/dist/types/model/depth.d.ts +4 -3
- package/dist/types/model/depth.d.ts.map +1 -1
- package/dist/types/model/market.d.ts +24 -13
- package/dist/types/model/market.d.ts.map +1 -1
- package/dist/types/model/open-order.d.ts +20 -27
- package/dist/types/model/open-order.d.ts.map +1 -1
- package/dist/types/model/pool.d.ts +77 -0
- package/dist/types/model/pool.d.ts.map +1 -0
- package/dist/types/model/vclob.d.ts +7 -0
- package/dist/types/model/vclob.d.ts.map +1 -0
- package/dist/types/type.d.ts +142 -6
- package/dist/types/type.d.ts.map +1 -1
- package/dist/types/utils/allowance.d.ts +3 -0
- package/dist/types/utils/allowance.d.ts.map +1 -0
- package/dist/types/utils/approval.d.ts +2 -1
- package/dist/types/utils/approval.d.ts.map +1 -1
- package/dist/types/utils/bigint.d.ts +2 -0
- package/dist/types/utils/bigint.d.ts.map +1 -1
- package/dist/types/utils/book-id.d.ts +2 -1
- package/dist/types/utils/book-id.d.ts.map +1 -1
- package/dist/types/utils/build-transaction.d.ts +3 -3
- package/dist/types/utils/build-transaction.d.ts.map +1 -1
- package/dist/types/utils/currency.d.ts +3 -2
- package/dist/types/utils/currency.d.ts.map +1 -1
- package/dist/types/utils/math.d.ts +1 -0
- package/dist/types/utils/math.d.ts.map +1 -1
- package/dist/types/utils/open.d.ts +2 -1
- package/dist/types/utils/open.d.ts.map +1 -1
- package/dist/types/utils/order.d.ts +4 -11
- package/dist/types/utils/order.d.ts.map +1 -1
- package/dist/types/utils/pool-key.d.ts +3 -0
- package/dist/types/utils/pool-key.d.ts.map +1 -0
- package/dist/types/utils/pool.d.ts +11 -0
- package/dist/types/utils/pool.d.ts.map +1 -0
- package/dist/types/utils/prices.d.ts +13 -2
- package/dist/types/utils/prices.d.ts.map +1 -1
- package/dist/types/utils/tick.d.ts +1 -0
- package/dist/types/utils/tick.d.ts.map +1 -1
- package/dist/types/utils/time-series.d.ts +4 -0
- package/dist/types/utils/time-series.d.ts.map +1 -0
- package/dist/types/utils/unit-size.d.ts +5 -0
- package/dist/types/utils/unit-size.d.ts.map +1 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/view.d.ts +248 -30
- package/dist/types/view.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/cjs/abis/core/params-abi.js +0 -62
- package/dist/cjs/abis/core/params-abi.js.map +0 -1
- package/dist/cjs/apis/subgraph.js +0 -26
- package/dist/cjs/apis/subgraph.js.map +0 -1
- package/dist/cjs/constants/client.js +0 -14
- package/dist/cjs/constants/client.js.map +0 -1
- package/dist/cjs/constants/subgraph-url.js +0 -8
- package/dist/cjs/constants/subgraph-url.js.map +0 -1
- package/dist/cjs/signature.js +0 -146
- package/dist/cjs/signature.js.map +0 -1
- package/dist/cjs/utils/decorator.js +0 -13
- package/dist/cjs/utils/decorator.js.map +0 -1
- package/dist/cjs/utils/unit.js +0 -34
- package/dist/cjs/utils/unit.js.map +0 -1
- package/dist/esm/abis/core/params-abi.js +0 -59
- package/dist/esm/abis/core/params-abi.js.map +0 -1
- package/dist/esm/apis/subgraph.js +0 -22
- package/dist/esm/apis/subgraph.js.map +0 -1
- package/dist/esm/constants/client.js +0 -10
- package/dist/esm/constants/client.js.map +0 -1
- package/dist/esm/constants/subgraph-url.js +0 -5
- package/dist/esm/constants/subgraph-url.js.map +0 -1
- package/dist/esm/signature.js +0 -182
- package/dist/esm/signature.js.map +0 -1
- package/dist/esm/utils/decorator.js +0 -9
- package/dist/esm/utils/decorator.js.map +0 -1
- package/dist/esm/utils/unit.js +0 -30
- package/dist/esm/utils/unit.js.map +0 -1
- package/dist/types/abis/core/params-abi.d.ts +0 -21
- package/dist/types/abis/core/params-abi.d.ts.map +0 -1
- package/dist/types/apis/subgraph.d.ts +0 -3
- package/dist/types/apis/subgraph.d.ts.map +0 -1
- package/dist/types/constants/client.d.ts +0 -5
- package/dist/types/constants/client.d.ts.map +0 -1
- package/dist/types/constants/subgraph-url.d.ts +0 -5
- package/dist/types/constants/subgraph-url.d.ts.map +0 -1
- package/dist/types/signature.d.ts +0 -50
- package/dist/types/signature.d.ts.map +0 -1
- package/dist/types/utils/decorator.d.ts +0 -6
- package/dist/types/utils/decorator.d.ts.map +0 -1
- package/dist/types/utils/unit.d.ts +0 -4
- package/dist/types/utils/unit.d.ts.map +0 -1
package/dist/cjs/call.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cancelOrders = exports.cancelOrder = exports.claimOrders = exports.claimOrder = exports.marketOrder = exports.limitOrder = exports.openMarket = void 0;
|
|
3
|
+
exports.burnVCLOB = exports.mintVCLOB = exports.end = exports.register = exports.vote = exports.resumePool = exports.pausePool = exports.setStrategyConfig = exports.adjustOrderPrice = exports.refillOrder = exports.removeLiquidity = exports.addLiquidity = exports.openPool = exports.cancelOrders = exports.cancelOrder = exports.claimOrders = exports.claimOrder = exports.marketOrder = exports.limitOrder = exports.openMarket = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const chain_1 = require("./constants/chain");
|
|
6
|
-
const
|
|
6
|
+
const unit_size_1 = require("./utils/unit-size");
|
|
7
7
|
const controller_abi_1 = require("./abis/core/controller-abi");
|
|
8
8
|
const time_1 = require("./utils/time");
|
|
9
9
|
const build_transaction_1 = require("./utils/build-transaction");
|
|
@@ -15,60 +15,91 @@ const tick_1 = require("./utils/tick");
|
|
|
15
15
|
const view_1 = require("./view");
|
|
16
16
|
const book_id_1 = require("./utils/book-id");
|
|
17
17
|
const approval_1 = require("./utils/approval");
|
|
18
|
-
const decorator_1 = require("./utils/decorator");
|
|
19
18
|
const order_1 = require("./utils/order");
|
|
20
|
-
const decimals_1 = require("./utils/decimals");
|
|
21
19
|
const bigint_1 = require("./utils/bigint");
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const pool_1 = require("./apis/pool");
|
|
21
|
+
const rebalancer_abi_1 = require("./abis/rebalancer/rebalancer-abi");
|
|
22
|
+
const pool_2 = require("./utils/pool");
|
|
23
|
+
const odos_1 = require("./apis/odos");
|
|
24
|
+
const minter_abi_1 = require("./abis/rebalancer/minter-abi");
|
|
25
|
+
const permit_1 = require("./constants/permit");
|
|
26
|
+
const math_1 = require("./utils/math");
|
|
27
|
+
const pool_key_1 = require("./utils/pool-key");
|
|
28
|
+
const operator_abi_1 = require("./abis/rebalancer/operator-abi");
|
|
29
|
+
const strategy_abi_1 = require("./abis/rebalancer/strategy-abi");
|
|
30
|
+
const election_governor_abi_1 = require("./abis/governance/election-governor-abi");
|
|
31
|
+
const vclob_abi_1 = require("./abis/governance/vclob-abi");
|
|
32
|
+
const openMarket = async ({ chainId, userAddress, inputToken, outputToken, options, }) => {
|
|
33
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
34
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
35
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
36
|
+
});
|
|
37
|
+
const market = await (0, market_1.fetchMarket)(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
24
38
|
const isBid = (0, viem_1.isAddressEqual)(market.quote.address, inputToken);
|
|
25
|
-
if ((isBid && !market.
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
if ((isBid && !market.bidBook.isOpened) ||
|
|
40
|
+
(!isBid && !market.askBook.isOpened)) {
|
|
41
|
+
const unitSize = await (0, unit_size_1.calculateUnitSize)(publicClient, chainId, isBid ? market.quote : market.base);
|
|
42
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
43
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
28
44
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
45
|
+
account: userAddress,
|
|
29
46
|
abi: controller_abi_1.CONTROLLER_ABI,
|
|
30
47
|
functionName: 'open',
|
|
31
48
|
args: [
|
|
32
49
|
[
|
|
33
50
|
{
|
|
34
51
|
key: {
|
|
35
|
-
base:
|
|
36
|
-
|
|
37
|
-
quote:
|
|
38
|
-
makerPolicy: fee_1.MAKER_DEFAULT_POLICY.value,
|
|
52
|
+
base: outputToken,
|
|
53
|
+
unitSize,
|
|
54
|
+
quote: inputToken,
|
|
55
|
+
makerPolicy: fee_1.MAKER_DEFAULT_POLICY[chainId].value,
|
|
39
56
|
hooks: viem_1.zeroAddress,
|
|
40
|
-
takerPolicy: fee_1.TAKER_DEFAULT_POLICY.value,
|
|
57
|
+
takerPolicy: fee_1.TAKER_DEFAULT_POLICY[chainId].value,
|
|
41
58
|
},
|
|
42
59
|
hookData: viem_1.zeroHash,
|
|
43
60
|
},
|
|
44
61
|
],
|
|
45
62
|
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
46
63
|
],
|
|
47
|
-
});
|
|
64
|
+
}, options?.gasLimit);
|
|
48
65
|
}
|
|
49
66
|
return undefined;
|
|
50
|
-
}
|
|
51
|
-
exports.
|
|
52
|
-
|
|
67
|
+
};
|
|
68
|
+
exports.openMarket = openMarket;
|
|
69
|
+
const limitOrder = async ({ chainId, userAddress, inputToken, outputToken, amount, price, options, }) => {
|
|
70
|
+
const [roundingUpMakeBid, roundingDownMakeAsk, roundingDownTakenBid, roundingUpTakenAsk,] = [
|
|
71
|
+
options?.roundingUpMakeBid ? options.roundingUpMakeBid : false,
|
|
72
|
+
options?.roundingDownMakeAsk ? options.roundingDownMakeAsk : false,
|
|
73
|
+
options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
|
|
74
|
+
options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
|
|
75
|
+
];
|
|
76
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
77
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
78
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
79
|
+
});
|
|
80
|
+
const market = await (0, market_1.fetchMarket)(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
53
81
|
const isBid = (0, viem_1.isAddressEqual)(market.quote.address, inputToken);
|
|
54
|
-
|
|
82
|
+
const [inputCurrency, outputCurrency] = isBid
|
|
83
|
+
? [market.quote, market.base]
|
|
84
|
+
: [market.base, market.quote];
|
|
85
|
+
if ((isBid && !market.bidBook.isOpened) ||
|
|
86
|
+
(!isBid && !market.askBook.isOpened)) {
|
|
55
87
|
throw new Error(`
|
|
56
88
|
Open the market before placing a limit order.
|
|
57
89
|
import { openMarket } from '@clober/v2-sdk'
|
|
58
90
|
|
|
59
|
-
const transaction = await openMarket(
|
|
60
|
-
${chainId},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
91
|
+
const transaction = await openMarket({
|
|
92
|
+
chainId: ${chainId},
|
|
93
|
+
inputToken: '${inputToken}',
|
|
94
|
+
outputToken: '${outputToken}',
|
|
95
|
+
})
|
|
64
96
|
`);
|
|
65
97
|
}
|
|
66
|
-
const
|
|
67
|
-
const tick = isBid ? (0, tick_1.fromPrice)(rawPrice) : (0, tick_1.fromPrice)((0, tick_1.invertPrice)(rawPrice));
|
|
98
|
+
const { roundingDownTick, roundingUpTick } = (0, prices_1.parsePrice)(Number(price), market.quote.decimals, market.base.decimals);
|
|
68
99
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !(0, viem_1.isAddressEqual)(address, viem_1.zeroAddress));
|
|
69
|
-
const quoteAmount = (0, viem_1.parseUnits)(amount,
|
|
70
|
-
const [
|
|
71
|
-
(0,
|
|
100
|
+
const quoteAmount = (0, viem_1.parseUnits)(amount, inputCurrency.decimals);
|
|
101
|
+
const [unitSize, { takenAmount, spentAmount, bookId, events }] = await Promise.all([
|
|
102
|
+
(0, unit_size_1.calculateUnitSize)(publicClient, chainId, inputCurrency),
|
|
72
103
|
(0, view_1.getExpectedOutput)({
|
|
73
104
|
chainId,
|
|
74
105
|
inputToken,
|
|
@@ -81,24 +112,21 @@ exports.limitOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress, i
|
|
|
81
112
|
}),
|
|
82
113
|
]);
|
|
83
114
|
const isETH = (0, viem_1.isAddressEqual)(inputToken, viem_1.zeroAddress);
|
|
84
|
-
const permitParamsList = options?.signature && !isETH
|
|
85
|
-
? [
|
|
86
|
-
{
|
|
87
|
-
token: inputToken,
|
|
88
|
-
permitAmount: quoteAmount,
|
|
89
|
-
signature: options.signature,
|
|
90
|
-
},
|
|
91
|
-
]
|
|
92
|
-
: [];
|
|
93
115
|
const makeParam = {
|
|
94
|
-
id: (0, book_id_1.toBookId)(inputToken, outputToken,
|
|
95
|
-
tick:
|
|
116
|
+
id: (0, book_id_1.toBookId)(chainId, inputToken, outputToken, unitSize),
|
|
117
|
+
tick: options?.makeTick
|
|
118
|
+
? Number(options.makeTick)
|
|
119
|
+
: Number(isBid
|
|
120
|
+
? roundingUpMakeBid
|
|
121
|
+
? roundingUpTick
|
|
122
|
+
: roundingDownTick
|
|
123
|
+
: (0, tick_1.invertTick)(roundingDownMakeAsk ? roundingDownTick : roundingUpTick)),
|
|
96
124
|
quoteAmount,
|
|
97
125
|
hookData: viem_1.zeroHash,
|
|
98
126
|
};
|
|
99
|
-
if (options?.postOnly === true ||
|
|
127
|
+
if (options?.postOnly === true || spentAmount === '0') {
|
|
100
128
|
return {
|
|
101
|
-
transaction: await (0, build_transaction_1.buildTransaction)(
|
|
129
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
102
130
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
103
131
|
account: userAddress,
|
|
104
132
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -107,28 +135,38 @@ exports.limitOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress, i
|
|
|
107
135
|
args: [
|
|
108
136
|
[makeParam],
|
|
109
137
|
tokensToSettle,
|
|
110
|
-
|
|
138
|
+
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
111
139
|
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
112
140
|
],
|
|
113
141
|
value: isETH ? quoteAmount : 0n,
|
|
114
|
-
}),
|
|
142
|
+
}, options?.gasLimit),
|
|
115
143
|
result: {
|
|
116
144
|
make: {
|
|
117
|
-
amount: (0, viem_1.formatUnits)(quoteAmount,
|
|
118
|
-
currency:
|
|
145
|
+
amount: (0, viem_1.formatUnits)(quoteAmount, inputCurrency.decimals),
|
|
146
|
+
currency: inputCurrency,
|
|
147
|
+
direction: 'in',
|
|
148
|
+
price: (0, prices_1.formatPrice)(isBid
|
|
149
|
+
? (0, tick_1.toPrice)(BigInt(makeParam.tick))
|
|
150
|
+
: (0, tick_1.toPrice)((0, tick_1.invertTick)(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
151
|
+
},
|
|
152
|
+
spent: {
|
|
153
|
+
amount: '0',
|
|
154
|
+
currency: inputCurrency,
|
|
119
155
|
direction: 'in',
|
|
156
|
+
events: [],
|
|
120
157
|
},
|
|
121
|
-
|
|
158
|
+
taken: {
|
|
122
159
|
amount: '0',
|
|
123
|
-
currency:
|
|
160
|
+
currency: outputCurrency,
|
|
124
161
|
direction: 'out',
|
|
162
|
+
events: [],
|
|
125
163
|
},
|
|
126
164
|
},
|
|
127
165
|
};
|
|
128
166
|
}
|
|
129
167
|
else {
|
|
130
168
|
return {
|
|
131
|
-
transaction: await (0, build_transaction_1.buildTransaction)(
|
|
169
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
132
170
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
133
171
|
account: userAddress,
|
|
134
172
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -139,7 +177,15 @@ exports.limitOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress, i
|
|
|
139
177
|
{
|
|
140
178
|
takeBookId: bookId,
|
|
141
179
|
makeBookId: makeParam.id,
|
|
142
|
-
limitPrice:
|
|
180
|
+
limitPrice: options?.takeLimitTick
|
|
181
|
+
? (0, tick_1.toPrice)(options.takeLimitTick)
|
|
182
|
+
: (0, tick_1.toPrice)(isBid
|
|
183
|
+
? (0, tick_1.invertTick)(roundingUpTakenAsk
|
|
184
|
+
? roundingUpTick
|
|
185
|
+
: roundingDownTick)
|
|
186
|
+
: roundingDownTakenBid
|
|
187
|
+
? roundingDownTick
|
|
188
|
+
: roundingUpTick),
|
|
143
189
|
tick: makeParam.tick,
|
|
144
190
|
quoteAmount,
|
|
145
191
|
takeHookData: viem_1.zeroHash,
|
|
@@ -147,30 +193,61 @@ exports.limitOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress, i
|
|
|
147
193
|
},
|
|
148
194
|
],
|
|
149
195
|
tokensToSettle,
|
|
150
|
-
|
|
196
|
+
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
151
197
|
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
152
198
|
],
|
|
153
199
|
value: isETH ? quoteAmount : 0n,
|
|
154
|
-
}),
|
|
200
|
+
}, options?.gasLimit),
|
|
155
201
|
result: {
|
|
156
202
|
make: {
|
|
157
|
-
amount: (0, viem_1.formatUnits)(quoteAmount
|
|
158
|
-
currency:
|
|
203
|
+
amount: (0, viem_1.formatUnits)(quoteAmount - (0, viem_1.parseUnits)(spentAmount, inputCurrency.decimals), inputCurrency.decimals),
|
|
204
|
+
currency: inputCurrency,
|
|
159
205
|
direction: 'in',
|
|
206
|
+
price: (0, prices_1.formatPrice)(isBid
|
|
207
|
+
? (0, tick_1.toPrice)(BigInt(makeParam.tick))
|
|
208
|
+
: (0, tick_1.toPrice)((0, tick_1.invertTick)(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
160
209
|
},
|
|
161
|
-
|
|
162
|
-
amount:
|
|
163
|
-
currency:
|
|
210
|
+
spent: {
|
|
211
|
+
amount: spentAmount,
|
|
212
|
+
currency: inputCurrency,
|
|
213
|
+
direction: 'in',
|
|
214
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
215
|
+
price,
|
|
216
|
+
amount: spentAmount,
|
|
217
|
+
})),
|
|
218
|
+
},
|
|
219
|
+
taken: {
|
|
220
|
+
amount: takenAmount,
|
|
221
|
+
currency: outputCurrency,
|
|
164
222
|
direction: 'out',
|
|
223
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
224
|
+
price,
|
|
225
|
+
amount: takenAmount,
|
|
226
|
+
})),
|
|
165
227
|
},
|
|
166
228
|
},
|
|
167
229
|
};
|
|
168
230
|
}
|
|
169
|
-
}
|
|
170
|
-
exports.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
231
|
+
};
|
|
232
|
+
exports.limitOrder = limitOrder;
|
|
233
|
+
const marketOrder = async ({ chainId, userAddress, inputToken, outputToken, amountIn, amountOut, options, }) => {
|
|
234
|
+
if (!amountIn && !amountOut) {
|
|
235
|
+
throw new Error('Either amountIn or amountOut must be provided');
|
|
236
|
+
}
|
|
237
|
+
else if (amountIn && amountOut) {
|
|
238
|
+
throw new Error('Only one of amountIn or amountOut can be provided');
|
|
239
|
+
}
|
|
240
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
241
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
242
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
243
|
+
});
|
|
244
|
+
const market = await (0, market_1.fetchMarket)(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
245
|
+
const isTakingBid = (0, viem_1.isAddressEqual)(market.base.address, inputToken);
|
|
246
|
+
const [inputCurrency, outputCurrency] = isTakingBid
|
|
247
|
+
? [market.base, market.quote]
|
|
248
|
+
: [market.quote, market.base];
|
|
249
|
+
if ((isTakingBid && !market.bidBook.isOpened) ||
|
|
250
|
+
(!isTakingBid && !market.askBook.isOpened)) {
|
|
174
251
|
throw new Error(`
|
|
175
252
|
Open the market before placing a market order.
|
|
176
253
|
import { openMarket } from '@clober/v2-sdk'
|
|
@@ -182,51 +259,135 @@ exports.marketOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress,
|
|
|
182
259
|
)
|
|
183
260
|
`);
|
|
184
261
|
}
|
|
185
|
-
const rawLimitPrice = (0, prices_1.parsePrice)(Number(options?.limitPrice ?? '0'), market.quote.decimals, market.base.decimals);
|
|
186
262
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !(0, viem_1.isAddressEqual)(address, viem_1.zeroAddress));
|
|
187
|
-
const quoteAmount = (0, viem_1.parseUnits)(amount, isBid ? market.quote.decimals : market.base.decimals);
|
|
188
|
-
const { bookId, takenAmount } = await (0, view_1.getExpectedOutput)({
|
|
189
|
-
chainId,
|
|
190
|
-
inputToken,
|
|
191
|
-
outputToken,
|
|
192
|
-
amountIn: amount,
|
|
193
|
-
options: {
|
|
194
|
-
...options,
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
263
|
const isETH = (0, viem_1.isAddressEqual)(inputToken, viem_1.zeroAddress);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
264
|
+
if (amountIn && !amountOut) {
|
|
265
|
+
const { bookId, takenAmount, spentAmount, events } = await (0, view_1.getExpectedOutput)({
|
|
266
|
+
chainId,
|
|
267
|
+
inputToken,
|
|
268
|
+
outputToken,
|
|
269
|
+
amountIn,
|
|
270
|
+
options: {
|
|
271
|
+
...options,
|
|
204
272
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
273
|
+
});
|
|
274
|
+
const baseAmount = (0, viem_1.parseUnits)(amountIn, inputCurrency.decimals);
|
|
275
|
+
return {
|
|
276
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
277
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
278
|
+
account: userAddress,
|
|
279
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
280
|
+
abi: controller_abi_1.CONTROLLER_ABI,
|
|
281
|
+
functionName: 'spend',
|
|
282
|
+
args: [
|
|
283
|
+
[
|
|
284
|
+
{
|
|
285
|
+
id: bookId,
|
|
286
|
+
limitPrice: 0n,
|
|
287
|
+
baseAmount,
|
|
288
|
+
minQuoteAmount: options?.slippage
|
|
289
|
+
? (0, bigint_1.applyPercent)((0, viem_1.parseUnits)(takenAmount, outputCurrency.decimals), 100 - options.slippage)
|
|
290
|
+
: 0n,
|
|
291
|
+
hookData: viem_1.zeroHash,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
tokensToSettle,
|
|
295
|
+
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
296
|
+
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
297
|
+
],
|
|
298
|
+
value: isETH ? baseAmount : 0n,
|
|
299
|
+
}, options?.gasLimit),
|
|
300
|
+
result: {
|
|
301
|
+
spent: {
|
|
302
|
+
amount: spentAmount,
|
|
303
|
+
currency: inputCurrency,
|
|
304
|
+
direction: 'in',
|
|
305
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
306
|
+
price,
|
|
307
|
+
amount: spentAmount,
|
|
308
|
+
})),
|
|
220
309
|
},
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
229
|
-
|
|
310
|
+
taken: {
|
|
311
|
+
amount: takenAmount,
|
|
312
|
+
currency: outputCurrency,
|
|
313
|
+
direction: 'out',
|
|
314
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
315
|
+
price,
|
|
316
|
+
amount: takenAmount,
|
|
317
|
+
})),
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
else if (!amountIn && amountOut) {
|
|
323
|
+
const { bookId, spentAmount, takenAmount, events } = await (0, view_1.getExpectedInput)({
|
|
324
|
+
chainId,
|
|
325
|
+
inputToken,
|
|
326
|
+
outputToken,
|
|
327
|
+
amountOut,
|
|
328
|
+
options: {
|
|
329
|
+
...options,
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
const quoteAmount = (0, viem_1.parseUnits)(amountOut, outputCurrency.decimals);
|
|
333
|
+
const baseAmount = (0, viem_1.parseUnits)(spentAmount, inputCurrency.decimals);
|
|
334
|
+
const maxBaseAmount = options?.erc20PermitParam?.permitAmount ??
|
|
335
|
+
(options?.slippage
|
|
336
|
+
? (0, bigint_1.applyPercent)(baseAmount, 100 + options.slippage)
|
|
337
|
+
: isETH
|
|
338
|
+
? baseAmount
|
|
339
|
+
: 2n ** 256n - 1n);
|
|
340
|
+
return {
|
|
341
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
342
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
343
|
+
account: userAddress,
|
|
344
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
345
|
+
abi: controller_abi_1.CONTROLLER_ABI,
|
|
346
|
+
functionName: 'take',
|
|
347
|
+
args: [
|
|
348
|
+
[
|
|
349
|
+
{
|
|
350
|
+
id: bookId,
|
|
351
|
+
limitPrice: 0n,
|
|
352
|
+
quoteAmount,
|
|
353
|
+
maxBaseAmount,
|
|
354
|
+
hookData: viem_1.zeroHash,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
tokensToSettle,
|
|
358
|
+
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
359
|
+
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
360
|
+
],
|
|
361
|
+
value: isETH ? maxBaseAmount : 0n,
|
|
362
|
+
}, options?.gasLimit),
|
|
363
|
+
result: {
|
|
364
|
+
spent: {
|
|
365
|
+
amount: spentAmount,
|
|
366
|
+
currency: inputCurrency,
|
|
367
|
+
direction: 'in',
|
|
368
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
369
|
+
price,
|
|
370
|
+
amount: spentAmount,
|
|
371
|
+
})),
|
|
372
|
+
},
|
|
373
|
+
taken: {
|
|
374
|
+
amount: takenAmount,
|
|
375
|
+
currency: outputCurrency,
|
|
376
|
+
direction: 'out',
|
|
377
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
378
|
+
price,
|
|
379
|
+
amount: takenAmount,
|
|
380
|
+
})),
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
throw new Error('Either amountIn or amountOut must be provided');
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
exports.marketOrder = marketOrder;
|
|
390
|
+
const claimOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
230
391
|
const { transaction, result } = await (0, exports.claimOrders)({
|
|
231
392
|
chainId,
|
|
232
393
|
userAddress,
|
|
@@ -237,62 +398,60 @@ exports.claimOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress, i
|
|
|
237
398
|
transaction,
|
|
238
399
|
result: result[0],
|
|
239
400
|
};
|
|
240
|
-
}
|
|
241
|
-
exports.
|
|
242
|
-
|
|
401
|
+
};
|
|
402
|
+
exports.claimOrder = claimOrder;
|
|
403
|
+
const claimOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
404
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
405
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
406
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
407
|
+
});
|
|
408
|
+
const isApprovedForAll = await (0, approval_1.fetchIsApprovedForAll)(publicClient, chainId, userAddress);
|
|
243
409
|
if (!isApprovedForAll) {
|
|
244
410
|
throw new Error(`
|
|
245
411
|
Set ApprovalForAll before calling this function.
|
|
246
412
|
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
247
413
|
|
|
248
|
-
const hash = await setApprovalOfOpenOrdersForAll(
|
|
249
|
-
${chainId},
|
|
250
|
-
|
|
251
|
-
)
|
|
414
|
+
const hash = await setApprovalOfOpenOrdersForAll({
|
|
415
|
+
chainId: ${chainId},
|
|
416
|
+
walletClient, // use viem
|
|
417
|
+
})
|
|
252
418
|
`);
|
|
253
419
|
}
|
|
254
|
-
const orders = (await (0, order_1.
|
|
420
|
+
const orders = (await (0, order_1.fetchOnChainOrders)(publicClient, chainId, ids.map((id) => BigInt(id)), !!(options && options.useSubgraph))).filter((order) => (0, viem_1.isAddressEqual)(order.user, userAddress) && order.claimable.value !== '0');
|
|
255
421
|
const tokensToSettle = orders
|
|
256
|
-
.map((order) => [order.
|
|
422
|
+
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
257
423
|
.flat()
|
|
258
424
|
.filter((address, index, self) => self.findIndex((c) => (0, viem_1.isAddressEqual)(c, address)) === index)
|
|
259
425
|
.filter((address) => !(0, viem_1.isAddressEqual)(address, viem_1.zeroAddress));
|
|
260
426
|
return {
|
|
261
|
-
transaction: await (0, build_transaction_1.buildTransaction)(
|
|
427
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
262
428
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
263
429
|
account: userAddress,
|
|
264
430
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
265
431
|
abi: controller_abi_1.CONTROLLER_ABI,
|
|
266
432
|
functionName: 'claim',
|
|
267
433
|
args: [
|
|
268
|
-
orders.map(({
|
|
269
|
-
id
|
|
434
|
+
orders.map(({ id }) => ({
|
|
435
|
+
id,
|
|
270
436
|
hookData: viem_1.zeroHash,
|
|
271
437
|
})),
|
|
272
438
|
tokensToSettle,
|
|
273
439
|
[],
|
|
274
440
|
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
275
441
|
],
|
|
276
|
-
}),
|
|
277
|
-
result: orders
|
|
278
|
-
.map((order) => {
|
|
279
|
-
const amount = (0, decimals_1.quoteToBase)(order.tick, order.unit * order.claimable, false);
|
|
280
|
-
return {
|
|
281
|
-
currency: order.baseCurrency,
|
|
282
|
-
amount: (0, viem_1.formatUnits)(amount, order.baseCurrency.decimals),
|
|
283
|
-
};
|
|
284
|
-
})
|
|
285
|
-
.reduce((acc, { currency, amount }) => {
|
|
442
|
+
}, options?.gasLimit),
|
|
443
|
+
result: orders.reduce((acc, { claimable: { currency, value } }) => {
|
|
286
444
|
const index = acc.findIndex((c) => (0, viem_1.isAddressEqual)(c.currency.address, currency.address));
|
|
287
445
|
if (index === -1) {
|
|
288
|
-
return [...acc, { currency, amount, direction: 'out' }];
|
|
446
|
+
return [...acc, { currency, amount: value, direction: 'out' }];
|
|
289
447
|
}
|
|
290
|
-
acc[index].amount = (Number(acc[index].amount) + Number(
|
|
448
|
+
acc[index].amount = (Number(acc[index].amount) + Number(value)).toString();
|
|
291
449
|
return acc;
|
|
292
450
|
}, []),
|
|
293
451
|
};
|
|
294
|
-
}
|
|
295
|
-
exports.
|
|
452
|
+
};
|
|
453
|
+
exports.claimOrders = claimOrders;
|
|
454
|
+
const cancelOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
296
455
|
const { transaction, result } = await (0, exports.cancelOrders)({
|
|
297
456
|
chainId,
|
|
298
457
|
userAddress,
|
|
@@ -303,36 +462,41 @@ exports.cancelOrder = (0, decorator_1.decorator)(async ({ chainId, userAddress,
|
|
|
303
462
|
transaction,
|
|
304
463
|
result: result[0],
|
|
305
464
|
};
|
|
306
|
-
}
|
|
307
|
-
exports.
|
|
308
|
-
|
|
465
|
+
};
|
|
466
|
+
exports.cancelOrder = cancelOrder;
|
|
467
|
+
const cancelOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
468
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
469
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
470
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
471
|
+
});
|
|
472
|
+
const isApprovedForAll = await (0, approval_1.fetchIsApprovedForAll)(publicClient, chainId, userAddress);
|
|
309
473
|
if (!isApprovedForAll) {
|
|
310
474
|
throw new Error(`
|
|
311
475
|
Set ApprovalForAll before calling this function.
|
|
312
476
|
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
313
477
|
|
|
314
|
-
const hash = await setApprovalOfOpenOrdersForAll(
|
|
315
|
-
${chainId},
|
|
316
|
-
|
|
317
|
-
)
|
|
478
|
+
const hash = await setApprovalOfOpenOrdersForAll({
|
|
479
|
+
chainId: ${chainId},
|
|
480
|
+
walletClient, // use viem
|
|
481
|
+
})
|
|
318
482
|
`);
|
|
319
483
|
}
|
|
320
|
-
const orders = (await (0, order_1.
|
|
484
|
+
const orders = (await (0, order_1.fetchOnChainOrders)(publicClient, chainId, ids.map((id) => BigInt(id)), !!(options && options.useSubgraph))).filter((order) => (0, viem_1.isAddressEqual)(order.user, userAddress) && order.cancelable.value !== '0');
|
|
321
485
|
const tokensToSettle = orders
|
|
322
|
-
.map((order) => [order.
|
|
486
|
+
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
323
487
|
.flat()
|
|
324
488
|
.filter((address, index, self) => self.findIndex((c) => (0, viem_1.isAddressEqual)(c, address)) === index)
|
|
325
489
|
.filter((address) => !(0, viem_1.isAddressEqual)(address, viem_1.zeroAddress));
|
|
326
490
|
return {
|
|
327
|
-
transaction: await (0, build_transaction_1.buildTransaction)(
|
|
491
|
+
transaction: await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
328
492
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
329
493
|
account: userAddress,
|
|
330
494
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
331
495
|
abi: controller_abi_1.CONTROLLER_ABI,
|
|
332
496
|
functionName: 'cancel',
|
|
333
497
|
args: [
|
|
334
|
-
orders.map(({
|
|
335
|
-
id
|
|
498
|
+
orders.map(({ id }) => ({
|
|
499
|
+
id,
|
|
336
500
|
leftQuoteAmount: 0n,
|
|
337
501
|
hookData: viem_1.zeroHash,
|
|
338
502
|
})),
|
|
@@ -340,25 +504,613 @@ exports.cancelOrders = (0, decorator_1.decorator)(async ({ chainId, userAddress,
|
|
|
340
504
|
[],
|
|
341
505
|
(0, time_1.getDeadlineTimestampInSeconds)(),
|
|
342
506
|
],
|
|
343
|
-
}),
|
|
344
|
-
result: orders
|
|
345
|
-
.map((order) => {
|
|
346
|
-
const amount = (0, bigint_1.applyPercent)(order.unit * order.open, 100 +
|
|
347
|
-
(Number(fee_1.MAKER_DEFAULT_POLICY.rate) * 100) /
|
|
348
|
-
Number(fee_1.MAKER_DEFAULT_POLICY.RATE_PRECISION), 6);
|
|
349
|
-
return {
|
|
350
|
-
currency: order.quoteCurrency,
|
|
351
|
-
amount: (0, viem_1.formatUnits)(amount, order.quoteCurrency.decimals),
|
|
352
|
-
};
|
|
353
|
-
})
|
|
354
|
-
.reduce((acc, { currency, amount }) => {
|
|
507
|
+
}, options?.gasLimit),
|
|
508
|
+
result: orders.reduce((acc, { cancelable: { currency, value } }) => {
|
|
355
509
|
const index = acc.findIndex((c) => (0, viem_1.isAddressEqual)(c.currency.address, currency.address));
|
|
356
510
|
if (index === -1) {
|
|
357
|
-
return [...acc, { currency, amount, direction: 'out' }];
|
|
511
|
+
return [...acc, { currency, amount: value, direction: 'out' }];
|
|
358
512
|
}
|
|
359
|
-
acc[index].amount = (Number(acc[index].amount) + Number(
|
|
513
|
+
acc[index].amount = (Number(acc[index].amount) + Number(value)).toString();
|
|
360
514
|
return acc;
|
|
361
515
|
}, []),
|
|
362
516
|
};
|
|
363
|
-
}
|
|
517
|
+
};
|
|
518
|
+
exports.cancelOrders = cancelOrders;
|
|
519
|
+
const openPool = async ({ chainId, userAddress, tokenA, tokenB, salt, options, }) => {
|
|
520
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
521
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
522
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
523
|
+
});
|
|
524
|
+
const pool = await (0, pool_1.fetchPool)(publicClient, chainId, [tokenA, tokenB], salt, !!(options && options.useSubgraph));
|
|
525
|
+
if (!pool.isOpened) {
|
|
526
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
527
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
528
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
529
|
+
account: userAddress,
|
|
530
|
+
abi: rebalancer_abi_1.REBALANCER_ABI,
|
|
531
|
+
functionName: 'open',
|
|
532
|
+
args: [
|
|
533
|
+
{
|
|
534
|
+
base: pool.market.bidBook.base.address,
|
|
535
|
+
unitSize: pool.market.bidBook.unitSize,
|
|
536
|
+
quote: pool.market.bidBook.quote.address,
|
|
537
|
+
makerPolicy: fee_1.MAKER_DEFAULT_POLICY[chainId].value,
|
|
538
|
+
hooks: viem_1.zeroAddress,
|
|
539
|
+
takerPolicy: fee_1.TAKER_DEFAULT_POLICY[chainId].value,
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
base: pool.market.askBook.base.address,
|
|
543
|
+
unitSize: pool.market.askBook.unitSize,
|
|
544
|
+
quote: pool.market.askBook.quote.address,
|
|
545
|
+
makerPolicy: fee_1.MAKER_DEFAULT_POLICY[chainId].value,
|
|
546
|
+
hooks: viem_1.zeroAddress,
|
|
547
|
+
takerPolicy: fee_1.TAKER_DEFAULT_POLICY[chainId].value,
|
|
548
|
+
},
|
|
549
|
+
(0, pool_key_1.toBytes32)(salt),
|
|
550
|
+
addresses_1.CONTRACT_ADDRESSES[chainId].Strategy,
|
|
551
|
+
],
|
|
552
|
+
}, options?.gasLimit);
|
|
553
|
+
}
|
|
554
|
+
return undefined;
|
|
555
|
+
};
|
|
556
|
+
exports.openPool = openPool;
|
|
557
|
+
const addLiquidity = async ({ chainId, userAddress, token0, token1, salt, amount0, amount1, options, }) => {
|
|
558
|
+
if ((0, viem_1.isAddressEqual)(token0, viem_1.zeroAddress) ||
|
|
559
|
+
(0, viem_1.isAddressEqual)(token1, viem_1.zeroAddress)) {
|
|
560
|
+
throw new Error('ETH is not supported for adding liquidity');
|
|
561
|
+
}
|
|
562
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
563
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
564
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
565
|
+
});
|
|
566
|
+
const pool = await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
567
|
+
if (!pool.isOpened) {
|
|
568
|
+
throw new Error(`
|
|
569
|
+
Open the pool before adding liquidity.
|
|
570
|
+
import { openPool } from '@clober/v2-sdk'
|
|
571
|
+
|
|
572
|
+
const transaction = await openPool({
|
|
573
|
+
chainId: ${chainId},
|
|
574
|
+
tokenA: '${token0}',
|
|
575
|
+
tokenB: '${token1}',
|
|
576
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
577
|
+
})
|
|
578
|
+
`);
|
|
579
|
+
}
|
|
580
|
+
const [amountAOrigin, amountBOrigin] = (0, viem_1.isAddressEqual)(pool.currencyA.address, (0, viem_1.getAddress)(token0))
|
|
581
|
+
? [
|
|
582
|
+
(0, viem_1.parseUnits)(amount0 ?? '0', pool.currencyA.decimals),
|
|
583
|
+
(0, viem_1.parseUnits)(amount1 ?? '0', pool.currencyB.decimals),
|
|
584
|
+
]
|
|
585
|
+
: [
|
|
586
|
+
(0, viem_1.parseUnits)(amount1 ?? '0', pool.currencyA.decimals),
|
|
587
|
+
(0, viem_1.parseUnits)(amount0 ?? '0', pool.currencyB.decimals),
|
|
588
|
+
];
|
|
589
|
+
let [amountA, amountB] = [amountAOrigin, amountBOrigin];
|
|
590
|
+
const tokenAPermitParams = (0, viem_1.isAddressEqual)(pool.currencyA.address, (0, viem_1.getAddress)(token0))
|
|
591
|
+
? options?.token0PermitParams ?? permit_1.emptyERC20PermitParams
|
|
592
|
+
: options?.token1PermitParams ?? permit_1.emptyERC20PermitParams;
|
|
593
|
+
const tokenBPermitParams = (0, viem_1.isAddressEqual)(pool.currencyA.address, (0, viem_1.getAddress)(token0))
|
|
594
|
+
? options?.token1PermitParams ?? permit_1.emptyERC20PermitParams
|
|
595
|
+
: options?.token0PermitParams ?? permit_1.emptyERC20PermitParams;
|
|
596
|
+
let disableSwap = !!(options && options.disableSwap);
|
|
597
|
+
if (pool.totalSupply === 0n ||
|
|
598
|
+
(pool.liquidityA === 0n && pool.liquidityB === 0n)) {
|
|
599
|
+
disableSwap = true;
|
|
600
|
+
}
|
|
601
|
+
const slippageLimitPercent = options?.slippage ?? 2;
|
|
602
|
+
const swapParams = {
|
|
603
|
+
inCurrency: viem_1.zeroAddress,
|
|
604
|
+
amount: 0n,
|
|
605
|
+
data: '0x',
|
|
606
|
+
};
|
|
607
|
+
if (!disableSwap) {
|
|
608
|
+
const currencyBPerCurrencyA = options?.testnetPrice
|
|
609
|
+
? (0, viem_1.isAddressEqual)((0, view_1.getQuoteToken)({
|
|
610
|
+
chainId,
|
|
611
|
+
token0,
|
|
612
|
+
token1,
|
|
613
|
+
}), pool.currencyA.address)
|
|
614
|
+
? 1 / Number(options.testnetPrice)
|
|
615
|
+
: Number(options.testnetPrice)
|
|
616
|
+
: undefined;
|
|
617
|
+
const swapAmountA = (0, viem_1.parseUnits)('1', pool.currencyA.decimals);
|
|
618
|
+
const { amountOut: swapAmountB } = await (0, odos_1.fetchQuote)({
|
|
619
|
+
chainId,
|
|
620
|
+
amountIn: swapAmountA,
|
|
621
|
+
tokenIn: pool.currencyA,
|
|
622
|
+
tokenOut: pool.currencyB,
|
|
623
|
+
slippageLimitPercent: 20,
|
|
624
|
+
userAddress: addresses_1.CONTRACT_ADDRESSES[chainId].Minter,
|
|
625
|
+
testnetPrice: currencyBPerCurrencyA,
|
|
626
|
+
});
|
|
627
|
+
const { deltaA, deltaB } = (0, pool_2.getIdealDelta)(amountA, amountB, pool.liquidityA, pool.liquidityB, swapAmountA, swapAmountB);
|
|
628
|
+
if (deltaA < 0n) {
|
|
629
|
+
swapParams.inCurrency = pool.currencyA.address;
|
|
630
|
+
swapParams.amount = -deltaA;
|
|
631
|
+
const { amountOut: actualDeltaB, data: calldata } = await (0, odos_1.fetchCallData)({
|
|
632
|
+
chainId,
|
|
633
|
+
amountIn: swapParams.amount,
|
|
634
|
+
tokenIn: pool.currencyA,
|
|
635
|
+
tokenOut: pool.currencyB,
|
|
636
|
+
slippageLimitPercent,
|
|
637
|
+
userAddress: addresses_1.CONTRACT_ADDRESSES[chainId].Minter,
|
|
638
|
+
testnetPrice: currencyBPerCurrencyA,
|
|
639
|
+
});
|
|
640
|
+
swapParams.data = calldata;
|
|
641
|
+
amountA += deltaA;
|
|
642
|
+
amountB += actualDeltaB;
|
|
643
|
+
}
|
|
644
|
+
else if (deltaB < 0n) {
|
|
645
|
+
swapParams.inCurrency = pool.currencyB.address;
|
|
646
|
+
swapParams.amount = -deltaB;
|
|
647
|
+
const { amountOut: actualDeltaA, data: calldata } = await (0, odos_1.fetchCallData)({
|
|
648
|
+
chainId,
|
|
649
|
+
amountIn: swapParams.amount,
|
|
650
|
+
tokenIn: pool.currencyB,
|
|
651
|
+
tokenOut: pool.currencyA,
|
|
652
|
+
slippageLimitPercent,
|
|
653
|
+
userAddress: addresses_1.CONTRACT_ADDRESSES[chainId].Minter,
|
|
654
|
+
testnetPrice: currencyBPerCurrencyA
|
|
655
|
+
? 1 / currencyBPerCurrencyA
|
|
656
|
+
: undefined,
|
|
657
|
+
});
|
|
658
|
+
swapParams.data = calldata;
|
|
659
|
+
amountA += actualDeltaA;
|
|
660
|
+
amountB += deltaB;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
const { mintAmount, inAmountA, inAmountB } = (0, pool_2.getExpectedMintResult)(pool.totalSupply, pool.liquidityA, pool.liquidityB, amountA, amountB, pool.currencyA, pool.currencyB);
|
|
664
|
+
if (mintAmount === 0n) {
|
|
665
|
+
return {
|
|
666
|
+
transaction: undefined,
|
|
667
|
+
result: {
|
|
668
|
+
currencyA: {
|
|
669
|
+
currency: pool.currencyA,
|
|
670
|
+
amount: '0',
|
|
671
|
+
direction: 'in',
|
|
672
|
+
},
|
|
673
|
+
currencyB: {
|
|
674
|
+
currency: pool.currencyB,
|
|
675
|
+
amount: '0',
|
|
676
|
+
direction: 'in',
|
|
677
|
+
},
|
|
678
|
+
lpCurrency: {
|
|
679
|
+
currency: pool.currencyLp,
|
|
680
|
+
amount: '0',
|
|
681
|
+
direction: 'out',
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
const minMintAmount = (0, bigint_1.applyPercent)(mintAmount, 100 - slippageLimitPercent);
|
|
687
|
+
const transaction = await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
688
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
689
|
+
account: userAddress,
|
|
690
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Minter,
|
|
691
|
+
abi: minter_abi_1.MINTER_ABI,
|
|
692
|
+
functionName: 'mint',
|
|
693
|
+
args: [
|
|
694
|
+
pool.key,
|
|
695
|
+
amountAOrigin,
|
|
696
|
+
amountBOrigin,
|
|
697
|
+
minMintAmount,
|
|
698
|
+
{
|
|
699
|
+
permitAmount: tokenAPermitParams.permitAmount,
|
|
700
|
+
signature: tokenAPermitParams.signature,
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
permitAmount: tokenBPermitParams.permitAmount,
|
|
704
|
+
signature: tokenBPermitParams.signature,
|
|
705
|
+
},
|
|
706
|
+
swapParams,
|
|
707
|
+
],
|
|
708
|
+
value: (0, viem_1.isAddressEqual)(token0, viem_1.zeroAddress)
|
|
709
|
+
? amountAOrigin
|
|
710
|
+
: (0, viem_1.isAddressEqual)(token1, viem_1.zeroAddress)
|
|
711
|
+
? amountBOrigin
|
|
712
|
+
: undefined,
|
|
713
|
+
}, options?.gasLimit);
|
|
714
|
+
const currencyARefund = amountA - inAmountA;
|
|
715
|
+
const currencyBRefund = amountB - inAmountB;
|
|
716
|
+
const currencyAResultAmount = amountAOrigin - currencyARefund;
|
|
717
|
+
const currencyBResultAmount = amountBOrigin - currencyBRefund;
|
|
718
|
+
return {
|
|
719
|
+
transaction,
|
|
720
|
+
result: {
|
|
721
|
+
currencyA: {
|
|
722
|
+
currency: pool.currencyA,
|
|
723
|
+
amount: (0, viem_1.formatUnits)((0, math_1.abs)(currencyAResultAmount), pool.currencyA.decimals),
|
|
724
|
+
direction: currencyAResultAmount >= 0 ? 'in' : 'out',
|
|
725
|
+
},
|
|
726
|
+
currencyB: {
|
|
727
|
+
currency: pool.currencyB,
|
|
728
|
+
amount: (0, viem_1.formatUnits)((0, math_1.abs)(currencyBResultAmount), pool.currencyB.decimals),
|
|
729
|
+
direction: currencyBResultAmount >= 0 ? 'in' : 'out',
|
|
730
|
+
},
|
|
731
|
+
lpCurrency: {
|
|
732
|
+
currency: pool.currencyLp,
|
|
733
|
+
amount: (0, viem_1.formatUnits)(mintAmount, pool.currencyLp.decimals),
|
|
734
|
+
direction: 'out',
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
};
|
|
738
|
+
};
|
|
739
|
+
exports.addLiquidity = addLiquidity;
|
|
740
|
+
const removeLiquidity = async ({ chainId, userAddress, token0, token1, salt, amount, options, }) => {
|
|
741
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
742
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
743
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
744
|
+
});
|
|
745
|
+
const pool = await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
746
|
+
if (!pool.isOpened) {
|
|
747
|
+
throw new Error(`
|
|
748
|
+
Open the pool before removing liquidity.
|
|
749
|
+
import { openPool } from '@clober/v2-sdk'
|
|
750
|
+
|
|
751
|
+
const transaction = await openPool({
|
|
752
|
+
chainId: ${chainId},
|
|
753
|
+
tokenA: '${token0}',
|
|
754
|
+
tokenB: '${token1}',
|
|
755
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
756
|
+
})
|
|
757
|
+
`);
|
|
758
|
+
}
|
|
759
|
+
const burnAmount = (0, viem_1.parseUnits)(amount, pool.currencyLp.decimals);
|
|
760
|
+
const slippageLimitPercent = options?.slippage ?? 2;
|
|
761
|
+
const withdrawAmountA = (burnAmount * pool.liquidityA) / pool.totalSupply;
|
|
762
|
+
const withdrawAmountB = (burnAmount * pool.liquidityB) / pool.totalSupply;
|
|
763
|
+
const minWithdrawAmountA = (0, bigint_1.applyPercent)(withdrawAmountA, 100 - slippageLimitPercent);
|
|
764
|
+
const minWithdrawAmountB = (0, bigint_1.applyPercent)(withdrawAmountB, 100 - slippageLimitPercent);
|
|
765
|
+
if (burnAmount === 0n) {
|
|
766
|
+
return {
|
|
767
|
+
transaction: undefined,
|
|
768
|
+
result: {
|
|
769
|
+
currencyA: {
|
|
770
|
+
currency: pool.currencyA,
|
|
771
|
+
amount: '0',
|
|
772
|
+
direction: 'out',
|
|
773
|
+
},
|
|
774
|
+
currencyB: {
|
|
775
|
+
currency: pool.currencyB,
|
|
776
|
+
amount: '0',
|
|
777
|
+
direction: 'out',
|
|
778
|
+
},
|
|
779
|
+
lpCurrency: {
|
|
780
|
+
currency: pool.currencyLp,
|
|
781
|
+
amount: '0',
|
|
782
|
+
direction: 'in',
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
const transaction = await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
788
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
789
|
+
account: userAddress,
|
|
790
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
791
|
+
abi: rebalancer_abi_1.REBALANCER_ABI,
|
|
792
|
+
functionName: 'burn',
|
|
793
|
+
args: [pool.key, burnAmount, minWithdrawAmountA, minWithdrawAmountB],
|
|
794
|
+
}, options?.gasLimit);
|
|
795
|
+
return {
|
|
796
|
+
transaction,
|
|
797
|
+
result: {
|
|
798
|
+
currencyA: {
|
|
799
|
+
currency: pool.currencyA,
|
|
800
|
+
amount: (0, viem_1.formatUnits)(withdrawAmountA, pool.currencyA.decimals),
|
|
801
|
+
direction: 'out',
|
|
802
|
+
},
|
|
803
|
+
currencyB: {
|
|
804
|
+
currency: pool.currencyB,
|
|
805
|
+
amount: (0, viem_1.formatUnits)(withdrawAmountB, pool.currencyB.decimals),
|
|
806
|
+
direction: 'out',
|
|
807
|
+
},
|
|
808
|
+
lpCurrency: {
|
|
809
|
+
currency: pool.currencyLp,
|
|
810
|
+
amount: amount,
|
|
811
|
+
direction: 'in',
|
|
812
|
+
},
|
|
813
|
+
},
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
exports.removeLiquidity = removeLiquidity;
|
|
817
|
+
const refillOrder = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
818
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
819
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
820
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
821
|
+
});
|
|
822
|
+
const pool = options?.pool
|
|
823
|
+
? options.pool
|
|
824
|
+
: (await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
825
|
+
if (!pool.isOpened) {
|
|
826
|
+
throw new Error(`
|
|
827
|
+
Open the pool before rebalancing pool.
|
|
828
|
+
import { openPool } from '@clober/v2-sdk'
|
|
829
|
+
|
|
830
|
+
const transaction = await openPool({
|
|
831
|
+
chainId: ${chainId},
|
|
832
|
+
tokenA: '${token0}',
|
|
833
|
+
tokenB: '${token1}',
|
|
834
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
835
|
+
})
|
|
836
|
+
`);
|
|
837
|
+
}
|
|
838
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
839
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
840
|
+
account: userAddress,
|
|
841
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
842
|
+
abi: rebalancer_abi_1.REBALANCER_ABI,
|
|
843
|
+
functionName: 'rebalance',
|
|
844
|
+
args: [pool.key],
|
|
845
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
846
|
+
};
|
|
847
|
+
exports.refillOrder = refillOrder;
|
|
848
|
+
const adjustOrderPrice = async ({ chainId, userAddress, token0, token1, salt, oraclePrice, bidPrice, askPrice, alpha, options, }) => {
|
|
849
|
+
if (Number(alpha) <= 0 || Number(alpha) > 1) {
|
|
850
|
+
throw new Error('Alpha value must be in the range (0, 1]');
|
|
851
|
+
}
|
|
852
|
+
if (Number(bidPrice) <= 0 || Number(askPrice) <= 0) {
|
|
853
|
+
throw new Error('Price must be greater than 0');
|
|
854
|
+
}
|
|
855
|
+
if (Number(bidPrice) >= Number(askPrice)) {
|
|
856
|
+
throw new Error('Bid price must be less than ask price');
|
|
857
|
+
}
|
|
858
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
859
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
860
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
861
|
+
});
|
|
862
|
+
const pool = options?.pool
|
|
863
|
+
? options.pool
|
|
864
|
+
: (await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
865
|
+
if (!pool.isOpened) {
|
|
866
|
+
throw new Error(`
|
|
867
|
+
Open the pool before updating strategy price.
|
|
868
|
+
import { openPool } from '@clober/v2-sdk'
|
|
869
|
+
|
|
870
|
+
const transaction = await openPool({
|
|
871
|
+
chainId: ${chainId},
|
|
872
|
+
tokenA: '${token0}',
|
|
873
|
+
tokenB: '${token1}',
|
|
874
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
875
|
+
})
|
|
876
|
+
`);
|
|
877
|
+
}
|
|
878
|
+
const [roundingUpBidPrice, roundingUpAskPrice] = [
|
|
879
|
+
options?.roundingUpBidPrice ? options.roundingUpBidPrice : false,
|
|
880
|
+
options?.roundingUpAskPrice ? options.roundingUpAskPrice : false,
|
|
881
|
+
];
|
|
882
|
+
const { roundingDownTick: roundingDownTickA, roundingUpTick: roundingUpTickA, } = (0, prices_1.parsePrice)(Number(bidPrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
883
|
+
const { roundingDownTick: roundingDownTickB, roundingUpTick: roundingUpTickB, } = (0, prices_1.parsePrice)(Number(askPrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
884
|
+
const oracleRawPrice = (0, prices_1.convertHumanReadablePriceToRawPrice)(Number(oraclePrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
885
|
+
const tickA = options?.bidTick
|
|
886
|
+
? Number(options.bidTick)
|
|
887
|
+
: Number(roundingUpBidPrice ? roundingUpTickA : roundingDownTickA);
|
|
888
|
+
let tickB = options?.askTick
|
|
889
|
+
? Number(options.askTick)
|
|
890
|
+
: Number((0, tick_1.invertTick)(roundingUpAskPrice ? roundingUpTickB : roundingDownTickB));
|
|
891
|
+
if ((0, tick_1.invertTick)(BigInt(tickB)) <= BigInt(tickA)) {
|
|
892
|
+
tickB = Number((0, tick_1.invertTick)(BigInt(tickA + 1)));
|
|
893
|
+
}
|
|
894
|
+
const rateRaw = (0, viem_1.parseUnits)(alpha, 6);
|
|
895
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
896
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
897
|
+
account: userAddress,
|
|
898
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Operator,
|
|
899
|
+
abi: operator_abi_1.OPERATOR_ABI,
|
|
900
|
+
functionName: 'updatePosition',
|
|
901
|
+
args: [pool.key, oracleRawPrice, tickA, tickB, rateRaw],
|
|
902
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
903
|
+
};
|
|
904
|
+
exports.adjustOrderPrice = adjustOrderPrice;
|
|
905
|
+
const setStrategyConfig = async ({ chainId, userAddress, token0, token1, salt, config, options, }) => {
|
|
906
|
+
if (Number(config.referenceThreshold) < 0 ||
|
|
907
|
+
Number(config.referenceThreshold) > 1) {
|
|
908
|
+
throw new Error('Reference threshold must be in the range [0, 1]');
|
|
909
|
+
}
|
|
910
|
+
if (Number(config.rebalanceThreshold) < 0 ||
|
|
911
|
+
Number(config.rebalanceThreshold) > 1) {
|
|
912
|
+
throw new Error('Rebalance threshold must be in the range [0, 1]');
|
|
913
|
+
}
|
|
914
|
+
if (Number(config.priceThresholdA) < 0 ||
|
|
915
|
+
Number(config.priceThresholdA) > 1 ||
|
|
916
|
+
Number(config.priceThresholdB) < 0 ||
|
|
917
|
+
Number(config.priceThresholdB) > 1) {
|
|
918
|
+
throw new Error('Price threshold must be in the range [0, 1]');
|
|
919
|
+
}
|
|
920
|
+
if (Number(config.rateA) < 0 ||
|
|
921
|
+
Number(config.rateA) > 1 ||
|
|
922
|
+
Number(config.rateB) < 0 ||
|
|
923
|
+
Number(config.rateB) > 1) {
|
|
924
|
+
throw new Error('Rate must be in the range [0, 1]');
|
|
925
|
+
}
|
|
926
|
+
if (Number(config.minRateA) < 0 ||
|
|
927
|
+
Number(config.minRateA) > 1 ||
|
|
928
|
+
Number(config.minRateB) < 0 ||
|
|
929
|
+
Number(config.minRateB) > 1) {
|
|
930
|
+
throw new Error('Min rate must be in the range [0, 1]');
|
|
931
|
+
}
|
|
932
|
+
if (Number(config.minRateA) > Number(config.rateA) ||
|
|
933
|
+
Number(config.minRateB) > Number(config.rateB)) {
|
|
934
|
+
throw new Error('Min rate must be less or equal to rate');
|
|
935
|
+
}
|
|
936
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
937
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
938
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
939
|
+
});
|
|
940
|
+
const pool = await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
941
|
+
if (!pool.isOpened) {
|
|
942
|
+
throw new Error(`
|
|
943
|
+
Open the pool before set strategy config.
|
|
944
|
+
import { openPool } from '@clober/v2-sdk'
|
|
945
|
+
|
|
946
|
+
const transaction = await openPool({
|
|
947
|
+
chainId: ${chainId},
|
|
948
|
+
tokenA: '${token0}',
|
|
949
|
+
tokenB: '${token1}',
|
|
950
|
+
})
|
|
951
|
+
`);
|
|
952
|
+
}
|
|
953
|
+
const configRaw = {
|
|
954
|
+
referenceThreshold: (0, viem_1.parseUnits)(config.referenceThreshold, 6),
|
|
955
|
+
rebalanceThreshold: (0, viem_1.parseUnits)(config.rebalanceThreshold, 6),
|
|
956
|
+
rateA: (0, viem_1.parseUnits)(config.rateA, 6),
|
|
957
|
+
rateB: (0, viem_1.parseUnits)(config.rateB, 6),
|
|
958
|
+
minRateA: (0, viem_1.parseUnits)(config.minRateA, 6),
|
|
959
|
+
minRateB: (0, viem_1.parseUnits)(config.minRateB, 6),
|
|
960
|
+
priceThresholdA: (0, viem_1.parseUnits)(config.priceThresholdA, 6),
|
|
961
|
+
priceThresholdB: (0, viem_1.parseUnits)(config.priceThresholdB, 6),
|
|
962
|
+
};
|
|
963
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
964
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
965
|
+
account: userAddress,
|
|
966
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Strategy,
|
|
967
|
+
abi: strategy_abi_1.STRATEGY_ABI,
|
|
968
|
+
functionName: 'setConfig',
|
|
969
|
+
args: [pool.key, configRaw],
|
|
970
|
+
}, options?.gasLimit);
|
|
971
|
+
};
|
|
972
|
+
exports.setStrategyConfig = setStrategyConfig;
|
|
973
|
+
const pausePool = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
974
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
975
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
976
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
977
|
+
});
|
|
978
|
+
const pool = options?.pool
|
|
979
|
+
? options.pool
|
|
980
|
+
: (await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
981
|
+
if (!pool.isOpened) {
|
|
982
|
+
throw new Error(`
|
|
983
|
+
Open the pool before trying pause.
|
|
984
|
+
import { openPool } from '@clober/v2-sdk'
|
|
985
|
+
|
|
986
|
+
const transaction = await openPool({
|
|
987
|
+
chainId: ${chainId},
|
|
988
|
+
tokenA: '${token0}',
|
|
989
|
+
tokenB: '${token1}',
|
|
990
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
991
|
+
})
|
|
992
|
+
`);
|
|
993
|
+
}
|
|
994
|
+
if (pool.paused) {
|
|
995
|
+
return undefined;
|
|
996
|
+
}
|
|
997
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
998
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
999
|
+
account: userAddress,
|
|
1000
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Operator,
|
|
1001
|
+
abi: operator_abi_1.OPERATOR_ABI,
|
|
1002
|
+
functionName: 'pause',
|
|
1003
|
+
args: [pool.key],
|
|
1004
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1005
|
+
};
|
|
1006
|
+
exports.pausePool = pausePool;
|
|
1007
|
+
const resumePool = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
1008
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1009
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1010
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1011
|
+
});
|
|
1012
|
+
const pool = options?.pool
|
|
1013
|
+
? options.pool
|
|
1014
|
+
: (await (0, pool_1.fetchPool)(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
1015
|
+
if (!pool.isOpened) {
|
|
1016
|
+
throw new Error(`
|
|
1017
|
+
Open the pool before trying resume.
|
|
1018
|
+
import { openPool } from '@clober/v2-sdk'
|
|
1019
|
+
|
|
1020
|
+
const transaction = await openPool({
|
|
1021
|
+
chainId: ${chainId},
|
|
1022
|
+
tokenA: '${token0}',
|
|
1023
|
+
tokenB: '${token1}',
|
|
1024
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1025
|
+
})
|
|
1026
|
+
`);
|
|
1027
|
+
}
|
|
1028
|
+
if (!pool.paused) {
|
|
1029
|
+
return undefined;
|
|
1030
|
+
}
|
|
1031
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1032
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1033
|
+
account: userAddress,
|
|
1034
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].Strategy,
|
|
1035
|
+
abi: strategy_abi_1.STRATEGY_ABI,
|
|
1036
|
+
functionName: 'unpause',
|
|
1037
|
+
args: [pool.key],
|
|
1038
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1039
|
+
};
|
|
1040
|
+
exports.resumePool = resumePool;
|
|
1041
|
+
const vote = async ({ chainId, userAddress, candidateAddress, inFavor, options, }) => {
|
|
1042
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1043
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1044
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1045
|
+
});
|
|
1046
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1047
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1048
|
+
account: userAddress,
|
|
1049
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
1050
|
+
abi: election_governor_abi_1.ELECTION_GOVERNOR_ABI,
|
|
1051
|
+
functionName: 'vote',
|
|
1052
|
+
args: [candidateAddress, inFavor],
|
|
1053
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1054
|
+
};
|
|
1055
|
+
exports.vote = vote;
|
|
1056
|
+
const register = async ({ chainId, userAddress, options, }) => {
|
|
1057
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1058
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1059
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1060
|
+
});
|
|
1061
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1062
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1063
|
+
account: userAddress,
|
|
1064
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
1065
|
+
abi: election_governor_abi_1.ELECTION_GOVERNOR_ABI,
|
|
1066
|
+
functionName: 'register',
|
|
1067
|
+
args: [],
|
|
1068
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1069
|
+
};
|
|
1070
|
+
exports.register = register;
|
|
1071
|
+
const end = async ({ chainId, userAddress, options, }) => {
|
|
1072
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1073
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1074
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1075
|
+
});
|
|
1076
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1077
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1078
|
+
account: userAddress,
|
|
1079
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
1080
|
+
abi: election_governor_abi_1.ELECTION_GOVERNOR_ABI,
|
|
1081
|
+
functionName: 'end',
|
|
1082
|
+
args: [],
|
|
1083
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1084
|
+
};
|
|
1085
|
+
exports.end = end;
|
|
1086
|
+
const mintVCLOB = async ({ chainId, userAddress, amount, options, }) => {
|
|
1087
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1088
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1089
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1090
|
+
});
|
|
1091
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1092
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1093
|
+
account: userAddress,
|
|
1094
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
|
|
1095
|
+
abi: vclob_abi_1.VCLOB_ABI,
|
|
1096
|
+
functionName: 'mint',
|
|
1097
|
+
args: [amount, userAddress],
|
|
1098
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1099
|
+
};
|
|
1100
|
+
exports.mintVCLOB = mintVCLOB;
|
|
1101
|
+
const burnVCLOB = async ({ chainId, userAddress, id, options, }) => {
|
|
1102
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
1103
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1104
|
+
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
1105
|
+
});
|
|
1106
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
1107
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
1108
|
+
account: userAddress,
|
|
1109
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
|
|
1110
|
+
abi: vclob_abi_1.VCLOB_ABI,
|
|
1111
|
+
functionName: 'burn',
|
|
1112
|
+
args: [Number(id), userAddress],
|
|
1113
|
+
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1114
|
+
};
|
|
1115
|
+
exports.burnVCLOB = burnVCLOB;
|
|
364
1116
|
//# sourceMappingURL=call.js.map
|