-
Notifications
You must be signed in to change notification settings - Fork 23
Consolidate chain-specific deployment parameters #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0x1NotMe
wants to merge
3
commits into
main
Choose a base branch
from
consolidate-chain-params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
# Chain Configuration System | ||
|
||
## Overview | ||
|
||
The chain configuration system provides a centralized location for all chain-specific deployment parameters, eliminating hardcoded values scattered across deployment scripts. | ||
|
||
## Architecture | ||
|
||
### ChainConfig Library (`src/contracts/libraries/ChainConfig.sol`) | ||
|
||
A pure Solidity library that stores all chain-specific parameters: | ||
- **Escrow Duration**: Number of blocks for escrow period | ||
- **L2 Gas Calculator**: Address of L2 gas calculator (if needed) | ||
- **Atlas Surcharge Rate**: Fee percentage for Atlas operations (in basis points) | ||
- **Bundler Surcharge Rate**: Fee percentage for bundler operations (in basis points) | ||
|
||
### Supported Chains | ||
|
||
#### Mainnet Chains | ||
| Chain | Chain ID | Escrow Duration | Block Time | L2 Gas Calculator | | ||
|-------|----------|-----------------|------------|-------------------| | ||
| Ethereum | 1 | 64 blocks | ~12s | Not required | | ||
| Polygon | 137 | 64 blocks | ~2s | Not required | | ||
| Optimism | 10 | 16 blocks | ~2s | Required (OP Stack) | | ||
| Base | 8453 | 16 blocks | ~2s | Required (OP Stack) | | ||
| Arbitrum* | 42161 | - | ~250ms | Not supported on main | | ||
| Hyperliquid | 999 | 30 blocks | ~1s | Not required | | ||
| Unichain | 130 | 30 blocks | ~1s | Required (OP Stack) | | ||
| Berachain | 80094 | 15 blocks | ~5s | Not required | | ||
|
||
*Arbitrum requires special handling and is supported on separate branches: `arbitrum/atlas-v1.6.1` or `arbitrum/atlas-v1.7-exp` | ||
|
||
#### Testnet Chains | ||
| Chain | Chain ID | Escrow Duration | Block Time | L2 Gas Calculator | | ||
|-------|----------|-----------------|------------|-------------------| | ||
| Sepolia | 11155111 | 64 blocks | ~12s | Not required | | ||
| Polygon Amoy | 80002 | 64 blocks | ~2s | Not required | | ||
| OP Sepolia | 11155420 | 16 blocks | ~2s | Required (OP Stack) | | ||
| Base Sepolia | 84532 | 16 blocks | ~2s | Required (OP Stack) | | ||
| Arbitrum Sepolia* | 421614 | - | ~250ms | Not supported on main | | ||
| Unichain Sepolia | 1301 | 30 blocks | ~1s | Required (OP Stack) | | ||
| Berachain Bepolia | 80069 | 15 blocks | ~5s | Not required | | ||
|
||
*Arbitrum requires special handling and is supported on separate branches: `arbitrum/atlas-v1.6.1` or `arbitrum/atlas-v1.7-exp` | ||
|
||
## Usage | ||
|
||
### In Deployment Scripts | ||
|
||
```solidity | ||
import { ChainConfig } from "../src/contracts/libraries/ChainConfig.sol"; | ||
|
||
contract DeployAtlasScript is DeployBaseScript { | ||
function run() external { | ||
// Get chain-specific configuration | ||
ChainConfig.ChainParameters memory chainParams = ChainConfig.getChainParameters(block.chainid); | ||
|
||
// Use parameters in deployment | ||
atlas = new Atlas({ | ||
escrowDuration: chainParams.escrowDuration, | ||
atlasSurchargeRate: chainParams.atlasSurchargeRate, | ||
l2GasCalculator: chainParams.l2GasCalculator, | ||
// ... other parameters | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
### Helper Functions | ||
|
||
```solidity | ||
// Get chain name | ||
string memory chainName = ChainConfig.getChainName(block.chainid); | ||
|
||
// Check if L2 gas calculator is required | ||
bool requiresCalc = ChainConfig.requiresL2GasCalculator(block.chainid); | ||
|
||
// Get surcharge rates | ||
ChainConfig.ChainParameters memory params = ChainConfig.getChainParameters(block.chainid); | ||
uint256 atlasSurcharge = params.atlasSurchargeRate; // in basis points (1000 = 10%) | ||
uint256 bundlerSurcharge = params.bundlerSurchargeRate; // in basis points | ||
``` | ||
|
||
## Adding New Chains | ||
|
||
To add support for a new chain: | ||
|
||
1. Add the chain configuration in `ChainConfig.sol`: | ||
```solidity | ||
} else if (chainId == YOUR_CHAIN_ID) { | ||
return ChainParameters({ | ||
escrowDuration: BLOCKS, // Calculate based on block time | ||
l2GasCalculator: address(0), // Or specific address if needed | ||
atlasSurchargeRate: 1000, // 10% default | ||
bundlerSurchargeRate: 1000, // 10% default | ||
name: "YOUR_CHAIN_NAME" | ||
}); | ||
} | ||
``` | ||
|
||
2. Update `requiresL2GasCalculator()` if the chain needs a gas calculator: | ||
```solidity | ||
function requiresL2GasCalculator(uint256 chainId) internal pure returns (bool) { | ||
return chainId == 42161 || chainId == 421614 || // Arbitrum chains | ||
chainId == YOUR_CHAIN_ID; // Add your chain if needed | ||
} | ||
``` | ||
|
||
## Escrow Duration Calculation | ||
|
||
Escrow duration is calculated to achieve approximately 30-35 seconds of real time: | ||
|
||
- **Ethereum/Sepolia**: 64 blocks × 12s = ~768s (adjusted for network conditions) | ||
0x1NotMe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- **Polygon/Amoy**: 64 blocks × 2s = ~128s (adjusted for faster finality) | ||
- **OP Stack (Optimism/Base)**: 16 blocks × 2s = ~32s | ||
0x1NotMe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- **Arbitrum**: 128 blocks × 250ms = ~32s | ||
- **Hyperliquid/Unichain**: 30 blocks × 1s = ~30s | ||
0x1NotMe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- **Berachain**: 15 blocks × 5s = ~75s (Cosmos-based consensus) | ||
0x1NotMe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## L2 Gas Calculator | ||
|
||
L2 Gas Calculator requirements by chain type: | ||
- **OP Stack chains (Base, Optimism, Unichain)**: Require L2 gas calculator for proper gas accounting | ||
- **Automatic Deployment**: The Atlas deployment script automatically deploys an L2 gas calculator if one is required but not configured | ||
- **Manual Deployment** (optional): Can be deployed separately using `script/deploy-gas-calculator-op-stack.s.sol` | ||
- **Arbitrum**: Not supported on main branch - use branches `arbitrum/atlas-v1.6.1` or `arbitrum/atlas-v1.7-exp` | ||
- **Other chains (Ethereum, Polygon, Hyperliquid, Berachain)**: Standard gas calculation, no L2 calculator needed | ||
|
||
## Arbitrum Deployment | ||
|
||
Arbitrum requires special handling due to its unique architecture and is maintained on separate branches: | ||
|
||
### Available Arbitrum Branches | ||
- `arbitrum/atlas-v1.6.1` - Stable version for Arbitrum One and Arbitrum Sepolia | ||
- `arbitrum/atlas-v1.7-exp` - Experimental version with latest features | ||
0x1NotMe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- `arbitrum/atlas-v1.1` - Legacy version (not recommended for new deployments) | ||
- `arbitrum/atlas-v1.0` - Legacy version (not recommended for new deployments) | ||
|
||
### Switching to Arbitrum Branch | ||
```bash | ||
# List available Arbitrum branches | ||
git branch -r | grep arbitrum | ||
|
||
# Checkout the desired Arbitrum branch | ||
git checkout arbitrum/atlas-v1.6.1 | ||
|
||
# Deploy on Arbitrum | ||
forge script script/deploy-atlas.s.sol --chain-id 42161 --broadcast | ||
``` | ||
|
||
If you attempt to deploy on Arbitrum from the main branch, you'll receive an error directing you to use the appropriate Arbitrum branch. | ||
|
||
## Migration from Hardcoded Values | ||
|
||
Previous approach: | ||
```solidity | ||
// In deploy-atlas.s.sol | ||
uint256 ESCROW_DURATION = 128; // Hardcoded | ||
address L2_GAS_CALCULATOR = 0x870584...; // Hardcoded | ||
|
||
// In deploy-base.s.sol | ||
function _getSurchargeRates() internal view returns (...) { | ||
if (chainId == 137) { | ||
atlasSurchargeRate = 500; // Hardcoded | ||
} | ||
} | ||
``` | ||
|
||
New approach: | ||
```solidity | ||
// All configuration in one place | ||
ChainConfig.ChainParameters memory params = ChainConfig.getChainParameters(block.chainid); | ||
// Use params.escrowDuration, params.l2GasCalculator, etc. | ||
``` | ||
|
||
## Testing | ||
|
||
Run the test script to verify configuration: | ||
```bash | ||
forge script script/test-chain-config.s.sol -vv | ||
``` | ||
|
||
This will display all chain configurations and verify the values are correctly set. | ||
|
||
## Benefits | ||
|
||
1. **Single Source of Truth**: All chain parameters in one location | ||
2. **Type Safety**: Compile-time checking prevents errors | ||
3. **Easy Maintenance**: Add new chains or update parameters in one place | ||
4. **Reduced Duplication**: No more hardcoded values across multiple scripts | ||
5. **Better Documentation**: Clear overview of all chain configurations | ||
6. **Testability**: Easy to verify all configurations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.