SDK
Integrate the Castle ecosystem of products into your app to supercharge your UX
Client-Side Integration
Client-side integrations are powered by our SDK, which lives alongside the program code in the Vault repository. The primary actions a user takes are deposit and withdraw.
The SDK exposes deposit() and withdraw(), both abstract away intermediate instructions like creating ATAs, (un)wrapping sol, refreshing or reconciling the vault.
If you run into transaction size limits (for example: sending transactions as part of governance proposals that increase the bytes to over 1232), then you can split up certain instructions into their own transactions. Each section will provide code for both single SDK call and multi-SDK call cases.
Here's the full list of instructions the vault contract expects:
refresh: (permissionless) Refreshes the vaults accountsreconcile: (permissionless) Withdraws from the underlying lending markets to allow a user to withdrawdeposit: Sends reserve token (e.g. USDC) assets into the vault in exchange for LP tokenswithdraw: Sends LP tokens into the vault in exchange for reserve token assets
Vault Client
Installation
SDK NPM: https://www.npmjs.com/package/@castlefinance/vault-sdk
yarn add @castlefinance/vault-sdk
Usage
The VaultClient contains static and member functions for loading information about a specific vault, along with all the necessary instructions for depositing and withdrawing.
Here is an example deployed vault along with the Anchor annotations: https://explorer.solana.com/address/9n6ekjHHgkPB9fVuWHzH6iNuxBxN22hEBryZXYFg6cNk/anchor-account?cluster=devnet
Deposit
Here are the following instructions needed to make a deposit:
Create the user's LP token account if it does not exist
Refresh the Vault
Deposit into the Vault
Note: The refresh and deposit instructions need to be sent in the same transaction.
Deposit (single SDK call)
Deposit (multi-SDK call)
Create LP Token Account Transaction:
Refresh and Deposit into the Vault:
Withdraw
Withdrawing requires the following transactions to be sent:
Transaction #1
Refresh the vault
Reconcile the markets
Transaction #2
Refresh the vault
Withdraw from the vault
Withdraw (single SDK call)
Withdraw (multi-SDK call)
Create the reconcile transactions:
Note: There may be up to 3 different reconcile transactions. Simply send off all of them.
Create the ATAs as needed and withdraw from the vault:
Final Notes
These docs are still a work-in-progress. Please reach out to our Twitter or Discord if you have any questions or something is not working.
Last updated