@velocity-exchange/sdk 0.0.3 → 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 +35 -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/decode/user.js +5 -5
- package/lib/browser/dlob/DLOB.d.ts +1 -1
- package/lib/browser/dlob/DLOB.js +7 -7
- package/lib/browser/dlob/DLOBNode.js +1 -2
- 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} +1043 -768
- package/lib/browser/idl/{drift.json → velocity.json} +1034 -759
- 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.d.ts +1 -1
- package/lib/browser/math/auction.js +18 -21
- 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 +12 -12
- 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 +81 -93
- 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 +59 -44
- package/lib/browser/velocityClient.js +259 -197
- 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/decode/user.js +5 -5
- 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 +7 -7
- package/lib/node/dlob/DLOBNode.js +1 -2
- 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} +1044 -769
- package/lib/node/idl/velocity.d.ts.map +1 -0
- package/lib/node/idl/{drift.json → velocity.json} +1034 -759
- 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 +1 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +18 -21
- 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 +12 -12
- 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 +81 -93
- 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 +59 -44
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +259 -197
- 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 -64
- 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/decode/user.ts +5 -5
- package/src/dlob/DLOB.ts +7 -7
- package/src/dlob/DLOBNode.ts +1 -1
- 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} +1034 -759
- package/src/idl/{drift.ts → velocity.ts} +1036 -761
- 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 +19 -22
- 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 +21 -11
- 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 +4 -9
- 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 +86 -104
- 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 +345 -231
- package/src/velocityClientConfig.ts +3 -11
- 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/auctions/test.ts +4 -4
- package/tests/ci/verifyConstants.ts +24 -27
- package/tests/decode/test.ts +3 -3
- package/tests/dlob/helpers.ts +5 -9
- package/tests/dlob/test.ts +5 -5
- package/tests/events/parseLogsForCuUsage.ts +15 -15
- package/tests/user/helpers.ts +10 -10
- 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 -25
- /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
|
@@ -15,7 +15,7 @@ const assert_1 = require("../assert/assert");
|
|
|
15
15
|
* @return markPrice : Precision PRICE_PRECISION
|
|
16
16
|
*/
|
|
17
17
|
function calculateReservePrice(market, mmOraclePriceData) {
|
|
18
|
-
const newAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
|
|
18
|
+
const newAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, market.totalExchangeFee, mmOraclePriceData);
|
|
19
19
|
return (0, amm_1.calculatePrice)(newAmm.baseAssetReserve, newAmm.quoteAssetReserve, newAmm.pegMultiplier);
|
|
20
20
|
}
|
|
21
21
|
exports.calculateReservePrice = calculateReservePrice;
|
|
@@ -26,7 +26,7 @@ exports.calculateReservePrice = calculateReservePrice;
|
|
|
26
26
|
* @return bidPrice : Precision PRICE_PRECISION
|
|
27
27
|
*/
|
|
28
28
|
function calculateBidPrice(market, mmOraclePriceData, latestSlot) {
|
|
29
|
-
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, types_1.PositionDirection.SHORT, mmOraclePriceData, latestSlot);
|
|
29
|
+
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, types_1.PositionDirection.SHORT, mmOraclePriceData, latestSlot);
|
|
30
30
|
return (0, amm_1.calculatePrice)(baseAssetReserve, quoteAssetReserve, newPeg);
|
|
31
31
|
}
|
|
32
32
|
exports.calculateBidPrice = calculateBidPrice;
|
|
@@ -37,7 +37,7 @@ exports.calculateBidPrice = calculateBidPrice;
|
|
|
37
37
|
* @return askPrice : Precision PRICE_PRECISION
|
|
38
38
|
*/
|
|
39
39
|
function calculateAskPrice(market, mmOraclePriceData, latestSlot) {
|
|
40
|
-
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, types_1.PositionDirection.LONG, mmOraclePriceData, latestSlot);
|
|
40
|
+
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, types_1.PositionDirection.LONG, mmOraclePriceData, latestSlot);
|
|
41
41
|
return (0, amm_1.calculatePrice)(baseAssetReserve, quoteAssetReserve, newPeg);
|
|
42
42
|
}
|
|
43
43
|
exports.calculateAskPrice = calculateAskPrice;
|
|
@@ -122,7 +122,7 @@ function calculateNetUserPnl(perpMarket, oraclePriceData) {
|
|
|
122
122
|
.mul(oraclePriceData.price)
|
|
123
123
|
.div(numericConstants_1.BASE_PRECISION)
|
|
124
124
|
.div(numericConstants_1.PRICE_TO_QUOTE_PRECISION);
|
|
125
|
-
const netUserCostBasis = perpMarket.
|
|
125
|
+
const netUserCostBasis = perpMarket.quoteAssetAmount.add(perpMarket.netUnsettledFundingPnl);
|
|
126
126
|
const netUserPnl = netUserPositionValue.add(netUserCostBasis);
|
|
127
127
|
return netUserPnl;
|
|
128
128
|
}
|
|
@@ -139,7 +139,7 @@ function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData, a
|
|
|
139
139
|
}
|
|
140
140
|
exports.calculateNetUserPnlImbalance = calculateNetUserPnlImbalance;
|
|
141
141
|
function calculateAvailablePerpLiquidity(market, mmOraclePriceData, dlob, slot) {
|
|
142
|
-
let [bids, asks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.
|
|
142
|
+
let [bids, asks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.orderStepSize);
|
|
143
143
|
asks = asks.abs();
|
|
144
144
|
for (const bid of dlob.getRestingLimitBids(market.marketIndex, slot, types_1.MarketType.PERP, mmOraclePriceData)) {
|
|
145
145
|
bids = bids.add(bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled));
|
|
@@ -172,8 +172,8 @@ function getTriggerPrice(market, oraclePrice, now, useMedianPrice) {
|
|
|
172
172
|
}
|
|
173
173
|
const lastFillPrice = market.lastFillPrice;
|
|
174
174
|
// Calculate 5-minute basis
|
|
175
|
-
const markPrice5minTwap = market.
|
|
176
|
-
const lastOraclePriceTwap5min = market.
|
|
175
|
+
const markPrice5minTwap = market.marketStats.lastMarkPriceTwap5Min;
|
|
176
|
+
const lastOraclePriceTwap5min = market.marketStats.historicalOracleData.lastOraclePriceTwap5Min;
|
|
177
177
|
const basis5min = markPrice5minTwap.sub(lastOraclePriceTwap5min);
|
|
178
178
|
const oraclePlusBasis5min = oraclePrice.add(basis5min);
|
|
179
179
|
// Calculate funding basis
|
|
@@ -193,19 +193,19 @@ exports.getTriggerPrice = getTriggerPrice;
|
|
|
193
193
|
* Implements the same logic as the Rust get_last_funding_basis function
|
|
194
194
|
*/
|
|
195
195
|
function getLastFundingBasis(market, oraclePrice, now) {
|
|
196
|
-
if (market.
|
|
197
|
-
const lastFundingRate = market.
|
|
196
|
+
if (market.lastFundingOracleTwap.gt(numericConstants_1.ZERO)) {
|
|
197
|
+
const lastFundingRate = market.lastFundingRate
|
|
198
198
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
199
|
-
.div(market.
|
|
199
|
+
.div(market.lastFundingOracleTwap)
|
|
200
200
|
.muln(24);
|
|
201
201
|
const lastFundingRatePreAdj = lastFundingRate.sub(numericConstants_1.FUNDING_RATE_PRECISION.div(new anchor_1.BN(3333)) // FUNDING_RATE_OFFSET_PERCENTAGE
|
|
202
202
|
);
|
|
203
|
-
const timeLeftUntilFundingUpdate = anchor_1.BN.min(anchor_1.BN.max(now.sub(market.
|
|
203
|
+
const timeLeftUntilFundingUpdate = anchor_1.BN.min(anchor_1.BN.max(now.sub(market.lastFundingRateTs), numericConstants_1.ZERO), market.marketStats.fundingPeriod);
|
|
204
204
|
const lastFundingBasis = oraclePrice
|
|
205
205
|
.mul(lastFundingRatePreAdj)
|
|
206
206
|
.div(numericConstants_1.PERCENTAGE_PRECISION)
|
|
207
|
-
.mul(market.
|
|
208
|
-
.div(market.
|
|
207
|
+
.mul(market.marketStats.fundingPeriod.sub(timeLeftUntilFundingUpdate))
|
|
208
|
+
.div(market.marketStats.fundingPeriod)
|
|
209
209
|
.div(new anchor_1.BN(1000)); // FUNDING_RATE_BUFFER
|
|
210
210
|
return lastFundingBasis;
|
|
211
211
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import {
|
|
4
|
+
import { HistoricalOracleData, MarketStats, OracleGuardRails, OracleSource, OracleValidity, PerpMarketAccount } from '../types';
|
|
5
5
|
import { OraclePriceData } from '../oracles/types';
|
|
6
6
|
import { BN } from '../isomorphic/anchor';
|
|
7
7
|
export declare function oraclePriceBands(market: PerpMarketAccount, oraclePriceData: Pick<OraclePriceData, 'price'>): [BN, BN];
|
|
8
8
|
export declare function getMaxConfidenceIntervalMultiplier(market: PerpMarketAccount): BN;
|
|
9
9
|
export declare function getOracleValidity(market: PerpMarketAccount, oraclePriceData: OraclePriceData, oracleGuardRails: OracleGuardRails, slot: BN, oracleStalenessBuffer?: BN): OracleValidity;
|
|
10
10
|
export declare function isOracleValid(market: PerpMarketAccount, oraclePriceData: OraclePriceData, oracleGuardRails: OracleGuardRails, slot: number): boolean;
|
|
11
|
-
export declare function isOracleTooDivergent(
|
|
11
|
+
export declare function isOracleTooDivergent(marketStats: MarketStats, oraclePriceData: OraclePriceData, oracleGuardRails: OracleGuardRails): boolean;
|
|
12
12
|
export declare function calculateLiveOracleTwap(histOracleData: HistoricalOracleData, oraclePriceData: OraclePriceData, now: BN, period: BN): BN;
|
|
13
|
-
export declare function calculateLiveOracleStd(
|
|
14
|
-
export declare function getNewOracleConfPct(
|
|
13
|
+
export declare function calculateLiveOracleStd(marketStats: MarketStats, oraclePriceData: OraclePriceData, now: BN): BN;
|
|
14
|
+
export declare function getNewOracleConfPct(marketStats: MarketStats, oraclePriceData: OraclePriceData, reservePrice: BN, now: BN): BN;
|
|
15
15
|
export declare function trimVaaSignatures(vaa: Buffer, n?: number): Buffer;
|
|
16
16
|
export declare function getMultipleBetweenOracleSources(firstOracleSource: OracleSource, secondOracleSource: OracleSource): {
|
|
17
17
|
numerator: BN;
|
|
@@ -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)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { User } from '../user';
|
|
3
|
-
import { PerpMarketAccount, AMM, Order, PositionDirection, MarketTypeStr, StateAccount } from '../types';
|
|
3
|
+
import { PerpMarketAccount, AMM, MarketStats, Order, PositionDirection, MarketTypeStr, StateAccount } from '../types';
|
|
4
4
|
import { BN } from '../isomorphic/anchor';
|
|
5
5
|
import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
|
|
6
6
|
export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
|
|
@@ -14,7 +14,7 @@ export declare function hasAuctionPrice(order: Order, slot: number): boolean;
|
|
|
14
14
|
export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, slot: number, ts: number, state: StateAccount): boolean;
|
|
15
15
|
export declare function isLowRiskForAmm(order: Order, mmOraclePriceData: MMOraclePriceData, isLiquidation?: boolean): boolean;
|
|
16
16
|
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;
|
|
17
|
+
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, amm: AMM, marketStats: MarketStats, orderStepSize: BN, orderTickSize: BN, limitPrice: BN, mmOraclePriceData: MMOraclePriceData): BN;
|
|
18
18
|
export declare function isOrderExpired(order: Order, ts: number, enforceBuffer?: boolean, bufferSeconds?: number): boolean;
|
|
19
19
|
export declare function isMarketOrder(order: Order): boolean;
|
|
20
20
|
export declare function isLimitOrder(order: Order): boolean;
|
|
@@ -101,8 +101,8 @@ function getLimitPrice(order, oraclePriceData, slot, fallbackPrice) {
|
|
|
101
101
|
if (hasAuctionPrice(order, slot)) {
|
|
102
102
|
return (0, auction_1.getAuctionPrice)(order, slot, oraclePriceData.price);
|
|
103
103
|
}
|
|
104
|
-
else if (order.oraclePriceOffset
|
|
105
|
-
return anchor_1.BN.max(oraclePriceData.price.add(
|
|
104
|
+
else if (!order.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
|
|
105
|
+
return anchor_1.BN.max(oraclePriceData.price.add(order.oraclePriceOffset), numericConstants_1.ONE);
|
|
106
106
|
}
|
|
107
107
|
else if (order.price.eq(numericConstants_1.ZERO)) {
|
|
108
108
|
return fallbackPrice;
|
|
@@ -114,7 +114,7 @@ function getLimitPrice(order, oraclePriceData, slot, fallbackPrice) {
|
|
|
114
114
|
exports.getLimitPrice = getLimitPrice;
|
|
115
115
|
function hasLimitPrice(order, slot) {
|
|
116
116
|
return (order.price.gt(numericConstants_1.ZERO) ||
|
|
117
|
-
order.oraclePriceOffset
|
|
117
|
+
!order.oraclePriceOffset.eq(numericConstants_1.ZERO) ||
|
|
118
118
|
!(0, auction_1.isAuctionComplete)(order, slot));
|
|
119
119
|
}
|
|
120
120
|
exports.hasLimitPrice = hasLimitPrice;
|
|
@@ -145,23 +145,23 @@ function calculateBaseAssetAmountForAmmToFulfill(order, market, mmOraclePriceDat
|
|
|
145
145
|
}
|
|
146
146
|
const limitPrice = getLimitPrice(order, mmOraclePriceData, slot);
|
|
147
147
|
let baseAssetAmount;
|
|
148
|
-
const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
|
|
148
|
+
const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, market.totalExchangeFee, mmOraclePriceData);
|
|
149
149
|
if (limitPrice !== undefined) {
|
|
150
|
-
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, limitPrice, mmOraclePriceData);
|
|
150
|
+
baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, market.marketStats, market.orderStepSize, market.orderTickSize, limitPrice, mmOraclePriceData);
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
153
|
baseAssetAmount = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
|
|
154
154
|
}
|
|
155
|
-
const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, order.direction);
|
|
155
|
+
const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, market.orderStepSize, order.direction);
|
|
156
156
|
return anchor_1.BN.min(maxBaseAssetAmount, baseAssetAmount);
|
|
157
157
|
}
|
|
158
158
|
exports.calculateBaseAssetAmountForAmmToFulfill = calculateBaseAssetAmountForAmmToFulfill;
|
|
159
|
-
function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, limitPrice, mmOraclePriceData) {
|
|
159
|
+
function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, marketStats, orderStepSize, orderTickSize, limitPrice, mmOraclePriceData) {
|
|
160
160
|
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,
|
|
161
|
+
? limitPrice.sub(orderTickSize)
|
|
162
|
+
: limitPrice.add(orderTickSize);
|
|
163
|
+
const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(amm, marketStats, adjustedLimitPrice, order.direction, mmOraclePriceData);
|
|
164
|
+
const baseAssetAmount = standardizeBaseAssetAmount(maxAmountToTrade, orderStepSize);
|
|
165
165
|
// Check that directions are the same
|
|
166
166
|
const sameDirection = isSameDirection(direction, order.direction);
|
|
167
167
|
if (!sameDirection) {
|
|
@@ -285,7 +285,7 @@ function maxSizeForTargetLiabilityWeightBN(target, imfFactor, liabilityWeight, m
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
// cap at max OI
|
|
288
|
-
const maxOpenInterest = market.
|
|
288
|
+
const maxOpenInterest = market.maxOpenInterest;
|
|
289
289
|
if (lo.gt(maxOpenInterest)) {
|
|
290
290
|
return maxOpenInterest;
|
|
291
291
|
}
|
|
@@ -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, market.totalExchangeFee, directionToClose, mmOraclePriceData, latestSlot);
|
|
27
27
|
prepegAmm = {
|
|
28
28
|
baseAssetReserve,
|
|
29
29
|
quoteAssetReserve,
|
|
@@ -32,7 +32,7 @@ function calculateBaseAssetValue(market, userPosition, mmOraclePriceData, useSpr
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
prepegAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
|
|
35
|
+
prepegAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, market.totalExchangeFee, mmOraclePriceData);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
@@ -124,10 +124,10 @@ function calculateUnsettledFundingPnl(market, perpPosition) {
|
|
|
124
124
|
}
|
|
125
125
|
let ammCumulativeFundingRate;
|
|
126
126
|
if (perpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
127
|
-
ammCumulativeFundingRate = market.
|
|
127
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateLong;
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
|
-
ammCumulativeFundingRate = market.
|
|
130
|
+
ammCumulativeFundingRate = market.cumulativeFundingRateShort;
|
|
131
131
|
}
|
|
132
132
|
const perPositionFundingRate = ammCumulativeFundingRate
|
|
133
133
|
.sub(perpPosition.lastCumulativeFundingRate)
|
|
@@ -29,13 +29,11 @@ export type BSOL_EMISSIONS_API_RESPONSE = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare function fetchBSolMetrics(): Promise<any>;
|
|
31
31
|
export declare function fetchBSolVelocityEmissions(): Promise<any>;
|
|
32
|
-
|
|
33
|
-
export declare const fetchBSolDriftEmissions: typeof fetchBSolVelocityEmissions;
|
|
34
|
-
export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
|
|
32
|
+
export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, velocityClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
|
|
35
33
|
marketIndex: number;
|
|
36
34
|
amount: BN;
|
|
37
35
|
jupiterClient: JupiterClient;
|
|
38
|
-
|
|
36
|
+
velocityClient: VelocityClient;
|
|
39
37
|
price?: number;
|
|
40
38
|
userAccountPublicKey?: PublicKey;
|
|
41
39
|
forceMarinade?: boolean;
|
|
@@ -47,10 +45,10 @@ export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClie
|
|
|
47
45
|
method: 'jupiter' | 'marinade';
|
|
48
46
|
price?: number;
|
|
49
47
|
}>;
|
|
50
|
-
export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient,
|
|
48
|
+
export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
|
|
51
49
|
amount: BN;
|
|
52
50
|
jupiterClient: JupiterClient;
|
|
53
|
-
|
|
51
|
+
velocityClient: VelocityClient;
|
|
54
52
|
price?: number;
|
|
55
53
|
userAccountPublicKey?: PublicKey;
|
|
56
54
|
forceMarinade?: boolean;
|
|
@@ -62,10 +60,10 @@ export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, drift
|
|
|
62
60
|
method: 'jupiter' | 'marinade';
|
|
63
61
|
price: number;
|
|
64
62
|
}>;
|
|
65
|
-
export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient,
|
|
63
|
+
export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, onlyDirectRoutes, jupiterQuote, }: {
|
|
66
64
|
amount: BN;
|
|
67
65
|
jupiterClient: JupiterClient;
|
|
68
|
-
|
|
66
|
+
velocityClient: VelocityClient;
|
|
69
67
|
userAccountPublicKey?: PublicKey;
|
|
70
68
|
onlyDirectRoutes?: boolean;
|
|
71
69
|
jupiterQuote?: QuoteResponse;
|
|
@@ -80,12 +78,12 @@ export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, dr
|
|
|
80
78
|
*
|
|
81
79
|
* Without doing any extra steps like checking if you can get a better rate by staking directly with that LST platform
|
|
82
80
|
*/
|
|
83
|
-
export declare function findBestLstSuperStakeIxs({ amount, jupiterClient,
|
|
81
|
+
export declare function findBestLstSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, onlyDirectRoutes, lstMarketIndex, jupiterQuote, }: {
|
|
84
82
|
amount: BN;
|
|
85
83
|
lstMint: PublicKey;
|
|
86
84
|
lstMarketIndex: number;
|
|
87
85
|
jupiterClient: JupiterClient;
|
|
88
|
-
|
|
86
|
+
velocityClient: VelocityClient;
|
|
89
87
|
userAccountPublicKey?: PublicKey;
|
|
90
88
|
onlyDirectRoutes?: boolean;
|
|
91
89
|
jupiterQuote?: QuoteResponse;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateEstimatedSuperStakeLiquidationPrice = exports.calculateSolEarned = exports.fetchMSolMetrics = exports.fetchJitoSolMetrics = exports.findBestLstSuperStakeIxs = exports.findBestJitoSolSuperStakeIxs = exports.findBestMSolSuperStakeIxs = exports.findBestSuperStakeIxs = exports.
|
|
6
|
+
exports.calculateEstimatedSuperStakeLiquidationPrice = exports.calculateSolEarned = exports.fetchMSolMetrics = exports.fetchJitoSolMetrics = exports.findBestLstSuperStakeIxs = exports.findBestJitoSolSuperStakeIxs = exports.findBestMSolSuperStakeIxs = exports.findBestSuperStakeIxs = exports.fetchBSolVelocityEmissions = exports.fetchBSolMetrics = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const marinade_1 = require("../marinade");
|
|
9
9
|
const anchor_1 = require("../isomorphic/anchor");
|
|
@@ -16,17 +16,15 @@ async function fetchBSolMetrics() {
|
|
|
16
16
|
}
|
|
17
17
|
exports.fetchBSolMetrics = fetchBSolMetrics;
|
|
18
18
|
async function fetchBSolVelocityEmissions() {
|
|
19
|
-
return await (0, node_fetch_1.default)('https://stake.solblaze.org/api/v1/
|
|
19
|
+
return await (0, node_fetch_1.default)('https://stake.solblaze.org/api/v1/velocity_emissions');
|
|
20
20
|
}
|
|
21
21
|
exports.fetchBSolVelocityEmissions = fetchBSolVelocityEmissions;
|
|
22
|
-
|
|
23
|
-
exports.fetchBSolDriftEmissions = fetchBSolVelocityEmissions;
|
|
24
|
-
async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }) {
|
|
22
|
+
async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, velocityClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }) {
|
|
25
23
|
if (marketIndex === 2) {
|
|
26
24
|
return findBestMSolSuperStakeIxs({
|
|
27
25
|
amount,
|
|
28
26
|
jupiterClient,
|
|
29
|
-
|
|
27
|
+
velocityClient,
|
|
30
28
|
userAccountPublicKey,
|
|
31
29
|
price,
|
|
32
30
|
forceMarinade,
|
|
@@ -38,7 +36,7 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
38
36
|
return findBestJitoSolSuperStakeIxs({
|
|
39
37
|
amount,
|
|
40
38
|
jupiterClient,
|
|
41
|
-
|
|
39
|
+
velocityClient,
|
|
42
40
|
userAccountPublicKey,
|
|
43
41
|
onlyDirectRoutes,
|
|
44
42
|
jupiterQuote,
|
|
@@ -47,10 +45,10 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
47
45
|
else if (marketIndex === 8) {
|
|
48
46
|
return findBestLstSuperStakeIxs({
|
|
49
47
|
amount,
|
|
50
|
-
lstMint:
|
|
48
|
+
lstMint: velocityClient.getSpotMarketAccount(8).mint,
|
|
51
49
|
lstMarketIndex: 8,
|
|
52
50
|
jupiterClient,
|
|
53
|
-
|
|
51
|
+
velocityClient,
|
|
54
52
|
userAccountPublicKey,
|
|
55
53
|
onlyDirectRoutes,
|
|
56
54
|
jupiterQuote,
|
|
@@ -61,13 +59,13 @@ async function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, drift
|
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
exports.findBestSuperStakeIxs = findBestSuperStakeIxs;
|
|
64
|
-
async function findBestMSolSuperStakeIxs({ amount, jupiterClient,
|
|
62
|
+
async function findBestMSolSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }) {
|
|
65
63
|
if (!price) {
|
|
66
|
-
const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(
|
|
64
|
+
const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(velocityClient.provider);
|
|
67
65
|
price = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
|
|
68
66
|
}
|
|
69
|
-
const solSpotMarketAccount =
|
|
70
|
-
const mSolSpotMarketAccount =
|
|
67
|
+
const solSpotMarketAccount = velocityClient.getSpotMarketAccount(1);
|
|
68
|
+
const mSolSpotMarketAccount = velocityClient.getSpotMarketAccount(2);
|
|
71
69
|
let jupiterPrice;
|
|
72
70
|
let quote = jupiterQuote;
|
|
73
71
|
if (!jupiterQuote) {
|
|
@@ -87,7 +85,7 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, u
|
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
if (!jupiterPrice || price <= jupiterPrice || forceMarinade) {
|
|
90
|
-
const ixs = await
|
|
88
|
+
const ixs = await velocityClient.getStakeForMSOLIx({
|
|
91
89
|
amount,
|
|
92
90
|
userAccountPublicKey,
|
|
93
91
|
});
|
|
@@ -99,7 +97,7 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, u
|
|
|
99
97
|
};
|
|
100
98
|
}
|
|
101
99
|
else {
|
|
102
|
-
const { ixs, lookupTables } = await
|
|
100
|
+
const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
|
|
103
101
|
inMarketIndex: 1,
|
|
104
102
|
outMarketIndex: 2,
|
|
105
103
|
jupiterClient,
|
|
@@ -117,14 +115,14 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, driftClient, u
|
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
exports.findBestMSolSuperStakeIxs = findBestMSolSuperStakeIxs;
|
|
120
|
-
async function findBestJitoSolSuperStakeIxs({ amount, jupiterClient,
|
|
118
|
+
async function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, onlyDirectRoutes, jupiterQuote, }) {
|
|
121
119
|
return await findBestLstSuperStakeIxs({
|
|
122
120
|
amount,
|
|
123
121
|
jupiterClient,
|
|
124
|
-
|
|
122
|
+
velocityClient,
|
|
125
123
|
userAccountPublicKey,
|
|
126
124
|
onlyDirectRoutes,
|
|
127
|
-
lstMint:
|
|
125
|
+
lstMint: velocityClient.getSpotMarketAccount(6).mint,
|
|
128
126
|
lstMarketIndex: 6,
|
|
129
127
|
jupiterQuote,
|
|
130
128
|
});
|
|
@@ -135,8 +133,8 @@ exports.findBestJitoSolSuperStakeIxs = findBestJitoSolSuperStakeIxs;
|
|
|
135
133
|
*
|
|
136
134
|
* Without doing any extra steps like checking if you can get a better rate by staking directly with that LST platform
|
|
137
135
|
*/
|
|
138
|
-
async function findBestLstSuperStakeIxs({ amount, jupiterClient,
|
|
139
|
-
const { ixs, lookupTables } = await
|
|
136
|
+
async function findBestLstSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, onlyDirectRoutes, lstMarketIndex, jupiterQuote, }) {
|
|
137
|
+
const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
|
|
140
138
|
inMarketIndex: 1,
|
|
141
139
|
outMarketIndex: lstMarketIndex,
|
|
142
140
|
jupiterClient,
|
|
@@ -53,7 +53,7 @@ function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quo
|
|
|
53
53
|
.div(acquiredBaseReserve.abs());
|
|
54
54
|
let amm;
|
|
55
55
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
56
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, mmOraclePriceData, latestSlot);
|
|
56
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, direction, mmOraclePriceData, latestSlot);
|
|
57
57
|
amm = {
|
|
58
58
|
baseAssetReserve,
|
|
59
59
|
quoteAssetReserve,
|
|
@@ -102,7 +102,7 @@ function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType
|
|
|
102
102
|
const swapDirection = (0, amm_1.getSwapDirection)(inputAssetType, direction);
|
|
103
103
|
let amm;
|
|
104
104
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
105
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, mmOraclePriceData, latestSlot);
|
|
105
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, direction, mmOraclePriceData, latestSlot);
|
|
106
106
|
amm = {
|
|
107
107
|
baseAssetReserve,
|
|
108
108
|
quoteAssetReserve,
|
|
@@ -166,7 +166,7 @@ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAsse
|
|
|
166
166
|
let quoteAssetReserveBefore;
|
|
167
167
|
let peg = market.amm.pegMultiplier;
|
|
168
168
|
if (useSpread && market.amm.baseSpread > 0) {
|
|
169
|
-
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, mmOraclePriceData, latestSlot);
|
|
169
|
+
const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, direction, mmOraclePriceData, latestSlot);
|
|
170
170
|
baseAssetReserveBefore = baseAssetReserve;
|
|
171
171
|
quoteAssetReserveBefore = quoteAssetReserve;
|
|
172
172
|
peg = newPeg;
|
|
@@ -280,14 +280,14 @@ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market,
|
|
|
280
280
|
const takerIsLong = (0, types_2.isVariant)(direction, 'long');
|
|
281
281
|
const limitOrders = dlob[takerIsLong ? 'getRestingLimitAsks' : 'getRestingLimitBids'](market.marketIndex, slot, types_1.MarketType.PERP, mmOraclePriceData);
|
|
282
282
|
const swapDirection = (0, amm_1.getSwapDirection)(assetType, direction);
|
|
283
|
-
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, mmOraclePriceData, new anchor_1.BN(slot));
|
|
283
|
+
const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, direction, mmOraclePriceData, new anchor_1.BN(slot));
|
|
284
284
|
const amm = {
|
|
285
285
|
baseAssetReserve,
|
|
286
286
|
quoteAssetReserve,
|
|
287
287
|
sqrtK: sqrtK,
|
|
288
288
|
pegMultiplier: newPeg,
|
|
289
289
|
};
|
|
290
|
-
const [ammBids, ammAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.
|
|
290
|
+
const [ammBids, ammAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.orderStepSize);
|
|
291
291
|
let ammLiquidity;
|
|
292
292
|
if (assetType === 'base') {
|
|
293
293
|
ammLiquidity = takerIsLong ? ammAsks.abs() : ammBids;
|
|
@@ -18,6 +18,6 @@ export declare function isBNSafe(number: number): boolean;
|
|
|
18
18
|
/**
|
|
19
19
|
* 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)
|
|
20
20
|
* @param number the number to convert to BN
|
|
21
|
-
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from
|
|
21
|
+
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from velocity sdk)
|
|
22
22
|
*/
|
|
23
23
|
export declare function numberToSafeBN(number: number, precision: BN): BN;
|
|
@@ -93,7 +93,7 @@ exports.isBNSafe = isBNSafe;
|
|
|
93
93
|
/**
|
|
94
94
|
* 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)
|
|
95
95
|
* @param number the number to convert to BN
|
|
96
|
-
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from
|
|
96
|
+
* @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from velocity sdk)
|
|
97
97
|
*/
|
|
98
98
|
function numberToSafeBN(number, precision) {
|
|
99
99
|
// check if number has decimals
|
|
@@ -8,7 +8,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
8
8
|
const anchor_1 = require("../isomorphic/anchor");
|
|
9
9
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
10
10
|
const wallet_1 = require("../wallet");
|
|
11
|
-
const
|
|
11
|
+
const velocity_json_1 = __importDefault(require("../idl/velocity.json"));
|
|
12
12
|
class PythLazerClient {
|
|
13
13
|
constructor(connection, multiple = numericConstants_1.ONE, stableCoin = false) {
|
|
14
14
|
this.connection = connection;
|
|
@@ -19,7 +19,7 @@ class PythLazerClient {
|
|
|
19
19
|
new wallet_1.Wallet(new web3_js_1.Keypair()), {
|
|
20
20
|
commitment: connection.commitment,
|
|
21
21
|
});
|
|
22
|
-
this.program = new anchor_1.Program(
|
|
22
|
+
this.program = new anchor_1.Program(velocity_json_1.default, provider);
|
|
23
23
|
this.decodeFunc = this.program.account.pythLazerOracle.coder.accounts.decodeUnchecked.bind(this.program.account.pythLazerOracle.coder.accounts);
|
|
24
24
|
}
|
|
25
25
|
async getOraclePriceData(pricePublicKey) {
|
|
@@ -14,8 +14,6 @@ import { EventEmitter } from 'events';
|
|
|
14
14
|
import { grpcSubscription } from './grpcSubscription';
|
|
15
15
|
export declare class OrderSubscriber {
|
|
16
16
|
velocityClient: VelocityClient;
|
|
17
|
-
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
18
|
-
get driftClient(): VelocityClient;
|
|
19
17
|
usersAccounts: Map<string, {
|
|
20
18
|
slot: number;
|
|
21
19
|
userAccount: UserAccount;
|