@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
@@ -1,615 +1,413 @@
1
- import { getAddress, EstimateGasExecutionError, } from 'viem';
2
- import { Mailer__factory } from '../../typechain-types/factories/Mailer__factory.js';
1
+ import { getAddress } from "viem";
2
+ import { Mailer__factory } from "../../typechain-types/factories/Mailer__factory.js";
3
+ // Get ABI from typechain-generated factories
3
4
  const MAILER_ABI = Mailer__factory.abi;
5
+ // Get bytecode from typechain-generated factories
4
6
  const MAILER_BYTECODE = Mailer__factory.bytecode;
5
7
  /**
6
- * Normalize any Address-like input (string with checksum or lowercase) to checksum format.
7
- */
8
- function normalizeAddress(value) {
9
- return getAddress(value);
10
- }
11
- /**
12
- * High-level client for interacting with the EVM Mailer contract.
13
- * Exposes every callable contract function with type-safe wrappers.
14
- * Includes automatic gas estimation with configurable buffer for all transactions.
8
+ * @class MailerClient
9
+ * @description High-level TypeScript client for the Mailer contract using viem
10
+ * @notice Provides easy-to-use methods for sending messages with USDC fees and revenue sharing
11
+ *
12
+ * ## Key Features:
13
+ * - **Delegation Management**: Delegate mail handling with rejection capability
14
+ * - **Priority Messages**: Full fee (0.1 USDC) with 90% revenue share to recipient
15
+ * - **Standard Messages**: 10% fee only (0.01 USDC) with no revenue share
16
+ * - **Revenue Claims**: 60-day claim period for priority message revenue shares
17
+ *
18
+ * ## Usage Examples:
19
+ * ```typescript
20
+ * // Connect to existing contract
21
+ * import { createPublicClient, createWalletClient, http } from 'viem';
22
+ * import { mainnet } from 'viem/chains';
23
+ *
24
+ * const publicClient = createPublicClient({
25
+ * chain: mainnet,
26
+ * transport: http()
27
+ * });
28
+ *
29
+ * const mailer = new MailerClient('CONTRACT_ADDRESS', publicClient);
30
+ *
31
+ * // Send message with revenue sharing to recipient
32
+ * const walletClient = createWalletClient({
33
+ * chain: mainnet,
34
+ * transport: http()
35
+ * });
36
+ *
37
+ * await mailer.send('0x...', 'Subject', 'Body', true, walletClient, account);
38
+ *
39
+ * // Claim your revenue share (as recipient)
40
+ * await mailer.claimRecipientShare(walletClient, account);
41
+ * ```
15
42
  */
