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

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 (163) hide show
  1. package/.github/workflows/beta.yml +28 -0
  2. package/README.md +98 -2
  3. package/dist/cjs/airdrop/AirdropClient.d.ts +46 -0
  4. package/dist/cjs/airdrop/AirdropClient.js +251 -0
  5. package/dist/cjs/airdrop/AirdropClient.js.map +1 -0
  6. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +39 -0
  7. package/dist/cjs/airdrop/SignatureAirdropClient.js +185 -0
  8. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -0
  9. package/dist/cjs/airdrop/common/index.d.ts +1 -1
  10. package/dist/cjs/airdrop/constants/index.d.ts +4 -0
  11. package/dist/cjs/airdrop/constants/index.js +5 -1
  12. package/dist/cjs/airdrop/constants/index.js.map +1 -1
  13. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
  14. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js +71 -0
  15. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  16. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
  17. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js +47 -0
  18. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  19. package/dist/cjs/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  20. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
  21. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js +71 -0
  22. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
  23. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
  24. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +38 -0
  25. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
  26. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
  27. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js +21 -0
  28. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
  29. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
  30. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +73 -0
  31. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
  32. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +10 -0
  33. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +37 -0
  34. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
  35. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
  36. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js +14 -0
  37. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
  38. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
  39. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +118 -0
  40. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
  41. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
  42. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +118 -0
  43. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
  44. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
  45. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +29 -0
  46. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
  47. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
  48. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js +30 -0
  49. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
  50. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
  51. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js +41 -0
  52. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
  53. package/dist/cjs/airdrop/index.d.ts +4 -46
  54. package/dist/cjs/airdrop/index.js +22 -241
  55. package/dist/cjs/airdrop/index.js.map +1 -1
  56. package/dist/cjs/airdrop/services/index.d.ts +33 -1
  57. package/dist/cjs/airdrop/services/index.js +46 -2
  58. package/dist/cjs/airdrop/services/index.js.map +1 -1
  59. package/dist/cjs/airdrop/types/index.d.ts +45 -4
  60. package/dist/cjs/airdrop/types/index.js +7 -1
  61. package/dist/cjs/airdrop/types/index.js.map +1 -1
  62. package/dist/cjs/index.d.ts +1 -1
  63. package/dist/cjs/index.js +7 -1
  64. package/dist/cjs/index.js.map +1 -1
  65. package/dist/cjs/utils/api-client.d.ts +1 -0
  66. package/dist/cjs/utils/api-client.js +2 -2
  67. package/dist/cjs/utils/api-client.js.map +1 -1
  68. package/dist/cjs/utils/utils.d.ts +1 -0
  69. package/dist/cjs/utils/utils.js +2 -1
  70. package/dist/cjs/utils/utils.js.map +1 -1
  71. package/dist/esm/airdrop/AirdropClient.d.ts +46 -0
  72. package/dist/esm/airdrop/AirdropClient.js +247 -0
  73. package/dist/esm/airdrop/AirdropClient.js.map +1 -0
  74. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +39 -0
  75. package/dist/esm/airdrop/SignatureAirdropClient.js +181 -0
  76. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -0
  77. package/dist/esm/airdrop/common/index.d.ts +1 -1
  78. package/dist/esm/airdrop/constants/index.d.ts +4 -0
  79. package/dist/esm/airdrop/constants/index.js +4 -0
  80. package/dist/esm/airdrop/constants/index.js.map +1 -1
  81. package/dist/esm/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
  82. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js +67 -0
  83. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  84. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
  85. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js +40 -0
  86. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  87. package/dist/esm/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  88. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
  89. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js +67 -0
  90. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
  91. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
  92. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +34 -0
  93. package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
  94. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
  95. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js +3 -0
  96. package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
  97. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
  98. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +68 -0
  99. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
  100. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +10 -0
  101. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +31 -0
  102. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
  103. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
  104. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js +5 -0
  105. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
  106. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
  107. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +108 -0
  108. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
  109. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
  110. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +113 -0
  111. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
  112. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
  113. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +24 -0
  114. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
  115. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
  116. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js +27 -0
  117. package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
  118. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
  119. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js +35 -0
  120. package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
  121. package/dist/esm/airdrop/index.d.ts +4 -46
  122. package/dist/esm/airdrop/index.js +4 -239
  123. package/dist/esm/airdrop/index.js.map +1 -1
  124. package/dist/esm/airdrop/services/index.d.ts +33 -1
  125. package/dist/esm/airdrop/services/index.js +40 -1
  126. package/dist/esm/airdrop/services/index.js.map +1 -1
  127. package/dist/esm/airdrop/types/index.d.ts +45 -4
  128. package/dist/esm/airdrop/types/index.js +6 -0
  129. package/dist/esm/airdrop/types/index.js.map +1 -1
  130. package/dist/esm/index.d.ts +1 -1
  131. package/dist/esm/index.js +1 -1
  132. package/dist/esm/index.js.map +1 -1
  133. package/dist/esm/utils/api-client.d.ts +1 -0
  134. package/dist/esm/utils/api-client.js +2 -2
  135. package/dist/esm/utils/api-client.js.map +1 -1
  136. package/dist/esm/utils/utils.d.ts +1 -0
  137. package/dist/esm/utils/utils.js +1 -0
  138. package/dist/esm/utils/utils.js.map +1 -1
  139. package/package.json +15 -3
  140. package/src/airdrop/AirdropClient.ts +307 -0
  141. package/src/airdrop/SignatureAirdropClient.ts +248 -0
  142. package/src/airdrop/constants/index.ts +5 -0
  143. package/src/airdrop/core/evm/SignatureAirdropService.ts +90 -0
  144. package/src/airdrop/core/evm/contracts/AirdropSignatureClient.ts +56 -0
  145. package/src/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  146. package/src/airdrop/core/useWeb3ConnectWallet/WalletBase.ts +92 -0
  147. package/src/airdrop/core/useWeb3ConnectWallet/WalletFactory.tsx +35 -0
  148. package/src/airdrop/core/useWeb3ConnectWallet/index.ts +3 -0
  149. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.ts +93 -0
  150. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/index.tsx +56 -0
  151. package/src/airdrop/core/useWeb3ConnectWallet/providers/index.ts +4 -0
  152. package/src/airdrop/core/useWeb3ConnectWallet/providers/solana/index.tsx +138 -0
  153. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.ts +153 -0
  154. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/index.tsx +41 -0
  155. package/src/airdrop/core/useWeb3ConnectWallet/types.ts +45 -0
  156. package/src/airdrop/core/useWeb3ConnectWallet/utils/index.ts +61 -0
  157. package/src/airdrop/index.ts +4 -304
  158. package/src/airdrop/services/index.ts +92 -3
  159. package/src/airdrop/types/index.ts +53 -6
  160. package/src/index.ts +9 -1
  161. package/src/utils/api-client.ts +3 -2
  162. package/src/utils/utils.ts +2 -0
  163. package/tsconfig.json +2 -2
