@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,61 @@
|
|
|
1
|
+
import { PerpMarketConfig, SpotMarketConfig } from '@drift-labs/sdk';
|
|
2
|
+
export interface IPredictionMarketConfig {
|
|
3
|
+
title: string;
|
|
4
|
+
shortTitle: string;
|
|
5
|
+
category?: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
imgSrc: string;
|
|
8
|
+
previewImgSrc?: string;
|
|
9
|
+
devnetMarketIndex?: number;
|
|
10
|
+
mainnetMarketIndex?: number;
|
|
11
|
+
production?: boolean;
|
|
12
|
+
endingSoonThresholdDays?: number;
|
|
13
|
+
resolutionDateUnknown?: boolean;
|
|
14
|
+
resolutionDate: Date;
|
|
15
|
+
newUntilTs?: number;
|
|
16
|
+
}
|
|
17
|
+
export type SerializedPredictionMarketConfig = Omit<IPredictionMarketConfig, 'resolutionDate'> & {
|
|
18
|
+
resolutionDateUnix: number;
|
|
19
|
+
};
|
|
20
|
+
export type SerializedSpotMarketConfig = Omit<SpotMarketConfig, 'oracle' | 'mint' | 'oracleSource' | 'precision' | 'precisionExp' | 'serumMarket' | 'phoenixMarket' | 'openbookMarket'> & {
|
|
21
|
+
oracle: string;
|
|
22
|
+
mint: string;
|
|
23
|
+
oracleSource: string;
|
|
24
|
+
precision: number;
|
|
25
|
+
precisionExp: number;
|
|
26
|
+
serumMarket?: string;
|
|
27
|
+
phoenixMarket?: string;
|
|
28
|
+
openbookMarket?: string;
|
|
29
|
+
production?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type SerializedPerpMarketConfig = Omit<PerpMarketConfig, 'oracle' | 'oracleSource'> & {
|
|
32
|
+
oracle: string;
|
|
33
|
+
oracleSource: string;
|
|
34
|
+
production?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export type SerializedRemoteConfigs = {
|
|
37
|
+
marketConfigs: {
|
|
38
|
+
devnet: {
|
|
39
|
+
spot: SerializedSpotMarketConfig[];
|
|
40
|
+
perp: SerializedPerpMarketConfig[];
|
|
41
|
+
};
|
|
42
|
+
mainnet: {
|
|
43
|
+
spot: SerializedSpotMarketConfig[];
|
|
44
|
+
perp: SerializedPerpMarketConfig[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
predictionMarkets: SerializedPredictionMarketConfig[];
|
|
48
|
+
};
|
|
49
|
+
export type RemoteConfigs = {
|
|
50
|
+
marketConfigs: {
|
|
51
|
+
devnet: {
|
|
52
|
+
spot: SpotMarketConfig[];
|
|
53
|
+
perp: PerpMarketConfig[];
|
|
54
|
+
};
|
|
55
|
+
mainnet: {
|
|
56
|
+
spot: SpotMarketConfig[];
|
|
57
|
+
perp: PerpMarketConfig[];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
predictionMarkets: IPredictionMarketConfig[];
|
|
61
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-configs.js","sourceRoot":"","sources":["../../src/types/remote-configs.ts"],"names":[],"mappings":"","sourcesContent":["import { PerpMarketConfig, SpotMarketConfig } from '@drift-labs/sdk';\n\nexport interface IPredictionMarketConfig {\n\ttitle: string;\n\tshortTitle: string;\n\tcategory?: string;\n\tsymbol: string;\n\timgSrc: string;\n\tpreviewImgSrc?: string;\n\tdevnetMarketIndex?: number;\n\tmainnetMarketIndex?: number;\n\tproduction?: boolean;\n\tendingSoonThresholdDays?: number;\n\tresolutionDateUnknown?: boolean;\n\tresolutionDate: Date;\n\tnewUntilTs?: number;\n}\n\nexport type SerializedPredictionMarketConfig = Omit<\n\tIPredictionMarketConfig,\n\t'resolutionDate'\n> & {\n\tresolutionDateUnix: number;\n};\n\nexport type SerializedSpotMarketConfig = Omit<\n\tSpotMarketConfig,\n\t| 'oracle'\n\t| 'mint'\n\t| 'oracleSource'\n\t| 'precision'\n\t| 'precisionExp'\n\t| 'serumMarket'\n\t| 'phoenixMarket'\n\t| 'openbookMarket'\n> & {\n\toracle: string;\n\tmint: string;\n\toracleSource: string;\n\tprecision: number;\n\tprecisionExp: number;\n\tserumMarket?: string;\n\tphoenixMarket?: string;\n\topenbookMarket?: string;\n\tproduction?: boolean;\n};\n\nexport type SerializedPerpMarketConfig = Omit<\n\tPerpMarketConfig,\n\t'oracle' | 'oracleSource'\n> & {\n\toracle: string;\n\toracleSource: string;\n\tproduction?: boolean;\n};\n\nexport type SerializedRemoteConfigs = {\n\tmarketConfigs: {\n\t\tdevnet: {\n\t\t\tspot: SerializedSpotMarketConfig[];\n\t\t\tperp: SerializedPerpMarketConfig[];\n\t\t};\n\t\tmainnet: {\n\t\t\tspot: SerializedSpotMarketConfig[];\n\t\t\tperp: SerializedPerpMarketConfig[];\n\t\t};\n\t};\n\tpredictionMarkets: SerializedPredictionMarketConfig[];\n};\n\nexport type RemoteConfigs = {\n\tmarketConfigs: {\n\t\tdevnet: {\n\t\t\tspot: SpotMarketConfig[];\n\t\t\tperp: PerpMarketConfig[];\n\t\t};\n\t\tmainnet: {\n\t\t\tspot: SpotMarketConfig[];\n\t\t\tperp: PerpMarketConfig[];\n\t\t};\n\t};\n\tpredictionMarkets: IPredictionMarketConfig[];\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BN, OrderType } from '@drift-labs/sdk';
|
|
2
|
+
export type TradeOffsetPrice = 'worst' | 'best' | 'oracle' | 'mark' | 'entry' | 'bestOffer';
|
|
3
|
+
export type UIOrderType = 'market' | 'limit' | 'stopMarket' | 'stopLimit' | 'takeProfitMarket' | 'takeProfitLimit' | 'oracle' | 'oracleLimit' | 'scaledOrders';
|
|
4
|
+
export type UIOrderTypeValue = {
|
|
5
|
+
label: string;
|
|
6
|
+
value: UIOrderType;
|
|
7
|
+
orderType: OrderType;
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
export type UIOrderTypeLookup = {
|
|
11
|
+
[key in UIOrderType]: UIOrderTypeValue;
|
|
12
|
+
};
|
|
13
|
+
export type AuctionParams = {
|
|
14
|
+
auctionStartPrice: BN;
|
|
15
|
+
auctionEndPrice: BN;
|
|
16
|
+
auctionDuration: number;
|
|
17
|
+
constrainedBySlippage?: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../../src/types/trade.ts"],"names":[],"mappings":"","sourcesContent":["import { BN, OrderType } from '@drift-labs/sdk';\n\nexport type TradeOffsetPrice =\n\t| 'worst'\n\t| 'best'\n\t| 'oracle'\n\t| 'mark'\n\t| 'entry'\n\t| 'bestOffer';\n\nexport type UIOrderType =\n\t| 'market'\n\t| 'limit'\n\t| 'stopMarket'\n\t| 'stopLimit'\n\t| 'takeProfitMarket'\n\t| 'takeProfitLimit'\n\t| 'oracle'\n\t| 'oracleLimit'\n\t| 'scaledOrders';\n\nexport type UIOrderTypeValue = {\n\tlabel: string;\n\tvalue: UIOrderType;\n\torderType: OrderType;\n\tdescription?: string;\n};\n\nexport type UIOrderTypeLookup = {\n\t[key in UIOrderType]: UIOrderTypeValue;\n};\n\nexport type AuctionParams = {\n\tauctionStartPrice: BN;\n\tauctionEndPrice: BN;\n\tauctionDuration: number;\n\tconstrainedBySlippage?: boolean; // flag to tell the UI that end price is constrained by max slippage tolerance\n};\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BN, PublicKey, SpotPosition } from '@drift-labs/sdk';
|
|
2
|
+
export type OpenPosition = {
|
|
3
|
+
marketIndex: number;
|
|
4
|
+
marketSymbol: string;
|
|
5
|
+
direction: 'short' | 'long';
|
|
6
|
+
notional: BN;
|
|
7
|
+
baseSize: BN;
|
|
8
|
+
entryPrice: BN;
|
|
9
|
+
exitPrice: BN;
|
|
10
|
+
liqPrice: BN;
|
|
11
|
+
pnlVsOracle: BN;
|
|
12
|
+
pnlVsMark: BN;
|
|
13
|
+
quoteAssetNotionalAmount: BN;
|
|
14
|
+
quoteEntryAmount: BN;
|
|
15
|
+
quoteBreakEvenAmount: BN;
|
|
16
|
+
unrealizedFundingPnl: BN;
|
|
17
|
+
feesAndFundingPnl: BN;
|
|
18
|
+
lastCumulativeFundingRate: BN;
|
|
19
|
+
openOrders: number;
|
|
20
|
+
/**
|
|
21
|
+
* This is the unsettled pnl that is claimable. Naming is a bit confusing here.
|
|
22
|
+
*/
|
|
23
|
+
unsettledPnl: BN;
|
|
24
|
+
unsettledFundingPnl: BN;
|
|
25
|
+
/**
|
|
26
|
+
* This is the total of unsettled pnl and unsettled funding.
|
|
27
|
+
*/
|
|
28
|
+
totalUnrealizedPnl: BN;
|
|
29
|
+
costBasis: BN;
|
|
30
|
+
realizedPnl: BN;
|
|
31
|
+
lpShares: BN;
|
|
32
|
+
pnlIsClaimable: boolean;
|
|
33
|
+
remainderBaseAmount?: number;
|
|
34
|
+
lpDeriskPrice?: BN;
|
|
35
|
+
};
|
|
36
|
+
export type BankBalanceUI = SpotPosition & {
|
|
37
|
+
accountId: number;
|
|
38
|
+
accountName: string;
|
|
39
|
+
accountAuthority: PublicKey;
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":"","sourcesContent":["import { BN, PublicKey, SpotPosition } from '@drift-labs/sdk';\n\nexport type OpenPosition = {\n\tmarketIndex: number;\n\tmarketSymbol: string;\n\tdirection: 'short' | 'long';\n\tnotional: BN;\n\tbaseSize: BN;\n\tentryPrice: BN;\n\texitPrice: BN;\n\tliqPrice: BN;\n\tpnlVsOracle: BN;\n\tpnlVsMark: BN;\n\tquoteAssetNotionalAmount: BN;\n\tquoteEntryAmount: BN;\n\tquoteBreakEvenAmount: BN;\n\tunrealizedFundingPnl: BN;\n\tfeesAndFundingPnl: BN;\n\tlastCumulativeFundingRate: BN;\n\topenOrders: number;\n\t/**\n\t * This is the unsettled pnl that is claimable. Naming is a bit confusing here.\n\t */\n\tunsettledPnl: BN;\n\tunsettledFundingPnl: BN;\n\t/**\n\t * This is the total of unsettled pnl and unsettled funding.\n\t */\n\ttotalUnrealizedPnl: BN;\n\tcostBasis: BN;\n\trealizedPnl: BN;\n\tlpShares: BN;\n\tpnlIsClaimable: boolean;\n\tremainderBaseAmount?: number; // LP only\n\tlpDeriskPrice?: BN; //LP only\n};\n\nexport type BankBalanceUI = SpotPosition & {\n\taccountId: number;\n\taccountName: string;\n\taccountAuthority: PublicKey;\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a utility type that is used to create opaque types.
|
|
3
|
+
*
|
|
4
|
+
* E.g.
|
|
5
|
+
* ```ts
|
|
6
|
+
* type MyOpaqueType = Opaque<"MyOpaqueType", string>;
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* This will create a type that is a string, but will not allow you to assign any other type to it.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
*/
|
|
13
|
+
export type Opaque<K, T> = T & {
|
|
14
|
+
__TYPE__: K;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * This is a utility type that is used to create opaque types.\n *\n * E.g.\n * ```ts\n * type MyOpaqueType = Opaque<\"MyOpaqueType\", string>;\n * ```\n *\n * This will create a type that is a string, but will not allow you to assign any other type to it.\n *\n * ```ts\n */\nexport type Opaque<K, T> = T & { __TYPE__: K };\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare class Node<T> {
|
|
2
|
+
readonly value: T;
|
|
3
|
+
next: Node<T> | null;
|
|
4
|
+
constructor(value: T, next?: Node<T> | null);
|
|
5
|
+
}
|
|
6
|
+
export declare class CircularBuffer<T> {
|
|
7
|
+
protected _head: Node<T> | null;
|
|
8
|
+
protected _tail: Node<T> | null;
|
|
9
|
+
protected _size: number;
|
|
10
|
+
private readonly _capacity;
|
|
11
|
+
constructor(capacity: number);
|
|
12
|
+
protected get head(): Node<T> | null;
|
|
13
|
+
protected set head(value: Node<T> | null);
|
|
14
|
+
protected get tail(): Node<T> | null;
|
|
15
|
+
protected set tail(value: Node<T> | null);
|
|
16
|
+
get size(): number;
|
|
17
|
+
protected set size(value: number);
|
|
18
|
+
get capacity(): number;
|
|
19
|
+
add(value: T): T | null;
|
|
20
|
+
toArray(): T[];
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircularBuffer = void 0;
|
|
4
|
+
class Node {
|
|
5
|
+
constructor(value, next = null) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
this.next = next;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class CircularBuffer {
|
|
11
|
+
constructor(capacity) {
|
|
12
|
+
this._head = null;
|
|
13
|
+
this._tail = null;
|
|
14
|
+
this._size = 0;
|
|
15
|
+
this._capacity = capacity;
|
|
16
|
+
}
|
|
17
|
+
get head() {
|
|
18
|
+
return this._head;
|
|
19
|
+
}
|
|
20
|
+
set head(value) {
|
|
21
|
+
this._head = value;
|
|
22
|
+
}
|
|
23
|
+
get tail() {
|
|
24
|
+
return this._tail;
|
|
25
|
+
}
|
|
26
|
+
set tail(value) {
|
|
27
|
+
this._tail = value;
|
|
28
|
+
}
|
|
29
|
+
get size() {
|
|
30
|
+
return this._size;
|
|
31
|
+
}
|
|
32
|
+
set size(value) {
|
|
33
|
+
this._size = value;
|
|
34
|
+
}
|
|
35
|
+
get capacity() {
|
|
36
|
+
return this._capacity;
|
|
37
|
+
}
|
|
38
|
+
add(value) {
|
|
39
|
+
const newNode = new Node(value);
|
|
40
|
+
let removedValue = null;
|
|
41
|
+
if (this._size === 0) {
|
|
42
|
+
this._head = this._tail = newNode;
|
|
43
|
+
newNode.next = newNode;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
newNode.next = this._head;
|
|
47
|
+
this._tail.next = newNode;
|
|
48
|
+
this._tail = newNode;
|
|
49
|
+
}
|
|
50
|
+
this._size++;
|
|
51
|
+
if (this._size > this._capacity) {
|
|
52
|
+
removedValue = this._head.value;
|
|
53
|
+
this._head = this._head.next;
|
|
54
|
+
this._tail.next = this._head;
|
|
55
|
+
this._size--;
|
|
56
|
+
}
|
|
57
|
+
return removedValue;
|
|
58
|
+
}
|
|
59
|
+
toArray() {
|
|
60
|
+
if (!this._head)
|
|
61
|
+
return [];
|
|
62
|
+
const result = [];
|
|
63
|
+
let current = this._head;
|
|
64
|
+
do {
|
|
65
|
+
result.push(current.value);
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
+
current = current.next;
|
|
68
|
+
} while (current !== this._head);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.CircularBuffer = CircularBuffer;
|
|
73
|
+
//# sourceMappingURL=CircularBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircularBuffer.js","sourceRoot":"","sources":["../../../src/utils/CircularBuffers/CircularBuffer.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI;IACT,YAA4B,KAAQ,EAAS,OAAuB,IAAI;QAA5C,UAAK,GAAL,KAAK,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAuB;IAAG,CAAC;CAC5E;AAED,MAAa,cAAc;IAM1B,YAAY,QAAgB;QALlB,UAAK,GAAmB,IAAI,CAAC;QAC7B,UAAK,GAAmB,IAAI,CAAC;QAC7B,UAAK,GAAG,CAAC,CAAC;QAInB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAc,IAAI;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,IAAc,IAAI,CAAC,KAAqB;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,IAAc,IAAI;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,IAAc,IAAI,CAAC,KAAqB;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,IAAc,IAAI,CAAC,KAAa;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,GAAG,CAAC,KAAQ;QACX,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,YAAY,GAAa,IAAI,CAAC;QAElC,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;YAClC,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC;QACxB,CAAC;aAAM,CAAC;YACP,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;QACtB,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;QAEb,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACjC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,OAAO;QACN,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,GAAG,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC3B,oEAAoE;YACpE,OAAO,GAAG,OAAO,CAAC,IAAK,CAAC;QACzB,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE;QACjC,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AA1ED,wCA0EC","sourcesContent":["class Node<T> {\n\tconstructor(public readonly value: T, public next: Node<T> | null = null) {}\n}\n\nexport class CircularBuffer<T> {\n\tprotected _head: Node<T> | null = null;\n\tprotected _tail: Node<T> | null = null;\n\tprotected _size = 0;\n\tprivate readonly _capacity: number;\n\n\tconstructor(capacity: number) {\n\t\tthis._capacity = capacity;\n\t}\n\n\tprotected get head(): Node<T> | null {\n\t\treturn this._head;\n\t}\n\n\tprotected set head(value: Node<T> | null) {\n\t\tthis._head = value;\n\t}\n\n\tprotected get tail(): Node<T> | null {\n\t\treturn this._tail;\n\t}\n\n\tprotected set tail(value: Node<T> | null) {\n\t\tthis._tail = value;\n\t}\n\n\tpublic get size(): number {\n\t\treturn this._size;\n\t}\n\n\tprotected set size(value: number) {\n\t\tthis._size = value;\n\t}\n\n\tpublic get capacity(): number {\n\t\treturn this._capacity;\n\t}\n\n\tadd(value: T): T | null {\n\t\tconst newNode = new Node(value);\n\t\tlet removedValue: T | null = null;\n\n\t\tif (this._size === 0) {\n\t\t\tthis._head = this._tail = newNode;\n\t\t\tnewNode.next = newNode;\n\t\t} else {\n\t\t\tnewNode.next = this._head;\n\t\t\tthis._tail.next = newNode;\n\t\t\tthis._tail = newNode;\n\t\t}\n\n\t\tthis._size++;\n\n\t\tif (this._size > this._capacity) {\n\t\t\tremovedValue = this._head.value;\n\t\t\tthis._head = this._head.next;\n\t\t\tthis._tail.next = this._head;\n\t\t\tthis._size--;\n\t\t}\n\n\t\treturn removedValue;\n\t}\n\n\ttoArray(): T[] {\n\t\tif (!this._head) return [];\n\t\tconst result: T[] = [];\n\t\tlet current = this._head;\n\t\tdo {\n\t\t\tresult.push(current.value);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tcurrent = current.next!;\n\t\t} while (current !== this._head);\n\t\treturn result;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CircularBuffer } from './CircularBuffer';
|
|
2
|
+
/**
|
|
3
|
+
* A circular buffer that only allows unique elements based on a key generator function.
|
|
4
|
+
* When adding an element, if its generated key already exists in the buffer, the element
|
|
5
|
+
* is not added and the add operation returns false. When the buffer is full and a new
|
|
6
|
+
* unique element is added, the oldest element is removed to make space.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UniqueCircularBuffer<T> extends CircularBuffer<T> {
|
|
9
|
+
private uniquenessKeyGenerator;
|
|
10
|
+
private uniqueKeys;
|
|
11
|
+
constructor(capacity: number, uniquenessKeyGenerator: (value: T) => string);
|
|
12
|
+
/**
|
|
13
|
+
* Try add an element to the buffer. Returns true if the element was added, false if it was already in the buffer.
|
|
14
|
+
* @param value
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
add(value: T): boolean;
|
|
18
|
+
toArray(): T[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueCircularBuffer = void 0;
|
|
4
|
+
const CircularBuffer_1 = require("./CircularBuffer");
|
|
5
|
+
class Node {
|
|
6
|
+
constructor(value, next = null) {
|
|
7
|
+
this.value = value;
|
|
8
|
+
this.next = next;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A circular buffer that only allows unique elements based on a key generator function.
|
|
13
|
+
* When adding an element, if its generated key already exists in the buffer, the element
|
|
14
|
+
* is not added and the add operation returns false. When the buffer is full and a new
|
|
15
|
+
* unique element is added, the oldest element is removed to make space.
|
|
16
|
+
*/
|
|
17
|
+
class UniqueCircularBuffer extends CircularBuffer_1.CircularBuffer {
|
|
18
|
+
constructor(capacity, uniquenessKeyGenerator) {
|
|
19
|
+
super(capacity);
|
|
20
|
+
this.uniquenessKeyGenerator = uniquenessKeyGenerator;
|
|
21
|
+
this.uniqueKeys = new Set();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Try add an element to the buffer. Returns true if the element was added, false if it was already in the buffer.
|
|
25
|
+
* @param value
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
// @ts-expect-error :: we're reimplementing add from CircularBuffer but with a different interface. This is fine.
|
|
29
|
+
add(value) {
|
|
30
|
+
const key = this.uniquenessKeyGenerator(value);
|
|
31
|
+
if (this.uniqueKeys.has(key)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const newNode = new Node(value);
|
|
35
|
+
if (this.size === 0) {
|
|
36
|
+
// If the buffer is empty, set the head and tail to the new node
|
|
37
|
+
this.tail = newNode;
|
|
38
|
+
this.head = this.tail;
|
|
39
|
+
newNode.next = newNode;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Point the new node to the head
|
|
43
|
+
newNode.next = this.head;
|
|
44
|
+
// Point the current tail to the new node
|
|
45
|
+
this.tail.next = newNode;
|
|
46
|
+
// Update the tail to the new node
|
|
47
|
+
this.tail = newNode;
|
|
48
|
+
}
|
|
49
|
+
this.size++;
|
|
50
|
+
this.uniqueKeys.add(key);
|
|
51
|
+
if (this.size > this.capacity) {
|
|
52
|
+
// If the buffer is full, remove the head
|
|
53
|
+
const nodeToRemove = this.head;
|
|
54
|
+
// Update the head to the element after the head
|
|
55
|
+
this.head = this.head.next;
|
|
56
|
+
// Point the tail to the new head
|
|
57
|
+
this.tail.next = this.head;
|
|
58
|
+
this.size--;
|
|
59
|
+
const removedKey = this.uniquenessKeyGenerator(nodeToRemove.value);
|
|
60
|
+
this.uniqueKeys.delete(removedKey);
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
toArray() {
|
|
65
|
+
if (!this.head)
|
|
66
|
+
return [];
|
|
67
|
+
const result = [];
|
|
68
|
+
let current = this.head;
|
|
69
|
+
do {
|
|
70
|
+
result.push(current.value);
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
72
|
+
current = current.next;
|
|
73
|
+
} while (current !== this.head);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.UniqueCircularBuffer = UniqueCircularBuffer;
|
|
78
|
+
//# sourceMappingURL=UniqueCircularBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniqueCircularBuffer.js","sourceRoot":"","sources":["../../../src/utils/CircularBuffers/UniqueCircularBuffer.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD,MAAM,IAAI;IACT,YAAmB,KAAQ,EAAS,OAAuB,IAAI;QAA5C,UAAK,GAAL,KAAK,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAuB;IAAG,CAAC;CACnE;AAED;;;;;GAKG;AACH,MAAa,oBAAwB,SAAQ,+BAAiB;IAG7D,YACC,QAAgB,EACR,sBAA4C;QAEpD,KAAK,CAAC,QAAQ,CAAC,CAAC;QAFR,2BAAsB,GAAtB,sBAAsB,CAAsB;QAJ7C,eAAU,GAAgB,IAAI,GAAG,EAAE,CAAC;IAO5C,CAAC;IAED;;;;OAIG;IACH,iHAAiH;IACjH,GAAG,CAAC,KAAQ;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAE/C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhC,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,gEAAgE;YAChE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;YACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACtB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC;QACxB,CAAC;aAAM,CAAC;YACP,iCAAiC;YACjC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACzB,yCAAyC;YACzC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;YACzB,kCAAkC;YAClC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACrB,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEzB,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC/B,yCAAyC;YACzC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC;YAC/B,gDAAgD;YAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAC3B,iCAAiC;YACjC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;YAEZ,MAAM,UAAU,GAAG,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACnE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO;QACN,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,GAAG,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC3B,oEAAoE;YACpE,OAAO,GAAG,OAAO,CAAC,IAAK,CAAC;QACzB,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC,IAAI,EAAE;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AArED,oDAqEC","sourcesContent":["import { CircularBuffer } from './CircularBuffer';\n\nclass Node<T> {\n\tconstructor(public value: T, public next: Node<T> | null = null) {}\n}\n\n/**\n * A circular buffer that only allows unique elements based on a key generator function.\n * When adding an element, if its generated key already exists in the buffer, the element\n * is not added and the add operation returns false. When the buffer is full and a new\n * unique element is added, the oldest element is removed to make space.\n */\nexport class UniqueCircularBuffer<T> extends CircularBuffer<T> {\n\tprivate uniqueKeys: Set<string> = new Set();\n\n\tconstructor(\n\t\tcapacity: number,\n\t\tprivate uniquenessKeyGenerator: (value: T) => string\n\t) {\n\t\tsuper(capacity);\n\t}\n\n\t/**\n\t * Try add an element to the buffer. Returns true if the element was added, false if it was already in the buffer.\n\t * @param value\n\t * @returns\n\t */\n\t// @ts-expect-error :: we're reimplementing add from CircularBuffer but with a different interface. This is fine.\n\tadd(value: T): boolean {\n\t\tconst key = this.uniquenessKeyGenerator(value);\n\n\t\tif (this.uniqueKeys.has(key)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst newNode = new Node(value);\n\n\t\tif (this.size === 0) {\n\t\t\t// If the buffer is empty, set the head and tail to the new node\n\t\t\tthis.tail = newNode;\n\t\t\tthis.head = this.tail;\n\t\t\tnewNode.next = newNode;\n\t\t} else {\n\t\t\t// Point the new node to the head\n\t\t\tnewNode.next = this.head;\n\t\t\t// Point the current tail to the new node\n\t\t\tthis.tail.next = newNode;\n\t\t\t// Update the tail to the new node\n\t\t\tthis.tail = newNode;\n\t\t}\n\n\t\tthis.size++;\n\t\tthis.uniqueKeys.add(key);\n\n\t\tif (this.size > this.capacity) {\n\t\t\t// If the buffer is full, remove the head\n\t\t\tconst nodeToRemove = this.head;\n\t\t\t// Update the head to the element after the head\n\t\t\tthis.head = this.head.next;\n\t\t\t// Point the tail to the new head\n\t\t\tthis.tail.next = this.head;\n\t\t\tthis.size--;\n\n\t\t\tconst removedKey = this.uniquenessKeyGenerator(nodeToRemove.value);\n\t\t\tthis.uniqueKeys.delete(removedKey);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\ttoArray(): T[] {\n\t\tif (!this.head) return [];\n\t\tconst result: T[] = [];\n\t\tlet current = this.head;\n\t\tdo {\n\t\t\tresult.push(current.value);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tcurrent = current.next!;\n\t\t} while (current !== this.head);\n\t\treturn result;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CircularBuffer"), exports);
|
|
18
|
+
__exportStar(require("./UniqueCircularBuffer"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/CircularBuffers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,yDAAuC","sourcesContent":["export * from './CircularBuffer';\nexport * from './UniqueCircularBuffer';\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/// <reference types="ws" />
|
|
2
|
+
import { Subject, Subscription } from 'rxjs';
|
|
3
|
+
import WebSocket from 'isomorphic-ws';
|
|
4
|
+
type WebSocketMessage<T = Record<string, unknown>> = T;
|
|
5
|
+
type WebSocketSubscriptionProps<T = Record<string, unknown>> = {
|
|
6
|
+
wsUrl: string;
|
|
7
|
+
subscriptionId: string;
|
|
8
|
+
subscribeMessage: string;
|
|
9
|
+
unsubscribeMessage: string;
|
|
10
|
+
onError: (err?: any) => void;
|
|
11
|
+
onMessage: (message: WebSocketMessage<T>) => void;
|
|
12
|
+
messageFilter: (message: WebSocketMessage<T>) => boolean;
|
|
13
|
+
errorMessageFilter: (message: WebSocketMessage<T>) => boolean;
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
enableHeartbeatMonitoring?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type WebSocketSubscriptionState<T = Record<string, unknown>> = WebSocketSubscriptionProps<T> & {
|
|
18
|
+
hasSentSubscribeMessage?: boolean;
|
|
19
|
+
subjectSubscription?: Subscription;
|
|
20
|
+
};
|
|
21
|
+
type WebSocketUrl = string;
|
|
22
|
+
type SubscriptionId = string;
|
|
23
|
+
declare enum WebSocketConnectionState {
|
|
24
|
+
CONNECTING = 0,
|
|
25
|
+
CONNECTED = 1,
|
|
26
|
+
DISCONNECTING = 2,
|
|
27
|
+
DISCONNECTED = 3
|
|
28
|
+
}
|
|
29
|
+
type IMultiplexWebSocket<T = Record<string, unknown>> = {
|
|
30
|
+
wsUrl: WebSocketUrl;
|
|
31
|
+
webSocket: WebSocket;
|
|
32
|
+
customConnectionState: WebSocketConnectionState;
|
|
33
|
+
subject: Subject<WebSocketMessage<T>>;
|
|
34
|
+
subscriptions: Map<SubscriptionId, Omit<WebSocketSubscriptionProps<T>, 'wsUrl' | 'subscriptionId'>>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* MultiplexWebSocket allows for multiple subscriptions to a single websocket of the same URL, improving efficiency and reducing the number of open connections.
|
|
38
|
+
*
|
|
39
|
+
* This implementation assumes the following:
|
|
40
|
+
* - All websocket streams are treated equally - reconnection attempts are performed at the same standards
|
|
41
|
+
* - All messages returned are in the `WebSocketMessage` format
|
|
42
|
+
* - A single instance of the websocket manager is created for each websocket URL - this means all subscriptions to the same websocket URL will share the same websocket instance
|
|
43
|
+
*
|
|
44
|
+
* Internal implementation details:
|
|
45
|
+
* - The websocket is closed when the number of subscriptions is 0
|
|
46
|
+
* - The websocket will be refreshed (new instance) when it disconnects unexpectedly or errors, until it reaches the maximum number of reconnect attempts
|
|
47
|
+
*/
|
|
48
|
+
export declare class MultiplexWebSocket<T = Record<string, unknown>> implements IMultiplexWebSocket<T> {
|
|
49
|
+
#private;
|
|
50
|
+
/**
|
|
51
|
+
* A lookup of all websockets by their URL.
|
|
52
|
+
*/
|
|
53
|
+
private static URL_TO_WEBSOCKETS_LOOKUP;
|
|
54
|
+
/**
|
|
55
|
+
* A lookup from websocket URL to all subscription IDs for that URL.
|
|
56
|
+
*/
|
|
57
|
+
private static URL_TO_SUBSCRIPTION_IDS_LOOKUP;
|
|
58
|
+
wsUrl: WebSocketUrl;
|
|
59
|
+
customConnectionState: WebSocketConnectionState;
|
|
60
|
+
subject: Subject<WebSocketMessage<T>>;
|
|
61
|
+
subscriptions: Map<SubscriptionId, Omit<WebSocketSubscriptionState<T>, 'wsUrl' | 'subscriptionId'>>;
|
|
62
|
+
private reconnectionManager;
|
|
63
|
+
private closeTimeout;
|
|
64
|
+
private heartbeatTimeout;
|
|
65
|
+
private heartbeatMonitoringEnabled;
|
|
66
|
+
private constructor();
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new virtual websocket subscription. If an existing websocket for the given URL exists, the subscription will be added to the existing websocket.
|
|
69
|
+
* Returns a function that can be called to unsubscribe from the subscription.
|
|
70
|
+
*/
|
|
71
|
+
static createWebSocketSubscription<T = Record<string, unknown>>(props: WebSocketSubscriptionProps<T>): {
|
|
72
|
+
unsubscribe: () => void;
|
|
73
|
+
};
|
|
74
|
+
private static handleNewSubForNewWsUrl;
|
|
75
|
+
private static handleNewSubForExistingWsUrl;
|
|
76
|
+
get webSocket(): WebSocket;
|
|
77
|
+
/**
|
|
78
|
+
* Setting the WebSocket instance will automatically add event handlers to the WebSocket instance.
|
|
79
|
+
* When the WebSocket is connected, all existing subscriptions will be subscribed to.
|
|
80
|
+
*/
|
|
81
|
+
set webSocket(webSocket: WebSocket);
|
|
82
|
+
private subscribeToWebSocket;
|
|
83
|
+
private subscribe;
|
|
84
|
+
private unsubscribe;
|
|
85
|
+
private scheduleDelayedClose;
|
|
86
|
+
private cancelDelayedClose;
|
|
87
|
+
private close;
|
|
88
|
+
private startHeartbeatMonitoring;
|
|
89
|
+
private stopHeartbeatMonitoring;
|
|
90
|
+
private resetHeartbeatTimeout;
|
|
91
|
+
private isHeartbeatMessage;
|
|
92
|
+
private handleHeartbeat;
|
|
93
|
+
private refreshWebSocket;
|
|
94
|
+
}
|
|
95
|
+
export {};
|