@sudobility/contracts 0.14.0 → 0.15.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 (123) 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/onchain-mailer-client.d.ts +224 -139
  56. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  57. package/dist/unified/src/unified/onchain-mailer-client.js +577 -857
  58. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  59. package/dist/unified/src/unified/types.d.ts +9 -2
  60. package/dist/unified/src/unified/types.d.ts.map +1 -1
  61. package/dist/{unified/src/evm/mailer-client.d.ts → unified-esm/src/evm/evm-mailer-client.d.ts} +146 -50
  62. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +1 -0
  63. package/dist/unified-esm/src/evm/evm-mailer-client.js +920 -0
  64. package/dist/unified-esm/src/evm/evm-mailer-client.js.map +1 -0
  65. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  66. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  67. package/dist/unified-esm/src/evm/index.js +2 -2
  68. package/dist/unified-esm/src/evm/index.js.map +1 -1
  69. package/dist/unified-esm/src/react/context/MailerProvider.d.ts +26 -20
  70. package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
  71. package/dist/unified-esm/src/react/context/MailerProvider.js +25 -26
  72. package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
  73. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +225 -192
  74. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  75. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +254 -262
  76. package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
  77. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +117 -63
  78. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  79. package/dist/unified-esm/src/react/hooks/useMailerQueries.js +232 -102
  80. package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
  81. package/dist/unified-esm/src/react/index.d.ts +5 -3
  82. package/dist/unified-esm/src/react/index.d.ts.map +1 -1
  83. package/dist/unified-esm/src/react/index.js +9 -5
  84. package/dist/unified-esm/src/react/index.js.map +1 -1
  85. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  86. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  87. package/dist/unified-esm/src/solana/index.js +2 -1
  88. package/dist/unified-esm/src/solana/index.js.map +1 -1
  89. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +209 -0
  90. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +1 -0
  91. package/dist/unified-esm/src/solana/solana-mailer-client.js +1000 -0
  92. package/dist/unified-esm/src/solana/solana-mailer-client.js.map +1 -0
  93. package/dist/unified-esm/src/solana/types.d.ts +3 -2
  94. package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
  95. package/dist/unified-esm/src/solana/types.js.map +1 -1
  96. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +224 -139
  97. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  98. package/dist/unified-esm/src/unified/onchain-mailer-client.js +579 -859
  99. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  100. package/dist/unified-esm/src/unified/types.d.ts +9 -2
  101. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  102. package/package.json +3 -3
  103. package/dist/evm/src/evm/mailer-client.d.ts.map +0 -1
  104. package/dist/evm/src/evm/mailer-client.js +0 -619
  105. package/dist/evm/src/evm/mailer-client.js.map +0 -1
  106. package/dist/solana/solana/mailer-client.d.ts +0 -282
  107. package/dist/solana/solana/mailer-client.d.ts.map +0 -1
  108. package/dist/solana/solana/mailer-client.js +0 -989
  109. package/dist/solana/solana/mailer-client.js.map +0 -1
  110. package/dist/unified/src/evm/mailer-client.d.ts.map +0 -1
  111. package/dist/unified/src/evm/mailer-client.js +0 -619
  112. package/dist/unified/src/evm/mailer-client.js.map +0 -1
  113. package/dist/unified/src/solana/mailer-client.d.ts +0 -282
  114. package/dist/unified/src/solana/mailer-client.d.ts.map +0 -1
  115. package/dist/unified/src/solana/mailer-client.js +0 -989
  116. package/dist/unified/src/solana/mailer-client.js.map +0 -1
  117. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +0 -1
  118. package/dist/unified-esm/src/evm/mailer-client.js +0 -615
  119. package/dist/unified-esm/src/evm/mailer-client.js.map +0 -1
  120. package/dist/unified-esm/src/solana/mailer-client.d.ts +0 -282
  121. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +0 -1
  122. package/dist/unified-esm/src/solana/mailer-client.js +0 -985
  123. package/dist/unified-esm/src/solana/mailer-client.js.map +0 -1
@@ -38,1011 +38,731 @@ exports.OnchainMailerClient = void 0;
38
38
  // @ts-nocheck - Suppress false TypeScript errors with ESNext modules accessing class properties
39
39
  const types_1 = require("@sudobility/types");
40
40
  /**
41
- * OnchainMailerClient v2 - Refactored to use standard wallet libraries
41
+ * OnchainMailerClient - Stateless multi-chain messaging client
42
42
  *
43
- * This version removes the UnifiedWallet abstraction and instead accepts
44
- * standard wallet clients from wagmi (EVM) or wallet-adapter (Solana).
43
+ * This version uses stateless EVM and Solana clients underneath.
44
+ * All wallet connections and chain information are passed as parameters to each method.
45
45
  *
46
- * @example EVM Usage with wagmi
46
+ * @example EVM Usage
47
47
  * ```typescript
48
48
  * import { createWalletClient, createPublicClient, http } from 'viem';
49
- * import { mainnet } from 'viem/chains';
49
+ * import { RpcHelpers } from '@sudobility/configs';
50
+ * import { Chain } from '@sudobility/types';
50
51
  *
52
+ * const chainInfo = RpcHelpers.getChainInfo(Chain.ETH_MAINNET);
51
53
  * const walletClient = createWalletClient({
52
54
  * chain: mainnet,
53
55
  * transport: http()
54
56
  * });
55
- * const publicClient = createPublicClient({
56
- * chain: mainnet,
57
- * transport: http()
58
- * });
59
57
  *
60
- * const client = OnchainMailerClient.forEVM(
61
- * walletClient,
62
- * publicClient,
63
- * '0xMailerContractAddress',
64
- * '0xUSDCAddress'
58
+ * const client = new OnchainMailerClient();
59
+ * await client.sendMessage(
60
+ * 'Subject',
61
+ * 'Body',
62
+ * { walletClient },
63
+ * chainInfo,
64
+ * { priority: true }
65
65
  * );
66
66
  * ```
67
67
  *
68
- * @example Solana Usage with wallet-adapter
68
+ * @example Solana Usage
69
69
  * ```typescript
70
70
  * import { useWallet } from '@solana/wallet-adapter-react';
71
71
  * import { Connection } from '@solana/web3.js';
72
+ * import { RpcHelpers } from '@sudobility/configs';
73
+ * import { Chain } from '@sudobility/types';
72
74
  *
75
+ * const chainInfo = RpcHelpers.getChainInfo(Chain.SOLANA_MAINNET);
73
76
  * const wallet = useWallet();
74
- * const connection = new Connection('https://api.mainnet-beta.solana.com');
75
77
  *
76
- * const client = OnchainMailerClient.forSolana(
77
- * wallet,
78
- * connection,
79
- * 'MailerProgramId',
80
- * 'USDCMintAddress'
78
+ * const client = new OnchainMailerClient();
79
+ * await client.sendMessage(
80
+ * 'Subject',
81
+ * 'Body',
82
+ * { wallet },
83
+ * chainInfo,
84
+ * { priority: true }
81
85
  * );
82
86
  * ```
83
87
  */
