-
Notifications
You must be signed in to change notification settings - Fork 353
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
USDC v3 #338
Open
alexkroeger
wants to merge
1
commit into
circlefin:master
Choose a base branch
from
alexkroeger:v3
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
USDC v3 #338
Changes from all commits
Commits
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
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,276 @@ | ||
/** | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
pragma solidity 0.6.12; | ||
|
||
import { FiatTokenV2_1 } from "../v2/FiatTokenV2_1.sol"; | ||
import { EIP712 } from "../util/EIP712.sol"; | ||
|
||
/** | ||
* @title FiatToken | ||
* @dev ERC20 Token backed by fiat reserves | ||
*/ | ||
contract FiatTokenV3 is FiatTokenV2_1 { | ||
mapping(address => uint256) internal frozenBalances; | ||
|
||
event BalanceFrozen(address indexed _account, uint256 amountFrozen); | ||
event BalanceUnfrozen(address indexed _account, uint256 amountUnfrozen); | ||
|
||
/** | ||
* @notice Initialize v3 | ||
*/ | ||
function initializeV3() external { | ||
require(_initializedVersion == 2, "v3 initialized out of order"); | ||
|
||
DOMAIN_SEPARATOR = EIP712.makeDomainSeparator(name, "3"); | ||
|
||
_initializedVersion = 3; | ||
} | ||
|
||
/** | ||
* @dev Freezes an account's balance | ||
* @param _account The address whose balance will be frozen | ||
*/ | ||
function freezeBalance(address _account) external onlyBlacklister { | ||
uint256 amountFrozen = balances[_account]; | ||
|
||
totalSupply_ = totalSupply_.sub(amountFrozen); | ||
frozenBalances[_account] = frozenBalances[_account].add(amountFrozen); | ||
balances[_account] = 0; | ||
|
||
emit BalanceFrozen(_account, amountFrozen); | ||
emit Transfer(_account, address(0), amountFrozen); | ||
} | ||
|
||
/** | ||
* @dev Unfreezes an account's balance | ||
* @param _account The address whose balance will be unfrozen | ||
*/ | ||
function unfreezeBalance(address _account) external onlyBlacklister { | ||
uint256 amountUnfrozen = frozenBalances[_account]; | ||
|
||
totalSupply_ = totalSupply_.add(amountUnfrozen); | ||
frozenBalances[_account] = 0; | ||
balances[_account] = balances[_account].add(amountUnfrozen); | ||
|
||
emit BalanceUnfrozen(_account, amountUnfrozen); | ||
emit Transfer(address(0), _account, amountUnfrozen); | ||
} | ||
|
||
/** | ||
* @dev Get frozen token balance of an account | ||
* @param account address The account | ||
*/ | ||
function frozenBalanceOf(address account) external view returns (uint256) { | ||
return frozenBalances[account]; | ||
} | ||
|
||
/** | ||
* @notice Set spender's allowance over the caller's tokens to be a given | ||
* value. | ||
* @param spender Spender's address | ||
* @param value Allowance amount | ||
* @return True if successful | ||
*/ | ||
function approve(address spender, uint256 value) | ||
external | ||
override | ||
whenNotPaused | ||
returns (bool) | ||
{ | ||
_approve(msg.sender, spender, value); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Transfer tokens by spending allowance | ||
* @param from Payer's address | ||
* @param to Payee's address | ||
* @param value Transfer amount | ||
* @return True if successful | ||
*/ | ||
function transferFrom( | ||
address from, | ||
address to, | ||
uint256 value | ||
) external override whenNotPaused returns (bool) { | ||
require( | ||
value <= allowed[from][msg.sender], | ||
"ERC20: transfer amount exceeds allowance" | ||
); | ||
_transfer(from, to, value); | ||
allowed[from][msg.sender] = allowed[from][msg.sender].sub(value); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Transfer tokens from the caller | ||
* @param to Payee's address | ||
* @param value Transfer amount | ||
* @return True if successful | ||
*/ | ||
function transfer(address to, uint256 value) | ||
external | ||
override | ||
whenNotPaused | ||
returns (bool) | ||
{ | ||
_transfer(msg.sender, to, value); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Increase the allowance by a given increment | ||
* @param spender Spender's address | ||
* @param increment Amount of increase in allowance | ||
* @return True if successful | ||
*/ | ||
function increaseAllowance(address spender, uint256 increment) | ||
external | ||
override | ||
whenNotPaused | ||
returns (bool) | ||
{ | ||
_increaseAllowance(msg.sender, spender, increment); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Decrease the allowance by a given decrement | ||
* @param spender Spender's address | ||
* @param decrement Amount of decrease in allowance | ||
* @return True if successful | ||
*/ | ||
function decreaseAllowance(address spender, uint256 decrement) | ||
external | ||
override | ||
whenNotPaused | ||
returns (bool) | ||
{ | ||
_decreaseAllowance(msg.sender, spender, decrement); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Execute a transfer with a signed authorization | ||
* @param from Payer's address (Authorizer) | ||
* @param to Payee's address | ||
* @param value Amount to be transferred | ||
* @param validAfter The time after which this is valid (unix time) | ||
* @param validBefore The time before which this is valid (unix time) | ||
* @param nonce Unique nonce | ||
* @param v v of the signature | ||
* @param r r of the signature | ||
* @param s s of the signature | ||
*/ | ||
function transferWithAuthorization( | ||
address from, | ||
address to, | ||
uint256 value, | ||
uint256 validAfter, | ||
uint256 validBefore, | ||
bytes32 nonce, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external override whenNotPaused { | ||
_transferWithAuthorization( | ||
from, | ||
to, | ||
value, | ||
validAfter, | ||
validBefore, | ||
nonce, | ||
v, | ||
r, | ||
s | ||
); | ||
} | ||
|
||
/** | ||
* @notice Receive a transfer with a signed authorization from the payer | ||
* @dev This has an additional check to ensure that the payee's address | ||
* matches the caller of this function to prevent front-running attacks. | ||
* @param from Payer's address (Authorizer) | ||
* @param to Payee's address | ||
* @param value Amount to be transferred | ||
* @param validAfter The time after which this is valid (unix time) | ||
* @param validBefore The time before which this is valid (unix time) | ||
* @param nonce Unique nonce | ||
* @param v v of the signature | ||
* @param r r of the signature | ||
* @param s s of the signature | ||
*/ | ||
function receiveWithAuthorization( | ||
address from, | ||
address to, | ||
uint256 value, | ||
uint256 validAfter, | ||
uint256 validBefore, | ||
bytes32 nonce, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external override whenNotPaused { | ||
_receiveWithAuthorization( | ||
from, | ||
to, | ||
value, | ||
validAfter, | ||
validBefore, | ||
nonce, | ||
v, | ||
r, | ||
s | ||
); | ||
} | ||
|
||
/** | ||
* @notice Update allowance with a signed permit | ||
* @param owner Token owner's address (Authorizer) | ||
* @param spender Spender's address | ||
* @param value Amount of allowance | ||
* @param deadline Expiration time, seconds since the epoch | ||
* @param v v of the signature | ||
* @param r r of the signature | ||
* @param s s of the signature | ||
*/ | ||
function permit( | ||
address owner, | ||
address spender, | ||
uint256 value, | ||
uint256 deadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external override whenNotPaused { | ||
_permit(owner, spender, value, deadline, v, r, s); | ||
} | ||
|
||
/** | ||
* @notice Version string for the EIP712 domain separator | ||
* @return Version string | ||
*/ | ||
function version() external override view returns (string memory) { | ||
return "3"; | ||
} | ||
} |
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.
While you're at it, can save 5k more gas on swaps and contract interactions by using infinite approval gas optimization!!
Something like this:
Reference
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 this moment I am euphoric
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.
@phil-ociraptor in your suggestion aren't you missing a
]
?L121 of your suggestion 👇
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.
🦅 👀
great catch! updated