@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
@@ -1,3 +1,3 @@
1
- export * from './mailer-client.js';
1
+ export { MailerClient } from './mailer-client.js';
2
2
  export * from './types.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/solana/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/solana/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAIb,MAAM,oBAAoB,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAY;IAClC,OAAO,CAAC,UAAU,CAAS;gBAGzB,UAAU,EA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AAG,SAAS,EACtB,SAAS,EAAE,MAAM,EACjB,sBAAsB,GAAE,OAAe,EACvC,mBAAmB,GAAE,OAAe,EACpC,cAAc,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwDlE;;;;OAIG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2BtG;;;;OAIG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAcxG;;;;OAIG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAcjH;;;;;OAKG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,CAAC,EAAE,cAAc,EACxB,cAAc,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwClE;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAKnC;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAelC;;;;;OAKG;YACW,eAAe;IAoC7B;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;CAiB9C"}
@@ -1,4 +1,4 @@
1
- import { PublicKey, Transaction, TransactionInstruction, SystemProgram, } from '@solana/web3.js';
1
+ import { PublicKey, Transaction, TransactionInstruction, SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js';
2
2
  import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, } from '@solana/spl-token';
3
3
  /**
4
4
  * Native Solana Program instruction data structures
@@ -287,6 +287,7 @@ var InstructionType;
287
287
  */
288
288
  export class MailerClient {
289
289
  constructor(connection, wallet, programId, usdcMint) {
290
+ this.defaultComputeUnitMultiplier = 1.2; // 20% buffer by default
290
291
  this.connection = connection;
291
292
  this.wallet = wallet;
292
293
  this.programId = programId;
@@ -296,10 +297,69 @@ export class MailerClient {
296
297
  this.mailerStatePda = mailerPda;
297
298
  this.mailerBump = bump;
298
299
  }
300
+ /**
301
+ * Optimize compute units for a transaction
302
+ * @param transaction Transaction to optimize
303
+ * @param options Compute unit options
304
+ * @returns Optimized transaction with compute budget instructions
305
+ */
306
+ async optimizeComputeUnits(transaction, options) {
307
+ // Skip if explicitly disabled
308
+ if (options?.skipComputeUnits) {
309
+ return { transaction };
310
+ }
311
+ let simulatedUnits;
312
+ let computeUnitLimit = options?.computeUnitLimit;
313
+ // Auto-optimize by simulating transaction
314
+ if (options?.autoOptimize && !computeUnitLimit) {
315
+ try {
316
+ // Set a high limit for simulation
317
+ const simTransaction = new Transaction().add(...transaction.instructions);
318
+ simTransaction.add(ComputeBudgetProgram.setComputeUnitLimit({
319
+ units: 1400000, // Max for simulation
320
+ }));
321
+ simTransaction.recentBlockhash = (await this.connection.getLatestBlockhash()).blockhash;
322
+ simTransaction.feePayer = this.wallet.publicKey;
323
+ const simulation = await this.connection.simulateTransaction(simTransaction);
324
+ if (simulation.value.err === null && simulation.value.unitsConsumed) {
325
+ simulatedUnits = simulation.value.unitsConsumed;
326
+ const multiplier = options.computeUnitMultiplier ?? this.defaultComputeUnitMultiplier;
327
+ computeUnitLimit = Math.min(Math.ceil(simulatedUnits * multiplier), 1400000 // Max compute units
328
+ );
329
+ }
330
+ }
331
+ catch (error) {
332
+ console.warn('Failed to simulate transaction for compute unit optimization:', error);
333
+ // Fall back to default or specified limit
334
+ computeUnitLimit = computeUnitLimit ?? 200000;
335
+ }
336
+ }
337
+ // Create new transaction with compute budget instructions prepended
338
+ const optimizedTx = new Transaction();
339
+ // Add compute unit limit if specified or auto-optimized
340
+ if (computeUnitLimit) {
341
+ optimizedTx.add(ComputeBudgetProgram.setComputeUnitLimit({
342
+ units: computeUnitLimit,
343
+ }));
344
+ }
345
+ // Add priority fee if specified
346
+ if (options?.computeUnitPrice) {
347
+ optimizedTx.add(ComputeBudgetProgram.setComputeUnitPrice({
348
+ microLamports: options.computeUnitPrice,
349
+ }));
350
+ }
351
+ // Add original instructions
352
+ optimizedTx.add(...transaction.instructions);
353
+ return {
354
+ transaction: optimizedTx,
355
+ simulatedUnits,
356
+ };
357
+ }
299
358
  /**
300
359
  * Initialize the mailer program (owner only)
360
+ * @param computeOptions Compute unit optimization options
301
361
  */
302
- async initialize() {
362
+ async initialize(computeOptions) {
303
363
  const instruction = new TransactionInstruction({
304
364
  keys: [
305
365
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -310,7 +370,7 @@ export class MailerClient {
310
370
  data: encodeInitialize(this.usdcMint),
311
371
  });
312
372
  const transaction = new Transaction().add(instruction);
313
- return await this.sendTransaction(transaction);
373
+ return await this.sendTransaction(transaction, undefined, computeOptions);
314
374
  }
315
375
  /**
316
376
  * Send a message with optional revenue sharing
@@ -319,9 +379,10 @@ export class MailerClient {
319
379
  * @param body Message body
320
380
  * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
321
381
  * @param resolveSenderToName If true, resolve sender address to name via off-chain service
322
- * @returns Transaction signature
382
+ * @param computeOptions Compute unit optimization options
383
+ * @returns Transaction result with signature and compute details
323
384
  */
324
- async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false) {
385
+ async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
325
386
  const recipientKey = typeof to === 'string' ? new PublicKey(to) : to;
326
387
  // Derive recipient claim PDA
327
388
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
@@ -351,13 +412,13 @@ export class MailerClient {
351
412
  });
352
413
  instructions.push(sendInstruction);
353
414
  const transaction = new Transaction().add(...instructions);
354
- return await this.sendTransaction(transaction);
415
+ return await this.sendTransaction(transaction, undefined, computeOptions);
355
416
  }
356
417
  /**
357
418
  * Claim recipient share of revenue
358
- * @returns Transaction signature
419
+ * @returns Transaction result
359
420
  */
360
- async claimRecipientShare() {
421
+ async claimRecipientShare(computeOptions) {
361
422
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), this.wallet.publicKey.toBuffer()], this.programId);
362
423
  const recipientTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
363
424
  const mailerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.mailerStatePda, true);
@@ -374,13 +435,13 @@ export class MailerClient {
374
435
  data: encodeSimpleInstruction(InstructionType.ClaimRecipientShare),
375
436
  });