84
88
  class OnchainMailerClient {
85
89
  /**
86
- * Create an OnchainMailerClient for EVM chains using wagmi clients
87
- *
88
- * @param walletClient - wagmi WalletClient for signing transactions
89
- * @param publicClient - wagmi PublicClient for reading chain data
90
- * @param mailerAddress - Deployed Mailer contract address
91
- * @param usdcAddress - USDC token contract address
92
- * @returns Configured OnchainMailerClient for EVM
90
+ * Create a new stateless OnchainMailerClient
91
+ * No configuration needed in constructor
93
92
  */
94
- static forEVM(walletClient, publicClient, mailerAddress, usdcAddress) {
95
- const client = new OnchainMailerClient({}, { evm: undefined, solana: undefined });
96
- client.chainType = types_1.ChainType.EVM;
97
- client.evmWalletClient = walletClient;
98
- client.evmPublicClient = publicClient;
99
- client.evmContractAddress = mailerAddress;
100
- client.evmUsdcAddress = usdcAddress;
101
- return client;
93
+ constructor() {
94
+ // Stateless - no initialization needed
102
95
  }
103
- /**
104
- * Create an OnchainMailerClient for Solana using wallet-adapter
105
- *
106
- * @param wallet - Solana wallet adapter
107
- * @param connection - Solana connection
108
- * @param programId - Deployed Mailer program ID
109
- * @param usdcMint - USDC mint address
110
- * @returns Configured OnchainMailerClient for Solana
111
- */
112
- static forSolana(
113
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
- wallet, // Wallet adapter interface
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- connection, // Connection
117
- programId, usdcMint) {
118
- const client = new OnchainMailerClient({}, { evm: undefined, solana: undefined });
119
- client.chainType = types_1.ChainType.SOLANA;
120
- client.solanaWallet = wallet;
121
- client.solanaConnection = connection;
122
- client.solanaProgramId = programId;
123
- client.solanaUsdcMint = usdcMint;
124
- return client;
96
+ // Performance optimization: cache client imports
97
+ async getEVMClient() {
98
+ if (!OnchainMailerClient.evmClient) {
99
+ const { EVMMailerClient } = await Promise.resolve().then(() => __importStar(require('../evm/evm-mailer-client.js')));
100
+ OnchainMailerClient.evmClient = new EVMMailerClient();
101
+ }
102
+ return OnchainMailerClient.evmClient;
103
+ }
104
+ async getSolanaClient() {
105
+ if (!OnchainMailerClient.solanaClient) {
106
+ const { SolanaMailerClient } = await Promise.resolve().then(() => __importStar(require('../solana/solana-mailer-client.js')));
107
+ OnchainMailerClient.solanaClient = new SolanaMailerClient();
108
+ }
109
+ return OnchainMailerClient.solanaClient;
125
110
  }
126
111
  /**
127
- * Create an OnchainMailerClient from a generic config (backward compatibility)
128
- * This constructor is provided for backward compatibility with React provider
112
+ * Send a message on the blockchain
113
+ * @param subject - Message subject (1-200 characters)
114
+ * @param body - Message body (1-10000 characters)
115
+ * @param wallet - Wallet connection (EVM or Solana)
116
+ * @param chainInfo - Chain information including RPC endpoints and contract addresses
117
+ * @param options - Optional parameters
118
+ * @returns Transaction result
129
119
  */
130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
- constructor(wallet, config) {
132
- // Simple chain detection based on wallet properties
133
- const hasEthereumProperties = wallet && (wallet.address || wallet.request || wallet.selectedAddress);
134
- const hasSolanaProperties = wallet && wallet.publicKey && typeof wallet.signTransaction === 'function';
135
- if (hasEthereumProperties) {
136
- this.chainType = types_1.ChainType.EVM;
137
- if (config.evm) {
138
- // Store config for lazy initialization
139
- this.evmContractAddress = config.evm.contracts.mailer;
140
- this.evmUsdcAddress = config.evm.contracts.usdc;
141
- // Wallet and public clients will be created on first use
142
- // Store raw wallet for backward compatibility
143
- // @ts-ignore
144
- this._rawEvmWallet = wallet;
145
- }
146
- else {
147
- throw new Error('EVM configuration required for EVM wallet');
148
- }
149
- }
150
- else if (hasSolanaProperties) {
151
- this.chainType = types_1.ChainType.SOLANA;
152
- if (config.solana) {
153
- this.solanaWallet = wallet;
154
- // Connection will be created on first use
155
- this.solanaProgramId = config.solana.programs.mailer;
156
- this.solanaUsdcMint = config.solana.usdcMint;
157
- }
158
- else {
159
- throw new Error('Solana configuration required for Solana wallet');
160
- }
120
+ async sendMessage(connectedWallet, chainInfo, subject, body, options) {
121
+ // Validate message
122
+ if (!subject || subject.length > 200) {
123
+ throw new Error('Subject must be 1-200 characters');
124
+ }
125
+ if (!body || body.length > 10000) {
126
+ throw new Error('Body must be 1-10000 characters');
127
+ }
128
+ // Route to appropriate implementation based on chain type
129
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
130
+ const evmClient = await this.getEVMClient();
131
+ const evmWallet = connectedWallet;
132
+ const [account] = await evmWallet.walletClient.getAddresses();
133
+ const to = options?.to || account;
134
+ const priority = options?.priority ?? false;
135
+ const resolveSenderToName = options?.resolveSenderToName ?? false;
136
+ const result = await evmClient.send(evmWallet, chainInfo, to, subject, body, account, // payer
137
+ priority, // revenueShareToReceiver
138
+ resolveSenderToName, options?.gasOptions);
139
+ return {
140
+ transactionHash: result.hash,
141
+ chainType: types_1.ChainType.EVM,
142
+ fee: BigInt(priority ? '100000' : '10000'),
143
+ gasUsed: result.gasUsed,
144
+ isPriority: priority,
145
+ success: true
146
+ };
147
+ }
148
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
149
+ const solanaClient = await this.getSolanaClient();
150
+ const solanaWallet = connectedWallet;
151
+ const to = options?.to || solanaWallet.wallet.publicKey.toBase58();
152
+ const priority = options?.priority ?? false;
153
+ const result = await solanaClient.send(solanaWallet, chainInfo, to, subject, body, priority, // revenueShareToReceiver
154
+ options?.computeOptions);
155
+ return {
156
+ transactionHash: result.transactionHash,
157
+ chainType: types_1.ChainType.SOLANA,
158
+ fee: BigInt(priority ? '100000' : '10000'),
159
+ isPriority: priority,
160
+ success: true
161
+ };
161
162
  }
162
163
  else {
163
- throw new Error('Unable to detect wallet type from provided wallet object');
164
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
164
165
  }
165
166
  }
166
167
  /**
167
- * Send a message using the appropriate chain implementation
168
- * Note: For backward compatibility, 'to' defaults to sender's own address
168
+ * Send a prepared message
169
169
  */
170
- async sendMessage(subject, body, priority = false, resolveSenderToName = false, to) {
171
- // For backward compatibility, default to sending to self
172
- const recipient = to || await this.getWalletAddressAsync();
173
- if (this.chainType === types_1.ChainType.EVM) {
174
- return this.sendEVMMessage(recipient, subject, body, priority, resolveSenderToName);
170
+ async sendPrepared(connectedWallet, chainInfo, to, mailId, options) {
171
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
172
+ const evmClient = await this.getEVMClient();
173
+ const evmWallet = connectedWallet;
174
+ const [account] = await evmWallet.walletClient.getAddresses();
175
+ const priority = options?.priority ?? false;
176
+ const resolveSenderToName = options?.resolveSenderToName ?? false;
177
+ const result = await evmClient.sendPrepared(evmWallet, chainInfo, to, mailId, account, // payer
178
+ priority, // revenueShareToReceiver
179
+ resolveSenderToName, options?.gasOptions);
180
+ return {
181
+ transactionHash: result.hash,
182
+ chainType: types_1.ChainType.EVM,
183
+ fee: BigInt(priority ? '100000' : '10000'),
184
+ gasUsed: result.gasUsed,
185
+ isPriority: priority,
186
+ success: true
187
+ };
188
+ }
189
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
190
+ const solanaClient = await this.getSolanaClient();
191
+ const solanaWallet = connectedWallet;
192
+ const priority = options?.priority ?? false;
193
+ const result = await solanaClient.sendPrepared(solanaWallet, chainInfo, to, mailId, priority, options?.computeOptions);
194
+ return {
195
+ transactionHash: result.transactionHash,
196
+ chainType: types_1.ChainType.SOLANA,
197
+ fee: BigInt(priority ? '100000' : '10000'),
198
+ isPriority: priority,
199
+ success: true
200
+ };
175
201
  }
176
202
  else {
177
- return this.sendSolanaMessage(recipient, subject, body, priority, resolveSenderToName);
203
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
178
204
  }
179
205
  }
180
206
  /**
181
- * Register a domain (not implemented - for backward compatibility)
207
+ * Send through webhook
182
208
  */
183
- async registerDomain(_domain) {
184
- throw new Error('Domain registration not yet implemented');
209
+ async sendThroughWebhook(connectedWallet, chainInfo, to, webhookId, options) {
210
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
211
+ const evmClient = await this.getEVMClient();
212
+ const evmWallet = connectedWallet;
213
+ const [account] = await evmWallet.walletClient.getAddresses();
214
+ const priority = options?.priority ?? false;
215
+ const result = await evmClient.sendThroughWebhook(to, subject, body, webhookId, account, // payer
216
+ priority, evmWallet, chainInfo, options?.gasOptions);
217
+ return {
218
+ transactionHash: result.hash,
219
+ chainType: types_1.ChainType.EVM,
220
+ fee: BigInt(priority ? '100000' : '10000'),
221
+ gasUsed: result.gasUsed,
222
+ isPriority: priority,
223
+ success: true
224
+ };
225
+ }
226
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
227
+ const solanaClient = await this.getSolanaClient();
228
+ const solanaWallet = connectedWallet;
229
+ const priority = options?.priority ?? false;
230
+ const result = await solanaClient.sendThroughWebhook(solanaWallet, chainInfo, to, webhookId, priority, options?.computeOptions);
231
+ return {
232
+ transactionHash: result.transactionHash,
233
+ chainType: types_1.ChainType.SOLANA,
234
+ fee: BigInt(priority ? '100000' : '10000'),
235
+ isPriority: priority,
236
+ success: true
237
+ };
238
+ }
239
+ else {
240
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
241
+ }
185
242
  }
186
243
  /**
187
244
  * Delegate to another address
245
+ * @param delegate - Address to delegate to
246
+ * @param wallet - Wallet connection
247
+ * @param chainInfo - Chain information
248
+ * @returns Transaction result
188
249
  */
189
- async delegateTo(delegate) {
190
- if (this.chainType === types_1.ChainType.EVM) {
191
- return this.delegateEVM(delegate);
250
+ async delegateTo(connectedWallet, chainInfo, delegate, options) {
251
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
252
+ const evmClient = await this.getEVMClient();
253
+ const result = await evmClient.delegateTo(delegate, connectedWallet, chainInfo, options?.gasOptions);
254
+ return {
255
+ transactionHash: result.hash,
256
+ chainType: types_1.ChainType.EVM,
257
+ delegate,
258
+ success: true
259
+ };
260
+ }
261
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
262
+ const solanaClient = await this.getSolanaClient();
263
+ const result = await solanaClient.delegateTo(delegate, connectedWallet, chainInfo, options?.computeOptions);
264
+ return {
265
+ transactionHash: result.transactionHash,
266
+ chainType: types_1.ChainType.SOLANA,
267
+ delegate,
268
+ success: true
269
+ };
192
270
  }
193
271
  else {
194
- return this.delegateSolana(delegate);
272
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
195
273
  }
196
274
  }
197
275
  /**
198
- * Claim revenue share
276
+ * Reject delegation
199
277
  */
200
- async claimRevenue() {
201
- if (this.chainType === types_1.ChainType.EVM) {
202
- return this.claimEVMRevenue();
278
+ async rejectDelegation(connectedWallet, chainInfo, delegatingAddress, options) {
279
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
280
+ const evmClient = await this.getEVMClient();
281
+ const result = await evmClient.rejectDelegation(connectedWallet, chainInfo, delegatingAddress, options?.gasOptions);
282
+ return {
283
+ hash: result.hash,
284
+ chainType: types_1.ChainType.EVM
285
+ };
286
+ }
287
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
288
+ const solanaClient = await this.getSolanaClient();
289
+ const result = await solanaClient.rejectDelegation(connectedWallet, chainInfo, delegatingAddress, options?.computeOptions);
290
+ return {
291
+ hash: result.transactionHash,
292
+ chainType: types_1.ChainType.SOLANA
293
+ };
203
294
  }
204
295
  else {
205
- return this.claimSolanaRevenue();
296
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
206
297
  }
207
298
  }
208
- // Performance optimization: cache module imports
209
- async getEVMModules() {
210
- if (!OnchainMailerClient.evmModules) {
211
- const evmModule = await Promise.resolve().then(() => __importStar(require('../evm/index.js')));
212
- OnchainMailerClient.evmModules = {
213
- MailerClient: evmModule.MailerClient
299
+ /**
300
+ * Claim revenue share
301
+ * @param wallet - Wallet connection
302
+ * @param chainInfo - Chain information
303
+ * @returns Transaction result
304
+ */
305
+ async claimRevenue(connectedWallet, chainInfo, options) {
306
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
307
+ const evmClient = await this.getEVMClient();
308
+ const result = await evmClient.claimRecipientShare(connectedWallet, chainInfo, options?.gasOptions);
309
+ return {
310
+ hash: result.hash,
311
+ chainType: types_1.ChainType.EVM
214
312
  };
215
313
  }
216
- return OnchainMailerClient.evmModules;
217
- }
218
- async getSolanaModules() {
219
- if (!OnchainMailerClient.solanaModules) {
220
- const [solanaModule, web3Module] = await Promise.all([
221
- Promise.resolve().then(() => __importStar(require('../solana/index.js'))),
222
- Promise.resolve().then(() => __importStar(require('@solana/web3.js')))
223
- ]);
224
- OnchainMailerClient.solanaModules = {
225
- MailerClient: solanaModule.MailerClient,
226
- PublicKey: web3Module.PublicKey,
227
- Connection: web3Module.Connection
314
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
315
+ const solanaClient = await this.getSolanaClient();
316
+ const result = await solanaClient.claimRecipientShare(connectedWallet, chainInfo, options?.computeOptions);
317
+ return {
318
+ hash: result.transactionHash,
319
+ chainType: types_1.ChainType.SOLANA
228
320
  };
229
321
  }
230
- return OnchainMailerClient.solanaModules;
322
+ else {
323
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
324
+ }
231
325
  }
232
- // EVM implementation methods
233
- async sendEVMMessage(to, subject, body, priority, resolveSenderToName) {
234
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
235
- throw new Error('EVM client not properly initialized');
326
+ /**
327
+ * Claim owner share (owner only)
328
+ */
329
+ async claimOwnerShare(connectedWallet, chainInfo, options) {
330
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
331
+ const evmClient = await this.getEVMClient();
332
+ const result = await evmClient.claimOwnerShare(connectedWallet, chainInfo, options?.gasOptions);
333
+ return {
334
+ hash: result.hash,
335
+ chainType: types_1.ChainType.EVM
336
+ };
236
337
  }
237
- const { MailerClient } = await this.getEVMModules();
238
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
239
- // Validate message
240
- if (!subject || subject.length > 200) {
241
- throw new Error('Subject must be 1-200 characters');
338
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
339
+ const solanaClient = await this.getSolanaClient();
340
+ const result = await solanaClient.claimOwnerShare(connectedWallet, chainInfo, options?.computeOptions);
341
+ return {
342
+ hash: result.transactionHash,
343
+ chainType: types_1.ChainType.SOLANA
344
+ };
242
345
  }
243
- if (!body || body.length > 10000) {
244
- throw new Error('Body must be 1-10000 characters');
346
+ else {
347
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
245
348
  }
246
- const [account] = await this.evmWalletClient.getAddresses();
247
- const payer = account;
248
- const result = await client.send(to, subject, body, payer, priority, resolveSenderToName, this.evmWalletClient, account);
249
- // Convert to MessageResult format
250
- return {
251
- transactionHash: result.hash,
252
- chainType: types_1.ChainType.EVM,
253
- fee: BigInt(priority ? '100000' : '10000'),
254
- gasUsed: result.gasUsed,
255
- isPriority: priority,
256
- success: true
257
- };
258
- }
259
- async delegateEVM(delegate) {
260
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
261
- throw new Error('EVM client not properly initialized');
262
- }
263
- const { MailerClient } = await this.getEVMModules();
264
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
265
- const [account] = await this.evmWalletClient.getAddresses();
266
- const result = await client.delegateTo(delegate, this.evmWalletClient, account);
267
- return {
268
- transactionHash: result.hash,
269
- chainType: types_1.ChainType.EVM,
270
- delegate,
271
- success: true
272
- };
273
- }
274
- async claimEVMRevenue() {
275
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
276
- throw new Error('EVM client not properly initialized');
277
- }
278
- const { MailerClient } = await this.getEVMModules();
279
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
280
- const [account] = await this.evmWalletClient.getAddresses();
281
- const result = await client.claimRecipientShare(this.evmWalletClient, account);
282
- return {
283
- hash: result.hash,
284
- chainType: types_1.ChainType.EVM,
285
- blockNumber: result.blockNumber,
286
- timestamp: Date.now()
287
- };
288
- }
289
- // Solana implementation methods
290
- async sendSolanaMessage(to, subject, body, priority, resolveSenderToName) {
291
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
292
- throw new Error('Solana client not properly initialized');
293
- }
294
- const { MailerClient, PublicKey } = await this.getSolanaModules();
295
- const programId = new PublicKey(this.solanaProgramId);
296
- const usdcMint = new PublicKey(this.solanaUsdcMint);
297
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
298
- const result = await client.send(to, subject, body, priority, resolveSenderToName);
299
- // Get current fees
300
- const fees = await client.getFees();
301
- return {
302
- transactionHash: result.signature,
303
- chainType: types_1.ChainType.SOLANA,
304
- fee: priority ? fees.sendFee : fees.sendFee / 10,
305
- isPriority: priority,
306
- success: true
307
- };
308
- }
309
- async delegateSolana(delegate) {
310
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
311
- throw new Error('Solana client not properly initialized');
312
- }
313
- const { MailerClient, PublicKey } = await this.getSolanaModules();
314
- const programId = new PublicKey(this.solanaProgramId);
315
- const usdcMint = new PublicKey(this.solanaUsdcMint);
316
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
317
- const result = await client.delegateTo(delegate);
318
- return {
319
- transactionHash: result.signature,
320
- chainType: types_1.ChainType.SOLANA,
321
- delegate,
322
- success: true
323
- };
324
- }
325
- async claimSolanaRevenue() {
326
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
327
- throw new Error('Solana client not properly initialized');
328
- }
329
- const { MailerClient, PublicKey } = await this.getSolanaModules();
330
- const programId = new PublicKey(this.solanaProgramId);
331
- const usdcMint = new PublicKey(this.solanaUsdcMint);
332
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
333
- const result = await client.claimRecipientShare();
334
- const slot = await this.solanaConnection.getSlot();
335
- return {
336
- hash: result.signature,
337
- chainType: types_1.ChainType.SOLANA,
338
- slot,
339
- timestamp: Date.now()
340
- };
341
349
  }
342
- // Read methods
343
- async getSendFee() {
344
- if (this.chainType === types_1.ChainType.EVM) {
345
- return this.getEVMSendFee();
350
+ /**
351
+ * Claim expired shares (owner only)
352
+ */
353
+ async claimExpiredShares(connectedWallet, chainInfo, recipient, options) {
354
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
355
+ const evmClient = await this.getEVMClient();
356
+ const result = await evmClient.claimExpiredShares(recipient, connectedWallet, chainInfo, options?.gasOptions);
357
+ return {
358
+ hash: result.hash,
359
+ chainType: types_1.ChainType.EVM
360
+ };
361
+ }
362
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
363
+ const solanaClient = await this.getSolanaClient();
364
+ const result = await solanaClient.claimExpiredShares(recipient, connectedWallet, chainInfo, options?.computeOptions);
365
+ return {
366
+ hash: result.transactionHash,
367
+ chainType: types_1.ChainType.SOLANA
368
+ };
346
369
  }
347
370
  else {
348
- return this.getSolanaSendFee();
371
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
349
372
  }
350
373
  }
351
- async getEVMSendFee() {
352
- if (!this.evmPublicClient || !this.evmContractAddress) {
353
- throw new Error('EVM client not properly initialized');
374
+ /**
375
+ * Set fees (owner only)
376
+ */
377
+ async setFees(connectedWallet, chainInfo, sendFee, delegationFee, options) {
378
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
379
+ const evmClient = await this.getEVMClient();
380
+ // EVM client uses separate methods
381
+ await evmClient.setFee(connectedWallet, chainInfo, sendFee, options?.gasOptions);
382
+ const result2 = await evmClient.setDelegationFee(connectedWallet, chainInfo, delegationFee, options?.gasOptions);
383
+ return {
384
+ hash: result2.hash, // Return last transaction
385
+ chainType: types_1.ChainType.EVM
386
+ };
354
387
  }
355
- const { MailerClient } = await this.getEVMModules();
356
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
357
- return client.getSendFee();
358
- }
359
- async getSolanaSendFee() {
360
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
361
- throw new Error('Solana client not properly initialized');
362
- }
363
- const { MailerClient, PublicKey } = await this.getSolanaModules();
364
- const programId = new PublicKey(this.solanaProgramId);
365
- const usdcMint = new PublicKey(this.solanaUsdcMint);
366
- // Create a minimal wallet object for reading
367
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
368
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
369
- const fees = await client.getFees();
370
- return BigInt(fees.sendFee);
371
- }
372
- // Additional read methods
373
- async getClaimableAmount(address) {
374
- const targetAddress = address || await this.getWalletAddressAsync();
375
- if (this.chainType === types_1.ChainType.EVM) {
376
- return this.getEVMClaimableAmount(targetAddress);
388
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
389
+ const solanaClient = await this.getSolanaClient();
390
+ const result = await solanaClient.setFees(connectedWallet, chainInfo, sendFee, delegationFee, options?.computeOptions);
391
+ return {
392
+ hash: result.transactionHash,
393
+ chainType: types_1.ChainType.SOLANA
394
+ };
377
395
  }
378
396
  else {
379
- return this.getSolanaClaimableAmount(targetAddress);
397
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
380
398
  }
381
399
  }
382
- async getEVMClaimableAmount(address) {
383
- if (!this.evmPublicClient || !this.evmContractAddress) {
384
- throw new Error('EVM client not properly initialized');
385
- }
386
- const { MailerClient } = await this.getEVMModules();
387
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
388
- const result = await client.getRecipientClaimable(address);
389
- return result.amount;
390
- }
391
- async getSolanaClaimableAmount(address) {
392
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
393
- throw new Error('Solana client not properly initialized');
394
- }
395
- const { MailerClient, PublicKey } = await this.getSolanaModules();
396
- const programId = new PublicKey(this.solanaProgramId);
397
- const usdcMint = new PublicKey(this.solanaUsdcMint);
398
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
399
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
400
- const recipientKey = new PublicKey(address);
401
- const claimInfo = await client.getRecipientClaimable(recipientKey);
402
- return claimInfo ? BigInt(claimInfo.amount) : 0n;
403
- }
404
- async getOwnerClaimable() {
405
- if (this.chainType === types_1.ChainType.EVM) {
406
- return this.getEVMOwnerClaimable();
400
+ /**
401
+ * Set custom fee percentage
402
+ */
403
+ async setCustomFeePercentage(connectedWallet, chainInfo, target, percentage, options) {
404
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
405
+ const evmClient = await this.getEVMClient();
406
+ const result = await evmClient.setCustomFeePercentage(connectedWallet, chainInfo, target, percentage, options?.gasOptions);
407
+ return {
408
+ hash: result.hash,
409
+ chainType: types_1.ChainType.EVM
410
+ };
411
+ }
412
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
413
+ const solanaClient = await this.getSolanaClient();
414
+ const result = await solanaClient.setCustomFeePercentage(connectedWallet, chainInfo, target, percentage, options?.computeOptions);
415
+ return {
416
+ hash: result.transactionHash,
417
+ chainType: types_1.ChainType.SOLANA
418
+ };
407
419
  }
408
420
  else {
409
- return this.getSolanaOwnerClaimable();
421
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
410
422
  }
411
423
  }
