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