@sudobility/contracts 0.14.0 → 1.9.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 (110) hide show
  1. package/README.md +2 -3
  2. package/artifacts/contracts/Mailer.sol/Mailer.dbg.json +1 -1
  3. package/artifacts/contracts/Mailer.sol/Mailer.json +2 -278
  4. package/artifacts/contracts/MockUSDC.sol/MockUSDC.dbg.json +1 -1
  5. package/artifacts/contracts/interfaces/IERC20.sol/IERC20.dbg.json +1 -1
  6. package/dist/evm/src/evm/index.d.ts +1 -1
  7. package/dist/evm/src/evm/index.d.ts.map +1 -1
  8. package/dist/evm/src/evm/index.js +1 -1
  9. package/dist/evm/src/evm/index.js.map +1 -1
  10. package/dist/evm/src/evm/mailer-client.d.ts +180 -936
  11. package/dist/evm/src/evm/mailer-client.d.ts.map +1 -1
  12. package/dist/evm/src/evm/mailer-client.js +249 -451
  13. package/dist/evm/src/evm/mailer-client.js.map +1 -1
  14. package/dist/evm/typechain-types/Mailer.d.ts +10 -177
  15. package/dist/evm/typechain-types/Mailer.d.ts.map +1 -1
  16. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts +1 -216
  17. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  18. package/dist/evm/typechain-types/factories/Mailer__factory.js +1 -277
  19. package/dist/evm/typechain-types/factories/Mailer__factory.js.map +1 -1
  20. package/dist/solana/solana/index.d.ts +1 -1
  21. package/dist/solana/solana/index.d.ts.map +1 -1
  22. package/dist/solana/solana/index.js +1 -3
  23. package/dist/solana/solana/index.js.map +1 -1
  24. package/dist/solana/solana/mailer-client.d.ts +18 -91
  25. package/dist/solana/solana/mailer-client.d.ts.map +1 -1
  26. package/dist/solana/solana/mailer-client.js +55 -316
  27. package/dist/solana/solana/mailer-client.js.map +1 -1
  28. package/dist/unified/src/evm/index.d.ts +1 -1
  29. package/dist/unified/src/evm/index.d.ts.map +1 -1
  30. package/dist/unified/src/evm/index.js +1 -1
  31. package/dist/unified/src/evm/index.js.map +1 -1
  32. package/dist/unified/src/evm/mailer-client.d.ts +180 -936
  33. package/dist/unified/src/evm/mailer-client.d.ts.map +1 -1
  34. package/dist/unified/src/evm/mailer-client.js +249 -451
  35. package/dist/unified/src/evm/mailer-client.js.map +1 -1
  36. package/dist/unified/src/react/hooks/useMailerMutations.d.ts +1 -1
  37. package/dist/unified/src/react/hooks/useMailerMutations.js +1 -1
  38. package/dist/unified/src/solana/index.d.ts +1 -1
  39. package/dist/unified/src/solana/index.d.ts.map +1 -1
  40. package/dist/unified/src/solana/index.js +1 -3
  41. package/dist/unified/src/solana/index.js.map +1 -1
  42. package/dist/unified/src/solana/mailer-client.d.ts +18 -91
  43. package/dist/unified/src/solana/mailer-client.d.ts.map +1 -1
  44. package/dist/unified/src/solana/mailer-client.js +55 -316
  45. package/dist/unified/src/solana/mailer-client.js.map +1 -1
  46. package/dist/unified/src/unified/index.d.ts +1 -1
  47. package/dist/unified/src/unified/index.d.ts.map +1 -1
  48. package/dist/unified/src/unified/onchain-mailer-client.d.ts +251 -111
  49. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  50. package/dist/unified/src/unified/onchain-mailer-client.js +1375 -744
  51. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  52. package/dist/unified/src/unified/types.d.ts +6 -16
  53. package/dist/unified/src/unified/types.d.ts.map +1 -1
  54. package/dist/unified/src/utils/chain-config.d.ts +2 -4
  55. package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
  56. package/dist/unified/src/utils/chain-config.js +36 -46
  57. package/dist/unified/src/utils/chain-config.js.map +1 -1
  58. package/dist/unified/typechain-types/Mailer.d.ts +10 -177
  59. package/dist/unified/typechain-types/Mailer.d.ts.map +1 -1
  60. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts +1 -216
  61. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  62. package/dist/unified/typechain-types/factories/Mailer__factory.js +1 -277
  63. package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
  64. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  65. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  66. package/dist/unified-esm/src/evm/index.js +1 -1
  67. package/dist/unified-esm/src/evm/index.js.map +1 -1
  68. package/dist/unified-esm/src/evm/mailer-client.d.ts +180 -936
  69. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +1 -1
  70. package/dist/unified-esm/src/evm/mailer-client.js +251 -453
  71. package/dist/unified-esm/src/evm/mailer-client.js.map +1 -1
  72. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +1 -1
  73. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +1 -1
  74. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  75. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  76. package/dist/unified-esm/src/solana/index.js +1 -1
  77. package/dist/unified-esm/src/solana/index.js.map +1 -1
  78. package/dist/unified-esm/src/solana/mailer-client.d.ts +18 -91
  79. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +1 -1
  80. package/dist/unified-esm/src/solana/mailer-client.js +56 -317
  81. package/dist/unified-esm/src/solana/mailer-client.js.map +1 -1
  82. package/dist/unified-esm/src/unified/index.d.ts +1 -1
  83. package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
  84. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +251 -111
  85. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  86. package/dist/unified-esm/src/unified/onchain-mailer-client.js +1379 -748
  87. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  88. package/dist/unified-esm/src/unified/types.d.ts +6 -16
  89. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  90. package/dist/unified-esm/src/utils/chain-config.d.ts +2 -4
  91. package/dist/unified-esm/src/utils/chain-config.d.ts.map +1 -1
  92. package/dist/unified-esm/src/utils/chain-config.js +35 -46
  93. package/dist/unified-esm/src/utils/chain-config.js.map +1 -1
  94. package/dist/unified-esm/typechain-types/Mailer.d.ts +10 -177
  95. package/dist/unified-esm/typechain-types/Mailer.d.ts.map +1 -1
  96. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +1 -216
  97. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  98. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +1 -277
  99. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +1 -1
  100. package/package.json +9 -20
  101. package/programs/mailer/src/lib.rs +171 -1026
  102. package/programs/mailer/tests/integration_tests.rs +65 -586
  103. package/typechain-types/Mailer.ts +8 -319
  104. package/typechain-types/factories/Mailer__factory.ts +1 -277
  105. package/artifacts/contracts/Mailer.sol/Mailer.d.ts +0 -1146
  106. package/artifacts/contracts/Mailer.sol/artifacts.d.ts +0 -21
  107. package/artifacts/contracts/MockUSDC.sol/MockUSDC.d.ts +0 -284
  108. package/artifacts/contracts/MockUSDC.sol/artifacts.d.ts +0 -21
  109. package/artifacts/contracts/interfaces/IERC20.sol/IERC20.d.ts +0 -157
  110. package/artifacts/contracts/interfaces/IERC20.sol/artifacts.d.ts +0 -21
