@tetherto/wdk-wallet-solana-gasless 1.0.0-beta.2 → 1.0.0-beta.4

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/index.js CHANGED
@@ -15,10 +15,15 @@
15
15
 
16
16
  /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
17
17
  /** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
18
+ /** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
19
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
20
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
21
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
18
22
  /** @typedef {import('@tetherto/wdk-wallet-solana').TransferOptions} TransferOptions */
19
23
  /** @typedef {import('@tetherto/wdk-wallet-solana').TransferResult} TransferResult */
20
24
  /** @typedef {import('./src/wallet-account-solana-gasless.js').FullySignedTransaction} FullySignedTransaction */
21
25
  /** @typedef {import('./src/wallet-account-read-only-solana-gasless.js').SolanaTransactionReceipt} SolanaTransactionReceipt */
26
+ /** @typedef {import('@tetherto/wdk-wallet-solana').SolanaTransactionDetails} SolanaTransactionDetails */
22
27
  /** @typedef {import('./src/wallet-account-read-only-solana-gasless.js').SolanaTransaction} SolanaTransaction */
23
28
  /** @typedef {import('./src/wallet-account-read-only-solana-gasless.js').PaymasterTokenConfig} PaymasterTokenConfig */
24
29
  /** @typedef {import('./src/wallet-account-read-only-solana-gasless.js').SolanaGaslessWalletPaymasterConfig} SolanaGaslessWalletPaymasterConfig */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-solana-gasless",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "A simple package to manage BIP-32 wallets for the solana blockchain, which implement the gasless functionality.",
5
5
  "keywords": [
6
6
  "wdk",
@@ -39,8 +39,8 @@
39
39
  "@solana/transaction-messages": "3.0.3",
40
40
  "@solana/transactions": "3.0.3",
41
41
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
42
- "@tetherto/wdk-wallet": "1.0.0-beta.12",
43
- "@tetherto/wdk-wallet-solana": "1.0.0-beta.9",
42
+ "@tetherto/wdk-wallet": "1.0.0-beta.17",
43
+ "@tetherto/wdk-wallet-solana": "1.0.0-beta.13",
44
44
  "bare-node-runtime": "1.3.1"
45
45
  },
