@perena/bankineco-sdk
v1.0.120
Published
SDK for interacting with Bankineco program on Solana.
Readme
@perena/bankineco-sdk
SDK for interacting with the Bankineco program on Solana.
Installation
npm install @perena/bankineco-sdkExample Usage
Initialize the Client
import { UsdStarClient, USDC_MINT, USDC_DECIMALS, USD_STAR_DECIMALS, fromUiAmount, BankinecoAction } from "@perena/bankineco-sdk";
import { Wallet } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
const rpcUrl: string = ...; // TODO
const anchorWallet: Wallet = ...; // TODO
const client = UsdStarClient.new({
env: "prod",
rpcUrl,
wallet: anchorWallet,
});Minting USD*
// Mint USD* with 1 USDC
const { transaction, lookupTables } = await client.mintFromYieldingTx({
yieldingAmount: fromUiAmount(1, USDC_DECIMALS),
fromYieldingMint: USDC_MINT,
user: anchorWallet.publicKey,
});
// OR, If performing a CPI, pull accounts quicker:
const cpiAccounts = client.cpiAccounts(USDC_MINT, BankinecoAction.Mint);Burning USD*
// Burn 1 USD* for USDC
const { transaction, lookupTables } = await client.burnForYieldingTx({
banKMintAmount: fromUiAmount(1, USD_STAR_DECIMALS),
toYieldingMint: USDC_MINT,
user: anchorWallet.publicKey,
});
// OR, If performing a CPI, pull accounts quicker:
const cpiAccounts = client.cpiAccounts(USDC_MINT, BankinecoAction.Burn);Get USD* Price
const usdStarPrice = await client.latestBankMintUiPrice();Get Junior Mint Price
const juniorMintPrice = await client.latestJuniorMintUiPrice();Get USD* Price
import { getLatestUsdStarUiPrice } from "@perena/bankineco-sdk";
const usdStarPrice = await getLatestUsdStarUiPrice(rpcUrl, "prod");Get Quote
const vault = this.getVault(USDC_MINT);
// Calculate the amount of USD* you will get from the USDC provided
const { amount: usdStarOutput, details: mintDetails } =
await client.yieldingToBankMintQuote(fromUiAmount(1, USDC_DECIMALS), vault);
// Calculate the amount of USDC you will receive from the USD* amount provided
const { amount: usdcOutput, details: burnDetails } =
await client.bankMintToYieldingQuote(
fromUiAmount(1, USD_STAR_DECIMALS),
vault,
);Staking (Junior Tranche)
Stake USD* into the junior tranche to earn leveraged yield. Staked tokens are represented by junior share tokens.
// Stake 10 USD* into the junior tranche
const { transaction, lookupTables, juniorMint } = await client.stakeJuniorTx({
amount: fromUiAmount(10, USD_STAR_DECIMALS),
user: anchorWallet.publicKey,
});Unstaking (Junior Tranche)
Unstaking is a two-step process: first request the unstake (which locks your shares in a withdrawal queue), then fulfill it once the lockup period expires. An admin crank automatically fulfills expired queues, so in most cases you only need to submit the request and wait.
Fulfilling immediately is possible but incurs a higher early unstake fee. Waiting for the lockup to expire means a lower standard fee is applied instead.
// Request unstake — locks shares in a withdrawal queue
const { transaction, lookupTables, withdrawalQueue } = await client.requestUnstakeJuniorTx({
shares: fromUiAmount(5, USD_STAR_DECIMALS),
queueId: 0, // unique per-user queue identifier
user: anchorWallet.publicKey,
});To receive a yielding token (e.g. USDC) directly instead of USD*, pass targetMint:
const { transaction, lookupTables } = await client.requestUnstakeJuniorTx({
shares: fromUiAmount(5, USD_STAR_DECIMALS),
queueId: 0,
targetMint: USDC_MINT,
});If you need to fulfill immediately (paying the early unstake fee), you can compose both steps into a single transaction:
import { Transaction } from "@solana/web3.js";
const { transaction: requestTx, lookupTables } = await client.requestUnstakeJuniorTx({
shares: fromUiAmount(5, USD_STAR_DECIMALS),
queueId: 0,
user: anchorWallet.publicKey,
});
const { transaction: fulfillTx } = await client.fulfillUnstakeJuniorTx({
owner: anchorWallet.publicKey,
queueId: 0,
});
const transaction = new Transaction().add(requestTx, fulfillTx);Reading Withdrawal Queues
After requesting an unstake, you can fetch all withdrawal queue entries for a given owner to check amounts awaiting unstake and how much time remains until each lockup expires.
const queues = await client.fetchAllWithdrawalQueues(anchorWallet.publicKey);
for (const queue of queues) {
queue.queueId; // the queue identifier
queue.address; // on-chain address of this queue entry
queue.amount; // junior shares locked in this queue entry
queue.targetMint; // the mint the user receives upon fulfillment (e.g. USD* or USDC)
queue.requestTs; // when the unstake was requested
queue.expiryTs; // when the lockup expires
queue.secondsRemaining; // seconds until the admin crank can fulfill (0 if expired)
queue.isExpired; // true if the lockup period has passed
}Get Unstake Fee
Fetch the fee that would be applied for a given unstake amount. Set early: true for an immediate unstake (higher fee) or early: false for a standard unstake after the lockup expires.
// Early unstake fee (fulfilling before lockup expires)
const { feeBps, feeAmount, amountAfterFee } = await client.fetchUnstakeFee({
amount: fromUiAmount(5, USD_STAR_DECIMALS),
early: true,
});
// Standard unstake fee (after lockup expires)
const standard = await client.fetchUnstakeFee({
amount: fromUiAmount(5, USD_STAR_DECIMALS),
early: false,
});Use Insured USD*
import { InsuredUsdStarClient } from "@perena/bankineco-sdk";
const client = InsuredUsdStarClient.new({
env: "prod",
rpcUrl,
wallet: anchorWallet,
});