forked from circlefin/stablecoin-evm
-
Notifications
You must be signed in to change notification settings - Fork 1
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
add OptimismMintableFiatTokenV2_2 #1
Open
alvrs
wants to merge
21
commits into
master
Choose a base branch
from
alvrs/optimism
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
89a7982
add OptimismFiatTokenV2_2
alvrs 9997137
add natspec
alvrs 9e471ed
use predeploy bridge
alvrs adcd09d
call parent constructor
alvrs 224bba5
add tests
alvrs 4e1a072
use kwargs style syntax
alvrs d2887f4
revert changes to package.json
alvrs 5144f94
remove unused variable
alvrs 312f27d
remove todo
alvrs 174f0e4
add script to set token's bridge address
alvrs a9e5131
update param names
alvrs 670f674
make l1 token optional
alvrs 2e295a2
move view function out of broadcast
alvrs 4466a7e
move view function out of broadcast
alvrs 4703175
fix: add burn function with _from param
alvrs fd2c580
add upgrade script
alvrs 2e6dd3f
remove unused variable
alvrs 9edbf79
emit msg.sender as minter
alvrs 67ed7e6
respect blacklist in burn
alvrs 891d66e
minor upgrade script polish
alvrs fb58394
ignore _from blacklist in burn
alvrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
import { IERC165 } from "@openzeppelin/contracts/introspection/IERC165.sol"; | ||
|
||
/** | ||
* @title IOptimismMintableERC20 | ||
* @notice This interface is available on the OptimismMintableERC20 contract. | ||
* We declare it as a separate interface so that it can be used in | ||
* custom implementations of OptimismMintableERC20. | ||
* @notice From https://github.com/ethereum-optimism/optimism/blob/6b231760b3f352d5c4f6df8431b67d836f316f84/packages/contracts-bedrock/src/universal/IOptimismMintableERC20.sol#L10-L18 | ||
*/ | ||
interface IOptimismMintableERC20 is IERC165 { | ||
function remoteToken() external view returns (address); | ||
|
||
function bridge() external returns (address); | ||
|
||
function mint(address _to, uint256 _amount) external; | ||
|
||
function burn(address _from, uint256 _amount) external; | ||
} | ||
|
||
/** | ||
* @title IOptimismMintableFiatToken | ||
* @author Lattice (https://lattice.xyz) | ||
* @notice This interface adds the functions from IOptimismMintableERC20 missing from FiatTokenV2_2. | ||
* It doesn't include `mint(address _to, uint256 _amount)`, as this function already exists | ||
* on FiatTokenV2_2 (from FiatTokenV1), and can't be overridden. The only difference is a | ||
* (bool) return type for the FiatTokenV1 version, which doesn't matter for consumers of | ||
* IOptimismMintableERC20 that don't expect a return type. | ||
*/ | ||
interface IOptimismMintableFiatToken is IERC165 { | ||
function remoteToken() external view returns (address); | ||
|
||
function bridge() external returns (address); | ||
|
||
function burn(address _from, uint256 _amount) external; | ||
} |
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,74 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
import { FiatTokenV1 } from "../v1/FiatTokenV1.sol"; | ||
import { FiatTokenV2_2 } from "./FiatTokenV2_2.sol"; | ||
import { | ||
IOptimismMintableERC20, | ||
IOptimismMintableFiatToken | ||
} from "./IOptimismMintableFiatToken.sol"; | ||
import { IERC165 } from "@openzeppelin/contracts/introspection/IERC165.sol"; | ||
|
||
/** | ||
* @title OptimismMintableFiatTokenV2_2 | ||
* @author Lattice (https://lattice.xyz) | ||
* @notice Adds compatibility with IOptimismMintableERC20 to the Bridged USDC Standard, | ||
* so it can be used with Optimism's StandardBridge. | ||
*/ | ||
contract OptimismMintableFiatTokenV2_2 is | ||
FiatTokenV2_2, | ||
IOptimismMintableFiatToken | ||
{ | ||
address private immutable l1RemoteToken; | ||
|
||
constructor(address _l1RemoteToken) public FiatTokenV2_2() { | ||
l1RemoteToken = _l1RemoteToken; | ||
} | ||
|
||
function remoteToken() external override view returns (address) { | ||
return l1RemoteToken; | ||
} | ||
|
||
function bridge() external override returns (address) { | ||
// OP Stack L2StandardBridge predeploy | ||
// https://specs.optimism.io/protocol/predeploys.html | ||
return address(0x4200000000000000000000000000000000000010); | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) | ||
external | ||
override | ||
view | ||
returns (bool) | ||
{ | ||
return | ||
interfaceId == type(IOptimismMintableERC20).interfaceId || | ||
interfaceId == type(IERC165).interfaceId; | ||
} | ||
|
||
/** | ||
* @notice Allows a minter to burn tokens for the given account. | ||
* @dev The caller must be a minter, must not be blacklisted, and the amount to burn | ||
* should be less than or equal to the account's balance. | ||
* The function is a requirement for IOptimismMintableERC20. | ||
* It is mostly equivalent to FiatTokenV1.burn, with the only change being | ||
* the additional _from parameter to burn from instead of burning from msg.sender. | ||
* @param _amount the amount of tokens to be burned. | ||
*/ | ||
function burn(address _from, uint256 _amount) | ||
external | ||
override | ||
whenNotPaused | ||
onlyMinters | ||
notBlacklisted(msg.sender) | ||
{ | ||
uint256 balance = _balanceOf(_from); | ||
require(_amount > 0, "FiatToken: burn amount not greater than 0"); | ||
require(balance >= _amount, "FiatToken: burn amount exceeds balance"); | ||
|
||
totalSupply_ = totalSupply_.sub(_amount); | ||
_setBalance(_from, balance.sub(_amount)); | ||
emit Burn(_from, _amount); | ||
emit Transfer(_from, address(0), _amount); | ||
} | ||
} |
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,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
import "forge-std/console.sol"; // solhint-disable no-global-import, no-console | ||
import { Script } from "forge-std/Script.sol"; | ||
import { | ||
OptimismMintableFiatTokenV2_2 | ||
} from "../../contracts/v2/OptimismMintableFiatTokenV2_2.sol"; | ||
import { MasterMinter } from "../../contracts/minting/MasterMinter.sol"; | ||
|
||
/** | ||
* A utility script to set the token's l2StandardBridge as the minter | ||
*/ | ||
contract SetL2StandardBridge is Script { | ||
/** | ||
* @notice main function that will be run by forge | ||
*/ | ||
function run( | ||
address masterMinterOwner, | ||
OptimismMintableFiatTokenV2_2 optimismMintableFiatTokenV2_2 | ||
) external { | ||
address l2StandardBridge = optimismMintableFiatTokenV2_2.bridge(); | ||
if (l2StandardBridge == address(0)) { | ||
revert("Expected no-zero bridge address"); | ||
} | ||
MasterMinter masterMinter = MasterMinter( | ||
optimismMintableFiatTokenV2_2.masterMinter() | ||
); | ||
|
||
vm.startBroadcast(masterMinterOwner); | ||
masterMinter.configureController(masterMinterOwner, l2StandardBridge); | ||
masterMinter.configureMinter(type(uint256).max); | ||
masterMinter.removeController(masterMinterOwner); | ||
vm.stopBroadcast(); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if
emit Transfer
makes sense here? We are not transferring tokens toaddress(0)
as far as I can tell, just decreasingtotalSupply
and user's balance.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.
this follows the pattern in common ERC20 contracts:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L232
https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol#L204
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.
This method is taken from
FiatTokenV1
, only change is the_from
param instead of usingmsg.sender
:stablecoin-evm/contracts/v1/FiatTokenV1.sol
Lines 354 to 374 in 2af605e
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.
In the OpenZeppelin example though there is an
_update
function that increases the balance ofaddress(0)
- https://github.com/OpenZeppelin/openzeppelin-contracts/blob/e3786e63e6def6f3b71ce7b4b30906123bffe67c/contracts/token/ERC20/ERC20.sol#L206 so it makes sense to emitTransfer
toaddress(0)
.Although I see in Solmate's case the balance is also not increased. And also was not aware of such pattern. I suppose it's useful if you want to monitor for burned tokens, fair enough.