376
437
  const transaction = new Transaction().add(instruction);
377
- return await this.sendTransaction(transaction);
438
+ return await this.sendTransaction(transaction, undefined, computeOptions);
378
439
  }
379
440
  /**
380
441
  * Claim owner share of fees (owner only)
381
- * @returns Transaction signature
442
+ * @returns Transaction result
382
443
  */
383
- async claimOwnerShare() {
444
+ async claimOwnerShare(computeOptions) {
384
445
  const ownerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
385
446
  const mailerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.mailerStatePda, true);
386
447
  const instruction = new TransactionInstruction({
@@ -395,7 +456,7 @@ export class MailerClient {
395
456
  data: encodeSimpleInstruction(InstructionType.ClaimOwnerShare),
396
457
  });
397
458
  const transaction = new Transaction().add(instruction);
398
- return await this.sendTransaction(transaction);
459
+ return await this.sendTransaction(transaction, undefined, computeOptions);
399
460
  }
400
461
  /**
401
462
  * Claim expired recipient shares and move them under owner control
@@ -403,7 +464,7 @@ export class MailerClient {
403
464
  * @param options Transaction confirm options
404
465
  * @returns Transaction signature
405
466
  */
406
- async claimExpiredShares(recipient, options) {
467
+ async claimExpiredShares(recipient, options, computeOptions) {
407
468
  const recipientKey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
408
469
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
409
470
  const instruction = new TransactionInstruction({
@@ -416,14 +477,14 @@ export class MailerClient {
416
477
  data: encodeClaimExpiredShares(recipientKey),
417
478
  });
418
479
  const transaction = new Transaction().add(instruction);
419
- return await this.sendTransaction(transaction, options);
480
+ return await this.sendTransaction(transaction, options, computeOptions);
420
481
  }
421
482
  /**
422
483
  * Delegate message handling to another address
423
484
  * @param delegate Address to delegate to, or null to clear delegation
424
485
  * @returns Transaction signature
425
486
  */
426
- async delegateTo(delegate) {
487
+ async delegateTo(delegate, computeOptions) {
427
488
  const delegateKey = delegate
428
489
  ? typeof delegate === 'string'
429
490
  ? new PublicKey(delegate)
@@ -446,14 +507,14 @@ export class MailerClient {
446
507
  data: encodeDelegateTo(delegateKey),
447
508
  });
448
509
  const transaction = new Transaction().add(instruction);
449
- return await this.sendTransaction(transaction);
510
+ return await this.sendTransaction(transaction, undefined, computeOptions);
450
511
  }
451
512
  /**
452
513
  * Reject a delegation made to you
453
514
  * @param delegator Address that delegated to you
454
515
  * @returns Transaction signature
455
516
  */
456
- async rejectDelegation(delegator) {
517
+ async rejectDelegation(delegator, computeOptions) {
457
518
  const delegatorKey = typeof delegator === 'string' ? new PublicKey(delegator) : delegator;
458
519
  const [delegationPda] = PublicKey.findProgramAddressSync([Buffer.from('delegation'), delegatorKey.toBuffer()], this.programId);
459
520
  const instruction = new TransactionInstruction({
@@ -466,14 +527,15 @@ export class MailerClient {
466
527
  data: encodeSimpleInstruction(InstructionType.RejectDelegation),
467
528
  });
468
529
  const transaction = new Transaction().add(instruction);
469
- return await this.sendTransaction(transaction);
530
+ return await this.sendTransaction(transaction, undefined, computeOptions);
470
531
  }
471
532
  /**
472
533
  * Set the send fee (owner only)
473
534
  * @param newFee New fee in USDC micro-units (6 decimals)
474
- * @returns Transaction signature
535
+ * @param computeOptions Compute unit optimization options
536
+ * @returns Transaction result
475
537
  */
476
- async setFee(newFee) {
538
+ async setFee(newFee, computeOptions) {
477
539
  const instruction = new TransactionInstruction({
478
540
  keys: [
479
541
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -483,14 +545,14 @@ export class MailerClient {
483
545
  data: encodeSetFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
484
546
  });
485
547
  const transaction = new Transaction().add(instruction);
486
- return await this.sendTransaction(transaction);
548
+ return await this.sendTransaction(transaction, undefined, computeOptions);
487
549
  }
488
550
  /**
489
551
  * Set the delegation fee (owner only)
490
552
  * @param newFee New delegation fee in USDC micro-units (6 decimals)
491
553
  * @returns Transaction signature
492
554
  */
493
- async setDelegationFee(newFee) {
555
+ async setDelegationFee(newFee, computeOptions) {
494
556
  const instruction = new TransactionInstruction({
495
557
  keys: [
496
558
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -500,9 +562,9 @@ export class MailerClient {
500
562
  data: encodeSetDelegationFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
501
563
  });
502
564
  const transaction = new Transaction().add(instruction);
503
- return await this.sendTransaction(transaction);
565
+ return await this.sendTransaction(transaction, undefined, computeOptions);
504
566
  }
505
- async setCustomFeePercentage(account, percentage, payer) {
567
+ async setCustomFeePercentage(account, percentage, payer, computeOptions) {
506
568
  const normalizedPercentage = Math.trunc(percentage);
507
569
  if (normalizedPercentage < 0 || normalizedPercentage > 100) {
508
570
  throw new Error('Percentage must be between 0 and 100');
@@ -527,9 +589,9 @@ export class MailerClient {
527
589
  data: encodeSetCustomFeePercentage(accountKey, normalizedPercentage),
528
590
  });
529
591
  const transaction = new Transaction().add(instruction);
530
- return this.sendTransaction(transaction);
592
+ return this.sendTransaction(transaction, undefined, computeOptions);
531
593
  }
532
- async clearCustomFeePercentage(account) {
594
+ async clearCustomFeePercentage(account, computeOptions) {
533
595
  const accountKey = typeof account === 'string' ? new PublicKey(account) : account;
534
596
  const [discountPda] = PublicKey.findProgramAddressSync([Buffer.from('discount'), accountKey.toBuffer()], this.programId);
535
597
  const instruction = new TransactionInstruction({
@@ -542,7 +604,7 @@ export class MailerClient {
542
604
  data: encodeClearCustomFeePercentage(accountKey),
543
605
  });
544
606
  const transaction = new Transaction().add(instruction);
545
- return this.sendTransaction(transaction);
607
+ return this.sendTransaction(transaction, undefined, computeOptions);
546
608
  }
547
609
  async getCustomFeePercentage(account) {
548
610
  const accountKey = typeof account === 'string' ? new PublicKey(account) : account;
@@ -640,7 +702,7 @@ export class MailerClient {
640
702
  * @param options Transaction confirm options
641
703
  * @returns Transaction signature
642
704
  */
643
- async sendToEmail(toEmail, subject, body, options) {
705
+ async sendToEmail(toEmail, subject, body, options, computeOptions) {
644
706
  // Get associated token accounts
645
707
  const senderTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
646
708
  const mailerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.mailerStatePda, true);
@@ -666,7 +728,7 @@ export class MailerClient {
666
728
  data: instructionData,
667
729
  }));
668
730
  const transaction = new Transaction().add(...instructions);
669
- return this.sendTransaction(transaction, options);
731
+ return this.sendTransaction(transaction, options, computeOptions);
670
732
  }
671
733
  /**
672
734
  * Send a prepared message to an email address (no wallet known)
@@ -676,7 +738,7 @@ export class MailerClient {
676
738
  * @param options Transaction confirm options
677
739
  * @returns Transaction signature
678
740
  */
679
- async sendPreparedToEmail(toEmail, mailId, options) {
741
+ async sendPreparedToEmail(toEmail, mailId, options, computeOptions) {
680
742
  // Get associated token accounts
681
743
  const senderTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
682
744
  const mailerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.mailerStatePda, true);
@@ -702,7 +764,7 @@ export class MailerClient {
702
764
  data: instructionData,
703
765
  }));
704
766
  const transaction = new Transaction().add(...instructions);
705
- return this.sendTransaction(transaction, options);
767
+ return this.sendTransaction(transaction, options, computeOptions);
706
768
  }
707
769
  /**
708
770
  * Send a prepared message using a mailId (to match EVM behavior)
@@ -712,7 +774,7 @@ export class MailerClient {
712
774
  * @param resolveSenderToName If true, resolve sender address to name
713
775
  * @returns Transaction signature
714
776
  */
715
- async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false) {
777
+ async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
716
778
  const recipientKey = typeof to === 'string' ? new PublicKey(to) : to;
717
779
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
718
780
  const senderTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
@@ -737,9 +799,9 @@ export class MailerClient {
737
799
  });
738
800
  instructions.push(sendInstruction);
739
801
  const transaction = new Transaction().add(...instructions);
740
- return this.sendTransaction(transaction);
802
+ return this.sendTransaction(transaction, undefined, computeOptions);
741
803
  }
742
- async sendThroughWebhook(to, webhookId, revenueShareToReceiver = false, resolveSenderToName = false) {
804
+ async sendThroughWebhook(to, webhookId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
743
805
  const recipientKey = typeof to === 'string' ? new PublicKey(to) : to;
744
806
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
745
807
  const senderTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
@@ -764,14 +826,14 @@ export class MailerClient {
764
826
  });
765
827
  instructions.push(sendInstruction);
766
828
  const transaction = new Transaction().add(...instructions);
767
- return this.sendTransaction(transaction);
829
+ return this.sendTransaction(transaction, undefined, computeOptions);
768
830
  }
769
831
  /**
770
832
  * Pause the contract and distribute owner claimable funds (owner only)
771
833
  * @param options Transaction confirm options
772
834
  * @returns Transaction signature
773
835
  */
774
- async pause(options) {
836
+ async pause(options, computeOptions) {
775
837
  const ownerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.wallet.publicKey);
776
838
  const mailerTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, this.mailerStatePda, true);
777
839
  const instruction = new TransactionInstruction({
@@ -786,14 +848,14 @@ export class MailerClient {
786
848
  data: encodeSimpleInstruction(InstructionType.Pause),
787
849
  });
788
850
  const transaction = new Transaction().add(instruction);
789
- return await this.sendTransaction(transaction, options);
851
+ return await this.sendTransaction(transaction, options, computeOptions);
790
852
  }
791
853
  /**
792
854
  * Unpause the contract (owner only)
793
855
  * @param options Transaction confirm options
794
856
  * @returns Transaction signature
795
857
  */
796
- async unpause(options) {
858
+ async unpause(options, computeOptions) {
797
859
  const instruction = new TransactionInstruction({
798
860
  keys: [
799
861
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -803,14 +865,14 @@ export class MailerClient {
803
865
  data: encodeSimpleInstruction(InstructionType.Unpause),
804
866
  });
805
867
  const transaction = new Transaction().add(instruction);
806
- return await this.sendTransaction(transaction, options);
868
+ return await this.sendTransaction(transaction, options, computeOptions);
807
869
  }
808
870
  /**
809
871
  * Emergency unpause without fund distribution (owner only)
810
872
  * @param options Transaction confirm options
811
873
  * @returns Transaction signature
812
874
  */
813
- async emergencyUnpause(options) {
875
+ async emergencyUnpause(options, computeOptions) {
814
876
  const instruction = new TransactionInstruction({
815
877
  keys: [
816
878
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -820,7 +882,7 @@ export class MailerClient {
820
882
  data: encodeSimpleInstruction(InstructionType.EmergencyUnpause),
821
883
  });
822
884
  const transaction = new Transaction().add(instruction);
823
- return await this.sendTransaction(transaction, options);
885
+ return await this.sendTransaction(transaction, options, computeOptions);
824
886
  }
825
887
  /**
826
888
  * Distribute claimable funds to a recipient when contract is paused
@@ -828,7 +890,7 @@ export class MailerClient {
828
890
  * @param options Transaction confirm options
829
891
  * @returns Transaction signature
830
892
  */
831
- async distributeClaimableFunds(recipient, options) {
893
+ async distributeClaimableFunds(recipient, options, computeOptions) {
832
894
  const recipientKey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
833
895
  const [recipientClaimPda] = PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
834
896
  const recipientTokenAccount = getAssociatedTokenAddressSync(this.usdcMint, recipientKey);
@@ -850,7 +912,7 @@ export class MailerClient {
850
912
  data,
851
913
  });
852
914
  const transaction = new Transaction().add(instruction);
853
- return await this.sendTransaction(transaction, options);
915
+ return await this.sendTransaction(transaction, options, computeOptions);
854
916
  }
855
917
  /**
856
918
  * Get the current send fee
@@ -879,17 +941,24 @@ export class MailerClient {
879
941
  * @param options Confirm options
880
942
  * @returns Transaction signature
881
943
  */
882
- async sendTransaction(transaction, options) {
944
+ async sendTransaction(transaction, options, computeOptions) {
945
+ // Optimize compute units if requested
946
+ const { transaction: optimizedTx, simulatedUnits } = await this.optimizeComputeUnits(transaction, computeOptions);
883
947
  // Get recent blockhash
884
948
  const { blockhash } = await this.connection.getLatestBlockhash();
885
- transaction.recentBlockhash = blockhash;
886
- transaction.feePayer = this.wallet.publicKey;
949
+ optimizedTx.recentBlockhash = blockhash;
950
+ optimizedTx.feePayer = this.wallet.publicKey;
887
951
  // Sign transaction
888
- const signedTx = await this.wallet.signTransaction(transaction);
952
+ const signedTx = await this.wallet.signTransaction(optimizedTx);
889
953
  // Send and confirm
890
954
  const signature = await this.connection.sendRawTransaction(signedTx.serialize());
891
955
  await this.connection.confirmTransaction(signature, options?.commitment || 'confirmed');
892
- return signature;
956
+ return {
957
+ signature,
958
+ simulatedUnits,
959
+ computeUnitLimit: computeOptions?.computeUnitLimit,
960
+ computeUnitPrice: computeOptions?.computeUnitPrice,
961
+ };
893
962
  }
894
963
  /**
895
964
  * Create a simple wallet from a keypair for testing