-
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.
feat(protocol): improve TaikoToken, BridgedERC20, and ERC20Vault (#16950
) Co-authored-by: d1onys1us <[email protected]> Co-authored-by: d1onys1us <[email protected]> Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
4b4a502
commit 97a328e
Showing
32 changed files
with
9,337 additions
and
11,508 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ on: | |
jobs: | ||
build: | ||
runs-on: [taiko-runner] | ||
permissions: | ||
# Give the necessary permissions for stefanzweifel/git-auto-commit-action. | ||
contents: write | ||
steps: | ||
- name: Cancel previous runs | ||
uses: styfle/[email protected] | ||
|
@@ -35,34 +38,32 @@ jobs: | |
working-directory: ./packages/protocol | ||
run: forge fmt --check | ||
|
||
- name: Unit Tests | ||
- name: Unit tests | ||
working-directory: ./packages/protocol | ||
run: pnpm clean && pnpm test | ||
|
||
- name: Generate Genesis | ||
- name: Generate contract layout table | ||
working-directory: ./packages/protocol | ||
run: pnpm test:genesis | ||
run: pnpm layout | ||
|
||
- name: Commit contract layout table | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: "Add contract layout table" | ||
|
||
# TODO: CompilerError: Stack too deep | ||
# - name: Test Coverage | ||
# working-directory: ./packages/protocol | ||
# run: pnpm test:coverage | ||
- name: Generate genesis | ||
working-directory: ./packages/protocol | ||
run: pnpm test:genesis | ||
|
||
- name: Run snapshot (foundry) | ||
- name: Run snapshot (Foundry) | ||
working-directory: ./packages/protocol | ||
run: pnpm snapshot | ||
|
||
- name: Deploy L1 Contracts | ||
- name: Deploy L1 contracts | ||
working-directory: ./packages/protocol | ||
run: | | ||
anvil --hardfork cancun & | ||
while ! nc -z localhost 8545; do | ||
sleep 1 | ||
done | ||
pnpm test:deploy | ||
# - name: Upload coverage to Codecov | ||
# uses: codecov/codecov-action@v3 | ||
# with: | ||
# directory: ./packages/protocol/coverage | ||
# flags: protocol |
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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
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,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "../tokenvault/IBridgedERC20.sol"; | ||
import "./TaikoTokenBase.sol"; | ||
|
||
/// @title BridgedTaikoToken | ||
/// @notice The TaikoToken on L2 to support checkpoints and voting. For testnets, we do not need to | ||
/// use this contract. | ||
/// @custom:security-contact [email protected] | ||
contract BridgedTaikoToken is TaikoTokenBase, IBridgedERC20 { | ||
/// @notice Initializes the contract. | ||
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero. | ||
/// @param _addressManager The address manager address. | ||
function init(address _owner, address _addressManager) external initializer { | ||
__Essential_init(_owner, _addressManager); | ||
__ERC20_init("Taiko Token", "TKO"); | ||
__ERC20Votes_init(); | ||
__ERC20Permit_init("Taiko Token"); | ||
} | ||
|
||
function mint( | ||
address _account, | ||
uint256 _amount | ||
) | ||
external | ||
override | ||
whenNotPaused | ||
onlyFromOwnerOrNamed(LibStrings.B_ERC20_VAULT) | ||
nonReentrant | ||
{ | ||
_mint(_account, _amount); | ||
} | ||
|
||
function burn(uint256 _amount) | ||
external | ||
override | ||
whenNotPaused | ||
onlyFromOwnerOrNamed(LibStrings.B_ERC20_VAULT) | ||
nonReentrant | ||
{ | ||
_burn(msg.sender, _amount); | ||
} | ||
|
||
function owner() public view override(IBridgedERC20, OwnableUpgradeable) returns (address) { | ||
return OwnableUpgradeable.owner(); | ||
} | ||
|
||
/// @notice Gets the canonical token's address and chain ID. | ||
/// @return The canonical token's address. | ||
/// @return The canonical token's chain ID. | ||
function canonical() public pure returns (address, uint256) { | ||
// 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800 is the TKO's mainnet address, | ||
// 1 is the Ethereum's network id. | ||
return (0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800, 1); | ||
} | ||
|
||
function changeMigrationStatus(address, bool) public pure notImplemented { } | ||
} |
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,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "./TaikoTokenBase.sol"; | ||
|
||
/// @title TaikoToken | ||
/// @notice The TaikoToken (TKO), in the protocol is used for prover collateral | ||
/// in the form of bonds. It is an ERC20 token with 18 decimal places of precision. | ||
/// @dev Labeled in AddressResolver as "taiko_token" | ||
/// @dev On Ethereum, this contract is deployed behind a proxy at | ||
/// 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800 (token.taiko.eth) | ||
/// @custom:security-contact [email protected] | ||
contract TaikoToken is TaikoTokenBase { | ||
/// @notice Initializes the contract. | ||
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero. | ||
/// @param _recipient The address to receive initial token minting. | ||
function init(address _owner, address _recipient) public initializer { | ||
__Essential_init(_owner); | ||
__ERC20_init("Taiko Token", "TKO"); | ||
__ERC20Votes_init(); | ||
__ERC20Permit_init("Taiko Token"); | ||
// Mint 1 billion tokens | ||
_mint(_recipient, 1_000_000_000 ether); | ||
} | ||
} |
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,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; | ||
import "../common/EssentialContract.sol"; | ||
import "../common/LibStrings.sol"; | ||
|
||
/// @notice TaikoToken was `EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`. | ||
/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent | ||
/// contract list. | ||
/// We can simplify the code since we no longer need to maintain upgradability with Hekla. | ||
abstract contract TaikoTokenBase0 is EssentialContract { | ||
// solhint-disable var-name-mixedcase | ||
uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable; | ||
} | ||
|
||
/// @title TaikoTokenBase | ||
/// @notice The base contract for both the canonical and the bridged Taiko token. | ||
/// @custom:security-contact [email protected] | ||
abstract contract TaikoTokenBase is TaikoTokenBase0, ERC20VotesUpgradeable { | ||
uint256[50] private __gap; | ||
|
||
function clock() public view override returns (uint48) { | ||
return SafeCastUpgradeable.toUint48(block.timestamp); | ||
} | ||
|
||
// solhint-disable-next-line func-name-mixedcase | ||
function CLOCK_MODE() public pure override returns (string memory) { | ||
// See https://eips.ethereum.org/EIPS/eip-6372 | ||
return "mode=timestamp"; | ||
} | ||
} |
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
Oops, something went wrong.