@sign-global/tokentable 0.0.1 → 0.0.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.
- package/README.md +7 -21
- package/dist/cjs/airdrop/core/evm/AirdropService.d.ts +1 -1
- package/dist/cjs/airdrop/core/evm/AirdropService.js +3 -3
- 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 +39 -3
- package/dist/cjs/airdrop/index.js +140 -20
- package/dist/cjs/airdrop/index.js.map +1 -1
- package/dist/cjs/airdrop/types/index.d.ts +4 -23
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/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 -3
- 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 +39 -3
- package/dist/esm/airdrop/index.js +138 -3
- package/dist/esm/airdrop/index.js.map +1 -1
- package/dist/esm/airdrop/types/index.d.ts +4 -23
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/airdrop/core/evm/AirdropService.ts +3 -3
- package/src/airdrop/core/ton/AirdropService.ts +6 -0
- package/src/airdrop/index.ts +175 -3
- package/src/airdrop/types/index.ts +6 -32
- package/src/index.ts +1 -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
|
@@ -1,4 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AirdropService as TonAirdropService } from './core/ton/AirdropService';
|
|
2
|
+
import { AirdropService as EvmAirdropService } from './core/evm/AirdropService';
|
|
3
|
+
import { getAirdropPro, getAirdropProject, getAirdropQuery } from './services';
|
|
4
|
+
import { ChainType } from './types';
|
|
5
|
+
import { getTonProjectIdByAddress } from './common';
|
|
6
|
+
export class AirdropClient {
|
|
7
|
+
tonClient;
|
|
8
|
+
slug;
|
|
9
|
+
projectId;
|
|
10
|
+
endpoint;
|
|
11
|
+
project;
|
|
12
|
+
claims;
|
|
13
|
+
contractInstance;
|
|
14
|
+
projectPromise;
|
|
15
|
+
constructor(params) {
|
|
16
|
+
if ('slug' in params) {
|
|
17
|
+
this.slug = params.slug;
|
|
18
|
+
}
|
|
19
|
+
this.tonClient = params.tonClient;
|
|
20
|
+
this.projectId = params.projectId;
|
|
21
|
+
this.endpoint = params.endpoint;
|
|
22
|
+
this.projectPromise = this.initializeProjects();
|
|
23
|
+
}
|
|
24
|
+
async initializeProjects(address) {
|
|
25
|
+
let projectId = this.projectId;
|
|
26
|
+
if (this.slug) {
|
|
27
|
+
const res = await getAirdropPro(this.slug, this.endpoint);
|
|
28
|
+
const projectMap = res?.childProjectMapping;
|
|
29
|
+
let legacyProjectId;
|
|
30
|
+
if (!address) {
|
|
31
|
+
legacyProjectId = Object.values(projectMap)[0];
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
legacyProjectId = getTonProjectIdByAddress({ address, slug: this.slug, data: projectMap });
|
|
35
|
+
}
|
|
36
|
+
if (legacyProjectId) {
|
|
37
|
+
projectId = legacyProjectId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!projectId)
|
|
41
|
+
throw new Error('Project ID is required');
|
|
42
|
+
this.project = await getAirdropProject(projectId, this.endpoint);
|
|
43
|
+
}
|
|
44
|
+
async getProjectInfo() {
|
|
45
|
+
console.log(this.projectPromise);
|
|
46
|
+
await this.projectPromise;
|
|
47
|
+
if (!this.project)
|
|
48
|
+
throw new Error('Project not found');
|
|
49
|
+
return this.project;
|
|
50
|
+
}
|
|
51
|
+
async getAirdropClaims(data) {
|
|
52
|
+
const project = await this.getProjectInfo();
|
|
53
|
+
const res = await getAirdropQuery({
|
|
54
|
+
recipient: data.address,
|
|
55
|
+
projectId: project.id,
|
|
56
|
+
recipientType: project.recipientType
|
|
57
|
+
}, this.endpoint);
|
|
58
|
+
const claimsRes = res.claims?.map((it) => ({
|
|
59
|
+
...it,
|
|
60
|
+
project: project,
|
|
61
|
+
claimId: project.chainType === ChainType.Evm ? `${project.id}:${it.leaf}` : `${project.id}:${it.index}`
|
|
62
|
+
}));
|
|
63
|
+
this.claims = claimsRes;
|
|
64
|
+
return this.claims;
|
|
65
|
+
}
|
|
66
|
+
async getAirdropContractWrapper(options) {
|
|
67
|
+
if (!this.contractInstance) {
|
|
68
|
+
const project = await this.getProjectInfo();
|
|
69
|
+
const instance = project.chainType === ChainType.Evm
|
|
70
|
+
? new EvmAirdropService({
|
|
71
|
+
contractAddress: project.contractAddress,
|
|
72
|
+
chainId: Number(project.chainId),
|
|
73
|
+
walletClient: options.walletClient
|
|
74
|
+
})
|
|
75
|
+
: new TonAirdropService({
|
|
76
|
+
chainId: project.chainId.toString(),
|
|
77
|
+
address: project.contractAddress,
|
|
78
|
+
walletClient: options.walletClient,
|
|
79
|
+
tonClient: this.tonClient
|
|
80
|
+
});
|
|
81
|
+
this.contractInstance = instance;
|
|
82
|
+
}
|
|
83
|
+
return this.contractInstance;
|
|
84
|
+
}
|
|
85
|
+
getClaimDataById(claimId) {
|
|
86
|
+
const claimData = this.claims?.find((it) => it.claimId === claimId);
|
|
87
|
+
if (!claimData)
|
|
88
|
+
throw new Error('Claim data not found');
|
|
89
|
+
return claimData;
|
|
90
|
+
}
|
|
91
|
+
async claimAirdrop({ claimId, walletClient }, options) {
|
|
92
|
+
const claimData = this.getClaimDataById(claimId);
|
|
93
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
94
|
+
walletClient
|
|
95
|
+
});
|
|
96
|
+
return contractWrapper.claim(claimData, options);
|
|
97
|
+
}
|
|
98
|
+
async checkClaimed(claimId) {
|
|
99
|
+
const claimData = this.getClaimDataById(claimId);
|
|
100
|
+
const project = await this.getProjectInfo();
|
|
101
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
102
|
+
tonClient: this.tonClient
|
|
103
|
+
});
|
|
104
|
+
if (project.chainType === ChainType.Evm) {
|
|
105
|
+
return contractWrapper.isLeafUsed(claimData.leaf);
|
|
106
|
+
}
|
|
107
|
+
return contractWrapper.checkClaimed(claimData);
|
|
108
|
+
}
|
|
109
|
+
async getPaused() {
|
|
110
|
+
const project = await this.getProjectInfo();
|
|
111
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
112
|
+
tonClient: this.tonClient
|
|
113
|
+
});
|
|
114
|
+
if (project.chainType === ChainType.Evm) {
|
|
115
|
+
throw new Error('EVM chain is not supported');
|
|
116
|
+
}
|
|
117
|
+
return contractWrapper.getPaused();
|
|
118
|
+
}
|
|
119
|
+
async getVersion() {
|
|
120
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
121
|
+
tonClient: this.tonClient
|
|
122
|
+
});
|
|
123
|
+
return contractWrapper?.getVersion();
|
|
124
|
+
}
|
|
125
|
+
async batchFetchClaimed(leafs) {
|
|
126
|
+
const project = await this.getProjectInfo();
|
|
127
|
+
if (project.chainType === ChainType.Ton) {
|
|
128
|
+
throw new Error('TON chain is not supported');
|
|
129
|
+
}
|
|
130
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
131
|
+
return contractWrapper.batchFetchClaimed(leafs);
|
|
132
|
+
}
|
|
133
|
+
async getClaimFee(amount) {
|
|
134
|
+
const project = await this.getProjectInfo();
|
|
135
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
136
|
+
return contractWrapper.getClaimFee(project.contractAddress, amount);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
4
139
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/airdrop/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/airdrop/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAW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AM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5C,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,GAAG,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;QAEjE,OAAQ,eAAqC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAAc;QAC9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5C,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;QAEjE,OAAO,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -70,36 +70,17 @@ export declare enum EvmAirdropVersionEnum {
|
|
|
70
70
|
}
|
|
71
71
|
export type IWalletClient = TonConnectUI | ViemWalletClient;
|
|
72
72
|
export type IAirdropService = TonAirdropService | EvmAirdropService;
|
|
73
|
-
|
|
74
|
-
endpoint?: string;
|
|
75
|
-
projectId?: string;
|
|
76
|
-
};
|
|
77
|
-
type BaseTonConfig = {
|
|
73
|
+
type BaseAirdropOptions = {
|
|
78
74
|
endpoint?: string;
|
|
79
75
|
tonClient?: TonClient;
|
|
80
76
|
};
|
|
81
|
-
type
|
|
77
|
+
type ProjectIdOptions = BaseAirdropOptions & {
|
|
82
78
|
projectId: string;
|
|
83
79
|
slug?: never;
|
|
84
80
|
};
|
|
85
|
-
type
|
|
81
|
+
type SlugOptions = BaseAirdropOptions & {
|
|
86
82
|
slug: string;
|
|
87
83
|
projectId?: never;
|
|
88
84
|
};
|
|
89
|
-
export type
|
|
90
|
-
export interface EvmAirdropOptions extends BaseAirdropOptions {
|
|
91
|
-
projectId: string;
|
|
92
|
-
}
|
|
93
|
-
export interface TonContractWrapperOptions {
|
|
94
|
-
chainId: ChainId;
|
|
95
|
-
contractAddress: string;
|
|
96
|
-
walletClient?: TonConnectUI;
|
|
97
|
-
tonClient?: TonClient;
|
|
98
|
-
}
|
|
99
|
-
export interface EvmContractWrapperOptions {
|
|
100
|
-
chainId: ChainId;
|
|
101
|
-
contractAddress: string;
|
|
102
|
-
walletClient?: ViemWalletClient;
|
|
103
|
-
}
|
|
104
|
-
export type ContractWrapperOptions = TonContractWrapperOptions | EvmContractWrapperOptions;
|
|
85
|
+
export type IAirdropOptions = ProjectIdOptions | SlugOptions;
|
|
105
86
|
export {};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AirdropClient } from './airdrop';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AirdropClient } from './airdrop';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -156,17 +156,17 @@ export class AirdropService {
|
|
|
156
156
|
return this.airdropV3FeeClient.getFeelessThreshold();
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
async getClaimFee(address: string,
|
|
159
|
+
async getClaimFee(address: string, amount: bigint): Promise<bigint | undefined> {
|
|
160
160
|
const feeCollector = await this.feeCollectors(this.options.contractAddress as string);
|
|
161
161
|
if (!feeCollector || feeCollector === ZERO_ADDRESS) {
|
|
162
162
|
return undefined;
|
|
163
163
|
}
|
|
164
164
|
const feeClient = this.getFeeClient(feeCollector as string);
|
|
165
|
-
const fee = await feeClient.getFee(address,
|
|
165
|
+
const fee = await feeClient.getFee(address, amount);
|
|
166
166
|
const version = await this.getVersion();
|
|
167
167
|
if (version === AirdropVersionEnum.V3) {
|
|
168
168
|
const threshold = await this.getFeelessThreshold();
|
|
169
|
-
if (BigNumber(Number(
|
|
169
|
+
if (BigNumber(Number(amount)).gt(BigNumber(Number(threshold)))) {
|
|
170
170
|
return fee;
|
|
171
171
|
} else {
|
|
172
172
|
return undefined;
|
|
@@ -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,175 @@
|
|
|
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 { ChainId, ChainType, IAirdropClaim, IAirdropOptions, IProject, IWalletClient } from './types';
|
|
7
|
+
import { getTonProjectIdByAddress } from './common';
|
|
8
|
+
import { WalletClient as ViemWalletClient } from 'viem';
|
|
9
|
+
|
|
10
|
+
export class AirdropClient {
|
|
11
|
+
private tonClient?: TonClient;
|
|
12
|
+
private slug?: string;
|
|
13
|
+
private projectId?: string;
|
|
14
|
+
private endpoint?: string;
|
|
15
|
+
private project: IProject | undefined;
|
|
16
|
+
protected claims?: IAirdropClaim[];
|
|
17
|
+
private contractInstance: TonAirdropService | EvmAirdropService | undefined;
|
|
18
|
+
private projectPromise: Promise<void> | undefined;
|
|
19
|
+
|
|
20
|
+
constructor(params: IAirdropOptions) {
|
|
21
|
+
if ('slug' in params) {
|
|
22
|
+
this.slug = params.slug;
|
|
23
|
+
}
|
|
24
|
+
this.tonClient = params.tonClient;
|
|
25
|
+
this.projectId = params.projectId;
|
|
26
|
+
this.endpoint = params.endpoint;
|
|
27
|
+
this.projectPromise = this.initializeProjects();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected async initializeProjects(address?: string) {
|
|
31
|
+
let projectId: string | undefined = this.projectId;
|
|
32
|
+
if (this.slug) {
|
|
33
|
+
const res = await getAirdropPro(this.slug, this.endpoint);
|
|
34
|
+
const projectMap = res?.childProjectMapping;
|
|
35
|
+
|
|
36
|
+
let legacyProjectId: string | undefined;
|
|
37
|
+
if (!address) {
|
|
38
|
+
legacyProjectId = Object.values(projectMap)[0];
|
|
39
|
+
} else {
|
|
40
|
+
legacyProjectId = getTonProjectIdByAddress({ address, slug: this.slug, data: projectMap });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (legacyProjectId) {
|
|
44
|
+
projectId = legacyProjectId;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!projectId) throw new Error('Project ID is required');
|
|
48
|
+
this.project = await getAirdropProject(projectId, this.endpoint);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getProjectInfo() {
|
|
52
|
+
console.log(this.projectPromise);
|
|
53
|
+
await this.projectPromise;
|
|
54
|
+
if (!this.project) throw new Error('Project not found');
|
|
55
|
+
return this.project;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getAirdropClaims(data: { address: string }) {
|
|
59
|
+
const project = await this.getProjectInfo();
|
|
60
|
+
|
|
61
|
+
const res = await getAirdropQuery(
|
|
62
|
+
{
|
|
63
|
+
recipient: data.address,
|
|
64
|
+
projectId: project!.id,
|
|
65
|
+
recipientType: project!.recipientType
|
|
66
|
+
},
|
|
67
|
+
this.endpoint
|
|
68
|
+
);
|
|
69
|
+
const claimsRes = res.claims?.map((it) => ({
|
|
70
|
+
...it,
|
|
71
|
+
project: project!,
|
|
72
|
+
claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`
|
|
73
|
+
}));
|
|
74
|
+
this.claims = claimsRes;
|
|
75
|
+
return this.claims;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getAirdropContractWrapper(options: {
|
|
79
|
+
walletClient?: IWalletClient;
|
|
80
|
+
tonClient?: TonClient;
|
|
81
|
+
}): Promise<TonAirdropService | EvmAirdropService> {
|
|
82
|
+
if (!this.contractInstance) {
|
|
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
|
+
}
|
|
100
|
+
|
|
101
|
+
return this.contractInstance!;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private getClaimDataById(claimId: string) {
|
|
105
|
+
const claimData = this.claims?.find((it) => it.claimId === claimId);
|
|
106
|
+
if (!claimData) throw new Error('Claim data not found');
|
|
107
|
+
return claimData;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async claimAirdrop(
|
|
111
|
+
{ claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
|
|
112
|
+
options: { onLoading?: () => void }
|
|
113
|
+
) {
|
|
114
|
+
const claimData = this.getClaimDataById(claimId);
|
|
115
|
+
|
|
116
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
117
|
+
walletClient
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return contractWrapper.claim(claimData, options);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async checkClaimed(claimId: string): Promise<boolean> {
|
|
124
|
+
const claimData = this.getClaimDataById(claimId);
|
|
125
|
+
const project = await this.getProjectInfo();
|
|
126
|
+
|
|
127
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
128
|
+
tonClient: this.tonClient
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (project.chainType === ChainType.Evm) {
|
|
132
|
+
return (contractWrapper as EvmAirdropService).isLeafUsed(claimData.leaf);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (contractWrapper as TonAirdropService).checkClaimed(claimData);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async getPaused() {
|
|
139
|
+
const project = await this.getProjectInfo();
|
|
140
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
141
|
+
tonClient: this.tonClient
|
|
142
|
+
});
|
|
143
|
+
if (project.chainType === ChainType.Evm) {
|
|
144
|
+
throw new Error('EVM chain is not supported');
|
|
145
|
+
}
|
|
146
|
+
return (contractWrapper as TonAirdropService).getPaused();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async getVersion() {
|
|
150
|
+
const contractWrapper = await this.getAirdropContractWrapper({
|
|
151
|
+
tonClient: this.tonClient
|
|
152
|
+
});
|
|
153
|
+
return contractWrapper?.getVersion();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async batchFetchClaimed(leafs: string[]) {
|
|
157
|
+
const project = await this.getProjectInfo();
|
|
158
|
+
|
|
159
|
+
if (project.chainType === ChainType.Ton) {
|
|
160
|
+
throw new Error('TON chain is not supported');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
164
|
+
|
|
165
|
+
return (contractWrapper as EvmAirdropService).batchFetchClaimed(leafs);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async getClaimFee(amount: bigint) {
|
|
169
|
+
const project = await this.getProjectInfo();
|
|
170
|
+
|
|
171
|
+
const contractWrapper = await this.getAirdropContractWrapper({});
|
|
172
|
+
|
|
173
|
+
return contractWrapper.getClaimFee(project.contractAddress, amount);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -84,45 +84,19 @@ export type IWalletClient = TonConnectUI | ViemWalletClient;
|
|
|
84
84
|
|
|
85
85
|
export type IAirdropService = TonAirdropService | EvmAirdropService;
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
endpoint?: string;
|
|
89
|
-
projectId?: string;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
type BaseTonConfig = {
|
|
87
|
+
type BaseAirdropOptions = {
|
|
93
88
|
endpoint?: string;
|
|
94
89
|
tonClient?: TonClient;
|
|
95
90
|
};
|
|
96
91
|
|
|
97
|
-
|
|
98
|
-
type TonProjectIdConfig = BaseTonConfig & {
|
|
92
|
+
type ProjectIdOptions = BaseAirdropOptions & {
|
|
99
93
|
projectId: string;
|
|
100
|
-
slug?: never;
|
|
94
|
+
slug?: never;
|
|
101
95
|
};
|
|
102
96
|
|
|
103
|
-
|
|
104
|
-
type TonSlugConfig = BaseTonConfig & {
|
|
97
|
+
type SlugOptions = BaseAirdropOptions & {
|
|
105
98
|
slug: string;
|
|
106
|
-
projectId?: never;
|
|
99
|
+
projectId?: never;
|
|
107
100
|
};
|
|
108
101
|
|
|
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;
|
|
102
|
+
export type IAirdropOptions = ProjectIdOptions | SlugOptions;
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AirdropClient } from './airdrop';
|
|
@@ -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,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtH,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAyB;QAChD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAClC,MAAM,GAAG,GAAG,MAAM,IAAA,0BAAe,EAC/B;gBACE,SAAS,EAAE,IAAI,CAAC,OAAO;gBACvB,SAAS,EAAE,OAAO,CAAC,EAAE;gBACrB,aAAa,EAAE,OAAO,CAAC,aAAa;aACrC,EACD,IAAI,CAAC,QAAQ,CACd,CAAC;YACF,OAAO,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC9B,GAAG,EAAE;gBACL,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,OAAO,CAAC,SAAS,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE;aACxG,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CACH,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CAQF;AA/DD,8CA+DC"}
|
|
@@ -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
|
|
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