@nosana/kit 1.0.10 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +539 -152
- package/dist/NosanaClient.d.ts +58 -0
- package/dist/NosanaClient.js +103 -0
- package/dist/NosanaClient.js.map +1 -0
- package/dist/config/defaultConfigs.d.ts +2 -1
- package/dist/config/defaultConfigs.js +4 -4
- package/dist/config/defaultConfigs.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +41 -33
- package/dist/config/types.js +14 -13
- package/dist/config/types.js.map +1 -0
- package/dist/config/utils.d.ts +2 -2
- package/dist/config/utils.js +11 -4
- package/dist/config/utils.js.map +1 -0
- package/dist/errors/NosanaError.d.ts +1 -0
- package/dist/errors/NosanaError.js +2 -0
- package/dist/errors/NosanaError.js.map +1 -0
- package/dist/generated_clients/jobs/accounts/index.d.ts +5 -5
- package/dist/generated_clients/jobs/accounts/index.js +6 -5
- package/dist/generated_clients/jobs/accounts/index.js.map +1 -0
- package/dist/generated_clients/jobs/accounts/jobAccount.d.ts +10 -6
- package/dist/generated_clients/jobs/accounts/jobAccount.js +6 -2
- package/dist/generated_clients/jobs/accounts/jobAccount.js.map +1 -0
- package/dist/generated_clients/jobs/accounts/marketAccount.d.ts +6 -2
- package/dist/generated_clients/jobs/accounts/marketAccount.js +6 -2
- package/dist/generated_clients/jobs/accounts/marketAccount.js.map +1 -0
- package/dist/generated_clients/jobs/accounts/runAccount.d.ts +10 -6
- package/dist/generated_clients/jobs/accounts/runAccount.js +6 -2
- package/dist/generated_clients/jobs/accounts/runAccount.js.map +1 -0
- package/dist/generated_clients/jobs/errors/index.d.ts +3 -3
- package/dist/generated_clients/jobs/errors/index.js +4 -3
- package/dist/generated_clients/jobs/errors/index.js.map +1 -0
- package/dist/generated_clients/jobs/errors/nosanaJobs.d.ts +2 -2
- package/dist/generated_clients/jobs/errors/nosanaJobs.js +4 -3
- package/dist/generated_clients/jobs/errors/nosanaJobs.js.map +1 -0
- package/dist/generated_clients/jobs/index.d.ts +7 -7
- package/dist/generated_clients/jobs/index.js +8 -7
- package/dist/generated_clients/jobs/index.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/assign.d.ts +14 -14
- package/dist/generated_clients/jobs/instructions/assign.js +8 -8
- package/dist/generated_clients/jobs/instructions/assign.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/claim.d.ts +13 -13
- package/dist/generated_clients/jobs/instructions/claim.js +8 -8
- package/dist/generated_clients/jobs/instructions/claim.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/clean.d.ts +10 -10
- package/dist/generated_clients/jobs/instructions/clean.js +8 -8
- package/dist/generated_clients/jobs/instructions/clean.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/cleanAdmin.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/cleanAdmin.js +8 -8
- package/dist/generated_clients/jobs/instructions/cleanAdmin.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/close.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/close.js +8 -8
- package/dist/generated_clients/jobs/instructions/close.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/closeAdmin.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/closeAdmin.js +8 -8
- package/dist/generated_clients/jobs/instructions/closeAdmin.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/complete.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/complete.js +9 -12
- package/dist/generated_clients/jobs/instructions/complete.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/delist.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/delist.js +8 -8
- package/dist/generated_clients/jobs/instructions/delist.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/end.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/end.js +8 -8
- package/dist/generated_clients/jobs/instructions/end.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/extend.d.ts +12 -12
- package/dist/generated_clients/jobs/instructions/extend.js +8 -8
- package/dist/generated_clients/jobs/instructions/extend.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/finish.d.ts +23 -20
- package/dist/generated_clients/jobs/instructions/finish.js +15 -12
- package/dist/generated_clients/jobs/instructions/finish.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/index.d.ts +21 -21
- package/dist/generated_clients/jobs/instructions/index.js +22 -21
- package/dist/generated_clients/jobs/instructions/index.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/list.d.ts +14 -14
- package/dist/generated_clients/jobs/instructions/list.js +8 -8
- package/dist/generated_clients/jobs/instructions/list.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/open.d.ts +12 -12
- package/dist/generated_clients/jobs/instructions/open.js +8 -8
- package/dist/generated_clients/jobs/instructions/open.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/quit.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/quit.js +8 -8
- package/dist/generated_clients/jobs/instructions/quit.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/quitAdmin.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/quitAdmin.js +8 -8
- package/dist/generated_clients/jobs/instructions/quitAdmin.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/recover.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/recover.js +8 -8
- package/dist/generated_clients/jobs/instructions/recover.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/stop.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/stop.js +8 -8
- package/dist/generated_clients/jobs/instructions/stop.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/update.d.ts +11 -11
- package/dist/generated_clients/jobs/instructions/update.js +8 -8
- package/dist/generated_clients/jobs/instructions/update.js.map +1 -0
- package/dist/generated_clients/jobs/instructions/work.d.ts +13 -13
- package/dist/generated_clients/jobs/instructions/work.js +8 -8
- package/dist/generated_clients/jobs/instructions/work.js.map +1 -0
- package/dist/generated_clients/jobs/programs/index.d.ts +3 -3
- package/dist/generated_clients/jobs/programs/index.js +4 -3
- package/dist/generated_clients/jobs/programs/index.js.map +1 -0
- package/dist/generated_clients/jobs/programs/nosanaJobs.d.ts +52 -50
- package/dist/generated_clients/jobs/programs/nosanaJobs.js +30 -31
- package/dist/generated_clients/jobs/programs/nosanaJobs.js.map +1 -0
- package/dist/generated_clients/jobs/shared/index.d.ts +5 -5
- package/dist/generated_clients/jobs/shared/index.js +4 -3
- package/dist/generated_clients/jobs/shared/index.js.map +1 -0
- package/dist/generated_clients/jobs/types/index.d.ts +5 -5
- package/dist/generated_clients/jobs/types/index.js +6 -5
- package/dist/generated_clients/jobs/types/index.js.map +1 -0
- package/dist/generated_clients/jobs/types/jobState.d.ts +12 -11
- package/dist/generated_clients/jobs/types/jobState.js +8 -8
- package/dist/generated_clients/jobs/types/jobState.js.map +1 -0
- package/dist/generated_clients/jobs/types/jobType.d.ts +15 -14
- package/dist/generated_clients/jobs/types/jobType.js +11 -11
- package/dist/generated_clients/jobs/types/jobType.js.map +1 -0
- package/dist/generated_clients/jobs/types/queueType.d.ts +12 -11
- package/dist/generated_clients/jobs/types/queueType.js +8 -8
- package/dist/generated_clients/jobs/types/queueType.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/accounts/claimStatus.d.ts +10 -6
- package/dist/generated_clients/merkle_distributor/accounts/claimStatus.js +6 -2
- package/dist/generated_clients/merkle_distributor/accounts/claimStatus.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/accounts/index.d.ts +4 -4
- package/dist/generated_clients/merkle_distributor/accounts/index.js +5 -4
- package/dist/generated_clients/merkle_distributor/accounts/index.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/accounts/merkleDistributor.d.ts +10 -6
- package/dist/generated_clients/merkle_distributor/accounts/merkleDistributor.js +6 -2
- package/dist/generated_clients/merkle_distributor/accounts/merkleDistributor.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/errors/index.d.ts +3 -3
- package/dist/generated_clients/merkle_distributor/errors/index.js +4 -3
- package/dist/generated_clients/merkle_distributor/errors/index.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/errors/merkleDistributor.d.ts +2 -2
- package/dist/generated_clients/merkle_distributor/errors/merkleDistributor.js +4 -3
- package/dist/generated_clients/merkle_distributor/errors/merkleDistributor.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/index.d.ts +6 -6
- package/dist/generated_clients/merkle_distributor/index.js +7 -6
- package/dist/generated_clients/merkle_distributor/index.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/claimLocked.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/claimLocked.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/claimLocked.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/clawback.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/clawback.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/clawback.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/closeClaimStatus.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/closeClaimStatus.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/closeClaimStatus.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/closeDistributor.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/closeDistributor.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/closeDistributor.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/index.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/index.js +12 -11
- package/dist/generated_clients/merkle_distributor/instructions/index.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/newClaim.d.ts +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/newClaim.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/newClaim.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/newDistributor.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/newDistributor.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/newDistributor.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/setAdmin.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/setAdmin.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/setAdmin.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/setClawbackReceiver.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/setClawbackReceiver.js +8 -8
- package/dist/generated_clients/merkle_distributor/instructions/setClawbackReceiver.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/instructions/setEnableSlot.d.ts +11 -11
- package/dist/generated_clients/merkle_distributor/instructions/setEnableSlot.js +9 -12
- package/dist/generated_clients/merkle_distributor/instructions/setEnableSlot.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/programs/index.d.ts +3 -3
- package/dist/generated_clients/merkle_distributor/programs/index.js +4 -3
- package/dist/generated_clients/merkle_distributor/programs/index.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/programs/merkleDistributor.d.ts +29 -27
- package/dist/generated_clients/merkle_distributor/programs/merkleDistributor.js +18 -19
- package/dist/generated_clients/merkle_distributor/programs/merkleDistributor.js.map +1 -0
- package/dist/generated_clients/merkle_distributor/shared/index.d.ts +5 -5
- package/dist/generated_clients/merkle_distributor/shared/index.js +4 -3
- package/dist/generated_clients/merkle_distributor/shared/index.js.map +1 -0
- package/dist/generated_clients/staking/accounts/index.d.ts +4 -4
- package/dist/generated_clients/staking/accounts/index.js +5 -4
- package/dist/generated_clients/staking/accounts/index.js.map +1 -0
- package/dist/generated_clients/staking/accounts/settingsAccount.d.ts +9 -6
- package/dist/generated_clients/staking/accounts/settingsAccount.js +6 -2
- package/dist/generated_clients/staking/accounts/settingsAccount.js.map +1 -0
- package/dist/generated_clients/staking/accounts/stakeAccount.d.ts +9 -6
- package/dist/generated_clients/staking/accounts/stakeAccount.js +6 -2
- package/dist/generated_clients/staking/accounts/stakeAccount.js.map +1 -0
- package/dist/generated_clients/staking/errors/index.d.ts +3 -3
- package/dist/generated_clients/staking/errors/index.js +4 -3
- package/dist/generated_clients/staking/errors/index.js.map +1 -0
- package/dist/generated_clients/staking/errors/nosanaStaking.d.ts +2 -2
- package/dist/generated_clients/staking/errors/nosanaStaking.js +4 -3
- package/dist/generated_clients/staking/errors/nosanaStaking.js.map +1 -0
- package/dist/generated_clients/staking/index.d.ts +6 -6
- package/dist/generated_clients/staking/index.js +7 -6
- package/dist/generated_clients/staking/index.js.map +1 -0
- package/dist/generated_clients/staking/instructions/close.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/close.js +8 -8
- package/dist/generated_clients/staking/instructions/close.js.map +1 -0
- package/dist/generated_clients/staking/instructions/extend.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/extend.js +9 -12
- package/dist/generated_clients/staking/instructions/extend.js.map +1 -0
- package/dist/generated_clients/staking/instructions/index.d.ts +12 -12
- package/dist/generated_clients/staking/instructions/index.js +13 -12
- package/dist/generated_clients/staking/instructions/index.js.map +1 -0
- package/dist/generated_clients/staking/instructions/init.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/init.js +8 -8
- package/dist/generated_clients/staking/instructions/init.js.map +1 -0
- package/dist/generated_clients/staking/instructions/restake.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/restake.js +8 -8
- package/dist/generated_clients/staking/instructions/restake.js.map +1 -0
- package/dist/generated_clients/staking/instructions/slash.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/slash.js +8 -8
- package/dist/generated_clients/staking/instructions/slash.js.map +1 -0
- package/dist/generated_clients/staking/instructions/stake.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/stake.js +8 -8
- package/dist/generated_clients/staking/instructions/stake.js.map +1 -0
- package/dist/generated_clients/staking/instructions/topup.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/topup.js +8 -8
- package/dist/generated_clients/staking/instructions/topup.js.map +1 -0
- package/dist/generated_clients/staking/instructions/unstake.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/unstake.js +8 -8
- package/dist/generated_clients/staking/instructions/unstake.js.map +1 -0
- package/dist/generated_clients/staking/instructions/updateSettings.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/updateSettings.js +8 -8
- package/dist/generated_clients/staking/instructions/updateSettings.js.map +1 -0
- package/dist/generated_clients/staking/instructions/withdraw.d.ts +11 -11
- package/dist/generated_clients/staking/instructions/withdraw.js +8 -8
- package/dist/generated_clients/staking/instructions/withdraw.js.map +1 -0
- package/dist/generated_clients/staking/programs/index.d.ts +3 -3
- package/dist/generated_clients/staking/programs/index.js +4 -3
- package/dist/generated_clients/staking/programs/index.js.map +1 -0
- package/dist/generated_clients/staking/programs/nosanaStaking.d.ts +33 -31
- package/dist/generated_clients/staking/programs/nosanaStaking.js +20 -21
- package/dist/generated_clients/staking/programs/nosanaStaking.js.map +1 -0
- package/dist/generated_clients/staking/shared/index.d.ts +5 -5
- package/dist/generated_clients/staking/shared/index.js +4 -3
- package/dist/generated_clients/staking/shared/index.js.map +1 -0
- package/dist/index.d.ts +13 -32
- package/dist/index.js +13 -37
- package/dist/index.js.map +1 -0
- package/dist/logger/Logger.d.ts +4 -4
- package/dist/logger/Logger.js +7 -2
- package/dist/logger/Logger.js.map +1 -0
- package/dist/services/SolanaService.d.ts +49 -26
- package/dist/services/SolanaService.js +191 -133
- package/dist/services/SolanaService.js.map +1 -0
- package/dist/services/TokenService.d.ts +41 -0
- package/dist/services/TokenService.js +136 -0
- package/dist/services/TokenService.js.map +1 -0
- package/dist/services/programs/JobsProgram.d.ts +106 -0
- package/dist/services/programs/JobsProgram.js +584 -0
- package/dist/services/programs/JobsProgram.js.map +1 -0
- package/dist/services/programs/MerkleDistributorProgram.d.ts +101 -0
- package/dist/services/programs/MerkleDistributorProgram.js +343 -0
- package/dist/services/programs/MerkleDistributorProgram.js.map +1 -0
- package/dist/services/programs/StakeProgram.d.ts +46 -0
- package/dist/services/programs/StakeProgram.js +87 -0
- package/dist/services/programs/StakeProgram.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/convertBigIntToNumber.d.ts +19 -0
- package/dist/utils/convertBigIntToNumber.js +15 -0
- package/dist/utils/convertBigIntToNumber.js.map +1 -0
- package/dist/utils/getStaticAccounts.d.ts +23 -0
- package/dist/utils/getStaticAccounts.js +39 -0
- package/dist/utils/getStaticAccounts.js.map +1 -0
- package/dist/utils/index.d.ts +3 -20
- package/dist/utils/index.js +5 -16
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/walletToAuthorizationSigner.d.ts +10 -0
- package/dist/utils/walletToAuthorizationSigner.js +42 -0
- package/dist/utils/walletToAuthorizationSigner.js.map +1 -0
- package/package.json +17 -14
- package/dist/ipfs/IPFS.d.ts +0 -50
- package/dist/ipfs/IPFS.js +0 -149
- package/dist/programs/BaseProgram.d.ts +0 -20
- package/dist/programs/BaseProgram.js +0 -31
- package/dist/programs/JobsProgram.d.ts +0 -129
- package/dist/programs/JobsProgram.js +0 -559
- package/dist/programs/MerkleDistributorProgram.d.ts +0 -115
- package/dist/programs/MerkleDistributorProgram.js +0 -337
- package/dist/programs/StakeProgram.d.ts +0 -29
- package/dist/programs/StakeProgram.js +0 -91
- package/dist/services/NosService.d.ts +0 -48
- package/dist/services/NosService.js +0 -139
- package/dist/utils/walletConverter.d.ts +0 -9
- package/dist/utils/walletConverter.js +0 -141
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { parseBase64RpcAccount, address, } from 'gill';
|
|
3
|
-
import { NosanaError, ErrorCodes } from '../index.js';
|
|
4
|
-
import * as programClient from '../generated_clients/merkle_distributor/index.js';
|
|
5
|
-
import { convertBigIntToNumber } from '../utils/index.js';
|
|
6
|
-
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
7
|
-
import bs58 from 'bs58';
|
|
8
|
-
import { SYSTEM_PROGRAM_ADDRESS } from 'gill/programs';
|
|
9
|
-
/**
|
|
10
|
-
* Claim target enum for merkle distributor.
|
|
11
|
-
* Determines which address receives the claimed tokens.
|
|
12
|
-
*/
|
|
13
|
-
export var ClaimTarget;
|
|
14
|
-
(function (ClaimTarget) {
|
|
15
|
-
ClaimTarget["YES"] = "YES";
|
|
16
|
-
ClaimTarget["NO"] = "NO";
|
|
17
|
-
})(ClaimTarget || (ClaimTarget = {}));
|
|
18
|
-
/**
|
|
19
|
-
* Allowed addresses for receiving claimed tokens from merkle distributor.
|
|
20
|
-
* The `to` account must be the ATA of one of these addresses.
|
|
21
|
-
*/
|
|
22
|
-
export const ALLOWED_RECEIVE_ADDRESSES = {
|
|
23
|
-
[ClaimTarget.YES]: address('YessuvqUauj9yW4B3eERcyRLWmQtWpFc2ERKmaedmCE'),
|
|
24
|
-
[ClaimTarget.NO]: address('NopXntmRdXhYNkoZaNTMUMShJ3aVG5RvwpiyPdd4bMh'),
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Error thrown when a claim status account is not found
|
|
28
|
-
*/
|
|
29
|
-
export class ClaimStatusNotFoundError extends Error {
|
|
30
|
-
constructor(address) {
|
|
31
|
-
super(`Claim status account not found at address ${address}`);
|
|
32
|
-
this.name = 'ClaimStatusNotFoundError';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export class MerkleDistributorProgram extends BaseProgram {
|
|
36
|
-
constructor(sdk) {
|
|
37
|
-
super(sdk);
|
|
38
|
-
this.client = programClient;
|
|
39
|
-
}
|
|
40
|
-
getProgramId() {
|
|
41
|
-
return this.sdk.config.programs.merkleDistributorAddress;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Derive the ClaimStatus PDA address for a given distributor and optional claimant.
|
|
45
|
-
* If claimant is not provided, uses the wallet's address.
|
|
46
|
-
*
|
|
47
|
-
* @param distributor The address of the merkle distributor
|
|
48
|
-
* @param claimant Optional claimant address. If not provided, uses the wallet's address.
|
|
49
|
-
* @returns The ClaimStatus PDA address
|
|
50
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
51
|
-
*/
|
|
52
|
-
async getClaimStatusPda(distributor, claimant) {
|
|
53
|
-
let claimantAddress;
|
|
54
|
-
if (claimant) {
|
|
55
|
-
claimantAddress = claimant;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
if (!this.sdk.wallet) {
|
|
59
|
-
throw new Error('Wallet not set. Please set a wallet or provide a claimant address.');
|
|
60
|
-
}
|
|
61
|
-
claimantAddress = this.sdk.wallet.address;
|
|
62
|
-
}
|
|
63
|
-
return await this.sdk.solana.pda(['ClaimStatus', claimantAddress, distributor], this.getProgramId());
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Fetch a merkle distributor account by address
|
|
67
|
-
*/
|
|
68
|
-
async get(addr) {
|
|
69
|
-
try {
|
|
70
|
-
const distributorAccount = await this.client.fetchMerkleDistributor(this.sdk.solana.rpc, addr);
|
|
71
|
-
const distributor = this.transformMerkleDistributorAccount(distributorAccount);
|
|
72
|
-
return distributor;
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
this.sdk.logger.error(`Failed to fetch merkle distributor ${err}`);
|
|
76
|
-
throw err;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Fetch all merkle distributor accounts
|
|
81
|
-
*/
|
|
82
|
-
async all() {
|
|
83
|
-
try {
|
|
84
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
85
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
86
|
-
encoding: 'base64',
|
|
87
|
-
filters: [
|
|
88
|
-
{
|
|
89
|
-
memcmp: {
|
|
90
|
-
offset: BigInt(0),
|
|
91
|
-
bytes: bs58.encode(Buffer.from(this.client.MERKLE_DISTRIBUTOR_DISCRIMINATOR)),
|
|
92
|
-
encoding: 'base58',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
})
|
|
97
|
-
.send();
|
|
98
|
-
const distributors = getProgramAccountsResponse
|
|
99
|
-
.map((result) => {
|
|
100
|
-
try {
|
|
101
|
-
const distributorAccount = programClient.decodeMerkleDistributor(parseBase64RpcAccount(result.pubkey, result.account));
|
|
102
|
-
return this.transformMerkleDistributorAccount(distributorAccount);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
this.sdk.logger.error(`Failed to decode merkle distributor ${err}`);
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
.filter((account) => account !== null);
|
|
110
|
-
return distributors;
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
this.sdk.logger.error(`Failed to fetch all merkle distributors ${err}`);
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Fetch a claim status account by address
|
|
119
|
-
*/
|
|
120
|
-
async getClaimStatus(addr) {
|
|
121
|
-
try {
|
|
122
|
-
const maybeClaimStatus = await this.client.fetchMaybeClaimStatus(this.sdk.solana.rpc, addr);
|
|
123
|
-
// If account doesn't exist, throw a specific error
|
|
124
|
-
if (!maybeClaimStatus.exists) {
|
|
125
|
-
throw new ClaimStatusNotFoundError(addr);
|
|
126
|
-
}
|
|
127
|
-
// Transform and return the claim status
|
|
128
|
-
return this.transformClaimStatusAccount(maybeClaimStatus);
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
this.sdk.logger.error(`Failed to fetch claim status ${err}`);
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Fetch claim status for a specific distributor and optional claimant.
|
|
137
|
-
* Derives the ClaimStatus PDA using the claimant address (or wallet's address if not provided) and the distributor address.
|
|
138
|
-
*
|
|
139
|
-
* @param distributor The address of the merkle distributor
|
|
140
|
-
* @param claimant Optional claimant address. If not provided, uses the wallet's address.
|
|
141
|
-
* @returns The claim status if it exists, null otherwise
|
|
142
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
143
|
-
*/
|
|
144
|
-
async getClaimStatusForDistributor(distributor, claimant) {
|
|
145
|
-
try {
|
|
146
|
-
// Derive ClaimStatus PDA
|
|
147
|
-
const claimStatusPda = await this.getClaimStatusPda(distributor, claimant);
|
|
148
|
-
// Reuse getClaimStatus to fetch and transform the claim status
|
|
149
|
-
// If the account doesn't exist, it will throw, so we catch and return null
|
|
150
|
-
return await this.getClaimStatus(claimStatusPda);
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
// If the account doesn't exist, return null instead of throwing
|
|
154
|
-
// Check if it's the specific ClaimStatusNotFoundError from getClaimStatus
|
|
155
|
-
if (err instanceof ClaimStatusNotFoundError) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
// For other errors, log and rethrow
|
|
159
|
-
this.sdk.logger.error(`Failed to fetch claim status ${err}`);
|
|
160
|
-
throw err;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Fetch all claim status accounts
|
|
165
|
-
* TODO: add filter for claimant and distributor
|
|
166
|
-
*/
|
|
167
|
-
async allClaimStatus() {
|
|
168
|
-
try {
|
|
169
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
170
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
171
|
-
encoding: 'base64',
|
|
172
|
-
filters: [
|
|
173
|
-
{
|
|
174
|
-
memcmp: {
|
|
175
|
-
offset: BigInt(0),
|
|
176
|
-
bytes: bs58.encode(Buffer.from(this.client.CLAIM_STATUS_DISCRIMINATOR)),
|
|
177
|
-
encoding: 'base58',
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
})
|
|
182
|
-
.send();
|
|
183
|
-
const claimStatuses = getProgramAccountsResponse
|
|
184
|
-
.map((result) => {
|
|
185
|
-
try {
|
|
186
|
-
const claimStatusAccount = programClient.decodeClaimStatus(parseBase64RpcAccount(result.pubkey, result.account));
|
|
187
|
-
return this.transformClaimStatusAccount(claimStatusAccount);
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
this.sdk.logger.error(`Failed to decode claim status ${err}`);
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
.filter((account) => account !== null);
|
|
195
|
-
return claimStatuses;
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
this.sdk.logger.error(`Failed to fetch all claim statuses ${err}`);
|
|
199
|
-
throw err;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Transform merkle distributor account to include address and convert BigInt to numbers
|
|
204
|
-
*/
|
|
205
|
-
transformMerkleDistributorAccount(distributorAccount) {
|
|
206
|
-
const {
|
|
207
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
208
|
-
discriminator: _, root, buffer0, buffer1, buffer2, ...distributorAccountData } = distributorAccount.data;
|
|
209
|
-
const converted = convertBigIntToNumber(distributorAccountData);
|
|
210
|
-
return {
|
|
211
|
-
address: distributorAccount.address,
|
|
212
|
-
...converted,
|
|
213
|
-
root: bs58.encode(Buffer.from(root)),
|
|
214
|
-
buffer0: bs58.encode(Buffer.from(buffer0)),
|
|
215
|
-
buffer1: bs58.encode(Buffer.from(buffer1)),
|
|
216
|
-
buffer2: bs58.encode(Buffer.from(buffer2)),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Transform claim status account to include address and convert BigInt to numbers
|
|
221
|
-
*/
|
|
222
|
-
transformClaimStatusAccount(claimStatusAccount) {
|
|
223
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
224
|
-
const { discriminator: _, ...claimStatusAccountData } = claimStatusAccount.data;
|
|
225
|
-
return {
|
|
226
|
-
address: claimStatusAccount.address,
|
|
227
|
-
...convertBigIntToNumber(claimStatusAccountData),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Claim tokens from a merkle distributor.
|
|
232
|
-
* This function creates a new ClaimStatus account and claims the tokens in a single instruction.
|
|
233
|
-
*
|
|
234
|
-
* @param params Parameters for claiming tokens
|
|
235
|
-
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
236
|
-
* @returns The newClaim instruction
|
|
237
|
-
* @throws NosanaError if tokens have already been claimed
|
|
238
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
239
|
-
*/
|
|
240
|
-
async claim(params) {
|
|
241
|
-
// Determine claimant signer and address
|
|
242
|
-
let claimantSigner;
|
|
243
|
-
let claimantAddress;
|
|
244
|
-
if (params.claimant) {
|
|
245
|
-
claimantSigner = params.claimant;
|
|
246
|
-
claimantAddress = params.claimant.address;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
if (!this.sdk.wallet) {
|
|
250
|
-
throw new Error('Wallet not set. Please set a wallet or provide a claimant signer.');
|
|
251
|
-
}
|
|
252
|
-
claimantSigner = this.sdk.wallet;
|
|
253
|
-
claimantAddress = this.sdk.wallet.address;
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
// Get the distributor account to find mint and tokenVault
|
|
257
|
-
const distributorAccount = await this.client.fetchMerkleDistributor(this.sdk.solana.rpc, params.distributor);
|
|
258
|
-
// Derive ClaimStatus PDA using the claimant address
|
|
259
|
-
const claimStatusPda = await this.getClaimStatusPda(params.distributor, claimantAddress);
|
|
260
|
-
// Check if ClaimStatus account exists
|
|
261
|
-
const maybeClaimStatus = await this.client.fetchMaybeClaimStatus(this.sdk.solana.rpc, claimStatusPda);
|
|
262
|
-
// If ClaimStatus already exists, throw an error (already claimed)
|
|
263
|
-
if (maybeClaimStatus.exists) {
|
|
264
|
-
throw new NosanaError('Tokens have already been claimed from this distributor', ErrorCodes.VALIDATION_ERROR);
|
|
265
|
-
}
|
|
266
|
-
// Get the target address for receiving tokens (YES or NO)
|
|
267
|
-
const targetAddress = ALLOWED_RECEIVE_ADDRESSES[params.target];
|
|
268
|
-
// Find the ATA of the target address (where tokens will be sent)
|
|
269
|
-
const [targetAta] = await findAssociatedTokenPda({
|
|
270
|
-
mint: distributorAccount.data.mint,
|
|
271
|
-
owner: targetAddress,
|
|
272
|
-
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
273
|
-
});
|
|
274
|
-
// Create newClaim instruction which creates the account and claims the tokens
|
|
275
|
-
// Note: tokens go to the ATA of the target address (YES or NO), not the claimant's ATA
|
|
276
|
-
// The claimant in the instruction is the claimant signer (or wallet if not provided)
|
|
277
|
-
const newClaimInstruction = programClient.getNewClaimInstruction({
|
|
278
|
-
distributor: params.distributor,
|
|
279
|
-
claimStatus: claimStatusPda,
|
|
280
|
-
from: distributorAccount.data.tokenVault,
|
|
281
|
-
to: targetAta, // ATA of YES or NO address, not claimant's ATA
|
|
282
|
-
claimant: claimantSigner, // Claimant signer (or wallet if not provided)
|
|
283
|
-
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
284
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
285
|
-
amountUnlocked: params.amountUnlocked,
|
|
286
|
-
amountLocked: params.amountLocked,
|
|
287
|
-
proof: params.proof,
|
|
288
|
-
}, { programAddress: this.getProgramId() });
|
|
289
|
-
return newClaimInstruction;
|
|
290
|
-
}
|
|
291
|
-
catch (err) {
|
|
292
|
-
this.sdk.logger.error(`Failed to create claim instructions: ${err}`);
|
|
293
|
-
throw err;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Clawback tokens from a merkle distributor.
|
|
298
|
-
* This function creates a clawback instruction to transfer tokens from the distributor's token vault to the clawback receiver.
|
|
299
|
-
*
|
|
300
|
-
* @param params Parameters for clawback
|
|
301
|
-
* @param params.distributor The address of the merkle distributor
|
|
302
|
-
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
303
|
-
* @returns The clawback instruction
|
|
304
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
305
|
-
*/
|
|
306
|
-
async clawback(params) {
|
|
307
|
-
// Determine claimant signer
|
|
308
|
-
let claimantSigner;
|
|
309
|
-
if (params.claimant) {
|
|
310
|
-
claimantSigner = params.claimant;
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
if (!this.sdk.wallet) {
|
|
314
|
-
throw new Error('Wallet not set. Please set a wallet or provide a claimant signer.');
|
|
315
|
-
}
|
|
316
|
-
claimantSigner = this.sdk.wallet;
|
|
317
|
-
}
|
|
318
|
-
try {
|
|
319
|
-
// Get the distributor account to find tokenVault and clawbackReceiver
|
|
320
|
-
const distributorAccount = await this.client.fetchMerkleDistributor(this.sdk.solana.rpc, params.distributor);
|
|
321
|
-
// Create clawback instruction
|
|
322
|
-
const clawbackInstruction = this.client.getClawbackInstruction({
|
|
323
|
-
distributor: params.distributor,
|
|
324
|
-
from: distributorAccount.data.tokenVault,
|
|
325
|
-
to: distributorAccount.data.clawbackReceiver,
|
|
326
|
-
claimant: claimantSigner,
|
|
327
|
-
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
328
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
329
|
-
}, { programAddress: this.getProgramId() });
|
|
330
|
-
return clawbackInstruction;
|
|
331
|
-
}
|
|
332
|
-
catch (err) {
|
|
333
|
-
this.sdk.logger.error(`Failed to create clawback instruction: ${err}`);
|
|
334
|
-
throw err;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { Address, Account } from 'gill';
|
|
3
|
-
import { NosanaClient } from '../index.js';
|
|
4
|
-
import * as programClient from '../generated_clients/staking/index.js';
|
|
5
|
-
import { ConvertTypesForDb } from '../utils/index.js';
|
|
6
|
-
export type Stake = ConvertTypesForDb<programClient.StakeAccountArgs> & {
|
|
7
|
-
address: Address;
|
|
8
|
-
};
|
|
9
|
-
export declare class StakeProgram extends BaseProgram {
|
|
10
|
-
readonly client: typeof programClient;
|
|
11
|
-
constructor(sdk: NosanaClient);
|
|
12
|
-
protected getProgramId(): Address;
|
|
13
|
-
/**
|
|
14
|
-
* Fetch a stake account by address
|
|
15
|
-
*/
|
|
16
|
-
get(addr: Address): Promise<Stake>;
|
|
17
|
-
/**
|
|
18
|
-
* Fetch multiple stake accounts by address
|
|
19
|
-
*/
|
|
20
|
-
multiple(addresses: Address[]): Promise<Stake[]>;
|
|
21
|
-
/**
|
|
22
|
-
* Fetch all stake accounts
|
|
23
|
-
*/
|
|
24
|
-
all(): Promise<Stake[]>;
|
|
25
|
-
/**
|
|
26
|
-
* Transform stake account to include address and convert BigInt to numbers
|
|
27
|
-
*/
|
|
28
|
-
transformStakeAccount(stakeAccount: Account<programClient.StakeAccount>): Stake;
|
|
29
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { parseBase64RpcAccount } from 'gill';
|
|
3
|
-
import * as programClient from '../generated_clients/staking/index.js';
|
|
4
|
-
import { convertBigIntToNumber } from '../utils/index.js';
|
|
5
|
-
import bs58 from 'bs58';
|
|
6
|
-
export class StakeProgram extends BaseProgram {
|
|
7
|
-
constructor(sdk) {
|
|
8
|
-
super(sdk);
|
|
9
|
-
this.client = programClient;
|
|
10
|
-
}
|
|
11
|
-
getProgramId() {
|
|
12
|
-
return this.sdk.config.programs.stakeAddress;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Fetch a stake account by address
|
|
16
|
-
*/
|
|
17
|
-
async get(addr) {
|
|
18
|
-
try {
|
|
19
|
-
const stakeAccount = await this.client.fetchStakeAccount(this.sdk.solana.rpc, addr);
|
|
20
|
-
const stake = this.transformStakeAccount(stakeAccount);
|
|
21
|
-
return stake;
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
this.sdk.logger.error(`Failed to fetch stake ${err}`);
|
|
25
|
-
throw err;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Fetch multiple stake accounts by address
|
|
30
|
-
*/
|
|
31
|
-
async multiple(addresses) {
|
|
32
|
-
try {
|
|
33
|
-
const stakeAccounts = await this.client.fetchAllStakeAccount(this.sdk.solana.rpc, addresses);
|
|
34
|
-
const stakes = stakeAccounts.map((stakeAccount) => this.transformStakeAccount(stakeAccount));
|
|
35
|
-
return stakes;
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
this.sdk.logger.error(`Failed to fetch stakes ${err}`);
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Fetch all stake accounts
|
|
44
|
-
*/
|
|
45
|
-
async all() {
|
|
46
|
-
try {
|
|
47
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
48
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
49
|
-
encoding: 'base64',
|
|
50
|
-
filters: [
|
|
51
|
-
{
|
|
52
|
-
memcmp: {
|
|
53
|
-
offset: BigInt(0),
|
|
54
|
-
bytes: bs58.encode(Buffer.from(this.client.STAKE_ACCOUNT_DISCRIMINATOR)),
|
|
55
|
-
encoding: 'base58',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
})
|
|
60
|
-
.send();
|
|
61
|
-
const stakes = getProgramAccountsResponse
|
|
62
|
-
.map((result) => {
|
|
63
|
-
try {
|
|
64
|
-
const stakeAccount = programClient.decodeStakeAccount(parseBase64RpcAccount(result.pubkey, result.account));
|
|
65
|
-
return this.transformStakeAccount(stakeAccount);
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
this.sdk.logger.error(`Failed to decode stake ${err}`);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
.filter((account) => account !== null);
|
|
73
|
-
return stakes;
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
this.sdk.logger.error(`Failed to fetch all stakes ${err}`);
|
|
77
|
-
throw err;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Transform stake account to include address and convert BigInt to numbers
|
|
82
|
-
*/
|
|
83
|
-
transformStakeAccount(stakeAccount) {
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
-
const { discriminator: _, ...stakeAccountData } = stakeAccount.data;
|
|
86
|
-
return {
|
|
87
|
-
address: stakeAccount.address,
|
|
88
|
-
...convertBigIntToNumber(stakeAccountData),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Address } from 'gill';
|
|
2
|
-
import { NosanaClient } from '../index.js';
|
|
3
|
-
export interface TokenAccount {
|
|
4
|
-
pubkey: Address;
|
|
5
|
-
owner: Address;
|
|
6
|
-
mint: Address;
|
|
7
|
-
amount: bigint;
|
|
8
|
-
decimals: number;
|
|
9
|
-
}
|
|
10
|
-
export interface TokenAccountWithBalance extends TokenAccount {
|
|
11
|
-
uiAmount: number;
|
|
12
|
-
}
|
|
13
|
-
export declare class NosService {
|
|
14
|
-
private readonly sdk;
|
|
15
|
-
constructor(sdk: NosanaClient);
|
|
16
|
-
/**
|
|
17
|
-
* Get the NOS token mint address for the current network
|
|
18
|
-
*/
|
|
19
|
-
private getNosTokenMint;
|
|
20
|
-
/**
|
|
21
|
-
* Retrieve all token accounts for all NOS token holders
|
|
22
|
-
* Uses a single RPC call to fetch all accounts holding the NOS token
|
|
23
|
-
*
|
|
24
|
-
* @param options - Optional configuration
|
|
25
|
-
* @param options.includeZeroBalance - Whether to include accounts with zero balance (default: false)
|
|
26
|
-
* @param options.excludePdaAccounts - Whether to exclude PDA (Program Derived Address) accounts owned by smart contracts (default: false)
|
|
27
|
-
* @returns Array of token accounts with their balances
|
|
28
|
-
*/
|
|
29
|
-
getAllTokenHolders(options?: {
|
|
30
|
-
includeZeroBalance?: boolean;
|
|
31
|
-
excludePdaAccounts?: boolean;
|
|
32
|
-
}): Promise<TokenAccountWithBalance[]>;
|
|
33
|
-
/**
|
|
34
|
-
* Retrieve the NOS token account for a specific owner address
|
|
35
|
-
*
|
|
36
|
-
* @param owner - The owner address to query
|
|
37
|
-
* @returns The token account with balance, or null if no account exists
|
|
38
|
-
*/
|
|
39
|
-
getTokenAccountForAddress(owner: string | Address): Promise<TokenAccountWithBalance | null>;
|
|
40
|
-
/**
|
|
41
|
-
* Get the NOS token balance for a specific owner address
|
|
42
|
-
* Convenience method that returns just the balance
|
|
43
|
-
*
|
|
44
|
-
* @param owner - The owner address to query
|
|
45
|
-
* @returns The token balance as a UI amount (with decimals), or 0 if no account exists
|
|
46
|
-
*/
|
|
47
|
-
getBalance(owner: string | Address): Promise<number>;
|
|
48
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { address } from 'gill';
|
|
2
|
-
import { NosanaError, ErrorCodes } from '../errors/NosanaError.js';
|
|
3
|
-
import { TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
4
|
-
// Standard SPL token account size
|
|
5
|
-
const TOKEN_ACCOUNT_SIZE = 165;
|
|
6
|
-
// Offset of mint address in token account data structure
|
|
7
|
-
const MINT_OFFSET = 0;
|
|
8
|
-
export class NosService {
|
|
9
|
-
constructor(sdk) {
|
|
10
|
-
this.sdk = sdk;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get the NOS token mint address for the current network
|
|
14
|
-
*/
|
|
15
|
-
getNosTokenMint() {
|
|
16
|
-
return this.sdk.config.programs.nosTokenAddress;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieve all token accounts for all NOS token holders
|
|
20
|
-
* Uses a single RPC call to fetch all accounts holding the NOS token
|
|
21
|
-
*
|
|
22
|
-
* @param options - Optional configuration
|
|
23
|
-
* @param options.includeZeroBalance - Whether to include accounts with zero balance (default: false)
|
|
24
|
-
* @param options.excludePdaAccounts - Whether to exclude PDA (Program Derived Address) accounts owned by smart contracts (default: false)
|
|
25
|
-
* @returns Array of token accounts with their balances
|
|
26
|
-
*/
|
|
27
|
-
async getAllTokenHolders(options) {
|
|
28
|
-
try {
|
|
29
|
-
const nosMint = this.getNosTokenMint();
|
|
30
|
-
this.sdk.logger.debug(`Fetching all NOS token holders for mint: ${nosMint}`);
|
|
31
|
-
// Use getProgramAccounts to fetch all token accounts for the NOS mint
|
|
32
|
-
const accounts = await this.sdk.solana.rpc
|
|
33
|
-
.getProgramAccounts(TOKEN_PROGRAM_ADDRESS, {
|
|
34
|
-
encoding: 'jsonParsed',
|
|
35
|
-
filters: [
|
|
36
|
-
{
|
|
37
|
-
dataSize: BigInt(TOKEN_ACCOUNT_SIZE),
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
memcmp: {
|
|
41
|
-
offset: BigInt(MINT_OFFSET),
|
|
42
|
-
bytes: nosMint.toString(),
|
|
43
|
-
encoding: 'base58',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
})
|
|
48
|
-
.send();
|
|
49
|
-
this.sdk.logger.info(`Found ${accounts.length} NOS token accounts`);
|
|
50
|
-
// Parse the response
|
|
51
|
-
const allAccounts = accounts.map((accountInfo) => {
|
|
52
|
-
const parsed = accountInfo.account.data.parsed.info;
|
|
53
|
-
return {
|
|
54
|
-
pubkey: accountInfo.pubkey,
|
|
55
|
-
owner: parsed.owner,
|
|
56
|
-
mint: parsed.mint,
|
|
57
|
-
amount: BigInt(parsed.tokenAmount.amount),
|
|
58
|
-
decimals: parsed.tokenAmount.decimals,
|
|
59
|
-
uiAmount: parsed.tokenAmount.uiAmount ?? 0,
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
// Apply filters
|
|
63
|
-
const includeZeroBalance = options?.includeZeroBalance ?? false;
|
|
64
|
-
const excludePdaAccounts = options?.excludePdaAccounts ?? false;
|
|
65
|
-
let filteredAccounts = allAccounts;
|
|
66
|
-
// Filter out zero balance accounts unless explicitly included
|
|
67
|
-
if (!includeZeroBalance) {
|
|
68
|
-
filteredAccounts = filteredAccounts.filter((account) => account.uiAmount > 0);
|
|
69
|
-
}
|
|
70
|
-
// Filter out PDA accounts (where token account equals owner, indicating smart contract ownership)
|
|
71
|
-
if (excludePdaAccounts) {
|
|
72
|
-
const beforePdaFilter = filteredAccounts.length;
|
|
73
|
-
filteredAccounts = filteredAccounts.filter((account) => account.pubkey !== account.owner);
|
|
74
|
-
const pdaCount = beforePdaFilter - filteredAccounts.length;
|
|
75
|
-
this.sdk.logger.debug(`Filtered out ${pdaCount} PDA accounts`);
|
|
76
|
-
}
|
|
77
|
-
const filterInfo = [];
|
|
78
|
-
if (!includeZeroBalance)
|
|
79
|
-
filterInfo.push('excluding zero balances');
|
|
80
|
-
if (excludePdaAccounts)
|
|
81
|
-
filterInfo.push('excluding PDA accounts');
|
|
82
|
-
const filterText = filterInfo.length > 0 ? ` (${filterInfo.join(', ')})` : '';
|
|
83
|
-
this.sdk.logger.info(`Returning ${filteredAccounts.length} NOS token holders${filterText}`);
|
|
84
|
-
return filteredAccounts;
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
this.sdk.logger.error(`Failed to fetch NOS token holders: ${error}`);
|
|
88
|
-
throw new NosanaError('Failed to fetch NOS token holders', ErrorCodes.RPC_ERROR, error);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Retrieve the NOS token account for a specific owner address
|
|
93
|
-
*
|
|
94
|
-
* @param owner - The owner address to query
|
|
95
|
-
* @returns The token account with balance, or null if no account exists
|
|
96
|
-
*/
|
|
97
|
-
async getTokenAccountForAddress(owner) {
|
|
98
|
-
try {
|
|
99
|
-
const ownerAddr = typeof owner === 'string' ? address(owner) : owner;
|
|
100
|
-
const nosMint = this.getNosTokenMint();
|
|
101
|
-
this.sdk.logger.debug(`Fetching NOS token account for owner: ${ownerAddr}`);
|
|
102
|
-
// Use getTokenAccountsByOwner to fetch token accounts for this owner filtered by NOS mint
|
|
103
|
-
const response = await this.sdk.solana.rpc
|
|
104
|
-
.getTokenAccountsByOwner(ownerAddr, { mint: nosMint }, { encoding: 'jsonParsed' })
|
|
105
|
-
.send();
|
|
106
|
-
if (response.value.length === 0) {
|
|
107
|
-
this.sdk.logger.debug(`No NOS token account found for owner: ${ownerAddr}`);
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
// Typically there should only be one token account per owner per mint
|
|
111
|
-
const accountInfo = response.value[0];
|
|
112
|
-
const parsed = accountInfo.account.data.parsed.info;
|
|
113
|
-
this.sdk.logger.info(`Found NOS token account for owner ${ownerAddr}: balance = ${parsed.tokenAmount.uiAmount}`);
|
|
114
|
-
return {
|
|
115
|
-
pubkey: accountInfo.pubkey,
|
|
116
|
-
owner: parsed.owner,
|
|
117
|
-
mint: parsed.mint,
|
|
118
|
-
amount: BigInt(parsed.tokenAmount.amount),
|
|
119
|
-
decimals: parsed.tokenAmount.decimals,
|
|
120
|
-
uiAmount: parsed.tokenAmount.uiAmount ?? 0,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
this.sdk.logger.error(`Failed to fetch NOS token account for owner: ${error}`);
|
|
125
|
-
throw new NosanaError('Failed to fetch NOS token account', ErrorCodes.RPC_ERROR, error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get the NOS token balance for a specific owner address
|
|
130
|
-
* Convenience method that returns just the balance
|
|
131
|
-
*
|
|
132
|
-
* @param owner - The owner address to query
|
|
133
|
-
* @returns The token balance as a UI amount (with decimals), or 0 if no account exists
|
|
134
|
-
*/
|
|
135
|
-
async getBalance(owner) {
|
|
136
|
-
const account = await this.getTokenAccountForAddress(owner);
|
|
137
|
-
return account ? account.uiAmount : 0;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { KeyPairSigner } from 'gill';
|
|
2
|
-
import { WalletConfig } from '../config/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Converts various wallet configurations to a KeyPairSigner
|
|
5
|
-
* @param wallet The wallet configuration to convert
|
|
6
|
-
* @returns A KeyPairSigner instance
|
|
7
|
-
* @throws NosanaError if conversion fails
|
|
8
|
-
*/
|
|
9
|
-
export declare function convertWalletConfigToKeyPairSigner(wallet: WalletConfig): Promise<KeyPairSigner>;
|