Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- ERC20.sol @openzepplin + v0.8.11
- https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
- FiatTokenV1Test.sol @original + v0.8.11
- FiatTokenV1_1Test.sol @original + v0.8.11
- FiatTokenV2Test.sol @original + v0.8.11
- IERC20Metadata.sol @openzeppelin + v0.8.11
- https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/IERC20Metadata.sol
Expand Down Expand Up @@ -70,6 +71,15 @@
- Rescuable.sol @centre-tokens + v0.8.11 + gap
- https://github.com/centrehq/centre-tokens/blob/master/contracts/v1.1/Rescuable.sol

## v1_1
- EIP712Domain.sol @fork-centre-tokens + v0.8.11 + gap
- https://github.com/centrehq/centre-tokens/blob/master/contracts/v2/EIP712Domain.sol
- EIP2612.sol @centre-tokens + v0.8.11 + gap
- https://github.com/centrehq/centre-tokens/blob/master/contracts/v2/EIP2612.sol
- EIP3009.sol @centre-tokens + v0.8.11 + gap
- https://github.com/centrehq/centre-tokens/blob/master/contracts/v2/EIP3009.sol
- FiatTokenV1_1.sol @original + v0.8.11

## v2
- FiatTokenV2.sol @original + v0.8.11
- FiatTokenV2test.sol @original + v0.8.11
2 changes: 0 additions & 2 deletions contracts/test/FiatTokenV1Test.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/**
* SPDX-License-Identifier: MIT
*
Expand Down
33 changes: 33 additions & 0 deletions contracts/test/FiatTokenV1_1Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018 zOS Global Limited.
*
* 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.8.11;

import "../v1_1/FiatTokenV1_1.sol";

contract FiatTokenV1_1Test is FiatTokenV1_1 {
function approveTest(address owner, address spender, uint256 value) external {
_approve(owner, spender, value);
}
}
99 changes: 99 additions & 0 deletions contracts/v1_1/EIP2612.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018-2020 CENTRE SECZ
* Copyright (c) 2022 JPYC
*
* 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.8.11;

import "../v1/AbstractFiatTokenV1.sol";
import "./EIP712Domain.sol";
import "../util/EIP712.sol";

/**
* @dev Forked from https://github.com/centrehq/centre-tokens/blob/37039f00534d3e5148269adf98bd2d42ea9fcfd7/contracts/v2/EIP2612.sol
* Modifications:
* 1. Change solidity version to 0.8.11
* 2. Make domain separator dynamic by adding function: domainSeparatorV4
* 3. Add gap
* 4. Change now to block.timestamp
*/

/**
* @title EIP-2612
* @notice Provide internal implementation for gas-abstracted approvals
*/
abstract contract EIP2612 is AbstractFiatTokenV1, EIP712Domain {
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
bytes32 public constant PERMIT_TYPEHASH =
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

mapping(address => uint256) private _permitNonces;

/**
* @notice Nonces for permit
* @param owner Token owner's address (Authorizer)
* @return Next nonce
*/
function nonces(address owner) external view returns (uint256) {
return _permitNonces[owner];
}

/**
* @notice Verify a signed approval permit and execute if valid
* @param owner Token owner's address (Authorizer)
* @param spender Spender's address
* @param value Amount of allowance
* @param deadline The time at which this expires (unix time)
* @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
) internal {
require(deadline >= block.timestamp, "EIP2612: permit is expired");

bytes memory data = abi.encode(
PERMIT_TYPEHASH,
owner,
spender,
value,
_permitNonces[owner]++,
deadline
);
require(
EIP712.recover(_domainSeparatorV4(), v, r, s, data) == owner,
"EIP2612: invalid signature"
);

_approve(owner, spender, value);
}

uint256[50] private __gap;
}
Loading