412
- async getEVMOwnerClaimable() {
413
- if (!this.evmPublicClient || !this.evmContractAddress) {
414
- throw new Error('EVM client not properly initialized');
424
+ /**
425
+ * Clear custom fee percentage
426
+ */
427
+ async clearCustomFeePercentage(connectedWallet, chainInfo, target, options) {
428
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
429
+ const evmClient = await this.getEVMClient();
430
+ const result = await evmClient.clearCustomFeePercentage(connectedWallet, chainInfo, target, options?.gasOptions);
431
+ return {
432
+ hash: result.hash,
433
+ chainType: types_1.ChainType.EVM
434
+ };
415
435
  }
416
- const { MailerClient } = await this.getEVMModules();
417
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
418
- return client.getOwnerClaimable();
419
- }
420
- async getSolanaOwnerClaimable() {
421
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
422
- throw new Error('Solana client not properly initialized');
423
- }
424
- const { MailerClient, PublicKey } = await this.getSolanaModules();
425
- const programId = new PublicKey(this.solanaProgramId);
426
- const usdcMint = new PublicKey(this.solanaUsdcMint);
427
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
428
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
429
- const amount = await client.getOwnerClaimable();
430
- return BigInt(amount);
431
- }
432
- async getDelegation(address) {
433
- const targetAddress = address || await this.getWalletAddressAsync();
434
- if (this.chainType === types_1.ChainType.EVM) {
435
- return this.getEVMDelegation(targetAddress);
436
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
437
+ const solanaClient = await this.getSolanaClient();
438
+ const result = await solanaClient.clearCustomFeePercentage(connectedWallet, chainInfo, target, options?.computeOptions);
439
+ return {
440
+ hash: result.transactionHash,
441
+ chainType: types_1.ChainType.SOLANA
442
+ };
436
443
  }
437
444
  else {
438
- return this.getSolanaDelegation(targetAddress);
445
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
439
446
  }
440
447
  }
