@drift-labs/sdk-browser 2.162.0-beta.2 → 2.163.0-beta.9
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 -0
- package/.yarn/install-state.gz +0 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/bun.lock +47 -79
- package/lib/browser/accounts/fetch.d.ts +6 -6
- package/lib/browser/accounts/fetch.js +4 -4
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.d.ts +3 -3
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +2 -2
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/laserProgramAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +2 -2
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +1 -1
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +1 -1
- package/lib/browser/accounts/testBulkAccountLoader.js +3 -5
- package/lib/browser/accounts/types.d.ts +11 -14
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/webSocketAccountSubscriber.js +1 -2
- package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +3 -3
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -5
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +2 -2
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriberV2.d.ts +3 -3
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriberV2.js +2 -2
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -3
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -3
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +3 -3
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -3
- package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +2 -2
- package/lib/browser/addresses/pda.d.ts +6 -2
- package/lib/browser/addresses/pda.js +7 -12
- package/lib/browser/adminClient.d.ts +11 -9
- package/lib/browser/adminClient.js +30 -72
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +1 -1
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +1 -1
- package/lib/browser/config.d.ts +7 -3
- package/lib/browser/config.js +9 -7
- package/lib/browser/constants/index.d.ts +5 -0
- package/lib/browser/constants/index.js +5 -0
- package/lib/browser/constants/numericConstants.d.ts +1 -1
- package/lib/browser/constants/numericConstants.js +3 -3
- package/lib/browser/constants/perpMarkets.js +3 -412
- package/lib/browser/constants/spotMarkets.js +7 -91
- package/lib/browser/constituentMap/constituentMap.js +2 -2
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.d.ts +3 -3
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +3 -3
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +1 -1
- package/lib/browser/decode/customCoder.d.ts +7 -9
- package/lib/browser/decode/customCoder.js +17 -28
- package/lib/browser/decode/user.js +7 -25
- package/lib/browser/dlob/DLOB.d.ts +12 -0
- package/lib/browser/dlob/DLOB.js +12 -0
- package/lib/browser/dlob/orderBookLevels.js +1 -1
- package/lib/browser/driftClient.d.ts +32 -59
- package/lib/browser/driftClient.js +85 -562
- package/lib/browser/driftClientConfig.d.ts +7 -0
- package/lib/browser/events/eventSubscriber.d.ts +8 -0
- package/lib/browser/events/eventSubscriber.js +5 -2
- package/lib/browser/events/parse.d.ts +1 -1
- package/lib/browser/factory/oracleClient.d.ts +2 -2
- package/lib/browser/factory/oracleClient.js +9 -21
- package/lib/browser/idl/drift.d.ts +25708 -0
- package/lib/browser/idl/drift.js +2 -0
- package/lib/browser/idl/drift.json +20850 -15287
- package/lib/browser/idl/pyth.d.ts +97 -0
- package/lib/browser/idl/pyth.js +2 -0
- package/lib/browser/idl/token_faucet.d.ts +197 -0
- package/lib/browser/idl/token_faucet.js +2 -0
- package/lib/browser/idl/token_faucet.json +148 -61
- package/lib/browser/index.d.ts +13 -6
- package/lib/browser/index.js +12 -5
- package/lib/browser/marinade/index.d.ts +1 -1
- package/lib/browser/marinade/index.js +2 -2
- package/lib/browser/math/amm.d.ts +4 -5
- package/lib/browser/math/amm.js +8 -35
- package/lib/browser/math/funding.js +6 -1
- package/lib/browser/math/margin.d.ts +3 -4
- package/lib/browser/math/margin.js +16 -47
- package/lib/browser/math/market.d.ts +2 -2
- package/lib/browser/math/market.js +10 -42
- package/lib/browser/math/oracles.js +14 -19
- package/lib/browser/math/position.js +1 -1
- package/lib/browser/math/trade.js +4 -4
- package/lib/browser/memcmp.js +8 -8
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +1 -1
- package/lib/browser/openbook/openbookV2Subscriber.js +3 -3
- package/lib/browser/oracles/oracleClientCache.d.ts +2 -2
- package/lib/browser/oracles/prelaunchOracleClient.d.ts +2 -2
- package/lib/browser/oracles/prelaunchOracleClient.js +1 -1
- package/lib/browser/oracles/pythLazerClient.js +3 -5
- package/lib/browser/oracles/types.d.ts +6 -0
- package/lib/browser/orderParams.d.ts +0 -1
- package/lib/browser/orderParams.js +1 -5
- package/lib/browser/orderSubscriber/OrderSubscriber.js +3 -4
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/browser/orderSubscriber/index.d.ts +5 -0
- package/lib/browser/orderSubscriber/index.js +5 -0
- package/lib/browser/priorityFee/index.d.ts +5 -0
- package/lib/browser/priorityFee/index.js +5 -0
- package/lib/browser/pyth/index.d.ts +2 -2
- package/lib/browser/pyth/types.d.ts +1 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +1 -1
- package/lib/browser/swift/index.d.ts +7 -0
- package/lib/browser/swift/index.js +7 -0
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +4 -3
- package/lib/browser/tokenFaucet.d.ts +2 -2
- package/lib/browser/tokenFaucet.js +4 -4
- package/lib/browser/tx/txHandler.d.ts +12 -0
- package/lib/browser/tx/txHandler.js +12 -0
- package/lib/browser/types.d.ts +19 -31
- package/lib/browser/types.js +6 -11
- package/lib/browser/user.d.ts +27 -18
- package/lib/browser/user.js +64 -100
- package/lib/browser/userMap/WebsocketSubscription.js +1 -1
- package/lib/browser/userMap/grpcSubscription.js +1 -1
- package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/browser/userMap/userMap.js +4 -5
- package/lib/browser/userMap/userStatsMap.js +2 -3
- package/lib/browser/userStats.d.ts +5 -0
- package/lib/node/accounts/fetch.d.ts +6 -6
- package/lib/node/accounts/fetch.d.ts.map +1 -1
- package/lib/node/accounts/fetch.js +4 -4
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts +3 -3
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +2 -2
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +2 -2
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +1 -1
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +1 -1
- package/lib/node/accounts/testBulkAccountLoader.d.ts.map +1 -1
- package/lib/node/accounts/testBulkAccountLoader.js +3 -5
- package/lib/node/accounts/types.d.ts +11 -14
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.js +1 -2
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +3 -3
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -5
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +2 -2
- package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.d.ts +3 -3
- package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.js +2 -2
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -3
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -3
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +3 -3
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -3
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/addresses/pda.d.ts +6 -2
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +7 -12
- package/lib/node/adminClient.d.ts +11 -9
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +30 -72
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +1 -1
- package/lib/node/config.d.ts +7 -3
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +9 -7
- package/lib/node/constants/index.d.ts +5 -0
- package/lib/node/constants/index.d.ts.map +1 -1
- package/lib/node/constants/index.js +5 -0
- package/lib/node/constants/numericConstants.d.ts +1 -1
- package/lib/node/constants/numericConstants.d.ts.map +1 -1
- package/lib/node/constants/numericConstants.js +3 -3
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +3 -412
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constants/spotMarkets.js +7 -91
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +2 -2
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts +3 -3
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +3 -3
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +1 -1
- package/lib/node/decode/customCoder.d.ts +7 -9
- package/lib/node/decode/customCoder.d.ts.map +1 -1
- package/lib/node/decode/customCoder.js +17 -28
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +7 -25
- package/lib/node/dlob/DLOB.d.ts +12 -0
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +12 -0
- package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
- package/lib/node/dlob/orderBookLevels.js +1 -1
- package/lib/node/driftClient.d.ts +32 -59
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +85 -562
- package/lib/node/driftClientConfig.d.ts +7 -0
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.d.ts +8 -0
- package/lib/node/events/eventSubscriber.d.ts.map +1 -1
- package/lib/node/events/eventSubscriber.js +5 -2
- package/lib/node/events/parse.d.ts +1 -1
- package/lib/node/events/parse.d.ts.map +1 -1
- package/lib/node/factory/oracleClient.d.ts +2 -2
- package/lib/node/factory/oracleClient.d.ts.map +1 -1
- package/lib/node/factory/oracleClient.js +9 -21
- package/lib/node/idl/drift.d.ts +25709 -0
- package/lib/node/idl/drift.d.ts.map +1 -0
- package/lib/node/idl/drift.js +2 -0
- package/lib/node/idl/drift.json +20850 -15287
- package/lib/node/idl/pyth.d.ts +98 -0
- package/lib/node/idl/pyth.d.ts.map +1 -0
- package/lib/node/idl/pyth.js +2 -0
- package/lib/node/idl/token_faucet.d.ts +198 -0
- package/lib/node/idl/token_faucet.d.ts.map +1 -0
- package/lib/node/idl/token_faucet.js +2 -0
- package/lib/node/idl/token_faucet.json +148 -61
- package/lib/node/index.d.ts +13 -6
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +12 -5
- package/lib/node/marinade/index.d.ts +1 -1
- package/lib/node/marinade/index.d.ts.map +1 -1
- package/lib/node/marinade/index.js +2 -2
- package/lib/node/math/amm.d.ts +4 -5
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +8 -35
- package/lib/node/math/funding.d.ts.map +1 -1
- package/lib/node/math/funding.js +6 -1
- package/lib/node/math/margin.d.ts +3 -4
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +16 -47
- package/lib/node/math/market.d.ts +2 -2
- package/lib/node/math/market.d.ts.map +1 -1
- package/lib/node/math/market.js +10 -42
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +14 -19
- package/lib/node/math/position.d.ts.map +1 -1
- package/lib/node/math/position.js +1 -1
- package/lib/node/math/trade.d.ts.map +1 -1
- package/lib/node/math/trade.js +4 -4
- package/lib/node/memcmp.js +8 -8
- package/lib/node/openbook/openbookV2Subscriber.d.ts +1 -1
- package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
- package/lib/node/openbook/openbookV2Subscriber.js +3 -3
- package/lib/node/oracles/oracleClientCache.d.ts +2 -2
- package/lib/node/oracles/oracleClientCache.d.ts.map +1 -1
- package/lib/node/oracles/prelaunchOracleClient.d.ts +2 -2
- package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
- package/lib/node/oracles/prelaunchOracleClient.js +1 -1
- package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
- package/lib/node/oracles/pythLazerClient.js +3 -5
- package/lib/node/oracles/types.d.ts +6 -0
- package/lib/node/oracles/types.d.ts.map +1 -1
- package/lib/node/orderParams.d.ts +0 -1
- package/lib/node/orderParams.d.ts.map +1 -1
- package/lib/node/orderParams.js +1 -5
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +3 -4
- package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
- package/lib/node/orderSubscriber/index.d.ts +5 -0
- package/lib/node/orderSubscriber/index.d.ts.map +1 -1
- package/lib/node/orderSubscriber/index.js +5 -0
- package/lib/node/priorityFee/index.d.ts +5 -0
- package/lib/node/priorityFee/index.d.ts.map +1 -1
- package/lib/node/priorityFee/index.js +5 -0
- package/lib/node/pyth/index.d.ts +2 -2
- package/lib/node/pyth/index.d.ts.map +1 -1
- package/lib/node/pyth/types.d.ts +1 -1
- package/lib/node/pyth/types.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +1 -1
- package/lib/node/swift/index.d.ts +7 -0
- package/lib/node/swift/index.d.ts.map +1 -1
- package/lib/node/swift/index.js +7 -0
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +4 -3
- package/lib/node/tokenFaucet.d.ts +2 -2
- package/lib/node/tokenFaucet.d.ts.map +1 -1
- package/lib/node/tokenFaucet.js +4 -4
- package/lib/node/tx/txHandler.d.ts +12 -0
- package/lib/node/tx/txHandler.d.ts.map +1 -1
- package/lib/node/tx/txHandler.js +12 -0
- package/lib/node/types.d.ts +19 -31
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +6 -11
- package/lib/node/user.d.ts +27 -18
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +64 -100
- package/lib/node/userMap/WebsocketSubscription.js +1 -1
- package/lib/node/userMap/grpcSubscription.js +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +4 -5
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +2 -3
- package/lib/node/userStats.d.ts +5 -0
- package/lib/node/userStats.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/accounts/fetch.ts +18 -17
- package/src/accounts/grpcAccountSubscriber.ts +3 -3
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +2 -3
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +5 -6
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +2 -2
- package/src/accounts/grpcMultiAccountSubscriber.ts +4 -4
- package/src/accounts/grpcMultiUserAccountSubscriber.ts +4 -4
- package/src/accounts/grpcProgramAccountSubscriber.ts +3 -3
- package/src/accounts/grpcUserAccountSubscriber.ts +2 -2
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +2 -2
- package/src/accounts/laserProgramAccountSubscriber.ts +3 -3
- package/src/accounts/oneShotUserAccountSubscriber.ts +6 -7
- package/src/accounts/oneShotUserStatsAccountSubscriber.ts +10 -9
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +12 -11
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -10
- package/src/accounts/pollingOracleAccountSubscriber.ts +2 -2
- package/src/accounts/pollingTokenAccountSubscriber.ts +2 -2
- package/src/accounts/pollingUserAccountSubscriber.ts +2 -2
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +14 -14
- package/src/accounts/testBulkAccountLoader.ts +3 -5
- package/src/accounts/types.ts +10 -25
- package/src/accounts/webSocketAccountSubscriber.ts +5 -5
- package/src/accounts/webSocketAccountSubscriberV2.ts +4 -3
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +9 -10
- package/src/accounts/webSocketDriftClientAccountSubscriberV2.ts +13 -10
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +3 -3
- package/src/accounts/webSocketProgramAccountSubscriber.ts +4 -3
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +4 -3
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +4 -3
- package/src/accounts/webSocketUserAccountSubscriber.ts +3 -3
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +3 -3
- package/src/accounts/websocketProgramUserAccountSubscriber.ts +4 -4
- package/src/addresses/pda.ts +6 -22
- package/src/adminClient.ts +154 -239
- package/src/auctionSubscriber/auctionSubscriber.ts +5 -3
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +5 -3
- package/src/config.ts +24 -16
- package/src/constants/index.ts +5 -0
- package/src/constants/numericConstants.ts +2 -3
- package/src/constants/perpMarkets.ts +3 -445
- package/src/constants/spotMarkets.ts +7 -102
- package/src/constituentMap/constituentMap.ts +5 -6
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +3 -3
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +6 -6
- package/src/decode/customCoder.ts +26 -35
- package/src/decode/user.ts +7 -25
- package/src/dlob/DLOB.ts +12 -0
- package/src/dlob/orderBookLevels.ts +0 -1
- package/src/driftClient.ts +245 -1091
- package/src/driftClientConfig.ts +7 -0
- package/src/events/eventSubscriber.ts +14 -2
- package/src/events/parse.ts +2 -2
- package/src/factory/oracleClient.ts +17 -28
- package/src/idl/drift.json +20850 -15287
- package/src/idl/drift.ts +25708 -0
- package/src/idl/pyth.ts +97 -0
- package/src/idl/token_faucet.json +148 -61
- package/src/idl/token_faucet.ts +197 -0
- package/src/index.ts +13 -12
- package/src/margin/README.md +0 -1
- package/src/marinade/index.ts +2 -2
- package/src/math/amm.ts +2 -48
- package/src/math/funding.ts +8 -3
- package/src/math/margin.ts +12 -67
- package/src/math/market.ts +15 -69
- package/src/math/oracles.ts +14 -30
- package/src/math/position.ts +0 -1
- package/src/math/trade.ts +0 -4
- package/src/memcmp.ts +1 -1
- package/src/openbook/openbookV2Subscriber.ts +1 -1
- package/src/oracles/oracleClientCache.ts +2 -2
- package/src/oracles/prelaunchOracleClient.ts +9 -8
- package/src/oracles/pythLazerClient.ts +10 -12
- package/src/oracles/types.ts +6 -0
- package/src/orderParams.ts +0 -5
- package/src/orderSubscriber/OrderSubscriber.ts +7 -6
- package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
- package/src/orderSubscriber/grpcSubscription.ts +2 -2
- package/src/orderSubscriber/index.ts +5 -0
- package/src/priorityFee/index.ts +5 -0
- package/src/pyth/index.ts +4 -4
- package/src/pyth/types.ts +1 -1
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +1 -1
- package/src/swift/index.ts +7 -0
- package/src/swift/signedMsgUserAccountSubscriber.ts +7 -4
- package/src/tokenFaucet.ts +8 -4
- package/src/tx/txHandler.ts +12 -0
- package/src/types.ts +16 -20
- package/src/user.ts +66 -144
- package/src/userMap/WebsocketSubscription.ts +1 -1
- package/src/userMap/grpcSubscription.ts +1 -1
- package/src/userMap/revenueShareEscrowMap.ts +24 -20
- package/src/userMap/userMap.ts +8 -7
- package/src/userMap/userStatsMap.ts +6 -5
- package/src/userStats.ts +5 -0
- package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +5 -4
- package/tests/amm/test.ts +45 -64
- package/tests/ci/verifyConstants.ts +23 -26
- package/tests/decode/test.ts +2 -4
- package/tests/dlob/helpers.ts +8 -15
- package/tests/user/helpers.ts +0 -2
- package/tests/user/marginCalculations.test.ts +2 -3
- package/tests/user/test.ts +18 -15
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +0 -29
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +0 -111
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +0 -23
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +0 -69
- package/lib/browser/idl/pyth_solana_receiver.json +0 -628
- package/lib/browser/idl/switchboard.json +0 -8354
- package/lib/browser/idl/switchboard_on_demand_30.json +0 -5849
- package/lib/browser/oracles/pythPullClient.d.ts +0 -19
- package/lib/browser/oracles/pythPullClient.js +0 -65
- package/lib/browser/oracles/switchboardClient.d.ts +0 -12
- package/lib/browser/oracles/switchboardClient.js +0 -40
- package/lib/browser/oracles/switchboardOnDemandClient.d.ts +0 -12
- package/lib/browser/oracles/switchboardOnDemandClient.js +0 -33
- package/lib/browser/util/pythOracleUtils.d.ts +0 -2
- package/lib/browser/util/pythOracleUtils.js +0 -15
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +0 -30
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts.map +0 -1
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +0 -111
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +0 -24
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts.map +0 -1
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +0 -69
- package/lib/node/idl/pyth_solana_receiver.json +0 -628
- package/lib/node/idl/switchboard.json +0 -8354
- package/lib/node/idl/switchboard_on_demand_30.json +0 -5849
- package/lib/node/oracles/pythPullClient.d.ts +0 -20
- package/lib/node/oracles/pythPullClient.d.ts.map +0 -1
- package/lib/node/oracles/pythPullClient.js +0 -65
- package/lib/node/oracles/switchboardClient.d.ts +0 -13
- package/lib/node/oracles/switchboardClient.d.ts.map +0 -1
- package/lib/node/oracles/switchboardClient.js +0 -40
- package/lib/node/oracles/switchboardOnDemandClient.d.ts +0 -13
- package/lib/node/oracles/switchboardOnDemandClient.d.ts.map +0 -1
- package/lib/node/oracles/switchboardOnDemandClient.js +0 -33
- package/lib/node/util/pythOracleUtils.d.ts +0 -3
- package/lib/node/util/pythOracleUtils.d.ts.map +0 -1
- package/lib/node/util/pythOracleUtils.js +0 -15
- package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +0 -189
- package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +0 -131
- package/src/idl/switchboard.json +0 -8354
- package/src/idl/switchboard_on_demand_30.json +0 -5849
- package/src/oracles/pythPullClient.ts +0 -112
- package/src/oracles/switchboardClient.ts +0 -77
- package/src/oracles/switchboardOnDemandClient.ts +0 -64
- package/src/util/pythOracleUtils.ts +0 -11
package/src/math/amm.ts
CHANGED
|
@@ -197,7 +197,6 @@ export function calculateUpdatedAMMSpreadReserves(
|
|
|
197
197
|
amm: AMM,
|
|
198
198
|
direction: PositionDirection,
|
|
199
199
|
mmOraclePriceData: MMOraclePriceData,
|
|
200
|
-
isPrediction = false,
|
|
201
200
|
latestSlot?: BN
|
|
202
201
|
): { baseAssetReserve: BN; quoteAssetReserve: BN; sqrtK: BN; newPeg: BN } {
|
|
203
202
|
const newAmm = calculateUpdatedAMM(amm, mmOraclePriceData);
|
|
@@ -205,7 +204,6 @@ export function calculateUpdatedAMMSpreadReserves(
|
|
|
205
204
|
newAmm,
|
|
206
205
|
mmOraclePriceData,
|
|
207
206
|
undefined,
|
|
208
|
-
isPrediction,
|
|
209
207
|
latestSlot
|
|
210
208
|
);
|
|
211
209
|
|
|
@@ -227,7 +225,6 @@ export function calculateBidAskPrice(
|
|
|
227
225
|
amm: AMM,
|
|
228
226
|
mmOraclePriceData: MMOraclePriceData,
|
|
229
227
|
withUpdate = true,
|
|
230
|
-
isPrediction = false,
|
|
231
228
|
latestSlot?: BN
|
|
232
229
|
): [BN, BN] {
|
|
233
230
|
let newAmm: AMM;
|
|
@@ -241,7 +238,6 @@ export function calculateBidAskPrice(
|
|
|
241
238
|
newAmm,
|
|
242
239
|
mmOraclePriceData,
|
|
243
240
|
undefined,
|
|
244
|
-
isPrediction,
|
|
245
241
|
latestSlot
|
|
246
242
|
);
|
|
247
243
|
|
|
@@ -927,42 +923,10 @@ export function calculateSpread(
|
|
|
927
923
|
return [longSpread, shortSpread];
|
|
928
924
|
}
|
|
929
925
|
|
|
930
|
-
export function getQuoteAssetReservePredictionMarketBounds(
|
|
931
|
-
amm: AMM,
|
|
932
|
-
direction: PositionDirection
|
|
933
|
-
): [BN, BN] {
|
|
934
|
-
let quoteAssetReserveLowerBound = ZERO;
|
|
935
|
-
|
|
936
|
-
const pegSqrt = squareRootBN(
|
|
937
|
-
amm.pegMultiplier.mul(PEG_PRECISION).addn(1)
|
|
938
|
-
).addn(1);
|
|
939
|
-
|
|
940
|
-
let quoteAssetReserveUpperBound = amm.sqrtK
|
|
941
|
-
.mul(pegSqrt)
|
|
942
|
-
.div(amm.pegMultiplier);
|
|
943
|
-
|
|
944
|
-
if (direction === PositionDirection.LONG) {
|
|
945
|
-
quoteAssetReserveLowerBound = amm.sqrtK
|
|
946
|
-
.muln(22361)
|
|
947
|
-
.mul(pegSqrt)
|
|
948
|
-
.divn(100000)
|
|
949
|
-
.div(amm.pegMultiplier);
|
|
950
|
-
} else {
|
|
951
|
-
quoteAssetReserveUpperBound = amm.sqrtK
|
|
952
|
-
.muln(97467)
|
|
953
|
-
.mul(pegSqrt)
|
|
954
|
-
.divn(100000)
|
|
955
|
-
.div(amm.pegMultiplier);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
return [quoteAssetReserveLowerBound, quoteAssetReserveUpperBound];
|
|
959
|
-
}
|
|
960
|
-
|
|
961
926
|
export function calculateSpreadReserves(
|
|
962
927
|
amm: AMM,
|
|
963
928
|
mmOraclePriceData: MMOraclePriceData,
|
|
964
929
|
now?: BN,
|
|
965
|
-
isPrediction = false,
|
|
966
930
|
latestSlot?: BN
|
|
967
931
|
) {
|
|
968
932
|
function calculateSpreadReserve(
|
|
@@ -1001,14 +965,6 @@ export function calculateSpreadReserves(
|
|
|
1001
965
|
);
|
|
1002
966
|
}
|
|
1003
967
|
|
|
1004
|
-
if (isPrediction) {
|
|
1005
|
-
const [qarLower, qarUpper] = getQuoteAssetReservePredictionMarketBounds(
|
|
1006
|
-
amm,
|
|
1007
|
-
direction
|
|
1008
|
-
);
|
|
1009
|
-
quoteAssetReserve = clampBN(quoteAssetReserve, qarLower, qarUpper);
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
968
|
const baseAssetReserve = amm.sqrtK.mul(amm.sqrtK).div(quoteAssetReserve);
|
|
1013
969
|
return {
|
|
1014
970
|
baseAssetReserve,
|
|
@@ -1206,8 +1162,7 @@ export function calculateMaxBaseAssetAmountToTrade(
|
|
|
1206
1162
|
limit_price: BN,
|
|
1207
1163
|
direction: PositionDirection,
|
|
1208
1164
|
mmOraclePriceData?: MMOraclePriceData,
|
|
1209
|
-
now?: BN
|
|
1210
|
-
isPrediction = false
|
|
1165
|
+
now?: BN
|
|
1211
1166
|
): [BN, PositionDirection] {
|
|
1212
1167
|
const invariant = amm.sqrtK.mul(amm.sqrtK);
|
|
1213
1168
|
|
|
@@ -1221,8 +1176,7 @@ export function calculateMaxBaseAssetAmountToTrade(
|
|
|
1221
1176
|
const [shortSpreadReserves, longSpreadReserves] = calculateSpreadReserves(
|
|
1222
1177
|
amm,
|
|
1223
1178
|
mmOraclePriceData,
|
|
1224
|
-
now
|
|
1225
|
-
isPrediction
|
|
1179
|
+
now
|
|
1226
1180
|
);
|
|
1227
1181
|
|
|
1228
1182
|
const baseAssetReserveBefore: BN = isVariant(direction, 'long')
|
package/src/math/funding.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
ZERO,
|
|
7
7
|
ONE,
|
|
8
8
|
FUNDING_RATE_OFFSET_DENOMINATOR,
|
|
9
|
+
FUNDING_RATE_CLAMP_DENOMINATOR,
|
|
9
10
|
} from '../constants/numericConstants';
|
|
10
11
|
import { BigNum } from '../factory/bigNum';
|
|
11
12
|
import { PerpMarketAccount, isVariant } from '../types';
|
|
@@ -164,9 +165,13 @@ export function calculateAllEstimatedFundingRate(
|
|
|
164
165
|
// }
|
|
165
166
|
|
|
166
167
|
const twapSpread = markTwap.sub(oracleTwap);
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const offset = oracleTwap.abs().div(FUNDING_RATE_OFFSET_DENOMINATOR);
|
|
169
|
+
const twapSpreadWithOffset = twapSpread
|
|
170
|
+
.abs()
|
|
171
|
+
.lte(oracleTwap.abs().div(FUNDING_RATE_CLAMP_DENOMINATOR))
|
|
172
|
+
? offset
|
|
173
|
+
: twapSpread.add(offset);
|
|
174
|
+
|
|
170
175
|
const maxSpread = getMaxPriceDivergenceForFundingRate(market, oracleTwap);
|
|
171
176
|
|
|
172
177
|
const clampedSpreadWithOffset = clampBN(
|
package/src/math/margin.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Margin calculation helpers — TypeScript mirror of `programs/drift/src/math/margin.rs`.
|
|
3
|
+
* Computes initial/maintenance margin requirements, free collateral, and account health.
|
|
4
|
+
* Used by {@link User} for leverage queries and by keeper bots for liquidation eligibility checks.
|
|
5
|
+
*/
|
|
1
6
|
import { squareRootBN } from './utils';
|
|
2
7
|
import {
|
|
3
8
|
SPOT_MARKET_WEIGHT_PRECISION,
|
|
@@ -5,12 +10,10 @@ import {
|
|
|
5
10
|
ZERO,
|
|
6
11
|
BID_ASK_SPREAD_PRECISION,
|
|
7
12
|
AMM_RESERVE_PRECISION,
|
|
8
|
-
MAX_PREDICTION_PRICE,
|
|
9
13
|
BASE_PRECISION,
|
|
10
14
|
MARGIN_PRECISION,
|
|
11
15
|
PRICE_PRECISION,
|
|
12
16
|
QUOTE_PRECISION,
|
|
13
|
-
PERCENTAGE_PRECISION,
|
|
14
17
|
} from '../constants/numericConstants';
|
|
15
18
|
import { BN } from '@coral-xyz/anchor';
|
|
16
19
|
import { OraclePriceData } from '../oracles/types';
|
|
@@ -168,15 +171,13 @@ export function calculateWorstCasePerpLiabilityValue(
|
|
|
168
171
|
oraclePrice: BN,
|
|
169
172
|
includeOpenOrders: boolean = true
|
|
170
173
|
): { worstCaseBaseAssetAmount: BN; worstCaseLiabilityValue: BN } {
|
|
171
|
-
const isPredictionMarket = isVariant(perpMarket.contractType, 'prediction');
|
|
172
174
|
// return early if no open orders required
|
|
173
175
|
if (!includeOpenOrders) {
|
|
174
176
|
return {
|
|
175
177
|
worstCaseBaseAssetAmount: perpPosition.baseAssetAmount,
|
|
176
178
|
worstCaseLiabilityValue: calculatePerpLiabilityValue(
|
|
177
179
|
perpPosition.baseAssetAmount,
|
|
178
|
-
oraclePrice
|
|
179
|
-
isPredictionMarket
|
|
180
|
+
oraclePrice
|
|
180
181
|
),
|
|
181
182
|
};
|
|
182
183
|
}
|
|
@@ -185,13 +186,11 @@ export function calculateWorstCasePerpLiabilityValue(
|
|
|
185
186
|
|
|
186
187
|
const allBidsLiabilityValue = calculatePerpLiabilityValue(
|
|
187
188
|
allBids,
|
|
188
|
-
oraclePrice
|
|
189
|
-
isPredictionMarket
|
|
189
|
+
oraclePrice
|
|
190
190
|
);
|
|
191
191
|
const allAsksLiabilityValue = calculatePerpLiabilityValue(
|
|
192
192
|
allAsks,
|
|
193
|
-
oraclePrice
|
|
194
|
-
isPredictionMarket
|
|
193
|
+
oraclePrice
|
|
195
194
|
);
|
|
196
195
|
|
|
197
196
|
if (allAsksLiabilityValue.gte(allBidsLiabilityValue)) {
|
|
@@ -209,21 +208,9 @@ export function calculateWorstCasePerpLiabilityValue(
|
|
|
209
208
|
|
|
210
209
|
export function calculatePerpLiabilityValue(
|
|
211
210
|
baseAssetAmount: BN,
|
|
212
|
-
price: BN
|
|
213
|
-
isPredictionMarket: boolean
|
|
211
|
+
price: BN
|
|
214
212
|
): BN {
|
|
215
|
-
|
|
216
|
-
if (baseAssetAmount.gt(ZERO)) {
|
|
217
|
-
return baseAssetAmount.mul(price).div(BASE_PRECISION);
|
|
218
|
-
} else {
|
|
219
|
-
return baseAssetAmount
|
|
220
|
-
.abs()
|
|
221
|
-
.mul(MAX_PREDICTION_PRICE.sub(price))
|
|
222
|
-
.div(BASE_PRECISION);
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
return baseAssetAmount.abs().mul(price).div(BASE_PRECISION);
|
|
226
|
-
}
|
|
213
|
+
return baseAssetAmount.abs().mul(price).div(BASE_PRECISION);
|
|
227
214
|
}
|
|
228
215
|
|
|
229
216
|
/**
|
|
@@ -237,7 +224,6 @@ export function calculateMarginUSDCRequiredForTrade(
|
|
|
237
224
|
targetMarketIndex: number,
|
|
238
225
|
baseSize: BN,
|
|
239
226
|
userMaxMarginRatio?: number,
|
|
240
|
-
userHighLeverageMode?: boolean,
|
|
241
227
|
entryPrice?: BN
|
|
242
228
|
): BN {
|
|
243
229
|
const targetMarket = driftClient.getPerpMarketAccount(targetMarketIndex);
|
|
@@ -246,19 +232,14 @@ export function calculateMarginUSDCRequiredForTrade(
|
|
|
246
232
|
entryPrice ??
|
|
247
233
|
driftClient.getOracleDataForPerpMarket(targetMarket.marketIndex).price;
|
|
248
234
|
|
|
249
|
-
const perpLiabilityValue = calculatePerpLiabilityValue(
|
|
250
|
-
baseSize,
|
|
251
|
-
price,
|
|
252
|
-
isVariant(targetMarket.contractType, 'prediction')
|
|
253
|
-
);
|
|
235
|
+
const perpLiabilityValue = calculatePerpLiabilityValue(baseSize, price);
|
|
254
236
|
|
|
255
237
|
const marginRequired = new BN(
|
|
256
238
|
calculateMarketMarginRatio(
|
|
257
239
|
targetMarket,
|
|
258
240
|
baseSize.abs(),
|
|
259
241
|
'Initial',
|
|
260
|
-
userMaxMarginRatio
|
|
261
|
-
userHighLeverageMode
|
|
242
|
+
userMaxMarginRatio
|
|
262
243
|
)
|
|
263
244
|
)
|
|
264
245
|
.mul(perpLiabilityValue)
|
|
@@ -278,7 +259,6 @@ export function calculateCollateralDepositRequiredForTrade(
|
|
|
278
259
|
baseSize: BN,
|
|
279
260
|
collateralIndex: number,
|
|
280
261
|
userMaxMarginRatio?: number,
|
|
281
|
-
userHighLeverageMode?: boolean,
|
|
282
262
|
estEntryPrice?: BN
|
|
283
263
|
): BN {
|
|
284
264
|
const marginRequiredUsdc = calculateMarginUSDCRequiredForTrade(
|
|
@@ -286,7 +266,6 @@ export function calculateCollateralDepositRequiredForTrade(
|
|
|
286
266
|
targetMarketIndex,
|
|
287
267
|
baseSize,
|
|
288
268
|
userMaxMarginRatio,
|
|
289
|
-
userHighLeverageMode,
|
|
290
269
|
estEntryPrice
|
|
291
270
|
);
|
|
292
271
|
|
|
@@ -387,37 +366,3 @@ export function calculateUserMaxPerpOrderSize(
|
|
|
387
366
|
|
|
388
367
|
return user.getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide);
|
|
389
368
|
}
|
|
390
|
-
|
|
391
|
-
export function calcHighLeverageModeInitialMarginRatioFromSize(
|
|
392
|
-
preSizeAdjMarginRatio: BN,
|
|
393
|
-
sizeAdjMarginRatio: BN,
|
|
394
|
-
defaultMarginRatio: BN
|
|
395
|
-
): BN {
|
|
396
|
-
let result: BN;
|
|
397
|
-
|
|
398
|
-
if (sizeAdjMarginRatio.lt(preSizeAdjMarginRatio)) {
|
|
399
|
-
const sizePctDiscountFactor = PERCENTAGE_PRECISION.sub(
|
|
400
|
-
preSizeAdjMarginRatio
|
|
401
|
-
.sub(sizeAdjMarginRatio)
|
|
402
|
-
.mul(PERCENTAGE_PRECISION)
|
|
403
|
-
.div(preSizeAdjMarginRatio.div(new BN(5)))
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
const hlmMarginDelta = BN.max(
|
|
407
|
-
preSizeAdjMarginRatio.sub(defaultMarginRatio),
|
|
408
|
-
new BN(1)
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
const hlmMarginDeltaProportion = hlmMarginDelta
|
|
412
|
-
.mul(sizePctDiscountFactor)
|
|
413
|
-
.div(PERCENTAGE_PRECISION);
|
|
414
|
-
|
|
415
|
-
result = hlmMarginDeltaProportion.add(defaultMarginRatio);
|
|
416
|
-
} else if (sizeAdjMarginRatio.eq(preSizeAdjMarginRatio)) {
|
|
417
|
-
result = defaultMarginRatio;
|
|
418
|
-
} else {
|
|
419
|
-
result = sizeAdjMarginRatio;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return result;
|
|
423
|
-
}
|
package/src/math/market.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
calculateSizeDiscountAssetWeight,
|
|
21
21
|
calculateSizePremiumLiabilityWeight,
|
|
22
|
-
calcHighLeverageModeInitialMarginRatioFromSize,
|
|
23
22
|
} from './margin';
|
|
24
23
|
import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
|
|
25
24
|
import {
|
|
@@ -70,7 +69,6 @@ export function calculateBidPrice(
|
|
|
70
69
|
market.amm,
|
|
71
70
|
PositionDirection.SHORT,
|
|
72
71
|
mmOraclePriceData,
|
|
73
|
-
undefined,
|
|
74
72
|
latestSlot
|
|
75
73
|
);
|
|
76
74
|
|
|
@@ -93,7 +91,6 @@ export function calculateAskPrice(
|
|
|
93
91
|
market.amm,
|
|
94
92
|
PositionDirection.LONG,
|
|
95
93
|
mmOraclePriceData,
|
|
96
|
-
undefined,
|
|
97
94
|
latestSlot
|
|
98
95
|
);
|
|
99
96
|
|
|
@@ -141,31 +138,17 @@ export function calculateMarketMarginRatio(
|
|
|
141
138
|
market: PerpMarketAccount,
|
|
142
139
|
size: BN,
|
|
143
140
|
marginCategory: MarginCategory,
|
|
144
|
-
customMarginRatio = 0
|
|
145
|
-
userHighLeverageMode = false
|
|
141
|
+
customMarginRatio = 0
|
|
146
142
|
): number {
|
|
147
143
|
if (market.status === 'Settlement') return 0;
|
|
148
144
|
|
|
149
|
-
const isHighLeverageUser =
|
|
150
|
-
userHighLeverageMode &&
|
|
151
|
-
market.highLeverageMarginRatioInitial > 0 &&
|
|
152
|
-
market.highLeverageMarginRatioMaintenance > 0;
|
|
153
|
-
|
|
154
|
-
const marginRatioInitial = isHighLeverageUser
|
|
155
|
-
? market.highLeverageMarginRatioInitial
|
|
156
|
-
: market.marginRatioInitial;
|
|
157
|
-
|
|
158
|
-
const marginRatioMaintenance = isHighLeverageUser
|
|
159
|
-
? market.highLeverageMarginRatioMaintenance
|
|
160
|
-
: market.marginRatioMaintenance;
|
|
161
|
-
|
|
162
145
|
let defaultMarginRatio: number;
|
|
163
146
|
switch (marginCategory) {
|
|
164
147
|
case 'Initial':
|
|
165
|
-
defaultMarginRatio = marginRatioInitial;
|
|
148
|
+
defaultMarginRatio = market.marginRatioInitial;
|
|
166
149
|
break;
|
|
167
150
|
case 'Maintenance':
|
|
168
|
-
defaultMarginRatio = marginRatioMaintenance;
|
|
151
|
+
defaultMarginRatio = market.marginRatioMaintenance;
|
|
169
152
|
break;
|
|
170
153
|
default:
|
|
171
154
|
throw new Error('Invalid margin category');
|
|
@@ -173,42 +156,15 @@ export function calculateMarketMarginRatio(
|
|
|
173
156
|
|
|
174
157
|
let marginRatio: number;
|
|
175
158
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const sizeAdjMarginRatio = calculateSizePremiumLiabilityWeight(
|
|
189
|
-
size,
|
|
190
|
-
new BN(market.imfFactor),
|
|
191
|
-
new BN(preSizeAdjMarginRatio),
|
|
192
|
-
MARGIN_PRECISION,
|
|
193
|
-
false
|
|
194
|
-
).toNumber();
|
|
195
|
-
|
|
196
|
-
marginRatio = calcHighLeverageModeInitialMarginRatioFromSize(
|
|
197
|
-
new BN(preSizeAdjMarginRatio),
|
|
198
|
-
new BN(sizeAdjMarginRatio),
|
|
199
|
-
new BN(defaultMarginRatio)
|
|
200
|
-
).toNumber();
|
|
201
|
-
} else {
|
|
202
|
-
const sizeAdjMarginRatio = calculateSizePremiumLiabilityWeight(
|
|
203
|
-
size,
|
|
204
|
-
new BN(market.imfFactor),
|
|
205
|
-
new BN(defaultMarginRatio),
|
|
206
|
-
MARGIN_PRECISION,
|
|
207
|
-
true
|
|
208
|
-
).toNumber();
|
|
209
|
-
|
|
210
|
-
marginRatio = Math.max(defaultMarginRatio, sizeAdjMarginRatio);
|
|
211
|
-
}
|
|
159
|
+
const sizeAdjMarginRatio = calculateSizePremiumLiabilityWeight(
|
|
160
|
+
size,
|
|
161
|
+
new BN(market.imfFactor),
|
|
162
|
+
new BN(defaultMarginRatio),
|
|
163
|
+
MARGIN_PRECISION,
|
|
164
|
+
true
|
|
165
|
+
).toNumber();
|
|
166
|
+
|
|
167
|
+
marginRatio = Math.max(defaultMarginRatio, sizeAdjMarginRatio);
|
|
212
168
|
|
|
213
169
|
if (marginCategory === 'Initial') {
|
|
214
170
|
marginRatio = Math.max(marginRatio, customMarginRatio);
|
|
@@ -376,19 +332,9 @@ export function calculateAvailablePerpLiquidity(
|
|
|
376
332
|
}
|
|
377
333
|
|
|
378
334
|
export function calculatePerpMarketBaseLiquidatorFee(
|
|
379
|
-
market: PerpMarketAccount
|
|
380
|
-
userHighLeverageMode: boolean
|
|
335
|
+
market: PerpMarketAccount
|
|
381
336
|
): number {
|
|
382
|
-
|
|
383
|
-
const marginRatio = market.highLeverageMarginRatioMaintenance * 100;
|
|
384
|
-
// min(liquidator_fee, .8 * high_leverage_margin_ratio_maintenance)
|
|
385
|
-
return Math.min(
|
|
386
|
-
market.liquidatorFee,
|
|
387
|
-
marginRatio - Math.floor(marginRatio / 5)
|
|
388
|
-
);
|
|
389
|
-
} else {
|
|
390
|
-
return market.liquidatorFee;
|
|
391
|
-
}
|
|
337
|
+
return market.liquidatorFee;
|
|
392
338
|
}
|
|
393
339
|
|
|
394
340
|
/**
|
|
@@ -449,7 +395,7 @@ function getLastFundingBasis(
|
|
|
449
395
|
.div(market.amm.lastFundingOracleTwap)
|
|
450
396
|
.muln(24);
|
|
451
397
|
const lastFundingRatePreAdj = lastFundingRate.sub(
|
|
452
|
-
FUNDING_RATE_PRECISION.div(new BN(
|
|
398
|
+
FUNDING_RATE_PRECISION.div(new BN(3333)) // FUNDING_RATE_OFFSET_PERCENTAGE
|
|
453
399
|
);
|
|
454
400
|
const timeLeftUntilFundingUpdate = BN.min(
|
|
455
401
|
BN.max(now.sub(market.amm.lastFundingRateTs), ZERO),
|
package/src/math/oracles.ts
CHANGED
|
@@ -109,12 +109,7 @@ export function getOracleValidity(
|
|
|
109
109
|
let isStaleForMargin = oracleDelay.gt(
|
|
110
110
|
new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin)
|
|
111
111
|
);
|
|
112
|
-
if (
|
|
113
|
-
isOneOfVariant(market.amm.oracleSource, [
|
|
114
|
-
'pythStableCoinPull',
|
|
115
|
-
'pythLazerStableCoin',
|
|
116
|
-
])
|
|
117
|
-
) {
|
|
112
|
+
if (isVariant(market.amm.oracleSource, 'pythLazerStableCoin')) {
|
|
118
113
|
isStaleForMargin = oracleDelay.gt(
|
|
119
114
|
new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin).muln(3)
|
|
120
115
|
);
|
|
@@ -324,31 +319,20 @@ export function getMultipleBetweenOracleSources(
|
|
|
324
319
|
secondOracleSource: OracleSource
|
|
325
320
|
): { numerator: BN; denominator: BN } {
|
|
326
321
|
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (
|
|
341
|
-
isVariant(firstOracleSource, 'pyth1MPull') &&
|
|
342
|
-
isVariant(secondOracleSource, 'pythPull')
|
|
343
|
-
) {
|
|
344
|
-
return { numerator: new BN(1), denominator: new BN(1000000) };
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (
|
|
348
|
-
isVariant(firstOracleSource, 'pyth1KPull') &&
|
|
349
|
-
isVariant(secondOracleSource, 'pythPull')
|
|
322
|
+
isOneOfVariant(firstOracleSource, [
|
|
323
|
+
'pythPull',
|
|
324
|
+
'pyth1KPull',
|
|
325
|
+
'pyth1MPull',
|
|
326
|
+
'pythStableCoinPull',
|
|
327
|
+
]) ||
|
|
328
|
+
isOneOfVariant(secondOracleSource, [
|
|
329
|
+
'pythPull',
|
|
330
|
+
'pyth1KPull',
|
|
331
|
+
'pyth1MPull',
|
|
332
|
+
'pythStableCoinPull',
|
|
333
|
+
])
|
|
350
334
|
) {
|
|
351
|
-
|
|
335
|
+
throw new Error('Pyth pull oracle support has been removed from the SDK');
|
|
352
336
|
}
|
|
353
337
|
|
|
354
338
|
if (
|
package/src/math/position.ts
CHANGED
package/src/math/trade.ts
CHANGED
|
@@ -117,7 +117,6 @@ export function calculateTradeSlippage(
|
|
|
117
117
|
market.amm,
|
|
118
118
|
direction,
|
|
119
119
|
mmOraclePriceData,
|
|
120
|
-
undefined,
|
|
121
120
|
latestSlot
|
|
122
121
|
);
|
|
123
122
|
amm = {
|
|
@@ -189,7 +188,6 @@ export function calculateTradeAcquiredAmounts(
|
|
|
189
188
|
market.amm,
|
|
190
189
|
direction,
|
|
191
190
|
mmOraclePriceData,
|
|
192
|
-
undefined,
|
|
193
191
|
latestSlot
|
|
194
192
|
);
|
|
195
193
|
amm = {
|
|
@@ -280,7 +278,6 @@ export function calculateTargetPriceTrade(
|
|
|
280
278
|
market.amm,
|
|
281
279
|
direction,
|
|
282
280
|
mmOraclePriceData,
|
|
283
|
-
undefined,
|
|
284
281
|
latestSlot
|
|
285
282
|
);
|
|
286
283
|
baseAssetReserveBefore = baseAssetReserve;
|
|
@@ -443,7 +440,6 @@ export function calculateEstimatedPerpEntryPrice(
|
|
|
443
440
|
market.amm,
|
|
444
441
|
direction,
|
|
445
442
|
mmOraclePriceData,
|
|
446
|
-
undefined,
|
|
447
443
|
new BN(slot)
|
|
448
444
|
);
|
|
449
445
|
const amm = {
|
package/src/memcmp.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import bs58 from 'bs58';
|
|
3
|
-
import { BorshAccountsCoder } from '@coral-xyz/anchor';
|
|
3
|
+
import { BorshAccountsCoder } from '@coral-xyz/anchor-29';
|
|
4
4
|
import { encodeName } from './userName';
|
|
5
5
|
|
|
6
6
|
export function getUserFilter(): MemcmpFilter {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
3
|
import { PRICE_PRECISION } from '../constants/numericConstants';
|
|
4
|
-
import { AnchorProvider, BN, Idl, Program, Wallet } from '@coral-xyz/anchor';
|
|
4
|
+
import { AnchorProvider, BN, Idl, Program, Wallet } from '@coral-xyz/anchor-29';
|
|
5
5
|
import { L2Level, L2OrderBookGenerator } from '../dlob/orderBookLevels';
|
|
6
6
|
import { Market, OpenBookV2Client } from '@openbook-dex/openbook-v2';
|
|
7
7
|
import openbookV2Idl from '../idl/openbook.json';
|
|
@@ -2,7 +2,7 @@ import { OracleClient } from './types';
|
|
|
2
2
|
import { OracleSource } from '../types';
|
|
3
3
|
import { getOracleClient } from '../factory/oracleClient';
|
|
4
4
|
import { Connection } from '@solana/web3.js';
|
|
5
|
-
import {
|
|
5
|
+
import { DriftProgram } from '../config';
|
|
6
6
|
|
|
7
7
|
export class OracleClientCache {
|
|
8
8
|
cache = new Map<string, OracleClient>();
|
|
@@ -11,7 +11,7 @@ export class OracleClientCache {
|
|
|
11
11
|
public get(
|
|
12
12
|
oracleSource: OracleSource,
|
|
13
13
|
connection: Connection,
|
|
14
|
-
program:
|
|
14
|
+
program: DriftProgram
|
|
15
15
|
) {
|
|
16
16
|
const key = Object.keys(oracleSource)[0];
|
|
17
17
|
if (this.cache.has(key)) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { OracleClient, OraclePriceData } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import { DriftProgram } from '../config';
|
|
4
4
|
import { PrelaunchOracle } from '../types';
|
|
5
5
|
|
|
6
6
|
export class PrelaunchOracleClient implements OracleClient {
|
|
7
7
|
private connection: Connection;
|
|
8
|
-
private program:
|
|
8
|
+
private program: DriftProgram;
|
|
9
9
|
|
|
10
|
-
public constructor(connection: Connection, program:
|
|
10
|
+
public constructor(connection: Connection, program: DriftProgram) {
|
|
11
11
|
this.connection = connection;
|
|
12
12
|
this.program = program;
|
|
13
13
|
}
|
|
@@ -20,11 +20,12 @@ export class PrelaunchOracleClient implements OracleClient {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
|
|
23
|
-
const prelaunchOracle =
|
|
24
|
-
this.program.account
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const prelaunchOracle = (
|
|
24
|
+
this.program.account as any
|
|
25
|
+
).prelaunchOracle.coder.accounts.decodeUnchecked(
|
|
26
|
+
'prelaunchOracle',
|
|
27
|
+
buffer
|
|
28
|
+
) as PrelaunchOracle;
|
|
28
29
|
|
|
29
30
|
return {
|
|
30
31
|
price: prelaunchOracle.price,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { OracleClient, OraclePriceData } from './types';
|
|
3
|
-
import { AnchorProvider, BN,
|
|
3
|
+
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
4
|
+
import { Drift } from '../idl/drift';
|
|
5
|
+
import { DriftProgram } from '../config';
|
|
4
6
|
import {
|
|
5
7
|
ONE,
|
|
6
8
|
PRICE_PRECISION,
|
|
7
9
|
QUOTE_PRECISION,
|
|
8
10
|
TEN,
|
|
9
11
|
} from '../constants/numericConstants';
|
|
10
|
-
import { DRIFT_PROGRAM_ID } from '../config';
|
|
11
12
|
import { Wallet } from '../wallet';
|
|
12
13
|
import driftIDL from '../idl/drift.json';
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ export class PythLazerClient implements OracleClient {
|
|
|
15
16
|
private connection: Connection;
|
|
16
17
|
private multiple: BN;
|
|
17
18
|
private stableCoin: boolean;
|
|
18
|
-
private program:
|
|
19
|
+
private program: DriftProgram;
|
|
19
20
|
readonly decodeFunc: (name: string, data: Buffer) => any;
|
|
20
21
|
|
|
21
22
|
public constructor(
|
|
@@ -34,15 +35,12 @@ export class PythLazerClient implements OracleClient {
|
|
|
34
35
|
commitment: connection.commitment,
|
|
35
36
|
}
|
|
36
37
|
);
|
|
37
|
-
this.program = new Program(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
this.program = new Program<Drift>(driftIDL as Drift, provider);
|
|
39
|
+
this.decodeFunc = (
|
|
40
|
+
this.program.account as any
|
|
41
|
+
).pythLazerOracle.coder.accounts.decodeUnchecked.bind(
|
|
42
|
+
(this.program.account as any).pythLazerOracle.coder.accounts
|
|
41
43
|
);
|
|
42
|
-
this.decodeFunc =
|
|
43
|
-
this.program.account.pythLazerOracle.coder.accounts.decodeUnchecked.bind(
|
|
44
|
-
this.program.account.pythLazerOracle.coder.accounts
|
|
45
|
-
);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
public async getOraclePriceData(
|
|
@@ -53,7 +51,7 @@ export class PythLazerClient implements OracleClient {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
|
|
56
|
-
const priceData = this.decodeFunc('
|
|
54
|
+
const priceData = this.decodeFunc('pythLazerOracle', buffer);
|
|
57
55
|
const confidence = convertPythPrice(
|
|
58
56
|
priceData.conf,
|
|
59
57
|
priceData.exponent,
|
package/src/oracles/types.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oracle types and the OraclePriceData interface used throughout the SDK.
|
|
3
|
+
* Each oracle source (Pyth, Switchboard, Pyth Lazer, Prelaunch) has a client adapter
|
|
4
|
+
* in this directory that fetches and normalises prices into OraclePriceData.
|
|
5
|
+
* Oracle client selection is configured via DriftClientConfig and cached in OracleClientCache.
|
|
6
|
+
*/
|
|
1
7
|
import { BN } from '@coral-xyz/anchor';
|
|
2
8
|
import { PublicKey } from '@solana/web3.js';
|
|
3
9
|
import { OracleSource } from '../types';
|
package/src/orderParams.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
DefaultOrderParams,
|
|
3
3
|
OptionalOrderParams,
|
|
4
4
|
OrderParams,
|
|
5
|
-
OrderParamsBitFlag,
|
|
6
5
|
OrderTriggerCondition,
|
|
7
6
|
OrderType,
|
|
8
7
|
} from './types';
|
|
@@ -78,7 +77,3 @@ export function getOrderParams(
|
|
|
78
77
|
overridingParams
|
|
79
78
|
);
|
|
80
79
|
}
|
|
81
|
-
|
|
82
|
-
export function isUpdateHighLeverageMode(bitFlags: number): boolean {
|
|
83
|
-
return (bitFlags & OrderParamsBitFlag.UpdateHighLeverageMode) !== 0;
|
|
84
|
-
}
|