@haneullabs/deepbook-v3 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +984 -0
- package/README.md +1 -0
- package/dist/cjs/client.d.ts +861 -0
- package/dist/cjs/client.js +1982 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/contracts/deepbook/account.d.ts +105 -0
- package/dist/cjs/contracts/deepbook/account.js +163 -0
- package/dist/cjs/contracts/deepbook/account.js.map +7 -0
- package/dist/cjs/contracts/deepbook/balance_manager.d.ts +268 -0
- package/dist/cjs/contracts/deepbook/balance_manager.js +361 -0
- package/dist/cjs/contracts/deepbook/balance_manager.js.map +7 -0
- package/dist/cjs/contracts/deepbook/balances.d.ts +10 -0
- package/dist/cjs/contracts/deepbook/balances.js +35 -0
- package/dist/cjs/contracts/deepbook/balances.js.map +7 -0
- package/dist/cjs/contracts/deepbook/big_vector.d.ts +62 -0
- package/dist/cjs/contracts/deepbook/big_vector.js +80 -0
- package/dist/cjs/contracts/deepbook/big_vector.js.map +7 -0
- package/dist/cjs/contracts/deepbook/book.d.ts +34 -0
- package/dist/cjs/contracts/deepbook/book.js +50 -0
- package/dist/cjs/contracts/deepbook/book.js.map +7 -0
- package/dist/cjs/contracts/deepbook/constants.d.ts +176 -0
- package/dist/cjs/contracts/deepbook/constants.js +338 -0
- package/dist/cjs/contracts/deepbook/constants.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deep_price.d.ts +60 -0
- package/dist/cjs/contracts/deepbook/deep_price.js +87 -0
- package/dist/cjs/contracts/deepbook/deep_price.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +14 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js +42 -0
- package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js +47 -0
- package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +9 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +5 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.js +33 -0
- package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +28 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.js +47 -0
- package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +45 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +35 -0
- package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +45 -0
- package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +7 -0
- package/dist/cjs/contracts/deepbook/ewma.d.ts +17 -0
- package/dist/cjs/contracts/deepbook/ewma.js +39 -0
- package/dist/cjs/contracts/deepbook/ewma.js.map +7 -0
- package/dist/cjs/contracts/deepbook/fill.d.ts +153 -0
- package/dist/cjs/contracts/deepbook/fill.js +251 -0
- package/dist/cjs/contracts/deepbook/fill.js.map +7 -0
- package/dist/cjs/contracts/deepbook/governance.d.ts +63 -0
- package/dist/cjs/contracts/deepbook/governance.js +79 -0
- package/dist/cjs/contracts/deepbook/governance.js.map +7 -0
- package/dist/cjs/contracts/deepbook/history.d.ts +60 -0
- package/dist/cjs/contracts/deepbook/history.js +78 -0
- package/dist/cjs/contracts/deepbook/history.js.map +7 -0
- package/dist/cjs/contracts/deepbook/math.d.ts +94 -0
- package/dist/cjs/contracts/deepbook/math.js +132 -0
- package/dist/cjs/contracts/deepbook/math.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order.d.ts +135 -0
- package/dist/cjs/contracts/deepbook/order.js +218 -0
- package/dist/cjs/contracts/deepbook/order.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order_info.d.ts +296 -0
- package/dist/cjs/contracts/deepbook/order_info.js +386 -0
- package/dist/cjs/contracts/deepbook/order_info.js.map +7 -0
- package/dist/cjs/contracts/deepbook/order_query.d.ts +85 -0
- package/dist/cjs/contracts/deepbook/order_query.js +96 -0
- package/dist/cjs/contracts/deepbook/order_query.js.map +7 -0
- package/dist/cjs/contracts/deepbook/pool.d.ts +1218 -0
- package/dist/cjs/contracts/deepbook/pool.js +1236 -0
- package/dist/cjs/contracts/deepbook/pool.js.map +7 -0
- package/dist/cjs/contracts/deepbook/registry.d.ts +134 -0
- package/dist/cjs/contracts/deepbook/registry.js +182 -0
- package/dist/cjs/contracts/deepbook/registry.js.map +7 -0
- package/dist/cjs/contracts/deepbook/state.d.ts +117 -0
- package/dist/cjs/contracts/deepbook/state.js +104 -0
- package/dist/cjs/contracts/deepbook/state.js.map +7 -0
- package/dist/cjs/contracts/deepbook/trade_params.d.ts +7 -0
- package/dist/cjs/contracts/deepbook/trade_params.js +35 -0
- package/dist/cjs/contracts/deepbook/trade_params.js.map +7 -0
- package/dist/cjs/contracts/deepbook/vault.d.ts +30 -0
- package/dist/cjs/contracts/deepbook/vault.js +65 -0
- package/dist/cjs/contracts/deepbook/vault.js.map +7 -0
- package/dist/cjs/contracts/utils/index.d.ts +25 -0
- package/dist/cjs/contracts/utils/index.js +148 -0
- package/dist/cjs/contracts/utils/index.js.map +7 -0
- package/dist/cjs/index.d.ts +23 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
- package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
- package/dist/cjs/pyth/pyth-helpers.js +36 -0
- package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
- package/dist/cjs/pyth/pyth.d.ts +65 -0
- package/dist/cjs/pyth/pyth.js +269 -0
- package/dist/cjs/pyth/pyth.js.map +7 -0
- package/dist/cjs/transactions/balanceManager.d.ts +168 -0
- package/dist/cjs/transactions/balanceManager.js +384 -0
- package/dist/cjs/transactions/balanceManager.js.map +7 -0
- package/dist/cjs/transactions/deepbook.d.ts +477 -0
- package/dist/cjs/transactions/deepbook.js +1335 -0
- package/dist/cjs/transactions/deepbook.js.map +7 -0
- package/dist/cjs/transactions/deepbookAdmin.d.ts +105 -0
- package/dist/cjs/transactions/deepbookAdmin.js +334 -0
- package/dist/cjs/transactions/deepbookAdmin.js.map +7 -0
- package/dist/cjs/transactions/flashLoans.d.ts +56 -0
- package/dist/cjs/transactions/flashLoans.js +124 -0
- package/dist/cjs/transactions/flashLoans.js.map +7 -0
- package/dist/cjs/transactions/governance.d.ts +42 -0
- package/dist/cjs/transactions/governance.js +135 -0
- package/dist/cjs/transactions/governance.js.map +7 -0
- package/dist/cjs/transactions/marginAdmin.d.ts +133 -0
- package/dist/cjs/transactions/marginAdmin.js +393 -0
- package/dist/cjs/transactions/marginAdmin.js.map +7 -0
- package/dist/cjs/transactions/marginLiquidations.d.ts +61 -0
- package/dist/cjs/transactions/marginLiquidations.js +173 -0
- package/dist/cjs/transactions/marginLiquidations.js.map +7 -0
- package/dist/cjs/transactions/marginMaintainer.d.ts +80 -0
- package/dist/cjs/transactions/marginMaintainer.js +251 -0
- package/dist/cjs/transactions/marginMaintainer.js.map +7 -0
- package/dist/cjs/transactions/marginManager.d.ts +236 -0
- package/dist/cjs/transactions/marginManager.js +688 -0
- package/dist/cjs/transactions/marginManager.js.map +7 -0
- package/dist/cjs/transactions/marginPool.d.ts +134 -0
- package/dist/cjs/transactions/marginPool.js +330 -0
- package/dist/cjs/transactions/marginPool.js.map +7 -0
- package/dist/cjs/transactions/marginRegistry.d.ts +94 -0
- package/dist/cjs/transactions/marginRegistry.js +221 -0
- package/dist/cjs/transactions/marginRegistry.js.map +7 -0
- package/dist/cjs/transactions/marginTPSL.d.ts +93 -0
- package/dist/cjs/transactions/marginTPSL.js +286 -0
- package/dist/cjs/transactions/marginTPSL.js.map +7 -0
- package/dist/cjs/transactions/poolProxy.d.ts +104 -0
- package/dist/cjs/transactions/poolProxy.js +435 -0
- package/dist/cjs/transactions/poolProxy.js.map +7 -0
- package/dist/cjs/types/bcs.d.ts +5 -0
- package/dist/cjs/types/bcs.js +33 -0
- package/dist/cjs/types/bcs.js.map +7 -0
- package/dist/cjs/types/index.d.ts +218 -0
- package/dist/cjs/types/index.js +38 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/utils/config.d.ts +65 -0
- package/dist/cjs/utils/config.js +144 -0
- package/dist/cjs/utils/config.js.map +7 -0
- package/dist/cjs/utils/constants.d.ts +76 -0
- package/dist/cjs/utils/constants.js +382 -0
- package/dist/cjs/utils/constants.js.map +7 -0
- package/dist/cjs/utils/errors.d.ts +42 -0
- package/dist/cjs/utils/errors.js +70 -0
- package/dist/cjs/utils/errors.js.map +7 -0
- package/dist/cjs/utils/validation.d.ts +50 -0
- package/dist/cjs/utils/validation.js +67 -0
- package/dist/cjs/utils/validation.js.map +7 -0
- package/dist/esm/client.d.ts +861 -0
- package/dist/esm/client.js +1967 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/contracts/deepbook/account.d.ts +105 -0
- package/dist/esm/contracts/deepbook/account.js +133 -0
- package/dist/esm/contracts/deepbook/account.js.map +7 -0
- package/dist/esm/contracts/deepbook/balance_manager.d.ts +268 -0
- package/dist/esm/contracts/deepbook/balance_manager.js +331 -0
- package/dist/esm/contracts/deepbook/balance_manager.js.map +7 -0
- package/dist/esm/contracts/deepbook/balances.d.ts +10 -0
- package/dist/esm/contracts/deepbook/balances.js +15 -0
- package/dist/esm/contracts/deepbook/balances.js.map +7 -0
- package/dist/esm/contracts/deepbook/big_vector.d.ts +62 -0
- package/dist/esm/contracts/deepbook/big_vector.js +50 -0
- package/dist/esm/contracts/deepbook/big_vector.js.map +7 -0
- package/dist/esm/contracts/deepbook/book.d.ts +34 -0
- package/dist/esm/contracts/deepbook/book.js +20 -0
- package/dist/esm/contracts/deepbook/book.js.map +7 -0
- package/dist/esm/contracts/deepbook/constants.d.ts +176 -0
- package/dist/esm/contracts/deepbook/constants.js +318 -0
- package/dist/esm/contracts/deepbook/constants.js.map +7 -0
- package/dist/esm/contracts/deepbook/deep_price.d.ts +60 -0
- package/dist/esm/contracts/deepbook/deep_price.js +67 -0
- package/dist/esm/contracts/deepbook/deep_price.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +14 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.js +22 -0
- package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +33 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.js +17 -0
- package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +9 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.js +13 -0
- package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +5 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.js +13 -0
- package/dist/esm/contracts/deepbook/deps/sui/object.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +28 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.js +17 -0
- package/dist/esm/contracts/deepbook/deps/sui/table.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +25 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js +15 -0
- package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +7 -0
- package/dist/esm/contracts/deepbook/ewma.d.ts +17 -0
- package/dist/esm/contracts/deepbook/ewma.js +19 -0
- package/dist/esm/contracts/deepbook/ewma.js.map +7 -0
- package/dist/esm/contracts/deepbook/fill.d.ts +153 -0
- package/dist/esm/contracts/deepbook/fill.js +221 -0
- package/dist/esm/contracts/deepbook/fill.js.map +7 -0
- package/dist/esm/contracts/deepbook/governance.d.ts +63 -0
- package/dist/esm/contracts/deepbook/governance.js +49 -0
- package/dist/esm/contracts/deepbook/governance.js.map +7 -0
- package/dist/esm/contracts/deepbook/history.d.ts +60 -0
- package/dist/esm/contracts/deepbook/history.js +48 -0
- package/dist/esm/contracts/deepbook/history.js.map +7 -0
- package/dist/esm/contracts/deepbook/math.d.ts +94 -0
- package/dist/esm/contracts/deepbook/math.js +112 -0
- package/dist/esm/contracts/deepbook/math.js.map +7 -0
- package/dist/esm/contracts/deepbook/order.d.ts +135 -0
- package/dist/esm/contracts/deepbook/order.js +188 -0
- package/dist/esm/contracts/deepbook/order.js.map +7 -0
- package/dist/esm/contracts/deepbook/order_info.d.ts +296 -0
- package/dist/esm/contracts/deepbook/order_info.js +356 -0
- package/dist/esm/contracts/deepbook/order_info.js.map +7 -0
- package/dist/esm/contracts/deepbook/order_query.d.ts +85 -0
- package/dist/esm/contracts/deepbook/order_query.js +66 -0
- package/dist/esm/contracts/deepbook/order_query.js.map +7 -0
- package/dist/esm/contracts/deepbook/pool.d.ts +1218 -0
- package/dist/esm/contracts/deepbook/pool.js +1206 -0
- package/dist/esm/contracts/deepbook/pool.js.map +7 -0
- package/dist/esm/contracts/deepbook/registry.d.ts +134 -0
- package/dist/esm/contracts/deepbook/registry.js +152 -0
- package/dist/esm/contracts/deepbook/registry.js.map +7 -0
- package/dist/esm/contracts/deepbook/state.d.ts +117 -0
- package/dist/esm/contracts/deepbook/state.js +74 -0
- package/dist/esm/contracts/deepbook/state.js.map +7 -0
- package/dist/esm/contracts/deepbook/trade_params.d.ts +7 -0
- package/dist/esm/contracts/deepbook/trade_params.js +15 -0
- package/dist/esm/contracts/deepbook/trade_params.js.map +7 -0
- package/dist/esm/contracts/deepbook/vault.d.ts +30 -0
- package/dist/esm/contracts/deepbook/vault.js +35 -0
- package/dist/esm/contracts/deepbook/vault.js.map +7 -0
- package/dist/esm/contracts/utils/index.d.ts +25 -0
- package/dist/esm/contracts/utils/index.js +128 -0
- package/dist/esm/contracts/utils/index.js.map +7 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.js +81 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/esm/pyth/PriceServiceConnection.js +38 -0
- package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
- package/dist/esm/pyth/pyth-helpers.js +16 -0
- package/dist/esm/pyth/pyth-helpers.js.map +7 -0
- package/dist/esm/pyth/pyth.d.ts +65 -0
- package/dist/esm/pyth/pyth.js +249 -0
- package/dist/esm/pyth/pyth.js.map +7 -0
- package/dist/esm/transactions/balanceManager.d.ts +168 -0
- package/dist/esm/transactions/balanceManager.js +364 -0
- package/dist/esm/transactions/balanceManager.js.map +7 -0
- package/dist/esm/transactions/deepbook.d.ts +477 -0
- package/dist/esm/transactions/deepbook.js +1321 -0
- package/dist/esm/transactions/deepbook.js.map +7 -0
- package/dist/esm/transactions/deepbookAdmin.d.ts +105 -0
- package/dist/esm/transactions/deepbookAdmin.js +314 -0
- package/dist/esm/transactions/deepbookAdmin.js.map +7 -0
- package/dist/esm/transactions/flashLoans.d.ts +56 -0
- package/dist/esm/transactions/flashLoans.js +104 -0
- package/dist/esm/transactions/flashLoans.js.map +7 -0
- package/dist/esm/transactions/governance.d.ts +42 -0
- package/dist/esm/transactions/governance.js +115 -0
- package/dist/esm/transactions/governance.js.map +7 -0
- package/dist/esm/transactions/marginAdmin.d.ts +133 -0
- package/dist/esm/transactions/marginAdmin.js +373 -0
- package/dist/esm/transactions/marginAdmin.js.map +7 -0
- package/dist/esm/transactions/marginLiquidations.d.ts +61 -0
- package/dist/esm/transactions/marginLiquidations.js +153 -0
- package/dist/esm/transactions/marginLiquidations.js.map +7 -0
- package/dist/esm/transactions/marginMaintainer.d.ts +80 -0
- package/dist/esm/transactions/marginMaintainer.js +231 -0
- package/dist/esm/transactions/marginMaintainer.js.map +7 -0
- package/dist/esm/transactions/marginManager.d.ts +236 -0
- package/dist/esm/transactions/marginManager.js +668 -0
- package/dist/esm/transactions/marginManager.js.map +7 -0
- package/dist/esm/transactions/marginPool.d.ts +134 -0
- package/dist/esm/transactions/marginPool.js +310 -0
- package/dist/esm/transactions/marginPool.js.map +7 -0
- package/dist/esm/transactions/marginRegistry.d.ts +94 -0
- package/dist/esm/transactions/marginRegistry.js +201 -0
- package/dist/esm/transactions/marginRegistry.js.map +7 -0
- package/dist/esm/transactions/marginTPSL.d.ts +93 -0
- package/dist/esm/transactions/marginTPSL.js +266 -0
- package/dist/esm/transactions/marginTPSL.js.map +7 -0
- package/dist/esm/transactions/poolProxy.d.ts +104 -0
- package/dist/esm/transactions/poolProxy.js +415 -0
- package/dist/esm/transactions/poolProxy.js.map +7 -0
- package/dist/esm/types/bcs.d.ts +5 -0
- package/dist/esm/types/bcs.js +13 -0
- package/dist/esm/types/bcs.js.map +7 -0
- package/dist/esm/types/index.d.ts +218 -0
- package/dist/esm/types/index.js +18 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/config.d.ts +65 -0
- package/dist/esm/utils/config.js +135 -0
- package/dist/esm/utils/config.js.map +7 -0
- package/dist/esm/utils/constants.d.ts +76 -0
- package/dist/esm/utils/constants.js +362 -0
- package/dist/esm/utils/constants.js.map +7 -0
- package/dist/esm/utils/errors.d.ts +42 -0
- package/dist/esm/utils/errors.js +50 -0
- package/dist/esm/utils/errors.js.map +7 -0
- package/dist/esm/utils/validation.d.ts +50 -0
- package/dist/esm/utils/validation.js +47 -0
- package/dist/esm/utils/validation.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/src/client.ts +2451 -0
- package/src/contracts/deepbook/account.ts +199 -0
- package/src/contracts/deepbook/balance_manager.ts +532 -0
- package/src/contracts/deepbook/balances.ts +19 -0
- package/src/contracts/deepbook/big_vector.ts +74 -0
- package/src/contracts/deepbook/book.ts +24 -0
- package/src/contracts/deepbook/constants.ts +458 -0
- package/src/contracts/deepbook/deep_price.ts +84 -0
- package/src/contracts/deepbook/deps/std/type_name.ts +23 -0
- package/src/contracts/deepbook/deps/sui/bag.ts +41 -0
- package/src/contracts/deepbook/deps/sui/balance.ts +18 -0
- package/src/contracts/deepbook/deps/sui/object.ts +14 -0
- package/src/contracts/deepbook/deps/sui/table.ts +36 -0
- package/src/contracts/deepbook/deps/sui/vec_map.ts +33 -0
- package/src/contracts/deepbook/deps/sui/vec_set.ts +22 -0
- package/src/contracts/deepbook/deps/sui/versioned.ts +13 -0
- package/src/contracts/deepbook/ewma.ts +26 -0
- package/src/contracts/deepbook/fill.ts +336 -0
- package/src/contracts/deepbook/governance.ts +52 -0
- package/src/contracts/deepbook/history.ts +51 -0
- package/src/contracts/deepbook/math.ts +210 -0
- package/src/contracts/deepbook/order.ts +269 -0
- package/src/contracts/deepbook/order_info.ts +513 -0
- package/src/contracts/deepbook/order_query.ts +115 -0
- package/src/contracts/deepbook/pool.ts +2269 -0
- package/src/contracts/deepbook/registry.ts +242 -0
- package/src/contracts/deepbook/state.ts +74 -0
- package/src/contracts/deepbook/trade_params.ts +16 -0
- package/src/contracts/deepbook/vault.ts +37 -0
- package/src/contracts/utils/index.ts +184 -0
- package/src/index.ts +95 -0
- package/src/pyth/PriceServiceConnection.ts +48 -0
- package/src/pyth/pyth-helpers.ts +23 -0
- package/src/pyth/pyth.ts +305 -0
- package/src/transactions/balanceManager.ts +399 -0
- package/src/transactions/deepbook.ts +1519 -0
- package/src/transactions/deepbookAdmin.ts +332 -0
- package/src/transactions/flashLoans.ts +123 -0
- package/src/transactions/governance.ts +123 -0
- package/src/transactions/marginAdmin.ts +396 -0
- package/src/transactions/marginLiquidations.ts +175 -0
- package/src/transactions/marginMaintainer.ts +280 -0
- package/src/transactions/marginManager.ts +708 -0
- package/src/transactions/marginPool.ts +339 -0
- package/src/transactions/marginRegistry.ts +212 -0
- package/src/transactions/marginTPSL.ts +296 -0
- package/src/transactions/poolProxy.ts +438 -0
- package/src/types/bcs.ts +8 -0
- package/src/types/index.ts +255 -0
- package/src/utils/config.ts +177 -0
- package/src/utils/constants.ts +374 -0
- package/src/utils/errors.ts +67 -0
- package/src/utils/validation.ts +91 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
5
|
+
|
|
6
|
+
import type { CreatePoolAdminParams, SetEwmaParams } from '../types/index.js';
|
|
7
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
8
|
+
import { FLOAT_SCALAR } from '../utils/config.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* DeepBookAdminContract class for managing admin actions.
|
|
12
|
+
*/
|
|
13
|
+
export class DeepBookAdminContract {
|
|
14
|
+
#config: DeepBookConfig;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {DeepBookConfig} config Configuration for DeepBookAdminContract
|
|
18
|
+
*/
|
|
19
|
+
constructor(config: DeepBookConfig) {
|
|
20
|
+
this.#config = config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns The admin capability required for admin operations
|
|
25
|
+
* @throws Error if the admin capability is not set
|
|
26
|
+
*/
|
|
27
|
+
#adminCap() {
|
|
28
|
+
const adminCap = this.#config.adminCap;
|
|
29
|
+
if (!adminCap) {
|
|
30
|
+
throw new Error('ADMIN_CAP environment variable not set');
|
|
31
|
+
}
|
|
32
|
+
return adminCap;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @description Create a new pool as admin
|
|
37
|
+
* @param {CreatePoolAdminParams} params Parameters for creating pool as admin
|
|
38
|
+
* @returns A function that takes a Transaction object
|
|
39
|
+
*/
|
|
40
|
+
createPoolAdmin = (params: CreatePoolAdminParams) => (tx: Transaction) => {
|
|
41
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
42
|
+
const { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, whitelisted, stablePool } =
|
|
43
|
+
params;
|
|
44
|
+
const baseCoin = this.#config.getCoin(baseCoinKey);
|
|
45
|
+
const quoteCoin = this.#config.getCoin(quoteCoinKey);
|
|
46
|
+
|
|
47
|
+
const baseScalar = baseCoin.scalar;
|
|
48
|
+
const quoteScalar = quoteCoin.scalar;
|
|
49
|
+
|
|
50
|
+
const adjustedTickSize = Math.round((tickSize * FLOAT_SCALAR * quoteScalar) / baseScalar);
|
|
51
|
+
const adjustedLotSize = Math.round(lotSize * baseScalar);
|
|
52
|
+
const adjustedMinSize = Math.round(minSize * baseScalar);
|
|
53
|
+
|
|
54
|
+
tx.moveCall({
|
|
55
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::create_pool_admin`,
|
|
56
|
+
arguments: [
|
|
57
|
+
tx.object(this.#config.REGISTRY_ID), // registry_id
|
|
58
|
+
tx.pure.u64(adjustedTickSize), // adjusted tick_size
|
|
59
|
+
tx.pure.u64(adjustedLotSize), // adjusted lot_size
|
|
60
|
+
tx.pure.u64(adjustedMinSize), // adjusted min_size
|
|
61
|
+
tx.pure.bool(whitelisted),
|
|
62
|
+
tx.pure.bool(stablePool),
|
|
63
|
+
tx.object(this.#adminCap()),
|
|
64
|
+
],
|
|
65
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description Unregister a pool as admin
|
|
71
|
+
* @param {string} poolKey The key of the pool to be unregistered by admin
|
|
72
|
+
* @returns A function that takes a Transaction object
|
|
73
|
+
*/
|
|
74
|
+
unregisterPoolAdmin = (poolKey: string) => (tx: Transaction) => {
|
|
75
|
+
const pool = this.#config.getPool(poolKey);
|
|
76
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
77
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
78
|
+
tx.moveCall({
|
|
79
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unregister_pool_admin`,
|
|
80
|
+
arguments: [
|
|
81
|
+
tx.object(pool.address),
|
|
82
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
83
|
+
tx.object(this.#adminCap()),
|
|
84
|
+
],
|
|
85
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @description Update the allowed versions for a pool
|
|
91
|
+
* @param {string} poolKey The key of the pool to be updated
|
|
92
|
+
* @returns A function that takes a Transaction object
|
|
93
|
+
*/
|
|
94
|
+
updateAllowedVersions = (poolKey: string) => (tx: Transaction) => {
|
|
95
|
+
const pool = this.#config.getPool(poolKey);
|
|
96
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
97
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
98
|
+
tx.moveCall({
|
|
99
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::update_allowed_versions`,
|
|
100
|
+
arguments: [
|
|
101
|
+
tx.object(pool.address),
|
|
102
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
103
|
+
tx.object(this.#adminCap()),
|
|
104
|
+
],
|
|
105
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @description Enable a specific version
|
|
111
|
+
* @param {number} version The version to be enabled
|
|
112
|
+
* @returns A function that takes a Transaction object
|
|
113
|
+
*/
|
|
114
|
+
enableVersion = (version: number) => (tx: Transaction) => {
|
|
115
|
+
tx.moveCall({
|
|
116
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::enable_version`,
|
|
117
|
+
arguments: [
|
|
118
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
119
|
+
tx.pure.u64(version),
|
|
120
|
+
tx.object(this.#adminCap()),
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @description Disable a specific version
|
|
127
|
+
* @param {number} version The version to be disabled
|
|
128
|
+
* @returns A function that takes a Transaction object
|
|
129
|
+
*/
|
|
130
|
+
disableVersion = (version: number) => (tx: Transaction) => {
|
|
131
|
+
tx.moveCall({
|
|
132
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::disable_version`,
|
|
133
|
+
arguments: [
|
|
134
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
135
|
+
tx.pure.u64(version),
|
|
136
|
+
tx.object(this.#adminCap()),
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @description Sets the treasury address where pool creation fees will be sent
|
|
143
|
+
* @param {string} treasuryAddress The treasury address
|
|
144
|
+
* @returns A function that takes a Transaction object
|
|
145
|
+
*/
|
|
146
|
+
setTreasuryAddress = (treasuryAddress: string) => (tx: Transaction) => {
|
|
147
|
+
tx.moveCall({
|
|
148
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::set_treasury_address`,
|
|
149
|
+
arguments: [
|
|
150
|
+
tx.object(this.#config.REGISTRY_ID),
|
|
151
|
+
tx.pure.address(treasuryAddress),
|
|
152
|
+
tx.object(this.#adminCap()),
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @description Add a coin to whitelist of stable coins
|
|
159
|
+
* @param {string} stableCoinKey The name of the stable coin to be added
|
|
160
|
+
* @returns A function that takes a Transaction object
|
|
161
|
+
*/
|
|
162
|
+
addStableCoin = (stableCoinKey: string) => (tx: Transaction) => {
|
|
163
|
+
const stableCoinType = this.#config.getCoin(stableCoinKey).type;
|
|
164
|
+
tx.moveCall({
|
|
165
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::add_stablecoin`,
|
|
166
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],
|
|
167
|
+
typeArguments: [stableCoinType],
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @description Remove a coin from whitelist of stable coins
|
|
173
|
+
* @param {string} stableCoinKey The name of the stable coin to be removed
|
|
174
|
+
* @returns A function that takes a Transaction object
|
|
175
|
+
*/
|
|
176
|
+
removeStableCoin = (stableCoinKey: string) => (tx: Transaction) => {
|
|
177
|
+
const stableCoinType = this.#config.getCoin(stableCoinKey).type;
|
|
178
|
+
tx.moveCall({
|
|
179
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::remove_stablecoin`,
|
|
180
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],
|
|
181
|
+
typeArguments: [stableCoinType],
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @description Adjust the tick size of a pool
|
|
187
|
+
* @param {string} poolKey The key to identify the pool
|
|
188
|
+
* @param {number} newTickSize The new tick size
|
|
189
|
+
* @returns A function that takes a Transaction object
|
|
190
|
+
*/
|
|
191
|
+
adjustTickSize = (poolKey: string, newTickSize: number) => (tx: Transaction) => {
|
|
192
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
193
|
+
const pool = this.#config.getPool(poolKey);
|
|
194
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
195
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
196
|
+
|
|
197
|
+
const baseScalar = baseCoin.scalar;
|
|
198
|
+
const quoteScalar = quoteCoin.scalar;
|
|
199
|
+
|
|
200
|
+
const adjustedTickSize = (newTickSize * FLOAT_SCALAR * quoteScalar) / baseScalar;
|
|
201
|
+
|
|
202
|
+
tx.moveCall({
|
|
203
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::adjust_tick_size_admin`,
|
|
204
|
+
arguments: [
|
|
205
|
+
tx.object(pool.address), // pool address
|
|
206
|
+
tx.pure.u64(adjustedTickSize), // adjusted tick_size
|
|
207
|
+
tx.object(this.#adminCap()),
|
|
208
|
+
tx.object.clock(),
|
|
209
|
+
],
|
|
210
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @description Adjust the lot size and min size of a pool
|
|
216
|
+
* @param {string} poolKey The key to identify the pool
|
|
217
|
+
* @param {number} newLotSize The new lot size
|
|
218
|
+
* @param {number} newMinSize The new min size
|
|
219
|
+
* @returns A function that takes a Transaction object
|
|
220
|
+
*/
|
|
221
|
+
adjustMinLotSize =
|
|
222
|
+
(poolKey: string, newLotSize: number, newMinSize: number) => (tx: Transaction) => {
|
|
223
|
+
tx.setSenderIfNotSet(this.#config.address);
|
|
224
|
+
const pool = this.#config.getPool(poolKey);
|
|
225
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
226
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
227
|
+
|
|
228
|
+
const baseScalar = baseCoin.scalar;
|
|
229
|
+
|
|
230
|
+
const adjustedLotSize = newLotSize * baseScalar;
|
|
231
|
+
const adjustedMinSize = newMinSize * baseScalar;
|
|
232
|
+
|
|
233
|
+
tx.moveCall({
|
|
234
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::adjust_min_lot_size_admin`,
|
|
235
|
+
arguments: [
|
|
236
|
+
tx.object(pool.address), // pool address
|
|
237
|
+
tx.pure.u64(adjustedLotSize),
|
|
238
|
+
tx.pure.u64(adjustedMinSize),
|
|
239
|
+
tx.object(this.#adminCap()),
|
|
240
|
+
tx.object.clock(),
|
|
241
|
+
],
|
|
242
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @description Initialize the balance manager map
|
|
248
|
+
* @returns A function that takes a Transaction object
|
|
249
|
+
*/
|
|
250
|
+
initBalanceManagerMap = () => (tx: Transaction) => {
|
|
251
|
+
tx.moveCall({
|
|
252
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::init_balance_manager_map`,
|
|
253
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @description Set the EWMA parameters for a pool
|
|
259
|
+
* @param {string} poolKey The key to identify the pool
|
|
260
|
+
* @param {SetEwmaParamsParams} params The parameters to set
|
|
261
|
+
* @returns A function that takes a Transaction object
|
|
262
|
+
*/
|
|
263
|
+
setEwmaParams = (poolKey: string, params: SetEwmaParams) => (tx: Transaction) => {
|
|
264
|
+
const { alpha, zScoreThreshold, additionalTakerFee } = params;
|
|
265
|
+
const adjustedAlpha = Math.round(alpha * FLOAT_SCALAR);
|
|
266
|
+
const adjustedZScoreThreshold = Math.round(zScoreThreshold * FLOAT_SCALAR);
|
|
267
|
+
const adjustedAdditionalTakerFee = Math.round(additionalTakerFee * FLOAT_SCALAR);
|
|
268
|
+
const pool = this.#config.getPool(poolKey);
|
|
269
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
270
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
271
|
+
|
|
272
|
+
tx.moveCall({
|
|
273
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::set_ewma_params`,
|
|
274
|
+
arguments: [
|
|
275
|
+
tx.object(pool.address),
|
|
276
|
+
tx.object(this.#adminCap()),
|
|
277
|
+
tx.pure.u64(adjustedAlpha),
|
|
278
|
+
tx.pure.u64(adjustedZScoreThreshold),
|
|
279
|
+
tx.pure.u64(adjustedAdditionalTakerFee),
|
|
280
|
+
tx.object.clock(),
|
|
281
|
+
],
|
|
282
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @description Enable or disable the EWMA state for a pool
|
|
288
|
+
* @param {string} poolKey The key to identify the pool
|
|
289
|
+
* @param {boolean} enable Whether to enable or disable the EWMA state
|
|
290
|
+
* @returns A function that takes a Transaction object
|
|
291
|
+
*/
|
|
292
|
+
enableEwmaState = (poolKey: string, enable: boolean) => (tx: Transaction) => {
|
|
293
|
+
const pool = this.#config.getPool(poolKey);
|
|
294
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
295
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
296
|
+
|
|
297
|
+
tx.moveCall({
|
|
298
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::enable_ewma_state`,
|
|
299
|
+
arguments: [
|
|
300
|
+
tx.object(pool.address),
|
|
301
|
+
tx.object(this.#adminCap()),
|
|
302
|
+
tx.pure.bool(enable),
|
|
303
|
+
tx.object.clock(),
|
|
304
|
+
],
|
|
305
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @description Authorize the MarginApp to access protected features of DeepBook
|
|
311
|
+
* @returns A function that takes a Transaction object
|
|
312
|
+
*/
|
|
313
|
+
authorizeMarginApp = () => (tx: Transaction) => {
|
|
314
|
+
tx.moveCall({
|
|
315
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::authorize_app`,
|
|
316
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],
|
|
317
|
+
typeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::margin_manager::MarginApp`],
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @description Deauthorize the MarginApp by removing its authorization key
|
|
323
|
+
* @returns A function that takes a Transaction object and returns a bool
|
|
324
|
+
*/
|
|
325
|
+
deauthorizeMarginApp = () => (tx: Transaction) => {
|
|
326
|
+
return tx.moveCall({
|
|
327
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::deauthorize_app`,
|
|
328
|
+
arguments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],
|
|
329
|
+
typeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::margin_manager::MarginApp`],
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
|
|
4
|
+
|
|
5
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* FlashLoanContract class for managing flash loans.
|
|
9
|
+
*/
|
|
10
|
+
export class FlashLoanContract {
|
|
11
|
+
#config: DeepBookConfig;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {DeepBookConfig} config Configuration object for DeepBook
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: DeepBookConfig) {
|
|
17
|
+
this.#config = config;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @description Borrow base asset from the pool
|
|
22
|
+
* @param {string} poolKey The key to identify the pool
|
|
23
|
+
* @param {number} borrowAmount The amount to borrow
|
|
24
|
+
* @returns A function that takes a Transaction object
|
|
25
|
+
*/
|
|
26
|
+
borrowBaseAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {
|
|
27
|
+
const pool = this.#config.getPool(poolKey);
|
|
28
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
29
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
30
|
+
const inputQuantity = Math.round(borrowAmount * baseCoin.scalar);
|
|
31
|
+
const [baseCoinResult, flashLoan] = tx.moveCall({
|
|
32
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,
|
|
33
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
34
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
35
|
+
});
|
|
36
|
+
return [baseCoinResult, flashLoan] as const;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description Return base asset to the pool after a flash loan.
|
|
41
|
+
* @param {string} poolKey The key to identify the pool
|
|
42
|
+
* @param {number} borrowAmount The amount of the base asset to return
|
|
43
|
+
* @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned
|
|
44
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
45
|
+
* @returns A function that takes a Transaction object
|
|
46
|
+
*/
|
|
47
|
+
returnBaseAsset =
|
|
48
|
+
(
|
|
49
|
+
poolKey: string,
|
|
50
|
+
borrowAmount: number,
|
|
51
|
+
baseCoinInput: TransactionObjectArgument,
|
|
52
|
+
flashLoan: TransactionObjectArgument,
|
|
53
|
+
) =>
|
|
54
|
+
(tx: Transaction) => {
|
|
55
|
+
const pool = this.#config.getPool(poolKey);
|
|
56
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
57
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
58
|
+
const borrowScalar = baseCoin.scalar;
|
|
59
|
+
|
|
60
|
+
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [
|
|
61
|
+
tx.pure.u64(Math.round(borrowAmount * borrowScalar)),
|
|
62
|
+
]);
|
|
63
|
+
tx.moveCall({
|
|
64
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,
|
|
65
|
+
arguments: [tx.object(pool.address), baseCoinReturn, flashLoan],
|
|
66
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return baseCoinInput;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @description Borrow quote asset from the pool
|
|
74
|
+
* @param {string} poolKey The key to identify the pool
|
|
75
|
+
* @param {number} borrowAmount The amount to borrow
|
|
76
|
+
* @returns A function that takes a Transaction object
|
|
77
|
+
*/
|
|
78
|
+
borrowQuoteAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {
|
|
79
|
+
const pool = this.#config.getPool(poolKey);
|
|
80
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
81
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
82
|
+
const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar);
|
|
83
|
+
const [quoteCoinResult, flashLoan] = tx.moveCall({
|
|
84
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,
|
|
85
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
86
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
87
|
+
});
|
|
88
|
+
return [quoteCoinResult, flashLoan] as const;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @description Return quote asset to the pool after a flash loan.
|
|
93
|
+
* @param {string} poolKey The key to identify the pool
|
|
94
|
+
* @param {number} borrowAmount The amount of the quote asset to return
|
|
95
|
+
* @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned
|
|
96
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
97
|
+
* @returns A function that takes a Transaction object
|
|
98
|
+
*/
|
|
99
|
+
returnQuoteAsset =
|
|
100
|
+
(
|
|
101
|
+
poolKey: string,
|
|
102
|
+
borrowAmount: number,
|
|
103
|
+
quoteCoinInput: TransactionObjectArgument,
|
|
104
|
+
flashLoan: TransactionObjectArgument,
|
|
105
|
+
) =>
|
|
106
|
+
(tx: Transaction) => {
|
|
107
|
+
const pool = this.#config.getPool(poolKey);
|
|
108
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
109
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
110
|
+
const borrowScalar = quoteCoin.scalar;
|
|
111
|
+
|
|
112
|
+
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [
|
|
113
|
+
tx.pure.u64(Math.round(borrowAmount * borrowScalar)),
|
|
114
|
+
]);
|
|
115
|
+
tx.moveCall({
|
|
116
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,
|
|
117
|
+
arguments: [tx.object(pool.address), quoteCoinReturn, flashLoan],
|
|
118
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return quoteCoinInput;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
4
|
+
|
|
5
|
+
import type { ProposalParams } from '../types/index.js';
|
|
6
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
7
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* GovernanceContract class for managing governance operations in DeepBook.
|
|
11
|
+
*/
|
|
12
|
+
export class GovernanceContract {
|
|
13
|
+
#config: DeepBookConfig;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {DeepBookConfig} config Configuration for GovernanceContract
|
|
17
|
+
*/
|
|
18
|
+
constructor(config: DeepBookConfig) {
|
|
19
|
+
this.#config = config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @description Stake a specified amount in the pool
|
|
24
|
+
* @param {string} poolKey The key to identify the pool
|
|
25
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
26
|
+
* @param {number} stakeAmount The amount to stake
|
|
27
|
+
* @returns A function that takes a Transaction object
|
|
28
|
+
*/
|
|
29
|
+
stake =
|
|
30
|
+
(poolKey: string, balanceManagerKey: string, stakeAmount: number) => (tx: Transaction) => {
|
|
31
|
+
const pool = this.#config.getPool(poolKey);
|
|
32
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
33
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
34
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
35
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
36
|
+
const stakeInput = Math.round(stakeAmount * DEEP_SCALAR);
|
|
37
|
+
|
|
38
|
+
tx.moveCall({
|
|
39
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,
|
|
40
|
+
arguments: [
|
|
41
|
+
tx.object(pool.address),
|
|
42
|
+
tx.object(balanceManager.address),
|
|
43
|
+
tradeProof,
|
|
44
|
+
tx.pure.u64(stakeInput),
|
|
45
|
+
],
|
|
46
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description Unstake from the pool
|
|
52
|
+
* @param {string} poolKey The key to identify the pool
|
|
53
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
54
|
+
* @returns A function that takes a Transaction object
|
|
55
|
+
*/
|
|
56
|
+
unstake = (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => {
|
|
57
|
+
const pool = this.#config.getPool(poolKey);
|
|
58
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
59
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
60
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
61
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
62
|
+
|
|
63
|
+
tx.moveCall({
|
|
64
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unstake`,
|
|
65
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
|
|
66
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @description Submit a governance proposal
|
|
72
|
+
* @param {ProposalParams} params Parameters for the proposal
|
|
73
|
+
* @returns A function that takes a Transaction object
|
|
74
|
+
*/
|
|
75
|
+
submitProposal = (params: ProposalParams) => (tx: Transaction) => {
|
|
76
|
+
const { poolKey, balanceManagerKey, takerFee, makerFee, stakeRequired } = params;
|
|
77
|
+
|
|
78
|
+
const pool = this.#config.getPool(poolKey);
|
|
79
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
80
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
81
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
82
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
83
|
+
|
|
84
|
+
tx.moveCall({
|
|
85
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::submit_proposal`,
|
|
86
|
+
arguments: [
|
|
87
|
+
tx.object(pool.address),
|
|
88
|
+
tx.object(balanceManager.address),
|
|
89
|
+
tradeProof,
|
|
90
|
+
tx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)),
|
|
91
|
+
tx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)),
|
|
92
|
+
tx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR)),
|
|
93
|
+
],
|
|
94
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description Vote on a proposal
|
|
100
|
+
* @param {string} poolKey The key to identify the pool
|
|
101
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
102
|
+
* @param {string} proposal_id The ID of the proposal to vote on
|
|
103
|
+
* @returns A function that takes a Transaction object
|
|
104
|
+
*/
|
|
105
|
+
vote = (poolKey: string, balanceManagerKey: string, proposal_id: string) => (tx: Transaction) => {
|
|
106
|
+
const pool = this.#config.getPool(poolKey);
|
|
107
|
+
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
108
|
+
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
109
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
110
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
111
|
+
|
|
112
|
+
tx.moveCall({
|
|
113
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::vote`,
|
|
114
|
+
arguments: [
|
|
115
|
+
tx.object(pool.address),
|
|
116
|
+
tx.object(balanceManager.address),
|
|
117
|
+
tradeProof,
|
|
118
|
+
tx.pure.id(proposal_id),
|
|
119
|
+
],
|
|
120
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|