SystemConfig
Manage the configuration of the Layer 2 network, with all configurations stored on L1 and retrieved by L2.
The SystemConfig
contract is designed to manage the configuration settings for an Optimism network. It allows for various system settings to be updated and stored on Layer 1 (L1), which are then utilized by Layer 2 (L2) as part of the derivation of the L2 chain.
import "@stdlib/deploy";
import "@stdlib/ownable";
// Define constants for UpdateType
const BATCHER: Int = 0;
const GAS_CONFIG: Int = 1;
const GAS_LIMIT: Int = 2;
const UNSAFE_BLOCK_SIGNER: Int = 3;
// Define the structure for ResourceConfig
struct ResourceConfig {
maxResourceLimit: Int;
elasticityMultiplier: Int;
baseFeeMaxChangeDenominator: Int;
minimumBaseFee: Int;
systemTxMaxGas: Int;
maximumBaseFee: Int;
}
// Define the structure for Addresses
struct Addresses {
l1CrossDomainMessenger: Address;
l1AbstractionBridge: Address;
l1StandardBridge: Address;
l2OutputOracle: Address;
statePortal: Address;
stateMintableTokenFactory: Address;
}
// Contract SystemConfig
contract SystemConfig with Deployable, Ownable {
version: String;
overhead: Int;
scalar: Int;
batcherHash: Slice;
gasLimit: Int;
resourceConfig: ResourceConfig;
addresses: Addresses;
owner: Address; // Required by Ownable trait
// Storage slots (represented as simplified placeholders)
unsafeBlockSigner: Address;
startBlock: Int;
// Constructor initializes with default values
init() {
self.version = "1.12.0";
self.overhead = 0;
self.scalar = 0;
self.batcherHash = beginCell().storeUint(0, 256).endCell().beginParse(); // Placeholder
self.gasLimit = 100000; // Placeholder
self.resourceConfig = ResourceConfig{
maxResourceLimit: 0,
elasticityMultiplier: 0,
baseFeeMaxChangeDenominator: 0,
minimumBaseFee: 0,
systemTxMaxGas: 0,
maximumBaseFee: 0
};
self.addresses = Addresses{
l1CrossDomainMessenger: myAddress(),
l1AbstractionBridge: myAddress(),
l1StandardBridge: myAddress(),
l2OutputOracle: myAddress(),
statePortal: myAddress(),
stateMintableTokenFactory: myAddress()
};
self.owner = sender(); // Set the contract's owner
self.unsafeBlockSigner = myAddress(); // Default to contract address
self.startBlock = now(); // Use current timestamp as a proxy for block number
}
// Function to check if the contract is paused (Placeholder)
get fun paused(): Bool {
return false;
}
// Function to update configuration (Placeholder for actual implementation)
fun updateConfiguration(updateType: Int, data: Slice) {
// Placeholder logic to update configuration based on type
emit(beginCell().storeUint(updateType, 32).storeSlice(data).endCell());
}
// Function to get the current resource configuration
get fun getResourceConfig(): ResourceConfig {
return self.resourceConfig;
}
// Function to set a new resource configuration
receive("setResourceConfig") {
let newConfig: ResourceConfig = ResourceConfig{
maxResourceLimit: 1,
elasticityMultiplier: 1,
baseFeeMaxChangeDenominator: 1,
minimumBaseFee: 1,
systemTxMaxGas: 1,
maximumBaseFee: 1
};
self.resourceConfig = newConfig;
emit(beginCell().storeUint(1, 32).endCell()); // Simulated update event
}
// Function to get the start block
get fun getStartBlock(): Int {
return self.startBlock;
}
// Function to set the start block (illustrative)
fun setStartBlock(newStartBlock: Int) {
self.startBlock = newStartBlock;
}
}
Last updated