Protocol Guide
Sona currently supports Solend lending, Jupiter swaps, and basic wallet operations with attested transaction generation.
Solend
Solend is the autonomous interest rate machine for lending on Solana.
See the API Reference for detailed parameter schemas, response types, and interactive examples for all Solend endpoints.
Deposit
const intent = await sona.solend.deposit({
amount: 100_000_000 // 100 USDC (6 decimals)
});
await intent.verify();
await intent.confirm(signAndSendFunction);
Withdraw
const intent = await sona.solend.withdraw({
amount: 50_000_000 // 50 USDC
});
await intent.verify();
await intent.confirm(signAndSendFunction);
Positions
const positions = await sona.solend.positions({});
console.log('Deposited USDC:', positions.depositedUSDC);
Jupiter
Jupiter provides best-price token swaps across all Solana DEXs.
See the API Reference for detailed parameter schemas, response types, and interactive examples for all Jupiter endpoints.
Swap
const intent = await sona.jupiter.swap({
inputMint: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', // BONK
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
amount: 1_000_000_000,
slippageBps: 100 // 1% slippage
});
await intent.verify();
await intent.confirm(signAndSendFunction);
Wallet
Basic wallet operations for transfers and balance queries.
See the API Reference for detailed parameter schemas, response types, and interactive examples for all Wallet endpoints.
Transfer
const intent = await sona.wallet.transfer({
recipient: 'RECIPIENT_WALLET_ADDRESS',
amount: 1_000_000 // 1 USDC
});
await intent.verify();
await intent.confirm(signAndSendFunction);
Balance
const balance = await sona.wallet.balance({
symbols: ['USDC', 'SOL', 'BONK']
});
console.log('USDC Balance:', balance.amount);
Complete Example
Full workflow with wallet integration:
import { Sona } from '@sonabuild/kit';
import { createSolanaRpc } from '@solana/rpc';
import { getBase64Decoder } from '@solana/codecs-strings';
// Initialize client
const sona = new Sona({
wallet: wallet.publicKey.toString()
});
// Create RPC connection
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
// 1. Deposit to Solend
const depositIntent = await sona.solend.deposit({
amount: 100_000_000 // 100 USDC
});
// 2. Verify attestation
if (!await depositIntent.verify()) {
throw new Error('Attestation verification failed');
}
// 3. Sign and send
await depositIntent.confirm(async (intents) => {
const signatures = [];
for (const intent of intents) {
// Get transaction bytes
const txBytes = getBase64Decoder().decode(intent.getTransaction());
// Sign with wallet (wallet handles deserialization)
const signed = await wallet.signTransaction(txBytes);
// Send to network
const signature = await rpc.sendTransaction(signed, {
encoding: 'base64'
}).send();
// Confirm
await rpc.confirmTransaction(signature, {
commitment: 'confirmed'
}).send();
signatures.push(signature);
}
return { signatures };
});
console.log('✓ Deposit successful');
Error Handling
Always include proper error handling:
try {
const intent = await sona.solend.deposit({
amount: 100_000_000
});
if (!await intent.verify()) {
throw new Error('Attestation verification failed - do not sign!');
}
await intent.confirm(signAndSendFunction);
} catch (error) {
if (error.message.includes('Insufficient funds')) {
console.error('Not enough balance');
} else if (error.message.includes('User rejected')) {
console.error('Transaction rejected by user');
} else {
console.error('Transaction failed:', error.message);
}
}
Amount Formatting
All amounts use base units (smallest divisible unit):
// USDC (6 decimals)
1 USDC = 1_000_000 base units
100 USDC = 100_000_000 base units
// SOL (9 decimals)
1 SOL = 1_000_000_000 lamports
0.5 SOL = 500_000_000 lamports
// Helper function
function toBaseUnits(amount, decimals) {
return Math.floor(amount * Math.pow(10, decimals));
}
// Usage
const amount = toBaseUnits(100, 6); // 100 USDC → 100_000_000
Coming Soon
We're actively adding support for:
- Drift Protocol - Perpetual futures and margin trading
- Marginfi - Decentralized margin lending
- Kamino - Automated liquidity management
- Phoenix - Decentralized orderbook
Request a protocol by opening an issue on GitHub.