@drift-labs/sdk-browser 2.162.0-beta.2 → 2.163.0-beta.10
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 +21406 -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 +21407 -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 +21406 -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/lib/node/user.js
CHANGED
|
@@ -185,7 +185,6 @@ class User {
|
|
|
185
185
|
settledPnl: numericConstants_1.ZERO,
|
|
186
186
|
lpShares: numericConstants_1.ZERO,
|
|
187
187
|
lastQuoteAssetAmountPerLp: numericConstants_1.ZERO,
|
|
188
|
-
perLpBase: 0,
|
|
189
188
|
maxMarginRatio: 0,
|
|
190
189
|
isolatedPositionScaledBalance: numericConstants_1.ZERO,
|
|
191
190
|
positionFlag: 0,
|
|
@@ -303,7 +302,7 @@ class User {
|
|
|
303
302
|
* calculates Buying Power = free collateral / initial margin ratio
|
|
304
303
|
* @returns : Precision QUOTE_PRECISION
|
|
305
304
|
*/
|
|
306
|
-
getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO,
|
|
305
|
+
getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO, maxMarginRatio = undefined, positionType = 'cross') {
|
|
307
306
|
const perpPosition = this.getPerpPositionOrEmpty(marketIndex);
|
|
308
307
|
const perpMarket = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
309
308
|
const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
|
|
@@ -315,27 +314,26 @@ class User {
|
|
|
315
314
|
if (positionType === 'isolated') {
|
|
316
315
|
const { totalAssetValue: quoteSpotMarketAssetValue, totalLiabilityValue: quoteSpotMarketLiabilityValue, } = this.getSpotMarketAssetAndLiabilityValue(perpMarket.quoteSpotMarketIndex, 'Initial', undefined, undefined, true);
|
|
317
316
|
const usdcAvailableForIsolatedMargin = quoteSpotMarketAssetValue.sub(quoteSpotMarketLiabilityValue);
|
|
318
|
-
const generalFreeCollateral = this.getFreeCollateral('Initial',
|
|
317
|
+
const generalFreeCollateral = this.getFreeCollateral('Initial', undefined);
|
|
319
318
|
freeCollateral = anchor_1.BN.min(usdcAvailableForIsolatedMargin, generalFreeCollateral).sub(collateralBuffer);
|
|
320
319
|
}
|
|
321
320
|
else {
|
|
322
321
|
// free collateral from the cross account only
|
|
323
|
-
freeCollateral = this.getFreeCollateral('Initial',
|
|
322
|
+
freeCollateral = this.getFreeCollateral('Initial', undefined).sub(collateralBuffer);
|
|
324
323
|
}
|
|
325
|
-
return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount,
|
|
324
|
+
return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, maxMarginRatio || perpPosition.maxMarginRatio);
|
|
326
325
|
}
|
|
327
|
-
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount,
|
|
326
|
+
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, perpMarketMaxMarginRatio = undefined) {
|
|
328
327
|
const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
329
|
-
const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio
|
|
328
|
+
const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio);
|
|
330
329
|
return freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new anchor_1.BN(marginRatio));
|
|
331
330
|
}
|
|
332
331
|
/**
|
|
333
332
|
* calculates Free Collateral = Total collateral - margin requirement
|
|
334
333
|
* @returns : Precision QUOTE_PRECISION
|
|
335
334
|
*/
|
|
336
|
-
getFreeCollateral(marginCategory = 'Initial',
|
|
335
|
+
getFreeCollateral(marginCategory = 'Initial', perpMarketIndex) {
|
|
337
336
|
const calc = this.getMarginCalculation(marginCategory, {
|
|
338
|
-
enteringHighLeverage: enterHighLeverageMode,
|
|
339
337
|
strict: marginCategory === 'Initial',
|
|
340
338
|
});
|
|
341
339
|
if (perpMarketIndex !== undefined) {
|
|
@@ -351,7 +349,7 @@ class User {
|
|
|
351
349
|
return calc.getCrossFreeCollateral();
|
|
352
350
|
}
|
|
353
351
|
}
|
|
354
|
-
getMarginRequirement(marginCategory, liquidationBuffer, strict, includeOpenOrders,
|
|
352
|
+
getMarginRequirement(marginCategory, liquidationBuffer, strict, includeOpenOrders, perpMarketIndex) {
|
|
355
353
|
const liquidationBufferMap = new Map();
|
|
356
354
|
if (liquidationBuffer && perpMarketIndex !== undefined) {
|
|
357
355
|
liquidationBufferMap.set(perpMarketIndex, liquidationBuffer);
|
|
@@ -362,7 +360,6 @@ class User {
|
|
|
362
360
|
const marginCalc = this.getMarginCalculation(marginCategory, {
|
|
363
361
|
strict,
|
|
364
362
|
includeOpenOrders,
|
|
365
|
-
enteringHighLeverage,
|
|
366
363
|
liquidationBufferMap,
|
|
367
364
|
});
|
|
368
365
|
// If perpMarketIndex is provided, compute only for that market index
|
|
@@ -385,8 +382,8 @@ class User {
|
|
|
385
382
|
/**
|
|
386
383
|
* @returns The initial margin requirement in USDC. : QUOTE_PRECISION
|
|
387
384
|
*/
|
|
388
|
-
getInitialMarginRequirement(
|
|
389
|
-
return this.getMarginRequirement('Initial', undefined, true, undefined,
|
|
385
|
+
getInitialMarginRequirement(perpMarketIndex) {
|
|
386
|
+
return this.getMarginRequirement('Initial', undefined, true, undefined, perpMarketIndex);
|
|
390
387
|
}
|
|
391
388
|
/**
|
|
392
389
|
* @returns The maintenance margin requirement in USDC. : QUOTE_PRECISION
|
|
@@ -394,7 +391,6 @@ class User {
|
|
|
394
391
|
getMaintenanceMarginRequirement(liquidationBuffer, perpMarketIndex) {
|
|
395
392
|
return this.getMarginRequirement('Maintenance', liquidationBuffer, false, // strict default
|
|
396
393
|
true, // includeOpenOrders default
|
|
397
|
-
false, // enteringHighLeverage default
|
|
398
394
|
perpMarketIndex);
|
|
399
395
|
}
|
|
400
396
|
getActivePerpPositionsForUserAccount(userAccount) {
|
|
@@ -721,7 +717,7 @@ class User {
|
|
|
721
717
|
}
|
|
722
718
|
return health;
|
|
723
719
|
}
|
|
724
|
-
calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false
|
|
720
|
+
calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
|
|
725
721
|
const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
|
|
726
722
|
let valuationPrice = this.getOracleDataForPerpMarket(market.marketIndex).price;
|
|
727
723
|
if ((0, types_1.isVariant)(market.status, 'settlement')) {
|
|
@@ -736,14 +732,11 @@ class User {
|
|
|
736
732
|
}
|
|
737
733
|
else {
|
|
738
734
|
baseAssetAmount = perpPosition.baseAssetAmount;
|
|
739
|
-
liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, valuationPrice
|
|
735
|
+
liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, valuationPrice);
|
|
740
736
|
}
|
|
741
737
|
if (marginCategory) {
|
|
742
738
|
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
743
|
-
let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory,
|
|
744
|
-
? Math.max(market.marginRatioInitial, userCustomMargin)
|
|
745
|
-
: userCustomMargin, this.isHighLeverageMode(marginCategory) ||
|
|
746
|
-
enteringHighLeverage === true));
|
|
739
|
+
let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin));
|
|
747
740
|
if (liquidationBuffer !== undefined) {
|
|
748
741
|
marginRatio = marginRatio.add(liquidationBuffer);
|
|
749
742
|
}
|
|
@@ -782,9 +775,9 @@ class User {
|
|
|
782
775
|
* calculates sum of position value across all positions in margin system
|
|
783
776
|
* @returns : Precision QUOTE_PRECISION
|
|
784
777
|
*/
|
|
785
|
-
getTotalPerpPositionLiability(marginCategory, liquidationBuffer, includeOpenOrders, strict = false
|
|
778
|
+
getTotalPerpPositionLiability(marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
|
|
786
779
|
return this.getActivePerpPositions().reduce((totalPerpValue, perpPosition) => {
|
|
787
|
-
const baseAssetValue = this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict
|
|
780
|
+
const baseAssetValue = this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict);
|
|
788
781
|
return totalPerpValue.add(baseAssetValue);
|
|
789
782
|
}, numericConstants_1.ZERO);
|
|
790
783
|
}
|
|
@@ -808,7 +801,7 @@ class User {
|
|
|
808
801
|
return (0, margin_1.calculateWorstCasePerpLiabilityValue)(userPosition, market, oraclePriceData.price).worstCaseLiabilityValue;
|
|
809
802
|
}
|
|
810
803
|
else {
|
|
811
|
-
return (0, margin_1.calculatePerpLiabilityValue)(userPosition.baseAssetAmount, oraclePriceData.price
|
|
804
|
+
return (0, margin_1.calculatePerpLiabilityValue)(userPosition.baseAssetAmount, oraclePriceData.price);
|
|
812
805
|
}
|
|
813
806
|
}
|
|
814
807
|
getPositionSide(currentPosition) {
|
|
@@ -973,10 +966,9 @@ class User {
|
|
|
973
966
|
* for large sizes where imf factor activates, result is a lower bound
|
|
974
967
|
* @param marginCategory {Initial, Maintenance}
|
|
975
968
|
* @param isLp if calculating max leveraging for adding lp, need to add buffer
|
|
976
|
-
* @param enterHighLeverageMode can pass this as true to calculate max leverage if the user was to enter high leverage mode
|
|
977
969
|
* @returns : Precision TEN_THOUSAND
|
|
978
970
|
*/
|
|
979
|
-
getMaxLeverageForPerp(perpMarketIndex, _marginCategory = 'Initial', isLp = false
|
|
971
|
+
getMaxLeverageForPerp(perpMarketIndex, _marginCategory = 'Initial', isLp = false) {
|
|
980
972
|
const market = this.driftClient.getPerpMarketAccount(perpMarketIndex);
|
|
981
973
|
const marketPrice = this.driftClient.getOracleDataForPerpMarket(perpMarketIndex).price;
|
|
982
974
|
const { perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue } = this.getLeverageComponents();
|
|
@@ -990,7 +982,7 @@ class User {
|
|
|
990
982
|
? marketPrice.mul(market.amm.orderStepSize).div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
991
983
|
: numericConstants_1.ZERO;
|
|
992
984
|
// absolute max fesible size (upper bound)
|
|
993
|
-
const maxSizeQuote = anchor_1.BN.max(anchor_1.BN.min(this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.LONG, false
|
|
985
|
+
const maxSizeQuote = anchor_1.BN.max(anchor_1.BN.min(this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.LONG, false).tradeSize, this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.SHORT, false).tradeSize).sub(lpBuffer), numericConstants_1.ZERO);
|
|
994
986
|
return totalLiabilityValue
|
|
995
987
|
.add(maxSizeQuote)
|
|
996
988
|
.mul(numericConstants_1.TEN_THOUSAND)
|
|
@@ -1150,11 +1142,6 @@ class User {
|
|
|
1150
1142
|
isBankrupt() {
|
|
1151
1143
|
return (this.getUserAccount().status & types_1.UserStatus.BANKRUPT) > 0;
|
|
1152
1144
|
}
|
|
1153
|
-
isHighLeverageMode(marginCategory) {
|
|
1154
|
-
return ((0, types_1.isVariant)(this.getUserAccount().marginMode, 'highLeverage') ||
|
|
1155
|
-
(marginCategory === 'Maintenance' &&
|
|
1156
|
-
(0, types_1.isVariant)(this.getUserAccount().marginMode, 'highLeverageMaintenance')));
|
|
1157
|
-
}
|
|
1158
1145
|
/**
|
|
1159
1146
|
* Checks if any user position cumulative funding differs from respective market cumulative funding
|
|
1160
1147
|
* @returns
|
|
@@ -1233,7 +1220,7 @@ class User {
|
|
|
1233
1220
|
* @param offsetCollateral // allows calculating the liquidation price after this offset collateral is added to the user's account (e.g. : what will the liquidation price be for this position AFTER I deposit $x worth of collateral)
|
|
1234
1221
|
* @returns Precision : PRICE_PRECISION
|
|
1235
1222
|
*/
|
|
1236
|
-
liquidationPrice(marketIndex, positionBaseSizeChange = numericConstants_1.ZERO, estimatedEntryPrice = numericConstants_1.ZERO, marginCategory = 'Maintenance', includeOpenOrders = false, offsetCollateral = numericConstants_1.ZERO,
|
|
1223
|
+
liquidationPrice(marketIndex, positionBaseSizeChange = numericConstants_1.ZERO, estimatedEntryPrice = numericConstants_1.ZERO, marginCategory = 'Maintenance', includeOpenOrders = false, offsetCollateral = numericConstants_1.ZERO, marginType) {
|
|
1237
1224
|
const market = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
1238
1225
|
const oracle = this.driftClient.getPerpMarketAccount(marketIndex).amm.oracle;
|
|
1239
1226
|
const oraclePrice = this.driftClient.getOracleDataForPerpMarket(marketIndex).price;
|
|
@@ -1242,14 +1229,13 @@ class User {
|
|
|
1242
1229
|
const marginCalculation = this.getMarginCalculation(marginCategory, {
|
|
1243
1230
|
strict: false,
|
|
1244
1231
|
includeOpenOrders,
|
|
1245
|
-
enteringHighLeverage,
|
|
1246
1232
|
});
|
|
1247
1233
|
const isolatedMarginCalculation = marginCalculation.isolatedMarginCalculations.get(marketIndex);
|
|
1248
1234
|
if (!isolatedMarginCalculation)
|
|
1249
1235
|
return new anchor_1.BN(-1);
|
|
1250
1236
|
const { totalCollateral, marginRequirement } = isolatedMarginCalculation;
|
|
1251
1237
|
const freeCollateral = anchor_1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(marginRequirement)).add(offsetCollateral);
|
|
1252
|
-
const freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders
|
|
1238
|
+
const freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders);
|
|
1253
1239
|
if (!freeCollateralDelta || freeCollateralDelta.eq(numericConstants_1.ZERO)) {
|
|
1254
1240
|
return new anchor_1.BN(-1);
|
|
1255
1241
|
}
|
|
@@ -1263,12 +1249,12 @@ class User {
|
|
|
1263
1249
|
return liqPrice;
|
|
1264
1250
|
}
|
|
1265
1251
|
const totalCollateral = this.getTotalCollateral(marginCategory, false, includeOpenOrders);
|
|
1266
|
-
const marginRequirement = this.getMarginRequirement(marginCategory, undefined, false, includeOpenOrders
|
|
1252
|
+
const marginRequirement = this.getMarginRequirement(marginCategory, undefined, false, includeOpenOrders);
|
|
1267
1253
|
let freeCollateral = anchor_1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(marginRequirement)).add(offsetCollateral);
|
|
1268
1254
|
positionBaseSizeChange = (0, orders_1.standardizeBaseAssetAmount)(positionBaseSizeChange, market.amm.orderStepSize);
|
|
1269
|
-
const freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(market, oraclePrice, currentPerpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders
|
|
1255
|
+
const freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(market, oraclePrice, currentPerpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders);
|
|
1270
1256
|
freeCollateral = freeCollateral.add(freeCollateralChangeFromNewPosition);
|
|
1271
|
-
let freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders
|
|
1257
|
+
let freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders);
|
|
1272
1258
|
if (!freeCollateralDelta) {
|
|
1273
1259
|
return new anchor_1.BN(-1);
|
|
1274
1260
|
}
|
|
@@ -1301,7 +1287,7 @@ class User {
|
|
|
1301
1287
|
}
|
|
1302
1288
|
return liqPrice;
|
|
1303
1289
|
}
|
|
1304
|
-
calculateEntriesEffectOnFreeCollateral(market, oraclePrice, perpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders,
|
|
1290
|
+
calculateEntriesEffectOnFreeCollateral(market, oraclePrice, perpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders, marginCategory = 'Maintenance') {
|
|
1305
1291
|
let freeCollateralChange = numericConstants_1.ZERO;
|
|
1306
1292
|
// update free collateral to account for change in pnl from new position
|
|
1307
1293
|
if (!estimatedEntryPrice.eq(numericConstants_1.ZERO) &&
|
|
@@ -1336,12 +1322,10 @@ class User {
|
|
|
1336
1322
|
}
|
|
1337
1323
|
else {
|
|
1338
1324
|
baseAssetAmount = perpPosition.baseAssetAmount;
|
|
1339
|
-
liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice
|
|
1325
|
+
liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice);
|
|
1340
1326
|
}
|
|
1341
1327
|
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1342
|
-
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory,
|
|
1343
|
-
? Math.max(market.marginRatioInitial, userCustomMargin)
|
|
1344
|
-
: userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
|
|
1328
|
+
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin);
|
|
1345
1329
|
return liabilityValue.mul(new anchor_1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION);
|
|
1346
1330
|
};
|
|
1347
1331
|
const freeCollateralConsumptionBefore = calculateMarginRequirement(perpPosition);
|
|
@@ -1350,7 +1334,7 @@ class User {
|
|
|
1350
1334
|
const freeCollateralConsumptionAfter = calculateMarginRequirement(perpPositionAfter);
|
|
1351
1335
|
return freeCollateralChange.sub(freeCollateralConsumptionAfter.sub(freeCollateralConsumptionBefore));
|
|
1352
1336
|
}
|
|
1353
|
-
calculateFreeCollateralDeltaForPerp(market, perpPosition, positionBaseSizeChange, oraclePrice, marginCategory = 'Maintenance', includeOpenOrders = false
|
|
1337
|
+
calculateFreeCollateralDeltaForPerp(market, perpPosition, positionBaseSizeChange, oraclePrice, marginCategory = 'Maintenance', includeOpenOrders = false) {
|
|
1354
1338
|
const baseAssetAmount = includeOpenOrders
|
|
1355
1339
|
? (0, margin_2.calculateWorstCaseBaseAssetAmount)(perpPosition, market, oraclePrice)
|
|
1356
1340
|
: perpPosition.baseAssetAmount;
|
|
@@ -1358,9 +1342,7 @@ class User {
|
|
|
1358
1342
|
const orderBaseAssetAmount = baseAssetAmount.sub(perpPosition.baseAssetAmount);
|
|
1359
1343
|
const proposedBaseAssetAmount = baseAssetAmount.add(positionBaseSizeChange);
|
|
1360
1344
|
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1361
|
-
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory,
|
|
1362
|
-
? Math.max(market.marginRatioInitial, userCustomMargin)
|
|
1363
|
-
: userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
|
|
1345
|
+
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory, userCustomMargin);
|
|
1364
1346
|
const marginRatioQuotePrecision = new anchor_1.BN(marginRatio)
|
|
1365
1347
|
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
1366
1348
|
.div(numericConstants_1.MARGIN_PRECISION);
|
|
@@ -1368,33 +1350,21 @@ class User {
|
|
|
1368
1350
|
return undefined;
|
|
1369
1351
|
}
|
|
1370
1352
|
let freeCollateralDelta = numericConstants_1.ZERO;
|
|
1371
|
-
if (
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
freeCollateralDelta = marginRatioQuotePrecision.neg();
|
|
1376
|
-
}
|
|
1377
|
-
else if (orderBaseAssetAmount.lt(numericConstants_1.ZERO)) {
|
|
1378
|
-
freeCollateralDelta = marginRatioQuotePrecision;
|
|
1379
|
-
}
|
|
1353
|
+
if (proposedBaseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
1354
|
+
freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.sub(marginRatioQuotePrecision)
|
|
1355
|
+
.mul(proposedBaseAssetAmount)
|
|
1356
|
+
.div(numericConstants_1.BASE_PRECISION);
|
|
1380
1357
|
}
|
|
1381
1358
|
else {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
.div(numericConstants_1.BASE_PRECISION);
|
|
1392
|
-
}
|
|
1393
|
-
if (!orderBaseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
1394
|
-
freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
|
|
1395
|
-
.mul(orderBaseAssetAmount.abs())
|
|
1396
|
-
.div(numericConstants_1.BASE_PRECISION));
|
|
1397
|
-
}
|
|
1359
|
+
freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.neg()
|
|
1360
|
+
.sub(marginRatioQuotePrecision)
|
|
1361
|
+
.mul(proposedBaseAssetAmount.abs())
|
|
1362
|
+
.div(numericConstants_1.BASE_PRECISION);
|
|
1363
|
+
}
|
|
1364
|
+
if (!orderBaseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
1365
|
+
freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
|
|
1366
|
+
.mul(orderBaseAssetAmount.abs())
|
|
1367
|
+
.div(numericConstants_1.BASE_PRECISION));
|
|
1398
1368
|
}
|
|
1399
1369
|
return freeCollateralDelta;
|
|
1400
1370
|
}
|
|
@@ -1435,12 +1405,11 @@ class User {
|
|
|
1435
1405
|
}
|
|
1436
1406
|
getMarginUSDCRequiredForTrade(targetMarketIndex, baseSize, estEntryPrice, perpMarketMaxMarginRatio) {
|
|
1437
1407
|
const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1438
|
-
return (0, margin_2.calculateMarginUSDCRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, maxMarginRatio,
|
|
1408
|
+
return (0, margin_2.calculateMarginUSDCRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, maxMarginRatio, estEntryPrice);
|
|
1439
1409
|
}
|
|
1440
1410
|
getCollateralDepositRequiredForTrade(targetMarketIndex, baseSize, collateralIndex, perpMarketMaxMarginRatio) {
|
|
1441
1411
|
const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1442
|
-
return (0, margin_2.calculateCollateralDepositRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, collateralIndex, maxMarginRatio
|
|
1443
|
-
);
|
|
1412
|
+
return (0, margin_2.calculateCollateralDepositRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, collateralIndex, maxMarginRatio);
|
|
1444
1413
|
}
|
|
1445
1414
|
/**
|
|
1446
1415
|
* Separates the max trade size into two parts:
|
|
@@ -1451,7 +1420,7 @@ class User {
|
|
|
1451
1420
|
* @param isLp
|
|
1452
1421
|
* @returns { tradeSize: BN, oppositeSideTradeSize: BN} : Precision QUOTE_PRECISION
|
|
1453
1422
|
*/
|
|
1454
|
-
getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide, isLp = false,
|
|
1423
|
+
getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide, isLp = false, maxMarginRatio = undefined, positionType = 'cross') {
|
|
1455
1424
|
let tradeSize = numericConstants_1.ZERO;
|
|
1456
1425
|
let oppositeSideTradeSize = numericConstants_1.ZERO;
|
|
1457
1426
|
const currentPosition = this.getPerpPositionOrEmpty(targetMarketIndex);
|
|
@@ -1472,8 +1441,8 @@ class User {
|
|
|
1472
1441
|
// add any position we have on the opposite side of the current trade, because we can "flip" the size of this position without taking any extra leverage.
|
|
1473
1442
|
const oppositeSizeLiabilityValue = targetingSameSide
|
|
1474
1443
|
? numericConstants_1.ZERO
|
|
1475
|
-
: (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price
|
|
1476
|
-
const maxPositionSize = this.getPerpBuyingPower(targetMarketIndex, lpBuffer,
|
|
1444
|
+
: (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price);
|
|
1445
|
+
const maxPositionSize = this.getPerpBuyingPower(targetMarketIndex, lpBuffer, maxMarginRatio, positionType);
|
|
1477
1446
|
if (maxPositionSize.gte(numericConstants_1.ZERO)) {
|
|
1478
1447
|
if (oppositeSizeLiabilityValue.eq(numericConstants_1.ZERO)) {
|
|
1479
1448
|
// case 1 : Regular trade where current total position less than max, and no opposite position to account for
|
|
@@ -1489,10 +1458,9 @@ class User {
|
|
|
1489
1458
|
else {
|
|
1490
1459
|
// current leverage is greater than max leverage - can only reduce position size
|
|
1491
1460
|
if (!targetingSameSide) {
|
|
1492
|
-
const
|
|
1493
|
-
const perpLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price, (0, types_1.isVariant)(market.contractType, 'prediction'));
|
|
1461
|
+
const perpLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price);
|
|
1494
1462
|
const totalCollateral = this.getTotalCollateral();
|
|
1495
|
-
const marginRequirement = this.getInitialMarginRequirement(
|
|
1463
|
+
const marginRequirement = this.getInitialMarginRequirement();
|
|
1496
1464
|
const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1497
1465
|
const marginFreedByClosing = perpLiabilityValue
|
|
1498
1466
|
.mul(new anchor_1.BN(marginRatio))
|
|
@@ -1513,11 +1481,11 @@ class User {
|
|
|
1513
1481
|
tradeSize = maxPositionSize;
|
|
1514
1482
|
}
|
|
1515
1483
|
}
|
|
1516
|
-
const freeCollateral = this.getFreeCollateral('Initial'
|
|
1484
|
+
const freeCollateral = this.getFreeCollateral('Initial');
|
|
1517
1485
|
let baseTradeSize = targetSide === 'long'
|
|
1518
1486
|
? tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price)
|
|
1519
1487
|
: tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price).neg();
|
|
1520
|
-
let freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false,
|
|
1488
|
+
let freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, 'Initial');
|
|
1521
1489
|
while (freeCollateralChangeFromNewPosition.isNeg() &&
|
|
1522
1490
|
freeCollateralChangeFromNewPosition.abs().gt(freeCollateral)) {
|
|
1523
1491
|
tradeSize = tradeSize.mul(new anchor_1.BN(99)).div(new anchor_1.BN(100));
|
|
@@ -1526,7 +1494,7 @@ class User {
|
|
|
1526
1494
|
? tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price)
|
|
1527
1495
|
: tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price).neg();
|
|
1528
1496
|
freeCollateralChangeFromNewPosition =
|
|
1529
|
-
this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false,
|
|
1497
|
+
this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, 'Initial');
|
|
1530
1498
|
}
|
|
1531
1499
|
return { tradeSize, oppositeSideTradeSize };
|
|
1532
1500
|
}
|
|
@@ -1871,9 +1839,6 @@ class User {
|
|
|
1871
1839
|
const state = this.driftClient.getStateAccount();
|
|
1872
1840
|
const feeTierIndex = 0;
|
|
1873
1841
|
if ((0, types_1.isVariant)(marketType, 'perp')) {
|
|
1874
|
-
if (this.isHighLeverageMode('Initial')) {
|
|
1875
|
-
return state.perpFeeStructure.feeTiers[0];
|
|
1876
|
-
}
|
|
1877
1842
|
const userStatsAccount = this.driftClient
|
|
1878
1843
|
.getUserStats()
|
|
1879
1844
|
.getAccount();
|
|
@@ -1924,9 +1889,9 @@ class User {
|
|
|
1924
1889
|
* @param quoteAmount
|
|
1925
1890
|
* @returns feeForQuote : Precision QUOTE_PRECISION
|
|
1926
1891
|
*/
|
|
1927
|
-
calculateFeeForQuoteAmount(quoteAmount, marketIndex
|
|
1892
|
+
calculateFeeForQuoteAmount(quoteAmount, marketIndex) {
|
|
1928
1893
|
if (marketIndex !== undefined) {
|
|
1929
|
-
const takerFeeMultiplier = this.driftClient.getMarketFees(types_2.MarketType.PERP, marketIndex, this
|
|
1894
|
+
const takerFeeMultiplier = this.driftClient.getMarketFees(types_2.MarketType.PERP, marketIndex, this).takerFee;
|
|
1930
1895
|
const feeAmountNum = bigNum_1.BigNum.from(quoteAmount, numericConstants_1.QUOTE_PRECISION_EXP).toNum() *
|
|
1931
1896
|
takerFeeMultiplier;
|
|
1932
1897
|
return bigNum_1.BigNum.fromPrint(feeAmountNum.toString(), numericConstants_1.QUOTE_PRECISION_EXP).val;
|
|
@@ -2158,10 +2123,10 @@ class User {
|
|
|
2158
2123
|
}
|
|
2159
2124
|
else {
|
|
2160
2125
|
worstCaseBaseAmount = perpPosition.baseAssetAmount;
|
|
2161
|
-
worstCaseLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(perpPosition.baseAssetAmount, oraclePrice
|
|
2126
|
+
worstCaseLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(perpPosition.baseAssetAmount, oraclePrice);
|
|
2162
2127
|
}
|
|
2163
2128
|
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
2164
|
-
const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin
|
|
2129
|
+
const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin));
|
|
2165
2130
|
const _quoteOraclePriceData = quoteOraclePriceData ||
|
|
2166
2131
|
this.driftClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
2167
2132
|
let marginRequirement = worstCaseLiabilityValue
|
|
@@ -2317,23 +2282,22 @@ class User {
|
|
|
2317
2282
|
* Consumers can use this to avoid duplicating work across separate calls.
|
|
2318
2283
|
*/
|
|
2319
2284
|
getMarginCalculation(marginCategory = 'Initial', opts) {
|
|
2320
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
2285
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2321
2286
|
const strict = (_a = opts === null || opts === void 0 ? void 0 : opts.strict) !== null && _a !== void 0 ? _a : false;
|
|
2322
|
-
const
|
|
2323
|
-
const
|
|
2324
|
-
const includeOpenOrders = (_d = opts === null || opts === void 0 ? void 0 : opts.includeOpenOrders) !== null && _d !== void 0 ? _d : true;
|
|
2287
|
+
const liquidationBufferMap = (_b = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _b !== void 0 ? _b : new Map();
|
|
2288
|
+
const includeOpenOrders = (_c = opts === null || opts === void 0 ? void 0 : opts.includeOpenOrders) !== null && _c !== void 0 ? _c : true;
|
|
2325
2289
|
// Equivalent to on-chain user_custom_margin_ratio
|
|
2326
2290
|
const userCustomMarginRatio = marginCategory === 'Initial' ? this.getUserAccount().maxMarginRatio : 0;
|
|
2327
2291
|
// Initialize calc via JS mirror of Rust/on-chain MarginCalculation
|
|
2328
2292
|
const isolatedMarginBuffers = new Map();
|
|
2329
|
-
for (const [marketIndex, isolatedMarginBuffer,] of (
|
|
2293
|
+
for (const [marketIndex, isolatedMarginBuffer,] of (_d = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _d !== void 0 ? _d : new Map()) {
|
|
2330
2294
|
if (marketIndex !== 'cross') {
|
|
2331
2295
|
isolatedMarginBuffers.set(marketIndex, isolatedMarginBuffer);
|
|
2332
2296
|
}
|
|
2333
2297
|
}
|
|
2334
2298
|
const ctx = marginCalculation_1.MarginContext.standard(marginCategory)
|
|
2335
2299
|
.strictMode(strict)
|
|
2336
|
-
.setCrossMarginBuffer((
|
|
2300
|
+
.setCrossMarginBuffer((_f = (_e = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) === null || _e === void 0 ? void 0 : _e.get('cross')) !== null && _f !== void 0 ? _f : numericConstants_1.ZERO)
|
|
2337
2301
|
.setIsolatedMarginBuffers(isolatedMarginBuffers);
|
|
2338
2302
|
const calc = new marginCalculation_1.MarginCalculation(ctx);
|
|
2339
2303
|
// SPOT POSITIONS
|
|
@@ -2356,7 +2320,7 @@ class User {
|
|
|
2356
2320
|
}
|
|
2357
2321
|
else {
|
|
2358
2322
|
// borrow on quote contributes to margin requirement
|
|
2359
|
-
const tokenValueAbs = this.getSpotLiabilityValue(tokenAmount, strictOracle, spotMarket, marginCategory, (
|
|
2323
|
+
const tokenValueAbs = this.getSpotLiabilityValue(tokenAmount, strictOracle, spotMarket, marginCategory, (_g = liquidationBufferMap.get('cross')) !== null && _g !== void 0 ? _g : new anchor_1.BN(0)).abs();
|
|
2360
2324
|
calc.addCrossMarginRequirement(tokenValueAbs, tokenValueAbs);
|
|
2361
2325
|
}
|
|
2362
2326
|
continue;
|
|
@@ -2399,7 +2363,7 @@ class User {
|
|
|
2399
2363
|
const { worstCaseBaseAssetAmount, worstCaseLiabilityValue } = (0, margin_1.calculateWorstCasePerpLiabilityValue)(marketPosition, market, nonMmmOraclePriceData.price, includeOpenOrders);
|
|
2400
2364
|
// margin ratio for this perp
|
|
2401
2365
|
const customMarginRatio = Math.max(userCustomMarginRatio, marketPosition.maxMarginRatio);
|
|
2402
|
-
let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, worstCaseBaseAssetAmount.abs(), marginCategory, customMarginRatio
|
|
2366
|
+
let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, worstCaseBaseAssetAmount.abs(), marginCategory, customMarginRatio));
|
|
2403
2367
|
if ((0, types_1.isVariant)(market.status, 'settlement')) {
|
|
2404
2368
|
marginRatio = numericConstants_1.ZERO;
|
|
2405
2369
|
}
|
|
@@ -2443,13 +2407,13 @@ class User {
|
|
|
2443
2407
|
if (isIsolated) {
|
|
2444
2408
|
// derive isolated quote deposit value, mirroring on-chain logic
|
|
2445
2409
|
let depositValue = numericConstants_1.ZERO;
|
|
2446
|
-
if ((
|
|
2410
|
+
if ((_h = marketPosition.isolatedPositionScaledBalance) === null || _h === void 0 ? void 0 : _h.gt(numericConstants_1.ZERO)) {
|
|
2447
2411
|
const quoteSpotMarket = this.driftClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
|
|
2448
2412
|
const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
|
|
2449
2413
|
const strictQuote = new strictOraclePrice_1.StrictOraclePrice(quoteOraclePriceData.price, strict
|
|
2450
2414
|
? quoteSpotMarket.historicalOracleData.lastOraclePriceTwap5Min
|
|
2451
2415
|
: undefined);
|
|
2452
|
-
const quoteTokenAmount = (0, spotBalance_2.getTokenAmount)((
|
|
2416
|
+
const quoteTokenAmount = (0, spotBalance_2.getTokenAmount)((_j = marketPosition.isolatedPositionScaledBalance) !== null && _j !== void 0 ? _j : numericConstants_1.ZERO, quoteSpotMarket, types_2.SpotBalanceType.DEPOSIT);
|
|
2453
2417
|
depositValue = (0, spotBalance_1.getStrictTokenValue)(quoteTokenAmount, quoteSpotMarket.decimals, strictQuote);
|
|
2454
2418
|
}
|
|
2455
2419
|
calc.addIsolatedMarginCalculation(market.marketIndex, depositValue, positionUnrealizedPnl, worstCaseLiabilityValue, perpMarginRequirement);
|
|
@@ -22,7 +22,7 @@ class WebsocketSubscription {
|
|
|
22
22
|
if (this.additionalFilters) {
|
|
23
23
|
filters.push(...this.additionalFilters);
|
|
24
24
|
}
|
|
25
|
-
this.subscriber = new webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber('UserMap', '
|
|
25
|
+
this.subscriber = new webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber('UserMap', 'user', this.userMap.driftClient.program, this.decodeFn, {
|
|
26
26
|
filters,
|
|
27
27
|
commitment: this.commitment,
|
|
28
28
|
}, this.resubOpts);
|
|
@@ -22,7 +22,7 @@ class grpcSubscription {
|
|
|
22
22
|
if (this.additionalFilters) {
|
|
23
23
|
filters.push(...this.additionalFilters);
|
|
24
24
|
}
|
|
25
|
-
this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'UserMap', '
|
|
25
|
+
this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'UserMap', 'user', this.userMap.driftClient.program, this.decodeFn, {
|
|
26
26
|
filters,
|
|
27
27
|
}, this.resubOpts);
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revenueShareEscrowMap.d.ts","sourceRoot":"","sources":["../../../src/userMap/revenueShareEscrowMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MA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G,SAAS;IAIxC;;;;;OAKG;IACU,OAAO,CACnB,kBAAkB,EAAE,MAAM,GACxB,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;IAOpC,qBAAqB,CAAC,SAAS,EAAE,MAAM;IA8B7C,IAAI,IAAI,MAAM;IAIR,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBlC;;;OAGG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA4FrC;;OAEG;IACI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAIvD;;OAEG;IACI,cAAc,IAAI,MAAM,EAAE;IAIjC;;OAEG;IACI,+BAA+B,IAAI,GAAG,CAC5C,MAAM,EACN,yBAAyB,CACzB;IAUD;;OAEG;IACI,oBAAoB,IAAI,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAUrE;;OAEG;IACI,aAAa,CACnB,iBAAiB,EAAE,MAAM,GACvB,yBAAyB,GAAG,SAAS;IASxC;;OAEG;IACI,gBAAgB,CACtB,iBAAiB,EAAE,MAAM,GACvB,yBAAyB,EAAE;IAUjB,WAAW;CAGxB"}
|
|
@@ -52,7 +52,7 @@ class RevenueShareEscrowMap {
|
|
|
52
52
|
try {
|
|
53
53
|
const accountInfo = await this.driftClient.connection.getAccountInfo(escrowAccountPublicKey, 'processed');
|
|
54
54
|
if (accountInfo && accountInfo.data) {
|
|
55
|
-
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('
|
|
55
|
+
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', accountInfo.data);
|
|
56
56
|
this.authorityEscrowMap.set(authority, escrow);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -89,7 +89,7 @@ class RevenueShareEscrowMap {
|
|
|
89
89
|
}
|
|
90
90
|
for (const authority of this.authorityEscrowMap.keys()) {
|
|
91
91
|
const accountInfo = await this.driftClient.connection.getAccountInfo((0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.driftClient.program.programId, new web3_js_1.PublicKey(authority)), 'confirmed');
|
|
92
|
-
const escrowNew = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('
|
|
92
|
+
const escrowNew = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', accountInfo.data);
|
|
93
93
|
this.authorityEscrowMap.set(authority, escrowNew);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -115,7 +115,7 @@ class RevenueShareEscrowMap {
|
|
|
115
115
|
try {
|
|
116
116
|
// @ts-ignore
|
|
117
117
|
const buffer = Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
|
|
118
|
-
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('
|
|
118
|
+
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', buffer);
|
|
119
119
|
// Extract authority from the account data
|
|
120
120
|
const authorityKey = escrow.authority.toBase58();
|
|
121
121
|
this.authorityEscrowMap.set(authorityKey, escrow);
|
|
@@ -130,7 +130,7 @@ class RevenueShareEscrowMap {
|
|
|
130
130
|
try {
|
|
131
131
|
// @ts-ignore
|
|
132
132
|
const buffer = Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
|
|
133
|
-
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('
|
|
133
|
+
const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', buffer);
|
|
134
134
|
// Extract authority from the account data
|
|
135
135
|
const authorityKey = escrow.authority.toBase58();
|
|
136
136
|
this.authorityEscrowMap.set(authorityKey, escrow);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userMap.d.ts","sourceRoot":"","sources":["../../../src/userMap/userMap.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,WAA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C,cAAc,IAAI,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAIpD,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAK5C,eAAe,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAIhE,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACI,oBAAoB,CAC1B,cAAc,CAAC,EAAE,kBAAkB,GACjC,SAAS,EAAE;IAmBD,IAAI;IAQjB,OAAO,CAAC,UAAU;IAclB;;;;OAIG;YACW,WAAW;IA4FzB;;;;OAIG;YACW,aAAa;IAqHd,WAAW;IAoBX,iBAAiB,CAC7B,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM;IAkBb,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7B,OAAO,IAAI,MAAM;CAGxB"}
|
|
@@ -50,8 +50,7 @@ class UserMap {
|
|
|
50
50
|
decodeFn = (name, buffer) => (0, user_2.decodeUser)(buffer);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
decodeFn =
|
|
54
|
-
this.driftClient.program.account.user.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.user.coder.accounts);
|
|
53
|
+
decodeFn = this.driftClient.program.account.user.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.user.coder.accounts);
|
|
55
54
|
}
|
|
56
55
|
this.decode = decodeFn;
|
|
57
56
|
if (config.subscriptionConfig.type === 'polling') {
|
|
@@ -323,12 +322,12 @@ class UserMap {
|
|
|
323
322
|
const currAccountWithSlot = this.getWithSlot(key);
|
|
324
323
|
if (currAccountWithSlot) {
|
|
325
324
|
if (slot >= currAccountWithSlot.slot) {
|
|
326
|
-
const userAccount = this.decode('
|
|
325
|
+
const userAccount = this.decode('user', buffer);
|
|
327
326
|
this.updateUserAccount(key, userAccount, slot);
|
|
328
327
|
}
|
|
329
328
|
}
|
|
330
329
|
else {
|
|
331
|
-
const userAccount = this.decode('
|
|
330
|
+
const userAccount = this.decode('user', buffer);
|
|
332
331
|
await this.addPubkey(new web3_js_1.PublicKey(key), userAccount, slot);
|
|
333
332
|
}
|
|
334
333
|
})());
|
|
@@ -413,7 +412,7 @@ class UserMap {
|
|
|
413
412
|
const publicKeyString = chunk[j].toString();
|
|
414
413
|
const buffer = buffer_1.Buffer.from(accountInfo.data);
|
|
415
414
|
programAccountBufferMap.set(publicKeyString, buffer);
|
|
416
|
-
const decodedUser = this.decode('
|
|
415
|
+
const decodedUser = this.decode('user', buffer);
|
|
417
416
|
const currAccountWithSlot = this.getWithSlot(publicKeyString);
|
|
418
417
|
if (currAccountWithSlot &&
|
|
419
418
|
currAccountWithSlot.slot <= accountInfosSlot) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userStatsMap.d.ts","sourceRoot":"","sources":["../../../src/userMap/userStatsMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EACN,WAAW,EACX,gBAAgB,EAShB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,YAAY;IACxB;;OAEG;IACH,OAAO,CAAC,YAAY,CAAgC;IACpD,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,UAAU,CAAa;IAE/B,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M,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO;IAO3D,qBAAqB,CACjC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE,OAAO;IAiEX,GAAG,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO;IAIxC,GAAG,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS;IAIjD;;;;;OAKG;IACU,OAAO,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAW7D,MAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC;IAIrC,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACU,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE;IAQ1C;;;;OAIG;YACW,WAAW;IASzB;;;OAGG;YACW,aAAa;IA8Gd,WAAW;CAMxB"}
|
|
@@ -26,8 +26,7 @@ class UserStatsMap {
|
|
|
26
26
|
this.syncConfig = syncConfig !== null && syncConfig !== void 0 ? syncConfig : {
|
|
27
27
|
type: 'default',
|
|
28
28
|
};
|
|
29
|
-
this.decode =
|
|
30
|
-
this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.userStats.coder.accounts);
|
|
29
|
+
this.decode = this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.userStats.coder.accounts);
|
|
31
30
|
}
|
|
32
31
|
async subscribe(authorities) {
|
|
33
32
|
if (this.size() > 0) {
|
|
@@ -235,7 +234,7 @@ class UserStatsMap {
|
|
|
235
234
|
const publicKeyString = chunk[j].toString();
|
|
236
235
|
if (!this.has(publicKeyString)) {
|
|
237
236
|
const buffer = Buffer.from(accountInfo.data);
|
|
238
|
-
const decodedUserStats = this.decode('
|
|
237
|
+
const decodedUserStats = this.decode('userStats', buffer);
|
|
239
238
|
programAccountBufferMap.add(decodedUserStats.authority.toBase58());
|
|
240
239
|
this.addUserStat(decodedUserStats.authority, decodedUserStats, false);
|
|
241
240
|
}
|