@velocity-exchange/sdk 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.js +18 -0
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +18 -0
- package/lib/browser/accounts/bulkAccountLoader.d.ts +52 -0
- package/lib/browser/accounts/bulkAccountLoader.js +51 -0
- package/lib/browser/accounts/bulkUserStatsSubscription.d.ts +9 -2
- package/lib/browser/accounts/bulkUserStatsSubscription.js +9 -2
- package/lib/browser/accounts/bulkUserSubscription.d.ts +8 -2
- package/lib/browser/accounts/bulkUserSubscription.js +8 -2
- package/lib/browser/accounts/customizedCadenceBulkAccountLoader.d.ts +37 -0
- package/lib/browser/accounts/customizedCadenceBulkAccountLoader.js +37 -0
- package/lib/browser/accounts/fetch.d.ts +59 -2
- package/lib/browser/accounts/fetch.js +57 -2
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +30 -0
- package/lib/browser/accounts/grpcAccountSubscriber.js +30 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +16 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +16 -0
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +60 -1
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +118 -37
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +32 -0
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +40 -12
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +33 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +33 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +15 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.js +15 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +15 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +15 -0
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +41 -0
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +41 -0
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +116 -0
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +152 -1
- package/lib/browser/accounts/laserProgramAccountSubscriber.d.ts +34 -0
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +34 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +19 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.js +19 -0
- package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.d.ts +19 -0
- package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +19 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +31 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +31 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +19 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.js +21 -2
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +22 -0
- package/lib/browser/accounts/pollingTokenAccountSubscriber.js +22 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +32 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +32 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +22 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +22 -0
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +83 -0
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +84 -1
- package/lib/browser/accounts/testBulkAccountLoader.d.ts +8 -0
- package/lib/browser/accounts/testBulkAccountLoader.js +8 -0
- package/lib/browser/accounts/types.d.ts +149 -0
- package/lib/browser/accounts/types.js +13 -0
- package/lib/browser/accounts/utils.d.ts +18 -0
- package/lib/browser/accounts/utils.js +32 -16
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +41 -0
- package/lib/browser/accounts/webSocketAccountSubscriber.js +41 -0
- package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +31 -0
- package/lib/browser/accounts/webSocketAccountSubscriberV2.js +31 -23
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +27 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +36 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +36 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +21 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +25 -0
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +21 -0
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +21 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +26 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.js +26 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +20 -0
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +121 -0
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +123 -2
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +96 -0
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +108 -0
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +28 -0
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +33 -0
- package/lib/browser/addresses/marketAddresses.d.ts +10 -0
- package/lib/browser/addresses/marketAddresses.js +10 -0
- package/lib/browser/addresses/pda.d.ts +214 -2
- package/lib/browser/addresses/pda.js +217 -5
- package/lib/browser/adminClient.d.ts +2136 -4
- package/lib/browser/adminClient.js +2150 -4
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +15 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +15 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +19 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +19 -0
- package/lib/browser/auctionSubscriber/index.d.ts +6 -0
- package/lib/browser/auctionSubscriber/index.js +6 -0
- package/lib/browser/auctionSubscriber/types.d.ts +7 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +33 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +33 -0
- package/lib/browser/blockhashSubscriber/index.d.ts +5 -0
- package/lib/browser/blockhashSubscriber/index.js +5 -0
- package/lib/browser/blockhashSubscriber/types.d.ts +5 -0
- package/lib/browser/clock/clockSubscriber.d.ts +24 -0
- package/lib/browser/clock/clockSubscriber.js +22 -0
- package/lib/browser/config.d.ts +58 -4
- package/lib/browser/config.js +88 -21
- package/lib/browser/constants/numericConstants.d.ts +67 -0
- package/lib/browser/constants/numericConstants.js +68 -1
- package/lib/browser/constants/perpMarkets.d.ts +10 -0
- package/lib/browser/constants/perpMarkets.js +40 -908
- package/lib/browser/constants/spotMarkets.d.ts +13 -0
- package/lib/browser/constants/spotMarkets.js +16 -742
- package/lib/browser/constants/txConstants.d.ts +1 -0
- package/lib/browser/constants/txConstants.js +1 -0
- package/lib/browser/core/VelocityCore.d.ts +285 -8
- package/lib/browser/core/VelocityCore.js +281 -8
- package/lib/browser/core/instructions/deposit.d.ts +22 -0
- package/lib/browser/core/instructions/deposit.js +22 -0
- package/lib/browser/core/instructions/fill.d.ts +17 -0
- package/lib/browser/core/instructions/fill.js +17 -0
- package/lib/browser/core/instructions/funding.d.ts +12 -0
- package/lib/browser/core/instructions/funding.js +12 -0
- package/lib/browser/core/instructions/liquidation.d.ts +18 -0
- package/lib/browser/core/instructions/liquidation.js +18 -0
- package/lib/browser/core/instructions/orders.d.ts +28 -0
- package/lib/browser/core/instructions/orders.js +28 -0
- package/lib/browser/core/instructions/perpOrders.d.ts +106 -0
- package/lib/browser/core/instructions/perpOrders.js +106 -0
- package/lib/browser/core/instructions/settlement.d.ts +14 -0
- package/lib/browser/core/instructions/settlement.js +14 -0
- package/lib/browser/core/instructions/trigger.d.ts +15 -0
- package/lib/browser/core/instructions/trigger.js +15 -0
- package/lib/browser/core/instructions/withdraw.d.ts +21 -0
- package/lib/browser/core/instructions/withdraw.js +21 -0
- package/lib/browser/core/remainingAccounts.d.ts +47 -3
- package/lib/browser/core/remainingAccounts.js +20 -0
- package/lib/browser/core/signedMsg.d.ts +38 -0
- package/lib/browser/core/signedMsg.js +33 -0
- package/lib/browser/decode/customCoder.d.ts +39 -3
- package/lib/browser/decode/customCoder.js +45 -3
- package/lib/browser/decode/user.d.ts +22 -0
- package/lib/browser/decode/user.js +22 -0
- package/lib/browser/dlob/DLOB.d.ts +502 -53
- package/lib/browser/dlob/DLOB.js +540 -98
- package/lib/browser/dlob/DLOBNode.d.ts +86 -4
- package/lib/browser/dlob/DLOBNode.js +37 -4
- package/lib/browser/dlob/DLOBSubscriber.d.ts +39 -12
- package/lib/browser/dlob/DLOBSubscriber.js +42 -12
- package/lib/browser/dlob/NodeList.d.ts +69 -0
- package/lib/browser/dlob/NodeList.js +66 -0
- package/lib/browser/dlob/orderBookLevels.d.ts +106 -13
- package/lib/browser/dlob/orderBookLevels.js +84 -14
- package/lib/browser/dlob/types.d.ts +15 -0
- package/lib/browser/events/eventList.d.ts +14 -0
- package/lib/browser/events/eventList.js +14 -0
- package/lib/browser/events/eventSubscriber.d.ts +87 -10
- package/lib/browser/events/eventSubscriber.js +93 -8
- package/lib/browser/events/eventsServerLogProvider.d.ts +22 -0
- package/lib/browser/events/eventsServerLogProvider.js +27 -0
- package/lib/browser/events/fetchLogs.d.ts +31 -0
- package/lib/browser/events/fetchLogs.js +46 -1
- package/lib/browser/events/parse.d.ts +23 -0
- package/lib/browser/events/parse.js +23 -0
- package/lib/browser/events/pollingLogProvider.d.ts +24 -0
- package/lib/browser/events/pollingLogProvider.js +24 -0
- package/lib/browser/events/sort.d.ts +11 -0
- package/lib/browser/events/sort.js +12 -0
- package/lib/browser/events/txEventCache.d.ts +13 -3
- package/lib/browser/events/txEventCache.js +19 -7
- package/lib/browser/events/types.d.ts +118 -2
- package/lib/browser/events/types.js +11 -0
- package/lib/browser/events/webSocketLogProvider.d.ts +23 -0
- package/lib/browser/events/webSocketLogProvider.js +28 -0
- package/lib/browser/factory/oracleClient.js +2 -2
- package/lib/browser/idl/velocity.d.ts +4 -4
- package/lib/browser/idl/velocity.json +4 -4
- package/lib/browser/keypair.d.ts +8 -0
- package/lib/browser/keypair.js +8 -0
- package/lib/browser/marginCalculation.d.ts +134 -2
- package/lib/browser/marginCalculation.js +121 -0
- package/lib/browser/math/amm.d.ts +348 -29
- package/lib/browser/math/amm.js +310 -32
- package/lib/browser/math/auction.d.ts +95 -19
- package/lib/browser/math/auction.js +118 -28
- package/lib/browser/math/bankruptcy.d.ts +46 -0
- package/lib/browser/math/bankruptcy.js +89 -1
- package/lib/browser/math/builder.d.ts +64 -8
- package/lib/browser/math/builder.js +71 -9
- package/lib/browser/math/conversion.d.ts +21 -0
- package/lib/browser/math/conversion.js +21 -0
- package/lib/browser/math/exchangeStatus.d.ts +91 -0
- package/lib/browser/math/exchangeStatus.js +106 -3
- package/lib/browser/math/funding.d.ts +57 -20
- package/lib/browser/math/funding.js +63 -23
- package/lib/browser/math/insurance.d.ts +62 -0
- package/lib/browser/math/insurance.js +62 -0
- package/lib/browser/math/liquidation.d.ts +127 -11
- package/lib/browser/math/liquidation.js +182 -19
- package/lib/browser/math/margin.d.ts +79 -13
- package/lib/browser/math/margin.js +80 -14
- package/lib/browser/math/market.d.ts +135 -15
- package/lib/browser/math/market.js +145 -17
- package/lib/browser/math/oracles.d.ts +113 -0
- package/lib/browser/math/oracles.js +118 -1
- package/lib/browser/math/orders.d.ts +115 -10
- package/lib/browser/math/orders.js +130 -19
- package/lib/browser/math/position.d.ts +80 -33
- package/lib/browser/math/position.js +80 -33
- package/lib/browser/math/repeg.d.ts +48 -10
- package/lib/browser/math/repeg.js +48 -10
- package/lib/browser/math/spotBalance.d.ts +200 -5
- package/lib/browser/math/spotBalance.js +239 -10
- package/lib/browser/math/spotMarket.d.ts +36 -3
- package/lib/browser/math/spotMarket.js +36 -3
- package/lib/browser/math/spotPosition.d.ts +72 -0
- package/lib/browser/math/spotPosition.js +62 -0
- package/lib/browser/math/state.d.ts +31 -0
- package/lib/browser/math/state.js +31 -0
- package/lib/browser/math/superStake.d.ts +126 -2
- package/lib/browser/math/superStake.js +123 -3
- package/lib/browser/math/tiers.d.ts +29 -0
- package/lib/browser/math/tiers.js +29 -0
- package/lib/browser/math/trade.d.ts +102 -51
- package/lib/browser/math/trade.js +101 -55
- package/lib/browser/math/utils.d.ts +71 -9
- package/lib/browser/math/utils.js +71 -9
- package/lib/browser/memcmp.d.ts +94 -0
- package/lib/browser/memcmp.js +103 -2
- package/lib/browser/oracles/oracleClientCache.d.ts +16 -0
- package/lib/browser/oracles/oracleClientCache.js +16 -0
- package/lib/browser/oracles/oracleId.d.ts +31 -0
- package/lib/browser/oracles/oracleId.js +39 -8
- package/lib/browser/oracles/prelaunchOracleClient.d.ts +20 -0
- package/lib/browser/oracles/prelaunchOracleClient.js +20 -0
- package/lib/browser/oracles/pythClient.d.ts +31 -0
- package/lib/browser/oracles/pythClient.js +32 -1
- package/lib/browser/oracles/pythLazerClient.d.ts +34 -0
- package/lib/browser/oracles/pythLazerClient.js +35 -1
- package/lib/browser/oracles/quoteAssetOracleClient.d.ts +18 -0
- package/lib/browser/oracles/quoteAssetOracleClient.js +18 -0
- package/lib/browser/oracles/strictOraclePrice.d.ts +21 -0
- package/lib/browser/oracles/strictOraclePrice.js +21 -0
- package/lib/browser/oracles/types.d.ts +45 -0
- package/lib/browser/oracles/utils.d.ts +20 -0
- package/lib/browser/oracles/utils.js +20 -0
- package/lib/browser/orderParams.d.ts +42 -4
- package/lib/browser/orderParams.js +42 -4
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +56 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.js +56 -0
- package/lib/browser/orderSubscriber/PollingSubscription.d.ts +11 -0
- package/lib/browser/orderSubscriber/PollingSubscription.js +11 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.d.ts +18 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +18 -0
- package/lib/browser/orderSubscriber/grpcSubscription.d.ts +16 -0
- package/lib/browser/orderSubscriber/grpcSubscription.js +16 -0
- package/lib/browser/orderSubscriber/types.d.ts +9 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.d.ts +1 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.js +1 -0
- package/lib/browser/priorityFee/averageStrategy.d.ts +1 -0
- package/lib/browser/priorityFee/averageStrategy.js +1 -0
- package/lib/browser/priorityFee/ewmaStrategy.d.ts +10 -0
- package/lib/browser/priorityFee/ewmaStrategy.js +10 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +13 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.js +9 -2
- package/lib/browser/priorityFee/maxOverSlotsStrategy.d.ts +1 -0
- package/lib/browser/priorityFee/maxOverSlotsStrategy.js +1 -0
- package/lib/browser/priorityFee/maxStrategy.d.ts +1 -0
- package/lib/browser/priorityFee/maxStrategy.js +1 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +39 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +39 -0
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +20 -1
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +21 -2
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +12 -0
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.js +10 -0
- package/lib/browser/priorityFee/types.d.ts +32 -0
- package/lib/browser/priorityFee/types.js +5 -0
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +11 -0
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +8 -0
- package/lib/browser/slot/SlotSubscriber.d.ts +18 -0
- package/lib/browser/slot/SlotSubscriber.js +16 -0
- package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/browser/slot/SlothashSubscriber.js +25 -1
- package/lib/browser/tx/baseTxSender.d.ts +163 -0
- package/lib/browser/tx/baseTxSender.js +174 -6
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +12 -0
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.js +12 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +15 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.js +15 -0
- package/lib/browser/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/browser/tx/fastSingleTxSender.d.ts +47 -0
- package/lib/browser/tx/fastSingleTxSender.js +48 -1
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +48 -0
- package/lib/browser/tx/forwardOnlyTxSender.js +48 -0
- package/lib/browser/tx/reportTransactionError.d.ts +18 -6
- package/lib/browser/tx/reportTransactionError.js +18 -6
- package/lib/browser/tx/retryTxSender.d.ts +40 -0
- package/lib/browser/tx/retryTxSender.js +39 -0
- package/lib/browser/tx/txHandler.d.ts +146 -35
- package/lib/browser/tx/txHandler.js +132 -32
- package/lib/browser/tx/txParamProcessor.d.ts +47 -0
- package/lib/browser/tx/txParamProcessor.js +47 -0
- package/lib/browser/tx/types.d.ts +46 -0
- package/lib/browser/tx/types.js +5 -0
- package/lib/browser/tx/utils.d.ts +26 -0
- package/lib/browser/tx/utils.js +26 -0
- package/lib/browser/tx/whileValidTxSender.d.ts +82 -0
- package/lib/browser/tx/whileValidTxSender.js +81 -0
- package/lib/browser/types.d.ts +781 -13
- package/lib/browser/types.js +126 -9
- package/lib/browser/user.d.ts +645 -84
- package/lib/browser/user.js +779 -96
- package/lib/browser/userMap/PollingSubscription.d.ts +10 -0
- package/lib/browser/userMap/PollingSubscription.js +14 -2
- package/lib/browser/userMap/WebsocketSubscription.d.ts +9 -0
- package/lib/browser/userMap/WebsocketSubscription.js +9 -0
- package/lib/browser/userMap/grpcSubscription.d.ts +8 -0
- package/lib/browser/userMap/grpcSubscription.js +8 -0
- package/lib/browser/userMap/referrerMap.d.ts +72 -2
- package/lib/browser/userMap/referrerMap.js +84 -2
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +37 -10
- package/lib/browser/userMap/revenueShareEscrowMap.js +38 -11
- package/lib/browser/userMap/userMap.d.ts +81 -3
- package/lib/browser/userMap/userMap.js +81 -4
- package/lib/browser/userMap/userMapConfig.d.ts +23 -0
- package/lib/browser/userMap/userStatsMap.d.ts +22 -0
- package/lib/browser/userMap/userStatsMap.js +22 -0
- package/lib/browser/userName.d.ts +16 -0
- package/lib/browser/userName.js +16 -0
- package/lib/browser/userStats.d.ts +28 -1
- package/lib/browser/userStats.js +28 -1
- package/lib/browser/util/TransactionConfirmationManager.d.ts +33 -0
- package/lib/browser/util/TransactionConfirmationManager.js +33 -0
- package/lib/browser/util/chainClock.d.ts +24 -0
- package/lib/browser/util/chainClock.js +20 -0
- package/lib/browser/util/computeUnits.d.ts +32 -0
- package/lib/browser/util/computeUnits.js +32 -0
- package/lib/browser/util/digest.d.ts +17 -0
- package/lib/browser/util/digest.js +17 -0
- package/lib/browser/util/ed25519Utils.d.ts +12 -2
- package/lib/browser/util/ed25519Utils.js +12 -2
- package/lib/browser/util/promiseTimeout.d.ts +9 -0
- package/lib/browser/util/promiseTimeout.js +9 -0
- package/lib/browser/velocityClient.d.ts +3322 -215
- package/lib/browser/velocityClient.js +3412 -245
- package/lib/browser/wallet.d.ts +37 -0
- package/lib/browser/wallet.js +37 -0
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserAccountSubscriber.js +18 -0
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserStatsAccountSubscriber.js +18 -0
- package/lib/node/accounts/bulkAccountLoader.d.ts +52 -0
- package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/bulkAccountLoader.js +51 -0
- package/lib/node/accounts/bulkUserStatsSubscription.d.ts +9 -2
- package/lib/node/accounts/bulkUserStatsSubscription.d.ts.map +1 -1
- package/lib/node/accounts/bulkUserStatsSubscription.js +9 -2
- package/lib/node/accounts/bulkUserSubscription.d.ts +8 -2
- package/lib/node/accounts/bulkUserSubscription.d.ts.map +1 -1
- package/lib/node/accounts/bulkUserSubscription.js +8 -2
- package/lib/node/accounts/customizedCadenceBulkAccountLoader.d.ts +37 -0
- package/lib/node/accounts/customizedCadenceBulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/customizedCadenceBulkAccountLoader.js +37 -0
- package/lib/node/accounts/fetch.d.ts +59 -2
- package/lib/node/accounts/fetch.d.ts.map +1 -1
- package/lib/node/accounts/fetch.js +57 -2
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +30 -0
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcAccountSubscriber.js +30 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +16 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +16 -0
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +60 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +118 -37
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +32 -0
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +40 -12
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +33 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +33 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +15 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcUserAccountSubscriber.js +15 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +15 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +15 -0
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +41 -0
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +41 -0
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +116 -0
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +152 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +34 -0
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +34 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +19 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +19 -0
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts +19 -0
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +19 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +31 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +31 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +19 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +21 -2
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +22 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +22 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +32 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserAccountSubscriber.js +32 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +22 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +22 -0
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +83 -0
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +84 -1
- package/lib/node/accounts/testBulkAccountLoader.d.ts +8 -0
- package/lib/node/accounts/testBulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/testBulkAccountLoader.js +8 -0
- package/lib/node/accounts/types.d.ts +149 -0
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/types.js +13 -0
- package/lib/node/accounts/utils.d.ts +18 -0
- package/lib/node/accounts/utils.d.ts.map +1 -1
- package/lib/node/accounts/utils.js +32 -16
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +41 -0
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.js +41 -0
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +31 -0
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriberV2.js +31 -23
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +27 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +36 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +36 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +21 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +25 -0
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +21 -0
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +21 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +26 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +26 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +20 -0
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +121 -0
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +123 -2
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +96 -0
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +108 -0
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +28 -0
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +33 -0
- package/lib/node/addresses/marketAddresses.d.ts +10 -0
- package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
- package/lib/node/addresses/marketAddresses.js +10 -0
- package/lib/node/addresses/pda.d.ts +214 -2
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +217 -5
- package/lib/node/adminClient.d.ts +2136 -4
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +2150 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +15 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +15 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +19 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +19 -0
- package/lib/node/auctionSubscriber/index.d.ts +6 -0
- package/lib/node/auctionSubscriber/index.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/index.js +6 -0
- package/lib/node/auctionSubscriber/types.d.ts +7 -0
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +33 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +33 -0
- package/lib/node/blockhashSubscriber/index.d.ts +5 -0
- package/lib/node/blockhashSubscriber/index.d.ts.map +1 -1
- package/lib/node/blockhashSubscriber/index.js +5 -0
- package/lib/node/blockhashSubscriber/types.d.ts +5 -0
- package/lib/node/blockhashSubscriber/types.d.ts.map +1 -1
- package/lib/node/clock/clockSubscriber.d.ts +24 -0
- package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
- package/lib/node/clock/clockSubscriber.js +22 -0
- package/lib/node/config.d.ts +58 -4
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +88 -21
- package/lib/node/constants/numericConstants.d.ts +67 -0
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +68 -1
- package/lib/node/constants/perpMarkets.d.ts +10 -0
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +40 -908
- package/lib/node/constants/spotMarkets.d.ts +13 -0
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constants/spotMarkets.js +16 -742
- package/lib/node/constants/txConstants.d.ts +1 -0
- package/lib/node/constants/txConstants.d.ts.map +1 -1
- package/lib/node/constants/txConstants.js +1 -0
- package/lib/node/core/VelocityCore.d.ts +285 -8
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +281 -8
- package/lib/node/core/instructions/deposit.d.ts +22 -0
- package/lib/node/core/instructions/deposit.d.ts.map +1 -1
- package/lib/node/core/instructions/deposit.js +22 -0
- package/lib/node/core/instructions/fill.d.ts +17 -0
- package/lib/node/core/instructions/fill.d.ts.map +1 -1
- package/lib/node/core/instructions/fill.js +17 -0
- package/lib/node/core/instructions/funding.d.ts +12 -0
- package/lib/node/core/instructions/funding.d.ts.map +1 -1
- package/lib/node/core/instructions/funding.js +12 -0
- package/lib/node/core/instructions/liquidation.d.ts +18 -0
- package/lib/node/core/instructions/liquidation.d.ts.map +1 -1
- package/lib/node/core/instructions/liquidation.js +18 -0
- package/lib/node/core/instructions/orders.d.ts +28 -0
- package/lib/node/core/instructions/orders.d.ts.map +1 -1
- package/lib/node/core/instructions/orders.js +28 -0
- package/lib/node/core/instructions/perpOrders.d.ts +106 -0
- package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
- package/lib/node/core/instructions/perpOrders.js +106 -0
- package/lib/node/core/instructions/settlement.d.ts +14 -0
- package/lib/node/core/instructions/settlement.d.ts.map +1 -1
- package/lib/node/core/instructions/settlement.js +14 -0
- package/lib/node/core/instructions/trigger.d.ts +15 -0
- package/lib/node/core/instructions/trigger.d.ts.map +1 -1
- package/lib/node/core/instructions/trigger.js +15 -0
- package/lib/node/core/instructions/withdraw.d.ts +21 -0
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
- package/lib/node/core/instructions/withdraw.js +21 -0
- package/lib/node/core/remainingAccounts.d.ts +47 -3
- package/lib/node/core/remainingAccounts.d.ts.map +1 -1
- package/lib/node/core/remainingAccounts.js +20 -0
- package/lib/node/core/signedMsg.d.ts +38 -0
- package/lib/node/core/signedMsg.d.ts.map +1 -1
- package/lib/node/core/signedMsg.js +33 -0
- package/lib/node/decode/customCoder.d.ts +39 -3
- package/lib/node/decode/customCoder.d.ts.map +1 -1
- package/lib/node/decode/customCoder.js +45 -3
- package/lib/node/decode/user.d.ts +22 -0
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +22 -0
- package/lib/node/dlob/DLOB.d.ts +502 -53
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +540 -98
- package/lib/node/dlob/DLOBNode.d.ts +86 -4
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.js +37 -4
- package/lib/node/dlob/DLOBSubscriber.d.ts +39 -12
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +42 -12
- package/lib/node/dlob/NodeList.d.ts +69 -0
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.js +66 -0
- package/lib/node/dlob/orderBookLevels.d.ts +106 -13
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +84 -14
- package/lib/node/dlob/types.d.ts +15 -0
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/events/eventList.d.ts +14 -0
- package/lib/node/events/eventList.d.ts.map +1 -1
- package/lib/node/events/eventList.js +14 -0
- package/lib/node/events/eventSubscriber.d.ts +87 -10
- package/lib/node/events/eventSubscriber.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.js +93 -8
- package/lib/node/events/eventsServerLogProvider.d.ts +22 -0
- package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
- package/lib/node/events/eventsServerLogProvider.js +27 -0
- package/lib/node/events/fetchLogs.d.ts +31 -0
- package/lib/node/events/fetchLogs.d.ts.map +1 -1
- package/lib/node/events/fetchLogs.js +46 -1
- package/lib/node/events/parse.d.ts +23 -0
- package/lib/node/events/parse.d.ts.map +1 -1
- package/lib/node/events/parse.js +23 -0
- package/lib/node/events/pollingLogProvider.d.ts +24 -0
- package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
- package/lib/node/events/pollingLogProvider.js +24 -0
- package/lib/node/events/sort.d.ts +11 -0
- package/lib/node/events/sort.d.ts.map +1 -1
- package/lib/node/events/sort.js +12 -0
- package/lib/node/events/txEventCache.d.ts +13 -3
- package/lib/node/events/txEventCache.d.ts.map +1 -1
- package/lib/node/events/txEventCache.js +19 -7
- package/lib/node/events/types.d.ts +118 -2
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +11 -0
- package/lib/node/events/webSocketLogProvider.d.ts +23 -0
- package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
- package/lib/node/events/webSocketLogProvider.js +28 -0
- package/lib/node/factory/oracleClient.js +2 -2
- package/lib/node/idl/velocity.d.ts +4 -4
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +4 -4
- package/lib/node/keypair.d.ts +8 -0
- package/lib/node/keypair.d.ts.map +1 -1
- package/lib/node/keypair.js +8 -0
- package/lib/node/marginCalculation.d.ts +134 -2
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marginCalculation.js +121 -0
- package/lib/node/math/amm.d.ts +348 -29
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +310 -32
- package/lib/node/math/auction.d.ts +95 -19
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +118 -28
- package/lib/node/math/bankruptcy.d.ts +46 -0
- package/lib/node/math/bankruptcy.d.ts.map +1 -1
- package/lib/node/math/bankruptcy.js +89 -1
- package/lib/node/math/builder.d.ts +64 -8
- package/lib/node/math/builder.d.ts.map +1 -1
- package/lib/node/math/builder.js +71 -9
- package/lib/node/math/conversion.d.ts +21 -0
- package/lib/node/math/conversion.d.ts.map +1 -1
- package/lib/node/math/conversion.js +21 -0
- package/lib/node/math/exchangeStatus.d.ts +91 -0
- package/lib/node/math/exchangeStatus.d.ts.map +1 -1
- package/lib/node/math/exchangeStatus.js +106 -3
- package/lib/node/math/funding.d.ts +57 -20
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +63 -23
- package/lib/node/math/insurance.d.ts +62 -0
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/insurance.js +62 -0
- package/lib/node/math/liquidation.d.ts +127 -11
- package/lib/node/math/liquidation.d.ts.map +1 -1
- package/lib/node/math/liquidation.js +182 -19
- package/lib/node/math/margin.d.ts +79 -13
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +80 -14
- package/lib/node/math/market.d.ts +135 -15
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +145 -17
- package/lib/node/math/oracles.d.ts +113 -0
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +118 -1
- package/lib/node/math/orders.d.ts +115 -10
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +130 -19
- package/lib/node/math/position.d.ts +80 -33
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +80 -33
- package/lib/node/math/repeg.d.ts +48 -10
- package/lib/node/math/repeg.d.ts.map +1 -1
- package/lib/node/math/repeg.js +48 -10
- package/lib/node/math/spotBalance.d.ts +200 -5
- package/lib/node/math/spotBalance.d.ts.map +1 -1
- package/lib/node/math/spotBalance.js +239 -10
- package/lib/node/math/spotMarket.d.ts +36 -3
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotMarket.js +36 -3
- package/lib/node/math/spotPosition.d.ts +72 -0
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/spotPosition.js +62 -0
- package/lib/node/math/state.d.ts +31 -0
- package/lib/node/math/state.d.ts.map +1 -1
- package/lib/node/math/state.js +31 -0
- package/lib/node/math/superStake.d.ts +126 -2
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +123 -3
- package/lib/node/math/tiers.d.ts +29 -0
- package/lib/node/math/tiers.d.ts.map +1 -1
- package/lib/node/math/tiers.js +29 -0
- package/lib/node/math/trade.d.ts +102 -51
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +101 -55
- package/lib/node/math/utils.d.ts +71 -9
- package/lib/node/math/utils.d.ts.map +1 -1
- package/lib/node/math/utils.js +71 -9
- package/lib/node/memcmp.d.ts +94 -0
- package/lib/node/memcmp.d.ts.map +1 -1
- package/lib/node/memcmp.js +103 -2
- package/lib/node/oracles/oracleClientCache.d.ts +16 -0
- package/lib/node/oracles/oracleClientCache.d.ts.map +1 -1
- package/lib/node/oracles/oracleClientCache.js +16 -0
- package/lib/node/oracles/oracleId.d.ts +31 -0
- package/lib/node/oracles/oracleId.d.ts.map +1 -1
- package/lib/node/oracles/oracleId.js +39 -8
- package/lib/node/oracles/prelaunchOracleClient.d.ts +20 -0
- package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
- package/lib/node/oracles/prelaunchOracleClient.js +20 -0
- package/lib/node/oracles/pythClient.d.ts +31 -0
- package/lib/node/oracles/pythClient.d.ts.map +1 -1
- package/lib/node/oracles/pythClient.js +32 -1
- package/lib/node/oracles/pythLazerClient.d.ts +34 -0
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +35 -1
- package/lib/node/oracles/quoteAssetOracleClient.d.ts +18 -0
- package/lib/node/oracles/quoteAssetOracleClient.d.ts.map +1 -1
- package/lib/node/oracles/quoteAssetOracleClient.js +18 -0
- package/lib/node/oracles/strictOraclePrice.d.ts +21 -0
- package/lib/node/oracles/strictOraclePrice.d.ts.map +1 -1
- package/lib/node/oracles/strictOraclePrice.js +21 -0
- package/lib/node/oracles/types.d.ts +45 -0
- package/lib/node/oracles/types.d.ts.map +1 -1
- package/lib/node/oracles/utils.d.ts +20 -0
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/oracles/utils.js +20 -0
- package/lib/node/orderParams.d.ts +42 -4
- package/lib/node/orderParams.d.ts.map +1 -1
- package/lib/node/orderParams.js +42 -4
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +56 -0
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +56 -0
- package/lib/node/orderSubscriber/PollingSubscription.d.ts +11 -0
- package/lib/node/orderSubscriber/PollingSubscription.d.ts.map +1 -1
- package/lib/node/orderSubscriber/PollingSubscription.js +11 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +18 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/orderSubscriber/WebsocketSubscription.js +18 -0
- package/lib/node/orderSubscriber/grpcSubscription.d.ts +16 -0
- package/lib/node/orderSubscriber/grpcSubscription.d.ts.map +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.js +16 -0
- package/lib/node/orderSubscriber/types.d.ts +9 -0
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +1 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts.map +1 -1
- package/lib/node/priorityFee/averageOverSlotsStrategy.js +1 -0
- package/lib/node/priorityFee/averageStrategy.d.ts +1 -0
- package/lib/node/priorityFee/averageStrategy.d.ts.map +1 -1
- package/lib/node/priorityFee/averageStrategy.js +1 -0
- package/lib/node/priorityFee/ewmaStrategy.d.ts +10 -0
- package/lib/node/priorityFee/ewmaStrategy.d.ts.map +1 -1
- package/lib/node/priorityFee/ewmaStrategy.js +10 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +13 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/heliusPriorityFeeMethod.js +9 -2
- package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +1 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts.map +1 -1
- package/lib/node/priorityFee/maxOverSlotsStrategy.js +1 -0
- package/lib/node/priorityFee/maxStrategy.d.ts +1 -0
- package/lib/node/priorityFee/maxStrategy.d.ts.map +1 -1
- package/lib/node/priorityFee/maxStrategy.js +1 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +39 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +39 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +20 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +21 -2
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +12 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/solanaPriorityFeeMethod.js +10 -0
- package/lib/node/priorityFee/types.d.ts +32 -0
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/types.js +5 -0
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +11 -0
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/velocityPriorityFeeMethod.js +8 -0
- package/lib/node/slot/SlotSubscriber.d.ts +18 -0
- package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlotSubscriber.js +16 -0
- package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlothashSubscriber.js +25 -1
- package/lib/node/tx/baseTxSender.d.ts +163 -0
- package/lib/node/tx/baseTxSender.d.ts.map +1 -1
- package/lib/node/tx/baseTxSender.js +174 -6
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +12 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts.map +1 -1
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +12 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +15 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts.map +1 -1
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +15 -0
- package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/node/tx/blockhashFetcher/types.d.ts.map +1 -1
- package/lib/node/tx/fastSingleTxSender.d.ts +47 -0
- package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
- package/lib/node/tx/fastSingleTxSender.js +48 -1
- package/lib/node/tx/forwardOnlyTxSender.d.ts +48 -0
- package/lib/node/tx/forwardOnlyTxSender.d.ts.map +1 -1
- package/lib/node/tx/forwardOnlyTxSender.js +48 -0
- package/lib/node/tx/reportTransactionError.d.ts +18 -6
- package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
- package/lib/node/tx/reportTransactionError.js +18 -6
- package/lib/node/tx/retryTxSender.d.ts +40 -0
- package/lib/node/tx/retryTxSender.d.ts.map +1 -1
- package/lib/node/tx/retryTxSender.js +39 -0
- package/lib/node/tx/txHandler.d.ts +146 -35
- package/lib/node/tx/txHandler.d.ts.map +1 -1
- package/lib/node/tx/txHandler.js +132 -32
- package/lib/node/tx/txParamProcessor.d.ts +47 -0
- package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
- package/lib/node/tx/txParamProcessor.js +47 -0
- package/lib/node/tx/types.d.ts +46 -0
- package/lib/node/tx/types.d.ts.map +1 -1
- package/lib/node/tx/types.js +5 -0
- package/lib/node/tx/utils.d.ts +26 -0
- package/lib/node/tx/utils.d.ts.map +1 -1
- package/lib/node/tx/utils.js +26 -0
- package/lib/node/tx/whileValidTxSender.d.ts +82 -0
- package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
- package/lib/node/tx/whileValidTxSender.js +81 -0
- package/lib/node/types.d.ts +781 -13
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +126 -9
- package/lib/node/user.d.ts +645 -84
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +779 -96
- package/lib/node/userMap/PollingSubscription.d.ts +10 -0
- package/lib/node/userMap/PollingSubscription.d.ts.map +1 -1
- package/lib/node/userMap/PollingSubscription.js +14 -2
- package/lib/node/userMap/WebsocketSubscription.d.ts +9 -0
- package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.js +9 -0
- package/lib/node/userMap/grpcSubscription.d.ts +8 -0
- package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
- package/lib/node/userMap/grpcSubscription.js +8 -0
- package/lib/node/userMap/referrerMap.d.ts +72 -2
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +84 -2
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +37 -10
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +38 -11
- package/lib/node/userMap/userMap.d.ts +81 -3
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +81 -4
- package/lib/node/userMap/userMapConfig.d.ts +23 -0
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +22 -0
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +22 -0
- package/lib/node/userName.d.ts +16 -0
- package/lib/node/userName.d.ts.map +1 -1
- package/lib/node/userName.js +16 -0
- package/lib/node/userStats.d.ts +28 -1
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +28 -1
- package/lib/node/util/TransactionConfirmationManager.d.ts +33 -0
- package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
- package/lib/node/util/TransactionConfirmationManager.js +33 -0
- package/lib/node/util/chainClock.d.ts +24 -0
- package/lib/node/util/chainClock.d.ts.map +1 -1
- package/lib/node/util/chainClock.js +20 -0
- package/lib/node/util/computeUnits.d.ts +32 -0
- package/lib/node/util/computeUnits.d.ts.map +1 -1
- package/lib/node/util/computeUnits.js +32 -0
- package/lib/node/util/digest.d.ts +17 -0
- package/lib/node/util/digest.d.ts.map +1 -1
- package/lib/node/util/digest.js +17 -0
- package/lib/node/util/ed25519Utils.d.ts +12 -2
- package/lib/node/util/ed25519Utils.d.ts.map +1 -1
- package/lib/node/util/ed25519Utils.js +12 -2
- package/lib/node/util/promiseTimeout.d.ts +9 -0
- package/lib/node/util/promiseTimeout.d.ts.map +1 -1
- package/lib/node/util/promiseTimeout.js +9 -0
- package/lib/node/velocityClient.d.ts +3322 -215
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +3412 -245
- package/lib/node/wallet.d.ts +37 -0
- package/lib/node/wallet.d.ts.map +1 -1
- package/lib/node/wallet.js +37 -0
- package/package.json +2 -1
- package/src/accounts/basicUserAccountSubscriber.ts +18 -0
- package/src/accounts/basicUserStatsAccountSubscriber.ts +18 -0
- package/src/accounts/bulkAccountLoader.ts +52 -0
- package/src/accounts/bulkUserStatsSubscription.ts +9 -2
- package/src/accounts/bulkUserSubscription.ts +8 -2
- package/src/accounts/customizedCadenceBulkAccountLoader.ts +37 -0
- package/src/accounts/fetch.ts +59 -2
- package/src/accounts/grpcAccountSubscriber.ts +30 -0
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +16 -0
- package/src/accounts/grpcMultiAccountSubscriber.ts +121 -38
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +49 -11
- package/src/accounts/grpcProgramAccountSubscriber.ts +33 -0
- package/src/accounts/grpcUserAccountSubscriber.ts +15 -0
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +15 -0
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +41 -0
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +160 -1
- package/src/accounts/laserProgramAccountSubscriber.ts +34 -0
- package/src/accounts/oneShotUserAccountSubscriber.ts +19 -0
- package/src/accounts/oneShotUserStatsAccountSubscriber.ts +19 -0
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +31 -0
- package/src/accounts/pollingOracleAccountSubscriber.ts +21 -2
- package/src/accounts/pollingTokenAccountSubscriber.ts +22 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +32 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +22 -0
- package/src/accounts/pollingVelocityClientAccountSubscriber.ts +84 -1
- package/src/accounts/testBulkAccountLoader.ts +8 -0
- package/src/accounts/types.ts +149 -0
- package/src/accounts/utils.ts +42 -24
- package/src/accounts/webSocketAccountSubscriber.ts +41 -0
- package/src/accounts/webSocketAccountSubscriberV2.ts +31 -23
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +27 -0
- package/src/accounts/webSocketProgramAccountSubscriber.ts +36 -0
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +26 -0
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +21 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +26 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +20 -0
- package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +127 -2
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +110 -0
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +33 -0
- package/src/addresses/marketAddresses.ts +10 -0
- package/src/addresses/pda.ts +228 -12
- package/src/adminClient.ts +2156 -4
- package/src/auctionSubscriber/auctionSubscriber.ts +15 -0
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +19 -0
- package/src/auctionSubscriber/index.ts +6 -0
- package/src/auctionSubscriber/types.ts +7 -0
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +33 -0
- package/src/blockhashSubscriber/index.ts +5 -0
- package/src/blockhashSubscriber/types.ts +5 -4
- package/src/clock/clockSubscriber.ts +24 -0
- package/src/config.ts +109 -22
- package/src/constants/numericConstants.ts +70 -0
- package/src/constants/perpMarkets.ts +45 -960
- package/src/constants/spotMarkets.ts +23 -793
- package/src/constants/txConstants.ts +1 -0
- package/src/core/VelocityCore.ts +286 -8
- package/src/core/instructions/deposit.ts +22 -0
- package/src/core/instructions/fill.ts +17 -0
- package/src/core/instructions/funding.ts +12 -0
- package/src/core/instructions/liquidation.ts +18 -0
- package/src/core/instructions/orders.ts +28 -0
- package/src/core/instructions/perpOrders.ts +106 -0
- package/src/core/instructions/settlement.ts +14 -0
- package/src/core/instructions/trigger.ts +15 -0
- package/src/core/instructions/withdraw.ts +21 -0
- package/src/core/remainingAccounts.ts +47 -3
- package/src/core/signedMsg.ts +38 -0
- package/src/decode/customCoder.ts +46 -3
- package/src/decode/user.ts +22 -0
- package/src/dlob/DLOB.ts +668 -97
- package/src/dlob/DLOBNode.ts +98 -6
- package/src/dlob/DLOBSubscriber.ts +49 -12
- package/src/dlob/NodeList.ts +69 -0
- package/src/dlob/orderBookLevels.ts +108 -14
- package/src/dlob/types.ts +15 -0
- package/src/events/eventList.ts +14 -0
- package/src/events/eventSubscriber.ts +100 -19
- package/src/events/eventsServerLogProvider.ts +28 -0
- package/src/events/fetchLogs.ts +52 -2
- package/src/events/parse.ts +23 -0
- package/src/events/pollingLogProvider.ts +24 -0
- package/src/events/sort.ts +12 -0
- package/src/events/txEventCache.ts +19 -7
- package/src/events/types.ts +131 -11
- package/src/events/webSocketLogProvider.ts +29 -0
- package/src/factory/oracleClient.ts +2 -2
- package/src/idl/velocity.json +4 -4
- package/src/idl/velocity.ts +4 -4
- package/src/keypair.ts +8 -0
- package/src/marginCalculation.ts +153 -2
- package/src/math/amm.ts +371 -36
- package/src/math/auction.ts +139 -30
- package/src/math/bankruptcy.ts +104 -1
- package/src/math/builder.ts +74 -8
- package/src/math/conversion.ts +21 -0
- package/src/math/exchangeStatus.ts +117 -2
- package/src/math/funding.ts +63 -23
- package/src/math/insurance.ts +62 -0
- package/src/math/liquidation.ts +227 -17
- package/src/math/margin.ts +80 -14
- package/src/math/market.ts +148 -17
- package/src/math/oracles.ts +124 -0
- package/src/math/orders.ts +141 -19
- package/src/math/position.ts +80 -33
- package/src/math/repeg.ts +48 -10
- package/src/math/spotBalance.ts +252 -12
- package/src/math/spotMarket.ts +36 -3
- package/src/math/spotPosition.ts +72 -0
- package/src/math/state.ts +31 -0
- package/src/math/superStake.ts +126 -3
- package/src/math/tiers.ts +29 -0
- package/src/math/trade.ts +125 -55
- package/src/math/utils.ts +71 -9
- package/src/memcmp.ts +104 -2
- package/src/oracles/oracleClientCache.ts +16 -0
- package/src/oracles/oracleId.ts +39 -6
- package/src/oracles/prelaunchOracleClient.ts +20 -0
- package/src/oracles/pythClient.ts +32 -1
- package/src/oracles/pythLazerClient.ts +35 -1
- package/src/oracles/quoteAssetOracleClient.ts +18 -0
- package/src/oracles/strictOraclePrice.ts +21 -0
- package/src/oracles/types.ts +45 -0
- package/src/oracles/utils.ts +20 -0
- package/src/orderParams.ts +42 -4
- package/src/orderSubscriber/OrderSubscriber.ts +56 -0
- package/src/orderSubscriber/PollingSubscription.ts +11 -0
- package/src/orderSubscriber/WebsocketSubscription.ts +18 -0
- package/src/orderSubscriber/grpcSubscription.ts +16 -0
- package/src/orderSubscriber/types.ts +9 -0
- package/src/priorityFee/averageOverSlotsStrategy.ts +1 -0
- package/src/priorityFee/averageStrategy.ts +1 -0
- package/src/priorityFee/ewmaStrategy.ts +10 -0
- package/src/priorityFee/heliusPriorityFeeMethod.ts +13 -2
- package/src/priorityFee/maxOverSlotsStrategy.ts +1 -0
- package/src/priorityFee/maxStrategy.ts +1 -0
- package/src/priorityFee/priorityFeeSubscriber.ts +39 -0
- package/src/priorityFee/priorityFeeSubscriberMap.ts +21 -2
- package/src/priorityFee/solanaPriorityFeeMethod.ts +12 -0
- package/src/priorityFee/types.ts +33 -15
- package/src/priorityFee/velocityPriorityFeeMethod.ts +11 -0
- package/src/slot/SlotSubscriber.ts +18 -0
- package/src/slot/SlothashSubscriber.ts +27 -1
- package/src/tx/baseTxSender.ts +185 -5
- package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +12 -0
- package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +15 -0
- package/src/tx/blockhashFetcher/types.ts +4 -0
- package/src/tx/fastSingleTxSender.ts +58 -4
- package/src/tx/forwardOnlyTxSender.ts +48 -0
- package/src/tx/reportTransactionError.ts +18 -6
- package/src/tx/retryTxSender.ts +40 -0
- package/src/tx/txHandler.ts +146 -35
- package/src/tx/txParamProcessor.ts +47 -0
- package/src/tx/types.ts +46 -0
- package/src/tx/utils.ts +26 -0
- package/src/tx/whileValidTxSender.ts +82 -0
- package/src/types.ts +777 -24
- package/src/user.ts +869 -110
- package/src/userMap/PollingSubscription.ts +16 -2
- package/src/userMap/WebsocketSubscription.ts +9 -0
- package/src/userMap/grpcSubscription.ts +8 -0
- package/src/userMap/referrerMap.ts +92 -3
- package/src/userMap/revenueShareEscrowMap.ts +38 -11
- package/src/userMap/userMap.ts +82 -4
- package/src/userMap/userMapConfig.ts +23 -10
- package/src/userMap/userStatsMap.ts +22 -0
- package/src/userName.ts +16 -0
- package/src/userStats.ts +28 -1
- package/src/util/TransactionConfirmationManager.ts +33 -0
- package/src/util/chainClock.ts +24 -0
- package/src/util/computeUnits.ts +32 -0
- package/src/util/digest.ts +17 -0
- package/src/util/ed25519Utils.ts +12 -2
- package/src/util/promiseTimeout.ts +9 -0
- package/src/velocityClient.ts +3439 -249
- package/src/wallet.ts +37 -0
- package/tests/VelocityCore/builder_escrow.test.ts +121 -0
- package/tests/amm/test.ts +102 -0
- package/tests/builder/builderFee.test.ts +42 -0
- package/tests/dlob/tickSizeStandardization.ts +545 -0
- package/tests/exchangeStatus/test.ts +45 -0
- package/tests/liquidation/test.ts +125 -0
- package/tests/oracles/mmOracleGate.test.ts +379 -0
- package/tests/oracles/pythPegSnap.test.ts +76 -0
- package/tests/sdkParity/enumParity.test.ts +84 -0
- package/tests/sdkParity/marginCategoryFill.test.ts +143 -0
- package/tests/sdkParity/memcmpOffsets.test.ts +139 -0
- package/tests/spot/test.ts +55 -0
- package/tests/user/bankruptcy.ts +165 -0
- package/tests/user/feeAndWithdrawLimits.ts +284 -0
- package/tests/user/getMarginCalculation.ts +226 -1
- package/tests/user/test.ts +8 -4
package/lib/node/dlob/DLOB.js
CHANGED
|
@@ -8,9 +8,9 @@ exports.DLOB = void 0;
|
|
|
8
8
|
* Used by keeper bots to identify the best maker orders to match against taker fills.
|
|
9
9
|
*
|
|
10
10
|
* Key types:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* `DLOBNode` — a single order node with price/size/user info (DLOBNode.ts)
|
|
12
|
+
* `DLOBSubscriber` — subscribes to on-chain accounts and keeps the DLOB live (DLOBSubscriber.ts)
|
|
13
|
+
* `NodeList` — sorted linked list of DLOBNodes per side/market (NodeList.ts)
|
|
14
14
|
* `orderBookLevels.ts` — aggregated L2/L3 book level construction for quoting
|
|
15
15
|
*/
|
|
16
16
|
const NodeList_1 = require("./NodeList");
|
|
@@ -43,11 +43,24 @@ function getUserAccountOrThrow(node) {
|
|
|
43
43
|
}
|
|
44
44
|
return node.userAccount;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* In-memory order book. Indexes every open order it is given into per-market, per-side sorted
|
|
48
|
+
* `NodeList`s (see `MarketNodeLists`), and provides the crossing/fill-finding logic
|
|
49
|
+
* (`findNodesToFill`) and aggregated book views (`getL2`/`getL3`) that keepers and clients use to
|
|
50
|
+
* predict and drive on-chain fills. A `DLOB` instance is normally built once per slot (e.g. via
|
|
51
|
+
* `initFromUserMap`) rather than mutated indefinitely, since state changes (`insertOrder`,
|
|
52
|
+
* `delete`) must be paired with the caller's own bookkeeping of what's already been applied.
|
|
53
|
+
*/
|
|
46
54
|
class DLOB {
|
|
55
|
+
/** Constructs an empty, uninitialized `DLOB` with no orders. Call `initFromUserMap` (or `insertOrder`/`insertSignedMsgOrder`) to populate it. */
|
|
47
56
|
constructor() {
|
|
57
|
+
/** Order signatures (`getOrderSignature`) currently open, keyed by market type (`'perp'`/`'spot'`). */
|
|
48
58
|
this.openOrders = new Map();
|
|
59
|
+
/** Every market's `MarketNodeLists`, keyed by market type then market index. */
|
|
49
60
|
this.orderLists = new Map();
|
|
61
|
+
/** The highest slot `updateRestingLimitOrders` has processed; used to skip redundant re-promotion of taking→resting orders when called with a slot that's already been seen. */
|
|
50
62
|
this.maxSlotForRestingLimitOrders = 0;
|
|
63
|
+
/** Set to `true` once `initFromUserMap` has successfully populated this instance; `initFromUserMap` is then a no-op. */
|
|
51
64
|
this.initialized = false;
|
|
52
65
|
this.init();
|
|
53
66
|
}
|
|
@@ -82,6 +95,7 @@ class DLOB {
|
|
|
82
95
|
}
|
|
83
96
|
return marketNodeLists;
|
|
84
97
|
}
|
|
98
|
+
/** Empties every order list and resets the DLOB to its freshly-constructed (uninitialized) state, including `maxSlotForRestingLimitOrders` and `initialized`. */
|
|
85
99
|
clear() {
|
|
86
100
|
for (const openOrders of this.openOrders.values()) {
|
|
87
101
|
openOrders.clear();
|
|
@@ -101,9 +115,15 @@ class DLOB {
|
|
|
101
115
|
this.init();
|
|
102
116
|
}
|
|
103
117
|
/**
|
|
104
|
-
*
|
|
118
|
+
* Populates this DLOB from every open order across every user in `userMap`. For reduce-only
|
|
119
|
+
* orders, the fillable amount is capped via `calculateOrderBaseAssetAmount` against the
|
|
120
|
+
* user's existing perp position for that market, rather than trusting the order's full
|
|
121
|
+
* stated `baseAssetAmount`. No-ops (returns `false` immediately) if this instance has already
|
|
122
|
+
* been initialized — call `clear()` first to rebuild from scratch.
|
|
105
123
|
*
|
|
106
|
-
* @
|
|
124
|
+
* @param userMap map of all users' accounts to index orders from
|
|
125
|
+
* @param slot slot orders are inserted at, used to classify taking vs. resting limit orders
|
|
126
|
+
* @returns `true` if this call performed initialization, `false` if it was already initialized
|
|
107
127
|
*/
|
|
108
128
|
async initFromUserMap(userMap, slot) {
|
|
109
129
|
var _a;
|
|
@@ -127,6 +147,22 @@ class DLOB {
|
|
|
127
147
|
this.initialized = true;
|
|
128
148
|
return true;
|
|
129
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Inserts a single on-chain order into the appropriate `NodeList` for its market/side/type.
|
|
152
|
+
* No-ops if the order's status isn't `open`, or if its `orderType` isn't one of the
|
|
153
|
+
* DLOB-supported types (`market`, `limit`, `triggerMarket`, `triggerLimit`, `oracle`).
|
|
154
|
+
* Lazily creates the market's `MarketNodeLists` (via `addOrderList`) on first insert for that
|
|
155
|
+
* market. Which list the order lands in (taking vs. resting limit, floating, market, or
|
|
156
|
+
* inactive trigger) is decided by `getListForOnChainOrder`.
|
|
157
|
+
*
|
|
158
|
+
* @param order the on-chain order to insert
|
|
159
|
+
* @param userAccount base58 pubkey string of the order's owner
|
|
160
|
+
* @param slot current slot, used to classify taking vs. resting limit orders
|
|
161
|
+
* @param baseAssetAmount remaining fillable base amount, BASE_PRECISION (1e9) — for
|
|
162
|
+
* reduce-only orders this should be the position-capped amount (see
|
|
163
|
+
* `calculateOrderBaseAssetAmount`), not the raw `order.baseAssetAmount`
|
|
164
|
+
* @param onInsert optional callback invoked after a successful insert
|
|
165
|
+
*/
|
|
130
166
|
insertOrder(order, userAccount, slot, baseAssetAmount, onInsert) {
|
|
131
167
|
var _a;
|
|
132
168
|
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
@@ -147,6 +183,16 @@ class DLOB {
|
|
|
147
183
|
onInsert();
|
|
148
184
|
}
|
|
149
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Inserts an off-chain signed-message order (not yet landed on-chain) into the market's
|
|
188
|
+
* `signedMsg` bid/ask list, unconditionally (no status/order-type filtering, unlike
|
|
189
|
+
* `insertOrder`). Lazily creates the market's `MarketNodeLists` on first insert.
|
|
190
|
+
*
|
|
191
|
+
* @param order the signed-message order to insert
|
|
192
|
+
* @param userAccount base58 pubkey string of the order's owner
|
|
193
|
+
* @param baseAssetAmount remaining fillable base amount, BASE_PRECISION (1e9); defaults to `order.baseAssetAmount`
|
|
194
|
+
* @param onInsert optional callback invoked after insert
|
|
195
|
+
*/
|
|
150
196
|
insertSignedMsgOrder(order, userAccount, baseAssetAmount, onInsert) {
|
|
151
197
|
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
152
198
|
const marketIndex = order.marketIndex;
|
|
@@ -160,6 +206,7 @@ class DLOB {
|
|
|
160
206
|
onInsert();
|
|
161
207
|
}
|
|
162
208
|
}
|
|
209
|
+
/** Creates and registers an empty `MarketNodeLists` (all six order categories, both sides) for `marketIndex`, overwriting any existing lists for that market. */
|
|
163
210
|
addOrderList(marketType, marketIndex) {
|
|
164
211
|
this.getOrderListsForMarketType(marketType).set(marketIndex, {
|
|
165
212
|
restingLimit: {
|
|
@@ -188,6 +235,17 @@ class DLOB {
|
|
|
188
235
|
},
|
|
189
236
|
});
|
|
190
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Removes an order from whichever `NodeList` it currently lives in. No-ops if the order's
|
|
240
|
+
* status isn't `open`. First calls `updateRestingLimitOrders(slot)` so a taking-limit order
|
|
241
|
+
* that has since become a resting-limit order is looked up (and removed from) the correct
|
|
242
|
+
* list.
|
|
243
|
+
*
|
|
244
|
+
* @param order the order to remove
|
|
245
|
+
* @param userAccount pubkey of the order's owner
|
|
246
|
+
* @param slot current slot, used to resolve which list the order is currently in
|
|
247
|
+
* @param onDelete optional callback invoked after a successful delete
|
|
248
|
+
*/
|
|
191
249
|
delete(order, userAccount, slot, onDelete) {
|
|
192
250
|
var _a;
|
|
193
251
|
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
@@ -199,6 +257,18 @@ class DLOB {
|
|
|
199
257
|
onDelete();
|
|
200
258
|
}
|
|
201
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Determines which `NodeList` an order belongs in, given its current state and the slot:
|
|
262
|
+
* a trigger order (`triggerMarket`/`triggerLimit`) that hasn't fired yet goes in
|
|
263
|
+
* `trigger.above`/`trigger.below`; a market/oracle-type order goes in `market`; a limit order
|
|
264
|
+
* with a non-zero `oraclePriceOffset` goes in `floatingLimit`; otherwise a limit order goes in
|
|
265
|
+
* `restingLimit` once its auction is complete or it's post-only (per `isRestingLimitOrder`),
|
|
266
|
+
* and in `takingLimit` while still auctioning.
|
|
267
|
+
*
|
|
268
|
+
* @param order the order to classify
|
|
269
|
+
* @param slot current slot, used to evaluate `isRestingLimitOrder`
|
|
270
|
+
* @returns the matching `NodeList`, or `undefined` if the order's market has no `MarketNodeLists` registered yet (e.g. `insertOrder`/`addOrderList` hasn't been called for it)
|
|
271
|
+
*/
|
|
202
272
|
getListForOnChainOrder(order, slot) {
|
|
203
273
|
const isInactiveTriggerOrder = (0, orders_1.mustBeTriggered)(order) && !(0, orders_1.isTriggered)(order);
|
|
204
274
|
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
@@ -233,6 +303,15 @@ class DLOB {
|
|
|
233
303
|
}
|
|
234
304
|
return list;
|
|
235
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Promotes any `takingLimit` orders across all perp and spot markets whose auction has since
|
|
308
|
+
* completed (per `isRestingLimitOrder`) into their market's `restingLimit` list. No-ops if
|
|
309
|
+
* `slot` is not newer than the last slot this was called with (`maxSlotForRestingLimitOrders`),
|
|
310
|
+
* so it is cheap to call defensively before any read that depends on resting-limit state
|
|
311
|
+
* being current (most getters here do so internally).
|
|
312
|
+
*
|
|
313
|
+
* @param slot current slot
|
|
314
|
+
*/
|
|
236
315
|
updateRestingLimitOrders(slot) {
|
|
237
316
|
if (slot <= this.maxSlotForRestingLimitOrders) {
|
|
238
317
|
return;
|
|
@@ -241,6 +320,7 @@ class DLOB {
|
|
|
241
320
|
this.updateRestingLimitOrdersForMarketType(slot, 'perp');
|
|
242
321
|
this.updateRestingLimitOrdersForMarketType(slot, 'spot');
|
|
243
322
|
}
|
|
323
|
+
/** Does the `takingLimit` → `restingLimit` promotion (see `updateRestingLimitOrders`) for every market of one market type. */
|
|
244
324
|
updateRestingLimitOrdersForMarketType(slot, marketTypeStr) {
|
|
245
325
|
for (const [_, nodeLists] of this.getOrderListsForMarketType(marketTypeStr)) {
|
|
246
326
|
const nodesToUpdate = [];
|
|
@@ -271,6 +351,15 @@ class DLOB {
|
|
|
271
351
|
}
|
|
272
352
|
}
|
|
273
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Looks up an order by id/owner across every `NodeList` in the DLOB (perp and spot, all
|
|
356
|
+
* categories/sides) via `getNodeLists`. O(number of lists); prefer a narrower lookup (e.g.
|
|
357
|
+
* `NodeList.get`) if you already know the order's market/type.
|
|
358
|
+
*
|
|
359
|
+
* @param orderId the order's id (unique per user account)
|
|
360
|
+
* @param userAccount pubkey of the order's owner
|
|
361
|
+
* @returns the matching `Order`, or `undefined` if not found in any list
|
|
362
|
+
*/
|
|
274
363
|
getOrder(orderId, userAccount) {
|
|
275
364
|
const orderSignature = (0, NodeList_1.getOrderSignature)(orderId, userAccount.toString());
|
|
276
365
|
for (const nodeList of this.getNodeLists()) {
|
|
@@ -281,14 +370,38 @@ class DLOB {
|
|
|
281
370
|
}
|
|
282
371
|
return undefined;
|
|
283
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Top-level entry point for keepers: finds every node in one market that is currently
|
|
375
|
+
* fillable, combining four sources — crossing resting-limit orders
|
|
376
|
+
* (`findRestingLimitOrderNodesToFill`), taking (still-auctioning) orders that cross a maker or
|
|
377
|
+
* fallback price (`findTakingNodesToFill`), expired orders to cancel/settle
|
|
378
|
+
* (`findExpiredNodesToFill`), and unfillable reduce-only orders below the step size to cancel
|
|
379
|
+
* (`findUnfillableReduceOnlyOrdersToCancel`). Returns `[]` immediately if fills are paused for
|
|
380
|
+
* this market (`fillPaused`). The market's `orderTickSize` is read from `marketAccount` and
|
|
381
|
+
* threaded through to every price comparison below so all crossing checks agree with on-chain
|
|
382
|
+
* price standardization.
|
|
383
|
+
*
|
|
384
|
+
* @param marketIndex the market to scan
|
|
385
|
+
* @param fallbackBid best available non-DLOB bid (e.g. vAMM), PRICE_PRECISION (1e6); `undefined` disables fallback-bid crossing checks
|
|
386
|
+
* @param fallbackAsk best available non-DLOB ask (e.g. vAMM), PRICE_PRECISION (1e6); `undefined` disables fallback-ask crossing checks
|
|
387
|
+
* @param slot current slot
|
|
388
|
+
* @param ts current unix timestamp (seconds), used to find expired orders
|
|
389
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`; determines whether `oraclePriceData`/`marketAccount` are typed as spot or perp
|
|
390
|
+
* @param oraclePriceData oracle price data for the market (`MMOraclePriceData` for perp, `OraclePriceData` for spot)
|
|
391
|
+
* @param stateAccount global protocol state, used for pause checks and fee-tier maker rebates
|
|
392
|
+
* @param marketAccount the market's account, used for `orderTickSize`/`orderStepSize` and pause checks
|
|
393
|
+
* @returns deduplicated `NodeToFill`s (see `mergeNodesToFill`) merging resting-limit and taking-order matches, plus expired and cancel-eligible nodes appended
|
|
394
|
+
*/
|
|
284
395
|
findNodesToFill(marketIndex, fallbackBid, fallbackAsk, slot, ts, marketType, oraclePriceData, stateAccount, marketAccount) {
|
|
285
396
|
if ((0, exchangeStatus_1.fillPaused)(stateAccount, marketAccount)) {
|
|
286
397
|
return [];
|
|
287
398
|
}
|
|
288
399
|
const isAmmPaused = (0, exchangeStatus_1.ammPaused)(stateAccount, marketAccount);
|
|
400
|
+
const tickSize = marketAccount
|
|
401
|
+
.orderTickSize;
|
|
289
402
|
const { makerRebateNumerator, makerRebateDenominator } = this.getMakerRebate(marketType, stateAccount, marketAccount);
|
|
290
|
-
const takingOrderNodesToFill = this.findTakingNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, stateAccount, marketAccount, fallbackAsk, fallbackBid);
|
|
291
|
-
const restingLimitOrderNodesToFill = this.findRestingLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, stateAccount, marketAccount, makerRebateNumerator, makerRebateDenominator, fallbackAsk, fallbackBid);
|
|
403
|
+
const takingOrderNodesToFill = this.findTakingNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, stateAccount, marketAccount, fallbackAsk, fallbackBid, tickSize);
|
|
404
|
+
const restingLimitOrderNodesToFill = this.findRestingLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, stateAccount, marketAccount, makerRebateNumerator, makerRebateDenominator, fallbackAsk, fallbackBid, tickSize);
|
|
292
405
|
// get expired market nodes
|
|
293
406
|
const expiredNodesToFill = this.findExpiredNodesToFill(marketIndex, ts, marketType, new anchor_1.BN(slot));
|
|
294
407
|
const stepSize = (0, types_1.isVariant)(marketType, 'perp')
|
|
@@ -299,6 +412,18 @@ class DLOB {
|
|
|
299
412
|
.concat(expiredNodesToFill)
|
|
300
413
|
.concat(cancelReduceOnlyNodesToFill);
|
|
301
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Reads the tier-0 maker rebate fraction (`makerRebateNumerator / makerRebateDenominator`)
|
|
417
|
+
* for a market from `stateAccount`'s perp/spot fee structure, then scales the numerator up by
|
|
418
|
+
* the market's `feeAdjustment` percentage if one is set. Used by `findRestingLimitOrderNodesToFill`
|
|
419
|
+
* to size the buffer added to fallback prices so fallback fills aren't triggered by rebate-sized
|
|
420
|
+
* noise.
|
|
421
|
+
*
|
|
422
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
423
|
+
* @param stateAccount global protocol state holding the perp/spot fee tier tables
|
|
424
|
+
* @param marketAccount the specific market, whose optional `feeAdjustment` (percent) scales the rebate
|
|
425
|
+
* @returns the rebate as a numerator/denominator pair (unitless fraction, not a fixed-point BN)
|
|
426
|
+
*/
|
|
302
427
|
getMakerRebate(marketType, stateAccount, marketAccount) {
|
|
303
428
|
let makerRebateNumerator;
|
|
304
429
|
let makerRebateDenominator;
|
|
@@ -321,6 +446,16 @@ class DLOB {
|
|
|
321
446
|
}
|
|
322
447
|
return { makerRebateNumerator, makerRebateDenominator };
|
|
323
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Merges two `NodeToFill` arrays (typically resting-limit crossings and taking-order
|
|
451
|
+
* crossings for the same market/pass) by taker order signature, concatenating `makerNodes`
|
|
452
|
+
* for any taker that appears in both — e.g. an order that both crosses a resting maker and
|
|
453
|
+
* separately crosses fallback liquidity ends up as one `NodeToFill` with both maker sources.
|
|
454
|
+
*
|
|
455
|
+
* @param restingLimitOrderNodesToFill fills found via resting-limit crossing
|
|
456
|
+
* @param takingOrderNodesToFill fills found via taking-order crossing
|
|
457
|
+
* @returns one `NodeToFill` per distinct taker order, with all matched maker nodes combined
|
|
458
|
+
*/
|
|
324
459
|
mergeNodesToFill(restingLimitOrderNodesToFill, takingOrderNodesToFill) {
|
|
325
460
|
const mergedNodesToFill = new Map();
|
|
326
461
|
const mergeNodesToFillHelper = (nodesToFillArray) => {
|
|
@@ -343,41 +478,85 @@ class DLOB {
|
|
|
343
478
|
mergeNodesToFillHelper(takingOrderNodesToFill);
|
|
344
479
|
return Array.from(mergedNodesToFill.values());
|
|
345
480
|
}
|
|
346
|
-
|
|
481
|
+
/**
|
|
482
|
+
* Finds resting-limit-order fills for a market: resting bids/asks that cross each other
|
|
483
|
+
* (`findCrossingRestingLimitOrders`), plus resting asks that cross the fallback bid and
|
|
484
|
+
* resting bids that cross the fallback ask (each skipped entirely if the AMM is paused).
|
|
485
|
+
* The fallback price on each side is tightened by the maker rebate before comparing, so a
|
|
486
|
+
* maker order priced exactly at the rebate-adjusted fallback isn't spuriously flagged as
|
|
487
|
+
* crossing (`fallbackBidWithBuffer = fallbackBid - fallbackBid * makerRebateNumerator / makerRebateDenominator`,
|
|
488
|
+
* and symmetrically for the ask).
|
|
489
|
+
*
|
|
490
|
+
* @param marketIndex the market to scan
|
|
491
|
+
* @param slot current slot
|
|
492
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
493
|
+
* @param oraclePriceData oracle price data for the market
|
|
494
|
+
* @param isAmmPaused if true, skips fallback-crossing checks (only maker-vs-maker crossings are returned)
|
|
495
|
+
* @param stateAccount global protocol state, forwarded to fallback-availability checks
|
|
496
|
+
* @param marketAccount the market's account, forwarded to fallback-availability checks
|
|
497
|
+
* @param makerRebateNumerator numerator of the maker rebate fraction (see `getMakerRebate`)
|
|
498
|
+
* @param makerRebateDenominator denominator of the maker rebate fraction (see `getMakerRebate`)
|
|
499
|
+
* @param fallbackAsk best available non-DLOB ask, PRICE_PRECISION (1e6); `undefined` skips fallback-ask crossing
|
|
500
|
+
* @param fallbackBid best available non-DLOB bid, PRICE_PRECISION (1e6); `undefined` skips fallback-bid crossing
|
|
501
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), threaded into every price comparison; omit to fall back to no rounding
|
|
502
|
+
* @returns `NodeToFill`s for maker-crossing-maker and maker-crossing-fallback matches
|
|
503
|
+
*/
|
|
504
|
+
findRestingLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, stateAccount, marketAccount, makerRebateNumerator, makerRebateDenominator, fallbackAsk, fallbackBid, tickSize) {
|
|
347
505
|
const nodesToFill = new Array();
|
|
348
|
-
const crossingNodes = this.findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData);
|
|
506
|
+
const crossingNodes = this.findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData, tickSize);
|
|
349
507
|
for (const crossingNode of crossingNodes) {
|
|
350
508
|
nodesToFill.push(crossingNode);
|
|
351
509
|
}
|
|
352
510
|
if (fallbackBid && !isAmmPaused) {
|
|
353
|
-
const askGenerator = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
511
|
+
const askGenerator = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
354
512
|
const fallbackBidWithBuffer = fallbackBid.sub(fallbackBid.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
355
513
|
const asksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, askGenerator, (askPrice) => {
|
|
356
514
|
if (askPrice === undefined) {
|
|
357
515
|
throw new Error('Resting limit ask must have a limit price');
|
|
358
516
|
}
|
|
359
517
|
return askPrice.lte(fallbackBidWithBuffer);
|
|
360
|
-
}, stateAccount, marketAccount);
|
|
518
|
+
}, stateAccount, marketAccount, tickSize);
|
|
361
519
|
for (const askCrossingFallback of asksCrossingFallback) {
|
|
362
520
|
nodesToFill.push(askCrossingFallback);
|
|
363
521
|
}
|
|
364
522
|
}
|
|
365
523
|
if (fallbackAsk && !isAmmPaused) {
|
|
366
|
-
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
524
|
+
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
367
525
|
const fallbackAskWithBuffer = fallbackAsk.add(fallbackAsk.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
368
526
|
const bidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, bidGenerator, (bidPrice) => {
|
|
369
527
|
if (bidPrice === undefined) {
|
|
370
528
|
throw new Error('Resting limit bid must have a limit price');
|
|
371
529
|
}
|
|
372
530
|
return bidPrice.gte(fallbackAskWithBuffer);
|
|
373
|
-
}, stateAccount, marketAccount);
|
|
531
|
+
}, stateAccount, marketAccount, tickSize);
|
|
374
532
|
for (const bidCrossingFallback of bidsCrossingFallback) {
|
|
375
533
|
nodesToFill.push(bidCrossingFallback);
|
|
376
534
|
}
|
|
377
535
|
}
|
|
378
536
|
return nodesToFill;
|
|
379
537
|
}
|
|
380
|
-
|
|
538
|
+
/**
|
|
539
|
+
* Finds fills for taking (still-auctioning) orders: taking asks crossing resting bids or the
|
|
540
|
+
* fallback bid, and taking bids crossing resting asks or the fallback ask
|
|
541
|
+
* (`findTakingNodesCrossingMakerNodes` / `findNodesCrossingFallbackLiquidity`). Fallback
|
|
542
|
+
* crossing checks are skipped entirely when `isAmmPaused`. For spot markets, a taking order is
|
|
543
|
+
* only allowed to cross the opposite fallback price if doing so wouldn't also require crossing
|
|
544
|
+
* beyond the *other* fallback price (see the inline `fallbackBid`/`fallbackAsk` guards) —
|
|
545
|
+
* this prevents a taking order from routing through DLOB makers priced worse than the AMM.
|
|
546
|
+
*
|
|
547
|
+
* @param marketIndex the market to scan
|
|
548
|
+
* @param slot current slot
|
|
549
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
550
|
+
* @param oraclePriceData oracle price data for the market
|
|
551
|
+
* @param isAmmPaused if true, skips fallback-crossing checks
|
|
552
|
+
* @param state global protocol state, forwarded to fallback-availability checks
|
|
553
|
+
* @param marketAccount the market's account, forwarded to fallback-availability checks
|
|
554
|
+
* @param fallbackAsk best available non-DLOB ask, PRICE_PRECISION (1e6); `undefined` skips ask-side fallback crossing
|
|
555
|
+
* @param fallbackBid best available non-DLOB bid, PRICE_PRECISION (1e6); `undefined` skips bid-side fallback crossing
|
|
556
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), threaded into every price comparison; omit to fall back to no rounding
|
|
557
|
+
* @returns `NodeToFill`s for taking orders that cross a resting maker or fallback liquidity
|
|
558
|
+
*/
|
|
559
|
+
findTakingNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, state, marketAccount, fallbackAsk, fallbackBid, tickSize) {
|
|
381
560
|
const nodesToFill = new Array();
|
|
382
561
|
let takingOrderGenerator = this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData);
|
|
383
562
|
const takingAsksCrossingBids = this.findTakingNodesCrossingMakerNodes(marketIndex, slot, marketType, oraclePriceData, takingOrderGenerator, this.getRestingLimitBids.bind(this), (takerPrice, makerPrice) => {
|
|
@@ -390,7 +569,7 @@ class DLOB {
|
|
|
390
569
|
}
|
|
391
570
|
}
|
|
392
571
|
return takerPrice === undefined || takerPrice.lte(makerPrice);
|
|
393
|
-
});
|
|
572
|
+
}, tickSize);
|
|
394
573
|
for (const takingAskCrossingBid of takingAsksCrossingBids) {
|
|
395
574
|
nodesToFill.push(takingAskCrossingBid);
|
|
396
575
|
}
|
|
@@ -398,7 +577,7 @@ class DLOB {
|
|
|
398
577
|
takingOrderGenerator = this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData);
|
|
399
578
|
const takingAsksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, takingOrderGenerator, (takerPrice) => {
|
|
400
579
|
return takerPrice === undefined || takerPrice.lte(fallbackBid);
|
|
401
|
-
}, state, marketAccount);
|
|
580
|
+
}, state, marketAccount, tickSize);
|
|
402
581
|
for (const takingAskCrossingFallback of takingAsksCrossingFallback) {
|
|
403
582
|
nodesToFill.push(takingAskCrossingFallback);
|
|
404
583
|
}
|
|
@@ -414,7 +593,7 @@ class DLOB {
|
|
|
414
593
|
}
|
|
415
594
|
}
|
|
416
595
|
return takerPrice === undefined || takerPrice.gte(makerPrice);
|
|
417
|
-
});
|
|
596
|
+
}, tickSize);
|
|
418
597
|
for (const takingBidToFill of takingBidsToFill) {
|
|
419
598
|
nodesToFill.push(takingBidToFill);
|
|
420
599
|
}
|
|
@@ -422,25 +601,47 @@ class DLOB {
|
|
|
422
601
|
takingOrderGenerator = this.getTakingBids(marketIndex, marketType, slot, oraclePriceData);
|
|
423
602
|
const takingBidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, takingOrderGenerator, (takerPrice) => {
|
|
424
603
|
return takerPrice === undefined || takerPrice.gte(fallbackAsk);
|
|
425
|
-
}, state, marketAccount);
|
|
604
|
+
}, state, marketAccount, tickSize);
|
|
426
605
|
for (const marketBidCrossingFallback of takingBidsCrossingFallback) {
|
|
427
606
|
nodesToFill.push(marketBidCrossingFallback);
|
|
428
607
|
}
|
|
429
608
|
}
|
|
430
609
|
return nodesToFill;
|
|
431
610
|
}
|
|
432
|
-
|
|
611
|
+
/**
|
|
612
|
+
* Walks `takerNodeGenerator` (taking bids or asks, sorted by arrival slot) against a fresh
|
|
613
|
+
* maker-side generator (built per taker via `makerNodeGeneratorFn`, e.g.
|
|
614
|
+
* `getRestingLimitBids`) and records a `NodeToFill` for every taker/maker pair that
|
|
615
|
+
* `doesCross` accepts, skipping same-user matches. For each match this method also **mutates
|
|
616
|
+
* DLOB state**: it applies the simulated fill to both the maker's and taker's order lists
|
|
617
|
+
* (via `NodeList.update`) so subsequent iterations see updated `baseAssetAmountFilled` and a
|
|
618
|
+
* taker stops matching once fully filled. Because maker nodes (sorted by price) are scanned
|
|
619
|
+
* in order, `doesCross` returning false breaks out of the maker loop entirely — this is
|
|
620
|
+
* correct for resting-limit makers but relies on the maker generator being price-sorted, not
|
|
621
|
+
* time-sorted.
|
|
622
|
+
*
|
|
623
|
+
* @param marketIndex the market being scanned (used only to route signed-message taker fills into the right list)
|
|
624
|
+
* @param slot current slot, forwarded to price lookups
|
|
625
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
626
|
+
* @param oraclePriceData oracle price data for the market
|
|
627
|
+
* @param takerNodeGenerator taking orders to check, e.g. from `getTakingAsks`/`getTakingBids`
|
|
628
|
+
* @param makerNodeGeneratorFn factory invoked once per taker to get a fresh maker-side generator, e.g. `getRestingLimitBids`/`getRestingLimitAsks`
|
|
629
|
+
* @param doesCross given the taker's price (`undefined` if it has none, e.g. still mid-auction) and the maker's price, returns whether they cross
|
|
630
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), threaded into all price lookups
|
|
631
|
+
* @returns one `NodeToFill` per matched taker/maker pair (a taker matched against multiple makers yields multiple entries, each with one maker)
|
|
632
|
+
*/
|
|
633
|
+
findTakingNodesCrossingMakerNodes(marketIndex, slot, marketType, oraclePriceData, takerNodeGenerator, makerNodeGeneratorFn, doesCross, tickSize) {
|
|
433
634
|
const nodesToFill = new Array();
|
|
434
635
|
for (const takerNode of takerNodeGenerator) {
|
|
435
|
-
const makerNodeGenerator = makerNodeGeneratorFn(marketIndex, slot, marketType, oraclePriceData);
|
|
636
|
+
const makerNodeGenerator = makerNodeGeneratorFn(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
436
637
|
for (const makerNode of makerNodeGenerator) {
|
|
437
638
|
// Can't match orders from the same user
|
|
438
639
|
const sameUser = takerNode.userAccount === makerNode.userAccount;
|
|
439
640
|
if (sameUser) {
|
|
440
641
|
continue;
|
|
441
642
|
}
|
|
442
|
-
const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot);
|
|
443
|
-
const takerPrice = takerNode.getPrice(oraclePriceData, slot);
|
|
643
|
+
const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot, tickSize);
|
|
644
|
+
const takerPrice = takerNode.getPrice(oraclePriceData, slot, tickSize);
|
|
444
645
|
const ordersCross = doesCross(takerPrice, makerPrice);
|
|
445
646
|
if (!ordersCross) {
|
|
446
647
|
// market orders aren't sorted by price, they are sorted by time, so we need to traverse
|
|
@@ -481,7 +682,28 @@ class DLOB {
|
|
|
481
682
|
}
|
|
482
683
|
return nodesToFill;
|
|
483
684
|
}
|
|
484
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Scans `nodeGenerator` for nodes that both cross the fallback price (`doesCross`, evaluated
|
|
687
|
+
* against each node's `getLimitPrice`, or crossing unconditionally if the node has no limit
|
|
688
|
+
* price) and have fallback liquidity actually available to fill against. For spot markets,
|
|
689
|
+
* post-only orders are skipped (they can never take against the AMM) and fallback liquidity
|
|
690
|
+
* is always considered available; for perp markets, availability additionally requires
|
|
691
|
+
* `isFallbackAvailableLiquiditySource` (broadly: the order's auction is complete and the
|
|
692
|
+
* oracle is valid enough for AMM fills). Does not mutate any order state — unlike
|
|
693
|
+
* `findTakingNodesCrossingMakerNodes`, fallback fills are expected to be sized/settled
|
|
694
|
+
* on-chain rather than simulated here.
|
|
695
|
+
*
|
|
696
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
697
|
+
* @param slot current slot
|
|
698
|
+
* @param oraclePriceData oracle price data for the market
|
|
699
|
+
* @param nodeGenerator candidate nodes to check, e.g. resting-limit or taking orders
|
|
700
|
+
* @param doesCross given a node's limit price (`undefined` if it has none), returns whether it crosses the fallback price
|
|
701
|
+
* @param state global protocol state, used by the perp fallback-availability check
|
|
702
|
+
* @param marketAccount the market's account, used by the perp fallback-availability check
|
|
703
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), used to resolve each node's limit price
|
|
704
|
+
* @returns `NodeToFill`s with an empty `makerNodes` array (the fill is expected to route through fallback liquidity, not a DLOB maker)
|
|
705
|
+
*/
|
|
706
|
+
findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, nodeGenerator, doesCross, state, marketAccount, tickSize) {
|
|
485
707
|
var _a;
|
|
486
708
|
const nodesToFill = new Array();
|
|
487
709
|
let nextNode = nodeGenerator.next();
|
|
@@ -492,7 +714,7 @@ class DLOB {
|
|
|
492
714
|
continue;
|
|
493
715
|
}
|
|
494
716
|
const nodeOrder = getOrderOrThrow(node);
|
|
495
|
-
const nodePrice = (0, orders_1.getLimitPrice)(nodeOrder, oraclePriceData, slot);
|
|
717
|
+
const nodePrice = (0, orders_1.getLimitPrice)(nodeOrder, oraclePriceData, slot, undefined, tickSize);
|
|
496
718
|
// order crosses if there is no limit price or it crosses fallback price
|
|
497
719
|
const crosses = doesCross(nodePrice);
|
|
498
720
|
// fallback is available if auction is complete or it's a spot order
|
|
@@ -508,6 +730,20 @@ class DLOB {
|
|
|
508
730
|
}
|
|
509
731
|
return nodesToFill;
|
|
510
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Finds orders in a market that are eligible to be expired: any non-trigger, non-TIF-limit
|
|
735
|
+
* order whose `maxTs` (plus a 25-second buffer for limit orders, via `isOrderExpired`) has
|
|
736
|
+
* passed the given timestamp. Also proactively removes (not just reports) signed-message
|
|
737
|
+
* orders whose auction window (`order.slot + order.auctionDuration`) has passed `slot`, since
|
|
738
|
+
* those never landed on-chain and have no on-chain expiration to wait for.
|
|
739
|
+
*
|
|
740
|
+
* @param marketIndex the market to scan
|
|
741
|
+
* @param ts current unix timestamp (seconds)
|
|
742
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
743
|
+
* @param slot current slot; required if the market has any signed-message orders (throws otherwise)
|
|
744
|
+
* @returns `NodeToFill`s (with empty `makerNodes`) for orders ready to expire
|
|
745
|
+
* @throws if a signed-message order is present and `slot` was not provided
|
|
746
|
+
*/
|
|
511
747
|
findExpiredNodesToFill(marketIndex, ts, marketType, slot) {
|
|
512
748
|
const nodesToFill = new Array();
|
|
513
749
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
@@ -573,6 +809,17 @@ class DLOB {
|
|
|
573
809
|
}
|
|
574
810
|
return nodesToFill;
|
|
575
811
|
}
|
|
812
|
+
/**
|
|
813
|
+
* Finds reduce-only orders across every category/side in a market whose remaining
|
|
814
|
+
* `baseAssetAmount` (as tracked on the node, not necessarily the order's original size) has
|
|
815
|
+
* dropped below the market's minimum step size — meaning the order can never be filled again
|
|
816
|
+
* and should be canceled by a keeper rather than left to linger.
|
|
817
|
+
*
|
|
818
|
+
* @param marketIndex the market to scan
|
|
819
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
820
|
+
* @param stepSize market's minimum order step size, BASE_PRECISION (1e9)
|
|
821
|
+
* @returns `NodeToFill`s (with empty `makerNodes`) for reduce-only orders that should be canceled
|
|
822
|
+
*/
|
|
576
823
|
findUnfillableReduceOnlyOrdersToCancel(marketIndex, marketType, stepSize) {
|
|
577
824
|
const nodesToFill = new Array();
|
|
578
825
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
@@ -609,6 +856,19 @@ class DLOB {
|
|
|
609
856
|
}
|
|
610
857
|
return nodesToFill;
|
|
611
858
|
}
|
|
859
|
+
/**
|
|
860
|
+
* Yields taking (still-auctioning) bid nodes for a market — market-bid orders, taking-limit
|
|
861
|
+
* bids, and signed-message bids not yet resting — merged in arrival order (earliest `slot`
|
|
862
|
+
* first, via `getBestNode`). Calls `updateRestingLimitOrders(slot)` first so a signed-message
|
|
863
|
+
* order that has since become a resting-limit order is excluded here.
|
|
864
|
+
*
|
|
865
|
+
* @param marketIndex the market to scan
|
|
866
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
867
|
+
* @param slot current slot
|
|
868
|
+
* @param oraclePriceData oracle price data for the market (unused for the ordering itself, forwarded to `getBestNode`)
|
|
869
|
+
* @param filterFcn optional predicate; nodes it rejects are skipped and not yielded
|
|
870
|
+
* @returns a generator of taking bid nodes, or an empty generator if the market has no `MarketNodeLists`
|
|
871
|
+
*/
|
|
612
872
|
*getTakingBids(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
613
873
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
614
874
|
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
@@ -625,6 +885,7 @@ class DLOB {
|
|
|
625
885
|
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
626
886
|
}, filterFcn);
|
|
627
887
|
}
|
|
888
|
+
/** Same as `getTakingBids`, but for the ask side. */
|
|
628
889
|
*getTakingAsks(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
629
890
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
630
891
|
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
@@ -641,6 +902,7 @@ class DLOB {
|
|
|
641
902
|
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
642
903
|
}, filterFcn);
|
|
643
904
|
}
|
|
905
|
+
/** Filters a `signedMsg` `NodeList`'s nodes by an arbitrary predicate — used to split signed-message orders into "still taking" vs. "now resting" subsets based on `isRestingLimitOrder`. */
|
|
644
906
|
*signedMsgGenerator(signedMsgOrderList, filter) {
|
|
645
907
|
for (const signedMsgOrder of signedMsgOrderList.getGenerator()) {
|
|
646
908
|
if (filter(signedMsgOrder)) {
|
|
@@ -648,6 +910,20 @@ class DLOB {
|
|
|
648
910
|
}
|
|
649
911
|
}
|
|
650
912
|
}
|
|
913
|
+
/**
|
|
914
|
+
* K-way-merges multiple node generators (e.g. one per order category feeding one side of the
|
|
915
|
+
* book) into a single generator ordered by `compareFcn`, skipping nodes that are already
|
|
916
|
+
* fully filled (`isBaseFilled`) or rejected by `filterFcn`. This is the shared core behind
|
|
917
|
+
* `getTakingBids`/`getTakingAsks`/`getRestingLimitBids`/`getRestingLimitAsks`/`getBids`/`getAsks`
|
|
918
|
+
* — each just supplies a different `generatorList` and `compareFcn`.
|
|
919
|
+
*
|
|
920
|
+
* @param generatorList the node generators to merge; each must already be sorted per `compareFcn`
|
|
921
|
+
* @param oraclePriceData oracle price data, forwarded to `compareFcn`
|
|
922
|
+
* @param slot current slot, forwarded to `compareFcn`
|
|
923
|
+
* @param compareFcn returns true if `bestDLOBNode` should be preferred over `currentDLOBNode`
|
|
924
|
+
* @param filterFcn optional predicate; nodes it rejects are advanced past and not yielded
|
|
925
|
+
* @returns a single generator yielding the merged, filtered, non-fully-filled nodes in `compareFcn` order
|
|
926
|
+
*/
|
|
651
927
|
*getBestNode(generatorList, oraclePriceData, slot, compareFcn, filterFcn) {
|
|
652
928
|
const generators = generatorList.map((generator) => {
|
|
653
929
|
return {
|
|
@@ -688,7 +964,24 @@ class DLOB {
|
|
|
688
964
|
}
|
|
689
965
|
}
|
|
690
966
|
}
|
|
691
|
-
|
|
967
|
+
/**
|
|
968
|
+
* Yields resting-limit ask nodes for a market — `restingLimit`, `floatingLimit`, and any
|
|
969
|
+
* `signedMsg` asks that have become resting — merged best-price-first (lowest ask price
|
|
970
|
+
* first, ties broken by `getBestNode`'s underlying comparator). Calls
|
|
971
|
+
* `updateRestingLimitOrders(slot)` first. `tickSize` is threaded into every price comparison
|
|
972
|
+
* via `DLOBNode.getPriceOrThrow`, so pass the market's `orderTickSize` to match on-chain
|
|
973
|
+
* price standardization — omitting it defaults to no rounding (tick of 1).
|
|
974
|
+
*
|
|
975
|
+
* @param marketIndex the market to scan
|
|
976
|
+
* @param slot current slot
|
|
977
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
978
|
+
* @param oraclePriceData oracle price data for the market; required for spot markets (throws if missing)
|
|
979
|
+
* @param filterFcn optional predicate; nodes it rejects are skipped
|
|
980
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
981
|
+
* @returns a generator of resting-limit ask nodes, best price first
|
|
982
|
+
* @throws if `marketType` is spot and `oraclePriceData` is not provided; also throws (via `getPriceOrThrow`) if any node has no resolvable limit price
|
|
983
|
+
*/
|
|
984
|
+
*getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, filterFcn, tickSize) {
|
|
692
985
|
if ((0, types_1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
693
986
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
694
987
|
}
|
|
@@ -705,11 +998,12 @@ class DLOB {
|
|
|
705
998
|
];
|
|
706
999
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
707
1000
|
return bestNode
|
|
708
|
-
.getPriceOrThrow(oraclePriceData, slot)
|
|
709
|
-
.lt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
1001
|
+
.getPriceOrThrow(oraclePriceData, slot, tickSize)
|
|
1002
|
+
.lt(currentNode.getPriceOrThrow(oraclePriceData, slot, tickSize));
|
|
710
1003
|
}, filterFcn);
|
|
711
1004
|
}
|
|
712
|
-
|
|
1005
|
+
/** Same as `getRestingLimitAsks`, but for the bid side (merged best-price-first, highest bid first). */
|
|
1006
|
+
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, filterFcn, tickSize) {
|
|
713
1007
|
if ((0, types_1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
714
1008
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
715
1009
|
}
|
|
@@ -726,31 +1020,38 @@ class DLOB {
|
|
|
726
1020
|
];
|
|
727
1021
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
728
1022
|
return bestNode
|
|
729
|
-
.getPriceOrThrow(oraclePriceData, slot)
|
|
730
|
-
.gt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
1023
|
+
.getPriceOrThrow(oraclePriceData, slot, tickSize)
|
|
1024
|
+
.gt(currentNode.getPriceOrThrow(oraclePriceData, slot, tickSize));
|
|
731
1025
|
}, filterFcn);
|
|
732
1026
|
}
|
|
733
1027
|
/**
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
* @param
|
|
1028
|
+
* Merges `getTakingAsks` and `getRestingLimitAsks` into a single best-price-first generator
|
|
1029
|
+
* (ties broken by earliest arrival slot). Nodes with no resolvable price (e.g. still
|
|
1030
|
+
* mid-auction) sort as price `0` — i.e. best — since `getPrice` (not `getPriceOrThrow`) is
|
|
1031
|
+
* used here. Unlike `findTakingNodesToFill`/`findNodesToFill`, this does **not** merge in
|
|
1032
|
+
* fallback (e.g. vAMM) liquidity; the `fallbackAsk` parameter is currently unused/reserved.
|
|
1033
|
+
*
|
|
1034
|
+
* @param marketIndex the market to scan
|
|
1035
|
+
* @param fallbackAsk currently unused
|
|
1036
|
+
* @param slot current slot
|
|
1037
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1038
|
+
* @param oraclePriceData oracle price data for the market; required for spot markets (throws if missing)
|
|
1039
|
+
* @param filterFcn optional predicate; nodes it rejects are skipped
|
|
1040
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1041
|
+
* @returns a generator of all ask nodes (taking + resting-limit), best price first
|
|
741
1042
|
*/
|
|
742
|
-
*getAsks(marketIndex, _fallbackAsk, slot, marketType, oraclePriceData, filterFcn) {
|
|
1043
|
+
*getAsks(marketIndex, _fallbackAsk, slot, marketType, oraclePriceData, filterFcn, tickSize) {
|
|
743
1044
|
if ((0, types_1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
744
1045
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
745
1046
|
}
|
|
746
1047
|
const generatorList = [
|
|
747
1048
|
this.getTakingAsks(marketIndex, marketType, slot, oraclePriceData),
|
|
748
|
-
this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData),
|
|
1049
|
+
this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize),
|
|
749
1050
|
];
|
|
750
1051
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
751
1052
|
var _a, _b;
|
|
752
|
-
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO;
|
|
753
|
-
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.ZERO;
|
|
1053
|
+
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot, tickSize)) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO;
|
|
1054
|
+
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot, tickSize)) !== null && _b !== void 0 ? _b : numericConstants_1.ZERO;
|
|
754
1055
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
755
1056
|
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
756
1057
|
}
|
|
@@ -758,39 +1059,61 @@ class DLOB {
|
|
|
758
1059
|
}, filterFcn);
|
|
759
1060
|
}
|
|
760
1061
|
/**
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
* @param
|
|
767
|
-
* @param
|
|
1062
|
+
* Merges `getTakingBids` and `getRestingLimitBids` into a single best-price-first generator
|
|
1063
|
+
* (ties broken by earliest arrival slot). Nodes with no resolvable price sort as `BN_MAX` —
|
|
1064
|
+
* i.e. worst — since a priceless bid shouldn't be preferred over a priced one. Does not merge
|
|
1065
|
+
* in fallback (e.g. vAMM) liquidity; the `fallbackBid` parameter is currently unused/reserved.
|
|
1066
|
+
*
|
|
1067
|
+
* @param marketIndex the market to scan
|
|
1068
|
+
* @param fallbackBid currently unused
|
|
1069
|
+
* @param slot current slot
|
|
1070
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1071
|
+
* @param oraclePriceData oracle price data for the market; required for spot markets (throws if missing)
|
|
1072
|
+
* @param filterFcn optional predicate; nodes it rejects are skipped
|
|
1073
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1074
|
+
* @returns a generator of all bid nodes (taking + resting-limit), best price first
|
|
768
1075
|
*/
|
|
769
|
-
*getBids(marketIndex, _fallbackBid, slot, marketType, oraclePriceData, filterFcn) {
|
|
1076
|
+
*getBids(marketIndex, _fallbackBid, slot, marketType, oraclePriceData, filterFcn, tickSize) {
|
|
770
1077
|
if ((0, types_1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
771
1078
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
772
1079
|
}
|
|
773
1080
|
const generatorList = [
|
|
774
1081
|
this.getTakingBids(marketIndex, marketType, slot, oraclePriceData),
|
|
775
|
-
this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData),
|
|
1082
|
+
this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize),
|
|
776
1083
|
];
|
|
777
1084
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
778
1085
|
var _a, _b;
|
|
779
|
-
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.BN_MAX;
|
|
780
|
-
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.BN_MAX;
|
|
1086
|
+
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot, tickSize)) !== null && _a !== void 0 ? _a : numericConstants_1.BN_MAX;
|
|
1087
|
+
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot, tickSize)) !== null && _b !== void 0 ? _b : numericConstants_1.BN_MAX;
|
|
781
1088
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
782
1089
|
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
783
1090
|
}
|
|
784
1091
|
return bestNodePrice.gt(currentNodePrice);
|
|
785
1092
|
}, filterFcn);
|
|
786
1093
|
}
|
|
787
|
-
|
|
1094
|
+
/**
|
|
1095
|
+
* Finds pairs of resting-limit asks and bids that cross each other (`bidPrice >= askPrice`),
|
|
1096
|
+
* assigns maker/taker roles via `determineMakerAndTaker` (post-only orders are always makers;
|
|
1097
|
+
* otherwise whichever order's auction finished later is the taker), and simulates the fill by
|
|
1098
|
+
* updating both orders' `baseAssetAmountFilled` in their `NodeList`s so subsequent iterations
|
|
1099
|
+
* see the reduced remaining size. Same-user matches are skipped. Because both ask and bid
|
|
1100
|
+
* generators are price-sorted, the inner loop `break`s as soon as `bidPrice < askPrice` for a
|
|
1101
|
+
* given ask, since no later (worse) bid can cross either.
|
|
1102
|
+
*
|
|
1103
|
+
* @param marketIndex the market to scan
|
|
1104
|
+
* @param slot current slot
|
|
1105
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1106
|
+
* @param oraclePriceData oracle price data for the market
|
|
1107
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), threaded into all price lookups
|
|
1108
|
+
* @returns `NodeToFill`s (taker node + one maker node each) for every crossing pair found
|
|
1109
|
+
*/
|
|
1110
|
+
findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData, tickSize) {
|
|
788
1111
|
const nodesToFill = new Array();
|
|
789
|
-
for (const askNode of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)) {
|
|
790
|
-
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
1112
|
+
for (const askNode of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize)) {
|
|
1113
|
+
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
791
1114
|
for (const bidNode of bidGenerator) {
|
|
792
|
-
const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot);
|
|
793
|
-
const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot);
|
|
1115
|
+
const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot, tickSize);
|
|
1116
|
+
const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot, tickSize);
|
|
794
1117
|
// orders don't cross
|
|
795
1118
|
if (bidPrice.lt(askPrice)) {
|
|
796
1119
|
break;
|
|
@@ -831,6 +1154,16 @@ class DLOB {
|
|
|
831
1154
|
}
|
|
832
1155
|
return nodesToFill;
|
|
833
1156
|
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Decides which of a crossing ask/bid pair is the maker and which is the taker: if both are
|
|
1159
|
+
* post-only, they can't be matched (`undefined`); if exactly one is post-only, it's the
|
|
1160
|
+
* maker; otherwise whichever order's auction window (`order.slot + order.auctionDuration`)
|
|
1161
|
+
* ends later is treated as the taker (it "arrived crossing" the earlier order).
|
|
1162
|
+
*
|
|
1163
|
+
* @param askNode the crossing ask node
|
|
1164
|
+
* @param bidNode the crossing bid node
|
|
1165
|
+
* @returns the assigned `{ takerNode, makerNode }`, or `undefined` if both orders are post-only and neither can take
|
|
1166
|
+
*/
|
|
834
1167
|
determineMakerAndTaker(askNode, bidNode) {
|
|
835
1168
|
const askOrder = getOrderOrThrow(askNode);
|
|
836
1169
|
const bidOrder = getOrderOrThrow(bidNode);
|
|
@@ -864,20 +1197,54 @@ class DLOB {
|
|
|
864
1197
|
};
|
|
865
1198
|
}
|
|
866
1199
|
}
|
|
867
|
-
|
|
868
|
-
|
|
1200
|
+
/**
|
|
1201
|
+
* Gets the best (lowest) resting-limit ask price for a market. Does not consider fallback
|
|
1202
|
+
* (e.g. vAMM) liquidity.
|
|
1203
|
+
*
|
|
1204
|
+
* @param marketIndex the market to query
|
|
1205
|
+
* @param slot current slot
|
|
1206
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1207
|
+
* @param oraclePriceData oracle price data for the market
|
|
1208
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1209
|
+
* @returns the best ask price, PRICE_PRECISION (1e6), or `undefined` if there are no resting-limit asks
|
|
1210
|
+
*/
|
|
1211
|
+
getBestAsk(marketIndex, slot, marketType, oraclePriceData, tickSize) {
|
|
1212
|
+
const bestAsk = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize).next().value;
|
|
869
1213
|
if (bestAsk) {
|
|
870
|
-
return bestAsk.getPrice(oraclePriceData, slot);
|
|
1214
|
+
return bestAsk.getPrice(oraclePriceData, slot, tickSize);
|
|
871
1215
|
}
|
|
872
1216
|
return undefined;
|
|
873
1217
|
}
|
|
874
|
-
|
|
875
|
-
|
|
1218
|
+
/**
|
|
1219
|
+
* Gets the best (highest) resting-limit bid price for a market. Does not consider fallback
|
|
1220
|
+
* (e.g. vAMM) liquidity.
|
|
1221
|
+
*
|
|
1222
|
+
* @param marketIndex the market to query
|
|
1223
|
+
* @param slot current slot
|
|
1224
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1225
|
+
* @param oraclePriceData oracle price data for the market
|
|
1226
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1227
|
+
* @returns the best bid price, PRICE_PRECISION (1e6), or `undefined` if there are no resting-limit bids
|
|
1228
|
+
*/
|
|
1229
|
+
getBestBid(marketIndex, slot, marketType, oraclePriceData, tickSize) {
|
|
1230
|
+
const bestBid = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize).next().value;
|
|
876
1231
|
if (bestBid) {
|
|
877
|
-
return bestBid.getPrice(oraclePriceData, slot);
|
|
1232
|
+
return bestBid.getPrice(oraclePriceData, slot, tickSize);
|
|
878
1233
|
}
|
|
879
1234
|
return undefined;
|
|
880
1235
|
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Yields untriggered trigger orders that would close a position in `direction`: for a `long`
|
|
1238
|
+
* position, short-direction orders in the `trigger.below` list (stop triggers on a price
|
|
1239
|
+
* drop); for a `short` position, long-direction orders in `trigger.above` (stop triggers on a
|
|
1240
|
+
* price rise). Includes both `triggerMarket` and `triggerLimit` order types — see
|
|
1241
|
+
* `getStopLossMarkets`/`getStopLossLimits` to filter to one.
|
|
1242
|
+
*
|
|
1243
|
+
* @param marketIndex the market to scan
|
|
1244
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1245
|
+
* @param direction the direction of the position being protected (not the order's own direction)
|
|
1246
|
+
* @returns a generator of stop-loss trigger order nodes
|
|
1247
|
+
*/
|
|
881
1248
|
*getStopLosses(marketIndex, marketType, direction) {
|
|
882
1249
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
883
1250
|
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
@@ -896,6 +1263,7 @@ class DLOB {
|
|
|
896
1263
|
}
|
|
897
1264
|
}
|
|
898
1265
|
}
|
|
1266
|
+
/** Same as `getStopLosses`, filtered to `triggerMarket` orders only. */
|
|
899
1267
|
*getStopLossMarkets(marketIndex, marketType, direction) {
|
|
900
1268
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
901
1269
|
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
@@ -903,6 +1271,7 @@ class DLOB {
|
|
|
903
1271
|
}
|
|
904
1272
|
}
|
|
905
1273
|
}
|
|
1274
|
+
/** Same as `getStopLosses`, filtered to `triggerLimit` orders only. */
|
|
906
1275
|
*getStopLossLimits(marketIndex, marketType, direction) {
|
|
907
1276
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
908
1277
|
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
@@ -910,6 +1279,18 @@ class DLOB {
|
|
|
910
1279
|
}
|
|
911
1280
|
}
|
|
912
1281
|
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Yields untriggered trigger orders that would close a position in `direction` for profit:
|
|
1284
|
+
* for a `long` position, short-direction orders in `trigger.above` (take-profit on a price
|
|
1285
|
+
* rise); for a `short` position, long-direction orders in `trigger.below` (take-profit on a
|
|
1286
|
+
* price drop). Includes both `triggerMarket` and `triggerLimit` order types — see
|
|
1287
|
+
* `getTakeProfitMarkets`/`getTakeProfitLimits` to filter to one.
|
|
1288
|
+
*
|
|
1289
|
+
* @param marketIndex the market to scan
|
|
1290
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1291
|
+
* @param direction the direction of the position being protected (not the order's own direction)
|
|
1292
|
+
* @returns a generator of take-profit trigger order nodes
|
|
1293
|
+
*/
|
|
913
1294
|
*getTakeProfits(marketIndex, marketType, direction) {
|
|
914
1295
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
915
1296
|
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
@@ -928,6 +1309,7 @@ class DLOB {
|
|
|
928
1309
|
}
|
|
929
1310
|
}
|
|
930
1311
|
}
|
|
1312
|
+
/** Same as `getTakeProfits`, filtered to `triggerMarket` orders only. */
|
|
931
1313
|
*getTakeProfitMarkets(marketIndex, marketType, direction) {
|
|
932
1314
|
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
933
1315
|
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
@@ -935,6 +1317,7 @@ class DLOB {
|
|
|
935
1317
|
}
|
|
936
1318
|
}
|
|
937
1319
|
}
|
|
1320
|
+
/** Same as `getTakeProfits`, filtered to `triggerLimit` orders only. */
|
|
938
1321
|
*getTakeProfitLimits(marketIndex, marketType, direction) {
|
|
939
1322
|
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
940
1323
|
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
@@ -942,6 +1325,20 @@ class DLOB {
|
|
|
942
1325
|
}
|
|
943
1326
|
}
|
|
944
1327
|
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Finds trigger orders whose condition is now satisfied by `triggerPrice`: `trigger.above`
|
|
1330
|
+
* orders with `triggerPrice > order.triggerPrice`, and `trigger.below` orders with
|
|
1331
|
+
* `triggerPrice < order.triggerPrice`. Both lists are sorted by trigger price with the
|
|
1332
|
+
* nearest-to-triggering order at `head`, so each scan walks from `head` and `break`s at the
|
|
1333
|
+
* first order that isn't (yet) triggered. Returns `[]` immediately if the exchange is paused.
|
|
1334
|
+
*
|
|
1335
|
+
* @param marketIndex the market to scan
|
|
1336
|
+
* @param slot current slot (currently unused by the scan itself, reserved for future use)
|
|
1337
|
+
* @param triggerPrice the price to check trigger conditions against, PRICE_PRECISION (1e6) — typically the current oracle or mark price
|
|
1338
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1339
|
+
* @param stateAccount global protocol state, used for the exchange-pause check
|
|
1340
|
+
* @returns `NodeToTrigger`s for every order ready to be triggered on-chain
|
|
1341
|
+
*/
|
|
945
1342
|
findNodesToTrigger(marketIndex, slot, triggerPrice, marketType, stateAccount) {
|
|
946
1343
|
var _a;
|
|
947
1344
|
if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
|
|
@@ -983,6 +1380,17 @@ class DLOB {
|
|
|
983
1380
|
}
|
|
984
1381
|
return nodesToTrigger;
|
|
985
1382
|
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Debug helper: logs the market's best bid, best ask, and mid price (all resting-limit only,
|
|
1385
|
+
* no fallback liquidity), along with each side's spread to the current oracle price, as a
|
|
1386
|
+
* percentage.
|
|
1387
|
+
*
|
|
1388
|
+
* @param velocityClient client used to resolve market accounts and oracle price data
|
|
1389
|
+
* @param slotSubscriber source of the current slot
|
|
1390
|
+
* @param marketIndex the market to print
|
|
1391
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1392
|
+
* @throws if the market currently has no resting-limit bid or ask (best bid/ask is `undefined`)
|
|
1393
|
+
*/
|
|
986
1394
|
printTop(velocityClient, slotSubscriber, marketIndex, marketType) {
|
|
987
1395
|
if ((0, types_1.isVariant)(marketType, 'perp')) {
|
|
988
1396
|
const slot = slotSubscriber.getSlot();
|
|
@@ -1031,6 +1439,7 @@ class DLOB {
|
|
|
1031
1439
|
console.log(` Bid`, (0, conversion_1.convertToNumber)(bestBid, numericConstants_1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
|
|
1032
1440
|
}
|
|
1033
1441
|
}
|
|
1442
|
+
/** Flattens every order across every `NodeList` (perp and spot, all categories/sides) into a single `DLOBOrders` array of `{ user, order }` pairs, in no particular cross-list order. */
|
|
1034
1443
|
getDLOBOrders() {
|
|
1035
1444
|
const dlobOrders = [];
|
|
1036
1445
|
for (const nodeList of this.getNodeLists()) {
|
|
@@ -1043,6 +1452,7 @@ class DLOB {
|
|
|
1043
1452
|
}
|
|
1044
1453
|
return dlobOrders;
|
|
1045
1454
|
}
|
|
1455
|
+
/** Yields every `NodeList` (all ten category/side combinations, per market) across every perp market, then every spot market. Used by `getOrder`/`getDLOBOrders` to walk the entire book. */
|
|
1046
1456
|
*getNodeLists() {
|
|
1047
1457
|
for (const [_, nodeLists] of this.getOrderListsForMarketType('perp')) {
|
|
1048
1458
|
yield nodeLists.restingLimit.bid;
|
|
@@ -1070,17 +1480,23 @@ class DLOB {
|
|
|
1070
1480
|
}
|
|
1071
1481
|
}
|
|
1072
1482
|
/**
|
|
1073
|
-
* Get an L2 view of the order book for a given market
|
|
1483
|
+
* Get an L2 (aggregated price/size) view of the order book for a given market: resting-limit
|
|
1484
|
+
* DLOB liquidity merged with any supplied fallback generators (e.g. the vAMM, via
|
|
1485
|
+
* `getVammL2Generator`), then bucketed into up to `depth` levels per side via `createL2Levels`.
|
|
1486
|
+
* Does not include taking (still-auctioning) orders — only resting-limit makers and fallback
|
|
1487
|
+
* liquidity are represented.
|
|
1074
1488
|
*
|
|
1075
|
-
* @param marketIndex
|
|
1076
|
-
* @param marketType
|
|
1077
|
-
* @param slot
|
|
1078
|
-
* @param oraclePriceData
|
|
1079
|
-
* @param depth how many levels of the order book to return
|
|
1080
|
-
* @param fallbackL2Generators
|
|
1489
|
+
* @param marketIndex the market to build a book for
|
|
1490
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1491
|
+
* @param slot current slot, used to resolve resting-limit order prices
|
|
1492
|
+
* @param oraclePriceData oracle price data for the market
|
|
1493
|
+
* @param depth how many price levels of the order book to return, per side
|
|
1494
|
+
* @param fallbackL2Generators additional non-DLOB liquidity sources to merge in, e.g. `getVammL2Generator`'s output; defaults to `[]`
|
|
1495
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6), threaded into all DLOB price lookups; defaults to no rounding if omitted
|
|
1496
|
+
* @returns the merged `L2OrderBook`, tagged with the given `slot`
|
|
1081
1497
|
*/
|
|
1082
|
-
getL2({ marketIndex, marketType, slot, oraclePriceData, depth, fallbackL2Generators = [], }) {
|
|
1083
|
-
const makerAskL2LevelGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData), oraclePriceData, slot);
|
|
1498
|
+
getL2({ marketIndex, marketType, slot, oraclePriceData, depth, fallbackL2Generators = [], tickSize, }) {
|
|
1499
|
+
const makerAskL2LevelGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize), oraclePriceData, slot, tickSize);
|
|
1084
1500
|
const fallbackAskGenerators = fallbackL2Generators.map((fallbackL2Generator) => {
|
|
1085
1501
|
return fallbackL2Generator.getL2Asks();
|
|
1086
1502
|
});
|
|
@@ -1088,7 +1504,7 @@ class DLOB {
|
|
|
1088
1504
|
return a.price.lt(b.price);
|
|
1089
1505
|
});
|
|
1090
1506
|
const asks = (0, orderBookLevels_1.createL2Levels)(askL2LevelGenerator, depth);
|
|
1091
|
-
const makerBidGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData), oraclePriceData, slot);
|
|
1507
|
+
const makerBidGenerator = (0, orderBookLevels_1.getL2GeneratorFromDLOBNodes)(this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize), oraclePriceData, slot, tickSize);
|
|
1092
1508
|
const fallbackBidGenerators = fallbackL2Generators.map((fallbackOrders) => {
|
|
1093
1509
|
return fallbackOrders.getL2Bids();
|
|
1094
1510
|
});
|
|
@@ -1103,31 +1519,34 @@ class DLOB {
|
|
|
1103
1519
|
};
|
|
1104
1520
|
}
|
|
1105
1521
|
/**
|
|
1106
|
-
* Get an L3 view of the order book for a given market.
|
|
1522
|
+
* Get an L3 (individual resting order) view of the order book for a given market. Only
|
|
1523
|
+
* resting-limit orders are included — no taking orders and no fallback (e.g. vAMM) liquidity.
|
|
1107
1524
|
*
|
|
1108
|
-
* @param marketIndex
|
|
1109
|
-
* @param marketType
|
|
1110
|
-
* @param slot
|
|
1111
|
-
* @param oraclePriceData
|
|
1525
|
+
* @param marketIndex the market to build a book for
|
|
1526
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1527
|
+
* @param slot current slot, used to resolve resting-limit order prices
|
|
1528
|
+
* @param oraclePriceData oracle price data for the market
|
|
1529
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1530
|
+
* @returns the `L3OrderBook`, tagged with the given `slot`
|
|
1112
1531
|
*/
|
|
1113
|
-
getL3({ marketIndex, marketType, slot, oraclePriceData, }) {
|
|
1532
|
+
getL3({ marketIndex, marketType, slot, oraclePriceData, tickSize, }) {
|
|
1114
1533
|
const bids = [];
|
|
1115
1534
|
const asks = [];
|
|
1116
|
-
const restingAsks = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1535
|
+
const restingAsks = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
1117
1536
|
for (const ask of restingAsks) {
|
|
1118
1537
|
const askOrder = getOrderOrThrow(ask);
|
|
1119
1538
|
asks.push({
|
|
1120
|
-
price: ask.getPriceOrThrow(oraclePriceData, slot),
|
|
1539
|
+
price: ask.getPriceOrThrow(oraclePriceData, slot, tickSize),
|
|
1121
1540
|
size: askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled),
|
|
1122
1541
|
maker: new web3_js_1.PublicKey(getUserAccountOrThrow(ask)),
|
|
1123
1542
|
orderId: askOrder.orderId,
|
|
1124
1543
|
});
|
|
1125
1544
|
}
|
|
1126
|
-
const restingBids = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
1545
|
+
const restingBids = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
1127
1546
|
for (const bid of restingBids) {
|
|
1128
1547
|
const bidOrder = getOrderOrThrow(bid);
|
|
1129
1548
|
bids.push({
|
|
1130
|
-
price: bid.getPriceOrThrow(oraclePriceData, slot),
|
|
1549
|
+
price: bid.getPriceOrThrow(oraclePriceData, slot, tickSize),
|
|
1131
1550
|
size: bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled),
|
|
1132
1551
|
maker: new web3_js_1.PublicKey(getUserAccountOrThrow(bid)),
|
|
1133
1552
|
orderId: bidOrder.orderId,
|
|
@@ -1139,11 +1558,11 @@ class DLOB {
|
|
|
1139
1558
|
slot,
|
|
1140
1559
|
};
|
|
1141
1560
|
}
|
|
1142
|
-
estimateFillExactBaseAmountInForSide(baseAmountIn, oraclePriceData, slot, dlobSide) {
|
|
1561
|
+
estimateFillExactBaseAmountInForSide(baseAmountIn, oraclePriceData, slot, dlobSide, tickSize) {
|
|
1143
1562
|
let runningSumQuote = numericConstants_1.ZERO;
|
|
1144
1563
|
let runningSumBase = numericConstants_1.ZERO;
|
|
1145
1564
|
for (const side of dlobSide) {
|
|
1146
|
-
const price = side.getPriceOrThrow(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
|
|
1565
|
+
const price = side.getPriceOrThrow(oraclePriceData, slot, tickSize); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
|
|
1147
1566
|
const sideOrder = getOrderOrThrow(side);
|
|
1148
1567
|
const baseAmountRemaining = sideOrder.baseAssetAmount.sub(sideOrder.baseAssetAmountFilled);
|
|
1149
1568
|
if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
|
|
@@ -1162,29 +1581,52 @@ class DLOB {
|
|
|
1162
1581
|
.div(numericConstants_1.BASE_PRECISION.mul(numericConstants_1.PRICE_PRECISION));
|
|
1163
1582
|
}
|
|
1164
1583
|
/**
|
|
1584
|
+
* Estimates the quote amount that would be filled for a given base amount, walking
|
|
1585
|
+
* resting-limit asks (for a `long`/buy) or bids (for a `short`/sell) from best price outward
|
|
1586
|
+
* and summing `price * size` until `baseAmount` is consumed. Does not include fallback (e.g.
|
|
1587
|
+
* vAMM) liquidity or taking orders, and does not mutate any order state — this is a read-only
|
|
1588
|
+
* estimate, not a simulated fill.
|
|
1165
1589
|
*
|
|
1166
|
-
* @param
|
|
1167
|
-
* @param
|
|
1168
|
-
* @param
|
|
1169
|
-
* @param
|
|
1170
|
-
* @param
|
|
1171
|
-
* @param
|
|
1172
|
-
* @
|
|
1590
|
+
* @param marketIndex the market to estimate against
|
|
1591
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1592
|
+
* @param baseAmount the base amount to fill, BASE_PRECISION (1e9)
|
|
1593
|
+
* @param orderDirection direction of the hypothetical taker order (`long` walks asks, `short` walks bids)
|
|
1594
|
+
* @param slot current slot, used to resolve resting-limit order prices
|
|
1595
|
+
* @param oraclePriceData oracle price data for the market
|
|
1596
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1597
|
+
* @returns the estimated quote amount filled, QUOTE_PRECISION (1e6); if resting liquidity is thinner than `baseAmount`, the result silently reflects only the liquidity that was actually walked (no error/flag for partial fill), and is `0` if there is no resting liquidity on that side at all
|
|
1598
|
+
* @throws if `orderDirection` is neither `long` nor `short`
|
|
1173
1599
|
*/
|
|
1174
|
-
estimateFillWithExactBaseAmount({ marketIndex, marketType, baseAmount, orderDirection, slot, oraclePriceData, }) {
|
|
1600
|
+
estimateFillWithExactBaseAmount({ marketIndex, marketType, baseAmount, orderDirection, slot, oraclePriceData, tickSize, }) {
|
|
1175
1601
|
if ((0, types_1.isVariant)(orderDirection, 'long')) {
|
|
1176
|
-
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData));
|
|
1602
|
+
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize), tickSize);
|
|
1177
1603
|
}
|
|
1178
1604
|
else if ((0, types_1.isVariant)(orderDirection, 'short')) {
|
|
1179
|
-
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData));
|
|
1605
|
+
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize), tickSize);
|
|
1180
1606
|
}
|
|
1181
1607
|
throw new Error(`Invalid order direction ${(0, types_1.getVariant)(orderDirection)}: must be long or short`);
|
|
1182
1608
|
}
|
|
1183
|
-
|
|
1609
|
+
/**
|
|
1610
|
+
* Collects the pubkeys of up to `numMakers` distinct makers currently resting best-priced on
|
|
1611
|
+
* one side of the book — bids for a `long` taker, asks for a `short` taker — in best-price
|
|
1612
|
+
* order. Used to pick candidate maker accounts to pass as `remaining_accounts` when
|
|
1613
|
+
* submitting a fill instruction. A maker with multiple resting orders at different prices
|
|
1614
|
+
* only counts once toward `numMakers`.
|
|
1615
|
+
*
|
|
1616
|
+
* @param marketIndex the market to scan
|
|
1617
|
+
* @param marketType `MarketType.PERP` or `MarketType.SPOT`
|
|
1618
|
+
* @param direction direction of the taker order being matched (`long` collects bid-side makers, `short` collects ask-side makers)
|
|
1619
|
+
* @param slot current slot, used to resolve resting-limit order prices
|
|
1620
|
+
* @param oraclePriceData oracle price data for the market
|
|
1621
|
+
* @param numMakers maximum number of distinct maker pubkeys to return
|
|
1622
|
+
* @param tickSize market order tick size, PRICE_PRECISION (1e6); defaults to no rounding if omitted
|
|
1623
|
+
* @returns up to `numMakers` distinct maker `PublicKey`s, best price first
|
|
1624
|
+
*/
|
|
1625
|
+
getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, tickSize, }) {
|
|
1184
1626
|
const makers = new Map();
|
|
1185
1627
|
const generator = (0, types_1.isVariant)(direction, 'long')
|
|
1186
|
-
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
1187
|
-
: this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1628
|
+
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize)
|
|
1629
|
+
: this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, undefined, tickSize);
|
|
1188
1630
|
for (const node of generator) {
|
|
1189
1631
|
const userAccount = getUserAccountOrThrow(node);
|
|
1190
1632
|
if (!makers.has(userAccount)) {
|