@sudobility/contracts 1.12.0 → 1.13.1

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 (128) hide show
  1. package/dist/evm/src/evm/{mailer-client.d.ts → evm-mailer-client.d.ts} +146 -50
  2. package/dist/evm/src/evm/evm-mailer-client.d.ts.map +1 -0
  3. package/dist/evm/src/evm/evm-mailer-client.js +924 -0
  4. package/dist/evm/src/evm/evm-mailer-client.js.map +1 -0
  5. package/dist/evm/src/evm/index.d.ts +1 -1
  6. package/dist/evm/src/evm/index.d.ts.map +1 -1
  7. package/dist/evm/src/evm/index.js +4 -4
  8. package/dist/evm/src/evm/index.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 +4 -3
  12. package/dist/solana/solana/index.js.map +1 -1
  13. package/dist/solana/solana/solana-mailer-client.d.ts +209 -0
  14. package/dist/solana/solana/solana-mailer-client.d.ts.map +1 -0
  15. package/dist/solana/solana/solana-mailer-client.js +1004 -0
  16. package/dist/solana/solana/solana-mailer-client.js.map +1 -0
  17. package/dist/solana/solana/types.d.ts +3 -2
  18. package/dist/solana/solana/types.d.ts.map +1 -1
  19. package/dist/solana/solana/types.js.map +1 -1
  20. package/dist/{unified-esm/src/evm/mailer-client.d.ts → unified/src/evm/evm-mailer-client.d.ts} +146 -50
  21. package/dist/unified/src/evm/evm-mailer-client.d.ts.map +1 -0
  22. package/dist/unified/src/evm/evm-mailer-client.js +924 -0
  23. package/dist/unified/src/evm/evm-mailer-client.js.map +1 -0
  24. package/dist/unified/src/evm/index.d.ts +1 -1
  25. package/dist/unified/src/evm/index.d.ts.map +1 -1
  26. package/dist/unified/src/evm/index.js +4 -4
  27. package/dist/unified/src/evm/index.js.map +1 -1
  28. package/dist/unified/src/react/context/MailerProvider.d.ts +26 -20
  29. package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
  30. package/dist/unified/src/react/context/MailerProvider.js +26 -26
  31. package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
  32. package/dist/unified/src/react/hooks/useMailerMutations.d.ts +225 -192
  33. package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  34. package/dist/unified/src/react/hooks/useMailerMutations.js +263 -266
  35. package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
  36. package/dist/unified/src/react/hooks/useMailerQueries.d.ts +117 -63
  37. package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  38. package/dist/unified/src/react/hooks/useMailerQueries.js +239 -104
  39. package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
  40. package/dist/unified/src/react/index.d.ts +5 -3
  41. package/dist/unified/src/react/index.d.ts.map +1 -1
  42. package/dist/unified/src/react/index.js +41 -26
  43. package/dist/unified/src/react/index.js.map +1 -1
  44. package/dist/unified/src/solana/index.d.ts +1 -1
  45. package/dist/unified/src/solana/index.d.ts.map +1 -1
  46. package/dist/unified/src/solana/index.js +4 -3
  47. package/dist/unified/src/solana/index.js.map +1 -1
  48. package/dist/unified/src/solana/solana-mailer-client.d.ts +209 -0
  49. package/dist/unified/src/solana/solana-mailer-client.d.ts.map +1 -0
  50. package/dist/unified/src/solana/solana-mailer-client.js +1004 -0
  51. package/dist/unified/src/solana/solana-mailer-client.js.map +1 -0
  52. package/dist/unified/src/solana/types.d.ts +3 -2
  53. package/dist/unified/src/solana/types.d.ts.map +1 -1
  54. package/dist/unified/src/solana/types.js.map +1 -1
  55. package/dist/unified/src/unified/index.d.ts +1 -1
  56. package/dist/unified/src/unified/index.d.ts.map +1 -1
  57. package/dist/unified/src/unified/onchain-mailer-client.d.ts +187 -268
  58. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  59. package/dist/unified/src/unified/onchain-mailer-client.js +539 -1614
  60. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  61. package/dist/unified/src/unified/types.d.ts +23 -6
  62. package/dist/unified/src/unified/types.d.ts.map +1 -1
  63. package/dist/{unified/src/evm/mailer-client.d.ts → unified-esm/src/evm/evm-mailer-client.d.ts} +146 -50
  64. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +1 -0
  65. package/dist/unified-esm/src/evm/evm-mailer-client.js +920 -0
  66. package/dist/unified-esm/src/evm/evm-mailer-client.js.map +1 -0
  67. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  68. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  69. package/dist/unified-esm/src/evm/index.js +2 -2
  70. package/dist/unified-esm/src/evm/index.js.map +1 -1
  71. package/dist/unified-esm/src/react/context/MailerProvider.d.ts +26 -20
  72. package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
  73. package/dist/unified-esm/src/react/context/MailerProvider.js +25 -26
  74. package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
  75. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +225 -192
  76. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  77. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +254 -262
  78. package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
  79. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +117 -63
  80. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  81. package/dist/unified-esm/src/react/hooks/useMailerQueries.js +232 -102
  82. package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
  83. package/dist/unified-esm/src/react/index.d.ts +5 -3
  84. package/dist/unified-esm/src/react/index.d.ts.map +1 -1
  85. package/dist/unified-esm/src/react/index.js +9 -5
  86. package/dist/unified-esm/src/react/index.js.map +1 -1
  87. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  88. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  89. package/dist/unified-esm/src/solana/index.js +2 -1
  90. package/dist/unified-esm/src/solana/index.js.map +1 -1
  91. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +209 -0
  92. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +1 -0
  93. package/dist/unified-esm/src/solana/solana-mailer-client.js +1000 -0
  94. package/dist/unified-esm/src/solana/solana-mailer-client.js.map +1 -0
  95. package/dist/unified-esm/src/solana/types.d.ts +3 -2
  96. package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
  97. package/dist/unified-esm/src/solana/types.js.map +1 -1
  98. package/dist/unified-esm/src/unified/index.d.ts +1 -1
  99. package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
  100. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +187 -268
  101. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  102. package/dist/unified-esm/src/unified/onchain-mailer-client.js +539 -1614
  103. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  104. package/dist/unified-esm/src/unified/types.d.ts +23 -6
  105. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  106. package/package.json +5 -4
  107. package/programs/mailer/Cargo.toml +1 -1
  108. package/dist/evm/src/evm/mailer-client.d.ts.map +0 -1
  109. package/dist/evm/src/evm/mailer-client.js +0 -619
  110. package/dist/evm/src/evm/mailer-client.js.map +0 -1
  111. package/dist/solana/solana/mailer-client.d.ts +0 -282
  112. package/dist/solana/solana/mailer-client.d.ts.map +0 -1
  113. package/dist/solana/solana/mailer-client.js +0 -989
  114. package/dist/solana/solana/mailer-client.js.map +0 -1
  115. package/dist/unified/src/evm/mailer-client.d.ts.map +0 -1
  116. package/dist/unified/src/evm/mailer-client.js +0 -619
  117. package/dist/unified/src/evm/mailer-client.js.map +0 -1
  118. package/dist/unified/src/solana/mailer-client.d.ts +0 -282
  119. package/dist/unified/src/solana/mailer-client.d.ts.map +0 -1
  120. package/dist/unified/src/solana/mailer-client.js +0 -989
  121. package/dist/unified/src/solana/mailer-client.js.map +0 -1
  122. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +0 -1
  123. package/dist/unified-esm/src/evm/mailer-client.js +0 -615
  124. package/dist/unified-esm/src/evm/mailer-client.js.map +0 -1
  125. package/dist/unified-esm/src/solana/mailer-client.d.ts +0 -282
  126. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +0 -1
  127. package/dist/unified-esm/src/solana/mailer-client.js +0 -985
  128. package/dist/unified-esm/src/solana/mailer-client.js.map +0 -1
