Skip to content

Commit 0922a91

Browse files
format
1 parent e72d01a commit 0922a91

4 files changed

Lines changed: 47 additions & 41 deletions

File tree

evm/src/CustomStablecoin/CustomStablecoin.sol

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ contract CustomStablecoin is
8989
initializer
9090
{
9191
// Decimals must be set before granting mint role.
92-
MetadataStorage.setDecimals(tokenDecimals);
92+
MetadataStorage.setDecimals({value: tokenDecimals});
9393
__ERC20_init(name, symbol);
9494
__ERC20Pausable_init();
9595
__AccessControlDefaultAdminRules_init(adminDelay, admin);
96-
_grantRole(MINT_ALLOWANCE_ROLE, admin);
97-
_grantRole(MINT_ROLE, admin);
98-
_grantRole(BURN_ROLE, admin);
99-
_grantRole(PAUSE_ROLE, admin);
100-
_grantRole(BLACKLIST_ROLE, admin);
96+
_grantRole({role: MINT_ALLOWANCE_ROLE, account: admin});
97+
_grantRole({role: MINT_ROLE, account: admin});
98+
_grantRole({role: BURN_ROLE, account: admin});
99+
_grantRole({role: PAUSE_ROLE, account: admin});
100+
_grantRole({role: BLACKLIST_ROLE, account: admin});
101101
}
102102

103103
/// @notice Mints `amount` tokens to `to`.
@@ -106,7 +106,7 @@ contract CustomStablecoin is
106106
/// @param amount Number of tokens to mint.
107107
function mint(address to, uint256 amount) external onlyRole(MINT_ROLE) {
108108
if (to == address(0)) revert MintToZeroAddress();
109-
MintAllowanceStorage.consume(msg.sender, amount);
109+
MintAllowanceStorage.consume({minter: msg.sender, amount: amount});
110110
_mint(to, amount);
111111
emit Minted({minter: msg.sender, to: to, amount: amount});
112112
}
@@ -126,17 +126,6 @@ contract CustomStablecoin is
126126
MintAllowanceStorage.configureMinter(minter, maxAllowance, interval);
127127
}
128128

129-
/// @notice Returns the estimated current mint allowance for `caller`.
130-
///
131-
/// @dev Includes any pending replenishment that would apply at the current timestamp.
132-
///
133-
/// @param caller Address to query.
134-
///
135-
/// @return Current allowance including any pending replenishment.
136-
function estimatedAllowance(address caller) external view returns (uint256) {
137-
return MintAllowanceStorage.estimatedAllowance(caller);
138-
}
139-
140129
/// @notice Burns `amount` tokens from the caller's balance.
141130
///
142131
/// @param amount Number of tokens to burn.
@@ -169,6 +158,17 @@ contract CustomStablecoin is
169158
BlacklistStorage.unBlacklist(account);
170159
}
171160

161+
/// @notice Returns the estimated current mint allowance for `caller`.
162+
///
163+
/// @dev Includes any pending replenishment that would apply at the current timestamp.
164+
///
165+
/// @param caller Address to query.
166+
///
167+
/// @return Current allowance including any pending replenishment.
168+
function estimatedAllowance(address caller) external view returns (uint256) {
169+
return MintAllowanceStorage.estimatedAllowance({minter: caller});
170+
}
171+
172172
/// @notice Returns whether `account` is blacklisted.
173173
///
174174
/// @param account Address to query.
@@ -201,7 +201,9 @@ contract CustomStablecoin is
201201
bool granted = super._grantRole(role, account);
202202
if (granted && role == MINT_ROLE) {
203203
uint256 allowance = DEFAULT_MINT_ALLOWANCE * 10 ** decimals();
204-
MintAllowanceStorage.configureMinter(account, allowance, DEFAULT_MINT_INTERVAL);
204+
MintAllowanceStorage.configureMinter({
205+
minter: account, maxAllowance: allowance, interval: DEFAULT_MINT_INTERVAL
206+
});
205207
}
206208
return granted;
207209
}
@@ -215,7 +217,7 @@ contract CustomStablecoin is
215217
function _revokeRole(bytes32 role, address account) internal override returns (bool) {
216218
bool revoked = super._revokeRole(role, account);
217219
if (revoked && role == MINT_ROLE) {
218-
MintAllowanceStorage.removeMinter(account);
220+
MintAllowanceStorage.removeMinter({minter: account});
219221
}
220222
return revoked;
221223
}
@@ -229,9 +231,9 @@ contract CustomStablecoin is
229231
internal
230232
override(ERC20Upgradeable, ERC20PausableUpgradeable)
231233
{
232-
BlacklistStorage.requireNotBlacklisted(msg.sender);
233-
BlacklistStorage.requireNotBlacklisted(from);
234-
BlacklistStorage.requireNotBlacklisted(to);
234+
BlacklistStorage.requireNotBlacklisted({account: msg.sender});
235+
BlacklistStorage.requireNotBlacklisted({account: from});
236+
BlacklistStorage.requireNotBlacklisted({account: to});
235237
super._update(from, to, value);
236238
}
237239
}