441
- async getEVMDelegation(_address) {
442
- // Delegation read not implemented in EVM client yet
443
- throw new Error('getDelegation not yet implemented for EVM');
444
- }
445
- async getSolanaDelegation(address) {
446
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
447
- throw new Error('Solana client not properly initialized');
448
- }
449
- const { MailerClient, PublicKey } = await this.getSolanaModules();
450
- const programId = new PublicKey(this.solanaProgramId);
451
- const usdcMint = new PublicKey(this.solanaUsdcMint);
452
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
453
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
454
- const delegatorKey = new PublicKey(address);
455
- const delegationInfo = await client.getDelegation(delegatorKey);
456
- return delegationInfo?.delegate || null;
457
- }
458
- async getDelegationFee() {
459
- if (this.chainType === types_1.ChainType.EVM) {
460
- return this.getEVMDelegationFee();
448
+ /**
449
+ * Pause the contract/program (owner only)
450
+ */
451
+ async pause(connectedWallet, chainInfo, options) {
452
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
453
+ const evmClient = await this.getEVMClient();
454
+ const result = await evmClient.pause(connectedWallet, chainInfo, options?.gasOptions);
455
+ return {
456
+ hash: result.hash,
457
+ chainType: types_1.ChainType.EVM
458
+ };
459
+ }
460
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
461
+ const solanaClient = await this.getSolanaClient();
462
+ const result = await solanaClient.pause(connectedWallet, chainInfo, options?.computeOptions);
463
+ return {
464
+ hash: result.transactionHash,
465
+ chainType: types_1.ChainType.SOLANA
466
+ };
461
467
  }
462
468
  else {
463
- return this.getSolanaDelegationFee();
469
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
464
470
  }
465
471
  }
