@sudobility/contracts 0.15.1 → 1.10.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 (166) hide show
  1. package/README.md +2 -3
  2. package/artifacts/contracts/Mailer.sol/Mailer.d.ts +2 -185
  3. package/artifacts/contracts/Mailer.sol/Mailer.dbg.json +1 -1
  4. package/artifacts/contracts/Mailer.sol/Mailer.json +2 -185
  5. package/artifacts/contracts/MockUSDC.sol/MockUSDC.dbg.json +1 -1
  6. package/artifacts/contracts/interfaces/IERC20.sol/IERC20.dbg.json +1 -1
  7. package/dist/evm/src/evm/index.d.ts +1 -1
  8. package/dist/evm/src/evm/index.d.ts.map +1 -1
  9. package/dist/evm/src/evm/index.js +4 -4
  10. package/dist/evm/src/evm/index.js.map +1 -1
  11. package/dist/evm/src/evm/mailer-client.d.ts +210 -0
  12. package/dist/evm/src/evm/mailer-client.d.ts.map +1 -0
  13. package/dist/evm/src/evm/mailer-client.js +417 -0
  14. package/dist/evm/src/evm/mailer-client.js.map +1 -0
  15. package/dist/evm/typechain-types/Mailer.d.ts +10 -128
  16. package/dist/evm/typechain-types/Mailer.d.ts.map +1 -1
  17. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts +1 -145
  18. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  19. package/dist/evm/typechain-types/factories/Mailer__factory.js +1 -184
  20. package/dist/evm/typechain-types/factories/Mailer__factory.js.map +1 -1
  21. package/dist/solana/solana/index.d.ts +1 -1
  22. package/dist/solana/solana/index.d.ts.map +1 -1
  23. package/dist/solana/solana/index.js +1 -4
  24. package/dist/solana/solana/index.js.map +1 -1
  25. package/dist/solana/solana/mailer-client.d.ts +209 -0
  26. package/dist/solana/solana/mailer-client.d.ts.map +1 -0
  27. package/dist/solana/solana/mailer-client.js +728 -0
  28. package/dist/solana/solana/mailer-client.js.map +1 -0
  29. package/dist/solana/solana/types.d.ts +2 -3
  30. package/dist/solana/solana/types.d.ts.map +1 -1
  31. package/dist/solana/solana/types.js.map +1 -1
  32. package/dist/unified/src/evm/index.d.ts +1 -1
  33. package/dist/unified/src/evm/index.d.ts.map +1 -1
  34. package/dist/unified/src/evm/index.js +4 -4
  35. package/dist/unified/src/evm/index.js.map +1 -1
  36. package/dist/unified/src/evm/mailer-client.d.ts +210 -0
  37. package/dist/unified/src/evm/mailer-client.d.ts.map +1 -0
  38. package/dist/unified/src/evm/mailer-client.js +417 -0
  39. package/dist/unified/src/evm/mailer-client.js.map +1 -0
  40. package/dist/unified/src/react/context/MailerProvider.d.ts +20 -26
  41. package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
  42. package/dist/unified/src/react/context/MailerProvider.js +26 -26
  43. package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
  44. package/dist/unified/src/react/hooks/useMailerMutations.d.ts +192 -225
  45. package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  46. package/dist/unified/src/react/hooks/useMailerMutations.js +266 -263
  47. package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
  48. package/dist/unified/src/react/hooks/useMailerQueries.d.ts +63 -117
  49. package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  50. package/dist/unified/src/react/hooks/useMailerQueries.js +104 -239
  51. package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
  52. package/dist/unified/src/react/index.d.ts +3 -5
  53. package/dist/unified/src/react/index.d.ts.map +1 -1
  54. package/dist/unified/src/react/index.js +26 -41
  55. package/dist/unified/src/react/index.js.map +1 -1
  56. package/dist/unified/src/solana/index.d.ts +1 -1
  57. package/dist/unified/src/solana/index.d.ts.map +1 -1
  58. package/dist/unified/src/solana/index.js +1 -4
  59. package/dist/unified/src/solana/index.js.map +1 -1
  60. package/dist/unified/src/solana/mailer-client.d.ts +209 -0
  61. package/dist/unified/src/solana/mailer-client.d.ts.map +1 -0
  62. package/dist/unified/src/solana/mailer-client.js +728 -0
  63. package/dist/unified/src/solana/mailer-client.js.map +1 -0
  64. package/dist/unified/src/solana/types.d.ts +2 -3
  65. package/dist/unified/src/solana/types.d.ts.map +1 -1
  66. package/dist/unified/src/solana/types.js.map +1 -1
  67. package/dist/unified/src/unified/index.d.ts +1 -1
  68. package/dist/unified/src/unified/index.d.ts.map +1 -1
  69. package/dist/unified/src/unified/onchain-mailer-client.d.ts +247 -192
  70. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  71. package/dist/unified/src/unified/onchain-mailer-client.js +1462 -551
  72. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  73. package/dist/unified/src/unified/types.d.ts +6 -23
  74. package/dist/unified/src/unified/types.d.ts.map +1 -1
  75. package/dist/unified/src/utils/chain-config.d.ts +2 -4
  76. package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
  77. package/dist/unified/src/utils/chain-config.js +36 -46
  78. package/dist/unified/src/utils/chain-config.js.map +1 -1
  79. package/dist/unified/typechain-types/Mailer.d.ts +10 -128
  80. package/dist/unified/typechain-types/Mailer.d.ts.map +1 -1
  81. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts +1 -145
  82. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  83. package/dist/unified/typechain-types/factories/Mailer__factory.js +1 -184
  84. package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
  85. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  86. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  87. package/dist/unified-esm/src/evm/index.js +2 -2
  88. package/dist/unified-esm/src/evm/index.js.map +1 -1
  89. package/dist/unified-esm/src/evm/mailer-client.d.ts +210 -0
  90. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +1 -0
  91. package/dist/unified-esm/src/evm/mailer-client.js +413 -0
  92. package/dist/unified-esm/src/evm/mailer-client.js.map +1 -0
  93. package/dist/unified-esm/src/react/context/MailerProvider.d.ts +20 -26
  94. package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
  95. package/dist/unified-esm/src/react/context/MailerProvider.js +26 -25
  96. package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
  97. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +192 -225
  98. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  99. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +262 -254
  100. package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
  101. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +63 -117
  102. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  103. package/dist/unified-esm/src/react/hooks/useMailerQueries.js +102 -232
  104. package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
  105. package/dist/unified-esm/src/react/index.d.ts +3 -5
  106. package/dist/unified-esm/src/react/index.d.ts.map +1 -1
  107. package/dist/unified-esm/src/react/index.js +5 -9
  108. package/dist/unified-esm/src/react/index.js.map +1 -1
  109. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  110. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  111. package/dist/unified-esm/src/solana/index.js +1 -2
  112. package/dist/unified-esm/src/solana/index.js.map +1 -1
  113. package/dist/unified-esm/src/solana/mailer-client.d.ts +209 -0
  114. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +1 -0
  115. package/dist/unified-esm/src/solana/mailer-client.js +724 -0
  116. package/dist/unified-esm/src/solana/mailer-client.js.map +1 -0
  117. package/dist/unified-esm/src/solana/types.d.ts +2 -3
  118. package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
  119. package/dist/unified-esm/src/solana/types.js.map +1 -1
  120. package/dist/unified-esm/src/unified/index.d.ts +1 -1
  121. package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
  122. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +247 -192
  123. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  124. package/dist/unified-esm/src/unified/onchain-mailer-client.js +1462 -551
  125. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  126. package/dist/unified-esm/src/unified/types.d.ts +6 -23
  127. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  128. package/dist/unified-esm/src/utils/chain-config.d.ts +2 -4
  129. package/dist/unified-esm/src/utils/chain-config.d.ts.map +1 -1
  130. package/dist/unified-esm/src/utils/chain-config.js +35 -46
  131. package/dist/unified-esm/src/utils/chain-config.js.map +1 -1
  132. package/dist/unified-esm/typechain-types/Mailer.d.ts +10 -128
  133. package/dist/unified-esm/typechain-types/Mailer.d.ts.map +1 -1
  134. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +1 -145
  135. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  136. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +1 -184
  137. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +1 -1
  138. package/package.json +10 -17
  139. package/programs/mailer/src/lib.rs +145 -764
  140. package/programs/mailer/tests/integration_tests.rs +65 -586
  141. package/typechain-types/Mailer.ts +8 -215
  142. package/typechain-types/factories/Mailer__factory.ts +1 -184
  143. package/dist/evm/src/evm/evm-mailer-client.d.ts +0 -1062
  144. package/dist/evm/src/evm/evm-mailer-client.d.ts.map +0 -1
  145. package/dist/evm/src/evm/evm-mailer-client.js +0 -924
  146. package/dist/evm/src/evm/evm-mailer-client.js.map +0 -1
  147. package/dist/solana/solana/solana-mailer-client.d.ts +0 -209
  148. package/dist/solana/solana/solana-mailer-client.d.ts.map +0 -1
  149. package/dist/solana/solana/solana-mailer-client.js +0 -1004
  150. package/dist/solana/solana/solana-mailer-client.js.map +0 -1
  151. package/dist/unified/src/evm/evm-mailer-client.d.ts +0 -1062
  152. package/dist/unified/src/evm/evm-mailer-client.d.ts.map +0 -1
  153. package/dist/unified/src/evm/evm-mailer-client.js +0 -924
  154. package/dist/unified/src/evm/evm-mailer-client.js.map +0 -1
  155. package/dist/unified/src/solana/solana-mailer-client.d.ts +0 -209
  156. package/dist/unified/src/solana/solana-mailer-client.d.ts.map +0 -1
  157. package/dist/unified/src/solana/solana-mailer-client.js +0 -1004
  158. package/dist/unified/src/solana/solana-mailer-client.js.map +0 -1
  159. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts +0 -1062
  160. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +0 -1
  161. package/dist/unified-esm/src/evm/evm-mailer-client.js +0 -920
  162. package/dist/unified-esm/src/evm/evm-mailer-client.js.map +0 -1
  163. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +0 -209
  164. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +0 -1
  165. package/dist/unified-esm/src/solana/solana-mailer-client.js +0 -1000
  166. package/dist/unified-esm/src/solana/solana-mailer-client.js.map +0 -1