evm/src/CustomStablecoin/lib/MintAllowanceStorage.sol

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ library MintAllowanceStorage {
2121
uint256 maxAllowance;
2222
/// @dev The current available allowance.
2323
uint256 allowance;
24-
/// @dev The replenishment interval in seconds.
25-
uint256 interval;
26-
/// @dev The unix timestamp of the last replenishment.
27-
uint256 lastReplenished;
24+
/// @dev The replenishment interval in seconds. Packed with `lastReplenished`.
25+
uint40 interval;
26+
/// @dev The unix timestamp (seconds) of the last replenishment. Packed with `interval`.
27+
uint40 lastReplenished;
2828
}
2929

3030
/// @notice Storage layout for mint allowances.
@@ -89,7 +89,10 @@ library MintAllowanceStorage {
8989
function configureMinter(address minter, uint256 maxAllowance, uint256 interval) internal {
9090
if (maxAllowance == 0 || interval == 0) revert InvalidMinterConfig();
9191
layout().minters[minter] = MinterConfig({
92-
maxAllowance: maxAllowance, allowance: maxAllowance, interval: interval, lastReplenished: block.timestamp
92+
maxAllowance: maxAllowance,
93+
allowance: maxAllowance,
94+
interval: uint40(interval),
95+
lastReplenished: uint40(block.timestamp)
9396
});
9497
emit MinterConfigured({minter: minter, maxAllowance: maxAllowance, interval: interval});
9598
}
@@ -146,13 +149,13 @@ library MintAllowanceStorage {
146149
function _replenish(address minter) private {
147150
MinterConfig storage config = layout().minters[minter];
148151
if (config.allowance == config.maxAllowance) {
149-
config.lastReplenished = block.timestamp;
152+
config.lastReplenished = uint40(block.timestamp);
150153
return;
151154
}
152155
uint256 amount = _replenishAmount(config);
153156
if (amount == 0) return;
154157
config.allowance += amount;
155-
config.lastReplenished = block.timestamp;
158+
config.lastReplenished = uint40(block.timestamp);
156159
emit AllowanceReplenished({minter: minter, allowance: config.allowance, amountReplenished: amount});
157160
}
158161

evm/src/OverrideableBeaconProxy.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ contract OverrideableBeaconProxy is BeaconProxy {
123123
emit ImplementationOverrideSet({implementation: implementation});
124124
}
125125

126-
/// @notice Returns the current implementation override, or `address(0)` if using the beacon.
127-
///
128-
/// @return The override implementation address.
129-
function implementationOverride() external view returns (address) {
130-
return ERC1967Utils.getImplementation();
131-
}
132-
133126
/// @notice Starts a two-step transfer of the proxy admin role to `newAdmin`.
134127
///
135128
/// @dev Setting `newAdmin` to `address(0)` cancels a pending transfer.
@@ -150,6 +143,13 @@ contract OverrideableBeaconProxy is BeaconProxy {
150143
emit ProxyAdminTransferred({previousAdmin: oldAdmin, newAdmin: msg.sender});
151144
}
152145

146+
/// @notice Returns the current implementation override, or `address(0)` if using the beacon.
147+
///
148+
/// @return The override implementation address.
149+
function implementationOverride() external view returns (address) {
150+
return ERC1967Utils.getImplementation();
151+
}
152+
153153
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
154154
/* PUBLIC FUNCTIONS */
155155
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

evm/src/OverrideableBeaconProxyFactory.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ contract OverrideableBeaconProxyFactory is Initializable, AccessControlDefaultAd
7676
function initialize(address admin, uint48 adminDelay, address beacon_) external initializer {
7777
if (beacon_ == address(0)) revert BeaconNotSet();
7878
__AccessControlDefaultAdminRules_init(adminDelay, admin);
79-
_grantRole(DEPLOYER_ROLE, admin);
79+
_grantRole({role: DEPLOYER_ROLE, account: admin});
8080
_getFactoryStorage().beacon = beacon_;
8181
}
8282

@@ -86,14 +86,15 @@ contract OverrideableBeaconProxyFactory is Initializable, AccessControlDefaultAd
8686
/// @param admin The admin of the new proxy (controls implementation override).
8787
/// @param data Optional initializer calldata forwarded via delegatecall.
8888
///
89-
/// @return proxy The address of the newly deployed proxy.
89+
/// @return The address of the newly deployed proxy.
9090
function deploy(bytes32 salt, address admin, bytes calldata data)
9191
external
9292
onlyRole(DEPLOYER_ROLE)
93-
returns (address proxy)
93+
returns (address)
9494
{
95-
proxy = address(new OverrideableBeaconProxy{salt: salt}(_getFactoryStorage().beacon, admin, data));
95+
address proxy = address(new OverrideableBeaconProxy{salt: salt}(_getFactoryStorage().beacon, admin, data));
9696
emit ProxyDeployed({proxy: proxy, admin: admin, salt: salt});
97+
return proxy;
9798
}
9899

99100
/// @notice Returns the deterministic address for a proxy deployed with the given

0 commit comments

Comments
 (0)