UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

81 lines (80 loc) 4.24 kB
"use strict"; 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.claimGemFarm = void 0; const anchor_1 = require("@project-serum/anchor"); const helpers_1 = require("../../helpers"); const common_1 = require("../../../common"); const claimGemFarm = ({ programId, connection, user, gemFarm, farm, nftMint, loan, isDegod, rewardAMint, rewardBMint, sendTxn, }) => __awaiter(void 0, void 0, void 0, function* () { const encoder = new TextEncoder(); const program = (0, helpers_1.returnAnchorProgram)(programId, connection); const [identity, bumpAuth] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('degod_stake'), nftMint.toBuffer(), loan.toBuffer()], programId); const [farmer, bumpFarmer] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('farmer'), farm.toBuffer(), identity.toBuffer()], gemFarm); const [farmAuthority, bumpAuthAuthority] = yield anchor_1.web3.PublicKey.findProgramAddress([farm.toBuffer()], gemFarm); const [lendingStake] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('stake_acc'), loan.toBuffer()], programId); const [rewardAPot, bumpPotA] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('reward_pot'), farm.toBuffer(), rewardAMint.toBuffer()], gemFarm); const [rewardBPot, bumpPotB] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('reward_pot'), farm.toBuffer(), rewardBMint.toBuffer()], gemFarm); const rewardADestinationIdentity = yield (0, common_1.findAssociatedTokenAddress)(identity, rewardAMint); const rewardBDestinationIdentity = yield (0, common_1.findAssociatedTokenAddress)(identity, rewardBMint); const rewardADestination = yield (0, common_1.findAssociatedTokenAddress)(user, rewardAMint); const rewardBDestination = yield (0, common_1.findAssociatedTokenAddress)(user, rewardBMint); const claim = program.instruction.claimGemFarmStaking({ bumpAuth, bumpFarmer, bumpAuthAuthority, bumpPotA, bumpPotB, isDegod }, { accounts: { user, gemFarm, farm, farmAuthority, farmer, loan, identity, gemMint: nftMint, rewardADestinationIdentity, rewardAMint, rewardAPot, rewardBDestinationIdentity, rewardBMint, rewardBPot, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, systemProgram: anchor_1.web3.SystemProgram.programId, tokenProgram: anchor_1.utils.token.TOKEN_PROGRAM_ID, associatedTokenProgram: anchor_1.utils.token.ASSOCIATED_PROGRAM_ID, } }); const claimed = program.instruction.getClaimedGemFarmStaking(bumpAuth, { accounts: { user, loan, identity, gemMint: nftMint, rewardADestinationIdentity, rewardADestination, rewardAMint, lendingStake, rewardBDestinationIdentity, rewardBDestination, rewardBMint, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, systemProgram: anchor_1.web3.SystemProgram.programId, tokenProgram: anchor_1.utils.token.TOKEN_PROGRAM_ID, associatedTokenProgram: anchor_1.utils.token.ASSOCIATED_PROGRAM_ID, } }); const transaction = new anchor_1.web3.Transaction().add(claim).add(claimed); yield sendTxn(transaction); }); exports.claimGemFarm = claimGemFarm;