@velocity-exchange/sdk 0.1.0 → 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/CHANGELOG.md +15 -0
- package/bun.lock +23 -1
- 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 -28
- 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 +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 +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 -3
- package/lib/browser/constants/numericConstants.js +3 -5
- 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/instructions/perpOrders.d.ts +14 -0
- package/lib/browser/core/instructions/perpOrders.js +14 -0
- 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 -1
- package/lib/browser/dlob/DLOB.js +201 -138
- package/lib/browser/dlob/DLOBNode.d.ts +5 -2
- package/lib/browser/dlob/DLOBNode.js +7 -0
- package/lib/browser/dlob/DLOBSubscriber.js +37 -32
- package/lib/browser/dlob/NodeList.js +8 -7
- package/lib/browser/dlob/orderBookLevels.js +19 -12
- 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 +1 -1
- 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 +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 +2 -4
- package/lib/browser/events/types.js +0 -2
- 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/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/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 +77 -22
- package/lib/browser/math/bankruptcy.js +1 -1
- package/lib/browser/math/funding.js +6 -6
- package/lib/browser/math/insurance.d.ts +1 -1
- package/lib/browser/math/insurance.js +4 -5
- package/lib/browser/math/margin.d.ts +1 -9
- package/lib/browser/math/margin.js +3 -62
- package/lib/browser/math/market.d.ts +4 -12
- package/lib/browser/math/market.js +6 -40
- package/lib/browser/math/oracles.d.ts +0 -3
- package/lib/browser/math/oracles.js +1 -14
- package/lib/browser/math/orders.d.ts +0 -5
- package/lib/browser/math/orders.js +2 -74
- package/lib/browser/math/position.d.ts +0 -4
- package/lib/browser/math/position.js +5 -10
- 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 +3 -53
- package/lib/browser/math/superStake.js +16 -13
- package/lib/browser/math/trade.js +6 -6
- 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 +3 -2
- 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 -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/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/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 +27 -70
- package/lib/browser/types.js +2 -2
- package/lib/browser/user.d.ts +21 -7
- 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 +92 -34
- 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 -28
- 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 +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 +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 -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.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/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/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 -1
- 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 -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.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +37 -32
- 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 +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.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/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 +77 -22
- package/lib/node/math/bankruptcy.js +1 -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 -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 +1 -9
- 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 -12
- 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 -3
- 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 -5
- 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 -5
- 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 -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 +3 -53
- 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 -2
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +6 -6
- 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 +3 -2
- 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 -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/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/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 -68
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +2 -2
- package/lib/node/user.d.ts +21 -7
- 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 -35
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +414 -280
- package/package.json +5 -3
- 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 +83 -39
- 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 +3 -3
- 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/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 +13 -9
- package/src/userMap/revenueShareEscrowMap.ts +6 -1
- 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/amm/test.ts +138 -0
- package/tests/dlob/helpers.ts +6 -1
- 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/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/src/constants/insuranceFund.ts +0 -8
- package/src/tx/forwardOnlyTxSender.ts +0 -145
- package/src/util/tps.ts +0 -27
|
@@ -66,8 +66,10 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
66
66
|
delistedMarketSetting: DelistedMarketSetting;
|
|
67
67
|
|
|
68
68
|
private isSubscribing = false;
|
|
69
|
-
private
|
|
70
|
-
private
|
|
69
|
+
private subscriptionPromiseResolver: (val: boolean) => void = () => {};
|
|
70
|
+
private subscriptionPromise: Promise<boolean> = new Promise((res) => {
|
|
71
|
+
this.subscriptionPromiseResolver = res;
|
|
72
|
+
});
|
|
71
73
|
|
|
72
74
|
public constructor(
|
|
73
75
|
program: VelocityProgram,
|
|
@@ -249,6 +251,38 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
249
251
|
});
|
|
250
252
|
}
|
|
251
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Routes a freshly-decoded account into the correct container based on
|
|
256
|
+
* its poll key. Replaces dynamic `this[key]` indexing with explicit,
|
|
257
|
+
* type-checked dispatch.
|
|
258
|
+
*/
|
|
259
|
+
private storeDecodedAccount(
|
|
260
|
+
accountToPoll: AccountToPoll,
|
|
261
|
+
account: any,
|
|
262
|
+
slot: number
|
|
263
|
+
): void {
|
|
264
|
+
const dataAndSlot = { data: account, slot };
|
|
265
|
+
switch (accountToPoll.key) {
|
|
266
|
+
case 'perpMarket':
|
|
267
|
+
if (accountToPoll.mapKey !== undefined) {
|
|
268
|
+
this.perpMarket.set(accountToPoll.mapKey, dataAndSlot);
|
|
269
|
+
}
|
|
270
|
+
break;
|
|
271
|
+
case 'spotMarket':
|
|
272
|
+
if (accountToPoll.mapKey !== undefined) {
|
|
273
|
+
this.spotMarket.set(accountToPoll.mapKey, dataAndSlot);
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
case 'state':
|
|
277
|
+
this.state = dataAndSlot;
|
|
278
|
+
break;
|
|
279
|
+
default: {
|
|
280
|
+
const _exhaustive: never = accountToPoll.key;
|
|
281
|
+
throw new Error(`Unhandled account poll key: ${String(_exhaustive)}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
252
286
|
async addAccountToAccountLoader(accountToPoll: AccountToPoll): Promise<void> {
|
|
253
287
|
accountToPoll.callbackId = await this.accountLoader.addAccount(
|
|
254
288
|
accountToPoll.publicKey,
|
|
@@ -259,15 +293,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
259
293
|
accountToPoll.key,
|
|
260
294
|
buffer
|
|
261
295
|
);
|
|
262
|
-
|
|
263
|
-
data: account,
|
|
264
|
-
slot,
|
|
265
|
-
};
|
|
266
|
-
if (accountToPoll.mapKey != undefined) {
|
|
267
|
-
this[accountToPoll.key].set(accountToPoll.mapKey, dataAndSlot);
|
|
268
|
-
} else {
|
|
269
|
-
this[accountToPoll.key] = dataAndSlot;
|
|
270
|
-
}
|
|
296
|
+
this.storeDecodedAccount(accountToPoll, account, slot);
|
|
271
297
|
|
|
272
298
|
// @ts-ignore
|
|
273
299
|
this.eventEmitter.emit(accountToPoll.eventType, account);
|
|
@@ -293,6 +319,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
293
319
|
oracleToPoll.publicKey,
|
|
294
320
|
(buffer: Buffer, slot: number) => {
|
|
295
321
|
if (!buffer) return;
|
|
322
|
+
if (!oracleClient) return;
|
|
296
323
|
|
|
297
324
|
const oraclePriceData =
|
|
298
325
|
oracleClient.getOraclePriceDataFromBuffer(buffer);
|
|
@@ -332,17 +359,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
332
359
|
accountToPoll.key,
|
|
333
360
|
buffer
|
|
334
361
|
);
|
|
335
|
-
|
|
336
|
-
this[accountToPoll.key].set(accountToPoll.mapKey, {
|
|
337
|
-
data: account,
|
|
338
|
-
slot,
|
|
339
|
-
});
|
|
340
|
-
} else {
|
|
341
|
-
this[accountToPoll.key] = {
|
|
342
|
-
data: account,
|
|
343
|
-
slot,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
362
|
+
this.storeDecodedAccount(accountToPoll, account, slot);
|
|
346
363
|
}
|
|
347
364
|
}
|
|
348
365
|
|
|
@@ -363,6 +380,9 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
363
380
|
this.program.provider.connection,
|
|
364
381
|
this.program
|
|
365
382
|
);
|
|
383
|
+
if (!oracleClient) {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
366
386
|
const oraclePriceData =
|
|
367
387
|
oracleClient.getOraclePriceDataFromBuffer(buffer);
|
|
368
388
|
this.oracles.set(
|
|
@@ -418,6 +438,9 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
418
438
|
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
419
439
|
|
|
420
440
|
const accountToPoll = this.accountsToPoll.get(marketPublicKey.toString());
|
|
441
|
+
if (!accountToPoll) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
421
444
|
|
|
422
445
|
await this.addAccountToAccountLoader(accountToPoll);
|
|
423
446
|
this.setSpotOracleMap();
|
|
@@ -436,6 +459,9 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
436
459
|
|
|
437
460
|
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
438
461
|
const accountToPoll = this.accountsToPoll.get(marketPublicKey.toString());
|
|
462
|
+
if (!accountToPoll) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
439
465
|
await this.addAccountToAccountLoader(accountToPoll);
|
|
440
466
|
await this.setPerpOracleMap();
|
|
441
467
|
return true;
|
|
@@ -455,7 +481,9 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
455
481
|
if (!this.oraclesToPoll.has(oracleId)) {
|
|
456
482
|
this.addOracleToPoll(oracleInfo);
|
|
457
483
|
const oracleToPoll = this.oraclesToPoll.get(oracleId);
|
|
458
|
-
|
|
484
|
+
if (oracleToPoll) {
|
|
485
|
+
await this.addOracleToAccountLoader(oracleToPoll);
|
|
486
|
+
}
|
|
459
487
|
}
|
|
460
488
|
|
|
461
489
|
await this.pauseForOracleToBeAdded(3, oracleInfo.publicKey.toBase58());
|
|
@@ -535,10 +563,22 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
535
563
|
);
|
|
536
564
|
|
|
537
565
|
for (const perpMarketIndex of perpMarketIndexes) {
|
|
538
|
-
const
|
|
539
|
-
|
|
566
|
+
const perpMarketData = this.perpMarket.get(perpMarketIndex);
|
|
567
|
+
if (!perpMarketData) {
|
|
568
|
+
throw new Error(
|
|
569
|
+
`PollingVelocityClientAccountSubscriber: delisted perp market ${perpMarketIndex} not found in perpMarket map`
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
const perpMarketPubkey = perpMarketData.data.pubkey;
|
|
573
|
+
const accountToPoll = this.accountsToPoll.get(
|
|
540
574
|
perpMarketPubkey.toBase58()
|
|
541
|
-
)
|
|
575
|
+
);
|
|
576
|
+
if (!accountToPoll) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
`PollingVelocityClientAccountSubscriber: delisted perp market ${perpMarketIndex} not found in accountsToPoll map`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
const callbackId = accountToPoll.callbackId;
|
|
542
582
|
this.accountLoader.removeAccount(perpMarketPubkey, callbackId);
|
|
543
583
|
if (this.delistedMarketSetting === DelistedMarketSetting.Discard) {
|
|
544
584
|
this.perpMarket.delete(perpMarketIndex);
|
|
@@ -547,7 +587,13 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
547
587
|
|
|
548
588
|
for (const oracle of oracles) {
|
|
549
589
|
const oracleId = getOracleId(oracle.publicKey, oracle.source);
|
|
550
|
-
const
|
|
590
|
+
const oracleToPoll = this.oraclesToPoll.get(oracleId);
|
|
591
|
+
if (!oracleToPoll) {
|
|
592
|
+
throw new Error(
|
|
593
|
+
`PollingVelocityClientAccountSubscriber: delisted oracle ${oracleId} not found in oraclesToPoll map`
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
const callbackId = oracleToPoll.callbackId;
|
|
551
597
|
this.accountLoader.removeAccount(oracle.publicKey, callbackId);
|
|
552
598
|
if (this.delistedMarketSetting === DelistedMarketSetting.Discard) {
|
|
553
599
|
this.oracles.delete(oracleId);
|
|
@@ -565,7 +611,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
565
611
|
|
|
566
612
|
public getStateAccountAndSlot(): DataAndSlot<StateAccount> {
|
|
567
613
|
this.assertIsSubscribed();
|
|
568
|
-
return this.state
|
|
614
|
+
return this.state!;
|
|
569
615
|
}
|
|
570
616
|
|
|
571
617
|
public getMarketAccountAndSlot(
|
|
@@ -609,7 +655,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
609
655
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
610
656
|
const oracleId = this.perpOracleStringMap.get(marketIndex);
|
|
611
657
|
|
|
612
|
-
if (!perpMarketAccount || !oracle) {
|
|
658
|
+
if (!perpMarketAccount || !oracle || !oracleId) {
|
|
613
659
|
return undefined;
|
|
614
660
|
}
|
|
615
661
|
|
|
@@ -627,7 +673,7 @@ export class PollingVelocityClientAccountSubscriber
|
|
|
627
673
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
628
674
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
629
675
|
const oracleId = this.spotOracleStringMap.get(marketIndex);
|
|
630
|
-
if (!spotMarketAccount || !oracle) {
|
|
676
|
+
if (!spotMarketAccount || !oracle || !oracleId) {
|
|
631
677
|
return undefined;
|
|
632
678
|
}
|
|
633
679
|
|
package/src/accounts/types.ts
CHANGED
|
@@ -128,7 +128,7 @@ export interface UserAccountSubscriber {
|
|
|
128
128
|
updateData(userAccount: UserAccount, slot: number): void;
|
|
129
129
|
unsubscribe(): Promise<void>;
|
|
130
130
|
|
|
131
|
-
getUserAccountAndSlot(): DataAndSlot<UserAccount
|
|
131
|
+
getUserAccountAndSlot(): DataAndSlot<UserAccount> | undefined;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export interface TokenAccountEvents {
|
|
@@ -159,7 +159,9 @@ export interface InsuranceFundStakeAccountSubscriber {
|
|
|
159
159
|
fetch(): Promise<void>;
|
|
160
160
|
unsubscribe(): Promise<void>;
|
|
161
161
|
|
|
162
|
-
getInsuranceFundStakeAccountAndSlot():
|
|
162
|
+
getInsuranceFundStakeAccountAndSlot():
|
|
163
|
+
| DataAndSlot<InsuranceFundStake>
|
|
164
|
+
| undefined;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
export interface InsuranceFundStakeAccountEvents {
|
|
@@ -186,7 +188,7 @@ export interface OracleAccountSubscriber {
|
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
export type AccountToPoll = {
|
|
189
|
-
key:
|
|
191
|
+
key: 'state' | 'perpMarket' | 'spotMarket';
|
|
190
192
|
publicKey: PublicKey;
|
|
191
193
|
eventType: string;
|
|
192
194
|
callbackId?: string;
|
|
@@ -231,7 +233,7 @@ export interface UserStatsAccountSubscriber {
|
|
|
231
233
|
fetch(): Promise<void>;
|
|
232
234
|
unsubscribe(): Promise<void>;
|
|
233
235
|
|
|
234
|
-
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount
|
|
236
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount> | undefined;
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
type BaseGrpcConfigs = {
|
package/src/accounts/utils.ts
CHANGED
|
@@ -7,6 +7,16 @@ export function capitalize(value: string): string {
|
|
|
7
7
|
return value[0].toUpperCase() + value.slice(1);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export function assertDataAndSlot<T>(
|
|
11
|
+
dataAndSlot: DataAndSlot<T> | undefined,
|
|
12
|
+
message: string
|
|
13
|
+
): DataAndSlot<T> {
|
|
14
|
+
if (!dataAndSlot) {
|
|
15
|
+
throw new Error(message);
|
|
16
|
+
}
|
|
17
|
+
return dataAndSlot;
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
export function findDelistedPerpMarketsAndOracles(
|
|
11
21
|
perpMarkets: DataAndSlot<PerpMarketAccount>[],
|
|
12
22
|
spotMarkets: DataAndSlot<SpotMarketAccount>[]
|
|
@@ -16,8 +16,17 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
16
16
|
logAccountName: string;
|
|
17
17
|
program: VelocityProgram;
|
|
18
18
|
accountPublicKey: PublicKey;
|
|
19
|
-
decodeBufferFn
|
|
20
|
-
|
|
19
|
+
decodeBufferFn?: (buffer: Buffer) => T;
|
|
20
|
+
private _onChange?: (data: T) => void;
|
|
21
|
+
get onChange(): (data: T) => void {
|
|
22
|
+
if (!this._onChange) {
|
|
23
|
+
throw new Error('onChange callback function must be set');
|
|
24
|
+
}
|
|
25
|
+
return this._onChange;
|
|
26
|
+
}
|
|
27
|
+
set onChange(onChange: (data: T) => void) {
|
|
28
|
+
this._onChange = onChange;
|
|
29
|
+
}
|
|
21
30
|
listenerId?: number;
|
|
22
31
|
|
|
23
32
|
resubOpts?: ResubOpts;
|
|
@@ -43,7 +52,10 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
43
52
|
this.accountPublicKey = accountPublicKey;
|
|
44
53
|
this.decodeBufferFn = decodeBuffer;
|
|
45
54
|
this.resubOpts = resubOpts;
|
|
46
|
-
if (
|
|
55
|
+
if (
|
|
56
|
+
this.resubOpts?.resubTimeoutMs != null &&
|
|
57
|
+
this.resubOpts.resubTimeoutMs < 1000
|
|
58
|
+
) {
|
|
47
59
|
console.log(
|
|
48
60
|
`resubTimeoutMs should be at least 1000ms to avoid spamming resub ${this.logAccountName}`
|
|
49
61
|
);
|
|
@@ -97,12 +109,12 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
97
109
|
|
|
98
110
|
this.dataAndSlot = {
|
|
99
111
|
data,
|
|
100
|
-
slot,
|
|
112
|
+
slot: newSlot,
|
|
101
113
|
};
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
protected setTimeout(): void {
|
|
105
|
-
if (!this.
|
|
117
|
+
if (!this._onChange) {
|
|
106
118
|
throw new Error('onChange callback function must be set');
|
|
107
119
|
}
|
|
108
120
|
this.timeoutId = setTimeout(
|
|
@@ -149,7 +161,10 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
149
161
|
this.accountPublicKey,
|
|
150
162
|
(this.program.provider as AnchorProvider).opts.commitment
|
|
151
163
|
);
|
|
152
|
-
this.handleRpcResponse(
|
|
164
|
+
this.handleRpcResponse(
|
|
165
|
+
rpcResponse.context,
|
|
166
|
+
rpcResponse?.value ?? undefined
|
|
167
|
+
);
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
handleRpcResponse(context: Context, accountInfo?: AccountInfo<Buffer>): void {
|
|
@@ -198,10 +213,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
198
213
|
if (this.decodeBufferFn) {
|
|
199
214
|
return this.decodeBufferFn(buffer);
|
|
200
215
|
} else {
|
|
201
|
-
return this.program.
|
|
202
|
-
this.accountName,
|
|
203
|
-
buffer
|
|
204
|
-
);
|
|
216
|
+
return this.program.coder.accounts.decode(this.accountName, buffer);
|
|
205
217
|
}
|
|
206
218
|
}
|
|
207
219
|
|
|
@@ -245,6 +257,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
245
257
|
return promise;
|
|
246
258
|
} else {
|
|
247
259
|
this.isUnsubscribing = false;
|
|
260
|
+
return Promise.resolve();
|
|
248
261
|
}
|
|
249
262
|
}
|
|
250
263
|
}
|
|
@@ -77,8 +77,17 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
77
77
|
logAccountName: string;
|
|
78
78
|
program: VelocityProgram;
|
|
79
79
|
accountPublicKey: PublicKey;
|
|
80
|
-
decodeBufferFn
|
|
81
|
-
|
|
80
|
+
decodeBufferFn?: (buffer: Buffer) => T;
|
|
81
|
+
private _onChange?: (data: T) => void;
|
|
82
|
+
get onChange(): (data: T) => void {
|
|
83
|
+
if (!this._onChange) {
|
|
84
|
+
throw new Error('onChange callback function must be set');
|
|
85
|
+
}
|
|
86
|
+
return this._onChange;
|
|
87
|
+
}
|
|
88
|
+
set onChange(onChange: (data: T) => void) {
|
|
89
|
+
this._onChange = onChange;
|
|
90
|
+
}
|
|
82
91
|
listenerId?: number;
|
|
83
92
|
|
|
84
93
|
resubOpts: ResubOpts;
|
|
@@ -131,7 +140,10 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
131
140
|
usePollingInsteadOfResub: true,
|
|
132
141
|
logResubMessages: false,
|
|
133
142
|
};
|
|
134
|
-
if (
|
|
143
|
+
if (
|
|
144
|
+
this.resubOpts.resubTimeoutMs != null &&
|
|
145
|
+
this.resubOpts.resubTimeoutMs < 1000
|
|
146
|
+
) {
|
|
135
147
|
console.log(
|
|
136
148
|
`resubTimeoutMs should be at least 1000ms to avoid spamming resub ${this.logAccountName}`
|
|
137
149
|
);
|
|
@@ -139,7 +151,7 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
139
151
|
this.receivingData = false;
|
|
140
152
|
if (
|
|
141
153
|
['recent', 'single', 'singleGossip', 'root', 'max'].includes(
|
|
142
|
-
(this.program.provider as AnchorProvider).opts.commitment
|
|
154
|
+
(this.program.provider as AnchorProvider).opts.commitment ?? ''
|
|
143
155
|
)
|
|
144
156
|
) {
|
|
145
157
|
console.warn(
|
|
@@ -264,7 +276,7 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
264
276
|
|
|
265
277
|
this.dataAndSlot = {
|
|
266
278
|
data,
|
|
267
|
-
slot,
|
|
279
|
+
slot: newSlot,
|
|
268
280
|
};
|
|
269
281
|
}
|
|
270
282
|
|
|
@@ -274,7 +286,7 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
274
286
|
* `resubOpts.resubTimeoutMs` and `receivingData` is true, trigger either
|
|
275
287
|
* a polling loop or a resubscribe depending on options.
|
|
276
288
|
*/
|
|
277
|
-
if (!this.
|
|
289
|
+
if (!this._onChange) {
|
|
278
290
|
throw new Error('onChange callback function must be set');
|
|
279
291
|
}
|
|
280
292
|
this.timeoutId = setTimeout(async () => {
|
|
@@ -411,7 +423,10 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
411
423
|
|
|
412
424
|
const accountInfo = rpcResponse.value;
|
|
413
425
|
|
|
414
|
-
this.handleRpcResponse(
|
|
426
|
+
this.handleRpcResponse(
|
|
427
|
+
{ slot: BigInt(context.slot) },
|
|
428
|
+
accountInfo ?? undefined
|
|
429
|
+
);
|
|
415
430
|
}
|
|
416
431
|
|
|
417
432
|
handleRpcResponse(
|
|
@@ -480,7 +495,7 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
|
|
|
480
495
|
if (this.decodeBufferFn) {
|
|
481
496
|
return this.decodeBufferFn(buffer);
|
|
482
497
|
} else {
|
|
483
|
-
return this.program.
|
|
498
|
+
return this.program.coder.accounts.decode(
|
|
484
499
|
capitalize(this.accountName),
|
|
485
500
|
buffer
|
|
486
501
|
);
|
|
@@ -25,7 +25,20 @@ export class WebSocketInsuranceFundStakeAccountSubscriber
|
|
|
25
25
|
>;
|
|
26
26
|
insuranceFundStakeAccountPublicKey: PublicKey;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
private _insuranceFundStakeDataAccountSubscriber?: AccountSubscriber<InsuranceFundStake>;
|
|
29
|
+
get insuranceFundStakeDataAccountSubscriber(): AccountSubscriber<InsuranceFundStake> {
|
|
30
|
+
if (!this._insuranceFundStakeDataAccountSubscriber) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'insuranceFundStakeDataAccountSubscriber accessed before subscribe()'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return this._insuranceFundStakeDataAccountSubscriber;
|
|
36
|
+
}
|
|
37
|
+
set insuranceFundStakeDataAccountSubscriber(
|
|
38
|
+
subscriber: AccountSubscriber<InsuranceFundStake>
|
|
39
|
+
) {
|
|
40
|
+
this._insuranceFundStakeDataAccountSubscriber = subscriber;
|
|
41
|
+
}
|
|
29
42
|
|
|
30
43
|
public constructor(
|
|
31
44
|
program: VelocityProgram,
|
|
@@ -103,7 +116,9 @@ export class WebSocketInsuranceFundStakeAccountSubscriber
|
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
|
|
106
|
-
public getInsuranceFundStakeAccountAndSlot():
|
|
119
|
+
public getInsuranceFundStakeAccountAndSlot():
|
|
120
|
+
| DataAndSlot<InsuranceFundStake>
|
|
121
|
+
| undefined {
|
|
107
122
|
this.assertIsSubscribed();
|
|
108
123
|
return this.insuranceFundStakeDataAccountSubscriber.dataAndSlot;
|
|
109
124
|
}
|
|
@@ -19,12 +19,33 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
19
19
|
bufferAndSlotMap: Map<string, BufferAndSlot> = new Map();
|
|
20
20
|
program: VelocityProgram;
|
|
21
21
|
decodeBuffer: (accountName: string, ix: Buffer) => T;
|
|
22
|
-
|
|
22
|
+
private _onChange?: (
|
|
23
23
|
accountId: PublicKey,
|
|
24
24
|
data: T,
|
|
25
25
|
context: Context,
|
|
26
26
|
buffer: Buffer
|
|
27
27
|
) => void;
|
|
28
|
+
get onChange(): (
|
|
29
|
+
accountId: PublicKey,
|
|
30
|
+
data: T,
|
|
31
|
+
context: Context,
|
|
32
|
+
buffer: Buffer
|
|
33
|
+
) => void {
|
|
34
|
+
if (!this._onChange) {
|
|
35
|
+
throw new Error('onChange callback function must be set');
|
|
36
|
+
}
|
|
37
|
+
return this._onChange;
|
|
38
|
+
}
|
|
39
|
+
set onChange(
|
|
40
|
+
onChange: (
|
|
41
|
+
accountId: PublicKey,
|
|
42
|
+
data: T,
|
|
43
|
+
context: Context,
|
|
44
|
+
buffer: Buffer
|
|
45
|
+
) => void
|
|
46
|
+
) {
|
|
47
|
+
this._onChange = onChange;
|
|
48
|
+
}
|
|
28
49
|
listenerId?: number;
|
|
29
50
|
resubOpts?: ResubOpts;
|
|
30
51
|
isUnsubscribing = false;
|
|
@@ -48,7 +69,10 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
48
69
|
this.program = program;
|
|
49
70
|
this.decodeBuffer = decodeBufferFn;
|
|
50
71
|
this.resubOpts = resubOpts;
|
|
51
|
-
if (
|
|
72
|
+
if (
|
|
73
|
+
this.resubOpts?.resubTimeoutMs != null &&
|
|
74
|
+
this.resubOpts.resubTimeoutMs < 1000
|
|
75
|
+
) {
|
|
52
76
|
console.log(
|
|
53
77
|
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
54
78
|
);
|
|
@@ -95,7 +119,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
95
119
|
}
|
|
96
120
|
|
|
97
121
|
protected setTimeout(): void {
|
|
98
|
-
if (!this.
|
|
122
|
+
if (!this._onChange) {
|
|
99
123
|
throw new Error('onChange callback function must be set');
|
|
100
124
|
}
|
|
101
125
|
this.timeoutId = setTimeout(
|
|
@@ -161,7 +185,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
161
185
|
}
|
|
162
186
|
|
|
163
187
|
unsubscribe(onResub = false): Promise<void> {
|
|
164
|
-
if (!onResub) {
|
|
188
|
+
if (!onResub && this.resubOpts) {
|
|
165
189
|
this.resubOpts.resubTimeoutMs = undefined;
|
|
166
190
|
}
|
|
167
191
|
this.isUnsubscribing = true;
|
|
@@ -178,6 +202,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
178
202
|
return promise;
|
|
179
203
|
} else {
|
|
180
204
|
this.isUnsubscribing = false;
|
|
205
|
+
return Promise.resolve();
|
|
181
206
|
}
|
|
182
207
|
}
|
|
183
208
|
}
|
|
@@ -101,12 +101,33 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
101
101
|
bufferAndSlotMap: Map<string, BufferAndSlot> = new Map();
|
|
102
102
|
program: VelocityProgram;
|
|
103
103
|
decodeBuffer: (accountName: string, ix: Buffer) => T;
|
|
104
|
-
|
|
104
|
+
private _onChange?: (
|
|
105
105
|
accountId: PublicKey,
|
|
106
106
|
data: T,
|
|
107
107
|
context: Context,
|
|
108
108
|
buffer: Buffer
|
|
109
109
|
) => void;
|
|
110
|
+
get onChange(): (
|
|
111
|
+
accountId: PublicKey,
|
|
112
|
+
data: T,
|
|
113
|
+
context: Context,
|
|
114
|
+
buffer: Buffer
|
|
115
|
+
) => void {
|
|
116
|
+
if (!this._onChange) {
|
|
117
|
+
throw new Error('onChange callback function must be set');
|
|
118
|
+
}
|
|
119
|
+
return this._onChange;
|
|
120
|
+
}
|
|
121
|
+
set onChange(
|
|
122
|
+
onChange: (
|
|
123
|
+
accountId: PublicKey,
|
|
124
|
+
data: T,
|
|
125
|
+
context: Context,
|
|
126
|
+
buffer: Buffer
|
|
127
|
+
) => void
|
|
128
|
+
) {
|
|
129
|
+
this._onChange = onChange;
|
|
130
|
+
}
|
|
110
131
|
listenerId?: number;
|
|
111
132
|
resubOpts: ResubOpts;
|
|
112
133
|
isUnsubscribing = false;
|
|
@@ -160,7 +181,10 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
160
181
|
usePollingInsteadOfResub: true,
|
|
161
182
|
logResubMessages: false,
|
|
162
183
|
};
|
|
163
|
-
if (
|
|
184
|
+
if (
|
|
185
|
+
this.resubOpts?.resubTimeoutMs !== undefined &&
|
|
186
|
+
this.resubOpts.resubTimeoutMs < 1000
|
|
187
|
+
) {
|
|
164
188
|
console.log(
|
|
165
189
|
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
166
190
|
);
|
|
@@ -319,7 +343,7 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
319
343
|
}
|
|
320
344
|
|
|
321
345
|
protected setTimeout(): void {
|
|
322
|
-
if (!this.
|
|
346
|
+
if (!this._onChange) {
|
|
323
347
|
throw new Error('onChange callback function must be set');
|
|
324
348
|
}
|
|
325
349
|
this.timeoutId = setTimeout(
|
|
@@ -389,7 +413,9 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
389
413
|
// If this account was being polled, stop polling it if the buffer has changed
|
|
390
414
|
if (
|
|
391
415
|
this.accountsCurrentlyPolling.has(accountIdString) &&
|
|
392
|
-
|
|
416
|
+
newBuffer &&
|
|
417
|
+
(!existingBufferAndSlot?.buffer ||
|
|
418
|
+
!newBuffer.equals(existingBufferAndSlot.buffer))
|
|
393
419
|
) {
|
|
394
420
|
this.accountsCurrentlyPolling.delete(accountIdString);
|
|
395
421
|
|
|
@@ -101,12 +101,33 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
101
101
|
bufferAndSlotMap: Map<string, BufferAndSlot> = new Map();
|
|
102
102
|
program: VelocityProgram;
|
|
103
103
|
decodeBuffer: (accountName: string, ix: Buffer) => T;
|
|
104
|
-
|
|
104
|
+
private _onChange?: (
|
|
105
105
|
accountId: PublicKey,
|
|
106
106
|
data: T,
|
|
107
107
|
context: Context,
|
|
108
108
|
buffer: Buffer
|
|
109
109
|
) => void;
|
|
110
|
+
get onChange(): (
|
|
111
|
+
accountId: PublicKey,
|
|
112
|
+
data: T,
|
|
113
|
+
context: Context,
|
|
114
|
+
buffer: Buffer
|
|
115
|
+
) => void {
|
|
116
|
+
if (!this._onChange) {
|
|
117
|
+
throw new Error('onChange callback function must be set');
|
|
118
|
+
}
|
|
119
|
+
return this._onChange;
|
|
120
|
+
}
|
|
121
|
+
set onChange(
|
|
122
|
+
onChange: (
|
|
123
|
+
accountId: PublicKey,
|
|
124
|
+
data: T,
|
|
125
|
+
context: Context,
|
|
126
|
+
buffer: Buffer
|
|
127
|
+
) => void
|
|
128
|
+
) {
|
|
129
|
+
this._onChange = onChange;
|
|
130
|
+
}
|
|
110
131
|
listenerId?: number;
|
|
111
132
|
resubOpts: ResubOpts;
|
|
112
133
|
isUnsubscribing = false;
|
|
@@ -160,7 +181,10 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
160
181
|
usePollingInsteadOfResub: true,
|
|
161
182
|
logResubMessages: false,
|
|
162
183
|
};
|
|
163
|
-
if (
|
|
184
|
+
if (
|
|
185
|
+
this.resubOpts.resubTimeoutMs != null &&
|
|
186
|
+
this.resubOpts.resubTimeoutMs < 1000
|
|
187
|
+
) {
|
|
164
188
|
console.log(
|
|
165
189
|
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
166
190
|
);
|
|
@@ -319,7 +343,7 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
319
343
|
}
|
|
320
344
|
|
|
321
345
|
protected setTimeout(): void {
|
|
322
|
-
if (!this.
|
|
346
|
+
if (!this._onChange) {
|
|
323
347
|
throw new Error('onChange callback function must be set');
|
|
324
348
|
}
|
|
325
349
|
this.timeoutId = setTimeout(
|
|
@@ -389,7 +413,8 @@ export class WebSocketProgramAccountsSubscriberV2<T>
|
|
|
389
413
|
// If this account was being polled, stop polling it if the buffer has changed
|
|
390
414
|
if (
|
|
391
415
|
this.accountsCurrentlyPolling.has(accountIdString) &&
|
|
392
|
-
!existingBufferAndSlot?.buffer
|
|
416
|
+
(!existingBufferAndSlot?.buffer ||
|
|
417
|
+
(newBuffer != null && !existingBufferAndSlot.buffer.equals(newBuffer)))
|
|
393
418
|
) {
|
|
394
419
|
this.accountsCurrentlyPolling.delete(accountIdString);
|
|
395
420
|
|
|
@@ -21,7 +21,16 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
21
21
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
22
22
|
userAccountPublicKey: PublicKey;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
private _userDataAccountSubscriber?: AccountSubscriber<UserAccount>;
|
|
25
|
+
get userDataAccountSubscriber(): AccountSubscriber<UserAccount> {
|
|
26
|
+
if (!this._userDataAccountSubscriber) {
|
|
27
|
+
throw new Error('userDataAccountSubscriber accessed before subscribe()');
|
|
28
|
+
}
|
|
29
|
+
return this._userDataAccountSubscriber;
|
|
30
|
+
}
|
|
31
|
+
set userDataAccountSubscriber(subscriber: AccountSubscriber<UserAccount>) {
|
|
32
|
+
this._userDataAccountSubscriber = subscriber;
|
|
33
|
+
}
|
|
25
34
|
|
|
26
35
|
public constructor(
|
|
27
36
|
program: VelocityProgram,
|
|
@@ -87,7 +96,7 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
public getUserAccountAndSlot(): DataAndSlot<UserAccount> {
|
|
99
|
+
public getUserAccountAndSlot(): DataAndSlot<UserAccount> | undefined {
|
|
91
100
|
this.assertIsSubscribed();
|
|
92
101
|
return this.userDataAccountSubscriber.dataAndSlot;
|
|
93
102
|
}
|