@clober/v2-sdk 0.0.128 → 1.0.0-rc.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/dist/cjs/calls/approval/open-order.js +49 -0
- package/dist/cjs/calls/approval/open-order.js.map +1 -0
- package/dist/cjs/calls/approval/token.js +60 -0
- package/dist/cjs/calls/approval/token.js.map +1 -0
- package/dist/cjs/calls/index.js +36 -0
- package/dist/cjs/calls/index.js.map +1 -0
- package/dist/cjs/calls/market/cancel.js +80 -0
- package/dist/cjs/calls/market/cancel.js.map +1 -0
- package/dist/cjs/calls/market/claim.js +79 -0
- package/dist/cjs/calls/market/claim.js.map +1 -0
- package/dist/cjs/calls/market/limit.js +177 -0
- package/dist/cjs/calls/market/limit.js.map +1 -0
- package/dist/cjs/calls/market/market.js +170 -0
- package/dist/cjs/calls/market/market.js.map +1 -0
- package/dist/cjs/calls/market/open.js +50 -0
- package/dist/cjs/calls/market/open.js.map +1 -0
- package/dist/cjs/calls/pool/burn.js +88 -0
- package/dist/cjs/calls/pool/burn.js.map +1 -0
- package/dist/cjs/calls/pool/market-making/adjust.js +69 -0
- package/dist/cjs/calls/pool/market-making/adjust.js.map +1 -0
- package/dist/cjs/calls/pool/market-making/pause.js +44 -0
- package/dist/cjs/calls/pool/market-making/pause.js.map +1 -0
- package/dist/cjs/calls/pool/market-making/refill.js +41 -0
- package/dist/cjs/calls/pool/market-making/refill.js.map +1 -0
- package/dist/cjs/calls/pool/market-making/resume.js +44 -0
- package/dist/cjs/calls/pool/market-making/resume.js.map +1 -0
- package/dist/cjs/calls/pool/market-making/strategy.js +78 -0
- package/dist/cjs/calls/pool/market-making/strategy.js.map +1 -0
- package/dist/cjs/calls/pool/mint.js +163 -0
- package/dist/cjs/calls/pool/mint.js.map +1 -0
- package/dist/cjs/calls/pool/open.js +50 -0
- package/dist/cjs/calls/pool/open.js.map +1 -0
- package/dist/cjs/constants/abis/core/book-manager-abi.js.map +1 -0
- package/dist/cjs/constants/abis/core/book-viewer-abi.js.map +1 -0
- package/dist/cjs/constants/abis/core/controller-abi.js.map +1 -0
- package/dist/cjs/constants/abis/rebalancer/minter-abi.js.map +1 -0
- package/dist/cjs/constants/abis/rebalancer/mock-swap-abi.js.map +1 -0
- package/dist/cjs/constants/abis/rebalancer/operator-abi.js.map +1 -0
- package/dist/cjs/constants/abis/rebalancer/rebalancer-abi.js.map +1 -0
- package/dist/cjs/constants/abis/rebalancer/strategy-abi.js.map +1 -0
- package/dist/cjs/constants/{addresses.js → chain-configs/addresses.js} +0 -27
- package/dist/cjs/constants/chain-configs/addresses.js.map +1 -0
- package/dist/cjs/constants/{chain.js → chain-configs/chain.js} +3 -15
- package/dist/cjs/constants/chain-configs/chain.js.map +1 -0
- package/dist/cjs/constants/chain-configs/currency.js +52 -0
- package/dist/cjs/constants/chain-configs/currency.js.map +1 -0
- package/dist/cjs/constants/chain-configs/fee.js +20 -0
- package/dist/cjs/constants/chain-configs/fee.js.map +1 -0
- package/dist/cjs/constants/{subgraph.js → chain-configs/subgraph.js} +6 -9
- package/dist/cjs/constants/chain-configs/subgraph.js.map +1 -0
- package/dist/cjs/constants/networks/rise-sepolia.js.map +1 -0
- package/dist/cjs/constants/networks/test-chain.js.map +1 -0
- package/dist/cjs/constants/permit.js +2 -2
- package/dist/cjs/constants/permit.js.map +1 -1
- package/dist/cjs/constants/price.js.map +1 -1
- package/dist/cjs/entities/analytics/apis/index.js +102 -0
- package/dist/cjs/entities/analytics/apis/index.js.map +1 -0
- package/dist/cjs/{model/depth.js → entities/analytics/types.js} +1 -1
- package/dist/cjs/entities/analytics/types.js.map +1 -0
- package/dist/cjs/entities/book/apis/index.js +56 -0
- package/dist/cjs/entities/book/apis/index.js.map +1 -0
- package/dist/cjs/{utils → entities/book/apis}/open.js +1 -1
- package/dist/cjs/entities/book/apis/open.js.map +1 -0
- package/dist/cjs/{model/book.js → entities/book/model.js} +11 -11
- package/dist/cjs/entities/book/model.js.map +1 -0
- package/dist/cjs/{model/currency.js → entities/book/types.js} +1 -1
- package/dist/cjs/entities/book/types.js.map +1 -0
- package/dist/cjs/{utils → entities/book/utils}/book-id.js +1 -1
- package/dist/cjs/entities/book/utils/book-id.js.map +1 -0
- package/dist/cjs/entities/currency/apis/allowance.js +38 -0
- package/dist/cjs/entities/currency/apis/allowance.js.map +1 -0
- package/dist/cjs/entities/currency/apis/approval.js +39 -0
- package/dist/cjs/entities/currency/apis/approval.js.map +1 -0
- package/dist/cjs/entities/currency/apis/index.js +128 -0
- package/dist/cjs/entities/currency/apis/index.js.map +1 -0
- package/dist/cjs/entities/currency/apis/price.js +36 -0
- package/dist/cjs/entities/currency/apis/price.js.map +1 -0
- package/dist/cjs/entities/currency/apis/total-supply.js +70 -0
- package/dist/cjs/entities/currency/apis/total-supply.js.map +1 -0
- package/dist/cjs/{model/chart-log.js → entities/currency/types.js} +1 -1
- package/dist/cjs/entities/currency/types.js.map +1 -0
- package/dist/cjs/{model/fee-policy.js → entities/fee-policy/model.js} +2 -2
- package/dist/cjs/entities/fee-policy/model.js.map +1 -0
- package/dist/cjs/{apis/chart-logs.js → entities/market/apis/chart-log.js} +15 -15
- package/dist/cjs/entities/market/apis/chart-log.js.map +1 -0
- package/dist/cjs/entities/market/apis/index.js +33 -0
- package/dist/cjs/entities/market/apis/index.js.map +1 -0
- package/dist/cjs/entities/market/apis/snapshot.js +220 -0
- package/dist/cjs/entities/market/apis/snapshot.js.map +1 -0
- package/dist/cjs/{model/market.js → entities/market/model.js} +14 -16
- package/dist/cjs/entities/market/model.js.map +1 -0
- package/dist/cjs/{model/open-order.js → entities/market/types.js} +1 -1
- package/dist/cjs/entities/market/types.js.map +1 -0
- package/dist/cjs/{utils/market.js → entities/market/utils/market-id.js} +3 -5
- package/dist/cjs/entities/market/utils/market-id.js.map +1 -0
- package/dist/cjs/entities/open-order/apis/index.js +199 -0
- package/dist/cjs/entities/open-order/apis/index.js.map +1 -0
- package/dist/cjs/entities/open-order/types.js +3 -0
- package/dist/cjs/entities/open-order/types.js.map +1 -0
- package/dist/cjs/entities/open-order/utils/order-id.js +13 -0
- package/dist/cjs/entities/open-order/utils/order-id.js.map +1 -0
- package/dist/cjs/entities/pool/apis/index.js +76 -0
- package/dist/cjs/entities/pool/apis/index.js.map +1 -0
- package/dist/cjs/entities/pool/apis/snapshot.js +88 -0
- package/dist/cjs/entities/pool/apis/snapshot.js.map +1 -0
- package/dist/cjs/{apis → entities/pool/apis}/strategy.js +4 -22
- package/dist/cjs/entities/pool/apis/strategy.js.map +1 -0
- package/dist/cjs/{model/pool.js → entities/pool/model.js} +5 -5
- package/dist/cjs/entities/pool/model.js.map +1 -0
- package/dist/cjs/entities/pool/types.js +3 -0
- package/dist/cjs/entities/pool/types.js.map +1 -0
- package/dist/cjs/{utils/pool.js → entities/pool/utils/mint.js} +14 -2
- package/dist/cjs/entities/pool/utils/mint.js.map +1 -0
- package/dist/cjs/{utils → entities/pool/utils}/pool-key.js +3 -6
- package/dist/cjs/entities/pool/utils/pool-key.js.map +1 -0
- package/dist/cjs/index.js +3 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/default-options.js +3 -0
- package/dist/cjs/types/default-options.js.map +1 -0
- package/dist/cjs/{type.js → types/index.js} +2 -2
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/permit.js +3 -0
- package/dist/cjs/types/permit.js.map +1 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/utils/{decimals.js → conversion.js} +1 -1
- package/dist/cjs/utils/conversion.js.map +1 -0
- package/dist/cjs/{utils.js → utils/index.js} +8 -8
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/prices.js +1 -2
- package/dist/cjs/utils/prices.js.map +1 -1
- package/dist/cjs/utils/time.js +7 -2
- package/dist/cjs/utils/time.js.map +1 -1
- package/dist/cjs/utils/unit-size.js +2 -2
- package/dist/cjs/utils/unit-size.js.map +1 -1
- package/dist/cjs/views/address.js +14 -0
- package/dist/cjs/views/address.js.map +1 -0
- package/dist/cjs/views/analytics.js +13 -0
- package/dist/cjs/views/analytics.js.map +1 -0
- package/dist/cjs/views/currency.js +22 -0
- package/dist/cjs/views/currency.js.map +1 -0
- package/dist/cjs/views/index.js +38 -0
- package/dist/cjs/views/index.js.map +1 -0
- package/dist/cjs/views/market/chart-log.js +13 -0
- package/dist/cjs/views/market/chart-log.js.map +1 -0
- package/dist/cjs/views/market/index.js +30 -0
- package/dist/cjs/views/market/index.js.map +1 -0
- package/dist/cjs/views/market/quote.js +97 -0
- package/dist/cjs/views/market/quote.js.map +1 -0
- package/dist/cjs/views/market/snapshot.js +28 -0
- package/dist/cjs/views/market/snapshot.js.map +1 -0
- package/dist/cjs/views/market/token.js +10 -0
- package/dist/cjs/views/market/token.js.map +1 -0
- package/dist/cjs/views/open-order.js +13 -0
- package/dist/cjs/views/open-order.js.map +1 -0
- package/dist/cjs/views/pool/index.js +28 -0
- package/dist/cjs/views/pool/index.js.map +1 -0
- package/dist/cjs/views/pool/market-making.js +23 -0
- package/dist/cjs/views/pool/market-making.js.map +1 -0
- package/dist/cjs/views/pool/snapshot.js +17 -0
- package/dist/cjs/views/pool/snapshot.js.map +1 -0
- package/dist/cjs/views/subgraph.js +14 -0
- package/dist/cjs/views/subgraph.js.map +1 -0
- package/dist/cjs/views/tick.js +80 -0
- package/dist/cjs/views/tick.js.map +1 -0
- package/dist/esm/calls/approval/open-order.js +69 -0
- package/dist/esm/calls/approval/open-order.js.map +1 -0
- package/dist/esm/{approval.js → calls/approval/token.js} +5 -70
- package/dist/esm/calls/approval/token.js.map +1 -0
- package/dist/esm/calls/index.js +16 -0
- package/dist/esm/calls/index.js.map +1 -0
- package/dist/esm/calls/market/cancel.js +123 -0
- package/dist/esm/calls/market/cancel.js.map +1 -0
- package/dist/esm/calls/market/claim.js +122 -0
- package/dist/esm/calls/market/claim.js.map +1 -0
- package/dist/esm/calls/market/limit.js +219 -0
- package/dist/esm/calls/market/limit.js.map +1 -0
- package/dist/esm/calls/market/market.js +201 -0
- package/dist/esm/calls/market/market.js.map +1 -0
- package/dist/esm/calls/market/open.js +65 -0
- package/dist/esm/calls/market/open.js.map +1 -0
- package/dist/esm/calls/pool/burn.js +85 -0
- package/dist/esm/calls/pool/burn.js.map +1 -0
- package/dist/esm/calls/pool/market-making/adjust.js +65 -0
- package/dist/esm/calls/pool/market-making/adjust.js.map +1 -0
- package/dist/esm/calls/pool/market-making/pause.js +40 -0
- package/dist/esm/calls/pool/market-making/pause.js.map +1 -0
- package/dist/esm/calls/pool/market-making/refill.js +37 -0
- package/dist/esm/calls/pool/market-making/refill.js.map +1 -0
- package/dist/esm/calls/pool/market-making/resume.js +40 -0
- package/dist/esm/calls/pool/market-making/resume.js.map +1 -0
- package/dist/esm/calls/pool/market-making/strategy.js +75 -0
- package/dist/esm/calls/pool/market-making/strategy.js.map +1 -0
- package/dist/esm/calls/pool/mint.js +212 -0
- package/dist/esm/calls/pool/mint.js.map +1 -0
- package/dist/esm/calls/pool/open.js +66 -0
- package/dist/esm/calls/pool/open.js.map +1 -0
- package/dist/esm/constants/abis/core/book-manager-abi.js.map +1 -0
- package/dist/esm/constants/abis/core/book-viewer-abi.js.map +1 -0
- package/dist/esm/constants/abis/core/controller-abi.js.map +1 -0
- package/dist/esm/constants/abis/rebalancer/minter-abi.js.map +1 -0
- package/dist/esm/constants/abis/rebalancer/mock-swap-abi.js.map +1 -0
- package/dist/esm/constants/abis/rebalancer/operator-abi.js.map +1 -0
- package/dist/esm/constants/abis/rebalancer/rebalancer-abi.js.map +1 -0
- package/dist/esm/constants/abis/rebalancer/strategy-abi.js.map +1 -0
- package/dist/esm/constants/{addresses.js → chain-configs/addresses.js} +28 -28
- package/dist/esm/constants/chain-configs/addresses.js.map +1 -0
- package/dist/esm/constants/{chain.js → chain-configs/chain.js} +9 -14
- package/dist/esm/constants/chain-configs/chain.js.map +1 -0
- package/dist/esm/constants/chain-configs/currency.js +79 -0
- package/dist/esm/constants/chain-configs/currency.js.map +1 -0
- package/dist/esm/constants/{fee.js → chain-configs/fee.js} +7 -7
- package/dist/esm/constants/chain-configs/fee.js.map +1 -0
- package/dist/esm/constants/{subgraph.js → chain-configs/subgraph.js} +12 -9
- package/dist/esm/constants/chain-configs/subgraph.js.map +1 -0
- package/dist/esm/constants/networks/rise-sepolia.js.map +1 -0
- package/dist/esm/constants/networks/test-chain.js.map +1 -0
- package/dist/esm/constants/permit.js +1 -1
- package/dist/esm/constants/permit.js.map +1 -1
- package/dist/esm/constants/price.js.map +1 -1
- package/dist/esm/entities/analytics/apis/index.js +97 -0
- package/dist/esm/entities/analytics/apis/index.js.map +1 -0
- package/dist/esm/entities/analytics/types.js +2 -0
- package/dist/esm/entities/analytics/types.js.map +1 -0
- package/dist/esm/entities/book/apis/index.js +52 -0
- package/dist/esm/entities/book/apis/index.js.map +1 -0
- package/dist/esm/{utils → entities/book/apis}/open.js +1 -1
- package/dist/esm/entities/book/apis/open.js.map +1 -0
- package/dist/esm/{model/book.js → entities/book/model.js} +6 -6
- package/dist/esm/entities/book/model.js.map +1 -0
- package/dist/esm/entities/book/types.js +2 -0
- package/dist/esm/entities/book/types.js.map +1 -0
- package/dist/esm/{utils → entities/book/utils}/book-id.js +1 -1
- package/dist/esm/entities/book/utils/book-id.js.map +1 -0
- package/dist/esm/entities/currency/apis/allowance.js +34 -0
- package/dist/esm/entities/currency/apis/allowance.js.map +1 -0
- package/dist/esm/entities/currency/apis/approval.js +35 -0
- package/dist/esm/entities/currency/apis/approval.js.map +1 -0
- package/dist/esm/entities/currency/apis/index.js +123 -0
- package/dist/esm/entities/currency/apis/index.js.map +1 -0
- package/dist/esm/entities/currency/apis/price.js +30 -0
- package/dist/esm/entities/currency/apis/price.js.map +1 -0
- package/dist/esm/entities/currency/apis/total-supply.js +65 -0
- package/dist/esm/entities/currency/apis/total-supply.js.map +1 -0
- package/dist/esm/entities/currency/types.js +2 -0
- package/dist/esm/entities/currency/types.js.map +1 -0
- package/dist/esm/{model/fee-policy.js → entities/fee-policy/model.js} +2 -2
- package/dist/esm/entities/fee-policy/model.js.map +1 -0
- package/dist/esm/{apis/chart-logs.js → entities/market/apis/chart-log.js} +3 -3
- package/dist/esm/entities/market/apis/chart-log.js.map +1 -0
- package/dist/esm/entities/market/apis/index.js +29 -0
- package/dist/esm/entities/market/apis/index.js.map +1 -0
- package/dist/esm/entities/market/apis/snapshot.js +216 -0
- package/dist/esm/entities/market/apis/snapshot.js.map +1 -0
- package/dist/esm/{model/market.js → entities/market/model.js} +5 -7
- package/dist/esm/entities/market/model.js.map +1 -0
- package/dist/esm/entities/market/types.js +2 -0
- package/dist/esm/entities/market/types.js.map +1 -0
- package/dist/esm/{utils/market.js → entities/market/utils/market-id.js} +3 -5
- package/dist/esm/entities/market/utils/market-id.js.map +1 -0
- package/dist/esm/entities/open-order/apis/index.js +196 -0
- package/dist/esm/entities/open-order/apis/index.js.map +1 -0
- package/dist/esm/entities/open-order/types.js +2 -0
- package/dist/esm/entities/open-order/types.js.map +1 -0
- package/dist/esm/entities/open-order/utils/order-id.js +9 -0
- package/dist/esm/entities/open-order/utils/order-id.js.map +1 -0
- package/dist/esm/entities/pool/apis/index.js +72 -0
- package/dist/esm/entities/pool/apis/index.js.map +1 -0
- package/dist/esm/entities/pool/apis/snapshot.js +83 -0
- package/dist/esm/entities/pool/apis/snapshot.js.map +1 -0
- package/dist/esm/entities/pool/apis/strategy.js +30 -0
- package/dist/esm/entities/pool/apis/strategy.js.map +1 -0
- package/dist/esm/{model/pool.js → entities/pool/model.js} +3 -3
- package/dist/esm/entities/pool/model.js.map +1 -0
- package/dist/esm/entities/pool/types.js +2 -0
- package/dist/esm/entities/pool/types.js.map +1 -0
- package/dist/esm/{utils/pool.js → entities/pool/utils/mint.js} +11 -1
- package/dist/esm/entities/pool/utils/mint.js.map +1 -0
- package/dist/esm/{utils → entities/pool/utils}/pool-key.js +1 -3
- package/dist/esm/entities/pool/utils/pool-key.js.map +1 -0
- package/dist/esm/index.js +3 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/default-options.js +2 -0
- package/dist/esm/types/default-options.js.map +1 -0
- package/dist/esm/{type.js → types/index.js} +2 -2
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/permit.js +2 -0
- package/dist/esm/types/permit.js.map +1 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/utils/{decimals.js → conversion.js} +1 -1
- package/dist/esm/utils/conversion.js.map +1 -0
- package/dist/esm/utils/index.js +5 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/prices.js +1 -2
- package/dist/esm/utils/prices.js.map +1 -1
- package/dist/esm/utils/time.js +4 -1
- package/dist/esm/utils/time.js.map +1 -1
- package/dist/esm/utils/unit-size.js +2 -2
- package/dist/esm/utils/unit-size.js.map +1 -1
- package/dist/esm/views/address.js +33 -0
- package/dist/esm/views/address.js.map +1 -0
- package/dist/esm/views/analytics.js +8 -0
- package/dist/esm/views/analytics.js.map +1 -0
- package/dist/esm/views/currency.js +27 -0
- package/dist/esm/views/currency.js.map +1 -0
- package/dist/esm/views/index.js +9 -0
- package/dist/esm/views/index.js.map +1 -0
- package/dist/esm/views/market/chart-log.js +48 -0
- package/dist/esm/views/market/chart-log.js.map +1 -0
- package/dist/esm/views/market/index.js +37 -0
- package/dist/esm/views/market/index.js.map +1 -0
- package/dist/esm/views/market/quote.js +137 -0
- package/dist/esm/views/market/quote.js.map +1 -0
- package/dist/esm/views/market/snapshot.js +23 -0
- package/dist/esm/views/market/snapshot.js.map +1 -0
- package/dist/esm/views/market/token.js +23 -0
- package/dist/esm/views/market/token.js.map +1 -0
- package/dist/esm/views/open-order.js +38 -0
- package/dist/esm/views/open-order.js.map +1 -0
- package/dist/esm/views/pool/index.js +40 -0
- package/dist/esm/views/pool/index.js.map +1 -0
- package/dist/esm/views/pool/market-making.js +18 -0
- package/dist/esm/views/pool/market-making.js.map +1 -0
- package/dist/esm/views/pool/snapshot.js +12 -0
- package/dist/esm/views/pool/snapshot.js.map +1 -0
- package/dist/esm/views/subgraph.js +33 -0
- package/dist/esm/views/subgraph.js.map +1 -0
- package/dist/esm/views/tick.js +89 -0
- package/dist/esm/views/tick.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/calls/approval/open-order.d.ts +33 -0
- package/dist/types/calls/approval/open-order.d.ts.map +1 -0
- package/dist/types/{approval.d.ts → calls/approval/token.d.ts} +3 -32
- package/dist/types/calls/approval/token.d.ts.map +1 -0
- package/dist/types/calls/index.d.ts +16 -0
- package/dist/types/calls/index.d.ts.map +1 -0
- package/dist/types/calls/market/cancel.d.ts +73 -0
- package/dist/types/calls/market/cancel.d.ts.map +1 -0
- package/dist/types/calls/market/claim.d.ts +73 -0
- package/dist/types/calls/market/claim.d.ts.map +1 -0
- package/dist/types/calls/market/limit.d.ts +86 -0
- package/dist/types/calls/market/limit.d.ts.map +1 -0
- package/dist/types/calls/market/market.d.ts +67 -0
- package/dist/types/calls/market/market.d.ts.map +1 -0
- package/dist/types/calls/market/open.d.ts +31 -0
- package/dist/types/calls/market/open.d.ts.map +1 -0
- package/dist/types/calls/pool/burn.d.ts +22 -0
- package/dist/types/calls/pool/burn.d.ts.map +1 -0
- package/dist/types/calls/pool/market-making/adjust.d.ts +22 -0
- package/dist/types/calls/pool/market-making/adjust.d.ts.map +1 -0
- package/dist/types/calls/pool/market-making/pause.d.ts +14 -0
- package/dist/types/calls/pool/market-making/pause.d.ts.map +1 -0
- package/dist/types/calls/pool/market-making/refill.d.ts +14 -0
- package/dist/types/calls/pool/market-making/refill.d.ts.map +1 -0
- package/dist/types/calls/pool/market-making/resume.d.ts +14 -0
- package/dist/types/calls/pool/market-making/resume.d.ts.map +1 -0
- package/dist/types/calls/pool/market-making/strategy.d.ts +23 -0
- package/dist/types/calls/pool/market-making/strategy.d.ts.map +1 -0
- package/dist/types/calls/pool/mint.d.ts +29 -0
- package/dist/types/calls/pool/mint.d.ts.map +1 -0
- package/dist/types/calls/pool/open.d.ts +33 -0
- package/dist/types/calls/pool/open.d.ts.map +1 -0
- package/dist/types/constants/abis/core/book-manager-abi.d.ts.map +1 -0
- package/dist/types/{abis → constants/abis}/core/book-viewer-abi.d.ts.map +1 -1
- package/dist/types/{abis → constants/abis}/core/controller-abi.d.ts.map +1 -1
- package/dist/types/{abis → constants/abis}/rebalancer/minter-abi.d.ts.map +1 -1
- package/dist/types/constants/abis/rebalancer/mock-swap-abi.d.ts.map +1 -0
- package/dist/types/{abis → constants/abis}/rebalancer/operator-abi.d.ts.map +1 -1
- package/dist/types/{abis → constants/abis}/rebalancer/rebalancer-abi.d.ts.map +1 -1
- package/dist/types/{abis → constants/abis}/rebalancer/strategy-abi.d.ts.map +1 -1
- package/dist/types/constants/chain-configs/addresses.d.ts.map +1 -0
- package/dist/types/constants/{chain.d.ts → chain-configs/chain.d.ts} +0 -4
- package/dist/types/constants/chain-configs/chain.d.ts.map +1 -0
- package/dist/types/constants/chain-configs/currency.d.ts +17 -0
- package/dist/types/constants/chain-configs/currency.d.ts.map +1 -0
- package/dist/types/constants/{fee.d.ts → chain-configs/fee.d.ts} +1 -1
- package/dist/types/constants/chain-configs/fee.d.ts.map +1 -0
- package/dist/types/constants/chain-configs/subgraph.d.ts.map +1 -0
- package/dist/types/constants/networks/rise-sepolia.d.ts.map +1 -0
- package/dist/types/constants/networks/test-chain.d.ts.map +1 -0
- package/dist/types/constants/permit.d.ts +1 -1
- package/dist/types/constants/permit.d.ts.map +1 -1
- package/dist/types/constants/price.d.ts.map +1 -1
- package/dist/types/entities/analytics/apis/index.d.ts +5 -0
- package/dist/types/entities/analytics/apis/index.d.ts.map +1 -0
- package/dist/types/entities/analytics/types.d.ts +40 -0
- package/dist/types/entities/analytics/types.d.ts.map +1 -0
- package/dist/types/entities/book/apis/index.d.ts +6 -0
- package/dist/types/entities/book/apis/index.d.ts.map +1 -0
- package/dist/types/{utils → entities/book/apis}/open.d.ts +1 -1
- package/dist/types/entities/book/apis/open.d.ts.map +1 -0
- package/dist/types/{model/book.d.ts → entities/book/model.d.ts} +11 -7
- package/dist/types/entities/book/model.d.ts.map +1 -0
- package/dist/types/entities/book/types.d.ts +14 -0
- package/dist/types/entities/book/types.d.ts.map +1 -0
- package/dist/types/{utils → entities/book/utils}/book-id.d.ts +1 -1
- package/dist/types/entities/book/utils/book-id.d.ts.map +1 -0
- package/dist/types/entities/currency/apis/allowance.d.ts.map +1 -0
- package/dist/types/{utils → entities/currency/apis}/approval.d.ts +1 -1
- package/dist/types/entities/currency/apis/approval.d.ts.map +1 -0
- package/dist/types/entities/currency/apis/index.d.ts +6 -0
- package/dist/types/entities/currency/apis/index.d.ts.map +1 -0
- package/dist/types/entities/currency/apis/price.d.ts +10 -0
- package/dist/types/entities/currency/apis/price.d.ts.map +1 -0
- package/dist/types/entities/currency/apis/total-supply.d.ts +6 -0
- package/dist/types/entities/currency/apis/total-supply.d.ts.map +1 -0
- package/dist/types/entities/currency/types.d.ts +32 -0
- package/dist/types/entities/currency/types.d.ts.map +1 -0
- package/dist/types/{model/fee-policy.d.ts → entities/fee-policy/model.d.ts} +1 -1
- package/dist/types/entities/fee-policy/model.d.ts.map +1 -0
- package/dist/types/{apis/chart-logs.d.ts → entities/market/apis/chart-log.d.ts} +4 -3
- package/dist/types/entities/market/apis/chart-log.d.ts.map +1 -0
- package/dist/types/entities/market/apis/index.d.ts +5 -0
- package/dist/types/entities/market/apis/index.d.ts.map +1 -0
- package/dist/types/entities/market/apis/snapshot.d.ts +6 -0
- package/dist/types/entities/market/apis/snapshot.d.ts.map +1 -0
- package/dist/types/{model/market.d.ts → entities/market/model.d.ts} +16 -11
- package/dist/types/entities/market/model.d.ts.map +1 -0
- package/dist/types/entities/market/types.d.ts +36 -0
- package/dist/types/entities/market/types.d.ts.map +1 -0
- package/dist/types/{utils/market.d.ts → entities/market/utils/market-id.d.ts} +2 -2
- package/dist/types/entities/market/utils/market-id.d.ts.map +1 -0
- package/dist/types/{apis/open-order.d.ts → entities/open-order/apis/index.d.ts} +6 -3
- package/dist/types/entities/open-order/apis/index.d.ts.map +1 -0
- package/dist/types/entities/open-order/types.d.ts +22 -0
- package/dist/types/entities/open-order/types.d.ts.map +1 -0
- package/dist/types/entities/open-order/utils/order-id.d.ts +6 -0
- package/dist/types/entities/open-order/utils/order-id.d.ts.map +1 -0
- package/dist/types/entities/pool/apis/index.d.ts +6 -0
- package/dist/types/entities/pool/apis/index.d.ts.map +1 -0
- package/dist/types/entities/pool/apis/snapshot.d.ts +5 -0
- package/dist/types/entities/pool/apis/snapshot.d.ts.map +1 -0
- package/dist/types/entities/pool/apis/strategy.d.ts +6 -0
- package/dist/types/entities/pool/apis/strategy.d.ts.map +1 -0
- package/dist/types/{model/pool.d.ts → entities/pool/model.d.ts} +4 -32
- package/dist/types/entities/pool/model.d.ts.map +1 -0
- package/dist/types/entities/pool/types.d.ts +70 -0
- package/dist/types/entities/pool/types.d.ts.map +1 -0
- package/dist/types/{utils/pool.d.ts → entities/pool/utils/mint.d.ts} +4 -2
- package/dist/types/entities/pool/utils/mint.d.ts.map +1 -0
- package/dist/types/entities/pool/utils/pool-key.d.ts +2 -0
- package/dist/types/entities/pool/utils/pool-key.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/default-options.d.ts +10 -0
- package/dist/types/types/default-options.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +24 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/permit.d.ts +12 -0
- package/dist/types/types/permit.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +10 -0
- package/dist/types/types/transaction.d.ts.map +1 -0
- package/dist/types/utils/build-transaction.d.ts +1 -1
- package/dist/types/utils/build-transaction.d.ts.map +1 -1
- package/dist/types/utils/{decimals.d.ts → conversion.d.ts} +1 -1
- package/dist/types/utils/conversion.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/prices.d.ts +1 -1
- package/dist/types/utils/prices.d.ts.map +1 -1
- package/dist/types/utils/time.d.ts +2 -0
- package/dist/types/utils/time.d.ts.map +1 -1
- package/dist/types/utils/unit-size.d.ts +2 -2
- package/dist/types/utils/unit-size.d.ts.map +1 -1
- package/dist/types/views/address.d.ts +40 -0
- package/dist/types/views/address.d.ts.map +1 -0
- package/dist/types/views/analytics.d.ts +10 -0
- package/dist/types/views/analytics.d.ts.map +1 -0
- package/dist/types/views/currency.d.ts +32 -0
- package/dist/types/views/currency.d.ts.map +1 -0
- package/dist/types/views/index.d.ts +9 -0
- package/dist/types/views/index.d.ts.map +1 -0
- package/dist/types/views/market/chart-log.d.ts +56 -0
- package/dist/types/views/market/chart-log.d.ts.map +1 -0
- package/dist/types/views/market/index.d.ts +34 -0
- package/dist/types/views/market/index.d.ts.map +1 -0
- package/dist/types/views/market/quote.d.ts +90 -0
- package/dist/types/views/market/quote.d.ts.map +1 -0
- package/dist/types/views/market/snapshot.d.ts +17 -0
- package/dist/types/views/market/snapshot.d.ts.map +1 -0
- package/dist/types/views/market/token.d.ts +24 -0
- package/dist/types/views/market/token.d.ts.map +1 -0
- package/dist/types/views/open-order.d.ts +41 -0
- package/dist/types/views/open-order.d.ts.map +1 -0
- package/dist/types/views/pool/index.d.ts +36 -0
- package/dist/types/views/pool/index.d.ts.map +1 -0
- package/dist/types/views/pool/market-making.d.ts +13 -0
- package/dist/types/views/pool/market-making.d.ts.map +1 -0
- package/dist/types/views/pool/snapshot.d.ts +10 -0
- package/dist/types/views/pool/snapshot.d.ts.map +1 -0
- package/dist/types/views/subgraph.d.ts +32 -0
- package/dist/types/views/subgraph.d.ts.map +1 -0
- package/dist/types/views/tick.d.ts +77 -0
- package/dist/types/views/tick.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/cjs/abis/core/book-manager-abi.js.map +0 -1
- package/dist/cjs/abis/core/book-viewer-abi.js.map +0 -1
- package/dist/cjs/abis/core/controller-abi.js.map +0 -1
- package/dist/cjs/abis/rebalancer/minter-abi.js.map +0 -1
- package/dist/cjs/abis/rebalancer/mock-swap-abi.js.map +0 -1
- package/dist/cjs/abis/rebalancer/operator-abi.js.map +0 -1
- package/dist/cjs/abis/rebalancer/rebalancer-abi.js.map +0 -1
- package/dist/cjs/abis/rebalancer/strategy-abi.js.map +0 -1
- package/dist/cjs/apis/chart-logs.js.map +0 -1
- package/dist/cjs/apis/market.js +0 -89
- package/dist/cjs/apis/market.js.map +0 -1
- package/dist/cjs/apis/odos.js +0 -100
- package/dist/cjs/apis/odos.js.map +0 -1
- package/dist/cjs/apis/open-order.js +0 -131
- package/dist/cjs/apis/open-order.js.map +0 -1
- package/dist/cjs/apis/pool.js +0 -95
- package/dist/cjs/apis/pool.js.map +0 -1
- package/dist/cjs/apis/strategy.js.map +0 -1
- package/dist/cjs/approval.js +0 -102
- package/dist/cjs/approval.js.map +0 -1
- package/dist/cjs/call.js +0 -1057
- package/dist/cjs/call.js.map +0 -1
- package/dist/cjs/constants/action.js +0 -14
- package/dist/cjs/constants/action.js.map +0 -1
- package/dist/cjs/constants/addresses.js.map +0 -1
- package/dist/cjs/constants/chain.js.map +0 -1
- package/dist/cjs/constants/currency.js +0 -95
- package/dist/cjs/constants/currency.js.map +0 -1
- package/dist/cjs/constants/fee.js +0 -26
- package/dist/cjs/constants/fee.js.map +0 -1
- package/dist/cjs/constants/rise-sepolia.js.map +0 -1
- package/dist/cjs/constants/subgraph.js.map +0 -1
- package/dist/cjs/constants/test-chain.js.map +0 -1
- package/dist/cjs/model/book.js.map +0 -1
- package/dist/cjs/model/chart-log.js.map +0 -1
- package/dist/cjs/model/currency.js.map +0 -1
- package/dist/cjs/model/depth.js.map +0 -1
- package/dist/cjs/model/fee-policy.js.map +0 -1
- package/dist/cjs/model/market.js.map +0 -1
- package/dist/cjs/model/open-order.js.map +0 -1
- package/dist/cjs/model/pool.js.map +0 -1
- package/dist/cjs/type.js.map +0 -1
- package/dist/cjs/utils/allowance.js +0 -39
- package/dist/cjs/utils/allowance.js.map +0 -1
- package/dist/cjs/utils/approval.js +0 -40
- package/dist/cjs/utils/approval.js.map +0 -1
- package/dist/cjs/utils/book-id.js.map +0 -1
- package/dist/cjs/utils/currency.js +0 -165
- package/dist/cjs/utils/currency.js.map +0 -1
- package/dist/cjs/utils/decimals.js.map +0 -1
- package/dist/cjs/utils/market.js.map +0 -1
- package/dist/cjs/utils/open.js.map +0 -1
- package/dist/cjs/utils/order.js +0 -97
- package/dist/cjs/utils/order.js.map +0 -1
- package/dist/cjs/utils/pool-key.js.map +0 -1
- package/dist/cjs/utils/pool.js.map +0 -1
- package/dist/cjs/utils/quotes.js +0 -16
- package/dist/cjs/utils/quotes.js.map +0 -1
- package/dist/cjs/utils/time-series.js +0 -31
- package/dist/cjs/utils/time-series.js.map +0 -1
- package/dist/cjs/utils.js.map +0 -1
- package/dist/cjs/view.js +0 -349
- package/dist/cjs/view.js.map +0 -1
- package/dist/esm/abis/core/book-manager-abi.js.map +0 -1
- package/dist/esm/abis/core/book-viewer-abi.js.map +0 -1
- package/dist/esm/abis/core/controller-abi.js.map +0 -1
- package/dist/esm/abis/rebalancer/minter-abi.js.map +0 -1
- package/dist/esm/abis/rebalancer/mock-swap-abi.js.map +0 -1
- package/dist/esm/abis/rebalancer/operator-abi.js.map +0 -1
- package/dist/esm/abis/rebalancer/rebalancer-abi.js.map +0 -1
- package/dist/esm/abis/rebalancer/strategy-abi.js.map +0 -1
- package/dist/esm/apis/chart-logs.js.map +0 -1
- package/dist/esm/apis/market.js +0 -85
- package/dist/esm/apis/market.js.map +0 -1
- package/dist/esm/apis/odos.js +0 -94
- package/dist/esm/apis/odos.js.map +0 -1
- package/dist/esm/apis/open-order.js +0 -129
- package/dist/esm/apis/open-order.js.map +0 -1
- package/dist/esm/apis/pool.js +0 -90
- package/dist/esm/apis/pool.js.map +0 -1
- package/dist/esm/apis/strategy.js +0 -48
- package/dist/esm/apis/strategy.js.map +0 -1
- package/dist/esm/approval.js.map +0 -1
- package/dist/esm/call.js +0 -1257
- package/dist/esm/call.js.map +0 -1
- package/dist/esm/constants/action.js +0 -11
- package/dist/esm/constants/action.js.map +0 -1
- package/dist/esm/constants/addresses.js.map +0 -1
- package/dist/esm/constants/chain.js.map +0 -1
- package/dist/esm/constants/currency.js +0 -94
- package/dist/esm/constants/currency.js.map +0 -1
- package/dist/esm/constants/fee.js.map +0 -1
- package/dist/esm/constants/rise-sepolia.js.map +0 -1
- package/dist/esm/constants/subgraph.js.map +0 -1
- package/dist/esm/constants/test-chain.js.map +0 -1
- package/dist/esm/model/book.js.map +0 -1
- package/dist/esm/model/chart-log.js +0 -2
- package/dist/esm/model/chart-log.js.map +0 -1
- package/dist/esm/model/currency.js +0 -2
- package/dist/esm/model/currency.js.map +0 -1
- package/dist/esm/model/depth.js +0 -2
- package/dist/esm/model/depth.js.map +0 -1
- package/dist/esm/model/fee-policy.js.map +0 -1
- package/dist/esm/model/market.js.map +0 -1
- package/dist/esm/model/open-order.js +0 -2
- package/dist/esm/model/open-order.js.map +0 -1
- package/dist/esm/model/pool.js.map +0 -1
- package/dist/esm/type.js.map +0 -1
- package/dist/esm/utils/allowance.js +0 -35
- package/dist/esm/utils/allowance.js.map +0 -1
- package/dist/esm/utils/approval.js +0 -36
- package/dist/esm/utils/approval.js.map +0 -1
- package/dist/esm/utils/book-id.js.map +0 -1
- package/dist/esm/utils/currency.js +0 -160
- package/dist/esm/utils/currency.js.map +0 -1
- package/dist/esm/utils/decimals.js.map +0 -1
- package/dist/esm/utils/market.js.map +0 -1
- package/dist/esm/utils/open.js.map +0 -1
- package/dist/esm/utils/order.js +0 -92
- package/dist/esm/utils/order.js.map +0 -1
- package/dist/esm/utils/pool-key.js.map +0 -1
- package/dist/esm/utils/pool.js.map +0 -1
- package/dist/esm/utils/quotes.js +0 -12
- package/dist/esm/utils/quotes.js.map +0 -1
- package/dist/esm/utils/time-series.js +0 -27
- package/dist/esm/utils/time-series.js.map +0 -1
- package/dist/esm/utils.js +0 -5
- package/dist/esm/utils.js.map +0 -1
- package/dist/esm/view.js +0 -549
- package/dist/esm/view.js.map +0 -1
- package/dist/types/abis/core/book-manager-abi.d.ts.map +0 -1
- package/dist/types/abis/rebalancer/mock-swap-abi.d.ts.map +0 -1
- package/dist/types/apis/chart-logs.d.ts.map +0 -1
- package/dist/types/apis/market.d.ts +0 -5
- package/dist/types/apis/market.d.ts.map +0 -1
- package/dist/types/apis/odos.d.ts +0 -28
- package/dist/types/apis/odos.d.ts.map +0 -1
- package/dist/types/apis/open-order.d.ts.map +0 -1
- package/dist/types/apis/pool.d.ts +0 -11
- package/dist/types/apis/pool.d.ts.map +0 -1
- package/dist/types/apis/strategy.d.ts +0 -6
- package/dist/types/apis/strategy.d.ts.map +0 -1
- package/dist/types/approval.d.ts.map +0 -1
- package/dist/types/call.d.ts +0 -465
- package/dist/types/call.d.ts.map +0 -1
- package/dist/types/constants/action.d.ts +0 -10
- package/dist/types/constants/action.d.ts.map +0 -1
- package/dist/types/constants/addresses.d.ts.map +0 -1
- package/dist/types/constants/chain.d.ts.map +0 -1
- package/dist/types/constants/currency.d.ts +0 -16
- package/dist/types/constants/currency.d.ts.map +0 -1
- package/dist/types/constants/fee.d.ts.map +0 -1
- package/dist/types/constants/rise-sepolia.d.ts.map +0 -1
- package/dist/types/constants/subgraph.d.ts.map +0 -1
- package/dist/types/constants/test-chain.d.ts.map +0 -1
- package/dist/types/model/book.d.ts.map +0 -1
- package/dist/types/model/chart-log.d.ts +0 -9
- package/dist/types/model/chart-log.d.ts.map +0 -1
- package/dist/types/model/currency.d.ts +0 -14
- package/dist/types/model/currency.d.ts.map +0 -1
- package/dist/types/model/depth.d.ts +0 -10
- package/dist/types/model/depth.d.ts.map +0 -1
- package/dist/types/model/fee-policy.d.ts.map +0 -1
- package/dist/types/model/market.d.ts.map +0 -1
- package/dist/types/model/open-order.d.ts +0 -50
- package/dist/types/model/open-order.d.ts.map +0 -1
- package/dist/types/model/pool.d.ts.map +0 -1
- package/dist/types/type.d.ts +0 -159
- package/dist/types/type.d.ts.map +0 -1
- package/dist/types/utils/allowance.d.ts.map +0 -1
- package/dist/types/utils/approval.d.ts.map +0 -1
- package/dist/types/utils/book-id.d.ts.map +0 -1
- package/dist/types/utils/currency.d.ts +0 -8
- package/dist/types/utils/currency.d.ts.map +0 -1
- package/dist/types/utils/decimals.d.ts.map +0 -1
- package/dist/types/utils/market.d.ts.map +0 -1
- package/dist/types/utils/open.d.ts.map +0 -1
- package/dist/types/utils/order.d.ts +0 -10
- package/dist/types/utils/order.d.ts.map +0 -1
- package/dist/types/utils/pool-key.d.ts +0 -3
- package/dist/types/utils/pool-key.d.ts.map +0 -1
- package/dist/types/utils/pool.d.ts.map +0 -1
- package/dist/types/utils/quotes.d.ts +0 -2
- package/dist/types/utils/quotes.d.ts.map +0 -1
- package/dist/types/utils/time-series.d.ts +0 -4
- package/dist/types/utils/time-series.d.ts.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.d.ts.map +0 -1
- package/dist/types/view.d.ts +0 -423
- package/dist/types/view.d.ts.map +0 -1
- /package/dist/cjs/{abis → constants/abis}/core/book-manager-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/core/book-viewer-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/core/controller-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/rebalancer/minter-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/rebalancer/mock-swap-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/rebalancer/operator-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/rebalancer/rebalancer-abi.js +0 -0
- /package/dist/cjs/{abis → constants/abis}/rebalancer/strategy-abi.js +0 -0
- /package/dist/cjs/constants/{rise-sepolia.js → networks/rise-sepolia.js} +0 -0
- /package/dist/cjs/constants/{test-chain.js → networks/test-chain.js} +0 -0
- /package/dist/esm/{abis → constants/abis}/core/book-manager-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/core/book-viewer-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/core/controller-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/rebalancer/minter-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/rebalancer/mock-swap-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/rebalancer/operator-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/rebalancer/rebalancer-abi.js +0 -0
- /package/dist/esm/{abis → constants/abis}/rebalancer/strategy-abi.js +0 -0
- /package/dist/esm/constants/{rise-sepolia.js → networks/rise-sepolia.js} +0 -0
- /package/dist/esm/constants/{test-chain.js → networks/test-chain.js} +0 -0
- /package/dist/types/{abis → constants/abis}/core/book-manager-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/core/book-viewer-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/core/controller-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/rebalancer/minter-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/rebalancer/mock-swap-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/rebalancer/operator-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/rebalancer/rebalancer-abi.d.ts +0 -0
- /package/dist/types/{abis → constants/abis}/rebalancer/strategy-abi.d.ts +0 -0
- /package/dist/types/constants/{addresses.d.ts → chain-configs/addresses.d.ts} +0 -0
- /package/dist/types/constants/{subgraph.d.ts → chain-configs/subgraph.d.ts} +0 -0
- /package/dist/types/constants/{rise-sepolia.d.ts → networks/rise-sepolia.d.ts} +0 -0
- /package/dist/types/constants/{test-chain.d.ts → networks/test-chain.d.ts} +0 -0
- /package/dist/types/{utils → entities/currency/apis}/allowance.d.ts +0 -0
package/dist/esm/call.js
DELETED
|
@@ -1,1257 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, formatUnits, getAddress, http, isAddressEqual, parseUnits, zeroAddress, zeroHash, } from 'viem';
|
|
2
|
-
import { CHAIN_MAP } from './constants/chain';
|
|
3
|
-
import { calculateUnitSize } from './utils/unit-size';
|
|
4
|
-
import { CONTROLLER_ABI } from './abis/core/controller-abi';
|
|
5
|
-
import { getDeadlineTimestampInSeconds } from './utils/time';
|
|
6
|
-
import { buildTransaction } from './utils/build-transaction';
|
|
7
|
-
import { CONTRACT_ADDRESSES } from './constants/addresses';
|
|
8
|
-
import { MAKER_DEFAULT_POLICY, TAKER_DEFAULT_POLICY } from './constants/fee';
|
|
9
|
-
import { fetchMarket } from './apis/market';
|
|
10
|
-
import { convertHumanReadablePriceToRawPrice, formatPrice, parsePrice, } from './utils/prices';
|
|
11
|
-
import { invertTick, toPrice } from './utils/tick';
|
|
12
|
-
import { getExpectedInput, getExpectedOutput, getQuoteToken } from './view';
|
|
13
|
-
import { toBookId } from './utils/book-id';
|
|
14
|
-
import { fetchIsApprovedForAll } from './utils/approval';
|
|
15
|
-
import { fetchOnChainOrders } from './utils/order';
|
|
16
|
-
import { applyPercent } from './utils/bigint';
|
|
17
|
-
import { fetchPool } from './apis/pool';
|
|
18
|
-
import { REBALANCER_ABI } from './abis/rebalancer/rebalancer-abi';
|
|
19
|
-
import { getExpectedMintResult, getIdealDelta } from './utils/pool';
|
|
20
|
-
import { fetchCallData, fetchQuote } from './apis/odos';
|
|
21
|
-
import { MINTER_ABI } from './abis/rebalancer/minter-abi';
|
|
22
|
-
import { emptyERC20PermitParams } from './constants/permit';
|
|
23
|
-
import { abs } from './utils/math';
|
|
24
|
-
import { toBytes32 } from './utils/pool-key';
|
|
25
|
-
import { OPERATOR_ABI } from './abis/rebalancer/operator-abi';
|
|
26
|
-
import { STRATEGY_ABI } from './abis/rebalancer/strategy-abi';
|
|
27
|
-
import { fetchOpenOrdersByOrderIdsFromSubgraph } from './apis/open-order';
|
|
28
|
-
import { quotes } from './utils/quotes';
|
|
29
|
-
/**
|
|
30
|
-
* Build a transaction to open a market.
|
|
31
|
-
*
|
|
32
|
-
* @param chainId The chain ID of the blockchain.
|
|
33
|
-
* @param userAddress The address of the user.
|
|
34
|
-
* @param inputToken The address of the input token.
|
|
35
|
-
* @param outputToken The address of the output token.
|
|
36
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
37
|
-
* @returns A Promise resolving to a transaction object. If the market is already open, returns undefined.
|
|
38
|
-
* @example
|
|
39
|
-
* import { openMarket } from '@clober/v2-sdk'
|
|
40
|
-
*
|
|
41
|
-
* const transaction = await openMarket({
|
|
42
|
-
* chainId: 421614,
|
|
43
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
44
|
-
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
45
|
-
* outputToken: '0x0000000000000000000000000000000000000000'
|
|
46
|
-
* })
|
|
47
|
-
*/
|
|
48
|
-
export const openMarket = async ({ chainId, userAddress, inputToken, outputToken, options, }) => {
|
|
49
|
-
const publicClient = createPublicClient({
|
|
50
|
-
chain: CHAIN_MAP[chainId],
|
|
51
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
52
|
-
});
|
|
53
|
-
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
54
|
-
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
55
|
-
if ((isBid && !market.bidBook.isOpened) ||
|
|
56
|
-
(!isBid && !market.askBook.isOpened)) {
|
|
57
|
-
const unitSize = calculateUnitSize(chainId, isBid ? market.quote : market.base);
|
|
58
|
-
return buildTransaction(publicClient, {
|
|
59
|
-
chain: CHAIN_MAP[chainId],
|
|
60
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
61
|
-
account: userAddress,
|
|
62
|
-
abi: CONTROLLER_ABI,
|
|
63
|
-
functionName: 'open',
|
|
64
|
-
args: [
|
|
65
|
-
[
|
|
66
|
-
{
|
|
67
|
-
key: {
|
|
68
|
-
base: outputToken,
|
|
69
|
-
unitSize,
|
|
70
|
-
quote: inputToken,
|
|
71
|
-
makerPolicy: MAKER_DEFAULT_POLICY[chainId].value,
|
|
72
|
-
hooks: zeroAddress,
|
|
73
|
-
takerPolicy: TAKER_DEFAULT_POLICY[chainId].value,
|
|
74
|
-
},
|
|
75
|
-
hookData: zeroHash,
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
getDeadlineTimestampInSeconds(),
|
|
79
|
-
],
|
|
80
|
-
}, options?.gasLimit);
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Places a limit order on the specified chain for trading tokens.
|
|
86
|
-
*
|
|
87
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
88
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user placing the order.
|
|
89
|
-
* @param {`0x${string}`} inputToken The address of the token to be used as input.
|
|
90
|
-
* @param {`0x${string}`} outputToken The address of the token to be received as output.
|
|
91
|
-
* @param {string} amount The amount of input tokens for the order.
|
|
92
|
-
* @param {string} price The price at which the order should be executed.
|
|
93
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
94
|
-
* @param {erc20PermitParam} [options.erc20PermitParam] The permit signature for token approval.
|
|
95
|
-
* @param {boolean} [options.postOnly] A boolean indicating whether the order is only to be made not taken.
|
|
96
|
-
* @param {bigint} [options.makeTick] The tick for the make order.
|
|
97
|
-
* @param {bigint} [options.takeLimitTick] The tick for the take order.
|
|
98
|
-
* @param {boolean} [options.roundingUpMakeBid] A boolean indicating whether to round up the make bid.
|
|
99
|
-
* @param {boolean} [options.roundingDownMakeAsk] A boolean indicating whether to round down the make ask.
|
|
100
|
-
* @param {boolean} [options.roundingDownTakenBid] A boolean indicating whether to round down the taken bid.
|
|
101
|
-
* @param {boolean} [options.roundingUpTakenAsk] A boolean indicating whether to round up the taken ask.
|
|
102
|
-
* @returns {Promise<{ transaction: Transaction, result: { make: CurrencyFlow, take: CurrencyFlow, spent: CurrencyFlow }>}
|
|
103
|
-
* Promise resolving to the transaction object representing the limit order with the result of the order.
|
|
104
|
-
* @example
|
|
105
|
-
* import { limitOrder } from '@clober/v2-sdk'
|
|
106
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
107
|
-
*
|
|
108
|
-
* const { transaction } = await limitOrder({
|
|
109
|
-
* chainId: 421614,
|
|
110
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
|
|
111
|
-
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
112
|
-
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
113
|
-
* amount: '100.123', // 100.123 USDC
|
|
114
|
-
* price: '4000.01', // price at 4000.01 (ETH/USDC)
|
|
115
|
-
* })
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* import { limitOrder } from '@clober/v2-sdk'
|
|
119
|
-
*
|
|
120
|
-
* const { transaction } = await limitOrder({
|
|
121
|
-
* chainId: 421614,
|
|
122
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
|
|
123
|
-
* inputToken: '0x0000000000000000000000000000000000000000',
|
|
124
|
-
* outputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
125
|
-
* amount: '0.13', // 0.13 ETH
|
|
126
|
-
* price: '4000.01', // price at 4000.01 (ETH/USDC)
|
|
127
|
-
* })
|
|
128
|
-
*/
|
|
129
|
-
export const limitOrder = async ({ chainId, userAddress, inputToken, outputToken, amount, price, options, }) => {
|
|
130
|
-
const [roundingUpMakeBid, roundingDownMakeAsk, roundingDownTakenBid, roundingUpTakenAsk,] = [
|
|
131
|
-
options?.roundingUpMakeBid ? options.roundingUpMakeBid : false,
|
|
132
|
-
options?.roundingDownMakeAsk ? options.roundingDownMakeAsk : false,
|
|
133
|
-
options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
|
|
134
|
-
options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
|
|
135
|
-
];
|
|
136
|
-
const publicClient = createPublicClient({
|
|
137
|
-
chain: CHAIN_MAP[chainId],
|
|
138
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
139
|
-
});
|
|
140
|
-
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
141
|
-
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
142
|
-
const [inputCurrency, outputCurrency] = isBid
|
|
143
|
-
? [market.quote, market.base]
|
|
144
|
-
: [market.base, market.quote];
|
|
145
|
-
if ((isBid && !market.bidBook.isOpened) ||
|
|
146
|
-
(!isBid && !market.askBook.isOpened)) {
|
|
147
|
-
throw new Error(`
|
|
148
|
-
Open the market before placing a limit order.
|
|
149
|
-
import { openMarket } from '@clober/v2-sdk'
|
|
150
|
-
|
|
151
|
-
const transaction = await openMarket({
|
|
152
|
-
chainId: ${chainId},
|
|
153
|
-
inputToken: '${inputToken}',
|
|
154
|
-
outputToken: '${outputToken}',
|
|
155
|
-
})
|
|
156
|
-
`);
|
|
157
|
-
}
|
|
158
|
-
const { roundingDownTick, roundingUpTick } = parsePrice(Number(price), market.quote.decimals, market.base.decimals);
|
|
159
|
-
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
160
|
-
const quoteAmount = parseUnits(amount, inputCurrency.decimals);
|
|
161
|
-
const unitSize = calculateUnitSize(chainId, inputCurrency);
|
|
162
|
-
const { takenAmount, spentAmount, bookId, events } = await getExpectedOutput({
|
|
163
|
-
chainId,
|
|
164
|
-
inputToken,
|
|
165
|
-
outputToken,
|
|
166
|
-
amountIn: amount,
|
|
167
|
-
options: {
|
|
168
|
-
...options,
|
|
169
|
-
limitPrice: price,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
const isETH = isAddressEqual(inputToken, zeroAddress);
|
|
173
|
-
const makeParam = {
|
|
174
|
-
id: toBookId(chainId, inputToken, outputToken, unitSize),
|
|
175
|
-
tick: options?.makeTick
|
|
176
|
-
? Number(options.makeTick)
|
|
177
|
-
: Number(isBid
|
|
178
|
-
? roundingUpMakeBid
|
|
179
|
-
? roundingUpTick
|
|
180
|
-
: roundingDownTick
|
|
181
|
-
: invertTick(roundingDownMakeAsk ? roundingDownTick : roundingUpTick)),
|
|
182
|
-
quoteAmount,
|
|
183
|
-
hookData: zeroHash,
|
|
184
|
-
};
|
|
185
|
-
if (options?.postOnly === true || spentAmount === '0') {
|
|
186
|
-
return {
|
|
187
|
-
transaction: await buildTransaction(publicClient, {
|
|
188
|
-
chain: CHAIN_MAP[chainId],
|
|
189
|
-
account: userAddress,
|
|
190
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
191
|
-
abi: CONTROLLER_ABI,
|
|
192
|
-
functionName: 'make',
|
|
193
|
-
args: [
|
|
194
|
-
[makeParam],
|
|
195
|
-
tokensToSettle,
|
|
196
|
-
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
197
|
-
getDeadlineTimestampInSeconds(),
|
|
198
|
-
],
|
|
199
|
-
value: isETH ? quoteAmount : 0n,
|
|
200
|
-
}, options?.gasLimit),
|
|
201
|
-
result: {
|
|
202
|
-
make: {
|
|
203
|
-
amount: formatUnits(quoteAmount, inputCurrency.decimals),
|
|
204
|
-
currency: inputCurrency,
|
|
205
|
-
direction: 'in',
|
|
206
|
-
price: formatPrice(isBid
|
|
207
|
-
? toPrice(BigInt(makeParam.tick))
|
|
208
|
-
: toPrice(invertTick(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
209
|
-
},
|
|
210
|
-
spent: {
|
|
211
|
-
amount: '0',
|
|
212
|
-
currency: inputCurrency,
|
|
213
|
-
direction: 'in',
|
|
214
|
-
events: [],
|
|
215
|
-
},
|
|
216
|
-
taken: {
|
|
217
|
-
amount: '0',
|
|
218
|
-
currency: outputCurrency,
|
|
219
|
-
direction: 'out',
|
|
220
|
-
events: [],
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
// take and make
|
|
227
|
-
return {
|
|
228
|
-
transaction: await buildTransaction(publicClient, {
|
|
229
|
-
chain: CHAIN_MAP[chainId],
|
|
230
|
-
account: userAddress,
|
|
231
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
232
|
-
abi: CONTROLLER_ABI,
|
|
233
|
-
functionName: 'limit',
|
|
234
|
-
args: [
|
|
235
|
-
[
|
|
236
|
-
{
|
|
237
|
-
takeBookId: bookId,
|
|
238
|
-
makeBookId: makeParam.id,
|
|
239
|
-
limitPrice: options?.takeLimitTick
|
|
240
|
-
? toPrice(options.takeLimitTick)
|
|
241
|
-
: toPrice(isBid
|
|
242
|
-
? invertTick(roundingUpTakenAsk
|
|
243
|
-
? roundingUpTick
|
|
244
|
-
: roundingDownTick)
|
|
245
|
-
: roundingDownTakenBid
|
|
246
|
-
? roundingDownTick
|
|
247
|
-
: roundingUpTick),
|
|
248
|
-
tick: makeParam.tick,
|
|
249
|
-
quoteAmount,
|
|
250
|
-
takeHookData: zeroHash,
|
|
251
|
-
makeHookData: makeParam.hookData,
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
tokensToSettle,
|
|
255
|
-
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
256
|
-
getDeadlineTimestampInSeconds(),
|
|
257
|
-
],
|
|
258
|
-
value: isETH ? quoteAmount : 0n,
|
|
259
|
-
}, options?.gasLimit),
|
|
260
|
-
result: {
|
|
261
|
-
make: {
|
|
262
|
-
amount: formatUnits(quoteAmount - parseUnits(spentAmount, inputCurrency.decimals), inputCurrency.decimals),
|
|
263
|
-
currency: inputCurrency,
|
|
264
|
-
direction: 'in',
|
|
265
|
-
price: formatPrice(isBid
|
|
266
|
-
? toPrice(BigInt(makeParam.tick))
|
|
267
|
-
: toPrice(invertTick(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
268
|
-
},
|
|
269
|
-
spent: {
|
|
270
|
-
amount: spentAmount,
|
|
271
|
-
currency: inputCurrency,
|
|
272
|
-
direction: 'in',
|
|
273
|
-
events: events.map(({ price, spentAmount }) => ({
|
|
274
|
-
price,
|
|
275
|
-
amount: spentAmount,
|
|
276
|
-
})),
|
|
277
|
-
},
|
|
278
|
-
taken: {
|
|
279
|
-
amount: takenAmount,
|
|
280
|
-
currency: outputCurrency,
|
|
281
|
-
direction: 'out',
|
|
282
|
-
events: events.map(({ price, takenAmount }) => ({
|
|
283
|
-
price,
|
|
284
|
-
amount: takenAmount,
|
|
285
|
-
})),
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* Executes a market order on the specified chain for trading tokens.
|
|
293
|
-
* If only `amountIn` is provided, spend the specified amount of input tokens.
|
|
294
|
-
* If only `amountOut` is provided, take the specified amount of output tokens.
|
|
295
|
-
*
|
|
296
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
297
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user placing the order.
|
|
298
|
-
* @param {`0x${string}`} inputToken The address of the token to be used as input.
|
|
299
|
-
* @param {`0x${string}`} outputToken The address of the token to be received as output.
|
|
300
|
-
* @param {string} amountIn The amount of input tokens for the order to spend.
|
|
301
|
-
* @param {string} amountOut The amount of output tokens for the order to take.
|
|
302
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
303
|
-
* @param {erc20PermitParam} [options.erc20PermitParam] The permit signature for token approval.
|
|
304
|
-
* @param {number} [options.slippage] The maximum slippage percentage allowed for the order.
|
|
305
|
-
* @param {boolean} [options.roundingDownTakenBid] A boolean indicating whether to round down the taken bid.
|
|
306
|
-
* @param {boolean} [options.roundingUpTakenAsk] A boolean indicating whether to round up the taken ask.
|
|
307
|
-
* if the slippage is not provided, unlimited slippage is allowed.
|
|
308
|
-
* @returns {Promise<{ transaction: Transaction, result: { spent: CurrencyFlow, taken: CurrencyFlow } }>}
|
|
309
|
-
* Promise resolving to the transaction object representing the market order with the result of the order.
|
|
310
|
-
* @example
|
|
311
|
-
* import { marketOrder } from '@clober/v2-sdk'
|
|
312
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
313
|
-
*
|
|
314
|
-
* const transaction = await marketOrder({
|
|
315
|
-
* chainId: 421614,
|
|
316
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
|
|
317
|
-
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
318
|
-
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
319
|
-
* amount: '100.123', // 100.123 USDC
|
|
320
|
-
* options: { erc20PermitParam }
|
|
321
|
-
* })
|
|
322
|
-
*
|
|
323
|
-
*/
|
|
324
|
-
export const marketOrder = async ({ chainId, userAddress, inputToken, outputToken, amountIn, amountOut, options, }) => {
|
|
325
|
-
if (!amountIn && !amountOut) {
|
|
326
|
-
throw new Error('Either amountIn or amountOut must be provided');
|
|
327
|
-
}
|
|
328
|
-
else if (amountIn && amountOut) {
|
|
329
|
-
throw new Error('Only one of amountIn or amountOut can be provided');
|
|
330
|
-
}
|
|
331
|
-
const publicClient = createPublicClient({
|
|
332
|
-
chain: CHAIN_MAP[chainId],
|
|
333
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
334
|
-
});
|
|
335
|
-
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
336
|
-
const isTakingBid = isAddressEqual(market.base.address, inputToken);
|
|
337
|
-
const [inputCurrency, outputCurrency] = isTakingBid
|
|
338
|
-
? [market.base, market.quote]
|
|
339
|
-
: [market.quote, market.base];
|
|
340
|
-
if ((isTakingBid && !market.bidBook.isOpened) ||
|
|
341
|
-
(!isTakingBid && !market.askBook.isOpened)) {
|
|
342
|
-
throw new Error(`
|
|
343
|
-
Open the market before placing a market order.
|
|
344
|
-
import { openMarket } from '@clober/v2-sdk'
|
|
345
|
-
|
|
346
|
-
const transaction = await openMarket(
|
|
347
|
-
${chainId},
|
|
348
|
-
'${inputToken}',
|
|
349
|
-
'${outputToken}',
|
|
350
|
-
)
|
|
351
|
-
`);
|
|
352
|
-
}
|
|
353
|
-
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
354
|
-
const isETH = isAddressEqual(inputToken, zeroAddress);
|
|
355
|
-
if (amountIn && !amountOut) {
|
|
356
|
-
const { bookId, takenAmount, spentAmount, events } = await getExpectedOutput({
|
|
357
|
-
chainId,
|
|
358
|
-
inputToken,
|
|
359
|
-
outputToken,
|
|
360
|
-
amountIn,
|
|
361
|
-
options: {
|
|
362
|
-
...options,
|
|
363
|
-
// don't need to check limit price for market order
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
const baseAmount = parseUnits(amountIn, inputCurrency.decimals);
|
|
367
|
-
return {
|
|
368
|
-
transaction: await buildTransaction(publicClient, {
|
|
369
|
-
chain: CHAIN_MAP[chainId],
|
|
370
|
-
account: userAddress,
|
|
371
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
372
|
-
abi: CONTROLLER_ABI,
|
|
373
|
-
functionName: 'spend',
|
|
374
|
-
args: [
|
|
375
|
-
[
|
|
376
|
-
{
|
|
377
|
-
id: bookId,
|
|
378
|
-
limitPrice: 0n,
|
|
379
|
-
baseAmount,
|
|
380
|
-
minQuoteAmount: options?.slippage
|
|
381
|
-
? applyPercent(parseUnits(takenAmount, outputCurrency.decimals), 100 - options.slippage)
|
|
382
|
-
: 0n,
|
|
383
|
-
hookData: zeroHash,
|
|
384
|
-
},
|
|
385
|
-
],
|
|
386
|
-
tokensToSettle,
|
|
387
|
-
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
388
|
-
getDeadlineTimestampInSeconds(),
|
|
389
|
-
],
|
|
390
|
-
value: isETH ? baseAmount : 0n,
|
|
391
|
-
}, options?.gasLimit),
|
|
392
|
-
result: {
|
|
393
|
-
spent: {
|
|
394
|
-
amount: spentAmount,
|
|
395
|
-
currency: inputCurrency,
|
|
396
|
-
direction: 'in',
|
|
397
|
-
events: events.map(({ price, spentAmount }) => ({
|
|
398
|
-
price,
|
|
399
|
-
amount: spentAmount,
|
|
400
|
-
})),
|
|
401
|
-
},
|
|
402
|
-
taken: {
|
|
403
|
-
amount: takenAmount,
|
|
404
|
-
currency: outputCurrency,
|
|
405
|
-
direction: 'out',
|
|
406
|
-
events: events.map(({ price, takenAmount }) => ({
|
|
407
|
-
price,
|
|
408
|
-
amount: takenAmount,
|
|
409
|
-
})),
|
|
410
|
-
},
|
|
411
|
-
},
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
else if (!amountIn && amountOut) {
|
|
415
|
-
const { bookId, spentAmount, takenAmount, events } = await getExpectedInput({
|
|
416
|
-
chainId,
|
|
417
|
-
inputToken,
|
|
418
|
-
outputToken,
|
|
419
|
-
amountOut,
|
|
420
|
-
options: {
|
|
421
|
-
...options,
|
|
422
|
-
// don't need to check limit price for market order
|
|
423
|
-
},
|
|
424
|
-
});
|
|
425
|
-
const quoteAmount = parseUnits(amountOut, outputCurrency.decimals);
|
|
426
|
-
const baseAmount = parseUnits(spentAmount, inputCurrency.decimals);
|
|
427
|
-
const maxBaseAmount = options?.erc20PermitParam?.permitAmount ??
|
|
428
|
-
(options?.slippage
|
|
429
|
-
? applyPercent(baseAmount, 100 + options.slippage)
|
|
430
|
-
: isETH
|
|
431
|
-
? baseAmount
|
|
432
|
-
: 2n ** 256n - 1n);
|
|
433
|
-
return {
|
|
434
|
-
transaction: await buildTransaction(publicClient, {
|
|
435
|
-
chain: CHAIN_MAP[chainId],
|
|
436
|
-
account: userAddress,
|
|
437
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
438
|
-
abi: CONTROLLER_ABI,
|
|
439
|
-
functionName: 'take',
|
|
440
|
-
args: [
|
|
441
|
-
[
|
|
442
|
-
{
|
|
443
|
-
id: bookId,
|
|
444
|
-
limitPrice: 0n,
|
|
445
|
-
quoteAmount,
|
|
446
|
-
maxBaseAmount,
|
|
447
|
-
hookData: zeroHash,
|
|
448
|
-
},
|
|
449
|
-
],
|
|
450
|
-
tokensToSettle,
|
|
451
|
-
options?.erc20PermitParam ? [options.erc20PermitParam] : [],
|
|
452
|
-
getDeadlineTimestampInSeconds(),
|
|
453
|
-
],
|
|
454
|
-
value: isETH ? maxBaseAmount : 0n,
|
|
455
|
-
}, options?.gasLimit),
|
|
456
|
-
result: {
|
|
457
|
-
spent: {
|
|
458
|
-
amount: spentAmount,
|
|
459
|
-
currency: inputCurrency,
|
|
460
|
-
direction: 'in',
|
|
461
|
-
events: events.map(({ price, spentAmount }) => ({
|
|
462
|
-
price,
|
|
463
|
-
amount: spentAmount,
|
|
464
|
-
})),
|
|
465
|
-
},
|
|
466
|
-
taken: {
|
|
467
|
-
amount: takenAmount,
|
|
468
|
-
currency: outputCurrency,
|
|
469
|
-
direction: 'out',
|
|
470
|
-
events: events.map(({ price, takenAmount }) => ({
|
|
471
|
-
price,
|
|
472
|
-
amount: takenAmount,
|
|
473
|
-
})),
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
throw new Error('Either amountIn or amountOut must be provided');
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
/**
|
|
483
|
-
* Claims specified open order for settlement.
|
|
484
|
-
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
485
|
-
*
|
|
486
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
487
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
488
|
-
* @param {string} id An ID representing the open order to be claimed.
|
|
489
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
490
|
-
* @returns {Promise<{ transaction: Transaction, result: CurrencyFlow }>}
|
|
491
|
-
* Promise resolving to the transaction object representing the claim action with the result of the order.
|
|
492
|
-
* @throws {Error} Throws an error if no open orders are found for the specified user.
|
|
493
|
-
* @example
|
|
494
|
-
* import { getOpenOrders, claimOrders } from '@clober/v2-sdk'
|
|
495
|
-
*
|
|
496
|
-
* const openOrders = await getOpenOrders({
|
|
497
|
-
* chainId: 421614,
|
|
498
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'
|
|
499
|
-
* })
|
|
500
|
-
* const transaction = await claimOrders({
|
|
501
|
-
* chainId: 421614,
|
|
502
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
503
|
-
* id: openOrders.map((order) => order.id)
|
|
504
|
-
* })
|
|
505
|
-
*/
|
|
506
|
-
export const claimOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
507
|
-
const { transaction, result } = await claimOrders({
|
|
508
|
-
chainId,
|
|
509
|
-
userAddress,
|
|
510
|
-
ids: [id],
|
|
511
|
-
options: { ...options },
|
|
512
|
-
});
|
|
513
|
-
return {
|
|
514
|
-
transaction,
|
|
515
|
-
result: result[0],
|
|
516
|
-
};
|
|
517
|
-
};
|
|
518
|
-
/**
|
|
519
|
-
* Claims specified open orders for settlement.
|
|
520
|
-
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
521
|
-
*
|
|
522
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
523
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
524
|
-
* @param {string[]} ids An array of IDs representing the open orders to be claimed.
|
|
525
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
526
|
-
* @returns {Promise<{ transaction: Transaction, result: CurrencyFlow[] }>}
|
|
527
|
-
* Promise resolving to the transaction object representing the claim action with the result of the orders.
|
|
528
|
-
* @throws {Error} Throws an error if no open orders are found for the specified user.
|
|
529
|
-
* @example
|
|
530
|
-
* import { getOpenOrders, claimOrders } from '@clober/v2-sdk'
|
|
531
|
-
*
|
|
532
|
-
* const openOrders = await getOpenOrders({
|
|
533
|
-
* chainId: 421614,
|
|
534
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'
|
|
535
|
-
* })
|
|
536
|
-
* const transaction = await claimOrders(
|
|
537
|
-
* chainId: 421614,
|
|
538
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
539
|
-
* ids: openOrders.map((order) => order.id)
|
|
540
|
-
* )
|
|
541
|
-
*/
|
|
542
|
-
export const claimOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
543
|
-
const publicClient = createPublicClient({
|
|
544
|
-
chain: CHAIN_MAP[chainId],
|
|
545
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
546
|
-
});
|
|
547
|
-
const isApprovedForAll = await fetchIsApprovedForAll(publicClient, chainId, userAddress);
|
|
548
|
-
if (!isApprovedForAll) {
|
|
549
|
-
throw new Error(`
|
|
550
|
-
Set ApprovalForAll before calling this function.
|
|
551
|
-
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
552
|
-
|
|
553
|
-
const hash = await setApprovalOfOpenOrdersForAll({
|
|
554
|
-
chainId: ${chainId},
|
|
555
|
-
walletClient, // use viem
|
|
556
|
-
})
|
|
557
|
-
`);
|
|
558
|
-
}
|
|
559
|
-
const useSubgraph = !!(options && options.useSubgraph);
|
|
560
|
-
const orders = (useSubgraph
|
|
561
|
-
? await fetchOpenOrdersByOrderIdsFromSubgraph(chainId, ids)
|
|
562
|
-
: await fetchOnChainOrders(publicClient, chainId, ids.map((id) => BigInt(id)))).filter((order) => isAddressEqual(order.user, userAddress) && order.claimable.value !== '0');
|
|
563
|
-
const tokensToSettle = orders
|
|
564
|
-
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
565
|
-
.flat()
|
|
566
|
-
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
567
|
-
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
568
|
-
return {
|
|
569
|
-
transaction: await buildTransaction(publicClient, {
|
|
570
|
-
chain: CHAIN_MAP[chainId],
|
|
571
|
-
account: userAddress,
|
|
572
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
573
|
-
abi: CONTROLLER_ABI,
|
|
574
|
-
functionName: 'claim',
|
|
575
|
-
args: [
|
|
576
|
-
orders.map(({ id }) => ({
|
|
577
|
-
id,
|
|
578
|
-
hookData: zeroHash,
|
|
579
|
-
})),
|
|
580
|
-
tokensToSettle,
|
|
581
|
-
[],
|
|
582
|
-
getDeadlineTimestampInSeconds(),
|
|
583
|
-
],
|
|
584
|
-
}, options?.gasLimit),
|
|
585
|
-
result: orders.reduce((acc, { claimable: { currency, value } }) => {
|
|
586
|
-
const index = acc.findIndex((c) => isAddressEqual(c.currency.address, currency.address));
|
|
587
|
-
if (index === -1) {
|
|
588
|
-
return [...acc, { currency, amount: value, direction: 'out' }];
|
|
589
|
-
}
|
|
590
|
-
acc[index].amount = (Number(acc[index].amount) + Number(value)).toString();
|
|
591
|
-
return acc;
|
|
592
|
-
}, []),
|
|
593
|
-
};
|
|
594
|
-
};
|
|
595
|
-
/**
|
|
596
|
-
* Cancels specified open order if the order is not fully filled.
|
|
597
|
-
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
598
|
-
*
|
|
599
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
600
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
601
|
-
* @param {string} id An ID representing the open order to be canceled
|
|
602
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
603
|
-
* @returns {Promise<{ transaction: Transaction, result: CurrencyFlow }>}
|
|
604
|
-
* Promise resolving to the transaction object representing the cancel action with the result of the order.
|
|
605
|
-
* @throws {Error} Throws an error if no open orders are found for the specified user.
|
|
606
|
-
* @example
|
|
607
|
-
* import { getOpenOrders, cancelOrders } from '@clober/v2-sdk'
|
|
608
|
-
*
|
|
609
|
-
* const openOrders = await getOpenOrders({
|
|
610
|
-
* chainId: 421614,
|
|
611
|
-
* userAddress:'0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'
|
|
612
|
-
* })
|
|
613
|
-
* const transaction = await cancelOrders({
|
|
614
|
-
* chainId: 421614,
|
|
615
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
616
|
-
* id: openOrders.map((order) => order.id)
|
|
617
|
-
* })
|
|
618
|
-
*/
|
|
619
|
-
export const cancelOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
620
|
-
const { transaction, result } = await cancelOrders({
|
|
621
|
-
chainId,
|
|
622
|
-
userAddress,
|
|
623
|
-
ids: [id],
|
|
624
|
-
options: { ...options },
|
|
625
|
-
});
|
|
626
|
-
return {
|
|
627
|
-
transaction,
|
|
628
|
-
result: result[0],
|
|
629
|
-
};
|
|
630
|
-
};
|
|
631
|
-
/**
|
|
632
|
-
* Cancels specified open orders if orders are not fully filled.
|
|
633
|
-
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
634
|
-
*
|
|
635
|
-
* @param {CHAIN_IDS} chainId The chain ID.
|
|
636
|
-
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
637
|
-
* @param {string[]} ids An array of IDs representing the open orders to be canceled.
|
|
638
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
639
|
-
* @returns {Promise<{ transaction: Transaction, result: CurrencyFlow[] }>
|
|
640
|
-
* Promise resolving to the transaction object representing the cancel action with the result of the orders.
|
|
641
|
-
* @throws {Error} Throws an error if no open orders are found for the specified user.
|
|
642
|
-
* @example
|
|
643
|
-
* import { getOpenOrders, cancelOrders } from '@clober/v2-sdk'
|
|
644
|
-
*
|
|
645
|
-
* const openOrders = await getOpenOrders({
|
|
646
|
-
* chainId: 421614,
|
|
647
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'
|
|
648
|
-
* })
|
|
649
|
-
* const transaction = await cancelOrders({
|
|
650
|
-
* chainId: 421614,
|
|
651
|
-
* userAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
652
|
-
* ids: openOrders.map((order) => order.id)
|
|
653
|
-
* })
|
|
654
|
-
*/
|
|
655
|
-
export const cancelOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
656
|
-
const publicClient = createPublicClient({
|
|
657
|
-
chain: CHAIN_MAP[chainId],
|
|
658
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
659
|
-
});
|
|
660
|
-
const isApprovedForAll = await fetchIsApprovedForAll(publicClient, chainId, userAddress);
|
|
661
|
-
if (!isApprovedForAll) {
|
|
662
|
-
throw new Error(`
|
|
663
|
-
Set ApprovalForAll before calling this function.
|
|
664
|
-
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
665
|
-
|
|
666
|
-
const hash = await setApprovalOfOpenOrdersForAll({
|
|
667
|
-
chainId: ${chainId},
|
|
668
|
-
walletClient, // use viem
|
|
669
|
-
})
|
|
670
|
-
`);
|
|
671
|
-
}
|
|
672
|
-
const useSubgraph = !!(options && options.useSubgraph);
|
|
673
|
-
const orders = (useSubgraph
|
|
674
|
-
? await fetchOpenOrdersByOrderIdsFromSubgraph(chainId, ids)
|
|
675
|
-
: await fetchOnChainOrders(publicClient, chainId, ids.map((id) => BigInt(id)))).filter((order) => isAddressEqual(order.user, userAddress) && order.cancelable.value !== '0');
|
|
676
|
-
const tokensToSettle = orders
|
|
677
|
-
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
678
|
-
.flat()
|
|
679
|
-
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
680
|
-
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
681
|
-
return {
|
|
682
|
-
transaction: await buildTransaction(publicClient, {
|
|
683
|
-
chain: CHAIN_MAP[chainId],
|
|
684
|
-
account: userAddress,
|
|
685
|
-
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
686
|
-
abi: CONTROLLER_ABI,
|
|
687
|
-
functionName: 'cancel',
|
|
688
|
-
args: [
|
|
689
|
-
orders.map(({ id }) => ({
|
|
690
|
-
id,
|
|
691
|
-
leftQuoteAmount: 0n,
|
|
692
|
-
hookData: zeroHash,
|
|
693
|
-
})),
|
|
694
|
-
tokensToSettle,
|
|
695
|
-
[],
|
|
696
|
-
getDeadlineTimestampInSeconds(),
|
|
697
|
-
],
|
|
698
|
-
}, options?.gasLimit),
|
|
699
|
-
result: orders.reduce((acc, { cancelable: { currency, value } }) => {
|
|
700
|
-
const index = acc.findIndex((c) => isAddressEqual(c.currency.address, currency.address));
|
|
701
|
-
if (index === -1) {
|
|
702
|
-
return [...acc, { currency, amount: value, direction: 'out' }];
|
|
703
|
-
}
|
|
704
|
-
acc[index].amount = (Number(acc[index].amount) + Number(value)).toString();
|
|
705
|
-
return acc;
|
|
706
|
-
}, []),
|
|
707
|
-
};
|
|
708
|
-
};
|
|
709
|
-
/**
|
|
710
|
-
* Build a transaction to open a pool,
|
|
711
|
-
*
|
|
712
|
-
* @param chainId The chain ID of the blockchain.
|
|
713
|
-
* @param userAddress The address of the user.
|
|
714
|
-
* @param inputToken The address of the input token.
|
|
715
|
-
* @param outputToken The address of the output token.
|
|
716
|
-
* @param options {@link DefaultWriteContractOptions} options.
|
|
717
|
-
* @returns A Promise resolving to a transaction object. If the market is already open, returns undefined.
|
|
718
|
-
* @example
|
|
719
|
-
* import { openPool } from '@clober/v2-sdk'
|
|
720
|
-
*
|
|
721
|
-
* const transaction = await openPool({
|
|
722
|
-
* chainId: 421614,
|
|
723
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
724
|
-
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
725
|
-
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
726
|
-
* salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
727
|
-
* })
|
|
728
|
-
*/
|
|
729
|
-
export const openPool = async ({ chainId, userAddress, tokenA, tokenB, salt, options, }) => {
|
|
730
|
-
const publicClient = createPublicClient({
|
|
731
|
-
chain: CHAIN_MAP[chainId],
|
|
732
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
733
|
-
});
|
|
734
|
-
const pool = await fetchPool(publicClient, chainId, [tokenA, tokenB], salt, !!(options && options.useSubgraph));
|
|
735
|
-
if (!pool.isOpened) {
|
|
736
|
-
return buildTransaction(publicClient, {
|
|
737
|
-
chain: CHAIN_MAP[chainId],
|
|
738
|
-
address: CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
739
|
-
account: userAddress,
|
|
740
|
-
abi: REBALANCER_ABI,
|
|
741
|
-
functionName: 'open',
|
|
742
|
-
args: [
|
|
743
|
-
{
|
|
744
|
-
base: pool.market.bidBook.base.address,
|
|
745
|
-
unitSize: pool.market.bidBook.unitSize,
|
|
746
|
-
quote: pool.market.bidBook.quote.address,
|
|
747
|
-
makerPolicy: MAKER_DEFAULT_POLICY[chainId].value,
|
|
748
|
-
hooks: zeroAddress,
|
|
749
|
-
takerPolicy: TAKER_DEFAULT_POLICY[chainId].value,
|
|
750
|
-
},
|
|
751
|
-
{
|
|
752
|
-
base: pool.market.askBook.base.address,
|
|
753
|
-
unitSize: pool.market.askBook.unitSize,
|
|
754
|
-
quote: pool.market.askBook.quote.address,
|
|
755
|
-
makerPolicy: MAKER_DEFAULT_POLICY[chainId].value,
|
|
756
|
-
hooks: zeroAddress,
|
|
757
|
-
takerPolicy: TAKER_DEFAULT_POLICY[chainId].value,
|
|
758
|
-
},
|
|
759
|
-
toBytes32(salt),
|
|
760
|
-
CONTRACT_ADDRESSES[chainId].Strategy,
|
|
761
|
-
],
|
|
762
|
-
}, options?.gasLimit);
|
|
763
|
-
}
|
|
764
|
-
return undefined;
|
|
765
|
-
};
|
|
766
|
-
export const addLiquidity = async ({ chainId, userAddress, token0, token1, salt, amount0, amount1, options, }) => {
|
|
767
|
-
const publicClient = createPublicClient({
|
|
768
|
-
chain: CHAIN_MAP[chainId],
|
|
769
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
770
|
-
});
|
|
771
|
-
const pool = await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
772
|
-
if (!pool.isOpened) {
|
|
773
|
-
throw new Error(`
|
|
774
|
-
Open the pool before adding liquidity.
|
|
775
|
-
import { openPool } from '@clober/v2-sdk'
|
|
776
|
-
|
|
777
|
-
const transaction = await openPool({
|
|
778
|
-
chainId: ${chainId},
|
|
779
|
-
tokenA: '${token0}',
|
|
780
|
-
tokenB: '${token1}',
|
|
781
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
782
|
-
})
|
|
783
|
-
`);
|
|
784
|
-
}
|
|
785
|
-
const [amountAOrigin, amountBOrigin] = isAddressEqual(pool.currencyA.address, getAddress(token0))
|
|
786
|
-
? [
|
|
787
|
-
parseUnits(amount0 ?? '0', pool.currencyA.decimals),
|
|
788
|
-
parseUnits(amount1 ?? '0', pool.currencyB.decimals),
|
|
789
|
-
]
|
|
790
|
-
: [
|
|
791
|
-
parseUnits(amount1 ?? '0', pool.currencyA.decimals),
|
|
792
|
-
parseUnits(amount0 ?? '0', pool.currencyB.decimals),
|
|
793
|
-
];
|
|
794
|
-
let [amountA, amountB] = [amountAOrigin, amountBOrigin];
|
|
795
|
-
const tokenAPermitParams = isAddressEqual(pool.currencyA.address, getAddress(token0))
|
|
796
|
-
? options?.token0PermitParams ?? emptyERC20PermitParams
|
|
797
|
-
: options?.token1PermitParams ?? emptyERC20PermitParams;
|
|
798
|
-
const tokenBPermitParams = isAddressEqual(pool.currencyA.address, getAddress(token0))
|
|
799
|
-
? options?.token1PermitParams ?? emptyERC20PermitParams
|
|
800
|
-
: options?.token0PermitParams ?? emptyERC20PermitParams;
|
|
801
|
-
let disableSwap = !!(options && options.disableSwap);
|
|
802
|
-
if (pool.totalSupply === 0n ||
|
|
803
|
-
(pool.liquidityA === 0n && pool.liquidityB === 0n)) {
|
|
804
|
-
disableSwap = true;
|
|
805
|
-
}
|
|
806
|
-
const slippageLimitPercent = options?.slippage ?? 1.0;
|
|
807
|
-
const swapParams = {
|
|
808
|
-
inCurrency: zeroAddress,
|
|
809
|
-
amount: 0n,
|
|
810
|
-
data: '0x',
|
|
811
|
-
};
|
|
812
|
-
if (!disableSwap) {
|
|
813
|
-
const currencyBPerCurrencyA = options?.testnetPrice
|
|
814
|
-
? isAddressEqual(getQuoteToken({
|
|
815
|
-
chainId,
|
|
816
|
-
token0,
|
|
817
|
-
token1,
|
|
818
|
-
}), pool.currencyA.address)
|
|
819
|
-
? 1 / Number(options.testnetPrice)
|
|
820
|
-
: Number(options.testnetPrice)
|
|
821
|
-
: undefined;
|
|
822
|
-
const swapAmountA = parseUnits('1', pool.currencyA.decimals);
|
|
823
|
-
let swapAmountB = -1n;
|
|
824
|
-
if (options && options.token0Price && options.token1Price) {
|
|
825
|
-
const tokenAPrice = isAddressEqual(pool.currencyA.address, getAddress(token0))
|
|
826
|
-
? options.token0Price
|
|
827
|
-
: options.token1Price;
|
|
828
|
-
const tokenBPrice = isAddressEqual(pool.currencyA.address, getAddress(token0))
|
|
829
|
-
? options.token1Price
|
|
830
|
-
: options.token0Price;
|
|
831
|
-
swapAmountB = quotes(swapAmountA, tokenAPrice, tokenBPrice, pool.currencyA.decimals, pool.currencyB.decimals);
|
|
832
|
-
}
|
|
833
|
-
else {
|
|
834
|
-
;
|
|
835
|
-
({ amountOut: swapAmountB } = await fetchQuote({
|
|
836
|
-
chainId,
|
|
837
|
-
amountIn: swapAmountA,
|
|
838
|
-
tokenIn: pool.currencyA,
|
|
839
|
-
tokenOut: pool.currencyB,
|
|
840
|
-
slippageLimitPercent: 1,
|
|
841
|
-
userAddress: CONTRACT_ADDRESSES[chainId].Minter,
|
|
842
|
-
testnetPrice: currencyBPerCurrencyA,
|
|
843
|
-
}));
|
|
844
|
-
}
|
|
845
|
-
if (swapAmountB === -1n) {
|
|
846
|
-
throw new Error('Failed to fetch quote');
|
|
847
|
-
}
|
|
848
|
-
const { deltaA, deltaB } = getIdealDelta(amountA, amountB, pool.liquidityA, pool.liquidityB, swapAmountA, swapAmountB);
|
|
849
|
-
if (deltaA < 0n) {
|
|
850
|
-
swapParams.inCurrency = pool.currencyA.address;
|
|
851
|
-
swapParams.amount = -deltaA;
|
|
852
|
-
const { amountOut: actualDeltaB, data: calldata } = await fetchCallData({
|
|
853
|
-
chainId,
|
|
854
|
-
amountIn: swapParams.amount,
|
|
855
|
-
tokenIn: pool.currencyA,
|
|
856
|
-
tokenOut: pool.currencyB,
|
|
857
|
-
slippageLimitPercent,
|
|
858
|
-
userAddress: CONTRACT_ADDRESSES[chainId].Minter,
|
|
859
|
-
testnetPrice: currencyBPerCurrencyA,
|
|
860
|
-
});
|
|
861
|
-
swapParams.data = calldata;
|
|
862
|
-
amountA += deltaA;
|
|
863
|
-
amountB += actualDeltaB;
|
|
864
|
-
}
|
|
865
|
-
else if (deltaB < 0n) {
|
|
866
|
-
swapParams.inCurrency = pool.currencyB.address;
|
|
867
|
-
swapParams.amount = -deltaB;
|
|
868
|
-
const { amountOut: actualDeltaA, data: calldata } = await fetchCallData({
|
|
869
|
-
chainId,
|
|
870
|
-
amountIn: swapParams.amount,
|
|
871
|
-
tokenIn: pool.currencyB,
|
|
872
|
-
tokenOut: pool.currencyA,
|
|
873
|
-
slippageLimitPercent,
|
|
874
|
-
userAddress: CONTRACT_ADDRESSES[chainId].Minter,
|
|
875
|
-
testnetPrice: currencyBPerCurrencyA
|
|
876
|
-
? 1 / currencyBPerCurrencyA
|
|
877
|
-
: undefined,
|
|
878
|
-
});
|
|
879
|
-
swapParams.data = calldata;
|
|
880
|
-
amountA += actualDeltaA;
|
|
881
|
-
amountB += deltaB;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
const { mintAmount, inAmountA, inAmountB } = getExpectedMintResult(pool.totalSupply, pool.liquidityA, pool.liquidityB, amountA, amountB, pool.currencyA, pool.currencyB);
|
|
885
|
-
if (mintAmount === 0n) {
|
|
886
|
-
return {
|
|
887
|
-
transaction: undefined,
|
|
888
|
-
result: {
|
|
889
|
-
currencyA: {
|
|
890
|
-
currency: pool.currencyA,
|
|
891
|
-
amount: '0',
|
|
892
|
-
direction: 'in',
|
|
893
|
-
},
|
|
894
|
-
currencyB: {
|
|
895
|
-
currency: pool.currencyB,
|
|
896
|
-
amount: '0',
|
|
897
|
-
direction: 'in',
|
|
898
|
-
},
|
|
899
|
-
lpCurrency: {
|
|
900
|
-
currency: pool.currencyLp,
|
|
901
|
-
amount: '0',
|
|
902
|
-
direction: 'out',
|
|
903
|
-
},
|
|
904
|
-
},
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
const minMintAmount = applyPercent(mintAmount, 100 - slippageLimitPercent);
|
|
908
|
-
const transaction = await buildTransaction(publicClient, {
|
|
909
|
-
chain: CHAIN_MAP[chainId],
|
|
910
|
-
account: userAddress,
|
|
911
|
-
address: CONTRACT_ADDRESSES[chainId].Minter,
|
|
912
|
-
abi: MINTER_ABI,
|
|
913
|
-
functionName: 'mint',
|
|
914
|
-
args: [
|
|
915
|
-
pool.key,
|
|
916
|
-
amountAOrigin,
|
|
917
|
-
amountBOrigin,
|
|
918
|
-
minMintAmount,
|
|
919
|
-
{
|
|
920
|
-
permitAmount: tokenAPermitParams.permitAmount,
|
|
921
|
-
signature: tokenAPermitParams.signature,
|
|
922
|
-
},
|
|
923
|
-
{
|
|
924
|
-
permitAmount: tokenBPermitParams.permitAmount,
|
|
925
|
-
signature: tokenBPermitParams.signature,
|
|
926
|
-
},
|
|
927
|
-
swapParams,
|
|
928
|
-
],
|
|
929
|
-
value: isAddressEqual(token0, zeroAddress)
|
|
930
|
-
? amountAOrigin
|
|
931
|
-
: isAddressEqual(token1, zeroAddress)
|
|
932
|
-
? amountBOrigin
|
|
933
|
-
: undefined,
|
|
934
|
-
}, options?.gasLimit);
|
|
935
|
-
const currencyARefund = amountA - inAmountA;
|
|
936
|
-
const currencyBRefund = amountB - inAmountB;
|
|
937
|
-
const currencyAResultAmount = amountAOrigin - currencyARefund;
|
|
938
|
-
const currencyBResultAmount = amountBOrigin - currencyBRefund;
|
|
939
|
-
return {
|
|
940
|
-
transaction,
|
|
941
|
-
result: {
|
|
942
|
-
currencyA: {
|
|
943
|
-
currency: pool.currencyA,
|
|
944
|
-
amount: formatUnits(abs(currencyAResultAmount), pool.currencyA.decimals),
|
|
945
|
-
direction: currencyAResultAmount >= 0 ? 'in' : 'out',
|
|
946
|
-
},
|
|
947
|
-
currencyB: {
|
|
948
|
-
currency: pool.currencyB,
|
|
949
|
-
amount: formatUnits(abs(currencyBResultAmount), pool.currencyB.decimals),
|
|
950
|
-
direction: currencyBResultAmount >= 0 ? 'in' : 'out',
|
|
951
|
-
},
|
|
952
|
-
lpCurrency: {
|
|
953
|
-
currency: pool.currencyLp,
|
|
954
|
-
amount: formatUnits(mintAmount, pool.currencyLp.decimals),
|
|
955
|
-
direction: 'out',
|
|
956
|
-
},
|
|
957
|
-
},
|
|
958
|
-
};
|
|
959
|
-
};
|
|
960
|
-
// @dev: Withdraw amount calculation logic is based on the contract code.
|
|
961
|
-
export const removeLiquidity = async ({ chainId, userAddress, token0, token1, salt, amount, options, }) => {
|
|
962
|
-
const publicClient = createPublicClient({
|
|
963
|
-
chain: CHAIN_MAP[chainId],
|
|
964
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
965
|
-
});
|
|
966
|
-
const pool = await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
967
|
-
if (!pool.isOpened) {
|
|
968
|
-
throw new Error(`
|
|
969
|
-
Open the pool before removing liquidity.
|
|
970
|
-
import { openPool } from '@clober/v2-sdk'
|
|
971
|
-
|
|
972
|
-
const transaction = await openPool({
|
|
973
|
-
chainId: ${chainId},
|
|
974
|
-
tokenA: '${token0}',
|
|
975
|
-
tokenB: '${token1}',
|
|
976
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
977
|
-
})
|
|
978
|
-
`);
|
|
979
|
-
}
|
|
980
|
-
const burnAmount = parseUnits(amount, pool.currencyLp.decimals);
|
|
981
|
-
const slippageLimitPercent = options?.slippage ?? 2;
|
|
982
|
-
const withdrawAmountA = (burnAmount * pool.liquidityA) / pool.totalSupply;
|
|
983
|
-
const withdrawAmountB = (burnAmount * pool.liquidityB) / pool.totalSupply;
|
|
984
|
-
const minWithdrawAmountA = applyPercent(withdrawAmountA, 100 - slippageLimitPercent);
|
|
985
|
-
const minWithdrawAmountB = applyPercent(withdrawAmountB, 100 - slippageLimitPercent);
|
|
986
|
-
if (burnAmount === 0n) {
|
|
987
|
-
return {
|
|
988
|
-
transaction: undefined,
|
|
989
|
-
result: {
|
|
990
|
-
currencyA: {
|
|
991
|
-
currency: pool.currencyA,
|
|
992
|
-
amount: '0',
|
|
993
|
-
direction: 'out',
|
|
994
|
-
},
|
|
995
|
-
currencyB: {
|
|
996
|
-
currency: pool.currencyB,
|
|
997
|
-
amount: '0',
|
|
998
|
-
direction: 'out',
|
|
999
|
-
},
|
|
1000
|
-
lpCurrency: {
|
|
1001
|
-
currency: pool.currencyLp,
|
|
1002
|
-
amount: '0',
|
|
1003
|
-
direction: 'in',
|
|
1004
|
-
},
|
|
1005
|
-
},
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
const transaction = await buildTransaction(publicClient, {
|
|
1009
|
-
chain: CHAIN_MAP[chainId],
|
|
1010
|
-
account: userAddress,
|
|
1011
|
-
address: CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
1012
|
-
abi: REBALANCER_ABI,
|
|
1013
|
-
functionName: 'burn',
|
|
1014
|
-
args: [pool.key, burnAmount, minWithdrawAmountA, minWithdrawAmountB],
|
|
1015
|
-
}, options?.gasLimit);
|
|
1016
|
-
return {
|
|
1017
|
-
transaction,
|
|
1018
|
-
result: {
|
|
1019
|
-
currencyA: {
|
|
1020
|
-
currency: pool.currencyA,
|
|
1021
|
-
amount: formatUnits(withdrawAmountA, pool.currencyA.decimals),
|
|
1022
|
-
direction: 'out',
|
|
1023
|
-
},
|
|
1024
|
-
currencyB: {
|
|
1025
|
-
currency: pool.currencyB,
|
|
1026
|
-
amount: formatUnits(withdrawAmountB, pool.currencyB.decimals),
|
|
1027
|
-
direction: 'out',
|
|
1028
|
-
},
|
|
1029
|
-
lpCurrency: {
|
|
1030
|
-
currency: pool.currencyLp,
|
|
1031
|
-
amount: amount,
|
|
1032
|
-
direction: 'in',
|
|
1033
|
-
},
|
|
1034
|
-
},
|
|
1035
|
-
};
|
|
1036
|
-
};
|
|
1037
|
-
export const refillOrder = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
1038
|
-
const publicClient = createPublicClient({
|
|
1039
|
-
chain: CHAIN_MAP[chainId],
|
|
1040
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
1041
|
-
});
|
|
1042
|
-
const pool = options?.pool
|
|
1043
|
-
? options.pool
|
|
1044
|
-
: (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
1045
|
-
if (!pool.isOpened) {
|
|
1046
|
-
throw new Error(`
|
|
1047
|
-
Open the pool before rebalancing pool.
|
|
1048
|
-
import { openPool } from '@clober/v2-sdk'
|
|
1049
|
-
|
|
1050
|
-
const transaction = await openPool({
|
|
1051
|
-
chainId: ${chainId},
|
|
1052
|
-
tokenA: '${token0}',
|
|
1053
|
-
tokenB: '${token1}',
|
|
1054
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1055
|
-
})
|
|
1056
|
-
`);
|
|
1057
|
-
}
|
|
1058
|
-
return buildTransaction(publicClient, {
|
|
1059
|
-
chain: CHAIN_MAP[chainId],
|
|
1060
|
-
account: userAddress,
|
|
1061
|
-
address: CONTRACT_ADDRESSES[chainId].Rebalancer,
|
|
1062
|
-
abi: REBALANCER_ABI,
|
|
1063
|
-
functionName: 'rebalance',
|
|
1064
|
-
args: [pool.key],
|
|
1065
|
-
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1066
|
-
};
|
|
1067
|
-
export const adjustOrderPrice = async ({ chainId, userAddress, token0, token1, salt, oraclePrice, bidPrice, askPrice, alpha, options, }) => {
|
|
1068
|
-
if (Number(alpha) <= 0 || Number(alpha) > 1) {
|
|
1069
|
-
throw new Error('Alpha value must be in the range (0, 1]');
|
|
1070
|
-
}
|
|
1071
|
-
if (Number(bidPrice) <= 0 || Number(askPrice) <= 0) {
|
|
1072
|
-
throw new Error('Price must be greater than 0');
|
|
1073
|
-
}
|
|
1074
|
-
if (Number(bidPrice) >= Number(askPrice)) {
|
|
1075
|
-
throw new Error('Bid price must be less than ask price');
|
|
1076
|
-
}
|
|
1077
|
-
const publicClient = createPublicClient({
|
|
1078
|
-
chain: CHAIN_MAP[chainId],
|
|
1079
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
1080
|
-
});
|
|
1081
|
-
const pool = options?.pool
|
|
1082
|
-
? options.pool
|
|
1083
|
-
: (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
1084
|
-
if (!pool.isOpened) {
|
|
1085
|
-
throw new Error(`
|
|
1086
|
-
Open the pool before updating strategy price.
|
|
1087
|
-
import { openPool } from '@clober/v2-sdk'
|
|
1088
|
-
|
|
1089
|
-
const transaction = await openPool({
|
|
1090
|
-
chainId: ${chainId},
|
|
1091
|
-
tokenA: '${token0}',
|
|
1092
|
-
tokenB: '${token1}',
|
|
1093
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1094
|
-
})
|
|
1095
|
-
`);
|
|
1096
|
-
}
|
|
1097
|
-
const [roundingUpBidPrice, roundingUpAskPrice] = [
|
|
1098
|
-
options?.roundingUpBidPrice ? options.roundingUpBidPrice : false,
|
|
1099
|
-
options?.roundingUpAskPrice ? options.roundingUpAskPrice : false,
|
|
1100
|
-
];
|
|
1101
|
-
const { roundingDownTick: roundingDownTickA, roundingUpTick: roundingUpTickA, } = parsePrice(Number(bidPrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
1102
|
-
const { roundingDownTick: roundingDownTickB, roundingUpTick: roundingUpTickB, } = parsePrice(Number(askPrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
1103
|
-
const oracleRawPrice = convertHumanReadablePriceToRawPrice(Number(oraclePrice), pool.currencyA.decimals, pool.currencyB.decimals);
|
|
1104
|
-
const tickA = options?.bidTick
|
|
1105
|
-
? Number(options.bidTick)
|
|
1106
|
-
: Number(roundingUpBidPrice ? roundingUpTickA : roundingDownTickA);
|
|
1107
|
-
let tickB = options?.askTick
|
|
1108
|
-
? Number(options.askTick)
|
|
1109
|
-
: Number(invertTick(roundingUpAskPrice ? roundingUpTickB : roundingDownTickB));
|
|
1110
|
-
if (invertTick(BigInt(tickB)) <= BigInt(tickA)) {
|
|
1111
|
-
tickB = Number(invertTick(BigInt(tickA + 1)));
|
|
1112
|
-
}
|
|
1113
|
-
const rateRaw = parseUnits(alpha, 6);
|
|
1114
|
-
return buildTransaction(publicClient, {
|
|
1115
|
-
chain: CHAIN_MAP[chainId],
|
|
1116
|
-
account: userAddress,
|
|
1117
|
-
address: CONTRACT_ADDRESSES[chainId].Operator,
|
|
1118
|
-
abi: OPERATOR_ABI,
|
|
1119
|
-
functionName: 'updatePosition',
|
|
1120
|
-
args: [pool.key, oracleRawPrice, tickA, tickB, rateRaw],
|
|
1121
|
-
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1122
|
-
};
|
|
1123
|
-
export const setStrategyConfig = async ({ chainId, userAddress, token0, token1, salt, config, options, }) => {
|
|
1124
|
-
// validate config
|
|
1125
|
-
if (Number(config.referenceThreshold) < 0 ||
|
|
1126
|
-
Number(config.referenceThreshold) > 1) {
|
|
1127
|
-
throw new Error('Reference threshold must be in the range [0, 1]');
|
|
1128
|
-
}
|
|
1129
|
-
if (Number(config.rebalanceThreshold) < 0 ||
|
|
1130
|
-
Number(config.rebalanceThreshold) > 1) {
|
|
1131
|
-
throw new Error('Rebalance threshold must be in the range [0, 1]');
|
|
1132
|
-
}
|
|
1133
|
-
if (Number(config.priceThresholdA) < 0 ||
|
|
1134
|
-
Number(config.priceThresholdA) > 1 ||
|
|
1135
|
-
Number(config.priceThresholdB) < 0 ||
|
|
1136
|
-
Number(config.priceThresholdB) > 1) {
|
|
1137
|
-
throw new Error('Price threshold must be in the range [0, 1]');
|
|
1138
|
-
}
|
|
1139
|
-
if (Number(config.rateA) < 0 ||
|
|
1140
|
-
Number(config.rateA) > 1 ||
|
|
1141
|
-
Number(config.rateB) < 0 ||
|
|
1142
|
-
Number(config.rateB) > 1) {
|
|
1143
|
-
throw new Error('Rate must be in the range [0, 1]');
|
|
1144
|
-
}
|
|
1145
|
-
if (Number(config.minRateA) < 0 ||
|
|
1146
|
-
Number(config.minRateA) > 1 ||
|
|
1147
|
-
Number(config.minRateB) < 0 ||
|
|
1148
|
-
Number(config.minRateB) > 1) {
|
|
1149
|
-
throw new Error('Min rate must be in the range [0, 1]');
|
|
1150
|
-
}
|
|
1151
|
-
if (Number(config.minRateA) > Number(config.rateA) ||
|
|
1152
|
-
Number(config.minRateB) > Number(config.rateB)) {
|
|
1153
|
-
throw new Error('Min rate must be less or equal to rate');
|
|
1154
|
-
}
|
|
1155
|
-
const publicClient = createPublicClient({
|
|
1156
|
-
chain: CHAIN_MAP[chainId],
|
|
1157
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
1158
|
-
});
|
|
1159
|
-
const pool = await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph));
|
|
1160
|
-
if (!pool.isOpened) {
|
|
1161
|
-
throw new Error(`
|
|
1162
|
-
Open the pool before set strategy config.
|
|
1163
|
-
import { openPool } from '@clober/v2-sdk'
|
|
1164
|
-
|
|
1165
|
-
const transaction = await openPool({
|
|
1166
|
-
chainId: ${chainId},
|
|
1167
|
-
tokenA: '${token0}',
|
|
1168
|
-
tokenB: '${token1}',
|
|
1169
|
-
})
|
|
1170
|
-
`);
|
|
1171
|
-
}
|
|
1172
|
-
const configRaw = {
|
|
1173
|
-
referenceThreshold: parseUnits(config.referenceThreshold, 6),
|
|
1174
|
-
rebalanceThreshold: parseUnits(config.rebalanceThreshold, 6),
|
|
1175
|
-
rateA: parseUnits(config.rateA, 6),
|
|
1176
|
-
rateB: parseUnits(config.rateB, 6),
|
|
1177
|
-
minRateA: parseUnits(config.minRateA, 6),
|
|
1178
|
-
minRateB: parseUnits(config.minRateB, 6),
|
|
1179
|
-
priceThresholdA: parseUnits(config.priceThresholdA, 6),
|
|
1180
|
-
priceThresholdB: parseUnits(config.priceThresholdB, 6),
|
|
1181
|
-
};
|
|
1182
|
-
return buildTransaction(publicClient, {
|
|
1183
|
-
chain: CHAIN_MAP[chainId],
|
|
1184
|
-
account: userAddress,
|
|
1185
|
-
address: CONTRACT_ADDRESSES[chainId].Strategy,
|
|
1186
|
-
abi: STRATEGY_ABI,
|
|
1187
|
-
functionName: 'setConfig',
|
|
1188
|
-
args: [pool.key, configRaw],
|
|
1189
|
-
}, options?.gasLimit);
|
|
1190
|
-
};
|
|
1191
|
-
export const pausePool = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
1192
|
-
const publicClient = createPublicClient({
|
|
1193
|
-
chain: CHAIN_MAP[chainId],
|
|
1194
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
1195
|
-
});
|
|
1196
|
-
const pool = options?.pool
|
|
1197
|
-
? options.pool
|
|
1198
|
-
: (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
1199
|
-
if (!pool.isOpened) {
|
|
1200
|
-
throw new Error(`
|
|
1201
|
-
Open the pool before trying pause.
|
|
1202
|
-
import { openPool } from '@clober/v2-sdk'
|
|
1203
|
-
|
|
1204
|
-
const transaction = await openPool({
|
|
1205
|
-
chainId: ${chainId},
|
|
1206
|
-
tokenA: '${token0}',
|
|
1207
|
-
tokenB: '${token1}',
|
|
1208
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1209
|
-
})
|
|
1210
|
-
`);
|
|
1211
|
-
}
|
|
1212
|
-
if (pool.paused) {
|
|
1213
|
-
return undefined;
|
|
1214
|
-
}
|
|
1215
|
-
return buildTransaction(publicClient, {
|
|
1216
|
-
chain: CHAIN_MAP[chainId],
|
|
1217
|
-
account: userAddress,
|
|
1218
|
-
address: CONTRACT_ADDRESSES[chainId].Operator,
|
|
1219
|
-
abi: OPERATOR_ABI,
|
|
1220
|
-
functionName: 'pause',
|
|
1221
|
-
args: [pool.key],
|
|
1222
|
-
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1223
|
-
};
|
|
1224
|
-
export const resumePool = async ({ chainId, userAddress, token0, token1, salt, options, }) => {
|
|
1225
|
-
const publicClient = createPublicClient({
|
|
1226
|
-
chain: CHAIN_MAP[chainId],
|
|
1227
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
1228
|
-
});
|
|
1229
|
-
const pool = options?.pool
|
|
1230
|
-
? options.pool
|
|
1231
|
-
: (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph))).toJson();
|
|
1232
|
-
if (!pool.isOpened) {
|
|
1233
|
-
throw new Error(`
|
|
1234
|
-
Open the pool before trying resume.
|
|
1235
|
-
import { openPool } from '@clober/v2-sdk'
|
|
1236
|
-
|
|
1237
|
-
const transaction = await openPool({
|
|
1238
|
-
chainId: ${chainId},
|
|
1239
|
-
tokenA: '${token0}',
|
|
1240
|
-
tokenB: '${token1}',
|
|
1241
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1242
|
-
})
|
|
1243
|
-
`);
|
|
1244
|
-
}
|
|
1245
|
-
if (!pool.paused) {
|
|
1246
|
-
return undefined;
|
|
1247
|
-
}
|
|
1248
|
-
return buildTransaction(publicClient, {
|
|
1249
|
-
chain: CHAIN_MAP[chainId],
|
|
1250
|
-
account: userAddress,
|
|
1251
|
-
address: CONTRACT_ADDRESSES[chainId].Strategy,
|
|
1252
|
-
abi: STRATEGY_ABI,
|
|
1253
|
-
functionName: 'unpause',
|
|
1254
|
-
args: [pool.key],
|
|
1255
|
-
}, options?.gasLimit, options?.gasPriceLimit);
|
|
1256
|
-
};
|
|
1257
|
-
//# sourceMappingURL=call.js.map
|