goosefx-stake-rewards-sdk
Version:
A SDK for interfacing with the GooseFX stake rewards program
492 lines • 27.1 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GfxStakeRewards = void 0;
const constants_1 = require("../constants");
const web3_js_1 = require("@solana/web3.js");
const anchor_1 = require("@project-serum/anchor");
const spl_token_1 = require("@solana/spl-token");
const buffer_1 = require("buffer");
const types_1 = require("../types");
const goosefx_ssl_sdk_1 = require("goosefx-ssl-sdk");
const bn_js_1 = __importDefault(require("bn.js"));
;
class GfxStakeRewards {
constructor(connection, network, wallet) {
this.connection = connection;
this.network = network;
this.wallet = wallet;
this.program = this.newProgram();
this.swap = this.newSwap();
}
setConnection(conn, network, commitment) {
this.connection = conn;
this.network = network;
this.program = this.newProgram(commitment);
this.swap = this.newSwap();
}
setWallet(wallet, commitment) {
this.wallet = wallet;
this.program = this.newProgram(commitment);
this.swap = this.newSwap();
}
setNetwork(network, commitment) {
this.network = network;
this.program = this.newProgram(commitment);
this.swap = this.newSwap();
}
newProgram(commitment) {
return new anchor_1.Program(types_1.IDL, GfxStakeRewards.programId.toBase58(), new anchor_1.AnchorProvider(this.connection, this.wallet, commitment ?? { commitment: 'confirmed' }));
}
newSwap() {
return new goosefx_ssl_sdk_1.Swap(this.connection, constants_1.ADDRESSES[this.network].GFX_CONTROLLER, constants_1.ADDRESSES[this.network].SSL_PROGRAM_ID);
}
async initializeUserAccount(secondaryFunder, walletPublicKey) {
const currentWallet = (walletPublicKey ?? this.wallet.publicKey);
const userMetadata = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, currentWallet.toBuffer()], GfxStakeRewards.programId);
const usdcMint = constants_1.ADDRESSES[this.network].USDC_MINT;
const accounts = {
owner: currentWallet,
funder: secondaryFunder ?? currentWallet,
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
userMetadata: userMetadata[0],
systemProgram: web3_js_1.SystemProgram.programId,
usdcMint,
userRewardsHoldingAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(usdcMint, userMetadata[0], true)
};
return await this.program.methods
.initializeUserAccount()
.accounts(accounts)
.instruction();
}
async crank(mint) {
const usdcFeeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const sslIn = goosefx_ssl_sdk_1.SSL.findAddress(constants_1.ADDRESSES[this.network].GFX_CONTROLLER, mint);
const sslOut = goosefx_ssl_sdk_1.SSL.findAddress(constants_1.ADDRESSES[this.network].GFX_CONTROLLER, constants_1.ADDRESSES[this.network].USDC_MINT);
const pair = this.swap.getPairAddress(sslIn, sslOut);
const feeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const [liabilityVaultIn, swappedLiabilityVaultIn, liabilityVaultOut, swappedLiabilityVaultOut, userInAta, feeCollectorAta, usdcFeeVault,] = await Promise.all([
(0, spl_token_1.getAssociatedTokenAddress)(mint, sslIn, true),
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, sslIn, true),
(0, spl_token_1.getAssociatedTokenAddress)(mint, sslOut, true),
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, sslOut, true),
(0, spl_token_1.getAssociatedTokenAddress)(mint, feeSigner[0], true),
(0, spl_token_1.getAssociatedTokenAddress)(mint, new web3_js_1.PublicKey("GFXSwpZBSU9LF1gHRpRv2u967ACKKncFnfy3VKyQqwhp")),
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, feeSigner[0], true),
]);
return await this.program.methods
.crank(constants_1.CRANK_AMOUNT)
.accounts({
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
usdcFeeVault: usdcFeeVault,
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
usdcFeeSigner: usdcFeeSigner[0],
gfxSslProgram: constants_1.ADDRESSES[this.network].SSL_PROGRAM_ID,
controller: constants_1.ADDRESSES[this.network].GFX_CONTROLLER,
pair,
sslIn,
sslOut,
liabilityVaultIn,
swappedLiabilityVaultIn,
liabilityVaultOut,
swappedLiabilityVaultOut,
userInAta,
feeCollectorAta,
userWallet: feeSigner[0],
feeCollector: constants_1.ADDRESSES[this.network].SSL_SWAP_FEE_COLLECTOR,
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
}
async crankV2Single(swap) {
const usdcFeeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const feeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const usdcFeeVault = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, feeSigner[0], true);
const userInAta = swap.inputTokenAccount ?? await (0, spl_token_1.getAssociatedTokenAddress)(swap.inputMint, feeSigner[0], true);
return await this.program.methods
.crankV2Single(swap.minOut ?? constants_1.CRANK_AMOUNT)
.accounts({
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
usdcFeeVault: usdcFeeVault,
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
usdcFeeSigner: usdcFeeSigner[0],
gfxAmmProgram: swap.ammProgram,
ammAuthority: swap.authority,
ammConfig: swap.config,
ammPoolState: swap.state,
ammInputVault: swap.inputVault,
ammOutputVault: swap.outputVault,
ammObservationState: swap.observationState,
inputTokenMint: swap.inputMint,
outputTokenMint: constants_1.ADDRESSES[this.network].USDC_MINT,
inputTokenProgram: swap.inputTokenProgram,
outputTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
userInAta
})
.instruction();
}
async crankV2TwoHop(swap1, swap2) {
const usdcFeeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const feeSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const usdcFeeVault = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, feeSigner[0], true);
const userInAta = swap1.inputTokenAccount ?? await (0, spl_token_1.getAssociatedTokenAddress)(swap1.inputMint, feeSigner[0], true);
const intermediateAta = await (0, spl_token_1.getAssociatedTokenAddress)(swap1.outputMint, feeSigner[0], true);
const createAta = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, intermediateAta, feeSigner[0], swap1.outputMint);
const crank = await this.program.methods
.crankV2TwoHop(swap1.minOut ?? constants_1.CRANK_AMOUNT, swap2.minOut ?? constants_1.CRANK_AMOUNT)
.accounts({
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
usdcFeeVault: usdcFeeVault,
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
usdcFeeSigner: usdcFeeSigner[0],
gfxAmmProgram: swap1.ammProgram,
ammAuthority: swap1.authority,
ammConfig: swap1.config,
hop1AmmPoolState: swap1.state,
hop1AmmInputVault: swap1.inputVault,
hop1AmmOutputVault: swap1.outputVault,
hop1AmmObservationState: swap1.observationState,
userInAta,
inputTokenMint: swap1.inputMint,
intermediateTokenMint: swap1.outputMint,
outputTokenMint: swap2.outputMint,
inputTokenProgram: swap1.inputTokenProgram,
intermediateTokenProgram: swap1.outputTokenProgram,
outputTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
intermediateTokenAccount: intermediateAta,
hop2AmmPoolState: swap2.state,
hop2AmmInputVault: swap2.inputVault,
hop2AmmOutputVault: swap2.outputVault,
hop2AmmObservationState: swap2.observationState,
})
.instruction();
return [createAta, crank];
}
async crankUserRewardsHoldingAccount(user) {
user = user ?? this.wallet.publicKey;
const [usdcRewardSigner, userMetadata] = await Promise.all([
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.usdcRewardSigner], GfxStakeRewards.programId),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, user.toBuffer()], GfxStakeRewards.programId)
]);
const userRewardsHoldingAccount = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
return await this.program.methods
.crankUserRewardsHoldingAccount()
.accounts({
user,
userRewardsHoldingAccount,
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
gofxVault: constants_1.ADDRESSES[this.network].GOFX_VAULT,
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
usdcRewardSigner: usdcRewardSigner[0],
userMetadata: userMetadata[0],
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
systemProgram: web3_js_1.SystemProgram.programId
})
.instruction();
}
async stake(amount, walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const [ownerGofx, usdcRewardSigner, userMetadata] = await Promise.all([
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].GOFX_MINT, wallet),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.usdcRewardSigner], GfxStakeRewards.programId),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId)
]);
const userRewardsHoldingAccount = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
return this.program.methods
.stake(amount)
.accounts({
owner: wallet,
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
userRewardsHoldingAccount,
usdcRewardSigner: usdcRewardSigner[0],
ownerGofx: ownerGofx,
gofxVault: constants_1.ADDRESSES[this.network].GOFX_VAULT,
userMetadata: userMetadata[0],
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
}
async unstake(amount, walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const [gofxVaultSigner, usdcRewardSigner, userMetadata] = await Promise.all([
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.gofxVaultSigner], GfxStakeRewards.programId),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.usdcRewardSigner], GfxStakeRewards.programId),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId)
]);
const userRewardsHoldingAccount = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
return this.program.methods
.unstake(amount)
.accounts({
owner: wallet,
stakePool: constants_1.ADDRESSES[this.network].STAKE_POOL,
gofxVault: constants_1.ADDRESSES[this.network].GOFX_VAULT,
gofxUnstakedVault: constants_1.ADDRESSES[this.network].GOFX_UNSTAKED_VAULT,
gofxVaultSigner: gofxVaultSigner[0],
usdcRewardSigner: usdcRewardSigner[0],
usdcRewardVault: constants_1.ADDRESSES[this.network].USDC_REWARD_VAULT,
userRewardsHoldingAccount,
userMetadata: userMetadata[0],
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
}
async initializeTokenCrank(tokenCrank, outputMint, destinationOwner, payer) {
const crankSigner = this.getCrankSignerPDA(tokenCrank).publicKey;
const crankOutputVault = await (0, spl_token_1.getAssociatedTokenAddress)(outputMint, crankSigner, true);
return await this.program.methods
.initializeTokenCrank(destinationOwner)
.accounts({
payer: payer ?? this.wallet.publicKey,
tokenCrank,
crankSigner,
outputMint,
crankOutputVault,
})
.instruction();
}
async crankTokensViaGammaSwap(crank, swap, output) {
const crankSigner = this.getCrankSignerPDA(crank).publicKey;
const crankOutput = output ?? await this.getTokenCrankAccount(crank).then((res) => {
return {
owner: res.destinationOwner,
mint: res.outputMint
};
});
if (!crankOutput) {
throw new Error(`Failed to fetch crank information`);
}
const isFinalStep = swap.outputMint.toBase58() === crankOutput.mint.toBase58();
const inputTokenAccount = swap.inputTokenAccount ?? (0, spl_token_1.getAssociatedTokenAddressSync)(swap.inputMint, crankSigner, true);
const outputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swap.outputMint, crankSigner, true);
const instructions = [];
if (!isFinalStep) {
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, outputTokenAccount, crankSigner, swap.outputMint));
}
const destinationOutputTokenAccount = isFinalStep ? (0, spl_token_1.getAssociatedTokenAddressSync)(crankOutput.mint, crankOutput.owner, true) : null;
if (destinationOutputTokenAccount) {
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, destinationOutputTokenAccount, crankOutput.owner, crankOutput.mint));
}
const crankIx = await this.program.methods
.crankTokensGammaStep(swap.minOut ?? new bn_js_1.default(0))
.accounts({
crank,
crankSigner,
inputTokenMint: swap.inputMint,
outputTokenMint: swap.outputMint,
inputTokenAccount,
outputTokenAccount,
gammaAuthority: swap.authority,
gammaConfig: swap.config,
gammaPoolState: swap.state,
gammaPoolObservationState: swap.observationState,
gammaPoolInputVault: swap.inputVault,
gammaPoolOutputVault: swap.outputVault,
inputTokenProgram: swap.inputTokenProgram,
outputTokenProgram: swap.outputTokenProgram,
destinationOwner: crankOutput.owner,
destinationOutputTokenAccount,
gammaProgram: swap.ammProgram,
})
.instruction();
instructions.push(crankIx);
return instructions;
}
async initializeLstRewards(authority, destinationReserveAccount, payer) {
const lstRewards = this.getLSTRewardsPDA().publicKey;
return this.program.methods
.initializeLstRewards(authority, destinationReserveAccount)
.accounts({
payer: payer ?? this.wallet.publicKey,
lstRewards,
systemProgram: web3_js_1.SystemProgram.programId
})
.instruction();
}
async updateLstRewards(newAuthority, newDestinationReserveAccount, authority) {
const lstRewards = this.getLSTRewardsPDA().publicKey;
return this.program.methods
.updateLstRewardsParams(newAuthority, newDestinationReserveAccount)
.accounts({
authority: authority ?? this.wallet.publicKey,
lstRewards,
systemProgram: web3_js_1.SystemProgram.programId
})
.instruction();
}
async transferLSTRewards(reserveAccount, outputMint) {
const lstRewards = this.getLSTRewardsPDA().publicKey;
const outputTokenMint = outputMint ?? spl_token_1.NATIVE_MINT;
const rewardsTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(outputTokenMint, lstRewards, true);
return this.program.methods
.transferLstRewards()
.accounts({
rewardsTokenAccount,
reserveAccount,
lstRewards,
systemProgram: web3_js_1.SystemProgram.programId,
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
}
isUnstakingTicketClaimable(createdAt) {
const currentDate = new Date();
const sevenDaysFromCreation = new Date(createdAt * 1000);
sevenDaysFromCreation.setTime(sevenDaysFromCreation.getTime() + constants_1.SEVEN_DAYS);
return (sevenDaysFromCreation.getTime() <= currentDate.getTime());
}
async resolveUnstakingTicket(unstakeableTickets, walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
if (!unstakeableTickets || unstakeableTickets.length == 0) {
console.warn('[WARN]: No tickets to unstake');
}
const [gofxSigner, ownerGofx, userMetadata] = await Promise.all([
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.gofxUnstakedSigner], GfxStakeRewards.programId),
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].GOFX_MINT, wallet),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId)
]);
return await this.program.methods.resolveUnstakingTicket(buffer_1.Buffer.from(unstakeableTickets))
.accounts({
owner: wallet,
gofxUnstakedVault: constants_1.ADDRESSES[this.network].GOFX_UNSTAKED_VAULT,
gofxUnstakedSigner: gofxSigner[0],
ownerGofx: ownerGofx,
userMetadata: userMetadata[0],
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
}
async claimFees(walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const [usdcSigner, ownerUsdc, userMetadata] = await Promise.all([
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.usdcRewardSigner], GfxStakeRewards.programId),
(0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, wallet),
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId)
]);
const userRewardsHoldingAccount = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
return await this.program.methods
.claimFees()
.accounts({
owner: wallet,
userMetadata: userMetadata[0],
userRewardsHoldingAccount,
userUsdcAccount: ownerUsdc,
usdcRewardSigner: usdcSigner[0],
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
usdcMint: constants_1.ADDRESSES[this.network].USDC_MINT
})
.instruction();
}
async closeUserAccount(rentRecipient, walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const userMetadata = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId);
const userRewardsHoldingAccount = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
return await this.program.methods
.closeUserAccount()
.accounts({
owner: wallet,
rentRecipient: rentRecipient ?? wallet,
userMetadata: userMetadata[0],
systemProgram: web3_js_1.SystemProgram.programId,
userRewardsHoldingAccount,
})
.instruction();
}
async getStakePool() {
const stakePoolAddress = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.stakePool], GfxStakeRewards.programId);
const result = await this.program.account.stakePool.fetch(stakePoolAddress[0], 'confirmed');
return result;
}
async getUSDCRewardVault() {
const usdcRewardVaultSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.usdcRewardSigner], GfxStakeRewards.programId);
const usdcAddress = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, usdcRewardVaultSigner[0], true);
return await (0, spl_token_1.getAccount)(this.connection, usdcAddress, "processed");
}
async getFeesCollected(mint) {
const mintSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.feeCollector], GfxStakeRewards.programId);
const mintAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mint ?? constants_1.ADDRESSES[this.network].USDC_MINT, mintSigner[0], true);
return await (0, spl_token_1.getAccount)(this.connection, mintAddress, "processed");
}
async getGoFxVault() {
const mintSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.gofxVaultSigner], GfxStakeRewards.programId);
const mintAddress = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].GOFX_MINT, mintSigner[0], true);
return await (0, spl_token_1.getAccount)(this.connection, mintAddress, "confirmed");
}
async getGoFxUnstakedVault() {
const mintSigner = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.gofxUnstakedSigner], GfxStakeRewards.programId);
const mintAddress = await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].GOFX_MINT, mintSigner[0], true);
return await (0, spl_token_1.getAccount)(this.connection, mintAddress, "confirmed");
}
async getUserMetaData(walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const userMetaDataAddress = web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId);
return await this.program.account.userMetadata.fetch(userMetaDataAddress[0], 'processed');
}
async getUnstakingTickets(walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const userMetadata = await this.getUserMetaData(wallet);
if (!userMetadata) {
console.warn('[WARNING]: Could not get the users metadata');
return [];
}
const tickets = [];
for (let i = 0; i < userMetadata.unstakingTickets.length; i++) {
const ticket = userMetadata.unstakingTickets[i];
if (ticket.createdAt.toNumber() > 0) {
tickets.push(ticket);
}
}
return tickets;
}
getCrankSignerPDA(crank, programOverride) {
const [publicKey, nonce] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from('crank_signer', 'utf-8'), crank.toBuffer()], programOverride ?? GfxStakeRewards.programId);
return { publicKey, nonce };
}
getLSTRewardsPDA(programOverride) {
const [publicKey, nonce] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from('lst_rewards', 'utf-8')], programOverride ?? GfxStakeRewards.programId);
return { publicKey, nonce };
}
async getLSTRewardsAccount(address) {
const lstRewards = address ?? this.getLSTRewardsPDA().publicKey;
return this.program.account.lstRewards.fetch(lstRewards);
}
async getTokenCrankAccount(address) {
return this.program.account.tokenCrank.fetch(address);
}
getUnstakeableTickets(unstakingTickets) {
const tickets = [];
for (let i = 0; i < unstakingTickets.length; i++) {
const createdAt = unstakingTickets[i].createdAt.toNumber();
if (createdAt === 0) {
continue;
}
if (this.isUnstakingTicketClaimable(unstakingTickets[i].createdAt.toNumber())) {
tickets.push({ index: i, ticket: unstakingTickets[i] });
}
}
return tickets;
}
getTotalUnstakeClaimable(unstakeableTickets) {
return unstakeableTickets.reduce((a, b) => a + b.ticket.totalUnstaked.toNumber(), 0.0);
}
async getUserRewardsHoldingAccount(walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const [userMetadata] = await Promise.all([
web3_js_1.PublicKey.findProgramAddressSync([constants_1.TOKEN_SEEDS.userMetaData, wallet.toBuffer()], GfxStakeRewards.programId)
]);
return await (0, spl_token_1.getAssociatedTokenAddress)(constants_1.ADDRESSES[this.network].USDC_MINT, userMetadata[0], true);
}
async getUserRewardsHoldingAmount(walletPublicKey) {
const wallet = walletPublicKey ?? this.wallet.publicKey;
const userRewardsHoldingAccount = await this.getUserRewardsHoldingAccount(wallet);
const accountInfo = await this.connection.getParsedAccountInfo(userRewardsHoldingAccount, 'confirmed');
if (!accountInfo || !accountInfo.value)
return "0.0";
return accountInfo.value.data.parsed.info.tokenAmount.uiAmountString ?? "0.0";
}
}
exports.GfxStakeRewards = GfxStakeRewards;
GfxStakeRewards.programId = new web3_js_1.PublicKey("STKRWxT4irmTthSJydggspWmkc3ovYHx62DHLPVv1f1");
//# sourceMappingURL=gfxStakeRewards.js.map