@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/driftClient.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DriftClient — main SDK entry point for all trading and keeper operations.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Builds and sends all on-chain instructions (place/cancel/fill orders, deposits, withdrawals,
|
|
6
|
+
* settle PnL, update funding rate, liquidations).
|
|
7
|
+
* - Manages the program account subscription lifecycle (markets, oracles, user accounts).
|
|
8
|
+
* - Provides oracle price reads, market config lookups, and PDA derivation helpers.
|
|
9
|
+
*
|
|
10
|
+
* Admin operations (market init, fee updates, oracle config) live in {@link AdminClient} (adminClient.ts).
|
|
11
|
+
* Read-only user account queries (margin, positions, PnL) live in {@link User} (user.ts).
|
|
12
|
+
*
|
|
13
|
+
* Instruction → on-chain handler mapping: see ARCHITECTURE.md § SDK↔Instruction Mapping.
|
|
14
|
+
*/
|
|
1
15
|
import * as anchor from '@coral-xyz/anchor';
|
|
2
|
-
import {
|
|
3
|
-
AnchorProvider,
|
|
4
|
-
BN,
|
|
5
|
-
Idl,
|
|
6
|
-
Program,
|
|
7
|
-
ProgramAccount,
|
|
8
|
-
} from '@coral-xyz/anchor';
|
|
9
|
-
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
16
|
+
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
10
17
|
import bs58 from 'bs58';
|
|
11
18
|
import {
|
|
12
19
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -26,7 +33,6 @@ import {
|
|
|
26
33
|
} from '@solana/spl-token';
|
|
27
34
|
import {
|
|
28
35
|
DriftClientMetricsEvents,
|
|
29
|
-
HighLeverageModeConfig,
|
|
30
36
|
isVariant,
|
|
31
37
|
IWallet,
|
|
32
38
|
MakerInfo,
|
|
@@ -72,6 +78,10 @@ import {
|
|
|
72
78
|
} from './types';
|
|
73
79
|
import driftIDL from './idl/drift.json';
|
|
74
80
|
|
|
81
|
+
/** Client-side guardrail; mirrors on-chain `ErrorCode::SpotDlobTradingDisabled`. */
|
|
82
|
+
const SPOT_DLOB_TRADING_DISABLED_MSG =
|
|
83
|
+
'Spot DLOB trading is disabled; spot balances, deposits, and swaps remain available.';
|
|
84
|
+
|
|
75
85
|
import {
|
|
76
86
|
AccountMeta,
|
|
77
87
|
AddressLookupTableAccount,
|
|
@@ -99,14 +109,12 @@ import {
|
|
|
99
109
|
getDriftSignerPublicKey,
|
|
100
110
|
getDriftStateAccountPublicKey,
|
|
101
111
|
getFuelOverflowAccountPublicKey,
|
|
102
|
-
getHighLeverageModeConfigPublicKey,
|
|
103
112
|
getInsuranceFundStakeAccountPublicKey,
|
|
104
113
|
getOpenbookV2FulfillmentConfigPublicKey,
|
|
105
114
|
getPerpMarketPublicKey,
|
|
106
115
|
getPhoenixFulfillmentConfigPublicKey,
|
|
107
116
|
getProtectedMakerModeConfigPublicKey,
|
|
108
117
|
getPythLazerOraclePublicKey,
|
|
109
|
-
getPythPullOraclePublicKey,
|
|
110
118
|
getReferrerNamePublicKeySync,
|
|
111
119
|
getSerumFulfillmentConfigPublicKey,
|
|
112
120
|
getSerumSignerPublicKey,
|
|
@@ -164,12 +172,12 @@ import { User } from './user';
|
|
|
164
172
|
import { UserSubscriptionConfig } from './userConfig';
|
|
165
173
|
import {
|
|
166
174
|
configs,
|
|
167
|
-
DRIFT_ORACLE_RECEIVER_ID,
|
|
168
175
|
DEFAULT_CONFIRMATION_OPTS,
|
|
169
|
-
DRIFT_PROGRAM_ID,
|
|
170
176
|
DriftEnv,
|
|
177
|
+
DriftProgram,
|
|
171
178
|
PYTH_LAZER_STORAGE_ACCOUNT_KEY,
|
|
172
179
|
} from './config';
|
|
180
|
+
import { Drift } from './idl/drift';
|
|
173
181
|
import { WRAPPED_SOL_MINT } from './constants/spotMarkets';
|
|
174
182
|
import { UserStats } from './userStats';
|
|
175
183
|
import { isSpotPositionAvailable } from './math/spotPosition';
|
|
@@ -181,28 +189,19 @@ import { SwapMode, UnifiedQuoteResponse } from './swap/UnifiedSwapClient';
|
|
|
181
189
|
import { getNonIdleUserFilter } from './memcmp';
|
|
182
190
|
import { UserStatsSubscriptionConfig } from './userStatsConfig';
|
|
183
191
|
import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
|
|
184
|
-
import { getOrderParams
|
|
192
|
+
import { getOrderParams } from './orderParams';
|
|
185
193
|
import { numberToSafeBN } from './math/utils';
|
|
186
194
|
import { TransactionParamProcessor } from './tx/txParamProcessor';
|
|
187
|
-
import {
|
|
188
|
-
isOracleTooDivergent,
|
|
189
|
-
isOracleValid,
|
|
190
|
-
trimVaaSignatures,
|
|
191
|
-
} from './math/oracles';
|
|
195
|
+
import { isOracleTooDivergent, isOracleValid } from './math/oracles';
|
|
192
196
|
import { TxHandler } from './tx/txHandler';
|
|
193
|
-
import { parseAccumulatorUpdateData } from '@pythnetwork/price-service-sdk';
|
|
194
|
-
import { getFeedIdUint8Array, trimFeedId } from './util/pythOracleUtils';
|
|
195
197
|
import { createMinimalEd25519VerifyIx } from './util/ed25519Utils';
|
|
196
198
|
import {
|
|
197
199
|
createNativeInstructionDiscriminatorBuffer,
|
|
198
200
|
isVersionedTransaction,
|
|
199
201
|
MAX_TX_BYTE_SIZE,
|
|
200
202
|
} from './tx/utils';
|
|
201
|
-
import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
|
|
202
|
-
import { asV0Tx, PullFeed, AnchorUtils } from '@switchboard-xyz/on-demand';
|
|
203
203
|
import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
204
204
|
import nacl from 'tweetnacl';
|
|
205
|
-
import { Slothash } from './slot/SlothashSubscriber';
|
|
206
205
|
import { getOracleId } from './oracles/oracleId';
|
|
207
206
|
import { SignedMsgOrderParams } from './types';
|
|
208
207
|
import { TakerInfo } from './types';
|
|
@@ -218,15 +217,6 @@ import {
|
|
|
218
217
|
} from './math/builder';
|
|
219
218
|
import { TitanClient, SwapMode as TitanSwapMode } from './titan/titanClient';
|
|
220
219
|
import { UnifiedSwapClient } from './swap/UnifiedSwapClient';
|
|
221
|
-
import {
|
|
222
|
-
DEFAULT_RECEIVER_PROGRAM_ID,
|
|
223
|
-
WORMHOLE_CORE_BRIDGE_SOLANA_IDL,
|
|
224
|
-
DEFAULT_WORMHOLE_PROGRAM_ID,
|
|
225
|
-
getGuardianSetPda,
|
|
226
|
-
WormholeCoreBridgeSolana,
|
|
227
|
-
PythSolanaReceiver,
|
|
228
|
-
} from './pyth';
|
|
229
|
-
|
|
230
220
|
/**
|
|
231
221
|
* Union type for swap clients (Titan and Jupiter) - Legacy type
|
|
232
222
|
* @deprecated Use UnifiedSwapClient class instead
|
|
@@ -249,7 +239,7 @@ type RemainingAccountParams = {
|
|
|
249
239
|
export class DriftClient {
|
|
250
240
|
connection: Connection;
|
|
251
241
|
wallet: IWallet;
|
|
252
|
-
public program:
|
|
242
|
+
public program: DriftProgram;
|
|
253
243
|
provider: AnchorProvider;
|
|
254
244
|
env: DriftEnv;
|
|
255
245
|
opts?: ConfirmOptions;
|
|
@@ -290,12 +280,6 @@ export class DriftClient {
|
|
|
290
280
|
|
|
291
281
|
txHandler: TxHandler;
|
|
292
282
|
|
|
293
|
-
receiverProgram?: Program<PythSolanaReceiver>;
|
|
294
|
-
wormholeProgram?: Program<WormholeCoreBridgeSolana>;
|
|
295
|
-
sbOnDemandProgramdId: PublicKey;
|
|
296
|
-
sbOnDemandProgram?: Program30<Idl30>;
|
|
297
|
-
sbProgramFeedConfigs?: Map<string, any>;
|
|
298
|
-
|
|
299
283
|
public get isSubscribed() {
|
|
300
284
|
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
301
285
|
}
|
|
@@ -363,9 +347,8 @@ export class DriftClient {
|
|
|
363
347
|
config.wallet,
|
|
364
348
|
this.opts
|
|
365
349
|
);
|
|
366
|
-
this.program = new Program(
|
|
367
|
-
driftIDL as
|
|
368
|
-
config.programID ?? new PublicKey(DRIFT_PROGRAM_ID),
|
|
350
|
+
this.program = new Program<Drift>(
|
|
351
|
+
driftIDL as Drift,
|
|
369
352
|
this.provider,
|
|
370
353
|
config.coder
|
|
371
354
|
);
|
|
@@ -504,12 +487,12 @@ export class DriftClient {
|
|
|
504
487
|
delistedMarketSetting
|
|
505
488
|
);
|
|
506
489
|
} else if (config.accountSubscription?.type === 'grpc') {
|
|
507
|
-
const accountSubscriberClass =
|
|
490
|
+
const accountSubscriberClass: any =
|
|
508
491
|
config.accountSubscription?.driftClientAccountSubscriber ??
|
|
509
492
|
grpcDriftClientAccountSubscriber;
|
|
510
493
|
this.accountSubscriber = new accountSubscriberClass(
|
|
511
494
|
config.accountSubscription.grpcConfigs,
|
|
512
|
-
this.program,
|
|
495
|
+
this.program as any,
|
|
513
496
|
config.perpMarketIndexes ?? [],
|
|
514
497
|
config.spotMarketIndexes ?? [],
|
|
515
498
|
config.oracleInfos ?? [],
|
|
@@ -521,11 +504,11 @@ export class DriftClient {
|
|
|
521
504
|
}
|
|
522
505
|
);
|
|
523
506
|
} else {
|
|
524
|
-
const accountSubscriberClass =
|
|
507
|
+
const accountSubscriberClass: any =
|
|
525
508
|
config.accountSubscription?.driftClientAccountSubscriber ??
|
|
526
509
|
WebSocketDriftClientAccountSubscriber;
|
|
527
510
|
this.accountSubscriber = new accountSubscriberClass(
|
|
528
|
-
this.program,
|
|
511
|
+
this.program as any,
|
|
529
512
|
config.perpMarketIndexes ?? [],
|
|
530
513
|
config.spotMarketIndexes ?? [],
|
|
531
514
|
config.oracleInfos ?? [],
|
|
@@ -554,8 +537,6 @@ export class DriftClient {
|
|
|
554
537
|
opts: this.opts,
|
|
555
538
|
txHandler: this.txHandler,
|
|
556
539
|
});
|
|
557
|
-
|
|
558
|
-
this.sbOnDemandProgramdId = configs[this.env].SB_ON_DEMAND_PID;
|
|
559
540
|
}
|
|
560
541
|
|
|
561
542
|
public getUserMapKey(subAccountId: number, authority: PublicKey): string {
|
|
@@ -739,7 +720,7 @@ export class DriftClient {
|
|
|
739
720
|
this.program.programId,
|
|
740
721
|
serumMarket
|
|
741
722
|
);
|
|
742
|
-
return (await this.program.account.serumV3FulfillmentConfig.fetch(
|
|
723
|
+
return (await (this.program.account as any).serumV3FulfillmentConfig.fetch(
|
|
743
724
|
address
|
|
744
725
|
)) as SerumV3FulfillmentConfigAccount;
|
|
745
726
|
}
|
|
@@ -747,7 +728,9 @@ export class DriftClient {
|
|
|
747
728
|
public async getSerumV3FulfillmentConfigs(): Promise<
|
|
748
729
|
SerumV3FulfillmentConfigAccount[]
|
|
749
730
|
> {
|
|
750
|
-
const accounts = await
|
|
731
|
+
const accounts = await (
|
|
732
|
+
this.program.account as any
|
|
733
|
+
).serumV3FulfillmentConfig.all();
|
|
751
734
|
return accounts.map(
|
|
752
735
|
(account) => account.account
|
|
753
736
|
) as SerumV3FulfillmentConfigAccount[];
|
|
@@ -760,7 +743,9 @@ export class DriftClient {
|
|
|
760
743
|
this.program.programId,
|
|
761
744
|
phoenixMarket
|
|
762
745
|
);
|
|
763
|
-
return (await
|
|
746
|
+
return (await (
|
|
747
|
+
this.program.account as any
|
|
748
|
+
).phoenixV1FulfillmentConfig.fetch(
|
|
764
749
|
address
|
|
765
750
|
)) as PhoenixV1FulfillmentConfigAccount;
|
|
766
751
|
}
|
|
@@ -768,8 +753,9 @@ export class DriftClient {
|
|
|
768
753
|
public async getPhoenixV1FulfillmentConfigs(): Promise<
|
|
769
754
|
PhoenixV1FulfillmentConfigAccount[]
|
|
770
755
|
> {
|
|
771
|
-
const accounts =
|
|
772
|
-
|
|
756
|
+
const accounts = await (
|
|
757
|
+
this.program.account as any
|
|
758
|
+
).phoenixV1FulfillmentConfig.all();
|
|
773
759
|
return accounts.map(
|
|
774
760
|
(account) => account.account
|
|
775
761
|
) as PhoenixV1FulfillmentConfigAccount[];
|
|
@@ -782,7 +768,9 @@ export class DriftClient {
|
|
|
782
768
|
this.program.programId,
|
|
783
769
|
openbookMarket
|
|
784
770
|
);
|
|
785
|
-
return (await
|
|
771
|
+
return (await (
|
|
772
|
+
this.program.account as any
|
|
773
|
+
).openbookV2FulfillmentConfig.fetch(
|
|
786
774
|
address
|
|
787
775
|
)) as OpenbookV2FulfillmentConfigAccount;
|
|
788
776
|
}
|
|
@@ -790,8 +778,9 @@ export class DriftClient {
|
|
|
790
778
|
public async getOpenbookV2FulfillmentConfigs(): Promise<
|
|
791
779
|
OpenbookV2FulfillmentConfigAccount[]
|
|
792
780
|
> {
|
|
793
|
-
const accounts =
|
|
794
|
-
|
|
781
|
+
const accounts = await (
|
|
782
|
+
this.program.account as any
|
|
783
|
+
).openbookV2FulfillmentConfig.all();
|
|
795
784
|
return accounts.map(
|
|
796
785
|
(account) => account.account
|
|
797
786
|
) as OpenbookV2FulfillmentConfigAccount[];
|
|
@@ -870,11 +859,7 @@ export class DriftClient {
|
|
|
870
859
|
newWallet,
|
|
871
860
|
this.opts
|
|
872
861
|
);
|
|
873
|
-
const newProgram = new Program(
|
|
874
|
-
driftIDL as Idl,
|
|
875
|
-
this.program.programId,
|
|
876
|
-
newProvider
|
|
877
|
-
);
|
|
862
|
+
const newProgram = new Program<Drift>(driftIDL as Drift, newProvider);
|
|
878
863
|
|
|
879
864
|
this.skipLoadUsers = false;
|
|
880
865
|
// Update provider for txSender with new wallet details
|
|
@@ -1419,7 +1404,7 @@ export class DriftClient {
|
|
|
1419
1404
|
this.program.programId,
|
|
1420
1405
|
authority
|
|
1421
1406
|
);
|
|
1422
|
-
return this.program.instruction.migrateReferrer({
|
|
1407
|
+
return (this.program.instruction as any).migrateReferrer({
|
|
1423
1408
|
accounts: {
|
|
1424
1409
|
escrow,
|
|
1425
1410
|
authority,
|
|
@@ -1884,21 +1869,14 @@ export class DriftClient {
|
|
|
1884
1869
|
perpMarketIndex: number,
|
|
1885
1870
|
marginRatio: number,
|
|
1886
1871
|
subAccountId = 0,
|
|
1887
|
-
txParams?: TxParams
|
|
1888
|
-
enterHighLeverageMode?: boolean
|
|
1872
|
+
txParams?: TxParams
|
|
1889
1873
|
): Promise<TransactionSignature> {
|
|
1890
|
-
const ixs = [];
|
|
1891
|
-
if (enterHighLeverageMode) {
|
|
1892
|
-
const enableIx = await this.getEnableHighLeverageModeIx(subAccountId);
|
|
1893
|
-
ixs.push(enableIx);
|
|
1894
|
-
}
|
|
1895
1874
|
const updateIx = await this.getUpdateUserPerpPositionCustomMarginRatioIx(
|
|
1896
1875
|
perpMarketIndex,
|
|
1897
1876
|
marginRatio,
|
|
1898
1877
|
subAccountId
|
|
1899
1878
|
);
|
|
1900
|
-
|
|
1901
|
-
const tx = await this.buildTransaction(ixs, txParams ?? this.txParams);
|
|
1879
|
+
const tx = await this.buildTransaction(updateIx, txParams ?? this.txParams);
|
|
1902
1880
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1903
1881
|
return txSig;
|
|
1904
1882
|
}
|
|
@@ -2021,7 +1999,7 @@ export class DriftClient {
|
|
|
2021
1999
|
advancedLp: boolean,
|
|
2022
2000
|
subAccountId: number
|
|
2023
2001
|
) {
|
|
2024
|
-
const ix = await this.program.instruction.updateUserAdvancedLp(
|
|
2002
|
+
const ix = await (this.program.instruction as any).updateUserAdvancedLp(
|
|
2025
2003
|
subAccountId,
|
|
2026
2004
|
advancedLp,
|
|
2027
2005
|
{
|
|
@@ -2117,7 +2095,7 @@ export class DriftClient {
|
|
|
2117
2095
|
if (!includeIdle) {
|
|
2118
2096
|
filters = [getNonIdleUserFilter()];
|
|
2119
2097
|
}
|
|
2120
|
-
return (await this.program.account.user.all(
|
|
2098
|
+
return (await (this.program.account as any).user.all(
|
|
2121
2099
|
filters
|
|
2122
2100
|
)) as ProgramAccount<UserAccount>[];
|
|
2123
2101
|
}
|
|
@@ -2125,7 +2103,7 @@ export class DriftClient {
|
|
|
2125
2103
|
public async getUserAccountsForDelegate(
|
|
2126
2104
|
delegate: PublicKey
|
|
2127
2105
|
): Promise<UserAccount[]> {
|
|
2128
|
-
const programAccounts = await this.program.account.user.all([
|
|
2106
|
+
const programAccounts = await (this.program.account as any).user.all([
|
|
2129
2107
|
{
|
|
2130
2108
|
memcmp: {
|
|
2131
2109
|
offset: 40,
|
|
@@ -2143,7 +2121,7 @@ export class DriftClient {
|
|
|
2143
2121
|
public async getUserAccountsAndAddressesForAuthority(
|
|
2144
2122
|
authority: PublicKey
|
|
2145
2123
|
): Promise<ProgramAccount<UserAccount>[]> {
|
|
2146
|
-
const programAccounts = await this.program.account.user.all([
|
|
2124
|
+
const programAccounts = await (this.program.account as any).user.all([
|
|
2147
2125
|
{
|
|
2148
2126
|
memcmp: {
|
|
2149
2127
|
offset: 8,
|
|
@@ -2161,7 +2139,7 @@ export class DriftClient {
|
|
|
2161
2139
|
public async getUserAccountsForAuthority(
|
|
2162
2140
|
authority: PublicKey
|
|
2163
2141
|
): Promise<UserAccount[]> {
|
|
2164
|
-
const programAccounts = await this.program.account.user.all([
|
|
2142
|
+
const programAccounts = await (this.program.account as any).user.all([
|
|
2165
2143
|
{
|
|
2166
2144
|
memcmp: {
|
|
2167
2145
|
offset: 8,
|
|
@@ -2179,7 +2157,7 @@ export class DriftClient {
|
|
|
2179
2157
|
public async getReferredUserStatsAccountsByReferrer(
|
|
2180
2158
|
referrer: PublicKey
|
|
2181
2159
|
): Promise<UserStatsAccount[]> {
|
|
2182
|
-
const programAccounts = await this.program.account.userStats.all([
|
|
2160
|
+
const programAccounts = await (this.program.account as any).userStats.all([
|
|
2183
2161
|
{
|
|
2184
2162
|
memcmp: {
|
|
2185
2163
|
offset: 40,
|
|
@@ -2190,14 +2168,16 @@ export class DriftClient {
|
|
|
2190
2168
|
]);
|
|
2191
2169
|
|
|
2192
2170
|
return programAccounts.map(
|
|
2193
|
-
(programAccount) => programAccount.account as UserStatsAccount
|
|
2171
|
+
(programAccount) => programAccount.account as unknown as UserStatsAccount
|
|
2194
2172
|
);
|
|
2195
2173
|
}
|
|
2196
2174
|
|
|
2197
2175
|
public async getReferrerNameAccountsForAuthority(
|
|
2198
2176
|
authority: PublicKey
|
|
2199
2177
|
): Promise<ReferrerNameAccount[]> {
|
|
2200
|
-
const programAccounts = await
|
|
2178
|
+
const programAccounts = await (
|
|
2179
|
+
this.program.account as any
|
|
2180
|
+
).referrerName.all([
|
|
2201
2181
|
{
|
|
2202
2182
|
memcmp: {
|
|
2203
2183
|
offset: 8,
|
|
@@ -2366,7 +2346,9 @@ export class DriftClient {
|
|
|
2366
2346
|
}
|
|
2367
2347
|
|
|
2368
2348
|
public async getSignedMsgUserOrdersDeletionIx(authority: PublicKey) {
|
|
2369
|
-
const ix = await
|
|
2349
|
+
const ix = await (
|
|
2350
|
+
this.program.instruction as any
|
|
2351
|
+
).deleteSignedMsgUserOrders({
|
|
2370
2352
|
accounts: {
|
|
2371
2353
|
user: authority,
|
|
2372
2354
|
signedMsgUserOrders: getSignedMsgUserAccountPublicKey(
|
|
@@ -2475,7 +2457,7 @@ export class DriftClient {
|
|
|
2475
2457
|
this.program.programId,
|
|
2476
2458
|
nameBuffer
|
|
2477
2459
|
);
|
|
2478
|
-
return (await this.program.account.referrerName.fetch(
|
|
2460
|
+
return (await (this.program.account as any).referrerName.fetch(
|
|
2479
2461
|
referrerNameAccountPublicKey
|
|
2480
2462
|
)) as ReferrerNameAccount;
|
|
2481
2463
|
}
|
|
@@ -3191,7 +3173,7 @@ export class DriftClient {
|
|
|
3191
3173
|
|
|
3192
3174
|
const authority = overrides?.authority ?? this.wallet.publicKey;
|
|
3193
3175
|
const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
3194
|
-
return await this.program.instruction.deposit(
|
|
3176
|
+
return await (this.program.instruction as any).deposit(
|
|
3195
3177
|
marketIndex,
|
|
3196
3178
|
amount,
|
|
3197
3179
|
reduceOnly,
|
|
@@ -3894,7 +3876,7 @@ export class DriftClient {
|
|
|
3894
3876
|
|
|
3895
3877
|
const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
3896
3878
|
|
|
3897
|
-
return await this.program.instruction.withdraw(
|
|
3879
|
+
return await (this.program.instruction as any).withdraw(
|
|
3898
3880
|
marketIndex,
|
|
3899
3881
|
amount,
|
|
3900
3882
|
reduceOnly,
|
|
@@ -3988,7 +3970,7 @@ export class DriftClient {
|
|
|
3988
3970
|
fromSubAccountId
|
|
3989
3971
|
);
|
|
3990
3972
|
|
|
3991
|
-
const fromUserAccount = (await this.program.account.user.fetch(
|
|
3973
|
+
const fromUserAccount = (await (this.program.account as any).user.fetch(
|
|
3992
3974
|
userAccountPublicKey
|
|
3993
3975
|
)) as UserAccount;
|
|
3994
3976
|
remainingAccounts = this.getRemainingAccounts({
|
|
@@ -4538,7 +4520,7 @@ export class DriftClient {
|
|
|
4538
4520
|
settleeUserAccountPublicKey: PublicKey,
|
|
4539
4521
|
marketIndex: number
|
|
4540
4522
|
): Promise<TransactionInstruction> {
|
|
4541
|
-
const settleeUserAccount = (await this.program.account.user.fetch(
|
|
4523
|
+
const settleeUserAccount = (await (this.program.account as any).user.fetch(
|
|
4542
4524
|
settleeUserAccountPublicKey
|
|
4543
4525
|
)) as UserAccount;
|
|
4544
4526
|
|
|
@@ -4547,7 +4529,7 @@ export class DriftClient {
|
|
|
4547
4529
|
writablePerpMarketIndexes: [marketIndex],
|
|
4548
4530
|
});
|
|
4549
4531
|
|
|
4550
|
-
return this.program.instruction.settleLp(marketIndex, {
|
|
4532
|
+
return (this.program.instruction as any).settleLp(marketIndex, {
|
|
4551
4533
|
accounts: {
|
|
4552
4534
|
state: await this.getStatePublicKey(),
|
|
4553
4535
|
user: settleeUserAccountPublicKey,
|
|
@@ -4603,7 +4585,7 @@ export class DriftClient {
|
|
|
4603
4585
|
userAccountPublicKey: PublicKey,
|
|
4604
4586
|
sharesToBurn?: BN
|
|
4605
4587
|
): Promise<TransactionInstruction> {
|
|
4606
|
-
const userAccount = (await this.program.account.user.fetch(
|
|
4588
|
+
const userAccount = (await (this.program.account as any).user.fetch(
|
|
4607
4589
|
userAccountPublicKey
|
|
4608
4590
|
)) as UserAccount;
|
|
4609
4591
|
|
|
@@ -4620,7 +4602,7 @@ export class DriftClient {
|
|
|
4620
4602
|
console.log('burning lp shares:', sharesToBurn.toString());
|
|
4621
4603
|
}
|
|
4622
4604
|
|
|
4623
|
-
return this.program.instruction.removePerpLpSharesInExpiringMarket(
|
|
4605
|
+
return (this.program.instruction as any).removePerpLpSharesInExpiringMarket(
|
|
4624
4606
|
sharesToBurn,
|
|
4625
4607
|
marketIndex,
|
|
4626
4608
|
{
|
|
@@ -4654,7 +4636,7 @@ export class DriftClient {
|
|
|
4654
4636
|
console.log('burning lp shares:', sharesToBurn.toString());
|
|
4655
4637
|
}
|
|
4656
4638
|
|
|
4657
|
-
return this.program.instruction.removePerpLpShares(
|
|
4639
|
+
return (this.program.instruction as any).removePerpLpShares(
|
|
4658
4640
|
sharesToBurn,
|
|
4659
4641
|
marketIndex,
|
|
4660
4642
|
{
|
|
@@ -4698,14 +4680,18 @@ export class DriftClient {
|
|
|
4698
4680
|
writablePerpMarketIndexes: [marketIndex],
|
|
4699
4681
|
});
|
|
4700
4682
|
|
|
4701
|
-
return this.program.instruction.addPerpLpShares(
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4683
|
+
return (this.program.instruction as any).addPerpLpShares(
|
|
4684
|
+
amount,
|
|
4685
|
+
marketIndex,
|
|
4686
|
+
{
|
|
4687
|
+
accounts: {
|
|
4688
|
+
state: await this.getStatePublicKey(),
|
|
4689
|
+
user,
|
|
4690
|
+
authority: this.wallet.publicKey,
|
|
4691
|
+
},
|
|
4692
|
+
remainingAccounts: remainingAccounts,
|
|
4693
|
+
}
|
|
4694
|
+
);
|
|
4709
4695
|
}
|
|
4710
4696
|
|
|
4711
4697
|
public getQuoteValuePerLpShare(marketIndex: number): BN {
|
|
@@ -5018,15 +5004,7 @@ export class DriftClient {
|
|
|
5018
5004
|
: undefined,
|
|
5019
5005
|
});
|
|
5020
5006
|
|
|
5021
|
-
|
|
5022
|
-
remainingAccounts.push({
|
|
5023
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
5024
|
-
isWritable: true,
|
|
5025
|
-
isSigner: false,
|
|
5026
|
-
});
|
|
5027
|
-
}
|
|
5028
|
-
|
|
5029
|
-
return await this.program.instruction.placePerpOrder(orderParams, {
|
|
5007
|
+
return await (this.program.instruction as any).placePerpOrder(orderParams, {
|
|
5030
5008
|
accounts: {
|
|
5031
5009
|
state: await this.getStatePublicKey(),
|
|
5032
5010
|
user,
|
|
@@ -5248,15 +5226,18 @@ export class DriftClient {
|
|
|
5248
5226
|
useMarketLastSlotCache: true,
|
|
5249
5227
|
});
|
|
5250
5228
|
|
|
5251
|
-
return await this.program.instruction.cancelOrderByUserId(
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5229
|
+
return await (this.program.instruction as any).cancelOrderByUserId(
|
|
5230
|
+
userOrderId,
|
|
5231
|
+
{
|
|
5232
|
+
accounts: {
|
|
5233
|
+
state: await this.getStatePublicKey(),
|
|
5234
|
+
user,
|
|
5235
|
+
authority: this.wallet.publicKey,
|
|
5236
|
+
oracle,
|
|
5237
|
+
},
|
|
5238
|
+
remainingAccounts,
|
|
5239
|
+
}
|
|
5240
|
+
);
|
|
5260
5241
|
}
|
|
5261
5242
|
|
|
5262
5243
|
/**
|
|
@@ -5514,28 +5495,21 @@ export class DriftClient {
|
|
|
5514
5495
|
useMarketLastSlotCache: true,
|
|
5515
5496
|
});
|
|
5516
5497
|
|
|
5517
|
-
for (const param of params) {
|
|
5518
|
-
if (isUpdateHighLeverageMode(param.bitFlags)) {
|
|
5519
|
-
remainingAccounts.push({
|
|
5520
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
5521
|
-
isWritable: true,
|
|
5522
|
-
isSigner: false,
|
|
5523
|
-
});
|
|
5524
|
-
}
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
5498
|
const formattedParams = params.map((item) => getOrderParams(item));
|
|
5528
5499
|
const authority = overrides?.authority ?? this.wallet.publicKey;
|
|
5529
5500
|
|
|
5530
|
-
return await this.program.instruction.placeOrders(
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5501
|
+
return await (this.program.instruction as any).placeOrders(
|
|
5502
|
+
formattedParams,
|
|
5503
|
+
{
|
|
5504
|
+
accounts: {
|
|
5505
|
+
state: await this.getStatePublicKey(),
|
|
5506
|
+
user,
|
|
5507
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
5508
|
+
authority,
|
|
5509
|
+
},
|
|
5510
|
+
remainingAccounts,
|
|
5511
|
+
}
|
|
5512
|
+
);
|
|
5539
5513
|
}
|
|
5540
5514
|
|
|
5541
5515
|
public async getPlaceOrdersAndSetPositionMaxLevIx(
|
|
@@ -5565,19 +5539,9 @@ export class DriftClient {
|
|
|
5565
5539
|
useMarketLastSlotCache: true,
|
|
5566
5540
|
});
|
|
5567
5541
|
|
|
5568
|
-
for (const param of params) {
|
|
5569
|
-
if (isUpdateHighLeverageMode(param.bitFlags)) {
|
|
5570
|
-
remainingAccounts.push({
|
|
5571
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
5572
|
-
isWritable: true,
|
|
5573
|
-
isSigner: false,
|
|
5574
|
-
});
|
|
5575
|
-
}
|
|
5576
|
-
}
|
|
5577
|
-
|
|
5578
5542
|
const formattedParams = params.map((item) => getOrderParams(item));
|
|
5579
5543
|
|
|
5580
|
-
const placeOrdersIxs = await this.program.instruction.placeOrders(
|
|
5544
|
+
const placeOrdersIxs = await (this.program.instruction as any).placeOrders(
|
|
5581
5545
|
formattedParams,
|
|
5582
5546
|
{
|
|
5583
5547
|
accounts: {
|
|
@@ -5660,14 +5624,6 @@ export class DriftClient {
|
|
|
5660
5624
|
useMarketLastSlotCache: true,
|
|
5661
5625
|
});
|
|
5662
5626
|
|
|
5663
|
-
if (isUpdateHighLeverageMode(params.bitFlags)) {
|
|
5664
|
-
remainingAccounts.push({
|
|
5665
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
5666
|
-
isWritable: true,
|
|
5667
|
-
isSigner: false,
|
|
5668
|
-
});
|
|
5669
|
-
}
|
|
5670
|
-
|
|
5671
5627
|
const formattedParams = {
|
|
5672
5628
|
marketType: params.marketType,
|
|
5673
5629
|
direction: params.direction,
|
|
@@ -5683,15 +5639,18 @@ export class DriftClient {
|
|
|
5683
5639
|
maxTs: params.maxTs,
|
|
5684
5640
|
};
|
|
5685
5641
|
|
|
5686
|
-
return await this.program.instruction.placeScaleOrders(
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5642
|
+
return await (this.program.instruction as any).placeScaleOrders(
|
|
5643
|
+
formattedParams,
|
|
5644
|
+
{
|
|
5645
|
+
accounts: {
|
|
5646
|
+
state: await this.getStatePublicKey(),
|
|
5647
|
+
user,
|
|
5648
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
5649
|
+
authority: this.wallet.publicKey,
|
|
5650
|
+
},
|
|
5651
|
+
remainingAccounts,
|
|
5652
|
+
}
|
|
5653
|
+
);
|
|
5695
5654
|
}
|
|
5696
5655
|
|
|
5697
5656
|
public async fillPerpOrder(
|
|
@@ -5878,178 +5837,59 @@ export class DriftClient {
|
|
|
5878
5837
|
}
|
|
5879
5838
|
|
|
5880
5839
|
public async placeSpotOrder(
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5840
|
+
_orderParams: OptionalOrderParams,
|
|
5841
|
+
_txParams?: TxParams,
|
|
5842
|
+
_subAccountId?: number
|
|
5884
5843
|
): Promise<TransactionSignature> {
|
|
5885
|
-
|
|
5886
|
-
(await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId))
|
|
5887
|
-
.placeSpotOrderTx,
|
|
5888
|
-
[],
|
|
5889
|
-
this.opts,
|
|
5890
|
-
false
|
|
5891
|
-
);
|
|
5892
|
-
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
5893
|
-
this.spotMarketLastSlotCache.set(QUOTE_SPOT_MARKET_INDEX, slot);
|
|
5894
|
-
return txSig;
|
|
5844
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
5895
5845
|
}
|
|
5896
5846
|
|
|
5897
5847
|
public async preparePlaceSpotOrderTx(
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5848
|
+
_orderParams: OptionalOrderParams,
|
|
5849
|
+
_txParams?: TxParams,
|
|
5850
|
+
_subAccountId?: number
|
|
5901
5851
|
) {
|
|
5902
|
-
|
|
5903
|
-
await this.getPlaceSpotOrderIx(orderParams, subAccountId),
|
|
5904
|
-
txParams
|
|
5905
|
-
);
|
|
5906
|
-
|
|
5907
|
-
return {
|
|
5908
|
-
placeSpotOrderTx: tx,
|
|
5909
|
-
};
|
|
5852
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
5910
5853
|
}
|
|
5911
5854
|
|
|
5912
5855
|
public async getPlaceSpotOrderIx(
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5856
|
+
_orderParams: OptionalOrderParams,
|
|
5857
|
+
_subAccountId?: number,
|
|
5858
|
+
_overrides?: {
|
|
5916
5859
|
authority?: PublicKey;
|
|
5917
5860
|
}
|
|
5918
5861
|
): Promise<TransactionInstruction> {
|
|
5919
|
-
|
|
5920
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey(
|
|
5921
|
-
subAccountId
|
|
5922
|
-
);
|
|
5923
|
-
const authority = overrides?.authority ?? this.wallet.publicKey;
|
|
5924
|
-
|
|
5925
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
5926
|
-
userAccounts: [this.getUserAccount(subAccountId)],
|
|
5927
|
-
useMarketLastSlotCache: true,
|
|
5928
|
-
readableSpotMarketIndexes: [
|
|
5929
|
-
orderParams.marketIndex,
|
|
5930
|
-
QUOTE_SPOT_MARKET_INDEX,
|
|
5931
|
-
],
|
|
5932
|
-
});
|
|
5933
|
-
|
|
5934
|
-
return await this.program.instruction.placeSpotOrder(orderParams, {
|
|
5935
|
-
accounts: {
|
|
5936
|
-
state: await this.getStatePublicKey(),
|
|
5937
|
-
user: userAccountPublicKey,
|
|
5938
|
-
userStats: this.getUserStatsAccountPublicKey(),
|
|
5939
|
-
authority,
|
|
5940
|
-
},
|
|
5941
|
-
remainingAccounts,
|
|
5942
|
-
});
|
|
5862
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
5943
5863
|
}
|
|
5944
5864
|
|
|
5945
5865
|
public async fillSpotOrder(
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5866
|
+
_userAccountPublicKey: PublicKey,
|
|
5867
|
+
_user: UserAccount,
|
|
5868
|
+
_order?: Pick<Order, 'marketIndex' | 'orderId'>,
|
|
5869
|
+
_fulfillmentConfig?:
|
|
5950
5870
|
| SerumV3FulfillmentConfigAccount
|
|
5951
5871
|
| PhoenixV1FulfillmentConfigAccount
|
|
5952
5872
|
| OpenbookV2FulfillmentConfigAccount,
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5873
|
+
_makerInfo?: MakerInfo | MakerInfo[],
|
|
5874
|
+
_referrerInfo?: ReferrerInfo,
|
|
5875
|
+
_txParams?: TxParams
|
|
5956
5876
|
): Promise<TransactionSignature> {
|
|
5957
|
-
|
|
5958
|
-
await this.buildTransaction(
|
|
5959
|
-
await this.getFillSpotOrderIx(
|
|
5960
|
-
userAccountPublicKey,
|
|
5961
|
-
user,
|
|
5962
|
-
order,
|
|
5963
|
-
fulfillmentConfig,
|
|
5964
|
-
makerInfo,
|
|
5965
|
-
referrerInfo
|
|
5966
|
-
),
|
|
5967
|
-
txParams
|
|
5968
|
-
),
|
|
5969
|
-
[],
|
|
5970
|
-
this.opts
|
|
5971
|
-
);
|
|
5972
|
-
return txSig;
|
|
5877
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
5973
5878
|
}
|
|
5974
5879
|
|
|
5975
5880
|
public async getFillSpotOrderIx(
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5881
|
+
_userAccountPublicKey: PublicKey,
|
|
5882
|
+
_userAccount: UserAccount,
|
|
5883
|
+
_order?: Pick<Order, 'marketIndex' | 'orderId'>,
|
|
5884
|
+
_fulfillmentConfig?:
|
|
5980
5885
|
| SerumV3FulfillmentConfigAccount
|
|
5981
5886
|
| PhoenixV1FulfillmentConfigAccount
|
|
5982
5887
|
| OpenbookV2FulfillmentConfigAccount,
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5888
|
+
_makerInfo?: MakerInfo | MakerInfo[],
|
|
5889
|
+
_referrerInfo?: ReferrerInfo,
|
|
5890
|
+
_fillerPublicKey?: PublicKey
|
|
5986
5891
|
): Promise<TransactionInstruction> {
|
|
5987
|
-
|
|
5988
|
-
this.program.programId,
|
|
5989
|
-
userAccount.authority
|
|
5990
|
-
);
|
|
5991
|
-
|
|
5992
|
-
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
5993
|
-
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
5994
|
-
|
|
5995
|
-
const marketIndex = order
|
|
5996
|
-
? order.marketIndex
|
|
5997
|
-
: userAccount.orders.find(
|
|
5998
|
-
(order) => order.orderId === userAccount.nextOrderId - 1
|
|
5999
|
-
).marketIndex;
|
|
6000
|
-
|
|
6001
|
-
makerInfo = Array.isArray(makerInfo)
|
|
6002
|
-
? makerInfo
|
|
6003
|
-
: makerInfo
|
|
6004
|
-
? [makerInfo]
|
|
6005
|
-
: [];
|
|
6006
|
-
|
|
6007
|
-
const userAccounts = [userAccount];
|
|
6008
|
-
for (const maker of makerInfo) {
|
|
6009
|
-
userAccounts.push(maker.makerUserAccount);
|
|
6010
|
-
}
|
|
6011
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
6012
|
-
userAccounts,
|
|
6013
|
-
writableSpotMarketIndexes: [marketIndex, QUOTE_SPOT_MARKET_INDEX],
|
|
6014
|
-
});
|
|
6015
|
-
|
|
6016
|
-
for (const maker of makerInfo) {
|
|
6017
|
-
remainingAccounts.push({
|
|
6018
|
-
pubkey: maker.maker,
|
|
6019
|
-
isWritable: true,
|
|
6020
|
-
isSigner: false,
|
|
6021
|
-
});
|
|
6022
|
-
remainingAccounts.push({
|
|
6023
|
-
pubkey: maker.makerStats,
|
|
6024
|
-
isWritable: true,
|
|
6025
|
-
isSigner: false,
|
|
6026
|
-
});
|
|
6027
|
-
}
|
|
6028
|
-
|
|
6029
|
-
const orderId = order.orderId;
|
|
6030
|
-
|
|
6031
|
-
this.addSpotFulfillmentAccounts(
|
|
6032
|
-
marketIndex,
|
|
6033
|
-
remainingAccounts,
|
|
6034
|
-
fulfillmentConfig
|
|
6035
|
-
);
|
|
6036
|
-
|
|
6037
|
-
return await this.program.instruction.fillSpotOrder(
|
|
6038
|
-
orderId,
|
|
6039
|
-
fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null,
|
|
6040
|
-
null,
|
|
6041
|
-
{
|
|
6042
|
-
accounts: {
|
|
6043
|
-
state: await this.getStatePublicKey(),
|
|
6044
|
-
filler,
|
|
6045
|
-
fillerStats: fillerStatsPublicKey,
|
|
6046
|
-
user: userAccountPublicKey,
|
|
6047
|
-
userStats: userStatsPublicKey,
|
|
6048
|
-
authority: this.wallet.publicKey,
|
|
6049
|
-
},
|
|
6050
|
-
remainingAccounts,
|
|
6051
|
-
}
|
|
6052
|
-
);
|
|
5892
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
6053
5893
|
}
|
|
6054
5894
|
|
|
6055
5895
|
addSpotFulfillmentAccounts(
|
|
@@ -7238,7 +7078,7 @@ export class DriftClient {
|
|
|
7238
7078
|
public async getLogUserBalancesIx(
|
|
7239
7079
|
userAccountPublicKey: PublicKey
|
|
7240
7080
|
): Promise<TransactionInstruction> {
|
|
7241
|
-
const userAccount = (await this.program.account.user.fetch(
|
|
7081
|
+
const userAccount = (await (this.program.account as any).user.fetch(
|
|
7242
7082
|
userAccountPublicKey
|
|
7243
7083
|
)) as UserAccount;
|
|
7244
7084
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -7292,7 +7132,7 @@ export class DriftClient {
|
|
|
7292
7132
|
userAccounts: [userAccount],
|
|
7293
7133
|
});
|
|
7294
7134
|
|
|
7295
|
-
return await this.program.instruction.updateUserFuelBonus({
|
|
7135
|
+
return await (this.program.instruction as any).updateUserFuelBonus({
|
|
7296
7136
|
accounts: {
|
|
7297
7137
|
state: await this.getStatePublicKey(),
|
|
7298
7138
|
user: userAccountPublicKey,
|
|
@@ -7367,7 +7207,7 @@ export class DriftClient {
|
|
|
7367
7207
|
userAccounts: [userAccount],
|
|
7368
7208
|
});
|
|
7369
7209
|
|
|
7370
|
-
return await this.program.instruction.updateUserOpenOrdersCount({
|
|
7210
|
+
return await (this.program.instruction as any).updateUserOpenOrdersCount({
|
|
7371
7211
|
accounts: {
|
|
7372
7212
|
state: await this.getStatePublicKey(),
|
|
7373
7213
|
filler,
|
|
@@ -7721,14 +7561,6 @@ export class DriftClient {
|
|
|
7721
7561
|
}
|
|
7722
7562
|
}
|
|
7723
7563
|
|
|
7724
|
-
if (isUpdateHighLeverageMode(orderParams.bitFlags)) {
|
|
7725
|
-
remainingAccounts.push({
|
|
7726
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
7727
|
-
isWritable: true,
|
|
7728
|
-
isSigner: false,
|
|
7729
|
-
});
|
|
7730
|
-
}
|
|
7731
|
-
|
|
7732
7564
|
let optionalParams = null;
|
|
7733
7565
|
if (auctionDurationPercentage || successCondition) {
|
|
7734
7566
|
optionalParams =
|
|
@@ -7926,11 +7758,11 @@ export class DriftClient {
|
|
|
7926
7758
|
prefix,
|
|
7927
7759
|
delegateSigner
|
|
7928
7760
|
? this.program.coder.types.encode(
|
|
7929
|
-
'
|
|
7761
|
+
'signedMsgOrderParamsDelegateMessage',
|
|
7930
7762
|
withBuilderDefaults as SignedMsgOrderParamsDelegateMessage
|
|
7931
7763
|
)
|
|
7932
7764
|
: this.program.coder.types.encode(
|
|
7933
|
-
'
|
|
7765
|
+
'signedMsgOrderParamsMessage',
|
|
7934
7766
|
withBuilderDefaults as SignedMsgOrderParamsMessage
|
|
7935
7767
|
),
|
|
7936
7768
|
]);
|
|
@@ -7948,8 +7780,8 @@ export class DriftClient {
|
|
|
7948
7780
|
delegateSigner?: boolean
|
|
7949
7781
|
): SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage {
|
|
7950
7782
|
const decodeStr = delegateSigner
|
|
7951
|
-
? '
|
|
7952
|
-
: '
|
|
7783
|
+
? 'signedMsgOrderParamsDelegateMessage'
|
|
7784
|
+
: 'signedMsgOrderParamsMessage';
|
|
7953
7785
|
return this.program.coder.types.decode(
|
|
7954
7786
|
decodeStr,
|
|
7955
7787
|
Buffer.concat([
|
|
@@ -8033,13 +7865,6 @@ export class DriftClient {
|
|
|
8033
7865
|
writableSpotMarketIndexes,
|
|
8034
7866
|
});
|
|
8035
7867
|
|
|
8036
|
-
if (isUpdateHighLeverageMode(signedMessage.signedMsgOrderParams.bitFlags)) {
|
|
8037
|
-
remainingAccounts.push({
|
|
8038
|
-
pubkey: getHighLeverageModeConfigPublicKey(this.program.programId),
|
|
8039
|
-
isWritable: true,
|
|
8040
|
-
isSigner: false,
|
|
8041
|
-
});
|
|
8042
|
-
}
|
|
8043
7868
|
if (
|
|
8044
7869
|
signedMessage.builderFeeTenthBps !== null &&
|
|
8045
7870
|
signedMessage.builderIdx !== null
|
|
@@ -8237,216 +8062,55 @@ export class DriftClient {
|
|
|
8237
8062
|
}
|
|
8238
8063
|
|
|
8239
8064
|
public async preparePlaceAndTakeSpotOrder(
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8065
|
+
_orderParams: OptionalOrderParams,
|
|
8066
|
+
_fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
8067
|
+
_makerInfo?: MakerInfo,
|
|
8068
|
+
_referrerInfo?: ReferrerInfo,
|
|
8069
|
+
_txParams?: TxParams,
|
|
8070
|
+
_subAccountId?: number
|
|
8246
8071
|
) {
|
|
8247
|
-
|
|
8248
|
-
await this.getPlaceAndTakeSpotOrderIx(
|
|
8249
|
-
orderParams,
|
|
8250
|
-
fulfillmentConfig,
|
|
8251
|
-
makerInfo,
|
|
8252
|
-
referrerInfo,
|
|
8253
|
-
subAccountId
|
|
8254
|
-
),
|
|
8255
|
-
txParams
|
|
8256
|
-
);
|
|
8257
|
-
|
|
8258
|
-
return {
|
|
8259
|
-
placeAndTakeSpotOrderTx: tx,
|
|
8260
|
-
};
|
|
8072
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
8261
8073
|
}
|
|
8262
8074
|
|
|
8263
8075
|
public async placeAndTakeSpotOrder(
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8076
|
+
_orderParams: OptionalOrderParams,
|
|
8077
|
+
_fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
8078
|
+
_makerInfo?: MakerInfo,
|
|
8079
|
+
_referrerInfo?: ReferrerInfo,
|
|
8080
|
+
_txParams?: TxParams,
|
|
8081
|
+
_subAccountId?: number
|
|
8270
8082
|
): Promise<TransactionSignature> {
|
|
8271
|
-
|
|
8272
|
-
(
|
|
8273
|
-
await this.preparePlaceAndTakeSpotOrder(
|
|
8274
|
-
orderParams,
|
|
8275
|
-
fulfillmentConfig,
|
|
8276
|
-
makerInfo,
|
|
8277
|
-
referrerInfo,
|
|
8278
|
-
txParams,
|
|
8279
|
-
subAccountId
|
|
8280
|
-
)
|
|
8281
|
-
).placeAndTakeSpotOrderTx,
|
|
8282
|
-
[],
|
|
8283
|
-
this.opts,
|
|
8284
|
-
false
|
|
8285
|
-
);
|
|
8286
|
-
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
8287
|
-
this.spotMarketLastSlotCache.set(QUOTE_SPOT_MARKET_INDEX, slot);
|
|
8288
|
-
return txSig;
|
|
8083
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
8289
8084
|
}
|
|
8290
8085
|
public async getPlaceAndTakeSpotOrderIx(
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8086
|
+
_orderParams: OptionalOrderParams,
|
|
8087
|
+
_fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
8088
|
+
_makerInfo?: MakerInfo,
|
|
8089
|
+
_referrerInfo?: ReferrerInfo,
|
|
8090
|
+
_subAccountId?: number
|
|
8296
8091
|
): Promise<TransactionInstruction> {
|
|
8297
|
-
|
|
8298
|
-
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8299
|
-
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
8300
|
-
|
|
8301
|
-
const userAccounts = [this.getUserAccount(subAccountId)];
|
|
8302
|
-
if (makerInfo !== undefined) {
|
|
8303
|
-
userAccounts.push(makerInfo.makerUserAccount);
|
|
8304
|
-
}
|
|
8305
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
8306
|
-
userAccounts,
|
|
8307
|
-
useMarketLastSlotCache: true,
|
|
8308
|
-
writableSpotMarketIndexes: [
|
|
8309
|
-
orderParams.marketIndex,
|
|
8310
|
-
QUOTE_SPOT_MARKET_INDEX,
|
|
8311
|
-
],
|
|
8312
|
-
});
|
|
8313
|
-
|
|
8314
|
-
let makerOrderId = null;
|
|
8315
|
-
if (makerInfo) {
|
|
8316
|
-
makerOrderId = makerInfo.order.orderId;
|
|
8317
|
-
remainingAccounts.push({
|
|
8318
|
-
pubkey: makerInfo.maker,
|
|
8319
|
-
isSigner: false,
|
|
8320
|
-
isWritable: true,
|
|
8321
|
-
});
|
|
8322
|
-
remainingAccounts.push({
|
|
8323
|
-
pubkey: makerInfo.makerStats,
|
|
8324
|
-
isSigner: false,
|
|
8325
|
-
isWritable: true,
|
|
8326
|
-
});
|
|
8327
|
-
}
|
|
8328
|
-
|
|
8329
|
-
if (referrerInfo) {
|
|
8330
|
-
remainingAccounts.push({
|
|
8331
|
-
pubkey: referrerInfo.referrer,
|
|
8332
|
-
isWritable: true,
|
|
8333
|
-
isSigner: false,
|
|
8334
|
-
});
|
|
8335
|
-
remainingAccounts.push({
|
|
8336
|
-
pubkey: referrerInfo.referrerStats,
|
|
8337
|
-
isWritable: true,
|
|
8338
|
-
isSigner: false,
|
|
8339
|
-
});
|
|
8340
|
-
}
|
|
8341
|
-
|
|
8342
|
-
this.addSpotFulfillmentAccounts(
|
|
8343
|
-
orderParams.marketIndex,
|
|
8344
|
-
remainingAccounts,
|
|
8345
|
-
fulfillmentConfig
|
|
8346
|
-
);
|
|
8347
|
-
|
|
8348
|
-
return await this.program.instruction.placeAndTakeSpotOrder(
|
|
8349
|
-
orderParams,
|
|
8350
|
-
fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null,
|
|
8351
|
-
makerOrderId,
|
|
8352
|
-
{
|
|
8353
|
-
accounts: {
|
|
8354
|
-
state: await this.getStatePublicKey(),
|
|
8355
|
-
user,
|
|
8356
|
-
userStats: userStatsPublicKey,
|
|
8357
|
-
authority: this.wallet.publicKey,
|
|
8358
|
-
},
|
|
8359
|
-
remainingAccounts,
|
|
8360
|
-
}
|
|
8361
|
-
);
|
|
8092
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
8362
8093
|
}
|
|
8363
8094
|
|
|
8364
8095
|
public async placeAndMakeSpotOrder(
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8096
|
+
_orderParams: OptionalOrderParams,
|
|
8097
|
+
_takerInfo: TakerInfo,
|
|
8098
|
+
_fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
8099
|
+
_referrerInfo?: ReferrerInfo,
|
|
8100
|
+
_txParams?: TxParams,
|
|
8101
|
+
_subAccountId?: number
|
|
8371
8102
|
): Promise<TransactionSignature> {
|
|
8372
|
-
|
|
8373
|
-
await this.buildTransaction(
|
|
8374
|
-
await this.getPlaceAndMakeSpotOrderIx(
|
|
8375
|
-
orderParams,
|
|
8376
|
-
takerInfo,
|
|
8377
|
-
fulfillmentConfig,
|
|
8378
|
-
referrerInfo,
|
|
8379
|
-
subAccountId
|
|
8380
|
-
),
|
|
8381
|
-
txParams
|
|
8382
|
-
),
|
|
8383
|
-
[],
|
|
8384
|
-
this.opts
|
|
8385
|
-
);
|
|
8386
|
-
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
8387
|
-
this.spotMarketLastSlotCache.set(QUOTE_SPOT_MARKET_INDEX, slot);
|
|
8388
|
-
return txSig;
|
|
8103
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
8389
8104
|
}
|
|
8390
8105
|
|
|
8391
8106
|
public async getPlaceAndMakeSpotOrderIx(
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8107
|
+
_orderParams: OptionalOrderParams,
|
|
8108
|
+
_takerInfo: TakerInfo,
|
|
8109
|
+
_fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
8110
|
+
_referrerInfo?: ReferrerInfo,
|
|
8111
|
+
_subAccountId?: number
|
|
8397
8112
|
): Promise<TransactionInstruction> {
|
|
8398
|
-
|
|
8399
|
-
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
8400
|
-
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
8401
|
-
|
|
8402
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
8403
|
-
userAccounts: [
|
|
8404
|
-
this.getUserAccount(subAccountId),
|
|
8405
|
-
takerInfo.takerUserAccount,
|
|
8406
|
-
],
|
|
8407
|
-
useMarketLastSlotCache: true,
|
|
8408
|
-
writableSpotMarketIndexes: [
|
|
8409
|
-
orderParams.marketIndex,
|
|
8410
|
-
QUOTE_SPOT_MARKET_INDEX,
|
|
8411
|
-
],
|
|
8412
|
-
});
|
|
8413
|
-
|
|
8414
|
-
if (referrerInfo) {
|
|
8415
|
-
remainingAccounts.push({
|
|
8416
|
-
pubkey: referrerInfo.referrer,
|
|
8417
|
-
isWritable: true,
|
|
8418
|
-
isSigner: false,
|
|
8419
|
-
});
|
|
8420
|
-
remainingAccounts.push({
|
|
8421
|
-
pubkey: referrerInfo.referrerStats,
|
|
8422
|
-
isWritable: true,
|
|
8423
|
-
isSigner: false,
|
|
8424
|
-
});
|
|
8425
|
-
}
|
|
8426
|
-
|
|
8427
|
-
this.addSpotFulfillmentAccounts(
|
|
8428
|
-
orderParams.marketIndex,
|
|
8429
|
-
remainingAccounts,
|
|
8430
|
-
fulfillmentConfig
|
|
8431
|
-
);
|
|
8432
|
-
|
|
8433
|
-
const takerOrderId = takerInfo.order.orderId;
|
|
8434
|
-
return await this.program.instruction.placeAndMakeSpotOrder(
|
|
8435
|
-
orderParams,
|
|
8436
|
-
takerOrderId,
|
|
8437
|
-
fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null,
|
|
8438
|
-
{
|
|
8439
|
-
accounts: {
|
|
8440
|
-
state: await this.getStatePublicKey(),
|
|
8441
|
-
user,
|
|
8442
|
-
userStats: userStatsPublicKey,
|
|
8443
|
-
taker: takerInfo.taker,
|
|
8444
|
-
takerStats: takerInfo.takerStats,
|
|
8445
|
-
authority: this.wallet.publicKey,
|
|
8446
|
-
},
|
|
8447
|
-
remainingAccounts,
|
|
8448
|
-
}
|
|
8449
|
-
);
|
|
8113
|
+
throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
|
|
8450
8114
|
}
|
|
8451
8115
|
|
|
8452
8116
|
/**
|
|
@@ -8655,15 +8319,19 @@ export class DriftClient {
|
|
|
8655
8319
|
overrides?.authority ??
|
|
8656
8320
|
overrides?.user?.getUserAccount().authority ??
|
|
8657
8321
|
this.wallet.publicKey;
|
|
8658
|
-
return await this.program.instruction.modifyOrder(
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8322
|
+
return await (this.program.instruction as any).modifyOrder(
|
|
8323
|
+
orderId,
|
|
8324
|
+
orderParams,
|
|
8325
|
+
{
|
|
8326
|
+
accounts: {
|
|
8327
|
+
state: await this.getStatePublicKey(),
|
|
8328
|
+
user: userPubKey,
|
|
8329
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
8330
|
+
authority,
|
|
8331
|
+
},
|
|
8332
|
+
remainingAccounts,
|
|
8333
|
+
}
|
|
8334
|
+
);
|
|
8667
8335
|
}
|
|
8668
8336
|
|
|
8669
8337
|
/**
|
|
@@ -8776,7 +8444,7 @@ export class DriftClient {
|
|
|
8776
8444
|
maxTs: maxTs || null,
|
|
8777
8445
|
};
|
|
8778
8446
|
|
|
8779
|
-
return await this.program.instruction.modifyOrderByUserId(
|
|
8447
|
+
return await (this.program.instruction as any).modifyOrderByUserId(
|
|
8780
8448
|
userOrderId,
|
|
8781
8449
|
orderParams,
|
|
8782
8450
|
{
|
|
@@ -10268,7 +9936,7 @@ export class DriftClient {
|
|
|
10268
9936
|
public async getSettleFundingPaymentIx(
|
|
10269
9937
|
userAccountPublicKey: PublicKey
|
|
10270
9938
|
): Promise<TransactionInstruction> {
|
|
10271
|
-
const userAccount = (await this.program.account.user.fetch(
|
|
9939
|
+
const userAccount = (await (this.program.account as any).user.fetch(
|
|
10272
9940
|
userAccountPublicKey
|
|
10273
9941
|
)) as UserAccount;
|
|
10274
9942
|
|
|
@@ -10651,23 +10319,21 @@ export class DriftClient {
|
|
|
10651
10319
|
marketIndex
|
|
10652
10320
|
);
|
|
10653
10321
|
|
|
10654
|
-
const ix = await
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
{
|
|
10658
|
-
|
|
10659
|
-
|
|
10660
|
-
|
|
10661
|
-
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
10668
|
-
|
|
10669
|
-
}
|
|
10670
|
-
);
|
|
10322
|
+
const ix = await (
|
|
10323
|
+
this.program.instruction as any
|
|
10324
|
+
).requestRemoveInsuranceFundStake(marketIndex, amount, {
|
|
10325
|
+
accounts: {
|
|
10326
|
+
state: await this.getStatePublicKey(),
|
|
10327
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
10328
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
10329
|
+
userStats: getUserStatsAccountPublicKey(
|
|
10330
|
+
this.program.programId,
|
|
10331
|
+
this.wallet.publicKey // only allow payer to request remove own insurance fund stake account
|
|
10332
|
+
),
|
|
10333
|
+
authority: this.wallet.publicKey,
|
|
10334
|
+
insuranceFundVault: spotMarketAccount.insuranceFund.vault,
|
|
10335
|
+
},
|
|
10336
|
+
});
|
|
10671
10337
|
|
|
10672
10338
|
const tx = await this.buildTransaction(ix, txParams);
|
|
10673
10339
|
|
|
@@ -10686,23 +10352,21 @@ export class DriftClient {
|
|
|
10686
10352
|
marketIndex
|
|
10687
10353
|
);
|
|
10688
10354
|
|
|
10689
|
-
const ix =
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
}
|
|
10705
|
-
);
|
|
10355
|
+
const ix = await (
|
|
10356
|
+
this.program.instruction as any
|
|
10357
|
+
).cancelRequestRemoveInsuranceFundStake(marketIndex, {
|
|
10358
|
+
accounts: {
|
|
10359
|
+
state: await this.getStatePublicKey(),
|
|
10360
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
10361
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
10362
|
+
userStats: getUserStatsAccountPublicKey(
|
|
10363
|
+
this.program.programId,
|
|
10364
|
+
this.wallet.publicKey // only allow payer to request remove own insurance fund stake account
|
|
10365
|
+
),
|
|
10366
|
+
authority: this.wallet.publicKey,
|
|
10367
|
+
insuranceFundVault: spotMarketAccount.insuranceFund.vault,
|
|
10368
|
+
},
|
|
10369
|
+
});
|
|
10706
10370
|
|
|
10707
10371
|
const tx = await this.buildTransaction(ix, txParams);
|
|
10708
10372
|
|
|
@@ -11069,14 +10733,10 @@ export class DriftClient {
|
|
|
11069
10733
|
public getMarketFees(
|
|
11070
10734
|
marketType: MarketType,
|
|
11071
10735
|
marketIndex?: number,
|
|
11072
|
-
user?: User
|
|
11073
|
-
enteringHighLeverageMode?: boolean
|
|
10736
|
+
user?: User
|
|
11074
10737
|
) {
|
|
11075
10738
|
let feeTier;
|
|
11076
|
-
|
|
11077
|
-
(user?.isHighLeverageMode('Initial') ?? false) ||
|
|
11078
|
-
enteringHighLeverageMode;
|
|
11079
|
-
if (user && !userHLM) {
|
|
10739
|
+
if (user) {
|
|
11080
10740
|
feeTier = user.getUserFeeTier(marketType);
|
|
11081
10741
|
} else {
|
|
11082
10742
|
const state = this.getStateAccount();
|
|
@@ -11098,9 +10758,6 @@ export class DriftClient {
|
|
|
11098
10758
|
}
|
|
11099
10759
|
|
|
11100
10760
|
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
11101
|
-
if (userHLM) {
|
|
11102
|
-
takerFee *= 2;
|
|
11103
|
-
}
|
|
11104
10761
|
makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
|
|
11105
10762
|
}
|
|
11106
10763
|
|
|
@@ -11141,240 +10798,6 @@ export class DriftClient {
|
|
|
11141
10798
|
return undefined;
|
|
11142
10799
|
}
|
|
11143
10800
|
|
|
11144
|
-
public getReceiverProgram(): Program<PythSolanaReceiver> {
|
|
11145
|
-
if (this.receiverProgram === undefined) {
|
|
11146
|
-
this.receiverProgram = new Program(
|
|
11147
|
-
pythSolanaReceiverIdl as PythSolanaReceiver,
|
|
11148
|
-
DEFAULT_RECEIVER_PROGRAM_ID,
|
|
11149
|
-
this.provider
|
|
11150
|
-
);
|
|
11151
|
-
}
|
|
11152
|
-
return this.receiverProgram;
|
|
11153
|
-
}
|
|
11154
|
-
|
|
11155
|
-
public async getSwitchboardOnDemandProgram(): Promise<Program30<Idl30>> {
|
|
11156
|
-
if (this.sbOnDemandProgram === undefined) {
|
|
11157
|
-
this.sbOnDemandProgram = await AnchorUtils.loadProgramFromConnection(
|
|
11158
|
-
this.connection
|
|
11159
|
-
);
|
|
11160
|
-
}
|
|
11161
|
-
return this.sbOnDemandProgram;
|
|
11162
|
-
}
|
|
11163
|
-
|
|
11164
|
-
public async postPythPullOracleUpdateAtomic(
|
|
11165
|
-
vaaString: string,
|
|
11166
|
-
feedId: string
|
|
11167
|
-
): Promise<TransactionSignature> {
|
|
11168
|
-
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(
|
|
11169
|
-
vaaString,
|
|
11170
|
-
feedId
|
|
11171
|
-
);
|
|
11172
|
-
const tx = await this.buildTransaction(postIxs);
|
|
11173
|
-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
11174
|
-
|
|
11175
|
-
return txSig;
|
|
11176
|
-
}
|
|
11177
|
-
|
|
11178
|
-
public async postMultiPythPullOracleUpdatesAtomic(
|
|
11179
|
-
vaaString: string,
|
|
11180
|
-
feedIds: string[]
|
|
11181
|
-
): Promise<TransactionSignature> {
|
|
11182
|
-
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(
|
|
11183
|
-
vaaString,
|
|
11184
|
-
feedIds
|
|
11185
|
-
);
|
|
11186
|
-
const tx = await this.buildTransaction(postIxs);
|
|
11187
|
-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
11188
|
-
|
|
11189
|
-
return txSig;
|
|
11190
|
-
}
|
|
11191
|
-
|
|
11192
|
-
public async getPostPythPullOracleUpdateAtomicIxs(
|
|
11193
|
-
vaaString: string,
|
|
11194
|
-
feedIds: string | string[],
|
|
11195
|
-
numSignatures = 2
|
|
11196
|
-
): Promise<TransactionInstruction[]> {
|
|
11197
|
-
const accumulatorUpdateData = parseAccumulatorUpdateData(
|
|
11198
|
-
Buffer.from(vaaString, 'base64')
|
|
11199
|
-
);
|
|
11200
|
-
const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
|
|
11201
|
-
const guardianSet = getGuardianSetPda(
|
|
11202
|
-
guardianSetIndex,
|
|
11203
|
-
DEFAULT_WORMHOLE_PROGRAM_ID
|
|
11204
|
-
);
|
|
11205
|
-
|
|
11206
|
-
const trimmedVaa = trimVaaSignatures(
|
|
11207
|
-
accumulatorUpdateData.vaa,
|
|
11208
|
-
numSignatures
|
|
11209
|
-
);
|
|
11210
|
-
|
|
11211
|
-
const postIxs: TransactionInstruction[] = [];
|
|
11212
|
-
if (accumulatorUpdateData.updates.length > 1) {
|
|
11213
|
-
const encodedParams = this.getReceiverProgram().coder.types.encode(
|
|
11214
|
-
'PostMultiUpdatesAtomicParams',
|
|
11215
|
-
{
|
|
11216
|
-
vaa: trimmedVaa,
|
|
11217
|
-
merklePriceUpdates: accumulatorUpdateData.updates,
|
|
11218
|
-
}
|
|
11219
|
-
);
|
|
11220
|
-
const feedIdsToUse: string[] =
|
|
11221
|
-
typeof feedIds === 'string' ? [feedIds] : feedIds;
|
|
11222
|
-
const pubkeys = feedIdsToUse.map((feedId) => {
|
|
11223
|
-
return getPythPullOraclePublicKey(
|
|
11224
|
-
this.program.programId,
|
|
11225
|
-
getFeedIdUint8Array(feedId)
|
|
11226
|
-
);
|
|
11227
|
-
});
|
|
11228
|
-
|
|
11229
|
-
const remainingAccounts: Array<AccountMeta> = pubkeys.map((pubkey) => {
|
|
11230
|
-
return {
|
|
11231
|
-
pubkey,
|
|
11232
|
-
isSigner: false,
|
|
11233
|
-
isWritable: true,
|
|
11234
|
-
};
|
|
11235
|
-
});
|
|
11236
|
-
postIxs.push(
|
|
11237
|
-
this.program.instruction.postMultiPythPullOracleUpdatesAtomic(
|
|
11238
|
-
encodedParams,
|
|
11239
|
-
{
|
|
11240
|
-
accounts: {
|
|
11241
|
-
keeper: this.wallet.publicKey,
|
|
11242
|
-
pythSolanaReceiver: DRIFT_ORACLE_RECEIVER_ID,
|
|
11243
|
-
guardianSet,
|
|
11244
|
-
},
|
|
11245
|
-
remainingAccounts,
|
|
11246
|
-
}
|
|
11247
|
-
)
|
|
11248
|
-
);
|
|
11249
|
-
} else {
|
|
11250
|
-
let feedIdToUse = typeof feedIds === 'string' ? feedIds : feedIds[0];
|
|
11251
|
-
feedIdToUse = trimFeedId(feedIdToUse);
|
|
11252
|
-
postIxs.push(
|
|
11253
|
-
await this.getSinglePostPythPullOracleAtomicIx(
|
|
11254
|
-
{
|
|
11255
|
-
vaa: trimmedVaa,
|
|
11256
|
-
merklePriceUpdate: accumulatorUpdateData.updates[0],
|
|
11257
|
-
},
|
|
11258
|
-
feedIdToUse,
|
|
11259
|
-
guardianSet
|
|
11260
|
-
)
|
|
11261
|
-
);
|
|
11262
|
-
}
|
|
11263
|
-
return postIxs;
|
|
11264
|
-
}
|
|
11265
|
-
|
|
11266
|
-
private async getSinglePostPythPullOracleAtomicIx(
|
|
11267
|
-
params: {
|
|
11268
|
-
vaa: Buffer;
|
|
11269
|
-
merklePriceUpdate: {
|
|
11270
|
-
message: Buffer;
|
|
11271
|
-
proof: number[][];
|
|
11272
|
-
};
|
|
11273
|
-
},
|
|
11274
|
-
feedId: string,
|
|
11275
|
-
guardianSet: PublicKey
|
|
11276
|
-
): Promise<TransactionInstruction> {
|
|
11277
|
-
const feedIdBuffer = getFeedIdUint8Array(feedId);
|
|
11278
|
-
const receiverProgram = this.getReceiverProgram();
|
|
11279
|
-
|
|
11280
|
-
const encodedParams = receiverProgram.coder.types.encode(
|
|
11281
|
-
'PostUpdateAtomicParams',
|
|
11282
|
-
params
|
|
11283
|
-
);
|
|
11284
|
-
|
|
11285
|
-
return this.program.instruction.postPythPullOracleUpdateAtomic(
|
|
11286
|
-
feedIdBuffer,
|
|
11287
|
-
encodedParams,
|
|
11288
|
-
{
|
|
11289
|
-
accounts: {
|
|
11290
|
-
keeper: this.wallet.publicKey,
|
|
11291
|
-
pythSolanaReceiver: DRIFT_ORACLE_RECEIVER_ID,
|
|
11292
|
-
guardianSet,
|
|
11293
|
-
priceFeed: getPythPullOraclePublicKey(
|
|
11294
|
-
this.program.programId,
|
|
11295
|
-
feedIdBuffer
|
|
11296
|
-
),
|
|
11297
|
-
},
|
|
11298
|
-
}
|
|
11299
|
-
);
|
|
11300
|
-
}
|
|
11301
|
-
|
|
11302
|
-
public async updatePythPullOracle(
|
|
11303
|
-
vaaString: string,
|
|
11304
|
-
feedId: string
|
|
11305
|
-
): Promise<TransactionSignature> {
|
|
11306
|
-
feedId = trimFeedId(feedId);
|
|
11307
|
-
const accumulatorUpdateData = parseAccumulatorUpdateData(
|
|
11308
|
-
Buffer.from(vaaString, 'base64')
|
|
11309
|
-
);
|
|
11310
|
-
const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
|
|
11311
|
-
const guardianSet = getGuardianSetPda(
|
|
11312
|
-
guardianSetIndex,
|
|
11313
|
-
DEFAULT_WORMHOLE_PROGRAM_ID
|
|
11314
|
-
);
|
|
11315
|
-
|
|
11316
|
-
const [postIxs, encodedVaaAddress] = await this.getBuildEncodedVaaIxs(
|
|
11317
|
-
accumulatorUpdateData.vaa,
|
|
11318
|
-
guardianSet
|
|
11319
|
-
);
|
|
11320
|
-
|
|
11321
|
-
for (const update of accumulatorUpdateData.updates) {
|
|
11322
|
-
postIxs.push(
|
|
11323
|
-
await this.getUpdatePythPullOracleIxs(
|
|
11324
|
-
{
|
|
11325
|
-
merklePriceUpdate: update,
|
|
11326
|
-
},
|
|
11327
|
-
feedId,
|
|
11328
|
-
encodedVaaAddress.publicKey
|
|
11329
|
-
)
|
|
11330
|
-
);
|
|
11331
|
-
}
|
|
11332
|
-
|
|
11333
|
-
const tx = await this.buildTransaction(postIxs);
|
|
11334
|
-
const { txSig } = await this.sendTransaction(
|
|
11335
|
-
tx,
|
|
11336
|
-
[encodedVaaAddress],
|
|
11337
|
-
this.opts
|
|
11338
|
-
);
|
|
11339
|
-
|
|
11340
|
-
return txSig;
|
|
11341
|
-
}
|
|
11342
|
-
|
|
11343
|
-
public async getUpdatePythPullOracleIxs(
|
|
11344
|
-
params: {
|
|
11345
|
-
merklePriceUpdate: {
|
|
11346
|
-
message: Buffer;
|
|
11347
|
-
proof: number[][];
|
|
11348
|
-
};
|
|
11349
|
-
},
|
|
11350
|
-
feedId: string,
|
|
11351
|
-
encodedVaaAddress: PublicKey
|
|
11352
|
-
): Promise<TransactionInstruction> {
|
|
11353
|
-
const feedIdBuffer = getFeedIdUint8Array(feedId);
|
|
11354
|
-
const receiverProgram = this.getReceiverProgram();
|
|
11355
|
-
|
|
11356
|
-
const encodedParams = receiverProgram.coder.types.encode(
|
|
11357
|
-
'PostUpdateParams',
|
|
11358
|
-
params
|
|
11359
|
-
);
|
|
11360
|
-
|
|
11361
|
-
return this.program.instruction.updatePythPullOracle(
|
|
11362
|
-
feedIdBuffer,
|
|
11363
|
-
encodedParams,
|
|
11364
|
-
{
|
|
11365
|
-
accounts: {
|
|
11366
|
-
keeper: this.wallet.publicKey,
|
|
11367
|
-
pythSolanaReceiver: DRIFT_ORACLE_RECEIVER_ID,
|
|
11368
|
-
encodedVaa: encodedVaaAddress,
|
|
11369
|
-
priceFeed: getPythPullOraclePublicKey(
|
|
11370
|
-
this.program.programId,
|
|
11371
|
-
feedIdBuffer
|
|
11372
|
-
),
|
|
11373
|
-
},
|
|
11374
|
-
}
|
|
11375
|
-
);
|
|
11376
|
-
}
|
|
11377
|
-
|
|
11378
10801
|
public async postPythLazerOracleUpdate(
|
|
11379
10802
|
feedIds: number[],
|
|
11380
10803
|
pythMessageHex: string
|
|
@@ -11426,282 +10849,13 @@ export class DriftClient {
|
|
|
11426
10849
|
return [verifyIx, ix];
|
|
11427
10850
|
}
|
|
11428
10851
|
|
|
11429
|
-
public async getPostManySwitchboardOnDemandUpdatesAtomicIxs(
|
|
11430
|
-
feeds: PublicKey[],
|
|
11431
|
-
recentSlothash?: Slothash,
|
|
11432
|
-
numSignatures = 3
|
|
11433
|
-
): Promise<TransactionInstruction[] | undefined> {
|
|
11434
|
-
const program = await this.getSwitchboardOnDemandProgram();
|
|
11435
|
-
const [pullIxs, _luts, _rawResponse] =
|
|
11436
|
-
await PullFeed.fetchUpdateManyLightIx(program, {
|
|
11437
|
-
feeds,
|
|
11438
|
-
numSignatures,
|
|
11439
|
-
recentSlothashes: recentSlothash
|
|
11440
|
-
? [[new BN(recentSlothash.slot), recentSlothash.hash]]
|
|
11441
|
-
: undefined,
|
|
11442
|
-
chain: 'solana',
|
|
11443
|
-
network: this.env,
|
|
11444
|
-
});
|
|
11445
|
-
if (!pullIxs) {
|
|
11446
|
-
return undefined;
|
|
11447
|
-
}
|
|
11448
|
-
return pullIxs;
|
|
11449
|
-
}
|
|
11450
|
-
|
|
11451
|
-
// @deprecated use getPostManySwitchboardOnDemandUpdatesAtomicIxs instead. This function no longer returns the required ixs due to upstream sdk changes.
|
|
11452
|
-
public async getPostSwitchboardOnDemandUpdateAtomicIx(
|
|
11453
|
-
feed: PublicKey,
|
|
11454
|
-
recentSlothash?: Slothash,
|
|
11455
|
-
numSignatures = 3
|
|
11456
|
-
): Promise<TransactionInstruction | undefined> {
|
|
11457
|
-
const program = await this.getSwitchboardOnDemandProgram();
|
|
11458
|
-
const feedAccount = new PullFeed(program, feed);
|
|
11459
|
-
if (!this.sbProgramFeedConfigs) {
|
|
11460
|
-
this.sbProgramFeedConfigs = new Map();
|
|
11461
|
-
}
|
|
11462
|
-
if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
|
|
11463
|
-
const feedConfig = await feedAccount.loadConfigs();
|
|
11464
|
-
this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
|
|
11465
|
-
}
|
|
11466
|
-
const [pullIx, _responses, success] = await PullFeed.fetchUpdateManyIx(
|
|
11467
|
-
program,
|
|
11468
|
-
{
|
|
11469
|
-
feeds: [feed],
|
|
11470
|
-
numSignatures,
|
|
11471
|
-
recentSlothashes: recentSlothash
|
|
11472
|
-
? [[new BN(recentSlothash.slot), recentSlothash.hash]]
|
|
11473
|
-
: undefined,
|
|
11474
|
-
}
|
|
11475
|
-
);
|
|
11476
|
-
if (!success) {
|
|
11477
|
-
return undefined;
|
|
11478
|
-
}
|
|
11479
|
-
return pullIx[0];
|
|
11480
|
-
}
|
|
11481
|
-
|
|
11482
|
-
public async postSwitchboardOnDemandUpdate(
|
|
11483
|
-
feed: PublicKey,
|
|
11484
|
-
recentSlothash?: Slothash,
|
|
11485
|
-
numSignatures = 3
|
|
11486
|
-
): Promise<TransactionSignature> {
|
|
11487
|
-
const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(
|
|
11488
|
-
feed,
|
|
11489
|
-
recentSlothash,
|
|
11490
|
-
numSignatures
|
|
11491
|
-
);
|
|
11492
|
-
if (!pullIx) {
|
|
11493
|
-
return undefined;
|
|
11494
|
-
}
|
|
11495
|
-
const tx = await asV0Tx({
|
|
11496
|
-
connection: this.connection,
|
|
11497
|
-
ixs: [pullIx],
|
|
11498
|
-
payer: this.wallet.publicKey,
|
|
11499
|
-
computeUnitLimitMultiple: 1.3,
|
|
11500
|
-
lookupTables: await this.fetchAllLookupTableAccounts(),
|
|
11501
|
-
});
|
|
11502
|
-
const { txSig } = await this.sendTransaction(tx, [], {
|
|
11503
|
-
commitment: 'processed',
|
|
11504
|
-
skipPreflight: true,
|
|
11505
|
-
maxRetries: 0,
|
|
11506
|
-
});
|
|
11507
|
-
return txSig;
|
|
11508
|
-
}
|
|
11509
|
-
|
|
11510
|
-
private async getBuildEncodedVaaIxs(
|
|
11511
|
-
vaa: Buffer,
|
|
11512
|
-
guardianSet: PublicKey
|
|
11513
|
-
): Promise<[TransactionInstruction[], Keypair]> {
|
|
11514
|
-
const postIxs: TransactionInstruction[] = [];
|
|
11515
|
-
|
|
11516
|
-
if (this.wormholeProgram === undefined) {
|
|
11517
|
-
this.wormholeProgram = new Program(
|
|
11518
|
-
WORMHOLE_CORE_BRIDGE_SOLANA_IDL,
|
|
11519
|
-
DEFAULT_WORMHOLE_PROGRAM_ID,
|
|
11520
|
-
this.provider
|
|
11521
|
-
);
|
|
11522
|
-
}
|
|
11523
|
-
|
|
11524
|
-
const encodedVaaKeypair = new Keypair();
|
|
11525
|
-
postIxs.push(
|
|
11526
|
-
await this.wormholeProgram.account.encodedVaa.createInstruction(
|
|
11527
|
-
encodedVaaKeypair,
|
|
11528
|
-
vaa.length + 46
|
|
11529
|
-
)
|
|
11530
|
-
);
|
|
11531
|
-
|
|
11532
|
-
// Why do we need this too?
|
|
11533
|
-
postIxs.push(
|
|
11534
|
-
await this.wormholeProgram.methods
|
|
11535
|
-
.initEncodedVaa()
|
|
11536
|
-
.accounts({
|
|
11537
|
-
encodedVaa: encodedVaaKeypair.publicKey,
|
|
11538
|
-
})
|
|
11539
|
-
.instruction()
|
|
11540
|
-
);
|
|
11541
|
-
|
|
11542
|
-
// Split the write into two ixs
|
|
11543
|
-
postIxs.push(
|
|
11544
|
-
await this.wormholeProgram.methods
|
|
11545
|
-
.writeEncodedVaa({
|
|
11546
|
-
index: 0,
|
|
11547
|
-
data: vaa.subarray(0, 755),
|
|
11548
|
-
})
|
|
11549
|
-
.accounts({
|
|
11550
|
-
draftVaa: encodedVaaKeypair.publicKey,
|
|
11551
|
-
})
|
|
11552
|
-
.instruction()
|
|
11553
|
-
);
|
|
11554
|
-
|
|
11555
|
-
postIxs.push(
|
|
11556
|
-
await this.wormholeProgram.methods
|
|
11557
|
-
.writeEncodedVaa({
|
|
11558
|
-
index: 755,
|
|
11559
|
-
data: vaa.subarray(755),
|
|
11560
|
-
})
|
|
11561
|
-
.accounts({
|
|
11562
|
-
draftVaa: encodedVaaKeypair.publicKey,
|
|
11563
|
-
})
|
|
11564
|
-
.instruction()
|
|
11565
|
-
);
|
|
11566
|
-
|
|
11567
|
-
// Verify
|
|
11568
|
-
postIxs.push(
|
|
11569
|
-
await this.wormholeProgram.methods
|
|
11570
|
-
.verifyEncodedVaaV1()
|
|
11571
|
-
.accounts({
|
|
11572
|
-
guardianSet,
|
|
11573
|
-
draftVaa: encodedVaaKeypair.publicKey,
|
|
11574
|
-
})
|
|
11575
|
-
.instruction()
|
|
11576
|
-
);
|
|
11577
|
-
|
|
11578
|
-
return [postIxs, encodedVaaKeypair];
|
|
11579
|
-
}
|
|
11580
|
-
|
|
11581
|
-
public async enableUserHighLeverageMode(
|
|
11582
|
-
subAccountId: number,
|
|
11583
|
-
txParams?: TxParams
|
|
11584
|
-
): Promise<TransactionSignature> {
|
|
11585
|
-
const { txSig } = await this.sendTransaction(
|
|
11586
|
-
await this.buildTransaction(
|
|
11587
|
-
await this.getEnableHighLeverageModeIx(subAccountId),
|
|
11588
|
-
txParams
|
|
11589
|
-
),
|
|
11590
|
-
[],
|
|
11591
|
-
this.opts
|
|
11592
|
-
);
|
|
11593
|
-
return txSig;
|
|
11594
|
-
}
|
|
11595
|
-
|
|
11596
|
-
public async getEnableHighLeverageModeIx(
|
|
11597
|
-
subAccountId: number,
|
|
11598
|
-
depositToTradeArgs?: {
|
|
11599
|
-
isMakingNewAccount: boolean;
|
|
11600
|
-
depositMarketIndex: number;
|
|
11601
|
-
orderMarketIndex: number;
|
|
11602
|
-
},
|
|
11603
|
-
overrides?: {
|
|
11604
|
-
user?: User;
|
|
11605
|
-
signingAuthority?: PublicKey;
|
|
11606
|
-
}
|
|
11607
|
-
): Promise<TransactionInstruction> {
|
|
11608
|
-
const isDepositToTradeTx = depositToTradeArgs !== undefined;
|
|
11609
|
-
const userAccountPublicKey =
|
|
11610
|
-
overrides?.user?.getUserAccountPublicKey() ??
|
|
11611
|
-
getUserAccountPublicKeySync(
|
|
11612
|
-
this.program.programId,
|
|
11613
|
-
this.wallet.publicKey,
|
|
11614
|
-
subAccountId
|
|
11615
|
-
);
|
|
11616
|
-
const signingAuthority =
|
|
11617
|
-
overrides?.signingAuthority ?? this.wallet.publicKey;
|
|
11618
|
-
const userAccount =
|
|
11619
|
-
overrides?.user.getUserAccount() ?? this.getUserAccount(subAccountId);
|
|
11620
|
-
|
|
11621
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
11622
|
-
userAccounts: depositToTradeArgs?.isMakingNewAccount ? [] : [userAccount],
|
|
11623
|
-
useMarketLastSlotCache: false,
|
|
11624
|
-
readablePerpMarketIndex: depositToTradeArgs?.orderMarketIndex,
|
|
11625
|
-
readableSpotMarketIndexes: isDepositToTradeTx
|
|
11626
|
-
? [depositToTradeArgs?.depositMarketIndex]
|
|
11627
|
-
: undefined,
|
|
11628
|
-
});
|
|
11629
|
-
|
|
11630
|
-
const ix = await this.program.instruction.enableUserHighLeverageMode(
|
|
11631
|
-
subAccountId,
|
|
11632
|
-
{
|
|
11633
|
-
accounts: {
|
|
11634
|
-
state: await this.getStatePublicKey(),
|
|
11635
|
-
user: userAccountPublicKey,
|
|
11636
|
-
authority: signingAuthority,
|
|
11637
|
-
highLeverageModeConfig: getHighLeverageModeConfigPublicKey(
|
|
11638
|
-
this.program.programId
|
|
11639
|
-
),
|
|
11640
|
-
},
|
|
11641
|
-
remainingAccounts,
|
|
11642
|
-
}
|
|
11643
|
-
);
|
|
11644
|
-
|
|
11645
|
-
return ix;
|
|
11646
|
-
}
|
|
11647
|
-
|
|
11648
|
-
public async disableUserHighLeverageMode(
|
|
11649
|
-
user: PublicKey,
|
|
11650
|
-
userAccount?: UserAccount,
|
|
11651
|
-
txParams?: TxParams
|
|
11652
|
-
): Promise<TransactionSignature> {
|
|
11653
|
-
const { txSig } = await this.sendTransaction(
|
|
11654
|
-
await this.buildTransaction(
|
|
11655
|
-
await this.getDisableHighLeverageModeIx(user, userAccount),
|
|
11656
|
-
txParams
|
|
11657
|
-
),
|
|
11658
|
-
[],
|
|
11659
|
-
this.opts
|
|
11660
|
-
);
|
|
11661
|
-
return txSig;
|
|
11662
|
-
}
|
|
11663
|
-
|
|
11664
|
-
public async getDisableHighLeverageModeIx(
|
|
11665
|
-
user: PublicKey,
|
|
11666
|
-
userAccount?: UserAccount,
|
|
11667
|
-
maintenance = false
|
|
11668
|
-
): Promise<TransactionInstruction> {
|
|
11669
|
-
const remainingAccounts = userAccount
|
|
11670
|
-
? this.getRemainingAccounts({
|
|
11671
|
-
userAccounts: [userAccount],
|
|
11672
|
-
})
|
|
11673
|
-
: undefined;
|
|
11674
|
-
|
|
11675
|
-
const ix = await this.program.instruction.disableUserHighLeverageMode(
|
|
11676
|
-
maintenance,
|
|
11677
|
-
{
|
|
11678
|
-
accounts: {
|
|
11679
|
-
state: await this.getStatePublicKey(),
|
|
11680
|
-
user,
|
|
11681
|
-
authority: this.wallet.publicKey,
|
|
11682
|
-
highLeverageModeConfig: getHighLeverageModeConfigPublicKey(
|
|
11683
|
-
this.program.programId
|
|
11684
|
-
),
|
|
11685
|
-
},
|
|
11686
|
-
remainingAccounts,
|
|
11687
|
-
}
|
|
11688
|
-
);
|
|
11689
|
-
|
|
11690
|
-
return ix;
|
|
11691
|
-
}
|
|
11692
|
-
|
|
11693
|
-
public async fetchHighLeverageModeConfig(): Promise<HighLeverageModeConfig> {
|
|
11694
|
-
const config = await this.program.account.highLeverageModeConfig.fetch(
|
|
11695
|
-
getHighLeverageModeConfigPublicKey(this.program.programId)
|
|
11696
|
-
);
|
|
11697
|
-
return config as HighLeverageModeConfig;
|
|
11698
|
-
}
|
|
11699
|
-
|
|
11700
10852
|
public async fetchProtectedMakerModeConfig(): Promise<ProtectedMakerModeConfig> {
|
|
11701
|
-
const config = await
|
|
10853
|
+
const config = await (
|
|
10854
|
+
this.program.account as any
|
|
10855
|
+
).protectedMakerModeConfig.fetch(
|
|
11702
10856
|
getProtectedMakerModeConfigPublicKey(this.program.programId)
|
|
11703
10857
|
);
|
|
11704
|
-
return config as ProtectedMakerModeConfig;
|
|
10858
|
+
return config as unknown as ProtectedMakerModeConfig;
|
|
11705
10859
|
}
|
|
11706
10860
|
public async updateUserProtectedMakerOrders(
|
|
11707
10861
|
subAccountId: number,
|
|
@@ -11887,15 +11041,15 @@ export class DriftClient {
|
|
|
11887
11041
|
}
|
|
11888
11042
|
|
|
11889
11043
|
public async getLpPoolAccount(lpPoolId: number): Promise<LPPoolAccount> {
|
|
11890
|
-
return (await this.program.account.lpPool.fetch(
|
|
11044
|
+
return (await (this.program.account as any).lpPool.fetch(
|
|
11891
11045
|
getLpPoolPublicKey(this.program.programId, lpPoolId)
|
|
11892
|
-
)) as LPPoolAccount;
|
|
11046
|
+
)) as unknown as LPPoolAccount;
|
|
11893
11047
|
}
|
|
11894
11048
|
|
|
11895
11049
|
public async getConstituentTargetBaseAccount(
|
|
11896
11050
|
lpPoolId: number
|
|
11897
11051
|
): Promise<ConstituentTargetBaseAccount> {
|
|
11898
|
-
return (await this.program.account.constituentTargetBase.fetch(
|
|
11052
|
+
return (await (this.program.account as any).constituentTargetBase.fetch(
|
|
11899
11053
|
getConstituentTargetBasePublicKey(
|
|
11900
11054
|
this.program.programId,
|
|
11901
11055
|
getLpPoolPublicKey(this.program.programId, lpPoolId)
|
|
@@ -11904,7 +11058,7 @@ export class DriftClient {
|
|
|
11904
11058
|
}
|
|
11905
11059
|
|
|
11906
11060
|
public async getAmmCache(): Promise<AmmCache> {
|
|
11907
|
-
return (await this.program.account.ammCache.fetch(
|
|
11061
|
+
return (await (this.program.account as any).ammCache.fetch(
|
|
11908
11062
|
getAmmCachePublicKey(this.program.programId)
|
|
11909
11063
|
)) as AmmCache;
|
|
11910
11064
|
}
|