@sign-global/tokentable 0.4.3-beta.0 → 0.4.3-beta.1

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 (213) hide show
  1. package/dist/cjs/airdrop/AirdropClient.d.ts +1 -1
  2. package/dist/cjs/airdrop/AirdropClient.js +4 -3
  3. package/dist/cjs/airdrop/AirdropClient.js.map +1 -1
  4. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +10 -1
  5. package/dist/cjs/airdrop/SignatureAirdropClient.js +48 -11
  6. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -1
  7. package/dist/cjs/airdrop/common/index.d.ts +1 -1
  8. package/dist/cjs/airdrop/constants/chain-config.d.ts +1 -1
  9. package/dist/cjs/airdrop/constants/chain-config.js +1 -1
  10. package/dist/cjs/airdrop/constants/chain-config.js.map +1 -1
  11. package/dist/cjs/airdrop/constants/index.d.ts +1 -0
  12. package/dist/cjs/airdrop/constants/index.js +1 -0
  13. package/dist/cjs/airdrop/constants/index.js.map +1 -1
  14. package/dist/cjs/airdrop/contracts/evm/contracts/AirdropSignatureClient.js +0 -1
  15. package/dist/cjs/airdrop/contracts/evm/contracts/AirdropSignatureClient.js.map +1 -1
  16. package/dist/cjs/airdrop/contracts/index.d.ts +1 -0
  17. package/dist/cjs/airdrop/contracts/index.js +3 -1
  18. package/dist/cjs/airdrop/contracts/index.js.map +1 -1
  19. package/dist/cjs/airdrop/contracts/solana/AirdropService.d.ts +16 -0
  20. package/dist/cjs/airdrop/contracts/solana/AirdropService.js +38 -0
  21. package/dist/cjs/airdrop/contracts/solana/AirdropService.js.map +1 -0
  22. package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js +2 -2
  23. package/dist/cjs/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
  24. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.d.ts +3 -2
  25. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js +7 -3
  26. package/dist/cjs/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
  27. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.d.ts +49 -0
  28. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.js +242 -0
  29. package/dist/cjs/airdrop/contracts/solana/MerkleDistributorClient.js.map +1 -0
  30. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.d.ts +1 -0
  31. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.js +3 -0
  32. package/dist/cjs/airdrop/contracts/solana/SolanaContractClient.js.map +1 -1
  33. package/dist/cjs/airdrop/contracts/solana/fee_collector.d.ts +49 -1
  34. package/dist/cjs/airdrop/contracts/solana/fee_collector.json +51 -3
  35. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.d.ts +1695 -0
  36. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.js +3 -0
  37. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.js.map +1 -0
  38. package/dist/cjs/airdrop/contracts/solana/merkle_token_distributor_solana.json +1689 -0
  39. package/dist/cjs/airdrop/services/index.d.ts +3 -2
  40. package/dist/cjs/airdrop/services/index.js +8 -1
  41. package/dist/cjs/airdrop/services/index.js.map +1 -1
  42. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.d.ts +1 -0
  43. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.js +2 -1
  44. package/dist/cjs/airdrop/strategies/AirdropStrategyFactory.js.map +1 -1
  45. package/dist/cjs/airdrop/strategies/IAirdropStrategy.d.ts +1 -0
  46. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.d.ts +25 -0
  47. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.js +62 -0
  48. package/dist/cjs/airdrop/strategies/SolanaAirdropStrategy.js.map +1 -0
  49. package/dist/cjs/airdrop/types/index.d.ts +6 -1
  50. package/dist/cjs/airdrop/types/index.js +1 -0
  51. package/dist/cjs/airdrop/types/index.js.map +1 -1
  52. package/dist/esm/airdrop/AirdropClient.d.ts +1 -1
  53. package/dist/esm/airdrop/AirdropClient.js +4 -3
  54. package/dist/esm/airdrop/AirdropClient.js.map +1 -1
  55. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +10 -1
  56. package/dist/esm/airdrop/SignatureAirdropClient.js +49 -12
  57. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -1
  58. package/dist/esm/airdrop/common/index.d.ts +1 -1
  59. package/dist/esm/airdrop/constants/chain-config.d.ts +1 -1
  60. package/dist/esm/airdrop/constants/chain-config.js +1 -1
  61. package/dist/esm/airdrop/constants/chain-config.js.map +1 -1
  62. package/dist/esm/airdrop/constants/index.d.ts +1 -0
  63. package/dist/esm/airdrop/constants/index.js +1 -0
  64. package/dist/esm/airdrop/constants/index.js.map +1 -1
  65. package/dist/esm/airdrop/contracts/evm/contracts/AirdropSignatureClient.js +0 -1
  66. package/dist/esm/airdrop/contracts/evm/contracts/AirdropSignatureClient.js.map +1 -1
  67. package/dist/esm/airdrop/contracts/index.d.ts +1 -0
  68. package/dist/esm/airdrop/contracts/index.js +1 -0
  69. package/dist/esm/airdrop/contracts/index.js.map +1 -1
  70. package/dist/esm/airdrop/contracts/solana/AirdropService.d.ts +16 -0
  71. package/dist/esm/airdrop/contracts/solana/AirdropService.js +34 -0
  72. package/dist/esm/airdrop/contracts/solana/AirdropService.js.map +1 -0
  73. package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js +2 -2
  74. package/dist/esm/airdrop/contracts/solana/AirdropSignatureClient.js.map +1 -1
  75. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.d.ts +3 -2
  76. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js +7 -3
  77. package/dist/esm/airdrop/contracts/solana/FeeCollectorClient.js.map +1 -1
  78. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.d.ts +49 -0
  79. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.js +212 -0
  80. package/dist/esm/airdrop/contracts/solana/MerkleDistributorClient.js.map +1 -0
  81. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.d.ts +1 -0
  82. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.js +3 -0
  83. package/dist/esm/airdrop/contracts/solana/SolanaContractClient.js.map +1 -1
  84. package/dist/esm/airdrop/contracts/solana/fee_collector.d.ts +49 -1
  85. package/dist/esm/airdrop/contracts/solana/fee_collector.json +51 -3
  86. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.d.ts +1695 -0
  87. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.js +2 -0
  88. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.js.map +1 -0
  89. package/dist/esm/airdrop/contracts/solana/merkle_token_distributor_solana.json +1689 -0
  90. package/dist/esm/airdrop/services/index.d.ts +3 -2
  91. package/dist/esm/airdrop/services/index.js +6 -0
  92. package/dist/esm/airdrop/services/index.js.map +1 -1
  93. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.d.ts +1 -0
  94. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.js +2 -1
  95. package/dist/esm/airdrop/strategies/AirdropStrategyFactory.js.map +1 -1
  96. package/dist/esm/airdrop/strategies/IAirdropStrategy.d.ts +1 -0
  97. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.d.ts +25 -0
  98. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.js +58 -0
  99. package/dist/esm/airdrop/strategies/SolanaAirdropStrategy.js.map +1 -0
  100. package/dist/esm/airdrop/types/index.d.ts +6 -1
  101. package/dist/esm/airdrop/types/index.js +1 -0
  102. package/dist/esm/airdrop/types/index.js.map +1 -1
  103. package/package.json +2 -9
  104. package/src/airdrop/AirdropClient.ts +0 -307
  105. package/src/airdrop/SignatureAirdropClient.ts +0 -337
  106. package/src/airdrop/common/index.ts +0 -54
  107. package/src/airdrop/common/projectDataForTon.ts +0 -79
  108. package/src/airdrop/constants/chain-config.ts +0 -107
  109. package/src/airdrop/constants/index.ts +0 -8
  110. package/src/airdrop/constants/network.ts +0 -78
  111. package/src/airdrop/contracts/evm/AirdropService.ts +0 -181
  112. package/src/airdrop/contracts/evm/SignatureAirdropService.ts +0 -114
  113. package/src/airdrop/contracts/evm/contracts/AirdropSignatureClient.ts +0 -63
  114. package/src/airdrop/contracts/evm/contracts/AirdropSignatureFeeClient.ts +0 -61
  115. package/src/airdrop/contracts/evm/contracts/AirdropV2Client.ts +0 -37
  116. package/src/airdrop/contracts/evm/contracts/AirdropV3Client.ts +0 -49
  117. package/src/airdrop/contracts/evm/contracts/AirdropV3FeeClient.ts +0 -16
  118. package/src/airdrop/contracts/evm/contracts/AirdropV4Client.ts +0 -36
  119. package/src/airdrop/contracts/evm/contracts/ContractBaseClient.ts +0 -85
  120. package/src/airdrop/contracts/evm/contracts/DeployClient.ts +0 -35
  121. package/src/airdrop/contracts/evm/contracts/FeeCollectorClient.ts +0 -21
  122. package/src/airdrop/contracts/evm/contracts/KycClient.ts +0 -21
  123. package/src/airdrop/contracts/evm/contracts/abis/Airdrop.json +0 -674
  124. package/src/airdrop/contracts/evm/contracts/abis/AirdropV2.json +0 -676
  125. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3.json +0 -740
  126. package/src/airdrop/contracts/evm/contracts/abis/AirdropV3_Fee.json +0 -678
  127. package/src/airdrop/contracts/evm/contracts/abis/CustomFeeNativeAirdropV4.json +0 -701
  128. package/src/airdrop/contracts/evm/contracts/abis/Deployer.json +0 -271
  129. package/src/airdrop/contracts/evm/contracts/abis/ERC721.json +0 -737
  130. package/src/airdrop/contracts/evm/contracts/abis/FeeCollector.json +0 -322
  131. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenECDSADistributor.json +0 -564
  132. package/src/airdrop/contracts/evm/contracts/abis/FungibleTokenWithFeesECDSADistributor.json +0 -260
  133. package/src/airdrop/contracts/evm/contracts/abis/KycHook.json +0 -312
  134. package/src/airdrop/contracts/index.ts +0 -4
  135. package/src/airdrop/contracts/solana/AirdropSignatureClient.ts +0 -242
  136. package/src/airdrop/contracts/solana/FeeCollectorClient.ts +0 -43
  137. package/src/airdrop/contracts/solana/SignatureAirdropService.ts +0 -51
  138. package/src/airdrop/contracts/solana/SolanaContractClient.ts +0 -126
  139. package/src/airdrop/contracts/solana/fee_collector.json +0 -1063
  140. package/src/airdrop/contracts/solana/fee_collector.ts +0 -1069
  141. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.json +0 -1573
  142. package/src/airdrop/contracts/solana/fungible_token_distributor_solana.ts +0 -1579
  143. package/src/airdrop/contracts/ton/AirdropClientV1.ts +0 -122
  144. package/src/airdrop/contracts/ton/AirdropClientV2.ts +0 -118
  145. package/src/airdrop/contracts/ton/AirdropClientV21.ts +0 -131
  146. package/src/airdrop/contracts/ton/AirdropClientV3.ts +0 -127
  147. package/src/airdrop/contracts/ton/AirdropService.ts +0 -150
  148. package/src/airdrop/contracts/ton/TonContractBaseClient.ts +0 -236
  149. package/src/airdrop/contracts/ton/v1/build/Leaf.compiled.json +0 -1
  150. package/src/airdrop/contracts/ton/v1/build/MerkleTokenDistributor.compiled.json +0 -1
  151. package/src/airdrop/contracts/ton/v1/utils/constants.ts +0 -42
  152. package/src/airdrop/contracts/ton/v1/utils/date.utils.ts +0 -11
  153. package/src/airdrop/contracts/ton/v1/utils/index.ts +0 -3
  154. package/src/airdrop/contracts/ton/v1/utils/ton.utils.ts +0 -84
  155. package/src/airdrop/contracts/ton/v1/wrappers/JettonMinter.ts +0 -81
  156. package/src/airdrop/contracts/ton/v1/wrappers/JettonWallet.ts +0 -73
  157. package/src/airdrop/contracts/ton/v1/wrappers/Leaf.ts +0 -88
  158. package/src/airdrop/contracts/ton/v1/wrappers/MerkleTokenDistributor.ts +0 -317
  159. package/src/airdrop/contracts/ton/v1/wrappers/index.ts +0 -2
  160. package/src/airdrop/contracts/ton/v2/build/Leaf.compiled.json +0 -1
  161. package/src/airdrop/contracts/ton/v2/build/MerkleTokenDistributor.compiled.json +0 -1
  162. package/src/airdrop/contracts/ton/v2/utils/constants.ts +0 -43
  163. package/src/airdrop/contracts/ton/v2/utils/date.utils.ts +0 -11
  164. package/src/airdrop/contracts/ton/v2/utils/index.ts +0 -3
  165. package/src/airdrop/contracts/ton/v2/utils/ton.utils.ts +0 -102
  166. package/src/airdrop/contracts/ton/v2/wrappers/Leaf.ts +0 -69
  167. package/src/airdrop/contracts/ton/v2/wrappers/MerkleTokenDistributor.ts +0 -340
  168. package/src/airdrop/contracts/ton/v2/wrappers/index.ts +0 -2
  169. package/src/airdrop/contracts/ton/v21/build/Leaf.compiled.json +0 -1
  170. package/src/airdrop/contracts/ton/v21/build/MerkleTokenDistributor.compiled.json +0 -1
  171. package/src/airdrop/contracts/ton/v21/utils/constants.ts +0 -48
  172. package/src/airdrop/contracts/ton/v21/utils/date.utils.ts +0 -11
  173. package/src/airdrop/contracts/ton/v21/utils/index.ts +0 -3
  174. package/src/airdrop/contracts/ton/v21/utils/ton.utils.ts +0 -84
  175. package/src/airdrop/contracts/ton/v21/wrappers/Leaf.ts +0 -69
  176. package/src/airdrop/contracts/ton/v21/wrappers/MerkleTokenDistributor.ts +0 -346
  177. package/src/airdrop/contracts/ton/v21/wrappers/index.ts +0 -2
  178. package/src/airdrop/contracts/ton/v3/build/Leaf.compiled.json +0 -1
  179. package/src/airdrop/contracts/ton/v3/build/MerkleTokenDistributor.compiled.json +0 -1
  180. package/src/airdrop/contracts/ton/v3/utils/constants.ts +0 -43
  181. package/src/airdrop/contracts/ton/v3/utils/date.utils.ts +0 -11
  182. package/src/airdrop/contracts/ton/v3/utils/index.ts +0 -3
  183. package/src/airdrop/contracts/ton/v3/utils/ton.utils.ts +0 -84
  184. package/src/airdrop/contracts/ton/v3/wrappers/Leaf.ts +0 -68
  185. package/src/airdrop/contracts/ton/v3/wrappers/MerkleTokenDistributor.ts +0 -316
  186. package/src/airdrop/contracts/ton/v3/wrappers/index.ts +0 -2
  187. package/src/airdrop/index.ts +0 -10
  188. package/src/airdrop/services/index.ts +0 -159
  189. package/src/airdrop/services/wallet-service/ton/WalletService.ts +0 -226
  190. package/src/airdrop/services/wallet-service/ton/index.ts +0 -1
  191. package/src/airdrop/strategies/AirdropStrategyFactory.ts +0 -31
  192. package/src/airdrop/strategies/EvmAirdropStrategy.ts +0 -81
  193. package/src/airdrop/strategies/IAirdropStrategy.ts +0 -26
  194. package/src/airdrop/strategies/StrategyCache.ts +0 -34
  195. package/src/airdrop/strategies/TonAirdropStrategy.ts +0 -77
  196. package/src/airdrop/tests/index.test.ts +0 -387
  197. package/src/airdrop/types/index.ts +0 -199
  198. package/src/index.ts +0 -3
  199. package/src/utils/api-client.ts +0 -69
  200. package/src/utils/index.ts +0 -3
  201. package/src/utils/utils.ts +0 -45
  202. package/src/utils/web3.ts +0 -172
  203. package/src/wallets/WalletBase.ts +0 -92
  204. package/src/wallets/WalletFactory.tsx +0 -35
  205. package/src/wallets/index.ts +0 -3
  206. package/src/wallets/providers/evm/EvmWallet.ts +0 -101
  207. package/src/wallets/providers/evm/index.tsx +0 -56
  208. package/src/wallets/providers/index.ts +0 -4
  209. package/src/wallets/providers/solana/index.tsx +0 -133
  210. package/src/wallets/providers/ton/TonWallet.ts +0 -153
  211. package/src/wallets/providers/ton/index.tsx +0 -41
  212. package/src/wallets/types.ts +0 -45
  213. package/src/wallets/utils/index.ts +0 -61
