@clober/v2-sdk 0.0.8 → 0.0.9-6.dev-2
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 +20 -11
- package/dist/cjs/apis/chart-logs.js.map +1 -1
- package/dist/cjs/apis/market.js +44 -21
- 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 +59 -35
- package/dist/cjs/apis/open-order.js.map +1 -1
- package/dist/cjs/apis/pool.js +97 -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 +943 -156
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/addresses.js +92 -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 +25 -2
- package/dist/cjs/constants/chain.js.map +1 -1
- package/dist/cjs/constants/currency.js +82 -3
- package/dist/cjs/constants/currency.js.map +1 -1
- package/dist/cjs/constants/fee.js +21 -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/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 +37 -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 +72 -36
- package/dist/cjs/model/book.js.map +1 -1
- package/dist/cjs/model/fee-policy.js +10 -0
- package/dist/cjs/model/fee-policy.js.map +1 -1
- package/dist/cjs/model/market.js +65 -27
- 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 -8
- 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 +55 -24
- 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 +67 -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 +503 -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 +18 -9
- package/dist/esm/apis/chart-logs.js.map +1 -1
- package/dist/esm/apis/market.js +45 -22
- 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 +60 -35
- package/dist/esm/apis/open-order.js.map +1 -1
- package/dist/esm/apis/pool.js +92 -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 +982 -210
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/constants/addresses.js +93 -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 +24 -2
- package/dist/esm/constants/chain.js.map +1 -1
- package/dist/esm/constants/currency.js +85 -2
- package/dist/esm/constants/currency.js.map +1 -1
- package/dist/esm/constants/fee.js +21 -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/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 +33 -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 +72 -36
- package/dist/esm/model/book.js.map +1 -1
- package/dist/esm/model/fee-policy.js +10 -0
- package/dist/esm/model/fee-policy.js.map +1 -1
- package/dist/esm/model/market.js +67 -29
- 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 -8
- 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 +53 -22
- 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 +66 -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 +576 -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 +3 -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 +5 -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 +299 -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 +9 -2
- package/dist/types/constants/chain.d.ts.map +1 -1
- package/dist/types/constants/currency.d.ts +8 -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/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 +30 -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/fee-policy.d.ts +1 -0
- package/dist/types/model/fee-policy.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 +143 -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 +5 -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 +283 -31
- 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/esm/view.js
CHANGED
|
@@ -1,18 +1,60 @@
|
|
|
1
|
-
import { formatUnits, isAddressEqual, parseUnits } from 'viem';
|
|
1
|
+
import { createPublicClient, formatUnits, getAddress, http, isAddressEqual, parseUnits, } from 'viem';
|
|
2
2
|
import { fetchMarket } from './apis/market';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { fetchOpenOrder,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { CHAIN_MAP } from './constants/chain';
|
|
4
|
+
import { formatPrice, parsePrice } from './utils/prices';
|
|
5
|
+
import { fetchOpenOrder, fetchOpenOrdersByUserAddress } from './apis/open-order';
|
|
6
|
+
import { CHART_LOG_INTERVAL_TIMESTAMP, fetchChartLogs, fetchLatestChartLog, } from './apis/chart-logs';
|
|
7
|
+
import { getMarketId } from './utils/market';
|
|
8
|
+
import { CONTRACT_ADDRESSES } from './constants/addresses';
|
|
9
|
+
import { invertTick, toPrice } from './utils/tick';
|
|
10
|
+
import { MAX_TICK, MIN_TICK } from './constants/tick';
|
|
11
|
+
import { fetchPool, fetchPoolPerformance } from './apis/pool';
|
|
12
|
+
import { fetchLastRawAmounts, fetchStrategyPosition } from './apis/strategy';
|
|
13
|
+
import { Subgraph } from './constants/subgraph';
|
|
14
|
+
import { fillAndSortByTimestamp } from './utils/time-series';
|
|
15
|
+
import { fetchVCLOBList } from './apis/vclob';
|
|
16
|
+
import { ELECTION_GOVERNOR_ABI } from './abis/governance/election-governor-abi';
|
|
17
|
+
import { VCLOB_ABI } from './abis/governance/vclob-abi';
|
|
18
|
+
import { KEEPERS_REGISTRY_ABI } from './abis/governance/keepers-registry-abi';
|
|
19
|
+
import { MAKER_DEFAULT_POLICY, TAKER_DEFAULT_POLICY } from './constants/fee';
|
|
20
|
+
/**
|
|
21
|
+
* Get contract addresses by chain id
|
|
22
|
+
* @param chainId - chain id from {@link CHAIN_IDS}
|
|
23
|
+
* @returns Contract addresses
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import { getContractAddresses } from '@clober/v2-sdk'
|
|
27
|
+
*
|
|
28
|
+
* const addresses = await getContractAddresses({
|
|
29
|
+
* chainId: 421614,
|
|
30
|
+
* })
|
|
31
|
+
*/
|
|
32
|
+
export const getContractAddresses = ({ chainId }) => {
|
|
33
|
+
return CONTRACT_ADDRESSES[chainId];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Get subgraph block number by chain id
|
|
37
|
+
* @param chainId - chain id from {@link CHAIN_IDS}
|
|
38
|
+
* @returns Contract addresses
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* import { getContractAddresses } from '@clober/v2-sdk'
|
|
42
|
+
*
|
|
43
|
+
* const blockNumber = await getSubgraphBlockNumber({
|
|
44
|
+
* chainId: 421614,
|
|
45
|
+
* })
|
|
46
|
+
*/
|
|
47
|
+
export const getSubgraphBlockNumber = async ({ chainId, }) => {
|
|
48
|
+
const { data: { latestBlock: { blockNumber }, }, } = await Subgraph.get(chainId, 'getLatestBlockNumber', 'query getLatestBlockNumber { latestBlock(id: "latest") { blockNumber } }', {});
|
|
49
|
+
return Number(blockNumber);
|
|
50
|
+
};
|
|
8
51
|
/**
|
|
9
52
|
* Get market information by chain id and token addresses
|
|
10
53
|
* @param chainId - chain id from {@link CHAIN_IDS}
|
|
11
54
|
* @param token0 - token0 address
|
|
12
55
|
* @param token1 - token1 address
|
|
13
|
-
* @param options
|
|
56
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
14
57
|
* @param options.n - number of depth levels to fetch
|
|
15
|
-
* @param options.rpcUrl - RPC URL of the blockchain
|
|
16
58
|
* @returns A market {@link Market}
|
|
17
59
|
*
|
|
18
60
|
* @example
|
|
@@ -24,23 +66,401 @@ import { fetchChartLogs, fetchLatestChartLog } from './apis/chart-logs';
|
|
|
24
66
|
* token1: '0x0000000000000000000000000000000000000000',
|
|
25
67
|
* })
|
|
26
68
|
*/
|
|
27
|
-
export const getMarket =
|
|
69
|
+
export const getMarket = async ({ chainId, token0, token1, options, }) => {
|
|
28
70
|
if (isAddressEqual(token0, token1)) {
|
|
29
71
|
throw new Error('Token0 and token1 must be different');
|
|
30
72
|
}
|
|
31
|
-
const
|
|
73
|
+
const publicClient = createPublicClient({
|
|
74
|
+
chain: CHAIN_MAP[chainId],
|
|
75
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
76
|
+
});
|
|
77
|
+
const [bidBookMakerFeePolicy, bidBookTakerFeePolicy, askBookMakerFeePolicy, askBookTakerFeePolicy,] = [
|
|
78
|
+
options && options.bidBookMakerFeePolicy
|
|
79
|
+
? options.bidBookMakerFeePolicy
|
|
80
|
+
: MAKER_DEFAULT_POLICY[chainId],
|
|
81
|
+
options && options.bidBookTakerFeePolicy
|
|
82
|
+
? options.bidBookTakerFeePolicy
|
|
83
|
+
: TAKER_DEFAULT_POLICY[chainId],
|
|
84
|
+
options && options.askBookMakerFeePolicy
|
|
85
|
+
? options.askBookMakerFeePolicy
|
|
86
|
+
: MAKER_DEFAULT_POLICY[chainId],
|
|
87
|
+
options && options.askBookTakerFeePolicy
|
|
88
|
+
? options.askBookTakerFeePolicy
|
|
89
|
+
: TAKER_DEFAULT_POLICY[chainId],
|
|
90
|
+
];
|
|
91
|
+
const market = await fetchMarket(publicClient, chainId, [token0, token1], bidBookMakerFeePolicy, bidBookTakerFeePolicy, askBookMakerFeePolicy, askBookTakerFeePolicy, !!(options && options.useSubgraph), options?.n);
|
|
92
|
+
return market.toJson();
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Get pool information by chain id and token addresses
|
|
96
|
+
* @param chainId - chain id from {@link CHAIN_IDS}
|
|
97
|
+
* @param token0 - token0 address
|
|
98
|
+
* @param token1 - token1 address
|
|
99
|
+
* @param salt - salt for the pool
|
|
100
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
101
|
+
* @param options.n - number of depth levels to fetch
|
|
102
|
+
* @returns A pool {@link Pool}
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* import { getPool } from '@clober/v2-sdk'
|
|
106
|
+
*
|
|
107
|
+
* const market = await getPool({
|
|
108
|
+
* chainId: 421614,
|
|
109
|
+
* token0: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
110
|
+
* token1: '0x0000000000000000000000000000000000000000',
|
|
111
|
+
* salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
112
|
+
* })
|
|
113
|
+
*/
|
|
114
|
+
export const getPool = async ({ chainId, token0, token1, salt, options, }) => {
|
|
115
|
+
if (isAddressEqual(token0, token1)) {
|
|
116
|
+
throw new Error('Token0 and token1 must be different');
|
|
117
|
+
}
|
|
118
|
+
const publicClient = createPublicClient({
|
|
119
|
+
chain: CHAIN_MAP[chainId],
|
|
120
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
121
|
+
});
|
|
122
|
+
const pool = await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
|
|
123
|
+
return pool.toJson();
|
|
124
|
+
};
|
|
125
|
+
export const getPoolPerformance = async ({ chainId, token0, token1, salt, volumeFromTimestamp, volumeToTimestamp, snapshotFromTimestamp, snapshotToTimestamp, snapshotIntervalType, spreadProfitFromTimestamp, spreadProfitToTimestamp, options, }) => {
|
|
126
|
+
if (isAddressEqual(token0, token1)) {
|
|
127
|
+
throw new Error('Token0 and token1 must be different');
|
|
128
|
+
}
|
|
129
|
+
if (!options?.useSubgraph) {
|
|
130
|
+
throw new Error('useSubgraph must be true');
|
|
131
|
+
}
|
|
132
|
+
let pool;
|
|
133
|
+
if (options?.pool) {
|
|
134
|
+
pool = options.pool;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const publicClient = createPublicClient({
|
|
138
|
+
chain: CHAIN_MAP[chainId],
|
|
139
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
140
|
+
});
|
|
141
|
+
pool = (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), undefined)).toJson();
|
|
142
|
+
}
|
|
143
|
+
const poolPerformance = await fetchPoolPerformance(chainId, pool.key, volumeFromTimestamp, snapshotFromTimestamp, snapshotIntervalType, spreadProfitFromTimestamp);
|
|
144
|
+
const poolVolumes = fillAndSortByTimestamp(poolPerformance.poolVolumes, 300, volumeFromTimestamp, volumeToTimestamp, (timestamp) => {
|
|
145
|
+
const emptyPoolVolume = {
|
|
146
|
+
id: '',
|
|
147
|
+
poolKey: pool.key,
|
|
148
|
+
intervalType: '5m',
|
|
149
|
+
timestamp: BigInt(timestamp),
|
|
150
|
+
currencyAVolume: 0n,
|
|
151
|
+
currencyBVolume: 0n,
|
|
152
|
+
bookACurrencyAVolume: 0n,
|
|
153
|
+
bookACurrencyBVolume: 0n,
|
|
154
|
+
bookBCurrencyAVolume: 0n,
|
|
155
|
+
bookBCurrencyBVolume: 0n,
|
|
156
|
+
};
|
|
157
|
+
return emptyPoolVolume;
|
|
158
|
+
});
|
|
159
|
+
const poolSnapshots = fillAndSortByTimestamp(poolPerformance.poolSnapshots, CHART_LOG_INTERVAL_TIMESTAMP[snapshotIntervalType], snapshotFromTimestamp, snapshotToTimestamp, (timestamp, prev) => {
|
|
160
|
+
const emptyPoolSnapshot = {
|
|
161
|
+
id: '',
|
|
162
|
+
poolKey: pool.key,
|
|
163
|
+
intervalType: snapshotIntervalType,
|
|
164
|
+
timestamp: BigInt(timestamp),
|
|
165
|
+
price: prev ? prev.price : 0n,
|
|
166
|
+
liquidityA: prev ? prev.liquidityA : 0n,
|
|
167
|
+
liquidityB: prev ? prev.liquidityB : 0n,
|
|
168
|
+
totalSupply: prev ? prev.totalSupply : 0n,
|
|
169
|
+
};
|
|
170
|
+
return emptyPoolSnapshot;
|
|
171
|
+
});
|
|
172
|
+
const poolSpreadProfits = fillAndSortByTimestamp(poolPerformance.poolSpreadProfits, 300, spreadProfitFromTimestamp, spreadProfitToTimestamp, (timestamp) => {
|
|
173
|
+
const emptyPoolSpreadProfit = {
|
|
174
|
+
id: '',
|
|
175
|
+
intervalType: '5m',
|
|
176
|
+
timestamp: BigInt(timestamp),
|
|
177
|
+
accumulatedProfitInUsd: '0',
|
|
178
|
+
};
|
|
179
|
+
return emptyPoolSpreadProfit;
|
|
180
|
+
});
|
|
32
181
|
return {
|
|
182
|
+
poolVolumes: poolVolumes.map((poolVolume) => ({
|
|
183
|
+
poolKey: poolVolume.poolKey,
|
|
184
|
+
intervalType: poolVolume.intervalType,
|
|
185
|
+
timestamp: Number(poolVolume.timestamp),
|
|
186
|
+
currencyAVolume: {
|
|
187
|
+
currency: pool.currencyA,
|
|
188
|
+
value: formatUnits(poolVolume.currencyAVolume, pool.currencyA.decimals),
|
|
189
|
+
},
|
|
190
|
+
currencyBVolume: {
|
|
191
|
+
currency: pool.currencyB,
|
|
192
|
+
value: formatUnits(poolVolume.currencyBVolume, pool.currencyB.decimals),
|
|
193
|
+
},
|
|
194
|
+
})),
|
|
195
|
+
poolSnapshots: poolSnapshots.map((poolSnapshot) => ({
|
|
196
|
+
poolKey: poolSnapshot.poolKey,
|
|
197
|
+
intervalType: poolSnapshot.intervalType,
|
|
198
|
+
timestamp: Number(poolSnapshot.timestamp),
|
|
199
|
+
price: formatUnits(poolSnapshot.price, 18),
|
|
200
|
+
liquidityA: {
|
|
201
|
+
currency: pool.currencyA,
|
|
202
|
+
value: formatUnits(poolSnapshot.liquidityA, pool.currencyA.decimals),
|
|
203
|
+
},
|
|
204
|
+
liquidityB: {
|
|
205
|
+
currency: pool.currencyB,
|
|
206
|
+
value: formatUnits(poolSnapshot.liquidityB, pool.currencyB.decimals),
|
|
207
|
+
},
|
|
208
|
+
totalSupply: {
|
|
209
|
+
currency: pool.currencyLp,
|
|
210
|
+
value: formatUnits(poolSnapshot.totalSupply, pool.currencyLp.decimals),
|
|
211
|
+
},
|
|
212
|
+
})),
|
|
213
|
+
poolSpreadProfits: poolSpreadProfits.map((poolSpreadProfit) => ({
|
|
214
|
+
intervalType: poolSpreadProfit.intervalType,
|
|
215
|
+
timestamp: Number(poolSpreadProfit.timestamp),
|
|
216
|
+
accumulatedProfitInUsd: poolSpreadProfit.accumulatedProfitInUsd,
|
|
217
|
+
})),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
export const getStrategyPrice = async ({ chainId, token0, token1, salt, options, }) => {
|
|
221
|
+
if (isAddressEqual(token0, token1)) {
|
|
222
|
+
throw new Error('Token0 and token1 must be different');
|
|
223
|
+
}
|
|
224
|
+
const publicClient = createPublicClient({
|
|
225
|
+
chain: CHAIN_MAP[chainId],
|
|
226
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
227
|
+
});
|
|
228
|
+
return fetchStrategyPosition(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
|
|
229
|
+
};
|
|
230
|
+
export const getLastRawAmounts = async ({ chainId, token0, token1, salt, options, }) => {
|
|
231
|
+
if (isAddressEqual(token0, token1)) {
|
|
232
|
+
throw new Error('Token0 and token1 must be different');
|
|
233
|
+
}
|
|
234
|
+
const publicClient = createPublicClient({
|
|
235
|
+
chain: CHAIN_MAP[chainId],
|
|
236
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
237
|
+
});
|
|
238
|
+
return fetchLastRawAmounts(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
|
|
239
|
+
};
|
|
240
|
+
export const getVCLOBList = async ({ chainId, userAddress, options, }) => {
|
|
241
|
+
const publicClient = createPublicClient({
|
|
242
|
+
chain: CHAIN_MAP[chainId],
|
|
243
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
244
|
+
});
|
|
245
|
+
return fetchVCLOBList(publicClient, chainId, userAddress, !!(options && options.useSubgraph));
|
|
246
|
+
};
|
|
247
|
+
export const getKeepersElectionGovernorMetadata = async ({ chainId, options, }) => {
|
|
248
|
+
const publicClient = createPublicClient({
|
|
249
|
+
chain: CHAIN_MAP[chainId],
|
|
250
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
251
|
+
});
|
|
252
|
+
const [minCandidateBalance, quota] = await publicClient.multicall({
|
|
253
|
+
contracts: [
|
|
254
|
+
{
|
|
255
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
256
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
257
|
+
functionName: 'minCandidateBalance',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
261
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
262
|
+
functionName: 'quota',
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
allowFailure: false,
|
|
266
|
+
});
|
|
267
|
+
return {
|
|
268
|
+
minCandidateBalance,
|
|
269
|
+
quota,
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
export const getKeepersElectionCurrentRoundData = async ({ chainId, userAddress, options, }) => {
|
|
273
|
+
const publicClient = createPublicClient({
|
|
274
|
+
chain: CHAIN_MAP[chainId],
|
|
275
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
276
|
+
});
|
|
277
|
+
const [currentRound, nextRoundStartTime, currentKeepers] = await publicClient.multicall({
|
|
278
|
+
contracts: [
|
|
279
|
+
{
|
|
280
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
281
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
282
|
+
functionName: 'currentRound',
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
286
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
287
|
+
functionName: 'nextRoundStartTime',
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
address: CONTRACT_ADDRESSES[chainId].KeepersRegistry,
|
|
291
|
+
abi: KEEPERS_REGISTRY_ABI,
|
|
292
|
+
functionName: 'getCurrentKeepers',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
allowFailure: false,
|
|
296
|
+
});
|
|
297
|
+
const [currentRoundData, candidates, finalists] = await publicClient.multicall({
|
|
298
|
+
contracts: [
|
|
299
|
+
{
|
|
300
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
301
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
302
|
+
functionName: 'getRoundData',
|
|
303
|
+
args: [currentRound],
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
307
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
308
|
+
functionName: 'getCandidates',
|
|
309
|
+
args: [currentRound],
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
313
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
314
|
+
functionName: 'getFinalists',
|
|
315
|
+
args: [currentRound],
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
allowFailure: false,
|
|
319
|
+
});
|
|
320
|
+
const [userVCLOBAmount, ...multicallResults] = await publicClient.multicall({
|
|
321
|
+
contracts: [
|
|
322
|
+
{
|
|
323
|
+
address: CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
|
|
324
|
+
abi: VCLOB_ABI,
|
|
325
|
+
functionName: 'getPastBalanceOf',
|
|
326
|
+
args: [userAddress, currentRoundData.startTime],
|
|
327
|
+
},
|
|
328
|
+
...candidates.map((candidate) => ({
|
|
329
|
+
address: CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
|
|
330
|
+
abi: VCLOB_ABI,
|
|
331
|
+
functionName: 'getPastBalanceOf',
|
|
332
|
+
args: [candidate, currentRoundData.startTime],
|
|
333
|
+
})),
|
|
334
|
+
...candidates.map((candidate) => ({
|
|
335
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
336
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
337
|
+
functionName: 'hasVotedTo',
|
|
338
|
+
args: [currentRound, userAddress, candidate],
|
|
339
|
+
})),
|
|
340
|
+
...candidates.map((candidate) => ({
|
|
341
|
+
address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
|
|
342
|
+
abi: ELECTION_GOVERNOR_ABI,
|
|
343
|
+
functionName: 'getVotes',
|
|
344
|
+
args: [currentRound, candidate],
|
|
345
|
+
})),
|
|
346
|
+
],
|
|
347
|
+
allowFailure: false,
|
|
348
|
+
});
|
|
349
|
+
const vclobAmountOfCandidateList = multicallResults.slice(0, candidates.length);
|
|
350
|
+
const hasVotedToCandidateList = multicallResults.slice(candidates.length, candidates.length * 2);
|
|
351
|
+
const votesForCandidateList = multicallResults.slice(candidates.length * 2);
|
|
352
|
+
const candidateDataMap = new Map();
|
|
353
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
354
|
+
candidateDataMap.set(candidates[i], {
|
|
355
|
+
address: candidates[i],
|
|
356
|
+
vclobAmount: vclobAmountOfCandidateList[i],
|
|
357
|
+
hasVotedTo: hasVotedToCandidateList[i],
|
|
358
|
+
forVotes: votesForCandidateList[i][0],
|
|
359
|
+
againstVotes: votesForCandidateList[i][1],
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
round: currentRound,
|
|
364
|
+
keepers: currentKeepers,
|
|
365
|
+
nextRoundStartTime: nextRoundStartTime,
|
|
366
|
+
vclobAmount: userVCLOBAmount,
|
|
367
|
+
status: currentRoundData.status,
|
|
368
|
+
quota: currentRoundData.quota,
|
|
369
|
+
finalistsThreshold: currentRoundData.finalistsThreshold,
|
|
370
|
+
startTime: BigInt(currentRoundData.startTime),
|
|
371
|
+
votingEndTime: BigInt(currentRoundData.votingEndTime),
|
|
372
|
+
registrationEndTime: BigInt(currentRoundData.registrationEndTime),
|
|
373
|
+
candidatesLength: currentRoundData.candidatesLength,
|
|
374
|
+
finalistsLength: currentRoundData.finalistsLength,
|
|
375
|
+
candidates: candidates.map((candidate) => candidateDataMap.get(candidate)),
|
|
376
|
+
finalists: finalists.map((finalist) => candidateDataMap.get(finalist)),
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Calculates and returns the neighboring price ticks and their corresponding prices for a given input price.
|
|
381
|
+
*
|
|
382
|
+
* @param {CHAIN_IDS} chainId - chain id from {@link CHAIN_IDS}
|
|
383
|
+
* @param {string} price - The input price to calculate the neighborhood for, as a string.
|
|
384
|
+
* @param {Currency} currency0 - token0 currency {@link Currency}.
|
|
385
|
+
* @param {Currency} currency1 - token1 currency {@link Currency}.
|
|
386
|
+
*
|
|
387
|
+
* @returns {Object} An object containing the normal and inverted price neighborhoods. Each neighborhood includes:
|
|
388
|
+
* - up: The tick and price for one tick above the current price.
|
|
389
|
+
* - now: The tick and price for the current price.
|
|
390
|
+
* - down: The tick and price for one tick below the current price.
|
|
391
|
+
*/
|
|
392
|
+
export const getPriceNeighborhood = ({ chainId, price, currency0, currency1, }) => {
|
|
393
|
+
const quoteTokenAddress = getQuoteToken({
|
|
33
394
|
chainId,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
395
|
+
token0: currency0.address,
|
|
396
|
+
token1: currency1.address,
|
|
397
|
+
});
|
|
398
|
+
const quoteCurrency = isAddressEqual(quoteTokenAddress, currency0.address)
|
|
399
|
+
? currency0
|
|
400
|
+
: currency1;
|
|
401
|
+
const baseCurrency = isAddressEqual(quoteTokenAddress, currency0.address)
|
|
402
|
+
? currency1
|
|
403
|
+
: currency0;
|
|
404
|
+
const { roundingDownTick, roundingUpTick } = parsePrice(Number(price), quoteCurrency.decimals, baseCurrency.decimals);
|
|
405
|
+
const bidBookTick = roundingDownTick;
|
|
406
|
+
const askBookTick = invertTick(roundingUpTick);
|
|
407
|
+
return {
|
|
408
|
+
normal: {
|
|
409
|
+
nextUp: {
|
|
410
|
+
tick: bidBookTick + 2n,
|
|
411
|
+
price: formatPrice(toPrice(bidBookTick + 2n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
412
|
+
marketPrice: formatPrice(toPrice(bidBookTick + 2n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
413
|
+
},
|
|
414
|
+
up: {
|
|
415
|
+
tick: bidBookTick + 1n,
|
|
416
|
+
price: formatPrice(toPrice(bidBookTick + 1n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
417
|
+
marketPrice: formatPrice(toPrice(bidBookTick + 1n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
418
|
+
},
|
|
419
|
+
now: {
|
|
420
|
+
tick: bidBookTick,
|
|
421
|
+
price: formatPrice(toPrice(bidBookTick), quoteCurrency.decimals, baseCurrency.decimals),
|
|
422
|
+
marketPrice: formatPrice(toPrice(bidBookTick), quoteCurrency.decimals, baseCurrency.decimals),
|
|
423
|
+
},
|
|
424
|
+
down: {
|
|
425
|
+
tick: bidBookTick - 1n,
|
|
426
|
+
price: formatPrice(toPrice(bidBookTick - 1n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
427
|
+
marketPrice: formatPrice(toPrice(bidBookTick - 1n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
428
|
+
},
|
|
429
|
+
nextDown: {
|
|
430
|
+
tick: bidBookTick - 2n,
|
|
431
|
+
price: formatPrice(toPrice(bidBookTick - 2n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
432
|
+
marketPrice: formatPrice(toPrice(bidBookTick - 2n), quoteCurrency.decimals, baseCurrency.decimals),
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
inverted: {
|
|
436
|
+
nextUp: {
|
|
437
|
+
tick: askBookTick + 2n,
|
|
438
|
+
price: formatPrice(toPrice(askBookTick + 2n), baseCurrency.decimals, quoteCurrency.decimals),
|
|
439
|
+
marketPrice: formatPrice(toPrice(invertTick(askBookTick + 2n)), quoteCurrency.decimals, baseCurrency.decimals),
|
|
440
|
+
},
|
|
441
|
+
up: {
|
|
442
|
+
tick: askBookTick + 1n,
|
|
443
|
+
price: formatPrice(toPrice(askBookTick + 1n), baseCurrency.decimals, quoteCurrency.decimals),
|
|
444
|
+
marketPrice: formatPrice(toPrice(invertTick(askBookTick + 1n)), quoteCurrency.decimals, baseCurrency.decimals),
|
|
445
|
+
},
|
|
446
|
+
now: {
|
|
447
|
+
tick: askBookTick,
|
|
448
|
+
price: formatPrice(toPrice(askBookTick), baseCurrency.decimals, quoteCurrency.decimals),
|
|
449
|
+
marketPrice: formatPrice(toPrice(invertTick(askBookTick)), quoteCurrency.decimals, baseCurrency.decimals),
|
|
450
|
+
},
|
|
451
|
+
down: {
|
|
452
|
+
tick: askBookTick - 1n,
|
|
453
|
+
price: formatPrice(toPrice(askBookTick - 1n), baseCurrency.decimals, quoteCurrency.decimals),
|
|
454
|
+
marketPrice: formatPrice(toPrice(invertTick(askBookTick - 1n)), quoteCurrency.decimals, baseCurrency.decimals),
|
|
455
|
+
},
|
|
456
|
+
nextDown: {
|
|
457
|
+
tick: askBookTick - 2n,
|
|
458
|
+
price: formatPrice(toPrice(askBookTick - 2n), baseCurrency.decimals, quoteCurrency.decimals),
|
|
459
|
+
marketPrice: formatPrice(toPrice(invertTick(askBookTick - 2n)), quoteCurrency.decimals, baseCurrency.decimals),
|
|
460
|
+
},
|
|
461
|
+
},
|
|
42
462
|
};
|
|
43
|
-
}
|
|
463
|
+
};
|
|
44
464
|
/**
|
|
45
465
|
* Calculates the expected output for a given input amount, based on the provided market data.
|
|
46
466
|
*
|
|
@@ -48,40 +468,75 @@ export const getMarket = decorator(async ({ chainId, token0, token1, options, })
|
|
|
48
468
|
* @param inputToken The address of the input token.
|
|
49
469
|
* @param outputToken The address of the output token.
|
|
50
470
|
* @param amountIn The amount of expected input amount. (ex 1.2 ETH -> 1.2)
|
|
51
|
-
* @param options
|
|
52
|
-
* @param options.limitPrice The maximum limit price to
|
|
53
|
-
* @param options.
|
|
471
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
472
|
+
* @param options.limitPrice The maximum limit price to take.
|
|
473
|
+
* @param options.roundingDownTakenBid Whether to round down the taken bid.
|
|
474
|
+
* @param options.roundingUpTakenAsk Whether to round up the taken ask.
|
|
54
475
|
* @returns A Promise resolving to an object containing the taken amount, spend amount and result of the calculation.
|
|
55
476
|
* @example
|
|
56
477
|
* import { getExpectedOutput } from '@clober/v2-sdk'
|
|
57
478
|
*
|
|
58
|
-
* const { takenAmount,
|
|
479
|
+
* const { takenAmount, spentAmount } = await getExpectedOutput({
|
|
59
480
|
* chainId: 421614,
|
|
60
481
|
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
61
482
|
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
62
483
|
* amountIn: '1000.123', // spend 1000.123 USDC
|
|
63
484
|
* })
|
|
64
485
|
*/
|
|
65
|
-
export const getExpectedOutput =
|
|
66
|
-
const
|
|
486
|
+
export const getExpectedOutput = async ({ chainId, inputToken, outputToken, amountIn, options, }) => {
|
|
487
|
+
const [roundingDownTakenBid, roundingUpTakenAsk] = [
|
|
488
|
+
options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
|
|
489
|
+
options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
|
|
490
|
+
];
|
|
491
|
+
const publicClient = createPublicClient({
|
|
492
|
+
chain: CHAIN_MAP[chainId],
|
|
493
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
494
|
+
});
|
|
495
|
+
const [makerFeePolicy, takerFeePolicy] = [
|
|
496
|
+
options && options.makerFeePolicy
|
|
497
|
+
? options.makerFeePolicy
|
|
498
|
+
: MAKER_DEFAULT_POLICY[chainId],
|
|
499
|
+
options && options.takerFeePolicy
|
|
500
|
+
? options.takerFeePolicy
|
|
501
|
+
: TAKER_DEFAULT_POLICY[chainId],
|
|
502
|
+
];
|
|
503
|
+
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], makerFeePolicy, takerFeePolicy, makerFeePolicy, takerFeePolicy, !!(options && options.useSubgraph));
|
|
67
504
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
68
|
-
const
|
|
505
|
+
const { roundingDownTick, roundingUpTick } = options && options.limitPrice
|
|
69
506
|
? parsePrice(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
|
|
70
507
|
: isBid
|
|
71
|
-
?
|
|
72
|
-
|
|
508
|
+
? {
|
|
509
|
+
roundingDownTick: MAX_TICK,
|
|
510
|
+
roundingUpTick: MAX_TICK,
|
|
511
|
+
}
|
|
512
|
+
: {
|
|
513
|
+
roundingDownTick: MIN_TICK,
|
|
514
|
+
roundingUpTick: MIN_TICK,
|
|
515
|
+
};
|
|
73
516
|
const inputCurrency = isBid ? market.quote : market.base;
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
517
|
+
const isTakingBidSide = !isBid;
|
|
518
|
+
const { takenQuoteAmount, spentBaseAmount, bookId, events } = market.spend({
|
|
519
|
+
spentBase: isTakingBidSide,
|
|
520
|
+
limitTick: isTakingBidSide
|
|
521
|
+
? roundingDownTakenBid
|
|
522
|
+
? roundingDownTick
|
|
523
|
+
: roundingUpTick
|
|
524
|
+
: roundingUpTakenAsk
|
|
525
|
+
? roundingUpTick
|
|
526
|
+
: roundingDownTick,
|
|
77
527
|
amountIn: parseUnits(amountIn, inputCurrency.decimals),
|
|
78
528
|
});
|
|
79
529
|
return {
|
|
80
530
|
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
81
|
-
|
|
531
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
82
532
|
bookId,
|
|
533
|
+
events: events.map(({ tick, takenQuoteAmount, spentBaseAmount }) => ({
|
|
534
|
+
price: formatPrice(toPrice(isBid ? invertTick(BigInt(tick)) : BigInt(tick)), market.quote.decimals, market.base.decimals),
|
|
535
|
+
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
536
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
537
|
+
})),
|
|
83
538
|
};
|
|
84
|
-
}
|
|
539
|
+
};
|
|
85
540
|
/**
|
|
86
541
|
* Calculates the expected input for a given output amount, based on the provided market data.
|
|
87
542
|
*
|
|
@@ -89,47 +544,76 @@ export const getExpectedOutput = decorator(async ({ chainId, inputToken, outputT
|
|
|
89
544
|
* @param inputToken The address of the input token.
|
|
90
545
|
* @param outputToken The address of the output token.
|
|
91
546
|
* @param amountOut The amount of expected output amount. (ex 1.2 ETH -> 1.2)
|
|
92
|
-
* @param options
|
|
547
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
93
548
|
* @param options.limitPrice The maximum limit price to take.
|
|
94
|
-
* @param options.
|
|
95
|
-
* @
|
|
549
|
+
* @param options.roundingDownTakenBid Whether to round down the taken bid.
|
|
550
|
+
* @param options.roundingUpTakenAsk Whether to round up the taken ask.
|
|
551
|
+
* @param options.useSubgraph Whether to use the subgraph to fetch the market data.
|
|
552
|
+
* @returns A Promise resolving to an object containing the taken amount, spent amount and result of the calculation.
|
|
96
553
|
* @example
|
|
97
554
|
* import { getExpectedInput } from '@clober/v2-sdk'
|
|
98
555
|
*
|
|
99
|
-
* const { takenAmount,
|
|
556
|
+
* const { takenAmount, spentAmount } = await getExpectedInput({
|
|
100
557
|
* chainId: 421614,
|
|
101
558
|
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
102
559
|
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
103
560
|
* amountOut: '0.1', // take 0.1 ETH
|
|
104
561
|
* })
|
|
105
562
|
*/
|
|
106
|
-
export const getExpectedInput =
|
|
107
|
-
const
|
|
563
|
+
export const getExpectedInput = async ({ chainId, inputToken, outputToken, amountOut, options, }) => {
|
|
564
|
+
const [roundingDownTakenBid, roundingUpTakenAsk] = [
|
|
565
|
+
options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
|
|
566
|
+
options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
|
|
567
|
+
];
|
|
568
|
+
const publicClient = createPublicClient({
|
|
569
|
+
chain: CHAIN_MAP[chainId],
|
|
570
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
571
|
+
});
|
|
572
|
+
const [makerFeePolicy, takerFeePolicy] = [
|
|
573
|
+
options && options.makerFeePolicy
|
|
574
|
+
? options.makerFeePolicy
|
|
575
|
+
: MAKER_DEFAULT_POLICY[chainId],
|
|
576
|
+
options && options.takerFeePolicy
|
|
577
|
+
? options.takerFeePolicy
|
|
578
|
+
: TAKER_DEFAULT_POLICY[chainId],
|
|
579
|
+
];
|
|
580
|
+
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], makerFeePolicy, takerFeePolicy, makerFeePolicy, takerFeePolicy, !!(options && options.useSubgraph));
|
|
108
581
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
109
|
-
const
|
|
582
|
+
const { roundingDownTick, roundingUpTick } = options && options.limitPrice
|
|
110
583
|
? parsePrice(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
|
|
111
584
|
: isBid
|
|
112
|
-
?
|
|
113
|
-
:
|
|
585
|
+
? { roundingDownTick: MAX_TICK, roundingUpTick: MAX_TICK }
|
|
586
|
+
: { roundingDownTick: MIN_TICK, roundingUpTick: MIN_TICK };
|
|
114
587
|
const outputCurrency = isBid ? market.base : market.quote;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
588
|
+
const isTakingBidSide = !isBid;
|
|
589
|
+
const { takenQuoteAmount, spentBaseAmount, bookId, events } = market.take({
|
|
590
|
+
takeQuote: isTakingBidSide,
|
|
591
|
+
limitTick: isTakingBidSide
|
|
592
|
+
? roundingDownTakenBid
|
|
593
|
+
? roundingDownTick
|
|
594
|
+
: roundingUpTick
|
|
595
|
+
: roundingUpTakenAsk
|
|
596
|
+
? roundingUpTick
|
|
597
|
+
: roundingDownTick,
|
|
118
598
|
amountOut: parseUnits(amountOut, outputCurrency.decimals),
|
|
119
599
|
});
|
|
120
600
|
return {
|
|
121
601
|
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
122
|
-
|
|
602
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
123
603
|
bookId,
|
|
604
|
+
events: events.map(({ tick, takenQuoteAmount, spentBaseAmount }) => ({
|
|
605
|
+
price: formatPrice(toPrice(isBid ? invertTick(BigInt(tick)) : BigInt(tick)), market.quote.decimals, market.base.decimals),
|
|
606
|
+
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
607
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
608
|
+
})),
|
|
124
609
|
};
|
|
125
|
-
}
|
|
610
|
+
};
|
|
126
611
|
/**
|
|
127
612
|
* Retrieves the open order with the specified ID on the given chain.
|
|
128
613
|
*
|
|
129
614
|
* @param {CHAIN_IDS} chainId The chain ID.
|
|
130
615
|
* @param {string} id The ID of the open order.
|
|
131
|
-
* @param options
|
|
132
|
-
* @param options.rpcUrl The RPC URL of the blockchain.
|
|
616
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
133
617
|
* @returns {Promise<OpenOrder>} Promise resolving to the open order object, or undefined if not found.
|
|
134
618
|
* @example
|
|
135
619
|
* import { getOpenOrder } from '@clober/v2-sdk'
|
|
@@ -139,16 +623,21 @@ export const getExpectedInput = decorator(async ({ chainId, inputToken, outputTo
|
|
|
139
623
|
* id: '46223845323662364279893361453861711542636620039907198451770258805035840307200'
|
|
140
624
|
* })
|
|
141
625
|
*/
|
|
142
|
-
export const getOpenOrder =
|
|
143
|
-
|
|
144
|
-
|
|
626
|
+
export const getOpenOrder = async ({ chainId, id, options, }) => {
|
|
627
|
+
const publicClient = createPublicClient({
|
|
628
|
+
chain: CHAIN_MAP[chainId],
|
|
629
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
630
|
+
});
|
|
631
|
+
return fetchOpenOrder(publicClient, chainId, id, options && options.makerFeePolicy
|
|
632
|
+
? options.makerFeePolicy
|
|
633
|
+
: MAKER_DEFAULT_POLICY[chainId]);
|
|
634
|
+
};
|
|
145
635
|
/**
|
|
146
636
|
* Retrieves open orders for the specified user on the given chain.
|
|
147
637
|
*
|
|
148
638
|
* @param {CHAIN_IDS} chainId The chain ID.
|
|
149
639
|
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
150
|
-
* @param options
|
|
151
|
-
* @param options.rpcUrl The RPC URL of the blockchain.
|
|
640
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
152
641
|
* @returns {Promise<OpenOrder[]>} Promise resolving to an array of open orders.
|
|
153
642
|
* @example
|
|
154
643
|
* import { getOpenOrders } from '@clober/v2-sdk'
|
|
@@ -158,9 +647,15 @@ export const getOpenOrder = decorator(async ({ chainId, id, }) => {
|
|
|
158
647
|
* userAddress: '0x5F79EE8f8fA862E98201120d83c4eC39D9468D49'
|
|
159
648
|
* })
|
|
160
649
|
*/
|
|
161
|
-
export const getOpenOrders =
|
|
162
|
-
|
|
163
|
-
|
|
650
|
+
export const getOpenOrders = async ({ chainId, userAddress, options, }) => {
|
|
651
|
+
const publicClient = createPublicClient({
|
|
652
|
+
chain: CHAIN_MAP[chainId],
|
|
653
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
654
|
+
});
|
|
655
|
+
return fetchOpenOrdersByUserAddress(publicClient, chainId, userAddress, options && options.makerFeePolicy
|
|
656
|
+
? options.makerFeePolicy
|
|
657
|
+
: MAKER_DEFAULT_POLICY[chainId]);
|
|
658
|
+
};
|
|
164
659
|
/**
|
|
165
660
|
* Retrieves the latest chart log for a specific market.
|
|
166
661
|
*
|
|
@@ -178,9 +673,9 @@ export const getOpenOrders = decorator(async ({ chainId, userAddress, }) => {
|
|
|
178
673
|
* base: '0x0000000000000000000000000000000000000000',
|
|
179
674
|
* })
|
|
180
675
|
*/
|
|
181
|
-
export const getLatestChartLog =
|
|
676
|
+
export const getLatestChartLog = async ({ chainId, quote, base, }) => {
|
|
182
677
|
return fetchLatestChartLog(chainId, `${base}/${quote}`);
|
|
183
|
-
}
|
|
678
|
+
};
|
|
184
679
|
/**
|
|
185
680
|
* Retrieves chart logs for a specific market within a specified time interval.
|
|
186
681
|
*
|
|
@@ -204,7 +699,27 @@ export const getLatestChartLog = decorator(async ({ chainId, quote, base, }) =>
|
|
|
204
699
|
* to: 1713312000,
|
|
205
700
|
* })
|
|
206
701
|
*/
|
|
207
|
-
export const getChartLogs =
|
|
702
|
+
export const getChartLogs = async ({ chainId, quote, base, intervalType, from, to, }) => {
|
|
208
703
|
return fetchChartLogs(chainId, `${base}/${quote}`, intervalType, from, to);
|
|
209
|
-
}
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* Retrieves the quote token address for a given chain and a pair of tokens.
|
|
707
|
+
*
|
|
708
|
+
* @param chainId - chain id from {@link CHAIN_IDS}
|
|
709
|
+
* @param token0 - token0 address
|
|
710
|
+
* @param token1 - token1 address
|
|
711
|
+
* @returns {string} The address of the quote token.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* import { getQuoteToken } from '@clober/v2-sdk'
|
|
715
|
+
*
|
|
716
|
+
* const quote = await getQuoteToken({
|
|
717
|
+
* chainId: 421614,
|
|
718
|
+
* token0: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
719
|
+
* token1: '0x0000000000000000000000000000000000000000',
|
|
720
|
+
* })
|
|
721
|
+
*/
|
|
722
|
+
export const getQuoteToken = ({ chainId, token0, token1, }) => {
|
|
723
|
+
return getAddress(getMarketId(chainId, [token0, token1]).quoteTokenAddress);
|
|
724
|
+
};
|
|
210
725
|
//# sourceMappingURL=view.js.map
|