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