@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMultipleBetweenOracleSources = exports.
|
|
3
|
+
exports.getMultipleBetweenOracleSources = exports.getNewOracleConfPct = exports.calculateLiveOracleStd = exports.calculateLiveOracleTwap = exports.isOracleTooDivergent = exports.isOracleValid = exports.getOracleValidity = exports.getMaxConfidenceIntervalMultiplier = exports.oraclePriceBands = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const assert_1 = require("../assert/assert");
|
|
@@ -36,8 +36,8 @@ function getMaxConfidenceIntervalMultiplier(market) {
|
|
|
36
36
|
exports.getMaxConfidenceIntervalMultiplier = getMaxConfidenceIntervalMultiplier;
|
|
37
37
|
function getOracleValidity(market, oraclePriceData, oracleGuardRails, slot, oracleStalenessBuffer = numericConstants_1.FIVE) {
|
|
38
38
|
const isNonPositive = oraclePriceData.price.lte(numericConstants_1.ZERO);
|
|
39
|
-
const isTooVolatile = anchor_1.BN.max(oraclePriceData.price, market.
|
|
40
|
-
.div(anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(oraclePriceData.price, market.
|
|
39
|
+
const isTooVolatile = anchor_1.BN.max(oraclePriceData.price, market.marketStats.historicalOracleData.lastOraclePriceTwap)
|
|
40
|
+
.div(anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(oraclePriceData.price, market.marketStats.historicalOracleData.lastOraclePriceTwap)))
|
|
41
41
|
.gt(oracleGuardRails.validity.tooVolatileRatio);
|
|
42
42
|
const confPctOfPrice = oraclePriceData.confidence
|
|
43
43
|
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
|
|
@@ -45,18 +45,18 @@ function getOracleValidity(market, oraclePriceData, oracleGuardRails, slot, orac
|
|
|
45
45
|
const isConfTooLarge = confPctOfPrice.gt(oracleGuardRails.validity.confidenceIntervalMaxSize.mul(getMaxConfidenceIntervalMultiplier(market)));
|
|
46
46
|
const oracleDelay = slot.sub(oraclePriceData.slot).sub(oracleStalenessBuffer);
|
|
47
47
|
let isStaleForAmmImmediate = true;
|
|
48
|
-
if (market.
|
|
49
|
-
isStaleForAmmImmediate = oracleDelay.gt(anchor_1.BN.max(new anchor_1.BN(market.
|
|
48
|
+
if (market.oracleSlotDelayOverride != 0) {
|
|
49
|
+
isStaleForAmmImmediate = oracleDelay.gt(anchor_1.BN.max(new anchor_1.BN(market.oracleSlotDelayOverride), numericConstants_1.ZERO));
|
|
50
50
|
}
|
|
51
51
|
let isStaleForAmmLowRisk = false;
|
|
52
|
-
if (market.
|
|
53
|
-
isStaleForAmmLowRisk = oracleDelay.gt(anchor_1.BN.max(new anchor_1.BN(market.
|
|
52
|
+
if (market.oracleLowRiskSlotDelayOverride != 0) {
|
|
53
|
+
isStaleForAmmLowRisk = oracleDelay.gt(anchor_1.BN.max(new anchor_1.BN(market.oracleLowRiskSlotDelayOverride), numericConstants_1.ZERO));
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
56
|
isStaleForAmmLowRisk = oracleDelay.gt(oracleGuardRails.validity.slotsBeforeStaleForAmm);
|
|
57
57
|
}
|
|
58
58
|
let isStaleForMargin = oracleDelay.gt(new anchor_1.BN(oracleGuardRails.validity.slotsBeforeStaleForMargin));
|
|
59
|
-
if ((0, types_1.isVariant)(market.
|
|
59
|
+
if ((0, types_1.isVariant)(market.oracleSource, 'pythLazerStableCoin')) {
|
|
60
60
|
isStaleForMargin = oracleDelay.gt(new anchor_1.BN(oracleGuardRails.validity.slotsBeforeStaleForMargin).muln(3));
|
|
61
61
|
}
|
|
62
62
|
if (isNonPositive) {
|
|
@@ -87,12 +87,12 @@ function getOracleValidity(market, oraclePriceData, oracleGuardRails, slot, orac
|
|
|
87
87
|
exports.getOracleValidity = getOracleValidity;
|
|
88
88
|
function isOracleValid(market, oraclePriceData, oracleGuardRails, slot) {
|
|
89
89
|
// checks if oracle is valid for an AMM only fill
|
|
90
|
-
const
|
|
90
|
+
const stats = market.marketStats;
|
|
91
91
|
const isOraclePriceNonPositive = oraclePriceData.price.lte(numericConstants_1.ZERO);
|
|
92
92
|
const isOraclePriceTooVolatile = oraclePriceData.price
|
|
93
|
-
.div(anchor_1.BN.max(numericConstants_1.ONE,
|
|
93
|
+
.div(anchor_1.BN.max(numericConstants_1.ONE, stats.historicalOracleData.lastOraclePriceTwap))
|
|
94
94
|
.gt(oracleGuardRails.validity.tooVolatileRatio) ||
|
|
95
|
-
|
|
95
|
+
stats.historicalOracleData.lastOraclePriceTwap
|
|
96
96
|
.div(anchor_1.BN.max(numericConstants_1.ONE, oraclePriceData.price))
|
|
97
97
|
.gt(oracleGuardRails.validity.tooVolatileRatio);
|
|
98
98
|
const maxConfidenceIntervalMultiplier = getMaxConfidenceIntervalMultiplier(market);
|
|
@@ -110,11 +110,11 @@ function isOracleValid(market, oraclePriceData, oracleGuardRails, slot) {
|
|
|
110
110
|
isConfidenceTooLarge);
|
|
111
111
|
}
|
|
112
112
|
exports.isOracleValid = isOracleValid;
|
|
113
|
-
function isOracleTooDivergent(
|
|
113
|
+
function isOracleTooDivergent(marketStats, oraclePriceData, oracleGuardRails) {
|
|
114
114
|
const oracleSpreadPct = oraclePriceData.price
|
|
115
|
-
.sub(
|
|
115
|
+
.sub(marketStats.historicalOracleData.lastOraclePriceTwap5Min)
|
|
116
116
|
.mul(numericConstants_1.PERCENTAGE_PRECISION)
|
|
117
|
-
.div(
|
|
117
|
+
.div(marketStats.historicalOracleData.lastOraclePriceTwap5Min);
|
|
118
118
|
const maxDivergence = anchor_1.BN.max(oracleGuardRails.priceDivergence.oracleTwap5MinPercentDivergence, numericConstants_1.PERCENTAGE_PRECISION.div(new anchor_1.BN(2)));
|
|
119
119
|
const tooDivergent = oracleSpreadPct.abs().gte(maxDivergence);
|
|
120
120
|
return tooDivergent;
|
|
@@ -141,23 +141,23 @@ function calculateLiveOracleTwap(histOracleData, oraclePriceData, now, period) {
|
|
|
141
141
|
return newOracleTwap;
|
|
142
142
|
}
|
|
143
143
|
exports.calculateLiveOracleTwap = calculateLiveOracleTwap;
|
|
144
|
-
function calculateLiveOracleStd(
|
|
145
|
-
const sinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, now.sub(
|
|
146
|
-
const sinceStart = anchor_1.BN.max(numericConstants_1.ZERO,
|
|
147
|
-
const liveOracleTwap = calculateLiveOracleTwap(
|
|
148
|
-
const liveOracleTwap5MIN = calculateLiveOracleTwap(
|
|
144
|
+
function calculateLiveOracleStd(marketStats, oraclePriceData, now) {
|
|
145
|
+
const sinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs));
|
|
146
|
+
const sinceStart = anchor_1.BN.max(numericConstants_1.ZERO, marketStats.fundingPeriod.sub(sinceLastUpdate));
|
|
147
|
+
const liveOracleTwap = calculateLiveOracleTwap(marketStats.historicalOracleData, oraclePriceData, now, marketStats.fundingPeriod);
|
|
148
|
+
const liveOracleTwap5MIN = calculateLiveOracleTwap(marketStats.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE);
|
|
149
149
|
const priceDeltaVsTwap = anchor_1.BN.max(oraclePriceData.price.sub(liveOracleTwap).abs(), oraclePriceData.price.sub(liveOracleTwap5MIN).abs());
|
|
150
|
-
const oracleStd = priceDeltaVsTwap.add(
|
|
150
|
+
const oracleStd = priceDeltaVsTwap.add(marketStats.oracleStd.mul(sinceStart).div(sinceStart.add(sinceLastUpdate)));
|
|
151
151
|
return oracleStd;
|
|
152
152
|
}
|
|
153
153
|
exports.calculateLiveOracleStd = calculateLiveOracleStd;
|
|
154
|
-
function getNewOracleConfPct(
|
|
154
|
+
function getNewOracleConfPct(marketStats, oraclePriceData, reservePrice, now) {
|
|
155
155
|
const confInterval = oraclePriceData.confidence || numericConstants_1.ZERO;
|
|
156
|
-
const sinceLastUpdate = anchor_1.BN.max(numericConstants_1.ZERO, now.sub(
|
|
157
|
-
let lowerBoundConfPct =
|
|
156
|
+
const sinceLastUpdate = anchor_1.BN.max(numericConstants_1.ZERO, now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs));
|
|
157
|
+
let lowerBoundConfPct = marketStats.lastOracleConfPct;
|
|
158
158
|
if (sinceLastUpdate.gt(numericConstants_1.ZERO)) {
|
|
159
159
|
const lowerBoundConfDivisor = anchor_1.BN.max(new anchor_1.BN(21).sub(sinceLastUpdate), new anchor_1.BN(5));
|
|
160
|
-
lowerBoundConfPct =
|
|
160
|
+
lowerBoundConfPct = marketStats.lastOracleConfPct.sub(marketStats.lastOracleConfPct.div(lowerBoundConfDivisor));
|
|
161
161
|
}
|
|
162
162
|
const confIntervalPct = confInterval
|
|
163
163
|
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
|
|
@@ -166,19 +166,6 @@ function getNewOracleConfPct(amm, oraclePriceData, reservePrice, now) {
|
|
|
166
166
|
return confIntervalPctResult;
|
|
167
167
|
}
|
|
168
168
|
exports.getNewOracleConfPct = getNewOracleConfPct;
|
|
169
|
-
function trimVaaSignatures(vaa, n = 3) {
|
|
170
|
-
const currentNumSignatures = vaa[5];
|
|
171
|
-
if (n > currentNumSignatures) {
|
|
172
|
-
throw new Error("Resulting VAA can't have more signatures than the original VAA");
|
|
173
|
-
}
|
|
174
|
-
const trimmedVaa = Buffer.concat([
|
|
175
|
-
vaa.subarray(0, 6 + n * 66),
|
|
176
|
-
vaa.subarray(6 + currentNumSignatures * 66),
|
|
177
|
-
]);
|
|
178
|
-
trimmedVaa[5] = n;
|
|
179
|
-
return trimmedVaa;
|
|
180
|
-
}
|
|
181
|
-
exports.trimVaaSignatures = trimVaaSignatures;
|
|
182
169
|
function getMultipleBetweenOracleSources(firstOracleSource, secondOracleSource) {
|
|
183
170
|
if ((0, types_1.isOneOfVariant)(firstOracleSource, [
|
|
184
171
|
'pythPull',
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import {
|
|
3
|
-
import { PerpMarketAccount, AMM, Order, PositionDirection, MarketTypeStr, StateAccount } from '../types';
|
|
2
|
+
import { PerpMarketAccount, AMM, MarketStats, Order, PositionDirection, MarketTypeStr, StateAccount } from '../types';
|
|
4
3
|
import { BN } from '../isomorphic/anchor';
|
|
5
4
|
import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
|
|
6
|
-
export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
|
|
7
|
-
export declare function isOrderRiskIncreasingInSameDirection(user: User, order: Order): boolean;
|
|
8
|
-
export declare function isOrderReduceOnly(user: User, order: Order): boolean;
|
|
9
5
|
export declare function standardizeBaseAssetAmount(baseAssetAmount: BN, stepSize: BN): BN;
|
|
10
6
|
export declare function standardizePrice(price: BN, tickSize: BN, direction: PositionDirection): BN;
|
|
11
7
|
export declare function getLimitPrice<T extends MarketTypeStr>(order: Order, oraclePriceData: T extends 'spot' ? OraclePriceData : MMOraclePriceData, slot: number, fallbackPrice?: BN): BN | undefined;
|
|
@@ -14,14 +10,13 @@ export declare function hasAuctionPrice(order: Order, slot: number): boolean;
|
|
|
14
10
|
export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, slot: number, ts: number, state: StateAccount): boolean;
|
|
15
11
|
export declare function isLowRiskForAmm(order: Order, mmOraclePriceData: MMOraclePriceData, isLiquidation?: boolean): boolean;
|
|
16
12
|
export declare function calculateBaseAssetAmountForAmmToFulfill(order: Order, market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, slot: number): BN;
|
|
17
|
-
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, amm: AMM, limitPrice: BN, mmOraclePriceData: MMOraclePriceData): BN;
|
|
13
|
+
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, amm: AMM, marketStats: MarketStats, orderStepSize: BN, orderTickSize: BN, limitPrice: BN, mmOraclePriceData: MMOraclePriceData): BN;
|
|
18
14
|
export declare function isOrderExpired(order: Order, ts: number, enforceBuffer?: boolean, bufferSeconds?: number): boolean;
|
|
19
15
|
export declare function isMarketOrder(order: Order): boolean;
|
|
20
16
|
export declare function isLimitOrder(order: Order): boolean;
|
|
21
17
|
export declare function mustBeTriggered(order: Order): boolean;
|
|
22
18
|
export declare function isTriggered(order: Order): boolean;
|
|
23
19
|
export declare function isRestingLimitOrder(order: Order, slot: number): boolean;
|
|
24
|
-
export declare function isTakingOrder(order: Order, slot: number): boolean;
|
|
25
20
|
export declare function isSignedMsgOrder(order: Order): boolean;
|
|
26
21
|
export declare function hasBuilder(order: Order): boolean;
|
|
27
22
|
export declare function calculateOrderBaseAssetAmount(order: Order, existingBaseAssetAmount: BN): BN;
|
|
@@ -1,80 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.maxSizeForTargetLiabilityWeightBN = exports.calculateOrderBaseAssetAmount = exports.hasBuilder = exports.isSignedMsgOrder = exports.
|
|
3
|
+
exports.maxSizeForTargetLiabilityWeightBN = exports.calculateOrderBaseAssetAmount = exports.hasBuilder = exports.isSignedMsgOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isLowRiskForAmm = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const anchor_1 = require("../isomorphic/anchor");
|
|
7
7
|
const auction_1 = require("./auction");
|
|
8
8
|
const amm_1 = require("./amm");
|
|
9
9
|
const margin_1 = require("./margin");
|
|
10
|
-
function isOrderRiskIncreasing(user, order) {
|
|
11
|
-
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const position = user.getPerpPosition(order.marketIndex) ||
|
|
15
|
-
user.getEmptyPosition(order.marketIndex);
|
|
16
|
-
// if no position exists, it's risk increasing
|
|
17
|
-
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
// if position is long and order is long
|
|
21
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
// if position is short and order is short
|
|
25
|
-
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
26
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
30
|
-
// if order will flip position
|
|
31
|
-
if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
|
37
|
-
function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
38
|
-
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const position = user.getPerpPosition(order.marketIndex) ||
|
|
42
|
-
user.getEmptyPosition(order.marketIndex);
|
|
43
|
-
// if no position exists, it's risk increasing
|
|
44
|
-
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
// if position is long and order is long
|
|
48
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
// if position is short and order is short
|
|
52
|
-
if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
|
|
53
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
|
|
59
|
-
function isOrderReduceOnly(user, order) {
|
|
60
|
-
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const position = user.getPerpPosition(order.marketIndex) ||
|
|
64
|
-
user.getEmptyPosition(order.marketIndex);
|
|
65
|
-
// if position is long and order is long
|
|
66
|
-
if (position.baseAssetAmount.gte(numericConstants_1.ZERO) &&
|
|
67
|
-
(0, types_1.isVariant)(order.direction, 'long')) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
// if position is short and order is short
|
|
71
|
-
if (position.baseAssetAmount.lte(numericConstants_1.ZERO) &&
|
|
72
|
-
(0, types_1.isVariant)(order.direction, 'short')) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
exports.isOrderReduceOnly = isOrderReduceOnly;
|
|
78
10
|
function standardizeBaseAssetAmount(baseAssetAmount, stepSize) {
|
|
79
11
|
const remainder = baseAssetAmount.mod(stepSize);
|
|
80
12
|
return baseAssetAmount.sub(remainder);
|
|
@@ -147,21 +79,21 @@ function calculateBaseAssetAmountForAmmToFulfill(order, market, mmOraclePriceDat
|
|
|
147
79
|
let baseAssetAmount;
|
|
148
80
|
const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
|
|
149
81
|
if (limitPrice !== undefined) {
|
|
150
|
-
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, limitPrice, mmOraclePriceData);
|
|
82
|
+
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, market.marketStats, market.orderStepSize, market.orderTickSize, limitPrice, mmOraclePriceData);
|
|
151
83
|
}
|
|
152
84
|
else {
|
|
153
85
|
baseAssetAmount = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
154
86
|
}
|
|
155
|
-
const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, order.direction);
|
|
87
|
+
const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, market.orderStepSize, order.direction);
|
|
156
88
|
return anchor_1.BN.min(maxBaseAssetAmount, baseAssetAmount);
|
|
157
89
|
}
|
|
158
90
|
exports.calculateBaseAssetAmountForAmmToFulfill = calculateBaseAssetAmountForAmmToFulfill;
|
|
159
|
-
function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, limitPrice, mmOraclePriceData) {
|
|
91
|
+
function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, marketStats, orderStepSize, orderTickSize, limitPrice, mmOraclePriceData) {
|
|
160
92
|
const adjustedLimitPrice = (0, types_1.isVariant)(order.direction, 'long')
|
|
161
|
-
? limitPrice.sub(
|
|
162
|
-
: limitPrice.add(
|
|
163
|
-
const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(amm, adjustedLimitPrice, order.direction, mmOraclePriceData);
|
|
164
|
-
const baseAssetAmount = standardizeBaseAssetAmount(maxAmountToTrade,
|
|
93
|
+
? limitPrice.sub(orderTickSize)
|
|
94
|
+
: limitPrice.add(orderTickSize);
|
|
95
|
+
const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(amm, marketStats, adjustedLimitPrice, order.direction, mmOraclePriceData);
|
|
96
|
+
const baseAssetAmount = standardizeBaseAssetAmount(maxAmountToTrade, orderStepSize);
|
|
165
97
|
// Check that directions are the same
|
|
166
98
|
const sameDirection = isSameDirection(direction, order.direction);
|
|
167
99
|
if (!sameDirection) {
|
|
@@ -219,10 +151,6 @@ function isRestingLimitOrder(order, slot) {
|
|
|
219
151
|
return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
|
|
220
152
|
}
|
|
221
153
|
exports.isRestingLimitOrder = isRestingLimitOrder;
|
|
222
|
-
function isTakingOrder(order, slot) {
|
|
223
|
-
return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
|
|
224
|
-
}
|
|
225
|
-
exports.isTakingOrder = isTakingOrder;
|
|
226
154
|
const FLAG_IS_SIGNED_MSG = 0x01;
|
|
227
155
|
function isSignedMsgOrder(order) {
|
|
228
156
|
return (order.bitFlags & FLAG_IS_SIGNED_MSG) !== 0;
|
|
@@ -285,7 +213,7 @@ function maxSizeForTargetLiabilityWeightBN(target, imfFactor, liabilityWeight, m
|
|
|
285
213
|
}
|
|
286
214
|
}
|
|
287
215
|
// cap at max OI
|
|
288
|
-
const maxOpenInterest = market.
|
|
216
|
+
const maxOpenInterest = market.maxOpenInterest;
|
|
289
217
|
if (lo.gt(maxOpenInterest)) {
|
|
290
218
|
return maxOpenInterest;
|
|
291
219
|
}
|
|
@@ -41,10 +41,6 @@ export declare function calculateFeesAndFundingPnl(market: PerpMarketAccount, pe
|
|
|
41
41
|
* @returns // QUOTE_PRECISION
|
|
42
42
|
*/
|
|
43
43
|
export declare function calculateUnsettledFundingPnl(market: PerpMarketAccount, perpPosition: PerpPosition): BN;
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated use calculateUnsettledFundingPnl or calculateFeesAndFundingPnl instead
|
|
46
|
-
*/
|
|
47
|
-
export declare function calculatePositionFundingPNL(market: PerpMarketAccount, perpPosition: PerpPosition): BN;
|
|
48
44
|
export declare function positionIsAvailable(position: PerpPosition): boolean;
|
|
49
45
|
export declare function positionIsBeingLiquidated(position: PerpPosition): boolean;
|
|
50
46
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasOpenOrders = exports.isEmptyPosition = exports.positionCurrentDirection = exports.findDirectionToClose = exports.calculateCostBasis = exports.calculateEntryPrice = exports.calculateBreakEvenPrice = exports.positionIsBeingLiquidated = exports.positionIsAvailable = exports.
|
|
3
|
+
exports.hasOpenOrders = exports.isEmptyPosition = exports.positionCurrentDirection = exports.findDirectionToClose = exports.calculateCostBasis = exports.calculateEntryPrice = exports.calculateBreakEvenPrice = exports.positionIsBeingLiquidated = exports.positionIsAvailable = exports.calculateUnsettledFundingPnl = exports.calculateFeesAndFundingPnl = exports.calculateClaimablePnl = exports.calculatePositionPNL = exports.calculateBaseAssetValue = 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");
|
|
@@ -23,7 +23,7 @@ function calculateBaseAssetValue(market, userPosition, mmOraclePriceData, useSpr
|
|
|
23
23
|
let prepegAmm;
|
|
24
24
|
if (!skipUpdate) {
|
|
25
25
|
if (market.amm.baseSpread > 0 && useSpread) {
|
|
26
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, directionToClose, mmOraclePriceData, latestSlot);
|
|
26
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, directionToClose, mmOraclePriceData, latestSlot);
|
|
27
27
|
prepegAmm = {
|
|
28
28
|
baseAssetReserve,
|
|
29
29
|
quoteAssetReserve,
|
|
@@ -51,6 +51,8 @@ function calculateBaseAssetValue(market, userPosition, mmOraclePriceData, useSpr
|
|
|
51
51
|
.mul(prepegAmm.pegMultiplier)
|
|
52
52
|
.div(numericConstants_1.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO)
|
|
53
53
|
.add(numericConstants_1.ONE);
|
|
54
|
+
default:
|
|
55
|
+
throw new Error('Invalid position direction to close');
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
exports.calculateBaseAssetValue = calculateBaseAssetValue;
|
|
@@ -124,10 +126,10 @@ function calculateUnsettledFundingPnl(market, perpPosition) {
|
|
|
124
126
|
}
|
|
125
127
|
let ammCumulativeFundingRate;
|
|
126
128
|
if (perpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
127
|
-
ammCumulativeFundingRate = market.
|
|
129
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateLong;
|
|
128
130
|
}
|
|
129
131
|
else {
|
|
130
|
-
ammCumulativeFundingRate = market.
|
|
132
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateShort;
|
|
131
133
|
}
|
|
132
134
|
const perPositionFundingRate = ammCumulativeFundingRate
|
|
133
135
|
.sub(perpPosition.lastCumulativeFundingRate)
|
|
@@ -138,13 +140,6 @@ function calculateUnsettledFundingPnl(market, perpPosition) {
|
|
|
138
140
|
return perPositionFundingRate;
|
|
139
141
|
}
|
|
140
142
|
exports.calculateUnsettledFundingPnl = calculateUnsettledFundingPnl;
|
|
141
|
-
/**
|
|
142
|
-
* @deprecated use calculateUnsettledFundingPnl or calculateFeesAndFundingPnl instead
|
|
143
|
-
*/
|
|
144
|
-
function calculatePositionFundingPNL(market, perpPosition) {
|
|
145
|
-
return calculateUnsettledFundingPnl(market, perpPosition);
|
|
146
|
-
}
|
|
147
|
-
exports.calculatePositionFundingPNL = calculatePositionFundingPNL;
|
|
148
143
|
function positionIsAvailable(position) {
|
|
149
144
|
return (position.baseAssetAmount.eq(numericConstants_1.ZERO) &&
|
|
150
145
|
position.openOrders === 0 &&
|
|
@@ -18,5 +18,4 @@ export declare function calculateAdjustKCost(amm: AMM, numerator: BN, denomenato
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function calculateRepegCost(amm: AMM, newPeg: BN): BN;
|
|
20
20
|
export declare function calculateBudgetedKBN(x: BN, y: BN, budget: BN, Q: BN, d: BN): [BN, BN];
|
|
21
|
-
export declare function calculateBudgetedK(amm: AMM, cost: BN): [BN, BN];
|
|
22
21
|
export declare function calculateBudgetedPeg(amm: AMM, budget: BN, targetPrice: BN): BN;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateBudgetedPeg = exports.
|
|
3
|
+
exports.calculateBudgetedPeg = exports.calculateBudgetedKBN = exports.calculateRepegCost = exports.calculateAdjustKCost = void 0;
|
|
4
4
|
const anchor_1 = require("../isomorphic/anchor");
|
|
5
5
|
const assert_1 = require("../assert/assert");
|
|
6
6
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
@@ -115,28 +115,6 @@ function calculateBudgetedKBN(x, y, budget, Q, d) {
|
|
|
115
115
|
return [numerator, denominator];
|
|
116
116
|
}
|
|
117
117
|
exports.calculateBudgetedKBN = calculateBudgetedKBN;
|
|
118
|
-
function calculateBudgetedK(amm, cost) {
|
|
119
|
-
// wolframalpha.com
|
|
120
|
-
// (1/(x+d) - p/(x*p+d))*y*d*Q = C solve for p
|
|
121
|
-
// p = (d(y*d*Q - C(x+d))) / (C*x(x+d) + y*d*d*Q)
|
|
122
|
-
// numer
|
|
123
|
-
// = y*d*d*Q - Cxd - Cdd
|
|
124
|
-
// = y/x*Q*d*d - Cd - Cd/x
|
|
125
|
-
// = mark - C/d - C/(x)
|
|
126
|
-
// = mark/C - 1/d - 1/x
|
|
127
|
-
// denom
|
|
128
|
-
// = C*x*x + C*x*d + y*d*d*Q
|
|
129
|
-
// = x/d**2 + 1 / d + mark/C
|
|
130
|
-
// todo: assumes k = x * y
|
|
131
|
-
// otherwise use: (y(1-p) + (kp^2/(x*p+d)) - k/(x+d)) * Q = C solve for p
|
|
132
|
-
const x = amm.baseAssetReserve;
|
|
133
|
-
const y = amm.quoteAssetReserve;
|
|
134
|
-
const d = amm.baseAssetAmountWithAmm;
|
|
135
|
-
const Q = amm.pegMultiplier;
|
|
136
|
-
const [numerator, denominator] = calculateBudgetedKBN(x, y, cost, Q, d);
|
|
137
|
-
return [numerator, denominator];
|
|
138
|
-
}
|
|
139
|
-
exports.calculateBudgetedK = calculateBudgetedK;
|
|
140
118
|
function calculateBudgetedPeg(amm, budget, targetPrice) {
|
|
141
119
|
let perPegCost = amm.quoteAssetReserve
|
|
142
120
|
.sub(amm.terminalQuoteAssetReserve)
|
|
@@ -48,9 +48,9 @@ export declare function getStrictTokenValue(tokenAmount: BN, spotDecimals: numbe
|
|
|
48
48
|
* @return {BN} The value of the token based on the oracle, scaled by `PRICE_PRECISION`
|
|
49
49
|
*/
|
|
50
50
|
export declare function getTokenValue(tokenAmount: BN, spotDecimals: number, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
|
|
51
|
-
export declare function calculateAssetWeight(balanceAmount: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
51
|
+
export declare function calculateAssetWeight(balanceAmount: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory | undefined): BN;
|
|
52
52
|
export declare function calculateScaledInitialAssetWeight(spotMarket: SpotMarketAccount, oraclePrice: BN): BN;
|
|
53
|
-
export declare function calculateLiabilityWeight(size: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
53
|
+
export declare function calculateLiabilityWeight(size: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory | undefined): BN;
|
|
54
54
|
export declare function calculateUtilization(bank: SpotMarketAccount, delta?: BN): BN;
|
|
55
55
|
/**
|
|
56
56
|
* calculates max borrow amount where rate would stay below targetBorrowRate
|
|
@@ -78,8 +78,8 @@ export declare function calculateWithdrawLimit(spotMarket: SpotMarketAccount, no
|
|
|
78
78
|
withdrawLimit: BN;
|
|
79
79
|
minDepositAmount: BN;
|
|
80
80
|
maxBorrowAmount: BN;
|
|
81
|
-
currentDepositAmount:
|
|
82
|
-
currentBorrowAmount:
|
|
81
|
+
currentDepositAmount: BN;
|
|
82
|
+
currentBorrowAmount: BN;
|
|
83
83
|
};
|
|
84
84
|
export declare function getSpotAssetValue(tokenAmount: BN, strictOraclePrice: StrictOraclePrice, spotMarketAccount: SpotMarketAccount, maxMarginRatio: number, marginCategory?: MarginCategory): BN;
|
|
85
85
|
export declare function getSpotLiabilityValue(tokenAmount: BN, strictOraclePrice: StrictOraclePrice, spotMarketAccount: SpotMarketAccount, maxMarginRatio: number, marginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
|
|
@@ -246,9 +246,9 @@ function calculateSpotMarketBorrowCapacity(spotMarketAccount, targetBorrowRate)
|
|
|
246
246
|
return { totalCapacity, remainingCapacity };
|
|
247
247
|
}
|
|
248
248
|
exports.calculateSpotMarketBorrowCapacity = calculateSpotMarketBorrowCapacity;
|
|
249
|
-
function calculateInterestRate(bank, delta = numericConstants_1.ZERO, currentUtilization
|
|
249
|
+
function calculateInterestRate(bank, delta = numericConstants_1.ZERO, currentUtilization) {
|
|
250
250
|
// todo: ensure both a delta and current util aren't pass?
|
|
251
|
-
const utilization = currentUtilization
|
|
251
|
+
const utilization = currentUtilization !== null && currentUtilization !== void 0 ? currentUtilization : calculateUtilization(bank, delta);
|
|
252
252
|
const optimalUtil = new anchor_1.BN(bank.optimalUtilization);
|
|
253
253
|
const optimalRate = new anchor_1.BN(bank.optimalBorrowRate);
|
|
254
254
|
const maxRate = new anchor_1.BN(bank.maxBorrowRate);
|
|
@@ -296,20 +296,20 @@ function calculateInterestRate(bank, delta = numericConstants_1.ZERO, currentUti
|
|
|
296
296
|
return anchor_1.BN.max(minRate, rate);
|
|
297
297
|
}
|
|
298
298
|
exports.calculateInterestRate = calculateInterestRate;
|
|
299
|
-
function calculateDepositRate(bank, delta = numericConstants_1.ZERO, currentUtilization
|
|
299
|
+
function calculateDepositRate(bank, delta = numericConstants_1.ZERO, currentUtilization) {
|
|
300
300
|
// positive delta => adding to deposit
|
|
301
301
|
// negative delta => adding to borrow
|
|
302
|
-
const utilization = currentUtilization
|
|
302
|
+
const utilization = currentUtilization !== null && currentUtilization !== void 0 ? currentUtilization : calculateUtilization(bank, delta);
|
|
303
303
|
const borrowRate = calculateBorrowRate(bank, delta, utilization);
|
|
304
304
|
const depositRate = borrowRate
|
|
305
|
-
.mul(numericConstants_2.PERCENTAGE_PRECISION.sub(new anchor_1.BN(bank.insuranceFund.
|
|
305
|
+
.mul(numericConstants_2.PERCENTAGE_PRECISION.sub(new anchor_1.BN(bank.insuranceFund.ifFeeFactor + bank.protocolFeeFactor)))
|
|
306
306
|
.mul(utilization)
|
|
307
307
|
.div(numericConstants_1.SPOT_MARKET_UTILIZATION_PRECISION)
|
|
308
308
|
.div(numericConstants_2.PERCENTAGE_PRECISION);
|
|
309
309
|
return depositRate;
|
|
310
310
|
}
|
|
311
311
|
exports.calculateDepositRate = calculateDepositRate;
|
|
312
|
-
function calculateBorrowRate(bank, delta = numericConstants_1.ZERO, currentUtilization
|
|
312
|
+
function calculateBorrowRate(bank, delta = numericConstants_1.ZERO, currentUtilization) {
|
|
313
313
|
return calculateInterestRate(bank, delta, currentUtilization);
|
|
314
314
|
}
|
|
315
315
|
exports.calculateBorrowRate = calculateBorrowRate;
|
|
@@ -3,9 +3,3 @@ import { BN } from '../isomorphic/anchor';
|
|
|
3
3
|
import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
|
|
4
4
|
export declare function castNumberToSpotPrecision(value: number | BN, spotMarket: SpotMarketAccount): BN;
|
|
5
5
|
export declare function calculateSpotMarketMarginRatio(market: SpotMarketAccount, oraclePrice: BN, marginCategory: MarginCategory, size: BN, balanceType: SpotBalanceType, customMarginRatio?: number): number;
|
|
6
|
-
/**
|
|
7
|
-
* Returns the maximum remaining deposit that can be made to the spot market. If the maxTokenDeposits on the market is zero then there is no limit and this function will also return zero. (so that needs to be checked)
|
|
8
|
-
* @param market
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export declare function calculateMaxRemainingDeposit(market: SpotMarketAccount): BN;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.calculateSpotMarketMarginRatio = exports.castNumberToSpotPrecision = void 0;
|
|
4
4
|
const anchor_1 = require("../isomorphic/anchor");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const spotBalance_1 = require("./spotBalance");
|
|
@@ -32,18 +32,3 @@ function calculateSpotMarketMarginRatio(market, oraclePrice, marginCategory, siz
|
|
|
32
32
|
return marginRatio;
|
|
33
33
|
}
|
|
34
34
|
exports.calculateSpotMarketMarginRatio = calculateSpotMarketMarginRatio;
|
|
35
|
-
/**
|
|
36
|
-
* Returns the maximum remaining deposit that can be made to the spot market. If the maxTokenDeposits on the market is zero then there is no limit and this function will also return zero. (so that needs to be checked)
|
|
37
|
-
* @param market
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
function calculateMaxRemainingDeposit(market) {
|
|
41
|
-
const marketMaxTokenDeposits = market.maxTokenDeposits;
|
|
42
|
-
if (marketMaxTokenDeposits.eq(numericConstants_1.ZERO)) {
|
|
43
|
-
// If the maxTokenDeposits is set to zero then that means there is no limit. Return the largest number we can to represent infinite available deposit.
|
|
44
|
-
return numericConstants_1.ZERO;
|
|
45
|
-
}
|
|
46
|
-
const totalDepositsTokenAmount = (0, spotBalance_1.getTokenAmount)(market.depositBalance, market, types_1.SpotBalanceType.DEPOSIT);
|
|
47
|
-
return marketMaxTokenDeposits.sub(totalDepositsTokenAmount);
|
|
48
|
-
}
|
|
49
|
-
exports.calculateMaxRemainingDeposit = calculateMaxRemainingDeposit;
|
|
@@ -9,11 +9,11 @@ export type OrderFillSimulation = {
|
|
|
9
9
|
tokenValue: BN;
|
|
10
10
|
weight: BN;
|
|
11
11
|
weightedTokenValue: BN;
|
|
12
|
-
freeCollateralContribution:
|
|
12
|
+
freeCollateralContribution: BN;
|
|
13
13
|
};
|
|
14
|
-
export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, strictOraclePrice: StrictOraclePrice, marginCategory: MarginCategory, customMarginRatio?: number, includeOpenOrders?: boolean): OrderFillSimulation;
|
|
15
|
-
export declare function calculateWeightedTokenValue(tokenAmount: BN, tokenValue: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory, customMarginRatio?: number): {
|
|
14
|
+
export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, strictOraclePrice: StrictOraclePrice, marginCategory: MarginCategory | undefined, customMarginRatio?: number, includeOpenOrders?: boolean): OrderFillSimulation;
|
|
15
|
+
export declare function calculateWeightedTokenValue(tokenAmount: BN, tokenValue: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory | undefined, customMarginRatio?: number): {
|
|
16
16
|
weight: BN;
|
|
17
17
|
weightedTokenValue: BN;
|
|
18
18
|
};
|
|
19
|
-
export declare function simulateOrderFill(tokenAmount: BN, tokenValue: BN, openOrders: BN, strictOraclePrice: StrictOraclePrice, spotMarket: SpotMarketAccount, marginCategory: MarginCategory, customMarginRatio?: number): OrderFillSimulation;
|
|
19
|
+
export declare function simulateOrderFill(tokenAmount: BN, tokenValue: BN, openOrders: BN, strictOraclePrice: StrictOraclePrice, spotMarket: SpotMarketAccount, marginCategory: MarginCategory | undefined, customMarginRatio?: number): OrderFillSimulation;
|
|
@@ -4,5 +4,3 @@ import { StateAccount } from '../types';
|
|
|
4
4
|
export declare function calculateInitUserFee(stateAccount: StateAccount): BN;
|
|
5
5
|
export declare function getMaxNumberOfSubAccounts(stateAccount: StateAccount): BN;
|
|
6
6
|
export declare function useMedianTriggerPrice(stateAccount: StateAccount): boolean;
|
|
7
|
-
export declare function builderCodesEnabled(stateAccount: StateAccount): boolean;
|
|
8
|
-
export declare function builderReferralEnabled(stateAccount: StateAccount): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useMedianTriggerPrice = exports.getMaxNumberOfSubAccounts = exports.calculateInitUserFee = 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");
|
|
@@ -34,11 +34,3 @@ function useMedianTriggerPrice(stateAccount) {
|
|
|
34
34
|
return ((stateAccount.featureBitFlags & types_1.FeatureBitFlags.MEDIAN_TRIGGER_PRICE) > 0);
|
|
35
35
|
}
|
|
36
36
|
exports.useMedianTriggerPrice = useMedianTriggerPrice;
|
|
37
|
-
function builderCodesEnabled(stateAccount) {
|
|
38
|
-
return (stateAccount.featureBitFlags & types_1.FeatureBitFlags.BUILDER_CODES) > 0;
|
|
39
|
-
}
|
|
40
|
-
exports.builderCodesEnabled = builderCodesEnabled;
|
|
41
|
-
function builderReferralEnabled(stateAccount) {
|
|
42
|
-
return (stateAccount.featureBitFlags & types_1.FeatureBitFlags.BUILDER_REFERRAL) > 0;
|
|
43
|
-
}
|
|
44
|
-
exports.builderReferralEnabled = builderReferralEnabled;
|