@sign-global/tokentable 0.3.0 → 0.4.0-beta.2

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 (148) hide show
  1. package/.github/workflows/beta.yml +28 -0
  2. package/dist/cjs/airdrop/AirdropClient.d.ts +46 -0
  3. package/dist/cjs/airdrop/AirdropClient.js +251 -0
  4. package/dist/cjs/airdrop/AirdropClient.js.map +1 -0
  5. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +24 -0
  6. package/dist/cjs/airdrop/SignatureAirdropClient.js +109 -0
  7. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -0
  8. package/dist/cjs/airdrop/common/index.d.ts +1 -1
  9. package/dist/cjs/airdrop/constants/index.d.ts +4 -0
  10. package/dist/cjs/airdrop/constants/index.js +5 -1
  11. package/dist/cjs/airdrop/constants/index.js.map +1 -1
  12. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +15 -0
  13. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js +51 -0
  14. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  15. package/dist/cjs/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  16. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
  17. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js +71 -0
  18. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
  19. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
  20. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +38 -0
  21. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
  22. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
  23. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js +21 -0
  24. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
  25. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
  26. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +70 -0
  27. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
  28. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +9 -0
  29. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +35 -0
  30. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
  31. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
  32. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js +14 -0
  33. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
  34. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
  35. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +119 -0
  36. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
  37. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
  38. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +117 -0
  39. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
  40. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
  41. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +29 -0
  42. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
  43. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
  44. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js +30 -0
  45. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
  46. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
  47. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js +41 -0
  48. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
  49. package/dist/cjs/airdrop/index.d.ts +4 -46
  50. package/dist/cjs/airdrop/index.js +22 -241
  51. package/dist/cjs/airdrop/index.js.map +1 -1
  52. package/dist/cjs/airdrop/services/index.d.ts +15 -0
  53. package/dist/cjs/airdrop/services/index.js +16 -1
  54. package/dist/cjs/airdrop/services/index.js.map +1 -1
  55. package/dist/cjs/airdrop/types/index.d.ts +19 -4
  56. package/dist/cjs/airdrop/types/index.js +7 -1
  57. package/dist/cjs/airdrop/types/index.js.map +1 -1
  58. package/dist/cjs/index.d.ts +1 -1
  59. package/dist/cjs/index.js +7 -1
  60. package/dist/cjs/index.js.map +1 -1
  61. package/dist/cjs/utils/utils.d.ts +1 -0
  62. package/dist/cjs/utils/utils.js +2 -1
  63. package/dist/cjs/utils/utils.js.map +1 -1
  64. package/dist/esm/airdrop/AirdropClient.d.ts +46 -0
  65. package/dist/esm/airdrop/AirdropClient.js +247 -0
  66. package/dist/esm/airdrop/AirdropClient.js.map +1 -0
  67. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +24 -0
  68. package/dist/esm/airdrop/SignatureAirdropClient.js +105 -0
  69. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -0
  70. package/dist/esm/airdrop/common/index.d.ts +1 -1
  71. package/dist/esm/airdrop/constants/index.d.ts +4 -0
  72. package/dist/esm/airdrop/constants/index.js +4 -0
  73. package/dist/esm/airdrop/constants/index.js.map +1 -1
  74. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +15 -0
  75. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js +44 -0
  76. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  77. package/dist/esm/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  78. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
  79. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js +67 -0
  80. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
  81. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
  82. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +34 -0
  83. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
  84. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
  85. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js +3 -0
  86. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
  87. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
  88. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +65 -0
  89. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
  90. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +9 -0
  91. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +29 -0
  92. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
  93. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
  94. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js +5 -0
  95. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
  96. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
  97. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +109 -0
  98. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
  99. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
  100. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +112 -0
  101. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
  102. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
  103. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +24 -0
  104. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
  105. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
  106. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js +27 -0
  107. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
  108. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
  109. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js +35 -0
  110. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
  111. package/dist/esm/airdrop/index.d.ts +4 -46
  112. package/dist/esm/airdrop/index.js +4 -239
  113. package/dist/esm/airdrop/index.js.map +1 -1
  114. package/dist/esm/airdrop/services/index.d.ts +15 -0
  115. package/dist/esm/airdrop/services/index.js +12 -0
  116. package/dist/esm/airdrop/services/index.js.map +1 -1
  117. package/dist/esm/airdrop/types/index.d.ts +19 -4
  118. package/dist/esm/airdrop/types/index.js +6 -0
  119. package/dist/esm/airdrop/types/index.js.map +1 -1
  120. package/dist/esm/index.d.ts +1 -1
  121. package/dist/esm/index.js +1 -1
  122. package/dist/esm/index.js.map +1 -1
  123. package/dist/esm/utils/utils.d.ts +1 -0
  124. package/dist/esm/utils/utils.js +1 -0
  125. package/dist/esm/utils/utils.js.map +1 -1
  126. package/package.json +15 -3
  127. package/src/airdrop/AirdropClient.ts +307 -0
  128. package/src/airdrop/SignatureAirdropClient.ts +120 -0
  129. package/src/airdrop/constants/index.ts +5 -0
  130. package/src/airdrop/core/evm/contracts/AirdropSignatureClient.ts +59 -0
  131. package/src/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  132. package/src/airdrop/core/useWeb3ConnectWallet/WalletBase.ts +92 -0
  133. package/src/airdrop/core/useWeb3ConnectWallet/WalletFactory.tsx +35 -0
  134. package/src/airdrop/core/useWeb3ConnectWallet/index.ts +3 -0
  135. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.ts +90 -0
  136. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/index.tsx +43 -0
  137. package/src/airdrop/core/useWeb3ConnectWallet/providers/index.ts +4 -0
  138. package/src/airdrop/core/useWeb3ConnectWallet/providers/solana/index.tsx +141 -0
  139. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.ts +149 -0
  140. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/index.tsx +41 -0
  141. package/src/airdrop/core/useWeb3ConnectWallet/types.ts +45 -0
  142. package/src/airdrop/core/useWeb3ConnectWallet/utils/index.ts +61 -0
  143. package/src/airdrop/index.ts +4 -304
  144. package/src/airdrop/services/index.ts +29 -1
  145. package/src/airdrop/types/index.ts +23 -5
  146. package/src/index.ts +9 -1
  147. package/src/utils/utils.ts +2 -0
  148. package/tsconfig.json +2 -2