@@ -35,23 +35,6 @@ function encodeSend(to, subject, body, revenueShareToReceiver, resolveSenderToNa
35
35
  data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
36
36
  return data;
37
37
  }
38
- function encodeSendPrepared(to, mailId, revenueShareToReceiver, resolveSenderToName = false) {
39
- const mailIdBytes = Buffer.from(mailId, 'utf8');
40
- const data = Buffer.alloc(1 + 32 + 4 + mailIdBytes.length + 1 + 1);
41
- let offset = 0;
42
- data.writeUInt8(InstructionType.SendPrepared, offset);
43
- offset += 1;
44
- to.toBuffer().copy(data, offset);
45
- offset += 32;
46
- data.writeUInt32LE(mailIdBytes.length, offset);
47
- offset += 4;
48
- mailIdBytes.copy(data, offset);
49
- offset += mailIdBytes.length;
50
- data.writeUInt8(revenueShareToReceiver ? 1 : 0, offset);
51
- offset += 1;
52
- data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
53
- return data;
54
- }
55
38
  function encodeSendToEmail(toEmail, subject, body) {
56
39
  const emailBytes = Buffer.from(toEmail, 'utf8');
57
40
  const subjectBytes = Buffer.from(subject, 'utf8');
@@ -89,23 +72,6 @@ function encodeSendPreparedToEmail(toEmail, mailId) {
89
72
  mailIdBytes.copy(data, offset);
90
73
  return data;
91
74
  }
92
- function encodeSendThroughWebhook(to, webhookId, revenueShareToReceiver, resolveSenderToName = false) {
93
- const webhookBytes = Buffer.from(webhookId, 'utf8');
94
- const data = Buffer.alloc(1 + 32 + 4 + webhookBytes.length + 1 + 1);
95
- let offset = 0;
96
- data.writeUInt8(InstructionType.SendThroughWebhook, offset);
97
- offset += 1;
98
- to.toBuffer().copy(data, offset);
99
- offset += 32;
100
- data.writeUInt32LE(webhookBytes.length, offset);
101
- offset += 4;
102
- webhookBytes.copy(data, offset);
103
- offset += webhookBytes.length;
104
- data.writeUInt8(revenueShareToReceiver ? 1 : 0, offset);
105
- offset += 1;
106
- data.writeUInt8(resolveSenderToName ? 1 : 0, offset);
107
- return data;
108
- }
109
75
  function encodeSimpleInstruction(instructionType) {
110
76
  const data = Buffer.alloc(1);
111
77
  data.writeUInt8(instructionType, 0);
@@ -123,19 +89,6 @@ function encodeSetDelegationFee(newFee) {
123
89
  data.writeBigUInt64LE(newFee, 1);
124
90
  return data;
125
91
  }
126
- function encodeSetCustomFeePercentage(account, percentage) {
127
- const data = Buffer.alloc(1 + 32 + 1);
128
- data.writeUInt8(InstructionType.SetCustomFeePercentage, 0);
129
- account.toBuffer().copy(data, 1);
130
- data.writeUInt8(percentage, 33);
131
- return data;
132
- }
133
- function encodeClearCustomFeePercentage(account) {
134
- const data = Buffer.alloc(1 + 32);
135
- data.writeUInt8(InstructionType.ClearCustomFeePercentage, 0);
136
- account.toBuffer().copy(data, 1);
137
- return data;
138
- }
139
92
  function encodeDelegateTo(delegate) {
140
93
  if (!delegate) {
141
94
  // Clear delegation - just send the instruction type and a null option
@@ -153,12 +106,6 @@ function encodeDelegateTo(delegate) {
153
106
  return data;
154
107
  }
155
108
  }
156
- function encodeClaimExpiredShares(recipient) {
157
- const data = Buffer.alloc(1 + 32);
158
- data.writeUInt8(InstructionType.ClaimExpiredShares, 0);
159
- recipient.toBuffer().copy(data, 1);
160
- return data;
161
- }
162
109
  // Account data parsing functions
163
110
  function parseMailerState(data) {
164
111
  let offset = 0;
@@ -219,40 +166,25 @@ function parseDelegation(data) {
219
166
  bump,
220
167
  };
221
168
  }
222
- function parseFeeDiscount(data) {
223
- let offset = 0;
224
- const account = new web3_js_1.PublicKey(data.slice(offset, offset + 32));
225
- offset += 32;
226
- const discount = data.readUInt8(offset);
227
- offset += 1;
228
- const bump = data.readUInt8(offset);
229
- return {
230
- account,
231
- discount,
232
- bump,
233
- };
234
- }
169
+ /**
170
+ * Instruction types for the native Solana program
171
+ */
235
172
  var InstructionType;
236
173
  (function (InstructionType) {
237
174
  InstructionType[InstructionType["Initialize"] = 0] = "Initialize";
238
175
  InstructionType[InstructionType["Send"] = 1] = "Send";
239
- InstructionType[InstructionType["SendPrepared"] = 2] = "SendPrepared";
240
- InstructionType[InstructionType["SendToEmail"] = 3] = "SendToEmail";
241
- InstructionType[InstructionType["SendPreparedToEmail"] = 4] = "SendPreparedToEmail";
242
- InstructionType[InstructionType["SendThroughWebhook"] = 5] = "SendThroughWebhook";
243
- InstructionType[InstructionType["ClaimRecipientShare"] = 6] = "ClaimRecipientShare";
244
- InstructionType[InstructionType["ClaimOwnerShare"] = 7] = "ClaimOwnerShare";
245
- InstructionType[InstructionType["SetFee"] = 8] = "SetFee";
246
- InstructionType[InstructionType["DelegateTo"] = 9] = "DelegateTo";
247
- InstructionType[InstructionType["RejectDelegation"] = 10] = "RejectDelegation";
248
- InstructionType[InstructionType["SetDelegationFee"] = 11] = "SetDelegationFee";
249
- InstructionType[InstructionType["SetCustomFeePercentage"] = 12] = "SetCustomFeePercentage";
250
- InstructionType[InstructionType["ClearCustomFeePercentage"] = 13] = "ClearCustomFeePercentage";
251
- InstructionType[InstructionType["Pause"] = 14] = "Pause";
252
- InstructionType[InstructionType["Unpause"] = 15] = "Unpause";
253
- InstructionType[InstructionType["DistributeClaimableFunds"] = 16] = "DistributeClaimableFunds";
254
- InstructionType[InstructionType["ClaimExpiredShares"] = 17] = "ClaimExpiredShares";
255
- InstructionType[InstructionType["EmergencyUnpause"] = 18] = "EmergencyUnpause";
176
+ InstructionType[InstructionType["SendToEmail"] = 2] = "SendToEmail";
177
+ InstructionType[InstructionType["SendPreparedToEmail"] = 3] = "SendPreparedToEmail";
178
+ InstructionType[InstructionType["ClaimRecipientShare"] = 4] = "ClaimRecipientShare";
179
+ InstructionType[InstructionType["ClaimOwnerShare"] = 5] = "ClaimOwnerShare";
180
+ InstructionType[InstructionType["SetFee"] = 6] = "SetFee";
181
+ InstructionType[InstructionType["DelegateTo"] = 7] = "DelegateTo";
182
+ InstructionType[InstructionType["RejectDelegation"] = 8] = "RejectDelegation";
183
+ InstructionType[InstructionType["SetDelegationFee"] = 9] = "SetDelegationFee";
184
+ InstructionType[InstructionType["Pause"] = 10] = "Pause";
185
+ InstructionType[InstructionType["Unpause"] = 11] = "Unpause";
186
+ InstructionType[InstructionType["DistributeClaimableFunds"] = 12] = "DistributeClaimableFunds";
187
+ InstructionType[InstructionType["EmergencyUnpause"] = 13] = "EmergencyUnpause";
256
188
  })(InstructionType || (InstructionType = {}));
257
189
  /**
258
190
  * @class MailerClient
@@ -290,7 +222,6 @@ var InstructionType;
290
222
  */
291
223
  class MailerClient {
292
224
  constructor(connection, wallet, programId, usdcMint) {
293
- this.defaultComputeUnitMultiplier = 1.2; // 20% buffer by default
294
225
  this.connection = connection;
295
226
  this.wallet = wallet;
296
227
  this.programId = programId;
@@ -300,69 +231,10 @@ class MailerClient {
300
231
  this.mailerStatePda = mailerPda;
301
232
  this.mailerBump = bump;
302
233
  }
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
- }
361
234
  /**
362
235
  * Initialize the mailer program (owner only)
363
- * @param computeOptions Compute unit optimization options
364
236
  */
365
- async initialize(computeOptions) {
237
+ async initialize() {
366
238
  const instruction = new web3_js_1.TransactionInstruction({
367
239
  keys: [
368
240
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -373,7 +245,7 @@ class MailerClient {
373
245
  data: encodeInitialize(this.usdcMint),
374
246
  });
375
247
  const transaction = new web3_js_1.Transaction().add(instruction);
376
- return await this.sendTransaction(transaction, undefined, computeOptions);
248
+ return await this.sendTransaction(transaction);
377
249
  }
378
250
  /**
379
251
  * Send a message with optional revenue sharing
@@ -382,10 +254,9 @@ class MailerClient {
382
254
  * @param body Message body
383
255
  * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
384
256
  * @param resolveSenderToName If true, resolve sender address to name via off-chain service
385
- * @param computeOptions Compute unit optimization options
386
- * @returns Transaction result with signature and compute details
257
+ * @returns Transaction signature
387
258
  */
388
- async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
259
+ async send(to, subject, body, revenueShareToReceiver = false, resolveSenderToName = false) {
389
260
  const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
390
261
  // Derive recipient claim PDA
391
262
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
@@ -415,13 +286,13 @@ class MailerClient {
415
286
  });
416
287
  instructions.push(sendInstruction);
417
288
  const transaction = new web3_js_1.Transaction().add(...instructions);
418
- return await this.sendTransaction(transaction, undefined, computeOptions);
289
+ return await this.sendTransaction(transaction);
419
290
  }
420
291
  /**
421
292
  * Claim recipient share of revenue
422
- * @returns Transaction result
293
+ * @returns Transaction signature
423
294
  */
424
- async claimRecipientShare(computeOptions) {
295
+ async claimRecipientShare() {
425
296
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), this.wallet.publicKey.toBuffer()], this.programId);
426
297
  const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
427
298
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -438,13 +309,13 @@ class MailerClient {
438
309
  data: encodeSimpleInstruction(InstructionType.ClaimRecipientShare),
439
310
  });
440
311
  const transaction = new web3_js_1.Transaction().add(instruction);
441
- return await this.sendTransaction(transaction, undefined, computeOptions);
312
+ return await this.sendTransaction(transaction);
442
313
  }
443
314
  /**
444
315
  * Claim owner share of fees (owner only)
445
- * @returns Transaction result
316
+ * @returns Transaction signature
446
317
  */
447
- async claimOwnerShare(computeOptions) {
318
+ async claimOwnerShare() {
448
319
  const ownerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
449
320
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
450
321
  const instruction = new web3_js_1.TransactionInstruction({
@@ -459,35 +330,14 @@ class MailerClient {
459
330
  data: encodeSimpleInstruction(InstructionType.ClaimOwnerShare),
460
331
  });
461
332
  const transaction = new web3_js_1.Transaction().add(instruction);
462
- return await this.sendTransaction(transaction, undefined, computeOptions);
463
- }
464
- /**
465
- * Claim expired recipient shares and move them under owner control
466
- * @param recipient Recipient whose expired shares to reclaim
467
- * @param options Transaction confirm options
468
- * @returns Transaction signature
469
- */
470
- async claimExpiredShares(recipient, options, computeOptions) {
471
- const recipientKey = typeof recipient === 'string' ? new web3_js_1.PublicKey(recipient) : recipient;
472
- const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
473
- const instruction = new web3_js_1.TransactionInstruction({
474
- keys: [
475
- { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
476
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: true },
477
- { pubkey: recipientClaimPda, isSigner: false, isWritable: true },
478
- ],
479
- programId: this.programId,
480
- data: encodeClaimExpiredShares(recipientKey),
481
- });
482
- const transaction = new web3_js_1.Transaction().add(instruction);
483
- return await this.sendTransaction(transaction, options, computeOptions);
333
+ return await this.sendTransaction(transaction);
484
334
  }
485
335
  /**
486
336
  * Delegate message handling to another address
487
337
  * @param delegate Address to delegate to, or null to clear delegation
488
338
  * @returns Transaction signature
489
339
  */
490
- async delegateTo(delegate, computeOptions) {
340
+ async delegateTo(delegate) {
491
341
  const delegateKey = delegate
492
342
  ? typeof delegate === 'string'
493
343
  ? new web3_js_1.PublicKey(delegate)
@@ -510,35 +360,33 @@ class MailerClient {
510
360
  data: encodeDelegateTo(delegateKey),
511
361
  });
512
362
  const transaction = new web3_js_1.Transaction().add(instruction);
513
- return await this.sendTransaction(transaction, undefined, computeOptions);
363
+ return await this.sendTransaction(transaction);
514
364
  }
515
365
  /**
516
366
  * Reject a delegation made to you
517
367
  * @param delegator Address that delegated to you
518
368
  * @returns Transaction signature
519
369
  */
520
- async rejectDelegation(delegator, computeOptions) {
370
+ async rejectDelegation(delegator) {
521
371
  const delegatorKey = typeof delegator === 'string' ? new web3_js_1.PublicKey(delegator) : delegator;
522
372
  const [delegationPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('delegation'), delegatorKey.toBuffer()], this.programId);
523
373
  const instruction = new web3_js_1.TransactionInstruction({
524
374
  keys: [
525
375
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
526
376
  { pubkey: delegationPda, isSigner: false, isWritable: true },
527
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: false },
528
377
  ],
529
378
  programId: this.programId,
530
379
  data: encodeSimpleInstruction(InstructionType.RejectDelegation),
531
380
  });
532
381
  const transaction = new web3_js_1.Transaction().add(instruction);
533
- return await this.sendTransaction(transaction, undefined, computeOptions);
382
+ return await this.sendTransaction(transaction);
534
383
  }
535
384
  /**
536
385
  * Set the send fee (owner only)
537
386
  * @param newFee New fee in USDC micro-units (6 decimals)
538
- * @param computeOptions Compute unit optimization options
539
- * @returns Transaction result
387
+ * @returns Transaction signature
540
388
  */
541
- async setFee(newFee, computeOptions) {
389
+ async setFee(newFee) {
542
390
  const instruction = new web3_js_1.TransactionInstruction({
543
391
  keys: [
544
392
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -548,14 +396,14 @@ class MailerClient {
548
396
  data: encodeSetFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
549
397
  });
550
398
  const transaction = new web3_js_1.Transaction().add(instruction);
551
- return await this.sendTransaction(transaction, undefined, computeOptions);
399
+ return await this.sendTransaction(transaction);
552
400
  }
553
401
  /**
554
402
  * Set the delegation fee (owner only)
555
403
  * @param newFee New delegation fee in USDC micro-units (6 decimals)
556
404
  * @returns Transaction signature
557
405
  */
558
- async setDelegationFee(newFee, computeOptions) {
406
+ async setDelegationFee(newFee) {
559
407
  const instruction = new web3_js_1.TransactionInstruction({
560
408
  keys: [
561
409
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -565,59 +413,7 @@ class MailerClient {
565
413
  data: encodeSetDelegationFee(typeof newFee === 'bigint' ? newFee : BigInt(newFee)),
566
414
  });
567
415
  const transaction = new web3_js_1.Transaction().add(instruction);
568
- return await this.sendTransaction(transaction, undefined, computeOptions);
569
- }
570
- async setCustomFeePercentage(account, percentage, payer, computeOptions) {
571
- const normalizedPercentage = Math.trunc(percentage);
572
- if (normalizedPercentage < 0 || normalizedPercentage > 100) {
573
- throw new Error('Percentage must be between 0 and 100');
574
- }
575
- const accountKey = typeof account === 'string' ? new web3_js_1.PublicKey(account) : account;
576
- const payerKey = payer
577
- ? typeof payer === 'string'
578
- ? new web3_js_1.PublicKey(payer)
579
- : payer
580
- : this.wallet.publicKey;
581
- const [discountPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('discount'), accountKey.toBuffer()], this.programId);
582
- const instruction = new web3_js_1.TransactionInstruction({
583
- keys: [
584
- { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
585
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: false },
586
- { pubkey: discountPda, isSigner: false, isWritable: true },
587
- { pubkey: accountKey, isSigner: false, isWritable: false },
588
- { pubkey: payerKey, isSigner: true, isWritable: true },
589
- { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
590
- ],
591
- programId: this.programId,
592
- data: encodeSetCustomFeePercentage(accountKey, normalizedPercentage),
593
- });
594
- const transaction = new web3_js_1.Transaction().add(instruction);
595
- return this.sendTransaction(transaction, undefined, computeOptions);
596
- }
597
- async clearCustomFeePercentage(account, computeOptions) {
598
- const accountKey = typeof account === 'string' ? new web3_js_1.PublicKey(account) : account;
599
- const [discountPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('discount'), accountKey.toBuffer()], this.programId);
600
- const instruction = new web3_js_1.TransactionInstruction({
601
- keys: [
602
- { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
603
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: false },
604
- { pubkey: discountPda, isSigner: false, isWritable: true },
605
- ],
606
- programId: this.programId,
607
- data: encodeClearCustomFeePercentage(accountKey),
608
- });
609
- const transaction = new web3_js_1.Transaction().add(instruction);
610
- return this.sendTransaction(transaction, undefined, computeOptions);
611
- }
612
- async getCustomFeePercentage(account) {
613
- const accountKey = typeof account === 'string' ? new web3_js_1.PublicKey(account) : account;
614
- const [discountPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('discount'), accountKey.toBuffer()], this.programId);
615
- const accountInfo = await this.connection.getAccountInfo(discountPda);
616
- if (!accountInfo) {
617
- return 100;
618
- }
619
- const discountState = parseFeeDiscount(accountInfo.data);
620
- return 100 - discountState.discount;
416
+ return await this.sendTransaction(transaction);
621
417
  }
622
418
  /**
623
419
  * Get current fees from the mailer state
@@ -705,7 +501,7 @@ class MailerClient {
705
501
  * @param options Transaction confirm options
706
502
  * @returns Transaction signature
707
503
  */
708
- async sendToEmail(toEmail, subject, body, options, computeOptions) {
504
+ async sendToEmail(toEmail, subject, body, options) {
709
505
  // Get associated token accounts
710
506
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
711
507
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -731,7 +527,7 @@ class MailerClient {
731
527
  data: instructionData,
732
528
  }));
733
529
  const transaction = new web3_js_1.Transaction().add(...instructions);
734
- return this.sendTransaction(transaction, options, computeOptions);
530
+ return this.sendTransaction(transaction, options);
735
531
  }
736
532
  /**
737
533
  * Send a prepared message to an email address (no wallet known)
@@ -741,7 +537,7 @@ class MailerClient {
741
537
  * @param options Transaction confirm options
742
538
  * @returns Transaction signature
743
539
  */
744
- async sendPreparedToEmail(toEmail, mailId, options, computeOptions) {
540
+ async sendPreparedToEmail(toEmail, mailId, options) {
745
541
  // Get associated token accounts
746
542
  const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
747
543
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
@@ -767,7 +563,7 @@ class MailerClient {
767
563
  data: instructionData,
768
564
  }));
769
565
  const transaction = new web3_js_1.Transaction().add(...instructions);
770
- return this.sendTransaction(transaction, options, computeOptions);
566
+ return this.sendTransaction(transaction, options);
771
567
  }
772
568
  /**
773
569
  * Send a prepared message using a mailId (to match EVM behavior)
@@ -777,66 +573,16 @@ class MailerClient {
777
573
  * @param resolveSenderToName If true, resolve sender address to name
778
574
  * @returns Transaction signature
779
575
  */
780
- async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
781
- const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
782
- const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
783
- const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
784
- const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
785
- const instructions = [];
786
- const mailerTokenInfo = await this.connection.getAccountInfo(mailerTokenAccount);
787
- if (!mailerTokenInfo) {
788
- instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, mailerTokenAccount, this.mailerStatePda, this.usdcMint));
789
- }
790
- const sendInstruction = new web3_js_1.TransactionInstruction({
791
- keys: [
792
- { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
793
- { pubkey: recipientClaimPda, isSigner: false, isWritable: true },
794
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: false },
795
- { pubkey: senderTokenAccount, isSigner: false, isWritable: true },
796
- { pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
797
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
798
- { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
799
- ],
800
- programId: this.programId,
801
- data: encodeSendPrepared(recipientKey, mailId, revenueShareToReceiver, resolveSenderToName),
802
- });
803
- instructions.push(sendInstruction);
804
- const transaction = new web3_js_1.Transaction().add(...instructions);
805
- return this.sendTransaction(transaction, undefined, computeOptions);
806
- }
807
- async sendThroughWebhook(to, webhookId, revenueShareToReceiver = false, resolveSenderToName = false, computeOptions) {
808
- const recipientKey = typeof to === 'string' ? new web3_js_1.PublicKey(to) : to;
809
- const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
810
- const senderTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
811
- const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
812
- const instructions = [];
813
- const mailerTokenInfo = await this.connection.getAccountInfo(mailerTokenAccount);
814
- if (!mailerTokenInfo) {
815
- instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, mailerTokenAccount, this.mailerStatePda, this.usdcMint));
816
- }
817
- const sendInstruction = new web3_js_1.TransactionInstruction({
818
- keys: [
819
- { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
820
- { pubkey: recipientClaimPda, isSigner: false, isWritable: true },
821
- { pubkey: this.mailerStatePda, isSigner: false, isWritable: false },
822
- { pubkey: senderTokenAccount, isSigner: false, isWritable: true },
823
- { pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
824
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
825
- { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
826
- ],
827
- programId: this.programId,
828
- data: encodeSendThroughWebhook(recipientKey, webhookId, revenueShareToReceiver, resolveSenderToName),
829
- });
830
- instructions.push(sendInstruction);
831
- const transaction = new web3_js_1.Transaction().add(...instructions);
832
- return this.sendTransaction(transaction, undefined, computeOptions);
576
+ async sendPrepared(to, mailId, revenueShareToReceiver = false, resolveSenderToName = false) {
577
+ // For Solana, we send the mailId as both subject and body to indicate it's a prepared message
578
+ return this.send(to, mailId, '', revenueShareToReceiver, resolveSenderToName);
833
579
  }
834
580
  /**
835
581
  * Pause the contract and distribute owner claimable funds (owner only)
836
582
  * @param options Transaction confirm options
837
583
  * @returns Transaction signature
838
584
  */
839
- async pause(options, computeOptions) {
585
+ async pause(options) {
840
586
  const ownerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.wallet.publicKey);
841
587
  const mailerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, this.mailerStatePda, true);
842
588
  const instruction = new web3_js_1.TransactionInstruction({
@@ -851,14 +597,14 @@ class MailerClient {
851
597
  data: encodeSimpleInstruction(InstructionType.Pause),
852
598
  });
853
599
  const transaction = new web3_js_1.Transaction().add(instruction);
854
- return await this.sendTransaction(transaction, options, computeOptions);
600
+ return await this.sendTransaction(transaction, options);
855
601
  }
856
602
  /**
857
603
  * Unpause the contract (owner only)
858
604
  * @param options Transaction confirm options
859
605
  * @returns Transaction signature
860
606
  */
861
- async unpause(options, computeOptions) {
607
+ async unpause(options) {
862
608
  const instruction = new web3_js_1.TransactionInstruction({
863
609
  keys: [
864
610
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -868,14 +614,14 @@ class MailerClient {
868
614
  data: encodeSimpleInstruction(InstructionType.Unpause),
869
615
  });
870
616
  const transaction = new web3_js_1.Transaction().add(instruction);
871
- return await this.sendTransaction(transaction, options, computeOptions);
617
+ return await this.sendTransaction(transaction, options);
872
618
  }
873
619
  /**
874
620
  * Emergency unpause without fund distribution (owner only)
875
621
  * @param options Transaction confirm options
876
622
  * @returns Transaction signature
877
623
  */
878
- async emergencyUnpause(options, computeOptions) {
624
+ async emergencyUnpause(options) {
879
625
  const instruction = new web3_js_1.TransactionInstruction({
880
626
  keys: [
881
627
  { pubkey: this.wallet.publicKey, isSigner: true, isWritable: false },
@@ -885,7 +631,7 @@ class MailerClient {
885
631
  data: encodeSimpleInstruction(InstructionType.EmergencyUnpause),
886
632
  });
887
633
  const transaction = new web3_js_1.Transaction().add(instruction);
888
- return await this.sendTransaction(transaction, options, computeOptions);
634
+ return await this.sendTransaction(transaction, options);
889
635
  }
890
636
  /**
891
637
  * Distribute claimable funds to a recipient when contract is paused
@@ -893,7 +639,7 @@ class MailerClient {
893
639
  * @param options Transaction confirm options
894
640
  * @returns Transaction signature
895
641
  */
896
- async distributeClaimableFunds(recipient, options, computeOptions) {
642
+ async distributeClaimableFunds(recipient, options) {
897
643
  const recipientKey = typeof recipient === 'string' ? new web3_js_1.PublicKey(recipient) : recipient;
898
644
  const [recipientClaimPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claim'), recipientKey.toBuffer()], this.programId);
899
645
  const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.usdcMint, recipientKey);
@@ -915,7 +661,7 @@ class MailerClient {
915
661
  data,
916
662
  });
917
663
  const transaction = new web3_js_1.Transaction().add(instruction);
918
- return await this.sendTransaction(transaction, options, computeOptions);
664
+ return await this.sendTransaction(transaction, options);
919
665
  }
920
666
  /**
921
667
  * Get the current send fee
@@ -944,24 +690,17 @@ class MailerClient {
944
690
  * @param options Confirm options
945
691
  * @returns Transaction signature
946
692
  */
947
- async sendTransaction(transaction, options, computeOptions) {
948
- // Optimize compute units if requested
949
- const { transaction: optimizedTx, simulatedUnits } = await this.optimizeComputeUnits(transaction, computeOptions);
693
+ async sendTransaction(transaction, options) {
950
694
  // Get recent blockhash
951
695
  const { blockhash } = await this.connection.getLatestBlockhash();
952
- optimizedTx.recentBlockhash = blockhash;
953
- optimizedTx.feePayer = this.wallet.publicKey;
696
+ transaction.recentBlockhash = blockhash;
697
+ transaction.feePayer = this.wallet.publicKey;
954
698
  // Sign transaction
955
- const signedTx = await this.wallet.signTransaction(optimizedTx);
699
+ const signedTx = await this.wallet.signTransaction(transaction);
956
700
  // Send and confirm
957
701
  const signature = await this.connection.sendRawTransaction(signedTx.serialize());
958
702
  await this.connection.confirmTransaction(signature, options?.commitment || 'confirmed');
959
- return {
960
- signature,
961
- simulatedUnits,
962
- computeUnitLimit: computeOptions?.computeUnitLimit,
963
- computeUnitPrice: computeOptions?.computeUnitPrice,
964
- };
703
+ return signature;
965
704
  }
966
705
  /**
967
706
  * Create a simple wallet from a keypair for testing