@sign-global/tokentable 0.4.2-beta.2 → 0.4.2-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 (119) hide show
  1. package/dist/cjs/airdrop/common/index.d.ts +1 -1
  2. package/dist/cjs/airdrop/constants/chain-config.d.ts +1 -1
  3. package/dist/cjs/airdrop/constants/chain-config.js +1 -1
  4. package/dist/cjs/airdrop/constants/chain-config.js.map +1 -1
  5. package/dist/esm/airdrop/common/index.d.ts +1 -1
  6. package/dist/esm/airdrop/constants/chain-config.d.ts +1 -1
  7. package/dist/esm/airdrop/constants/chain-config.js +1 -1
  8. package/dist/esm/airdrop/constants/chain-config.js.map +1 -1
  9. package/package.json +2 -9
  10. package/src/airdrop/AirdropClient.ts +0 -307
  11. package/src/airdrop/SignatureAirdropClient.ts +0 -378
  12. package/src/airdrop/common/index.ts +0 -54
  13. package/src/airdrop/common/projectDataForTon.ts +0 -79
  14. package/src/airdrop/constants/chain-config.ts +0 -107
  15. package/src/airdrop/constants/index.ts +0 -9
  16. package/src/airdrop/constants/network.ts +0 -78
  17. package/src/airdrop/contracts/evm/AirdropService.ts +0 -181
  18. package/src/airdrop/contracts/evm/SignatureAirdropService.ts +0 -114
  19. package/src/airdrop/contracts/evm/contracts/AirdropSignatureClient.ts +0 -63
  20. package/src/airdrop/contracts/evm/contracts/AirdropSignatureFeeClient.ts +0 -61
  21. package/src/airdrop/contracts/evm/contracts/AirdropV2Client.ts +0 -37
  22. package/src/airdrop/contracts/evm/contracts/AirdropV3Client.ts +0 -49
  23. package/src/airdrop/contracts/evm/contracts/AirdropV3FeeClient.ts +0 -16
  24. package/src/airdrop/contracts/evm/contracts/AirdropV4Client.ts +0 -36
  25. package/src/airdrop/contracts/evm/contracts/ContractBaseClient.ts +0 -85
  26. package/src/airdrop/contracts/evm/contracts/DeployClient.ts +0 -35
  27. package/src/airdrop/contracts/evm/contracts/FeeCollectorClient.ts +0 -21
  28. package/src/airdrop/contracts/evm/contracts/KycClient.ts +0 -21
  29. package/src/airdrop/contracts/evm/contracts/abis/Airdrop.json +0 -674
  30. package/src/airdrop/contracts/evm/contracts/abis/AirdropV2.json +0 -676
  31. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3.json +0 -740
  32. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3_Fee.json +0 -678
  33. package/src/airdrop/contracts/evm/contracts/abis/CustomFeeNativeAirdropV4.json +0 -701
  34. package/src/airdrop/contracts/evm/contracts/abis/Deployer.json +0 -271
  35. package/src/airdrop/contracts/evm/contracts/abis/ERC721.json +0 -737
  36. package/src/airdrop/contracts/evm/contracts/abis/FeeCollector.json +0 -322
  37. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenECDSADistributor.json +0 -564
  38. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenWithFeesECDSADistributor.json +0 -260
  39. package/src/airdrop/contracts/evm/contracts/abis/KycHook.json +0 -312
  40. package/src/airdrop/contracts/index.ts +0 -4
  41. package/src/airdrop/contracts/solana/AirdropSignatureClient.ts +0 -242
  42. package/src/airdrop/contracts/solana/FeeCollectorClient.ts +0 -43
  43. package/src/airdrop/contracts/solana/SignatureAirdropService.ts +0 -51
  44. package/src/airdrop/contracts/solana/SolanaContractClient.ts +0 -126
  45. package/src/airdrop/contracts/solana/fee_collector.json +0 -1063
  46. package/src/airdrop/contracts/solana/fee_collector.ts +0 -1069
  47. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.json +0 -1573
  48. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.ts +0 -1579
  49. package/src/airdrop/contracts/ton/AirdropClientV1.ts +0 -122
  50. package/src/airdrop/contracts/ton/AirdropClientV2.ts +0 -118
  51. package/src/airdrop/contracts/ton/AirdropClientV21.ts +0 -131
  52. package/src/airdrop/contracts/ton/AirdropClientV3.ts +0 -127
  53. package/src/airdrop/contracts/ton/AirdropService.ts +0 -150
  54. package/src/airdrop/contracts/ton/TonContractBaseClient.ts +0 -236
  55. package/src/airdrop/contracts/ton/v1/build/Leaf.compiled.json +0 -1
  56. package/src/airdrop/contracts/ton/v1/build/MerkleTokenDistributor.compiled.json +0 -1
  57. package/src/airdrop/contracts/ton/v1/utils/constants.ts +0 -42
  58. package/src/airdrop/contracts/ton/v1/utils/date.utils.ts +0 -11
  59. package/src/airdrop/contracts/ton/v1/utils/index.ts +0 -3
  60. package/src/airdrop/contracts/ton/v1/utils/ton.utils.ts +0 -84
  61. package/src/airdrop/contracts/ton/v1/wrappers/JettonMinter.ts +0 -81
  62. package/src/airdrop/contracts/ton/v1/wrappers/JettonWallet.ts +0 -73
  63. package/src/airdrop/contracts/ton/v1/wrappers/Leaf.ts +0 -88
  64. package/src/airdrop/contracts/ton/v1/wrappers/MerkleTokenDistributor.ts +0 -317
  65. package/src/airdrop/contracts/ton/v1/wrappers/index.ts +0 -2
  66. package/src/airdrop/contracts/ton/v2/build/Leaf.compiled.json +0 -1
  67. package/src/airdrop/contracts/ton/v2/build/MerkleTokenDistributor.compiled.json +0 -1
  68. package/src/airdrop/contracts/ton/v2/utils/constants.ts +0 -43
  69. package/src/airdrop/contracts/ton/v2/utils/date.utils.ts +0 -11
  70. package/src/airdrop/contracts/ton/v2/utils/index.ts +0 -3
  71. package/src/airdrop/contracts/ton/v2/utils/ton.utils.ts +0 -102
  72. package/src/airdrop/contracts/ton/v2/wrappers/Leaf.ts +0 -69
  73. package/src/airdrop/contracts/ton/v2/wrappers/MerkleTokenDistributor.ts +0 -340
  74. package/src/airdrop/contracts/ton/v2/wrappers/index.ts +0 -2
  75. package/src/airdrop/contracts/ton/v21/build/Leaf.compiled.json +0 -1
  76. package/src/airdrop/contracts/ton/v21/build/MerkleTokenDistributor.compiled.json +0 -1
  77. package/src/airdrop/contracts/ton/v21/utils/constants.ts +0 -48
  78. package/src/airdrop/contracts/ton/v21/utils/date.utils.ts +0 -11
  79. package/src/airdrop/contracts/ton/v21/utils/index.ts +0 -3
  80. package/src/airdrop/contracts/ton/v21/utils/ton.utils.ts +0 -84
  81. package/src/airdrop/contracts/ton/v21/wrappers/Leaf.ts +0 -69
  82. package/src/airdrop/contracts/ton/v21/wrappers/MerkleTokenDistributor.ts +0 -346
  83. package/src/airdrop/contracts/ton/v21/wrappers/index.ts +0 -2
  84. package/src/airdrop/contracts/ton/v3/build/Leaf.compiled.json +0 -1
  85. package/src/airdrop/contracts/ton/v3/build/MerkleTokenDistributor.compiled.json +0 -1
  86. package/src/airdrop/contracts/ton/v3/utils/constants.ts +0 -43
  87. package/src/airdrop/contracts/ton/v3/utils/date.utils.ts +0 -11
  88. package/src/airdrop/contracts/ton/v3/utils/index.ts +0 -3
  89. package/src/airdrop/contracts/ton/v3/utils/ton.utils.ts +0 -84
  90. package/src/airdrop/contracts/ton/v3/wrappers/Leaf.ts +0 -68
  91. package/src/airdrop/contracts/ton/v3/wrappers/MerkleTokenDistributor.ts +0 -316
  92. package/src/airdrop/contracts/ton/v3/wrappers/index.ts +0 -2
  93. package/src/airdrop/index.ts +0 -10
  94. package/src/airdrop/services/index.ts +0 -166
  95. package/src/airdrop/services/wallet-service/ton/WalletService.ts +0 -226
  96. package/src/airdrop/services/wallet-service/ton/index.ts +0 -1
  97. package/src/airdrop/strategies/AirdropStrategyFactory.ts +0 -31
  98. package/src/airdrop/strategies/EvmAirdropStrategy.ts +0 -81
  99. package/src/airdrop/strategies/IAirdropStrategy.ts +0 -26
  100. package/src/airdrop/strategies/StrategyCache.ts +0 -34
  101. package/src/airdrop/strategies/TonAirdropStrategy.ts +0 -77
  102. package/src/airdrop/tests/index.test.ts +0 -387
  103. package/src/airdrop/types/index.ts +0 -200
  104. package/src/index.ts +0 -3
  105. package/src/utils/api-client.ts +0 -69
  106. package/src/utils/index.ts +0 -3
  107. package/src/utils/utils.ts +0 -45
  108. package/src/utils/web3.ts +0 -172
  109. package/src/wallets/WalletBase.ts +0 -92
  110. package/src/wallets/WalletFactory.tsx +0 -35
  111. package/src/wallets/index.ts +0 -3
  112. package/src/wallets/providers/evm/EvmWallet.ts +0 -101
  113. package/src/wallets/providers/evm/index.tsx +0 -56
  114. package/src/wallets/providers/index.ts +0 -4
  115. package/src/wallets/providers/solana/index.tsx +0 -133
  116. package/src/wallets/providers/ton/TonWallet.ts +0 -153
  117. package/src/wallets/providers/ton/index.tsx +0 -41
  118. package/src/wallets/types.ts +0 -45
  119. package/src/wallets/utils/index.ts +0 -61
