@velocity-exchange/sdk 0.0.5 → 0.2.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/.prettierignore +1 -1
- package/CHANGELOG.md +35 -0
- package/README.md +30 -30
- package/bun.lock +24 -2
- 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 +9 -3
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +4 -1
- 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 -5
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
- package/lib/browser/accounts/types.d.ts +6 -12
- package/lib/browser/accounts/utils.d.ts +1 -0
- package/lib/browser/accounts/utils.js +10 -3
- 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 -8
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
- 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 +1 -9
- package/lib/browser/addresses/pda.js +4 -23
- package/lib/browser/adminClient.d.ts +25 -29
- package/lib/browser/adminClient.js +168 -169
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +2 -4
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +8 -10
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
- package/lib/browser/auctionSubscriber/types.d.ts +3 -2
- package/lib/browser/bankrun/bankrunConnection.d.ts +6 -4
- package/lib/browser/bankrun/bankrunConnection.js +69 -31
- 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 +11 -20
- package/lib/browser/config.js +13 -36
- 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 -3
- package/lib/browser/constants/numericConstants.js +3 -5
- package/lib/browser/constituentMap/constituentMap.d.ts +0 -2
- package/lib/browser/constituentMap/constituentMap.js +10 -6
- 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 +9 -15
- package/lib/browser/core/VelocityCore.js +5 -7
- 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 +1 -1
- package/lib/browser/core/instructions/withdraw.js +1 -1
- package/lib/browser/core/remainingAccounts.d.ts +2 -2
- package/lib/browser/core/remainingAccounts.js +5 -5
- package/lib/browser/decode/user.js +9 -1
- package/lib/browser/dlob/DLOB.d.ts +7 -2
- package/lib/browser/dlob/DLOB.js +205 -142
- package/lib/browser/dlob/DLOBNode.d.ts +5 -2
- package/lib/browser/dlob/DLOBNode.js +7 -0
- package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
- package/lib/browser/dlob/DLOBSubscriber.js +39 -39
- package/lib/browser/dlob/NodeList.js +8 -7
- package/lib/browser/dlob/orderBookLevels.js +24 -17
- package/lib/browser/dlob/types.d.ts +0 -2
- package/lib/browser/events/eventList.js +4 -1
- package/lib/browser/events/eventSubscriber.d.ts +6 -3
- package/lib/browser/events/eventSubscriber.js +75 -26
- package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
- package/lib/browser/events/eventsServerLogProvider.js +17 -10
- package/lib/browser/events/fetchLogs.d.ts +1 -1
- package/lib/browser/events/fetchLogs.js +4 -2
- package/lib/browser/events/parse.js +14 -14
- package/lib/browser/events/pollingLogProvider.d.ts +1 -1
- package/lib/browser/events/pollingLogProvider.js +1 -0
- package/lib/browser/events/txEventCache.js +6 -2
- package/lib/browser/events/types.d.ts +3 -7
- package/lib/browser/events/types.js +1 -3
- package/lib/browser/events/webSocketLogProvider.d.ts +1 -1
- package/lib/browser/events/webSocketLogProvider.js +5 -2
- package/lib/browser/factory/bigNum.js +1 -1
- package/lib/{node/idl/drift.d.ts → browser/idl/velocity.d.ts} +2412 -2481
- package/lib/browser/idl/{drift.json → velocity.json} +2265 -2333
- package/lib/browser/index.d.ts +1 -3
- package/lib/browser/index.js +1 -4
- package/lib/browser/jupiter/jupiterClient.d.ts +1 -1
- package/lib/browser/jupiter/jupiterClient.js +18 -8
- package/lib/browser/marginCalculation.js +1 -0
- package/lib/browser/math/amm.d.ts +31 -13
- package/lib/browser/math/amm.js +87 -31
- package/lib/browser/math/auction.js +16 -12
- package/lib/browser/math/bankruptcy.js +1 -1
- package/lib/browser/math/builder.d.ts +18 -1
- package/lib/browser/math/builder.js +32 -1
- package/lib/browser/math/funding.js +30 -30
- package/lib/browser/math/insurance.d.ts +1 -1
- package/lib/browser/math/insurance.js +4 -5
- package/lib/browser/math/margin.d.ts +3 -11
- package/lib/browser/math/margin.js +10 -69
- package/lib/browser/math/market.d.ts +4 -12
- package/lib/browser/math/market.js +12 -46
- package/lib/browser/math/oracles.d.ts +4 -7
- package/lib/browser/math/oracles.js +24 -37
- package/lib/browser/math/orders.d.ts +2 -7
- package/lib/browser/math/orders.js +9 -81
- package/lib/browser/math/position.d.ts +0 -4
- package/lib/browser/math/position.js +6 -11
- package/lib/browser/math/repeg.d.ts +0 -1
- package/lib/browser/math/repeg.js +1 -23
- package/lib/browser/math/spotBalance.d.ts +4 -4
- package/lib/browser/math/spotBalance.js +6 -6
- package/lib/browser/math/spotMarket.d.ts +0 -6
- package/lib/browser/math/spotMarket.js +1 -16
- package/lib/browser/math/spotPosition.d.ts +4 -4
- package/lib/browser/math/state.d.ts +0 -2
- package/lib/browser/math/state.js +1 -9
- package/lib/browser/math/superStake.d.ts +11 -63
- package/lib/browser/math/superStake.js +29 -28
- package/lib/browser/math/trade.js +7 -7
- package/lib/browser/math/utils.d.ts +1 -1
- package/lib/browser/math/utils.js +1 -1
- package/lib/browser/memcmp.d.ts +0 -1
- package/lib/browser/memcmp.js +1 -10
- package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
- package/lib/browser/oracles/pythClient.js +9 -3
- package/lib/browser/oracles/pythLazerClient.js +5 -4
- package/lib/browser/oracles/utils.d.ts +4 -0
- package/lib/browser/oracles/utils.js +9 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -3
- package/lib/browser/orderSubscriber/OrderSubscriber.js +16 -14
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/browser/orderSubscriber/types.d.ts +0 -2
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +2 -6
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +34 -18
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/types.d.ts +3 -8
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +1 -3
- package/lib/browser/pyth/pythLazerSubscriber.d.ts +1 -1
- package/lib/browser/pyth/pythLazerSubscriber.js +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.js +1 -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 +7 -7
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +14 -10
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -6
- package/lib/browser/swift/swiftOrderSubscriber.js +15 -16
- package/lib/browser/testClient.js +3 -2
- 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 +7 -1
- 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 +102 -157
- package/lib/browser/types.js +6 -2
- package/lib/browser/user.d.ts +22 -10
- package/lib/browser/user.js +174 -154
- package/lib/browser/userConfig.d.ts +3 -2
- package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/browser/userMap/WebsocketSubscription.js +1 -1
- package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
- package/lib/browser/userMap/grpcSubscription.js +1 -1
- package/lib/browser/userMap/referrerMap.d.ts +0 -2
- package/lib/browser/userMap/referrerMap.js +10 -7
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
- package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/browser/userMap/userMap.d.ts +3 -5
- package/lib/browser/userMap/userMap.js +39 -30
- package/lib/browser/userMap/userMapConfig.d.ts +3 -2
- package/lib/browser/userMap/userStatsMap.d.ts +1 -3
- package/lib/browser/userMap/userStatsMap.js +18 -17
- package/lib/browser/userStats.d.ts +7 -4
- package/lib/browser/userStats.js +28 -18
- package/lib/browser/userStatsConfig.d.ts +3 -2
- 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/util/ed25519Utils.d.ts +1 -1
- package/lib/browser/util/ed25519Utils.js +1 -1
- package/lib/browser/velocityClient.d.ts +144 -71
- package/lib/browser/velocityClient.js +653 -457
- package/lib/browser/velocityClientConfig.d.ts +0 -8
- 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 +9 -3
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +4 -1
- 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 -5
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
- package/lib/node/accounts/types.d.ts +6 -12
- 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 +10 -3
- 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 -8
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
- 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 +1 -9
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +4 -23
- package/lib/node/adminClient.d.ts +25 -29
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +168 -169
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +2 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +8 -10
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
- package/lib/node/auctionSubscriber/types.d.ts +3 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.d.ts +6 -4
- package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.js +69 -31
- 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 +11 -20
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +13 -36
- 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 -3
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +3 -5
- package/lib/node/constituentMap/constituentMap.d.ts +0 -2
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +10 -6
- 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 +9 -15
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +5 -7
- 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 +1 -1
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
- package/lib/node/core/instructions/withdraw.js +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 +5 -5
- 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 +7 -2
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +205 -142
- package/lib/node/dlob/DLOBNode.d.ts +5 -2
- 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 -2
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +39 -39
- 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.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +24 -17
- package/lib/node/dlob/types.d.ts +0 -2
- package/lib/node/dlob/types.d.ts.map +1 -1
- 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 +6 -3
- 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 +17 -10
- 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/parse.d.ts.map +1 -1
- package/lib/node/events/parse.js +14 -14
- 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 +3 -7
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +1 -3
- 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.js +1 -1
- package/lib/{browser/idl/drift.d.ts → node/idl/velocity.d.ts} +2413 -2480
- package/lib/node/idl/velocity.d.ts.map +1 -0
- package/lib/node/idl/{drift.json → velocity.json} +2265 -2333
- package/lib/node/index.d.ts +1 -3
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -4
- package/lib/node/jupiter/jupiterClient.d.ts +1 -1
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.js +18 -8
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marginCalculation.js +1 -0
- package/lib/node/math/amm.d.ts +31 -13
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +87 -31
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +16 -12
- package/lib/node/math/bankruptcy.js +1 -1
- package/lib/node/math/builder.d.ts +18 -1
- package/lib/node/math/builder.d.ts.map +1 -1
- package/lib/node/math/builder.js +32 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +30 -30
- package/lib/node/math/insurance.d.ts +1 -1
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/insurance.js +4 -5
- package/lib/node/math/margin.d.ts +3 -11
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +10 -69
- package/lib/node/math/market.d.ts +4 -12
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +12 -46
- package/lib/node/math/oracles.d.ts +4 -7
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +24 -37
- package/lib/node/math/orders.d.ts +2 -7
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +9 -81
- package/lib/node/math/position.d.ts +1 -5
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +6 -11
- package/lib/node/math/repeg.d.ts +0 -1
- 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 -4
- 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 -6
- 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 -4
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/state.d.ts +0 -2
- 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 +11 -63
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +29 -28
- package/lib/node/math/trade.d.ts +2 -2
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +7 -7
- package/lib/node/math/utils.d.ts +1 -1
- package/lib/node/math/utils.js +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.map +1 -1
- package/lib/node/oracles/pythClient.js +9 -3
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +5 -4
- package/lib/node/oracles/utils.d.ts +4 -0
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/oracles/utils.js +9 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -3
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +16 -14
- package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/node/orderSubscriber/types.d.ts +0 -2
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- 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 +2 -6
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +34 -18
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +3 -11
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/types.d.ts +3 -8
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/velocityPriorityFeeMethod.js +1 -3
- package/lib/node/pyth/pythLazerSubscriber.d.ts +1 -1
- package/lib/node/pyth/pythLazerSubscriber.js +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.js +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 +7 -7
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +14 -10
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -6
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +15 -16
- package/lib/node/testClient.js +3 -2
- 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 +100 -155
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +6 -2
- package/lib/node/user.d.ts +22 -10
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +174 -154
- package/lib/node/userConfig.d.ts +3 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.js +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/grpcSubscription.js +1 -1
- package/lib/node/userMap/referrerMap.d.ts +0 -2
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +10 -7
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +0 -2
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/node/userMap/userMap.d.ts +3 -5
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +39 -30
- package/lib/node/userMap/userMapConfig.d.ts +3 -2
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +1 -3
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +18 -17
- package/lib/node/userStats.d.ts +7 -4
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +28 -18
- package/lib/node/userStatsConfig.d.ts +3 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- 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/util/ed25519Utils.d.ts +1 -1
- package/lib/node/util/ed25519Utils.js +1 -1
- package/lib/node/velocityClient.d.ts +145 -72
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +653 -457
- package/lib/node/velocityClientConfig.d.ts +0 -8
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +10 -9
- package/scripts/deposit-isolated-positions.ts +2 -2
- package/scripts/find-flagged-users.ts +1 -1
- package/scripts/grpc-client-test-comparison.ts +4 -4
- package/scripts/grpc-multiuser-client-test-comparison.ts +2 -2
- package/scripts/single-grpc-client-test.ts +3 -3
- package/scripts/updateVersion.js +4 -4
- package/scripts/withdraw-isolated-positions.ts +2 -2
- 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 +12 -4
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -14
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +69 -49
- package/src/accounts/laserProgramAccountSubscriber.ts +4 -1
- 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 +80 -41
- package/src/accounts/types.ts +8 -13
- package/src/accounts/utils.ts +12 -2
- 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 +79 -58
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +77 -45
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
- package/src/addresses/marketAddresses.ts +3 -2
- package/src/addresses/pda.ts +3 -38
- package/src/adminClient.ts +285 -315
- package/src/auctionSubscriber/auctionSubscriber.ts +8 -11
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +13 -11
- package/src/auctionSubscriber/types.ts +3 -3
- package/src/bankrun/bankrunConnection.ts +83 -39
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
- package/src/clock/clockSubscriber.ts +10 -9
- package/src/config.ts +16 -70
- package/src/constants/index.ts +1 -2
- package/src/constants/numericConstants.ts +3 -3
- package/src/constituentMap/constituentMap.ts +10 -7
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
- package/src/core/VelocityCore.ts +11 -20
- package/src/core/instructions/perpOrders.ts +14 -0
- package/src/core/instructions/withdraw.ts +2 -2
- package/src/core/remainingAccounts.ts +7 -7
- package/src/decode/user.ts +8 -1
- package/src/dlob/DLOB.ts +300 -176
- package/src/dlob/DLOBNode.ts +23 -3
- package/src/dlob/DLOBSubscriber.ts +53 -42
- package/src/dlob/NodeList.ts +8 -7
- package/src/dlob/orderBookLevels.ts +51 -25
- package/src/dlob/types.ts +0 -2
- package/src/events/eventList.ts +4 -1
- package/src/events/eventSubscriber.ts +108 -50
- package/src/events/eventsServerLogProvider.ts +24 -15
- package/src/events/fetchLogs.ts +3 -3
- package/src/events/parse.ts +14 -14
- package/src/events/pollingLogProvider.ts +2 -2
- package/src/events/txEventCache.ts +8 -2
- package/src/events/types.ts +4 -15
- package/src/events/webSocketLogProvider.ts +5 -3
- package/src/factory/bigNum.ts +2 -2
- package/src/idl/{drift.json → velocity.json} +2265 -2333
- package/src/idl/{drift.ts → velocity.ts} +2267 -2335
- package/src/index.ts +1 -6
- package/src/jupiter/jupiterClient.ts +30 -10
- package/src/margin/README.md +2 -2
- package/src/marginCalculation.ts +1 -0
- package/src/math/amm.ts +217 -40
- package/src/math/auction.ts +16 -12
- package/src/math/bankruptcy.ts +1 -1
- package/src/math/builder.ts +45 -1
- package/src/math/funding.ts +51 -47
- package/src/math/insurance.ts +6 -8
- package/src/math/margin.ts +12 -119
- package/src/math/market.ts +16 -98
- package/src/math/oracles.ts +29 -43
- package/src/math/orders.ts +13 -109
- package/src/math/position.ts +6 -12
- 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 +36 -85
- package/src/math/trade.ts +7 -3
- package/src/math/utils.ts +1 -1
- 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 +10 -5
- package/src/oracles/utils.ts +15 -0
- package/src/orderSubscriber/OrderSubscriber.ts +12 -12
- package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
- package/src/orderSubscriber/grpcSubscription.ts +2 -2
- package/src/orderSubscriber/types.ts +0 -2
- package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +50 -21
- package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
- package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/types.ts +3 -13
- package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
- package/src/pyth/pythLazerSubscriber.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/swap/UnifiedSwapClient.ts +1 -1
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
- package/src/swift/signedMsgUserAccountSubscriber.ts +18 -16
- package/src/swift/swiftOrderSubscriber.ts +17 -21
- 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 +119 -173
- package/src/user.ts +208 -165
- package/src/userConfig.ts +1 -3
- package/src/userMap/WebsocketSubscription.ts +2 -2
- package/src/userMap/grpcSubscription.ts +2 -2
- package/src/userMap/referrerMap.ts +13 -13
- package/src/userMap/revenueShareEscrowMap.ts +6 -5
- package/src/userMap/userMap.ts +46 -32
- package/src/userMap/userMapConfig.ts +3 -3
- package/src/userMap/userStatsMap.ts +32 -23
- package/src/userStats.ts +22 -13
- package/src/userStatsConfig.ts +3 -3
- package/src/util/TransactionConfirmationManager.ts +10 -2
- package/src/util/chainClock.ts +1 -1
- package/src/util/computeUnits.ts +7 -3
- package/src/util/ed25519Utils.ts +1 -1
- package/src/velocityClient.ts +867 -600
- package/src/velocityClientConfig.ts +0 -10
- package/tests/{DriftCore → VelocityCore}/decode.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/fill_trigger.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/instructions.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/pdas.test.ts +4 -2
- package/tests/amm/test.ts +138 -0
- package/tests/ci/verifyConstants.ts +24 -27
- package/tests/decode/test.ts +2 -2
- package/tests/dlob/helpers.ts +11 -10
- package/tests/events/parseLogsForCuUsage.ts +15 -15
- package/tests/user/helpers.ts +9 -9
- package/tests/user/test.ts +13 -10
- package/tsconfig.json +1 -0
- 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/deprecatedAlias.d.ts +0 -26
- package/lib/browser/util/deprecatedAlias.js +0 -10
- 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/idl/drift.d.ts.map +0 -1
- 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/deprecatedAlias.d.ts +0 -27
- package/lib/node/util/deprecatedAlias.d.ts.map +0 -1
- package/lib/node/util/deprecatedAlias.js +0 -10
- 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/src/constants/insuranceFund.ts +0 -8
- package/src/tx/forwardOnlyTxSender.ts +0 -145
- package/src/util/deprecatedAlias.ts +0 -21
- package/src/util/tps.ts +0 -27
- /package/lib/browser/idl/{drift.js → velocity.js} +0 -0
- /package/lib/node/idl/{drift.js → velocity.js} +0 -0
- /package/tests/{DriftCore → VelocityCore}/perp_orders.test.ts +0 -0
- /package/tests/{DriftCore → VelocityCore}/remainingAccounts.test.ts +0 -0
- /package/tests/{DriftCore → VelocityCore}/settlement_liquidation.test.ts +0 -0
package/lib/node/dlob/DLOB.js
CHANGED
|
@@ -31,6 +31,18 @@ const SUPPORTED_ORDER_TYPES = [
|
|
|
31
31
|
'triggerLimit',
|
|
32
32
|
'oracle',
|
|
33
33
|
];
|
|
34
|
+
function getOrderOrThrow(node) {
|
|
35
|
+
if (!node.order) {
|
|
36
|
+
throw new Error('DLOBNode must have an order');
|
|
37
|
+
}
|
|
38
|
+
return node.order;
|
|
39
|
+
}
|
|
40
|
+
function getUserAccountOrThrow(node) {
|
|
41
|
+
if (node.userAccount === undefined) {
|
|
42
|
+
throw new Error('DLOBNode must have a userAccount');
|
|
43
|
+
}
|
|
44
|
+
return node.userAccount;
|
|
45
|
+
}
|
|
34
46
|
class DLOB {
|
|
35
47
|
constructor() {
|
|
36
48
|
this.openOrders = new Map();
|
|
@@ -45,19 +57,41 @@ class DLOB {
|
|
|
45
57
|
this.orderLists.set('perp', new Map());
|
|
46
58
|
this.orderLists.set('spot', new Map());
|
|
47
59
|
}
|
|
60
|
+
getOpenOrdersForMarketType(marketTypeStr) {
|
|
61
|
+
const openOrders = this.openOrders.get(marketTypeStr);
|
|
62
|
+
if (!openOrders) {
|
|
63
|
+
throw new Error(`DLOB has no open orders set for market type ${marketTypeStr}`);
|
|
64
|
+
}
|
|
65
|
+
return openOrders;
|
|
66
|
+
}
|
|
67
|
+
getOrderListsForMarketType(marketTypeStr) {
|
|
68
|
+
const orderLists = this.orderLists.get(marketTypeStr);
|
|
69
|
+
if (!orderLists) {
|
|
70
|
+
throw new Error(`DLOB has no order lists for market type ${marketTypeStr}`);
|
|
71
|
+
}
|
|
72
|
+
return orderLists;
|
|
73
|
+
}
|
|
74
|
+
tryGetMarketNodeLists(marketTypeStr, marketIndex) {
|
|
75
|
+
var _a;
|
|
76
|
+
return (_a = this.orderLists.get(marketTypeStr)) === null || _a === void 0 ? void 0 : _a.get(marketIndex);
|
|
77
|
+
}
|
|
78
|
+
getMarketNodeLists(marketTypeStr, marketIndex) {
|
|
79
|
+
const marketNodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
80
|
+
if (!marketNodeLists) {
|
|
81
|
+
throw new Error(`DLOB has no order lists for market type ${marketTypeStr} and market index ${marketIndex}`);
|
|
82
|
+
}
|
|
83
|
+
return marketNodeLists;
|
|
84
|
+
}
|
|
48
85
|
clear() {
|
|
49
|
-
for (const
|
|
50
|
-
|
|
86
|
+
for (const openOrders of this.openOrders.values()) {
|
|
87
|
+
openOrders.clear();
|
|
51
88
|
}
|
|
52
89
|
this.openOrders.clear();
|
|
53
|
-
for (const
|
|
54
|
-
for (const
|
|
55
|
-
const
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
for (const side of Object.keys(marketNodeLists)) {
|
|
59
|
-
for (const orderType of Object.keys(marketNodeLists[side])) {
|
|
60
|
-
marketNodeLists[side][orderType].clear();
|
|
90
|
+
for (const marketNodeListsMap of this.orderLists.values()) {
|
|
91
|
+
for (const marketNodeLists of marketNodeListsMap.values()) {
|
|
92
|
+
for (const side of Object.values(marketNodeLists)) {
|
|
93
|
+
for (const nodeList of Object.values(side)) {
|
|
94
|
+
nodeList.clear();
|
|
61
95
|
}
|
|
62
96
|
}
|
|
63
97
|
}
|
|
@@ -78,7 +112,7 @@ class DLOB {
|
|
|
78
112
|
}
|
|
79
113
|
// initialize the dlob with the user map
|
|
80
114
|
for (const user of userMap.values()) {
|
|
81
|
-
const userAccount = user.
|
|
115
|
+
const userAccount = user.getUserAccountOrThrow();
|
|
82
116
|
const userAccountPubkey = user.getUserAccountPublicKey();
|
|
83
117
|
const userAccountPubkeyString = userAccountPubkey.toString();
|
|
84
118
|
for (const order of userAccount.orders) {
|
|
@@ -102,13 +136,11 @@ class DLOB {
|
|
|
102
136
|
return;
|
|
103
137
|
}
|
|
104
138
|
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
105
|
-
if (!this.
|
|
139
|
+
if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
|
|
106
140
|
this.addOrderList(marketType, order.marketIndex);
|
|
107
141
|
}
|
|
108
142
|
if ((0, types_1.isVariant)(order.status, 'open')) {
|
|
109
|
-
this.
|
|
110
|
-
.get(marketType)
|
|
111
|
-
.add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
143
|
+
this.getOpenOrdersForMarketType(marketType).add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
112
144
|
}
|
|
113
145
|
(_a = this.getListForOnChainOrder(order, slot)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, baseAssetAmount);
|
|
114
146
|
if (onInsert) {
|
|
@@ -119,22 +151,17 @@ class DLOB {
|
|
|
119
151
|
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
120
152
|
const marketIndex = order.marketIndex;
|
|
121
153
|
const bidOrAsk = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
|
|
122
|
-
if (!this.
|
|
154
|
+
if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
|
|
123
155
|
this.addOrderList(marketType, order.marketIndex);
|
|
124
156
|
}
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
.add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
128
|
-
this.orderLists
|
|
129
|
-
.get(marketType)
|
|
130
|
-
.get(marketIndex)
|
|
131
|
-
.signedMsg[bidOrAsk].insert(order, marketType, userAccount, baseAssetAmount);
|
|
157
|
+
this.getOpenOrdersForMarketType(marketType).add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
|
|
158
|
+
this.getMarketNodeLists(marketType, marketIndex).signedMsg[bidOrAsk].insert(order, marketType, userAccount, baseAssetAmount);
|
|
132
159
|
if (onInsert) {
|
|
133
160
|
onInsert();
|
|
134
161
|
}
|
|
135
162
|
}
|
|
136
163
|
addOrderList(marketType, marketIndex) {
|
|
137
|
-
this.
|
|
164
|
+
this.getOrderListsForMarketType(marketType).set(marketIndex, {
|
|
138
165
|
restingLimit: {
|
|
139
166
|
ask: new NodeList_1.NodeList('restingLimit', 'asc'),
|
|
140
167
|
bid: new NodeList_1.NodeList('restingLimit', 'desc'),
|
|
@@ -174,32 +201,37 @@ class DLOB {
|
|
|
174
201
|
}
|
|
175
202
|
getListForOnChainOrder(order, slot) {
|
|
176
203
|
const isInactiveTriggerOrder = (0, orders_1.mustBeTriggered)(order) && !(0, orders_1.isTriggered)(order);
|
|
177
|
-
|
|
204
|
+
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
205
|
+
const marketNodeLists = this.tryGetMarketNodeLists(marketType, order.marketIndex);
|
|
206
|
+
if (!marketNodeLists) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
178
209
|
if (isInactiveTriggerOrder) {
|
|
179
|
-
|
|
210
|
+
const subType = (0, types_1.isVariant)(order.triggerCondition, 'above')
|
|
211
|
+
? 'above'
|
|
212
|
+
: 'below';
|
|
213
|
+
return marketNodeLists.trigger[subType];
|
|
180
214
|
}
|
|
181
|
-
|
|
182
|
-
|
|
215
|
+
const subType = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
|
|
216
|
+
if ((0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
|
|
217
|
+
return marketNodeLists.market[subType];
|
|
183
218
|
}
|
|
184
219
|
else if (!order.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
|
|
185
|
-
|
|
220
|
+
return marketNodeLists.floatingLimit[subType];
|
|
186
221
|
}
|
|
187
222
|
else {
|
|
188
223
|
const isResting = (0, orders_1.isRestingLimitOrder)(order, slot);
|
|
189
|
-
|
|
224
|
+
return isResting
|
|
225
|
+
? marketNodeLists.restingLimit[subType]
|
|
226
|
+
: marketNodeLists.takingLimit[subType];
|
|
190
227
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
subType = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
|
|
197
|
-
}
|
|
198
|
-
const marketType = (0, types_1.getVariant)(order.marketType);
|
|
199
|
-
if (!this.orderLists.has(marketType)) {
|
|
200
|
-
return undefined;
|
|
228
|
+
}
|
|
229
|
+
getListForOnChainOrderOrThrow(order, slot) {
|
|
230
|
+
const list = this.getListForOnChainOrder(order, slot);
|
|
231
|
+
if (!list) {
|
|
232
|
+
throw new Error(`No order list found for order ${order.orderId} in market ${order.marketIndex}`);
|
|
201
233
|
}
|
|
202
|
-
return
|
|
234
|
+
return list;
|
|
203
235
|
}
|
|
204
236
|
updateRestingLimitOrders(slot) {
|
|
205
237
|
if (slot <= this.maxSlotForRestingLimitOrders) {
|
|
@@ -210,10 +242,10 @@ class DLOB {
|
|
|
210
242
|
this.updateRestingLimitOrdersForMarketType(slot, 'spot');
|
|
211
243
|
}
|
|
212
244
|
updateRestingLimitOrdersForMarketType(slot, marketTypeStr) {
|
|
213
|
-
for (const [_, nodeLists] of this.
|
|
245
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType(marketTypeStr)) {
|
|
214
246
|
const nodesToUpdate = [];
|
|
215
247
|
for (const node of nodeLists.takingLimit.ask.getGenerator()) {
|
|
216
|
-
if (!(0, orders_1.isRestingLimitOrder)(node
|
|
248
|
+
if (!(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(node), slot)) {
|
|
217
249
|
continue;
|
|
218
250
|
}
|
|
219
251
|
nodesToUpdate.push({
|
|
@@ -222,7 +254,7 @@ class DLOB {
|
|
|
222
254
|
});
|
|
223
255
|
}
|
|
224
256
|
for (const node of nodeLists.takingLimit.bid.getGenerator()) {
|
|
225
|
-
if (!(0, orders_1.isRestingLimitOrder)(node
|
|
257
|
+
if (!(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(node), slot)) {
|
|
226
258
|
continue;
|
|
227
259
|
}
|
|
228
260
|
nodesToUpdate.push({
|
|
@@ -232,8 +264,10 @@ class DLOB {
|
|
|
232
264
|
}
|
|
233
265
|
for (const nodeToUpdate of nodesToUpdate) {
|
|
234
266
|
const { side, node } = nodeToUpdate;
|
|
235
|
-
|
|
236
|
-
|
|
267
|
+
const order = getOrderOrThrow(node);
|
|
268
|
+
const userAccount = getUserAccountOrThrow(node);
|
|
269
|
+
nodeLists.takingLimit[side].remove(order, userAccount);
|
|
270
|
+
nodeLists.restingLimit[side].insert(order, marketTypeStr, userAccount);
|
|
237
271
|
}
|
|
238
272
|
}
|
|
239
273
|
}
|
|
@@ -258,7 +292,7 @@ class DLOB {
|
|
|
258
292
|
// get expired market nodes
|
|
259
293
|
const expiredNodesToFill = this.findExpiredNodesToFill(marketIndex, ts, marketType, new anchor_1.BN(slot));
|
|
260
294
|
const stepSize = (0, types_1.isVariant)(marketType, 'perp')
|
|
261
|
-
? marketAccount.
|
|
295
|
+
? marketAccount.orderStepSize
|
|
262
296
|
: marketAccount.orderStepSize;
|
|
263
297
|
const cancelReduceOnlyNodesToFill = this.findUnfillableReduceOnlyOrdersToCancel(marketIndex, marketType, stepSize);
|
|
264
298
|
return this.mergeNodesToFill(restingLimitOrderNodesToFill, takingOrderNodesToFill)
|
|
@@ -291,17 +325,17 @@ class DLOB {
|
|
|
291
325
|
const mergedNodesToFill = new Map();
|
|
292
326
|
const mergeNodesToFillHelper = (nodesToFillArray) => {
|
|
293
327
|
nodesToFillArray.forEach((nodeToFill) => {
|
|
294
|
-
const nodeSignature = (0, NodeList_1.getOrderSignature)(nodeToFill.node.
|
|
295
|
-
|
|
296
|
-
|
|
328
|
+
const nodeSignature = (0, NodeList_1.getOrderSignature)(getOrderOrThrow(nodeToFill.node).orderId, getUserAccountOrThrow(nodeToFill.node));
|
|
329
|
+
let mergedNodeToFill = mergedNodesToFill.get(nodeSignature);
|
|
330
|
+
if (!mergedNodeToFill) {
|
|
331
|
+
mergedNodeToFill = {
|
|
297
332
|
node: nodeToFill.node,
|
|
298
333
|
makerNodes: [],
|
|
299
|
-
}
|
|
334
|
+
};
|
|
335
|
+
mergedNodesToFill.set(nodeSignature, mergedNodeToFill);
|
|
300
336
|
}
|
|
301
337
|
if (nodeToFill.makerNodes) {
|
|
302
|
-
|
|
303
|
-
.get(nodeSignature)
|
|
304
|
-
.makerNodes.push(...nodeToFill.makerNodes);
|
|
338
|
+
mergedNodeToFill.makerNodes.push(...nodeToFill.makerNodes);
|
|
305
339
|
}
|
|
306
340
|
});
|
|
307
341
|
};
|
|
@@ -319,6 +353,9 @@ class DLOB {
|
|
|
319
353
|
const askGenerator = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
320
354
|
const fallbackBidWithBuffer = fallbackBid.sub(fallbackBid.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
321
355
|
const asksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, askGenerator, (askPrice) => {
|
|
356
|
+
if (askPrice === undefined) {
|
|
357
|
+
throw new Error('Resting limit ask must have a limit price');
|
|
358
|
+
}
|
|
322
359
|
return askPrice.lte(fallbackBidWithBuffer);
|
|
323
360
|
}, stateAccount, marketAccount);
|
|
324
361
|
for (const askCrossingFallback of asksCrossingFallback) {
|
|
@@ -329,6 +366,9 @@ class DLOB {
|
|
|
329
366
|
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
330
367
|
const fallbackAskWithBuffer = fallbackAsk.add(fallbackAsk.muln(makerRebateNumerator).divn(makerRebateDenominator));
|
|
331
368
|
const bidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, bidGenerator, (bidPrice) => {
|
|
369
|
+
if (bidPrice === undefined) {
|
|
370
|
+
throw new Error('Resting limit bid must have a limit price');
|
|
371
|
+
}
|
|
332
372
|
return bidPrice.gte(fallbackAskWithBuffer);
|
|
333
373
|
}, stateAccount, marketAccount);
|
|
334
374
|
for (const bidCrossingFallback of bidsCrossingFallback) {
|
|
@@ -399,7 +439,7 @@ class DLOB {
|
|
|
399
439
|
if (sameUser) {
|
|
400
440
|
continue;
|
|
401
441
|
}
|
|
402
|
-
const makerPrice = makerNode.
|
|
442
|
+
const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot);
|
|
403
443
|
const takerPrice = takerNode.getPrice(oraclePriceData, slot);
|
|
404
444
|
const ordersCross = doesCross(takerPrice, makerPrice);
|
|
405
445
|
if (!ordersCross) {
|
|
@@ -411,27 +451,28 @@ class DLOB {
|
|
|
411
451
|
node: takerNode,
|
|
412
452
|
makerNodes: [makerNode],
|
|
413
453
|
});
|
|
414
|
-
const makerOrder = makerNode
|
|
415
|
-
const takerOrder = takerNode
|
|
454
|
+
const makerOrder = getOrderOrThrow(makerNode);
|
|
455
|
+
const takerOrder = getOrderOrThrow(takerNode);
|
|
416
456
|
const makerBaseRemaining = makerOrder.baseAssetAmount.sub(makerOrder.baseAssetAmountFilled);
|
|
417
457
|
const takerBaseRemaining = takerOrder.baseAssetAmount.sub(takerOrder.baseAssetAmountFilled);
|
|
418
458
|
const baseFilled = anchor_1.BN.min(makerBaseRemaining, takerBaseRemaining);
|
|
419
459
|
const newMakerOrder = { ...makerOrder };
|
|
420
460
|
newMakerOrder.baseAssetAmountFilled =
|
|
421
461
|
makerOrder.baseAssetAmountFilled.add(baseFilled);
|
|
422
|
-
this.
|
|
462
|
+
this.getListForOnChainOrderOrThrow(newMakerOrder, slot).update(newMakerOrder, getUserAccountOrThrow(makerNode));
|
|
423
463
|
const newTakerOrder = { ...takerOrder };
|
|
424
464
|
newTakerOrder.baseAssetAmountFilled =
|
|
425
465
|
takerOrder.baseAssetAmountFilled.add(baseFilled);
|
|
426
466
|
if (takerNode.isSignedMsg) {
|
|
427
467
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
468
|
+
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
428
469
|
const orderList = (0, types_1.isVariant)(takerOrder.direction, 'long')
|
|
429
|
-
?
|
|
430
|
-
:
|
|
431
|
-
orderList.update(newTakerOrder, takerNode
|
|
470
|
+
? marketNodeLists.signedMsg.bid
|
|
471
|
+
: marketNodeLists.signedMsg.ask;
|
|
472
|
+
orderList.update(newTakerOrder, getUserAccountOrThrow(takerNode));
|
|
432
473
|
}
|
|
433
474
|
else {
|
|
434
|
-
this.
|
|
475
|
+
this.getListForOnChainOrderOrThrow(newTakerOrder, slot).update(newTakerOrder, getUserAccountOrThrow(takerNode));
|
|
435
476
|
}
|
|
436
477
|
if (newTakerOrder.baseAssetAmountFilled.eq(takerOrder.baseAssetAmount)) {
|
|
437
478
|
break;
|
|
@@ -450,12 +491,13 @@ class DLOB {
|
|
|
450
491
|
nextNode = nodeGenerator.next();
|
|
451
492
|
continue;
|
|
452
493
|
}
|
|
453
|
-
const
|
|
494
|
+
const nodeOrder = getOrderOrThrow(node);
|
|
495
|
+
const nodePrice = (0, orders_1.getLimitPrice)(nodeOrder, oraclePriceData, slot);
|
|
454
496
|
// order crosses if there is no limit price or it crosses fallback price
|
|
455
497
|
const crosses = doesCross(nodePrice);
|
|
456
498
|
// fallback is available if auction is complete or it's a spot order
|
|
457
499
|
const fallbackAvailable = (0, types_1.isVariant)(marketType, 'spot') ||
|
|
458
|
-
(0, auction_1.isFallbackAvailableLiquiditySource)(
|
|
500
|
+
(0, auction_1.isFallbackAvailableLiquiditySource)(nodeOrder, oraclePriceData, slot, state, marketAccount);
|
|
459
501
|
if (crosses && fallbackAvailable) {
|
|
460
502
|
nodesToFill.push({
|
|
461
503
|
node: node,
|
|
@@ -469,7 +511,7 @@ class DLOB {
|
|
|
469
511
|
findExpiredNodesToFill(marketIndex, ts, marketType, slot) {
|
|
470
512
|
const nodesToFill = new Array();
|
|
471
513
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
472
|
-
const nodeLists = this.
|
|
514
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
473
515
|
if (!nodeLists) {
|
|
474
516
|
return nodesToFill;
|
|
475
517
|
}
|
|
@@ -491,14 +533,17 @@ class DLOB {
|
|
|
491
533
|
];
|
|
492
534
|
for (const bidGenerator of bidGenerators) {
|
|
493
535
|
for (const bid of bidGenerator) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
536
|
+
const bidOrder = getOrderOrThrow(bid);
|
|
537
|
+
if (bid.isSignedMsg) {
|
|
538
|
+
if (slot === undefined) {
|
|
539
|
+
throw new Error('Must provide slot to findExpiredNodesToFill to expire signedMsg orders');
|
|
540
|
+
}
|
|
541
|
+
if (slot.gt(bidOrder.slot.addn(bidOrder.auctionDuration))) {
|
|
542
|
+
nodeLists.signedMsg.bid.remove(bidOrder, getUserAccountOrThrow(bid));
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
500
545
|
}
|
|
501
|
-
|
|
546
|
+
if ((0, orders_1.isOrderExpired)(bidOrder, ts, true, 25)) {
|
|
502
547
|
nodesToFill.push({
|
|
503
548
|
node: bid,
|
|
504
549
|
makerNodes: [],
|
|
@@ -508,14 +553,17 @@ class DLOB {
|
|
|
508
553
|
}
|
|
509
554
|
for (const askGenerator of askGenerators) {
|
|
510
555
|
for (const ask of askGenerator) {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
556
|
+
const askOrder = getOrderOrThrow(ask);
|
|
557
|
+
if (ask.isSignedMsg) {
|
|
558
|
+
if (slot === undefined) {
|
|
559
|
+
throw new Error('Must provide slot to findExpiredNodesToFill to expire signedMsg orders');
|
|
560
|
+
}
|
|
561
|
+
if (slot.gt(askOrder.slot.addn(askOrder.auctionDuration))) {
|
|
562
|
+
nodeLists.signedMsg.ask.remove(askOrder, getUserAccountOrThrow(ask));
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
517
565
|
}
|
|
518
|
-
|
|
566
|
+
if ((0, orders_1.isOrderExpired)(askOrder, ts, true, 25)) {
|
|
519
567
|
nodesToFill.push({
|
|
520
568
|
node: ask,
|
|
521
569
|
makerNodes: [],
|
|
@@ -528,7 +576,7 @@ class DLOB {
|
|
|
528
576
|
findUnfillableReduceOnlyOrdersToCancel(marketIndex, marketType, stepSize) {
|
|
529
577
|
const nodesToFill = new Array();
|
|
530
578
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
531
|
-
const nodeLists = this.
|
|
579
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
532
580
|
if (!nodeLists) {
|
|
533
581
|
return nodesToFill;
|
|
534
582
|
}
|
|
@@ -548,7 +596,7 @@ class DLOB {
|
|
|
548
596
|
];
|
|
549
597
|
for (const generator of generators) {
|
|
550
598
|
for (const node of generator) {
|
|
551
|
-
if (!node.
|
|
599
|
+
if (!getOrderOrThrow(node).reduceOnly) {
|
|
552
600
|
continue;
|
|
553
601
|
}
|
|
554
602
|
if (node.baseAssetAmount.lt(stepSize)) {
|
|
@@ -563,7 +611,7 @@ class DLOB {
|
|
|
563
611
|
}
|
|
564
612
|
*getTakingBids(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
565
613
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
566
|
-
const orderLists = this.
|
|
614
|
+
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
567
615
|
if (!orderLists) {
|
|
568
616
|
return;
|
|
569
617
|
}
|
|
@@ -571,15 +619,15 @@ class DLOB {
|
|
|
571
619
|
const generatorList = [
|
|
572
620
|
orderLists.market.bid.getGenerator(),
|
|
573
621
|
orderLists.takingLimit.bid.getGenerator(),
|
|
574
|
-
this.signedMsgGenerator(orderLists.signedMsg.bid, (x) => !(0, orders_1.isRestingLimitOrder)(x
|
|
622
|
+
this.signedMsgGenerator(orderLists.signedMsg.bid, (x) => !(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
|
|
575
623
|
];
|
|
576
624
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
577
|
-
return bestNode.
|
|
625
|
+
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
578
626
|
}, filterFcn);
|
|
579
627
|
}
|
|
580
628
|
*getTakingAsks(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
|
|
581
629
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
582
|
-
const orderLists = this.
|
|
630
|
+
const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
583
631
|
if (!orderLists) {
|
|
584
632
|
return;
|
|
585
633
|
}
|
|
@@ -587,10 +635,10 @@ class DLOB {
|
|
|
587
635
|
const generatorList = [
|
|
588
636
|
orderLists.market.ask.getGenerator(),
|
|
589
637
|
orderLists.takingLimit.ask.getGenerator(),
|
|
590
|
-
this.signedMsgGenerator(orderLists.signedMsg.ask, (x) => !(0, orders_1.isRestingLimitOrder)(x
|
|
638
|
+
this.signedMsgGenerator(orderLists.signedMsg.ask, (x) => !(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
|
|
591
639
|
];
|
|
592
640
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
|
|
593
|
-
return bestNode.
|
|
641
|
+
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
594
642
|
}, filterFcn);
|
|
595
643
|
}
|
|
596
644
|
*signedMsgGenerator(signedMsgOrderList, filter) {
|
|
@@ -646,19 +694,19 @@ class DLOB {
|
|
|
646
694
|
}
|
|
647
695
|
this.updateRestingLimitOrders(slot);
|
|
648
696
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
649
|
-
const nodeLists = this.
|
|
697
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
650
698
|
if (!nodeLists) {
|
|
651
699
|
return;
|
|
652
700
|
}
|
|
653
701
|
const generatorList = [
|
|
654
702
|
nodeLists.restingLimit.ask.getGenerator(),
|
|
655
703
|
nodeLists.floatingLimit.ask.getGenerator(),
|
|
656
|
-
this.signedMsgGenerator(nodeLists.signedMsg.ask, (x) => (0, orders_1.isRestingLimitOrder)(x
|
|
704
|
+
this.signedMsgGenerator(nodeLists.signedMsg.ask, (x) => (0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
|
|
657
705
|
];
|
|
658
706
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
659
707
|
return bestNode
|
|
660
|
-
.
|
|
661
|
-
.lt(currentNode.
|
|
708
|
+
.getPriceOrThrow(oraclePriceData, slot)
|
|
709
|
+
.lt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
662
710
|
}, filterFcn);
|
|
663
711
|
}
|
|
664
712
|
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
|
|
@@ -667,19 +715,19 @@ class DLOB {
|
|
|
667
715
|
}
|
|
668
716
|
this.updateRestingLimitOrders(slot);
|
|
669
717
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
670
|
-
const nodeLists = this.
|
|
718
|
+
const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
|
|
671
719
|
if (!nodeLists) {
|
|
672
720
|
return;
|
|
673
721
|
}
|
|
674
722
|
const generatorList = [
|
|
675
723
|
nodeLists.restingLimit.bid.getGenerator(),
|
|
676
724
|
nodeLists.floatingLimit.bid.getGenerator(),
|
|
677
|
-
this.signedMsgGenerator(nodeLists.signedMsg.bid, (x) => (0, orders_1.isRestingLimitOrder)(x
|
|
725
|
+
this.signedMsgGenerator(nodeLists.signedMsg.bid, (x) => (0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
|
|
678
726
|
];
|
|
679
727
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
|
|
680
728
|
return bestNode
|
|
681
|
-
.
|
|
682
|
-
.gt(currentNode.
|
|
729
|
+
.getPriceOrThrow(oraclePriceData, slot)
|
|
730
|
+
.gt(currentNode.getPriceOrThrow(oraclePriceData, slot));
|
|
683
731
|
}, filterFcn);
|
|
684
732
|
}
|
|
685
733
|
/**
|
|
@@ -704,7 +752,7 @@ class DLOB {
|
|
|
704
752
|
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO;
|
|
705
753
|
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.ZERO;
|
|
706
754
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
707
|
-
return bestNode.
|
|
755
|
+
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
708
756
|
}
|
|
709
757
|
return bestNodePrice.lt(currentNodePrice);
|
|
710
758
|
}, filterFcn);
|
|
@@ -731,7 +779,7 @@ class DLOB {
|
|
|
731
779
|
const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.BN_MAX;
|
|
732
780
|
const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.BN_MAX;
|
|
733
781
|
if (bestNodePrice.eq(currentNodePrice)) {
|
|
734
|
-
return bestNode.
|
|
782
|
+
return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
|
|
735
783
|
}
|
|
736
784
|
return bestNodePrice.gt(currentNodePrice);
|
|
737
785
|
}, filterFcn);
|
|
@@ -741,14 +789,14 @@ class DLOB {
|
|
|
741
789
|
for (const askNode of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)) {
|
|
742
790
|
const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
743
791
|
for (const bidNode of bidGenerator) {
|
|
744
|
-
const bidPrice = bidNode.
|
|
745
|
-
const askPrice = askNode.
|
|
792
|
+
const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot);
|
|
793
|
+
const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot);
|
|
746
794
|
// orders don't cross
|
|
747
795
|
if (bidPrice.lt(askPrice)) {
|
|
748
796
|
break;
|
|
749
797
|
}
|
|
750
|
-
const bidOrder = bidNode
|
|
751
|
-
const askOrder = askNode
|
|
798
|
+
const bidOrder = getOrderOrThrow(bidNode);
|
|
799
|
+
const askOrder = getOrderOrThrow(askNode);
|
|
752
800
|
// Can't match orders from the same user
|
|
753
801
|
const sameUser = bidNode.userAccount === askNode.userAccount;
|
|
754
802
|
if (sameUser) {
|
|
@@ -766,12 +814,12 @@ class DLOB {
|
|
|
766
814
|
const newBidOrder = { ...bidOrder };
|
|
767
815
|
newBidOrder.baseAssetAmountFilled =
|
|
768
816
|
bidOrder.baseAssetAmountFilled.add(baseFilled);
|
|
769
|
-
this.
|
|
817
|
+
this.getListForOnChainOrderOrThrow(newBidOrder, slot).update(newBidOrder, getUserAccountOrThrow(bidNode));
|
|
770
818
|
// ask completely filled
|
|
771
819
|
const newAskOrder = { ...askOrder };
|
|
772
820
|
newAskOrder.baseAssetAmountFilled =
|
|
773
821
|
askOrder.baseAssetAmountFilled.add(baseFilled);
|
|
774
|
-
this.
|
|
822
|
+
this.getListForOnChainOrderOrThrow(newAskOrder, slot).update(newAskOrder, getUserAccountOrThrow(askNode));
|
|
775
823
|
nodesToFill.push({
|
|
776
824
|
node: takerNode,
|
|
777
825
|
makerNodes: [makerNode],
|
|
@@ -784,18 +832,20 @@ class DLOB {
|
|
|
784
832
|
return nodesToFill;
|
|
785
833
|
}
|
|
786
834
|
determineMakerAndTaker(askNode, bidNode) {
|
|
787
|
-
const
|
|
788
|
-
const
|
|
789
|
-
|
|
835
|
+
const askOrder = getOrderOrThrow(askNode);
|
|
836
|
+
const bidOrder = getOrderOrThrow(bidNode);
|
|
837
|
+
const askSlot = askOrder.slot.add(new anchor_1.BN(askOrder.auctionDuration));
|
|
838
|
+
const bidSlot = bidOrder.slot.add(new anchor_1.BN(bidOrder.auctionDuration));
|
|
839
|
+
if (bidOrder.postOnly && askOrder.postOnly) {
|
|
790
840
|
return undefined;
|
|
791
841
|
}
|
|
792
|
-
else if (
|
|
842
|
+
else if (bidOrder.postOnly) {
|
|
793
843
|
return {
|
|
794
844
|
takerNode: askNode,
|
|
795
845
|
makerNode: bidNode,
|
|
796
846
|
};
|
|
797
847
|
}
|
|
798
|
-
else if (
|
|
848
|
+
else if (askOrder.postOnly) {
|
|
799
849
|
return {
|
|
800
850
|
takerNode: bidNode,
|
|
801
851
|
makerNode: askNode,
|
|
@@ -830,17 +880,17 @@ class DLOB {
|
|
|
830
880
|
}
|
|
831
881
|
*getStopLosses(marketIndex, marketType, direction) {
|
|
832
882
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
833
|
-
const marketNodeLists = this.
|
|
883
|
+
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
834
884
|
if ((0, types_1.isVariant)(direction, 'long') && marketNodeLists.trigger.below) {
|
|
835
885
|
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
836
|
-
if ((0, types_1.isVariant)(node.
|
|
886
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'short')) {
|
|
837
887
|
yield node;
|
|
838
888
|
}
|
|
839
889
|
}
|
|
840
890
|
}
|
|
841
891
|
else if ((0, types_1.isVariant)(direction, 'short') && marketNodeLists.trigger.above) {
|
|
842
892
|
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
843
|
-
if ((0, types_1.isVariant)(node.
|
|
893
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'long')) {
|
|
844
894
|
yield node;
|
|
845
895
|
}
|
|
846
896
|
}
|
|
@@ -848,31 +898,31 @@ class DLOB {
|
|
|
848
898
|
}
|
|
849
899
|
*getStopLossMarkets(marketIndex, marketType, direction) {
|
|
850
900
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
851
|
-
if ((0, types_1.isVariant)(node.
|
|
901
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
852
902
|
yield node;
|
|
853
903
|
}
|
|
854
904
|
}
|
|
855
905
|
}
|
|
856
906
|
*getStopLossLimits(marketIndex, marketType, direction) {
|
|
857
907
|
for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
|
|
858
|
-
if ((0, types_1.isVariant)(node.
|
|
908
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
859
909
|
yield node;
|
|
860
910
|
}
|
|
861
911
|
}
|
|
862
912
|
}
|
|
863
913
|
*getTakeProfits(marketIndex, marketType, direction) {
|
|
864
914
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
865
|
-
const marketNodeLists = this.
|
|
915
|
+
const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
|
|
866
916
|
if ((0, types_1.isVariant)(direction, 'long') && marketNodeLists.trigger.above) {
|
|
867
917
|
for (const node of marketNodeLists.trigger.above.getGenerator()) {
|
|
868
|
-
if ((0, types_1.isVariant)(node.
|
|
918
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'short')) {
|
|
869
919
|
yield node;
|
|
870
920
|
}
|
|
871
921
|
}
|
|
872
922
|
}
|
|
873
923
|
else if ((0, types_1.isVariant)(direction, 'short') && marketNodeLists.trigger.below) {
|
|
874
924
|
for (const node of marketNodeLists.trigger.below.getGenerator()) {
|
|
875
|
-
if ((0, types_1.isVariant)(node.
|
|
925
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'long')) {
|
|
876
926
|
yield node;
|
|
877
927
|
}
|
|
878
928
|
}
|
|
@@ -880,30 +930,32 @@ class DLOB {
|
|
|
880
930
|
}
|
|
881
931
|
*getTakeProfitMarkets(marketIndex, marketType, direction) {
|
|
882
932
|
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
883
|
-
if ((0, types_1.isVariant)(node.
|
|
933
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
|
|
884
934
|
yield node;
|
|
885
935
|
}
|
|
886
936
|
}
|
|
887
937
|
}
|
|
888
938
|
*getTakeProfitLimits(marketIndex, marketType, direction) {
|
|
889
939
|
for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
|
|
890
|
-
if ((0, types_1.isVariant)(node.
|
|
940
|
+
if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
|
|
891
941
|
yield node;
|
|
892
942
|
}
|
|
893
943
|
}
|
|
894
944
|
}
|
|
895
945
|
findNodesToTrigger(marketIndex, slot, triggerPrice, marketType, stateAccount) {
|
|
946
|
+
var _a;
|
|
896
947
|
if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
|
|
897
948
|
return [];
|
|
898
949
|
}
|
|
899
950
|
const nodesToTrigger = [];
|
|
900
951
|
const marketTypeStr = (0, types_1.getVariant)(marketType);
|
|
901
|
-
const marketNodeLists = this.orderLists
|
|
952
|
+
const marketNodeLists = (_a = this.orderLists
|
|
953
|
+
.get(marketTypeStr)) === null || _a === void 0 ? void 0 : _a.get(marketIndex);
|
|
902
954
|
const triggerAboveList = marketNodeLists
|
|
903
955
|
? marketNodeLists.trigger.above
|
|
904
956
|
: undefined;
|
|
905
957
|
if (triggerAboveList) {
|
|
906
|
-
for (
|
|
958
|
+
for (let node = triggerAboveList.head; node !== undefined; node = node.next) {
|
|
907
959
|
if (triggerPrice.gt(node.order.triggerPrice)) {
|
|
908
960
|
nodesToTrigger.push({
|
|
909
961
|
node: node,
|
|
@@ -918,7 +970,7 @@ class DLOB {
|
|
|
918
970
|
? marketNodeLists.trigger.below
|
|
919
971
|
: undefined;
|
|
920
972
|
if (triggerBelowList) {
|
|
921
|
-
for (
|
|
973
|
+
for (let node = triggerBelowList.head; node !== undefined; node = node.next) {
|
|
922
974
|
if (triggerPrice.lt(node.order.triggerPrice)) {
|
|
923
975
|
nodesToTrigger.push({
|
|
924
976
|
node: node,
|
|
@@ -931,12 +983,15 @@ class DLOB {
|
|
|
931
983
|
}
|
|
932
984
|
return nodesToTrigger;
|
|
933
985
|
}
|
|
934
|
-
printTop(
|
|
986
|
+
printTop(velocityClient, slotSubscriber, marketIndex, marketType) {
|
|
935
987
|
if ((0, types_1.isVariant)(marketType, 'perp')) {
|
|
936
988
|
const slot = slotSubscriber.getSlot();
|
|
937
|
-
const oraclePriceData =
|
|
989
|
+
const oraclePriceData = velocityClient.getMMOracleDataForPerpMarket(marketIndex);
|
|
938
990
|
const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
|
|
939
991
|
const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
|
|
992
|
+
if (bestAsk === undefined || bestBid === undefined) {
|
|
993
|
+
throw new Error(`printTop requires both a best ask and best bid for market ${marketIndex}`);
|
|
994
|
+
}
|
|
940
995
|
const mid = bestAsk.add(bestBid).div(new anchor_1.BN(2));
|
|
941
996
|
const bidSpread = ((0, conversion_1.convertToNumber)(bestBid, numericConstants_1.PRICE_PRECISION) /
|
|
942
997
|
(0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
|
|
@@ -946,7 +1001,7 @@ class DLOB {
|
|
|
946
1001
|
(0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
|
|
947
1002
|
1) *
|
|
948
1003
|
100.0;
|
|
949
|
-
const name = (0, userName_1.decodeName)(
|
|
1004
|
+
const name = (0, userName_1.decodeName)(velocityClient.getPerpMarketAccountOrThrow(marketIndex).name);
|
|
950
1005
|
console.log(`Market ${name} Orders`);
|
|
951
1006
|
console.log(` Ask`, (0, conversion_1.convertToNumber)(bestAsk, numericConstants_1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
952
1007
|
console.log(` Mid`, (0, conversion_1.convertToNumber)(mid, numericConstants_1.PRICE_PRECISION).toFixed(3));
|
|
@@ -954,9 +1009,12 @@ class DLOB {
|
|
|
954
1009
|
}
|
|
955
1010
|
else if ((0, types_1.isVariant)(marketType, 'spot')) {
|
|
956
1011
|
const slot = slotSubscriber.getSlot();
|
|
957
|
-
const oraclePriceData =
|
|
1012
|
+
const oraclePriceData = velocityClient.getOracleDataForSpotMarket(marketIndex);
|
|
958
1013
|
const bestAsk = this.getBestAsk(marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
|
|
959
1014
|
const bestBid = this.getBestBid(marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
|
|
1015
|
+
if (bestAsk === undefined || bestBid === undefined) {
|
|
1016
|
+
throw new Error(`printTop requires both a best ask and best bid for market ${marketIndex}`);
|
|
1017
|
+
}
|
|
960
1018
|
const mid = bestAsk.add(bestBid).div(new anchor_1.BN(2));
|
|
961
1019
|
const bidSpread = ((0, conversion_1.convertToNumber)(bestBid, numericConstants_1.PRICE_PRECISION) /
|
|
962
1020
|
(0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
|
|
@@ -966,7 +1024,7 @@ class DLOB {
|
|
|
966
1024
|
(0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
|
|
967
1025
|
1) *
|
|
968
1026
|
100.0;
|
|
969
|
-
const name = (0, userName_1.decodeName)(
|
|
1027
|
+
const name = (0, userName_1.decodeName)(velocityClient.getSpotMarketAccountOrThrow(marketIndex).name);
|
|
970
1028
|
console.log(`Market ${name} Orders`);
|
|
971
1029
|
console.log(` Ask`, (0, conversion_1.convertToNumber)(bestAsk, numericConstants_1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
972
1030
|
console.log(` Mid`, (0, conversion_1.convertToNumber)(mid, numericConstants_1.PRICE_PRECISION).toFixed(3));
|
|
@@ -978,15 +1036,15 @@ class DLOB {
|
|
|
978
1036
|
for (const nodeList of this.getNodeLists()) {
|
|
979
1037
|
for (const node of nodeList.getGenerator()) {
|
|
980
1038
|
dlobOrders.push({
|
|
981
|
-
user: new web3_js_1.PublicKey(node
|
|
982
|
-
order: node
|
|
1039
|
+
user: new web3_js_1.PublicKey(getUserAccountOrThrow(node)),
|
|
1040
|
+
order: getOrderOrThrow(node),
|
|
983
1041
|
});
|
|
984
1042
|
}
|
|
985
1043
|
}
|
|
986
1044
|
return dlobOrders;
|
|
987
1045
|
}
|
|
988
1046
|
*getNodeLists() {
|
|
989
|
-
for (const [_, nodeLists] of this.
|
|
1047
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType('perp')) {
|
|
990
1048
|
yield nodeLists.restingLimit.bid;
|
|
991
1049
|
yield nodeLists.restingLimit.ask;
|
|
992
1050
|
yield nodeLists.takingLimit.bid;
|
|
@@ -998,7 +1056,7 @@ class DLOB {
|
|
|
998
1056
|
yield nodeLists.trigger.above;
|
|
999
1057
|
yield nodeLists.trigger.below;
|
|
1000
1058
|
}
|
|
1001
|
-
for (const [_, nodeLists] of this.
|
|
1059
|
+
for (const [_, nodeLists] of this.getOrderListsForMarketType('spot')) {
|
|
1002
1060
|
yield nodeLists.restingLimit.bid;
|
|
1003
1061
|
yield nodeLists.restingLimit.ask;
|
|
1004
1062
|
yield nodeLists.takingLimit.bid;
|
|
@@ -1057,20 +1115,22 @@ class DLOB {
|
|
|
1057
1115
|
const asks = [];
|
|
1058
1116
|
const restingAsks = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1059
1117
|
for (const ask of restingAsks) {
|
|
1118
|
+
const askOrder = getOrderOrThrow(ask);
|
|
1060
1119
|
asks.push({
|
|
1061
|
-
price: ask.
|
|
1062
|
-
size:
|
|
1063
|
-
maker: new web3_js_1.PublicKey(ask
|
|
1064
|
-
orderId:
|
|
1120
|
+
price: ask.getPriceOrThrow(oraclePriceData, slot),
|
|
1121
|
+
size: askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled),
|
|
1122
|
+
maker: new web3_js_1.PublicKey(getUserAccountOrThrow(ask)),
|
|
1123
|
+
orderId: askOrder.orderId,
|
|
1065
1124
|
});
|
|
1066
1125
|
}
|
|
1067
1126
|
const restingBids = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
|
|
1068
1127
|
for (const bid of restingBids) {
|
|
1128
|
+
const bidOrder = getOrderOrThrow(bid);
|
|
1069
1129
|
bids.push({
|
|
1070
|
-
price: bid.
|
|
1071
|
-
size:
|
|
1072
|
-
maker: new web3_js_1.PublicKey(bid
|
|
1073
|
-
orderId:
|
|
1130
|
+
price: bid.getPriceOrThrow(oraclePriceData, slot),
|
|
1131
|
+
size: bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled),
|
|
1132
|
+
maker: new web3_js_1.PublicKey(getUserAccountOrThrow(bid)),
|
|
1133
|
+
orderId: bidOrder.orderId,
|
|
1074
1134
|
});
|
|
1075
1135
|
}
|
|
1076
1136
|
return {
|
|
@@ -1083,8 +1143,9 @@ class DLOB {
|
|
|
1083
1143
|
let runningSumQuote = numericConstants_1.ZERO;
|
|
1084
1144
|
let runningSumBase = numericConstants_1.ZERO;
|
|
1085
1145
|
for (const side of dlobSide) {
|
|
1086
|
-
const price = side.
|
|
1087
|
-
const
|
|
1146
|
+
const price = side.getPriceOrThrow(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
|
|
1147
|
+
const sideOrder = getOrderOrThrow(side);
|
|
1148
|
+
const baseAmountRemaining = sideOrder.baseAssetAmount.sub(sideOrder.baseAssetAmountFilled);
|
|
1088
1149
|
if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
|
|
1089
1150
|
const remainingBase = baseAmountIn.sub(runningSumBase);
|
|
1090
1151
|
runningSumBase = runningSumBase.add(remainingBase);
|
|
@@ -1117,6 +1178,7 @@ class DLOB {
|
|
|
1117
1178
|
else if ((0, types_1.isVariant)(orderDirection, 'short')) {
|
|
1118
1179
|
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData));
|
|
1119
1180
|
}
|
|
1181
|
+
throw new Error(`Invalid order direction ${(0, types_1.getVariant)(orderDirection)}: must be long or short`);
|
|
1120
1182
|
}
|
|
1121
1183
|
getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, }) {
|
|
1122
1184
|
const makers = new Map();
|
|
@@ -1124,8 +1186,9 @@ class DLOB {
|
|
|
1124
1186
|
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
1125
1187
|
: this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1126
1188
|
for (const node of generator) {
|
|
1127
|
-
|
|
1128
|
-
|
|
1189
|
+
const userAccount = getUserAccountOrThrow(node);
|
|
1190
|
+
if (!makers.has(userAccount)) {
|
|
1191
|
+
makers.set(userAccount, new web3_js_1.PublicKey(userAccount));
|
|
1129
1192
|
}
|
|
1130
1193
|
if (makers.size === numMakers) {
|
|
1131
1194
|
break;
|