@sudobility/contracts 1.11.2 → 1.12.0

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.
Files changed (49) hide show
  1. package/dist/evm/src/evm/index.d.ts +1 -1
  2. package/dist/evm/src/evm/index.d.ts.map +1 -1
  3. package/dist/evm/src/evm/index.js +1 -1
  4. package/dist/evm/src/evm/index.js.map +1 -1
  5. package/dist/evm/src/evm/mailer-client.d.ts +79 -23
  6. package/dist/evm/src/evm/mailer-client.d.ts.map +1 -1
  7. package/dist/evm/src/evm/mailer-client.js +314 -44
  8. package/dist/evm/src/evm/mailer-client.js.map +1 -1
  9. package/dist/solana/solana/index.d.ts +1 -1
  10. package/dist/solana/solana/index.d.ts.map +1 -1
  11. package/dist/solana/solana/index.js +3 -1
  12. package/dist/solana/solana/index.js.map +1 -1
  13. package/dist/solana/solana/mailer-client.d.ts +85 -23
  14. package/dist/solana/solana/mailer-client.d.ts.map +1 -1
  15. package/dist/solana/solana/mailer-client.js +116 -47
  16. package/dist/solana/solana/mailer-client.js.map +1 -1
  17. package/dist/unified/src/evm/index.d.ts +1 -1
  18. package/dist/unified/src/evm/index.d.ts.map +1 -1
  19. package/dist/unified/src/evm/index.js +1 -1
  20. package/dist/unified/src/evm/index.js.map +1 -1
  21. package/dist/unified/src/evm/mailer-client.d.ts +79 -23
  22. package/dist/unified/src/evm/mailer-client.d.ts.map +1 -1
  23. package/dist/unified/src/evm/mailer-client.js +314 -44
  24. package/dist/unified/src/evm/mailer-client.js.map +1 -1
  25. package/dist/unified/src/solana/index.d.ts +1 -1
  26. package/dist/unified/src/solana/index.d.ts.map +1 -1
  27. package/dist/unified/src/solana/index.js +3 -1
  28. package/dist/unified/src/solana/index.js.map +1 -1
  29. package/dist/unified/src/solana/mailer-client.d.ts +85 -23
  30. package/dist/unified/src/solana/mailer-client.d.ts.map +1 -1
  31. package/dist/unified/src/solana/mailer-client.js +116 -47
  32. package/dist/unified/src/solana/mailer-client.js.map +1 -1
  33. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  34. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  35. package/dist/unified-esm/src/evm/index.js +1 -1
  36. package/dist/unified-esm/src/evm/index.js.map +1 -1
  37. package/dist/unified-esm/src/evm/mailer-client.d.ts +79 -23
  38. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +1 -1
  39. package/dist/unified-esm/src/evm/mailer-client.js +315 -45
  40. package/dist/unified-esm/src/evm/mailer-client.js.map +1 -1
  41. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  42. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  43. package/dist/unified-esm/src/solana/index.js +1 -1
  44. package/dist/unified-esm/src/solana/index.js.map +1 -1
  45. package/dist/unified-esm/src/solana/mailer-client.d.ts +85 -23
  46. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +1 -1
  47. package/dist/unified-esm/src/solana/mailer-client.js +117 -48
  48. package/dist/unified-esm/src/solana/mailer-client.js.map +1 -1
  49. package/package.json +1 -1
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mailer-client.js"), exports);
17
+ exports.MailerClient = void 0;
18
+ var mailer_client_js_1 = require("./mailer-client.js");
19
+ Object.defineProperty(exports, "MailerClient", { enumerable: true, get: function () { return mailer_client_js_1.MailerClient; } });
18
20
  __exportStar(require("./types.js"), exports);
19
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/solana/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/solana/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAK4B;AAJ1B,gHAAA,YAAY,OAAA;AAKd,6CAA2B"}
@@ -9,6 +9,57 @@ export interface Wallet {
9
9
  signTransaction<T extends Transaction>(transaction: T): Promise<T>;
10
10
  signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]>;
11
11
  }
