233 lines
5.1 KiB
Markdown
233 lines
5.1 KiB
Markdown
|
|
# Deployment Guide
|
||
|
|
|
||
|
|
## Prerequisites
|
||
|
|
|
||
|
|
1. **Node.js** >= 18.0.0
|
||
|
|
2. **Foundry** (Forge) installed
|
||
|
|
3. **Environment variables** configured
|
||
|
|
4. **Testnet tokens** for testing
|
||
|
|
|
||
|
|
## Environment Setup
|
||
|
|
|
||
|
|
### 1. Install Dependencies
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Install Node.js dependencies
|
||
|
|
npm install
|
||
|
|
|
||
|
|
# Install Foundry dependencies
|
||
|
|
forge install
|
||
|
|
```
|
||
|
|
|
||
|
|
### 2. Configure Environment
|
||
|
|
|
||
|
|
Create `.env` file:
|
||
|
|
|
||
|
|
```env
|
||
|
|
# RPC URLs
|
||
|
|
RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
|
||
|
|
TESTNET_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
|
||
|
|
|
||
|
|
# Private Keys
|
||
|
|
PRIVATE_KEY=your_private_key_here
|
||
|
|
MULTISIG_ADDRESS=your_multisig_address
|
||
|
|
|
||
|
|
# Contract Addresses (will be filled after deployment)
|
||
|
|
VAULT_ADDRESS=
|
||
|
|
KERNEL_ADDRESS=
|
||
|
|
FLASH_ROUTER_ADDRESS=
|
||
|
|
CONFIG_REGISTRY_ADDRESS=
|
||
|
|
POLICY_ENGINE_ADDRESS=
|
||
|
|
GOVERNANCE_GUARD_ADDRESS=
|
||
|
|
ORACLE_ADAPTER_ADDRESS=
|
||
|
|
COLLATERAL_MANAGER_ADDRESS=
|
||
|
|
|
||
|
|
# Protocol Addresses (Mainnet)
|
||
|
|
AAVE_POOL_ADDRESS=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
|
||
|
|
UNISWAP_ROUTER_ADDRESS=0xE592427A0AEce92De3Edee1F18E0157C05861564
|
||
|
|
BALANCER_VAULT_ADDRESS=0xBA12222222228d8Ba445958a75a0704d566BF2C8
|
||
|
|
DAI_FLASH_MINT_ADDRESS=0x1EB4CF3A948E7D72A198fe073cCb8C7a948cD853
|
||
|
|
|
||
|
|
# Chainlink Feeds
|
||
|
|
CHAINLINK_WETH_USD=0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
|
||
|
|
CHAINLINK_WBTC_USD=0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c
|
||
|
|
```
|
||
|
|
|
||
|
|
## Deployment Order
|
||
|
|
|
||
|
|
Deploy contracts in this order (respects dependencies):
|
||
|
|
|
||
|
|
### Step 1: Oracle Adapter
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployOracleAdapter --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 2: Config Registry
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployConfigRegistry --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 3: Policy Modules
|
||
|
|
|
||
|
|
Deploy all 4 policy modules:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployPolicyHFTrend --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
forge script scripts/deploy.ts:DeployPolicyFlashVolume --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
forge script scripts/deploy.ts:DeployPolicyLiquiditySpread --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
forge script scripts/deploy.ts:DeployPolicyProviderConcentration --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 4: Policy Engine
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployPolicyEngine --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 5: Vault
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployVault --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 6: Flash Router
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployFlashRouter --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 7: Collateral Manager
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployCollateralManager --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 8: Governance Guard
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployGovernanceGuard --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Step 9: Kernel
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge script scripts/deploy.ts:DeployKernel --rpc-url $TESTNET_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
## Configuration
|
||
|
|
|
||
|
|
After deployment, configure all contracts:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
tsx scripts/configure.ts
|
||
|
|
```
|
||
|
|
|
||
|
|
This script will:
|
||
|
|
1. Set Config Registry parameters
|
||
|
|
2. Register policy modules with Policy Engine
|
||
|
|
3. Configure Oracle Adapter with price feeds
|
||
|
|
4. Grant roles (Kernel, Operator)
|
||
|
|
5. Set allowed assets
|
||
|
|
6. Configure provider caps
|
||
|
|
|
||
|
|
## Verification
|
||
|
|
|
||
|
|
### 1. Verify Contracts on Etherscan
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge verify-contract --chain-id 1 --num-of-optimizations 200 \
|
||
|
|
--compiler-version v0.8.24 \
|
||
|
|
CONTRACT_ADDRESS CONTRACT_NAME \
|
||
|
|
--constructor-args $(cast abi-encode "constructor(...)" ARG1 ARG2 ...)
|
||
|
|
```
|
||
|
|
|
||
|
|
### 2. Run Tests
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Unit tests
|
||
|
|
forge test
|
||
|
|
|
||
|
|
# Fork tests (on mainnet fork)
|
||
|
|
forge test --fork-url $RPC_URL
|
||
|
|
|
||
|
|
# Coverage
|
||
|
|
forge coverage
|
||
|
|
```
|
||
|
|
|
||
|
|
### 3. Run Simulations
|
||
|
|
|
||
|
|
```bash
|
||
|
|
tsx scripts/simulate.ts
|
||
|
|
```
|
||
|
|
|
||
|
|
## Multi-Chain Deployment
|
||
|
|
|
||
|
|
### Arbitrum
|
||
|
|
|
||
|
|
```bash
|
||
|
|
export ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
|
||
|
|
forge script scripts/deploy.ts --rpc-url $ARBITRUM_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
### Polygon
|
||
|
|
|
||
|
|
```bash
|
||
|
|
export POLYGON_RPC_URL=https://polygon-rpc.com
|
||
|
|
forge script scripts/deploy.ts --rpc-url $POLYGON_RPC_URL --broadcast
|
||
|
|
```
|
||
|
|
|
||
|
|
Update protocol addresses for each chain in `.env`.
|
||
|
|
|
||
|
|
## Mainnet Deployment Checklist
|
||
|
|
|
||
|
|
- [ ] All contracts tested on testnet
|
||
|
|
- [ ] All parameters verified
|
||
|
|
- [ ] Multi-sig wallet configured
|
||
|
|
- [ ] Emergency pause mechanism ready
|
||
|
|
- [ ] Monitoring dashboard setup
|
||
|
|
- [ ] Alert system configured
|
||
|
|
- [ ] Documentation reviewed
|
||
|
|
- [ ] Security audit completed (if applicable)
|
||
|
|
- [ ] Gas optimization verified
|
||
|
|
- [ ] Backup deployment scripts ready
|
||
|
|
|
||
|
|
## Post-Deployment
|
||
|
|
|
||
|
|
1. **Monitor closely** for first 24-48 hours
|
||
|
|
2. **Start with conservative parameters**
|
||
|
|
3. **Gradually increase limits** after stability
|
||
|
|
4. **Enable MEV bot** after verification
|
||
|
|
5. **Set up alerts** for all critical metrics
|
||
|
|
|
||
|
|
## Emergency Procedures
|
||
|
|
|
||
|
|
### Pause System
|
||
|
|
```bash
|
||
|
|
# Call pause on all contracts
|
||
|
|
cast send $VAULT_ADDRESS "pause()" --private-key $PRIVATE_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
### Upgrade Contracts
|
||
|
|
```bash
|
||
|
|
# Upgrade via UUPS proxy
|
||
|
|
cast send $PROXY_ADDRESS "upgradeTo(address)" $NEW_IMPL_ADDRESS --private-key $PRIVATE_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
### Update Parameters
|
||
|
|
```bash
|
||
|
|
# Reduce limits immediately
|
||
|
|
cast send $CONFIG_REGISTRY_ADDRESS "setMaxLoops(uint256)" 1 --private-key $PRIVATE_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
## Monitoring
|
||
|
|
|
||
|
|
Set up monitoring for:
|
||
|
|
- Position health factors
|
||
|
|
- Flash loan execution rates
|
||
|
|
- Policy denial rates
|
||
|
|
- Gas costs
|
||
|
|
- Contract events
|
||
|
|
|