46
46
  "devDependencies": {
@@ -25,12 +25,14 @@ import { appendTransactionMessageInstruction, appendTransactionMessageInstructio
25
25
  import { KoraClient } from '@solana/kora'
26
26
  import { compileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions'
27
27
  import { findAssociatedTokenPda, getCreateAssociatedTokenIdempotentInstruction, getTransferInstruction, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token'
28
- import { AccountRole, blockhash, createNoopSigner, pipe } from '@solana/kit'
28
+ import { AccountRole, blockhash, createNoopSigner, getU64Decoder, pipe } from '@solana/kit'
29
29
  import { getTransferSolInstruction } from '@solana-program/system'
30
30
 
31
31
  import { ConfigurationError } from './errors.js'
32
32
 
33
33
  /** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
34
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
35
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
34
36
 
35
37
  /** @typedef {import('@solana/transaction-messages').TransactionMessage} TransactionMessage */
36
38
  /** @typedef {ReturnType<typeof import('@solana/rpc').createSolanaRpc>} SolanaRpc */
@@ -43,6 +45,7 @@ import { ConfigurationError } from './errors.js'
43
45
  /** @typedef {import('@tetherto/wdk-wallet-solana').SolanaWalletConfig} SolanaWalletConfig */
44
46
  /** @typedef {import('@tetherto/wdk-wallet-solana').TransferOptions} TransferOptions */
45
47
  /** @typedef {import('@tetherto/wdk-wallet-solana').TransferResult} TransferResult */
48
+ /** @typedef {import('@tetherto/wdk-wallet-solana').SolanaTransactionDetails} SolanaTransactionDetails */
46
49
 
47
50
  /**
48
51
  * @typedef {Object} PaymasterTokenConfig
@@ -202,6 +205,7 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
202
205
  /**
203
206
  * Retrieves a transaction receipt by its signature
204
207
  *
208
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw transaction remains available on its `transaction` property.
205
209
  * @param {string} hash - The transaction's hash.
206
210
  * @returns {Promise<SolanaTransactionReceipt | null>} — The receipt, or null if the transaction has not been included in a block yet.
207
211
  */
@@ -209,6 +213,35 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
209
213
  return await this._solanaReadOnlyAccount.getTransactionReceipt(hash)
210
214
  }
211
215
 
216
+ /**
217
+ * Returns a normalized, finality-based receipt for a transaction.
218
+ *
219
+ * @param {string} hash - The transaction's signature.
220
+ * @returns {Promise<TransactionReceipt & SolanaTransactionDetails>} The normalized receipt.
221
+ * @throws {ValueError} If the hash is not a valid signature.
222
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
223
+ */
224
+ async getTransaction (hash) {
225
+ return await this._solanaReadOnlyAccount.getTransaction(hash)
226
+ }
227
+
228
+ /**
229
+ * Blocks until a transaction reaches the requested finality target, or times out.
230
+ *
231
+ * Note: Solana RPC does not expose a `dropped` state. An evicted or never-landed
232
+ * signature simply reports no status, which is indistinguishable from a not-yet-seen
233
+ * transaction and is treated as still-pending. A dropped transaction therefore surfaces
234
+ * as a {@link TimeoutError} rather than resolving to a `dropped` receipt.
235
+ *
236
+ * @param {string} hash - The transaction's signature.
237
+ * @param {WaitForTransactionOptions} [options] - The wait options.
238
+ * @returns {Promise<TransactionReceipt & SolanaTransactionDetails>} The terminal receipt for the finality target reached (inspect `success` to tell success from revert).
239
+ * @throws {TimeoutError} If the target is not reached before the timeout.
240
+ */
241
+ async waitForTransaction (hash, options = {}) {
242
+ return await super.waitForTransaction(hash, options)
243
+ }
244
+
212
245
  /**
213
246
  * Verifies a message's signature.
214
247
  *
@@ -446,6 +479,7 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
446
479
  * @param {TransactionMessage} transactionMessage - The transaction message to fetch the payment info.
447
480
  * @param {SolanaGaslessWalletPaymasterConfigOverrides} [config] - If set, overrides the given configuration options.
448
481
  * @returns {Promise<GetPaymentInstructionResponse>} The payment info.
482
+ * @throws {Error} If the paymaster payment instruction is not a recognized SPL transfer to the paymaster token account.
449
483
  */
450
484
  async _getTransactionPaymentInfo (transactionMessage, config = {}) {
451
485
  const mergedConfig = { ...this._config, ...config }
@@ -470,6 +504,60 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
470
504
  })
471
505
  }
472
506
 
473
- return { ...payment, payment_instruction: upgradedPaymentInstruction }
507
+ const paymasterTokenAccount = await this._getPaymasterAssociatedTokenAccount(mergedConfig.paymasterToken.address)
508
+ const paymentAmount = this._getPaymentInstructionAmount(upgradedPaymentInstruction, paymasterTokenAccount)
509
+
510
+ return {
511
+ ...payment,
512
+ payment_amount: Number(paymentAmount),
513
+ payment_instruction: upgradedPaymentInstruction
514
+ }
515
+ }
516
+
517
+ /**
518
+ * @protected
519
+ * @param {string} [paymasterTokenAddress] - The paymaster fee token mint.
520
+ * @returns {Promise<string>} The paymaster's associated token account for that mint.
521
+ */
522
+ async _getPaymasterAssociatedTokenAccount (paymasterTokenAddress = this._config.paymasterToken.address) {
523
+ const [paymasterTokenAccount] = await findAssociatedTokenPda({
524
+ mint: address(paymasterTokenAddress),
525
+ owner: address(this._config.paymasterAddress),
526
+ tokenProgram: TOKEN_PROGRAM_ADDRESS
527
+ })
528
+
529
+ return paymasterTokenAccount
530
+ }
531
+
532
+ /**
533
+ * @protected
534
+ * @param {object} instruction - A candidate SPL token instruction.
535
+ * @param {string} paymasterTokenAccount - The paymaster associated token account.
536
+ * @returns {boolean} True if the instruction is an SPL transfer whose destination is the paymaster token account.
537
+ */
538
+ _isPaymentInstruction (instruction, paymasterTokenAccount) {
539
+ const discriminator = instruction.data?.[0]
540
+ if (instruction.programAddress !== TOKEN_PROGRAM_ADDRESS || (discriminator !== 3 && discriminator !== 12)) {
541
+ return false
542
+ }
543
+
544
+ const destinationIndex = discriminator === 12 ? 2 : 1
545
+
546
+ return instruction.accounts?.[destinationIndex]?.address === paymasterTokenAccount
547
+ }
548
+
549
+ /**
550
+ * @protected
551
+ * @param {object} paymentInstruction - The paymaster payment instruction.
552
+ * @param {string} paymasterTokenAccount - The paymaster associated token account.
553
+ * @returns {bigint} The transfer amount encoded in the instruction.
554
+ * @throws {Error} If the instruction is not a recognized SPL transfer to the paymaster token account.
555
+ */
556
+ _getPaymentInstructionAmount (paymentInstruction, paymasterTokenAccount) {
557
+ if (!this._isPaymentInstruction(paymentInstruction, paymasterTokenAccount)) {
558
+ throw new Error('Invalid payment instruction from paymaster.')
559
+ }
560
+
561
+ return BigInt(getU64Decoder().decode(paymentInstruction.data, 1))
474
562
  }