466
- async getEVMDelegationFee() {
467
- if (!this.evmPublicClient || !this.evmContractAddress) {
468
- throw new Error('EVM client not properly initialized');
472
+ /**
473
+ * Unpause the contract/program (owner only)
474
+ */
475
+ async unpause(connectedWallet, chainInfo, options) {
476
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
477
+ const evmClient = await this.getEVMClient();
478
+ const result = await evmClient.unpause(connectedWallet, chainInfo, options?.gasOptions);
479
+ return {
480
+ hash: result.hash,
481
+ chainType: types_1.ChainType.EVM
482
+ };
469
483
  }
470
- const { MailerClient } = await this.getEVMModules();
471
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
472
- return client.getDelegationFee();
473
- }
474
- async getSolanaDelegationFee() {
475
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
476
- throw new Error('Solana client not properly initialized');
477
- }
478
- const { MailerClient, PublicKey } = await this.getSolanaModules();
479
- const programId = new PublicKey(this.solanaProgramId);
480
- const usdcMint = new PublicKey(this.solanaUsdcMint);
481
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
482
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
483
- const fees = await client.getFees();
484
- return BigInt(fees.delegationFee);
485
- }
486
- async isPaused() {
487
- if (this.chainType === types_1.ChainType.EVM) {
488
- return this.isPausedEVM();
484
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
485
+ const solanaClient = await this.getSolanaClient();
486
+ const result = await solanaClient.unpause(connectedWallet, chainInfo, options?.computeOptions);
487
+ return {
488
+ hash: result.transactionHash,
489
+ chainType: types_1.ChainType.SOLANA
490
+ };
489
491
  }
490
492
  else {
491
- return this.isPausedSolana();
493
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
492
494
  }
493
495
  }
494
- async isPausedEVM() {
495
- if (!this.evmPublicClient || !this.evmContractAddress) {
496
- throw new Error('EVM client not properly initialized');
496
+ /**
497
+ * Emergency unpause (owner only)
498
+ */
499
+ async emergencyUnpause(connectedWallet, chainInfo, options) {
500
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
501
+ const evmClient = await this.getEVMClient();
502
+ const result = await evmClient.emergencyUnpause(connectedWallet, chainInfo, options?.gasOptions);
503
+ return {
504
+ hash: result.hash,
505
+ chainType: types_1.ChainType.EVM
506
+ };
497
507
  }
498
- const { MailerClient } = await this.getEVMModules();
499
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
500
- return client.isPaused();
501
- }
502
- async isPausedSolana() {
503
- if (!this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
504
- throw new Error('Solana client not properly initialized');
505
- }
506
- const { MailerClient, PublicKey } = await this.getSolanaModules();
507
- const programId = new PublicKey(this.solanaProgramId);
508
- const usdcMint = new PublicKey(this.solanaUsdcMint);
509
- const wallet = { publicKey: PublicKey.default, signTransaction: async (tx) => tx };
510
- const client = new MailerClient(this.solanaConnection, wallet, programId, usdcMint);
511
- return client.isPaused();
512
- }
513
- // Write methods for contract management
514
- async unpause() {
515
- if (this.chainType === types_1.ChainType.EVM) {
516
- return this.unpauseEVM();
508
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
509
+ const solanaClient = await this.getSolanaClient();
510
+ const result = await solanaClient.emergencyUnpause(connectedWallet, chainInfo, options?.computeOptions);
511
+ return {
512
+ hash: result.transactionHash,
513
+ chainType: types_1.ChainType.SOLANA
514
+ };
517
515
  }
518
516
  else {
519
- return this.unpauseSolana();
517
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
520
518
  }
521
519
  }
522
- async unpauseEVM() {
523
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
524
- throw new Error('EVM client not properly initialized');
525
- }
526
- const { MailerClient } = await this.getEVMModules();
527
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
528
- const [account] = await this.evmWalletClient.getAddresses();
529
- const result = await client.unpause(this.evmWalletClient, account);
530
- return {
531
- hash: result.hash,
532
- chainType: types_1.ChainType.EVM,
533
- blockNumber: result.blockNumber,
534
- timestamp: Date.now()
535
- };
536
- }
537
- async unpauseSolana() {
538
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
539
- throw new Error('Solana client not properly initialized');
540
- }
541
- const { MailerClient, PublicKey } = await this.getSolanaModules();
542
- const programId = new PublicKey(this.solanaProgramId);
543
- const usdcMint = new PublicKey(this.solanaUsdcMint);
544
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
545
- const result = await client.unpause();
546
- const slot = await this.solanaConnection.getSlot();
547
- return {
548
- hash: result.signature,
549
- chainType: types_1.ChainType.SOLANA,
550
- slot,
551
- timestamp: Date.now()
552
- };
553
- }
554
- async emergencyUnpause() {
555
- if (this.chainType === types_1.ChainType.EVM) {
556
- return this.emergencyUnpauseEVM();
520
+ /**
521
+ * Distribute claimable funds when paused
522
+ * Note: EVM supports single recipient, Solana supports multiple
523
+ */
524
+ async distributeClaimableFunds(connectedWallet, chainInfo, recipient, options) {
525
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
526
+ const evmClient = await this.getEVMClient();
527
+ // EVM only supports single recipient
528
+ const singleRecipient = Array.isArray(recipient) ? recipient[0] : recipient;
529
+ const result = await evmClient.distributeClaimableFunds(connectedWallet, chainInfo, singleRecipient, options?.gasOptions);
530
+ return {
531
+ hash: result.hash,
532
+ chainType: types_1.ChainType.EVM
533
+ };
534
+ }
535
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
536
+ const solanaClient = await this.getSolanaClient();
537
+ // Solana supports multiple recipients
538
+ const recipients = Array.isArray(recipient) ? recipient : [recipient];
539
+ const result = await solanaClient.distributeClaimableFunds(connectedWallet, chainInfo, recipients, options?.computeOptions);
540
+ return {
541
+ hash: result.transactionHash,
542
+ chainType: types_1.ChainType.SOLANA
543
+ };
557
544
  }
558
545
  else {
559
- return this.emergencyUnpauseSolana();
546
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
560
547
  }
561
548
  }
