@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,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
- }