@@ -0,0 +1,920 @@
1
+ import { getAddress, EstimateGasExecutionError, } from 'viem';
2
+ import { Mailer__factory } from '../../typechain-types/factories/Mailer__factory.js';
3
+ const MAILER_ABI = Mailer__factory.abi;
4
+ const MAILER_BYTECODE = Mailer__factory.bytecode;
5
+ /**
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
+ * Stateless EVM Mailer client.
13
+ * All methods take wallet and chainInfo as parameters.
14
+ * No state is stored in the instance.
15
+ */
16
+ export class EVMMailerClient {
17
+ constructor() {
18
+ this.defaultGasMultiplier = 1.2; // 20% buffer by default
19
+ // Default gas limits for common operations to use as fallbacks
20
+ this.defaultGasLimits = {
21
+ send: BigInt(150000),
22
+ sendPriority: BigInt(200000),
23
+ sendPrepared: BigInt(120000),
24
+ sendPriorityPrepared: BigInt(150000),
25
+ claimRevenue: BigInt(100000),
26
+ claimOwnerShare: BigInt(100000),
27
+ delegateTo: BigInt(80000),
28
+ setFee: BigInt(60000),
29
+ setPermission: BigInt(60000),
30
+ pause: BigInt(50000),
31
+ unpause: BigInt(50000),
32
+ deploy: BigInt(3000000),
33
+ };
34
+ }
35
+ /**
36
+ * Ensure publicClient is provided
37
+ */
38
+ ensurePublicClient(publicClient) {
39
+ if (!publicClient) {
40
+ throw new Error('PublicClient is required for this operation. Please provide it in the EVMWallet.');
41
+ }
42
+ return publicClient;
43
+ }
44
+ /**
45
+ * Switch chain if needed for EVM wallet
46
+ */
47
+ async switchChainIfNeeded(walletClient, targetChainId) {
48
+ try {
49
+ const currentChainId = walletClient.chain?.id;
50
+ if (currentChainId && currentChainId !== targetChainId) {
51
+ // Request chain switch
52
+ await walletClient.request({
53
+ method: 'wallet_switchEthereumChain',
54
+ params: [{ chainId: `0x${targetChainId.toString(16)}` }]
55
+ });
56
+ }
57
+ }
58
+ catch (error) {
59
+ console.warn('Chain switch failed or not supported:', error);
60
+ // Continue anyway - the transaction might still work
61
+ }
62
+ }
63
+ /**
64
+ * Helper method to estimate gas for a transaction with optional buffer
65
+ */
66
+ async estimateGasWithBuffer(estimateFn, gasOptions, fallbackGasLimit) {
67
+ // If gas limit is explicitly provided, use it
68
+ if (gasOptions?.gasLimit) {
69
+ return gasOptions.gasLimit;
70
+ }
71
+ let estimatedGas;
72
+ let retryCount = 0;
73
+ const maxRetries = 2;
74
+ while (retryCount <= maxRetries) {
75
+ try {
76
+ // Estimate gas for the transaction
77
+ estimatedGas = await estimateFn();
78
+ break; // Success, exit retry loop
79
+ }
80
+ catch (error) {
81
+ retryCount++;
82
+ // If we've exhausted retries, use fallback or throw
83
+ if (retryCount > maxRetries) {
84
+ if (fallbackGasLimit) {
85
+ console.warn(`Gas estimation failed after ${maxRetries} retries, using fallback: ${fallbackGasLimit}`);
86
+ estimatedGas = fallbackGasLimit;
87
+ }
88
+ else if (error instanceof EstimateGasExecutionError) {
89
+ throw new Error(`Gas estimation failed: ${error.message}`);
90
+ }
91
+ else {
92
+ throw error;
93
+ }
94
+ }
95
+ else {
96
+ // Wait before retrying (exponential backoff)
97
+ await new Promise(resolve => setTimeout(resolve, 1000 * retryCount));
98
+ }
99
+ }
100
+ }
101
+ // Apply multiplier for safety buffer
102
+ const multiplier = gasOptions?.gasMultiplier ?? this.defaultGasMultiplier;
103
+ const gasWithBuffer = BigInt(Math.ceil(Number(estimatedGas) * multiplier));
104
+ // Apply max gas limit if specified
105
+ if (gasOptions?.maxGasLimit) {
106
+ return gasWithBuffer > gasOptions.maxGasLimit ? gasOptions.maxGasLimit : gasWithBuffer;
107
+ }
108
+ return gasWithBuffer;
109
+ }
110
+ /**
111
+ * Helper method to build transaction parameters with gas options
112
+ */
113
+ buildTxParams(gasLimit, gasOptions) {
114
+ const params = { gas: gasLimit };
115
+ if (gasOptions?.maxFeePerGas) {
116
+ params.maxFeePerGas = gasOptions.maxFeePerGas;
117
+ }
118
+ if (gasOptions?.maxPriorityFeePerGas) {
119
+ params.maxPriorityFeePerGas = gasOptions.maxPriorityFeePerGas;
120
+ }
121
+ return params;
122
+ }
123
+ /**
124
+ * Deploy a fresh Mailer contract instance
125
+ */
126
+ async deploy(connectedWallet, chainInfo, ownerAddress, gasOptions) {
127
+ if (!chainInfo.usdcAddress) {
128
+ throw new Error(`No USDC address configured for chain ${chainInfo.name}`);
129
+ }
130
+ // Switch chain if needed
131
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
132
+ const [account] = await connectedWallet.walletClient.getAddresses();
133
+ // For deployment, use a reasonable default gas
134
+ const estimatedGas = BigInt(3000000);
135
+ const multiplier = gasOptions?.gasMultiplier ?? 1.5;
136
+ const gasLimit = gasOptions?.gasLimit ?? BigInt(Math.ceil(Number(estimatedGas) * multiplier));
137
+ const hash = await connectedWallet.walletClient.deployContract({
138
+ abi: MAILER_ABI,
139
+ bytecode: MAILER_BYTECODE,
140
+ args: [normalizeAddress(chainInfo.usdcAddress), normalizeAddress(ownerAddress)],
141
+ account,
142
+ chain: connectedWallet.walletClient.chain,
143
+ gas: gasLimit,
144
+ ...(gasOptions?.maxFeePerGas && { maxFeePerGas: gasOptions.maxFeePerGas }),
145
+ ...(gasOptions?.maxPriorityFeePerGas && { maxPriorityFeePerGas: gasOptions.maxPriorityFeePerGas }),
146
+ });
147
+ return { hash, estimatedGas, gasLimit };
148
+ }
149
+ /**
150
+ * Core message send with explicit payer control
151
+ */
152
+ async send(connectedWallet, chainInfo, to, subject, body, payer, revenueShareToReceiver, resolveSenderToName, gasOptions) {
153
+ if (!chainInfo.mailerAddress) {
154
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
155
+ }
156
+ // Switch chain if needed
157
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
158
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
159
+ const [account] = await connectedWallet.walletClient.getAddresses();
160
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
161
+ // Estimate gas for the transaction
162
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
163
+ address: contractAddress,
164
+ abi: MAILER_ABI,
165
+ functionName: 'send',
166
+ args: [
167
+ normalizeAddress(to),
168
+ subject,
169
+ body,
170
+ normalizeAddress(payer),
171
+ revenueShareToReceiver,
172
+ resolveSenderToName,
173
+ ],
174
+ account,
175
+ }), gasOptions, this.defaultGasLimits.send);
176
+ const hash = await connectedWallet.walletClient.writeContract({
177
+ address: contractAddress,
178
+ abi: MAILER_ABI,
179
+ functionName: 'send',
180
+ args: [
181
+ normalizeAddress(to),
182
+ subject,
183
+ body,
184
+ normalizeAddress(payer),
185
+ revenueShareToReceiver,
186
+ resolveSenderToName,
187
+ ],
188
+ account,
189
+ chain: connectedWallet.walletClient.chain,
190
+ ...this.buildTxParams(gasLimit, gasOptions),
191
+ });
192
+ return { hash, estimatedGas: gasLimit, gasLimit };
193
+ }
194
+ /**
195
+ * Send a prepared message
196
+ */
197
+ async sendPrepared(connectedWallet, chainInfo, to, mailId, payer, revenueShareToReceiver, resolveSenderToName, gasOptions) {
198
+ if (!chainInfo.mailerAddress) {
199
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
200
+ }
201
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
202
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
203
+ const [account] = await connectedWallet.walletClient.getAddresses();
204
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
205
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
206
+ address: contractAddress,
207
+ abi: MAILER_ABI,
208
+ functionName: 'sendPrepared',
209
+ args: [
210
+ normalizeAddress(to),
211
+ mailId,
212
+ normalizeAddress(payer),
213
+ revenueShareToReceiver,
214
+ resolveSenderToName,
215
+ ],
216
+ account,
217
+ }), gasOptions);
218
+ const hash = await connectedWallet.walletClient.writeContract({
219
+ address: contractAddress,
220
+ abi: MAILER_ABI,
221
+ functionName: 'sendPrepared',
222
+ args: [
223
+ normalizeAddress(to),
224
+ mailId,
225
+ normalizeAddress(payer),
226
+ revenueShareToReceiver,
227
+ resolveSenderToName,
228
+ ],
229
+ account,
230
+ chain: connectedWallet.walletClient.chain,
231
+ ...this.buildTxParams(gasLimit, gasOptions),
232
+ });
233
+ return { hash, estimatedGas: gasLimit, gasLimit };
234
+ }
235
+ /**
236
+ * Send through webhook
237
+ */
238
+ async sendThroughWebhook(connectedWallet, chainInfo, to, webhookId, payer, revenueShareToReceiver, resolveSenderToName, gasOptions) {
239
+ if (!chainInfo.mailerAddress) {
240
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
241
+ }
242
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
243
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
244
+ const [account] = await connectedWallet.walletClient.getAddresses();
245
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
246
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
247
+ address: contractAddress,
248
+ abi: MAILER_ABI,
249
+ functionName: 'sendThroughWebhook',
250
+ args: [
251
+ normalizeAddress(to),
252
+ webhookId,
253
+ normalizeAddress(payer),
254
+ revenueShareToReceiver,
255
+ resolveSenderToName,
256
+ ],
257
+ account,
258
+ }), gasOptions);
259
+ const hash = await connectedWallet.walletClient.writeContract({
260
+ address: contractAddress,
261
+ abi: MAILER_ABI,
262
+ functionName: 'sendThroughWebhook',
263
+ args: [
264
+ normalizeAddress(to),
265
+ webhookId,
266
+ normalizeAddress(payer),
267
+ revenueShareToReceiver,
268
+ resolveSenderToName,
269
+ ],
270
+ account,
271
+ chain: connectedWallet.walletClient.chain,
272
+ ...this.buildTxParams(gasLimit, gasOptions),
273
+ });
274
+ return { hash, estimatedGas: gasLimit, gasLimit };
275
+ }
276
+ /**
277
+ * Send to email address
278
+ */
279
+ async sendToEmailAddress(connectedWallet, chainInfo, toEmail, subject, body, payer, gasOptions) {
280
+ if (!chainInfo.mailerAddress) {
281
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
282
+ }
283
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
284
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
285
+ const [account] = await connectedWallet.walletClient.getAddresses();
286
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
287
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
288
+ address: contractAddress,
289
+ abi: MAILER_ABI,
290
+ functionName: 'sendToEmailAddress',
291
+ args: [toEmail, subject, body, normalizeAddress(payer)],
292
+ account,
293
+ }), gasOptions);
294
+ const hash = await connectedWallet.walletClient.writeContract({
295
+ address: contractAddress,
296
+ abi: MAILER_ABI,
297
+ functionName: 'sendToEmailAddress',
298
+ args: [toEmail, subject, body, normalizeAddress(payer)],
299
+ account,
300
+ chain: connectedWallet.walletClient.chain,
301
+ ...this.buildTxParams(gasLimit, gasOptions),
302
+ });
303
+ return { hash, estimatedGas: gasLimit, gasLimit };
304
+ }
305
+ /**
306
+ * Send prepared to email address
307
+ */
308
+ async sendPreparedToEmailAddress(connectedWallet, chainInfo, toEmail, mailId, payer, gasOptions) {
309
+ if (!chainInfo.mailerAddress) {
310
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
311
+ }
312
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
313
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
314
+ const [account] = await connectedWallet.walletClient.getAddresses();
315
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
316
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
317
+ address: contractAddress,
318
+ abi: MAILER_ABI,
319
+ functionName: 'sendPreparedToEmailAddress',
320
+ args: [toEmail, mailId, normalizeAddress(payer)],
321
+ account,
322
+ }), gasOptions);
323
+ const hash = await connectedWallet.walletClient.writeContract({
324
+ address: contractAddress,
325
+ abi: MAILER_ABI,
326
+ functionName: 'sendPreparedToEmailAddress',
327
+ args: [toEmail, mailId, normalizeAddress(payer)],
328
+ account,
329
+ chain: connectedWallet.walletClient.chain,
330
+ ...this.buildTxParams(gasLimit, gasOptions),
331
+ });
332
+ return { hash, estimatedGas: gasLimit, gasLimit };
333
+ }
334
+ /**
335
+ * Get the current send fee
336
+ */
337
+ async getSendFee(chainInfo, publicClient) {
338
+ if (!chainInfo.mailerAddress) {
339
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
340
+ }
341
+ const client = this.ensurePublicClient(publicClient);
342
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
343
+ return await client.readContract({
344
+ address: contractAddress,
345
+ abi: MAILER_ABI,
346
+ functionName: 'sendFee',
347
+ });
348
+ }
349
+ /**
350
+ * Set the send fee (owner only)
351
+ */
352
+ async setFee(connectedWallet, chainInfo, usdcAmount, gasOptions) {
353
+ if (!chainInfo.mailerAddress) {
354
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
355
+ }
356
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
357
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
358
+ const [account] = await connectedWallet.walletClient.getAddresses();
359
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
360
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
361
+ address: contractAddress,
362
+ abi: MAILER_ABI,
363
+ functionName: 'setFee',
364
+ args: [BigInt(usdcAmount)],
365
+ account,
366
+ }), gasOptions);
367
+ const hash = await connectedWallet.walletClient.writeContract({
368
+ address: contractAddress,
369
+ abi: MAILER_ABI,
370
+ functionName: 'setFee',
371
+ args: [BigInt(usdcAmount)],
372
+ account,
373
+ chain: connectedWallet.walletClient.chain,
374
+ ...this.buildTxParams(gasLimit, gasOptions),
375
+ });
376
+ return { hash, estimatedGas: gasLimit, gasLimit };
377
+ }
378
+ /**
379
+ * Get USDC token address
380
+ */
381
+ async getUsdcToken(chainInfo, publicClient) {
382
+ if (!chainInfo.mailerAddress) {
383
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
384
+ }
385
+ const client = this.ensurePublicClient(publicClient);
386
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
387
+ return await client.readContract({
388
+ address: contractAddress,
389
+ abi: MAILER_ABI,
390
+ functionName: 'usdcToken',
391
+ });
392
+ }
393
+ /**
394
+ * Get contract owner
395
+ */
396
+ async getOwner(chainInfo, publicClient) {
397
+ if (!chainInfo.mailerAddress) {
398
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
399
+ }
400
+ const client = this.ensurePublicClient(publicClient);
401
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
402
+ return await client.readContract({
403
+ address: contractAddress,
404
+ abi: MAILER_ABI,
405
+ functionName: 'owner',
406
+ });
407
+ }
408
+ /**
409
+ * Claim recipient share
410
+ */
411
+ async claimRecipientShare(connectedWallet, chainInfo, gasOptions) {
412
+ if (!chainInfo.mailerAddress) {
413
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
414
+ }
415
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
416
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
417
+ const [account] = await connectedWallet.walletClient.getAddresses();
418
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
419
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
420
+ address: contractAddress,
421
+ abi: MAILER_ABI,
422
+ functionName: 'claimRecipientShare',
423
+ args: [],
424
+ account,
425
+ }), gasOptions, this.defaultGasLimits.claimRevenue);
426
+ const hash = await connectedWallet.walletClient.writeContract({
427
+ address: contractAddress,
428
+ abi: MAILER_ABI,
429
+ functionName: 'claimRecipientShare',
430
+ args: [],
431
+ account,
432
+ chain: connectedWallet.walletClient.chain,
433
+ ...this.buildTxParams(gasLimit, gasOptions),
434
+ });
435
+ return { hash, estimatedGas: gasLimit, gasLimit };
436
+ }
437
+ /**
438
+ * Claim owner share (owner only)
439
+ */
440
+ async claimOwnerShare(connectedWallet, chainInfo, gasOptions) {
441
+ if (!chainInfo.mailerAddress) {
442
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
443
+ }
444
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
445
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
446
+ const [account] = await connectedWallet.walletClient.getAddresses();
447
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
448
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
449
+ address: contractAddress,
450
+ abi: MAILER_ABI,
451
+ functionName: 'claimOwnerShare',
452
+ args: [],
453
+ account,
454
+ }), gasOptions);
455
+ const hash = await connectedWallet.walletClient.writeContract({
456
+ address: contractAddress,
457
+ abi: MAILER_ABI,
458
+ functionName: 'claimOwnerShare',
459
+ args: [],
460
+ account,
461
+ chain: connectedWallet.walletClient.chain,
462
+ ...this.buildTxParams(gasLimit, gasOptions),
463
+ });
464
+ return { hash, estimatedGas: gasLimit, gasLimit };
465
+ }
466
+ /**
467
+ * Claim expired shares (owner only)
468
+ */
469
+ async claimExpiredShares(connectedWallet, chainInfo, recipient, gasOptions) {
470
+ if (!chainInfo.mailerAddress) {
471
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
472
+ }
473
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
474
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
475
+ const [account] = await connectedWallet.walletClient.getAddresses();
476
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
477
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
478
+ address: contractAddress,
479
+ abi: MAILER_ABI,
480
+ functionName: 'claimExpiredShares',
481
+ args: [normalizeAddress(recipient)],
482
+ account,
483
+ }), gasOptions);
484
+ const hash = await connectedWallet.walletClient.writeContract({
485
+ address: contractAddress,
486
+ abi: MAILER_ABI,
487
+ functionName: 'claimExpiredShares',
488
+ args: [normalizeAddress(recipient)],
489
+ account,
490
+ chain: connectedWallet.walletClient.chain,
491
+ ...this.buildTxParams(gasLimit, gasOptions),
492
+ });
493
+ return { hash, estimatedGas: gasLimit, gasLimit };
494
+ }
495
+ /**
496
+ * Get recipient claimable info
497
+ */
498
+ async getRecipientClaimable(recipient, chainInfo, publicClient) {
499
+ if (!chainInfo.mailerAddress) {
500
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
501
+ }
502
+ const client = this.ensurePublicClient(publicClient);
503
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
504
+ const result = await client.readContract({
505
+ address: contractAddress,
506
+ abi: MAILER_ABI,
507
+ functionName: 'getRecipientClaimable',
508
+ args: [normalizeAddress(recipient)],
509
+ });
510
+ return {
511
+ amount: result[0],
512
+ expiresAt: result[1],
513
+ isExpired: result[2],
514
+ };
515
+ }
516
+ /**
517
+ * Get owner claimable amount
518
+ */
519
+ async getOwnerClaimable(chainInfo, publicClient) {
520
+ if (!chainInfo.mailerAddress) {
521
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
522
+ }
523
+ const client = this.ensurePublicClient(publicClient);
524
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
525
+ return await client.readContract({
526
+ address: contractAddress,
527
+ abi: MAILER_ABI,
528
+ functionName: 'ownerClaimable',
529
+ });
530
+ }
531
+ /**
532
+ * Delegate to another address
533
+ */
534
+ async delegateTo(connectedWallet, chainInfo, delegate, gasOptions) {
535
+ if (!chainInfo.mailerAddress) {
536
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
537
+ }
538
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
539
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
540
+ const [account] = await connectedWallet.walletClient.getAddresses();
541
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
542
+ const delegateAddress = delegate ? normalizeAddress(delegate) : '0x0000000000000000000000000000000000000000';
543
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
544
+ address: contractAddress,
545
+ abi: MAILER_ABI,
546
+ functionName: 'delegateTo',
547
+ args: [delegateAddress],
548
+ account,
549
+ }), gasOptions);
550
+ const hash = await connectedWallet.walletClient.writeContract({
551
+ address: contractAddress,
552
+ abi: MAILER_ABI,
553
+ functionName: 'delegateTo',
554
+ args: [delegateAddress],
555
+ account,
556
+ chain: connectedWallet.walletClient.chain,
557
+ ...this.buildTxParams(gasLimit, gasOptions),
558
+ });
559
+ return { hash, estimatedGas: gasLimit, gasLimit };
560
+ }
561
+ /**
562
+ * Reject delegation
563
+ */
564
+ async rejectDelegation(connectedWallet, chainInfo, delegatingAddress, gasOptions) {
565
+ if (!chainInfo.mailerAddress) {
566
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
567
+ }
568
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
569
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
570
+ const [account] = await connectedWallet.walletClient.getAddresses();
571
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
572
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
573
+ address: contractAddress,
574
+ abi: MAILER_ABI,
575
+ functionName: 'rejectDelegation',
576
+ args: [normalizeAddress(delegatingAddress)],
577
+ account,
578
+ }), gasOptions);
579
+ const hash = await connectedWallet.walletClient.writeContract({
580
+ address: contractAddress,
581
+ abi: MAILER_ABI,
582
+ functionName: 'rejectDelegation',
583
+ args: [normalizeAddress(delegatingAddress)],
584
+ account,
585
+ chain: connectedWallet.walletClient.chain,
586
+ ...this.buildTxParams(gasLimit, gasOptions),
587
+ });
588
+ return { hash, estimatedGas: gasLimit, gasLimit };
589
+ }
590
+ /**
591
+ * Get delegation fee
592
+ */
593
+ async getDelegationFee(chainInfo, publicClient) {
594
+ if (!chainInfo.mailerAddress) {
595
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
596
+ }
597
+ const client = this.ensurePublicClient(publicClient);
598
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
599
+ return await client.readContract({
600
+ address: contractAddress,
601
+ abi: MAILER_ABI,
602
+ functionName: 'delegationFee',
603
+ });
604
+ }
605
+ /**
606
+ * Set delegation fee (owner only)
607
+ */
608
+ async setDelegationFee(connectedWallet, chainInfo, usdcAmount, gasOptions) {
609
+ if (!chainInfo.mailerAddress) {
610
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
611
+ }
612
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
613
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
614
+ const [account] = await connectedWallet.walletClient.getAddresses();
615
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
616
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
617
+ address: contractAddress,
618
+ abi: MAILER_ABI,
619
+ functionName: 'setDelegationFee',
620
+ args: [BigInt(usdcAmount)],
621
+ account,
622
+ }), gasOptions);
623
+ const hash = await connectedWallet.walletClient.writeContract({
624
+ address: contractAddress,
625
+ abi: MAILER_ABI,
626
+ functionName: 'setDelegationFee',
627
+ args: [BigInt(usdcAmount)],
628
+ account,
629
+ chain: connectedWallet.walletClient.chain,
630
+ ...this.buildTxParams(gasLimit, gasOptions),
631
+ });
632
+ return { hash, estimatedGas: gasLimit, gasLimit };
633
+ }
634
+ /**
635
+ * Set custom fee percentage
636
+ */
637
+ async setCustomFeePercentage(connectedWallet, chainInfo, account, percentage, gasOptions) {
638
+ if (!chainInfo.mailerAddress) {
639
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
640
+ }
641
+ if (percentage < 0 || percentage > 100) {
642
+ throw new Error('Percentage must be between 0 and 100');
643
+ }
644
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
645
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
646
+ const [senderAccount] = await connectedWallet.walletClient.getAddresses();
647
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
648
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
649
+ address: contractAddress,
650
+ abi: MAILER_ABI,
651
+ functionName: 'setCustomFeePercentage',
652
+ args: [normalizeAddress(account), BigInt(percentage)],
653
+ account: senderAccount,
654
+ }), gasOptions);
655
+ const hash = await connectedWallet.walletClient.writeContract({
656
+ address: contractAddress,
657
+ abi: MAILER_ABI,
658
+ functionName: 'setCustomFeePercentage',
659
+ args: [normalizeAddress(account), BigInt(percentage)],
660
+ account: senderAccount,
661
+ chain: connectedWallet.walletClient.chain,
662
+ ...this.buildTxParams(gasLimit, gasOptions),
663
+ });
664
+ return { hash, estimatedGas: gasLimit, gasLimit };
665
+ }
666
+ /**
667
+ * Clear custom fee percentage
668
+ */
669
+ async clearCustomFeePercentage(connectedWallet, chainInfo, account, gasOptions) {
670
+ if (!chainInfo.mailerAddress) {
671
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
672
+ }
673
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
674
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
675
+ const [senderAccount] = await connectedWallet.walletClient.getAddresses();
676
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
677
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
678
+ address: contractAddress,
679
+ abi: MAILER_ABI,
680
+ functionName: 'clearCustomFeePercentage',
681
+ args: [normalizeAddress(account)],
682
+ account: senderAccount,
683
+ }), gasOptions);
684
+ const hash = await connectedWallet.walletClient.writeContract({
685
+ address: contractAddress,
686
+ abi: MAILER_ABI,
687
+ functionName: 'clearCustomFeePercentage',
688
+ args: [normalizeAddress(account)],
689
+ account: senderAccount,
690
+ chain: connectedWallet.walletClient.chain,
691
+ ...this.buildTxParams(gasLimit, gasOptions),
692
+ });
693
+ return { hash, estimatedGas: gasLimit, gasLimit };
694
+ }
695
+ /**
696
+ * Get custom fee percentage
697
+ */
698
+ async getCustomFeePercentage(chainInfo, account, publicClient) {
699
+ if (!chainInfo.mailerAddress) {
700
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
701
+ }
702
+ const client = this.ensurePublicClient(publicClient);
703
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
704
+ const result = await client.readContract({
705
+ address: contractAddress,
706
+ abi: MAILER_ABI,
707
+ functionName: 'getCustomFeePercentage',
708
+ args: [normalizeAddress(account)],
709
+ });
710
+ return Number(result);
711
+ }
712
+ /**
713
+ * Set permission for a contract to use caller's USDC for sending messages
714
+ */
715
+ async setPermission(connectedWallet, chainInfo, contractAddress, gasOptions) {
716
+ if (!chainInfo.mailerAddress) {
717
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
718
+ }
719
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
720
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
721
+ const [account] = await connectedWallet.walletClient.getAddresses();
722
+ const mailerAddress = normalizeAddress(chainInfo.mailerAddress);
723
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
724
+ address: mailerAddress,
725
+ abi: MAILER_ABI,
726
+ functionName: 'setPermission',
727
+ args: [normalizeAddress(contractAddress)],
728
+ account,
729
+ }), gasOptions);
730
+ const hash = await connectedWallet.walletClient.writeContract({
731
+ address: mailerAddress,
732
+ abi: MAILER_ABI,
733
+ functionName: 'setPermission',
734
+ args: [normalizeAddress(contractAddress)],
735
+ account,
736
+ chain: connectedWallet.walletClient.chain,
737
+ ...this.buildTxParams(gasLimit, gasOptions),
738
+ });
739
+ return { hash, estimatedGas: gasLimit, gasLimit };
740
+ }
741
+ /**
742
+ * Remove permission
743
+ */
744
+ async removePermission(connectedWallet, chainInfo, contractAddress, gasOptions) {
745
+ if (!chainInfo.mailerAddress) {
746
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
747
+ }
748
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
749
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
750
+ const [account] = await connectedWallet.walletClient.getAddresses();
751
+ const mailerAddress = normalizeAddress(chainInfo.mailerAddress);
752
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
753
+ address: mailerAddress,
754
+ abi: MAILER_ABI,
755
+ functionName: 'removePermission',
756
+ args: [normalizeAddress(contractAddress)],
757
+ account,
758
+ }), gasOptions);
759
+ const hash = await connectedWallet.walletClient.writeContract({
760
+ address: mailerAddress,
761
+ abi: MAILER_ABI,
762
+ functionName: 'removePermission',
763
+ args: [normalizeAddress(contractAddress)],
764
+ account,
765
+ chain: connectedWallet.walletClient.chain,
766
+ ...this.buildTxParams(gasLimit, gasOptions),
767
+ });
768
+ return { hash, estimatedGas: gasLimit, gasLimit };
769
+ }
770
+ /**
771
+ * Check if permission exists
772
+ */
773
+ async hasPermission(contractAddress, wallet, chainInfo, publicClient) {
774
+ if (!chainInfo.mailerAddress) {
775
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
776
+ }
777
+ const client = this.ensurePublicClient(publicClient);
778
+ const mailerAddress = normalizeAddress(chainInfo.mailerAddress);
779
+ return await client.readContract({
780
+ address: mailerAddress,
781
+ abi: MAILER_ABI,
782
+ functionName: 'permissions',
783
+ args: [normalizeAddress(contractAddress), normalizeAddress(wallet)],
784
+ });
785
+ }
786
+ /**
787
+ * Pause the contract (owner only)
788
+ */
789
+ async pause(connectedWallet, chainInfo, gasOptions) {
790
+ if (!chainInfo.mailerAddress) {
791
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
792
+ }
793
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
794
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
795
+ const [account] = await connectedWallet.walletClient.getAddresses();
796
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
797
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
798
+ address: contractAddress,
799
+ abi: MAILER_ABI,
800
+ functionName: 'pause',
801
+ args: [],
802
+ account,
803
+ }), gasOptions);
804
+ const hash = await connectedWallet.walletClient.writeContract({
805
+ address: contractAddress,
806
+ abi: MAILER_ABI,
807
+ functionName: 'pause',
808
+ args: [],
809
+ account,
810
+ chain: connectedWallet.walletClient.chain,
811
+ ...this.buildTxParams(gasLimit, gasOptions),
812
+ });
813
+ return { hash, estimatedGas: gasLimit, gasLimit };
814
+ }
815
+ /**
816
+ * Unpause the contract (owner only)
817
+ */
818
+ async unpause(connectedWallet, chainInfo, gasOptions) {
819
+ if (!chainInfo.mailerAddress) {
820
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
821
+ }
822
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
823
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
824
+ const [account] = await connectedWallet.walletClient.getAddresses();
825
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
826
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
827
+ address: contractAddress,
828
+ abi: MAILER_ABI,
829
+ functionName: 'unpause',
830
+ args: [],
831
+ account,
832
+ }), gasOptions);
833
+ const hash = await connectedWallet.walletClient.writeContract({
834
+ address: contractAddress,
835
+ abi: MAILER_ABI,
836
+ functionName: 'unpause',
837
+ args: [],
838
+ account,
839
+ chain: connectedWallet.walletClient.chain,
840
+ ...this.buildTxParams(gasLimit, gasOptions),
841
+ });
842
+ return { hash, estimatedGas: gasLimit, gasLimit };
843
+ }
844
+ /**
845
+ * Emergency unpause (owner only)
846
+ */
847
+ async emergencyUnpause(connectedWallet, chainInfo, gasOptions) {
848
+ if (!chainInfo.mailerAddress) {
849
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
850
+ }
851
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
852
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
853
+ const [account] = await connectedWallet.walletClient.getAddresses();
854
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
855
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
856
+ address: contractAddress,
857
+ abi: MAILER_ABI,
858
+ functionName: 'emergencyUnpause',
859
+ args: [],
860
+ account,
861
+ }), gasOptions);
862
+ const hash = await connectedWallet.walletClient.writeContract({
863
+ address: contractAddress,
864
+ abi: MAILER_ABI,
865
+ functionName: 'emergencyUnpause',
866
+ args: [],
867
+ account,
868
+ chain: connectedWallet.walletClient.chain,
869
+ ...this.buildTxParams(gasLimit, gasOptions),
870
+ });
871
+ return { hash, estimatedGas: gasLimit, gasLimit };
872
+ }
873
+ /**
874
+ * Check if contract is paused
875
+ */
876
+ async isPaused(chainInfo, publicClient) {
877
+ if (!chainInfo.mailerAddress) {
878
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
879
+ }
880
+ const client = this.ensurePublicClient(publicClient);
881
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
882
+ return await client.readContract({
883
+ address: contractAddress,
884
+ abi: MAILER_ABI,
885
+ functionName: 'paused',
886
+ });
887
+ }
888
+ /**
889
+ * Distribute claimable funds when paused (anyone can call)
890
+ */
891
+ async distributeClaimableFunds(connectedWallet, chainInfo, recipient, gasOptions) {
892
+ if (!chainInfo.mailerAddress) {
893
+ throw new Error(`No mailer contract deployed on ${chainInfo.name}`);
894
+ }
895
+ await this.switchChainIfNeeded(connectedWallet.walletClient, chainInfo.chainId);
896
+ const publicClient = this.ensurePublicClient(connectedWallet.publicClient);
897
+ const [account] = await connectedWallet.walletClient.getAddresses();
898
+ const contractAddress = normalizeAddress(chainInfo.mailerAddress);
899
+ const gasLimit = await this.estimateGasWithBuffer(() => publicClient.estimateContractGas({
900
+ address: contractAddress,
901
+ abi: MAILER_ABI,
902
+ functionName: 'distributeClaimableFunds',
903
+ args: [normalizeAddress(recipient)],
904
+ account,
905
+ }), gasOptions);
906
+ const hash = await connectedWallet.walletClient.writeContract({
907
+ address: contractAddress,
908
+ abi: MAILER_ABI,
909
+ functionName: 'distributeClaimableFunds',
910
+ args: [normalizeAddress(recipient)],
911
+ account,
912
+ chain: connectedWallet.walletClient.chain,
913
+ ...this.buildTxParams(gasLimit, gasOptions),
914
+ });
915
+ return { hash, estimatedGas: gasLimit, gasLimit };
916
+ }
917
+ }
918
+ EVMMailerClient.abi = MAILER_ABI;
919
+ EVMMailerClient.bytecode = MAILER_BYTECODE;
920
+ //# sourceMappingURL=evm-mailer-client.js.map