@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.
- package/.github/workflows/beta.yml +28 -0
- package/README.md +98 -2
- package/dist/cjs/airdrop/AirdropClient.d.ts +46 -0
- package/dist/cjs/airdrop/AirdropClient.js +251 -0
- package/dist/cjs/airdrop/AirdropClient.js.map +1 -0
- package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +39 -0
- package/dist/cjs/airdrop/SignatureAirdropClient.js +185 -0
- package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -0
- package/dist/cjs/airdrop/common/index.d.ts +1 -1
- package/dist/cjs/airdrop/constants/index.d.ts +4 -0
- package/dist/cjs/airdrop/constants/index.js +5 -1
- package/dist/cjs/airdrop/constants/index.js.map +1 -1
- package/dist/cjs/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
- package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js +71 -0
- package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
- package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
- package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js +47 -0
- package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
- package/dist/cjs/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js +71 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +38 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js +21 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +73 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +10 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +37 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js +14 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +118 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +118 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +29 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js +30 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js +41 -0
- package/dist/cjs/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
- package/dist/cjs/airdrop/index.d.ts +4 -46
- package/dist/cjs/airdrop/index.js +22 -241
- package/dist/cjs/airdrop/index.js.map +1 -1
- package/dist/cjs/airdrop/services/index.d.ts +33 -1
- package/dist/cjs/airdrop/services/index.js +46 -2
- package/dist/cjs/airdrop/services/index.js.map +1 -1
- package/dist/cjs/airdrop/types/index.d.ts +45 -4
- 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 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/api-client.d.ts +1 -0
- package/dist/cjs/utils/api-client.js +2 -2
- package/dist/cjs/utils/api-client.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +2 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/esm/airdrop/AirdropClient.d.ts +46 -0
- package/dist/esm/airdrop/AirdropClient.js +247 -0
- package/dist/esm/airdrop/AirdropClient.js.map +1 -0
- package/dist/esm/airdrop/SignatureAirdropClient.d.ts +39 -0
- package/dist/esm/airdrop/SignatureAirdropClient.js +181 -0
- package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -0
- package/dist/esm/airdrop/common/index.d.ts +1 -1
- package/dist/esm/airdrop/constants/index.d.ts +4 -0
- package/dist/esm/airdrop/constants/index.js +4 -0
- package/dist/esm/airdrop/constants/index.js.map +1 -1
- package/dist/esm/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
- package/dist/esm/airdrop/core/evm/SignatureAirdropService.js +67 -0
- package/dist/esm/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
- package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
- package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js +40 -0
- package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
- package/dist/esm/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.d.ts +32 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js +67 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletBase.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.d.ts +8 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js +34 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/WalletFactory.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.d.ts +2 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js +3 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/index.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +26 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +68 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +10 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +31 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.d.ts +3 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js +5 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/index.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +27 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +108 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +23 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +113 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.d.ts +9 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js +24 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/index.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.d.ts +38 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js +27 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/types.js.map +1 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.d.ts +8 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js +35 -0
- package/dist/esm/airdrop/core/useWeb3ConnectWallet/utils/index.js.map +1 -0
- package/dist/esm/airdrop/index.d.ts +4 -46
- package/dist/esm/airdrop/index.js +4 -239
- package/dist/esm/airdrop/index.js.map +1 -1
- package/dist/esm/airdrop/services/index.d.ts +33 -1
- package/dist/esm/airdrop/services/index.js +40 -1
- package/dist/esm/airdrop/services/index.js.map +1 -1
- package/dist/esm/airdrop/types/index.d.ts +45 -4
- 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 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/api-client.d.ts +1 -0
- package/dist/esm/utils/api-client.js +2 -2
- package/dist/esm/utils/api-client.js.map +1 -1
- package/dist/esm/utils/utils.d.ts +1 -0
- package/dist/esm/utils/utils.js +1 -0
- package/dist/esm/utils/utils.js.map +1 -1
- package/package.json +15 -3
- package/src/airdrop/AirdropClient.ts +307 -0
- package/src/airdrop/SignatureAirdropClient.ts +248 -0
- package/src/airdrop/constants/index.ts +5 -0
- package/src/airdrop/core/evm/SignatureAirdropService.ts +90 -0
- package/src/airdrop/core/evm/contracts/AirdropSignatureClient.ts +56 -0
- package/src/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
- package/src/airdrop/core/useWeb3ConnectWallet/WalletBase.ts +92 -0
- package/src/airdrop/core/useWeb3ConnectWallet/WalletFactory.tsx +35 -0
- package/src/airdrop/core/useWeb3ConnectWallet/index.ts +3 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.ts +93 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/index.tsx +56 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/index.ts +4 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/solana/index.tsx +138 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.ts +153 -0
- package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/index.tsx +41 -0
- package/src/airdrop/core/useWeb3ConnectWallet/types.ts +45 -0
- package/src/airdrop/core/useWeb3ConnectWallet/utils/index.ts +61 -0
- package/src/airdrop/index.ts +4 -304
- package/src/airdrop/services/index.ts +92 -3
- package/src/airdrop/types/index.ts +53 -6
- package/src/index.ts +9 -1
- package/src/utils/api-client.ts +3 -2
- package/src/utils/utils.ts +2 -0
- package/tsconfig.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sign-global/tokentable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-beta.10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -17,14 +17,25 @@
|
|
|
17
17
|
"author": "Evan",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@ethsign/utils-web": "^0.8.9",
|
|
20
21
|
"@orbs-network/ton-access": "^2.3.3",
|
|
22
|
+
"@rainbow-me/rainbowkit": "^2.2.3",
|
|
23
|
+
"@solana/wallet-adapter-react": "^0.15.35",
|
|
24
|
+
"@solana/wallet-adapter-react-ui": "^0.9.35",
|
|
25
|
+
"@solana/wallet-adapter-wallets": "^0.19.32",
|
|
26
|
+
"@solana/web3.js": "^1.98.0",
|
|
21
27
|
"@ton/core": "^0.59.0",
|
|
22
28
|
"@ton/ton": "^15.1.0",
|
|
23
|
-
"@tonconnect/ui
|
|
29
|
+
"@tonconnect/ui": "^2.0.11",
|
|
30
|
+
"@tonconnect/ui-react": "^2.0.11",
|
|
24
31
|
"@types/jest": "^29.5.14",
|
|
25
32
|
"bignumber.js": "^9.1.2",
|
|
33
|
+
"bs58": "^6.0.0",
|
|
26
34
|
"dayjs": "^1.11.13",
|
|
27
35
|
"jest": "^29.7.0",
|
|
36
|
+
"nanoid": "^5.0.9",
|
|
37
|
+
"react": "^18.2.0",
|
|
38
|
+
"ton-core": "^0.53.0",
|
|
28
39
|
"tonapi-sdk-js": "^2.0.3",
|
|
29
40
|
"tonweb": "^0.0.66",
|
|
30
41
|
"ts-jest": "^29.2.5",
|
|
@@ -32,7 +43,8 @@
|
|
|
32
43
|
"wagmi": "^2.13.0"
|
|
33
44
|
},
|
|
34
45
|
"devDependencies": {
|
|
46
|
+
"@types/react": "^18.2.0",
|
|
35
47
|
"bun-types": "latest",
|
|
36
48
|
"typescript": "^5.6.3"
|
|
37
49
|
}
|
|
38
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
import { getAirdropPro, getAirdropProject, getAirdropQuery, getAirdropContractConfig } from './services';
|
|
3
|
+
import {
|
|
4
|
+
ChainType,
|
|
5
|
+
ETokenType,
|
|
6
|
+
EvmAirdropVersionEnum,
|
|
7
|
+
IAirdropClaim,
|
|
8
|
+
IAirdropOptions,
|
|
9
|
+
IContractConfig,
|
|
10
|
+
IProject,
|
|
11
|
+
IWalletClient
|
|
12
|
+
} from './types';
|
|
13
|
+
import { getTonProjectIdByAddress } from './common';
|
|
14
|
+
import { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';
|
|
15
|
+
import { IAirdropStrategy } from './strategies/IAirdropStrategy';
|
|
16
|
+
import { strategyCache } from './strategies/StrategyCache';
|
|
17
|
+
|
|
18
|
+
export class AirdropClient {
|
|
19
|
+
private tonClient?: TonClient;
|
|
20
|
+
private slug?: string;
|
|
21
|
+
private projectId?: string;
|
|
22
|
+
private endpoint?: string;
|
|
23
|
+
private project: IProject | undefined;
|
|
24
|
+
protected claims?: IAirdropClaim[];
|
|
25
|
+
private projectPromise: Promise<void> | undefined;
|
|
26
|
+
private claimHook: ((v: any) => any) | undefined;
|
|
27
|
+
private contractConfig: IContractConfig | null = null;
|
|
28
|
+
|
|
29
|
+
constructor(params: IAirdropOptions) {
|
|
30
|
+
if ('slug' in params) {
|
|
31
|
+
this.slug = params.slug;
|
|
32
|
+
}
|
|
33
|
+
this.projectId = params.projectId;
|
|
34
|
+
this.endpoint = params.endpoint;
|
|
35
|
+
if (this.project) {
|
|
36
|
+
this.project = params.project;
|
|
37
|
+
} else {
|
|
38
|
+
this.projectPromise = this.initializeProjects();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setTonClient(tonClient: TonClient) {
|
|
43
|
+
this.tonClient = tonClient;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private getTonClient(): TonClient | undefined {
|
|
47
|
+
if (!this.tonClient) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return this.tonClient;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {
|
|
54
|
+
if (!this.slug) return undefined;
|
|
55
|
+
|
|
56
|
+
const res = await getAirdropPro(this.slug, this.endpoint);
|
|
57
|
+
const projectMap = res?.childProjectMapping || {};
|
|
58
|
+
|
|
59
|
+
return getTonProjectIdByAddress({
|
|
60
|
+
address,
|
|
61
|
+
slug: this.slug,
|
|
62
|
+
data: projectMap
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private async fetchProjectDetails(projectId: string): Promise<void> {
|
|
67
|
+
this.project = await getAirdropProject(projectId, this.endpoint);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected async initializeProjects(address?: string) {
|
|
71
|
+
try {
|
|
72
|
+
let projectId = this.projectId;
|
|
73
|
+
|
|
74
|
+
// If slug is provided, try to fetch project ID from slug
|
|
75
|
+
if (!projectId) {
|
|
76
|
+
projectId = await this.fetchProjectFromSlug(address);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!projectId) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Fetch project details
|
|
84
|
+
await this.fetchProjectDetails(projectId);
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
throw new Error(`Failed to initialize project: ${error.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getProjectInfo() {
|
|
91
|
+
if (this.projectPromise) {
|
|
92
|
+
await this.projectPromise;
|
|
93
|
+
}
|
|
94
|
+
if (!this.project) throw new Error('Project not found');
|
|
95
|
+
return this.project;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async getAirdropClaims(data: { address: string }) {
|
|
99
|
+
if (this.slug) {
|
|
100
|
+
await this.initializeProjects(data.address); // Fetch project details by address & slug
|
|
101
|
+
}
|
|
102
|
+
const project = await this.getProjectInfo();
|
|
103
|
+
|
|
104
|
+
const res = await getAirdropQuery(
|
|
105
|
+
{
|
|
106
|
+
recipient: data.address,
|
|
107
|
+
projectId: project!.id,
|
|
108
|
+
recipientType: project!.recipientType
|
|
109
|
+
},
|
|
110
|
+
this.endpoint
|
|
111
|
+
);
|
|
112
|
+
const claimsRes = res.claims?.map((it) => ({
|
|
113
|
+
...it,
|
|
114
|
+
project: project!,
|
|
115
|
+
claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`
|
|
116
|
+
}));
|
|
117
|
+
this.claims = claimsRes;
|
|
118
|
+
return this.claims;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {
|
|
122
|
+
const project = await this.getProjectInfo();
|
|
123
|
+
const version = this.contractConfig?.version || undefined;
|
|
124
|
+
|
|
125
|
+
const hasWallet = !!walletClient;
|
|
126
|
+
|
|
127
|
+
// Try to get cached strategy
|
|
128
|
+
let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);
|
|
129
|
+
|
|
130
|
+
if (!strategy) {
|
|
131
|
+
// Create new strategy if not cached
|
|
132
|
+
strategy = AirdropStrategyFactory.createStrategy({
|
|
133
|
+
chainType: project.chainType,
|
|
134
|
+
contractAddress: project.contractAddress,
|
|
135
|
+
chainId: project.chainId,
|
|
136
|
+
walletClient,
|
|
137
|
+
tonClient: this.getTonClient(),
|
|
138
|
+
version
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Initialize the strategy
|
|
142
|
+
await strategy.initialize(walletClient);
|
|
143
|
+
|
|
144
|
+
// Cache the initialized strategy
|
|
145
|
+
strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);
|
|
146
|
+
} else if (hasWallet) {
|
|
147
|
+
// If we have a wallet and the strategy exists, just initialize with the new wallet
|
|
148
|
+
await strategy.initialize(walletClient);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return strategy;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private getClaimDataById(claimId: string) {
|
|
155
|
+
const claimData = this.claims?.find((it) => it.claimId === claimId);
|
|
156
|
+
if (!claimData) throw new Error('Claim data not found');
|
|
157
|
+
return claimData;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
setClaimHook(fn: (v: any) => any) {
|
|
161
|
+
this.claimHook = fn;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private getDefaultExtraData() {
|
|
165
|
+
return {
|
|
166
|
+
isLegacy: true,
|
|
167
|
+
attestationId: BigInt(1)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private async calculateClaimFee(project: IProject, claimAmount: string): Promise<string | bigint | undefined> {
|
|
172
|
+
if (project.chainType === ChainType.Evm) {
|
|
173
|
+
const version = await this.getVersion();
|
|
174
|
+
const isNativeFreeVersion =
|
|
175
|
+
project.tokenType === ETokenType.Native &&
|
|
176
|
+
[EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);
|
|
177
|
+
return isNativeFreeVersion ? undefined : await this.getClaimFee(BigInt(claimAmount));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (project.chainType === ChainType.Ton) {
|
|
181
|
+
return await this.getClaimFee(BigInt(claimAmount));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async claimAirdrop(
|
|
188
|
+
{ claimId, walletClient }: { claimId: string; walletClient: IWalletClient },
|
|
189
|
+
options?: { onLoading?: () => void }
|
|
190
|
+
) {
|
|
191
|
+
// Get claim data and initialize strategy
|
|
192
|
+
const claimData = this.getClaimDataById(claimId);
|
|
193
|
+
const strategy = await this.getStrategy(walletClient);
|
|
194
|
+
const project = await this.getProjectInfo();
|
|
195
|
+
|
|
196
|
+
// Process extra data
|
|
197
|
+
const extraData =
|
|
198
|
+
project.chainType === ChainType.Ton
|
|
199
|
+
? undefined
|
|
200
|
+
: this.claimHook
|
|
201
|
+
? this.claimHook(claimData)
|
|
202
|
+
: this.getDefaultExtraData();
|
|
203
|
+
|
|
204
|
+
// Calculate claim value based on project type
|
|
205
|
+
const value = await this.calculateClaimFee(project, claimData.amount);
|
|
206
|
+
|
|
207
|
+
// Execute claim with processed data
|
|
208
|
+
return strategy.claim(
|
|
209
|
+
{
|
|
210
|
+
...claimData,
|
|
211
|
+
extraData,
|
|
212
|
+
value
|
|
213
|
+
},
|
|
214
|
+
options
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async checkClaimed(claimId: string): Promise<boolean> {
|
|
219
|
+
const claimData = this.getClaimDataById(claimId);
|
|
220
|
+
const strategy = await this.getStrategy();
|
|
221
|
+
return strategy.checkClaimed(claimData);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private async getContractConfig(): Promise<IContractConfig | null> {
|
|
225
|
+
try {
|
|
226
|
+
const project = await this.getProjectInfo();
|
|
227
|
+
|
|
228
|
+
if (!this.contractConfig) {
|
|
229
|
+
this.contractConfig = await getAirdropContractConfig(
|
|
230
|
+
{
|
|
231
|
+
chainId: project.chainId,
|
|
232
|
+
chainType: project.chainType,
|
|
233
|
+
contractAddress: project.contractAddress
|
|
234
|
+
},
|
|
235
|
+
this.endpoint
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return this.contractConfig;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.error('Error fetching contract config:', error);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async getVersion(): Promise<string> {
|
|
246
|
+
const config = await this.getContractConfig();
|
|
247
|
+
if (config?.version) {
|
|
248
|
+
return config.version;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const strategy = await this.getStrategy();
|
|
252
|
+
return strategy.getVersion();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async getPaused(): Promise<boolean> {
|
|
256
|
+
const config = await this.getContractConfig();
|
|
257
|
+
if (config && config?.paused !== null) {
|
|
258
|
+
return config.paused;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const strategy = await this.getStrategy();
|
|
262
|
+
if (!strategy.getPaused) {
|
|
263
|
+
throw new Error('getPaused is not supported for this chain');
|
|
264
|
+
}
|
|
265
|
+
return strategy.getPaused();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async getClaimFee(amount?: bigint): Promise<string | bigint> {
|
|
269
|
+
const config = await this.getContractConfig();
|
|
270
|
+
if (config?.claimFee) {
|
|
271
|
+
return config.claimFee;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const strategy = await this.getStrategy();
|
|
275
|
+
if (!strategy.getClaimFee) {
|
|
276
|
+
throw new Error('getClaimFee is not supported for this chain');
|
|
277
|
+
}
|
|
278
|
+
return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// params claimId[]
|
|
282
|
+
async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {
|
|
283
|
+
const strategy = await this.getStrategy();
|
|
284
|
+
if (!strategy.batchCheckClaimed) {
|
|
285
|
+
throw new Error('batchCheckClaimed is not supported for this chain');
|
|
286
|
+
}
|
|
287
|
+
const leafs = this.claims?.map((it) => it.leaf);
|
|
288
|
+
if (!leafs) return [];
|
|
289
|
+
return strategy.batchCheckClaimed(leafs);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async getNFT(): Promise<string> {
|
|
293
|
+
const strategy = await this.getStrategy();
|
|
294
|
+
if (!strategy.getNFT) {
|
|
295
|
+
throw new Error('getNFT is not supported for this chain');
|
|
296
|
+
}
|
|
297
|
+
return strategy.getNFT();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async getKycThreshold(): Promise<bigint> {
|
|
301
|
+
const strategy = await this.getStrategy();
|
|
302
|
+
if (!strategy.getKycThreshold) {
|
|
303
|
+
throw new Error('getKycThreshold is not supported for this chain');
|
|
304
|
+
}
|
|
305
|
+
return strategy.getKycThreshold();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { getAddress } from 'viem';
|
|
2
|
+
import { CONST } from './constants';
|
|
3
|
+
import { SignatureAirdropService } from './core/evm/SignatureAirdropService';
|
|
4
|
+
import { WalletFactory } from './core/useWeb3ConnectWallet';
|
|
5
|
+
import { ChainType } from './core/useWeb3ConnectWallet/types';
|
|
6
|
+
import {
|
|
7
|
+
bindWallet,
|
|
8
|
+
checkEligibility,
|
|
9
|
+
checkGetSignatures,
|
|
10
|
+
connectTwitter,
|
|
11
|
+
disconnectRecipient,
|
|
12
|
+
getAirdropProject
|
|
13
|
+
} from './services';
|
|
14
|
+
import {
|
|
15
|
+
AirdropSigIdentityTypeEnum,
|
|
16
|
+
ChainId,
|
|
17
|
+
IAirdropOptions,
|
|
18
|
+
IAirdropSignatureClaim,
|
|
19
|
+
IClaimSignature,
|
|
20
|
+
IProject,
|
|
21
|
+
IWalletClient
|
|
22
|
+
} from './types';
|
|
23
|
+
|
|
24
|
+
export class SignatureAirdropClient {
|
|
25
|
+
private projectId?: string;
|
|
26
|
+
private endpoint?: string;
|
|
27
|
+
private project: IProject | undefined;
|
|
28
|
+
protected claims?: IAirdropSignatureClaim[];
|
|
29
|
+
private projectPromise: Promise<void> | undefined;
|
|
30
|
+
constructor(params: IAirdropOptions) {
|
|
31
|
+
this.projectId = params.projectId;
|
|
32
|
+
this.endpoint = params.endpoint;
|
|
33
|
+
if (this.project) {
|
|
34
|
+
this.project = params.project;
|
|
35
|
+
} else {
|
|
36
|
+
this.projectPromise = this.initializeProjects();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private readonly LOCAL_STORAGE_SID_PREFIX = 'sid_';
|
|
41
|
+
|
|
42
|
+
private setSid(projectId: string, sid: string): void {
|
|
43
|
+
window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private async fetchProjectDetails(projectId: string): Promise<void> {
|
|
47
|
+
this.project = await getAirdropProject(projectId, this.endpoint);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected async initializeProjects() {
|
|
51
|
+
try {
|
|
52
|
+
let projectId = this.projectId;
|
|
53
|
+
|
|
54
|
+
if (!projectId) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await this.fetchProjectDetails(projectId);
|
|
59
|
+
} catch (error: any) {
|
|
60
|
+
throw new Error(`Failed to initialize project: ${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async getProjectInfo() {
|
|
65
|
+
if (this.projectPromise) {
|
|
66
|
+
await this.projectPromise;
|
|
67
|
+
}
|
|
68
|
+
if (!this.project) throw new Error('Project not found');
|
|
69
|
+
return this.project;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: () => void }) {
|
|
73
|
+
const project = await this.getProjectInfo();
|
|
74
|
+
const onWindowMessage = async (message: any) => {
|
|
75
|
+
if (message.data.name && message.data.name === CONST.TWITTER_AUTH_SUCCESS) {
|
|
76
|
+
const { code } = message.data.data || {};
|
|
77
|
+
try {
|
|
78
|
+
const res = await connectTwitter({ code, projectId: project.id }, this.endpoint);
|
|
79
|
+
|
|
80
|
+
if (res?.sid) {
|
|
81
|
+
this.setSid(project.id, res?.sid);
|
|
82
|
+
}
|
|
83
|
+
onSuccess();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
onError();
|
|
86
|
+
} finally {
|
|
87
|
+
window.removeEventListener('message', onWindowMessage);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
window.addEventListener('message', onWindowMessage);
|
|
93
|
+
const authorizeUrl = project.identities.find(
|
|
94
|
+
(item: any) => item.identityType === AirdropSigIdentityTypeEnum.Twitter
|
|
95
|
+
)?.authorizeUrl;
|
|
96
|
+
window.open(authorizeUrl + '&state=state', '_blank', 'width=600,height=800');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async connectWallet({
|
|
100
|
+
chainType,
|
|
101
|
+
onSuccess,
|
|
102
|
+
onError
|
|
103
|
+
}: {
|
|
104
|
+
chainType: ChainType;
|
|
105
|
+
onSuccess?: () => void;
|
|
106
|
+
onError?: (error: any) => void;
|
|
107
|
+
}) {
|
|
108
|
+
try {
|
|
109
|
+
const project = await this.getProjectInfo();
|
|
110
|
+
const wallet = WalletFactory.getWallet(chainType);
|
|
111
|
+
await wallet.disconnect();
|
|
112
|
+
const timestamp = Date.now();
|
|
113
|
+
const recipientTypeMap = {
|
|
114
|
+
[ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,
|
|
115
|
+
[ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,
|
|
116
|
+
[ChainType.Ton]: ''
|
|
117
|
+
};
|
|
118
|
+
const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');
|
|
119
|
+
const signResult = await wallet.signin(msg, false);
|
|
120
|
+
|
|
121
|
+
const { message, signature } = signResult || {};
|
|
122
|
+
|
|
123
|
+
const payload = {
|
|
124
|
+
signature: signature as string,
|
|
125
|
+
message: message as string,
|
|
126
|
+
key: wallet.publicKey || wallet.address!,
|
|
127
|
+
projectId: project.id,
|
|
128
|
+
timestamp: timestamp,
|
|
129
|
+
recipientType: recipientTypeMap[chainType]
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const res = await bindWallet(payload, this.endpoint);
|
|
133
|
+
if (res?.sid) {
|
|
134
|
+
this.setSid(project.id, res?.sid);
|
|
135
|
+
}
|
|
136
|
+
onSuccess?.();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
onError?.(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async getClaims() {
|
|
143
|
+
const project = await this.getProjectInfo();
|
|
144
|
+
const res = await checkEligibility(
|
|
145
|
+
{
|
|
146
|
+
projectId: project.id
|
|
147
|
+
},
|
|
148
|
+
this.endpoint
|
|
149
|
+
);
|
|
150
|
+
this.claims = res.claims;
|
|
151
|
+
return res;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public async disconnectIdentity({
|
|
155
|
+
recipientType,
|
|
156
|
+
recipient
|
|
157
|
+
}: {
|
|
158
|
+
recipientType: AirdropSigIdentityTypeEnum;
|
|
159
|
+
recipient?: string;
|
|
160
|
+
}) {
|
|
161
|
+
const project = await this.getProjectInfo();
|
|
162
|
+
return await disconnectRecipient(
|
|
163
|
+
{
|
|
164
|
+
projectId: project.id,
|
|
165
|
+
recipientType,
|
|
166
|
+
recipient
|
|
167
|
+
},
|
|
168
|
+
this.endpoint
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public async getStrategy(walletClient?: IWalletClient): Promise<SignatureAirdropService> {
|
|
173
|
+
const project = await this.getProjectInfo();
|
|
174
|
+
|
|
175
|
+
return new SignatureAirdropService({
|
|
176
|
+
chainId: Number(project.chainId) as ChainId,
|
|
177
|
+
contractAddress: project.contractAddress,
|
|
178
|
+
walletClient: walletClient as any
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async getVersion(): Promise<string> {
|
|
183
|
+
const strategy = await this.getStrategy();
|
|
184
|
+
return strategy.getVersion();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async getClaimFee(amount?: bigint): Promise<undefined | bigint> {
|
|
188
|
+
const strategy = await this.getStrategy();
|
|
189
|
+
if (!strategy.getClaimFee) {
|
|
190
|
+
throw new Error('getClaimFee is not supported for this chain');
|
|
191
|
+
}
|
|
192
|
+
return await strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(1));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async claimAirdrop({
|
|
196
|
+
claimIds,
|
|
197
|
+
walletClient,
|
|
198
|
+
recipient
|
|
199
|
+
}: {
|
|
200
|
+
claimIds: string[];
|
|
201
|
+
walletClient: IWalletClient;
|
|
202
|
+
recipient?: string;
|
|
203
|
+
}) {
|
|
204
|
+
if (!claimIds.length) {
|
|
205
|
+
throw new Error('Claim IDs cannot be empty');
|
|
206
|
+
}
|
|
207
|
+
if (!walletClient) {
|
|
208
|
+
throw new Error('Wallet client is required');
|
|
209
|
+
}
|
|
210
|
+
const service = await this.getStrategy(walletClient);
|
|
211
|
+
const res = await checkGetSignatures(
|
|
212
|
+
{
|
|
213
|
+
claimIds,
|
|
214
|
+
projectId: this.projectId!
|
|
215
|
+
},
|
|
216
|
+
this.endpoint
|
|
217
|
+
);
|
|
218
|
+
const signatureMap = res?.signatures?.reduce((map, item) => {
|
|
219
|
+
map[item.claimId] = item;
|
|
220
|
+
return map;
|
|
221
|
+
}, {} as Record<string, IClaimSignature>);
|
|
222
|
+
const claimData =
|
|
223
|
+
this.claims
|
|
224
|
+
?.filter((it) => claimIds.includes(it.claimId))
|
|
225
|
+
.map((it) => ({
|
|
226
|
+
...it,
|
|
227
|
+
recipient: recipient ? recipient : walletClient.account?.address!,
|
|
228
|
+
...signatureMap?.[it.claimId]
|
|
229
|
+
})) || [];
|
|
230
|
+
const delegateMode = recipient ? getAddress(recipient) !== walletClient.account?.address : false;
|
|
231
|
+
const feeData = (await this.getClaimFee(1n)) || 0n;
|
|
232
|
+
const hash = (await service!.claim(
|
|
233
|
+
claimData,
|
|
234
|
+
delegateMode ? feeData * BigInt(claimData.length) : feeData
|
|
235
|
+
)) as `0x${string}`;
|
|
236
|
+
return hash;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async batchCheckClaimed(): Promise<boolean[]> {
|
|
240
|
+
if (!this.claims?.length) return [];
|
|
241
|
+
const strategy = await this.getStrategy();
|
|
242
|
+
if (!strategy.batchFetchClaimed) {
|
|
243
|
+
throw new Error('batchCheckClaimed is not supported for this chain');
|
|
244
|
+
}
|
|
245
|
+
const claimIds = this.claims?.map((it) => it.claimId);
|
|
246
|
+
return strategy.batchFetchClaimed(claimIds);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ZERO_ADDRESS } from '../../constants';
|
|
2
|
+
import { ChainId, EvmContractClientOption } from '../../types';
|
|
3
|
+
import { AirdropSignatureClient } from './contracts/AirdropSignatureClient';
|
|
4
|
+
import { DeployerClient } from './contracts/DeployClient';
|
|
5
|
+
import { FeeCollectorClient } from './contracts/FeeCollectorClient';
|
|
6
|
+
|
|
7
|
+
export class SignatureAirdropService {
|
|
8
|
+
options: EvmContractClientOption;
|
|
9
|
+
constructor(options: EvmContractClientOption) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private get airdropClient(): AirdropSignatureClient {
|
|
14
|
+
if (!this.options) {
|
|
15
|
+
throw new Error('options is empty');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return new AirdropSignatureClient(this.options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getDeployerClient(): Promise<DeployerClient> {
|
|
22
|
+
const deployer = await this.getDeployer();
|
|
23
|
+
return new DeployerClient({
|
|
24
|
+
...this.options,
|
|
25
|
+
contractAddress: deployer
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private getFeeClient(address: string): FeeCollectorClient {
|
|
30
|
+
if (!this.options) {
|
|
31
|
+
throw new Error('options is empty');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return new FeeCollectorClient({
|
|
35
|
+
...this.options,
|
|
36
|
+
chainId: this.options.chainId as ChainId,
|
|
37
|
+
contractAddress: address
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getDeployer() {
|
|
42
|
+
return this.airdropClient.getDeployer();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getVersion() {
|
|
46
|
+
return this.airdropClient.getVersion();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
feeCollectors = async (address: string) => {
|
|
50
|
+
const deployerClient = await this.getDeployerClient();
|
|
51
|
+
return await deployerClient.feeCollectors(address);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
feeTokens = async (address: string) => {
|
|
55
|
+
const deployerClient = await this.getDeployerClient();
|
|
56
|
+
return await deployerClient.feeTokens(address);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
async getFeelessThreshold() {
|
|
60
|
+
// return this.airdropClient.getFeelessThreshold();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async getClaimFee(address: string, amount: bigint): Promise<bigint | undefined> {
|
|
64
|
+
const feeCollector = await this.feeCollectors(this.options.contractAddress as string);
|
|
65
|
+
if (!feeCollector || feeCollector === ZERO_ADDRESS) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const feeClient = this.getFeeClient(feeCollector as string);
|
|
69
|
+
const fee = (await feeClient.getFee(address, amount)) as bigint;
|
|
70
|
+
return fee;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async batchFetchClaimed(userClaimIds: string[]): Promise<boolean[]> {
|
|
74
|
+
const res = await this.airdropClient.batchFetchClaimed(userClaimIds);
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async claim(
|
|
79
|
+
data: {
|
|
80
|
+
recipient: string;
|
|
81
|
+
claimId: string;
|
|
82
|
+
data: string;
|
|
83
|
+
signature: string;
|
|
84
|
+
extraData?: string;
|
|
85
|
+
}[],
|
|
86
|
+
value?: bigint
|
|
87
|
+
) {
|
|
88
|
+
return this.airdropClient.claim(data, value);
|
|
89
|
+
}
|
|
90
|
+
}
|