16
43
  export class MailerClient {
17
- constructor(contractAddress, publicClient) {
18
- this.defaultGasMultiplier = 1.2; // 20% buffer by default
19
- this.contractAddress = normalizeAddress(contractAddress);
20
- this.publicClient = publicClient;
21
- }
22
- /**
23
- * Helper method to estimate gas for a transaction with optional buffer
24
- */
25
- async estimateGasWithBuffer(estimateFn, gasOptions) {
26
- // If gas limit is explicitly provided, use it
27
- if (gasOptions?.gasLimit) {
28
- return gasOptions.gasLimit;
29
- }
30
- try {
31
- // Estimate gas for the transaction
32
- const estimatedGas = await estimateFn();
33
- // Apply multiplier for safety buffer
34
- const multiplier = gasOptions?.gasMultiplier ?? this.defaultGasMultiplier;
35
- const gasWithBuffer = BigInt(Math.ceil(Number(estimatedGas) * multiplier));
36
- // Apply max gas limit if specified
37
- if (gasOptions?.maxGasLimit) {
38
- return gasWithBuffer > gasOptions.maxGasLimit ? gasOptions.maxGasLimit : gasWithBuffer;
39
- }
40
- return gasWithBuffer;
41
- }
42
- catch (error) {
43
- // If estimation fails, throw with helpful message
44
- if (error instanceof EstimateGasExecutionError) {
45
- throw new Error(`Gas estimation failed: ${error.message}`);
46
- }
47
- throw error;
48
- }
49
- }
50
44
  /**
51
- * Helper method to build transaction parameters with gas options
45
+ * @description Creates a new MailerClient instance
46
+ * @param contractAddress The deployed Mailer contract address
47
+ * @param publicClient Viem public client for reading blockchain state
52
48
  */
53
- buildTxParams(gasLimit, gasOptions) {
54
- const params = { gas: gasLimit };
55
- if (gasOptions?.maxFeePerGas) {
56
- params.maxFeePerGas = gasOptions.maxFeePerGas;
57
- }
58
- if (gasOptions?.maxPriorityFeePerGas) {
59
- params.maxPriorityFeePerGas = gasOptions.maxPriorityFeePerGas;
60
- }
61
- return params;
49
+ constructor(contractAddress, publicClient) {
50
+ this.contractAddress = getAddress(contractAddress);
51
+ this.publicClient = publicClient;
62
52
  }
63
53
  /**
64
- * Deploy a fresh Mailer contract instance with gas estimation.
54
+ * @description Deploy a new Mailer contract and return a client instance
55
+ * @param walletClient Viem wallet client with deployment permissions
56
+ * @param account Account to deploy from
57
+ * @param usdcTokenAddress Address of the USDC token contract
58
+ * @param ownerAddress Address that will own the deployed contract
59
+ * @returns Promise resolving to a MailerClient instance
65
60
  */
66
- static async deploy(walletClient, publicClient, account, usdcTokenAddress, ownerAddress, gasOptions) {
67
- // For deployment, we need to estimate gas differently
68
- // Use a reasonable default for deployment gas
69
- const estimatedGas = BigInt(3000000); // Default deployment gas
70
- // Apply gas buffer
71
- const multiplier = gasOptions?.gasMultiplier ?? 1.5; // Higher multiplier for deployment
72
- const gasLimit = gasOptions?.gasLimit ?? BigInt(Math.ceil(Number(estimatedGas) * multiplier));
73
- // Deploy with estimated gas
61
+ static async deploy(walletClient, publicClient, account, usdcTokenAddress, ownerAddress) {
74
62
  const hash = await walletClient.deployContract({
75
63
  abi: MAILER_ABI,
76
64
  bytecode: MAILER_BYTECODE,
77
- args: [normalizeAddress(usdcTokenAddress), normalizeAddress(ownerAddress)],
65
+ args: [getAddress(usdcTokenAddress), getAddress(ownerAddress)],
78
66
  account,
79
67
  chain: walletClient.chain,
80
- gas: gasLimit,
81
- ...(gasOptions?.maxFeePerGas && { maxFeePerGas: gasOptions.maxFeePerGas }),
82
- ...(gasOptions?.maxPriorityFeePerGas && { maxPriorityFeePerGas: gasOptions.maxPriorityFeePerGas }),
83
68
  });
84
69
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
85
70
  if (!receipt.contractAddress) {
86
- throw new Error('Contract deployment failed');
71
+ throw new Error("Contract deployment failed");
87
72
  }
88
- return {
89
- client: new MailerClient(receipt.contractAddress, publicClient),
90
- result: { hash, estimatedGas, gasLimit }
91
- };
92
- }
93
- getAddress() {
94
- return this.contractAddress;
73
+ return new MailerClient(receipt.contractAddress, publicClient);
95
74
  }
96
75
  /**
97
- * Core message send with explicit payer control and gas estimation.
76
+ * @description Send a message with optional revenue sharing
77
+ * @notice Two modes:
78
+ * - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
79
+ * - revenueShareToReceiver=false: Sender pays 0.01 USDC only
80
+ * @param to Recipient address who receives the message and potential revenue share
81
+ * @param subject Message subject line
82
+ * @param body Message content
83
+ * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
84
+ * @param resolveSenderToName If true, resolve sender address to name via off-chain service
85
+ * @param walletClient Viem wallet client for transaction
86
+ * @param account Account to send from
87
+ * @returns Promise resolving to transaction hash
88
+ * @example
89
+ * ```typescript
90
+ * // Send with revenue share to recipient
91
+ * const hash = await mailer.send('0x...', 'Subject', 'Priority message', true, false, walletClient, account);
92
+ * // Send standard message (no revenue share)
93
+ * const hash2 = await mailer.send('0x...', 'Subject', 'Standard message', false, false, walletClient, account);
94
+ * await publicClient.waitForTransactionReceipt({ hash });
95
+ * ```
98
96
  */
99
- async send(to, subject, body, payer, revenueShareToReceiver, resolveSenderToName, walletClient, account, gasOptions) {
100
- // Estimate gas for the transaction
101
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
97
+ async send(to, subject, body, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
98
+ return await walletClient.writeContract({
102
99
  address: this.contractAddress,
103
100
  abi: MAILER_ABI,
104
101
  functionName: 'send',
105
- args: [
106
- normalizeAddress(to),
107
- subject,
108
- body,
109
- normalizeAddress(payer),
110
- revenueShareToReceiver,
111
- resolveSenderToName,
112
- ],
113
- account,
114
- }), gasOptions);
115
- const hash = await walletClient.writeContract({
116
- address: this.contractAddress,
117
- abi: MAILER_ABI,
118
- functionName: 'send',
119
- args: [
120
- normalizeAddress(to),
121
- subject,
122
- body,
123
- normalizeAddress(payer),
124
- revenueShareToReceiver,
125
- resolveSenderToName,
126
- ],
102
+ args: [to, subject, body, revenueShareToReceiver, resolveSenderToName],
127
103
  account,
128
104
  chain: walletClient.chain,
129
- ...this.buildTxParams(gasLimit, gasOptions),
130
105
  });
131
- return { hash, estimatedGas: gasLimit, gasLimit };
132
106
  }
133
- async sendPrepared(to, mailId, payer, revenueShareToReceiver, resolveSenderToName, walletClient, account, gasOptions) {
134
- // Estimate gas for the transaction
135
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
136
- address: this.contractAddress,
137
- abi: MAILER_ABI,
138
- functionName: 'sendPrepared',
139
- args: [
140
- normalizeAddress(to),
141
- mailId,
142
- normalizeAddress(payer),
143
- revenueShareToReceiver,
144
- resolveSenderToName,
145
- ],
146
- account,
147
- }), gasOptions);
148
- const hash = await walletClient.writeContract({
107
+ /**
108
+ * @description Send a message using a pre-prepared mail ID with optional revenue sharing
109
+ * @notice Two modes:
110
+ * - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
111
+ * - revenueShareToReceiver=false: Sender pays 0.01 USDC only
112
+ * @param to Recipient address who receives the message and potential revenue share
113
+ * @param mailId Pre-prepared message identifier
114
+ * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
115
+ * @param resolveSenderToName If true, resolve sender address to name via off-chain service
116
+ * @param walletClient Viem wallet client for transaction
117
+ * @param account Account to send from
118
+ * @returns Promise resolving to transaction hash
119
+ */
120
+ async sendPrepared(to, mailId, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
121
+ return await walletClient.writeContract({
149
122
  address: this.contractAddress,
150
123
  abi: MAILER_ABI,
151
124
  functionName: 'sendPrepared',
152
- args: [
153
- normalizeAddress(to),
154
- mailId,
155
- normalizeAddress(payer),
156
- revenueShareToReceiver,
157
- resolveSenderToName,
158
- ],
125
+ args: [to, mailId, revenueShareToReceiver, resolveSenderToName],
159
126
  account,
160
127
  chain: walletClient.chain,
161
- ...this.buildTxParams(gasLimit, gasOptions),
162
128
  });
163
- return { hash, estimatedGas: gasLimit, gasLimit };
164
- }
165
- async sendThroughWebhook(to, webhookId, payer, revenueShareToReceiver, resolveSenderToName, walletClient, account, gasOptions) {
166
- // Estimate gas for the transaction
167
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
168
- address: this.contractAddress,
169
- abi: MAILER_ABI,
170
- functionName: 'sendThroughWebhook',
171
- args: [
172
- normalizeAddress(to),
173
- webhookId,
174
- normalizeAddress(payer),
175
- revenueShareToReceiver,
176
- resolveSenderToName,
177
- ],
178
- account,
179
- }), gasOptions);
180
- const hash = await walletClient.writeContract({
181
- address: this.contractAddress,
182
- abi: MAILER_ABI,
183
- functionName: 'sendThroughWebhook',
184
- args: [
185
- normalizeAddress(to),
186
- webhookId,
187
- normalizeAddress(payer),
188
- revenueShareToReceiver,
189
- resolveSenderToName,
190
- ],
191
- account,
192
- chain: walletClient.chain,
193
- ...this.buildTxParams(gasLimit, gasOptions),
194
- });
195
- return { hash, estimatedGas: gasLimit, gasLimit };
196
- }
197
- async sendToEmailAddress(toEmail, subject, body, payer, walletClient, account, gasOptions) {
198
- // Estimate gas for the transaction
199
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
200
- address: this.contractAddress,
201
- abi: MAILER_ABI,
202
- functionName: 'sendToEmailAddress',
203
- args: [toEmail, subject, body, normalizeAddress(payer)],
204
- account,
205
- }), gasOptions);
206
- const hash = await walletClient.writeContract({
207
- address: this.contractAddress,
208
- abi: MAILER_ABI,
209
- functionName: 'sendToEmailAddress',
210
- args: [toEmail, subject, body, normalizeAddress(payer)],
211
- account,
212
- chain: walletClient.chain,
213
- ...this.buildTxParams(gasLimit, gasOptions),
214
- });
215
- return { hash, estimatedGas: gasLimit, gasLimit };
216
- }
217
- async sendPreparedToEmailAddress(toEmail, mailId, payer, walletClient, account, gasOptions) {
218
- // Estimate gas for the transaction
219
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
220
- address: this.contractAddress,
221
- abi: MAILER_ABI,
222
- functionName: 'sendPreparedToEmailAddress',
223
- args: [toEmail, mailId, normalizeAddress(payer)],
224
- account,
225
- }), gasOptions);
226
- const hash = await walletClient.writeContract({
227
- address: this.contractAddress,
228
- abi: MAILER_ABI,
229
- functionName: 'sendPreparedToEmailAddress',
230
- args: [toEmail, mailId, normalizeAddress(payer)],
231
- account,
232
- chain: walletClient.chain,
233
- ...this.buildTxParams(gasLimit, gasOptions),
234
- });
235
- return { hash, estimatedGas: gasLimit, gasLimit };
236
- }
237
- async getFee() {
238
- return (await this.publicClient.readContract({
239
- address: this.contractAddress,
240
- abi: MAILER_ABI,
241
- functionName: 'getFee',
242
- }));
243
129
  }
