Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bindings/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ bindings: \
morph-standard-erc20-factory-bindings \
morph-wrapped-ether-bindings \
erc20-bindings \
l2-wst-eth-bindings
l2-wst-eth-bindings \
l2-token-registry-bindings
version:
forge --version
abigen --version
Expand Down Expand Up @@ -118,6 +119,8 @@ l2-to-l1-message-passer-bindings: compile
./gen_bindings.sh contracts/l2/system/L2ToL1MessagePasser.sol:L2ToL1MessagePasser $(pkg)
l2-tx-fee-vault-bindings: compile
./gen_bindings.sh contracts/l2/system/L2TxFeeVault.sol:L2TxFeeVault $(pkg)
l2-token-registry-bindings: compile
./gen_bindings.sh contracts/l2/system/L2TokenRegistry.sol:L2TokenRegistry $(pkg)

# Staking
l2-gov-bindings: compile
Expand Down Expand Up @@ -191,7 +194,7 @@ more: compile-forge
go run ./gen/main.go \
-artifacts ../contracts/artifacts \
-out ./bindings \
-contracts ProxyAdmin,TransparentUpgradeableProxy,L1MessageQueueWithGasPriceOracle,L1USDCGateway,L1Staking,L1CrossDomainMessenger,L1StandardERC20Gateway,L1ETHGateway,L1ERC20Gateway,L1GatewayRouter,L1WETHGateway,L1LidoGateway,Rollup,MultipleVersionRollupVerifier,L2CrossDomainMessenger,GasPriceOracle,L2ToL1MessagePasser,L2TxFeeVault,Sequencer,Gov,Distribute,L2Staking,Record,L2ETHGateway,L2StandardERC20Gateway,L2GatewayRouter,L2WETHGateway,L2ERC20Gateway,L2ERC721Gateway,L2ERC1155Gateway,L2LidoGateway,MorphToken,MorphStandardERC20,MorphStandardERC20Factory,WrappedEther,L2USDCGateway,EnforcedTxGateway,L1ERC721Gateway,L1ERC1155Gateway,L1ReverseCustomGateway,L2WithdrawLockERC20Gateway,L2ReverseCustomGateway,Whitelist,ZkEvmVerifierV1,L2WstETHToken \
-contracts ProxyAdmin,TransparentUpgradeableProxy,L2TokenRegistry,L1MessageQueueWithGasPriceOracle,L1USDCGateway,L1Staking,L1CrossDomainMessenger,L1StandardERC20Gateway,L1ETHGateway,L1ERC20Gateway,L1GatewayRouter,L1WETHGateway,L1LidoGateway,Rollup,MultipleVersionRollupVerifier,L2CrossDomainMessenger,GasPriceOracle,L2ToL1MessagePasser,L2TxFeeVault,Sequencer,Gov,Distribute,L2Staking,Record,L2ETHGateway,L2StandardERC20Gateway,L2GatewayRouter,L2WETHGateway,L2ERC20Gateway,L2ERC721Gateway,L2ERC1155Gateway,L2LidoGateway,MorphToken,MorphStandardERC20,MorphStandardERC20Factory,WrappedEther,L2USDCGateway,EnforcedTxGateway,L1ERC721Gateway,L1ERC1155Gateway,L1ReverseCustomGateway,L2WithdrawLockERC20Gateway,L2ReverseCustomGateway,Whitelist,ZkEvmVerifierV1,L2WstETHToken \
-package bindings

mkdir:
Expand Down
2 changes: 1 addition & 1 deletion bindings/bin/l2staking_deployed.hex

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bindings/bin/l2tokenregistry_deployed.hex

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bindings/bindings/l2staking.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/l2staking_more.go

Large diffs are not rendered by default.

2,458 changes: 2,458 additions & 0 deletions bindings/bindings/l2tokenregistry.go

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions bindings/bindings/l2tokenregistry_more.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions bindings/predeploys/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
L2ReverseCustomGateway = "0x5300000000000000000000000000000000000018"
L2WithdrawLockERC20Gateway = "0x5300000000000000000000000000000000000019"
L2USDCGateway = "0x5300000000000000000000000000000000000020"
L2TokenRegistry = "0x5300000000000000000000000000000000000021"
)