562
- async emergencyUnpauseEVM() {
563
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
564
- throw new Error('EVM client not properly initialized');
565
- }
566
- const { MailerClient } = await this.getEVMModules();
567
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
568
- const [account] = await this.evmWalletClient.getAddresses();
569
- const result = await client.emergencyUnpause(this.evmWalletClient, account);
570
- return {
571
- hash: result.hash,
572
- chainType: types_1.ChainType.EVM,
573
- blockNumber: result.blockNumber,
574
- timestamp: Date.now()
575
- };
576
- }
577
- async emergencyUnpauseSolana() {
578
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
579
- throw new Error('Solana client not properly initialized');
580
- }
581
- const { MailerClient, PublicKey } = await this.getSolanaModules();
582
- const programId = new PublicKey(this.solanaProgramId);
583
- const usdcMint = new PublicKey(this.solanaUsdcMint);
584
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
585
- const result = await client.emergencyUnpause();
586
- const slot = await this.solanaConnection.getSlot();
587
- return {
588
- hash: result.signature,
589
- chainType: types_1.ChainType.SOLANA,
590
- slot,
591
- timestamp: Date.now()
592
- };
593
- }
594
- async distributeClaimableFunds(recipient) {
595
- if (this.chainType === types_1.ChainType.EVM) {
596
- return this.distributeClaimableFundsEVM(recipient);
549
+ /**
550
+ * Set permission for a contract to use caller's USDC for sending messages
551
+ * Note: Only supported on EVM chains
552
+ */
553
+ async setPermission(connectedWallet, chainInfo, contractAddress, options) {
554
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
555
+ const evmClient = await this.getEVMClient();
556
+ const result = await evmClient.setPermission(connectedWallet, chainInfo, contractAddress, options?.gasOptions);
557
+ return {
558
+ hash: result.hash,
559
+ chainType: types_1.ChainType.EVM
560
+ };
561
+ }
562
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
563
+ throw new Error('Permission system is not supported on Solana');
597
564
  }
598
565
  else {
599
- return this.distributeClaimableFundsSolana(recipient);
566
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
600
567
  }
601
568
  }
602
- async distributeClaimableFundsEVM(recipient) {
603
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
604
- throw new Error('EVM client not properly initialized');
605
- }
606
- const { MailerClient } = await this.getEVMModules();
607
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
608
- const [account] = await this.evmWalletClient.getAddresses();
609
- const result = await client.distributeClaimableFunds(recipient, this.evmWalletClient, account);
610
- return {
611
- hash: result.hash,
612
- chainType: types_1.ChainType.EVM,
613
- blockNumber: result.blockNumber,
614
- timestamp: Date.now()
615
- };
616
- }
617
- async distributeClaimableFundsSolana(recipient) {
618
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
619
- throw new Error('Solana client not properly initialized');
620
- }
621
- const { MailerClient, PublicKey } = await this.getSolanaModules();
622
- const programId = new PublicKey(this.solanaProgramId);
623
- const usdcMint = new PublicKey(this.solanaUsdcMint);
624
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
625
- const result = await client.distributeClaimableFunds(recipient);
626
- const slot = await this.solanaConnection.getSlot();
627
- return {
628
- hash: result.signature,
629
- chainType: types_1.ChainType.SOLANA,
630
- slot,
631
- timestamp: Date.now()
632
- };
633
- }
634
- // Additional methods for complete API compatibility
635
- async sendPrepared(to, mailId, priority = false, resolveSenderToName = false) {
636
- if (this.chainType === types_1.ChainType.EVM) {
637
- return this.sendPreparedEVM(to, mailId, priority, resolveSenderToName);
569
+ /**
570
+ * Remove permission from a contract
571
+ * Note: Only supported on EVM chains
572
+ */
573
+ async removePermission(connectedWallet, chainInfo, contractAddress, options) {
574
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
575
+ const evmClient = await this.getEVMClient();
576
+ const result = await evmClient.removePermission(connectedWallet, chainInfo, contractAddress, options?.gasOptions);
577
+ return {
578
+ hash: result.hash,
579
+ chainType: types_1.ChainType.EVM
580
+ };
581
+ }
582
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
583
+ throw new Error('Permission system is not supported on Solana');
638
584
  }
639
585
  else {
640
- return this.sendPreparedSolana(to, mailId, priority, resolveSenderToName);
586
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
641
587
  }
642
588
  }
643
- async sendPreparedEVM(to, mailId, priority, resolveSenderToName) {
644
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
645
- throw new Error('EVM client not properly initialized');
646
- }
647
- const { MailerClient } = await this.getEVMModules();
648
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
649
- const [account] = await this.evmWalletClient.getAddresses();
650
- const payer = account;
651
- const result = await client.sendPrepared(to, mailId, payer, priority, resolveSenderToName, this.evmWalletClient, account);
652
- return {
653
- transactionHash: result.hash,
654
- chainType: types_1.ChainType.EVM,
655
- fee: BigInt(priority ? '100000' : '10000'),
656
- gasUsed: result.gasUsed,
657
- isPriority: priority,
658
- success: true
659
- };
660
- }
661
- async sendPreparedSolana(to, mailId, priority, resolveSenderToName) {
662
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
663
- throw new Error('Solana client not properly initialized');
664
- }
665
- const { MailerClient, PublicKey } = await this.getSolanaModules();
666
- const programId = new PublicKey(this.solanaProgramId);
667
- const usdcMint = new PublicKey(this.solanaUsdcMint);
668
- const recipientKey = new PublicKey(to);
669
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
670
- const result = await client.sendPrepared(recipientKey, mailId, priority, resolveSenderToName);
671
- const fees = await client.getFees();
672
- return {
673
- transactionHash: result.signature,
674
- chainType: types_1.ChainType.SOLANA,
675
- fee: priority ? fees.sendFee : fees.sendFee / 10,
676
- isPriority: priority,
677
- success: true
678
- };
679
- }
680
- async sendToEmail(toEmail, subject, body) {
681
- if (this.chainType === types_1.ChainType.EVM) {
682
- return this.sendToEmailEVM(toEmail, subject, body);
589
+ /**
590
+ * Check if permission exists for a contract/wallet pair
591
+ * Note: Only supported on EVM chains
592
+ */
593
+ async hasPermission(chainInfo, contractAddress, walletAddress, publicClient) {
594
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
595
+ const evmClient = await this.getEVMClient();
596
+ return await evmClient.hasPermission(chainInfo, contractAddress, walletAddress, publicClient);
597
+ }
598
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
599
+ // Solana doesn't have permission system, always return false
600
+ return false;
683
601
  }
684
602
  else {
685
- return this.sendToEmailSolana(toEmail, subject, body);
603
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
686
604
  }
687
605
  }
688
- async sendToEmailEVM(toEmail, subject, body) {
689
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
690
- throw new Error('EVM client not properly initialized');
691
- }
692
- const { MailerClient } = await this.getEVMModules();
693
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
694
- const [account] = await this.evmWalletClient.getAddresses();
695
- const payer = account;
696
- const result = await client.sendToEmailAddress(toEmail, subject, body, payer, this.evmWalletClient, account);
697
- return {
698
- transactionHash: result.hash,
699
- chainType: types_1.ChainType.EVM,
700
- fee: BigInt('10000'), // 10% fee only
701
- gasUsed: result.gasUsed,
702
- isPriority: false,
703
- success: true
704
- };
705
- }
706
- async sendToEmailSolana(toEmail, subject, body) {
707
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
708
- throw new Error('Solana client not properly initialized');
709
- }
710
- const { MailerClient, PublicKey } = await this.getSolanaModules();
711
- const programId = new PublicKey(this.solanaProgramId);
712
- const usdcMint = new PublicKey(this.solanaUsdcMint);
713
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
714
- const result = await client.sendToEmail(toEmail, subject, body);
715
- const fees = await client.getFees();
716
- return {
717
- transactionHash: result.signature,
718
- chainType: types_1.ChainType.SOLANA,
719
- fee: fees.sendFee / 10, // 10% fee only
720
- isPriority: false,
721
- success: true
722
- };
723
- }
724
- async sendPreparedToEmail(toEmail, mailId) {
725
- if (this.chainType === types_1.ChainType.EVM) {
726
- return this.sendPreparedToEmailEVM(toEmail, mailId);
606
+ // ============= Read Methods =============
607
+ /**
608
+ * Get the send fee for messages
609
+ * @param chainInfo - Chain information with RPC endpoint
610
+ * @param publicClient - Optional public client for EVM (will create if not provided)
611
+ * @param connection - Optional connection for Solana (will create if not provided)
612
+ * @returns Fee amount in USDC micro-units
613
+ */
614
+ async getSendFee(chainInfo, publicClient, connection) {
615
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
616
+ const evmClient = await this.getEVMClient();
617
+ return await evmClient.getSendFee(chainInfo, publicClient);
618
+ }
619
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
620
+ const solanaClient = await this.getSolanaClient();
621
+ return await solanaClient.getSendFee(chainInfo, connection);
727
622
  }
728
623
  else {
729
- return this.sendPreparedToEmailSolana(toEmail, mailId);
624
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
730
625
  }
731
626
  }
