@velocity-exchange/sdk 0.0.5 → 0.1.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 +20 -0
- package/README.md +30 -30
- package/bun.lock +1 -1
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +1 -1
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +1 -3
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +0 -4
- package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +5 -7
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +1 -1
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +5 -7
- package/lib/browser/accounts/types.d.ts +2 -8
- package/lib/browser/accounts/utils.js +2 -2
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +5 -7
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +0 -4
- package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +5 -7
- package/lib/browser/addresses/pda.d.ts +1 -7
- package/lib/browser/addresses/pda.js +4 -10
- package/lib/browser/adminClient.d.ts +1 -1
- package/lib/browser/adminClient.js +21 -21
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +1 -3
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +2 -6
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -3
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +2 -6
- package/lib/browser/auctionSubscriber/types.d.ts +3 -2
- package/lib/browser/config.d.ts +10 -19
- package/lib/browser/config.js +6 -33
- package/lib/browser/constants/insuranceFund.d.ts +1 -1
- package/lib/browser/constants/insuranceFund.js +1 -1
- package/lib/browser/constituentMap/constituentMap.d.ts +0 -2
- package/lib/browser/constituentMap/constituentMap.js +5 -5
- package/lib/browser/core/VelocityCore.d.ts +9 -15
- package/lib/browser/core/VelocityCore.js +5 -7
- package/lib/browser/core/instructions/withdraw.d.ts +1 -1
- package/lib/browser/core/instructions/withdraw.js +1 -1
- package/lib/browser/core/remainingAccounts.js +3 -3
- package/lib/browser/dlob/DLOB.d.ts +1 -1
- package/lib/browser/dlob/DLOB.js +6 -6
- package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
- package/lib/browser/dlob/DLOBSubscriber.js +2 -7
- package/lib/browser/dlob/orderBookLevels.js +7 -7
- package/lib/browser/dlob/types.d.ts +0 -2
- package/lib/browser/events/eventSubscriber.d.ts +1 -1
- package/lib/browser/events/eventsServerLogProvider.js +2 -2
- package/lib/browser/events/parse.js +14 -14
- package/lib/browser/events/types.d.ts +3 -5
- package/lib/browser/events/types.js +1 -1
- package/lib/browser/idl/{drift.d.ts → velocity.d.ts} +1042 -767
- package/lib/browser/idl/{drift.json → velocity.json} +1033 -758
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +1 -2
- package/lib/browser/math/amm.d.ts +10 -10
- package/lib/browser/math/amm.js +29 -28
- package/lib/browser/math/auction.js +16 -12
- package/lib/browser/math/builder.d.ts +18 -1
- package/lib/browser/math/builder.js +32 -1
- package/lib/browser/math/funding.js +26 -26
- package/lib/browser/math/margin.d.ts +4 -4
- package/lib/browser/math/margin.js +15 -15
- package/lib/browser/math/market.js +13 -13
- package/lib/browser/math/oracles.d.ts +4 -4
- package/lib/browser/math/oracles.js +23 -23
- package/lib/browser/math/orders.d.ts +2 -2
- package/lib/browser/math/orders.js +9 -9
- package/lib/browser/math/position.js +4 -4
- package/lib/browser/math/superStake.d.ts +8 -10
- package/lib/browser/math/superStake.js +18 -20
- package/lib/browser/math/trade.js +5 -5
- package/lib/browser/math/utils.d.ts +1 -1
- package/lib/browser/math/utils.js +1 -1
- package/lib/browser/oracles/pythLazerClient.js +2 -2
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +0 -2
- package/lib/browser/orderSubscriber/OrderSubscriber.js +8 -12
- 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/priorityFeeSubscriber.d.ts +1 -5
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +7 -15
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
- 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/swap/UnifiedSwapClient.js +1 -1
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +4 -5
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +2 -6
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +6 -5
- package/lib/browser/swift/swiftOrderSubscriber.js +5 -11
- package/lib/browser/types.d.ts +79 -91
- package/lib/browser/types.js +4 -0
- package/lib/browser/user.d.ts +1 -3
- package/lib/browser/user.js +19 -23
- package/lib/browser/userConfig.d.ts +3 -2
- package/lib/browser/userMap/WebsocketSubscription.js +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 +0 -4
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
- package/lib/browser/userMap/revenueShareEscrowMap.js +0 -4
- package/lib/browser/userMap/userMap.d.ts +2 -4
- package/lib/browser/userMap/userMap.js +10 -14
- package/lib/browser/userMap/userMapConfig.d.ts +3 -2
- package/lib/browser/userMap/userStatsMap.d.ts +0 -2
- package/lib/browser/userMap/userStatsMap.js +0 -4
- package/lib/browser/userStats.d.ts +0 -2
- package/lib/browser/userStats.js +10 -14
- package/lib/browser/userStatsConfig.d.ts +3 -2
- package/lib/browser/util/ed25519Utils.d.ts +1 -1
- package/lib/browser/util/ed25519Utils.js +1 -1
- package/lib/browser/velocityClient.d.ts +53 -38
- package/lib/browser/velocityClient.js +258 -196
- package/lib/browser/velocityClientConfig.d.ts +0 -8
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +1 -1
- 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 +1 -3
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +0 -4
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +5 -7
- package/lib/node/accounts/laserProgramAccountSubscriber.js +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +5 -7
- package/lib/node/accounts/types.d.ts +2 -8
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/utils.js +2 -2
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +0 -4
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +5 -7
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +0 -4
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +5 -7
- package/lib/node/addresses/pda.d.ts +1 -7
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +4 -10
- package/lib/node/adminClient.d.ts +1 -1
- package/lib/node/adminClient.js +21 -21
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +1 -3
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +2 -6
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -3
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +2 -6
- package/lib/node/auctionSubscriber/types.d.ts +3 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/config.d.ts +10 -19
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +6 -33
- package/lib/node/constants/insuranceFund.d.ts +1 -1
- package/lib/node/constants/insuranceFund.js +1 -1
- 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 +5 -5
- 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/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.js +3 -3
- package/lib/node/dlob/DLOB.d.ts +1 -1
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +6 -6
- 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 +2 -7
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +7 -7
- package/lib/node/dlob/types.d.ts +0 -2
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.d.ts +1 -1
- package/lib/node/events/eventsServerLogProvider.js +2 -2
- package/lib/node/events/parse.d.ts.map +1 -1
- package/lib/node/events/parse.js +14 -14
- package/lib/node/events/types.d.ts +3 -5
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/events/types.js +1 -1
- package/lib/node/idl/{drift.d.ts → velocity.d.ts} +1043 -768
- package/lib/node/idl/velocity.d.ts.map +1 -0
- package/lib/node/idl/{drift.json → velocity.json} +1033 -758
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -2
- package/lib/node/math/amm.d.ts +10 -10
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +29 -28
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +16 -12
- 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 +26 -26
- package/lib/node/math/margin.d.ts +4 -4
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +15 -15
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +13 -13
- package/lib/node/math/oracles.d.ts +4 -4
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +23 -23
- package/lib/node/math/orders.d.ts +2 -2
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +9 -9
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +4 -4
- package/lib/node/math/superStake.d.ts +8 -10
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +18 -20
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +5 -5
- package/lib/node/math/utils.d.ts +1 -1
- package/lib/node/math/utils.js +1 -1
- package/lib/node/oracles/pythLazerClient.js +2 -2
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +0 -2
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +8 -12
- 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/priorityFeeSubscriber.d.ts +1 -5
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +7 -15
- 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/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/swap/UnifiedSwapClient.js +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +4 -5
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +2 -6
- package/lib/node/swift/swiftOrderSubscriber.d.ts +6 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +5 -11
- package/lib/node/types.d.ts +79 -91
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +4 -0
- package/lib/node/user.d.ts +1 -3
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +19 -23
- package/lib/node/userConfig.d.ts +3 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/WebsocketSubscription.js +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 +0 -4
- 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 +0 -4
- package/lib/node/userMap/userMap.d.ts +2 -4
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +10 -14
- 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 +0 -2
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +0 -4
- package/lib/node/userStats.d.ts +0 -2
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +10 -14
- package/lib/node/userStatsConfig.d.ts +3 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- package/lib/node/util/ed25519Utils.d.ts +1 -1
- package/lib/node/util/ed25519Utils.js +1 -1
- package/lib/node/velocityClient.d.ts +53 -38
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +258 -196
- package/lib/node/velocityClientConfig.d.ts +0 -8
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +6 -7
- 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/grpcProgramAccountSubscriber.ts +1 -1
- package/src/accounts/grpcVelocityClientAccountSubscriber.ts +0 -7
- package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +4 -11
- package/src/accounts/laserProgramAccountSubscriber.ts +1 -1
- package/src/accounts/pollingVelocityClientAccountSubscriber.ts +4 -11
- package/src/accounts/types.ts +2 -9
- package/src/accounts/utils.ts +2 -2
- package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +4 -11
- package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +4 -11
- package/src/addresses/pda.ts +3 -13
- package/src/adminClient.ts +21 -21
- package/src/auctionSubscriber/auctionSubscriber.ts +1 -6
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +1 -6
- package/src/auctionSubscriber/types.ts +3 -3
- package/src/config.ts +8 -67
- package/src/constants/insuranceFund.ts +1 -1
- package/src/constituentMap/constituentMap.ts +2 -6
- package/src/core/VelocityCore.ts +11 -20
- package/src/core/instructions/withdraw.ts +2 -2
- package/src/core/remainingAccounts.ts +3 -3
- package/src/dlob/DLOB.ts +6 -6
- package/src/dlob/DLOBSubscriber.ts +2 -8
- package/src/dlob/orderBookLevels.ts +12 -6
- package/src/dlob/types.ts +0 -2
- package/src/events/eventSubscriber.ts +1 -1
- package/src/events/eventsServerLogProvider.ts +2 -2
- package/src/events/parse.ts +14 -14
- package/src/events/types.ts +4 -7
- package/src/idl/{drift.json → velocity.json} +1033 -758
- package/src/idl/{drift.ts → velocity.ts} +1035 -760
- package/src/index.ts +1 -4
- package/src/margin/README.md +2 -2
- package/src/math/amm.ts +43 -21
- package/src/math/auction.ts +16 -12
- package/src/math/builder.ts +45 -1
- package/src/math/funding.ts +46 -43
- package/src/math/margin.ts +15 -15
- package/src/math/market.ts +21 -13
- package/src/math/oracles.ts +29 -26
- package/src/math/orders.ts +18 -5
- package/src/math/position.ts +9 -3
- package/src/math/superStake.ts +21 -24
- package/src/math/trade.ts +9 -1
- package/src/math/utils.ts +1 -1
- package/src/oracles/pythLazerClient.ts +3 -3
- package/src/orderSubscriber/OrderSubscriber.ts +2 -8
- package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
- package/src/orderSubscriber/grpcSubscription.ts +2 -2
- package/src/orderSubscriber/types.ts +0 -2
- package/src/priorityFee/priorityFeeSubscriber.ts +5 -12
- package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
- package/src/priorityFee/types.ts +3 -13
- package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
- package/src/pyth/pythLazerSubscriber.ts +1 -1
- package/src/swap/UnifiedSwapClient.ts +1 -1
- package/src/swift/signedMsgUserAccountSubscriber.ts +2 -8
- package/src/swift/swiftOrderSubscriber.ts +7 -12
- package/src/types.ts +84 -102
- package/src/user.ts +9 -14
- package/src/userConfig.ts +1 -3
- package/src/userMap/WebsocketSubscription.ts +1 -1
- package/src/userMap/grpcSubscription.ts +1 -1
- package/src/userMap/referrerMap.ts +0 -4
- package/src/userMap/revenueShareEscrowMap.ts +0 -4
- package/src/userMap/userMap.ts +3 -7
- package/src/userMap/userMapConfig.ts +3 -3
- package/src/userMap/userStatsMap.ts +0 -4
- package/src/userStats.ts +1 -5
- package/src/userStatsConfig.ts +3 -3
- package/src/util/ed25519Utils.ts +1 -1
- package/src/velocityClient.ts +339 -225
- 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/ci/verifyConstants.ts +24 -27
- package/tests/decode/test.ts +2 -2
- package/tests/dlob/helpers.ts +5 -9
- package/tests/events/parseLogsForCuUsage.ts +15 -15
- package/tests/user/helpers.ts +9 -9
- package/tests/user/test.ts +13 -10
- package/lib/browser/util/deprecatedAlias.d.ts +0 -26
- package/lib/browser/util/deprecatedAlias.js +0 -10
- package/lib/node/idl/drift.d.ts.map +0 -1
- 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/src/util/deprecatedAlias.ts +0 -21
- /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/src/math/market.ts
CHANGED
|
@@ -45,7 +45,11 @@ export function calculateReservePrice(
|
|
|
45
45
|
market: PerpMarketAccount,
|
|
46
46
|
mmOraclePriceData: MMOraclePriceData
|
|
47
47
|
): BN {
|
|
48
|
-
const newAmm = calculateUpdatedAMM(
|
|
48
|
+
const newAmm = calculateUpdatedAMM(
|
|
49
|
+
market.amm,
|
|
50
|
+
market.totalExchangeFee,
|
|
51
|
+
mmOraclePriceData
|
|
52
|
+
);
|
|
49
53
|
return calculatePrice(
|
|
50
54
|
newAmm.baseAssetReserve,
|
|
51
55
|
newAmm.quoteAssetReserve,
|
|
@@ -67,6 +71,8 @@ export function calculateBidPrice(
|
|
|
67
71
|
const { baseAssetReserve, quoteAssetReserve, newPeg } =
|
|
68
72
|
calculateUpdatedAMMSpreadReserves(
|
|
69
73
|
market.amm,
|
|
74
|
+
market.marketStats,
|
|
75
|
+
market.totalExchangeFee,
|
|
70
76
|
PositionDirection.SHORT,
|
|
71
77
|
mmOraclePriceData,
|
|
72
78
|
latestSlot
|
|
@@ -89,6 +95,8 @@ export function calculateAskPrice(
|
|
|
89
95
|
const { baseAssetReserve, quoteAssetReserve, newPeg } =
|
|
90
96
|
calculateUpdatedAMMSpreadReserves(
|
|
91
97
|
market.amm,
|
|
98
|
+
market.marketStats,
|
|
99
|
+
market.totalExchangeFee,
|
|
92
100
|
PositionDirection.LONG,
|
|
93
101
|
mmOraclePriceData,
|
|
94
102
|
latestSlot
|
|
@@ -251,8 +259,8 @@ export function calculateNetUserPnl(
|
|
|
251
259
|
.div(BASE_PRECISION)
|
|
252
260
|
.div(PRICE_TO_QUOTE_PRECISION);
|
|
253
261
|
|
|
254
|
-
const netUserCostBasis = perpMarket.
|
|
255
|
-
perpMarket.
|
|
262
|
+
const netUserCostBasis = perpMarket.quoteAssetAmount.add(
|
|
263
|
+
perpMarket.netUnsettledFundingPnl
|
|
256
264
|
);
|
|
257
265
|
|
|
258
266
|
const netUserPnl = netUserPositionValue.add(netUserCostBasis);
|
|
@@ -297,7 +305,7 @@ export function calculateAvailablePerpLiquidity(
|
|
|
297
305
|
market.amm.baseAssetReserve,
|
|
298
306
|
market.amm.minBaseAssetReserve,
|
|
299
307
|
market.amm.maxBaseAssetReserve,
|
|
300
|
-
market.
|
|
308
|
+
market.orderStepSize
|
|
301
309
|
);
|
|
302
310
|
|
|
303
311
|
asks = asks.abs();
|
|
@@ -358,9 +366,9 @@ export function getTriggerPrice(
|
|
|
358
366
|
const lastFillPrice = market.lastFillPrice;
|
|
359
367
|
|
|
360
368
|
// Calculate 5-minute basis
|
|
361
|
-
const markPrice5minTwap = market.
|
|
369
|
+
const markPrice5minTwap = market.marketStats.lastMarkPriceTwap5Min;
|
|
362
370
|
const lastOraclePriceTwap5min =
|
|
363
|
-
market.
|
|
371
|
+
market.marketStats.historicalOracleData.lastOraclePriceTwap5Min;
|
|
364
372
|
const basis5min = markPrice5minTwap.sub(lastOraclePriceTwap5min);
|
|
365
373
|
|
|
366
374
|
const oraclePlusBasis5min = oraclePrice.add(basis5min);
|
|
@@ -388,23 +396,23 @@ function getLastFundingBasis(
|
|
|
388
396
|
oraclePrice: BN,
|
|
389
397
|
now: BN
|
|
390
398
|
): BN {
|
|
391
|
-
if (market.
|
|
392
|
-
const lastFundingRate = market.
|
|
399
|
+
if (market.lastFundingOracleTwap.gt(ZERO)) {
|
|
400
|
+
const lastFundingRate = market.lastFundingRate
|
|
393
401
|
.mul(PRICE_PRECISION)
|
|
394
|
-
.div(market.
|
|
402
|
+
.div(market.lastFundingOracleTwap)
|
|
395
403
|
.muln(24);
|
|
396
404
|
const lastFundingRatePreAdj = lastFundingRate.sub(
|
|
397
405
|
FUNDING_RATE_PRECISION.div(new BN(3333)) // FUNDING_RATE_OFFSET_PERCENTAGE
|
|
398
406
|
);
|
|
399
407
|
const timeLeftUntilFundingUpdate = BN.min(
|
|
400
|
-
BN.max(now.sub(market.
|
|
401
|
-
market.
|
|
408
|
+
BN.max(now.sub(market.lastFundingRateTs), ZERO),
|
|
409
|
+
market.marketStats.fundingPeriod
|
|
402
410
|
);
|
|
403
411
|
const lastFundingBasis = oraclePrice
|
|
404
412
|
.mul(lastFundingRatePreAdj)
|
|
405
413
|
.div(PERCENTAGE_PRECISION)
|
|
406
|
-
.mul(market.
|
|
407
|
-
.div(market.
|
|
414
|
+
.mul(market.marketStats.fundingPeriod.sub(timeLeftUntilFundingUpdate))
|
|
415
|
+
.div(market.marketStats.fundingPeriod)
|
|
408
416
|
.div(new BN(1000)); // FUNDING_RATE_BUFFER
|
|
409
417
|
return lastFundingBasis;
|
|
410
418
|
} else {
|
package/src/math/oracles.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AMM,
|
|
3
2
|
HistoricalOracleData,
|
|
3
|
+
MarketStats,
|
|
4
4
|
OracleGuardRails,
|
|
5
5
|
OracleSource,
|
|
6
6
|
OracleValidity,
|
|
@@ -64,14 +64,14 @@ export function getOracleValidity(
|
|
|
64
64
|
const isNonPositive = oraclePriceData.price.lte(ZERO);
|
|
65
65
|
const isTooVolatile = BN.max(
|
|
66
66
|
oraclePriceData.price,
|
|
67
|
-
market.
|
|
67
|
+
market.marketStats.historicalOracleData.lastOraclePriceTwap
|
|
68
68
|
)
|
|
69
69
|
.div(
|
|
70
70
|
BN.max(
|
|
71
71
|
ONE,
|
|
72
72
|
BN.min(
|
|
73
73
|
oraclePriceData.price,
|
|
74
|
-
market.
|
|
74
|
+
market.marketStats.historicalOracleData.lastOraclePriceTwap
|
|
75
75
|
)
|
|
76
76
|
)
|
|
77
77
|
)
|
|
@@ -89,16 +89,16 @@ export function getOracleValidity(
|
|
|
89
89
|
const oracleDelay = slot.sub(oraclePriceData.slot).sub(oracleStalenessBuffer);
|
|
90
90
|
|
|
91
91
|
let isStaleForAmmImmediate = true;
|
|
92
|
-
if (market.
|
|
92
|
+
if (market.oracleSlotDelayOverride != 0) {
|
|
93
93
|
isStaleForAmmImmediate = oracleDelay.gt(
|
|
94
|
-
BN.max(new BN(market.
|
|
94
|
+
BN.max(new BN(market.oracleSlotDelayOverride), ZERO)
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
let isStaleForAmmLowRisk = false;
|
|
99
|
-
if (market.
|
|
99
|
+
if (market.oracleLowRiskSlotDelayOverride != 0) {
|
|
100
100
|
isStaleForAmmLowRisk = oracleDelay.gt(
|
|
101
|
-
BN.max(new BN(market.
|
|
101
|
+
BN.max(new BN(market.oracleLowRiskSlotDelayOverride), ZERO)
|
|
102
102
|
);
|
|
103
103
|
} else {
|
|
104
104
|
isStaleForAmmLowRisk = oracleDelay.gt(
|
|
@@ -109,7 +109,7 @@ export function getOracleValidity(
|
|
|
109
109
|
let isStaleForMargin = oracleDelay.gt(
|
|
110
110
|
new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin)
|
|
111
111
|
);
|
|
112
|
-
if (isVariant(market.
|
|
112
|
+
if (isVariant(market.oracleSource, 'pythLazerStableCoin')) {
|
|
113
113
|
isStaleForMargin = oracleDelay.gt(
|
|
114
114
|
new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin).muln(3)
|
|
115
115
|
);
|
|
@@ -142,13 +142,13 @@ export function isOracleValid(
|
|
|
142
142
|
): boolean {
|
|
143
143
|
// checks if oracle is valid for an AMM only fill
|
|
144
144
|
|
|
145
|
-
const
|
|
145
|
+
const stats = market.marketStats;
|
|
146
146
|
const isOraclePriceNonPositive = oraclePriceData.price.lte(ZERO);
|
|
147
147
|
const isOraclePriceTooVolatile =
|
|
148
148
|
oraclePriceData.price
|
|
149
|
-
.div(BN.max(ONE,
|
|
149
|
+
.div(BN.max(ONE, stats.historicalOracleData.lastOraclePriceTwap))
|
|
150
150
|
.gt(oracleGuardRails.validity.tooVolatileRatio) ||
|
|
151
|
-
|
|
151
|
+
stats.historicalOracleData.lastOraclePriceTwap
|
|
152
152
|
.div(BN.max(ONE, oraclePriceData.price))
|
|
153
153
|
.gt(oracleGuardRails.validity.tooVolatileRatio);
|
|
154
154
|
|
|
@@ -177,14 +177,14 @@ export function isOracleValid(
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
export function isOracleTooDivergent(
|
|
180
|
-
|
|
180
|
+
marketStats: MarketStats,
|
|
181
181
|
oraclePriceData: OraclePriceData,
|
|
182
182
|
oracleGuardRails: OracleGuardRails
|
|
183
183
|
): boolean {
|
|
184
184
|
const oracleSpreadPct = oraclePriceData.price
|
|
185
|
-
.sub(
|
|
185
|
+
.sub(marketStats.historicalOracleData.lastOraclePriceTwap5Min)
|
|
186
186
|
.mul(PERCENTAGE_PRECISION)
|
|
187
|
-
.div(
|
|
187
|
+
.div(marketStats.historicalOracleData.lastOraclePriceTwap5Min);
|
|
188
188
|
const maxDivergence = BN.max(
|
|
189
189
|
oracleGuardRails.priceDivergence.oracleTwap5MinPercentDivergence,
|
|
190
190
|
PERCENTAGE_PRECISION.div(new BN(2))
|
|
@@ -230,25 +230,28 @@ export function calculateLiveOracleTwap(
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
export function calculateLiveOracleStd(
|
|
233
|
-
|
|
233
|
+
marketStats: MarketStats,
|
|
234
234
|
oraclePriceData: OraclePriceData,
|
|
235
235
|
now: BN
|
|
236
236
|
): BN {
|
|
237
237
|
const sinceLastUpdate = BN.max(
|
|
238
238
|
ONE,
|
|
239
|
-
now.sub(
|
|
239
|
+
now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs)
|
|
240
|
+
);
|
|
241
|
+
const sinceStart = BN.max(
|
|
242
|
+
ZERO,
|
|
243
|
+
marketStats.fundingPeriod.sub(sinceLastUpdate)
|
|
240
244
|
);
|
|
241
|
-
const sinceStart = BN.max(ZERO, amm.fundingPeriod.sub(sinceLastUpdate));
|
|
242
245
|
|
|
243
246
|
const liveOracleTwap = calculateLiveOracleTwap(
|
|
244
|
-
|
|
247
|
+
marketStats.historicalOracleData,
|
|
245
248
|
oraclePriceData,
|
|
246
249
|
now,
|
|
247
|
-
|
|
250
|
+
marketStats.fundingPeriod
|
|
248
251
|
);
|
|
249
252
|
|
|
250
253
|
const liveOracleTwap5MIN = calculateLiveOracleTwap(
|
|
251
|
-
|
|
254
|
+
marketStats.historicalOracleData,
|
|
252
255
|
oraclePriceData,
|
|
253
256
|
now,
|
|
254
257
|
FIVE_MINUTE
|
|
@@ -260,14 +263,14 @@ export function calculateLiveOracleStd(
|
|
|
260
263
|
);
|
|
261
264
|
|
|
262
265
|
const oracleStd = priceDeltaVsTwap.add(
|
|
263
|
-
|
|
266
|
+
marketStats.oracleStd.mul(sinceStart).div(sinceStart.add(sinceLastUpdate))
|
|
264
267
|
);
|
|
265
268
|
|
|
266
269
|
return oracleStd;
|
|
267
270
|
}
|
|
268
271
|
|
|
269
272
|
export function getNewOracleConfPct(
|
|
270
|
-
|
|
273
|
+
marketStats: MarketStats,
|
|
271
274
|
oraclePriceData: OraclePriceData,
|
|
272
275
|
reservePrice: BN,
|
|
273
276
|
now: BN
|
|
@@ -276,16 +279,16 @@ export function getNewOracleConfPct(
|
|
|
276
279
|
|
|
277
280
|
const sinceLastUpdate = BN.max(
|
|
278
281
|
ZERO,
|
|
279
|
-
now.sub(
|
|
282
|
+
now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs)
|
|
280
283
|
);
|
|
281
|
-
let lowerBoundConfPct =
|
|
284
|
+
let lowerBoundConfPct = marketStats.lastOracleConfPct;
|
|
282
285
|
if (sinceLastUpdate.gt(ZERO)) {
|
|
283
286
|
const lowerBoundConfDivisor = BN.max(
|
|
284
287
|
new BN(21).sub(sinceLastUpdate),
|
|
285
288
|
new BN(5)
|
|
286
289
|
);
|
|
287
|
-
lowerBoundConfPct =
|
|
288
|
-
|
|
290
|
+
lowerBoundConfPct = marketStats.lastOracleConfPct.sub(
|
|
291
|
+
marketStats.lastOracleConfPct.div(lowerBoundConfDivisor)
|
|
289
292
|
);
|
|
290
293
|
}
|
|
291
294
|
const confIntervalPct = confInterval
|
package/src/math/orders.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
isVariant,
|
|
5
5
|
PerpMarketAccount,
|
|
6
6
|
AMM,
|
|
7
|
+
MarketStats,
|
|
7
8
|
Order,
|
|
8
9
|
PositionDirection,
|
|
9
10
|
MarketTypeStr,
|
|
@@ -251,11 +252,18 @@ export function calculateBaseAssetAmountForAmmToFulfill(
|
|
|
251
252
|
const limitPrice = getLimitPrice(order, mmOraclePriceData, slot);
|
|
252
253
|
let baseAssetAmount;
|
|
253
254
|
|
|
254
|
-
const updatedAMM = calculateUpdatedAMM(
|
|
255
|
+
const updatedAMM = calculateUpdatedAMM(
|
|
256
|
+
market.amm,
|
|
257
|
+
market.totalExchangeFee,
|
|
258
|
+
mmOraclePriceData
|
|
259
|
+
);
|
|
255
260
|
if (limitPrice !== undefined) {
|
|
256
261
|
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(
|
|
257
262
|
order,
|
|
258
263
|
updatedAMM,
|
|
264
|
+
market.marketStats,
|
|
265
|
+
market.orderStepSize,
|
|
266
|
+
market.orderTickSize,
|
|
259
267
|
limitPrice,
|
|
260
268
|
mmOraclePriceData
|
|
261
269
|
);
|
|
@@ -265,6 +273,7 @@ export function calculateBaseAssetAmountForAmmToFulfill(
|
|
|
265
273
|
|
|
266
274
|
const maxBaseAssetAmount = calculateMaxBaseAssetAmountFillable(
|
|
267
275
|
updatedAMM,
|
|
276
|
+
market.orderStepSize,
|
|
268
277
|
order.direction
|
|
269
278
|
);
|
|
270
279
|
|
|
@@ -274,15 +283,19 @@ export function calculateBaseAssetAmountForAmmToFulfill(
|
|
|
274
283
|
export function calculateBaseAssetAmountToFillUpToLimitPrice(
|
|
275
284
|
order: Order,
|
|
276
285
|
amm: AMM,
|
|
286
|
+
marketStats: MarketStats,
|
|
287
|
+
orderStepSize: BN,
|
|
288
|
+
orderTickSize: BN,
|
|
277
289
|
limitPrice: BN,
|
|
278
290
|
mmOraclePriceData: MMOraclePriceData
|
|
279
291
|
): BN {
|
|
280
292
|
const adjustedLimitPrice = isVariant(order.direction, 'long')
|
|
281
|
-
? limitPrice.sub(
|
|
282
|
-
: limitPrice.add(
|
|
293
|
+
? limitPrice.sub(orderTickSize)
|
|
294
|
+
: limitPrice.add(orderTickSize);
|
|
283
295
|
|
|
284
296
|
const [maxAmountToTrade, direction] = calculateMaxBaseAssetAmountToTrade(
|
|
285
297
|
amm,
|
|
298
|
+
marketStats,
|
|
286
299
|
adjustedLimitPrice,
|
|
287
300
|
order.direction,
|
|
288
301
|
mmOraclePriceData
|
|
@@ -290,7 +303,7 @@ export function calculateBaseAssetAmountToFillUpToLimitPrice(
|
|
|
290
303
|
|
|
291
304
|
const baseAssetAmount = standardizeBaseAssetAmount(
|
|
292
305
|
maxAmountToTrade,
|
|
293
|
-
|
|
306
|
+
orderStepSize
|
|
294
307
|
);
|
|
295
308
|
|
|
296
309
|
// Check that directions are the same
|
|
@@ -461,7 +474,7 @@ export function maxSizeForTargetLiabilityWeightBN(
|
|
|
461
474
|
}
|
|
462
475
|
|
|
463
476
|
// cap at max OI
|
|
464
|
-
const maxOpenInterest = market.
|
|
477
|
+
const maxOpenInterest = market.maxOpenInterest;
|
|
465
478
|
if (lo.gt(maxOpenInterest)) {
|
|
466
479
|
return maxOpenInterest;
|
|
467
480
|
}
|
package/src/math/position.ts
CHANGED
|
@@ -53,6 +53,8 @@ export function calculateBaseAssetValue(
|
|
|
53
53
|
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
|
|
54
54
|
calculateUpdatedAMMSpreadReserves(
|
|
55
55
|
market.amm,
|
|
56
|
+
market.marketStats,
|
|
57
|
+
market.totalExchangeFee,
|
|
56
58
|
directionToClose,
|
|
57
59
|
mmOraclePriceData,
|
|
58
60
|
latestSlot
|
|
@@ -64,7 +66,11 @@ export function calculateBaseAssetValue(
|
|
|
64
66
|
pegMultiplier: newPeg,
|
|
65
67
|
};
|
|
66
68
|
} else {
|
|
67
|
-
prepegAmm = calculateUpdatedAMM(
|
|
69
|
+
prepegAmm = calculateUpdatedAMM(
|
|
70
|
+
market.amm,
|
|
71
|
+
market.totalExchangeFee,
|
|
72
|
+
mmOraclePriceData
|
|
73
|
+
);
|
|
68
74
|
}
|
|
69
75
|
} else {
|
|
70
76
|
prepegAmm = market.amm;
|
|
@@ -213,9 +219,9 @@ export function calculateUnsettledFundingPnl(
|
|
|
213
219
|
|
|
214
220
|
let ammCumulativeFundingRate: BN;
|
|
215
221
|
if (perpPosition.baseAssetAmount.gt(ZERO)) {
|
|
216
|
-
ammCumulativeFundingRate = market.
|
|
222
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateLong;
|
|
217
223
|
} else {
|
|
218
|
-
ammCumulativeFundingRate = market.
|
|
224
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateShort;
|
|
219
225
|
}
|
|
220
226
|
|
|
221
227
|
const perPositionFundingRate = ammCumulativeFundingRate
|
package/src/math/superStake.ts
CHANGED
|
@@ -43,17 +43,14 @@ export async function fetchBSolMetrics() {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export async function fetchBSolVelocityEmissions() {
|
|
46
|
-
return await fetch('https://stake.solblaze.org/api/v1/
|
|
46
|
+
return await fetch('https://stake.solblaze.org/api/v1/velocity_emissions');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/** @deprecated Use `fetchBSolVelocityEmissions` instead. `fetchBSolDriftEmissions` will be removed in a future major. */
|
|
50
|
-
export const fetchBSolDriftEmissions = fetchBSolVelocityEmissions;
|
|
51
|
-
|
|
52
49
|
export async function findBestSuperStakeIxs({
|
|
53
50
|
marketIndex,
|
|
54
51
|
amount,
|
|
55
52
|
jupiterClient,
|
|
56
|
-
|
|
53
|
+
velocityClient,
|
|
57
54
|
userAccountPublicKey,
|
|
58
55
|
price,
|
|
59
56
|
forceMarinade,
|
|
@@ -63,7 +60,7 @@ export async function findBestSuperStakeIxs({
|
|
|
63
60
|
marketIndex: number;
|
|
64
61
|
amount: BN;
|
|
65
62
|
jupiterClient: JupiterClient;
|
|
66
|
-
|
|
63
|
+
velocityClient: VelocityClient;
|
|
67
64
|
price?: number;
|
|
68
65
|
userAccountPublicKey?: PublicKey;
|
|
69
66
|
forceMarinade?: boolean;
|
|
@@ -79,7 +76,7 @@ export async function findBestSuperStakeIxs({
|
|
|
79
76
|
return findBestMSolSuperStakeIxs({
|
|
80
77
|
amount,
|
|
81
78
|
jupiterClient,
|
|
82
|
-
|
|
79
|
+
velocityClient,
|
|
83
80
|
userAccountPublicKey,
|
|
84
81
|
price,
|
|
85
82
|
forceMarinade,
|
|
@@ -90,7 +87,7 @@ export async function findBestSuperStakeIxs({
|
|
|
90
87
|
return findBestJitoSolSuperStakeIxs({
|
|
91
88
|
amount,
|
|
92
89
|
jupiterClient,
|
|
93
|
-
|
|
90
|
+
velocityClient,
|
|
94
91
|
userAccountPublicKey,
|
|
95
92
|
onlyDirectRoutes,
|
|
96
93
|
jupiterQuote,
|
|
@@ -98,10 +95,10 @@ export async function findBestSuperStakeIxs({
|
|
|
98
95
|
} else if (marketIndex === 8) {
|
|
99
96
|
return findBestLstSuperStakeIxs({
|
|
100
97
|
amount,
|
|
101
|
-
lstMint:
|
|
98
|
+
lstMint: velocityClient.getSpotMarketAccount(8).mint,
|
|
102
99
|
lstMarketIndex: 8,
|
|
103
100
|
jupiterClient,
|
|
104
|
-
|
|
101
|
+
velocityClient,
|
|
105
102
|
userAccountPublicKey,
|
|
106
103
|
onlyDirectRoutes,
|
|
107
104
|
jupiterQuote,
|
|
@@ -114,7 +111,7 @@ export async function findBestSuperStakeIxs({
|
|
|
114
111
|
export async function findBestMSolSuperStakeIxs({
|
|
115
112
|
amount,
|
|
116
113
|
jupiterClient,
|
|
117
|
-
|
|
114
|
+
velocityClient,
|
|
118
115
|
userAccountPublicKey,
|
|
119
116
|
price,
|
|
120
117
|
forceMarinade,
|
|
@@ -123,7 +120,7 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
123
120
|
}: {
|
|
124
121
|
amount: BN;
|
|
125
122
|
jupiterClient: JupiterClient;
|
|
126
|
-
|
|
123
|
+
velocityClient: VelocityClient;
|
|
127
124
|
price?: number;
|
|
128
125
|
userAccountPublicKey?: PublicKey;
|
|
129
126
|
forceMarinade?: boolean;
|
|
@@ -136,12 +133,12 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
136
133
|
price: number;
|
|
137
134
|
}> {
|
|
138
135
|
if (!price) {
|
|
139
|
-
const marinadeProgram = getMarinadeFinanceProgram(
|
|
136
|
+
const marinadeProgram = getMarinadeFinanceProgram(velocityClient.provider);
|
|
140
137
|
price = await getMarinadeMSolPrice(marinadeProgram);
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
const solSpotMarketAccount =
|
|
144
|
-
const mSolSpotMarketAccount =
|
|
140
|
+
const solSpotMarketAccount = velocityClient.getSpotMarketAccount(1);
|
|
141
|
+
const mSolSpotMarketAccount = velocityClient.getSpotMarketAccount(2);
|
|
145
142
|
|
|
146
143
|
let jupiterPrice: number;
|
|
147
144
|
let quote = jupiterQuote;
|
|
@@ -164,7 +161,7 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
if (!jupiterPrice || price <= jupiterPrice || forceMarinade) {
|
|
167
|
-
const ixs = await
|
|
164
|
+
const ixs = await velocityClient.getStakeForMSOLIx({
|
|
168
165
|
amount,
|
|
169
166
|
userAccountPublicKey,
|
|
170
167
|
});
|
|
@@ -175,7 +172,7 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
175
172
|
price: price,
|
|
176
173
|
};
|
|
177
174
|
} else {
|
|
178
|
-
const { ixs, lookupTables } = await
|
|
175
|
+
const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
|
|
179
176
|
inMarketIndex: 1,
|
|
180
177
|
outMarketIndex: 2,
|
|
181
178
|
jupiterClient,
|
|
@@ -196,14 +193,14 @@ export async function findBestMSolSuperStakeIxs({
|
|
|
196
193
|
export async function findBestJitoSolSuperStakeIxs({
|
|
197
194
|
amount,
|
|
198
195
|
jupiterClient,
|
|
199
|
-
|
|
196
|
+
velocityClient,
|
|
200
197
|
userAccountPublicKey,
|
|
201
198
|
onlyDirectRoutes,
|
|
202
199
|
jupiterQuote,
|
|
203
200
|
}: {
|
|
204
201
|
amount: BN;
|
|
205
202
|
jupiterClient: JupiterClient;
|
|
206
|
-
|
|
203
|
+
velocityClient: VelocityClient;
|
|
207
204
|
userAccountPublicKey?: PublicKey;
|
|
208
205
|
onlyDirectRoutes?: boolean;
|
|
209
206
|
jupiterQuote?: QuoteResponse;
|
|
@@ -216,10 +213,10 @@ export async function findBestJitoSolSuperStakeIxs({
|
|
|
216
213
|
return await findBestLstSuperStakeIxs({
|
|
217
214
|
amount,
|
|
218
215
|
jupiterClient,
|
|
219
|
-
|
|
216
|
+
velocityClient,
|
|
220
217
|
userAccountPublicKey,
|
|
221
218
|
onlyDirectRoutes,
|
|
222
|
-
lstMint:
|
|
219
|
+
lstMint: velocityClient.getSpotMarketAccount(6).mint,
|
|
223
220
|
lstMarketIndex: 6,
|
|
224
221
|
jupiterQuote,
|
|
225
222
|
});
|
|
@@ -233,7 +230,7 @@ export async function findBestJitoSolSuperStakeIxs({
|
|
|
233
230
|
export async function findBestLstSuperStakeIxs({
|
|
234
231
|
amount,
|
|
235
232
|
jupiterClient,
|
|
236
|
-
|
|
233
|
+
velocityClient,
|
|
237
234
|
userAccountPublicKey,
|
|
238
235
|
onlyDirectRoutes,
|
|
239
236
|
lstMarketIndex,
|
|
@@ -243,7 +240,7 @@ export async function findBestLstSuperStakeIxs({
|
|
|
243
240
|
lstMint: PublicKey;
|
|
244
241
|
lstMarketIndex: number;
|
|
245
242
|
jupiterClient: JupiterClient;
|
|
246
|
-
|
|
243
|
+
velocityClient: VelocityClient;
|
|
247
244
|
userAccountPublicKey?: PublicKey;
|
|
248
245
|
onlyDirectRoutes?: boolean;
|
|
249
246
|
jupiterQuote?: QuoteResponse;
|
|
@@ -252,7 +249,7 @@ export async function findBestLstSuperStakeIxs({
|
|
|
252
249
|
lookupTables: AddressLookupTableAccount[];
|
|
253
250
|
method: 'jupiter' | 'marinade';
|
|
254
251
|
}> {
|
|
255
|
-
const { ixs, lookupTables } = await
|
|
252
|
+
const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
|
|
256
253
|
inMarketIndex: 1,
|
|
257
254
|
outMarketIndex: lstMarketIndex,
|
|
258
255
|
jupiterClient,
|
package/src/math/trade.ts
CHANGED
|
@@ -113,6 +113,8 @@ export function calculateTradeSlippage(
|
|
|
113
113
|
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
|
|
114
114
|
calculateUpdatedAMMSpreadReserves(
|
|
115
115
|
market.amm,
|
|
116
|
+
market.marketStats,
|
|
117
|
+
market.totalExchangeFee,
|
|
116
118
|
direction,
|
|
117
119
|
mmOraclePriceData,
|
|
118
120
|
latestSlot
|
|
@@ -184,6 +186,8 @@ export function calculateTradeAcquiredAmounts(
|
|
|
184
186
|
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
|
|
185
187
|
calculateUpdatedAMMSpreadReserves(
|
|
186
188
|
market.amm,
|
|
189
|
+
market.marketStats,
|
|
190
|
+
market.totalExchangeFee,
|
|
187
191
|
direction,
|
|
188
192
|
mmOraclePriceData,
|
|
189
193
|
latestSlot
|
|
@@ -274,6 +278,8 @@ export function calculateTargetPriceTrade(
|
|
|
274
278
|
const { baseAssetReserve, quoteAssetReserve, newPeg } =
|
|
275
279
|
calculateUpdatedAMMSpreadReserves(
|
|
276
280
|
market.amm,
|
|
281
|
+
market.marketStats,
|
|
282
|
+
market.totalExchangeFee,
|
|
277
283
|
direction,
|
|
278
284
|
mmOraclePriceData,
|
|
279
285
|
latestSlot
|
|
@@ -436,6 +442,8 @@ export function calculateEstimatedPerpEntryPrice(
|
|
|
436
442
|
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
|
|
437
443
|
calculateUpdatedAMMSpreadReserves(
|
|
438
444
|
market.amm,
|
|
445
|
+
market.marketStats,
|
|
446
|
+
market.totalExchangeFee,
|
|
439
447
|
direction,
|
|
440
448
|
mmOraclePriceData,
|
|
441
449
|
new BN(slot)
|
|
@@ -451,7 +459,7 @@ export function calculateEstimatedPerpEntryPrice(
|
|
|
451
459
|
market.amm.baseAssetReserve,
|
|
452
460
|
market.amm.minBaseAssetReserve,
|
|
453
461
|
market.amm.maxBaseAssetReserve,
|
|
454
|
-
market.
|
|
462
|
+
market.orderStepSize
|
|
455
463
|
);
|
|
456
464
|
|
|
457
465
|
let ammLiquidity: BN;
|
package/src/math/utils.ts
CHANGED
|
@@ -104,7 +104,7 @@ export function isBNSafe(number: number): boolean {
|
|
|
104
104
|
/**
|
|
105
105
|
* Converts a number to BN makes sure the number is safe to convert to BN (that it does not overflow number after multiplying by precision)
|
|
106
106
|
* @param number the number to convert to BN
|
|
107
|
-
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from
|
|
107
|
+
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from velocity sdk)
|
|
108
108
|
*/
|
|
109
109
|
export function numberToSafeBN(number: number, precision: BN): BN {
|
|
110
110
|
// check if number has decimals
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { OracleClient, OraclePriceData } from './types';
|
|
3
3
|
import { AnchorProvider, BN, Program } from '../isomorphic/anchor';
|
|
4
|
-
import {
|
|
4
|
+
import { Velocity } from '../idl/velocity';
|
|
5
5
|
import { VelocityProgram } from '../config';
|
|
6
6
|
import {
|
|
7
7
|
ONE,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
TEN,
|
|
11
11
|
} from '../constants/numericConstants';
|
|
12
12
|
import { Wallet } from '../wallet';
|
|
13
|
-
import
|
|
13
|
+
import velocityIDL from '../idl/velocity.json';
|
|
14
14
|
|
|
15
15
|
export class PythLazerClient implements OracleClient {
|
|
16
16
|
private connection: Connection;
|
|
@@ -35,7 +35,7 @@ export class PythLazerClient implements OracleClient {
|
|
|
35
35
|
commitment: connection.commitment,
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
|
-
this.program = new Program<
|
|
38
|
+
this.program = new Program<Velocity>(velocityIDL as Velocity, provider);
|
|
39
39
|
this.decodeFunc = (
|
|
40
40
|
this.program.account as any
|
|
41
41
|
).pythLazerOracle.coder.accounts.decodeUnchecked.bind(
|
|
@@ -21,10 +21,6 @@ import { ZERO } from '../constants/numericConstants';
|
|
|
21
21
|
|
|
22
22
|
export class OrderSubscriber {
|
|
23
23
|
velocityClient: VelocityClient;
|
|
24
|
-
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
25
|
-
public get driftClient(): VelocityClient {
|
|
26
|
-
return this.velocityClient;
|
|
27
|
-
}
|
|
28
24
|
usersAccounts = new Map<string, { slot: number; userAccount: UserAccount }>();
|
|
29
25
|
subscription: PollingSubscription | WebsocketSubscription | grpcSubscription;
|
|
30
26
|
commitment: Commitment;
|
|
@@ -40,11 +36,9 @@ export class OrderSubscriber {
|
|
|
40
36
|
fetchAllNonIdleUsers?: boolean;
|
|
41
37
|
|
|
42
38
|
constructor(config: OrderSubscriberConfig) {
|
|
43
|
-
const velocityClient = config.velocityClient
|
|
39
|
+
const velocityClient = config.velocityClient;
|
|
44
40
|
if (!velocityClient) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
'OrderSubscriber: velocityClient (or deprecated driftClient) must be provided'
|
|
47
|
-
);
|
|
41
|
+
throw new Error('OrderSubscriber: velocityClient must be provided');
|
|
48
42
|
}
|
|
49
43
|
this.velocityClient = velocityClient;
|
|
50
44
|
this.commitment = config.subscriptionConfig.commitment || 'processed';
|
|
@@ -48,7 +48,7 @@ export class WebsocketSubscription {
|
|
|
48
48
|
this.subscriber = new WebSocketProgramAccountSubscriber<UserAccount>(
|
|
49
49
|
'OrderSubscriber',
|
|
50
50
|
'user',
|
|
51
|
-
this.orderSubscriber.
|
|
51
|
+
this.orderSubscriber.velocityClient.program,
|
|
52
52
|
this.orderSubscriber.decodeFn,
|
|
53
53
|
{
|
|
54
54
|
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
@@ -56,7 +56,7 @@ export class grpcSubscription {
|
|
|
56
56
|
this.grpcConfigs,
|
|
57
57
|
'OrderSubscriber',
|
|
58
58
|
'user',
|
|
59
|
-
this.orderSubscriber.
|
|
59
|
+
this.orderSubscriber.velocityClient.program,
|
|
60
60
|
this.orderSubscriber.decodeFn,
|
|
61
61
|
{
|
|
62
62
|
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
@@ -68,7 +68,7 @@ export class grpcSubscription {
|
|
|
68
68
|
this.grpcConfigs,
|
|
69
69
|
'OrderSubscriber',
|
|
70
70
|
'user',
|
|
71
|
-
this.orderSubscriber.
|
|
71
|
+
this.orderSubscriber.velocityClient.program,
|
|
72
72
|
this.orderSubscriber.decodeFn,
|
|
73
73
|
{
|
|
74
74
|
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
@@ -5,8 +5,6 @@ import { GrpcConfigs } from '../accounts/types';
|
|
|
5
5
|
|
|
6
6
|
export type OrderSubscriberConfig = {
|
|
7
7
|
velocityClient?: VelocityClient;
|
|
8
|
-
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
9
|
-
driftClient?: VelocityClient;
|
|
10
8
|
subscriptionConfig:
|
|
11
9
|
| {
|
|
12
10
|
type: 'polling';
|