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