@@ -0,0 +1,417 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MailerClient = void 0;
4
+ const viem_1 = require("viem");
5
+ const Mailer__factory_js_1 = require("../../typechain-types/factories/Mailer__factory.js");
6
+ // Get ABI from typechain-generated factories
7
+ const MAILER_ABI = Mailer__factory_js_1.Mailer__factory.abi;
8
+ // Get bytecode from typechain-generated factories
9
+ const MAILER_BYTECODE = Mailer__factory_js_1.Mailer__factory.bytecode;
10
+ /**
11
+ * @class MailerClient
12
+ * @description High-level TypeScript client for the Mailer contract using viem
13
+ * @notice Provides easy-to-use methods for sending messages with USDC fees and revenue sharing
14
+ *
15
+ * ## Key Features:
16
+ * - **Delegation Management**: Delegate mail handling with rejection capability
17
+ * - **Priority Messages**: Full fee (0.1 USDC) with 90% revenue share to recipient
18
+ * - **Standard Messages**: 10% fee only (0.01 USDC) with no revenue share
19
+ * - **Revenue Claims**: 60-day claim period for priority message revenue shares
20
+ *
21
+ * ## Usage Examples:
22
+ * ```typescript
23
+ * // Connect to existing contract
24
+ * import { createPublicClient, createWalletClient, http } from 'viem';
25
+ * import { mainnet } from 'viem/chains';
26
+ *
27
+ * const publicClient = createPublicClient({
28
+ * chain: mainnet,
29
+ * transport: http()
30
+ * });
31
+ *
32
+ * const mailer = new MailerClient('CONTRACT_ADDRESS', publicClient);
33
+ *
34
+ * // Send message with revenue sharing to recipient
35
+ * const walletClient = createWalletClient({
36
+ * chain: mainnet,
37
+ * transport: http()
38
+ * });
39
+ *
40
+ * await mailer.send('0x...', 'Subject', 'Body', true, walletClient, account);
41
+ *
42
+ * // Claim your revenue share (as recipient)
43
+ * await mailer.claimRecipientShare(walletClient, account);
44
+ * ```
45
+ */
46
+ class MailerClient {
47
+ /**
48
+ * @description Creates a new MailerClient instance
49
+ * @param contractAddress The deployed Mailer contract address
50
+ * @param publicClient Viem public client for reading blockchain state
51
+ */
52
+ constructor(contractAddress, publicClient) {
53
+ this.contractAddress = (0, viem_1.getAddress)(contractAddress);
54
+ this.publicClient = publicClient;
55
+ }
56
+ /**
57
+ * @description Deploy a new Mailer contract and return a client instance
58
+ * @param walletClient Viem wallet client with deployment permissions
59
+ * @param account Account to deploy from
60
+ * @param usdcTokenAddress Address of the USDC token contract
61
+ * @param ownerAddress Address that will own the deployed contract
62
+ * @returns Promise resolving to a MailerClient instance
63
+ */
64
+ static async deploy(walletClient, publicClient, account, usdcTokenAddress, ownerAddress) {
65
+ const hash = await walletClient.deployContract({
66
+ abi: MAILER_ABI,
67
+ bytecode: MAILER_BYTECODE,
68
+ args: [(0, viem_1.getAddress)(usdcTokenAddress), (0, viem_1.getAddress)(ownerAddress)],
69
+ account,
70
+ chain: walletClient.chain,
71
+ });
72
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
73
+ if (!receipt.contractAddress) {
74
+ throw new Error("Contract deployment failed");
75
+ }
76
+ return new MailerClient(receipt.contractAddress, publicClient);
77
+ }
78
+ /**
79
+ * @description Send a message with optional revenue sharing
80
+ * @notice Two modes:
81
+ * - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
82
+ * - revenueShareToReceiver=false: Sender pays 0.01 USDC only
83
+ * @param to Recipient address who receives the message and potential revenue share
84
+ * @param subject Message subject line
85
+ * @param body Message content
86
+ * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
87
+ * @param resolveSenderToName If true, resolve sender address to name via off-chain service
88
+ * @param walletClient Viem wallet client for transaction
89
+ * @param account Account to send from
90
+ * @returns Promise resolving to transaction hash
91
+ * @example
92
+ * ```typescript
93
+ * // Send with revenue share to recipient
94
+ * const hash = await mailer.send('0x...', 'Subject', 'Priority message', true, false, walletClient, account);
95
+ * // Send standard message (no revenue share)
96
+ * const hash2 = await mailer.send('0x...', 'Subject', 'Standard message', false, false, walletClient, account);
97
+ * await publicClient.waitForTransactionReceipt({ hash });
98
+ * ```
99
+ */
100
+ async send(to, subject, body, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
101
+ return await walletClient.writeContract({
102
+ address: this.contractAddress,
103
+ abi: MAILER_ABI,
104
+ functionName: 'send',
105
+ args: [to, subject, body, revenueShareToReceiver, resolveSenderToName],
106
+ account,
107
+ chain: walletClient.chain,
108
+ });
109
+ }
110
+ /**
111
+ * @description Send a message using a pre-prepared mail ID with optional revenue sharing
112
+ * @notice Two modes:
113
+ * - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
114
+ * - revenueShareToReceiver=false: Sender pays 0.01 USDC only
115
+ * @param to Recipient address who receives the message and potential revenue share
116
+ * @param mailId Pre-prepared message identifier
117
+ * @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
118
+ * @param resolveSenderToName If true, resolve sender address to name via off-chain service
119
+ * @param walletClient Viem wallet client for transaction
120
+ * @param account Account to send from
121
+ * @returns Promise resolving to transaction hash
122
+ */
123
+ async sendPrepared(to, mailId, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
124
+ return await walletClient.writeContract({
125
+ address: this.contractAddress,
126
+ abi: MAILER_ABI,
127
+ functionName: 'sendPrepared',
128
+ args: [to, mailId, revenueShareToReceiver, resolveSenderToName],
129
+ account,
130
+ chain: walletClient.chain,
131
+ });
132
+ }
133
+ async getSendFee() {
134
+ return await this.publicClient.readContract({
135
+ address: this.contractAddress,
136
+ abi: MAILER_ABI,
137
+ functionName: 'sendFee',
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ });
140
+ }
141
+ async getUsdcToken() {
142
+ return await this.publicClient.readContract({
143
+ address: this.contractAddress,
144
+ abi: MAILER_ABI,
145
+ functionName: 'usdcToken',
146
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
+ });
148
+ }
149
+ getAddress() {
150
+ return this.contractAddress;
151
+ }
152
+ async claimRecipientShare(walletClient, account) {
153
+ return await walletClient.writeContract({
154
+ address: this.contractAddress,
155
+ abi: MAILER_ABI,
156
+ functionName: 'claimRecipientShare',
157
+ account,
158
+ chain: walletClient.chain,
159
+ });
160
+ }
161
+ async claimOwnerShare(walletClient, account) {
162
+ return await walletClient.writeContract({
163
+ address: this.contractAddress,
164
+ abi: MAILER_ABI,
165
+ functionName: 'claimOwnerShare',
166
+ account,
167
+ chain: walletClient.chain,
168
+ });
169
+ }
170
+ async claimExpiredShares(recipient, walletClient, account) {
171
+ return await walletClient.writeContract({
172
+ address: this.contractAddress,
173
+ abi: MAILER_ABI,
174
+ functionName: 'claimExpiredShares',
175
+ args: [(0, viem_1.getAddress)(recipient)],
176
+ account,
177
+ chain: walletClient.chain,
178
+ });
179
+ }
180
+ async getRecipientClaimable(recipient) {
181
+ const result = await this.publicClient.readContract({
182
+ address: this.contractAddress,
183
+ abi: MAILER_ABI,
184
+ functionName: 'getRecipientClaimable',
185
+ args: [(0, viem_1.getAddress)(recipient)],
186
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
+ });
188
+ return {
189
+ amount: result[0],
190
+ expiresAt: result[1],
191
+ isExpired: result[2]
192
+ };
193
+ }
194
+ async getOwnerClaimable() {
195
+ return await this.publicClient.readContract({
196
+ address: this.contractAddress,
197
+ abi: MAILER_ABI,
198
+ functionName: 'getOwnerClaimable'
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ });
201
+ }
202
+ // Delegation functionality
203
+ /**
204
+ * Delegate mail handling to another address
205
+ * @param delegate Address to delegate to (or 0x0 to clear delegation)
206
+ * @param walletClient Connected wallet client
207
+ * @param account Account to send transaction from
208
+ * @returns Transaction hash
209
+ */
210
+ async delegateTo(delegate, walletClient, account) {
211
+ return await walletClient.writeContract({
212
+ address: this.contractAddress,
213
+ abi: MAILER_ABI,
214
+ functionName: 'delegateTo',
215
+ args: [(0, viem_1.getAddress)(delegate)],
216
+ account,
217
+ chain: walletClient.chain,
218
+ });
219
+ }
220
+ /**
221
+ * Reject a delegation made to you by another address
222
+ * @param delegatingAddress Address that delegated to you
223
+ * @param walletClient Connected wallet client
224
+ * @param account Account to send transaction from
225
+ * @returns Transaction hash
226
+ */
227
+ async rejectDelegation(delegatingAddress, walletClient, account) {
228
+ return await walletClient.writeContract({
229
+ address: this.contractAddress,
230
+ abi: MAILER_ABI,
231
+ functionName: 'rejectDelegation',
232
+ args: [(0, viem_1.getAddress)(delegatingAddress)],
233
+ account,
234
+ chain: walletClient.chain,
235
+ });
236
+ }
237
+ /**
238
+ * Get current delegation fee in USDC (6 decimals)
239
+ * @returns Delegation fee amount
240
+ */
241
+ async getDelegationFee() {
242
+ return await this.publicClient.readContract({
243
+ address: this.contractAddress,
244
+ abi: MAILER_ABI,
245
+ functionName: 'getDelegationFee',
246
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
+ });
248
+ }
249
+ /**
250
+ * Update delegation fee (owner only)
251
+ * @param newFee New fee amount in USDC (6 decimals)
252
+ * @param walletClient Connected wallet client
253
+ * @param account Account to send transaction from
254
+ * @returns Transaction hash
255
+ */
256
+ async setDelegationFee(newFee, walletClient, account) {
257
+ return await walletClient.writeContract({
258
+ address: this.contractAddress,
259
+ abi: MAILER_ABI,
260
+ functionName: 'setDelegationFee',
261
+ args: [newFee],
262
+ account,
263
+ chain: walletClient.chain,
264
+ });
265
+ }
266
+ /**
267
+ * @description Send a message to an email address (no wallet known)
268
+ * @notice Charges only 10% owner fee since recipient wallet is unknown
269
+ * @param toEmail Email address of the recipient
270
+ * @param subject Message subject line
271
+ * @param body Message content
272
+ * @param walletClient Viem wallet client for transaction
273
+ * @param account Account to send from
274
+ * @returns Promise resolving to transaction hash
275
+ * @example
276
+ * ```typescript
277
+ * // Send to email address
278
+ * const hash = await mailer.sendToEmailAddress('user@example.com', 'Subject', 'Body', walletClient, account);
279
+ * await publicClient.waitForTransactionReceipt({ hash });
280
+ * ```
281
+ */
282
+ async sendToEmailAddress(toEmail, subject, body, walletClient, account) {
283
+ return await walletClient.writeContract({
284
+ address: this.contractAddress,
285
+ abi: MAILER_ABI,
286
+ functionName: 'sendToEmailAddress',
287
+ args: [toEmail, subject, body],
288
+ account,
289
+ chain: walletClient.chain,
290
+ });
291
+ }
292
+ /**
293
+ * @description Send a pre-prepared message to an email address (no wallet known)
294
+ * @notice Charges only 10% owner fee since recipient wallet is unknown
295
+ * @param toEmail Email address of the recipient
296
+ * @param mailId Pre-prepared message identifier
297
+ * @param walletClient Viem wallet client for transaction
298
+ * @param account Account to send from
299
+ * @returns Promise resolving to transaction hash
300
+ */
301
+ async sendPreparedToEmailAddress(toEmail, mailId, walletClient, account) {
302
+ return await walletClient.writeContract({
303
+ address: this.contractAddress,
304
+ abi: MAILER_ABI,
305
+ functionName: 'sendPreparedToEmailAddress',
306
+ args: [toEmail, mailId],
307
+ account,
308
+ chain: walletClient.chain,
309
+ });
310
+ }
311
+ /**
312
+ * Set the send fee (owner only)
313
+ * @param newFee New fee amount in USDC (6 decimals)
314
+ * @param walletClient Viem wallet client for transaction
315
+ * @param account Account to send from (must be owner)
316
+ * @returns Promise resolving to transaction hash
317
+ */
318
+ async setFee(newFee, walletClient, account) {
319
+ return await walletClient.writeContract({
320
+ address: this.contractAddress,
321
+ abi: MAILER_ABI,
322
+ functionName: 'setFee',
323
+ args: [newFee],
324
+ account,
325
+ chain: walletClient.chain,
326
+ });
327
+ }
328
+ /**
329
+ * Get the current send fee
330
+ * @returns Current send fee in USDC (6 decimals)
331
+ */
332
+ async getFee() {
333
+ return await this.publicClient.readContract({
334
+ address: this.contractAddress,
335
+ abi: MAILER_ABI,
336
+ functionName: 'getFee',
337
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
338
+ });
339
+ }
340
+ /**
341
+ * Pause the contract and distribute all claimable funds (owner only)
342
+ * @param walletClient Viem wallet client for transaction
343
+ * @param account Account to send from (must be owner)
344
+ * @returns Promise resolving to transaction hash
345
+ */
346
+ async pause(walletClient, account) {
347
+ return await walletClient.writeContract({
348
+ address: this.contractAddress,
349
+ abi: MAILER_ABI,
350
+ functionName: 'pause',
351
+ account,
352
+ chain: walletClient.chain,
353
+ });
354
+ }
355
+ /**
356
+ * Unpause the contract (owner only)
357
+ * @param walletClient Viem wallet client for transaction
358
+ * @param account Account to send from (must be owner)
359
+ * @returns Promise resolving to transaction hash
360
+ */
361
+ async unpause(walletClient, account) {
362
+ return await walletClient.writeContract({
363
+ address: this.contractAddress,
364
+ abi: MAILER_ABI,
365
+ functionName: 'unpause',
366
+ account,
367
+ chain: walletClient.chain,
368
+ });
369
+ }
370
+ /**
371
+ * Emergency unpause without fund distribution (owner only)
372
+ * @param walletClient Viem wallet client for transaction
373
+ * @param account Account to send from (must be owner)
374
+ * @returns Promise resolving to transaction hash
375
+ */
376
+ async emergencyUnpause(walletClient, account) {
377
+ return await walletClient.writeContract({
378
+ address: this.contractAddress,
379
+ abi: MAILER_ABI,
380
+ functionName: 'emergencyUnpause',
381
+ account,
382
+ chain: walletClient.chain,
383
+ });
384
+ }
385
+ /**
386
+ * Check if contract is currently paused
387
+ * @returns True if contract is paused, false otherwise
388
+ */
389
+ async isPaused() {
390
+ return await this.publicClient.readContract({
391
+ address: this.contractAddress,
392
+ abi: MAILER_ABI,
393
+ functionName: 'isPaused',
394
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+ });
396
+ }
397
+ /**
398
+ * Distribute a specific recipient's claimable funds during pause
399
+ * Anyone can call this function when contract is paused
400
+ * @param recipient Address to distribute funds for
401
+ * @param walletClient Viem wallet client for transaction
402
+ * @param account Account to send from
403
+ * @returns Promise resolving to transaction hash
404
+ */
405
+ async distributeClaimableFunds(recipient, walletClient, account) {
406
+ return await walletClient.writeContract({
407
+ address: this.contractAddress,
408
+ abi: MAILER_ABI,
409
+ functionName: 'distributeClaimableFunds',
410
+ args: [(0, viem_1.getAddress)(recipient)],
411
+ account,
412
+ chain: walletClient.chain,
413
+ });
414
+ }
415
+ }
416
+ exports.MailerClient = MailerClient;
417
+ //# sourceMappingURL=mailer-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailer-client.js","sourceRoot":"","sources":["../../../../src/evm/mailer-client.ts"],"names":[],"mappings":";;;AAAA,+BAOc;AACd,2FAAqF;AAErF,6CAA6C;AAC7C,MAAM,UAAU,GAAG,oCAAe,CAAC,GAAG,CAAC;AAEvC,kDAAkD;AAClD,MAAM,eAAe,GAAG,oCAAe,CAAC,QAAyB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,YAAY;IAIvB;;;;OAIG;IACH,YAAY,eAAuB,EAAE,YAA0B;QAC7D,IAAI,CAAC,eAAe,GAAG,IAAA,iBAAU,EAAC,eAAe,CAAC,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,YAA0B,EAC1B,YAA0B,EAC1B,OAA0B,EAC1B,gBAAwB,EACxB,YAAoB;QAEpB,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,cAAc,CAAC;YAC7C,GAAG,EAAE,UAAU;YACf,QAAQ,EAAE,eAAe;YACzB,IAAI,EAAE,CAAC,IAAA,iBAAU,EAAC,gBAAgB,C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a,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,SAAS;YACvB,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,gBAAgB,CACpB,YAA0B,EAC1B,OAA0B;QAE1B,OAAO,MAAM,YAAY,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,kBAAkB;YAChC,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YAC1C,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,UAAU;YACxB,8DAA8D;SACxD,CAAY,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,wBAAwB,CAC5B,SAAiB,EACjB,YAA0B,EAC1B,OAA0B;QAE1B,OAAO,MAAM,YAAY,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,IAAA,iBAAU,EAAC,SAAS,CAAC,CAAC;YAC7B,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;CACF;AAxdD,oCAwdC"}
@@ -1,16 +1,7 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { QueryClient } from '@tanstack/react-query';
3
3
  import { OnchainMailerClient } from '../../unified/onchain-mailer-client';