12
+ /**
13
+ * Compute unit optimization options for Solana transactions
14
+ */
15
+ export interface ComputeUnitOptions {
16
+ /**
17
+ * Compute unit limit for the transaction (default: 200,000)
18
+ * Max: 1,400,000
19
+ */
20
+ computeUnitLimit?: number;
21
+ /**
22
+ * Priority fee in micro-lamports per compute unit
23
+ * Higher values = faster inclusion during congestion
24
+ */
25
+ computeUnitPrice?: number;
26
+ /**
27
+ * Automatically simulate and optimize compute units
28
+ * @default false
29
+ */
30
+ autoOptimize?: boolean;
31
+ /**
32
+ * Multiplier for compute unit buffer when auto-optimizing
33
+ * @default 1.2 (20% buffer)
34
+ */
35
+ computeUnitMultiplier?: number;
36
+ /**
37
+ * Skip compute unit settings entirely
38
+ * @default false
39
+ */
40
+ skipComputeUnits?: boolean;
41
+ }
42
+ /**
43
+ * Transaction result with compute unit details
44
+ */
45
+ export interface TransactionResult {
46
+ /**
47
+ * Transaction signature
48
+ */
49
+ signature: string;
50
+ /**
51
+ * Simulated compute units (if auto-optimized)
52
+ */
53
+ simulatedUnits?: number;
54
+ /**
55
+ * Actual compute unit limit set
56
+ */
57
+ computeUnitLimit?: number;
58
+ /**
59
+ * Priority fee per compute unit (if set)
60
+ */
61
+ computeUnitPrice?: number;
62
+ }
12
63
  /**
13
64
  * @class MailerClient
14
65
  * @description Native Solana program client for the Mailer program
@@ -50,11 +101,20 @@ export declare class MailerClient {
50
101
  private usdcMint;
51
102
  private mailerStatePda;
52
103
  private mailerBump;
104
+ private defaultComputeUnitMultiplier;
53
105
  constructor(connection: Connection, wallet: Wallet, programId: PublicKey, usdcMint: PublicKey);
106
+ /**
107
+ * Optimize compute units for a transaction
108
+ * @param transaction Transaction to optimize
109
+ * @param options Compute unit options
110
+ * @returns Optimized transaction with compute budget instructions
111
+ */
112
+ private optimizeComputeUnits;
54
113
  /**
55
114
  * Initialize the mailer program (owner only)
115
+ * @param computeOptions Compute unit optimization options
56
116
  */
