@sudobility/contracts 1.13.1 → 1.13.3
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/evm-mailer-client.js +3 -3
- package/dist/evm/src/evm/evm-mailer-client.js.map +1 -1
- package/dist/evm/src/evm/index.d.ts +3 -3
- 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 +2 -2
- package/dist/solana/solana/index.d.ts.map +1 -1
- package/dist/solana/solana/index.js +3 -3
- package/dist/solana/solana/index.js.map +1 -1
- package/dist/solana/solana/solana-mailer-client.d.ts +1 -1
- package/dist/solana/solana/solana-mailer-client.d.ts.map +1 -1
- package/dist/solana/solana/solana-mailer-client.js +1 -1
- package/dist/solana/solana/solana-mailer-client.js.map +1 -1
- package/dist/solana/solana/types.d.ts +1 -1
- package/dist/solana/solana/types.d.ts.map +1 -1
- package/dist/solana/solana/types.js +5 -5
- package/dist/solana/solana/types.js.map +1 -1
- package/dist/unified/src/evm/evm-mailer-client.js +7 -11
- package/dist/unified/src/evm/evm-mailer-client.js.map +1 -1
- package/dist/unified/src/evm/index.d.ts +3 -3
- package/dist/unified/src/evm/index.d.ts.map +1 -1
- package/dist/unified/src/evm/index.js +2 -7
- package/dist/unified/src/evm/index.js.map +1 -1
- package/dist/unified/src/react/context/MailerProvider.js +14 -55
- package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.js +76 -98
- package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.js +52 -68
- package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified/src/react/index.js +5 -47
- package/dist/unified/src/react/index.js.map +1 -1
- package/dist/unified/src/solana/index.d.ts +2 -2
- package/dist/unified/src/solana/index.d.ts.map +1 -1
- package/dist/unified/src/solana/index.js +2 -20
- package/dist/unified/src/solana/index.js.map +1 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts +1 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/solana/solana-mailer-client.js +129 -133
- package/dist/unified/src/solana/solana-mailer-client.js.map +1 -1
- package/dist/unified/src/solana/types.d.ts +1 -1
- package/dist/unified/src/solana/types.d.ts.map +1 -1
- package/dist/unified/src/solana/types.js +6 -13
- package/dist/unified/src/solana/types.js.map +1 -1
- package/dist/unified/src/unified/index.d.ts +3 -3
- package/dist/unified/src/unified/index.d.ts.map +1 -1
- package/dist/unified/src/unified/index.js +2 -7
- package/dist/unified/src/unified/index.js.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.d.ts +35 -35
- package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.js +88 -125
- package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified/src/unified/types.js +1 -2
- package/dist/unified/src/unified/wallet-detector.js +10 -14
- package/dist/unified/src/unified/wallet-detector.js.map +1 -1
- package/dist/unified/src/utils/chain-config.d.ts +1 -1
- package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
- package/dist/unified/src/utils/chain-config.js +9 -13
- package/dist/unified/src/utils/chain-config.js.map +1 -1
- package/dist/unified/src/utils/currency.js +6 -11
- package/dist/unified/src/utils/currency.js.map +1 -1
- package/dist/unified/src/utils/index.d.ts +3 -3
- package/dist/unified/src/utils/index.d.ts.map +1 -1
- package/dist/unified/src/utils/index.js +3 -19
- package/dist/unified/src/utils/index.js.map +1 -1
- package/dist/unified/src/utils/validation.js +11 -17
- package/dist/unified/src/utils/validation.js.map +1 -1
- package/dist/unified/typechain-types/Mailer.js +1 -2
- package/dist/unified/typechain-types/MockUSDC.js +1 -2
- package/dist/unified/typechain-types/common.js +1 -2
- package/dist/unified/typechain-types/factories/Mailer__factory.js +4 -8
- package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/MockUSDC__factory.js +4 -8
- package/dist/unified/typechain-types/factories/MockUSDC__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/index.js +3 -41
- package/dist/unified/typechain-types/factories/index.js.map +1 -1
- package/dist/unified/typechain-types/factories/interfaces/IERC20__factory.js +4 -8
- package/dist/unified/typechain-types/factories/interfaces/IERC20__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/interfaces/index.js +1 -5
- package/dist/unified/typechain-types/factories/interfaces/index.js.map +1 -1
- package/dist/unified/typechain-types/index.js +4 -43
- package/dist/unified/typechain-types/index.js.map +1 -1
- package/dist/unified/typechain-types/interfaces/IERC20.js +1 -2
- package/dist/unified/typechain-types/interfaces/index.js +1 -2
- package/package.json +12 -18
- package/dist/unified/package.json +0 -3
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts +0 -1062
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/evm-mailer-client.js +0 -920
- package/dist/unified-esm/src/evm/evm-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/evm/index.d.ts +0 -4
- package/dist/unified-esm/src/evm/index.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/index.js +0 -5
- package/dist/unified-esm/src/evm/index.js.map +0 -1
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts +0 -108
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +0 -1
- package/dist/unified-esm/src/react/context/MailerProvider.js +0 -119
- package/dist/unified-esm/src/react/context/MailerProvider.js.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +0 -334
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js +0 -392
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +0 -184
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js +0 -316
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +0 -1
- package/dist/unified-esm/src/react/index.d.ts +0 -39
- package/dist/unified-esm/src/react/index.d.ts.map +0 -1
- package/dist/unified-esm/src/react/index.js +0 -43
- package/dist/unified-esm/src/react/index.js.map +0 -1
- package/dist/unified-esm/src/solana/index.d.ts +0 -3
- package/dist/unified-esm/src/solana/index.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/index.js +0 -4
- package/dist/unified-esm/src/solana/index.js.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +0 -209
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.js +0 -1000
- package/dist/unified-esm/src/solana/solana-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/solana/types.d.ts +0 -29
- package/dist/unified-esm/src/solana/types.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/types.js +0 -16
- package/dist/unified-esm/src/solana/types.js.map +0 -1
- package/dist/unified-esm/src/unified/index.d.ts +0 -4
- package/dist/unified-esm/src/unified/index.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/index.js +0 -4
- package/dist/unified-esm/src/unified/index.js.map +0 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +0 -258
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.js +0 -731
- package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/unified/types.d.ts +0 -54
- package/dist/unified-esm/src/unified/types.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/types.js +0 -2
- package/dist/unified-esm/src/unified/types.js.map +0 -1
- package/dist/unified-esm/src/unified/wallet-detector.d.ts +0 -28
- package/dist/unified-esm/src/unified/wallet-detector.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/wallet-detector.js +0 -59
- package/dist/unified-esm/src/unified/wallet-detector.js.map +0 -1
- package/dist/unified-esm/src/utils/chain-config.d.ts +0 -75
- package/dist/unified-esm/src/utils/chain-config.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/chain-config.js +0 -199
- package/dist/unified-esm/src/utils/chain-config.js.map +0 -1
- package/dist/unified-esm/src/utils/currency.d.ts +0 -26
- package/dist/unified-esm/src/utils/currency.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/currency.js +0 -31
- package/dist/unified-esm/src/utils/currency.js.map +0 -1
- package/dist/unified-esm/src/utils/index.d.ts +0 -4
- package/dist/unified-esm/src/utils/index.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/index.js +0 -4
- package/dist/unified-esm/src/utils/index.js.map +0 -1
- package/dist/unified-esm/src/utils/validation.d.ts +0 -10
- package/dist/unified-esm/src/utils/validation.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/validation.js +0 -96
- package/dist/unified-esm/src/utils/validation.js.map +0 -1
- package/dist/unified-esm/typechain-types/Mailer.d.ts +0 -698
- package/dist/unified-esm/typechain-types/Mailer.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/Mailer.js +0 -2
- package/dist/unified-esm/typechain-types/Mailer.js.map +0 -1
- package/dist/unified-esm/typechain-types/MockUSDC.d.ts +0 -118
- package/dist/unified-esm/typechain-types/MockUSDC.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/MockUSDC.js +0 -2
- package/dist/unified-esm/typechain-types/MockUSDC.js.map +0 -1
- package/dist/unified-esm/typechain-types/common.d.ts +0 -51
- package/dist/unified-esm/typechain-types/common.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/common.js +0 -2
- package/dist/unified-esm/typechain-types/common.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +0 -875
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +0 -1121
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.d.ts +0 -193
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.js +0 -259
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/index.d.ts +0 -4
- package/dist/unified-esm/typechain-types/factories/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/index.js +0 -7
- package/dist/unified-esm/typechain-types/factories/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.d.ts +0 -80
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.js +0 -112
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/index.d.ts +0 -2
- package/dist/unified-esm/typechain-types/factories/interfaces/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/index.js +0 -5
- package/dist/unified-esm/typechain-types/factories/interfaces/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/index.d.ts +0 -10
- package/dist/unified-esm/typechain-types/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/index.js +0 -5
- package/dist/unified-esm/typechain-types/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/IERC20.d.ts +0 -70
- package/dist/unified-esm/typechain-types/interfaces/IERC20.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/IERC20.js +0 -2
- package/dist/unified-esm/typechain-types/interfaces/IERC20.js.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/index.d.ts +0 -2
- package/dist/unified-esm/typechain-types/interfaces/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/index.js +0 -2
- package/dist/unified-esm/typechain-types/interfaces/index.js.map +0 -1
|
@@ -1,731 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
// @ts-nocheck - Suppress false TypeScript errors with ESNext modules accessing class properties
|
|
3
|
-
import { ChainType } from '@sudobility/types';
|
|
4
|
-
/**
|
|
5
|
-
* OnchainMailerClient - Stateless multi-chain messaging client
|
|
6
|
-
*
|
|
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
|
-
*
|
|
10
|
-
* @example EVM Usage
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { createWalletClient, createPublicClient, http } from 'viem';
|
|
13
|
-
* import { RpcHelpers } from '@sudobility/configs';
|
|
14
|
-
* import { Chain } from '@sudobility/types';
|
|
15
|
-
*
|
|
16
|
-
* const chainInfo = RpcHelpers.getChainInfo(Chain.ETH_MAINNET);
|
|
17
|
-
* const walletClient = createWalletClient({
|
|
18
|
-
* chain: mainnet,
|
|
19
|
-
* transport: http()
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* const client = new OnchainMailerClient();
|
|
23
|
-
* await client.sendMessage(
|
|
24
|
-
* 'Subject',
|
|
25
|
-
* 'Body',
|
|
26
|
-
* { walletClient },
|
|
27
|
-
* chainInfo,
|
|
28
|
-
* { priority: true }
|
|
29
|
-
* );
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @example Solana Usage
|
|
33
|
-
* ```typescript
|
|
34
|
-
* import { useWallet } from '@solana/wallet-adapter-react';
|
|
35
|
-
* import { Connection } from '@solana/web3.js';
|
|
36
|
-
* import { RpcHelpers } from '@sudobility/configs';
|
|
37
|
-
* import { Chain } from '@sudobility/types';
|
|
38
|
-
*
|
|
39
|
-
* const chainInfo = RpcHelpers.getChainInfo(Chain.SOLANA_MAINNET);
|
|
40
|
-
* const wallet = useWallet();
|
|
41
|
-
*
|
|
42
|
-
* const client = new OnchainMailerClient();
|
|
43
|
-
* await client.sendMessage(
|
|
44
|
-
* 'Subject',
|
|
45
|
-
* 'Body',
|
|
46
|
-
* { wallet },
|
|
47
|
-
* chainInfo,
|
|
48
|
-
* { priority: true }
|
|
49
|
-
* );
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export class OnchainMailerClient {
|
|
53
|
-
/**
|
|
54
|
-
* Create a new stateless OnchainMailerClient
|
|
55
|
-
* No configuration needed in constructor
|
|
56
|
-
*/
|
|
57
|
-
constructor() {
|
|
58
|
-
// Stateless - no initialization needed
|
|
59
|
-
}
|
|
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;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
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
|
|
83
|
-
*/
|
|
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
|
-
};
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Send a prepared message
|
|
133
|
-
*/
|
|
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
|
-
};
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Send through webhook
|
|
172
|
-
*/
|
|
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
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
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
|
|
213
|
-
*/
|
|
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
|
-
};
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Reject delegation
|
|
241
|
-
*/
|
|
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
|
-
};
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
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
|
|
276
|
-
};
|
|
277
|
-
}
|
|
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
|
-
}
|
|
289
|
-
}
|
|
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
|
-
};
|
|
301
|
-
}
|
|
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
|
-
};
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
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
|
-
};
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
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
|
-
};
|
|
351
|
-
}
|
|
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
|
-
};
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
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
|
-
};
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
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
|
-
};
|
|
399
|
-
}
|
|
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
|
-
};
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
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
|
-
};
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
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
|
-
};
|
|
447
|
-
}
|
|
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
|
-
};
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
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
|
-
};
|
|
471
|
-
}
|
|
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
|
-
};
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
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
|
-
};
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
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');
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
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');
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
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;
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
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);
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
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);
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
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;
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
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
|
-
};
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
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);
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
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);
|
|
681
|
-
}
|
|
682
|
-
else {
|
|
683
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
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);
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
throw new Error(`Unsupported chain type: ${chainInfo.chainType}`);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Get contract/program owner
|
|
704
|
-
*/
|
|
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);
|
|
709
|
-
}
|
|
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();
|
|
714
|
-
}
|
|
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');
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
// Cache for dynamic imports
|
|
727
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
728
|
-
OnchainMailerClient.evmClient = null;
|
|
729
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
730
|
-
OnchainMailerClient.solanaClient = null;
|
|
731
|
-
//# sourceMappingURL=onchain-mailer-client.js.map
|