@drift-labs/sdk-browser 2.104.0-beta.21
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/README.md +276 -0
- package/VERSION +1 -0
- package/bun.lockb +0 -0
- package/get_events.ts +47 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/basicUserAccountSubscriber.js +38 -0
- package/lib/browser/accounts/bulkAccountLoader.d.ts +37 -0
- package/lib/browser/accounts/bulkAccountLoader.js +222 -0
- package/lib/browser/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/browser/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/browser/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/browser/accounts/bulkUserSubscription.js +21 -0
- package/lib/browser/accounts/fetch.d.ts +6 -0
- package/lib/browser/accounts/fetch.js +30 -0
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/browser/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +98 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
- package/lib/browser/accounts/oneShotUserAccountSubscriber.js +48 -0
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +418 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/pollingOracleAccountSubscriber.js +78 -0
- package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/browser/accounts/pollingTokenAccountSubscriber.js +78 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingUserAccountSubscriber.js +102 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +94 -0
- package/lib/browser/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/browser/accounts/testBulkAccountLoader.js +45 -0
- package/lib/browser/accounts/types.d.ts +168 -0
- package/lib/browser/accounts/types.js +16 -0
- package/lib/browser/accounts/utils.d.ts +8 -0
- package/lib/browser/accounts/utils.js +49 -0
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/webSocketAccountSubscriber.js +149 -0
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +120 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketUserAccountSubscriber.js +61 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
- package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
- package/lib/browser/addresses/marketAddresses.d.ts +2 -0
- package/lib/browser/addresses/marketAddresses.js +15 -0
- package/lib/browser/addresses/pda.d.ts +32 -0
- package/lib/browser/addresses/pda.js +211 -0
- package/lib/browser/adminClient.d.ts +206 -0
- package/lib/browser/adminClient.js +1858 -0
- package/lib/browser/assert/assert.d.ts +1 -0
- package/lib/browser/assert/assert.js +9 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +14 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +32 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/browser/auctionSubscriber/index.d.ts +3 -0
- package/lib/browser/auctionSubscriber/index.js +19 -0
- package/lib/browser/auctionSubscriber/types.d.ts +14 -0
- package/lib/browser/auctionSubscriber/types.js +2 -0
- package/lib/browser/bankrun/bankrunConnection.d.ts +75 -0
- package/lib/browser/bankrun/bankrunConnection.js +332 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
- package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +89 -0
- package/lib/browser/blockhashSubscriber/index.d.ts +1 -0
- package/lib/browser/blockhashSubscriber/index.js +17 -0
- package/lib/browser/blockhashSubscriber/types.d.ts +7 -0
- package/lib/browser/blockhashSubscriber/types.js +2 -0
- package/lib/browser/clock/clockSubscriber.d.ts +31 -0
- package/lib/browser/clock/clockSubscriber.js +80 -0
- package/lib/browser/config.d.ts +60 -0
- package/lib/browser/config.js +130 -0
- package/lib/browser/constants/numericConstants.d.ts +71 -0
- package/lib/browser/constants/numericConstants.js +75 -0
- package/lib/browser/constants/perpMarkets.d.ts +19 -0
- package/lib/browser/constants/perpMarkets.js +997 -0
- package/lib/browser/constants/spotMarkets.d.ts +24 -0
- package/lib/browser/constants/spotMarkets.js +470 -0
- package/lib/browser/constants/txConstants.d.ts +1 -0
- package/lib/browser/constants/txConstants.js +4 -0
- package/lib/browser/decode/phoenix.d.ts +7 -0
- package/lib/browser/decode/phoenix.js +159 -0
- package/lib/browser/decode/user.d.ts +4 -0
- package/lib/browser/decode/user.js +339 -0
- package/lib/browser/dlob/DLOB.d.ts +186 -0
- package/lib/browser/dlob/DLOB.js +1039 -0
- package/lib/browser/dlob/DLOBNode.d.ts +68 -0
- package/lib/browser/dlob/DLOBNode.js +100 -0
- package/lib/browser/dlob/DLOBSubscriber.d.ts +54 -0
- package/lib/browser/dlob/DLOBSubscriber.js +139 -0
- package/lib/browser/dlob/NodeList.d.ts +25 -0
- package/lib/browser/dlob/NodeList.js +126 -0
- package/lib/browser/dlob/orderBookLevels.d.ts +72 -0
- package/lib/browser/dlob/orderBookLevels.js +438 -0
- package/lib/browser/dlob/types.d.ts +18 -0
- package/lib/browser/dlob/types.js +2 -0
- package/lib/browser/driftClient.d.ts +861 -0
- package/lib/browser/driftClient.js +4768 -0
- package/lib/browser/driftClientConfig.d.ts +49 -0
- package/lib/browser/driftClientConfig.js +2 -0
- package/lib/browser/events/eventList.d.ts +22 -0
- package/lib/browser/events/eventList.js +80 -0
- package/lib/browser/events/eventSubscriber.d.ts +46 -0
- package/lib/browser/events/eventSubscriber.js +223 -0
- package/lib/browser/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/browser/events/eventsServerLogProvider.js +121 -0
- package/lib/browser/events/fetchLogs.d.ts +25 -0
- package/lib/browser/events/fetchLogs.js +99 -0
- package/lib/browser/events/parse.d.ts +6 -0
- package/lib/browser/events/parse.js +106 -0
- package/lib/browser/events/pollingLogProvider.d.ts +17 -0
- package/lib/browser/events/pollingLogProvider.js +58 -0
- package/lib/browser/events/sort.d.ts +2 -0
- package/lib/browser/events/sort.js +24 -0
- package/lib/browser/events/txEventCache.d.ts +24 -0
- package/lib/browser/events/txEventCache.js +71 -0
- package/lib/browser/events/types.d.ts +79 -0
- package/lib/browser/events/types.js +32 -0
- package/lib/browser/events/webSocketLogProvider.d.ts +24 -0
- package/lib/browser/events/webSocketLogProvider.js +96 -0
- package/lib/browser/factory/bigNum.d.ts +122 -0
- package/lib/browser/factory/bigNum.js +457 -0
- package/lib/browser/factory/oracleClient.d.ts +5 -0
- package/lib/browser/factory/oracleClient.js +56 -0
- package/lib/browser/idl/drift.json +14440 -0
- package/lib/browser/idl/openbook.json +3854 -0
- package/lib/browser/idl/pyth_solana_receiver.json +628 -0
- package/lib/browser/idl/switchboard.json +8354 -0
- package/lib/browser/idl/switchboard_on_demand_30.json +4546 -0
- package/lib/browser/idl/token_faucet.json +142 -0
- package/lib/browser/index.d.ts +125 -0
- package/lib/browser/index.js +147 -0
- package/lib/browser/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.browser.js +8 -0
- package/lib/browser/isomorphic/grpc.d.ts +1 -0
- package/lib/browser/isomorphic/grpc.js +8 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +302 -0
- package/lib/browser/jupiter/jupiterClient.js +178 -0
- package/lib/browser/keypair.d.ts +2 -0
- package/lib/browser/keypair.js +28 -0
- package/lib/browser/marinade/index.d.ts +12 -0
- package/lib/browser/marinade/index.js +36 -0
- package/lib/browser/marinade/types.d.ts +1963 -0
- package/lib/browser/marinade/types.js +1965 -0
- package/lib/browser/math/amm.d.ts +98 -0
- package/lib/browser/math/amm.js +626 -0
- package/lib/browser/math/auction.d.ts +23 -0
- package/lib/browser/math/auction.js +130 -0
- package/lib/browser/math/bankruptcy.d.ts +2 -0
- package/lib/browser/math/bankruptcy.js +31 -0
- package/lib/browser/math/conversion.d.ts +2 -0
- package/lib/browser/math/conversion.js +11 -0
- package/lib/browser/math/exchangeStatus.d.ts +6 -0
- package/lib/browser/math/exchangeStatus.js +77 -0
- package/lib/browser/math/fuel.d.ts +6 -0
- package/lib/browser/math/fuel.js +55 -0
- package/lib/browser/math/funding.d.ts +34 -0
- package/lib/browser/math/funding.js +209 -0
- package/lib/browser/math/insurance.d.ts +7 -0
- package/lib/browser/math/insurance.js +73 -0
- package/lib/browser/math/margin.d.ts +39 -0
- package/lib/browser/math/margin.js +184 -0
- package/lib/browser/math/market.d.ts +39 -0
- package/lib/browser/math/market.js +163 -0
- package/lib/browser/math/oracles.d.ts +14 -0
- package/lib/browser/math/oracles.js +134 -0
- package/lib/browser/math/orders.d.ts +23 -0
- package/lib/browser/math/orders.js +216 -0
- package/lib/browser/math/position.d.ts +70 -0
- package/lib/browser/math/position.js +225 -0
- package/lib/browser/math/repeg.d.ts +22 -0
- package/lib/browser/math/repeg.js +164 -0
- package/lib/browser/math/spotBalance.d.ts +83 -0
- package/lib/browser/math/spotBalance.js +373 -0
- package/lib/browser/math/spotMarket.d.ts +11 -0
- package/lib/browser/math/spotMarket.js +49 -0
- package/lib/browser/math/spotPosition.d.ts +19 -0
- package/lib/browser/math/spotPosition.js +78 -0
- package/lib/browser/math/state.d.ts +5 -0
- package/lib/browser/math/state.js +30 -0
- package/lib/browser/math/superStake.d.ts +167 -0
- package/lib/browser/math/superStake.js +306 -0
- package/lib/browser/math/tiers.d.ts +4 -0
- package/lib/browser/math/tiers.js +52 -0
- package/lib/browser/math/trade.d.ts +117 -0
- package/lib/browser/math/trade.js +637 -0
- package/lib/browser/math/userStatus.d.ts +2 -0
- package/lib/browser/math/userStatus.js +8 -0
- package/lib/browser/math/utils.d.ts +23 -0
- package/lib/browser/math/utils.js +112 -0
- package/lib/browser/memcmp.d.ts +11 -0
- package/lib/browser/memcmp.js +99 -0
- package/lib/browser/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/browser/openbook/openbookV2Subscriber.js +104 -0
- package/lib/browser/oracles/oracleClientCache.d.ts +9 -0
- package/lib/browser/oracles/oracleClientCache.js +19 -0
- package/lib/browser/oracles/oracleId.d.ts +4 -0
- package/lib/browser/oracles/oracleId.js +38 -0
- package/lib/browser/oracles/prelaunchOracleClient.d.ts +12 -0
- package/lib/browser/oracles/prelaunchOracleClient.js +24 -0
- package/lib/browser/oracles/pythClient.d.ts +14 -0
- package/lib/browser/oracles/pythClient.js +51 -0
- package/lib/browser/oracles/pythLazerClient.d.ts +16 -0
- package/lib/browser/oracles/pythLazerClient.js +61 -0
- package/lib/browser/oracles/pythPullClient.d.ts +19 -0
- package/lib/browser/oracles/pythPullClient.js +60 -0
- package/lib/browser/oracles/quoteAssetOracleClient.d.ts +10 -0
- package/lib/browser/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/browser/oracles/strictOraclePrice.d.ts +9 -0
- package/lib/browser/oracles/strictOraclePrice.js +17 -0
- package/lib/browser/oracles/switchboardClient.d.ts +12 -0
- package/lib/browser/oracles/switchboardClient.js +40 -0
- package/lib/browser/oracles/switchboardOnDemandClient.d.ts +12 -0
- package/lib/browser/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/browser/oracles/types.d.ts +23 -0
- package/lib/browser/oracles/types.js +2 -0
- package/lib/browser/orderParams.d.ts +29 -0
- package/lib/browser/orderParams.js +44 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +42 -0
- package/lib/browser/orderSubscriber/OrderSubscriber.js +172 -0
- package/lib/browser/orderSubscriber/PollingSubscription.d.ts +12 -0
- package/lib/browser/orderSubscriber/PollingSubscription.js +23 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.d.ts +23 -0
- package/lib/browser/orderSubscriber/WebsocketSubscription.js +67 -0
- package/lib/browser/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/browser/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/browser/orderSubscriber/index.d.ts +2 -0
- package/lib/browser/orderSubscriber/index.js +18 -0
- package/lib/browser/orderSubscriber/types.d.ts +34 -0
- package/lib/browser/orderSubscriber/types.js +2 -0
- package/lib/browser/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/browser/phoenix/phoenixSubscriber.d.ts +41 -0
- package/lib/browser/phoenix/phoenixSubscriber.js +152 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/averageOverSlotsStrategy.js +16 -0
- package/lib/browser/priorityFee/averageStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/averageStrategy.js +11 -0
- package/lib/browser/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
- package/lib/browser/priorityFee/driftPriorityFeeMethod.js +26 -0
- package/lib/browser/priorityFee/ewmaStrategy.d.ts +11 -0
- package/lib/browser/priorityFee/ewmaStrategy.js +33 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
- package/lib/browser/priorityFee/heliusPriorityFeeMethod.js +46 -0
- package/lib/browser/priorityFee/index.d.ts +11 -0
- package/lib/browser/priorityFee/index.js +27 -0
- package/lib/browser/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
- package/lib/browser/priorityFee/maxOverSlotsStrategy.js +17 -0
- package/lib/browser/priorityFee/maxStrategy.d.ts +7 -0
- package/lib/browser/priorityFee/maxStrategy.js +9 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +46 -0
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +188 -0
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
- package/lib/browser/priorityFee/solanaPriorityFeeMethod.js +21 -0
- package/lib/browser/priorityFee/types.d.ts +31 -0
- package/lib/browser/priorityFee/types.js +10 -0
- package/lib/browser/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/browser/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/browser/serum/serumSubscriber.d.ts +32 -0
- package/lib/browser/serum/serumSubscriber.js +107 -0
- package/lib/browser/serum/types.d.ts +13 -0
- package/lib/browser/serum/types.js +2 -0
- package/lib/browser/slot/SlotSubscriber.d.ts +27 -0
- package/lib/browser/slot/SlotSubscriber.js +71 -0
- package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/browser/slot/SlothashSubscriber.js +85 -0
- package/lib/browser/testClient.d.ts +8 -0
- package/lib/browser/testClient.js +23 -0
- package/lib/browser/token/index.d.ts +5 -0
- package/lib/browser/token/index.js +15 -0
- package/lib/browser/tokenFaucet.d.ts +41 -0
- package/lib/browser/tokenFaucet.js +188 -0
- package/lib/browser/tx/baseTxSender.d.ts +59 -0
- package/lib/browser/tx/baseTxSender.js +294 -0
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
- package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
- package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
- package/lib/browser/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/browser/tx/blockhashFetcher/types.js +2 -0
- package/lib/browser/tx/fastSingleTxSender.d.ts +41 -0
- package/lib/browser/tx/fastSingleTxSender.js +86 -0
- package/lib/browser/tx/forwardOnlyTxSender.d.ts +37 -0
- package/lib/browser/tx/forwardOnlyTxSender.js +92 -0
- package/lib/browser/tx/priorityFeeCalculator.d.ts +44 -0
- package/lib/browser/tx/priorityFeeCalculator.js +85 -0
- package/lib/browser/tx/reportTransactionError.d.ts +20 -0
- package/lib/browser/tx/reportTransactionError.js +103 -0
- package/lib/browser/tx/retryTxSender.d.ts +37 -0
- package/lib/browser/tx/retryTxSender.js +86 -0
- package/lib/browser/tx/txHandler.d.ts +154 -0
- package/lib/browser/tx/txHandler.js +453 -0
- package/lib/browser/tx/txParamProcessor.d.ts +25 -0
- package/lib/browser/tx/txParamProcessor.js +88 -0
- package/lib/browser/tx/types.d.ts +29 -0
- package/lib/browser/tx/types.js +20 -0
- package/lib/browser/tx/utils.d.ts +2 -0
- package/lib/browser/tx/utils.js +10 -0
- package/lib/browser/tx/whileValidTxSender.d.ts +45 -0
- package/lib/browser/tx/whileValidTxSender.js +167 -0
- package/lib/browser/types.d.ts +1385 -0
- package/lib/browser/types.js +366 -0
- package/lib/browser/user.d.ts +411 -0
- package/lib/browser/user.js +2151 -0
- package/lib/browser/userConfig.d.ts +26 -0
- package/lib/browser/userConfig.js +2 -0
- package/lib/browser/userMap/PollingSubscription.d.ts +16 -0
- package/lib/browser/userMap/PollingSubscription.js +30 -0
- package/lib/browser/userMap/WebsocketSubscription.d.ts +27 -0
- package/lib/browser/userMap/WebsocketSubscription.js +45 -0
- package/lib/browser/userMap/grpcSubscription.d.ts +27 -0
- package/lib/browser/userMap/grpcSubscription.js +44 -0
- package/lib/browser/userMap/referrerMap.d.ts +45 -0
- package/lib/browser/userMap/referrerMap.js +181 -0
- package/lib/browser/userMap/userMap.d.ts +90 -0
- package/lib/browser/userMap/userMap.js +467 -0
- package/lib/browser/userMap/userMapConfig.d.ts +39 -0
- package/lib/browser/userMap/userMapConfig.js +2 -0
- package/lib/browser/userMap/userStatsMap.d.ts +46 -0
- package/lib/browser/userMap/userStatsMap.js +165 -0
- package/lib/browser/userName.d.ts +5 -0
- package/lib/browser/userName.js +21 -0
- package/lib/browser/userStats.d.ts +22 -0
- package/lib/browser/userStats.js +91 -0
- package/lib/browser/userStatsConfig.d.ts +25 -0
- package/lib/browser/userStatsConfig.js +2 -0
- package/lib/browser/util/TransactionConfirmationManager.d.ts +16 -0
- package/lib/browser/util/TransactionConfirmationManager.js +174 -0
- package/lib/browser/util/chainClock.d.ts +17 -0
- package/lib/browser/util/chainClock.js +29 -0
- package/lib/browser/util/computeUnits.d.ts +8 -0
- package/lib/browser/util/computeUnits.js +48 -0
- package/lib/browser/util/digest.d.ts +4 -0
- package/lib/browser/util/digest.js +14 -0
- package/lib/browser/util/promiseTimeout.d.ts +1 -0
- package/lib/browser/util/promiseTimeout.js +14 -0
- package/lib/browser/util/pythOracleUtils.d.ts +17 -0
- package/lib/browser/util/pythOracleUtils.js +107 -0
- package/lib/browser/util/tps.d.ts +2 -0
- package/lib/browser/util/tps.js +16 -0
- package/lib/browser/wallet.d.ts +11 -0
- package/lib/browser/wallet.js +32 -0
- package/lib/node/accounts/basicUserAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/basicUserAccountSubscriber.js +38 -0
- package/lib/node/accounts/bulkAccountLoader.d.ts +37 -0
- package/lib/node/accounts/bulkAccountLoader.js +222 -0
- package/lib/node/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/node/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/node/accounts/bulkUserSubscription.js +21 -0
- package/lib/node/accounts/fetch.d.ts +6 -0
- package/lib/node/accounts/fetch.js +30 -0
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +16 -0
- package/lib/node/accounts/grpcAccountSubscriber.js +154 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +98 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/grpcProgramAccountSubscriber.js +171 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserAccountSubscriber.js +28 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
- package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +28 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
- package/lib/node/accounts/oneShotUserAccountSubscriber.js +48 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +418 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingOracleAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/node/accounts/pollingTokenAccountSubscriber.js +78 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingUserAccountSubscriber.js +102 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +94 -0
- package/lib/node/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/node/accounts/testBulkAccountLoader.js +45 -0
- package/lib/node/accounts/types.d.ts +168 -0
- package/lib/node/accounts/types.js +16 -0
- package/lib/node/accounts/utils.d.ts +8 -0
- package/lib/node/accounts/utils.js +49 -0
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/webSocketAccountSubscriber.js +149 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriber.js +120 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketUserAccountSubscriber.js +61 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
- package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
- package/lib/node/addresses/marketAddresses.d.ts +2 -0
- package/lib/node/addresses/marketAddresses.js +15 -0
- package/lib/node/addresses/pda.d.ts +32 -0
- package/lib/node/addresses/pda.js +211 -0
- package/lib/node/adminClient.d.ts +206 -0
- package/lib/node/adminClient.js +1858 -0
- package/lib/node/assert/assert.d.ts +1 -0
- package/lib/node/assert/assert.js +9 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +14 -0
- package/lib/node/auctionSubscriber/auctionSubscriber.js +32 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
- package/lib/node/auctionSubscriber/index.d.ts +3 -0
- package/lib/node/auctionSubscriber/index.js +19 -0
- package/lib/node/auctionSubscriber/types.d.ts +14 -0
- package/lib/node/auctionSubscriber/types.js +2 -0
- package/lib/node/bankrun/bankrunConnection.d.ts +75 -0
- package/lib/node/bankrun/bankrunConnection.js +332 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
- package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +89 -0
- package/lib/node/blockhashSubscriber/index.d.ts +1 -0
- package/lib/node/blockhashSubscriber/index.js +17 -0
- package/lib/node/blockhashSubscriber/types.d.ts +7 -0
- package/lib/node/blockhashSubscriber/types.js +2 -0
- package/lib/node/clock/clockSubscriber.d.ts +31 -0
- package/lib/node/clock/clockSubscriber.js +80 -0
- package/lib/node/config.d.ts +60 -0
- package/lib/node/config.js +130 -0
- package/lib/node/constants/numericConstants.d.ts +71 -0
- package/lib/node/constants/numericConstants.js +75 -0
- package/lib/node/constants/perpMarkets.d.ts +19 -0
- package/lib/node/constants/perpMarkets.js +997 -0
- package/lib/node/constants/spotMarkets.d.ts +24 -0
- package/lib/node/constants/spotMarkets.js +470 -0
- package/lib/node/constants/txConstants.d.ts +1 -0
- package/lib/node/constants/txConstants.js +4 -0
- package/lib/node/decode/phoenix.d.ts +7 -0
- package/lib/node/decode/phoenix.js +159 -0
- package/lib/node/decode/user.d.ts +4 -0
- package/lib/node/decode/user.js +339 -0
- package/lib/node/dlob/DLOB.d.ts +186 -0
- package/lib/node/dlob/DLOB.js +1039 -0
- package/lib/node/dlob/DLOBNode.d.ts +68 -0
- package/lib/node/dlob/DLOBNode.js +100 -0
- package/lib/node/dlob/DLOBSubscriber.d.ts +54 -0
- package/lib/node/dlob/DLOBSubscriber.js +139 -0
- package/lib/node/dlob/NodeList.d.ts +25 -0
- package/lib/node/dlob/NodeList.js +126 -0
- package/lib/node/dlob/orderBookLevels.d.ts +72 -0
- package/lib/node/dlob/orderBookLevels.js +438 -0
- package/lib/node/dlob/types.d.ts +18 -0
- package/lib/node/dlob/types.js +2 -0
- package/lib/node/driftClient.d.ts +861 -0
- package/lib/node/driftClient.js +4768 -0
- package/lib/node/driftClientConfig.d.ts +49 -0
- package/lib/node/driftClientConfig.js +2 -0
- package/lib/node/events/eventList.d.ts +22 -0
- package/lib/node/events/eventList.js +80 -0
- package/lib/node/events/eventSubscriber.d.ts +46 -0
- package/lib/node/events/eventSubscriber.js +223 -0
- package/lib/node/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/node/events/eventsServerLogProvider.js +121 -0
- package/lib/node/events/fetchLogs.d.ts +25 -0
- package/lib/node/events/fetchLogs.js +99 -0
- package/lib/node/events/parse.d.ts +6 -0
- package/lib/node/events/parse.js +106 -0
- package/lib/node/events/pollingLogProvider.d.ts +17 -0
- package/lib/node/events/pollingLogProvider.js +58 -0
- package/lib/node/events/sort.d.ts +2 -0
- package/lib/node/events/sort.js +24 -0
- package/lib/node/events/txEventCache.d.ts +24 -0
- package/lib/node/events/txEventCache.js +71 -0
- package/lib/node/events/types.d.ts +79 -0
- package/lib/node/events/types.js +32 -0
- package/lib/node/events/webSocketLogProvider.d.ts +24 -0
- package/lib/node/events/webSocketLogProvider.js +96 -0
- package/lib/node/factory/bigNum.d.ts +122 -0
- package/lib/node/factory/bigNum.js +457 -0
- package/lib/node/factory/oracleClient.d.ts +5 -0
- package/lib/node/factory/oracleClient.js +56 -0
- package/lib/node/idl/drift.json +14440 -0
- package/lib/node/idl/openbook.json +3854 -0
- package/lib/node/idl/pyth_solana_receiver.json +628 -0
- package/lib/node/idl/switchboard.json +8354 -0
- package/lib/node/idl/switchboard_on_demand_30.json +4546 -0
- package/lib/node/idl/token_faucet.json +142 -0
- package/lib/node/index.d.ts +125 -0
- package/lib/node/index.js +147 -0
- package/lib/node/isomorphic/grpc.browser.d.ts +1 -0
- package/lib/node/isomorphic/grpc.browser.js +8 -0
- package/lib/node/isomorphic/grpc.d.ts +1 -0
- package/lib/node/isomorphic/grpc.js +8 -0
- package/lib/node/jupiter/jupiterClient.d.ts +302 -0
- package/lib/node/jupiter/jupiterClient.js +178 -0
- package/lib/node/keypair.d.ts +2 -0
- package/lib/node/keypair.js +28 -0
- package/lib/node/marinade/index.d.ts +12 -0
- package/lib/node/marinade/index.js +36 -0
- package/lib/node/marinade/types.d.ts +1963 -0
- package/lib/node/marinade/types.js +1965 -0
- package/lib/node/math/amm.d.ts +98 -0
- package/lib/node/math/amm.js +626 -0
- package/lib/node/math/auction.d.ts +23 -0
- package/lib/node/math/auction.js +130 -0
- package/lib/node/math/bankruptcy.d.ts +2 -0
- package/lib/node/math/bankruptcy.js +31 -0
- package/lib/node/math/conversion.d.ts +2 -0
- package/lib/node/math/conversion.js +11 -0
- package/lib/node/math/exchangeStatus.d.ts +6 -0
- package/lib/node/math/exchangeStatus.js +77 -0
- package/lib/node/math/fuel.d.ts +6 -0
- package/lib/node/math/fuel.js +55 -0
- package/lib/node/math/funding.d.ts +34 -0
- package/lib/node/math/funding.js +209 -0
- package/lib/node/math/insurance.d.ts +7 -0
- package/lib/node/math/insurance.js +73 -0
- package/lib/node/math/margin.d.ts +39 -0
- package/lib/node/math/margin.js +184 -0
- package/lib/node/math/market.d.ts +39 -0
- package/lib/node/math/market.js +163 -0
- package/lib/node/math/oracles.d.ts +14 -0
- package/lib/node/math/oracles.js +134 -0
- package/lib/node/math/orders.d.ts +23 -0
- package/lib/node/math/orders.js +216 -0
- package/lib/node/math/position.d.ts +70 -0
- package/lib/node/math/position.js +225 -0
- package/lib/node/math/repeg.d.ts +22 -0
- package/lib/node/math/repeg.js +164 -0
- package/lib/node/math/spotBalance.d.ts +83 -0
- package/lib/node/math/spotBalance.js +373 -0
- package/lib/node/math/spotMarket.d.ts +11 -0
- package/lib/node/math/spotMarket.js +49 -0
- package/lib/node/math/spotPosition.d.ts +19 -0
- package/lib/node/math/spotPosition.js +78 -0
- package/lib/node/math/state.d.ts +5 -0
- package/lib/node/math/state.js +30 -0
- package/lib/node/math/superStake.d.ts +167 -0
- package/lib/node/math/superStake.js +306 -0
- package/lib/node/math/tiers.d.ts +4 -0
- package/lib/node/math/tiers.js +52 -0
- package/lib/node/math/trade.d.ts +117 -0
- package/lib/node/math/trade.js +637 -0
- package/lib/node/math/userStatus.d.ts +2 -0
- package/lib/node/math/userStatus.js +8 -0
- package/lib/node/math/utils.d.ts +23 -0
- package/lib/node/math/utils.js +112 -0
- package/lib/node/memcmp.d.ts +11 -0
- package/lib/node/memcmp.js +99 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/node/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/node/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/node/openbook/openbookV2Subscriber.js +104 -0
- package/lib/node/oracles/oracleClientCache.d.ts +9 -0
- package/lib/node/oracles/oracleClientCache.js +19 -0
- package/lib/node/oracles/oracleId.d.ts +4 -0
- package/lib/node/oracles/oracleId.js +38 -0
- package/lib/node/oracles/prelaunchOracleClient.d.ts +12 -0
- package/lib/node/oracles/prelaunchOracleClient.js +24 -0
- package/lib/node/oracles/pythClient.d.ts +14 -0
- package/lib/node/oracles/pythClient.js +51 -0
- package/lib/node/oracles/pythLazerClient.d.ts +16 -0
- package/lib/node/oracles/pythLazerClient.js +61 -0
- package/lib/node/oracles/pythPullClient.d.ts +19 -0
- package/lib/node/oracles/pythPullClient.js +60 -0
- package/lib/node/oracles/quoteAssetOracleClient.d.ts +10 -0
- package/lib/node/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/node/oracles/strictOraclePrice.d.ts +9 -0
- package/lib/node/oracles/strictOraclePrice.js +17 -0
- package/lib/node/oracles/switchboardClient.d.ts +12 -0
- package/lib/node/oracles/switchboardClient.js +40 -0
- package/lib/node/oracles/switchboardOnDemandClient.d.ts +12 -0
- package/lib/node/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/node/oracles/types.d.ts +23 -0
- package/lib/node/oracles/types.js +2 -0
- package/lib/node/orderParams.d.ts +29 -0
- package/lib/node/orderParams.js +44 -0
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +42 -0
- package/lib/node/orderSubscriber/OrderSubscriber.js +172 -0
- package/lib/node/orderSubscriber/PollingSubscription.d.ts +12 -0
- package/lib/node/orderSubscriber/PollingSubscription.js +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +23 -0
- package/lib/node/orderSubscriber/WebsocketSubscription.js +67 -0
- package/lib/node/orderSubscriber/grpcSubscription.d.ts +22 -0
- package/lib/node/orderSubscriber/grpcSubscription.js +66 -0
- package/lib/node/orderSubscriber/index.d.ts +2 -0
- package/lib/node/orderSubscriber/index.js +18 -0
- package/lib/node/orderSubscriber/types.d.ts +34 -0
- package/lib/node/orderSubscriber/types.js +2 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/node/phoenix/phoenixSubscriber.d.ts +41 -0
- package/lib/node/phoenix/phoenixSubscriber.js +152 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageOverSlotsStrategy.js +16 -0
- package/lib/node/priorityFee/averageStrategy.d.ts +5 -0
- package/lib/node/priorityFee/averageStrategy.js +11 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
- package/lib/node/priorityFee/driftPriorityFeeMethod.js +26 -0
- package/lib/node/priorityFee/ewmaStrategy.d.ts +11 -0
- package/lib/node/priorityFee/ewmaStrategy.js +33 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
- package/lib/node/priorityFee/heliusPriorityFeeMethod.js +46 -0
- package/lib/node/priorityFee/index.d.ts +11 -0
- package/lib/node/priorityFee/index.js +27 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
- package/lib/node/priorityFee/maxOverSlotsStrategy.js +17 -0
- package/lib/node/priorityFee/maxStrategy.d.ts +7 -0
- package/lib/node/priorityFee/maxStrategy.js +9 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +46 -0
- package/lib/node/priorityFee/priorityFeeSubscriber.js +188 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
- package/lib/node/priorityFee/solanaPriorityFeeMethod.js +21 -0
- package/lib/node/priorityFee/types.d.ts +31 -0
- package/lib/node/priorityFee/types.js +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/node/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/node/serum/serumSubscriber.d.ts +32 -0
- package/lib/node/serum/serumSubscriber.js +107 -0
- package/lib/node/serum/types.d.ts +13 -0
- package/lib/node/serum/types.js +2 -0
- package/lib/node/slot/SlotSubscriber.d.ts +27 -0
- package/lib/node/slot/SlotSubscriber.js +71 -0
- package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/node/slot/SlothashSubscriber.js +85 -0
- package/lib/node/testClient.d.ts +8 -0
- package/lib/node/testClient.js +23 -0
- package/lib/node/token/index.d.ts +5 -0
- package/lib/node/token/index.js +15 -0
- package/lib/node/tokenFaucet.d.ts +41 -0
- package/lib/node/tokenFaucet.js +188 -0
- package/lib/node/tx/baseTxSender.d.ts +59 -0
- package/lib/node/tx/baseTxSender.js +294 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
- package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
- package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
- package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
- package/lib/node/tx/blockhashFetcher/types.js +2 -0
- package/lib/node/tx/fastSingleTxSender.d.ts +41 -0
- package/lib/node/tx/fastSingleTxSender.js +86 -0
- package/lib/node/tx/forwardOnlyTxSender.d.ts +37 -0
- package/lib/node/tx/forwardOnlyTxSender.js +92 -0
- package/lib/node/tx/priorityFeeCalculator.d.ts +44 -0
- package/lib/node/tx/priorityFeeCalculator.js +85 -0
- package/lib/node/tx/reportTransactionError.d.ts +20 -0
- package/lib/node/tx/reportTransactionError.js +103 -0
- package/lib/node/tx/retryTxSender.d.ts +37 -0
- package/lib/node/tx/retryTxSender.js +86 -0
- package/lib/node/tx/txHandler.d.ts +154 -0
- package/lib/node/tx/txHandler.js +453 -0
- package/lib/node/tx/txParamProcessor.d.ts +25 -0
- package/lib/node/tx/txParamProcessor.js +88 -0
- package/lib/node/tx/types.d.ts +29 -0
- package/lib/node/tx/types.js +20 -0
- package/lib/node/tx/utils.d.ts +2 -0
- package/lib/node/tx/utils.js +10 -0
- package/lib/node/tx/whileValidTxSender.d.ts +45 -0
- package/lib/node/tx/whileValidTxSender.js +167 -0
- package/lib/node/types.d.ts +1385 -0
- package/lib/node/types.js +366 -0
- package/lib/node/user.d.ts +411 -0
- package/lib/node/user.js +2151 -0
- package/lib/node/userConfig.d.ts +26 -0
- package/lib/node/userConfig.js +2 -0
- package/lib/node/userMap/PollingSubscription.d.ts +16 -0
- package/lib/node/userMap/PollingSubscription.js +30 -0
- package/lib/node/userMap/WebsocketSubscription.d.ts +27 -0
- package/lib/node/userMap/WebsocketSubscription.js +45 -0
- package/lib/node/userMap/grpcSubscription.d.ts +27 -0
- package/lib/node/userMap/grpcSubscription.js +44 -0
- package/lib/node/userMap/referrerMap.d.ts +45 -0
- package/lib/node/userMap/referrerMap.js +181 -0
- package/lib/node/userMap/userMap.d.ts +90 -0
- package/lib/node/userMap/userMap.js +467 -0
- package/lib/node/userMap/userMapConfig.d.ts +39 -0
- package/lib/node/userMap/userMapConfig.js +2 -0
- package/lib/node/userMap/userStatsMap.d.ts +46 -0
- package/lib/node/userMap/userStatsMap.js +165 -0
- package/lib/node/userName.d.ts +5 -0
- package/lib/node/userName.js +21 -0
- package/lib/node/userStats.d.ts +22 -0
- package/lib/node/userStats.js +91 -0
- package/lib/node/userStatsConfig.d.ts +25 -0
- package/lib/node/userStatsConfig.js +2 -0
- package/lib/node/util/TransactionConfirmationManager.d.ts +16 -0
- package/lib/node/util/TransactionConfirmationManager.js +174 -0
- package/lib/node/util/chainClock.d.ts +17 -0
- package/lib/node/util/chainClock.js +29 -0
- package/lib/node/util/computeUnits.d.ts +8 -0
- package/lib/node/util/computeUnits.js +48 -0
- package/lib/node/util/digest.d.ts +4 -0
- package/lib/node/util/digest.js +14 -0
- package/lib/node/util/promiseTimeout.d.ts +1 -0
- package/lib/node/util/promiseTimeout.js +14 -0
- package/lib/node/util/pythOracleUtils.d.ts +17 -0
- package/lib/node/util/pythOracleUtils.js +107 -0
- package/lib/node/util/tps.d.ts +2 -0
- package/lib/node/util/tps.js +16 -0
- package/lib/node/wallet.d.ts +11 -0
- package/lib/node/wallet.js +32 -0
- package/package.json +92 -0
- package/scripts/postbuild.js +95 -0
- package/scripts/updateVersion.js +28 -0
- package/src/accounts/basicUserAccountSubscriber.ts +59 -0
- package/src/accounts/bulkAccountLoader.ts +294 -0
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +33 -0
- package/src/accounts/fetch.ts +66 -0
- package/src/accounts/grpcAccountSubscriber.ts +160 -0
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +203 -0
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +56 -0
- package/src/accounts/grpcProgramAccountSubscriber.ts +190 -0
- package/src/accounts/grpcUserAccountSubscriber.ts +48 -0
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +50 -0
- package/src/accounts/oneShotUserAccountSubscriber.ts +68 -0
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +644 -0
- package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +185 -0
- package/src/accounts/pollingOracleAccountSubscriber.ts +125 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +118 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +160 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +156 -0
- package/src/accounts/testBulkAccountLoader.ts +53 -0
- package/src/accounts/types.ts +245 -0
- package/src/accounts/utils.ts +62 -0
- package/src/accounts/webSocketAccountSubscriber.ts +205 -0
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +621 -0
- package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +129 -0
- package/src/accounts/webSocketProgramAccountSubscriber.ts +182 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +104 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +98 -0
- package/src/addresses/marketAddresses.ts +17 -0
- package/src/addresses/pda.ts +355 -0
- package/src/adminClient.ts +4030 -0
- package/src/assert/assert.ts +5 -0
- package/src/auctionSubscriber/auctionSubscriber.ts +66 -0
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +70 -0
- package/src/auctionSubscriber/index.ts +3 -0
- package/src/auctionSubscriber/types.ts +20 -0
- package/src/bankrun/bankrunConnection.ts +534 -0
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +126 -0
- package/src/blockhashSubscriber/index.ts +1 -0
- package/src/blockhashSubscriber/types.ts +12 -0
- package/src/clock/clockSubscriber.ts +121 -0
- package/src/config.ts +212 -0
- package/src/constants/numericConstants.ts +113 -0
- package/src/constants/perpMarkets.ts +1084 -0
- package/src/constants/spotMarkets.ts +565 -0
- package/src/constants/txConstants.ts +1 -0
- package/src/decode/phoenix.ts +207 -0
- package/src/decode/user.ts +368 -0
- package/src/dlob/DLOB.ts +1897 -0
- package/src/dlob/DLOBNode.ts +197 -0
- package/src/dlob/DLOBSubscriber.ts +201 -0
- package/src/dlob/NodeList.ts +173 -0
- package/src/dlob/orderBookLevels.ts +643 -0
- package/src/dlob/types.ts +22 -0
- package/src/driftClient.ts +9032 -0
- package/src/driftClientConfig.ts +60 -0
- package/src/events/eventList.ts +97 -0
- package/src/events/eventSubscriber.ts +364 -0
- package/src/events/eventsServerLogProvider.ts +152 -0
- package/src/events/fetchLogs.ts +169 -0
- package/src/events/parse.ts +133 -0
- package/src/events/pollingLogProvider.ts +89 -0
- package/src/events/sort.ts +39 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.ts +185 -0
- package/src/events/webSocketLogProvider.ts +121 -0
- package/src/factory/bigNum.ts +660 -0
- package/src/factory/oracleClient.ts +72 -0
- package/src/idl/drift.json +14440 -0
- package/src/idl/openbook.json +3854 -0
- package/src/idl/pyth.json +142 -0
- package/src/idl/pyth_solana_receiver.json +628 -0
- package/src/idl/switchboard.json +8354 -0
- package/src/idl/switchboard_on_demand_30.json +4546 -0
- package/src/idl/token_faucet.json +142 -0
- package/src/index.ts +127 -0
- package/src/isomorphic/README.md +19 -0
- package/src/isomorphic/grpc.browser.ts +4 -0
- package/src/isomorphic/grpc.node.ts +23 -0
- package/src/isomorphic/grpc.ts +1 -0
- package/src/jupiter/jupiterClient.ts +510 -0
- package/src/keypair.ts +24 -0
- package/src/marinade/idl/idl.json +1962 -0
- package/src/marinade/index.ts +64 -0
- package/src/marinade/types.ts +3925 -0
- package/src/math/amm.ts +1162 -0
- package/src/math/auction.ts +173 -0
- package/src/math/bankruptcy.ts +34 -0
- package/src/math/conversion.ts +13 -0
- package/src/math/exchangeStatus.ts +121 -0
- package/src/math/fuel.ts +70 -0
- package/src/math/funding.ts +342 -0
- package/src/math/insurance.ts +110 -0
- package/src/math/margin.ts +340 -0
- package/src/math/market.ts +336 -0
- package/src/math/oracles.ts +228 -0
- package/src/math/orders.ts +343 -0
- package/src/math/position.ts +324 -0
- package/src/math/repeg.ts +214 -0
- package/src/math/spotBalance.ts +630 -0
- package/src/math/spotMarket.ts +82 -0
- package/src/math/spotPosition.ts +184 -0
- package/src/math/state.ts +29 -0
- package/src/math/superStake.ts +525 -0
- package/src/math/tiers.ts +44 -0
- package/src/math/trade.ts +993 -0
- package/src/math/userStatus.ts +5 -0
- package/src/math/utils.ts +120 -0
- package/src/memcmp.ts +94 -0
- package/src/openbook/openbookV2FulfillmentConfigMap.ts +29 -0
- package/src/openbook/openbookV2Subscriber.ts +165 -0
- package/src/oracles/oracleClientCache.ts +25 -0
- package/src/oracles/oracleId.ts +28 -0
- package/src/oracles/prelaunchOracleClient.ts +37 -0
- package/src/oracles/pythClient.ts +85 -0
- package/src/oracles/pythLazerClient.ts +102 -0
- package/src/oracles/pythPullClient.ts +111 -0
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/strictOraclePrice.ts +19 -0
- package/src/oracles/switchboardClient.ts +77 -0
- package/src/oracles/switchboardOnDemandClient.ts +56 -0
- package/src/oracles/types.ts +23 -0
- package/src/orderParams.ts +79 -0
- package/src/orderSubscriber/OrderSubscriber.ts +249 -0
- package/src/orderSubscriber/PollingSubscription.ts +39 -0
- package/src/orderSubscriber/WebsocketSubscription.ts +119 -0
- package/src/orderSubscriber/grpcSubscription.ts +121 -0
- package/src/orderSubscriber/index.ts +2 -0
- package/src/orderSubscriber/types.ts +54 -0
- package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
- package/src/phoenix/phoenixSubscriber.ts +235 -0
- package/src/priorityFee/averageOverSlotsStrategy.ts +16 -0
- package/src/priorityFee/averageStrategy.ts +12 -0
- package/src/priorityFee/driftPriorityFeeMethod.ts +42 -0
- package/src/priorityFee/ewmaStrategy.ts +41 -0
- package/src/priorityFee/heliusPriorityFeeMethod.ts +57 -0
- package/src/priorityFee/index.ts +11 -0
- package/src/priorityFee/maxOverSlotsStrategy.ts +17 -0
- package/src/priorityFee/maxStrategy.ts +7 -0
- package/src/priorityFee/priorityFeeSubscriber.ts +251 -0
- package/src/priorityFee/priorityFeeSubscriberMap.ts +112 -0
- package/src/priorityFee/solanaPriorityFeeMethod.ts +34 -0
- package/src/priorityFee/types.ts +60 -0
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +169 -0
- package/src/serum/types.ts +17 -0
- package/src/slot/SlotSubscriber.ts +101 -0
- package/src/slot/SlothashSubscriber.ts +126 -0
- package/src/testClient.ts +41 -0
- package/src/token/index.ts +13 -0
- package/src/tokenFaucet.ts +269 -0
- package/src/tx/baseTxSender.ts +477 -0
- package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +19 -0
- package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +90 -0
- package/src/tx/blockhashFetcher/types.ts +5 -0
- package/src/tx/fastSingleTxSender.ts +142 -0
- package/src/tx/forwardOnlyTxSender.ts +145 -0
- package/src/tx/priorityFeeCalculator.ts +117 -0
- package/src/tx/reportTransactionError.ts +159 -0
- package/src/tx/retryTxSender.ts +135 -0
- package/src/tx/txHandler.ts +737 -0
- package/src/tx/txParamProcessor.ts +155 -0
- package/src/tx/types.ts +71 -0
- package/src/tx/utils.ts +11 -0
- package/src/tx/whileValidTxSender.ts +265 -0
- package/src/types.ts +1386 -0
- package/src/user.ts +4054 -0
- package/src/userConfig.ts +32 -0
- package/src/userMap/PollingSubscription.ts +47 -0
- package/src/userMap/WebsocketSubscription.ts +84 -0
- package/src/userMap/grpcSubscription.ts +85 -0
- package/src/userMap/referrerMap.ts +267 -0
- package/src/userMap/userMap.ts +654 -0
- package/src/userMap/userMapConfig.ts +63 -0
- package/src/userMap/userStatsMap.ts +218 -0
- package/src/userName.ts +21 -0
- package/src/userStats.ts +174 -0
- package/src/userStatsConfig.ts +31 -0
- package/src/util/TransactionConfirmationManager.ts +292 -0
- package/src/util/chainClock.ts +41 -0
- package/src/util/computeUnits.ts +65 -0
- package/src/util/digest.ts +11 -0
- package/src/util/promiseTimeout.ts +14 -0
- package/src/util/pythOracleUtils.ts +136 -0
- package/src/util/tps.ts +27 -0
- package/src/wallet.ts +43 -0
- package/tests/amm/test.ts +2092 -0
- package/tests/auctions/test.ts +81 -0
- package/tests/bn/test.ts +341 -0
- package/tests/ci/idl.ts +101 -0
- package/tests/ci/verifyConstants.ts +278 -0
- package/tests/decode/phoenix.ts +71 -0
- package/tests/decode/test.ts +266 -0
- package/tests/decode/userAccountBufferStrings.ts +102 -0
- package/tests/dlob/helpers.ts +749 -0
- package/tests/dlob/test.ts +6623 -0
- package/tests/insurance/test.ts +40 -0
- package/tests/spot/test.ts +226 -0
- package/tests/subscriber/openbook.ts +62 -0
- package/tests/tx/TransactionConfirmationManager.test.ts +305 -0
- package/tests/tx/cachedBlockhashFetcher.test.ts +96 -0
- package/tests/tx/priorityFeeCalculator.ts +77 -0
- package/tests/tx/priorityFeeStrategy.ts +95 -0
- package/tests/user/helpers.ts +92 -0
- package/tests/user/test.ts +517 -0
- package/tsconfig.browser.json +13 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressLookupTableAccount,
|
|
3
|
+
BlockhashWithExpiryBlockHeight,
|
|
4
|
+
Commitment,
|
|
5
|
+
ComputeBudgetProgram,
|
|
6
|
+
ConfirmOptions,
|
|
7
|
+
Connection,
|
|
8
|
+
Message,
|
|
9
|
+
MessageV0,
|
|
10
|
+
Signer,
|
|
11
|
+
Transaction,
|
|
12
|
+
TransactionInstruction,
|
|
13
|
+
TransactionMessage,
|
|
14
|
+
TransactionVersion,
|
|
15
|
+
VersionedTransaction,
|
|
16
|
+
} from '@solana/web3.js';
|
|
17
|
+
import { TransactionParamProcessor } from './txParamProcessor';
|
|
18
|
+
import bs58 from 'bs58';
|
|
19
|
+
import {
|
|
20
|
+
BaseTxParams,
|
|
21
|
+
DriftClientMetricsEvents,
|
|
22
|
+
IWallet,
|
|
23
|
+
MappedRecord,
|
|
24
|
+
SignedTxData,
|
|
25
|
+
TxParams,
|
|
26
|
+
} from '../types';
|
|
27
|
+
import { containsComputeUnitIxs } from '../util/computeUnits';
|
|
28
|
+
import { CachedBlockhashFetcher } from './blockhashFetcher/cachedBlockhashFetcher';
|
|
29
|
+
import { BaseBlockhashFetcher } from './blockhashFetcher/baseBlockhashFetcher';
|
|
30
|
+
import { BlockhashFetcher } from './blockhashFetcher/types';
|
|
31
|
+
import { isVersionedTransaction } from './utils';
|
|
32
|
+
import { DEFAULT_CONFIRMATION_OPTS } from '../config';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Explanation for SIGNATURE_BLOCK_AND_EXPIRY:
|
|
36
|
+
*
|
|
37
|
+
* When the whileValidTxSender waits for confirmation of a given transaction, it needs the last available blockheight and blockhash used in the signature to do so. For pre-signed transactions, these values aren't attached to the transaction object by default. For a "scrappy" workaround which doesn't break backwards compatibility, the SIGNATURE_BLOCK_AND_EXPIRY property is simply attached to the transaction objects as they are created or signed in this handler despite a mismatch in the typescript types. If the values are attached to the transaction when they reach the whileValidTxSender, it can opt-in to use these values.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
const DEV_TRY_FORCE_TX_TIMEOUTS =
|
|
41
|
+
process.env.DEV_TRY_FORCE_TX_TIMEOUTS === 'true' || false;
|
|
42
|
+
|
|
43
|
+
export const COMPUTE_UNITS_DEFAULT = 200_000;
|
|
44
|
+
|
|
45
|
+
const BLOCKHASH_FETCH_RETRY_COUNT = 3;
|
|
46
|
+
const BLOCKHASH_FETCH_RETRY_SLEEP = 200;
|
|
47
|
+
const RECENT_BLOCKHASH_STALE_TIME_MS = 2_000; // Reuse blockhashes within this timeframe during bursts of tx contruction
|
|
48
|
+
|
|
49
|
+
export type TxBuildingProps = {
|
|
50
|
+
instructions: TransactionInstruction | TransactionInstruction[];
|
|
51
|
+
txVersion: TransactionVersion;
|
|
52
|
+
connection: Connection;
|
|
53
|
+
preFlightCommitment: Commitment;
|
|
54
|
+
fetchMarketLookupTableAccount: () => Promise<AddressLookupTableAccount>;
|
|
55
|
+
lookupTables?: AddressLookupTableAccount[];
|
|
56
|
+
forceVersionedTransaction?: boolean;
|
|
57
|
+
txParams?: TxParams;
|
|
58
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight;
|
|
59
|
+
wallet?: IWallet;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type TxHandlerConfig = {
|
|
63
|
+
blockhashCachingEnabled?: boolean;
|
|
64
|
+
blockhashCachingConfig?: {
|
|
65
|
+
retryCount: number;
|
|
66
|
+
retrySleepTimeMs: number;
|
|
67
|
+
staleCacheTimeMs: number;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* This class is responsible for creating and signing transactions.
|
|
73
|
+
*/
|
|
74
|
+
export class TxHandler {
|
|
75
|
+
private blockHashToLastValidBlockHeightLookup: Record<string, number> = {};
|
|
76
|
+
private returnBlockHeightsWithSignedTxCallbackData = false;
|
|
77
|
+
|
|
78
|
+
private connection: Connection;
|
|
79
|
+
private wallet: IWallet;
|
|
80
|
+
private confirmationOptions: ConfirmOptions;
|
|
81
|
+
|
|
82
|
+
private preSignedCb?: () => void;
|
|
83
|
+
private onSignedCb?: (txSigs: DriftClientMetricsEvents['txSigned']) => void;
|
|
84
|
+
|
|
85
|
+
private blockhashCommitment: Commitment =
|
|
86
|
+
DEFAULT_CONFIRMATION_OPTS.commitment;
|
|
87
|
+
private blockHashFetcher: BlockhashFetcher;
|
|
88
|
+
|
|
89
|
+
constructor(props: {
|
|
90
|
+
connection: Connection;
|
|
91
|
+
wallet: IWallet;
|
|
92
|
+
confirmationOptions: ConfirmOptions;
|
|
93
|
+
opts?: {
|
|
94
|
+
returnBlockHeightsWithSignedTxCallbackData?: boolean;
|
|
95
|
+
onSignedCb?: (txSigs: DriftClientMetricsEvents['txSigned']) => void;
|
|
96
|
+
preSignedCb?: () => void;
|
|
97
|
+
};
|
|
98
|
+
config?: TxHandlerConfig;
|
|
99
|
+
}) {
|
|
100
|
+
this.connection = props.connection;
|
|
101
|
+
this.wallet = props.wallet;
|
|
102
|
+
this.confirmationOptions = props.confirmationOptions;
|
|
103
|
+
this.blockhashCommitment =
|
|
104
|
+
props.confirmationOptions?.preflightCommitment ??
|
|
105
|
+
props?.connection?.commitment ??
|
|
106
|
+
this.blockhashCommitment ??
|
|
107
|
+
'confirmed';
|
|
108
|
+
|
|
109
|
+
this.blockHashFetcher = props?.config?.blockhashCachingEnabled
|
|
110
|
+
? new CachedBlockhashFetcher(
|
|
111
|
+
this.connection,
|
|
112
|
+
this.blockhashCommitment,
|
|
113
|
+
props?.config?.blockhashCachingConfig?.retryCount ??
|
|
114
|
+
BLOCKHASH_FETCH_RETRY_COUNT,
|
|
115
|
+
props?.config?.blockhashCachingConfig?.retrySleepTimeMs ??
|
|
116
|
+
BLOCKHASH_FETCH_RETRY_SLEEP,
|
|
117
|
+
props?.config?.blockhashCachingConfig?.staleCacheTimeMs ??
|
|
118
|
+
RECENT_BLOCKHASH_STALE_TIME_MS
|
|
119
|
+
)
|
|
120
|
+
: new BaseBlockhashFetcher(this.connection, this.blockhashCommitment);
|
|
121
|
+
|
|
122
|
+
// #Optionals
|
|
123
|
+
this.returnBlockHeightsWithSignedTxCallbackData =
|
|
124
|
+
props.opts?.returnBlockHeightsWithSignedTxCallbackData ?? false;
|
|
125
|
+
this.onSignedCb = props.opts?.onSignedCb;
|
|
126
|
+
this.preSignedCb = props.opts?.preSignedCb;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private addHashAndExpiryToLookup(
|
|
130
|
+
hashAndExpiry: BlockhashWithExpiryBlockHeight
|
|
131
|
+
) {
|
|
132
|
+
if (!this.returnBlockHeightsWithSignedTxCallbackData) return;
|
|
133
|
+
|
|
134
|
+
this.blockHashToLastValidBlockHeightLookup[hashAndExpiry.blockhash] =
|
|
135
|
+
hashAndExpiry.lastValidBlockHeight;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private getProps = (wallet?: IWallet, confirmationOpts?: ConfirmOptions) =>
|
|
139
|
+
[wallet ?? this.wallet, confirmationOpts ?? this.confirmationOptions] as [
|
|
140
|
+
IWallet,
|
|
141
|
+
ConfirmOptions,
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
public updateWallet(wallet: IWallet) {
|
|
145
|
+
this.wallet = wallet;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Created this to prevent non-finalized blockhashes being used when building transactions. We want to always use finalized because otherwise it's easy to get the BlockHashNotFound error (RPC uses finalized to validate a transaction). Using an older blockhash when building transactions should never really be a problem right now.
|
|
150
|
+
*
|
|
151
|
+
* https://www.helius.dev/blog/how-to-deal-with-blockhash-errors-on-solana#why-do-blockhash-errors-occur
|
|
152
|
+
*
|
|
153
|
+
* @returns
|
|
154
|
+
*/
|
|
155
|
+
public async getLatestBlockhashForTransaction() {
|
|
156
|
+
return this.blockHashFetcher.getLatestBlockhash();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Applies recent blockhash and signs a given transaction
|
|
161
|
+
* @param tx
|
|
162
|
+
* @param additionalSigners
|
|
163
|
+
* @param wallet
|
|
164
|
+
* @param confirmationOpts
|
|
165
|
+
* @param preSigned
|
|
166
|
+
* @param recentBlockhash
|
|
167
|
+
* @returns
|
|
168
|
+
*/
|
|
169
|
+
public async prepareTx(
|
|
170
|
+
tx: Transaction,
|
|
171
|
+
additionalSigners: Array<Signer>,
|
|
172
|
+
wallet?: IWallet,
|
|
173
|
+
confirmationOpts?: ConfirmOptions,
|
|
174
|
+
preSigned?: boolean,
|
|
175
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight
|
|
176
|
+
): Promise<Transaction> {
|
|
177
|
+
if (preSigned) {
|
|
178
|
+
return tx;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
[wallet, confirmationOpts] = this.getProps(wallet, confirmationOpts);
|
|
182
|
+
|
|
183
|
+
tx.feePayer = wallet.publicKey;
|
|
184
|
+
recentBlockhash = recentBlockhash
|
|
185
|
+
? recentBlockhash
|
|
186
|
+
: await this.getLatestBlockhashForTransaction();
|
|
187
|
+
tx.recentBlockhash = recentBlockhash.blockhash;
|
|
188
|
+
|
|
189
|
+
this.addHashAndExpiryToLookup(recentBlockhash);
|
|
190
|
+
|
|
191
|
+
const signedTx = await this.signTx(tx, additionalSigners);
|
|
192
|
+
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
signedTx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
|
|
195
|
+
|
|
196
|
+
return signedTx;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private isVersionedTransaction(
|
|
200
|
+
tx: Transaction | VersionedTransaction
|
|
201
|
+
): boolean {
|
|
202
|
+
return isVersionedTransaction(tx);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private isLegacyTransaction(tx: Transaction | VersionedTransaction) {
|
|
206
|
+
return !this.isVersionedTransaction(tx);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private getTxSigFromSignedTx(signedTx: Transaction | VersionedTransaction) {
|
|
210
|
+
if (this.isVersionedTransaction(signedTx)) {
|
|
211
|
+
return bs58.encode(
|
|
212
|
+
Buffer.from((signedTx as VersionedTransaction).signatures[0])
|
|
213
|
+
) as string;
|
|
214
|
+
} else {
|
|
215
|
+
return bs58.encode(
|
|
216
|
+
Buffer.from((signedTx as Transaction).signature)
|
|
217
|
+
) as string;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private getBlockhashFromSignedTx(
|
|
222
|
+
signedTx: Transaction | VersionedTransaction
|
|
223
|
+
) {
|
|
224
|
+
if (this.isVersionedTransaction(signedTx)) {
|
|
225
|
+
return (signedTx as VersionedTransaction).message.recentBlockhash;
|
|
226
|
+
} else {
|
|
227
|
+
return (signedTx as Transaction).recentBlockhash;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private async signTx(
|
|
232
|
+
tx: Transaction,
|
|
233
|
+
additionalSigners: Array<Signer>,
|
|
234
|
+
wallet?: IWallet
|
|
235
|
+
): Promise<Transaction> {
|
|
236
|
+
[wallet] = this.getProps(wallet);
|
|
237
|
+
|
|
238
|
+
additionalSigners
|
|
239
|
+
.filter((s): s is Signer => s !== undefined)
|
|
240
|
+
.forEach((kp) => {
|
|
241
|
+
tx.partialSign(kp);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
this.preSignedCb?.();
|
|
245
|
+
|
|
246
|
+
const signedTx = await wallet.signTransaction(tx);
|
|
247
|
+
|
|
248
|
+
// Turn txSig Buffer into base58 string
|
|
249
|
+
const txSig = this.getTxSigFromSignedTx(signedTx);
|
|
250
|
+
|
|
251
|
+
this.handleSignedTxData([
|
|
252
|
+
{
|
|
253
|
+
txSig,
|
|
254
|
+
signedTx,
|
|
255
|
+
blockHash: this.getBlockhashFromSignedTx(signedTx),
|
|
256
|
+
},
|
|
257
|
+
]);
|
|
258
|
+
|
|
259
|
+
return signedTx;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public async signVersionedTx(
|
|
263
|
+
tx: VersionedTransaction,
|
|
264
|
+
additionalSigners: Array<Signer>,
|
|
265
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight,
|
|
266
|
+
wallet?: IWallet
|
|
267
|
+
): Promise<VersionedTransaction> {
|
|
268
|
+
[wallet] = this.getProps(wallet);
|
|
269
|
+
|
|
270
|
+
if (recentBlockhash) {
|
|
271
|
+
tx.message.recentBlockhash = recentBlockhash.blockhash;
|
|
272
|
+
|
|
273
|
+
this.addHashAndExpiryToLookup(recentBlockhash);
|
|
274
|
+
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
tx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
additionalSigners
|
|
280
|
+
?.filter((s): s is Signer => s !== undefined)
|
|
281
|
+
.forEach((kp) => {
|
|
282
|
+
tx.sign([kp]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
this.preSignedCb?.();
|
|
286
|
+
|
|
287
|
+
//@ts-ignore
|
|
288
|
+
const signedTx = (await wallet.signTransaction(tx)) as VersionedTransaction;
|
|
289
|
+
|
|
290
|
+
// Turn txSig Buffer into base58 string
|
|
291
|
+
const txSig = this.getTxSigFromSignedTx(signedTx);
|
|
292
|
+
|
|
293
|
+
this.handleSignedTxData([
|
|
294
|
+
{
|
|
295
|
+
txSig,
|
|
296
|
+
signedTx,
|
|
297
|
+
blockHash: this.getBlockhashFromSignedTx(signedTx),
|
|
298
|
+
},
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
return signedTx;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private handleSignedTxData(
|
|
305
|
+
txData: Omit<SignedTxData, 'lastValidBlockHeight'>[]
|
|
306
|
+
) {
|
|
307
|
+
if (!this.returnBlockHeightsWithSignedTxCallbackData) {
|
|
308
|
+
if (this.onSignedCb) {
|
|
309
|
+
this.onSignedCb(txData);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const signedTxData = txData.map((tx) => {
|
|
316
|
+
const lastValidBlockHeight =
|
|
317
|
+
this.blockHashToLastValidBlockHeightLookup[tx.blockHash];
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
...tx,
|
|
321
|
+
lastValidBlockHeight,
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (this.onSignedCb) {
|
|
326
|
+
this.onSignedCb(signedTxData);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return signedTxData;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Gets transaction params with extra processing applied, like using the simulated compute units or using a dynamically calculated compute unit price.
|
|
334
|
+
* @param txBuildingProps
|
|
335
|
+
* @returns
|
|
336
|
+
*/
|
|
337
|
+
private async getProcessedTransactionParams(
|
|
338
|
+
txBuildingProps: TxBuildingProps
|
|
339
|
+
): Promise<BaseTxParams> {
|
|
340
|
+
const baseTxParams: BaseTxParams = {
|
|
341
|
+
computeUnits: txBuildingProps?.txParams?.computeUnits,
|
|
342
|
+
computeUnitsPrice: txBuildingProps?.txParams?.computeUnitsPrice,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const processedTxParams = await TransactionParamProcessor.process({
|
|
346
|
+
baseTxParams,
|
|
347
|
+
txBuilder: (updatedTxParams) =>
|
|
348
|
+
this.buildTransaction({
|
|
349
|
+
...txBuildingProps,
|
|
350
|
+
txParams: updatedTxParams.txParams ?? baseTxParams,
|
|
351
|
+
forceVersionedTransaction: true,
|
|
352
|
+
}) as Promise<VersionedTransaction>,
|
|
353
|
+
processConfig: {
|
|
354
|
+
useSimulatedComputeUnits:
|
|
355
|
+
txBuildingProps.txParams.useSimulatedComputeUnits,
|
|
356
|
+
computeUnitsBufferMultiplier:
|
|
357
|
+
txBuildingProps.txParams.computeUnitsBufferMultiplier,
|
|
358
|
+
useSimulatedComputeUnitsForCUPriceCalculation:
|
|
359
|
+
txBuildingProps.txParams
|
|
360
|
+
.useSimulatedComputeUnitsForCUPriceCalculation,
|
|
361
|
+
getCUPriceFromComputeUnits:
|
|
362
|
+
txBuildingProps.txParams.getCUPriceFromComputeUnits,
|
|
363
|
+
},
|
|
364
|
+
processParams: {
|
|
365
|
+
connection: this.connection,
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
return processedTxParams;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private _generateVersionedTransaction(
|
|
373
|
+
recentBlockhash: BlockhashWithExpiryBlockHeight,
|
|
374
|
+
message: Message | MessageV0
|
|
375
|
+
) {
|
|
376
|
+
this.addHashAndExpiryToLookup(recentBlockhash);
|
|
377
|
+
|
|
378
|
+
return new VersionedTransaction(message);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
public generateLegacyVersionedTransaction(
|
|
382
|
+
recentBlockhash: BlockhashWithExpiryBlockHeight,
|
|
383
|
+
ixs: TransactionInstruction[],
|
|
384
|
+
wallet?: IWallet
|
|
385
|
+
) {
|
|
386
|
+
[wallet] = this.getProps(wallet);
|
|
387
|
+
|
|
388
|
+
const message = new TransactionMessage({
|
|
389
|
+
payerKey: wallet.publicKey,
|
|
390
|
+
recentBlockhash: recentBlockhash.blockhash,
|
|
391
|
+
instructions: ixs,
|
|
392
|
+
}).compileToLegacyMessage();
|
|
393
|
+
|
|
394
|
+
const tx = this._generateVersionedTransaction(recentBlockhash, message);
|
|
395
|
+
|
|
396
|
+
// @ts-ignore
|
|
397
|
+
tx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
|
|
398
|
+
|
|
399
|
+
return tx;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
public generateVersionedTransaction(
|
|
403
|
+
recentBlockhash: BlockhashWithExpiryBlockHeight,
|
|
404
|
+
ixs: TransactionInstruction[],
|
|
405
|
+
lookupTableAccounts: AddressLookupTableAccount[],
|
|
406
|
+
wallet?: IWallet
|
|
407
|
+
) {
|
|
408
|
+
[wallet] = this.getProps(wallet);
|
|
409
|
+
|
|
410
|
+
const message = new TransactionMessage({
|
|
411
|
+
payerKey: wallet.publicKey,
|
|
412
|
+
recentBlockhash: recentBlockhash.blockhash,
|
|
413
|
+
instructions: ixs,
|
|
414
|
+
}).compileToV0Message(lookupTableAccounts);
|
|
415
|
+
|
|
416
|
+
const tx = this._generateVersionedTransaction(recentBlockhash, message);
|
|
417
|
+
|
|
418
|
+
// @ts-ignore
|
|
419
|
+
tx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
|
|
420
|
+
|
|
421
|
+
return tx;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public generateLegacyTransaction(
|
|
425
|
+
ixs: TransactionInstruction[],
|
|
426
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight
|
|
427
|
+
) {
|
|
428
|
+
const tx = new Transaction().add(...ixs);
|
|
429
|
+
if (recentBlockhash) {
|
|
430
|
+
tx.recentBlockhash = recentBlockhash.blockhash;
|
|
431
|
+
}
|
|
432
|
+
return tx;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Accepts multiple instructions and builds a transaction for each. Prevents needing to spam RPC with requests for the same blockhash.
|
|
437
|
+
* @param props
|
|
438
|
+
* @returns
|
|
439
|
+
*/
|
|
440
|
+
public async buildBulkTransactions(
|
|
441
|
+
props: Omit<TxBuildingProps, 'instructions'> & {
|
|
442
|
+
instructions: (TransactionInstruction | TransactionInstruction[])[];
|
|
443
|
+
}
|
|
444
|
+
) {
|
|
445
|
+
const recentBlockhash =
|
|
446
|
+
props?.recentBlockhash ?? (await this.getLatestBlockhashForTransaction());
|
|
447
|
+
|
|
448
|
+
return await Promise.all(
|
|
449
|
+
props.instructions.map((ix) => {
|
|
450
|
+
if (!ix) return undefined;
|
|
451
|
+
return this.buildTransaction({
|
|
452
|
+
...props,
|
|
453
|
+
instructions: ix,
|
|
454
|
+
recentBlockhash,
|
|
455
|
+
});
|
|
456
|
+
})
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
*
|
|
462
|
+
* @param instructions
|
|
463
|
+
* @param txParams
|
|
464
|
+
* @param txVersion
|
|
465
|
+
* @param lookupTables
|
|
466
|
+
* @param forceVersionedTransaction Return a VersionedTransaction instance even if the version of the transaction is Legacy
|
|
467
|
+
* @returns
|
|
468
|
+
*/
|
|
469
|
+
public async buildTransaction(
|
|
470
|
+
props: TxBuildingProps
|
|
471
|
+
): Promise<Transaction | VersionedTransaction> {
|
|
472
|
+
const {
|
|
473
|
+
instructions,
|
|
474
|
+
txVersion,
|
|
475
|
+
txParams,
|
|
476
|
+
connection: _connection,
|
|
477
|
+
preFlightCommitment: _preFlightCommitment,
|
|
478
|
+
fetchMarketLookupTableAccount,
|
|
479
|
+
forceVersionedTransaction,
|
|
480
|
+
} = props;
|
|
481
|
+
|
|
482
|
+
let { lookupTables } = props;
|
|
483
|
+
|
|
484
|
+
// # Collect and process Tx Params
|
|
485
|
+
let baseTxParams: BaseTxParams = {
|
|
486
|
+
computeUnits: txParams?.computeUnits,
|
|
487
|
+
computeUnitsPrice: txParams?.computeUnitsPrice,
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
if (txParams?.useSimulatedComputeUnits) {
|
|
491
|
+
const processedTxParams = await this.getProcessedTransactionParams(props);
|
|
492
|
+
|
|
493
|
+
baseTxParams = {
|
|
494
|
+
...baseTxParams,
|
|
495
|
+
...processedTxParams,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const instructionsArray = Array.isArray(instructions)
|
|
500
|
+
? instructions
|
|
501
|
+
: [instructions];
|
|
502
|
+
const { hasSetComputeUnitLimitIx, hasSetComputeUnitPriceIx } =
|
|
503
|
+
containsComputeUnitIxs(instructionsArray);
|
|
504
|
+
|
|
505
|
+
// # Create Tx Instructions
|
|
506
|
+
const allIx = [];
|
|
507
|
+
const computeUnits = baseTxParams?.computeUnits;
|
|
508
|
+
if (computeUnits > 0 && !hasSetComputeUnitLimitIx) {
|
|
509
|
+
allIx.push(
|
|
510
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
511
|
+
units: computeUnits,
|
|
512
|
+
})
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const computeUnitsPrice = baseTxParams?.computeUnitsPrice;
|
|
517
|
+
|
|
518
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
519
|
+
allIx.push(
|
|
520
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
521
|
+
microLamports: 0,
|
|
522
|
+
})
|
|
523
|
+
);
|
|
524
|
+
} else if (computeUnitsPrice > 0 && !hasSetComputeUnitPriceIx) {
|
|
525
|
+
allIx.push(
|
|
526
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
527
|
+
microLamports: computeUnitsPrice,
|
|
528
|
+
})
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
allIx.push(...instructionsArray);
|
|
533
|
+
|
|
534
|
+
const recentBlockhash =
|
|
535
|
+
props?.recentBlockhash ?? (await this.getLatestBlockhashForTransaction());
|
|
536
|
+
|
|
537
|
+
// # Create and return Transaction
|
|
538
|
+
if (txVersion === 'legacy') {
|
|
539
|
+
if (forceVersionedTransaction) {
|
|
540
|
+
return this.generateLegacyVersionedTransaction(recentBlockhash, allIx);
|
|
541
|
+
} else {
|
|
542
|
+
return this.generateLegacyTransaction(allIx, recentBlockhash);
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
const marketLookupTable = await fetchMarketLookupTableAccount();
|
|
546
|
+
lookupTables = lookupTables
|
|
547
|
+
? [...lookupTables, marketLookupTable]
|
|
548
|
+
: [marketLookupTable];
|
|
549
|
+
|
|
550
|
+
return this.generateVersionedTransaction(
|
|
551
|
+
recentBlockhash,
|
|
552
|
+
allIx,
|
|
553
|
+
lookupTables
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
public wrapInTx(
|
|
559
|
+
instruction: TransactionInstruction,
|
|
560
|
+
computeUnits = 600_000,
|
|
561
|
+
computeUnitsPrice = 0
|
|
562
|
+
): Transaction {
|
|
563
|
+
const tx = new Transaction();
|
|
564
|
+
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
565
|
+
tx.add(
|
|
566
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
567
|
+
units: computeUnits,
|
|
568
|
+
})
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
573
|
+
tx.add(
|
|
574
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
575
|
+
microLamports: 0,
|
|
576
|
+
})
|
|
577
|
+
);
|
|
578
|
+
} else if (computeUnitsPrice != 0) {
|
|
579
|
+
tx.add(
|
|
580
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
581
|
+
microLamports: computeUnitsPrice,
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return tx.add(instruction);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Get a map of signed and prepared transactions from an array of legacy transactions
|
|
591
|
+
* @param txsToSign
|
|
592
|
+
* @param keys
|
|
593
|
+
* @param wallet
|
|
594
|
+
* @param commitment
|
|
595
|
+
* @returns
|
|
596
|
+
*/
|
|
597
|
+
public async getPreparedAndSignedLegacyTransactionMap<
|
|
598
|
+
T extends Record<string, Transaction | undefined>,
|
|
599
|
+
>(
|
|
600
|
+
txsMap: T,
|
|
601
|
+
wallet?: IWallet,
|
|
602
|
+
commitment?: Commitment,
|
|
603
|
+
recentBlockhash?: BlockhashWithExpiryBlockHeight
|
|
604
|
+
) {
|
|
605
|
+
recentBlockhash = recentBlockhash
|
|
606
|
+
? recentBlockhash
|
|
607
|
+
: await this.getLatestBlockhashForTransaction();
|
|
608
|
+
|
|
609
|
+
this.addHashAndExpiryToLookup(recentBlockhash);
|
|
610
|
+
|
|
611
|
+
for (const tx of Object.values(txsMap)) {
|
|
612
|
+
if (!tx) continue;
|
|
613
|
+
tx.recentBlockhash = recentBlockhash.blockhash;
|
|
614
|
+
tx.feePayer = wallet?.publicKey ?? this.wallet?.publicKey;
|
|
615
|
+
|
|
616
|
+
// @ts-ignore
|
|
617
|
+
tx.SIGNATURE_BLOCK_AND_EXPIRY = recentBlockhash;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return this.getSignedTransactionMap(txsMap, wallet);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Get a map of signed transactions from an array of transactions to sign.
|
|
625
|
+
* @param txsToSign
|
|
626
|
+
* @param keys
|
|
627
|
+
* @param wallet
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
public async getSignedTransactionMap<
|
|
631
|
+
T extends Record<string, Transaction | VersionedTransaction | undefined>,
|
|
632
|
+
>(
|
|
633
|
+
txsToSignMap: T,
|
|
634
|
+
wallet?: IWallet
|
|
635
|
+
): Promise<{
|
|
636
|
+
signedTxMap: T;
|
|
637
|
+
signedTxData: SignedTxData[];
|
|
638
|
+
}> {
|
|
639
|
+
[wallet] = this.getProps(wallet);
|
|
640
|
+
|
|
641
|
+
const txsToSignEntries = Object.entries(txsToSignMap);
|
|
642
|
+
|
|
643
|
+
// Create a map of the same keys as the input map, but with the values set to undefined. We'll populate the filtered (non-undefined) values with signed transactions.
|
|
644
|
+
const signedTxMap = txsToSignEntries.reduce((acc, [key]) => {
|
|
645
|
+
acc[key] = undefined;
|
|
646
|
+
return acc;
|
|
647
|
+
}, {}) as T;
|
|
648
|
+
|
|
649
|
+
const filteredTxEntries = txsToSignEntries.filter(([_, tx]) => !!tx);
|
|
650
|
+
|
|
651
|
+
// Extra handling for legacy transactions
|
|
652
|
+
for (const [_key, tx] of filteredTxEntries) {
|
|
653
|
+
if (this.isLegacyTransaction(tx)) {
|
|
654
|
+
(tx as Transaction).feePayer = wallet.publicKey;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
this.preSignedCb?.();
|
|
659
|
+
|
|
660
|
+
const signedFilteredTxs = await wallet.signAllTransactions(
|
|
661
|
+
filteredTxEntries.map(([_, tx]) => tx as Transaction)
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
signedFilteredTxs.forEach((signedTx, index) => {
|
|
665
|
+
// @ts-ignore
|
|
666
|
+
signedTx.SIGNATURE_BLOCK_AND_EXPIRY =
|
|
667
|
+
// @ts-ignore
|
|
668
|
+
filteredTxEntries[index][1]?.SIGNATURE_BLOCK_AND_EXPIRY;
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
const signedTxData = this.handleSignedTxData(
|
|
672
|
+
signedFilteredTxs.map((signedTx) => {
|
|
673
|
+
return {
|
|
674
|
+
txSig: this.getTxSigFromSignedTx(signedTx),
|
|
675
|
+
signedTx,
|
|
676
|
+
blockHash: this.getBlockhashFromSignedTx(signedTx),
|
|
677
|
+
};
|
|
678
|
+
})
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
filteredTxEntries.forEach(([key], index) => {
|
|
682
|
+
const signedTx = signedFilteredTxs[index];
|
|
683
|
+
// @ts-ignore
|
|
684
|
+
signedTxMap[key] = signedTx;
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
return { signedTxMap, signedTxData };
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Accepts multiple instructions and builds a transaction for each. Prevents needing to spam RPC with requests for the same blockhash.
|
|
692
|
+
* @param props
|
|
693
|
+
* @returns
|
|
694
|
+
*/
|
|
695
|
+
public async buildTransactionsMap<
|
|
696
|
+
T extends Record<string, TransactionInstruction | TransactionInstruction[]>,
|
|
697
|
+
>(
|
|
698
|
+
props: Omit<TxBuildingProps, 'instructions'> & {
|
|
699
|
+
instructionsMap: T;
|
|
700
|
+
}
|
|
701
|
+
): Promise<MappedRecord<T, Transaction | VersionedTransaction>> {
|
|
702
|
+
const builtTxs = await this.buildBulkTransactions({
|
|
703
|
+
...props,
|
|
704
|
+
instructions: Object.values(props.instructionsMap),
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
return Object.keys(props.instructionsMap).reduce((acc, key, index) => {
|
|
708
|
+
acc[key] = builtTxs[index];
|
|
709
|
+
return acc;
|
|
710
|
+
}, {}) as MappedRecord<T, Transaction | VersionedTransaction>;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Builds and signs transactions from a given array of instructions for multiple transactions.
|
|
715
|
+
* @param props
|
|
716
|
+
* @returns
|
|
717
|
+
*/
|
|
718
|
+
public async buildAndSignTransactionMap<
|
|
719
|
+
T extends Record<string, TransactionInstruction | TransactionInstruction[]>,
|
|
720
|
+
>(
|
|
721
|
+
props: Omit<TxBuildingProps, 'instructions'> & {
|
|
722
|
+
instructionsMap: T;
|
|
723
|
+
}
|
|
724
|
+
) {
|
|
725
|
+
const builtTxs = await this.buildTransactionsMap(props);
|
|
726
|
+
|
|
727
|
+
const preppedTransactions = await (props.txVersion === 'legacy'
|
|
728
|
+
? this.getPreparedAndSignedLegacyTransactionMap(
|
|
729
|
+
builtTxs as Record<string, Transaction>,
|
|
730
|
+
props.wallet,
|
|
731
|
+
props.preFlightCommitment
|
|
732
|
+
)
|
|
733
|
+
: this.getSignedTransactionMap(builtTxs, props.wallet));
|
|
734
|
+
|
|
735
|
+
return preppedTransactions;
|
|
736
|
+
}
|
|
737
|
+
}
|