@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
package/lib/node/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
|
|
|
25
25
|
export { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
26
26
|
export { WebSocketProgramUserAccountSubscriber } from './accounts/websocketProgramUserAccountSubscriber';
|
|
27
27
|
export { WebSocketProgramAccountsSubscriberV2 } from './accounts/webSocketProgramAccountsSubscriberV2';
|
|
28
|
-
export { WebSocketVelocityClientAccountSubscriberV2
|
|
28
|
+
export { WebSocketVelocityClientAccountSubscriberV2 } from './accounts/webSocketVelocityClientAccountSubscriberV2';
|
|
29
29
|
export * from './accounts/bulkAccountLoader';
|
|
30
30
|
export * from './accounts/bulkUserSubscription';
|
|
31
31
|
export * from './accounts/bulkUserStatsSubscription';
|
package/lib/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,qDAAqD,CAAC;AACpE,cAAc,yDAAyD,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,iCAAiC,EAAE,MAAM,8CAA8C,CAAC;AACjG,OAAO,EAAE,qCAAqC,EAAE,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAE,oCAAoC,EAAE,MAAM,iDAAiD,CAAC;AACvG,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,qDAAqD,CAAC;AACpE,cAAc,yDAAyD,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE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c,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AACxC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,aAAa,CAAC;AAC5B,cAAc,iCAAiC,CAAC;AAChD,cAAc,QAAQ,CAAC;AAEvB,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC"}
|
package/lib/node/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.pyth = exports.PublicKey = exports.BN = exports.PythLazerSubscriber = exports.CustomizedCadenceBulkAccountLoader = exports.
|
|
20
|
+
exports.pyth = exports.PublicKey = exports.BN = exports.PythLazerSubscriber = exports.CustomizedCadenceBulkAccountLoader = exports.WebSocketVelocityClientAccountSubscriberV2 = exports.WebSocketProgramAccountsSubscriberV2 = exports.WebSocketProgramUserAccountSubscriber = exports.WebSocketProgramAccountSubscriber = exports.WebSocketAccountSubscriberV2 = void 0;
|
|
21
21
|
/**
|
|
22
22
|
* @module @velocity-exchange/sdk
|
|
23
23
|
* Main package barrel — re-exports all public SDK types, classes, and utilities.
|
|
@@ -54,7 +54,6 @@ var webSocketProgramAccountsSubscriberV2_1 = require("./accounts/webSocketProgra
|
|
|
54
54
|
Object.defineProperty(exports, "WebSocketProgramAccountsSubscriberV2", { enumerable: true, get: function () { return webSocketProgramAccountsSubscriberV2_1.WebSocketProgramAccountsSubscriberV2; } });
|
|
55
55
|
var webSocketVelocityClientAccountSubscriberV2_1 = require("./accounts/webSocketVelocityClientAccountSubscriberV2");
|
|
56
56
|
Object.defineProperty(exports, "WebSocketVelocityClientAccountSubscriberV2", { enumerable: true, get: function () { return webSocketVelocityClientAccountSubscriberV2_1.WebSocketVelocityClientAccountSubscriberV2; } });
|
|
57
|
-
Object.defineProperty(exports, "WebSocketDriftClientAccountSubscriberV2", { enumerable: true, get: function () { return webSocketVelocityClientAccountSubscriberV2_1.WebSocketDriftClientAccountSubscriberV2; } });
|
|
58
57
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
59
58
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
60
59
|
__exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
|
package/lib/node/math/amm.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { BN } from '../isomorphic/anchor';
|
|
3
|
-
import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
3
|
+
import { AMM, MarketStats, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
4
4
|
import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
|
|
5
5
|
export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
|
|
6
|
-
export declare function calculateOptimalPegAndBudget(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, boolean];
|
|
7
|
-
export declare function calculateNewAmm(amm: AMM, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, BN];
|
|
8
|
-
export declare function calculateUpdatedAMM(amm: AMM, mmOraclePriceData: MMOraclePriceData): AMM;
|
|
9
|
-
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: PositionDirection, mmOraclePriceData: MMOraclePriceData, latestSlot?: BN): {
|
|
6
|
+
export declare function calculateOptimalPegAndBudget(amm: AMM, totalExchangeFee: BN, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, boolean];
|
|
7
|
+
export declare function calculateNewAmm(amm: AMM, totalExchangeFee: BN, mmOraclePriceData: MMOraclePriceData): [BN, BN, BN, BN];
|
|
8
|
+
export declare function calculateUpdatedAMM(amm: AMM, totalExchangeFee: BN, mmOraclePriceData: MMOraclePriceData): AMM;
|
|
9
|
+
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, marketStats: MarketStats, totalExchangeFee: BN, direction: PositionDirection, mmOraclePriceData: MMOraclePriceData, latestSlot?: BN): {
|
|
10
10
|
baseAssetReserve: BN;
|
|
11
11
|
quoteAssetReserve: BN;
|
|
12
12
|
sqrtK: BN;
|
|
13
13
|
newPeg: BN;
|
|
14
14
|
};
|
|
15
|
-
export declare function calculateBidAskPrice(amm: AMM, mmOraclePriceData: MMOraclePriceData, withUpdate?: boolean, latestSlot?: BN): [BN, BN];
|
|
15
|
+
export declare function calculateBidAskPrice(amm: AMM, marketStats: MarketStats, totalExchangeFee: BN, mmOraclePriceData: MMOraclePriceData, withUpdate?: boolean, latestSlot?: BN): [BN, BN];
|
|
16
16
|
/**
|
|
17
17
|
* Calculates a price given an arbitrary base and quote amount (they must have the same precision)
|
|
18
18
|
*
|
|
@@ -64,8 +64,8 @@ export declare function calculateSpreadBN(baseSpread: number, lastOracleReserveP
|
|
|
64
64
|
longSpread: number;
|
|
65
65
|
shortSpread: number;
|
|
66
66
|
};
|
|
67
|
-
export declare function calculateSpread(amm: AMM, oraclePriceData: OraclePriceData, now?: BN, reservePrice?: BN): [number, number];
|
|
68
|
-
export declare function calculateSpreadReserves(amm: AMM, mmOraclePriceData: MMOraclePriceData, now?: BN, latestSlot?: BN): {
|
|
67
|
+
export declare function calculateSpread(amm: AMM, marketStats: MarketStats, oraclePriceData: OraclePriceData, now?: BN, reservePrice?: BN): [number, number];
|
|
68
|
+
export declare function calculateSpreadReserves(amm: AMM, marketStats: MarketStats, mmOraclePriceData: MMOraclePriceData, now?: BN, latestSlot?: BN): {
|
|
69
69
|
baseAssetReserve: any;
|
|
70
70
|
quoteAssetReserve: any;
|
|
71
71
|
}[];
|
|
@@ -93,7 +93,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
93
93
|
* @returns cost : Precision PRICE_PRECISION
|
|
94
94
|
*/
|
|
95
95
|
export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
|
|
96
|
-
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, mmOraclePriceData?: MMOraclePriceData, now?: BN): [BN, PositionDirection];
|
|
96
|
+
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, marketStats: MarketStats, limit_price: BN, direction: PositionDirection, mmOraclePriceData?: MMOraclePriceData, now?: BN): [BN, PositionDirection];
|
|
97
97
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|
|
98
|
-
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
|
|
98
|
+
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderStepSize: BN, orderDirection: PositionDirection): BN;
|
|
99
99
|
//# sourceMappingURL=amm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amm.d.ts","sourceRoot":"","sources":["../../../src/math/amm.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAiB1C,OAAO,EACN,GAAG,EACH,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EAEjB,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStE,wBAAgB,2BAA2B,CAC1C,WAAW,EAAE,EAAE,EACf,gBAAgB,EAAE,EAAE,EACpB,iBAAiB,EAAE,EAAE,GACnB,EAAE,CASJ;AAED,wBAAgB,4BAA4B,CAC3C,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAwDvB;AAED,wBAAgB,eAAe,CAC9B,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAqClB;AAED,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,GAAG,
|
|
1
|
+
{"version":3,"file":"amm.d.ts","sourceRoot":"","sources":["../../../src/math/amm.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAiB1C,OAAO,EACN,GAAG,EACH,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EAEjB,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStE,wBAAgB,2BAA2B,CAC1C,WAAW,EAAE,EAAE,EACf,gBAAgB,EAAE,EAAE,EACpB,iBAAiB,EAAE,EAAE,GACnB,EAAE,CASJ;AAED,wBAAgB,4BAA4B,CAC3C,GAAG,EAAE,GAAG,EACR,gBAAgB,EAA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AAE,EAAE,EACR,UAAU,CAAC,EAAE,EAAE;;;IA4Jf;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAClC,iBAAiB,EAAE,EAAE,EACrB,UAAU,EAAE,EAAE,EACd,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,EAAE,GACX,CAAC,EAAE,EAAE,EAAE,CAAC,CASV;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,cAAc,EAAE,SAAS,EACzB,iBAAiB,EAAE,iBAAiB,GAClC,aAAa,CAUf;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,iBAAiB,MAoB/D;AAED,wBAAgB,kCAAkC,CACjD,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,EAAE,EACf,SAAS,EAAE,iBAAiB,EAC5B,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,GAAG,CAAC,EAAE,EAAE,GACN,CAAC,EAAE,EAAE,iBAAiB,CAAC,CAmCzB;AAED,wBAAgB,gCAAgC,CAC/C,kBAAkB,EAAE,EAAE,EACtB,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,aAAa,GAC1B,EAAE,CAcJ;AAED,wBAAgB,mCAAmC,CAClD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,EAAE,EACjB,cAAc,EAAE,iBAAiB,GAC/B,EAAE,CAqBJ"}
|
package/lib/node/math/amm.js
CHANGED
|
@@ -17,12 +17,12 @@ function calculatePegFromTargetPrice(targetPrice, baseAssetReserve, quoteAssetRe
|
|
|
17
17
|
.div(numericConstants_1.PRICE_DIV_PEG), numericConstants_1.ONE);
|
|
18
18
|
}
|
|
19
19
|
exports.calculatePegFromTargetPrice = calculatePegFromTargetPrice;
|
|
20
|
-
function calculateOptimalPegAndBudget(amm, mmOraclePriceData) {
|
|
20
|
+
function calculateOptimalPegAndBudget(amm, totalExchangeFee, mmOraclePriceData) {
|
|
21
21
|
const reservePriceBefore = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
22
22
|
const targetPrice = mmOraclePriceData.price;
|
|
23
23
|
const newPeg = calculatePegFromTargetPrice(targetPrice, amm.baseAssetReserve, amm.quoteAssetReserve);
|
|
24
24
|
const prePegCost = (0, repeg_1.calculateRepegCost)(amm, newPeg);
|
|
25
|
-
const totalFeeLB =
|
|
25
|
+
const totalFeeLB = totalExchangeFee.div(new anchor_1.BN(2));
|
|
26
26
|
const budget = anchor_1.BN.max(numericConstants_1.ZERO, amm.totalFeeMinusDistributions.sub(totalFeeLB));
|
|
27
27
|
let checkLowerBound = true;
|
|
28
28
|
if (budget.lt(prePegCost)) {
|
|
@@ -47,17 +47,17 @@ function calculateOptimalPegAndBudget(amm, mmOraclePriceData) {
|
|
|
47
47
|
checkLowerBound = false;
|
|
48
48
|
return [newTargetPrice, newOptimalPeg, newBudget, false];
|
|
49
49
|
}
|
|
50
|
-
else if (amm.totalFeeMinusDistributions.lt(
|
|
50
|
+
else if (amm.totalFeeMinusDistributions.lt(totalExchangeFee.div(new anchor_1.BN(2)))) {
|
|
51
51
|
checkLowerBound = false;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
return [targetPrice, newPeg, budget, checkLowerBound];
|
|
55
55
|
}
|
|
56
56
|
exports.calculateOptimalPegAndBudget = calculateOptimalPegAndBudget;
|
|
57
|
-
function calculateNewAmm(amm, mmOraclePriceData) {
|
|
57
|
+
function calculateNewAmm(amm, totalExchangeFee, mmOraclePriceData) {
|
|
58
58
|
let pKNumer = new anchor_1.BN(1);
|
|
59
59
|
let pKDenom = new anchor_1.BN(1);
|
|
60
|
-
const [targetPrice, _newPeg, budget, _checkLowerBound] = calculateOptimalPegAndBudget(amm, mmOraclePriceData);
|
|
60
|
+
const [targetPrice, _newPeg, budget, _checkLowerBound] = calculateOptimalPegAndBudget(amm, totalExchangeFee, mmOraclePriceData);
|
|
61
61
|
let prePegCost = (0, repeg_1.calculateRepegCost)(amm, _newPeg);
|
|
62
62
|
let newPeg = _newPeg;
|
|
63
63
|
if (prePegCost.gte(budget) && prePegCost.gt(numericConstants_1.ZERO)) {
|
|
@@ -81,12 +81,12 @@ function calculateNewAmm(amm, mmOraclePriceData) {
|
|
|
81
81
|
return [prePegCost, pKNumer, pKDenom, newPeg];
|
|
82
82
|
}
|
|
83
83
|
exports.calculateNewAmm = calculateNewAmm;
|
|
84
|
-
function calculateUpdatedAMM(amm, mmOraclePriceData) {
|
|
84
|
+
function calculateUpdatedAMM(amm, totalExchangeFee, mmOraclePriceData) {
|
|
85
85
|
if (amm.curveUpdateIntensity == 0 || mmOraclePriceData === undefined) {
|
|
86
86
|
return amm;
|
|
87
87
|
}
|
|
88
88
|
const newAmm = Object.assign({}, amm);
|
|
89
|
-
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(amm, mmOraclePriceData);
|
|
89
|
+
const [prepegCost, pKNumer, pKDenom, newPeg] = calculateNewAmm(amm, totalExchangeFee, mmOraclePriceData);
|
|
90
90
|
newAmm.baseAssetReserve = newAmm.baseAssetReserve.mul(pKNumer).div(pKDenom);
|
|
91
91
|
newAmm.sqrtK = newAmm.sqrtK.mul(pKNumer).div(pKDenom);
|
|
92
92
|
const invariant = newAmm.sqrtK.mul(newAmm.sqrtK);
|
|
@@ -104,9 +104,9 @@ function calculateUpdatedAMM(amm, mmOraclePriceData) {
|
|
|
104
104
|
return newAmm;
|
|
105
105
|
}
|
|
106
106
|
exports.calculateUpdatedAMM = calculateUpdatedAMM;
|
|
107
|
-
function calculateUpdatedAMMSpreadReserves(amm, direction, mmOraclePriceData, latestSlot) {
|
|
108
|
-
const newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
109
|
-
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, mmOraclePriceData, undefined, latestSlot);
|
|
107
|
+
function calculateUpdatedAMMSpreadReserves(amm, marketStats, totalExchangeFee, direction, mmOraclePriceData, latestSlot) {
|
|
108
|
+
const newAmm = calculateUpdatedAMM(amm, totalExchangeFee, mmOraclePriceData);
|
|
109
|
+
const [shortReserves, longReserves] = calculateSpreadReserves(newAmm, marketStats, mmOraclePriceData, undefined, latestSlot);
|
|
110
110
|
const dirReserves = (0, types_1.isVariant)(direction, 'long')
|
|
111
111
|
? longReserves
|
|
112
112
|
: shortReserves;
|
|
@@ -119,15 +119,15 @@ function calculateUpdatedAMMSpreadReserves(amm, direction, mmOraclePriceData, la
|
|
|
119
119
|
return result;
|
|
120
120
|
}
|
|
121
121
|
exports.calculateUpdatedAMMSpreadReserves = calculateUpdatedAMMSpreadReserves;
|
|
122
|
-
function calculateBidAskPrice(amm, mmOraclePriceData, withUpdate = true, latestSlot) {
|
|
122
|
+
function calculateBidAskPrice(amm, marketStats, totalExchangeFee, mmOraclePriceData, withUpdate = true, latestSlot) {
|
|
123
123
|
let newAmm;
|
|
124
124
|
if (withUpdate) {
|
|
125
|
-
newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
125
|
+
newAmm = calculateUpdatedAMM(amm, totalExchangeFee, mmOraclePriceData);
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
newAmm = amm;
|
|
129
129
|
}
|
|
130
|
-
const [bidReserves, askReserves] = calculateSpreadReserves(newAmm, mmOraclePriceData, undefined, latestSlot);
|
|
130
|
+
const [bidReserves, askReserves] = calculateSpreadReserves(newAmm, marketStats, mmOraclePriceData, undefined, latestSlot);
|
|
131
131
|
const askPrice = calculatePrice(askReserves.baseAssetReserve, askReserves.quoteAssetReserve, newAmm.pegMultiplier);
|
|
132
132
|
const bidPrice = calculatePrice(bidReserves.baseAssetReserve, bidReserves.quoteAssetReserve, newAmm.pegMultiplier);
|
|
133
133
|
return [bidPrice, askPrice];
|
|
@@ -446,7 +446,7 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
|
|
|
446
446
|
return [longSpread, shortSpread];
|
|
447
447
|
}
|
|
448
448
|
exports.calculateSpreadBN = calculateSpreadBN;
|
|
449
|
-
function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
449
|
+
function calculateSpread(amm, marketStats, oraclePriceData, now, reservePrice) {
|
|
450
450
|
if (amm.baseSpread == 0 || amm.curveUpdateIntensity == 0) {
|
|
451
451
|
return [amm.baseSpread / 2, amm.baseSpread / 2];
|
|
452
452
|
}
|
|
@@ -459,9 +459,9 @@ function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
|
459
459
|
.mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
|
|
460
460
|
.div(reservePrice);
|
|
461
461
|
now = now || new anchor_1.BN(new Date().getTime() / 1000); //todo
|
|
462
|
-
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(
|
|
463
|
-
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(
|
|
464
|
-
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve,
|
|
462
|
+
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(marketStats, oraclePriceData, now);
|
|
463
|
+
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(marketStats, oraclePriceData, reservePrice, now);
|
|
464
|
+
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve, marketStats.markStd, liveOracleStd, marketStats.longIntensityVolume, marketStats.shortIntensityVolume, marketStats.volume24H, amm.ammInventorySpreadAdjustment);
|
|
465
465
|
let longSpread = spreads[0];
|
|
466
466
|
let shortSpread = spreads[1];
|
|
467
467
|
if (amm.ammSpreadAdjustment > 0) {
|
|
@@ -475,7 +475,7 @@ function calculateSpread(amm, oraclePriceData, now, reservePrice) {
|
|
|
475
475
|
return [longSpread, shortSpread];
|
|
476
476
|
}
|
|
477
477
|
exports.calculateSpread = calculateSpread;
|
|
478
|
-
function calculateSpreadReserves(amm, mmOraclePriceData, now, latestSlot) {
|
|
478
|
+
function calculateSpreadReserves(amm, marketStats, mmOraclePriceData, now, latestSlot) {
|
|
479
479
|
function calculateSpreadReserve(spread, direction, amm) {
|
|
480
480
|
if (spread === 0) {
|
|
481
481
|
return {
|
|
@@ -529,21 +529,22 @@ function calculateSpreadReserves(amm, mmOraclePriceData, now, latestSlot) {
|
|
|
529
529
|
liquidityFractionAfterDeadband = liquidityFractionAfterDeadband.sub(deadbandPct.mul((0, utils_1.sigNum)(liquidityFractionAfterDeadband)));
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
-
referencePriceOffset = calculateReferencePriceOffset(reservePrice,
|
|
532
|
+
referencePriceOffset = calculateReferencePriceOffset(reservePrice, marketStats.last24HAvgFundingRate, liquidityFractionAfterDeadband, marketStats.historicalOracleData.lastOraclePriceTwap5Min, marketStats.lastMarkPriceTwap5Min, marketStats.historicalOracleData.lastOraclePriceTwap, marketStats.lastMarkPriceTwap, maxOffset).toNumber();
|
|
533
533
|
}
|
|
534
|
-
let [longSpread, shortSpread] = calculateSpread(amm, mmOraclePriceData, now, reservePrice);
|
|
535
|
-
const
|
|
534
|
+
let [longSpread, shortSpread] = calculateSpread(amm, marketStats, mmOraclePriceData, now, reservePrice);
|
|
535
|
+
const lastReferencePriceOffset = marketStats.lastReferencePriceOffset;
|
|
536
|
+
const doReferencePricOffsetSmooth = Math.sign(referencePriceOffset) !== Math.sign(lastReferencePriceOffset) &&
|
|
536
537
|
amm.curveUpdateIntensity > 100;
|
|
537
538
|
if (doReferencePricOffsetSmooth) {
|
|
538
539
|
const slotsPassed = latestSlot != null
|
|
539
540
|
? anchor_1.BN.max(latestSlot.sub(amm.lastUpdateSlot), numericConstants_1.ZERO).toNumber()
|
|
540
541
|
: 0;
|
|
541
|
-
const fullOffsetDelta = referencePriceOffset -
|
|
542
|
+
const fullOffsetDelta = referencePriceOffset - lastReferencePriceOffset;
|
|
542
543
|
const raw = Math.trunc(Math.min(Math.abs(fullOffsetDelta), slotsPassed * 1000) / 10);
|
|
543
|
-
const maxAllowed = Math.abs(
|
|
544
|
+
const maxAllowed = Math.abs(lastReferencePriceOffset) || Math.abs(referencePriceOffset);
|
|
544
545
|
const magnitude = Math.min(Math.max(raw, 10), maxAllowed);
|
|
545
546
|
const referencePriceDelta = Math.sign(fullOffsetDelta) * magnitude;
|
|
546
|
-
referencePriceOffset =
|
|
547
|
+
referencePriceOffset = lastReferencePriceOffset + referencePriceDelta;
|
|
547
548
|
if (referencePriceDelta < 0) {
|
|
548
549
|
longSpread += Math.abs(referencePriceDelta);
|
|
549
550
|
shortSpread += Math.abs(referencePriceOffset);
|
|
@@ -614,7 +615,7 @@ function calculateTerminalPrice(market) {
|
|
|
614
615
|
return terminalPrice;
|
|
615
616
|
}
|
|
616
617
|
exports.calculateTerminalPrice = calculateTerminalPrice;
|
|
617
|
-
function calculateMaxBaseAssetAmountToTrade(amm, limit_price, direction, mmOraclePriceData, now) {
|
|
618
|
+
function calculateMaxBaseAssetAmountToTrade(amm, marketStats, limit_price, direction, mmOraclePriceData, now) {
|
|
618
619
|
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
|
619
620
|
const newBaseAssetReserveSquared = invariant
|
|
620
621
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
@@ -622,7 +623,7 @@ function calculateMaxBaseAssetAmountToTrade(amm, limit_price, direction, mmOracl
|
|
|
622
623
|
.div(limit_price)
|
|
623
624
|
.div(numericConstants_1.PEG_PRECISION);
|
|
624
625
|
const newBaseAssetReserve = (0, utils_1.squareRootBN)(newBaseAssetReserveSquared);
|
|
625
|
-
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(amm, mmOraclePriceData, now);
|
|
626
|
+
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(amm, marketStats, mmOraclePriceData, now);
|
|
626
627
|
const baseAssetReserveBefore = (0, types_1.isVariant)(direction, 'long')
|
|
627
628
|
? longSpreadReserves.baseAssetReserve
|
|
628
629
|
: shortSpreadReserves.baseAssetReserve;
|
|
@@ -657,7 +658,7 @@ function calculateQuoteAssetAmountSwapped(quoteAssetReserves, pegMultiplier, swa
|
|
|
657
658
|
return quoteAssetAmount;
|
|
658
659
|
}
|
|
659
660
|
exports.calculateQuoteAssetAmountSwapped = calculateQuoteAssetAmountSwapped;
|
|
660
|
-
function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
|
661
|
+
function calculateMaxBaseAssetAmountFillable(amm, orderStepSize, orderDirection) {
|
|
661
662
|
const maxFillSize = amm.baseAssetReserve.div(new anchor_1.BN(amm.maxFillReserveFraction));
|
|
662
663
|
let maxBaseAssetAmountOnSide;
|
|
663
664
|
if ((0, types_1.isVariant)(orderDirection, 'long')) {
|
|
@@ -666,6 +667,6 @@ function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
|
|
666
667
|
else {
|
|
667
668
|
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.maxBaseAssetReserve.sub(amm.baseAssetReserve));
|
|
668
669
|
}
|
|
669
|
-
return (0, orders_1.standardizeBaseAssetAmount)(anchor_1.BN.min(maxFillSize, maxBaseAssetAmountOnSide),
|
|
670
|
+
return (0, orders_1.standardizeBaseAssetAmount)(anchor_1.BN.min(maxFillSize, maxBaseAssetAmountOnSide), orderStepSize);
|
|
670
671
|
}
|
|
671
672
|
exports.calculateMaxBaseAssetAmountFillable = calculateMaxBaseAssetAmountFillable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auction.d.ts","sourceRoot":"","sources":["../../../src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E,EAAE,CAAC;IAChB,iBAAiB,EAAE,EAAE,CAAC;IACtB,eAAe,EAAE,EAAE,CAAC;IACpB,UAAU,EAAE,EAAE,CAAC;IACf,gBAAgB,CAAC,EAAE;QAClB,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,EAAE,EAAE,CAAC;KACR,CAAC;CACF,GAAG;IAAE,iBAAiB,EAAE,EAAE,CAAC;IAAC,eAAe,EAAE,EAAE,CAAC;IAAC,iBAAiB,EAAE,EAAE,CAAA;CAAE,CA+BxE;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IACnD,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,WAAW,EAAE,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,EAAE,CAAC;CAChB,GAAG,EAAE,CAkFL;AAED;;;;GAIG;AACH,wBAAgB,uCAAuC,CAAC,MAAM,EAAE;IAC/D,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,WAAW,EAAE,EAAE,CAAC;IAChB,aAAa,EAAE,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,EAAE,CAAC;CAChB,GAAG;IAAE,UAAU,EAAE,EAAE,CAAC;IAAC,cAAc,EAAE,EAAE,CAAA;CAAE,CAuBzC"}
|
package/lib/node/math/auction.js
CHANGED
|
@@ -56,7 +56,7 @@ function getAuctionPrice(order, slot, oraclePrice) {
|
|
|
56
56
|
return getAuctionPriceForFixedAuction(order, slot);
|
|
57
57
|
}
|
|
58
58
|
else if ((0, types_1.isVariant)(order.orderType, 'limit')) {
|
|
59
|
-
if (order.oraclePriceOffset != null && order.oraclePriceOffset
|
|
59
|
+
if (order.oraclePriceOffset != null && !order.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
|
|
60
60
|
return getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice);
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
@@ -153,13 +153,6 @@ function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice,
|
|
|
153
153
|
? auctionEndPrice.sub(oraclePrice).add(numericConstants_1.ONE)
|
|
154
154
|
: auctionEndPrice.sub(oraclePrice).sub(numericConstants_1.ONE);
|
|
155
155
|
}
|
|
156
|
-
let oraclePriceOffsetNum;
|
|
157
|
-
try {
|
|
158
|
-
oraclePriceOffsetNum = oraclePriceOffset.toNumber();
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
oraclePriceOffsetNum = 0;
|
|
162
|
-
}
|
|
163
156
|
if (auctionPriceCaps) {
|
|
164
157
|
auctionStartPrice = anchor_1.BN.min(anchor_1.BN.max(auctionStartPrice, auctionPriceCaps.min), auctionPriceCaps.max);
|
|
165
158
|
auctionEndPrice = anchor_1.BN.min(anchor_1.BN.max(auctionEndPrice, auctionPriceCaps.min), auctionPriceCaps.max);
|
|
@@ -167,7 +160,7 @@ function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice,
|
|
|
167
160
|
return {
|
|
168
161
|
auctionStartPrice: auctionStartPrice.sub(oraclePrice),
|
|
169
162
|
auctionEndPrice: auctionEndPrice.sub(oraclePrice),
|
|
170
|
-
oraclePriceOffset:
|
|
163
|
+
oraclePriceOffset: oraclePriceOffset,
|
|
171
164
|
};
|
|
172
165
|
}
|
|
173
166
|
exports.deriveOracleAuctionParams = deriveOracleAuctionParams;
|
|
@@ -178,32 +171,36 @@ exports.deriveOracleAuctionParams = deriveOracleAuctionParams;
|
|
|
178
171
|
*/
|
|
179
172
|
function getTriggerAuctionStartPrice(params) {
|
|
180
173
|
const { perpMarket, direction, oraclePrice, limitPrice } = params;
|
|
181
|
-
const twapMismatch = perpMarket.
|
|
182
|
-
.sub(perpMarket.
|
|
174
|
+
const twapMismatch = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwapTs
|
|
175
|
+
.sub(perpMarket.marketStats.lastMarkPriceTwapTs)
|
|
183
176
|
.abs()
|
|
184
177
|
.gte(new anchor_1.BN(60)) ||
|
|
185
|
-
perpMarket.
|
|
178
|
+
perpMarket.marketStats.volume24H.lte(new anchor_1.BN(100000).mul(numericConstants_1.QUOTE_PRECISION));
|
|
186
179
|
let baselineStartOffset;
|
|
187
180
|
if (twapMismatch) {
|
|
188
181
|
const contractTierNumber = (0, tiers_1.getPerpMarketTierNumber)(perpMarket);
|
|
189
182
|
const priceDivisor = contractTierNumber <= 1 ? 500 : 100;
|
|
190
183
|
baselineStartOffset = (0, types_1.isVariant)(direction, 'long')
|
|
191
|
-
? perpMarket.
|
|
192
|
-
: perpMarket.
|
|
184
|
+
? perpMarket.marketStats.lastBidPriceTwap.divn(priceDivisor)
|
|
185
|
+
: perpMarket.marketStats.lastAskPriceTwap.divn(priceDivisor).neg();
|
|
193
186
|
}
|
|
194
187
|
else {
|
|
195
188
|
const markTwapSlow = (0, types_1.isVariant)(direction, 'long')
|
|
196
|
-
? perpMarket.
|
|
197
|
-
: perpMarket.
|
|
198
|
-
const markTwapFast = perpMarket.
|
|
199
|
-
const oracleTwapSlow = perpMarket.
|
|
200
|
-
const oracleTwapFast = perpMarket.
|
|
189
|
+
? perpMarket.marketStats.lastBidPriceTwap
|
|
190
|
+
: perpMarket.marketStats.lastAskPriceTwap;
|
|
191
|
+
const markTwapFast = perpMarket.marketStats.lastMarkPriceTwap5Min;
|
|
192
|
+
const oracleTwapSlow = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwap;
|
|
193
|
+
const oracleTwapFast = perpMarket.marketStats.historicalOracleData.lastOraclePriceTwap5Min;
|
|
201
194
|
const offsetSlow = markTwapSlow.sub(oracleTwapSlow);
|
|
202
195
|
const offsetFast = markTwapFast.sub(oracleTwapFast);
|
|
203
|
-
|
|
196
|
+
// long_spread/short_spread were removed from AMM in the decoupling refactor.
|
|
197
|
+
// Fall back to half base_spread as the per-side spread approximation; the
|
|
198
|
+
// AMM no longer caches an exact per-side spread without oracle context.
|
|
199
|
+
const halfBaseSpread = new anchor_1.BN(Math.floor(perpMarket.amm.baseSpread / 2));
|
|
200
|
+
const fracOfLongSpreadInPrice = halfBaseSpread
|
|
204
201
|
.mul(markTwapSlow)
|
|
205
202
|
.div(numericConstants_1.PRICE_PRECISION.muln(10)); // divide by 10x for safety
|
|
206
|
-
const fracOfShortSpreadInPrice =
|
|
203
|
+
const fracOfShortSpreadInPrice = halfBaseSpread
|
|
207
204
|
.mul(markTwapSlow)
|
|
208
205
|
.div(numericConstants_1.PRICE_PRECISION.muln(10)); // divide by 10x for safety
|
|
209
206
|
baselineStartOffset = (0, types_1.isVariant)(direction, 'long')
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { RevenueShareOrder } from '../types';
|
|
1
|
+
import { OrderParams, RevenueShareEscrowAccount, RevenueShareOrder, UserStatsAccount } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* True when the user's RevenueShareEscrow was initialized with a referrer.
|
|
4
|
+
* Fills for such users must include the escrow account or the program rejects
|
|
5
|
+
* them with UnableToLoadRevenueShareAccount.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBuilderReferral(userStats: Pick<UserStatsAccount, 'referrerStatus'>): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* True when the escrow was initialized with a referrer. Referral rewards
|
|
10
|
+
* accrue into such escrows on fills, so fills of the escrow owner's orders
|
|
11
|
+
* must include the escrow account (see `isBuilderReferral`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function escrowHasReferrer(escrow: Pick<RevenueShareEscrowAccount, 'referrer'>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* True when the order params carry a builder code (`builderIdx` +
|
|
16
|
+
* `builderFeeTenthBps`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasBuilderParams(orderParams: Pick<OrderParams, 'builderIdx' | 'builderFeeTenthBps'>): boolean;
|
|
2
19
|
export declare function isBuilderOrderOpen(order: RevenueShareOrder): boolean;
|
|
3
20
|
export declare function isBuilderOrderCompleted(order: RevenueShareOrder): boolean;
|
|
4
21
|
export declare function isBuilderOrderReferral(order: RevenueShareOrder): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/math/builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/math/builder.ts"],"names":[],"mappings":"AACA,OAAO,EACN,WAAW,EAEX,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GACjD,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,IAAI,CAAC,yBAAyB,EAAE,UAAU,CAAC,GACjD,OAAO,CAET;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,oBAAoB,CAAC,GACjE,OAAO,CAOT;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAEpE;AAGD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAEzE;AAGD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAExE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAEzE"}
|
package/lib/node/math/builder.js
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBuilderOrderAvailable = exports.isBuilderOrderReferral = exports.isBuilderOrderCompleted = exports.isBuilderOrderOpen = void 0;
|
|
3
|
+
exports.isBuilderOrderAvailable = exports.isBuilderOrderReferral = exports.isBuilderOrderCompleted = exports.isBuilderOrderOpen = exports.hasBuilderParams = exports.escrowHasReferrer = exports.isBuilderReferral = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
/**
|
|
7
|
+
* True when the user's RevenueShareEscrow was initialized with a referrer.
|
|
8
|
+
* Fills for such users must include the escrow account or the program rejects
|
|
9
|
+
* them with UnableToLoadRevenueShareAccount.
|
|
10
|
+
*/
|
|
11
|
+
function isBuilderReferral(userStats) {
|
|
12
|
+
return (userStats.referrerStatus & types_1.ReferrerStatus.BuilderReferral) !== 0;
|
|
13
|
+
}
|
|
14
|
+
exports.isBuilderReferral = isBuilderReferral;
|
|
15
|
+
/**
|
|
16
|
+
* True when the escrow was initialized with a referrer. Referral rewards
|
|
17
|
+
* accrue into such escrows on fills, so fills of the escrow owner's orders
|
|
18
|
+
* must include the escrow account (see `isBuilderReferral`).
|
|
19
|
+
*/
|
|
20
|
+
function escrowHasReferrer(escrow) {
|
|
21
|
+
return !escrow.referrer.equals(web3_js_1.PublicKey.default);
|
|
22
|
+
}
|
|
23
|
+
exports.escrowHasReferrer = escrowHasReferrer;
|
|
24
|
+
/**
|
|
25
|
+
* True when the order params carry a builder code (`builderIdx` +
|
|
26
|
+
* `builderFeeTenthBps`).
|
|
27
|
+
*/
|
|
28
|
+
function hasBuilderParams(orderParams) {
|
|
29
|
+
return (orderParams.builderIdx !== null &&
|
|
30
|
+
orderParams.builderIdx !== undefined &&
|
|
31
|
+
orderParams.builderFeeTenthBps !== null &&
|
|
32
|
+
orderParams.builderFeeTenthBps !== undefined);
|
|
33
|
+
}
|
|
34
|
+
exports.hasBuilderParams = hasBuilderParams;
|
|
4
35
|
const FLAG_IS_OPEN = 0x01;
|
|
5
36
|
function isBuilderOrderOpen(order) {
|
|
6
37
|
return (order.bitFlags & FLAG_IS_OPEN) !== 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"funding.d.ts","sourceRoot":"","sources":["../../../src/math/funding.ts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AAED;;;;;;GAMG;AACH,wBAAgB,yCAAyC,CACxD,MAAM,EAAE,iBAAiB,EACzB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,eAAe,CAAC,EAAE,eAAe,EACjC,SAAS,CAAC,EAAE,EAAE,EACd,GAAG,CAAC,EAAE,EAAE,GACN,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAiBlB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,EAAE,CAWlE"}
|
package/lib/node/math/funding.js
CHANGED
|
@@ -11,12 +11,12 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
const numericConstants_2 = require("../constants/numericConstants");
|
|
12
12
|
function calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, period = new anchor_1.BN(3600)) {
|
|
13
13
|
now = now || new anchor_1.BN((Date.now() / 1000).toFixed(0));
|
|
14
|
-
const lastMarkTwapWithMantissa = market.
|
|
15
|
-
const lastMarkPriceTwapTs = market.
|
|
14
|
+
const lastMarkTwapWithMantissa = market.marketStats.lastMarkPriceTwap;
|
|
15
|
+
const lastMarkPriceTwapTs = market.marketStats.lastMarkPriceTwapTs;
|
|
16
16
|
const timeSinceLastMarkChange = now.sub(lastMarkPriceTwapTs);
|
|
17
17
|
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(period, anchor_1.BN.max(numericConstants_1.ZERO, period.sub(timeSinceLastMarkChange)));
|
|
18
18
|
if (!markPrice) {
|
|
19
|
-
const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, mmOraclePriceData);
|
|
19
|
+
const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, market.marketStats, market.totalExchangeFee, mmOraclePriceData);
|
|
20
20
|
markPrice = bid.add(ask).div(new anchor_1.BN(2));
|
|
21
21
|
}
|
|
22
22
|
const markTwapWithMantissa = markTwapTimeSinceLastUpdate
|
|
@@ -29,21 +29,21 @@ function shrinkStaleTwaps(market, markTwapWithMantissa, oracleTwapWithMantissa,
|
|
|
29
29
|
now = now || new anchor_1.BN((Date.now() / 1000).toFixed(0));
|
|
30
30
|
let newMarkTwap = markTwapWithMantissa;
|
|
31
31
|
let newOracleTwap = oracleTwapWithMantissa;
|
|
32
|
-
if (market.
|
|
32
|
+
if (market.marketStats.lastMarkPriceTwapTs.gt(market.marketStats.historicalOracleData.lastOraclePriceTwapTs)) {
|
|
33
33
|
// shrink oracle based on invalid intervals
|
|
34
|
-
const oracleInvalidDuration = anchor_1.BN.max(numericConstants_1.ZERO, market.
|
|
35
|
-
const timeSinceLastOracleTwapUpdate = now.sub(market.
|
|
36
|
-
const oracleTwapTimeSinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(market.
|
|
34
|
+
const oracleInvalidDuration = anchor_1.BN.max(numericConstants_1.ZERO, market.marketStats.lastMarkPriceTwapTs.sub(market.marketStats.historicalOracleData.lastOraclePriceTwapTs));
|
|
35
|
+
const timeSinceLastOracleTwapUpdate = now.sub(market.marketStats.historicalOracleData.lastOraclePriceTwapTs);
|
|
36
|
+
const oracleTwapTimeSinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(market.marketStats.fundingPeriod, anchor_1.BN.max(numericConstants_1.ONE, market.marketStats.fundingPeriod.sub(timeSinceLastOracleTwapUpdate))));
|
|
37
37
|
newOracleTwap = oracleTwapTimeSinceLastUpdate
|
|
38
38
|
.mul(oracleTwapWithMantissa)
|
|
39
39
|
.add(oracleInvalidDuration.mul(markTwapWithMantissa))
|
|
40
40
|
.div(oracleTwapTimeSinceLastUpdate.add(oracleInvalidDuration));
|
|
41
41
|
}
|
|
42
|
-
else if (market.
|
|
42
|
+
else if (market.marketStats.lastMarkPriceTwapTs.lt(market.marketStats.historicalOracleData.lastOraclePriceTwapTs)) {
|
|
43
43
|
// shrink mark to oracle twap over tradless intervals
|
|
44
|
-
const tradelessDuration = anchor_1.BN.max(numericConstants_1.ZERO, market.
|
|
45
|
-
const timeSinceLastMarkTwapUpdate = now.sub(market.
|
|
46
|
-
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(market.
|
|
44
|
+
const tradelessDuration = anchor_1.BN.max(numericConstants_1.ZERO, market.marketStats.historicalOracleData.lastOraclePriceTwapTs.sub(market.marketStats.lastMarkPriceTwapTs));
|
|
45
|
+
const timeSinceLastMarkTwapUpdate = now.sub(market.marketStats.lastMarkPriceTwapTs);
|
|
46
|
+
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(numericConstants_1.ONE, anchor_1.BN.min(market.marketStats.fundingPeriod, anchor_1.BN.max(numericConstants_1.ONE, market.marketStats.fundingPeriod.sub(timeSinceLastMarkTwapUpdate))));
|
|
47
47
|
newMarkTwap = markTwapTimeSinceLastUpdate
|
|
48
48
|
.mul(markTwapWithMantissa)
|
|
49
49
|
.add(tradelessDuration.mul(oracleTwapWithMantissa))
|
|
@@ -65,8 +65,8 @@ function calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePrice
|
|
|
65
65
|
// todo: sufficiently differs from blockchain timestamp?
|
|
66
66
|
now = now || new anchor_1.BN((Date.now() / 1000).toFixed(0));
|
|
67
67
|
// calculate real-time mark and oracle twap
|
|
68
|
-
const liveMarkTwap = calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, market.
|
|
69
|
-
const liveOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(market.
|
|
68
|
+
const liveMarkTwap = calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, market.marketStats.fundingPeriod);
|
|
69
|
+
const liveOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(market.marketStats.historicalOracleData, oraclePriceData, now, market.marketStats.fundingPeriod);
|
|
70
70
|
const [markTwap, oracleTwap] = shrinkStaleTwaps(market, liveMarkTwap, liveOracleTwap, now);
|
|
71
71
|
// if(!markTwap.eq(liveMarkTwap)){
|
|
72
72
|
// console.log('shrink mark:', liveMarkTwap.toString(), '->', markTwap.toString());
|
|
@@ -89,9 +89,9 @@ function calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePrice
|
|
|
89
89
|
.div(oracleTwap);
|
|
90
90
|
const secondsInHour = new anchor_1.BN(3600);
|
|
91
91
|
const hoursInDay = new anchor_1.BN(24);
|
|
92
|
-
const timeSinceLastUpdate = now.sub(market.
|
|
92
|
+
const timeSinceLastUpdate = now.sub(market.lastFundingRateTs);
|
|
93
93
|
const lowerboundEst = twapSpreadPct
|
|
94
|
-
.mul(market.
|
|
94
|
+
.mul(market.marketStats.fundingPeriod)
|
|
95
95
|
.mul(anchor_1.BN.min(secondsInHour, timeSinceLastUpdate))
|
|
96
96
|
.div(secondsInHour)
|
|
97
97
|
.div(secondsInHour)
|
|
@@ -107,16 +107,16 @@ function calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePrice
|
|
|
107
107
|
let cappedAltEst;
|
|
108
108
|
let largerSide;
|
|
109
109
|
let smallerSide;
|
|
110
|
-
if (market.
|
|
111
|
-
largerSide = market.
|
|
112
|
-
smallerSide = market.
|
|
110
|
+
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort.abs())) {
|
|
111
|
+
largerSide = market.baseAssetAmountLong.abs();
|
|
112
|
+
smallerSide = market.baseAssetAmountShort.abs();
|
|
113
113
|
if (twapSpread.gt(new anchor_1.BN(0))) {
|
|
114
114
|
return [markTwap, oracleTwap, lowerboundEst, interpEst, interpEst];
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
else if (market.
|
|
118
|
-
largerSide = market.
|
|
119
|
-
smallerSide = market.
|
|
117
|
+
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort.abs())) {
|
|
118
|
+
largerSide = market.baseAssetAmountShort.abs();
|
|
119
|
+
smallerSide = market.baseAssetAmountLong.abs();
|
|
120
120
|
if (twapSpread.lt(new anchor_1.BN(0))) {
|
|
121
121
|
return [markTwap, oracleTwap, lowerboundEst, interpEst, interpEst];
|
|
122
122
|
}
|
|
@@ -212,10 +212,10 @@ function getMaxPriceDivergenceForFundingRate(market, oracleTwap) {
|
|
|
212
212
|
*/
|
|
213
213
|
function calculateLongShortFundingRate(market, mmOraclePriceData, oraclePriceData, markPrice, now) {
|
|
214
214
|
const [_1, _2, _, cappedAltEst, interpEst] = calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePriceData, markPrice, now);
|
|
215
|
-
if (market.
|
|
215
|
+
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort)) {
|
|
216
216
|
return [cappedAltEst, interpEst];
|
|
217
217
|
}
|
|
218
|
-
else if (market.
|
|
218
|
+
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort)) {
|
|
219
219
|
return [interpEst, cappedAltEst];
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
@@ -232,10 +232,10 @@ exports.calculateLongShortFundingRate = calculateLongShortFundingRate;
|
|
|
232
232
|
*/
|
|
233
233
|
function calculateLongShortFundingRateAndLiveTwaps(market, mmOraclePriceData, oraclePriceData, markPrice, now) {
|
|
234
234
|
const [markTwapLive, oracleTwapLive, _2, cappedAltEst, interpEst] = calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePriceData, markPrice, now);
|
|
235
|
-
if (market.
|
|
235
|
+
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort.abs())) {
|
|
236
236
|
return [markTwapLive, oracleTwapLive, cappedAltEst, interpEst];
|
|
237
237
|
}
|
|
238
|
-
else if (market.
|
|
238
|
+
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort.abs())) {
|
|
239
239
|
return [markTwapLive, oracleTwapLive, interpEst, cappedAltEst];
|
|
240
240
|
}
|
|
241
241
|
else {
|
|
@@ -250,7 +250,7 @@ exports.calculateLongShortFundingRateAndLiveTwaps = calculateLongShortFundingRat
|
|
|
250
250
|
*/
|
|
251
251
|
function calculateFundingPool(market) {
|
|
252
252
|
// todo
|
|
253
|
-
const totalFeeLB = market.
|
|
253
|
+
const totalFeeLB = market.totalExchangeFee.div(new anchor_1.BN(2));
|
|
254
254
|
const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions
|
|
255
255
|
.sub(totalFeeLB)
|
|
256
256
|
.mul(new anchor_1.BN(1))
|