@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.
- package/dist/evm/src/evm/{mailer-client.d.ts → evm-mailer-client.d.ts} +146 -50
- package/dist/evm/src/evm/evm-mailer-client.d.ts.map +1 -0
- package/dist/evm/src/evm/evm-mailer-client.js +924 -0
- package/dist/evm/src/evm/evm-mailer-client.js.map +1 -0
- package/dist/evm/src/evm/index.d.ts +1 -1
- package/dist/evm/src/evm/index.d.ts.map +1 -1
- package/dist/evm/src/evm/index.js +4 -4
- package/dist/evm/src/evm/index.js.map +1 -1
- package/dist/solana/solana/index.d.ts +1 -1
- package/dist/solana/solana/index.d.ts.map +1 -1
- package/dist/solana/solana/index.js +4 -3
- package/dist/solana/solana/index.js.map +1 -1
- package/dist/solana/solana/solana-mailer-client.d.ts +209 -0
- package/dist/solana/solana/solana-mailer-client.d.ts.map +1 -0
- package/dist/solana/solana/solana-mailer-client.js +1004 -0
- package/dist/solana/solana/solana-mailer-client.js.map +1 -0
- package/dist/solana/solana/types.d.ts +3 -2
- package/dist/solana/solana/types.d.ts.map +1 -1
- package/dist/solana/solana/types.js.map +1 -1
- package/dist/{unified-esm/src/evm/mailer-client.d.ts → unified/src/evm/evm-mailer-client.d.ts} +146 -50
- package/dist/unified/src/evm/evm-mailer-client.d.ts.map +1 -0
- package/dist/unified/src/evm/evm-mailer-client.js +924 -0
- package/dist/unified/src/evm/evm-mailer-client.js.map +1 -0
- package/dist/unified/src/evm/index.d.ts +1 -1
- package/dist/unified/src/evm/index.d.ts.map +1 -1
- package/dist/unified/src/evm/index.js +4 -4
- package/dist/unified/src/evm/index.js.map +1 -1
- package/dist/unified/src/react/context/MailerProvider.d.ts +26 -20
- package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
- package/dist/unified/src/react/context/MailerProvider.js +26 -26
- package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.d.ts +225 -192
- package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.js +263 -266
- package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.d.ts +117 -63
- package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.js +239 -104
- package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified/src/react/index.d.ts +5 -3
- package/dist/unified/src/react/index.d.ts.map +1 -1
- package/dist/unified/src/react/index.js +41 -26
- package/dist/unified/src/react/index.js.map +1 -1
- package/dist/unified/src/solana/index.d.ts +1 -1
- package/dist/unified/src/solana/index.d.ts.map +1 -1
- package/dist/unified/src/solana/index.js +4 -3
- package/dist/unified/src/solana/index.js.map +1 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts +209 -0
- package/dist/unified/src/solana/solana-mailer-client.d.ts.map +1 -0
- package/dist/unified/src/solana/solana-mailer-client.js +1004 -0
- package/dist/unified/src/solana/solana-mailer-client.js.map +1 -0
- package/dist/unified/src/solana/types.d.ts +3 -2
- package/dist/unified/src/solana/types.d.ts.map +1 -1
- package/dist/unified/src/solana/types.js.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.d.ts +224 -139
- package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.js +577 -857
- package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified/src/unified/types.d.ts +9 -2
- package/dist/unified/src/unified/types.d.ts.map +1 -1
- package/dist/{unified/src/evm/mailer-client.d.ts → unified-esm/src/evm/evm-mailer-client.d.ts} +146 -50
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +1 -0
- package/dist/unified-esm/src/evm/evm-mailer-client.js +920 -0
- package/dist/unified-esm/src/evm/evm-mailer-client.js.map +1 -0
- package/dist/unified-esm/src/evm/index.d.ts +1 -1
- package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
- package/dist/unified-esm/src/evm/index.js +2 -2
- package/dist/unified-esm/src/evm/index.js.map +1 -1
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts +26 -20
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
- package/dist/unified-esm/src/react/context/MailerProvider.js +25 -26
- package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +225 -192
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js +254 -262
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +117 -63
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js +232 -102
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified-esm/src/react/index.d.ts +5 -3
- package/dist/unified-esm/src/react/index.d.ts.map +1 -1
- package/dist/unified-esm/src/react/index.js +9 -5
- package/dist/unified-esm/src/react/index.js.map +1 -1
- package/dist/unified-esm/src/solana/index.d.ts +1 -1
- package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
- package/dist/unified-esm/src/solana/index.js +2 -1
- package/dist/unified-esm/src/solana/index.js.map +1 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +209 -0
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +1 -0
- package/dist/unified-esm/src/solana/solana-mailer-client.js +1000 -0
- package/dist/unified-esm/src/solana/solana-mailer-client.js.map +1 -0
- package/dist/unified-esm/src/solana/types.d.ts +3 -2
- package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
- package/dist/unified-esm/src/solana/types.js.map +1 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +224 -139
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.js +579 -859
- package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified-esm/src/unified/types.d.ts +9 -2
- package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/evm/src/evm/mailer-client.d.ts.map +0 -1
- package/dist/evm/src/evm/mailer-client.js +0 -619
- package/dist/evm/src/evm/mailer-client.js.map +0 -1
- package/dist/solana/solana/mailer-client.d.ts +0 -282
- package/dist/solana/solana/mailer-client.d.ts.map +0 -1
- package/dist/solana/solana/mailer-client.js +0 -989
- package/dist/solana/solana/mailer-client.js.map +0 -1
- package/dist/unified/src/evm/mailer-client.d.ts.map +0 -1
- package/dist/unified/src/evm/mailer-client.js +0 -619
- package/dist/unified/src/evm/mailer-client.js.map +0 -1
- package/dist/unified/src/solana/mailer-client.d.ts +0 -282
- package/dist/unified/src/solana/mailer-client.d.ts.map +0 -1
- package/dist/unified/src/solana/mailer-client.js +0 -989
- package/dist/unified/src/solana/mailer-client.js.map +0 -1
- package/dist/unified-esm/src/evm/mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/mailer-client.js +0 -615
- package/dist/unified-esm/src/evm/mailer-client.js.map +0 -1
- package/dist/unified-esm/src/solana/mailer-client.d.ts +0 -282
- package/dist/unified-esm/src/solana/mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/mailer-client.js +0 -985
- 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
|
|
5
|
+
* OnchainMailerClient - Stateless multi-chain messaging client
|
|
6
6
|
*
|
|
7
|
-
* This version
|
|
8
|
-
*
|
|
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
|
|
10
|
+
* @example EVM Usage
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { createWalletClient, createPublicClient, http } from 'viem';
|
|
13
|
-
* import {
|
|
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
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* '
|
|
28
|
-
*
|
|
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
|
|
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
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* '
|
|
44
|
-
*
|
|
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
|
|
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
|
-
|
|
59
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
*
|
|
92
|
-
*
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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(
|
|
128
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
131
|
-
* Send a message
|
|
132
|
-
* Note: For backward compatibility, 'to' defaults to sender's own address
|
|
132
|
+
* Send a prepared message
|
|
133
133
|
*/
|
|
134
|
-
async
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
167
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
142
168
|
}
|
|
143
169
|
}
|
|
144
170
|
/**
|
|
145
|
-
*
|
|
171
|
+
* Send through webhook
|
|
146
172
|
*/
|
|
147
|
-
async
|
|
148
|
-
|
|
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 (
|
|
155
|
-
|
|
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
|
-
|
|
236
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
159
237
|
}
|
|
160
238
|
}
|
|
161
239
|
/**
|
|
162
|
-
*
|
|
240
|
+
* Reject delegation
|
|
163
241
|
*/
|
|
164
|
-
async
|
|
165
|
-
if (
|
|
166
|
-
|
|
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
|
-
|
|
260
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
170
261
|
}
|
|
171
262
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
208
|
-
throw new Error(
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
335
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
313
336
|
}
|
|
314
337
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
361
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
344
362
|
}
|
|
345
363
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
385
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
374
386
|
}
|
|
375
387
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
409
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
403
410
|
}
|
|
404
411
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
433
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
428
434
|
}
|
|
429
435
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
-
|
|
457
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
456
458
|
}
|
|
457
459
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
481
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
484
482
|
}
|
|
485
483
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
|
|
510
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
524
511
|
}
|
|
525
512
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
-
|
|
530
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
564
531
|
}
|
|
565
532
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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
|
-
|
|
550
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
605
551
|
}
|
|
606
552
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
|
|
567
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
650
568
|
}
|
|
651
569
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
588
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
694
589
|
}
|
|
695
590
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
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
|
-
|
|
604
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
738
605
|
}
|
|
739
606
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
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
|
-
|
|
627
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
778
628
|
}
|
|
779
629
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
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
|
-
|
|
650
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
819
651
|
}
|
|
820
652
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
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
|
-
|
|
667
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
859
668
|
}
|
|
860
669
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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
|
-
|
|
683
|
+
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
899
684
|
}
|
|
900
685
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
-
|
|
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
|
|
703
|
+
* Get contract/program owner
|
|
994
704
|
*/
|
|
995
|
-
async
|
|
996
|
-
if (
|
|
997
|
-
const
|
|
998
|
-
return
|
|
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 (
|
|
1001
|
-
|
|
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
|
-
|
|
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.
|
|
728
|
+
OnchainMailerClient.evmClient = null;
|
|
1009
729
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1010
|
-
OnchainMailerClient.
|
|
730
|
+
OnchainMailerClient.solanaClient = null;
|
|
1011
731
|
//# sourceMappingURL=onchain-mailer-client.js.map
|