@sign-global/tokentable 1.0.0 → 1.1.0
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/CHANGELOG.md +43 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/AirdropClient.ts +13 -5
- package/src/SignatureAirdropClient.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @sign-global/tokentable
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add Ledger wallet support and enhance signing functionality
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @sign-global/tokentable-wallets@1.1.0
|
|
13
|
+
|
|
14
|
+
## 1.0.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @sign-global/tokentable-core@1.1.0
|
|
20
|
+
- @sign-global/tokentable-wallets@1.0.1
|
|
21
|
+
|
|
22
|
+
## 0.0.0-beta-20250625021659
|
|
23
|
+
|
|
24
|
+
### Major Changes
|
|
25
|
+
|
|
26
|
+
- ✨ feat: add beta version script and improve claim fee calculation
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
- @sign-global/tokentable-wallets@0.0.0-beta-20250625021659
|
|
32
|
+
- @sign-global/tokentable-core@0.0.0-beta-20250625021659
|
|
33
|
+
|
|
34
|
+
## 0.0.0-beta-20250624084326
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- ✨ feat: add fee handling for TokenTableMerkleDistributorWithFees
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies
|
|
43
|
+
- @sign-global/tokentable-wallets@0.0.0-beta-20250624084326
|
|
44
|
+
- @sign-global/tokentable-core@0.0.0-beta-20250624084326
|
|
45
|
+
|
|
3
46
|
## 1.0.0
|
|
4
47
|
|
|
5
48
|
### Major Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -45,7 +45,10 @@ declare class AirdropClient {
|
|
|
45
45
|
}): Promise<IAirdropClaim[]>;
|
|
46
46
|
getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy>;
|
|
47
47
|
private getClaimDataById;
|
|
48
|
-
setClaimHook(fn: (
|
|
48
|
+
setClaimHook(fn: (claimData: IAirdropClaim) => {
|
|
49
|
+
isLegacy: boolean;
|
|
50
|
+
attestationId: bigint;
|
|
51
|
+
}): void;
|
|
49
52
|
private getDefaultExtraData;
|
|
50
53
|
private calculateClaimFee;
|
|
51
54
|
claimAirdrop({ claimId, walletClient }: {
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,10 @@ declare class AirdropClient {
|
|
|
45
45
|
}): Promise<IAirdropClaim[]>;
|
|
46
46
|
getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy>;
|
|
47
47
|
private getClaimDataById;
|
|
48
|
-
setClaimHook(fn: (
|
|
48
|
+
setClaimHook(fn: (claimData: IAirdropClaim) => {
|
|
49
|
+
isLegacy: boolean;
|
|
50
|
+
attestationId: bigint;
|
|
51
|
+
}): void;
|
|
49
52
|
private getDefaultExtraData;
|
|
50
53
|
private calculateClaimFee;
|
|
51
54
|
claimAirdrop({ claimId, walletClient }: {
|
package/dist/index.js
CHANGED
|
@@ -401,11 +401,19 @@ var AirdropClient = class {
|
|
|
401
401
|
attestationId: BigInt(1)
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
|
-
async calculateClaimFee(project,
|
|
404
|
+
async calculateClaimFee(project, claimData) {
|
|
405
|
+
const claimAmount = claimData.amount;
|
|
405
406
|
if (project.chainType === import_tokentable_core5.ChainType.Evm) {
|
|
406
407
|
const version = await this.getVersion();
|
|
407
408
|
const isNativeFreeVersion = project.tokenType === import_tokentable_core5.ETokenType.Native && [import_tokentable_core5.EvmAirdropVersionEnum.V3, import_tokentable_core5.EvmAirdropVersionEnum.V4].includes(version);
|
|
408
|
-
|
|
409
|
+
if (isNativeFreeVersion) {
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
if (version.includes("TokenTableMerkleDistributorWithFees")) {
|
|
413
|
+
const fees = claimData.fees;
|
|
414
|
+
return fees ? BigInt(fees) : "0";
|
|
415
|
+
}
|
|
416
|
+
return await this.getClaimFee(BigInt(claimAmount));
|
|
409
417
|
}
|
|
410
418
|
if (project.chainType === import_tokentable_core5.ChainType.Ton) {
|
|
411
419
|
return await this.getClaimFee(BigInt(claimAmount));
|
|
@@ -417,7 +425,7 @@ var AirdropClient = class {
|
|
|
417
425
|
const strategy = await this.getStrategy(walletClient);
|
|
418
426
|
const project = await this.getProjectInfo();
|
|
419
427
|
const extraData = project.chainType === import_tokentable_core5.ChainType.Ton ? void 0 : this.claimHook ? this.claimHook(claimData) : this.getDefaultExtraData();
|
|
420
|
-
const value = await this.calculateClaimFee(project, claimData
|
|
428
|
+
const value = await this.calculateClaimFee(project, claimData);
|
|
421
429
|
return strategy.claim(
|
|
422
430
|
{
|
|
423
431
|
...claimData,
|
|
@@ -659,7 +667,7 @@ var SignatureAirdropClient = class {
|
|
|
659
667
|
const msg = [project.id, recipientTypeMap[chainType], timestamp].join(",");
|
|
660
668
|
const signResult = await wallet.signin(msg, false);
|
|
661
669
|
await wallet.disconnect();
|
|
662
|
-
const { message, signature } = signResult || {};
|
|
670
|
+
const { message, signature, signedMessage } = signResult || {};
|
|
663
671
|
if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {
|
|
664
672
|
onError?.(import_tokentable_core6.ErrorCode.WALLET_ALREADY_CONNECTED);
|
|
665
673
|
return;
|
|
@@ -671,7 +679,8 @@ var SignatureAirdropClient = class {
|
|
|
671
679
|
address: wallet.address,
|
|
672
680
|
projectId: project.id,
|
|
673
681
|
timestamp,
|
|
674
|
-
recipientType: recipientTypeMap[chainType]
|
|
682
|
+
recipientType: recipientTypeMap[chainType],
|
|
683
|
+
encodedMessage: signedMessage
|
|
675
684
|
};
|
|
676
685
|
const res = await (0, import_tokentable_core6.bindWallet)(payload, this.endpoint);
|
|
677
686
|
if (res?.sid) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/AirdropClient.ts","../src/strategies/AirdropStrategyFactory.ts","../src/strategies/EvmAirdropStrategy.ts","../src/strategies/SolanaAirdropStrategy.ts","../src/strategies/TonAirdropStrategy.ts","../src/strategies/StrategyCache.ts","../src/SignatureAirdropClient.ts"],"sourcesContent":["export { AirdropClient } from './AirdropClient';\nexport { SignatureAirdropClient } from './SignatureAirdropClient';\nexport * from '@sign-global/tokentable-core';\nexport * from '@sign-global/tokentable-wallets';\n","import { TonClient } from '@ton/ton';\nimport {\n getAirdropPro,\n getAirdropProject,\n getAirdropQuery,\n getAirdropContractConfig,\n getChainRpc,\n getTonProjectIdByAddress,\n ChainId,\n ChainType,\n ETokenType,\n EvmAirdropVersionEnum,\n IAirdropClaim,\n IAirdropOptions,\n IContractConfig,\n IProject,\n IWalletClient\n} from '@sign-global/tokentable-core';\nimport { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';\nimport { IAirdropStrategy } from './strategies/IAirdropStrategy';\nimport { strategyCache } from './strategies/StrategyCache';\n\nexport class AirdropClient {\n private tonClient?: TonClient;\n private slug?: string;\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n protected chainRpc?: string;\n protected claims?: IAirdropClaim[];\n private projectPromise: Promise<void> | undefined;\n private claimHook: ((v: any) => any) | undefined;\n private contractConfig: IContractConfig | null = null;\n\n constructor(params: IAirdropOptions) {\n if ('slug' in params) {\n this.slug = params.slug;\n }\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n }\n\n setTonClient(tonClient: TonClient) {\n this.tonClient = tonClient;\n }\n\n private getTonClient(): TonClient | undefined {\n if (!this.tonClient) {\n return undefined;\n }\n return this.tonClient;\n }\n\n private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {\n if (!this.slug) return undefined;\n\n const res = await getAirdropPro(this.slug, this.endpoint);\n const projectMap = res?.childProjectMapping || {};\n\n return getTonProjectIdByAddress({\n address,\n slug: this.slug,\n data: projectMap\n });\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects(address?: string) {\n try {\n let projectId = this.projectId;\n\n // If slug is provided, try to fetch project ID from slug\n if (!projectId) {\n projectId = await this.fetchProjectFromSlug(address);\n }\n\n if (!projectId) {\n return;\n }\n\n // Fetch project details\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async getAirdropClaims(data: { address: string }) {\n if (this.slug) {\n await this.initializeProjects(data.address); // Fetch project details by address & slug\n }\n const project = await this.getProjectInfo();\n\n const res = await getAirdropQuery(\n {\n recipient: data.address,\n projectId: project!.id,\n recipientType: project!.recipientType\n },\n this.endpoint\n );\n const claimsRes = res.claims?.map((it) => ({\n ...it,\n project: project!,\n claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`\n }));\n this.claims = claimsRes;\n return this.claims;\n }\n\n public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {\n const project = await this.getProjectInfo();\n const version = this.contractConfig?.version || undefined;\n\n const hasWallet = !!walletClient;\n\n // Try to get cached strategy\n let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);\n\n if (!strategy) {\n // Create new strategy if not cached\n strategy = AirdropStrategyFactory.createStrategy({\n chainType: project.chainType,\n contractAddress: project.contractAddress,\n chainId: project.chainId,\n projectId: project.id,\n walletClient,\n tonClient: this.getTonClient(),\n version,\n chainRpc: this.chainRpc!\n });\n\n // Initialize the strategy\n await strategy.initialize(walletClient);\n\n // Cache the initialized strategy\n strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);\n } else if (hasWallet) {\n // If we have a wallet and the strategy exists, just initialize with the new wallet\n await strategy.initialize(walletClient);\n }\n\n return strategy;\n }\n\n private getClaimDataById(claimId: string) {\n const claimData = this.claims?.find((it) => it.claimId === claimId);\n if (!claimData) throw new Error('Claim data not found');\n return claimData;\n }\n\n setClaimHook(fn: (v: any) => any) {\n this.claimHook = fn;\n }\n\n private getDefaultExtraData() {\n return {\n isLegacy: true,\n attestationId: BigInt(1)\n };\n }\n\n private async calculateClaimFee(project: IProject, claimAmount: string): Promise<string | bigint | undefined> {\n if (project.chainType === ChainType.Evm) {\n const version = await this.getVersion();\n const isNativeFreeVersion =\n project.tokenType === ETokenType.Native &&\n [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);\n return isNativeFreeVersion ? undefined : await this.getClaimFee(BigInt(claimAmount));\n }\n\n if (project.chainType === ChainType.Ton) {\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n return undefined;\n }\n\n async claimAirdrop(\n { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },\n options?: { onLoading?: () => void }\n ) {\n // Get claim data and initialize strategy\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n\n // Process extra data\n const extraData =\n project.chainType === ChainType.Ton\n ? undefined\n : this.claimHook\n ? this.claimHook(claimData)\n : this.getDefaultExtraData();\n\n // Calculate claim value based on project type\n const value = await this.calculateClaimFee(project, claimData.amount);\n\n // Execute claim with processed data\n return strategy.claim(\n {\n ...claimData,\n extraData,\n value\n },\n options\n );\n }\n\n async checkClaimed(claimId: string): Promise<boolean> {\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy();\n return strategy.checkClaimed(claimData);\n }\n\n private async getContractConfig(): Promise<IContractConfig | null> {\n try {\n const project = await this.getProjectInfo();\n\n if (!this.contractConfig && [ChainType.Evm, ChainType.Ton].includes(project.chainType)) {\n this.contractConfig = await getAirdropContractConfig(\n {\n chainId: project.chainId,\n chainType: project.chainType,\n contractAddress: project.contractAddress\n },\n this.endpoint\n );\n }\n return this.contractConfig;\n } catch (error) {\n console.error('Error fetching contract config:', error);\n return null;\n }\n }\n\n async getVersion(): Promise<string> {\n const config = await this.getContractConfig();\n if (config?.version) {\n return config.version;\n }\n\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n async getPaused(): Promise<boolean> {\n const config = await this.getContractConfig();\n if (config && config?.paused !== null) {\n return config.paused;\n }\n\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<string | bigint> {\n const config = await this.getContractConfig();\n if (config?.claimFee) {\n return config.claimFee;\n }\n\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));\n }\n\n // params claimId[]\n async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {\n const strategy = await this.getStrategy();\n if (!strategy.batchCheckClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const leafs = this.claims?.map((it) => it.leaf);\n if (!leafs) return [];\n return strategy.batchCheckClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n const strategy = await this.getStrategy();\n if (!strategy.getNFT) {\n throw new Error('getNFT is not supported for this chain');\n }\n return strategy.getNFT();\n }\n\n async getKycThreshold(): Promise<bigint> {\n const strategy = await this.getStrategy();\n if (!strategy.getKycThreshold) {\n throw new Error('getKycThreshold is not supported for this chain');\n }\n return strategy.getKycThreshold();\n }\n}\n","import { ChainType, IWalletClient } from '@sign-global/tokentable-core';\nimport { EvmAirdropStrategy } from './EvmAirdropStrategy';\nimport { IAirdropStrategy, IAirdropStrategyConstructor } from './IAirdropStrategy';\nimport { SolanaAirdropStrategy } from './SolanaAirdropStrategy';\nimport { TonAirdropStrategy } from './TonAirdropStrategy';\nimport { TonClient } from '@ton/ton';\n\nexport class AirdropStrategyFactory {\n private static strategyMap: Record<ChainType, IAirdropStrategyConstructor | null> = {\n [ChainType.Evm]: EvmAirdropStrategy,\n [ChainType.Ton]: TonAirdropStrategy,\n [ChainType.Solana]: SolanaAirdropStrategy\n };\n\n static createStrategy(params: {\n chainType: ChainType;\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n projectId: string;\n chainRpc: string;\n }): IAirdropStrategy {\n const { chainType, ...strategyParams } = params;\n const StrategyClass = this.strategyMap[chainType];\n\n if (!StrategyClass) {\n throw new Error(`Unsupported chain type: ${chainType}`);\n }\n\n return new StrategyClass(strategyParams);\n }\n}\n","import { EvmAirdropService, ChainId, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\nimport { WalletClient as ViemWalletClient } from 'viem';\n\nexport class EvmAirdropStrategy implements IAirdropStrategy {\n private service: EvmAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: ViemWalletClient;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n chainRpc: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = Number(params.chainId) as ChainId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as ViemWalletClient;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as ViemWalletClient;\n }\n this.service = new EvmAirdropService({\n contractAddress: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n const { proof, group, data, value, extraData } = claimData;\n return this.service.claim({\n proof,\n group,\n data,\n value,\n extraData\n });\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getNFT() as unknown as string;\n }\n\n async getKycThreshold(): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getKycThreshold();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n}\n","import { SolanaAirdropService, ChainId, IWalletClient, SolanaWalletState } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class SolanaAirdropStrategy implements IAirdropStrategy {\n private service: SolanaAirdropService | undefined;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: SolanaWalletState;\n private cachedVersion: string | null = null;\n private projectId: string;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n projectId: string;\n chainRpc: string;\n }) {\n this.chainId = params.chainId as ChainId;\n this.projectId = params.projectId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as SolanaWalletState;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as SolanaWalletState;\n }\n this.service = new SolanaAirdropService({\n projectId: this.projectId,\n chainId: this.chainId as string,\n walletClient: this.walletClient as any,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n}\n","import { TonClient } from '@ton/ton';\nimport { TonConnectUI } from '@tonconnect/ui-react';\nimport { TonAirdropService, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class TonAirdropStrategy implements IAirdropStrategy {\n private service: TonAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: string;\n private readonly tonClient?: TonClient;\n private walletClient?: TonConnectUI;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = params.chainId.toString();\n this.tonClient = params.tonClient;\n if (params.walletClient) {\n this.walletClient = params.walletClient as TonConnectUI;\n }\n if (params.version) {\n this.cachedVersion = params.version;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as TonConnectUI;\n }\n this.service = new TonAirdropService({\n address: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n tonClient: this.tonClient,\n version: this.cachedVersion || undefined\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n if (!this.cachedVersion) {\n this.cachedVersion = await this.service.getVersion();\n }\n return this.cachedVersion;\n }\n\n async claim(claimData: any, options?: { onLoading?: () => void }): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData, options);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.checkClaimed(claimData);\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount);\n }\n}\n","import { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class StrategyCache {\n private readOnlyStrategies: Map<string, IAirdropStrategy> = new Map();\n private walletStrategies: Map<string, IAirdropStrategy> = new Map();\n\n private getCacheKey(contractAddress: string, chainId: string | number, chainType: string): string {\n return `${chainType}:${contractAddress}:${chainId}`;\n }\n\n getStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet: boolean = false): IAirdropStrategy | undefined {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n return cache.get(cacheKey);\n }\n\n setStrategy(contractAddress: string, chainId: string | number, chainType: string, strategy: IAirdropStrategy, hasWallet: boolean = false): void {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n cache.set(cacheKey, strategy);\n }\n\n clearStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet?: boolean): void {\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n if (hasWallet === undefined || hasWallet) {\n this.walletStrategies.delete(cacheKey);\n }\n if (hasWallet === undefined || !hasWallet) {\n this.readOnlyStrategies.delete(cacheKey);\n }\n }\n}\n\nexport const strategyCache = new StrategyCache();\n","import { WalletFactory } from '@sign-global/tokentable-wallets';\nimport {\n bindWallet,\n checkEligibility,\n checkGetSignatures,\n connectGoogleApi,\n connectTwitter,\n disconnectRecipient,\n getAirdropProject,\n cleanUrlParams,\n isMobile,\n getChainRpc,\n CONST,\n EvmSignatureAirdropService,\n SolanaSignatureAirdropService,\n AirdropSigIdentityTypeEnum,\n ChainId,\n ErrorCode,\n IAirdropOptions,\n IAirdropSignatureClaim,\n IAirdropSignatureIdentity,\n IClaimSignature,\n IProject,\n IWalletClient,\n SolanaWalletState,\n ViemWalletClient,\n ChainType\n} from '@sign-global/tokentable-core';\n\nexport class SignatureAirdropClient {\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n private chainRpc?: string;\n protected claims?: IAirdropSignatureClaim[];\n protected identities?: IAirdropSignatureIdentity[];\n private projectPromise: Promise<void> | undefined;\n private authPromise: Promise<void> | undefined;\n private strategyCache: Map<string, EvmSignatureAirdropService | SolanaSignatureAirdropService> = new Map();\n constructor(params: IAirdropOptions) {\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n if (isMobile()) {\n this.authPromise = this.checkAndHandleTwitterCode();\n }\n }\n\n private readonly LOCAL_STORAGE_SID_PREFIX = 'sid_';\n\n private async checkAndHandleTwitterCode() {\n try {\n const urlParams = new URLSearchParams(window.location.search);\n const code = urlParams.get('code');\n const type = urlParams.get('type');\n\n if (code && this.projectId) {\n let res;\n if (type === 'twitter') {\n res = await connectTwitter({ code, projectId: this.projectId }, this.endpoint);\n } else if (type === 'google') {\n res = await connectGoogleApi({ code, projectId: this.projectId }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(this.projectId!, res.sid);\n } else {\n throw new Error('Failed to connect');\n }\n cleanUrlParams(['code', 'type']);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n private setSid(projectId: string, sid: string): void {\n window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects() {\n try {\n let projectId = this.projectId;\n if (!projectId) {\n return;\n }\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async connectOAuth({\n onSuccess,\n onError,\n type\n }: {\n onSuccess: () => void;\n onError: (error: Error) => void;\n type: AirdropSigIdentityTypeEnum;\n }) {\n const project = await this.getProjectInfo();\n const authorizeUrl = project.identities.find((item: any) => item.identityType === type)?.authorizeUrl;\n if (!authorizeUrl) {\n onError(new Error('Authorize URL not found'));\n return;\n }\n if (isMobile()) {\n const state = encodeURIComponent(window.location.href);\n window.location.href = `${authorizeUrl}&state=${state}`;\n return;\n }\n const onWindowMessage = async (message: any) => {\n const name = message.data?.name;\n if (name && [CONST.TWITTER_AUTH_SUCCESS, CONST.GOOGLE_AUTH_SUCCESS].includes(name)) {\n const { code } = message.data.data || {};\n try {\n let res;\n if (name === CONST.GOOGLE_AUTH_SUCCESS) {\n res = await connectGoogleApi({ code, projectId: project.id }, this.endpoint);\n } else if (name === CONST.TWITTER_AUTH_SUCCESS) {\n res = await connectTwitter({ code, projectId: project.id }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n onSuccess();\n } else {\n onError(new Error('Failed to connect'));\n }\n } catch (error) {\n onError(error as Error);\n } finally {\n window.removeEventListener('message', onWindowMessage);\n }\n }\n };\n\n window.addEventListener('message', onWindowMessage);\n window.open(`${authorizeUrl}&state=state`, `twitter_auth_${project.id}`, 'width=600,height=800');\n }\n\n async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Twitter\n });\n }\n\n async connectGoogle({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Google\n });\n }\n\n async connectWallet({\n chainType,\n onSuccess,\n onError\n }: {\n chainType: ChainType;\n onSuccess?: (address: string) => void;\n onError?: (error: any) => void;\n }) {\n try {\n const project = await this.getProjectInfo();\n const wallet = WalletFactory.getWallet(chainType);\n const timestamp = Date.now();\n const recipientTypeMap = {\n [ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,\n [ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,\n [ChainType.Ton]: AirdropSigIdentityTypeEnum.TONWallet\n };\n const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');\n const signResult = await wallet.signin(msg, false);\n await wallet.disconnect();\n const { message, signature } = signResult || {};\n\n if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {\n onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);\n return;\n }\n\n const payload = {\n signature: signature as string,\n message: message as string,\n key: wallet.publicKey || wallet.address!,\n address: wallet.address!,\n projectId: project.id,\n timestamp: timestamp,\n recipientType: recipientTypeMap[chainType]\n };\n\n const res = await bindWallet(payload, this.endpoint);\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n }\n onSuccess?.(wallet.address!);\n } catch (error) {\n onError?.(error);\n }\n }\n\n async getClaims() {\n const project = await this.getProjectInfo();\n if (this.authPromise) {\n await this.authPromise;\n }\n const res = await checkEligibility(\n {\n projectId: project.id\n },\n this.endpoint\n );\n this.claims = res.claims;\n this.identities = res.identities;\n return res;\n }\n\n public async disconnectIdentity({\n recipientType,\n recipient\n }: {\n recipientType: AirdropSigIdentityTypeEnum;\n recipient?: string;\n }) {\n const project = await this.getProjectInfo();\n return await disconnectRecipient(\n {\n projectId: project.id,\n recipientType,\n recipient\n },\n this.endpoint\n );\n }\n\n public async getStrategy(\n walletClient?: IWalletClient\n ): Promise<EvmSignatureAirdropService | SolanaSignatureAirdropService> {\n const project = await this.getProjectInfo();\n\n const cacheKey = walletClient\n ? project.chainType === ChainType.Evm\n ? (walletClient as ViemWalletClient).account?.address!\n : project.chainType === ChainType.Solana\n ? (walletClient as SolanaWalletState).publicKey!.toString()\n : 'walletClient'\n : 'default';\n if (this.strategyCache.has(cacheKey)) {\n return this.strategyCache.get(cacheKey)!;\n }\n\n const strategy =\n project.chainType === ChainType.Solana\n ? new SolanaSignatureAirdropService({\n chainId: project.chainId,\n projectId: project.id,\n token: project.tokenAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n })\n : new EvmSignatureAirdropService({\n chainId: Number(project.chainId) as ChainId,\n contractAddress: project.contractAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n });\n this.strategyCache.set(cacheKey, strategy);\n return strategy;\n }\n\n async getVersion(): Promise<string> {\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n // solana prams need to wallet\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<undefined | bigint> {\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return await strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(1));\n }\n\n async claimAirdrop({\n claimIds,\n walletClient,\n recipient\n }: {\n claimIds: string[];\n walletClient: IWalletClient;\n recipient: string;\n }) {\n if (!claimIds.length) {\n throw new Error('Claim IDs cannot be empty');\n }\n if (!walletClient) {\n throw new Error('Wallet client is required');\n }\n if (!this.claims?.length) {\n throw new Error('No claims available');\n }\n const service = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n const res = await checkGetSignatures(\n {\n claimIds,\n projectId: this.projectId!,\n recipient\n },\n this.endpoint\n );\n if (!res?.signatures?.length) {\n throw new Error('Failed to get signatures');\n }\n const signatureMap = res?.signatures?.reduce(\n (map, item) => {\n map[item.claimId] = item;\n return map;\n },\n {} as Record<string, IClaimSignature>\n );\n const filteredClaims = this.claims.filter((it) => claimIds.includes(it.claimId));\n if (!filteredClaims.length) {\n throw new Error('No matching claims found');\n }\n\n // only evm use\n const defaultRecipient =\n project.chainType === ChainType.Evm ? (walletClient as ViemWalletClient).account?.address! : '';\n\n const claimData = filteredClaims.map((it) => {\n const signature = signatureMap[it.claimId];\n if (!signature) {\n throw new Error(`Signature not found for claim ID: ${it.claimId}`);\n }\n\n return {\n ...it,\n recipient: recipient ? recipient : defaultRecipient,\n ...signature\n };\n });\n\n const hash = (await service!.claim(claimData, recipient)) as `0x${string}`;\n return hash;\n }\n\n async batchCheckClaimed(): Promise<boolean[]> {\n if (!this.claims?.length) return [];\n const strategy = await this.getStrategy();\n if (!strategy.batchFetchClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const claimIds = this.claims?.map((it) => it.claimId);\n return strategy.batchFetchClaimed(claimIds);\n }\n\n async getPaused(): Promise<boolean> {\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,0BAgBO;;;ACjBP,IAAAC,0BAAyC;;;ACAzC,6BAA0D;AAInD,IAAM,qBAAN,MAAqD;AAAA,EAClD;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EACA,gBAA+B;AAAA,EAEvC,YAAY,QAKT;AACD,SAAK,kBAAkB,OAAO;AAC9B,SAAK,UAAU,OAAO,OAAO,OAAO;AACpC,SAAK,WAAW,OAAO;AACvB,QAAI,OAAO,cAAc;AACvB,WAAK,eAAe,OAAO;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,cAA6C;AAC5D,QAAI,cAAc;AAChB,WAAK,eAAe;AAAA,IACtB;AACA,SAAK,UAAU,IAAI,yCAAkB;AAAA,MACnC,iBAAiB,KAAK;AAAA,MACtB,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,UAAU,KAAK;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,gBAAyB;AACvB,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA,EAEA,MAAM,aAA8B;AAClC,QAAI,KAAK,eAAe;AACtB,aAAO,KAAK;AAAA,IACd;AACA,QAAI,CAAC,KAAK,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAC7D,SAAK,gBAAgB,MAAM,KAAK,QAAQ,WAAW;AACnD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,MAAM,WAA8B;AACxC,QAAI,CAAC,KAAK,QAAS,OAAM,I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AACd,cAAM,IAAI,MAAM,qCAAqC,GAAG,OAAO,EAAE;AAAA,MACnE;AAEA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW,YAAY,YAAY;AAAA,QACnC,GAAG;AAAA,MACL;AAAA,IACF,CAAC;AAED,UAAM,OAAQ,MAAM,QAAS,MAAM,WAAW,SAAS;AACvD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,oBAAwC;AAC5C,QAAI,CAAC,KAAK,QAAQ,OAAQ,QAAO,CAAC;AAClC,UAAM,WAAW,MAAM,KAAK,YAAY;AACxC,QAAI,CAAC,SAAS,mBAAmB;AAC/B,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AACA,UAAM,WAAW,KAAK,QAAQ,IAAI,CAAC,OAAO,GAAG,OAAO;AACpD,WAAO,SAAS,kBAAkB,QAAQ;AAAA,EAC5C;AAAA,EAEA,MAAM,YAA8B;AAClC,UAAM,WAAW,MAAM,KAAK,YAAY;AACxC,QAAI,CAAC,SAAS,WAAW;AACvB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AACA,WAAO,SAAS,UAAU;AAAA,EAC5B;AACF;;;APnYA,0BAAc,yCAFd;AAGA,0BAAc,4CAHd;","names":["import_tokentable_core","import_tokentable_core","import_tokentable_core","import_tokentable_core","import_tokentable_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/AirdropClient.ts","../src/strategies/AirdropStrategyFactory.ts","../src/strategies/EvmAirdropStrategy.ts","../src/strategies/SolanaAirdropStrategy.ts","../src/strategies/TonAirdropStrategy.ts","../src/strategies/StrategyCache.ts","../src/SignatureAirdropClient.ts"],"sourcesContent":["export { AirdropClient } from './AirdropClient';\nexport { SignatureAirdropClient } from './SignatureAirdropClient';\nexport * from '@sign-global/tokentable-core';\nexport * from '@sign-global/tokentable-wallets';\n","import { TonClient } from '@ton/ton';\nimport {\n getAirdropPro,\n getAirdropProject,\n getAirdropQuery,\n getAirdropContractConfig,\n getChainRpc,\n getTonProjectIdByAddress,\n ChainId,\n ChainType,\n ETokenType,\n EvmAirdropVersionEnum,\n IAirdropClaim,\n IAirdropOptions,\n IContractConfig,\n IProject,\n IWalletClient\n} from '@sign-global/tokentable-core';\nimport { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';\nimport { IAirdropStrategy } from './strategies/IAirdropStrategy';\nimport { strategyCache } from './strategies/StrategyCache';\n\nexport class AirdropClient {\n private tonClient?: TonClient;\n private slug?: string;\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n protected chainRpc?: string;\n protected claims?: IAirdropClaim[];\n private projectPromise: Promise<void> | undefined;\n private claimHook: ((claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) | undefined;\n private contractConfig: IContractConfig | null = null;\n\n constructor(params: IAirdropOptions) {\n if ('slug' in params) {\n this.slug = params.slug;\n }\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n }\n\n setTonClient(tonClient: TonClient) {\n this.tonClient = tonClient;\n }\n\n private getTonClient(): TonClient | undefined {\n if (!this.tonClient) {\n return undefined;\n }\n return this.tonClient;\n }\n\n private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {\n if (!this.slug) return undefined;\n\n const res = await getAirdropPro(this.slug, this.endpoint);\n const projectMap = res?.childProjectMapping || {};\n\n return getTonProjectIdByAddress({\n address,\n slug: this.slug,\n data: projectMap\n });\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects(address?: string) {\n try {\n let projectId = this.projectId;\n\n // If slug is provided, try to fetch project ID from slug\n if (!projectId) {\n projectId = await this.fetchProjectFromSlug(address);\n }\n\n if (!projectId) {\n return;\n }\n\n // Fetch project details\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async getAirdropClaims(data: { address: string }) {\n if (this.slug) {\n await this.initializeProjects(data.address); // Fetch project details by address & slug\n }\n const project = await this.getProjectInfo();\n\n const res = await getAirdropQuery(\n {\n recipient: data.address,\n projectId: project!.id,\n recipientType: project!.recipientType\n },\n this.endpoint\n );\n const claimsRes = res.claims?.map((it) => ({\n ...it,\n project: project!,\n claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`\n }));\n this.claims = claimsRes;\n return this.claims;\n }\n\n public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {\n const project = await this.getProjectInfo();\n const version = this.contractConfig?.version || undefined;\n\n const hasWallet = !!walletClient;\n\n // Try to get cached strategy\n let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);\n\n if (!strategy) {\n // Create new strategy if not cached\n strategy = AirdropStrategyFactory.createStrategy({\n chainType: project.chainType,\n contractAddress: project.contractAddress,\n chainId: project.chainId,\n projectId: project.id,\n walletClient,\n tonClient: this.getTonClient(),\n version,\n chainRpc: this.chainRpc!\n });\n\n // Initialize the strategy\n await strategy.initialize(walletClient);\n\n // Cache the initialized strategy\n strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);\n } else if (hasWallet) {\n // If we have a wallet and the strategy exists, just initialize with the new wallet\n await strategy.initialize(walletClient);\n }\n\n return strategy;\n }\n\n private getClaimDataById(claimId: string) {\n const claimData = this.claims?.find((it) => it.claimId === claimId);\n if (!claimData) throw new Error('Claim data not found');\n return claimData;\n }\n\n setClaimHook(fn: (claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) {\n this.claimHook = fn;\n }\n\n private getDefaultExtraData() {\n return {\n isLegacy: true,\n attestationId: BigInt(1)\n };\n }\n\n private async calculateClaimFee(project: IProject, claimData: IAirdropClaim): Promise<string | bigint | undefined> {\n const claimAmount = claimData.amount;\n if (project.chainType === ChainType.Evm) {\n const version = await this.getVersion();\n const isNativeFreeVersion =\n project.tokenType === ETokenType.Native &&\n [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);\n if (isNativeFreeVersion) {\n return undefined;\n }\n if (version.includes('TokenTableMerkleDistributorWithFees')) {\n const fees = claimData.fees;\n return fees ? BigInt(fees) : '0';\n }\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n if (project.chainType === ChainType.Ton) {\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n return undefined;\n }\n\n async claimAirdrop(\n { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },\n options?: { onLoading?: () => void }\n ) {\n // Get claim data and initialize strategy\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n\n // Process extra data\n const extraData =\n project.chainType === ChainType.Ton\n ? undefined\n : this.claimHook\n ? this.claimHook(claimData)\n : this.getDefaultExtraData();\n\n // Calculate claim value based on project type\n const value = await this.calculateClaimFee(project, claimData);\n\n // Execute claim with processed data\n return strategy.claim(\n {\n ...claimData,\n extraData,\n value\n },\n options\n );\n }\n\n async checkClaimed(claimId: string): Promise<boolean> {\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy();\n return strategy.checkClaimed(claimData);\n }\n\n private async getContractConfig(): Promise<IContractConfig | null> {\n try {\n const project = await this.getProjectInfo();\n\n if (!this.contractConfig && [ChainType.Evm, ChainType.Ton].includes(project.chainType)) {\n this.contractConfig = await getAirdropContractConfig(\n {\n chainId: project.chainId,\n chainType: project.chainType,\n contractAddress: project.contractAddress\n },\n this.endpoint\n );\n }\n return this.contractConfig;\n } catch (error) {\n console.error('Error fetching contract config:', error);\n return null;\n }\n }\n\n async getVersion(): Promise<string> {\n const config = await this.getContractConfig();\n if (config?.version) {\n return config.version;\n }\n\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n async getPaused(): Promise<boolean> {\n const config = await this.getContractConfig();\n if (config && config?.paused !== null) {\n return config.paused;\n }\n\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<string | bigint> {\n const config = await this.getContractConfig();\n if (config?.claimFee) {\n return config.claimFee;\n }\n\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));\n }\n\n // params claimId[]\n async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {\n const strategy = await this.getStrategy();\n if (!strategy.batchCheckClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const leafs = this.claims?.map((it) => it.leaf);\n if (!leafs) return [];\n return strategy.batchCheckClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n const strategy = await this.getStrategy();\n if (!strategy.getNFT) {\n throw new Error('getNFT is not supported for this chain');\n }\n return strategy.getNFT();\n }\n\n async getKycThreshold(): Promise<bigint> {\n const strategy = await this.getStrategy();\n if (!strategy.getKycThreshold) {\n throw new Error('getKycThreshold is not supported for this chain');\n }\n return strategy.getKycThreshold();\n }\n}\n","import { ChainType, IWalletClient } from '@sign-global/tokentable-core';\nimport { EvmAirdropStrategy } from './EvmAirdropStrategy';\nimport { IAirdropStrategy, IAirdropStrategyConstructor } from './IAirdropStrategy';\nimport { SolanaAirdropStrategy } from './SolanaAirdropStrategy';\nimport { TonAirdropStrategy } from './TonAirdropStrategy';\nimport { TonClient } from '@ton/ton';\n\nexport class AirdropStrategyFactory {\n private static strategyMap: Record<ChainType, IAirdropStrategyConstructor | null> = {\n [ChainType.Evm]: EvmAirdropStrategy,\n [ChainType.Ton]: TonAirdropStrategy,\n [ChainType.Solana]: SolanaAirdropStrategy\n };\n\n static createStrategy(params: {\n chainType: ChainType;\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n projectId: string;\n chainRpc: string;\n }): IAirdropStrategy {\n const { chainType, ...strategyParams } = params;\n const StrategyClass = this.strategyMap[chainType];\n\n if (!StrategyClass) {\n throw new Error(`Unsupported chain type: ${chainType}`);\n }\n\n return new StrategyClass(strategyParams);\n }\n}\n","import { EvmAirdropService, ChainId, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\nimport { WalletClient as ViemWalletClient } from 'viem';\n\nexport class EvmAirdropStrategy implements IAirdropStrategy {\n private service: EvmAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: ViemWalletClient;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n chainRpc: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = Number(params.chainId) as ChainId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as ViemWalletClient;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as ViemWalletClient;\n }\n this.service = new EvmAirdropService({\n contractAddress: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n const { proof, group, data, value, extraData } = claimData;\n return this.service.claim({\n proof,\n group,\n data,\n value,\n extraData\n });\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getNFT() as unknown as string;\n }\n\n async getKycThreshold(): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getKycThreshold();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n}\n","import { SolanaAirdropService, ChainId, IWalletClient, SolanaWalletState } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class SolanaAirdropStrategy implements IAirdropStrategy {\n private service: SolanaAirdropService | undefined;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: SolanaWalletState;\n private cachedVersion: string | null = null;\n private projectId: string;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n projectId: string;\n chainRpc: string;\n }) {\n this.chainId = params.chainId as ChainId;\n this.projectId = params.projectId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as SolanaWalletState;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as SolanaWalletState;\n }\n this.service = new SolanaAirdropService({\n projectId: this.projectId,\n chainId: this.chainId as string,\n walletClient: this.walletClient as any,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n}\n","import { TonClient } from '@ton/ton';\nimport { TonConnectUI } from '@tonconnect/ui-react';\nimport { TonAirdropService, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class TonAirdropStrategy implements IAirdropStrategy {\n private service: TonAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: string;\n private readonly tonClient?: TonClient;\n private walletClient?: TonConnectUI;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = params.chainId.toString();\n this.tonClient = params.tonClient;\n if (params.walletClient) {\n this.walletClient = params.walletClient as TonConnectUI;\n }\n if (params.version) {\n this.cachedVersion = params.version;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as TonConnectUI;\n }\n this.service = new TonAirdropService({\n address: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n tonClient: this.tonClient,\n version: this.cachedVersion || undefined\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n if (!this.cachedVersion) {\n this.cachedVersion = await this.service.getVersion();\n }\n return this.cachedVersion;\n }\n\n async claim(claimData: any, options?: { onLoading?: () => void }): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData, options);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.checkClaimed(claimData);\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount);\n }\n}\n","import { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class StrategyCache {\n private readOnlyStrategies: Map<string, IAirdropStrategy> = new Map();\n private walletStrategies: Map<string, IAirdropStrategy> = new Map();\n\n private getCacheKey(contractAddress: string, chainId: string | number, chainType: string): string {\n return `${chainType}:${contractAddress}:${chainId}`;\n }\n\n getStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet: boolean = false): IAirdropStrategy | undefined {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n return cache.get(cacheKey);\n }\n\n setStrategy(contractAddress: string, chainId: string | number, chainType: string, strategy: IAirdropStrategy, hasWallet: boolean = false): void {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n cache.set(cacheKey, strategy);\n }\n\n clearStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet?: boolean): void {\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n if (hasWallet === undefined || hasWallet) {\n this.walletStrategies.delete(cacheKey);\n }\n if (hasWallet === undefined || !hasWallet) {\n this.readOnlyStrategies.delete(cacheKey);\n }\n }\n}\n\nexport const strategyCache = new StrategyCache();\n","import { WalletFactory } from '@sign-global/tokentable-wallets';\nimport {\n bindWallet,\n checkEligibility,\n checkGetSignatures,\n connectGoogleApi,\n connectTwitter,\n disconnectRecipient,\n getAirdropProject,\n cleanUrlParams,\n isMobile,\n getChainRpc,\n CONST,\n EvmSignatureAirdropService,\n SolanaSignatureAirdropService,\n AirdropSigIdentityTypeEnum,\n ChainId,\n ErrorCode,\n IAirdropOptions,\n IAirdropSignatureClaim,\n IAirdropSignatureIdentity,\n IClaimSignature,\n IProject,\n IWalletClient,\n SolanaWalletState,\n ViemWalletClient,\n ChainType\n} from '@sign-global/tokentable-core';\n\nexport class SignatureAirdropClient {\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n private chainRpc?: string;\n protected claims?: IAirdropSignatureClaim[];\n protected identities?: IAirdropSignatureIdentity[];\n private projectPromise: Promise<void> | undefined;\n private authPromise: Promise<void> | undefined;\n private strategyCache: Map<string, EvmSignatureAirdropService | SolanaSignatureAirdropService> = new Map();\n constructor(params: IAirdropOptions) {\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n if (isMobile()) {\n this.authPromise = this.checkAndHandleTwitterCode();\n }\n }\n\n private readonly LOCAL_STORAGE_SID_PREFIX = 'sid_';\n\n private async checkAndHandleTwitterCode() {\n try {\n const urlParams = new URLSearchParams(window.location.search);\n const code = urlParams.get('code');\n const type = urlParams.get('type');\n\n if (code && this.projectId) {\n let res;\n if (type === 'twitter') {\n res = await connectTwitter({ code, projectId: this.projectId }, this.endpoint);\n } else if (type === 'google') {\n res = await connectGoogleApi({ code, projectId: this.projectId }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(this.projectId!, res.sid);\n } else {\n throw new Error('Failed to connect');\n }\n cleanUrlParams(['code', 'type']);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n private setSid(projectId: string, sid: string): void {\n window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects() {\n try {\n let projectId = this.projectId;\n if (!projectId) {\n return;\n }\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async connectOAuth({\n onSuccess,\n onError,\n type\n }: {\n onSuccess: () => void;\n onError: (error: Error) => void;\n type: AirdropSigIdentityTypeEnum;\n }) {\n const project = await this.getProjectInfo();\n const authorizeUrl = project.identities.find((item: any) => item.identityType === type)?.authorizeUrl;\n if (!authorizeUrl) {\n onError(new Error('Authorize URL not found'));\n return;\n }\n if (isMobile()) {\n const state = encodeURIComponent(window.location.href);\n window.location.href = `${authorizeUrl}&state=${state}`;\n return;\n }\n const onWindowMessage = async (message: any) => {\n const name = message.data?.name;\n if (name && [CONST.TWITTER_AUTH_SUCCESS, CONST.GOOGLE_AUTH_SUCCESS].includes(name)) {\n const { code } = message.data.data || {};\n try {\n let res;\n if (name === CONST.GOOGLE_AUTH_SUCCESS) {\n res = await connectGoogleApi({ code, projectId: project.id }, this.endpoint);\n } else if (name === CONST.TWITTER_AUTH_SUCCESS) {\n res = await connectTwitter({ code, projectId: project.id }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n onSuccess();\n } else {\n onError(new Error('Failed to connect'));\n }\n } catch (error) {\n onError(error as Error);\n } finally {\n window.removeEventListener('message', onWindowMessage);\n }\n }\n };\n\n window.addEventListener('message', onWindowMessage);\n window.open(`${authorizeUrl}&state=state`, `twitter_auth_${project.id}`, 'width=600,height=800');\n }\n\n async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Twitter\n });\n }\n\n async connectGoogle({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Google\n });\n }\n\n async connectWallet({\n chainType,\n onSuccess,\n onError\n }: {\n chainType: ChainType;\n onSuccess?: (address: string) => void;\n onError?: (error: any) => void;\n }) {\n try {\n const project = await this.getProjectInfo();\n const wallet = WalletFactory.getWallet(chainType);\n const timestamp = Date.now();\n const recipientTypeMap = {\n [ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,\n [ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,\n [ChainType.Ton]: AirdropSigIdentityTypeEnum.TONWallet\n };\n const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');\n const signResult = await wallet.signin(msg, false);\n await wallet.disconnect();\n const { message, signature, signedMessage } = signResult || {};\n\n if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {\n onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);\n return;\n }\n\n const payload = {\n signature: signature as string,\n message: message as string,\n key: wallet.publicKey || wallet.address!,\n address: wallet.address!,\n projectId: project.id,\n timestamp: timestamp,\n recipientType: recipientTypeMap[chainType],\n encodedMessage: signedMessage\n };\n\n const res = await bindWallet(payload, this.endpoint);\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n }\n onSuccess?.(wallet.address!);\n } catch (error) {\n onError?.(error);\n }\n }\n\n async getClaims() {\n const project = await this.getProjectInfo();\n if (this.authPromise) {\n await this.authPromise;\n }\n const res = await checkEligibility(\n {\n projectId: project.id\n },\n this.endpoint\n );\n this.claims = res.claims;\n this.identities = res.identities;\n return res;\n }\n\n public async disconnectIdentity({\n recipientType,\n recipient\n }: {\n recipientType: AirdropSigIdentityTypeEnum;\n recipient?: string;\n }) {\n const project = await this.getProjectInfo();\n return await disconnectRecipient(\n {\n projectId: project.id,\n recipientType,\n recipient\n },\n this.endpoint\n );\n }\n\n public async getStrategy(\n walletClient?: IWalletClient\n ): Promise<EvmSignatureAirdropService | SolanaSignatureAirdropService> {\n const project = await this.getProjectInfo();\n\n const cacheKey = walletClient\n ? project.chainType === ChainType.Evm\n ? (walletClient as ViemWalletClient).account?.address!\n : project.chainType === ChainType.Solana\n ? (walletClient as SolanaWalletState).publicKey!.toString()\n : 'walletClient'\n : 'default';\n if (this.strategyCache.has(cacheKey)) {\n return this.strategyCache.get(cacheKey)!;\n }\n\n const strategy =\n project.chainType === ChainType.Solana\n ? new SolanaSignatureAirdropService({\n chainId: project.chainId,\n projectId: project.id,\n token: project.tokenAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n })\n : new EvmSignatureAirdropService({\n chainId: Number(project.chainId) as ChainId,\n contractAddress: project.contractAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n });\n this.strategyCache.set(cacheKey, strategy);\n return strategy;\n }\n\n async getVersion(): Promise<string> {\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n // solana prams need to wallet\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<undefined | bigint> {\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return await strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(1));\n }\n\n async claimAirdrop({\n claimIds,\n walletClient,\n recipient\n }: {\n claimIds: string[];\n walletClient: IWalletClient;\n recipient: string;\n }) {\n if (!claimIds.length) {\n throw new Error('Claim IDs cannot be empty');\n }\n if (!walletClient) {\n throw new Error('Wallet client is required');\n }\n if (!this.claims?.length) {\n throw new Error('No claims available');\n }\n const service = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n const res = await checkGetSignatures(\n {\n claimIds,\n projectId: this.projectId!,\n recipient\n },\n this.endpoint\n );\n if (!res?.signatures?.length) {\n throw new Error('Failed to get signatures');\n }\n const signatureMap = res?.signatures?.reduce(\n (map, item) => {\n map[item.claimId] = item;\n return map;\n },\n {} as Record<string, IClaimSignature>\n );\n const filteredClaims = this.claims.filter((it) => claimIds.includes(it.claimId));\n if (!filteredClaims.length) {\n throw new Error('No matching claims found');\n }\n\n // only evm use\n const defaultRecipient =\n project.chainType === ChainType.Evm ? (walletClient as ViemWalletClient).account?.address! : '';\n\n const claimData = filteredClaims.map((it) => {\n const signature = signatureMap[it.claimId];\n if (!signature) {\n throw new Error(`Signature not found for claim ID: ${it.claimId}`);\n }\n\n return {\n ...it,\n recipient: recipient ? recipient : defaultRecipient,\n ...signature\n };\n });\n\n const hash = (await service!.claim(claimData, recipient)) as `0x${string}`;\n return hash;\n }\n\n async batchCheckClaimed(): Promise<boolean[]> {\n if (!this.claims?.length) return [];\n const strategy = await this.getStrategy();\n if (!strategy.batchFetchClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const claimIds = this.claims?.map((it) => it.claimId);\n return strategy.batchFetchClaimed(claimIds);\n }\n\n async getPaused(): Promise<boolean> {\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,0BAgBO;;;ACjBP,IAAAC,0BAAyC;;;ACAzC,6BAA0D;AAInD,IAAM,qBAAN,MAAqD;AAAA,EAClD;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EACA,gBAA+B;AAAA,EAEvC,YAAY,QAKT;AACD,SAAK,kBAAkB,OAAO;AAC9B,SAAK,UAAU,OAAO,OAAO,OAAO;AACpC,SAAK,WAA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B,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AACA,UAAM,WAAW,KAAK,QAAQ,IAAI,CAAC,OAAO,GAAG,OAAO;AACpD,WAAO,SAAS,kBAAkB,QAAQ;AAAA,EAC5C;AAAA,EAEA,MAAM,YAA8B;AAClC,UAAM,WAAW,MAAM,KAAK,YAAY;AACxC,QAAI,CAAC,SAAS,WAAW;AACvB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AACA,WAAO,SAAS,UAAU;AAAA,EAC5B;AACF;;;APpYA,0BAAc,yCAFd;AAGA,0BAAc,4CAHd;","names":["import_tokentable_core","import_tokentable_core","import_tokentable_core","import_tokentable_core","import_tokentable_core"]}
|
package/dist/index.mjs
CHANGED
|
@@ -383,11 +383,19 @@ var AirdropClient = class {
|
|
|
383
383
|
attestationId: BigInt(1)
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
async calculateClaimFee(project,
|
|
386
|
+
async calculateClaimFee(project, claimData) {
|
|
387
|
+
const claimAmount = claimData.amount;
|
|
387
388
|
if (project.chainType === ChainType2.Evm) {
|
|
388
389
|
const version = await this.getVersion();
|
|
389
390
|
const isNativeFreeVersion = project.tokenType === ETokenType.Native && [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version);
|
|
390
|
-
|
|
391
|
+
if (isNativeFreeVersion) {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
394
|
+
if (version.includes("TokenTableMerkleDistributorWithFees")) {
|
|
395
|
+
const fees = claimData.fees;
|
|
396
|
+
return fees ? BigInt(fees) : "0";
|
|
397
|
+
}
|
|
398
|
+
return await this.getClaimFee(BigInt(claimAmount));
|
|
391
399
|
}
|
|
392
400
|
if (project.chainType === ChainType2.Ton) {
|
|
393
401
|
return await this.getClaimFee(BigInt(claimAmount));
|
|
@@ -399,7 +407,7 @@ var AirdropClient = class {
|
|
|
399
407
|
const strategy = await this.getStrategy(walletClient);
|
|
400
408
|
const project = await this.getProjectInfo();
|
|
401
409
|
const extraData = project.chainType === ChainType2.Ton ? void 0 : this.claimHook ? this.claimHook(claimData) : this.getDefaultExtraData();
|
|
402
|
-
const value = await this.calculateClaimFee(project, claimData
|
|
410
|
+
const value = await this.calculateClaimFee(project, claimData);
|
|
403
411
|
return strategy.claim(
|
|
404
412
|
{
|
|
405
413
|
...claimData,
|
|
@@ -658,7 +666,7 @@ var SignatureAirdropClient = class {
|
|
|
658
666
|
const msg = [project.id, recipientTypeMap[chainType], timestamp].join(",");
|
|
659
667
|
const signResult = await wallet.signin(msg, false);
|
|
660
668
|
await wallet.disconnect();
|
|
661
|
-
const { message, signature } = signResult || {};
|
|
669
|
+
const { message, signature, signedMessage } = signResult || {};
|
|
662
670
|
if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {
|
|
663
671
|
onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);
|
|
664
672
|
return;
|
|
@@ -670,7 +678,8 @@ var SignatureAirdropClient = class {
|
|
|
670
678
|
address: wallet.address,
|
|
671
679
|
projectId: project.id,
|
|
672
680
|
timestamp,
|
|
673
|
-
recipientType: recipientTypeMap[chainType]
|
|
681
|
+
recipientType: recipientTypeMap[chainType],
|
|
682
|
+
encodedMessage: signedMessage
|
|
674
683
|
};
|
|
675
684
|
const res = await bindWallet(payload, this.endpoint);
|
|
676
685
|
if (res?.sid) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AirdropClient.ts","../src/strategies/AirdropStrategyFactory.ts","../src/strategies/EvmAirdropStrategy.ts","../src/strategies/SolanaAirdropStrategy.ts","../src/strategies/TonAirdropStrategy.ts","../src/strategies/StrategyCache.ts","../src/SignatureAirdropClient.ts","../src/index.ts"],"sourcesContent":["import { TonClient } from '@ton/ton';\nimport {\n getAirdropPro,\n getAirdropProject,\n getAirdropQuery,\n getAirdropContractConfig,\n getChainRpc,\n getTonProjectIdByAddress,\n ChainId,\n ChainType,\n ETokenType,\n EvmAirdropVersionEnum,\n IAirdropClaim,\n IAirdropOptions,\n IContractConfig,\n IProject,\n IWalletClient\n} from '@sign-global/tokentable-core';\nimport { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';\nimport { IAirdropStrategy } from './strategies/IAirdropStrategy';\nimport { strategyCache } from './strategies/StrategyCache';\n\nexport class AirdropClient {\n private tonClient?: TonClient;\n private slug?: string;\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n protected chainRpc?: string;\n protected claims?: IAirdropClaim[];\n private projectPromise: Promise<void> | undefined;\n private claimHook: ((v: any) => any) | undefined;\n private contractConfig: IContractConfig | null = null;\n\n constructor(params: IAirdropOptions) {\n if ('slug' in params) {\n this.slug = params.slug;\n }\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n }\n\n setTonClient(tonClient: TonClient) {\n this.tonClient = tonClient;\n }\n\n private getTonClient(): TonClient | undefined {\n if (!this.tonClient) {\n return undefined;\n }\n return this.tonClient;\n }\n\n private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {\n if (!this.slug) return undefined;\n\n const res = await getAirdropPro(this.slug, this.endpoint);\n const projectMap = res?.childProjectMapping || {};\n\n return getTonProjectIdByAddress({\n address,\n slug: this.slug,\n data: projectMap\n });\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects(address?: string) {\n try {\n let projectId = this.projectId;\n\n // If slug is provided, try to fetch project ID from slug\n if (!projectId) {\n projectId = await this.fetchProjectFromSlug(address);\n }\n\n if (!projectId) {\n return;\n }\n\n // Fetch project details\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async getAirdropClaims(data: { address: string }) {\n if (this.slug) {\n await this.initializeProjects(data.address); // Fetch project details by address & slug\n }\n const project = await this.getProjectInfo();\n\n const res = await getAirdropQuery(\n {\n recipient: data.address,\n projectId: project!.id,\n recipientType: project!.recipientType\n },\n this.endpoint\n );\n const claimsRes = res.claims?.map((it) => ({\n ...it,\n project: project!,\n claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`\n }));\n this.claims = claimsRes;\n return this.claims;\n }\n\n public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {\n const project = await this.getProjectInfo();\n const version = this.contractConfig?.version || undefined;\n\n const hasWallet = !!walletClient;\n\n // Try to get cached strategy\n let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);\n\n if (!strategy) {\n // Create new strategy if not cached\n strategy = AirdropStrategyFactory.createStrategy({\n chainType: project.chainType,\n contractAddress: project.contractAddress,\n chainId: project.chainId,\n projectId: project.id,\n walletClient,\n tonClient: this.getTonClient(),\n version,\n chainRpc: this.chainRpc!\n });\n\n // Initialize the strategy\n await strategy.initialize(walletClient);\n\n // Cache the initialized strategy\n strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);\n } else if (hasWallet) {\n // If we have a wallet and the strategy exists, just initialize with the new wallet\n await strategy.initialize(walletClient);\n }\n\n return strategy;\n }\n\n private getClaimDataById(claimId: string) {\n const claimData = this.claims?.find((it) => it.claimId === claimId);\n if (!claimData) throw new Error('Claim data not found');\n return claimData;\n }\n\n setClaimHook(fn: (v: any) => any) {\n this.claimHook = fn;\n }\n\n private getDefaultExtraData() {\n return {\n isLegacy: true,\n attestationId: BigInt(1)\n };\n }\n\n private async calculateClaimFee(project: IProject, claimAmount: string): Promise<string | bigint | undefined> {\n if (project.chainType === ChainType.Evm) {\n const version = await this.getVersion();\n const isNativeFreeVersion =\n project.tokenType === ETokenType.Native &&\n [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);\n return isNativeFreeVersion ? undefined : await this.getClaimFee(BigInt(claimAmount));\n }\n\n if (project.chainType === ChainType.Ton) {\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n return undefined;\n }\n\n async claimAirdrop(\n { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },\n options?: { onLoading?: () => void }\n ) {\n // Get claim data and initialize strategy\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n\n // Process extra data\n const extraData =\n project.chainType === ChainType.Ton\n ? undefined\n : this.claimHook\n ? this.claimHook(claimData)\n : this.getDefaultExtraData();\n\n // Calculate claim value based on project type\n const value = await this.calculateClaimFee(project, claimData.amount);\n\n // Execute claim with processed data\n return strategy.claim(\n {\n ...claimData,\n extraData,\n value\n },\n options\n );\n }\n\n async checkClaimed(claimId: string): Promise<boolean> {\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy();\n return strategy.checkClaimed(claimData);\n }\n\n private async getContractConfig(): Promise<IContractConfig | null> {\n try {\n const project = await this.getProjectInfo();\n\n if (!this.contractConfig && [ChainType.Evm, ChainType.Ton].includes(project.chainType)) {\n this.contractConfig = await getAirdropContractConfig(\n {\n chainId: project.chainId,\n chainType: project.chainType,\n contractAddress: project.contractAddress\n },\n this.endpoint\n );\n }\n return this.contractConfig;\n } catch (error) {\n console.error('Error fetching contract config:', error);\n return null;\n }\n }\n\n async getVersion(): Promise<string> {\n const config = await this.getContractConfig();\n if (config?.version) {\n return config.version;\n }\n\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n async getPaused(): Promise<boolean> {\n const config = await this.getContractConfig();\n if (config && config?.paused !== null) {\n return config.paused;\n }\n\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<string | bigint> {\n const config = await this.getContractConfig();\n if (config?.claimFee) {\n return config.claimFee;\n }\n\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));\n }\n\n // params claimId[]\n async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {\n const strategy = await this.getStrategy();\n if (!strategy.batchCheckClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const leafs = this.claims?.map((it) => it.leaf);\n if (!leafs) return [];\n return strategy.batchCheckClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n const strategy = await this.getStrategy();\n if (!strategy.getNFT) {\n throw new Error('getNFT is not supported for this chain');\n }\n return strategy.getNFT();\n }\n\n async getKycThreshold(): Promise<bigint> {\n const strategy = await this.getStrategy();\n if (!strategy.getKycThreshold) {\n throw new Error('getKycThreshold is not supported for this chain');\n }\n return strategy.getKycThreshold();\n }\n}\n","import { ChainType, IWalletClient } from '@sign-global/tokentable-core';\nimport { EvmAirdropStrategy } from './EvmAirdropStrategy';\nimport { IAirdropStrategy, IAirdropStrategyConstructor } from './IAirdropStrategy';\nimport { SolanaAirdropStrategy } from './SolanaAirdropStrategy';\nimport { TonAirdropStrategy } from './TonAirdropStrategy';\nimport { TonClient } from '@ton/ton';\n\nexport class AirdropStrategyFactory {\n private static strategyMap: Record<ChainType, IAirdropStrategyConstructor | null> = {\n [ChainType.Evm]: EvmAirdropStrategy,\n [ChainType.Ton]: TonAirdropStrategy,\n [ChainType.Solana]: SolanaAirdropStrategy\n };\n\n static createStrategy(params: {\n chainType: ChainType;\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n projectId: string;\n chainRpc: string;\n }): IAirdropStrategy {\n const { chainType, ...strategyParams } = params;\n const StrategyClass = this.strategyMap[chainType];\n\n if (!StrategyClass) {\n throw new Error(`Unsupported chain type: ${chainType}`);\n }\n\n return new StrategyClass(strategyParams);\n }\n}\n","import { EvmAirdropService, ChainId, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\nimport { WalletClient as ViemWalletClient } from 'viem';\n\nexport class EvmAirdropStrategy implements IAirdropStrategy {\n private service: EvmAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: ViemWalletClient;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n chainRpc: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = Number(params.chainId) as ChainId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as ViemWalletClient;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as ViemWalletClient;\n }\n this.service = new EvmAirdropService({\n contractAddress: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n const { proof, group, data, value, extraData } = claimData;\n return this.service.claim({\n proof,\n group,\n data,\n value,\n extraData\n });\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getNFT() as unknown as string;\n }\n\n async getKycThreshold(): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getKycThreshold();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n}\n","import { SolanaAirdropService, ChainId, IWalletClient, SolanaWalletState } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class SolanaAirdropStrategy implements IAirdropStrategy {\n private service: SolanaAirdropService | undefined;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: SolanaWalletState;\n private cachedVersion: string | null = null;\n private projectId: string;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n projectId: string;\n chainRpc: string;\n }) {\n this.chainId = params.chainId as ChainId;\n this.projectId = params.projectId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as SolanaWalletState;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as SolanaWalletState;\n }\n this.service = new SolanaAirdropService({\n projectId: this.projectId,\n chainId: this.chainId as string,\n walletClient: this.walletClient as any,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n}\n","import { TonClient } from '@ton/ton';\nimport { TonConnectUI } from '@tonconnect/ui-react';\nimport { TonAirdropService, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class TonAirdropStrategy implements IAirdropStrategy {\n private service: TonAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: string;\n private readonly tonClient?: TonClient;\n private walletClient?: TonConnectUI;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = params.chainId.toString();\n this.tonClient = params.tonClient;\n if (params.walletClient) {\n this.walletClient = params.walletClient as TonConnectUI;\n }\n if (params.version) {\n this.cachedVersion = params.version;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as TonConnectUI;\n }\n this.service = new TonAirdropService({\n address: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n tonClient: this.tonClient,\n version: this.cachedVersion || undefined\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n if (!this.cachedVersion) {\n this.cachedVersion = await this.service.getVersion();\n }\n return this.cachedVersion;\n }\n\n async claim(claimData: any, options?: { onLoading?: () => void }): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData, options);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.checkClaimed(claimData);\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount);\n }\n}\n","import { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class StrategyCache {\n private readOnlyStrategies: Map<string, IAirdropStrategy> = new Map();\n private walletStrategies: Map<string, IAirdropStrategy> = new Map();\n\n private getCacheKey(contractAddress: string, chainId: string | number, chainType: string): string {\n return `${chainType}:${contractAddress}:${chainId}`;\n }\n\n getStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet: boolean = false): IAirdropStrategy | undefined {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n return cache.get(cacheKey);\n }\n\n setStrategy(contractAddress: string, chainId: string | number, chainType: string, strategy: IAirdropStrategy, hasWallet: boolean = false): void {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n cache.set(cacheKey, strategy);\n }\n\n clearStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet?: boolean): void {\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n if (hasWallet === undefined || hasWallet) {\n this.walletStrategies.delete(cacheKey);\n }\n if (hasWallet === undefined || !hasWallet) {\n this.readOnlyStrategies.delete(cacheKey);\n }\n }\n}\n\nexport const strategyCache = new StrategyCache();\n","import { WalletFactory } from '@sign-global/tokentable-wallets';\nimport {\n bindWallet,\n checkEligibility,\n checkGetSignatures,\n connectGoogleApi,\n connectTwitter,\n disconnectRecipient,\n getAirdropProject,\n cleanUrlParams,\n isMobile,\n getChainRpc,\n CONST,\n EvmSignatureAirdropService,\n SolanaSignatureAirdropService,\n AirdropSigIdentityTypeEnum,\n ChainId,\n ErrorCode,\n IAirdropOptions,\n IAirdropSignatureClaim,\n IAirdropSignatureIdentity,\n IClaimSignature,\n IProject,\n IWalletClient,\n SolanaWalletState,\n ViemWalletClient,\n ChainType\n} from '@sign-global/tokentable-core';\n\nexport class SignatureAirdropClient {\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n private chainRpc?: string;\n protected claims?: IAirdropSignatureClaim[];\n protected identities?: IAirdropSignatureIdentity[];\n private projectPromise: Promise<void> | undefined;\n private authPromise: Promise<void> | undefined;\n private strategyCache: Map<string, EvmSignatureAirdropService | SolanaSignatureAirdropService> = new Map();\n constructor(params: IAirdropOptions) {\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n if (isMobile()) {\n this.authPromise = this.checkAndHandleTwitterCode();\n }\n }\n\n private readonly LOCAL_STORAGE_SID_PREFIX = 'sid_';\n\n private async checkAndHandleTwitterCode() {\n try {\n const urlParams = new URLSearchParams(window.location.search);\n const code = urlParams.get('code');\n const type = urlParams.get('type');\n\n if (code && this.projectId) {\n let res;\n if (type === 'twitter') {\n res = await connectTwitter({ code, projectId: this.projectId }, this.endpoint);\n } else if (type === 'google') {\n res = await connectGoogleApi({ code, projectId: this.projectId }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(this.projectId!, res.sid);\n } else {\n throw new Error('Failed to connect');\n }\n cleanUrlParams(['code', 'type']);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n private setSid(projectId: string, sid: string): void {\n window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects() {\n try {\n let projectId = this.projectId;\n if (!projectId) {\n return;\n }\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async connectOAuth({\n onSuccess,\n onError,\n type\n }: {\n onSuccess: () => void;\n onError: (error: Error) => void;\n type: AirdropSigIdentityTypeEnum;\n }) {\n const project = await this.getProjectInfo();\n const authorizeUrl = project.identities.find((item: any) => item.identityType === type)?.authorizeUrl;\n if (!authorizeUrl) {\n onError(new Error('Authorize URL not found'));\n return;\n }\n if (isMobile()) {\n const state = encodeURIComponent(window.location.href);\n window.location.href = `${authorizeUrl}&state=${state}`;\n return;\n }\n const onWindowMessage = async (message: any) => {\n const name = message.data?.name;\n if (name && [CONST.TWITTER_AUTH_SUCCESS, CONST.GOOGLE_AUTH_SUCCESS].includes(name)) {\n const { code } = message.data.data || {};\n try {\n let res;\n if (name === CONST.GOOGLE_AUTH_SUCCESS) {\n res = await connectGoogleApi({ code, projectId: project.id }, this.endpoint);\n } else if (name === CONST.TWITTER_AUTH_SUCCESS) {\n res = await connectTwitter({ code, projectId: project.id }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n onSuccess();\n } else {\n onError(new Error('Failed to connect'));\n }\n } catch (error) {\n onError(error as Error);\n } finally {\n window.removeEventListener('message', onWindowMessage);\n }\n }\n };\n\n window.addEventListener('message', onWindowMessage);\n window.open(`${authorizeUrl}&state=state`, `twitter_auth_${project.id}`, 'width=600,height=800');\n }\n\n async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Twitter\n });\n }\n\n async connectGoogle({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Google\n });\n }\n\n async connectWallet({\n chainType,\n onSuccess,\n onError\n }: {\n chainType: ChainType;\n onSuccess?: (address: string) => void;\n onError?: (error: any) => void;\n }) {\n try {\n const project = await this.getProjectInfo();\n const wallet = WalletFactory.getWallet(chainType);\n const timestamp = Date.now();\n const recipientTypeMap = {\n [ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,\n [ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,\n [ChainType.Ton]: AirdropSigIdentityTypeEnum.TONWallet\n };\n const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');\n const signResult = await wallet.signin(msg, false);\n await wallet.disconnect();\n const { message, signature } = signResult || {};\n\n if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {\n onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);\n return;\n }\n\n const payload = {\n signature: signature as string,\n message: message as string,\n key: wallet.publicKey || wallet.address!,\n address: wallet.address!,\n projectId: project.id,\n timestamp: timestamp,\n recipientType: recipientTypeMap[chainType]\n };\n\n const res = await bindWallet(payload, this.endpoint);\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n }\n onSuccess?.(wallet.address!);\n } catch (error) {\n onError?.(error);\n }\n }\n\n async getClaims() {\n const project = await this.getProjectInfo();\n if (this.authPromise) {\n await this.authPromise;\n }\n const res = await checkEligibility(\n {\n projectId: project.id\n },\n this.endpoint\n );\n this.claims = res.claims;\n this.identities = res.identities;\n return res;\n }\n\n public async disconnectIdentity({\n recipientType,\n recipient\n }: {\n recipientType: AirdropSigIdentityTypeEnum;\n recipient?: string;\n }) {\n const project = await this.getProjectInfo();\n return await disconnectRecipient(\n {\n projectId: project.id,\n recipientType,\n recipient\n },\n this.endpoint\n );\n }\n\n public async getStrategy(\n walletClient?: IWalletClient\n ): Promise<EvmSignatureAirdropService | SolanaSignatureAirdropService> {\n const project = await this.getProjectInfo();\n\n const cacheKey = walletClient\n ? project.chainType === ChainType.Evm\n ? (walletClient as ViemWalletClient).account?.address!\n : project.chainType === ChainType.Solana\n ? (walletClient as SolanaWalletState).publicKey!.toString()\n : 'walletClient'\n : 'default';\n if (this.strategyCache.has(cacheKey)) {\n return this.strategyCache.get(cacheKey)!;\n }\n\n const strategy =\n project.chainType === ChainType.Solana\n ? new SolanaSignatureAirdropService({\n chainId: project.chainId,\n projectId: project.id,\n token: project.tokenAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n })\n : new EvmSignatureAirdropService({\n chainId: Number(project.chainId) as ChainId,\n contractAddress: project.contractAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n });\n this.strategyCache.set(cacheKey, strategy);\n return strategy;\n }\n\n async getVersion(): Promise<string> {\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n // solana prams need to wallet\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<undefined | bigint> {\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return await strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(1));\n }\n\n async claimAirdrop({\n claimIds,\n walletClient,\n recipient\n }: {\n claimIds: string[];\n walletClient: IWalletClient;\n recipient: string;\n }) {\n if (!claimIds.length) {\n throw new Error('Claim IDs cannot be empty');\n }\n if (!walletClient) {\n throw new Error('Wallet client is required');\n }\n if (!this.claims?.length) {\n throw new Error('No claims available');\n }\n const service = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n const res = await checkGetSignatures(\n {\n claimIds,\n projectId: this.projectId!,\n recipient\n },\n this.endpoint\n );\n if (!res?.signatures?.length) {\n throw new Error('Failed to get signatures');\n }\n const signatureMap = res?.signatures?.reduce(\n (map, item) => {\n map[item.claimId] = item;\n return map;\n },\n {} as Record<string, IClaimSignature>\n );\n const filteredClaims = this.claims.filter((it) => claimIds.includes(it.claimId));\n if (!filteredClaims.length) {\n throw new Error('No matching claims found');\n }\n\n // only evm use\n const defaultRecipient =\n project.chainType === ChainType.Evm ? (walletClient as ViemWalletClient).account?.address! : '';\n\n const claimData = filteredClaims.map((it) => {\n const signature = signatureMap[it.claimId];\n if (!signature) {\n throw new Error(`Signature not found for claim ID: ${it.claimId}`);\n }\n\n return {\n ...it,\n recipient: recipient ? recipient : defaultRecipient,\n ...signature\n };\n });\n\n const hash = (await service!.claim(claimData, recipient)) as `0x${string}`;\n return hash;\n }\n\n async batchCheckClaimed(): Promise<boolean[]> {\n if (!this.claims?.length) return [];\n const strategy = await this.getStrategy();\n if (!strategy.batchFetchClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const claimIds = this.claims?.map((it) => it.claimId);\n return strategy.batchFetchClaimed(claimIds);\n }\n\n async getPaused(): Promise<boolean> {\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n}\n","export { AirdropClient } from './AirdropClient';\nexport { SignatureAirdropClient } from './SignatureAirdropClient';\nexport * from '@sign-global/tokentable-core';\nexport * from '@sign-global/tokentable-wallets';\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,aAAAA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;;;ACjBP,SAAS,iBAAgC;;;ACAzC,SAAS,yBAAiD;AAInD,IAAM,qBAAN,MAAqD;AAAA,EAClD;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EACA,gBAA+B;AAAA,EAEvC,YAAY,QAKT;AACD,SAAK,kBAAkB,OAAO;AAC9B,SAAK,UAAU,OAAO,OAAO,OAAO;AACpC,SAAK,WAAW,OAAO;AACvB,QAAI,OAAO,cAAc;AACvB,WAAK,eAAe,OAAO;AAAA,IAC7B;AAAA,EACF;AAAA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O;AACpD,WAAO,SAAS,kBAAkB,QAAQ;AAAA,EAC5C;AAAA,EAEA,MAAM,YAA8B;AAClC,UAAM,WAAW,MAAM,KAAK,YAAY;AACxC,QAAI,CAAC,SAAS,WAAW;AACvB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AACA,WAAO,SAAS,UAAU;AAAA,EAC5B;AACF;;;ACnYA,cAAc;AACd,cAAc;","names":["ChainType","ChainType","getAirdropProject","getChainRpc","ChainType"]}
|
|
1
|
+
{"version":3,"sources":["../src/AirdropClient.ts","../src/strategies/AirdropStrategyFactory.ts","../src/strategies/EvmAirdropStrategy.ts","../src/strategies/SolanaAirdropStrategy.ts","../src/strategies/TonAirdropStrategy.ts","../src/strategies/StrategyCache.ts","../src/SignatureAirdropClient.ts","../src/index.ts"],"sourcesContent":["import { TonClient } from '@ton/ton';\nimport {\n getAirdropPro,\n getAirdropProject,\n getAirdropQuery,\n getAirdropContractConfig,\n getChainRpc,\n getTonProjectIdByAddress,\n ChainId,\n ChainType,\n ETokenType,\n EvmAirdropVersionEnum,\n IAirdropClaim,\n IAirdropOptions,\n IContractConfig,\n IProject,\n IWalletClient\n} from '@sign-global/tokentable-core';\nimport { AirdropStrategyFactory } from './strategies/AirdropStrategyFactory';\nimport { IAirdropStrategy } from './strategies/IAirdropStrategy';\nimport { strategyCache } from './strategies/StrategyCache';\n\nexport class AirdropClient {\n private tonClient?: TonClient;\n private slug?: string;\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n protected chainRpc?: string;\n protected claims?: IAirdropClaim[];\n private projectPromise: Promise<void> | undefined;\n private claimHook: ((claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) | undefined;\n private contractConfig: IContractConfig | null = null;\n\n constructor(params: IAirdropOptions) {\n if ('slug' in params) {\n this.slug = params.slug;\n }\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n }\n\n setTonClient(tonClient: TonClient) {\n this.tonClient = tonClient;\n }\n\n private getTonClient(): TonClient | undefined {\n if (!this.tonClient) {\n return undefined;\n }\n return this.tonClient;\n }\n\n private async fetchProjectFromSlug(address?: string): Promise<string | undefined> {\n if (!this.slug) return undefined;\n\n const res = await getAirdropPro(this.slug, this.endpoint);\n const projectMap = res?.childProjectMapping || {};\n\n return getTonProjectIdByAddress({\n address,\n slug: this.slug,\n data: projectMap\n });\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects(address?: string) {\n try {\n let projectId = this.projectId;\n\n // If slug is provided, try to fetch project ID from slug\n if (!projectId) {\n projectId = await this.fetchProjectFromSlug(address);\n }\n\n if (!projectId) {\n return;\n }\n\n // Fetch project details\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async getAirdropClaims(data: { address: string }) {\n if (this.slug) {\n await this.initializeProjects(data.address); // Fetch project details by address & slug\n }\n const project = await this.getProjectInfo();\n\n const res = await getAirdropQuery(\n {\n recipient: data.address,\n projectId: project!.id,\n recipientType: project!.recipientType\n },\n this.endpoint\n );\n const claimsRes = res.claims?.map((it) => ({\n ...it,\n project: project!,\n claimId: project!.chainType === ChainType.Evm ? `${project!.id}:${it.leaf}` : `${project!.id}:${it.index}`\n }));\n this.claims = claimsRes;\n return this.claims;\n }\n\n public async getStrategy(walletClient?: IWalletClient): Promise<IAirdropStrategy> {\n const project = await this.getProjectInfo();\n const version = this.contractConfig?.version || undefined;\n\n const hasWallet = !!walletClient;\n\n // Try to get cached strategy\n let strategy = strategyCache.getStrategy(project.contractAddress, project.chainId, project.chainType, hasWallet);\n\n if (!strategy) {\n // Create new strategy if not cached\n strategy = AirdropStrategyFactory.createStrategy({\n chainType: project.chainType,\n contractAddress: project.contractAddress,\n chainId: project.chainId,\n projectId: project.id,\n walletClient,\n tonClient: this.getTonClient(),\n version,\n chainRpc: this.chainRpc!\n });\n\n // Initialize the strategy\n await strategy.initialize(walletClient);\n\n // Cache the initialized strategy\n strategyCache.setStrategy(project.contractAddress, project.chainId, project.chainType, strategy, hasWallet);\n } else if (hasWallet) {\n // If we have a wallet and the strategy exists, just initialize with the new wallet\n await strategy.initialize(walletClient);\n }\n\n return strategy;\n }\n\n private getClaimDataById(claimId: string) {\n const claimData = this.claims?.find((it) => it.claimId === claimId);\n if (!claimData) throw new Error('Claim data not found');\n return claimData;\n }\n\n setClaimHook(fn: (claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) {\n this.claimHook = fn;\n }\n\n private getDefaultExtraData() {\n return {\n isLegacy: true,\n attestationId: BigInt(1)\n };\n }\n\n private async calculateClaimFee(project: IProject, claimData: IAirdropClaim): Promise<string | bigint | undefined> {\n const claimAmount = claimData.amount;\n if (project.chainType === ChainType.Evm) {\n const version = await this.getVersion();\n const isNativeFreeVersion =\n project.tokenType === ETokenType.Native &&\n [EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);\n if (isNativeFreeVersion) {\n return undefined;\n }\n if (version.includes('TokenTableMerkleDistributorWithFees')) {\n const fees = claimData.fees;\n return fees ? BigInt(fees) : '0';\n }\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n if (project.chainType === ChainType.Ton) {\n return await this.getClaimFee(BigInt(claimAmount));\n }\n\n return undefined;\n }\n\n async claimAirdrop(\n { claimId, walletClient }: { claimId: string; walletClient: IWalletClient },\n options?: { onLoading?: () => void }\n ) {\n // Get claim data and initialize strategy\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n\n // Process extra data\n const extraData =\n project.chainType === ChainType.Ton\n ? undefined\n : this.claimHook\n ? this.claimHook(claimData)\n : this.getDefaultExtraData();\n\n // Calculate claim value based on project type\n const value = await this.calculateClaimFee(project, claimData);\n\n // Execute claim with processed data\n return strategy.claim(\n {\n ...claimData,\n extraData,\n value\n },\n options\n );\n }\n\n async checkClaimed(claimId: string): Promise<boolean> {\n const claimData = this.getClaimDataById(claimId);\n const strategy = await this.getStrategy();\n return strategy.checkClaimed(claimData);\n }\n\n private async getContractConfig(): Promise<IContractConfig | null> {\n try {\n const project = await this.getProjectInfo();\n\n if (!this.contractConfig && [ChainType.Evm, ChainType.Ton].includes(project.chainType)) {\n this.contractConfig = await getAirdropContractConfig(\n {\n chainId: project.chainId,\n chainType: project.chainType,\n contractAddress: project.contractAddress\n },\n this.endpoint\n );\n }\n return this.contractConfig;\n } catch (error) {\n console.error('Error fetching contract config:', error);\n return null;\n }\n }\n\n async getVersion(): Promise<string> {\n const config = await this.getContractConfig();\n if (config?.version) {\n return config.version;\n }\n\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n async getPaused(): Promise<boolean> {\n const config = await this.getContractConfig();\n if (config && config?.paused !== null) {\n return config.paused;\n }\n\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<string | bigint> {\n const config = await this.getContractConfig();\n if (config?.claimFee) {\n return config.claimFee;\n }\n\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0));\n }\n\n // params claimId[]\n async batchCheckClaimed(): Promise<{ result: boolean; status: string }[]> {\n const strategy = await this.getStrategy();\n if (!strategy.batchCheckClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const leafs = this.claims?.map((it) => it.leaf);\n if (!leafs) return [];\n return strategy.batchCheckClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n const strategy = await this.getStrategy();\n if (!strategy.getNFT) {\n throw new Error('getNFT is not supported for this chain');\n }\n return strategy.getNFT();\n }\n\n async getKycThreshold(): Promise<bigint> {\n const strategy = await this.getStrategy();\n if (!strategy.getKycThreshold) {\n throw new Error('getKycThreshold is not supported for this chain');\n }\n return strategy.getKycThreshold();\n }\n}\n","import { ChainType, IWalletClient } from '@sign-global/tokentable-core';\nimport { EvmAirdropStrategy } from './EvmAirdropStrategy';\nimport { IAirdropStrategy, IAirdropStrategyConstructor } from './IAirdropStrategy';\nimport { SolanaAirdropStrategy } from './SolanaAirdropStrategy';\nimport { TonAirdropStrategy } from './TonAirdropStrategy';\nimport { TonClient } from '@ton/ton';\n\nexport class AirdropStrategyFactory {\n private static strategyMap: Record<ChainType, IAirdropStrategyConstructor | null> = {\n [ChainType.Evm]: EvmAirdropStrategy,\n [ChainType.Ton]: TonAirdropStrategy,\n [ChainType.Solana]: SolanaAirdropStrategy\n };\n\n static createStrategy(params: {\n chainType: ChainType;\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n projectId: string;\n chainRpc: string;\n }): IAirdropStrategy {\n const { chainType, ...strategyParams } = params;\n const StrategyClass = this.strategyMap[chainType];\n\n if (!StrategyClass) {\n throw new Error(`Unsupported chain type: ${chainType}`);\n }\n\n return new StrategyClass(strategyParams);\n }\n}\n","import { EvmAirdropService, ChainId, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\nimport { WalletClient as ViemWalletClient } from 'viem';\n\nexport class EvmAirdropStrategy implements IAirdropStrategy {\n private service: EvmAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: ViemWalletClient;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n chainRpc: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = Number(params.chainId) as ChainId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as ViemWalletClient;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as ViemWalletClient;\n }\n this.service = new EvmAirdropService({\n contractAddress: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n const { proof, group, data, value, extraData } = claimData;\n return this.service.claim({\n proof,\n group,\n data,\n value,\n extraData\n });\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getNFT(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getNFT() as unknown as string;\n }\n\n async getKycThreshold(): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getKycThreshold();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n}\n","import { SolanaAirdropService, ChainId, IWalletClient, SolanaWalletState } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class SolanaAirdropStrategy implements IAirdropStrategy {\n private service: SolanaAirdropService | undefined;\n private readonly chainId: ChainId;\n private readonly chainRpc: string;\n private walletClient?: SolanaWalletState;\n private cachedVersion: string | null = null;\n private projectId: string;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n projectId: string;\n chainRpc: string;\n }) {\n this.chainId = params.chainId as ChainId;\n this.projectId = params.projectId;\n this.chainRpc = params.chainRpc;\n if (params.walletClient) {\n this.walletClient = params.walletClient as SolanaWalletState;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as SolanaWalletState;\n }\n this.service = new SolanaAirdropService({\n projectId: this.projectId,\n chainId: this.chainId as string,\n walletClient: this.walletClient as any,\n chainRpc: this.chainRpc\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (this.cachedVersion) {\n return this.cachedVersion;\n }\n if (!this.service) throw new Error('Strategy not initialized');\n this.cachedVersion = await this.service.getVersion();\n return this.cachedVersion;\n }\n\n async claim(claimData: any): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.isLeafUsed(claimData.leaf);\n }\n\n async batchCheckClaimed(leafs: string[]): Promise<{ result: boolean; status: string }[]> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.batchFetchClaimed(leafs);\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<bigint> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount) as unknown as bigint;\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n}\n","import { TonClient } from '@ton/ton';\nimport { TonConnectUI } from '@tonconnect/ui-react';\nimport { TonAirdropService, IWalletClient } from '@sign-global/tokentable-core';\nimport { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class TonAirdropStrategy implements IAirdropStrategy {\n private service: TonAirdropService | undefined;\n private readonly contractAddress: string;\n private readonly chainId: string;\n private readonly tonClient?: TonClient;\n private walletClient?: TonConnectUI;\n private cachedVersion: string | null = null;\n\n constructor(params: {\n contractAddress: string;\n chainId: string | number;\n walletClient?: IWalletClient;\n tonClient?: TonClient;\n version?: string;\n }) {\n this.contractAddress = params.contractAddress;\n this.chainId = params.chainId.toString();\n this.tonClient = params.tonClient;\n if (params.walletClient) {\n this.walletClient = params.walletClient as TonConnectUI;\n }\n if (params.version) {\n this.cachedVersion = params.version;\n }\n }\n\n async initialize(walletClient?: IWalletClient): Promise<void> {\n if (walletClient) {\n this.walletClient = walletClient as TonConnectUI;\n }\n this.service = new TonAirdropService({\n address: this.contractAddress,\n chainId: this.chainId,\n walletClient: this.walletClient,\n tonClient: this.tonClient,\n version: this.cachedVersion || undefined\n });\n }\n\n isInitialized(): boolean {\n return !!this.service;\n }\n\n async getVersion(): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n if (!this.cachedVersion) {\n this.cachedVersion = await this.service.getVersion();\n }\n return this.cachedVersion;\n }\n\n async claim(claimData: any, options?: { onLoading?: () => void }): Promise<any> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.claim(claimData, options);\n }\n\n async checkClaimed(claimData: any): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.checkClaimed(claimData);\n }\n\n async getPaused(): Promise<boolean> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getPaused();\n }\n\n async getClaimFee(contractAddress: string, amount: bigint): Promise<string> {\n if (!this.service) throw new Error('Strategy not initialized');\n return this.service.getClaimFee(contractAddress, amount);\n }\n}\n","import { IAirdropStrategy } from './IAirdropStrategy';\n\nexport class StrategyCache {\n private readOnlyStrategies: Map<string, IAirdropStrategy> = new Map();\n private walletStrategies: Map<string, IAirdropStrategy> = new Map();\n\n private getCacheKey(contractAddress: string, chainId: string | number, chainType: string): string {\n return `${chainType}:${contractAddress}:${chainId}`;\n }\n\n getStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet: boolean = false): IAirdropStrategy | undefined {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n return cache.get(cacheKey);\n }\n\n setStrategy(contractAddress: string, chainId: string | number, chainType: string, strategy: IAirdropStrategy, hasWallet: boolean = false): void {\n const cache = hasWallet ? this.walletStrategies : this.readOnlyStrategies;\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n cache.set(cacheKey, strategy);\n }\n\n clearStrategy(contractAddress: string, chainId: string | number, chainType: string, hasWallet?: boolean): void {\n const cacheKey = this.getCacheKey(contractAddress, chainId, chainType);\n if (hasWallet === undefined || hasWallet) {\n this.walletStrategies.delete(cacheKey);\n }\n if (hasWallet === undefined || !hasWallet) {\n this.readOnlyStrategies.delete(cacheKey);\n }\n }\n}\n\nexport const strategyCache = new StrategyCache();\n","import { WalletFactory } from '@sign-global/tokentable-wallets';\nimport {\n bindWallet,\n checkEligibility,\n checkGetSignatures,\n connectGoogleApi,\n connectTwitter,\n disconnectRecipient,\n getAirdropProject,\n cleanUrlParams,\n isMobile,\n getChainRpc,\n CONST,\n EvmSignatureAirdropService,\n SolanaSignatureAirdropService,\n AirdropSigIdentityTypeEnum,\n ChainId,\n ErrorCode,\n IAirdropOptions,\n IAirdropSignatureClaim,\n IAirdropSignatureIdentity,\n IClaimSignature,\n IProject,\n IWalletClient,\n SolanaWalletState,\n ViemWalletClient,\n ChainType\n} from '@sign-global/tokentable-core';\n\nexport class SignatureAirdropClient {\n private projectId?: string;\n private endpoint?: string;\n private project: IProject | undefined;\n private chainRpc?: string;\n protected claims?: IAirdropSignatureClaim[];\n protected identities?: IAirdropSignatureIdentity[];\n private projectPromise: Promise<void> | undefined;\n private authPromise: Promise<void> | undefined;\n private strategyCache: Map<string, EvmSignatureAirdropService | SolanaSignatureAirdropService> = new Map();\n constructor(params: IAirdropOptions) {\n this.projectId = params.projectId;\n this.endpoint = params.endpoint;\n this.chainRpc = params.chainRpc;\n if (this.project) {\n this.project = params.project;\n } else {\n this.projectPromise = this.initializeProjects();\n }\n if (isMobile()) {\n this.authPromise = this.checkAndHandleTwitterCode();\n }\n }\n\n private readonly LOCAL_STORAGE_SID_PREFIX = 'sid_';\n\n private async checkAndHandleTwitterCode() {\n try {\n const urlParams = new URLSearchParams(window.location.search);\n const code = urlParams.get('code');\n const type = urlParams.get('type');\n\n if (code && this.projectId) {\n let res;\n if (type === 'twitter') {\n res = await connectTwitter({ code, projectId: this.projectId }, this.endpoint);\n } else if (type === 'google') {\n res = await connectGoogleApi({ code, projectId: this.projectId }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(this.projectId!, res.sid);\n } else {\n throw new Error('Failed to connect');\n }\n cleanUrlParams(['code', 'type']);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n private setSid(projectId: string, sid: string): void {\n window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);\n }\n\n private async fetchProjectDetails(projectId: string): Promise<void> {\n const project = await getAirdropProject(projectId, this.endpoint);\n this.project = project;\n if (this.chainRpc) return;\n const chainId = project.chainType === ChainType.Evm ? Number(project.chainId) : project.chainId;\n this.chainRpc = getChainRpc(chainId as ChainId);\n }\n\n protected async initializeProjects() {\n try {\n let projectId = this.projectId;\n if (!projectId) {\n return;\n }\n await this.fetchProjectDetails(projectId);\n } catch (error: any) {\n throw new Error(`Failed to initialize project: ${error.message}`);\n }\n }\n\n async getProjectInfo() {\n if (this.projectPromise) {\n await this.projectPromise;\n }\n if (!this.project) throw new Error('Project not found');\n return this.project;\n }\n\n async connectOAuth({\n onSuccess,\n onError,\n type\n }: {\n onSuccess: () => void;\n onError: (error: Error) => void;\n type: AirdropSigIdentityTypeEnum;\n }) {\n const project = await this.getProjectInfo();\n const authorizeUrl = project.identities.find((item: any) => item.identityType === type)?.authorizeUrl;\n if (!authorizeUrl) {\n onError(new Error('Authorize URL not found'));\n return;\n }\n if (isMobile()) {\n const state = encodeURIComponent(window.location.href);\n window.location.href = `${authorizeUrl}&state=${state}`;\n return;\n }\n const onWindowMessage = async (message: any) => {\n const name = message.data?.name;\n if (name && [CONST.TWITTER_AUTH_SUCCESS, CONST.GOOGLE_AUTH_SUCCESS].includes(name)) {\n const { code } = message.data.data || {};\n try {\n let res;\n if (name === CONST.GOOGLE_AUTH_SUCCESS) {\n res = await connectGoogleApi({ code, projectId: project.id }, this.endpoint);\n } else if (name === CONST.TWITTER_AUTH_SUCCESS) {\n res = await connectTwitter({ code, projectId: project.id }, this.endpoint);\n }\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n onSuccess();\n } else {\n onError(new Error('Failed to connect'));\n }\n } catch (error) {\n onError(error as Error);\n } finally {\n window.removeEventListener('message', onWindowMessage);\n }\n }\n };\n\n window.addEventListener('message', onWindowMessage);\n window.open(`${authorizeUrl}&state=state`, `twitter_auth_${project.id}`, 'width=600,height=800');\n }\n\n async connectX({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Twitter\n });\n }\n\n async connectGoogle({ onSuccess, onError }: { onSuccess: () => void; onError: (error: Error) => void }) {\n await this.connectOAuth({\n onSuccess,\n onError,\n type: AirdropSigIdentityTypeEnum.Google\n });\n }\n\n async connectWallet({\n chainType,\n onSuccess,\n onError\n }: {\n chainType: ChainType;\n onSuccess?: (address: string) => void;\n onError?: (error: any) => void;\n }) {\n try {\n const project = await this.getProjectInfo();\n const wallet = WalletFactory.getWallet(chainType);\n const timestamp = Date.now();\n const recipientTypeMap = {\n [ChainType.Evm]: AirdropSigIdentityTypeEnum.EVMWallet,\n [ChainType.Solana]: AirdropSigIdentityTypeEnum.SolanaWallet,\n [ChainType.Ton]: AirdropSigIdentityTypeEnum.TONWallet\n };\n const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');\n const signResult = await wallet.signin(msg, false);\n await wallet.disconnect();\n const { message, signature, signedMessage } = signResult || {};\n\n if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {\n onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);\n return;\n }\n\n const payload = {\n signature: signature as string,\n message: message as string,\n key: wallet.publicKey || wallet.address!,\n address: wallet.address!,\n projectId: project.id,\n timestamp: timestamp,\n recipientType: recipientTypeMap[chainType],\n encodedMessage: signedMessage\n };\n\n const res = await bindWallet(payload, this.endpoint);\n if (res?.sid) {\n this.setSid(project.id, res?.sid);\n }\n onSuccess?.(wallet.address!);\n } catch (error) {\n onError?.(error);\n }\n }\n\n async getClaims() {\n const project = await this.getProjectInfo();\n if (this.authPromise) {\n await this.authPromise;\n }\n const res = await checkEligibility(\n {\n projectId: project.id\n },\n this.endpoint\n );\n this.claims = res.claims;\n this.identities = res.identities;\n return res;\n }\n\n public async disconnectIdentity({\n recipientType,\n recipient\n }: {\n recipientType: AirdropSigIdentityTypeEnum;\n recipient?: string;\n }) {\n const project = await this.getProjectInfo();\n return await disconnectRecipient(\n {\n projectId: project.id,\n recipientType,\n recipient\n },\n this.endpoint\n );\n }\n\n public async getStrategy(\n walletClient?: IWalletClient\n ): Promise<EvmSignatureAirdropService | SolanaSignatureAirdropService> {\n const project = await this.getProjectInfo();\n\n const cacheKey = walletClient\n ? project.chainType === ChainType.Evm\n ? (walletClient as ViemWalletClient).account?.address!\n : project.chainType === ChainType.Solana\n ? (walletClient as SolanaWalletState).publicKey!.toString()\n : 'walletClient'\n : 'default';\n if (this.strategyCache.has(cacheKey)) {\n return this.strategyCache.get(cacheKey)!;\n }\n\n const strategy =\n project.chainType === ChainType.Solana\n ? new SolanaSignatureAirdropService({\n chainId: project.chainId,\n projectId: project.id,\n token: project.tokenAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n })\n : new EvmSignatureAirdropService({\n chainId: Number(project.chainId) as ChainId,\n contractAddress: project.contractAddress,\n walletClient: walletClient as any,\n chainRpc: this.chainRpc!\n });\n this.strategyCache.set(cacheKey, strategy);\n return strategy;\n }\n\n async getVersion(): Promise<string> {\n const strategy = await this.getStrategy();\n return strategy.getVersion();\n }\n\n // solana prams need to wallet\n async getClaimFee(amount?: bigint, walletClient?: IWalletClient): Promise<undefined | bigint> {\n const strategy = await this.getStrategy(walletClient);\n if (!strategy.getClaimFee) {\n throw new Error('getClaimFee is not supported for this chain');\n }\n return await strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(1));\n }\n\n async claimAirdrop({\n claimIds,\n walletClient,\n recipient\n }: {\n claimIds: string[];\n walletClient: IWalletClient;\n recipient: string;\n }) {\n if (!claimIds.length) {\n throw new Error('Claim IDs cannot be empty');\n }\n if (!walletClient) {\n throw new Error('Wallet client is required');\n }\n if (!this.claims?.length) {\n throw new Error('No claims available');\n }\n const service = await this.getStrategy(walletClient);\n const project = await this.getProjectInfo();\n const res = await checkGetSignatures(\n {\n claimIds,\n projectId: this.projectId!,\n recipient\n },\n this.endpoint\n );\n if (!res?.signatures?.length) {\n throw new Error('Failed to get signatures');\n }\n const signatureMap = res?.signatures?.reduce(\n (map, item) => {\n map[item.claimId] = item;\n return map;\n },\n {} as Record<string, IClaimSignature>\n );\n const filteredClaims = this.claims.filter((it) => claimIds.includes(it.claimId));\n if (!filteredClaims.length) {\n throw new Error('No matching claims found');\n }\n\n // only evm use\n const defaultRecipient =\n project.chainType === ChainType.Evm ? (walletClient as ViemWalletClient).account?.address! : '';\n\n const claimData = filteredClaims.map((it) => {\n const signature = signatureMap[it.claimId];\n if (!signature) {\n throw new Error(`Signature not found for claim ID: ${it.claimId}`);\n }\n\n return {\n ...it,\n recipient: recipient ? recipient : defaultRecipient,\n ...signature\n };\n });\n\n const hash = (await service!.claim(claimData, recipient)) as `0x${string}`;\n return hash;\n }\n\n async batchCheckClaimed(): Promise<boolean[]> {\n if (!this.claims?.length) return [];\n const strategy = await this.getStrategy();\n if (!strategy.batchFetchClaimed) {\n throw new Error('batchCheckClaimed is not supported for this chain');\n }\n const claimIds = this.claims?.map((it) => it.claimId);\n return strategy.batchFetchClaimed(claimIds);\n }\n\n async getPaused(): Promise<boolean> {\n const strategy = await this.getStrategy();\n if (!strategy.getPaused) {\n throw new Error('getPaused is not supported for this chain');\n }\n return strategy.getPaused();\n }\n}\n","export { AirdropClient } from './AirdropClient';\nexport { SignatureAirdropClient } from './SignatureAirdropClient';\nexport * from '@sign-global/tokentable-core';\nexport * from '@sign-global/tokentable-wallets';\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,aAAAA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;;;ACjBP,SAAS,iBAAgC;;;ACAzC,SAAS,yBAAiD;AAInD,IAAM,qBAAN,MAAqD;AAAA,EAClD;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EACA,gBAA+B;AAAA,EAEvC,YAAY,QAKT;AACD,SAAK,kBAAkB,OAAO;AAC9B,SAAK,UAAU,OAAO,OAAO,OAAO;AACpC,SAAK,WAAW,OAAO;AACvB,QAAI,OAAO,cAAc;AACvB,WAAK,eAAe,OAAO;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,cAA6C;AAC5D,QAAI,cAAc;AAChB,WAAK,eAAe;AAAA,IACtB;AACA,SAAK,UAAU,IAAI,kBAAkB;AAAA,MACnC,iBAAiB,KAAK;AAAA,MACtB,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,UAAU,KAAK;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,gBAAyB;AACvB,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA,EAEA,MAAM,aAA8B;AAClC,QAAI,KAAK,eAAe;AACtB,aAAO,KAAK;AAAA,IACd;AACA,QAAI,CAAC,K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U;AAAA,EAC5B;AACF;;;ACpYA,cAAc;AACd,cAAc;","names":["ChainType","ChainType","getAirdropProject","getChainRpc","ChainType"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sign-global/tokentable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@tonconnect/sdk": "^3.0.6",
|
|
30
30
|
"tonweb": "^0.0.66",
|
|
31
31
|
"viem": "^2.0.0",
|
|
32
|
-
"@sign-global/tokentable-core": "1.
|
|
33
|
-
"@sign-global/tokentable-wallets": "1.
|
|
32
|
+
"@sign-global/tokentable-core": "1.1.0",
|
|
33
|
+
"@sign-global/tokentable-wallets": "1.1.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
package/src/AirdropClient.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class AirdropClient {
|
|
|
29
29
|
protected chainRpc?: string;
|
|
30
30
|
protected claims?: IAirdropClaim[];
|
|
31
31
|
private projectPromise: Promise<void> | undefined;
|
|
32
|
-
private claimHook: ((
|
|
32
|
+
private claimHook: ((claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) | undefined;
|
|
33
33
|
private contractConfig: IContractConfig | null = null;
|
|
34
34
|
|
|
35
35
|
constructor(params: IAirdropOptions) {
|
|
@@ -170,7 +170,7 @@ export class AirdropClient {
|
|
|
170
170
|
return claimData;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
setClaimHook(fn: (
|
|
173
|
+
setClaimHook(fn: (claimData: IAirdropClaim) => { isLegacy: boolean; attestationId: bigint }) {
|
|
174
174
|
this.claimHook = fn;
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -181,13 +181,21 @@ export class AirdropClient {
|
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
private async calculateClaimFee(project: IProject,
|
|
184
|
+
private async calculateClaimFee(project: IProject, claimData: IAirdropClaim): Promise<string | bigint | undefined> {
|
|
185
|
+
const claimAmount = claimData.amount;
|
|
185
186
|
if (project.chainType === ChainType.Evm) {
|
|
186
187
|
const version = await this.getVersion();
|
|
187
188
|
const isNativeFreeVersion =
|
|
188
189
|
project.tokenType === ETokenType.Native &&
|
|
189
190
|
[EvmAirdropVersionEnum.V3, EvmAirdropVersionEnum.V4].includes(version as EvmAirdropVersionEnum);
|
|
190
|
-
|
|
191
|
+
if (isNativeFreeVersion) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
if (version.includes('TokenTableMerkleDistributorWithFees')) {
|
|
195
|
+
const fees = claimData.fees;
|
|
196
|
+
return fees ? BigInt(fees) : '0';
|
|
197
|
+
}
|
|
198
|
+
return await this.getClaimFee(BigInt(claimAmount));
|
|
191
199
|
}
|
|
192
200
|
|
|
193
201
|
if (project.chainType === ChainType.Ton) {
|
|
@@ -215,7 +223,7 @@ export class AirdropClient {
|
|
|
215
223
|
: this.getDefaultExtraData();
|
|
216
224
|
|
|
217
225
|
// Calculate claim value based on project type
|
|
218
|
-
const value = await this.calculateClaimFee(project, claimData
|
|
226
|
+
const value = await this.calculateClaimFee(project, claimData);
|
|
219
227
|
|
|
220
228
|
// Execute claim with processed data
|
|
221
229
|
return strategy.claim(
|
|
@@ -196,7 +196,7 @@ export class SignatureAirdropClient {
|
|
|
196
196
|
const msg = [project.id, recipientTypeMap[chainType], timestamp].join(',');
|
|
197
197
|
const signResult = await wallet.signin(msg, false);
|
|
198
198
|
await wallet.disconnect();
|
|
199
|
-
const { message, signature } = signResult || {};
|
|
199
|
+
const { message, signature, signedMessage } = signResult || {};
|
|
200
200
|
|
|
201
201
|
if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {
|
|
202
202
|
onError?.(ErrorCode.WALLET_ALREADY_CONNECTED);
|
|
@@ -210,7 +210,8 @@ export class SignatureAirdropClient {
|
|
|
210
210
|
address: wallet.address!,
|
|
211
211
|
projectId: project.id,
|
|
212
212
|
timestamp: timestamp,
|
|
213
|
-
recipientType: recipientTypeMap[chainType]
|
|
213
|
+
recipientType: recipientTypeMap[chainType],
|
|
214
|
+
encodedMessage: signedMessage
|
|
214
215
|
};
|
|
215
216
|
|
|
216
217
|
const res = await bindWallet(payload, this.endpoint);
|