@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
package/src/velocityClient.ts
CHANGED
|
@@ -116,7 +116,6 @@ import {
|
|
|
116
116
|
getUserAccountPublicKeySync,
|
|
117
117
|
getUserStatsAccountPublicKey,
|
|
118
118
|
getSignedMsgWsDelegatesAccountPublicKey,
|
|
119
|
-
getIfRebalanceConfigPublicKey,
|
|
120
119
|
getRevenueShareAccountPublicKey,
|
|
121
120
|
getRevenueShareEscrowAccountPublicKey,
|
|
122
121
|
getConstituentTargetBasePublicKey,
|
|
@@ -138,7 +137,6 @@ import {
|
|
|
138
137
|
import { TxSender, TxSigAndSlot } from './tx/types';
|
|
139
138
|
import {
|
|
140
139
|
BASE_PRECISION,
|
|
141
|
-
GOV_SPOT_MARKET_INDEX,
|
|
142
140
|
MARGIN_PRECISION,
|
|
143
141
|
MIN_I64,
|
|
144
142
|
ONE,
|
|
@@ -227,11 +225,12 @@ export class VelocityClient {
|
|
|
227
225
|
public program: VelocityProgram;
|
|
228
226
|
provider: AnchorProvider;
|
|
229
227
|
env: VelocityEnv;
|
|
230
|
-
opts
|
|
228
|
+
opts: ConfirmOptions;
|
|
231
229
|
useHotWalletAdmin?: boolean;
|
|
232
230
|
users = new Map<string, User>();
|
|
233
231
|
userStats?: UserStats;
|
|
234
|
-
|
|
232
|
+
userStatsAccountPublicKey?: PublicKey;
|
|
233
|
+
activeSubAccountId: number | undefined;
|
|
235
234
|
userAccountSubscriptionConfig: UserSubscriptionConfig;
|
|
236
235
|
userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig;
|
|
237
236
|
accountSubscriber: VelocityClientAccountSubscriber;
|
|
@@ -248,13 +247,8 @@ export class VelocityClient {
|
|
|
248
247
|
mustIncludeSpotMarketIndexes = new Set<number>();
|
|
249
248
|
authority: PublicKey;
|
|
250
249
|
|
|
251
|
-
/** @deprecated use marketLookupTables */
|
|
252
|
-
marketLookupTable: PublicKey;
|
|
253
|
-
/** @deprecated use lookupTableAccounts */
|
|
254
|
-
lookupTableAccount: AddressLookupTableAccount;
|
|
255
|
-
|
|
256
250
|
marketLookupTables: PublicKey[];
|
|
257
|
-
lookupTableAccounts
|
|
251
|
+
lookupTableAccounts?: AddressLookupTableAccount[];
|
|
258
252
|
|
|
259
253
|
includeDelegates?: boolean;
|
|
260
254
|
authoritySubAccountMap?: Map<string, number[]>;
|
|
@@ -441,19 +435,11 @@ export class VelocityClient {
|
|
|
441
435
|
});
|
|
442
436
|
}
|
|
443
437
|
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
this.
|
|
447
|
-
configs[this.env].MARKET_LOOKUP_TABLE
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
this.marketLookupTables = config.marketLookupTables;
|
|
452
|
-
if (!this.marketLookupTables) {
|
|
453
|
-
this.marketLookupTables = configs[this.env].MARKET_LOOKUP_TABLES.map(
|
|
438
|
+
this.marketLookupTables =
|
|
439
|
+
config.marketLookupTables ??
|
|
440
|
+
configs[this.env].MARKET_LOOKUP_TABLES.map(
|
|
454
441
|
(tableAddr) => new PublicKey(tableAddr)
|
|
455
442
|
);
|
|
456
|
-
}
|
|
457
443
|
|
|
458
444
|
const delistedMarketSetting =
|
|
459
445
|
config.delistedMarketSetting || DelistedMarketSetting.Unsubscribe;
|
|
@@ -633,6 +619,18 @@ export class VelocityClient {
|
|
|
633
619
|
return this.accountSubscriber.getMarketAccountAndSlot(marketIndex)?.data;
|
|
634
620
|
}
|
|
635
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Like {@link getPerpMarketAccount} but throws if the market is not loaded,
|
|
624
|
+
* for call sites that require a guaranteed account.
|
|
625
|
+
*/
|
|
626
|
+
public getPerpMarketAccountOrThrow(marketIndex: number): PerpMarketAccount {
|
|
627
|
+
const perpMarketAccount = this.getPerpMarketAccount(marketIndex);
|
|
628
|
+
if (!perpMarketAccount) {
|
|
629
|
+
throw new Error(`Perp market ${marketIndex} not found`);
|
|
630
|
+
}
|
|
631
|
+
return perpMarketAccount;
|
|
632
|
+
}
|
|
633
|
+
|
|
636
634
|
/**
|
|
637
635
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
638
636
|
* @param marketIndex
|
|
@@ -662,7 +660,20 @@ export class VelocityClient {
|
|
|
662
660
|
public getSpotMarketAccount(
|
|
663
661
|
marketIndex: number
|
|
664
662
|
): SpotMarketAccount | undefined {
|
|
665
|
-
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)
|
|
663
|
+
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)
|
|
664
|
+
?.data;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Like {@link getSpotMarketAccount} but throws if the market is not loaded,
|
|
669
|
+
* for call sites that require a guaranteed account.
|
|
670
|
+
*/
|
|
671
|
+
public getSpotMarketAccountOrThrow(marketIndex: number): SpotMarketAccount {
|
|
672
|
+
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
673
|
+
if (!spotMarketAccount) {
|
|
674
|
+
throw new Error(`Spot market ${marketIndex} not found`);
|
|
675
|
+
}
|
|
676
|
+
return spotMarketAccount;
|
|
666
677
|
}
|
|
667
678
|
|
|
668
679
|
/**
|
|
@@ -673,7 +684,8 @@ export class VelocityClient {
|
|
|
673
684
|
marketIndex: number
|
|
674
685
|
): Promise<SpotMarketAccount | undefined> {
|
|
675
686
|
await this.accountSubscriber.fetch();
|
|
676
|
-
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)
|
|
687
|
+
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)
|
|
688
|
+
?.data;
|
|
677
689
|
}
|
|
678
690
|
|
|
679
691
|
public getSpotMarketAccounts(): SpotMarketAccount[] {
|
|
@@ -684,9 +696,7 @@ export class VelocityClient {
|
|
|
684
696
|
}
|
|
685
697
|
|
|
686
698
|
public getQuoteSpotMarketAccount(): SpotMarketAccount {
|
|
687
|
-
return this.
|
|
688
|
-
QUOTE_SPOT_MARKET_INDEX
|
|
689
|
-
).data;
|
|
699
|
+
return this.getSpotMarketAccountOrThrow(QUOTE_SPOT_MARKET_INDEX);
|
|
690
700
|
}
|
|
691
701
|
|
|
692
702
|
public getOraclePriceDataAndSlot(
|
|
@@ -698,22 +708,6 @@ export class VelocityClient {
|
|
|
698
708
|
);
|
|
699
709
|
}
|
|
700
710
|
|
|
701
|
-
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
702
|
-
public async fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount> {
|
|
703
|
-
if (this.lookupTableAccount) return this.lookupTableAccount;
|
|
704
|
-
|
|
705
|
-
if (!this.marketLookupTable) {
|
|
706
|
-
console.log('Market lookup table address not set');
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
const lookupTableAccount = (
|
|
711
|
-
await this.connection.getAddressLookupTable(this.marketLookupTable)
|
|
712
|
-
).value;
|
|
713
|
-
this.lookupTableAccount = lookupTableAccount;
|
|
714
|
-
|
|
715
|
-
return lookupTableAccount;
|
|
716
|
-
}
|
|
717
711
|
public async fetchAllLookupTableAccounts(): Promise<
|
|
718
712
|
AddressLookupTableAccount[]
|
|
719
713
|
> {
|
|
@@ -892,10 +886,11 @@ export class VelocityClient {
|
|
|
892
886
|
|
|
893
887
|
this.activeSubAccountId = subAccountId;
|
|
894
888
|
this.authority = authority ?? this.authority;
|
|
895
|
-
|
|
889
|
+
const userStatsAccountPublicKey = getUserStatsAccountPublicKey(
|
|
896
890
|
this.program.programId,
|
|
897
891
|
this.authority
|
|
898
892
|
);
|
|
893
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
899
894
|
|
|
900
895
|
/* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
|
|
901
896
|
if (authorityChanged && this.userStats) {
|
|
@@ -905,7 +900,7 @@ export class VelocityClient {
|
|
|
905
900
|
|
|
906
901
|
this.userStats = new UserStats({
|
|
907
902
|
velocityClient: this,
|
|
908
|
-
userStatsAccountPublicKey:
|
|
903
|
+
userStatsAccountPublicKey: userStatsAccountPublicKey,
|
|
909
904
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
910
905
|
});
|
|
911
906
|
|
|
@@ -921,7 +916,7 @@ export class VelocityClient {
|
|
|
921
916
|
authority = authority ?? this.authority;
|
|
922
917
|
const userKey = this.getUserMapKey(subAccountId, authority);
|
|
923
918
|
|
|
924
|
-
if (this.users.has(userKey) && this.users.get(userKey)
|
|
919
|
+
if (this.users.has(userKey) && this.users.get(userKey)?.isSubscribed) {
|
|
925
920
|
return true;
|
|
926
921
|
}
|
|
927
922
|
|
|
@@ -968,8 +963,8 @@ export class VelocityClient {
|
|
|
968
963
|
);
|
|
969
964
|
}
|
|
970
965
|
} else {
|
|
971
|
-
let userAccounts = [];
|
|
972
|
-
let delegatedAccounts = [];
|
|
966
|
+
let userAccounts: UserAccount[] = [];
|
|
967
|
+
let delegatedAccounts: UserAccount[] = [];
|
|
973
968
|
|
|
974
969
|
const userAccountsPromise = this.getUserAccountsForAuthority(
|
|
975
970
|
authority ?? this.wallet.publicKey
|
|
@@ -1570,7 +1565,7 @@ export class VelocityClient {
|
|
|
1570
1565
|
|
|
1571
1566
|
async getNextSubAccountId(): Promise<number> {
|
|
1572
1567
|
const userStats = this.getUserStats();
|
|
1573
|
-
let userStatsAccount: UserStatsAccount;
|
|
1568
|
+
let userStatsAccount: UserStatsAccount | undefined;
|
|
1574
1569
|
if (!userStats) {
|
|
1575
1570
|
userStatsAccount = await fetchUserStatsAccount(
|
|
1576
1571
|
this.connection,
|
|
@@ -1578,7 +1573,19 @@ export class VelocityClient {
|
|
|
1578
1573
|
this.wallet.publicKey
|
|
1579
1574
|
);
|
|
1580
1575
|
} else {
|
|
1581
|
-
|
|
1576
|
+
const account = userStats.getAccount();
|
|
1577
|
+
if (!account) {
|
|
1578
|
+
userStatsAccount = await fetchUserStatsAccount(
|
|
1579
|
+
this.connection,
|
|
1580
|
+
this.program,
|
|
1581
|
+
this.wallet.publicKey
|
|
1582
|
+
);
|
|
1583
|
+
} else {
|
|
1584
|
+
userStatsAccount = account;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
if (!userStatsAccount) {
|
|
1588
|
+
throw new Error('UserStats account does not exist');
|
|
1582
1589
|
}
|
|
1583
1590
|
return userStatsAccount.numberOfSubAccountsCreated;
|
|
1584
1591
|
}
|
|
@@ -1755,10 +1762,10 @@ export class VelocityClient {
|
|
|
1755
1762
|
|
|
1756
1763
|
await this.addUser(subAccountId, this.wallet.publicKey);
|
|
1757
1764
|
|
|
1758
|
-
let remainingAccounts;
|
|
1765
|
+
let remainingAccounts: AccountMeta[];
|
|
1759
1766
|
try {
|
|
1760
1767
|
remainingAccounts = this.getRemainingAccounts({
|
|
1761
|
-
userAccounts: [this.
|
|
1768
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
1762
1769
|
});
|
|
1763
1770
|
} catch (err) {
|
|
1764
1771
|
remainingAccounts = [];
|
|
@@ -1988,7 +1995,9 @@ export class VelocityClient {
|
|
|
1988
1995
|
public async getUserAccountsForDelegate(
|
|
1989
1996
|
delegate: PublicKey
|
|
1990
1997
|
): Promise<UserAccount[]> {
|
|
1991
|
-
const programAccounts = await (
|
|
1998
|
+
const programAccounts: ProgramAccount<UserAccount>[] = await (
|
|
1999
|
+
this.program.account as any
|
|
2000
|
+
).user.all([
|
|
1992
2001
|
{
|
|
1993
2002
|
memcmp: {
|
|
1994
2003
|
offset: 40,
|
|
@@ -2006,7 +2015,9 @@ export class VelocityClient {
|
|
|
2006
2015
|
public async getUserAccountsAndAddressesForAuthority(
|
|
2007
2016
|
authority: PublicKey
|
|
2008
2017
|
): Promise<ProgramAccount<UserAccount>[]> {
|
|
2009
|
-
const programAccounts = await (
|
|
2018
|
+
const programAccounts: ProgramAccount<UserAccount>[] = await (
|
|
2019
|
+
this.program.account as any
|
|
2020
|
+
).user.all([
|
|
2010
2021
|
{
|
|
2011
2022
|
memcmp: {
|
|
2012
2023
|
offset: 8,
|
|
@@ -2024,7 +2035,9 @@ export class VelocityClient {
|
|
|
2024
2035
|
public async getUserAccountsForAuthority(
|
|
2025
2036
|
authority: PublicKey
|
|
2026
2037
|
): Promise<UserAccount[]> {
|
|
2027
|
-
const programAccounts = await (
|
|
2038
|
+
const programAccounts: ProgramAccount<UserAccount>[] = await (
|
|
2039
|
+
this.program.account as any
|
|
2040
|
+
).user.all([
|
|
2028
2041
|
{
|
|
2029
2042
|
memcmp: {
|
|
2030
2043
|
offset: 8,
|
|
@@ -2042,7 +2055,9 @@ export class VelocityClient {
|
|
|
2042
2055
|
public async getReferredUserStatsAccountsByReferrer(
|
|
2043
2056
|
referrer: PublicKey
|
|
2044
2057
|
): Promise<UserStatsAccount[]> {
|
|
2045
|
-
const programAccounts = await (
|
|
2058
|
+
const programAccounts: ProgramAccount<UserStatsAccount>[] = await (
|
|
2059
|
+
this.program.account as any
|
|
2060
|
+
).userStats.all([
|
|
2046
2061
|
{
|
|
2047
2062
|
memcmp: {
|
|
2048
2063
|
offset: 40,
|
|
@@ -2060,7 +2075,7 @@ export class VelocityClient {
|
|
|
2060
2075
|
public async getReferrerNameAccountsForAuthority(
|
|
2061
2076
|
authority: PublicKey
|
|
2062
2077
|
): Promise<ReferrerNameAccount[]> {
|
|
2063
|
-
const programAccounts = await (
|
|
2078
|
+
const programAccounts: ProgramAccount<ReferrerNameAccount>[] = await (
|
|
2064
2079
|
this.program.account as any
|
|
2065
2080
|
).referrerName.all([
|
|
2066
2081
|
{
|
|
@@ -2164,7 +2179,9 @@ export class VelocityClient {
|
|
|
2164
2179
|
if (isSpotPositionAvailable(spotPosition)) {
|
|
2165
2180
|
continue;
|
|
2166
2181
|
}
|
|
2167
|
-
const spotMarket = this.
|
|
2182
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(
|
|
2183
|
+
spotPosition.marketIndex
|
|
2184
|
+
);
|
|
2168
2185
|
remainingAccounts.push({
|
|
2169
2186
|
isSigner: false,
|
|
2170
2187
|
isWritable: true,
|
|
@@ -2300,17 +2317,26 @@ export class VelocityClient {
|
|
|
2300
2317
|
public getUser(subAccountId?: number, authority?: PublicKey): User {
|
|
2301
2318
|
subAccountId = subAccountId ?? this.activeSubAccountId;
|
|
2302
2319
|
authority = authority ?? this.authority;
|
|
2320
|
+
|
|
2321
|
+
if (subAccountId === undefined || authority === undefined) {
|
|
2322
|
+
throw new Error('Subaccount ID and authority are required');
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2303
2325
|
const userMapKey = this.getUserMapKey(subAccountId, authority);
|
|
2304
2326
|
|
|
2305
|
-
|
|
2327
|
+
const user = this.users.get(userMapKey);
|
|
2328
|
+
if (!user) {
|
|
2306
2329
|
throw new Error(`VelocityClient has no user for user id ${userMapKey}`);
|
|
2307
2330
|
}
|
|
2308
|
-
return
|
|
2331
|
+
return user;
|
|
2309
2332
|
}
|
|
2310
2333
|
|
|
2311
2334
|
public hasUser(subAccountId?: number, authority?: PublicKey): boolean {
|
|
2312
2335
|
subAccountId = subAccountId ?? this.activeSubAccountId;
|
|
2313
2336
|
authority = authority ?? this.authority;
|
|
2337
|
+
if (subAccountId === undefined || authority === undefined) {
|
|
2338
|
+
throw new Error('Subaccount ID and authority are required');
|
|
2339
|
+
}
|
|
2314
2340
|
const userMapKey = this.getUserMapKey(subAccountId, authority);
|
|
2315
2341
|
|
|
2316
2342
|
return this.users.has(userMapKey);
|
|
@@ -2319,18 +2345,29 @@ export class VelocityClient {
|
|
|
2319
2345
|
public getUsers(): User[] {
|
|
2320
2346
|
// delegate users get added to the end
|
|
2321
2347
|
return [...this.users.values()]
|
|
2322
|
-
.filter(
|
|
2323
|
-
acct.getUserAccount()
|
|
2348
|
+
.filter(
|
|
2349
|
+
(acct) => acct.getUserAccount()?.authority.equals(this.wallet.publicKey)
|
|
2324
2350
|
)
|
|
2325
2351
|
.concat(
|
|
2326
2352
|
[...this.users.values()].filter(
|
|
2327
2353
|
(acct) =>
|
|
2328
|
-
!acct.getUserAccount()
|
|
2354
|
+
!acct.getUserAccount()?.authority.equals(this.wallet.publicKey)
|
|
2329
2355
|
)
|
|
2330
2356
|
);
|
|
2331
2357
|
}
|
|
2332
2358
|
|
|
2333
|
-
public getUserStats(): UserStats {
|
|
2359
|
+
public getUserStats(): UserStats | undefined {
|
|
2360
|
+
return this.userStats;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
/**
|
|
2364
|
+
* Like {@link getUserStats} but throws if there is no UserStats
|
|
2365
|
+
* subscription, for call sites that require a guaranteed account.
|
|
2366
|
+
*/
|
|
2367
|
+
public getUserStatsOrThrow(): UserStats {
|
|
2368
|
+
if (!this.userStats) {
|
|
2369
|
+
throw new Error('VelocityClient has no UserStats subscription');
|
|
2370
|
+
}
|
|
2334
2371
|
return this.userStats;
|
|
2335
2372
|
}
|
|
2336
2373
|
|
|
@@ -2347,7 +2384,6 @@ export class VelocityClient {
|
|
|
2347
2384
|
)) as ReferrerNameAccount;
|
|
2348
2385
|
}
|
|
2349
2386
|
|
|
2350
|
-
userStatsAccountPublicKey: PublicKey;
|
|
2351
2387
|
public getUserStatsAccountPublicKey(): PublicKey {
|
|
2352
2388
|
if (this.userStatsAccountPublicKey) {
|
|
2353
2389
|
return this.userStatsAccountPublicKey;
|
|
@@ -2374,6 +2410,18 @@ export class VelocityClient {
|
|
|
2374
2410
|
return this.getUser(subAccountId, authority).getUserAccount();
|
|
2375
2411
|
}
|
|
2376
2412
|
|
|
2413
|
+
/**
|
|
2414
|
+
* Like {@link getUserAccount} but throws a named error instead of returning
|
|
2415
|
+
* `undefined` when the account has not been loaded yet. Use at call sites
|
|
2416
|
+
* that structurally require a loaded account.
|
|
2417
|
+
*/
|
|
2418
|
+
public getUserAccountOrThrow(
|
|
2419
|
+
subAccountId?: number,
|
|
2420
|
+
authority?: PublicKey
|
|
2421
|
+
): UserAccount {
|
|
2422
|
+
return this.getUser(subAccountId, authority).getUserAccountOrThrow();
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2377
2425
|
/**
|
|
2378
2426
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
2379
2427
|
* @param subAccountId
|
|
@@ -2397,7 +2445,7 @@ export class VelocityClient {
|
|
|
2397
2445
|
marketIndex: number,
|
|
2398
2446
|
subAccountId?: number
|
|
2399
2447
|
): SpotPosition | undefined {
|
|
2400
|
-
return this.
|
|
2448
|
+
return this.getUserAccountOrThrow(subAccountId).spotPositions.find(
|
|
2401
2449
|
(spotPosition) => spotPosition.marketIndex === marketIndex
|
|
2402
2450
|
);
|
|
2403
2451
|
}
|
|
@@ -2425,7 +2473,7 @@ export class VelocityClient {
|
|
|
2425
2473
|
if (spotPosition === undefined) {
|
|
2426
2474
|
return ZERO;
|
|
2427
2475
|
}
|
|
2428
|
-
const spotMarket = this.
|
|
2476
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2429
2477
|
return getSignedTokenAmount(
|
|
2430
2478
|
getTokenAmount(
|
|
2431
2479
|
spotPosition.scaledBalance,
|
|
@@ -2442,7 +2490,7 @@ export class VelocityClient {
|
|
|
2442
2490
|
* @param amount
|
|
2443
2491
|
*/
|
|
2444
2492
|
public convertToSpotPrecision(marketIndex: number, amount: BN | number): BN {
|
|
2445
|
-
const spotMarket = this.
|
|
2493
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2446
2494
|
return castNumberToSpotPrecision(amount, spotMarket);
|
|
2447
2495
|
}
|
|
2448
2496
|
|
|
@@ -2492,8 +2540,52 @@ export class VelocityClient {
|
|
|
2492
2540
|
this.mustIncludeSpotMarketIndexes.add(spotMarketIndex);
|
|
2493
2541
|
});
|
|
2494
2542
|
}
|
|
2543
|
+
private cachePerpMarketSlot(
|
|
2544
|
+
slot: number | undefined,
|
|
2545
|
+
...marketIndexes: number[]
|
|
2546
|
+
): void {
|
|
2547
|
+
for (const marketIndex of marketIndexes) {
|
|
2548
|
+
if (slot !== undefined) {
|
|
2549
|
+
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
2550
|
+
} else {
|
|
2551
|
+
this.perpMarketLastSlotCache.delete(marketIndex);
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
private cacheSpotMarketSlot(
|
|
2557
|
+
slot: number | undefined,
|
|
2558
|
+
...marketIndexes: number[]
|
|
2559
|
+
): void {
|
|
2560
|
+
for (const marketIndex of marketIndexes) {
|
|
2561
|
+
if (slot !== undefined) {
|
|
2562
|
+
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
2563
|
+
} else {
|
|
2564
|
+
this.spotMarketLastSlotCache.delete(marketIndex);
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2495
2569
|
getRemainingAccounts(params: RemainingAccountParams): AccountMeta[] {
|
|
2496
|
-
return VelocityCore.remainingAccounts.getRemainingAccounts(
|
|
2570
|
+
return VelocityCore.remainingAccounts.getRemainingAccounts(
|
|
2571
|
+
{
|
|
2572
|
+
getPerpMarketAccount: (marketIndex: number) =>
|
|
2573
|
+
this.getPerpMarketAccountOrThrow(marketIndex),
|
|
2574
|
+
getSpotMarketAccount: (marketIndex: number) =>
|
|
2575
|
+
this.getSpotMarketAccountOrThrow(marketIndex),
|
|
2576
|
+
getUserAccountAndSlot: (
|
|
2577
|
+
subAccountId: number | undefined,
|
|
2578
|
+
authority: PublicKey
|
|
2579
|
+
) => this.getUserAccountAndSlot(subAccountId, authority),
|
|
2580
|
+
activeSubAccountId: this.activeSubAccountId,
|
|
2581
|
+
authority: this.authority,
|
|
2582
|
+
perpMarketLastSlotCache: this.perpMarketLastSlotCache,
|
|
2583
|
+
spotMarketLastSlotCache: this.spotMarketLastSlotCache,
|
|
2584
|
+
mustIncludePerpMarketIndexes: this.mustIncludePerpMarketIndexes,
|
|
2585
|
+
mustIncludeSpotMarketIndexes: this.mustIncludeSpotMarketIndexes,
|
|
2586
|
+
},
|
|
2587
|
+
params
|
|
2588
|
+
);
|
|
2497
2589
|
}
|
|
2498
2590
|
|
|
2499
2591
|
addPerpMarketToRemainingAccountMaps(
|
|
@@ -2503,7 +2595,7 @@ export class VelocityClient {
|
|
|
2503
2595
|
spotMarketAccountMap: Map<number, AccountMeta>,
|
|
2504
2596
|
perpMarketAccountMap: Map<number, AccountMeta>
|
|
2505
2597
|
): void {
|
|
2506
|
-
const perpMarketAccount = this.
|
|
2598
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
2507
2599
|
perpMarketAccountMap.set(marketIndex, {
|
|
2508
2600
|
pubkey: perpMarketAccount.pubkey,
|
|
2509
2601
|
isSigner: false,
|
|
@@ -2530,7 +2622,7 @@ export class VelocityClient {
|
|
|
2530
2622
|
oracleAccountMap: Map<string, AccountMeta>,
|
|
2531
2623
|
spotMarketAccountMap: Map<number, AccountMeta>
|
|
2532
2624
|
): void {
|
|
2533
|
-
const spotMarketAccount = this.
|
|
2625
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2534
2626
|
spotMarketAccountMap.set(spotMarketAccount.marketIndex, {
|
|
2535
2627
|
pubkey: spotMarketAccount.pubkey,
|
|
2536
2628
|
isSigner: false,
|
|
@@ -2633,12 +2725,37 @@ export class VelocityClient {
|
|
|
2633
2725
|
};
|
|
2634
2726
|
}
|
|
2635
2727
|
|
|
2636
|
-
|
|
2728
|
+
/**
|
|
2729
|
+
* Look up an open order by its program-assigned order ID from the cached user account.
|
|
2730
|
+
*
|
|
2731
|
+
* `orderId` is the monotonically incrementing u32 counter that the program assigns at
|
|
2732
|
+
* placement time — it is not known until the place instruction executes on-chain. Use
|
|
2733
|
+
* {@link getOrderByUserId} when you need to look up an order by the caller-supplied
|
|
2734
|
+
* `userOrderId` instead.
|
|
2735
|
+
*
|
|
2736
|
+
* Returns `undefined` when the order is not found (already filled, cancelled, or the
|
|
2737
|
+
* account cache is stale).
|
|
2738
|
+
*/
|
|
2739
|
+
public getOrder(
|
|
2740
|
+
orderId: number | undefined,
|
|
2741
|
+
subAccountId?: number
|
|
2742
|
+
): Order | undefined {
|
|
2637
2743
|
return this.getUserAccount(subAccountId)?.orders.find(
|
|
2638
2744
|
(order) => order.orderId === orderId
|
|
2639
2745
|
);
|
|
2640
2746
|
}
|
|
2641
2747
|
|
|
2748
|
+
/**
|
|
2749
|
+
* Look up an open order by the caller-supplied `userOrderId` from the cached user account.
|
|
2750
|
+
*
|
|
2751
|
+
* `userOrderId` is a 1-255 slot chosen by the caller in {@link OrderParams} and is stable
|
|
2752
|
+
* across the life of the order — useful when you need to reference an order before the
|
|
2753
|
+
* program-assigned {@link Order.orderId} is known (e.g. immediately after placing without
|
|
2754
|
+
* waiting for confirmation). Use {@link getOrder} when you have the program-assigned ID.
|
|
2755
|
+
*
|
|
2756
|
+
* Returns `undefined` when the order is not found (already filled, cancelled, or the
|
|
2757
|
+
* account cache is stale).
|
|
2758
|
+
*/
|
|
2642
2759
|
public getOrderByUserId(
|
|
2643
2760
|
userOrderId: number,
|
|
2644
2761
|
subAccountId?: number
|
|
@@ -2661,7 +2778,7 @@ export class VelocityClient {
|
|
|
2661
2778
|
authority = this.wallet.publicKey,
|
|
2662
2779
|
allowOwnerOffCurve = false
|
|
2663
2780
|
): Promise<PublicKey> {
|
|
2664
|
-
const spotMarket = this.
|
|
2781
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2665
2782
|
if (useNative && spotMarket.mint.equals(WRAPPED_SOL_MINT)) {
|
|
2666
2783
|
return authority;
|
|
2667
2784
|
}
|
|
@@ -2709,7 +2826,7 @@ export class VelocityClient {
|
|
|
2709
2826
|
authority?: PublicKey;
|
|
2710
2827
|
}
|
|
2711
2828
|
): Promise<TransactionInstruction[]> {
|
|
2712
|
-
const spotMarketAccount = this.
|
|
2829
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2713
2830
|
|
|
2714
2831
|
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
2715
2832
|
|
|
@@ -2893,7 +3010,7 @@ export class VelocityClient {
|
|
|
2893
3010
|
);
|
|
2894
3011
|
|
|
2895
3012
|
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
2896
|
-
this.
|
|
3013
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
2897
3014
|
return txSig;
|
|
2898
3015
|
}
|
|
2899
3016
|
|
|
@@ -2916,8 +3033,12 @@ export class VelocityClient {
|
|
|
2916
3033
|
|
|
2917
3034
|
let remainingAccounts = [];
|
|
2918
3035
|
if (userInitialized) {
|
|
3036
|
+
const userAccount = await this.forceGetUserAccount(subAccountId);
|
|
3037
|
+
if (!userAccount) {
|
|
3038
|
+
throw new Error('User account not loaded after force fetch');
|
|
3039
|
+
}
|
|
2919
3040
|
remainingAccounts = this.getRemainingAccounts({
|
|
2920
|
-
userAccounts: [
|
|
3041
|
+
userAccounts: [userAccount],
|
|
2921
3042
|
useMarketLastSlotCache: true,
|
|
2922
3043
|
writableSpotMarketIndexes: [marketIndex],
|
|
2923
3044
|
});
|
|
@@ -2928,7 +3049,7 @@ export class VelocityClient {
|
|
|
2928
3049
|
});
|
|
2929
3050
|
}
|
|
2930
3051
|
|
|
2931
|
-
const spotMarketAccount = this.
|
|
3052
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2932
3053
|
|
|
2933
3054
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
2934
3055
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
@@ -2991,7 +3112,11 @@ export class VelocityClient {
|
|
|
2991
3112
|
TOKEN_PROGRAM_ID
|
|
2992
3113
|
);
|
|
2993
3114
|
|
|
2994
|
-
const result
|
|
3115
|
+
const result: {
|
|
3116
|
+
ixs: TransactionInstruction[];
|
|
3117
|
+
signers: Signer[];
|
|
3118
|
+
pubkey: PublicKey;
|
|
3119
|
+
} = {
|
|
2995
3120
|
ixs: [],
|
|
2996
3121
|
signers: [],
|
|
2997
3122
|
pubkey: wrappedSolAccount,
|
|
@@ -3078,9 +3203,15 @@ export class VelocityClient {
|
|
|
3078
3203
|
mint,
|
|
3079
3204
|
hookAccount!.programId
|
|
3080
3205
|
);
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3206
|
+
const extraAccountMetasAccount = await this.connection.getAccountInfo(
|
|
3207
|
+
extraAccountMetasAddress
|
|
3083
3208
|
);
|
|
3209
|
+
if (!extraAccountMetasAccount) {
|
|
3210
|
+
throw new Error(
|
|
3211
|
+
'Extra account metas account not found for transfer hook'
|
|
3212
|
+
);
|
|
3213
|
+
}
|
|
3214
|
+
const extraAccountMetas = getExtraAccountMetas(extraAccountMetasAccount);
|
|
3084
3215
|
|
|
3085
3216
|
for (const acc of extraAccountMetas) {
|
|
3086
3217
|
// assuming it's an extra account meta that does not rely on ix data
|
|
@@ -3166,7 +3297,7 @@ export class VelocityClient {
|
|
|
3166
3297
|
ixs.push(initializeSignedMsgUserOrdersAccountIx);
|
|
3167
3298
|
}
|
|
3168
3299
|
|
|
3169
|
-
const spotMarket = this.
|
|
3300
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
3170
3301
|
|
|
3171
3302
|
const isSolMarket = spotMarket.mint.equals(WRAPPED_SOL_MINT);
|
|
3172
3303
|
|
|
@@ -3188,7 +3319,7 @@ export class VelocityClient {
|
|
|
3188
3319
|
|
|
3189
3320
|
const wSolAmount = isSolMarket ? amount.add(donateAmount) : donateAmount;
|
|
3190
3321
|
|
|
3191
|
-
let wsolTokenAccount: PublicKey;
|
|
3322
|
+
let wsolTokenAccount: PublicKey | undefined;
|
|
3192
3323
|
if (createWSOLTokenAccount) {
|
|
3193
3324
|
const { ixs: startIxs, pubkey } =
|
|
3194
3325
|
await this.getWrappedSolAccountCreationIxs(
|
|
@@ -3262,6 +3393,9 @@ export class VelocityClient {
|
|
|
3262
3393
|
ixs.push(depositCollateralIx);
|
|
3263
3394
|
|
|
3264
3395
|
if (!donateAmount.eq(ZERO)) {
|
|
3396
|
+
if (!wsolTokenAccount) {
|
|
3397
|
+
throw new Error('wsolTokenAccount is required to donate to rev pool');
|
|
3398
|
+
}
|
|
3265
3399
|
const donateIx = await this.getDepositIntoSpotMarketRevenuePoolIx(
|
|
3266
3400
|
1,
|
|
3267
3401
|
donateAmount,
|
|
@@ -3283,6 +3417,9 @@ export class VelocityClient {
|
|
|
3283
3417
|
// Close the wrapped sol account at the end of the transaction
|
|
3284
3418
|
// Return funds to the deposit source (external wallet if provided)
|
|
3285
3419
|
if (createWSOLTokenAccount) {
|
|
3420
|
+
if (!wsolTokenAccount) {
|
|
3421
|
+
throw new Error('wsolTokenAccount was not created');
|
|
3422
|
+
}
|
|
3286
3423
|
ixs.push(
|
|
3287
3424
|
createCloseAccountInstruction(
|
|
3288
3425
|
wsolTokenAccount,
|
|
@@ -3388,7 +3525,7 @@ export class VelocityClient {
|
|
|
3388
3525
|
additionalSigners,
|
|
3389
3526
|
this.opts
|
|
3390
3527
|
);
|
|
3391
|
-
this.
|
|
3528
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
3392
3529
|
|
|
3393
3530
|
await this.addUser(subAccountId);
|
|
3394
3531
|
|
|
@@ -3457,7 +3594,7 @@ export class VelocityClient {
|
|
|
3457
3594
|
): Promise<TransactionInstruction[]> {
|
|
3458
3595
|
const withdrawIxs: TransactionInstruction[] = [];
|
|
3459
3596
|
|
|
3460
|
-
const spotMarketAccount = this.
|
|
3597
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
3461
3598
|
|
|
3462
3599
|
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
3463
3600
|
|
|
@@ -3552,7 +3689,7 @@ export class VelocityClient {
|
|
|
3552
3689
|
additionalSigners,
|
|
3553
3690
|
this.opts
|
|
3554
3691
|
);
|
|
3555
|
-
this.
|
|
3692
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
3556
3693
|
return txSig;
|
|
3557
3694
|
}
|
|
3558
3695
|
|
|
@@ -3619,13 +3756,13 @@ export class VelocityClient {
|
|
|
3619
3756
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
3620
3757
|
|
|
3621
3758
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3622
|
-
userAccounts: [this.
|
|
3759
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
3623
3760
|
useMarketLastSlotCache: true,
|
|
3624
3761
|
writableSpotMarketIndexes: [marketIndex],
|
|
3625
3762
|
readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
3626
3763
|
});
|
|
3627
3764
|
|
|
3628
|
-
const spotMarketAccount = this.
|
|
3765
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
3629
3766
|
|
|
3630
3767
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
3631
3768
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
@@ -3687,7 +3824,7 @@ export class VelocityClient {
|
|
|
3687
3824
|
fromSubAccountId === this.activeSubAccountId ||
|
|
3688
3825
|
toSubAccountId === this.activeSubAccountId
|
|
3689
3826
|
) {
|
|
3690
|
-
this.
|
|
3827
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
3691
3828
|
}
|
|
3692
3829
|
return txSig;
|
|
3693
3830
|
}
|
|
@@ -3715,9 +3852,10 @@ export class VelocityClient {
|
|
|
3715
3852
|
fromSubAccountId,
|
|
3716
3853
|
this.wallet.publicKey
|
|
3717
3854
|
);
|
|
3718
|
-
|
|
3855
|
+
const mapUser = this.users.get(userMapKey);
|
|
3856
|
+
if (mapUser) {
|
|
3719
3857
|
remainingAccounts = this.getRemainingAccounts({
|
|
3720
|
-
userAccounts: [
|
|
3858
|
+
userAccounts: [mapUser.getUserAccountOrThrow()],
|
|
3721
3859
|
useMarketLastSlotCache: true,
|
|
3722
3860
|
writableSpotMarketIndexes: [marketIndex],
|
|
3723
3861
|
});
|
|
@@ -3745,7 +3883,7 @@ export class VelocityClient {
|
|
|
3745
3883
|
toUser,
|
|
3746
3884
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
3747
3885
|
state: await this.getStatePublicKey(),
|
|
3748
|
-
spotMarketVault: this.
|
|
3886
|
+
spotMarketVault: this.getSpotMarketAccountOrThrow(marketIndex).vault,
|
|
3749
3887
|
},
|
|
3750
3888
|
remainingAccounts,
|
|
3751
3889
|
});
|
|
@@ -3775,7 +3913,7 @@ export class VelocityClient {
|
|
|
3775
3913
|
fromSubAccountId === this.activeSubAccountId ||
|
|
3776
3914
|
toSubAccountId === this.activeSubAccountId
|
|
3777
3915
|
) {
|
|
3778
|
-
this.
|
|
3916
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
3779
3917
|
}
|
|
3780
3918
|
return txSig;
|
|
3781
3919
|
}
|
|
@@ -3800,9 +3938,10 @@ export class VelocityClient {
|
|
|
3800
3938
|
let remainingAccounts;
|
|
3801
3939
|
|
|
3802
3940
|
const userMapKey = this.getUserMapKey(fromSubAccountId, this.authority);
|
|
3803
|
-
|
|
3941
|
+
const mapUser = this.users.get(userMapKey);
|
|
3942
|
+
if (mapUser) {
|
|
3804
3943
|
remainingAccounts = this.getRemainingAccounts({
|
|
3805
|
-
userAccounts: [
|
|
3944
|
+
userAccounts: [mapUser.getUserAccountOrThrow()],
|
|
3806
3945
|
useMarketLastSlotCache: true,
|
|
3807
3946
|
writableSpotMarketIndexes: [marketIndex],
|
|
3808
3947
|
});
|
|
@@ -3827,7 +3966,7 @@ export class VelocityClient {
|
|
|
3827
3966
|
toUser,
|
|
3828
3967
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
3829
3968
|
state: await this.getStatePublicKey(),
|
|
3830
|
-
spotMarketVault: this.
|
|
3969
|
+
spotMarketVault: this.getSpotMarketAccountOrThrow(marketIndex).vault,
|
|
3831
3970
|
},
|
|
3832
3971
|
remainingAccounts,
|
|
3833
3972
|
}
|
|
@@ -3867,10 +4006,13 @@ export class VelocityClient {
|
|
|
3867
4006
|
fromSubAccountId === this.activeSubAccountId ||
|
|
3868
4007
|
toSubAccountId === this.activeSubAccountId
|
|
3869
4008
|
) {
|
|
3870
|
-
this.
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
4009
|
+
this.cacheSpotMarketSlot(
|
|
4010
|
+
slot,
|
|
4011
|
+
depositFromMarketIndex,
|
|
4012
|
+
depositToMarketIndex,
|
|
4013
|
+
borrowFromMarketIndex,
|
|
4014
|
+
borrowToMarketIndex
|
|
4015
|
+
);
|
|
3874
4016
|
}
|
|
3875
4017
|
return txSig;
|
|
3876
4018
|
}
|
|
@@ -3897,10 +4039,10 @@ export class VelocityClient {
|
|
|
3897
4039
|
toSubAccountId
|
|
3898
4040
|
);
|
|
3899
4041
|
|
|
3900
|
-
const userAccounts = [this.
|
|
4042
|
+
const userAccounts = [this.getUserAccountOrThrow(fromSubAccountId)];
|
|
3901
4043
|
|
|
3902
4044
|
if (!isToNewSubAccount) {
|
|
3903
|
-
userAccounts.push(this.
|
|
4045
|
+
userAccounts.push(this.getUserAccountOrThrow(toSubAccountId));
|
|
3904
4046
|
}
|
|
3905
4047
|
|
|
3906
4048
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -3915,10 +4057,10 @@ export class VelocityClient {
|
|
|
3915
4057
|
});
|
|
3916
4058
|
|
|
3917
4059
|
const tokenPrograms = new Set<string>();
|
|
3918
|
-
const depositFromSpotMarket = this.
|
|
4060
|
+
const depositFromSpotMarket = this.getSpotMarketAccountOrThrow(
|
|
3919
4061
|
depositFromMarketIndex
|
|
3920
4062
|
);
|
|
3921
|
-
const borrowFromSpotMarket = this.
|
|
4063
|
+
const borrowFromSpotMarket = this.getSpotMarketAccountOrThrow(
|
|
3922
4064
|
borrowFromMarketIndex
|
|
3923
4065
|
);
|
|
3924
4066
|
|
|
@@ -3951,16 +4093,16 @@ export class VelocityClient {
|
|
|
3951
4093
|
toUser,
|
|
3952
4094
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
3953
4095
|
state: await this.getStatePublicKey(),
|
|
3954
|
-
depositFromSpotMarketVault: this.
|
|
4096
|
+
depositFromSpotMarketVault: this.getSpotMarketAccountOrThrow(
|
|
3955
4097
|
depositFromMarketIndex
|
|
3956
4098
|
).vault,
|
|
3957
4099
|
depositToSpotMarketVault:
|
|
3958
|
-
this.
|
|
3959
|
-
borrowFromSpotMarketVault: this.
|
|
4100
|
+
this.getSpotMarketAccountOrThrow(depositToMarketIndex).vault,
|
|
4101
|
+
borrowFromSpotMarketVault: this.getSpotMarketAccountOrThrow(
|
|
3960
4102
|
borrowFromMarketIndex
|
|
3961
4103
|
).vault,
|
|
3962
4104
|
borrowToSpotMarketVault:
|
|
3963
|
-
this.
|
|
4105
|
+
this.getSpotMarketAccountOrThrow(borrowToMarketIndex).vault,
|
|
3964
4106
|
velocitySigner: this.getSignerPublicKey(),
|
|
3965
4107
|
},
|
|
3966
4108
|
remainingAccounts,
|
|
@@ -4010,8 +4152,8 @@ export class VelocityClient {
|
|
|
4010
4152
|
|
|
4011
4153
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4012
4154
|
userAccounts: [
|
|
4013
|
-
this.
|
|
4014
|
-
this.
|
|
4155
|
+
this.getUserAccountOrThrow(fromSubAccountId),
|
|
4156
|
+
this.getUserAccountOrThrow(toSubAccountId),
|
|
4015
4157
|
],
|
|
4016
4158
|
useMarketLastSlotCache: true,
|
|
4017
4159
|
writablePerpMarketIndexes: [marketIndex],
|
|
@@ -4108,9 +4250,9 @@ export class VelocityClient {
|
|
|
4108
4250
|
subAccountId ?? this.activeSubAccountId
|
|
4109
4251
|
);
|
|
4110
4252
|
|
|
4111
|
-
const perpMarketAccount = this.
|
|
4253
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4112
4254
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
4113
|
-
const spotMarketAccount = this.
|
|
4255
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
4114
4256
|
|
|
4115
4257
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4116
4258
|
userAccounts: [],
|
|
@@ -4165,7 +4307,7 @@ export class VelocityClient {
|
|
|
4165
4307
|
this.authority,
|
|
4166
4308
|
subAccountId ?? this.activeSubAccountId
|
|
4167
4309
|
),
|
|
4168
|
-
this.
|
|
4310
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
4169
4311
|
[perpMarketIndex],
|
|
4170
4312
|
SettlePnlMode.TRY_SETTLE
|
|
4171
4313
|
);
|
|
@@ -4195,10 +4337,10 @@ export class VelocityClient {
|
|
|
4195
4337
|
subAccountId ?? this.activeSubAccountId
|
|
4196
4338
|
);
|
|
4197
4339
|
|
|
4198
|
-
const perpMarketAccount = this.
|
|
4340
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4199
4341
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
4200
|
-
const spotMarketAccount = this.
|
|
4201
|
-
const user = await this.
|
|
4342
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
4343
|
+
const user = await this.getUserAccountOrThrow(subAccountId);
|
|
4202
4344
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4203
4345
|
userAccounts: [user],
|
|
4204
4346
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
@@ -4258,18 +4400,26 @@ export class VelocityClient {
|
|
|
4258
4400
|
this.authority,
|
|
4259
4401
|
subAccountId ?? this.activeSubAccountId
|
|
4260
4402
|
);
|
|
4261
|
-
const userAccount = this.
|
|
4403
|
+
const userAccount = this.getUserAccountOrThrow(subAccountId);
|
|
4262
4404
|
|
|
4263
4405
|
const tokenAmountDeposited =
|
|
4264
4406
|
this.getIsolatedPerpPositionTokenAmount(perpMarketIndex);
|
|
4407
|
+
const isolatedPerpPosition = userAccount.perpPositions.find(
|
|
4408
|
+
(p) => p.marketIndex === perpMarketIndex
|
|
4409
|
+
);
|
|
4410
|
+
if (!isolatedPerpPosition) {
|
|
4411
|
+
throw new Error(
|
|
4412
|
+
`No perp position found for market index ${perpMarketIndex}`
|
|
4413
|
+
);
|
|
4414
|
+
}
|
|
4265
4415
|
const isolatedPositionUnrealizedPnl = calculateClaimablePnl(
|
|
4266
|
-
this.
|
|
4267
|
-
this.
|
|
4268
|
-
this.
|
|
4416
|
+
this.getPerpMarketAccountOrThrow(perpMarketIndex),
|
|
4417
|
+
this.getSpotMarketAccountOrThrow(
|
|
4418
|
+
this.getPerpMarketAccountOrThrow(perpMarketIndex).quoteSpotMarketIndex
|
|
4269
4419
|
),
|
|
4270
|
-
|
|
4420
|
+
isolatedPerpPosition,
|
|
4271
4421
|
this.getOracleDataForSpotMarket(
|
|
4272
|
-
this.
|
|
4422
|
+
this.getPerpMarketAccountOrThrow(perpMarketIndex).quoteSpotMarketIndex
|
|
4273
4423
|
)
|
|
4274
4424
|
);
|
|
4275
4425
|
|
|
@@ -4282,7 +4432,8 @@ export class VelocityClient {
|
|
|
4282
4432
|
: amount;
|
|
4283
4433
|
let associatedTokenAccount = userTokenAccount;
|
|
4284
4434
|
if (!associatedTokenAccount) {
|
|
4285
|
-
const perpMarketAccount =
|
|
4435
|
+
const perpMarketAccount =
|
|
4436
|
+
this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4286
4437
|
const quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
4287
4438
|
associatedTokenAccount = await this.getAssociatedTokenAccount(
|
|
4288
4439
|
quoteSpotMarketIndex
|
|
@@ -4323,11 +4474,11 @@ export class VelocityClient {
|
|
|
4323
4474
|
this.authority,
|
|
4324
4475
|
subAccountId ?? this.activeSubAccountId
|
|
4325
4476
|
);
|
|
4326
|
-
const perpMarketAccount = this.
|
|
4477
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4327
4478
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
4328
|
-
const spotMarketAccount = this.
|
|
4479
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
4329
4480
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4330
|
-
userAccounts: [this.
|
|
4481
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
4331
4482
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
4332
4483
|
readablePerpMarketIndex: [perpMarketIndex],
|
|
4333
4484
|
});
|
|
@@ -4370,7 +4521,7 @@ export class VelocityClient {
|
|
|
4370
4521
|
public async updateSpotMarketCumulativeInterestIx(
|
|
4371
4522
|
marketIndex: number
|
|
4372
4523
|
): Promise<TransactionInstruction> {
|
|
4373
|
-
const spotMarket = this.
|
|
4524
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4374
4525
|
return await this.program.instruction.updateSpotMarketCumulativeInterest({
|
|
4375
4526
|
accounts: {
|
|
4376
4527
|
state: await this.getStatePublicKey(),
|
|
@@ -4449,7 +4600,7 @@ export class VelocityClient {
|
|
|
4449
4600
|
|
|
4450
4601
|
const ixPromisesForTxs: Record<
|
|
4451
4602
|
TxKeys,
|
|
4452
|
-
Promise<TransactionInstruction | TransactionInstruction[]>
|
|
4603
|
+
Promise<TransactionInstruction | TransactionInstruction[]> | undefined
|
|
4453
4604
|
> = {
|
|
4454
4605
|
cancelExistingOrdersTx: undefined,
|
|
4455
4606
|
settlePnlTx: undefined,
|
|
@@ -4514,7 +4665,12 @@ export class VelocityClient {
|
|
|
4514
4665
|
|
|
4515
4666
|
const ixs = await Promise.all(Object.values(ixPromisesForTxs));
|
|
4516
4667
|
|
|
4517
|
-
const ixsMap = ixs.reduce
|
|
4668
|
+
const ixsMap = ixs.reduce<
|
|
4669
|
+
Record<
|
|
4670
|
+
string,
|
|
4671
|
+
TransactionInstruction | TransactionInstruction[] | undefined
|
|
4672
|
+
>
|
|
4673
|
+
>((acc, ix, i) => {
|
|
4518
4674
|
acc[txKeys[i]] = ix;
|
|
4519
4675
|
return acc;
|
|
4520
4676
|
}, {}) as MappedRecord<
|
|
@@ -4578,7 +4734,7 @@ export class VelocityClient {
|
|
|
4578
4734
|
true
|
|
4579
4735
|
);
|
|
4580
4736
|
|
|
4581
|
-
this.
|
|
4737
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
4582
4738
|
|
|
4583
4739
|
return {
|
|
4584
4740
|
txSig,
|
|
@@ -4622,7 +4778,7 @@ export class VelocityClient {
|
|
|
4622
4778
|
[],
|
|
4623
4779
|
this.opts
|
|
4624
4780
|
);
|
|
4625
|
-
this.
|
|
4781
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
4626
4782
|
return txSig;
|
|
4627
4783
|
}
|
|
4628
4784
|
|
|
@@ -4708,7 +4864,7 @@ export class VelocityClient {
|
|
|
4708
4864
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4709
4865
|
userAccounts: depositToTradeArgs?.isMakingNewAccount
|
|
4710
4866
|
? []
|
|
4711
|
-
: [this.
|
|
4867
|
+
: [this.getUserAccountOrThrow(subAccountId)],
|
|
4712
4868
|
useMarketLastSlotCache: false,
|
|
4713
4869
|
readablePerpMarketIndex: orderParams.marketIndex,
|
|
4714
4870
|
readableSpotMarketIndexes: isDepositToTradeTx
|
|
@@ -4756,7 +4912,7 @@ export class VelocityClient {
|
|
|
4756
4912
|
const marketAccountInfos = [];
|
|
4757
4913
|
const oracleAccountInfos = [];
|
|
4758
4914
|
for (const marketIndex of marketIndexes) {
|
|
4759
|
-
const market = this.
|
|
4915
|
+
const market = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
4760
4916
|
marketAccountInfos.push({
|
|
4761
4917
|
pubkey: market.pubkey,
|
|
4762
4918
|
isWritable: true,
|
|
@@ -4861,6 +5017,20 @@ export class VelocityClient {
|
|
|
4861
5017
|
);
|
|
4862
5018
|
}
|
|
4863
5019
|
|
|
5020
|
+
/**
|
|
5021
|
+
* Cancel an open order and broadcast the transaction.
|
|
5022
|
+
*
|
|
5023
|
+
* When `orderId` is `undefined` (omitted or passed explicitly), the instruction is
|
|
5024
|
+
* sent with a `null` order ID and the program cancels the most recently placed order
|
|
5025
|
+
* on-chain via `get_last_order_id`. This is safe to use in a composed transaction
|
|
5026
|
+
* where a place instruction runs first and the assigned order ID is not yet known.
|
|
5027
|
+
*
|
|
5028
|
+
* Note: when `orderId` is `undefined` and `overrides.withdrawIsolatedDepositAmount`
|
|
5029
|
+
* is also provided, `getOrder` will return `undefined` (the ID is unknown client-side),
|
|
5030
|
+
* causing the withdraw path to throw — supply an explicit `orderId` in that case.
|
|
5031
|
+
*
|
|
5032
|
+
* @see {@link getCancelOrderIx} to obtain the instruction without sending.
|
|
5033
|
+
*/
|
|
4864
5034
|
public async cancelOrder(
|
|
4865
5035
|
orderId?: number,
|
|
4866
5036
|
txParams?: TxParams,
|
|
@@ -4877,6 +5047,11 @@ export class VelocityClient {
|
|
|
4877
5047
|
const withdrawAmount = overrides.withdrawIsolatedDepositAmount;
|
|
4878
5048
|
|
|
4879
5049
|
if (withdrawAmount.gt(ZERO)) {
|
|
5050
|
+
if (perpMarketIndex === undefined) {
|
|
5051
|
+
throw new Error(
|
|
5052
|
+
`Order ${orderId} not found when withdrawing isolated deposit`
|
|
5053
|
+
);
|
|
5054
|
+
}
|
|
4880
5055
|
const withdrawIxs =
|
|
4881
5056
|
await this.getWithdrawFromIsolatedPerpPositionIxsBundle(
|
|
4882
5057
|
withdrawAmount,
|
|
@@ -4895,6 +5070,21 @@ export class VelocityClient {
|
|
|
4895
5070
|
return txSig;
|
|
4896
5071
|
}
|
|
4897
5072
|
|
|
5073
|
+
/**
|
|
5074
|
+
* Build a `cancelOrder` instruction for the given order.
|
|
5075
|
+
*
|
|
5076
|
+
* When `orderId` is `undefined` (omitted or passed explicitly), the instruction is
|
|
5077
|
+
* built with a `null` order ID (`orderId ?? null`). The program interprets a `null`
|
|
5078
|
+
* ID as "cancel the user's most recently placed order" (via `get_last_order_id`
|
|
5079
|
+
* on-chain). This is useful when composing a multi-instruction transaction where a
|
|
5080
|
+
* place instruction precedes the cancel and the program-assigned order ID is not yet
|
|
5081
|
+
* known at build time.
|
|
5082
|
+
*
|
|
5083
|
+
* When `orderId` is supplied, only that specific order is cancelled.
|
|
5084
|
+
*
|
|
5085
|
+
* @see {@link cancelOrder} to send the transaction directly.
|
|
5086
|
+
* @see {@link getCancelOrderByUserIdIx} to cancel by the caller-supplied `userOrderId`.
|
|
5087
|
+
*/
|
|
4898
5088
|
public async getCancelOrderIx(
|
|
4899
5089
|
orderId?: number,
|
|
4900
5090
|
subAccountId?: number
|
|
@@ -4902,7 +5092,7 @@ export class VelocityClient {
|
|
|
4902
5092
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4903
5093
|
|
|
4904
5094
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4905
|
-
userAccounts: [this.
|
|
5095
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
4906
5096
|
useMarketLastSlotCache: true,
|
|
4907
5097
|
});
|
|
4908
5098
|
|
|
@@ -4938,11 +5128,14 @@ export class VelocityClient {
|
|
|
4938
5128
|
): Promise<TransactionInstruction> {
|
|
4939
5129
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4940
5130
|
|
|
4941
|
-
const order = this.getOrderByUserId(userOrderId);
|
|
4942
|
-
|
|
5131
|
+
const order = this.getOrderByUserId(userOrderId, subAccountId);
|
|
5132
|
+
if (!order) {
|
|
5133
|
+
throw new Error(`Order with user order id ${userOrderId} not found`);
|
|
5134
|
+
}
|
|
5135
|
+
const oracle = this.getPerpMarketAccountOrThrow(order.marketIndex).oracle;
|
|
4943
5136
|
|
|
4944
5137
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4945
|
-
userAccounts: [this.
|
|
5138
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
4946
5139
|
useMarketLastSlotCache: true,
|
|
4947
5140
|
});
|
|
4948
5141
|
|
|
@@ -5011,7 +5204,7 @@ export class VelocityClient {
|
|
|
5011
5204
|
user?.userAccountPublicKey ??
|
|
5012
5205
|
(await this.getUserAccountPublicKey(subAccountId));
|
|
5013
5206
|
const userAccount =
|
|
5014
|
-
user?.getUserAccount() ?? this.
|
|
5207
|
+
user?.getUserAccount() ?? this.getUserAccountOrThrow(subAccountId);
|
|
5015
5208
|
|
|
5016
5209
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5017
5210
|
userAccounts: [userAccount],
|
|
@@ -5054,9 +5247,9 @@ export class VelocityClient {
|
|
|
5054
5247
|
}
|
|
5055
5248
|
|
|
5056
5249
|
public async getCancelOrdersIx(
|
|
5057
|
-
marketType: MarketType | null,
|
|
5058
|
-
marketIndex: number | null,
|
|
5059
|
-
direction: PositionDirection | null,
|
|
5250
|
+
marketType: MarketType | null | undefined,
|
|
5251
|
+
marketIndex: number | null | undefined,
|
|
5252
|
+
direction: PositionDirection | null | undefined,
|
|
5060
5253
|
subAccountId?: number
|
|
5061
5254
|
): Promise<TransactionInstruction> {
|
|
5062
5255
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
@@ -5073,7 +5266,7 @@ export class VelocityClient {
|
|
|
5073
5266
|
}
|
|
5074
5267
|
|
|
5075
5268
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5076
|
-
userAccounts: [this.
|
|
5269
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
5077
5270
|
readablePerpMarketIndex,
|
|
5078
5271
|
readableSpotMarketIndexes,
|
|
5079
5272
|
useMarketLastSlotCache: true,
|
|
@@ -5204,7 +5397,7 @@ export class VelocityClient {
|
|
|
5204
5397
|
}
|
|
5205
5398
|
|
|
5206
5399
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5207
|
-
userAccounts: [this.
|
|
5400
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
5208
5401
|
readablePerpMarketIndex,
|
|
5209
5402
|
readableSpotMarketIndexes,
|
|
5210
5403
|
useMarketLastSlotCache: true,
|
|
@@ -5258,7 +5451,7 @@ export class VelocityClient {
|
|
|
5258
5451
|
}
|
|
5259
5452
|
|
|
5260
5453
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5261
|
-
userAccounts: [this.
|
|
5454
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
5262
5455
|
readablePerpMarketIndex,
|
|
5263
5456
|
readableSpotMarketIndexes,
|
|
5264
5457
|
useMarketLastSlotCache: true,
|
|
@@ -5343,7 +5536,7 @@ export class VelocityClient {
|
|
|
5343
5536
|
const isPerp = isVariant(params.marketType, 'perp');
|
|
5344
5537
|
|
|
5345
5538
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5346
|
-
userAccounts: [this.
|
|
5539
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
5347
5540
|
readablePerpMarketIndex: isPerp ? [params.marketIndex] : [],
|
|
5348
5541
|
readableSpotMarketIndexes: isPerp ? [] : [params.marketIndex],
|
|
5349
5542
|
useMarketLastSlotCache: true,
|
|
@@ -5413,7 +5606,7 @@ export class VelocityClient {
|
|
|
5413
5606
|
public async getFillPerpOrderIx(
|
|
5414
5607
|
userAccountPublicKey: PublicKey,
|
|
5415
5608
|
userAccount: UserAccount,
|
|
5416
|
-
order
|
|
5609
|
+
order?: Pick<Order, 'marketIndex' | 'orderId'>,
|
|
5417
5610
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
5418
5611
|
fillerSubAccountId?: number,
|
|
5419
5612
|
isSignedMsg?: boolean,
|
|
@@ -5457,7 +5650,10 @@ export class VelocityClient {
|
|
|
5457
5650
|
? order.marketIndex
|
|
5458
5651
|
: userAccount.orders.find(
|
|
5459
5652
|
(order) => order.orderId === userAccount.nextOrderId - 1
|
|
5460
|
-
)
|
|
5653
|
+
)?.marketIndex;
|
|
5654
|
+
if (marketIndex === undefined) {
|
|
5655
|
+
throw new Error('No order found to fill');
|
|
5656
|
+
}
|
|
5461
5657
|
|
|
5462
5658
|
makerInfo = Array.isArray(makerInfo)
|
|
5463
5659
|
? makerInfo
|
|
@@ -5515,7 +5711,13 @@ export class VelocityClient {
|
|
|
5515
5711
|
remainingAccounts.push(takerEscrowMeta);
|
|
5516
5712
|
}
|
|
5517
5713
|
|
|
5518
|
-
|
|
5714
|
+
let orderId: number | null = null;
|
|
5715
|
+
if (!isSignedMsg) {
|
|
5716
|
+
if (!order) {
|
|
5717
|
+
throw new Error('order is required to fill a non-signedMsg order');
|
|
5718
|
+
}
|
|
5719
|
+
orderId = order.orderId;
|
|
5720
|
+
}
|
|
5519
5721
|
return await VelocityCore.buildFillPerpOrderInstruction({
|
|
5520
5722
|
program: this.program,
|
|
5521
5723
|
orderId,
|
|
@@ -5717,8 +5919,7 @@ export class VelocityClient {
|
|
|
5717
5919
|
)) as VersionedTransaction;
|
|
5718
5920
|
|
|
5719
5921
|
const { txSig, slot } = await this.sendTransaction(tx);
|
|
5720
|
-
this.
|
|
5721
|
-
this.spotMarketLastSlotCache.set(inMarketIndex, slot);
|
|
5922
|
+
this.cacheSpotMarketSlot(slot, outMarketIndex, inMarketIndex);
|
|
5722
5923
|
|
|
5723
5924
|
return txSig;
|
|
5724
5925
|
}
|
|
@@ -5751,8 +5952,8 @@ export class VelocityClient {
|
|
|
5751
5952
|
ixs: TransactionInstruction[];
|
|
5752
5953
|
lookupTables: AddressLookupTableAccount[];
|
|
5753
5954
|
}> {
|
|
5754
|
-
const outMarket = this.
|
|
5755
|
-
const inMarket = this.
|
|
5955
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
5956
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
5756
5957
|
|
|
5757
5958
|
const isExactOut = swapMode === 'ExactOut';
|
|
5758
5959
|
const exactOutBufferedAmountIn = amount.muln(1001).divn(1000); // Add 10bp buffer
|
|
@@ -5873,8 +6074,8 @@ export class VelocityClient {
|
|
|
5873
6074
|
ixs: TransactionInstruction[];
|
|
5874
6075
|
lookupTables: AddressLookupTableAccount[];
|
|
5875
6076
|
}> {
|
|
5876
|
-
const outMarket = this.
|
|
5877
|
-
const inMarket = this.
|
|
6077
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
6078
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
5878
6079
|
|
|
5879
6080
|
if (!quote) {
|
|
5880
6081
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
@@ -6022,8 +6223,11 @@ export class VelocityClient {
|
|
|
6022
6223
|
|
|
6023
6224
|
const userAccounts = [];
|
|
6024
6225
|
try {
|
|
6025
|
-
|
|
6026
|
-
|
|
6226
|
+
const userAccount = this.hasUser()
|
|
6227
|
+
? this.getUser().getUserAccount()
|
|
6228
|
+
: undefined;
|
|
6229
|
+
if (userAccount) {
|
|
6230
|
+
userAccounts.push(userAccount);
|
|
6027
6231
|
}
|
|
6028
6232
|
} catch (err) {
|
|
6029
6233
|
// ignore
|
|
@@ -6035,8 +6239,8 @@ export class VelocityClient {
|
|
|
6035
6239
|
readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
6036
6240
|
});
|
|
6037
6241
|
|
|
6038
|
-
const outSpotMarket = this.
|
|
6039
|
-
const inSpotMarket = this.
|
|
6242
|
+
const outSpotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
6243
|
+
const inSpotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
6040
6244
|
|
|
6041
6245
|
const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
|
|
6042
6246
|
const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
|
|
@@ -6157,8 +6361,8 @@ export class VelocityClient {
|
|
|
6157
6361
|
lookupTables: AddressLookupTableAccount[];
|
|
6158
6362
|
}> {
|
|
6159
6363
|
// Get market accounts to determine mints
|
|
6160
|
-
const outMarket = this.
|
|
6161
|
-
const inMarket = this.
|
|
6364
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
6365
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
6162
6366
|
|
|
6163
6367
|
const isExactOut = swapMode === 'ExactOut';
|
|
6164
6368
|
|
|
@@ -6278,7 +6482,7 @@ export class VelocityClient {
|
|
|
6278
6482
|
amount: BN;
|
|
6279
6483
|
userAccountPublicKey?: PublicKey;
|
|
6280
6484
|
}): Promise<TransactionInstruction[]> {
|
|
6281
|
-
const wSOLMint = this.
|
|
6485
|
+
const wSOLMint = this.getSpotMarketAccountOrThrow(1).mint;
|
|
6282
6486
|
const mSOLAccount = await this.getAssociatedTokenAccount(2);
|
|
6283
6487
|
const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
|
|
6284
6488
|
|
|
@@ -6607,7 +6811,7 @@ export class VelocityClient {
|
|
|
6607
6811
|
[],
|
|
6608
6812
|
this.opts
|
|
6609
6813
|
);
|
|
6610
|
-
this.
|
|
6814
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
6611
6815
|
return txSig;
|
|
6612
6816
|
}
|
|
6613
6817
|
public async preparePlaceAndTakePerpOrderWithAdditionalOrders(
|
|
@@ -6623,15 +6827,18 @@ export class VelocityClient {
|
|
|
6623
6827
|
optionalIxs?: TransactionInstruction[],
|
|
6624
6828
|
isolatedPositionDepositAmount?: BN
|
|
6625
6829
|
): Promise<{
|
|
6626
|
-
placeAndTakeTx: Transaction | VersionedTransaction;
|
|
6627
|
-
cancelExistingOrdersTx: Transaction | VersionedTransaction;
|
|
6628
|
-
settlePnlTx: Transaction | VersionedTransaction;
|
|
6629
|
-
}> {
|
|
6830
|
+
placeAndTakeTx: Transaction | VersionedTransaction | undefined;
|
|
6831
|
+
cancelExistingOrdersTx: Transaction | VersionedTransaction | undefined;
|
|
6832
|
+
settlePnlTx: Transaction | VersionedTransaction | undefined;
|
|
6833
|
+
} | null> {
|
|
6630
6834
|
const placeAndTakeIxs: TransactionInstruction[] = [];
|
|
6631
6835
|
|
|
6632
6836
|
type TxKeys = 'placeAndTakeTx' | 'cancelExistingOrdersTx' | 'settlePnlTx';
|
|
6633
6837
|
|
|
6634
|
-
const txsToSign: Record<
|
|
6838
|
+
const txsToSign: Record<
|
|
6839
|
+
TxKeys,
|
|
6840
|
+
Transaction | VersionedTransaction | undefined
|
|
6841
|
+
> = {
|
|
6635
6842
|
placeAndTakeTx: undefined,
|
|
6636
6843
|
cancelExistingOrdersTx: undefined,
|
|
6637
6844
|
settlePnlTx: undefined,
|
|
@@ -6693,6 +6900,11 @@ export class VelocityClient {
|
|
|
6693
6900
|
};
|
|
6694
6901
|
|
|
6695
6902
|
if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
|
|
6903
|
+
if (!txParams) {
|
|
6904
|
+
throw new Error(
|
|
6905
|
+
'txParams is required when simulating compute units or exiting early on failed simulation'
|
|
6906
|
+
);
|
|
6907
|
+
}
|
|
6696
6908
|
const placeAndTakeTxToSim = (await this.buildTransaction(
|
|
6697
6909
|
placeAndTakeIxs,
|
|
6698
6910
|
txParams,
|
|
@@ -6774,7 +6986,7 @@ export class VelocityClient {
|
|
|
6774
6986
|
|
|
6775
6987
|
const settlePnlIx = await this.settlePNLIx(
|
|
6776
6988
|
userAccountPublicKey,
|
|
6777
|
-
this.
|
|
6989
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
6778
6990
|
orderParams.marketIndex
|
|
6779
6991
|
);
|
|
6780
6992
|
|
|
@@ -6817,7 +7029,7 @@ export class VelocityClient {
|
|
|
6817
7029
|
txSig: TransactionSignature;
|
|
6818
7030
|
signedCancelExistingOrdersTx?: Transaction;
|
|
6819
7031
|
signedSettlePnlTx?: Transaction;
|
|
6820
|
-
}> {
|
|
7032
|
+
} | null> {
|
|
6821
7033
|
const txsToSign =
|
|
6822
7034
|
await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(
|
|
6823
7035
|
orderParams,
|
|
@@ -6842,6 +7054,10 @@ export class VelocityClient {
|
|
|
6842
7054
|
)
|
|
6843
7055
|
).signedTxMap;
|
|
6844
7056
|
|
|
7057
|
+
if (!signedTxs.placeAndTakeTx) {
|
|
7058
|
+
throw new Error('placeAndTakeTx was not built');
|
|
7059
|
+
}
|
|
7060
|
+
|
|
6845
7061
|
const { txSig, slot } = await this.sendTransaction(
|
|
6846
7062
|
signedTxs.placeAndTakeTx,
|
|
6847
7063
|
[],
|
|
@@ -6849,7 +7065,7 @@ export class VelocityClient {
|
|
|
6849
7065
|
true
|
|
6850
7066
|
);
|
|
6851
7067
|
|
|
6852
|
-
this.
|
|
7068
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
6853
7069
|
|
|
6854
7070
|
return {
|
|
6855
7071
|
txSig,
|
|
@@ -6884,7 +7100,7 @@ export class VelocityClient {
|
|
|
6884
7100
|
? [makerInfo]
|
|
6885
7101
|
: [];
|
|
6886
7102
|
|
|
6887
|
-
const userAccounts = [this.
|
|
7103
|
+
const userAccounts = [this.getUserAccountOrThrow(subAccountId)];
|
|
6888
7104
|
for (const maker of makerInfo) {
|
|
6889
7105
|
userAccounts.push(maker.makerUserAccount);
|
|
6890
7106
|
}
|
|
@@ -6958,7 +7174,7 @@ export class VelocityClient {
|
|
|
6958
7174
|
this.opts
|
|
6959
7175
|
);
|
|
6960
7176
|
|
|
6961
|
-
this.
|
|
7177
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
6962
7178
|
|
|
6963
7179
|
return txSig;
|
|
6964
7180
|
}
|
|
@@ -6979,7 +7195,7 @@ export class VelocityClient {
|
|
|
6979
7195
|
|
|
6980
7196
|
const remainingAccounts = this.getRemainingAccounts({
|
|
6981
7197
|
userAccounts: [
|
|
6982
|
-
this.
|
|
7198
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
6983
7199
|
takerInfo.takerUserAccount,
|
|
6984
7200
|
],
|
|
6985
7201
|
useMarketLastSlotCache: true,
|
|
@@ -7095,8 +7311,11 @@ export class VelocityClient {
|
|
|
7095
7311
|
|
|
7096
7312
|
public signMessage(
|
|
7097
7313
|
message: Uint8Array,
|
|
7098
|
-
keypair: Keypair = this.wallet.payer
|
|
7314
|
+
keypair: Keypair | undefined = this.wallet.payer
|
|
7099
7315
|
): Buffer {
|
|
7316
|
+
if (!keypair) {
|
|
7317
|
+
throw new Error('No keypair available to sign message');
|
|
7318
|
+
}
|
|
7100
7319
|
return Buffer.from(nacl.sign.detached(message, keypair.secretKey));
|
|
7101
7320
|
}
|
|
7102
7321
|
|
|
@@ -7252,7 +7471,7 @@ export class VelocityClient {
|
|
|
7252
7471
|
this.opts
|
|
7253
7472
|
);
|
|
7254
7473
|
|
|
7255
|
-
this.
|
|
7474
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
7256
7475
|
return txSig;
|
|
7257
7476
|
}
|
|
7258
7477
|
|
|
@@ -7289,7 +7508,7 @@ export class VelocityClient {
|
|
|
7289
7508
|
|
|
7290
7509
|
const remainingAccounts = this.getRemainingAccounts({
|
|
7291
7510
|
userAccounts: [
|
|
7292
|
-
this.
|
|
7511
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
7293
7512
|
takerInfo.takerUserAccount,
|
|
7294
7513
|
],
|
|
7295
7514
|
useMarketLastSlotCache: false,
|
|
@@ -7568,8 +7787,12 @@ export class VelocityClient {
|
|
|
7568
7787
|
const userPubKey =
|
|
7569
7788
|
overrides?.user?.getUserAccountPublicKey() ??
|
|
7570
7789
|
(await this.getUserAccountPublicKey(subAccountId));
|
|
7790
|
+
const overrideUserAccount = overrides?.user?.getUserAccount();
|
|
7791
|
+
if (overrides?.user && !overrideUserAccount) {
|
|
7792
|
+
throw new Error('modifyOrder: override user account is not loaded');
|
|
7793
|
+
}
|
|
7571
7794
|
const userAccount =
|
|
7572
|
-
|
|
7795
|
+
overrideUserAccount ?? this.getUserAccountOrThrow(subAccountId);
|
|
7573
7796
|
|
|
7574
7797
|
const remainingAccounts = this.getRemainingAccounts({
|
|
7575
7798
|
userAccounts: [userAccount],
|
|
@@ -7595,7 +7818,7 @@ export class VelocityClient {
|
|
|
7595
7818
|
|
|
7596
7819
|
const authority =
|
|
7597
7820
|
overrides?.authority ??
|
|
7598
|
-
|
|
7821
|
+
overrideUserAccount?.authority ??
|
|
7599
7822
|
this.wallet.publicKey;
|
|
7600
7823
|
return await VelocityCore.buildModifyOrderInstruction({
|
|
7601
7824
|
program: this.program,
|
|
@@ -7698,7 +7921,7 @@ export class VelocityClient {
|
|
|
7698
7921
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
7699
7922
|
|
|
7700
7923
|
const remainingAccounts = this.getRemainingAccounts({
|
|
7701
|
-
userAccounts: [this.
|
|
7924
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
7702
7925
|
useMarketLastSlotCache: true,
|
|
7703
7926
|
});
|
|
7704
7927
|
|
|
@@ -7751,7 +7974,7 @@ export class VelocityClient {
|
|
|
7751
7974
|
|
|
7752
7975
|
if (filterInvalidMarkets) {
|
|
7753
7976
|
for (const marketIndex of marketIndexes) {
|
|
7754
|
-
const perpMarketAccount = this.
|
|
7977
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
7755
7978
|
const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
|
|
7756
7979
|
const stateAccountAndSlot =
|
|
7757
7980
|
this.accountSubscriber.getStateAccountAndSlot();
|
|
@@ -8211,7 +8434,7 @@ export class VelocityClient {
|
|
|
8211
8434
|
[],
|
|
8212
8435
|
this.opts
|
|
8213
8436
|
);
|
|
8214
|
-
this.
|
|
8437
|
+
this.cachePerpMarketSlot(slot, marketIndex);
|
|
8215
8438
|
return txSig;
|
|
8216
8439
|
}
|
|
8217
8440
|
public async getLiquidatePerpIx(
|
|
@@ -8233,7 +8456,10 @@ export class VelocityClient {
|
|
|
8233
8456
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8234
8457
|
|
|
8235
8458
|
const remainingAccounts = this.getRemainingAccounts({
|
|
8236
|
-
userAccounts: [
|
|
8459
|
+
userAccounts: [
|
|
8460
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
8461
|
+
userAccount,
|
|
8462
|
+
],
|
|
8237
8463
|
useMarketLastSlotCache: true,
|
|
8238
8464
|
writablePerpMarketIndexes: [marketIndex],
|
|
8239
8465
|
});
|
|
@@ -8275,7 +8501,7 @@ export class VelocityClient {
|
|
|
8275
8501
|
[],
|
|
8276
8502
|
this.opts
|
|
8277
8503
|
);
|
|
8278
|
-
this.
|
|
8504
|
+
this.cachePerpMarketSlot(slot, marketIndex);
|
|
8279
8505
|
return txSig;
|
|
8280
8506
|
}
|
|
8281
8507
|
|
|
@@ -8356,8 +8582,7 @@ export class VelocityClient {
|
|
|
8356
8582
|
[],
|
|
8357
8583
|
this.opts
|
|
8358
8584
|
);
|
|
8359
|
-
this.
|
|
8360
|
-
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
8585
|
+
this.cacheSpotMarketSlot(slot, assetMarketIndex, liabilityMarketIndex);
|
|
8361
8586
|
return txSig;
|
|
8362
8587
|
}
|
|
8363
8588
|
|
|
@@ -8381,7 +8606,10 @@ export class VelocityClient {
|
|
|
8381
8606
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8382
8607
|
|
|
8383
8608
|
const remainingAccounts = this.getRemainingAccounts({
|
|
8384
|
-
userAccounts: [
|
|
8609
|
+
userAccounts: [
|
|
8610
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
8611
|
+
userAccount,
|
|
8612
|
+
],
|
|
8385
8613
|
useMarketLastSlotCache: true,
|
|
8386
8614
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
8387
8615
|
});
|
|
@@ -8439,8 +8667,9 @@ export class VelocityClient {
|
|
|
8439
8667
|
ixs: TransactionInstruction[];
|
|
8440
8668
|
lookupTables: AddressLookupTableAccount[];
|
|
8441
8669
|
}> {
|
|
8442
|
-
const liabilityMarket =
|
|
8443
|
-
|
|
8670
|
+
const liabilityMarket =
|
|
8671
|
+
this.getSpotMarketAccountOrThrow(liabilityMarketIndex);
|
|
8672
|
+
const assetMarket = this.getSpotMarketAccountOrThrow(assetMarketIndex);
|
|
8444
8673
|
|
|
8445
8674
|
if (!quote) {
|
|
8446
8675
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
@@ -8583,8 +8812,9 @@ export class VelocityClient {
|
|
|
8583
8812
|
readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
8584
8813
|
});
|
|
8585
8814
|
|
|
8586
|
-
const liabilitySpotMarket =
|
|
8587
|
-
|
|
8815
|
+
const liabilitySpotMarket =
|
|
8816
|
+
this.getSpotMarketAccountOrThrow(liabilityMarketIndex);
|
|
8817
|
+
const assetSpotMarket = this.getSpotMarketAccountOrThrow(assetMarketIndex);
|
|
8588
8818
|
|
|
8589
8819
|
const liabilityTokenProgram =
|
|
8590
8820
|
this.getTokenProgramForSpotMarket(liabilitySpotMarket);
|
|
@@ -8674,105 +8904,6 @@ export class VelocityClient {
|
|
|
8674
8904
|
return { beginSwapIx, endSwapIx };
|
|
8675
8905
|
}
|
|
8676
8906
|
|
|
8677
|
-
public async getInsuranceFundSwapIx({
|
|
8678
|
-
inMarketIndex,
|
|
8679
|
-
outMarketIndex,
|
|
8680
|
-
amountIn,
|
|
8681
|
-
inTokenAccount,
|
|
8682
|
-
outTokenAccount,
|
|
8683
|
-
}: {
|
|
8684
|
-
inMarketIndex: number;
|
|
8685
|
-
outMarketIndex: number;
|
|
8686
|
-
amountIn: BN;
|
|
8687
|
-
inTokenAccount: PublicKey;
|
|
8688
|
-
outTokenAccount: PublicKey;
|
|
8689
|
-
}): Promise<{
|
|
8690
|
-
beginSwapIx: TransactionInstruction;
|
|
8691
|
-
endSwapIx: TransactionInstruction;
|
|
8692
|
-
}> {
|
|
8693
|
-
const remainingAccounts = await this.getRemainingAccounts({
|
|
8694
|
-
userAccounts: [],
|
|
8695
|
-
writableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
|
|
8696
|
-
});
|
|
8697
|
-
|
|
8698
|
-
const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
8699
|
-
const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
8700
|
-
|
|
8701
|
-
if (this.isToken2022(inSpotMarket) || this.isToken2022(outSpotMarket)) {
|
|
8702
|
-
remainingAccounts.push({
|
|
8703
|
-
pubkey: inSpotMarket.mint,
|
|
8704
|
-
isWritable: false,
|
|
8705
|
-
isSigner: false,
|
|
8706
|
-
});
|
|
8707
|
-
remainingAccounts.push({
|
|
8708
|
-
pubkey: outSpotMarket.mint,
|
|
8709
|
-
isWritable: false,
|
|
8710
|
-
isSigner: false,
|
|
8711
|
-
});
|
|
8712
|
-
if (this.isTransferHook(inSpotMarket)) {
|
|
8713
|
-
this.addExtraAccountMetasToRemainingAccounts(
|
|
8714
|
-
inSpotMarket.mint,
|
|
8715
|
-
remainingAccounts
|
|
8716
|
-
);
|
|
8717
|
-
}
|
|
8718
|
-
if (this.isTransferHook(outSpotMarket)) {
|
|
8719
|
-
this.addExtraAccountMetasToRemainingAccounts(
|
|
8720
|
-
outSpotMarket.mint,
|
|
8721
|
-
remainingAccounts
|
|
8722
|
-
);
|
|
8723
|
-
}
|
|
8724
|
-
}
|
|
8725
|
-
|
|
8726
|
-
const ifRebalanceConfig = getIfRebalanceConfigPublicKey(
|
|
8727
|
-
this.program.programId,
|
|
8728
|
-
inMarketIndex,
|
|
8729
|
-
outMarketIndex
|
|
8730
|
-
);
|
|
8731
|
-
|
|
8732
|
-
const beginSwapIx = await this.program.instruction.beginInsuranceFundSwap(
|
|
8733
|
-
inMarketIndex,
|
|
8734
|
-
outMarketIndex,
|
|
8735
|
-
amountIn,
|
|
8736
|
-
{
|
|
8737
|
-
accounts: {
|
|
8738
|
-
state: await this.getStatePublicKey(),
|
|
8739
|
-
authority: this.wallet.publicKey,
|
|
8740
|
-
outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
|
|
8741
|
-
inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
|
|
8742
|
-
outTokenAccount,
|
|
8743
|
-
inTokenAccount,
|
|
8744
|
-
ifRebalanceConfig: ifRebalanceConfig,
|
|
8745
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
8746
|
-
velocitySigner: this.getStateAccount().signer,
|
|
8747
|
-
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
8748
|
-
},
|
|
8749
|
-
remainingAccounts,
|
|
8750
|
-
}
|
|
8751
|
-
);
|
|
8752
|
-
|
|
8753
|
-
const endSwapIx = await this.program.instruction.endInsuranceFundSwap(
|
|
8754
|
-
inMarketIndex,
|
|
8755
|
-
outMarketIndex,
|
|
8756
|
-
{
|
|
8757
|
-
accounts: {
|
|
8758
|
-
state: await this.getStatePublicKey(),
|
|
8759
|
-
authority: this.wallet.publicKey,
|
|
8760
|
-
outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
|
|
8761
|
-
inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
|
|
8762
|
-
outTokenAccount,
|
|
8763
|
-
inTokenAccount,
|
|
8764
|
-
ifRebalanceConfig: ifRebalanceConfig,
|
|
8765
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
8766
|
-
velocitySigner: this.getStateAccount().signer,
|
|
8767
|
-
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
8768
|
-
},
|
|
8769
|
-
remainingAccounts,
|
|
8770
|
-
}
|
|
8771
|
-
);
|
|
8772
|
-
|
|
8773
|
-
return { beginSwapIx, endSwapIx };
|
|
8774
|
-
}
|
|
8775
|
-
|
|
8776
8907
|
public async liquidateBorrowForPerpPnl(
|
|
8777
8908
|
userAccountPublicKey: PublicKey,
|
|
8778
8909
|
userAccount: UserAccount,
|
|
@@ -8799,8 +8930,8 @@ export class VelocityClient {
|
|
|
8799
8930
|
[],
|
|
8800
8931
|
this.opts
|
|
8801
8932
|
);
|
|
8802
|
-
this.
|
|
8803
|
-
this.
|
|
8933
|
+
this.cachePerpMarketSlot(slot, perpMarketIndex);
|
|
8934
|
+
this.cacheSpotMarketSlot(slot, liabilityMarketIndex);
|
|
8804
8935
|
return txSig;
|
|
8805
8936
|
}
|
|
8806
8937
|
|
|
@@ -8824,7 +8955,10 @@ export class VelocityClient {
|
|
|
8824
8955
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8825
8956
|
|
|
8826
8957
|
const remainingAccounts = this.getRemainingAccounts({
|
|
8827
|
-
userAccounts: [
|
|
8958
|
+
userAccounts: [
|
|
8959
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
8960
|
+
userAccount,
|
|
8961
|
+
],
|
|
8828
8962
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
8829
8963
|
writableSpotMarketIndexes: [liabilityMarketIndex],
|
|
8830
8964
|
});
|
|
@@ -8874,8 +9008,8 @@ export class VelocityClient {
|
|
|
8874
9008
|
[],
|
|
8875
9009
|
this.opts
|
|
8876
9010
|
);
|
|
8877
|
-
this.
|
|
8878
|
-
this.
|
|
9011
|
+
this.cachePerpMarketSlot(slot, perpMarketIndex);
|
|
9012
|
+
this.cacheSpotMarketSlot(slot, assetMarketIndex);
|
|
8879
9013
|
return txSig;
|
|
8880
9014
|
}
|
|
8881
9015
|
|
|
@@ -8899,7 +9033,10 @@ export class VelocityClient {
|
|
|
8899
9033
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8900
9034
|
|
|
8901
9035
|
const remainingAccounts = this.getRemainingAccounts({
|
|
8902
|
-
userAccounts: [
|
|
9036
|
+
userAccounts: [
|
|
9037
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
9038
|
+
userAccount,
|
|
9039
|
+
],
|
|
8903
9040
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
8904
9041
|
writableSpotMarketIndexes: [assetMarketIndex],
|
|
8905
9042
|
});
|
|
@@ -8963,7 +9100,10 @@ export class VelocityClient {
|
|
|
8963
9100
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8964
9101
|
|
|
8965
9102
|
const remainingAccounts = this.getRemainingAccounts({
|
|
8966
|
-
userAccounts: [
|
|
9103
|
+
userAccounts: [
|
|
9104
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
9105
|
+
userAccount,
|
|
9106
|
+
],
|
|
8967
9107
|
writablePerpMarketIndexes: [marketIndex],
|
|
8968
9108
|
writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
8969
9109
|
});
|
|
@@ -9030,11 +9170,14 @@ export class VelocityClient {
|
|
|
9030
9170
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
9031
9171
|
|
|
9032
9172
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9033
|
-
userAccounts: [
|
|
9173
|
+
userAccounts: [
|
|
9174
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
9175
|
+
userAccount,
|
|
9176
|
+
],
|
|
9034
9177
|
writableSpotMarketIndexes: [marketIndex],
|
|
9035
9178
|
});
|
|
9036
9179
|
|
|
9037
|
-
const spotMarket = this.
|
|
9180
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9038
9181
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
9039
9182
|
|
|
9040
9183
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
@@ -9113,7 +9256,7 @@ export class VelocityClient {
|
|
|
9113
9256
|
public async getUpdatePrelaunchOracleIx(
|
|
9114
9257
|
perpMarketIndex: number
|
|
9115
9258
|
): Promise<TransactionInstruction> {
|
|
9116
|
-
const perpMarket = this.
|
|
9259
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
9117
9260
|
|
|
9118
9261
|
if (!isVariant(perpMarket.oracleSource, 'prelaunch')) {
|
|
9119
9262
|
throw new Error(`Wrong oracle source ${perpMarket.oracleSource}`);
|
|
@@ -9148,7 +9291,7 @@ export class VelocityClient {
|
|
|
9148
9291
|
perpMarketIndex: number,
|
|
9149
9292
|
makers: [PublicKey, PublicKey][]
|
|
9150
9293
|
): Promise<TransactionInstruction> {
|
|
9151
|
-
const perpMarket = this.
|
|
9294
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
9152
9295
|
|
|
9153
9296
|
const remainingAccounts = [];
|
|
9154
9297
|
for (const [maker, makerStats] of makers) {
|
|
@@ -9227,13 +9370,18 @@ export class VelocityClient {
|
|
|
9227
9370
|
}
|
|
9228
9371
|
|
|
9229
9372
|
public getOracleDataForPerpMarket(marketIndex: number): OraclePriceData {
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9373
|
+
const oraclePriceDataAndSlot =
|
|
9374
|
+
this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(
|
|
9375
|
+
marketIndex
|
|
9376
|
+
);
|
|
9377
|
+
if (!oraclePriceDataAndSlot) {
|
|
9378
|
+
throw new Error(`No oracle price data for perp market ${marketIndex}`);
|
|
9379
|
+
}
|
|
9380
|
+
return oraclePriceDataAndSlot.data;
|
|
9233
9381
|
}
|
|
9234
9382
|
|
|
9235
9383
|
public getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData {
|
|
9236
|
-
const perpMarket = this.
|
|
9384
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
9237
9385
|
const oracleData = this.getOracleDataForPerpMarket(marketIndex);
|
|
9238
9386
|
const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
|
|
9239
9387
|
const isMMOracleActive = !perpMarket.marketStats.mmOracleSlot.eq(ZERO);
|
|
@@ -9258,12 +9406,13 @@ export class VelocityClient {
|
|
|
9258
9406
|
let isExchangeOracleMoreRecent = true;
|
|
9259
9407
|
if (
|
|
9260
9408
|
doSlotCheckForRecency &&
|
|
9261
|
-
oracleData.slot
|
|
9409
|
+
oracleData.slot.lte(perpMarket.marketStats.mmOracleSlot)
|
|
9262
9410
|
) {
|
|
9263
9411
|
isExchangeOracleMoreRecent = false;
|
|
9264
9412
|
} else if (
|
|
9265
9413
|
!doSlotCheckForRecency &&
|
|
9266
|
-
oracleData.sequenceId
|
|
9414
|
+
oracleData.sequenceId != null &&
|
|
9415
|
+
oracleData.sequenceId.lt(mmOracleSequenceId)
|
|
9267
9416
|
) {
|
|
9268
9417
|
isExchangeOracleMoreRecent = false;
|
|
9269
9418
|
}
|
|
@@ -9301,9 +9450,14 @@ export class VelocityClient {
|
|
|
9301
9450
|
}
|
|
9302
9451
|
|
|
9303
9452
|
public getOracleDataForSpotMarket(marketIndex: number): OraclePriceData {
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9453
|
+
const oraclePriceDataAndSlot =
|
|
9454
|
+
this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(
|
|
9455
|
+
marketIndex
|
|
9456
|
+
);
|
|
9457
|
+
if (!oraclePriceDataAndSlot) {
|
|
9458
|
+
throw new Error(`No oracle price data for spot market ${marketIndex}`);
|
|
9459
|
+
}
|
|
9460
|
+
return oraclePriceDataAndSlot.data;
|
|
9307
9461
|
}
|
|
9308
9462
|
|
|
9309
9463
|
public async initializeInsuranceFundStake(
|
|
@@ -9332,7 +9486,7 @@ export class VelocityClient {
|
|
|
9332
9486
|
|
|
9333
9487
|
const accounts = {
|
|
9334
9488
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
9335
|
-
spotMarket: this.
|
|
9489
|
+
spotMarket: this.getSpotMarketAccountOrThrow(marketIndex).pubkey,
|
|
9336
9490
|
userStats: getUserStatsAccountPublicKey(
|
|
9337
9491
|
this.program.programId,
|
|
9338
9492
|
this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
|
|
@@ -9357,14 +9511,14 @@ export class VelocityClient {
|
|
|
9357
9511
|
amount: BN,
|
|
9358
9512
|
collateralAccountPublicKey: PublicKey
|
|
9359
9513
|
): Promise<TransactionInstruction> {
|
|
9360
|
-
const spotMarket = this.
|
|
9514
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9361
9515
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9362
9516
|
this.program.programId,
|
|
9363
9517
|
this.wallet.publicKey,
|
|
9364
9518
|
marketIndex
|
|
9365
9519
|
);
|
|
9366
9520
|
|
|
9367
|
-
const remainingAccounts = [];
|
|
9521
|
+
const remainingAccounts: AccountMeta[] = [];
|
|
9368
9522
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
9369
9523
|
if (this.isTransferHook(spotMarket)) {
|
|
9370
9524
|
await this.addExtraAccountMetasToRemainingAccounts(
|
|
@@ -9480,7 +9634,7 @@ export class VelocityClient {
|
|
|
9480
9634
|
}): Promise<TransactionInstruction[]> {
|
|
9481
9635
|
const addIfStakeIxs = [];
|
|
9482
9636
|
|
|
9483
|
-
const spotMarketAccount = this.
|
|
9637
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9484
9638
|
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
9485
9639
|
const createWSOLTokenAccount =
|
|
9486
9640
|
isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
@@ -9573,7 +9727,7 @@ export class VelocityClient {
|
|
|
9573
9727
|
amount: BN,
|
|
9574
9728
|
txParams?: TxParams
|
|
9575
9729
|
): Promise<TransactionSignature> {
|
|
9576
|
-
const spotMarketAccount = this.
|
|
9730
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9577
9731
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9578
9732
|
this.program.programId,
|
|
9579
9733
|
this.wallet.publicKey,
|
|
@@ -9606,7 +9760,7 @@ export class VelocityClient {
|
|
|
9606
9760
|
marketIndex: number,
|
|
9607
9761
|
txParams?: TxParams
|
|
9608
9762
|
): Promise<TransactionSignature> {
|
|
9609
|
-
const spotMarketAccount = this.
|
|
9763
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9610
9764
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9611
9765
|
this.program.programId,
|
|
9612
9766
|
this.wallet.publicKey,
|
|
@@ -9641,7 +9795,7 @@ export class VelocityClient {
|
|
|
9641
9795
|
txParams?: TxParams
|
|
9642
9796
|
): Promise<TransactionSignature> {
|
|
9643
9797
|
const removeIfStakeIxs = [];
|
|
9644
|
-
const spotMarketAccount = this.
|
|
9798
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9645
9799
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9646
9800
|
this.program.programId,
|
|
9647
9801
|
this.wallet.publicKey,
|
|
@@ -9681,7 +9835,7 @@ export class VelocityClient {
|
|
|
9681
9835
|
}
|
|
9682
9836
|
}
|
|
9683
9837
|
|
|
9684
|
-
const remainingAccounts = [];
|
|
9838
|
+
const remainingAccounts: AccountMeta[] = [];
|
|
9685
9839
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
9686
9840
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
9687
9841
|
await this.addExtraAccountMetasToRemainingAccounts(
|
|
@@ -9750,7 +9904,7 @@ export class VelocityClient {
|
|
|
9750
9904
|
authority: PublicKey
|
|
9751
9905
|
): Promise<TransactionInstruction> {
|
|
9752
9906
|
const marketIndex = QUOTE_SPOT_MARKET_INDEX;
|
|
9753
|
-
const spotMarket = this.
|
|
9907
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9754
9908
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9755
9909
|
this.program.programId,
|
|
9756
9910
|
authority,
|
|
@@ -9775,45 +9929,6 @@ export class VelocityClient {
|
|
|
9775
9929
|
return ix;
|
|
9776
9930
|
}
|
|
9777
9931
|
|
|
9778
|
-
public async updateUserGovTokenInsuranceStake(
|
|
9779
|
-
authority: PublicKey,
|
|
9780
|
-
txParams?: TxParams
|
|
9781
|
-
): Promise<TransactionSignature> {
|
|
9782
|
-
const ix = await this.getUpdateUserGovTokenInsuranceStakeIx(authority);
|
|
9783
|
-
const tx = await this.buildTransaction(ix, txParams);
|
|
9784
|
-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
9785
|
-
return txSig;
|
|
9786
|
-
}
|
|
9787
|
-
|
|
9788
|
-
public async getUpdateUserGovTokenInsuranceStakeIx(
|
|
9789
|
-
authority: PublicKey
|
|
9790
|
-
): Promise<TransactionInstruction> {
|
|
9791
|
-
const marketIndex = GOV_SPOT_MARKET_INDEX;
|
|
9792
|
-
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
9793
|
-
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
9794
|
-
this.program.programId,
|
|
9795
|
-
authority,
|
|
9796
|
-
marketIndex
|
|
9797
|
-
);
|
|
9798
|
-
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
9799
|
-
this.program.programId,
|
|
9800
|
-
authority
|
|
9801
|
-
);
|
|
9802
|
-
|
|
9803
|
-
const ix = this.program.instruction.updateUserGovTokenInsuranceStake({
|
|
9804
|
-
accounts: {
|
|
9805
|
-
state: await this.getStatePublicKey(),
|
|
9806
|
-
spotMarket: spotMarket.pubkey,
|
|
9807
|
-
insuranceFundStake: ifStakeAccountPublicKey,
|
|
9808
|
-
userStats: userStatsPublicKey,
|
|
9809
|
-
signer: this.wallet.publicKey,
|
|
9810
|
-
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
9811
|
-
},
|
|
9812
|
-
});
|
|
9813
|
-
|
|
9814
|
-
return ix;
|
|
9815
|
-
}
|
|
9816
|
-
|
|
9817
9932
|
public async settleRevenueToInsuranceFund(
|
|
9818
9933
|
spotMarketIndex: number,
|
|
9819
9934
|
txParams?: TxParams
|
|
@@ -9828,10 +9943,10 @@ export class VelocityClient {
|
|
|
9828
9943
|
public async getSettleRevenueToInsuranceFundIx(
|
|
9829
9944
|
spotMarketIndex: number
|
|
9830
9945
|
): Promise<TransactionInstruction> {
|
|
9831
|
-
const spotMarketAccount = this.
|
|
9946
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
9832
9947
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
9833
9948
|
|
|
9834
|
-
const remainingAccounts = [];
|
|
9949
|
+
const remainingAccounts: AccountMeta[] = [];
|
|
9835
9950
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
9836
9951
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
9837
9952
|
await this.addExtraAccountMetasToRemainingAccounts(
|
|
@@ -9857,6 +9972,40 @@ export class VelocityClient {
|
|
|
9857
9972
|
return ix;
|
|
9858
9973
|
}
|
|
9859
9974
|
|
|
9975
|
+
public async sweepPerpMarketFees(
|
|
9976
|
+
perpMarketIndex: number,
|
|
9977
|
+
txParams?: TxParams
|
|
9978
|
+
): Promise<TransactionSignature> {
|
|
9979
|
+
const tx = await this.buildTransaction(
|
|
9980
|
+
await this.getSweepPerpMarketFeesIx(perpMarketIndex),
|
|
9981
|
+
txParams
|
|
9982
|
+
);
|
|
9983
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
9984
|
+
return txSig;
|
|
9985
|
+
}
|
|
9986
|
+
|
|
9987
|
+
public async getSweepPerpMarketFeesIx(
|
|
9988
|
+
perpMarketIndex: number
|
|
9989
|
+
): Promise<TransactionInstruction> {
|
|
9990
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
9991
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(
|
|
9992
|
+
perpMarketAccount.quoteSpotMarketIndex
|
|
9993
|
+
);
|
|
9994
|
+
|
|
9995
|
+
const ix = await this.program.instruction.sweepPerpMarketFees(
|
|
9996
|
+
perpMarketIndex,
|
|
9997
|
+
{
|
|
9998
|
+
accounts: {
|
|
9999
|
+
state: await this.getStatePublicKey(),
|
|
10000
|
+
perpMarket: perpMarketAccount.pubkey,
|
|
10001
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
10002
|
+
oracle: perpMarketAccount.oracle,
|
|
10003
|
+
},
|
|
10004
|
+
}
|
|
10005
|
+
);
|
|
10006
|
+
return ix;
|
|
10007
|
+
}
|
|
10008
|
+
|
|
9860
10009
|
public async resolvePerpPnlDeficit(
|
|
9861
10010
|
spotMarketIndex: number,
|
|
9862
10011
|
perpMarketIndex: number,
|
|
@@ -9878,12 +10027,12 @@ export class VelocityClient {
|
|
|
9878
10027
|
perpMarketIndex: number
|
|
9879
10028
|
): Promise<TransactionInstruction> {
|
|
9880
10029
|
const remainingAccounts = this.getRemainingAccounts({
|
|
9881
|
-
userAccounts: [
|
|
10030
|
+
userAccounts: [],
|
|
9882
10031
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
9883
10032
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
9884
10033
|
});
|
|
9885
10034
|
|
|
9886
|
-
const spotMarket = this.
|
|
10035
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
9887
10036
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
9888
10037
|
|
|
9889
10038
|
return await this.program.instruction.resolvePerpPnlDeficit(
|
|
@@ -9908,9 +10057,9 @@ export class VelocityClient {
|
|
|
9908
10057
|
amount: BN,
|
|
9909
10058
|
userTokenAccountPublicKey: PublicKey
|
|
9910
10059
|
): Promise<TransactionInstruction> {
|
|
9911
|
-
const spotMarket = await this.
|
|
10060
|
+
const spotMarket = await this.getSpotMarketAccountOrThrow(marketIndex);
|
|
9912
10061
|
|
|
9913
|
-
const remainingAccounts = [];
|
|
10062
|
+
const remainingAccounts: AccountMeta[] = [];
|
|
9914
10063
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
9915
10064
|
if (this.isTransferHook(spotMarket)) {
|
|
9916
10065
|
await this.addExtraAccountMetasToRemainingAccounts(
|
|
@@ -9963,8 +10112,10 @@ export class VelocityClient {
|
|
|
9963
10112
|
public getPerpMarketExtendedInfo(
|
|
9964
10113
|
marketIndex: number
|
|
9965
10114
|
): PerpMarketExtendedInfo {
|
|
9966
|
-
const marketAccount = this.
|
|
9967
|
-
const quoteAccount = this.
|
|
10115
|
+
const marketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
10116
|
+
const quoteAccount = this.getSpotMarketAccountOrThrow(
|
|
10117
|
+
QUOTE_SPOT_MARKET_INDEX
|
|
10118
|
+
);
|
|
9968
10119
|
|
|
9969
10120
|
const extendedInfo: PerpMarketExtendedInfo = {
|
|
9970
10121
|
marketIndex,
|
|
@@ -10011,11 +10162,11 @@ export class VelocityClient {
|
|
|
10011
10162
|
feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
|
|
10012
10163
|
|
|
10013
10164
|
if (marketIndex !== undefined) {
|
|
10014
|
-
let marketAccount
|
|
10165
|
+
let marketAccount: PerpMarketAccount | SpotMarketAccount;
|
|
10015
10166
|
if (isVariant(marketType, 'perp')) {
|
|
10016
|
-
marketAccount = this.
|
|
10167
|
+
marketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
10017
10168
|
} else {
|
|
10018
|
-
marketAccount = this.
|
|
10169
|
+
marketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
10019
10170
|
}
|
|
10020
10171
|
|
|
10021
10172
|
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
@@ -10113,7 +10264,7 @@ export class VelocityClient {
|
|
|
10113
10264
|
public async getPauseSpotMarketDepositWithdrawIx(
|
|
10114
10265
|
spotMarketIndex: number
|
|
10115
10266
|
): Promise<TransactionInstruction> {
|
|
10116
|
-
const spotMarket = await this.
|
|
10267
|
+
const spotMarket = await this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
10117
10268
|
return this.program.instruction.pauseSpotMarketDepositWithdraw({
|
|
10118
10269
|
accounts: {
|
|
10119
10270
|
state: await this.getStatePublicKey(),
|
|
@@ -10175,7 +10326,7 @@ export class VelocityClient {
|
|
|
10175
10326
|
programId: this.program.programId,
|
|
10176
10327
|
keys: [
|
|
10177
10328
|
{
|
|
10178
|
-
pubkey: this.
|
|
10329
|
+
pubkey: this.getPerpMarketAccountOrThrow(marketIndex).pubkey,
|
|
10179
10330
|
isWritable: true,
|
|
10180
10331
|
isSigner: false,
|
|
10181
10332
|
},
|
|
@@ -10231,7 +10382,7 @@ export class VelocityClient {
|
|
|
10231
10382
|
programId: this.program.programId,
|
|
10232
10383
|
keys: [
|
|
10233
10384
|
{
|
|
10234
|
-
pubkey: this.
|
|
10385
|
+
pubkey: this.getPerpMarketAccountOrThrow(marketIndex).pubkey,
|
|
10235
10386
|
isWritable: true,
|
|
10236
10387
|
isSigner: false,
|
|
10237
10388
|
},
|
|
@@ -10405,7 +10556,7 @@ export class VelocityClient {
|
|
|
10405
10556
|
state: await this.getStatePublicKey(),
|
|
10406
10557
|
keeper: this.wallet.publicKey,
|
|
10407
10558
|
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
10408
|
-
quoteMarket: this.
|
|
10559
|
+
quoteMarket: this.getSpotMarketAccountOrThrow(0).pubkey,
|
|
10409
10560
|
},
|
|
10410
10561
|
remainingAccounts,
|
|
10411
10562
|
});
|
|
@@ -10428,7 +10579,9 @@ export class VelocityClient {
|
|
|
10428
10579
|
public async getUpdateConstituentOracleInfoIx(
|
|
10429
10580
|
constituent: ConstituentAccount
|
|
10430
10581
|
): Promise<TransactionInstruction> {
|
|
10431
|
-
const spotMarket = this.
|
|
10582
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(
|
|
10583
|
+
constituent.spotMarketIndex
|
|
10584
|
+
);
|
|
10432
10585
|
return this.program.instruction.updateConstituentOracleInfo({
|
|
10433
10586
|
accounts: {
|
|
10434
10587
|
keeper: this.wallet.publicKey,
|
|
@@ -10491,11 +10644,11 @@ export class VelocityClient {
|
|
|
10491
10644
|
outMarketIndex
|
|
10492
10645
|
);
|
|
10493
10646
|
const userInTokenAccount = await getAssociatedTokenAddress(
|
|
10494
|
-
this.
|
|
10647
|
+
this.getSpotMarketAccountOrThrow(inMarketIndex).mint,
|
|
10495
10648
|
userAuthority
|
|
10496
10649
|
);
|
|
10497
10650
|
const userOutTokenAccount = await getAssociatedTokenAddress(
|
|
10498
|
-
this.
|
|
10651
|
+
this.getSpotMarketAccountOrThrow(outMarketIndex).mint,
|
|
10499
10652
|
userAuthority
|
|
10500
10653
|
);
|
|
10501
10654
|
const inConstituent = getConstituentPublicKey(
|
|
@@ -10508,8 +10661,8 @@ export class VelocityClient {
|
|
|
10508
10661
|
lpPool,
|
|
10509
10662
|
outMarketIndex
|
|
10510
10663
|
);
|
|
10511
|
-
const inMarketMint = this.
|
|
10512
|
-
const outMarketMint = this.
|
|
10664
|
+
const inMarketMint = this.getSpotMarketAccountOrThrow(inMarketIndex).mint;
|
|
10665
|
+
const outMarketMint = this.getSpotMarketAccountOrThrow(outMarketIndex).mint;
|
|
10513
10666
|
|
|
10514
10667
|
const constituentTargetBase = getConstituentTargetBasePublicKey(
|
|
10515
10668
|
this.program.programId,
|
|
@@ -10707,7 +10860,7 @@ export class VelocityClient {
|
|
|
10707
10860
|
writableSpotMarketIndexes: [inMarketIndex],
|
|
10708
10861
|
});
|
|
10709
10862
|
|
|
10710
|
-
const spotMarket = this.
|
|
10863
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
10711
10864
|
const inMarketMint = spotMarket.mint;
|
|
10712
10865
|
const isSolMarket = inMarketMint.equals(WRAPPED_SOL_MINT);
|
|
10713
10866
|
|
|
@@ -10844,7 +10997,7 @@ export class VelocityClient {
|
|
|
10844
10997
|
readableSpotMarketIndexes: [inMarketIndex],
|
|
10845
10998
|
});
|
|
10846
10999
|
|
|
10847
|
-
const spotMarket = this.
|
|
11000
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
10848
11001
|
const inMarketMint = spotMarket.mint;
|
|
10849
11002
|
const inConstituent = getConstituentPublicKey(
|
|
10850
11003
|
this.program.programId,
|
|
@@ -10922,7 +11075,7 @@ export class VelocityClient {
|
|
|
10922
11075
|
writableSpotMarketIndexes: [outMarketIndex],
|
|
10923
11076
|
});
|
|
10924
11077
|
|
|
10925
|
-
const spotMarket = this.
|
|
11078
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
10926
11079
|
const outMarketMint = spotMarket.mint;
|
|
10927
11080
|
const outConstituent = getConstituentPublicKey(
|
|
10928
11081
|
this.program.programId,
|
|
@@ -11033,7 +11186,7 @@ export class VelocityClient {
|
|
|
11033
11186
|
writableSpotMarketIndexes: [outMarketIndex],
|
|
11034
11187
|
});
|
|
11035
11188
|
|
|
11036
|
-
const spotMarket = this.
|
|
11189
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
11037
11190
|
const outMarketMint = spotMarket.mint;
|
|
11038
11191
|
const outConstituent = getConstituentPublicKey(
|
|
11039
11192
|
this.program.programId,
|
|
@@ -11272,7 +11425,7 @@ export class VelocityClient {
|
|
|
11272
11425
|
remainingAccounts.push(
|
|
11273
11426
|
...perpMarketIndexes.map((index) => {
|
|
11274
11427
|
return {
|
|
11275
|
-
pubkey: this.
|
|
11428
|
+
pubkey: this.getPerpMarketAccountOrThrow(index).pubkey,
|
|
11276
11429
|
isSigner: false,
|
|
11277
11430
|
isWritable: true,
|
|
11278
11431
|
};
|
|
@@ -11396,7 +11549,7 @@ export class VelocityClient {
|
|
|
11396
11549
|
txVersion?: TransactionVersion,
|
|
11397
11550
|
lookupTables?: AddressLookupTableAccount[],
|
|
11398
11551
|
forceVersionedTransaction?: boolean
|
|
11399
|
-
): Promise<(Transaction | VersionedTransaction)[]> {
|
|
11552
|
+
): Promise<(Transaction | VersionedTransaction | undefined)[]> {
|
|
11400
11553
|
return this.txHandler.buildBulkTransactions({
|
|
11401
11554
|
instructions,
|
|
11402
11555
|
txVersion: txVersion ?? this.txVersion,
|
|
@@ -11458,9 +11611,9 @@ export class VelocityClient {
|
|
|
11458
11611
|
|
|
11459
11612
|
isOrderIncreasingPosition(
|
|
11460
11613
|
orderParams: OptionalOrderParams,
|
|
11461
|
-
subAccountId
|
|
11614
|
+
subAccountId?: number
|
|
11462
11615
|
): boolean {
|
|
11463
|
-
const userAccount = this.
|
|
11616
|
+
const userAccount = this.getUserAccountOrThrow(subAccountId);
|
|
11464
11617
|
const perpPosition = userAccount.perpPositions.find(
|
|
11465
11618
|
(p) => p.marketIndex === orderParams.marketIndex
|
|
11466
11619
|
);
|