@sign-global/tokentable 0.4.1-beta.4 → 0.4.1-beta.5
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/dist/cjs/airdrop/SignatureAirdropClient.d.ts +2 -1
- package/dist/cjs/airdrop/SignatureAirdropClient.js +25 -13
- package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -1
- package/dist/cjs/airdrop/common/index.d.ts +35 -0
- package/dist/cjs/airdrop/constants/chain-config.d.ts +36 -0
- package/dist/cjs/airdrop/constants/chain-config.js +5 -0
- package/dist/cjs/airdrop/constants/chain-config.js.map +1 -1
- package/dist/cjs/airdrop/contracts/evm/SignatureAirdropService.d.ts +1 -1
- package/dist/cjs/airdrop/contracts/evm/SignatureAirdropService.js +6 -1
- package/dist/cjs/airdrop/contracts/evm/SignatureAirdropService.js.map +1 -1
- package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.d.ts +1 -0
- package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js +3 -6
- package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
- package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.d.ts +1 -0
- package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js +5 -0
- package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
- package/dist/cjs/airdrop/contracts/solana/SignatureAirdropService.d.ts +2 -2
- package/dist/cjs/airdrop/contracts/solana/SignatureAirdropService.js +3 -9
- package/dist/cjs/airdrop/contracts/solana/SignatureAirdropService.js.map +1 -1
- package/dist/cjs/airdrop/contracts/solana/fee_collector.d.ts +601 -352
- package/dist/cjs/airdrop/contracts/solana/fee_collector.json +1 -1
- package/dist/cjs/airdrop/contracts/solana/fungible_token_distributor_solana.d.ts +939 -504
- package/dist/cjs/airdrop/contracts/solana/fungible_token_distributor_solana.json +2 -2
- package/dist/cjs/airdrop/types/index.d.ts +4 -3
- package/dist/cjs/airdrop/types/index.js.map +1 -1
- package/dist/esm/airdrop/SignatureAirdropClient.d.ts +2 -1
- package/dist/esm/airdrop/SignatureAirdropClient.js +25 -13
- package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -1
- package/dist/esm/airdrop/common/index.d.ts +35 -0
- package/dist/esm/airdrop/constants/chain-config.d.ts +36 -0
- package/dist/esm/airdrop/constants/chain-config.js +6 -1
- package/dist/esm/airdrop/constants/chain-config.js.map +1 -1
- package/dist/esm/airdrop/contracts/evm/SignatureAirdropService.d.ts +1 -1
- package/dist/esm/airdrop/contracts/evm/SignatureAirdropService.js +6 -1
- package/dist/esm/airdrop/contracts/evm/SignatureAirdropService.js.map +1 -1
- package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.d.ts +1 -0
- package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js +3 -6
- package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
- package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.d.ts +1 -0
- package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js +5 -0
- package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
- package/dist/esm/airdrop/contracts/solana/SignatureAirdropService.d.ts +2 -2
- package/dist/esm/airdrop/contracts/solana/SignatureAirdropService.js +3 -9
- package/dist/esm/airdrop/contracts/solana/SignatureAirdropService.js.map +1 -1
- package/dist/esm/airdrop/contracts/solana/fee_collector.d.ts +601 -352
- package/dist/esm/airdrop/contracts/solana/fee_collector.json +1 -1
- package/dist/esm/airdrop/contracts/solana/fungible_token_distributor_solana.d.ts +939 -504
- package/dist/esm/airdrop/contracts/solana/fungible_token_distributor_solana.json +2 -2
- package/dist/esm/airdrop/types/index.d.ts +4 -3
- package/dist/esm/airdrop/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/airdrop/SignatureAirdropClient.ts +38 -22
- package/src/airdrop/constants/chain-config.ts +7 -2
- package/src/airdrop/contracts/evm/SignatureAirdropService.ts +6 -1
- package/src/airdrop/contracts/solana/AirdropSignatureClient.ts +4 -20
- package/src/airdrop/contracts/solana/FeeCollectorClient.ts +6 -0
- package/src/airdrop/contracts/solana/SignatureAirdropService.ts +4 -10
- package/src/airdrop/contracts/solana/fee_collector.json +1 -1
- package/src/airdrop/contracts/solana/fee_collector.ts +679 -430
- package/src/airdrop/contracts/solana/fungible_token_distributor_solana.json +2 -2
- package/src/airdrop/contracts/solana/fungible_token_distributor_solana.ts +1049 -614
- package/src/airdrop/types/index.ts +4 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"address": "
|
|
2
|
+
"address": "FCkSnf5Qd5Jva3ZdjFNGyZNhpCxmvjikXDkpWgE1vD3R",
|
|
3
3
|
"metadata": {
|
|
4
4
|
"name": "fungible_token_distributor_solana",
|
|
5
5
|
"version": "0.1.0",
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
{
|
|
208
208
|
"name": "fee_collector",
|
|
209
209
|
"optional": true,
|
|
210
|
-
"address": "
|
|
210
|
+
"address": "4dfP4CMvznzUuuYLhybXy71zasrhtjrFkChSFjtqS3on"
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
"name": "user_fee",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { TonConnectUI } from '@tonconnect/ui-react';
|
|
1
|
+
import { TonConnectUI as TonWalletClient } from '@tonconnect/ui-react';
|
|
2
2
|
import { AirdropService as TonAirdropService } from '../contracts/ton/AirdropService';
|
|
3
3
|
import { AirdropService as EvmAirdropService } from '../contracts/evm/AirdropService';
|
|
4
4
|
import { ChainConfig } from '../constants';
|
|
5
5
|
import { WalletClient as ViemWalletClient } from 'viem';
|
|
6
|
+
import { WalletContextState as SolanaWalletState } from '@solana/wallet-adapter-react';
|
|
6
7
|
export type ChainId = keyof typeof ChainConfig;
|
|
7
8
|
export interface EvmContractClientOption {
|
|
8
9
|
chainId: ChainId;
|
|
@@ -143,7 +144,8 @@ export declare enum EvmAirdropVersionEnum {
|
|
|
143
144
|
V3 = "0.3.0",// zeta 收费
|
|
144
145
|
V4 = "0.4.0"
|
|
145
146
|
}
|
|
146
|
-
export type IWalletClient =
|
|
147
|
+
export type IWalletClient = TonWalletClient | ViemWalletClient | SolanaWalletState;
|
|
148
|
+
export type { TonWalletClient, ViemWalletClient, SolanaWalletState };
|
|
147
149
|
export type IAirdropService = TonAirdropService | EvmAirdropService;
|
|
148
150
|
type BaseAirdropOptions = {
|
|
149
151
|
endpoint?: string;
|
|
@@ -166,4 +168,3 @@ export interface IContractConfig {
|
|
|
166
168
|
export declare enum ErrorCode {
|
|
167
169
|
WALLET_ALREADY_CONNECTED = "Wallet already connected"
|
|
168
170
|
}
|
|
169
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/airdrop/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/airdrop/types/index.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,8BAAiB,CAAA;AACnB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB;AAsDD,MAAM,CAAN,IAAY,0BAKX;AALD,WAAY,0BAA0B;IACpC,mDAAqB,CAAA;IACrB,4DAA8B,CAAA;IAC9B,sDAAwB,CAAA;IACxB,sDAAwB,CAAA;AAC1B,CAAC,EALW,0BAA0B,KAA1B,0BAA0B,QAKrC;AAUD,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,qCAAuB,CAAA;IACvB,4BAAc,CAAA;AAChB,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AA6DD,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,0CAAiB,CAAA;IACjB,4CAAmB,CAAA;AACrB,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;AAED,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,qCAAY,CAAA,CAAC,yBAAyB;AACxC,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC;AA8BD,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,6BAA6B;IAC7B,kEAAqD,CAAA;AACvD,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getAddress } from 'viem';
|
|
2
1
|
import { CONST } from './constants';
|
|
3
2
|
import { EvmSignatureAirdropService, SolanaSignatureAirdropService } from './contracts';
|
|
4
3
|
import { WalletFactory } from '../wallets';
|
|
@@ -20,7 +19,9 @@ import {
|
|
|
20
19
|
IAirdropSignatureIdentity,
|
|
21
20
|
IClaimSignature,
|
|
22
21
|
IProject,
|
|
23
|
-
IWalletClient
|
|
22
|
+
IWalletClient,
|
|
23
|
+
SolanaWalletState,
|
|
24
|
+
ViemWalletClient
|
|
24
25
|
} from './types';
|
|
25
26
|
import { cleanUrlParams, isMobile } from '../utils';
|
|
26
27
|
|
|
@@ -32,6 +33,7 @@ export class SignatureAirdropClient {
|
|
|
32
33
|
protected identities?: IAirdropSignatureIdentity[];
|
|
33
34
|
private projectPromise: Promise<void> | undefined;
|
|
34
35
|
private twitterPromise: Promise<void> | undefined;
|
|
36
|
+
private strategyCache: Map<string, EvmSignatureAirdropService | SolanaSignatureAirdropService> = new Map();
|
|
35
37
|
constructor(params: IAirdropOptions) {
|
|
36
38
|
this.projectId = params.projectId;
|
|
37
39
|
this.endpoint = params.endpoint;
|
|
@@ -212,19 +214,32 @@ export class SignatureAirdropClient {
|
|
|
212
214
|
): Promise<EvmSignatureAirdropService | SolanaSignatureAirdropService> {
|
|
213
215
|
const project = await this.getProjectInfo();
|
|
214
216
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
const cacheKey = walletClient
|
|
218
|
+
? project.chainType === ChainType.Evm
|
|
219
|
+
? (walletClient as ViemWalletClient).account?.address!
|
|
220
|
+
: project.chainType === ChainType.Solana
|
|
221
|
+
? (walletClient as SolanaWalletState).publicKey!.toString()
|
|
222
|
+
: 'walletClient'
|
|
223
|
+
: 'default';
|
|
224
|
+
if (this.strategyCache.has(cacheKey)) {
|
|
225
|
+
return this.strategyCache.get(cacheKey)!;
|
|
222
226
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
|
|
228
|
+
const strategy =
|
|
229
|
+
project.chainType === ChainType.Solana
|
|
230
|
+
? new SolanaSignatureAirdropService({
|
|
231
|
+
chainId: project.chainId,
|
|
232
|
+
projectId: project.id,
|
|
233
|
+
token: project.tokenAddress,
|
|
234
|
+
walletClient: walletClient as any
|
|
235
|
+
})
|
|
236
|
+
: new EvmSignatureAirdropService({
|
|
237
|
+
chainId: Number(project.chainId) as ChainId,
|
|
238
|
+
contractAddress: project.contractAddress,
|
|
239
|
+
walletClient: walletClient as any
|
|
240
|
+
});
|
|
241
|
+
this.strategyCache.set(cacheKey, strategy);
|
|
242
|
+
return strategy;
|
|
228
243
|
}
|
|
229
244
|
|
|
230
245
|
async getVersion(): Promise<string> {
|
|
@@ -232,7 +247,7 @@ export class SignatureAirdropClient {
|
|
|
232
247
|
return strategy.getVersion();
|
|
233
248
|
}
|
|
234
249
|
|
|
235
|
-
async getClaimFee(amount?: bigint): Promise<undefined | bigint> {
|
|
250
|
+
async getClaimFee(amount?: bigint): Promise<undefined | bigint | string> {
|
|
236
251
|
const strategy = await this.getStrategy();
|
|
237
252
|
if (!strategy.getClaimFee) {
|
|
238
253
|
throw new Error('getClaimFee is not supported for this chain');
|
|
@@ -259,6 +274,7 @@ export class SignatureAirdropClient {
|
|
|
259
274
|
throw new Error('No claims available');
|
|
260
275
|
}
|
|
261
276
|
const service = await this.getStrategy(walletClient);
|
|
277
|
+
const project = await this.getProjectInfo();
|
|
262
278
|
const res = await checkGetSignatures(
|
|
263
279
|
{
|
|
264
280
|
claimIds,
|
|
@@ -278,6 +294,10 @@ export class SignatureAirdropClient {
|
|
|
278
294
|
throw new Error('No matching claims found');
|
|
279
295
|
}
|
|
280
296
|
|
|
297
|
+
// only evm use
|
|
298
|
+
const defaultRecipient =
|
|
299
|
+
project.chainType === ChainType.Evm ? (walletClient as ViemWalletClient).account?.address! : '';
|
|
300
|
+
|
|
281
301
|
const claimData = filteredClaims.map((it) => {
|
|
282
302
|
const signature = signatureMap[it.claimId];
|
|
283
303
|
if (!signature) {
|
|
@@ -286,16 +306,12 @@ export class SignatureAirdropClient {
|
|
|
286
306
|
|
|
287
307
|
return {
|
|
288
308
|
...it,
|
|
289
|
-
recipient: recipient ? recipient :
|
|
309
|
+
recipient: recipient ? recipient : defaultRecipient,
|
|
290
310
|
...signature
|
|
291
311
|
};
|
|
292
312
|
});
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
const hash = (await service!.claim(
|
|
296
|
-
claimData,
|
|
297
|
-
delegateMode ? feeData * BigInt(claimData.length) : feeData
|
|
298
|
-
)) as `0x${string}`;
|
|
313
|
+
|
|
314
|
+
const hash = (await service!.claim(claimData, recipient)) as `0x${string}`;
|
|
299
315
|
return hash;
|
|
300
316
|
}
|
|
301
317
|
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
baseSepolia,
|
|
5
5
|
cyber,
|
|
6
6
|
mainnet,
|
|
7
|
-
mantaTestnet,
|
|
8
7
|
polygonMumbai,
|
|
9
8
|
polygonAmoy,
|
|
10
9
|
sepolia,
|
|
@@ -12,7 +11,8 @@ import {
|
|
|
12
11
|
zetachainAthensTestnet,
|
|
13
12
|
zkSync,
|
|
14
13
|
bsc,
|
|
15
|
-
berachainTestnet
|
|
14
|
+
berachainTestnet,
|
|
15
|
+
arbitrum
|
|
16
16
|
} from 'viem/chains';
|
|
17
17
|
import { mevmDevNet, tonMainNet, tonTestNet } from './network';
|
|
18
18
|
|
|
@@ -49,6 +49,10 @@ export const ChainConfig = {
|
|
|
49
49
|
contractAddress: '0x00aFD4466E4Afa4F43cCd414b1BC65e574ACA2f5',
|
|
50
50
|
rpcUrl: 'https://zetachain-mainnet.g.alchemy.com/v2/1tmk0FrhwTJHXh0XIyae7_SXw1lDCjgs'
|
|
51
51
|
},
|
|
52
|
+
[arbitrum.id]: {
|
|
53
|
+
contractAddress: '0x759ac3CA33FeeAfB8C41aEbC8687A7Bd849Fc87a',
|
|
54
|
+
rpcUrl: arbitrum.rpcUrls.default.http[0]
|
|
55
|
+
},
|
|
52
56
|
[berachainTestnet.id]: {
|
|
53
57
|
contractAddress: '',
|
|
54
58
|
rpcUrl: '',
|
|
@@ -97,6 +101,7 @@ export const SupportedChains = [
|
|
|
97
101
|
polygonMumbai,
|
|
98
102
|
polygonAmoy,
|
|
99
103
|
mevmDevNet,
|
|
104
|
+
arbitrum,
|
|
100
105
|
tonTestNet,
|
|
101
106
|
tonMainNet
|
|
102
107
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAddress } from 'viem';
|
|
1
2
|
import { ZERO_ADDRESS } from '../../constants';
|
|
2
3
|
import { ChainId, EvmContractClientOption } from '../../types';
|
|
3
4
|
import { AirdropSignatureClient } from './contracts/AirdropSignatureClient';
|
|
@@ -87,8 +88,12 @@ export class SignatureAirdropService {
|
|
|
87
88
|
signature: string;
|
|
88
89
|
extraData?: string;
|
|
89
90
|
}[],
|
|
90
|
-
|
|
91
|
+
recipient?: string
|
|
91
92
|
) {
|
|
93
|
+
const defaultRecipient = this.options.walletClient?.account?.address;
|
|
94
|
+
const delegateMode = recipient ? getAddress(recipient) !== defaultRecipient : false;
|
|
95
|
+
const feeData = (await this.getClaimFee(this.options.contractAddress, 1n)) || 0n;
|
|
96
|
+
const value = delegateMode ? feeData * BigInt(data.length) : feeData;
|
|
92
97
|
return this.airdropClient.claim(data, value);
|
|
93
98
|
}
|
|
94
99
|
}
|
|
@@ -29,6 +29,10 @@ export class AirdropSignatureClient extends SolanaContractClientBase<FungibleTok
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
async getClaimFee() {
|
|
33
|
+
return this.FeeCollector.getClaimFee();
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
async getStoragePDA(): Promise<PublicKey> {
|
|
33
37
|
const [storagePDA] = await this.findProgramAddress([
|
|
34
38
|
anchor.utils.bytes.utf8.encode('storage'),
|
|
@@ -172,32 +176,12 @@ export class AirdropSignatureClient extends SolanaContractClientBase<FungibleTok
|
|
|
172
176
|
})
|
|
173
177
|
);
|
|
174
178
|
|
|
175
|
-
console.log(
|
|
176
|
-
anchor.web3.Ed25519Program.programId.toString(),
|
|
177
|
-
{
|
|
178
|
-
publicKey: new PublicKey(config.signer).toBytes(),
|
|
179
|
-
message: Uint8Array.from(hexStrToU8Array(claim.hash)),
|
|
180
|
-
signature: new Uint8Array(hexStrToU8Array(claim.signature))
|
|
181
|
-
},
|
|
182
|
-
'sign'
|
|
183
|
-
);
|
|
184
|
-
|
|
185
179
|
const claimPDA = await this.getClaimPDA(claim.claimId);
|
|
186
180
|
|
|
187
181
|
const decodedData = {
|
|
188
182
|
claimableTimestamp: new anchor.BN(claim.unlockingAt),
|
|
189
183
|
claimableAmount: new anchor.BN(claim.value)
|
|
190
184
|
};
|
|
191
|
-
console.log(
|
|
192
|
-
airdropPDA.toString(),
|
|
193
|
-
claimPDA,
|
|
194
|
-
this.projectId,
|
|
195
|
-
new Uint8Array(hexStrToU8Array(claim.claimId)),
|
|
196
|
-
[],
|
|
197
|
-
decodedData,
|
|
198
|
-
Buffer.from(hexStrToU8Array(claim.signature)),
|
|
199
|
-
'txdata'
|
|
200
|
-
);
|
|
201
185
|
|
|
202
186
|
tx.add(
|
|
203
187
|
await this.program.methods
|
|
@@ -31,4 +31,10 @@ export class FeeCollectorClient extends SolanaContractClientBase<FeeCollector> {
|
|
|
31
31
|
async setDefaultFee(fee: string) {
|
|
32
32
|
return this.invokeInstruction('setDefaultFee', {}, [new anchor.BN(fee)]);
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
async getClaimFee(): Promise<string> {
|
|
36
|
+
const storagePDA = await this.getStoragePDA();
|
|
37
|
+
const storageData = await this.program.account.feeCollectorStorage.fetch(storagePDA);
|
|
38
|
+
return storageData.defaultFeesBips.toString();
|
|
39
|
+
}
|
|
34
40
|
}
|
|
@@ -39,15 +39,9 @@ export class SignatureAirdropService {
|
|
|
39
39
|
return '';
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
async getClaimFee(address: string, amount: bigint): Promise<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// return undefined;
|
|
46
|
-
// }
|
|
47
|
-
// const feeClient = this.getFeeClient(feeCollector as string);
|
|
48
|
-
// const fee = (await feeClient.getFee(address, amount)) as bigint;
|
|
49
|
-
// return fee;
|
|
50
|
-
return 0n;
|
|
42
|
+
async getClaimFee(address: string, amount: bigint): Promise<string> {
|
|
43
|
+
const fee = this.airdropClient.getClaimFee();
|
|
44
|
+
return fee;
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
async batchFetchClaimed(userClaimIds: string[]): Promise<boolean[]> {
|
|
@@ -70,7 +64,7 @@ export class SignatureAirdropService {
|
|
|
70
64
|
value: string;
|
|
71
65
|
hash: string;
|
|
72
66
|
}[],
|
|
73
|
-
|
|
67
|
+
recipient?: string
|
|
74
68
|
) {
|
|
75
69
|
return this.airdropClient.claim(data);
|
|
76
70
|
}
|