@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,373 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _config, _MarginAdminContract_instances, marginAdminCap_fn;
|
|
10
|
+
import { FLOAT_SCALAR } from "../utils/config.js";
|
|
11
|
+
import { hexToBytes } from "@noble/hashes/utils";
|
|
12
|
+
class MarginAdminContract {
|
|
13
|
+
/**
|
|
14
|
+
* @param {DeepBookConfig} config Configuration for MarginAdminContract
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
__privateAdd(this, _MarginAdminContract_instances);
|
|
18
|
+
__privateAdd(this, _config);
|
|
19
|
+
/**
|
|
20
|
+
* @description Mint a maintainer cap
|
|
21
|
+
* @returns A function that takes a Transaction object
|
|
22
|
+
*/
|
|
23
|
+
this.mintMaintainerCap = () => (tx) => {
|
|
24
|
+
return tx.moveCall({
|
|
25
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::mint_maintainer_cap`,
|
|
26
|
+
arguments: [
|
|
27
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
28
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
29
|
+
tx.object.clock()
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @description Revoke a maintainer cap
|
|
35
|
+
* @returns A function that takes a Transaction object
|
|
36
|
+
*/
|
|
37
|
+
this.revokeMaintainerCap = (maintainerCapId) => (tx) => {
|
|
38
|
+
tx.moveCall({
|
|
39
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::revoke_maintainer_cap`,
|
|
40
|
+
arguments: [
|
|
41
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
42
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
43
|
+
tx.object(maintainerCapId),
|
|
44
|
+
tx.object.clock()
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @description Register a deepbook pool
|
|
50
|
+
* @param {string} poolKey The key of the pool to be registered
|
|
51
|
+
* @param {TransactionArgument} poolConfig The configuration of the pool
|
|
52
|
+
* @returns A function that takes a Transaction object
|
|
53
|
+
*/
|
|
54
|
+
this.registerDeepbookPool = (poolKey, poolConfig) => (tx) => {
|
|
55
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
56
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
57
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
58
|
+
tx.moveCall({
|
|
59
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::register_deepbook_pool`,
|
|
60
|
+
arguments: [
|
|
61
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
62
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
63
|
+
tx.object(pool.address),
|
|
64
|
+
poolConfig,
|
|
65
|
+
tx.object.clock()
|
|
66
|
+
],
|
|
67
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @description Enable a deepbook pool for margin trading
|
|
72
|
+
* @param {string} poolKey The key of the pool to be enabled
|
|
73
|
+
* @returns A function that takes a Transaction object
|
|
74
|
+
*/
|
|
75
|
+
this.enableDeepbookPool = (poolKey) => (tx) => {
|
|
76
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
77
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
78
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
79
|
+
tx.moveCall({
|
|
80
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::enable_deepbook_pool`,
|
|
81
|
+
arguments: [
|
|
82
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
83
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
84
|
+
tx.object(pool.address),
|
|
85
|
+
tx.object.clock()
|
|
86
|
+
],
|
|
87
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @description Disable a deepbook pool from margin trading
|
|
92
|
+
* @param {string} poolKey The key of the pool to be disabled
|
|
93
|
+
* @returns A function that takes a Transaction object
|
|
94
|
+
*/
|
|
95
|
+
this.disableDeepbookPool = (poolKey) => (tx) => {
|
|
96
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
97
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
98
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
99
|
+
tx.moveCall({
|
|
100
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::disable_deepbook_pool`,
|
|
101
|
+
arguments: [
|
|
102
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
103
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
104
|
+
tx.object(pool.address),
|
|
105
|
+
tx.object.clock()
|
|
106
|
+
],
|
|
107
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* @description Update the risk parameters for a margin
|
|
112
|
+
* @param {string} poolKey The key of the pool to be updated
|
|
113
|
+
* @param {TransactionArgument} poolConfig The configuration of the pool
|
|
114
|
+
* @returns A function that takes a Transaction object
|
|
115
|
+
*/
|
|
116
|
+
this.updateRiskParams = (poolKey, poolConfig) => (tx) => {
|
|
117
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
118
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
119
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
120
|
+
tx.moveCall({
|
|
121
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::update_risk_params`,
|
|
122
|
+
arguments: [
|
|
123
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
124
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
125
|
+
tx.object(pool.address),
|
|
126
|
+
poolConfig,
|
|
127
|
+
tx.object.clock()
|
|
128
|
+
],
|
|
129
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* @description Add the PythConfig to the margin registry
|
|
134
|
+
* @param {Transaction} tx The transaction object
|
|
135
|
+
* @param {TransactionArgument} config The config to be added
|
|
136
|
+
* @returns A function that takes a Transaction object
|
|
137
|
+
*/
|
|
138
|
+
this.addConfig = (config) => (tx) => {
|
|
139
|
+
tx.moveCall({
|
|
140
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::add_config`,
|
|
141
|
+
arguments: [
|
|
142
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
143
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
144
|
+
config
|
|
145
|
+
],
|
|
146
|
+
typeArguments: [`${__privateGet(this, _config).MARGIN_PACKAGE_ID}::oracle::PythConfig`]
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* @description Remove the PythConfig from the margin registry
|
|
151
|
+
* @param {Transaction} tx The transaction object
|
|
152
|
+
* @returns A function that takes a Transaction object
|
|
153
|
+
*/
|
|
154
|
+
this.removeConfig = () => (tx) => {
|
|
155
|
+
tx.moveCall({
|
|
156
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::remove_config`,
|
|
157
|
+
arguments: [tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID), tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this))],
|
|
158
|
+
typeArguments: [`${__privateGet(this, _config).MARGIN_PACKAGE_ID}::oracle::PythConfig`]
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* @description Enable a specific version
|
|
163
|
+
* @param {number} version The version to be enabled
|
|
164
|
+
* @returns A function that takes a Transaction object
|
|
165
|
+
*/
|
|
166
|
+
this.enableVersion = (version) => (tx) => {
|
|
167
|
+
tx.moveCall({
|
|
168
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::enable_version`,
|
|
169
|
+
arguments: [
|
|
170
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
171
|
+
tx.pure.u64(version),
|
|
172
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this))
|
|
173
|
+
]
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* @description Disable a specific version
|
|
178
|
+
* @param {number} version The version to be disabled
|
|
179
|
+
* @returns A function that takes a Transaction object
|
|
180
|
+
*/
|
|
181
|
+
this.disableVersion = (version) => (tx) => {
|
|
182
|
+
tx.moveCall({
|
|
183
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::disable_version`,
|
|
184
|
+
arguments: [
|
|
185
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
186
|
+
tx.pure.u64(version),
|
|
187
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this))
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* @description Create a new pool config
|
|
193
|
+
* @param {string} poolKey The key to identify the pool
|
|
194
|
+
* @param {PoolConfigParams} poolConfigParams The parameters for the pool config
|
|
195
|
+
* @returns A function that takes a Transaction object
|
|
196
|
+
*/
|
|
197
|
+
this.newPoolConfig = (poolKey, poolConfigParams) => (tx) => {
|
|
198
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
199
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
200
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
201
|
+
const {
|
|
202
|
+
minWithdrawRiskRatio,
|
|
203
|
+
minBorrowRiskRatio,
|
|
204
|
+
liquidationRiskRatio,
|
|
205
|
+
targetLiquidationRiskRatio,
|
|
206
|
+
userLiquidationReward,
|
|
207
|
+
poolLiquidationReward
|
|
208
|
+
} = poolConfigParams;
|
|
209
|
+
return tx.moveCall({
|
|
210
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,
|
|
211
|
+
arguments: [
|
|
212
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
213
|
+
tx.pure.u64(minWithdrawRiskRatio * FLOAT_SCALAR),
|
|
214
|
+
tx.pure.u64(minBorrowRiskRatio * FLOAT_SCALAR),
|
|
215
|
+
tx.pure.u64(liquidationRiskRatio * FLOAT_SCALAR),
|
|
216
|
+
tx.pure.u64(targetLiquidationRiskRatio * FLOAT_SCALAR),
|
|
217
|
+
tx.pure.u64(userLiquidationReward * FLOAT_SCALAR),
|
|
218
|
+
tx.pure.u64(poolLiquidationReward * FLOAT_SCALAR)
|
|
219
|
+
],
|
|
220
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* @description Create a new pool config with leverage
|
|
225
|
+
* @param {string} poolKey The key to identify the pool
|
|
226
|
+
* @param {number} leverage The leverage for the pool
|
|
227
|
+
* @returns A function that takes a Transaction object
|
|
228
|
+
*/
|
|
229
|
+
this.newPoolConfigWithLeverage = (poolKey, leverage) => (tx) => {
|
|
230
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
231
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
232
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
233
|
+
tx.moveCall({
|
|
234
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,
|
|
235
|
+
arguments: [tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID), tx.pure.u64(leverage * FLOAT_SCALAR)],
|
|
236
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* @description Create a new coin type data
|
|
241
|
+
* @param {string} coinKey The key to identify the coin
|
|
242
|
+
* @param {number} maxConfBps The maximum confidence interval in basis points
|
|
243
|
+
* @param {number} maxEwmaDifferenceBps The maximum EWMA difference in basis points
|
|
244
|
+
* @returns A function that takes a Transaction object
|
|
245
|
+
*/
|
|
246
|
+
this.newCoinTypeData = (coinKey, maxConfBps, maxEwmaDifferenceBps) => (tx) => {
|
|
247
|
+
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
248
|
+
if (!coin.feed) {
|
|
249
|
+
throw new Error("Coin feed not found");
|
|
250
|
+
}
|
|
251
|
+
const priceFeedInput = new Uint8Array(
|
|
252
|
+
hexToBytes(coin["feed"].startsWith("0x") ? coin.feed.slice(2) : coin["feed"])
|
|
253
|
+
);
|
|
254
|
+
return tx.moveCall({
|
|
255
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::oracle::new_coin_type_data_from_currency`,
|
|
256
|
+
arguments: [
|
|
257
|
+
tx.object(coin.currencyId),
|
|
258
|
+
tx.pure.vector("u8", priceFeedInput),
|
|
259
|
+
tx.pure.u64(maxConfBps),
|
|
260
|
+
tx.pure.u64(maxEwmaDifferenceBps)
|
|
261
|
+
],
|
|
262
|
+
typeArguments: [coin.type]
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* @description Create a new Pyth config
|
|
267
|
+
* @param {Array<{coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number}>} coinSetups The coins with their oracle config to be added to the Pyth config
|
|
268
|
+
* @param {number} maxAgeSeconds The max age in seconds for the Pyth config
|
|
269
|
+
* @returns A function that takes a Transaction object
|
|
270
|
+
*/
|
|
271
|
+
this.newPythConfig = (coinSetups, maxAgeSeconds) => (tx) => {
|
|
272
|
+
const coinTypeDataList = [];
|
|
273
|
+
for (const setup of coinSetups) {
|
|
274
|
+
coinTypeDataList.push(
|
|
275
|
+
this.newCoinTypeData(setup.coinKey, setup.maxConfBps, setup.maxEwmaDifferenceBps)(tx)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
return tx.moveCall({
|
|
279
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::oracle::new_pyth_config`,
|
|
280
|
+
arguments: [
|
|
281
|
+
tx.makeMoveVec({
|
|
282
|
+
elements: coinTypeDataList,
|
|
283
|
+
type: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::oracle::CoinTypeData`
|
|
284
|
+
}),
|
|
285
|
+
tx.pure.u64(maxAgeSeconds)
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* @description Mint a pause cap
|
|
291
|
+
* @returns A function that takes a Transaction object
|
|
292
|
+
*/
|
|
293
|
+
this.mintPauseCap = () => (tx) => {
|
|
294
|
+
return tx.moveCall({
|
|
295
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::mint_pause_cap`,
|
|
296
|
+
arguments: [
|
|
297
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
298
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
299
|
+
tx.object.clock()
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* @description Revoke a pause cap
|
|
305
|
+
* @param {string} pauseCapId The ID of the pause cap to revoke
|
|
306
|
+
* @returns A function that takes a Transaction object
|
|
307
|
+
*/
|
|
308
|
+
this.revokePauseCap = (pauseCapId) => (tx) => {
|
|
309
|
+
tx.moveCall({
|
|
310
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::revoke_pause_cap`,
|
|
311
|
+
arguments: [
|
|
312
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
313
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this)),
|
|
314
|
+
tx.object.clock(),
|
|
315
|
+
tx.pure.id(pauseCapId)
|
|
316
|
+
]
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* @description Disable a version using pause cap
|
|
321
|
+
* @param {number} version The version to disable
|
|
322
|
+
* @param {string} pauseCapId The ID of the pause cap
|
|
323
|
+
* @returns A function that takes a Transaction object
|
|
324
|
+
*/
|
|
325
|
+
this.disableVersionPauseCap = (version, pauseCapId) => (tx) => {
|
|
326
|
+
tx.moveCall({
|
|
327
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_registry::disable_version_pause_cap`,
|
|
328
|
+
arguments: [
|
|
329
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
330
|
+
tx.pure.u64(version),
|
|
331
|
+
tx.object(pauseCapId)
|
|
332
|
+
]
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* @description Withdraw the default referral fees (admin only)
|
|
337
|
+
* The default referral at 0x0 doesn't have a SupplyReferral object
|
|
338
|
+
* @param {string} coinKey The key to identify the margin pool
|
|
339
|
+
* @returns A function that takes a Transaction object and returns a Coin<Asset>
|
|
340
|
+
*/
|
|
341
|
+
this.adminWithdrawDefaultReferralFees = (coinKey) => (tx) => {
|
|
342
|
+
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
343
|
+
const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
|
|
344
|
+
return tx.moveCall({
|
|
345
|
+
target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::admin_withdraw_default_referral_fees`,
|
|
346
|
+
arguments: [
|
|
347
|
+
tx.object(marginPool.address),
|
|
348
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
349
|
+
tx.object(__privateMethod(this, _MarginAdminContract_instances, marginAdminCap_fn).call(this))
|
|
350
|
+
],
|
|
351
|
+
typeArguments: [coin.type]
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
__privateSet(this, _config, config);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
_config = new WeakMap();
|
|
358
|
+
_MarginAdminContract_instances = new WeakSet();
|
|
359
|
+
/**
|
|
360
|
+
* @returns The admin capability required for admin operations
|
|
361
|
+
* @throws Error if the admin capability is not set
|
|
362
|
+
*/
|
|
363
|
+
marginAdminCap_fn = function() {
|
|
364
|
+
const marginAdminCap = __privateGet(this, _config).marginAdminCap;
|
|
365
|
+
if (!marginAdminCap) {
|
|
366
|
+
throw new Error("MARGIN_ADMIN_CAP environment variable not set");
|
|
367
|
+
}
|
|
368
|
+
return marginAdminCap;
|
|
369
|
+
};
|
|
370
|
+
export {
|
|
371
|
+
MarginAdminContract
|
|
372
|
+
};
|
|
373
|
+
//# sourceMappingURL=marginAdmin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/transactions/marginAdmin.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@haneullabs/haneul/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { TransactionArgument } from '@haneullabs/haneul/transactions';\nimport type { PoolConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport { hexToBytes } from '@noble/hashes/utils';\n\n/**\n * MarginAdminContract class for managing admin actions.\n */\nexport class MarginAdminContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginAdminContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginAdminCap() {\n\t\tconst marginAdminCap = this.#config.marginAdminCap;\n\t\tif (!marginAdminCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginAdminCap;\n\t}\n\n\t/**\n\t * @description Mint a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintMaintainerCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokeMaintainerCap = (maintainerCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(maintainerCapId),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Register a deepbook pool\n\t * @param {string} poolKey The key of the pool to be registered\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tregisterDeepbookPool =\n\t\t(poolKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::register_deepbook_pool`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\tpoolConfig,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Enable a deepbook pool for margin trading\n\t * @param {string} poolKey The key of the pool to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a deepbook pool from margin trading\n\t * @param {string} poolKey The key of the pool to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Update the risk parameters for a margin\n\t * @param {string} poolKey The key of the pool to be updated\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateRiskParams = (poolKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::update_risk_params`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Add the PythConfig to the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @param {TransactionArgument} config The config to be added\n\t * @returns A function that takes a Transaction object\n\t */\n\taddConfig = (config: TransactionArgument) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::add_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\tconfig,\n\t\t\t],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Remove the PythConfig from the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @returns A function that takes a Transaction object\n\t */\n\tremoveConfig = () => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::remove_config`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object(this.#marginAdminCap())],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a specific version\n\t * @param {number} version The version to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a specific version\n\t * @param {number} version The version to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PoolConfigParams} poolConfigParams The parameters for the pool config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfig = (poolKey: string, poolConfigParams: PoolConfigParams) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst {\n\t\t\tminWithdrawRiskRatio,\n\t\t\tminBorrowRiskRatio,\n\t\t\tliquidationRiskRatio,\n\t\t\ttargetLiquidationRiskRatio,\n\t\t\tuserLiquidationReward,\n\t\t\tpoolLiquidationReward,\n\t\t} = poolConfigParams;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(minWithdrawRiskRatio * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(minBorrowRiskRatio * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(liquidationRiskRatio * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(targetLiquidationRiskRatio * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(userLiquidationReward * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(poolLiquidationReward * FLOAT_SCALAR),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config with leverage\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} leverage The leverage for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfigWithLeverage = (poolKey: string, leverage: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.u64(leverage * FLOAT_SCALAR)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new coin type data\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {number} maxConfBps The maximum confidence interval in basis points\n\t * @param {number} maxEwmaDifferenceBps The maximum EWMA difference in basis points\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewCoinTypeData =\n\t\t(coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tif (!coin.feed) {\n\t\t\t\tthrow new Error('Coin feed not found');\n\t\t\t}\n\t\t\tconst priceFeedInput = new Uint8Array(\n\t\t\t\thexToBytes(coin['feed']!.startsWith('0x') ? coin.feed!.slice(2) : coin['feed']),\n\t\t\t);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_coin_type_data_from_currency`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(coin.currencyId!),\n\t\t\t\t\ttx.pure.vector('u8', priceFeedInput),\n\t\t\t\t\ttx.pure.u64(maxConfBps),\n\t\t\t\t\ttx.pure.u64(maxEwmaDifferenceBps),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new Pyth config\n\t * @param {Array<{coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number}>} coinSetups The coins with their oracle config to be added to the Pyth config\n\t * @param {number} maxAgeSeconds The max age in seconds for the Pyth config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPythConfig =\n\t\t(\n\t\t\tcoinSetups: Array<{ coinKey: string; maxConfBps: number; maxEwmaDifferenceBps: number }>,\n\t\t\tmaxAgeSeconds: number,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coinTypeDataList = [];\n\t\t\tfor (const setup of coinSetups) {\n\t\t\t\tcoinTypeDataList.push(\n\t\t\t\t\tthis.newCoinTypeData(setup.coinKey, setup.maxConfBps, setup.maxEwmaDifferenceBps)(tx),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_pyth_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.makeMoveVec({\n\t\t\t\t\t\telements: coinTypeDataList,\n\t\t\t\t\t\ttype: `${this.#config.MARGIN_PACKAGE_ID}::oracle::CoinTypeData`,\n\t\t\t\t\t}),\n\t\t\t\t\ttx.pure.u64(maxAgeSeconds),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Mint a pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintPauseCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a pause cap\n\t * @param {string} pauseCapId The ID of the pause cap to revoke\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokePauseCap = (pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t\ttx.pure.id(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a version using pause cap\n\t * @param {number} version The version to disable\n\t * @param {string} pauseCapId The ID of the pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersionPauseCap = (version: number, pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw the default referral fees (admin only)\n\t * The default referral at 0x0 doesn't have a SupplyReferral object\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @returns A function that takes a Transaction object and returns a Coin<Asset>\n\t */\n\tadminWithdrawDefaultReferralFees = (coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::admin_withdraw_default_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;AAQA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAKpB,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAMhC,YAAY,QAAwB;AAN9B;AACN;AAyBA;AAAA;AAAA;AAAA;AAAA,6BAAoB,MAAM,CAAC,OAAoB;AAC9C,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA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QACzC,WAAW;AAAA,UACV,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC,GAAG,KAAK,IAAI,OAAO;AAAA,UACnB,GAAG,OAAO,UAAU;AAAA,QACrB;AAAA,MACD,CAAC;AAAA,IACF;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4CAAmC,CAAC,YAAoB,CAAC,OAAoB;AAC5E,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,WAAW,OAAO;AAAA,UAC5B,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC,GAAG,OAAO,sBAAK,mDAAL,UAAsB;AAAA,QACjC;AAAA,QACA,eAAe,CAAC,KAAK,IAAI;AAAA,MAC1B,CAAC;AAAA,IACF;AArXC,uBAAK,SAAU;AAAA,EAChB;AAqXD;AA5XC;AADM;AAAA;AAAA;AAAA;AAAA;AAcN,oBAAe,WAAG;AACjB,QAAM,iBAAiB,mBAAK,SAAQ;AACpC,MAAI,CAAC,gBAAgB;AACpB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
2
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* MarginLiquidationsContract class for managing LiquidationVault operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MarginLiquidationsContract {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param {DeepBookConfig} config Configuration for MarginLiquidationsContract
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: DeepBookConfig);
|
|
12
|
+
/**
|
|
13
|
+
* @description Create a new liquidation vault
|
|
14
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
15
|
+
* @returns A function that takes a Transaction object
|
|
16
|
+
*/
|
|
17
|
+
createLiquidationVault: (liquidationAdminCap: string) => (tx: Transaction) => void;
|
|
18
|
+
/**
|
|
19
|
+
* @description Deposit coins into a liquidation vault
|
|
20
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
21
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
22
|
+
* @param {string} coinKey The key to identify the coin type
|
|
23
|
+
* @param {number} amount The amount to deposit
|
|
24
|
+
* @returns A function that takes a Transaction object
|
|
25
|
+
*/
|
|
26
|
+
deposit: (vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) => (tx: Transaction) => void;
|
|
27
|
+
/**
|
|
28
|
+
* @description Withdraw coins from a liquidation vault
|
|
29
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
30
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
31
|
+
* @param {string} coinKey The key to identify the coin type
|
|
32
|
+
* @param {number} amount The amount to withdraw
|
|
33
|
+
* @returns A function that takes a Transaction object and returns the withdrawn coin
|
|
34
|
+
*/
|
|
35
|
+
withdraw: (vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
36
|
+
/**
|
|
37
|
+
* @description Liquidate a margin manager by repaying base debt
|
|
38
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
39
|
+
* @param {string} managerAddress The margin manager address to liquidate
|
|
40
|
+
* @param {string} poolKey The key to identify the pool
|
|
41
|
+
* @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation
|
|
42
|
+
* @returns A function that takes a Transaction object
|
|
43
|
+
*/
|
|
44
|
+
liquidateBase: (vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) => (tx: Transaction) => void;
|
|
45
|
+
/**
|
|
46
|
+
* @description Liquidate a margin manager by repaying quote debt
|
|
47
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
48
|
+
* @param {string} managerAddress The margin manager address to liquidate
|
|
49
|
+
* @param {string} poolKey The key to identify the pool
|
|
50
|
+
* @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation
|
|
51
|
+
* @returns A function that takes a Transaction object
|
|
52
|
+
*/
|
|
53
|
+
liquidateQuote: (vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) => (tx: Transaction) => void;
|
|
54
|
+
/**
|
|
55
|
+
* @description Get the balance of a specific coin type in the liquidation vault
|
|
56
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
57
|
+
* @param {string} coinKey The key to identify the coin type
|
|
58
|
+
* @returns A function that takes a Transaction object
|
|
59
|
+
*/
|
|
60
|
+
balance: (vaultId: string, coinKey: string) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
61
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _config;
|
|
9
|
+
import { coinWithBalance } from "@haneullabs/haneul/transactions";
|
|
10
|
+
class MarginLiquidationsContract {
|
|
11
|
+
/**
|
|
12
|
+
* @param {DeepBookConfig} config Configuration for MarginLiquidationsContract
|
|
13
|
+
*/
|
|
14
|
+
constructor(config) {
|
|
15
|
+
__privateAdd(this, _config);
|
|
16
|
+
/**
|
|
17
|
+
* @description Create a new liquidation vault
|
|
18
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
19
|
+
* @returns A function that takes a Transaction object
|
|
20
|
+
*/
|
|
21
|
+
this.createLiquidationVault = (liquidationAdminCap) => (tx) => {
|
|
22
|
+
tx.moveCall({
|
|
23
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::create_liquidation_vault`,
|
|
24
|
+
arguments: [tx.object(liquidationAdminCap)]
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @description Deposit coins into a liquidation vault
|
|
29
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
30
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
31
|
+
* @param {string} coinKey The key to identify the coin type
|
|
32
|
+
* @param {number} amount The amount to deposit
|
|
33
|
+
* @returns A function that takes a Transaction object
|
|
34
|
+
*/
|
|
35
|
+
this.deposit = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
|
|
36
|
+
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
37
|
+
const depositCoin = coinWithBalance({
|
|
38
|
+
type: coin.type,
|
|
39
|
+
balance: amount * coin.scalar
|
|
40
|
+
});
|
|
41
|
+
tx.moveCall({
|
|
42
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,
|
|
43
|
+
arguments: [tx.object(vaultId), tx.object(liquidationAdminCap), depositCoin],
|
|
44
|
+
typeArguments: [coin.type]
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @description Withdraw coins from a liquidation vault
|
|
49
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
50
|
+
* @param {string} liquidationAdminCap The liquidation admin cap object ID
|
|
51
|
+
* @param {string} coinKey The key to identify the coin type
|
|
52
|
+
* @param {number} amount The amount to withdraw
|
|
53
|
+
* @returns A function that takes a Transaction object and returns the withdrawn coin
|
|
54
|
+
*/
|
|
55
|
+
this.withdraw = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
|
|
56
|
+
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
57
|
+
return tx.moveCall({
|
|
58
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::withdraw`,
|
|
59
|
+
arguments: [
|
|
60
|
+
tx.object(vaultId),
|
|
61
|
+
tx.object(liquidationAdminCap),
|
|
62
|
+
tx.pure.u64(amount * coin.scalar)
|
|
63
|
+
],
|
|
64
|
+
typeArguments: [coin.type]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @description Liquidate a margin manager by repaying base debt
|
|
69
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
70
|
+
* @param {string} managerAddress The margin manager address to liquidate
|
|
71
|
+
* @param {string} poolKey The key to identify the pool
|
|
72
|
+
* @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation
|
|
73
|
+
* @returns A function that takes a Transaction object
|
|
74
|
+
*/
|
|
75
|
+
this.liquidateBase = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
|
|
76
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
77
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
78
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
79
|
+
const baseMarginPool = __privateGet(this, _config).getMarginPool(pool.baseCoin);
|
|
80
|
+
const quoteMarginPool = __privateGet(this, _config).getMarginPool(pool.quoteCoin);
|
|
81
|
+
const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * baseCoin.scalar))) : tx.pure.option("u64", null);
|
|
82
|
+
tx.moveCall({
|
|
83
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,
|
|
84
|
+
arguments: [
|
|
85
|
+
tx.object(vaultId),
|
|
86
|
+
tx.object(managerAddress),
|
|
87
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
88
|
+
tx.object(baseCoin.priceInfoObjectId),
|
|
89
|
+
tx.object(quoteCoin.priceInfoObjectId),
|
|
90
|
+
tx.object(baseMarginPool.address),
|
|
91
|
+
tx.object(quoteMarginPool.address),
|
|
92
|
+
tx.object(pool.address),
|
|
93
|
+
repayAmountArg,
|
|
94
|
+
tx.object.clock()
|
|
95
|
+
],
|
|
96
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @description Liquidate a margin manager by repaying quote debt
|
|
101
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
102
|
+
* @param {string} managerAddress The margin manager address to liquidate
|
|
103
|
+
* @param {string} poolKey The key to identify the pool
|
|
104
|
+
* @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation
|
|
105
|
+
* @returns A function that takes a Transaction object
|
|
106
|
+
*/
|
|
107
|
+
this.liquidateQuote = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
|
|
108
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
109
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
110
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
111
|
+
const baseMarginPool = __privateGet(this, _config).getMarginPool(pool.baseCoin);
|
|
112
|
+
const quoteMarginPool = __privateGet(this, _config).getMarginPool(pool.quoteCoin);
|
|
113
|
+
const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * quoteCoin.scalar))) : tx.pure.option("u64", null);
|
|
114
|
+
tx.moveCall({
|
|
115
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,
|
|
116
|
+
arguments: [
|
|
117
|
+
tx.object(vaultId),
|
|
118
|
+
tx.object(managerAddress),
|
|
119
|
+
tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
|
|
120
|
+
tx.object(baseCoin.priceInfoObjectId),
|
|
121
|
+
tx.object(quoteCoin.priceInfoObjectId),
|
|
122
|
+
tx.object(baseMarginPool.address),
|
|
123
|
+
tx.object(quoteMarginPool.address),
|
|
124
|
+
tx.object(pool.address),
|
|
125
|
+
repayAmountArg,
|
|
126
|
+
tx.object.clock()
|
|
127
|
+
],
|
|
128
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
// === Read-Only Functions ===
|
|
132
|
+
/**
|
|
133
|
+
* @description Get the balance of a specific coin type in the liquidation vault
|
|
134
|
+
* @param {string} vaultId The liquidation vault object ID
|
|
135
|
+
* @param {string} coinKey The key to identify the coin type
|
|
136
|
+
* @returns A function that takes a Transaction object
|
|
137
|
+
*/
|
|
138
|
+
this.balance = (vaultId, coinKey) => (tx) => {
|
|
139
|
+
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
140
|
+
return tx.moveCall({
|
|
141
|
+
target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::balance`,
|
|
142
|
+
arguments: [tx.object(vaultId)],
|
|
143
|
+
typeArguments: [coin.type]
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
__privateSet(this, _config, config);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
_config = new WeakMap();
|
|
150
|
+
export {
|
|
151
|
+
MarginLiquidationsContract
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=marginLiquidations.js.map
|