@frakt-protocol/frakt-sdk
Version:
Frakt SDK for interacting with frakt.xyz protocols
44 lines (43 loc) • 2.9 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.harvestInFusion = void 0;
const anchor_1 = require("@project-serum/anchor");
const spl_token_1 = require("@solana/spl-token");
const common_1 = require("../../common");
const harvestInFusion = (programId, provider, userPublicKey, mintToStake, mintToHarvest) => __awaiter(void 0, void 0, void 0, function* () {
const encoder = new TextEncoder();
const program = yield (0, common_1.returnAnchorMultiRewardStaking)(programId, provider);
const [vaultOwnerPda, bump] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("vaultownerpda"), programId.toBuffer()], program.programId);
const userToHarvest = yield (0, common_1.findAssociatedTokenAddress)(userPublicKey, mintToHarvest);
const vaultTokenAccountOutput = yield (0, common_1.findAssociatedTokenAddress)(vaultOwnerPda, mintToHarvest);
const [mainRouter, bumpRouter] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("mainRouter"), mintToStake.toBuffer(), mintToHarvest.toBuffer()], program.programId);
const [configOutput, bumpConfigOutput] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("mainConfigAccountOutput"), mintToHarvest.toBuffer(), mainRouter.toBuffer()], program.programId);
const [stakeAccount, bumpStake] = yield anchor_1.web3.PublicKey.findProgramAddress([userPublicKey.toBuffer(), mainRouter.toBuffer()], program.programId);
return program.instruction.harvestMainReward(bump, bumpConfigOutput, bumpRouter, bumpStake, {
accounts: {
initializer: userPublicKey,
userTokenAccountOutput: userToHarvest,
tokenMintInput: mintToStake,
tokenMintOutput: mintToHarvest,
vaultOwnerPda,
vaultTokenAccountOutput,
stakeAccount: stakeAccount,
mainRouter,
configOutput,
rent: anchor_1.web3.SYSVAR_RENT_PUBKEY,
systemProgram: anchor_1.web3.SystemProgram.programId,
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
},
});
});
exports.harvestInFusion = harvestInFusion;