@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,559 +0,0 @@
|
|
|
1
|
-
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { generateKeyPairSigner, parseBase64RpcAccount, } from 'gill';
|
|
3
|
-
import { ErrorCodes, NosanaError } from '../index.js';
|
|
4
|
-
import * as programClient from '../generated_clients/jobs/index.js';
|
|
5
|
-
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
6
|
-
import bs58 from 'bs58';
|
|
7
|
-
import { IPFS } from '../ipfs/IPFS.js';
|
|
8
|
-
import { convertBigIntToNumber } from '../utils/index.js';
|
|
9
|
-
export var JobState;
|
|
10
|
-
(function (JobState) {
|
|
11
|
-
JobState[JobState["QUEUED"] = 0] = "QUEUED";
|
|
12
|
-
JobState[JobState["RUNNING"] = 1] = "RUNNING";
|
|
13
|
-
JobState[JobState["COMPLETED"] = 2] = "COMPLETED";
|
|
14
|
-
JobState[JobState["STOPPED"] = 3] = "STOPPED";
|
|
15
|
-
})(JobState || (JobState = {}));
|
|
16
|
-
export var MarketQueueType;
|
|
17
|
-
(function (MarketQueueType) {
|
|
18
|
-
MarketQueueType[MarketQueueType["JOB_QUEUE"] = 0] = "JOB_QUEUE";
|
|
19
|
-
MarketQueueType[MarketQueueType["NODE_QUEUE"] = 1] = "NODE_QUEUE";
|
|
20
|
-
})(MarketQueueType || (MarketQueueType = {}));
|
|
21
|
-
export class JobsProgram extends BaseProgram {
|
|
22
|
-
constructor(sdk) {
|
|
23
|
-
super(sdk);
|
|
24
|
-
this.client = programClient;
|
|
25
|
-
}
|
|
26
|
-
getProgramId() {
|
|
27
|
-
return this.sdk.config.programs.jobsAddress;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fetch a job account by address
|
|
31
|
-
*/
|
|
32
|
-
async get(addr, checkRun = true) {
|
|
33
|
-
try {
|
|
34
|
-
const jobAccount = await this.client.fetchJobAccount(this.sdk.solana.rpc, addr);
|
|
35
|
-
const job = this.transformJobAccount(jobAccount);
|
|
36
|
-
if (checkRun && job.state === JobState.QUEUED) {
|
|
37
|
-
// If job is queued, check if there is a run account for the job
|
|
38
|
-
const runs = await this.runs({ job: job.address });
|
|
39
|
-
if (runs.length > 0) {
|
|
40
|
-
const run = runs[0];
|
|
41
|
-
job.state = JobState.RUNNING;
|
|
42
|
-
job.timeStart = run.time;
|
|
43
|
-
job.node = run.node;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return job;
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
this.sdk.logger.error(`Failed to fetch job ${err}`);
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Fetch a run account by address
|
|
55
|
-
*/
|
|
56
|
-
async run(addr) {
|
|
57
|
-
try {
|
|
58
|
-
const runAccount = await this.client.fetchRunAccount(this.sdk.solana.rpc, addr);
|
|
59
|
-
const run = this.transformRunAccount(runAccount);
|
|
60
|
-
return run;
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
this.sdk.logger.error(`Failed to fetch run ${err}`);
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Fetch a run account by address
|
|
69
|
-
*/
|
|
70
|
-
async market(addr) {
|
|
71
|
-
try {
|
|
72
|
-
const marketAccount = await this.client.fetchMarketAccount(this.sdk.solana.rpc, addr);
|
|
73
|
-
const market = this.transformMarketAccount(marketAccount);
|
|
74
|
-
return market;
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
this.sdk.logger.error(`Failed to fetch market ${err}`);
|
|
78
|
-
throw err;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Fetch multiple job accounts by address
|
|
83
|
-
*/
|
|
84
|
-
async multiple(addresses, checkRuns = false) {
|
|
85
|
-
try {
|
|
86
|
-
const jobAccounts = await this.client.fetchAllJobAccount(this.sdk.solana.rpc, addresses);
|
|
87
|
-
const jobs = jobAccounts.map((jobAccount) => this.transformJobAccount(jobAccount));
|
|
88
|
-
if (checkRuns) {
|
|
89
|
-
const runs = await this.runs();
|
|
90
|
-
jobs.forEach((job) => {
|
|
91
|
-
if (job.state === JobState.QUEUED) {
|
|
92
|
-
const run = runs.find((run) => run.job === job.address);
|
|
93
|
-
if (run) {
|
|
94
|
-
job.state = JobState.RUNNING;
|
|
95
|
-
job.timeStart = run.time;
|
|
96
|
-
job.node = run.node;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return jobs;
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
this.sdk.logger.error(`Failed to fetch job ${err}`);
|
|
105
|
-
throw err;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Fetch all job accounts
|
|
110
|
-
*/
|
|
111
|
-
async all(filters, checkRuns = false) {
|
|
112
|
-
try {
|
|
113
|
-
const extraGPAFilters = [];
|
|
114
|
-
if (filters) {
|
|
115
|
-
if (typeof filters.state === 'number') {
|
|
116
|
-
extraGPAFilters.push({
|
|
117
|
-
memcmp: {
|
|
118
|
-
offset: BigInt(208),
|
|
119
|
-
bytes: bs58.encode(Buffer.from([filters.state])),
|
|
120
|
-
encoding: 'base58',
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (filters.project) {
|
|
125
|
-
extraGPAFilters.push({
|
|
126
|
-
memcmp: {
|
|
127
|
-
offset: BigInt(176),
|
|
128
|
-
bytes: filters.project.toString(),
|
|
129
|
-
encoding: 'base58',
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (filters.node) {
|
|
134
|
-
extraGPAFilters.push({
|
|
135
|
-
memcmp: {
|
|
136
|
-
offset: BigInt(104),
|
|
137
|
-
bytes: filters.node.toString(),
|
|
138
|
-
encoding: 'base58',
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (filters.market) {
|
|
143
|
-
extraGPAFilters.push({
|
|
144
|
-
memcmp: {
|
|
145
|
-
offset: BigInt(72),
|
|
146
|
-
bytes: filters.market.toString(),
|
|
147
|
-
encoding: 'base58',
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
153
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
154
|
-
encoding: 'base64',
|
|
155
|
-
filters: [
|
|
156
|
-
{
|
|
157
|
-
memcmp: {
|
|
158
|
-
offset: BigInt(0),
|
|
159
|
-
bytes: bs58.encode(Buffer.from(programClient.JOB_ACCOUNT_DISCRIMINATOR)),
|
|
160
|
-
encoding: 'base58',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
...extraGPAFilters,
|
|
164
|
-
],
|
|
165
|
-
})
|
|
166
|
-
.send();
|
|
167
|
-
const jobs = getProgramAccountsResponse
|
|
168
|
-
.map((result) => {
|
|
169
|
-
try {
|
|
170
|
-
const jobAccount = programClient.decodeJobAccount(parseBase64RpcAccount(result.pubkey, result.account));
|
|
171
|
-
return this.transformJobAccount(jobAccount);
|
|
172
|
-
}
|
|
173
|
-
catch (err) {
|
|
174
|
-
this.sdk.logger.error(`Failed to decode job ${err}`);
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
.filter((account) => account !== null);
|
|
179
|
-
if (checkRuns) {
|
|
180
|
-
const runs = await this.runs();
|
|
181
|
-
jobs.forEach((job) => {
|
|
182
|
-
if (job.state === JobState.QUEUED) {
|
|
183
|
-
const run = runs.find((run) => run.job === job.address);
|
|
184
|
-
if (run) {
|
|
185
|
-
job.state = JobState.RUNNING;
|
|
186
|
-
job.timeStart = run.time;
|
|
187
|
-
job.node = run.node;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
return jobs;
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
this.sdk.logger.error(`Failed to fetch all jobs ${err}`);
|
|
196
|
-
throw err;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Fetch all run accounts
|
|
201
|
-
*/
|
|
202
|
-
async runs(filters) {
|
|
203
|
-
try {
|
|
204
|
-
const extraGPAFilters = [];
|
|
205
|
-
if (filters) {
|
|
206
|
-
if (filters.node) {
|
|
207
|
-
extraGPAFilters.push({
|
|
208
|
-
memcmp: {
|
|
209
|
-
offset: BigInt(40),
|
|
210
|
-
bytes: filters.node.toString(),
|
|
211
|
-
encoding: 'base58',
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
if (filters.job) {
|
|
216
|
-
extraGPAFilters.push({
|
|
217
|
-
memcmp: {
|
|
218
|
-
offset: BigInt(8),
|
|
219
|
-
bytes: filters.job.toString(),
|
|
220
|
-
encoding: 'base58',
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
226
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
227
|
-
encoding: 'base64',
|
|
228
|
-
filters: [
|
|
229
|
-
{
|
|
230
|
-
memcmp: {
|
|
231
|
-
offset: BigInt(0),
|
|
232
|
-
bytes: bs58.encode(Buffer.from(programClient.RUN_ACCOUNT_DISCRIMINATOR)),
|
|
233
|
-
encoding: 'base58',
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
})
|
|
238
|
-
.send();
|
|
239
|
-
const runAccounts = getProgramAccountsResponse
|
|
240
|
-
.map((result) => {
|
|
241
|
-
try {
|
|
242
|
-
const runAccount = programClient.decodeRunAccount(parseBase64RpcAccount(result.pubkey, result.account));
|
|
243
|
-
return this.transformRunAccount(runAccount);
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
this.sdk.logger.error(`Failed to decode run ${err}`);
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
})
|
|
250
|
-
.filter((account) => account !== null);
|
|
251
|
-
return runAccounts;
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
this.sdk.logger.error(`Failed to fetch all runs ${err}`);
|
|
255
|
-
throw err;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Fetch all market accounts
|
|
260
|
-
*/
|
|
261
|
-
async markets() {
|
|
262
|
-
try {
|
|
263
|
-
const getProgramAccountsResponse = await this.sdk.solana.rpc
|
|
264
|
-
.getProgramAccounts(this.getProgramId(), {
|
|
265
|
-
encoding: 'base64',
|
|
266
|
-
filters: [
|
|
267
|
-
{
|
|
268
|
-
memcmp: {
|
|
269
|
-
offset: BigInt(0),
|
|
270
|
-
bytes: bs58.encode(Buffer.from(programClient.MARKET_ACCOUNT_DISCRIMINATOR)),
|
|
271
|
-
encoding: 'base58',
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
],
|
|
275
|
-
})
|
|
276
|
-
.send();
|
|
277
|
-
const marketAccounts = getProgramAccountsResponse
|
|
278
|
-
.map((result) => {
|
|
279
|
-
try {
|
|
280
|
-
const marketAccount = programClient.decodeMarketAccount(parseBase64RpcAccount(result.pubkey, result.account));
|
|
281
|
-
return this.transformMarketAccount(marketAccount);
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
this.sdk.logger.error(`Failed to decode market ${err}`);
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
.filter((account) => account !== null);
|
|
289
|
-
return marketAccounts;
|
|
290
|
-
}
|
|
291
|
-
catch (err) {
|
|
292
|
-
this.sdk.logger.error(`Failed to fetch all markets ${err}`);
|
|
293
|
-
throw err;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Post a new job to the marketplace
|
|
298
|
-
* @param params Parameters for listing a job
|
|
299
|
-
* @returns The transaction signature
|
|
300
|
-
*/
|
|
301
|
-
async post(params) {
|
|
302
|
-
const jobKey = await generateKeyPairSigner();
|
|
303
|
-
const runKey = await generateKeyPairSigner();
|
|
304
|
-
const [associatedTokenAddress] = await findAssociatedTokenPda({
|
|
305
|
-
mint: this.sdk.config.programs.nosTokenAddress,
|
|
306
|
-
owner: this.sdk.wallet.address,
|
|
307
|
-
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
308
|
-
});
|
|
309
|
-
try {
|
|
310
|
-
const staticAccounts = await this.getStaticAccounts();
|
|
311
|
-
// Create the list instruction
|
|
312
|
-
const instruction = this.client.getListInstruction({
|
|
313
|
-
job: jobKey,
|
|
314
|
-
market: params.market,
|
|
315
|
-
run: runKey,
|
|
316
|
-
user: associatedTokenAddress,
|
|
317
|
-
vault: await this.sdk.solana.pda([params.market, this.sdk.config.programs.nosTokenAddress], staticAccounts.jobsProgram),
|
|
318
|
-
payer: this.sdk.wallet,
|
|
319
|
-
rewardsReflection: staticAccounts.rewardsReflection,
|
|
320
|
-
rewardsVault: staticAccounts.rewardsVault,
|
|
321
|
-
authority: this.sdk.wallet,
|
|
322
|
-
rewardsProgram: staticAccounts.rewardsProgram,
|
|
323
|
-
ipfsJob: bs58.decode(params.ipfsHash).subarray(2),
|
|
324
|
-
timeout: params.timeout,
|
|
325
|
-
});
|
|
326
|
-
return instruction;
|
|
327
|
-
}
|
|
328
|
-
catch (err) {
|
|
329
|
-
const errorMessage = `Failed to create list instruction: ${err instanceof Error ? err.message : String(err)}`;
|
|
330
|
-
this.sdk.logger.error(errorMessage);
|
|
331
|
-
throw new Error(errorMessage);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Monitor program account updates using callback functions
|
|
336
|
-
* Uses WebSocket subscriptions with automatic restart on failure
|
|
337
|
-
*
|
|
338
|
-
* @example
|
|
339
|
-
* ```typescript
|
|
340
|
-
* // Example: Monitor job accounts and save to file
|
|
341
|
-
* const stopMonitoring = await jobsProgram.monitor({
|
|
342
|
-
* onJobAccount: async (jobAccount) => {
|
|
343
|
-
* console.log('Job updated:', jobAccount.address.toString());
|
|
344
|
-
* // Save to database, file, or process as needed
|
|
345
|
-
* },
|
|
346
|
-
* onRunAccount: async (runAccount) => {
|
|
347
|
-
* console.log('Run updated:', runAccount.address.toString());
|
|
348
|
-
* },
|
|
349
|
-
* onError: async (error, accountType) => {
|
|
350
|
-
* console.error('Error processing account:', error, accountType);
|
|
351
|
-
* }
|
|
352
|
-
* });
|
|
353
|
-
*
|
|
354
|
-
* // Stop monitoring when done
|
|
355
|
-
* stopMonitoring();
|
|
356
|
-
* ```
|
|
357
|
-
*
|
|
358
|
-
* @param options Configuration options for monitoring
|
|
359
|
-
* @returns A function to stop monitoring
|
|
360
|
-
*/
|
|
361
|
-
async monitor(options = {}) {
|
|
362
|
-
const { onJobAccount, onMarketAccount, onRunAccount, onError } = options;
|
|
363
|
-
const programId = this.getProgramId();
|
|
364
|
-
try {
|
|
365
|
-
this.sdk.logger.info(`Starting to monitor job program account updates for program: ${programId}`);
|
|
366
|
-
let abortController = null;
|
|
367
|
-
let isMonitoring = true;
|
|
368
|
-
// Function to stop all monitoring
|
|
369
|
-
const stopMonitoring = () => {
|
|
370
|
-
isMonitoring = false;
|
|
371
|
-
if (abortController) {
|
|
372
|
-
abortController.abort();
|
|
373
|
-
}
|
|
374
|
-
this.sdk.logger.info(`Stopped monitoring job program account updates`);
|
|
375
|
-
};
|
|
376
|
-
// Function to start/restart subscription with retry logic
|
|
377
|
-
const startSubscription = async () => {
|
|
378
|
-
while (isMonitoring) {
|
|
379
|
-
try {
|
|
380
|
-
this.sdk.logger.info('Attempting to establish WebSocket subscription...');
|
|
381
|
-
abortController = new AbortController();
|
|
382
|
-
const subscriptionIterable = await this.setupSubscription(abortController);
|
|
383
|
-
this.sdk.logger.info('Successfully established WebSocket subscription');
|
|
384
|
-
// Start processing subscription notifications
|
|
385
|
-
await this.processSubscriptionNotifications(subscriptionIterable, { onJobAccount, onMarketAccount, onRunAccount, onError }, () => isMonitoring);
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
this.sdk.logger.warn(`WebSocket subscription failed: ${error}`);
|
|
389
|
-
// Clean up current subscription
|
|
390
|
-
if (abortController) {
|
|
391
|
-
abortController.abort();
|
|
392
|
-
abortController = null;
|
|
393
|
-
}
|
|
394
|
-
if (isMonitoring) {
|
|
395
|
-
this.sdk.logger.info('Retrying WebSocket subscription in 5 seconds...');
|
|
396
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
// Start the subscription loop
|
|
402
|
-
startSubscription().catch((error) => {
|
|
403
|
-
this.sdk.logger.error(`Failed to start subscription loop: ${error}`);
|
|
404
|
-
});
|
|
405
|
-
this.sdk.logger.info(`Successfully started monitoring job program account updates`);
|
|
406
|
-
return stopMonitoring;
|
|
407
|
-
}
|
|
408
|
-
catch (error) {
|
|
409
|
-
this.sdk.logger.error(`Failed to start monitoring job program accounts: ${error}`);
|
|
410
|
-
throw new NosanaError('Failed to start monitoring job program accounts', ErrorCodes.RPC_ERROR, error);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Set up WebSocket subscription for program notifications
|
|
415
|
-
*/
|
|
416
|
-
async setupSubscription(abortController) {
|
|
417
|
-
try {
|
|
418
|
-
// Set up the subscription using the correct API pattern
|
|
419
|
-
const subscriptionIterable = await this.sdk.solana.rpcSubscriptions
|
|
420
|
-
.programNotifications(this.getProgramId(), { encoding: 'base64' })
|
|
421
|
-
.subscribe({ abortSignal: abortController.signal });
|
|
422
|
-
return subscriptionIterable;
|
|
423
|
-
}
|
|
424
|
-
catch (error) {
|
|
425
|
-
throw new Error(`Failed to setup subscription: ${error}`);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Process subscription notifications
|
|
430
|
-
*/
|
|
431
|
-
async processSubscriptionNotifications(notificationIterable, options, isMonitoring) {
|
|
432
|
-
try {
|
|
433
|
-
for await (const notification of notificationIterable) {
|
|
434
|
-
// Check if monitoring should continue
|
|
435
|
-
if (!isMonitoring()) {
|
|
436
|
-
this.sdk.logger.info('Monitoring stopped, exiting subscription processing');
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
try {
|
|
440
|
-
const { value } = notification;
|
|
441
|
-
await this.handleAccountUpdate(value, options, isMonitoring);
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
this.sdk.logger.error(`Error handling account update notification: ${error}`);
|
|
445
|
-
if (options.onError) {
|
|
446
|
-
try {
|
|
447
|
-
await options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
448
|
-
}
|
|
449
|
-
catch (callbackError) {
|
|
450
|
-
this.sdk.logger.error(`Error in onError callback: ${callbackError}`);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
catch (error) {
|
|
457
|
-
this.sdk.logger.error(`Subscription error: ${error}`);
|
|
458
|
-
// Throw the error so the calling function can restart the subscription
|
|
459
|
-
throw error;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
transformJobAccount(jobAccount) {
|
|
463
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
464
|
-
const { discriminator: _, ...jobAccountData } = jobAccount.data;
|
|
465
|
-
const converted = convertBigIntToNumber(jobAccountData);
|
|
466
|
-
return {
|
|
467
|
-
address: jobAccount.address,
|
|
468
|
-
...converted,
|
|
469
|
-
ipfsJob: IPFS.solHashToIpfsHash(jobAccountData.ipfsJob),
|
|
470
|
-
ipfsResult: IPFS.solHashToIpfsHash(jobAccountData.ipfsResult),
|
|
471
|
-
state: converted.state,
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
transformRunAccount(runAccount) {
|
|
475
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
476
|
-
const { discriminator: _, ...runAccountData } = runAccount.data;
|
|
477
|
-
return {
|
|
478
|
-
address: runAccount.address,
|
|
479
|
-
...convertBigIntToNumber(runAccountData),
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
transformMarketAccount(marketAccount) {
|
|
483
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
484
|
-
const { discriminator: _, ...marketAccountData } = marketAccount.data;
|
|
485
|
-
const converted = convertBigIntToNumber(marketAccountData);
|
|
486
|
-
return {
|
|
487
|
-
address: marketAccount.address,
|
|
488
|
-
...converted,
|
|
489
|
-
queueType: converted.queueType,
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Handle account update using callback functions
|
|
494
|
-
*/
|
|
495
|
-
async handleAccountUpdate(accountData, options, isMonitoring) {
|
|
496
|
-
try {
|
|
497
|
-
const { account, pubkey } = accountData;
|
|
498
|
-
const encodedAccount = parseBase64RpcAccount(pubkey, account);
|
|
499
|
-
const accountType = programClient.identifyNosanaJobsAccount(encodedAccount);
|
|
500
|
-
switch (accountType) {
|
|
501
|
-
case programClient.NosanaJobsAccount.JobAccount:
|
|
502
|
-
const jobAccount = programClient.decodeJobAccount(encodedAccount);
|
|
503
|
-
await this.handleJobAccount(jobAccount, options.onJobAccount, isMonitoring);
|
|
504
|
-
break;
|
|
505
|
-
case programClient.NosanaJobsAccount.MarketAccount:
|
|
506
|
-
const marketAccount = programClient.decodeMarketAccount(encodedAccount);
|
|
507
|
-
await this.handleMarketAccount(marketAccount, options.onMarketAccount, isMonitoring);
|
|
508
|
-
break;
|
|
509
|
-
case programClient.NosanaJobsAccount.RunAccount:
|
|
510
|
-
const runAccount = programClient.decodeRunAccount(encodedAccount);
|
|
511
|
-
await this.handleRunAccount(runAccount, options.onRunAccount, isMonitoring);
|
|
512
|
-
break;
|
|
513
|
-
default:
|
|
514
|
-
this.sdk.logger.error(`No support yet for account type: ${accountType}`);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
catch (error) {
|
|
519
|
-
this.sdk.logger.error(`Error in handleAccountUpdate: ${error}`);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
async handleJobAccount(jobAccount, onJobAccount, _isMonitoring) {
|
|
523
|
-
if (onJobAccount) {
|
|
524
|
-
try {
|
|
525
|
-
await onJobAccount(this.transformJobAccount(jobAccount));
|
|
526
|
-
}
|
|
527
|
-
catch (error) {
|
|
528
|
-
this.sdk.logger.error(`Error in onJobAccount callback: ${error}`);
|
|
529
|
-
throw error;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
this.sdk.logger.debug(`Processed job account ${jobAccount.address.toString()}`);
|
|
533
|
-
}
|
|
534
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
535
|
-
async handleMarketAccount(marketAccount, onMarketAccount, _isMonitoring) {
|
|
536
|
-
if (onMarketAccount) {
|
|
537
|
-
try {
|
|
538
|
-
await onMarketAccount(this.transformMarketAccount(marketAccount));
|
|
539
|
-
}
|
|
540
|
-
catch (error) {
|
|
541
|
-
this.sdk.logger.error(`Error in onMarketAccount callback: ${error}`);
|
|
542
|
-
throw error;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
this.sdk.logger.debug(`Processed market account ${marketAccount.address.toString()}`);
|
|
546
|
-
}
|
|
547
|
-
async handleRunAccount(runAccount, onRunAccount, _isMonitoring) {
|
|
548
|
-
if (onRunAccount) {
|
|
549
|
-
try {
|
|
550
|
-
await onRunAccount(this.transformRunAccount(runAccount));
|
|
551
|
-
}
|
|
552
|
-
catch (error) {
|
|
553
|
-
this.sdk.logger.error(`Error in onRunAccount callback: ${error}`);
|
|
554
|
-
throw error;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
this.sdk.logger.debug(`Processed run account ${runAccount.address.toString()}`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { BaseProgram } from './BaseProgram.js';
|
|
2
|
-
import { Address, Account, ReadonlyUint8Array, KeyPairSigner } from 'gill';
|
|
3
|
-
import { NosanaClient } from '../index.js';
|
|
4
|
-
import * as programClient from '../generated_clients/merkle_distributor/index.js';
|
|
5
|
-
import { ConvertTypesForDb } from '../utils/index.js';
|
|
6
|
-
/**
|
|
7
|
-
* Claim target enum for merkle distributor.
|
|
8
|
-
* Determines which address receives the claimed tokens.
|
|
9
|
-
*/
|
|
10
|
-
export declare enum ClaimTarget {
|
|
11
|
-
YES = "YES",
|
|
12
|
-
NO = "NO"
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Allowed addresses for receiving claimed tokens from merkle distributor.
|
|
16
|
-
* The `to` account must be the ATA of one of these addresses.
|
|
17
|
-
*/
|
|
18
|
-
export declare const ALLOWED_RECEIVE_ADDRESSES: {
|
|
19
|
-
readonly YES: Address<"YessuvqUauj9yW4B3eERcyRLWmQtWpFc2ERKmaedmCE">;
|
|
20
|
-
readonly NO: Address<"NopXntmRdXhYNkoZaNTMUMShJ3aVG5RvwpiyPdd4bMh">;
|
|
21
|
-
};
|
|
22
|
-
export type MerkleDistributor = ConvertTypesForDb<programClient.MerkleDistributorArgs> & {
|
|
23
|
-
address: Address;
|
|
24
|
-
};
|
|
25
|
-
export type ClaimStatus = ConvertTypesForDb<programClient.ClaimStatusArgs> & {
|
|
26
|
-
address: Address;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Error thrown when a claim status account is not found
|
|
30
|
-
*/
|
|
31
|
-
export declare class ClaimStatusNotFoundError extends Error {
|
|
32
|
-
constructor(address: Address);
|
|
33
|
-
}
|
|
34
|
-
export declare class MerkleDistributorProgram extends BaseProgram {
|
|
35
|
-
readonly client: typeof programClient;
|
|
36
|
-
constructor(sdk: NosanaClient);
|
|
37
|
-
protected getProgramId(): Address;
|
|
38
|
-
/**
|
|
39
|
-
* Derive the ClaimStatus PDA address for a given distributor and optional claimant.
|
|
40
|
-
* If claimant is not provided, uses the wallet's address.
|
|
41
|
-
*
|
|
42
|
-
* @param distributor The address of the merkle distributor
|
|
43
|
-
* @param claimant Optional claimant address. If not provided, uses the wallet's address.
|
|
44
|
-
* @returns The ClaimStatus PDA address
|
|
45
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
46
|
-
*/
|
|
47
|
-
getClaimStatusPda(distributor: Address, claimant?: Address): Promise<Address>;
|
|
48
|
-
/**
|
|
49
|
-
* Fetch a merkle distributor account by address
|
|
50
|
-
*/
|
|
51
|
-
get(addr: Address): Promise<MerkleDistributor>;
|
|
52
|
-
/**
|
|
53
|
-
* Fetch all merkle distributor accounts
|
|
54
|
-
*/
|
|
55
|
-
all(): Promise<MerkleDistributor[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Fetch a claim status account by address
|
|
58
|
-
*/
|
|
59
|
-
getClaimStatus(addr: Address): Promise<ClaimStatus>;
|
|
60
|
-
/**
|
|
61
|
-
* Fetch claim status for a specific distributor and optional claimant.
|
|
62
|
-
* Derives the ClaimStatus PDA using the claimant address (or wallet's address if not provided) and the distributor address.
|
|
63
|
-
*
|
|
64
|
-
* @param distributor The address of the merkle distributor
|
|
65
|
-
* @param claimant Optional claimant address. If not provided, uses the wallet's address.
|
|
66
|
-
* @returns The claim status if it exists, null otherwise
|
|
67
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
68
|
-
*/
|
|
69
|
-
getClaimStatusForDistributor(distributor: Address, claimant?: Address): Promise<ClaimStatus | null>;
|
|
70
|
-
/**
|
|
71
|
-
* Fetch all claim status accounts
|
|
72
|
-
* TODO: add filter for claimant and distributor
|
|
73
|
-
*/
|
|
74
|
-
allClaimStatus(): Promise<ClaimStatus[]>;
|
|
75
|
-
/**
|
|
76
|
-
* Transform merkle distributor account to include address and convert BigInt to numbers
|
|
77
|
-
*/
|
|
78
|
-
transformMerkleDistributorAccount(distributorAccount: Account<programClient.MerkleDistributor>): MerkleDistributor;
|
|
79
|
-
/**
|
|
80
|
-
* Transform claim status account to include address and convert BigInt to numbers
|
|
81
|
-
*/
|
|
82
|
-
transformClaimStatusAccount(claimStatusAccount: Account<programClient.ClaimStatus>): ClaimStatus;
|
|
83
|
-
/**
|
|
84
|
-
* Claim tokens from a merkle distributor.
|
|
85
|
-
* This function creates a new ClaimStatus account and claims the tokens in a single instruction.
|
|
86
|
-
*
|
|
87
|
-
* @param params Parameters for claiming tokens
|
|
88
|
-
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
89
|
-
* @returns The newClaim instruction
|
|
90
|
-
* @throws NosanaError if tokens have already been claimed
|
|
91
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
92
|
-
*/
|
|
93
|
-
claim(params: {
|
|
94
|
-
distributor: Address;
|
|
95
|
-
amountUnlocked: number | bigint;
|
|
96
|
-
amountLocked: number | bigint;
|
|
97
|
-
proof: Array<ReadonlyUint8Array>;
|
|
98
|
-
target: ClaimTarget;
|
|
99
|
-
claimant?: KeyPairSigner;
|
|
100
|
-
}): Promise<ReturnType<typeof programClient.getNewClaimInstruction>>;
|
|
101
|
-
/**
|
|
102
|
-
* Clawback tokens from a merkle distributor.
|
|
103
|
-
* This function creates a clawback instruction to transfer tokens from the distributor's token vault to the clawback receiver.
|
|
104
|
-
*
|
|
105
|
-
* @param params Parameters for clawback
|
|
106
|
-
* @param params.distributor The address of the merkle distributor
|
|
107
|
-
* @param params.claimant Optional claimant signer. If not provided, uses the wallet.
|
|
108
|
-
* @returns The clawback instruction
|
|
109
|
-
* @throws Error if wallet is not set and claimant is not provided
|
|
110
|
-
*/
|
|
111
|
-
clawback(params: {
|
|
112
|
-
distributor: Address;
|
|
113
|
-
claimant?: KeyPairSigner;
|
|
114
|
-
}): Promise<ReturnType<typeof programClient.getClawbackInstruction>>;
|
|
115
|
-
}
|