475
563
  }
@@ -20,8 +20,7 @@ import { createKeyPairSignerFromPrivateKeyBytes, partiallySignTransactionMessage
20
20
  import { assertIsFullySignedTransaction, getBase64EncodedWireTransaction, getTransactionDecoder } from '@solana/transactions'
21
21
  import { appendTransactionMessageInstruction, setTransactionMessageFeePayer } from '@solana/transaction-messages'
22
22
  import { address } from '@solana/addresses'
23
- import { AccountRole, decompileTransactionMessageFetchingLookupTables, getBase64Encoder, getCompiledTransactionMessageDecoder, getU64Decoder, pipe } from '@solana/kit'
24
- import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token'
23
+ import { AccountRole, decompileTransactionMessageFetchingLookupTables, getBase64Encoder, getCompiledTransactionMessageDecoder, pipe } from '@solana/kit'
25
24
 
26
25
  import WalletAccountReadOnlySolanaGasless from './wallet-account-read-only-solana-gasless.js'
27
26
 
@@ -333,22 +332,14 @@ export default class WalletAccountSolanaGasless extends WalletAccountReadOnlySol
333
332
 
334
333
  const { instructions } = await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, this._rpc)
335
334
 
336
- const [paymasterTokenAccount] = await findAssociatedTokenPda({
337
- mint: address(this._config.paymasterToken.address),
338
- owner: address(this._config.paymasterAddress),
339
- tokenProgram: TOKEN_PROGRAM_ADDRESS
340
- })
341
-
342
- const paymentInstruction = instructions.find((instruction) => {
343
- const discriminator = instruction.data?.[0]
344
- const isTokenTransfer = instruction.programAddress === TOKEN_PROGRAM_ADDRESS && (discriminator === 3 || discriminator === 12)
345
-
346
- return isTokenTransfer && instruction.accounts?.some((account) => account.address === paymasterTokenAccount)
347
- })
335
+ const paymasterTokenAccount = await this._getPaymasterAssociatedTokenAccount()
348
336
 
349
- const paymentAmount = paymentInstruction && getU64Decoder().decode(paymentInstruction.data, 1)
337
+ const paymentInstruction = instructions.find((instruction) =>
338
+ this._isPaymentInstruction(instruction, paymasterTokenAccount))
350
339
 
351
- return BigInt(paymentAmount || 0n)
340
+ return paymentInstruction
341
+ ? this._getPaymentInstructionAmount(paymentInstruction, paymasterTokenAccount)
342
+ : 0n
352
343
  }
353
344
 
354
345
  /**
package/types/index.d.ts CHANGED
@@ -3,11 +3,16 @@ export { default as WalletAccountReadOnlySolanaGasless } from "./src/wallet-acco
3
3
  export { default as WalletAccountSolanaGasless } from "./src/wallet-account-solana-gasless.js";
4
4
  export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
5
5
  export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
6
+ export type Finality = import("@tetherto/wdk-wallet").Finality;
7
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
8
+ export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
9
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
6
10
  export type TransferOptions = import("@tetherto/wdk-wallet-solana").TransferOptions;
7
11
  export type TransferResult = import("@tetherto/wdk-wallet-solana").TransferResult;
8
12
  export { ConfigurationError } from "./src/errors.js";
9
13
  export type FullySignedTransaction = import("./src/wallet-account-solana-gasless.js").FullySignedTransaction;
10
14
  export type SolanaTransactionReceipt = import("./src/wallet-account-read-only-solana-gasless.js").SolanaTransactionReceipt;
15
+ export type SolanaTransactionDetails = import("@tetherto/wdk-wallet-solana").SolanaTransactionDetails;
11
16
  export type SolanaTransaction = import("./src/wallet-account-read-only-solana-gasless.js").SolanaTransaction;
12
17
  export type PaymasterTokenConfig = import("./src/wallet-account-read-only-solana-gasless.js").PaymasterTokenConfig;
13
18
  export type SolanaGaslessWalletPaymasterConfig = import("./src/wallet-account-read-only-solana-gasless.js").SolanaGaslessWalletPaymasterConfig;
@@ -83,10 +83,34 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
83
83
  /**
84
84
  * Retrieves a transaction receipt by its signature
85
85
  *
86
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw transaction remains available on its `transaction` property.
86
87
  * @param {string} hash - The transaction's hash.
87
88
  * @returns {Promise<SolanaTransactionReceipt | null>} — The receipt, or null if the transaction has not been included in a block yet.
88
89
  */
