@haneullabs/deepbook-v3 0.1.0 → 1.2.1
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 +342 -81
- package/dist/client.d.mts +238 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +397 -0
- package/dist/client.mjs.map +1 -0
- package/dist/contracts/deepbook/account.d.mts +37 -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 +12 -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 +12 -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 +21 -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 +23 -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/queries/accountQueries.mjs +104 -0
- package/dist/queries/accountQueries.mjs.map +1 -0
- package/dist/queries/balanceManagerQueries.mjs +113 -0
- package/dist/queries/balanceManagerQueries.mjs.map +1 -0
- package/dist/queries/context.mjs +15 -0
- package/dist/queries/context.mjs.map +1 -0
- package/dist/queries/marginManagerQueries.mjs +365 -0
- package/dist/queries/marginManagerQueries.mjs.map +1 -0
- package/dist/queries/marginPoolQueries.mjs +184 -0
- package/dist/queries/marginPoolQueries.mjs.map +1 -0
- package/dist/queries/orderQueries.mjs +165 -0
- package/dist/queries/orderQueries.mjs.map +1 -0
- package/dist/queries/poolQueries.mjs +234 -0
- package/dist/queries/poolQueries.mjs.map +1 -0
- package/dist/queries/priceFeedQueries.mjs +83 -0
- package/dist/queries/priceFeedQueries.mjs.map +1 -0
- package/dist/queries/quantityQueries.mjs +216 -0
- package/dist/queries/quantityQueries.mjs.map +1 -0
- package/dist/queries/referralQueries.mjs +96 -0
- package/dist/queries/referralQueries.mjs.map +1 -0
- package/dist/queries/registryQueries.mjs +162 -0
- package/dist/queries/registryQueries.mjs.map +1 -0
- package/dist/queries/tpslQueries.mjs +62 -0
- package/dist/queries/tpslQueries.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 +234 -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 +979 -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 +222 -0
- package/dist/transactions/deepbookAdmin.mjs.map +1 -0
- package/dist/transactions/flashLoans.d.mts +61 -0
- package/dist/transactions/flashLoans.d.mts.map +1 -0
- package/dist/transactions/flashLoans.mjs +77 -0
- package/dist/transactions/flashLoans.mjs.map +1 -0
- package/dist/transactions/governance.d.mts +47 -0
- package/dist/transactions/governance.d.mts.map +1 -0
- package/dist/transactions/governance.mjs +91 -0
- package/dist/transactions/governance.mjs.map +1 -0
- package/dist/transactions/marginAdmin.d.mts +138 -0
- package/dist/transactions/marginAdmin.d.mts.map +1 -0
- package/dist/transactions/marginAdmin.mjs +250 -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 +110 -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 +161 -0
- package/dist/transactions/marginMaintainer.mjs.map +1 -0
- package/dist/transactions/marginManager.d.mts +247 -0
- package/dist/transactions/marginManager.d.mts.map +1 -0
- package/dist/transactions/marginManager.mjs +548 -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 +207 -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 +173 -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 +374 -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 +90 -0
- package/dist/utils/config.d.mts.map +1 -0
- package/dist/utils/config.mjs +104 -0
- package/dist/utils/config.mjs.map +1 -0
- package/dist/utils/constants.d.mts +93 -0
- package/dist/utils/constants.d.mts.map +1 -0
- package/dist/utils/constants.mjs +408 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/conversion.mjs +26 -0
- package/dist/utils/conversion.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 +30 -26
- package/src/client.ts +467 -2255
- 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 +44 -3
- package/src/pyth/pyth.ts +51 -50
- package/src/queries/accountQueries.ts +117 -0
- package/src/queries/balanceManagerQueries.ts +156 -0
- package/src/queries/context.ts +44 -0
- package/src/queries/index.ts +16 -0
- package/src/queries/marginManagerQueries.ts +575 -0
- package/src/queries/marginPoolQueries.ts +226 -0
- package/src/queries/orderQueries.ts +202 -0
- package/src/queries/poolQueries.ts +266 -0
- package/src/queries/priceFeedQueries.ts +141 -0
- package/src/queries/quantityQueries.ts +266 -0
- package/src/queries/referralQueries.ts +112 -0
- package/src/queries/registryQueries.ts +185 -0
- package/src/queries/tpslQueries.ts +88 -0
- package/src/transactions/balanceManager.ts +5 -4
- package/src/transactions/deepbook.ts +117 -84
- package/src/transactions/deepbookAdmin.ts +10 -9
- package/src/transactions/flashLoans.ts +5 -4
- package/src/transactions/governance.ts +5 -4
- package/src/transactions/marginAdmin.ts +12 -8
- package/src/transactions/marginLiquidations.ts +5 -4
- package/src/transactions/marginMaintainer.ts +28 -16
- package/src/transactions/marginManager.ts +78 -29
- package/src/transactions/marginPool.ts +7 -7
- package/src/transactions/marginTPSL.ts +16 -11
- package/src/transactions/poolProxy.ts +62 -11
- package/src/types/bcs.ts +1 -1
- package/src/types/index.ts +217 -53
- package/src/utils/config.ts +38 -17
- package/src/utils/constants.ts +73 -18
- package/src/utils/conversion.ts +33 -0
- 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,226 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
|
+
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
6
|
+
|
|
7
|
+
import { FLOAT_SCALAR } from '../utils/config.js';
|
|
8
|
+
import { formatTokenAmount } from './context.js';
|
|
9
|
+
import type { QueryContext } from './context.js';
|
|
10
|
+
|
|
11
|
+
export class MarginPoolQueries {
|
|
12
|
+
#ctx: QueryContext;
|
|
13
|
+
|
|
14
|
+
constructor(ctx: QueryContext) {
|
|
15
|
+
this.#ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getMarginPoolId(coinKey: string): Promise<string> {
|
|
19
|
+
const tx = new Transaction();
|
|
20
|
+
tx.add(this.#ctx.marginPool.getId(coinKey));
|
|
21
|
+
|
|
22
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
23
|
+
transaction: tx,
|
|
24
|
+
include: { commandResults: true, effects: true },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
28
|
+
return bcs.Address.parse(bytes);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async isDeepbookPoolAllowed(coinKey: string, deepbookPoolId: string): Promise<boolean> {
|
|
32
|
+
const tx = new Transaction();
|
|
33
|
+
tx.add(this.#ctx.marginPool.deepbookPoolAllowed(coinKey, deepbookPoolId));
|
|
34
|
+
|
|
35
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
36
|
+
transaction: tx,
|
|
37
|
+
include: { commandResults: true, effects: true },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
41
|
+
return bcs.bool().parse(bytes);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async getMarginPoolTotalSupply(coinKey: string, decimals: number = 6): Promise<string> {
|
|
45
|
+
const tx = new Transaction();
|
|
46
|
+
tx.add(this.#ctx.marginPool.totalSupply(coinKey));
|
|
47
|
+
|
|
48
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
49
|
+
transaction: tx,
|
|
50
|
+
include: { commandResults: true, effects: true },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
54
|
+
const rawAmount = BigInt(bcs.U64.parse(bytes));
|
|
55
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
56
|
+
return formatTokenAmount(rawAmount, coin.scalar, decimals);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getMarginPoolSupplyShares(coinKey: string, decimals: number = 6): Promise<string> {
|
|
60
|
+
const tx = new Transaction();
|
|
61
|
+
tx.add(this.#ctx.marginPool.supplyShares(coinKey));
|
|
62
|
+
|
|
63
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
64
|
+
transaction: tx,
|
|
65
|
+
include: { commandResults: true, effects: true },
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
69
|
+
const rawShares = BigInt(bcs.U64.parse(bytes));
|
|
70
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
71
|
+
return formatTokenAmount(rawShares, coin.scalar, decimals);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getMarginPoolTotalBorrow(coinKey: string, decimals: number = 6): Promise<string> {
|
|
75
|
+
const tx = new Transaction();
|
|
76
|
+
tx.add(this.#ctx.marginPool.totalBorrow(coinKey));
|
|
77
|
+
|
|
78
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
79
|
+
transaction: tx,
|
|
80
|
+
include: { commandResults: true, effects: true },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
84
|
+
const rawAmount = BigInt(bcs.U64.parse(bytes));
|
|
85
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
86
|
+
return formatTokenAmount(rawAmount, coin.scalar, decimals);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async getMarginPoolBorrowShares(coinKey: string, decimals: number = 6): Promise<string> {
|
|
90
|
+
const tx = new Transaction();
|
|
91
|
+
tx.add(this.#ctx.marginPool.borrowShares(coinKey));
|
|
92
|
+
|
|
93
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
94
|
+
transaction: tx,
|
|
95
|
+
include: { commandResults: true, effects: true },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
99
|
+
const rawShares = BigInt(bcs.U64.parse(bytes));
|
|
100
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
101
|
+
return formatTokenAmount(rawShares, coin.scalar, decimals);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getMarginPoolLastUpdateTimestamp(coinKey: string): Promise<number> {
|
|
105
|
+
const tx = new Transaction();
|
|
106
|
+
tx.add(this.#ctx.marginPool.lastUpdateTimestamp(coinKey));
|
|
107
|
+
|
|
108
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
109
|
+
transaction: tx,
|
|
110
|
+
include: { commandResults: true, effects: true },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
114
|
+
return Number(bcs.U64.parse(bytes));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async getMarginPoolSupplyCap(coinKey: string, decimals: number = 6): Promise<string> {
|
|
118
|
+
const tx = new Transaction();
|
|
119
|
+
tx.add(this.#ctx.marginPool.supplyCap(coinKey));
|
|
120
|
+
|
|
121
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
122
|
+
transaction: tx,
|
|
123
|
+
include: { commandResults: true, effects: true },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
127
|
+
const rawAmount = BigInt(bcs.U64.parse(bytes));
|
|
128
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
129
|
+
return formatTokenAmount(rawAmount, coin.scalar, decimals);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async getMarginPoolMaxUtilizationRate(coinKey: string): Promise<number> {
|
|
133
|
+
const tx = new Transaction();
|
|
134
|
+
tx.add(this.#ctx.marginPool.maxUtilizationRate(coinKey));
|
|
135
|
+
|
|
136
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
137
|
+
transaction: tx,
|
|
138
|
+
include: { commandResults: true, effects: true },
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
142
|
+
const rawRate = Number(bcs.U64.parse(bytes));
|
|
143
|
+
return rawRate / FLOAT_SCALAR;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async getMarginPoolProtocolSpread(coinKey: string): Promise<number> {
|
|
147
|
+
const tx = new Transaction();
|
|
148
|
+
tx.add(this.#ctx.marginPool.protocolSpread(coinKey));
|
|
149
|
+
|
|
150
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
151
|
+
transaction: tx,
|
|
152
|
+
include: { commandResults: true, effects: true },
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
156
|
+
const rawSpread = Number(bcs.U64.parse(bytes));
|
|
157
|
+
return rawSpread / FLOAT_SCALAR;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async getMarginPoolMinBorrow(coinKey: string, decimals: number = 6): Promise<string> {
|
|
161
|
+
const tx = new Transaction();
|
|
162
|
+
tx.add(this.#ctx.marginPool.minBorrow(coinKey));
|
|
163
|
+
|
|
164
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
165
|
+
transaction: tx,
|
|
166
|
+
include: { commandResults: true, effects: true },
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
170
|
+
const rawAmount = BigInt(bcs.U64.parse(bytes));
|
|
171
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
172
|
+
return formatTokenAmount(rawAmount, coin.scalar, decimals);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async getMarginPoolInterestRate(coinKey: string): Promise<number> {
|
|
176
|
+
const tx = new Transaction();
|
|
177
|
+
tx.add(this.#ctx.marginPool.interestRate(coinKey));
|
|
178
|
+
|
|
179
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
180
|
+
transaction: tx,
|
|
181
|
+
include: { commandResults: true, effects: true },
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
185
|
+
const rawRate = Number(bcs.U64.parse(bytes));
|
|
186
|
+
return rawRate / FLOAT_SCALAR;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async getUserSupplyShares(
|
|
190
|
+
coinKey: string,
|
|
191
|
+
supplierCapId: string,
|
|
192
|
+
decimals: number = 6,
|
|
193
|
+
): Promise<string> {
|
|
194
|
+
const tx = new Transaction();
|
|
195
|
+
tx.add(this.#ctx.marginPool.userSupplyShares(coinKey, supplierCapId));
|
|
196
|
+
|
|
197
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
198
|
+
transaction: tx,
|
|
199
|
+
include: { commandResults: true, effects: true },
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
203
|
+
const rawShares = BigInt(bcs.U64.parse(bytes));
|
|
204
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
205
|
+
return formatTokenAmount(rawShares, coin.scalar, decimals);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async getUserSupplyAmount(
|
|
209
|
+
coinKey: string,
|
|
210
|
+
supplierCapId: string,
|
|
211
|
+
decimals: number = 6,
|
|
212
|
+
): Promise<string> {
|
|
213
|
+
const tx = new Transaction();
|
|
214
|
+
tx.add(this.#ctx.marginPool.userSupplyAmount(coinKey, supplierCapId));
|
|
215
|
+
|
|
216
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
217
|
+
transaction: tx,
|
|
218
|
+
include: { commandResults: true, effects: true },
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
222
|
+
const rawAmount = BigInt(bcs.U64.parse(bytes));
|
|
223
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
224
|
+
return formatTokenAmount(rawAmount, coin.scalar, decimals);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
|
+
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
6
|
+
|
|
7
|
+
import { Order } from '../types/bcs.js';
|
|
8
|
+
import { VecSet } from '../types/bcs.js';
|
|
9
|
+
import type { Level2Range, Level2TicksFromMid } from '../types/index.js';
|
|
10
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';
|
|
11
|
+
import type { QueryContext } from './context.js';
|
|
12
|
+
|
|
13
|
+
export class OrderQueries {
|
|
14
|
+
#ctx: QueryContext;
|
|
15
|
+
|
|
16
|
+
constructor(ctx: QueryContext) {
|
|
17
|
+
this.#ctx = ctx;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async accountOpenOrders(poolKey: string, managerKey: string): Promise<string[]> {
|
|
21
|
+
const tx = new Transaction();
|
|
22
|
+
|
|
23
|
+
tx.add(this.#ctx.deepBook.accountOpenOrders(poolKey, managerKey));
|
|
24
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
25
|
+
transaction: tx,
|
|
26
|
+
include: { commandResults: true, effects: true },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const order_ids = res.commandResults![0].returnValues[0].bcs;
|
|
30
|
+
|
|
31
|
+
return VecSet(bcs.u128()).parse(new Uint8Array(order_ids)).contents;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getOrder(poolKey: string, orderId: string): Promise<ReturnType<typeof Order.parse> | null> {
|
|
35
|
+
const tx = new Transaction();
|
|
36
|
+
|
|
37
|
+
tx.add(this.#ctx.deepBook.getOrder(poolKey, orderId));
|
|
38
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
39
|
+
transaction: tx,
|
|
40
|
+
include: { commandResults: true, effects: true },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const orderInformation = res.commandResults![0].returnValues[0].bcs;
|
|
45
|
+
return Order.parse(new Uint8Array(orderInformation));
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getOrderNormalized(poolKey: string, orderId: string) {
|
|
52
|
+
const tx = new Transaction();
|
|
53
|
+
tx.add(this.#ctx.deepBook.getOrder(poolKey, orderId));
|
|
54
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
55
|
+
transaction: tx,
|
|
56
|
+
include: { commandResults: true, effects: true },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const orderInformation = res.commandResults![0].returnValues[0].bcs;
|
|
61
|
+
const orderInfo = Order.parse(new Uint8Array(orderInformation));
|
|
62
|
+
|
|
63
|
+
if (!orderInfo) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const baseCoin = this.#ctx.config.getCoin(this.#ctx.config.getPool(poolKey).baseCoin);
|
|
67
|
+
const quoteCoin = this.#ctx.config.getCoin(this.#ctx.config.getPool(poolKey).quoteCoin);
|
|
68
|
+
|
|
69
|
+
const encodedOrderId = BigInt(orderInfo.order_id);
|
|
70
|
+
const isBid = encodedOrderId >> 127n === 0n;
|
|
71
|
+
const rawPrice = Number((encodedOrderId >> 64n) & ((1n << 63n) - 1n));
|
|
72
|
+
const normalizedPrice = (rawPrice * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;
|
|
73
|
+
|
|
74
|
+
const normalizedOrderInfo = {
|
|
75
|
+
...orderInfo,
|
|
76
|
+
quantity: String((Number(orderInfo.quantity) / baseCoin.scalar).toFixed(9)),
|
|
77
|
+
filled_quantity: String((Number(orderInfo.filled_quantity) / baseCoin.scalar).toFixed(9)),
|
|
78
|
+
order_deep_price: {
|
|
79
|
+
...orderInfo.order_deep_price,
|
|
80
|
+
deep_per_asset: String(
|
|
81
|
+
(Number(orderInfo.order_deep_price.deep_per_asset) / DEEP_SCALAR).toFixed(9),
|
|
82
|
+
),
|
|
83
|
+
},
|
|
84
|
+
isBid,
|
|
85
|
+
normalized_price: normalizedPrice.toFixed(9),
|
|
86
|
+
};
|
|
87
|
+
return normalizedOrderInfo;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getOrders(
|
|
94
|
+
poolKey: string,
|
|
95
|
+
orderIds: string[],
|
|
96
|
+
): Promise<ReturnType<typeof Order.parse>[] | null> {
|
|
97
|
+
const tx = new Transaction();
|
|
98
|
+
|
|
99
|
+
tx.add(this.#ctx.deepBook.getOrders(poolKey, orderIds));
|
|
100
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
101
|
+
transaction: tx,
|
|
102
|
+
include: { commandResults: true, effects: true },
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const orderInformation = res.commandResults![0].returnValues[0].bcs;
|
|
107
|
+
return bcs.vector(Order).parse(new Uint8Array(orderInformation));
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async getLevel2Range(
|
|
114
|
+
poolKey: string,
|
|
115
|
+
priceLow: number | bigint,
|
|
116
|
+
priceHigh: number | bigint,
|
|
117
|
+
isBid: boolean,
|
|
118
|
+
): Promise<Level2Range> {
|
|
119
|
+
const tx = new Transaction();
|
|
120
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
121
|
+
const baseCoin = this.#ctx.config.getCoin(pool.baseCoin);
|
|
122
|
+
const quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);
|
|
123
|
+
|
|
124
|
+
tx.add(this.#ctx.deepBook.getLevel2Range(poolKey, priceLow, priceHigh, isBid));
|
|
125
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
126
|
+
transaction: tx,
|
|
127
|
+
include: { commandResults: true, effects: true },
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const prices = res.commandResults![0].returnValues[0].bcs;
|
|
131
|
+
const parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(prices));
|
|
132
|
+
const quantities = res.commandResults![0].returnValues[1].bcs;
|
|
133
|
+
const parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(quantities));
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
prices: parsed_prices.map((price) =>
|
|
137
|
+
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),
|
|
138
|
+
),
|
|
139
|
+
quantities: parsed_quantities.map((price) =>
|
|
140
|
+
Number((Number(price) / baseCoin.scalar).toFixed(9)),
|
|
141
|
+
),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async getLevel2TicksFromMid(poolKey: string, ticks: number): Promise<Level2TicksFromMid> {
|
|
146
|
+
const tx = new Transaction();
|
|
147
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
148
|
+
const baseCoin = this.#ctx.config.getCoin(pool.baseCoin);
|
|
149
|
+
const quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);
|
|
150
|
+
|
|
151
|
+
tx.add(this.#ctx.deepBook.getLevel2TicksFromMid(poolKey, ticks));
|
|
152
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
153
|
+
transaction: tx,
|
|
154
|
+
include: { commandResults: true, effects: true },
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const bid_prices = res.commandResults![0].returnValues[0].bcs;
|
|
158
|
+
const bid_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_prices));
|
|
159
|
+
const bid_quantities = res.commandResults![0].returnValues[1].bcs;
|
|
160
|
+
const bid_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_quantities));
|
|
161
|
+
|
|
162
|
+
const ask_prices = res.commandResults![0].returnValues[2].bcs;
|
|
163
|
+
const ask_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_prices));
|
|
164
|
+
const ask_quantities = res.commandResults![0].returnValues[3].bcs;
|
|
165
|
+
const ask_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_quantities));
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
bid_prices: bid_parsed_prices.map((price) =>
|
|
169
|
+
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),
|
|
170
|
+
),
|
|
171
|
+
bid_quantities: bid_parsed_quantities.map((quantity) =>
|
|
172
|
+
Number((Number(quantity) / baseCoin.scalar).toFixed(9)),
|
|
173
|
+
),
|
|
174
|
+
ask_prices: ask_parsed_prices.map((price) =>
|
|
175
|
+
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),
|
|
176
|
+
),
|
|
177
|
+
ask_quantities: ask_parsed_quantities.map((quantity) =>
|
|
178
|
+
Number((Number(quantity) / baseCoin.scalar).toFixed(9)),
|
|
179
|
+
),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async getAccountOrderDetails(
|
|
184
|
+
poolKey: string,
|
|
185
|
+
managerKey: string,
|
|
186
|
+
): Promise<ReturnType<typeof Order.parse>[] | []> {
|
|
187
|
+
const tx = new Transaction();
|
|
188
|
+
tx.add(this.#ctx.deepBook.getAccountOrderDetails(poolKey, managerKey));
|
|
189
|
+
|
|
190
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
191
|
+
transaction: tx,
|
|
192
|
+
include: { commandResults: true, effects: true },
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
const orderInformation = res.commandResults![0].returnValues[0].bcs;
|
|
197
|
+
return bcs.vector(Order).parse(new Uint8Array(orderInformation));
|
|
198
|
+
} catch {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@haneullabs/haneul/bcs';
|
|
5
|
+
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
6
|
+
import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
CanPlaceLimitOrderParams,
|
|
10
|
+
CanPlaceMarketOrderParams,
|
|
11
|
+
PoolBookParams,
|
|
12
|
+
PoolTradeParams,
|
|
13
|
+
VaultBalances,
|
|
14
|
+
} from '../types/index.js';
|
|
15
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';
|
|
16
|
+
import type { QueryContext } from './context.js';
|
|
17
|
+
|
|
18
|
+
export class PoolQueries {
|
|
19
|
+
#ctx: QueryContext;
|
|
20
|
+
|
|
21
|
+
constructor(ctx: QueryContext) {
|
|
22
|
+
this.#ctx = ctx;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async whitelisted(poolKey: string): Promise<boolean> {
|
|
26
|
+
const tx = new Transaction();
|
|
27
|
+
|
|
28
|
+
tx.add(this.#ctx.deepBook.whitelisted(poolKey));
|
|
29
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
30
|
+
transaction: tx,
|
|
31
|
+
include: { commandResults: true, effects: true },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
35
|
+
return bcs.Bool.parse(bytes);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async vaultBalances(poolKey: string): Promise<VaultBalances> {
|
|
39
|
+
const tx = new Transaction();
|
|
40
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
41
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
42
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
43
|
+
|
|
44
|
+
tx.add(this.#ctx.deepBook.vaultBalances(poolKey));
|
|
45
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
46
|
+
transaction: tx,
|
|
47
|
+
include: { commandResults: true, effects: true },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const baseInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
|
|
51
|
+
const quoteInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
|
|
52
|
+
const deepInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
base: Number((baseInVault / baseScalar).toFixed(9)),
|
|
56
|
+
quote: Number((quoteInVault / quoteScalar).toFixed(9)),
|
|
57
|
+
deep: Number((deepInVault / DEEP_SCALAR).toFixed(9)),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getPoolIdByAssets(baseType: string, quoteType: string): Promise<string> {
|
|
62
|
+
const tx = new Transaction();
|
|
63
|
+
tx.add(this.#ctx.deepBook.getPoolIdByAssets(baseType, quoteType));
|
|
64
|
+
|
|
65
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
66
|
+
transaction: tx,
|
|
67
|
+
include: { commandResults: true, effects: true },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return bcs.Address.parse(res.commandResults![0].returnValues[0].bcs);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async midPrice(poolKey: string): Promise<number> {
|
|
74
|
+
const tx = new Transaction();
|
|
75
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
76
|
+
tx.add(this.#ctx.deepBook.midPrice(poolKey));
|
|
77
|
+
|
|
78
|
+
const baseCoin = this.#ctx.config.getCoin(pool.baseCoin);
|
|
79
|
+
const quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);
|
|
80
|
+
|
|
81
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
82
|
+
transaction: tx,
|
|
83
|
+
include: { commandResults: true, effects: true },
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
87
|
+
const parsed_mid_price = Number(bcs.U64.parse(bytes));
|
|
88
|
+
const adjusted_mid_price =
|
|
89
|
+
(parsed_mid_price * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;
|
|
90
|
+
|
|
91
|
+
return Number(adjusted_mid_price.toFixed(9));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async poolTradeParams(poolKey: string): Promise<PoolTradeParams> {
|
|
95
|
+
const tx = new Transaction();
|
|
96
|
+
|
|
97
|
+
tx.add(this.#ctx.deepBook.poolTradeParams(poolKey));
|
|
98
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
99
|
+
transaction: tx,
|
|
100
|
+
include: { commandResults: true, effects: true },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
|
|
104
|
+
const makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
|
|
105
|
+
const stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
takerFee: Number(takerFee / FLOAT_SCALAR),
|
|
109
|
+
makerFee: Number(makerFee / FLOAT_SCALAR),
|
|
110
|
+
stakeRequired: Number(stakeRequired / DEEP_SCALAR),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async poolBookParams(poolKey: string): Promise<PoolBookParams> {
|
|
115
|
+
const tx = new Transaction();
|
|
116
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
117
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
118
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
119
|
+
|
|
120
|
+
tx.add(this.#ctx.deepBook.poolBookParams(poolKey));
|
|
121
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
122
|
+
transaction: tx,
|
|
123
|
+
include: { commandResults: true, effects: true },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const tickSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
|
|
127
|
+
const lotSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
|
|
128
|
+
const minSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
tickSize: Number((tickSize * baseScalar) / quoteScalar / FLOAT_SCALAR),
|
|
132
|
+
lotSize: Number(lotSize / baseScalar),
|
|
133
|
+
minSize: Number(minSize / baseScalar),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async stablePool(poolKey: string): Promise<boolean> {
|
|
138
|
+
const tx = new Transaction();
|
|
139
|
+
tx.add(this.#ctx.deepBook.stablePool(poolKey));
|
|
140
|
+
|
|
141
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
142
|
+
transaction: tx,
|
|
143
|
+
include: { commandResults: true, effects: true },
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
147
|
+
return bcs.bool().parse(bytes);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async registeredPool(poolKey: string): Promise<boolean> {
|
|
151
|
+
const tx = new Transaction();
|
|
152
|
+
tx.add(this.#ctx.deepBook.registeredPool(poolKey));
|
|
153
|
+
|
|
154
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
155
|
+
transaction: tx,
|
|
156
|
+
include: { commandResults: true, effects: true },
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
160
|
+
return bcs.bool().parse(bytes);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async poolTradeParamsNext(poolKey: string): Promise<PoolTradeParams> {
|
|
164
|
+
const tx = new Transaction();
|
|
165
|
+
tx.add(this.#ctx.deepBook.poolTradeParamsNext(poolKey));
|
|
166
|
+
|
|
167
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
168
|
+
transaction: tx,
|
|
169
|
+
include: { commandResults: true, effects: true },
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
|
|
173
|
+
const makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
|
|
174
|
+
const stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
takerFee: takerFee / FLOAT_SCALAR,
|
|
178
|
+
makerFee: makerFee / FLOAT_SCALAR,
|
|
179
|
+
stakeRequired: stakeRequired / DEEP_SCALAR,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async quorum(poolKey: string): Promise<number> {
|
|
184
|
+
const tx = new Transaction();
|
|
185
|
+
tx.add(this.#ctx.deepBook.quorum(poolKey));
|
|
186
|
+
|
|
187
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
188
|
+
transaction: tx,
|
|
189
|
+
include: { commandResults: true, effects: true },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
193
|
+
const quorum = Number(bcs.U64.parse(bytes));
|
|
194
|
+
return quorum / DEEP_SCALAR;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async poolId(poolKey: string): Promise<string> {
|
|
198
|
+
const tx = new Transaction();
|
|
199
|
+
tx.add(this.#ctx.deepBook.poolId(poolKey));
|
|
200
|
+
|
|
201
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
202
|
+
transaction: tx,
|
|
203
|
+
include: { commandResults: true, effects: true },
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
207
|
+
return normalizeHaneulAddress(bcs.Address.parse(bytes));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async canPlaceLimitOrder(params: CanPlaceLimitOrderParams): Promise<boolean> {
|
|
211
|
+
const tx = new Transaction();
|
|
212
|
+
tx.add(this.#ctx.deepBook.canPlaceLimitOrder(params));
|
|
213
|
+
|
|
214
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
215
|
+
transaction: tx,
|
|
216
|
+
include: { commandResults: true, effects: true },
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
220
|
+
return bcs.bool().parse(bytes);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async canPlaceMarketOrder(params: CanPlaceMarketOrderParams): Promise<boolean> {
|
|
224
|
+
const tx = new Transaction();
|
|
225
|
+
tx.add(this.#ctx.deepBook.canPlaceMarketOrder(params));
|
|
226
|
+
|
|
227
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
228
|
+
transaction: tx,
|
|
229
|
+
include: { commandResults: true, effects: true },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
233
|
+
return bcs.bool().parse(bytes);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async checkMarketOrderParams(poolKey: string, quantity: number | bigint): Promise<boolean> {
|
|
237
|
+
const tx = new Transaction();
|
|
238
|
+
tx.add(this.#ctx.deepBook.checkMarketOrderParams(poolKey, quantity));
|
|
239
|
+
|
|
240
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
241
|
+
transaction: tx,
|
|
242
|
+
include: { commandResults: true, effects: true },
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
246
|
+
return bcs.bool().parse(bytes);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async checkLimitOrderParams(
|
|
250
|
+
poolKey: string,
|
|
251
|
+
price: number | bigint,
|
|
252
|
+
quantity: number | bigint,
|
|
253
|
+
expireTimestamp: number,
|
|
254
|
+
): Promise<boolean> {
|
|
255
|
+
const tx = new Transaction();
|
|
256
|
+
tx.add(this.#ctx.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));
|
|
257
|
+
|
|
258
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
259
|
+
transaction: tx,
|
|
260
|
+
include: { commandResults: true, effects: true },
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
264
|
+
return bcs.bool().parse(bytes);
|
|
265
|
+
}
|
|
266
|
+
}
|