244
130
  async getSendFee() {
245
- return (await this.publicClient.readContract({
131
+ return await this.publicClient.readContract({
246
132
  address: this.contractAddress,
247
133
  abi: MAILER_ABI,
248
134
  functionName: 'sendFee',
249
- }));
250
- }
251
- async setFee(newFee, walletClient, account, gasOptions) {
252
- // Estimate gas for the transaction
253
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
254
- address: this.contractAddress,
255
- abi: MAILER_ABI,
256
- functionName: 'setFee',
257
- args: [newFee],
258
- account,
259
- }), gasOptions);
260
- const hash = await walletClient.writeContract({
261
- address: this.contractAddress,
262
- abi: MAILER_ABI,
263
- functionName: 'setFee',
264
- args: [newFee],
265
- account,
266
- chain: walletClient.chain,
267
- ...this.buildTxParams(gasLimit, gasOptions),
135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
268
136
  });
269
- return { hash, estimatedGas: gasLimit, gasLimit };
270
137
  }
271
138
  async getUsdcToken() {
272
- return (await this.publicClient.readContract({
139
+ return await this.publicClient.readContract({
273
140
  address: this.contractAddress,
274
141
  abi: MAILER_ABI,
275
142
  functionName: 'usdcToken',
276
- }));
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ });
277
145
  }
