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