UNPKG

@frakters/nft-lending-v2

Version:

Client library for interacting with nft lenging solana program

535 lines (534 loc) 28.9 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.USER_STAKE_INFO_ACCOUNT_LAYOUT_V5 = exports.USER_STAKE_INFO_ACCOUNT_LAYOUT_V4 = exports.USER_STAKE_INFO_ACCOUNT_LAYOUT = exports.STAKE_INFO_LAYOUT_V4 = exports.STAKE_INFO_LAYOUT = exports.createAssociatedLedgerAccountInstructionV5 = exports.emergencyWithdrawInstructionV4 = exports.withdrawInstructionV5 = exports.withdrawInstructionV4 = exports.withdrawInstruction = exports.depositInstructionV5 = exports.depositInstructionV4 = exports.depositInstruction = exports.emergencyWithdrawV4 = exports.withdrawV5 = exports.withdrawV4 = exports.withdraw = exports.depositV5 = exports.depositV4 = exports.deposit = void 0; const borsh_1 = require("@project-serum/borsh"); const web3_js_1 = require("@solana/web3.js"); // @ts-ignore const buffer_layout_1 = require("buffer-layout"); const ids_1 = require("./ids"); const safe_math_1 = require("./safe-math"); const web3_1 = require("./web3"); const layouts_1 = require("./layouts"); // deposit function deposit(connection, wallet, farmInfo, lpAccount, rewardAccount, infoAccount, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); // if no userinfo account, create new one const programId = new web3_js_1.PublicKey(farmInfo.programId); const userInfoAccount = yield web3_1.createProgramAccountIfNotExist(connection, infoAccount, owner, programId, null, exports.USER_STAKE_INFO_ACCOUNT_LAYOUT, transaction, signers); const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(depositInstruction(programId, new web3_js_1.PublicKey(farmInfo.poolId), new web3_js_1.PublicKey(farmInfo.poolAuthority), userInfoAccount, wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.deposit = deposit; // depositV4 function depositV4(connection, wallet, farmInfo, lpAccount, rewardAccount, rewardAccountB, infoAccount, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccountB = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccountB, owner, // @ts-ignore farmInfo.rewardB.mintAddress, transaction, atas); // if no userinfo account, create new one const programId = new web3_js_1.PublicKey(farmInfo.programId); const userInfoAccount = yield web3_1.createProgramAccountIfNotExist(connection, infoAccount, owner, programId, null, exports.USER_STAKE_INFO_ACCOUNT_LAYOUT_V4, transaction, signers); const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(depositInstructionV4(programId, new web3_js_1.PublicKey(farmInfo.poolId), new web3_js_1.PublicKey(farmInfo.poolAuthority), userInfoAccount, wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), userRewardTokenAccountB, // @ts-ignore new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccountB), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.depositV4 = depositV4; // depositV5 function depositV5(connection, wallet, farmInfo, lpAccount, rewardAccount, rewardAccountB, infoAccount, auxiliaryInfoAccounts, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccountB = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccountB, owner, // @ts-ignore farmInfo.rewardB.mintAddress, transaction, atas); const poolId = new web3_js_1.PublicKey(farmInfo.poolId); const programId = new web3_js_1.PublicKey(farmInfo.programId); const pda = yield web3_1.findAssociatedStakeInfoAddress(poolId, wallet.publicKey, programId); // if no associated userinfo account, create new one if (pda.toBase58() !== infoAccount) { transaction.add(createAssociatedLedgerAccountInstructionV5(programId, poolId, pda, wallet.publicKey)); } const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(depositInstructionV5(programId, poolId, new web3_js_1.PublicKey(farmInfo.poolAuthority), pda, auxiliaryInfoAccounts.map((k) => new web3_js_1.PublicKey(k)), wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), userRewardTokenAccountB, // @ts-ignore new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccountB), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.depositV5 = depositV5; // withdraw function withdraw(connection, wallet, farmInfo, lpAccount, rewardAccount, infoAccount, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!infoAccount) throw new Error('Miss account infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); const programId = new web3_js_1.PublicKey(farmInfo.programId); const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(withdrawInstruction(programId, new web3_js_1.PublicKey(farmInfo.poolId), new web3_js_1.PublicKey(farmInfo.poolAuthority), new web3_js_1.PublicKey(infoAccount), wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.withdraw = withdraw; // withdrawV4 function withdrawV4(connection, wallet, farmInfo, lpAccount, rewardAccount, rewardAccountB, infoAccount, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!infoAccount) throw new Error('Miss account infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccountB = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccountB, owner, // @ts-ignore farmInfo.rewardB.mintAddress, transaction, atas); const programId = new web3_js_1.PublicKey(farmInfo.programId); const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(withdrawInstructionV4(programId, new web3_js_1.PublicKey(farmInfo.poolId), new web3_js_1.PublicKey(farmInfo.poolAuthority), new web3_js_1.PublicKey(infoAccount), wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), userRewardTokenAccountB, // @ts-ignore new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccountB), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.withdrawV4 = withdrawV4; // withdrawV5 function withdrawV5(connection, wallet, farmInfo, lpAccount, rewardAccount, rewardAccountB, infoAccount, auxiliaryInfoAccounts, amount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!infoAccount) throw new Error('Miss account infomations'); if (!amount) throw new Error('Miss amount infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccount, owner, farmInfo.reward.mintAddress, transaction, atas); // if no account, create new one const userRewardTokenAccountB = yield web3_1.createAssociatedTokenAccountIfNotExist(rewardAccountB, owner, // @ts-ignore farmInfo.rewardB.mintAddress, transaction, atas); const poolId = new web3_js_1.PublicKey(farmInfo.poolId); const programId = new web3_js_1.PublicKey(farmInfo.programId); const pda = yield web3_1.findAssociatedStakeInfoAddress(poolId, wallet.publicKey, programId); // if no associated userinfo account, create new one if (pda.toBase58() !== infoAccount) { transaction.add(createAssociatedLedgerAccountInstructionV5(programId, poolId, pda, wallet.publicKey)); } const value = layouts_1.getBigNumber(new safe_math_1.TokenAmount(amount, farmInfo.lp.decimals, false).wei); transaction.add(withdrawInstructionV5(programId, poolId, new web3_js_1.PublicKey(farmInfo.poolAuthority), pda, auxiliaryInfoAccounts.map((k) => new web3_js_1.PublicKey(k)), wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount), userRewardTokenAccount, new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccount), userRewardTokenAccountB, // @ts-ignore new web3_js_1.PublicKey(farmInfo.poolRewardTokenAccountB), value)); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.withdrawV5 = withdrawV5; function emergencyWithdrawV4(connection, wallet, farmInfo, lpAccount, infoAccount) { return __awaiter(this, void 0, void 0, function* () { if (!connection || !wallet) throw new Error('Miss connection'); if (!farmInfo) throw new Error('Miss pool infomations'); if (!infoAccount) throw new Error('Miss account infomations'); const transaction = new web3_js_1.Transaction(); const signers = []; const owner = wallet.publicKey; const atas = []; const userLpAccount = yield web3_1.createAssociatedTokenAccountIfNotExist(lpAccount, owner, farmInfo.lp.mintAddress, transaction, atas); const programId = new web3_js_1.PublicKey(farmInfo.programId); transaction.add(emergencyWithdrawInstructionV4(programId, new web3_js_1.PublicKey(farmInfo.poolId), new web3_js_1.PublicKey(farmInfo.poolAuthority), new web3_js_1.PublicKey(infoAccount), wallet.publicKey, userLpAccount, new web3_js_1.PublicKey(farmInfo.poolLpTokenAccount))); return yield web3_1.sendTransaction(connection, wallet, transaction, signers); }); } exports.emergencyWithdrawV4 = emergencyWithdrawV4; function depositInstruction(programId, // staking pool poolId, poolAuthority, // user userInfoAccount, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 1, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.depositInstruction = depositInstruction; function depositInstructionV4(programId, // staking pool poolId, poolAuthority, // user userInfoAccount, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, userRewardTokenAccountB, poolRewardTokenAccountB, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: userRewardTokenAccountB, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccountB, isSigner: false, isWritable: true }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 1, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.depositInstructionV4 = depositInstructionV4; function depositInstructionV5(programId, // staking pool poolId, poolAuthority, // user userAssociatedInfoAccount, userInfoAccounts, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, userRewardTokenAccountB, poolRewardTokenAccountB, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userAssociatedInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: userRewardTokenAccountB, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccountB, isSigner: false, isWritable: true }, ]; for (const userInfoAccount of userInfoAccounts) { keys.push({ pubkey: userInfoAccount, isSigner: false, isWritable: true }); } const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 11, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.depositInstructionV5 = depositInstructionV5; function withdrawInstruction(programId, // staking pool poolId, poolAuthority, // user userInfoAccount, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 2, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.withdrawInstruction = withdrawInstruction; function withdrawInstructionV4(programId, // staking pool poolId, poolAuthority, // user userInfoAccount, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, userRewardTokenAccountB, poolRewardTokenAccountB, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: userRewardTokenAccountB, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccountB, isSigner: false, isWritable: true }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 2, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.withdrawInstructionV4 = withdrawInstructionV4; function withdrawInstructionV5(programId, // staking pool poolId, poolAuthority, // user userAssociatedInfoAccount, userInfoAccounts, userOwner, userLpTokenAccount, poolLpTokenAccount, userRewardTokenAccount, poolRewardTokenAccount, userRewardTokenAccountB, poolRewardTokenAccountB, // tokenProgramId: PublicKey, amount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction'), buffer_layout_1.nu64('amount')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userAssociatedInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: userRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccount, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: userRewardTokenAccountB, isSigner: false, isWritable: true }, { pubkey: poolRewardTokenAccountB, isSigner: false, isWritable: true }, ]; for (const userInfoAccount of userInfoAccounts) { keys.push({ pubkey: userInfoAccount, isSigner: false, isWritable: true }); } const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 12, amount, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.withdrawInstructionV5 = withdrawInstructionV5; function emergencyWithdrawInstructionV4(programId, // staking pool poolId, poolAuthority, // user userInfoAccount, userOwner, userLpTokenAccount, poolLpTokenAccount) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: poolAuthority, isSigner: false, isWritable: false }, { pubkey: userInfoAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: userLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: poolLpTokenAccount, isSigner: false, isWritable: true }, { pubkey: ids_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 7, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.emergencyWithdrawInstructionV4 = emergencyWithdrawInstructionV4; function createAssociatedLedgerAccountInstructionV5(programId, // staking pool poolId, // user associatedLedgerAccount, userOwner) { const dataLayout = buffer_layout_1.struct([buffer_layout_1.u8('instruction')]); const keys = [ { pubkey: poolId, isSigner: false, isWritable: true }, { pubkey: associatedLedgerAccount, isSigner: false, isWritable: true }, { pubkey: userOwner, isSigner: true, isWritable: false }, { pubkey: ids_1.SYSTEM_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, ]; const data = Buffer.alloc(dataLayout.span); dataLayout.encode({ instruction: 10, }, data); return new web3_js_1.TransactionInstruction({ keys, programId, data, }); } exports.createAssociatedLedgerAccountInstructionV5 = createAssociatedLedgerAccountInstructionV5; exports.STAKE_INFO_LAYOUT = buffer_layout_1.struct([ borsh_1.u64('state'), borsh_1.u64('nonce'), borsh_1.publicKey('poolLpTokenAccount'), borsh_1.publicKey('poolRewardTokenAccount'), borsh_1.publicKey('owner'), borsh_1.publicKey('feeOwner'), borsh_1.u64('feeY'), borsh_1.u64('feeX'), borsh_1.u64('totalReward'), borsh_1.u128('rewardPerShareNet'), borsh_1.u64('lastBlock'), borsh_1.u64('rewardPerBlock'), ]); exports.STAKE_INFO_LAYOUT_V4 = buffer_layout_1.struct([ borsh_1.u64('state'), borsh_1.u64('nonce'), borsh_1.publicKey('poolLpTokenAccount'), borsh_1.publicKey('poolRewardTokenAccount'), borsh_1.u64('totalReward'), borsh_1.u128('perShare'), borsh_1.u64('perBlock'), buffer_layout_1.u8('option'), borsh_1.publicKey('poolRewardTokenAccountB'), buffer_layout_1.blob(7), borsh_1.u64('totalRewardB'), borsh_1.u128('perShareB'), borsh_1.u64('perBlockB'), borsh_1.u64('lastBlock'), borsh_1.publicKey('owner'), ]); exports.USER_STAKE_INFO_ACCOUNT_LAYOUT = buffer_layout_1.struct([ borsh_1.u64('state'), borsh_1.publicKey('poolId'), borsh_1.publicKey('stakerOwner'), borsh_1.u64('depositBalance'), borsh_1.u64('rewardDebt'), ]); exports.USER_STAKE_INFO_ACCOUNT_LAYOUT_V4 = buffer_layout_1.struct([ borsh_1.u64('state'), borsh_1.publicKey('poolId'), borsh_1.publicKey('stakerOwner'), borsh_1.u64('depositBalance'), borsh_1.u64('rewardDebt'), borsh_1.u64('rewardDebtB'), ]); exports.USER_STAKE_INFO_ACCOUNT_LAYOUT_V5 = buffer_layout_1.struct([ borsh_1.u64('state'), borsh_1.publicKey('poolId'), borsh_1.publicKey('stakerOwner'), borsh_1.u64('depositBalance'), borsh_1.u128('rewardDebt'), borsh_1.u128('rewardDebtB'), buffer_layout_1.seq(borsh_1.u64(), 17), ]);