@sign-global/tokentable 0.4.2-beta.2 → 0.4.2-beta.4
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/cjs/airdrop/common/index.d.ts +1 -1
- package/dist/cjs/airdrop/constants/chain-config.d.ts +1 -1
- package/dist/cjs/airdrop/constants/chain-config.js +1 -1
- package/dist/cjs/airdrop/constants/chain-config.js.map +1 -1
- package/dist/esm/airdrop/common/index.d.ts +1 -1
- package/dist/esm/airdrop/constants/chain-config.d.ts +1 -1
- package/dist/esm/airdrop/constants/chain-config.js +1 -1
- package/dist/esm/airdrop/constants/chain-config.js.map +1 -1
- package/package.json +2 -9
- package/src/airdrop/AirdropClient.ts +0 -307
- package/src/airdrop/SignatureAirdropClient.ts +0 -378
- package/src/airdrop/common/index.ts +0 -54
- package/src/airdrop/common/projectDataForTon.ts +0 -79
- package/src/airdrop/constants/chain-config.ts +0 -107
- package/src/airdrop/constants/index.ts +0 -9
- package/src/airdrop/constants/network.ts +0 -78
- package/src/airdrop/contracts/evm/AirdropService.ts +0 -181
- package/src/airdrop/contracts/evm/SignatureAirdropService.ts +0 -114
- package/src/airdrop/contracts/evm/contracts/AirdropSignatureClient.ts +0 -63
- package/src/airdrop/contracts/evm/contracts/AirdropSignatureFeeClient.ts +0 -61
- package/src/airdrop/contracts/evm/contracts/AirdropV2Client.ts +0 -37
- package/src/airdrop/contracts/evm/contracts/AirdropV3Client.ts +0 -49
- package/src/airdrop/contracts/evm/contracts/AirdropV3FeeClient.ts +0 -16
- package/src/airdrop/contracts/evm/contracts/AirdropV4Client.ts +0 -36
- package/src/airdrop/contracts/evm/contracts/ContractBaseClient.ts +0 -85
- package/src/airdrop/contracts/evm/contracts/DeployClient.ts +0 -35
- package/src/airdrop/contracts/evm/contracts/FeeCollectorClient.ts +0 -21
- package/src/airdrop/contracts/evm/contracts/KycClient.ts +0 -21
- package/src/airdrop/contracts/evm/contracts/abis/Airdrop.json +0 -674
- package/src/airdrop/contracts/evm/contracts/abis/AirdropV2.json +0 -676
- package/src/airdrop/contracts/evm/contracts/abis/AirdropV3.json +0 -740
- package/src/airdrop/contracts/evm/contracts/abis/AirdropV3_Fee.json +0 -678
- package/src/airdrop/contracts/evm/contracts/abis/CustomFeeNativeAirdropV4.json +0 -701
- package/src/airdrop/contracts/evm/contracts/abis/Deployer.json +0 -271
- package/src/airdrop/contracts/evm/contracts/abis/ERC721.json +0 -737
- package/src/airdrop/contracts/evm/contracts/abis/FeeCollector.json +0 -322
- package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenECDSADistributor.json +0 -564
- package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenWithFeesECDSADistributor.json +0 -260
- package/src/airdrop/contracts/evm/contracts/abis/KycHook.json +0 -312
- package/src/airdrop/contracts/index.ts +0 -4
- package/src/airdrop/contracts/solana/AirdropSignatureClient.ts +0 -242
- package/src/airdrop/contracts/solana/FeeCollectorClient.ts +0 -43
- package/src/airdrop/contracts/solana/SignatureAirdropService.ts +0 -51
- package/src/airdrop/contracts/solana/SolanaContractClient.ts +0 -126
- package/src/airdrop/contracts/solana/fee_collector.json +0 -1063
- package/src/airdrop/contracts/solana/fee_collector.ts +0 -1069
- package/src/airdrop/contracts/solana/fungible_token_distributor_solana.json +0 -1573
- package/src/airdrop/contracts/solana/fungible_token_distributor_solana.ts +0 -1579
- package/src/airdrop/contracts/ton/AirdropClientV1.ts +0 -122
- package/src/airdrop/contracts/ton/AirdropClientV2.ts +0 -118
- package/src/airdrop/contracts/ton/AirdropClientV21.ts +0 -131
- package/src/airdrop/contracts/ton/AirdropClientV3.ts +0 -127
- package/src/airdrop/contracts/ton/AirdropService.ts +0 -150
- package/src/airdrop/contracts/ton/TonContractBaseClient.ts +0 -236
- package/src/airdrop/contracts/ton/v1/build/Leaf.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v1/build/MerkleTokenDistributor.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v1/utils/constants.ts +0 -42
- package/src/airdrop/contracts/ton/v1/utils/date.utils.ts +0 -11
- package/src/airdrop/contracts/ton/v1/utils/index.ts +0 -3
- package/src/airdrop/contracts/ton/v1/utils/ton.utils.ts +0 -84
- package/src/airdrop/contracts/ton/v1/wrappers/JettonMinter.ts +0 -81
- package/src/airdrop/contracts/ton/v1/wrappers/JettonWallet.ts +0 -73
- package/src/airdrop/contracts/ton/v1/wrappers/Leaf.ts +0 -88
- package/src/airdrop/contracts/ton/v1/wrappers/MerkleTokenDistributor.ts +0 -317
- package/src/airdrop/contracts/ton/v1/wrappers/index.ts +0 -2
- package/src/airdrop/contracts/ton/v2/build/Leaf.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v2/build/MerkleTokenDistributor.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v2/utils/constants.ts +0 -43
- package/src/airdrop/contracts/ton/v2/utils/date.utils.ts +0 -11
- package/src/airdrop/contracts/ton/v2/utils/index.ts +0 -3
- package/src/airdrop/contracts/ton/v2/utils/ton.utils.ts +0 -102
- package/src/airdrop/contracts/ton/v2/wrappers/Leaf.ts +0 -69
- package/src/airdrop/contracts/ton/v2/wrappers/MerkleTokenDistributor.ts +0 -340
- package/src/airdrop/contracts/ton/v2/wrappers/index.ts +0 -2
- package/src/airdrop/contracts/ton/v21/build/Leaf.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v21/build/MerkleTokenDistributor.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v21/utils/constants.ts +0 -48
- package/src/airdrop/contracts/ton/v21/utils/date.utils.ts +0 -11
- package/src/airdrop/contracts/ton/v21/utils/index.ts +0 -3
- package/src/airdrop/contracts/ton/v21/utils/ton.utils.ts +0 -84
- package/src/airdrop/contracts/ton/v21/wrappers/Leaf.ts +0 -69
- package/src/airdrop/contracts/ton/v21/wrappers/MerkleTokenDistributor.ts +0 -346
- package/src/airdrop/contracts/ton/v21/wrappers/index.ts +0 -2
- package/src/airdrop/contracts/ton/v3/build/Leaf.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v3/build/MerkleTokenDistributor.compiled.json +0 -1
- package/src/airdrop/contracts/ton/v3/utils/constants.ts +0 -43
- package/src/airdrop/contracts/ton/v3/utils/date.utils.ts +0 -11
- package/src/airdrop/contracts/ton/v3/utils/index.ts +0 -3
- package/src/airdrop/contracts/ton/v3/utils/ton.utils.ts +0 -84
- package/src/airdrop/contracts/ton/v3/wrappers/Leaf.ts +0 -68
- package/src/airdrop/contracts/ton/v3/wrappers/MerkleTokenDistributor.ts +0 -316
- package/src/airdrop/contracts/ton/v3/wrappers/index.ts +0 -2
- package/src/airdrop/index.ts +0 -10
- package/src/airdrop/services/index.ts +0 -166
- package/src/airdrop/services/wallet-service/ton/WalletService.ts +0 -226
- package/src/airdrop/services/wallet-service/ton/index.ts +0 -1
- package/src/airdrop/strategies/AirdropStrategyFactory.ts +0 -31
- package/src/airdrop/strategies/EvmAirdropStrategy.ts +0 -81
- package/src/airdrop/strategies/IAirdropStrategy.ts +0 -26
- package/src/airdrop/strategies/StrategyCache.ts +0 -34
- package/src/airdrop/strategies/TonAirdropStrategy.ts +0 -77
- package/src/airdrop/tests/index.test.ts +0 -387
- package/src/airdrop/types/index.ts +0 -200
- package/src/index.ts +0 -3
- package/src/utils/api-client.ts +0 -69
- package/src/utils/index.ts +0 -3
- package/src/utils/utils.ts +0 -45
- package/src/utils/web3.ts +0 -172
- package/src/wallets/WalletBase.ts +0 -92
- package/src/wallets/WalletFactory.tsx +0 -35
- package/src/wallets/index.ts +0 -3
- package/src/wallets/providers/evm/EvmWallet.ts +0 -101
- package/src/wallets/providers/evm/index.tsx +0 -56
- package/src/wallets/providers/index.ts +0 -4
- package/src/wallets/providers/solana/index.tsx +0 -133
- package/src/wallets/providers/ton/TonWallet.ts +0 -153
- package/src/wallets/providers/ton/index.tsx +0 -41
- package/src/wallets/types.ts +0 -45
- package/src/wallets/utils/index.ts +0 -61
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import TonWeb from 'tonweb';
|
|
2
|
-
import { Address } from '@ton/core';
|
|
3
|
-
import { JettonMaster, TonClient } from '@ton/ton';
|
|
4
|
-
import { delay, flipAddressType } from '../../../../utils';
|
|
5
|
-
|
|
6
|
-
import { Api, HttpClient, Event } from 'tonapi-sdk-js';
|
|
7
|
-
import { ChainConfig } from '../../../constants';
|
|
8
|
-
import { getJettonInfo } from '../../index';
|
|
9
|
-
import { CHAIN } from '@tonconnect/ui-react';
|
|
10
|
-
// import { getHttpEndpoint } from '@orbs-network/ton-access';
|
|
11
|
-
// import { CHAIN } from '@tonconnect/ui-react';
|
|
12
|
-
|
|
13
|
-
interface WaitForTransactionOptions {
|
|
14
|
-
address: string;
|
|
15
|
-
hash: string;
|
|
16
|
-
refetchInterval?: number;
|
|
17
|
-
refetchLimit?: number;
|
|
18
|
-
chainId: string;
|
|
19
|
-
contractAddress?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export abstract class TonWalletService {
|
|
23
|
-
// static walletClient = tonStore.walletClient;
|
|
24
|
-
|
|
25
|
-
static disconnect() {
|
|
26
|
-
//
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static async getTonClient(chainId: string) {
|
|
30
|
-
const endpoint = ChainConfig[chainId as keyof typeof ChainConfig].rpcUrl;
|
|
31
|
-
// const endpoint = await getHttpEndpoint({ network: chainId === CHAIN.TESTNET ? 'testnet' : 'mainnet' });
|
|
32
|
-
return new TonClient({
|
|
33
|
-
endpoint: endpoint
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static getTonApiClient(chainId: string) {
|
|
38
|
-
const { tonApiPrefix } = ChainConfig[chainId as keyof typeof ChainConfig] as any;
|
|
39
|
-
|
|
40
|
-
const httpClient = new HttpClient({
|
|
41
|
-
baseUrl: tonApiPrefix
|
|
42
|
-
// baseApiParams: {
|
|
43
|
-
// headers: {
|
|
44
|
-
// Authorization: `Bearer ${tonApiKey}`,
|
|
45
|
-
// 'Content-type': 'application/json'
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const client = new Api(httpClient);
|
|
51
|
-
return client;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static waitForTransactionByClient = async (options: WaitForTransactionOptions): Promise<Event | null> => {
|
|
55
|
-
const { hash, refetchInterval = 3000, refetchLimit, chainId } = options;
|
|
56
|
-
|
|
57
|
-
return new Promise((resolve) => {
|
|
58
|
-
let refetches = 0;
|
|
59
|
-
const interval = setInterval(async () => {
|
|
60
|
-
refetches += 1;
|
|
61
|
-
|
|
62
|
-
console.log(hash, 'waiting transaction...');
|
|
63
|
-
const tonApi = this.getTonApiClient(chainId);
|
|
64
|
-
const events = await tonApi.events.getEvent(hash);
|
|
65
|
-
console.log(events, 'traceData');
|
|
66
|
-
if (!events.in_progress) {
|
|
67
|
-
await delay(3000);
|
|
68
|
-
clearInterval(interval);
|
|
69
|
-
resolve(events);
|
|
70
|
-
}
|
|
71
|
-
if (refetchLimit && refetches >= refetchLimit) {
|
|
72
|
-
clearInterval(interval);
|
|
73
|
-
resolve(null);
|
|
74
|
-
}
|
|
75
|
-
}, refetchInterval);
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
static waitForTransactionLegacy = async (options: WaitForTransactionOptions): Promise<Event | null> => {
|
|
80
|
-
const { refetchInterval = 3000, refetchLimit, chainId, address, contractAddress } = options;
|
|
81
|
-
|
|
82
|
-
const tonApi = this.getTonApiClient(chainId);
|
|
83
|
-
const tonClient = await this.getTonClient(chainId);
|
|
84
|
-
const walletAddress = Address.parse(address);
|
|
85
|
-
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
let refetches = 0;
|
|
88
|
-
const interval = setInterval(async () => {
|
|
89
|
-
refetches += 1;
|
|
90
|
-
|
|
91
|
-
console.log('waiting transaction...');
|
|
92
|
-
|
|
93
|
-
let hash;
|
|
94
|
-
|
|
95
|
-
if (contractAddress) {
|
|
96
|
-
const res = await tonApi.accounts.getAccountEvents(address, {
|
|
97
|
-
limit: 5
|
|
98
|
-
});
|
|
99
|
-
const targetTransaction = res.events.find((it) => {
|
|
100
|
-
return (
|
|
101
|
-
it.actions.length &&
|
|
102
|
-
it.actions.find((action) => {
|
|
103
|
-
return action.simple_preview.accounts.find((ac) => {
|
|
104
|
-
return Address.parse(ac.address).toRawString() === Address.parse(contractAddress).toRawString();
|
|
105
|
-
});
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
console.log(targetTransaction, 'res');
|
|
110
|
-
if (targetTransaction) {
|
|
111
|
-
hash = targetTransaction.event_id;
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
const state = await tonClient.getContractState(walletAddress);
|
|
115
|
-
console.log(state, 'state');
|
|
116
|
-
hash = state.lastTransaction?.hash;
|
|
117
|
-
}
|
|
118
|
-
if (hash) {
|
|
119
|
-
const events = await tonApi.events.getEvent(hash);
|
|
120
|
-
console.log(events, 'events');
|
|
121
|
-
if (!events.in_progress) {
|
|
122
|
-
clearInterval(interval);
|
|
123
|
-
resolve(events);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (refetchLimit && refetches >= refetchLimit) {
|
|
127
|
-
clearInterval(interval);
|
|
128
|
-
resolve(null);
|
|
129
|
-
}
|
|
130
|
-
}, refetchInterval);
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
static async waitForTransaction({
|
|
135
|
-
hash,
|
|
136
|
-
chainId,
|
|
137
|
-
address,
|
|
138
|
-
contractAddress
|
|
139
|
-
}: {
|
|
140
|
-
hash: string;
|
|
141
|
-
chainId: string;
|
|
142
|
-
address: string;
|
|
143
|
-
contractAddress?: string;
|
|
144
|
-
}) {
|
|
145
|
-
return this.waitForTransactionByClient({ hash, address, chainId, contractAddress });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static async fetchBalance(args: { chainId: string; address: string; token?: string }) {
|
|
149
|
-
try {
|
|
150
|
-
const config = ChainConfig[args.chainId as keyof typeof ChainConfig] as any;
|
|
151
|
-
const options = { method: 'GET' };
|
|
152
|
-
const rawAddress = flipAddressType(args.address);
|
|
153
|
-
|
|
154
|
-
const url = args.token
|
|
155
|
-
? `${config.tonApiPrefix}/v2/accounts/${rawAddress}/jettons?currencies=usd`
|
|
156
|
-
: `${config.tonApiPrefix}/v2/blockchain/accounts/${rawAddress}`;
|
|
157
|
-
|
|
158
|
-
const response = await fetch(url, options);
|
|
159
|
-
const responseJSON: any = await response.json();
|
|
160
|
-
const current = args.token
|
|
161
|
-
? responseJSON.balances.find((it: any) => it.jetton.address === flipAddressType(args.token!))
|
|
162
|
-
: { balance: responseJSON.balance / 1000000000 };
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
value: current?.balance || 0
|
|
166
|
-
};
|
|
167
|
-
} catch {
|
|
168
|
-
return {
|
|
169
|
-
value: 0
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
static async fetchToken(args: { chainId: string; address: string }) {
|
|
175
|
-
return getJettonInfo({
|
|
176
|
-
address: args.address,
|
|
177
|
-
isTestnet: args.chainId === CHAIN.TESTNET ? 'true' : 'false'
|
|
178
|
-
});
|
|
179
|
-
// const client = this.getTonApiClient(args.chainId as string);
|
|
180
|
-
// const data: any = await client.jettons.getJettonInfo(args.address);
|
|
181
|
-
// const { metadata, total_supply } = data;
|
|
182
|
-
// return {
|
|
183
|
-
// ...metadata,
|
|
184
|
-
// totalSupply: {
|
|
185
|
-
// value: total_supply,
|
|
186
|
-
// formatted: fromNano(total_supply)
|
|
187
|
-
// }
|
|
188
|
-
// };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
static async signMessage() {}
|
|
192
|
-
|
|
193
|
-
static async addChain() {}
|
|
194
|
-
|
|
195
|
-
static async fetchEnsAddress() {
|
|
196
|
-
return '';
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
static validateAddress(address: string) {
|
|
200
|
-
try {
|
|
201
|
-
Address.parse(address);
|
|
202
|
-
return true;
|
|
203
|
-
} catch (e) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
static isSameAddress(address1: string, address2: string) {
|
|
209
|
-
return Address.parse(address1).toRawString() === Address.parse(address2).toRawString();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
static getJettonAddress = async ({
|
|
213
|
-
chainId,
|
|
214
|
-
address,
|
|
215
|
-
token
|
|
216
|
-
}: {
|
|
217
|
-
chainId: string;
|
|
218
|
-
address: string;
|
|
219
|
-
token: string;
|
|
220
|
-
}) => {
|
|
221
|
-
const client = await this.getTonClient(chainId);
|
|
222
|
-
const jettonWallet = client.open(JettonMaster.create(Address.parse(token)));
|
|
223
|
-
|
|
224
|
-
return jettonWallet.getWalletAddress(Address.parse(address));
|
|
225
|
-
};
|
|
226
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { TonWalletService } from './WalletService';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ChainType, IWalletClient } from '../types';
|
|
2
|
-
import { EvmAirdropStrategy } from './EvmAirdropStrategy';
|
|
3
|
-
import { IAirdropStrategy, IAirdropStrategyConstructor } from './IAirdropStrategy';
|
|
4
|
-
import { TonAirdropStrategy } from './TonAirdropStrategy';
|
|
5
|
-
import { TonClient } from '@ton/ton';
|
|
6
|
-
|
|
7
|
-
export class AirdropStrategyFactory {
|
|
8
|
-
private static strategyMap: Record<ChainType, IAirdropStrategyConstructor | null> = {
|
|
9
|
-
[ChainType.Evm]: EvmAirdropStrategy,
|
|
10
|
-
[ChainType.Ton]: TonAirdropStrategy,
|
|
11
|
-
[ChainType.Solana]: null
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
static createStrategy(params: {
|
|
15
|
-
chainType: ChainType;
|
|
16
|
-
contractAddress: string;
|
|
17
|
-
chainId: string | number;
|
|
18
|
-
walletClient?: IWalletClient;
|
|
19
|
-
tonClient?: TonClient;
|
|
20
|
-
version?: string;
|
|
21
|
-
}): IAirdropStrategy {
|
|
22
|
-
const { chainType, ...strategyParams } = params;
|
|
23
|
-
const StrategyClass = this.strategyMap[chainType];
|
|
24
|
-
|
|
25
|
-
if (!StrategyClass) {
|
|
26
|
-
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return new StrategyClass(strategyParams);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { EvmAirdropService } from '../contracts';
|
|
2
|
-
import { ChainId, IWalletClient } from '../types';
|
|
3
|
-
import { IAirdropStrategy } from './IAirdropStrategy';
|
|
4
|
-
import { WalletClient as ViemWalletClient } from 'viem';
|
|
5
|
-
|
|
6
|
-
export class EvmAirdropStrategy implements IAirdropStrategy {
|
|
7
|
-
private service: EvmAirdropService | undefined;
|
|
8
|
-
private readonly contractAddress: string;
|
|
9
|
-
private readonly chainId: ChainId;
|
|
10
|
-
private walletClient?: ViemWalletClient;
|
|
11
|
-
private cachedVersion: string | null = null;
|
|
12
|
-
|
|
13
|
-
constructor(params: { contractAddress: string; chainId: string | number; walletClient?: IWalletClient }) {
|
|
14
|
-
this.contractAddress = params.contractAddress;
|
|
15
|
-
this.chainId = Number(params.chainId) as ChainId;
|
|
16
|
-
if (params.walletClient) {
|
|
17
|
-
this.walletClient = params.walletClient as ViemWalletClient;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async initialize(walletClient?: IWalletClient): Promise<void> {
|
|
22
|
-
if (walletClient) {
|
|
23
|
-
this.walletClient = walletClient as ViemWalletClient;
|
|
24
|
-
}
|
|
25
|
-
this.service = new EvmAirdropService({
|
|
26
|
-
contractAddress: this.contractAddress,
|
|
27
|
-
chainId: this.chainId,
|
|
28
|
-
walletClient: this.walletClient
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
isInitialized(): boolean {
|
|
33
|
-
return !!this.service;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getVersion(): Promise<string> {
|
|
37
|
-
if (this.cachedVersion) {
|
|
38
|
-
return this.cachedVersion;
|
|
39
|
-
}
|
|
40
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
41
|
-
this.cachedVersion = await this.service.getVersion();
|
|
42
|
-
return this.cachedVersion;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async claim(claimData: any): Promise<any> {
|
|
46
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
47
|
-
const { proof, group, data, value, extraData } = claimData;
|
|
48
|
-
return this.service.claim({
|
|
49
|
-
proof,
|
|
50
|
-
group,
|
|
51
|
-
data,
|
|
52
|
-
value,
|
|
53
|
-
extraData
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async checkClaimed(claimData: any): Promise<boolean> {
|
|
58
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
59
|
-
return this.service.isLeafUsed(claimData.leaf);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {
|
|
63
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
64
|
-
return this.service.batchFetchClaimed(leafs);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async getNFT(): Promise<string> {
|
|
68
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
69
|
-
return this.service.getNFT() as unknown as string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async getKycThreshold(): Promise<bigint> {
|
|
73
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
74
|
-
return this.service.getKycThreshold();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {
|
|
78
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
79
|
-
return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { IWalletClient } from '../types';
|
|
2
|
-
import { TonClient } from '@ton/ton';
|
|
3
|
-
|
|
4
|
-
export interface IAirdropStrategy {
|
|
5
|
-
getVersion(): Promise<string>;
|
|
6
|
-
claim(claimData: any, options?: { onLoading?: () => void }): Promise<any>;
|
|
7
|
-
checkClaimed(claimData: any): Promise<boolean>;
|
|
8
|
-
isInitialized(): boolean;
|
|
9
|
-
initialize(walletClient?: IWalletClient): Promise<void>;
|
|
10
|
-
getPaused?(): Promise<boolean>;
|
|
11
|
-
// EVM specific methods
|
|
12
|
-
batchCheckClaimed?(leafs: string[]): Promise<Array<{ result: boolean; status: string }>>;
|
|
13
|
-
getNFT?(): Promise<string>;
|
|
14
|
-
getKycThreshold?(): Promise<bigint>;
|
|
15
|
-
getClaimFee?(contractAddress: string, amount: bigint): Promise<string | bigint>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IAirdropStrategyConstructor {
|
|
19
|
-
new (params: {
|
|
20
|
-
contractAddress: string;
|
|
21
|
-
chainId: string | number;
|
|
22
|
-
walletClient?: IWalletClient;
|
|
23
|
-
tonClient?: TonClient;
|
|
24
|
-
version?: string;
|
|
25
|
-
}): IAirdropStrategy;
|
|
26
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IAirdropStrategy } from './IAirdropStrategy';
|
|
2
|
-
|
|
3
|
-
export class StrategyCache {
|
|
4
|
-
private readOnlyStrategies: Map<string, IAirdropStrategy> = new Map();
|
|
5
|
-
private walletStrategies: Map<string, IAirdropStrategy> = new Map();
|
|
6
|
-
|
|
7
|
-
private getCacheKey(contractAddress: string, chainId: string | number, chainType: string): string {
|
|
8
|
-
return `${chainType}:${contractAddress}:${chainId}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
getStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet: boolean = false): IAirdropStrategy | undefined {
|
|
12
|
-
const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;
|
|
13
|
-
const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);
|
|
14
|
-
return cache.get(cacheKey);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
setStrategy(contractAddress: string, chainId: string | number, chainType: string, strategy: IAirdropStrategy, hasWallet: boolean = false): void {
|
|
18
|
-
const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;
|
|
19
|
-
const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);
|
|
20
|
-
cache.set(cacheKey, strategy);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
clearStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet?: boolean): void {
|
|
24
|
-
const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);
|
|
25
|
-
if (hasWallet === undefined || hasWallet) {
|
|
26
|
-
this.walletStrategies.delete(cacheKey);
|
|
27
|
-
}
|
|
28
|
-
if (hasWallet === undefined || !hasWallet) {
|
|
29
|
-
this.readOnlyStrategies.delete(cacheKey);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const strategyCache = new StrategyCache();
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { TonClient } from '@ton/ton';
|
|
2
|
-
import { TonConnectUI } from '@tonconnect/ui-react';
|
|
3
|
-
import { TonAirdropService } from '../contracts';
|
|
4
|
-
import { IWalletClient } from '../types';
|
|
5
|
-
import { IAirdropStrategy } from './IAirdropStrategy';
|
|
6
|
-
|
|
7
|
-
export class TonAirdropStrategy implements IAirdropStrategy {
|
|
8
|
-
private service: TonAirdropService | undefined;
|
|
9
|
-
private readonly contractAddress: string;
|
|
10
|
-
private readonly chainId: string;
|
|
11
|
-
private readonly tonClient?: TonClient;
|
|
12
|
-
private walletClient?: TonConnectUI;
|
|
13
|
-
private cachedVersion: string | null = null;
|
|
14
|
-
|
|
15
|
-
constructor(params: {
|
|
16
|
-
contractAddress: string;
|
|
17
|
-
chainId: string | number;
|
|
18
|
-
walletClient?: IWalletClient;
|
|
19
|
-
tonClient?: TonClient;
|
|
20
|
-
version?: string;
|
|
21
|
-
}) {
|
|
22
|
-
this.contractAddress = params.contractAddress;
|
|
23
|
-
this.chainId = params.chainId.toString();
|
|
24
|
-
this.tonClient = params.tonClient;
|
|
25
|
-
if (params.walletClient) {
|
|
26
|
-
this.walletClient = params.walletClient as TonConnectUI;
|
|
27
|
-
}
|
|
28
|
-
if (params.version) {
|
|
29
|
-
this.cachedVersion = params.version;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async initialize(walletClient?: IWalletClient): Promise<void> {
|
|
34
|
-
if (walletClient) {
|
|
35
|
-
this.walletClient = walletClient as TonConnectUI;
|
|
36
|
-
}
|
|
37
|
-
this.service = new TonAirdropService({
|
|
38
|
-
address: this.contractAddress,
|
|
39
|
-
chainId: this.chainId,
|
|
40
|
-
walletClient: this.walletClient,
|
|
41
|
-
tonClient: this.tonClient,
|
|
42
|
-
version: this.cachedVersion || undefined
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
isInitialized(): boolean {
|
|
47
|
-
return !!this.service;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async getVersion(): Promise<string> {
|
|
51
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
52
|
-
if (!this.cachedVersion) {
|
|
53
|
-
this.cachedVersion = await this.service.getVersion();
|
|
54
|
-
}
|
|
55
|
-
return this.cachedVersion;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async claim(claimData: any, options?: { onLoading?: () => void }): Promise<any> {
|
|
59
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
60
|
-
return this.service.claim(claimData, options);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async checkClaimed(claimData: any): Promise<boolean> {
|
|
64
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
65
|
-
return this.service.checkClaimed(claimData);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async getPaused(): Promise<boolean> {
|
|
69
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
70
|
-
return this.service.getPaused();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async getClaimFee(contractAddress: string, amount: bigint): Promise<string> {
|
|
74
|
-
if (!this.service) throw new Error('Strategy not initialized');
|
|
75
|
-
return this.service.getClaimFee(contractAddress, amount);
|
|
76
|
-
}
|
|
77
|
-
}
|