-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat: add shared lockbox spec #465
base: main
Are you sure you want to change the base?
Changes from all commits
f9ef0fc
46aaed0
b25ed80
1fa11bc
7ed9e1c
688c2ad
10cfcf2
87fadfa
d7c8d15
594ff64
d82bedd
eb01368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# OptimismPortal Interop | ||
|
||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** | ||
|
||
- [Overview](#overview) | ||
- [Integrating `SharedLockbox`](#integrating-sharedlockbox) | ||
- [Interface and properties](#interface-and-properties) | ||
- [ETH Management](#eth-management) | ||
- [`migrateLiquidity`](#migrateliquidity) | ||
- [Internal ETH Functions](#internal-eth-functions) | ||
- [`_lockETH`](#_locketh) | ||
- [`_unlockETH`](#_unlocketh) | ||
- [Events](#events) | ||
- [`ETHMigrated`](#ethmigrated) | ||
- [Invariants](#invariants) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Overview | ||
|
||
The `OptimismPortal` contract is extended to integrate with the `SharedLockbox` | ||
for managing unified ETH liquidity. | ||
This liquidity consists of every ETH balance migrated from each `OptimismPortal` when joining | ||
the op-governed dependency set. | ||
|
||
It is possible to upgrade to this version without being part of the op-governed dependency set. In this case, | ||
the corresponding chain would need to deploy and manage its own `SharedLockbox` and `SuperchainConfig`. | ||
|
||
### Integrating `SharedLockbox` | ||
|
||
The integration with the `SharedLockbox` involves locking ETH when executing deposit transactions and unlocking ETH | ||
when finalizing withdrawal transactions, without altering other aspects of the current `OptimismPortal` implementation. | ||
|
||
## Interface and properties | ||
|
||
### ETH Management | ||
|
||
#### `migrateLiquidity` | ||
|
||
Migrates the ETH liquidity to the SharedLockbox. This function will only be called once by the | ||
SuperchainConfig when adding this chain to the dependency set. | ||
|
||
```solidity | ||
function migrateLiquidity() external; | ||
``` | ||
|
||
- MUST only be callable by the `SuperchainConfig` contract | ||
- MUST set the migrated flag to true | ||
- MUST transfer all ETH balance to the `SharedLockbox` | ||
- MUST emit an `ETHMigrated` event with the amount transferred | ||
|
||
### Internal ETH Functions | ||
|
||
The contract overrides two internal functions from `OptimismPortal2` to handle ETH management with the `SharedLockbox`: | ||
|
||
#### `_lockETH` | ||
|
||
Called during deposit transactions to handle ETH locking. | ||
|
||
```solidity | ||
function _lockETH() internal virtual override; | ||
``` | ||
|
||
- MUST be called during `depositTransaction` when there is ETH value | ||
- If not migrated, function is a no-op | ||
- If migrated: | ||
- MUST lock any ETH value in the `SharedLockbox` | ||
- MUST NOT revert on zero value | ||
|
||
#### `_unlockETH` | ||
|
||
Called during withdrawal finalization to handle ETH unlocking. | ||
|
||
```solidity | ||
function _unlockETH(Types.WithdrawalTransaction memory _tx) internal virtual override; | ||
``` | ||
|
||
- MUST be called during withdrawal finalization when there is ETH value | ||
- If not migrated, function is a no-op | ||
- If migrated: | ||
- MUST unlock the withdrawal value from the `SharedLockbox` | ||
- MUST NOT revert on zero value | ||
- MUST revert if withdrawal target is the `SharedLockbox` | ||
|
||
## Events | ||
|
||
### `ETHMigrated` | ||
|
||
MUST be triggered when the ETH liquidity is migrated to the SharedLockbox. | ||
|
||
```solidity | ||
event ETHMigrated(uint256 amount); | ||
``` | ||
|
||
## Invariants | ||
|
||
- Before migration: | ||
|
||
- Deposits MUST keep the ETH in the portal | ||
|
||
- Withdrawals MUST use the portal's own ETH balance | ||
|
||
- After migration: | ||
|
||
- Deposits MUST lock the ETH in the `SharedLockbox` | ||
|
||
- Withdrawals MUST unlock the ETH from the `SharedLockbox` and forward it to the withdrawal target | ||
|
||
- The contract MUST NOT hold any ETH balance from deposits or withdrawals | ||
|
||
- General invariants: | ||
|
||
- The contract MUST be able to handle zero ETH value operations | ||
|
||
- The contract MUST NOT allow withdrawals to target the `SharedLockbox` address | ||
|
||
- The contract MUST only migrate liquidity once |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Shared Lockbox - Upgrade and migration process | ||
|
||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** | ||
|
||
- [Overview](#overview) | ||
- [Upgrade Process](#upgrade-process) | ||
- [ETH Migration](#eth-migration) | ||
- [Diagram](#diagram) | ||
- [Future Considerations / Additional Notes](#future-considerations--additional-notes) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Overview | ||
|
||
When a new chain joins the op-governed dependency set, it must integrate with the `SharedLockbox` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should distinguish what op-governed means here, and realistically just say "Superchain" unless we want to mention other interop dependency sets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I believe this should be common for every cluster so maybe finding a more general definition could be better |
||
to participate in unified ETH liquidity management. This process is initiated by the `CLUSTER_MANAGER` role. | ||
|
||
## Upgrade Process | ||
|
||
1. The `CLUSTER_MANAGER` role calls `addDependency` on the `SuperchainConfig` | ||
contract with the new chain ID and it's system config address | ||
|
||
2. The `SuperchainConfig` processes the addition by: | ||
|
||
- Validating the request came from the cluster manager | ||
- Verifying the chain ID isn't already in the dependency set | ||
- Adding the chain ID to the dependency set | ||
- Getting the chain's portal address from its `SystemConfig` | ||
|
||
3. The portal is authorized in the `SharedLockbox`: | ||
|
||
- Verifying the portal uses the correct `SuperchainConfig` | ||
- Checking the portal isn't already authorized | ||
- Adding the portal to the authorized portals mapping | ||
- Triggering ETH migration via `migrateLiquidity()` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be very explicit here that this is the step where the eth actually changes hands |
||
- In this step the `OptimismPortal`'s ETH balance is transferred to the `SharedLockbox` | ||
|
||
4. The `OptimismPortal` migrates its ETH: | ||
- Sets migrated flag to true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would include the second order effect of why this matters |
||
- This is necessary to start using the `SharedLockbox` for ETH operations, | ||
if not set the `OptimismPortal` will continue using it's own ETH balance. | ||
- Transfers entire ETH balance to `SharedLockbox` via `lockETH()` | ||
- `SharedLockbox` emits `ETHLocked` event | ||
- Portal emits `ETHMigrated` event | ||
|
||
### ETH Migration | ||
|
||
After authorization, the `OptimismPortal`'s ETH liquidity is migrated to the `SharedLockbox`: | ||
|
||
1. The `OptimismPortal`'s ETH balance is transferred to the `SharedLockbox` | ||
2. The `OptimismPortal` is configured to use the `SharedLockbox` for all future ETH operations | ||
|
||
After migration: | ||
|
||
- All deposits lock ETH in the `SharedLockbox` | ||
- All withdrawals unlock ETH from the `SharedLockbox` | ||
- The `OptimismPortal` no longer holds ETH directly | ||
|
||
## Diagram | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant ClusterManager | ||
participant Config as SuperchainConfig | ||
participant Portal as OptimismPortal | ||
participant Lockbox as SharedLockbox | ||
|
||
ClusterManager->>Config: addDependency(chainId, systemConfig) | ||
Config->>Config: validate & add to set | ||
Config->>Config: authorize portal | ||
Config->>Portal: migrateLiquidity() | ||
Portal->>Lockbox: lockETH(balance) | ||
Lockbox->>Config: authorizedPortals(portal) | ||
Lockbox-->>Lockbox: emits ETHLocked | ||
Portal-->>Portal: emits ETHMigrated | ||
Config-->>Config: emits DependencyAdded | ||
``` | ||
|
||
## Future Considerations / Additional Notes | ||
|
||
- Before calling `addDependency`, it MUST be ensured that the `chainId` and `systemConfig` match. | ||
This means that the `systemConfig` address is the correct one for the chain ID. There is no on-chain source of truth | ||
for this information, so it is the responsibility of the `CLUSTER_MANAGER` to ensure the correct parameters are used. | ||
|
||
- The `OptimismPortal` MUST be updated before initiating the migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be clear that its possible to upgrade to this hardfork and not be part of a cluster. The requirement would be that a chain has its own lockbox