@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
|
@@ -74,7 +74,7 @@ export class SwiftOrderSubscriber {
|
|
|
74
74
|
private ws: WebSocket | null = null;
|
|
75
75
|
private velocityClient: VelocityClient;
|
|
76
76
|
public userAccountGetter?: AccountGetter; // In practice, this for now is just an OrderSubscriber or a UserMap
|
|
77
|
-
public onOrder
|
|
77
|
+
public onOrder?: (
|
|
78
78
|
orderMessageRaw: SwiftOrderMessage,
|
|
79
79
|
signedMessage:
|
|
80
80
|
| SignedMsgOrderParamsMessage
|
|
@@ -92,8 +92,8 @@ export class SwiftOrderSubscriber {
|
|
|
92
92
|
|
|
93
93
|
unsubscribe() {
|
|
94
94
|
if (this.subscribed) {
|
|
95
|
-
this.ws
|
|
96
|
-
this.ws
|
|
95
|
+
this.ws?.removeAllListeners();
|
|
96
|
+
this.ws?.terminate();
|
|
97
97
|
this.ws = null;
|
|
98
98
|
this.subscribed = false;
|
|
99
99
|
}
|
|
@@ -245,11 +245,8 @@ export class SwiftOrderSubscriber {
|
|
|
245
245
|
}, 5000);
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
-
ws.on('error', async (
|
|
249
|
-
console.error(
|
|
250
|
-
'WS closed from error, reconnecting in 1s:',
|
|
251
|
-
response.statusCode
|
|
252
|
-
);
|
|
248
|
+
ws.on('error', async (error: Error) => {
|
|
249
|
+
console.error('WS closed from error, reconnecting in 1s:', error);
|
|
253
250
|
setTimeout(() => {
|
|
254
251
|
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
|
|
255
252
|
this.reconnect();
|
|
@@ -343,8 +340,12 @@ export class SwiftOrderSubscriber {
|
|
|
343
340
|
}
|
|
344
341
|
|
|
345
342
|
console.log('Reconnecting to WebSocket...');
|
|
343
|
+
const onOrder = this.onOrder;
|
|
344
|
+
if (!onOrder) {
|
|
345
|
+
throw new Error('onOrder callback function must be set');
|
|
346
|
+
}
|
|
346
347
|
setTimeout(() => {
|
|
347
|
-
this.subscribe(
|
|
348
|
+
this.subscribe(onOrder);
|
|
348
349
|
}, 1000);
|
|
349
350
|
}
|
|
350
351
|
}
|
package/src/testClient.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { VelocityClientConfig } from './velocityClientConfig';
|
|
|
7
7
|
export class TestClient extends AdminClient {
|
|
8
8
|
public constructor(config: VelocityClientConfig) {
|
|
9
9
|
config.txVersion = 'legacy';
|
|
10
|
-
if (config.accountSubscription
|
|
10
|
+
if (config.accountSubscription?.type !== 'polling') {
|
|
11
11
|
throw new Error('Test client must be polling');
|
|
12
12
|
}
|
|
13
13
|
super(config);
|
|
@@ -30,7 +30,7 @@ export class TestClient extends AdminClient {
|
|
|
30
30
|
this.accountSubscriber as PollingVelocityClientAccountSubscriber
|
|
31
31
|
).accountLoader.mostRecentSlot;
|
|
32
32
|
await this.fetchAccounts();
|
|
33
|
-
while (lastFetchedSlot < slot) {
|
|
33
|
+
while (slot !== undefined && lastFetchedSlot < slot) {
|
|
34
34
|
await this.fetchAccounts();
|
|
35
35
|
lastFetchedSlot = (
|
|
36
36
|
this.accountSubscriber as PollingVelocityClientAccountSubscriber
|
package/src/tokenFaucet.ts
CHANGED
|
@@ -101,6 +101,11 @@ export class TokenFaucet {
|
|
|
101
101
|
},
|
|
102
102
|
});
|
|
103
103
|
const tx = new Transaction().add(ix);
|
|
104
|
+
if (!this.context) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
'TokenFaucet: initialize() requires a BankrunContextWrapper context'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
104
109
|
const txSig = await this.context.sendTransaction(tx);
|
|
105
110
|
return txSig;
|
|
106
111
|
}
|
|
@@ -134,6 +139,11 @@ export class TokenFaucet {
|
|
|
134
139
|
if (this.context) {
|
|
135
140
|
return await this.context.sendTransaction(tx);
|
|
136
141
|
} else {
|
|
142
|
+
if (!this.program.provider.sendAndConfirm) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
'TokenFaucet: program provider does not support sendAndConfirm'
|
|
145
|
+
);
|
|
146
|
+
}
|
|
137
147
|
return await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
138
148
|
}
|
|
139
149
|
}
|
|
@@ -180,8 +190,9 @@ export class TokenFaucet {
|
|
|
180
190
|
let associatedTokenAccountExists = false;
|
|
181
191
|
|
|
182
192
|
try {
|
|
183
|
-
const assosciatedTokenAccount =
|
|
184
|
-
await this.context.connection.getAccountInfo(associatedTokenPublicKey)
|
|
193
|
+
const assosciatedTokenAccount = this.context
|
|
194
|
+
? await this.context.connection.getAccountInfo(associatedTokenPublicKey)
|
|
195
|
+
: await this.connection.getAccountInfo(associatedTokenPublicKey);
|
|
185
196
|
|
|
186
197
|
associatedTokenAccountExists = !!assosciatedTokenAccount;
|
|
187
198
|
} catch (e) {
|
|
@@ -199,6 +210,11 @@ export class TokenFaucet {
|
|
|
199
210
|
if (this.context) {
|
|
200
211
|
txSig = await this.context.sendTransaction(tx);
|
|
201
212
|
} else {
|
|
213
|
+
if (!this.program.provider.sendAndConfirm) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
'TokenFaucet: program provider does not support sendAndConfirm'
|
|
216
|
+
);
|
|
217
|
+
}
|
|
202
218
|
txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
203
219
|
}
|
|
204
220
|
|
|
@@ -257,7 +273,10 @@ export class TokenFaucet {
|
|
|
257
273
|
props.callback(await this.getTokenAccountInfo(props));
|
|
258
274
|
|
|
259
275
|
// Couldn't find a way to do it using anchor framework subscription — fall back to onAccountChange.
|
|
260
|
-
this.context
|
|
276
|
+
const subscribeConnection = this.context
|
|
277
|
+
? this.context.connection
|
|
278
|
+
: this.connection;
|
|
279
|
+
subscribeConnection.onAccountChange(
|
|
261
280
|
tokenAccountKey,
|
|
262
281
|
async (
|
|
263
282
|
_accountInfo /* accountInfo is a buffer which we don't know how to deserialize */
|
package/src/tx/baseTxSender.ts
CHANGED
|
@@ -40,7 +40,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
40
40
|
additionalConnections: Connection[];
|
|
41
41
|
timeoutCount = 0;
|
|
42
42
|
confirmationStrategy: ConfirmationStrategy;
|
|
43
|
-
additionalTxSenderCallbacks
|
|
43
|
+
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
44
44
|
txHandler: TxHandler;
|
|
45
45
|
trackTxLandRate?: boolean;
|
|
46
46
|
throwOnTimeoutError: boolean;
|
|
@@ -72,7 +72,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
72
72
|
wallet: IWallet;
|
|
73
73
|
opts?: ConfirmOptions;
|
|
74
74
|
timeout?: number;
|
|
75
|
-
additionalConnections
|
|
75
|
+
additionalConnections?: Connection[];
|
|
76
76
|
confirmationStrategy?: ConfirmationStrategy;
|
|
77
77
|
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
78
78
|
txHandler?: TxHandler;
|
|
@@ -181,7 +181,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
181
181
|
} else {
|
|
182
182
|
signedTx = await this.txHandler.signVersionedTx(
|
|
183
183
|
tx,
|
|
184
|
-
additionalSigners,
|
|
184
|
+
additionalSigners ?? [],
|
|
185
185
|
undefined,
|
|
186
186
|
this.wallet
|
|
187
187
|
);
|
|
@@ -221,7 +221,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
221
221
|
async confirmTransactionWebSocket(
|
|
222
222
|
signature: TransactionSignature,
|
|
223
223
|
commitment?: Commitment
|
|
224
|
-
): Promise<RpcResponseAndContext<SignatureResult
|
|
224
|
+
): Promise<RpcResponseAndContext<SignatureResult> | undefined> {
|
|
225
225
|
let decodedSignature;
|
|
226
226
|
try {
|
|
227
227
|
decodedSignature = bs58.decode(signature);
|
|
@@ -234,11 +234,11 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
234
234
|
const start = Date.now();
|
|
235
235
|
const subscriptionCommitment = commitment || this.opts.commitment;
|
|
236
236
|
|
|
237
|
-
const subscriptionIds = new Array<number>();
|
|
237
|
+
const subscriptionIds = new Array<number | undefined>();
|
|
238
238
|
const connections = [this.connection, ...this.additionalConnections];
|
|
239
239
|
let response: RpcResponseAndContext<SignatureResult> | null = null;
|
|
240
240
|
const promises = connections.map((connection, i) => {
|
|
241
|
-
let subscriptionId;
|
|
241
|
+
let subscriptionId: number | undefined;
|
|
242
242
|
const confirmPromise = new Promise((resolve, reject) => {
|
|
243
243
|
try {
|
|
244
244
|
subscriptionId = connection.onSignature(
|
|
@@ -301,7 +301,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
return response;
|
|
304
|
+
return response ?? undefined;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
async confirmTransactionPolling(
|
|
@@ -349,7 +349,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
349
349
|
async confirmTransaction(
|
|
350
350
|
signature: TransactionSignature,
|
|
351
351
|
commitment?: Commitment
|
|
352
|
-
): Promise<RpcResponseAndContext<SignatureResult
|
|
352
|
+
): Promise<RpcResponseAndContext<SignatureResult> | undefined> {
|
|
353
353
|
if (
|
|
354
354
|
this.confirmationStrategy === ConfirmationStrategy.WebSocket ||
|
|
355
355
|
this.confirmationStrategy === ConfirmationStrategy.Combo
|
|
@@ -431,7 +431,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
public getTxLandRate(): number {
|
|
434
|
-
if (!this.trackTxLandRate) {
|
|
434
|
+
if (!this.trackTxLandRate || !this.txSigCache) {
|
|
435
435
|
return this.txLandRate;
|
|
436
436
|
}
|
|
437
437
|
const keys = this.txSigCache.keys();
|
|
@@ -453,7 +453,7 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
453
453
|
private defaultLandRateToFeeFunc(txLandRate: number) {
|
|
454
454
|
if (
|
|
455
455
|
txLandRate >= BASELINE_TX_LAND_RATE ||
|
|
456
|
-
this.txSigCache
|
|
456
|
+
(this.txSigCache?.keys().length ?? 0) < 3
|
|
457
457
|
) {
|
|
458
458
|
return 1;
|
|
459
459
|
}
|
|
@@ -22,11 +22,11 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
22
22
|
blockhashRefreshInterval: number;
|
|
23
23
|
additionalConnections: Connection[];
|
|
24
24
|
timoutCount = 0;
|
|
25
|
-
recentBlockhash
|
|
25
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight;
|
|
26
26
|
skipConfirmation: boolean;
|
|
27
27
|
confirmInBackground: boolean;
|
|
28
28
|
blockhashCommitment: Commitment;
|
|
29
|
-
blockhashIntervalId
|
|
29
|
+
blockhashIntervalId?: NodeJS.Timer;
|
|
30
30
|
|
|
31
31
|
public constructor({
|
|
32
32
|
connection,
|
|
@@ -50,7 +50,7 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
50
50
|
opts?: ConfirmOptions;
|
|
51
51
|
timeout?: number;
|
|
52
52
|
blockhashRefreshInterval?: number;
|
|
53
|
-
additionalConnections
|
|
53
|
+
additionalConnections?: Connection[];
|
|
54
54
|
skipConfirmation?: boolean;
|
|
55
55
|
confirmInBackground?: boolean;
|
|
56
56
|
blockhashCommitment?: Commitment;
|
|
@@ -114,22 +114,26 @@ export class FastSingleTxSender extends BaseTxSender {
|
|
|
114
114
|
throw e;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
let slot: number;
|
|
117
|
+
let slot: number | undefined;
|
|
118
118
|
if (!this.skipConfirmation) {
|
|
119
119
|
try {
|
|
120
120
|
if (this.confirmInBackground) {
|
|
121
121
|
this.confirmTransaction(txid, opts.commitment).then(
|
|
122
122
|
async (result) => {
|
|
123
123
|
this.txSigCache?.set(txid, true);
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
if (result) {
|
|
125
|
+
await this.checkConfirmationResultForError(txid, result.value);
|
|
126
|
+
slot = result.context.slot;
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
129
|
);
|
|
128
130
|
} else {
|
|
129
131
|
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
130
132
|
this.txSigCache?.set(txid, true);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
if (result) {
|
|
134
|
+
await this.checkConfirmationResultForError(txid, result.value);
|
|
135
|
+
slot = result.context.slot;
|
|
136
|
+
}
|
|
133
137
|
}
|
|
134
138
|
} catch (e) {
|
|
135
139
|
console.error(e);
|
|
@@ -29,10 +29,15 @@ const getTransactionResult = async (
|
|
|
29
29
|
txSig: string,
|
|
30
30
|
connection: Connection,
|
|
31
31
|
commitment?: Commitment
|
|
32
|
-
): Promise<VersionedTransactionResponse> => {
|
|
33
|
-
const
|
|
34
|
-
commitment || connection.commitment || DEFAULT_CONFIRMATION_OPTS.commitment
|
|
35
|
-
)
|
|
32
|
+
): Promise<VersionedTransactionResponse | null> => {
|
|
33
|
+
const resolvedCommitment =
|
|
34
|
+
commitment || connection.commitment || DEFAULT_CONFIRMATION_OPTS.commitment;
|
|
35
|
+
if (!resolvedCommitment) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'No commitment available when reporting transaction error. Provide a commitment, set one on the connection, or configure DEFAULT_CONFIRMATION_OPTS.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const finality = commitmentToFinality(resolvedCommitment);
|
|
36
41
|
return await connection.getTransaction(txSig, {
|
|
37
42
|
maxSupportedTransactionVersion: 0,
|
|
38
43
|
commitment: finality,
|
|
@@ -43,7 +48,7 @@ const getTransactionResultWithRetry = async (
|
|
|
43
48
|
txSig: string,
|
|
44
49
|
connection: Connection,
|
|
45
50
|
commitment?: Commitment
|
|
46
|
-
): Promise<VersionedTransactionResponse> => {
|
|
51
|
+
): Promise<VersionedTransactionResponse | null> => {
|
|
47
52
|
const start = Date.now();
|
|
48
53
|
|
|
49
54
|
const retryTimeout = 3_000; // Timeout after 3 seconds
|
|
@@ -111,7 +116,7 @@ export const getTransactionErrorFromTxSig = async (
|
|
|
111
116
|
txSig: string,
|
|
112
117
|
connection: Connection,
|
|
113
118
|
commitment?: Commitment
|
|
114
|
-
): Promise<SendTransactionError> => {
|
|
119
|
+
): Promise<SendTransactionError | undefined> => {
|
|
115
120
|
const transactionResult = await getTransactionResultWithRetry(
|
|
116
121
|
txSig,
|
|
117
122
|
connection,
|
|
@@ -137,7 +142,7 @@ export const getTransactionErrorFromTxSig = async (
|
|
|
137
142
|
|
|
138
143
|
export const getTransactionError = (
|
|
139
144
|
transactionResult: VersionedTransactionResponse
|
|
140
|
-
): SendTransactionError => {
|
|
145
|
+
): SendTransactionError | undefined => {
|
|
141
146
|
if (!transactionResult?.meta?.err) {
|
|
142
147
|
return;
|
|
143
148
|
}
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class RetryTxSender extends BaseTxSender {
|
|
|
41
41
|
opts?: ConfirmOptions;
|
|
42
42
|
timeout?: number;
|
|
43
43
|
retrySleep?: number;
|
|
44
|
-
additionalConnections
|
|
44
|
+
additionalConnections?: Connection[];
|
|
45
45
|
confirmationStrategy?: ConfirmationStrategy;
|
|
46
46
|
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
47
47
|
txHandler?: TxHandler;
|
|
@@ -115,14 +115,16 @@ export class RetryTxSender extends BaseTxSender {
|
|
|
115
115
|
}
|
|
116
116
|
})();
|
|
117
117
|
|
|
118
|
-
let slot: number;
|
|
118
|
+
let slot: number | undefined;
|
|
119
119
|
try {
|
|
120
120
|
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
121
121
|
this.txSigCache?.set(txid, true);
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
if (result) {
|
|
124
|
+
await this.checkConfirmationResultForError(txid, result.value);
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
slot = result.context?.slot;
|
|
127
|
+
}
|
|
126
128
|
// eslint-disable-next-line no-useless-catch
|
|
127
129
|
} catch (e) {
|
|
128
130
|
throw e;
|
package/src/tx/txHandler.ts
CHANGED
|
@@ -67,7 +67,7 @@ export type TxBuildingProps = {
|
|
|
67
67
|
instructions: TransactionInstruction | TransactionInstruction[];
|
|
68
68
|
txVersion: TransactionVersion;
|
|
69
69
|
connection: Connection;
|
|
70
|
-
preFlightCommitment
|
|
70
|
+
preFlightCommitment?: Commitment;
|
|
71
71
|
fetchAllMarketLookupTableAccounts: () => Promise<AddressLookupTableAccount[]>;
|
|
72
72
|
lookupTables?: AddressLookupTableAccount[];
|
|
73
73
|
forceVersionedTransaction?: boolean;
|
|
@@ -104,7 +104,7 @@ export class TxHandler {
|
|
|
104
104
|
) => void;
|
|
105
105
|
|
|
106
106
|
private blockhashCommitment: Commitment =
|
|
107
|
-
DEFAULT_CONFIRMATION_OPTS.commitment;
|
|
107
|
+
DEFAULT_CONFIRMATION_OPTS.commitment ?? 'confirmed';
|
|
108
108
|
private blockHashFetcher: BlockhashFetcher;
|
|
109
109
|
|
|
110
110
|
constructor(props: {
|
|
@@ -181,6 +181,22 @@ export class TxHandler {
|
|
|
181
181
|
return this.blockHashFetcher.getLatestBlockhash();
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Resolves a usable recent blockhash, preferring a caller-provided one and
|
|
186
|
+
* otherwise fetching the latest. Throws if no blockhash can be obtained,
|
|
187
|
+
* since a transaction cannot be built or signed without one.
|
|
188
|
+
*/
|
|
189
|
+
private async resolveRecentBlockhash(
|
|
190
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight
|
|
191
|
+
): Promise<BlockhashWithExpiryBlockHeight> {
|
|
192
|
+
const resolved =
|
|
193
|
+
recentBlockhash ?? (await this.getLatestBlockhashForTransaction());
|
|
194
|
+
if (!resolved) {
|
|
195
|
+
throw new Error('TxHandler: failed to fetch a recent blockhash');
|
|
196
|
+
}
|
|
197
|
+
return resolved;
|
|
198
|
+
}
|
|
199
|
+
|
|
184
200
|
/**
|
|
185
201
|
* Applies recent blockhash and signs a given transaction
|
|
186
202
|
* @param tx
|
|
@@ -206,17 +222,17 @@ export class TxHandler {
|
|
|
206
222
|
[wallet, confirmationOpts] = this.getProps(wallet, confirmationOpts);
|
|
207
223
|
|
|
208
224
|
tx.feePayer = wallet.publicKey;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
tx.recentBlockhash =
|
|
225
|
+
const resolvedBlockhash = await this.resolveRecentBlockhash(
|
|
226
|
+
recentBlockhash
|
|
227
|
+
);
|
|
228
|
+
tx.recentBlockhash = resolvedBlockhash.blockhash;
|
|
213
229
|
|
|
214
|
-
this.addHashAndExpiryToLookup(
|
|
230
|
+
this.addHashAndExpiryToLookup(resolvedBlockhash);
|
|
215
231
|
|
|
216
232
|
const signedTx = await this.signTx(tx, additionalSigners);
|
|
217
233
|
|
|
218
234
|
// @ts-ignore
|
|
219
|
-
signedTx.SIGNATURE_BLOCK_AND_EXPIRY =
|
|
235
|
+
signedTx.SIGNATURE_BLOCK_AND_EXPIRY = resolvedBlockhash;
|
|
220
236
|
|
|
221
237
|
return signedTx;
|
|
222
238
|
}
|
|
@@ -237,20 +253,30 @@ export class TxHandler {
|
|
|
237
253
|
Buffer.from((signedTx as VersionedTransaction).signatures[0])
|
|
238
254
|
) as string;
|
|
239
255
|
} else {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
256
|
+
const signature = (signedTx as Transaction).signature;
|
|
257
|
+
if (!signature) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
'TxHandler: cannot derive txSig from an unsigned legacy transaction'
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return bs58.encode(Buffer.from(signature)) as string;
|
|
243
263
|
}
|
|
244
264
|
}
|
|
245
265
|
|
|
246
266
|
private getBlockhashFromSignedTx(
|
|
247
267
|
signedTx: Transaction | VersionedTransaction
|
|
248
|
-
) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
): string {
|
|
269
|
+
const blockHash = this.isVersionedTransaction(signedTx)
|
|
270
|
+
? (signedTx as VersionedTransaction).message.recentBlockhash
|
|
271
|
+
: (signedTx as Transaction).recentBlockhash;
|
|
272
|
+
|
|
273
|
+
if (!blockHash) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
'TxHandler: signed transaction is missing a recentBlockhash'
|
|
276
|
+
);
|
|
253
277
|
}
|
|
278
|
+
|
|
279
|
+
return blockHash;
|
|
254
280
|
}
|
|
255
281
|
|
|
256
282
|
private async signTx(
|
|
@@ -328,13 +354,13 @@ export class TxHandler {
|
|
|
328
354
|
|
|
329
355
|
private handleSignedTxData(
|
|
330
356
|
txData: Omit<SignedTxData, 'lastValidBlockHeight'>[]
|
|
331
|
-
) {
|
|
357
|
+
): SignedTxData[] {
|
|
332
358
|
if (!this.returnBlockHeightsWithSignedTxCallbackData) {
|
|
333
359
|
if (this.onSignedCb) {
|
|
334
360
|
this.onSignedCb(txData);
|
|
335
361
|
}
|
|
336
362
|
|
|
337
|
-
return;
|
|
363
|
+
return [];
|
|
338
364
|
}
|
|
339
365
|
|
|
340
366
|
const signedTxData = txData.map((tx) => {
|
|
@@ -377,14 +403,14 @@ export class TxHandler {
|
|
|
377
403
|
}) as Promise<VersionedTransaction>,
|
|
378
404
|
processConfig: {
|
|
379
405
|
useSimulatedComputeUnits:
|
|
380
|
-
txBuildingProps.txParams
|
|
406
|
+
txBuildingProps.txParams?.useSimulatedComputeUnits,
|
|
381
407
|
computeUnitsBufferMultiplier:
|
|
382
|
-
txBuildingProps.txParams
|
|
408
|
+
txBuildingProps.txParams?.computeUnitsBufferMultiplier,
|
|
383
409
|
useSimulatedComputeUnitsForCUPriceCalculation:
|
|
384
410
|
txBuildingProps.txParams
|
|
385
|
-
|
|
411
|
+
?.useSimulatedComputeUnitsForCUPriceCalculation,
|
|
386
412
|
getCUPriceFromComputeUnits:
|
|
387
|
-
txBuildingProps.txParams
|
|
413
|
+
txBuildingProps.txParams?.getCUPriceFromComputeUnits,
|
|
388
414
|
},
|
|
389
415
|
processParams: {
|
|
390
416
|
connection: this.connection,
|
|
@@ -468,8 +494,9 @@ export class TxHandler {
|
|
|
468
494
|
instructions: (TransactionInstruction | TransactionInstruction[])[];
|
|
469
495
|
}
|
|
470
496
|
) {
|
|
471
|
-
const recentBlockhash =
|
|
472
|
-
props?.recentBlockhash
|
|
497
|
+
const recentBlockhash = await this.resolveRecentBlockhash(
|
|
498
|
+
props?.recentBlockhash
|
|
499
|
+
);
|
|
473
500
|
|
|
474
501
|
return await Promise.all(
|
|
475
502
|
props.instructions.map((ix) => {
|
|
@@ -567,7 +594,11 @@ export class TxHandler {
|
|
|
567
594
|
// # Create Tx Instructions
|
|
568
595
|
const allIx = [];
|
|
569
596
|
const computeUnits = baseTxParams?.computeUnits;
|
|
570
|
-
if (
|
|
597
|
+
if (
|
|
598
|
+
computeUnits !== undefined &&
|
|
599
|
+
computeUnits > 0 &&
|
|
600
|
+
!hasSetComputeUnitLimitIx
|
|
601
|
+
) {
|
|
571
602
|
allIx.push(
|
|
572
603
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
573
604
|
units: computeUnits,
|
|
@@ -583,7 +614,11 @@ export class TxHandler {
|
|
|
583
614
|
microLamports: 0,
|
|
584
615
|
})
|
|
585
616
|
);
|
|
586
|
-
} else if (
|
|
617
|
+
} else if (
|
|
618
|
+
computeUnitsPrice !== undefined &&
|
|
619
|
+
computeUnitsPrice > 0 &&
|
|
620
|
+
!hasSetComputeUnitPriceIx
|
|
621
|
+
) {
|
|
587
622
|
allIx.push(
|
|
588
623
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
589
624
|
microLamports: computeUnitsPrice,
|
|
@@ -593,8 +628,9 @@ export class TxHandler {
|
|
|
593
628
|
|
|
594
629
|
allIx.push(...instructionsToUse);
|
|
595
630
|
|
|
596
|
-
const recentBlockhash =
|
|
597
|
-
props?.recentBlockhash
|
|
631
|
+
const recentBlockhash = await this.resolveRecentBlockhash(
|
|
632
|
+
props?.recentBlockhash
|
|
633
|
+
);
|
|
598
634
|
|
|
599
635
|
// # Create and return Transaction
|
|
600
636
|
if (txVersion === 'legacy') {
|
|
@@ -659,19 +695,19 @@ export class TxHandler {
|
|
|
659
695
|
commitment?: Commitment,
|
|
660
696
|
recentBlockhash?: BlockhashWithExpiryBlockHeight
|
|
661
697
|
) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
698
|
+
const resolvedBlockhash = await this.resolveRecentBlockhash(
|
|
699
|
+
recentBlockhash
|
|
700
|
+
);
|
|
665
701
|
|
|
666
|
-
this.addHashAndExpiryToLookup(
|
|
702
|
+
this.addHashAndExpiryToLookup(resolvedBlockhash);
|
|
667
703
|
|
|
668
704
|
for (const tx of Object.values(txsMap)) {
|
|
669
705
|
if (!tx) continue;
|
|
670
|
-
tx.recentBlockhash =
|
|
706
|
+
tx.recentBlockhash = resolvedBlockhash.blockhash;
|
|
671
707
|
tx.feePayer = wallet?.publicKey ?? this.wallet?.publicKey;
|
|
672
708
|
|
|
673
709
|
// @ts-ignore
|
|
674
|
-
tx.SIGNATURE_BLOCK_AND_EXPIRY =
|
|
710
|
+
tx.SIGNATURE_BLOCK_AND_EXPIRY = resolvedBlockhash;
|
|
675
711
|
}
|
|
676
712
|
|
|
677
713
|
return this.getSignedTransactionMap(txsMap, wallet);
|
|
@@ -698,12 +734,18 @@ export class TxHandler {
|
|
|
698
734
|
const txsToSignEntries = Object.entries(txsToSignMap);
|
|
699
735
|
|
|
700
736
|
// Create a map of the same keys as the input map, but with the values set to undefined. We'll populate the filtered (non-undefined) values with signed transactions.
|
|
701
|
-
const signedTxMap = txsToSignEntries.reduce(
|
|
702
|
-
acc[key]
|
|
703
|
-
|
|
704
|
-
|
|
737
|
+
const signedTxMap = txsToSignEntries.reduce(
|
|
738
|
+
(acc, [key]) => {
|
|
739
|
+
acc[key] = undefined;
|
|
740
|
+
return acc;
|
|
741
|
+
},
|
|
742
|
+
{} as Record<string, Transaction | VersionedTransaction | undefined>
|
|
743
|
+
) as T;
|
|
705
744
|
|
|
706
|
-
const filteredTxEntries = txsToSignEntries.filter(
|
|
745
|
+
const filteredTxEntries = txsToSignEntries.filter(
|
|
746
|
+
(entry): entry is [string, Transaction | VersionedTransaction] =>
|
|
747
|
+
!!entry[1]
|
|
748
|
+
);
|
|
707
749
|
|
|
708
750
|
// Extra handling for legacy transactions
|
|
709
751
|
for (const [_key, tx] of filteredTxEntries) {
|
|
@@ -761,10 +803,13 @@ export class TxHandler {
|
|
|
761
803
|
instructions: Object.values(props.instructionsMap),
|
|
762
804
|
});
|
|
763
805
|
|
|
764
|
-
return Object.keys(props.instructionsMap).reduce(
|
|
765
|
-
acc
|
|
766
|
-
|
|
767
|
-
|
|
806
|
+
return Object.keys(props.instructionsMap).reduce(
|
|
807
|
+
(acc, key, index) => {
|
|
808
|
+
acc[key] = builtTxs[index];
|
|
809
|
+
return acc;
|
|
810
|
+
},
|
|
811
|
+
{} as Record<string, Transaction | VersionedTransaction | undefined>
|
|
812
|
+
) as MappedRecord<T, Transaction | VersionedTransaction>;
|
|
768
813
|
}
|
|
769
814
|
|
|
770
815
|
/**
|
|
@@ -35,7 +35,10 @@ export class TransactionParamProcessor {
|
|
|
35
35
|
bufferMultiplier: number, // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
|
|
36
36
|
lowerBoundCu?: number,
|
|
37
37
|
simulatedTx?: SimulatedTransactionResponse
|
|
38
|
-
): Promise<
|
|
38
|
+
): Promise<
|
|
39
|
+
| { success: true; computeUnits: number }
|
|
40
|
+
| { success: false; computeUnits: undefined }
|
|
41
|
+
> {
|
|
39
42
|
try {
|
|
40
43
|
if (TEST_SIMS_ALWAYS_FAIL)
|
|
41
44
|
throw new Error('Test Error::SIMS_ALWAYS_FAIL');
|
|
@@ -54,6 +57,12 @@ export class TransactionParamProcessor {
|
|
|
54
57
|
|
|
55
58
|
const computeUnits = await this.getComputeUnitsFromSim(simTxResult);
|
|
56
59
|
|
|
60
|
+
if (computeUnits === undefined) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
'TransactionParamProcessor: simulation did not return units consumed'
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
// Apply the buffer, but round down to the MAX_COMPUTE_UNITS, and round up to the nearest whole number
|
|
58
67
|
let bufferedComputeUnits = Math.ceil(
|
|
59
68
|
Math.min(computeUnits * bufferMultiplier, MAX_COMPUTE_UNITS)
|
|
@@ -68,7 +77,7 @@ export class TransactionParamProcessor {
|
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
return {
|
|
71
|
-
success: true,
|
|
80
|
+
success: true as const,
|
|
72
81
|
computeUnits: bufferedComputeUnits,
|
|
73
82
|
};
|
|
74
83
|
} catch (e) {
|
|
@@ -78,7 +87,7 @@ export class TransactionParamProcessor {
|
|
|
78
87
|
);
|
|
79
88
|
|
|
80
89
|
return {
|
|
81
|
-
success: false,
|
|
90
|
+
success: false as const,
|
|
82
91
|
computeUnits: undefined,
|
|
83
92
|
};
|
|
84
93
|
}
|
|
@@ -146,6 +155,12 @@ export class TransactionParamProcessor {
|
|
|
146
155
|
|
|
147
156
|
const simulatedComputeUnits = finalTxParams.computeUnits;
|
|
148
157
|
|
|
158
|
+
if (simulatedComputeUnits === undefined) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`encountered useSimulatedComputeUnitsForFees=true, but simulated compute units are unavailable (simulation likely failed)`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
149
164
|
const computeUnitPrice = processConfig.getCUPriceFromComputeUnits(
|
|
150
165
|
simulatedComputeUnits
|
|
151
166
|
);
|