@@ -1,122 +0,0 @@
1
- import { IAirdropOption, TonContractBaseClient } from './TonContractBaseClient';
2
- import { Address, Cell } from '@ton/core';
3
- import { Leaf, leafConfigToCell, MerkleTokenDistributor } from './v1/wrappers';
4
- import LeafCode from './v1/build/Leaf.compiled.json';
5
- import { IAirdropClaim } from '../../types';
6
- import { TonWalletService } from '../../services';
7
-
8
- export class TonAirdropClientV1 extends TonContractBaseClient {
9
- version = '1.0.0';
10
-
11
- constructor(option: IAirdropOption) {
12
- super(option);
13
- }
14
-
15
- async getVersion() {
16
- const airDropContract = await this.getAirdropContract();
17
- const version = await airDropContract.getVersion();
18
- this.version = version;
19
- return version;
20
- }
21
-
22
- getAirdropContract = async () => {
23
- const provider = await this.getTonClient();
24
- const contract = new MerkleTokenDistributor(Address.parse(this.address));
25
- return provider.open(contract);
26
- };
27
-
28
- async getBaseParams() {
29
- const airDropContract = await this.getAirdropContract();
30
- const [startTime, endTime] = await airDropContract!.getTime();
31
- const token = await airDropContract?.getToken();
32
- const root = await airDropContract?.getRoot();
33
- const deployer = await airDropContract.getDeployer();
34
-
35
- const owner = Address.parse(deployer?.toString()).toString({ bounceable: false });
36
-
37
- const version = this.version || (await airDropContract.getVersion());
38
- return {
39
- startTime: startTime ? String(startTime?.valueOf() / 1000) : '',
40
- endTime: endTime ? String(endTime?.valueOf() / 1000) : '',
41
- token: token?.toString(),
42
- root: root?.toString(),
43
- owner: owner,
44
- version
45
- };
46
- }
47
-
48
- async getFeeInfo() {
49
- const airDropContract = await this.getAirdropContract();
50
- const claimFee = await airDropContract.getClaimFee();
51
- const claimFeeReceiver = await airDropContract.getClaimFeeAddress();
52
- return {
53
- claimFee,
54
- claimFeeReceiver
55
- };
56
- }
57
-
58
- claim = async (claimData: any) => {
59
- const provider = await this.getTonClient();
60
- const airdropContract = await this.getAirdropContract();
61
- const proof = Cell.fromBase64(claimData.proofBoc);
62
-
63
- const index = BigInt(claimData.index);
64
- const leafAddress = await airdropContract!.getLeafAddress(index);
65
- const leaf = provider.open(Leaf.createFromAddress(leafAddress));
66
- const leafCode = Cell.fromBoc(Buffer.from(LeafCode.hex, 'hex'))[0];
67
-
68
- const isDeployed = await provider.isContractDeployed(leafAddress);
69
-
70
- let leafBalanceValue = 1;
71
-
72
- if (isDeployed) {
73
- const leafBalance = await TonWalletService.fetchBalance({
74
- address: leafAddress.toString(),
75
- chainId: this.chainId
76
- });
77
- leafBalanceValue = Number(leafBalance?.value) || 0;
78
- }
79
-
80
- if (!isDeployed || leafBalanceValue <= 0) {
81
- const claimFee = await airdropContract!.getClaimFee();
82
- leaf.sendLeafFees(
83
- this.connection.senderDeploy,
84
- claimFee,
85
- leafCode,
86
- leafConfigToCell({
87
- distributor: airdropContract!.address,
88
- index
89
- })
90
- );
91
- await this.waitForTransaction();
92
- await this.waitForContractDeployment(provider, leafAddress);
93
- }
94
-
95
- const queryId = await leaf.getSeqno();
96
- await leaf.sendClaim(proof, index, queryId);
97
- return null;
98
- };
99
-
100
- checkClaimed = async (claimData: IAirdropClaim) => {
101
- try {
102
- const provider = await this.getTonClient();
103
- const airdropContract = await this.getAirdropContract();
104
-
105
- const index = BigInt(claimData.index);
106
-
107
- const leafAddress = await airdropContract.getLeafAddress(index);
108
-
109
- const isDeployed = await provider.isContractDeployed(leafAddress);
110
-
111
- if (!isDeployed) return false;
112
-
113
- const leaf = new Leaf(leafAddress);
114
- const leafContract = provider.open(leaf);
115
- const isUsed = await leafContract?.getIsUsed();
116
-
117
- return isUsed;
118
- } catch (e: any) {
119
- return false;
120
- }
121
- };
122
- }
@@ -1,118 +0,0 @@
1
- import { TonContractBaseClient, IAirdropOption } from './TonContractBaseClient';
2
- import { Leaf, MerkleTokenDistributor } from './v2/wrappers';
3
- import { Address, Cell, toNano } from '@ton/core';
4
- import { IAirdropClaim } from '../../types';
5
- import LeafCode from './v2/build/Leaf.compiled.json';
6
- import { isBeforeByUnix } from '../../../utils';
7
-
8
- export class TonAirdropClientV2 extends TonContractBaseClient {
9
- version = '2.0.0';
10
-
11
- constructor(option: IAirdropOption) {
12
- super(option);
13
- }
14
-
15
- async getVersion() {
16
- const airDropContract = await this.getAirdropContract();
17
- const version = await airDropContract.getVersion();
18
- this.version = version;
19
- return version;
20
- }
21
-
22
- getAirdropContract = async () => {
23
- const provider = await this.getTonClient();
24
- const contract = new MerkleTokenDistributor(Address.parse(this.address));
25
- return provider.open(contract);
26
- };
27
-
28
- getPaused = async () => {
29
- const airDropContract = await this.getAirdropContract();
30
- return airDropContract?.getPaused();
31
- };
32
-
33
- getFeelessThreshold = async () => {
34
- const airDropContract = await this.getAirdropContract();
35
- return airDropContract?.getFeelessThreshold();
36
- };
37
-
38
- async getBaseParams() {
39
- const airDropContract = await this.getAirdropContract();
40
- const [startTime, endTime] = await airDropContract!.getTime();
41
- const token = await airDropContract?.getToken();
42
- const root = await airDropContract?.getRoot();
43
- const version = this.version || (await airDropContract.getVersion());
44
-
45
- const paused = await airDropContract?.getPaused();
46
-
47
- return {
48
- startTime: startTime ? String(startTime?.valueOf() / 1000) : '',
49
- endTime: endTime ? String(endTime?.valueOf() / 1000) : '',
50
- token: token?.toString(),
51
- root: root?.toString(),
52
- version,
53
- paused
54
- };
55
- }
56
-
57
- async getFeeInfo() {
58
- const airDropContract = await this.getAirdropContract();
59
- const claimFee = await airDropContract.getClaimFee();
60
- const claimFeeReceiver = await airDropContract.getClaimFeeAddress();
61
- return {
62
- claimFee,
63
- claimFeeReceiver
64
- };
65
- }
66
-
67
- claim = async (claimData: IAirdropClaim & { value: string | null }, options?: { onLoading?: () => void }) => {
68
- const provider = await this.getTonClient();
69
- const airdropContract = await this.getAirdropContract();
70
- const index = BigInt(claimData.index);
71
- const claimFee = claimData.value ? toNano(claimData.value) : await airdropContract!.getClaimFee();
72
- const proof = Cell.fromBase64(claimData.proofBoc);
73
-
74
- const leafCode = Cell.fromBoc(Buffer.from(LeafCode.hex, 'hex'))[0];
75
-
76
- const leaf = provider.open(
77
- Leaf.createFromConfig(
78
- {
79
- distributor: airdropContract.address,
80
- index
81
- },
82
- leafCode
83
- )
84
- );
85
-
86
- leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
87
- const res = await this.waitForTransaction(options?.onLoading);
88
- if (res) {
89
- console.log(res, res.event_id, 'res');
90
- }
91
- return res;
92
- };
93
-
94
- checkClaimed = async (claimData: IAirdropClaim) => {
95
- try {
96
- if (isBeforeByUnix(claimData.unlockingAt)) return false;
97
- const provider = await this.getTonClient();
98
- const airdropContract = await this.getAirdropContract();
99
-
100
- const index = BigInt(claimData.index);
101
-
102
- const leafAddress = await airdropContract.getLeafAddress(index);
103
-
104
- const isDeployed = await provider.isContractDeployed(leafAddress);
105
-
106
- if (!isDeployed) return false;
107
-
108
- const leaf = new Leaf(leafAddress);
109
- const leafContract = provider.open(leaf);
110
- const isUsed = await leafContract?.getIsUsed();
111
-
112
- return isUsed;
113
- } catch (e: any) {
114
- console.log(e, 'check claim err');
115
- return false;
116
- }
117
- };
118
- }
@@ -1,131 +0,0 @@
1
- import { TonContractBaseClient, IAirdropOption } from './TonContractBaseClient';
2
- import { Leaf, MerkleTokenDistributor } from './v21/wrappers';
3
- import { Address, Cell, fromNano, toNano } from '@ton/core';
4
- import { IAirdropClaim } from '../../types';
5
- import LeafCode from './v21/build/Leaf.compiled.json';
6
- import { isBeforeByUnix } from '../../../utils';
7
-
8
- export class TonAirdropClientV21 extends TonContractBaseClient {
9
- version = '21.0.0';
10
-
11
- constructor(option: IAirdropOption) {
12
- super(option);
13
- }
14
-
15
- async getVersion() {
16
- const airDropContract = await this.getAirdropContract();
17
- const version = await airDropContract.getVersion();
18
- this.version = version;
19
- return version;
20
- }
21
-
22
- getAirdropContract = async () => {
23
- const provider = await this.getTonClient();
24
- const contract = new MerkleTokenDistributor(Address.parse(this.address));
25
- return provider.open(contract);
26
- };
27
-
28
- getPaused = async () => {
29
- const airDropContract = await this.getAirdropContract();
30
- return airDropContract?.getPaused();
31
- };
32
-
33
- async getBaseParams() {
34
- const airDropContract = await this.getAirdropContract();
35
- const [startTime, endTime] = await airDropContract!.getTime();
36
- const root = await airDropContract?.getRoot();
37
- const adminAddress = await airDropContract?.getAdminAddress();
38
-
39
- const owner = Address.parse(adminAddress?.toString()).toString({ bounceable: false });
40
-
41
- const version = this.version || (await airDropContract.getVersion());
42
-
43
- const feelessThreshold = await airDropContract?.getFeelessThreshold();
44
- const paused = await airDropContract?.getPaused();
45
- return {
46
- startTime: startTime ? String(startTime?.valueOf() / 1000) : '',
47
- endTime: endTime ? String(endTime?.valueOf() / 1000) : '',
48
- root: root?.toString(),
49
- owner: owner,
50
- version,
51
- feelessThreshold: fromNano(feelessThreshold),
52
- paused
53
- };
54
- }
55
-
56
- async getFeeInfo() {
57
- const airDropContract = await this.getAirdropContract();
58
- const claimFee = await airDropContract.getClaimFee();
59
- const claimFeeReceiver = await airDropContract.getClaimFeeAddress();
60
- return {
61
- claimFee,
62
- claimFeeReceiver
63
- };
64
- }
65
-
66
- getFeelessThreshold = async () => {
67
- const airDropContract = await this.getAirdropContract();
68
- return airDropContract?.getFeelessThreshold();
69
- };
70
-
71
- claim = async (claimData: IAirdropClaim & { value: string | null }, options?: { onLoading?: () => void }) => {
72
- const provider = await this.getTonClient();
73
- const airdropContract = await this.getAirdropContract();
74
- const index = BigInt(claimData.index);
75
- const claimFee = claimData.value ? toNano(claimData.value) : await airdropContract!.getClaimFee();
76
- const proof = Cell.fromBase64(claimData.proofBoc);
77
-
78
- const leafCode = Cell.fromBoc(Buffer.from(LeafCode.hex, 'hex'))[0];
79
-
80
- const leaf = provider.open(
81
- Leaf.createFromConfig(
82
- {
83
- distributor: airdropContract.address,
84
- index
85
- },
86
- leafCode
87
- )
88
- );
89
-
90
- leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
91
- const res = await this.waitForTransaction(options?.onLoading);
92
-
93
- // while (!(await provider.isContractDeployed(leafAddress))) {
94
- // console.log('waiting for leaf to deploy');
95
- // await new Promise((resolve) => setTimeout(resolve, 1000));
96
- // }
97
- // // const res = await this.waitForTransactionForLegacy();
98
- if (res) {
99
- console.log(res, res.event_id, 'res');
100
- }
101
- return res;
102
- };
103
-
104
- checkClaimed = async (claimData: IAirdropClaim) => {
105
- try {
106
- if (isBeforeByUnix(claimData.unlockingAt)) return false;
107
- const provider = await this.getTonClient();
108
- const airdropContract = await this.getAirdropContract();
109
-
110
- const index = BigInt(claimData.index);
111
-
112
- const leafAddress = await airdropContract.getLeafAddress(index);
113
-
114
- const isDeployed = await provider.isContractDeployed(leafAddress);
115
-
116
- console.log(index, leafAddress.toString(), isDeployed, 'index');
117
-
118
- if (!isDeployed) return false;
119
-
120
- const leaf = new Leaf(leafAddress);
121
- const leafContract = provider.open(leaf);
122
- const isUsed = await leafContract?.getIsUsed();
123
-
124
- console.log(isUsed, leafAddress.toString(), 'use');
125
- return isUsed;
126
- } catch (e: any) {
127
- console.log(e, 'check claim err');
128
- return false;
129
- }
130
- };
131
- }
@@ -1,127 +0,0 @@
1
- import { TonContractBaseClient, IAirdropOption } from './TonContractBaseClient';
2
- import { Leaf, MerkleTokenDistributor } from './v3/wrappers';
3
- import { Address, Cell, toNano } from '@ton/core';
4
- import { IAirdropClaim } from '../../types';
5
- import LeafCode from './v3/build/Leaf.compiled.json';
6
- import { isBeforeByUnix } from '../../../utils';
7
-
8
- export class TonAirdropClientV3 extends TonContractBaseClient {
9
- version = '11.0.0';
10
-
11
- constructor(option: IAirdropOption) {
12
- super(option);
13
- }
14
-
15
- async getVersion() {
16
- const airDropContract = await this.getAirdropContract();
17
- const version = await airDropContract.getVersion();
18
- this.version = version;
19
- return version;
20
- }
21
-
22
- getAirdropContract = async () => {
23
- const provider = await this.getTonClient();
24
- const contract = new MerkleTokenDistributor(Address.parse(this.address));
25
- return provider.open(contract);
26
- };
27
-
28
- getPaused = async () => {
29
- const airDropContract = await this.getAirdropContract();
30
- return airDropContract?.getPaused();
31
- };
32
-
33
- getFeelessThreshold = async () => {
34
- const airDropContract = await this.getAirdropContract();
35
- return airDropContract?.getFeelessThreshold();
36
- };
37
-
38
- async getBaseParams() {
39
- const airDropContract = await this.getAirdropContract();
40
- const [startTime, endTime] = await airDropContract!.getTime();
41
- const token = await airDropContract?.getToken();
42
- const root = await airDropContract?.getRoot();
43
-
44
- const version = this.version || (await airDropContract.getVersion());
45
-
46
- const paused = await airDropContract?.getPaused();
47
-
48
- return {
49
- startTime: startTime ? String(startTime?.valueOf() / 1000) : '',
50
- endTime: endTime ? String(endTime?.valueOf() / 1000) : '',
51
- token: token?.toString(),
52
- root: root?.toString(),
53
- version,
54
- paused
55
- };
56
- }
57
-
58
- async getFeeInfo() {
59
- const airDropContract = await this.getAirdropContract();
60
- const claimFee = await airDropContract.getClaimFee();
61
- const claimFeeReceiver = await airDropContract.getClaimFeeAddress();
62
- return {
63
- claimFee,
64
- claimFeeReceiver
65
- };
66
- }
67
-
68
- claim = async (claimData: IAirdropClaim & { value: string | null }, options?: { onLoading?: () => void }) => {
69
- // const { provider, airdropContract, claimFee, leafAddress } = prepreData;
70
- const provider = await this.getTonClient();
71
- const airdropContract = await this.getAirdropContract();
72
- const index = BigInt(claimData.index);
73
- // const leafAddress = await airdropContract!.getLeafAddress(index);
74
- const claimFee = claimData.value ? toNano(claimData.value) : await airdropContract!.getClaimFee();
75
- const proof = Cell.fromBase64(claimData.proofBoc);
76
-
77
- const leafCode = Cell.fromBoc(Buffer.from(LeafCode.hex, 'hex'))[0];
78
-
79
- const leaf = provider.open(
80
- Leaf.createFromConfig(
81
- {
82
- distributor: airdropContract.address,
83
- index
84
- },
85
- leafCode
86
- )
87
- );
88
-
89
- leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
90
- const res = await this.waitForTransaction(options?.onLoading);
91
-
92
- // while (!(await provider.isContractDeployed(leafAddress))) {
93
- // console.log('waiting for leaf to deploy');
94
- // await new Promise((resolve) => setTimeout(resolve, 1000));
95
- // }
96
- // // const res = await this.waitForTransactionForLegacy();
97
- if (res) {
98
- console.log(res, res.event_id, 'res');
99
- }
100
- return res;
101
- };
102
-
103
- checkClaimed = async (claimData: IAirdropClaim) => {
104
- try {
105
- if (isBeforeByUnix(claimData.unlockingAt)) return false;
106
- const provider = await this.getTonClient();
107
- const airdropContract = await this.getAirdropContract();
108
-
109
- const index = BigInt(claimData.index);
110
-
111
- const leafAddress = await airdropContract.getLeafAddress(index);
112
-
113
- const isDeployed = await provider.isContractDeployed(leafAddress);
114
-
115
- if (!isDeployed) return false;
116
-
117
- const leaf = new Leaf(leafAddress);
118
- const leafContract = provider.open(leaf);
119
- const isUsed = await leafContract?.getIsUsed();
120
-
121
- return isUsed;
122
- } catch (e: any) {
123
- console.log(e.toString(), 'check claim err');
124
- return false;
125
- }
126
- };
127
- }
@@ -1,150 +0,0 @@
1
- import { TonAirdropClientV1 } from './AirdropClientV1';
2
- import { TonConnectUI } from '@tonconnect/ui-react';
3
- import { TonAirdropClientV2 } from './AirdropClientV2';
4
- import { IAirdropClaim, TonAirdropVersionEnum } from '../../types';
5
- import { IAirdropOption } from './TonContractBaseClient';
6
- import { TonAirdropClientV3 } from './AirdropClientV3';
7
- import { fromNano } from '@ton/core';
8
- import { TonClient } from '@ton/ton';
9
- import { TonAirdropClientV21 } from './AirdropClientV21';
10
-
11
- export class AirdropService {
12
- private address: string;
13
-
14
- private walletClient?: TonConnectUI;
15
-
16
- private chainId: string;
17
-
18
- private cachedVersion: string | null = null;
19
-
20
- private tonClient?: TonClient;
21
-
22
- constructor(options: IAirdropOption) {
23
- const { chainId, address, walletClient, tonClient, version } = options;
24
- this.address = address;
25
- this.walletClient = walletClient;
26
- this.chainId = chainId;
27
- this.tonClient = tonClient;
28
- if (version) {
29
- this.cachedVersion = version;
30
- }
31
- }
32
-
33
- private get airdropClientV1(): TonAirdropClientV1 {
34
- if (!this?.address) {
35
- throw new Error('Contract address is empty');
36
- }
37
-
38
- return new TonAirdropClientV1({
39
- chainId: this.chainId,
40
- address: this.address,
41
- walletClient: this.walletClient,
42
- tonClient: this.tonClient
43
- });
44
- }
45
-
46
- private get airdropClientV2(): TonAirdropClientV2 {
47
- if (!this?.address) {
48
- throw new Error('Contract address is empty');
49
- }
50
-
51
- return new TonAirdropClientV2({
52
- chainId: this.chainId,
53
- address: this.address,
54
- walletClient: this.walletClient,
55
- tonClient: this.tonClient
56
- });
57
- }
58
-
59
- private get airdropClientV3(): TonAirdropClientV3 {
60
- if (!this?.address) {
61
- throw new Error('Contract address is empty');
62
- }
63
-
64
- return new TonAirdropClientV3({
65
- chainId: this.chainId,
66
- address: this.address,
67
- walletClient: this.walletClient,
68
- tonClient: this.tonClient
69
- });
70
- }
71
-
72
- private get airdropClientV21(): TonAirdropClientV21 {
73
- if (!this?.address) {
74
- throw new Error('Contract address is empty');
75
- }
76
-
77
- return new TonAirdropClientV21({
78
- chainId: this.chainId,
79
- address: this.address,
80
- walletClient: this.walletClient,
81
- tonClient: this.tonClient
82
- });
83
- }
84
-
85
- async getVersion() {
86
- if (this.cachedVersion !== null) {
87
- return this.cachedVersion;
88
- }
89
-
90
- this.cachedVersion = await this.airdropClientV2.getVersion();
91
- return this.cachedVersion;
92
- }
93
-
94
- private async getClient() {
95
- const version = await this.getVersion();
96
-
97
- if (version === TonAirdropVersionEnum.NativeV1) {
98
- return this.airdropClientV21;
99
- }
100
-
101
- if (version === TonAirdropVersionEnum.LiteV1) {
102
- return this.airdropClientV3;
103
- }
104
- return version === TonAirdropVersionEnum.V2 ? this.airdropClientV2 : this.airdropClientV1;
105
- }
106
-
107
- async getAirdropContract() {
108
- const client = await this.getClient();
109
- return client.getAirdropContract();
110
- }
111
-
112
- async claim(claimData: IAirdropClaim & { value: string | null }, options?: { onLoading?: () => void }) {
113
- const client = await this.getClient();
114
- return client.claim(claimData, options);
115
- }
116
-
117
- async checkClaimed(claimData: IAirdropClaim) {
118
- const client = await this.getClient();
119
- return client.checkClaimed(claimData);
120
- }
121
-
122
- async getContractInfo() {
123
- const client = await this.getClient();
124
- return client.getBaseParams();
125
- }
126
-
127
- async getPaused() {
128
- const client = await this.getClient();
129
- if (!(client instanceof TonAirdropClientV1)) {
130
- return client.getPaused();
131
- } else {
132
- return false;
133
- }
134
- }
135
-
136
- async getClaimFeeInfo() {
137
- const client = await this.getClient();
138
- const feeInfo = await client.getFeeInfo();
139
- return {
140
- claimFee: fromNano(feeInfo.claimFee),
141
- claimFeeReceiver: feeInfo.claimFeeReceiver?.toString({ bounceable: false })
142
- };
143
- }
144
-
145
- async getClaimFee(address: string, amount: bigint) {
146
- const client = await this.getClient();
147
- const feeInfo = await client.getFeeInfo();
148
- return fromNano(feeInfo.claimFee);
149
- }
150
- }