The 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:
- User is granted/airdropped a bond, indicating they have been given access to the platform.
- User leverages the bond to gain access to the platform by calling
grantAccess
. - User purchases and mints new bonds by calling
mintBond
. - User lets bonds mature for a period of time, ideally a year or more, but can do so immediately after purchasing.
- 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. - 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:
import { StablebondProgram } from "@etherfuse/stablebond-sdk";
Collect the static stablebond information
const bonds = await StablebondProgram.getBonds(rpcEndpoint);
Then, once a user has authenticated, create an instance of the StablebondProgram class:
const stablebondProgram = new StablebondProgram(rpcEndpoint, wallet);
async getUserBondBalances(): Promise<Map<string, Decimal>>
Fetches the user's bond balances in the Stablebond program.
async getUserTokens(): Promise<Stablebond[]>
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.
async getUserNFTs(): Promise<PartialNFT[]>
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.
async hasAccess(): Promise<boolean>
Checks if the user has access to the Stablebond program.
async grantAccess(bondAddress: string, bondMint: string): Promise<Uint8Array>
Grants access to the user by leveraging a bond in their wallet, proving they have sought out and requsted access to the platform.
async hasKYC(): Promise<boolean>
Checks if the user has completed KYC (Know Your Customer) verification in the Stablebond program.
async mintBond(stablebondAddress: Address, uiAmount: Decimal): Promise<Uint8Array>
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.
async instantRedeemBonds(stablebondAddress: Address, passedUIAmount?: Decimal): Promise<Uint8Array>
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.
async createPurchaseOrder(stablebondAddress: Address, paymentAmount: Decimal): Promise<Uint8Array>
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.
async redeemPurchaseOrder(nftMintString: Address): Promise<Uint8Array>
Redeems a purchase order for the user to claim bonds previously paid for within the Stablebond program.
async redeemBonds(stablebondAddress: Address, passedUIAmount?: Decimal): Promise<Uint8Array>
Redeems bonds in the Stablebond program. This results in a user receiving an NFT that will mature at the end of the current issuance.
async redeemNFT(nftMintString: Address): Promise<Uint8Array>
Redeems an NFT in the Stablebond program. This results in a user receiving the underlying asset of the NFT.
static async getBonds(rpcEndpoint: string): Promise<Stablebond[]>
Fetches the bonds in the Stablebond program.
static async getBond(rpcEndpoint: string, bondAddress: string): Promise<Stablebond>
Fetches a bond in the Stablebond program.
static async getBondPrices(host = StablebondProgram.etherfuseHost): Promise<{ [mint: string]: PriceData }>
Fetches current prices for active bonds in their payment tokens, keyed by bond mint. This defaults to using the etherfuse production host.
static async getBondPrice(mint: Address, host = StablebondProgram.etherfuseHost): Promise<PriceData>
Fetches the current price for a bond in its payment token. This defaults to using the etherfuse production host.
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.
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.