@frakt-protocol/frakt-sdk
Version:
Frakt SDK for interacting with frakt.xyz protocols
94 lines (93 loc) • 4.79 kB
JavaScript
"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.unstakeCardinalIx = void 0;
const anchor_1 = require("@project-serum/anchor");
const constants_1 = require("../../constants");
const helpers_1 = require("../../helpers");
const common_1 = require("../../../common");
const unstakeCardinalIx = ({ programId, connection, user, payer, cardinalRewardsCenter, nftMint, stakePool, loan, rewardMint, unstakeRewardsPaymentInfo, paymentPubkey1, paymentPubkey2, }) => __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_cardinal'), user.toBuffer()], programId);
const [lendingStake] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('stake_acc'), loan.toBuffer()], programId);
const [stakeEntry] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('stake-entry'), stakePool.toBuffer(), nftMint.toBuffer(), anchor_1.web3.PublicKey.default.toBuffer()], cardinalRewardsCenter);
const [identityEscrow] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('escrow'), identity.toBuffer()], cardinalRewardsCenter);
const [communityPoolsAuthority, bumpPoolsAuth] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('nftlendingv2'), programId.toBuffer()], program.programId);
const [nftMintMetadata] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('metadata'), constants_1.METADATA_PROGRAM_PUBKEY.toBuffer(), nftMint.toBuffer()], constants_1.METADATA_PROGRAM_PUBKEY);
const payerTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(payer, rewardMint);
const reward1TokenAccount = yield (0, common_1.findAssociatedTokenAddress)(paymentPubkey1, rewardMint);
const reward2TokenAccount = yield (0, common_1.findAssociatedTokenAddress)(paymentPubkey2, rewardMint);
const nftUserTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(payer, nftMint);
const identityStakeMintTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(identity, nftMint);
const editionId = (0, helpers_1.getMetaplexEditionPda)(nftMint);
const additionalComputeBudgetInstructionIx = anchor_1.web3.ComputeBudgetProgram.setComputeUnitLimit({
units: 400000,
});
const unstakeIx = yield program.methods
.unstakeCardinal()
.accountsStrict({
user,
lendingStake,
loan,
stakeMint: nftMint,
nftUserTokenAccount,
identity,
identityStakeMintTokenAccount,
payer,
cardinalStakeCenter: cardinalRewardsCenter,
stakeEntry,
stakePool,
identityEscrow,
communityPoolsAuthority,
editionInfo: editionId,
metadataProgram: constants_1.METADATA_PROGRAM_PUBKEY,
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,
})
.remainingAccounts([
{
pubkey: unstakeRewardsPaymentInfo,
isSigner: false,
isWritable: true,
},
{
pubkey: payer,
isSigner: true,
isWritable: true,
},
{
pubkey: anchor_1.utils.token.TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: payerTokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: reward1TokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: reward2TokenAccount,
isSigner: false,
isWritable: true,
},
])
.instruction();
return { additionalComputeBudgetInstructionIx, unstakeIx };
});
exports.unstakeCardinalIx = unstakeCardinalIx;