@@ -1,305 +1,5 @@
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';
1
+ export { AirdropClient } from './AirdropClient';
2
+ export { SignatureAirdropClient } from './SignatureAirdropClient';
17
3
 
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
- this.projectPromise = this.initializeProjects();
36
- }
37
-
38
- setTonClient(tonClient: TonClient) {
39
- this.tonClient = tonClient;
40
- }
41
-
42
- private getTonClient(): TonClient | undefined {
43
- if (!this.tonClient) {
44
- return undefined;
45
- }
46
- return this.tonClient;
47
- }
48
-
49
- private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {
50
- if (!this.slug) return undefined;
51
-
52
- const res = await getAirdropPro(this.slug, this.endpoint);
53
- const projectMap = res?.childProjectMapping || {};
54
-
55
- return getTonProjectIdByAddress({
56
- address,
57
- slug: this.slug,
58
- data: projectMap
59
- });
60
- }
61
-
62
- private async fetchProjectDetails(projectId: string): Promise<void> {
63
- this.project = await getAirdropProject(projectId, this.endpoint);
64
- }
65
-
66
- protected async initializeProjects(address?: string) {
67
- try {
68
- let projectId = this.projectId;
69
-
70
- // If slug is provided, try to fetch project ID from slug
71
- if (!projectId) {
72
- projectId = await this.fetchProjectFromSlug(address);
73
- }
74
-
75
- if (!projectId) {
76
- return;
77
- }
78
-
79
- // Fetch project details
80
- await this.fetchProjectDetails(projectId);
81
- } catch (error: any) {
82
- throw new Error(`Failed to initialize project: ${error.message}`);
83
- }
84
- }
85
-
86
- async getProjectInfo() {
87
- await this.projectPromise;
88
- if (!this.project) throw new Error('Project not found');
89
- return this.project;
90
- }
91
-
92
- async getAirdropClaims(data: { address: string }) {
93
- if (this.slug) {
94
- await this.initializeProjects(data.address); // Fetch project details by address & slug
95
- }
96
- const project = await this.getProjectInfo();
97
-
98
- const res = await getAirdropQuery(
99
- {
100
- recipient: data.address,
101
- projectId: project!.id,
102
- recipientType: project!.recipientType
103
- },
104
- this.endpoint
105
- );
106
- const claimsRes = res.claims?.map((it) => ({
107
- ...it,
108
- project: project!,
109
- claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`
110
- }));
111
- this.claims = claimsRes;
112
- return this.claims;
113
- }
114
-
115
- public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {
116
- const project = await this.getProjectInfo();
117
- const version = this.contractConfig?.version || undefined;
118
-
119
- const hasWallet = !!walletClient;
120
-
121
- // Try to get cached strategy
122
- let strategy = strategyCache.getStrategy(
123
- project.contractAddress,
124
- project.chainId,
125
- project.chainType,
126
- hasWallet
127
- );
128
-
129
- if (!strategy) {
130
- // Create new strategy if not cached
131
- strategy = AirdropStrategyFactory.createStrategy({
132
- chainType: project.chainType,
133
- contractAddress: project.contractAddress,
134
- chainId: project.chainId,
135
- walletClient,
136
- tonClient: this.getTonClient(),
137
- version
138
- });
139
-
140
- // Initialize the strategy
141
- await strategy.initialize(walletClient);
142
-
143
- // Cache the initialized strategy
144
- strategyCache.setStrategy(
145
- project.contractAddress,
146
- project.chainId,
147
- project.chainType,
148
- strategy,
149
- hasWallet
150
- );
151
- } else if (hasWallet) {
152
- // If we have a wallet and the strategy exists, just initialize with the new wallet
153
- await strategy.initialize(walletClient);
154
- }
155
-
156
- return strategy;
157
- }
158
-
159
- private getClaimDataById(claimId: string) {
160
- const claimData = this.claims?.find((it) => it.claimId === claimId);
161
- if (!claimData) throw new Error('Claim data not found');
162
- return claimData;
163
- }
164
-
165
- setClaimHook(fn: (v: any) => any) {
166
- this.claimHook = fn;
167
- }
168
-
169
- private getDefaultExtraData() {
170
- return {
171
- isLegacy: true,
172
- attestationId: BigInt(1)
173
- };
174
- }
175
-
176
- private async calculateClaimFee(project: IProject, claimAmount: string): Promise<string | bigint | undefined> {
177
- if (project.chainType === ChainType.Evm) {
178
- const version = await this.getVersion();
179
- const isNativeFreeVersion =
180
- project.tokenType === ETokenType.Native &&
181
- [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);
182
- return isNativeFreeVersion ? undefined : await this.getClaimFee(BigInt(claimAmount));
183
- }
184
-
185
- if(project.chainType === ChainType.Ton) {
186
- return await this.getClaimFee(BigInt(claimAmount));
187
- }
188
-
189
- return undefined;
190
- }
191
-
192
- async claimAirdrop(
193
- { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
194
- options?: { onLoading?: () => void }
195
- ) {
196
- // Get claim data and initialize strategy
197
- const claimData = this.getClaimDataById(claimId);
198
- const strategy = await this.getStrategy(walletClient);
199
- const project = await this.getProjectInfo();
200
-
201
- // Process extra data
202
- const extraData = project.chainType === ChainType.Ton
203
- ? undefined
204
- : this.claimHook
205
- ? this.claimHook(claimData)
206
- : this.getDefaultExtraData();
207
-
208
- // Calculate claim value based on project type
209
- const value = await this.calculateClaimFee(project, claimData.amount);
210
-
211
- // Execute claim with processed data
212
- return strategy.claim({
213
- ...claimData,
214
- extraData,
215
- value
216
- }, options);
217
- }
218
-
219
- async checkClaimed(claimId: string): Promise<boolean> {
220
- const claimData = this.getClaimDataById(claimId);
221
- const strategy = await this.getStrategy();
222
- return strategy.checkClaimed(claimData);
223
- }
224
-
225
- private async getContractConfig(): Promise<IContractConfig | null> {
226
- try {
227
- const project = await this.getProjectInfo();
228
-
229
- if (!this.contractConfig) {
230
- this.contractConfig = await getAirdropContractConfig({
231
- chainId: project.chainId,
232
- chainType: project.chainType,
233
- contractAddress: project.contractAddress
234
- }, this.endpoint);
235
- }
236
- return this.contractConfig;
237
- } catch (error) {
238
- console.error('Error fetching contract config:', error);
239
- return null;
240
- }
241
- }
242
-
243
- async getVersion(): Promise<string> {
244
- const config = await this.getContractConfig();
245
- if (config?.version) {
246
- return config.version;
247
- }
248
-
249
- const strategy = await this.getStrategy();
250
- return strategy.getVersion();
251
- }
252
-
253
- async getPaused(): Promise<boolean> {
254
- const config = await this.getContractConfig();
255
- if (config && config?.paused !== null) {
256
- return config.paused;
257
- }
258
-
259
- const strategy = await this.getStrategy();
260
- if (!strategy.getPaused) {
261
- throw new Error('getPaused is not supported for this chain');
262
- }
263
- return strategy.getPaused();
264
- }
265
-
266
- async getClaimFee(amount?: bigint): Promise<string | bigint> {
267
- const config = await this.getContractConfig();
268
- if (config?.claimFee) {
269
- return config.claimFee;
270
- }
271
-
272
- const strategy = await this.getStrategy();
273
- if (!strategy.getClaimFee) {
274
- throw new Error('getClaimFee is not supported for this chain');
275
- }
276
- return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));
277
- }
278
-
279
- // params claimId[]
280
- async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {
281
- const strategy = await this.getStrategy();
282
- if (!strategy.batchCheckClaimed) {
283
- throw new Error('batchCheckClaimed is not supported for this chain');
284
- }
285
- const leafs = this.claims?.map((it) => it.leaf);
286
- if (!leafs) return [];
287
- return strategy.batchCheckClaimed(leafs);
288
- }
289
-
290
- async getNFT(): Promise<string> {
291
- const strategy = await this.getStrategy();
292
- if (!strategy.getNFT) {
293
- throw new Error('getNFT is not supported for this chain');
294
- }
295
- return strategy.getNFT();
296
- }
297
-
298
- async getKycThreshold(): Promise<bigint> {
299
- const strategy = await this.getStrategy();
300
- if (!strategy.getKycThreshold) {
301
- throw new Error('getKycThreshold is not supported for this chain');
302
- }
303
- return strategy.getKycThreshold();
304
- }
305
- }
4
+ export { CONST } from './constants';
5
+ export * from './core/useWeb3ConnectWallet';
@@ -1,6 +1,13 @@
1
1
  import { apiClient } from '../../utils/api-client';
2
2
  import { safeParseJSON } from '../../utils/utils';
3
- import { IAirdropData, IContractConfig, IProject } from '../types';
3
+ import {
4
+ AirdropSigIdentityTypeEnum,
5
+ IAirdropData,
6
+ IAirdropSignatureData,
7
+ IClaimSignature,
8
+ IContractConfig,
9
+ IProject
10
+ } from '../types';
4
11
 
5
12
  export { TonWalletService } from './wallet-service/ton';
6
13
 
@@ -11,7 +18,7 @@ const createApiClient = (baseURL?: string) => {
11
18
  export const getAirdropProject = async (projectId: string, baseURL?: string): Promise<IProject> => {
12
19
  const client = createApiClient(baseURL);
13
20
  const res = await client.get<any>(`/airdrop-open/projects/${projectId}`);
14
- if (!res) return res; // res为null
21
+ if (!res) return res; // res is null
15
22
  const projectConfig = res?.themeConf;
16
23
  const blockCountries = safeParseJSON(projectConfig?.blockCountries);
17
24
  return {
@@ -54,7 +61,10 @@ export const getAirdropQuery = async (
54
61
  return client.post(`/airdrop-open/query`, data);
55
62
  };
56
63
 
57
- export const getAirdropContractConfig = async (data: { chainId: string; chainType: string; contractAddress: string }, baseURL?: string): Promise<IContractConfig> => {
64
+ export const getAirdropContractConfig = async (
65
+ data: { chainId: string; chainType: string; contractAddress: string },
66
+ baseURL?: string
67
+ ): Promise<IContractConfig> => {
58
68
  const client = createApiClient(baseURL);
59
69
  return client.post(`/airdrop-open/contract/config`, data);
60
70
  };
@@ -66,3 +76,82 @@ export const getJettonInfo = async (
66
76
  const client = createApiClient(baseURL);
67
77
  return client.get(`/airdrop-open/jetton/${data.address}?isTestnet=${data.isTestnet}`);
68
78
  };
79
+
80
+ interface SidResponse {
81
+ sid: string;
82
+ }
83
+
84
+ interface TwitterConnectParams {
85
+ code: string;
86
+ projectId: string;
87
+ }
88
+
89
+ interface WalletBindParams {
90
+ projectId: string;
91
+ key: string;
92
+ signature: string;
93
+ message: string;
94
+ timestamp: number;
95
+ recipientType: string;
96
+ }
97
+
98
+ const getSidHeader = (projectId: string) => ({
99
+ sid: window.localStorage.getItem(`sid_${projectId}`) || ''
100
+ });
101
+
102
+ export const connectTwitter = async (data: TwitterConnectParams, baseURL?: string): Promise<SidResponse> => {
103
+ const client = createApiClient(baseURL);
104
+ return client.post('/airdrop-open/connect-twitter', data, {
105
+ headers: getSidHeader(data.projectId)
106
+ });
107
+ };
108
+
109
+ export const checkEligibility = async (
110
+ data: { projectId: string },
111
+ baseURL?: string
112
+ ): Promise<IAirdropSignatureData> => {
113
+ const headers = getSidHeader(data.projectId);
114
+ if (!headers.sid)
115
+ return {
116
+ claims: [],
117
+ identities: []
118
+ };
119
+ const client = createApiClient(baseURL);
120
+
121
+ return client.post('/airdrop-open/check-eligibility', data, {
122
+ headers: headers
123
+ });
124
+ };
125
+
126
+ export const bindWallet = async (data: WalletBindParams, baseURL?: string): Promise<SidResponse> => {
127
+ const client = createApiClient(baseURL);
128
+ return client.post('/airdrop-open/connect-wallet', data, {
129
+ headers: getSidHeader(data.projectId)
130
+ });
131
+ };
132
+
133
+ interface DisconnectParams {
134
+ projectId: string;
135
+ recipientType: AirdropSigIdentityTypeEnum;
136
+ recipient?: string;
137
+ }
138
+
139
+ export const disconnectRecipient = async (data: DisconnectParams, baseURL?: string): Promise<void> => {
140
+ const client = createApiClient(baseURL);
141
+ return client.post('/airdrop-open/disconnect', data, {
142
+ headers: getSidHeader(data.projectId)
143
+ });
144
+ };
145
+
146
+ export const checkGetSignatures = async (
147
+ data: {
148
+ projectId: string;
149
+ claimIds: string[];
150
+ },
151
+ baseURL?: string
152
+ ): Promise<{ signatures: IClaimSignature[] }> => {
153
+ const client = createApiClient(baseURL);
154
+ return client.post('/airdrop-open/check-get-signatures', data, {
155
+ headers: getSidHeader(data.projectId)
156
+ });
157
+ };
@@ -1,7 +1,6 @@
1
1
  import { TonConnectUI } from '@tonconnect/ui-react';
2
2
  import { AirdropService as TonAirdropService } from '../core/ton/AirdropService';
3
3
  import { AirdropService as EvmAirdropService } from '../core/evm/AirdropService';
4
- import { TonClient } from '@ton/ton';
5
4
  import { ChainConfig } from '../constants';
6
5
  import { WalletClient as ViemWalletClient } from 'viem';
7
6
 
@@ -61,10 +60,28 @@ export interface IProject {
61
60
  blockCountries: Record<string, string>;
62
61
  themeConf: ThemeConfig | null;
63
62
  version: string;
64
- extra?: {
65
- kyc: boolean;
66
- tag: string;
67
- };
63
+ extra?: IProjectExtra;
64
+ identities: Identity[];
65
+ projectTag: string;
66
+ }
67
+
68
+ export interface Identity {
69
+ identityType: string;
70
+ authorizeUrl?: string;
71
+ }
72
+
73
+ export enum AirdropSigIdentityTypeEnum {
74
+ Twitter = 'X Account',
75
+ SolanaWallet = 'Solana Wallet',
76
+ EVMWallet = 'EVM Wallet'
77
+ }
78
+
79
+ export interface IProjectExtra {
80
+ kyc: boolean;
81
+ tag: string;
82
+ seed: number;
83
+ signer: string;
84
+ identities: string[];
68
85
  }
69
86
 
70
87
  export enum ETokenType {
@@ -96,10 +113,39 @@ export type IAirdropClaim = {
96
113
  project: IProject;
97
114
  };
98
115
 
116
+ export type IAirdropSignatureClaim = {
117
+ percent: number;
118
+ unlockingAt: number;
119
+ claimDeadline: number;
120
+ value: string;
121
+ recipient: string;
122
+ recipientType: string;
123
+ claimId: string;
124
+ data?: string;
125
+ signature?: string;
126
+ claimed?: boolean;
127
+ };
128
+
129
+ export interface IAirdropSignatureIdentity {
130
+ type: AirdropSigIdentityTypeEnum;
131
+ value: string;
132
+ }
133
+
99
134
  export interface IAirdropData {
100
135
  claims: IAirdropClaim[];
101
136
  }
102
137
 
138
+ export interface IAirdropSignatureData {
139
+ claims: IAirdropSignatureClaim[];
140
+ identities: IAirdropSignatureIdentity[];
141
+ }
142
+
143
+ export interface IClaimSignature {
144
+ claimId: string;
145
+ data: string;
146
+ signature: string;
147
+ }
148
+
103
149
  export enum TonAirdropVersionEnum {
104
150
  V1 = '1.0.0',
105
151
  V2 = '2.0.0',
@@ -119,6 +165,7 @@ export type IAirdropService = TonAirdropService | EvmAirdropService;
119
165
 
120
166
  type BaseAirdropOptions = {
121
167
  endpoint?: string;
168
+ project?: IProject;
122
169
  };
123
170
 
124
171
  type ProjectIdOptions = BaseAirdropOptions & {
@@ -137,4 +184,4 @@ export interface IContractConfig {
137
184
  version?: string | null;
138
185
  paused: boolean | null;
139
186
  claimFee?: string | null;
140
- }
187
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,10 @@
1
- export { AirdropClient } from './airdrop';
1
+ export {
2
+ AirdropClient,
3
+ SignatureAirdropClient,
4
+ CONST,
5
+ WalletFactory,
6
+ EvmProvider,
7
+ SolanaProvider,
8
+ TonProvider
9
+ } from './airdrop';
2
10
  export * from './airdrop/types';
@@ -5,6 +5,7 @@ export type ApiClientOptions = {
5
5
  export type ApiRequestOptions = {
6
6
  params?: Record<string, string | number>;
7
7
  skipHandleError?: boolean;
8
+ headers?: Record<string, string>;
8
9
  };
9
10
 
10
11
  type ApiResponse = {
@@ -48,11 +49,11 @@ export class ApiClient {
48
49
  ): Promise<unknown> {
49
50
  const finalUrl = (this.options?.baseURL || '') + url;
50
51
 
51
- const init: RequestInit = { method };
52
+ const init: RequestInit = { method, headers: options?.headers || {} };
52
53
  if (data instanceof FormData) {
53
54
  init.body = data;
54
55
  } else {
55
- init.headers = { 'content-type': 'application/json' };
56
+ init.headers = { 'content-type': 'application/json', ...init.headers };
56
57
  init.body = data ? JSON.stringify(data) : void 0;
57
58
  }
58
59
 
@@ -28,3 +28,5 @@ export async function retry<T>(fn: () => Promise<T>, options: { retries: number;
28
28
  }
29
29
  throw lastError;
30
30
  }
31
+
32
+ export const isLocal = window.location.href.includes('localhost');
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  // Enable latest features
4
- "lib": ["ESNext"],
4
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
5
5
  "target": "ESNext",
6
6
  "module": "ESNext",
7
7
 
@@ -14,7 +14,7 @@
14
14
  "moduleResolution": "node",
15
15
  "esModuleInterop": true,
16
16
  "resolveJsonModule": true,
17
-
17
+ "jsx": "react-jsx",
18
18
  // Best practices
19
19
  "strict": true,
20
20
  "skipLibCheck": true,