4
- import type { ChainInfo } from '../../unified/types';
5
- import type { Wallet } from '../../unified/types';
6
- /**
7
- * Context for Mailer client and configuration
8
- */
9
- interface MailerContextValue {
10
- client: OnchainMailerClient;
11
- wallet: Wallet;
12
- chainInfo: ChainInfo;
13
- }
4
+ import type { ChainConfig } from '../../unified/types';
14
5
  /**
15
6
  * Props for MailerProvider
16
7
  */
@@ -18,9 +9,9 @@ export interface MailerProviderProps {
18
9
  /** Child components */
19
10
  children: ReactNode;
20
11
  /** Wallet instance (EVM or Solana) */
21
- wallet: Wallet;
22
- /** Chain information */
23
- chainInfo: ChainInfo;
12
+ wallet: any;
13
+ /** Chain configuration */
14
+ config: ChainConfig;
24
15
  /** Optional React Query client (creates default if not provided) */
25
16
  queryClient?: QueryClient;
26
17
  }
@@ -33,14 +24,22 @@ export interface MailerProviderProps {
33
24
  * @example
34
25
  * ```tsx
35
26
  * import { MailerProvider } from '@johnqh/mail_box_contracts/react';
36
- * import { getChainInfo } from '@sudobility/configs';
37
27
  *
38
28
  * function App() {
39
29
  * const wallet = useWallet(); // Your wallet hook
40
- * const chainInfo = getChainInfo('ethereum'); // Get chain configuration
30
+ * const config = {
31
+ * evm: {
32
+ * rpc: 'https://eth-mainnet.g.alchemy.com/v2/YOUR-KEY',
33
+ * chainId: 1,
34
+ * contracts: {
35
+ * mailer: '0x123...',
36
+ * usdc: '0x456...'
37
+ * }
38
+ * }
39
+ * };
41
40
  *
42
41
  * return (
43
- * <MailerProvider wallet={wallet} chainInfo={chainInfo}>
42
+ * <MailerProvider wallet={wallet} config={config}>
44
43
  * <YourApp />
45
44
  * </MailerProvider>
46
45
  * );
@@ -63,7 +62,7 @@ export interface MailerProviderProps {
63
62
  * return (
64
63
  * <MailerProvider
65
64
  * wallet={wallet}
66
- * chainInfo={chainInfo}
65
+ * config={config}
67
66
  * queryClient={customQueryClient}
68
67
  * >
69
68
  * <YourApp />
@@ -72,9 +71,9 @@ export interface MailerProviderProps {
72
71
  * }
73
72
  * ```
74
73
  */
75
- export declare function MailerProvider({ children, wallet, chainInfo, queryClient }: MailerProviderProps): React.JSX.Element;
74
+ export declare function MailerProvider({ children, wallet, config, queryClient }: MailerProviderProps): React.JSX.Element;
76
75
  /**
77
- * Hook to access the Mailer context
76
+ * Hook to access the OnchainMailerClient instance
78
77
  *
79
78
  * Must be used within a MailerProvider component.
80
79
  *
@@ -83,11 +82,11 @@ export declare function MailerProvider({ children, wallet, chainInfo, queryClien
83
82
  * @example
84
83
  * ```tsx
85
84
  * function MyComponent() {
86
- * const { client, wallet, chainInfo } = useMailerContext();
85
+ * const client = useMailerClient();
87
86
  *
88
87
  * const handleDirectCall = async () => {
89
88
  * // Direct API call (not recommended, use hooks instead)
90
- * const fee = await client.getSendFee(wallet, chainInfo);
89
+ * const fee = await client.getSendFee();
91
90
  * console.log('Fee:', fee);
92
91
  * };
93
92
  *
@@ -95,11 +94,6 @@ export declare function MailerProvider({ children, wallet, chainInfo, queryClien
95
94
  * }
96
95
  * ```
97
96
  */
98
- export declare function useMailerContext(): MailerContextValue;
99
- /**
100
- * Hook to access the OnchainMailerClient instance
101
- * @deprecated Use useMailerContext() instead to get client, wallet, and chainInfo
102
- */
103
97
  export declare function useMailerClient(): OnchainMailerClient;
104
98
  /**
105
99
  * Re-export QueryClientProvider for convenience
@@ -1 +1 @@
1
- {"version":3,"file":"MailerProvider.d.ts","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,UAAU,kBAAkB;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CA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;;;;;;;;;GAuDG;AACH,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,mBAAmB,qBAgB5F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,IAAI,mBAAmB,CAQrD;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}
@@ -35,11 +35,13 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.QueryClient = exports.QueryClientProvider = void 0;
37
37
  exports.MailerProvider = MailerProvider;
38
- exports.useMailerContext = useMailerContext;
39
38
  exports.useMailerClient = useMailerClient;
40
39
  const react_1 = __importStar(require("react"));
41
40
  const react_query_1 = require("@tanstack/react-query");
42
41
  const onchain_mailer_client_1 = require("../../unified/onchain-mailer-client");
42
+ /**
43
+ * Context for OnchainMailerClient
44
+ */
43
45
  const MailerClientContext = (0, react_1.createContext)(null);
44
46
  /**
45
47
  * Default React Query client with sensible defaults for blockchain queries
@@ -66,14 +68,22 @@ const defaultQueryClient = new react_query_1.QueryClient({
66
68
  * @example
67
69
  * ```tsx
68
70
  * import { MailerProvider } from '@johnqh/mail_box_contracts/react';
69
- * import { getChainInfo } from '@sudobility/configs';
70
71
  *
71
72
  * function App() {
72
73
  * const wallet = useWallet(); // Your wallet hook
73
- * const chainInfo = getChainInfo('ethereum'); // Get chain configuration
74
+ * const config = {
75
+ * evm: {
76
+ * rpc: 'https://eth-mainnet.g.alchemy.com/v2/YOUR-KEY',
77
+ * chainId: 1,
78
+ * contracts: {
79
+ * mailer: '0x123...',
80
+ * usdc: '0x456...'
81
+ * }
82
+ * }
83
+ * };
74
84
  *
75
85
  * return (
76
- * <MailerProvider wallet={wallet} chainInfo={chainInfo}>
86
+ * <MailerProvider wallet={wallet} config={config}>
77
87
  * <YourApp />
78
88
  * </MailerProvider>
79
89
  * );
@@ -96,7 +106,7 @@ const defaultQueryClient = new react_query_1.QueryClient({
96
106
  * return (
97
107
  * <MailerProvider
98
108
  * wallet={wallet}
99
- * chainInfo={chainInfo}
109
+ * config={config}
100
110
  * queryClient={customQueryClient}
101
111
  * >
102
112
  * <YourApp />
@@ -105,17 +115,15 @@ const defaultQueryClient = new react_query_1.QueryClient({
105
115
  * }
106
116
  * ```
107
117
  */
108
- function MailerProvider({ children, wallet, chainInfo, queryClient }) {
109
- // Create OnchainMailerClient instance (stateless, no constructor params)
110
- const client = react_1.default.useMemo(() => new onchain_mailer_client_1.OnchainMailerClient(), []);
111
- // Create context value with client, wallet, and chainInfo
112
- const contextValue = react_1.default.useMemo(() => ({ client, wallet, chainInfo }), [client, wallet, chainInfo]);
118
+ function MailerProvider({ children, wallet, config, queryClient }) {
119
+ // Create OnchainMailerClient instance
120
+ const client = react_1.default.useMemo(() => new onchain_mailer_client_1.OnchainMailerClient(wallet, config), [wallet, config]);
113
121
  const qc = queryClient || defaultQueryClient;
114
122
  return (react_1.default.createElement(react_query_1.QueryClientProvider, { client: qc },
115
- react_1.default.createElement(MailerClientContext.Provider, { value: contextValue }, children)));
123
+ react_1.default.createElement(MailerClientContext.Provider, { value: client }, children)));
116
124
  }