278
- async getOwner() {
279
- return (await this.publicClient.readContract({
280
- address: this.contractAddress,
281
- abi: MAILER_ABI,
282
- functionName: 'owner',
283
- }));
146
+ getAddress() {
147
+ return this.contractAddress;
284
148
  }
285
- async claimRecipientShare(walletClient, account, gasOptions) {
286
- // Estimate gas for the transaction
287
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
288
- address: this.contractAddress,
289
- abi: MAILER_ABI,
290
- functionName: 'claimRecipientShare',
291
- account,
292
- }), gasOptions);
293
- const hash = await walletClient.writeContract({
149
+ async claimRecipientShare(walletClient, account) {
150
+ return await walletClient.writeContract({
294
151
  address: this.contractAddress,
295
152
  abi: MAILER_ABI,
296
153
  functionName: 'claimRecipientShare',
297
154
  account,
298
155
  chain: walletClient.chain,
299
- ...this.buildTxParams(gasLimit, gasOptions),
300
156
  });
301
- return { hash, estimatedGas: gasLimit, gasLimit };
302
157
  }
303
- async claimOwnerShare(walletClient, account, gasOptions) {
304
- // Estimate gas for the transaction
305
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
306
- address: this.contractAddress,
307
- abi: MAILER_ABI,
308
- functionName: 'claimOwnerShare',
309
- account,
310
- }), gasOptions);
311
- const hash = await walletClient.writeContract({
158
+ async claimOwnerShare(walletClient, account) {
159
+ return await walletClient.writeContract({
312
160
  address: this.contractAddress,
313
161
  abi: MAILER_ABI,
314
162
  functionName: 'claimOwnerShare',
315
163
  account,
316
164
  chain: walletClient.chain,
317
- ...this.buildTxParams(gasLimit, gasOptions),
318
165
  });
319
- return { hash, estimatedGas: gasLimit, gasLimit };
320
166
  }
321
- async claimExpiredShares(recipient, walletClient, account, gasOptions) {
322
- // Estimate gas for the transaction
323
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
324
- address: this.contractAddress,
325
- abi: MAILER_ABI,
326
- functionName: 'claimExpiredShares',
327
- args: [normalizeAddress(recipient)],
328
- account,
329
- }), gasOptions);
330
- const hash = await walletClient.writeContract({
167
+ async claimExpiredShares(recipient, walletClient, account) {
168
+ return await walletClient.writeContract({
331
169
  address: this.contractAddress,
332
170
  abi: MAILER_ABI,
333
171
  functionName: 'claimExpiredShares',
334
- args: [normalizeAddress(recipient)],
172
+ args: [getAddress(recipient)],
335
173
  account,
336
174
  chain: walletClient.chain,
337
- ...this.buildTxParams(gasLimit, gasOptions),
338
175
  });
339
- return { hash, estimatedGas: gasLimit, gasLimit };
340
176
  }
341
177
  async getRecipientClaimable(recipient) {
342
- const [amount, expiresAt, isExpired] = (await this.publicClient.readContract({
178
+ const result = await this.publicClient.readContract({
343
179
  address: this.contractAddress,
344
180
  abi: MAILER_ABI,
345
181
  functionName: 'getRecipientClaimable',
346
- args: [normalizeAddress(recipient)],
347
- }));
348
- return { amount, expiresAt, isExpired };
182
+ args: [getAddress(recipient)],
183
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
+ });
185
+ return {
186
+ amount: result[0],
187
+ expiresAt: result[1],
188
+ isExpired: result[2]
189
+ };
349
190
  }
350
191
  async getOwnerClaimable() {
351
- return (await this.publicClient.readContract({
192
+ return await this.publicClient.readContract({
352
193
  address: this.contractAddress,
353
194
  abi: MAILER_ABI,
354
- functionName: 'getOwnerClaimable',
355
- }));
195
+ functionName: 'getOwnerClaimable'
196
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
197
+ });
356
198
  }
357
- async delegateTo(delegate, walletClient, account, gasOptions) {
358
- // Estimate gas for the transaction
359
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
360
- address: this.contractAddress,
361
- abi: MAILER_ABI,
362
- functionName: 'delegateTo',
363
- args: [normalizeAddress(delegate)],
364
- account,
365
- }), gasOptions);
366
- const hash = await walletClient.writeContract({
199
+ // Delegation functionality
200
+ /**
201
+ * Delegate mail handling to another address
202
+ * @param delegate Address to delegate to (or 0x0 to clear delegation)
203
+ * @param walletClient Connected wallet client
204
+ * @param account Account to send transaction from
205
+ * @returns Transaction hash
206
+ */
207
+ async delegateTo(delegate, walletClient, account) {
208
+ return await walletClient.writeContract({
367
209
  address: this.contractAddress,
368
210
  abi: MAILER_ABI,
369
211
  functionName: 'delegateTo',
370
- args: [normalizeAddress(delegate)],
212
+ args: [getAddress(delegate)],
371
213
  account,
372
214
  chain: walletClient.chain,
373
- ...this.buildTxParams(gasLimit, gasOptions),
374
215
  });
375
- return { hash, estimatedGas: gasLimit, gasLimit };
376
216
  }
377
- async rejectDelegation(delegatingAddress, walletClient, account, gasOptions) {
378
- // Estimate gas for the transaction
379
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
380
- address: this.contractAddress,
381
- abi: MAILER_ABI,
382
- functionName: 'rejectDelegation',
383
- args: [normalizeAddress(delegatingAddress)],
384
- account,
385
- }), gasOptions);
386
- const hash = await walletClient.writeContract({
217
+ /**
218
+ * Reject a delegation made to you by another address
219
+ * @param delegatingAddress Address that delegated to you
220
+ * @param walletClient Connected wallet client
221
+ * @param account Account to send transaction from
222
+ * @returns Transaction hash
223
+ */
224
+ async rejectDelegation(delegatingAddress, walletClient, account) {
225
+ return await walletClient.writeContract({
387
226
  address: this.contractAddress,
388
227
  abi: MAILER_ABI,
389
228
  functionName: 'rejectDelegation',
390
- args: [normalizeAddress(delegatingAddress)],
229
+ args: [getAddress(delegatingAddress)],
391
230
  account,
392
231
  chain: walletClient.chain,
393
- ...this.buildTxParams(gasLimit, gasOptions),
394
232
  });
395
- return { hash, estimatedGas: gasLimit, gasLimit };
396
233
  }
234
+ /**
235
+ * Get current delegation fee in USDC (6 decimals)
236
+ * @returns Delegation fee amount
237
+ */
397
238
  async getDelegationFee() {
398
- return (await this.publicClient.readContract({
239
+ return await this.publicClient.readContract({
399
240
  address: this.contractAddress,
400
241
  abi: MAILER_ABI,
401
242
  functionName: 'getDelegationFee',
402
- }));
243
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
244
+ });
403
245
  }
404
- async setDelegationFee(newFee, walletClient, account, gasOptions) {
405
- // Estimate gas for the transaction
406
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
407
- address: this.contractAddress,
408
- abi: MAILER_ABI,
409
- functionName: 'setDelegationFee',
410
- args: [newFee],
411
- account,
412
- }), gasOptions);
413
- const hash = await walletClient.writeContract({
246
+ /**
247
+ * Update delegation fee (owner only)
248
+ * @param newFee New fee amount in USDC (6 decimals)
249
+ * @param walletClient Connected wallet client
250
+ * @param account Account to send transaction from
251
+ * @returns Transaction hash
252
+ */
253
+ async setDelegationFee(newFee, walletClient, account) {
254
+ return await walletClient.writeContract({
414
255
  address: this.contractAddress,
415
256
  abi: MAILER_ABI,
416
257
  functionName: 'setDelegationFee',
417
258
  args: [newFee],
418
259
  account,
419
260
  chain: walletClient.chain,
420
- ...this.buildTxParams(gasLimit, gasOptions),
421
261
  });
422
- return { hash, estimatedGas: gasLimit, gasLimit };
423
262
  }
424
- async setCustomFeePercentage(target, percentage, walletClient, account, gasOptions) {
425
- // Estimate gas for the transaction
426
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
427
- address: this.contractAddress,
428
- abi: MAILER_ABI,
429
- functionName: 'setCustomFeePercentage',
430
- args: [normalizeAddress(target), BigInt(percentage)],
431
- account,
432
- }), gasOptions);
433
- const hash = await walletClient.writeContract({
263
+ /**
264
+ * @description Send a message to an email address (no wallet known)
265
+ * @notice Charges only 10% owner fee since recipient wallet is unknown
266
+ * @param toEmail Email address of the recipient
267
+ * @param subject Message subject line
268
+ * @param body Message content
269
+ * @param walletClient Viem wallet client for transaction
270
+ * @param account Account to send from
271
+ * @returns Promise resolving to transaction hash
272
+ * @example
273
+ * ```typescript
274
+ * // Send to email address
275
+ * const hash = await mailer.sendToEmailAddress('user@example.com', 'Subject', 'Body', walletClient, account);
276
+ * await publicClient.waitForTransactionReceipt({ hash });
277
+ * ```
278
+ */
279
+ async sendToEmailAddress(toEmail, subject, body, walletClient, account) {
280
+ return await walletClient.writeContract({
434
281
  address: this.contractAddress,
435
282
  abi: MAILER_ABI,
436
- functionName: 'setCustomFeePercentage',
437
- args: [normalizeAddress(target), BigInt(percentage)],
283
+ functionName: 'sendToEmailAddress',
284
+ args: [toEmail, subject, body],
438
285
  account,
439
286
  chain: walletClient.chain,
440
- ...this.buildTxParams(gasLimit, gasOptions),
441
287
  });
442
- return { hash, estimatedGas: gasLimit, gasLimit };
443
288
  }
444
- async clearCustomFeePercentage(target, walletClient, account, gasOptions) {
445
- // Estimate gas for the transaction
446
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
447
- address: this.contractAddress,
448
- abi: MAILER_ABI,
449
- functionName: 'clearCustomFeePercentage',
450
- args: [normalizeAddress(target)],
451
- account,
452
- }), gasOptions);
453
- const hash = await walletClient.writeContract({
289
+ /**
290
+ * @description Send a pre-prepared message to an email address (no wallet known)
291
+ * @notice Charges only 10% owner fee since recipient wallet is unknown
292
+ * @param toEmail Email address of the recipient
293
+ * @param mailId Pre-prepared message identifier
294
+ * @param walletClient Viem wallet client for transaction
295
+ * @param account Account to send from
296
+ * @returns Promise resolving to transaction hash
297
+ */
298
+ async sendPreparedToEmailAddress(toEmail, mailId, walletClient, account) {
299
+ return await walletClient.writeContract({
454
300
  address: this.contractAddress,
455
301
  abi: MAILER_ABI,
456
- functionName: 'clearCustomFeePercentage',
457
- args: [normalizeAddress(target)],
302
+ functionName: 'sendPreparedToEmailAddress',
303
+ args: [toEmail, mailId],
458
304
  account,
459
305
  chain: walletClient.chain,
460
- ...this.buildTxParams(gasLimit, gasOptions),
461
306
  });
462
- return { hash, estimatedGas: gasLimit, gasLimit };
463
- }
464
- async getCustomFeePercentage(target) {
465
- const percentage = (await this.publicClient.readContract({
466
- address: this.contractAddress,
467
- abi: MAILER_ABI,
468
- functionName: 'getCustomFeePercentage',
469
- args: [normalizeAddress(target)],
470
- }));
471
- return Number(percentage);
472
- }
473
- async getCustomFeeDiscount(target) {
474
- const discount = (await this.publicClient.readContract({
475
- address: this.contractAddress,
476
- abi: MAILER_ABI,
477
- functionName: 'customFeeDiscount',
478
- args: [normalizeAddress(target)],
479
- }));
480
- return Number(discount);
481
307
  }
482
- async setPermission(contractAddress, walletClient, account, gasOptions) {
483
- // Estimate gas for the transaction
484
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
485
- address: this.contractAddress,
486
- abi: MAILER_ABI,
487
- functionName: 'setPermission',
488
- args: [normalizeAddress(contractAddress)],
489
- account,
490
- }), gasOptions);
491
- const hash = await walletClient.writeContract({
308
+ /**
309
+ * Set the send fee (owner only)
310
+ * @param newFee New fee amount in USDC (6 decimals)
311
+ * @param walletClient Viem wallet client for transaction
312
+ * @param account Account to send from (must be owner)
313
+ * @returns Promise resolving to transaction hash
314
+ */
315
+ async setFee(newFee, walletClient, account) {
316
+ return await walletClient.writeContract({
492
317
  address: this.contractAddress,
493
318
  abi: MAILER_ABI,
494
- functionName: 'setPermission',
495
- args: [normalizeAddress(contractAddress)],
319
+ functionName: 'setFee',
320
+ args: [newFee],
496
321
  account,
497
322
  chain: walletClient.chain,
498
- ...this.buildTxParams(gasLimit, gasOptions),
499
323
  });
500
- return { hash, estimatedGas: gasLimit, gasLimit };
501
324
  }
502
- async removePermission(contractAddress, walletClient, account, gasOptions) {
503
- // Estimate gas for the transaction
504
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
505
- address: this.contractAddress,
506
- abi: MAILER_ABI,
507
- functionName: 'removePermission',
508
- args: [normalizeAddress(contractAddress)],
509
- account,
510
- }), gasOptions);
511
- const hash = await walletClient.writeContract({
325
+ /**
326
+ * Get the current send fee
327
+ * @returns Current send fee in USDC (6 decimals)
328
+ */
329
+ async getFee() {
330
+ return await this.publicClient.readContract({
512
331
  address: this.contractAddress,
513
332
  abi: MAILER_ABI,
514
- functionName: 'removePermission',
515
- args: [normalizeAddress(contractAddress)],
516
- account,
517
- chain: walletClient.chain,
518
- ...this.buildTxParams(gasLimit, gasOptions),
333
+ functionName: 'getFee',
334
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
519
335
  });
520
- return { hash, estimatedGas: gasLimit, gasLimit };
521
336
  }
522
- async hasPermission(contractAddress, wallet) {
523
- const permitted = (await this.publicClient.readContract({
524
- address: this.contractAddress,
525
- abi: MAILER_ABI,
526
- functionName: 'permissions',
527
- args: [normalizeAddress(contractAddress), normalizeAddress(wallet)],
528
- }));
529
- return permitted;
530
- }
531
- async pause(walletClient, account, gasOptions) {
532
- // Estimate gas for the transaction
533
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
534
- address: this.contractAddress,
535
- abi: MAILER_ABI,
536
- functionName: 'pause',
537
- account,
538
- }), gasOptions);
539
- const hash = await walletClient.writeContract({
337
+ /**
338
+ * Pause the contract and distribute all claimable funds (owner only)
339
+ * @param walletClient Viem wallet client for transaction
340
+ * @param account Account to send from (must be owner)
341
+ * @returns Promise resolving to transaction hash
342
+ */
343
+ async pause(walletClient, account) {
344
+ return await walletClient.writeContract({
540
345
  address: this.contractAddress,
541
346
  abi: MAILER_ABI,
542
347
  functionName: 'pause',
543
348
  account,
544
349
  chain: walletClient.chain,
545
- ...this.buildTxParams(gasLimit, gasOptions),
546
350
  });
547
- return { hash, estimatedGas: gasLimit, gasLimit };
548
351
  }
549
- async unpause(walletClient, account, gasOptions) {
550
- // Estimate gas for the transaction
551
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
552
- address: this.contractAddress,
553
- abi: MAILER_ABI,
554
- functionName: 'unpause',
555
- account,
556
- }), gasOptions);
557
- const hash = await walletClient.writeContract({
352
+ /**
353
+ * Unpause the contract (owner only)
354
+ * @param walletClient Viem wallet client for transaction
355
+ * @param account Account to send from (must be owner)
356
+ * @returns Promise resolving to transaction hash
357
+ */
358
+ async unpause(walletClient, account) {
359
+ return await walletClient.writeContract({
558
360
  address: this.contractAddress,
559
361
  abi: MAILER_ABI,
560
362
  functionName: 'unpause',
561
363
  account,
562
364
  chain: walletClient.chain,
563
- ...this.buildTxParams(gasLimit, gasOptions),
564
365
  });
565
- return { hash, estimatedGas: gasLimit, gasLimit };
566
366
  }
567
- async emergencyUnpause(walletClient, account, gasOptions) {
568
- // Estimate gas for the transaction
569
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
570
- address: this.contractAddress,
571
- abi: MAILER_ABI,
572
- functionName: 'emergencyUnpause',
573
- account,
574
- }), gasOptions);
575
- const hash = await walletClient.writeContract({
367
+ /**
368
+ * Emergency unpause without fund distribution (owner only)
369
+ * @param walletClient Viem wallet client for transaction
370
+ * @param account Account to send from (must be owner)
371
+ * @returns Promise resolving to transaction hash
372
+ */
373
+ async emergencyUnpause(walletClient, account) {
374
+ return await walletClient.writeContract({
576
375
  address: this.contractAddress,
577
376
  abi: MAILER_ABI,
578
377
  functionName: 'emergencyUnpause',
579
378
  account,
580
379
  chain: walletClient.chain,
581
- ...this.buildTxParams(gasLimit, gasOptions),
582
380
  });
583
- return { hash, estimatedGas: gasLimit, gasLimit };
584
381
  }
382
+ /**
383
+ * Check if contract is currently paused
384
+ * @returns True if contract is paused, false otherwise
385
+ */
585
386
  async isPaused() {
586
- return (await this.publicClient.readContract({
387
+ return await this.publicClient.readContract({
587
388
  address: this.contractAddress,
588
389
  abi: MAILER_ABI,
589
390
  functionName: 'isPaused',
590
- }));
391
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
+ });
591
393
  }
592
- async distributeClaimableFunds(recipient, walletClient, account, gasOptions) {
593
- // Estimate gas for the transaction
594
- const gasLimit = await this.estimateGasWithBuffer(() => this.publicClient.estimateContractGas({
595
- address: this.contractAddress,
596
- abi: MAILER_ABI,
597
- functionName: 'distributeClaimableFunds',
598
- args: [normalizeAddress(recipient)],
599
- account,
600
- }), gasOptions);
601
- const hash = await walletClient.writeContract({
394
+ /**
395
+ * Distribute a specific recipient's claimable funds during pause
396
+ * Anyone can call this function when contract is paused
397
+ * @param recipient Address to distribute funds for
398
+ * @param walletClient Viem wallet client for transaction
399
+ * @param account Account to send from
400
+ * @returns Promise resolving to transaction hash
401
+ */
402
+ async distributeClaimableFunds(recipient, walletClient, account) {
403
+ return await walletClient.writeContract({
602
404
  address: this.contractAddress,
603
405
  abi: MAILER_ABI,
604
406
  functionName: 'distributeClaimableFunds',
605
- args: [normalizeAddress(recipient)],
407
+ args: [getAddress(recipient)],
606
408
  account,
607
409
  chain: walletClient.chain,
608
- ...this.buildTxParams(gasLimit, gasOptions),
609
410
  });
610
- return { hash, estimatedGas: gasLimit, gasLimit };
611
411
  }
612
412
  }
613
- MailerClient.abi = MAILER_ABI;
614
- MailerClient.bytecode = MAILER_BYTECODE;
615
413
  //# sourceMappingURL=mailer-client.js.map