@nosana/kit
Version:
Nosana KIT
38 lines • 1.53 kB
JavaScript
export async function end({ job }, { config, deps, client, get, getRuns, getRequiredWallet, getStaticAccounts, getNosATA, }) {
try {
const wallet = getRequiredWallet();
// Get Required accounts
const [{ market, payer }, [run], { jobsProgram }] = await Promise.all([
get(job, false),
getRuns({ job }),
getStaticAccounts(),
]);
if (!run) {
throw new Error('No job run account found for the specified job');
}
// Get associated token addresses
const [payerATA, nodeATA] = await Promise.all([
getNosATA(payer), // ATA for the job's payer (for deposit)
getNosATA(run.node), // ATA for the node (for user)
]);
const vault = await deps.solana.pda([market, config.nosTokenAddress], jobsProgram);
return client.getEndInstruction({
job,
market: market,
run: run.address,
deposit: payerATA, // ATA of the job payer
user: nodeATA, // ATA of the node (from run account)
vault: vault,
payer: run.payer, // Use payer from the run account
authority: wallet,
}, {
programAddress: jobsProgram,
});
}
catch (err) {
const errorMessage = `Failed to create end instruction: ${err instanceof Error ? err.message : String(err)}`;
deps.logger.error(errorMessage);
throw new Error(errorMessage);
}
}
//# sourceMappingURL=end.js.map