@haneullabs/deepbook-v3 0.1.0 → 1.0.11
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 +268 -81
- package/dist/client.d.mts +957 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +2293 -0
- package/dist/client.mjs.map +1 -0
- package/dist/contracts/deepbook/account.d.mts +38 -0
- package/dist/contracts/deepbook/account.d.mts.map +1 -0
- package/dist/contracts/deepbook/account.mjs +31 -0
- package/dist/contracts/deepbook/account.mjs.map +1 -0
- package/dist/contracts/deepbook/balances.d.mts +13 -0
- package/dist/contracts/deepbook/balances.d.mts.map +1 -0
- package/dist/contracts/deepbook/balances.mjs +24 -0
- package/dist/contracts/deepbook/balances.mjs.map +1 -0
- package/dist/contracts/deepbook/deep_price.d.mts +13 -0
- package/dist/contracts/deepbook/deep_price.d.mts.map +1 -0
- package/dist/contracts/deepbook/deep_price.mjs +49 -0
- package/dist/contracts/deepbook/deep_price.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/haneul/vec_set.d.mts +22 -0
- package/dist/contracts/deepbook/deps/haneul/vec_set.d.mts.map +1 -0
- package/dist/contracts/deepbook/deps/haneul/vec_set.mjs +26 -0
- package/dist/contracts/deepbook/deps/haneul/vec_set.mjs.map +1 -0
- package/dist/contracts/deepbook/order.d.mts +24 -0
- package/dist/contracts/deepbook/order.d.mts.map +1 -0
- package/dist/contracts/deepbook/order.mjs +63 -0
- package/dist/contracts/deepbook/order.mjs.map +1 -0
- package/dist/contracts/pyth/data_source.mjs +20 -0
- package/dist/contracts/pyth/data_source.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs +16 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs +16 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs +16 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs.map +1 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs +16 -0
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs.map +1 -0
- package/dist/contracts/pyth/i64.mjs +19 -0
- package/dist/contracts/pyth/i64.mjs.map +1 -0
- package/dist/contracts/pyth/price.mjs +22 -0
- package/dist/contracts/pyth/price.mjs.map +1 -0
- package/dist/contracts/pyth/price_feed.mjs +21 -0
- package/dist/contracts/pyth/price_feed.mjs.map +1 -0
- package/dist/contracts/pyth/price_identifier.mjs +16 -0
- package/dist/contracts/pyth/price_identifier.mjs.map +1 -0
- package/dist/contracts/pyth/price_info.mjs +28 -0
- package/dist/contracts/pyth/price_info.mjs.map +1 -0
- package/dist/contracts/pyth/state.mjs +36 -0
- package/dist/contracts/pyth/state.mjs.map +1 -0
- package/dist/contracts/utils/index.d.mts +34 -0
- package/dist/contracts/utils/index.d.mts.map +1 -0
- package/dist/contracts/utils/index.mjs +35 -0
- package/dist/contracts/utils/index.mjs.map +1 -0
- package/dist/contracts/wormhole/bytes32.mjs +16 -0
- package/dist/contracts/wormhole/bytes32.mjs.map +1 -0
- package/dist/contracts/wormhole/consumed_vaas.mjs +16 -0
- package/dist/contracts/wormhole/consumed_vaas.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +16 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
- package/dist/contracts/wormhole/external_address.mjs +16 -0
- package/dist/contracts/wormhole/external_address.mjs.map +1 -0
- package/dist/contracts/wormhole/fee_collector.mjs +20 -0
- package/dist/contracts/wormhole/fee_collector.mjs.map +1 -0
- package/dist/contracts/wormhole/set.mjs +16 -0
- package/dist/contracts/wormhole/set.mjs.map +1 -0
- package/dist/contracts/wormhole/state.mjs +31 -0
- package/dist/contracts/wormhole/state.mjs.map +1 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +26 -0
- package/dist/pyth/PriceServiceConnection.d.mts +26 -0
- package/dist/pyth/PriceServiceConnection.d.mts.map +1 -0
- package/dist/pyth/PriceServiceConnection.mjs +35 -0
- package/dist/pyth/PriceServiceConnection.mjs.map +1 -0
- package/dist/pyth/pyth-helpers.mjs +18 -0
- package/dist/pyth/pyth-helpers.mjs.map +1 -0
- package/dist/pyth/pyth.d.mts +69 -0
- package/dist/pyth/pyth.d.mts.map +1 -0
- package/dist/pyth/pyth.mjs +220 -0
- package/dist/pyth/pyth.mjs.map +1 -0
- package/dist/transactions/balanceManager.d.mts +174 -0
- package/dist/transactions/balanceManager.d.mts.map +1 -0
- package/dist/transactions/balanceManager.mjs +233 -0
- package/dist/transactions/balanceManager.mjs.map +1 -0
- package/dist/transactions/deepbook.d.mts +490 -0
- package/dist/transactions/deepbook.d.mts.map +1 -0
- package/dist/transactions/deepbook.mjs +978 -0
- package/dist/transactions/deepbook.mjs.map +1 -0
- package/dist/transactions/deepbookAdmin.d.mts +111 -0
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -0
- package/dist/transactions/deepbookAdmin.mjs +221 -0
- package/dist/transactions/deepbookAdmin.mjs.map +1 -0
- package/dist/transactions/flashLoans.d.mts +62 -0
- package/dist/transactions/flashLoans.d.mts.map +1 -0
- package/dist/transactions/flashLoans.mjs +75 -0
- package/dist/transactions/flashLoans.mjs.map +1 -0
- package/dist/transactions/governance.d.mts +48 -0
- package/dist/transactions/governance.d.mts.map +1 -0
- package/dist/transactions/governance.mjs +90 -0
- package/dist/transactions/governance.mjs.map +1 -0
- package/dist/transactions/marginAdmin.d.mts +139 -0
- package/dist/transactions/marginAdmin.d.mts.map +1 -0
- package/dist/transactions/marginAdmin.mjs +249 -0
- package/dist/transactions/marginAdmin.mjs.map +1 -0
- package/dist/transactions/marginLiquidations.d.mts +67 -0
- package/dist/transactions/marginLiquidations.d.mts.map +1 -0
- package/dist/transactions/marginLiquidations.mjs +109 -0
- package/dist/transactions/marginLiquidations.mjs.map +1 -0
- package/dist/transactions/marginMaintainer.d.mts +86 -0
- package/dist/transactions/marginMaintainer.d.mts.map +1 -0
- package/dist/transactions/marginMaintainer.mjs +160 -0
- package/dist/transactions/marginMaintainer.mjs.map +1 -0
- package/dist/transactions/marginManager.d.mts +255 -0
- package/dist/transactions/marginManager.d.mts.map +1 -0
- package/dist/transactions/marginManager.mjs +558 -0
- package/dist/transactions/marginManager.mjs.map +1 -0
- package/dist/transactions/marginPool.d.mts +140 -0
- package/dist/transactions/marginPool.d.mts.map +1 -0
- package/dist/transactions/marginPool.mjs +206 -0
- package/dist/transactions/marginPool.mjs.map +1 -0
- package/dist/transactions/marginRegistry.d.mts +100 -0
- package/dist/transactions/marginRegistry.d.mts.map +1 -0
- package/dist/transactions/marginRegistry.mjs +128 -0
- package/dist/transactions/marginRegistry.mjs.map +1 -0
- package/dist/transactions/marginTPSL.d.mts +100 -0
- package/dist/transactions/marginTPSL.d.mts.map +1 -0
- package/dist/transactions/marginTPSL.mjs +175 -0
- package/dist/transactions/marginTPSL.mjs.map +1 -0
- package/dist/transactions/poolProxy.d.mts +123 -0
- package/dist/transactions/poolProxy.d.mts.map +1 -0
- package/dist/transactions/poolProxy.mjs +336 -0
- package/dist/transactions/poolProxy.mjs.map +1 -0
- package/dist/types/bcs.d.mts +5 -0
- package/dist/types/bcs.mjs +7 -0
- package/dist/types/index.d.mts +237 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +18 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/utils/config.d.mts +82 -0
- package/dist/utils/config.d.mts.map +1 -0
- package/dist/utils/config.mjs +88 -0
- package/dist/utils/config.mjs.map +1 -0
- package/dist/utils/constants.d.mts +85 -0
- package/dist/utils/constants.d.mts.map +1 -0
- package/dist/utils/constants.mjs +384 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/errors.d.mts +46 -0
- package/dist/utils/errors.d.mts.map +1 -0
- package/dist/utils/errors.mjs +59 -0
- package/dist/utils/errors.mjs.map +1 -0
- package/dist/{cjs/utils/validation.d.ts → utils/validation.d.mts} +11 -7
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/validation.mjs +76 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +29 -26
- package/src/client.ts +1016 -545
- package/src/contracts/deepbook/account.ts +15 -15
- package/src/contracts/deepbook/balance_manager.ts +343 -57
- package/src/contracts/deepbook/balances.ts +3 -2
- package/src/contracts/deepbook/big_vector.ts +6 -7
- package/src/contracts/deepbook/book.ts +3 -2
- package/src/contracts/deepbook/constants.ts +95 -3
- package/src/contracts/deepbook/deep_price.ts +7 -7
- package/src/contracts/deepbook/deps/{sui → haneul}/bag.ts +8 -8
- package/src/contracts/deepbook/deps/{sui → haneul}/balance.ts +4 -3
- package/src/contracts/deepbook/deps/{sui → haneul}/table.ts +6 -6
- package/src/contracts/deepbook/deps/{sui → haneul}/vec_map.ts +4 -4
- package/src/contracts/deepbook/deps/{sui → haneul}/vec_set.ts +4 -4
- package/src/contracts/deepbook/deps/{sui → haneul}/versioned.ts +4 -4
- package/src/contracts/deepbook/deps/std/type_name.ts +3 -2
- package/src/contracts/deepbook/ewma.ts +14 -3
- package/src/contracts/deepbook/fill.ts +21 -21
- package/src/contracts/deepbook/governance.ts +4 -3
- package/src/contracts/deepbook/history.ts +4 -3
- package/src/contracts/deepbook/math.ts +15 -15
- package/src/contracts/deepbook/order.ts +16 -16
- package/src/contracts/deepbook/order_info.ts +39 -27
- package/src/contracts/deepbook/order_query.ts +12 -12
- package/src/contracts/deepbook/pool.ts +883 -526
- package/src/contracts/deepbook/registry.ts +149 -38
- package/src/contracts/deepbook/state.ts +14 -3
- package/src/contracts/deepbook/trade_params.ts +3 -2
- package/src/contracts/deepbook/vault.ts +5 -4
- package/src/contracts/pyth/batch_price_attestation.ts +92 -0
- package/src/contracts/pyth/contract_upgrade.ts +54 -0
- package/src/contracts/pyth/data_source.ts +64 -0
- package/src/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
- package/src/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts +13 -0
- package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.ts +12 -0
- package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.ts +13 -0
- package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.ts +13 -0
- package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.ts +12 -0
- package/src/contracts/pyth/deserialize.ts +117 -0
- package/src/contracts/pyth/event.ts +20 -0
- package/src/contracts/pyth/governance.ts +113 -0
- package/src/contracts/pyth/governance_action.ts +130 -0
- package/src/contracts/pyth/governance_instruction.ts +98 -0
- package/src/contracts/pyth/hot_potato_vector.ts +70 -0
- package/src/contracts/pyth/i64.ts +94 -0
- package/src/contracts/pyth/merkle_tree.ts +41 -0
- package/src/contracts/pyth/migrate.ts +29 -0
- package/src/contracts/pyth/price.ts +102 -0
- package/src/contracts/pyth/price_feed.ts +101 -0
- package/src/contracts/pyth/price_identifier.ts +46 -0
- package/src/contracts/pyth/price_info.ts +220 -0
- package/src/contracts/pyth/price_status.ts +74 -0
- package/src/contracts/pyth/pyth.ts +236 -0
- package/src/contracts/pyth/set.ts +93 -0
- package/src/contracts/pyth/set_data_sources.ts +14 -0
- package/src/contracts/pyth/set_fee_recipient.ts +13 -0
- package/src/contracts/pyth/set_governance_data_source.ts +16 -0
- package/src/contracts/pyth/set_stale_price_threshold.ts +13 -0
- package/src/contracts/pyth/set_update_fee.ts +14 -0
- package/src/contracts/pyth/setup.ts +12 -0
- package/src/contracts/pyth/state.ts +227 -0
- package/src/contracts/pyth/version_control.ts +25 -0
- package/src/contracts/utils/index.ts +100 -50
- package/src/contracts/wormhole/bytes32.ts +12 -0
- package/src/contracts/wormhole/consumed_vaas.ts +13 -0
- package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts +12 -0
- package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
- package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts +13 -0
- package/src/contracts/wormhole/external_address.ts +13 -0
- package/src/contracts/wormhole/fee_collector.ts +15 -0
- package/src/contracts/wormhole/set.ts +12 -0
- package/src/contracts/wormhole/state.ts +25 -0
- package/src/index.ts +17 -3
- package/src/pyth/pyth.ts +51 -50
- package/src/transactions/deepbook.ts +31 -12
- package/src/transactions/deepbookAdmin.ts +3 -3
- package/src/transactions/marginAdmin.ts +11 -8
- package/src/transactions/marginMaintainer.ts +23 -12
- package/src/transactions/marginManager.ts +104 -28
- package/src/transactions/marginPool.ts +5 -6
- package/src/transactions/marginTPSL.ts +5 -5
- package/src/transactions/poolProxy.ts +50 -0
- package/src/types/bcs.ts +1 -1
- package/src/types/index.ts +19 -2
- package/src/utils/config.ts +12 -14
- package/src/utils/constants.ts +44 -12
- package/src/utils/validation.ts +1 -1
- package/dist/cjs/client.d.ts +0 -861
- package/dist/cjs/client.js +0 -1982
- package/dist/cjs/client.js.map +0 -7
- package/dist/cjs/contracts/deepbook/account.d.ts +0 -105
- package/dist/cjs/contracts/deepbook/account.js +0 -163
- package/dist/cjs/contracts/deepbook/account.js.map +0 -7
- package/dist/cjs/contracts/deepbook/balance_manager.d.ts +0 -268
- package/dist/cjs/contracts/deepbook/balance_manager.js +0 -361
- package/dist/cjs/contracts/deepbook/balance_manager.js.map +0 -7
- package/dist/cjs/contracts/deepbook/balances.d.ts +0 -10
- package/dist/cjs/contracts/deepbook/balances.js +0 -35
- package/dist/cjs/contracts/deepbook/balances.js.map +0 -7
- package/dist/cjs/contracts/deepbook/big_vector.d.ts +0 -62
- package/dist/cjs/contracts/deepbook/big_vector.js +0 -80
- package/dist/cjs/contracts/deepbook/big_vector.js.map +0 -7
- package/dist/cjs/contracts/deepbook/book.d.ts +0 -34
- package/dist/cjs/contracts/deepbook/book.js +0 -50
- package/dist/cjs/contracts/deepbook/book.js.map +0 -7
- package/dist/cjs/contracts/deepbook/constants.d.ts +0 -176
- package/dist/cjs/contracts/deepbook/constants.js +0 -338
- package/dist/cjs/contracts/deepbook/constants.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deep_price.d.ts +0 -60
- package/dist/cjs/contracts/deepbook/deep_price.js +0 -87
- package/dist/cjs/contracts/deepbook/deep_price.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +0 -14
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js +0 -42
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +0 -33
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js +0 -47
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +0 -9
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js +0 -33
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +0 -5
- package/dist/cjs/contracts/deepbook/deps/sui/object.js +0 -33
- package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +0 -28
- package/dist/cjs/contracts/deepbook/deps/sui/table.js +0 -47
- package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +0 -27
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +0 -45
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +0 -15
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +0 -35
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +0 -7
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +0 -45
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +0 -7
- package/dist/cjs/contracts/deepbook/ewma.d.ts +0 -17
- package/dist/cjs/contracts/deepbook/ewma.js +0 -39
- package/dist/cjs/contracts/deepbook/ewma.js.map +0 -7
- package/dist/cjs/contracts/deepbook/fill.d.ts +0 -153
- package/dist/cjs/contracts/deepbook/fill.js +0 -251
- package/dist/cjs/contracts/deepbook/fill.js.map +0 -7
- package/dist/cjs/contracts/deepbook/governance.d.ts +0 -63
- package/dist/cjs/contracts/deepbook/governance.js +0 -79
- package/dist/cjs/contracts/deepbook/governance.js.map +0 -7
- package/dist/cjs/contracts/deepbook/history.d.ts +0 -60
- package/dist/cjs/contracts/deepbook/history.js +0 -78
- package/dist/cjs/contracts/deepbook/history.js.map +0 -7
- package/dist/cjs/contracts/deepbook/math.d.ts +0 -94
- package/dist/cjs/contracts/deepbook/math.js +0 -132
- package/dist/cjs/contracts/deepbook/math.js.map +0 -7
- package/dist/cjs/contracts/deepbook/order.d.ts +0 -135
- package/dist/cjs/contracts/deepbook/order.js +0 -218
- package/dist/cjs/contracts/deepbook/order.js.map +0 -7
- package/dist/cjs/contracts/deepbook/order_info.d.ts +0 -296
- package/dist/cjs/contracts/deepbook/order_info.js +0 -386
- package/dist/cjs/contracts/deepbook/order_info.js.map +0 -7
- package/dist/cjs/contracts/deepbook/order_query.d.ts +0 -85
- package/dist/cjs/contracts/deepbook/order_query.js +0 -96
- package/dist/cjs/contracts/deepbook/order_query.js.map +0 -7
- package/dist/cjs/contracts/deepbook/pool.d.ts +0 -1218
- package/dist/cjs/contracts/deepbook/pool.js +0 -1236
- package/dist/cjs/contracts/deepbook/pool.js.map +0 -7
- package/dist/cjs/contracts/deepbook/registry.d.ts +0 -134
- package/dist/cjs/contracts/deepbook/registry.js +0 -182
- package/dist/cjs/contracts/deepbook/registry.js.map +0 -7
- package/dist/cjs/contracts/deepbook/state.d.ts +0 -117
- package/dist/cjs/contracts/deepbook/state.js +0 -104
- package/dist/cjs/contracts/deepbook/state.js.map +0 -7
- package/dist/cjs/contracts/deepbook/trade_params.d.ts +0 -7
- package/dist/cjs/contracts/deepbook/trade_params.js +0 -35
- package/dist/cjs/contracts/deepbook/trade_params.js.map +0 -7
- package/dist/cjs/contracts/deepbook/vault.d.ts +0 -30
- package/dist/cjs/contracts/deepbook/vault.js +0 -65
- package/dist/cjs/contracts/deepbook/vault.js.map +0 -7
- package/dist/cjs/contracts/utils/index.d.ts +0 -25
- package/dist/cjs/contracts/utils/index.js +0 -148
- package/dist/cjs/contracts/utils/index.js.map +0 -7
- package/dist/cjs/index.d.ts +0 -23
- package/dist/cjs/index.js +0 -81
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/package.json +0 -4
- package/dist/cjs/pyth/PriceServiceConnection.d.ts +0 -26
- package/dist/cjs/pyth/PriceServiceConnection.js +0 -68
- package/dist/cjs/pyth/PriceServiceConnection.js.map +0 -7
- package/dist/cjs/pyth/pyth-helpers.d.ts +0 -7
- package/dist/cjs/pyth/pyth-helpers.js +0 -36
- package/dist/cjs/pyth/pyth-helpers.js.map +0 -7
- package/dist/cjs/pyth/pyth.d.ts +0 -65
- package/dist/cjs/pyth/pyth.js +0 -269
- package/dist/cjs/pyth/pyth.js.map +0 -7
- package/dist/cjs/transactions/balanceManager.d.ts +0 -168
- package/dist/cjs/transactions/balanceManager.js +0 -384
- package/dist/cjs/transactions/balanceManager.js.map +0 -7
- package/dist/cjs/transactions/deepbook.d.ts +0 -477
- package/dist/cjs/transactions/deepbook.js +0 -1335
- package/dist/cjs/transactions/deepbook.js.map +0 -7
- package/dist/cjs/transactions/deepbookAdmin.d.ts +0 -105
- package/dist/cjs/transactions/deepbookAdmin.js +0 -334
- package/dist/cjs/transactions/deepbookAdmin.js.map +0 -7
- package/dist/cjs/transactions/flashLoans.d.ts +0 -56
- package/dist/cjs/transactions/flashLoans.js +0 -124
- package/dist/cjs/transactions/flashLoans.js.map +0 -7
- package/dist/cjs/transactions/governance.d.ts +0 -42
- package/dist/cjs/transactions/governance.js +0 -135
- package/dist/cjs/transactions/governance.js.map +0 -7
- package/dist/cjs/transactions/marginAdmin.d.ts +0 -133
- package/dist/cjs/transactions/marginAdmin.js +0 -393
- package/dist/cjs/transactions/marginAdmin.js.map +0 -7
- package/dist/cjs/transactions/marginLiquidations.d.ts +0 -61
- package/dist/cjs/transactions/marginLiquidations.js +0 -173
- package/dist/cjs/transactions/marginLiquidations.js.map +0 -7
- package/dist/cjs/transactions/marginMaintainer.d.ts +0 -80
- package/dist/cjs/transactions/marginMaintainer.js +0 -251
- package/dist/cjs/transactions/marginMaintainer.js.map +0 -7
- package/dist/cjs/transactions/marginManager.d.ts +0 -236
- package/dist/cjs/transactions/marginManager.js +0 -688
- package/dist/cjs/transactions/marginManager.js.map +0 -7
- package/dist/cjs/transactions/marginPool.d.ts +0 -134
- package/dist/cjs/transactions/marginPool.js +0 -330
- package/dist/cjs/transactions/marginPool.js.map +0 -7
- package/dist/cjs/transactions/marginRegistry.d.ts +0 -94
- package/dist/cjs/transactions/marginRegistry.js +0 -221
- package/dist/cjs/transactions/marginRegistry.js.map +0 -7
- package/dist/cjs/transactions/marginTPSL.d.ts +0 -93
- package/dist/cjs/transactions/marginTPSL.js +0 -286
- package/dist/cjs/transactions/marginTPSL.js.map +0 -7
- package/dist/cjs/transactions/poolProxy.d.ts +0 -104
- package/dist/cjs/transactions/poolProxy.js +0 -435
- package/dist/cjs/transactions/poolProxy.js.map +0 -7
- package/dist/cjs/types/bcs.d.ts +0 -5
- package/dist/cjs/types/bcs.js +0 -33
- package/dist/cjs/types/bcs.js.map +0 -7
- package/dist/cjs/types/index.d.ts +0 -218
- package/dist/cjs/types/index.js +0 -38
- package/dist/cjs/types/index.js.map +0 -7
- package/dist/cjs/utils/config.d.ts +0 -65
- package/dist/cjs/utils/config.js +0 -144
- package/dist/cjs/utils/config.js.map +0 -7
- package/dist/cjs/utils/constants.d.ts +0 -76
- package/dist/cjs/utils/constants.js +0 -382
- package/dist/cjs/utils/constants.js.map +0 -7
- package/dist/cjs/utils/errors.d.ts +0 -42
- package/dist/cjs/utils/errors.js +0 -70
- package/dist/cjs/utils/errors.js.map +0 -7
- package/dist/cjs/utils/validation.js +0 -67
- package/dist/cjs/utils/validation.js.map +0 -7
- package/dist/esm/client.d.ts +0 -861
- package/dist/esm/client.js +0 -1967
- package/dist/esm/client.js.map +0 -7
- package/dist/esm/contracts/deepbook/account.d.ts +0 -105
- package/dist/esm/contracts/deepbook/account.js +0 -133
- package/dist/esm/contracts/deepbook/account.js.map +0 -7
- package/dist/esm/contracts/deepbook/balance_manager.d.ts +0 -268
- package/dist/esm/contracts/deepbook/balance_manager.js +0 -331
- package/dist/esm/contracts/deepbook/balance_manager.js.map +0 -7
- package/dist/esm/contracts/deepbook/balances.d.ts +0 -10
- package/dist/esm/contracts/deepbook/balances.js +0 -15
- package/dist/esm/contracts/deepbook/balances.js.map +0 -7
- package/dist/esm/contracts/deepbook/big_vector.d.ts +0 -62
- package/dist/esm/contracts/deepbook/big_vector.js +0 -50
- package/dist/esm/contracts/deepbook/big_vector.js.map +0 -7
- package/dist/esm/contracts/deepbook/book.d.ts +0 -34
- package/dist/esm/contracts/deepbook/book.js +0 -20
- package/dist/esm/contracts/deepbook/book.js.map +0 -7
- package/dist/esm/contracts/deepbook/constants.d.ts +0 -176
- package/dist/esm/contracts/deepbook/constants.js +0 -318
- package/dist/esm/contracts/deepbook/constants.js.map +0 -7
- package/dist/esm/contracts/deepbook/deep_price.d.ts +0 -60
- package/dist/esm/contracts/deepbook/deep_price.js +0 -67
- package/dist/esm/contracts/deepbook/deep_price.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +0 -14
- package/dist/esm/contracts/deepbook/deps/std/type_name.js +0 -22
- package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +0 -33
- package/dist/esm/contracts/deepbook/deps/sui/bag.js +0 -17
- package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +0 -9
- package/dist/esm/contracts/deepbook/deps/sui/balance.js +0 -13
- package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +0 -5
- package/dist/esm/contracts/deepbook/deps/sui/object.js +0 -13
- package/dist/esm/contracts/deepbook/deps/sui/object.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +0 -28
- package/dist/esm/contracts/deepbook/deps/sui/table.js +0 -17
- package/dist/esm/contracts/deepbook/deps/sui/table.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +0 -27
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +0 -25
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +0 -15
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +0 -15
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +0 -7
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js +0 -15
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +0 -7
- package/dist/esm/contracts/deepbook/ewma.d.ts +0 -17
- package/dist/esm/contracts/deepbook/ewma.js +0 -19
- package/dist/esm/contracts/deepbook/ewma.js.map +0 -7
- package/dist/esm/contracts/deepbook/fill.d.ts +0 -153
- package/dist/esm/contracts/deepbook/fill.js +0 -221
- package/dist/esm/contracts/deepbook/fill.js.map +0 -7
- package/dist/esm/contracts/deepbook/governance.d.ts +0 -63
- package/dist/esm/contracts/deepbook/governance.js +0 -49
- package/dist/esm/contracts/deepbook/governance.js.map +0 -7
- package/dist/esm/contracts/deepbook/history.d.ts +0 -60
- package/dist/esm/contracts/deepbook/history.js +0 -48
- package/dist/esm/contracts/deepbook/history.js.map +0 -7
- package/dist/esm/contracts/deepbook/math.d.ts +0 -94
- package/dist/esm/contracts/deepbook/math.js +0 -112
- package/dist/esm/contracts/deepbook/math.js.map +0 -7
- package/dist/esm/contracts/deepbook/order.d.ts +0 -135
- package/dist/esm/contracts/deepbook/order.js +0 -188
- package/dist/esm/contracts/deepbook/order.js.map +0 -7
- package/dist/esm/contracts/deepbook/order_info.d.ts +0 -296
- package/dist/esm/contracts/deepbook/order_info.js +0 -356
- package/dist/esm/contracts/deepbook/order_info.js.map +0 -7
- package/dist/esm/contracts/deepbook/order_query.d.ts +0 -85
- package/dist/esm/contracts/deepbook/order_query.js +0 -66
- package/dist/esm/contracts/deepbook/order_query.js.map +0 -7
- package/dist/esm/contracts/deepbook/pool.d.ts +0 -1218
- package/dist/esm/contracts/deepbook/pool.js +0 -1206
- package/dist/esm/contracts/deepbook/pool.js.map +0 -7
- package/dist/esm/contracts/deepbook/registry.d.ts +0 -134
- package/dist/esm/contracts/deepbook/registry.js +0 -152
- package/dist/esm/contracts/deepbook/registry.js.map +0 -7
- package/dist/esm/contracts/deepbook/state.d.ts +0 -117
- package/dist/esm/contracts/deepbook/state.js +0 -74
- package/dist/esm/contracts/deepbook/state.js.map +0 -7
- package/dist/esm/contracts/deepbook/trade_params.d.ts +0 -7
- package/dist/esm/contracts/deepbook/trade_params.js +0 -15
- package/dist/esm/contracts/deepbook/trade_params.js.map +0 -7
- package/dist/esm/contracts/deepbook/vault.d.ts +0 -30
- package/dist/esm/contracts/deepbook/vault.js +0 -35
- package/dist/esm/contracts/deepbook/vault.js.map +0 -7
- package/dist/esm/contracts/utils/index.d.ts +0 -25
- package/dist/esm/contracts/utils/index.js +0 -128
- package/dist/esm/contracts/utils/index.js.map +0 -7
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -81
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/package.json +0 -4
- package/dist/esm/pyth/PriceServiceConnection.d.ts +0 -26
- package/dist/esm/pyth/PriceServiceConnection.js +0 -38
- package/dist/esm/pyth/PriceServiceConnection.js.map +0 -7
- package/dist/esm/pyth/pyth-helpers.d.ts +0 -7
- package/dist/esm/pyth/pyth-helpers.js +0 -16
- package/dist/esm/pyth/pyth-helpers.js.map +0 -7
- package/dist/esm/pyth/pyth.d.ts +0 -65
- package/dist/esm/pyth/pyth.js +0 -249
- package/dist/esm/pyth/pyth.js.map +0 -7
- package/dist/esm/transactions/balanceManager.d.ts +0 -168
- package/dist/esm/transactions/balanceManager.js +0 -364
- package/dist/esm/transactions/balanceManager.js.map +0 -7
- package/dist/esm/transactions/deepbook.d.ts +0 -477
- package/dist/esm/transactions/deepbook.js +0 -1321
- package/dist/esm/transactions/deepbook.js.map +0 -7
- package/dist/esm/transactions/deepbookAdmin.d.ts +0 -105
- package/dist/esm/transactions/deepbookAdmin.js +0 -314
- package/dist/esm/transactions/deepbookAdmin.js.map +0 -7
- package/dist/esm/transactions/flashLoans.d.ts +0 -56
- package/dist/esm/transactions/flashLoans.js +0 -104
- package/dist/esm/transactions/flashLoans.js.map +0 -7
- package/dist/esm/transactions/governance.d.ts +0 -42
- package/dist/esm/transactions/governance.js +0 -115
- package/dist/esm/transactions/governance.js.map +0 -7
- package/dist/esm/transactions/marginAdmin.d.ts +0 -133
- package/dist/esm/transactions/marginAdmin.js +0 -373
- package/dist/esm/transactions/marginAdmin.js.map +0 -7
- package/dist/esm/transactions/marginLiquidations.d.ts +0 -61
- package/dist/esm/transactions/marginLiquidations.js +0 -153
- package/dist/esm/transactions/marginLiquidations.js.map +0 -7
- package/dist/esm/transactions/marginMaintainer.d.ts +0 -80
- package/dist/esm/transactions/marginMaintainer.js +0 -231
- package/dist/esm/transactions/marginMaintainer.js.map +0 -7
- package/dist/esm/transactions/marginManager.d.ts +0 -236
- package/dist/esm/transactions/marginManager.js +0 -668
- package/dist/esm/transactions/marginManager.js.map +0 -7
- package/dist/esm/transactions/marginPool.d.ts +0 -134
- package/dist/esm/transactions/marginPool.js +0 -310
- package/dist/esm/transactions/marginPool.js.map +0 -7
- package/dist/esm/transactions/marginRegistry.d.ts +0 -94
- package/dist/esm/transactions/marginRegistry.js +0 -201
- package/dist/esm/transactions/marginRegistry.js.map +0 -7
- package/dist/esm/transactions/marginTPSL.d.ts +0 -93
- package/dist/esm/transactions/marginTPSL.js +0 -266
- package/dist/esm/transactions/marginTPSL.js.map +0 -7
- package/dist/esm/transactions/poolProxy.d.ts +0 -104
- package/dist/esm/transactions/poolProxy.js +0 -415
- package/dist/esm/transactions/poolProxy.js.map +0 -7
- package/dist/esm/types/bcs.d.ts +0 -5
- package/dist/esm/types/bcs.js +0 -13
- package/dist/esm/types/bcs.js.map +0 -7
- package/dist/esm/types/index.d.ts +0 -218
- package/dist/esm/types/index.js +0 -18
- package/dist/esm/types/index.js.map +0 -7
- package/dist/esm/utils/config.d.ts +0 -65
- package/dist/esm/utils/config.js +0 -135
- package/dist/esm/utils/config.js.map +0 -7
- package/dist/esm/utils/constants.d.ts +0 -76
- package/dist/esm/utils/constants.js +0 -362
- package/dist/esm/utils/constants.js.map +0 -7
- package/dist/esm/utils/errors.d.ts +0 -42
- package/dist/esm/utils/errors.js +0 -50
- package/dist/esm/utils/errors.js.map +0 -7
- package/dist/esm/utils/validation.d.ts +0 -50
- package/dist/esm/utils/validation.js +0 -47
- package/dist/esm/utils/validation.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/contracts/deepbook/deps/sui/object.ts +0 -14
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
import { OrderType, SelfMatchingOptions } from "../types/index.mjs";
|
|
2
|
+
import { DEEP_SCALAR, FLOAT_SCALAR, GAS_BUDGET, MAX_TIMESTAMP, POOL_CREATION_FEE_DEEP } from "../utils/config.mjs";
|
|
3
|
+
import { coinWithBalance } from "@haneullabs/haneul/transactions";
|
|
4
|
+
|
|
5
|
+
//#region src/transactions/deepbook.ts
|
|
6
|
+
/**
|
|
7
|
+
* DeepBookContract class for managing DeepBook operations.
|
|
8
|
+
*/
|
|
9
|
+
var DeepBookContract = class {
|
|
10
|
+
#config;
|
|
11
|
+
/**
|
|
12
|
+
* @param {DeepBookConfig} config Configuration for DeepBookContract
|
|
13
|
+
*/
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.placeLimitOrder = (params) => (tx) => {
|
|
16
|
+
const { poolKey, balanceManagerKey, clientOrderId, price, quantity, isBid, expiration = MAX_TIMESTAMP, orderType = OrderType.NO_RESTRICTION, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
17
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
18
|
+
const pool = this.#config.getPool(poolKey);
|
|
19
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
20
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
21
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
22
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
23
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
24
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
25
|
+
tx.moveCall({
|
|
26
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::place_limit_order`,
|
|
27
|
+
arguments: [
|
|
28
|
+
tx.object(pool.address),
|
|
29
|
+
tx.object(balanceManager.address),
|
|
30
|
+
tradeProof,
|
|
31
|
+
tx.pure.u64(clientOrderId),
|
|
32
|
+
tx.pure.u8(orderType),
|
|
33
|
+
tx.pure.u8(selfMatchingOption),
|
|
34
|
+
tx.pure.u64(inputPrice),
|
|
35
|
+
tx.pure.u64(inputQuantity),
|
|
36
|
+
tx.pure.bool(isBid),
|
|
37
|
+
tx.pure.bool(payWithDeep),
|
|
38
|
+
tx.pure.u64(expiration),
|
|
39
|
+
tx.object.clock()
|
|
40
|
+
],
|
|
41
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
this.placeMarketOrder = (params) => (tx) => {
|
|
45
|
+
const { poolKey, balanceManagerKey, clientOrderId, quantity, isBid, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
46
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
47
|
+
const pool = this.#config.getPool(poolKey);
|
|
48
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
49
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
50
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
51
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
52
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
53
|
+
tx.moveCall({
|
|
54
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::place_market_order`,
|
|
55
|
+
arguments: [
|
|
56
|
+
tx.object(pool.address),
|
|
57
|
+
tx.object(balanceManager.address),
|
|
58
|
+
tradeProof,
|
|
59
|
+
tx.pure.u64(clientOrderId),
|
|
60
|
+
tx.pure.u8(selfMatchingOption),
|
|
61
|
+
tx.pure.u64(inputQuantity),
|
|
62
|
+
tx.pure.bool(isBid),
|
|
63
|
+
tx.pure.bool(payWithDeep),
|
|
64
|
+
tx.object.clock()
|
|
65
|
+
],
|
|
66
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
this.modifyOrder = (poolKey, balanceManagerKey, orderId, newQuantity) => (tx) => {
|
|
70
|
+
const pool = this.#config.getPool(poolKey);
|
|
71
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
72
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
73
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
74
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
75
|
+
const inputQuantity = Math.round(newQuantity * baseCoin.scalar);
|
|
76
|
+
tx.moveCall({
|
|
77
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::modify_order`,
|
|
78
|
+
arguments: [
|
|
79
|
+
tx.object(pool.address),
|
|
80
|
+
tx.object(balanceManager.address),
|
|
81
|
+
tradeProof,
|
|
82
|
+
tx.pure.u128(orderId),
|
|
83
|
+
tx.pure.u64(inputQuantity),
|
|
84
|
+
tx.object.clock()
|
|
85
|
+
],
|
|
86
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
this.cancelOrder = (poolKey, balanceManagerKey, orderId) => (tx) => {
|
|
90
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
91
|
+
const pool = this.#config.getPool(poolKey);
|
|
92
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
93
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
94
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
95
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
96
|
+
tx.moveCall({
|
|
97
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::cancel_order`,
|
|
98
|
+
arguments: [
|
|
99
|
+
tx.object(pool.address),
|
|
100
|
+
tx.object(balanceManager.address),
|
|
101
|
+
tradeProof,
|
|
102
|
+
tx.pure.u128(orderId),
|
|
103
|
+
tx.object.clock()
|
|
104
|
+
],
|
|
105
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
this.cancelOrders = (poolKey, balanceManagerKey, orderIds) => (tx) => {
|
|
109
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
110
|
+
const pool = this.#config.getPool(poolKey);
|
|
111
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
112
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
113
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
114
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
115
|
+
tx.moveCall({
|
|
116
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::cancel_orders`,
|
|
117
|
+
arguments: [
|
|
118
|
+
tx.object(pool.address),
|
|
119
|
+
tx.object(balanceManager.address),
|
|
120
|
+
tradeProof,
|
|
121
|
+
tx.pure.vector("u128", orderIds),
|
|
122
|
+
tx.object.clock()
|
|
123
|
+
],
|
|
124
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
this.cancelAllOrders = (poolKey, balanceManagerKey) => (tx) => {
|
|
128
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
129
|
+
const pool = this.#config.getPool(poolKey);
|
|
130
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
131
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
132
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
133
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
134
|
+
tx.moveCall({
|
|
135
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::cancel_all_orders`,
|
|
136
|
+
arguments: [
|
|
137
|
+
tx.object(pool.address),
|
|
138
|
+
tx.object(balanceManager.address),
|
|
139
|
+
tradeProof,
|
|
140
|
+
tx.object.clock()
|
|
141
|
+
],
|
|
142
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
this.withdrawSettledAmounts = (poolKey, balanceManagerKey) => (tx) => {
|
|
146
|
+
const pool = this.#config.getPool(poolKey);
|
|
147
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
148
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
149
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
150
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
151
|
+
tx.moveCall({
|
|
152
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts`,
|
|
153
|
+
arguments: [
|
|
154
|
+
tx.object(pool.address),
|
|
155
|
+
tx.object(balanceManager.address),
|
|
156
|
+
tradeProof
|
|
157
|
+
],
|
|
158
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
this.withdrawSettledAmountsPermissionless = (poolKey, balanceManagerKey) => (tx) => {
|
|
162
|
+
const pool = this.#config.getPool(poolKey);
|
|
163
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
164
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
165
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
166
|
+
tx.moveCall({
|
|
167
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
|
|
168
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address)],
|
|
169
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
this.withdrawSettledAmountsManagerID = (poolKey, balanceManagerId) => (tx) => {
|
|
173
|
+
const pool = this.#config.getPool(poolKey);
|
|
174
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
175
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
176
|
+
tx.moveCall({
|
|
177
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
|
|
178
|
+
arguments: [tx.object(pool.address), tx.object(balanceManagerId)],
|
|
179
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
this.addDeepPricePoint = (targetPoolKey, referencePoolKey) => (tx) => {
|
|
183
|
+
const targetPool = this.#config.getPool(targetPoolKey);
|
|
184
|
+
const referencePool = this.#config.getPool(referencePoolKey);
|
|
185
|
+
const targetBaseCoin = this.#config.getCoin(targetPool.baseCoin);
|
|
186
|
+
const targetQuoteCoin = this.#config.getCoin(targetPool.quoteCoin);
|
|
187
|
+
const referenceBaseCoin = this.#config.getCoin(referencePool.baseCoin);
|
|
188
|
+
const referenceQuoteCoin = this.#config.getCoin(referencePool.quoteCoin);
|
|
189
|
+
tx.moveCall({
|
|
190
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::add_deep_price_point`,
|
|
191
|
+
arguments: [
|
|
192
|
+
tx.object(targetPool.address),
|
|
193
|
+
tx.object(referencePool.address),
|
|
194
|
+
tx.object.clock()
|
|
195
|
+
],
|
|
196
|
+
typeArguments: [
|
|
197
|
+
targetBaseCoin.type,
|
|
198
|
+
targetQuoteCoin.type,
|
|
199
|
+
referenceBaseCoin.type,
|
|
200
|
+
referenceQuoteCoin.type
|
|
201
|
+
]
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
this.claimRebates = (poolKey, balanceManagerKey) => (tx) => {
|
|
205
|
+
const pool = this.#config.getPool(poolKey);
|
|
206
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
207
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
208
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
209
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
210
|
+
tx.moveCall({
|
|
211
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::claim_rebates`,
|
|
212
|
+
arguments: [
|
|
213
|
+
tx.object(pool.address),
|
|
214
|
+
tx.object(balanceManager.address),
|
|
215
|
+
tradeProof
|
|
216
|
+
],
|
|
217
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
this.mintReferral = (poolKey, multiplier) => (tx) => {
|
|
221
|
+
const pool = this.#config.getPool(poolKey);
|
|
222
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
223
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
224
|
+
const adjustedNumber = Math.round(multiplier * FLOAT_SCALAR);
|
|
225
|
+
tx.moveCall({
|
|
226
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::mint_referral`,
|
|
227
|
+
arguments: [tx.object(pool.address), tx.pure.u64(adjustedNumber)],
|
|
228
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
this.updatePoolReferralMultiplier = (poolKey, referral, multiplier) => (tx) => {
|
|
232
|
+
const pool = this.#config.getPool(poolKey);
|
|
233
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
234
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
235
|
+
const adjustedNumber = Math.round(multiplier * FLOAT_SCALAR);
|
|
236
|
+
tx.moveCall({
|
|
237
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::update_pool_referral_multiplier`,
|
|
238
|
+
arguments: [
|
|
239
|
+
tx.object(pool.address),
|
|
240
|
+
tx.object(referral),
|
|
241
|
+
tx.pure.u64(adjustedNumber)
|
|
242
|
+
],
|
|
243
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
this.claimPoolReferralRewards = (poolKey, referral) => (tx) => {
|
|
247
|
+
const pool = this.#config.getPool(poolKey);
|
|
248
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
249
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
250
|
+
const [baseRewards, quoteRewards, deepRewards] = tx.moveCall({
|
|
251
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::claim_pool_referral_rewards`,
|
|
252
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
253
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
baseRewards,
|
|
257
|
+
quoteRewards,
|
|
258
|
+
deepRewards
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
this.updatePoolAllowedVersions = (poolKey) => (tx) => {
|
|
262
|
+
const pool = this.#config.getPool(poolKey);
|
|
263
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
264
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
265
|
+
tx.moveCall({
|
|
266
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::update_pool_allowed_versions`,
|
|
267
|
+
arguments: [tx.object(pool.address), tx.object(this.#config.REGISTRY_ID)],
|
|
268
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
this.getOrder = (poolKey, orderId) => (tx) => {
|
|
272
|
+
const pool = this.#config.getPool(poolKey);
|
|
273
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
274
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
275
|
+
tx.moveCall({
|
|
276
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_order`,
|
|
277
|
+
arguments: [tx.object(pool.address), tx.pure.u128(orderId)],
|
|
278
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
this.getOrders = (poolKey, orderIds) => (tx) => {
|
|
282
|
+
const pool = this.#config.getPool(poolKey);
|
|
283
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
284
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
285
|
+
tx.moveCall({
|
|
286
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_orders`,
|
|
287
|
+
arguments: [tx.object(pool.address), tx.pure.vector("u128", orderIds)],
|
|
288
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
this.burnDeep = (poolKey) => (tx) => {
|
|
292
|
+
const pool = this.#config.getPool(poolKey);
|
|
293
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
294
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
295
|
+
tx.moveCall({
|
|
296
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::burn_deep`,
|
|
297
|
+
arguments: [tx.object(pool.address), tx.object(this.#config.DEEP_TREASURY_ID)],
|
|
298
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
this.midPrice = (poolKey) => (tx) => {
|
|
302
|
+
const pool = this.#config.getPool(poolKey);
|
|
303
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
304
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
305
|
+
tx.moveCall({
|
|
306
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::mid_price`,
|
|
307
|
+
arguments: [tx.object(pool.address), tx.object.clock()],
|
|
308
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
this.whitelisted = (poolKey) => (tx) => {
|
|
312
|
+
const pool = this.#config.getPool(poolKey);
|
|
313
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
314
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
315
|
+
tx.moveCall({
|
|
316
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::whitelisted`,
|
|
317
|
+
arguments: [tx.object(pool.address)],
|
|
318
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
this.getQuoteQuantityOut = (poolKey, baseQuantity) => (tx) => {
|
|
322
|
+
const pool = this.#config.getPool(poolKey);
|
|
323
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
324
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
325
|
+
tx.moveCall({
|
|
326
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out`,
|
|
327
|
+
arguments: [
|
|
328
|
+
tx.object(pool.address),
|
|
329
|
+
tx.pure.u64(Math.round(baseQuantity * baseCoin.scalar)),
|
|
330
|
+
tx.object.clock()
|
|
331
|
+
],
|
|
332
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
this.getBaseQuantityOut = (poolKey, quoteQuantity) => (tx) => {
|
|
336
|
+
const pool = this.#config.getPool(poolKey);
|
|
337
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
338
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
339
|
+
const quoteScalar = quoteCoin.scalar;
|
|
340
|
+
tx.moveCall({
|
|
341
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out`,
|
|
342
|
+
arguments: [
|
|
343
|
+
tx.object(pool.address),
|
|
344
|
+
tx.pure.u64(Math.round(quoteQuantity * quoteScalar)),
|
|
345
|
+
tx.object.clock()
|
|
346
|
+
],
|
|
347
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
this.getQuantityOut = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
|
|
351
|
+
const pool = this.#config.getPool(poolKey);
|
|
352
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
353
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
354
|
+
const quoteScalar = quoteCoin.scalar;
|
|
355
|
+
tx.moveCall({
|
|
356
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out`,
|
|
357
|
+
arguments: [
|
|
358
|
+
tx.object(pool.address),
|
|
359
|
+
tx.pure.u64(Math.round(baseQuantity * baseCoin.scalar)),
|
|
360
|
+
tx.pure.u64(Math.round(quoteQuantity * quoteScalar)),
|
|
361
|
+
tx.object.clock()
|
|
362
|
+
],
|
|
363
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
this.accountOpenOrders = (poolKey, managerKey) => (tx) => {
|
|
367
|
+
const pool = this.#config.getPool(poolKey);
|
|
368
|
+
const manager = this.#config.getBalanceManager(managerKey);
|
|
369
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
370
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
371
|
+
tx.moveCall({
|
|
372
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::account_open_orders`,
|
|
373
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
374
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
this.getLevel2Range = (poolKey, priceLow, priceHigh, isBid) => (tx) => {
|
|
378
|
+
const pool = this.#config.getPool(poolKey);
|
|
379
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
380
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
381
|
+
tx.moveCall({
|
|
382
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_level2_range`,
|
|
383
|
+
arguments: [
|
|
384
|
+
tx.object(pool.address),
|
|
385
|
+
tx.pure.u64(Math.round(priceLow * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar)),
|
|
386
|
+
tx.pure.u64(Math.round(priceHigh * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar)),
|
|
387
|
+
tx.pure.bool(isBid),
|
|
388
|
+
tx.object.clock()
|
|
389
|
+
],
|
|
390
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
this.getLevel2TicksFromMid = (poolKey, tickFromMid) => (tx) => {
|
|
394
|
+
const pool = this.#config.getPool(poolKey);
|
|
395
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
396
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
397
|
+
tx.moveCall({
|
|
398
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_level2_ticks_from_mid`,
|
|
399
|
+
arguments: [
|
|
400
|
+
tx.object(pool.address),
|
|
401
|
+
tx.pure.u64(tickFromMid),
|
|
402
|
+
tx.object.clock()
|
|
403
|
+
],
|
|
404
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
this.vaultBalances = (poolKey) => (tx) => {
|
|
408
|
+
const pool = this.#config.getPool(poolKey);
|
|
409
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
410
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
411
|
+
tx.moveCall({
|
|
412
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::vault_balances`,
|
|
413
|
+
arguments: [tx.object(pool.address)],
|
|
414
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
this.getPoolIdByAssets = (baseType, quoteType) => (tx) => {
|
|
418
|
+
tx.moveCall({
|
|
419
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_pool_id_by_asset`,
|
|
420
|
+
arguments: [tx.object(this.#config.REGISTRY_ID)],
|
|
421
|
+
typeArguments: [baseType, quoteType]
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
this.swapExactBaseForQuote = (params) => (tx) => {
|
|
425
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
426
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
427
|
+
if (params.quoteCoin) throw new Error("quoteCoin is not accepted for swapping base asset");
|
|
428
|
+
const { poolKey, amount: baseAmount, deepAmount, minOut: minQuote } = params;
|
|
429
|
+
const pool = this.#config.getPool(poolKey);
|
|
430
|
+
const deepCoinType = this.#config.getCoin("DEEP").type;
|
|
431
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
432
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
433
|
+
const baseCoinInput = params.baseCoin ?? coinWithBalance({
|
|
434
|
+
type: baseCoin.type,
|
|
435
|
+
balance: Math.round(baseAmount * baseCoin.scalar)
|
|
436
|
+
});
|
|
437
|
+
const deepCoin = params.deepCoin ?? coinWithBalance({
|
|
438
|
+
type: deepCoinType,
|
|
439
|
+
balance: Math.round(deepAmount * DEEP_SCALAR)
|
|
440
|
+
});
|
|
441
|
+
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar);
|
|
442
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
443
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`,
|
|
444
|
+
arguments: [
|
|
445
|
+
tx.object(pool.address),
|
|
446
|
+
baseCoinInput,
|
|
447
|
+
deepCoin,
|
|
448
|
+
tx.pure.u64(minQuoteInput),
|
|
449
|
+
tx.object.clock()
|
|
450
|
+
],
|
|
451
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
452
|
+
});
|
|
453
|
+
return [
|
|
454
|
+
baseCoinResult,
|
|
455
|
+
quoteCoinResult,
|
|
456
|
+
deepCoinResult
|
|
457
|
+
];
|
|
458
|
+
};
|
|
459
|
+
this.swapExactQuoteForBase = (params) => (tx) => {
|
|
460
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
461
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
462
|
+
if (params.baseCoin) throw new Error("baseCoin is not accepted for swapping quote asset");
|
|
463
|
+
const { poolKey, amount: quoteAmount, deepAmount, minOut: minBase } = params;
|
|
464
|
+
const pool = this.#config.getPool(poolKey);
|
|
465
|
+
const deepCoinType = this.#config.getCoin("DEEP").type;
|
|
466
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
467
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
468
|
+
const quoteCoinInput = params.quoteCoin ?? coinWithBalance({
|
|
469
|
+
type: quoteCoin.type,
|
|
470
|
+
balance: Math.round(quoteAmount * quoteCoin.scalar)
|
|
471
|
+
});
|
|
472
|
+
const deepCoin = params.deepCoin ?? coinWithBalance({
|
|
473
|
+
type: deepCoinType,
|
|
474
|
+
balance: Math.round(deepAmount * DEEP_SCALAR)
|
|
475
|
+
});
|
|
476
|
+
const minBaseInput = Math.round(minBase * baseCoin.scalar);
|
|
477
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
478
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`,
|
|
479
|
+
arguments: [
|
|
480
|
+
tx.object(pool.address),
|
|
481
|
+
quoteCoinInput,
|
|
482
|
+
deepCoin,
|
|
483
|
+
tx.pure.u64(minBaseInput),
|
|
484
|
+
tx.object.clock()
|
|
485
|
+
],
|
|
486
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
487
|
+
});
|
|
488
|
+
return [
|
|
489
|
+
baseCoinResult,
|
|
490
|
+
quoteCoinResult,
|
|
491
|
+
deepCoinResult
|
|
492
|
+
];
|
|
493
|
+
};
|
|
494
|
+
this.swapExactQuantity = (params) => (tx) => {
|
|
495
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
496
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
497
|
+
const { poolKey, amount, deepAmount, minOut, baseCoin, quoteCoin, deepCoin, isBaseToCoin } = params;
|
|
498
|
+
const pool = this.#config.getPool(poolKey);
|
|
499
|
+
const deepCoinType = this.#config.getCoin("DEEP").type;
|
|
500
|
+
const baseCoinType = this.#config.getCoin(pool.baseCoin);
|
|
501
|
+
const quoteCoinType = this.#config.getCoin(pool.quoteCoin);
|
|
502
|
+
const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
|
|
503
|
+
type: baseCoinType.type,
|
|
504
|
+
balance: Math.round(amount * baseCoinType.scalar)
|
|
505
|
+
}) : coinWithBalance({
|
|
506
|
+
type: baseCoinType.type,
|
|
507
|
+
balance: 0
|
|
508
|
+
});
|
|
509
|
+
const quoteCoinInput = isBaseToCoin ? coinWithBalance({
|
|
510
|
+
type: quoteCoinType.type,
|
|
511
|
+
balance: 0
|
|
512
|
+
}) : quoteCoin ?? coinWithBalance({
|
|
513
|
+
type: quoteCoinType.type,
|
|
514
|
+
balance: Math.round(amount * quoteCoinType.scalar)
|
|
515
|
+
});
|
|
516
|
+
const deepCoinInput = deepCoin ?? coinWithBalance({
|
|
517
|
+
type: deepCoinType,
|
|
518
|
+
balance: Math.round(deepAmount * DEEP_SCALAR)
|
|
519
|
+
});
|
|
520
|
+
const minOutInput = Math.round(minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar));
|
|
521
|
+
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
522
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity`,
|
|
523
|
+
arguments: [
|
|
524
|
+
tx.object(pool.address),
|
|
525
|
+
baseCoinInput,
|
|
526
|
+
quoteCoinInput,
|
|
527
|
+
deepCoinInput,
|
|
528
|
+
tx.pure.u64(minOutInput),
|
|
529
|
+
tx.object.clock()
|
|
530
|
+
],
|
|
531
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
532
|
+
});
|
|
533
|
+
return [
|
|
534
|
+
baseCoinResult,
|
|
535
|
+
quoteCoinResult,
|
|
536
|
+
deepCoinResult
|
|
537
|
+
];
|
|
538
|
+
};
|
|
539
|
+
this.swapExactBaseForQuoteWithManager = (params) => (tx) => {
|
|
540
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
541
|
+
const { poolKey, balanceManagerKey, tradeCap, depositCap, withdrawCap, amount: baseAmount, minOut: minQuote, baseCoin } = params;
|
|
542
|
+
const pool = this.#config.getPool(poolKey);
|
|
543
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
544
|
+
const baseCoinType = this.#config.getCoin(pool.baseCoin);
|
|
545
|
+
const quoteCoinType = this.#config.getCoin(pool.quoteCoin);
|
|
546
|
+
const baseCoinInput = baseCoin ?? coinWithBalance({
|
|
547
|
+
type: baseCoinType.type,
|
|
548
|
+
balance: Math.round(baseAmount * baseCoinType.scalar)
|
|
549
|
+
});
|
|
550
|
+
const minQuoteInput = Math.round(minQuote * quoteCoinType.scalar);
|
|
551
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
552
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote_with_manager`,
|
|
553
|
+
arguments: [
|
|
554
|
+
tx.object(pool.address),
|
|
555
|
+
tx.object(balanceManager.address),
|
|
556
|
+
tx.object(tradeCap),
|
|
557
|
+
tx.object(depositCap),
|
|
558
|
+
tx.object(withdrawCap),
|
|
559
|
+
baseCoinInput,
|
|
560
|
+
tx.pure.u64(minQuoteInput),
|
|
561
|
+
tx.object.clock()
|
|
562
|
+
],
|
|
563
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
564
|
+
});
|
|
565
|
+
return [baseCoinResult, quoteCoinResult];
|
|
566
|
+
};
|
|
567
|
+
this.swapExactQuoteForBaseWithManager = (params) => (tx) => {
|
|
568
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
569
|
+
const { poolKey, balanceManagerKey, tradeCap, depositCap, withdrawCap, amount: quoteAmount, minOut: minBase, quoteCoin } = params;
|
|
570
|
+
const pool = this.#config.getPool(poolKey);
|
|
571
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
572
|
+
const baseCoinType = this.#config.getCoin(pool.baseCoin);
|
|
573
|
+
const quoteCoinType = this.#config.getCoin(pool.quoteCoin);
|
|
574
|
+
const quoteCoinInput = quoteCoin ?? coinWithBalance({
|
|
575
|
+
type: quoteCoinType.type,
|
|
576
|
+
balance: Math.round(quoteAmount * quoteCoinType.scalar)
|
|
577
|
+
});
|
|
578
|
+
const minBaseInput = Math.round(minBase * baseCoinType.scalar);
|
|
579
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
580
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base_with_manager`,
|
|
581
|
+
arguments: [
|
|
582
|
+
tx.object(pool.address),
|
|
583
|
+
tx.object(balanceManager.address),
|
|
584
|
+
tx.object(tradeCap),
|
|
585
|
+
tx.object(depositCap),
|
|
586
|
+
tx.object(withdrawCap),
|
|
587
|
+
quoteCoinInput,
|
|
588
|
+
tx.pure.u64(minBaseInput),
|
|
589
|
+
tx.object.clock()
|
|
590
|
+
],
|
|
591
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
592
|
+
});
|
|
593
|
+
return [baseCoinResult, quoteCoinResult];
|
|
594
|
+
};
|
|
595
|
+
this.swapExactQuantityWithManager = (params) => (tx) => {
|
|
596
|
+
tx.setGasBudgetIfNotSet(GAS_BUDGET);
|
|
597
|
+
const { poolKey, balanceManagerKey, tradeCap, depositCap, withdrawCap, amount, minOut, baseCoin, quoteCoin, isBaseToCoin } = params;
|
|
598
|
+
const pool = this.#config.getPool(poolKey);
|
|
599
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
600
|
+
const baseCoinType = this.#config.getCoin(pool.baseCoin);
|
|
601
|
+
const quoteCoinType = this.#config.getCoin(pool.quoteCoin);
|
|
602
|
+
const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
|
|
603
|
+
type: baseCoinType.type,
|
|
604
|
+
balance: Math.round(amount * baseCoinType.scalar)
|
|
605
|
+
}) : coinWithBalance({
|
|
606
|
+
type: baseCoinType.type,
|
|
607
|
+
balance: 0
|
|
608
|
+
});
|
|
609
|
+
const quoteCoinInput = isBaseToCoin ? coinWithBalance({
|
|
610
|
+
type: quoteCoinType.type,
|
|
611
|
+
balance: 0
|
|
612
|
+
}) : quoteCoin ?? coinWithBalance({
|
|
613
|
+
type: quoteCoinType.type,
|
|
614
|
+
balance: Math.round(amount * quoteCoinType.scalar)
|
|
615
|
+
});
|
|
616
|
+
const minOutInput = Math.round(minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar));
|
|
617
|
+
const [baseCoinResult, quoteCoinResult] = tx.moveCall({
|
|
618
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity_with_manager`,
|
|
619
|
+
arguments: [
|
|
620
|
+
tx.object(pool.address),
|
|
621
|
+
tx.object(balanceManager.address),
|
|
622
|
+
tx.object(tradeCap),
|
|
623
|
+
tx.object(depositCap),
|
|
624
|
+
tx.object(withdrawCap),
|
|
625
|
+
baseCoinInput,
|
|
626
|
+
quoteCoinInput,
|
|
627
|
+
tx.pure.u64(minOutInput),
|
|
628
|
+
tx.object.clock()
|
|
629
|
+
],
|
|
630
|
+
typeArguments: [baseCoinType.type, quoteCoinType.type]
|
|
631
|
+
});
|
|
632
|
+
return [baseCoinResult, quoteCoinResult];
|
|
633
|
+
};
|
|
634
|
+
this.createPermissionlessPool = (params) => (tx) => {
|
|
635
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
636
|
+
const { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, deepCoin } = params;
|
|
637
|
+
const baseCoin = this.#config.getCoin(baseCoinKey);
|
|
638
|
+
const quoteCoin = this.#config.getCoin(quoteCoinKey);
|
|
639
|
+
const deepCoinType = this.#config.getCoin("DEEP").type;
|
|
640
|
+
const baseScalar = baseCoin.scalar;
|
|
641
|
+
const quoteScalar = quoteCoin.scalar;
|
|
642
|
+
const adjustedTickSize = Math.round(tickSize * FLOAT_SCALAR * quoteScalar / baseScalar);
|
|
643
|
+
const adjustedLotSize = Math.round(lotSize * baseScalar);
|
|
644
|
+
const adjustedMinSize = Math.round(minSize * baseScalar);
|
|
645
|
+
const deepCoinInput = deepCoin ?? coinWithBalance({
|
|
646
|
+
type: deepCoinType,
|
|
647
|
+
balance: POOL_CREATION_FEE_DEEP
|
|
648
|
+
});
|
|
649
|
+
tx.moveCall({
|
|
650
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::create_permissionless_pool`,
|
|
651
|
+
arguments: [
|
|
652
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
653
|
+
tx.pure.u64(adjustedTickSize),
|
|
654
|
+
tx.pure.u64(adjustedLotSize),
|
|
655
|
+
tx.pure.u64(adjustedMinSize),
|
|
656
|
+
deepCoinInput
|
|
657
|
+
],
|
|
658
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
this.poolTradeParams = (poolKey) => (tx) => {
|
|
662
|
+
const pool = this.#config.getPool(poolKey);
|
|
663
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
664
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
665
|
+
tx.moveCall({
|
|
666
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params`,
|
|
667
|
+
arguments: [tx.object(pool.address)],
|
|
668
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
669
|
+
});
|
|
670
|
+
};
|
|
671
|
+
this.poolBookParams = (poolKey) => (tx) => {
|
|
672
|
+
const pool = this.#config.getPool(poolKey);
|
|
673
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
674
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
675
|
+
tx.moveCall({
|
|
676
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::pool_book_params`,
|
|
677
|
+
arguments: [tx.object(pool.address)],
|
|
678
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
this.account = (poolKey, managerKey) => (tx) => {
|
|
682
|
+
const pool = this.#config.getPool(poolKey);
|
|
683
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
684
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
685
|
+
const managerId = this.#config.getBalanceManager(managerKey).address;
|
|
686
|
+
tx.moveCall({
|
|
687
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::account`,
|
|
688
|
+
arguments: [tx.object(pool.address), tx.object(managerId)],
|
|
689
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
this.lockedBalance = (poolKey, managerKey) => (tx) => {
|
|
693
|
+
const pool = this.#config.getPool(poolKey);
|
|
694
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
695
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
696
|
+
const managerId = this.#config.getBalanceManager(managerKey).address;
|
|
697
|
+
tx.moveCall({
|
|
698
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::locked_balance`,
|
|
699
|
+
arguments: [tx.object(pool.address), tx.object(managerId)],
|
|
700
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
this.getPoolDeepPrice = (poolKey) => (tx) => {
|
|
704
|
+
const pool = this.#config.getPool(poolKey);
|
|
705
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
706
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
707
|
+
tx.moveCall({
|
|
708
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_price`,
|
|
709
|
+
arguments: [tx.object(pool.address)],
|
|
710
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
this.getBalanceManagerIds = (owner) => (tx) => {
|
|
714
|
+
tx.moveCall({
|
|
715
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::get_balance_manager_ids`,
|
|
716
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.pure.address(owner)]
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
this.getPoolReferralBalances = (poolKey, referral) => (tx) => {
|
|
720
|
+
const pool = this.#config.getPool(poolKey);
|
|
721
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
722
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
723
|
+
return tx.moveCall({
|
|
724
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_pool_referral_balances`,
|
|
725
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
726
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
this.poolReferralMultiplier = (poolKey, referral) => (tx) => {
|
|
730
|
+
const pool = this.#config.getPool(poolKey);
|
|
731
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
732
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
733
|
+
return tx.moveCall({
|
|
734
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::pool_referral_multiplier`,
|
|
735
|
+
arguments: [tx.object(pool.address), tx.object(referral)],
|
|
736
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
this.stablePool = (poolKey) => (tx) => {
|
|
740
|
+
const pool = this.#config.getPool(poolKey);
|
|
741
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
742
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
743
|
+
return tx.moveCall({
|
|
744
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stable_pool`,
|
|
745
|
+
arguments: [tx.object(pool.address)],
|
|
746
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
this.registeredPool = (poolKey) => (tx) => {
|
|
750
|
+
const pool = this.#config.getPool(poolKey);
|
|
751
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
752
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
753
|
+
return tx.moveCall({
|
|
754
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::registered_pool`,
|
|
755
|
+
arguments: [tx.object(pool.address)],
|
|
756
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
757
|
+
});
|
|
758
|
+
};
|
|
759
|
+
this.getQuoteQuantityOutInputFee = (poolKey, baseQuantity) => (tx) => {
|
|
760
|
+
const pool = this.#config.getPool(poolKey);
|
|
761
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
762
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
763
|
+
return tx.moveCall({
|
|
764
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out_input_fee`,
|
|
765
|
+
arguments: [
|
|
766
|
+
tx.object(pool.address),
|
|
767
|
+
tx.pure.u64(Math.round(baseQuantity * baseCoin.scalar)),
|
|
768
|
+
tx.object.clock()
|
|
769
|
+
],
|
|
770
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
771
|
+
});
|
|
772
|
+
};
|
|
773
|
+
this.getBaseQuantityOutInputFee = (poolKey, quoteQuantity) => (tx) => {
|
|
774
|
+
const pool = this.#config.getPool(poolKey);
|
|
775
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
776
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
777
|
+
return tx.moveCall({
|
|
778
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out_input_fee`,
|
|
779
|
+
arguments: [
|
|
780
|
+
tx.object(pool.address),
|
|
781
|
+
tx.pure.u64(Math.round(quoteQuantity * quoteCoin.scalar)),
|
|
782
|
+
tx.object.clock()
|
|
783
|
+
],
|
|
784
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
785
|
+
});
|
|
786
|
+
};
|
|
787
|
+
this.getQuantityOutInputFee = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
|
|
788
|
+
const pool = this.#config.getPool(poolKey);
|
|
789
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
790
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
791
|
+
return tx.moveCall({
|
|
792
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out_input_fee`,
|
|
793
|
+
arguments: [
|
|
794
|
+
tx.object(pool.address),
|
|
795
|
+
tx.pure.u64(Math.round(baseQuantity * baseCoin.scalar)),
|
|
796
|
+
tx.pure.u64(Math.round(quoteQuantity * quoteCoin.scalar)),
|
|
797
|
+
tx.object.clock()
|
|
798
|
+
],
|
|
799
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
800
|
+
});
|
|
801
|
+
};
|
|
802
|
+
this.getBaseQuantityIn = (poolKey, targetQuoteQuantity, payWithDeep) => (tx) => {
|
|
803
|
+
const pool = this.#config.getPool(poolKey);
|
|
804
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
805
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
806
|
+
return tx.moveCall({
|
|
807
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_in`,
|
|
808
|
+
arguments: [
|
|
809
|
+
tx.object(pool.address),
|
|
810
|
+
tx.pure.u64(Math.round(targetQuoteQuantity * quoteCoin.scalar)),
|
|
811
|
+
tx.pure.bool(payWithDeep),
|
|
812
|
+
tx.object.clock()
|
|
813
|
+
],
|
|
814
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
815
|
+
});
|
|
816
|
+
};
|
|
817
|
+
this.getQuoteQuantityIn = (poolKey, targetBaseQuantity, payWithDeep) => (tx) => {
|
|
818
|
+
const pool = this.#config.getPool(poolKey);
|
|
819
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
820
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
821
|
+
return tx.moveCall({
|
|
822
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_in`,
|
|
823
|
+
arguments: [
|
|
824
|
+
tx.object(pool.address),
|
|
825
|
+
tx.pure.u64(Math.round(targetBaseQuantity * baseCoin.scalar)),
|
|
826
|
+
tx.pure.bool(payWithDeep),
|
|
827
|
+
tx.object.clock()
|
|
828
|
+
],
|
|
829
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
830
|
+
});
|
|
831
|
+
};
|
|
832
|
+
this.getAccountOrderDetails = (poolKey, managerKey) => (tx) => {
|
|
833
|
+
const pool = this.#config.getPool(poolKey);
|
|
834
|
+
const manager = this.#config.getBalanceManager(managerKey);
|
|
835
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
836
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
837
|
+
return tx.moveCall({
|
|
838
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
|
|
839
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
840
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
841
|
+
});
|
|
842
|
+
};
|
|
843
|
+
this.getOrderDeepRequired = (poolKey, baseQuantity, price) => (tx) => {
|
|
844
|
+
const pool = this.#config.getPool(poolKey);
|
|
845
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
846
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
847
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
848
|
+
const inputQuantity = Math.round(baseQuantity * baseCoin.scalar);
|
|
849
|
+
return tx.moveCall({
|
|
850
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_required`,
|
|
851
|
+
arguments: [
|
|
852
|
+
tx.object(pool.address),
|
|
853
|
+
tx.pure.u64(inputQuantity),
|
|
854
|
+
tx.pure.u64(inputPrice)
|
|
855
|
+
],
|
|
856
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
this.accountExists = (poolKey, managerKey) => (tx) => {
|
|
860
|
+
const pool = this.#config.getPool(poolKey);
|
|
861
|
+
const manager = this.#config.getBalanceManager(managerKey);
|
|
862
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
863
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
864
|
+
return tx.moveCall({
|
|
865
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::account_exists`,
|
|
866
|
+
arguments: [tx.object(pool.address), tx.object(manager.address)],
|
|
867
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
this.poolTradeParamsNext = (poolKey) => (tx) => {
|
|
871
|
+
const pool = this.#config.getPool(poolKey);
|
|
872
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
873
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
874
|
+
return tx.moveCall({
|
|
875
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params_next`,
|
|
876
|
+
arguments: [tx.object(pool.address)],
|
|
877
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
878
|
+
});
|
|
879
|
+
};
|
|
880
|
+
this.quorum = (poolKey) => (tx) => {
|
|
881
|
+
const pool = this.#config.getPool(poolKey);
|
|
882
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
883
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
884
|
+
return tx.moveCall({
|
|
885
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::quorum`,
|
|
886
|
+
arguments: [tx.object(pool.address)],
|
|
887
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
888
|
+
});
|
|
889
|
+
};
|
|
890
|
+
this.poolId = (poolKey) => (tx) => {
|
|
891
|
+
const pool = this.#config.getPool(poolKey);
|
|
892
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
893
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
894
|
+
return tx.moveCall({
|
|
895
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::id`,
|
|
896
|
+
arguments: [tx.object(pool.address)],
|
|
897
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
this.canPlaceLimitOrder = (params) => (tx) => {
|
|
901
|
+
const { poolKey, balanceManagerKey, price, quantity, isBid, payWithDeep, expireTimestamp } = params;
|
|
902
|
+
const pool = this.#config.getPool(poolKey);
|
|
903
|
+
const manager = this.#config.getBalanceManager(balanceManagerKey);
|
|
904
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
905
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
906
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
907
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
908
|
+
return tx.moveCall({
|
|
909
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::can_place_limit_order`,
|
|
910
|
+
arguments: [
|
|
911
|
+
tx.object(pool.address),
|
|
912
|
+
tx.object(manager.address),
|
|
913
|
+
tx.pure.u64(inputPrice),
|
|
914
|
+
tx.pure.u64(inputQuantity),
|
|
915
|
+
tx.pure.bool(isBid),
|
|
916
|
+
tx.pure.bool(payWithDeep),
|
|
917
|
+
tx.pure.u64(expireTimestamp),
|
|
918
|
+
tx.object.clock()
|
|
919
|
+
],
|
|
920
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
this.canPlaceMarketOrder = (params) => (tx) => {
|
|
924
|
+
const { poolKey, balanceManagerKey, quantity, isBid, payWithDeep } = params;
|
|
925
|
+
const pool = this.#config.getPool(poolKey);
|
|
926
|
+
const manager = this.#config.getBalanceManager(balanceManagerKey);
|
|
927
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
928
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
929
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
930
|
+
return tx.moveCall({
|
|
931
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::can_place_market_order`,
|
|
932
|
+
arguments: [
|
|
933
|
+
tx.object(pool.address),
|
|
934
|
+
tx.object(manager.address),
|
|
935
|
+
tx.pure.u64(inputQuantity),
|
|
936
|
+
tx.pure.bool(isBid),
|
|
937
|
+
tx.pure.bool(payWithDeep),
|
|
938
|
+
tx.object.clock()
|
|
939
|
+
],
|
|
940
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
this.checkMarketOrderParams = (poolKey, quantity) => (tx) => {
|
|
944
|
+
const pool = this.#config.getPool(poolKey);
|
|
945
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
946
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
947
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
948
|
+
return tx.moveCall({
|
|
949
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::check_market_order_params`,
|
|
950
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
951
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
952
|
+
});
|
|
953
|
+
};
|
|
954
|
+
this.checkLimitOrderParams = (poolKey, price, quantity, expireTimestamp) => (tx) => {
|
|
955
|
+
const pool = this.#config.getPool(poolKey);
|
|
956
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
957
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
958
|
+
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
959
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
960
|
+
return tx.moveCall({
|
|
961
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::check_limit_order_params`,
|
|
962
|
+
arguments: [
|
|
963
|
+
tx.object(pool.address),
|
|
964
|
+
tx.pure.u64(inputPrice),
|
|
965
|
+
tx.pure.u64(inputQuantity),
|
|
966
|
+
tx.pure.u64(expireTimestamp),
|
|
967
|
+
tx.object.clock()
|
|
968
|
+
],
|
|
969
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
970
|
+
});
|
|
971
|
+
};
|
|
972
|
+
this.#config = config;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
//#endregion
|
|
977
|
+
export { DeepBookContract };
|
|
978
|
+
//# sourceMappingURL=deepbook.mjs.map
|