@sign-global/tokentable 0.4.3-beta.0 → 0.4.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/cjs/airdrop/AirdropClient.d.ts +1 -1
  2. package/dist/cjs/airdrop/AirdropClient.js +4 -3
  3. package/dist/cjs/airdrop/AirdropClient.js.map +1 -1
  4. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +10 -1
  5. package/dist/cjs/airdrop/SignatureAirdropClient.js +48 -11
  6. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -1
  7. package/dist/cjs/airdrop/common/index.d.ts +1 -1
  8. package/dist/cjs/airdrop/constants/chain-config.d.ts +1 -1
  9. package/dist/cjs/airdrop/constants/chain-config.js +1 -1
  10. package/dist/cjs/airdrop/constants/chain-config.js.map +1 -1
  11. package/dist/cjs/airdrop/constants/index.d.ts +1 -0
  12. package/dist/cjs/airdrop/constants/index.js +1 -0
  13. package/dist/cjs/airdrop/constants/index.js.map +1 -1
  14. package/dist/cjs/airdrop/contracts/evm/contracts/AirdropSignatureClient.js +0 -1
  15. package/dist/cjs/airdrop/contracts/evm/contracts/AirdropSignatureClient.js.map +1 -1
  16. package/dist/cjs/airdrop/contracts/index.d.ts +1 -0
  17. package/dist/cjs/airdrop/contracts/index.js +3 -1
  18. package/dist/cjs/airdrop/contracts/index.js.map +1 -1
  19. package/dist/cjs/airdrop/contracts/solana/AirdropService.d.ts +16 -0
  20. package/dist/cjs/airdrop/contracts/solana/AirdropService.js +38 -0
  21. package/dist/cjs/airdrop/contracts/solana/AirdropService.js.map +1 -0
  22. package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js +2 -2
  23. package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
  24. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.d.ts +3 -2
  25. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js +7 -3
  26. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
  27. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.d.ts +49 -0
  28. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.js +242 -0
  29. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.js.map +1 -0
  30. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.d.ts +1 -0
  31. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.js +3 -0
  32. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.js.map +1 -1
  33. package/dist/cjs/airdrop/contracts/solana/fee_collector.d.ts +49 -1
  34. package/dist/cjs/airdrop/contracts/solana/fee_collector.json +51 -3
  35. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.d.ts +1695 -0
  36. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.js +3 -0
  37. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.js.map +1 -0
  38. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.json +1689 -0
  39. package/dist/cjs/airdrop/services/index.d.ts +3 -2
  40. package/dist/cjs/airdrop/services/index.js +8 -1
  41. package/dist/cjs/airdrop/services/index.js.map +1 -1
  42. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.d.ts +1 -0
  43. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.js +2 -1
  44. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.js.map +1 -1
  45. package/dist/cjs/airdrop/strategies/IAirdropStrategy.d.ts +1 -0
  46. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.d.ts +25 -0
  47. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.js +62 -0
  48. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.js.map +1 -0
  49. package/dist/cjs/airdrop/types/index.d.ts +6 -1
  50. package/dist/cjs/airdrop/types/index.js +1 -0
  51. package/dist/cjs/airdrop/types/index.js.map +1 -1
  52. package/dist/esm/airdrop/AirdropClient.d.ts +1 -1
  53. package/dist/esm/airdrop/AirdropClient.js +4 -3
  54. package/dist/esm/airdrop/AirdropClient.js.map +1 -1
  55. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +10 -1
  56. package/dist/esm/airdrop/SignatureAirdropClient.js +49 -12
  57. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -1
  58. package/dist/esm/airdrop/common/index.d.ts +1 -1
  59. package/dist/esm/airdrop/constants/chain-config.d.ts +1 -1
  60. package/dist/esm/airdrop/constants/chain-config.js +1 -1
  61. package/dist/esm/airdrop/constants/chain-config.js.map +1 -1
  62. package/dist/esm/airdrop/constants/index.d.ts +1 -0
  63. package/dist/esm/airdrop/constants/index.js +1 -0
  64. package/dist/esm/airdrop/constants/index.js.map +1 -1
  65. package/dist/esm/airdrop/contracts/evm/contracts/AirdropSignatureClient.js +0 -1
  66. package/dist/esm/airdrop/contracts/evm/contracts/AirdropSignatureClient.js.map +1 -1
  67. package/dist/esm/airdrop/contracts/index.d.ts +1 -0
  68. package/dist/esm/airdrop/contracts/index.js +1 -0
  69. package/dist/esm/airdrop/contracts/index.js.map +1 -1
  70. package/dist/esm/airdrop/contracts/solana/AirdropService.d.ts +16 -0
  71. package/dist/esm/airdrop/contracts/solana/AirdropService.js +34 -0
  72. package/dist/esm/airdrop/contracts/solana/AirdropService.js.map +1 -0
  73. package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js +2 -2
  74. package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
  75. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.d.ts +3 -2
  76. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js +7 -3
  77. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
  78. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.d.ts +49 -0
  79. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.js +212 -0
  80. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.js.map +1 -0
  81. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.d.ts +1 -0
  82. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.js +3 -0
  83. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.js.map +1 -1
  84. package/dist/esm/airdrop/contracts/solana/fee_collector.d.ts +49 -1
  85. package/dist/esm/airdrop/contracts/solana/fee_collector.json +51 -3
  86. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.d.ts +1695 -0
  87. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.js +2 -0
  88. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.js.map +1 -0
  89. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.json +1689 -0
  90. package/dist/esm/airdrop/services/index.d.ts +3 -2
  91. package/dist/esm/airdrop/services/index.js +6 -0
  92. package/dist/esm/airdrop/services/index.js.map +1 -1
  93. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.d.ts +1 -0
  94. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.js +2 -1
  95. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.js.map +1 -1
  96. package/dist/esm/airdrop/strategies/IAirdropStrategy.d.ts +1 -0
  97. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.d.ts +25 -0
  98. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.js +58 -0
  99. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.js.map +1 -0
  100. package/dist/esm/airdrop/types/index.d.ts +6 -1
  101. package/dist/esm/airdrop/types/index.js +1 -0
  102. package/dist/esm/airdrop/types/index.js.map +1 -1
  103. package/package.json +2 -9
  104. package/src/airdrop/AirdropClient.ts +0 -307
  105. package/src/airdrop/SignatureAirdropClient.ts +0 -337
  106. package/src/airdrop/common/index.ts +0 -54
  107. package/src/airdrop/common/projectDataForTon.ts +0 -79
  108. package/src/airdrop/constants/chain-config.ts +0 -107
  109. package/src/airdrop/constants/index.ts +0 -8
  110. package/src/airdrop/constants/network.ts +0 -78
  111. package/src/airdrop/contracts/evm/AirdropService.ts +0 -181
  112. package/src/airdrop/contracts/evm/SignatureAirdropService.ts +0 -114
  113. package/src/airdrop/contracts/evm/contracts/AirdropSignatureClient.ts +0 -63
  114. package/src/airdrop/contracts/evm/contracts/AirdropSignatureFeeClient.ts +0 -61
  115. package/src/airdrop/contracts/evm/contracts/AirdropV2Client.ts +0 -37
  116. package/src/airdrop/contracts/evm/contracts/AirdropV3Client.ts +0 -49
  117. package/src/airdrop/contracts/evm/contracts/AirdropV3FeeClient.ts +0 -16
  118. package/src/airdrop/contracts/evm/contracts/AirdropV4Client.ts +0 -36
  119. package/src/airdrop/contracts/evm/contracts/ContractBaseClient.ts +0 -85
  120. package/src/airdrop/contracts/evm/contracts/DeployClient.ts +0 -35
  121. package/src/airdrop/contracts/evm/contracts/FeeCollectorClient.ts +0 -21
  122. package/src/airdrop/contracts/evm/contracts/KycClient.ts +0 -21
  123. package/src/airdrop/contracts/evm/contracts/abis/Airdrop.json +0 -674
  124. package/src/airdrop/contracts/evm/contracts/abis/AirdropV2.json +0 -676
  125. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3.json +0 -740
  126. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3_Fee.json +0 -678
  127. package/src/airdrop/contracts/evm/contracts/abis/CustomFeeNativeAirdropV4.json +0 -701
  128. package/src/airdrop/contracts/evm/contracts/abis/Deployer.json +0 -271
  129. package/src/airdrop/contracts/evm/contracts/abis/ERC721.json +0 -737
  130. package/src/airdrop/contracts/evm/contracts/abis/FeeCollector.json +0 -322
  131. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenECDSADistributor.json +0 -564
  132. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenWithFeesECDSADistributor.json +0 -260
  133. package/src/airdrop/contracts/evm/contracts/abis/KycHook.json +0 -312
  134. package/src/airdrop/contracts/index.ts +0 -4
  135. package/src/airdrop/contracts/solana/AirdropSignatureClient.ts +0 -242
  136. package/src/airdrop/contracts/solana/FeeCollectorClient.ts +0 -43
  137. package/src/airdrop/contracts/solana/SignatureAirdropService.ts +0 -51
  138. package/src/airdrop/contracts/solana/SolanaContractClient.ts +0 -126
  139. package/src/airdrop/contracts/solana/fee_collector.json +0 -1063
  140. package/src/airdrop/contracts/solana/fee_collector.ts +0 -1069
  141. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.json +0 -1573
  142. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.ts +0 -1579
  143. package/src/airdrop/contracts/ton/AirdropClientV1.ts +0 -122
  144. package/src/airdrop/contracts/ton/AirdropClientV2.ts +0 -118
  145. package/src/airdrop/contracts/ton/AirdropClientV21.ts +0 -131
  146. package/src/airdrop/contracts/ton/AirdropClientV3.ts +0 -127
  147. package/src/airdrop/contracts/ton/AirdropService.ts +0 -150
  148. package/src/airdrop/contracts/ton/TonContractBaseClient.ts +0 -236
  149. package/src/airdrop/contracts/ton/v1/build/Leaf.compiled.json +0 -1
  150. package/src/airdrop/contracts/ton/v1/build/MerkleTokenDistributor.compiled.json +0 -1
  151. package/src/airdrop/contracts/ton/v1/utils/constants.ts +0 -42
  152. package/src/airdrop/contracts/ton/v1/utils/date.utils.ts +0 -11
  153. package/src/airdrop/contracts/ton/v1/utils/index.ts +0 -3
  154. package/src/airdrop/contracts/ton/v1/utils/ton.utils.ts +0 -84
  155. package/src/airdrop/contracts/ton/v1/wrappers/JettonMinter.ts +0 -81
  156. package/src/airdrop/contracts/ton/v1/wrappers/JettonWallet.ts +0 -73
  157. package/src/airdrop/contracts/ton/v1/wrappers/Leaf.ts +0 -88
  158. package/src/airdrop/contracts/ton/v1/wrappers/MerkleTokenDistributor.ts +0 -317
  159. package/src/airdrop/contracts/ton/v1/wrappers/index.ts +0 -2
  160. package/src/airdrop/contracts/ton/v2/build/Leaf.compiled.json +0 -1
  161. package/src/airdrop/contracts/ton/v2/build/MerkleTokenDistributor.compiled.json +0 -1
  162. package/src/airdrop/contracts/ton/v2/utils/constants.ts +0 -43
  163. package/src/airdrop/contracts/ton/v2/utils/date.utils.ts +0 -11
  164. package/src/airdrop/contracts/ton/v2/utils/index.ts +0 -3
  165. package/src/airdrop/contracts/ton/v2/utils/ton.utils.ts +0 -102
  166. package/src/airdrop/contracts/ton/v2/wrappers/Leaf.ts +0 -69
  167. package/src/airdrop/contracts/ton/v2/wrappers/MerkleTokenDistributor.ts +0 -340
  168. package/src/airdrop/contracts/ton/v2/wrappers/index.ts +0 -2
  169. package/src/airdrop/contracts/ton/v21/build/Leaf.compiled.json +0 -1
  170. package/src/airdrop/contracts/ton/v21/build/MerkleTokenDistributor.compiled.json +0 -1
  171. package/src/airdrop/contracts/ton/v21/utils/constants.ts +0 -48
  172. package/src/airdrop/contracts/ton/v21/utils/date.utils.ts +0 -11
  173. package/src/airdrop/contracts/ton/v21/utils/index.ts +0 -3
  174. package/src/airdrop/contracts/ton/v21/utils/ton.utils.ts +0 -84
  175. package/src/airdrop/contracts/ton/v21/wrappers/Leaf.ts +0 -69
  176. package/src/airdrop/contracts/ton/v21/wrappers/MerkleTokenDistributor.ts +0 -346
  177. package/src/airdrop/contracts/ton/v21/wrappers/index.ts +0 -2
  178. package/src/airdrop/contracts/ton/v3/build/Leaf.compiled.json +0 -1
  179. package/src/airdrop/contracts/ton/v3/build/MerkleTokenDistributor.compiled.json +0 -1
  180. package/src/airdrop/contracts/ton/v3/utils/constants.ts +0 -43
  181. package/src/airdrop/contracts/ton/v3/utils/date.utils.ts +0 -11
  182. package/src/airdrop/contracts/ton/v3/utils/index.ts +0 -3
  183. package/src/airdrop/contracts/ton/v3/utils/ton.utils.ts +0 -84
  184. package/src/airdrop/contracts/ton/v3/wrappers/Leaf.ts +0 -68
  185. package/src/airdrop/contracts/ton/v3/wrappers/MerkleTokenDistributor.ts +0 -316
  186. package/src/airdrop/contracts/ton/v3/wrappers/index.ts +0 -2
  187. package/src/airdrop/index.ts +0 -10
  188. package/src/airdrop/services/index.ts +0 -159
  189. package/src/airdrop/services/wallet-service/ton/WalletService.ts +0 -226
  190. package/src/airdrop/services/wallet-service/ton/index.ts +0 -1
  191. package/src/airdrop/strategies/AirdropStrategyFactory.ts +0 -31
  192. package/src/airdrop/strategies/EvmAirdropStrategy.ts +0 -81
  193. package/src/airdrop/strategies/IAirdropStrategy.ts +0 -26
  194. package/src/airdrop/strategies/StrategyCache.ts +0 -34
  195. package/src/airdrop/strategies/TonAirdropStrategy.ts +0 -77
  196. package/src/airdrop/tests/index.test.ts +0 -387
  197. package/src/airdrop/types/index.ts +0 -199
  198. package/src/index.ts +0 -3
  199. package/src/utils/api-client.ts +0 -69
  200. package/src/utils/index.ts +0 -3
  201. package/src/utils/utils.ts +0 -45
  202. package/src/utils/web3.ts +0 -172
  203. package/src/wallets/WalletBase.ts +0 -92
  204. package/src/wallets/WalletFactory.tsx +0 -35
  205. package/src/wallets/index.ts +0 -3
  206. package/src/wallets/providers/evm/EvmWallet.ts +0 -101
  207. package/src/wallets/providers/evm/index.tsx +0 -56
  208. package/src/wallets/providers/index.ts +0 -4
  209. package/src/wallets/providers/solana/index.tsx +0 -133
  210. package/src/wallets/providers/ton/TonWallet.ts +0 -153
  211. package/src/wallets/providers/ton/index.tsx +0 -41
  212. package/src/wallets/types.ts +0 -45
  213. package/src/wallets/utils/index.ts +0 -61