@@ -1,242 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- import { SolanaContractClientBase, SolanaContractInfo } from './SolanaContractClient';
3
- import IDL from './fungible_token_distributor_solana.json';
4
- import * as anchor from '@coral-xyz/anchor';
5
- import { FungibleTokenDistributorSolana } from './fungible_token_distributor_solana';
6
- import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
7
- import { FeeCollectorClient } from './FeeCollectorClient';
8
- import { fetchTokenVersion, getOrCreateAssociatedTokenAccount, hexStrToU8Array } from '../../../utils';
9
-
10
- export class AirdropSignatureClient extends SolanaContractClientBase<FungibleTokenDistributorSolana> {
11
- projectId: string;
12
- constructor(options: SolanaContractInfo) {
13
- super({
14
- ...options,
15
- idl: IDL
16
- });
17
- this.projectId = options.projectId;
18
- }
19
-
20
- async getVersionPDA(): Promise<PublicKey> {
21
- const [versionPDA] = await this.findProgramAddress([anchor.utils.bytes.utf8.encode('version')]);
22
-
23
- return versionPDA;
24
- }
25
-
26
- async getVersion() {
27
- const versionPDA = await this.getVersionPDA();
28
- const versionData = await this.fetchAccountData('version', versionPDA);
29
- return versionData.version;
30
- }
31
-
32
- get FeeCollector() {
33
- return new FeeCollectorClient({
34
- projectId: this.projectId,
35
- walletClient: this.wallet,
36
- chainId: this.chainId
37
- });
38
- }
39
-
40
- async getClaimFee(amount: bigint) {
41
- return this.FeeCollector.getClaimFee(amount.toString());
42
- }
43
-
44
- async getStoragePDA(): Promise<PublicKey> {
45
- const [storagePDA] = await this.findProgramAddress([
46
- anchor.utils.bytes.utf8.encode('storage'),
47
- anchor.utils.bytes.utf8.encode(this.projectId)
48
- ]);
49
-
50
- return storagePDA;
51
- }
52
-
53
- async getAirdropPDA(): Promise<PublicKey> {
54
- const [airdropPDA] = await this.findProgramAddress([
55
- anchor.utils.bytes.utf8.encode('airdrop'),
56
- anchor.utils.bytes.utf8.encode(this.projectId)
57
- ]);
58
-
59
- return airdropPDA;
60
- }
61
-
62
- async getVaultPDA(): Promise<PublicKey> {
63
- const airdropPDA = await this.getAirdropPDA();
64
- const [vaultPDA] = await this.findProgramAddress([anchor.utils.bytes.utf8.encode('vault'), airdropPDA.toBuffer()]);
65
-
66
- return vaultPDA;
67
- }
68
-
69
- async getClaimPDA(claimId: string): Promise<PublicKey> {
70
- const airdropPDA = await this.getAirdropPDA();
71
- const [claimPDA] = await this.findProgramAddress([
72
- anchor.utils.bytes.utf8.encode('claim'),
73
- airdropPDA.toBuffer(),
74
- new Uint8Array(hexStrToU8Array(claimId))
75
- ]);
76
- return claimPDA;
77
- }
78
-
79
- async getContractInfo() {
80
- const airdropPDA = await this.getAirdropPDA();
81
- const config: any = await this.fetchAccountData('airdrop', airdropPDA);
82
-
83
- const version = await this.getVersion();
84
- return {
85
- version: version,
86
- token: config.token.toString() as string,
87
- startTime: Number(config.startTime),
88
- endTime: Number(config.endTime),
89
- paused: config.paused as boolean,
90
- signer: config.authorizedSigner.toString() as string,
91
- owner: config.owner.toString() as string
92
- };
93
- }
94
-
95
- async getPaused() {
96
- const config = await this.getContractInfo();
97
- return config.paused;
98
- }
99
-
100
- async checkClaim(id: string) {
101
- const claimPDA = await this.getClaimPDA(id);
102
- try {
103
- const claimData = await this.fetchAccountData('claim', claimPDA);
104
- return claimData?.used;
105
- } catch (error) {
106
- return false;
107
- }
108
- }
109
-
110
- async batchFetchClaimed(userClaimIds: string[]): Promise<boolean[]> {
111
- const res = await Promise.all(userClaimIds.map((id) => this.checkClaim(id)));
112
- return res;
113
- }
114
-
115
- async initialize(projectId: string, feeCollector?: PublicKey): Promise<string> {
116
- try {
117
- const airdropPDA = await this.getAirdropPDA();
118
- console.log(airdropPDA);
119
- const config = await this.getContractInfo();
120
- console.log(config);
121
- return airdropPDA.toString();
122
- } catch (error) {
123
- const owner = this.wallet.publicKey;
124
- const res = await this.invokeInstruction(
125
- 'initialize',
126
- {
127
- // storage: storagePDA,
128
- // authority: this.wallet.publicKey
129
- },
130
- [projectId, owner, feeCollector || PublicKey.default]
131
- );
132
- console.log(res);
133
- const airdropPDA = await this.getAirdropPDA();
134
- return airdropPDA.toString();
135
- }
136
- }
137
-
138
- async setBaseParams(tokenAddress: string, startTime: number, endTime: number, signer: string) {
139
- const start = new anchor.BN(startTime),
140
- end = new anchor.BN(endTime);
141
- console.log(start, end, tokenAddress, signer);
142
- await this.invokeInstruction('setBaseParams', {}, [new PublicKey(tokenAddress), start, end, new PublicKey(signer)]);
143
- }
144
-
145
- async togglePause() {
146
- await this.invokeInstruction('togglePause', {}, [this.projectId]);
147
- }
148
-
149
- async getFeeInfo() {
150
- const airdropPDA = await this.getAirdropPDA();
151
- const config = await this.fetchAccountData('airdrop', airdropPDA);
152
- return {
153
- feeToken: config.feeToken.toString(),
154
- feeCollector: config.feeCollector.toString()
155
- };
156
- }
157
-
158
- async claim(
159
- data: {
160
- recipient: string;
161
- data: string;
162
- claimId: string;
163
- signature: string;
164
- extraData?: string;
165
- unlockingAt: number;
166
- value: string;
167
- hash: string;
168
- }[]
169
- ) {
170
- const config = await this.getContractInfo();
171
-
172
- const feeCollectorStoragePDA = await this.FeeCollector.getStoragePDA();
173
- const feePDA = await this.FeeCollector.getProjectFeePDA();
174
- const airdropPDA = await this.getAirdropPDA();
175
- const tokenVersion = await fetchTokenVersion(config.token, {
176
- clusterOrEndpoint: this.chainId
177
- });
178
-
179
- const authorityATA = await getOrCreateAssociatedTokenAccount({
180
- connection: this.connection,
181
- payer: this.wallet.publicKey,
182
- mint: new PublicKey(config.token),
183
- owner: new PublicKey(this.wallet.publicKey),
184
- signTransaction: (this.wallet as any).signTransaction,
185
- programId: tokenVersion?.programId || TOKEN_2022_PROGRAM_ID
186
- });
187
-
188
- let lastHash = '';
189
- // solana max transaction size of 1232
190
- for (const claim of data) {
191
- const tx = new anchor.web3.Transaction();
192
- tx.add(
193
- anchor.web3.Ed25519Program.createInstructionWithPublicKey({
194
- publicKey: new PublicKey(config.signer).toBytes(),
195
- message: Uint8Array.from(hexStrToU8Array(claim.hash)),
196
- signature: new Uint8Array(hexStrToU8Array(claim.signature))
197
- })
198
- );
199
-
200
- const claimPDA = await this.getClaimPDA(claim.claimId);
201
-
202
- const decodedData = {
203
- claimableTimestamp: new anchor.BN(claim.unlockingAt),
204
- claimableAmount: new anchor.BN(claim.value)
205
- };
206
-
207
- tx.add(
208
- await this.program.methods
209
- .claim(
210
- this.projectId,
211
- new Uint8Array(hexStrToU8Array(claim.claimId)),
212
- [],
213
- decodedData,
214
- Buffer.from(hexStrToU8Array(claim.signature))
215
- )
216
- .accountsPartial({
217
- authority: this.wallet.publicKey,
218
- airdrop: airdropPDA,
219
- claim: claimPDA,
220
- authorityAta: authorityATA.address,
221
- tokenMint: new PublicKey(config.token),
222
- feeCollectorStorage: feeCollectorStoragePDA,
223
- feeCollectorVault: null,
224
- fee: feePDA,
225
- authorityFeeAta: null,
226
- tokenProgram: tokenVersion?.programId || TOKEN_2022_PROGRAM_ID,
227
- feeTokenProgram: null,
228
- feeTokenMint: null
229
- })
230
- .transaction()
231
- );
232
-
233
- const hash = await this.program.provider.sendAndConfirm?.(tx, [], {
234
- commitment: 'finalized'
235
- });
236
-
237
- lastHash = hash!;
238
- }
239
-
240
- return lastHash;
241
- }
242
- }
@@ -1,43 +0,0 @@
1
- import { FeeCollector } from './fee_collector';
2
- import { SolanaContractClientBase, SolanaContractInfo } from './SolanaContractClient';
3
- import IDL from './fee_collector.json';
4
- import { PublicKey } from '@solana/web3.js';
5
- import * as anchor from '@coral-xyz/anchor';
6
-
7
- export class FeeCollectorClient extends SolanaContractClientBase<FeeCollector> {
8
- projectId: string;
9
- constructor(options: SolanaContractInfo) {
10
- super({
11
- ...options,
12
- idl: IDL
13
- });
14
- this.projectId = options.projectId;
15
- }
16
-
17
- async getStoragePDA(): Promise<PublicKey> {
18
- const [storagePDA] = await this.findProgramAddress([anchor.utils.bytes.utf8.encode('storage')]);
19
-
20
- return storagePDA;
21
- }
22
-
23
- async getProjectFeePDA(): Promise<PublicKey> {
24
- const [projectFeePDA] = await this.findProgramAddress([
25
- anchor.utils.bytes.utf8.encode('fee'),
26
- anchor.utils.bytes.utf8.encode(this.projectId)
27
- ]);
28
- return projectFeePDA;
29
- }
30
-
31
- async setDefaultFee(fee: string) {
32
- return this.invokeInstruction('setDefaultFee', {}, [new anchor.BN(fee)]);
33
- }
34
-
35
- async getClaimFee(tokenAmount: string): Promise<bigint> {
36
- try {
37
- const fee = await this.invokeView('getFee', [this.projectId, new anchor.BN(tokenAmount)]);
38
- return BigInt(fee);
39
- } catch (error) {
40
- return BigInt(0);
41
- }
42
- }
43
- }
@@ -1,51 +0,0 @@
1
- import { AirdropSignatureClient } from './AirdropSignatureClient';
2
- import { SolanaContractInfo } from './SolanaContractClient';
3
-
4
- export class SignatureAirdropService {
5
- options: SolanaContractInfo;
6
- constructor(options: SolanaContractInfo) {
7
- this.options = options;
8
- }
9
-
10
- private get airdropClient(): AirdropSignatureClient {
11
- if (!this.options) {
12
- throw new Error('options is empty');
13
- }
14
-
15
- return new AirdropSignatureClient(this.options);
16
- }
17
-
18
- async getVersion() {
19
- return this.airdropClient.getVersion();
20
- }
21
-
22
- async getClaimFee(address: string, amount: bigint): Promise<bigint> {
23
- const fee = await this.airdropClient.getClaimFee(amount);
24
- return fee;
25
- }
26
-
27
- async batchFetchClaimed(userClaimIds: string[]): Promise<boolean[]> {
28
- const res = await this.airdropClient.batchFetchClaimed(userClaimIds);
29
- return res;
30
- }
31
-
32
- async getPaused() {
33
- return this.airdropClient.getPaused();
34
- }
35
-
36
- async claim(
37
- data: {
38
- recipient: string;
39
- claimId: string;
40
- data: string;
41
- signature: string;
42
- extraData?: string;
43
- unlockingAt: number;
44
- value: string;
45
- hash: string;
46
- }[],
47
- recipient?: string
48
- ) {
49
- return this.airdropClient.claim(data);
50
- }
51
- }
@@ -1,126 +0,0 @@
1
- import { Program, AnchorProvider, setProvider, Wallet, Idl } from '@coral-xyz/anchor';
2
- import {
3
- AllAccountsMap,
4
- AllInstructions,
5
- IdlAccounts,
6
- MakeMethodsNamespace
7
- } from '@coral-xyz/anchor/dist/cjs/program/namespace/types';
8
- import { Cluster, clusterApiUrl, Commitment, Connection, PublicKey, Signer } from '@solana/web3.js';
9
-
10
- export interface SolanaContractInfo {
11
- projectId: string;
12
- chainId?: string;
13
- idl?: any;
14
- token?: string;
15
- walletClient: Wallet;
16
- }
17
-
18
- export abstract class SolanaContractClientBase<T extends Idl = Idl> {
19
- protected program: Program<T>;
20
- protected connection: Connection;
21
- protected wallet: Wallet;
22
- protected chainId: string;
23
-
24
- constructor(contractInfo: SolanaContractInfo) {
25
- console.log(contractInfo);
26
- const { idl, walletClient, chainId } = contractInfo;
27
- this.chainId = chainId || 'mainnet-beta';
28
-
29
- this.connection = this.getConnection(chainId);
30
- this.wallet = walletClient;
31
-
32
- const provider = new AnchorProvider(this.connection, this.wallet, { commitment: 'confirmed' });
33
- setProvider(provider);
34
-
35
- this.program = new Program(idl, provider);
36
- }
37
-
38
- getConnection(endpoint?: string) {
39
- const apiUrl = clusterApiUrl((endpoint as Cluster) ?? 'mainnet-beta');
40
-
41
- const conn = new Connection(apiUrl);
42
- return conn;
43
- }
44
-
45
- protected async findProgramAddress(
46
- seeds: Array<Buffer | Uint8Array>,
47
- programId?: PublicKey
48
- ): Promise<[PublicKey, number]> {
49
- return await PublicKey.findProgramAddressSync(seeds, programId || new PublicKey(this.program.idl.address));
50
- }
51
-
52
- async fetchAccountData<A extends keyof AllAccountsMap<T>>(
53
- accountName: A,
54
- address: PublicKey | string,
55
- commitment?: Commitment
56
- ): Promise<IdlAccounts<T>[A]> {
57
- try {
58
- if (!this.program.account[accountName]) {
59
- throw new Error(`Account ${String(accountName)} not found in program`);
60
- }
61
-
62
- const account = await this.program.account[accountName].fetch(address, commitment);
63
- return account as IdlAccounts<T>[A];
64
- } catch (error) {
65
- console.error(`Error fetching account ${String(accountName)}:`, error);
66
- throw error;
67
- }
68
- }
69
-
70
- async invokeView<M extends keyof MakeMethodsNamespace<T, AllInstructions<T>>>(
71
- methodName: M,
72
- args: Parameters<MakeMethodsNamespace<T, AllInstructions<T>>[M]>
73
- ): Promise<any> {
74
- try {
75
- if (!this.program.methods[methodName]) {
76
- throw new Error(`Method ${methodName} not found in program`);
77
- }
78
-
79
- const result = await this.program.methods[methodName](...args).view();
80
-
81
- return result;
82
- } catch (error) {
83
- console.error(`Error invoking view method ${methodName}:`, error);
84
- throw error;
85
- }
86
- }
87
-
88
- async invokeInstruction<M extends keyof MakeMethodsNamespace<T, AllInstructions<T>>>(
89
- methodName: M,
90
- accounts: any,
91
- args: any,
92
- options?: { signers?: Signer[] }
93
- ): Promise<string> {
94
- if (!this.program.methods[methodName]) {
95
- throw new Error(`Method ${methodName} not found in program`);
96
- }
97
- let instruction = this.program.methods[methodName](...args).accounts(accounts);
98
-
99
- if (options?.signers?.length) {
100
- instruction = instruction.signers(options.signers);
101
- }
102
-
103
- const tx = await instruction.rpc();
104
-
105
- await this.confirmTransaction(tx);
106
- console.log(tx);
107
-
108
- return tx;
109
- }
110
-
111
- async confirmTransaction(tx: string): Promise<string> {
112
- const latestBlockhash = await this.connection.getLatestBlockhash();
113
- await this.connection.confirmTransaction(
114
- {
115
- signature: tx,
116
- blockhash: latestBlockhash.blockhash,
117
- lastValidBlockHeight: latestBlockhash.lastValidBlockHeight
118
- },
119
- 'finalized'
120
- );
121
- return tx;
122
- }
123
- // protected abstract getProgramAccount(accountName: string, address: PublicKey): Promise<any>;
124
-
125
- // protected abstract getEventLogs(signature: string, eventName: string): Promise<any[]>;
126
- }