@sign-global/tokentable 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -55
- package/dist/cjs/airdrop/common/index.d.ts +1 -1
- package/dist/cjs/airdrop/common/index.js +4 -0
- package/dist/cjs/airdrop/common/index.js.map +1 -1
- package/dist/cjs/airdrop/core/evm/AirdropService.d.ts +1 -1
- package/dist/cjs/airdrop/core/evm/AirdropService.js +3 -4
- package/dist/cjs/airdrop/core/evm/AirdropService.js.map +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropService.d.ts +1 -0
- package/dist/cjs/airdrop/core/ton/AirdropService.js +5 -0
- package/dist/cjs/airdrop/core/ton/AirdropService.js.map +1 -1
- package/dist/cjs/airdrop/index.d.ts +42 -3
- package/dist/cjs/airdrop/index.js +188 -20
- package/dist/cjs/airdrop/index.js.map +1 -1
- package/dist/cjs/airdrop/types/index.d.ts +35 -24
- package/dist/cjs/airdrop/types/index.js +7 -1
- package/dist/cjs/airdrop/types/index.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +17 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/airdrop/common/index.d.ts +1 -1
- package/dist/esm/airdrop/common/index.js +4 -0
- package/dist/esm/airdrop/common/index.js.map +1 -1
- package/dist/esm/airdrop/core/evm/AirdropService.d.ts +1 -1
- package/dist/esm/airdrop/core/evm/AirdropService.js +3 -4
- package/dist/esm/airdrop/core/evm/AirdropService.js.map +1 -1
- package/dist/esm/airdrop/core/ton/AirdropService.d.ts +1 -0
- package/dist/esm/airdrop/core/ton/AirdropService.js +5 -0
- package/dist/esm/airdrop/core/ton/AirdropService.js.map +1 -1
- package/dist/esm/airdrop/index.d.ts +42 -3
- package/dist/esm/airdrop/index.js +186 -3
- package/dist/esm/airdrop/index.js.map +1 -1
- package/dist/esm/airdrop/types/index.d.ts +35 -24
- package/dist/esm/airdrop/types/index.js +6 -0
- package/dist/esm/airdrop/types/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/jest.config.cjs +5 -0
- package/package.json +6 -2
- package/src/airdrop/common/index.ts +6 -1
- package/src/airdrop/core/evm/AirdropService.ts +3 -4
- package/src/airdrop/core/ton/AirdropService.ts +6 -0
- package/src/airdrop/index.ts +243 -3
- package/src/airdrop/tests/index.test.ts +95 -0
- package/src/airdrop/types/index.ts +39 -33
- package/src/index.ts +2 -1
- package/dist/cjs/airdrop/BaseAirdropClient.d.ts +0 -28
- package/dist/cjs/airdrop/BaseAirdropClient.js +0 -50
- package/dist/cjs/airdrop/BaseAirdropClient.js.map +0 -1
- package/dist/cjs/airdrop/EvmAirdropClient.d.ts +0 -19
- package/dist/cjs/airdrop/EvmAirdropClient.js +0 -65
- package/dist/cjs/airdrop/EvmAirdropClient.js.map +0 -1
- package/dist/cjs/airdrop/TonAirdropClient.d.ts +0 -24
- package/dist/cjs/airdrop/TonAirdropClient.js +0 -78
- package/dist/cjs/airdrop/TonAirdropClient.js.map +0 -1
- package/dist/esm/airdrop/BaseAirdropClient.d.ts +0 -28
- package/dist/esm/airdrop/BaseAirdropClient.js +0 -46
- package/dist/esm/airdrop/BaseAirdropClient.js.map +0 -1
- package/dist/esm/airdrop/EvmAirdropClient.d.ts +0 -19
- package/dist/esm/airdrop/EvmAirdropClient.js +0 -61
- package/dist/esm/airdrop/EvmAirdropClient.js.map +0 -1
- package/dist/esm/airdrop/TonAirdropClient.d.ts +0 -24
- package/dist/esm/airdrop/TonAirdropClient.js +0 -74
- package/dist/esm/airdrop/TonAirdropClient.js.map +0 -1
- package/index.ts +0 -34
- package/src/airdrop/BaseAirdropClient.ts +0 -75
- package/src/airdrop/EvmAirdropClient.ts +0 -74
- package/src/airdrop/TonAirdropClient.ts +0 -93
|
@@ -118,4 +118,10 @@ export class AirdropService {
|
|
|
118
118
|
claimFeeReceiver: feeInfo.claimFeeReceiver.toString({ bounceable: false })
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
async getClaimFee(address: string, amount: bigint) {
|
|
123
|
+
const client = await this.getClient();
|
|
124
|
+
const feeInfo = await client.getFeeInfo();
|
|
125
|
+
return fromNano(feeInfo.claimFee);
|
|
126
|
+
}
|
|
121
127
|
}
|
package/src/airdrop/index.ts
CHANGED
|
@@ -1,3 +1,243 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
import { TonConnectUI } from '@tonconnect/ui-react';
|
|
3
|
+
import { AirdropService as TonAirdropService } from './core/ton/AirdropService';
|
|
4
|
+
import { AirdropService as EvmAirdropService } from './core/evm/AirdropService';
|
|
5
|
+
import { getAirdropPro, getAirdropProject, getAirdropQuery } from './services';
|
|
6
|
+
import {
|
|
7
|
+
ChainId,
|
|
8
|
+
ChainType,
|
|
9
|
+
ETokenType,
|
|
10
|
+
EvmAirdropVersionEnum,
|
|
11
|
+
IAirdropClaim,
|
|
12
|
+
IAirdropOptions,
|
|
13
|
+
IProject,
|
|
14
|
+
IWalletClient
|
|
15
|
+
} from './types';
|
|
16
|
+
import { getTonProjectIdByAddress } from './common';
|
|
17
|
+
import { WalletClient as ViemWalletClient } from 'viem';
|
|
18
|
+
|
|
19
|
+
export class AirdropClient {
|
|
20
|
+
private tonClient?: TonClient;
|
|
21
|
+
private slug?: string;
|
|
22
|
+
private projectId?: string;
|
|
23
|
+
private endpoint?: string;
|
|
24
|
+
private project: IProject | undefined;
|
|
25
|
+
protected claims?: IAirdropClaim[];
|
|
26
|
+
private contractInstanceWithWallet: TonAirdropService | EvmAirdropService | undefined;
|
|
27
|
+
private contractInstanceWithoutWallet: TonAirdropService | EvmAirdropService | undefined;
|
|
28
|
+
private projectPromise: Promise<void> | undefined;
|
|
29
|
+
private claimHook: ((v: any) => any) | undefined;
|
|
30
|
+
private cachedVersion: string | null = null;
|
|
31
|
+
|
|
32
|
+
constructor(params: IAirdropOptions) {
|
|
33
|
+
if ('slug' in params) {
|
|
34
|
+
this.slug = params.slug;
|
|
35
|
+
}
|
|
36
|
+
this.tonClient = params.tonClient;
|
|
37
|
+
this.projectId = params.projectId;
|
|
38
|
+
this.endpoint = params.endpoint;
|
|
39
|
+
this.projectPromise = this.initializeProjects();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected async initializeProjects(address?: string) {
|
|
43
|
+
let projectId: string | undefined = this.projectId;
|
|
44
|
+
if (this.slug) {
|
|
45
|
+
const res = await getAirdropPro(this.slug, this.endpoint);
|
|
46
|
+
const projectMap = res?.childProjectMapping || {};
|
|
47
|
+
|
|
48
|
+
let legacyProjectId: string | undefined;
|
|
49
|
+
legacyProjectId = getTonProjectIdByAddress({ address, slug: this.slug, data: projectMap });
|
|
50
|
+
|
|
51
|
+
if (legacyProjectId) {
|
|
52
|
+
projectId = legacyProjectId;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!projectId) throw new Error('Project ID is required');
|
|
56
|
+
this.project = await getAirdropProject(projectId, this.endpoint);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getProjectInfo() {
|
|
60
|
+
await this.projectPromise;
|
|
61
|
+
if (!this.project) throw new Error('Project not found');
|
|
62
|
+
return this.project;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getAirdropClaims(data: { address: string }) {
|
|
66
|
+
const project = await this.getProjectInfo();
|
|
67
|
+
|
|
68
|
+
const res = await getAirdropQuery(
|
|
69
|
+
{
|
|
70
|
+
recipient: data.address,
|
|
71
|
+
projectId: project!.id,
|
|
72
|
+
recipientType: project!.recipientType
|
|
73
|
+
},
|
|
74
|
+
this.endpoint
|
|
75
|
+
);
|
|
76
|
+
const claimsRes = res.claims?.map((it) => ({
|
|
77
|
+
...it,
|
|
78
|
+
project: project!,
|
|
79
|
+
claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`
|
|
80
|
+
}));
|
|
81
|
+
this.claims = claimsRes;
|
|
82
|
+
return this.claims;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async getAirdropContractWrapper(options?: {
|
|
86
|
+
walletClient?: IWalletClient;
|
|
87
|
+
}): Promise<TonAirdropService | EvmAirdropService> {
|
|
88
|
+
const project = await this.getProjectInfo();
|
|
89
|
+
|
|
90
|
+
if (options?.walletClient) {
|
|
91
|
+
if (!this.contractInstanceWithWallet) {
|
|
92
|
+
const instance =
|
|
93
|
+
project.chainType === ChainType.Evm
|
|
94
|
+
? new EvmAirdropService({
|
|
95
|
+
contractAddress: project.contractAddress,
|
|
96
|
+
chainId: Number(project.chainId) as ChainId,
|
|
97
|
+
walletClient: options.walletClient as ViemWalletClient
|
|
98
|
+
})
|
|
99
|
+
: new TonAirdropService({
|
|
100
|
+
chainId: project.chainId.toString(),
|
|
101
|
+
address: project.contractAddress,
|
|
102
|
+
walletClient: options.walletClient as TonConnectUI,
|
|
103
|
+
tonClient: this.tonClient
|
|
104
|
+
});
|
|
105
|
+
this.contractInstanceWithWallet = instance;
|
|
106
|
+
}
|
|
107
|
+
return this.contractInstanceWithWallet;
|
|
108
|
+
} else {
|
|
109
|
+
if (!this.contractInstanceWithoutWallet) {
|
|
110
|
+
const instance =
|
|
111
|
+
project.chainType === ChainType.Evm
|
|
112
|
+
? new EvmAirdropService({
|
|
113
|
+
contractAddress: project.contractAddress,
|
|
114
|
+
chainId: Number(project.chainId) as ChainId
|
|
115
|
+
})
|
|
116
|
+
: new TonAirdropService({
|
|
117
|
+
chainId: project.chainId.toString(),
|
|
118
|
+
address: project.contractAddress,
|
|
119
|
+
tonClient: this.tonClient
|
|
120
|
+
});
|
|
121
|
+
this.contractInstanceWithoutWallet = instance;
|
|
122
|
+
}
|
|
123
|
+
return this.contractInstanceWithoutWallet;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private getClaimDataById(claimId: string) {
|
|
128
|
+
const claimData = this.claims?.find((it) => it.claimId === claimId);
|
|
129
|
+
if (!claimData) throw new Error('Claim data not found');
|
|
130
|
+
return claimData;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setClaimFeeHook(fn: (v: any) => any) {
|
|
134
|
+
this.claimHook = fn;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async claimAirdrop(
|
|
138
|
+
{ claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
|
|
139
|
+
options: { onLoading?: () => void }
|
|
140
|
+
) {
|
|
141
|
+
const claimData = this.getClaimDataById(claimId);
|
|
142
|
+
const project = await this.getProjectInfo();
|
|
143
|
+
|
|
144
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
145
|
+
walletClient
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (project.chainType === ChainType.Evm) {
|
|
149
|
+
const version = await contractWrapper.getVersion();
|
|
150
|
+
const needsFeeData = !(
|
|
151
|
+
project.tokenType === ETokenType.Native &&
|
|
152
|
+
[EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum)
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const value = needsFeeData ? await this.getClaimFee(BigInt(claimData.amount)) : undefined;
|
|
156
|
+
|
|
157
|
+
let extraData = {
|
|
158
|
+
isLegacy: true,
|
|
159
|
+
attestationId: BigInt(1)
|
|
160
|
+
};
|
|
161
|
+
if (this.claimHook) {
|
|
162
|
+
extraData = this.claimHook(claimData);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return (contractWrapper as EvmAirdropService).claim({
|
|
166
|
+
proof: claimData.proof,
|
|
167
|
+
group: claimData.group,
|
|
168
|
+
data: claimData.data,
|
|
169
|
+
value: value as bigint | undefined,
|
|
170
|
+
extraData: extraData
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return contractWrapper.claim(claimData, options);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async checkClaimed(claimId: string): Promise<boolean> {
|
|
178
|
+
const claimData = this.getClaimDataById(claimId);
|
|
179
|
+
const project = await this.getProjectInfo();
|
|
180
|
+
|
|
181
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
182
|
+
|
|
183
|
+
if (project.chainType === ChainType.Evm) {
|
|
184
|
+
return (contractWrapper as EvmAirdropService).isLeafUsed(claimData.leaf);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return (contractWrapper as TonAirdropService).checkClaimed(claimData);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async getPaused() {
|
|
191
|
+
const project = await this.getProjectInfo();
|
|
192
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
193
|
+
if (project.chainType === ChainType.Evm) {
|
|
194
|
+
throw new Error('EVM chain is not supported');
|
|
195
|
+
}
|
|
196
|
+
return (contractWrapper as TonAirdropService).getPaused();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async getVersion() {
|
|
200
|
+
if (this.cachedVersion) {
|
|
201
|
+
return this.cachedVersion;
|
|
202
|
+
}
|
|
203
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
204
|
+
|
|
205
|
+
this.cachedVersion = await contractWrapper?.getVersion();
|
|
206
|
+
return this.cachedVersion;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async batchCheckClaimed() {
|
|
210
|
+
const project = await this.getProjectInfo();
|
|
211
|
+
|
|
212
|
+
if (project.chainType === ChainType.Ton) {
|
|
213
|
+
throw new Error('TON chain is not supported');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
217
|
+
const leafs = this.claims?.map((it) => it.leaf);
|
|
218
|
+
|
|
219
|
+
if (!leafs) return [];
|
|
220
|
+
|
|
221
|
+
return (contractWrapper as EvmAirdropService).batchFetchClaimed(leafs);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async getNFT() {
|
|
225
|
+
const project = await this.getProjectInfo();
|
|
226
|
+
|
|
227
|
+
if (project.chainType === ChainType.Ton) {
|
|
228
|
+
throw new Error('TON chain is not supported');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
232
|
+
|
|
233
|
+
return (contractWrapper as EvmAirdropService).getNFT();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async getClaimFee(amount?: bigint) {
|
|
237
|
+
const project = await this.getProjectInfo();
|
|
238
|
+
|
|
239
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
240
|
+
|
|
241
|
+
return contractWrapper.getClaimFee(project.contractAddress, amount || BigInt(1));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AirdropClient } from '../index';
|
|
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 = 'http://ec2-3-89-178-45.compute-1.amazonaws.com:3030/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
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should use slug correctly', async () => {
|
|
27
|
+
client = new AirdropClient({
|
|
28
|
+
slug: 'wat',
|
|
29
|
+
tonClient: mockTonClient
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const projectInfo = await client.getProjectInfo();
|
|
33
|
+
expect(projectInfo).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('test main features', () => {
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
client = new AirdropClient({
|
|
40
|
+
projectId: 'AD_TEV94wvkxkvn',
|
|
41
|
+
endpoint: mockEndpoint
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should get version', async () => {
|
|
46
|
+
const version = await client.getVersion();
|
|
47
|
+
console.log(version);
|
|
48
|
+
expect(version).toBeDefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should get claim fee', async () => {
|
|
52
|
+
const client = new AirdropClient({
|
|
53
|
+
projectId: 'AD_50lczFu9Yhvq',
|
|
54
|
+
endpoint: mockEndpoint
|
|
55
|
+
});
|
|
56
|
+
const fee = await client.getClaimFee();
|
|
57
|
+
console.log(fee);
|
|
58
|
+
expect(fee).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should get airdrop claims', async () => {
|
|
62
|
+
const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
|
|
63
|
+
expect(claims).toBeTruthy();
|
|
64
|
+
expect(claims?.length).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should check claimed', async () => {
|
|
68
|
+
const claims = await client.getAirdropClaims({ address: '0xDfc4FbbDd9C47c7976fEBb14B1D37C7f85FE299D' });
|
|
69
|
+
|
|
70
|
+
const claimed = await client.checkClaimed(claims?.[0].claimId as string);
|
|
71
|
+
expect(claimed).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// describe('catch error', () => {
|
|
76
|
+
// it('throw error when projectId is not provided', async () => {
|
|
77
|
+
// client = new AirdropClient({
|
|
78
|
+
// tonClient: mockTonClient,
|
|
79
|
+
// endpoint: mockEndpoint
|
|
80
|
+
// });
|
|
81
|
+
|
|
82
|
+
// await expect(client.getProjectInfo()).rejects.toThrow('Project ID is required');
|
|
83
|
+
// });
|
|
84
|
+
|
|
85
|
+
// it('throw error when claim data not found', async () => {
|
|
86
|
+
// client = new AirdropClient({
|
|
87
|
+
// projectId: 'project-1',
|
|
88
|
+
// tonClient: mockTonClient,
|
|
89
|
+
// endpoint: mockEndpoint
|
|
90
|
+
// });
|
|
91
|
+
|
|
92
|
+
// await expect(client.checkClaimed('invalid-claim-id')).rejects.toThrow('Claim data not found');
|
|
93
|
+
// });
|
|
94
|
+
// });
|
|
95
|
+
});
|
|
@@ -19,6 +19,32 @@ export enum ChainType {
|
|
|
19
19
|
Ton = 'ton'
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export type ThemeConfig = {
|
|
23
|
+
logo: string;
|
|
24
|
+
title: string;
|
|
25
|
+
description: string;
|
|
26
|
+
coverImage: string;
|
|
27
|
+
subTitle: string;
|
|
28
|
+
primaryColor: string;
|
|
29
|
+
secondaryColor: string;
|
|
30
|
+
buttonPrimaryHover: string;
|
|
31
|
+
buttonSecondaryHover: string;
|
|
32
|
+
buttonPrimaryForeground: string;
|
|
33
|
+
buttonSecondaryForeground: string;
|
|
34
|
+
welcomeModalText: string;
|
|
35
|
+
welcomeModalTitle: string;
|
|
36
|
+
isShowWelcomeModal: boolean;
|
|
37
|
+
blockCountries: string;
|
|
38
|
+
termsOfUse: string;
|
|
39
|
+
successModalPrimaryBtnText: string;
|
|
40
|
+
successModalUrl: string;
|
|
41
|
+
successModalTitle: string;
|
|
42
|
+
successModalDesc: string;
|
|
43
|
+
successModalShareTexts: string;
|
|
44
|
+
isUnAvailable: boolean;
|
|
45
|
+
privacyPolicy: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
22
48
|
export interface IProject {
|
|
23
49
|
id: string;
|
|
24
50
|
name: string;
|
|
@@ -33,7 +59,7 @@ export interface IProject {
|
|
|
33
59
|
merkleRoot: string;
|
|
34
60
|
ownerAddress: string;
|
|
35
61
|
blockCountries: Record<string, string>;
|
|
36
|
-
themeConf:
|
|
62
|
+
themeConf: ThemeConfig | null;
|
|
37
63
|
version: string;
|
|
38
64
|
extra?: {
|
|
39
65
|
kyc: boolean;
|
|
@@ -41,6 +67,12 @@ export interface IProject {
|
|
|
41
67
|
};
|
|
42
68
|
}
|
|
43
69
|
|
|
70
|
+
export enum ETokenType {
|
|
71
|
+
Erc20 = 'ERC20',
|
|
72
|
+
Native = 'NATIVE_TOKEN',
|
|
73
|
+
NFT = 'ERC721'
|
|
74
|
+
}
|
|
75
|
+
|
|
44
76
|
export type IAirdropClaim = {
|
|
45
77
|
index: number;
|
|
46
78
|
recipient: string;
|
|
@@ -84,45 +116,19 @@ export type IWalletClient = TonConnectUI | ViemWalletClient;
|
|
|
84
116
|
|
|
85
117
|
export type IAirdropService = TonAirdropService | EvmAirdropService;
|
|
86
118
|
|
|
87
|
-
|
|
88
|
-
endpoint?: string;
|
|
89
|
-
projectId?: string;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
type BaseTonConfig = {
|
|
119
|
+
type BaseAirdropOptions = {
|
|
93
120
|
endpoint?: string;
|
|
94
121
|
tonClient?: TonClient;
|
|
95
122
|
};
|
|
96
123
|
|
|
97
|
-
|
|
98
|
-
type TonProjectIdConfig = BaseTonConfig & {
|
|
124
|
+
type ProjectIdOptions = BaseAirdropOptions & {
|
|
99
125
|
projectId: string;
|
|
100
|
-
slug?: never;
|
|
126
|
+
slug?: never;
|
|
101
127
|
};
|
|
102
128
|
|
|
103
|
-
|
|
104
|
-
type TonSlugConfig = BaseTonConfig & {
|
|
129
|
+
type SlugOptions = BaseAirdropOptions & {
|
|
105
130
|
slug: string;
|
|
106
|
-
projectId?: never;
|
|
131
|
+
projectId?: never;
|
|
107
132
|
};
|
|
108
133
|
|
|
109
|
-
export type
|
|
110
|
-
|
|
111
|
-
export interface EvmAirdropOptions extends BaseAirdropOptions {
|
|
112
|
-
projectId: string;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface TonContractWrapperOptions {
|
|
116
|
-
chainId: ChainId;
|
|
117
|
-
contractAddress: string;
|
|
118
|
-
walletClient?: TonConnectUI;
|
|
119
|
-
tonClient?: TonClient;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface EvmContractWrapperOptions {
|
|
123
|
-
chainId: ChainId;
|
|
124
|
-
contractAddress: string;
|
|
125
|
-
walletClient?: ViemWalletClient;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export type ContractWrapperOptions = TonContractWrapperOptions | EvmContractWrapperOptions;
|
|
134
|
+
export type IAirdropOptions = ProjectIdOptions | SlugOptions;
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AirdropClient } from './airdrop';
|
|
2
|
+
export * from './airdrop/types';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BaseAirdropOptions, ContractWrapperOptions, IAirdropClaim, IAirdropService, IProject, IWalletClient } from './types';
|
|
2
|
-
export declare abstract class BaseAirdropClient {
|
|
3
|
-
protected endpoint?: string;
|
|
4
|
-
protected projectId?: string;
|
|
5
|
-
protected claims?: IAirdropClaim[];
|
|
6
|
-
protected projects?: IProject[];
|
|
7
|
-
constructor(params: BaseAirdropOptions);
|
|
8
|
-
abstract getAirdropContractWrapper(options: ContractWrapperOptions): IAirdropService | undefined;
|
|
9
|
-
fetchAirdropProjectIds(data: {
|
|
10
|
-
recipient: string;
|
|
11
|
-
slug: string;
|
|
12
|
-
}): Promise<{
|
|
13
|
-
recipient: string;
|
|
14
|
-
projectIds: string[];
|
|
15
|
-
}>;
|
|
16
|
-
protected initializeProjects(address: string): Promise<void>;
|
|
17
|
-
fetchAirdropClaims(data: {
|
|
18
|
-
address: string;
|
|
19
|
-
}): Promise<IAirdropClaim[]>;
|
|
20
|
-
getProjectList(): IProject[] | undefined;
|
|
21
|
-
abstract claimAirdrop(params: {
|
|
22
|
-
claimId: string;
|
|
23
|
-
walletClient: IWalletClient;
|
|
24
|
-
}, options: {
|
|
25
|
-
onLoading?: () => void;
|
|
26
|
-
}): Promise<unknown>;
|
|
27
|
-
abstract checkClaimed(claimId: string): Promise<boolean>;
|
|
28
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseAirdropClient = void 0;
|
|
4
|
-
const services_1 = require("./services");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
class BaseAirdropClient {
|
|
7
|
-
endpoint;
|
|
8
|
-
projectId;
|
|
9
|
-
claims;
|
|
10
|
-
projects;
|
|
11
|
-
constructor(params) {
|
|
12
|
-
this.endpoint = params.endpoint;
|
|
13
|
-
this.projectId = params.projectId;
|
|
14
|
-
}
|
|
15
|
-
async fetchAirdropProjectIds(data) {
|
|
16
|
-
const res = await (0, services_1.getAirdropProjectId)(data, this.endpoint);
|
|
17
|
-
return res;
|
|
18
|
-
}
|
|
19
|
-
async initializeProjects(address) {
|
|
20
|
-
const projectIds = this.projectId ? [this.projectId] : [];
|
|
21
|
-
this.projects = await Promise.all(projectIds.map(async (projectId) => (0, services_1.getAirdropProject)(projectId, this.endpoint)));
|
|
22
|
-
}
|
|
23
|
-
async fetchAirdropClaims(data) {
|
|
24
|
-
if (!this.projects) {
|
|
25
|
-
await this.initializeProjects(data.address);
|
|
26
|
-
}
|
|
27
|
-
if (!this.projects?.length) {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
const claimsRes = await Promise.all(this.projects.map(async (project) => {
|
|
31
|
-
const res = await (0, services_1.getAirdropQuery)({
|
|
32
|
-
recipient: data.address,
|
|
33
|
-
projectId: project.id,
|
|
34
|
-
recipientType: project.recipientType
|
|
35
|
-
}, this.endpoint);
|
|
36
|
-
return res.claims?.map((it) => ({
|
|
37
|
-
...it,
|
|
38
|
-
project: project,
|
|
39
|
-
claimId: project.chainType === types_1.ChainType.Evm ? `${project.id}:${it.leaf}` : `${project.id}:${it.index}`
|
|
40
|
-
}));
|
|
41
|
-
}));
|
|
42
|
-
this.claims = claimsRes.flat();
|
|
43
|
-
return this.claims;
|
|
44
|
-
}
|
|
45
|
-
getProjectList() {
|
|
46
|
-
return this.projects;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.BaseAirdropClient = BaseAirdropClient;
|
|
50
|
-
//# sourceMappingURL=BaseAirdropClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAirdropClient.js","sourceRoot":"","sources":["../../../src/airdrop/BaseAirdropClient.ts"],"names":[],"mappings":";;;AAAA,yCAAqF;AACrF,mCAQiB;AAEjB,MAAsB,iBAAiB;IAC3B,QAAQ,CAAU;IAClB,SAAS,CAAU;IACnB,MAAM,CAAmB;IACzB,QAAQ,CAAc;IAEhC,YAAY,MAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACpC,CAAC;IAID,KAAK,CAAC,sBAAsB,CAAC,IAAyC;QACpE,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAmB,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3D,OAAO,GAAG,CAAC;IACb,CAAC;IAES,KAAK,CAAC,kBAAkB,CAAC,OAAe;QAChD,MAAM,UAAU,GAAa,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,IAAI,CAAC,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,IAAA,4BAAiB,EAAC,SAAS,E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
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BaseAirdropClient } from './BaseAirdropClient';
|
|
2
|
-
import { EvmContractWrapperOptions } from './types';
|
|
3
|
-
import { AirdropService as EvmAirdropService } from './core/evm/AirdropService';
|
|
4
|
-
import { WalletClient as ViemWalletClient } from 'viem';
|
|
5
|
-
export declare class EvmAirdropClient extends BaseAirdropClient {
|
|
6
|
-
private contractInstances;
|
|
7
|
-
getAirdropContractWrapper(options: EvmContractWrapperOptions): EvmAirdropService;
|
|
8
|
-
private getClaimDataById;
|
|
9
|
-
claimAirdrop({ claimId, walletClient }: {
|
|
10
|
-
claimId: string;
|
|
11
|
-
walletClient: ViemWalletClient;
|
|
12
|
-
}): Promise<`0x${string}`>;
|
|
13
|
-
checkClaimed(claimId: string): Promise<boolean>;
|
|
14
|
-
batchFetchClaimed(leafs: string[]): Promise<{
|
|
15
|
-
result: boolean;
|
|
16
|
-
status: string;
|
|
17
|
-
}[]>;
|
|
18
|
-
getClaimFee(amount: bigint): Promise<bigint | undefined>;
|
|
19
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EvmAirdropClient = void 0;
|
|
4
|
-
const BaseAirdropClient_1 = require("./BaseAirdropClient");
|
|
5
|
-
const AirdropService_1 = require("./core/evm/AirdropService");
|
|
6
|
-
class EvmAirdropClient extends BaseAirdropClient_1.BaseAirdropClient {
|
|
7
|
-
contractInstances = new Map();
|
|
8
|
-
getAirdropContractWrapper(options) {
|
|
9
|
-
const instanceKey = `${options.chainId}:${options.contractAddress}`;
|
|
10
|
-
if (!this.contractInstances.has(instanceKey)) {
|
|
11
|
-
const instance = new AirdropService_1.AirdropService({
|
|
12
|
-
contractAddress: options.contractAddress,
|
|
13
|
-
chainId: Number(options.chainId),
|
|
14
|
-
walletClient: options.walletClient
|
|
15
|
-
});
|
|
16
|
-
this.contractInstances.set(instanceKey, instance);
|
|
17
|
-
}
|
|
18
|
-
return this.contractInstances.get(instanceKey);
|
|
19
|
-
}
|
|
20
|
-
getClaimDataById(claimId) {
|
|
21
|
-
const claimData = this.claims?.find((it) => it.claimId === claimId);
|
|
22
|
-
if (!claimData)
|
|
23
|
-
throw new Error('Claim data not found');
|
|
24
|
-
return claimData;
|
|
25
|
-
}
|
|
26
|
-
async claimAirdrop({ claimId, walletClient }) {
|
|
27
|
-
const claimData = this.getClaimDataById(claimId);
|
|
28
|
-
const contractWrapper = this.getAirdropContractWrapper({
|
|
29
|
-
chainId: claimData.project.chainId,
|
|
30
|
-
contractAddress: claimData.project.contractAddress,
|
|
31
|
-
walletClient
|
|
32
|
-
});
|
|
33
|
-
return contractWrapper.claim(claimData);
|
|
34
|
-
}
|
|
35
|
-
async checkClaimed(claimId) {
|
|
36
|
-
const claimData = this.getClaimDataById(claimId);
|
|
37
|
-
const contractWrapper = this.getAirdropContractWrapper({
|
|
38
|
-
chainId: Number(claimData.project.chainId),
|
|
39
|
-
contractAddress: claimData.project.contractAddress
|
|
40
|
-
});
|
|
41
|
-
return contractWrapper.isLeafUsed(claimData.leaf);
|
|
42
|
-
}
|
|
43
|
-
async batchFetchClaimed(leafs) {
|
|
44
|
-
const claimData = this.claims?.[0];
|
|
45
|
-
if (!claimData)
|
|
46
|
-
throw new Error('Claim data not found');
|
|
47
|
-
const contractWrapper = this.getAirdropContractWrapper({
|
|
48
|
-
chainId: Number(claimData.project.chainId),
|
|
49
|
-
contractAddress: claimData.project.contractAddress
|
|
50
|
-
});
|
|
51
|
-
return contractWrapper.batchFetchClaimed(leafs);
|
|
52
|
-
}
|
|
53
|
-
async getClaimFee(amount) {
|
|
54
|
-
const claimData = this.claims?.[0];
|
|
55
|
-
if (!claimData)
|
|
56
|
-
throw new Error('Claim data not found');
|
|
57
|
-
const contractWrapper = this.getAirdropContractWrapper({
|
|
58
|
-
chainId: Number(claimData.project.chainId),
|
|
59
|
-
contractAddress: claimData.project.contractAddress
|
|
60
|
-
});
|
|
61
|
-
return contractWrapper.getClaimFee(claimData.project.contractAddress, amount);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.EvmAirdropClient = EvmAirdropClient;
|
|
65
|
-
//# sourceMappingURL=EvmAirdropClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EvmAirdropClient.js","sourceRoot":"","sources":["../../../src/airdrop/EvmAirdropClient.ts"],"names":[],"mappings":";;;AAAA,2DAAwD;AAExD,8DAAgF;AAGhF,MAAa,gBAAiB,SAAQ,qCAAiB;IAC7C,iBAAiB,GAAG,IAAI,GAAG,EAA6B,CAAC;IACjE,yBAAyB,CAAC,OAAkC;QAC1D,MAAM,WAAW,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QACpE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7C,MAAM,QAAQ,GAAG,IAAI,+BAAiB,CAAC;gBACrC,eAAe,EAAE,OAAO,CAAC,eAAe;gBACxC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAY;gBAC3C,YAAY,EAAE,OAAO,CAAC,YAAgC;aACvD,CAAC,CAAC;YACH,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;IAClD,CAAC;IAEO,gBAAgB,CAAC,OAAe;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACxD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED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G,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAExD,MAAM,eAAe,GAAG,IAAI,CAAC,yBAAyB,CAAC;YACrD,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAY;YACrD,eAAe,EAAE,SAAS,CAAC,OAAO,CAAC,eAAe;SACnD,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC;CACF;AApED,4CAoEC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BaseAirdropClient } from './BaseAirdropClient';
|
|
2
|
-
import { TonConnectUI } from '@tonconnect/ui-react';
|
|
3
|
-
import { AirdropService as TonAirdropService } from './core/ton/AirdropService';
|
|
4
|
-
import { TonAirdropOptions, TonContractWrapperOptions } from './types';
|
|
5
|
-
export declare class TonAirdropClient extends BaseAirdropClient {
|
|
6
|
-
private tonClient?;
|
|
7
|
-
private slug?;
|
|
8
|
-
private contractInstances;
|
|
9
|
-
constructor(params: TonAirdropOptions);
|
|
10
|
-
protected initializeProjects(address: string): Promise<void>;
|
|
11
|
-
getAirdropContractWrapper(options: TonContractWrapperOptions): TonAirdropService;
|
|
12
|
-
private getClaimDataById;
|
|
13
|
-
claimAirdrop({ claimId, walletClient }: {
|
|
14
|
-
claimId: string;
|
|
15
|
-
walletClient: TonConnectUI;
|
|
16
|
-
}, options: {
|
|
17
|
-
onLoading?: () => void;
|
|
18
|
-
}): Promise<import("tonapi-sdk-js").Event | null>;
|
|
19
|
-
checkClaimed(claimId: string): Promise<boolean>;
|
|
20
|
-
getPaused({ contractAddress, chainId }: {
|
|
21
|
-
contractAddress: string;
|
|
22
|
-
chainId: string;
|
|
23
|
-
}): Promise<boolean>;
|
|
24
|
-
}
|