@layerzerolabs/lz-solana-sdk-v2 3.0.47 → 3.0.48
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/CHANGELOG.md +13 -0
- package/package.json +11 -10
- package/src/base-oapp.ts +159 -0
- package/src/config.ts +32 -0
- package/src/deployment.test.ts +11 -0
- package/src/deployment.ts +128 -0
- package/src/dvn.ts +606 -0
- package/src/endpoint.ts +1518 -0
- package/src/executor.ts +577 -0
- package/src/generated/blocked_messagelib/index.ts +18 -0
- package/src/generated/blocked_messagelib/instructions/index.ts +1 -0
- package/src/generated/blocked_messagelib/instructions/version.ts +59 -0
- package/src/generated/dvn/accounts/DvnConfig.ts +217 -0
- package/src/generated/dvn/accounts/ExecuteHash.ts +179 -0
- package/src/generated/dvn/accounts/ReceiveConfig.ts +169 -0
- package/src/generated/dvn/accounts/index.ts +9 -0
- package/src/generated/dvn/errors/index.ts +396 -0
- package/src/generated/dvn/events/AdminConfigSetEvent.ts +22 -0
- package/src/generated/dvn/events/FeeWithdrawnEvent.ts +26 -0
- package/src/generated/dvn/events/MultisigConfigSetEvent.ts +22 -0
- package/src/generated/dvn/events/index.ts +3 -0
- package/src/generated/dvn/index.ts +21 -0
- package/src/generated/dvn/instructions/closeExecute.ts +148 -0
- package/src/generated/dvn/instructions/index.ts +7 -0
- package/src/generated/dvn/instructions/initDvn.ts +144 -0
- package/src/generated/dvn/instructions/invoke.ts +178 -0
- package/src/generated/dvn/instructions/quoteDvn.ts +145 -0
- package/src/generated/dvn/instructions/setConfig.ts +157 -0
- package/src/generated/dvn/instructions/verifiable.ts +160 -0
- package/src/generated/dvn/instructions/withdrawFee.ts +172 -0
- package/src/generated/dvn/types/Acl.ts +26 -0
- package/src/generated/dvn/types/AdminConfig.ts +100 -0
- package/src/generated/dvn/types/CloseExecuteParams.ts +21 -0
- package/src/generated/dvn/types/DstConfig.ts +28 -0
- package/src/generated/dvn/types/ExecuteTransactionDigest.ts +37 -0
- package/src/generated/dvn/types/InitDvnParams.ts +34 -0
- package/src/generated/dvn/types/InvokeParams.ts +28 -0
- package/src/generated/dvn/types/LzOption.ts +24 -0
- package/src/generated/dvn/types/Multisig.ts +24 -0
- package/src/generated/dvn/types/MultisigConfig.ts +124 -0
- package/src/generated/dvn/types/QuoteDvnParams.ts +38 -0
- package/src/generated/dvn/types/SetConfigParams.ts +22 -0
- package/src/generated/dvn/types/TransactionAccount.ts +29 -0
- package/src/generated/dvn/types/UlnConfig.ts +34 -0
- package/src/generated/dvn/types/VerifiableParams.ts +24 -0
- package/src/generated/dvn/types/VerificationState.ts +27 -0
- package/src/generated/dvn/types/WithdrawFeeParams.ts +20 -0
- package/src/generated/dvn/types/index.ts +17 -0
- package/src/generated/endpoint/accounts/ComposeMessageState.ts +170 -0
- package/src/generated/endpoint/accounts/EndpointSettings.ts +184 -0
- package/src/generated/endpoint/accounts/MessageLibInfo.ts +178 -0
- package/src/generated/endpoint/accounts/Nonce.ts +193 -0
- package/src/generated/endpoint/accounts/OAppRegistry.ts +169 -0
- package/src/generated/endpoint/accounts/PayloadHash.ts +169 -0
- package/src/generated/endpoint/accounts/PendingInboundNonce.ts +172 -0
- package/src/generated/endpoint/accounts/ReceiveLibraryConfig.ts +183 -0
- package/src/generated/endpoint/accounts/SendLibraryConfig.ts +171 -0
- package/src/generated/endpoint/accounts/index.ts +31 -0
- package/src/generated/endpoint/errors/index.ts +428 -0
- package/src/generated/endpoint/events/AdminTransferredEvent.ts +23 -0
- package/src/generated/endpoint/events/ComposeDeliveredEvent.ts +31 -0
- package/src/generated/endpoint/events/ComposeSentEvent.ts +33 -0
- package/src/generated/endpoint/events/DefaultReceiveLibrarySetEvent.ts +27 -0
- package/src/generated/endpoint/events/DefaultReceiveLibraryTimeoutSetEvent.ts +29 -0
- package/src/generated/endpoint/events/DefaultSendLibrarySetEvent.ts +27 -0
- package/src/generated/endpoint/events/DelegateSetEvent.ts +22 -0
- package/src/generated/endpoint/events/InboundNonceSkippedEvent.ts +31 -0
- package/src/generated/endpoint/events/LibraryRegisteredEvent.ts +27 -0
- package/src/generated/endpoint/events/LzComposeAlertEvent.ts +43 -0
- package/src/generated/endpoint/events/LzReceiveAlertEvent.ts +45 -0
- package/src/generated/endpoint/events/LzTokenSetEvent.ts +23 -0
- package/src/generated/endpoint/events/OAppRegisteredEvent.ts +27 -0
- package/src/generated/endpoint/events/PacketBurntEvent.ts +32 -0
- package/src/generated/endpoint/events/PacketDeliveredEvent.ts +31 -0
- package/src/generated/endpoint/events/PacketNilifiedEvent.ts +33 -0
- package/src/generated/endpoint/events/PacketSentEvent.ts +29 -0
- package/src/generated/endpoint/events/PacketVerifiedEvent.ts +33 -0
- package/src/generated/endpoint/events/ReceiveLibrarySetEvent.ts +29 -0
- package/src/generated/endpoint/events/ReceiveLibraryTimeoutSetEvent.ts +33 -0
- package/src/generated/endpoint/events/RentWithdrawnEvent.ts +27 -0
- package/src/generated/endpoint/events/SendLibrarySetEvent.ts +29 -0
- package/src/generated/endpoint/events/index.ts +22 -0
- package/src/generated/endpoint/index.ts +21 -0
- package/src/generated/endpoint/instructions/burn.ts +191 -0
- package/src/generated/endpoint/instructions/clear.ts +193 -0
- package/src/generated/endpoint/instructions/clearCompose.ts +160 -0
- package/src/generated/endpoint/instructions/index.ts +32 -0
- package/src/generated/endpoint/instructions/initConfig.ts +172 -0
- package/src/generated/endpoint/instructions/initDefaultReceiveLibrary.ts +195 -0
- package/src/generated/endpoint/instructions/initDefaultSendLibrary.ts +195 -0
- package/src/generated/endpoint/instructions/initEndpoint.ts +147 -0
- package/src/generated/endpoint/instructions/initNonce.ts +168 -0
- package/src/generated/endpoint/instructions/initReceiveLibrary.ts +159 -0
- package/src/generated/endpoint/instructions/initSendLibrary.ts +159 -0
- package/src/generated/endpoint/instructions/initVerify.ts +159 -0
- package/src/generated/endpoint/instructions/lzComposeAlert.ts +148 -0
- package/src/generated/endpoint/instructions/lzReceiveAlert.ts +148 -0
- package/src/generated/endpoint/instructions/nilify.ts +193 -0
- package/src/generated/endpoint/instructions/quote.ts +181 -0
- package/src/generated/endpoint/instructions/registerLibrary.ts +183 -0
- package/src/generated/endpoint/instructions/registerOapp.ts +183 -0
- package/src/generated/endpoint/instructions/send.ts +215 -0
- package/src/generated/endpoint/instructions/sendCompose.ts +183 -0
- package/src/generated/endpoint/instructions/setConfig.ts +169 -0
- package/src/generated/endpoint/instructions/setDefaultReceiveLibrary.ts +184 -0
- package/src/generated/endpoint/instructions/setDefaultReceiveLibraryTimeout.ts +185 -0
- package/src/generated/endpoint/instructions/setDefaultSendLibrary.ts +184 -0
- package/src/generated/endpoint/instructions/setDelegate.ts +160 -0
- package/src/generated/endpoint/instructions/setLzToken.ts +160 -0
- package/src/generated/endpoint/instructions/setReceiveLibrary.ts +190 -0
- package/src/generated/endpoint/instructions/setReceiveLibraryTimeout.ts +184 -0
- package/src/generated/endpoint/instructions/setSendLibrary.ts +190 -0
- package/src/generated/endpoint/instructions/skip.ts +203 -0
- package/src/generated/endpoint/instructions/transferAdmin.ts +160 -0
- package/src/generated/endpoint/instructions/verify.ts +205 -0
- package/src/generated/endpoint/instructions/withdrawRent.ts +172 -0
- package/src/generated/endpoint/types/BurnParams.ts +32 -0
- package/src/generated/endpoint/types/ClearComposeParams.ts +31 -0
- package/src/generated/endpoint/types/ClearParams.ts +34 -0
- package/src/generated/endpoint/types/InitConfigParams.ts +26 -0
- package/src/generated/endpoint/types/InitDefaultReceiveLibraryParams.ts +27 -0
- package/src/generated/endpoint/types/InitDefaultSendLibraryParams.ts +27 -0
- package/src/generated/endpoint/types/InitEndpointParams.ts +27 -0
- package/src/generated/endpoint/types/InitNonceParams.ts +28 -0
- package/src/generated/endpoint/types/InitReceiveLibraryParams.ts +27 -0
- package/src/generated/endpoint/types/InitSendLibraryParams.ts +27 -0
- package/src/generated/endpoint/types/InitVerifyParams.ts +30 -0
- package/src/generated/endpoint/types/LzComposeAlertParams.ts +41 -0
- package/src/generated/endpoint/types/LzReceiveAlertParams.ts +43 -0
- package/src/generated/endpoint/types/MessageLibType.ts +25 -0
- package/src/generated/endpoint/types/MessagingFee.ts +24 -0
- package/src/generated/endpoint/types/MessagingReceipt.ts +27 -0
- package/src/generated/endpoint/types/NilifyParams.ts +32 -0
- package/src/generated/endpoint/types/QuoteParams.ts +34 -0
- package/src/generated/endpoint/types/ReceiveLibraryTimeout.ts +27 -0
- package/src/generated/endpoint/types/RegisterLibraryParams.ts +28 -0
- package/src/generated/endpoint/types/RegisterOAppParams.ts +23 -0
- package/src/generated/endpoint/types/SendComposeParams.ts +31 -0
- package/src/generated/endpoint/types/SendParams.ts +32 -0
- package/src/generated/endpoint/types/SetConfigParams.ts +31 -0
- package/src/generated/endpoint/types/SetDefaultReceiveLibraryParams.ts +29 -0
- package/src/generated/endpoint/types/SetDefaultReceiveLibraryTimeoutParams.ts +29 -0
- package/src/generated/endpoint/types/SetDefaultSendLibraryParams.ts +27 -0
- package/src/generated/endpoint/types/SetDelegateParams.ts +22 -0
- package/src/generated/endpoint/types/SetLzTokenParams.ts +23 -0
- package/src/generated/endpoint/types/SetReceiveLibraryParams.ts +31 -0
- package/src/generated/endpoint/types/SetReceiveLibraryTimeoutParams.ts +31 -0
- package/src/generated/endpoint/types/SetSendLibraryParams.ts +29 -0
- package/src/generated/endpoint/types/SkipParams.ts +30 -0
- package/src/generated/endpoint/types/TransferAdminParams.ts +23 -0
- package/src/generated/endpoint/types/VerifyParams.ts +32 -0
- package/src/generated/endpoint/types/WithdrawRentParams.ts +21 -0
- package/src/generated/endpoint/types/index.ts +36 -0
- package/src/generated/executor/accounts/ExecutorConfig.ts +216 -0
- package/src/generated/executor/accounts/Nonce.ts +193 -0
- package/src/generated/executor/accounts/index.ts +7 -0
- package/src/generated/executor/errors/index.ts +434 -0
- package/src/generated/executor/events/NativeDropAppliedEvent.ts +38 -0
- package/src/generated/executor/events/index.ts +1 -0
- package/src/generated/executor/index.ts +21 -0
- package/src/generated/executor/instructions/adminSetConfig.ts +136 -0
- package/src/generated/executor/instructions/compose.ts +181 -0
- package/src/generated/executor/instructions/executable.ts +136 -0
- package/src/generated/executor/instructions/execute.ts +181 -0
- package/src/generated/executor/instructions/index.ts +8 -0
- package/src/generated/executor/instructions/initExecutor.ts +147 -0
- package/src/generated/executor/instructions/nativeDrop.ts +171 -0
- package/src/generated/executor/instructions/ownerSetConfig.ts +136 -0
- package/src/generated/executor/instructions/quoteExecutor.ts +148 -0
- package/src/generated/executor/types/Acl.ts +26 -0
- package/src/generated/executor/types/AdminSetConfigParams.ts +83 -0
- package/src/generated/executor/types/ComposeParams.ts +27 -0
- package/src/generated/executor/types/DstConfig.ts +32 -0
- package/src/generated/executor/types/ExecutableParams.ts +30 -0
- package/src/generated/executor/types/ExecuteParams.ts +31 -0
- package/src/generated/executor/types/ExecutionState.ts +26 -0
- package/src/generated/executor/types/InitExecutorParams.ts +33 -0
- package/src/generated/executor/types/LzComposeParams.ts +35 -0
- package/src/generated/executor/types/LzOption.ts +24 -0
- package/src/generated/executor/types/LzReceiveParams.ts +33 -0
- package/src/generated/executor/types/NativeDropParams.ts +36 -0
- package/src/generated/executor/types/NativeDropRequest.ts +26 -0
- package/src/generated/executor/types/OwnerSetConfigParams.ts +123 -0
- package/src/generated/executor/types/QuoteExecutorParams.ts +34 -0
- package/src/generated/executor/types/index.ts +15 -0
- package/src/generated/pricefeed/accounts/PriceFeed.ts +220 -0
- package/src/generated/pricefeed/accounts/index.ts +5 -0
- package/src/generated/pricefeed/errors/index.ts +115 -0
- package/src/generated/pricefeed/index.ts +21 -0
- package/src/generated/pricefeed/instructions/getFee.ts +121 -0
- package/src/generated/pricefeed/instructions/index.ts +6 -0
- package/src/generated/pricefeed/instructions/initPriceFeed.ts +147 -0
- package/src/generated/pricefeed/instructions/setPrice.ts +133 -0
- package/src/generated/pricefeed/instructions/setPriceFeed.ts +136 -0
- package/src/generated/pricefeed/instructions/setSolPrice.ts +136 -0
- package/src/generated/pricefeed/instructions/transferAdmin.ts +136 -0
- package/src/generated/pricefeed/types/GetFeeParams.ts +26 -0
- package/src/generated/pricefeed/types/InitPriceFeedParams.ts +27 -0
- package/src/generated/pricefeed/types/ModelType.ts +66 -0
- package/src/generated/pricefeed/types/Price.ts +31 -0
- package/src/generated/pricefeed/types/PriceParams.ts +29 -0
- package/src/generated/pricefeed/types/SetPriceFeedParams.ts +29 -0
- package/src/generated/pricefeed/types/SetPriceParams.ts +26 -0
- package/src/generated/pricefeed/types/SetSolPriceParams.ts +21 -0
- package/src/generated/pricefeed/types/TransferAdminParams.ts +23 -0
- package/src/generated/pricefeed/types/index.ts +9 -0
- package/src/generated/simple_messagelib/accounts/MessageLib.ts +222 -0
- package/src/generated/simple_messagelib/accounts/ReceiveConfigStore.ts +168 -0
- package/src/generated/simple_messagelib/accounts/SendConfigStore.ts +170 -0
- package/src/generated/simple_messagelib/accounts/index.ts +13 -0
- package/src/generated/simple_messagelib/errors/index.ts +207 -0
- package/src/generated/simple_messagelib/index.ts +21 -0
- package/src/generated/simple_messagelib/instructions/index.ts +15 -0
- package/src/generated/simple_messagelib/instructions/initConfig.ts +183 -0
- package/src/generated/simple_messagelib/instructions/initDefaultConfig.ts +171 -0
- package/src/generated/simple_messagelib/instructions/initMessageLib.ts +147 -0
- package/src/generated/simple_messagelib/instructions/quote.ts +133 -0
- package/src/generated/simple_messagelib/instructions/revertCall.ts +59 -0
- package/src/generated/simple_messagelib/instructions/send.ts +154 -0
- package/src/generated/simple_messagelib/instructions/sendWithLzToken.ts +207 -0
- package/src/generated/simple_messagelib/instructions/setConfig.ts +157 -0
- package/src/generated/simple_messagelib/instructions/setDefaultConfig.ts +171 -0
- package/src/generated/simple_messagelib/instructions/setFee.ts +133 -0
- package/src/generated/simple_messagelib/instructions/setWlCaller.ts +136 -0
- package/src/generated/simple_messagelib/instructions/transferAdmin.ts +136 -0
- package/src/generated/simple_messagelib/instructions/validatePacket.ts +136 -0
- package/src/generated/simple_messagelib/instructions/version.ts +59 -0
- package/src/generated/simple_messagelib/instructions/withdrawFees.ts +148 -0
- package/src/generated/simple_messagelib/types/InitConfigParams.ts +26 -0
- package/src/generated/simple_messagelib/types/InitDefaultConfigParams.ts +27 -0
- package/src/generated/simple_messagelib/types/InitMessageLibParams.ts +35 -0
- package/src/generated/simple_messagelib/types/MessagingFee.ts +24 -0
- package/src/generated/simple_messagelib/types/Packet.ts +36 -0
- package/src/generated/simple_messagelib/types/QuoteParams.ts +27 -0
- package/src/generated/simple_messagelib/types/SendParams.ts +27 -0
- package/src/generated/simple_messagelib/types/SendWithLzTokenParams.ts +34 -0
- package/src/generated/simple_messagelib/types/SetConfigParams.ts +31 -0
- package/src/generated/simple_messagelib/types/SetDefaultConfigParams.ts +27 -0
- package/src/generated/simple_messagelib/types/SetFeeParams.ts +24 -0
- package/src/generated/simple_messagelib/types/SetWlCallerParams.ts +22 -0
- package/src/generated/simple_messagelib/types/TransferAdminParams.ts +23 -0
- package/src/generated/simple_messagelib/types/ValidatePacketParams.ts +21 -0
- package/src/generated/simple_messagelib/types/Version.ts +26 -0
- package/src/generated/simple_messagelib/types/WithdrawFeesParams.ts +21 -0
- package/src/generated/simple_messagelib/types/index.ts +16 -0
- package/src/generated/uln/accounts/Confirmations.ts +171 -0
- package/src/generated/uln/accounts/ReceiveConfig.ts +169 -0
- package/src/generated/uln/accounts/SendConfig.ts +177 -0
- package/src/generated/uln/accounts/UlnSettings.ts +195 -0
- package/src/generated/uln/accounts/index.ts +16 -0
- package/src/generated/uln/errors/index.ts +761 -0
- package/src/generated/uln/events/AdminTransferredEvent.ts +23 -0
- package/src/generated/uln/events/ConfigSetEvent.ts +30 -0
- package/src/generated/uln/events/DefaultConfigSetEvent.ts +31 -0
- package/src/generated/uln/events/FeesPaidEvent.ts +28 -0
- package/src/generated/uln/events/LzTokenSetEvent.ts +23 -0
- package/src/generated/uln/events/PayloadVerifiedEvent.ts +31 -0
- package/src/generated/uln/events/RentWithdrawnEvent.ts +27 -0
- package/src/generated/uln/events/TreasuryFeeCapSetEvent.ts +21 -0
- package/src/generated/uln/events/TreasurySetEvent.ts +22 -0
- package/src/generated/uln/events/index.ts +7 -0
- package/src/generated/uln/index.ts +21 -0
- package/src/generated/uln/instructions/closeVerify.ts +148 -0
- package/src/generated/uln/instructions/commitVerification.ts +148 -0
- package/src/generated/uln/instructions/index.ts +16 -0
- package/src/generated/uln/instructions/initConfig.ts +183 -0
- package/src/generated/uln/instructions/initDefaultConfig.ts +195 -0
- package/src/generated/uln/instructions/initUln.ts +144 -0
- package/src/generated/uln/instructions/initVerify.ts +147 -0
- package/src/generated/uln/instructions/quote.ts +157 -0
- package/src/generated/uln/instructions/send.ts +220 -0
- package/src/generated/uln/instructions/sendWithLzToken.ts +255 -0
- package/src/generated/uln/instructions/setConfig.ts +205 -0
- package/src/generated/uln/instructions/setDefaultConfig.ts +184 -0
- package/src/generated/uln/instructions/setTreasury.ts +160 -0
- package/src/generated/uln/instructions/transferAdmin.ts +160 -0
- package/src/generated/uln/instructions/verify.ts +157 -0
- package/src/generated/uln/instructions/version.ts +59 -0
- package/src/generated/uln/instructions/withdrawRent.ts +172 -0
- package/src/generated/uln/types/CloseVerifyParams.ts +24 -0
- package/src/generated/uln/types/CommitVerificationParams.ts +25 -0
- package/src/generated/uln/types/Config.ts +75 -0
- package/src/generated/uln/types/ExecutorConfig.ts +26 -0
- package/src/generated/uln/types/InitConfigParams.ts +26 -0
- package/src/generated/uln/types/InitDefaultConfigParams.ts +31 -0
- package/src/generated/uln/types/InitUlnParams.ts +30 -0
- package/src/generated/uln/types/InitVerifyParams.ts +28 -0
- package/src/generated/uln/types/LzTokenTreasury.ts +26 -0
- package/src/generated/uln/types/MessagingFee.ts +24 -0
- package/src/generated/uln/types/Packet.ts +36 -0
- package/src/generated/uln/types/QuoteParams.ts +27 -0
- package/src/generated/uln/types/SendParams.ts +27 -0
- package/src/generated/uln/types/SendWithLzTokenParams.ts +34 -0
- package/src/generated/uln/types/SetConfigParams.ts +31 -0
- package/src/generated/uln/types/SetDefaultConfigParams.ts +31 -0
- package/src/generated/uln/types/SetTreasuryParams.ts +22 -0
- package/src/generated/uln/types/TransferAdminParams.ts +23 -0
- package/src/generated/uln/types/Treasury.ts +31 -0
- package/src/generated/uln/types/TreasuryFee.ts +28 -0
- package/src/generated/uln/types/UlnConfig.ts +34 -0
- package/src/generated/uln/types/VerifyParams.ts +26 -0
- package/src/generated/uln/types/Version.ts +26 -0
- package/src/generated/uln/types/WithdrawRentParams.ts +21 -0
- package/src/generated/uln/types/WorkerFee.ts +26 -0
- package/src/generated/uln/types/index.ts +25 -0
- package/src/generated/worker_interface/errors/index.ts +75 -0
- package/src/generated/worker_interface/index.ts +20 -0
- package/src/generated/worker_interface/instructions/index.ts +2 -0
- package/src/generated/worker_interface/instructions/quoteDvn.ts +145 -0
- package/src/generated/worker_interface/instructions/quoteExecutor.ts +148 -0
- package/src/generated/worker_interface/types/LzOption.ts +24 -0
- package/src/generated/worker_interface/types/QuoteDvnParams.ts +38 -0
- package/src/generated/worker_interface/types/QuoteExecutorParams.ts +34 -0
- package/src/generated/worker_interface/types/index.ts +3 -0
- package/src/index.ts +120 -0
- package/src/pda-deriver.ts +658 -0
- package/src/pricefeed.ts +208 -0
- package/src/recevie.ts +269 -0
- package/src/send-helper.ts +504 -0
- package/src/simple-message-lib.ts +303 -0
- package/src/types.ts +222 -0
- package/src/uln.ts +1045 -0
- package/src/utility.ts +592 -0
package/src/utility.ts
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
import * as beet from '@metaplex-foundation/beet'
|
|
4
|
+
import {
|
|
5
|
+
AddressLookupTableProgram,
|
|
6
|
+
Blockhash,
|
|
7
|
+
CloseLookupTableParams,
|
|
8
|
+
Commitment,
|
|
9
|
+
Connection,
|
|
10
|
+
DeactivateLookupTableParams,
|
|
11
|
+
Finality,
|
|
12
|
+
GetAccountInfoConfig,
|
|
13
|
+
GetVersionedTransactionConfig,
|
|
14
|
+
Keypair,
|
|
15
|
+
MessageV0,
|
|
16
|
+
NONCE_ACCOUNT_LENGTH,
|
|
17
|
+
NonceAccount,
|
|
18
|
+
PartiallyDecodedInstruction,
|
|
19
|
+
PublicKey,
|
|
20
|
+
SystemProgram,
|
|
21
|
+
Transaction,
|
|
22
|
+
TransactionInstruction,
|
|
23
|
+
TransactionMessage,
|
|
24
|
+
TransactionSignature,
|
|
25
|
+
VersionedTransaction,
|
|
26
|
+
} from '@solana/web3.js'
|
|
27
|
+
import base58 from 'bs58'
|
|
28
|
+
|
|
29
|
+
import { sha2_256 } from '@layerzerolabs/lz-foundation'
|
|
30
|
+
|
|
31
|
+
import { EventEmitDiscriminator } from './endpoint'
|
|
32
|
+
import {
|
|
33
|
+
ComposeDeliveredEvent,
|
|
34
|
+
ComposeSentEvent,
|
|
35
|
+
PacketDeliveredEvent,
|
|
36
|
+
PacketSentEvent,
|
|
37
|
+
PacketVerifiedEvent,
|
|
38
|
+
composeDeliveredEventBeet,
|
|
39
|
+
composeSentEventBeet,
|
|
40
|
+
packetDeliveredEventBeet,
|
|
41
|
+
packetSentEventBeet,
|
|
42
|
+
packetVerifiedEventBeet,
|
|
43
|
+
} from './generated/endpoint/events'
|
|
44
|
+
import { FeesPaidEvent, feesPaidEventBeet } from './generated/uln/events'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets the event discriminator for a given event.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} event - The event name.
|
|
50
|
+
* @returns {string} The event discriminator.
|
|
51
|
+
*/
|
|
52
|
+
function getEventDiscriminator(event: string): string {
|
|
53
|
+
const hash = crypto.createHash('sha256')
|
|
54
|
+
/*
|
|
55
|
+
https://book.anchor-lang.com/anchor_bts/discriminator.html
|
|
56
|
+
sha256(namespace:eventName) namespace of cpi event is 'event'
|
|
57
|
+
*/
|
|
58
|
+
hash.update(`event:${event}`)
|
|
59
|
+
const sha256 = hash.digest('hex')
|
|
60
|
+
return sha256.slice(0, 16) // first 8 bytes
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Extracts the sent packet event by transaction hash.
|
|
65
|
+
*
|
|
66
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
67
|
+
* @param {PublicKey} program - The program public key.
|
|
68
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
69
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
70
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
71
|
+
* @returns {Promise<PacketSentEvent[] | null>} A promise that resolves to an array of sent packet events or null if not found.
|
|
72
|
+
*/
|
|
73
|
+
export async function extractSentPacketEventByTxHash(
|
|
74
|
+
connection: Connection,
|
|
75
|
+
program: PublicKey,
|
|
76
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
77
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
78
|
+
unsafeParseErr = false
|
|
79
|
+
): Promise<PacketSentEvent[] | null> {
|
|
80
|
+
const events = await extractEventFromTransactionSignature<PacketSentEvent>(
|
|
81
|
+
connection,
|
|
82
|
+
program,
|
|
83
|
+
signature,
|
|
84
|
+
packetSentEventBeet,
|
|
85
|
+
commitment,
|
|
86
|
+
unsafeParseErr
|
|
87
|
+
)
|
|
88
|
+
if (!events) return null
|
|
89
|
+
return events
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extracts the verified packet event by transaction hash.
|
|
94
|
+
*
|
|
95
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
96
|
+
* @param {PublicKey} program - The program public key.
|
|
97
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
98
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
99
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
100
|
+
* @returns {Promise<PacketVerifiedEvent[] | null>} A promise that resolves to an array of verified packet events or null if not found.
|
|
101
|
+
*/
|
|
102
|
+
export async function extractVerifiedPacketEventByTxHash(
|
|
103
|
+
connection: Connection,
|
|
104
|
+
program: PublicKey,
|
|
105
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
106
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
107
|
+
unsafeParseErr = false
|
|
108
|
+
): Promise<PacketVerifiedEvent[] | null> {
|
|
109
|
+
const events = await extractEventFromTransactionSignature<PacketVerifiedEvent>(
|
|
110
|
+
connection,
|
|
111
|
+
program,
|
|
112
|
+
signature,
|
|
113
|
+
packetVerifiedEventBeet,
|
|
114
|
+
commitment,
|
|
115
|
+
unsafeParseErr
|
|
116
|
+
)
|
|
117
|
+
if (!events) return null
|
|
118
|
+
return events
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Extracts the received packet event by transaction hash.
|
|
123
|
+
*
|
|
124
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
125
|
+
* @param {PublicKey} program - The program public key.
|
|
126
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
127
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
128
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
129
|
+
* @returns {Promise<PacketDeliveredEvent[] | null>} A promise that resolves to an array of received packet events or null if not found.
|
|
130
|
+
*/
|
|
131
|
+
export async function extractReceivedPacketEventByTxHash(
|
|
132
|
+
connection: Connection,
|
|
133
|
+
program: PublicKey,
|
|
134
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
135
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
136
|
+
unsafeParseErr = false
|
|
137
|
+
): Promise<PacketDeliveredEvent[] | null> {
|
|
138
|
+
const events = await extractEventFromTransactionSignature<PacketDeliveredEvent>(
|
|
139
|
+
connection,
|
|
140
|
+
program,
|
|
141
|
+
signature,
|
|
142
|
+
packetDeliveredEventBeet,
|
|
143
|
+
commitment,
|
|
144
|
+
unsafeParseErr
|
|
145
|
+
)
|
|
146
|
+
if (!events) return null
|
|
147
|
+
return events
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Extracts the compose sent event by transaction hash.
|
|
152
|
+
*
|
|
153
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
154
|
+
* @param {PublicKey} program - The program public key.
|
|
155
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
156
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
157
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
158
|
+
* @returns {Promise<ComposeSentEvent[] | null>} A promise that resolves to an array of compose sent events or null if not found.
|
|
159
|
+
*/
|
|
160
|
+
export async function extractComposeSentEventByTxHash(
|
|
161
|
+
connection: Connection,
|
|
162
|
+
program: PublicKey,
|
|
163
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
164
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
165
|
+
unsafeParseErr = false
|
|
166
|
+
): Promise<ComposeSentEvent[] | null> {
|
|
167
|
+
const events = await extractEventFromTransactionSignature<ComposeSentEvent>(
|
|
168
|
+
connection,
|
|
169
|
+
program,
|
|
170
|
+
signature,
|
|
171
|
+
composeSentEventBeet,
|
|
172
|
+
commitment,
|
|
173
|
+
unsafeParseErr
|
|
174
|
+
)
|
|
175
|
+
if (!events) return null
|
|
176
|
+
return events
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Extracts the compose delivered event by transaction hash.
|
|
181
|
+
*
|
|
182
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
183
|
+
* @param {PublicKey} program - The program public key.
|
|
184
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
185
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
186
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
187
|
+
* @returns {Promise<ComposeDeliveredEvent[] | null>} A promise that resolves to an array of compose delivered events or null if not found.
|
|
188
|
+
*/
|
|
189
|
+
export async function extractComposeDeliveredEventByTxHash(
|
|
190
|
+
connection: Connection,
|
|
191
|
+
program: PublicKey,
|
|
192
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
193
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
194
|
+
unsafeParseErr = false
|
|
195
|
+
): Promise<ComposeDeliveredEvent[] | null> {
|
|
196
|
+
const events = await extractEventFromTransactionSignature<ComposeDeliveredEvent>(
|
|
197
|
+
connection,
|
|
198
|
+
program,
|
|
199
|
+
signature,
|
|
200
|
+
composeDeliveredEventBeet,
|
|
201
|
+
commitment,
|
|
202
|
+
unsafeParseErr
|
|
203
|
+
)
|
|
204
|
+
if (!events) return null
|
|
205
|
+
return events
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Extracts the worker fee paid event by transaction hash.
|
|
210
|
+
*
|
|
211
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
212
|
+
* @param {PublicKey} program - The program public key.
|
|
213
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature or parsed transaction.
|
|
214
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
215
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed.
|
|
216
|
+
* @returns {Promise<FeesPaidEvent[] | null>} A promise that resolves to an array of worker fee paid events or null if not found.
|
|
217
|
+
*/
|
|
218
|
+
export async function extractWorkerFeePaidEventByTxHash(
|
|
219
|
+
connection: Connection,
|
|
220
|
+
program: PublicKey,
|
|
221
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
222
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
223
|
+
unsafeParseErr = false
|
|
224
|
+
): Promise<FeesPaidEvent[] | null> {
|
|
225
|
+
const events = await extractEventFromTransactionSignature<FeesPaidEvent>(
|
|
226
|
+
connection,
|
|
227
|
+
program,
|
|
228
|
+
signature,
|
|
229
|
+
feesPaidEventBeet,
|
|
230
|
+
commitment,
|
|
231
|
+
unsafeParseErr
|
|
232
|
+
)
|
|
233
|
+
if (!events) return null
|
|
234
|
+
return events
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Extracts events from a transaction signature.
|
|
239
|
+
*
|
|
240
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
241
|
+
* @param {PublicKey} program - The program public key, extract event from specific program id
|
|
242
|
+
* @param {TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>} signature - The transaction signature(tx hash) or parsed transaction.
|
|
243
|
+
* @param {beet.FixableBeetArgsStruct<E> | beet.BeetArgsStruct<E>} eventBeet - The beet struct for the event.
|
|
244
|
+
* @param {Finality | GetVersionedTransactionConfig} [commitment] - The commitment level.
|
|
245
|
+
* @param {boolean} [unsafeParseErr=false] - Whether to parse the event even if the transaction failed. Default is false, only parse event if transaction succeeded. if true, will parse event even if transaction failed. Please set this to false if you want to ignore failed transaction and set `true` with caution as it may lead to unexpected behavior.
|
|
246
|
+
* @returns {Promise<E[] | null>} A promise that resolves to an array of events or null if not found.
|
|
247
|
+
*/
|
|
248
|
+
export async function extractEventFromTransactionSignature<E>(
|
|
249
|
+
connection: Connection,
|
|
250
|
+
program: PublicKey,
|
|
251
|
+
signature: TransactionSignature | Awaited<ReturnType<typeof connection.getParsedTransaction>>,
|
|
252
|
+
eventBeet: beet.FixableBeetArgsStruct<E> | beet.BeetArgsStruct<E>,
|
|
253
|
+
commitment?: Finality | GetVersionedTransactionConfig,
|
|
254
|
+
unsafeParseErr = false
|
|
255
|
+
): Promise<E[] | null> {
|
|
256
|
+
const tx = typeof signature === 'string' ? await connection.getParsedTransaction(signature, commitment) : signature
|
|
257
|
+
if (tx == null) return null
|
|
258
|
+
const events = new Array<E>()
|
|
259
|
+
// refer: https://solana.com/docs/rpc/http/gettransaction
|
|
260
|
+
// tx.meta.err: Error if transaction failed, null if transaction succeeded
|
|
261
|
+
if (tx.meta?.err !== null && !unsafeParseErr) {
|
|
262
|
+
return null
|
|
263
|
+
}
|
|
264
|
+
for (const instruction of tx.meta?.innerInstructions ?? []) {
|
|
265
|
+
for (const innerInstruction of instruction.instructions) {
|
|
266
|
+
const inst = innerInstruction as PartiallyDecodedInstruction
|
|
267
|
+
if (!inst.programId.equals(program)) {
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
const decoded = base58.decode(inst.data)
|
|
271
|
+
const discriminator = Buffer.from(decoded.subarray(0, 8)).toString('hex')
|
|
272
|
+
if (discriminator !== EventEmitDiscriminator) {
|
|
273
|
+
continue
|
|
274
|
+
}
|
|
275
|
+
// get second 8 bits, filter event here
|
|
276
|
+
const eventDiscriminator = Buffer.from(decoded.subarray(8, 16)).toString('hex')
|
|
277
|
+
if (eventDiscriminator !== getEventDiscriminator(eventBeet.description)) {
|
|
278
|
+
continue
|
|
279
|
+
}
|
|
280
|
+
const dataBuffer = Buffer.from(decoded.subarray(16, decoded.length))
|
|
281
|
+
if (eventBeet instanceof beet.FixableBeetArgsStruct) {
|
|
282
|
+
const beet = eventBeet.toFixedFromData(dataBuffer, 0)
|
|
283
|
+
events.push(beet.read(dataBuffer, 0))
|
|
284
|
+
} else {
|
|
285
|
+
events.push(eventBeet.read(dataBuffer, 0))
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return events.length > 0 ? events : null
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Generates an address lookup table.
|
|
294
|
+
*
|
|
295
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
296
|
+
* @param {PublicKey} payer - The payer public key.
|
|
297
|
+
* @param {PublicKey} authority - The authority public key.
|
|
298
|
+
* @param {PublicKey[]} addresses - The addresses to include in the lookup table.
|
|
299
|
+
* @returns {Promise<{ instructions: TransactionInstruction[]; address: PublicKey }>} A promise that resolves to the instructions and lookup table address.
|
|
300
|
+
*/
|
|
301
|
+
export async function generateAddressLookupTable(
|
|
302
|
+
connection: Connection,
|
|
303
|
+
payer: PublicKey,
|
|
304
|
+
authority: PublicKey,
|
|
305
|
+
addresses: PublicKey[]
|
|
306
|
+
): Promise<{ instructions: TransactionInstruction[]; address: PublicKey }> {
|
|
307
|
+
const slot = await connection.getSlot('finalized')
|
|
308
|
+
const [createInstruction, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({
|
|
309
|
+
payer,
|
|
310
|
+
authority,
|
|
311
|
+
recentSlot: slot,
|
|
312
|
+
})
|
|
313
|
+
const extendInstruction = AddressLookupTableProgram.extendLookupTable({
|
|
314
|
+
payer,
|
|
315
|
+
authority,
|
|
316
|
+
lookupTable: lookupTableAddress,
|
|
317
|
+
addresses,
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
instructions: [createInstruction, extendInstruction],
|
|
322
|
+
address: lookupTableAddress,
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Deactivates an address lookup table.
|
|
328
|
+
* To properly terminate the lookup table, it is advisable to initially invoke `deactivateLookupTable`,
|
|
329
|
+
* pause for a duration of 500 blocks, and subsequently invoke `closeLookupTable`.
|
|
330
|
+
*
|
|
331
|
+
* @param {PublicKey} authority - The authority public key.
|
|
332
|
+
* @param {PublicKey} lookupTable - The lookup table public key.
|
|
333
|
+
* @returns {TransactionInstruction} The transaction instruction.
|
|
334
|
+
*/
|
|
335
|
+
export function deactivateLookupTable(authority: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
336
|
+
return AddressLookupTableProgram.deactivateLookupTable({
|
|
337
|
+
authority,
|
|
338
|
+
lookupTable,
|
|
339
|
+
} satisfies DeactivateLookupTableParams)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Closes an address lookup table.
|
|
344
|
+
* To properly terminate the lookup table, it is advisable to initially invoke `deactivateLookupTable`,
|
|
345
|
+
* pause for a duration of 500 blocks, and subsequently invoke `closeLookupTable`.
|
|
346
|
+
*
|
|
347
|
+
* @param {PublicKey} recipient - The recipient public key.
|
|
348
|
+
* @param {PublicKey} authority - The authority public key.
|
|
349
|
+
* @param {PublicKey} lookupTable - The lookup table public key.
|
|
350
|
+
* @returns {TransactionInstruction} The transaction instruction.
|
|
351
|
+
*/
|
|
352
|
+
export function closeLookupTable(
|
|
353
|
+
recipient: PublicKey,
|
|
354
|
+
authority: PublicKey,
|
|
355
|
+
lookupTable: PublicKey
|
|
356
|
+
): TransactionInstruction {
|
|
357
|
+
return AddressLookupTableProgram.closeLookupTable({
|
|
358
|
+
authority,
|
|
359
|
+
recipient,
|
|
360
|
+
lookupTable,
|
|
361
|
+
} satisfies CloseLookupTableParams)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates a versioned transaction with an address lookup table.
|
|
366
|
+
*
|
|
367
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
368
|
+
* @param {PublicKey} payer - The payer public key.
|
|
369
|
+
* @param {TransactionInstruction[]} instructions - The transaction instructions.
|
|
370
|
+
* @param {Blockhash} [recentBlockHash] - The recent block hash.
|
|
371
|
+
* @param {PublicKey} [tableAddr] - The address lookup table public key.
|
|
372
|
+
* @returns {Promise<VersionedTransaction>} A promise that resolves to the versioned transaction.
|
|
373
|
+
*/
|
|
374
|
+
export async function txWithAddressLookupTable(
|
|
375
|
+
connection: Connection,
|
|
376
|
+
payer: PublicKey,
|
|
377
|
+
instructions: TransactionInstruction[],
|
|
378
|
+
recentBlockHash?: Blockhash,
|
|
379
|
+
tableAddr?: PublicKey
|
|
380
|
+
): Promise<VersionedTransaction> {
|
|
381
|
+
recentBlockHash = recentBlockHash ?? (await connection.getLatestBlockhash()).blockhash
|
|
382
|
+
if (!tableAddr) {
|
|
383
|
+
return new VersionedTransaction(
|
|
384
|
+
new TransactionMessage({
|
|
385
|
+
instructions,
|
|
386
|
+
payerKey: payer,
|
|
387
|
+
recentBlockhash: recentBlockHash,
|
|
388
|
+
}).compileToV0Message()
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
const { value: lookupTableAccount } = await connection.getAddressLookupTable(tableAddr)
|
|
392
|
+
return new VersionedTransaction(
|
|
393
|
+
new TransactionMessage({
|
|
394
|
+
instructions,
|
|
395
|
+
payerKey: payer,
|
|
396
|
+
recentBlockhash: recentBlockHash,
|
|
397
|
+
}).compileToV0Message(lookupTableAccount ? [lookupTableAccount] : undefined)
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Creates a nonce account transaction.
|
|
403
|
+
*
|
|
404
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
405
|
+
* @param {PublicKey} auth - The authorized public key.
|
|
406
|
+
* @param {number} [lamportsForRent] - The lamports for rent.
|
|
407
|
+
* @returns {Promise<{ tx: Transaction; nonceAccount: Keypair }>} A promise that resolves to the transaction and nonce account.
|
|
408
|
+
*/
|
|
409
|
+
export async function createNonceAccountTX(
|
|
410
|
+
connection: Connection,
|
|
411
|
+
auth: PublicKey,
|
|
412
|
+
lamportsForRent?: number
|
|
413
|
+
): Promise<{ tx: Transaction; nonceAccount: Keypair }> {
|
|
414
|
+
const nonceAccount = Keypair.generate()
|
|
415
|
+
|
|
416
|
+
const lamports = lamportsForRent ?? (await connection.getMinimumBalanceForRentExemption(NONCE_ACCOUNT_LENGTH))
|
|
417
|
+
|
|
418
|
+
const tx = new Transaction()
|
|
419
|
+
tx.add(
|
|
420
|
+
// create nonce account
|
|
421
|
+
SystemProgram.createAccount({
|
|
422
|
+
fromPubkey: auth,
|
|
423
|
+
newAccountPubkey: nonceAccount.publicKey,
|
|
424
|
+
lamports,
|
|
425
|
+
space: NONCE_ACCOUNT_LENGTH,
|
|
426
|
+
programId: SystemProgram.programId,
|
|
427
|
+
}),
|
|
428
|
+
// init nonce account
|
|
429
|
+
SystemProgram.nonceInitialize({
|
|
430
|
+
noncePubkey: nonceAccount.publicKey, // nonce account pubkey
|
|
431
|
+
authorizedPubkey: auth, // nonce account auth
|
|
432
|
+
})
|
|
433
|
+
)
|
|
434
|
+
return { tx, nonceAccount }
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Creates a transaction with a nonce.
|
|
439
|
+
*
|
|
440
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
441
|
+
* @param {PublicKey} noncePubkey - The nonce public key.
|
|
442
|
+
* @param {TransactionInstruction[]} instructions - The transaction instructions.
|
|
443
|
+
* @param {NonceAccount} [nonceInfo] - The nonce account information.
|
|
444
|
+
* @returns {Promise<Transaction | null>} A promise that resolves to the transaction or null if not found.
|
|
445
|
+
*/
|
|
446
|
+
export async function txWithNonce(
|
|
447
|
+
connection: Connection,
|
|
448
|
+
noncePubkey: PublicKey,
|
|
449
|
+
instructions: TransactionInstruction[],
|
|
450
|
+
nonceInfo?: NonceAccount
|
|
451
|
+
): Promise<Transaction | null> {
|
|
452
|
+
const tx = new Transaction()
|
|
453
|
+
|
|
454
|
+
if (!nonceInfo) {
|
|
455
|
+
const accountInfo = await connection.getAccountInfo(noncePubkey)
|
|
456
|
+
if (accountInfo) {
|
|
457
|
+
nonceInfo = NonceAccount.fromAccountData(accountInfo.data)
|
|
458
|
+
} else {
|
|
459
|
+
return null
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
tx.add(
|
|
464
|
+
// nonce advance must be the first insturction
|
|
465
|
+
SystemProgram.nonceAdvance({
|
|
466
|
+
noncePubkey: noncePubkey,
|
|
467
|
+
authorizedPubkey: nonceInfo.authorizedPubkey,
|
|
468
|
+
})
|
|
469
|
+
)
|
|
470
|
+
tx.add(...instructions)
|
|
471
|
+
tx.recentBlockhash = nonceInfo.nonce
|
|
472
|
+
return tx
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Checks if an account is initialized.
|
|
477
|
+
*
|
|
478
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
479
|
+
* @param {PublicKey} account - The account public key.
|
|
480
|
+
* @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
|
|
481
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the account is initialized, false otherwise.
|
|
482
|
+
*/
|
|
483
|
+
export async function isAccountInitialized(
|
|
484
|
+
connection: Connection,
|
|
485
|
+
account: PublicKey,
|
|
486
|
+
commitmentOrConfig?: Commitment | GetAccountInfoConfig
|
|
487
|
+
): Promise<boolean> {
|
|
488
|
+
return connection.getAccountInfo(account, commitmentOrConfig).then((res) => {
|
|
489
|
+
return res !== null
|
|
490
|
+
})
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Builds a version 0 message.
|
|
495
|
+
*
|
|
496
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
497
|
+
* @param {PublicKey} payerKey - The payer public key.
|
|
498
|
+
* @param {TransactionInstruction[]} instructions - The transaction instructions.
|
|
499
|
+
* @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
|
|
500
|
+
* @param {Blockhash} [blockhash] - The blockhash.
|
|
501
|
+
* @returns {Promise<MessageV0>} A promise that resolves to the version 0 message.
|
|
502
|
+
*/
|
|
503
|
+
export async function buildMessageV0(
|
|
504
|
+
connection: Connection,
|
|
505
|
+
payerKey: PublicKey,
|
|
506
|
+
instructions: TransactionInstruction[],
|
|
507
|
+
commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed',
|
|
508
|
+
blockhash?: Blockhash
|
|
509
|
+
): Promise<MessageV0> {
|
|
510
|
+
return new TransactionMessage({
|
|
511
|
+
payerKey: payerKey,
|
|
512
|
+
recentBlockhash: blockhash ?? (await connection.getLatestBlockhash(commitmentOrConfig)).blockhash,
|
|
513
|
+
instructions: instructions,
|
|
514
|
+
}).compileToV0Message()
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Builds a versioned transaction.
|
|
519
|
+
*
|
|
520
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
521
|
+
* @param {PublicKey} payerKey - The payer public key.
|
|
522
|
+
* @param {TransactionInstruction[]} instructions - The transaction instructions.
|
|
523
|
+
* @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
|
|
524
|
+
* @param {Blockhash} [blockhash] - The blockhash.
|
|
525
|
+
* @param {PublicKey} [lookupTableAddress] - The lookup table address.
|
|
526
|
+
* @returns {Promise<VersionedTransaction>} A promise that resolves to the versioned transaction.
|
|
527
|
+
*/
|
|
528
|
+
export async function buildVersionedTransaction(
|
|
529
|
+
connection: Connection,
|
|
530
|
+
payerKey: PublicKey,
|
|
531
|
+
instructions: TransactionInstruction[],
|
|
532
|
+
commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed',
|
|
533
|
+
blockhash?: Blockhash,
|
|
534
|
+
lookupTableAddress?: PublicKey
|
|
535
|
+
): Promise<VersionedTransaction> {
|
|
536
|
+
if (lookupTableAddress) {
|
|
537
|
+
return txWithAddressLookupTable(connection, payerKey, instructions, blockhash, lookupTableAddress)
|
|
538
|
+
}
|
|
539
|
+
return new VersionedTransaction(
|
|
540
|
+
await buildMessageV0(connection, payerKey, instructions, commitmentOrConfig, blockhash)
|
|
541
|
+
)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Generates an instruction discriminator.
|
|
546
|
+
*
|
|
547
|
+
* @param {string} method - The method name.
|
|
548
|
+
* @returns {Buffer} The instruction discriminator.
|
|
549
|
+
*/
|
|
550
|
+
export function instructionDiscriminator(method: string): Buffer {
|
|
551
|
+
return Buffer.from(sha2_256(Buffer.from(`global:${method}`))).subarray(0, 8)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Simulates a transaction.
|
|
556
|
+
*
|
|
557
|
+
* @param {Connection} connection - The connection to the Solana cluster.
|
|
558
|
+
* @param {TransactionInstruction[]} instructions - The transaction instructions.
|
|
559
|
+
* @param {PublicKey} programId - The program public key.
|
|
560
|
+
* @param {PublicKey} payer - The payer public key.
|
|
561
|
+
* @param {Commitment} [commitment='confirmed'] - The commitment level.
|
|
562
|
+
* @param {Blockhash} [blockhash] - The blockhash.
|
|
563
|
+
* @param {PublicKey} [lookupTableAddress] - The lookup table address.
|
|
564
|
+
* @returns {Promise<Buffer>} A promise that resolves to the simulation result.
|
|
565
|
+
* @throws {Error} If the simulation fails.
|
|
566
|
+
*/
|
|
567
|
+
export async function simulateTransaction(
|
|
568
|
+
connection: Connection,
|
|
569
|
+
instructions: TransactionInstruction[],
|
|
570
|
+
programId: PublicKey,
|
|
571
|
+
payer: PublicKey,
|
|
572
|
+
commitment: Commitment = 'confirmed',
|
|
573
|
+
blockhash?: Blockhash,
|
|
574
|
+
lookupTableAddress?: PublicKey
|
|
575
|
+
): Promise<Buffer> {
|
|
576
|
+
const tx = await buildVersionedTransaction(
|
|
577
|
+
connection,
|
|
578
|
+
payer,
|
|
579
|
+
instructions,
|
|
580
|
+
commitment,
|
|
581
|
+
blockhash,
|
|
582
|
+
lookupTableAddress
|
|
583
|
+
)
|
|
584
|
+
const simulateResp = await connection.simulateTransaction(tx, { sigVerify: false, commitment })
|
|
585
|
+
const returnPrefix = `Program return: ${programId.toBase58()} `
|
|
586
|
+
const returnLog = simulateResp.value.logs?.find((l) => l.startsWith(returnPrefix))
|
|
587
|
+
if (returnLog === undefined || simulateResp.value.returnData?.programId !== programId.toBase58()) {
|
|
588
|
+
throw new Error(`Simulate Fail: ${JSON.stringify(simulateResp)}`)
|
|
589
|
+
} else {
|
|
590
|
+
return Buffer.from(returnLog.slice(returnPrefix.length), 'base64')
|
|
591
|
+
}
|
|
592
|
+
}
|