@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
|
@@ -90,7 +90,7 @@ class VelocityClient {
|
|
|
90
90
|
this._isSubscribed = val;
|
|
91
91
|
}
|
|
92
92
|
constructor(config) {
|
|
93
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
|
|
93
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
|
|
94
94
|
this.users = new Map();
|
|
95
95
|
this._isSubscribed = false;
|
|
96
96
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -197,34 +197,28 @@ class VelocityClient {
|
|
|
197
197
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
|
-
this.
|
|
201
|
-
|
|
202
|
-
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
|
|
203
|
-
}
|
|
204
|
-
this.marketLookupTables = config.marketLookupTables;
|
|
205
|
-
if (!this.marketLookupTables) {
|
|
206
|
-
this.marketLookupTables = config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
|
|
207
|
-
}
|
|
200
|
+
this.marketLookupTables =
|
|
201
|
+
(_5 = config.marketLookupTables) !== null && _5 !== void 0 ? _5 : config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
|
|
208
202
|
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
209
203
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
210
204
|
config.spotMarketIndexes === undefined &&
|
|
211
205
|
config.oracleInfos === undefined;
|
|
212
|
-
if (((
|
|
213
|
-
this.accountSubscriber = new pollingVelocityClientAccountSubscriber_1.PollingVelocityClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
214
|
-
}
|
|
215
|
-
else if (((
|
|
216
|
-
const accountSubscriberClass = (
|
|
217
|
-
this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (
|
|
218
|
-
resubTimeoutMs: (
|
|
219
|
-
logResubMessages: (
|
|
206
|
+
if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'polling') {
|
|
207
|
+
this.accountSubscriber = new pollingVelocityClientAccountSubscriber_1.PollingVelocityClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_7 = config.perpMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.spotMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.oracleInfos) !== null && _9 !== void 0 ? _9 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
208
|
+
}
|
|
209
|
+
else if (((_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.type) === 'grpc') {
|
|
210
|
+
const accountSubscriberClass = (_12 = (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.velocityClientAccountSubscriber) !== null && _12 !== void 0 ? _12 : grpcVelocityClientAccountSubscriber_1.grpcVelocityClientAccountSubscriber;
|
|
211
|
+
this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_13 = config.perpMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.spotMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.oracleInfos) !== null && _15 !== void 0 ? _15 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
212
|
+
resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
|
|
213
|
+
logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
|
|
220
214
|
});
|
|
221
215
|
}
|
|
222
216
|
else {
|
|
223
|
-
const accountSubscriberClass = (
|
|
224
|
-
this.accountSubscriber = new accountSubscriberClass(this.program, (
|
|
225
|
-
resubTimeoutMs: (
|
|
226
|
-
logResubMessages: (
|
|
227
|
-
}, (
|
|
217
|
+
const accountSubscriberClass = (_19 = (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.velocityClientAccountSubscriber) !== null && _19 !== void 0 ? _19 : webSocketVelocityClientAccountSubscriber_1.WebSocketVelocityClientAccountSubscriber;
|
|
218
|
+
this.accountSubscriber = new accountSubscriberClass(this.program, (_20 = config.perpMarketIndexes) !== null && _20 !== void 0 ? _20 : [], (_21 = config.spotMarketIndexes) !== null && _21 !== void 0 ? _21 : [], (_22 = config.oracleInfos) !== null && _22 !== void 0 ? _22 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
219
|
+
resubTimeoutMs: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.resubTimeoutMs,
|
|
220
|
+
logResubMessages: (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.logResubMessages,
|
|
221
|
+
}, (_25 = config.accountSubscription) === null || _25 === void 0 ? void 0 : _25.commitment);
|
|
228
222
|
}
|
|
229
223
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
230
224
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -232,7 +226,7 @@ class VelocityClient {
|
|
|
232
226
|
this.enableMetricsEvents = true;
|
|
233
227
|
}
|
|
234
228
|
this.txSender =
|
|
235
|
-
(
|
|
229
|
+
(_26 = config.txSender) !== null && _26 !== void 0 ? _26 : new retryTxSender_1.RetryTxSender({
|
|
236
230
|
connection: this.connection,
|
|
237
231
|
wallet: this.wallet,
|
|
238
232
|
opts: this.opts,
|
|
@@ -312,6 +306,17 @@ class VelocityClient {
|
|
|
312
306
|
var _a;
|
|
313
307
|
return (_a = this.accountSubscriber.getMarketAccountAndSlot(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
|
|
314
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Like {@link getPerpMarketAccount} but throws if the market is not loaded,
|
|
311
|
+
* for call sites that require a guaranteed account.
|
|
312
|
+
*/
|
|
313
|
+
getPerpMarketAccountOrThrow(marketIndex) {
|
|
314
|
+
const perpMarketAccount = this.getPerpMarketAccount(marketIndex);
|
|
315
|
+
if (!perpMarketAccount) {
|
|
316
|
+
throw new Error(`Perp market ${marketIndex} not found`);
|
|
317
|
+
}
|
|
318
|
+
return perpMarketAccount;
|
|
319
|
+
}
|
|
315
320
|
/**
|
|
316
321
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
317
322
|
* @param marketIndex
|
|
@@ -335,15 +340,28 @@ class VelocityClient {
|
|
|
335
340
|
.map((value) => value.data);
|
|
336
341
|
}
|
|
337
342
|
getSpotMarketAccount(marketIndex) {
|
|
338
|
-
|
|
343
|
+
var _a;
|
|
344
|
+
return (_a = this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Like {@link getSpotMarketAccount} but throws if the market is not loaded,
|
|
348
|
+
* for call sites that require a guaranteed account.
|
|
349
|
+
*/
|
|
350
|
+
getSpotMarketAccountOrThrow(marketIndex) {
|
|
351
|
+
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
352
|
+
if (!spotMarketAccount) {
|
|
353
|
+
throw new Error(`Spot market ${marketIndex} not found`);
|
|
354
|
+
}
|
|
355
|
+
return spotMarketAccount;
|
|
339
356
|
}
|
|
340
357
|
/**
|
|
341
358
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
342
359
|
* @param marketIndex
|
|
343
360
|
*/
|
|
344
361
|
async forceGetSpotMarketAccount(marketIndex) {
|
|
362
|
+
var _a;
|
|
345
363
|
await this.accountSubscriber.fetch();
|
|
346
|
-
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data;
|
|
364
|
+
return (_a = this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
|
|
347
365
|
}
|
|
348
366
|
getSpotMarketAccounts() {
|
|
349
367
|
return this.accountSubscriber
|
|
@@ -352,23 +370,11 @@ class VelocityClient {
|
|
|
352
370
|
.map((value) => value.data);
|
|
353
371
|
}
|
|
354
372
|
getQuoteSpotMarketAccount() {
|
|
355
|
-
return this.
|
|
373
|
+
return this.getSpotMarketAccountOrThrow(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
356
374
|
}
|
|
357
375
|
getOraclePriceDataAndSlot(oraclePublicKey, oracleSource) {
|
|
358
376
|
return this.accountSubscriber.getOraclePriceDataAndSlot((0, oracleId_1.getOracleId)(oraclePublicKey, oracleSource));
|
|
359
377
|
}
|
|
360
|
-
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
361
|
-
async fetchMarketLookupTableAccount() {
|
|
362
|
-
if (this.lookupTableAccount)
|
|
363
|
-
return this.lookupTableAccount;
|
|
364
|
-
if (!this.marketLookupTable) {
|
|
365
|
-
console.log('Market lookup table address not set');
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const lookupTableAccount = (await this.connection.getAddressLookupTable(this.marketLookupTable)).value;
|
|
369
|
-
this.lookupTableAccount = lookupTableAccount;
|
|
370
|
-
return lookupTableAccount;
|
|
371
|
-
}
|
|
372
378
|
async fetchAllLookupTableAccounts() {
|
|
373
379
|
if (this.lookupTableAccounts)
|
|
374
380
|
return this.lookupTableAccounts;
|
|
@@ -493,7 +499,8 @@ class VelocityClient {
|
|
|
493
499
|
const authorityChanged = authority && !((_a = this.authority) === null || _a === void 0 ? void 0 : _a.equals(authority));
|
|
494
500
|
this.activeSubAccountId = subAccountId;
|
|
495
501
|
this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
496
|
-
|
|
502
|
+
const userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
|
|
503
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
497
504
|
/* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
|
|
498
505
|
if (authorityChanged && this.userStats) {
|
|
499
506
|
if (this.userStats.isSubscribed) {
|
|
@@ -501,16 +508,17 @@ class VelocityClient {
|
|
|
501
508
|
}
|
|
502
509
|
this.userStats = new userStats_1.UserStats({
|
|
503
510
|
velocityClient: this,
|
|
504
|
-
userStatsAccountPublicKey:
|
|
511
|
+
userStatsAccountPublicKey: userStatsAccountPublicKey,
|
|
505
512
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
506
513
|
});
|
|
507
514
|
this.userStats.subscribe();
|
|
508
515
|
}
|
|
509
516
|
}
|
|
510
517
|
async addUser(subAccountId, authority, userAccount) {
|
|
518
|
+
var _a;
|
|
511
519
|
authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
512
520
|
const userKey = this.getUserMapKey(subAccountId, authority);
|
|
513
|
-
if (this.users.has(userKey) && this.users.get(userKey).isSubscribed) {
|
|
521
|
+
if (this.users.has(userKey) && ((_a = this.users.get(userKey)) === null || _a === void 0 ? void 0 : _a.isSubscribed)) {
|
|
514
522
|
return true;
|
|
515
523
|
}
|
|
516
524
|
const user = this.createUser(subAccountId, this.userAccountSubscriptionConfig, authority);
|
|
@@ -887,7 +895,16 @@ class VelocityClient {
|
|
|
887
895
|
userStatsAccount = await (0, fetch_1.fetchUserStatsAccount)(this.connection, this.program, this.wallet.publicKey);
|
|
888
896
|
}
|
|
889
897
|
else {
|
|
890
|
-
|
|
898
|
+
const account = userStats.getAccount();
|
|
899
|
+
if (!account) {
|
|
900
|
+
userStatsAccount = await (0, fetch_1.fetchUserStatsAccount)(this.connection, this.program, this.wallet.publicKey);
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
userStatsAccount = account;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (!userStatsAccount) {
|
|
907
|
+
throw new Error('UserStats account does not exist');
|
|
891
908
|
}
|
|
892
909
|
return userStatsAccount.numberOfSubAccountsCreated;
|
|
893
910
|
}
|
|
@@ -969,7 +986,7 @@ class VelocityClient {
|
|
|
969
986
|
let remainingAccounts;
|
|
970
987
|
try {
|
|
971
988
|
remainingAccounts = this.getRemainingAccounts({
|
|
972
|
-
userAccounts: [this.
|
|
989
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
973
990
|
});
|
|
974
991
|
}
|
|
975
992
|
catch (err) {
|
|
@@ -1201,7 +1218,7 @@ class VelocityClient {
|
|
|
1201
1218
|
if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
|
|
1202
1219
|
continue;
|
|
1203
1220
|
}
|
|
1204
|
-
const spotMarket = this.
|
|
1221
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
|
|
1205
1222
|
remainingAccounts.push({
|
|
1206
1223
|
isSigner: false,
|
|
1207
1224
|
isWritable: true,
|
|
@@ -1287,27 +1304,44 @@ class VelocityClient {
|
|
|
1287
1304
|
getUser(subAccountId, authority) {
|
|
1288
1305
|
subAccountId = subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId;
|
|
1289
1306
|
authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
1307
|
+
if (subAccountId === undefined || authority === undefined) {
|
|
1308
|
+
throw new Error('Subaccount ID and authority are required');
|
|
1309
|
+
}
|
|
1290
1310
|
const userMapKey = this.getUserMapKey(subAccountId, authority);
|
|
1291
|
-
|
|
1311
|
+
const user = this.users.get(userMapKey);
|
|
1312
|
+
if (!user) {
|
|
1292
1313
|
throw new Error(`VelocityClient has no user for user id ${userMapKey}`);
|
|
1293
1314
|
}
|
|
1294
|
-
return
|
|
1315
|
+
return user;
|
|
1295
1316
|
}
|
|
1296
1317
|
hasUser(subAccountId, authority) {
|
|
1297
1318
|
subAccountId = subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId;
|
|
1298
1319
|
authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
1320
|
+
if (subAccountId === undefined || authority === undefined) {
|
|
1321
|
+
throw new Error('Subaccount ID and authority are required');
|
|
1322
|
+
}
|
|
1299
1323
|
const userMapKey = this.getUserMapKey(subAccountId, authority);
|
|
1300
1324
|
return this.users.has(userMapKey);
|
|
1301
1325
|
}
|
|
1302
1326
|
getUsers() {
|
|
1303
1327
|
// delegate users get added to the end
|
|
1304
1328
|
return [...this.users.values()]
|
|
1305
|
-
.filter((acct) => acct.getUserAccount().authority.equals(this.wallet.publicKey))
|
|
1306
|
-
.concat([...this.users.values()].filter((acct) => !acct.getUserAccount().authority.equals(this.wallet.publicKey)));
|
|
1329
|
+
.filter((acct) => { var _a; return (_a = acct.getUserAccount()) === null || _a === void 0 ? void 0 : _a.authority.equals(this.wallet.publicKey); })
|
|
1330
|
+
.concat([...this.users.values()].filter((acct) => { var _a; return !((_a = acct.getUserAccount()) === null || _a === void 0 ? void 0 : _a.authority.equals(this.wallet.publicKey)); }));
|
|
1307
1331
|
}
|
|
1308
1332
|
getUserStats() {
|
|
1309
1333
|
return this.userStats;
|
|
1310
1334
|
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Like {@link getUserStats} but throws if there is no UserStats
|
|
1337
|
+
* subscription, for call sites that require a guaranteed account.
|
|
1338
|
+
*/
|
|
1339
|
+
getUserStatsOrThrow() {
|
|
1340
|
+
if (!this.userStats) {
|
|
1341
|
+
throw new Error('VelocityClient has no UserStats subscription');
|
|
1342
|
+
}
|
|
1343
|
+
return this.userStats;
|
|
1344
|
+
}
|
|
1311
1345
|
async fetchReferrerNameAccount(name) {
|
|
1312
1346
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
1313
1347
|
const referrerNameAccountPublicKey = (0, pda_1.getReferrerNamePublicKeySync)(this.program.programId, nameBuffer);
|
|
@@ -1326,6 +1360,14 @@ class VelocityClient {
|
|
|
1326
1360
|
getUserAccount(subAccountId, authority) {
|
|
1327
1361
|
return this.getUser(subAccountId, authority).getUserAccount();
|
|
1328
1362
|
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Like {@link getUserAccount} but throws a named error instead of returning
|
|
1365
|
+
* `undefined` when the account has not been loaded yet. Use at call sites
|
|
1366
|
+
* that structurally require a loaded account.
|
|
1367
|
+
*/
|
|
1368
|
+
getUserAccountOrThrow(subAccountId, authority) {
|
|
1369
|
+
return this.getUser(subAccountId, authority).getUserAccountOrThrow();
|
|
1370
|
+
}
|
|
1329
1371
|
/**
|
|
1330
1372
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
1331
1373
|
* @param subAccountId
|
|
@@ -1338,7 +1380,7 @@ class VelocityClient {
|
|
|
1338
1380
|
return this.getUser(subAccountId, authority).getUserAccountAndSlot();
|
|
1339
1381
|
}
|
|
1340
1382
|
getSpotPosition(marketIndex, subAccountId) {
|
|
1341
|
-
return this.
|
|
1383
|
+
return this.getUserAccountOrThrow(subAccountId).spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
|
|
1342
1384
|
}
|
|
1343
1385
|
getQuoteAssetTokenAmount() {
|
|
1344
1386
|
return this.getTokenAmount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
@@ -1356,7 +1398,7 @@ class VelocityClient {
|
|
|
1356
1398
|
if (spotPosition === undefined) {
|
|
1357
1399
|
return numericConstants_1.ZERO;
|
|
1358
1400
|
}
|
|
1359
|
-
const spotMarket = this.
|
|
1401
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1360
1402
|
return (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType), spotPosition.balanceType);
|
|
1361
1403
|
}
|
|
1362
1404
|
/**
|
|
@@ -1365,7 +1407,7 @@ class VelocityClient {
|
|
|
1365
1407
|
* @param amount
|
|
1366
1408
|
*/
|
|
1367
1409
|
convertToSpotPrecision(marketIndex, amount) {
|
|
1368
|
-
const spotMarket = this.
|
|
1410
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1369
1411
|
return (0, spotMarket_1.castNumberToSpotPrecision)(amount, spotMarket);
|
|
1370
1412
|
}
|
|
1371
1413
|
/**
|
|
@@ -1407,11 +1449,41 @@ class VelocityClient {
|
|
|
1407
1449
|
this.mustIncludeSpotMarketIndexes.add(spotMarketIndex);
|
|
1408
1450
|
});
|
|
1409
1451
|
}
|
|
1452
|
+
cachePerpMarketSlot(slot, ...marketIndexes) {
|
|
1453
|
+
for (const marketIndex of marketIndexes) {
|
|
1454
|
+
if (slot !== undefined) {
|
|
1455
|
+
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
this.perpMarketLastSlotCache.delete(marketIndex);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
cacheSpotMarketSlot(slot, ...marketIndexes) {
|
|
1463
|
+
for (const marketIndex of marketIndexes) {
|
|
1464
|
+
if (slot !== undefined) {
|
|
1465
|
+
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
1466
|
+
}
|
|
1467
|
+
else {
|
|
1468
|
+
this.spotMarketLastSlotCache.delete(marketIndex);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1410
1472
|
getRemainingAccounts(params) {
|
|
1411
|
-
return VelocityCore_1.VelocityCore.remainingAccounts.getRemainingAccounts(
|
|
1473
|
+
return VelocityCore_1.VelocityCore.remainingAccounts.getRemainingAccounts({
|
|
1474
|
+
getPerpMarketAccount: (marketIndex) => this.getPerpMarketAccountOrThrow(marketIndex),
|
|
1475
|
+
getSpotMarketAccount: (marketIndex) => this.getSpotMarketAccountOrThrow(marketIndex),
|
|
1476
|
+
getUserAccountAndSlot: (subAccountId, authority) => this.getUserAccountAndSlot(subAccountId, authority),
|
|
1477
|
+
activeSubAccountId: this.activeSubAccountId,
|
|
1478
|
+
authority: this.authority,
|
|
1479
|
+
perpMarketLastSlotCache: this.perpMarketLastSlotCache,
|
|
1480
|
+
spotMarketLastSlotCache: this.spotMarketLastSlotCache,
|
|
1481
|
+
mustIncludePerpMarketIndexes: this.mustIncludePerpMarketIndexes,
|
|
1482
|
+
mustIncludeSpotMarketIndexes: this.mustIncludeSpotMarketIndexes,
|
|
1483
|
+
}, params);
|
|
1412
1484
|
}
|
|
1413
1485
|
addPerpMarketToRemainingAccountMaps(marketIndex, writable, oracleAccountMap, spotMarketAccountMap, perpMarketAccountMap) {
|
|
1414
|
-
const perpMarketAccount = this.
|
|
1486
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
1415
1487
|
perpMarketAccountMap.set(marketIndex, {
|
|
1416
1488
|
pubkey: perpMarketAccount.pubkey,
|
|
1417
1489
|
isSigner: false,
|
|
@@ -1426,7 +1498,7 @@ class VelocityClient {
|
|
|
1426
1498
|
this.addSpotMarketToRemainingAccountMaps(perpMarketAccount.quoteSpotMarketIndex, false, oracleAccountMap, spotMarketAccountMap);
|
|
1427
1499
|
}
|
|
1428
1500
|
addSpotMarketToRemainingAccountMaps(marketIndex, writable, oracleAccountMap, spotMarketAccountMap) {
|
|
1429
|
-
const spotMarketAccount = this.
|
|
1501
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1430
1502
|
spotMarketAccountMap.set(spotMarketAccount.marketIndex, {
|
|
1431
1503
|
pubkey: spotMarketAccount.pubkey,
|
|
1432
1504
|
isSigner: false,
|
|
@@ -1491,10 +1563,32 @@ class VelocityClient {
|
|
|
1491
1563
|
perpMarketAccountMap,
|
|
1492
1564
|
};
|
|
1493
1565
|
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Look up an open order by its program-assigned order ID from the cached user account.
|
|
1568
|
+
*
|
|
1569
|
+
* `orderId` is the monotonically incrementing u32 counter that the program assigns at
|
|
1570
|
+
* placement time — it is not known until the place instruction executes on-chain. Use
|
|
1571
|
+
* {@link getOrderByUserId} when you need to look up an order by the caller-supplied
|
|
1572
|
+
* `userOrderId` instead.
|
|
1573
|
+
*
|
|
1574
|
+
* Returns `undefined` when the order is not found (already filled, cancelled, or the
|
|
1575
|
+
* account cache is stale).
|
|
1576
|
+
*/
|
|
1494
1577
|
getOrder(orderId, subAccountId) {
|
|
1495
1578
|
var _a;
|
|
1496
1579
|
return (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.orderId === orderId);
|
|
1497
1580
|
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Look up an open order by the caller-supplied `userOrderId` from the cached user account.
|
|
1583
|
+
*
|
|
1584
|
+
* `userOrderId` is a 1-255 slot chosen by the caller in {@link OrderParams} and is stable
|
|
1585
|
+
* across the life of the order — useful when you need to reference an order before the
|
|
1586
|
+
* program-assigned {@link Order.orderId} is known (e.g. immediately after placing without
|
|
1587
|
+
* waiting for confirmation). Use {@link getOrder} when you have the program-assigned ID.
|
|
1588
|
+
*
|
|
1589
|
+
* Returns `undefined` when the order is not found (already filled, cancelled, or the
|
|
1590
|
+
* account cache is stale).
|
|
1591
|
+
*/
|
|
1498
1592
|
getOrderByUserId(userOrderId, subAccountId) {
|
|
1499
1593
|
var _a;
|
|
1500
1594
|
return (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.userOrderId === userOrderId);
|
|
@@ -1506,7 +1600,7 @@ class VelocityClient {
|
|
|
1506
1600
|
* @param tokenProgram
|
|
1507
1601
|
*/
|
|
1508
1602
|
async getAssociatedTokenAccount(marketIndex, useNative = true, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, authority = this.wallet.publicKey, allowOwnerOffCurve = false) {
|
|
1509
|
-
const spotMarket = this.
|
|
1603
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1510
1604
|
if (useNative && spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
|
|
1511
1605
|
return authority;
|
|
1512
1606
|
}
|
|
@@ -1533,7 +1627,7 @@ class VelocityClient {
|
|
|
1533
1627
|
}
|
|
1534
1628
|
async getDepositTxnIx(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false, overrides) {
|
|
1535
1629
|
var _a;
|
|
1536
|
-
const spotMarketAccount = this.
|
|
1630
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1537
1631
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
1538
1632
|
const signer = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
|
|
1539
1633
|
const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signer);
|
|
@@ -1594,7 +1688,7 @@ class VelocityClient {
|
|
|
1594
1688
|
async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false, txParams, initSwiftAccount = false, overrides) {
|
|
1595
1689
|
const tx = await this.createDepositTxn(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, txParams, initSwiftAccount, overrides);
|
|
1596
1690
|
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
1597
|
-
this.
|
|
1691
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
1598
1692
|
return txSig;
|
|
1599
1693
|
}
|
|
1600
1694
|
async getDepositInstruction(amount, marketIndex, userTokenAccount, subAccountId, reduceOnly = false, userInitialized = true, overrides) {
|
|
@@ -1602,8 +1696,12 @@ class VelocityClient {
|
|
|
1602
1696
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
1603
1697
|
let remainingAccounts = [];
|
|
1604
1698
|
if (userInitialized) {
|
|
1699
|
+
const userAccount = await this.forceGetUserAccount(subAccountId);
|
|
1700
|
+
if (!userAccount) {
|
|
1701
|
+
throw new Error('User account not loaded after force fetch');
|
|
1702
|
+
}
|
|
1605
1703
|
remainingAccounts = this.getRemainingAccounts({
|
|
1606
|
-
userAccounts: [
|
|
1704
|
+
userAccounts: [userAccount],
|
|
1607
1705
|
useMarketLastSlotCache: true,
|
|
1608
1706
|
writableSpotMarketIndexes: [marketIndex],
|
|
1609
1707
|
});
|
|
@@ -1614,7 +1712,7 @@ class VelocityClient {
|
|
|
1614
1712
|
writableSpotMarketIndexes: [marketIndex],
|
|
1615
1713
|
});
|
|
1616
1714
|
}
|
|
1617
|
-
const spotMarketAccount = this.
|
|
1715
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1618
1716
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
1619
1717
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
1620
1718
|
await this.addExtraAccountMetasToRemainingAccounts(spotMarketAccount.mint, remainingAccounts);
|
|
@@ -1703,7 +1801,11 @@ class VelocityClient {
|
|
|
1703
1801
|
return;
|
|
1704
1802
|
}
|
|
1705
1803
|
const extraAccountMetasAddress = (0, spl_token_1.getExtraAccountMetaAddress)(mint, hookAccount.programId);
|
|
1706
|
-
const
|
|
1804
|
+
const extraAccountMetasAccount = await this.connection.getAccountInfo(extraAccountMetasAddress);
|
|
1805
|
+
if (!extraAccountMetasAccount) {
|
|
1806
|
+
throw new Error('Extra account metas account not found for transfer hook');
|
|
1807
|
+
}
|
|
1808
|
+
const extraAccountMetas = (0, spl_token_1.getExtraAccountMetas)(extraAccountMetasAccount);
|
|
1707
1809
|
for (const acc of extraAccountMetas) {
|
|
1708
1810
|
// assuming it's an extra account meta that does not rely on ix data
|
|
1709
1811
|
const resolvedAcc = await (0, spl_token_1.resolveExtraAccountMeta)(this.connection, acc, remainingAccounts, Buffer.from([]), hookAccount.programId);
|
|
@@ -1733,7 +1835,7 @@ class VelocityClient {
|
|
|
1733
1835
|
const [, initializeSignedMsgUserOrdersAccountIx] = await this.getInitializeSignedMsgUserOrdersAccountIx(this.authority, 8, overrides);
|
|
1734
1836
|
ixs.push(initializeSignedMsgUserOrdersAccountIx);
|
|
1735
1837
|
}
|
|
1736
|
-
const spotMarket = this.
|
|
1838
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1737
1839
|
const isSolMarket = spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
1738
1840
|
// Use external wallet for deposit source if provided, otherwise use the wallet
|
|
1739
1841
|
const depositSource = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.externalWallet) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
|
|
@@ -1784,6 +1886,9 @@ class VelocityClient {
|
|
|
1784
1886
|
}
|
|
1785
1887
|
ixs.push(depositCollateralIx);
|
|
1786
1888
|
if (!donateAmount.eq(numericConstants_1.ZERO)) {
|
|
1889
|
+
if (!wsolTokenAccount) {
|
|
1890
|
+
throw new Error('wsolTokenAccount is required to donate to rev pool');
|
|
1891
|
+
}
|
|
1787
1892
|
const donateIx = await this.getDepositIntoSpotMarketRevenuePoolIx(1, donateAmount, wsolTokenAccount);
|
|
1788
1893
|
ixs.push(donateIx);
|
|
1789
1894
|
}
|
|
@@ -1795,6 +1900,9 @@ class VelocityClient {
|
|
|
1795
1900
|
// Close the wrapped sol account at the end of the transaction
|
|
1796
1901
|
// Return funds to the deposit source (external wallet if provided)
|
|
1797
1902
|
if (createWSOLTokenAccount) {
|
|
1903
|
+
if (!wsolTokenAccount) {
|
|
1904
|
+
throw new Error('wsolTokenAccount was not created');
|
|
1905
|
+
}
|
|
1798
1906
|
ixs.push((0, spl_token_1.createCloseAccountInstruction)(wsolTokenAccount, depositSource, depositSource, []));
|
|
1799
1907
|
}
|
|
1800
1908
|
return {
|
|
@@ -1827,7 +1935,7 @@ class VelocityClient {
|
|
|
1827
1935
|
const [tx, userAccountPublicKey] = await this.createInitializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex, subAccountId, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio, poolId, overrides);
|
|
1828
1936
|
const additionalSigners = [];
|
|
1829
1937
|
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
1830
|
-
this.
|
|
1938
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
1831
1939
|
await this.addUser(subAccountId);
|
|
1832
1940
|
return [txSig, userAccountPublicKey];
|
|
1833
1941
|
}
|
|
@@ -1850,7 +1958,7 @@ class VelocityClient {
|
|
|
1850
1958
|
}
|
|
1851
1959
|
async getWithdrawalIxs(amount, marketIndex, associatedTokenAddress, reduceOnly = false, subAccountId) {
|
|
1852
1960
|
const withdrawIxs = [];
|
|
1853
|
-
const spotMarketAccount = this.
|
|
1961
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1854
1962
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
1855
1963
|
const authority = this.wallet.publicKey;
|
|
1856
1964
|
const createWSOLTokenAccount = isSolMarket && associatedTokenAddress.equals(authority);
|
|
@@ -1886,7 +1994,7 @@ class VelocityClient {
|
|
|
1886
1994
|
const withdrawIxs = await this.getWithdrawalIxs(amount, marketIndex, associatedTokenAddress, reduceOnly, subAccountId);
|
|
1887
1995
|
const tx = await this.buildTransaction(withdrawIxs, txParams !== null && txParams !== void 0 ? txParams : this.txParams);
|
|
1888
1996
|
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
1889
|
-
this.
|
|
1997
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
1890
1998
|
return txSig;
|
|
1891
1999
|
}
|
|
1892
2000
|
async withdrawAllDustPositions(subAccountId, txParams, opts) {
|
|
@@ -1915,12 +2023,12 @@ class VelocityClient {
|
|
|
1915
2023
|
async getWithdrawIx(amount, marketIndex, userTokenAccount, reduceOnly = false, subAccountId) {
|
|
1916
2024
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1917
2025
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1918
|
-
userAccounts: [this.
|
|
2026
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
1919
2027
|
useMarketLastSlotCache: true,
|
|
1920
2028
|
writableSpotMarketIndexes: [marketIndex],
|
|
1921
2029
|
readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
1922
2030
|
});
|
|
1923
|
-
const spotMarketAccount = this.
|
|
2031
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
1924
2032
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
1925
2033
|
if (this.isTransferHook(spotMarketAccount)) {
|
|
1926
2034
|
await this.addExtraAccountMetasToRemainingAccounts(spotMarketAccount.mint, remainingAccounts);
|
|
@@ -1955,7 +2063,7 @@ class VelocityClient {
|
|
|
1955
2063
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
|
|
1956
2064
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
1957
2065
|
toSubAccountId === this.activeSubAccountId) {
|
|
1958
|
-
this.
|
|
2066
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
1959
2067
|
}
|
|
1960
2068
|
return txSig;
|
|
1961
2069
|
}
|
|
@@ -1964,9 +2072,10 @@ class VelocityClient {
|
|
|
1964
2072
|
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
1965
2073
|
let remainingAccounts;
|
|
1966
2074
|
const userMapKey = this.getUserMapKey(fromSubAccountId, this.wallet.publicKey);
|
|
1967
|
-
|
|
2075
|
+
const mapUser = this.users.get(userMapKey);
|
|
2076
|
+
if (mapUser) {
|
|
1968
2077
|
remainingAccounts = this.getRemainingAccounts({
|
|
1969
|
-
userAccounts: [
|
|
2078
|
+
userAccounts: [mapUser.getUserAccountOrThrow()],
|
|
1970
2079
|
useMarketLastSlotCache: true,
|
|
1971
2080
|
writableSpotMarketIndexes: [marketIndex],
|
|
1972
2081
|
});
|
|
@@ -1987,7 +2096,7 @@ class VelocityClient {
|
|
|
1987
2096
|
toUser,
|
|
1988
2097
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
1989
2098
|
state: await this.getStatePublicKey(),
|
|
1990
|
-
spotMarketVault: this.
|
|
2099
|
+
spotMarketVault: this.getSpotMarketAccountOrThrow(marketIndex).vault,
|
|
1991
2100
|
},
|
|
1992
2101
|
remainingAccounts,
|
|
1993
2102
|
});
|
|
@@ -1996,7 +2105,7 @@ class VelocityClient {
|
|
|
1996
2105
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferDepositByDelegateIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
|
|
1997
2106
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
1998
2107
|
toSubAccountId === this.activeSubAccountId) {
|
|
1999
|
-
this.
|
|
2108
|
+
this.cacheSpotMarketSlot(slot, marketIndex);
|
|
2000
2109
|
}
|
|
2001
2110
|
return txSig;
|
|
2002
2111
|
}
|
|
@@ -2005,9 +2114,10 @@ class VelocityClient {
|
|
|
2005
2114
|
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, toSubAccountId);
|
|
2006
2115
|
let remainingAccounts;
|
|
2007
2116
|
const userMapKey = this.getUserMapKey(fromSubAccountId, this.authority);
|
|
2008
|
-
|
|
2117
|
+
const mapUser = this.users.get(userMapKey);
|
|
2118
|
+
if (mapUser) {
|
|
2009
2119
|
remainingAccounts = this.getRemainingAccounts({
|
|
2010
|
-
userAccounts: [
|
|
2120
|
+
userAccounts: [mapUser.getUserAccountOrThrow()],
|
|
2011
2121
|
useMarketLastSlotCache: true,
|
|
2012
2122
|
writableSpotMarketIndexes: [marketIndex],
|
|
2013
2123
|
});
|
|
@@ -2027,7 +2137,7 @@ class VelocityClient {
|
|
|
2027
2137
|
toUser,
|
|
2028
2138
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2029
2139
|
state: await this.getStatePublicKey(),
|
|
2030
|
-
spotMarketVault: this.
|
|
2140
|
+
spotMarketVault: this.getSpotMarketAccountOrThrow(marketIndex).vault,
|
|
2031
2141
|
},
|
|
2032
2142
|
remainingAccounts,
|
|
2033
2143
|
});
|
|
@@ -2036,19 +2146,16 @@ class VelocityClient {
|
|
|
2036
2146
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferPoolsIx(depositFromMarketIndex, depositToMarketIndex, borrowFromMarketIndex, borrowToMarketIndex, depositAmount, borrowAmount, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
|
|
2037
2147
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
2038
2148
|
toSubAccountId === this.activeSubAccountId) {
|
|
2039
|
-
this.
|
|
2040
|
-
this.spotMarketLastSlotCache.set(depositToMarketIndex, slot);
|
|
2041
|
-
this.spotMarketLastSlotCache.set(borrowFromMarketIndex, slot);
|
|
2042
|
-
this.spotMarketLastSlotCache.set(borrowToMarketIndex, slot);
|
|
2149
|
+
this.cacheSpotMarketSlot(slot, depositFromMarketIndex, depositToMarketIndex, borrowFromMarketIndex, borrowToMarketIndex);
|
|
2043
2150
|
}
|
|
2044
2151
|
return txSig;
|
|
2045
2152
|
}
|
|
2046
2153
|
async getTransferPoolsIx(depositFromMarketIndex, depositToMarketIndex, borrowFromMarketIndex, borrowToMarketIndex, depositAmount, borrowAmount, fromSubAccountId, toSubAccountId, isToNewSubAccount) {
|
|
2047
2154
|
const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, fromSubAccountId);
|
|
2048
2155
|
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
2049
|
-
const userAccounts = [this.
|
|
2156
|
+
const userAccounts = [this.getUserAccountOrThrow(fromSubAccountId)];
|
|
2050
2157
|
if (!isToNewSubAccount) {
|
|
2051
|
-
userAccounts.push(this.
|
|
2158
|
+
userAccounts.push(this.getUserAccountOrThrow(toSubAccountId));
|
|
2052
2159
|
}
|
|
2053
2160
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2054
2161
|
userAccounts,
|
|
@@ -2061,8 +2168,8 @@ class VelocityClient {
|
|
|
2061
2168
|
],
|
|
2062
2169
|
});
|
|
2063
2170
|
const tokenPrograms = new Set();
|
|
2064
|
-
const depositFromSpotMarket = this.
|
|
2065
|
-
const borrowFromSpotMarket = this.
|
|
2171
|
+
const depositFromSpotMarket = this.getSpotMarketAccountOrThrow(depositFromMarketIndex);
|
|
2172
|
+
const borrowFromSpotMarket = this.getSpotMarketAccountOrThrow(borrowFromMarketIndex);
|
|
2066
2173
|
tokenPrograms.add(this.getTokenProgramForSpotMarket(depositFromSpotMarket).toBase58());
|
|
2067
2174
|
tokenPrograms.add(this.getTokenProgramForSpotMarket(borrowFromSpotMarket).toBase58());
|
|
2068
2175
|
for (const tokenProgram of tokenPrograms) {
|
|
@@ -2079,10 +2186,10 @@ class VelocityClient {
|
|
|
2079
2186
|
toUser,
|
|
2080
2187
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2081
2188
|
state: await this.getStatePublicKey(),
|
|
2082
|
-
depositFromSpotMarketVault: this.
|
|
2083
|
-
depositToSpotMarketVault: this.
|
|
2084
|
-
borrowFromSpotMarketVault: this.
|
|
2085
|
-
borrowToSpotMarketVault: this.
|
|
2189
|
+
depositFromSpotMarketVault: this.getSpotMarketAccountOrThrow(depositFromMarketIndex).vault,
|
|
2190
|
+
depositToSpotMarketVault: this.getSpotMarketAccountOrThrow(depositToMarketIndex).vault,
|
|
2191
|
+
borrowFromSpotMarketVault: this.getSpotMarketAccountOrThrow(borrowFromMarketIndex).vault,
|
|
2192
|
+
borrowToSpotMarketVault: this.getSpotMarketAccountOrThrow(borrowToMarketIndex).vault,
|
|
2086
2193
|
velocitySigner: this.getSignerPublicKey(),
|
|
2087
2194
|
},
|
|
2088
2195
|
remainingAccounts,
|
|
@@ -2097,8 +2204,8 @@ class VelocityClient {
|
|
|
2097
2204
|
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, toSubAccountId);
|
|
2098
2205
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2099
2206
|
userAccounts: [
|
|
2100
|
-
this.
|
|
2101
|
-
this.
|
|
2207
|
+
this.getUserAccountOrThrow(fromSubAccountId),
|
|
2208
|
+
this.getUserAccountOrThrow(toSubAccountId),
|
|
2102
2209
|
],
|
|
2103
2210
|
useMarketLastSlotCache: true,
|
|
2104
2211
|
writablePerpMarketIndexes: [marketIndex],
|
|
@@ -2140,9 +2247,9 @@ class VelocityClient {
|
|
|
2140
2247
|
}
|
|
2141
2248
|
async getDepositIntoIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId) {
|
|
2142
2249
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
2143
|
-
const perpMarketAccount = this.
|
|
2250
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
2144
2251
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
2145
|
-
const spotMarketAccount = this.
|
|
2252
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
2146
2253
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2147
2254
|
userAccounts: [],
|
|
2148
2255
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
@@ -2168,7 +2275,7 @@ class VelocityClient {
|
|
|
2168
2275
|
const transferIx = await this.getTransferIsolatedPerpPositionDepositIx(amount, perpMarketIndex, subAccountId, noBuffer);
|
|
2169
2276
|
const needsToSettle = amount.lt(tokenAmountDeposited.neg()) || amount.eq(numericConstants_1.MIN_I64) || trySettle;
|
|
2170
2277
|
if (needsToSettle) {
|
|
2171
|
-
const settleIx = await this.settleMultiplePNLsIx(await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId), this.
|
|
2278
|
+
const settleIx = await this.settleMultiplePNLsIx(await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId), this.getUserAccountOrThrow(subAccountId), [perpMarketIndex], types_1.SettlePnlMode.TRY_SETTLE);
|
|
2172
2279
|
ixs.push(settleIx);
|
|
2173
2280
|
}
|
|
2174
2281
|
ixs.push(transferIx);
|
|
@@ -2181,10 +2288,10 @@ class VelocityClient {
|
|
|
2181
2288
|
}
|
|
2182
2289
|
async getTransferIsolatedPerpPositionDepositIx(amount, perpMarketIndex, subAccountId, noAmountBuffer, signingAuthority) {
|
|
2183
2290
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
2184
|
-
const perpMarketAccount = this.
|
|
2291
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
2185
2292
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
2186
|
-
const spotMarketAccount = this.
|
|
2187
|
-
const user = await this.
|
|
2293
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
2294
|
+
const user = await this.getUserAccountOrThrow(subAccountId);
|
|
2188
2295
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2189
2296
|
userAccounts: [user],
|
|
2190
2297
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
@@ -2211,16 +2318,20 @@ class VelocityClient {
|
|
|
2211
2318
|
}
|
|
2212
2319
|
async getWithdrawFromIsolatedPerpPositionIxsBundle(amount, perpMarketIndex, subAccountId, userTokenAccount) {
|
|
2213
2320
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
2214
|
-
const userAccount = this.
|
|
2321
|
+
const userAccount = this.getUserAccountOrThrow(subAccountId);
|
|
2215
2322
|
const tokenAmountDeposited = this.getIsolatedPerpPositionTokenAmount(perpMarketIndex);
|
|
2216
|
-
const
|
|
2323
|
+
const isolatedPerpPosition = userAccount.perpPositions.find((p) => p.marketIndex === perpMarketIndex);
|
|
2324
|
+
if (!isolatedPerpPosition) {
|
|
2325
|
+
throw new Error(`No perp position found for market index ${perpMarketIndex}`);
|
|
2326
|
+
}
|
|
2327
|
+
const isolatedPositionUnrealizedPnl = (0, position_1.calculateClaimablePnl)(this.getPerpMarketAccountOrThrow(perpMarketIndex), this.getSpotMarketAccountOrThrow(this.getPerpMarketAccountOrThrow(perpMarketIndex).quoteSpotMarketIndex), isolatedPerpPosition, this.getOracleDataForSpotMarket(this.getPerpMarketAccountOrThrow(perpMarketIndex).quoteSpotMarketIndex));
|
|
2217
2328
|
const depositAmountPlusUnrealizedPnl = tokenAmountDeposited.add(isolatedPositionUnrealizedPnl);
|
|
2218
2329
|
const amountToWithdraw = amount.gt(depositAmountPlusUnrealizedPnl)
|
|
2219
2330
|
? numericConstants_1.MIN_I64 // min i64
|
|
2220
2331
|
: amount;
|
|
2221
2332
|
let associatedTokenAccount = userTokenAccount;
|
|
2222
2333
|
if (!associatedTokenAccount) {
|
|
2223
|
-
const perpMarketAccount = this.
|
|
2334
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
2224
2335
|
const quoteSpotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
2225
2336
|
associatedTokenAccount = await this.getAssociatedTokenAccount(quoteSpotMarketIndex);
|
|
2226
2337
|
}
|
|
@@ -2236,11 +2347,11 @@ class VelocityClient {
|
|
|
2236
2347
|
}
|
|
2237
2348
|
async getWithdrawFromIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId) {
|
|
2238
2349
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
2239
|
-
const perpMarketAccount = this.
|
|
2350
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
2240
2351
|
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
|
|
2241
|
-
const spotMarketAccount = this.
|
|
2352
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
2242
2353
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2243
|
-
userAccounts: [this.
|
|
2354
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2244
2355
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
2245
2356
|
readablePerpMarketIndex: [perpMarketIndex],
|
|
2246
2357
|
});
|
|
@@ -2263,7 +2374,7 @@ class VelocityClient {
|
|
|
2263
2374
|
return txSig;
|
|
2264
2375
|
}
|
|
2265
2376
|
async updateSpotMarketCumulativeInterestIx(marketIndex) {
|
|
2266
|
-
const spotMarket = this.
|
|
2377
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
2267
2378
|
return await this.program.instruction.updateSpotMarketCumulativeInterest({
|
|
2268
2379
|
accounts: {
|
|
2269
2380
|
state: await this.getStatePublicKey(),
|
|
@@ -2348,7 +2459,7 @@ class VelocityClient {
|
|
|
2348
2459
|
const preppedTxs = await this.prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams, cancelExistingOrders, settlePnl);
|
|
2349
2460
|
const signedTxs = (await this.txHandler.getSignedTransactionMap(preppedTxs, this.wallet)).signedTxMap;
|
|
2350
2461
|
const { txSig, slot } = await this.sendTransaction(signedTxs.marketOrderTx, [], this.opts, true);
|
|
2351
|
-
this.
|
|
2462
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
2352
2463
|
return {
|
|
2353
2464
|
txSig,
|
|
2354
2465
|
signedFillTx: signedTxs.fillTx,
|
|
@@ -2364,7 +2475,7 @@ class VelocityClient {
|
|
|
2364
2475
|
preIxs.push(await this.getTransferIsolatedPerpPositionDepositIx(isolatedPositionDepositAmount, orderParams.marketIndex, subAccountId));
|
|
2365
2476
|
}
|
|
2366
2477
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlacePerpOrderIx(orderParams, subAccountId), txParams, undefined, undefined, undefined, undefined, preIxs), [], this.opts);
|
|
2367
|
-
this.
|
|
2478
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
2368
2479
|
return txSig;
|
|
2369
2480
|
}
|
|
2370
2481
|
/**
|
|
@@ -2418,7 +2529,7 @@ class VelocityClient {
|
|
|
2418
2529
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2419
2530
|
userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount)
|
|
2420
2531
|
? []
|
|
2421
|
-
: [this.
|
|
2532
|
+
: [this.getUserAccountOrThrow(subAccountId)],
|
|
2422
2533
|
useMarketLastSlotCache: false,
|
|
2423
2534
|
readablePerpMarketIndex: orderParams.marketIndex,
|
|
2424
2535
|
readableSpotMarketIndexes: isDepositToTradeTx
|
|
@@ -2447,7 +2558,7 @@ class VelocityClient {
|
|
|
2447
2558
|
const marketAccountInfos = [];
|
|
2448
2559
|
const oracleAccountInfos = [];
|
|
2449
2560
|
for (const marketIndex of marketIndexes) {
|
|
2450
|
-
const market = this.
|
|
2561
|
+
const market = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
2451
2562
|
marketAccountInfos.push({
|
|
2452
2563
|
pubkey: market.pubkey,
|
|
2453
2564
|
isWritable: true,
|
|
@@ -2508,6 +2619,20 @@ class VelocityClient {
|
|
|
2508
2619
|
},
|
|
2509
2620
|
});
|
|
2510
2621
|
}
|
|
2622
|
+
/**
|
|
2623
|
+
* Cancel an open order and broadcast the transaction.
|
|
2624
|
+
*
|
|
2625
|
+
* When `orderId` is `undefined` (omitted or passed explicitly), the instruction is
|
|
2626
|
+
* sent with a `null` order ID and the program cancels the most recently placed order
|
|
2627
|
+
* on-chain via `get_last_order_id`. This is safe to use in a composed transaction
|
|
2628
|
+
* where a place instruction runs first and the assigned order ID is not yet known.
|
|
2629
|
+
*
|
|
2630
|
+
* Note: when `orderId` is `undefined` and `overrides.withdrawIsolatedDepositAmount`
|
|
2631
|
+
* is also provided, `getOrder` will return `undefined` (the ID is unknown client-side),
|
|
2632
|
+
* causing the withdraw path to throw — supply an explicit `orderId` in that case.
|
|
2633
|
+
*
|
|
2634
|
+
* @see {@link getCancelOrderIx} to obtain the instruction without sending.
|
|
2635
|
+
*/
|
|
2511
2636
|
async cancelOrder(orderId, txParams, subAccountId, overrides) {
|
|
2512
2637
|
const cancelIx = await this.getCancelOrderIx(orderId, subAccountId);
|
|
2513
2638
|
const instructions = [cancelIx];
|
|
@@ -2516,6 +2641,9 @@ class VelocityClient {
|
|
|
2516
2641
|
const perpMarketIndex = order === null || order === void 0 ? void 0 : order.marketIndex;
|
|
2517
2642
|
const withdrawAmount = overrides.withdrawIsolatedDepositAmount;
|
|
2518
2643
|
if (withdrawAmount.gt(numericConstants_1.ZERO)) {
|
|
2644
|
+
if (perpMarketIndex === undefined) {
|
|
2645
|
+
throw new Error(`Order ${orderId} not found when withdrawing isolated deposit`);
|
|
2646
|
+
}
|
|
2519
2647
|
const withdrawIxs = await this.getWithdrawFromIsolatedPerpPositionIxsBundle(withdrawAmount, perpMarketIndex, subAccountId);
|
|
2520
2648
|
instructions.push(...withdrawIxs);
|
|
2521
2649
|
}
|
|
@@ -2523,10 +2651,25 @@ class VelocityClient {
|
|
|
2523
2651
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(instructions, txParams), [], this.opts);
|
|
2524
2652
|
return txSig;
|
|
2525
2653
|
}
|
|
2654
|
+
/**
|
|
2655
|
+
* Build a `cancelOrder` instruction for the given order.
|
|
2656
|
+
*
|
|
2657
|
+
* When `orderId` is `undefined` (omitted or passed explicitly), the instruction is
|
|
2658
|
+
* built with a `null` order ID (`orderId ?? null`). The program interprets a `null`
|
|
2659
|
+
* ID as "cancel the user's most recently placed order" (via `get_last_order_id`
|
|
2660
|
+
* on-chain). This is useful when composing a multi-instruction transaction where a
|
|
2661
|
+
* place instruction precedes the cancel and the program-assigned order ID is not yet
|
|
2662
|
+
* known at build time.
|
|
2663
|
+
*
|
|
2664
|
+
* When `orderId` is supplied, only that specific order is cancelled.
|
|
2665
|
+
*
|
|
2666
|
+
* @see {@link cancelOrder} to send the transaction directly.
|
|
2667
|
+
* @see {@link getCancelOrderByUserIdIx} to cancel by the caller-supplied `userOrderId`.
|
|
2668
|
+
*/
|
|
2526
2669
|
async getCancelOrderIx(orderId, subAccountId) {
|
|
2527
2670
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2528
2671
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2529
|
-
userAccounts: [this.
|
|
2672
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2530
2673
|
useMarketLastSlotCache: true,
|
|
2531
2674
|
});
|
|
2532
2675
|
return await VelocityCore_1.VelocityCore.buildCancelOrderInstruction({
|
|
@@ -2544,10 +2687,13 @@ class VelocityClient {
|
|
|
2544
2687
|
}
|
|
2545
2688
|
async getCancelOrderByUserIdIx(userOrderId, subAccountId) {
|
|
2546
2689
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2547
|
-
const order = this.getOrderByUserId(userOrderId);
|
|
2548
|
-
|
|
2690
|
+
const order = this.getOrderByUserId(userOrderId, subAccountId);
|
|
2691
|
+
if (!order) {
|
|
2692
|
+
throw new Error(`Order with user order id ${userOrderId} not found`);
|
|
2693
|
+
}
|
|
2694
|
+
const oracle = this.getPerpMarketAccountOrThrow(order.marketIndex).oracle;
|
|
2549
2695
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2550
|
-
userAccounts: [this.
|
|
2696
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2551
2697
|
useMarketLastSlotCache: true,
|
|
2552
2698
|
});
|
|
2553
2699
|
return await VelocityCore_1.VelocityCore.buildCancelOrderByUserIdInstruction({
|
|
@@ -2584,7 +2730,7 @@ class VelocityClient {
|
|
|
2584
2730
|
async getCancelOrdersByIdsIx(orderIds, subAccountId, user, overrides) {
|
|
2585
2731
|
var _a, _b, _c;
|
|
2586
2732
|
const userAccountPubKey = (_a = user === null || user === void 0 ? void 0 : user.userAccountPublicKey) !== null && _a !== void 0 ? _a : (await this.getUserAccountPublicKey(subAccountId));
|
|
2587
|
-
const userAccount = (_b = user === null || user === void 0 ? void 0 : user.getUserAccount()) !== null && _b !== void 0 ? _b : this.
|
|
2733
|
+
const userAccount = (_b = user === null || user === void 0 ? void 0 : user.getUserAccount()) !== null && _b !== void 0 ? _b : this.getUserAccountOrThrow(subAccountId);
|
|
2588
2734
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2589
2735
|
userAccounts: [userAccount],
|
|
2590
2736
|
useMarketLastSlotCache: true,
|
|
@@ -2616,7 +2762,7 @@ class VelocityClient {
|
|
|
2616
2762
|
}
|
|
2617
2763
|
}
|
|
2618
2764
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2619
|
-
userAccounts: [this.
|
|
2765
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2620
2766
|
readablePerpMarketIndex,
|
|
2621
2767
|
readableSpotMarketIndexes,
|
|
2622
2768
|
useMarketLastSlotCache: true,
|
|
@@ -2680,7 +2826,7 @@ class VelocityClient {
|
|
|
2680
2826
|
}
|
|
2681
2827
|
}
|
|
2682
2828
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2683
|
-
userAccounts: [this.
|
|
2829
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2684
2830
|
readablePerpMarketIndex,
|
|
2685
2831
|
readableSpotMarketIndexes,
|
|
2686
2832
|
useMarketLastSlotCache: true,
|
|
@@ -2722,7 +2868,7 @@ class VelocityClient {
|
|
|
2722
2868
|
}
|
|
2723
2869
|
}
|
|
2724
2870
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2725
|
-
userAccounts: [this.
|
|
2871
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2726
2872
|
readablePerpMarketIndex,
|
|
2727
2873
|
readableSpotMarketIndexes,
|
|
2728
2874
|
useMarketLastSlotCache: true,
|
|
@@ -2765,7 +2911,7 @@ class VelocityClient {
|
|
|
2765
2911
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2766
2912
|
const isPerp = (0, types_1.isVariant)(params.marketType, 'perp');
|
|
2767
2913
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2768
|
-
userAccounts: [this.
|
|
2914
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
2769
2915
|
readablePerpMarketIndex: isPerp ? [params.marketIndex] : [],
|
|
2770
2916
|
readableSpotMarketIndexes: isPerp ? [] : [params.marketIndex],
|
|
2771
2917
|
useMarketLastSlotCache: true,
|
|
@@ -2804,6 +2950,7 @@ class VelocityClient {
|
|
|
2804
2950
|
// is detected from the order bitflags; pass the taker's decoded escrow (e.g.
|
|
2805
2951
|
// from a RevenueShareEscrowMap) so referred takers also get it attached.
|
|
2806
2952
|
takerEscrow) {
|
|
2953
|
+
var _a;
|
|
2807
2954
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2808
2955
|
let filler;
|
|
2809
2956
|
if (fillerAuthority) {
|
|
@@ -2821,7 +2968,10 @@ class VelocityClient {
|
|
|
2821
2968
|
}
|
|
2822
2969
|
const marketIndex = order
|
|
2823
2970
|
? order.marketIndex
|
|
2824
|
-
: userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
|
|
2971
|
+
: (_a = userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1)) === null || _a === void 0 ? void 0 : _a.marketIndex;
|
|
2972
|
+
if (marketIndex === undefined) {
|
|
2973
|
+
throw new Error('No order found to fill');
|
|
2974
|
+
}
|
|
2825
2975
|
makerInfo = Array.isArray(makerInfo)
|
|
2826
2976
|
? makerInfo
|
|
2827
2977
|
: makerInfo
|
|
@@ -2869,7 +3019,13 @@ class VelocityClient {
|
|
|
2869
3019
|
if (takerEscrowMeta) {
|
|
2870
3020
|
remainingAccounts.push(takerEscrowMeta);
|
|
2871
3021
|
}
|
|
2872
|
-
|
|
3022
|
+
let orderId = null;
|
|
3023
|
+
if (!isSignedMsg) {
|
|
3024
|
+
if (!order) {
|
|
3025
|
+
throw new Error('order is required to fill a non-signedMsg order');
|
|
3026
|
+
}
|
|
3027
|
+
orderId = order.orderId;
|
|
3028
|
+
}
|
|
2873
3029
|
return await VelocityCore_1.VelocityCore.buildFillPerpOrderInstruction({
|
|
2874
3030
|
program: this.program,
|
|
2875
3031
|
orderId,
|
|
@@ -2987,13 +3143,12 @@ class VelocityClient {
|
|
|
2987
3143
|
const lookupTables = res.lookupTables;
|
|
2988
3144
|
const tx = (await this.buildTransaction(ixs, txParams, 0, lookupTables));
|
|
2989
3145
|
const { txSig, slot } = await this.sendTransaction(tx);
|
|
2990
|
-
this.
|
|
2991
|
-
this.spotMarketLastSlotCache.set(inMarketIndex, slot);
|
|
3146
|
+
this.cacheSpotMarketSlot(slot, outMarketIndex, inMarketIndex);
|
|
2992
3147
|
return txSig;
|
|
2993
3148
|
}
|
|
2994
3149
|
async getTitanSwapIx({ titanClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, reduceOnly, userAccountPublicKey, }) {
|
|
2995
|
-
const outMarket = this.
|
|
2996
|
-
const inMarket = this.
|
|
3150
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
3151
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
2997
3152
|
const isExactOut = swapMode === 'ExactOut';
|
|
2998
3153
|
const exactOutBufferedAmountIn = amount.muln(1001).divn(1000); // Add 10bp buffer
|
|
2999
3154
|
const preInstructions = [];
|
|
@@ -3046,8 +3201,8 @@ class VelocityClient {
|
|
|
3046
3201
|
return { ixs, lookupTables };
|
|
3047
3202
|
}
|
|
3048
3203
|
async getJupiterSwapIxV6({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }) {
|
|
3049
|
-
const outMarket = this.
|
|
3050
|
-
const inMarket = this.
|
|
3204
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
3205
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
3051
3206
|
if (!quote) {
|
|
3052
3207
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
3053
3208
|
inputMint: inMarket.mint,
|
|
@@ -3128,8 +3283,11 @@ class VelocityClient {
|
|
|
3128
3283
|
const userAccountPublicKeyToUse = userAccountPublicKey || (await this.getUserAccountPublicKey());
|
|
3129
3284
|
const userAccounts = [];
|
|
3130
3285
|
try {
|
|
3131
|
-
|
|
3132
|
-
|
|
3286
|
+
const userAccount = this.hasUser()
|
|
3287
|
+
? this.getUser().getUserAccount()
|
|
3288
|
+
: undefined;
|
|
3289
|
+
if (userAccount) {
|
|
3290
|
+
userAccounts.push(userAccount);
|
|
3133
3291
|
}
|
|
3134
3292
|
}
|
|
3135
3293
|
catch (err) {
|
|
@@ -3140,8 +3298,8 @@ class VelocityClient {
|
|
|
3140
3298
|
writableSpotMarketIndexes: [outMarketIndex, inMarketIndex],
|
|
3141
3299
|
readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
3142
3300
|
});
|
|
3143
|
-
const outSpotMarket = this.
|
|
3144
|
-
const inSpotMarket = this.
|
|
3301
|
+
const outSpotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
3302
|
+
const inSpotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
3145
3303
|
const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
|
|
3146
3304
|
const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
|
|
3147
3305
|
if (!outTokenProgram.equals(inTokenProgram)) {
|
|
@@ -3205,8 +3363,8 @@ class VelocityClient {
|
|
|
3205
3363
|
}
|
|
3206
3364
|
async getSwapIxV2({ swapClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, reduceOnly, quote, v6, userAccountPublicKey, }) {
|
|
3207
3365
|
// Get market accounts to determine mints
|
|
3208
|
-
const outMarket = this.
|
|
3209
|
-
const inMarket = this.
|
|
3366
|
+
const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
3367
|
+
const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
3210
3368
|
const isExactOut = swapMode === 'ExactOut';
|
|
3211
3369
|
const preInstructions = [];
|
|
3212
3370
|
// Handle token accounts if not provided
|
|
@@ -3280,7 +3438,7 @@ class VelocityClient {
|
|
|
3280
3438
|
return this.sendTransaction(tx);
|
|
3281
3439
|
}
|
|
3282
3440
|
async getStakeForMSOLIx({ amount, userAccountPublicKey, }) {
|
|
3283
|
-
const wSOLMint = this.
|
|
3441
|
+
const wSOLMint = this.getSpotMarketAccountOrThrow(1).mint;
|
|
3284
3442
|
const mSOLAccount = await this.getAssociatedTokenAccount(2);
|
|
3285
3443
|
const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
|
|
3286
3444
|
const wSOLAccountExists = await this.checkIfAccountExists(wSOLAccount);
|
|
@@ -3431,7 +3589,7 @@ class VelocityClient {
|
|
|
3431
3589
|
}
|
|
3432
3590
|
async placeAndTakePerpOrder(orderParams, makerInfo, successCondition, auctionDurationPercentage, txParams, subAccountId, takerEscrow) {
|
|
3433
3591
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, successCondition, auctionDurationPercentage, subAccountId, undefined, takerEscrow), txParams), [], this.opts);
|
|
3434
|
-
this.
|
|
3592
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
3435
3593
|
return txSig;
|
|
3436
3594
|
}
|
|
3437
3595
|
async preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails, auctionDurationPercentage, optionalIxs, isolatedPositionDepositAmount) {
|
|
@@ -3469,6 +3627,9 @@ class VelocityClient {
|
|
|
3469
3627
|
useSimulatedComputeUnits: false,
|
|
3470
3628
|
};
|
|
3471
3629
|
if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
|
|
3630
|
+
if (!txParams) {
|
|
3631
|
+
throw new Error('txParams is required when simulating compute units or exiting early on failed simulation');
|
|
3632
|
+
}
|
|
3472
3633
|
const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined, lookupTableAccounts, true, recentBlockHash, optionalIxs));
|
|
3473
3634
|
const simulationResult = await txParamProcessor_1.TransactionParamProcessor.getTxSimComputeUnits(placeAndTakeTxToSim, this.connection, (_b = txParams.computeUnitsBufferMultiplier) !== null && _b !== void 0 ? _b : 1.2, txParams.lowerBoundCu);
|
|
3474
3635
|
if (shouldExitIfSimulationFails && !simulationResult.success) {
|
|
@@ -3495,7 +3656,7 @@ class VelocityClient {
|
|
|
3495
3656
|
const prepSettlePnlTx = async () => {
|
|
3496
3657
|
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
3497
3658
|
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
3498
|
-
const settlePnlIx = await this.settlePNLIx(userAccountPublicKey, this.
|
|
3659
|
+
const settlePnlIx = await this.settlePNLIx(userAccountPublicKey, this.getUserAccountOrThrow(subAccountId), orderParams.marketIndex);
|
|
3499
3660
|
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3500
3661
|
}
|
|
3501
3662
|
return;
|
|
@@ -3518,8 +3679,11 @@ class VelocityClient {
|
|
|
3518
3679
|
const signedTxs = (await this.txHandler.getSignedTransactionMap(txsToSign,
|
|
3519
3680
|
// @ts-ignore
|
|
3520
3681
|
this.provider.wallet)).signedTxMap;
|
|
3682
|
+
if (!signedTxs.placeAndTakeTx) {
|
|
3683
|
+
throw new Error('placeAndTakeTx was not built');
|
|
3684
|
+
}
|
|
3521
3685
|
const { txSig, slot } = await this.sendTransaction(signedTxs.placeAndTakeTx, [], this.opts, true);
|
|
3522
|
-
this.
|
|
3686
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
3523
3687
|
return {
|
|
3524
3688
|
txSig,
|
|
3525
3689
|
signedCancelExistingOrdersTx: signedTxs.cancelExistingOrdersTx,
|
|
@@ -3541,7 +3705,7 @@ class VelocityClient {
|
|
|
3541
3705
|
: makerInfo
|
|
3542
3706
|
? [makerInfo]
|
|
3543
3707
|
: [];
|
|
3544
|
-
const userAccounts = [this.
|
|
3708
|
+
const userAccounts = [this.getUserAccountOrThrow(subAccountId)];
|
|
3545
3709
|
for (const maker of makerInfo) {
|
|
3546
3710
|
userAccounts.push(maker.makerUserAccount);
|
|
3547
3711
|
}
|
|
@@ -3585,7 +3749,7 @@ class VelocityClient {
|
|
|
3585
3749
|
}
|
|
3586
3750
|
async placeAndMakePerpOrder(orderParams, takerInfo, txParams, subAccountId, takerEscrow) {
|
|
3587
3751
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, subAccountId, takerEscrow), txParams), [], this.opts);
|
|
3588
|
-
this.
|
|
3752
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
3589
3753
|
return txSig;
|
|
3590
3754
|
}
|
|
3591
3755
|
async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, subAccountId,
|
|
@@ -3599,7 +3763,7 @@ class VelocityClient {
|
|
|
3599
3763
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
3600
3764
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3601
3765
|
userAccounts: [
|
|
3602
|
-
this.
|
|
3766
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
3603
3767
|
takerInfo.takerUserAccount,
|
|
3604
3768
|
],
|
|
3605
3769
|
useMarketLastSlotCache: true,
|
|
@@ -3674,6 +3838,9 @@ class VelocityClient {
|
|
|
3674
3838
|
});
|
|
3675
3839
|
}
|
|
3676
3840
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3841
|
+
if (!keypair) {
|
|
3842
|
+
throw new Error('No keypair available to sign message');
|
|
3843
|
+
}
|
|
3677
3844
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
|
3678
3845
|
}
|
|
3679
3846
|
async placeSignedMsgTakerOrder(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex, txParams) {
|
|
@@ -3727,7 +3894,7 @@ class VelocityClient {
|
|
|
3727
3894
|
async placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, txParams, subAccountId, precedingIxs = [], overrideCustomIxIndex, takerEscrow) {
|
|
3728
3895
|
const ixs = await this.getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, subAccountId, precedingIxs, overrideCustomIxIndex, takerEscrow);
|
|
3729
3896
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3730
|
-
this.
|
|
3897
|
+
this.cachePerpMarketSlot(slot, orderParams.marketIndex);
|
|
3731
3898
|
return txSig;
|
|
3732
3899
|
}
|
|
3733
3900
|
async getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, subAccountId, precedingIxs = [], overrideCustomIxIndex,
|
|
@@ -3741,7 +3908,7 @@ class VelocityClient {
|
|
|
3741
3908
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
3742
3909
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3743
3910
|
userAccounts: [
|
|
3744
|
-
this.
|
|
3911
|
+
this.getUserAccountOrThrow(subAccountId),
|
|
3745
3912
|
takerInfo.takerUserAccount,
|
|
3746
3913
|
],
|
|
3747
3914
|
useMarketLastSlotCache: false,
|
|
@@ -3867,9 +4034,13 @@ class VelocityClient {
|
|
|
3867
4034
|
* @returns
|
|
3868
4035
|
*/
|
|
3869
4036
|
async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }, subAccountId, overrides) {
|
|
3870
|
-
var _a, _b, _c, _d, _e
|
|
4037
|
+
var _a, _b, _c, _d, _e;
|
|
3871
4038
|
const userPubKey = (_b = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _a === void 0 ? void 0 : _a.getUserAccountPublicKey()) !== null && _b !== void 0 ? _b : (await this.getUserAccountPublicKey(subAccountId));
|
|
3872
|
-
const
|
|
4039
|
+
const overrideUserAccount = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _c === void 0 ? void 0 : _c.getUserAccount();
|
|
4040
|
+
if ((overrides === null || overrides === void 0 ? void 0 : overrides.user) && !overrideUserAccount) {
|
|
4041
|
+
throw new Error('modifyOrder: override user account is not loaded');
|
|
4042
|
+
}
|
|
4043
|
+
const userAccount = overrideUserAccount !== null && overrideUserAccount !== void 0 ? overrideUserAccount : this.getUserAccountOrThrow(subAccountId);
|
|
3873
4044
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3874
4045
|
userAccounts: [userAccount],
|
|
3875
4046
|
useMarketLastSlotCache: true,
|
|
@@ -3890,7 +4061,7 @@ class VelocityClient {
|
|
|
3890
4061
|
policy: policy || null,
|
|
3891
4062
|
maxTs: maxTs || null,
|
|
3892
4063
|
};
|
|
3893
|
-
const authority = (
|
|
4064
|
+
const authority = (_e = (_d = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _d !== void 0 ? _d : overrideUserAccount === null || overrideUserAccount === void 0 ? void 0 : overrideUserAccount.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
3894
4065
|
return await VelocityCore_1.VelocityCore.buildModifyOrderInstruction({
|
|
3895
4066
|
program: this.program,
|
|
3896
4067
|
orderId,
|
|
@@ -3927,7 +4098,7 @@ class VelocityClient {
|
|
|
3927
4098
|
async getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }, subAccountId) {
|
|
3928
4099
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
3929
4100
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3930
|
-
userAccounts: [this.
|
|
4101
|
+
userAccounts: [this.getUserAccountOrThrow(subAccountId)],
|
|
3931
4102
|
useMarketLastSlotCache: true,
|
|
3932
4103
|
});
|
|
3933
4104
|
const orderParams = {
|
|
@@ -3965,7 +4136,7 @@ class VelocityClient {
|
|
|
3965
4136
|
: marketIndexes;
|
|
3966
4137
|
if (filterInvalidMarkets) {
|
|
3967
4138
|
for (const marketIndex of marketIndexes) {
|
|
3968
|
-
const perpMarketAccount = this.
|
|
4139
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
3969
4140
|
const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
|
|
3970
4141
|
const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
|
|
3971
4142
|
const oracleGuardRails = stateAccountAndSlot.data.oracleGuardRails;
|
|
@@ -4205,7 +4376,7 @@ class VelocityClient {
|
|
|
4205
4376
|
}
|
|
4206
4377
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams, liquidatorSubAccountId) {
|
|
4207
4378
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
4208
|
-
this.
|
|
4379
|
+
this.cachePerpMarketSlot(slot, marketIndex);
|
|
4209
4380
|
return txSig;
|
|
4210
4381
|
}
|
|
4211
4382
|
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, liquidatorSubAccountId) {
|
|
@@ -4213,7 +4384,10 @@ class VelocityClient {
|
|
|
4213
4384
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4214
4385
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4215
4386
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4216
|
-
userAccounts: [
|
|
4387
|
+
userAccounts: [
|
|
4388
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4389
|
+
userAccount,
|
|
4390
|
+
],
|
|
4217
4391
|
useMarketLastSlotCache: true,
|
|
4218
4392
|
writablePerpMarketIndexes: [marketIndex],
|
|
4219
4393
|
});
|
|
@@ -4233,7 +4407,7 @@ class VelocityClient {
|
|
|
4233
4407
|
}
|
|
4234
4408
|
async liquidatePerpWithFill(userAccountPublicKey, userAccount, marketIndex, makerInfos, txParams, liquidatorSubAccountId) {
|
|
4235
4409
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId), txParams), [], this.opts);
|
|
4236
|
-
this.
|
|
4410
|
+
this.cachePerpMarketSlot(slot, marketIndex);
|
|
4237
4411
|
return txSig;
|
|
4238
4412
|
}
|
|
4239
4413
|
async getLiquidatePerpWithFillIx(userAccountPublicKey, userAccount, marketIndex, makerInfos, liquidatorSubAccountId) {
|
|
@@ -4273,8 +4447,7 @@ class VelocityClient {
|
|
|
4273
4447
|
}
|
|
4274
4448
|
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
4275
4449
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
4276
|
-
this.
|
|
4277
|
-
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
4450
|
+
this.cacheSpotMarketSlot(slot, assetMarketIndex, liabilityMarketIndex);
|
|
4278
4451
|
return txSig;
|
|
4279
4452
|
}
|
|
4280
4453
|
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId) {
|
|
@@ -4282,7 +4455,10 @@ class VelocityClient {
|
|
|
4282
4455
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4283
4456
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4284
4457
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4285
|
-
userAccounts: [
|
|
4458
|
+
userAccounts: [
|
|
4459
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4460
|
+
userAccount,
|
|
4461
|
+
],
|
|
4286
4462
|
useMarketLastSlotCache: true,
|
|
4287
4463
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
4288
4464
|
});
|
|
@@ -4299,8 +4475,8 @@ class VelocityClient {
|
|
|
4299
4475
|
});
|
|
4300
4476
|
}
|
|
4301
4477
|
async getJupiterLiquidateSpotWithSwapIxV6({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, liquidatorSubAccountId, maxAccounts, }) {
|
|
4302
|
-
const liabilityMarket = this.
|
|
4303
|
-
const assetMarket = this.
|
|
4478
|
+
const liabilityMarket = this.getSpotMarketAccountOrThrow(liabilityMarketIndex);
|
|
4479
|
+
const assetMarket = this.getSpotMarketAccountOrThrow(assetMarketIndex);
|
|
4304
4480
|
if (!quote) {
|
|
4305
4481
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
4306
4482
|
inputMint: assetMarket.mint,
|
|
@@ -4378,8 +4554,8 @@ class VelocityClient {
|
|
|
4378
4554
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
4379
4555
|
readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
4380
4556
|
});
|
|
4381
|
-
const liabilitySpotMarket = this.
|
|
4382
|
-
const assetSpotMarket = this.
|
|
4557
|
+
const liabilitySpotMarket = this.getSpotMarketAccountOrThrow(liabilityMarketIndex);
|
|
4558
|
+
const assetSpotMarket = this.getSpotMarketAccountOrThrow(assetMarketIndex);
|
|
4383
4559
|
const liabilityTokenProgram = this.getTokenProgramForSpotMarket(liabilitySpotMarket);
|
|
4384
4560
|
const assetTokenProgram = this.getTokenProgramForSpotMarket(assetSpotMarket);
|
|
4385
4561
|
if (!liabilityTokenProgram.equals(assetTokenProgram)) {
|
|
@@ -4442,68 +4618,10 @@ class VelocityClient {
|
|
|
4442
4618
|
});
|
|
4443
4619
|
return { beginSwapIx, endSwapIx };
|
|
4444
4620
|
}
|
|
4445
|
-
async getInsuranceFundSwapIx({ inMarketIndex, outMarketIndex, amountIn, inTokenAccount, outTokenAccount, }) {
|
|
4446
|
-
const remainingAccounts = await this.getRemainingAccounts({
|
|
4447
|
-
userAccounts: [],
|
|
4448
|
-
writableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
|
|
4449
|
-
});
|
|
4450
|
-
const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
4451
|
-
const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
4452
|
-
if (this.isToken2022(inSpotMarket) || this.isToken2022(outSpotMarket)) {
|
|
4453
|
-
remainingAccounts.push({
|
|
4454
|
-
pubkey: inSpotMarket.mint,
|
|
4455
|
-
isWritable: false,
|
|
4456
|
-
isSigner: false,
|
|
4457
|
-
});
|
|
4458
|
-
remainingAccounts.push({
|
|
4459
|
-
pubkey: outSpotMarket.mint,
|
|
4460
|
-
isWritable: false,
|
|
4461
|
-
isSigner: false,
|
|
4462
|
-
});
|
|
4463
|
-
if (this.isTransferHook(inSpotMarket)) {
|
|
4464
|
-
this.addExtraAccountMetasToRemainingAccounts(inSpotMarket.mint, remainingAccounts);
|
|
4465
|
-
}
|
|
4466
|
-
if (this.isTransferHook(outSpotMarket)) {
|
|
4467
|
-
this.addExtraAccountMetasToRemainingAccounts(outSpotMarket.mint, remainingAccounts);
|
|
4468
|
-
}
|
|
4469
|
-
}
|
|
4470
|
-
const ifRebalanceConfig = (0, pda_1.getIfRebalanceConfigPublicKey)(this.program.programId, inMarketIndex, outMarketIndex);
|
|
4471
|
-
const beginSwapIx = await this.program.instruction.beginInsuranceFundSwap(inMarketIndex, outMarketIndex, amountIn, {
|
|
4472
|
-
accounts: {
|
|
4473
|
-
state: await this.getStatePublicKey(),
|
|
4474
|
-
authority: this.wallet.publicKey,
|
|
4475
|
-
outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
|
|
4476
|
-
inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
|
|
4477
|
-
outTokenAccount,
|
|
4478
|
-
inTokenAccount,
|
|
4479
|
-
ifRebalanceConfig: ifRebalanceConfig,
|
|
4480
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4481
|
-
velocitySigner: this.getStateAccount().signer,
|
|
4482
|
-
instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4483
|
-
},
|
|
4484
|
-
remainingAccounts,
|
|
4485
|
-
});
|
|
4486
|
-
const endSwapIx = await this.program.instruction.endInsuranceFundSwap(inMarketIndex, outMarketIndex, {
|
|
4487
|
-
accounts: {
|
|
4488
|
-
state: await this.getStatePublicKey(),
|
|
4489
|
-
authority: this.wallet.publicKey,
|
|
4490
|
-
outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
|
|
4491
|
-
inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
|
|
4492
|
-
outTokenAccount,
|
|
4493
|
-
inTokenAccount,
|
|
4494
|
-
ifRebalanceConfig: ifRebalanceConfig,
|
|
4495
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4496
|
-
velocitySigner: this.getStateAccount().signer,
|
|
4497
|
-
instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4498
|
-
},
|
|
4499
|
-
remainingAccounts,
|
|
4500
|
-
});
|
|
4501
|
-
return { beginSwapIx, endSwapIx };
|
|
4502
|
-
}
|
|
4503
4621
|
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
4504
4622
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
4505
|
-
this.
|
|
4506
|
-
this.
|
|
4623
|
+
this.cachePerpMarketSlot(slot, perpMarketIndex);
|
|
4624
|
+
this.cacheSpotMarketSlot(slot, liabilityMarketIndex);
|
|
4507
4625
|
return txSig;
|
|
4508
4626
|
}
|
|
4509
4627
|
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId) {
|
|
@@ -4511,7 +4629,10 @@ class VelocityClient {
|
|
|
4511
4629
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4512
4630
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4513
4631
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4514
|
-
userAccounts: [
|
|
4632
|
+
userAccounts: [
|
|
4633
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4634
|
+
userAccount,
|
|
4635
|
+
],
|
|
4515
4636
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
4516
4637
|
writableSpotMarketIndexes: [liabilityMarketIndex],
|
|
4517
4638
|
});
|
|
@@ -4529,8 +4650,8 @@ class VelocityClient {
|
|
|
4529
4650
|
}
|
|
4530
4651
|
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
4531
4652
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
4532
|
-
this.
|
|
4533
|
-
this.
|
|
4653
|
+
this.cachePerpMarketSlot(slot, perpMarketIndex);
|
|
4654
|
+
this.cacheSpotMarketSlot(slot, assetMarketIndex);
|
|
4534
4655
|
return txSig;
|
|
4535
4656
|
}
|
|
4536
4657
|
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, liquidatorSubAccountId) {
|
|
@@ -4538,7 +4659,10 @@ class VelocityClient {
|
|
|
4538
4659
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4539
4660
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4540
4661
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4541
|
-
userAccounts: [
|
|
4662
|
+
userAccounts: [
|
|
4663
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4664
|
+
userAccount,
|
|
4665
|
+
],
|
|
4542
4666
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
4543
4667
|
writableSpotMarketIndexes: [assetMarketIndex],
|
|
4544
4668
|
});
|
|
@@ -4563,7 +4687,10 @@ class VelocityClient {
|
|
|
4563
4687
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4564
4688
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4565
4689
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4566
|
-
userAccounts: [
|
|
4690
|
+
userAccounts: [
|
|
4691
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4692
|
+
userAccount,
|
|
4693
|
+
],
|
|
4567
4694
|
writablePerpMarketIndexes: [marketIndex],
|
|
4568
4695
|
writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
4569
4696
|
});
|
|
@@ -4593,10 +4720,13 @@ class VelocityClient {
|
|
|
4593
4720
|
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
4594
4721
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4595
4722
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4596
|
-
userAccounts: [
|
|
4723
|
+
userAccounts: [
|
|
4724
|
+
this.getUserAccountOrThrow(liquidatorSubAccountId),
|
|
4725
|
+
userAccount,
|
|
4726
|
+
],
|
|
4597
4727
|
writableSpotMarketIndexes: [marketIndex],
|
|
4598
4728
|
});
|
|
4599
|
-
const spotMarket = this.
|
|
4729
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4600
4730
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
4601
4731
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
4602
4732
|
if (this.isTransferHook(spotMarket)) {
|
|
@@ -4637,7 +4767,7 @@ class VelocityClient {
|
|
|
4637
4767
|
return txSig;
|
|
4638
4768
|
}
|
|
4639
4769
|
async getUpdatePrelaunchOracleIx(perpMarketIndex) {
|
|
4640
|
-
const perpMarket = this.
|
|
4770
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4641
4771
|
if (!(0, types_1.isVariant)(perpMarket.oracleSource, 'prelaunch')) {
|
|
4642
4772
|
throw new Error(`Wrong oracle source ${perpMarket.oracleSource}`);
|
|
4643
4773
|
}
|
|
@@ -4654,7 +4784,7 @@ class VelocityClient {
|
|
|
4654
4784
|
return txSig;
|
|
4655
4785
|
}
|
|
4656
4786
|
async getUpdatePerpBidAskTwapIx(perpMarketIndex, makers) {
|
|
4657
|
-
const perpMarket = this.
|
|
4787
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
4658
4788
|
const remainingAccounts = [];
|
|
4659
4789
|
for (const [maker, makerStats] of makers) {
|
|
4660
4790
|
remainingAccounts.push({
|
|
@@ -4707,10 +4837,14 @@ class VelocityClient {
|
|
|
4707
4837
|
this.eventEmitter.emit(eventName, data);
|
|
4708
4838
|
}
|
|
4709
4839
|
getOracleDataForPerpMarket(marketIndex) {
|
|
4710
|
-
|
|
4840
|
+
const oraclePriceDataAndSlot = this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(marketIndex);
|
|
4841
|
+
if (!oraclePriceDataAndSlot) {
|
|
4842
|
+
throw new Error(`No oracle price data for perp market ${marketIndex}`);
|
|
4843
|
+
}
|
|
4844
|
+
return oraclePriceDataAndSlot.data;
|
|
4711
4845
|
}
|
|
4712
4846
|
getMMOracleDataForPerpMarket(marketIndex) {
|
|
4713
|
-
const perpMarket = this.
|
|
4847
|
+
const perpMarket = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
4714
4848
|
const oracleData = this.getOracleDataForPerpMarket(marketIndex);
|
|
4715
4849
|
const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
|
|
4716
4850
|
const isMMOracleActive = !perpMarket.marketStats.mmOracleSlot.eq(numericConstants_1.ZERO);
|
|
@@ -4730,11 +4864,12 @@ class VelocityClient {
|
|
|
4730
4864
|
.gt(oracleData.sequenceId.div(new anchor_1.BN(10000)));
|
|
4731
4865
|
let isExchangeOracleMoreRecent = true;
|
|
4732
4866
|
if (doSlotCheckForRecency &&
|
|
4733
|
-
oracleData.slot
|
|
4867
|
+
oracleData.slot.lte(perpMarket.marketStats.mmOracleSlot)) {
|
|
4734
4868
|
isExchangeOracleMoreRecent = false;
|
|
4735
4869
|
}
|
|
4736
4870
|
else if (!doSlotCheckForRecency &&
|
|
4737
|
-
oracleData.sequenceId
|
|
4871
|
+
oracleData.sequenceId != null &&
|
|
4872
|
+
oracleData.sequenceId.lt(mmOracleSequenceId)) {
|
|
4738
4873
|
isExchangeOracleMoreRecent = false;
|
|
4739
4874
|
}
|
|
4740
4875
|
const conf = (0, utils_3.getOracleConfidenceFromMMOracleData)(perpMarket.marketStats.mmOraclePrice, oracleData);
|
|
@@ -4761,7 +4896,11 @@ class VelocityClient {
|
|
|
4761
4896
|
}
|
|
4762
4897
|
}
|
|
4763
4898
|
getOracleDataForSpotMarket(marketIndex) {
|
|
4764
|
-
|
|
4899
|
+
const oraclePriceDataAndSlot = this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(marketIndex);
|
|
4900
|
+
if (!oraclePriceDataAndSlot) {
|
|
4901
|
+
throw new Error(`No oracle price data for spot market ${marketIndex}`);
|
|
4902
|
+
}
|
|
4903
|
+
return oraclePriceDataAndSlot.data;
|
|
4765
4904
|
}
|
|
4766
4905
|
async initializeInsuranceFundStake(marketIndex, txParams) {
|
|
4767
4906
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams), [], this.opts);
|
|
@@ -4771,7 +4910,7 @@ class VelocityClient {
|
|
|
4771
4910
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
4772
4911
|
const accounts = {
|
|
4773
4912
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
4774
|
-
spotMarket: this.
|
|
4913
|
+
spotMarket: this.getSpotMarketAccountOrThrow(marketIndex).pubkey,
|
|
4775
4914
|
userStats: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
|
|
4776
4915
|
),
|
|
4777
4916
|
authority: this.wallet.publicKey,
|
|
@@ -4785,7 +4924,7 @@ class VelocityClient {
|
|
|
4785
4924
|
});
|
|
4786
4925
|
}
|
|
4787
4926
|
async getAddInsuranceFundStakeIx(marketIndex, amount, collateralAccountPublicKey) {
|
|
4788
|
-
const spotMarket = this.
|
|
4927
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4789
4928
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
4790
4929
|
const remainingAccounts = [];
|
|
4791
4930
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
@@ -4832,7 +4971,7 @@ class VelocityClient {
|
|
|
4832
4971
|
*/
|
|
4833
4972
|
async getAddInsuranceFundStakeIxs({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }) {
|
|
4834
4973
|
const addIfStakeIxs = [];
|
|
4835
|
-
const spotMarketAccount = this.
|
|
4974
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4836
4975
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
4837
4976
|
const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
4838
4977
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
@@ -4870,7 +5009,7 @@ class VelocityClient {
|
|
|
4870
5009
|
return addIfStakeIxs;
|
|
4871
5010
|
}
|
|
4872
5011
|
async requestRemoveInsuranceFundStake(marketIndex, amount, txParams) {
|
|
4873
|
-
const spotMarketAccount = this.
|
|
5012
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4874
5013
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
4875
5014
|
const ix = await this.program.instruction.requestRemoveInsuranceFundStake(marketIndex, amount, {
|
|
4876
5015
|
accounts: {
|
|
@@ -4888,7 +5027,7 @@ class VelocityClient {
|
|
|
4888
5027
|
return txSig;
|
|
4889
5028
|
}
|
|
4890
5029
|
async cancelRequestRemoveInsuranceFundStake(marketIndex, txParams) {
|
|
4891
|
-
const spotMarketAccount = this.
|
|
5030
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4892
5031
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
4893
5032
|
const ix = await this.program.instruction.cancelRequestRemoveInsuranceFundStake(marketIndex, {
|
|
4894
5033
|
accounts: {
|
|
@@ -4907,7 +5046,7 @@ class VelocityClient {
|
|
|
4907
5046
|
}
|
|
4908
5047
|
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey, txParams) {
|
|
4909
5048
|
const removeIfStakeIxs = [];
|
|
4910
|
-
const spotMarketAccount = this.
|
|
5049
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4911
5050
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
4912
5051
|
const additionalSigners = [];
|
|
4913
5052
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
@@ -4966,7 +5105,7 @@ class VelocityClient {
|
|
|
4966
5105
|
}
|
|
4967
5106
|
async getUpdateUserQuoteAssetInsuranceStakeIx(authority) {
|
|
4968
5107
|
const marketIndex = numericConstants_1.QUOTE_SPOT_MARKET_INDEX;
|
|
4969
|
-
const spotMarket = this.
|
|
5108
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
4970
5109
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
|
|
4971
5110
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
|
|
4972
5111
|
const ix = this.program.instruction.updateUserQuoteAssetInsuranceStake({
|
|
@@ -4981,36 +5120,13 @@ class VelocityClient {
|
|
|
4981
5120
|
});
|
|
4982
5121
|
return ix;
|
|
4983
5122
|
}
|
|
4984
|
-
async updateUserGovTokenInsuranceStake(authority, txParams) {
|
|
4985
|
-
const ix = await this.getUpdateUserGovTokenInsuranceStakeIx(authority);
|
|
4986
|
-
const tx = await this.buildTransaction(ix, txParams);
|
|
4987
|
-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4988
|
-
return txSig;
|
|
4989
|
-
}
|
|
4990
|
-
async getUpdateUserGovTokenInsuranceStakeIx(authority) {
|
|
4991
|
-
const marketIndex = numericConstants_1.GOV_SPOT_MARKET_INDEX;
|
|
4992
|
-
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
4993
|
-
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
|
|
4994
|
-
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
|
|
4995
|
-
const ix = this.program.instruction.updateUserGovTokenInsuranceStake({
|
|
4996
|
-
accounts: {
|
|
4997
|
-
state: await this.getStatePublicKey(),
|
|
4998
|
-
spotMarket: spotMarket.pubkey,
|
|
4999
|
-
insuranceFundStake: ifStakeAccountPublicKey,
|
|
5000
|
-
userStats: userStatsPublicKey,
|
|
5001
|
-
signer: this.wallet.publicKey,
|
|
5002
|
-
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
5003
|
-
},
|
|
5004
|
-
});
|
|
5005
|
-
return ix;
|
|
5006
|
-
}
|
|
5007
5123
|
async settleRevenueToInsuranceFund(spotMarketIndex, txParams) {
|
|
5008
5124
|
const tx = await this.buildTransaction(await this.getSettleRevenueToInsuranceFundIx(spotMarketIndex), txParams);
|
|
5009
5125
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5010
5126
|
return txSig;
|
|
5011
5127
|
}
|
|
5012
5128
|
async getSettleRevenueToInsuranceFundIx(spotMarketIndex) {
|
|
5013
|
-
const spotMarketAccount = this.
|
|
5129
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
5014
5130
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
5015
5131
|
const remainingAccounts = [];
|
|
5016
5132
|
this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
|
|
@@ -5030,17 +5146,35 @@ class VelocityClient {
|
|
|
5030
5146
|
});
|
|
5031
5147
|
return ix;
|
|
5032
5148
|
}
|
|
5149
|
+
async sweepPerpMarketFees(perpMarketIndex, txParams) {
|
|
5150
|
+
const tx = await this.buildTransaction(await this.getSweepPerpMarketFeesIx(perpMarketIndex), txParams);
|
|
5151
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5152
|
+
return txSig;
|
|
5153
|
+
}
|
|
5154
|
+
async getSweepPerpMarketFeesIx(perpMarketIndex) {
|
|
5155
|
+
const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
5156
|
+
const spotMarketAccount = this.getSpotMarketAccountOrThrow(perpMarketAccount.quoteSpotMarketIndex);
|
|
5157
|
+
const ix = await this.program.instruction.sweepPerpMarketFees(perpMarketIndex, {
|
|
5158
|
+
accounts: {
|
|
5159
|
+
state: await this.getStatePublicKey(),
|
|
5160
|
+
perpMarket: perpMarketAccount.pubkey,
|
|
5161
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
5162
|
+
oracle: perpMarketAccount.oracle,
|
|
5163
|
+
},
|
|
5164
|
+
});
|
|
5165
|
+
return ix;
|
|
5166
|
+
}
|
|
5033
5167
|
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, txParams) {
|
|
5034
5168
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex), txParams), [], this.opts);
|
|
5035
5169
|
return txSig;
|
|
5036
5170
|
}
|
|
5037
5171
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|
|
5038
5172
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5039
|
-
userAccounts: [
|
|
5173
|
+
userAccounts: [],
|
|
5040
5174
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
5041
5175
|
writableSpotMarketIndexes: [spotMarketIndex],
|
|
5042
5176
|
});
|
|
5043
|
-
const spotMarket = this.
|
|
5177
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
5044
5178
|
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
|
|
5045
5179
|
return await this.program.instruction.resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, {
|
|
5046
5180
|
accounts: {
|
|
@@ -5055,7 +5189,7 @@ class VelocityClient {
|
|
|
5055
5189
|
});
|
|
5056
5190
|
}
|
|
5057
5191
|
async getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey) {
|
|
5058
|
-
const spotMarket = await this.
|
|
5192
|
+
const spotMarket = await this.getSpotMarketAccountOrThrow(marketIndex);
|
|
5059
5193
|
const remainingAccounts = [];
|
|
5060
5194
|
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
5061
5195
|
if (this.isTransferHook(spotMarket)) {
|
|
@@ -5089,8 +5223,8 @@ class VelocityClient {
|
|
|
5089
5223
|
}
|
|
5090
5224
|
getPerpMarketExtendedInfo(marketIndex) {
|
|
5091
5225
|
var _a, _b;
|
|
5092
|
-
const marketAccount = this.
|
|
5093
|
-
const quoteAccount = this.
|
|
5226
|
+
const marketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
5227
|
+
const quoteAccount = this.getSpotMarketAccountOrThrow(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
5094
5228
|
const extendedInfo = {
|
|
5095
5229
|
marketIndex,
|
|
5096
5230
|
minOrderSize: (_a = marketAccount.marketStats) === null || _a === void 0 ? void 0 : _a.minOrderSize,
|
|
@@ -5121,12 +5255,12 @@ class VelocityClient {
|
|
|
5121
5255
|
let takerFee = feeTier.feeNumerator / feeTier.feeDenominator;
|
|
5122
5256
|
let makerFee = feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
|
|
5123
5257
|
if (marketIndex !== undefined) {
|
|
5124
|
-
let marketAccount
|
|
5258
|
+
let marketAccount;
|
|
5125
5259
|
if ((0, types_1.isVariant)(marketType, 'perp')) {
|
|
5126
|
-
marketAccount = this.
|
|
5260
|
+
marketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
|
|
5127
5261
|
}
|
|
5128
5262
|
else {
|
|
5129
|
-
marketAccount = this.
|
|
5263
|
+
marketAccount = this.getSpotMarketAccountOrThrow(marketIndex);
|
|
5130
5264
|
}
|
|
5131
5265
|
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
5132
5266
|
makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
|
|
@@ -5189,7 +5323,7 @@ class VelocityClient {
|
|
|
5189
5323
|
return [verifyIx, ix];
|
|
5190
5324
|
}
|
|
5191
5325
|
async getPauseSpotMarketDepositWithdrawIx(spotMarketIndex) {
|
|
5192
|
-
const spotMarket = await this.
|
|
5326
|
+
const spotMarket = await this.getSpotMarketAccountOrThrow(spotMarketIndex);
|
|
5193
5327
|
return this.program.instruction.pauseSpotMarketDepositWithdraw({
|
|
5194
5328
|
accounts: {
|
|
5195
5329
|
state: await this.getStatePublicKey(),
|
|
@@ -5223,7 +5357,7 @@ class VelocityClient {
|
|
|
5223
5357
|
programId: this.program.programId,
|
|
5224
5358
|
keys: [
|
|
5225
5359
|
{
|
|
5226
|
-
pubkey: this.
|
|
5360
|
+
pubkey: this.getPerpMarketAccountOrThrow(marketIndex).pubkey,
|
|
5227
5361
|
isWritable: true,
|
|
5228
5362
|
isSigner: false,
|
|
5229
5363
|
},
|
|
@@ -5266,7 +5400,7 @@ class VelocityClient {
|
|
|
5266
5400
|
programId: this.program.programId,
|
|
5267
5401
|
keys: [
|
|
5268
5402
|
{
|
|
5269
|
-
pubkey: this.
|
|
5403
|
+
pubkey: this.getPerpMarketAccountOrThrow(marketIndex).pubkey,
|
|
5270
5404
|
isWritable: true,
|
|
5271
5405
|
isSigner: false,
|
|
5272
5406
|
},
|
|
@@ -5360,7 +5494,7 @@ class VelocityClient {
|
|
|
5360
5494
|
state: await this.getStatePublicKey(),
|
|
5361
5495
|
keeper: this.wallet.publicKey,
|
|
5362
5496
|
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
5363
|
-
quoteMarket: this.
|
|
5497
|
+
quoteMarket: this.getSpotMarketAccountOrThrow(0).pubkey,
|
|
5364
5498
|
},
|
|
5365
5499
|
remainingAccounts,
|
|
5366
5500
|
});
|
|
@@ -5370,7 +5504,7 @@ class VelocityClient {
|
|
|
5370
5504
|
return txSig;
|
|
5371
5505
|
}
|
|
5372
5506
|
async getUpdateConstituentOracleInfoIx(constituent) {
|
|
5373
|
-
const spotMarket = this.
|
|
5507
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(constituent.spotMarketIndex);
|
|
5374
5508
|
return this.program.instruction.updateConstituentOracleInfo({
|
|
5375
5509
|
accounts: {
|
|
5376
5510
|
keeper: this.wallet.publicKey,
|
|
@@ -5392,12 +5526,12 @@ class VelocityClient {
|
|
|
5392
5526
|
});
|
|
5393
5527
|
const constituentInTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, inMarketIndex);
|
|
5394
5528
|
const constituentOutTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, outMarketIndex);
|
|
5395
|
-
const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.
|
|
5396
|
-
const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.
|
|
5529
|
+
const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccountOrThrow(inMarketIndex).mint, userAuthority);
|
|
5530
|
+
const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccountOrThrow(outMarketIndex).mint, userAuthority);
|
|
5397
5531
|
const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, inMarketIndex);
|
|
5398
5532
|
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, outMarketIndex);
|
|
5399
|
-
const inMarketMint = this.
|
|
5400
|
-
const outMarketMint = this.
|
|
5533
|
+
const inMarketMint = this.getSpotMarketAccountOrThrow(inMarketIndex).mint;
|
|
5534
|
+
const outMarketMint = this.getSpotMarketAccountOrThrow(outMarketIndex).mint;
|
|
5401
5535
|
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool);
|
|
5402
5536
|
return this.program.instruction.lpPoolSwap(inMarketIndex, outMarketIndex, inAmount, minOutAmount, {
|
|
5403
5537
|
remainingAccounts,
|
|
@@ -5469,7 +5603,7 @@ class VelocityClient {
|
|
|
5469
5603
|
userAccounts: [],
|
|
5470
5604
|
writableSpotMarketIndexes: [inMarketIndex],
|
|
5471
5605
|
});
|
|
5472
|
-
const spotMarket = this.
|
|
5606
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
5473
5607
|
const inMarketMint = spotMarket.mint;
|
|
5474
5608
|
const isSolMarket = inMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
5475
5609
|
let wSolTokenAccount;
|
|
@@ -5531,7 +5665,7 @@ class VelocityClient {
|
|
|
5531
5665
|
userAccounts: [],
|
|
5532
5666
|
readableSpotMarketIndexes: [inMarketIndex],
|
|
5533
5667
|
});
|
|
5534
|
-
const spotMarket = this.
|
|
5668
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
|
|
5535
5669
|
const inMarketMint = spotMarket.mint;
|
|
5536
5670
|
const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, inMarketIndex);
|
|
5537
5671
|
const lpMint = lpPool.mint;
|
|
@@ -5564,7 +5698,7 @@ class VelocityClient {
|
|
|
5564
5698
|
userAccounts: [],
|
|
5565
5699
|
writableSpotMarketIndexes: [outMarketIndex],
|
|
5566
5700
|
});
|
|
5567
|
-
const spotMarket = this.
|
|
5701
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
5568
5702
|
const outMarketMint = spotMarket.mint;
|
|
5569
5703
|
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
|
|
5570
5704
|
if (outMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
|
|
@@ -5610,7 +5744,7 @@ class VelocityClient {
|
|
|
5610
5744
|
userAccounts: [],
|
|
5611
5745
|
writableSpotMarketIndexes: [outMarketIndex],
|
|
5612
5746
|
});
|
|
5613
|
-
const spotMarket = this.
|
|
5747
|
+
const spotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
|
|
5614
5748
|
const outMarketMint = spotMarket.mint;
|
|
5615
5749
|
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
|
|
5616
5750
|
const lpMint = lpPool.mint;
|
|
@@ -5710,7 +5844,7 @@ class VelocityClient {
|
|
|
5710
5844
|
const remainingAccounts = [];
|
|
5711
5845
|
remainingAccounts.push(...perpMarketIndexes.map((index) => {
|
|
5712
5846
|
return {
|
|
5713
|
-
pubkey: this.
|
|
5847
|
+
pubkey: this.getPerpMarketAccountOrThrow(index).pubkey,
|
|
5714
5848
|
isSigner: false,
|
|
5715
5849
|
isWritable: true,
|
|
5716
5850
|
};
|
|
@@ -5824,7 +5958,7 @@ class VelocityClient {
|
|
|
5824
5958
|
});
|
|
5825
5959
|
}
|
|
5826
5960
|
isOrderIncreasingPosition(orderParams, subAccountId) {
|
|
5827
|
-
const userAccount = this.
|
|
5961
|
+
const userAccount = this.getUserAccountOrThrow(subAccountId);
|
|
5828
5962
|
const perpPosition = userAccount.perpPositions.find((p) => p.marketIndex === orderParams.marketIndex);
|
|
5829
5963
|
if (!perpPosition)
|
|
5830
5964
|
return true;
|