@velocity-exchange/sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/bun.lock +23 -1
- package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +5 -3
- package/lib/browser/accounts/basicUserAccountSubscriber.js +4 -3
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
- package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +4 -3
- package/lib/browser/accounts/bulkAccountLoader.d.ts +5 -5
- package/lib/browser/accounts/bulkAccountLoader.js +12 -1
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcAccountSubscriber.js +8 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +13 -5
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +12 -8
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +8 -2
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +3 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.js +4 -3
- package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
- package/lib/browser/accounts/pollingOracleAccountSubscriber.js +16 -5
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
- package/lib/browser/accounts/pollingTokenAccountSubscriber.js +16 -5
- package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +8 -4
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +17 -11
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +6 -6
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
- package/lib/browser/accounts/types.d.ts +4 -4
- package/lib/browser/accounts/utils.d.ts +1 -0
- package/lib/browser/accounts/utils.js +8 -1
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketAccountSubscriber.js +17 -5
- package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
- package/lib/browser/accounts/webSocketAccountSubscriberV2.js +17 -6
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +14 -3
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +0 -3
- package/lib/browser/addresses/marketAddresses.js +3 -2
- package/lib/browser/addresses/pda.d.ts +0 -2
- package/lib/browser/addresses/pda.js +1 -14
- package/lib/browser/adminClient.d.ts +24 -28
- package/lib/browser/adminClient.js +156 -157
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +1 -1
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +6 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/browser/bankrun/bankrunConnection.d.ts +6 -4
- package/lib/browser/bankrun/bankrunConnection.js +69 -31
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +3 -2
- package/lib/browser/clock/clockSubscriber.d.ts +6 -6
- package/lib/browser/clock/clockSubscriber.js +4 -3
- package/lib/browser/config.d.ts +1 -1
- package/lib/browser/config.js +8 -4
- package/lib/browser/constants/index.d.ts +1 -2
- package/lib/browser/constants/index.js +1 -2
- package/lib/browser/constants/numericConstants.d.ts +1 -3
- package/lib/browser/constants/numericConstants.js +3 -5
- package/lib/browser/constituentMap/constituentMap.js +5 -1
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
- package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
- package/lib/browser/core/instructions/perpOrders.js +14 -0
- package/lib/browser/core/remainingAccounts.d.ts +2 -2
- package/lib/browser/core/remainingAccounts.js +2 -2
- package/lib/browser/decode/user.js +9 -1
- package/lib/browser/dlob/DLOB.d.ts +6 -1
- package/lib/browser/dlob/DLOB.js +201 -138
- package/lib/browser/dlob/DLOBNode.d.ts +5 -2
- package/lib/browser/dlob/DLOBNode.js +7 -0
- package/lib/browser/dlob/DLOBSubscriber.js +37 -32
- package/lib/browser/dlob/NodeList.js +8 -7
- package/lib/browser/dlob/orderBookLevels.js +19 -12
- package/lib/browser/events/eventList.js +4 -1
- package/lib/browser/events/eventSubscriber.d.ts +5 -2
- package/lib/browser/events/eventSubscriber.js +75 -26
- package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
- package/lib/browser/events/eventsServerLogProvider.js +15 -8
- package/lib/browser/events/fetchLogs.d.ts +1 -1
- package/lib/browser/events/fetchLogs.js +4 -2
- package/lib/browser/events/pollingLogProvider.d.ts +1 -1
- package/lib/browser/events/pollingLogProvider.js +1 -0
- package/lib/browser/events/txEventCache.js +6 -2
- package/lib/browser/events/types.d.ts +2 -4
- package/lib/browser/events/types.js +0 -2
- package/lib/browser/events/webSocketLogProvider.d.ts +1 -1
- package/lib/browser/events/webSocketLogProvider.js +5 -2
- package/lib/browser/factory/bigNum.js +1 -1
- package/lib/browser/idl/velocity.d.ts +1243 -1586
- package/lib/browser/idl/velocity.json +1234 -1577
- package/lib/browser/index.d.ts +0 -2
- package/lib/browser/index.js +0 -2
- package/lib/browser/jupiter/jupiterClient.d.ts +1 -1
- package/lib/browser/jupiter/jupiterClient.js +18 -8
- package/lib/browser/marginCalculation.js +1 -0
- package/lib/browser/math/amm.d.ts +31 -13
- package/lib/browser/math/amm.js +77 -22
- package/lib/browser/math/bankruptcy.js +1 -1
- package/lib/browser/math/funding.js +6 -6
- package/lib/browser/math/insurance.d.ts +1 -1
- package/lib/browser/math/insurance.js +4 -5
- package/lib/browser/math/margin.d.ts +1 -9
- package/lib/browser/math/margin.js +3 -62
- package/lib/browser/math/market.d.ts +4 -12
- package/lib/browser/math/market.js +6 -40
- package/lib/browser/math/oracles.d.ts +0 -3
- package/lib/browser/math/oracles.js +1 -14
- package/lib/browser/math/orders.d.ts +0 -5
- package/lib/browser/math/orders.js +2 -74
- package/lib/browser/math/position.d.ts +0 -4
- package/lib/browser/math/position.js +5 -10
- package/lib/browser/math/repeg.d.ts +0 -1
- package/lib/browser/math/repeg.js +1 -23
- package/lib/browser/math/spotBalance.d.ts +4 -4
- package/lib/browser/math/spotBalance.js +6 -6
- package/lib/browser/math/spotMarket.d.ts +0 -6
- package/lib/browser/math/spotMarket.js +1 -16
- package/lib/browser/math/spotPosition.d.ts +4 -4
- package/lib/browser/math/state.d.ts +0 -2
- package/lib/browser/math/state.js +1 -9
- package/lib/browser/math/superStake.d.ts +3 -53
- package/lib/browser/math/superStake.js +16 -13
- package/lib/browser/math/trade.js +6 -6
- package/lib/browser/memcmp.d.ts +0 -1
- package/lib/browser/memcmp.js +1 -10
- package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
- package/lib/browser/oracles/pythClient.js +9 -3
- package/lib/browser/oracles/pythLazerClient.js +3 -2
- package/lib/browser/oracles/utils.d.ts +4 -0
- package/lib/browser/oracles/utils.js +9 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +8 -2
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +32 -8
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/pyth/types.d.ts +0 -1
- package/lib/browser/slot/SlotSubscriber.d.ts +1 -1
- package/lib/browser/slot/SlotSubscriber.js +2 -1
- package/lib/browser/slot/SlothashSubscriber.d.ts +3 -2
- package/lib/browser/slot/SlothashSubscriber.js +11 -4
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +13 -5
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +1 -1
- package/lib/browser/swift/swiftOrderSubscriber.js +10 -5
- package/lib/browser/testClient.js +3 -2
- package/lib/browser/tokenFaucet.js +16 -2
- package/lib/browser/tx/baseTxSender.d.ts +4 -4
- package/lib/browser/tx/baseTxSender.js +5 -4
- package/lib/browser/tx/fastSingleTxSender.d.ts +3 -3
- package/lib/browser/tx/fastSingleTxSender.js +9 -5
- package/lib/browser/tx/reportTransactionError.d.ts +2 -2
- package/lib/browser/tx/reportTransactionError.js +5 -1
- package/lib/browser/tx/retryTxSender.d.ts +1 -1
- package/lib/browser/tx/retryTxSender.js +4 -2
- package/lib/browser/tx/txHandler.d.ts +7 -1
- package/lib/browser/tx/txHandler.js +54 -40
- package/lib/browser/tx/txParamProcessor.d.ts +4 -1
- package/lib/browser/tx/txParamProcessor.js +6 -0
- package/lib/browser/tx/types.d.ts +1 -1
- package/lib/browser/tx/whileValidTxSender.d.ts +1 -6
- package/lib/browser/tx/whileValidTxSender.js +35 -13
- package/lib/browser/types.d.ts +27 -70
- package/lib/browser/types.js +2 -2
- package/lib/browser/user.d.ts +21 -7
- package/lib/browser/user.js +156 -132
- package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
- package/lib/browser/userMap/referrerMap.js +10 -3
- package/lib/browser/userMap/revenueShareEscrowMap.js +4 -0
- package/lib/browser/userMap/userMap.d.ts +1 -1
- package/lib/browser/userMap/userMap.js +36 -23
- package/lib/browser/userMap/userStatsMap.d.ts +1 -1
- package/lib/browser/userMap/userStatsMap.js +18 -13
- package/lib/browser/userStats.d.ts +7 -2
- package/lib/browser/userStats.js +18 -4
- package/lib/browser/util/TransactionConfirmationManager.js +4 -2
- package/lib/browser/util/chainClock.d.ts +1 -1
- package/lib/browser/util/computeUnits.d.ts +1 -1
- package/lib/browser/util/computeUnits.js +6 -1
- package/lib/browser/velocityClient.d.ts +92 -34
- package/lib/browser/velocityClient.js +414 -280
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +5 -3
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserAccountSubscriber.js +4 -3
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
- package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/basicUserStatsAccountSubscriber.js +4 -3
- package/lib/node/accounts/bulkAccountLoader.d.ts +5 -5
- package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/bulkAccountLoader.js +12 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcAccountSubscriber.js +8 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +13 -5
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +12 -8
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +8 -2
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +3 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +4 -3
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +16 -5
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +16 -5
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +8 -4
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserAccountSubscriber.js +17 -11
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +6 -6
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
- package/lib/node/accounts/types.d.ts +4 -4
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/utils.d.ts +1 -0
- package/lib/node/accounts/utils.d.ts.map +1 -1
- package/lib/node/accounts/utils.js +8 -1
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.js +17 -5
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriberV2.js +17 -6
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +14 -3
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +0 -3
- package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
- package/lib/node/addresses/marketAddresses.js +3 -2
- package/lib/node/addresses/pda.d.ts +0 -2
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +1 -14
- package/lib/node/adminClient.d.ts +24 -28
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +156 -157
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +6 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/node/bankrun/bankrunConnection.d.ts +6 -4
- package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
- package/lib/node/bankrun/bankrunConnection.js +69 -31
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +3 -2
- package/lib/node/clock/clockSubscriber.d.ts +6 -6
- package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
- package/lib/node/clock/clockSubscriber.js +4 -3
- package/lib/node/config.d.ts +1 -1
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +8 -4
- package/lib/node/constants/index.d.ts +1 -2
- package/lib/node/constants/index.d.ts.map +1 -1
- package/lib/node/constants/index.js +1 -2
- package/lib/node/constants/numericConstants.d.ts +1 -3
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +3 -5
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +5 -1
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
- package/lib/node/core/instructions/perpOrders.d.ts +14 -0
- package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
- package/lib/node/core/instructions/perpOrders.js +14 -0
- package/lib/node/core/remainingAccounts.d.ts +2 -2
- package/lib/node/core/remainingAccounts.d.ts.map +1 -1
- package/lib/node/core/remainingAccounts.js +2 -2
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +9 -1
- package/lib/node/dlob/DLOB.d.ts +6 -1
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +201 -138
- package/lib/node/dlob/DLOBNode.d.ts +5 -2
- package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
- package/lib/node/dlob/DLOBNode.js +7 -0
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +37 -32
- package/lib/node/dlob/NodeList.d.ts.map +1 -1
- package/lib/node/dlob/NodeList.js +8 -7
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +19 -12
- package/lib/node/events/eventList.d.ts +3 -3
- package/lib/node/events/eventList.d.ts.map +1 -1
- package/lib/node/events/eventList.js +4 -1
- package/lib/node/events/eventSubscriber.d.ts +5 -2
- package/lib/node/events/eventSubscriber.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.js +75 -26
- package/lib/node/events/eventsServerLogProvider.d.ts +2 -2
- package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
- package/lib/node/events/eventsServerLogProvider.js +15 -8
- package/lib/node/events/fetchLogs.d.ts +1 -1
- package/lib/node/events/fetchLogs.d.ts.map +1 -1
- package/lib/node/events/fetchLogs.js +4 -2
- package/lib/node/events/pollingLogProvider.d.ts +2 -2
- package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
- package/lib/node/events/pollingLogProvider.js +1 -0
- package/lib/node/events/txEventCache.d.ts +3 -3
- package/lib/node/events/txEventCache.d.ts.map +1 -1
- package/lib/node/events/txEventCache.js +6 -2
- package/lib/node/events/types.d.ts +2 -4
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +0 -2
- package/lib/node/events/webSocketLogProvider.d.ts +2 -2
- package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
- package/lib/node/events/webSocketLogProvider.js +5 -2
- package/lib/node/factory/bigNum.js +1 -1
- package/lib/node/idl/velocity.d.ts +1243 -1586
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +1234 -1577
- package/lib/node/index.d.ts +0 -2
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +0 -2
- package/lib/node/jupiter/jupiterClient.d.ts +1 -1
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.js +18 -8
- package/lib/node/marginCalculation.d.ts.map +1 -1
- package/lib/node/marginCalculation.js +1 -0
- package/lib/node/math/amm.d.ts +31 -13
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +77 -22
- package/lib/node/math/bankruptcy.js +1 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +6 -6
- package/lib/node/math/insurance.d.ts +1 -1
- package/lib/node/math/insurance.d.ts.map +1 -1
- package/lib/node/math/insurance.js +4 -5
- package/lib/node/math/margin.d.ts +1 -9
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +3 -62
- package/lib/node/math/market.d.ts +4 -12
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +6 -40
- package/lib/node/math/oracles.d.ts +0 -3
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +1 -14
- package/lib/node/math/orders.d.ts +0 -5
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +2 -74
- package/lib/node/math/position.d.ts +1 -5
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +5 -10
- package/lib/node/math/repeg.d.ts +0 -1
- package/lib/node/math/repeg.d.ts.map +1 -1
- package/lib/node/math/repeg.js +1 -23
- package/lib/node/math/spotBalance.d.ts +4 -4
- package/lib/node/math/spotBalance.d.ts.map +1 -1
- package/lib/node/math/spotBalance.js +6 -6
- package/lib/node/math/spotMarket.d.ts +0 -6
- package/lib/node/math/spotMarket.d.ts.map +1 -1
- package/lib/node/math/spotMarket.js +1 -16
- package/lib/node/math/spotPosition.d.ts +4 -4
- package/lib/node/math/spotPosition.d.ts.map +1 -1
- package/lib/node/math/state.d.ts +0 -2
- package/lib/node/math/state.d.ts.map +1 -1
- package/lib/node/math/state.js +1 -9
- package/lib/node/math/superStake.d.ts +3 -53
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +16 -13
- package/lib/node/math/trade.d.ts +2 -2
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +6 -6
- package/lib/node/memcmp.d.ts +0 -1
- package/lib/node/memcmp.d.ts.map +1 -1
- package/lib/node/memcmp.js +1 -10
- package/lib/node/oracles/oracleClientCache.d.ts +1 -1
- package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
- package/lib/node/oracles/prelaunchOracleClient.js +3 -2
- package/lib/node/oracles/pythClient.d.ts.map +1 -1
- package/lib/node/oracles/pythClient.js +9 -3
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +3 -2
- package/lib/node/oracles/utils.d.ts +4 -0
- package/lib/node/oracles/utils.d.ts.map +1 -1
- package/lib/node/oracles/utils.js +9 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +8 -2
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +32 -8
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/pyth/types.d.ts +0 -1
- package/lib/node/pyth/types.d.ts.map +1 -1
- package/lib/node/slot/SlotSubscriber.d.ts +1 -1
- package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlotSubscriber.js +2 -1
- package/lib/node/slot/SlothashSubscriber.d.ts +3 -2
- package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
- package/lib/node/slot/SlothashSubscriber.js +11 -4
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +13 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts +1 -1
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +10 -5
- package/lib/node/testClient.js +3 -2
- package/lib/node/tokenFaucet.d.ts.map +1 -1
- package/lib/node/tokenFaucet.js +16 -2
- package/lib/node/tx/baseTxSender.d.ts +4 -4
- package/lib/node/tx/baseTxSender.d.ts.map +1 -1
- package/lib/node/tx/baseTxSender.js +5 -4
- package/lib/node/tx/fastSingleTxSender.d.ts +3 -3
- package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
- package/lib/node/tx/fastSingleTxSender.js +9 -5
- package/lib/node/tx/reportTransactionError.d.ts +2 -2
- package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
- package/lib/node/tx/reportTransactionError.js +5 -1
- package/lib/node/tx/retryTxSender.d.ts +1 -1
- package/lib/node/tx/retryTxSender.d.ts.map +1 -1
- package/lib/node/tx/retryTxSender.js +4 -2
- package/lib/node/tx/txHandler.d.ts +9 -3
- package/lib/node/tx/txHandler.d.ts.map +1 -1
- package/lib/node/tx/txHandler.js +54 -40
- package/lib/node/tx/txParamProcessor.d.ts +4 -1
- package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
- package/lib/node/tx/txParamProcessor.js +6 -0
- package/lib/node/tx/types.d.ts +1 -1
- package/lib/node/tx/types.d.ts.map +1 -1
- package/lib/node/tx/whileValidTxSender.d.ts +1 -6
- package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
- package/lib/node/tx/whileValidTxSender.js +35 -13
- package/lib/node/types.d.ts +25 -68
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +2 -2
- package/lib/node/user.d.ts +21 -7
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +156 -132
- package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/userMap/grpcSubscription.d.ts +1 -1
- package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +10 -3
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +4 -0
- package/lib/node/userMap/userMap.d.ts +1 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +36 -23
- package/lib/node/userMap/userStatsMap.d.ts +1 -1
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +18 -13
- package/lib/node/userStats.d.ts +7 -2
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +18 -4
- package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
- package/lib/node/util/TransactionConfirmationManager.js +4 -2
- package/lib/node/util/chainClock.d.ts +1 -1
- package/lib/node/util/chainClock.d.ts.map +1 -1
- package/lib/node/util/computeUnits.d.ts +1 -1
- package/lib/node/util/computeUnits.d.ts.map +1 -1
- package/lib/node/util/computeUnits.js +6 -1
- package/lib/node/velocityClient.d.ts +93 -35
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +414 -280
- package/package.json +5 -3
- package/src/accounts/basicUserAccountSubscriber.ts +7 -5
- package/src/accounts/basicUserStatsAccountSubscriber.ts +9 -5
- package/src/accounts/bulkAccountLoader.ts +20 -7
- package/src/accounts/grpcAccountSubscriber.ts +11 -3
- package/src/accounts/grpcMultiAccountSubscriber.ts +24 -9
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +16 -12
- package/src/accounts/grpcProgramAccountSubscriber.ts +11 -3
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -7
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +66 -39
- package/src/accounts/laserProgramAccountSubscriber.ts +3 -0
- package/src/accounts/oneShotUserAccountSubscriber.ts +5 -3
- package/src/accounts/oneShotUserStatsAccountSubscriber.ts +8 -3
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -5
- package/src/accounts/pollingOracleAccountSubscriber.ts +17 -10
- package/src/accounts/pollingTokenAccountSubscriber.ts +17 -10
- package/src/accounts/pollingUserAccountSubscriber.ts +26 -20
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +12 -10
- package/src/accounts/pollingVelocityClientAccountSubscriber.ts +76 -30
- package/src/accounts/types.ts +6 -4
- package/src/accounts/utils.ts +10 -0
- package/src/accounts/webSocketAccountSubscriber.ts +23 -10
- package/src/accounts/webSocketAccountSubscriberV2.ts +23 -8
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +17 -2
- package/src/accounts/webSocketProgramAccountSubscriber.ts +29 -4
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +30 -4
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +29 -4
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -2
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +15 -2
- package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +76 -48
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +74 -35
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
- package/src/addresses/marketAddresses.ts +3 -2
- package/src/addresses/pda.ts +0 -25
- package/src/adminClient.ts +273 -303
- package/src/auctionSubscriber/auctionSubscriber.ts +7 -5
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -5
- package/src/bankrun/bankrunConnection.ts +83 -39
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
- package/src/clock/clockSubscriber.ts +10 -9
- package/src/config.ts +8 -3
- package/src/constants/index.ts +1 -2
- package/src/constants/numericConstants.ts +3 -3
- package/src/constituentMap/constituentMap.ts +8 -1
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
- package/src/core/instructions/perpOrders.ts +14 -0
- package/src/core/remainingAccounts.ts +4 -4
- package/src/decode/user.ts +8 -1
- package/src/dlob/DLOB.ts +296 -172
- package/src/dlob/DLOBNode.ts +23 -3
- package/src/dlob/DLOBSubscriber.ts +51 -34
- package/src/dlob/NodeList.ts +8 -7
- package/src/dlob/orderBookLevels.ts +45 -25
- package/src/events/eventList.ts +4 -1
- package/src/events/eventSubscriber.ts +107 -49
- package/src/events/eventsServerLogProvider.ts +22 -13
- package/src/events/fetchLogs.ts +3 -3
- package/src/events/pollingLogProvider.ts +2 -2
- package/src/events/txEventCache.ts +8 -2
- package/src/events/types.ts +0 -8
- package/src/events/webSocketLogProvider.ts +5 -3
- package/src/factory/bigNum.ts +2 -2
- package/src/idl/velocity.json +1234 -1577
- package/src/idl/velocity.ts +1234 -1577
- package/src/index.ts +0 -2
- package/src/jupiter/jupiterClient.ts +30 -10
- package/src/marginCalculation.ts +1 -0
- package/src/math/amm.ts +188 -33
- package/src/math/bankruptcy.ts +1 -1
- package/src/math/funding.ts +7 -6
- package/src/math/insurance.ts +6 -8
- package/src/math/margin.ts +5 -112
- package/src/math/market.ts +6 -96
- package/src/math/oracles.ts +0 -17
- package/src/math/orders.ts +1 -110
- package/src/math/position.ts +4 -16
- package/src/math/repeg.ts +0 -29
- package/src/math/spotBalance.ts +14 -10
- package/src/math/spotMarket.ts +2 -28
- package/src/math/spotPosition.ts +4 -4
- package/src/math/state.ts +0 -8
- package/src/math/superStake.ts +19 -65
- package/src/math/trade.ts +2 -6
- package/src/memcmp.ts +0 -9
- package/src/oracles/prelaunchOracleClient.ts +7 -2
- package/src/oracles/pythClient.ts +12 -3
- package/src/oracles/pythLazerClient.ts +7 -2
- package/src/oracles/utils.ts +15 -0
- package/src/orderSubscriber/OrderSubscriber.ts +10 -4
- package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +45 -9
- package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
- package/src/pyth/types.ts +0 -2
- package/src/slot/SlotSubscriber.ts +3 -3
- package/src/slot/SlothashSubscriber.ts +17 -6
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
- package/src/swift/signedMsgUserAccountSubscriber.ts +16 -8
- package/src/swift/swiftOrderSubscriber.ts +10 -9
- package/src/testClient.ts +2 -2
- package/src/tokenFaucet.ts +22 -3
- package/src/tx/baseTxSender.ts +10 -10
- package/src/tx/fastSingleTxSender.ts +12 -8
- package/src/tx/reportTransactionError.ts +12 -7
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/txHandler.ts +88 -43
- package/src/tx/txParamProcessor.ts +18 -3
- package/src/tx/types.ts +1 -1
- package/src/tx/whileValidTxSender.ts +51 -22
- package/src/types.ts +39 -75
- package/src/user.ts +200 -152
- package/src/userMap/WebsocketSubscription.ts +1 -1
- package/src/userMap/grpcSubscription.ts +1 -1
- package/src/userMap/referrerMap.ts +13 -9
- package/src/userMap/revenueShareEscrowMap.ts +6 -1
- package/src/userMap/userMap.ts +43 -25
- package/src/userMap/userStatsMap.ts +32 -19
- package/src/userStats.ts +21 -8
- package/src/util/TransactionConfirmationManager.ts +10 -2
- package/src/util/chainClock.ts +1 -1
- package/src/util/computeUnits.ts +7 -3
- package/src/velocityClient.ts +536 -383
- package/tests/amm/test.ts +138 -0
- package/tests/dlob/helpers.ts +6 -1
- package/tsconfig.json +1 -0
- package/lib/browser/constants/insuranceFund.d.ts +0 -5
- package/lib/browser/constants/insuranceFund.js +0 -9
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +0 -37
- package/lib/browser/tx/forwardOnlyTxSender.js +0 -92
- package/lib/browser/util/tps.d.ts +0 -2
- package/lib/browser/util/tps.js +0 -16
- package/lib/node/constants/insuranceFund.d.ts +0 -6
- package/lib/node/constants/insuranceFund.d.ts.map +0 -1
- package/lib/node/constants/insuranceFund.js +0 -9
- package/lib/node/tx/forwardOnlyTxSender.d.ts +0 -38
- package/lib/node/tx/forwardOnlyTxSender.d.ts.map +0 -1
- package/lib/node/tx/forwardOnlyTxSender.js +0 -92
- package/lib/node/util/tps.d.ts +0 -3
- package/lib/node/util/tps.d.ts.map +0 -1
- package/lib/node/util/tps.js +0 -16
- package/src/constants/insuranceFund.ts +0 -8
- package/src/tx/forwardOnlyTxSender.ts +0 -145
- package/src/util/tps.ts +0 -27
package/src/index.ts
CHANGED
|
@@ -107,13 +107,11 @@ export * from './tx/fastSingleTxSender';
|
|
|
107
107
|
export * from './tx/retryTxSender';
|
|
108
108
|
export * from './tx/whileValidTxSender';
|
|
109
109
|
export * from './tx/priorityFeeCalculator';
|
|
110
|
-
export * from './tx/forwardOnlyTxSender';
|
|
111
110
|
export * from './tx/types';
|
|
112
111
|
export * from './tx/txHandler';
|
|
113
112
|
export * from './tx/txParamProcessor';
|
|
114
113
|
export * from './util/computeUnits';
|
|
115
114
|
export * from './util/digest';
|
|
116
|
-
export * from './util/tps';
|
|
117
115
|
export * from './util/promiseTimeout';
|
|
118
116
|
export * from './math/spotBalance';
|
|
119
117
|
export * from './velocityClientConfig';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
TransactionMessage,
|
|
7
7
|
VersionedTransaction,
|
|
8
8
|
} from '@solana/web3.js';
|
|
9
|
-
import fetch from 'node-fetch';
|
|
9
|
+
import fetch, { RequestInit } from 'node-fetch';
|
|
10
10
|
import { BN } from '../isomorphic/anchor';
|
|
11
11
|
import { SwapMode } from '../swap/UnifiedSwapClient';
|
|
12
12
|
|
|
@@ -302,6 +302,22 @@ export class JupiterClient {
|
|
|
302
302
|
maxAutoSlippageBps?: number;
|
|
303
303
|
usdEstimate?: number;
|
|
304
304
|
}): Promise<QuoteResponse> {
|
|
305
|
+
if (autoSlippage && maxAutoSlippageBps === undefined) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
'JupiterClient.getQuote: maxAutoSlippageBps is required when autoSlippage is enabled'
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (autoSlippage && usdEstimate === undefined) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
'JupiterClient.getQuote: usdEstimate is required when autoSlippage is enabled'
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
const maxAutoSlippageBpsParam =
|
|
316
|
+
autoSlippage && maxAutoSlippageBps !== undefined
|
|
317
|
+
? maxAutoSlippageBps.toString()
|
|
318
|
+
: '0';
|
|
319
|
+
const autoSlippageCollisionUsdValueParam =
|
|
320
|
+
autoSlippage && usdEstimate !== undefined ? usdEstimate.toString() : '0';
|
|
305
321
|
const params = new URLSearchParams({
|
|
306
322
|
inputMint: inputMint.toString(),
|
|
307
323
|
outputMint: outputMint.toString(),
|
|
@@ -311,10 +327,8 @@ export class JupiterClient {
|
|
|
311
327
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
312
328
|
maxAccounts: maxAccounts.toString(),
|
|
313
329
|
autoSlippage: autoSlippage.toString(),
|
|
314
|
-
maxAutoSlippageBps:
|
|
315
|
-
autoSlippageCollisionUsdValue:
|
|
316
|
-
? usdEstimate.toString()
|
|
317
|
-
: '0',
|
|
330
|
+
maxAutoSlippageBps: maxAutoSlippageBpsParam,
|
|
331
|
+
autoSlippageCollisionUsdValue: autoSlippageCollisionUsdValueParam,
|
|
318
332
|
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
319
333
|
});
|
|
320
334
|
if (swapMode === 'ExactOut') {
|
|
@@ -409,7 +423,9 @@ export class JupiterClient {
|
|
|
409
423
|
return await this.getLookupTable(lookup.accountKey);
|
|
410
424
|
})
|
|
411
425
|
)
|
|
412
|
-
).filter(
|
|
426
|
+
).filter(
|
|
427
|
+
(lookup): lookup is AddressLookupTableAccount => lookup !== undefined
|
|
428
|
+
);
|
|
413
429
|
|
|
414
430
|
const transactionMessage = TransactionMessage.decompile(message, {
|
|
415
431
|
addressLookupTableAccounts: lookupTables,
|
|
@@ -422,12 +438,16 @@ export class JupiterClient {
|
|
|
422
438
|
|
|
423
439
|
async getLookupTable(
|
|
424
440
|
accountKey: PublicKey
|
|
425
|
-
): Promise<AddressLookupTableAccount> {
|
|
426
|
-
|
|
427
|
-
|
|
441
|
+
): Promise<AddressLookupTableAccount | undefined> {
|
|
442
|
+
const cached = this.lookupTableCahce.get(accountKey.toString());
|
|
443
|
+
if (cached !== undefined) {
|
|
444
|
+
return cached;
|
|
428
445
|
}
|
|
429
446
|
|
|
430
|
-
return (
|
|
447
|
+
return (
|
|
448
|
+
(await this.connection.getAddressLookupTable(accountKey)).value ??
|
|
449
|
+
undefined
|
|
450
|
+
);
|
|
431
451
|
}
|
|
432
452
|
|
|
433
453
|
/**
|
package/src/marginCalculation.ts
CHANGED
package/src/math/amm.ts
CHANGED
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
ONE,
|
|
9
9
|
AMM_TO_QUOTE_PRECISION_RATIO,
|
|
10
10
|
QUOTE_PRECISION,
|
|
11
|
-
MARGIN_PRECISION,
|
|
12
11
|
PRICE_DIV_PEG,
|
|
13
12
|
PERCENTAGE_PRECISION,
|
|
14
13
|
DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT,
|
|
15
14
|
FUNDING_RATE_BUFFER_PRECISION,
|
|
15
|
+
FUNDING_RATE_OFFSET_PERCENTAGE,
|
|
16
16
|
TWO,
|
|
17
17
|
} from '../constants/numericConstants';
|
|
18
18
|
import {
|
|
@@ -53,7 +53,6 @@ export function calculatePegFromTargetPrice(
|
|
|
53
53
|
|
|
54
54
|
export function calculateOptimalPegAndBudget(
|
|
55
55
|
amm: AMM,
|
|
56
|
-
totalExchangeFee: BN,
|
|
57
56
|
mmOraclePriceData: MMOraclePriceData
|
|
58
57
|
): [BN, BN, BN, boolean] {
|
|
59
58
|
const reservePriceBefore = calculatePrice(
|
|
@@ -69,8 +68,9 @@ export function calculateOptimalPegAndBudget(
|
|
|
69
68
|
);
|
|
70
69
|
const prePegCost = calculateRepegCost(amm, newPeg);
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
// no protocol floor post-isolation: tfmd contains only the AMM's own
|
|
72
|
+
// equity and is fully spendable on the repeg
|
|
73
|
+
const budget = BN.max(ZERO, amm.totalFeeMinusDistributions);
|
|
74
74
|
|
|
75
75
|
let checkLowerBound = true;
|
|
76
76
|
if (budget.lt(prePegCost)) {
|
|
@@ -103,9 +103,9 @@ export function calculateOptimalPegAndBudget(
|
|
|
103
103
|
checkLowerBound = false;
|
|
104
104
|
|
|
105
105
|
return [newTargetPrice, newOptimalPeg, newBudget, false];
|
|
106
|
-
} else if (
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
} else if (budget.eq(ZERO)) {
|
|
107
|
+
// mirrors the program: budget = max(0, tfmd), so a zero budget
|
|
108
|
+
// means the AMM has no equity to spend (no floor post-isolation)
|
|
109
109
|
checkLowerBound = false;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -115,14 +115,13 @@ export function calculateOptimalPegAndBudget(
|
|
|
115
115
|
|
|
116
116
|
export function calculateNewAmm(
|
|
117
117
|
amm: AMM,
|
|
118
|
-
totalExchangeFee: BN,
|
|
119
118
|
mmOraclePriceData: MMOraclePriceData
|
|
120
119
|
): [BN, BN, BN, BN] {
|
|
121
120
|
let pKNumer = new BN(1);
|
|
122
121
|
let pKDenom = new BN(1);
|
|
123
122
|
|
|
124
123
|
const [targetPrice, _newPeg, budget, _checkLowerBound] =
|
|
125
|
-
calculateOptimalPegAndBudget(amm,
|
|
124
|
+
calculateOptimalPegAndBudget(amm, mmOraclePriceData);
|
|
126
125
|
let prePegCost = calculateRepegCost(amm, _newPeg);
|
|
127
126
|
let newPeg = _newPeg;
|
|
128
127
|
|
|
@@ -158,8 +157,7 @@ export function calculateNewAmm(
|
|
|
158
157
|
|
|
159
158
|
export function calculateUpdatedAMM(
|
|
160
159
|
amm: AMM,
|
|
161
|
-
|
|
162
|
-
mmOraclePriceData: MMOraclePriceData
|
|
160
|
+
mmOraclePriceData?: MMOraclePriceData
|
|
163
161
|
): AMM {
|
|
164
162
|
if (amm.curveUpdateIntensity == 0 || mmOraclePriceData === undefined) {
|
|
165
163
|
return amm;
|
|
@@ -167,7 +165,6 @@ export function calculateUpdatedAMM(
|
|
|
167
165
|
const newAmm = Object.assign({}, amm);
|
|
168
166
|
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(
|
|
169
167
|
amm,
|
|
170
|
-
totalExchangeFee,
|
|
171
168
|
mmOraclePriceData
|
|
172
169
|
);
|
|
173
170
|
|
|
@@ -201,12 +198,11 @@ export function calculateUpdatedAMM(
|
|
|
201
198
|
export function calculateUpdatedAMMSpreadReserves(
|
|
202
199
|
amm: AMM,
|
|
203
200
|
marketStats: MarketStats,
|
|
204
|
-
totalExchangeFee: BN,
|
|
205
201
|
direction: PositionDirection,
|
|
206
|
-
mmOraclePriceData
|
|
202
|
+
mmOraclePriceData?: MMOraclePriceData,
|
|
207
203
|
latestSlot?: BN
|
|
208
204
|
): { baseAssetReserve: BN; quoteAssetReserve: BN; sqrtK: BN; newPeg: BN } {
|
|
209
|
-
const newAmm = calculateUpdatedAMM(amm,
|
|
205
|
+
const newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
210
206
|
const [shortReserves, longReserves] = calculateSpreadReserves(
|
|
211
207
|
newAmm,
|
|
212
208
|
marketStats,
|
|
@@ -232,14 +228,13 @@ export function calculateUpdatedAMMSpreadReserves(
|
|
|
232
228
|
export function calculateBidAskPrice(
|
|
233
229
|
amm: AMM,
|
|
234
230
|
marketStats: MarketStats,
|
|
235
|
-
|
|
236
|
-
mmOraclePriceData: MMOraclePriceData,
|
|
231
|
+
mmOraclePriceData?: MMOraclePriceData,
|
|
237
232
|
withUpdate = true,
|
|
238
233
|
latestSlot?: BN
|
|
239
234
|
): [BN, BN] {
|
|
240
235
|
let newAmm: AMM;
|
|
241
236
|
if (withUpdate) {
|
|
242
|
-
newAmm = calculateUpdatedAMM(amm,
|
|
237
|
+
newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
243
238
|
} else {
|
|
244
239
|
newAmm = amm;
|
|
245
240
|
}
|
|
@@ -557,14 +552,6 @@ export function calculateEffectiveLeverage(
|
|
|
557
552
|
return effectiveLeverage;
|
|
558
553
|
}
|
|
559
554
|
|
|
560
|
-
export function calculateMaxSpread(marginRatioInitial: number): number {
|
|
561
|
-
const maxTargetSpread: number = new BN(marginRatioInitial)
|
|
562
|
-
.mul(BID_ASK_SPREAD_PRECISION.div(MARGIN_PRECISION))
|
|
563
|
-
.toNumber();
|
|
564
|
-
|
|
565
|
-
return maxTargetSpread;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
555
|
export function calculateVolSpreadBN(
|
|
569
556
|
lastOracleConfPct: BN,
|
|
570
557
|
reservePrice: BN,
|
|
@@ -614,6 +601,81 @@ export function calculateVolSpreadBN(
|
|
|
614
601
|
return [longVolSpread, shortVolSpread];
|
|
615
602
|
}
|
|
616
603
|
|
|
604
|
+
/**
|
|
605
|
+
* Funding bias β(f) (BID_ASK_SPREAD_PRECISION): bounded multiplier for the
|
|
606
|
+
* paying-side spread while the vAMM is paying funding. Mirrors the program's
|
|
607
|
+
* `calculate_spread_funding_bias_scale`.
|
|
608
|
+
*
|
|
609
|
+
* ρ(f) = clamp(|f| / f_ref, 0, 1), f_ref = FUNDING_RATE_OFFSET_PERCENTAGE
|
|
610
|
+
* β(f) = 1 + s * ρ(f), s = fundingBiasSensitivity / 100
|
|
611
|
+
*
|
|
612
|
+
* f = 24h avg funding rate normalized to a daily fraction of the oracle twap
|
|
613
|
+
* captured at the last funding update. The vAMM pays when f * q < 0
|
|
614
|
+
* (q = baseAssetAmountWithAmm). Returns 1x when the vAMM receives funding or
|
|
615
|
+
* s = 0.
|
|
616
|
+
*/
|
|
617
|
+
export function calculateSpreadFundingBiasScale(
|
|
618
|
+
baseAssetAmountWithAmm: BN,
|
|
619
|
+
last24HAvgFundingRate: BN,
|
|
620
|
+
lastFundingOracleTwap: BN,
|
|
621
|
+
fundingBiasSensitivity: number
|
|
622
|
+
): number {
|
|
623
|
+
const one = BID_ASK_SPREAD_PRECISION.toNumber();
|
|
624
|
+
if (fundingBiasSensitivity === 0 || lastFundingOracleTwap.lte(ZERO)) {
|
|
625
|
+
return one;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// f: daily funding rate as a fraction of price, FUNDING_RATE_PRECISION
|
|
629
|
+
const fNorm = last24HAvgFundingRate
|
|
630
|
+
.mul(PRICE_PRECISION)
|
|
631
|
+
.div(lastFundingOracleTwap)
|
|
632
|
+
.muln(24);
|
|
633
|
+
|
|
634
|
+
// f * q >= 0: vAMM receives (or rate/inventory is zero), β = 1
|
|
635
|
+
if (fNorm.isZero() || baseAssetAmountWithAmm.isZero()) {
|
|
636
|
+
return one;
|
|
637
|
+
}
|
|
638
|
+
if (fNorm.isNeg() === baseAssetAmountWithAmm.isNeg()) {
|
|
639
|
+
return one;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// ρ = clamp(|f| / f_ref, 0, 1), PERCENTAGE_PRECISION
|
|
643
|
+
const ramp = BN.min(
|
|
644
|
+
fNorm.abs().mul(PERCENTAGE_PRECISION).div(FUNDING_RATE_OFFSET_PERCENTAGE),
|
|
645
|
+
PERCENTAGE_PRECISION
|
|
646
|
+
).toNumber();
|
|
647
|
+
|
|
648
|
+
// β = 1 + s * ρ
|
|
649
|
+
return one + Math.floor((fundingBiasSensitivity * ramp) / 100);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export interface SpreadTerms {
|
|
653
|
+
longVolSpread: number;
|
|
654
|
+
shortVolSpread: number;
|
|
655
|
+
longSpreadwPS: number;
|
|
656
|
+
shortSpreadwPS: number;
|
|
657
|
+
maxTargetSpread: number;
|
|
658
|
+
inventorySpreadScale: number;
|
|
659
|
+
longSpreadwInvScale: number;
|
|
660
|
+
shortSpreadwInvScale: number;
|
|
661
|
+
effectiveLeverage: number;
|
|
662
|
+
effectiveLeverageCapped: number;
|
|
663
|
+
longSpreadwEL: number;
|
|
664
|
+
shortSpreadwEL: number;
|
|
665
|
+
revenueRetreatAmount: number;
|
|
666
|
+
halfRevenueRetreatAmount: number;
|
|
667
|
+
longSpreadwRevRetreat: number;
|
|
668
|
+
shortSpreadwRevRetreat: number;
|
|
669
|
+
fundingBiasScale: number;
|
|
670
|
+
longSpreadwFundingBias: number;
|
|
671
|
+
shortSpreadwFundingBias: number;
|
|
672
|
+
longSpreadwOffsetShrink: number;
|
|
673
|
+
shortSpreadwOffsetShrink: number;
|
|
674
|
+
totalSpread: number;
|
|
675
|
+
longSpread: number;
|
|
676
|
+
shortSpread: number;
|
|
677
|
+
}
|
|
678
|
+
|
|
617
679
|
export function calculateSpreadBN(
|
|
618
680
|
baseSpread: number,
|
|
619
681
|
lastOracleReservePriceSpreadPct: BN,
|
|
@@ -635,8 +697,63 @@ export function calculateSpreadBN(
|
|
|
635
697
|
shortIntensity: BN,
|
|
636
698
|
volume24H: BN,
|
|
637
699
|
ammInventorySpreadAdjustment: number,
|
|
700
|
+
last24HAvgFundingRate?: BN,
|
|
701
|
+
lastFundingOracleTwap?: BN,
|
|
702
|
+
fundingBiasSensitivity?: number,
|
|
703
|
+
returnTerms?: false
|
|
704
|
+
): [number, number];
|
|
705
|
+
export function calculateSpreadBN(
|
|
706
|
+
baseSpread: number,
|
|
707
|
+
lastOracleReservePriceSpreadPct: BN,
|
|
708
|
+
lastOracleConfPct: BN,
|
|
709
|
+
maxSpread: number,
|
|
710
|
+
quoteAssetReserve: BN,
|
|
711
|
+
terminalQuoteAssetReserve: BN,
|
|
712
|
+
pegMultiplier: BN,
|
|
713
|
+
baseAssetAmountWithAmm: BN,
|
|
714
|
+
reservePrice: BN,
|
|
715
|
+
totalFeeMinusDistributions: BN,
|
|
716
|
+
netRevenueSinceLastFunding: BN,
|
|
717
|
+
baseAssetReserve: BN,
|
|
718
|
+
minBaseAssetReserve: BN,
|
|
719
|
+
maxBaseAssetReserve: BN,
|
|
720
|
+
markStd: BN,
|
|
721
|
+
oracleStd: BN,
|
|
722
|
+
longIntensity: BN,
|
|
723
|
+
shortIntensity: BN,
|
|
724
|
+
volume24H: BN,
|
|
725
|
+
ammInventorySpreadAdjustment: number,
|
|
726
|
+
last24HAvgFundingRate: BN,
|
|
727
|
+
lastFundingOracleTwap: BN,
|
|
728
|
+
fundingBiasSensitivity: number,
|
|
729
|
+
returnTerms: true
|
|
730
|
+
): SpreadTerms;
|
|
731
|
+
export function calculateSpreadBN(
|
|
732
|
+
baseSpread: number,
|
|
733
|
+
lastOracleReservePriceSpreadPct: BN,
|
|
734
|
+
lastOracleConfPct: BN,
|
|
735
|
+
maxSpread: number,
|
|
736
|
+
quoteAssetReserve: BN,
|
|
737
|
+
terminalQuoteAssetReserve: BN,
|
|
738
|
+
pegMultiplier: BN,
|
|
739
|
+
baseAssetAmountWithAmm: BN,
|
|
740
|
+
reservePrice: BN,
|
|
741
|
+
totalFeeMinusDistributions: BN,
|
|
742
|
+
netRevenueSinceLastFunding: BN,
|
|
743
|
+
baseAssetReserve: BN,
|
|
744
|
+
minBaseAssetReserve: BN,
|
|
745
|
+
maxBaseAssetReserve: BN,
|
|
746
|
+
markStd: BN,
|
|
747
|
+
oracleStd: BN,
|
|
748
|
+
longIntensity: BN,
|
|
749
|
+
shortIntensity: BN,
|
|
750
|
+
volume24H: BN,
|
|
751
|
+
ammInventorySpreadAdjustment: number,
|
|
752
|
+
last24HAvgFundingRate: BN = ZERO,
|
|
753
|
+
lastFundingOracleTwap: BN = ZERO,
|
|
754
|
+
fundingBiasSensitivity = 0,
|
|
638
755
|
returnTerms = false
|
|
639
|
-
) {
|
|
756
|
+
): [number, number] | SpreadTerms {
|
|
640
757
|
assert(Number.isInteger(baseSpread));
|
|
641
758
|
assert(Number.isInteger(maxSpread));
|
|
642
759
|
|
|
@@ -657,6 +774,9 @@ export function calculateSpreadBN(
|
|
|
657
774
|
halfRevenueRetreatAmount: 0,
|
|
658
775
|
longSpreadwRevRetreat: 0,
|
|
659
776
|
shortSpreadwRevRetreat: 0,
|
|
777
|
+
fundingBiasScale: 0,
|
|
778
|
+
longSpreadwFundingBias: 0,
|
|
779
|
+
shortSpreadwFundingBias: 0,
|
|
660
780
|
longSpreadwOffsetShrink: 0,
|
|
661
781
|
shortSpreadwOffsetShrink: 0,
|
|
662
782
|
totalSpread: 0,
|
|
@@ -803,6 +923,32 @@ export function calculateSpreadBN(
|
|
|
803
923
|
spreadTerms.longSpreadwRevRetreat = longSpread;
|
|
804
924
|
spreadTerms.shortSpreadwRevRetreat = shortSpread;
|
|
805
925
|
|
|
926
|
+
// funding bias: w_pay = min(w_max, (w_0 * σ(q) * λ(q) + r(q)) * β(f)).
|
|
927
|
+
// β multiplies the fully built paying side only, selected by sign(q)
|
|
928
|
+
// (the same side σ widens); the max-spread cap below still bounds it.
|
|
929
|
+
// β = 1 when the vAMM receives.
|
|
930
|
+
const fundingBiasScale = calculateSpreadFundingBiasScale(
|
|
931
|
+
baseAssetAmountWithAmm,
|
|
932
|
+
last24HAvgFundingRate,
|
|
933
|
+
lastFundingOracleTwap,
|
|
934
|
+
fundingBiasSensitivity
|
|
935
|
+
);
|
|
936
|
+
const spreadPrecision = BID_ASK_SPREAD_PRECISION.toNumber();
|
|
937
|
+
if (fundingBiasScale > spreadPrecision) {
|
|
938
|
+
if (baseAssetAmountWithAmm.gt(ZERO)) {
|
|
939
|
+
longSpread = Math.floor(
|
|
940
|
+
(longSpread * fundingBiasScale) / spreadPrecision
|
|
941
|
+
);
|
|
942
|
+
} else if (baseAssetAmountWithAmm.lt(ZERO)) {
|
|
943
|
+
shortSpread = Math.floor(
|
|
944
|
+
(shortSpread * fundingBiasScale) / spreadPrecision
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
spreadTerms.fundingBiasScale = fundingBiasScale;
|
|
949
|
+
spreadTerms.longSpreadwFundingBias = longSpread;
|
|
950
|
+
spreadTerms.shortSpreadwFundingBias = shortSpread;
|
|
951
|
+
|
|
806
952
|
if (ammInventorySpreadAdjustment < 0) {
|
|
807
953
|
const adjustment = Math.abs(ammInventorySpreadAdjustment);
|
|
808
954
|
|
|
@@ -856,7 +1002,7 @@ export function calculateSpreadBN(
|
|
|
856
1002
|
export function calculateSpread(
|
|
857
1003
|
amm: AMM,
|
|
858
1004
|
marketStats: MarketStats,
|
|
859
|
-
oraclePriceData
|
|
1005
|
+
oraclePriceData?: OraclePriceData,
|
|
860
1006
|
now?: BN,
|
|
861
1007
|
reservePrice?: BN
|
|
862
1008
|
): [number, number] {
|
|
@@ -864,6 +1010,12 @@ export function calculateSpread(
|
|
|
864
1010
|
return [amm.baseSpread / 2, amm.baseSpread / 2];
|
|
865
1011
|
}
|
|
866
1012
|
|
|
1013
|
+
if (!oraclePriceData) {
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
'calculateSpread: oraclePriceData is required when baseSpread and curveUpdateIntensity are nonzero'
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
867
1019
|
if (!reservePrice) {
|
|
868
1020
|
reservePrice = calculatePrice(
|
|
869
1021
|
amm.baseAssetReserve,
|
|
@@ -911,7 +1063,10 @@ export function calculateSpread(
|
|
|
911
1063
|
marketStats.longIntensityVolume,
|
|
912
1064
|
marketStats.shortIntensityVolume,
|
|
913
1065
|
marketStats.volume24H,
|
|
914
|
-
amm.ammInventorySpreadAdjustment
|
|
1066
|
+
amm.ammInventorySpreadAdjustment,
|
|
1067
|
+
marketStats.last24HAvgFundingRate,
|
|
1068
|
+
marketStats.lastFundingOracleTwap,
|
|
1069
|
+
amm.fundingBiasSensitivity
|
|
915
1070
|
);
|
|
916
1071
|
let longSpread = spreads[0];
|
|
917
1072
|
let shortSpread = spreads[1];
|
|
@@ -942,7 +1097,7 @@ export function calculateSpread(
|
|
|
942
1097
|
export function calculateSpreadReserves(
|
|
943
1098
|
amm: AMM,
|
|
944
1099
|
marketStats: MarketStats,
|
|
945
|
-
mmOraclePriceData
|
|
1100
|
+
mmOraclePriceData?: MMOraclePriceData,
|
|
946
1101
|
now?: BN,
|
|
947
1102
|
latestSlot?: BN
|
|
948
1103
|
) {
|
|
@@ -951,8 +1106,8 @@ export function calculateSpreadReserves(
|
|
|
951
1106
|
direction: PositionDirection,
|
|
952
1107
|
amm: AMM
|
|
953
1108
|
): {
|
|
954
|
-
baseAssetReserve;
|
|
955
|
-
quoteAssetReserve;
|
|
1109
|
+
baseAssetReserve: BN;
|
|
1110
|
+
quoteAssetReserve: BN;
|
|
956
1111
|
} {
|
|
957
1112
|
if (spread === 0) {
|
|
958
1113
|
return {
|
|
@@ -1181,7 +1336,7 @@ export function calculateMaxBaseAssetAmountToTrade(
|
|
|
1181
1336
|
marketStats: MarketStats,
|
|
1182
1337
|
limit_price: BN,
|
|
1183
1338
|
direction: PositionDirection,
|
|
1184
|
-
mmOraclePriceData
|
|
1339
|
+
mmOraclePriceData: MMOraclePriceData,
|
|
1185
1340
|
now?: BN
|
|
1186
1341
|
): [BN, PositionDirection] {
|
|
1187
1342
|
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
package/src/math/bankruptcy.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { isVariant } from '../types';
|
|
|
4
4
|
import { User } from '../user';
|
|
5
5
|
|
|
6
6
|
export function isUserBankrupt(user: User): boolean {
|
|
7
|
-
const userAccount = user.
|
|
7
|
+
const userAccount = user.getUserAccountOrThrow();
|
|
8
8
|
let hasLiability = false;
|
|
9
9
|
for (const position of userAccount.spotPositions) {
|
|
10
10
|
if (position.scaledBalance.gt(ZERO)) {
|
package/src/math/funding.ts
CHANGED
|
@@ -41,7 +41,6 @@ function calculateLiveMarkTwap(
|
|
|
41
41
|
const [bid, ask] = calculateBidAskPrice(
|
|
42
42
|
market.amm,
|
|
43
43
|
market.marketStats,
|
|
44
|
-
market.totalExchangeFee,
|
|
45
44
|
mmOraclePriceData
|
|
46
45
|
);
|
|
47
46
|
markPrice = bid.add(ask).div(new BN(2));
|
|
@@ -156,6 +155,11 @@ export function calculateAllEstimatedFundingRate(
|
|
|
156
155
|
now,
|
|
157
156
|
market.marketStats.fundingPeriod
|
|
158
157
|
);
|
|
158
|
+
if (!oraclePriceData) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
'calculateAllEstimatedFundingRate: oraclePriceData is required for an initialized market'
|
|
161
|
+
);
|
|
162
|
+
}
|
|
159
163
|
const liveOracleTwap = calculateLiveOracleTwap(
|
|
160
164
|
market.marketStats.historicalOracleData,
|
|
161
165
|
oraclePriceData,
|
|
@@ -427,13 +431,10 @@ export function calculateLongShortFundingRateAndLiveTwaps(
|
|
|
427
431
|
*/
|
|
428
432
|
export function calculateFundingPool(market: PerpMarketAccount): BN {
|
|
429
433
|
// todo
|
|
430
|
-
|
|
434
|
+
// no protocol floor post-isolation: 1/3 of the AMM's own equity
|
|
431
435
|
const feePool = BN.max(
|
|
432
436
|
ZERO,
|
|
433
|
-
market.amm.totalFeeMinusDistributions
|
|
434
|
-
.sub(totalFeeLB)
|
|
435
|
-
.mul(new BN(1))
|
|
436
|
-
.div(new BN(3))
|
|
437
|
+
market.amm.totalFeeMinusDistributions.mul(new BN(1)).div(new BN(3))
|
|
437
438
|
);
|
|
438
439
|
return feePool;
|
|
439
440
|
}
|
package/src/math/insurance.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { SpotBalanceType, SpotMarketAccount } from '../types';
|
|
|
6
6
|
export function nextRevenuePoolSettleApr(
|
|
7
7
|
spotMarket: SpotMarketAccount,
|
|
8
8
|
vaultBalance: BN, // vault token amount
|
|
9
|
-
amount
|
|
9
|
+
amount: BN // delta token amount
|
|
10
10
|
): number {
|
|
11
11
|
const MAX_APR = new BN(10).mul(PERCENTAGE_PRECISION); // 1000% APR
|
|
12
12
|
|
|
@@ -18,13 +18,11 @@ export function nextRevenuePoolSettleApr(
|
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
const payoutRatio = 0.1;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
spotMarket.insuranceFund.totalFactor
|
|
27
|
-
: 0;
|
|
21
|
+
// the insurance fund is 100% staker-owned: every settled token accrues to
|
|
22
|
+
// stakers as share-price appreciation (no protocol split)
|
|
23
|
+
const ratioForStakers = spotMarket.insuranceFund.revenueSettlePeriod.gt(ZERO)
|
|
24
|
+
? 1
|
|
25
|
+
: 0;
|
|
28
26
|
|
|
29
27
|
// Settle periods from on-chain data:
|
|
30
28
|
const revSettlePeriod =
|
package/src/math/margin.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
SPOT_MARKET_WEIGHT_PRECISION,
|
|
9
9
|
SPOT_MARKET_IMF_PRECISION,
|
|
10
10
|
ZERO,
|
|
11
|
-
BID_ASK_SPREAD_PRECISION,
|
|
12
11
|
AMM_RESERVE_PRECISION,
|
|
13
12
|
BASE_PRECISION,
|
|
14
13
|
MARGIN_PRECISION,
|
|
@@ -20,15 +19,7 @@ import { OraclePriceData } from '../oracles/types';
|
|
|
20
19
|
import { calculateMarketMarginRatio } from './market';
|
|
21
20
|
import { calculateScaledInitialAssetWeight } from './spotBalance';
|
|
22
21
|
import { VelocityClient } from '../velocityClient';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
PerpMarketAccount,
|
|
26
|
-
PerpPosition,
|
|
27
|
-
PositionDirection,
|
|
28
|
-
UserAccount,
|
|
29
|
-
} from '../types';
|
|
30
|
-
import { PublicKey } from '@solana/web3.js';
|
|
31
|
-
import { User } from '../user';
|
|
22
|
+
import { PerpMarketAccount, PerpPosition } from '../types';
|
|
32
23
|
import { isVariant } from '../types';
|
|
33
24
|
import { assert } from '../assert/assert';
|
|
34
25
|
|
|
@@ -97,32 +88,6 @@ export function calculateSizeDiscountAssetWeight(
|
|
|
97
88
|
return minAssetWeight;
|
|
98
89
|
}
|
|
99
90
|
|
|
100
|
-
export function calculateOraclePriceForPerpMargin(
|
|
101
|
-
perpPosition: PerpPosition,
|
|
102
|
-
market: PerpMarketAccount,
|
|
103
|
-
oraclePriceData: OraclePriceData
|
|
104
|
-
): BN {
|
|
105
|
-
const oraclePriceOffset = BN.min(
|
|
106
|
-
new BN(market.amm.maxSpread)
|
|
107
|
-
.mul(oraclePriceData.price)
|
|
108
|
-
.div(BID_ASK_SPREAD_PRECISION),
|
|
109
|
-
oraclePriceData.confidence.add(
|
|
110
|
-
new BN(market.amm.baseSpread)
|
|
111
|
-
.mul(oraclePriceData.price)
|
|
112
|
-
.div(BID_ASK_SPREAD_PRECISION)
|
|
113
|
-
)
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
let marginPrice: BN;
|
|
117
|
-
if (perpPosition.baseAssetAmount.gt(ZERO)) {
|
|
118
|
-
marginPrice = oraclePriceData.price.sub(oraclePriceOffset);
|
|
119
|
-
} else {
|
|
120
|
-
marginPrice = oraclePriceData.price.add(oraclePriceOffset);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return marginPrice;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
91
|
/**
|
|
127
92
|
* This is _not_ the same as liability value as for prediction markets, the liability for the short in prediction market is (1 - oracle price) * base
|
|
128
93
|
* See {@link calculatePerpLiabilityValue} to get the liabiltiy value
|
|
@@ -226,7 +191,8 @@ export function calculateMarginUSDCRequiredForTrade(
|
|
|
226
191
|
userMaxMarginRatio?: number,
|
|
227
192
|
entryPrice?: BN
|
|
228
193
|
): BN {
|
|
229
|
-
const targetMarket =
|
|
194
|
+
const targetMarket =
|
|
195
|
+
velocityClient.getPerpMarketAccountOrThrow(targetMarketIndex);
|
|
230
196
|
|
|
231
197
|
const price =
|
|
232
198
|
entryPrice ??
|
|
@@ -269,7 +235,8 @@ export function calculateCollateralDepositRequiredForTrade(
|
|
|
269
235
|
estEntryPrice
|
|
270
236
|
);
|
|
271
237
|
|
|
272
|
-
const collateralMarket =
|
|
238
|
+
const collateralMarket =
|
|
239
|
+
velocityClient.getSpotMarketAccountOrThrow(collateralIndex);
|
|
273
240
|
|
|
274
241
|
const collateralOracleData =
|
|
275
242
|
velocityClient.getOracleDataForSpotMarket(collateralIndex);
|
|
@@ -292,77 +259,3 @@ export function calculateCollateralDepositRequiredForTrade(
|
|
|
292
259
|
|
|
293
260
|
return baseAmountRequired;
|
|
294
261
|
}
|
|
295
|
-
|
|
296
|
-
export function calculateCollateralValueOfDeposit(
|
|
297
|
-
velocityClient: VelocityClient,
|
|
298
|
-
collateralIndex: number,
|
|
299
|
-
baseSize: BN
|
|
300
|
-
): BN {
|
|
301
|
-
const collateralMarket = velocityClient.getSpotMarketAccount(collateralIndex);
|
|
302
|
-
|
|
303
|
-
const collateralOracleData =
|
|
304
|
-
velocityClient.getOracleDataForSpotMarket(collateralIndex);
|
|
305
|
-
|
|
306
|
-
const scaledAssetWeight = calculateScaledInitialAssetWeight(
|
|
307
|
-
collateralMarket,
|
|
308
|
-
collateralOracleData.price
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
// CollateralBaseValue = oracle price * collateral base amount (and shift to QUOTE_PRECISION)
|
|
312
|
-
const collateralBaseValue = collateralOracleData.price
|
|
313
|
-
.mul(baseSize)
|
|
314
|
-
.mul(QUOTE_PRECISION)
|
|
315
|
-
.div(PRICE_PRECISION)
|
|
316
|
-
.div(new BN(10).pow(new BN(collateralMarket.decimals)));
|
|
317
|
-
|
|
318
|
-
const depositCollateralValue = collateralBaseValue
|
|
319
|
-
.mul(scaledAssetWeight)
|
|
320
|
-
.div(SPOT_MARKET_WEIGHT_PRECISION);
|
|
321
|
-
|
|
322
|
-
return depositCollateralValue;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function calculateLiquidationPrice(
|
|
326
|
-
freeCollateral: BN,
|
|
327
|
-
freeCollateralDelta: BN,
|
|
328
|
-
oraclePrice: BN
|
|
329
|
-
): BN {
|
|
330
|
-
const liqPriceDelta = freeCollateral
|
|
331
|
-
.mul(QUOTE_PRECISION)
|
|
332
|
-
.div(freeCollateralDelta);
|
|
333
|
-
|
|
334
|
-
const liqPrice = oraclePrice.sub(liqPriceDelta);
|
|
335
|
-
|
|
336
|
-
if (liqPrice.lt(ZERO)) {
|
|
337
|
-
return new BN(-1);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
return liqPrice;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export function calculateUserMaxPerpOrderSize(
|
|
344
|
-
velocityClient: VelocityClient,
|
|
345
|
-
userAccountKey: PublicKey,
|
|
346
|
-
userAccount: UserAccount,
|
|
347
|
-
targetMarketIndex: number,
|
|
348
|
-
tradeSide: PositionDirection
|
|
349
|
-
): { tradeSize: BN; oppositeSideTradeSize: BN } {
|
|
350
|
-
const userAccountSubscriber = new OneShotUserAccountSubscriber(
|
|
351
|
-
velocityClient.program,
|
|
352
|
-
userAccountKey,
|
|
353
|
-
userAccount
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
const user = new User({
|
|
357
|
-
velocityClient,
|
|
358
|
-
userAccountPublicKey: userAccountKey,
|
|
359
|
-
accountSubscription: {
|
|
360
|
-
type: 'custom',
|
|
361
|
-
userAccountSubscriber: userAccountSubscriber,
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
user.isSubscribed = true;
|
|
366
|
-
|
|
367
|
-
return user.getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide);
|
|
368
|
-
}
|