57
- initialize(): Promise<string>;
117
+ initialize(computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
58
118
  /**
59
119
  * Send a message with optional revenue sharing
60
120
  * @param to Recipient's public key or address string who receives message and potential revenue share
@@ -62,52 +122,54 @@ export declare class MailerClient {
62
122
  * @param body Message body
63
123
  * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
64
124
  * @param resolveSenderToName If true, resolve sender address to name via off-chain service
65
- * @returns Transaction signature
125
+ * @param computeOptions Compute unit optimization options
126
+ * @returns Transaction result with signature and compute details
66
127
  */
67
- send(to: string | PublicKey, subject: string, body: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean): Promise<string>;
128
+ send(to: string | PublicKey, subject: string, body: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
68
129
  /**
69
130
  * Claim recipient share of revenue
70
- * @returns Transaction signature
131
+ * @returns Transaction result
71
132
  */
72
- claimRecipientShare(): Promise<string>;
133
+ claimRecipientShare(computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
73
134
  /**
74
135
  * Claim owner share of fees (owner only)
75
- * @returns Transaction signature
136
+ * @returns Transaction result
76
137
  */
77
- claimOwnerShare(): Promise<string>;
138
+ claimOwnerShare(computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
78
139
  /**
79
140
  * Claim expired recipient shares and move them under owner control
80
141
  * @param recipient Recipient whose expired shares to reclaim
81
142
  * @param options Transaction confirm options
82
143
  * @returns Transaction signature
83
144
  */
84
- claimExpiredShares(recipient: string | PublicKey, options?: ConfirmOptions): Promise<string>;
145
+ claimExpiredShares(recipient: string | PublicKey, options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
85
146
  /**
86
147
  * Delegate message handling to another address
87
148
  * @param delegate Address to delegate to, or null to clear delegation
88
149
  * @returns Transaction signature
89
150
  */
90
- delegateTo(delegate?: Optional<string | PublicKey>): Promise<string>;
151
+ delegateTo(delegate?: Optional<string | PublicKey>, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
91
152
  /**
92
153
  * Reject a delegation made to you
93
154
  * @param delegator Address that delegated to you
94
155
  * @returns Transaction signature
95
156
  */
96
- rejectDelegation(delegator: string | PublicKey): Promise<string>;
157
+ rejectDelegation(delegator: string | PublicKey, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
97
158
  /**
98
159
  * Set the send fee (owner only)
99
160
  * @param newFee New fee in USDC micro-units (6 decimals)
100
- * @returns Transaction signature
161
+ * @param computeOptions Compute unit optimization options
162
+ * @returns Transaction result
101
163
  */
102
- setFee(newFee: number | bigint): Promise<string>;
164
+ setFee(newFee: number | bigint, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
103
165
  /**
104
166
  * Set the delegation fee (owner only)
105
167
  * @param newFee New delegation fee in USDC micro-units (6 decimals)
106
168
  * @returns Transaction signature
107
169
  */
108
- setDelegationFee(newFee: number | bigint): Promise<string>;
109
- setCustomFeePercentage(account: string | PublicKey, percentage: number, payer?: Optional<string | PublicKey>): Promise<string>;
110
- clearCustomFeePercentage(account: string | PublicKey): Promise<string>;
170
+ setDelegationFee(newFee: number | bigint, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
171
+ setCustomFeePercentage(account: string | PublicKey, percentage: number, payer?: Optional<string | PublicKey>, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
172
+ clearCustomFeePercentage(account: string | PublicKey, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
111
173
  getCustomFeePercentage(account: string | PublicKey): Promise<number>;
112
174
  /**
113
175
  * Get current fees from the mailer state
@@ -148,7 +210,7 @@ export declare class MailerClient {
148
210
  * @param options Transaction confirm options
149
211
  * @returns Transaction signature
150
212
  */
151
- sendToEmail(toEmail: string, subject: string, body: string, options?: ConfirmOptions): Promise<string>;
213
+ sendToEmail(toEmail: string, subject: string, body: string, options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
152
214
  /**
153
215
  * Send a prepared message to an email address (no wallet known)
154
216
  * Charges only 10% owner fee since recipient wallet is unknown
@@ -157,7 +219,7 @@ export declare class MailerClient {
157
219
  * @param options Transaction confirm options
158
220
  * @returns Transaction signature
159
221
  */
160
- sendPreparedToEmail(toEmail: string, mailId: string, options?: ConfirmOptions): Promise<string>;
222
+ sendPreparedToEmail(toEmail: string, mailId: string, options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
161
223
  /**
162
224
  * Send a prepared message using a mailId (to match EVM behavior)
163
225
  * @param to Recipient's public key or address string
@@ -166,33 +228,33 @@ export declare class MailerClient {
166
228
  * @param resolveSenderToName If true, resolve sender address to name
167
229
  * @returns Transaction signature
168
230
  */
169
- sendPrepared(to: string | PublicKey, mailId: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean): Promise<string>;
170
- sendThroughWebhook(to: string | PublicKey, webhookId: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean): Promise<string>;
231
+ sendPrepared(to: string | PublicKey, mailId: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
232
+ sendThroughWebhook(to: string | PublicKey, webhookId: string, revenueShareToReceiver?: boolean, resolveSenderToName?: boolean, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
171
233
  /**
172
234
  * Pause the contract and distribute owner claimable funds (owner only)
173
235
  * @param options Transaction confirm options
174
236
  * @returns Transaction signature
175
237
  */
176
- pause(options?: ConfirmOptions): Promise<string>;
238
+ pause(options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
177
239
  /**
178
240
  * Unpause the contract (owner only)
179
241
  * @param options Transaction confirm options
180
242
  * @returns Transaction signature
181
243
  */
182
- unpause(options?: ConfirmOptions): Promise<string>;
244
+ unpause(options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
183
245
  /**
184
246
  * Emergency unpause without fund distribution (owner only)
185
247
  * @param options Transaction confirm options
186
248
  * @returns Transaction signature
187
249
  */
188
- emergencyUnpause(options?: ConfirmOptions): Promise<string>;
250
+ emergencyUnpause(options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
189
251
  /**
190
252
  * Distribute claimable funds to a recipient when contract is paused
191
253
  * @param recipient Recipient address to distribute funds for
192
254
  * @param options Transaction confirm options
193
255
  * @returns Transaction signature
194
256
  */
195
- distributeClaimableFunds(recipient: string | PublicKey, options?: ConfirmOptions): Promise<string>;
257
+ distributeClaimableFunds(recipient: string | PublicKey, options?: ConfirmOptions, computeOptions?: ComputeUnitOptions): Promise<TransactionResult>;
196
258
  /**
197
259
  * Get the current send fee
198
260
  * @returns Send fee in USDC micro-units (6 decimals)
@@ -1 +1 @@
1
- {"version":3,"file":"mailer-client.d.ts","sourceRoot":"","sources":["../../../src/solana/mailer-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EAEX,OAAO,EAEP,cAAc,EACf,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnE,mBAAmB,CAAC,CAAC,SAAS,WAAW,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAC7E;AA2WD;;;;;;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292
292
  constructor(connection, wallet, programId, usdcMint) {
293
+ this.defaultComputeUnitMultiplier = 1.2; // 20% buffer by default
293
294
  this.connection = connection;
294
295
  this.wallet = wallet;
295
296
  this.programId = programId;
@@ -299,10 +300,69 @@ class MailerClient {
299
300
  this.mailerStatePda = mailerPda;
300
301
  this.mailerBump = bump;
301
302
  }
303
+ /**
304
+ * Optimize compute units for a transaction
305
+ * @param transaction Transaction to optimize
306
+ * @param options Compute unit options
307
+ * @returns Optimized transaction with compute budget instructions
308
+ */
309
+ async optimizeComputeUnits(transaction, options) {
310
+ // Skip if explicitly disabled
311
+ if (options?.skipComputeUnits) {
312
+ return { transaction };
313
+ }
314
+ let simulatedUnits;
315
+ let computeUnitLimit = options?.computeUnitLimit;
316
+ // Auto-optimize by simulating transaction
317
+ if (options?.autoOptimize && !computeUnitLimit) {
318
+ try {
319
+ // Set a high limit for simulation
320
+ const simTransaction = new web3_js_1.Transaction().add(...transaction.instructions);
321
+ simTransaction.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
322
+ units: 1400000, // Max for simulation
323
+ }));
324
+ simTransaction.recentBlockhash = (await this.connection.getLatestBlockhash()).blockhash;
325
+ simTransaction.feePayer = this.wallet.publicKey;
326
+ const simulation = await this.connection.simulateTransaction(simTransaction);
327
+ if (simulation.value.err === null && simulation.value.unitsConsumed) {
328
+ simulatedUnits = simulation.value.unitsConsumed;
329
+ const multiplier = options.computeUnitMultiplier ?? this.defaultComputeUnitMultiplier;
330
+ computeUnitLimit = Math.min(Math.ceil(simulatedUnits * multiplier), 1400000 // Max compute units
331
+ );
332
+ }
333
+ }
334
+ catch (error) {
335
+ console.warn('Failed to simulate transaction for compute unit optimization:', error);
336
+ // Fall back to default or specified limit
337
+ computeUnitLimit = computeUnitLimit ?? 200000;
338
+ }
339
+ }
340
+ // Create new transaction with compute budget instructions prepended
341
+ const optimizedTx = new web3_js_1.Transaction();
342
+ // Add compute unit limit if specified or auto-optimized
343
+ if (computeUnitLimit) {
344
+ optimizedTx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
345
+ units: computeUnitLimit,
346
+ }));
347
+ }
348
+ // Add priority fee if specified
349
+ if (options?.computeUnitPrice) {
350
+ optimizedTx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
351
+ microLamports: options.computeUnitPrice,
352
+ }));
353
+ }
354
+ // Add original instructions
355
+ optimizedTx.add(...transaction.instructions);
356
+ return {
357
+ transaction: optimizedTx,
358
+ simulatedUnits,
359
+ };
360
+ }
302
361
  /**
303
362
  * Initialize the mailer program (owner only)
363
+ * @param computeOptions Compute unit optimization options
304
364
  */
305
- async initialize() {
365
+ async initialize(computeOptions) {
306
366
  const instruction = new web3_js_1.TransactionInstruction({
307
367
  keys: [
308
368
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -313,7 +373,7 @@ class MailerClient {
313
373
  data: encodeInitialize(this.usdcMint),
314
374
  });
315
375
  const transaction = new web3_js_1.Transaction().add(instruction);
316
- return await this.sendTransaction(transaction);
376
+ return await this.sendTransaction(transaction, undefined, computeOptions);
317
377
  }
318
378
  /**
319
379
  * Send a message with optional revenue sharing
@@ -322,9 +382,10 @@ class MailerClient {
322
382
  * @param body Message body
323
383
  * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
324
384
  * @param resolveSenderToName If true, resolve sender address to name via off-chain service
325
- * @returns Transaction signature
385
+ * @param computeOptions Compute unit optimization options
386
+ * @returns Transaction result with signature and compute details
326
387
  */
327
- async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false) {
388
+ async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
328
389
  const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
329
390
  // Derive recipient claim PDA
330
391
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
@@ -354,13 +415,13 @@ class MailerClient {
354
415
  });
355
416
  instructions.push(sendInstruction);
356
417
  const transaction = new web3_js_1.Transaction().add(...instructions);
357
- return await this.sendTransaction(transaction);
418
+ return await this.sendTransaction(transaction, undefined, computeOptions);
358
419
  }
359
420
  /**
360
421
  * Claim recipient share of revenue
361
- * @returns Transaction signature
422
+ * @returns Transaction result
362
423
  */
363
- async claimRecipientShare() {
424
+ async claimRecipientShare(computeOptions) {
364
425
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), this.wallet.publicKey.toBuffer()], this.programId);
365
426
  const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
366
427
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -377,13 +438,13 @@ class MailerClient {
377
438
  data: encodeSimpleInstruction(InstructionType.ClaimRecipientShare),
378
439
  });
379
440
  const transaction = new web3_js_1.Transaction().add(instruction);
380
- return await this.sendTransaction(transaction);
441
+ return await this.sendTransaction(transaction, undefined, computeOptions);
381
442
  }
382
443
  /**
383
444
  * Claim owner share of fees (owner only)
384
- * @returns Transaction signature
445
+ * @returns Transaction result
385
446
  */
386
- async claimOwnerShare() {
447
+ async claimOwnerShare(computeOptions) {
387
448
  const ownerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
388
449
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
389
450
  const instruction = new web3_js_1.TransactionInstruction({
@@ -398,7 +459,7 @@ class MailerClient {
398
459
  data: encodeSimpleInstruction(InstructionType.ClaimOwnerShare),
399
460
  });
400
461
  const transaction = new web3_js_1.Transaction().add(instruction);
401
- return await this.sendTransaction(transaction);
462
+ return await this.sendTransaction(transaction, undefined, computeOptions);
402
463
  }
403
464
  /**
404
465
  * Claim expired recipient shares and move them under owner control
@@ -406,7 +467,7 @@ class MailerClient {
406
467
  * @param options Transaction confirm options
407
468
  * @returns Transaction signature
408
469
  */
409
- async claimExpiredShares(recipient, options) {
470
+ async claimExpiredShares(recipient, options, computeOptions) {
410
471
  const recipientKey = typeof recipient === 'string' ? new web3_js_1.PublicKey(recipient) : recipient;
411
472
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
412
473
  const instruction = new web3_js_1.TransactionInstruction({
@@ -419,14 +480,14 @@ class MailerClient {
419
480
  data: encodeClaimExpiredShares(recipientKey),
420
481
  });
421
482
  const transaction = new web3_js_1.Transaction().add(instruction);
422
- return await this.sendTransaction(transaction, options);
483
+ return await this.sendTransaction(transaction, options, computeOptions);
423
484
  }
424
485
  /**
425
486
  * Delegate message handling to another address
426
487
  * @param delegate Address to delegate to, or null to clear delegation
427
488
  * @returns Transaction signature
428
489
  */
429
- async delegateTo(delegate) {
490
+ async delegateTo(delegate, computeOptions) {
430
491
  const delegateKey = delegate
431
492
  ? typeof delegate === 'string'
432
493
  ? new web3_js_1.PublicKey(delegate)
@@ -449,14 +510,14 @@ class MailerClient {
449
510
  data: encodeDelegateTo(delegateKey),
450
511
  });
451
512
  const transaction = new web3_js_1.Transaction().add(instruction);
452
- return await this.sendTransaction(transaction);
513
+ return await this.sendTransaction(transaction, undefined, computeOptions);
453
514
  }
454
515
  /**
455
516
  * Reject a delegation made to you
456
517
  * @param delegator Address that delegated to you
457
518
  * @returns Transaction signature
458
519
  */
459
- async rejectDelegation(delegator) {
520
+ async rejectDelegation(delegator, computeOptions) {
460
521
  const delegatorKey = typeof delegator === 'string' ? new web3_js_1.PublicKey(delegator) : delegator;
461
522
  const [delegationPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('delegation'), delegatorKey.toBuffer()], this.programId);
462
523
  const instruction = new web3_js_1.TransactionInstruction({
@@ -469,14 +530,15 @@ class MailerClient {
469
530
  data: encodeSimpleInstruction(InstructionType.RejectDelegation),
470
531
  });
471
532
  const transaction = new web3_js_1.Transaction().add(instruction);
472
- return await this.sendTransaction(transaction);
533
+ return await this.sendTransaction(transaction, undefined, computeOptions);
473
534
  }
474
535
  /**
475
536
  * Set the send fee (owner only)
476
537
  * @param newFee New fee in USDC micro-units (6 decimals)
477
- * @returns Transaction signature
538
+ * @param computeOptions Compute unit optimization options
539
+ * @returns Transaction result
478
540
  */
479
- async setFee(newFee) {
541
+ async setFee(newFee, computeOptions) {
480
542
  const instruction = new web3_js_1.TransactionInstruction({
481
543
  keys: [
482
544
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -486,14 +548,14 @@ class MailerClient {
486
548
  data: encodeSetFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
487
549
  });
488
550
  const transaction = new web3_js_1.Transaction().add(instruction);
489
- return await this.sendTransaction(transaction);
551
+ return await this.sendTransaction(transaction, undefined, computeOptions);
490
552
  }
491
553
  /**
492
554
  * Set the delegation fee (owner only)
493
555
  * @param newFee New delegation fee in USDC micro-units (6 decimals)
494
556
  * @returns Transaction signature
495
557
  */
496
- async setDelegationFee(newFee) {
558
+ async setDelegationFee(newFee, computeOptions) {
497
559
  const instruction = new web3_js_1.TransactionInstruction({
498
560
  keys: [
499
561
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -503,9 +565,9 @@ class MailerClient {
503
565
  data: encodeSetDelegationFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
504
566
  });
505
567
  const transaction = new web3_js_1.Transaction().add(instruction);
506
- return await this.sendTransaction(transaction);
568
+ return await this.sendTransaction(transaction, undefined, computeOptions);
507
569
  }
508
- async setCustomFeePercentage(account, percentage, payer) {
570
+ async setCustomFeePercentage(account, percentage, payer, computeOptions) {
509
571
  const normalizedPercentage = Math.trunc(percentage);
510
572
  if (normalizedPercentage < 0 || normalizedPercentage > 100) {
511
573
  throw new Error('Percentage must be between 0 and 100');
@@ -530,9 +592,9 @@ class MailerClient {
530
592
  data: encodeSetCustomFeePercentage(accountKey, normalizedPercentage),
531
593
  });
532
594
  const transaction = new web3_js_1.Transaction().add(instruction);
533
- return this.sendTransaction(transaction);
595
+ return this.sendTransaction(transaction, undefined, computeOptions);
534
596
  }
535
- async clearCustomFeePercentage(account) {
597
+ async clearCustomFeePercentage(account, computeOptions) {
536
598
  const accountKey = typeof account === 'string' ? new web3_js_1.PublicKey(account) : account;
537
599
  const [discountPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('discount'), accountKey.toBuffer()], this.programId);
538
600
  const instruction = new web3_js_1.TransactionInstruction({
@@ -545,7 +607,7 @@ class MailerClient {
545
607
  data: encodeClearCustomFeePercentage(accountKey),
546
608
  });
547
609
  const transaction = new web3_js_1.Transaction().add(instruction);
548
- return this.sendTransaction(transaction);
610
+ return this.sendTransaction(transaction, undefined, computeOptions);
549
611
  }
550
612
  async getCustomFeePercentage(account) {
551
613
  const accountKey = typeof account === 'string' ? new web3_js_1.PublicKey(account) : account;
@@ -643,7 +705,7 @@ class MailerClient {
643
705
  * @param options Transaction confirm options
644
706
  * @returns Transaction signature
645
707
  */
646
- async sendToEmail(toEmail, subject, body, options) {
708
+ async sendToEmail(toEmail, subject, body, options, computeOptions) {
647
709
  // Get associated token accounts
648
710
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
649
711
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -669,7 +731,7 @@ class MailerClient {
669
731
  data: instructionData,
670
732
  }));
671
733
  const transaction = new web3_js_1.Transaction().add(...instructions);
672
- return this.sendTransaction(transaction, options);
734
+ return this.sendTransaction(transaction, options, computeOptions);
673
735
  }
674
736
  /**
675
737
  * Send a prepared message to an email address (no wallet known)
@@ -679,7 +741,7 @@ class MailerClient {
679
741
  * @param options Transaction confirm options
680
742
  * @returns Transaction signature
681
743
  */
682
- async sendPreparedToEmail(toEmail, mailId, options) {
744
+ async sendPreparedToEmail(toEmail, mailId, options, computeOptions) {
683
745
  // Get associated token accounts
684
746
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
685
747
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -705,7 +767,7 @@ class MailerClient {
705
767
  data: instructionData,
706
768
  }));
707
769
  const transaction = new web3_js_1.Transaction().add(...instructions);
708
- return this.sendTransaction(transaction, options);
770
+ return this.sendTransaction(transaction, options, computeOptions);
709
771
  }
710
772
  /**
711
773
  * Send a prepared message using a mailId (to match EVM behavior)
@@ -715,7 +777,7 @@ class MailerClient {
715
777
  * @param resolveSenderToName If true, resolve sender address to name
716
778
  * @returns Transaction signature
717
779
  */
718
- async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false) {
780
+ async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
719
781
  const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
720
782
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
721
783
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
@@ -740,9 +802,9 @@ class MailerClient {
740
802
  });
741
803
  instructions.push(sendInstruction);
742
804
  const transaction = new web3_js_1.Transaction().add(...instructions);
743
- return this.sendTransaction(transaction);
805
+ return this.sendTransaction(transaction, undefined, computeOptions);
744
806
  }
745
- async sendThroughWebhook(to, webhookId, revenueShareToReceiver = false, resolveSenderToName = false) {
807
+ async sendThroughWebhook(to, webhookId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
746
808
  const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
747
809
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
748
810
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
@@ -767,14 +829,14 @@ class MailerClient {
767
829
  });
768
830
  instructions.push(sendInstruction);
769
831
  const transaction = new web3_js_1.Transaction().add(...instructions);
770
- return this.sendTransaction(transaction);
832
+ return this.sendTransaction(transaction, undefined, computeOptions);
771
833
  }
772
834
  /**
773
835
  * Pause the contract and distribute owner claimable funds (owner only)
774
836
  * @param options Transaction confirm options
775
837
  * @returns Transaction signature
776
838
  */
777
- async pause(options) {
839
+ async pause(options, computeOptions) {
778
840
  const ownerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
779
841
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
780
842
  const instruction = new web3_js_1.TransactionInstruction({
@@ -789,14 +851,14 @@ class MailerClient {
789
851
  data: encodeSimpleInstruction(InstructionType.Pause),
790
852
  });
791
853
  const transaction = new web3_js_1.Transaction().add(instruction);
792
- return await this.sendTransaction(transaction, options);
854
+ return await this.sendTransaction(transaction, options, computeOptions);
793
855
  }
794
856
  /**
795
857
  * Unpause the contract (owner only)
796
858
  * @param options Transaction confirm options
797
859
  * @returns Transaction signature
798
860
  */
799
- async unpause(options) {
861
+ async unpause(options, computeOptions) {
800
862
  const instruction = new web3_js_1.TransactionInstruction({
801
863
  keys: [
802
864
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -806,14 +868,14 @@ class MailerClient {
806
868
  data: encodeSimpleInstruction(InstructionType.Unpause),
807
869
  });
808
870
  const transaction = new web3_js_1.Transaction().add(instruction);
809
- return await this.sendTransaction(transaction, options);
871
+ return await this.sendTransaction(transaction, options, computeOptions);
810
872
  }
811
873
  /**
812
874
  * Emergency unpause without fund distribution (owner only)
813
875
  * @param options Transaction confirm options
814
876
  * @returns Transaction signature
815
877
  */
816
- async emergencyUnpause(options) {
878
+ async emergencyUnpause(options, computeOptions) {
817
879
  const instruction = new web3_js_1.TransactionInstruction({
818
880
  keys: [
819
881
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -823,7 +885,7 @@ class MailerClient {
823
885
  data: encodeSimpleInstruction(InstructionType.EmergencyUnpause),
824
886
  });
825
887
  const transaction = new web3_js_1.Transaction().add(instruction);
826
- return await this.sendTransaction(transaction, options);
888
+ return await this.sendTransaction(transaction, options, computeOptions);
827
889
  }
828
890
  /**
829
891
  * Distribute claimable funds to a recipient when contract is paused
@@ -831,7 +893,7 @@ class MailerClient {
831
893
  * @param options Transaction confirm options
832
894
  * @returns Transaction signature
833
895
  */
834
- async distributeClaimableFunds(recipient, options) {
896
+ async distributeClaimableFunds(recipient, options, computeOptions) {
835
897
  const recipientKey = typeof recipient === 'string' ? new web3_js_1.PublicKey(recipient) : recipient;
836
898
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
837
899
  const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, recipientKey);
@@ -853,7 +915,7 @@ class MailerClient {
853
915
  data,
854
916
  });
855
917
  const transaction = new web3_js_1.Transaction().add(instruction);
856
- return await this.sendTransaction(transaction, options);
918
+ return await this.sendTransaction(transaction, options, computeOptions);
857
919
  }
858
920
  /**
859
921
  * Get the current send fee
@@ -882,17 +944,24 @@ class MailerClient {
882
944
  * @param options Confirm options
883
945
  * @returns Transaction signature
884
946
  */
885
- async sendTransaction(transaction, options) {
947
+ async sendTransaction(transaction, options, computeOptions) {
948
+ // Optimize compute units if requested
949
+ const { transaction: optimizedTx, simulatedUnits } = await this.optimizeComputeUnits(transaction, computeOptions);
886
950
  // Get recent blockhash
887
951
  const { blockhash } = await this.connection.getLatestBlockhash();
888
- transaction.recentBlockhash = blockhash;
889
- transaction.feePayer = this.wallet.publicKey;
952
+ optimizedTx.recentBlockhash = blockhash;
953
+ optimizedTx.feePayer = this.wallet.publicKey;
890
954
  // Sign transaction
891
- const signedTx = await this.wallet.signTransaction(transaction);
955
+ const signedTx = await this.wallet.signTransaction(optimizedTx);
892
956
  // Send and confirm
893
957
  const signature = await this.connection.sendRawTransaction(signedTx.serialize());
894
958
  await this.connection.confirmTransaction(signature, options?.commitment || 'confirmed');
895
- return signature;
959
+ return {
960
+ signature,
961
+ simulatedUnits,
962
+ computeUnitLimit: computeOptions?.computeUnitLimit,
963
+ computeUnitPrice: computeOptions?.computeUnitPrice,
964
+ };
896
965
  }
897
966
  /**
898
967
  * Create a simple wallet from a keypair for testing