@sign-global/tokentable 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -34
- 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.js +0 -1
- package/dist/cjs/airdrop/core/evm/AirdropService.js.map +1 -1
- package/dist/cjs/airdrop/core/evm/contracts/ContractBaseClient.js +1 -1
- package/dist/cjs/airdrop/core/evm/contracts/ContractBaseClient.js.map +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV2.d.ts +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV2.js +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV2.js.map +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV3.d.ts +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV3.js +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropClientV3.js.map +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropService.d.ts +1 -1
- package/dist/cjs/airdrop/core/ton/AirdropService.js.map +1 -1
- package/dist/cjs/airdrop/index.d.ts +11 -7
- package/dist/cjs/airdrop/index.js +94 -38
- package/dist/cjs/airdrop/index.js.map +1 -1
- package/dist/cjs/airdrop/types/index.d.ts +31 -1
- 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 +1 -0
- package/dist/cjs/index.js +15 -0
- 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.js +0 -1
- package/dist/esm/airdrop/core/evm/AirdropService.js.map +1 -1
- package/dist/esm/airdrop/core/evm/contracts/ContractBaseClient.js +1 -1
- package/dist/esm/airdrop/core/evm/contracts/ContractBaseClient.js.map +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV2.d.ts +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV2.js +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV2.js.map +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV3.d.ts +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV3.js +1 -1
- package/dist/esm/airdrop/core/ton/AirdropClientV3.js.map +1 -1
- package/dist/esm/airdrop/core/ton/AirdropService.d.ts +1 -1
- package/dist/esm/airdrop/core/ton/AirdropService.js.map +1 -1
- package/dist/esm/airdrop/index.d.ts +11 -7
- package/dist/esm/airdrop/index.js +95 -39
- package/dist/esm/airdrop/index.js.map +1 -1
- package/dist/esm/airdrop/types/index.d.ts +31 -1
- 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 +1 -0
- package/dist/esm/index.js +1 -0
- 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 +0 -1
- package/src/airdrop/core/evm/contracts/ContractBaseClient.ts +1 -1
- package/src/airdrop/core/ton/AirdropClientV2.ts +2 -2
- package/src/airdrop/core/ton/AirdropClientV3.ts +2 -2
- package/src/airdrop/core/ton/AirdropService.ts +1 -1
- package/src/airdrop/index.ts +124 -46
- package/src/airdrop/tests/index.test.ts +95 -0
- package/src/airdrop/types/index.ts +33 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sign-global/tokentable",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build-cjs": "tsc -m commonjs --outDir dist/cjs",
|
|
13
13
|
"build-esm": "tsc -m esnext --outDir dist/esm",
|
|
14
|
-
"build": "pnpm run build-cjs && pnpm run build-esm"
|
|
14
|
+
"build": "pnpm run build-cjs && pnpm run build-esm",
|
|
15
|
+
"test": "jest"
|
|
15
16
|
},
|
|
16
17
|
"author": "Evan",
|
|
17
18
|
"license": "ISC",
|
|
@@ -20,10 +21,13 @@
|
|
|
20
21
|
"@ton/core": "^0.59.0",
|
|
21
22
|
"@ton/ton": "^15.1.0",
|
|
22
23
|
"@tonconnect/ui-react": "^2.0.9",
|
|
24
|
+
"@types/jest": "^29.5.14",
|
|
23
25
|
"bignumber.js": "^9.1.2",
|
|
24
26
|
"dayjs": "^1.11.13",
|
|
27
|
+
"jest": "^29.7.0",
|
|
25
28
|
"tonapi-sdk-js": "^2.0.3",
|
|
26
29
|
"tonweb": "^0.0.66",
|
|
30
|
+
"ts-jest": "^29.2.5",
|
|
27
31
|
"viem": "^2.21.49",
|
|
28
32
|
"wagmi": "^2.13.0"
|
|
29
33
|
},
|
|
@@ -31,7 +31,7 @@ export const getTonProjectIdByAddress = ({
|
|
|
31
31
|
slug,
|
|
32
32
|
data
|
|
33
33
|
}: {
|
|
34
|
-
address
|
|
34
|
+
address?: string;
|
|
35
35
|
slug: string;
|
|
36
36
|
data: Record<string, string>;
|
|
37
37
|
}): string | undefined => {
|
|
@@ -39,6 +39,11 @@ export const getTonProjectIdByAddress = ({
|
|
|
39
39
|
if (!project) {
|
|
40
40
|
project = data;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
if (!address) {
|
|
44
|
+
const firstProject = Object.values(project)[0];
|
|
45
|
+
return firstProject;
|
|
46
|
+
}
|
|
42
47
|
const lastText = address[address.length - 1];
|
|
43
48
|
|
|
44
49
|
const group = Object.keys(project || {}).find((key) => key.includes(lastText));
|
|
@@ -64,7 +64,7 @@ export class TonAirdropClientV2 extends TonContractBaseClient {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
claim = async (claimData: IAirdropClaim, options
|
|
67
|
+
claim = async (claimData: IAirdropClaim, options?: { onLoading?: () => void }) => {
|
|
68
68
|
const provider = await this.getTonClient();
|
|
69
69
|
const airdropContract = await this.getAirdropContract();
|
|
70
70
|
const index = BigInt(claimData.index);
|
|
@@ -84,7 +84,7 @@ export class TonAirdropClientV2 extends TonContractBaseClient {
|
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
|
|
87
|
-
const res = await this.waitForTransaction(options
|
|
87
|
+
const res = await this.waitForTransaction(options?.onLoading);
|
|
88
88
|
if (res) {
|
|
89
89
|
console.log(res, res.event_id, 'res');
|
|
90
90
|
}
|
|
@@ -65,7 +65,7 @@ export class TonAirdropClientV3 extends TonContractBaseClient {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
claim = async (claimData: IAirdropClaim, options
|
|
68
|
+
claim = async (claimData: IAirdropClaim, options?: { onLoading?: () => void }) => {
|
|
69
69
|
// const { provider, airdropContract, claimFee, leafAddress } = prepreData;
|
|
70
70
|
const provider = await this.getTonClient();
|
|
71
71
|
const airdropContract = await this.getAirdropContract();
|
|
@@ -87,7 +87,7 @@ export class TonAirdropClientV3 extends TonContractBaseClient {
|
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
|
|
90
|
-
const res = await this.waitForTransaction(options
|
|
90
|
+
const res = await this.waitForTransaction(options?.onLoading);
|
|
91
91
|
|
|
92
92
|
// while (!(await provider.isContractDeployed(leafAddress))) {
|
|
93
93
|
// console.log('waiting for leaf to deploy');
|
|
@@ -86,7 +86,7 @@ export class AirdropService {
|
|
|
86
86
|
return client.getAirdropContract();
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
async claim(claimData: IAirdropClaim, options
|
|
89
|
+
async claim(claimData: IAirdropClaim, options?: { onLoading?: () => void }) {
|
|
90
90
|
const client = await this.getClient();
|
|
91
91
|
return client.claim(claimData, options);
|
|
92
92
|
}
|
package/src/airdrop/index.ts
CHANGED
|
@@ -3,7 +3,16 @@ import { TonConnectUI } from '@tonconnect/ui-react';
|
|
|
3
3
|
import { AirdropService as TonAirdropService } from './core/ton/AirdropService';
|
|
4
4
|
import { AirdropService as EvmAirdropService } from './core/evm/AirdropService';
|
|
5
5
|
import { getAirdropPro, getAirdropProject, getAirdropQuery } from './services';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ChainId,
|
|
8
|
+
ChainType,
|
|
9
|
+
ETokenType,
|
|
10
|
+
EvmAirdropVersionEnum,
|
|
11
|
+
IAirdropClaim,
|
|
12
|
+
IAirdropOptions,
|
|
13
|
+
IProject,
|
|
14
|
+
IWalletClient
|
|
15
|
+
} from './types';
|
|
7
16
|
import { getTonProjectIdByAddress } from './common';
|
|
8
17
|
import { WalletClient as ViemWalletClient } from 'viem';
|
|
9
18
|
|
|
@@ -14,8 +23,11 @@ export class AirdropClient {
|
|
|
14
23
|
private endpoint?: string;
|
|
15
24
|
private project: IProject | undefined;
|
|
16
25
|
protected claims?: IAirdropClaim[];
|
|
17
|
-
private
|
|
26
|
+
private contractInstanceWithWallet: TonAirdropService | EvmAirdropService | undefined;
|
|
27
|
+
private contractInstanceWithoutWallet: TonAirdropService | EvmAirdropService | undefined;
|
|
18
28
|
private projectPromise: Promise<void> | undefined;
|
|
29
|
+
private claimHook: ((v: any) => any) | undefined;
|
|
30
|
+
private cachedVersion: string | null = null;
|
|
19
31
|
|
|
20
32
|
constructor(params: IAirdropOptions) {
|
|
21
33
|
if ('slug' in params) {
|
|
@@ -31,14 +43,10 @@ export class AirdropClient {
|
|
|
31
43
|
let projectId: string | undefined = this.projectId;
|
|
32
44
|
if (this.slug) {
|
|
33
45
|
const res = await getAirdropPro(this.slug, this.endpoint);
|
|
34
|
-
const projectMap = res?.childProjectMapping;
|
|
46
|
+
const projectMap = res?.childProjectMapping || {};
|
|
35
47
|
|
|
36
48
|
let legacyProjectId: string | undefined;
|
|
37
|
-
|
|
38
|
-
legacyProjectId = Object.values(projectMap)[0];
|
|
39
|
-
} else {
|
|
40
|
-
legacyProjectId = getTonProjectIdByAddress({ address, slug: this.slug, data: projectMap });
|
|
41
|
-
}
|
|
49
|
+
legacyProjectId = getTonProjectIdByAddress({ address, slug: this.slug, data: projectMap });
|
|
42
50
|
|
|
43
51
|
if (legacyProjectId) {
|
|
44
52
|
projectId = legacyProjectId;
|
|
@@ -49,7 +57,6 @@ export class AirdropClient {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
async getProjectInfo() {
|
|
52
|
-
console.log(this.projectPromise);
|
|
53
60
|
await this.projectPromise;
|
|
54
61
|
if (!this.project) throw new Error('Project not found');
|
|
55
62
|
return this.project;
|
|
@@ -75,30 +82,46 @@ export class AirdropClient {
|
|
|
75
82
|
return this.claims;
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
async getAirdropContractWrapper(options
|
|
85
|
+
async getAirdropContractWrapper(options?: {
|
|
79
86
|
walletClient?: IWalletClient;
|
|
80
|
-
tonClient?: TonClient;
|
|
81
87
|
}): Promise<TonAirdropService | EvmAirdropService> {
|
|
82
|
-
|
|
83
|
-
const project = await this.getProjectInfo();
|
|
84
|
-
|
|
85
|
-
const instance =
|
|
86
|
-
project.chainType === ChainType.Evm
|
|
87
|
-
? new EvmAirdropService({
|
|
88
|
-
contractAddress: project.contractAddress,
|
|
89
|
-
chainId: Number(project.chainId) as ChainId,
|
|
90
|
-
walletClient: options.walletClient as ViemWalletClient
|
|
91
|
-
})
|
|
92
|
-
: new TonAirdropService({
|
|
93
|
-
chainId: project.chainId.toString(),
|
|
94
|
-
address: project.contractAddress,
|
|
95
|
-
walletClient: options.walletClient as TonConnectUI,
|
|
96
|
-
tonClient: this.tonClient
|
|
97
|
-
});
|
|
98
|
-
this.contractInstance = instance;
|
|
99
|
-
}
|
|
88
|
+
const project = await this.getProjectInfo();
|
|
100
89
|
|
|
101
|
-
|
|
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
|
+
}
|
|
102
125
|
}
|
|
103
126
|
|
|
104
127
|
private getClaimDataById(claimId: string) {
|
|
@@ -107,26 +130,55 @@ export class AirdropClient {
|
|
|
107
130
|
return claimData;
|
|
108
131
|
}
|
|
109
132
|
|
|
133
|
+
setClaimHook(fn: (v: any) => any) {
|
|
134
|
+
this.claimHook = fn;
|
|
135
|
+
}
|
|
136
|
+
|
|
110
137
|
async claimAirdrop(
|
|
111
138
|
{ claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
|
|
112
|
-
options
|
|
139
|
+
options?: { onLoading?: () => void }
|
|
113
140
|
) {
|
|
114
141
|
const claimData = this.getClaimDataById(claimId);
|
|
142
|
+
const project = await this.getProjectInfo();
|
|
115
143
|
|
|
116
144
|
const contractWrapper = await this.getAirdropContractWrapper({
|
|
117
145
|
walletClient
|
|
118
146
|
});
|
|
119
147
|
|
|
120
|
-
|
|
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 as TonAirdropService).claim(claimData, options);
|
|
121
175
|
}
|
|
122
176
|
|
|
123
177
|
async checkClaimed(claimId: string): Promise<boolean> {
|
|
124
178
|
const claimData = this.getClaimDataById(claimId);
|
|
125
179
|
const project = await this.getProjectInfo();
|
|
126
180
|
|
|
127
|
-
const contractWrapper = await this.getAirdropContractWrapper(
|
|
128
|
-
tonClient: this.tonClient
|
|
129
|
-
});
|
|
181
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
130
182
|
|
|
131
183
|
if (project.chainType === ChainType.Evm) {
|
|
132
184
|
return (contractWrapper as EvmAirdropService).isLeafUsed(claimData.leaf);
|
|
@@ -137,9 +189,7 @@ export class AirdropClient {
|
|
|
137
189
|
|
|
138
190
|
async getPaused() {
|
|
139
191
|
const project = await this.getProjectInfo();
|
|
140
|
-
const contractWrapper = await this.getAirdropContractWrapper(
|
|
141
|
-
tonClient: this.tonClient
|
|
142
|
-
});
|
|
192
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
143
193
|
if (project.chainType === ChainType.Evm) {
|
|
144
194
|
throw new Error('EVM chain is not supported');
|
|
145
195
|
}
|
|
@@ -147,29 +197,57 @@ export class AirdropClient {
|
|
|
147
197
|
}
|
|
148
198
|
|
|
149
199
|
async getVersion() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
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;
|
|
154
207
|
}
|
|
155
208
|
|
|
156
|
-
async
|
|
209
|
+
async batchCheckClaimed() {
|
|
157
210
|
const project = await this.getProjectInfo();
|
|
158
211
|
|
|
159
212
|
if (project.chainType === ChainType.Ton) {
|
|
160
213
|
throw new Error('TON chain is not supported');
|
|
161
214
|
}
|
|
162
215
|
|
|
163
|
-
const contractWrapper = await this.getAirdropContractWrapper(
|
|
216
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
217
|
+
const leafs = this.claims?.map((it) => it.leaf);
|
|
218
|
+
|
|
219
|
+
if (!leafs) return [];
|
|
164
220
|
|
|
165
221
|
return (contractWrapper as EvmAirdropService).batchFetchClaimed(leafs);
|
|
166
222
|
}
|
|
167
223
|
|
|
168
|
-
async
|
|
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 getKycThreshold() {
|
|
237
|
+
const project = await this.getProjectInfo();
|
|
238
|
+
|
|
239
|
+
if (project.chainType === ChainType.Ton) {
|
|
240
|
+
throw new Error('TON chain is not supported');
|
|
241
|
+
}
|
|
242
|
+
const contractWrapper = await this.getAirdropContractWrapper();
|
|
243
|
+
return (contractWrapper as EvmAirdropService).getKycThreshold();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async getClaimFee(amount?: bigint) {
|
|
169
247
|
const project = await this.getProjectInfo();
|
|
170
248
|
|
|
171
249
|
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
172
250
|
|
|
173
|
-
return contractWrapper.getClaimFee(project.contractAddress, amount);
|
|
251
|
+
return contractWrapper.getClaimFee(project.contractAddress, amount || BigInt(1));
|
|
174
252
|
}
|
|
175
253
|
}
|
|
@@ -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;
|
package/src/index.ts
CHANGED