@velocity-exchange/sdk 0.0.5 → 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/.prettierignore +1 -1
- package/CHANGELOG.md +35 -0
- package/README.md +30 -30
- package/bun.lock +24 -2
- 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 +9 -3
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +4 -1
- 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 -5
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
- package/lib/browser/accounts/types.d.ts +6 -12
- package/lib/browser/accounts/utils.d.ts +1 -0
- package/lib/browser/accounts/utils.js +10 -3
- 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 -8
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
- 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 +1 -9
- package/lib/browser/addresses/pda.js +4 -23
- package/lib/browser/adminClient.d.ts +25 -29
- package/lib/browser/adminClient.js +168 -169
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +2 -4
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +8 -10
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
- package/lib/browser/auctionSubscriber/types.d.ts +3 -2
- 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 +11 -20
- package/lib/browser/config.js +13 -36
- 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.d.ts +0 -2
- package/lib/browser/constituentMap/constituentMap.js +10 -6
- 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/VelocityCore.d.ts +9 -15
- package/lib/browser/core/VelocityCore.js +5 -7
- package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
- package/lib/browser/core/instructions/perpOrders.js +14 -0
- package/lib/browser/core/instructions/withdraw.d.ts +1 -1
- package/lib/browser/core/instructions/withdraw.js +1 -1
- package/lib/browser/core/remainingAccounts.d.ts +2 -2
- package/lib/browser/core/remainingAccounts.js +5 -5
- package/lib/browser/decode/user.js +9 -1
- package/lib/browser/dlob/DLOB.d.ts +7 -2
- package/lib/browser/dlob/DLOB.js +205 -142
- package/lib/browser/dlob/DLOBNode.d.ts +5 -2
- package/lib/browser/dlob/DLOBNode.js +7 -0
- package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
- package/lib/browser/dlob/DLOBSubscriber.js +39 -39
- package/lib/browser/dlob/NodeList.js +8 -7
- package/lib/browser/dlob/orderBookLevels.js +24 -17
- package/lib/browser/dlob/types.d.ts +0 -2
- package/lib/browser/events/eventList.js +4 -1
- package/lib/browser/events/eventSubscriber.d.ts +6 -3
- package/lib/browser/events/eventSubscriber.js +75 -26
- package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
- package/lib/browser/events/eventsServerLogProvider.js +17 -10
- package/lib/browser/events/fetchLogs.d.ts +1 -1
- package/lib/browser/events/fetchLogs.js +4 -2
- package/lib/browser/events/parse.js +14 -14
- 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 +3 -7
- package/lib/browser/events/types.js +1 -3
- 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/{node/idl/drift.d.ts → browser/idl/velocity.d.ts} +2412 -2481
- package/lib/browser/idl/{drift.json → velocity.json} +2265 -2333
- package/lib/browser/index.d.ts +1 -3
- package/lib/browser/index.js +1 -4
- 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 +87 -31
- package/lib/browser/math/auction.js +16 -12
- package/lib/browser/math/bankruptcy.js +1 -1
- package/lib/browser/math/builder.d.ts +18 -1
- package/lib/browser/math/builder.js +32 -1
- package/lib/browser/math/funding.js +30 -30
- package/lib/browser/math/insurance.d.ts +1 -1
- package/lib/browser/math/insurance.js +4 -5
- package/lib/browser/math/margin.d.ts +3 -11
- package/lib/browser/math/margin.js +10 -69
- package/lib/browser/math/market.d.ts +4 -12
- package/lib/browser/math/market.js +12 -46
- package/lib/browser/math/oracles.d.ts +4 -7
- package/lib/browser/math/oracles.js +24 -37
- package/lib/browser/math/orders.d.ts +2 -7
- package/lib/browser/math/orders.js +9 -81
- package/lib/browser/math/position.d.ts +0 -4
- package/lib/browser/math/position.js +6 -11
- 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 +11 -63
- package/lib/browser/math/superStake.js +29 -28
- package/lib/browser/math/trade.js +7 -7
- package/lib/browser/math/utils.d.ts +1 -1
- package/lib/browser/math/utils.js +1 -1
- 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 +5 -4
- 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 -3
- package/lib/browser/orderSubscriber/OrderSubscriber.js +16 -14
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/browser/orderSubscriber/types.d.ts +0 -2
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +2 -6
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +34 -18
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/browser/priorityFee/types.d.ts +3 -8
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
- package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +1 -3
- package/lib/browser/pyth/pythLazerSubscriber.d.ts +1 -1
- package/lib/browser/pyth/pythLazerSubscriber.js +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/swap/UnifiedSwapClient.js +1 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +7 -7
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +14 -10
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -6
- package/lib/browser/swift/swiftOrderSubscriber.js +15 -16
- 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 +102 -157
- package/lib/browser/types.js +6 -2
- package/lib/browser/user.d.ts +22 -10
- package/lib/browser/user.js +174 -154
- package/lib/browser/userConfig.d.ts +3 -2
- package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/browser/userMap/WebsocketSubscription.js +1 -1
- package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
- package/lib/browser/userMap/grpcSubscription.js +1 -1
- package/lib/browser/userMap/referrerMap.d.ts +0 -2
- package/lib/browser/userMap/referrerMap.js +10 -7
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
- package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/browser/userMap/userMap.d.ts +3 -5
- package/lib/browser/userMap/userMap.js +39 -30
- package/lib/browser/userMap/userMapConfig.d.ts +3 -2
- package/lib/browser/userMap/userStatsMap.d.ts +1 -3
- package/lib/browser/userMap/userStatsMap.js +18 -17
- package/lib/browser/userStats.d.ts +7 -4
- package/lib/browser/userStats.js +28 -18
- package/lib/browser/userStatsConfig.d.ts +3 -2
- 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/util/ed25519Utils.d.ts +1 -1
- package/lib/browser/util/ed25519Utils.js +1 -1
- package/lib/browser/velocityClient.d.ts +144 -71
- package/lib/browser/velocityClient.js +653 -457
- package/lib/browser/velocityClientConfig.d.ts +0 -8
- 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 +9 -3
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +4 -1
- 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 -5
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
- package/lib/node/accounts/types.d.ts +6 -12
- 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 +10 -3
- 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 -8
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
- 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 +1 -9
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +4 -23
- package/lib/node/adminClient.d.ts +25 -29
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +168 -169
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +2 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +8 -10
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
- package/lib/node/auctionSubscriber/types.d.ts +3 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- 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 +11 -20
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +13 -36
- 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 +0 -2
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +10 -6
- 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/VelocityCore.d.ts +9 -15
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +5 -7
- 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/instructions/withdraw.d.ts +1 -1
- package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
- package/lib/node/core/instructions/withdraw.js +1 -1
- 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 +5 -5
- 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 +7 -2
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +205 -142
- 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 +0 -2
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +39 -39
- 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 +24 -17
- package/lib/node/dlob/types.d.ts +0 -2
- package/lib/node/dlob/types.d.ts.map +1 -1
- 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 +6 -3
- 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 +17 -10
- 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/parse.d.ts.map +1 -1
- package/lib/node/events/parse.js +14 -14
- 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 +3 -7
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +1 -3
- 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/{browser/idl/drift.d.ts → node/idl/velocity.d.ts} +2413 -2480
- package/lib/node/idl/velocity.d.ts.map +1 -0
- package/lib/node/idl/{drift.json → velocity.json} +2265 -2333
- package/lib/node/index.d.ts +1 -3
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -4
- 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 +87 -31
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +16 -12
- package/lib/node/math/bankruptcy.js +1 -1
- package/lib/node/math/builder.d.ts +18 -1
- package/lib/node/math/builder.d.ts.map +1 -1
- package/lib/node/math/builder.js +32 -1
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +30 -30
- 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 +3 -11
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +10 -69
- 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 +12 -46
- package/lib/node/math/oracles.d.ts +4 -7
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +24 -37
- package/lib/node/math/orders.d.ts +2 -7
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +9 -81
- 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 +6 -11
- 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 +11 -63
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +29 -28
- 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 +7 -7
- package/lib/node/math/utils.d.ts +1 -1
- package/lib/node/math/utils.js +1 -1
- 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 +5 -4
- 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 -3
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +16 -14
- package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/node/orderSubscriber/types.d.ts +0 -2
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- 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 +2 -6
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +34 -18
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +3 -11
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/types.d.ts +3 -8
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
- package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
- package/lib/node/priorityFee/velocityPriorityFeeMethod.js +1 -3
- package/lib/node/pyth/pythLazerSubscriber.d.ts +1 -1
- package/lib/node/pyth/pythLazerSubscriber.js +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/swap/UnifiedSwapClient.js +1 -1
- 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 +7 -7
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +14 -10
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -6
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +15 -16
- 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 +100 -155
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +6 -2
- package/lib/node/user.d.ts +22 -10
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +174 -154
- package/lib/node/userConfig.d.ts +3 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
- package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.js +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/grpcSubscription.js +1 -1
- package/lib/node/userMap/referrerMap.d.ts +0 -2
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +10 -7
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +0 -2
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/node/userMap/userMap.d.ts +3 -5
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +39 -30
- package/lib/node/userMap/userMapConfig.d.ts +3 -2
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +1 -3
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +18 -17
- package/lib/node/userStats.d.ts +7 -4
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +28 -18
- package/lib/node/userStatsConfig.d.ts +3 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- 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/util/ed25519Utils.d.ts +1 -1
- package/lib/node/util/ed25519Utils.js +1 -1
- package/lib/node/velocityClient.d.ts +145 -72
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +653 -457
- package/lib/node/velocityClientConfig.d.ts +0 -8
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +10 -9
- package/scripts/deposit-isolated-positions.ts +2 -2
- package/scripts/find-flagged-users.ts +1 -1
- package/scripts/grpc-client-test-comparison.ts +4 -4
- package/scripts/grpc-multiuser-client-test-comparison.ts +2 -2
- package/scripts/single-grpc-client-test.ts +3 -3
- package/scripts/updateVersion.js +4 -4
- package/scripts/withdraw-isolated-positions.ts +2 -2
- 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 +12 -4
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -14
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +69 -49
- package/src/accounts/laserProgramAccountSubscriber.ts +4 -1
- 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 +80 -41
- package/src/accounts/types.ts +8 -13
- package/src/accounts/utils.ts +12 -2
- 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 +79 -58
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +77 -45
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
- package/src/addresses/marketAddresses.ts +3 -2
- package/src/addresses/pda.ts +3 -38
- package/src/adminClient.ts +285 -315
- package/src/auctionSubscriber/auctionSubscriber.ts +8 -11
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +13 -11
- package/src/auctionSubscriber/types.ts +3 -3
- 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 +16 -70
- package/src/constants/index.ts +1 -2
- package/src/constants/numericConstants.ts +3 -3
- package/src/constituentMap/constituentMap.ts +10 -7
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
- package/src/core/VelocityCore.ts +11 -20
- package/src/core/instructions/perpOrders.ts +14 -0
- package/src/core/instructions/withdraw.ts +2 -2
- package/src/core/remainingAccounts.ts +7 -7
- package/src/decode/user.ts +8 -1
- package/src/dlob/DLOB.ts +300 -176
- package/src/dlob/DLOBNode.ts +23 -3
- package/src/dlob/DLOBSubscriber.ts +53 -42
- package/src/dlob/NodeList.ts +8 -7
- package/src/dlob/orderBookLevels.ts +51 -25
- package/src/dlob/types.ts +0 -2
- package/src/events/eventList.ts +4 -1
- package/src/events/eventSubscriber.ts +108 -50
- package/src/events/eventsServerLogProvider.ts +24 -15
- package/src/events/fetchLogs.ts +3 -3
- package/src/events/parse.ts +14 -14
- package/src/events/pollingLogProvider.ts +2 -2
- package/src/events/txEventCache.ts +8 -2
- package/src/events/types.ts +4 -15
- package/src/events/webSocketLogProvider.ts +5 -3
- package/src/factory/bigNum.ts +2 -2
- package/src/idl/{drift.json → velocity.json} +2265 -2333
- package/src/idl/{drift.ts → velocity.ts} +2267 -2335
- package/src/index.ts +1 -6
- package/src/jupiter/jupiterClient.ts +30 -10
- package/src/margin/README.md +2 -2
- package/src/marginCalculation.ts +1 -0
- package/src/math/amm.ts +217 -40
- package/src/math/auction.ts +16 -12
- package/src/math/bankruptcy.ts +1 -1
- package/src/math/builder.ts +45 -1
- package/src/math/funding.ts +51 -47
- package/src/math/insurance.ts +6 -8
- package/src/math/margin.ts +12 -119
- package/src/math/market.ts +16 -98
- package/src/math/oracles.ts +29 -43
- package/src/math/orders.ts +13 -109
- package/src/math/position.ts +6 -12
- 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 +36 -85
- package/src/math/trade.ts +7 -3
- package/src/math/utils.ts +1 -1
- 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 +10 -5
- package/src/oracles/utils.ts +15 -0
- package/src/orderSubscriber/OrderSubscriber.ts +12 -12
- package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
- package/src/orderSubscriber/grpcSubscription.ts +2 -2
- package/src/orderSubscriber/types.ts +0 -2
- package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +50 -21
- package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
- package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
- package/src/priorityFee/types.ts +3 -13
- package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
- package/src/pyth/pythLazerSubscriber.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/swap/UnifiedSwapClient.ts +1 -1
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
- package/src/swift/signedMsgUserAccountSubscriber.ts +18 -16
- package/src/swift/swiftOrderSubscriber.ts +17 -21
- 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 +119 -173
- package/src/user.ts +208 -165
- package/src/userConfig.ts +1 -3
- package/src/userMap/WebsocketSubscription.ts +2 -2
- package/src/userMap/grpcSubscription.ts +2 -2
- package/src/userMap/referrerMap.ts +13 -13
- package/src/userMap/revenueShareEscrowMap.ts +6 -5
- package/src/userMap/userMap.ts +46 -32
- package/src/userMap/userMapConfig.ts +3 -3
- package/src/userMap/userStatsMap.ts +32 -23
- package/src/userStats.ts +22 -13
- package/src/userStatsConfig.ts +3 -3
- package/src/util/TransactionConfirmationManager.ts +10 -2
- package/src/util/chainClock.ts +1 -1
- package/src/util/computeUnits.ts +7 -3
- package/src/util/ed25519Utils.ts +1 -1
- package/src/velocityClient.ts +867 -600
- package/src/velocityClientConfig.ts +0 -10
- package/tests/{DriftCore → VelocityCore}/decode.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/fill_trigger.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/instructions.test.ts +1 -1
- package/tests/{DriftCore → VelocityCore}/pdas.test.ts +4 -2
- package/tests/amm/test.ts +138 -0
- package/tests/ci/verifyConstants.ts +24 -27
- package/tests/decode/test.ts +2 -2
- package/tests/dlob/helpers.ts +11 -10
- package/tests/events/parseLogsForCuUsage.ts +15 -15
- package/tests/user/helpers.ts +9 -9
- package/tests/user/test.ts +13 -10
- 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/deprecatedAlias.d.ts +0 -26
- package/lib/browser/util/deprecatedAlias.js +0 -10
- 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/idl/drift.d.ts.map +0 -1
- 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/deprecatedAlias.d.ts +0 -27
- package/lib/node/util/deprecatedAlias.d.ts.map +0 -1
- package/lib/node/util/deprecatedAlias.js +0 -10
- 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/deprecatedAlias.ts +0 -21
- package/src/util/tps.ts +0 -27
- /package/lib/browser/idl/{drift.js → velocity.js} +0 -0
- /package/lib/node/idl/{drift.js → velocity.js} +0 -0
- /package/tests/{DriftCore → VelocityCore}/perp_orders.test.ts +0 -0
- /package/tests/{DriftCore → VelocityCore}/remainingAccounts.test.ts +0 -0
- /package/tests/{DriftCore → VelocityCore}/settlement_liquidation.test.ts +0 -0
package/lib/browser/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
|
|
|
25
25
|
export { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
26
26
|
export { WebSocketProgramUserAccountSubscriber } from './accounts/websocketProgramUserAccountSubscriber';
|
|
27
27
|
export { WebSocketProgramAccountsSubscriberV2 } from './accounts/webSocketProgramAccountsSubscriberV2';
|
|
28
|
-
export { WebSocketVelocityClientAccountSubscriberV2
|
|
28
|
+
export { WebSocketVelocityClientAccountSubscriberV2 } from './accounts/webSocketVelocityClientAccountSubscriberV2';
|
|
29
29
|
export * from './accounts/bulkAccountLoader';
|
|
30
30
|
export * from './accounts/bulkUserSubscription';
|
|
31
31
|
export * from './accounts/bulkUserStatsSubscription';
|
|
@@ -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
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.pyth = exports.PublicKey = exports.BN = exports.PythLazerSubscriber = exports.CustomizedCadenceBulkAccountLoader = exports.
|
|
20
|
+
exports.pyth = exports.PublicKey = exports.BN = exports.PythLazerSubscriber = exports.CustomizedCadenceBulkAccountLoader = exports.WebSocketVelocityClientAccountSubscriberV2 = exports.WebSocketProgramAccountsSubscriberV2 = exports.WebSocketProgramUserAccountSubscriber = exports.WebSocketProgramAccountSubscriber = exports.WebSocketAccountSubscriberV2 = void 0;
|
|
21
21
|
/**
|
|
22
22
|
* @module @velocity-exchange/sdk
|
|
23
23
|
* Main package barrel — re-exports all public SDK types, classes, and utilities.
|
|
@@ -54,7 +54,6 @@ var webSocketProgramAccountsSubscriberV2_1 = require("./accounts/webSocketProgra
|
|
|
54
54
|
Object.defineProperty(exports, "WebSocketProgramAccountsSubscriberV2", { enumerable: true, get: function () { return webSocketProgramAccountsSubscriberV2_1.WebSocketProgramAccountsSubscriberV2; } });
|
|
55
55
|
var webSocketVelocityClientAccountSubscriberV2_1 = require("./accounts/webSocketVelocityClientAccountSubscriberV2");
|
|
56
56
|
Object.defineProperty(exports, "WebSocketVelocityClientAccountSubscriberV2", { enumerable: true, get: function () { return webSocketVelocityClientAccountSubscriberV2_1.WebSocketVelocityClientAccountSubscriberV2; } });
|
|
57
|
-
Object.defineProperty(exports, "WebSocketDriftClientAccountSubscriberV2", { enumerable: true, get: function () { return webSocketVelocityClientAccountSubscriberV2_1.WebSocketDriftClientAccountSubscriberV2; } });
|
|
58
57
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
59
58
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
60
59
|
__exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
|
|
@@ -137,13 +136,11 @@ __exportStar(require("./tx/fastSingleTxSender"), exports);
|
|
|
137
136
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
138
137
|
__exportStar(require("./tx/whileValidTxSender"), exports);
|
|
139
138
|
__exportStar(require("./tx/priorityFeeCalculator"), exports);
|
|
140
|
-
__exportStar(require("./tx/forwardOnlyTxSender"), exports);
|
|
141
139
|
__exportStar(require("./tx/types"), exports);
|
|
142
140
|
__exportStar(require("./tx/txHandler"), exports);
|
|
143
141
|
__exportStar(require("./tx/txParamProcessor"), exports);
|
|
144
142
|
__exportStar(require("./util/computeUnits"), exports);
|
|
145
143
|
__exportStar(require("./util/digest"), exports);
|
|
146
|
-
__exportStar(require("./util/tps"), exports);
|
|
147
144
|
__exportStar(require("./util/promiseTimeout"), exports);
|
|
148
145
|
__exportStar(require("./math/spotBalance"), exports);
|
|
149
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);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { BN } from '../isomorphic/anchor';
|
|
3
|
-
import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
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
6
|
export declare function calculateOptimalPegAndBudget(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, boolean];
|
|
7
7
|
export declare function calculateNewAmm(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, BN];
|
|
8
|
-
export declare function calculateUpdatedAMM(amm: AMM, mmOraclePriceData
|
|
9
|
-
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: PositionDirection, mmOraclePriceData
|
|
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,
|
|
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, 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
|
-
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
|
|
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");
|
|
@@ -22,8 +22,9 @@ function calculateOptimalPegAndBudget(amm, mmOraclePriceData) {
|
|
|
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,7 +48,9 @@ function calculateOptimalPegAndBudget(amm, 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
|
}
|
|
@@ -104,9 +107,9 @@ function calculateUpdatedAMM(amm, mmOraclePriceData) {
|
|
|
104
107
|
return newAmm;
|
|
105
108
|
}
|
|
106
109
|
exports.calculateUpdatedAMM = calculateUpdatedAMM;
|
|
107
|
-
function calculateUpdatedAMMSpreadReserves(amm, direction, mmOraclePriceData, latestSlot) {
|
|
110
|
+
function calculateUpdatedAMMSpreadReserves(amm, marketStats, direction, mmOraclePriceData, latestSlot) {
|
|
108
111
|
const newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
109
|
-
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, mmOraclePriceData, undefined, latestSlot);
|
|
112
|
+
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, marketStats, mmOraclePriceData, undefined, latestSlot);
|
|
110
113
|
const dirReserves = (0, types_1.isVariant)(direction, 'long')
|
|
111
114
|
? longReserves
|
|
112
115
|
: shortReserves;
|
|
@@ -119,7 +122,7 @@ function calculateUpdatedAMMSpreadReserves(amm, direction, mmOraclePriceData, la
|
|
|
119
122
|
return result;
|
|
120
123
|
}
|
|
121
124
|
exports.calculateUpdatedAMMSpreadReserves = calculateUpdatedAMMSpreadReserves;
|
|
122
|
-
function calculateBidAskPrice(amm, mmOraclePriceData, withUpdate = true, latestSlot) {
|
|
125
|
+
function calculateBidAskPrice(amm, marketStats, mmOraclePriceData, withUpdate = true, latestSlot) {
|
|
123
126
|
let newAmm;
|
|
124
127
|
if (withUpdate) {
|
|
125
128
|
newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
@@ -127,7 +130,7 @@ function calculateBidAskPrice(amm, mmOraclePriceData, withUpdate = true, latestS
|
|
|
127
130
|
else {
|
|
128
131
|
newAmm = amm;
|
|
129
132
|
}
|
|
130
|
-
const [bidReserves, askReserves] = calculateSpreadReserves(newAmm, mmOraclePriceData, undefined, latestSlot);
|
|
133
|
+
const [bidReserves, askReserves] = calculateSpreadReserves(newAmm, marketStats, mmOraclePriceData, undefined, latestSlot);
|
|
131
134
|
const askPrice = calculatePrice(askReserves.baseAssetReserve, askReserves.quoteAssetReserve, newAmm.pegMultiplier);
|
|
132
135
|
const bidPrice = calculatePrice(bidReserves.baseAssetReserve, bidReserves.quoteAssetReserve, newAmm.pegMultiplier);
|
|
133
136
|
return [bidPrice, askPrice];
|
|
@@ -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));
|
|
@@ -446,10 +498,13 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
|
|
|
446
498
|
return [longSpread, shortSpread];
|
|
447
499
|
}
|
|
448
500
|
exports.calculateSpreadBN = calculateSpreadBN;
|
|
449
|
-
function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
501
|
+
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
|
}
|
|
@@ -459,9 +514,9 @@ function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
|
459
514
|
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
|
|
460
515
|
.div(reservePrice);
|
|
461
516
|
now = now || new anchor_1.BN(new Date().getTime() / 1000); //todo
|
|
462
|
-
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(
|
|
463
|
-
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(
|
|
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,
|
|
517
|
+
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(marketStats, oraclePriceData, now);
|
|
518
|
+
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(marketStats, oraclePriceData, reservePrice, now);
|
|
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) {
|
|
@@ -475,7 +530,7 @@ function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
|
475
530
|
return [longSpread, shortSpread];
|
|
476
531
|
}
|
|
477
532
|
exports.calculateSpread = calculateSpread;
|
|
478
|
-
function calculateSpreadReserves(amm, mmOraclePriceData, now, latestSlot) {
|
|
533
|
+
function calculateSpreadReserves(amm, marketStats, mmOraclePriceData, now, latestSlot) {
|
|
479
534
|
function calculateSpreadReserve(spread, direction, amm) {
|
|
480
535
|
if (spread === 0) {
|
|
481
536
|
return {
|
|
@@ -529,21 +584,22 @@ function calculateSpreadReserves(amm, mmOraclePriceData, now, latestSlot) {
|
|
|
529
584
|
liquidityFractionAfterDeadband = liquidityFractionAfterDeadband.sub(deadbandPct.mul((0, utils_1.sigNum)(liquidityFractionAfterDeadband)));
|
|
530
585
|
}
|
|
531
586
|
}
|
|
532
|
-
referencePriceOffset = calculateReferencePriceOffset(reservePrice,
|
|
587
|
+
referencePriceOffset = calculateReferencePriceOffset(reservePrice, marketStats.last24HAvgFundingRate, liquidityFractionAfterDeadband, marketStats.historicalOracleData.lastOraclePriceTwap5Min, marketStats.lastMarkPriceTwap5Min, marketStats.historicalOracleData.lastOraclePriceTwap, marketStats.lastMarkPriceTwap, maxOffset).toNumber();
|
|
533
588
|
}
|
|
534
|
-
let [longSpread, shortSpread] = calculateSpread(amm, mmOraclePriceData, now, reservePrice);
|
|
535
|
-
const
|
|
589
|
+
let [longSpread, shortSpread] = calculateSpread(amm, marketStats, mmOraclePriceData, now, reservePrice);
|
|
590
|
+
const lastReferencePriceOffset = marketStats.lastReferencePriceOffset;
|
|
591
|
+
const doReferencePricOffsetSmooth = Math.sign(referencePriceOffset) !== Math.sign(lastReferencePriceOffset) &&
|
|
536
592
|
amm.curveUpdateIntensity > 100;
|
|
537
593
|
if (doReferencePricOffsetSmooth) {
|
|
538
594
|
const slotsPassed = latestSlot != null
|
|
539
595
|
? anchor_1.BN.max(latestSlot.sub(amm.lastUpdateSlot), numericConstants_1.ZERO).toNumber()
|
|
540
596
|
: 0;
|
|
541
|
-
const fullOffsetDelta = referencePriceOffset -
|
|
597
|
+
const fullOffsetDelta = referencePriceOffset - lastReferencePriceOffset;
|
|
542
598
|
const raw = Math.trunc(Math.min(Math.abs(fullOffsetDelta), slotsPassed * 1000) / 10);
|
|
543
|
-
const maxAllowed = Math.abs(
|
|
599
|
+
const maxAllowed = Math.abs(lastReferencePriceOffset) || Math.abs(referencePriceOffset);
|
|
544
600
|
const magnitude = Math.min(Math.max(raw, 10), maxAllowed);
|
|
545
601
|
const referencePriceDelta = Math.sign(fullOffsetDelta) * magnitude;
|
|
546
|
-
referencePriceOffset =
|
|
602
|
+
referencePriceOffset = lastReferencePriceOffset + referencePriceDelta;
|
|
547
603
|
if (referencePriceDelta < 0) {
|
|
548
604
|
longSpread += Math.abs(referencePriceDelta);
|
|
549
605
|
shortSpread += Math.abs(referencePriceOffset);
|
|
@@ -614,7 +670,7 @@ function calculateTerminalPrice(market) {
|
|
|
614
670
|
return terminalPrice;
|
|
615
671
|
}
|
|
616
672
|
exports.calculateTerminalPrice = calculateTerminalPrice;
|
|
617
|
-
function calculateMaxBaseAssetAmountToTrade(amm, limit_price, direction, mmOraclePriceData, now) {
|
|
673
|
+
function calculateMaxBaseAssetAmountToTrade(amm, marketStats, limit_price, direction, mmOraclePriceData, now) {
|
|
618
674
|
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
|
619
675
|
const newBaseAssetReserveSquared = invariant
|
|
620
676
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
@@ -622,7 +678,7 @@ function calculateMaxBaseAssetAmountToTrade(amm, limit_price, direction, mmOracl
|
|
|
622
678
|
.div(limit_price)
|
|
623
679
|
.div(numericConstants_1.PEG_PRECISION);
|
|
624
680
|
const newBaseAssetReserve = (0, utils_1.squareRootBN)(newBaseAssetReserveSquared);
|
|
625
|
-
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(amm, mmOraclePriceData, now);
|
|
681
|
+
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(amm, marketStats, mmOraclePriceData, now);
|
|
626
682
|
const baseAssetReserveBefore = (0, types_1.isVariant)(direction, 'long')
|
|
627
683
|
? longSpreadReserves.baseAssetReserve
|
|
628
684
|
: shortSpreadReserves.baseAssetReserve;
|
|
@@ -657,7 +713,7 @@ function calculateQuoteAssetAmountSwapped(quoteAssetReserves, pegMultiplier, swa
|
|
|
657
713
|
return quoteAssetAmount;
|
|
658
714
|
}
|
|
659
715
|
exports.calculateQuoteAssetAmountSwapped = calculateQuoteAssetAmountSwapped;
|
|
660
|
-
function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
|
716
|
+
function calculateMaxBaseAssetAmountFillable(amm, orderStepSize, orderDirection) {
|
|
661
717
|
const maxFillSize = amm.baseAssetReserve.div(new anchor_1.BN(amm.maxFillReserveFraction));
|
|
662
718
|
let maxBaseAssetAmountOnSide;
|
|
663
719
|
if ((0, types_1.isVariant)(orderDirection, 'long')) {
|
|
@@ -666,6 +722,6 @@ function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
|
|
666
722
|
else {
|
|
667
723
|
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.maxBaseAssetReserve.sub(amm.baseAssetReserve));
|
|
668
724
|
}
|
|
669
|
-
return (0, orders_1.standardizeBaseAssetAmount)(anchor_1.BN.min(maxFillSize, maxBaseAssetAmountOnSide),
|
|
725
|
+
return (0, orders_1.standardizeBaseAssetAmount)(anchor_1.BN.min(maxFillSize, maxBaseAssetAmountOnSide), orderStepSize);
|
|
670
726
|
}
|
|
671
727
|
exports.calculateMaxBaseAssetAmountFillable = calculateMaxBaseAssetAmountFillable;
|
|
@@ -171,32 +171,36 @@ exports.deriveOracleAuctionParams = deriveOracleAuctionParams;
|
|
|
171
171
|
*/
|
|
172
172
|
function getTriggerAuctionStartPrice(params) {
|
|
173
173
|
const { perpMarket, direction, oraclePrice, limitPrice } = params;
|
|
174
|
-
const twapMismatch = perpMarket.
|
|
175
|
-
.sub(perpMarket.
|
|
174
|
+
const twapMismatch = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwapTs
|
|
175
|
+
.sub(perpMarket.marketStats.lastMarkPriceTwapTs)
|
|
176
176
|
.abs()
|
|
177
177
|
.gte(new anchor_1.BN(60)) ||
|
|
178
|
-
perpMarket.
|
|
178
|
+
perpMarket.marketStats.volume24H.lte(new anchor_1.BN(100000).mul(numericConstants_1.QUOTE_PRECISION));
|
|
179
179
|
let baselineStartOffset;
|
|
180
180
|
if (twapMismatch) {
|
|
181
181
|
const contractTierNumber = (0, tiers_1.getPerpMarketTierNumber)(perpMarket);
|
|
182
182
|
const priceDivisor = contractTierNumber <= 1 ? 500 : 100;
|
|
183
183
|
baselineStartOffset = (0, types_1.isVariant)(direction, 'long')
|
|
184
|
-
? perpMarket.
|
|
185
|
-
: perpMarket.
|
|
184
|
+
? perpMarket.marketStats.lastBidPriceTwap.divn(priceDivisor)
|
|
185
|
+
: perpMarket.marketStats.lastAskPriceTwap.divn(priceDivisor).neg();
|
|
186
186
|
}
|
|
187
187
|
else {
|
|
188
188
|
const markTwapSlow = (0, types_1.isVariant)(direction, 'long')
|
|
189
|
-
? perpMarket.
|
|
190
|
-
: perpMarket.
|
|
191
|
-
const markTwapFast = perpMarket.
|
|
192
|
-
const oracleTwapSlow = perpMarket.
|
|
193
|
-
const oracleTwapFast = perpMarket.
|
|
189
|
+
? perpMarket.marketStats.lastBidPriceTwap
|
|
190
|
+
: perpMarket.marketStats.lastAskPriceTwap;
|
|
191
|
+
const markTwapFast = perpMarket.marketStats.lastMarkPriceTwap5Min;
|
|
192
|
+
const oracleTwapSlow = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwap;
|
|
193
|
+
const oracleTwapFast = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwap5Min;
|
|
194
194
|
const offsetSlow = markTwapSlow.sub(oracleTwapSlow);
|
|
195
195
|
const offsetFast = markTwapFast.sub(oracleTwapFast);
|
|
196
|
-
|
|
196
|
+
// long_spread/short_spread were removed from AMM in the decoupling refactor.
|
|
197
|
+
// Fall back to half base_spread as the per-side spread approximation; the
|
|
198
|
+
// AMM no longer caches an exact per-side spread without oracle context.
|
|
199
|
+
const halfBaseSpread = new anchor_1.BN(Math.floor(perpMarket.amm.baseSpread / 2));
|
|
200
|
+
const fracOfLongSpreadInPrice = halfBaseSpread
|
|
197
201
|
.mul(markTwapSlow)
|
|
198
202
|
.div(numericConstants_1.PRICE_PRECISION.muln(10)); // divide by 10x for safety
|
|
199
|
-
const fracOfShortSpreadInPrice =
|
|
203
|
+
const fracOfShortSpreadInPrice = halfBaseSpread
|
|
200
204
|
.mul(markTwapSlow)
|
|
201
205
|
.div(numericConstants_1.PRICE_PRECISION.muln(10)); // divide by 10x for safety
|
|
202
206
|
baselineStartOffset = (0, types_1.isVariant)(direction, 'long')
|
|
@@ -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)) {
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { RevenueShareOrder } from '../types';
|
|
1
|
+
import { OrderParams, RevenueShareEscrowAccount, RevenueShareOrder, UserStatsAccount } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* True when the user's RevenueShareEscrow was initialized with a referrer.
|
|
4
|
+
* Fills for such users must include the escrow account or the program rejects
|
|
5
|
+
* them with UnableToLoadRevenueShareAccount.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBuilderReferral(userStats: Pick<UserStatsAccount, 'referrerStatus'>): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* True when the escrow was initialized with a referrer. Referral rewards
|
|
10
|
+
* accrue into such escrows on fills, so fills of the escrow owner's orders
|
|
11
|
+
* must include the escrow account (see `isBuilderReferral`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function escrowHasReferrer(escrow: Pick<RevenueShareEscrowAccount, 'referrer'>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* True when the order params carry a builder code (`builderIdx` +
|
|
16
|
+
* `builderFeeTenthBps`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasBuilderParams(orderParams: Pick<OrderParams, 'builderIdx' | 'builderFeeTenthBps'>): boolean;
|
|
2
19
|
export declare function isBuilderOrderOpen(order: RevenueShareOrder): boolean;
|
|
3
20
|
export declare function isBuilderOrderCompleted(order: RevenueShareOrder): boolean;
|
|
4
21
|
export declare function isBuilderOrderReferral(order: RevenueShareOrder): boolean;
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBuilderOrderAvailable = exports.isBuilderOrderReferral = exports.isBuilderOrderCompleted = exports.isBuilderOrderOpen = void 0;
|
|
3
|
+
exports.isBuilderOrderAvailable = exports.isBuilderOrderReferral = exports.isBuilderOrderCompleted = exports.isBuilderOrderOpen = exports.hasBuilderParams = exports.escrowHasReferrer = exports.isBuilderReferral = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
/**
|
|
7
|
+
* True when the user's RevenueShareEscrow was initialized with a referrer.
|
|
8
|
+
* Fills for such users must include the escrow account or the program rejects
|
|
9
|
+
* them with UnableToLoadRevenueShareAccount.
|
|
10
|
+
*/
|
|
11
|
+
function isBuilderReferral(userStats) {
|
|
12
|
+
return (userStats.referrerStatus & types_1.ReferrerStatus.BuilderReferral) !== 0;
|
|
13
|
+
}
|
|
14
|
+
exports.isBuilderReferral = isBuilderReferral;
|
|
15
|
+
/**
|
|
16
|
+
* True when the escrow was initialized with a referrer. Referral rewards
|
|
17
|
+
* accrue into such escrows on fills, so fills of the escrow owner's orders
|
|
18
|
+
* must include the escrow account (see `isBuilderReferral`).
|
|
19
|
+
*/
|
|
20
|
+
function escrowHasReferrer(escrow) {
|
|
21
|
+
return !escrow.referrer.equals(web3_js_1.PublicKey.default);
|
|
22
|
+
}
|
|
23
|
+
exports.escrowHasReferrer = escrowHasReferrer;
|
|
24
|
+
/**
|
|
25
|
+
* True when the order params carry a builder code (`builderIdx` +
|
|
26
|
+
* `builderFeeTenthBps`).
|
|
27
|
+
*/
|
|
28
|
+
function hasBuilderParams(orderParams) {
|
|
29
|
+
return (orderParams.builderIdx !== null &&
|
|
30
|
+
orderParams.builderIdx !== undefined &&
|
|
31
|
+
orderParams.builderFeeTenthBps !== null &&
|
|
32
|
+
orderParams.builderFeeTenthBps !== undefined);
|
|
33
|
+
}
|
|
34
|
+
exports.hasBuilderParams = hasBuilderParams;
|
|
4
35
|
const FLAG_IS_OPEN = 0x01;
|
|
5
36
|
function isBuilderOrderOpen(order) {
|
|
6
37
|
return (order.bitFlags & FLAG_IS_OPEN) !== 0;
|