Carrot SDK
A Rust SDK for interacting with the Carrot Protocol on Solana. This SDK provides a simple interface for depositing stablecoins (USDC, USDT, pyUSD) and withdrawing CRT tokens.
Features
- Deposit stablecoins (USDC, USDT, pyUSD) to receive CRT tokens
- Withdraw CRT tokens to receive stablecoins
- Automatic ATA (Associated Token Account) creation
- Simple, Anchor-free implementation using core Solana libraries
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Example - Deposit USDC
use ;
use Keypair;
Withdraw CRT
use ;
use Keypair;
Check Balances
use ;
use Pubkey;
Convenience Functions
The SDK provides convenience functions for common operations:
use ;
use Keypair;
Running Examples
The SDK includes example programs that demonstrate real-world usage:
Deposit Example
Deposits 1 USDC to the Carrot Protocol:
Withdraw Example
Withdraws half of your CRT balance:
Important Constants
The SDK provides pre-configured constants for mainnet:
use *;
// Program and addresses
CARROT_PROGRAM_ID // CarrotwivhMpDnm27EHmRLeQ683Z1PufuqEmBZvD282s
VAULT_ADDRESS // FfCRL34rkJiMiX5emNDrYp3MdWH2mES3FvDQyFppqgpJ
// Token mints
CRT_MINT // CRTx1JouZhzSU6XytsE42UQraoGqiHgxabocVfARTy2s
USDC_MINT // EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
USDT_MINT // Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
PYUSD_MINT // 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo
Token Decimals
- USDC: 6 decimals (1 USDC = 1,000,000)
- USDT: 6 decimals (1 USDT = 1,000,000)
- pyUSD: 6 decimals (1 pyUSD = 1,000,000)
- CRT: 9 decimals (1 CRT = 1,000,000,000)
API Reference
CarrotClient
Main client for interacting with Carrot Protocol.
Methods
new(rpc_url: String) -> Self- Create a new clientdeposit(user: &Keypair, asset_mint: &Pubkey, amount: u64) -> Result<Signature>- Deposit assetswithdraw(user: &Keypair, asset_mint: &Pubkey, amount: u64) -> Result<Signature>- Withdraw assetsget_asset_balance(user: &Pubkey, asset_mint: &Pubkey) -> Result<u64>- Check asset balanceget_crt_balance(user: &Pubkey) -> Result<u64>- Check CRT balancefetch_vault() -> Result<Vault>- Fetch vault data from blockchain
Error Handling
The SDK uses a custom error type that wraps common Solana and token errors:
use CarrotError;
match client.deposit
Testing
Run the test suite:
The tests verify:
- Vault PDA derivation
- ATA address derivation
- Program ID and constant correctness
Dependencies
This SDK uses the following Solana crates:
solana-sdk = "2.3.1"solana-client = "2.3.2"spl-token = "8.0.0"spl-associated-token-account = "7.0.0"borsh = "1.5.7"
License
MIT
Links
Support
For issues and questions, please open an issue on GitHub.