@drift-labs/sdk-browser 2.104.0-beta.21
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/README.md +276 -0
- package/VERSION +1 -0
- package/bun.lockb +0 -0
- package/get_events.ts +47 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.js +38 -0
- package/lib/browser/accounts/bulkAccountLoader.d.ts +37 -0
- package/lib/browser/accounts/bulkAccountLoader.js +222 -0
- package/lib/browser/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/browser/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/browser/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/browser/accounts/bulkUserSubscription.js +21 -0
- package/lib/browser/accounts/fetch.d.ts +6 -0
- package/lib/browser/accounts/fetch.js +30 -0
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/browser/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +98 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.js +48 -0
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +418 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.js +78 -0
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/browser/accounts/pollingTokenAccountSubscriber.js +78 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +102 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +94 -0
- package/lib/browser/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/browser/accounts/testBulkAccountLoader.js +45 -0
- package/lib/browser/accounts/types.d.ts +168 -0
- package/lib/browser/accounts/types.js +16 -0
- package/lib/browser/accounts/utils.d.ts +8 -0
- package/lib/browser/accounts/utils.js +49 -0
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/webSocketAccountSubscriber.js +149 -0
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +120 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.js +61 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
- package/lib/browser/addresses/marketAddresses.d.ts +2 -0
- package/lib/browser/addresses/marketAddresses.js +15 -0
- package/lib/browser/addresses/pda.d.ts +32 -0
- package/lib/browser/addresses/pda.js +211 -0
- package/lib/browser/adminClient.d.ts +206 -0
- package/lib/browser/adminClient.js +1858 -0
- package/lib/browser/assert/assert.d.ts +1 -0
- package/lib/browser/assert/assert.js +9 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +14 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +32 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/browser/auctionSubscriber/index.d.ts +3 -0
- package/lib/browser/auctionSubscriber/index.js +19 -0
- package/lib/browser/auctionSubscriber/types.d.ts +14 -0
- package/lib/browser/auctionSubscriber/types.js +2 -0
- package/lib/browser/bankrun/bankrunConnection.d.ts +75 -0
- package/lib/browser/bankrun/bankrunConnection.js +332 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +89 -0
- package/lib/browser/blockhashSubscriber/index.d.ts +1 -0
- package/lib/browser/blockhashSubscriber/index.js +17 -0
- package/lib/browser/blockhashSubscriber/types.d.ts +7 -0
- package/lib/browser/blockhashSubscriber/types.js +2 -0
- package/lib/browser/clock/clockSubscriber.d.ts +31 -0
- package/lib/browser/clock/clockSubscriber.js +80 -0
- package/lib/browser/config.d.ts +60 -0
- package/lib/browser/config.js +130 -0
- package/lib/browser/constants/numericConstants.d.ts +71 -0
- package/lib/browser/constants/numericConstants.js +75 -0
- package/lib/browser/constants/perpMarkets.d.ts +19 -0
- package/lib/browser/constants/perpMarkets.js +997 -0
- package/lib/browser/constants/spotMarkets.d.ts +24 -0
- package/lib/browser/constants/spotMarkets.js +470 -0
- package/lib/browser/constants/txConstants.d.ts +1 -0
- package/lib/browser/constants/txConstants.js +4 -0
- package/lib/browser/decode/phoenix.d.ts +7 -0
- package/lib/browser/decode/phoenix.js +159 -0
- package/lib/browser/decode/user.d.ts +4 -0
- package/lib/browser/decode/user.js +339 -0
- package/lib/browser/dlob/DLOB.d.ts +186 -0
- package/lib/browser/dlob/DLOB.js +1039 -0
- package/lib/browser/dlob/DLOBNode.d.ts +68 -0
- package/lib/browser/dlob/DLOBNode.js +100 -0
- package/lib/browser/dlob/DLOBSubscriber.d.ts +54 -0
- package/lib/browser/dlob/DLOBSubscriber.js +139 -0
- package/lib/browser/dlob/NodeList.d.ts +25 -0
- package/lib/browser/dlob/NodeList.js +126 -0
- package/lib/browser/dlob/orderBookLevels.d.ts +72 -0
- package/lib/browser/dlob/orderBookLevels.js +438 -0
- package/lib/browser/dlob/types.d.ts +18 -0
- package/lib/browser/dlob/types.js +2 -0
- package/lib/browser/driftClient.d.ts +861 -0
- package/lib/browser/driftClient.js +4768 -0
- package/lib/browser/driftClientConfig.d.ts +49 -0
- package/lib/browser/driftClientConfig.js +2 -0
- package/lib/browser/events/eventList.d.ts +22 -0
- package/lib/browser/events/eventList.js +80 -0
- package/lib/browser/events/eventSubscriber.d.ts +46 -0
- package/lib/browser/events/eventSubscriber.js +223 -0
- package/lib/browser/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/browser/events/eventsServerLogProvider.js +121 -0
- package/lib/browser/events/fetchLogs.d.ts +25 -0
- package/lib/browser/events/fetchLogs.js +99 -0
- package/lib/browser/events/parse.d.ts +6 -0
- package/lib/browser/events/parse.js +106 -0
- package/lib/browser/events/pollingLogProvider.d.ts +17 -0
- package/lib/browser/events/pollingLogProvider.js +58 -0
- package/lib/browser/events/sort.d.ts +2 -0
- package/lib/browser/events/sort.js +24 -0
- package/lib/browser/events/txEventCache.d.ts +24 -0
- package/lib/browser/events/txEventCache.js +71 -0
- package/lib/browser/events/types.d.ts +79 -0
- package/lib/browser/events/types.js +32 -0
- package/lib/browser/events/webSocketLogProvider.d.ts +24 -0
- package/lib/browser/events/webSocketLogProvider.js +96 -0
- package/lib/browser/factory/bigNum.d.ts +122 -0
- package/lib/browser/factory/bigNum.js +457 -0
- package/lib/browser/factory/oracleClient.d.ts +5 -0
- package/lib/browser/factory/oracleClient.js +56 -0
- package/lib/browser/idl/drift.json +14440 -0
- package/lib/browser/idl/openbook.json +3854 -0
- package/lib/browser/idl/pyth_solana_receiver.json +628 -0
- package/lib/browser/idl/switchboard.json +8354 -0
- package/lib/browser/idl/switchboard_on_demand_30.json +4546 -0
- package/lib/browser/idl/token_faucet.json +142 -0
- package/lib/browser/index.d.ts +125 -0
- package/lib/browser/index.js +147 -0
- package/lib/browser/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.browser.js +8 -0
- package/lib/browser/isomorphic/grpc.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.js +8 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +302 -0
- package/lib/browser/jupiter/jupiterClient.js +178 -0
- package/lib/browser/keypair.d.ts +2 -0
- package/lib/browser/keypair.js +28 -0
- package/lib/browser/marinade/index.d.ts +12 -0
- package/lib/browser/marinade/index.js +36 -0
- package/lib/browser/marinade/types.d.ts +1963 -0
- package/lib/browser/marinade/types.js +1965 -0
- package/lib/browser/math/amm.d.ts +98 -0
- package/lib/browser/math/amm.js +626 -0
- package/lib/browser/math/auction.d.ts +23 -0
- package/lib/browser/math/auction.js +130 -0
- package/lib/browser/math/bankruptcy.d.ts +2 -0
- package/lib/browser/math/bankruptcy.js +31 -0
- package/lib/browser/math/conversion.d.ts +2 -0
- package/lib/browser/math/conversion.js +11 -0
- package/lib/browser/math/exchangeStatus.d.ts +6 -0
- package/lib/browser/math/exchangeStatus.js +77 -0
- package/lib/browser/math/fuel.d.ts +6 -0
- package/lib/browser/math/fuel.js +55 -0
- package/lib/browser/math/funding.d.ts +34 -0
- package/lib/browser/math/funding.js +209 -0
- package/lib/browser/math/insurance.d.ts +7 -0
- package/lib/browser/math/insurance.js +73 -0
- package/lib/browser/math/margin.d.ts +39 -0
- package/lib/browser/math/margin.js +184 -0
- package/lib/browser/math/market.d.ts +39 -0
- package/lib/browser/math/market.js +163 -0
- package/lib/browser/math/oracles.d.ts +14 -0
- package/lib/browser/math/oracles.js +134 -0
- package/lib/browser/math/orders.d.ts +23 -0
- package/lib/browser/math/orders.js +216 -0
- package/lib/browser/math/position.d.ts +70 -0
- package/lib/browser/math/position.js +225 -0
- package/lib/browser/math/repeg.d.ts +22 -0
- package/lib/browser/math/repeg.js +164 -0
- package/lib/browser/math/spotBalance.d.ts +83 -0
- package/lib/browser/math/spotBalance.js +373 -0
- package/lib/browser/math/spotMarket.d.ts +11 -0
- package/lib/browser/math/spotMarket.js +49 -0
- package/lib/browser/math/spotPosition.d.ts +19 -0
- package/lib/browser/math/spotPosition.js +78 -0
- package/lib/browser/math/state.d.ts +5 -0
- package/lib/browser/math/state.js +30 -0
- package/lib/browser/math/superStake.d.ts +167 -0
- package/lib/browser/math/superStake.js +306 -0
- package/lib/browser/math/tiers.d.ts +4 -0
- package/lib/browser/math/tiers.js +52 -0
- package/lib/browser/math/trade.d.ts +117 -0
- package/lib/browser/math/trade.js +637 -0
- package/lib/browser/math/userStatus.d.ts +2 -0
- package/lib/browser/math/userStatus.js +8 -0
- package/lib/browser/math/utils.d.ts +23 -0
- package/lib/browser/math/utils.js +112 -0
- package/lib/browser/memcmp.d.ts +11 -0
- package/lib/browser/memcmp.js +99 -0
- package/lib/browser/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/browser/openbook/openbookV2Subscriber.js +104 -0
- package/lib/browser/oracles/oracleClientCache.d.ts +9 -0
- package/lib/browser/oracles/oracleClientCache.js +19 -0
- package/lib/browser/oracles/oracleId.d.ts +4 -0
- package/lib/browser/oracles/oracleId.js +38 -0
- package/lib/browser/oracles/prelaunchOracleClient.d.ts +12 -0
- package/lib/browser/oracles/prelaunchOracleClient.js +24 -0
- package/lib/browser/oracles/pythClient.d.ts +14 -0
- package/lib/browser/oracles/pythClient.js +51 -0
- package/lib/browser/oracles/pythLazerClient.d.ts +16 -0
- package/lib/browser/oracles/pythLazerClient.js +61 -0
- package/lib/browser/oracles/pythPullClient.d.ts +19 -0
- package/lib/browser/oracles/pythPullClient.js +60 -0
- package/lib/browser/oracles/quoteAssetOracleClient.d.ts +10 -0
- package/lib/browser/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/browser/oracles/strictOraclePrice.d.ts +9 -0
- package/lib/browser/oracles/strictOraclePrice.js +17 -0
- package/lib/browser/oracles/switchboardClient.d.ts +12 -0
- package/lib/browser/oracles/switchboardClient.js +40 -0
- package/lib/browser/oracles/switchboardOnDemandClient.d.ts +12 -0
- package/lib/browser/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/browser/oracles/types.d.ts +23 -0
- package/lib/browser/oracles/types.js +2 -0
- package/lib/browser/orderParams.d.ts +29 -0
- package/lib/browser/orderParams.js +44 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +42 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.js +172 -0
- package/lib/browser/orderSubscriber/PollingSubscription.d.ts +12 -0
- package/lib/browser/orderSubscriber/PollingSubscription.js +23 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.d.ts +23 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +67 -0
- package/lib/browser/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/browser/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/browser/orderSubscriber/index.d.ts +2 -0
- package/lib/browser/orderSubscriber/index.js +18 -0
- package/lib/browser/orderSubscriber/types.d.ts +34 -0
- package/lib/browser/orderSubscriber/types.js +2 -0
- package/lib/browser/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/browser/phoenix/phoenixSubscriber.d.ts +41 -0
- package/lib/browser/phoenix/phoenixSubscriber.js +152 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.js +16 -0
- package/lib/browser/priorityFee/averageStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/averageStrategy.js +11 -0
- package/lib/browser/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
- package/lib/browser/priorityFee/driftPriorityFeeMethod.js +26 -0
- package/lib/browser/priorityFee/ewmaStrategy.d.ts +11 -0
- package/lib/browser/priorityFee/ewmaStrategy.js +33 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.js +46 -0
- package/lib/browser/priorityFee/index.d.ts +11 -0
- package/lib/browser/priorityFee/index.js +27 -0
- package/lib/browser/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/maxOverSlotsStrategy.js +17 -0
- package/lib/browser/priorityFee/maxStrategy.d.ts +7 -0
- package/lib/browser/priorityFee/maxStrategy.js +9 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +46 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +188 -0
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.js +21 -0
- package/lib/browser/priorityFee/types.d.ts +31 -0
- package/lib/browser/priorityFee/types.js +10 -0
- package/lib/browser/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/browser/serum/serumSubscriber.d.ts +32 -0
- package/lib/browser/serum/serumSubscriber.js +107 -0
- package/lib/browser/serum/types.d.ts +13 -0
- package/lib/browser/serum/types.js +2 -0
- package/lib/browser/slot/SlotSubscriber.d.ts +27 -0
- package/lib/browser/slot/SlotSubscriber.js +71 -0
- package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/browser/slot/SlothashSubscriber.js +85 -0
- package/lib/browser/testClient.d.ts +8 -0
- package/lib/browser/testClient.js +23 -0
- package/lib/browser/token/index.d.ts +5 -0
- package/lib/browser/token/index.js +15 -0
- package/lib/browser/tokenFaucet.d.ts +41 -0
- package/lib/browser/tokenFaucet.js +188 -0
- package/lib/browser/tx/baseTxSender.d.ts +59 -0
- package/lib/browser/tx/baseTxSender.js +294 -0
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
- package/lib/browser/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/browser/tx/blockhashFetcher/types.js +2 -0
- package/lib/browser/tx/fastSingleTxSender.d.ts +41 -0
- package/lib/browser/tx/fastSingleTxSender.js +86 -0
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +37 -0
- package/lib/browser/tx/forwardOnlyTxSender.js +92 -0
- package/lib/browser/tx/priorityFeeCalculator.d.ts +44 -0
- package/lib/browser/tx/priorityFeeCalculator.js +85 -0
- package/lib/browser/tx/reportTransactionError.d.ts +20 -0
- package/lib/browser/tx/reportTransactionError.js +103 -0
- package/lib/browser/tx/retryTxSender.d.ts +37 -0
- package/lib/browser/tx/retryTxSender.js +86 -0
- package/lib/browser/tx/txHandler.d.ts +154 -0
- package/lib/browser/tx/txHandler.js +453 -0
- package/lib/browser/tx/txParamProcessor.d.ts +25 -0
- package/lib/browser/tx/txParamProcessor.js +88 -0
- package/lib/browser/tx/types.d.ts +29 -0
- package/lib/browser/tx/types.js +20 -0
- package/lib/browser/tx/utils.d.ts +2 -0
- package/lib/browser/tx/utils.js +10 -0
- package/lib/browser/tx/whileValidTxSender.d.ts +45 -0
- package/lib/browser/tx/whileValidTxSender.js +167 -0
- package/lib/browser/types.d.ts +1385 -0
- package/lib/browser/types.js +366 -0
- package/lib/browser/user.d.ts +411 -0
- package/lib/browser/user.js +2151 -0
- package/lib/browser/userConfig.d.ts +26 -0
- package/lib/browser/userConfig.js +2 -0
- package/lib/browser/userMap/PollingSubscription.d.ts +16 -0
- package/lib/browser/userMap/PollingSubscription.js +30 -0
- package/lib/browser/userMap/WebsocketSubscription.d.ts +27 -0
- package/lib/browser/userMap/WebsocketSubscription.js +45 -0
- package/lib/browser/userMap/grpcSubscription.d.ts +27 -0
- package/lib/browser/userMap/grpcSubscription.js +44 -0
- package/lib/browser/userMap/referrerMap.d.ts +45 -0
- package/lib/browser/userMap/referrerMap.js +181 -0
- package/lib/browser/userMap/userMap.d.ts +90 -0
- package/lib/browser/userMap/userMap.js +467 -0
- package/lib/browser/userMap/userMapConfig.d.ts +39 -0
- package/lib/browser/userMap/userMapConfig.js +2 -0
- package/lib/browser/userMap/userStatsMap.d.ts +46 -0
- package/lib/browser/userMap/userStatsMap.js +165 -0
- package/lib/browser/userName.d.ts +5 -0
- package/lib/browser/userName.js +21 -0
- package/lib/browser/userStats.d.ts +22 -0
- package/lib/browser/userStats.js +91 -0
- package/lib/browser/userStatsConfig.d.ts +25 -0
- package/lib/browser/userStatsConfig.js +2 -0
- package/lib/browser/util/TransactionConfirmationManager.d.ts +16 -0
- package/lib/browser/util/TransactionConfirmationManager.js +174 -0
- package/lib/browser/util/chainClock.d.ts +17 -0
- package/lib/browser/util/chainClock.js +29 -0
- package/lib/browser/util/computeUnits.d.ts +8 -0
- package/lib/browser/util/computeUnits.js +48 -0
- package/lib/browser/util/digest.d.ts +4 -0
- package/lib/browser/util/digest.js +14 -0
- package/lib/browser/util/promiseTimeout.d.ts +1 -0
- package/lib/browser/util/promiseTimeout.js +14 -0
- package/lib/browser/util/pythOracleUtils.d.ts +17 -0
- package/lib/browser/util/pythOracleUtils.js +107 -0
- package/lib/browser/util/tps.d.ts +2 -0
- package/lib/browser/util/tps.js +16 -0
- package/lib/browser/wallet.d.ts +11 -0
- package/lib/browser/wallet.js +32 -0
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/basicUserAccountSubscriber.js +38 -0
- package/lib/node/accounts/bulkAccountLoader.d.ts +37 -0
- package/lib/node/accounts/bulkAccountLoader.js +222 -0
- package/lib/node/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/node/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserSubscription.js +21 -0
- package/lib/node/accounts/fetch.d.ts +6 -0
- package/lib/node/accounts/fetch.js +30 -0
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/node/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +98 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +48 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +418 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.js +102 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +94 -0
- package/lib/node/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/node/accounts/testBulkAccountLoader.js +45 -0
- package/lib/node/accounts/types.d.ts +168 -0
- package/lib/node/accounts/types.js +16 -0
- package/lib/node/accounts/utils.d.ts +8 -0
- package/lib/node/accounts/utils.js +49 -0
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/webSocketAccountSubscriber.js +149 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +120 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +61 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
- package/lib/node/addresses/marketAddresses.d.ts +2 -0
- package/lib/node/addresses/marketAddresses.js +15 -0
- package/lib/node/addresses/pda.d.ts +32 -0
- package/lib/node/addresses/pda.js +211 -0
- package/lib/node/adminClient.d.ts +206 -0
- package/lib/node/adminClient.js +1858 -0
- package/lib/node/assert/assert.d.ts +1 -0
- package/lib/node/assert/assert.js +9 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +14 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.js +32 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/node/auctionSubscriber/index.d.ts +3 -0
- package/lib/node/auctionSubscriber/index.js +19 -0
- package/lib/node/auctionSubscriber/types.d.ts +14 -0
- package/lib/node/auctionSubscriber/types.js +2 -0
- package/lib/node/bankrun/bankrunConnection.d.ts +75 -0
- package/lib/node/bankrun/bankrunConnection.js +332 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +89 -0
- package/lib/node/blockhashSubscriber/index.d.ts +1 -0
- package/lib/node/blockhashSubscriber/index.js +17 -0
- package/lib/node/blockhashSubscriber/types.d.ts +7 -0
- package/lib/node/blockhashSubscriber/types.js +2 -0
- package/lib/node/clock/clockSubscriber.d.ts +31 -0
- package/lib/node/clock/clockSubscriber.js +80 -0
- package/lib/node/config.d.ts +60 -0
- package/lib/node/config.js +130 -0
- package/lib/node/constants/numericConstants.d.ts +71 -0
- package/lib/node/constants/numericConstants.js +75 -0
- package/lib/node/constants/perpMarkets.d.ts +19 -0
- package/lib/node/constants/perpMarkets.js +997 -0
- package/lib/node/constants/spotMarkets.d.ts +24 -0
- package/lib/node/constants/spotMarkets.js +470 -0
- package/lib/node/constants/txConstants.d.ts +1 -0
- package/lib/node/constants/txConstants.js +4 -0
- package/lib/node/decode/phoenix.d.ts +7 -0
- package/lib/node/decode/phoenix.js +159 -0
- package/lib/node/decode/user.d.ts +4 -0
- package/lib/node/decode/user.js +339 -0
- package/lib/node/dlob/DLOB.d.ts +186 -0
- package/lib/node/dlob/DLOB.js +1039 -0
- package/lib/node/dlob/DLOBNode.d.ts +68 -0
- package/lib/node/dlob/DLOBNode.js +100 -0
- package/lib/node/dlob/DLOBSubscriber.d.ts +54 -0
- package/lib/node/dlob/DLOBSubscriber.js +139 -0
- package/lib/node/dlob/NodeList.d.ts +25 -0
- package/lib/node/dlob/NodeList.js +126 -0
- package/lib/node/dlob/orderBookLevels.d.ts +72 -0
- package/lib/node/dlob/orderBookLevels.js +438 -0
- package/lib/node/dlob/types.d.ts +18 -0
- package/lib/node/dlob/types.js +2 -0
- package/lib/node/driftClient.d.ts +861 -0
- package/lib/node/driftClient.js +4768 -0
- package/lib/node/driftClientConfig.d.ts +49 -0
- package/lib/node/driftClientConfig.js +2 -0
- package/lib/node/events/eventList.d.ts +22 -0
- package/lib/node/events/eventList.js +80 -0
- package/lib/node/events/eventSubscriber.d.ts +46 -0
- package/lib/node/events/eventSubscriber.js +223 -0
- package/lib/node/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/node/events/eventsServerLogProvider.js +121 -0
- package/lib/node/events/fetchLogs.d.ts +25 -0
- package/lib/node/events/fetchLogs.js +99 -0
- package/lib/node/events/parse.d.ts +6 -0
- package/lib/node/events/parse.js +106 -0
- package/lib/node/events/pollingLogProvider.d.ts +17 -0
- package/lib/node/events/pollingLogProvider.js +58 -0
- package/lib/node/events/sort.d.ts +2 -0
- package/lib/node/events/sort.js +24 -0
- package/lib/node/events/txEventCache.d.ts +24 -0
- package/lib/node/events/txEventCache.js +71 -0
- package/lib/node/events/types.d.ts +79 -0
- package/lib/node/events/types.js +32 -0
- package/lib/node/events/webSocketLogProvider.d.ts +24 -0
- package/lib/node/events/webSocketLogProvider.js +96 -0
- package/lib/node/factory/bigNum.d.ts +122 -0
- package/lib/node/factory/bigNum.js +457 -0
- package/lib/node/factory/oracleClient.d.ts +5 -0
- package/lib/node/factory/oracleClient.js +56 -0
- package/lib/node/idl/drift.json +14440 -0
- package/lib/node/idl/openbook.json +3854 -0
- package/lib/node/idl/pyth_solana_receiver.json +628 -0
- package/lib/node/idl/switchboard.json +8354 -0
- package/lib/node/idl/switchboard_on_demand_30.json +4546 -0
- package/lib/node/idl/token_faucet.json +142 -0
- package/lib/node/index.d.ts +125 -0
- package/lib/node/index.js +147 -0
- package/lib/node/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/node/isomorphic/grpc.browser.js +8 -0
- package/lib/node/isomorphic/grpc.d.ts +1 -0
- package/lib/node/isomorphic/grpc.js +8 -0
- package/lib/node/jupiter/jupiterClient.d.ts +302 -0
- package/lib/node/jupiter/jupiterClient.js +178 -0
- package/lib/node/keypair.d.ts +2 -0
- package/lib/node/keypair.js +28 -0
- package/lib/node/marinade/index.d.ts +12 -0
- package/lib/node/marinade/index.js +36 -0
- package/lib/node/marinade/types.d.ts +1963 -0
- package/lib/node/marinade/types.js +1965 -0
- package/lib/node/math/amm.d.ts +98 -0
- package/lib/node/math/amm.js +626 -0
- package/lib/node/math/auction.d.ts +23 -0
- package/lib/node/math/auction.js +130 -0
- package/lib/node/math/bankruptcy.d.ts +2 -0
- package/lib/node/math/bankruptcy.js +31 -0
- package/lib/node/math/conversion.d.ts +2 -0
- package/lib/node/math/conversion.js +11 -0
- package/lib/node/math/exchangeStatus.d.ts +6 -0
- package/lib/node/math/exchangeStatus.js +77 -0
- package/lib/node/math/fuel.d.ts +6 -0
- package/lib/node/math/fuel.js +55 -0
- package/lib/node/math/funding.d.ts +34 -0
- package/lib/node/math/funding.js +209 -0
- package/lib/node/math/insurance.d.ts +7 -0
- package/lib/node/math/insurance.js +73 -0
- package/lib/node/math/margin.d.ts +39 -0
- package/lib/node/math/margin.js +184 -0
- package/lib/node/math/market.d.ts +39 -0
- package/lib/node/math/market.js +163 -0
- package/lib/node/math/oracles.d.ts +14 -0
- package/lib/node/math/oracles.js +134 -0
- package/lib/node/math/orders.d.ts +23 -0
- package/lib/node/math/orders.js +216 -0
- package/lib/node/math/position.d.ts +70 -0
- package/lib/node/math/position.js +225 -0
- package/lib/node/math/repeg.d.ts +22 -0
- package/lib/node/math/repeg.js +164 -0
- package/lib/node/math/spotBalance.d.ts +83 -0
- package/lib/node/math/spotBalance.js +373 -0
- package/lib/node/math/spotMarket.d.ts +11 -0
- package/lib/node/math/spotMarket.js +49 -0
- package/lib/node/math/spotPosition.d.ts +19 -0
- package/lib/node/math/spotPosition.js +78 -0
- package/lib/node/math/state.d.ts +5 -0
- package/lib/node/math/state.js +30 -0
- package/lib/node/math/superStake.d.ts +167 -0
- package/lib/node/math/superStake.js +306 -0
- package/lib/node/math/tiers.d.ts +4 -0
- package/lib/node/math/tiers.js +52 -0
- package/lib/node/math/trade.d.ts +117 -0
- package/lib/node/math/trade.js +637 -0
- package/lib/node/math/userStatus.d.ts +2 -0
- package/lib/node/math/userStatus.js +8 -0
- package/lib/node/math/utils.d.ts +23 -0
- package/lib/node/math/utils.js +112 -0
- package/lib/node/memcmp.d.ts +11 -0
- package/lib/node/memcmp.js +99 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/node/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/node/openbook/openbookV2Subscriber.js +104 -0
- package/lib/node/oracles/oracleClientCache.d.ts +9 -0
- package/lib/node/oracles/oracleClientCache.js +19 -0
- package/lib/node/oracles/oracleId.d.ts +4 -0
- package/lib/node/oracles/oracleId.js +38 -0
- package/lib/node/oracles/prelaunchOracleClient.d.ts +12 -0
- package/lib/node/oracles/prelaunchOracleClient.js +24 -0
- package/lib/node/oracles/pythClient.d.ts +14 -0
- package/lib/node/oracles/pythClient.js +51 -0
- package/lib/node/oracles/pythLazerClient.d.ts +16 -0
- package/lib/node/oracles/pythLazerClient.js +61 -0
- package/lib/node/oracles/pythPullClient.d.ts +19 -0
- package/lib/node/oracles/pythPullClient.js +60 -0
- package/lib/node/oracles/quoteAssetOracleClient.d.ts +10 -0
- package/lib/node/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/node/oracles/strictOraclePrice.d.ts +9 -0
- package/lib/node/oracles/strictOraclePrice.js +17 -0
- package/lib/node/oracles/switchboardClient.d.ts +12 -0
- package/lib/node/oracles/switchboardClient.js +40 -0
- package/lib/node/oracles/switchboardOnDemandClient.d.ts +12 -0
- package/lib/node/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/node/oracles/types.d.ts +23 -0
- package/lib/node/oracles/types.js +2 -0
- package/lib/node/orderParams.d.ts +29 -0
- package/lib/node/orderParams.js +44 -0
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +42 -0
- package/lib/node/orderSubscriber/OrderSubscriber.js +172 -0
- package/lib/node/orderSubscriber/PollingSubscription.d.ts +12 -0
- package/lib/node/orderSubscriber/PollingSubscription.js +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.js +67 -0
- package/lib/node/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/node/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/node/orderSubscriber/index.d.ts +2 -0
- package/lib/node/orderSubscriber/index.js +18 -0
- package/lib/node/orderSubscriber/types.d.ts +34 -0
- package/lib/node/orderSubscriber/types.js +2 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/node/phoenix/phoenixSubscriber.d.ts +41 -0
- package/lib/node/phoenix/phoenixSubscriber.js +152 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.js +16 -0
- package/lib/node/priorityFee/averageStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageStrategy.js +11 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.js +26 -0
- package/lib/node/priorityFee/ewmaStrategy.d.ts +11 -0
- package/lib/node/priorityFee/ewmaStrategy.js +33 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.js +46 -0
- package/lib/node/priorityFee/index.d.ts +11 -0
- package/lib/node/priorityFee/index.js +27 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.js +17 -0
- package/lib/node/priorityFee/maxStrategy.d.ts +7 -0
- package/lib/node/priorityFee/maxStrategy.js +9 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +46 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.js +188 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.js +21 -0
- package/lib/node/priorityFee/types.d.ts +31 -0
- package/lib/node/priorityFee/types.js +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/node/serum/serumSubscriber.d.ts +32 -0
- package/lib/node/serum/serumSubscriber.js +107 -0
- package/lib/node/serum/types.d.ts +13 -0
- package/lib/node/serum/types.js +2 -0
- package/lib/node/slot/SlotSubscriber.d.ts +27 -0
- package/lib/node/slot/SlotSubscriber.js +71 -0
- package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/node/slot/SlothashSubscriber.js +85 -0
- package/lib/node/testClient.d.ts +8 -0
- package/lib/node/testClient.js +23 -0
- package/lib/node/token/index.d.ts +5 -0
- package/lib/node/token/index.js +15 -0
- package/lib/node/tokenFaucet.d.ts +41 -0
- package/lib/node/tokenFaucet.js +188 -0
- package/lib/node/tx/baseTxSender.d.ts +59 -0
- package/lib/node/tx/baseTxSender.js +294 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
- package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/node/tx/blockhashFetcher/types.js +2 -0
- package/lib/node/tx/fastSingleTxSender.d.ts +41 -0
- package/lib/node/tx/fastSingleTxSender.js +86 -0
- package/lib/node/tx/forwardOnlyTxSender.d.ts +37 -0
- package/lib/node/tx/forwardOnlyTxSender.js +92 -0
- package/lib/node/tx/priorityFeeCalculator.d.ts +44 -0
- package/lib/node/tx/priorityFeeCalculator.js +85 -0
- package/lib/node/tx/reportTransactionError.d.ts +20 -0
- package/lib/node/tx/reportTransactionError.js +103 -0
- package/lib/node/tx/retryTxSender.d.ts +37 -0
- package/lib/node/tx/retryTxSender.js +86 -0
- package/lib/node/tx/txHandler.d.ts +154 -0
- package/lib/node/tx/txHandler.js +453 -0
- package/lib/node/tx/txParamProcessor.d.ts +25 -0
- package/lib/node/tx/txParamProcessor.js +88 -0
- package/lib/node/tx/types.d.ts +29 -0
- package/lib/node/tx/types.js +20 -0
- package/lib/node/tx/utils.d.ts +2 -0
- package/lib/node/tx/utils.js +10 -0
- package/lib/node/tx/whileValidTxSender.d.ts +45 -0
- package/lib/node/tx/whileValidTxSender.js +167 -0
- package/lib/node/types.d.ts +1385 -0
- package/lib/node/types.js +366 -0
- package/lib/node/user.d.ts +411 -0
- package/lib/node/user.js +2151 -0
- package/lib/node/userConfig.d.ts +26 -0
- package/lib/node/userConfig.js +2 -0
- package/lib/node/userMap/PollingSubscription.d.ts +16 -0
- package/lib/node/userMap/PollingSubscription.js +30 -0
- package/lib/node/userMap/WebsocketSubscription.d.ts +27 -0
- package/lib/node/userMap/WebsocketSubscription.js +45 -0
- package/lib/node/userMap/grpcSubscription.d.ts +27 -0
- package/lib/node/userMap/grpcSubscription.js +44 -0
- package/lib/node/userMap/referrerMap.d.ts +45 -0
- package/lib/node/userMap/referrerMap.js +181 -0
- package/lib/node/userMap/userMap.d.ts +90 -0
- package/lib/node/userMap/userMap.js +467 -0
- package/lib/node/userMap/userMapConfig.d.ts +39 -0
- package/lib/node/userMap/userMapConfig.js +2 -0
- package/lib/node/userMap/userStatsMap.d.ts +46 -0
- package/lib/node/userMap/userStatsMap.js +165 -0
- package/lib/node/userName.d.ts +5 -0
- package/lib/node/userName.js +21 -0
- package/lib/node/userStats.d.ts +22 -0
- package/lib/node/userStats.js +91 -0
- package/lib/node/userStatsConfig.d.ts +25 -0
- package/lib/node/userStatsConfig.js +2 -0
- package/lib/node/util/TransactionConfirmationManager.d.ts +16 -0
- package/lib/node/util/TransactionConfirmationManager.js +174 -0
- package/lib/node/util/chainClock.d.ts +17 -0
- package/lib/node/util/chainClock.js +29 -0
- package/lib/node/util/computeUnits.d.ts +8 -0
- package/lib/node/util/computeUnits.js +48 -0
- package/lib/node/util/digest.d.ts +4 -0
- package/lib/node/util/digest.js +14 -0
- package/lib/node/util/promiseTimeout.d.ts +1 -0
- package/lib/node/util/promiseTimeout.js +14 -0
- package/lib/node/util/pythOracleUtils.d.ts +17 -0
- package/lib/node/util/pythOracleUtils.js +107 -0
- package/lib/node/util/tps.d.ts +2 -0
- package/lib/node/util/tps.js +16 -0
- package/lib/node/wallet.d.ts +11 -0
- package/lib/node/wallet.js +32 -0
- package/package.json +92 -0
- package/scripts/postbuild.js +95 -0
- package/scripts/updateVersion.js +28 -0
- package/src/accounts/basicUserAccountSubscriber.ts +59 -0
- package/src/accounts/bulkAccountLoader.ts +294 -0
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +33 -0
- package/src/accounts/fetch.ts +66 -0
- package/src/accounts/grpcAccountSubscriber.ts +160 -0
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +203 -0
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +56 -0
- package/src/accounts/grpcProgramAccountSubscriber.ts +190 -0
- package/src/accounts/grpcUserAccountSubscriber.ts +48 -0
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +50 -0
- package/src/accounts/oneShotUserAccountSubscriber.ts +68 -0
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +644 -0
- package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +185 -0
- package/src/accounts/pollingOracleAccountSubscriber.ts +125 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +118 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +160 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +156 -0
- package/src/accounts/testBulkAccountLoader.ts +53 -0
- package/src/accounts/types.ts +245 -0
- package/src/accounts/utils.ts +62 -0
- package/src/accounts/webSocketAccountSubscriber.ts +205 -0
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +621 -0
- package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +129 -0
- package/src/accounts/webSocketProgramAccountSubscriber.ts +182 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +104 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +98 -0
- package/src/addresses/marketAddresses.ts +17 -0
- package/src/addresses/pda.ts +355 -0
- package/src/adminClient.ts +4030 -0
- package/src/assert/assert.ts +5 -0
- package/src/auctionSubscriber/auctionSubscriber.ts +66 -0
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +70 -0
- package/src/auctionSubscriber/index.ts +3 -0
- package/src/auctionSubscriber/types.ts +20 -0
- package/src/bankrun/bankrunConnection.ts +534 -0
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +126 -0
- package/src/blockhashSubscriber/index.ts +1 -0
- package/src/blockhashSubscriber/types.ts +12 -0
- package/src/clock/clockSubscriber.ts +121 -0
- package/src/config.ts +212 -0
- package/src/constants/numericConstants.ts +113 -0
- package/src/constants/perpMarkets.ts +1084 -0
- package/src/constants/spotMarkets.ts +565 -0
- package/src/constants/txConstants.ts +1 -0
- package/src/decode/phoenix.ts +207 -0
- package/src/decode/user.ts +368 -0
- package/src/dlob/DLOB.ts +1897 -0
- package/src/dlob/DLOBNode.ts +197 -0
- package/src/dlob/DLOBSubscriber.ts +201 -0
- package/src/dlob/NodeList.ts +173 -0
- package/src/dlob/orderBookLevels.ts +643 -0
- package/src/dlob/types.ts +22 -0
- package/src/driftClient.ts +9032 -0
- package/src/driftClientConfig.ts +60 -0
- package/src/events/eventList.ts +97 -0
- package/src/events/eventSubscriber.ts +364 -0
- package/src/events/eventsServerLogProvider.ts +152 -0
- package/src/events/fetchLogs.ts +169 -0
- package/src/events/parse.ts +133 -0
- package/src/events/pollingLogProvider.ts +89 -0
- package/src/events/sort.ts +39 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.ts +185 -0
- package/src/events/webSocketLogProvider.ts +121 -0
- package/src/factory/bigNum.ts +660 -0
- package/src/factory/oracleClient.ts +72 -0
- package/src/idl/drift.json +14440 -0
- package/src/idl/openbook.json +3854 -0
- package/src/idl/pyth.json +142 -0
- package/src/idl/pyth_solana_receiver.json +628 -0
- package/src/idl/switchboard.json +8354 -0
- package/src/idl/switchboard_on_demand_30.json +4546 -0
- package/src/idl/token_faucet.json +142 -0
- package/src/index.ts +127 -0
- package/src/isomorphic/README.md +19 -0
- package/src/isomorphic/grpc.browser.ts +4 -0
- package/src/isomorphic/grpc.node.ts +23 -0
- package/src/isomorphic/grpc.ts +1 -0
- package/src/jupiter/jupiterClient.ts +510 -0
- package/src/keypair.ts +24 -0
- package/src/marinade/idl/idl.json +1962 -0
- package/src/marinade/index.ts +64 -0
- package/src/marinade/types.ts +3925 -0
- package/src/math/amm.ts +1162 -0
- package/src/math/auction.ts +173 -0
- package/src/math/bankruptcy.ts +34 -0
- package/src/math/conversion.ts +13 -0
- package/src/math/exchangeStatus.ts +121 -0
- package/src/math/fuel.ts +70 -0
- package/src/math/funding.ts +342 -0
- package/src/math/insurance.ts +110 -0
- package/src/math/margin.ts +340 -0
- package/src/math/market.ts +336 -0
- package/src/math/oracles.ts +228 -0
- package/src/math/orders.ts +343 -0
- package/src/math/position.ts +324 -0
- package/src/math/repeg.ts +214 -0
- package/src/math/spotBalance.ts +630 -0
- package/src/math/spotMarket.ts +82 -0
- package/src/math/spotPosition.ts +184 -0
- package/src/math/state.ts +29 -0
- package/src/math/superStake.ts +525 -0
- package/src/math/tiers.ts +44 -0
- package/src/math/trade.ts +993 -0
- package/src/math/userStatus.ts +5 -0
- package/src/math/utils.ts +120 -0
- package/src/memcmp.ts +94 -0
- package/src/openbook/openbookV2FulfillmentConfigMap.ts +29 -0
- package/src/openbook/openbookV2Subscriber.ts +165 -0
- package/src/oracles/oracleClientCache.ts +25 -0
- package/src/oracles/oracleId.ts +28 -0
- package/src/oracles/prelaunchOracleClient.ts +37 -0
- package/src/oracles/pythClient.ts +85 -0
- package/src/oracles/pythLazerClient.ts +102 -0
- package/src/oracles/pythPullClient.ts +111 -0
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/strictOraclePrice.ts +19 -0
- package/src/oracles/switchboardClient.ts +77 -0
- package/src/oracles/switchboardOnDemandClient.ts +56 -0
- package/src/oracles/types.ts +23 -0
- package/src/orderParams.ts +79 -0
- package/src/orderSubscriber/OrderSubscriber.ts +249 -0
- package/src/orderSubscriber/PollingSubscription.ts +39 -0
- package/src/orderSubscriber/WebsocketSubscription.ts +119 -0
- package/src/orderSubscriber/grpcSubscription.ts +121 -0
- package/src/orderSubscriber/index.ts +2 -0
- package/src/orderSubscriber/types.ts +54 -0
- package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
- package/src/phoenix/phoenixSubscriber.ts +235 -0
- package/src/priorityFee/averageOverSlotsStrategy.ts +16 -0
- package/src/priorityFee/averageStrategy.ts +12 -0
- package/src/priorityFee/driftPriorityFeeMethod.ts +42 -0
- package/src/priorityFee/ewmaStrategy.ts +41 -0
- package/src/priorityFee/heliusPriorityFeeMethod.ts +57 -0
- package/src/priorityFee/index.ts +11 -0
- package/src/priorityFee/maxOverSlotsStrategy.ts +17 -0
- package/src/priorityFee/maxStrategy.ts +7 -0
- package/src/priorityFee/priorityFeeSubscriber.ts +251 -0
- package/src/priorityFee/priorityFeeSubscriberMap.ts +112 -0
- package/src/priorityFee/solanaPriorityFeeMethod.ts +34 -0
- package/src/priorityFee/types.ts +60 -0
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +169 -0
- package/src/serum/types.ts +17 -0
- package/src/slot/SlotSubscriber.ts +101 -0
- package/src/slot/SlothashSubscriber.ts +126 -0
- package/src/testClient.ts +41 -0
- package/src/token/index.ts +13 -0
- package/src/tokenFaucet.ts +269 -0
- package/src/tx/baseTxSender.ts +477 -0
- package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +19 -0
- package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +90 -0
- package/src/tx/blockhashFetcher/types.ts +5 -0
- package/src/tx/fastSingleTxSender.ts +142 -0
- package/src/tx/forwardOnlyTxSender.ts +145 -0
- package/src/tx/priorityFeeCalculator.ts +117 -0
- package/src/tx/reportTransactionError.ts +159 -0
- package/src/tx/retryTxSender.ts +135 -0
- package/src/tx/txHandler.ts +737 -0
- package/src/tx/txParamProcessor.ts +155 -0
- package/src/tx/types.ts +71 -0
- package/src/tx/utils.ts +11 -0
- package/src/tx/whileValidTxSender.ts +265 -0
- package/src/types.ts +1386 -0
- package/src/user.ts +4054 -0
- package/src/userConfig.ts +32 -0
- package/src/userMap/PollingSubscription.ts +47 -0
- package/src/userMap/WebsocketSubscription.ts +84 -0
- package/src/userMap/grpcSubscription.ts +85 -0
- package/src/userMap/referrerMap.ts +267 -0
- package/src/userMap/userMap.ts +654 -0
- package/src/userMap/userMapConfig.ts +63 -0
- package/src/userMap/userStatsMap.ts +218 -0
- package/src/userName.ts +21 -0
- package/src/userStats.ts +174 -0
- package/src/userStatsConfig.ts +31 -0
- package/src/util/TransactionConfirmationManager.ts +292 -0
- package/src/util/chainClock.ts +41 -0
- package/src/util/computeUnits.ts +65 -0
- package/src/util/digest.ts +11 -0
- package/src/util/promiseTimeout.ts +14 -0
- package/src/util/pythOracleUtils.ts +136 -0
- package/src/util/tps.ts +27 -0
- package/src/wallet.ts +43 -0
- package/tests/amm/test.ts +2092 -0
- package/tests/auctions/test.ts +81 -0
- package/tests/bn/test.ts +341 -0
- package/tests/ci/idl.ts +101 -0
- package/tests/ci/verifyConstants.ts +278 -0
- package/tests/decode/phoenix.ts +71 -0
- package/tests/decode/test.ts +266 -0
- package/tests/decode/userAccountBufferStrings.ts +102 -0
- package/tests/dlob/helpers.ts +749 -0
- package/tests/dlob/test.ts +6623 -0
- package/tests/insurance/test.ts +40 -0
- package/tests/spot/test.ts +226 -0
- package/tests/subscriber/openbook.ts +62 -0
- package/tests/tx/TransactionConfirmationManager.test.ts +305 -0
- package/tests/tx/cachedBlockhashFetcher.test.ts +96 -0
- package/tests/tx/priorityFeeCalculator.ts +77 -0
- package/tests/tx/priorityFeeStrategy.ts +95 -0
- package/tests/user/helpers.ts +92 -0
- package/tests/user/test.ts +517 -0
- package/tsconfig.browser.json +13 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,1039 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DLOB = void 0;
|
|
4
|
+
const NodeList_1 = require("./NodeList");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const exchangeStatus_1 = require("../math/exchangeStatus");
|
|
8
|
+
const orderBookLevels_1 = require("./orderBookLevels");
|
|
9
|
+
const SUPPORTED_ORDER_TYPES = [
|
|
10
|
+
'market',
|
|
11
|
+
'limit',
|
|
12
|
+
'triggerMarket',
|
|
13
|
+
'triggerLimit',
|
|
14
|
+
'oracle',
|
|
15
|
+
];
|
|
16
|
+
class DLOB {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.openOrders = new Map();
|
|
19
|
+
this.orderLists = new Map();
|
|
20
|
+
this.maxSlotForRestingLimitOrders = 0;
|
|
21
|
+
this.initialized = false;
|
|
22
|
+
this.init();
|
|
23
|
+
}
|
|
24
|
+
init() {
|
|
25
|
+
this.openOrders.set('perp', new Set());
|
|
26
|
+
this.openOrders.set('spot', new Set());
|
|
27
|
+
this.orderLists.set('perp', new Map());
|
|
28
|
+
this.orderLists.set('spot', new Map());
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
for (const marketType of this.openOrders.keys()) {
|
|
32
|
+
this.openOrders.get(marketType).clear();
|
|
33
|
+
}
|
|
34
|
+
this.openOrders.clear();
|
|
35
|
+
for (const marketType of this.orderLists.keys()) {
|
|
36
|
+
for (const marketIndex of this.orderLists.get(marketType).keys()) {
|
|
37
|
+
const marketNodeLists = this.orderLists
|
|
38
|
+
.get(marketType)
|
|
39
|
+
.get(marketIndex);
|
|
40
|
+
for (const side of Object.keys(marketNodeLists)) {
|
|
41
|
+
for (const orderType of Object.keys(marketNodeLists[side])) {
|
|
42
|
+
marketNodeLists[side][orderType].clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.orderLists.clear();
|
|
48
|
+
this.maxSlotForRestingLimitOrders = 0;
|
|
49
|
+
this.init();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* initializes a new DLOB instance
|
|
53
|
+
*
|
|
54
|
+
* @returns a promise that resolves when the DLOB is initialized
|
|
55
|
+
*/
|
|
56
|
+
async initFromUserMap(userMap, slot) {
|
|
57
|
+
if (this.initialized) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// initialize the dlob with the user map
|
|
61
|
+
for (const user of userMap.values()) {
|
|
62
|
+
const userAccount = user.getUserAccount();
|
|
63
|
+
const userAccountPubkey = user.getUserAccountPublicKey();
|
|
64
|
+
const userAccountPubkeyString = userAccountPubkey.toString();
|
|
65
|
+
const protectedMaker = (0, __1.isUserProtectedMaker)(userAccount);
|
|
66
|
+
for (const order of userAccount.orders) {
|
|
67
|
+
this.insertOrder(order, userAccountPubkeyString, slot, protectedMaker);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.initialized = true;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
insertOrder(order, userAccount, slot, isUserProtectedMaker, onInsert) {
|
|
74
|
+
var _a;
|
|
75
|
+
if ((0, __1.isVariant)(order.status, 'init')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!(0, __1.isOneOfVariant)(order.orderType, SUPPORTED_ORDER_TYPES)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const marketType = (0, __1.getVariant)(order.marketType);
|
|
82
|
+
if (!this.orderLists.get(marketType).has(order.marketIndex)) {
|
|
83
|
+
this.addOrderList(marketType, order.marketIndex);
|
|
84
|
+
}
|
|
85
|
+
if ((0, __1.isVariant)(order.status, 'open')) {
|
|
86
|
+
this.openOrders
|
|
87
|
+
.get(marketType)
|
|
88
|
+
.add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
89
|
+
}
|
|
90
|
+
(_a = this.getListForOnChainOrder(order, slot)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, isUserProtectedMaker);
|
|
91
|
+
if (onInsert) {
|
|
92
|
+
onInsert();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
insertSwiftOrder(order, userAccount, isUserProtectedMaker, onInsert) {
|
|
96
|
+
const marketType = (0, __1.getVariant)(order.marketType);
|
|
97
|
+
const marketIndex = order.marketIndex;
|
|
98
|
+
const bidOrAsk = (0, __1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
|
|
99
|
+
if (!this.orderLists.get(marketType).has(order.marketIndex)) {
|
|
100
|
+
this.addOrderList(marketType, order.marketIndex);
|
|
101
|
+
}
|
|
102
|
+
this.openOrders
|
|
103
|
+
.get(marketType)
|
|
104
|
+
.add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
105
|
+
this.orderLists
|
|
106
|
+
.get(marketType)
|
|
107
|
+
.get(marketIndex)
|
|
108
|
+
.swift[bidOrAsk].insert(order, marketType, userAccount, isUserProtectedMaker);
|
|
109
|
+
if (onInsert) {
|
|
110
|
+
onInsert();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
addOrderList(marketType, marketIndex) {
|
|
114
|
+
this.orderLists.get(marketType).set(marketIndex, {
|
|
115
|
+
restingLimit: {
|
|
116
|
+
ask: new NodeList_1.NodeList('restingLimit', 'asc'),
|
|
117
|
+
bid: new NodeList_1.NodeList('restingLimit', 'desc'),
|
|
118
|
+
},
|
|
119
|
+
floatingLimit: {
|
|
120
|
+
ask: new NodeList_1.NodeList('floatingLimit', 'asc'),
|
|
121
|
+
bid: new NodeList_1.NodeList('floatingLimit', 'desc'),
|
|
122
|
+
},
|
|
123
|
+
takingLimit: {
|
|
124
|
+
ask: new NodeList_1.NodeList('takingLimit', 'asc'),
|
|
125
|
+
bid: new NodeList_1.NodeList('takingLimit', 'asc'), // always sort ascending for market orders
|
|
126
|
+
},
|
|
127
|
+
market: {
|
|
128
|
+
ask: new NodeList_1.NodeList('market', 'asc'),
|
|
129
|
+
bid: new NodeList_1.NodeList('market', 'asc'), // always sort ascending for market orders
|
|
130
|
+
},
|
|
131
|
+
trigger: {
|
|
132
|
+
above: new NodeList_1.NodeList('trigger', 'asc'),
|
|
133
|
+
below: new NodeList_1.NodeList('trigger', 'desc'),
|
|
134
|
+
},
|
|
135
|
+
swift: {
|
|
136
|
+
ask: new NodeList_1.NodeList('swift', 'asc'),
|
|
137
|
+
bid: new NodeList_1.NodeList('swift', 'asc'),
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
getListForOnChainOrder(order, slot) {
|
|
142
|
+
const isInactiveTriggerOrder = (0, __1.mustBeTriggered)(order) && !(0, __1.isTriggered)(order);
|
|
143
|
+
let type;
|
|
144
|
+
if (isInactiveTriggerOrder) {
|
|
145
|
+
type = 'trigger';
|
|
146
|
+
}
|
|
147
|
+
else if ((0, __1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
|
|
148
|
+
type = 'market';
|
|
149
|
+
}
|
|
150
|
+
else if (order.oraclePriceOffset !== 0) {
|
|
151
|
+
type = 'floatingLimit';
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const isResting = (0, __1.isRestingLimitOrder)(order, slot);
|
|
155
|
+
type = isResting ? 'restingLimit' : 'takingLimit';
|
|
156
|
+
}
|
|
157
|
+
let subType;
|
|
158
|
+
if (isInactiveTriggerOrder) {
|
|
159
|
+
subType = (0, __1.isVariant)(order.triggerCondition, 'above') ? 'above' : 'below';
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
subType = (0, __1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
|
|
163
|
+
}
|
|
164
|
+
const marketType = (0, __1.getVariant)(order.marketType);
|
|
165
|
+
if (!this.orderLists.has(marketType)) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return this.orderLists.get(marketType).get(order.marketIndex)[type][subType];
|
|
169
|
+
}
|
|
170
|
+
updateRestingLimitOrders(slot) {
|
|
171
|
+
if (slot <= this.maxSlotForRestingLimitOrders) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.maxSlotForRestingLimitOrders = slot;
|
|
175
|
+
this.updateRestingLimitOrdersForMarketType(slot, 'perp');
|
|
176
|
+
this.updateRestingLimitOrdersForMarketType(slot, 'spot');
|
|
177
|
+
}
|
|
178
|
+
updateRestingLimitOrdersForMarketType(slot, marketTypeStr) {
|
|
179
|
+
for (const [_, nodeLists] of this.orderLists.get(marketTypeStr)) {
|
|
180
|
+
const nodesToUpdate = [];
|
|
181
|
+
for (const node of nodeLists.takingLimit.ask.getGenerator()) {
|
|
182
|
+
if (!(0, __1.isRestingLimitOrder)(node.order, slot)) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
nodesToUpdate.push({
|
|
186
|
+
side: 'ask',
|
|
187
|
+
node,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
for (const node of nodeLists.takingLimit.bid.getGenerator()) {
|
|
191
|
+
if (!(0, __1.isRestingLimitOrder)(node.order, slot)) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
nodesToUpdate.push({
|
|
195
|
+
side: 'bid',
|
|
196
|
+
node,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
for (const nodeToUpdate of nodesToUpdate) {
|
|
200
|
+
const { side, node } = nodeToUpdate;
|
|
201
|
+
nodeLists.takingLimit[side].remove(node.order, node.userAccount);
|
|
202
|
+
nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
getOrder(orderId, userAccount) {
|
|
207
|
+
const orderSignature = (0, NodeList_1.getOrderSignature)(orderId, userAccount.toString());
|
|
208
|
+
for (const nodeList of this.getNodeLists()) {
|
|
209
|
+
const node = nodeList.get(orderSignature);
|
|
210
|
+
if (node) {
|
|
211
|
+
return node.order;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
findNodesToFill(marketIndex, fallbackBid, fallbackAsk, slot, ts, marketType, oraclePriceData, stateAccount, marketAccount) {
|
|
217
|
+
if ((0, exchangeStatus_1.fillPaused)(stateAccount, marketAccount)) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
const isAmmPaused = (0, exchangeStatus_1.ammPaused)(stateAccount, marketAccount);
|
|
221
|
+
const minAuctionDuration = (0, __1.isVariant)(marketType, 'perp')
|
|
222
|
+
? stateAccount.minPerpAuctionDuration
|
|
223
|
+
: 0;
|
|
224
|
+
const { makerRebateNumerator, makerRebateDenominator } = this.getMakerRebate(marketType, stateAccount, marketAccount);
|
|
225
|
+
const takingOrderNodesToFill = this.findTakingNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, minAuctionDuration, fallbackAsk, fallbackBid);
|
|
226
|
+
const restingLimitOrderNodesToFill = this.findRestingLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, minAuctionDuration, makerRebateNumerator, makerRebateDenominator, fallbackAsk, fallbackBid);
|
|
227
|
+
// get expired market nodes
|
|
228
|
+
const expiredNodesToFill = this.findExpiredNodesToFill(marketIndex, ts, marketType, new __1.BN(slot));
|
|
229
|
+
return this.mergeNodesToFill(restingLimitOrderNodesToFill, takingOrderNodesToFill).concat(expiredNodesToFill);
|
|
230
|
+
}
|
|
231
|
+
getMakerRebate(marketType, stateAccount, marketAccount) {
|
|
232
|
+
let makerRebateNumerator;
|
|
233
|
+
let makerRebateDenominator;
|
|
234
|
+
if ((0, __1.isVariant)(marketType, 'perp')) {
|
|
235
|
+
makerRebateNumerator =
|
|
236
|
+
stateAccount.perpFeeStructure.feeTiers[0].makerRebateNumerator;
|
|
237
|
+
makerRebateDenominator =
|
|
238
|
+
stateAccount.perpFeeStructure.feeTiers[0].makerRebateDenominator;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
makerRebateNumerator =
|
|
242
|
+
stateAccount.spotFeeStructure.feeTiers[0].makerRebateNumerator;
|
|
243
|
+
makerRebateDenominator =
|
|
244
|
+
stateAccount.spotFeeStructure.feeTiers[0].makerRebateDenominator;
|
|
245
|
+
}
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
const feeAdjustment = marketAccount.feeAdjustment || 0;
|
|
248
|
+
if (feeAdjustment !== 0) {
|
|
249
|
+
makerRebateNumerator += (makerRebateNumerator * feeAdjustment) / 100;
|
|
250
|
+
}
|
|
251
|
+
return { makerRebateNumerator, makerRebateDenominator };
|
|
252
|
+
}
|
|
253
|
+
mergeNodesToFill(restingLimitOrderNodesToFill, takingOrderNodesToFill) {
|
|
254
|
+
const mergedNodesToFill = new Map();
|
|
255
|
+
const mergeNodesToFillHelper = (nodesToFillArray) => {
|
|
256
|
+
nodesToFillArray.forEach((nodeToFill) => {
|
|
257
|
+
const nodeSignature = (0, NodeList_1.getOrderSignature)(nodeToFill.node.order.orderId, nodeToFill.node.userAccount);
|
|
258
|
+
if (!mergedNodesToFill.has(nodeSignature)) {
|
|
259
|
+
mergedNodesToFill.set(nodeSignature, {
|
|
260
|
+
node: nodeToFill.node,
|
|
261
|
+
makerNodes: [],
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (nodeToFill.makerNodes) {
|
|
265
|
+
mergedNodesToFill
|
|
266
|
+
.get(nodeSignature)
|
|
267
|
+
.makerNodes.push(...nodeToFill.makerNodes);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
mergeNodesToFillHelper(restingLimitOrderNodesToFill);
|
|
272
|
+
mergeNodesToFillHelper(takingOrderNodesToFill);
|
|
273
|
+
return Array.from(mergedNodesToFill.values());
|
|
274
|
+
}
|
|
275
|
+
findRestingLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, minAuctionDuration, makerRebateNumerator, makerRebateDenominator, fallbackAsk, fallbackBid) {
|
|
276
|
+
const nodesToFill = new Array();
|
|
277
|
+
const crossingNodes = this.findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData);
|
|
278
|
+
for (const crossingNode of crossingNodes) {
|
|
279
|
+
nodesToFill.push(crossingNode);
|
|
280
|
+
}
|
|
281
|
+
if (fallbackBid && !isAmmPaused) {
|
|
282
|
+
const askGenerator = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
283
|
+
const fallbackBidWithBuffer = fallbackBid.sub(fallbackBid.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
284
|
+
const asksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, askGenerator, (askPrice) => {
|
|
285
|
+
return askPrice.lte(fallbackBidWithBuffer);
|
|
286
|
+
}, minAuctionDuration);
|
|
287
|
+
for (const askCrossingFallback of asksCrossingFallback) {
|
|
288
|
+
nodesToFill.push(askCrossingFallback);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (fallbackAsk && !isAmmPaused) {
|
|
292
|
+
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
293
|
+
const fallbackAskWithBuffer = fallbackAsk.add(fallbackAsk.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
294
|
+
const bidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, bidGenerator, (bidPrice) => {
|
|
295
|
+
return bidPrice.gte(fallbackAskWithBuffer);
|
|
296
|
+
}, minAuctionDuration);
|
|
297
|
+
for (const bidCrossingFallback of bidsCrossingFallback) {
|
|
298
|
+
nodesToFill.push(bidCrossingFallback);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return nodesToFill;
|
|
302
|
+
}
|
|
303
|
+
findTakingNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, minAuctionDuration, fallbackAsk, fallbackBid) {
|
|
304
|
+
const nodesToFill = new Array();
|
|
305
|
+
let takingOrderGenerator = this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData);
|
|
306
|
+
const takingAsksCrossingBids = this.findTakingNodesCrossingMakerNodes(marketIndex, slot, marketType, oraclePriceData, takingOrderGenerator, this.getRestingLimitBids.bind(this), (takerPrice, makerPrice) => {
|
|
307
|
+
if ((0, __1.isVariant)(marketType, 'spot')) {
|
|
308
|
+
if (takerPrice === undefined) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
if (fallbackBid && makerPrice.lt(fallbackBid)) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return takerPrice === undefined || takerPrice.lte(makerPrice);
|
|
316
|
+
});
|
|
317
|
+
for (const takingAskCrossingBid of takingAsksCrossingBids) {
|
|
318
|
+
nodesToFill.push(takingAskCrossingBid);
|
|
319
|
+
}
|
|
320
|
+
if (fallbackBid && !isAmmPaused) {
|
|
321
|
+
takingOrderGenerator = this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData);
|
|
322
|
+
const takingAsksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, takingOrderGenerator, (takerPrice) => {
|
|
323
|
+
return takerPrice === undefined || takerPrice.lte(fallbackBid);
|
|
324
|
+
}, minAuctionDuration);
|
|
325
|
+
for (const takingAskCrossingFallback of takingAsksCrossingFallback) {
|
|
326
|
+
nodesToFill.push(takingAskCrossingFallback);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
takingOrderGenerator = this.getTakingBids(marketIndex, marketType, slot, oraclePriceData);
|
|
330
|
+
const takingBidsToFill = this.findTakingNodesCrossingMakerNodes(marketIndex, slot, marketType, oraclePriceData, takingOrderGenerator, this.getRestingLimitAsks.bind(this), (takerPrice, makerPrice) => {
|
|
331
|
+
if ((0, __1.isVariant)(marketType, 'spot')) {
|
|
332
|
+
if (takerPrice === undefined) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
if (fallbackAsk && makerPrice.gt(fallbackAsk)) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return takerPrice === undefined || takerPrice.gte(makerPrice);
|
|
340
|
+
});
|
|
341
|
+
for (const takingBidToFill of takingBidsToFill) {
|
|
342
|
+
nodesToFill.push(takingBidToFill);
|
|
343
|
+
}
|
|
344
|
+
if (fallbackAsk && !isAmmPaused) {
|
|
345
|
+
takingOrderGenerator = this.getTakingBids(marketIndex, marketType, slot, oraclePriceData);
|
|
346
|
+
const takingBidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, takingOrderGenerator, (takerPrice) => {
|
|
347
|
+
return takerPrice === undefined || takerPrice.gte(fallbackAsk);
|
|
348
|
+
}, minAuctionDuration);
|
|
349
|
+
for (const marketBidCrossingFallback of takingBidsCrossingFallback) {
|
|
350
|
+
nodesToFill.push(marketBidCrossingFallback);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return nodesToFill;
|
|
354
|
+
}
|
|
355
|
+
findTakingNodesCrossingMakerNodes(marketIndex, slot, marketType, oraclePriceData, takerNodeGenerator, makerNodeGeneratorFn, doesCross) {
|
|
356
|
+
const nodesToFill = new Array();
|
|
357
|
+
for (const takerNode of takerNodeGenerator) {
|
|
358
|
+
const makerNodeGenerator = makerNodeGeneratorFn(marketIndex, slot, marketType, oraclePriceData);
|
|
359
|
+
for (const makerNode of makerNodeGenerator) {
|
|
360
|
+
// Can't match orders from the same user
|
|
361
|
+
const sameUser = takerNode.userAccount === makerNode.userAccount;
|
|
362
|
+
if (sameUser) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const makerPrice = makerNode.getPrice(oraclePriceData, slot);
|
|
366
|
+
const takerPrice = takerNode.getPrice(oraclePriceData, slot);
|
|
367
|
+
const ordersCross = doesCross(takerPrice, makerPrice);
|
|
368
|
+
if (!ordersCross) {
|
|
369
|
+
// market orders aren't sorted by price, they are sorted by time, so we need to traverse
|
|
370
|
+
// through all of em
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
nodesToFill.push({
|
|
374
|
+
node: takerNode,
|
|
375
|
+
makerNodes: [makerNode],
|
|
376
|
+
});
|
|
377
|
+
const makerOrder = makerNode.order;
|
|
378
|
+
const takerOrder = takerNode.order;
|
|
379
|
+
const makerBaseRemaining = makerOrder.baseAssetAmount.sub(makerOrder.baseAssetAmountFilled);
|
|
380
|
+
const takerBaseRemaining = takerOrder.baseAssetAmount.sub(takerOrder.baseAssetAmountFilled);
|
|
381
|
+
const baseFilled = __1.BN.min(makerBaseRemaining, takerBaseRemaining);
|
|
382
|
+
const newMakerOrder = { ...makerOrder };
|
|
383
|
+
newMakerOrder.baseAssetAmountFilled =
|
|
384
|
+
makerOrder.baseAssetAmountFilled.add(baseFilled);
|
|
385
|
+
this.getListForOnChainOrder(newMakerOrder, slot).update(newMakerOrder, makerNode.userAccount);
|
|
386
|
+
const newTakerOrder = { ...takerOrder };
|
|
387
|
+
newTakerOrder.baseAssetAmountFilled =
|
|
388
|
+
takerOrder.baseAssetAmountFilled.add(baseFilled);
|
|
389
|
+
this.getListForOnChainOrder(newTakerOrder, slot).update(newTakerOrder, takerNode.userAccount);
|
|
390
|
+
if (newTakerOrder.baseAssetAmountFilled.eq(takerOrder.baseAssetAmount)) {
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return nodesToFill;
|
|
396
|
+
}
|
|
397
|
+
findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, nodeGenerator, doesCross, minAuctionDuration) {
|
|
398
|
+
var _a;
|
|
399
|
+
const nodesToFill = new Array();
|
|
400
|
+
let nextNode = nodeGenerator.next();
|
|
401
|
+
while (!nextNode.done) {
|
|
402
|
+
const node = nextNode.value;
|
|
403
|
+
if ((0, __1.isVariant)(marketType, 'spot') && ((_a = node.order) === null || _a === void 0 ? void 0 : _a.postOnly)) {
|
|
404
|
+
nextNode = nodeGenerator.next();
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const nodePrice = (0, __1.getLimitPrice)(node.order, oraclePriceData, slot);
|
|
408
|
+
// order crosses if there is no limit price or it crosses fallback price
|
|
409
|
+
const crosses = doesCross(nodePrice);
|
|
410
|
+
// fallback is available if auction is complete or it's a spot order
|
|
411
|
+
const fallbackAvailable = (0, __1.isVariant)(marketType, 'spot') ||
|
|
412
|
+
(0, __1.isFallbackAvailableLiquiditySource)(node.order, minAuctionDuration, slot);
|
|
413
|
+
if (crosses && fallbackAvailable) {
|
|
414
|
+
nodesToFill.push({
|
|
415
|
+
node: node,
|
|
416
|
+
makerNodes: [], // filled by fallback
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
nextNode = nodeGenerator.next();
|
|
420
|
+
}
|
|
421
|
+
return nodesToFill;
|
|
422
|
+
}
|
|
423
|
+
findExpiredNodesToFill(marketIndex, ts, marketType, slot) {
|
|
424
|
+
const nodesToFill = new Array();
|
|
425
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
426
|
+
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
427
|
+
if (!nodeLists) {
|
|
428
|
+
return nodesToFill;
|
|
429
|
+
}
|
|
430
|
+
// All bids/asks that can expire
|
|
431
|
+
// dont try to expire limit orders with tif as its inefficient use of blockspace
|
|
432
|
+
const bidGenerators = [
|
|
433
|
+
nodeLists.takingLimit.bid.getGenerator(),
|
|
434
|
+
nodeLists.restingLimit.bid.getGenerator(),
|
|
435
|
+
nodeLists.floatingLimit.bid.getGenerator(),
|
|
436
|
+
nodeLists.market.bid.getGenerator(),
|
|
437
|
+
nodeLists.swift.bid.getGenerator(),
|
|
438
|
+
];
|
|
439
|
+
const askGenerators = [
|
|
440
|
+
nodeLists.takingLimit.ask.getGenerator(),
|
|
441
|
+
nodeLists.restingLimit.ask.getGenerator(),
|
|
442
|
+
nodeLists.floatingLimit.ask.getGenerator(),
|
|
443
|
+
nodeLists.market.ask.getGenerator(),
|
|
444
|
+
nodeLists.swift.ask.getGenerator(),
|
|
445
|
+
];
|
|
446
|
+
for (const bidGenerator of bidGenerators) {
|
|
447
|
+
for (const bid of bidGenerator) {
|
|
448
|
+
if (bid.isSwift &&
|
|
449
|
+
slot.gt(bid.order.slot.addn(bid.order.auctionDuration))) {
|
|
450
|
+
this.orderLists
|
|
451
|
+
.get(marketTypeStr)
|
|
452
|
+
.get(marketIndex)
|
|
453
|
+
.swift.bid.remove(bid.order, bid.userAccount);
|
|
454
|
+
}
|
|
455
|
+
else if ((0, __1.isOrderExpired)(bid.order, ts, true, 25)) {
|
|
456
|
+
nodesToFill.push({
|
|
457
|
+
node: bid,
|
|
458
|
+
makerNodes: [],
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
for (const askGenerator of askGenerators) {
|
|
464
|
+
for (const ask of askGenerator) {
|
|
465
|
+
if ((0, __1.isOrderExpired)(ask.order, ts, true, 25)) {
|
|
466
|
+
nodesToFill.push({
|
|
467
|
+
node: ask,
|
|
468
|
+
makerNodes: [],
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return nodesToFill;
|
|
474
|
+
}
|
|
475
|
+
*getTakingBids(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
476
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
477
|
+
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
478
|
+
if (!orderLists) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
this.updateRestingLimitOrders(slot);
|
|
482
|
+
const generatorList = [
|
|
483
|
+
orderLists.market.bid.getGenerator(),
|
|
484
|
+
orderLists.takingLimit.bid.getGenerator(),
|
|
485
|
+
orderLists.swift.bid.getGenerator(),
|
|
486
|
+
];
|
|
487
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
488
|
+
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
489
|
+
}, filterFcn);
|
|
490
|
+
}
|
|
491
|
+
*getTakingAsks(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
492
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
493
|
+
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
494
|
+
if (!orderLists) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
this.updateRestingLimitOrders(slot);
|
|
498
|
+
const generatorList = [
|
|
499
|
+
orderLists.market.ask.getGenerator(),
|
|
500
|
+
orderLists.takingLimit.ask.getGenerator(),
|
|
501
|
+
orderLists.swift.ask.getGenerator(),
|
|
502
|
+
];
|
|
503
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
504
|
+
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
505
|
+
}, filterFcn);
|
|
506
|
+
}
|
|
507
|
+
*getBestNode(generatorList, oraclePriceData, slot, compareFcn, filterFcn) {
|
|
508
|
+
const generators = generatorList.map((generator) => {
|
|
509
|
+
return {
|
|
510
|
+
next: generator.next(),
|
|
511
|
+
generator,
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
let sideExhausted = false;
|
|
515
|
+
while (!sideExhausted) {
|
|
516
|
+
const bestGenerator = generators.reduce((bestGenerator, currentGenerator) => {
|
|
517
|
+
if (currentGenerator.next.done) {
|
|
518
|
+
return bestGenerator;
|
|
519
|
+
}
|
|
520
|
+
if (bestGenerator.next.done) {
|
|
521
|
+
return currentGenerator;
|
|
522
|
+
}
|
|
523
|
+
const bestValue = bestGenerator.next.value;
|
|
524
|
+
const currentValue = currentGenerator.next.value;
|
|
525
|
+
return compareFcn(bestValue, currentValue, slot, oraclePriceData)
|
|
526
|
+
? bestGenerator
|
|
527
|
+
: currentGenerator;
|
|
528
|
+
});
|
|
529
|
+
if (!bestGenerator.next.done) {
|
|
530
|
+
// skip this node if it's already completely filled
|
|
531
|
+
if (bestGenerator.next.value.isBaseFilled()) {
|
|
532
|
+
bestGenerator.next = bestGenerator.generator.next();
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (filterFcn && !filterFcn(bestGenerator.next.value)) {
|
|
536
|
+
bestGenerator.next = bestGenerator.generator.next();
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
yield bestGenerator.next.value;
|
|
540
|
+
bestGenerator.next = bestGenerator.generator.next();
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
sideExhausted = true;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
*getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
|
|
548
|
+
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
549
|
+
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
550
|
+
}
|
|
551
|
+
this.updateRestingLimitOrders(slot);
|
|
552
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
553
|
+
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
554
|
+
if (!nodeLists) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const generatorList = [
|
|
558
|
+
nodeLists.restingLimit.ask.getGenerator(),
|
|
559
|
+
nodeLists.floatingLimit.ask.getGenerator(),
|
|
560
|
+
];
|
|
561
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
562
|
+
return bestNode
|
|
563
|
+
.getPrice(oraclePriceData, slot)
|
|
564
|
+
.lt(currentNode.getPrice(oraclePriceData, slot));
|
|
565
|
+
}, filterFcn);
|
|
566
|
+
}
|
|
567
|
+
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
|
|
568
|
+
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
569
|
+
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
570
|
+
}
|
|
571
|
+
this.updateRestingLimitOrders(slot);
|
|
572
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
573
|
+
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
574
|
+
if (!nodeLists) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const generatorList = [
|
|
578
|
+
nodeLists.restingLimit.bid.getGenerator(),
|
|
579
|
+
nodeLists.floatingLimit.bid.getGenerator(),
|
|
580
|
+
];
|
|
581
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
582
|
+
return bestNode
|
|
583
|
+
.getPrice(oraclePriceData, slot)
|
|
584
|
+
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
585
|
+
}, filterFcn);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* This will look at both the taking and resting limit asks
|
|
589
|
+
* @param marketIndex
|
|
590
|
+
* @param fallbackAsk
|
|
591
|
+
* @param slot
|
|
592
|
+
* @param marketType
|
|
593
|
+
* @param oraclePriceData
|
|
594
|
+
* @param filterFcn
|
|
595
|
+
*/
|
|
596
|
+
*getAsks(marketIndex, _fallbackAsk, slot, marketType, oraclePriceData, filterFcn) {
|
|
597
|
+
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
598
|
+
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
599
|
+
}
|
|
600
|
+
const generatorList = [
|
|
601
|
+
this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData),
|
|
602
|
+
this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData),
|
|
603
|
+
];
|
|
604
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
605
|
+
var _a, _b;
|
|
606
|
+
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : __1.ZERO;
|
|
607
|
+
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : __1.ZERO;
|
|
608
|
+
if (bestNodePrice.eq(currentNodePrice)) {
|
|
609
|
+
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
610
|
+
}
|
|
611
|
+
return bestNodePrice.lt(currentNodePrice);
|
|
612
|
+
}, filterFcn);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* This will look at both the taking and resting limit bids
|
|
616
|
+
* @param marketIndex
|
|
617
|
+
* @param fallbackBid
|
|
618
|
+
* @param slot
|
|
619
|
+
* @param marketType
|
|
620
|
+
* @param oraclePriceData
|
|
621
|
+
* @param filterFcn
|
|
622
|
+
*/
|
|
623
|
+
*getBids(marketIndex, _fallbackBid, slot, marketType, oraclePriceData, filterFcn) {
|
|
624
|
+
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
625
|
+
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
626
|
+
}
|
|
627
|
+
const generatorList = [
|
|
628
|
+
this.getTakingBids(marketIndex, marketType, slot, oraclePriceData),
|
|
629
|
+
this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData),
|
|
630
|
+
];
|
|
631
|
+
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
632
|
+
var _a, _b;
|
|
633
|
+
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : __1.BN_MAX;
|
|
634
|
+
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : __1.BN_MAX;
|
|
635
|
+
if (bestNodePrice.eq(currentNodePrice)) {
|
|
636
|
+
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
637
|
+
}
|
|
638
|
+
return bestNodePrice.gt(currentNodePrice);
|
|
639
|
+
}, filterFcn);
|
|
640
|
+
}
|
|
641
|
+
findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData) {
|
|
642
|
+
const nodesToFill = new Array();
|
|
643
|
+
for (const askNode of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)) {
|
|
644
|
+
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
645
|
+
for (const bidNode of bidGenerator) {
|
|
646
|
+
const bidPrice = bidNode.getPrice(oraclePriceData, slot);
|
|
647
|
+
const askPrice = askNode.getPrice(oraclePriceData, slot);
|
|
648
|
+
// orders don't cross
|
|
649
|
+
if (bidPrice.lt(askPrice)) {
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
const bidOrder = bidNode.order;
|
|
653
|
+
const askOrder = askNode.order;
|
|
654
|
+
// Can't match orders from the same user
|
|
655
|
+
const sameUser = bidNode.userAccount === askNode.userAccount;
|
|
656
|
+
if (sameUser) {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const makerAndTaker = this.determineMakerAndTaker(askNode, bidNode);
|
|
660
|
+
// unable to match maker and taker due to post only or slot
|
|
661
|
+
if (!makerAndTaker) {
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const { takerNode, makerNode } = makerAndTaker;
|
|
665
|
+
const bidBaseRemaining = bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled);
|
|
666
|
+
const askBaseRemaining = askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled);
|
|
667
|
+
const baseFilled = __1.BN.min(bidBaseRemaining, askBaseRemaining);
|
|
668
|
+
const newBidOrder = { ...bidOrder };
|
|
669
|
+
newBidOrder.baseAssetAmountFilled =
|
|
670
|
+
bidOrder.baseAssetAmountFilled.add(baseFilled);
|
|
671
|
+
this.getListForOnChainOrder(newBidOrder, slot).update(newBidOrder, bidNode.userAccount);
|
|
672
|
+
// ask completely filled
|
|
673
|
+
const newAskOrder = { ...askOrder };
|
|
674
|
+
newAskOrder.baseAssetAmountFilled =
|
|
675
|
+
askOrder.baseAssetAmountFilled.add(baseFilled);
|
|
676
|
+
this.getListForOnChainOrder(newAskOrder, slot).update(newAskOrder, askNode.userAccount);
|
|
677
|
+
nodesToFill.push({
|
|
678
|
+
node: takerNode,
|
|
679
|
+
makerNodes: [makerNode],
|
|
680
|
+
});
|
|
681
|
+
if (newAskOrder.baseAssetAmount.eq(newAskOrder.baseAssetAmountFilled)) {
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return nodesToFill;
|
|
687
|
+
}
|
|
688
|
+
determineMakerAndTaker(askNode, bidNode) {
|
|
689
|
+
const askSlot = askNode.order.slot.add(new __1.BN(askNode.order.auctionDuration));
|
|
690
|
+
const bidSlot = bidNode.order.slot.add(new __1.BN(bidNode.order.auctionDuration));
|
|
691
|
+
if (bidNode.order.postOnly && askNode.order.postOnly) {
|
|
692
|
+
return undefined;
|
|
693
|
+
}
|
|
694
|
+
else if (bidNode.order.postOnly) {
|
|
695
|
+
return {
|
|
696
|
+
takerNode: askNode,
|
|
697
|
+
makerNode: bidNode,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
else if (askNode.order.postOnly) {
|
|
701
|
+
return {
|
|
702
|
+
takerNode: bidNode,
|
|
703
|
+
makerNode: askNode,
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
else if (askSlot.lte(bidSlot)) {
|
|
707
|
+
return {
|
|
708
|
+
takerNode: bidNode,
|
|
709
|
+
makerNode: askNode,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
return {
|
|
714
|
+
takerNode: askNode,
|
|
715
|
+
makerNode: bidNode,
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
getBestAsk(marketIndex, slot, marketType, oraclePriceData) {
|
|
720
|
+
const bestAsk = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
721
|
+
if (bestAsk) {
|
|
722
|
+
return bestAsk.getPrice(oraclePriceData, slot);
|
|
723
|
+
}
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
getBestBid(marketIndex, slot, marketType, oraclePriceData) {
|
|
727
|
+
const bestBid = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData).next().value;
|
|
728
|
+
if (bestBid) {
|
|
729
|
+
return bestBid.getPrice(oraclePriceData, slot);
|
|
730
|
+
}
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
*getStopLosses(marketIndex, marketType, direction) {
|
|
734
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
735
|
+
const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
736
|
+
if ((0, __1.isVariant)(direction, 'long') && marketNodeLists.trigger.below) {
|
|
737
|
+
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
738
|
+
if ((0, __1.isVariant)(node.order.direction, 'short')) {
|
|
739
|
+
yield node;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else if ((0, __1.isVariant)(direction, 'short') && marketNodeLists.trigger.above) {
|
|
744
|
+
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
745
|
+
if ((0, __1.isVariant)(node.order.direction, 'long')) {
|
|
746
|
+
yield node;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
*getStopLossMarkets(marketIndex, marketType, direction) {
|
|
752
|
+
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
753
|
+
if ((0, __1.isVariant)(node.order.orderType, 'triggerMarket')) {
|
|
754
|
+
yield node;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
*getStopLossLimits(marketIndex, marketType, direction) {
|
|
759
|
+
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
760
|
+
if ((0, __1.isVariant)(node.order.orderType, 'triggerLimit')) {
|
|
761
|
+
yield node;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
*getTakeProfits(marketIndex, marketType, direction) {
|
|
766
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
767
|
+
const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
768
|
+
if ((0, __1.isVariant)(direction, 'long') && marketNodeLists.trigger.above) {
|
|
769
|
+
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
770
|
+
if ((0, __1.isVariant)(node.order.direction, 'short')) {
|
|
771
|
+
yield node;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
else if ((0, __1.isVariant)(direction, 'short') && marketNodeLists.trigger.below) {
|
|
776
|
+
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
777
|
+
if ((0, __1.isVariant)(node.order.direction, 'long')) {
|
|
778
|
+
yield node;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
*getTakeProfitMarkets(marketIndex, marketType, direction) {
|
|
784
|
+
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
785
|
+
if ((0, __1.isVariant)(node.order.orderType, 'triggerMarket')) {
|
|
786
|
+
yield node;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
*getTakeProfitLimits(marketIndex, marketType, direction) {
|
|
791
|
+
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
792
|
+
if ((0, __1.isVariant)(node.order.orderType, 'triggerLimit')) {
|
|
793
|
+
yield node;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
findNodesToTrigger(marketIndex, slot, oraclePrice, marketType, stateAccount) {
|
|
798
|
+
if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
|
|
799
|
+
return [];
|
|
800
|
+
}
|
|
801
|
+
const nodesToTrigger = [];
|
|
802
|
+
const marketTypeStr = (0, __1.getVariant)(marketType);
|
|
803
|
+
const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
804
|
+
const triggerAboveList = marketNodeLists
|
|
805
|
+
? marketNodeLists.trigger.above
|
|
806
|
+
: undefined;
|
|
807
|
+
if (triggerAboveList) {
|
|
808
|
+
for (const node of triggerAboveList.getGenerator()) {
|
|
809
|
+
if (oraclePrice.gt(node.order.triggerPrice)) {
|
|
810
|
+
nodesToTrigger.push({
|
|
811
|
+
node: node,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const triggerBelowList = marketNodeLists
|
|
820
|
+
? marketNodeLists.trigger.below
|
|
821
|
+
: undefined;
|
|
822
|
+
if (triggerBelowList) {
|
|
823
|
+
for (const node of triggerBelowList.getGenerator()) {
|
|
824
|
+
if (oraclePrice.lt(node.order.triggerPrice)) {
|
|
825
|
+
nodesToTrigger.push({
|
|
826
|
+
node: node,
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return nodesToTrigger;
|
|
835
|
+
}
|
|
836
|
+
printTop(driftClient, slotSubscriber, marketIndex, marketType) {
|
|
837
|
+
if ((0, __1.isVariant)(marketType, 'perp')) {
|
|
838
|
+
const slot = slotSubscriber.getSlot();
|
|
839
|
+
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
840
|
+
const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
|
|
841
|
+
const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
|
|
842
|
+
const mid = bestAsk.add(bestBid).div(new __1.BN(2));
|
|
843
|
+
const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
|
|
844
|
+
(0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
845
|
+
1) *
|
|
846
|
+
100.0;
|
|
847
|
+
const askSpread = ((0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION) /
|
|
848
|
+
(0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
849
|
+
1) *
|
|
850
|
+
100.0;
|
|
851
|
+
const name = (0, __1.decodeName)(driftClient.getPerpMarketAccount(marketIndex).name);
|
|
852
|
+
console.log(`Market ${name} Orders`);
|
|
853
|
+
console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
854
|
+
console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
|
|
855
|
+
console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
|
|
856
|
+
}
|
|
857
|
+
else if ((0, __1.isVariant)(marketType, 'spot')) {
|
|
858
|
+
const slot = slotSubscriber.getSlot();
|
|
859
|
+
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
860
|
+
const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
|
|
861
|
+
const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
|
|
862
|
+
const mid = bestAsk.add(bestBid).div(new __1.BN(2));
|
|
863
|
+
const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
|
|
864
|
+
(0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
865
|
+
1) *
|
|
866
|
+
100.0;
|
|
867
|
+
const askSpread = ((0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION) /
|
|
868
|
+
(0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
869
|
+
1) *
|
|
870
|
+
100.0;
|
|
871
|
+
const name = (0, __1.decodeName)(driftClient.getSpotMarketAccount(marketIndex).name);
|
|
872
|
+
console.log(`Market ${name} Orders`);
|
|
873
|
+
console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
874
|
+
console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
|
|
875
|
+
console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
getDLOBOrders() {
|
|
879
|
+
const dlobOrders = [];
|
|
880
|
+
for (const nodeList of this.getNodeLists()) {
|
|
881
|
+
for (const node of nodeList.getGenerator()) {
|
|
882
|
+
dlobOrders.push({
|
|
883
|
+
user: new web3_js_1.PublicKey(node.userAccount),
|
|
884
|
+
order: node.order,
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return dlobOrders;
|
|
889
|
+
}
|
|
890
|
+
*getNodeLists() {
|
|
891
|
+
for (const [_, nodeLists] of this.orderLists.get('perp')) {
|
|
892
|
+
yield nodeLists.restingLimit.bid;
|
|
893
|
+
yield nodeLists.restingLimit.ask;
|
|
894
|
+
yield nodeLists.takingLimit.bid;
|
|
895
|
+
yield nodeLists.takingLimit.ask;
|
|
896
|
+
yield nodeLists.market.bid;
|
|
897
|
+
yield nodeLists.market.ask;
|
|
898
|
+
yield nodeLists.floatingLimit.bid;
|
|
899
|
+
yield nodeLists.floatingLimit.ask;
|
|
900
|
+
yield nodeLists.trigger.above;
|
|
901
|
+
yield nodeLists.trigger.below;
|
|
902
|
+
}
|
|
903
|
+
for (const [_, nodeLists] of this.orderLists.get('spot')) {
|
|
904
|
+
yield nodeLists.restingLimit.bid;
|
|
905
|
+
yield nodeLists.restingLimit.ask;
|
|
906
|
+
yield nodeLists.takingLimit.bid;
|
|
907
|
+
yield nodeLists.takingLimit.ask;
|
|
908
|
+
yield nodeLists.market.bid;
|
|
909
|
+
yield nodeLists.market.ask;
|
|
910
|
+
yield nodeLists.floatingLimit.bid;
|
|
911
|
+
yield nodeLists.floatingLimit.ask;
|
|
912
|
+
yield nodeLists.trigger.above;
|
|
913
|
+
yield nodeLists.trigger.below;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Get an L2 view of the order book for a given market.
|
|
918
|
+
*
|
|
919
|
+
* @param marketIndex
|
|
920
|
+
* @param marketType
|
|
921
|
+
* @param slot
|
|
922
|
+
* @param oraclePriceData
|
|
923
|
+
* @param depth how many levels of the order book to return
|
|
924
|
+
* @param fallbackL2Generators L2 generators for fallback liquidity e.g. vAMM {@link getVammL2Generator}, openbook {@link SerumSubscriber}
|
|
925
|
+
*/
|
|
926
|
+
getL2({ marketIndex, marketType, slot, oraclePriceData, depth, fallbackL2Generators = [], }) {
|
|
927
|
+
const makerAskL2LevelGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData), oraclePriceData, slot);
|
|
928
|
+
const fallbackAskGenerators = fallbackL2Generators.map((fallbackL2Generator) => {
|
|
929
|
+
return fallbackL2Generator.getL2Asks();
|
|
930
|
+
});
|
|
931
|
+
const askL2LevelGenerator = (0, orderBookLevels_1.mergeL2LevelGenerators)([makerAskL2LevelGenerator, ...fallbackAskGenerators], (a, b) => {
|
|
932
|
+
return a.price.lt(b.price);
|
|
933
|
+
});
|
|
934
|
+
const asks = (0, orderBookLevels_1.createL2Levels)(askL2LevelGenerator, depth);
|
|
935
|
+
const makerBidGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData), oraclePriceData, slot);
|
|
936
|
+
const fallbackBidGenerators = fallbackL2Generators.map((fallbackOrders) => {
|
|
937
|
+
return fallbackOrders.getL2Bids();
|
|
938
|
+
});
|
|
939
|
+
const bidL2LevelGenerator = (0, orderBookLevels_1.mergeL2LevelGenerators)([makerBidGenerator, ...fallbackBidGenerators], (a, b) => {
|
|
940
|
+
return a.price.gt(b.price);
|
|
941
|
+
});
|
|
942
|
+
const bids = (0, orderBookLevels_1.createL2Levels)(bidL2LevelGenerator, depth);
|
|
943
|
+
return {
|
|
944
|
+
bids,
|
|
945
|
+
asks,
|
|
946
|
+
slot,
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Get an L3 view of the order book for a given market. Does not include fallback liquidity sources
|
|
951
|
+
*
|
|
952
|
+
* @param marketIndex
|
|
953
|
+
* @param marketType
|
|
954
|
+
* @param slot
|
|
955
|
+
* @param oraclePriceData
|
|
956
|
+
*/
|
|
957
|
+
getL3({ marketIndex, marketType, slot, oraclePriceData, }) {
|
|
958
|
+
const bids = [];
|
|
959
|
+
const asks = [];
|
|
960
|
+
const restingAsks = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
961
|
+
for (const ask of restingAsks) {
|
|
962
|
+
asks.push({
|
|
963
|
+
price: ask.getPrice(oraclePriceData, slot),
|
|
964
|
+
size: ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled),
|
|
965
|
+
maker: new web3_js_1.PublicKey(ask.userAccount),
|
|
966
|
+
orderId: ask.order.orderId,
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
const restingBids = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
970
|
+
for (const bid of restingBids) {
|
|
971
|
+
bids.push({
|
|
972
|
+
price: bid.getPrice(oraclePriceData, slot),
|
|
973
|
+
size: bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled),
|
|
974
|
+
maker: new web3_js_1.PublicKey(bid.userAccount),
|
|
975
|
+
orderId: bid.order.orderId,
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
return {
|
|
979
|
+
bids,
|
|
980
|
+
asks,
|
|
981
|
+
slot,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
estimateFillExactBaseAmountInForSide(baseAmountIn, oraclePriceData, slot, dlobSide) {
|
|
985
|
+
let runningSumQuote = __1.ZERO;
|
|
986
|
+
let runningSumBase = __1.ZERO;
|
|
987
|
+
for (const side of dlobSide) {
|
|
988
|
+
const price = side.getPrice(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
|
|
989
|
+
const baseAmountRemaining = side.order.baseAssetAmount.sub(side.order.baseAssetAmountFilled);
|
|
990
|
+
if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
|
|
991
|
+
const remainingBase = baseAmountIn.sub(runningSumBase);
|
|
992
|
+
runningSumBase = runningSumBase.add(remainingBase);
|
|
993
|
+
runningSumQuote = runningSumQuote.add(remainingBase.mul(price));
|
|
994
|
+
break;
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
runningSumBase = runningSumBase.add(baseAmountRemaining);
|
|
998
|
+
runningSumQuote = runningSumQuote.add(baseAmountRemaining.mul(price));
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return runningSumQuote
|
|
1002
|
+
.mul(__1.QUOTE_PRECISION)
|
|
1003
|
+
.div(__1.BASE_PRECISION.mul(__1.PRICE_PRECISION));
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
*
|
|
1007
|
+
* @param param.marketIndex the index of the market
|
|
1008
|
+
* @param param.marketType the type of the market
|
|
1009
|
+
* @param param.baseAmount the base amount in to estimate
|
|
1010
|
+
* @param param.orderDirection the direction of the trade
|
|
1011
|
+
* @param param.slot current slot for estimating dlob node price
|
|
1012
|
+
* @param param.oraclePriceData the oracle price data
|
|
1013
|
+
* @returns the estimated quote amount filled: QUOTE_PRECISION
|
|
1014
|
+
*/
|
|
1015
|
+
estimateFillWithExactBaseAmount({ marketIndex, marketType, baseAmount, orderDirection, slot, oraclePriceData, }) {
|
|
1016
|
+
if ((0, __1.isVariant)(orderDirection, 'long')) {
|
|
1017
|
+
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData));
|
|
1018
|
+
}
|
|
1019
|
+
else if ((0, __1.isVariant)(orderDirection, 'short')) {
|
|
1020
|
+
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData));
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, }) {
|
|
1024
|
+
const makers = new Map();
|
|
1025
|
+
const generator = (0, __1.isVariant)(direction, 'long')
|
|
1026
|
+
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
1027
|
+
: this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1028
|
+
for (const node of generator) {
|
|
1029
|
+
if (!makers.has(node.userAccount.toString())) {
|
|
1030
|
+
makers.set(node.userAccount.toString(), new web3_js_1.PublicKey(node.userAccount));
|
|
1031
|
+
}
|
|
1032
|
+
if (makers.size === numMakers) {
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return Array.from(makers.values());
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
exports.DLOB = DLOB;
|