-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(protocol): added cached version of the bridge and vaults (#1…
- Loading branch information
Showing
14 changed files
with
229 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
pragma solidity 0.8.24; | ||
|
||
import "../common/LibStrings.sol"; | ||
import "../libs/LibNetwork.sol"; | ||
|
||
/// @title LibAddressCache | ||
/// @title LibRollupAddressCache | ||
/// @custom:security-contact [email protected] | ||
library LibAddressCache { | ||
library LibRollupAddressCache { | ||
function getAddress( | ||
uint64 _chainId, | ||
bytes32 _name | ||
|
@@ -14,7 +15,7 @@ library LibAddressCache { | |
pure | ||
returns (bool found, address addr) | ||
{ | ||
if (_chainId == 1) { | ||
if (_chainId == LibNetwork.ETHEREUM_MAINNET) { | ||
if (_name == LibStrings.B_TAIKO_TOKEN) { | ||
return (true, 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800); | ||
} | ||
|
69 changes: 69 additions & 0 deletions
69
packages/protocol/contracts/mainnet/LibSharedAddressCache.sol
This file contains 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,69 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../common/LibStrings.sol"; | ||
import "../libs/LibNetwork.sol"; | ||
|
||
/// @title LibSharedAddressCache | ||
/// @custom:security-contact [email protected] | ||
library LibSharedAddressCache { | ||
function getAddress( | ||
uint64 _chainId, | ||
bytes32 _name | ||
) | ||
internal | ||
pure | ||
returns (bool found, address addr) | ||
{ | ||
if (_chainId == LibNetwork.ETHEREUM_MAINNET) { | ||
if (_name == LibStrings.B_TAIKO_TOKEN) { | ||
return (true, 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800); | ||
} | ||
if (_name == LibStrings.B_QUOTA_MANAGER) { | ||
return (true, 0x91f67118DD47d502B1f0C354D0611997B022f29E); | ||
} | ||
if (_name == LibStrings.B_BRIDGE) { | ||
return (true, 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC); | ||
} | ||
if (_name == LibStrings.B_BRIDGED_ERC20) { | ||
return (true, 0x79BC0Aada00fcF6E7AB514Bfeb093b5Fae3653e3); | ||
} | ||
if (_name == LibStrings.B_BRIDGED_ERC721) { | ||
return (true, 0xC3310905E2BC9Cfb198695B75EF3e5B69C6A1Bf7); | ||
} | ||
if (_name == LibStrings.B_BRIDGED_ERC1155) { | ||
return (true, 0x3c90963cFBa436400B0F9C46Aa9224cB379c2c40); | ||
} | ||
if (_name == LibStrings.B_ERC20_VAULT) { | ||
return (true, 0x996282cA11E5DEb6B5D122CC3B9A1FcAAD4415Ab); | ||
} | ||
if (_name == LibStrings.B_ERC721_VAULT) { | ||
return (true, 0x0b470dd3A0e1C41228856Fb319649E7c08f419Aa); | ||
} | ||
if (_name == LibStrings.B_ERC1155_VAULT) { | ||
return (true, 0xaf145913EA4a56BE22E120ED9C24589659881702); | ||
} | ||
if (_name == LibStrings.B_SIGNAL_SERVICE) { | ||
return (true, 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C); | ||
} | ||
} else if (_chainId == LibNetwork.TAIKO_MAINNET) { | ||
if (_name == LibStrings.B_BRIDGE) { | ||
return (true, 0x1670000000000000000000000000000000000001); | ||
} | ||
if (_name == LibStrings.B_ERC20_VAULT) { | ||
return (true, 0x1670000000000000000000000000000000000002); | ||
} | ||
if (_name == LibStrings.B_ERC721_VAULT) { | ||
return (true, 0x1670000000000000000000000000000000000003); | ||
} | ||
if (_name == LibStrings.B_ERC1155_VAULT) { | ||
return (true, 0x1670000000000000000000000000000000000004); | ||
} | ||
if (_name == LibStrings.B_SIGNAL_SERVICE) { | ||
return (true, 0x1670000000000000000000000000000000000005); | ||
} | ||
} | ||
|
||
return (false, address(0)); | ||
} | ||
} |
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../bridge/Bridge.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetBridge | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {Bridge}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetBridge is Bridge { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/protocol/contracts/mainnet/MainnetERC1155Vault.sol
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../tokenvault/ERC1155Vault.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetERC1155Vault | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {ER1155Vault}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetERC1155Vault is ERC1155Vault { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../tokenvault/ERC20Vault.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetERC20Vault | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {ER20Vault}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetERC20Vault is ERC20Vault { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/protocol/contracts/mainnet/MainnetERC721Vault.sol
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../tokenvault/ERC721Vault.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetERC721Vault | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {ER721Vault}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetERC721Vault is ERC721Vault { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -2,14 +2,17 @@ | |
pragma solidity 0.8.24; | ||
|
||
import "../team/proving/ProverSet.sol"; | ||
import "./LibAddressCache.sol"; | ||
import "./LibRollupAddressCache.sol"; | ||
|
||
/// @title MainnetProverSet | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {ProverSet}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetProverSet is ProverSet { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); | ||
(bool found, address addr) = LibRollupAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -3,14 +3,16 @@ pragma solidity 0.8.24; | |
|
||
import "../common/AddressManager.sol"; | ||
import "../common/LibStrings.sol"; | ||
import "./LibAddressCache.sol"; | ||
import "./LibRollupAddressCache.sol"; | ||
|
||
/// @title MainnetRollupAddressManager | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. | ||
/// @notice See the documentation in {IAddressManager}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetRollupAddressManager is AddressManager { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); | ||
(bool found, address addr) = LibRollupAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -3,52 +3,16 @@ pragma solidity 0.8.24; | |
|
||
import "../common/AddressManager.sol"; | ||
import "../common/LibStrings.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetSharedAddressManager | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. | ||
/// @notice See the documentation in {IAddressManager}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetSharedAddressManager is AddressManager { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
if (_chainId == 1) { | ||
if (_name == LibStrings.B_TAIKO_TOKEN) { | ||
return 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800; | ||
} | ||
if (_name == LibStrings.B_QUOTA_MANAGER) { | ||
return 0x91f67118DD47d502B1f0C354D0611997B022f29E; | ||
} | ||
if (_name == LibStrings.B_BRIDGE) { | ||
return 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC; | ||
} | ||
if (_name == LibStrings.B_ERC20_VAULT) { | ||
return 0x996282cA11E5DEb6B5D122CC3B9A1FcAAD4415Ab; | ||
} | ||
if (_name == LibStrings.B_ERC721_VAULT) { | ||
return 0x0b470dd3A0e1C41228856Fb319649E7c08f419Aa; | ||
} | ||
if (_name == LibStrings.B_ERC1155_VAULT) { | ||
return 0xaf145913EA4a56BE22E120ED9C24589659881702; | ||
} | ||
if (_name == LibStrings.B_SIGNAL_SERVICE) { | ||
return 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C; | ||
} | ||
} else if (_chainId == 167_000) { | ||
if (_name == LibStrings.B_BRIDGE) { | ||
return 0x1670000000000000000000000000000000000001; | ||
} | ||
if (_name == LibStrings.B_ERC20_VAULT) { | ||
return 0x1670000000000000000000000000000000000002; | ||
} | ||
if (_name == LibStrings.B_ERC721_VAULT) { | ||
return 0x1670000000000000000000000000000000000003; | ||
} | ||
if (_name == LibStrings.B_ERC1155_VAULT) { | ||
return 0x1670000000000000000000000000000000000004; | ||
} | ||
if (_name == LibStrings.B_SIGNAL_SERVICE) { | ||
return 0x1670000000000000000000000000000000000005; | ||
} | ||
} | ||
|
||
return super._getAddress(_chainId, _name); | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/protocol/contracts/mainnet/MainnetSignalService.sol
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../signal/SignalService.sol"; | ||
import "./LibSharedAddressCache.sol"; | ||
|
||
/// @title MainnetSignalService | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. In theory, the contract can also be deplyed on Taiko L2 but this is | ||
/// not well testee nor necessary. | ||
/// @notice See the documentation in {SignalService}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetSignalService is SignalService { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibSharedAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -2,14 +2,16 @@ | |
pragma solidity 0.8.24; | ||
|
||
import "../L1/TaikoL1.sol"; | ||
import "./LibAddressCache.sol"; | ||
import "./LibRollupAddressCache.sol"; | ||
|
||
/// @title MainnetTaikoL1 | ||
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko | ||
/// mainnet to reduce gas cost. | ||
/// @notice See the documentation in {TaikoL1}. | ||
/// @custom:security-contact [email protected] | ||
contract MainnetTaikoL1 is TaikoL1 { | ||
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { | ||
(bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); | ||
(bool found, address addr) = LibRollupAddressCache.getAddress(_chainId, _name); | ||
return found ? addr : super._getAddress(_chainId, _name); | ||
} | ||
} |
This file contains 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,5 @@ | ||
# Optimized Smart Contracts for Taiko Mainnet | ||
|
||
## Overview | ||
|
||
This directory contains optimized versions of smart contracts for deployment on Ethereum for Taiko mainnet. While some of these contracts may be used on Taiko L2, deployment on Layer 2 is not recommended due to lack of testing. |
Oops, something went wrong.