89
90
  getTransactionReceipt(hash: string): Promise<SolanaTransactionReceipt | null>;
91
+ /**
92
+ * Returns a normalized, finality-based receipt for a transaction.
93
+ *
94
+ * @param {string} hash - The transaction's signature.
95
+ * @returns {Promise<TransactionReceipt & SolanaTransactionDetails>} The normalized receipt.
96
+ * @throws {ValueError} If the hash is not a valid signature.
97
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
98
+ */
99
+ getTransaction(hash: string): Promise<TransactionReceipt & SolanaTransactionDetails>;
100
+ /**
101
+ * Blocks until a transaction reaches the requested finality target, or times out.
102
+ *
103
+ * Note: Solana RPC does not expose a `dropped` state. An evicted or never-landed
104
+ * signature simply reports no status, which is indistinguishable from a not-yet-seen
105
+ * transaction and is treated as still-pending. A dropped transaction therefore surfaces
106
+ * as a {@link TimeoutError} rather than resolving to a `dropped` receipt.
107
+ *
108
+ * @param {string} hash - The transaction's signature.
109
+ * @param {WaitForTransactionOptions} [options] - The wait options.
110
+ * @returns {Promise<TransactionReceipt & SolanaTransactionDetails>} The terminal receipt for the finality target reached (inspect `success` to tell success from revert).
111
+ * @throws {TimeoutError} If the target is not reached before the timeout.
112
+ */
113
+ waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt & SolanaTransactionDetails>;
90
114
  /**
91
115
  * Verifies a message's signature.
92
116
  *
@@ -161,10 +185,34 @@ export default class WalletAccountReadOnlySolanaGasless extends WalletAccountRea
161
185
  * @param {TransactionMessage} transactionMessage - The transaction message to fetch the payment info.
162
186
  * @param {SolanaGaslessWalletPaymasterConfigOverrides} [config] - If set, overrides the given configuration options.
163
187
  * @returns {Promise<GetPaymentInstructionResponse>} The payment info.
188
+ * @throws {Error} If the paymaster payment instruction is not a recognized SPL transfer to the paymaster token account.
164
189
  */
165
190
  protected _getTransactionPaymentInfo(transactionMessage: TransactionMessage, config?: SolanaGaslessWalletPaymasterConfigOverrides): Promise<GetPaymentInstructionResponse>;
191
+ /**
192
+ * @protected
193
+ * @param {string} [paymasterTokenAddress] - The paymaster fee token mint.
194
+ * @returns {Promise<string>} The paymaster's associated token account for that mint.
195
+ */
196
+ protected _getPaymasterAssociatedTokenAccount(paymasterTokenAddress?: string): Promise<string>;
197
+ /**
198
+ * @protected
199
+ * @param {object} instruction - A candidate SPL token instruction.
200
+ * @param {string} paymasterTokenAccount - The paymaster associated token account.
201
+ * @returns {boolean} True if the instruction is an SPL transfer whose destination is the paymaster token account.
202
+ */
203
+ protected _isPaymentInstruction(instruction: object, paymasterTokenAccount: string): boolean;
204
+ /**
205
+ * @protected
206
+ * @param {object} paymentInstruction - The paymaster payment instruction.
207
+ * @param {string} paymasterTokenAccount - The paymaster associated token account.
208
+ * @returns {bigint} The transfer amount encoded in the instruction.
209
+ * @throws {Error} If the instruction is not a recognized SPL transfer to the paymaster token account.
210
+ */
211
+ protected _getPaymentInstructionAmount(paymentInstruction: object, paymasterTokenAccount: string): bigint;
166
212
  }
167
213
  export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
214
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
215
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
168
216
  export type TransactionMessage = import("@solana/transaction-messages").TransactionMessage;
169
217
  export type SolanaRpc = ReturnType<typeof import("@solana/rpc").createSolanaRpc>;
170
218
  export type SolanaTransactionReceipt = ReturnType<import("@solana/rpc-api").SolanaRpcApi["getTransaction"]>;
@@ -176,6 +224,7 @@ export type SolanaWalletConfig = import("@tetherto/wdk-wallet-solana").SolanaWal
176
224
  export type TransferOptions = import("@tetherto/wdk-wallet-solana").TransferOptions;
177
225
  export type TransferResult = import("@tetherto/wdk-wallet-solana").TransferResult;
178
226
  import { ConfigurationError } from './errors.js';
227
+ export type SolanaTransactionDetails = import("@tetherto/wdk-wallet-solana").SolanaTransactionDetails;
179
228
  export type PaymasterTokenConfig = {
180
229
  /**
181
230
  * - The address of the paymaster token.