fbonds-core
Version:
Banx protocol sdk
378 lines (377 loc) • 15.8 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.getUnstakedSolAresteaVaulBalance = exports.createATAIdimpotentInstruction = exports.getBurnLrtsInstructions = exports.createUnstakeSolayerInstructionInstruction = exports.createSolayerUnrestakeInstruction = exports.createLrtsUnstakeInstructionParams = exports.getMintLrtsInstructions = exports.createLrtsSolDepositInstruction = exports.createSolayerRestakeInstruction = exports.createStakeSolToSolayerInstruction = exports.SSOL_TOKEN_ACCOUNT_POOL_VAULT = exports.AVS_PRORGAM = exports.AVS_TOKEN_VAULT = exports.AVS_TOKEN_MINT = exports.AVS = exports.AVS_POOL_TOKEN_VAULT = exports.WITHDRAW_AUTHORITHY_SOLAYER_POOL = exports.MANAGER_FEE_SOLAYER_POOL = exports.RESERVE_STAKE_SOLAYER_POOL = exports.STAKE_SOLAYER_POOL = void 0;
const common_1 = require("../../../common");
const constants_1 = require("../../constants");
const anchor_1 = require("@coral-xyz/anchor");
const spl_stake_pool_1 = require("@solana/spl-stake-pool");
const spl_token_1 = require("@solana/spl-token");
exports.STAKE_SOLAYER_POOL = new anchor_1.web3.PublicKey('po1osKDWYF9oiVEGmzKA4eTs8eMveFRMox3bUKazGN2');
exports.RESERVE_STAKE_SOLAYER_POOL = new anchor_1.web3.PublicKey('Brh9rB6npnjM1vDXyCXtzkXVGRnsh6KHqmBz26tVACg9');
exports.MANAGER_FEE_SOLAYER_POOL = new anchor_1.web3.PublicKey('ARs3HTD79nsaUdDKqfGhgbNMVJkXVdRs2EpHAm4LNEcq');
exports.WITHDRAW_AUTHORITHY_SOLAYER_POOL = new anchor_1.web3.PublicKey('H5rmot8ejBUWzMPt6E44h27xj5obbSz3jVuK4AsJpHmv');
exports.AVS_POOL_TOKEN_VAULT = new anchor_1.web3.PublicKey('wYPqKV6XuRBSBU1zYiYB1ZTPhkR8PsDRz5kKgmSyum1');
exports.AVS = new anchor_1.web3.PublicKey("HBkJwH6rjUUBK1wNhBuYgo9Wnk1iCx2phduyxWCQj6uk");
exports.AVS_TOKEN_MINT = new anchor_1.web3.PublicKey("sonickAJFiVLcYXx25X9vpF293udaWqDMUCiGtk7dg2");
exports.AVS_TOKEN_VAULT = new anchor_1.web3.PublicKey("Bc7hj6aFhBRihZ8dYp8qXWbuDBXYMya4dzFGmHezLnB7");
exports.AVS_PRORGAM = new anchor_1.web3.PublicKey("endoLNCKTqDn8gSVnN2hDdpgACUPWHZTwoYnnMybpAT");
exports.SSOL_TOKEN_ACCOUNT_POOL_VAULT = new anchor_1.web3.PublicKey("CivRStujQGKVqwpiJouqEYpt84Ge4XW7GMFRBA7d3szZ");
const createStakeSolToSolayerInstruction = ({ solAmount, signer, }) => {
const lpSolayerATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.LP_SOLAYER_MINT);
return spl_stake_pool_1.StakePoolInstruction.depositSol({
stakePool: exports.STAKE_SOLAYER_POOL,
reserveStake: exports.RESERVE_STAKE_SOLAYER_POOL,
fundingAccount: signer,
destinationPoolAccount: lpSolayerATA,
referralPoolAccount: lpSolayerATA,
managerFeeAccount: exports.MANAGER_FEE_SOLAYER_POOL,
poolMint: constants_1.LP_SOLAYER_MINT,
lamports: solAmount.toNumber(),
withdrawAuthority: exports.WITHDRAW_AUTHORITHY_SOLAYER_POOL,
});
};
exports.createStakeSolToSolayerInstruction = createStakeSolToSolayerInstruction;
const createSolayerRestakeInstruction = ({ signer, sSolAmount, }) => {
const lpSolayerATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.LP_SOLAYER_MINT);
const sSolATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.SSOL_MINT);
const keys = [
{
pubkey: signer,
isSigner: true,
isWritable: true,
},
{
pubkey: constants_1.LP_SOLAYER_MINT,
isSigner: false,
isWritable: false,
},
{
pubkey: lpSolayerATA,
isSigner: false,
isWritable: true,
},
{
pubkey: sSolATA,
isSigner: false,
isWritable: true,
},
{
pubkey: constants_1.SSOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: new anchor_1.web3.PublicKey('4eimDGZonDS41b7YEEtxuX1JbSRLanH2BLJfG5sqbCsB'),
isSigner: false,
isWritable: true,
},
{
pubkey: new anchor_1.web3.PublicKey('3sk58CzpitB9jsnVzZWwqeCn2zcXVherhALBh88Uw9GQ'),
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: anchor_1.web3.SystemProgram.programId,
isSigner: false,
isWritable: false,
},
];
const descriminator = Buffer.from([0x61, 0xa1, 0xf1, 0xa7, 0x06, 0x20, 0xd5, 0x35]);
return new anchor_1.web3.TransactionInstruction({
keys,
programId: new anchor_1.web3.PublicKey('sSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn'),
data: Buffer.concat([descriminator, sSolAmount.toArrayLike(Buffer, 'le', 8)]),
});
};
exports.createSolayerRestakeInstruction = createSolayerRestakeInstruction;
const createLrtsSolDepositInstruction = ({ signer, sSolAmount, }) => {
const lrtsATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.LRTS_SOL_MINT);
const sSolATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.SSOL_MINT);
const keys = [
{
pubkey: signer,
isSigner: true,
isWritable: true,
},
{
pubkey: constants_1.SSOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: sSolATA,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.SSOL_TOKEN_ACCOUNT_POOL_VAULT,
isSigner: false,
isWritable: true,
},
{
pubkey: constants_1.LRTS_SOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: lrtsATA,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.AVS_POOL_TOKEN_VAULT,
isSigner: false,
isWritable: true,
},
{
pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: anchor_1.web3.SystemProgram.programId,
isSigner: false,
isWritable: false,
},
];
const descriminator = Buffer.from([0xf2, 0x23, 0xc6, 0x89, 0x52, 0xe1, 0xf2, 0xb6]);
return new anchor_1.web3.TransactionInstruction({
keys,
programId: new anchor_1.web3.PublicKey('Lrt1aE9sgjyi6B9QEdcuzHC8GhU32N3PM9RSKLBeD7b'),
data: Buffer.concat([descriminator, sSolAmount.toArrayLike(Buffer, 'le', 8)]),
});
};
exports.createLrtsSolDepositInstruction = createLrtsSolDepositInstruction;
const getMintLrtsInstructions = ({ solAmount, conversionRate, walletPublicKey, }) => {
const lrtsATAIxn = (0, exports.createATAIdimpotentInstruction)(walletPublicKey, constants_1.LRTS_SOL_MINT);
const lpSolayerATAIxn = (0, exports.createATAIdimpotentInstruction)(walletPublicKey, constants_1.LP_SOLAYER_MINT);
const sSolATAIxn = (0, exports.createATAIdimpotentInstruction)(walletPublicKey, constants_1.SSOL_MINT);
const stakePoolIxn = (0, exports.createStakeSolToSolayerInstruction)({
signer: walletPublicKey,
solAmount,
});
const sSolAmount = new anchor_1.BN(Math.floor(solAmount.toNumber() * conversionRate));
const solayerRestakeIxn = (0, exports.createSolayerRestakeInstruction)({
signer: walletPublicKey,
sSolAmount,
});
const lrstDepositInstructionIxn = (0, exports.createLrtsSolDepositInstruction)({
signer: walletPublicKey,
sSolAmount,
});
return [lrtsATAIxn, lpSolayerATAIxn, sSolATAIxn, stakePoolIxn, solayerRestakeIxn, lrstDepositInstructionIxn];
};
exports.getMintLrtsInstructions = getMintLrtsInstructions;
const createLrtsUnstakeInstructionParams = ({ signer, lrtsAmount, undelegateStake, }) => {
const lrtsATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.LRTS_SOL_MINT);
const sSolATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.SSOL_MINT);
const withdrawKeys = [
{
pubkey: signer,
isSigner: true,
isWritable: true,
},
{
pubkey: constants_1.SSOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: sSolATA,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.SSOL_TOKEN_ACCOUNT_POOL_VAULT,
isSigner: false,
isWritable: true,
},
{
pubkey: constants_1.LRTS_SOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: lrtsATA,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.AVS_POOL_TOKEN_VAULT,
isSigner: false,
isWritable: true,
},
];
const programKeys = [
{
pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: anchor_1.web3.SystemProgram.programId,
isSigner: false,
isWritable: false,
},
];
const poolAvsTokenVault = (0, common_1.findAssociatedTokenAddresSync)(exports.AVS_POOL_TOKEN_VAULT, // wYPqKV6XuRBSBU1zYiYB1ZTPhkR8PsDRz5kKgmSyum1
exports.AVS_TOKEN_MINT);
const accountKeysUndelegate = [
{
pubkey: exports.AVS,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.AVS_TOKEN_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.AVS_TOKEN_VAULT,
isSigner: false,
isWritable: true,
},
{
pubkey: poolAvsTokenVault,
isSigner: false,
isWritable: true,
},
{
pubkey: exports.AVS_PRORGAM,
isSigner: false,
isWritable: false,
},
];
const keys = undelegateStake ? [...withdrawKeys, ...accountKeysUndelegate, ...programKeys,] : [...withdrawKeys, ...programKeys,];
const descriminator = undelegateStake ? Buffer.from([0xcb, 0x9f, 0xb7, 0xbe, 0x90, 0x1d, 0x72, 0xe6]) : Buffer.from([0xb7, 0x12, 0x46, 0x9c, 0x94, 0x6d, 0xa1, 0x22]);
return new anchor_1.web3.TransactionInstruction({
keys,
programId: new anchor_1.web3.PublicKey('Lrt1aE9sgjyi6B9QEdcuzHC8GhU32N3PM9RSKLBeD7b'),
data: Buffer.concat([descriminator, lrtsAmount.toArrayLike(Buffer, 'le', 8)]),
});
};
exports.createLrtsUnstakeInstructionParams = createLrtsUnstakeInstructionParams;
const createSolayerUnrestakeInstruction = ({ signer, unrestakeAmount, }) => {
const lpSolayerATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.LP_SOLAYER_MINT);
const sSolATA = (0, common_1.findAssociatedTokenAddresSync)(signer, constants_1.SSOL_MINT);
const keys = [
{
pubkey: signer,
isSigner: true,
isWritable: true,
},
{
pubkey: constants_1.LP_SOLAYER_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: lpSolayerATA,
isSigner: false,
isWritable: true,
},
{
pubkey: sSolATA,
isSigner: false,
isWritable: true,
},
{
pubkey: constants_1.SSOL_MINT,
isSigner: false,
isWritable: true,
},
{
pubkey: new anchor_1.web3.PublicKey('4eimDGZonDS41b7YEEtxuX1JbSRLanH2BLJfG5sqbCsB'),
isSigner: false,
isWritable: true,
},
{
pubkey: new anchor_1.web3.PublicKey('3sk58CzpitB9jsnVzZWwqeCn2zcXVherhALBh88Uw9GQ'),
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: anchor_1.web3.SystemProgram.programId,
isSigner: false,
isWritable: false,
},
];
const descriminator = Buffer.from([0x0a, 0xb1, 0xa1, 0xee, 0xfa, 0x25, 0x78, 0x18]);
return new anchor_1.web3.TransactionInstruction({
keys,
programId: new anchor_1.web3.PublicKey('sSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn'),
data: Buffer.concat([descriminator, unrestakeAmount.toArrayLike(Buffer, 'le', 8)]),
});
};
exports.createSolayerUnrestakeInstruction = createSolayerUnrestakeInstruction;
const createUnstakeSolayerInstructionInstruction = (_a) => __awaiter(void 0, [_a], void 0, function* ({ unstakeAmount, signer, connection, }) {
const instructions = [];
const withdrawStakeIxns = yield (0, spl_stake_pool_1.withdrawStake)(connection, exports.STAKE_SOLAYER_POOL, signer, unstakeAmount);
instructions.push(...withdrawStakeIxns.instructions);
return {
instructions,
signers: withdrawStakeIxns.signers,
};
});
exports.createUnstakeSolayerInstructionInstruction = createUnstakeSolayerInstructionInstruction;
const getBurnLrtsInstructions = ({ lrtsAmount, walletPublicKey, undelegateStake }) => {
const lpSolayerATAIxn = (0, exports.createATAIdimpotentInstruction)(walletPublicKey, constants_1.LP_SOLAYER_MINT);
const sSolATAIxn = (0, exports.createATAIdimpotentInstruction)(walletPublicKey, constants_1.SSOL_MINT);
const unstakeLrtsIxns = (0, exports.createLrtsUnstakeInstructionParams)({
lrtsAmount,
signer: walletPublicKey,
undelegateStake
});
return [lpSolayerATAIxn, sSolATAIxn, unstakeLrtsIxns];
};
exports.getBurnLrtsInstructions = getBurnLrtsInstructions;
const createATAIdimpotentInstruction = (walletPublicKey, tokenMint) => {
const ATA = (0, common_1.findAssociatedTokenAddresSync)(walletPublicKey, tokenMint);
return (0, common_1.createAssociatedTokenAccountInstructionIdimpotent)(ATA, walletPublicKey, walletPublicKey, tokenMint)[0];
};
exports.createATAIdimpotentInstruction = createATAIdimpotentInstruction;
const getUnstakedSolAresteaVaulBalance = (connection) => __awaiter(void 0, void 0, void 0, function* () {
const balance = yield connection.getTokenAccountBalance(exports.SSOL_TOKEN_ACCOUNT_POOL_VAULT);
return new anchor_1.BN(balance.value.amount);
});
exports.getUnstakedSolAresteaVaulBalance = getUnstakedSolAresteaVaulBalance;