JavaScript client for the stablebond program
npm install @etherfuse/stablebond-sdkThe StablebondProgram class provides a set of methods to interact with the Stablebond program on the Solana blockchain.
We're currently using this ourselves at app.etherfuse.com.
We also have a devnet version of the program running at devnet.etherfuse.com. This is useful for testing and development, reach out to us for play-money and we'll transfer you some fake tokens to use.
A users's bond lifecycle is as follows:
1. User is granted/airdropped a bond, indicating they have been given access to the platform.
2. User leverages the bond to gain access to the platform by calling grantAccess.
3. User purchases and mints new bonds by calling mintBond.
4. User lets bonds mature for a period of time, ideally a year or more, but can do so immediately after purchasing.
5. User redeems bonds by calling redeemBonds, getting an NFT that will store the user's bonds in a vault until the next issuance, similar to unstaking solana.
6. User redeems the NFT by calling redeemNFT, getting the payment stablecoin for the bonds they redeemed, the same token used to pay for the bond.
Though the SDK includes all autogenerated code and types from the program, we recommend interacting with the program through the StablebondProgram class. There are exported types to enable faster development and better type safety.
The pattern for interacting with the class is that static methods reveal catalog information about availible bonds, while instance methods are used to interact with the context of a user's wallet. This way, catalog infomation can be refreshed independently of the user's wallet state.
First, import the StablebondProgram class:
``ts`
import { StablebondProgram } from "@etherfuse/stablebond-sdk";
Collect the static stablebond information
`ts`
const bonds = await StablebondProgram.getBonds(rpcEndpoint);
Then, once a user has authenticated, create an instance of the StablebondProgram class:
`ts`
const stablebondProgram = new StablebondProgram(rpcEndpoint, wallet);
#### getUserBondBalances
`ts`
async getUserBondBalances(): Promise
Fetches the user's bond balances in the Stablebond program.
#### getUserTokens
`ts`
async getUserTokens(): Promise
Fetches the user's tokens in the Stablebond program, combining getBonds and getUserBondBalances. We don't call this in our code, but it's available for you to use.
#### getUserNFTs
`ts`
async getUserNFTs(): Promise
Fetches the user's NFTs in the Stablebond program. For the sake of effiency, catalog information about the bond is excluded. This information can be patched back in to complete a full NFT object using the static mapper method mapToCompleteNFT.
#### hasAccess
`ts`
async hasAccess(): Promise
Checks if the user has access to the Stablebond program.
#### grantAccess
`ts`
async grantAccess(bondAddress: string, bondMint: string): Promise
Grants access to the user by leveraging a bond in their wallet, proving they have sought out and requsted access to the platform.
#### hasKYC
`ts`
async hasKYC(): Promise
Checks if the user has completed KYC (Know Your Customer) verification in the Stablebond program.
#### mintBond
`ts`
async mintBond(stablebondAddress: Address, uiAmount: Decimal): Promise
Mints new bonds for the user matching the specified amount. Amount is is in the payment token of the bond, without specifying the amount of bonds to purchase.
#### instantRedeemBonds
`ts`
async instantRedeemBonds(stablebondAddress: Address, passedUIAmount?: Decimal): Promise
Instantly redeems bonds in the Stablebond program. This results in a user getting paid out in the payment token of the bond, minus a fee. The fee and available liquidity are determined by the bond's instant redeem configuration.
#### createPurchaseOrder
`ts`
async createPurchaseOrder(stablebondAddress: Address, paymentAmount: Decimal): Promise
Creates a purchase order for the user to reserve bonds in the upcoming issuance within the Stablebond program. The amount is in the payment token of the bond, without specifying the amount of bonds to purchase.
#### redeemPurchaseOrder
`ts`
async redeemPurchaseOrder(nftMintString: Address): Promise
Redeems a purchase order for the user to claim bonds previously paid for within the Stablebond program.
#### redeemBonds
`ts`
async redeemBonds(stablebondAddress: Address, passedUIAmount?: Decimal): Promise
Redeems bonds in the Stablebond program. This results in a user receiving an NFT that will mature at the end of the current issuance.
#### redeemNFT
`ts`
async redeemNFT(nftMintString: Address): Promise
Redeems an NFT in the Stablebond program. This results in a user receiving the underlying asset of the NFT.
#### getBonds
`ts`
static async getBonds(rpcEndpoint: string): Promise
Fetches the bonds in the Stablebond program.
#### getBond
`ts`
static async getBond(rpcEndpoint: string, bondAddress: string): Promise
Fetches a bond in the Stablebond program.
#### getBondPrices
`ts`
static async getBondPrices(host = StablebondProgram.etherfuseHost): Promise<{ [mint: string]: PriceData }>
Fetches current prices for active bonds, keyed by bond mint. This defaults to using the etherfuse production host.
#### getBondPrice
`ts`
static async getBondPrice(mint: Address, host = StablebondProgram.etherfuseHost): Promise
Fetches the current price for a bond in its payment token. This defaults to using the etherfuse production host.
#### mapToCompleteNFT
`ts`
static mapToCompleteNFT({ ...nft }: PartialNFT, bond: Stablebond): NFT
Maps a PartialNFT and a Stablebond to a complete NFT.
For more details, refer to the StablebondProgram class in the source code.
#### getInterestOverTime
`ts`
static getInterestOverTime(basisPoints: number, secondsPast: number): Decimal
Calculates the interest accrued over a period of time given a rate in basis points. This is used internally to calculate bond values but may be useful for external calculations.
Parameters:
- basisPoints: The interest rate in basis points (1/100th of a percent)secondsPast`: The number of seconds that have passed
-
Returns a Decimal representing the multiplier to apply to the principal amount.