@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,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DriftTvFeed = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const Candle_1 = require("../utils/candles/Candle");
|
|
7
|
+
const pollingSequenceGuard_1 = require("../utils/pollingSequenceGuard");
|
|
8
|
+
const candleClient_1 = require("./candleClient");
|
|
9
|
+
const DRIFT_V2_START_TS = 1668470400; // 15th November 2022 ... 2022-11-15T00:00:00.000Z
|
|
10
|
+
const resolutions = [
|
|
11
|
+
'1',
|
|
12
|
+
'3',
|
|
13
|
+
'5',
|
|
14
|
+
'15',
|
|
15
|
+
'30',
|
|
16
|
+
'60',
|
|
17
|
+
'240',
|
|
18
|
+
'6H',
|
|
19
|
+
'8H',
|
|
20
|
+
'1D',
|
|
21
|
+
'3D',
|
|
22
|
+
'1W',
|
|
23
|
+
'1M',
|
|
24
|
+
];
|
|
25
|
+
const tvResolutionStringToStandardResolutionString = (tvResolutionString) => {
|
|
26
|
+
switch (tvResolutionString) {
|
|
27
|
+
case '1':
|
|
28
|
+
return '1';
|
|
29
|
+
case '5':
|
|
30
|
+
return '5';
|
|
31
|
+
case '15':
|
|
32
|
+
return '15';
|
|
33
|
+
case '60':
|
|
34
|
+
return '60';
|
|
35
|
+
case '240':
|
|
36
|
+
return '240';
|
|
37
|
+
case 'D':
|
|
38
|
+
case '1D':
|
|
39
|
+
return 'D';
|
|
40
|
+
case 'W':
|
|
41
|
+
case '1W':
|
|
42
|
+
return 'W';
|
|
43
|
+
case 'M':
|
|
44
|
+
case '1M':
|
|
45
|
+
return 'M';
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const DATAFEED_CONFIG = {
|
|
49
|
+
exchanges: [],
|
|
50
|
+
supported_resolutions: [...resolutions],
|
|
51
|
+
currency_codes: [],
|
|
52
|
+
supports_marks: true,
|
|
53
|
+
supports_time: false,
|
|
54
|
+
supports_timescale_marks: false,
|
|
55
|
+
symbols_types: [],
|
|
56
|
+
};
|
|
57
|
+
const findMarketBySymbol = (symbol, perpMarketConfigs, spotMarketConfigs) => {
|
|
58
|
+
if (!symbol) {
|
|
59
|
+
throw new Error(`TVFeed::No symbol provided`);
|
|
60
|
+
}
|
|
61
|
+
const sanitisedSymbol = symbol.toLowerCase().replace('/usdc', ''); // Lowercase and replace /usdc (for spot markets) to santise symbol for lookup
|
|
62
|
+
const isPerp = sanitisedSymbol.toLowerCase().includes('perp');
|
|
63
|
+
const matchingMarketConfig = isPerp
|
|
64
|
+
? perpMarketConfigs.find((mkt) => mkt.symbol.toLowerCase().includes(sanitisedSymbol.toLowerCase()))
|
|
65
|
+
: spotMarketConfigs.find((mkt) => mkt.symbol.toLowerCase().includes(sanitisedSymbol.toLowerCase()));
|
|
66
|
+
if (!matchingMarketConfig) {
|
|
67
|
+
throw new Error(`TVFeed::No market found for symbol ${symbol}`);
|
|
68
|
+
}
|
|
69
|
+
if (isPerp) {
|
|
70
|
+
return {
|
|
71
|
+
type: 'perp',
|
|
72
|
+
config: matchingMarketConfig,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
type: 'spot',
|
|
77
|
+
config: matchingMarketConfig,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const candleFetchingPollKey = Symbol('candleFetchingPollKey');
|
|
81
|
+
const candleToTvBar = (candle, candleType) => {
|
|
82
|
+
const useOraclePrice = candleType === types_1.CandleType.ORACLE_PRICE;
|
|
83
|
+
return {
|
|
84
|
+
time: candle.ts * 1000,
|
|
85
|
+
open: useOraclePrice ? candle.oracleOpen : candle.fillOpen,
|
|
86
|
+
high: useOraclePrice ? candle.oracleHigh : candle.fillHigh,
|
|
87
|
+
low: useOraclePrice ? candle.oracleLow : candle.fillLow,
|
|
88
|
+
close: useOraclePrice ? candle.oracleClose : candle.fillClose,
|
|
89
|
+
volume: candle.quoteVolume,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const PerpMarketConfigToTVMarketInfo = (marketConfig) => {
|
|
93
|
+
return {
|
|
94
|
+
symbol: marketConfig.symbol,
|
|
95
|
+
full_name: marketConfig.fullName,
|
|
96
|
+
description: marketConfig.fullName,
|
|
97
|
+
exchange: 'Drift',
|
|
98
|
+
ticker: marketConfig.symbol,
|
|
99
|
+
type: 'crypto',
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const SpotMarketConfigToTVMarketInfo = (marketConfig) => {
|
|
103
|
+
return {
|
|
104
|
+
symbol: marketConfig.symbol,
|
|
105
|
+
full_name: marketConfig.symbol,
|
|
106
|
+
description: marketConfig.symbol,
|
|
107
|
+
exchange: 'Drift',
|
|
108
|
+
ticker: marketConfig.symbol,
|
|
109
|
+
type: 'crypto',
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
class DriftTvFeed {
|
|
113
|
+
constructor(env, candleType, driftClient, perpMarketConfigs, spotMarketConfigs, tvAppTradeDataManager) {
|
|
114
|
+
this.searchMarkets = (symbol) => {
|
|
115
|
+
const res = [];
|
|
116
|
+
const currentPerpMarkets = this.perpMarketConfigs;
|
|
117
|
+
const currentSpotMarkets = this.spotMarketConfigs;
|
|
118
|
+
if (!symbol) {
|
|
119
|
+
res.push(PerpMarketConfigToTVMarketInfo(currentPerpMarkets[0]));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
for (const market of currentPerpMarkets) {
|
|
123
|
+
const lowerCaseMarket = market.symbol.toLowerCase();
|
|
124
|
+
if (lowerCaseMarket.includes(symbol.toLowerCase())) {
|
|
125
|
+
res.push(PerpMarketConfigToTVMarketInfo(market));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const market of currentSpotMarkets) {
|
|
129
|
+
const lowerCaseMarket = market.symbol.toLowerCase();
|
|
130
|
+
if (lowerCaseMarket.includes(symbol.toLowerCase())) {
|
|
131
|
+
res.push(SpotMarketConfigToTVMarketInfo(market));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return res.map((mkt) => {
|
|
136
|
+
return {
|
|
137
|
+
...mkt,
|
|
138
|
+
exchange: 'Drift',
|
|
139
|
+
type: 'crypto',
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* TradingView sometimes asks for a FROM timestamp halfway between two candles, this isn't compatible with the new candles API so we round these down the nearest candle - which should be the exact same candle!!
|
|
145
|
+
* @param timestamp
|
|
146
|
+
* @param resolution
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
this.roundFromTimestampToExactCandleTs = (timestamp, resolution) => {
|
|
150
|
+
const ROUND_UP = true;
|
|
151
|
+
const timestampMs = timestamp * 1000;
|
|
152
|
+
const candleLengthMs = Candle_1.Candle.resolutionStringToCandleLengthMs(resolution);
|
|
153
|
+
const remainderMs = timestampMs % candleLengthMs;
|
|
154
|
+
if (remainderMs === 0) {
|
|
155
|
+
return timestamp;
|
|
156
|
+
}
|
|
157
|
+
const roundedDownTimestampMs = timestampMs - remainderMs;
|
|
158
|
+
const roundedTimestampMs = ROUND_UP
|
|
159
|
+
? roundedDownTimestampMs + candleLengthMs
|
|
160
|
+
: roundedDownTimestampMs;
|
|
161
|
+
return roundedTimestampMs / 1000;
|
|
162
|
+
};
|
|
163
|
+
this.formatTVRequestedRange = (fromTs, toTs, resolution) => {
|
|
164
|
+
const formattedFromTs = this.roundFromTimestampToExactCandleTs(fromTs, resolution); // TradingView sometimes asks for a FROM timestamp halfway between two candles, so we round down to the nearest candle
|
|
165
|
+
const formattedToTs = Math.floor(Math.min(toTs, Date.now() / 1000)); // TradingView sometimes asks for a TO timestamp in the future, so we cap it at the current timestamp
|
|
166
|
+
return {
|
|
167
|
+
from: formattedFromTs,
|
|
168
|
+
to: formattedToTs,
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
this.env = env;
|
|
172
|
+
this.candleType = candleType;
|
|
173
|
+
this.candleClient = new candleClient_1.CandleClient();
|
|
174
|
+
this.driftClient = driftClient;
|
|
175
|
+
this.perpMarketConfigs = perpMarketConfigs;
|
|
176
|
+
this.spotMarketConfigs = spotMarketConfigs;
|
|
177
|
+
this.tvAppTradeDataManager = tvAppTradeDataManager;
|
|
178
|
+
}
|
|
179
|
+
resetCache() {
|
|
180
|
+
var _a;
|
|
181
|
+
(_a = this.onResetCache) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
182
|
+
}
|
|
183
|
+
// IExternalDatafeed implementation
|
|
184
|
+
onReady(callback) {
|
|
185
|
+
// using setTimeout because tradingview wants this to resolve asynchronously
|
|
186
|
+
setTimeout(() => callback(DATAFEED_CONFIG), 0);
|
|
187
|
+
}
|
|
188
|
+
// IDatafeedChartApi implementation
|
|
189
|
+
searchSymbols(userInput, _exchange, _symbolType, onResult) {
|
|
190
|
+
if (!userInput)
|
|
191
|
+
return onResult([]);
|
|
192
|
+
const res = this.searchMarkets(userInput);
|
|
193
|
+
onResult(res);
|
|
194
|
+
}
|
|
195
|
+
resolveSymbol(symbolName, onResolve, onError) {
|
|
196
|
+
const targetMarket = findMarketBySymbol(symbolName, this.perpMarketConfigs, this.spotMarketConfigs);
|
|
197
|
+
if (targetMarket) {
|
|
198
|
+
const tvMarketName = targetMarket.config.symbol;
|
|
199
|
+
let tickSize;
|
|
200
|
+
if (targetMarket.type === 'perp') {
|
|
201
|
+
tickSize = this.driftClient
|
|
202
|
+
.getPerpMarketAccount(targetMarket.config.marketIndex)
|
|
203
|
+
.amm.orderTickSize.toNumber();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
tickSize = this.driftClient
|
|
207
|
+
.getSpotMarketAccount(targetMarket.config.marketIndex)
|
|
208
|
+
.orderTickSize.toNumber();
|
|
209
|
+
}
|
|
210
|
+
const pricePrecisionExp = sdk_1.PRICE_PRECISION_EXP.toNumber();
|
|
211
|
+
const tickSizeExp = Math.ceil(Math.log10(tickSize));
|
|
212
|
+
const priceScaleExponent = Math.max(0, pricePrecisionExp - tickSizeExp);
|
|
213
|
+
const priceScale = 10 ** priceScaleExponent;
|
|
214
|
+
onResolve({
|
|
215
|
+
name: tvMarketName,
|
|
216
|
+
full_name: tvMarketName,
|
|
217
|
+
description: tvMarketName,
|
|
218
|
+
exchange: 'Drift',
|
|
219
|
+
ticker: targetMarket.config.symbol,
|
|
220
|
+
type: 'crypto',
|
|
221
|
+
session: '24x7',
|
|
222
|
+
timezone: 'Etc/UTC',
|
|
223
|
+
listed_exchange: 'Drift',
|
|
224
|
+
format: 'price',
|
|
225
|
+
pricescale: priceScale,
|
|
226
|
+
minmov: 1,
|
|
227
|
+
supported_resolutions: [...resolutions],
|
|
228
|
+
has_intraday: true,
|
|
229
|
+
intraday_multipliers: ['1', '5', '15', '60', '240'],
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
onError(`Couldn't find market for symbol ${symbolName}`);
|
|
234
|
+
}
|
|
235
|
+
// https://www.tradingview.com/charting-library-docs/latest/api/interfaces/Charting_Library.Mark/ reference for marks type
|
|
236
|
+
async getMarks(_symbolInfo, startDate, endDate, onDataCallback, _resolution) {
|
|
237
|
+
if (!this.tvAppTradeDataManager) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const orderHistory = await this.tvAppTradeDataManager.getFilledOrdersData(startDate, endDate);
|
|
241
|
+
const currentUserAccount = this.tvAppTradeDataManager.getCurrentSubAccountAddress();
|
|
242
|
+
const tradeMarks = orderHistory.map((trade) => {
|
|
243
|
+
const currentUserIsMaker = trade.maker === currentUserAccount;
|
|
244
|
+
const currentUserIsTaker = trade.taker === currentUserAccount;
|
|
245
|
+
let isLong;
|
|
246
|
+
if (currentUserIsMaker) {
|
|
247
|
+
isLong = trade.makerOrderDirection === 'long';
|
|
248
|
+
}
|
|
249
|
+
else if (currentUserIsTaker) {
|
|
250
|
+
isLong = trade.takerOrderDirection === 'long';
|
|
251
|
+
}
|
|
252
|
+
const color = isLong ? '#5DD5A0' : '#FF615C';
|
|
253
|
+
const baseAmount = Number(trade.baseAssetAmountFilled);
|
|
254
|
+
const quoteAmount = Number(trade.quoteAssetAmountFilled);
|
|
255
|
+
const avgPrice = quoteAmount / baseAmount;
|
|
256
|
+
const formatPrice = (price) => {
|
|
257
|
+
if (price >= 1) {
|
|
258
|
+
return price.toLocaleString('en-US', {
|
|
259
|
+
minimumFractionDigits: 2,
|
|
260
|
+
maximumFractionDigits: 2,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
if (price === 0)
|
|
265
|
+
return '0.0000';
|
|
266
|
+
if (price < 0.00001)
|
|
267
|
+
return '<0.00001';
|
|
268
|
+
return price.toFixed(4);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return {
|
|
272
|
+
id: trade.txSig,
|
|
273
|
+
time: trade.ts,
|
|
274
|
+
color: {
|
|
275
|
+
background: color,
|
|
276
|
+
border: '#152A44',
|
|
277
|
+
},
|
|
278
|
+
borderWidth: 1,
|
|
279
|
+
hoveredBorderWidth: 1,
|
|
280
|
+
text: `${isLong ? 'Long' : 'Short'} at $${formatPrice(avgPrice)}`,
|
|
281
|
+
label: isLong ? 'B' : 'S',
|
|
282
|
+
labelFontColor: '#000000',
|
|
283
|
+
minSize: 16,
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
onDataCallback(tradeMarks);
|
|
287
|
+
}
|
|
288
|
+
async getBars(symbolInfo, resolution, periodParams, onResult, _onError) {
|
|
289
|
+
var _a;
|
|
290
|
+
// Can automatically return no data if the requested range is before the Drift V2 launch
|
|
291
|
+
if (periodParams.to < DRIFT_V2_START_TS) {
|
|
292
|
+
onResult([], {
|
|
293
|
+
noData: true,
|
|
294
|
+
});
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const symbolToUse = (_a = symbolInfo.ticker) !== null && _a !== void 0 ? _a : symbolInfo.name;
|
|
298
|
+
const targetResolution = tvResolutionStringToStandardResolutionString(resolution);
|
|
299
|
+
const targetMarket = findMarketBySymbol(symbolToUse, this.perpMarketConfigs, this.spotMarketConfigs);
|
|
300
|
+
const targetMarketId = targetMarket.type === 'perp'
|
|
301
|
+
? types_1.MarketId.createPerpMarket(targetMarket.config.marketIndex)
|
|
302
|
+
: types_1.MarketId.createSpotMarket(targetMarket.config.marketIndex);
|
|
303
|
+
const fetchCandles = async () => {
|
|
304
|
+
const formattedTsRange = this.formatTVRequestedRange(periodParams.from, periodParams.to, targetResolution);
|
|
305
|
+
const candles = await this.candleClient.fetch({
|
|
306
|
+
env: this.env,
|
|
307
|
+
marketId: targetMarketId,
|
|
308
|
+
resolution: targetResolution,
|
|
309
|
+
fromTs: formattedTsRange.from,
|
|
310
|
+
toTs: formattedTsRange.to,
|
|
311
|
+
});
|
|
312
|
+
return candles;
|
|
313
|
+
};
|
|
314
|
+
const candlesResult = await pollingSequenceGuard_1.PollingSequenceGuard.fetch(candleFetchingPollKey, fetchCandles);
|
|
315
|
+
if (candlesResult.length === 0) {
|
|
316
|
+
onResult([], {
|
|
317
|
+
noData: true,
|
|
318
|
+
});
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const bars = candlesResult.map((candle) => candleToTvBar(candle, this.candleType));
|
|
322
|
+
onResult(bars, {
|
|
323
|
+
noData: candlesResult.length === 0,
|
|
324
|
+
});
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
async subscribeBars(symbolInfo, resolution, onTick, subscriberGuid, onResetCache) {
|
|
328
|
+
this.onResetCache = onResetCache;
|
|
329
|
+
const targetResolution = tvResolutionStringToStandardResolutionString(resolution);
|
|
330
|
+
const targetMarket = findMarketBySymbol(symbolInfo.ticker, this.perpMarketConfigs, this.spotMarketConfigs);
|
|
331
|
+
const targetMarketId = targetMarket.type === 'perp'
|
|
332
|
+
? types_1.MarketId.createPerpMarket(targetMarket.config.marketIndex)
|
|
333
|
+
: types_1.MarketId.createSpotMarket(targetMarket.config.marketIndex);
|
|
334
|
+
// First create the subscription and wait for it to be ready
|
|
335
|
+
await this.candleClient.subscribe({
|
|
336
|
+
resolution: targetResolution,
|
|
337
|
+
marketId: targetMarketId,
|
|
338
|
+
env: this.env,
|
|
339
|
+
}, subscriberGuid);
|
|
340
|
+
// Then set up the event listener once the eventBus exists
|
|
341
|
+
this.candleClient.on(subscriberGuid, 'candle-update', (newCandle) => {
|
|
342
|
+
const newBar = candleToTvBar(newCandle, this.candleType);
|
|
343
|
+
onTick(newBar);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
unsubscribeBars(listenerGuid) {
|
|
347
|
+
this.candleClient.unsubscribe(listenerGuid);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.DriftTvFeed = DriftTvFeed;
|
|
351
|
+
//# sourceMappingURL=tvFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tvFeed.js","s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AM,IAAI,CAAC,YAAY,CAAC,SAAS,CAChC;YACC,UAAU,EAAE,gBAAgB;YAC5B,QAAQ,EAAE,cAAc;YACxB,GAAG,EAAE,IAAI,CAAC,GAAG;SACb,EACD,cAAc,CACd,CAAC;QAEF,0DAA0D;QAC1D,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,eAAe,EAAE,CAAC,SAAS,EAAE,EAAE;YACnE,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEzD,MAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,eAAe,CAAC,YAAoB;QACnC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;CACD;AAjXD,kCAiXC","sourcesContent":["import {\n\tCandleResolution,\n\tDriftClient,\n\tPerpMarketConfig,\n\tPRICE_PRECISION_EXP,\n\tSpotMarketConfig,\n} from '@drift-labs/sdk';\nimport { CandleType, JsonCandle, JsonTrade, MarketId } from '../types';\nimport { UIEnv } from '../types/UIEnv';\nimport { Candle } from '../utils/candles/Candle';\nimport { PollingSequenceGuard } from '../utils/pollingSequenceGuard';\nimport { CandleClient } from './candleClient';\n\nconst DRIFT_V2_START_TS = 1668470400; // 15th November 2022 ... 2022-11-15T00:00:00.000Z\n\nconst resolutions = [\n\t'1',\n\t'3',\n\t'5',\n\t'15',\n\t'30',\n\t'60',\n\t'240',\n\t'6H',\n\t'8H',\n\t'1D',\n\t'3D',\n\t'1W',\n\t'1M',\n];\n\nconst tvResolutionStringToStandardResolutionString = (\n\ttvResolutionString\n): CandleResolution => {\n\tswitch (tvResolutionString) {\n\t\tcase '1':\n\t\t\treturn '1';\n\t\tcase '5':\n\t\t\treturn '5';\n\t\tcase '15':\n\t\t\treturn '15';\n\t\tcase '60':\n\t\t\treturn '60';\n\t\tcase '240':\n\t\t\treturn '240';\n\t\tcase 'D':\n\t\tcase '1D':\n\t\t\treturn 'D';\n\t\tcase 'W':\n\t\tcase '1W':\n\t\t\treturn 'W';\n\t\tcase 'M':\n\t\tcase '1M':\n\t\t\treturn 'M';\n\t}\n};\n\ntype TVMarketInfo = {\n\tsymbol: string;\n\tfull_name: string;\n\tdescription: string;\n\texchange: string;\n\tticker: string;\n\ttype: string;\n};\n\nconst DATAFEED_CONFIG = {\n\texchanges: [],\n\tsupported_resolutions: [...resolutions],\n\tcurrency_codes: [],\n\tsupports_marks: true,\n\tsupports_time: false,\n\tsupports_timescale_marks: false,\n\tsymbols_types: [],\n};\n\ntype TVBar = {\n\t/** Bar time.\n\t * Amount of **milliseconds** since Unix epoch start in **UTC** timezone.\n\t * `time` for daily, weekly, and monthly bars is expected to be a trading day (not session start day) at 00:00 UTC.\n\t * The library adjusts time according to `session` from {@link LibrarySymbolInfo}.\n\t */\n\ttime: number;\n\t/** Opening price */\n\topen: number;\n\t/** High price */\n\thigh: number;\n\t/** Low price */\n\tlow: number;\n\t/** Closing price */\n\tclose: number;\n\t/** Trading Volume */\n\tvolume?: number;\n};\n\nconst findMarketBySymbol = (\n\tsymbol: string,\n\tperpMarketConfigs: PerpMarketConfig[],\n\tspotMarketConfigs: SpotMarketConfig[]\n):\n\t| {\n\t\t\ttype: 'perp';\n\t\t\tconfig: PerpMarketConfig;\n\t }\n\t| {\n\t\t\ttype: 'spot';\n\t\t\tconfig: SpotMarketConfig;\n\t } => {\n\tif (!symbol) {\n\t\tthrow new Error(`TVFeed::No symbol provided`);\n\t}\n\n\tconst sanitisedSymbol = symbol.toLowerCase().replace('/usdc', ''); // Lowercase and replace /usdc (for spot markets) to santise symbol for lookup\n\n\tconst isPerp = sanitisedSymbol.toLowerCase().includes('perp');\n\n\tconst matchingMarketConfig = isPerp\n\t\t? perpMarketConfigs.find((mkt) =>\n\t\t\t\tmkt.symbol.toLowerCase().includes(sanitisedSymbol.toLowerCase())\n\t\t )\n\t\t: spotMarketConfigs.find((mkt) =>\n\t\t\t\tmkt.symbol.toLowerCase().includes(sanitisedSymbol.toLowerCase())\n\t\t );\n\n\tif (!matchingMarketConfig) {\n\t\tthrow new Error(`TVFeed::No market found for symbol ${symbol}`);\n\t}\n\n\tif (isPerp) {\n\t\treturn {\n\t\t\ttype: 'perp',\n\t\t\tconfig: matchingMarketConfig as PerpMarketConfig,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'spot',\n\t\tconfig: matchingMarketConfig as SpotMarketConfig,\n\t};\n};\n\nconst candleFetchingPollKey = Symbol('candleFetchingPollKey');\n\nconst candleToTvBar = (candle: JsonCandle, candleType: CandleType): TVBar => {\n\tconst useOraclePrice = candleType === CandleType.ORACLE_PRICE;\n\n\treturn {\n\t\ttime: candle.ts * 1000,\n\t\topen: useOraclePrice ? candle.oracleOpen : candle.fillOpen,\n\t\thigh: useOraclePrice ? candle.oracleHigh : candle.fillHigh,\n\t\tlow: useOraclePrice ? candle.oracleLow : candle.fillLow,\n\t\tclose: useOraclePrice ? candle.oracleClose : candle.fillClose,\n\t\tvolume: candle.quoteVolume,\n\t};\n};\n\nconst PerpMarketConfigToTVMarketInfo = (\n\tmarketConfig: PerpMarketConfig\n): TVMarketInfo => {\n\treturn {\n\t\tsymbol: marketConfig.symbol,\n\t\tfull_name: marketConfig.fullName,\n\t\tdescription: marketConfig.fullName,\n\t\texchange: 'Drift',\n\t\tticker: marketConfig.symbol,\n\t\ttype: 'crypto',\n\t};\n};\n\nconst SpotMarketConfigToTVMarketInfo = (\n\tmarketConfig: SpotMarketConfig\n): TVMarketInfo => {\n\treturn {\n\t\tsymbol: marketConfig.symbol,\n\t\tfull_name: marketConfig.symbol,\n\t\tdescription: marketConfig.symbol,\n\t\texchange: 'Drift',\n\t\tticker: marketConfig.symbol,\n\t\ttype: 'crypto',\n\t};\n};\n\ninterface TvAppTradeDataManager {\n\tgetFilledOrdersData(startDate: number, endDate: number): Promise<JsonTrade[]>;\n\tgetCurrentSubAccountAddress(): string | null;\n}\n\nexport class DriftTvFeed {\n\tprivate env: UIEnv;\n\tprivate candleType: CandleType;\n\tprivate candleClient: CandleClient;\n\tprivate driftClient: DriftClient;\n\tprivate onResetCache: () => void;\n\tprivate perpMarketConfigs: PerpMarketConfig[];\n\tprivate spotMarketConfigs: SpotMarketConfig[];\n\tprivate tvAppTradeDataManager: TvAppTradeDataManager | undefined;\n\n\tconstructor(\n\t\tenv: UIEnv,\n\t\tcandleType: CandleType,\n\t\tdriftClient: DriftClient,\n\t\tperpMarketConfigs: PerpMarketConfig[],\n\t\tspotMarketConfigs: SpotMarketConfig[],\n\t\ttvAppTradeDataManager?: TvAppTradeDataManager\n\t) {\n\t\tthis.env = env;\n\t\tthis.candleType = candleType;\n\t\tthis.candleClient = new CandleClient();\n\t\tthis.driftClient = driftClient;\n\t\tthis.perpMarketConfigs = perpMarketConfigs;\n\t\tthis.spotMarketConfigs = spotMarketConfigs;\n\t\tthis.tvAppTradeDataManager = tvAppTradeDataManager;\n\t}\n\n\tpublic resetCache() {\n\t\tthis.onResetCache?.();\n\t}\n\n\tprivate searchMarkets = (symbol: string): TVMarketInfo[] => {\n\t\tconst res: Pick<\n\t\t\tTVMarketInfo,\n\t\t\t'symbol' | 'ticker' | 'full_name' | 'description'\n\t\t>[] = [];\n\n\t\tconst currentPerpMarkets = this.perpMarketConfigs;\n\t\tconst currentSpotMarkets = this.spotMarketConfigs;\n\n\t\tif (!symbol) {\n\t\t\tres.push(PerpMarketConfigToTVMarketInfo(currentPerpMarkets[0]));\n\t\t} else {\n\t\t\tfor (const market of currentPerpMarkets) {\n\t\t\t\tconst lowerCaseMarket = market.symbol.toLowerCase();\n\t\t\t\tif (lowerCaseMarket.includes(symbol.toLowerCase())) {\n\t\t\t\t\tres.push(PerpMarketConfigToTVMarketInfo(market));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const market of currentSpotMarkets) {\n\t\t\t\tconst lowerCaseMarket = market.symbol.toLowerCase();\n\t\t\t\tif (lowerCaseMarket.includes(symbol.toLowerCase())) {\n\t\t\t\t\tres.push(SpotMarketConfigToTVMarketInfo(market));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res.map((mkt) => {\n\t\t\treturn {\n\t\t\t\t...mkt,\n\t\t\t\texchange: 'Drift',\n\t\t\t\ttype: 'crypto',\n\t\t\t};\n\t\t});\n\t};\n\n\t// IExternalDatafeed implementation\n\tonReady(callback) {\n\t\t// using setTimeout because tradingview wants this to resolve asynchronously\n\t\tsetTimeout(() => callback(DATAFEED_CONFIG), 0);\n\t}\n\n\t// IDatafeedChartApi implementation\n\tsearchSymbols(\n\t\tuserInput: string,\n\t\t_exchange: string,\n\t\t_symbolType: string,\n\t\tonResult\n\t): void {\n\t\tif (!userInput) return onResult([]);\n\n\t\tconst res = this.searchMarkets(userInput);\n\n\t\tonResult(res);\n\t}\n\n\tresolveSymbol(symbolName: string, onResolve, onError): void {\n\t\tconst targetMarket = findMarketBySymbol(\n\t\t\tsymbolName,\n\t\t\tthis.perpMarketConfigs,\n\t\t\tthis.spotMarketConfigs\n\t\t);\n\n\t\tif (targetMarket) {\n\t\t\tconst tvMarketName = targetMarket.config.symbol;\n\n\t\t\tlet tickSize: number;\n\n\t\t\tif (targetMarket.type === 'perp') {\n\t\t\t\ttickSize = this.driftClient\n\t\t\t\t\t.getPerpMarketAccount(targetMarket.config.marketIndex)\n\t\t\t\t\t.amm.orderTickSize.toNumber();\n\t\t\t} else {\n\t\t\t\ttickSize = this.driftClient\n\t\t\t\t\t.getSpotMarketAccount(targetMarket.config.marketIndex)\n\t\t\t\t\t.orderTickSize.toNumber();\n\t\t\t}\n\n\t\t\tconst pricePrecisionExp = PRICE_PRECISION_EXP.toNumber();\n\t\t\tconst tickSizeExp = Math.ceil(Math.log10(tickSize));\n\t\t\tconst priceScaleExponent = Math.max(0, pricePrecisionExp - tickSizeExp);\n\t\t\tconst priceScale = 10 ** priceScaleExponent;\n\n\t\t\tonResolve({\n\t\t\t\tname: tvMarketName,\n\t\t\t\tfull_name: tvMarketName,\n\t\t\t\tdescription: tvMarketName,\n\t\t\t\texchange: 'Drift',\n\t\t\t\tticker: targetMarket.config.symbol,\n\t\t\t\ttype: 'crypto',\n\t\t\t\tsession: '24x7',\n\t\t\t\ttimezone: 'Etc/UTC',\n\t\t\t\tlisted_exchange: 'Drift',\n\t\t\t\tformat: 'price',\n\t\t\t\tpricescale: priceScale,\n\t\t\t\tminmov: 1,\n\t\t\t\tsupported_resolutions: [...resolutions],\n\t\t\t\thas_intraday: true,\n\t\t\t\tintraday_multipliers: ['1', '5', '15', '60', '240'],\n\t\t\t});\n\n\t\t\treturn;\n\t\t}\n\n\t\tonError(`Couldn't find market for symbol ${symbolName}`);\n\t}\n\n\t/**\n\t * TradingView sometimes asks for a FROM timestamp halfway between two candles, this isn't compatible with the new candles API so we round these down the nearest candle - which should be the exact same candle!!\n\t * @param timestamp\n\t * @param resolution\n\t * @returns\n\t */\n\tprivate roundFromTimestampToExactCandleTs = (\n\t\ttimestamp: number,\n\t\tresolution: CandleResolution\n\t) => {\n\t\tconst ROUND_UP = true;\n\n\t\tconst timestampMs = timestamp * 1000;\n\t\tconst candleLengthMs = Candle.resolutionStringToCandleLengthMs(resolution);\n\n\t\tconst remainderMs = timestampMs % candleLengthMs;\n\n\t\tif (remainderMs === 0) {\n\t\t\treturn timestamp;\n\t\t}\n\n\t\tconst roundedDownTimestampMs = timestampMs - remainderMs;\n\n\t\tconst roundedTimestampMs = ROUND_UP\n\t\t\t? roundedDownTimestampMs + candleLengthMs\n\t\t\t: roundedDownTimestampMs;\n\n\t\treturn roundedTimestampMs / 1000;\n\t};\n\n\tprivate formatTVRequestedRange = (\n\t\tfromTs: number,\n\t\ttoTs: number,\n\t\tresolution: CandleResolution\n\t) => {\n\t\tconst formattedFromTs = this.roundFromTimestampToExactCandleTs(\n\t\t\tfromTs,\n\t\t\tresolution\n\t\t); // TradingView sometimes asks for a FROM timestamp halfway between two candles, so we round down to the nearest candle\n\n\t\tconst formattedToTs = Math.floor(Math.min(toTs, Date.now() / 1000)); // TradingView sometimes asks for a TO timestamp in the future, so we cap it at the current timestamp\n\n\t\treturn {\n\t\t\tfrom: formattedFromTs,\n\t\t\tto: formattedToTs,\n\t\t};\n\t};\n\t// https://www.tradingview.com/charting-library-docs/latest/api/interfaces/Charting_Library.Mark/ reference for marks type\n\tasync getMarks(_symbolInfo, startDate, endDate, onDataCallback, _resolution) {\n\t\tif (!this.tvAppTradeDataManager) {\n\t\t\treturn;\n\t\t}\n\t\tconst orderHistory = await this.tvAppTradeDataManager.getFilledOrdersData(\n\t\t\tstartDate,\n\t\t\tendDate\n\t\t);\n\n\t\tconst currentUserAccount =\n\t\t\tthis.tvAppTradeDataManager.getCurrentSubAccountAddress();\n\n\t\tconst tradeMarks = orderHistory.map((trade) => {\n\t\t\tconst currentUserIsMaker = trade.maker === currentUserAccount;\n\t\t\tconst currentUserIsTaker = trade.taker === currentUserAccount;\n\n\t\t\tlet isLong: boolean;\n\t\t\tif (currentUserIsMaker) {\n\t\t\t\tisLong = trade.makerOrderDirection === 'long';\n\t\t\t} else if (currentUserIsTaker) {\n\t\t\t\tisLong = trade.takerOrderDirection === 'long';\n\t\t\t}\n\n\t\t\tconst color = isLong ? '#5DD5A0' : '#FF615C';\n\t\t\tconst baseAmount = Number(trade.baseAssetAmountFilled);\n\t\t\tconst quoteAmount = Number(trade.quoteAssetAmountFilled);\n\t\t\tconst avgPrice = quoteAmount / baseAmount;\n\n\t\t\tconst formatPrice = (price: number): string => {\n\t\t\t\tif (price >= 1) {\n\t\t\t\t\treturn price.toLocaleString('en-US', {\n\t\t\t\t\t\tminimumFractionDigits: 2,\n\t\t\t\t\t\tmaximumFractionDigits: 2,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tif (price === 0) return '0.0000';\n\t\t\t\t\tif (price < 0.00001) return '<0.00001';\n\t\t\t\t\treturn price.toFixed(4);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tid: trade.txSig,\n\t\t\t\ttime: trade.ts,\n\t\t\t\tcolor: {\n\t\t\t\t\tbackground: color,\n\t\t\t\t\tborder: '#152A44',\n\t\t\t\t},\n\t\t\t\tborderWidth: 1,\n\t\t\t\thoveredBorderWidth: 1,\n\t\t\t\ttext: `${isLong ? 'Long' : 'Short'} at $${formatPrice(avgPrice)}`,\n\t\t\t\tlabel: isLong ? 'B' : 'S',\n\t\t\t\tlabelFontColor: '#000000',\n\t\t\t\tminSize: 16,\n\t\t\t};\n\t\t});\n\n\t\tonDataCallback(tradeMarks);\n\t}\n\n\tasync getBars(\n\t\tsymbolInfo: {\n\t\t\tname: string;\n\t\t\tticker?: string;\n\t\t},\n\t\tresolution: string,\n\t\tperiodParams: {\n\t\t\tcountBack: number;\n\t\t\tfrom: number;\n\t\t\tto: number;\n\t\t},\n\t\tonResult: (\n\t\t\tbars: TVBar[],\n\t\t\tmeta?: {\n\t\t\t\tnoData: boolean;\n\t\t\t}\n\t\t) => void,\n\t\t_onError\n\t) {\n\t\t// Can automatically return no data if the requested range is before the Drift V2 launch\n\t\tif (periodParams.to < DRIFT_V2_START_TS) {\n\t\t\tonResult([], {\n\t\t\t\tnoData: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst symbolToUse = symbolInfo.ticker ?? symbolInfo.name;\n\n\t\tconst targetResolution =\n\t\t\ttvResolutionStringToStandardResolutionString(resolution);\n\t\tconst targetMarket = findMarketBySymbol(\n\t\t\tsymbolToUse,\n\t\t\tthis.perpMarketConfigs,\n\t\t\tthis.spotMarketConfigs\n\t\t);\n\t\tconst targetMarketId =\n\t\t\ttargetMarket.type === 'perp'\n\t\t\t\t? MarketId.createPerpMarket(targetMarket.config.marketIndex)\n\t\t\t\t: MarketId.createSpotMarket(targetMarket.config.marketIndex);\n\n\t\tconst fetchCandles = async () => {\n\t\t\tconst formattedTsRange = this.formatTVRequestedRange(\n\t\t\t\tperiodParams.from,\n\t\t\t\tperiodParams.to,\n\t\t\t\ttargetResolution\n\t\t\t);\n\n\t\t\tconst candles = await this.candleClient.fetch({\n\t\t\t\tenv: this.env,\n\t\t\t\tmarketId: targetMarketId,\n\t\t\t\tresolution: targetResolution,\n\t\t\t\tfromTs: formattedTsRange.from,\n\t\t\t\ttoTs: formattedTsRange.to,\n\t\t\t});\n\t\t\treturn candles;\n\t\t};\n\n\t\tconst candlesResult = await PollingSequenceGuard.fetch(\n\t\t\tcandleFetchingPollKey,\n\t\t\tfetchCandles\n\t\t);\n\n\t\tif (candlesResult.length === 0) {\n\t\t\tonResult([], {\n\t\t\t\tnoData: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst bars = candlesResult.map((candle) =>\n\t\t\tcandleToTvBar(candle, this.candleType)\n\t\t);\n\n\t\tonResult(bars, {\n\t\t\tnoData: candlesResult.length === 0,\n\t\t});\n\n\t\treturn;\n\t}\n\n\tasync subscribeBars(\n\t\tsymbolInfo,\n\t\tresolution,\n\t\tonTick,\n\t\tsubscriberGuid: string,\n\t\tonResetCache\n\t) {\n\t\tthis.onResetCache = onResetCache;\n\n\t\tconst targetResolution =\n\t\t\ttvResolutionStringToStandardResolutionString(resolution);\n\t\tconst targetMarket = findMarketBySymbol(\n\t\t\tsymbolInfo.ticker,\n\t\t\tthis.perpMarketConfigs,\n\t\t\tthis.spotMarketConfigs\n\t\t);\n\t\tconst targetMarketId =\n\t\t\ttargetMarket.type === 'perp'\n\t\t\t\t? MarketId.createPerpMarket(targetMarket.config.marketIndex)\n\t\t\t\t: MarketId.createSpotMarket(targetMarket.config.marketIndex);\n\n\t\t// First create the subscription and wait for it to be ready\n\t\tawait this.candleClient.subscribe(\n\t\t\t{\n\t\t\t\tresolution: targetResolution,\n\t\t\t\tmarketId: targetMarketId,\n\t\t\t\tenv: this.env,\n\t\t\t},\n\t\t\tsubscriberGuid\n\t\t);\n\n\t\t// Then set up the event listener once the eventBus exists\n\t\tthis.candleClient.on(subscriberGuid, 'candle-update', (newCandle) => {\n\t\t\tconst newBar = candleToTvBar(newCandle, this.candleType);\n\n\t\t\tonTick(newBar);\n\t\t});\n\t}\n\n\tunsubscribeBars(listenerGuid: string): void {\n\t\tthis.candleClient.unsubscribe(listenerGuid);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BN, BigNum, DriftClient, IWallet, MarketType, OptionalOrderParams, OrderType, PositionDirection, PublicKey, SpotMarketConfig, User, UserAccount } from '@drift-labs/sdk';
|
|
3
|
+
import { AccountInfo, Connection, ParsedAccountData } from '@solana/web3.js';
|
|
4
|
+
import { AuctionParams, TradeOffsetPrice } from 'src/types';
|
|
5
|
+
declare function chunks<T>(array: T[], size: number): T[][];
|
|
6
|
+
export declare const COMMON_UI_UTILS: {
|
|
7
|
+
getOrderLabelFromOrderDetails: (orderDetails: Pick<import("..").UISerializableOrder, "orderType" | "direction" | "triggerCondition" | "oraclePriceOffset" | "existingPositionDirection">) => string;
|
|
8
|
+
getLimitPriceFromOracleOffset: (order: import("..").UISerializableOrder, oraclePrice: BigNum) => BigNum;
|
|
9
|
+
isAuctionEmpty: (auctionParams: AuctionParams) => boolean;
|
|
10
|
+
getUIOrderTypeFromSdkOrderType: (orderType: OrderType, triggerCondition: import("@drift-labs/sdk").OrderTriggerCondition, direction: PositionDirection, oracleOffset: BigNum) => import("src/types").UIOrderTypeValue;
|
|
11
|
+
getBaseAssetSymbol: (marketName: string, removePrefix?: boolean) => string;
|
|
12
|
+
getPausedOperations: (marketAccount: import("@drift-labs/sdk").SpotMarketAccount | import("@drift-labs/sdk").PerpMarketAccount) => string[];
|
|
13
|
+
PerpOperationsMap: {
|
|
14
|
+
UPDATE_FUNDING: string;
|
|
15
|
+
AMM_FILL: string;
|
|
16
|
+
FILL: string;
|
|
17
|
+
SETTLE_PNL: string;
|
|
18
|
+
SETTLE_PNL_WITH_POSITION: string;
|
|
19
|
+
};
|
|
20
|
+
SpotOperationsMap: {
|
|
21
|
+
UPDATE_CUMULATIVE_INTEREST: string;
|
|
22
|
+
FILL: string;
|
|
23
|
+
WITHDRAW: string;
|
|
24
|
+
};
|
|
25
|
+
InsuranceFundOperationsMap: {
|
|
26
|
+
INIT: string;
|
|
27
|
+
ADD: string;
|
|
28
|
+
REQUEST_REMOVE: string;
|
|
29
|
+
REMOVE: string;
|
|
30
|
+
};
|
|
31
|
+
getMarketConfig: {
|
|
32
|
+
(driftEnv: import("@drift-labs/sdk").DriftEnv, marketType: {
|
|
33
|
+
perp: {};
|
|
34
|
+
}, marketIndex: number): import("@drift-labs/sdk").PerpMarketConfig;
|
|
35
|
+
(driftEnv: import("@drift-labs/sdk").DriftEnv, marketType: {
|
|
36
|
+
spot: {};
|
|
37
|
+
}, marketIndex: number): SpotMarketConfig;
|
|
38
|
+
};
|
|
39
|
+
calculatePnlPctFromPosition: (pnl: BN, quoteEntryAmount: BN, leverage?: number) => number;
|
|
40
|
+
calculatePotentialProfit: (props: {
|
|
41
|
+
currentPositionSize: BigNum;
|
|
42
|
+
currentPositionDirection: PositionDirection;
|
|
43
|
+
currentPositionEntryPrice: BigNum;
|
|
44
|
+
tradeDirection: PositionDirection;
|
|
45
|
+
exitBaseSize: BigNum;
|
|
46
|
+
exitPrice: BigNum;
|
|
47
|
+
takerFeeBps: number;
|
|
48
|
+
slippageTolerance?: number;
|
|
49
|
+
isMarketOrder?: boolean;
|
|
50
|
+
}) => {
|
|
51
|
+
estimatedProfit: BigNum;
|
|
52
|
+
estimatedProfitBeforeFees: BigNum;
|
|
53
|
+
estimatedTakerFee: BigNum;
|
|
54
|
+
notionalSizeAtEntry: BigNum;
|
|
55
|
+
notionalSizeAtExit: BigNum;
|
|
56
|
+
};
|
|
57
|
+
calculateLiquidationPriceAfterPerpTrade: ({ estEntryPrice, orderType, perpMarketIndex, tradeBaseSize, isLong, userClient, oraclePrice, limitPrice, offsetCollateral, precision, isEnteringHighLeverageMode, capLiqPrice, }: {
|
|
58
|
+
estEntryPrice: BN;
|
|
59
|
+
orderType: import("src/types").UIOrderType;
|
|
60
|
+
perpMarketIndex: number;
|
|
61
|
+
tradeBaseSize: BN;
|
|
62
|
+
isLong: boolean;
|
|
63
|
+
userClient: User;
|
|
64
|
+
oraclePrice: BN;
|
|
65
|
+
limitPrice?: BN;
|
|
66
|
+
offsetCollateral?: BN;
|
|
67
|
+
precision?: number;
|
|
68
|
+
isEnteringHighLeverageMode?: boolean;
|
|
69
|
+
capLiqPrice?: boolean;
|
|
70
|
+
}) => number;
|
|
71
|
+
checkIsMarketOrderType: (orderType: import("src/types").UIOrderType) => boolean;
|
|
72
|
+
convertLeverageToMarginRatio: (leverage: number) => number;
|
|
73
|
+
getMarketTickSize: (driftClient: DriftClient, marketId: import("src/types").MarketId) => BN;
|
|
74
|
+
getMarketTickSizeDecimals: (driftClient: DriftClient, marketId: import("src/types").MarketId) => number;
|
|
75
|
+
getMarketStepSize: (driftClient: DriftClient, marketId: import("src/types").MarketId) => BN;
|
|
76
|
+
getMarketStepSizeDecimals: (driftClient: DriftClient, marketId: import("src/types").MarketId) => number;
|
|
77
|
+
isEntirePositionOrder: (orderAmount: BigNum) => boolean;
|
|
78
|
+
getOpenPositionData: (driftClient: DriftClient, userPositions: import("@drift-labs/sdk").PerpPosition[], user: User, perpMarketLookup: import("@drift-labs/sdk").PerpMarketConfig[], markPriceCallback?: (marketIndex: number) => BN) => import("src/types").OpenPosition[];
|
|
79
|
+
checkIfUserAccountExists: (driftClient: DriftClient, config: {
|
|
80
|
+
type: "userPubKey";
|
|
81
|
+
userPubKey: PublicKey;
|
|
82
|
+
} | {
|
|
83
|
+
type: "subAccountId";
|
|
84
|
+
subAccountId: number;
|
|
85
|
+
authority: PublicKey;
|
|
86
|
+
}) => Promise<boolean>;
|
|
87
|
+
abbreviateAddress: (address: string | PublicKey, length?: number) => string;
|
|
88
|
+
calculateAverageEntryPrice: (quoteAssetAmount: BigNum, baseAssetAmount: BigNum) => BigNum;
|
|
89
|
+
chunks: typeof chunks;
|
|
90
|
+
compareSignatures: (original: string, hashed: string) => Promise<boolean>;
|
|
91
|
+
createThrowawayIWallet: (walletPubKey?: PublicKey) => IWallet;
|
|
92
|
+
createPlaceholderIWallet: (walletPubKey?: PublicKey) => IWallet;
|
|
93
|
+
deriveMarketOrderParams: ({ marketType, marketIndex, direction, maxLeverageSelected, maxLeverageOrderSize, baseAmount, reduceOnly, allowInfSlippage, oraclePrice, bestPrice, entryPrice, worstPrice, markPrice, auctionDuration, auctionStartPriceOffset, auctionEndPriceOffset, auctionStartPriceOffsetFrom, auctionEndPriceOffsetFrom, auctionPriceCaps, slippageTolerance, isOracleOrder, additionalEndPriceBuffer, forceUpToSlippage, }: {
|
|
94
|
+
marketType: MarketType;
|
|
95
|
+
marketIndex: number;
|
|
96
|
+
direction: PositionDirection;
|
|
97
|
+
maxLeverageSelected: boolean;
|
|
98
|
+
maxLeverageOrderSize: BN;
|
|
99
|
+
baseAmount: BN;
|
|
100
|
+
reduceOnly: boolean;
|
|
101
|
+
allowInfSlippage: boolean;
|
|
102
|
+
oraclePrice: BN;
|
|
103
|
+
bestPrice: BN;
|
|
104
|
+
entryPrice: BN;
|
|
105
|
+
worstPrice: BN;
|
|
106
|
+
markPrice: BN;
|
|
107
|
+
auctionDuration: number;
|
|
108
|
+
auctionStartPriceOffset: number;
|
|
109
|
+
auctionEndPriceOffset: number;
|
|
110
|
+
auctionPriceCaps?: {
|
|
111
|
+
min: BN;
|
|
112
|
+
max: BN;
|
|
113
|
+
};
|
|
114
|
+
auctionStartPriceOffsetFrom: TradeOffsetPrice;
|
|
115
|
+
auctionEndPriceOffsetFrom: TradeOffsetPrice;
|
|
116
|
+
slippageTolerance: number;
|
|
117
|
+
isOracleOrder?: boolean;
|
|
118
|
+
additionalEndPriceBuffer?: BN;
|
|
119
|
+
forceUpToSlippage?: boolean;
|
|
120
|
+
}) => OptionalOrderParams & {
|
|
121
|
+
constrainedBySlippage?: boolean;
|
|
122
|
+
};
|
|
123
|
+
fetchCurrentSubaccounts: (driftClient: DriftClient) => UserAccount[];
|
|
124
|
+
fetchUserClientsAndAccounts: (driftClient: DriftClient) => {
|
|
125
|
+
user: User;
|
|
126
|
+
userAccount: UserAccount;
|
|
127
|
+
}[];
|
|
128
|
+
formatTokenInputCurried: (setAmount: (amount: string) => void, spotMarketConfig: SpotMarketConfig) => (newAmount: string) => void;
|
|
129
|
+
getBalanceFromTokenAccountResult: (account: {
|
|
130
|
+
pubkey: PublicKey;
|
|
131
|
+
account: AccountInfo<ParsedAccountData>;
|
|
132
|
+
}) => any;
|
|
133
|
+
getIdAndAuthorityFromKey: (key: string) => {
|
|
134
|
+
userId: number;
|
|
135
|
+
userAuthority: PublicKey;
|
|
136
|
+
};
|
|
137
|
+
getLimitAuctionParams: ({ direction, inputPrice, startPriceFromSettings, duration, auctionStartPriceOffset, oraclePriceBands, }: {
|
|
138
|
+
direction: PositionDirection;
|
|
139
|
+
inputPrice: BigNum;
|
|
140
|
+
startPriceFromSettings: BN;
|
|
141
|
+
duration: number;
|
|
142
|
+
auctionStartPriceOffset: number;
|
|
143
|
+
oraclePriceBands?: [BN, BN];
|
|
144
|
+
}) => AuctionParams;
|
|
145
|
+
getLpSharesAmountForQuote: (driftClient: DriftClient, marketIndex: number, quoteAmount: BN) => BigNum;
|
|
146
|
+
getMarketAuctionParams: ({ direction, startPriceFromSettings, endPriceFromSettings, limitPrice, duration, auctionStartPriceOffset, auctionEndPriceOffset, additionalEndPriceBuffer, forceUpToSlippage, }: {
|
|
147
|
+
direction: PositionDirection;
|
|
148
|
+
startPriceFromSettings: BN;
|
|
149
|
+
endPriceFromSettings: BN;
|
|
150
|
+
/**
|
|
151
|
+
* Limit price is the oracle limit price - market orders use the oracle order type under the hood on Drift UI
|
|
152
|
+
* So oracle limit price is the oracle price + oracle offset
|
|
153
|
+
*/
|
|
154
|
+
limitPrice: BN;
|
|
155
|
+
duration: number;
|
|
156
|
+
auctionStartPriceOffset: number;
|
|
157
|
+
auctionEndPriceOffset: number;
|
|
158
|
+
additionalEndPriceBuffer?: BN;
|
|
159
|
+
forceUpToSlippage?: boolean;
|
|
160
|
+
}) => AuctionParams;
|
|
161
|
+
getMarketKey: (marketIndex: number, marketType: MarketType) => string;
|
|
162
|
+
getMarketOrderLimitPrice: ({ direction, baselinePrice, slippageTolerance, }: {
|
|
163
|
+
direction: PositionDirection;
|
|
164
|
+
baselinePrice: BN;
|
|
165
|
+
slippageTolerance: number;
|
|
166
|
+
}) => BN;
|
|
167
|
+
getMultipleAccounts: (connection: any, keys: string[], commitment: string) => Promise<{
|
|
168
|
+
keys: string[];
|
|
169
|
+
array: AccountInfo<Buffer>[];
|
|
170
|
+
}>;
|
|
171
|
+
getMultipleAccountsCore: (connection: any, keys: string[], commitment: string) => Promise<{
|
|
172
|
+
keys: string[];
|
|
173
|
+
array: AccountInfo<string[]>[];
|
|
174
|
+
}>;
|
|
175
|
+
getPriceObject: ({ oraclePrice, bestOffer, entryPrice, worstPrice, markPrice, direction, }: {
|
|
176
|
+
oraclePrice: BN;
|
|
177
|
+
bestOffer: BN;
|
|
178
|
+
entryPrice: BN;
|
|
179
|
+
worstPrice: BN;
|
|
180
|
+
markPrice: BN;
|
|
181
|
+
direction: PositionDirection;
|
|
182
|
+
}) => {
|
|
183
|
+
oracle: BN;
|
|
184
|
+
bestOffer: BN;
|
|
185
|
+
entry: BN;
|
|
186
|
+
best: BN;
|
|
187
|
+
worst: BN;
|
|
188
|
+
mark: BN;
|
|
189
|
+
};
|
|
190
|
+
getQuoteValueForLpShares: (driftClient: DriftClient, marketIndex: number, sharesAmount: BN) => BigNum;
|
|
191
|
+
getSignatureVerificationMessageForSettings: (authority: PublicKey, signTs: number) => Uint8Array;
|
|
192
|
+
getTokenAccount: (connection: Connection, mintAddress: PublicKey, userPubKey: PublicKey) => Promise<{
|
|
193
|
+
tokenAccount: {
|
|
194
|
+
pubkey: PublicKey;
|
|
195
|
+
account: import('@solana/web3.js').AccountInfo<import('@solana/web3.js').ParsedAccountData>;
|
|
196
|
+
};
|
|
197
|
+
tokenAccountWarning: boolean;
|
|
198
|
+
}>;
|
|
199
|
+
getTokenAddress: (mintAddress: PublicKey, userPubKey: PublicKey) => Promise<PublicKey>;
|
|
200
|
+
getUserKey: (userId: number, authority: PublicKey) => string;
|
|
201
|
+
hashSignature: (signature: string) => Promise<string>;
|
|
202
|
+
initializeAndSubscribeToNewUserAccount: (driftClient: DriftClient, userIdToInit: number, authority: PublicKey, callbacks: {
|
|
203
|
+
initializationStep: () => Promise<boolean>;
|
|
204
|
+
postInitializationStep?: () => Promise<boolean>;
|
|
205
|
+
handleSuccessStep?: (accountAlreadyExisted: boolean) => Promise<boolean>;
|
|
206
|
+
}) => Promise<'ok' | 'failed_initializationStep' | 'failed_postInitializationStep' | 'failed_awaitAccountInitializationChainState' | 'failed_handleSuccessStep'>;
|
|
207
|
+
userExists: (driftClient: DriftClient, userId: number, authority: PublicKey) => Promise<boolean>;
|
|
208
|
+
verifySignature: (signature: Uint8Array, message: Uint8Array, pubKey: PublicKey) => boolean;
|
|
209
|
+
trimTrailingZeros: (str: string, zerosToShow?: number) => string;
|
|
210
|
+
};
|
|
211
|
+
export {};
|