var (
Expand Down Expand Up @@ -56,6 +57,7 @@ var (
L2ReverseCustomGatewayAddr = common.HexToAddress(L2ReverseCustomGateway)
L2WithdrawLockERC20GatewayAddr = common.HexToAddress(L2WithdrawLockERC20Gateway)
L2USDCGatewayAddr = common.HexToAddress(L2USDCGateway)
L2TokenRegistryAddr = common.HexToAddress(L2TokenRegistry)

Predeploys = make(map[string]*common.Address)
)
Expand Down Expand Up @@ -85,4 +87,5 @@ func init() {
Predeploys["L2ReverseCustomGateway"] = &L2ReverseCustomGatewayAddr
Predeploys["L2WithdrawLockERC20Gateway"] = &L2WithdrawLockERC20GatewayAddr
Predeploys["L2USDCGateway"] = &L2USDCGatewayAddr
Predeploys["L2TokenRegistry"] = &L2TokenRegistryAddr
}
210 changes: 210 additions & 0 deletions contracts/contracts/l2/system/IL2TokenRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;

/**
* @title IL2TokenRegistry
* @dev Interface for L2TokenRegistry contract
* @notice Interface defining all external functions for ERC20 price oracle and token registry
*/
interface IL2TokenRegistry {
/*//////////////////////////////////////////////////////////////
Structs
//////////////////////////////////////////////////////////////*/

/// @notice Token information structure
struct TokenInfo {
address tokenAddress; // ERC20 token contract address
bytes32 balanceSlot; // Token balance storage slot, bytes32(0) -> nil
bool isActive; // Whether the token is active
uint8 decimals; // Token decimals
uint256 scale; // Core convention: rateScaled = tokenScale * (tokenPrice / ethPrice) * 10^(ethDecimals - tokenDecimals)
}

/*//////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////*/

event TokenRegistered(
uint16 indexed tokenID,
address indexed tokenAddress,
bytes32 balanceSlot,
bool isActive,
uint8 decimals,
uint256 scale
);
event TokensRegistered(uint16[] tokenIDs, address[] tokenAddresses);
event TokenInfoUpdated(
uint16 indexed tokenID,
address indexed tokenAddress,
bytes32 balanceSlot,
bool isActive,
uint8 decimals,
uint256 scale
);
event TokenActivated(uint16 indexed tokenID);
event TokenDeactivated(uint16 indexed tokenID);
event PriceRatioUpdated(uint16 indexed tokenID, uint256 newPrice);
event TokenScaleUpdated(uint16 indexed tokenID, uint256 newScale);
event AllowListSet(address indexed user, bool val);
event AllowListEnabledUpdated(bool isEnabled);

/*//////////////////////////////////////////////////////////////
Errors
//////////////////////////////////////////////////////////////*/

error TokenAlreadyRegistered();
error TokenNotFound();
error InvalidTokenID();
error InvalidTokenAddress();
error InvalidPrice();
error InvalidPercent();
error CallerNotAllowed();
error InvalidArrayLength();
error DifferentLength();
error AlreadyInitialized();

/*//////////////////////////////////////////////////////////////
Allow List Functions
//////////////////////////////////////////////////////////////*/

/**
* @notice Set Allow List
* @param user Array of user addresses
* @param val Array of permission values
*/
function setAllowList(address[] memory user, bool[] memory val) external;

/**
* @notice Set whether Allow List is enabled
* @param _allowListEnabled Whether to enable
*/
function setAllowListEnabled(bool _allowListEnabled) external;

/*//////////////////////////////////////////////////////////////
Token Registration Functions
//////////////////////////////////////////////////////////////*/

/**
* @notice Batch register tokens
* @param _tokenIDs Array of token IDs
* @param _tokenAddresses Array of token addresses
* @param _balanceSlots Array of balance storage slots
* @param _scales Array of scale values
*/
function registerTokens(
uint16[] memory _tokenIDs,
address[] memory _tokenAddresses,
bytes32[] memory _balanceSlots,
uint256[] memory _scales
) external;

/**
* @notice Register a single token
* @param _tokenID Token ID
* @param _tokenAddress Token contract address
* @param _balanceSlot Balance storage slot
* @param _scale Scale value
*/
function registerToken(uint16 _tokenID, address _tokenAddress, bytes32 _balanceSlot, uint256 _scale) external;

/**
* @notice Update token information
* @param _tokenID Token ID
* @param _tokenAddress New token contract address
* @param _balanceSlot New balance storage slot
* @param _isActive Whether to activate
* @param _scale Scale value
*/
function updateTokenInfo(
uint16 _tokenID,
address _tokenAddress,
bytes32 _balanceSlot,
bool _isActive,
uint256 _scale
) external;

/**
* @notice Batch update token activation status
* @param _tokenIDs Array of token IDs
* @param _isActives Array of activation statuses
*/
function batchUpdateTokenStatus(uint16[] memory _tokenIDs, bool[] memory _isActives) external;

/*//////////////////////////////////////////////////////////////
Price Management Functions
//////////////////////////////////////////////////////////////*/

/**
* @notice Update price ratio
* @param _tokenID Token ID
* @param _newPrice New price ratio (relative to ETH)
* @dev priceRatio should follow: priceRatio = tokenScale * (tokenPrice / ethPrice) * 10^(ethDecimals - tokenDecimals)
*/
function updatePriceRatio(uint16 _tokenID, uint256 _newPrice) external;

/**
* @notice Batch update price ratios
* @param _tokenIDs Array of token IDs
* @param _prices Array of price ratios
*/
function batchUpdatePrices(uint16[] memory _tokenIDs, uint256[] memory _prices) external;

/**
* @notice Get token price
* @param _tokenID Token ID
* @return price Price ratio
*/
function getTokenPrice(uint16 _tokenID) external view returns (uint256);

/**
* @notice Calculate the corresponding token amount for a given ETH amount
* @param _tokenID Token ID of the ERC20 token
* @param _ethAmount ETH amount (unit: wei)
* @return tokenAmount Corresponding token amount (unit: token's smallest unit)
*/
function calculateTokenAmount(uint16 _tokenID, uint256 _ethAmount) external view returns (uint256 tokenAmount);

/**
* @notice Get token information
* @param _tokenID Token ID
* @return TokenInfo structure
*/
function getTokenInfo(uint16 _tokenID) external view returns (TokenInfo memory);

/**
* @notice Get token ID by address
* @param tokenAddress Token address
* @return tokenID Token ID
*/
function getTokenIdByAddress(address tokenAddress) external view returns (uint16);

/*//////////////////////////////////////////////////////////////
Scale Management Functions
//////////////////////////////////////////////////////////////*/

/**
* @notice Update token scale
* @param _tokenID Token ID
* @param _newScale New scale value
*/
function updateTokenScale(uint16 _tokenID, uint256 _newScale) external;

/**
* @notice Get token scale
* @param _tokenID Token ID
* @return scale Token scale value
*/
function getTokenScale(uint16 _tokenID) external view returns (uint256);

/*//////////////////////////////////////////////////////////////
View Functions
//////////////////////////////////////////////////////////////*/

/**
* @notice Check if token is active
* @param _tokenID Token ID
* @return Whether the token is active
*/
function isTokenActive(uint16 _tokenID) external view returns (bool);
}

Loading
Loading