SDK
SDK
The Risk Protocol SDK is a TypeScript library for interacting with Risk Protocol's core smart contracts and services. Built on ethers.js v6, it provides a complete interface for token management, vault operations, rebalancing, and price estimation.
Installation
npm install risk-contracts
# or
yarn add risk-contracts
## Note that it's not published yet, the above is a placeholderQuick Start
Server-Side (Node.js)
import { RiskContracts, RiskSdkConfig } from 'risk-contracts';
const config: RiskSdkConfig = {
serverProvider: {
rpcUrl: "https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
privateKey: "YOUR_PRIVATE_KEY"
},
network: {
name: "sepolia",
chainId: 11155111
},
tokenFactory: {
address: "0x8888cF3da8E6Fb30bEEcD9dC1dd220060c2969DC"
},
smartToken: {
one: "0x...", // RiskON token address
two: "0x..." // RiskOFF token address
},
orchestrator: {
address: "0x..."
},
apiUrl: "https://api.riskprotocol.com"
};
const sdk = new RiskContracts(config);Client-Side (Browser with Wallet)
Configuration
The SDK requires a configuration object that specifies network settings, contract addresses, and provider details.
Important: Provide either serverProvider or clientProvider, not both.
Core Concepts
SDK Structure
The SDK exposes five main modules:
tokenFactory - Core token operations, management fees, and rebalancing
smartToken - ERC-4626 vault operations (deposits, withdrawals, transfers)
orchestrator - Scheduled operations and Balancer pool management
balancerHelper - Balancer pool calculations and swap estimations
priceEstimates - Price discovery and slippage calculations
Working with Amounts
All token amounts in the SDK use wei units (BigInt). Use ethers.js utilities for conversion:
Smart Tokens
Risk Protocol uses two smart tokens: RiskON (index 0) and RiskOFF (index 1). Most SmartToken methods accept an optional contract parameter:
Common Workflows
1. Deposit Tokens
2. Withdraw Tokens
3. Check Balances and Fees
4. Estimate Swap Outputs
Error Handling
Always wrap SDK calls in try-catch blocks:
Best Practices
1. Always Preview Before Executing
2. Check Maximum Limits
TypeScript Support
The SDK is fully typed. Import types as needed:
Next Steps
See the API Reference for complete method documentation
Last updated
