Skip to content

Commit dc80b10

Browse files
aalavandhanclaude
andcommitted
Add DRBalancerVault contract for system DR rebalancing
Implement a vault that holds underlying (AMPL) and perp (SPOT) tokens and auto-rebalances to maintain the system's target deviation ratio via IRolloverVault swaps. Key features: - Deposit underlying tokens and mint vault notes (LP tokens) - Redeem notes for proportional underlying + perp tokens - Auto-rebalance when system DR is outside equilibrium zone: - DR < 1 (perpTVL too high): redeem perps to decrease perpTVL - DR > 1 (perpTVL too low): mint perps to increase perpTVL - Rebalance formula: requiredChange = perpTVL × |dr - targetDR| (rolloverVaultTVL unchanged during flash mint/redeem) - Liquidity limits based on swap direction: - underlying->perp: limited by underlying balance - perp->underlying: limited by perp value held - Separate lag factors and percentage limits for each direction - Slippage protection with configurable max swap fee percentage - Keeper-controlled pause functionality Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b91b91d commit dc80b10

10 files changed

Lines changed: 2960 additions & 1340 deletions

File tree

CLAUDE.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
SPOT Protocol is a monorepo for an inflation-resistant store of value backed by AMPL derivatives. It contains smart contracts and subgraph infrastructure across four workspaces.
8+
9+
## Monorepo Structure
10+
11+
- **spot-contracts** - Core SPOT protocol contracts (PerpetualTranche, BondIssuer, RolloverVault, FeePolicy, RouterV2)
12+
- **spot-vaults** - Vault strategies (BillBroker for SPOT-USDC trading)
13+
- **spot-subgraph** - The Graph indexing for SPOT protocol
14+
- **spot-staking-subgraph** - The Graph indexing for SPOT staking
15+
16+
## Common Commands
17+
18+
### All Workspaces (from root)
19+
```bash
20+
yarn install # Install dependencies
21+
yarn workspaces foreach run compile # Compile all contracts
22+
yarn workspaces foreach run test # Run all tests
23+
yarn workspaces foreach run lint # Check linting
24+
yarn workspaces foreach run lint:fix # Fix lint issues
25+
yarn workspaces foreach run coverage # Run coverage
26+
```
27+
28+
### Single Workspace (from spot-contracts or spot-vaults)
29+
```bash
30+
yarn compile # Compile contracts
31+
yarn test # Run all tests
32+
yarn test test/RouterV2.ts # Run single test file
33+
yarn coverage # Code coverage report
34+
yarn lint # Run all linters
35+
yarn lint:fix # Auto-fix lint issues
36+
yarn profile # Tests with gas reporting (REPORT_GAS=true)
37+
```
38+
39+
### Subgraph (from spot-subgraph)
40+
```bash
41+
yarn codegen # Generate GraphQL types
42+
yarn build # Build subgraph
43+
```
44+
45+
## Technology Stack
46+
47+
- **Solidity**: 0.8.20 (spot-contracts), multiple versions 0.7.6-0.8.24 (spot-vaults)
48+
- **Framework**: Hardhat v3.1.0 (spot-contracts), Hardhat v2.24.1 (spot-vaults)
49+
- **Node**: v20+ required
50+
- **Package Manager**: Yarn 3.2.1 with workspaces
51+
- **Testing**: Mocha + Chai + Ethers.js v6
52+
53+
## Code Style
54+
55+
- **Solidity**: 4-space indent, Solhint linting
56+
- **TypeScript**: 2-space indent, ESLint + Prettier
57+
- **Print width**: 120 characters
58+
- **Quotes**: Double quotes
59+
60+
## Key Contract Interfaces
61+
62+
Interfaces in `spot-contracts/contracts/_interfaces/` define the protocol API:
63+
- `IPerpetualTranche.sol` - Core SPOT token interface
64+
- `IBondIssuer.sol` - Bond issuance interface
65+
- `IRolloverVault.sol` - Vault operations interface
66+
- `IFeePolicy.sol` - Fee calculation interface
67+
68+
## Deployment
69+
70+
Deployment tasks are in `/tasks/deploy/` directories. Networks configured: hardhat, ganache, sepolia (testnet), mainnet.
71+
72+
**Mainnet Deployed Contracts:**
73+
- SPOT: 0xC1f33e0cf7e40a67375007104B929E49a581bafE
74+
- Router: 0xCe2878d1f2901EFaF48cd456E586B470C145d1BC
75+
- Bill Broker: 0xA088Aef966CAD7fE0B38e28c2E07590127Ab4ccB
76+
77+
## Environment Variables
78+
79+
Required for deployment/operations (configure in `.env` files):
80+
- `INFURA_SECRET` / `ALCHEMY_SECRET` - RPC endpoints
81+
- `PROD_MNEMONIC` - Deployment wallet
82+
- `ETHERSCAN_API_KEY` - Contract verification
83+
- `REPORT_GAS` - Enable gas reporter
84+
85+
## Licensing
86+
87+
BUSL-1.1 with GPL-3.0-or-later option for interface files and subgraph code.

spot-contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@ethersproject/providers": "^5.6.8",
2727
"@nomicfoundation/hardhat-chai-matchers": "latest",
2828
"@nomicfoundation/hardhat-ethers": "^3.0.0",
29-
"@nomicfoundation/hardhat-verify": "latest",
29+
"@nomicfoundation/hardhat-verify": "^2.0.0",
3030
"@nomiclabs/hardhat-waffle": "^2.0.6",
3131
"@openzeppelin/hardhat-upgrades": "^3.0.4",
3232
"@openzeppelin/upgrades-core": "latest",

0 commit comments

Comments
 (0)