732
- async sendPreparedToEmailEVM(toEmail, mailId) {
733
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
734
- throw new Error('EVM client not properly initialized');
735
- }
736
- const { MailerClient } = await this.getEVMModules();
737
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
738
- const [account] = await this.evmWalletClient.getAddresses();
739
- const payer = account;
740
- const result = await client.sendPreparedToEmailAddress(toEmail, mailId, payer, this.evmWalletClient, account);
741
- return {
742
- transactionHash: result.hash,
743
- chainType: types_1.ChainType.EVM,
744
- fee: BigInt('10000'), // 10% fee only
745
- gasUsed: result.gasUsed,
746
- isPriority: false,
747
- success: true
748
- };
749
- }
750
- async sendPreparedToEmailSolana(toEmail, mailId) {
751
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
752
- throw new Error('Solana client not properly initialized');
753
- }
754
- const { MailerClient, PublicKey } = await this.getSolanaModules();
755
- const programId = new PublicKey(this.solanaProgramId);
756
- const usdcMint = new PublicKey(this.solanaUsdcMint);
757
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
758
- const result = await client.sendPreparedToEmail(toEmail, mailId);
759
- const fees = await client.getFees();
760
- return {
761
- transactionHash: result.signature,
762
- chainType: types_1.ChainType.SOLANA,
763
- fee: fees.sendFee / 10, // 10% fee only
764
- isPriority: false,
765
- success: true
766
- };
767
- }
768
- async claimOwnerShare() {
769
- if (this.chainType === types_1.ChainType.EVM) {
770
- return this.claimOwnerShareEVM();
627
+ /**
628
+ * Get delegation fee
629
+ */
630
+ async getDelegationFee(chainInfo, publicClient, connection) {
631
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
632
+ const evmClient = await this.getEVMClient();
633
+ return await evmClient.getDelegationFee(chainInfo, publicClient);
634
+ }
635
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
636
+ const solanaClient = await this.getSolanaClient();
637
+ return await solanaClient.getDelegationFee(chainInfo, connection);
771
638
  }
772
639
  else {
773
- return this.claimOwnerShareSolana();
640
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
774
641
  }
775
642
  }
776
- async claimOwnerShareEVM() {
777
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
778
- throw new Error('EVM client not properly initialized');
779
- }
780
- const { MailerClient } = await this.getEVMModules();
781
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
782
- const [account] = await this.evmWalletClient.getAddresses();
783
- const result = await client.claimOwnerShare(this.evmWalletClient, account);
784
- return {
785
- hash: result.hash,
786
- chainType: types_1.ChainType.EVM,
787
- blockNumber: result.blockNumber,
788
- timestamp: Date.now()
789
- };
790
- }
791
- async claimOwnerShareSolana() {
792
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
793
- throw new Error('Solana client not properly initialized');
794
- }
795
- const { MailerClient, PublicKey } = await this.getSolanaModules();
796
- const programId = new PublicKey(this.solanaProgramId);
797
- const usdcMint = new PublicKey(this.solanaUsdcMint);
798
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
799
- const result = await client.claimOwnerShare();
800
- const slot = await this.solanaConnection.getSlot();
801
- return {
802
- hash: result.signature,
803
- chainType: types_1.ChainType.SOLANA,
804
- slot,
805
- timestamp: Date.now()
806
- };
807
- }
808
- async claimExpiredShares(recipient) {
809
- if (this.chainType === types_1.ChainType.EVM) {
810
- return this.claimExpiredSharesEVM(recipient);
643
+ /**
644
+ * Get delegation for an address
645
+ * @param address - Address to check
646
+ * @param chainInfo - Chain information with RPC endpoint
647
+ * @param publicClient - Optional public client for EVM
648
+ * @param connection - Optional connection for Solana
649
+ * @returns Delegated address or null
650
+ */
651
+ async getDelegation(address, chainInfo, publicClient, connection) {
652
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
653
+ const evmClient = await this.getEVMClient();
654
+ const delegation = await evmClient.getDelegation(address, chainInfo, publicClient);
655
+ return delegation === '0x0000000000000000000000000000000000000000' ? null : delegation;
656
+ }
657
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
658
+ const solanaClient = await this.getSolanaClient();
659
+ const delegation = await solanaClient.getDelegation(address, chainInfo, connection);
660
+ return delegation ? delegation.toBase58() : null;
811
661
  }
812
662
  else {
813
- return this.claimExpiredSharesSolana(recipient);
663
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
814
664
  }
815
665
  }
816
- async claimExpiredSharesEVM(recipient) {
817
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
818
- throw new Error('EVM client not properly initialized');
819
- }
820
- const { MailerClient } = await this.getEVMModules();
821
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
822
- const [account] = await this.evmWalletClient.getAddresses();
823
- const result = await client.claimExpiredShares(recipient, this.evmWalletClient, account);
824
- return {
825
- hash: result.hash,
826
- chainType: types_1.ChainType.EVM,
827
- blockNumber: result.blockNumber,
828
- timestamp: Date.now()
829
- };
830
- }
831
- async claimExpiredSharesSolana(recipient) {
832
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
833
- throw new Error('Solana client not properly initialized');
834
- }
835
- const { MailerClient, PublicKey } = await this.getSolanaModules();
836
- const programId = new PublicKey(this.solanaProgramId);
837
- const usdcMint = new PublicKey(this.solanaUsdcMint);
838
- const recipientKey = new PublicKey(recipient);
839
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
840
- const result = await client.claimExpiredShares(recipientKey);
841
- const slot = await this.solanaConnection.getSlot();
842
- return {
843
- hash: result.signature,
844
- chainType: types_1.ChainType.SOLANA,
845
- slot,
846
- timestamp: Date.now()
847
- };
848
- }
849
- async rejectDelegation(delegatorAddress) {
850
- if (this.chainType === types_1.ChainType.EVM) {
851
- return this.rejectDelegationEVM(delegatorAddress);
666
+ /**
667
+ * Get recipient claimable info
668
+ */
669
+ async getRecipientClaimable(recipient, chainInfo, publicClient, connection) {
670
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
671
+ const evmClient = await this.getEVMClient();
672
+ return await evmClient.getRecipientClaimable(recipient, chainInfo, publicClient);
673
+ }
674
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
675
+ const solanaClient = await this.getSolanaClient();
676
+ const info = await solanaClient.getRecipientClaimable(recipient, chainInfo, connection);
677
+ if (!info)
678
+ return null;
679
+ return {
680
+ amount: BigInt(info.amount),
681
+ expiresAt: BigInt(info.expiresAt),
682
+ isExpired: info.isExpired
683
+ };
852
684
  }
853
685
  else {
854
- return this.rejectDelegationSolana(delegatorAddress);
686
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
855
687
  }
856
688
  }
857
- async rejectDelegationEVM(delegatorAddress) {
858
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
859
- throw new Error('EVM client not properly initialized');
860
- }
861
- const { MailerClient } = await this.getEVMModules();
862
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
863
- const [account] = await this.evmWalletClient.getAddresses();
864
- const result = await client.rejectDelegation(delegatorAddress, this.evmWalletClient, account);
865
- return {
866
- hash: result.hash,
867
- chainType: types_1.ChainType.EVM,
868
- blockNumber: result.blockNumber,
869
- timestamp: Date.now()
870
- };
871
- }
872
- async rejectDelegationSolana(delegatorAddress) {
873
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
874
- throw new Error('Solana client not properly initialized');
875
- }
876
- const { MailerClient, PublicKey } = await this.getSolanaModules();
877
- const programId = new PublicKey(this.solanaProgramId);
878
- const usdcMint = new PublicKey(this.solanaUsdcMint);
879
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
880
- const result = await client.rejectDelegation(delegatorAddress);
881
- const slot = await this.solanaConnection.getSlot();
882
- return {
883
- hash: result.signature,
884
- chainType: types_1.ChainType.SOLANA,
885
- slot,
886
- timestamp: Date.now()
887
- };
888
- }
889
- async setFee(newFee) {
890
- if (this.chainType === types_1.ChainType.EVM) {
891
- return this.setFeeEVM(newFee);
689
+ /**
690
+ * Get owner claimable amount
691
+ */
692
+ async getOwnerClaimable(chainInfo, publicClient, connection) {
693
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
694
+ const evmClient = await this.getEVMClient();
695
+ return await evmClient.getOwnerClaimable(chainInfo, publicClient);
696
+ }
697
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
698
+ const solanaClient = await this.getSolanaClient();
699
+ const amount = await solanaClient.getOwnerClaimable(chainInfo, connection);
700
+ return BigInt(amount);
892
701
  }
893
702
  else {
894
- return this.setFeeSolana(newFee);
703
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
895
704
  }
896
705
  }
