@sign-global/tokentable 0.4.0-beta.3 → 0.4.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +10 -2
  2. package/dist/cjs/airdrop/SignatureAirdropClient.js +57 -10
  3. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -1
  4. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.d.ts +22 -0
  5. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js +68 -0
  6. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  7. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +2 -2
  8. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js +4 -12
  9. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -1
  10. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +1 -1
  11. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +6 -3
  12. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -1
  13. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +1 -1
  14. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +6 -3
  15. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -1
  16. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +1 -1
  17. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +10 -9
  18. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -1
  19. package/dist/cjs/airdrop/services/index.d.ts +8 -4
  20. package/dist/cjs/airdrop/services/index.js +16 -3
  21. package/dist/cjs/airdrop/services/index.js.map +1 -1
  22. package/dist/cjs/utils/api-client.d.ts +1 -0
  23. package/dist/cjs/utils/api-client.js +2 -2
  24. package/dist/cjs/utils/api-client.js.map +1 -1
  25. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +10 -2
  26. package/dist/esm/airdrop/SignatureAirdropClient.js +58 -11
  27. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -1
  28. package/dist/esm/airdrop/core/evm/SignatureAirdropService.d.ts +22 -0
  29. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js +64 -0
  30. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  31. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +2 -2
  32. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js +4 -12
  33. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -1
  34. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +1 -1
  35. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +6 -3
  36. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -1
  37. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +1 -1
  38. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +6 -3
  39. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -1
  40. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +1 -1
  41. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +10 -9
  42. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -1
  43. package/dist/esm/airdrop/services/index.d.ts +8 -4
  44. package/dist/esm/airdrop/services/index.js +16 -3
  45. package/dist/esm/airdrop/services/index.js.map +1 -1
  46. package/dist/esm/utils/api-client.d.ts +1 -0
  47. package/dist/esm/utils/api-client.js +2 -2
  48. package/dist/esm/utils/api-client.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/airdrop/SignatureAirdropClient.ts +69 -12
  51. package/src/airdrop/core/evm/SignatureAirdropService.ts +86 -0
  52. package/src/airdrop/core/evm/contracts/AirdropSignatureClient.ts +4 -12
  53. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.ts +6 -3
  54. package/src/airdrop/core/useWeb3ConnectWallet/providers/solana/index.tsx +6 -3
  55. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.ts +16 -12
  56. package/src/airdrop/services/index.ts +22 -7
  57. package/src/utils/api-client.ts +3 -2
@@ -1,11 +1,11 @@
1
1
  import { CONST } from './constants';
2
+ import { SignatureAirdropService } from './core/evm/SignatureAirdropService';
2
3
  import { WalletFactory } from './core/useWeb3ConnectWallet';
3
4
  import { ChainType } from './core/useWeb3ConnectWallet/types';
4
- import { bindWallet, connectTwitter, getAirdropProject } from './services';
5
- import { AirdropSigIdentityTypeEnum, IAirdropOptions, IProject } from './types';
5
+ import { bindWallet, checkEligibility, connectTwitter, getAirdropProject } from './services';
6
+ import { AirdropSigIdentityTypeEnum, ChainId, IAirdropOptions, IProject, IWalletClient } from './types';
6
7
 
