@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/lib/browser/index.d.ts
CHANGED
|
@@ -105,13 +105,11 @@ export * from './tx/fastSingleTxSender';
|
|
|
105
105
|
export * from './tx/retryTxSender';
|
|
106
106
|
export * from './tx/whileValidTxSender';
|
|
107
107
|
export * from './tx/priorityFeeCalculator';
|
|
108
|
-
export * from './tx/forwardOnlyTxSender';
|
|
109
108
|
export * from './tx/types';
|
|
110
109
|
export * from './tx/txHandler';
|
|
111
110
|
export * from './tx/txParamProcessor';
|
|
112
111
|
export * from './util/computeUnits';
|
|
113
112
|
export * from './util/digest';
|
|
114
|
-
export * from './util/tps';
|
|
115
113
|
export * from './util/promiseTimeout';
|
|
116
114
|
export * from './math/spotBalance';
|
|
117
115
|
export * from './velocityClientConfig';
|
package/lib/browser/index.js
CHANGED
|
@@ -136,13 +136,11 @@ __exportStar(require("./tx/fastSingleTxSender"), exports);
|
|
|
136
136
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
137
137
|
__exportStar(require("./tx/whileValidTxSender"), exports);
|
|
138
138
|
__exportStar(require("./tx/priorityFeeCalculator"), exports);
|
|
139
|
-
__exportStar(require("./tx/forwardOnlyTxSender"), exports);
|
|
140
139
|
__exportStar(require("./tx/types"), exports);
|
|
141
140
|
__exportStar(require("./tx/txHandler"), exports);
|
|
142
141
|
__exportStar(require("./tx/txParamProcessor"), exports);
|
|
143
142
|
__exportStar(require("./util/computeUnits"), exports);
|
|
144
143
|
__exportStar(require("./util/digest"), exports);
|
|
145
|
-
__exportStar(require("./util/tps"), exports);
|
|
146
144
|
__exportStar(require("./util/promiseTimeout"), exports);
|
|
147
145
|
__exportStar(require("./math/spotBalance"), exports);
|
|
148
146
|
__exportStar(require("./velocityClientConfig"), exports);
|
|
@@ -276,7 +276,7 @@ export declare class JupiterClient {
|
|
|
276
276
|
transactionMessage: TransactionMessage;
|
|
277
277
|
lookupTables: AddressLookupTableAccount[];
|
|
278
278
|
}>;
|
|
279
|
-
getLookupTable(accountKey: PublicKey): Promise<AddressLookupTableAccount>;
|
|
279
|
+
getLookupTable(accountKey: PublicKey): Promise<AddressLookupTableAccount | undefined>;
|
|
280
280
|
/**
|
|
281
281
|
* Get the jupiter instructions from transaction by filtering out instructions to compute budget and associated token programs
|
|
282
282
|
* @param transactionMessage the transaction message
|
|
@@ -47,6 +47,16 @@ class JupiterClient {
|
|
|
47
47
|
*/
|
|
48
48
|
async getQuote({ inputMint, outputMint, amount, maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
49
49
|
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, excludeDexes, autoSlippage = false, maxAutoSlippageBps, usdEstimate, }) {
|
|
50
|
+
if (autoSlippage && maxAutoSlippageBps === undefined) {
|
|
51
|
+
throw new Error('JupiterClient.getQuote: maxAutoSlippageBps is required when autoSlippage is enabled');
|
|
52
|
+
}
|
|
53
|
+
if (autoSlippage && usdEstimate === undefined) {
|
|
54
|
+
throw new Error('JupiterClient.getQuote: usdEstimate is required when autoSlippage is enabled');
|
|
55
|
+
}
|
|
56
|
+
const maxAutoSlippageBpsParam = autoSlippage && maxAutoSlippageBps !== undefined
|
|
57
|
+
? maxAutoSlippageBps.toString()
|
|
58
|
+
: '0';
|
|
59
|
+
const autoSlippageCollisionUsdValueParam = autoSlippage && usdEstimate !== undefined ? usdEstimate.toString() : '0';
|
|
50
60
|
const params = new URLSearchParams({
|
|
51
61
|
inputMint: inputMint.toString(),
|
|
52
62
|
outputMint: outputMint.toString(),
|
|
@@ -56,10 +66,8 @@ class JupiterClient {
|
|
|
56
66
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
57
67
|
maxAccounts: maxAccounts.toString(),
|
|
58
68
|
autoSlippage: autoSlippage.toString(),
|
|
59
|
-
maxAutoSlippageBps:
|
|
60
|
-
autoSlippageCollisionUsdValue:
|
|
61
|
-
? usdEstimate.toString()
|
|
62
|
-
: '0',
|
|
69
|
+
maxAutoSlippageBps: maxAutoSlippageBpsParam,
|
|
70
|
+
autoSlippageCollisionUsdValue: autoSlippageCollisionUsdValueParam,
|
|
63
71
|
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
64
72
|
});
|
|
65
73
|
if (swapMode === 'ExactOut') {
|
|
@@ -116,7 +124,7 @@ class JupiterClient {
|
|
|
116
124
|
const message = transaction.message;
|
|
117
125
|
const lookupTables = (await Promise.all(message.addressTableLookups.map(async (lookup) => {
|
|
118
126
|
return await this.getLookupTable(lookup.accountKey);
|
|
119
|
-
}))).filter((lookup) => lookup);
|
|
127
|
+
}))).filter((lookup) => lookup !== undefined);
|
|
120
128
|
const transactionMessage = web3_js_1.TransactionMessage.decompile(message, {
|
|
121
129
|
addressLookupTableAccounts: lookupTables,
|
|
122
130
|
});
|
|
@@ -126,10 +134,12 @@ class JupiterClient {
|
|
|
126
134
|
};
|
|
127
135
|
}
|
|
128
136
|
async getLookupTable(accountKey) {
|
|
129
|
-
|
|
130
|
-
|
|
137
|
+
var _a;
|
|
138
|
+
const cached = this.lookupTableCahce.get(accountKey.toString());
|
|
139
|
+
if (cached !== undefined) {
|
|
140
|
+
return cached;
|
|
131
141
|
}
|
|
132
|
-
return (await this.connection.getAddressLookupTable(accountKey)).value;
|
|
142
|
+
return ((_a = (await this.connection.getAddressLookupTable(accountKey)).value) !== null && _a !== void 0 ? _a : undefined);
|
|
133
143
|
}
|
|
134
144
|
/**
|
|
135
145
|
* Get the jupiter instructions from transaction by filtering out instructions to compute budget and associated token programs
|
|
@@ -28,6 +28,7 @@ class MarginContext {
|
|
|
28
28
|
this.strict = false;
|
|
29
29
|
this.ignoreInvalidDepositOracles = false;
|
|
30
30
|
this.isolatedMarginBuffers = new Map();
|
|
31
|
+
this.crossMarginBuffer = numericConstants_1.ZERO;
|
|
31
32
|
}
|
|
32
33
|
static standard(marginType) {
|
|
33
34
|
return new MarginContext(marginType);
|
|
@@ -3,16 +3,16 @@ import { BN } from '../isomorphic/anchor';
|
|
|
3
3
|
import { AMM, MarketStats, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
4
4
|
import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
|
|
5
5
|
export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
|
|
6
|
-
export declare function calculateOptimalPegAndBudget(amm: AMM,
|
|
7
|
-
export declare function calculateNewAmm(amm: AMM,
|
|
8
|
-
export declare function calculateUpdatedAMM(amm: AMM,
|
|
9
|
-
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, marketStats: MarketStats,
|
|
6
|
+
export declare function calculateOptimalPegAndBudget(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, boolean];
|
|
7
|
+
export declare function calculateNewAmm(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, BN];
|
|
8
|
+
export declare function calculateUpdatedAMM(amm: AMM, mmOraclePriceData?: MMOraclePriceData): AMM;
|
|
9
|
+
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, marketStats: MarketStats, direction: PositionDirection, mmOraclePriceData?: MMOraclePriceData, latestSlot?: BN): {
|
|
10
10
|
baseAssetReserve: BN;
|
|
11
11
|
quoteAssetReserve: BN;
|
|
12
12
|
sqrtK: BN;
|
|
13
13
|
newPeg: BN;
|
|
14
14
|
};
|
|
15
|
-
export declare function calculateBidAskPrice(amm: AMM, marketStats: MarketStats,
|
|
15
|
+
export declare function calculateBidAskPrice(amm: AMM, marketStats: MarketStats, mmOraclePriceData?: MMOraclePriceData, withUpdate?: boolean, latestSlot?: BN): [BN, BN];
|
|
16
16
|
/**
|
|
17
17
|
* Calculates a price given an arbitrary base and quote amount (they must have the same precision)
|
|
18
18
|
*
|
|
@@ -39,9 +39,22 @@ export declare function calculateInventoryLiquidityRatioForReferencePriceOffset(
|
|
|
39
39
|
export declare function calculateInventoryScale(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, directionalSpread: number, maxSpread: number): number;
|
|
40
40
|
export declare function calculateReferencePriceOffset(reservePrice: BN, last24hAvgFundingRate: BN, liquidityFraction: BN, oracleTwapFast: BN, markTwapFast: BN, oracleTwapSlow: BN, markTwapSlow: BN, maxOffsetPct: number): BN;
|
|
41
41
|
export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, reservePrice: BN, totalFeeMinusDistributions: BN): number;
|
|
42
|
-
export declare function calculateMaxSpread(marginRatioInitial: number): number;
|
|
43
42
|
export declare function calculateVolSpreadBN(lastOracleConfPct: BN, reservePrice: BN, markStd: BN, oracleStd: BN, longIntensity: BN, shortIntensity: BN, volume24H: BN): [BN, BN];
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Funding bias β(f) (BID_ASK_SPREAD_PRECISION): bounded multiplier for the
|
|
45
|
+
* paying-side spread while the vAMM is paying funding. Mirrors the program's
|
|
46
|
+
* `calculate_spread_funding_bias_scale`.
|
|
47
|
+
*
|
|
48
|
+
* ρ(f) = clamp(|f| / f_ref, 0, 1), f_ref = FUNDING_RATE_OFFSET_PERCENTAGE
|
|
49
|
+
* β(f) = 1 + s * ρ(f), s = fundingBiasSensitivity / 100
|
|
50
|
+
*
|
|
51
|
+
* f = 24h avg funding rate normalized to a daily fraction of the oracle twap
|
|
52
|
+
* captured at the last funding update. The vAMM pays when f * q < 0
|
|
53
|
+
* (q = baseAssetAmountWithAmm). Returns 1x when the vAMM receives funding or
|
|
54
|
+
* s = 0.
|
|
55
|
+
*/
|
|
56
|
+
export declare function calculateSpreadFundingBiasScale(baseAssetAmountWithAmm: BN, last24HAvgFundingRate: BN, lastFundingOracleTwap: BN, fundingBiasSensitivity: number): number;
|
|
57
|
+
export interface SpreadTerms {
|
|
45
58
|
longVolSpread: number;
|
|
46
59
|
shortVolSpread: number;
|
|
47
60
|
longSpreadwPS: number;
|
|
@@ -58,16 +71,21 @@ export declare function calculateSpreadBN(baseSpread: number, lastOracleReserveP
|
|
|
58
71
|
halfRevenueRetreatAmount: number;
|
|
59
72
|
longSpreadwRevRetreat: number;
|
|
60
73
|
shortSpreadwRevRetreat: number;
|
|
74
|
+
fundingBiasScale: number;
|
|
75
|
+
longSpreadwFundingBias: number;
|
|
76
|
+
shortSpreadwFundingBias: number;
|
|
61
77
|
longSpreadwOffsetShrink: number;
|
|
62
78
|
shortSpreadwOffsetShrink: number;
|
|
63
79
|
totalSpread: number;
|
|
64
80
|
longSpread: number;
|
|
65
81
|
shortSpread: number;
|
|
66
|
-
}
|
|
67
|
-
export declare function
|
|
68
|
-
export declare function
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
}
|
|
83
|
+
export declare function calculateSpreadBN(baseSpread: number, lastOracleReservePriceSpreadPct: BN, lastOracleConfPct: BN, maxSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, baseAssetAmountWithAmm: BN, reservePrice: BN, totalFeeMinusDistributions: BN, netRevenueSinceLastFunding: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, markStd: BN, oracleStd: BN, longIntensity: BN, shortIntensity: BN, volume24H: BN, ammInventorySpreadAdjustment: number, last24HAvgFundingRate?: BN, lastFundingOracleTwap?: BN, fundingBiasSensitivity?: number, returnTerms?: false): [number, number];
|
|
84
|
+
export declare function calculateSpreadBN(baseSpread: number, lastOracleReservePriceSpreadPct: BN, lastOracleConfPct: BN, maxSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, baseAssetAmountWithAmm: BN, reservePrice: BN, totalFeeMinusDistributions: BN, netRevenueSinceLastFunding: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, markStd: BN, oracleStd: BN, longIntensity: BN, shortIntensity: BN, volume24H: BN, ammInventorySpreadAdjustment: number, last24HAvgFundingRate: BN, lastFundingOracleTwap: BN, fundingBiasSensitivity: number, returnTerms: true): SpreadTerms;
|
|
85
|
+
export declare function calculateSpread(amm: AMM, marketStats: MarketStats, oraclePriceData?: OraclePriceData, now?: BN, reservePrice?: BN): [number, number];
|
|
86
|
+
export declare function calculateSpreadReserves(amm: AMM, marketStats: MarketStats, mmOraclePriceData?: MMOraclePriceData, now?: BN, latestSlot?: BN): {
|
|
87
|
+
baseAssetReserve: BN;
|
|
88
|
+
quoteAssetReserve: BN;
|
|
71
89
|
}[];
|
|
72
90
|
/**
|
|
73
91
|
* Helper function calculating constant product curve output. Agnostic to whether input asset is quote or base
|
|
@@ -93,6 +111,6 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
93
111
|
* @returns cost : Precision PRICE_PRECISION
|
|
94
112
|
*/
|
|
95
113
|
export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
|
|
96
|
-
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, marketStats: MarketStats, limit_price: BN, direction: PositionDirection, mmOraclePriceData
|
|
114
|
+
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, marketStats: MarketStats, limit_price: BN, direction: PositionDirection, mmOraclePriceData: MMOraclePriceData, now?: BN): [BN, PositionDirection];
|
|
97
115
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|
|
98
116
|
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderStepSize: BN, orderDirection: PositionDirection): BN;
|
package/lib/browser/math/amm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateSpread = exports.calculateSpreadBN = exports.
|
|
3
|
+
exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateSpreadFundingBiasScale = exports.calculateVolSpreadBN = exports.calculateEffectiveLeverage = exports.calculateReferencePriceOffset = exports.calculateInventoryScale = exports.calculateInventoryLiquidityRatioForReferencePriceOffset = exports.calculateInventoryLiquidityRatio = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
|
|
4
4
|
const anchor_1 = require("../isomorphic/anchor");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const types_1 = require("../types");
|
|
@@ -17,13 +17,14 @@ function calculatePegFromTargetPrice(targetPrice, baseAssetReserve, quoteAssetRe
|
|
|
17
17
|
.div(numericConstants_1.PRICE_DIV_PEG), numericConstants_1.ONE);
|
|
18
18
|
}
|
|
19
19
|
exports.calculatePegFromTargetPrice = calculatePegFromTargetPrice;
|
|
20
|
-
function calculateOptimalPegAndBudget(amm,
|
|
20
|
+
function calculateOptimalPegAndBudget(amm, mmOraclePriceData) {
|
|
21
21
|
const reservePriceBefore = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
22
22
|
const targetPrice = mmOraclePriceData.price;
|
|
23
23
|
const newPeg = calculatePegFromTargetPrice(targetPrice, amm.baseAssetReserve, amm.quoteAssetReserve);
|
|
24
24
|
const prePegCost = (0, repeg_1.calculateRepegCost)(amm, newPeg);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// no protocol floor post-isolation: tfmd contains only the AMM's own
|
|
26
|
+
// equity and is fully spendable on the repeg
|
|
27
|
+
const budget = anchor_1.BN.max(numericConstants_1.ZERO, amm.totalFeeMinusDistributions);
|
|
27
28
|
let checkLowerBound = true;
|
|
28
29
|
if (budget.lt(prePegCost)) {
|
|
29
30
|
const halfMaxPriceSpread = new anchor_1.BN(amm.maxSpread)
|
|
@@ -47,17 +48,19 @@ function calculateOptimalPegAndBudget(amm, totalExchangeFee, mmOraclePriceData)
|
|
|
47
48
|
checkLowerBound = false;
|
|
48
49
|
return [newTargetPrice, newOptimalPeg, newBudget, false];
|
|
49
50
|
}
|
|
50
|
-
else if (
|
|
51
|
+
else if (budget.eq(numericConstants_1.ZERO)) {
|
|
52
|
+
// mirrors the program: budget = max(0, tfmd), so a zero budget
|
|
53
|
+
// means the AMM has no equity to spend (no floor post-isolation)
|
|
51
54
|
checkLowerBound = false;
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
return [targetPrice, newPeg, budget, checkLowerBound];
|
|
55
58
|
}
|
|
56
59
|
exports.calculateOptimalPegAndBudget = calculateOptimalPegAndBudget;
|
|
57
|
-
function calculateNewAmm(amm,
|
|
60
|
+
function calculateNewAmm(amm, mmOraclePriceData) {
|
|
58
61
|
let pKNumer = new anchor_1.BN(1);
|
|
59
62
|
let pKDenom = new anchor_1.BN(1);
|
|
60
|
-
const [targetPrice, _newPeg, budget, _checkLowerBound] = calculateOptimalPegAndBudget(amm,
|
|
63
|
+
const [targetPrice, _newPeg, budget, _checkLowerBound] = calculateOptimalPegAndBudget(amm, mmOraclePriceData);
|
|
61
64
|
let prePegCost = (0, repeg_1.calculateRepegCost)(amm, _newPeg);
|
|
62
65
|
let newPeg = _newPeg;
|
|
63
66
|
if (prePegCost.gte(budget) && prePegCost.gt(numericConstants_1.ZERO)) {
|
|
@@ -81,12 +84,12 @@ function calculateNewAmm(amm, totalExchangeFee, mmOraclePriceData) {
|
|
|
81
84
|
return [prePegCost, pKNumer, pKDenom, newPeg];
|
|
82
85
|
}
|
|
83
86
|
exports.calculateNewAmm = calculateNewAmm;
|
|
84
|
-
function calculateUpdatedAMM(amm,
|
|
87
|
+
function calculateUpdatedAMM(amm, mmOraclePriceData) {
|
|
85
88
|
if (amm.curveUpdateIntensity == 0 || mmOraclePriceData === undefined) {
|
|
86
89
|
return amm;
|
|
87
90
|
}
|
|
88
91
|
const newAmm = Object.assign({}, amm);
|
|
89
|
-
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(amm,
|
|
92
|
+
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(amm, mmOraclePriceData);
|
|
90
93
|
newAmm.baseAssetReserve = newAmm.baseAssetReserve.mul(pKNumer).div(pKDenom);
|
|
91
94
|
newAmm.sqrtK = newAmm.sqrtK.mul(pKNumer).div(pKDenom);
|
|
92
95
|
const invariant = newAmm.sqrtK.mul(newAmm.sqrtK);
|
|
@@ -104,8 +107,8 @@ function calculateUpdatedAMM(amm, totalExchangeFee, mmOraclePriceData) {
|
|
|
104
107
|
return newAmm;
|
|
105
108
|
}
|
|
106
109
|
exports.calculateUpdatedAMM = calculateUpdatedAMM;
|
|
107
|
-
function calculateUpdatedAMMSpreadReserves(amm, marketStats,
|
|
108
|
-
const newAmm = calculateUpdatedAMM(amm,
|
|
110
|
+
function calculateUpdatedAMMSpreadReserves(amm, marketStats, direction, mmOraclePriceData, latestSlot) {
|
|
111
|
+
const newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
109
112
|
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, marketStats, mmOraclePriceData, undefined, latestSlot);
|
|
110
113
|
const dirReserves = (0, types_1.isVariant)(direction, 'long')
|
|
111
114
|
? longReserves
|
|
@@ -119,10 +122,10 @@ function calculateUpdatedAMMSpreadReserves(amm, marketStats, totalExchangeFee, d
|
|
|
119
122
|
return result;
|
|
120
123
|
}
|
|
121
124
|
exports.calculateUpdatedAMMSpreadReserves = calculateUpdatedAMMSpreadReserves;
|
|
122
|
-
function calculateBidAskPrice(amm, marketStats,
|
|
125
|
+
function calculateBidAskPrice(amm, marketStats, mmOraclePriceData, withUpdate = true, latestSlot) {
|
|
123
126
|
let newAmm;
|
|
124
127
|
if (withUpdate) {
|
|
125
|
-
newAmm = calculateUpdatedAMM(amm,
|
|
128
|
+
newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
126
129
|
}
|
|
127
130
|
else {
|
|
128
131
|
newAmm = amm;
|
|
@@ -281,13 +284,6 @@ function calculateEffectiveLeverage(baseSpread, quoteAssetReserve, terminalQuote
|
|
|
281
284
|
return effectiveLeverage;
|
|
282
285
|
}
|
|
283
286
|
exports.calculateEffectiveLeverage = calculateEffectiveLeverage;
|
|
284
|
-
function calculateMaxSpread(marginRatioInitial) {
|
|
285
|
-
const maxTargetSpread = new anchor_1.BN(marginRatioInitial)
|
|
286
|
-
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION.div(numericConstants_1.MARGIN_PRECISION))
|
|
287
|
-
.toNumber();
|
|
288
|
-
return maxTargetSpread;
|
|
289
|
-
}
|
|
290
|
-
exports.calculateMaxSpread = calculateMaxSpread;
|
|
291
287
|
function calculateVolSpreadBN(lastOracleConfPct, reservePrice, markStd, oracleStd, longIntensity, shortIntensity, volume24H) {
|
|
292
288
|
const marketAvgStdPct = markStd
|
|
293
289
|
.add(oracleStd)
|
|
@@ -309,7 +305,43 @@ function calculateVolSpreadBN(lastOracleConfPct, reservePrice, markStd, oracleSt
|
|
|
309
305
|
return [longVolSpread, shortVolSpread];
|
|
310
306
|
}
|
|
311
307
|
exports.calculateVolSpreadBN = calculateVolSpreadBN;
|
|
312
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Funding bias β(f) (BID_ASK_SPREAD_PRECISION): bounded multiplier for the
|
|
310
|
+
* paying-side spread while the vAMM is paying funding. Mirrors the program's
|
|
311
|
+
* `calculate_spread_funding_bias_scale`.
|
|
312
|
+
*
|
|
313
|
+
* ρ(f) = clamp(|f| / f_ref, 0, 1), f_ref = FUNDING_RATE_OFFSET_PERCENTAGE
|
|
314
|
+
* β(f) = 1 + s * ρ(f), s = fundingBiasSensitivity / 100
|
|
315
|
+
*
|
|
316
|
+
* f = 24h avg funding rate normalized to a daily fraction of the oracle twap
|
|
317
|
+
* captured at the last funding update. The vAMM pays when f * q < 0
|
|
318
|
+
* (q = baseAssetAmountWithAmm). Returns 1x when the vAMM receives funding or
|
|
319
|
+
* s = 0.
|
|
320
|
+
*/
|
|
321
|
+
function calculateSpreadFundingBiasScale(baseAssetAmountWithAmm, last24HAvgFundingRate, lastFundingOracleTwap, fundingBiasSensitivity) {
|
|
322
|
+
const one = numericConstants_1.BID_ASK_SPREAD_PRECISION.toNumber();
|
|
323
|
+
if (fundingBiasSensitivity === 0 || lastFundingOracleTwap.lte(numericConstants_1.ZERO)) {
|
|
324
|
+
return one;
|
|
325
|
+
}
|
|
326
|
+
// f: daily funding rate as a fraction of price, FUNDING_RATE_PRECISION
|
|
327
|
+
const fNorm = last24HAvgFundingRate
|
|
328
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
329
|
+
.div(lastFundingOracleTwap)
|
|
330
|
+
.muln(24);
|
|
331
|
+
// f * q >= 0: vAMM receives (or rate/inventory is zero), β = 1
|
|
332
|
+
if (fNorm.isZero() || baseAssetAmountWithAmm.isZero()) {
|
|
333
|
+
return one;
|
|
334
|
+
}
|
|
335
|
+
if (fNorm.isNeg() === baseAssetAmountWithAmm.isNeg()) {
|
|
336
|
+
return one;
|
|
337
|
+
}
|
|
338
|
+
// ρ = clamp(|f| / f_ref, 0, 1), PERCENTAGE_PRECISION
|
|
339
|
+
const ramp = anchor_1.BN.min(fNorm.abs().mul(numericConstants_1.PERCENTAGE_PRECISION).div(numericConstants_1.FUNDING_RATE_OFFSET_PERCENTAGE), numericConstants_1.PERCENTAGE_PRECISION).toNumber();
|
|
340
|
+
// β = 1 + s * ρ
|
|
341
|
+
return one + Math.floor((fundingBiasSensitivity * ramp) / 100);
|
|
342
|
+
}
|
|
343
|
+
exports.calculateSpreadFundingBiasScale = calculateSpreadFundingBiasScale;
|
|
344
|
+
function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOracleConfPct, maxSpread, quoteAssetReserve, terminalQuoteAssetReserve, pegMultiplier, baseAssetAmountWithAmm, reservePrice, totalFeeMinusDistributions, netRevenueSinceLastFunding, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, markStd, oracleStd, longIntensity, shortIntensity, volume24H, ammInventorySpreadAdjustment, last24HAvgFundingRate = numericConstants_1.ZERO, lastFundingOracleTwap = numericConstants_1.ZERO, fundingBiasSensitivity = 0, returnTerms = false) {
|
|
313
345
|
(0, assert_1.assert)(Number.isInteger(baseSpread));
|
|
314
346
|
(0, assert_1.assert)(Number.isInteger(maxSpread));
|
|
315
347
|
const spreadTerms = {
|
|
@@ -329,6 +361,9 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
|
|
|
329
361
|
halfRevenueRetreatAmount: 0,
|
|
330
362
|
longSpreadwRevRetreat: 0,
|
|
331
363
|
shortSpreadwRevRetreat: 0,
|
|
364
|
+
fundingBiasScale: 0,
|
|
365
|
+
longSpreadwFundingBias: 0,
|
|
366
|
+
shortSpreadwFundingBias: 0,
|
|
332
367
|
longSpreadwOffsetShrink: 0,
|
|
333
368
|
shortSpreadwOffsetShrink: 0,
|
|
334
369
|
totalSpread: 0,
|
|
@@ -412,6 +447,23 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
|
|
|
412
447
|
}
|
|
413
448
|
spreadTerms.longSpreadwRevRetreat = longSpread;
|
|
414
449
|
spreadTerms.shortSpreadwRevRetreat = shortSpread;
|
|
450
|
+
// funding bias: w_pay = min(w_max, (w_0 * σ(q) * λ(q) + r(q)) * β(f)).
|
|
451
|
+
// β multiplies the fully built paying side only, selected by sign(q)
|
|
452
|
+
// (the same side σ widens); the max-spread cap below still bounds it.
|
|
453
|
+
// β = 1 when the vAMM receives.
|
|
454
|
+
const fundingBiasScale = calculateSpreadFundingBiasScale(baseAssetAmountWithAmm, last24HAvgFundingRate, lastFundingOracleTwap, fundingBiasSensitivity);
|
|
455
|
+
const spreadPrecision = numericConstants_1.BID_ASK_SPREAD_PRECISION.toNumber();
|
|
456
|
+
if (fundingBiasScale > spreadPrecision) {
|
|
457
|
+
if (baseAssetAmountWithAmm.gt(numericConstants_1.ZERO)) {
|
|
458
|
+
longSpread = Math.floor((longSpread * fundingBiasScale) / spreadPrecision);
|
|
459
|
+
}
|
|
460
|
+
else if (baseAssetAmountWithAmm.lt(numericConstants_1.ZERO)) {
|
|
461
|
+
shortSpread = Math.floor((shortSpread * fundingBiasScale) / spreadPrecision);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
spreadTerms.fundingBiasScale = fundingBiasScale;
|
|
465
|
+
spreadTerms.longSpreadwFundingBias = longSpread;
|
|
466
|
+
spreadTerms.shortSpreadwFundingBias = shortSpread;
|
|
415
467
|
if (ammInventorySpreadAdjustment < 0) {
|
|
416
468
|
const adjustment = Math.abs(ammInventorySpreadAdjustment);
|
|
417
469
|
const shrunkLong = Math.max(1, longSpread - Math.floor((longSpread * adjustment) / 100));
|
|
@@ -450,6 +502,9 @@ function calculateSpread(amm, marketStats, oraclePriceData, now, reservePrice) {
|
|
|
450
502
|
if (amm.baseSpread == 0 || amm.curveUpdateIntensity == 0) {
|
|
451
503
|
return [amm.baseSpread / 2, amm.baseSpread / 2];
|
|
452
504
|
}
|
|
505
|
+
if (!oraclePriceData) {
|
|
506
|
+
throw new Error('calculateSpread: oraclePriceData is required when baseSpread and curveUpdateIntensity are nonzero');
|
|
507
|
+
}
|
|
453
508
|
if (!reservePrice) {
|
|
454
509
|
reservePrice = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
455
510
|
}
|
|
@@ -461,7 +516,7 @@ function calculateSpread(amm, marketStats, oraclePriceData, now, reservePrice) {
|
|
|
461
516
|
now = now || new anchor_1.BN(new Date().getTime() / 1000); //todo
|
|
462
517
|
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(marketStats, oraclePriceData, now);
|
|
463
518
|
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(marketStats, oraclePriceData, reservePrice, now);
|
|
464
|
-
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve, marketStats.markStd, liveOracleStd, marketStats.longIntensityVolume, marketStats.shortIntensityVolume, marketStats.volume24H, amm.ammInventorySpreadAdjustment);
|
|
519
|
+
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve, marketStats.markStd, liveOracleStd, marketStats.longIntensityVolume, marketStats.shortIntensityVolume, marketStats.volume24H, amm.ammInventorySpreadAdjustment, marketStats.last24HAvgFundingRate, marketStats.lastFundingOracleTwap, amm.fundingBiasSensitivity);
|
|
465
520
|
let longSpread = spreads[0];
|
|
466
521
|
let shortSpread = spreads[1];
|
|
467
522
|
if (amm.ammSpreadAdjustment > 0) {
|
|
@@ -5,7 +5,7 @@ const numericConstants_1 = require("../constants/numericConstants");
|
|
|
5
5
|
const position_1 = require("./position");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
function isUserBankrupt(user) {
|
|
8
|
-
const userAccount = user.
|
|
8
|
+
const userAccount = user.getUserAccountOrThrow();
|
|
9
9
|
let hasLiability = false;
|
|
10
10
|
for (const position of userAccount.spotPositions) {
|
|
11
11
|
if (position.scaledBalance.gt(numericConstants_1.ZERO)) {
|
|
@@ -16,7 +16,7 @@ function calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, period
|
|
|
16
16
|
const timeSinceLastMarkChange = now.sub(lastMarkPriceTwapTs);
|
|
17
17
|
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(period, anchor_1.BN.max(numericConstants_1.ZERO, period.sub(timeSinceLastMarkChange)));
|
|
18
18
|
if (!markPrice) {
|
|
19
|
-
const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, market.marketStats,
|
|
19
|
+
const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, market.marketStats, mmOraclePriceData);
|
|
20
20
|
markPrice = bid.add(ask).div(new anchor_1.BN(2));
|
|
21
21
|
}
|
|
22
22
|
const markTwapWithMantissa = markTwapTimeSinceLastUpdate
|
|
@@ -66,6 +66,9 @@ function calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePrice
|
|
|
66
66
|
now = now || new anchor_1.BN((Date.now() / 1000).toFixed(0));
|
|
67
67
|
// calculate real-time mark and oracle twap
|
|
68
68
|
const liveMarkTwap = calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, market.marketStats.fundingPeriod);
|
|
69
|
+
if (!oraclePriceData) {
|
|
70
|
+
throw new Error('calculateAllEstimatedFundingRate: oraclePriceData is required for an initialized market');
|
|
71
|
+
}
|
|
69
72
|
const liveOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(market.marketStats.historicalOracleData, oraclePriceData, now, market.marketStats.fundingPeriod);
|
|
70
73
|
const [markTwap, oracleTwap] = shrinkStaleTwaps(market, liveMarkTwap, liveOracleTwap, now);
|
|
71
74
|
// if(!markTwap.eq(liveMarkTwap)){
|
|
@@ -250,11 +253,8 @@ exports.calculateLongShortFundingRateAndLiveTwaps = calculateLongShortFundingRat
|
|
|
250
253
|
*/
|
|
251
254
|
function calculateFundingPool(market) {
|
|
252
255
|
// todo
|
|
253
|
-
|
|
254
|
-
const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions
|
|
255
|
-
.sub(totalFeeLB)
|
|
256
|
-
.mul(new anchor_1.BN(1))
|
|
257
|
-
.div(new anchor_1.BN(3)));
|
|
256
|
+
// no protocol floor post-isolation: 1/3 of the AMM's own equity
|
|
257
|
+
const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions.mul(new anchor_1.BN(1)).div(new anchor_1.BN(3)));
|
|
258
258
|
return feePool;
|
|
259
259
|
}
|
|
260
260
|
exports.calculateFundingPool = calculateFundingPool;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { BN } from '../isomorphic/anchor';
|
|
3
3
|
import { SpotMarketAccount } from '../types';
|
|
4
4
|
export declare function nextRevenuePoolSettleApr(spotMarket: SpotMarketAccount, vaultBalance: BN, // vault token amount
|
|
5
|
-
amount
|
|
5
|
+
amount: BN): number;
|
|
6
6
|
export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
7
7
|
export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
8
8
|
export declare function unstakeSharesToAmountWithOpenRequest(nShares: BN, withdrawRequestShares: BN, withdrawRequestAmount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
@@ -12,11 +12,10 @@ amount // delta token amount
|
|
|
12
12
|
// Conmputing the APR:
|
|
13
13
|
const revenuePoolBN = (0, spotBalance_1.getTokenAmount)(spotMarket.revenuePool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
14
14
|
const payoutRatio = 0.1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
?
|
|
19
|
-
spotMarket.insuranceFund.totalFactor
|
|
15
|
+
// the insurance fund is 100% staker-owned: every settled token accrues to
|
|
16
|
+
// stakers as share-price appreciation (no protocol split)
|
|
17
|
+
const ratioForStakers = spotMarket.insuranceFund.revenueSettlePeriod.gt(numericConstants_1.ZERO)
|
|
18
|
+
? 1
|
|
20
19
|
: 0;
|
|
21
20
|
// Settle periods from on-chain data:
|
|
22
21
|
const revSettlePeriod = spotMarket.insuranceFund.revenueSettlePeriod.toNumber() * 1000;
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
import { BN } from '../isomorphic/anchor';
|
|
3
3
|
import { OraclePriceData } from '../oracles/types';
|
|
4
4
|
import { VelocityClient } from '../velocityClient';
|
|
5
|
-
import { PerpMarketAccount, PerpPosition
|
|
6
|
-
import { PublicKey } from '@solana/web3.js';
|
|
5
|
+
import { PerpMarketAccount, PerpPosition } from '../types';
|
|
7
6
|
export declare function calculateSizePremiumLiabilityWeight(size: BN, // AMM_RESERVE_PRECISION
|
|
8
7
|
imfFactor: BN, liabilityWeight: BN, precision: BN, isBounded?: boolean): BN;
|
|
9
8
|
export declare function calculateSizeDiscountAssetWeight(size: BN, // AMM_RESERVE_PRECISION
|
|
10
9
|
imfFactor: BN, assetWeight: BN): BN;
|
|
11
|
-
export declare function calculateOraclePriceForPerpMargin(perpPosition: PerpPosition, market: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
12
10
|
/**
|
|
13
11
|
* 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
|
|
14
12
|
* See {@link calculatePerpLiabilityValue} to get the liabiltiy value
|
|
@@ -37,9 +35,3 @@ export declare function calculateMarginUSDCRequiredForTrade(velocityClient: Velo
|
|
|
37
35
|
* Returns collateral required in the precision of the target collateral market.
|
|
38
36
|
*/
|
|
39
37
|
export declare function calculateCollateralDepositRequiredForTrade(velocityClient: VelocityClient, targetMarketIndex: number, baseSize: BN, collateralIndex: number, userMaxMarginRatio?: number, estEntryPrice?: BN): BN;
|
|
40
|
-
export declare function calculateCollateralValueOfDeposit(velocityClient: VelocityClient, collateralIndex: number, baseSize: BN): BN;
|
|
41
|
-
export declare function calculateLiquidationPrice(freeCollateral: BN, freeCollateralDelta: BN, oraclePrice: BN): BN;
|
|
42
|
-
export declare function calculateUserMaxPerpOrderSize(velocityClient: VelocityClient, userAccountKey: PublicKey, userAccount: UserAccount, targetMarketIndex: number, tradeSide: PositionDirection): {
|
|
43
|
-
tradeSize: BN;
|
|
44
|
-
oppositeSideTradeSize: BN;
|
|
45
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.calculateCollateralDepositRequiredForTrade = exports.calculateMarginUSDCRequiredForTrade = exports.calculatePerpLiabilityValue = exports.calculateWorstCasePerpLiabilityValue = exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Margin calculation helpers — TypeScript mirror of `programs/velocity/src/math/margin.rs`.
|
|
6
6
|
* Computes initial/maintenance margin requirements, free collateral, and account health.
|
|
@@ -11,8 +11,6 @@ const numericConstants_1 = require("../constants/numericConstants");
|
|
|
11
11
|
const anchor_1 = require("../isomorphic/anchor");
|
|
12
12
|
const market_1 = require("./market");
|
|
13
13
|
const spotBalance_1 = require("./spotBalance");
|
|
14
|
-
const oneShotUserAccountSubscriber_1 = require("../accounts/oneShotUserAccountSubscriber");
|
|
15
|
-
const user_1 = require("../user");
|
|
16
14
|
const types_1 = require("../types");
|
|
17
15
|
const assert_1 = require("../assert/assert");
|
|
18
16
|
function calculateSizePremiumLiabilityWeight(size, // AMM_RESERVE_PRECISION
|
|
@@ -55,22 +53,6 @@ imfFactor, assetWeight) {
|
|
|
55
53
|
return minAssetWeight;
|
|
56
54
|
}
|
|
57
55
|
exports.calculateSizeDiscountAssetWeight = calculateSizeDiscountAssetWeight;
|
|
58
|
-
function calculateOraclePriceForPerpMargin(perpPosition, market, oraclePriceData) {
|
|
59
|
-
const oraclePriceOffset = anchor_1.BN.min(new anchor_1.BN(market.amm.maxSpread)
|
|
60
|
-
.mul(oraclePriceData.price)
|
|
61
|
-
.div(numericConstants_1.BID_ASK_SPREAD_PRECISION), oraclePriceData.confidence.add(new anchor_1.BN(market.amm.baseSpread)
|
|
62
|
-
.mul(oraclePriceData.price)
|
|
63
|
-
.div(numericConstants_1.BID_ASK_SPREAD_PRECISION)));
|
|
64
|
-
let marginPrice;
|
|
65
|
-
if (perpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
66
|
-
marginPrice = oraclePriceData.price.sub(oraclePriceOffset);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
marginPrice = oraclePriceData.price.add(oraclePriceOffset);
|
|
70
|
-
}
|
|
71
|
-
return marginPrice;
|
|
72
|
-
}
|
|
73
|
-
exports.calculateOraclePriceForPerpMargin = calculateOraclePriceForPerpMargin;
|
|
74
56
|
/**
|
|
75
57
|
* 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
|
|
76
58
|
* See {@link calculatePerpLiabilityValue} to get the liabiltiy value
|
|
@@ -131,7 +113,7 @@ exports.calculatePerpLiabilityValue = calculatePerpLiabilityValue;
|
|
|
131
113
|
* @returns
|
|
132
114
|
*/
|
|
133
115
|
function calculateMarginUSDCRequiredForTrade(velocityClient, targetMarketIndex, baseSize, userMaxMarginRatio, entryPrice) {
|
|
134
|
-
const targetMarket = velocityClient.
|
|
116
|
+
const targetMarket = velocityClient.getPerpMarketAccountOrThrow(targetMarketIndex);
|
|
135
117
|
const price = entryPrice !== null && entryPrice !== void 0 ? entryPrice : velocityClient.getOracleDataForPerpMarket(targetMarket.marketIndex).price;
|
|
136
118
|
const perpLiabilityValue = calculatePerpLiabilityValue(baseSize, price);
|
|
137
119
|
const marginRequired = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(targetMarket, baseSize.abs(), 'Initial', userMaxMarginRatio))
|
|
@@ -147,7 +129,7 @@ exports.calculateMarginUSDCRequiredForTrade = calculateMarginUSDCRequiredForTrad
|
|
|
147
129
|
*/
|
|
148
130
|
function calculateCollateralDepositRequiredForTrade(velocityClient, targetMarketIndex, baseSize, collateralIndex, userMaxMarginRatio, estEntryPrice) {
|
|
149
131
|
const marginRequiredUsdc = calculateMarginUSDCRequiredForTrade(velocityClient, targetMarketIndex, baseSize, userMaxMarginRatio, estEntryPrice);
|
|
150
|
-
const collateralMarket = velocityClient.
|
|
132
|
+
const collateralMarket = velocityClient.getSpotMarketAccountOrThrow(collateralIndex);
|
|
151
133
|
const collateralOracleData = velocityClient.getOracleDataForSpotMarket(collateralIndex);
|
|
152
134
|
const scaledAssetWeight = (0, spotBalance_1.calculateScaledInitialAssetWeight)(collateralMarket, collateralOracleData.price);
|
|
153
135
|
// Base amount required to deposit = (marginRequiredUsdc / priceOfAsset) / assetWeight .. (E.g. $100 required / $10000 price / 0.5 weight)
|
|
@@ -162,44 +144,3 @@ function calculateCollateralDepositRequiredForTrade(velocityClient, targetMarket
|
|
|
162
144
|
return baseAmountRequired;
|
|
163
145
|
}
|
|
164
146
|
exports.calculateCollateralDepositRequiredForTrade = calculateCollateralDepositRequiredForTrade;
|
|
165
|
-
function calculateCollateralValueOfDeposit(velocityClient, collateralIndex, baseSize) {
|
|
166
|
-
const collateralMarket = velocityClient.getSpotMarketAccount(collateralIndex);
|
|
167
|
-
const collateralOracleData = velocityClient.getOracleDataForSpotMarket(collateralIndex);
|
|
168
|
-
const scaledAssetWeight = (0, spotBalance_1.calculateScaledInitialAssetWeight)(collateralMarket, collateralOracleData.price);
|
|
169
|
-
// CollateralBaseValue = oracle price * collateral base amount (and shift to QUOTE_PRECISION)
|
|
170
|
-
const collateralBaseValue = collateralOracleData.price
|
|
171
|
-
.mul(baseSize)
|
|
172
|
-
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
173
|
-
.div(numericConstants_1.PRICE_PRECISION)
|
|
174
|
-
.div(new anchor_1.BN(10).pow(new anchor_1.BN(collateralMarket.decimals)));
|
|
175
|
-
const depositCollateralValue = collateralBaseValue
|
|
176
|
-
.mul(scaledAssetWeight)
|
|
177
|
-
.div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
|
|
178
|
-
return depositCollateralValue;
|
|
179
|
-
}
|
|
180
|
-
exports.calculateCollateralValueOfDeposit = calculateCollateralValueOfDeposit;
|
|
181
|
-
function calculateLiquidationPrice(freeCollateral, freeCollateralDelta, oraclePrice) {
|
|
182
|
-
const liqPriceDelta = freeCollateral
|
|
183
|
-
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
184
|
-
.div(freeCollateralDelta);
|
|
185
|
-
const liqPrice = oraclePrice.sub(liqPriceDelta);
|
|
186
|
-
if (liqPrice.lt(numericConstants_1.ZERO)) {
|
|
187
|
-
return new anchor_1.BN(-1);
|
|
188
|
-
}
|
|
189
|
-
return liqPrice;
|
|
190
|
-
}
|
|
191
|
-
exports.calculateLiquidationPrice = calculateLiquidationPrice;
|
|
192
|
-
function calculateUserMaxPerpOrderSize(velocityClient, userAccountKey, userAccount, targetMarketIndex, tradeSide) {
|
|
193
|
-
const userAccountSubscriber = new oneShotUserAccountSubscriber_1.OneShotUserAccountSubscriber(velocityClient.program, userAccountKey, userAccount);
|
|
194
|
-
const user = new user_1.User({
|
|
195
|
-
velocityClient,
|
|
196
|
-
userAccountPublicKey: userAccountKey,
|
|
197
|
-
accountSubscription: {
|
|
198
|
-
type: 'custom',
|
|
199
|
-
userAccountSubscriber: userAccountSubscriber,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
user.isSubscribed = true;
|
|
203
|
-
return user.getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide);
|
|
204
|
-
}
|
|
205
|
-
exports.calculateUserMaxPerpOrderSize = calculateUserMaxPerpOrderSize;
|