@castlefinance/vault-sdk
TypeScript icon, indicating that this package has built-in type declarations

4.0.0-beta • Public • Published

Castle Vault SDK

Full technical documentation can be found here.

Installation

yarn add @castlefinance/vault-sdk

Getting Help

Join our Discord channel and post a message in #developers

Examples

Create the client

import { VaultClient, VaultConfig } from '@castlefinance/vault-sdk'

// Pull down the appropriate vault from the API.
const configResponse = await fetch('https://api.castle.finance/configs')
const vaults = (await response.json()) as VaultConfig[]
const vault = vaults.find(
  (v) => v.deploymentEnv == 'mainnet' && v.token_label == 'USDC'
)


// Create the vault client
const vaultClient = await VaultClient.load(
  new anchor.Provider(...),
  vault.vault_id,
  vault.deploymentEnv
)

Deposit

// Get the users reserve token ATA
const userReserveToken = await splToken.Token.getAssociatedTokenAddress(
  ASSOCIATED_TOKEN_PROGRAM_ID,
  TOKEN_PROGRAM_ID,
  vaultClient.getVaultState().reserveTokenMint,
  reserveTokenOwner, // e.g. wallet.pubkey or DAO's account
  true
);

// Deposit into the vault
const sig = await vaultClient.deposit(wallet, amount, userReserveToken)

Withdraw

const sig = await vaultClient.withdraw(wallet, amount)

Readme

Keywords

none

Package Sidebar

Install

npm i @castlefinance/vault-sdk

Weekly Downloads

48

Version

4.0.0-beta

License

MIT

Unpacked Size

257 kB

Total Files

38

Last publish

Collaborators

  • fycastle
  • aeksco
  • adamadlawrence
  • charlieyou