7
8
  export class SignatureAirdropClient {
8
- private slug?: string;
9
9
  private projectId?: string;
10
10
  private endpoint?: string;
11
11
  private project: IProject | undefined;
@@ -14,9 +14,9 @@ export class SignatureAirdropClient {
14
14
  private claimHook: ((v: any) => any) | undefined;
15
15
  // private contractConfig: IContractConfig | null = null;
16
16
  constructor(params: IAirdropOptions) {
17
- if ('slug' in params) {
18
- this.slug = params.slug;
19
- }
17
+ // if ('slug' in params) {
18
+ // this.slug = params.slug;
19
+ // }
20
20
  this.projectId = params.projectId;
21
21
  this.endpoint = params.endpoint;
22
22
  if (this.project) {
@@ -56,13 +56,12 @@ export class SignatureAirdropClient {
56
56
  const project = await this.getProjectInfo();
57
57
  const onWindowMessage = async (message: any) => {
58
58
  if (message.data.name && message.data.name === CONST.TWITTER_AUTH_SUCCESS) {
59
- const { isError, code, redirectUri } = message.data.data || {};
59
+ const { code } = message.data.data || {};
60
60
  try {
61
- await connectTwitter({ code, redirectUri: redirectUri }, this.endpoint);
61
+ const res = await connectTwitter({ code, projectId: project.id }, this.endpoint);
62
+
63
+ if (res?.sid) window.localStorage.setItem('sid_' + project.id, res?.sid);
62
64
  onSuccess();
63
- if (isError) {
64
- onError();
65
- }
66
65
  } catch (error) {
67
66
  onError();
68
67
  } finally {
@@ -110,10 +109,68 @@ export class SignatureAirdropClient {
110
109
  recipientType: recipientTypeMap[chainType]
111
110
  };
112
111
 
113
- await bindWallet(payload, this.endpoint);
112
+ const res = await bindWallet(payload, this.endpoint);
113
+ if (res?.sid) window.localStorage.setItem('sid_' + project.id, res?.sid);
114
114
  onSuccess?.();
115
115
  } catch (error) {
116
116
  onError?.(error);
117
117
  }
118
118
  }
119
+
120
+ async getClaims() {
121
+ const project = await this.getProjectInfo();
122
+ const res = await checkEligibility(
123
+ {
124
+ projectId: project.id
125
+ },
126
+ this.endpoint
127
+ );
128
+ this.claims = res.claims;
129
+ return this.claims;
130
+ }
131
+
132
+ public async getStrategy(walletClient?: IWalletClient): Promise<SignatureAirdropService> {
133
+ const project = await this.getProjectInfo();
134
+
135
+ return new SignatureAirdropService({
136
+ chainId: Number(project.chainId) as ChainId,
137
+ contractAddress: project.contractAddress,
138
+ walletClient: walletClient as any
139
+ });
140
+ }
141
+
142
+ async getClaimFee(amount?: bigint): Promise<bigint> {
143
+ const strategy = await this.getStrategy();
144
+ if (!strategy.getClaimFee) {
145
+ throw new Error('getClaimFee is not supported for this chain');
146
+ }
147
+ return strategy.getClaimFee(this.project?.contractAddress || '', amount || BigInt(0)) as unknown as bigint;
148
+ }
149
+
150
+ async claimAirdrop({ claimIds, walletClient }: { claimIds: string[]; walletClient: IWalletClient }) {
151
+ const service = await this.getStrategy(walletClient);
152
+ const claimData = this.claims?.filter((it) => claimIds.includes(it.claimId)) || [];
153
+ let delegateMode = false;
154
+ claimData.forEach((it) => {
155
+ if (it.recipient !== walletClient.account?.address) {
156
+ delegateMode = true;
157
+ }
158
+ });
159
+ const feeData = await this.getClaimFee(1n);
160
+ const hash = (await service!.claim(
161
+ claimData,
162
+ delegateMode ? feeData * BigInt(claimData.length) : feeData
163
+ )) as unknown as `0x${string}`;
164
+ return hash;
165
+ }
166
+
167
+ async batchCheckClaimed(): Promise<boolean[]> {
168
+ const strategy = await this.getStrategy();
169
+ if (!strategy.batchFetchClaimed) {
170
+ throw new Error('batchCheckClaimed is not supported for this chain');
171
+ }
172
+ const claimIds = this.claims?.map((it) => it.claimId);
173
+ if (!claimIds) return [];
174
+ return strategy.batchFetchClaimed(claimIds);
175
+ }
119
176
  }
@@ -0,0 +1,86 @@
1
+ import { ZERO_ADDRESS } from '../../constants';
2
+ import { ChainId, EvmContractClientOption } from '../../types';
3
+ import { AirdropSignatureClient } from './contracts/AirdropSignatureClient';
4
+ import { DeployerClient } from './contracts/DeployClient';
5
+ import { FeeCollectorClient } from './contracts/FeeCollectorClient';
6
+
7
+ export class SignatureAirdropService {
8
+ options: EvmContractClientOption;
9
+ constructor(options: EvmContractClientOption) {
10
+ this.options = options;
11
+ }
12
+
13
+ private get airdropClient(): AirdropSignatureClient {
14
+ if (!this.options) {
15
+ throw new Error('options is empty');
16
+ }
17
+
18
+ return new AirdropSignatureClient(this.options);
19
+ }
20
+
21
+ async getDeployerClient(): Promise<DeployerClient> {
22
+ const deployer = await this.getDeployer();
23
+ return new DeployerClient({
24
+ ...this.options,
25
+ contractAddress: deployer
26
+ });
27
+ }
28
+
29
+ private getFeeClient(address: string): FeeCollectorClient {
30
+ if (!this.options) {
31
+ throw new Error('options is empty');
32
+ }
33
+
34
+ return new FeeCollectorClient({
35
+ ...this.options,
36
+ chainId: this.options.chainId as ChainId,
37
+ contractAddress: address
38
+ });
39
+ }
40
+
41
+ async getDeployer() {
42
+ return this.airdropClient.getDeployer();
43
+ }
44
+
45
+ feeCollectors = async (address: string) => {
46
+ const deployerClient = await this.getDeployerClient();
47
+ return await deployerClient.feeCollectors(address);
48
+ };
49
+
50
+ feeTokens = async (address: string) => {
51
+ const deployerClient = await this.getDeployerClient();
52
+ return await deployerClient.feeTokens(address);
53
+ };
54
+
55
+ async getFeelessThreshold() {
56
+ // return this.airdropClient.getFeelessThreshold();
57
+ }
58
+
59
+ async getClaimFee(address: string, amount: bigint): Promise<bigint | undefined> {
60
+ const feeCollector = await this.feeCollectors(this.options.contractAddress as string);
61
+ if (!feeCollector || feeCollector === ZERO_ADDRESS) {
62
+ return undefined;
63
+ }
64
+ const feeClient = this.getFeeClient(feeCollector as string);
65
+ const fee = await feeClient.getFee(address, amount);
66
+ return fee;
67
+ }
68
+
69
+ async batchFetchClaimed(userClaimIds: string[]): Promise<boolean[]> {
70
+ const res = await this.airdropClient.batchFetchClaimed(userClaimIds);
71
+ return res;
72
+ }
73
+
74
+ async claim(
75
+ data: {
76
+ recipient: string;
77
+ group: string;
78
+ data: string;
79
+ signature: string;
80
+ extraData: string;
81
+ }[],
82
+ value?: bigint
83
+ ) {
84
+ return this.airdropClient.claim(data, value);
85
+ }
86
+ }
@@ -40,20 +40,12 @@ export class AirdropSignatureClient extends ContractBaseClient {
40
40
  }
41
41
 
42
42
  async batchFetchClaimed(userClaimIds: string[]) {
43
- // return this.multiCall({
44
- // chainId: this.chainId as any,
45
- // contracts: userClaimIds?.map((userClaimId) => {
46
- // return {
47
- // address: this.contractAddress,
48
- // abi: this.abi,
49
- // functionName: 'getClaimStatus',
50
- // args: [userClaimId]
51
- // };
52
- // })
53
- // });
43
+ const res: any = await this.readContract({ functionName: 'getClaimStatus', args: [userClaimIds] });
44
+ return res;
54
45
  }
55
46
 
56
47
  async getDeployer() {
57
- return this.readContract({ functionName: 'getDeployer' }) as Promise<string>;
48
+ const res: any = await this.readContract({ functionName: 'getStorage' });
49
+ return res?.[3];
58
50
  }
59
51
  }
@@ -53,13 +53,16 @@ export class EvmWallet extends WalletBase<EVMStoreType> {
53
53
  };
54
54
  }
55
55
 
56
- override async signin(statement?: string): Promise<ISignResult> {
56
+ override async signin(statement: string, prepare = true): Promise<ISignResult> {
57
57
  return new Promise((resolve) => {
58
58
  const signCallback = (data: ReturnType<typeof useAccount>) => {
59
59
  this.address = data.address;
60
60
  this.chainId = data.chainId;
61
- const msg = prepareSignMessage({ statement, chainId: data.chainId!, address: data.address! });
62
- const fullMessage = get4361Message(msg);
61
+ let fullMessage = statement;
62
+ if (prepare) {
63
+ const msg = prepareSignMessage({ statement, chainId: data.chainId!, address: data.address! });
64
+ fullMessage = get4361Message(msg);
65
+ }
63
66
 
64
67
  const res = this.sign(fullMessage);
65
68
 
@@ -63,14 +63,17 @@ export class SolWallet extends WalletBase<SolStoreType> {
63
63
  }
64
64
  }
65
65
 
66
- signin(statement?: string): Promise<ISignResult> {
66
+ signin(statement: string, prepare = true): Promise<ISignResult> {
67
67
  return new Promise((resolve) => {
68
68
  const signCallback = (data: ReturnType<typeof useWallet>) => {
69
69
  this.publicKey = data.publicKey?.toString();
70
70
  this.address = this.publicKey;
71
71
  this.chainId = 1;
72
- const msg = prepareSignMessage({ statement, chainId: '1', address: this.address! });
73
- const fullMessage = get4361Message(msg);
72
+ let fullMessage = statement;
73
+ if (prepare) {
74
+ const msg = prepareSignMessage({ statement, chainId: '1', address: this.address! });
75
+ fullMessage = get4361Message(msg);
76
+ }
74
77
 
75
78
  const res = this.sign(fullMessage);
76
79
 
@@ -57,11 +57,11 @@ export class TonWallet extends WalletBase<TonStoreType> {
57
57
 
58
58
  async sign(originMsg: string): Promise<ISignResult> {
59
59
  const message = await hashSha256(originMsg);
60
- const tonConnectUI = tonStore.walletClient as TonConnectUI;
60
+ const tonConnectUI = tonStore.walletClient as any;
61
61
  // const walletInfo = tonConnectUI?.wallet;
62
62
  const authType = '';
63
63
  // if (walletInfo?.jsBridgeKey && walletInfo?.openMethod !== 'qrcode') {
64
- // authType = walletInfo.jsBridgeKey;
64
+ // authType = walletInfo.jsBridgeKey;
65
65
  // }
66
66
 
67
67
  console.log(this.isConnected, tonConnectUI, 'connected');
@@ -72,12 +72,10 @@ export class TonWallet extends WalletBase<TonStoreType> {
72
72
  if (authType) {
73
73
  const wallets = await tonConnectUI.getWallets();
74
74
 
75
- const currentWallet = wallets.find((wallet) =>
75
+ const currentWallet = wallets.find((wallet: any) =>
76
76
  [wallet.name, wallet.appName].includes(authType)
77
77
  ) as WalletInfoRemote;
78
78
 
79
- console.log(wallets, currentWallet, 'ww');
80
-
81
79
  const link = tonConnectUI.connector.connect(
82
80
  {
83
81
  bridgeUrl: currentWallet.bridgeUrl,
@@ -133,13 +131,19 @@ export class TonWallet extends WalletBase<TonStoreType> {
133
131
  };
134
132
  }
135
133
 
136
- override async signin(statement?: string): Promise<ISignResult> {
137
- const fullMessage = {
138
- statement: statement || 'Welcome to EthSign',
139
- issuedAt: new Date().toISOString(),
140
- nonce: getCustomNaNoId()
141
- };
142
- const signRes = await this.sign(JSON.stringify(fullMessage, null, ' '));
134
+ override async signin(statement: string, prepare = true): Promise<ISignResult> {
135
+ const fullMessage = prepare
136
+ ? JSON.stringify(
137
+ {
138
+ statement: statement || 'Welcome to EthSign',
139
+ issuedAt: new Date().toISOString(),
140
+ nonce: getCustomNaNoId()
141
+ },
142
+ null,
143
+ ' '
144
+ )
145
+ : statement;
146
+ const signRes = await this.sign(fullMessage);
143
147
  return signRes;
144
148
  }
145
149
 
@@ -70,14 +70,25 @@ export const getJettonInfo = async (
70
70
  return client.get(`/airdrop-open/jetton/${data.address}?isTestnet=${data.isTestnet}`);
71
71
  };
72
72
 
73
- export const connectTwitter = async (data: { code: string; redirectUri: string }, baseURL?: string) => {
73
+ export const connectTwitter = async (
74
+ data: { code: string; projectId: string },
75
+ baseURL?: string
76
+ ): Promise<{ sid: string }> => {
74
77
  const client = createApiClient(baseURL);
75
- return client.post('/airdrop-open/connect-twitter', data);
78
+ return client.post('/airdrop-open/connect-twitter', data, {
79
+ headers: {
80
+ sid: window.localStorage.getItem('sid_' + data.projectId) || ''
81
+ }
82
+ });
76
83
  };
77
-
78
- export const checkEligibility = async (data: { projectId: string }, baseURL?: string) => {
84
+ //{{ttApi}}/airdrop-open/check-eligibility
85
+ export const checkEligibility = async (data: { projectId: string }, baseURL?: string): Promise<any> => {
79
86
  const client = createApiClient(baseURL);
80
- return client.post('/airdrop-open/check-eligibility', data);
87
+ return client.post('/airdrop-open/check-eligibility', data, {
88
+ headers: {
89
+ sid: window.localStorage.getItem('sid_' + data.projectId) || ''
90
+ }
91
+ });
81
92
  };
82
93
 
83
94
  export const bindWallet = async (
@@ -90,7 +101,11 @@ export const bindWallet = async (
90
101
  recipientType: string;
91
102
  },
92
103
  baseURL?: string
93
- ) => {
104
+ ): Promise<{ sid: string }> => {
94
105
  const client = createApiClient(baseURL);
95
- return client.post('/airdrop-open/connect-wallet', data);
106
+ return client.post('/airdrop-open/connect-wallet', data, {
107
+ headers: {
108
+ sid: window.localStorage.getItem('sid_' + data.projectId) || ''
109
+ }
110
+ });
96
111
  };
@@ -5,6 +5,7 @@ export type ApiClientOptions = {
5
5
  export type ApiRequestOptions = {
6
6
  params?: Record<string, string | number>;
7
7
  skipHandleError?: boolean;
8
+ headers?: Record<string, string>;
8
9
  };
9
10
 
10
11
  type ApiResponse = {
@@ -48,11 +49,11 @@ export class ApiClient {
48
49
  ): Promise<unknown> {
49
50
  const finalUrl = (this.options?.baseURL || '') + url;
50
51
 
51
- const init: RequestInit = { method };
52
+ const init: RequestInit = { method, headers: options?.headers || {} };
52
53
  if (data instanceof FormData) {
53
54
  init.body = data;
54
55
  } else {
55
- init.headers = { 'content-type': 'application/json' };
56
+ init.headers = { 'content-type': 'application/json', ...init.headers };
56
57
  init.body = data ? JSON.stringify(data) : void 0;
57
58
  }
58
59