@velocity-exchange/sdk 0.1.0 → 0.2.1
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 +4 -32
- package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +5 -3
- package/lib/browser/accounts/basicUserAccountSubscriber.js +4 -3
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +4 -3
- package/lib/browser/accounts/bulkAccountLoader.d.ts +5 -5
- package/lib/browser/accounts/bulkAccountLoader.js +12 -1
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcAccountSubscriber.js +8 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +13 -5
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +12 -8
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +8 -2
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +3 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.js +4 -3
- package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
- package/lib/browser/accounts/pollingOracleAccountSubscriber.js +16 -5
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
- package/lib/browser/accounts/pollingTokenAccountSubscriber.js +16 -5
- package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +8 -4
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +17 -11
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +6 -6
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
- package/lib/browser/accounts/types.d.ts +4 -4
- package/lib/browser/accounts/utils.d.ts +1 -0
- package/lib/browser/accounts/utils.js +8 -1
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketAccountSubscriber.js +17 -5
- package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
- package/lib/browser/accounts/webSocketAccountSubscriberV2.js +17 -6
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +14 -3
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +0 -3
- package/lib/browser/addresses/marketAddresses.js +3 -2
- package/lib/browser/addresses/pda.d.ts +0 -2
- package/lib/browser/addresses/pda.js +1 -14
- package/lib/browser/adminClient.d.ts +24 -29
- package/lib/browser/adminClient.js +156 -157
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +1 -1
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +6 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/browser/bankrun/bankrunConnection.d.ts +8 -5
- package/lib/browser/bankrun/bankrunConnection.js +92 -32
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +3 -2
- package/lib/browser/clock/clockSubscriber.d.ts +6 -6
- package/lib/browser/clock/clockSubscriber.js +4 -3
- package/lib/browser/config.d.ts +1 -1
- package/lib/browser/config.js +8 -4
- package/lib/browser/constants/index.d.ts +1 -2
- package/lib/browser/constants/index.js +1 -2
- package/lib/browser/constants/numericConstants.d.ts +1 -2
- package/lib/browser/constants/numericConstants.js +7 -5
- package/lib/browser/constants/spotMarkets.d.ts +0 -1
- package/lib/browser/constituentMap/constituentMap.js +5 -1
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
- package/lib/browser/core/VelocityCore.d.ts +0 -1
- package/lib/browser/core/instructions/deposit.d.ts +0 -1
- package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
- package/lib/browser/core/instructions/perpOrders.js +14 -0
- package/lib/browser/core/instructions/withdraw.d.ts +0 -1
- package/lib/browser/core/remainingAccounts.d.ts +2 -2
- package/lib/browser/core/remainingAccounts.js +2 -2
- package/lib/browser/decode/user.js +9 -1
- package/lib/browser/dlob/DLOB.d.ts +6 -2
- package/lib/browser/dlob/DLOB.js +201 -138
- package/lib/browser/dlob/DLOBNode.d.ts +5 -3
- package/lib/browser/dlob/DLOBNode.js +7 -0
- package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -1
- package/lib/browser/dlob/DLOBSubscriber.js +37 -32
- package/lib/browser/dlob/NodeList.d.ts +0 -1
- package/lib/browser/dlob/NodeList.js +8 -7
- package/lib/browser/dlob/orderBookLevels.d.ts +0 -1
- package/lib/browser/dlob/orderBookLevels.js +19 -12
- package/lib/browser/events/eventList.d.ts +3 -3
- package/lib/browser/events/eventList.js +4 -1
- package/lib/browser/events/eventSubscriber.d.ts +5 -2
- package/lib/browser/events/eventSubscriber.js +75 -26
- package/lib/browser/events/eventsServerLogProvider.d.ts +2 -2
- package/lib/browser/events/eventsServerLogProvider.js +15 -8
- package/lib/browser/events/fetchLogs.d.ts +1 -1
- package/lib/browser/events/fetchLogs.js +4 -2
- package/lib/browser/events/pollingLogProvider.d.ts +2 -2
- package/lib/browser/events/pollingLogProvider.js +1 -0
- package/lib/browser/events/txEventCache.d.ts +3 -3
- package/lib/browser/events/txEventCache.js +6 -2
- package/lib/browser/events/types.d.ts +2 -4
- package/lib/browser/events/types.js +0 -2
- package/lib/browser/events/webSocketLogProvider.d.ts +2 -2
- package/lib/browser/events/webSocketLogProvider.js +5 -2
- package/lib/browser/factory/bigNum.d.ts +0 -1
- package/lib/browser/factory/bigNum.js +1 -1
- package/lib/browser/idl/velocity.d.ts +1243 -1586
- package/lib/browser/idl/velocity.json +1234 -1577
- package/lib/browser/index.d.ts +0 -2
- package/lib/browser/index.js +0 -2
- package/lib/browser/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
- package/lib/browser/jupiter/jupiterClient.d.ts +1 -2
- package/lib/browser/jupiter/jupiterClient.js +18 -8
- package/lib/browser/marginCalculation.d.ts +0 -1
- package/lib/browser/marginCalculation.js +1 -0
- package/lib/browser/marinade/index.d.ts +2 -3
- package/lib/browser/marinade/index.js +5 -0
- package/lib/browser/math/amm.d.ts +31 -14
- package/lib/browser/math/amm.js +77 -22
- package/lib/browser/math/auction.d.ts +0 -1
- package/lib/browser/math/bankruptcy.js +1 -1
- package/lib/browser/math/conversion.d.ts +0 -1
- package/lib/browser/math/funding.d.ts +0 -1
- package/lib/browser/math/funding.js +6 -6
- package/lib/browser/math/insurance.d.ts +1 -2
- package/lib/browser/math/insurance.js +4 -5
- package/lib/browser/math/liquidation.d.ts +0 -1
- package/lib/browser/math/margin.d.ts +1 -10
- package/lib/browser/math/margin.js +3 -62
- package/lib/browser/math/market.d.ts +4 -13
- package/lib/browser/math/market.js +6 -40
- package/lib/browser/math/oracles.d.ts +0 -4
- package/lib/browser/math/oracles.js +1 -14
- package/lib/browser/math/orders.d.ts +0 -6
- package/lib/browser/math/orders.js +2 -74
- package/lib/browser/math/position.d.ts +1 -6
- package/lib/browser/math/position.js +5 -10
- package/lib/browser/math/repeg.d.ts +0 -2
- package/lib/browser/math/repeg.js +1 -23
- package/lib/browser/math/spotBalance.d.ts +4 -5
- package/lib/browser/math/spotBalance.js +6 -6
- package/lib/browser/math/spotMarket.d.ts +0 -7
- package/lib/browser/math/spotMarket.js +1 -16
- package/lib/browser/math/spotPosition.d.ts +4 -5
- package/lib/browser/math/state.d.ts +0 -3
- package/lib/browser/math/state.js +1 -9
- package/lib/browser/math/superStake.d.ts +3 -54
- package/lib/browser/math/superStake.js +16 -13
- package/lib/browser/math/trade.d.ts +2 -3
- package/lib/browser/math/trade.js +6 -6
- package/lib/browser/math/utils.d.ts +0 -1
- package/lib/browser/memcmp.d.ts +0 -1
- package/lib/browser/memcmp.js +1 -10
- package/lib/browser/oracles/oracleClientCache.d.ts +1 -1
- package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
- package/lib/browser/oracles/pythClient.d.ts +0 -1
- package/lib/browser/oracles/pythClient.js +9 -3
- package/lib/browser/oracles/pythLazerClient.d.ts +0 -1
- package/lib/browser/oracles/pythLazerClient.js +3 -2
- package/lib/browser/oracles/strictOraclePrice.d.ts +0 -1
- package/lib/browser/oracles/types.d.ts +0 -1
- package/lib/browser/oracles/utils.d.ts +4 -1
- package/lib/browser/oracles/utils.js +9 -1
- package/lib/browser/orderParams.d.ts +0 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +8 -2
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +32 -8
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/pyth/types.d.ts +0 -1
- package/lib/browser/slot/SlotSubscriber.d.ts +1 -1
- package/lib/browser/slot/SlotSubscriber.js +2 -1
- package/lib/browser/slot/SlothashSubscriber.d.ts +3 -2
- package/lib/browser/slot/SlothashSubscriber.js +11 -4
- package/lib/browser/swap/UnifiedSwapClient.d.ts +0 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +13 -5
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +1 -1
- package/lib/browser/swift/swiftOrderSubscriber.js +10 -5
- package/lib/browser/testClient.js +3 -2
- package/lib/browser/titan/titanClient.d.ts +0 -1
- package/lib/browser/tokenFaucet.d.ts +0 -1
- package/lib/browser/tokenFaucet.js +16 -2
- package/lib/browser/tx/baseTxSender.d.ts +4 -4
- package/lib/browser/tx/baseTxSender.js +5 -4
- package/lib/browser/tx/fastSingleTxSender.d.ts +3 -3
- package/lib/browser/tx/fastSingleTxSender.js +9 -5
- package/lib/browser/tx/reportTransactionError.d.ts +2 -2
- package/lib/browser/tx/reportTransactionError.js +5 -1
- package/lib/browser/tx/retryTxSender.d.ts +1 -1
- package/lib/browser/tx/retryTxSender.js +4 -2
- package/lib/browser/tx/txHandler.d.ts +9 -3
- package/lib/browser/tx/txHandler.js +54 -40
- package/lib/browser/tx/txParamProcessor.d.ts +4 -1
- package/lib/browser/tx/txParamProcessor.js +6 -0
- package/lib/browser/tx/types.d.ts +1 -1
- package/lib/browser/tx/whileValidTxSender.d.ts +1 -6
- package/lib/browser/tx/whileValidTxSender.js +35 -13
- package/lib/browser/types.d.ts +25 -69
- package/lib/browser/types.js +2 -2
- package/lib/browser/user.d.ts +21 -8
- package/lib/browser/user.js +156 -132
- package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
- package/lib/browser/userMap/referrerMap.js +10 -3
- package/lib/browser/userMap/revenueShareEscrowMap.js +4 -0
- package/lib/browser/userMap/userMap.d.ts +1 -1
- package/lib/browser/userMap/userMap.js +36 -23
- package/lib/browser/userMap/userStatsMap.d.ts +1 -1
- package/lib/browser/userMap/userStatsMap.js +18 -13
- package/lib/browser/userStats.d.ts +7 -2
- package/lib/browser/userStats.js +18 -4
- package/lib/browser/util/TransactionConfirmationManager.js +4 -2
- package/lib/browser/util/chainClock.d.ts +1 -1
- package/lib/browser/util/computeUnits.d.ts +1 -1
- package/lib/browser/util/computeUnits.js +6 -1
- package/lib/browser/velocityClient.d.ts +93 -36
- package/lib/browser/velocityClient.js +414 -280
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +5 -3
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserAccountSubscriber.js +4 -3
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserStatsAccountSubscriber.js +4 -3
- package/lib/node/accounts/bulkAccountLoader.d.ts +5 -5
- package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/bulkAccountLoader.js +12 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcAccountSubscriber.js +8 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +13 -5
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +12 -8
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +8 -2
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +3 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +4 -3
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +16 -5
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +16 -5
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +8 -4
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserAccountSubscriber.js +17 -11
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +6 -6
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
- package/lib/node/accounts/types.d.ts +4 -4
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/utils.d.ts +1 -0
- package/lib/node/accounts/utils.d.ts.map +1 -1
- package/lib/node/accounts/utils.js +8 -1
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.js +17 -5
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriberV2.js +17 -6
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +14 -3
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +0 -3
- package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
- package/lib/node/addresses/marketAddresses.js +3 -2
- package/lib/node/addresses/pda.d.ts +0 -2
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +1 -14
- package/lib/node/adminClient.d.ts +24 -29
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +156 -157
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +6 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/node/bankrun/bankrunConnection.d.ts +8 -5
- package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.js +92 -32
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +3 -2
- package/lib/node/clock/clockSubscriber.d.ts +6 -6
- package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
- package/lib/node/clock/clockSubscriber.js +4 -3
- package/lib/node/config.d.ts +1 -1
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +8 -4
- package/lib/node/constants/index.d.ts +1 -2
- package/lib/node/constants/index.d.ts.map +1 -1
- package/lib/node/constants/index.js +1 -2
- package/lib/node/constants/numericConstants.d.ts +1 -2
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +7 -5
- package/lib/node/constants/spotMarkets.d.ts +0 -1
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +5 -1
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
- package/lib/node/core/VelocityCore.d.ts +0 -1
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/instructions/deposit.d.ts +0 -1
- package/lib/node/core/instructions/deposit.d.ts.map +1 -1
- package/lib/node/core/instructions/perpOrders.d.ts +14 -0
- package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
- package/lib/node/core/instructions/perpOrders.js +14 -0
- package/lib/node/core/instructions/withdraw.d.ts +0 -1
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
- package/lib/node/core/remainingAccounts.d.ts +2 -2
- package/lib/node/core/remainingAccounts.d.ts.map +1 -1
- package/lib/node/core/remainingAccounts.js +2 -2
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +9 -1
- package/lib/node/dlob/DLOB.d.ts +6 -2
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +201 -138
- package/lib/node/dlob/DLOBNode.d.ts +5 -3
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.js +7 -0
- package/lib/node/dlob/DLOBSubscriber.d.ts +0 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +37 -32
- package/lib/node/dlob/NodeList.d.ts +0 -1
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.js +8 -7
- package/lib/node/dlob/orderBookLevels.d.ts +0 -1
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +19 -12
- package/lib/node/events/eventList.d.ts +3 -3
- package/lib/node/events/eventList.d.ts.map +1 -1
- package/lib/node/events/eventList.js +4 -1
- package/lib/node/events/eventSubscriber.d.ts +5 -2
- package/lib/node/events/eventSubscriber.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.js +75 -26
- package/lib/node/events/eventsServerLogProvider.d.ts +2 -2
- package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
- package/lib/node/events/eventsServerLogProvider.js +15 -8
- package/lib/node/events/fetchLogs.d.ts +1 -1
- package/lib/node/events/fetchLogs.d.ts.map +1 -1
- package/lib/node/events/fetchLogs.js +4 -2
- package/lib/node/events/pollingLogProvider.d.ts +2 -2
- package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
- package/lib/node/events/pollingLogProvider.js +1 -0
- package/lib/node/events/txEventCache.d.ts +3 -3
- package/lib/node/events/txEventCache.d.ts.map +1 -1
- package/lib/node/events/txEventCache.js +6 -2
- package/lib/node/events/types.d.ts +2 -4
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +0 -2
- package/lib/node/events/webSocketLogProvider.d.ts +2 -2
- package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
- package/lib/node/events/webSocketLogProvider.js +5 -2
- package/lib/node/factory/bigNum.d.ts +0 -1
- package/lib/node/factory/bigNum.d.ts.map +1 -1
- package/lib/node/factory/bigNum.js +1 -1
- package/lib/node/idl/velocity.d.ts +1243 -1586
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +1234 -1577
- package/lib/node/index.d.ts +0 -2
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +0 -2
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.d.ts +1 -2
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.js +18 -8
- package/lib/node/marginCalculation.d.ts +0 -1
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marginCalculation.js +1 -0
- package/lib/node/marinade/index.d.ts +2 -3
- package/lib/node/marinade/index.d.ts.map +1 -1
- package/lib/node/marinade/index.js +5 -0
- package/lib/node/math/amm.d.ts +31 -14
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +77 -22
- package/lib/node/math/auction.d.ts +0 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/bankruptcy.js +1 -1
- package/lib/node/math/conversion.d.ts +0 -1
- package/lib/node/math/conversion.d.ts.map +1 -1
- package/lib/node/math/funding.d.ts +0 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +6 -6
- package/lib/node/math/insurance.d.ts +1 -2
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/insurance.js +4 -5
- package/lib/node/math/liquidation.d.ts +0 -1
- package/lib/node/math/liquidation.d.ts.map +1 -1
- package/lib/node/math/margin.d.ts +1 -10
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +3 -62
- package/lib/node/math/market.d.ts +4 -13
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +6 -40
- package/lib/node/math/oracles.d.ts +0 -4
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +1 -14
- package/lib/node/math/orders.d.ts +0 -6
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +2 -74
- package/lib/node/math/position.d.ts +1 -6
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +5 -10
- package/lib/node/math/repeg.d.ts +0 -2
- package/lib/node/math/repeg.d.ts.map +1 -1
- package/lib/node/math/repeg.js +1 -23
- package/lib/node/math/spotBalance.d.ts +4 -5
- package/lib/node/math/spotBalance.d.ts.map +1 -1
- package/lib/node/math/spotBalance.js +6 -6
- package/lib/node/math/spotMarket.d.ts +0 -7
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotMarket.js +1 -16
- package/lib/node/math/spotPosition.d.ts +4 -5
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/state.d.ts +0 -3
- package/lib/node/math/state.d.ts.map +1 -1
- package/lib/node/math/state.js +1 -9
- package/lib/node/math/superStake.d.ts +3 -54
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +16 -13
- package/lib/node/math/trade.d.ts +2 -3
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +6 -6
- package/lib/node/math/utils.d.ts +0 -1
- package/lib/node/math/utils.d.ts.map +1 -1
- package/lib/node/memcmp.d.ts +0 -1
- package/lib/node/memcmp.d.ts.map +1 -1
- package/lib/node/memcmp.js +1 -10
- package/lib/node/oracles/oracleClientCache.d.ts +1 -1
- package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
- package/lib/node/oracles/prelaunchOracleClient.js +3 -2
- package/lib/node/oracles/pythClient.d.ts +0 -1
- package/lib/node/oracles/pythClient.d.ts.map +1 -1
- package/lib/node/oracles/pythClient.js +9 -3
- package/lib/node/oracles/pythLazerClient.d.ts +0 -1
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +3 -2
- package/lib/node/oracles/strictOraclePrice.d.ts +0 -1
- package/lib/node/oracles/strictOraclePrice.d.ts.map +1 -1
- package/lib/node/oracles/types.d.ts +0 -1
- package/lib/node/oracles/types.d.ts.map +1 -1
- package/lib/node/oracles/utils.d.ts +4 -1
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/oracles/utils.js +9 -1
- package/lib/node/orderParams.d.ts +0 -1
- package/lib/node/orderParams.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +8 -2
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +32 -8
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/pyth/types.d.ts +0 -1
- package/lib/node/pyth/types.d.ts.map +1 -1
- package/lib/node/slot/SlotSubscriber.d.ts +1 -1
- package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlotSubscriber.js +2 -1
- package/lib/node/slot/SlothashSubscriber.d.ts +3 -2
- package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlothashSubscriber.js +11 -4
- package/lib/node/swap/UnifiedSwapClient.d.ts +0 -1
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +13 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts +1 -1
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +10 -5
- package/lib/node/testClient.js +3 -2
- package/lib/node/titan/titanClient.d.ts +0 -1
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/tokenFaucet.d.ts +0 -1
- package/lib/node/tokenFaucet.d.ts.map +1 -1
- package/lib/node/tokenFaucet.js +16 -2
- package/lib/node/tx/baseTxSender.d.ts +4 -4
- package/lib/node/tx/baseTxSender.d.ts.map +1 -1
- package/lib/node/tx/baseTxSender.js +5 -4
- package/lib/node/tx/fastSingleTxSender.d.ts +3 -3
- package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
- package/lib/node/tx/fastSingleTxSender.js +9 -5
- package/lib/node/tx/reportTransactionError.d.ts +2 -2
- package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
- package/lib/node/tx/reportTransactionError.js +5 -1
- package/lib/node/tx/retryTxSender.d.ts +1 -1
- package/lib/node/tx/retryTxSender.d.ts.map +1 -1
- package/lib/node/tx/retryTxSender.js +4 -2
- package/lib/node/tx/txHandler.d.ts +9 -3
- package/lib/node/tx/txHandler.d.ts.map +1 -1
- package/lib/node/tx/txHandler.js +54 -40
- package/lib/node/tx/txParamProcessor.d.ts +4 -1
- package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
- package/lib/node/tx/txParamProcessor.js +6 -0
- package/lib/node/tx/types.d.ts +1 -1
- package/lib/node/tx/types.d.ts.map +1 -1
- package/lib/node/tx/whileValidTxSender.d.ts +1 -6
- package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
- package/lib/node/tx/whileValidTxSender.js +35 -13
- package/lib/node/types.d.ts +25 -69
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +2 -2
- package/lib/node/user.d.ts +21 -8
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +156 -132
- package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/userMap/grpcSubscription.d.ts +1 -1
- package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +10 -3
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +4 -0
- package/lib/node/userMap/userMap.d.ts +1 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +36 -23
- package/lib/node/userMap/userStatsMap.d.ts +1 -1
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +18 -13
- package/lib/node/userStats.d.ts +7 -2
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +18 -4
- package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
- package/lib/node/util/TransactionConfirmationManager.js +4 -2
- package/lib/node/util/chainClock.d.ts +1 -1
- package/lib/node/util/chainClock.d.ts.map +1 -1
- package/lib/node/util/computeUnits.d.ts +1 -1
- package/lib/node/util/computeUnits.d.ts.map +1 -1
- package/lib/node/util/computeUnits.js +6 -1
- package/lib/node/velocityClient.d.ts +93 -36
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +414 -280
- package/package.json +15 -8
- package/src/accounts/basicUserAccountSubscriber.ts +7 -5
- package/src/accounts/basicUserStatsAccountSubscriber.ts +9 -5
- package/src/accounts/bulkAccountLoader.ts +20 -7
- package/src/accounts/grpcAccountSubscriber.ts +11 -3
- package/src/accounts/grpcMultiAccountSubscriber.ts +24 -9
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +16 -12
- package/src/accounts/grpcProgramAccountSubscriber.ts +11 -3
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -7
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +66 -39
- package/src/accounts/laserProgramAccountSubscriber.ts +3 -0
- package/src/accounts/oneShotUserAccountSubscriber.ts +5 -3
- package/src/accounts/oneShotUserStatsAccountSubscriber.ts +8 -3
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -5
- package/src/accounts/pollingOracleAccountSubscriber.ts +17 -10
- package/src/accounts/pollingTokenAccountSubscriber.ts +17 -10
- package/src/accounts/pollingUserAccountSubscriber.ts +26 -20
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +12 -10
- package/src/accounts/pollingVelocityClientAccountSubscriber.ts +76 -30
- package/src/accounts/types.ts +6 -4
- package/src/accounts/utils.ts +10 -0
- package/src/accounts/webSocketAccountSubscriber.ts +23 -10
- package/src/accounts/webSocketAccountSubscriberV2.ts +23 -8
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +17 -2
- package/src/accounts/webSocketProgramAccountSubscriber.ts +29 -4
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +30 -4
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +29 -4
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -2
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +15 -2
- package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +76 -48
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +74 -35
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
- package/src/addresses/marketAddresses.ts +3 -2
- package/src/addresses/pda.ts +0 -25
- package/src/adminClient.ts +273 -303
- package/src/auctionSubscriber/auctionSubscriber.ts +7 -5
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -5
- package/src/bankrun/bankrunConnection.ts +110 -40
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
- package/src/clock/clockSubscriber.ts +10 -9
- package/src/config.ts +8 -3
- package/src/constants/index.ts +1 -2
- package/src/constants/numericConstants.ts +8 -4
- package/src/constituentMap/constituentMap.ts +8 -1
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
- package/src/core/instructions/perpOrders.ts +14 -0
- package/src/core/remainingAccounts.ts +4 -4
- package/src/decode/user.ts +8 -1
- package/src/dlob/DLOB.ts +296 -172
- package/src/dlob/DLOBNode.ts +23 -3
- package/src/dlob/DLOBSubscriber.ts +51 -34
- package/src/dlob/NodeList.ts +8 -7
- package/src/dlob/orderBookLevels.ts +45 -25
- package/src/events/eventList.ts +4 -1
- package/src/events/eventSubscriber.ts +107 -49
- package/src/events/eventsServerLogProvider.ts +22 -13
- package/src/events/fetchLogs.ts +3 -3
- package/src/events/pollingLogProvider.ts +2 -2
- package/src/events/txEventCache.ts +8 -2
- package/src/events/types.ts +0 -8
- package/src/events/webSocketLogProvider.ts +5 -3
- package/src/factory/bigNum.ts +2 -2
- package/src/idl/velocity.json +1234 -1577
- package/src/idl/velocity.ts +1234 -1577
- package/src/index.ts +0 -2
- package/src/jupiter/jupiterClient.ts +30 -10
- package/src/marginCalculation.ts +1 -0
- package/src/marinade/index.ts +11 -2
- package/src/math/amm.ts +188 -33
- package/src/math/bankruptcy.ts +1 -1
- package/src/math/funding.ts +7 -6
- package/src/math/insurance.ts +6 -8
- package/src/math/margin.ts +5 -112
- package/src/math/market.ts +6 -96
- package/src/math/oracles.ts +0 -17
- package/src/math/orders.ts +1 -110
- package/src/math/position.ts +4 -16
- package/src/math/repeg.ts +0 -29
- package/src/math/spotBalance.ts +14 -10
- package/src/math/spotMarket.ts +2 -28
- package/src/math/spotPosition.ts +4 -4
- package/src/math/state.ts +0 -8
- package/src/math/superStake.ts +19 -65
- package/src/math/trade.ts +2 -6
- package/src/memcmp.ts +0 -9
- package/src/oracles/prelaunchOracleClient.ts +7 -2
- package/src/oracles/pythClient.ts +12 -3
- package/src/oracles/pythLazerClient.ts +7 -2
- package/src/oracles/utils.ts +15 -0
- package/src/orderSubscriber/OrderSubscriber.ts +10 -4
- package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +45 -9
- package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
- package/src/pyth/types.ts +0 -2
- package/src/slot/SlotSubscriber.ts +3 -3
- package/src/slot/SlothashSubscriber.ts +17 -6
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
- package/src/swift/signedMsgUserAccountSubscriber.ts +16 -8
- package/src/swift/swiftOrderSubscriber.ts +10 -9
- package/src/testClient.ts +2 -2
- package/src/tokenFaucet.ts +22 -3
- package/src/tx/baseTxSender.ts +10 -10
- package/src/tx/fastSingleTxSender.ts +12 -8
- package/src/tx/reportTransactionError.ts +12 -7
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/txHandler.ts +88 -43
- package/src/tx/txParamProcessor.ts +18 -3
- package/src/tx/types.ts +1 -1
- package/src/tx/whileValidTxSender.ts +51 -22
- package/src/types.ts +39 -75
- package/src/user.ts +200 -152
- package/src/userMap/WebsocketSubscription.ts +1 -1
- package/src/userMap/grpcSubscription.ts +1 -1
- package/src/userMap/referrerMap.ts +14 -10
- package/src/userMap/revenueShareEscrowMap.ts +8 -3
- package/src/userMap/userMap.ts +43 -25
- package/src/userMap/userStatsMap.ts +32 -19
- package/src/userStats.ts +21 -8
- package/src/util/TransactionConfirmationManager.ts +10 -2
- package/src/util/chainClock.ts +1 -1
- package/src/util/computeUnits.ts +7 -3
- package/src/velocityClient.ts +536 -383
- package/tests/VelocityCore/remainingAccounts.test.ts +4 -5
- package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +19 -11
- package/tests/amm/test.ts +300 -95
- package/tests/decode/userAccountBufferStrings.ts +100 -100
- package/tests/dlob/helpers.ts +162 -173
- package/tests/dlob/test.ts +155 -106
- package/tests/tx/TransactionConfirmationManager.test.ts +9 -2
- package/tests/user/getMarginCalculation.ts +1 -1
- package/tests/user/helpers.ts +3 -4
- package/tests/user/marginCalculations.test.ts +2 -2
- package/tests/user/test.ts +3 -3
- package/tsconfig.browser.json +3 -1
- package/tsconfig.json +21 -2
- package/.yarn/install-state.gz +0 -0
- package/VERSION +0 -1
- package/bun.lock +0 -1885
- package/lib/browser/constants/insuranceFund.d.ts +0 -5
- package/lib/browser/constants/insuranceFund.js +0 -9
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +0 -37
- package/lib/browser/tx/forwardOnlyTxSender.js +0 -92
- package/lib/browser/util/tps.d.ts +0 -2
- package/lib/browser/util/tps.js +0 -16
- package/lib/node/constants/insuranceFund.d.ts +0 -6
- package/lib/node/constants/insuranceFund.d.ts.map +0 -1
- package/lib/node/constants/insuranceFund.js +0 -9
- package/lib/node/tx/forwardOnlyTxSender.d.ts +0 -38
- package/lib/node/tx/forwardOnlyTxSender.d.ts.map +0 -1
- package/lib/node/tx/forwardOnlyTxSender.js +0 -92
- package/lib/node/util/tps.d.ts +0 -3
- package/lib/node/util/tps.d.ts.map +0 -1
- package/lib/node/util/tps.js +0 -16
- package/scripts/updateVersion.js +0 -28
- package/src/constants/insuranceFund.ts +0 -8
- package/src/tx/forwardOnlyTxSender.ts +0 -145
- package/src/util/tps.ts +0 -27
- package/tests/decode/phoenix.ts +0 -71
package/src/dlob/DLOB.ts
CHANGED
|
@@ -116,6 +116,20 @@ const SUPPORTED_ORDER_TYPES = [
|
|
|
116
116
|
'oracle',
|
|
117
117
|
];
|
|
118
118
|
|
|
119
|
+
function getOrderOrThrow(node: DLOBNode): Order {
|
|
120
|
+
if (!node.order) {
|
|
121
|
+
throw new Error('DLOBNode must have an order');
|
|
122
|
+
}
|
|
123
|
+
return node.order;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getUserAccountOrThrow(node: DLOBNode): string {
|
|
127
|
+
if (node.userAccount === undefined) {
|
|
128
|
+
throw new Error('DLOBNode must have a userAccount');
|
|
129
|
+
}
|
|
130
|
+
return node.userAccount;
|
|
131
|
+
}
|
|
132
|
+
|
|
119
133
|
export class DLOB {
|
|
120
134
|
openOrders = new Map<MarketTypeStr, Set<string>>();
|
|
121
135
|
orderLists = new Map<MarketTypeStr, Map<number, MarketNodeLists>>();
|
|
@@ -134,20 +148,64 @@ export class DLOB {
|
|
|
134
148
|
this.orderLists.set('spot', new Map<number, MarketNodeLists>());
|
|
135
149
|
}
|
|
136
150
|
|
|
151
|
+
private getOpenOrdersForMarketType(
|
|
152
|
+
marketTypeStr: MarketTypeStr
|
|
153
|
+
): Set<string> {
|
|
154
|
+
const openOrders = this.openOrders.get(marketTypeStr);
|
|
155
|
+
if (!openOrders) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`DLOB has no open orders set for market type ${marketTypeStr}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return openOrders;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private getOrderListsForMarketType(
|
|
164
|
+
marketTypeStr: MarketTypeStr
|
|
165
|
+
): Map<number, MarketNodeLists> {
|
|
166
|
+
const orderLists = this.orderLists.get(marketTypeStr);
|
|
167
|
+
if (!orderLists) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`DLOB has no order lists for market type ${marketTypeStr}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return orderLists;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private tryGetMarketNodeLists(
|
|
176
|
+
marketTypeStr: MarketTypeStr,
|
|
177
|
+
marketIndex: number
|
|
178
|
+
): MarketNodeLists | undefined {
|
|
179
|
+
return this.orderLists.get(marketTypeStr)?.get(marketIndex);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private getMarketNodeLists(
|
|
183
|
+
marketTypeStr: MarketTypeStr,
|
|
184
|
+
marketIndex: number
|
|
185
|
+
): MarketNodeLists {
|
|
186
|
+
const marketNodeLists = this.tryGetMarketNodeLists(
|
|
187
|
+
marketTypeStr,
|
|
188
|
+
marketIndex
|
|
189
|
+
);
|
|
190
|
+
if (!marketNodeLists) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`DLOB has no order lists for market type ${marketTypeStr} and market index ${marketIndex}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return marketNodeLists;
|
|
196
|
+
}
|
|
197
|
+
|
|
137
198
|
public clear() {
|
|
138
|
-
for (const
|
|
139
|
-
|
|
199
|
+
for (const openOrders of this.openOrders.values()) {
|
|
200
|
+
openOrders.clear();
|
|
140
201
|
}
|
|
141
202
|
this.openOrders.clear();
|
|
142
203
|
|
|
143
|
-
for (const
|
|
144
|
-
for (const
|
|
145
|
-
const
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
for (const side of Object.keys(marketNodeLists)) {
|
|
149
|
-
for (const orderType of Object.keys(marketNodeLists[side])) {
|
|
150
|
-
marketNodeLists[side][orderType].clear();
|
|
204
|
+
for (const marketNodeListsMap of this.orderLists.values()) {
|
|
205
|
+
for (const marketNodeLists of marketNodeListsMap.values()) {
|
|
206
|
+
for (const side of Object.values(marketNodeLists)) {
|
|
207
|
+
for (const nodeList of Object.values(side)) {
|
|
208
|
+
nodeList.clear();
|
|
151
209
|
}
|
|
152
210
|
}
|
|
153
211
|
}
|
|
@@ -174,7 +232,7 @@ export class DLOB {
|
|
|
174
232
|
|
|
175
233
|
// initialize the dlob with the user map
|
|
176
234
|
for (const user of userMap.values()) {
|
|
177
|
-
const userAccount = user.
|
|
235
|
+
const userAccount = user.getUserAccountOrThrow();
|
|
178
236
|
const userAccountPubkey = user.getUserAccountPublicKey();
|
|
179
237
|
const userAccountPubkeyString = userAccountPubkey.toString();
|
|
180
238
|
|
|
@@ -217,14 +275,14 @@ export class DLOB {
|
|
|
217
275
|
|
|
218
276
|
const marketType = getVariant(order.marketType) as MarketTypeStr;
|
|
219
277
|
|
|
220
|
-
if (!this.
|
|
278
|
+
if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
|
|
221
279
|
this.addOrderList(marketType, order.marketIndex);
|
|
222
280
|
}
|
|
223
281
|
|
|
224
282
|
if (isVariant(order.status, 'open')) {
|
|
225
|
-
this.
|
|
226
|
-
.
|
|
227
|
-
|
|
283
|
+
this.getOpenOrdersForMarketType(marketType).add(
|
|
284
|
+
getOrderSignature(order.orderId, userAccount)
|
|
285
|
+
);
|
|
228
286
|
}
|
|
229
287
|
|
|
230
288
|
this.getListForOnChainOrder(order, slot)?.insert(
|
|
@@ -248,28 +306,25 @@ export class DLOB {
|
|
|
248
306
|
const marketType = getVariant(order.marketType) as MarketTypeStr;
|
|
249
307
|
const marketIndex = order.marketIndex;
|
|
250
308
|
const bidOrAsk = isVariant(order.direction, 'long') ? 'bid' : 'ask';
|
|
251
|
-
if (!this.
|
|
309
|
+
if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
|
|
252
310
|
this.addOrderList(marketType, order.marketIndex);
|
|
253
311
|
}
|
|
254
|
-
this.
|
|
255
|
-
.
|
|
256
|
-
|
|
257
|
-
this.
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
userAccount,
|
|
264
|
-
baseAssetAmount
|
|
265
|
-
);
|
|
312
|
+
this.getOpenOrdersForMarketType(marketType).add(
|
|
313
|
+
getOrderSignature(order.orderId, userAccount)
|
|
314
|
+
);
|
|
315
|
+
this.getMarketNodeLists(marketType, marketIndex).signedMsg[bidOrAsk].insert(
|
|
316
|
+
order,
|
|
317
|
+
marketType,
|
|
318
|
+
userAccount,
|
|
319
|
+
baseAssetAmount
|
|
320
|
+
);
|
|
266
321
|
if (onInsert) {
|
|
267
322
|
onInsert();
|
|
268
323
|
}
|
|
269
324
|
}
|
|
270
325
|
|
|
271
326
|
addOrderList(marketType: MarketTypeStr, marketIndex: number): void {
|
|
272
|
-
this.
|
|
327
|
+
this.getOrderListsForMarketType(marketType).set(marketIndex, {
|
|
273
328
|
restingLimit: {
|
|
274
329
|
ask: new NodeList('restingLimit', 'asc'),
|
|
275
330
|
bid: new NodeList('restingLimit', 'desc'),
|
|
@@ -326,36 +381,49 @@ export class DLOB {
|
|
|
326
381
|
const isInactiveTriggerOrder =
|
|
327
382
|
mustBeTriggered(order) && !isTriggered(order);
|
|
328
383
|
|
|
329
|
-
|
|
384
|
+
const marketType = getVariant(order.marketType) as MarketTypeStr;
|
|
385
|
+
|
|
386
|
+
const marketNodeLists = this.tryGetMarketNodeLists(
|
|
387
|
+
marketType,
|
|
388
|
+
order.marketIndex
|
|
389
|
+
);
|
|
390
|
+
if (!marketNodeLists) {
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
330
394
|
if (isInactiveTriggerOrder) {
|
|
331
|
-
|
|
332
|
-
|
|
395
|
+
const subType = isVariant(order.triggerCondition, 'above')
|
|
396
|
+
? 'above'
|
|
397
|
+
: 'below';
|
|
398
|
+
return marketNodeLists.trigger[subType];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const subType = isVariant(order.direction, 'long') ? 'bid' : 'ask';
|
|
402
|
+
if (
|
|
333
403
|
isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])
|
|
334
404
|
) {
|
|
335
|
-
|
|
405
|
+
return marketNodeLists.market[subType];
|
|
336
406
|
} else if (!order.oraclePriceOffset.eq(ZERO)) {
|
|
337
|
-
|
|
407
|
+
return marketNodeLists.floatingLimit[subType];
|
|
338
408
|
} else {
|
|
339
409
|
const isResting = isRestingLimitOrder(order, slot);
|
|
340
|
-
|
|
410
|
+
return isResting
|
|
411
|
+
? marketNodeLists.restingLimit[subType]
|
|
412
|
+
: marketNodeLists.takingLimit[subType];
|
|
341
413
|
}
|
|
414
|
+
}
|
|
342
415
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (!this.orderLists.has(marketType)) {
|
|
353
|
-
return undefined;
|
|
416
|
+
private getListForOnChainOrderOrThrow(
|
|
417
|
+
order: Order,
|
|
418
|
+
slot: number
|
|
419
|
+
): NodeList<any> {
|
|
420
|
+
const list = this.getListForOnChainOrder(order, slot);
|
|
421
|
+
if (!list) {
|
|
422
|
+
throw new Error(
|
|
423
|
+
`No order list found for order ${order.orderId} in market ${order.marketIndex}`
|
|
424
|
+
);
|
|
354
425
|
}
|
|
355
|
-
|
|
356
|
-
return this.orderLists.get(marketType).get(order.marketIndex)[type][
|
|
357
|
-
subType
|
|
358
|
-
];
|
|
426
|
+
return list;
|
|
359
427
|
}
|
|
360
428
|
|
|
361
429
|
public updateRestingLimitOrders(slot: number): void {
|
|
@@ -374,10 +442,12 @@ export class DLOB {
|
|
|
374
442
|
slot: number,
|
|
375
443
|
marketTypeStr: MarketTypeStr
|
|
376
444
|
): void {
|
|
377
|
-
for (const [_, nodeLists] of this.
|
|
378
|
-
|
|
445
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType(
|
|
446
|
+
marketTypeStr
|
|
447
|
+
)) {
|
|
448
|
+
const nodesToUpdate: Array<{ side: 'ask' | 'bid'; node: DLOBNode }> = [];
|
|
379
449
|
for (const node of nodeLists.takingLimit.ask.getGenerator()) {
|
|
380
|
-
if (!isRestingLimitOrder(node
|
|
450
|
+
if (!isRestingLimitOrder(getOrderOrThrow(node), slot)) {
|
|
381
451
|
continue;
|
|
382
452
|
}
|
|
383
453
|
|
|
@@ -388,7 +458,7 @@ export class DLOB {
|
|
|
388
458
|
}
|
|
389
459
|
|
|
390
460
|
for (const node of nodeLists.takingLimit.bid.getGenerator()) {
|
|
391
|
-
if (!isRestingLimitOrder(node
|
|
461
|
+
if (!isRestingLimitOrder(getOrderOrThrow(node), slot)) {
|
|
392
462
|
continue;
|
|
393
463
|
}
|
|
394
464
|
|
|
@@ -400,12 +470,10 @@ export class DLOB {
|
|
|
400
470
|
|
|
401
471
|
for (const nodeToUpdate of nodesToUpdate) {
|
|
402
472
|
const { side, node } = nodeToUpdate;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
node.userAccount
|
|
408
|
-
);
|
|
473
|
+
const order = getOrderOrThrow(node);
|
|
474
|
+
const userAccount = getUserAccountOrThrow(node);
|
|
475
|
+
nodeLists.takingLimit[side].remove(order, userAccount);
|
|
476
|
+
nodeLists.restingLimit[side].insert(order, marketTypeStr, userAccount);
|
|
409
477
|
}
|
|
410
478
|
}
|
|
411
479
|
}
|
|
@@ -538,21 +606,21 @@ export class DLOB {
|
|
|
538
606
|
const mergeNodesToFillHelper = (nodesToFillArray: NodeToFill[]) => {
|
|
539
607
|
nodesToFillArray.forEach((nodeToFill) => {
|
|
540
608
|
const nodeSignature = getOrderSignature(
|
|
541
|
-
nodeToFill.node.
|
|
542
|
-
nodeToFill.node
|
|
609
|
+
getOrderOrThrow(nodeToFill.node).orderId,
|
|
610
|
+
getUserAccountOrThrow(nodeToFill.node)
|
|
543
611
|
);
|
|
544
612
|
|
|
545
|
-
|
|
546
|
-
|
|
613
|
+
let mergedNodeToFill = mergedNodesToFill.get(nodeSignature);
|
|
614
|
+
if (!mergedNodeToFill) {
|
|
615
|
+
mergedNodeToFill = {
|
|
547
616
|
node: nodeToFill.node,
|
|
548
617
|
makerNodes: [],
|
|
549
|
-
}
|
|
618
|
+
};
|
|
619
|
+
mergedNodesToFill.set(nodeSignature, mergedNodeToFill);
|
|
550
620
|
}
|
|
551
621
|
|
|
552
622
|
if (nodeToFill.makerNodes) {
|
|
553
|
-
|
|
554
|
-
.get(nodeSignature)
|
|
555
|
-
.makerNodes.push(...nodeToFill.makerNodes);
|
|
623
|
+
mergedNodeToFill.makerNodes.push(...nodeToFill.makerNodes);
|
|
556
624
|
}
|
|
557
625
|
});
|
|
558
626
|
};
|
|
@@ -611,6 +679,9 @@ export class DLOB {
|
|
|
611
679
|
oraclePriceData,
|
|
612
680
|
askGenerator,
|
|
613
681
|
(askPrice) => {
|
|
682
|
+
if (askPrice === undefined) {
|
|
683
|
+
throw new Error('Resting limit ask must have a limit price');
|
|
684
|
+
}
|
|
614
685
|
return askPrice.lte(fallbackBidWithBuffer);
|
|
615
686
|
},
|
|
616
687
|
stateAccount,
|
|
@@ -640,6 +711,9 @@ export class DLOB {
|
|
|
640
711
|
oraclePriceData,
|
|
641
712
|
bidGenerator,
|
|
642
713
|
(bidPrice) => {
|
|
714
|
+
if (bidPrice === undefined) {
|
|
715
|
+
throw new Error('Resting limit bid must have a limit price');
|
|
716
|
+
}
|
|
643
717
|
return bidPrice.gte(fallbackAskWithBuffer);
|
|
644
718
|
},
|
|
645
719
|
stateAccount,
|
|
@@ -798,7 +872,7 @@ export class DLOB {
|
|
|
798
872
|
makerNodeGeneratorFn: (
|
|
799
873
|
marketIndex: number,
|
|
800
874
|
slot: number,
|
|
801
|
-
marketType:
|
|
875
|
+
marketType: T,
|
|
802
876
|
oraclePriceData: T extends { spot: unknown }
|
|
803
877
|
? OraclePriceData
|
|
804
878
|
: MMOraclePriceData
|
|
@@ -822,7 +896,7 @@ export class DLOB {
|
|
|
822
896
|
continue;
|
|
823
897
|
}
|
|
824
898
|
|
|
825
|
-
const makerPrice = makerNode.
|
|
899
|
+
const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot);
|
|
826
900
|
const takerPrice = takerNode.getPrice(oraclePriceData, slot);
|
|
827
901
|
|
|
828
902
|
const ordersCross = doesCross(takerPrice, makerPrice);
|
|
@@ -837,8 +911,8 @@ export class DLOB {
|
|
|
837
911
|
makerNodes: [makerNode],
|
|
838
912
|
});
|
|
839
913
|
|
|
840
|
-
const makerOrder = makerNode
|
|
841
|
-
const takerOrder = takerNode
|
|
914
|
+
const makerOrder = getOrderOrThrow(makerNode);
|
|
915
|
+
const takerOrder = getOrderOrThrow(takerNode);
|
|
842
916
|
|
|
843
917
|
const makerBaseRemaining = makerOrder.baseAssetAmount.sub(
|
|
844
918
|
makerOrder.baseAssetAmountFilled
|
|
@@ -852,9 +926,9 @@ export class DLOB {
|
|
|
852
926
|
const newMakerOrder = { ...makerOrder };
|
|
853
927
|
newMakerOrder.baseAssetAmountFilled =
|
|
854
928
|
makerOrder.baseAssetAmountFilled.add(baseFilled);
|
|
855
|
-
this.
|
|
929
|
+
this.getListForOnChainOrderOrThrow(newMakerOrder, slot).update(
|
|
856
930
|
newMakerOrder,
|
|
857
|
-
makerNode
|
|
931
|
+
getUserAccountOrThrow(makerNode)
|
|
858
932
|
);
|
|
859
933
|
|
|
860
934
|
const newTakerOrder = { ...takerOrder };
|
|
@@ -863,14 +937,18 @@ export class DLOB {
|
|
|
863
937
|
|
|
864
938
|
if (takerNode.isSignedMsg) {
|
|
865
939
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
940
|
+
const marketNodeLists = this.getMarketNodeLists(
|
|
941
|
+
marketTypeStr,
|
|
942
|
+
marketIndex
|
|
943
|
+
);
|
|
866
944
|
const orderList = isVariant(takerOrder.direction, 'long')
|
|
867
|
-
?
|
|
868
|
-
:
|
|
869
|
-
orderList.update(newTakerOrder, takerNode
|
|
945
|
+
? marketNodeLists.signedMsg.bid
|
|
946
|
+
: marketNodeLists.signedMsg.ask;
|
|
947
|
+
orderList.update(newTakerOrder, getUserAccountOrThrow(takerNode));
|
|
870
948
|
} else {
|
|
871
|
-
this.
|
|
949
|
+
this.getListForOnChainOrderOrThrow(newTakerOrder, slot).update(
|
|
872
950
|
newTakerOrder,
|
|
873
|
-
takerNode
|
|
951
|
+
getUserAccountOrThrow(takerNode)
|
|
874
952
|
);
|
|
875
953
|
}
|
|
876
954
|
|
|
@@ -908,8 +986,8 @@ export class DLOB {
|
|
|
908
986
|
nextNode = nodeGenerator.next();
|
|
909
987
|
continue;
|
|
910
988
|
}
|
|
911
|
-
|
|
912
|
-
const nodePrice = getLimitPrice(
|
|
989
|
+
const nodeOrder = getOrderOrThrow(node);
|
|
990
|
+
const nodePrice = getLimitPrice(nodeOrder, oraclePriceData, slot);
|
|
913
991
|
|
|
914
992
|
// order crosses if there is no limit price or it crosses fallback price
|
|
915
993
|
const crosses = doesCross(nodePrice);
|
|
@@ -918,7 +996,7 @@ export class DLOB {
|
|
|
918
996
|
const fallbackAvailable =
|
|
919
997
|
isVariant(marketType, 'spot') ||
|
|
920
998
|
isFallbackAvailableLiquiditySource(
|
|
921
|
-
|
|
999
|
+
nodeOrder,
|
|
922
1000
|
oraclePriceData as MMOraclePriceData,
|
|
923
1001
|
slot,
|
|
924
1002
|
state,
|
|
@@ -947,7 +1025,7 @@ export class DLOB {
|
|
|
947
1025
|
const nodesToFill = new Array<NodeToFill>();
|
|
948
1026
|
|
|
949
1027
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
950
|
-
const nodeLists = this.
|
|
1028
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
951
1029
|
|
|
952
1030
|
if (!nodeLists) {
|
|
953
1031
|
return nodesToFill;
|
|
@@ -972,15 +1050,22 @@ export class DLOB {
|
|
|
972
1050
|
|
|
973
1051
|
for (const bidGenerator of bidGenerators) {
|
|
974
1052
|
for (const bid of bidGenerator) {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1053
|
+
const bidOrder = getOrderOrThrow(bid);
|
|
1054
|
+
if (bid.isSignedMsg) {
|
|
1055
|
+
if (slot === undefined) {
|
|
1056
|
+
throw new Error(
|
|
1057
|
+
'Must provide slot to findExpiredNodesToFill to expire signedMsg orders'
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
if (slot.gt(bidOrder.slot.addn(bidOrder.auctionDuration))) {
|
|
1061
|
+
nodeLists.signedMsg.bid.remove(
|
|
1062
|
+
bidOrder,
|
|
1063
|
+
getUserAccountOrThrow(bid)
|
|
1064
|
+
);
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (isOrderExpired(bidOrder, ts, true, 25)) {
|
|
984
1069
|
nodesToFill.push({
|
|
985
1070
|
node: bid,
|
|
986
1071
|
makerNodes: [],
|
|
@@ -991,15 +1076,22 @@ export class DLOB {
|
|
|
991
1076
|
|
|
992
1077
|
for (const askGenerator of askGenerators) {
|
|
993
1078
|
for (const ask of askGenerator) {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1079
|
+
const askOrder = getOrderOrThrow(ask);
|
|
1080
|
+
if (ask.isSignedMsg) {
|
|
1081
|
+
if (slot === undefined) {
|
|
1082
|
+
throw new Error(
|
|
1083
|
+
'Must provide slot to findExpiredNodesToFill to expire signedMsg orders'
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
if (slot.gt(askOrder.slot.addn(askOrder.auctionDuration))) {
|
|
1087
|
+
nodeLists.signedMsg.ask.remove(
|
|
1088
|
+
askOrder,
|
|
1089
|
+
getUserAccountOrThrow(ask)
|
|
1090
|
+
);
|
|
1091
|
+
continue;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (isOrderExpired(askOrder, ts, true, 25)) {
|
|
1003
1095
|
nodesToFill.push({
|
|
1004
1096
|
node: ask,
|
|
1005
1097
|
makerNodes: [],
|
|
@@ -1019,7 +1111,7 @@ export class DLOB {
|
|
|
1019
1111
|
const nodesToFill = new Array<NodeToFill>();
|
|
1020
1112
|
|
|
1021
1113
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1022
|
-
const nodeLists = this.
|
|
1114
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
1023
1115
|
|
|
1024
1116
|
if (!nodeLists) {
|
|
1025
1117
|
return nodesToFill;
|
|
@@ -1042,7 +1134,7 @@ export class DLOB {
|
|
|
1042
1134
|
|
|
1043
1135
|
for (const generator of generators) {
|
|
1044
1136
|
for (const node of generator) {
|
|
1045
|
-
if (!node.
|
|
1137
|
+
if (!getOrderOrThrow(node).reduceOnly) {
|
|
1046
1138
|
continue;
|
|
1047
1139
|
}
|
|
1048
1140
|
|
|
@@ -1067,7 +1159,7 @@ export class DLOB {
|
|
|
1067
1159
|
filterFcn?: DLOBFilterFcn
|
|
1068
1160
|
): Generator<DLOBNode> {
|
|
1069
1161
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1070
|
-
const orderLists = this.
|
|
1162
|
+
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
1071
1163
|
if (!orderLists) {
|
|
1072
1164
|
return;
|
|
1073
1165
|
}
|
|
@@ -1079,7 +1171,7 @@ export class DLOB {
|
|
|
1079
1171
|
orderLists.takingLimit.bid.getGenerator(),
|
|
1080
1172
|
this.signedMsgGenerator(
|
|
1081
1173
|
orderLists.signedMsg.bid,
|
|
1082
|
-
(x: DLOBNode) => !isRestingLimitOrder(x
|
|
1174
|
+
(x: DLOBNode) => !isRestingLimitOrder(getOrderOrThrow(x), slot)
|
|
1083
1175
|
),
|
|
1084
1176
|
];
|
|
1085
1177
|
|
|
@@ -1088,7 +1180,9 @@ export class DLOB {
|
|
|
1088
1180
|
oraclePriceData,
|
|
1089
1181
|
slot,
|
|
1090
1182
|
(bestNode, currentNode) => {
|
|
1091
|
-
return bestNode.
|
|
1183
|
+
return getOrderOrThrow(bestNode).slot.lt(
|
|
1184
|
+
getOrderOrThrow(currentNode).slot
|
|
1185
|
+
);
|
|
1092
1186
|
},
|
|
1093
1187
|
filterFcn
|
|
1094
1188
|
);
|
|
@@ -1104,7 +1198,7 @@ export class DLOB {
|
|
|
1104
1198
|
filterFcn?: DLOBFilterFcn
|
|
1105
1199
|
): Generator<DLOBNode> {
|
|
1106
1200
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1107
|
-
const orderLists = this.
|
|
1201
|
+
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
1108
1202
|
if (!orderLists) {
|
|
1109
1203
|
return;
|
|
1110
1204
|
}
|
|
@@ -1116,7 +1210,7 @@ export class DLOB {
|
|
|
1116
1210
|
orderLists.takingLimit.ask.getGenerator(),
|
|
1117
1211
|
this.signedMsgGenerator(
|
|
1118
1212
|
orderLists.signedMsg.ask,
|
|
1119
|
-
(x: DLOBNode) => !isRestingLimitOrder(x
|
|
1213
|
+
(x: DLOBNode) => !isRestingLimitOrder(getOrderOrThrow(x), slot)
|
|
1120
1214
|
),
|
|
1121
1215
|
];
|
|
1122
1216
|
|
|
@@ -1125,7 +1219,9 @@ export class DLOB {
|
|
|
1125
1219
|
oraclePriceData,
|
|
1126
1220
|
slot,
|
|
1127
1221
|
(bestNode, currentNode) => {
|
|
1128
|
-
return bestNode.
|
|
1222
|
+
return getOrderOrThrow(bestNode).slot.lt(
|
|
1223
|
+
getOrderOrThrow(currentNode).slot
|
|
1224
|
+
);
|
|
1129
1225
|
},
|
|
1130
1226
|
filterFcn
|
|
1131
1227
|
);
|
|
@@ -1218,7 +1314,7 @@ export class DLOB {
|
|
|
1218
1314
|
this.updateRestingLimitOrders(slot);
|
|
1219
1315
|
|
|
1220
1316
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1221
|
-
const nodeLists = this.
|
|
1317
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
1222
1318
|
|
|
1223
1319
|
if (!nodeLists) {
|
|
1224
1320
|
return;
|
|
@@ -1228,7 +1324,7 @@ export class DLOB {
|
|
|
1228
1324
|
nodeLists.restingLimit.ask.getGenerator(),
|
|
1229
1325
|
nodeLists.floatingLimit.ask.getGenerator(),
|
|
1230
1326
|
this.signedMsgGenerator(nodeLists.signedMsg.ask, (x: DLOBNode) =>
|
|
1231
|
-
isRestingLimitOrder(x
|
|
1327
|
+
isRestingLimitOrder(getOrderOrThrow(x), slot)
|
|
1232
1328
|
),
|
|
1233
1329
|
];
|
|
1234
1330
|
|
|
@@ -1238,8 +1334,8 @@ export class DLOB {
|
|
|
1238
1334
|
slot,
|
|
1239
1335
|
(bestNode, currentNode, slot, oraclePriceData) => {
|
|
1240
1336
|
return bestNode
|
|
1241
|
-
.
|
|
1242
|
-
.lt(currentNode.
|
|
1337
|
+
.getPriceOrThrow(oraclePriceData, slot)
|
|
1338
|
+
.lt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
1243
1339
|
},
|
|
1244
1340
|
filterFcn
|
|
1245
1341
|
);
|
|
@@ -1261,7 +1357,7 @@ export class DLOB {
|
|
|
1261
1357
|
this.updateRestingLimitOrders(slot);
|
|
1262
1358
|
|
|
1263
1359
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1264
|
-
const nodeLists = this.
|
|
1360
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
1265
1361
|
|
|
1266
1362
|
if (!nodeLists) {
|
|
1267
1363
|
return;
|
|
@@ -1271,7 +1367,7 @@ export class DLOB {
|
|
|
1271
1367
|
nodeLists.restingLimit.bid.getGenerator(),
|
|
1272
1368
|
nodeLists.floatingLimit.bid.getGenerator(),
|
|
1273
1369
|
this.signedMsgGenerator(nodeLists.signedMsg.bid, (x: DLOBNode) =>
|
|
1274
|
-
isRestingLimitOrder(x
|
|
1370
|
+
isRestingLimitOrder(getOrderOrThrow(x), slot)
|
|
1275
1371
|
),
|
|
1276
1372
|
];
|
|
1277
1373
|
|
|
@@ -1281,8 +1377,8 @@ export class DLOB {
|
|
|
1281
1377
|
slot,
|
|
1282
1378
|
(bestNode, currentNode, slot, oraclePriceData) => {
|
|
1283
1379
|
return bestNode
|
|
1284
|
-
.
|
|
1285
|
-
.gt(currentNode.
|
|
1380
|
+
.getPriceOrThrow(oraclePriceData, slot)
|
|
1381
|
+
.gt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
1286
1382
|
},
|
|
1287
1383
|
filterFcn
|
|
1288
1384
|
);
|
|
@@ -1326,7 +1422,9 @@ export class DLOB {
|
|
|
1326
1422
|
currentNode.getPrice(oraclePriceData, slot) ?? ZERO;
|
|
1327
1423
|
|
|
1328
1424
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
1329
|
-
return bestNode.
|
|
1425
|
+
return getOrderOrThrow(bestNode).slot.lt(
|
|
1426
|
+
getOrderOrThrow(currentNode).slot
|
|
1427
|
+
);
|
|
1330
1428
|
}
|
|
1331
1429
|
|
|
1332
1430
|
return bestNodePrice.lt(currentNodePrice);
|
|
@@ -1374,7 +1472,9 @@ export class DLOB {
|
|
|
1374
1472
|
currentNode.getPrice(oraclePriceData, slot) ?? BN_MAX;
|
|
1375
1473
|
|
|
1376
1474
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
1377
|
-
return bestNode.
|
|
1475
|
+
return getOrderOrThrow(bestNode).slot.lt(
|
|
1476
|
+
getOrderOrThrow(currentNode).slot
|
|
1477
|
+
);
|
|
1378
1478
|
}
|
|
1379
1479
|
|
|
1380
1480
|
return bestNodePrice.gt(currentNodePrice);
|
|
@@ -1407,16 +1507,16 @@ export class DLOB {
|
|
|
1407
1507
|
);
|
|
1408
1508
|
|
|
1409
1509
|
for (const bidNode of bidGenerator) {
|
|
1410
|
-
const bidPrice = bidNode.
|
|
1411
|
-
const askPrice = askNode.
|
|
1510
|
+
const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot);
|
|
1511
|
+
const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot);
|
|
1412
1512
|
|
|
1413
1513
|
// orders don't cross
|
|
1414
1514
|
if (bidPrice.lt(askPrice)) {
|
|
1415
1515
|
break;
|
|
1416
1516
|
}
|
|
1417
1517
|
|
|
1418
|
-
const bidOrder = bidNode
|
|
1419
|
-
const askOrder = askNode
|
|
1518
|
+
const bidOrder = getOrderOrThrow(bidNode);
|
|
1519
|
+
const askOrder = getOrderOrThrow(askNode);
|
|
1420
1520
|
|
|
1421
1521
|
// Can't match orders from the same user
|
|
1422
1522
|
const sameUser = bidNode.userAccount === askNode.userAccount;
|
|
@@ -1445,18 +1545,18 @@ export class DLOB {
|
|
|
1445
1545
|
const newBidOrder = { ...bidOrder };
|
|
1446
1546
|
newBidOrder.baseAssetAmountFilled =
|
|
1447
1547
|
bidOrder.baseAssetAmountFilled.add(baseFilled);
|
|
1448
|
-
this.
|
|
1548
|
+
this.getListForOnChainOrderOrThrow(newBidOrder, slot).update(
|
|
1449
1549
|
newBidOrder,
|
|
1450
|
-
bidNode
|
|
1550
|
+
getUserAccountOrThrow(bidNode)
|
|
1451
1551
|
);
|
|
1452
1552
|
|
|
1453
1553
|
// ask completely filled
|
|
1454
1554
|
const newAskOrder = { ...askOrder };
|
|
1455
1555
|
newAskOrder.baseAssetAmountFilled =
|
|
1456
1556
|
askOrder.baseAssetAmountFilled.add(baseFilled);
|
|
1457
|
-
this.
|
|
1557
|
+
this.getListForOnChainOrderOrThrow(newAskOrder, slot).update(
|
|
1458
1558
|
newAskOrder,
|
|
1459
|
-
askNode
|
|
1559
|
+
getUserAccountOrThrow(askNode)
|
|
1460
1560
|
);
|
|
1461
1561
|
|
|
1462
1562
|
nodesToFill.push({
|
|
@@ -1477,21 +1577,19 @@ export class DLOB {
|
|
|
1477
1577
|
askNode: DLOBNode,
|
|
1478
1578
|
bidNode: DLOBNode
|
|
1479
1579
|
): { takerNode: DLOBNode; makerNode: DLOBNode } | undefined {
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
);
|
|
1483
|
-
const bidSlot =
|
|
1484
|
-
new BN(bidNode.order.auctionDuration)
|
|
1485
|
-
);
|
|
1580
|
+
const askOrder = getOrderOrThrow(askNode);
|
|
1581
|
+
const bidOrder = getOrderOrThrow(bidNode);
|
|
1582
|
+
const askSlot = askOrder.slot.add(new BN(askOrder.auctionDuration));
|
|
1583
|
+
const bidSlot = bidOrder.slot.add(new BN(bidOrder.auctionDuration));
|
|
1486
1584
|
|
|
1487
|
-
if (
|
|
1585
|
+
if (bidOrder.postOnly && askOrder.postOnly) {
|
|
1488
1586
|
return undefined;
|
|
1489
|
-
} else if (
|
|
1587
|
+
} else if (bidOrder.postOnly) {
|
|
1490
1588
|
return {
|
|
1491
1589
|
takerNode: askNode,
|
|
1492
1590
|
makerNode: bidNode,
|
|
1493
1591
|
};
|
|
1494
|
-
} else if (
|
|
1592
|
+
} else if (askOrder.postOnly) {
|
|
1495
1593
|
return {
|
|
1496
1594
|
takerNode: bidNode,
|
|
1497
1595
|
makerNode: askNode,
|
|
@@ -1557,17 +1655,17 @@ export class DLOB {
|
|
|
1557
1655
|
direction: PositionDirection
|
|
1558
1656
|
): Generator<DLOBNode> {
|
|
1559
1657
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1560
|
-
const marketNodeLists = this.
|
|
1658
|
+
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
1561
1659
|
|
|
1562
1660
|
if (isVariant(direction, 'long') && marketNodeLists.trigger.below) {
|
|
1563
1661
|
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
1564
|
-
if (isVariant(node.
|
|
1662
|
+
if (isVariant(getOrderOrThrow(node).direction, 'short')) {
|
|
1565
1663
|
yield node;
|
|
1566
1664
|
}
|
|
1567
1665
|
}
|
|
1568
1666
|
} else if (isVariant(direction, 'short') && marketNodeLists.trigger.above) {
|
|
1569
1667
|
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
1570
|
-
if (isVariant(node.
|
|
1668
|
+
if (isVariant(getOrderOrThrow(node).direction, 'long')) {
|
|
1571
1669
|
yield node;
|
|
1572
1670
|
}
|
|
1573
1671
|
}
|
|
@@ -1580,7 +1678,7 @@ export class DLOB {
|
|
|
1580
1678
|
direction: PositionDirection
|
|
1581
1679
|
): Generator<DLOBNode> {
|
|
1582
1680
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
1583
|
-
if (isVariant(node.
|
|
1681
|
+
if (isVariant(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
1584
1682
|
yield node;
|
|
1585
1683
|
}
|
|
1586
1684
|
}
|
|
@@ -1592,7 +1690,7 @@ export class DLOB {
|
|
|
1592
1690
|
direction: PositionDirection
|
|
1593
1691
|
): Generator<DLOBNode> {
|
|
1594
1692
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
1595
|
-
if (isVariant(node.
|
|
1693
|
+
if (isVariant(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
1596
1694
|
yield node;
|
|
1597
1695
|
}
|
|
1598
1696
|
}
|
|
@@ -1604,17 +1702,17 @@ export class DLOB {
|
|
|
1604
1702
|
direction: PositionDirection
|
|
1605
1703
|
): Generator<DLOBNode> {
|
|
1606
1704
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1607
|
-
const marketNodeLists = this.
|
|
1705
|
+
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
1608
1706
|
|
|
1609
1707
|
if (isVariant(direction, 'long') && marketNodeLists.trigger.above) {
|
|
1610
1708
|
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
1611
|
-
if (isVariant(node.
|
|
1709
|
+
if (isVariant(getOrderOrThrow(node).direction, 'short')) {
|
|
1612
1710
|
yield node;
|
|
1613
1711
|
}
|
|
1614
1712
|
}
|
|
1615
1713
|
} else if (isVariant(direction, 'short') && marketNodeLists.trigger.below) {
|
|
1616
1714
|
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
1617
|
-
if (isVariant(node.
|
|
1715
|
+
if (isVariant(getOrderOrThrow(node).direction, 'long')) {
|
|
1618
1716
|
yield node;
|
|
1619
1717
|
}
|
|
1620
1718
|
}
|
|
@@ -1631,7 +1729,7 @@ export class DLOB {
|
|
|
1631
1729
|
marketType,
|
|
1632
1730
|
direction
|
|
1633
1731
|
)) {
|
|
1634
|
-
if (isVariant(node.
|
|
1732
|
+
if (isVariant(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
1635
1733
|
yield node;
|
|
1636
1734
|
}
|
|
1637
1735
|
}
|
|
@@ -1647,7 +1745,7 @@ export class DLOB {
|
|
|
1647
1745
|
marketType,
|
|
1648
1746
|
direction
|
|
1649
1747
|
)) {
|
|
1650
|
-
if (isVariant(node.
|
|
1748
|
+
if (isVariant(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
1651
1749
|
yield node;
|
|
1652
1750
|
}
|
|
1653
1751
|
}
|
|
@@ -1664,15 +1762,21 @@ export class DLOB {
|
|
|
1664
1762
|
return [];
|
|
1665
1763
|
}
|
|
1666
1764
|
|
|
1667
|
-
const nodesToTrigger = [];
|
|
1765
|
+
const nodesToTrigger: NodeToTrigger[] = [];
|
|
1668
1766
|
const marketTypeStr = getVariant(marketType) as MarketTypeStr;
|
|
1669
|
-
const marketNodeLists = this.orderLists
|
|
1767
|
+
const marketNodeLists = this.orderLists
|
|
1768
|
+
.get(marketTypeStr)
|
|
1769
|
+
?.get(marketIndex);
|
|
1670
1770
|
|
|
1671
1771
|
const triggerAboveList = marketNodeLists
|
|
1672
1772
|
? marketNodeLists.trigger.above
|
|
1673
1773
|
: undefined;
|
|
1674
1774
|
if (triggerAboveList) {
|
|
1675
|
-
for (
|
|
1775
|
+
for (
|
|
1776
|
+
let node = triggerAboveList.head;
|
|
1777
|
+
node !== undefined;
|
|
1778
|
+
node = node.next
|
|
1779
|
+
) {
|
|
1676
1780
|
if (triggerPrice.gt(node.order.triggerPrice)) {
|
|
1677
1781
|
nodesToTrigger.push({
|
|
1678
1782
|
node: node,
|
|
@@ -1687,7 +1791,11 @@ export class DLOB {
|
|
|
1687
1791
|
? marketNodeLists.trigger.below
|
|
1688
1792
|
: undefined;
|
|
1689
1793
|
if (triggerBelowList) {
|
|
1690
|
-
for (
|
|
1794
|
+
for (
|
|
1795
|
+
let node = triggerBelowList.head;
|
|
1796
|
+
node !== undefined;
|
|
1797
|
+
node = node.next
|
|
1798
|
+
) {
|
|
1691
1799
|
if (triggerPrice.lt(node.order.triggerPrice)) {
|
|
1692
1800
|
nodesToTrigger.push({
|
|
1693
1801
|
node: node,
|
|
@@ -1724,6 +1832,11 @@ export class DLOB {
|
|
|
1724
1832
|
marketType,
|
|
1725
1833
|
oraclePriceData
|
|
1726
1834
|
);
|
|
1835
|
+
if (bestAsk === undefined || bestBid === undefined) {
|
|
1836
|
+
throw new Error(
|
|
1837
|
+
`printTop requires both a best ask and best bid for market ${marketIndex}`
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1727
1840
|
const mid = bestAsk.add(bestBid).div(new BN(2));
|
|
1728
1841
|
|
|
1729
1842
|
const bidSpread =
|
|
@@ -1738,7 +1851,7 @@ export class DLOB {
|
|
|
1738
1851
|
100.0;
|
|
1739
1852
|
|
|
1740
1853
|
const name = decodeName(
|
|
1741
|
-
velocityClient.
|
|
1854
|
+
velocityClient.getPerpMarketAccountOrThrow(marketIndex).name
|
|
1742
1855
|
);
|
|
1743
1856
|
console.log(`Market ${name} Orders`);
|
|
1744
1857
|
console.log(
|
|
@@ -1769,6 +1882,11 @@ export class DLOB {
|
|
|
1769
1882
|
MarketType.SPOT,
|
|
1770
1883
|
oraclePriceData
|
|
1771
1884
|
);
|
|
1885
|
+
if (bestAsk === undefined || bestBid === undefined) {
|
|
1886
|
+
throw new Error(
|
|
1887
|
+
`printTop requires both a best ask and best bid for market ${marketIndex}`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1772
1890
|
const mid = bestAsk.add(bestBid).div(new BN(2));
|
|
1773
1891
|
|
|
1774
1892
|
const bidSpread =
|
|
@@ -1783,7 +1901,7 @@ export class DLOB {
|
|
|
1783
1901
|
100.0;
|
|
1784
1902
|
|
|
1785
1903
|
const name = decodeName(
|
|
1786
|
-
velocityClient.
|
|
1904
|
+
velocityClient.getSpotMarketAccountOrThrow(marketIndex).name
|
|
1787
1905
|
);
|
|
1788
1906
|
console.log(`Market ${name} Orders`);
|
|
1789
1907
|
console.log(
|
|
@@ -1806,8 +1924,8 @@ export class DLOB {
|
|
|
1806
1924
|
for (const nodeList of this.getNodeLists()) {
|
|
1807
1925
|
for (const node of nodeList.getGenerator()) {
|
|
1808
1926
|
dlobOrders.push({
|
|
1809
|
-
user: new PublicKey(node
|
|
1810
|
-
order: node
|
|
1927
|
+
user: new PublicKey(getUserAccountOrThrow(node)),
|
|
1928
|
+
order: getOrderOrThrow(node),
|
|
1811
1929
|
});
|
|
1812
1930
|
}
|
|
1813
1931
|
}
|
|
@@ -1816,7 +1934,7 @@ export class DLOB {
|
|
|
1816
1934
|
}
|
|
1817
1935
|
|
|
1818
1936
|
*getNodeLists(): Generator<NodeList<DLOBNodeType>> {
|
|
1819
|
-
for (const [_, nodeLists] of this.
|
|
1937
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType('perp')) {
|
|
1820
1938
|
yield nodeLists.restingLimit.bid;
|
|
1821
1939
|
yield nodeLists.restingLimit.ask;
|
|
1822
1940
|
yield nodeLists.takingLimit.bid;
|
|
@@ -1829,7 +1947,7 @@ export class DLOB {
|
|
|
1829
1947
|
yield nodeLists.trigger.below;
|
|
1830
1948
|
}
|
|
1831
1949
|
|
|
1832
|
-
for (const [_, nodeLists] of this.
|
|
1950
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType('spot')) {
|
|
1833
1951
|
yield nodeLists.restingLimit.bid;
|
|
1834
1952
|
yield nodeLists.restingLimit.ask;
|
|
1835
1953
|
yield nodeLists.takingLimit.bid;
|
|
@@ -1949,11 +2067,12 @@ export class DLOB {
|
|
|
1949
2067
|
);
|
|
1950
2068
|
|
|
1951
2069
|
for (const ask of restingAsks) {
|
|
2070
|
+
const askOrder = getOrderOrThrow(ask);
|
|
1952
2071
|
asks.push({
|
|
1953
|
-
price: ask.
|
|
1954
|
-
size:
|
|
1955
|
-
maker: new PublicKey(ask
|
|
1956
|
-
orderId:
|
|
2072
|
+
price: ask.getPriceOrThrow(oraclePriceData, slot),
|
|
2073
|
+
size: askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled),
|
|
2074
|
+
maker: new PublicKey(getUserAccountOrThrow(ask)),
|
|
2075
|
+
orderId: askOrder.orderId,
|
|
1957
2076
|
});
|
|
1958
2077
|
}
|
|
1959
2078
|
|
|
@@ -1965,11 +2084,12 @@ export class DLOB {
|
|
|
1965
2084
|
);
|
|
1966
2085
|
|
|
1967
2086
|
for (const bid of restingBids) {
|
|
2087
|
+
const bidOrder = getOrderOrThrow(bid);
|
|
1968
2088
|
bids.push({
|
|
1969
|
-
price: bid.
|
|
1970
|
-
size:
|
|
1971
|
-
maker: new PublicKey(bid
|
|
1972
|
-
orderId:
|
|
2089
|
+
price: bid.getPriceOrThrow(oraclePriceData, slot),
|
|
2090
|
+
size: bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled),
|
|
2091
|
+
maker: new PublicKey(getUserAccountOrThrow(bid)),
|
|
2092
|
+
orderId: bidOrder.orderId,
|
|
1973
2093
|
});
|
|
1974
2094
|
}
|
|
1975
2095
|
|
|
@@ -1989,9 +2109,10 @@ export class DLOB {
|
|
|
1989
2109
|
let runningSumQuote = ZERO;
|
|
1990
2110
|
let runningSumBase = ZERO;
|
|
1991
2111
|
for (const side of dlobSide) {
|
|
1992
|
-
const price = side.
|
|
1993
|
-
const
|
|
1994
|
-
|
|
2112
|
+
const price = side.getPriceOrThrow(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
|
|
2113
|
+
const sideOrder = getOrderOrThrow(side);
|
|
2114
|
+
const baseAmountRemaining = sideOrder.baseAssetAmount.sub(
|
|
2115
|
+
sideOrder.baseAssetAmountFilled
|
|
1995
2116
|
);
|
|
1996
2117
|
if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
|
|
1997
2118
|
const remainingBase = baseAmountIn.sub(runningSumBase);
|
|
@@ -2051,6 +2172,11 @@ export class DLOB {
|
|
|
2051
2172
|
this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
2052
2173
|
);
|
|
2053
2174
|
}
|
|
2175
|
+
throw new Error(
|
|
2176
|
+
`Invalid order direction ${getVariant(
|
|
2177
|
+
orderDirection
|
|
2178
|
+
)}: must be long or short`
|
|
2179
|
+
);
|
|
2054
2180
|
}
|
|
2055
2181
|
|
|
2056
2182
|
public getBestMakers<T extends MarketType>({
|
|
@@ -2081,11 +2207,9 @@ export class DLOB {
|
|
|
2081
2207
|
);
|
|
2082
2208
|
|
|
2083
2209
|
for (const node of generator) {
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
new PublicKey(node.userAccount)
|
|
2088
|
-
);
|
|
2210
|
+
const userAccount = getUserAccountOrThrow(node);
|
|
2211
|
+
if (!makers.has(userAccount)) {
|
|
2212
|
+
makers.set(userAccount, new PublicKey(userAccount));
|
|
2089
2213
|
}
|
|
2090
2214
|
|
|
2091
2215
|
if (makers.size === numMakers) {
|