@haneullabs/deepbook-v3 0.1.0
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/CHANGELOG.md +984 -0
- package/README.md +1 -0
- package/dist/cjs/client.d.ts +861 -0
- package/dist/cjs/client.js +1982 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/contracts/deepbook/account.d.ts +105 -0
- package/dist/cjs/contracts/deepbook/account.js +163 -0
- package/dist/cjs/contracts/deepbook/account.js.map +7 -0
- package/dist/cjs/contracts/deepbook/balance_manager.d.ts +268 -0
- package/dist/cjs/contracts/deepbook/balance_manager.js +361 -0
- package/dist/cjs/contracts/deepbook/balance_manager.js.map +7 -0
- package/dist/cjs/contracts/deepbook/balances.d.ts +10 -0
- package/dist/cjs/contracts/deepbook/balances.js +35 -0
- package/dist/cjs/contracts/deepbook/balances.js.map +7 -0
- package/dist/cjs/contracts/deepbook/big_vector.d.ts +62 -0
- package/dist/cjs/contracts/deepbook/big_vector.js +80 -0
- package/dist/cjs/contracts/deepbook/big_vector.js.map +7 -0
- package/dist/cjs/contracts/deepbook/book.d.ts +34 -0
- package/dist/cjs/contracts/deepbook/book.js +50 -0
- package/dist/cjs/contracts/deepbook/book.js.map +7 -0
- package/dist/cjs/contracts/deepbook/constants.d.ts +176 -0
- package/dist/cjs/contracts/deepbook/constants.js +338 -0
- package/dist/cjs/contracts/deepbook/constants.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deep_price.d.ts +60 -0
- package/dist/cjs/contracts/deepbook/deep_price.js +87 -0
- package/dist/cjs/contracts/deepbook/deep_price.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +14 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js +42 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js +47 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +9 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +5 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.js +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +28 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.js +47 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +45 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +35 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +45 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +7 -0
- package/dist/cjs/contracts/deepbook/ewma.d.ts +17 -0
- package/dist/cjs/contracts/deepbook/ewma.js +39 -0
- package/dist/cjs/contracts/deepbook/ewma.js.map +7 -0
- package/dist/cjs/contracts/deepbook/fill.d.ts +153 -0
- package/dist/cjs/contracts/deepbook/fill.js +251 -0
- package/dist/cjs/contracts/deepbook/fill.js.map +7 -0
- package/dist/cjs/contracts/deepbook/governance.d.ts +63 -0
- package/dist/cjs/contracts/deepbook/governance.js +79 -0
- package/dist/cjs/contracts/deepbook/governance.js.map +7 -0
- package/dist/cjs/contracts/deepbook/history.d.ts +60 -0
- package/dist/cjs/contracts/deepbook/history.js +78 -0
- package/dist/cjs/contracts/deepbook/history.js.map +7 -0
- package/dist/cjs/contracts/deepbook/math.d.ts +94 -0
- package/dist/cjs/contracts/deepbook/math.js +132 -0
- package/dist/cjs/contracts/deepbook/math.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order.d.ts +135 -0
- package/dist/cjs/contracts/deepbook/order.js +218 -0
- package/dist/cjs/contracts/deepbook/order.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order_info.d.ts +296 -0
- package/dist/cjs/contracts/deepbook/order_info.js +386 -0
- package/dist/cjs/contracts/deepbook/order_info.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order_query.d.ts +85 -0
- package/dist/cjs/contracts/deepbook/order_query.js +96 -0
- package/dist/cjs/contracts/deepbook/order_query.js.map +7 -0
- package/dist/cjs/contracts/deepbook/pool.d.ts +1218 -0
- package/dist/cjs/contracts/deepbook/pool.js +1236 -0
- package/dist/cjs/contracts/deepbook/pool.js.map +7 -0
- package/dist/cjs/contracts/deepbook/registry.d.ts +134 -0
- package/dist/cjs/contracts/deepbook/registry.js +182 -0
- package/dist/cjs/contracts/deepbook/registry.js.map +7 -0
- package/dist/cjs/contracts/deepbook/state.d.ts +117 -0
- package/dist/cjs/contracts/deepbook/state.js +104 -0
- package/dist/cjs/contracts/deepbook/state.js.map +7 -0
- package/dist/cjs/contracts/deepbook/trade_params.d.ts +7 -0
- package/dist/cjs/contracts/deepbook/trade_params.js +35 -0
- package/dist/cjs/contracts/deepbook/trade_params.js.map +7 -0
- package/dist/cjs/contracts/deepbook/vault.d.ts +30 -0
- package/dist/cjs/contracts/deepbook/vault.js +65 -0
- package/dist/cjs/contracts/deepbook/vault.js.map +7 -0
- package/dist/cjs/contracts/utils/index.d.ts +25 -0
- package/dist/cjs/contracts/utils/index.js +148 -0
- package/dist/cjs/contracts/utils/index.js.map +7 -0
- package/dist/cjs/index.d.ts +23 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
- package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
- package/dist/cjs/pyth/pyth-helpers.js +36 -0
- package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
- package/dist/cjs/pyth/pyth.d.ts +65 -0
- package/dist/cjs/pyth/pyth.js +269 -0
- package/dist/cjs/pyth/pyth.js.map +7 -0
- package/dist/cjs/transactions/balanceManager.d.ts +168 -0
- package/dist/cjs/transactions/balanceManager.js +384 -0
- package/dist/cjs/transactions/balanceManager.js.map +7 -0
- package/dist/cjs/transactions/deepbook.d.ts +477 -0
- package/dist/cjs/transactions/deepbook.js +1335 -0
- package/dist/cjs/transactions/deepbook.js.map +7 -0
- package/dist/cjs/transactions/deepbookAdmin.d.ts +105 -0
- package/dist/cjs/transactions/deepbookAdmin.js +334 -0
- package/dist/cjs/transactions/deepbookAdmin.js.map +7 -0
- package/dist/cjs/transactions/flashLoans.d.ts +56 -0
- package/dist/cjs/transactions/flashLoans.js +124 -0
- package/dist/cjs/transactions/flashLoans.js.map +7 -0
- package/dist/cjs/transactions/governance.d.ts +42 -0
- package/dist/cjs/transactions/governance.js +135 -0
- package/dist/cjs/transactions/governance.js.map +7 -0
- package/dist/cjs/transactions/marginAdmin.d.ts +133 -0
- package/dist/cjs/transactions/marginAdmin.js +393 -0
- package/dist/cjs/transactions/marginAdmin.js.map +7 -0
- package/dist/cjs/transactions/marginLiquidations.d.ts +61 -0
- package/dist/cjs/transactions/marginLiquidations.js +173 -0
- package/dist/cjs/transactions/marginLiquidations.js.map +7 -0
- package/dist/cjs/transactions/marginMaintainer.d.ts +80 -0
- package/dist/cjs/transactions/marginMaintainer.js +251 -0
- package/dist/cjs/transactions/marginMaintainer.js.map +7 -0
- package/dist/cjs/transactions/marginManager.d.ts +236 -0
- package/dist/cjs/transactions/marginManager.js +688 -0
- package/dist/cjs/transactions/marginManager.js.map +7 -0
- package/dist/cjs/transactions/marginPool.d.ts +134 -0
- package/dist/cjs/transactions/marginPool.js +330 -0
- package/dist/cjs/transactions/marginPool.js.map +7 -0
- package/dist/cjs/transactions/marginRegistry.d.ts +94 -0
- package/dist/cjs/transactions/marginRegistry.js +221 -0
- package/dist/cjs/transactions/marginRegistry.js.map +7 -0
- package/dist/cjs/transactions/marginTPSL.d.ts +93 -0
- package/dist/cjs/transactions/marginTPSL.js +286 -0
- package/dist/cjs/transactions/marginTPSL.js.map +7 -0
- package/dist/cjs/transactions/poolProxy.d.ts +104 -0
- package/dist/cjs/transactions/poolProxy.js +435 -0
- package/dist/cjs/transactions/poolProxy.js.map +7 -0
- package/dist/cjs/types/bcs.d.ts +5 -0
- package/dist/cjs/types/bcs.js +33 -0
- package/dist/cjs/types/bcs.js.map +7 -0
- package/dist/cjs/types/index.d.ts +218 -0
- package/dist/cjs/types/index.js +38 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/utils/config.d.ts +65 -0
- package/dist/cjs/utils/config.js +144 -0
- package/dist/cjs/utils/config.js.map +7 -0
- package/dist/cjs/utils/constants.d.ts +76 -0
- package/dist/cjs/utils/constants.js +382 -0
- package/dist/cjs/utils/constants.js.map +7 -0
- package/dist/cjs/utils/errors.d.ts +42 -0
- package/dist/cjs/utils/errors.js +70 -0
- package/dist/cjs/utils/errors.js.map +7 -0
- package/dist/cjs/utils/validation.d.ts +50 -0
- package/dist/cjs/utils/validation.js +67 -0
- package/dist/cjs/utils/validation.js.map +7 -0
- package/dist/esm/client.d.ts +861 -0
- package/dist/esm/client.js +1967 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/contracts/deepbook/account.d.ts +105 -0
- package/dist/esm/contracts/deepbook/account.js +133 -0
- package/dist/esm/contracts/deepbook/account.js.map +7 -0
- package/dist/esm/contracts/deepbook/balance_manager.d.ts +268 -0
- package/dist/esm/contracts/deepbook/balance_manager.js +331 -0
- package/dist/esm/contracts/deepbook/balance_manager.js.map +7 -0
- package/dist/esm/contracts/deepbook/balances.d.ts +10 -0
- package/dist/esm/contracts/deepbook/balances.js +15 -0
- package/dist/esm/contracts/deepbook/balances.js.map +7 -0
- package/dist/esm/contracts/deepbook/big_vector.d.ts +62 -0
- package/dist/esm/contracts/deepbook/big_vector.js +50 -0
- package/dist/esm/contracts/deepbook/big_vector.js.map +7 -0
- package/dist/esm/contracts/deepbook/book.d.ts +34 -0
- package/dist/esm/contracts/deepbook/book.js +20 -0
- package/dist/esm/contracts/deepbook/book.js.map +7 -0
- package/dist/esm/contracts/deepbook/constants.d.ts +176 -0
- package/dist/esm/contracts/deepbook/constants.js +318 -0
- package/dist/esm/contracts/deepbook/constants.js.map +7 -0
- package/dist/esm/contracts/deepbook/deep_price.d.ts +60 -0
- package/dist/esm/contracts/deepbook/deep_price.js +67 -0
- package/dist/esm/contracts/deepbook/deep_price.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +14 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.js +22 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +33 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.js +17 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +9 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.js +13 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +5 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.js +13 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +28 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.js +17 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +25 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +7 -0
- package/dist/esm/contracts/deepbook/ewma.d.ts +17 -0
- package/dist/esm/contracts/deepbook/ewma.js +19 -0
- package/dist/esm/contracts/deepbook/ewma.js.map +7 -0
- package/dist/esm/contracts/deepbook/fill.d.ts +153 -0
- package/dist/esm/contracts/deepbook/fill.js +221 -0
- package/dist/esm/contracts/deepbook/fill.js.map +7 -0
- package/dist/esm/contracts/deepbook/governance.d.ts +63 -0
- package/dist/esm/contracts/deepbook/governance.js +49 -0
- package/dist/esm/contracts/deepbook/governance.js.map +7 -0
- package/dist/esm/contracts/deepbook/history.d.ts +60 -0
- package/dist/esm/contracts/deepbook/history.js +48 -0
- package/dist/esm/contracts/deepbook/history.js.map +7 -0
- package/dist/esm/contracts/deepbook/math.d.ts +94 -0
- package/dist/esm/contracts/deepbook/math.js +112 -0
- package/dist/esm/contracts/deepbook/math.js.map +7 -0
- package/dist/esm/contracts/deepbook/order.d.ts +135 -0
- package/dist/esm/contracts/deepbook/order.js +188 -0
- package/dist/esm/contracts/deepbook/order.js.map +7 -0
- package/dist/esm/contracts/deepbook/order_info.d.ts +296 -0
- package/dist/esm/contracts/deepbook/order_info.js +356 -0
- package/dist/esm/contracts/deepbook/order_info.js.map +7 -0
- package/dist/esm/contracts/deepbook/order_query.d.ts +85 -0
- package/dist/esm/contracts/deepbook/order_query.js +66 -0
- package/dist/esm/contracts/deepbook/order_query.js.map +7 -0
- package/dist/esm/contracts/deepbook/pool.d.ts +1218 -0
- package/dist/esm/contracts/deepbook/pool.js +1206 -0
- package/dist/esm/contracts/deepbook/pool.js.map +7 -0
- package/dist/esm/contracts/deepbook/registry.d.ts +134 -0
- package/dist/esm/contracts/deepbook/registry.js +152 -0
- package/dist/esm/contracts/deepbook/registry.js.map +7 -0
- package/dist/esm/contracts/deepbook/state.d.ts +117 -0
- package/dist/esm/contracts/deepbook/state.js +74 -0
- package/dist/esm/contracts/deepbook/state.js.map +7 -0
- package/dist/esm/contracts/deepbook/trade_params.d.ts +7 -0
- package/dist/esm/contracts/deepbook/trade_params.js +15 -0
- package/dist/esm/contracts/deepbook/trade_params.js.map +7 -0
- package/dist/esm/contracts/deepbook/vault.d.ts +30 -0
- package/dist/esm/contracts/deepbook/vault.js +35 -0
- package/dist/esm/contracts/deepbook/vault.js.map +7 -0
- package/dist/esm/contracts/utils/index.d.ts +25 -0
- package/dist/esm/contracts/utils/index.js +128 -0
- package/dist/esm/contracts/utils/index.js.map +7 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.js +81 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/esm/pyth/PriceServiceConnection.js +38 -0
- package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
- package/dist/esm/pyth/pyth-helpers.js +16 -0
- package/dist/esm/pyth/pyth-helpers.js.map +7 -0
- package/dist/esm/pyth/pyth.d.ts +65 -0
- package/dist/esm/pyth/pyth.js +249 -0
- package/dist/esm/pyth/pyth.js.map +7 -0
- package/dist/esm/transactions/balanceManager.d.ts +168 -0
- package/dist/esm/transactions/balanceManager.js +364 -0
- package/dist/esm/transactions/balanceManager.js.map +7 -0
- package/dist/esm/transactions/deepbook.d.ts +477 -0
- package/dist/esm/transactions/deepbook.js +1321 -0
- package/dist/esm/transactions/deepbook.js.map +7 -0
- package/dist/esm/transactions/deepbookAdmin.d.ts +105 -0
- package/dist/esm/transactions/deepbookAdmin.js +314 -0
- package/dist/esm/transactions/deepbookAdmin.js.map +7 -0
- package/dist/esm/transactions/flashLoans.d.ts +56 -0
- package/dist/esm/transactions/flashLoans.js +104 -0
- package/dist/esm/transactions/flashLoans.js.map +7 -0
- package/dist/esm/transactions/governance.d.ts +42 -0
- package/dist/esm/transactions/governance.js +115 -0
- package/dist/esm/transactions/governance.js.map +7 -0
- package/dist/esm/transactions/marginAdmin.d.ts +133 -0
- package/dist/esm/transactions/marginAdmin.js +373 -0
- package/dist/esm/transactions/marginAdmin.js.map +7 -0
- package/dist/esm/transactions/marginLiquidations.d.ts +61 -0
- package/dist/esm/transactions/marginLiquidations.js +153 -0
- package/dist/esm/transactions/marginLiquidations.js.map +7 -0
- package/dist/esm/transactions/marginMaintainer.d.ts +80 -0
- package/dist/esm/transactions/marginMaintainer.js +231 -0
- package/dist/esm/transactions/marginMaintainer.js.map +7 -0
- package/dist/esm/transactions/marginManager.d.ts +236 -0
- package/dist/esm/transactions/marginManager.js +668 -0
- package/dist/esm/transactions/marginManager.js.map +7 -0
- package/dist/esm/transactions/marginPool.d.ts +134 -0
- package/dist/esm/transactions/marginPool.js +310 -0
- package/dist/esm/transactions/marginPool.js.map +7 -0
- package/dist/esm/transactions/marginRegistry.d.ts +94 -0
- package/dist/esm/transactions/marginRegistry.js +201 -0
- package/dist/esm/transactions/marginRegistry.js.map +7 -0
- package/dist/esm/transactions/marginTPSL.d.ts +93 -0
- package/dist/esm/transactions/marginTPSL.js +266 -0
- package/dist/esm/transactions/marginTPSL.js.map +7 -0
- package/dist/esm/transactions/poolProxy.d.ts +104 -0
- package/dist/esm/transactions/poolProxy.js +415 -0
- package/dist/esm/transactions/poolProxy.js.map +7 -0
- package/dist/esm/types/bcs.d.ts +5 -0
- package/dist/esm/types/bcs.js +13 -0
- package/dist/esm/types/bcs.js.map +7 -0
- package/dist/esm/types/index.d.ts +218 -0
- package/dist/esm/types/index.js +18 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/config.d.ts +65 -0
- package/dist/esm/utils/config.js +135 -0
- package/dist/esm/utils/config.js.map +7 -0
- package/dist/esm/utils/constants.d.ts +76 -0
- package/dist/esm/utils/constants.js +362 -0
- package/dist/esm/utils/constants.js.map +7 -0
- package/dist/esm/utils/errors.d.ts +42 -0
- package/dist/esm/utils/errors.js +50 -0
- package/dist/esm/utils/errors.js.map +7 -0
- package/dist/esm/utils/validation.d.ts +50 -0
- package/dist/esm/utils/validation.js +47 -0
- package/dist/esm/utils/validation.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/src/client.ts +2451 -0
- package/src/contracts/deepbook/account.ts +199 -0
- package/src/contracts/deepbook/balance_manager.ts +532 -0
- package/src/contracts/deepbook/balances.ts +19 -0
- package/src/contracts/deepbook/big_vector.ts +74 -0
- package/src/contracts/deepbook/book.ts +24 -0
- package/src/contracts/deepbook/constants.ts +458 -0
- package/src/contracts/deepbook/deep_price.ts +84 -0
- package/src/contracts/deepbook/deps/std/type_name.ts +23 -0
- package/src/contracts/deepbook/deps/sui/bag.ts +41 -0
- package/src/contracts/deepbook/deps/sui/balance.ts +18 -0
- package/src/contracts/deepbook/deps/sui/object.ts +14 -0
- package/src/contracts/deepbook/deps/sui/table.ts +36 -0
- package/src/contracts/deepbook/deps/sui/vec_map.ts +33 -0
- package/src/contracts/deepbook/deps/sui/vec_set.ts +22 -0
- package/src/contracts/deepbook/deps/sui/versioned.ts +13 -0
- package/src/contracts/deepbook/ewma.ts +26 -0
- package/src/contracts/deepbook/fill.ts +336 -0
- package/src/contracts/deepbook/governance.ts +52 -0
- package/src/contracts/deepbook/history.ts +51 -0
- package/src/contracts/deepbook/math.ts +210 -0
- package/src/contracts/deepbook/order.ts +269 -0
- package/src/contracts/deepbook/order_info.ts +513 -0
- package/src/contracts/deepbook/order_query.ts +115 -0
- package/src/contracts/deepbook/pool.ts +2269 -0
- package/src/contracts/deepbook/registry.ts +242 -0
- package/src/contracts/deepbook/state.ts +74 -0
- package/src/contracts/deepbook/trade_params.ts +16 -0
- package/src/contracts/deepbook/vault.ts +37 -0
- package/src/contracts/utils/index.ts +184 -0
- package/src/index.ts +95 -0
- package/src/pyth/PriceServiceConnection.ts +48 -0
- package/src/pyth/pyth-helpers.ts +23 -0
- package/src/pyth/pyth.ts +305 -0
- package/src/transactions/balanceManager.ts +399 -0
- package/src/transactions/deepbook.ts +1519 -0
- package/src/transactions/deepbookAdmin.ts +332 -0
- package/src/transactions/flashLoans.ts +123 -0
- package/src/transactions/governance.ts +123 -0
- package/src/transactions/marginAdmin.ts +396 -0
- package/src/transactions/marginLiquidations.ts +175 -0
- package/src/transactions/marginMaintainer.ts +280 -0
- package/src/transactions/marginManager.ts +708 -0
- package/src/transactions/marginPool.ts +339 -0
- package/src/transactions/marginRegistry.ts +212 -0
- package/src/transactions/marginTPSL.ts +296 -0
- package/src/transactions/poolProxy.ts +438 -0
- package/src/types/bcs.ts +8 -0
- package/src/types/index.ts +255 -0
- package/src/utils/config.ts +177 -0
- package/src/utils/constants.ts +374 -0
- package/src/utils/errors.ts +67 -0
- package/src/utils/validation.ts +91 -0
|
@@ -0,0 +1,1321 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _config;
|
|
9
|
+
import { coinWithBalance } from "@haneullabs/haneul/transactions";
|
|
10
|
+
import { OrderType, SelfMatchingOptions } from "../types/index.js";
|
|
11
|
+
import {
|
|
12
|
+
DEEP_SCALAR,
|
|
13
|
+
FLOAT_SCALAR,
|
|
14
|
+
GAS_BUDGET,
|
|
15
|
+
MAX_TIMESTAMP,
|
|
16
|
+
POOL_CREATION_FEE_DEEP
|
|
17
|
+
} from "../utils/config.js";
|
|
18
|
+
class DeepBookContract {
|
|
19
|
+
/**
|
|
20
|
+
* @param {DeepBookConfig} config Configuration for DeepBookContract
|
|
21
|
+
*/
|
|
22
|
+
constructor(config) {
|
|
23
|
+
__privateAdd(this, _config);
|
|
24
|
+
/**
|
|
25
|
+
* @description Place a limit order
|
|
26
|
+
* @param {PlaceLimitOrderParams} params Parameters for placing a limit order
|
|
27
|
+
* @returns A function that takes a Transaction object
|
|
28
|
+
*/
|
|
29
|
+
this.placeLimitOrder = (params) => (tx) => {
|
|
30
|
+
const {
|
|
31
|
+
poolKey,
|
|
32
|
+
balanceManagerKey,
|
|
33
|
+
clientOrderId,
|
|
34
|
+
price,
|
|
35
|
+
quantity,
|
|
36
|
+
isBid,
|
|
37
|
+
expiration = MAX_TIMESTAMP,
|
|
38
|
+
orderType = OrderType.NO_RESTRICTION,
|
|
39
|
+
selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,
|
|
40
|
+
payWithDeep = true
|
|
41
|
+
} = params;
|
|
42
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
43
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
44
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
45
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
46
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
47
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
48
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
49
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
50
|
+
tx.moveCall({
|
|
51
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_limit_order`,
|
|
52
|
+
arguments: [
|
|
53
|
+
tx.object(pool.address),
|
|
54
|
+
tx.object(balanceManager.address),
|
|
55
|
+
tradeProof,
|
|
56
|
+
tx.pure.u64(clientOrderId),
|
|
57
|
+
tx.pure.u8(orderType),
|
|
58
|
+
tx.pure.u8(selfMatchingOption),
|
|
59
|
+
tx.pure.u64(inputPrice),
|
|
60
|
+
tx.pure.u64(inputQuantity),
|
|
61
|
+
tx.pure.bool(isBid),
|
|
62
|
+
tx.pure.bool(payWithDeep),
|
|
63
|
+
tx.pure.u64(expiration),
|
|
64
|
+
tx.object.clock()
|
|
65
|
+
],
|
|
66
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @description Place a market order
|
|
71
|
+
* @param {PlaceMarketOrderParams} params Parameters for placing a market order
|
|
72
|
+
* @returns A function that takes a Transaction object
|
|
73
|
+
*/
|
|
74
|
+
this.placeMarketOrder = (params) => (tx) => {
|
|
75
|
+
const {
|
|
76
|
+
poolKey,
|
|
77
|
+
balanceManagerKey,
|
|
78
|
+
clientOrderId,
|
|
79
|
+
quantity,
|
|
80
|
+
isBid,
|
|
81
|
+
selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,
|
|
82
|
+
payWithDeep = true
|
|
83
|
+
} = params;
|
|
84
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
85
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
86
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
87
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
88
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
89
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
90
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
91
|
+
tx.moveCall({
|
|
92
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_market_order`,
|
|
93
|
+
arguments: [
|
|
94
|
+
tx.object(pool.address),
|
|
95
|
+
tx.object(balanceManager.address),
|
|
96
|
+
tradeProof,
|
|
97
|
+
tx.pure.u64(clientOrderId),
|
|
98
|
+
tx.pure.u8(selfMatchingOption),
|
|
99
|
+
tx.pure.u64(inputQuantity),
|
|
100
|
+
tx.pure.bool(isBid),
|
|
101
|
+
tx.pure.bool(payWithDeep),
|
|
102
|
+
tx.object.clock()
|
|
103
|
+
],
|
|
104
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* @description Modify an existing order
|
|
109
|
+
* @param {string} poolKey The key to identify the pool
|
|
110
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
111
|
+
* @param {string} orderId Order ID to modify
|
|
112
|
+
* @param {number} newQuantity New quantity for the order
|
|
113
|
+
* @returns A function that takes a Transaction object
|
|
114
|
+
*/
|
|
115
|
+
this.modifyOrder = (poolKey, balanceManagerKey, orderId, newQuantity) => (tx) => {
|
|
116
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
117
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
118
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
119
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
120
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
121
|
+
const inputQuantity = Math.round(newQuantity * baseCoin.scalar);
|
|
122
|
+
tx.moveCall({
|
|
123
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::modify_order`,
|
|
124
|
+
arguments: [
|
|
125
|
+
tx.object(pool.address),
|
|
126
|
+
tx.object(balanceManager.address),
|
|
127
|
+
tradeProof,
|
|
128
|
+
tx.pure.u128(orderId),
|
|
129
|
+
tx.pure.u64(inputQuantity),
|
|
130
|
+
tx.object.clock()
|
|
131
|
+
],
|
|
132
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* @description Cancel an existing order
|
|
137
|
+
* @param {string} poolKey The key to identify the pool
|
|
138
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
139
|
+
* @param {string} orderId Order ID to cancel
|
|
140
|
+
* @returns A function that takes a Transaction object
|
|
141
|
+
*/
|
|
142
|
+
this.cancelOrder = (poolKey, balanceManagerKey, orderId) => (tx) => {
|
|
143
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
144
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
145
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
146
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
147
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
148
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
149
|
+
tx.moveCall({
|
|
150
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_order`,
|
|
151
|
+
arguments: [
|
|
152
|
+
tx.object(pool.address),
|
|
153
|
+
tx.object(balanceManager.address),
|
|
154
|
+
tradeProof,
|
|
155
|
+
tx.pure.u128(orderId),
|
|
156
|
+
tx.object.clock()
|
|
157
|
+
],
|
|
158
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* @description Cancel multiple orders
|
|
163
|
+
* @param {string} poolKey The key to identify the pool
|
|
164
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
165
|
+
* @param {string[]} orderIds Array of order IDs to cancel
|
|
166
|
+
* @returns A function that takes a Transaction object
|
|
167
|
+
*/
|
|
168
|
+
this.cancelOrders = (poolKey, balanceManagerKey, orderIds) => (tx) => {
|
|
169
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
170
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
171
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
172
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
173
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
174
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
175
|
+
tx.moveCall({
|
|
176
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_orders`,
|
|
177
|
+
arguments: [
|
|
178
|
+
tx.object(pool.address),
|
|
179
|
+
tx.object(balanceManager.address),
|
|
180
|
+
tradeProof,
|
|
181
|
+
tx.pure.vector("u128", orderIds),
|
|
182
|
+
tx.object.clock()
|
|
183
|
+
],
|
|
184
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* @description Cancel all open orders for a balance manager
|
|
189
|
+
* @param {string} poolKey The key to identify the pool
|
|
190
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
191
|
+
* @returns A function that takes a Transaction object
|
|
192
|
+
*/
|
|
193
|
+
this.cancelAllOrders = (poolKey, balanceManagerKey) => (tx) => {
|
|
194
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
195
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
196
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
197
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
198
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
199
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
200
|
+
tx.moveCall({
|
|
201
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_all_orders`,
|
|
202
|
+
arguments: [
|
|
203
|
+
tx.object(pool.address),
|
|
204
|
+
tx.object(balanceManager.address),
|
|
205
|
+
tradeProof,
|
|
206
|
+
tx.object.clock()
|
|
207
|
+
],
|
|
208
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* @description Withdraw settled amounts for a balance manager
|
|
213
|
+
* @param {string} poolKey The key to identify the pool
|
|
214
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
215
|
+
* @returns A function that takes a Transaction object
|
|
216
|
+
*/
|
|
217
|
+
this.withdrawSettledAmounts = (poolKey, balanceManagerKey) => (tx) => {
|
|
218
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
219
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
220
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
221
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
222
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
223
|
+
tx.moveCall({
|
|
224
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts`,
|
|
225
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
|
|
226
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* @description Withdraw settled amounts permissionlessly for a balance manager
|
|
231
|
+
* @param {string} poolKey The key to identify the pool
|
|
232
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
233
|
+
* @returns A function that takes a Transaction object
|
|
234
|
+
*/
|
|
235
|
+
this.withdrawSettledAmountsPermissionless = (poolKey, balanceManagerKey) => (tx) => {
|
|
236
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
237
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
238
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
239
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
240
|
+
tx.moveCall({
|
|
241
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
|
|
242
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address)],
|
|
243
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* @description Add a deep price point for a target pool using a reference pool
|
|
248
|
+
* @param {string} targetPoolKey The key to identify the target pool
|
|
249
|
+
* @param {string} referencePoolKey The key to identify the reference pool
|
|
250
|
+
* @returns A function that takes a Transaction object
|
|
251
|
+
*/
|
|
252
|
+
this.addDeepPricePoint = (targetPoolKey, referencePoolKey) => (tx) => {
|
|
253
|
+
const targetPool = __privateGet(this, _config).getPool(targetPoolKey);
|
|
254
|
+
const referencePool = __privateGet(this, _config).getPool(referencePoolKey);
|
|
255
|
+
const targetBaseCoin = __privateGet(this, _config).getCoin(targetPool.baseCoin);
|
|
256
|
+
const targetQuoteCoin = __privateGet(this, _config).getCoin(targetPool.quoteCoin);
|
|
257
|
+
const referenceBaseCoin = __privateGet(this, _config).getCoin(referencePool.baseCoin);
|
|
258
|
+
const referenceQuoteCoin = __privateGet(this, _config).getCoin(referencePool.quoteCoin);
|
|
259
|
+
tx.moveCall({
|
|
260
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::add_deep_price_point`,
|
|
261
|
+
arguments: [
|
|
262
|
+
tx.object(targetPool.address),
|
|
263
|
+
tx.object(referencePool.address),
|
|
264
|
+
tx.object.clock()
|
|
265
|
+
],
|
|
266
|
+
typeArguments: [
|
|
267
|
+
targetBaseCoin.type,
|
|
268
|
+
targetQuoteCoin.type,
|
|
269
|
+
referenceBaseCoin.type,
|
|
270
|
+
referenceQuoteCoin.type
|
|
271
|
+
]
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* @description Claim rebates for a balance manager
|
|
276
|
+
* @param {string} poolKey The key to identify the pool
|
|
277
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
278
|
+
* @returns A function that takes a Transaction object
|
|
279
|
+
*/
|
|
280
|
+
this.claimRebates = (poolKey, balanceManagerKey) => (tx) => {
|
|
281
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
282
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
283
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
284
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
285
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
286
|
+
tx.moveCall({
|
|
287
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::claim_rebates`,
|
|
288
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
|
|
289
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* @description Mint a referral for a pool
|
|
294
|
+
* @param {string} poolKey The key to identify the pool
|
|
295
|
+
* @param {number} multiplier The multiplier for the referral
|
|
296
|
+
* @returns A function that takes a Transaction object
|
|
297
|
+
*/
|
|
298
|
+
this.mintReferral = (poolKey, multiplier) => (tx) => {
|
|
299
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
300
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
301
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
302
|
+
const adjustedNumber = Math.round(multiplier * FLOAT_SCALAR);
|
|
303
|
+
tx.moveCall({
|
|
304
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::mint_referral`,
|
|
305
|
+
arguments: [tx.object(pool.address), tx.pure.u64(adjustedNumber)],
|
|
306
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* @description Update the referral multiplier for a pool (DeepBookPoolReferral)
|
|
311
|
+
* @param {string} poolKey The key to identify the pool
|
|
312
|
+
* @param {string} referral The referral (DeepBookPoolReferral) to update
|
|
313
|
+
* @param {number} multiplier The multiplier for the referral
|
|
314
|
+
* @returns A function that takes a Transaction object
|
|
315
|
+
*/
|
|
316
|
+
this.updatePoolReferralMultiplier = (poolKey, referral, multiplier) => (tx) => {
|
|
317
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
318
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
319
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
320
|
+
const adjustedNumber = Math.round(multiplier * FLOAT_SCALAR);
|
|
321
|
+
tx.moveCall({
|
|
322
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::update_pool_referral_multiplier`,
|
|
323
|
+
arguments: [tx.object(pool.address), tx.object(referral), tx.pure.u64(adjustedNumber)],
|
|
324
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* @description Claim the rewards for a referral (DeepBookPoolReferral)
|
|
329
|
+
* @param {string} poolKey The key to identify the pool
|
|
330
|
+
* @param {string} referral The referral (DeepBookPoolReferral) to claim the rewards for
|
|
331
|
+
* @returns A function that takes a Transaction object
|
|
332
|
+
*/
|
|
333
|
+
this.claimPoolReferralRewards = (poolKey, referral) => (tx) => {
|
|
334
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
335
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
336
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
337
|
+
const [baseRewards, quoteRewards, deepRewards] = tx.moveCall({
|
|
338
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::claim_pool_referral_rewards`,
|
|
339
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
340
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
341
|
+
});
|
|
342
|
+
return { baseRewards, quoteRewards, deepRewards };
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* @description Update the allowed versions for a pool
|
|
346
|
+
* @param {string} poolKey The key of the pool to be updated
|
|
347
|
+
* @returns A function that takes a Transaction object
|
|
348
|
+
*/
|
|
349
|
+
this.updatePoolAllowedVersions = (poolKey) => (tx) => {
|
|
350
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
351
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
352
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
353
|
+
tx.moveCall({
|
|
354
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::update_pool_allowed_versions`,
|
|
355
|
+
arguments: [tx.object(pool.address), tx.object(__privateGet(this, _config).REGISTRY_ID)],
|
|
356
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* @description Gets an order
|
|
361
|
+
* @param {string} poolKey The key to identify the pool
|
|
362
|
+
* @param {string} orderId Order ID to get
|
|
363
|
+
* @returns A function that takes a Transaction object
|
|
364
|
+
*/
|
|
365
|
+
this.getOrder = (poolKey, orderId) => (tx) => {
|
|
366
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
367
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
368
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
369
|
+
tx.moveCall({
|
|
370
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order`,
|
|
371
|
+
arguments: [tx.object(pool.address), tx.pure.u128(orderId)],
|
|
372
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* @description Prepares a transaction to retrieve multiple orders from a specified pool.
|
|
377
|
+
* @param {string} poolKey - The identifier key for the pool to retrieve orders from.
|
|
378
|
+
* @param {string[]} orderIds - Array of order IDs to retrieve.
|
|
379
|
+
* @returns {Function} A function that takes a Transaction object
|
|
380
|
+
*/
|
|
381
|
+
this.getOrders = (poolKey, orderIds) => (tx) => {
|
|
382
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
383
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
384
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
385
|
+
tx.moveCall({
|
|
386
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_orders`,
|
|
387
|
+
arguments: [tx.object(pool.address), tx.pure.vector("u128", orderIds)],
|
|
388
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* @description Burn DEEP tokens from the pool
|
|
393
|
+
* @param {string} poolKey The key to identify the pool
|
|
394
|
+
* @returns A function that takes a Transaction object
|
|
395
|
+
*/
|
|
396
|
+
this.burnDeep = (poolKey) => (tx) => {
|
|
397
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
398
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
399
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
400
|
+
tx.moveCall({
|
|
401
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::burn_deep`,
|
|
402
|
+
arguments: [tx.object(pool.address), tx.object(__privateGet(this, _config).DEEP_TREASURY_ID)],
|
|
403
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* @description Get the mid price for a pool
|
|
408
|
+
* @param {string} poolKey The key to identify the pool
|
|
409
|
+
* @returns A function that takes a Transaction object
|
|
410
|
+
*/
|
|
411
|
+
this.midPrice = (poolKey) => (tx) => {
|
|
412
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
413
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
414
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
415
|
+
tx.moveCall({
|
|
416
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::mid_price`,
|
|
417
|
+
arguments: [tx.object(pool.address), tx.object.clock()],
|
|
418
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* @description Check if a pool is whitelisted
|
|
423
|
+
* @param {string} poolKey The key to identify the pool
|
|
424
|
+
* @returns A function that takes a Transaction object
|
|
425
|
+
*/
|
|
426
|
+
this.whitelisted = (poolKey) => (tx) => {
|
|
427
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
428
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
429
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
430
|
+
tx.moveCall({
|
|
431
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::whitelisted`,
|
|
432
|
+
arguments: [tx.object(pool.address)],
|
|
433
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* @description Get the quote quantity out for a given base quantity in
|
|
438
|
+
* @param {string} poolKey The key to identify the pool
|
|
439
|
+
* @param {number} baseQuantity Base quantity to convert
|
|
440
|
+
* @returns A function that takes a Transaction object
|
|
441
|
+
*/
|
|
442
|
+
this.getQuoteQuantityOut = (poolKey, baseQuantity) => (tx) => {
|
|
443
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
444
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
445
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
446
|
+
tx.moveCall({
|
|
447
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out`,
|
|
448
|
+
arguments: [
|
|
449
|
+
tx.object(pool.address),
|
|
450
|
+
tx.pure.u64(baseQuantity * baseCoin.scalar),
|
|
451
|
+
tx.object.clock()
|
|
452
|
+
],
|
|
453
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* @description Get the base quantity out for a given quote quantity in
|
|
458
|
+
* @param {string} poolKey The key to identify the pool
|
|
459
|
+
* @param {number} quoteQuantity Quote quantity to convert
|
|
460
|
+
* @returns A function that takes a Transaction object
|
|
461
|
+
*/
|
|
462
|
+
this.getBaseQuantityOut = (poolKey, quoteQuantity) => (tx) => {
|
|
463
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
464
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
465
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
466
|
+
const quoteScalar = quoteCoin.scalar;
|
|
467
|
+
tx.moveCall({
|
|
468
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out`,
|
|
469
|
+
arguments: [
|
|
470
|
+
tx.object(pool.address),
|
|
471
|
+
tx.pure.u64(quoteQuantity * quoteScalar),
|
|
472
|
+
tx.object.clock()
|
|
473
|
+
],
|
|
474
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* @description Get the quantity out for a given base or quote quantity
|
|
479
|
+
* @param {string} poolKey The key to identify the pool
|
|
480
|
+
* @param {number} baseQuantity Base quantity to convert
|
|
481
|
+
* @param {number} quoteQuantity Quote quantity to convert
|
|
482
|
+
* @returns A function that takes a Transaction object
|
|
483
|
+
*/
|
|
484
|
+
this.getQuantityOut = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
|
|
485
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
486
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
487
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
488
|
+
const quoteScalar = quoteCoin.scalar;
|
|
489
|
+
tx.moveCall({
|
|
490
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out`,
|
|
491
|
+
arguments: [
|
|
492
|
+
tx.object(pool.address),
|
|
493
|
+
tx.pure.u64(baseQuantity * baseCoin.scalar),
|
|
494
|
+
tx.pure.u64(quoteQuantity * quoteScalar),
|
|
495
|
+
tx.object.clock()
|
|
496
|
+
],
|
|
497
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* @description Get open orders for a balance manager in a pool
|
|
502
|
+
* @param {string} poolKey The key to identify the pool
|
|
503
|
+
* @param {string} managerKey Key of the balance manager
|
|
504
|
+
* @returns A function that takes a Transaction object
|
|
505
|
+
*/
|
|
506
|
+
this.accountOpenOrders = (poolKey, managerKey) => (tx) => {
|
|
507
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
508
|
+
const manager = __privateGet(this, _config).getBalanceManager(managerKey);
|
|
509
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
510
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
511
|
+
tx.moveCall({
|
|
512
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_open_orders`,
|
|
513
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
514
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* @description Get level 2 order book specifying range of price
|
|
519
|
+
* @param {string} poolKey The key to identify the pool
|
|
520
|
+
* @param {number} priceLow Lower bound of the price range
|
|
521
|
+
* @param {number} priceHigh Upper bound of the price range
|
|
522
|
+
* @param {boolean} isBid Whether to get bid or ask orders
|
|
523
|
+
* @returns A function that takes a Transaction object
|
|
524
|
+
*/
|
|
525
|
+
this.getLevel2Range = (poolKey, priceLow, priceHigh, isBid) => (tx) => {
|
|
526
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
527
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
528
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
529
|
+
tx.moveCall({
|
|
530
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_level2_range`,
|
|
531
|
+
arguments: [
|
|
532
|
+
tx.object(pool.address),
|
|
533
|
+
tx.pure.u64(priceLow * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar),
|
|
534
|
+
tx.pure.u64(priceHigh * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar),
|
|
535
|
+
tx.pure.bool(isBid),
|
|
536
|
+
tx.object.clock()
|
|
537
|
+
],
|
|
538
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* @description Get level 2 order book ticks from mid-price for a pool
|
|
543
|
+
* @param {string} poolKey The key to identify the pool
|
|
544
|
+
* @param {number} tickFromMid Number of ticks from mid-price
|
|
545
|
+
* @returns A function that takes a Transaction object
|
|
546
|
+
*/
|
|
547
|
+
this.getLevel2TicksFromMid = (poolKey, tickFromMid) => (tx) => {
|
|
548
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
549
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
550
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
551
|
+
tx.moveCall({
|
|
552
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_level2_ticks_from_mid`,
|
|
553
|
+
arguments: [tx.object(pool.address), tx.pure.u64(tickFromMid), tx.object.clock()],
|
|
554
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* @description Get the vault balances for a pool
|
|
559
|
+
* @param {string} poolKey The key to identify the pool
|
|
560
|
+
* @returns A function that takes a Transaction object
|
|
561
|
+
*/
|
|
562
|
+
this.vaultBalances = (poolKey) => (tx) => {
|
|
563
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
564
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
565
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
566
|
+
tx.moveCall({
|
|
567
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::vault_balances`,
|
|
568
|
+
arguments: [tx.object(pool.address)],
|
|
569
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* @description Get the pool ID by asset types
|
|
574
|
+
* @param {string} baseType Type of the base asset
|
|
575
|
+
* @param {string} quoteType Type of the quote asset
|
|
576
|
+
* @returns A function that takes a Transaction object
|
|
577
|
+
*/
|
|
578
|
+
this.getPoolIdByAssets = (baseType, quoteType) => (tx) => {
|
|
579
|
+
tx.moveCall({
|
|
580
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_pool_id_by_asset`,
|
|
581
|
+
arguments: [tx.object(__privateGet(this, _config).REGISTRY_ID)],
|
|
582
|
+
typeArguments: [baseType, quoteType]
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* @description Swap exact base amount for quote amount
|
|
587
|
+
* @param {SwapParams} params Parameters for the swap
|
|
588
|
+
* @returns A function that takes a Transaction object
|
|
589
|
+
*/
|
|
590
|
+
this.swapExactBaseForQuote = (params) => (tx) => {
|
|
591
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
592
|
+
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
593
|
+
if (params.quoteCoin) {
|
|
594
|
+
throw new Error("quoteCoin is not accepted for swapping base asset");
|
|
595
|
+
}
|
|
596
|
+
const { poolKey, amount: baseAmount, deepAmount, minOut: minQuote } = params;
|
|
597
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
598
|
+
const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
599
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
600
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
601
|
+
const baseCoinInput = params.baseCoin ?? coinWithBalance({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) });
|
|
602
|
+
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
|
|
603
|
+
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar);
|
|
604
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
605
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`,
|
|
606
|
+
arguments: [
|
|
607
|
+
tx.object(pool.address),
|
|
608
|
+
baseCoinInput,
|
|
609
|
+
deepCoin,
|
|
610
|
+
tx.pure.u64(minQuoteInput),
|
|
611
|
+
tx.object.clock()
|
|
612
|
+
],
|
|
613
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
614
|
+
});
|
|
615
|
+
return [baseCoinResult, quoteCoinResult, deepCoinResult];
|
|
616
|
+
};
|
|
617
|
+
/**
|
|
618
|
+
* @description Swap exact quote amount for base amount
|
|
619
|
+
* @param {SwapParams} params Parameters for the swap
|
|
620
|
+
* @returns A function that takes a Transaction object
|
|
621
|
+
*/
|
|
622
|
+
this.swapExactQuoteForBase = (params) => (tx) => {
|
|
623
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
624
|
+
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
625
|
+
if (params.baseCoin) {
|
|
626
|
+
throw new Error("baseCoin is not accepted for swapping quote asset");
|
|
627
|
+
}
|
|
628
|
+
const { poolKey, amount: quoteAmount, deepAmount, minOut: minBase } = params;
|
|
629
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
630
|
+
const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
631
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
632
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
633
|
+
const quoteCoinInput = params.quoteCoin ?? coinWithBalance({
|
|
634
|
+
type: quoteCoin.type,
|
|
635
|
+
balance: Math.round(quoteAmount * quoteCoin.scalar)
|
|
636
|
+
});
|
|
637
|
+
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
|
|
638
|
+
const minBaseInput = Math.round(minBase * baseCoin.scalar);
|
|
639
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
640
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`,
|
|
641
|
+
arguments: [
|
|
642
|
+
tx.object(pool.address),
|
|
643
|
+
quoteCoinInput,
|
|
644
|
+
deepCoin,
|
|
645
|
+
tx.pure.u64(minBaseInput),
|
|
646
|
+
tx.object.clock()
|
|
647
|
+
],
|
|
648
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
649
|
+
});
|
|
650
|
+
return [baseCoinResult, quoteCoinResult, deepCoinResult];
|
|
651
|
+
};
|
|
652
|
+
/**
|
|
653
|
+
* @description Swap exact quantity without a balance manager
|
|
654
|
+
* @param {SwapParams & {isBaseToCoin: boolean}} params Parameters for the swap
|
|
655
|
+
* @returns A function that takes a Transaction object
|
|
656
|
+
*/
|
|
657
|
+
this.swapExactQuantity = (params) => (tx) => {
|
|
658
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
659
|
+
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
660
|
+
const { poolKey, amount, deepAmount, minOut, baseCoin, quoteCoin, deepCoin, isBaseToCoin } = params;
|
|
661
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
662
|
+
const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
663
|
+
const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
664
|
+
const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
665
|
+
const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
|
|
666
|
+
type: baseCoinType.type,
|
|
667
|
+
balance: Math.round(amount * baseCoinType.scalar)
|
|
668
|
+
}) : coinWithBalance({ type: baseCoinType.type, balance: 0 });
|
|
669
|
+
const quoteCoinInput = isBaseToCoin ? coinWithBalance({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? coinWithBalance({
|
|
670
|
+
type: quoteCoinType.type,
|
|
671
|
+
balance: Math.round(amount * quoteCoinType.scalar)
|
|
672
|
+
});
|
|
673
|
+
const deepCoinInput = deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
|
|
674
|
+
const minOutInput = Math.round(
|
|
675
|
+
minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
|
|
676
|
+
);
|
|
677
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
678
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity`,
|
|
679
|
+
arguments: [
|
|
680
|
+
tx.object(pool.address),
|
|
681
|
+
baseCoinInput,
|
|
682
|
+
quoteCoinInput,
|
|
683
|
+
deepCoinInput,
|
|
684
|
+
tx.pure.u64(minOutInput),
|
|
685
|
+
tx.object.clock()
|
|
686
|
+
],
|
|
687
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
688
|
+
});
|
|
689
|
+
return [baseCoinResult, quoteCoinResult, deepCoinResult];
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* @description Swap exact base for quote with a balance manager
|
|
693
|
+
* @param {SwapWithManagerParams} params Parameters for the swap
|
|
694
|
+
* @returns A function that takes a Transaction object
|
|
695
|
+
*/
|
|
696
|
+
this.swapExactBaseForQuoteWithManager = (params) => (tx) => {
|
|
697
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
698
|
+
const {
|
|
699
|
+
poolKey,
|
|
700
|
+
balanceManagerKey,
|
|
701
|
+
tradeCap,
|
|
702
|
+
depositCap,
|
|
703
|
+
withdrawCap,
|
|
704
|
+
amount: baseAmount,
|
|
705
|
+
minOut: minQuote,
|
|
706
|
+
baseCoin
|
|
707
|
+
} = params;
|
|
708
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
709
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
710
|
+
const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
711
|
+
const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
712
|
+
const baseCoinInput = baseCoin ?? coinWithBalance({
|
|
713
|
+
type: baseCoinType.type,
|
|
714
|
+
balance: Math.round(baseAmount * baseCoinType.scalar)
|
|
715
|
+
});
|
|
716
|
+
const minQuoteInput = Math.round(minQuote * quoteCoinType.scalar);
|
|
717
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
718
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote_with_manager`,
|
|
719
|
+
arguments: [
|
|
720
|
+
tx.object(pool.address),
|
|
721
|
+
tx.object(balanceManager.address),
|
|
722
|
+
tx.object(tradeCap),
|
|
723
|
+
tx.object(depositCap),
|
|
724
|
+
tx.object(withdrawCap),
|
|
725
|
+
baseCoinInput,
|
|
726
|
+
tx.pure.u64(minQuoteInput),
|
|
727
|
+
tx.object.clock()
|
|
728
|
+
],
|
|
729
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
730
|
+
});
|
|
731
|
+
return [baseCoinResult, quoteCoinResult];
|
|
732
|
+
};
|
|
733
|
+
/**
|
|
734
|
+
* @description Swap exact quote for base with a balance manager
|
|
735
|
+
* @param {SwapWithManagerParams} params Parameters for the swap
|
|
736
|
+
* @returns A function that takes a Transaction object
|
|
737
|
+
*/
|
|
738
|
+
this.swapExactQuoteForBaseWithManager = (params) => (tx) => {
|
|
739
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
740
|
+
const {
|
|
741
|
+
poolKey,
|
|
742
|
+
balanceManagerKey,
|
|
743
|
+
tradeCap,
|
|
744
|
+
depositCap,
|
|
745
|
+
withdrawCap,
|
|
746
|
+
amount: quoteAmount,
|
|
747
|
+
minOut: minBase,
|
|
748
|
+
quoteCoin
|
|
749
|
+
} = params;
|
|
750
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
751
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
752
|
+
const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
753
|
+
const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
754
|
+
const quoteCoinInput = quoteCoin ?? coinWithBalance({
|
|
755
|
+
type: quoteCoinType.type,
|
|
756
|
+
balance: Math.round(quoteAmount * quoteCoinType.scalar)
|
|
757
|
+
});
|
|
758
|
+
const minBaseInput = Math.round(minBase * baseCoinType.scalar);
|
|
759
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
760
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base_with_manager`,
|
|
761
|
+
arguments: [
|
|
762
|
+
tx.object(pool.address),
|
|
763
|
+
tx.object(balanceManager.address),
|
|
764
|
+
tx.object(tradeCap),
|
|
765
|
+
tx.object(depositCap),
|
|
766
|
+
tx.object(withdrawCap),
|
|
767
|
+
quoteCoinInput,
|
|
768
|
+
tx.pure.u64(minBaseInput),
|
|
769
|
+
tx.object.clock()
|
|
770
|
+
],
|
|
771
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
772
|
+
});
|
|
773
|
+
return [baseCoinResult, quoteCoinResult];
|
|
774
|
+
};
|
|
775
|
+
/**
|
|
776
|
+
* @description Swap exact quantity (base or quote) with a balance manager
|
|
777
|
+
* @param {SwapWithManagerParams & {isBaseToCoin: boolean}} params Parameters for the swap
|
|
778
|
+
* @returns A function that takes a Transaction object
|
|
779
|
+
*/
|
|
780
|
+
this.swapExactQuantityWithManager = (params) => (tx) => {
|
|
781
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
782
|
+
const {
|
|
783
|
+
poolKey,
|
|
784
|
+
balanceManagerKey,
|
|
785
|
+
tradeCap,
|
|
786
|
+
depositCap,
|
|
787
|
+
withdrawCap,
|
|
788
|
+
amount,
|
|
789
|
+
minOut,
|
|
790
|
+
baseCoin,
|
|
791
|
+
quoteCoin,
|
|
792
|
+
isBaseToCoin
|
|
793
|
+
} = params;
|
|
794
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
795
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
796
|
+
const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
797
|
+
const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
798
|
+
const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
|
|
799
|
+
type: baseCoinType.type,
|
|
800
|
+
balance: Math.round(amount * baseCoinType.scalar)
|
|
801
|
+
}) : coinWithBalance({ type: baseCoinType.type, balance: 0 });
|
|
802
|
+
const quoteCoinInput = isBaseToCoin ? coinWithBalance({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? coinWithBalance({
|
|
803
|
+
type: quoteCoinType.type,
|
|
804
|
+
balance: Math.round(amount * quoteCoinType.scalar)
|
|
805
|
+
});
|
|
806
|
+
const minOutInput = Math.round(
|
|
807
|
+
minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
|
|
808
|
+
);
|
|
809
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
810
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity_with_manager`,
|
|
811
|
+
arguments: [
|
|
812
|
+
tx.object(pool.address),
|
|
813
|
+
tx.object(balanceManager.address),
|
|
814
|
+
tx.object(tradeCap),
|
|
815
|
+
tx.object(depositCap),
|
|
816
|
+
tx.object(withdrawCap),
|
|
817
|
+
baseCoinInput,
|
|
818
|
+
quoteCoinInput,
|
|
819
|
+
tx.pure.u64(minOutInput),
|
|
820
|
+
tx.object.clock()
|
|
821
|
+
],
|
|
822
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
823
|
+
});
|
|
824
|
+
return [baseCoinResult, quoteCoinResult];
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* @description Create a new pool permissionlessly
|
|
828
|
+
* @param {CreatePermissionlessPoolParams} params Parameters for creating permissionless pool
|
|
829
|
+
* @returns A function that takes a Transaction object
|
|
830
|
+
*/
|
|
831
|
+
this.createPermissionlessPool = (params) => (tx) => {
|
|
832
|
+
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
833
|
+
const { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, deepCoin } = params;
|
|
834
|
+
const baseCoin = __privateGet(this, _config).getCoin(baseCoinKey);
|
|
835
|
+
const quoteCoin = __privateGet(this, _config).getCoin(quoteCoinKey);
|
|
836
|
+
const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
837
|
+
const baseScalar = baseCoin.scalar;
|
|
838
|
+
const quoteScalar = quoteCoin.scalar;
|
|
839
|
+
const adjustedTickSize = Math.round(tickSize * FLOAT_SCALAR * quoteScalar / baseScalar);
|
|
840
|
+
const adjustedLotSize = Math.round(lotSize * baseScalar);
|
|
841
|
+
const adjustedMinSize = Math.round(minSize * baseScalar);
|
|
842
|
+
const deepCoinInput = deepCoin ?? coinWithBalance({
|
|
843
|
+
type: deepCoinType,
|
|
844
|
+
balance: POOL_CREATION_FEE_DEEP
|
|
845
|
+
});
|
|
846
|
+
tx.moveCall({
|
|
847
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::create_permissionless_pool`,
|
|
848
|
+
arguments: [
|
|
849
|
+
tx.object(__privateGet(this, _config).REGISTRY_ID),
|
|
850
|
+
// registry_id
|
|
851
|
+
tx.pure.u64(adjustedTickSize),
|
|
852
|
+
// adjusted tick_size
|
|
853
|
+
tx.pure.u64(adjustedLotSize),
|
|
854
|
+
// adjusted lot_size
|
|
855
|
+
tx.pure.u64(adjustedMinSize),
|
|
856
|
+
// adjusted min_size
|
|
857
|
+
deepCoinInput
|
|
858
|
+
],
|
|
859
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
860
|
+
});
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* @description Get the trade parameters for a given pool, including taker fee, maker fee, and stake required.
|
|
864
|
+
* @param {string} poolKey Key of the pool
|
|
865
|
+
* @returns A function that takes a Transaction object
|
|
866
|
+
*/
|
|
867
|
+
this.poolTradeParams = (poolKey) => (tx) => {
|
|
868
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
869
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
870
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
871
|
+
tx.moveCall({
|
|
872
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params`,
|
|
873
|
+
arguments: [tx.object(pool.address)],
|
|
874
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
875
|
+
});
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* @description Get the book parameters for a given pool, including tick size, lot size, and min size.
|
|
879
|
+
* @param {string} poolKey Key of the pool
|
|
880
|
+
* @returns A function that takes a Transaction object
|
|
881
|
+
*/
|
|
882
|
+
this.poolBookParams = (poolKey) => (tx) => {
|
|
883
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
884
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
885
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
886
|
+
tx.moveCall({
|
|
887
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_book_params`,
|
|
888
|
+
arguments: [tx.object(pool.address)],
|
|
889
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
890
|
+
});
|
|
891
|
+
};
|
|
892
|
+
/**
|
|
893
|
+
* @description Get the account information for a given pool and balance manager
|
|
894
|
+
* @param {string} poolKey Key of the pool
|
|
895
|
+
* @param {string} managerKey The key of the BalanceManager
|
|
896
|
+
* @returns A function that takes a Transaction object
|
|
897
|
+
*/
|
|
898
|
+
this.account = (poolKey, managerKey) => (tx) => {
|
|
899
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
900
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
901
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
902
|
+
const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
|
|
903
|
+
tx.moveCall({
|
|
904
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account`,
|
|
905
|
+
arguments: [tx.object(pool.address), tx.object(managerId)],
|
|
906
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
907
|
+
});
|
|
908
|
+
};
|
|
909
|
+
/**
|
|
910
|
+
* @description Get the locked balance for a given pool and balance manager
|
|
911
|
+
* @param {string} poolKey Key of the pool
|
|
912
|
+
* @param {string} managerKey The key of the BalanceManager
|
|
913
|
+
* @returns A function that takes a Transaction object
|
|
914
|
+
*/
|
|
915
|
+
this.lockedBalance = (poolKey, managerKey) => (tx) => {
|
|
916
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
917
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
918
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
919
|
+
const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
|
|
920
|
+
tx.moveCall({
|
|
921
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::locked_balance`,
|
|
922
|
+
arguments: [tx.object(pool.address), tx.object(managerId)],
|
|
923
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
924
|
+
});
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* @description Get the DEEP price conversion for a pool
|
|
928
|
+
* @param {string} poolKey The key to identify the pool
|
|
929
|
+
* @returns A function that takes a Transaction object
|
|
930
|
+
*/
|
|
931
|
+
this.getPoolDeepPrice = (poolKey) => (tx) => {
|
|
932
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
933
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
934
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
935
|
+
tx.moveCall({
|
|
936
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_price`,
|
|
937
|
+
arguments: [tx.object(pool.address)],
|
|
938
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
* @description Get the balance manager IDs for a given owner
|
|
943
|
+
* @param {string} owner The owner address to get balance manager IDs for
|
|
944
|
+
* @returns A function that takes a Transaction object
|
|
945
|
+
*/
|
|
946
|
+
this.getBalanceManagerIds = (owner) => (tx) => {
|
|
947
|
+
tx.moveCall({
|
|
948
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::registry::get_balance_manager_ids`,
|
|
949
|
+
arguments: [tx.object(__privateGet(this, _config).REGISTRY_ID), tx.pure.address(owner)]
|
|
950
|
+
});
|
|
951
|
+
};
|
|
952
|
+
/**
|
|
953
|
+
* @description Get the balances for a referral (DeepBookPoolReferral)
|
|
954
|
+
* @param {string} poolKey The key to identify the pool
|
|
955
|
+
* @param {string} referral The referral (DeepBookPoolReferral) to get the balances for
|
|
956
|
+
* @returns A function that takes a Transaction object
|
|
957
|
+
*/
|
|
958
|
+
this.getPoolReferralBalances = (poolKey, referral) => (tx) => {
|
|
959
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
960
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
961
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
962
|
+
return tx.moveCall({
|
|
963
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_pool_referral_balances`,
|
|
964
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
965
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
966
|
+
});
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* @description Get the multiplier for a referral (DeepBookPoolReferral)
|
|
970
|
+
* @param {string} poolKey The key to identify the pool
|
|
971
|
+
* @param {string} referral The referral (DeepBookPoolReferral) to get the multiplier for
|
|
972
|
+
* @returns A function that takes a Transaction object
|
|
973
|
+
*/
|
|
974
|
+
this.poolReferralMultiplier = (poolKey, referral) => (tx) => {
|
|
975
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
976
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
977
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
978
|
+
return tx.moveCall({
|
|
979
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_referral_multiplier`,
|
|
980
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
981
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* @description Check if a pool is a stable pool
|
|
986
|
+
* @param {string} poolKey The key to identify the pool
|
|
987
|
+
* @returns A function that takes a Transaction object
|
|
988
|
+
*/
|
|
989
|
+
this.stablePool = (poolKey) => (tx) => {
|
|
990
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
991
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
992
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
993
|
+
return tx.moveCall({
|
|
994
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stable_pool`,
|
|
995
|
+
arguments: [tx.object(pool.address)],
|
|
996
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
997
|
+
});
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* @description Check if a pool is registered
|
|
1001
|
+
* @param {string} poolKey The key to identify the pool
|
|
1002
|
+
* @returns A function that takes a Transaction object
|
|
1003
|
+
*/
|
|
1004
|
+
this.registeredPool = (poolKey) => (tx) => {
|
|
1005
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1006
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1007
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1008
|
+
return tx.moveCall({
|
|
1009
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::registered_pool`,
|
|
1010
|
+
arguments: [tx.object(pool.address)],
|
|
1011
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1012
|
+
});
|
|
1013
|
+
};
|
|
1014
|
+
/**
|
|
1015
|
+
* @description Get the quote quantity out for a given base quantity using input token as fee
|
|
1016
|
+
* @param {string} poolKey The key to identify the pool
|
|
1017
|
+
* @param {number} baseQuantity Base quantity to convert
|
|
1018
|
+
* @returns A function that takes a Transaction object
|
|
1019
|
+
*/
|
|
1020
|
+
this.getQuoteQuantityOutInputFee = (poolKey, baseQuantity) => (tx) => {
|
|
1021
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1022
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1023
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1024
|
+
return tx.moveCall({
|
|
1025
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out_input_fee`,
|
|
1026
|
+
arguments: [
|
|
1027
|
+
tx.object(pool.address),
|
|
1028
|
+
tx.pure.u64(baseQuantity * baseCoin.scalar),
|
|
1029
|
+
tx.object.clock()
|
|
1030
|
+
],
|
|
1031
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1032
|
+
});
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* @description Get the base quantity out for a given quote quantity using input token as fee
|
|
1036
|
+
* @param {string} poolKey The key to identify the pool
|
|
1037
|
+
* @param {number} quoteQuantity Quote quantity to convert
|
|
1038
|
+
* @returns A function that takes a Transaction object
|
|
1039
|
+
*/
|
|
1040
|
+
this.getBaseQuantityOutInputFee = (poolKey, quoteQuantity) => (tx) => {
|
|
1041
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1042
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1043
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1044
|
+
return tx.moveCall({
|
|
1045
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out_input_fee`,
|
|
1046
|
+
arguments: [
|
|
1047
|
+
tx.object(pool.address),
|
|
1048
|
+
tx.pure.u64(quoteQuantity * quoteCoin.scalar),
|
|
1049
|
+
tx.object.clock()
|
|
1050
|
+
],
|
|
1051
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1052
|
+
});
|
|
1053
|
+
};
|
|
1054
|
+
/**
|
|
1055
|
+
* @description Get the quantity out for a given base or quote quantity using input token as fee
|
|
1056
|
+
* @param {string} poolKey The key to identify the pool
|
|
1057
|
+
* @param {number} baseQuantity Base quantity to convert
|
|
1058
|
+
* @param {number} quoteQuantity Quote quantity to convert
|
|
1059
|
+
* @returns A function that takes a Transaction object
|
|
1060
|
+
*/
|
|
1061
|
+
this.getQuantityOutInputFee = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
|
|
1062
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1063
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1064
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1065
|
+
return tx.moveCall({
|
|
1066
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out_input_fee`,
|
|
1067
|
+
arguments: [
|
|
1068
|
+
tx.object(pool.address),
|
|
1069
|
+
tx.pure.u64(baseQuantity * baseCoin.scalar),
|
|
1070
|
+
tx.pure.u64(quoteQuantity * quoteCoin.scalar),
|
|
1071
|
+
tx.object.clock()
|
|
1072
|
+
],
|
|
1073
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1074
|
+
});
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* @description Get the base quantity needed to receive a target quote quantity
|
|
1078
|
+
* @param {string} poolKey The key to identify the pool
|
|
1079
|
+
* @param {number} targetQuoteQuantity Target quote quantity
|
|
1080
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
1081
|
+
* @returns A function that takes a Transaction object
|
|
1082
|
+
*/
|
|
1083
|
+
this.getBaseQuantityIn = (poolKey, targetQuoteQuantity, payWithDeep) => (tx) => {
|
|
1084
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1085
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1086
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1087
|
+
return tx.moveCall({
|
|
1088
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_in`,
|
|
1089
|
+
arguments: [
|
|
1090
|
+
tx.object(pool.address),
|
|
1091
|
+
tx.pure.u64(targetQuoteQuantity * quoteCoin.scalar),
|
|
1092
|
+
tx.pure.bool(payWithDeep),
|
|
1093
|
+
tx.object.clock()
|
|
1094
|
+
],
|
|
1095
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1096
|
+
});
|
|
1097
|
+
};
|
|
1098
|
+
/**
|
|
1099
|
+
* @description Get the quote quantity needed to receive a target base quantity
|
|
1100
|
+
* @param {string} poolKey The key to identify the pool
|
|
1101
|
+
* @param {number} targetBaseQuantity Target base quantity
|
|
1102
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
1103
|
+
* @returns A function that takes a Transaction object
|
|
1104
|
+
*/
|
|
1105
|
+
this.getQuoteQuantityIn = (poolKey, targetBaseQuantity, payWithDeep) => (tx) => {
|
|
1106
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1107
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1108
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1109
|
+
return tx.moveCall({
|
|
1110
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_in`,
|
|
1111
|
+
arguments: [
|
|
1112
|
+
tx.object(pool.address),
|
|
1113
|
+
tx.pure.u64(targetBaseQuantity * baseCoin.scalar),
|
|
1114
|
+
tx.pure.bool(payWithDeep),
|
|
1115
|
+
tx.object.clock()
|
|
1116
|
+
],
|
|
1117
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1118
|
+
});
|
|
1119
|
+
};
|
|
1120
|
+
/**
|
|
1121
|
+
* @description Get account order details for a balance manager
|
|
1122
|
+
* @param {string} poolKey The key to identify the pool
|
|
1123
|
+
* @param {string} managerKey Key of the balance manager
|
|
1124
|
+
* @returns A function that takes a Transaction object
|
|
1125
|
+
*/
|
|
1126
|
+
this.getAccountOrderDetails = (poolKey, managerKey) => (tx) => {
|
|
1127
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1128
|
+
const manager = __privateGet(this, _config).getBalanceManager(managerKey);
|
|
1129
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1130
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1131
|
+
return tx.moveCall({
|
|
1132
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
|
|
1133
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
1134
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
/**
|
|
1138
|
+
* @description Get the DEEP required for an order
|
|
1139
|
+
* @param {string} poolKey The key to identify the pool
|
|
1140
|
+
* @param {number} baseQuantity Base quantity
|
|
1141
|
+
* @param {number} price Price
|
|
1142
|
+
* @returns A function that takes a Transaction object
|
|
1143
|
+
*/
|
|
1144
|
+
this.getOrderDeepRequired = (poolKey, baseQuantity, price) => (tx) => {
|
|
1145
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1146
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1147
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1148
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
1149
|
+
const inputQuantity = Math.round(baseQuantity * baseCoin.scalar);
|
|
1150
|
+
return tx.moveCall({
|
|
1151
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_required`,
|
|
1152
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity), tx.pure.u64(inputPrice)],
|
|
1153
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1154
|
+
});
|
|
1155
|
+
};
|
|
1156
|
+
/**
|
|
1157
|
+
* @description Check if account exists for a balance manager
|
|
1158
|
+
* @param {string} poolKey The key to identify the pool
|
|
1159
|
+
* @param {string} managerKey Key of the balance manager
|
|
1160
|
+
* @returns A function that takes a Transaction object
|
|
1161
|
+
*/
|
|
1162
|
+
this.accountExists = (poolKey, managerKey) => (tx) => {
|
|
1163
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1164
|
+
const manager = __privateGet(this, _config).getBalanceManager(managerKey);
|
|
1165
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1166
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1167
|
+
return tx.moveCall({
|
|
1168
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_exists`,
|
|
1169
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
1170
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1171
|
+
});
|
|
1172
|
+
};
|
|
1173
|
+
/**
|
|
1174
|
+
* @description Get the next epoch trade parameters for a pool
|
|
1175
|
+
* @param {string} poolKey The key to identify the pool
|
|
1176
|
+
* @returns A function that takes a Transaction object
|
|
1177
|
+
*/
|
|
1178
|
+
this.poolTradeParamsNext = (poolKey) => (tx) => {
|
|
1179
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1180
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1181
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1182
|
+
return tx.moveCall({
|
|
1183
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params_next`,
|
|
1184
|
+
arguments: [tx.object(pool.address)],
|
|
1185
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1186
|
+
});
|
|
1187
|
+
};
|
|
1188
|
+
/**
|
|
1189
|
+
* @description Get the quorum for a pool
|
|
1190
|
+
* @param {string} poolKey The key to identify the pool
|
|
1191
|
+
* @returns A function that takes a Transaction object
|
|
1192
|
+
*/
|
|
1193
|
+
this.quorum = (poolKey) => (tx) => {
|
|
1194
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1195
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1196
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1197
|
+
return tx.moveCall({
|
|
1198
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::quorum`,
|
|
1199
|
+
arguments: [tx.object(pool.address)],
|
|
1200
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
/**
|
|
1204
|
+
* @description Get the pool ID
|
|
1205
|
+
* @param {string} poolKey The key to identify the pool
|
|
1206
|
+
* @returns A function that takes a Transaction object
|
|
1207
|
+
*/
|
|
1208
|
+
this.poolId = (poolKey) => (tx) => {
|
|
1209
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1210
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1211
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1212
|
+
return tx.moveCall({
|
|
1213
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::id`,
|
|
1214
|
+
arguments: [tx.object(pool.address)],
|
|
1215
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1216
|
+
});
|
|
1217
|
+
};
|
|
1218
|
+
/**
|
|
1219
|
+
* @description Check if a limit order can be placed
|
|
1220
|
+
* @param {CanPlaceLimitOrderParams} params Parameters for checking limit order validity
|
|
1221
|
+
* @returns A function that takes a Transaction object
|
|
1222
|
+
*/
|
|
1223
|
+
this.canPlaceLimitOrder = (params) => (tx) => {
|
|
1224
|
+
const { poolKey, balanceManagerKey, price, quantity, isBid, payWithDeep, expireTimestamp } = params;
|
|
1225
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1226
|
+
const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
1227
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1228
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1229
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
1230
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
1231
|
+
return tx.moveCall({
|
|
1232
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_limit_order`,
|
|
1233
|
+
arguments: [
|
|
1234
|
+
tx.object(pool.address),
|
|
1235
|
+
tx.object(manager.address),
|
|
1236
|
+
tx.pure.u64(inputPrice),
|
|
1237
|
+
tx.pure.u64(inputQuantity),
|
|
1238
|
+
tx.pure.bool(isBid),
|
|
1239
|
+
tx.pure.bool(payWithDeep),
|
|
1240
|
+
tx.pure.u64(expireTimestamp),
|
|
1241
|
+
tx.object.clock()
|
|
1242
|
+
],
|
|
1243
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* @description Check if a market order can be placed
|
|
1248
|
+
* @param {CanPlaceMarketOrderParams} params Parameters for checking market order validity
|
|
1249
|
+
* @returns A function that takes a Transaction object
|
|
1250
|
+
*/
|
|
1251
|
+
this.canPlaceMarketOrder = (params) => (tx) => {
|
|
1252
|
+
const { poolKey, balanceManagerKey, quantity, isBid, payWithDeep } = params;
|
|
1253
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1254
|
+
const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
1255
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1256
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1257
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
1258
|
+
return tx.moveCall({
|
|
1259
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_market_order`,
|
|
1260
|
+
arguments: [
|
|
1261
|
+
tx.object(pool.address),
|
|
1262
|
+
tx.object(manager.address),
|
|
1263
|
+
tx.pure.u64(inputQuantity),
|
|
1264
|
+
tx.pure.bool(isBid),
|
|
1265
|
+
tx.pure.bool(payWithDeep),
|
|
1266
|
+
tx.object.clock()
|
|
1267
|
+
],
|
|
1268
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1269
|
+
});
|
|
1270
|
+
};
|
|
1271
|
+
/**
|
|
1272
|
+
* @description Check if market order params are valid
|
|
1273
|
+
* @param {string} poolKey The key to identify the pool
|
|
1274
|
+
* @param {number} quantity Quantity
|
|
1275
|
+
* @returns A function that takes a Transaction object
|
|
1276
|
+
*/
|
|
1277
|
+
this.checkMarketOrderParams = (poolKey, quantity) => (tx) => {
|
|
1278
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1279
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1280
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1281
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
1282
|
+
return tx.moveCall({
|
|
1283
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_market_order_params`,
|
|
1284
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
1285
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1286
|
+
});
|
|
1287
|
+
};
|
|
1288
|
+
/**
|
|
1289
|
+
* @description Check if limit order params are valid
|
|
1290
|
+
* @param {string} poolKey The key to identify the pool
|
|
1291
|
+
* @param {number} price Price
|
|
1292
|
+
* @param {number} quantity Quantity
|
|
1293
|
+
* @param {number} expireTimestamp Expiration timestamp
|
|
1294
|
+
* @returns A function that takes a Transaction object
|
|
1295
|
+
*/
|
|
1296
|
+
this.checkLimitOrderParams = (poolKey, price, quantity, expireTimestamp) => (tx) => {
|
|
1297
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1298
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1299
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1300
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
1301
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
1302
|
+
return tx.moveCall({
|
|
1303
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_limit_order_params`,
|
|
1304
|
+
arguments: [
|
|
1305
|
+
tx.object(pool.address),
|
|
1306
|
+
tx.pure.u64(inputPrice),
|
|
1307
|
+
tx.pure.u64(inputQuantity),
|
|
1308
|
+
tx.pure.u64(expireTimestamp),
|
|
1309
|
+
tx.object.clock()
|
|
1310
|
+
],
|
|
1311
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
1312
|
+
});
|
|
1313
|
+
};
|
|
1314
|
+
__privateSet(this, _config, config);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
_config = new WeakMap();
|
|
1318
|
+
export {
|
|
1319
|
+
DeepBookContract
|
|
1320
|
+
};
|
|
1321
|
+
//# sourceMappingURL=deepbook.js.map
|