117
125
  /**
118
- * Hook to access the Mailer context
126
+ * Hook to access the OnchainMailerClient instance
119
127
  *
120
128
  * Must be used within a MailerProvider component.
121
129
  *
@@ -124,11 +132,11 @@ function MailerProvider({ children, wallet, chainInfo, queryClient }) {
124
132
  * @example
125
133
  * ```tsx
126
134
  * function MyComponent() {
127
- * const { client, wallet, chainInfo } = useMailerContext();
135
+ * const client = useMailerClient();
128
136
  *
129
137
  * const handleDirectCall = async () => {
130
138
  * // Direct API call (not recommended, use hooks instead)
131
- * const fee = await client.getSendFee(wallet, chainInfo);
139
+ * const fee = await client.getSendFee();
132
140
  * console.log('Fee:', fee);
133
141
  * };
134
142
  *
@@ -136,19 +144,11 @@ function MailerProvider({ children, wallet, chainInfo, queryClient }) {
136
144
  * }
137
145
  * ```
138
146
  */
139
- function useMailerContext() {
140
- const context = (0, react_1.useContext)(MailerClientContext);
141
- if (!context) {
142
- throw new Error('useMailerContext must be used within a MailerProvider');
143
- }
144
- return context;
145
- }
146
- /**
147
- * Hook to access the OnchainMailerClient instance
148
- * @deprecated Use useMailerContext() instead to get client, wallet, and chainInfo
149
- */
150
147
  function useMailerClient() {
151
- const { client } = useMailerContext();
148
+ const client = (0, react_1.useContext)(MailerClientContext);
149
+ if (!client) {
150
+ throw new Error('useMailerClient must be used within a MailerProvider');
151
+ }
152
152
  return client;
153
153
  }
154
154
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"MailerProvider.js","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,wCAsBC;AAwBD,4CAQC;AAMD,0CAGC;AA/JD,+CAAoE;AACpE,uDAAyE;AACzE,+EAA0E;AAa1E,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAA4B,IAAI,CAAC,CAAC;AAgB3E;;GAEG;AACH,MAAM,kBAAkB,GAAG,IAAI,yBAAW,CAAC;IACzC,cAAc,EAAE;QACd,OAAO,EAAE;YACP,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,YAAY,EAAE,KAAK,CAAC;YACvE,oBAAoB,EAAE,KAAK;YAC3B,SAAS,EAAE,EAAE,GAAG,IAAI,EAAE,qBAAqB;SAC5C;QACD,SAAS,EAAE;YACT,KAAK,EAAE,CAAC;SACT;KACF;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAuB;IAC9F,yEAAyE;I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