-
Notifications
You must be signed in to change notification settings - Fork 41
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
Cross-chain Tokenized Threshold BTC: Generic L2 ERC20 implementation #550
Conversation
This is the first step for the implementation of a generic L2/sidechain token contract. The L2/sidechain token will be upgradeable, owned by Threshold Council, will delegate the minting authority to multiple parties, and have a pause functionality for mints and burns. Individual L2/sidechain token implementations will inherit from this contract setting only the token name and symbol. So far, adding and removing minters was implemented. More to come!
solidity/contracts/l2/L2TBTC.sol
Outdated
// * Be paused by any one of `n` guardians, allowing avoidance of contagion in case | ||
// of a chain- or bridge-specific incident. |
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.
@mhluongo Would you like to pause everything or just mints/burns. I assumed mint/burns given the bridges are posing most of the risk. It is not about blocking l2 DEXes, for example.
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.
Just mints and burns
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.
What about ERC20WithPermit, MisfundRecovery
functionality for tokens that will be inheriting from L2TBTC.sol
? Do we want/need to add it?
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 want it! See c710eec.
// Hacky workaround allowing to deploy proxy contract any number of times | ||
// without clearing `deployments/hardhat` directory. | ||
// See: https://github.com/keep-network/hardhat-helpers/issues/38 | ||
`L2TBTC_${randomBytes(8).toString("hex")}`, |
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.
@nkuba Not super proud of it but I had to move forward. May be replaced with a flag if we do keep-network/hardhat-helpers#38.
4.8.1 is the most recent version. In the `main` version of OpenZeppelin, `draft-ERC20PermitUpgradeable` is no longer a draft but this change is not yet present in 4.8.1 version of OpenZeppelin. Once a new version gets released we should update to drop the `draft-` prefix from the import in L2TBTC (see the very next commit). For now, I am updating to the most recent version to be closer to 4.8.2 or 4.9.0 we will be updating to.
Only the functions defined in L2TBTC are fully covered with tests. L2TBTC contract inherits from OpenZeppelin contracts and we do not want to test the framework. The basic tests for functions defined in the OpenZeppelin contracts ensure all expected OpenZeppelin extensions are inherited in L2TBTC contract and that they are properly initialized.
Allow one of the guardians to pause mints and burns allowing avoidance of contagion in case of a chain- or bridge-specific incident.
Added functions allowing the governance to recover any ERC20 or ERC721 sent mistakenly to the contract address.
Renames of some test scenarios plus additional assertions for empty guardian and minter lists.
Closes #543
The contract
L2TBTC
is a canonical L2/sidechain token implementation. tBTC token is minted on L1 and locked there to be moved to L2/sidechain. By deploying a canonical token on each L2/sidechain, we can ensure the supply of tBTC remains sacrosanct, while enabling quick, interoperable cross-chain bridges and localizing ecosystem risk.This contract is flexible enough to:
The token is burnable by the token holder and supports EIP2612 permits. Token holder can authorize a transfer of their token with a signature conforming EIP712 standard instead of an on-chain transaction from their address. Anyone can submit this signature on the user's behalf by calling the permit function, paying gas fees, and possibly performing other actions in the same transaction. The governance can recover ERC20 and ERC721 tokens sent mistakenly to
L2TBTC
token contract.Testing
All functions defined in
L2TBTC
contract are fully covered with tests.L2TBTC
contract inherits from OpenZeppelin contracts and we do not want to test the framework. At the same time, we need to make sure all the declared functionalities are exposed by the contract and that they work. The tests must fail if the contract initialization gets broken or if one of the OpenZeppelin extensions is dropped from the inheritance. To make it happen, the tests cover really basic scenarios for the code implemented in OpenZeppelin ERC20 and extensions.The tests use
helpers.upgrades.deployProxy
to deployL2TBTC
and to test it as a contract deployed behind a proxy. There is a small complication with this approach that led to opening an issue in our hardhat plugins repo: keep-network/hardhat-helpers#38.