@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 @@
|
|
|
1
|
+
{"version":3,"file":"borrow.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/borrow.ts"],"names":[],"mappings":";;;AAAO,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;IACxC,QAAQ;AACT,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB","sourcesContent":["export const createBorrowIx = async () => {\n\t// TODO:\n};\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BigNum, DriftClient, SpotMarketConfig, TxParams, User } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
interface CreateDepositIxParams {
|
|
4
|
+
driftClient: DriftClient;
|
|
5
|
+
user: User;
|
|
6
|
+
amount: BigNum;
|
|
7
|
+
spotMarketConfig: Pick<SpotMarketConfig, 'mint' | 'marketIndex'>;
|
|
8
|
+
isMaxBorrowRepayment?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates transaction instructions for depositing a spot token.
|
|
12
|
+
*
|
|
13
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
14
|
+
* @param user - The user account that will perform the deposit
|
|
15
|
+
* @param amount - The amount to deposit (in BigNum format)
|
|
16
|
+
* @param spotMarketConfig - The spot market configuration for the token being deposited
|
|
17
|
+
* @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)
|
|
18
|
+
*
|
|
19
|
+
* @returns Promise resolving to an array of transaction instructions for the deposit
|
|
20
|
+
*/
|
|
21
|
+
export declare const createDepositIxs: ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, }: CreateDepositIxParams) => Promise<TransactionInstruction[]>;
|
|
22
|
+
interface CreateDepositTxnParams extends CreateDepositIxParams {
|
|
23
|
+
txParams?: TxParams;
|
|
24
|
+
initSwiftAccount?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a complete transaction for depositing assets into a spot market.
|
|
28
|
+
*
|
|
29
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
30
|
+
* @param user - The user account that will perform the deposit
|
|
31
|
+
* @param amount - The amount to deposit (in BigNum format)
|
|
32
|
+
* @param spotMarketConfig - The spot market configuration for the token being deposited
|
|
33
|
+
* @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)
|
|
34
|
+
* @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)
|
|
35
|
+
* @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit
|
|
36
|
+
*
|
|
37
|
+
* @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)
|
|
38
|
+
*/
|
|
39
|
+
export declare const createDepositTxn: ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, txParams: _txParams, initSwiftAccount: _initSwiftAccount, }: CreateDepositTxnParams) => Promise<Transaction | VersionedTransaction>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDepositTxn = exports.createDepositIxs = void 0;
|
|
4
|
+
const token_1 = require("../../../../utils/token");
|
|
5
|
+
/**
|
|
6
|
+
* Creates transaction instructions for depositing a spot token.
|
|
7
|
+
*
|
|
8
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
9
|
+
* @param user - The user account that will perform the deposit
|
|
10
|
+
* @param amount - The amount to deposit (in BigNum format)
|
|
11
|
+
* @param spotMarketConfig - The spot market configuration for the token being deposited
|
|
12
|
+
* @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)
|
|
13
|
+
*
|
|
14
|
+
* @returns Promise resolving to an array of transaction instructions for the deposit
|
|
15
|
+
*/
|
|
16
|
+
const createDepositIxs = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, }) => {
|
|
17
|
+
const authority = user.getUserAccount().authority;
|
|
18
|
+
const associatedDepositTokenAddress = await (0, token_1.getTokenAddressForDepositAndWithdraw)(spotMarketConfig.mint, authority);
|
|
19
|
+
let finalDepositAmount = amount;
|
|
20
|
+
if (isMaxBorrowRepayment) {
|
|
21
|
+
// we over-estimate to ensure that there is no borrow dust left
|
|
22
|
+
// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate
|
|
23
|
+
finalDepositAmount = finalDepositAmount.scale(2, 1);
|
|
24
|
+
}
|
|
25
|
+
const depositIxs = await driftClient.getDepositTxnIx(finalDepositAmount.val, spotMarketConfig.marketIndex, associatedDepositTokenAddress, user.getUserAccount().subAccountId, isMaxBorrowRepayment);
|
|
26
|
+
return depositIxs;
|
|
27
|
+
};
|
|
28
|
+
exports.createDepositIxs = createDepositIxs;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a complete transaction for depositing assets into a spot market.
|
|
31
|
+
*
|
|
32
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
33
|
+
* @param user - The user account that will perform the deposit
|
|
34
|
+
* @param amount - The amount to deposit (in BigNum format)
|
|
35
|
+
* @param spotMarketConfig - The spot market configuration for the token being deposited
|
|
36
|
+
* @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)
|
|
37
|
+
* @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)
|
|
38
|
+
* @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit
|
|
39
|
+
*
|
|
40
|
+
* @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)
|
|
41
|
+
*/
|
|
42
|
+
const createDepositTxn = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, txParams: _txParams, initSwiftAccount: _initSwiftAccount, }) => {
|
|
43
|
+
// const authority = user.getUserAccount().authority;
|
|
44
|
+
// const associatedDepositTokenAddress =
|
|
45
|
+
// await getTokenAddressForDepositAndWithdraw(
|
|
46
|
+
// spotMarketConfig.mint,
|
|
47
|
+
// authority
|
|
48
|
+
// );
|
|
49
|
+
let finalDepositAmount = amount;
|
|
50
|
+
if (isMaxBorrowRepayment) {
|
|
51
|
+
// we over-estimate to ensure that there is no borrow dust left
|
|
52
|
+
// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate
|
|
53
|
+
finalDepositAmount = finalDepositAmount.scale(2, 1);
|
|
54
|
+
}
|
|
55
|
+
// we choose to not use createDepositIxs here because it doesn't have the initSwiftAccount logic
|
|
56
|
+
// const depositTxn = await driftClient.createDepositTxn(
|
|
57
|
+
// finalDepositAmount.val,
|
|
58
|
+
// spotMarketConfig.marketIndex,
|
|
59
|
+
// associatedDepositTokenAddress,
|
|
60
|
+
// user.getUserAccount().subAccountId,
|
|
61
|
+
// isMaxBorrowRepayment,
|
|
62
|
+
// txParams,
|
|
63
|
+
// initSwiftAccount
|
|
64
|
+
// );
|
|
65
|
+
const depositIxs = await (0, exports.createDepositIxs)({
|
|
66
|
+
driftClient,
|
|
67
|
+
user,
|
|
68
|
+
amount: finalDepositAmount,
|
|
69
|
+
spotMarketConfig,
|
|
70
|
+
isMaxBorrowRepayment,
|
|
71
|
+
});
|
|
72
|
+
const depositTxn = await driftClient.txHandler.buildTransaction({
|
|
73
|
+
instructions: depositIxs,
|
|
74
|
+
txVersion: 0,
|
|
75
|
+
connection: driftClient.connection,
|
|
76
|
+
preFlightCommitment: 'confirmed',
|
|
77
|
+
fetchAllMarketLookupTableAccounts: driftClient.fetchAllLookupTableAccounts.bind(driftClient),
|
|
78
|
+
});
|
|
79
|
+
return depositTxn;
|
|
80
|
+
};
|
|
81
|
+
exports.createDepositTxn = createDepositTxn;
|
|
82
|
+
//# sourceMappingURL=deposit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deposit.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/deposit.ts"],"names":[],"mappings":";;;AAYA,mDAA+E;AAU/E;;;;;;;;;;GAUG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,oBAAoB,GACG,EAAqC,EAAE;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC;IAClD,MAAM,6BAA6B,GAClC,MAAM,IAAA,4CAAoC,EACzC,gBAAgB,CAAC,IAAI,EACrB,SAAS,CACT,CAAC;IAEH,IAAI,kBAAkB,GAAG,MAAM,CAAC;IAEhC,IAAI,oBAAoB,EAAE,CAAC;QAC1B,+DAA+D;QAC/D,uEAAuE;QACvE,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,eAAe,CACnD,kBAAkB,CAAC,GAAG,EACtB,gBAAgB,CAAC,WAAW,EAC5B,6BAA6B,EAC7B,IAAI,CAAC,cAAc,EAAE,CAAC,YAAY,EAClC,oBAAoB,CACpB,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B;AAOF;;;;;;;;;;;;GAYG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EAAE,SAAS,EACnB,gBAAgB,EAAE,iBAAiB,GACX,EAA+C,EAAE;IACzE,qDAAqD;IACrD,wCAAwC;IACxC,+CAA+C;IAC/C,2BAA2B;IAC3B,cAAc;IACd,MAAM;IAEN,IAAI,kBAAkB,GAAG,MAAM,CAAC;IAEhC,IAAI,oBAAoB,EAAE,CAAC;QAC1B,+DAA+D;QAC/D,uEAAuE;QACvE,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,gGAAgG;IAChG,yDAAyD;IACzD,2BAA2B;IAC3B,iCAAiC;IACjC,kCAAkC;IAClC,uCAAuC;IACvC,yBAAyB;IACzB,aAAa;IACb,oBAAoB;IACpB,KAAK;IACL,MAAM,UAAU,GAAG,MAAM,IAAA,wBAAgB,EAAC;QACzC,WAAW;QACX,IAAI;QACJ,MAAM,EAAE,kBAAkB;QAC1B,gBAAgB;QAChB,oBAAoB;KACpB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAC/D,YAAY,EAAE,UAAU;QACxB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;KAC1D,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AApDW,QAAA,gBAAgB,oBAoD3B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\n\ninterface CreateDepositIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: Pick<SpotMarketConfig, 'mint' | 'marketIndex'>;\n\tisMaxBorrowRepayment?: boolean;\n}\n\n/**\n * Creates transaction instructions for depositing a spot token.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)\n *\n * @returns Promise resolving to an array of transaction instructions for the deposit\n */\nexport const createDepositIxs = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n}: CreateDepositIxParams): Promise<TransactionInstruction[]> => {\n\tconst authority = user.getUserAccount().authority;\n\tconst associatedDepositTokenAddress =\n\t\tawait getTokenAddressForDepositAndWithdraw(\n\t\t\tspotMarketConfig.mint,\n\t\t\tauthority\n\t\t);\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\tconst depositIxs = await driftClient.getDepositTxnIx(\n\t\tfinalDepositAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\tuser.getUserAccount().subAccountId,\n\t\tisMaxBorrowRepayment\n\t);\n\n\treturn depositIxs;\n};\n\ninterface CreateDepositTxnParams extends CreateDepositIxParams {\n\ttxParams?: TxParams;\n\tinitSwiftAccount?: boolean;\n}\n\n/**\n * Creates a complete transaction for depositing assets into a spot market.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)\n * @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)\n * @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createDepositTxn = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n\ttxParams: _txParams,\n\tinitSwiftAccount: _initSwiftAccount,\n}: CreateDepositTxnParams): Promise<Transaction | VersionedTransaction> => {\n\t// const authority = user.getUserAccount().authority;\n\t// const associatedDepositTokenAddress =\n\t// \tawait getTokenAddressForDepositAndWithdraw(\n\t// \t\tspotMarketConfig.mint,\n\t// \t\tauthority\n\t// \t);\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\t// we choose to not use createDepositIxs here because it doesn't have the initSwiftAccount logic\n\t// const depositTxn = await driftClient.createDepositTxn(\n\t// \tfinalDepositAmount.val,\n\t// \tspotMarketConfig.marketIndex,\n\t// \tassociatedDepositTokenAddress,\n\t// \tuser.getUserAccount().subAccountId,\n\t// \tisMaxBorrowRepayment,\n\t// \ttxParams,\n\t// \tinitSwiftAccount\n\t// );\n\tconst depositIxs = await createDepositIxs({\n\t\tdriftClient,\n\t\tuser,\n\t\tamount: finalDepositAmount,\n\t\tspotMarketConfig,\n\t\tisMaxBorrowRepayment,\n\t});\n\n\tconst depositTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: depositIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t});\n\n\treturn depositTxn;\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("./borrow"), exports);
|
|
18
|
+
__exportStar(require("./deposit"), exports);
|
|
19
|
+
__exportStar(require("./withdraw"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B","sourcesContent":["export * from './borrow';\nexport * from './deposit';\nexport * from './withdraw';\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BigNum, DriftClient, SpotMarketConfig, TxParams, User } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
interface CreateWithdrawIxParams {
|
|
4
|
+
driftClient: DriftClient;
|
|
5
|
+
user: User;
|
|
6
|
+
amount: BigNum;
|
|
7
|
+
spotMarketConfig: SpotMarketConfig;
|
|
8
|
+
isBorrow?: boolean;
|
|
9
|
+
isMax?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const createWithdrawIx: ({ driftClient, amount, spotMarketConfig, user, isBorrow, isMax, }: CreateWithdrawIxParams) => Promise<TransactionInstruction[]>;
|
|
12
|
+
interface CreateWithdrawTxnParams extends CreateWithdrawIxParams {
|
|
13
|
+
txParams?: TxParams;
|
|
14
|
+
}
|
|
15
|
+
export declare const createWithdrawTxn: ({ driftClient, amount, spotMarketConfig, user, isBorrow, isMax, txParams, }: CreateWithdrawTxnParams) => Promise<Transaction | VersionedTransaction>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWithdrawTxn = exports.createWithdrawIx = void 0;
|
|
4
|
+
const token_1 = require("../../../../utils/token");
|
|
5
|
+
const createWithdrawIx = async ({ driftClient, amount, spotMarketConfig, user, isBorrow, isMax, }) => {
|
|
6
|
+
const reduceOnly = !isBorrow;
|
|
7
|
+
let finalWithdrawAmount = amount;
|
|
8
|
+
if (isMax && reduceOnly) {
|
|
9
|
+
// we over-estimate to ensure that there is no borrow dust left
|
|
10
|
+
// since reduceOnly is true, it is safe to over-estimate
|
|
11
|
+
finalWithdrawAmount = finalWithdrawAmount.scale(2, 1);
|
|
12
|
+
}
|
|
13
|
+
const authority = user.getUserAccount().authority;
|
|
14
|
+
const associatedDepositTokenAddress = await (0, token_1.getTokenAddressForDepositAndWithdraw)(spotMarketConfig.mint, authority);
|
|
15
|
+
const withdrawIxs = await driftClient.getWithdrawalIxs(finalWithdrawAmount.val, spotMarketConfig.marketIndex, associatedDepositTokenAddress, reduceOnly, user.getUserAccount().subAccountId, undefined);
|
|
16
|
+
return withdrawIxs;
|
|
17
|
+
};
|
|
18
|
+
exports.createWithdrawIx = createWithdrawIx;
|
|
19
|
+
const createWithdrawTxn = async ({ driftClient, amount, spotMarketConfig, user, isBorrow, isMax, txParams, }) => {
|
|
20
|
+
const withdrawIxs = await (0, exports.createWithdrawIx)({
|
|
21
|
+
driftClient,
|
|
22
|
+
amount,
|
|
23
|
+
spotMarketConfig,
|
|
24
|
+
user,
|
|
25
|
+
isBorrow,
|
|
26
|
+
isMax,
|
|
27
|
+
});
|
|
28
|
+
const withdrawTxn = await driftClient.txHandler.buildTransaction({
|
|
29
|
+
instructions: withdrawIxs,
|
|
30
|
+
txVersion: 0,
|
|
31
|
+
connection: driftClient.connection,
|
|
32
|
+
preFlightCommitment: 'confirmed',
|
|
33
|
+
fetchAllMarketLookupTableAccounts: driftClient.fetchAllLookupTableAccounts.bind(driftClient),
|
|
34
|
+
txParams,
|
|
35
|
+
});
|
|
36
|
+
return withdrawTxn;
|
|
37
|
+
};
|
|
38
|
+
exports.createWithdrawTxn = createWithdrawTxn;
|
|
39
|
+
//# sourceMappingURL=withdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdraw.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/withdraw.ts"],"names":[],"mappings":";;;AAYA,mDAA+E;AAWxE,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,KAAK,GACmB,EAAqC,EAAE;IAC/D,MAAM,UAAU,GAAG,CAAC,QAAQ,CAAC;IAE7B,IAAI,mBAAmB,GAAG,MAAM,CAAC;IAEjC,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QACzB,+DAA+D;QAC/D,wDAAwD;QACxD,mBAAmB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC;IAClD,MAAM,6BAA6B,GAClC,MAAM,IAAA,4CAAoC,EACzC,gBAAgB,CAAC,IAAI,EACrB,SAAS,CACT,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,gBAAgB,CACrD,mBAAmB,CAAC,GAAG,EACvB,gBAAgB,CAAC,WAAW,EAC5B,6BAA6B,EAC7B,UAAU,EACV,IAAI,CAAC,cAAc,EAAE,CAAC,YAAY,EAClC,SAAS,CACT,CAAC;IAEF,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAnCW,QAAA,gBAAgB,oBAmC3B;AAMK,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACvC,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,QAAQ,GACiB,EAA+C,EAAE;IAC1E,MAAM,WAAW,GAAG,MAAM,IAAA,wBAAgB,EAAC;QAC1C,WAAW;QACX,MAAM;QACN,gBAAgB;QAChB,IAAI;QACJ,QAAQ;QACR,KAAK;KACL,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAChE,YAAY,EAAE,WAAW;QACzB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1D,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AA7BW,QAAA,iBAAiB,qBA6B5B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\n\ninterface CreateWithdrawIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: SpotMarketConfig;\n\tisBorrow?: boolean;\n\tisMax?: boolean;\n}\n\nexport const createWithdrawIx = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n}: CreateWithdrawIxParams): Promise<TransactionInstruction[]> => {\n\tconst reduceOnly = !isBorrow;\n\n\tlet finalWithdrawAmount = amount;\n\n\tif (isMax && reduceOnly) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since reduceOnly is true, it is safe to over-estimate\n\t\tfinalWithdrawAmount = finalWithdrawAmount.scale(2, 1);\n\t}\n\n\tconst authority = user.getUserAccount().authority;\n\tconst associatedDepositTokenAddress =\n\t\tawait getTokenAddressForDepositAndWithdraw(\n\t\t\tspotMarketConfig.mint,\n\t\t\tauthority\n\t\t);\n\n\tconst withdrawIxs = await driftClient.getWithdrawalIxs(\n\t\tfinalWithdrawAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\treduceOnly,\n\t\tuser.getUserAccount().subAccountId,\n\t\tundefined\n\t);\n\n\treturn withdrawIxs;\n};\n\ninterface CreateWithdrawTxnParams extends CreateWithdrawIxParams {\n\ttxParams?: TxParams;\n}\n\nexport const createWithdrawTxn = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n\ttxParams,\n}: CreateWithdrawTxnParams): Promise<Transaction | VersionedTransaction> => {\n\tconst withdrawIxs = await createWithdrawIx({\n\t\tdriftClient,\n\t\tamount,\n\t\tspotMarketConfig,\n\t\tuser,\n\t\tisBorrow,\n\t\tisMax,\n\t});\n\n\tconst withdrawTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: withdrawIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t\ttxParams,\n\t});\n\n\treturn withdrawTxn;\n};\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DriftClient, TxParams, User } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a transaction instruction to cancel multiple orders by their order IDs.
|
|
5
|
+
*
|
|
6
|
+
* @param driftClient - The Drift client instance.
|
|
7
|
+
* @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order
|
|
8
|
+
* @param user - The user client that owns the orders to be cancelled
|
|
9
|
+
*
|
|
10
|
+
* @returns Promise resolving to a TransactionInstruction that cancels the specified orders
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const instruction = await cancelOrderIxs(
|
|
15
|
+
* driftClient,
|
|
16
|
+
* [123, 456, 789], // Cancel orders with IDs 123, 456, and 789
|
|
17
|
+
* user
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const createCancelOrdersIx: (driftClient: DriftClient, orderIds: number[], user: User) => Promise<TransactionInstruction>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a transaction to cancel multiple orders by their IDs.
|
|
25
|
+
*
|
|
26
|
+
* @param driftClient - The Drift client instance.
|
|
27
|
+
* @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order
|
|
28
|
+
* @param user - The user client that owns the orders to be cancelled
|
|
29
|
+
* @param txParams - Optional transaction parameters for customizing the transaction
|
|
30
|
+
*
|
|
31
|
+
* @returns Promise resolving to a Transaction or VersionedTransaction ready for signing
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Cancel multiple orders
|
|
36
|
+
* const transaction = await cancelOrderTxn(
|
|
37
|
+
* driftClient,
|
|
38
|
+
* [123, 456], // Cancel orders with IDs 123 and 456
|
|
39
|
+
* user,
|
|
40
|
+
* { computeUnits: 200000 } // Optional transaction parameters
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* // Sign and send the transaction
|
|
44
|
+
* const signature = await wallet.sendTransaction(transaction, connection);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const createCancelOrdersTxn: (driftClient: DriftClient, user: User, orderIds: number[], txParams?: TxParams) => Promise<Transaction | VersionedTransaction>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCancelOrdersTxn = exports.createCancelOrdersIx = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a transaction instruction to cancel multiple orders by their order IDs.
|
|
6
|
+
*
|
|
7
|
+
* @param driftClient - The Drift client instance.
|
|
8
|
+
* @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order
|
|
9
|
+
* @param user - The user client that owns the orders to be cancelled
|
|
10
|
+
*
|
|
11
|
+
* @returns Promise resolving to a TransactionInstruction that cancels the specified orders
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const instruction = await cancelOrderIxs(
|
|
16
|
+
* driftClient,
|
|
17
|
+
* [123, 456, 789], // Cancel orders with IDs 123, 456, and 789
|
|
18
|
+
* user
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const createCancelOrdersIx = async (driftClient, orderIds, user) => {
|
|
24
|
+
return driftClient.getCancelOrdersByIdsIx(orderIds, undefined, user);
|
|
25
|
+
};
|
|
26
|
+
exports.createCancelOrdersIx = createCancelOrdersIx;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a transaction to cancel multiple orders by their IDs.
|
|
29
|
+
*
|
|
30
|
+
* @param driftClient - The Drift client instance.
|
|
31
|
+
* @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order
|
|
32
|
+
* @param user - The user client that owns the orders to be cancelled
|
|
33
|
+
* @param txParams - Optional transaction parameters for customizing the transaction
|
|
34
|
+
*
|
|
35
|
+
* @returns Promise resolving to a Transaction or VersionedTransaction ready for signing
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Cancel multiple orders
|
|
40
|
+
* const transaction = await cancelOrderTxn(
|
|
41
|
+
* driftClient,
|
|
42
|
+
* [123, 456], // Cancel orders with IDs 123 and 456
|
|
43
|
+
* user,
|
|
44
|
+
* { computeUnits: 200000 } // Optional transaction parameters
|
|
45
|
+
* );
|
|
46
|
+
*
|
|
47
|
+
* // Sign and send the transaction
|
|
48
|
+
* const signature = await wallet.sendTransaction(transaction, connection);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
const createCancelOrdersTxn = async (driftClient, user, orderIds, txParams) => {
|
|
52
|
+
return driftClient.buildTransaction(await (0, exports.createCancelOrdersIx)(driftClient, orderIds, user), txParams);
|
|
53
|
+
};
|
|
54
|
+
exports.createCancelOrdersTxn = createCancelOrdersTxn;
|
|
55
|
+
//# sourceMappingURL=cancelOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/cancelOrder.ts"],"names":[],"mappings":";;;AAOA;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,oBAAoB,GAAG,KAAK,EACxC,WAAwB,EACxB,QAAkB,EAClB,IAAU,EACwB,EAAE;IACpC,OAAO,WAAW,CAAC,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACtE,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACzC,WAAwB,EACxB,IAAU,EACV,QAAkB,EAClB,QAAmB,EAC2B,EAAE;IAChD,OAAO,WAAW,CAAC,gBAAgB,CAClC,MAAM,IAAA,4BAAoB,EAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,EACvD,QAAQ,CACR,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC","sourcesContent":["import { DriftClient, TxParams, User } from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\n/**\n * Creates a transaction instruction to cancel multiple orders by their order IDs.\n *\n * @param driftClient - The Drift client instance.\n * @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order\n * @param user - The user client that owns the orders to be cancelled\n *\n * @returns Promise resolving to a TransactionInstruction that cancels the specified orders\n *\n * @example\n * ```typescript\n * const instruction = await cancelOrderIxs(\n * driftClient,\n * [123, 456, 789], // Cancel orders with IDs 123, 456, and 789\n * user\n * );\n *\n * ```\n */\nexport const createCancelOrdersIx = async (\n\tdriftClient: DriftClient,\n\torderIds: number[],\n\tuser: User\n): Promise<TransactionInstruction> => {\n\treturn driftClient.getCancelOrdersByIdsIx(orderIds, undefined, user);\n};\n\n/**\n * Creates a transaction to cancel multiple orders by their IDs.\n *\n * @param driftClient - The Drift client instance.\n * @param orderIds - Array of order IDs to cancel. Each ID corresponds to a specific order\n * @param user - The user client that owns the orders to be cancelled\n * @param txParams - Optional transaction parameters for customizing the transaction\n *\n * @returns Promise resolving to a Transaction or VersionedTransaction ready for signing\n *\n * @example\n * ```typescript\n * // Cancel multiple orders\n * const transaction = await cancelOrderTxn(\n * driftClient,\n * [123, 456], // Cancel orders with IDs 123 and 456\n * user,\n * { computeUnits: 200000 } // Optional transaction parameters\n * );\n *\n * // Sign and send the transaction\n * const signature = await wallet.sendTransaction(transaction, connection);\n * ```\n */\nexport const createCancelOrdersTxn = async (\n\tdriftClient: DriftClient,\n\tuser: User,\n\torderIds: number[],\n\ttxParams?: TxParams\n): Promise<Transaction | VersionedTransaction> => {\n\treturn driftClient.buildTransaction(\n\t\tawait createCancelOrdersIx(driftClient, orderIds, user),\n\t\ttxParams\n\t);\n};\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BN, DriftClient, OrderTriggerCondition, PositionDirection, TxParams, User } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for editing an existing order
|
|
5
|
+
*/
|
|
6
|
+
interface EditOrderParams {
|
|
7
|
+
/** New direction for the order (long/short) */
|
|
8
|
+
newDirection?: PositionDirection;
|
|
9
|
+
/** New base amount for the order */
|
|
10
|
+
newBaseAmount?: BN;
|
|
11
|
+
/** New limit price for the order */
|
|
12
|
+
newLimitPrice?: BN;
|
|
13
|
+
/** New oracle price offset for oracle market/limit orders */
|
|
14
|
+
newOraclePriceOffset?: number;
|
|
15
|
+
/** New trigger price for conditional orders */
|
|
16
|
+
newTriggerPrice?: BN;
|
|
17
|
+
/** New trigger condition for conditional orders */
|
|
18
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
19
|
+
/** Duration of the auction in slots */
|
|
20
|
+
auctionDuration?: number;
|
|
21
|
+
/** Starting price for the auction */
|
|
22
|
+
auctionStartPrice?: BN;
|
|
23
|
+
/** Ending price for the auction */
|
|
24
|
+
auctionEndPrice?: BN;
|
|
25
|
+
/** Whether the order should only reduce position size */
|
|
26
|
+
reduceOnly?: boolean;
|
|
27
|
+
/** Whether the order should only be posted (maker only) */
|
|
28
|
+
postOnly?: boolean;
|
|
29
|
+
/** Bit flags for additional order configuration */
|
|
30
|
+
bitFlags?: number;
|
|
31
|
+
/** Maximum timestamp for order validity */
|
|
32
|
+
maxTs?: BN;
|
|
33
|
+
/** Order policy configuration */
|
|
34
|
+
policy?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a transaction instruction to edit an existing order
|
|
38
|
+
* @param driftClient - The DriftClient instance
|
|
39
|
+
* @param userPublicKey - The public key of the user who owns the order
|
|
40
|
+
* @param orderId - The ID of the order to edit
|
|
41
|
+
* @param editOrderParams - Parameters containing the new order values
|
|
42
|
+
* @returns Promise that resolves to a TransactionInstruction
|
|
43
|
+
*/
|
|
44
|
+
export declare const createEditOrderIx: (driftClient: DriftClient, user: User, orderId: number, editOrderParams: EditOrderParams) => Promise<TransactionInstruction>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a complete transaction to edit an existing order
|
|
47
|
+
* @param driftClient - The DriftClient instance
|
|
48
|
+
* @param userPublicKey - The public key of the user who owns the order
|
|
49
|
+
* @param orderId - The ID of the order to edit
|
|
50
|
+
* @param editOrderParams - Parameters containing the new order values
|
|
51
|
+
* @param txParams - Optional transaction parameters (compute units, priority fees, etc.)
|
|
52
|
+
* @returns Promise that resolves to a Transaction or VersionedTransaction
|
|
53
|
+
*/
|
|
54
|
+
export declare const createEditOrderTxn: (driftClient: DriftClient, user: User, orderId: number, editOrderParams: EditOrderParams, txParams?: TxParams) => Promise<Transaction | VersionedTransaction>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEditOrderTxn = exports.createEditOrderIx = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a transaction instruction to edit an existing order
|
|
6
|
+
* @param driftClient - The DriftClient instance
|
|
7
|
+
* @param userPublicKey - The public key of the user who owns the order
|
|
8
|
+
* @param orderId - The ID of the order to edit
|
|
9
|
+
* @param editOrderParams - Parameters containing the new order values
|
|
10
|
+
* @returns Promise that resolves to a TransactionInstruction
|
|
11
|
+
*/
|
|
12
|
+
const createEditOrderIx = async (driftClient, user, orderId, editOrderParams) => {
|
|
13
|
+
const userPublicKey = user.getUserAccountPublicKey();
|
|
14
|
+
const _currentOrder = user.getOrderByUserOrderId(orderId);
|
|
15
|
+
// TODO: handle auction params
|
|
16
|
+
return driftClient.getModifyOrderIx({
|
|
17
|
+
orderId,
|
|
18
|
+
...editOrderParams,
|
|
19
|
+
}, undefined, userPublicKey);
|
|
20
|
+
};
|
|
21
|
+
exports.createEditOrderIx = createEditOrderIx;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a complete transaction to edit an existing order
|
|
24
|
+
* @param driftClient - The DriftClient instance
|
|
25
|
+
* @param userPublicKey - The public key of the user who owns the order
|
|
26
|
+
* @param orderId - The ID of the order to edit
|
|
27
|
+
* @param editOrderParams - Parameters containing the new order values
|
|
28
|
+
* @param txParams - Optional transaction parameters (compute units, priority fees, etc.)
|
|
29
|
+
* @returns Promise that resolves to a Transaction or VersionedTransaction
|
|
30
|
+
*/
|
|
31
|
+
const createEditOrderTxn = async (driftClient, user, orderId, editOrderParams, txParams) => {
|
|
32
|
+
return driftClient.buildTransaction(await (0, exports.createEditOrderIx)(driftClient, user, orderId, editOrderParams), txParams);
|
|
33
|
+
};
|
|
34
|
+
exports.createEditOrderTxn = createEditOrderTxn;
|
|
35
|
+
//# sourceMappingURL=editOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editOrder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/editOrder.ts"],"names":[],"mappings":";;;AAgDA;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACrC,WAAwB,EACxB,IAAU,EACV,OAAe,EACf,eAAgC,EACE,EAAE;IACpC,MAAM,aAAa,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACrD,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE1D,8BAA8B;IAE9B,OAAO,WAAW,CAAC,gBAAgB,CAClC;QACC,OAAO;QACP,GAAG,eAAe;KAClB,EACD,SAAS,EACT,aAAa,CACb,CAAC;AACH,CAAC,CAAC;AAnBW,QAAA,iBAAiB,qBAmB5B;AAEF;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG,KAAK,EACtC,WAAwB,EACxB,IAAU,EACV,OAAe,EACf,eAAgC,EAChC,QAAmB,EAC2B,EAAE;IAChD,OAAO,WAAW,CAAC,gBAAgB,CAClC,MAAM,IAAA,yBAAiB,EAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,QAAQ,CACR,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B","sourcesContent":["import {\n\tBN,\n\tDriftClient,\n\tOrderTriggerCondition,\n\tPositionDirection,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\n/**\n * Parameters for editing an existing order\n */\ninterface EditOrderParams {\n\t/** New direction for the order (long/short) */\n\tnewDirection?: PositionDirection;\n\t/** New base amount for the order */\n\tnewBaseAmount?: BN;\n\t/** New limit price for the order */\n\tnewLimitPrice?: BN;\n\t/** New oracle price offset for oracle market/limit orders */\n\tnewOraclePriceOffset?: number;\n\t/** New trigger price for conditional orders */\n\tnewTriggerPrice?: BN;\n\t/** New trigger condition for conditional orders */\n\tnewTriggerCondition?: OrderTriggerCondition;\n\t/** Duration of the auction in slots */\n\tauctionDuration?: number;\n\t/** Starting price for the auction */\n\tauctionStartPrice?: BN;\n\t/** Ending price for the auction */\n\tauctionEndPrice?: BN;\n\t/** Whether the order should only reduce position size */\n\treduceOnly?: boolean;\n\t/** Whether the order should only be posted (maker only) */\n\tpostOnly?: boolean;\n\t/** Bit flags for additional order configuration */\n\tbitFlags?: number;\n\t/** Maximum timestamp for order validity */\n\tmaxTs?: BN;\n\t/** Order policy configuration */\n\tpolicy?: number;\n}\n\n/**\n * Creates a transaction instruction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @returns Promise that resolves to a TransactionInstruction\n */\nexport const createEditOrderIx = async (\n\tdriftClient: DriftClient,\n\tuser: User,\n\torderId: number,\n\teditOrderParams: EditOrderParams\n): Promise<TransactionInstruction> => {\n\tconst userPublicKey = user.getUserAccountPublicKey();\n\tconst _currentOrder = user.getOrderByUserOrderId(orderId);\n\n\t// TODO: handle auction params\n\n\treturn driftClient.getModifyOrderIx(\n\t\t{\n\t\t\torderId,\n\t\t\t...editOrderParams,\n\t\t},\n\t\tundefined,\n\t\tuserPublicKey\n\t);\n};\n\n/**\n * Creates a complete transaction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n * @returns Promise that resolves to a Transaction or VersionedTransaction\n */\nexport const createEditOrderTxn = async (\n\tdriftClient: DriftClient,\n\tuser: User,\n\torderId: number,\n\teditOrderParams: EditOrderParams,\n\ttxParams?: TxParams\n): Promise<Transaction | VersionedTransaction> => {\n\treturn driftClient.buildTransaction(\n\t\tawait createEditOrderIx(driftClient, user, orderId, editOrderParams),\n\t\ttxParams\n\t);\n};\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./openPerpOrder"), exports);
|
|
18
|
+
__exportStar(require("./cancelOrder"), exports);
|
|
19
|
+
__exportStar(require("./editOrder"), exports);
|
|
20
|
+
__exportStar(require("./swap"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB","sourcesContent":["export * from './openPerpOrder';\nexport * from './cancelOrder';\nexport * from './editOrder';\nexport * from './swap';\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("./openPerpMarketOrder"), exports);
|
|
18
|
+
__exportStar(require("./openPerpNonMarketOrder"), exports);
|
|
19
|
+
__exportStar(require("./openSwiftOrder"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/drift/base/actions/trade/openPerpOrder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,2DAAyC;AACzC,mDAAiC","sourcesContent":["export * from './openPerpMarketOrder';\nexport * from './openPerpNonMarketOrder';\nexport * from './openSwiftOrder';\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { DriftClient, User, BN, PositionDirection, MarketType } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { OptionalTriggerOrderParams, SwiftOrderOptions, SwiftOrderResult } from '../openSwiftOrder';
|
|
4
|
+
export interface AuctionParamsRequestOptions {
|
|
5
|
+
maxLeverageSelected?: boolean;
|
|
6
|
+
maxLeverageOrderSize?: BN;
|
|
7
|
+
reduceOnly?: boolean;
|
|
8
|
+
auctionDuration?: number;
|
|
9
|
+
auctionStartPriceOffset?: number;
|
|
10
|
+
auctionEndPriceOffset?: number;
|
|
11
|
+
auctionStartPriceOffsetFrom?: string;
|
|
12
|
+
auctionEndPriceOffsetFrom?: string;
|
|
13
|
+
slippageTolerance?: number | 'dynamic';
|
|
14
|
+
auctionPriceCaps?: {
|
|
15
|
+
min: BN;
|
|
16
|
+
max: BN;
|
|
17
|
+
};
|
|
18
|
+
isOracleOrder?: boolean;
|
|
19
|
+
additionalEndPriceBuffer?: BN;
|
|
20
|
+
forceUpToSlippage?: boolean;
|
|
21
|
+
orderType?: 'market' | 'oracle';
|
|
22
|
+
}
|
|
23
|
+
export type OpenPerpMarketOrderParams<T extends boolean = boolean> = {
|
|
24
|
+
driftClient: DriftClient;
|
|
25
|
+
user: User;
|
|
26
|
+
assetType: 'base' | 'quote';
|
|
27
|
+
marketIndex: number;
|
|
28
|
+
direction: PositionDirection;
|
|
29
|
+
amount: BN;
|
|
30
|
+
auctionParamsOptions?: AuctionParamsRequestOptions;
|
|
31
|
+
dlobServerHttpUrl: string;
|
|
32
|
+
bracketOrders?: {
|
|
33
|
+
takeProfit?: OptionalTriggerOrderParams;
|
|
34
|
+
stopLoss?: OptionalTriggerOrderParams;
|
|
35
|
+
};
|
|
36
|
+
marketType?: MarketType;
|
|
37
|
+
useSwift: T;
|
|
38
|
+
} & (T extends true ? {
|
|
39
|
+
swiftOptions: SwiftOrderOptions;
|
|
40
|
+
} : {
|
|
41
|
+
swiftOptions?: never;
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Creates transaction instructions for opening a perp market order.
|
|
45
|
+
* If swiftOptions is provided, it will create a Swift (signed message) order instead.
|
|
46
|
+
*
|
|
47
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
48
|
+
* @param user - The user account that will place the order
|
|
49
|
+
* @param assetType - Whether the amount is in base or quote units
|
|
50
|
+
* @param marketIndex - The perp market index to trade
|
|
51
|
+
* @param direction - The direction of the trade (long/short)
|
|
52
|
+
* @param amount - The amount to trade
|
|
53
|
+
* @param dlobServerHttpUrl - Server URL for the auction params endpoint
|
|
54
|
+
* @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration
|
|
55
|
+
* @param useSwift - Whether to use Swift (signed message) orders instead of regular transactions
|
|
56
|
+
* @param swiftOptions - Options for Swift (signed message) orders. Required if useSwift is true
|
|
57
|
+
*
|
|
58
|
+
* @returns Promise resolving to an array of transaction instructions for regular orders, or empty array for Swift orders
|
|
59
|
+
*/
|
|
60
|
+
export declare const createOpenPerpMarketOrderIx: ({ driftClient, user, assetType, marketIndex, direction, amount, dlobServerHttpUrl, auctionParamsOptions, useSwift, swiftOptions, }: OpenPerpMarketOrderParams) => Promise<TransactionInstruction[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a complete transaction for opening a perp market order.
|
|
63
|
+
*
|
|
64
|
+
* @param driftClient - The Drift client instance for interacting with the protocol
|
|
65
|
+
* @param user - The user account that will place the order
|
|
66
|
+
* @param marketIndex - The perp market index to trade
|
|
67
|
+
* @param direction - The direction of the trade (long/short)
|
|
68
|
+
* @param amount - The amount to trade
|
|
69
|
+
* @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration
|
|
70
|
+
* @param dlobServerHttpUrl - Server URL for the auction params endpoint
|
|
71
|
+
*
|
|
72
|
+
* @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)
|
|
73
|
+
*/
|
|
74
|
+
export declare const createOpenPerpMarketOrderTxn: <T extends boolean>({ driftClient, user, assetType, marketIndex, direction, amount, dlobServerHttpUrl, auctionParamsOptions, bracketOrders, useSwift, swiftOptions, }: OpenPerpMarketOrderParams<T>) => Promise<T extends true ? SwiftOrderResult : Transaction | VersionedTransaction>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a Swift (signed message) order directly.
|
|
77
|
+
* This is a convenience function for when you only want to create Swift orders.
|
|
78
|
+
*
|
|
79
|
+
* @param params - All the parameters needed for creating a Swift order
|
|
80
|
+
* @returns Promise resolving to SwiftOrderResult with observable and order UUID
|
|
81
|
+
*/
|
|
82
|
+
export declare const createSwiftPerpMarketOrder: (params: Omit<OpenPerpMarketOrderParams, 'useSwift'> & {
|
|
83
|
+
swiftOptions: SwiftOrderOptions;
|
|
84
|
+
}) => Promise<SwiftOrderResult>;
|