@algofi/js-sdk
Version:
The official Algofi JavaScript SDK
90 lines (89 loc) • 3.38 kB
TypeScript
import { Algodv2, Account, Transaction } from "algosdk";
import AlgofiUser from "../../algofiUser";
import AssetDataClient from "../../assetData/assetDataClient";
import AssetAmount from "../../assetData/assetAmount";
import StakingClient from "./stakingClient";
import StakingConfig from "./stakingConfig";
export default class Staking {
algod: Algodv2;
stakingClient: StakingClient;
assetDataClient: AssetDataClient;
managerAppId: number;
marketAppId: number;
oracleAppId: number;
managerAddress: string;
marketAddress: string;
assetId: number;
latestTime: number;
totalStaked: number;
rewardsProgramNumber: number;
rewardsCoefficient: number;
rewardsAmount: number;
rewardsAssetId: number;
rewardsPerSecond: number;
rewardsSecondaryAssetId: number;
rewardsSecondaryRatio: number;
projectedRewardsCoefficient: number;
/**
* Constructor for the staking object.
*
* @param algod - algod client
* @param stakingClient - staking client
* @param stakingConfig - stakingConfig object with information on the staking
* contract
*/
constructor(algod: Algodv2, stakingClient: StakingClient, stakingConfig: StakingConfig);
/**
* Function to load in global state into the relevant fields on the class.
*/
loadState(): Promise<void>;
getTotalStaked(): AssetAmount;
getRewardsAPR(): number;
getSecondaryRewardsAPR(): number;
/**
* Constructs a series of transactions to opt a user into the staking
* contract.
*
* @param user - user opting in
* @param storageAccount - storage account for user opting in
* @returns a series of transactions to opt a user into the staking
* contract.
*/
getOptInTxns(user: AlgofiUser, storageAccount: Account): Promise<Transaction[]>;
/**
* Constructs a series of transactions to put before many of the transactions
* in staking on the Algofi protocol.
*
* @param user - user to get preamble transactions for
* @returns a series of transactions to put before many of the transactions
* in staking on the Algofi protocol.
*/
getPreambleTxns(user: AlgofiUser): Promise<Transaction[]>;
/**
* Constructs a series of transactions to stake a certain amount of an asset for
* a user.
*
* @param user - user staking
* @param amount - amount staking
* @returns a series of transactions to stake a certain amount of an asset for
* a user.
*/
getStakeTxns(user: AlgofiUser, amount: number): Promise<Transaction[]>;
/**
* Constructs a series of transactions to unstake a certain amount for a user on
* a staking contract.
*
* @param user - user to unstake for
* @param amount - amount to unstake
* @returns a series of transactions to unstake a certain amount for a user on
* a staking contract.
*/
getUnstakeTxns(user: AlgofiUser, amount: number): Promise<Transaction[]>;
/**
* Constructs a series of transactions to claim a user's staked assets.
*
* @param user - user to claim
* @returns a series of transactions to claim a user's staked assets.
*/
getClaimTxns(user: AlgofiUser): Promise<Transaction[]>;
}