897
- async setFeeEVM(newFee) {
898
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
899
- throw new Error('EVM client not properly initialized');
900
- }
901
- const { MailerClient } = await this.getEVMModules();
902
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
903
- const [account] = await this.evmWalletClient.getAddresses();
904
- const result = await client.setFee(newFee, this.evmWalletClient, account);
905
- return {
906
- hash: result.hash,
907
- chainType: types_1.ChainType.EVM,
908
- blockNumber: result.blockNumber,
909
- timestamp: Date.now()
910
- };
911
- }
912
- async setFeeSolana(newFee) {
913
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
914
- throw new Error('Solana client not properly initialized');
915
- }
916
- const { MailerClient, PublicKey } = await this.getSolanaModules();
917
- const programId = new PublicKey(this.solanaProgramId);
918
- const usdcMint = new PublicKey(this.solanaUsdcMint);
919
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
920
- const result = await client.setFee(newFee);
921
- const slot = await this.solanaConnection.getSlot();
922
- return {
923
- hash: result.signature,
924
- chainType: types_1.ChainType.SOLANA,
925
- slot,
926
- timestamp: Date.now()
927
- };
928
- }
929
- async setDelegationFee(newFee) {
930
- if (this.chainType === types_1.ChainType.EVM) {
931
- return this.setDelegationFeeEVM(newFee);
706
+ /**
707
+ * Get custom fee percentage
708
+ */
709
+ async getCustomFeePercentage(target, chainInfo, publicClient, connection) {
710
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
711
+ const evmClient = await this.getEVMClient();
712
+ return await evmClient.getCustomFeePercentage(target, chainInfo, publicClient);
713
+ }
714
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
715
+ const solanaClient = await this.getSolanaClient();
716
+ return await solanaClient.getCustomFeePercentage(target, chainInfo, connection);
932
717
  }
933
718
  else {
934
- return this.setDelegationFeeSolana(newFee);
719
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
935
720
  }
936
721
  }
937
- async setDelegationFeeEVM(newFee) {
938
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
939
- throw new Error('EVM client not properly initialized');
940
- }
941
- const { MailerClient } = await this.getEVMModules();
942
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
943
- const [account] = await this.evmWalletClient.getAddresses();
944
- const result = await client.setDelegationFee(newFee, this.evmWalletClient, account);
945
- return {
946
- hash: result.hash,
947
- chainType: types_1.ChainType.EVM,
948
- blockNumber: result.blockNumber,
949
- timestamp: Date.now()
950
- };
951
- }
952
- async setDelegationFeeSolana(newFee) {
953
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
954
- throw new Error('Solana client not properly initialized');
955
- }
956
- const { MailerClient, PublicKey } = await this.getSolanaModules();
957
- const programId = new PublicKey(this.solanaProgramId);
958
- const usdcMint = new PublicKey(this.solanaUsdcMint);
959
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
960
- const result = await client.setDelegationFee(newFee);
961
- const slot = await this.solanaConnection.getSlot();
962
- return {
963
- hash: result.signature,
964
- chainType: types_1.ChainType.SOLANA,
965
- slot,
966
- timestamp: Date.now()
967
- };
968
- }
969
- async pause() {
970
- if (this.chainType === types_1.ChainType.EVM) {
971
- return this.pauseEVM();
722
+ /**
723
+ * Check if contract/program is paused
724
+ */
725
+ async isPaused(chainInfo, publicClient, connection) {
726
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
727
+ const evmClient = await this.getEVMClient();
728
+ return await evmClient.isPaused(chainInfo, publicClient);
729
+ }
730
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
731
+ const solanaClient = await this.getSolanaClient();
732
+ return await solanaClient.isPaused(chainInfo, connection);
972
733
  }
973
734
  else {
974
- return this.pauseSolana();
735
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
975
736
  }
976
737
  }
977
- async pauseEVM() {
978
- if (!this.evmWalletClient || !this.evmPublicClient || !this.evmContractAddress) {
979
- throw new Error('EVM client not properly initialized');
980
- }
981
- const { MailerClient } = await this.getEVMModules();
982
- const client = new MailerClient(this.evmContractAddress, this.evmPublicClient);
983
- const [account] = await this.evmWalletClient.getAddresses();
984
- const result = await client.pause(this.evmWalletClient, account);
985
- return {
986
- hash: result.hash,
987
- chainType: types_1.ChainType.EVM,
988
- blockNumber: result.blockNumber,
989
- timestamp: Date.now()
990
- };
991
- }
992
- async pauseSolana() {
993
- if (!this.solanaWallet || !this.solanaConnection || !this.solanaProgramId || !this.solanaUsdcMint) {
994
- throw new Error('Solana client not properly initialized');
995
- }
996
- const { MailerClient, PublicKey } = await this.getSolanaModules();
997
- const programId = new PublicKey(this.solanaProgramId);
998
- const usdcMint = new PublicKey(this.solanaUsdcMint);
999
- const client = new MailerClient(this.solanaConnection, this.solanaWallet, programId, usdcMint);
1000
- const result = await client.pause();
1001
- const slot = await this.solanaConnection.getSlot();
1002
- return {
1003
- hash: result.signature,
1004
- chainType: types_1.ChainType.SOLANA,
1005
- slot,
1006
- timestamp: Date.now()
1007
- };
1008
- }
1009
- // Utility methods
1010
- getChainType() {
1011
- return this.chainType;
1012
- }
1013
- getWalletAddress() {
1014
- if (this.chainType === types_1.ChainType.EVM) {
1015
- // Try to get address from raw wallet for backward compatibility
1016
- // @ts-ignore
1017
- if (this._rawEvmWallet) {
1018
- // @ts-ignore
1019
- return this._rawEvmWallet.address || this._rawEvmWallet.selectedAddress || '';
1020
- }
1021
- return ''; // Caller should use getWalletAddressAsync() for accurate address
1022
- }
1023
- else if (this.chainType === types_1.ChainType.SOLANA && this.solanaWallet) {
1024
- return this.solanaWallet.publicKey?.toString() || '';
1025
- }
1026
- return '';
1027
- }
1028
738
  /**
1029
- * Get wallet address asynchronously
739
+ * Get contract/program owner
1030
740
  */
1031
- async getWalletAddressAsync() {
1032
- if (this.chainType === types_1.ChainType.EVM && this.evmWalletClient) {
1033
- const [address] = await this.evmWalletClient.getAddresses();
1034
- return address;
741
+ async getOwner(chainInfo, publicClient, connection) {
742
+ if (chainInfo.chainType === types_1.ChainType.EVM) {
743
+ const evmClient = await this.getEVMClient();
744
+ return await evmClient.getOwner(chainInfo, publicClient);
745
+ }
746
+ else if (chainInfo.chainType === types_1.ChainType.SOLANA) {
747
+ const solanaClient = await this.getSolanaClient();
748
+ const owner = await solanaClient.getOwner(chainInfo, connection);
749
+ return owner.toBase58();
1035
750
  }
1036
- else if (this.chainType === types_1.ChainType.SOLANA && this.solanaWallet) {
1037
- return this.solanaWallet.publicKey?.toString() || '';
751
+ else {
752
+ throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
1038
753
  }
1039
- throw new Error('Wallet not initialized');
754
+ }
755
+ /**
756
+ * Register a domain (not implemented - for backward compatibility)
757
+ */
758
+ async registerDomain(_domain) {
759
+ throw new Error('Domain registration not yet implemented');
1040
760
  }
1041
761
  }
1042
762
  exports.OnchainMailerClient = OnchainMailerClient;
1043
763
  // Cache for dynamic imports
1044
764
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1045
- OnchainMailerClient.evmModules = null;
765
+ OnchainMailerClient.evmClient = null;
1046
766
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1047
- OnchainMailerClient.solanaModules = null;
767
+ OnchainMailerClient.solanaClient = null;
1048
768
  //# sourceMappingURL=onchain-mailer-client.js.map