@drift-labs/common 1.0.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/lib/Config.d.ts +26 -0
- package/lib/Config.js +29 -0
- package/lib/Config.js.map +1 -0
- package/lib/EnvironmentConstants.d.ts +40 -0
- package/lib/EnvironmentConstants.js +64 -0
- package/lib/EnvironmentConstants.js.map +1 -0
- package/lib/actions/actionHelpers/accountDeletionHelpers.d.ts +16 -0
- package/lib/actions/actionHelpers/accountDeletionHelpers.js +151 -0
- package/lib/actions/actionHelpers/accountDeletionHelpers.js.map +1 -0
- package/lib/actions/actionHelpers/actionHelpers.d.ts +13 -0
- package/lib/actions/actionHelpers/actionHelpers.js +8 -0
- package/lib/actions/actionHelpers/actionHelpers.js.map +1 -0
- package/lib/chartConstants.d.ts +2 -0
- package/lib/chartConstants.js +14 -0
- package/lib/chartConstants.js.map +1 -0
- package/lib/clients/candleClient.d.ts +74 -0
- package/lib/clients/candleClient.js +364 -0
- package/lib/clients/candleClient.js.map +1 -0
- package/lib/clients/dataApiWsClient.d.ts +33 -0
- package/lib/clients/dataApiWsClient.js +118 -0
- package/lib/clients/dataApiWsClient.js.map +1 -0
- package/lib/clients/index.d.ts +1 -0
- package/lib/clients/index.js +19 -0
- package/lib/clients/index.js.map +1 -0
- package/lib/clients/marketDataFeed.d.ts +42 -0
- package/lib/clients/marketDataFeed.js +422 -0
- package/lib/clients/marketDataFeed.js.map +1 -0
- package/lib/clients/redisClient.d.ts +89 -0
- package/lib/clients/redisClient.js +647 -0
- package/lib/clients/redisClient.js.map +1 -0
- package/lib/clients/swiftClient.d.ts +57 -0
- package/lib/clients/swiftClient.js +289 -0
- package/lib/clients/swiftClient.js.map +1 -0
- package/lib/clients/tvFeed.d.ts +63 -0
- package/lib/clients/tvFeed.js +351 -0
- package/lib/clients/tvFeed.js.map +1 -0
- package/lib/common-ui-utils/commonUiUtils.d.ts +211 -0
- package/lib/common-ui-utils/commonUiUtils.js +624 -0
- package/lib/common-ui-utils/commonUiUtils.js.map +1 -0
- package/lib/common-ui-utils/index.d.ts +6 -0
- package/lib/common-ui-utils/index.js +23 -0
- package/lib/common-ui-utils/index.js.map +1 -0
- package/lib/common-ui-utils/market.d.ts +27 -0
- package/lib/common-ui-utils/market.js +80 -0
- package/lib/common-ui-utils/market.js.map +1 -0
- package/lib/common-ui-utils/order.d.ts +11 -0
- package/lib/common-ui-utils/order.js +161 -0
- package/lib/common-ui-utils/order.js.map +1 -0
- package/lib/common-ui-utils/settings/settings.d.ts +51 -0
- package/lib/common-ui-utils/settings/settings.js +84 -0
- package/lib/common-ui-utils/settings/settings.js.map +1 -0
- package/lib/common-ui-utils/trading.d.ts +56 -0
- package/lib/common-ui-utils/trading.js +200 -0
- package/lib/common-ui-utils/trading.js.map +1 -0
- package/lib/common-ui-utils/user.d.ts +13 -0
- package/lib/common-ui-utils/user.js +124 -0
- package/lib/common-ui-utils/user.js.map +1 -0
- package/lib/constants/autogenerated/driftErrors.json +1787 -0
- package/lib/constants/autogenerated/jup-v4-error-codes.json +67 -0
- package/lib/constants/autogenerated/jup-v6-error-codes.json +115 -0
- package/lib/constants/dev.d.ts +15 -0
- package/lib/constants/dev.js +19 -0
- package/lib/constants/dev.js.map +1 -0
- package/lib/constants/geoblockList.d.ts +4 -0
- package/lib/constants/geoblockList.js +32 -0
- package/lib/constants/geoblockList.js.map +1 -0
- package/lib/constants/index.d.ts +9 -0
- package/lib/constants/index.js +26 -0
- package/lib/constants/index.js.map +1 -0
- package/lib/constants/markets.d.ts +1 -0
- package/lib/constants/markets.js +5 -0
- package/lib/constants/markets.js.map +1 -0
- package/lib/constants/misc.d.ts +23 -0
- package/lib/constants/misc.js +27 -0
- package/lib/constants/misc.js.map +1 -0
- package/lib/constants/orders.d.ts +12 -0
- package/lib/constants/orders.js +79 -0
- package/lib/constants/orders.js.map +1 -0
- package/lib/constants/pools.d.ts +5 -0
- package/lib/constants/pools.js +9 -0
- package/lib/constants/pools.js.map +1 -0
- package/lib/constants/predictionMarket.d.ts +3 -0
- package/lib/constants/predictionMarket.js +7 -0
- package/lib/constants/predictionMarket.js.map +1 -0
- package/lib/constants/superstake.d.ts +22 -0
- package/lib/constants/superstake.js +45 -0
- package/lib/constants/superstake.js.map +1 -0
- package/lib/constants/trade.d.ts +2 -0
- package/lib/constants/trade.js +9 -0
- package/lib/constants/trade.js.map +1 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.d.ts +68 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.js +146 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.js.map +1 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.d.ts +204 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +530 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +90 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js +3 -0
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -0
- package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.d.ts +139 -0
- package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.js +287 -0
- package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.js.map +1 -0
- package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +242 -0
- package/lib/drift/Drift/clients/AuthorityDrift/index.js +503 -0
- package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -0
- package/lib/drift/Drift/clients/CentralServerDrift.d.ts +91 -0
- package/lib/drift/Drift/clients/CentralServerDrift.js +326 -0
- package/lib/drift/Drift/clients/CentralServerDrift.js.map +1 -0
- package/lib/drift/Drift/clients/index.d.ts +3 -0
- package/lib/drift/Drift/clients/index.js +20 -0
- package/lib/drift/Drift/clients/index.js.map +1 -0
- package/lib/drift/Drift/constants/blockchain.d.ts +24 -0
- package/lib/drift/Drift/constants/blockchain.js +32 -0
- package/lib/drift/Drift/constants/blockchain.js.map +1 -0
- package/lib/drift/Drift/constants/errors.d.ts +6 -0
- package/lib/drift/Drift/constants/errors.js +14 -0
- package/lib/drift/Drift/constants/errors.js.map +1 -0
- package/lib/drift/Drift/constants/index.d.ts +3 -0
- package/lib/drift/Drift/constants/index.js +20 -0
- package/lib/drift/Drift/constants/index.js.map +1 -0
- package/lib/drift/Drift/constants/orderbook.d.ts +7 -0
- package/lib/drift/Drift/constants/orderbook.js +10 -0
- package/lib/drift/Drift/constants/orderbook.js.map +1 -0
- package/lib/drift/Drift/data/PollingDlob.d.ts +154 -0
- package/lib/drift/Drift/data/PollingDlob.js +387 -0
- package/lib/drift/Drift/data/PollingDlob.js.map +1 -0
- package/lib/drift/Drift/data/index.d.ts +1 -0
- package/lib/drift/Drift/data/index.js +18 -0
- package/lib/drift/Drift/data/index.js.map +1 -0
- package/lib/drift/Drift/index.d.ts +4 -0
- package/lib/drift/Drift/index.js +21 -0
- package/lib/drift/Drift/index.js.map +1 -0
- package/lib/drift/Drift/stores/MarkPriceCache.d.ts +27 -0
- package/lib/drift/Drift/stores/MarkPriceCache.js +59 -0
- package/lib/drift/Drift/stores/MarkPriceCache.js.map +1 -0
- package/lib/drift/Drift/stores/OraclePriceCache.d.ts +21 -0
- package/lib/drift/Drift/stores/OraclePriceCache.js +57 -0
- package/lib/drift/Drift/stores/OraclePriceCache.js.map +1 -0
- package/lib/drift/Drift/stores/UserAccountCache.d.ts +49 -0
- package/lib/drift/Drift/stores/UserAccountCache.js +107 -0
- package/lib/drift/Drift/stores/UserAccountCache.js.map +1 -0
- package/lib/drift/Drift/stores/index.d.ts +3 -0
- package/lib/drift/Drift/stores/index.js +20 -0
- package/lib/drift/Drift/stores/index.js.map +1 -0
- package/lib/drift/base/actions/index.d.ts +4 -0
- package/lib/drift/base/actions/index.js +21 -0
- package/lib/drift/base/actions/index.js.map +1 -0
- package/lib/drift/base/actions/perp/index.d.ts +2 -0
- package/lib/drift/base/actions/perp/index.js +19 -0
- package/lib/drift/base/actions/perp/index.js.map +1 -0
- package/lib/drift/base/actions/perp/settleFunding.d.ts +25 -0
- package/lib/drift/base/actions/perp/settleFunding.js +41 -0
- package/lib/drift/base/actions/perp/settleFunding.js.map +1 -0
- package/lib/drift/base/actions/perp/settlePnl.d.ts +35 -0
- package/lib/drift/base/actions/perp/settlePnl.js +44 -0
- package/lib/drift/base/actions/perp/settlePnl.js.map +1 -0
- package/lib/drift/base/actions/spot/borrow.d.ts +1 -0
- package/lib/drift/base/actions/spot/borrow.js +8 -0
- package/lib/drift/base/actions/spot/borrow.js.map +1 -0
- package/lib/drift/base/actions/spot/deposit.d.ts +40 -0
- package/lib/drift/base/actions/spot/deposit.js +82 -0
- package/lib/drift/base/actions/spot/deposit.js.map +1 -0
- package/lib/drift/base/actions/spot/index.d.ts +3 -0
- package/lib/drift/base/actions/spot/index.js +20 -0
- package/lib/drift/base/actions/spot/index.js.map +1 -0
- package/lib/drift/base/actions/spot/withdraw.d.ts +16 -0
- package/lib/drift/base/actions/spot/withdraw.js +39 -0
- package/lib/drift/base/actions/spot/withdraw.js.map +1 -0
- package/lib/drift/base/actions/trade/cancelOrder.d.ts +47 -0
- package/lib/drift/base/actions/trade/cancelOrder.js +55 -0
- package/lib/drift/base/actions/trade/cancelOrder.js.map +1 -0
- package/lib/drift/base/actions/trade/editOrder.d.ts +55 -0
- package/lib/drift/base/actions/trade/editOrder.js +35 -0
- package/lib/drift/base/actions/trade/editOrder.js.map +1 -0
- package/lib/drift/base/actions/trade/index.d.ts +4 -0
- package/lib/drift/base/actions/trade/index.js +21 -0
- package/lib/drift/base/actions/trade/index.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.d.ts +3 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js +20 -0
- package/lib/drift/base/actions/trade/openPerpOrder/index.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +84 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +293 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +19 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +161 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +166 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +156 -0
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -0
- package/lib/drift/base/actions/trade/swap.d.ts +62 -0
- package/lib/drift/base/actions/trade/swap.js +60 -0
- package/lib/drift/base/actions/trade/swap.js.map +1 -0
- package/lib/drift/base/actions/user/create.d.ts +75 -0
- package/lib/drift/base/actions/user/create.js +104 -0
- package/lib/drift/base/actions/user/create.js.map +1 -0
- package/lib/drift/base/actions/user/delete.d.ts +47 -0
- package/lib/drift/base/actions/user/delete.js +39 -0
- package/lib/drift/base/actions/user/delete.js.map +1 -0
- package/lib/drift/base/actions/user/index.d.ts +1 -0
- package/lib/drift/base/actions/user/index.js +18 -0
- package/lib/drift/base/actions/user/index.js.map +1 -0
- package/lib/drift/base/constants/accountNames.d.ts +1 -0
- package/lib/drift/base/constants/accountNames.js +13 -0
- package/lib/drift/base/constants/accountNames.js.map +1 -0
- package/lib/drift/base/details/index.d.ts +2 -0
- package/lib/drift/base/details/index.js +19 -0
- package/lib/drift/base/details/index.js.map +1 -0
- package/lib/drift/base/details/market/funding.d.ts +9 -0
- package/lib/drift/base/details/market/funding.js +50 -0
- package/lib/drift/base/details/market/funding.js.map +1 -0
- package/lib/drift/base/details/market/index.d.ts +2 -0
- package/lib/drift/base/details/market/index.js +19 -0
- package/lib/drift/base/details/market/index.js.map +1 -0
- package/lib/drift/base/details/market/openInterest.d.ts +5 -0
- package/lib/drift/base/details/market/openInterest.js +12 -0
- package/lib/drift/base/details/market/openInterest.js.map +1 -0
- package/lib/drift/base/details/user/balances.d.ts +40 -0
- package/lib/drift/base/details/user/balances.js +39 -0
- package/lib/drift/base/details/user/balances.js.map +1 -0
- package/lib/drift/base/details/user/index.d.ts +4 -0
- package/lib/drift/base/details/user/index.js +21 -0
- package/lib/drift/base/details/user/index.js.map +1 -0
- package/lib/drift/base/details/user/marginInfo.d.ts +29 -0
- package/lib/drift/base/details/user/marginInfo.js +49 -0
- package/lib/drift/base/details/user/marginInfo.js.map +1 -0
- package/lib/drift/base/details/user/orders.d.ts +3 -0
- package/lib/drift/base/details/user/orders.js +11 -0
- package/lib/drift/base/details/user/orders.js.map +1 -0
- package/lib/drift/base/details/user/positions.d.ts +70 -0
- package/lib/drift/base/details/user/positions.js +146 -0
- package/lib/drift/base/details/user/positions.js.map +1 -0
- package/lib/drift/cli.d.ts +25 -0
- package/lib/drift/cli.js +900 -0
- package/lib/drift/cli.js.map +1 -0
- package/lib/drift/constants/apiUrls.d.ts +27 -0
- package/lib/drift/constants/apiUrls.js +31 -0
- package/lib/drift/constants/apiUrls.js.map +1 -0
- package/lib/drift/example.d.ts +19 -0
- package/lib/drift/example.js +249 -0
- package/lib/drift/example.js.map +1 -0
- package/lib/drift/index.d.ts +3 -0
- package/lib/drift/index.js +20 -0
- package/lib/drift/index.js.map +1 -0
- package/lib/drift/utils/auctionParamsResponseMapper.d.ts +45 -0
- package/lib/drift/utils/auctionParamsResponseMapper.js +148 -0
- package/lib/drift/utils/auctionParamsResponseMapper.js.map +1 -0
- package/lib/drift/utils/funding.d.ts +2 -0
- package/lib/drift/utils/funding.js +9 -0
- package/lib/drift/utils/funding.js.map +1 -0
- package/lib/drift/utils/index.d.ts +3 -0
- package/lib/drift/utils/index.js +23 -0
- package/lib/drift/utils/index.js.map +1 -0
- package/lib/drift/utils/orderParams.d.ts +48 -0
- package/lib/drift/utils/orderParams.js +140 -0
- package/lib/drift/utils/orderParams.js.map +1 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +68 -0
- package/lib/index.js.map +1 -0
- package/lib/serializableTypes.d.ts +961 -0
- package/lib/serializableTypes.js +3887 -0
- package/lib/serializableTypes.js.map +1 -0
- package/lib/types/MarketId.d.ts +26 -0
- package/lib/types/MarketId.js +64 -0
- package/lib/types/MarketId.js.map +1 -0
- package/lib/types/Superstake.d.ts +7 -0
- package/lib/types/Superstake.js +3 -0
- package/lib/types/Superstake.js.map +1 -0
- package/lib/types/UIEnv.d.ts +26 -0
- package/lib/types/UIEnv.js +49 -0
- package/lib/types/UIEnv.js.map +1 -0
- package/lib/types/UIMarket.d.ts +94 -0
- package/lib/types/UIMarket.js +224 -0
- package/lib/types/UIMarket.js.map +1 -0
- package/lib/types/candles.d.ts +4 -0
- package/lib/types/candles.js +9 -0
- package/lib/types/candles.js.map +1 -0
- package/lib/types/dataServer.d.ts +53 -0
- package/lib/types/dataServer.js +3 -0
- package/lib/types/dataServer.js.map +1 -0
- package/lib/types/historyServer.d.ts +38 -0
- package/lib/types/historyServer.js +11 -0
- package/lib/types/historyServer.js.map +1 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +29 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/leaderboard.d.ts +80 -0
- package/lib/types/leaderboard.js +11 -0
- package/lib/types/leaderboard.js.map +1 -0
- package/lib/types/remote-configs.d.ts +61 -0
- package/lib/types/remote-configs.js +3 -0
- package/lib/types/remote-configs.js.map +1 -0
- package/lib/types/trade.d.ts +18 -0
- package/lib/types/trade.js +3 -0
- package/lib/types/trade.js.map +1 -0
- package/lib/types/user.d.ts +40 -0
- package/lib/types/user.js +3 -0
- package/lib/types/user.js.map +1 -0
- package/lib/types/utility.d.ts +15 -0
- package/lib/types/utility.js +3 -0
- package/lib/types/utility.js.map +1 -0
- package/lib/utils/CircularBuffers/CircularBuffer.d.ts +22 -0
- package/lib/utils/CircularBuffers/CircularBuffer.js +73 -0
- package/lib/utils/CircularBuffers/CircularBuffer.js.map +1 -0
- package/lib/utils/CircularBuffers/UniqueCircularBuffer.d.ts +19 -0
- package/lib/utils/CircularBuffers/UniqueCircularBuffer.js +78 -0
- package/lib/utils/CircularBuffers/UniqueCircularBuffer.js.map +1 -0
- package/lib/utils/CircularBuffers/index.d.ts +2 -0
- package/lib/utils/CircularBuffers/index.js +19 -0
- package/lib/utils/CircularBuffers/index.js.map +1 -0
- package/lib/utils/MultiplexWebSocket.d.ts +95 -0
- package/lib/utils/MultiplexWebSocket.js +416 -0
- package/lib/utils/MultiplexWebSocket.js.map +1 -0
- package/lib/utils/NumLib.d.ts +106 -0
- package/lib/utils/NumLib.js +300 -0
- package/lib/utils/NumLib.js.map +1 -0
- package/lib/utils/SharedInterval.d.ts +21 -0
- package/lib/utils/SharedInterval.js +47 -0
- package/lib/utils/SharedInterval.js.map +1 -0
- package/lib/utils/SlotBasedResultValidator.d.ts +9 -0
- package/lib/utils/SlotBasedResultValidator.js +27 -0
- package/lib/utils/SlotBasedResultValidator.js.map +1 -0
- package/lib/utils/Stopwatch.d.ts +15 -0
- package/lib/utils/Stopwatch.js +31 -0
- package/lib/utils/Stopwatch.js.map +1 -0
- package/lib/utils/StrictEventEmitter.d.ts +15 -0
- package/lib/utils/StrictEventEmitter.js +55 -0
- package/lib/utils/StrictEventEmitter.js.map +1 -0
- package/lib/utils/WalletConnectionState.d.ts +31 -0
- package/lib/utils/WalletConnectionState.js +83 -0
- package/lib/utils/WalletConnectionState.js.map +1 -0
- package/lib/utils/assert.d.ts +1 -0
- package/lib/utils/assert.js +10 -0
- package/lib/utils/assert.js.map +1 -0
- package/lib/utils/candles/Candle.d.ts +94 -0
- package/lib/utils/candles/Candle.js +580 -0
- package/lib/utils/candles/Candle.js.map +1 -0
- package/lib/utils/candles/types.d.ts +8 -0
- package/lib/utils/candles/types.js +3 -0
- package/lib/utils/candles/types.js.map +1 -0
- package/lib/utils/dlob-server/DlobServerWebsocketUtils.d.ts +57 -0
- package/lib/utils/dlob-server/DlobServerWebsocketUtils.js +137 -0
- package/lib/utils/dlob-server/DlobServerWebsocketUtils.js.map +1 -0
- package/lib/utils/driftEvents.d.ts +10 -0
- package/lib/utils/driftEvents.js +123 -0
- package/lib/utils/driftEvents.js.map +1 -0
- package/lib/utils/equalityChecks.d.ts +12 -0
- package/lib/utils/equalityChecks.js +71 -0
- package/lib/utils/equalityChecks.js.map +1 -0
- package/lib/utils/featureFlags.d.ts +3 -0
- package/lib/utils/featureFlags.js +7 -0
- package/lib/utils/featureFlags.js.map +1 -0
- package/lib/utils/geoblock/index.d.ts +4 -0
- package/lib/utils/geoblock/index.js +20 -0
- package/lib/utils/geoblock/index.js.map +1 -0
- package/lib/utils/index.d.ts +181 -0
- package/lib/utils/index.js +608 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/insuranceFund.d.ts +15 -0
- package/lib/utils/insuranceFund.js +84 -0
- package/lib/utils/insuranceFund.js.map +1 -0
- package/lib/utils/logger.d.ts +5 -0
- package/lib/utils/logger.js +53 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/math.d.ts +10 -0
- package/lib/utils/math.js +89 -0
- package/lib/utils/math.js.map +1 -0
- package/lib/utils/orderbook/index.d.ts +65 -0
- package/lib/utils/orderbook/index.js +80 -0
- package/lib/utils/orderbook/index.js.map +1 -0
- package/lib/utils/pollingSequenceGuard.d.ts +9 -0
- package/lib/utils/pollingSequenceGuard.js +24 -0
- package/lib/utils/pollingSequenceGuard.js.map +1 -0
- package/lib/utils/priority-fees/PriorityFeeCalculator.d.ts +24 -0
- package/lib/utils/priority-fees/PriorityFeeCalculator.js +53 -0
- package/lib/utils/priority-fees/PriorityFeeCalculator.js.map +1 -0
- package/lib/utils/priority-fees/PriorityFeeStrategies.d.ts +5 -0
- package/lib/utils/priority-fees/PriorityFeeStrategies.js +43 -0
- package/lib/utils/priority-fees/PriorityFeeStrategies.js.map +1 -0
- package/lib/utils/priority-fees/index.d.ts +2 -0
- package/lib/utils/priority-fees/index.js +19 -0
- package/lib/utils/priority-fees/index.js.map +1 -0
- package/lib/utils/priorityFees.d.ts +14 -0
- package/lib/utils/priorityFees.js +68 -0
- package/lib/utils/priorityFees.js.map +1 -0
- package/lib/utils/rpcLatency.d.ts +7 -0
- package/lib/utils/rpcLatency.js +49 -0
- package/lib/utils/rpcLatency.js.map +1 -0
- package/lib/utils/rxjs.d.ts +11 -0
- package/lib/utils/rxjs.js +24 -0
- package/lib/utils/rxjs.js.map +1 -0
- package/lib/utils/s3Buckets.d.ts +43 -0
- package/lib/utils/s3Buckets.js +108 -0
- package/lib/utils/s3Buckets.js.map +1 -0
- package/lib/utils/superstake.d.ts +86 -0
- package/lib/utils/superstake.js +224 -0
- package/lib/utils/superstake.js.map +1 -0
- package/lib/utils/token.d.ts +16 -0
- package/lib/utils/token.js +44 -0
- package/lib/utils/token.js.map +1 -0
- package/package.json +87 -0
package/lib/drift/cli.js
ADDED
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.parseSwapMode = exports.parseDirection = exports.parseAmount = exports.parseArgs = exports.main = void 0;
|
|
27
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
28
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
30
|
+
const tweetnacl_1 = require("tweetnacl");
|
|
31
|
+
const CentralServerDrift_1 = require("./Drift/clients/CentralServerDrift");
|
|
32
|
+
const utils_1 = require("../utils");
|
|
33
|
+
const apiUrls_1 = require("./constants/apiUrls");
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
// Load environment variables from .env file
|
|
36
|
+
const dotenv = require('dotenv');
|
|
37
|
+
dotenv.config({ path: path.resolve(__dirname, '.env') });
|
|
38
|
+
/**
|
|
39
|
+
* CLI Tool for CentralServerDrift client
|
|
40
|
+
*
|
|
41
|
+
* This CLI tool allows you to execute various Drift protocol operations via command line
|
|
42
|
+
* with human-readable parameters that are automatically converted to the proper precision.
|
|
43
|
+
*
|
|
44
|
+
* Prerequisites:
|
|
45
|
+
* - Create a .env file in the same directory as this CLI file with:
|
|
46
|
+
* ANCHOR_WALLET=[private key byte array]
|
|
47
|
+
* ENDPOINT=https://your-rpc-endpoint.com
|
|
48
|
+
*
|
|
49
|
+
* Usage Examples:
|
|
50
|
+
* ts-node cli.ts deposit --marketIndex=0 --amount=2 --userAccount=11111111111111111111111111111111
|
|
51
|
+
* ts-node cli.ts withdraw --marketIndex=0 --amount=1.5 --userAccount=11111111111111111111111111111111
|
|
52
|
+
* ts-node cli.ts settleFunding --userAccount=11111111111111111111111111111111
|
|
53
|
+
* ts-node cli.ts settlePnl --marketIndexes=0,1 --userAccount=11111111111111111111111111111111
|
|
54
|
+
* ts-node cli.ts openPerpMarketOrder --marketIndex=0 --direction=long --amount=0.1 --assetType=base --userAccount=11111111111111111111111111111111
|
|
55
|
+
* ts-node cli.ts openPerpMarketOrderSwift --marketIndex=0 --direction=short --amount=100 --assetType=quote --userAccount=11111111111111111111111111111111
|
|
56
|
+
* ts-node cli.ts openPerpNonMarketOrder --marketIndex=0 --direction=long --baseAssetAmount=0.1 --orderType=limit --limitPrice=100 --userAccount=11111111111111111111111111111111
|
|
57
|
+
* ts-node cli.ts openPerpNonMarketOrderSwift --marketIndex=0 --direction=long --baseAssetAmount=0.1 --orderType=limit --limitPrice=99.5 --userAccount=11111111111111111111111111111111
|
|
58
|
+
* ts-node cli.ts editOrder --userAccount=11111111111111111111111111111111 --orderId=123 --newLimitPrice=105.5
|
|
59
|
+
* ts-node cli.ts cancelOrder --userAccount=11111111111111111111111111111111 --orderIds=123,456,789
|
|
60
|
+
* ts-node cli.ts cancelAllOrders --userAccount=11111111111111111111111111111111 --marketType=perp
|
|
61
|
+
* ts-node cli.ts swap --userAccount=11111111111111111111111111111111 --fromMarketIndex=1 --toMarketIndex=0 --fromAmount=1.5 --slippage=100 --swapMode=ExactIn
|
|
62
|
+
* ts-node cli.ts swap --userAccount=11111111111111111111111111111111 --fromMarketIndex=1 --toMarketIndex=0 --toAmount=150 --slippage=100 --swapMode=ExactOut
|
|
63
|
+
*/
|
|
64
|
+
// Shared configuration
|
|
65
|
+
let centralServerDrift;
|
|
66
|
+
let wallet;
|
|
67
|
+
/**
|
|
68
|
+
* Parse command line arguments into a key-value object
|
|
69
|
+
*/
|
|
70
|
+
function parseArgs(args) {
|
|
71
|
+
const parsed = {};
|
|
72
|
+
for (let i = 0; i < args.length; i++) {
|
|
73
|
+
const arg = args[i];
|
|
74
|
+
if (arg.startsWith('--')) {
|
|
75
|
+
const [key, value] = arg.substring(2).split('=');
|
|
76
|
+
if (value !== undefined) {
|
|
77
|
+
// Handle comma-separated arrays
|
|
78
|
+
if (value.includes(',')) {
|
|
79
|
+
parsed[key] = value.split(',');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
parsed[key] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
|
|
86
|
+
// Handle space-separated values
|
|
87
|
+
const nextValue = args[i + 1];
|
|
88
|
+
if (nextValue.includes(',')) {
|
|
89
|
+
parsed[key] = nextValue.split(',');
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
parsed[key] = nextValue;
|
|
93
|
+
}
|
|
94
|
+
i++; // Skip the next argument as it's the value
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
parsed[key] = 'true'; // Boolean flag
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return parsed;
|
|
102
|
+
}
|
|
103
|
+
exports.parseArgs = parseArgs;
|
|
104
|
+
/**
|
|
105
|
+
* Convert human-readable amount to BN with proper precision
|
|
106
|
+
*/
|
|
107
|
+
function parseAmount(amount, precision = sdk_1.QUOTE_PRECISION) {
|
|
108
|
+
const floatAmount = parseFloat(amount);
|
|
109
|
+
if (isNaN(floatAmount)) {
|
|
110
|
+
throw new Error(`Invalid amount: ${amount}`);
|
|
111
|
+
}
|
|
112
|
+
// Convert to the proper precision
|
|
113
|
+
const scaledAmount = Math.floor(floatAmount * precision.toNumber());
|
|
114
|
+
return new sdk_1.BN(scaledAmount);
|
|
115
|
+
}
|
|
116
|
+
exports.parseAmount = parseAmount;
|
|
117
|
+
/**
|
|
118
|
+
* Parse direction string to PositionDirection
|
|
119
|
+
*/
|
|
120
|
+
function parseDirection(direction) {
|
|
121
|
+
const normalized = direction.toLowerCase();
|
|
122
|
+
if (normalized === 'long' || normalized === 'buy') {
|
|
123
|
+
return sdk_1.PositionDirection.LONG;
|
|
124
|
+
}
|
|
125
|
+
else if (normalized === 'short' || normalized === 'sell') {
|
|
126
|
+
return sdk_1.PositionDirection.SHORT;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw new Error(`Invalid direction: ${direction}. Use 'long', 'short', 'buy', or 'sell'`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.parseDirection = parseDirection;
|
|
133
|
+
/**
|
|
134
|
+
* Parse order type string to OrderType
|
|
135
|
+
*/
|
|
136
|
+
function _parseOrderType(orderType) {
|
|
137
|
+
const normalized = orderType.toLowerCase();
|
|
138
|
+
switch (normalized) {
|
|
139
|
+
case 'limit':
|
|
140
|
+
return sdk_1.OrderType.LIMIT;
|
|
141
|
+
case 'market':
|
|
142
|
+
return sdk_1.OrderType.MARKET;
|
|
143
|
+
case 'oracle':
|
|
144
|
+
return sdk_1.OrderType.ORACLE;
|
|
145
|
+
case 'trigger_market':
|
|
146
|
+
case 'stopmarket':
|
|
147
|
+
return sdk_1.OrderType.TRIGGER_MARKET;
|
|
148
|
+
case 'trigger_limit':
|
|
149
|
+
case 'stoplimit':
|
|
150
|
+
return sdk_1.OrderType.TRIGGER_LIMIT;
|
|
151
|
+
default:
|
|
152
|
+
throw new Error(`Invalid order type: ${orderType}. Use 'limit', 'market', 'oracle', 'trigger_market', or 'trigger_limit'`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Parse post only string to PostOnlyParams
|
|
157
|
+
*/
|
|
158
|
+
function parsePostOnly(postOnly) {
|
|
159
|
+
const normalized = postOnly.toLowerCase();
|
|
160
|
+
switch (normalized) {
|
|
161
|
+
case 'none':
|
|
162
|
+
case 'false':
|
|
163
|
+
return sdk_1.PostOnlyParams.NONE;
|
|
164
|
+
case 'must_post_only':
|
|
165
|
+
case 'true':
|
|
166
|
+
return sdk_1.PostOnlyParams.MUST_POST_ONLY;
|
|
167
|
+
case 'try_post_only':
|
|
168
|
+
return sdk_1.PostOnlyParams.TRY_POST_ONLY;
|
|
169
|
+
case 'slide':
|
|
170
|
+
return sdk_1.PostOnlyParams.SLIDE;
|
|
171
|
+
default:
|
|
172
|
+
throw new Error(`Invalid post only: ${postOnly}. Use 'none', 'must_post_only', 'try_post_only', or 'slide'`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Parse swap mode string to SwapMode
|
|
177
|
+
*/
|
|
178
|
+
function parseSwapMode(swapMode) {
|
|
179
|
+
const normalized = swapMode.toLowerCase();
|
|
180
|
+
switch (normalized) {
|
|
181
|
+
case 'exactin':
|
|
182
|
+
case 'exact_in':
|
|
183
|
+
return 'ExactIn';
|
|
184
|
+
case 'exactout':
|
|
185
|
+
case 'exact_out':
|
|
186
|
+
return 'ExactOut';
|
|
187
|
+
default:
|
|
188
|
+
throw new Error(`Invalid swap mode: ${swapMode}. Use 'ExactIn' or 'ExactOut'`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.parseSwapMode = parseSwapMode;
|
|
192
|
+
/**
|
|
193
|
+
* Get the precision for a spot market based on environment and market index
|
|
194
|
+
*/
|
|
195
|
+
function getMarketPrecision(marketIndex, isMainnet = true) {
|
|
196
|
+
const markets = isMainnet ? sdk_1.MainnetSpotMarkets : sdk_1.DevnetSpotMarkets;
|
|
197
|
+
const market = markets.find((m) => m.marketIndex === marketIndex);
|
|
198
|
+
if (!market) {
|
|
199
|
+
console.warn(`โ ๏ธ Market ${marketIndex} not found, using QUOTE_PRECISION as fallback`);
|
|
200
|
+
return sdk_1.QUOTE_PRECISION;
|
|
201
|
+
}
|
|
202
|
+
return market.precision;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Initialize CentralServerDrift instance
|
|
206
|
+
*/
|
|
207
|
+
async function initializeCentralServerDrift() {
|
|
208
|
+
console.log('๐ Initializing CentralServerDrift...\n');
|
|
209
|
+
// Validate required environment variables
|
|
210
|
+
if (!process.env.ANCHOR_WALLET) {
|
|
211
|
+
throw new Error('ANCHOR_WALLET must be set in .env file');
|
|
212
|
+
}
|
|
213
|
+
if (!process.env.ENDPOINT) {
|
|
214
|
+
throw new Error('ENDPOINT environment variable must be set to your Solana RPC endpoint');
|
|
215
|
+
}
|
|
216
|
+
// Set up the wallet
|
|
217
|
+
wallet = new anchor.Wallet((0, sdk_1.loadKeypair)(process.env.ANCHOR_WALLET));
|
|
218
|
+
console.log(`โ
Wallet Public Key: ${wallet.publicKey.toString()}`);
|
|
219
|
+
console.log(`โ
RPC Endpoint: ${process.env.ENDPOINT}\n`);
|
|
220
|
+
// Initialize CentralServerDrift
|
|
221
|
+
console.log('๐๏ธ Initializing CentralServerDrift...');
|
|
222
|
+
centralServerDrift = new CentralServerDrift_1.CentralServerDrift({
|
|
223
|
+
solanaRpcEndpoint: process.env.ENDPOINT,
|
|
224
|
+
driftEnv: 'mainnet-beta', // Change to 'devnet' for devnet testing
|
|
225
|
+
additionalDriftClientConfig: {
|
|
226
|
+
txVersion: 0,
|
|
227
|
+
txParams: {
|
|
228
|
+
computeUnits: 200000,
|
|
229
|
+
computeUnitsPrice: 1000,
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
console.log('โ
CentralServerDrift instance created successfully\n');
|
|
234
|
+
// Subscribe to market data
|
|
235
|
+
console.log('๐ก Subscribing to market data...');
|
|
236
|
+
await centralServerDrift.subscribe();
|
|
237
|
+
console.log('โ
Successfully subscribed to market data\n');
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Execute a regular transaction
|
|
241
|
+
*/
|
|
242
|
+
async function executeTransaction(txn, transactionType) {
|
|
243
|
+
console.log(`โ
${transactionType} transaction created successfully`);
|
|
244
|
+
console.log('\n๐ Signing Transaction...');
|
|
245
|
+
txn.sign([wallet.payer]);
|
|
246
|
+
console.log('โ
Transaction signed successfully');
|
|
247
|
+
console.log('\n๐ Sending transaction to the network...');
|
|
248
|
+
const { txSig } = await centralServerDrift.sendSignedTransaction(txn);
|
|
249
|
+
console.log('โ
Transaction sent successfully!');
|
|
250
|
+
console.log(`๐ Transaction Signature: ${txSig === null || txSig === void 0 ? void 0 : txSig.toString()}`);
|
|
251
|
+
console.log(`๐ View on Solscan: https://solscan.io/tx/${txSig === null || txSig === void 0 ? void 0 : txSig.toString()}`);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Handle Swift order observable
|
|
255
|
+
*/
|
|
256
|
+
function handleSwiftOrder(swiftResult, orderType) {
|
|
257
|
+
if (swiftResult.swiftOrderObservable) {
|
|
258
|
+
console.log('\n๐๏ธ Monitoring order status...');
|
|
259
|
+
swiftResult.swiftOrderObservable.subscribe({
|
|
260
|
+
next: (event) => {
|
|
261
|
+
if (event.type === 'sent') {
|
|
262
|
+
console.log(`โ
${orderType} Swift order submitted successfully`);
|
|
263
|
+
}
|
|
264
|
+
else if (event.type === 'confirmed') {
|
|
265
|
+
console.log('โ
Order confirmed!');
|
|
266
|
+
console.log(`๐ Order ID: ${event.orderId}`);
|
|
267
|
+
console.log(`๐ Hash: ${event.hash}`);
|
|
268
|
+
}
|
|
269
|
+
else if (event.type === 'errored') {
|
|
270
|
+
console.error('โ Order failed:', event.message);
|
|
271
|
+
console.error(`๐ Status: ${event.status}`);
|
|
272
|
+
}
|
|
273
|
+
else if (event.type === 'expired') {
|
|
274
|
+
console.error('โฐ Order expired:', event.message);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
error: (error) => {
|
|
278
|
+
console.error('โ Observable error:', error);
|
|
279
|
+
},
|
|
280
|
+
complete: () => {
|
|
281
|
+
console.log('๐ Order monitoring completed');
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
console.log('๐ Order confirmed and processing complete');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* CLI Command: deposit
|
|
291
|
+
*/
|
|
292
|
+
async function depositCommand(args) {
|
|
293
|
+
const userAccount = args.userAccount;
|
|
294
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
295
|
+
const amount = args.amount;
|
|
296
|
+
if (!userAccount || isNaN(marketIndex) || !amount) {
|
|
297
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --amount');
|
|
298
|
+
}
|
|
299
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
300
|
+
const amountBN = parseAmount(amount, sdk_1.QUOTE_PRECISION); // Most deposits are USDC (quote precision)
|
|
301
|
+
console.log('--- ๐ฅ Deposit Transaction ---');
|
|
302
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
303
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
304
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
305
|
+
const depositTxn = await centralServerDrift.getDepositTxn(userAccountPubkey, amountBN, marketIndex);
|
|
306
|
+
await executeTransaction(depositTxn, 'Deposit');
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* CLI Command: withdraw
|
|
310
|
+
*/
|
|
311
|
+
async function withdrawCommand(args) {
|
|
312
|
+
const userAccount = args.userAccount;
|
|
313
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
314
|
+
const amount = args.amount;
|
|
315
|
+
const isBorrow = args.isBorrow === 'true';
|
|
316
|
+
const isMax = args.isMax === 'true';
|
|
317
|
+
if (!userAccount || isNaN(marketIndex) || !amount) {
|
|
318
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --amount');
|
|
319
|
+
}
|
|
320
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
321
|
+
const amountBN = parseAmount(amount, sdk_1.QUOTE_PRECISION);
|
|
322
|
+
console.log('--- ๐ค Withdraw Transaction ---');
|
|
323
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
324
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
325
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
326
|
+
console.log(`๐ณ Is Borrow: ${isBorrow}`);
|
|
327
|
+
console.log(`๐ Is Max: ${isMax}`);
|
|
328
|
+
const withdrawTxn = await centralServerDrift.getWithdrawTxn(userAccountPubkey, amountBN, marketIndex, { isBorrow, isMax });
|
|
329
|
+
await executeTransaction(withdrawTxn, 'Withdraw');
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* CLI Command: settleFunding
|
|
333
|
+
*/
|
|
334
|
+
async function settleFundingCommand(args) {
|
|
335
|
+
const userAccount = args.userAccount;
|
|
336
|
+
if (!userAccount) {
|
|
337
|
+
throw new Error('Required arguments: --userAccount');
|
|
338
|
+
}
|
|
339
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
340
|
+
console.log('--- ๐ฐ Settle Funding Transaction ---');
|
|
341
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
342
|
+
const settleFundingTxn = await centralServerDrift.getSettleFundingTxn(userAccountPubkey);
|
|
343
|
+
await executeTransaction(settleFundingTxn, 'Settle Funding');
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* CLI Command: settlePnl
|
|
347
|
+
*/
|
|
348
|
+
async function settlePnlCommand(args) {
|
|
349
|
+
const userAccount = args.userAccount;
|
|
350
|
+
const marketIndexesArg = args.marketIndexes;
|
|
351
|
+
if (!userAccount || !marketIndexesArg) {
|
|
352
|
+
throw new Error('Required arguments: --userAccount, --marketIndexes (comma-separated)');
|
|
353
|
+
}
|
|
354
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
355
|
+
const marketIndexes = Array.isArray(marketIndexesArg)
|
|
356
|
+
? marketIndexesArg.map((idx) => parseInt(idx))
|
|
357
|
+
: [parseInt(marketIndexesArg)];
|
|
358
|
+
console.log('--- ๐ Settle PnL Transaction ---');
|
|
359
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
360
|
+
console.log(`๐ Market Indexes: ${marketIndexes.join(', ')}`);
|
|
361
|
+
const settlePnlTxn = await centralServerDrift.getSettlePnlTxn(userAccountPubkey, marketIndexes);
|
|
362
|
+
await executeTransaction(settlePnlTxn, 'Settle PnL');
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* CLI Command: openPerpMarketOrder (regular transaction)
|
|
366
|
+
*/
|
|
367
|
+
async function openPerpMarketOrderCommand(args) {
|
|
368
|
+
const userAccount = args.userAccount;
|
|
369
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
370
|
+
const direction = args.direction;
|
|
371
|
+
const amount = args.amount;
|
|
372
|
+
const assetType = args.assetType || 'base';
|
|
373
|
+
const dlobServerHttpUrl = apiUrls_1.API_URLS.DLOB;
|
|
374
|
+
if (!userAccount || isNaN(marketIndex) || !direction || !amount) {
|
|
375
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --direction, --amount');
|
|
376
|
+
}
|
|
377
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
378
|
+
const directionEnum = parseDirection(direction);
|
|
379
|
+
const precision = assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION;
|
|
380
|
+
const amountBN = parseAmount(amount, precision);
|
|
381
|
+
console.log('--- ๐ฏ Open Perp Order Transaction ---');
|
|
382
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
383
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
384
|
+
console.log(`๐ Direction: ${direction} (${utils_1.ENUM_UTILS.toStr(directionEnum)})`);
|
|
385
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
386
|
+
console.log(`๐ฑ Asset Type: ${assetType}`);
|
|
387
|
+
console.log(`๐ DLOB Server: ${dlobServerHttpUrl}`);
|
|
388
|
+
const orderTxn = await centralServerDrift.getOpenPerpMarketOrderTxn(userAccountPubkey, assetType, marketIndex, directionEnum, amountBN, dlobServerHttpUrl, undefined, // auctionParamsOptions
|
|
389
|
+
false // useSwift
|
|
390
|
+
);
|
|
391
|
+
await executeTransaction(orderTxn, 'Open Perp Order');
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* CLI Command: openPerpMarketOrderSwift (Swift signed message order)
|
|
395
|
+
*/
|
|
396
|
+
async function openPerpMarketOrderSwiftCommand(args) {
|
|
397
|
+
const userAccount = args.userAccount;
|
|
398
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
399
|
+
const direction = args.direction;
|
|
400
|
+
const amount = args.amount;
|
|
401
|
+
const assetType = args.assetType || 'base';
|
|
402
|
+
const dlobServerHttpUrl = apiUrls_1.API_URLS.DLOB;
|
|
403
|
+
const swiftServerUrl = args.swiftServerUrl || apiUrls_1.API_URLS.SWIFT;
|
|
404
|
+
if (!userAccount || isNaN(marketIndex) || !direction || !amount) {
|
|
405
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --direction, --amount');
|
|
406
|
+
}
|
|
407
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
408
|
+
const directionEnum = parseDirection(direction);
|
|
409
|
+
const precision = assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION;
|
|
410
|
+
const amountBN = parseAmount(amount, precision);
|
|
411
|
+
console.log('--- โก Open Perp Order Swift ---');
|
|
412
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
413
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
414
|
+
console.log(`๐ Direction: ${direction} (${utils_1.ENUM_UTILS.toStr(directionEnum)})`);
|
|
415
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
416
|
+
console.log(`๐ฑ Asset Type: ${assetType}`);
|
|
417
|
+
console.log(`๐ DLOB Server: ${dlobServerHttpUrl}`);
|
|
418
|
+
console.log(`โก Swift Server: ${swiftServerUrl}`);
|
|
419
|
+
console.log(`๐ Wallet Public Key: ${wallet.publicKey.toString()}`);
|
|
420
|
+
let swiftResult;
|
|
421
|
+
try {
|
|
422
|
+
swiftResult = (await centralServerDrift.getOpenPerpMarketOrderTxn(userAccountPubkey, assetType, marketIndex, directionEnum, amountBN, dlobServerHttpUrl, undefined, // auctionParamsOptions
|
|
423
|
+
true, // useSwift
|
|
424
|
+
{
|
|
425
|
+
wallet: {
|
|
426
|
+
signMessage: async (message) => {
|
|
427
|
+
// Sign the message using the keypair
|
|
428
|
+
const signature = tweetnacl_1.sign.detached(message, wallet.payer.secretKey);
|
|
429
|
+
return new Uint8Array(signature);
|
|
430
|
+
},
|
|
431
|
+
publicKey: wallet.publicKey,
|
|
432
|
+
},
|
|
433
|
+
swiftServerUrl,
|
|
434
|
+
confirmDuration: 30000,
|
|
435
|
+
}));
|
|
436
|
+
console.log('โ
[CLI] Swift order transaction created successfully!');
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
console.error('โ [CLI] Error creating Swift order:', error);
|
|
440
|
+
throw error;
|
|
441
|
+
}
|
|
442
|
+
handleSwiftOrder(swiftResult, 'Open Perp Order');
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* CLI Command: openPerpNonMarketOrder (regular limit/oracle order)
|
|
446
|
+
*/
|
|
447
|
+
async function openPerpNonMarketOrderCommand(args) {
|
|
448
|
+
const userAccount = args.userAccount;
|
|
449
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
450
|
+
const direction = args.direction;
|
|
451
|
+
const amount = args.amount;
|
|
452
|
+
const assetType = args.assetType || 'base';
|
|
453
|
+
const baseAssetAmount = args.baseAssetAmount;
|
|
454
|
+
const orderType = args.orderType;
|
|
455
|
+
const limitPrice = args.limitPrice;
|
|
456
|
+
const triggerPrice = args.triggerPrice;
|
|
457
|
+
const reduceOnly = args.reduceOnly === 'true';
|
|
458
|
+
const postOnly = args.postOnly || 'none';
|
|
459
|
+
const oraclePriceOffset = args.oraclePriceOffset;
|
|
460
|
+
if (!userAccount || isNaN(marketIndex) || !direction || !orderType) {
|
|
461
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --direction, --orderType');
|
|
462
|
+
}
|
|
463
|
+
if (!amount && !baseAssetAmount) {
|
|
464
|
+
throw new Error('Either --amount or --baseAssetAmount must be provided');
|
|
465
|
+
}
|
|
466
|
+
// Validate price requirements based on order type
|
|
467
|
+
if (orderType === 'limit') {
|
|
468
|
+
if (!limitPrice) {
|
|
469
|
+
throw new Error(`Order type '${orderType}' requires --limitPrice`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
else if (orderType === 'takeProfit' || orderType === 'stopLoss') {
|
|
473
|
+
if (!triggerPrice) {
|
|
474
|
+
throw new Error(`Order type '${orderType}' requires --triggerPrice`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
else if (orderType === 'oracleLimit') {
|
|
478
|
+
if (!oraclePriceOffset) {
|
|
479
|
+
throw new Error(`Order type '${orderType}' requires --oraclePriceOffset`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
483
|
+
const directionEnum = parseDirection(direction);
|
|
484
|
+
const postOnlyEnum = parsePostOnly(postOnly);
|
|
485
|
+
const limitPriceBN = limitPrice
|
|
486
|
+
? parseAmount(limitPrice, sdk_1.PRICE_PRECISION)
|
|
487
|
+
: undefined;
|
|
488
|
+
const triggerPriceBN = triggerPrice
|
|
489
|
+
? parseAmount(triggerPrice, sdk_1.PRICE_PRECISION)
|
|
490
|
+
: undefined;
|
|
491
|
+
console.log('--- ๐ Open Perp Non-Market Order ---');
|
|
492
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
493
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
494
|
+
console.log(`๐ Direction: ${direction} (${utils_1.ENUM_UTILS.toStr(directionEnum)})`);
|
|
495
|
+
if (amount) {
|
|
496
|
+
const precision = assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION;
|
|
497
|
+
const amountBN = parseAmount(amount, precision);
|
|
498
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
499
|
+
console.log(`๐ฑ Asset Type: ${assetType}`);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
const amountBN = parseAmount(baseAssetAmount, sdk_1.BASE_PRECISION);
|
|
503
|
+
console.log(`๐ฐ Base Asset Amount: ${baseAssetAmount} (${amountBN.toString()} raw units)`);
|
|
504
|
+
}
|
|
505
|
+
if (limitPriceBN) {
|
|
506
|
+
console.log(`๐ต Limit Price: ${limitPrice} (${limitPriceBN.toString()} raw units)`);
|
|
507
|
+
}
|
|
508
|
+
if (triggerPriceBN) {
|
|
509
|
+
console.log(`๐ฏ Trigger Price: ${triggerPrice} (${triggerPriceBN.toString()} raw units)`);
|
|
510
|
+
}
|
|
511
|
+
console.log(`๐ Order Type: ${orderType}`);
|
|
512
|
+
console.log(`๐ Reduce Only: ${reduceOnly}`);
|
|
513
|
+
console.log(`๐ Post Only: ${postOnly} (${utils_1.ENUM_UTILS.toStr(postOnlyEnum)})`);
|
|
514
|
+
// Just call the main method - it will handle both approaches internally
|
|
515
|
+
const orderTxn = await centralServerDrift.getOpenPerpNonMarketOrderTxn(userAccountPubkey, marketIndex, directionEnum, amount
|
|
516
|
+
? parseAmount(amount, assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION)
|
|
517
|
+
: parseAmount(baseAssetAmount, sdk_1.BASE_PRECISION), amount ? assetType : 'base', limitPriceBN, triggerPriceBN, orderType, reduceOnly, postOnlyEnum, false // useSwift
|
|
518
|
+
);
|
|
519
|
+
await executeTransaction(orderTxn, 'Open Perp Non-Market Order');
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* CLI Command: openPerpNonMarketOrderSwift (Swift signed message limit order)
|
|
523
|
+
*/
|
|
524
|
+
async function openPerpNonMarketOrderSwiftCommand(args) {
|
|
525
|
+
const userAccount = args.userAccount;
|
|
526
|
+
const marketIndex = parseInt(args.marketIndex);
|
|
527
|
+
const direction = args.direction;
|
|
528
|
+
const amount = args.amount;
|
|
529
|
+
const assetType = args.assetType || 'base';
|
|
530
|
+
const baseAssetAmount = args.baseAssetAmount;
|
|
531
|
+
const orderType = args.orderType;
|
|
532
|
+
const limitPrice = args.limitPrice;
|
|
533
|
+
const reduceOnly = args.reduceOnly === 'true';
|
|
534
|
+
const postOnly = args.postOnly || 'none';
|
|
535
|
+
const swiftServerUrl = apiUrls_1.API_URLS.SWIFT;
|
|
536
|
+
if (!userAccount || isNaN(marketIndex) || !direction || !orderType) {
|
|
537
|
+
throw new Error('Required arguments: --userAccount, --marketIndex, --direction, --orderType');
|
|
538
|
+
}
|
|
539
|
+
if (!amount && !baseAssetAmount) {
|
|
540
|
+
throw new Error('Either --amount or --baseAssetAmount must be provided');
|
|
541
|
+
}
|
|
542
|
+
// Swift orders only support LIMIT order type
|
|
543
|
+
if (orderType.toLowerCase() !== 'limit') {
|
|
544
|
+
throw new Error('Swift orders only support LIMIT order type');
|
|
545
|
+
}
|
|
546
|
+
// LIMIT orders require limitPrice
|
|
547
|
+
if (!limitPrice) {
|
|
548
|
+
throw new Error('LIMIT orders require --limitPrice');
|
|
549
|
+
}
|
|
550
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
551
|
+
const directionEnum = parseDirection(direction);
|
|
552
|
+
const postOnlyEnum = parsePostOnly(postOnly);
|
|
553
|
+
const limitPriceBN = parseAmount(limitPrice, sdk_1.PRICE_PRECISION);
|
|
554
|
+
console.log('--- โก Open Perp Non-Market Order Swift ---');
|
|
555
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
556
|
+
console.log(`๐ช Market Index: ${marketIndex}`);
|
|
557
|
+
console.log(`๐ Direction: ${direction} (${utils_1.ENUM_UTILS.toStr(directionEnum)})`);
|
|
558
|
+
if (amount) {
|
|
559
|
+
const precision = assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION;
|
|
560
|
+
const amountBN = parseAmount(amount, precision);
|
|
561
|
+
console.log(`๐ฐ Amount: ${amount} (${amountBN.toString()} raw units)`);
|
|
562
|
+
console.log(`๐ฑ Asset Type: ${assetType}`);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
const amountBN = parseAmount(baseAssetAmount, sdk_1.BASE_PRECISION);
|
|
566
|
+
console.log(`๐ฐ Base Asset Amount: ${baseAssetAmount} (${amountBN.toString()} raw units)`);
|
|
567
|
+
}
|
|
568
|
+
console.log(`๐ต Limit Price: ${limitPrice} (${limitPriceBN.toString()} raw units)`);
|
|
569
|
+
console.log(`๐ Order Type: ${orderType})`);
|
|
570
|
+
console.log(`๐ Reduce Only: ${reduceOnly}`);
|
|
571
|
+
console.log(`๐ Post Only: ${postOnly} (${utils_1.ENUM_UTILS.toStr(postOnlyEnum)})`);
|
|
572
|
+
console.log(`โก Swift Server: ${swiftServerUrl}`);
|
|
573
|
+
console.log(`๐ Wallet Public Key: ${wallet.publicKey.toString()}`);
|
|
574
|
+
let swiftResult;
|
|
575
|
+
try {
|
|
576
|
+
const swiftOptions = {
|
|
577
|
+
wallet: {
|
|
578
|
+
signMessage: async (message) => {
|
|
579
|
+
const signature = tweetnacl_1.sign.detached(message, wallet.payer.secretKey);
|
|
580
|
+
return new Uint8Array(signature);
|
|
581
|
+
},
|
|
582
|
+
publicKey: wallet.publicKey,
|
|
583
|
+
},
|
|
584
|
+
swiftServerUrl,
|
|
585
|
+
confirmDuration: 30000,
|
|
586
|
+
};
|
|
587
|
+
// Use the main method - it handles both approaches internally
|
|
588
|
+
swiftResult = (await centralServerDrift.getOpenPerpNonMarketOrderTxn(userAccountPubkey, marketIndex, directionEnum, amount
|
|
589
|
+
? parseAmount(amount, assetType === 'base' ? sdk_1.BASE_PRECISION : sdk_1.QUOTE_PRECISION)
|
|
590
|
+
: parseAmount(baseAssetAmount, sdk_1.BASE_PRECISION), amount ? assetType : 'base', limitPriceBN, undefined, // triggerPrice - not used for LIMIT orders
|
|
591
|
+
orderType, reduceOnly, postOnlyEnum, true, // useSwift
|
|
592
|
+
swiftOptions));
|
|
593
|
+
console.log('โ
[CLI] Swift non-market order transaction created successfully!');
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
console.error('โ [CLI] Error creating Swift non-market order:', error);
|
|
597
|
+
throw error;
|
|
598
|
+
}
|
|
599
|
+
handleSwiftOrder(swiftResult, 'Open Perp Non-Market Order');
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Show CLI usage information
|
|
603
|
+
*/
|
|
604
|
+
function showUsage() {
|
|
605
|
+
console.log('๐ Drift CLI Usage');
|
|
606
|
+
console.log('');
|
|
607
|
+
console.log('Available Commands:');
|
|
608
|
+
console.log('');
|
|
609
|
+
console.log('๐ฐ deposit');
|
|
610
|
+
console.log(' ts-node cli.ts deposit --userAccount=<pubkey> --marketIndex=<num> --amount=<num>');
|
|
611
|
+
console.log(' Example: ts-node cli.ts deposit --userAccount=11111111111111111111111111111111 --marketIndex=0 --amount=100');
|
|
612
|
+
console.log('');
|
|
613
|
+
console.log('๐ธ withdraw');
|
|
614
|
+
console.log(' ts-node cli.ts withdraw --userAccount=<pubkey> --marketIndex=<num> --amount=<num> [--isBorrow=<bool>] [--isMax=<bool>]');
|
|
615
|
+
console.log(' Example: ts-node cli.ts withdraw --userAccount=11111111111111111111111111111111 --marketIndex=0 --amount=50');
|
|
616
|
+
console.log('');
|
|
617
|
+
console.log('๐ฆ settleFunding');
|
|
618
|
+
console.log(' ts-node cli.ts settleFunding --userAccount=<pubkey>');
|
|
619
|
+
console.log(' Example: ts-node cli.ts settleFunding --userAccount=11111111111111111111111111111111');
|
|
620
|
+
console.log('');
|
|
621
|
+
console.log('๐ settlePnl');
|
|
622
|
+
console.log(' ts-node cli.ts settlePnl --userAccount=<pubkey> --marketIndexes=<comma-separated>');
|
|
623
|
+
console.log(' Example: ts-node cli.ts settlePnl --userAccount=11111111111111111111111111111111 --marketIndexes=0,1');
|
|
624
|
+
console.log('');
|
|
625
|
+
console.log('๐ฏ openPerpMarketOrder');
|
|
626
|
+
console.log(' ts-node cli.ts openPerpMarketOrder --userAccount=<pubkey> --marketIndex=<num> --direction=<long|short> --amount=<num> [--assetType=<base|quote>]');
|
|
627
|
+
console.log(' Example: ts-node cli.ts openPerpMarketOrder --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --amount=0.1 --assetType=base');
|
|
628
|
+
console.log('');
|
|
629
|
+
console.log('โก openPerpMarketOrderSwift');
|
|
630
|
+
console.log(' ts-node cli.ts openPerpMarketOrderSwift --userAccount=<pubkey> --marketIndex=<num> --direction=<long|short> --amount=<num> [--assetType=<base|quote>]');
|
|
631
|
+
console.log(' Example: ts-node cli.ts openPerpMarketOrderSwift --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=short --amount=100 --assetType=quote');
|
|
632
|
+
console.log('');
|
|
633
|
+
console.log('๐ openPerpNonMarketOrder');
|
|
634
|
+
console.log(' ts-node cli.ts openPerpNonMarketOrder --userAccount=<pubkey> --marketIndex=<num> --direction=<long|short> --amount=<num> [--assetType=<base|quote>] --orderType=<limit|trigger_limit|trigger_market|oracle> [--limitPrice=<num>] [--triggerPrice=<num>] [--reduceOnly=<true|false>] [--postOnly=<none|must_post_only|try_post_only|slide>]');
|
|
635
|
+
console.log(' New LIMIT: ts-node cli.ts openPerpNonMarketOrder --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --amount=0.1 --assetType=base --orderType=limit --limitPrice=100');
|
|
636
|
+
console.log(' New QUOTE: ts-node cli.ts openPerpNonMarketOrder --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --amount=100 --assetType=quote --orderType=limit --limitPrice=100');
|
|
637
|
+
console.log(' Legacy: ts-node cli.ts openPerpNonMarketOrder --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --baseAssetAmount=0.1 --orderType=limit --limitPrice=100');
|
|
638
|
+
console.log('');
|
|
639
|
+
console.log('โก openPerpNonMarketOrderSwift');
|
|
640
|
+
console.log(' ts-node cli.ts openPerpNonMarketOrderSwift --userAccount=<pubkey> --marketIndex=<num> --direction=<long|short> --amount=<num> [--assetType=<base|quote>] --orderType=limit --limitPrice=<num> [--reduceOnly=<true|false>] [--postOnly=<none|must_post_only|try_post_only|slide>]');
|
|
641
|
+
console.log(' New: ts-node cli.ts openPerpNonMarketOrderSwift --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --amount=0.1 --assetType=base --orderType=limit --limitPrice=99.5');
|
|
642
|
+
console.log(' Legacy: ts-node cli.ts openPerpNonMarketOrderSwift --userAccount=11111111111111111111111111111111 --marketIndex=0 --direction=long --baseAssetAmount=0.1 --orderType=limit --limitPrice=99.5');
|
|
643
|
+
console.log('');
|
|
644
|
+
console.log('โ๏ธ editOrder');
|
|
645
|
+
console.log(' ts-node cli.ts editOrder --userAccount=<pubkey> --orderId=<num> [--newDirection=<long|short>] [--newBaseAmount=<num>] [--newLimitPrice=<num>] [--newTriggerPrice=<num>] [--reduceOnly=<true|false>] [--postOnly=<true|false>]');
|
|
646
|
+
console.log(' Example: ts-node cli.ts editOrder --userAccount=11111111111111111111111111111111 --orderId=123 --newLimitPrice=105.5');
|
|
647
|
+
console.log('');
|
|
648
|
+
console.log('โ cancelOrder');
|
|
649
|
+
console.log(' ts-node cli.ts cancelOrder --userAccount=<pubkey> --orderIds=<comma-separated-list>');
|
|
650
|
+
console.log(' Example: ts-node cli.ts cancelOrder --userAccount=11111111111111111111111111111111 --orderIds=123,456,789');
|
|
651
|
+
console.log('');
|
|
652
|
+
console.log('๐งน cancelAllOrders');
|
|
653
|
+
console.log(' ts-node cli.ts cancelAllOrders --userAccount=<pubkey> [--marketType=<perp|spot>] [--marketIndex=<num>] [--direction=<long|short>]');
|
|
654
|
+
console.log(' Example: ts-node cli.ts cancelAllOrders --userAccount=11111111111111111111111111111111 --marketType=perp');
|
|
655
|
+
console.log('');
|
|
656
|
+
console.log('๐ swap');
|
|
657
|
+
console.log(' ts-node cli.ts swap --userAccount=<pubkey> --fromMarketIndex=<num> --toMarketIndex=<num> [--fromAmount=<num>] [--toAmount=<num>] [--slippage=<bps>] [--swapMode=<ExactIn|ExactOut>]');
|
|
658
|
+
console.log(' ExactIn: ts-node cli.ts swap --userAccount=11111111111111111111111111111111 --fromMarketIndex=1 --toMarketIndex=0 --fromAmount=1.5 --swapMode=ExactIn');
|
|
659
|
+
console.log(' ExactOut: ts-node cli.ts swap --userAccount=11111111111111111111111111111111 --fromMarketIndex=1 --toMarketIndex=0 --toAmount=150 --swapMode=ExactOut');
|
|
660
|
+
console.log('');
|
|
661
|
+
console.log('Options:');
|
|
662
|
+
console.log(' --help, -h Show this help message');
|
|
663
|
+
console.log('');
|
|
664
|
+
console.log('Notes:');
|
|
665
|
+
console.log(' - Amounts are in human-readable format (e.g., 1.5 USDC, 0.1 SOL)');
|
|
666
|
+
console.log(' - Direction can be: long, short, buy, sell');
|
|
667
|
+
console.log(' - Asset type: base (for native tokens like SOL) or quote (for USDC amounts)');
|
|
668
|
+
console.log(' - Swap modes:');
|
|
669
|
+
console.log(' * ExactIn: Specify --fromAmount (how much input token to swap)');
|
|
670
|
+
console.log(' * ExactOut: Specify --toAmount (how much output token to receive)');
|
|
671
|
+
console.log(' - Ensure your .env file contains ANCHOR_WALLET and ENDPOINT');
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* CLI Command: editOrder
|
|
675
|
+
*/
|
|
676
|
+
async function editOrderCommand(args) {
|
|
677
|
+
const userAccount = args.userAccount;
|
|
678
|
+
const orderId = parseInt(args.orderId);
|
|
679
|
+
const newDirection = args.newDirection;
|
|
680
|
+
const newBaseAmount = args.newBaseAmount;
|
|
681
|
+
const newLimitPrice = args.newLimitPrice;
|
|
682
|
+
const newTriggerPrice = args.newTriggerPrice;
|
|
683
|
+
const reduceOnly = args.reduceOnly === 'true';
|
|
684
|
+
const postOnly = args.postOnly === 'true';
|
|
685
|
+
if (!userAccount || isNaN(orderId)) {
|
|
686
|
+
throw new Error('Required arguments: --userAccount, --orderId');
|
|
687
|
+
}
|
|
688
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
689
|
+
const editParams = {};
|
|
690
|
+
if (newDirection) {
|
|
691
|
+
editParams.newDirection = parseDirection(newDirection);
|
|
692
|
+
}
|
|
693
|
+
if (newBaseAmount) {
|
|
694
|
+
editParams.newBaseAmount = parseAmount(newBaseAmount, sdk_1.BASE_PRECISION);
|
|
695
|
+
}
|
|
696
|
+
if (newLimitPrice) {
|
|
697
|
+
editParams.newLimitPrice = parseAmount(newLimitPrice, sdk_1.PRICE_PRECISION);
|
|
698
|
+
}
|
|
699
|
+
if (newTriggerPrice) {
|
|
700
|
+
editParams.newTriggerPrice = parseAmount(newTriggerPrice, sdk_1.PRICE_PRECISION);
|
|
701
|
+
}
|
|
702
|
+
if (reduceOnly) {
|
|
703
|
+
editParams.reduceOnly = true;
|
|
704
|
+
}
|
|
705
|
+
if (postOnly) {
|
|
706
|
+
editParams.postOnly = true;
|
|
707
|
+
}
|
|
708
|
+
console.log('--- โ๏ธ Edit Order ---');
|
|
709
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
710
|
+
console.log(`๐ Order ID: ${orderId}`);
|
|
711
|
+
console.log(`๐ Edit Parameters:`, editParams);
|
|
712
|
+
const editOrderTxn = await centralServerDrift.getEditOrderTxn(userAccountPubkey, orderId, editParams);
|
|
713
|
+
await executeTransaction(editOrderTxn, 'Edit Order');
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* CLI Command: cancelOrder
|
|
717
|
+
*/
|
|
718
|
+
async function cancelOrderCommand(args) {
|
|
719
|
+
const userAccount = args.userAccount;
|
|
720
|
+
const orderIds = args.orderIds;
|
|
721
|
+
if (!userAccount || !orderIds) {
|
|
722
|
+
throw new Error('Required arguments: --userAccount, --orderIds');
|
|
723
|
+
}
|
|
724
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
725
|
+
const orderIdArray = orderIds.split(',').map((id) => parseInt(id.trim()));
|
|
726
|
+
console.log('--- โ Cancel Orders ---');
|
|
727
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
728
|
+
console.log(`๐ Order IDs: ${orderIdArray.join(', ')}`);
|
|
729
|
+
const cancelOrderTxn = await centralServerDrift.getCancelOrdersTxn(userAccountPubkey, orderIdArray);
|
|
730
|
+
await executeTransaction(cancelOrderTxn, 'Cancel Orders');
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* CLI Command: cancelAllOrders
|
|
734
|
+
*/
|
|
735
|
+
async function cancelAllOrdersCommand(args) {
|
|
736
|
+
const userAccount = args.userAccount;
|
|
737
|
+
const marketType = args.marketType;
|
|
738
|
+
const marketIndex = args.marketIndex
|
|
739
|
+
? parseInt(args.marketIndex)
|
|
740
|
+
: undefined;
|
|
741
|
+
const direction = args.direction;
|
|
742
|
+
if (!userAccount) {
|
|
743
|
+
throw new Error('Required arguments: --userAccount');
|
|
744
|
+
}
|
|
745
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
746
|
+
let marketTypeEnum = undefined;
|
|
747
|
+
let directionEnum = undefined;
|
|
748
|
+
if (marketType) {
|
|
749
|
+
marketTypeEnum =
|
|
750
|
+
marketType.toLowerCase() === 'perp' ? { perp: {} } : { spot: {} };
|
|
751
|
+
}
|
|
752
|
+
if (direction) {
|
|
753
|
+
directionEnum = parseDirection(direction);
|
|
754
|
+
}
|
|
755
|
+
console.log('--- ๐งน Cancel All Orders ---');
|
|
756
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
757
|
+
console.log(`๐ช Market Type Filter: ${marketType || 'none'}`);
|
|
758
|
+
console.log(`๐ Market Index Filter: ${marketIndex !== undefined ? marketIndex : 'none'}`);
|
|
759
|
+
console.log(`๐ Direction Filter: ${direction || 'none'}`);
|
|
760
|
+
const cancelAllOrdersTxn = await centralServerDrift.getCancelAllOrdersTxn(userAccountPubkey, marketTypeEnum, marketIndex, directionEnum);
|
|
761
|
+
await executeTransaction(cancelAllOrdersTxn, 'Cancel All Orders');
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* CLI Command: swap
|
|
765
|
+
*/
|
|
766
|
+
async function swapCommand(args) {
|
|
767
|
+
const userAccount = args.userAccount;
|
|
768
|
+
const fromMarketIndex = parseInt(args.fromMarketIndex);
|
|
769
|
+
const toMarketIndex = parseInt(args.toMarketIndex);
|
|
770
|
+
const fromAmount = args.fromAmount;
|
|
771
|
+
const toAmount = args.toAmount;
|
|
772
|
+
const slippage = args.slippage ? parseInt(args.slippage) : 10; // Default 0.1%
|
|
773
|
+
const swapMode = args.swapMode || 'ExactIn';
|
|
774
|
+
if (!userAccount || isNaN(fromMarketIndex) || isNaN(toMarketIndex)) {
|
|
775
|
+
throw new Error('Required arguments: --userAccount, --fromMarketIndex, --toMarketIndex');
|
|
776
|
+
}
|
|
777
|
+
const swapModeEnum = parseSwapMode(swapMode);
|
|
778
|
+
// Validate amount parameters based on swap mode
|
|
779
|
+
if (swapModeEnum === 'ExactIn') {
|
|
780
|
+
if (!fromAmount) {
|
|
781
|
+
throw new Error('ExactIn swap mode requires --fromAmount');
|
|
782
|
+
}
|
|
783
|
+
if (toAmount) {
|
|
784
|
+
console.warn('โ ๏ธ Warning: --toAmount ignored in ExactIn mode, using --fromAmount');
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
else if (swapModeEnum === 'ExactOut') {
|
|
788
|
+
if (!toAmount) {
|
|
789
|
+
throw new Error('ExactOut swap mode requires --toAmount');
|
|
790
|
+
}
|
|
791
|
+
if (fromAmount) {
|
|
792
|
+
console.warn('โ ๏ธ Warning: --fromAmount ignored in ExactOut mode, using --toAmount');
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
const userAccountPubkey = new web3_js_1.PublicKey(userAccount);
|
|
796
|
+
// Use the appropriate amount based on swap mode
|
|
797
|
+
const amount = swapModeEnum === 'ExactIn' ? fromAmount : toAmount;
|
|
798
|
+
// Determine which market to use for precision (input market for ExactIn, output market for ExactOut)
|
|
799
|
+
const precisionMarketIndex = swapModeEnum === 'ExactIn' ? fromMarketIndex : toMarketIndex;
|
|
800
|
+
// Get the appropriate precision for the amount based on the market
|
|
801
|
+
const isMainnet = true; // Default to mainnet, could be made configurable
|
|
802
|
+
const precision = getMarketPrecision(precisionMarketIndex, isMainnet);
|
|
803
|
+
const amountBN = parseAmount(amount, precision);
|
|
804
|
+
console.log('--- ๐ Swap Transaction ---');
|
|
805
|
+
console.log(`๐ค User Account: ${userAccount}`);
|
|
806
|
+
console.log(`๐ค From Market Index: ${fromMarketIndex}`);
|
|
807
|
+
console.log(`๐ฅ To Market Index: ${toMarketIndex}`);
|
|
808
|
+
console.log(`๐ Swap Mode: ${swapMode}`);
|
|
809
|
+
console.log(`๐ฏ Using precision from market ${precisionMarketIndex}: ${precision.toString()}`);
|
|
810
|
+
if (swapModeEnum === 'ExactIn') {
|
|
811
|
+
console.log(`๐ฐ From Amount: ${fromAmount} (${amountBN.toString()} raw units)`);
|
|
812
|
+
console.log(`๐ฐ To Amount: Will be calculated based on quote`);
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
console.log(`๐ฐ From Amount: Will be calculated based on quote`);
|
|
816
|
+
console.log(`๐ฐ To Amount: ${toAmount} (${amountBN.toString()} raw units)`);
|
|
817
|
+
}
|
|
818
|
+
console.log(`๐ Slippage: ${slippage} BPS (${slippage / 100}%)`);
|
|
819
|
+
const swapTxn = await centralServerDrift.getSwapTxn(userAccountPubkey, fromMarketIndex, toMarketIndex, amountBN, {
|
|
820
|
+
slippageBps: slippage,
|
|
821
|
+
swapMode: swapModeEnum,
|
|
822
|
+
});
|
|
823
|
+
await executeTransaction(swapTxn, 'Swap');
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Main CLI entry point
|
|
827
|
+
*/
|
|
828
|
+
async function main() {
|
|
829
|
+
const args = process.argv.slice(2);
|
|
830
|
+
if (args.length === 0 ||
|
|
831
|
+
args[0] === '--help' ||
|
|
832
|
+
args[0] === '-h' ||
|
|
833
|
+
args[0] === 'help') {
|
|
834
|
+
showUsage();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const command = args[0];
|
|
838
|
+
const parsedArgs = parseArgs(args.slice(1));
|
|
839
|
+
// Initialize the client first
|
|
840
|
+
await initializeCentralServerDrift();
|
|
841
|
+
// Route to appropriate command
|
|
842
|
+
switch (command) {
|
|
843
|
+
case 'deposit':
|
|
844
|
+
await depositCommand(parsedArgs);
|
|
845
|
+
break;
|
|
846
|
+
case 'withdraw':
|
|
847
|
+
await withdrawCommand(parsedArgs);
|
|
848
|
+
break;
|
|
849
|
+
case 'settleFunding':
|
|
850
|
+
await settleFundingCommand(parsedArgs);
|
|
851
|
+
break;
|
|
852
|
+
case 'settlePnl':
|
|
853
|
+
await settlePnlCommand(parsedArgs);
|
|
854
|
+
break;
|
|
855
|
+
case 'openPerpMarketOrder':
|
|
856
|
+
await openPerpMarketOrderCommand(parsedArgs);
|
|
857
|
+
break;
|
|
858
|
+
case 'openPerpMarketOrderSwift':
|
|
859
|
+
await openPerpMarketOrderSwiftCommand(parsedArgs);
|
|
860
|
+
break;
|
|
861
|
+
case 'openPerpNonMarketOrder':
|
|
862
|
+
await openPerpNonMarketOrderCommand(parsedArgs);
|
|
863
|
+
break;
|
|
864
|
+
case 'openPerpNonMarketOrderSwift':
|
|
865
|
+
await openPerpNonMarketOrderSwiftCommand(parsedArgs);
|
|
866
|
+
break;
|
|
867
|
+
case 'editOrder':
|
|
868
|
+
await editOrderCommand(parsedArgs);
|
|
869
|
+
break;
|
|
870
|
+
case 'cancelOrder':
|
|
871
|
+
await cancelOrderCommand(parsedArgs);
|
|
872
|
+
break;
|
|
873
|
+
case 'cancelAllOrders':
|
|
874
|
+
await cancelAllOrdersCommand(parsedArgs);
|
|
875
|
+
break;
|
|
876
|
+
case 'swap':
|
|
877
|
+
await swapCommand(parsedArgs);
|
|
878
|
+
break;
|
|
879
|
+
default:
|
|
880
|
+
console.error(`โ Unknown command: ${command}`);
|
|
881
|
+
console.error('');
|
|
882
|
+
showUsage();
|
|
883
|
+
process.exit(1);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
exports.main = main;
|
|
887
|
+
// Run CLI if this file is executed directly
|
|
888
|
+
if (require.main === module) {
|
|
889
|
+
main()
|
|
890
|
+
.then(() => {
|
|
891
|
+
console.log('\nโจ Command executed successfully!');
|
|
892
|
+
// Don't exit immediately for Swift orders (they need time to process)
|
|
893
|
+
setTimeout(() => process.exit(0), 2000);
|
|
894
|
+
})
|
|
895
|
+
.catch((error) => {
|
|
896
|
+
console.error('\n๐ฅ Command failed:', error.message || error);
|
|
897
|
+
process.exit(1);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
//# sourceMappingURL=cli.js.map
|