@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BN, DriftClientConfig, DriftEnv, MarketType, OrderTriggerCondition, PositionDirection, PostOnlyParams, PublicKey, QuoteResponse, SwapMode } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { MarketId } from '../../../types';
|
|
4
|
+
import { AuctionParamsRequestOptions } from '../../base/actions/trade/openPerpOrder/openPerpMarketOrder';
|
|
5
|
+
import { SwiftOrderResult, SwiftOrderOptions } from '../../base/actions/trade/openPerpOrder/openSwiftOrder';
|
|
6
|
+
/**
|
|
7
|
+
* A Drift client that fetches user data on-demand, while market data is continuously subscribed to.
|
|
8
|
+
*
|
|
9
|
+
* This is useful for an API server that fetches user data on-demand, and return transaction messages specific to a given user
|
|
10
|
+
*/
|
|
11
|
+
export declare class CentralServerDrift {
|
|
12
|
+
private driftClient;
|
|
13
|
+
private _perpMarketConfigs;
|
|
14
|
+
private spotMarketConfigs;
|
|
15
|
+
/**
|
|
16
|
+
* @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.
|
|
17
|
+
* @param driftEnv - The drift environment to use for the drift client.
|
|
18
|
+
* @param activeTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.
|
|
19
|
+
* @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.
|
|
20
|
+
*/
|
|
21
|
+
constructor(config: {
|
|
22
|
+
solanaRpcEndpoint: string;
|
|
23
|
+
driftEnv: DriftEnv;
|
|
24
|
+
additionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;
|
|
25
|
+
activeTradeMarket?: MarketId;
|
|
26
|
+
marketsToSubscribe?: MarketId[];
|
|
27
|
+
});
|
|
28
|
+
subscribe(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Manages DriftClient state for transaction creation with proper setup and cleanup.
|
|
31
|
+
* This abstraction handles:
|
|
32
|
+
* - User creation and subscription
|
|
33
|
+
* - Authority management
|
|
34
|
+
* - Wallet replacement for correct transaction signing
|
|
35
|
+
* - Cleanup and state restoration
|
|
36
|
+
*
|
|
37
|
+
* @param userAccountPublicKey - The user account public key
|
|
38
|
+
* @param operation - The transaction creation operation to execute
|
|
39
|
+
* @returns The result of the operation
|
|
40
|
+
*/
|
|
41
|
+
private driftClientContextWrapper;
|
|
42
|
+
getDepositTxn(userAccountPublicKey: PublicKey, amount: BN, spotMarketIndex: number): Promise<VersionedTransaction | Transaction>;
|
|
43
|
+
getWithdrawTxn(userAccountPublicKey: PublicKey, amount: BN, spotMarketIndex: number, options?: {
|
|
44
|
+
isBorrow?: boolean;
|
|
45
|
+
isMax?: boolean;
|
|
46
|
+
}): Promise<VersionedTransaction | Transaction>;
|
|
47
|
+
getSettleFundingTxn(userAccountPublicKey: PublicKey): Promise<VersionedTransaction | Transaction>;
|
|
48
|
+
getSettlePnlTxn(userAccountPublicKey: PublicKey, marketIndexes: number[]): Promise<VersionedTransaction | Transaction>;
|
|
49
|
+
getOpenPerpMarketOrderTxn(userAccountPublicKey: PublicKey, assetType: 'base' | 'quote', marketIndex: number, direction: PositionDirection, amount: BN, dlobServerHttpUrl: string, auctionParamsOptions?: AuctionParamsRequestOptions, useSwift?: boolean, swiftOptions?: SwiftOrderOptions, marketType?: MarketType): Promise<VersionedTransaction | Transaction | SwiftOrderResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a perp non-market order with amount and asset type
|
|
52
|
+
*/
|
|
53
|
+
getOpenPerpNonMarketOrderTxn(userAccountPublicKey: PublicKey, marketIndex: number, direction: PositionDirection, amount: BN, assetType: 'base' | 'quote', limitPrice?: BN, triggerPrice?: BN, orderType?: 'limit' | 'takeProfit' | 'stopLoss' | 'oracleLimit', reduceOnly?: boolean, postOnly?: PostOnlyParams, useSwift?: boolean, swiftOptions?: SwiftOrderOptions, oraclePriceOffset?: BN): Promise<VersionedTransaction | Transaction | SwiftOrderResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Create a transaction to edit an existing order
|
|
56
|
+
*/
|
|
57
|
+
getEditOrderTxn(userAccountPublicKey: PublicKey, orderId: number, editOrderParams: {
|
|
58
|
+
newDirection?: PositionDirection;
|
|
59
|
+
newBaseAmount?: BN;
|
|
60
|
+
newLimitPrice?: BN;
|
|
61
|
+
newOraclePriceOffset?: number;
|
|
62
|
+
newTriggerPrice?: BN;
|
|
63
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
64
|
+
auctionDuration?: number;
|
|
65
|
+
auctionStartPrice?: BN;
|
|
66
|
+
auctionEndPrice?: BN;
|
|
67
|
+
reduceOnly?: boolean;
|
|
68
|
+
postOnly?: boolean;
|
|
69
|
+
bitFlags?: number;
|
|
70
|
+
maxTs?: BN;
|
|
71
|
+
policy?: number;
|
|
72
|
+
}): Promise<VersionedTransaction | Transaction>;
|
|
73
|
+
/**
|
|
74
|
+
* Create a transaction to cancel specific orders by their IDs
|
|
75
|
+
*/
|
|
76
|
+
getCancelOrdersTxn(userAccountPublicKey: PublicKey, orderIds: number[]): Promise<VersionedTransaction | Transaction>;
|
|
77
|
+
/**
|
|
78
|
+
* Create a transaction to cancel all orders for a user
|
|
79
|
+
*/
|
|
80
|
+
getCancelAllOrdersTxn(userAccountPublicKey: PublicKey, marketType?: MarketType, marketIndex?: number, direction?: PositionDirection): Promise<VersionedTransaction | Transaction>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a swap transaction between two spot markets using Jupiter
|
|
83
|
+
*/
|
|
84
|
+
getSwapTxn(userAccountPublicKey: PublicKey, fromMarketIndex: number, toMarketIndex: number, amount: BN, options?: {
|
|
85
|
+
slippageBps?: number;
|
|
86
|
+
swapMode?: SwapMode;
|
|
87
|
+
onlyDirectRoutes?: boolean;
|
|
88
|
+
quote?: QuoteResponse;
|
|
89
|
+
}): Promise<VersionedTransaction | Transaction>;
|
|
90
|
+
sendSignedTransaction(tx: VersionedTransaction | Transaction): Promise<import("@drift-labs/sdk").TxSigAndSlot>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CentralServerDrift = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const commonUiUtils_1 = require("../../../common-ui-utils/commonUiUtils");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const deposit_1 = require("../../base/actions/spot/deposit");
|
|
9
|
+
const withdraw_1 = require("../../base/actions/spot/withdraw");
|
|
10
|
+
const settleFunding_1 = require("../../base/actions/perp/settleFunding");
|
|
11
|
+
const settlePnl_1 = require("../../base/actions/perp/settlePnl");
|
|
12
|
+
const openPerpMarketOrder_1 = require("../../base/actions/trade/openPerpOrder/openPerpMarketOrder");
|
|
13
|
+
const openPerpNonMarketOrder_1 = require("../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder");
|
|
14
|
+
const editOrder_1 = require("../../base/actions/trade/editOrder");
|
|
15
|
+
const cancelOrder_1 = require("../../base/actions/trade/cancelOrder");
|
|
16
|
+
const swap_1 = require("../../base/actions/trade/swap");
|
|
17
|
+
/**
|
|
18
|
+
* A Drift client that fetches user data on-demand, while market data is continuously subscribed to.
|
|
19
|
+
*
|
|
20
|
+
* This is useful for an API server that fetches user data on-demand, and return transaction messages specific to a given user
|
|
21
|
+
*/
|
|
22
|
+
class CentralServerDrift {
|
|
23
|
+
/**
|
|
24
|
+
* @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.
|
|
25
|
+
* @param driftEnv - The drift environment to use for the drift client.
|
|
26
|
+
* @param activeTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.
|
|
27
|
+
* @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.
|
|
28
|
+
*/
|
|
29
|
+
constructor(config) {
|
|
30
|
+
const driftEnv = config.driftEnv;
|
|
31
|
+
const connection = new web3_js_1.Connection(config.solanaRpcEndpoint);
|
|
32
|
+
const driftProgramID = new sdk_1.PublicKey(sdk_1.DRIFT_PROGRAM_ID);
|
|
33
|
+
const accountLoader = new sdk_1.CustomizedCadenceBulkAccountLoader(connection, constants_1.DEFAULT_ACCOUNT_LOADER_COMMITMENT, constants_1.DEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS);
|
|
34
|
+
const wallet = commonUiUtils_1.COMMON_UI_UTILS.createPlaceholderIWallet(); // use random wallet to initialize a central-server instance
|
|
35
|
+
const driftClientConfig = {
|
|
36
|
+
env: driftEnv,
|
|
37
|
+
connection,
|
|
38
|
+
wallet,
|
|
39
|
+
programID: driftProgramID,
|
|
40
|
+
enableMetricsEvents: false,
|
|
41
|
+
accountSubscription: {
|
|
42
|
+
type: 'polling',
|
|
43
|
+
accountLoader,
|
|
44
|
+
},
|
|
45
|
+
userStats: false,
|
|
46
|
+
includeDelegates: false,
|
|
47
|
+
skipLoadUsers: true,
|
|
48
|
+
delistedMarketSetting: sdk_1.DelistedMarketSetting.Unsubscribe,
|
|
49
|
+
...config.additionalDriftClientConfig,
|
|
50
|
+
};
|
|
51
|
+
this.driftClient = new sdk_1.DriftClient(driftClientConfig);
|
|
52
|
+
const txSender = new sdk_1.WhileValidTxSender({
|
|
53
|
+
connection,
|
|
54
|
+
wallet,
|
|
55
|
+
additionalConnections: [],
|
|
56
|
+
additionalTxSenderCallbacks: [],
|
|
57
|
+
txHandler: this.driftClient.txHandler,
|
|
58
|
+
confirmationStrategy: constants_1.DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,
|
|
59
|
+
retrySleep: constants_1.DEFAULT_TX_SENDER_RETRY_INTERVAL,
|
|
60
|
+
});
|
|
61
|
+
this.driftClient.txSender = txSender;
|
|
62
|
+
this._perpMarketConfigs =
|
|
63
|
+
driftEnv === 'devnet' ? sdk_1.DevnetPerpMarkets : sdk_1.MainnetPerpMarkets;
|
|
64
|
+
this.spotMarketConfigs =
|
|
65
|
+
driftEnv === 'devnet' ? sdk_1.DevnetSpotMarkets : sdk_1.MainnetSpotMarkets;
|
|
66
|
+
}
|
|
67
|
+
async subscribe() {
|
|
68
|
+
await this.driftClient.subscribe();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Manages DriftClient state for transaction creation with proper setup and cleanup.
|
|
72
|
+
* This abstraction handles:
|
|
73
|
+
* - User creation and subscription
|
|
74
|
+
* - Authority management
|
|
75
|
+
* - Wallet replacement for correct transaction signing
|
|
76
|
+
* - Cleanup and state restoration
|
|
77
|
+
*
|
|
78
|
+
* @param userAccountPublicKey - The user account public key
|
|
79
|
+
* @param operation - The transaction creation operation to execute
|
|
80
|
+
* @returns The result of the operation
|
|
81
|
+
*/
|
|
82
|
+
async driftClientContextWrapper(userAccountPublicKey, operation) {
|
|
83
|
+
const user = new sdk_1.User({
|
|
84
|
+
driftClient: this.driftClient,
|
|
85
|
+
userAccountPublicKey,
|
|
86
|
+
});
|
|
87
|
+
// Store original state
|
|
88
|
+
const originalWallet = this.driftClient.wallet;
|
|
89
|
+
const originalAuthority = this.driftClient.authority;
|
|
90
|
+
try {
|
|
91
|
+
// Setup: Subscribe to user and configure DriftClient
|
|
92
|
+
await user.subscribe();
|
|
93
|
+
const authority = user.getUserAccount().authority;
|
|
94
|
+
this.driftClient.authority = authority;
|
|
95
|
+
const success = await this.driftClient.addUser(user.getUserAccount().subAccountId, authority);
|
|
96
|
+
if (!success) {
|
|
97
|
+
throw new Error('Failed to add user to DriftClient');
|
|
98
|
+
}
|
|
99
|
+
// Replace wallet with user's authority to ensure correct transaction signing
|
|
100
|
+
// This is necessary because DriftClient adds wallet.publicKey to instructions
|
|
101
|
+
const userWallet = {
|
|
102
|
+
publicKey: authority,
|
|
103
|
+
signTransaction: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
|
|
104
|
+
signAllTransactions: () => Promise.reject('This is a placeholder - do not sign with this wallet'),
|
|
105
|
+
};
|
|
106
|
+
// Update wallet in all places that reference it
|
|
107
|
+
this.driftClient.wallet = userWallet;
|
|
108
|
+
//@ts-ignore
|
|
109
|
+
this.driftClient.provider.wallet = userWallet;
|
|
110
|
+
this.driftClient.txHandler.updateWallet(userWallet);
|
|
111
|
+
// Execute the operation
|
|
112
|
+
const result = await operation(user);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
// Cleanup: Always restore original state and unsubscribe
|
|
117
|
+
this.driftClient.wallet = originalWallet;
|
|
118
|
+
this.driftClient.txHandler.updateWallet(originalWallet);
|
|
119
|
+
this.driftClient.authority = originalAuthority;
|
|
120
|
+
try {
|
|
121
|
+
await user.unsubscribe();
|
|
122
|
+
this.driftClient.users.clear();
|
|
123
|
+
}
|
|
124
|
+
catch (cleanupError) {
|
|
125
|
+
console.warn('Error during cleanup:', cleanupError);
|
|
126
|
+
// Don't throw cleanup errors, but log them
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async getDepositTxn(userAccountPublicKey, amount, spotMarketIndex) {
|
|
131
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
132
|
+
const spotMarketConfig = this.spotMarketConfigs.find((market) => market.marketIndex === spotMarketIndex);
|
|
133
|
+
if (!spotMarketConfig) {
|
|
134
|
+
throw new Error(`Spot market config not found for index ${spotMarketIndex}`);
|
|
135
|
+
}
|
|
136
|
+
const depositTxn = await (0, deposit_1.createDepositTxn)({
|
|
137
|
+
driftClient: this.driftClient,
|
|
138
|
+
user,
|
|
139
|
+
amount: sdk_1.BigNum.from(amount, spotMarketConfig.precisionExp),
|
|
140
|
+
spotMarketConfig,
|
|
141
|
+
});
|
|
142
|
+
return depositTxn;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async getWithdrawTxn(userAccountPublicKey, amount, spotMarketIndex, options) {
|
|
146
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
147
|
+
const spotMarketConfig = this.spotMarketConfigs.find((market) => market.marketIndex === spotMarketIndex);
|
|
148
|
+
if (!spotMarketConfig) {
|
|
149
|
+
throw new Error(`Spot market config not found for index ${spotMarketIndex}`);
|
|
150
|
+
}
|
|
151
|
+
const withdrawTxn = await (0, withdraw_1.createWithdrawTxn)({
|
|
152
|
+
driftClient: this.driftClient,
|
|
153
|
+
user,
|
|
154
|
+
amount: sdk_1.BigNum.from(amount, spotMarketConfig.precisionExp),
|
|
155
|
+
spotMarketConfig,
|
|
156
|
+
isBorrow: options === null || options === void 0 ? void 0 : options.isBorrow,
|
|
157
|
+
isMax: options === null || options === void 0 ? void 0 : options.isMax,
|
|
158
|
+
});
|
|
159
|
+
return withdrawTxn;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async getSettleFundingTxn(userAccountPublicKey) {
|
|
163
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
164
|
+
const settleFundingTxn = await (0, settleFunding_1.createSettleFundingTxn)({
|
|
165
|
+
driftClient: this.driftClient,
|
|
166
|
+
user,
|
|
167
|
+
});
|
|
168
|
+
return settleFundingTxn;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async getSettlePnlTxn(userAccountPublicKey, marketIndexes) {
|
|
172
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
173
|
+
const settlePnlTxn = await (0, settlePnl_1.createSettlePnlTxn)({
|
|
174
|
+
driftClient: this.driftClient,
|
|
175
|
+
user,
|
|
176
|
+
marketIndexes,
|
|
177
|
+
});
|
|
178
|
+
return settlePnlTxn;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async getOpenPerpMarketOrderTxn(userAccountPublicKey, assetType, marketIndex, direction, amount, dlobServerHttpUrl, auctionParamsOptions, useSwift, swiftOptions, marketType) {
|
|
182
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
183
|
+
const openPerpMarketOrderTxn = await (0, openPerpMarketOrder_1.createOpenPerpMarketOrderTxn)({
|
|
184
|
+
driftClient: this.driftClient,
|
|
185
|
+
user,
|
|
186
|
+
assetType,
|
|
187
|
+
marketIndex,
|
|
188
|
+
direction,
|
|
189
|
+
amount,
|
|
190
|
+
dlobServerHttpUrl,
|
|
191
|
+
auctionParamsOptions,
|
|
192
|
+
useSwift,
|
|
193
|
+
swiftOptions,
|
|
194
|
+
marketType,
|
|
195
|
+
});
|
|
196
|
+
return openPerpMarketOrderTxn;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a perp non-market order with amount and asset type
|
|
201
|
+
*/
|
|
202
|
+
async getOpenPerpNonMarketOrderTxn(userAccountPublicKey, marketIndex, direction, amount, assetType, limitPrice, triggerPrice, orderType, reduceOnly, postOnly, useSwift, swiftOptions, oraclePriceOffset) {
|
|
203
|
+
let orderConfig;
|
|
204
|
+
switch (orderType) {
|
|
205
|
+
case 'limit':
|
|
206
|
+
orderConfig = {
|
|
207
|
+
orderType,
|
|
208
|
+
limitPrice,
|
|
209
|
+
};
|
|
210
|
+
break;
|
|
211
|
+
case 'takeProfit':
|
|
212
|
+
case 'stopLoss':
|
|
213
|
+
orderConfig = {
|
|
214
|
+
orderType,
|
|
215
|
+
triggerPrice,
|
|
216
|
+
limitPrice,
|
|
217
|
+
};
|
|
218
|
+
break;
|
|
219
|
+
case 'oracleLimit':
|
|
220
|
+
orderConfig = {
|
|
221
|
+
orderType,
|
|
222
|
+
oraclePriceOffset,
|
|
223
|
+
};
|
|
224
|
+
break;
|
|
225
|
+
default: {
|
|
226
|
+
const _exhaustiveCheck = orderType;
|
|
227
|
+
throw new Error(`Unsupported order type: ${_exhaustiveCheck}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
231
|
+
const openPerpNonMarketOrderTxn = await (0, openPerpNonMarketOrder_1.createOpenPerpNonMarketOrderTxn)({
|
|
232
|
+
driftClient: this.driftClient,
|
|
233
|
+
user,
|
|
234
|
+
marketIndex,
|
|
235
|
+
direction,
|
|
236
|
+
amount,
|
|
237
|
+
assetType,
|
|
238
|
+
orderConfig,
|
|
239
|
+
reduceOnly,
|
|
240
|
+
postOnly,
|
|
241
|
+
useSwift,
|
|
242
|
+
swiftOptions,
|
|
243
|
+
});
|
|
244
|
+
return openPerpNonMarketOrderTxn;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create a transaction to edit an existing order
|
|
249
|
+
*/
|
|
250
|
+
async getEditOrderTxn(userAccountPublicKey, orderId, editOrderParams) {
|
|
251
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
252
|
+
const editOrderTxn = await (0, editOrder_1.createEditOrderTxn)(this.driftClient, user, orderId, editOrderParams);
|
|
253
|
+
return editOrderTxn;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a transaction to cancel specific orders by their IDs
|
|
258
|
+
*/
|
|
259
|
+
async getCancelOrdersTxn(userAccountPublicKey, orderIds) {
|
|
260
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
261
|
+
const cancelOrdersTxn = await (0, cancelOrder_1.createCancelOrdersTxn)(this.driftClient, user, orderIds);
|
|
262
|
+
return cancelOrdersTxn;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a transaction to cancel all orders for a user
|
|
267
|
+
*/
|
|
268
|
+
async getCancelAllOrdersTxn(userAccountPublicKey, marketType, marketIndex, direction) {
|
|
269
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
270
|
+
const ix = await this.driftClient.getCancelOrdersIx(marketType !== null && marketType !== void 0 ? marketType : null, marketIndex !== null && marketIndex !== void 0 ? marketIndex : null, direction !== null && direction !== void 0 ? direction : null, user.getUserAccount().subAccountId);
|
|
271
|
+
const cancelAllOrdersTxn = await this.driftClient.buildTransaction(ix);
|
|
272
|
+
return cancelAllOrdersTxn;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create a swap transaction between two spot markets using Jupiter
|
|
277
|
+
*/
|
|
278
|
+
async getSwapTxn(userAccountPublicKey, fromMarketIndex, toMarketIndex, amount, options) {
|
|
279
|
+
return this.driftClientContextWrapper(userAccountPublicKey, async (user) => {
|
|
280
|
+
var _a, _b, _c;
|
|
281
|
+
const fromSpotMarketConfig = this.spotMarketConfigs.find((market) => market.marketIndex === fromMarketIndex);
|
|
282
|
+
const toSpotMarketConfig = this.spotMarketConfigs.find((market) => market.marketIndex === toMarketIndex);
|
|
283
|
+
if (!fromSpotMarketConfig) {
|
|
284
|
+
throw new Error(`From spot market config not found for index ${fromMarketIndex}`);
|
|
285
|
+
}
|
|
286
|
+
if (!toSpotMarketConfig) {
|
|
287
|
+
throw new Error(`To spot market config not found for index ${toMarketIndex}`);
|
|
288
|
+
}
|
|
289
|
+
// Initialize Jupiter client
|
|
290
|
+
const jupiterClient = new sdk_1.JupiterClient({
|
|
291
|
+
connection: this.driftClient.connection,
|
|
292
|
+
});
|
|
293
|
+
// Get quote if not provided
|
|
294
|
+
let quote = options === null || options === void 0 ? void 0 : options.quote;
|
|
295
|
+
if (!quote) {
|
|
296
|
+
quote = await jupiterClient.getQuote({
|
|
297
|
+
inputMint: fromSpotMarketConfig.mint,
|
|
298
|
+
outputMint: toSpotMarketConfig.mint,
|
|
299
|
+
amount,
|
|
300
|
+
slippageBps: (_a = options === null || options === void 0 ? void 0 : options.slippageBps) !== null && _a !== void 0 ? _a : 10, // Default 0.1%
|
|
301
|
+
swapMode: (_b = options === null || options === void 0 ? void 0 : options.swapMode) !== null && _b !== void 0 ? _b : 'ExactIn',
|
|
302
|
+
onlyDirectRoutes: (_c = options === null || options === void 0 ? void 0 : options.onlyDirectRoutes) !== null && _c !== void 0 ? _c : false,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const swapTxn = await (0, swap_1.createSwapTxn)({
|
|
306
|
+
driftClient: this.driftClient,
|
|
307
|
+
jupiterClient,
|
|
308
|
+
user,
|
|
309
|
+
swapFromMarketIndex: fromMarketIndex,
|
|
310
|
+
swapToMarketIndex: toMarketIndex,
|
|
311
|
+
amount,
|
|
312
|
+
quote,
|
|
313
|
+
txParams: {
|
|
314
|
+
useSimulatedComputeUnits: true,
|
|
315
|
+
computeUnitsBufferMultiplier: 1.5,
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
return swapTxn;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
async sendSignedTransaction(tx) {
|
|
322
|
+
return this.driftClient.sendTransaction(tx, undefined, undefined, true);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
exports.CentralServerDrift = CentralServerDrift;
|
|
326
|
+
//# sourceMappingURL=CentralServerDrift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CentralServerD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,gBAAgB,mCAAI,KAAK;iBACpD,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAa,EAAC;gBACnC,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,aAAa;gBACb,IAAI;gBACJ,mBAAmB,EAAE,eAAe;gBACpC,iBAAiB,EAAE,aAAa;gBAChC,MAAM;gBACN,KAAK;gBACL,QAAQ,EAAE;oBACT,wBAAwB,EAAE,IAAI;oBAC9B,4BAA4B,EAAE,GAAG;iBACjC;aACD,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,EAAsC;QACxE,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;CACD;AArgBD,gDAqgBC","sourcesContent":["import {\n\tBigNum,\n\tBN,\n\tCustomizedCadenceBulkAccountLoader,\n\tDelistedMarketSetting,\n\tDevnetPerpMarkets,\n\tDevnetSpotMarkets,\n\tDRIFT_PROGRAM_ID,\n\tDriftClient,\n\tDriftClientConfig,\n\tDriftEnv,\n\tJupiterClient,\n\tMainnetPerpMarkets,\n\tMainnetSpotMarkets,\n\tMarketType,\n\tOrderTriggerCondition,\n\tPerpMarketConfig,\n\tPositionDirection,\n\tPostOnlyParams,\n\tPublicKey,\n\tQuoteResponse,\n\tSpotMarketConfig,\n\tSwapMode,\n\tUser,\n\tWhileValidTxSender,\n} from '@drift-labs/sdk';\nimport { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { COMMON_UI_UTILS } from '../../../common-ui-utils/commonUiUtils';\nimport {\n\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS,\n\tDEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\tDEFAULT_TX_SENDER_RETRY_INTERVAL,\n} from '../constants';\nimport { MarketId } from '../../../types';\nimport { createDepositTxn } from '../../base/actions/spot/deposit';\nimport { createWithdrawTxn } from '../../base/actions/spot/withdraw';\nimport { createSettleFundingTxn } from '../../base/actions/perp/settleFunding';\nimport { createSettlePnlTxn } from '../../base/actions/perp/settlePnl';\nimport {\n\tcreateOpenPerpMarketOrderTxn,\n\tAuctionParamsRequestOptions,\n} from '../../base/actions/trade/openPerpOrder/openPerpMarketOrder';\nimport { createOpenPerpNonMarketOrderTxn } from '../../base/actions/trade/openPerpOrder/openPerpNonMarketOrder';\nimport { createEditOrderTxn } from '../../base/actions/trade/editOrder';\nimport { createCancelOrdersTxn } from '../../base/actions/trade/cancelOrder';\nimport { createSwapTxn } from '../../base/actions/trade/swap';\nimport { NonMarketOrderParamsConfig } from '../../utils/orderParams';\nimport {\n\tSwiftOrderResult,\n\tSwiftOrderOptions,\n} from '../../base/actions/trade/openPerpOrder/openSwiftOrder';\n\n/**\n * A Drift client that fetches user data on-demand, while market data is continuously subscribed to.\n *\n * This is useful for an API server that fetches user data on-demand, and return transaction messages specific to a given user\n */\nexport class CentralServerDrift {\n\tprivate driftClient: DriftClient;\n\tprivate _perpMarketConfigs: PerpMarketConfig[];\n\tprivate spotMarketConfigs: SpotMarketConfig[];\n\n\t/**\n\t * @param solanaRpcEndpoint - The Solana RPC endpoint to use for reading RPC data.\n\t * @param driftEnv - The drift environment to use for the drift client.\n\t * @param activeTradeMarket - The active trade market to use for the drift client. This is used to subscribe to the market account, oracle data and mark price more frequently compared to the other markets.\n\t * @param additionalDriftClientConfig - Additional DriftClient config to use for the DriftClient.\n\t */\n\tconstructor(config: {\n\t\tsolanaRpcEndpoint: string;\n\t\tdriftEnv: DriftEnv;\n\t\tadditionalDriftClientConfig?: Partial<Omit<DriftClientConfig, 'env'>>;\n\t\tactiveTradeMarket?: MarketId;\n\t\tmarketsToSubscribe?: MarketId[];\n\t}) {\n\t\tconst driftEnv = config.driftEnv;\n\n\t\tconst connection = new Connection(config.solanaRpcEndpoint);\n\t\tconst driftProgramID = new PublicKey(DRIFT_PROGRAM_ID);\n\t\tconst accountLoader = new CustomizedCadenceBulkAccountLoader(\n\t\t\tconnection,\n\t\t\tDEFAULT_ACCOUNT_LOADER_COMMITMENT,\n\t\t\tDEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS\n\t\t);\n\n\t\tconst wallet = COMMON_UI_UTILS.createPlaceholderIWallet(); // use random wallet to initialize a central-server instance\n\n\t\tconst driftClientConfig: DriftClientConfig = {\n\t\t\tenv: driftEnv,\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tprogramID: driftProgramID,\n\t\t\tenableMetricsEvents: false,\n\t\t\taccountSubscription: {\n\t\t\t\ttype: 'polling',\n\t\t\t\taccountLoader,\n\t\t\t},\n\t\t\tuserStats: false,\n\t\t\tincludeDelegates: false,\n\t\t\tskipLoadUsers: true,\n\t\t\tdelistedMarketSetting: DelistedMarketSetting.Unsubscribe,\n\t\t\t...config.additionalDriftClientConfig,\n\t\t};\n\t\tthis.driftClient = new DriftClient(driftClientConfig);\n\n\t\tconst txSender = new WhileValidTxSender({\n\t\t\tconnection,\n\t\t\twallet,\n\t\t\tadditionalConnections: [],\n\t\t\tadditionalTxSenderCallbacks: [],\n\t\t\ttxHandler: this.driftClient.txHandler,\n\t\t\tconfirmationStrategy: DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY,\n\t\t\tretrySleep: DEFAULT_TX_SENDER_RETRY_INTERVAL,\n\t\t});\n\n\t\tthis.driftClient.txSender = txSender;\n\t\tthis._perpMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;\n\t\tthis.spotMarketConfigs =\n\t\t\tdriftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;\n\t}\n\n\tpublic async subscribe() {\n\t\tawait this.driftClient.subscribe();\n\t}\n\n\t/**\n\t * Manages DriftClient state for transaction creation with proper setup and cleanup.\n\t * This abstraction handles:\n\t * - User creation and subscription\n\t * - Authority management\n\t * - Wallet replacement for correct transaction signing\n\t * - Cleanup and state restoration\n\t *\n\t * @param userAccountPublicKey - The user account public key\n\t * @param operation - The transaction creation operation to execute\n\t * @returns The result of the operation\n\t */\n\tprivate async driftClientContextWrapper<T>(\n\t\tuserAccountPublicKey: PublicKey,\n\t\toperation: (user: User) => Promise<T>\n\t): Promise<T> {\n\t\tconst user = new User({\n\t\t\tdriftClient: this.driftClient,\n\t\t\tuserAccountPublicKey,\n\t\t});\n\n\t\t// Store original state\n\t\tconst originalWallet = this.driftClient.wallet;\n\t\tconst originalAuthority = this.driftClient.authority;\n\n\t\ttry {\n\t\t\t// Setup: Subscribe to user and configure DriftClient\n\t\t\tawait user.subscribe();\n\n\t\t\tconst authority = user.getUserAccount().authority;\n\t\t\tthis.driftClient.authority = authority;\n\n\t\t\tconst success = await this.driftClient.addUser(\n\t\t\t\tuser.getUserAccount().subAccountId,\n\t\t\t\tauthority\n\t\t\t);\n\n\t\t\tif (!success) {\n\t\t\t\tthrow new Error('Failed to add user to DriftClient');\n\t\t\t}\n\n\t\t\t// Replace wallet with user's authority to ensure correct transaction signing\n\t\t\t// This is necessary because DriftClient adds wallet.publicKey to instructions\n\t\t\tconst userWallet = {\n\t\t\t\tpublicKey: authority,\n\t\t\t\tsignTransaction: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t\tsignAllTransactions: () =>\n\t\t\t\t\tPromise.reject(\n\t\t\t\t\t\t'This is a placeholder - do not sign with this wallet'\n\t\t\t\t\t),\n\t\t\t};\n\n\t\t\t// Update wallet in all places that reference it\n\t\t\tthis.driftClient.wallet = userWallet;\n\t\t\t//@ts-ignore\n\t\t\tthis.driftClient.provider.wallet = userWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(userWallet);\n\n\t\t\t// Execute the operation\n\t\t\tconst result = await operation(user);\n\n\t\t\treturn result;\n\t\t} finally {\n\t\t\t// Cleanup: Always restore original state and unsubscribe\n\t\t\tthis.driftClient.wallet = originalWallet;\n\t\t\tthis.driftClient.txHandler.updateWallet(originalWallet);\n\t\t\tthis.driftClient.authority = originalAuthority;\n\n\t\t\ttry {\n\t\t\t\tawait user.unsubscribe();\n\t\t\t\tthis.driftClient.users.clear();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tconsole.warn('Error during cleanup:', cleanupError);\n\t\t\t\t// Don't throw cleanup errors, but log them\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async getDepositTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst depositTxn = await createDepositTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t});\n\n\t\t\t\treturn depositTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getWithdrawTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tamount: BN,\n\t\tspotMarketIndex: number,\n\t\toptions?: {\n\t\t\tisBorrow?: boolean;\n\t\t\tisMax?: boolean;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst spotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === spotMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!spotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Spot market config not found for index ${spotMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst withdrawTxn = await createWithdrawTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tamount: BigNum.from(amount, spotMarketConfig.precisionExp),\n\t\t\t\t\tspotMarketConfig,\n\t\t\t\t\tisBorrow: options?.isBorrow,\n\t\t\t\t\tisMax: options?.isMax,\n\t\t\t\t});\n\n\t\t\t\treturn withdrawTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettleFundingTxn(\n\t\tuserAccountPublicKey: PublicKey\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settleFundingTxn = await createSettleFundingTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\n\t\t\t\treturn settleFundingTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getSettlePnlTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketIndexes: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst settlePnlTxn = await createSettlePnlTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tmarketIndexes,\n\t\t\t\t});\n\n\t\t\t\treturn settlePnlTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async getOpenPerpMarketOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tassetType: 'base' | 'quote',\n\t\tmarketIndex: number,\n\t\tdirection: PositionDirection,\n\t\tamount: BN,\n\t\tdlobServerHttpUrl: string,\n\t\tauctionParamsOptions?: AuctionParamsRequestOptions,\n\t\tuseSwift?: boolean,\n\t\tswiftOptions?: SwiftOrderOptions,\n\t\tmarketType?: MarketType\n\t): Promise<VersionedTransaction | Transaction | SwiftOrderResult> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrderTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tassetType,\n\t\t\t\t\tmarketIndex,\n\t\t\t\t\tdirection,\n\t\t\t\t\tamount,\n\t\t\t\t\tdlobServerHttpUrl,\n\t\t\t\t\tauctionParamsOptions,\n\t\t\t\t\tuseSwift,\n\t\t\t\t\tswiftOptions,\n\t\t\t\t\tmarketType,\n\t\t\t\t});\n\n\t\t\t\treturn openPerpMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a perp non-market order with amount and asset type\n\t */\n\tpublic async getOpenPerpNonMarketOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketIndex: number,\n\t\tdirection: PositionDirection,\n\t\tamount: BN,\n\t\tassetType: 'base' | 'quote',\n\t\tlimitPrice?: BN,\n\t\ttriggerPrice?: BN,\n\t\torderType?: 'limit' | 'takeProfit' | 'stopLoss' | 'oracleLimit',\n\t\treduceOnly?: boolean,\n\t\tpostOnly?: PostOnlyParams,\n\t\tuseSwift?: boolean,\n\t\tswiftOptions?: SwiftOrderOptions,\n\t\toraclePriceOffset?: BN\n\t): Promise<VersionedTransaction | Transaction | SwiftOrderResult> {\n\t\tlet orderConfig: NonMarketOrderParamsConfig['orderConfig'];\n\n\t\tswitch (orderType) {\n\t\t\tcase 'limit':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\tlimitPrice,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'takeProfit':\n\t\t\tcase 'stopLoss':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\ttriggerPrice,\n\t\t\t\t\tlimitPrice,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'oracleLimit':\n\t\t\t\torderConfig = {\n\t\t\t\t\torderType,\n\t\t\t\t\toraclePriceOffset,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst _exhaustiveCheck: never = orderType;\n\t\t\t\tthrow new Error(`Unsupported order type: ${_exhaustiveCheck}`);\n\t\t\t}\n\t\t}\n\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst openPerpNonMarketOrderTxn = await createOpenPerpNonMarketOrderTxn(\n\t\t\t\t\t{\n\t\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tmarketIndex,\n\t\t\t\t\t\tdirection,\n\t\t\t\t\t\tamount,\n\t\t\t\t\t\tassetType,\n\t\t\t\t\t\torderConfig,\n\t\t\t\t\t\treduceOnly,\n\t\t\t\t\t\tpostOnly,\n\t\t\t\t\t\tuseSwift,\n\t\t\t\t\t\tswiftOptions,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn openPerpNonMarketOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to edit an existing order\n\t */\n\tpublic async getEditOrderTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderId: number,\n\t\teditOrderParams: {\n\t\t\tnewDirection?: PositionDirection;\n\t\t\tnewBaseAmount?: BN;\n\t\t\tnewLimitPrice?: BN;\n\t\t\tnewOraclePriceOffset?: number;\n\t\t\tnewTriggerPrice?: BN;\n\t\t\tnewTriggerCondition?: OrderTriggerCondition;\n\t\t\tauctionDuration?: number;\n\t\t\tauctionStartPrice?: BN;\n\t\t\tauctionEndPrice?: BN;\n\t\t\treduceOnly?: boolean;\n\t\t\tpostOnly?: boolean;\n\t\t\tbitFlags?: number;\n\t\t\tmaxTs?: BN;\n\t\t\tpolicy?: number;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst editOrderTxn = await createEditOrderTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderId,\n\t\t\t\t\teditOrderParams\n\t\t\t\t);\n\n\t\t\t\treturn editOrderTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel specific orders by their IDs\n\t */\n\tpublic async getCancelOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\torderIds: number[]\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst cancelOrdersTxn = await createCancelOrdersTxn(\n\t\t\t\t\tthis.driftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\torderIds\n\t\t\t\t);\n\n\t\t\t\treturn cancelOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a transaction to cancel all orders for a user\n\t */\n\tpublic async getCancelAllOrdersTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tmarketType?: MarketType,\n\t\tmarketIndex?: number,\n\t\tdirection?: PositionDirection\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst ix = await this.driftClient.getCancelOrdersIx(\n\t\t\t\t\tmarketType ?? null,\n\t\t\t\t\tmarketIndex ?? null,\n\t\t\t\t\tdirection ?? null,\n\t\t\t\t\tuser.getUserAccount().subAccountId\n\t\t\t\t);\n\n\t\t\t\tconst cancelAllOrdersTxn = await this.driftClient.buildTransaction(ix);\n\n\t\t\t\treturn cancelAllOrdersTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Create a swap transaction between two spot markets using Jupiter\n\t */\n\tpublic async getSwapTxn(\n\t\tuserAccountPublicKey: PublicKey,\n\t\tfromMarketIndex: number,\n\t\ttoMarketIndex: number,\n\t\tamount: BN,\n\t\toptions?: {\n\t\t\tslippageBps?: number;\n\t\t\tswapMode?: SwapMode;\n\t\t\tonlyDirectRoutes?: boolean;\n\t\t\tquote?: QuoteResponse;\n\t\t}\n\t): Promise<VersionedTransaction | Transaction> {\n\t\treturn this.driftClientContextWrapper(\n\t\t\tuserAccountPublicKey,\n\t\t\tasync (user) => {\n\t\t\t\tconst fromSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === fromMarketIndex\n\t\t\t\t);\n\t\t\t\tconst toSpotMarketConfig = this.spotMarketConfigs.find(\n\t\t\t\t\t(market) => market.marketIndex === toMarketIndex\n\t\t\t\t);\n\n\t\t\t\tif (!fromSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`From spot market config not found for index ${fromMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!toSpotMarketConfig) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`To spot market config not found for index ${toMarketIndex}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Initialize Jupiter client\n\t\t\t\tconst jupiterClient = new JupiterClient({\n\t\t\t\t\tconnection: this.driftClient.connection,\n\t\t\t\t});\n\n\t\t\t\t// Get quote if not provided\n\t\t\t\tlet quote = options?.quote;\n\t\t\t\tif (!quote) {\n\t\t\t\t\tquote = await jupiterClient.getQuote({\n\t\t\t\t\t\tinputMint: fromSpotMarketConfig.mint,\n\t\t\t\t\t\toutputMint: toSpotMarketConfig.mint,\n\t\t\t\t\t\tamount,\n\t\t\t\t\t\tslippageBps: options?.slippageBps ?? 10, // Default 0.1%\n\t\t\t\t\t\tswapMode: options?.swapMode ?? 'ExactIn',\n\t\t\t\t\t\tonlyDirectRoutes: options?.onlyDirectRoutes ?? false,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst swapTxn = await createSwapTxn({\n\t\t\t\t\tdriftClient: this.driftClient,\n\t\t\t\t\tjupiterClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tswapFromMarketIndex: fromMarketIndex,\n\t\t\t\t\tswapToMarketIndex: toMarketIndex,\n\t\t\t\t\tamount,\n\t\t\t\t\tquote,\n\t\t\t\t\ttxParams: {\n\t\t\t\t\t\tuseSimulatedComputeUnits: true,\n\t\t\t\t\t\tcomputeUnitsBufferMultiplier: 1.5,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\treturn swapTxn;\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic async sendSignedTransaction(tx: VersionedTransaction | Transaction) {\n\t\treturn this.driftClient.sendTransaction(tx, undefined, undefined, true);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AuthorityDrift"), exports);
|
|
18
|
+
__exportStar(require("./AuthorityDrift/DriftOperations/types"), exports);
|
|
19
|
+
__exportStar(require("./CentralServerDrift"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drift/Drift/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,yEAAuD;AACvD,uDAAqC","sourcesContent":["export * from './AuthorityDrift';\nexport * from './AuthorityDrift/DriftOperations/types';\nexport * from './CentralServerDrift';\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConfirmationStrategy } from '@drift-labs/sdk';
|
|
2
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
|
+
export declare const DEFAULT_ACCOUNT_LOADER_COMMITMENT: Commitment;
|
|
4
|
+
export declare const DEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS = 1000;
|
|
5
|
+
export declare const DEFAULT_TX_SENDER_RETRY_INTERVAL = 4000;
|
|
6
|
+
export declare const DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY = ConfirmationStrategy.Combo;
|
|
7
|
+
export declare const SELECTED_MARKET_ACCOUNT_POLLING_CADENCE = 1000;
|
|
8
|
+
export declare const USER_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 1000;
|
|
9
|
+
export declare const USER_NOT_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 60000;
|
|
10
|
+
export declare const DELISTED_MARKET_STATUSES: ({
|
|
11
|
+
settlement: {};
|
|
12
|
+
} | {
|
|
13
|
+
delisted: {};
|
|
14
|
+
})[];
|
|
15
|
+
export declare enum PollingCategory {
|
|
16
|
+
SELECTED_MARKET = "selected-market",
|
|
17
|
+
USER_INVOLVED = "user-involved",
|
|
18
|
+
USER_NOT_INVOLVED = "user-not-involved"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Accounts that are frequently used for trading.
|
|
22
|
+
* These accounts can be used to estimate priority fees.
|
|
23
|
+
*/
|
|
24
|
+
export declare const HIGH_ACTIVITY_MARKET_ACCOUNTS: PublicKey[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HIGH_ACTIVITY_MARKET_ACCOUNTS = exports.PollingCategory = exports.DELISTED_MARKET_STATUSES = exports.USER_NOT_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = exports.USER_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = exports.SELECTED_MARKET_ACCOUNT_POLLING_CADENCE = exports.DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY = exports.DEFAULT_TX_SENDER_RETRY_INTERVAL = exports.DEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS = exports.DEFAULT_ACCOUNT_LOADER_COMMITMENT = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
exports.DEFAULT_ACCOUNT_LOADER_COMMITMENT = 'confirmed';
|
|
7
|
+
exports.DEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS = 1000;
|
|
8
|
+
exports.DEFAULT_TX_SENDER_RETRY_INTERVAL = 4000;
|
|
9
|
+
exports.DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY = sdk_1.ConfirmationStrategy.Combo;
|
|
10
|
+
exports.SELECTED_MARKET_ACCOUNT_POLLING_CADENCE = 1000;
|
|
11
|
+
exports.USER_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 1000;
|
|
12
|
+
exports.USER_NOT_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 60000;
|
|
13
|
+
exports.DELISTED_MARKET_STATUSES = [
|
|
14
|
+
sdk_1.MarketStatus.DELISTED,
|
|
15
|
+
sdk_1.MarketStatus.SETTLEMENT,
|
|
16
|
+
];
|
|
17
|
+
var PollingCategory;
|
|
18
|
+
(function (PollingCategory) {
|
|
19
|
+
PollingCategory["SELECTED_MARKET"] = "selected-market";
|
|
20
|
+
PollingCategory["USER_INVOLVED"] = "user-involved";
|
|
21
|
+
PollingCategory["USER_NOT_INVOLVED"] = "user-not-involved";
|
|
22
|
+
})(PollingCategory || (exports.PollingCategory = PollingCategory = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Accounts that are frequently used for trading.
|
|
25
|
+
* These accounts can be used to estimate priority fees.
|
|
26
|
+
*/
|
|
27
|
+
exports.HIGH_ACTIVITY_MARKET_ACCOUNTS = [
|
|
28
|
+
new web3_js_1.PublicKey('8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'), // sol openbook market
|
|
29
|
+
new web3_js_1.PublicKey('8UJgxaiQx5nTrdDgph5FiahMmzduuLTLf5WmsPegYA6W'), // sol perp
|
|
30
|
+
new web3_js_1.PublicKey('6gMq3mRCKf8aP3ttTyYhuijVZ2LGi14oDsBbkgubfLB3'), // usdc
|
|
31
|
+
];
|
|
32
|
+
//# sourceMappingURL=blockchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../../../src/drift/Drift/constants/blockchain.ts"],"names":[],"mappings":";;;AAAA,yCAAqE;AACrE,6CAAwD;AAE3C,QAAA,iCAAiC,GAAe,WAAW,CAAC;AAC5D,QAAA,2CAA2C,GAAG,IAAI,CAAC;AACnD,QAAA,gCAAgC,GAAG,IAAI,CAAC;AACxC,QAAA,uCAAuC,GACnD,0BAAoB,CAAC,KAAK,CAAC;AAEf,QAAA,uCAAuC,GAAG,IAAK,CAAC;AAChD,QAAA,4CAA4C,GAAG,IAAK,CAAC;AACrD,QAAA,gDAAgD,GAAG,KAAM,CAAC;AAE1D,QAAA,wBAAwB,GAAG;IACvC,kBAAY,CAAC,QAAQ;IACrB,kBAAY,CAAC,UAAU;CACvB,CAAC;AAEF,IAAY,eAIX;AAJD,WAAY,eAAe;IAC1B,sDAAmC,CAAA;IACnC,kDAA+B,CAAA;IAC/B,0DAAuC,CAAA;AACxC,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED;;;GAGG;AACU,QAAA,6BAA6B,GAAG;IAC5C,IAAI,mBAAS,CAAC,8CAA8C,CAAC,EAAE,sBAAsB;IACrF,IAAI,mBAAS,CAAC,8CAA8C,CAAC,EAAE,WAAW;IAC1E,IAAI,mBAAS,CAAC,8CAA8C,CAAC,EAAE,OAAO;CACtE,CAAC","sourcesContent":["import { ConfirmationStrategy, MarketStatus } from '@drift-labs/sdk';\nimport { Commitment, PublicKey } from '@solana/web3.js';\n\nexport const DEFAULT_ACCOUNT_LOADER_COMMITMENT: Commitment = 'confirmed';\nexport const DEFAULT_ACCOUNT_LOADER_POLLING_FREQUENCY_MS = 1000;\nexport const DEFAULT_TX_SENDER_RETRY_INTERVAL = 4000;\nexport const DEFAULT_TX_SENDER_CONFIRMATION_STRATEGY =\n\tConfirmationStrategy.Combo;\n\nexport const SELECTED_MARKET_ACCOUNT_POLLING_CADENCE = 1_000;\nexport const USER_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 1_000;\nexport const USER_NOT_INVOLVED_MARKET_ACCOUNT_POLLING_CADENCE = 60_000;\n\nexport const DELISTED_MARKET_STATUSES = [\n\tMarketStatus.DELISTED,\n\tMarketStatus.SETTLEMENT,\n];\n\nexport enum PollingCategory {\n\tSELECTED_MARKET = 'selected-market',\n\tUSER_INVOLVED = 'user-involved',\n\tUSER_NOT_INVOLVED = 'user-not-involved',\n}\n\n/**\n * Accounts that are frequently used for trading.\n * These accounts can be used to estimate priority fees.\n */\nexport const HIGH_ACTIVITY_MARKET_ACCOUNTS = [\n\tnew PublicKey('8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'), // sol openbook market\n\tnew PublicKey('8UJgxaiQx5nTrdDgph5FiahMmzduuLTLf5WmsPegYA6W'), // sol perp\n\tnew PublicKey('6gMq3mRCKf8aP3ttTyYhuijVZ2LGi14oDsBbkgubfLB3'), // usdc\n];\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoBlockError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a method is called while the user is geographically blocked.
|
|
6
|
+
*/
|
|
7
|
+
class GeoBlockError extends Error {
|
|
8
|
+
constructor(methodName) {
|
|
9
|
+
super(`Method '${methodName}' is not available due to geographical restrictions.`);
|
|
10
|
+
this.name = 'GeoBlockError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.GeoBlockError = GeoBlockError;
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/drift/Drift/constants/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IACvC,YAAY,UAAkB;QAC7B,KAAK,CACJ,WAAW,UAAU,sDAAsD,CAC3E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAPD,sCAOC","sourcesContent":["/**\n * Error thrown when a method is called while the user is geographically blocked.\n */\nexport class GeoBlockError extends Error {\n\tconstructor(methodName: string) {\n\t\tsuper(\n\t\t\t`Method '${methodName}' is not available due to geographical restrictions.`\n\t\t);\n\t\tthis.name = 'GeoBlockError';\n\t}\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./blockchain"), exports);
|
|
18
|
+
__exportStar(require("./errors"), exports);
|
|
19
|
+
__exportStar(require("./orderbook"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drift/Drift/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,2CAAyB;AACzB,8CAA4B","sourcesContent":["export * from './blockchain';\nexport * from './errors';\nexport * from './orderbook';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DlobServerChannel, OrderbookGrouping } from '../../../utils/dlob-server/DlobServerWebsocketUtils';
|
|
2
|
+
export declare const DEFAULT_ORDERBOOK_GROUPING: OrderbookGrouping;
|
|
3
|
+
export declare const DEFAULT_ORDERBOOK_CHANNEL: DlobServerChannel;
|
|
4
|
+
export declare const DEFAULT_ORDERBOOK_SUBSCRIPTION_CONFIG: {
|
|
5
|
+
channel: "orderbook_indicative";
|
|
6
|
+
grouping: 100;
|
|
7
|
+
};
|