Skip to content

Commit afa3ac0

Browse files
cairoethernestognw
andauthored
Replace struct with params for ERC20Collateral (#24)
* Replace struct with params * Store timestamp in mock * Remove struct * lint --------- Co-authored-by: Ernesto García <[email protected]>
1 parent 2fb37ce commit afa3ac0

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

contracts/mocks/token/ERC20CollateralMock.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ pragma solidity ^0.8.20;
55
import {ERC20, ERC20Collateral} from "../../token/ERC20/extensions/ERC20Collateral.sol";
66

77
abstract contract ERC20CollateralMock is ERC20Collateral {
8-
ERC20Collateral.Collateral private _collateral;
9-
8+
uint48 private _timestamp;
109
constructor(
1110
uint48 liveness_,
1211
string memory name_,
1312
string memory symbol_
1413
) ERC20(name_, symbol_) ERC20Collateral(liveness_) {
15-
_collateral = ERC20Collateral.Collateral({amount: type(uint128).max, timestamp: clock()});
14+
_timestamp = clock();
1615
}
1716

18-
function collateral() public view override returns (ERC20Collateral.Collateral memory) {
19-
return _collateral;
17+
function collateral() public view override returns (uint256 amount, uint48 timestamp) {
18+
return (type(uint128).max, _timestamp);
2019
}
2120
}

contracts/token/ERC20/extensions/ERC20Collateral.sol

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import {IERC6372} from "@openzeppelin/contracts/interfaces/IERC6372.sol";
1313
* data. This function can call external oracles or use any local storage.
1414
*/
1515
abstract contract ERC20Collateral is ERC20, IERC6372 {
16-
// Structure that stores the details of the collateral
17-
struct Collateral {
18-
uint256 amount;
19-
uint48 timestamp;
20-
}
21-
2216
/**
2317
* @dev Liveness duration of collateral, defined in seconds.
2418
*/
@@ -66,7 +60,7 @@ abstract contract ERC20Collateral is ERC20, IERC6372 {
6660
/**
6761
* @dev Returns the collateral data of the token.
6862
*/
69-
function collateral() public view virtual returns (Collateral memory);
63+
function collateral() public view virtual returns (uint256 amount, uint48 timestamp);
7064

7165
/**
7266
* @dev See {ERC20-_update}.
@@ -75,16 +69,16 @@ abstract contract ERC20Collateral is ERC20, IERC6372 {
7569
super._update(from, to, value);
7670

7771
if (from == address(0)) {
78-
Collateral memory _collateral = collateral();
72+
(uint256 amount, uint48 timestamp) = collateral();
7973

80-
uint48 expiration = _collateral.timestamp + liveness();
74+
uint48 expiration = timestamp + liveness();
8175
if (expiration < clock()) {
82-
revert ERC20ExpiredCollateral(_collateral.timestamp, expiration);
76+
revert ERC20ExpiredCollateral(timestamp, expiration);
8377
}
8478

8579
uint256 supply = totalSupply();
86-
if (supply > _collateral.amount) {
87-
revert ERC20ExceededSupply(supply, _collateral.amount);
80+
if (supply > amount) {
81+
revert ERC20ExceededSupply(supply, amount);
8882
}
8983
}
9084
}

0 commit comments

Comments
 (0)