@@ -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
- }
@@ -1,387 +0,0 @@
1
- import { AirdropClient } from '../AirdropClient';
2
- import { TonClient } from '@ton/ton';
3
-
4
- describe('AirdropClient', () => {
5
- let client: AirdropClient;
6
- const mockTonClient = new TonClient({
7
- endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC'
8
- });
9
- const mockEndpoint = 'https://dev.dev.ethsign.xyz:3057/api';
10
-
11
- beforeEach(() => {
12
- jest.clearAllMocks();
13
- });
14
-
15
- describe('initialize', () => {
16
- it('should use projectId correctly', async () => {
17
- client = new AirdropClient({
18
- projectId: 'AD_TEV94wvkxkvn',
19
- endpoint: mockEndpoint
20
- });
21
-
22
- const projectInfo = await client.getProjectInfo();
23
- expect(projectInfo).toBeDefined();
24
- }, 6000);
25
-
26
- it('should use slug correctly', async () => {
27
- client = new AirdropClient({
28
- slug: 'wat'
29
- });
30
-
31
- const projectInfo = await client.getProjectInfo();
32
- expect(projectInfo).toBeTruthy();
33
- });
34
- });
35
-
36
- describe('test main features', () => {
37
- beforeEach(async () => {
38
- client = new AirdropClient({
39
- projectId: 'AD_TEV94wvkxkvn',
40
- endpoint: mockEndpoint
41
- });
42
- });
43
-
44
- it('should get version', async () => {
45
- const version = await client.getVersion();
46
- console.log(version);
47
- expect(version).toBeDefined();
48
-
49
- const client1 = new AirdropClient({
50
- projectId: 'AD_oLDjKWXU6JZe'
51
- });
52
-
53
- const version1 = await client1.getVersion();
54
- console.log(version1, 'v1');
55
- expect(version1).toBeDefined();
56
- });
57
-
58
- it('should get paused', async () => {
59
- const client = new AirdropClient({
60
- projectId: 'AD_PeMV2dboWAui',
61
- endpoint: mockEndpoint
62
- });
63
- const paused = await client.getPaused();
64
- console.log(paused);
65
- expect(paused).toBeDefined();
66
- });
67
-
68
- it('should get claim fee', async () => {
69
- // evm
70
- const client = new AirdropClient({
71
- projectId: 'AD_50lczFu9Yhvq',
72
- endpoint: mockEndpoint
73
- });
74
- const fee = await client.getClaimFee();
75
- console.log(fee);
76
- expect(fee).toBeDefined();
77
- });
78
-
79
- it('should get paused throw error', async () => {
80
- // evm
81
- const client = new AirdropClient({
82
- projectId: 'AD_50lczFu9Yhvq',
83
- endpoint: mockEndpoint
84
- });
85
- await expect(client.getPaused()).rejects.toThrow();
86
- });
87
-
88
- it('should check ton claimed', async () => {
89
- const tonClient = new TonClient({
90
- endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC'
91
- });
92
-
93
- const client = new AirdropClient({
94
- projectId: 'AD_WIN4aTbjJPOp',
95
- endpoint: mockEndpoint
96
- });
97
- client.setTonClient(tonClient);
98
-
99
- const version = await client.getVersion();
100
- console.log(version);
101
- expect(version).toBeDefined();
102
-
103
- const claims = await client.getAirdropClaims({ address: 'UQANAsrLyyHoq8N4EZ-QfADXhtoSUybdSKXOknMLWLbA7rt7' });
104
-
105
- const claimed = await client.checkClaimed(claims?.[0].claimId as string);
106
- expect(claimed).toBeDefined();
107
- });
108
-
109
- //AD_S4dSTEXQN96i
110
-
111
- it('should work on native v1', async () => {
112
- client = new AirdropClient({
113
- projectId: 'AD_S4dSTEXQN96i',
114
- endpoint: mockEndpoint
115
- });
116
- const version = await client.getVersion();
117
- console.log(version);
118
- expect(version).toBeDefined();
119
- const fee = await client.getClaimFee();
120
- console.log(fee);
121
- expect(fee).toBeDefined();
122
- });
123
-
124
- it('should get airdrop claims', async () => {
125
- const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
126
- expect(claims).toBeTruthy();
127
- expect(claims?.length).toBe(1);
128
- });
129
-
130
- it('should check claimed', async () => {
131
- const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
132
-
133
- const claimed = await client.checkClaimed(claims?.[0].claimId as string);
134
- expect(claimed).toBeDefined();
135
- });
136
- });
137
-
138
- describe('getStrategy', () => {
139
- let client: AirdropClient;
140
- const mockWalletClient = {
141
- connected: true,
142
- account: { address: '0xMockAddress' },
143
- network: { name: 'mock', chainId: 1 },
144
- connector: { name: 'mock' },
145
- sendTransaction: jest.fn()
146
- } as any;
147
-
148
- beforeEach(async () => {
149
- client = new AirdropClient({
150
- projectId: 'AD_TEV94wvkxkvn',
151
- endpoint: mockEndpoint
152
- });
153
- // Clear strategy cache before each test
154
- jest.clearAllMocks();
155
- });
156
-
157
- it('should get strategy without wallet client (read-only mode)', async () => {
158
- const strategy = await client.getStrategy();
159
- expect(strategy).toBeDefined();
160
- // Verify it's in read-only mode
161
- expect((strategy as any).walletClient).toBeUndefined();
162
- });
163
-
164
- it('should get strategy with wallet client (interactive mode)', async () => {
165
- const strategy = await client.getStrategy(mockWalletClient);
166
- expect(strategy).toBeDefined();
167
- expect((strategy as any).walletClient).toBeDefined();
168
- });
169
-
170
- it('should use cached strategy when available', async () => {
171
- // First call to get strategy
172
- const strategy1 = await client.getStrategy(mockWalletClient);
173
-
174
- // Second call should return cached strategy
175
- const strategy2 = await client.getStrategy(mockWalletClient);
176
-
177
- // Both should be the same instance
178
- expect(strategy1).toBe(strategy2);
179
- });
180
-
181
- it('should reinitialize wallet client even with cached strategy', async () => {
182
- // Get strategy with first wallet client
183
- const strategy1 = await client.getStrategy(mockWalletClient);
184
-
185
- // Create new mock wallet client
186
- const newMockWalletClient = {
187
- connected: true,
188
- account: { address: '0xNewMockAddress' },
189
- network: { name: 'mock', chainId: 1 },
190
- connector: { name: 'mock' },
191
- sendTransaction: jest.fn()
192
- } as any;
193
-
194
- // Get strategy with new wallet client
195
- const strategy2 = await client.getStrategy(newMockWalletClient);
196
-
197
- // Should be same strategy instance but reinitialized with new wallet
198
- expect((strategy2 as any).walletClient).toBeDefined();
199
- expect((strategy2 as any).walletClient).toBe(newMockWalletClient);
200
- });
201
- });
202
-
203
- describe('claimAirdrop', () => {
204
- const mockClaim = jest.fn();
205
- const mockGetClaimFee = jest.fn();
206
- const mockWalletClient = {
207
- connected: true,
208
- account: { address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' },
209
- network: { name: 'mock', chainId: 1 },
210
- connector: { name: 'mock' },
211
- sendTransaction: jest.fn(),
212
- writeContract: jest.fn()
213
- } as any;
214
-
215
- beforeEach(() => {
216
- jest.clearAllMocks();
217
- // Mock getStrategy to return a mock strategy
218
- jest.spyOn(AirdropClient.prototype, 'getStrategy').mockResolvedValue({
219
- claim: mockClaim,
220
- isInitialized: () => true,
221
- initialize: jest.fn(),
222
- getVersion: jest.fn().mockResolvedValue('1.0.0'),
223
- checkClaimed: jest.fn(),
224
- getClaimFee: mockGetClaimFee
225
- });
226
- });
227
-
228
- afterEach(() => {
229
- jest.restoreAllMocks();
230
- });
231
-
232
- it('should claim EVM airdrop with fee (v1/v2)', async () => {
233
- // Mock getClaimFee to return a specific value for this test
234
- mockGetClaimFee.mockResolvedValueOnce(BigInt(1000));
235
-
236
- const client = new AirdropClient({
237
- projectId: 'AD_50lczFu9Yhvq', // EVM project with fee
238
- endpoint: mockEndpoint
239
- });
240
-
241
- const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
242
-
243
- await client.claimAirdrop({
244
- claimId: claims[0].claimId as string,
245
- walletClient: mockWalletClient
246
- });
247
-
248
- // Verify claim was called with correct parameters
249
- expect(mockClaim).toHaveBeenCalledWith(
250
- expect.objectContaining({
251
- extraData: {
252
- isLegacy: true,
253
- attestationId: BigInt(1)
254
- },
255
- value: BigInt(1000) // Should match the mocked getClaimFee value
256
- }),
257
- undefined
258
- );
259
- });
260
-
261
- it('should claim EVM airdrop without fee', async () => {
262
- // Mock getClaimFee to return undefined for this test
263
- mockGetClaimFee.mockResolvedValueOnce(undefined);
264
-
265
- const client = new AirdropClient({
266
- projectId: 'AD_WMTW9cHZJB46', // EVM v3/v4 native project
267
- endpoint: mockEndpoint
268
- });
269
-
270
- const claims = await client.getAirdropClaims({ address: '0x5f5F5919dEc54AdF9743dd2c9dA4EbE7D60B8B9b' });
271
-
272
- await client.claimAirdrop({
273
- claimId: claims[0].claimId as string,
274
- walletClient: mockWalletClient
275
- });
276
-
277
- expect(mockClaim).toHaveBeenCalledWith(
278
- expect.objectContaining({
279
- extraData: {
280
- isLegacy: true,
281
- attestationId: BigInt(1)
282
- },
283
- value: undefined
284
- }),
285
- undefined
286
- );
287
- });
288
-
289
- it('should claim TON airdrop', async () => {
290
- const mockTonWallet = {
291
- connected: true,
292
- account: { address: 'EQMockTonAddress' },
293
- network: { name: 'mock', chainId: 'mainnet' },
294
- connector: { name: 'mock' },
295
- sendTransaction: jest.fn()
296
- } as any;
297
-
298
- const client = new AirdropClient({
299
- projectId: 'AD_PeMV2dboWAui', // TON project
300
- endpoint: mockEndpoint
301
- });
302
-
303
- const claims = await client.getAirdropClaims({ address: 'UQANAsrLyyHoq8N4EZ-QfADXhtoSUybdSKXOknMLWLbA7rt7' });
304
-
305
- await client.claimAirdrop({
306
- claimId: claims[0].claimId!,
307
- walletClient: mockTonWallet
308
- });
309
-
310
- // Verify claim parameters don't include extraData for TON
311
- expect(mockClaim).toHaveBeenCalledWith(
312
- expect.not.objectContaining({
313
- extraData: expect.anything()
314
- }),
315
- undefined
316
- );
317
-
318
- // Verify the claim parameters have the necessary data
319
- const callArgs = mockClaim.mock.calls[0][0];
320
- expect(callArgs).toHaveProperty('claimId');
321
- expect(callArgs).toHaveProperty('value', '0.1');
322
- expect(callArgs).toHaveProperty('extraData', undefined);
323
- });
324
-
325
- it('should use custom claimHook if provided', async () => {
326
- const client = new AirdropClient({
327
- projectId: 'AD_50lczFu9Yhvq',
328
- endpoint: mockEndpoint
329
- });
330
-
331
- const customExtraData = {
332
- isLegacy: false,
333
- attestationId: BigInt(999)
334
- };
335
-
336
- client.setClaimHook(() => customExtraData);
337
-
338
- const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
339
-
340
- await client.claimAirdrop({
341
- claimId: claims[0].claimId as string,
342
- walletClient: mockWalletClient
343
- });
344
-
345
- expect(mockClaim).toHaveBeenCalledWith(
346
- expect.objectContaining({
347
- extraData: customExtraData
348
- }),
349
- undefined
350
- );
351
- });
352
-
353
- it('should handle loading callback', async () => {
354
- const client = new AirdropClient({
355
- projectId: 'AD_PeMV2dboWAui',
356
- endpoint: mockEndpoint
357
- });
358
-
359
- const claims = await client.getAirdropClaims({ address: 'UQANAsrLyyHoq8N4EZ-QfADXhtoSUybdSKXOknMLWLbA7rt7' });
360
- const onLoading = jest.fn();
361
-
362
- await client.claimAirdrop(
363
- {
364
- claimId: claims[0].claimId!,
365
- walletClient: mockWalletClient
366
- },
367
- { onLoading }
368
- );
369
-
370
- expect(mockClaim).toHaveBeenCalledWith(expect.any(Object), { onLoading });
371
- });
372
-
373
- it('should throw error for invalid claim ID', async () => {
374
- const client = new AirdropClient({
375
- projectId: 'AD_50lczFu9Yhvq',
376
- endpoint: mockEndpoint
377
- });
378
-
379
- await expect(
380
- client.claimAirdrop({
381
- claimId: 'invalid_claim_id',
382
- walletClient: mockWalletClient
383
- })
384
- ).rejects.toThrow();
385
- });
386
- });
387
- });