@@ -0,0 +1,307 @@
1
+ import { TonClient } from '@ton/ton';
2
+ import { getAirdropPro, getAirdropProject, getAirdropQuery, getAirdropContractConfig } from './services';
3
+ import {
4
+ ChainType,
5
+ ETokenType,
6
+ EvmAirdropVersionEnum,
7
+ IAirdropClaim,
8
+ IAirdropOptions,
9
+ IContractConfig,
10
+ IProject,
11
+ IWalletClient
12
+ } from './types';
13
+ import { getTonProjectIdByAddress } from './common';
14
+ import { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';
15
+ import { IAirdropStrategy } from './strategies/IAirdropStrategy';
16
+ import { strategyCache } from './strategies/StrategyCache';
17
+
18
+ export class AirdropClient {
19
+ private tonClient?: TonClient;
20
+ private slug?: string;
21
+ private projectId?: string;
22
+ private endpoint?: string;
23
+ private project: IProject | undefined;
24
+ protected claims?: IAirdropClaim[];
25
+ private projectPromise: Promise<void> | undefined;
26
+ private claimHook: ((v: any) => any) | undefined;
27
+ private contractConfig: IContractConfig | null = null;
28
+
29
+ constructor(params: IAirdropOptions) {
30
+ if ('slug' in params) {
31
+ this.slug = params.slug;
32
+ }
33
+ this.projectId = params.projectId;
34
+ this.endpoint = params.endpoint;
35
+ if (this.project) {
36
+ this.project = params.project;
37
+ } else {
38
+ this.projectPromise = this.initializeProjects();
39
+ }
40
+ }
41
+
42
+ setTonClient(tonClient: TonClient) {
43
+ this.tonClient = tonClient;
44
+ }
45
+
46
+ private getTonClient(): TonClient | undefined {
47
+ if (!this.tonClient) {
48
+ return undefined;
49
+ }
50
+ return this.tonClient;
51
+ }
52
+
53
+ private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {
54
+ if (!this.slug) return undefined;
55
+
56
+ const res = await getAirdropPro(this.slug, this.endpoint);
57
+ const projectMap = res?.childProjectMapping || {};
58
+
59
+ return getTonProjectIdByAddress({
60
+ address,
61
+ slug: this.slug,
62
+ data: projectMap
63
+ });
64
+ }
65
+
66
+ private async fetchProjectDetails(projectId: string): Promise<void> {
67
+ this.project = await getAirdropProject(projectId, this.endpoint);
68
+ }
69
+
70
+ protected async initializeProjects(address?: string) {
71
+ try {
72
+ let projectId = this.projectId;
73
+
74
+ // If slug is provided, try to fetch project ID from slug
75
+ if (!projectId) {
76
+ projectId = await this.fetchProjectFromSlug(address);
77
+ }
78
+
79
+ if (!projectId) {
80
+ return;
81
+ }
82
+
83
+ // Fetch project details
84
+ await this.fetchProjectDetails(projectId);
85
+ } catch (error: any) {
86
+ throw new Error(`Failed to initialize project: ${error.message}`);
87
+ }
88
+ }
89
+
90
+ async getProjectInfo() {
91
+ if (this.projectPromise) {
92
+ await this.projectPromise;
93
+ }
94
+ if (!this.project) throw new Error('Project not found');
95
+ return this.project;
96
+ }
97
+
98
+ async getAirdropClaims(data: { address: string }) {
99
+ if (this.slug) {
100
+ await this.initializeProjects(data.address); // Fetch project details by address & slug
101
+ }
102
+ const project = await this.getProjectInfo();
103
+
104
+ const res = await getAirdropQuery(
105
+ {
106
+ recipient: data.address,
107
+ projectId: project!.id,
108
+ recipientType: project!.recipientType
109
+ },
110
+ this.endpoint
111
+ );
112
+ const claimsRes = res.claims?.map((it) => ({
113
+ ...it,
114
+ project: project!,
115
+ claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`
116
+ }));
117
+ this.claims = claimsRes;
118
+ return this.claims;
119
+ }
120
+
121
+ public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {
122
+ const project = await this.getProjectInfo();
123
+ const version = this.contractConfig?.version || undefined;
124
+
125
+ const hasWallet = !!walletClient;
126
+
127
+ // Try to get cached strategy
128
+ let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);
129
+
130
+ if (!strategy) {
131
+ // Create new strategy if not cached
132
+ strategy = AirdropStrategyFactory.createStrategy({
133
+ chainType: project.chainType,
134
+ contractAddress: project.contractAddress,
135
+ chainId: project.chainId,
136
+ walletClient,
137
+ tonClient: this.getTonClient(),
138
+ version
139
+ });
140
+
141
+ // Initialize the strategy
142
+ await strategy.initialize(walletClient);
143
+
144
+ // Cache the initialized strategy
145
+ strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);
146
+ } else if (hasWallet) {
147
+ // If we have a wallet and the strategy exists, just initialize with the new wallet
148
+ await strategy.initialize(walletClient);
149
+ }
150
+
151
+ return strategy;
152
+ }
153
+
154
+ private getClaimDataById(claimId: string) {
155
+ const claimData = this.claims?.find((it) => it.claimId === claimId);
156
+ if (!claimData) throw new Error('Claim data not found');
157
+ return claimData;
158
+ }
159
+
160
+ setClaimHook(fn: (v: any) => any) {
161
+ this.claimHook = fn;
162
+ }
163
+
164
+ private getDefaultExtraData() {
165
+ return {
166
+ isLegacy: true,
167
+ attestationId: BigInt(1)
168
+ };
169
+ }
170
+
171
+ private async calculateClaimFee(project: IProject, claimAmount: string): Promise<string | bigint | undefined> {
172
+ if (project.chainType === ChainType.Evm) {
173
+ const version = await this.getVersion();
174
+ const isNativeFreeVersion =
175
+ project.tokenType === ETokenType.Native &&
176
+ [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);
177
+ return isNativeFreeVersion ? undefined : await this.getClaimFee(BigInt(claimAmount));
178
+ }
179
+
180
+ if (project.chainType === ChainType.Ton) {
181
+ return await this.getClaimFee(BigInt(claimAmount));
182
+ }
183
+
184
+ return undefined;
185
+ }
186
+
187
+ async claimAirdrop(
188
+ { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
189
+ options?: { onLoading?: () => void }
190
+ ) {
191
+ // Get claim data and initialize strategy
192
+ const claimData = this.getClaimDataById(claimId);
193
+ const strategy = await this.getStrategy(walletClient);
194
+ const project = await this.getProjectInfo();
195
+
196
+ // Process extra data
197
+ const extraData =
198
+ project.chainType === ChainType.Ton
199
+ ? undefined
200
+ : this.claimHook
201
+ ? this.claimHook(claimData)
202
+ : this.getDefaultExtraData();
203
+
204
+ // Calculate claim value based on project type
205
+ const value = await this.calculateClaimFee(project, claimData.amount);
206
+
207
+ // Execute claim with processed data
208
+ return strategy.claim(
209
+ {
210
+ ...claimData,
211
+ extraData,
212
+ value
213
+ },
214
+ options
215
+ );
216
+ }
217
+
218
+ async checkClaimed(claimId: string): Promise<boolean> {
219
+ const claimData = this.getClaimDataById(claimId);
220
+ const strategy = await this.getStrategy();
221
+ return strategy.checkClaimed(claimData);
222
+ }
223
+
224
+ private async getContractConfig(): Promise<IContractConfig | null> {
225
+ try {
226
+ const project = await this.getProjectInfo();
227
+
228
+ if (!this.contractConfig) {
229
+ this.contractConfig = await getAirdropContractConfig(
230
+ {
231
+ chainId: project.chainId,
232
+ chainType: project.chainType,
233
+ contractAddress: project.contractAddress
234
+ },
235
+ this.endpoint
236
+ );
237
+ }
238
+ return this.contractConfig;
239
+ } catch (error) {
240
+ console.error('Error fetching contract config:', error);
241
+ return null;
242
+ }
243
+ }
244
+
245
+ async getVersion(): Promise<string> {
246
+ const config = await this.getContractConfig();
247
+ if (config?.version) {
248
+ return config.version;
249
+ }
250
+
251
+ const strategy = await this.getStrategy();
252
+ return strategy.getVersion();
253
+ }
254
+
255
+ async getPaused(): Promise<boolean> {
256
+ const config = await this.getContractConfig();
257
+ if (config && config?.paused !== null) {
258
+ return config.paused;
259
+ }
260
+
261
+ const strategy = await this.getStrategy();
262
+ if (!strategy.getPaused) {
263
+ throw new Error('getPaused is not supported for this chain');
264
+ }
265
+ return strategy.getPaused();
266
+ }
267
+
268
+ async getClaimFee(amount?: bigint): Promise<string | bigint> {
269
+ const config = await this.getContractConfig();
270
+ if (config?.claimFee) {
271
+ return config.claimFee;
272
+ }
273
+
274
+ const strategy = await this.getStrategy();
275
+ if (!strategy.getClaimFee) {
276
+ throw new Error('getClaimFee is not supported for this chain');
277
+ }
278
+ return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));
279
+ }
280
+
281
+ // params claimId[]
282
+ async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {
283
+ const strategy = await this.getStrategy();
284
+ if (!strategy.batchCheckClaimed) {
285
+ throw new Error('batchCheckClaimed is not supported for this chain');
286
+ }
287
+ const leafs = this.claims?.map((it) => it.leaf);
288
+ if (!leafs) return [];
289
+ return strategy.batchCheckClaimed(leafs);
290
+ }
291
+
292
+ async getNFT(): Promise<string> {
293
+ const strategy = await this.getStrategy();
294
+ if (!strategy.getNFT) {
295
+ throw new Error('getNFT is not supported for this chain');
296
+ }
297
+ return strategy.getNFT();
298
+ }
299
+
300
+ async getKycThreshold(): Promise<bigint> {
301
+ const strategy = await this.getStrategy();
302
+ if (!strategy.getKycThreshold) {
303
+ throw new Error('getKycThreshold is not supported for this chain');
304
+ }
305
+ return strategy.getKycThreshold();
306
+ }
307
+ }
@@ -0,0 +1,120 @@
1
+ import { CONST } from './constants';
2
+ import { WalletFactory } from './core/useWeb3ConnectWallet';
3
+ import { ChainType } from './core/useWeb3ConnectWallet/types';
4
+ import { bindWallet, connectTwitter, getAirdropProject } from './services';
5
+ import { AirdropSigIdentityTypeEnum, IAirdropOptions, IProject } from './types';
6
+
7
+ export class SignatureAirdropClient {
8
+ private slug?: string;
9
+ private projectId?: string;
10
+ private endpoint?: string;
11
+ private project: IProject | undefined;
12
+ protected claims?: any[];
13
+ private projectPromise: Promise<void> | undefined;
14
+ private claimHook: ((v: any) => any) | undefined;
15
+ // private contractConfig: IContractConfig | null = null;
16
+ constructor(params: IAirdropOptions) {
17
+ if ('slug' in params) {
18
+ this.slug = params.slug;
19
+ }
20
+ this.projectId = params.projectId;
21
+ this.endpoint = params.endpoint;
22
+ if (this.project) {
23
+ this.project = params.project;
24
+ } else {
25
+ this.projectPromise = this.initializeProjects();
26
+ }
27
+ }
28
+
29
+ private async fetchProjectDetails(projectId: string): Promise<void> {
30
+ this.project = await getAirdropProject(projectId, this.endpoint);
31
+ }
32
+
33
+ protected async initializeProjects() {
34
+ try {
35
+ let projectId = this.projectId;
36
+
37
+ if (!projectId) {
38
+ return;
39
+ }
40
+
41
+ await this.fetchProjectDetails(projectId);
42
+ } catch (error: any) {
43
+ throw new Error(`Failed to initialize project: ${error.message}`);
44
+ }
45
+ }
46
+
47
+ async getProjectInfo() {
48
+ if (this.projectPromise) {
49
+ await this.projectPromise;
50
+ }
51
+ if (!this.project) throw new Error('Project not found');
52
+ return this.project;
53
+ }
54
+
55
+ async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: () => void }) {
56
+ const project = await this.getProjectInfo();
57
+ const onWindowMessage = async (message: any) => {
58
+ if (message.data.name && message.data.name === CONST.TWITTER_AUTH_SUCCESS) {
59
+ const { isError, code, redirectUri } = message.data.data || {};
60
+ try {
61
+ await connectTwitter({ code, redirectUri: redirectUri }, this.endpoint);
62
+ onSuccess();
63
+ if (isError) {
64
+ onError();
65
+ }
66
+ } catch (error) {
67
+ onError();
68
+ } finally {
69
+ window.removeEventListener('message', onWindowMessage);
70
+ }
71
+ }
72
+ };
73
+
74
+ window.addEventListener('message', onWindowMessage);
75
+ const authorizeUrl = project.identities.find(
76
+ (item: any) => item.identityType === AirdropSigIdentityTypeEnum.Twitter
77
+ )?.authorizeUrl;
78
+ window.open(authorizeUrl + '&state=state', '_blank', 'width=600,height=800');
79
+ }
80
+
81
+ async connectWallet({
82
+ chainType,
83
+ onSuccess,
84
+ onError
85
+ }: {
86
+ chainType: ChainType;
87
+ onSuccess: () => void;
88
+ onError: (error: any) => void;
89
+ }) {
90
+ try {
91
+ const project = await this.getProjectInfo();
92
+ const wallet = WalletFactory.getWallet(chainType);
93
+ const signResult = await wallet.signin(CONST.WELCOME_SIGNATURE_STATEMENT);
94
+
95
+ const { message, signature } = signResult || {};
96
+
97
+ const recipientTypeMap = {
98
+ [ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,
99
+ [ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,
100
+ [ChainType.Ton]: ''
101
+ };
102
+
103
+ const payload = {
104
+ signature: signature as string,
105
+ message: message as string,
106
+ key: wallet.publicKey || wallet.address!,
107
+ projectId: project.id,
108
+ timestamp: Date.now(),
109
+ recipientType: recipientTypeMap[chainType]
110
+ };
111
+
112
+ await bindWallet(payload, this.endpoint);
113
+ onSuccess();
114
+ } catch (error) {
115
+ onError(error);
116
+ } finally {
117
+ onSuccess();
118
+ }
119
+ }
120
+ }
@@ -1,3 +1,8 @@
1
1
  export * from './chain-config';
2
2
 
3
3
  export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
4
+
5
+ export const CONST = {
6
+ TWITTER_AUTH_SUCCESS: 'twitter:auth:success',
7
+ WELCOME_SIGNATURE_STATEMENT: 'Welcome to TokenTable!'
8
+ } as const;
@@ -0,0 +1,59 @@
1
+ import { EvmContractClientOption } from '../../../types';
2
+ import ABI from './abis/FungibleTokenECDSADistributor.json';
3
+ import { ContractBaseClient } from './ContractBaseClient';
4
+
5
+ export class AirdropSignatureClient extends ContractBaseClient {
6
+ constructor(options: EvmContractClientOption) {
7
+ super({
8
+ ...options,
9
+ abi: ABI
10
+ });
11
+ }
12
+
13
+ async getClaimStatus(userClaimId: string) {
14
+ return this.readContract({ functionName: 'getClaimStatus', args: [userClaimId] });
15
+ }
16
+
17
+ async claim(
18
+ data: {
19
+ recipient: string;
20
+ group: string;
21
+ data: string;
22
+ signature: string;
23
+ extraData: string;
24
+ }[],
25
+ value?: bigint
26
+ ) {
27
+ const [recipients = [], userClaimIds = [], datas = [], signatures = [], extraDatas = []] = [
28
+ 'recipient',
29
+ 'claimId',
30
+ 'data',
31
+ 'signature',
32
+ 'extraData'
33
+ ].map((key) => data.map((item) => item[key as keyof (typeof data)[0]] || ''));
34
+
35
+ return this.writeContract({
36
+ functionName: 'claim',
37
+ args: [recipients, userClaimIds, datas, signatures, extraDatas],
38
+ value: value || 0n
39
+ });
40
+ }
41
+
42
+ async batchFetchClaimed(userClaimIds: string[]) {
43
+ // return this.multiCall({
44
+ // chainId: this.chainId as any,
45
+ // contracts: userClaimIds?.map((userClaimId) => {
46
+ // return {
47
+ // address: this.contractAddress,
48
+ // abi: this.abi,
49
+ // functionName: 'getClaimStatus',
50
+ // args: [userClaimId]
51
+ // };
52
+ // })
53
+ // });
54
+ }
55
+
56
+ async getDeployer() {
57
+ return this.readContract({ functionName: 'getDeployer' }) as Promise<string>;
58
+ }
59
+ }