@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,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAuctionParamsResponse = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const FIELD_MAPPING = {
|
|
7
|
+
// Enums (string -> enum object)
|
|
8
|
+
orderType: { type: 'enum' },
|
|
9
|
+
marketType: { type: 'enum' },
|
|
10
|
+
direction: { type: 'enum' },
|
|
11
|
+
postOnly: { type: 'enum' },
|
|
12
|
+
triggerCondition: { type: 'enum' },
|
|
13
|
+
// Numbers (keep as numbers)
|
|
14
|
+
userOrderId: { type: 'number' },
|
|
15
|
+
marketIndex: { type: 'number' },
|
|
16
|
+
auctionDuration: { type: 'number' },
|
|
17
|
+
// Booleans
|
|
18
|
+
reduceOnly: { type: 'boolean' },
|
|
19
|
+
immediateOrCancel: { type: 'boolean' },
|
|
20
|
+
// BNs (string/number -> BN)
|
|
21
|
+
baseAssetAmount: { type: 'bn' },
|
|
22
|
+
auctionStartPrice: { type: 'bn' },
|
|
23
|
+
auctionEndPrice: { type: 'bn' },
|
|
24
|
+
// Nullable BNs
|
|
25
|
+
oraclePriceOffset: { type: 'bn_nullable' },
|
|
26
|
+
triggerPrice: { type: 'bn_nullable' },
|
|
27
|
+
maxTs: { type: 'bn_nullable' },
|
|
28
|
+
};
|
|
29
|
+
// Type conversion functions
|
|
30
|
+
const convertValue = (value, type) => {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'enum':
|
|
33
|
+
try {
|
|
34
|
+
// Convert string values to proper SDK enums
|
|
35
|
+
let enumResult;
|
|
36
|
+
switch (value) {
|
|
37
|
+
case 'oracle':
|
|
38
|
+
enumResult = sdk_1.OrderType.ORACLE;
|
|
39
|
+
break;
|
|
40
|
+
case 'market':
|
|
41
|
+
enumResult = sdk_1.OrderType.MARKET;
|
|
42
|
+
break;
|
|
43
|
+
case 'limit':
|
|
44
|
+
enumResult = sdk_1.OrderType.LIMIT;
|
|
45
|
+
break;
|
|
46
|
+
case 'trigger_market':
|
|
47
|
+
enumResult = sdk_1.OrderType.TRIGGER_MARKET;
|
|
48
|
+
break;
|
|
49
|
+
case 'trigger_limit':
|
|
50
|
+
enumResult = sdk_1.OrderType.TRIGGER_LIMIT;
|
|
51
|
+
break;
|
|
52
|
+
case 'perp':
|
|
53
|
+
enumResult = sdk_1.MarketType.PERP;
|
|
54
|
+
break;
|
|
55
|
+
case 'spot':
|
|
56
|
+
enumResult = sdk_1.MarketType.SPOT;
|
|
57
|
+
break;
|
|
58
|
+
case 'long':
|
|
59
|
+
enumResult = sdk_1.PositionDirection.LONG;
|
|
60
|
+
break;
|
|
61
|
+
case 'short':
|
|
62
|
+
enumResult = sdk_1.PositionDirection.SHORT;
|
|
63
|
+
break;
|
|
64
|
+
case 'none':
|
|
65
|
+
enumResult = sdk_1.PostOnlyParams.NONE;
|
|
66
|
+
break;
|
|
67
|
+
case 'must_post_only':
|
|
68
|
+
enumResult = sdk_1.PostOnlyParams.MUST_POST_ONLY;
|
|
69
|
+
break;
|
|
70
|
+
case 'try_post_only':
|
|
71
|
+
enumResult = sdk_1.PostOnlyParams.TRY_POST_ONLY;
|
|
72
|
+
break;
|
|
73
|
+
case 'above':
|
|
74
|
+
enumResult = sdk_1.OrderTriggerCondition.ABOVE;
|
|
75
|
+
break;
|
|
76
|
+
case 'below':
|
|
77
|
+
enumResult = sdk_1.OrderTriggerCondition.BELOW;
|
|
78
|
+
break;
|
|
79
|
+
case 'triggered_above':
|
|
80
|
+
enumResult = sdk_1.OrderTriggerCondition.TRIGGERED_ABOVE;
|
|
81
|
+
break;
|
|
82
|
+
case 'triggered_below':
|
|
83
|
+
enumResult = sdk_1.OrderTriggerCondition.TRIGGERED_BELOW;
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
console.warn(`⚠️ [Converter] Unknown enum value: ${value}, using ENUM_UTILS.toObj as fallback`);
|
|
87
|
+
enumResult = utils_1.ENUM_UTILS.toObj(value);
|
|
88
|
+
}
|
|
89
|
+
return enumResult;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error(`❌ [Converter] Enum conversion failed for ${value}:`, error);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
case 'bn':
|
|
96
|
+
if (value === null || value === undefined) {
|
|
97
|
+
// Server returned null for a required BN field, this should cause fallback to client-side calculation
|
|
98
|
+
throw new Error(`Server returned ${value === null ? 'null' : 'undefined'} for required BN field, expected non-null value`);
|
|
99
|
+
}
|
|
100
|
+
return new sdk_1.BN(value.toString());
|
|
101
|
+
case 'bn_nullable':
|
|
102
|
+
return value === null || value === undefined
|
|
103
|
+
? null
|
|
104
|
+
: new sdk_1.BN(value.toString());
|
|
105
|
+
case 'number':
|
|
106
|
+
return value;
|
|
107
|
+
case 'boolean':
|
|
108
|
+
return value;
|
|
109
|
+
default:
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Maps the server response from getOrderParams back to proper client-side types
|
|
115
|
+
*/
|
|
116
|
+
function mapAuctionParamsResponse(serverResponse) {
|
|
117
|
+
var _a;
|
|
118
|
+
const mapped = {};
|
|
119
|
+
// Extract the actual params from the nested structure
|
|
120
|
+
const params = (_a = serverResponse.data) === null || _a === void 0 ? void 0 : _a.params;
|
|
121
|
+
if (!params) {
|
|
122
|
+
throw new Error('Invalid server response: missing data.params');
|
|
123
|
+
}
|
|
124
|
+
// Process each field based on its configuration
|
|
125
|
+
Object.entries(FIELD_MAPPING).forEach(([fieldName, config]) => {
|
|
126
|
+
const serverValue = params[fieldName];
|
|
127
|
+
if (serverValue !== undefined) {
|
|
128
|
+
try {
|
|
129
|
+
mapped[fieldName] = convertValue(serverValue, config.type);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error(`🔴 [Mapper] Field conversion error:`, {
|
|
133
|
+
fieldName,
|
|
134
|
+
serverValue,
|
|
135
|
+
expectedType: config.type,
|
|
136
|
+
actualType: typeof serverValue,
|
|
137
|
+
isNull: serverValue === null,
|
|
138
|
+
isUndefined: serverValue === undefined,
|
|
139
|
+
fullServerResponse: serverResponse,
|
|
140
|
+
});
|
|
141
|
+
throw new Error(`Failed to convert field '${fieldName}' (value: ${serverValue}, type: ${config.type}): ${error instanceof Error ? error.message : error}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return mapped;
|
|
146
|
+
}
|
|
147
|
+
exports.mapAuctionParamsResponse = mapAuctionParamsResponse;
|
|
148
|
+
//# sourceMappingURL=auctionParamsResponseMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auctionParamsResponseMapper.js","sourceRoot":"","sources":["../../../src/drift/utils/auctionParamsResponseMapper.ts"],"names":[],"mappings":";;;AAAA,yCAOyB;AACzB,uCAAyC;AA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CAAC,SAAsC,CAAC,CAAC;QAEnE,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACH,MAAc,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YACrE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE;oBACpD,SAAS;oBACT,WAAW;oBACX,YAAY,EAAE,MAAM,CAAC,IAAI;oBACzB,UAAU,EAAE,OAAO,WAAW;oBAC9B,MAAM,EAAE,WAAW,KAAK,IAAI;oBAC5B,WAAW,EAAE,WAAW,KAAK,SAAS;oBACtC,kBAAkB,EAAE,cAAc;iBAClC,CAAC,CAAC;gBACH,MAAM,IAAI,KAAK,CACd,4BAA4B,SAAS,aAAa,WAAW,WAC5D,MAAM,CAAC,IACR,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CACtD,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,MAA6B,CAAC;AACtC,CAAC;AAtCD,4DAsCC","sourcesContent":["import {\n\tBN,\n\tOrderType,\n\tMarketType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tOrderTriggerCondition,\n} from '@drift-labs/sdk';\nimport { ENUM_UTILS } from '../../utils';\n\n// TODO: remove response mapper from ui and use this one\nexport interface ServerAuctionParamsResponse {\n\tdata: {\n\t\tparams: {\n\t\t\torderType?: string;\n\t\t\tmarketType?: string;\n\t\t\tuserOrderId?: number;\n\t\t\tdirection?: string;\n\t\t\tbaseAssetAmount?: string | number;\n\t\t\tmarketIndex?: number;\n\t\t\treduceOnly?: boolean;\n\t\t\tpostOnly?: string;\n\t\t\timmediateOrCancel?: boolean;\n\t\t\ttriggerPrice?: string | number | null;\n\t\t\ttriggerCondition?: string;\n\t\t\toraclePriceOffset?: string | number;\n\t\t\tauctionDuration?: number;\n\t\t\tmaxTs?: string | number | null;\n\t\t\tauctionStartPrice?: string | number;\n\t\t\tauctionEndPrice?: string | number;\n\t\t};\n\t\t// Additional fields like entryPrice, bestPrice, etc. are ignored for now\n\t};\n}\n\nexport interface MappedAuctionParams {\n\torderType: OrderType;\n\tmarketType: MarketType;\n\tuserOrderId?: number;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\tmarketIndex: number;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\timmediateOrCancel?: boolean;\n\ttriggerPrice?: BN | null;\n\ttriggerCondition?: OrderTriggerCondition;\n\toraclePriceOffset?: BN;\n\tauctionDuration: number | undefined;\n\tmaxTs?: BN | null;\n\tauctionStartPrice: BN | undefined;\n\tauctionEndPrice: BN | undefined;\n}\n\n// Field mapping configuration\ntype FieldType = 'enum' | 'bn' | 'number' | 'boolean' | 'bn_nullable';\n\ninterface FieldConfig {\n\ttype: FieldType;\n}\n\n// Define the type for the actual params object\ninterface ServerAuctionParams {\n\torderType?: string;\n\tmarketType?: string;\n\tuserOrderId?: number;\n\tdirection?: string;\n\tbaseAssetAmount?: string | number;\n\tmarketIndex?: number;\n\treduceOnly?: boolean;\n\tpostOnly?: string;\n\timmediateOrCancel?: boolean;\n\ttriggerPrice?: string | number | null;\n\ttriggerCondition?: string;\n\toraclePriceOffset?: string | number;\n\tauctionDuration?: number;\n\tmaxTs?: string | number | null;\n\tauctionStartPrice?: string | number;\n\tauctionEndPrice?: string | number;\n}\n\nconst FIELD_MAPPING: Record<keyof ServerAuctionParams, FieldConfig> = {\n\t// Enums (string -> enum object)\n\torderType: { type: 'enum' },\n\tmarketType: { type: 'enum' },\n\tdirection: { type: 'enum' },\n\tpostOnly: { type: 'enum' },\n\ttriggerCondition: { type: 'enum' },\n\n\t// Numbers (keep as numbers)\n\tuserOrderId: { type: 'number' },\n\tmarketIndex: { type: 'number' },\n\tauctionDuration: { type: 'number' },\n\n\t// Booleans\n\treduceOnly: { type: 'boolean' },\n\timmediateOrCancel: { type: 'boolean' },\n\n\t// BNs (string/number -> BN)\n\tbaseAssetAmount: { type: 'bn' },\n\tauctionStartPrice: { type: 'bn' },\n\tauctionEndPrice: { type: 'bn' },\n\n\t// Nullable BNs\n\toraclePriceOffset: { type: 'bn_nullable' },\n\ttriggerPrice: { type: 'bn_nullable' },\n\tmaxTs: { type: 'bn_nullable' },\n};\n\n// Type conversion functions\nconst convertValue = (value: any, type: FieldType): any => {\n\tswitch (type) {\n\t\tcase 'enum':\n\t\t\ttry {\n\t\t\t\t// Convert string values to proper SDK enums\n\t\t\t\tlet enumResult;\n\t\t\t\tswitch (value) {\n\t\t\t\t\tcase 'oracle':\n\t\t\t\t\t\tenumResult = OrderType.ORACLE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'market':\n\t\t\t\t\t\tenumResult = OrderType.MARKET;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'limit':\n\t\t\t\t\t\tenumResult = OrderType.LIMIT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'trigger_market':\n\t\t\t\t\t\tenumResult = OrderType.TRIGGER_MARKET;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'trigger_limit':\n\t\t\t\t\t\tenumResult = OrderType.TRIGGER_LIMIT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'perp':\n\t\t\t\t\t\tenumResult = MarketType.PERP;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'spot':\n\t\t\t\t\t\tenumResult = MarketType.SPOT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'long':\n\t\t\t\t\t\tenumResult = PositionDirection.LONG;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'short':\n\t\t\t\t\t\tenumResult = PositionDirection.SHORT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'none':\n\t\t\t\t\t\tenumResult = PostOnlyParams.NONE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'must_post_only':\n\t\t\t\t\t\tenumResult = PostOnlyParams.MUST_POST_ONLY;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'try_post_only':\n\t\t\t\t\t\tenumResult = PostOnlyParams.TRY_POST_ONLY;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'above':\n\t\t\t\t\t\tenumResult = OrderTriggerCondition.ABOVE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'below':\n\t\t\t\t\t\tenumResult = OrderTriggerCondition.BELOW;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'triggered_above':\n\t\t\t\t\t\tenumResult = OrderTriggerCondition.TRIGGERED_ABOVE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'triggered_below':\n\t\t\t\t\t\tenumResult = OrderTriggerCondition.TRIGGERED_BELOW;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`⚠️ [Converter] Unknown enum value: ${value}, using ENUM_UTILS.toObj as fallback`\n\t\t\t\t\t\t);\n\t\t\t\t\t\tenumResult = ENUM_UTILS.toObj(value);\n\t\t\t\t}\n\t\t\t\treturn enumResult;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`❌ [Converter] Enum conversion failed for ${value}:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\tcase 'bn':\n\t\t\tif (value === null || value === undefined) {\n\t\t\t\t// Server returned null for a required BN field, this should cause fallback to client-side calculation\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Server returned ${\n\t\t\t\t\t\tvalue === null ? 'null' : 'undefined'\n\t\t\t\t\t} for required BN field, expected non-null value`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn new BN(value.toString());\n\t\tcase 'bn_nullable':\n\t\t\treturn value === null || value === undefined\n\t\t\t\t? null\n\t\t\t\t: new BN(value.toString());\n\t\tcase 'number':\n\t\t\treturn value;\n\t\tcase 'boolean':\n\t\t\treturn value;\n\t\tdefault:\n\t\t\treturn value;\n\t}\n};\n\n/**\n * Maps the server response from getOrderParams back to proper client-side types\n */\nexport function mapAuctionParamsResponse(\n\tserverResponse: ServerAuctionParamsResponse\n): MappedAuctionParams {\n\tconst mapped: Partial<MappedAuctionParams> = {};\n\n\t// Extract the actual params from the nested structure\n\tconst params = serverResponse.data?.params;\n\tif (!params) {\n\t\tthrow new Error('Invalid server response: missing data.params');\n\t}\n\n\t// Process each field based on its configuration\n\tObject.entries(FIELD_MAPPING).forEach(([fieldName, config]) => {\n\t\tconst serverValue = params[fieldName as keyof ServerAuctionParams];\n\n\t\tif (serverValue !== undefined) {\n\t\t\ttry {\n\t\t\t\t(mapped as any)[fieldName] = convertValue(serverValue, config.type);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`🔴 [Mapper] Field conversion error:`, {\n\t\t\t\t\tfieldName,\n\t\t\t\t\tserverValue,\n\t\t\t\t\texpectedType: config.type,\n\t\t\t\t\tactualType: typeof serverValue,\n\t\t\t\t\tisNull: serverValue === null,\n\t\t\t\t\tisUndefined: serverValue === undefined,\n\t\t\t\t\tfullServerResponse: serverResponse,\n\t\t\t\t});\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to convert field '${fieldName}' (value: ${serverValue}, type: ${\n\t\t\t\t\t\tconfig.type\n\t\t\t\t\t}): ${error instanceof Error ? error.message : error}`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t});\n\n\treturn mapped as MappedAuctionParams;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFundingRate = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const getFundingRate = (rate, oracleTwap) => {
|
|
6
|
+
return (sdk_1.BigNum.from(rate.mul(sdk_1.PRICE_PRECISION.mul(new sdk_1.BN(100))).div(oracleTwap), sdk_1.PRICE_PRECISION_EXP).toNum() / sdk_1.FUNDING_RATE_BUFFER_PRECISION.toNumber());
|
|
7
|
+
};
|
|
8
|
+
exports.getFundingRate = getFundingRate;
|
|
9
|
+
//# sourceMappingURL=funding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../../../src/drift/utils/funding.ts"],"names":[],"mappings":";;;AAAA,yCAMyB;AAElB,MAAM,cAAc,GAAG,CAAC,IAAQ,EAAE,UAAc,EAAU,EAAE;IAClE,OAAO,CACN,YAAM,CAAC,IAAI,CACV,IAAI,CAAC,GAAG,CAAC,qBAAe,CAAC,GAAG,CAAC,IAAI,QAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,EAC1D,yBAAmB,CACnB,CAAC,KAAK,EAAE,GAAG,mCAA6B,CAAC,QAAQ,EAAE,CACpD,CAAC;AACH,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB","sourcesContent":["import {\n\tBigNum,\n\tBN,\n\tPRICE_PRECISION,\n\tPRICE_PRECISION_EXP,\n\tFUNDING_RATE_BUFFER_PRECISION,\n} from '@drift-labs/sdk';\n\nexport const getFundingRate = (rate: BN, oracleTwap: BN): number => {\n\treturn (\n\t\tBigNum.from(\n\t\t\trate.mul(PRICE_PRECISION.mul(new BN(100))).div(oracleTwap),\n\t\t\tPRICE_PRECISION_EXP\n\t\t).toNum() / FUNDING_RATE_BUFFER_PRECISION.toNumber()\n\t);\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
exports.resolveBaseAssetAmount = exports.convertToBaseAssetAmount = void 0;
|
|
18
|
+
__exportStar(require("./auctionParamsResponseMapper"), exports);
|
|
19
|
+
__exportStar(require("./orderParams"), exports);
|
|
20
|
+
var orderParams_1 = require("./orderParams");
|
|
21
|
+
Object.defineProperty(exports, "convertToBaseAssetAmount", { enumerable: true, get: function () { return orderParams_1.convertToBaseAssetAmount; } });
|
|
22
|
+
Object.defineProperty(exports, "resolveBaseAssetAmount", { enumerable: true, get: function () { return orderParams_1.resolveBaseAssetAmount; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/drift/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,gDAA8B;AAC9B,6CAGuB;AAFtB,uHAAA,wBAAwB,OAAA;AACxB,qHAAA,sBAAsB,OAAA","sourcesContent":["export * from './auctionParamsResponseMapper';\nexport * from './orderParams';\nexport {\n\tconvertToBaseAssetAmount,\n\tresolveBaseAssetAmount,\n} from './orderParams';\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BN, MarketType, PositionDirection, PostOnlyParams, OptionalOrderParams } from '@drift-labs/sdk';
|
|
2
|
+
import { OptionalTriggerOrderParams } from '../base/actions/trade/openPerpOrder/openSwiftOrder';
|
|
3
|
+
/**
|
|
4
|
+
* Converts amount and assetType to base asset amount
|
|
5
|
+
* @param amount - The amount to convert
|
|
6
|
+
* @param assetType - 'base' or 'quote'
|
|
7
|
+
* @param limitPrice - Required when assetType is 'quote' for conversion
|
|
8
|
+
* @returns Base asset amount
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertToBaseAssetAmount(amount: BN, assetType: 'base' | 'quote', limitPrice?: BN): BN;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves amount parameters from either new (amount + assetType) or legacy (baseAssetAmount) approach
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveBaseAssetAmount(params: {
|
|
15
|
+
amount?: BN;
|
|
16
|
+
assetType?: 'base' | 'quote';
|
|
17
|
+
baseAssetAmount?: BN;
|
|
18
|
+
limitPrice?: BN;
|
|
19
|
+
}): BN;
|
|
20
|
+
export type NonMarketOrderType = 'limit' | 'takeProfit' | 'stopLoss' | 'oracleLimit';
|
|
21
|
+
export interface NonMarketOrderParamsConfig {
|
|
22
|
+
marketIndex: number;
|
|
23
|
+
marketType: MarketType;
|
|
24
|
+
direction: PositionDirection;
|
|
25
|
+
baseAssetAmount: BN;
|
|
26
|
+
reduceOnly?: boolean;
|
|
27
|
+
postOnly?: PostOnlyParams;
|
|
28
|
+
orderConfig: {
|
|
29
|
+
orderType: Extract<NonMarketOrderType, 'limit'>;
|
|
30
|
+
limitPrice: BN;
|
|
31
|
+
disableSwift?: boolean;
|
|
32
|
+
bracketOrders?: {
|
|
33
|
+
takeProfit?: OptionalTriggerOrderParams;
|
|
34
|
+
stopLoss?: OptionalTriggerOrderParams;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
orderType: Extract<NonMarketOrderType, 'takeProfit' | 'stopLoss'>;
|
|
38
|
+
triggerPrice: BN;
|
|
39
|
+
limitPrice?: BN;
|
|
40
|
+
} | {
|
|
41
|
+
orderType: Extract<NonMarketOrderType, 'oracleLimit'>;
|
|
42
|
+
oraclePriceOffset: BN;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Builds proper order parameters for non-market orders using the same logic as the UI
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildNonMarketOrderParams({ marketIndex, marketType, direction, baseAssetAmount, orderConfig, reduceOnly, postOnly, }: NonMarketOrderParamsConfig): OptionalOrderParams;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildNonMarketOrderParams = exports.resolveBaseAssetAmount = exports.convertToBaseAssetAmount = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Converts amount and assetType to base asset amount
|
|
8
|
+
* @param amount - The amount to convert
|
|
9
|
+
* @param assetType - 'base' or 'quote'
|
|
10
|
+
* @param limitPrice - Required when assetType is 'quote' for conversion
|
|
11
|
+
* @returns Base asset amount
|
|
12
|
+
*/
|
|
13
|
+
function convertToBaseAssetAmount(amount, assetType, limitPrice) {
|
|
14
|
+
if (assetType === 'quote') {
|
|
15
|
+
if (!limitPrice || limitPrice.isZero()) {
|
|
16
|
+
throw new Error('When using quote asset type, limitPrice is required for conversion to base amount');
|
|
17
|
+
}
|
|
18
|
+
// Convert quote amount to base amount: quoteAmount / price = baseAmount
|
|
19
|
+
// Using PRICE_PRECISION as the limit price is in price precision
|
|
20
|
+
const PRICE_PRECISION = new sdk_1.BN(10).pow(new sdk_1.BN(6));
|
|
21
|
+
return amount.mul(PRICE_PRECISION).div(limitPrice);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Base amount, use directly
|
|
25
|
+
return amount;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.convertToBaseAssetAmount = convertToBaseAssetAmount;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves amount parameters from either new (amount + assetType) or legacy (baseAssetAmount) approach
|
|
31
|
+
*/
|
|
32
|
+
function resolveBaseAssetAmount(params) {
|
|
33
|
+
const { amount, assetType, baseAssetAmount, limitPrice } = params;
|
|
34
|
+
if (amount && assetType) {
|
|
35
|
+
// New approach: convert if needed
|
|
36
|
+
return convertToBaseAssetAmount(amount, assetType, limitPrice);
|
|
37
|
+
}
|
|
38
|
+
else if (baseAssetAmount) {
|
|
39
|
+
// Legacy approach
|
|
40
|
+
return baseAssetAmount;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('Either (amount + assetType) or baseAssetAmount must be provided');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.resolveBaseAssetAmount = resolveBaseAssetAmount;
|
|
47
|
+
/**
|
|
48
|
+
* Determine trigger condition based on direction
|
|
49
|
+
* For stop orders: ABOVE when long, BELOW when short
|
|
50
|
+
* For take profit orders: BELOW when long, ABOVE when short
|
|
51
|
+
*/
|
|
52
|
+
const getTriggerCondition = (direction, tpOrSl) => {
|
|
53
|
+
const isTakeProfit = tpOrSl === 'takeProfit';
|
|
54
|
+
const isLong = utils_1.ENUM_UTILS.match(direction, sdk_1.PositionDirection.LONG);
|
|
55
|
+
if (isTakeProfit) {
|
|
56
|
+
if (isLong) {
|
|
57
|
+
return sdk_1.OrderTriggerCondition.BELOW;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return sdk_1.OrderTriggerCondition.ABOVE;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Stop loss
|
|
65
|
+
if (isLong) {
|
|
66
|
+
return sdk_1.OrderTriggerCondition.ABOVE;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return sdk_1.OrderTriggerCondition.BELOW;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Builds proper order parameters for non-market orders using the same logic as the UI
|
|
75
|
+
*/
|
|
76
|
+
function buildNonMarketOrderParams({ marketIndex, marketType, direction, baseAssetAmount, orderConfig, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, }) {
|
|
77
|
+
const orderType = orderConfig.orderType;
|
|
78
|
+
// Build order params based on order type using SDK functions
|
|
79
|
+
if (orderType === 'limit') {
|
|
80
|
+
if (!orderConfig.limitPrice) {
|
|
81
|
+
throw new Error('LIMIT orders require limitPrice');
|
|
82
|
+
}
|
|
83
|
+
return (0, sdk_1.getLimitOrderParams)({
|
|
84
|
+
marketIndex,
|
|
85
|
+
marketType,
|
|
86
|
+
direction,
|
|
87
|
+
baseAssetAmount,
|
|
88
|
+
price: orderConfig.limitPrice,
|
|
89
|
+
reduceOnly,
|
|
90
|
+
postOnly,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (orderType === 'takeProfit' || orderType === 'stopLoss') {
|
|
94
|
+
if (!orderConfig.triggerPrice) {
|
|
95
|
+
throw new Error('TRIGGER_MARKET orders require triggerPrice');
|
|
96
|
+
}
|
|
97
|
+
const triggerCondition = getTriggerCondition(direction, orderType);
|
|
98
|
+
const hasLimitPrice = !!orderConfig.limitPrice;
|
|
99
|
+
if (hasLimitPrice) {
|
|
100
|
+
return (0, sdk_1.getTriggerLimitOrderParams)({
|
|
101
|
+
marketIndex,
|
|
102
|
+
marketType,
|
|
103
|
+
direction,
|
|
104
|
+
baseAssetAmount,
|
|
105
|
+
triggerPrice: orderConfig.triggerPrice,
|
|
106
|
+
price: orderConfig.limitPrice,
|
|
107
|
+
triggerCondition,
|
|
108
|
+
reduceOnly,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return (0, sdk_1.getTriggerMarketOrderParams)({
|
|
113
|
+
marketIndex,
|
|
114
|
+
marketType,
|
|
115
|
+
direction,
|
|
116
|
+
baseAssetAmount,
|
|
117
|
+
triggerPrice: orderConfig.triggerPrice,
|
|
118
|
+
price: orderConfig.limitPrice,
|
|
119
|
+
triggerCondition,
|
|
120
|
+
reduceOnly,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (orderType === 'oracleLimit') {
|
|
125
|
+
if (!orderConfig.oraclePriceOffset) {
|
|
126
|
+
throw new Error('ORACLE orders require oraclePriceOffset');
|
|
127
|
+
}
|
|
128
|
+
return (0, sdk_1.getLimitOrderParams)({
|
|
129
|
+
marketIndex,
|
|
130
|
+
marketType,
|
|
131
|
+
direction,
|
|
132
|
+
baseAssetAmount,
|
|
133
|
+
price: sdk_1.ZERO,
|
|
134
|
+
oraclePriceOffset: orderConfig.oraclePriceOffset.toNumber(),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
throw new Error(`Unsupported order type: ${orderType}`);
|
|
138
|
+
}
|
|
139
|
+
exports.buildNonMarketOrderParams = buildNonMarketOrderParams;
|
|
140
|
+
//# sourceMappingURL=orderParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderParams.js","sourceRoot":"","sources":["../../../src/drift/utils/orderParams.ts"],"names":[],"mappings":";;;AAAA,yCAWyB;AACzB,uCAAyC;AAGzC;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACvC,MAAU,EACV,SAA2B,EAC3B,UAAe;IAEf,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACd,mFAAmF,CACnF,CAAC;QACH,CAAC;QACD,wEAAwE;QACxE,iEAAiE;QACjE,MAAM,eAAe,GAAG,IAAI,QAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,QAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;Q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IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,IAAA,yBAAmB,EAAC;YAC1B,WAAW;YACX,UAAU;YACV,SAAS;YACT,eAAe;YACf,KAAK,EAAE,UAAI;YACX,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,CAAC,QAAQ,EAAE;SAC3D,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;AACzD,CAAC;AA7ED,8DA6EC","sourcesContent":["import {\n\tBN,\n\tMarketType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tOptionalOrderParams,\n\tgetLimitOrderParams,\n\tgetTriggerMarketOrderParams,\n\tgetTriggerLimitOrderParams,\n\tOrderTriggerCondition,\n\tZERO,\n} from '@drift-labs/sdk';\nimport { ENUM_UTILS } from '../../utils';\nimport { OptionalTriggerOrderParams } from '../base/actions/trade/openPerpOrder/openSwiftOrder';\n\n/**\n * Converts amount and assetType to base asset amount\n * @param amount - The amount to convert\n * @param assetType - 'base' or 'quote'\n * @param limitPrice - Required when assetType is 'quote' for conversion\n * @returns Base asset amount\n */\nexport function convertToBaseAssetAmount(\n\tamount: BN,\n\tassetType: 'base' | 'quote',\n\tlimitPrice?: BN\n): BN {\n\tif (assetType === 'quote') {\n\t\tif (!limitPrice || limitPrice.isZero()) {\n\t\t\tthrow new Error(\n\t\t\t\t'When using quote asset type, limitPrice is required for conversion to base amount'\n\t\t\t);\n\t\t}\n\t\t// Convert quote amount to base amount: quoteAmount / price = baseAmount\n\t\t// Using PRICE_PRECISION as the limit price is in price precision\n\t\tconst PRICE_PRECISION = new BN(10).pow(new BN(6));\n\t\treturn amount.mul(PRICE_PRECISION).div(limitPrice);\n\t} else {\n\t\t// Base amount, use directly\n\t\treturn amount;\n\t}\n}\n\n/**\n * Resolves amount parameters from either new (amount + assetType) or legacy (baseAssetAmount) approach\n */\nexport function resolveBaseAssetAmount(params: {\n\tamount?: BN;\n\tassetType?: 'base' | 'quote';\n\tbaseAssetAmount?: BN;\n\tlimitPrice?: BN;\n}): BN {\n\tconst { amount, assetType, baseAssetAmount, limitPrice } = params;\n\n\tif (amount && assetType) {\n\t\t// New approach: convert if needed\n\t\treturn convertToBaseAssetAmount(amount, assetType, limitPrice);\n\t} else if (baseAssetAmount) {\n\t\t// Legacy approach\n\t\treturn baseAssetAmount;\n\t} else {\n\t\tthrow new Error(\n\t\t\t'Either (amount + assetType) or baseAssetAmount must be provided'\n\t\t);\n\t}\n}\n\nexport type NonMarketOrderType =\n\t| 'limit'\n\t| 'takeProfit'\n\t| 'stopLoss'\n\t| 'oracleLimit';\n\nexport interface NonMarketOrderParamsConfig {\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\torderConfig:\n\t\t| {\n\t\t\t\torderType: Extract<NonMarketOrderType, 'limit'>;\n\t\t\t\tlimitPrice: BN;\n\t\t\t\tdisableSwift?: boolean;\n\t\t\t\tbracketOrders?: {\n\t\t\t\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\t\t\t\tstopLoss?: OptionalTriggerOrderParams;\n\t\t\t\t};\n\t\t }\n\t\t| {\n\t\t\t\torderType: Extract<NonMarketOrderType, 'takeProfit' | 'stopLoss'>;\n\t\t\t\ttriggerPrice: BN;\n\t\t\t\tlimitPrice?: BN;\n\t\t }\n\t\t| {\n\t\t\t\torderType: Extract<NonMarketOrderType, 'oracleLimit'>;\n\t\t\t\toraclePriceOffset: BN;\n\t\t };\n}\n\n/**\n * Determine trigger condition based on direction\n * For stop orders: ABOVE when long, BELOW when short\n * For take profit orders: BELOW when long, ABOVE when short\n */\nconst getTriggerCondition = (\n\tdirection: PositionDirection,\n\ttpOrSl: 'takeProfit' | 'stopLoss'\n) => {\n\tconst isTakeProfit = tpOrSl === 'takeProfit';\n\tconst isLong = ENUM_UTILS.match(direction, PositionDirection.LONG);\n\n\tif (isTakeProfit) {\n\t\tif (isLong) {\n\t\t\treturn OrderTriggerCondition.BELOW;\n\t\t} else {\n\t\t\treturn OrderTriggerCondition.ABOVE;\n\t\t}\n\t} else {\n\t\t// Stop loss\n\t\tif (isLong) {\n\t\t\treturn OrderTriggerCondition.ABOVE;\n\t\t} else {\n\t\t\treturn OrderTriggerCondition.BELOW;\n\t\t}\n\t}\n};\n\n/**\n * Builds proper order parameters for non-market orders using the same logic as the UI\n */\nexport function buildNonMarketOrderParams({\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tbaseAssetAmount,\n\torderConfig,\n\treduceOnly = false,\n\tpostOnly = PostOnlyParams.NONE,\n}: NonMarketOrderParamsConfig): OptionalOrderParams {\n\tconst orderType = orderConfig.orderType;\n\n\t// Build order params based on order type using SDK functions\n\tif (orderType === 'limit') {\n\t\tif (!orderConfig.limitPrice) {\n\t\t\tthrow new Error('LIMIT orders require limitPrice');\n\t\t}\n\n\t\treturn getLimitOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount,\n\t\t\tprice: orderConfig.limitPrice,\n\t\t\treduceOnly,\n\t\t\tpostOnly,\n\t\t});\n\t}\n\n\tif (orderType === 'takeProfit' || orderType === 'stopLoss') {\n\t\tif (!orderConfig.triggerPrice) {\n\t\t\tthrow new Error('TRIGGER_MARKET orders require triggerPrice');\n\t\t}\n\n\t\tconst triggerCondition = getTriggerCondition(direction, orderType);\n\t\tconst hasLimitPrice = !!orderConfig.limitPrice;\n\n\t\tif (hasLimitPrice) {\n\t\t\treturn getTriggerLimitOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType,\n\t\t\t\tdirection,\n\t\t\t\tbaseAssetAmount,\n\t\t\t\ttriggerPrice: orderConfig.triggerPrice,\n\t\t\t\tprice: orderConfig.limitPrice,\n\t\t\t\ttriggerCondition,\n\t\t\t\treduceOnly,\n\t\t\t});\n\t\t} else {\n\t\t\treturn getTriggerMarketOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType,\n\t\t\t\tdirection,\n\t\t\t\tbaseAssetAmount,\n\t\t\t\ttriggerPrice: orderConfig.triggerPrice,\n\t\t\t\tprice: orderConfig.limitPrice,\n\t\t\t\ttriggerCondition,\n\t\t\t\treduceOnly,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (orderType === 'oracleLimit') {\n\t\tif (!orderConfig.oraclePriceOffset) {\n\t\t\tthrow new Error('ORACLE orders require oraclePriceOffset');\n\t\t}\n\n\t\treturn getLimitOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount,\n\t\t\tprice: ZERO,\n\t\t\toraclePriceOffset: orderConfig.oraclePriceOffset.toNumber(),\n\t\t});\n\t}\n\n\tthrow new Error(`Unsupported order type: ${orderType}`);\n}\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export * from './Config';
|
|
2
|
+
export * from './chartConstants';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './EnvironmentConstants';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export * from './utils/index';
|
|
7
|
+
export * from './utils/s3Buckets';
|
|
8
|
+
export * from './serializableTypes';
|
|
9
|
+
export * from './utils/candles/Candle';
|
|
10
|
+
export * from './utils/featureFlags';
|
|
11
|
+
export * from './utils/WalletConnectionState';
|
|
12
|
+
export * from './utils/rpcLatency';
|
|
13
|
+
export * from './utils/token';
|
|
14
|
+
export * from './utils/math';
|
|
15
|
+
export * from './utils/logger';
|
|
16
|
+
export * from './utils/equalityChecks';
|
|
17
|
+
export * from './common-ui-utils';
|
|
18
|
+
export * from './constants';
|
|
19
|
+
export * from './actions/actionHelpers/actionHelpers';
|
|
20
|
+
export * from './utils/SharedInterval';
|
|
21
|
+
export * from './utils/Stopwatch';
|
|
22
|
+
export * from './utils/priority-fees';
|
|
23
|
+
export * from './utils/superstake';
|
|
24
|
+
export * from './utils/dlob-server/DlobServerWebsocketUtils';
|
|
25
|
+
export * from './common-ui-utils/settings/settings';
|
|
26
|
+
export * from './utils/priority-fees';
|
|
27
|
+
export * from './utils/orderbook';
|
|
28
|
+
export * from './clients/candleClient';
|
|
29
|
+
export * from './clients/marketDataFeed';
|
|
30
|
+
export * from './clients/swiftClient';
|
|
31
|
+
export * from './clients/tvFeed';
|
|
32
|
+
export * from './utils/pollingSequenceGuard';
|
|
33
|
+
export * from './utils/driftEvents';
|
|
34
|
+
export * from './utils/MultiplexWebSocket';
|
|
35
|
+
export * from './utils/SlotBasedResultValidator';
|
|
36
|
+
export * from './utils/CircularBuffers';
|
|
37
|
+
export * from './utils/rxjs';
|
|
38
|
+
export * from './utils/priorityFees';
|
|
39
|
+
export * from './utils/NumLib';
|
|
40
|
+
export * from './drift';
|
|
41
|
+
import JupV4Errors from './constants/autogenerated/jup-v4-error-codes.json';
|
|
42
|
+
import JupV6Errors from './constants/autogenerated/jup-v6-error-codes.json';
|
|
43
|
+
export { JupV4Errors, JupV6Errors };
|
|
44
|
+
import DriftErrors from './constants/autogenerated/driftErrors.json';
|
|
45
|
+
export { DriftErrors };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.DriftErrors = exports.JupV6Errors = exports.JupV4Errors = void 0;
|
|
21
|
+
__exportStar(require("./Config"), exports);
|
|
22
|
+
__exportStar(require("./chartConstants"), exports);
|
|
23
|
+
__exportStar(require("./types"), exports);
|
|
24
|
+
__exportStar(require("./EnvironmentConstants"), exports);
|
|
25
|
+
__exportStar(require("./utils"), exports);
|
|
26
|
+
__exportStar(require("./utils/index"), exports);
|
|
27
|
+
__exportStar(require("./utils/s3Buckets"), exports);
|
|
28
|
+
__exportStar(require("./serializableTypes"), exports);
|
|
29
|
+
__exportStar(require("./utils/candles/Candle"), exports);
|
|
30
|
+
__exportStar(require("./utils/featureFlags"), exports);
|
|
31
|
+
__exportStar(require("./utils/WalletConnectionState"), exports);
|
|
32
|
+
__exportStar(require("./utils/rpcLatency"), exports);
|
|
33
|
+
__exportStar(require("./utils/token"), exports);
|
|
34
|
+
__exportStar(require("./utils/math"), exports);
|
|
35
|
+
__exportStar(require("./utils/logger"), exports);
|
|
36
|
+
__exportStar(require("./utils/equalityChecks"), exports);
|
|
37
|
+
__exportStar(require("./common-ui-utils"), exports);
|
|
38
|
+
__exportStar(require("./constants"), exports);
|
|
39
|
+
__exportStar(require("./actions/actionHelpers/actionHelpers"), exports);
|
|
40
|
+
__exportStar(require("./utils/SharedInterval"), exports);
|
|
41
|
+
__exportStar(require("./utils/Stopwatch"), exports);
|
|
42
|
+
__exportStar(require("./utils/priority-fees"), exports);
|
|
43
|
+
__exportStar(require("./utils/superstake"), exports);
|
|
44
|
+
__exportStar(require("./utils/dlob-server/DlobServerWebsocketUtils"), exports);
|
|
45
|
+
__exportStar(require("./common-ui-utils/settings/settings"), exports);
|
|
46
|
+
__exportStar(require("./utils/priority-fees"), exports);
|
|
47
|
+
__exportStar(require("./utils/orderbook"), exports);
|
|
48
|
+
__exportStar(require("./clients/candleClient"), exports);
|
|
49
|
+
__exportStar(require("./clients/marketDataFeed"), exports);
|
|
50
|
+
__exportStar(require("./clients/swiftClient"), exports);
|
|
51
|
+
__exportStar(require("./clients/tvFeed"), exports);
|
|
52
|
+
__exportStar(require("./utils/pollingSequenceGuard"), exports);
|
|
53
|
+
__exportStar(require("./utils/driftEvents"), exports);
|
|
54
|
+
__exportStar(require("./utils/MultiplexWebSocket"), exports);
|
|
55
|
+
__exportStar(require("./utils/SlotBasedResultValidator"), exports);
|
|
56
|
+
__exportStar(require("./utils/CircularBuffers"), exports);
|
|
57
|
+
__exportStar(require("./utils/rxjs"), exports);
|
|
58
|
+
__exportStar(require("./utils/priorityFees"), exports);
|
|
59
|
+
__exportStar(require("./utils/NumLib"), exports);
|
|
60
|
+
__exportStar(require("./drift"), exports);
|
|
61
|
+
// External Program Errors
|
|
62
|
+
const jup_v4_error_codes_json_1 = __importDefault(require("./constants/autogenerated/jup-v4-error-codes.json"));
|
|
63
|
+
exports.JupV4Errors = jup_v4_error_codes_json_1.default;
|
|
64
|
+
const jup_v6_error_codes_json_1 = __importDefault(require("./constants/autogenerated/jup-v6-error-codes.json"));
|
|
65
|
+
exports.JupV6Errors = jup_v6_error_codes_json_1.default;
|
|
66
|
+
const driftErrors_json_1 = __importDefault(require("./constants/autogenerated/driftErrors.json"));
|
|
67
|
+
exports.DriftErrors = driftErrors_json_1.default;
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,mDAAiC;AACjC,0CAAwB;AACxB,yDAAuC;AACvC,0CAAwB;AACxB,gDAA8B;AAC9B,oDAAkC;AAClC,sDAAoC;AACpC,yDAAuC;AACvC,uDAAqC;AACrC,gEAA8C;AAC9C,qDAAmC;AACnC,gDAA8B;AAC9B,+CAA6B;AAC7B,iDAA+B;AAC/B,yDAAuC;AACvC,oDAAkC;AAClC,8CAA4B;AAC5B,wEAAsD;AACtD,yDAAuC;AACvC,oDAAkC;AAClC,wDAAsC;AACtC,qDAAmC;AACnC,+EAA6D;AAC7D,sEAAoD;AACpD,wDAAsC;AACtC,oDAAkC;AAClC,yDAAuC;AACvC,2DAAyC;AACzC,wDAAsC;AACtC,mDAAiC;AACjC,+DAA6C;AAC7C,sDAAoC;AACpC,6DAA2C;AAC3C,mEAAiD;AACjD,0DAAwC;AACxC,+CAA6B;AAC7B,uDAAqC;AACrC,iDAA+B;AAC/B,0CAAwB;AAExB,0BAA0B;AAC1B,gHAA4E;AAEnE,sBAFF,iCAAW,CAEE;AADpB,gHAA4E;AACtD,sBADf,iCAAW,CACe;AAEjC,kGAAqE;AAC5D,sBADF,0BAAW,CACE","sourcesContent":["export * from './Config';\nexport * from './chartConstants';\nexport * from './types';\nexport * from './EnvironmentConstants';\nexport * from './utils';\nexport * from './utils/index';\nexport * from './utils/s3Buckets';\nexport * from './serializableTypes';\nexport * from './utils/candles/Candle';\nexport * from './utils/featureFlags';\nexport * from './utils/WalletConnectionState';\nexport * from './utils/rpcLatency';\nexport * from './utils/token';\nexport * from './utils/math';\nexport * from './utils/logger';\nexport * from './utils/equalityChecks';\nexport * from './common-ui-utils';\nexport * from './constants';\nexport * from './actions/actionHelpers/actionHelpers';\nexport * from './utils/SharedInterval';\nexport * from './utils/Stopwatch';\nexport * from './utils/priority-fees';\nexport * from './utils/superstake';\nexport * from './utils/dlob-server/DlobServerWebsocketUtils';\nexport * from './common-ui-utils/settings/settings';\nexport * from './utils/priority-fees';\nexport * from './utils/orderbook';\nexport * from './clients/candleClient';\nexport * from './clients/marketDataFeed';\nexport * from './clients/swiftClient';\nexport * from './clients/tvFeed';\nexport * from './utils/pollingSequenceGuard';\nexport * from './utils/driftEvents';\nexport * from './utils/MultiplexWebSocket';\nexport * from './utils/SlotBasedResultValidator';\nexport * from './utils/CircularBuffers';\nexport * from './utils/rxjs';\nexport * from './utils/priorityFees';\nexport * from './utils/NumLib';\nexport * from './drift';\n\n// External Program Errors\nimport JupV4Errors from './constants/autogenerated/jup-v4-error-codes.json';\nimport JupV6Errors from './constants/autogenerated/jup-v6-error-codes.json';\nexport { JupV4Errors, JupV6Errors };\n\nimport DriftErrors from './constants/autogenerated/driftErrors.json';\nexport { DriftErrors };\n"]}
|