@etherfuse/stablebond-sdk v1.0.12
Etherfuse Stablebond Program SDK
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.
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.
Usage
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);
Instance Methods
getUserBondBalances
async getUserBondBalances(): Promise<Map<string, Decimal>>
Fetches the user's bond balances in the Stablebond program.
getUserTokens
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.
getUserNFTs
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.
hasAccess
async hasAccess(): Promise<boolean>
Checks if the user has access to the Stablebond program.
grantAccess
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.
mintBond
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.
makePurchaseOrder
async makePurchaseOrder(stablebondAddress: Address, paymentAmount: Decimal): Promise<Uint8Array>
Creates a purchase order for the user to reserve bonds in the upcoming issuance within the Stablebond program. Amount is is in the payment token of the bond, without specifying the amount of bonds to purchase.
redeemPurchaseOrder
async redeemPurchaseOrder(nftMintString: Address): Promise<Uint8Array>
Redeems a purchase order for the user to claim bonds previously paid for within the Stablebond program.
redeemBonds
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.
redeemNFT
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 Methods
getBonds
static async getBonds(rpcEndpoint: string): Promise<Stablebond[]>
Fetches the bonds in the Stablebond program.
getBond
static async getBond(rpcEndpoint: string, bondAddress: string): Promise<Stablebond>
Fetches a bond in the Stablebond program.
getBondPrices
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.
getBondPrice
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.
mapToCompleteNFT
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.
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago