Documentation
Technical reference for the Cadence protocol architecture, smart contracts, and integrations.
Architecture
Cadence is a non-custodial yield aggregation protocol built on the ERC-4626 tokenized vault standard. Users deposit underlying assets (WETH, USDC) and receive vault shares representing their proportional claim on the pool.
The protocol follows a modular architecture with three primary layers:
- Vault Layer - ERC-4626 compliant vaults that custody user funds, manage share accounting, and enforce access control via OpenZeppelin's role-based system (Governor, Guardian, Harvester).
- Strategy Layer - Pluggable yield strategies that deploy idle capital. Strategies implement the
IYieldStrategyinterface and are upgradeable by governance without moving user funds. - Automation Layer - ERC-4337 account abstraction via ZeroDev session keys enables gasless recurring deposits with spending limits and time bounds.
Smart Contracts
YieldVault.sol
The core vault contract inherits ERC4626, AccessControl, Pausable, and ReentrancyGuard from OpenZeppelin v5.
Roles
| Role | Permissions |
|---|---|
| GOVERNOR_ROLE | Set strategy, update fees, pause/unpause |
| GUARDIAN_ROLE | Pause vault, emergency withdraw from strategy |
| HARVESTER_ROLE | Call harvest() to realize yield |
IYieldStrategy
Interface for pluggable strategies. The vault only interacts with strategies through this interface, enabling upgrades without migrating user funds.
interface IYieldStrategy {
function asset() external view returns (address);
function totalAssets() external view returns (uint256);
function deposit(uint256 amount) external;
function withdraw(uint256 amount) external returns (uint256);
function harvest() external returns (uint256 yieldAmount);
}MockYieldStrategy.sol
A deterministic yield simulator for testnet deployment. Accrues linear yield based on a configurable APR and a pre-funded yield reservoir. This ensures demo interactions produce predictable, verifiable results without external protocol dependencies.
Session Keys
Cadence uses ERC-4337 account abstraction to enable gasless, automated deposits. Users create scoped session keys with:
- Spending limits - Maximum amount that can be deposited per session
- Time bounds - Session expires after a configurable duration
- Target scope - Keys are bound to a specific vault contract address
Session keys are generated client-side using an ephemeral private key. The authorization is signed via EIP-712 typed data and persisted in localStorage. In production, these sessions are registered on-chain through ZeroDev's kernel smart account infrastructure.
// Session key authorization flow
1. Generate ephemeral keypair (viem)
2. Sign EIP-712 typed data (spending limit, expiry, target vault)
3. Register session via ZeroDev SDK (production)
4. Automated deposits execute as UserOperations
5. Bundler submits to EntryPoint, paymaster covers gasSubgraph
Vault events are indexed by a Graph Protocol subgraph deployed to Subgraph Studio. The subgraph tracks:
The frontend queries the subgraph for the activity feed, aggregating deposits, withdrawals, and harvest events sorted by timestamp.
Deployment
Contracts are deployed via Foundry's scripting framework:
# Deploy to Sepolia
forge script script/Deploy.s.sol \
--rpc-url $SEPOLIA_RPC_URL \
--broadcast \
--verifyThe deploy script creates mock tokens (mWETH, mUSDC), vaults, and strategies in a single transaction batch. It also funds each strategy's yield reservoir and sets the initial 5% APR and 10% performance fee.
Frontend Configuration
After deploying, paste the contract addresses into .env.local:
NEXT_PUBLIC_WETH_VAULT_ADDRESS=0x...
NEXT_PUBLIC_USDC_VAULT_ADDRESS=0x...
NEXT_PUBLIC_WETH_TOKEN_ADDRESS=0x...
NEXT_PUBLIC_USDC_TOKEN_ADDRESS=0x...
NEXT_PUBLIC_WETH_STRATEGY_ADDRESS=0x...
NEXT_PUBLIC_USDC_STRATEGY_ADDRESS=0x...
NEXT_PUBLIC_SUBGRAPH_URL=https://api.studio.thegraph.com/...Testing
# Run contract tests
cd contracts && forge test -vvv
# Run subgraph tests
cd subgraph && npx graph test