Skip to content

Commit d7827c4

Browse files
committed
chore(deploy.s): adding specification
1 parent 1a19eda commit d7827c4

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

script/deploy.s.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ contract All is Script {
1919
abi.encodeWithSelector(BlacklistValidatorUpgradeable.initialize.selector)
2020
);
2121

22+
// Deploy only one implementation of the Token contract for all currencies.
2223
Token implementation = new Token();
2324

2425
deployTokenProxy(implementation, "Monerium EUR emoney", "EURe", address(validatorProxy));

src/MintAllowanceUpgradeable.sol

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
pragma solidity ^0.8.20;
2+
3+
contract MintAllowanceUpgradeable {
4+
struct MintAllowanceStorage {
5+
mapping(address => uint256) _mintAllowance;
6+
uint256 _maxMintAllowance;
7+
}
8+
9+
//keccak256("Monerium.MintAllowanceStorage")
10+
bytes32 private constant MintAllowanceStorageLocation =
11+
0xb337526095403ef89c7becef1792605e55dadf16cfa1d0df874fad9581a6937d;
12+
13+
function _getMintAllowanceStorage()
14+
private
15+
pure
16+
returns (MintAllowanceStorage storage $)
17+
{
18+
assembly {
19+
$.slot := MintAllowanceStorageLocation
20+
}
21+
}
22+
23+
/**
24+
* @dev Emitted when allowance is set.
25+
* @param account The address of the account.
26+
* @param amount The amount of allowance.
27+
*/
28+
event MintAllowance(address indexed account, uint256 amount);
29+
30+
/**
31+
* @dev Emitted when max allowance is set.
32+
* @param amount The amount of allowance.
33+
*/
34+
event MaxMintAllowance(uint256 amount);
35+
36+
modifier onlyAllowedMinter(address account, uint256 amount) {
37+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
38+
require(
39+
s._mintAllowance[account] >= amount,
40+
"MintAllowance: not allowed to mint more than allowed"
41+
);
42+
_;
43+
}
44+
45+
function getMintAllowance(address account) public view returns (uint256) {
46+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
47+
return s._mintAllowance[account];
48+
}
49+
50+
function _setMintAllowance(address account, uint256 amount) internal {
51+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
52+
53+
require(
54+
amount <= s._maxMintAllowance,
55+
"MintAllowance: cannot set allowance higher than max"
56+
);
57+
58+
s._mintAllowance[account] = amount;
59+
60+
emit MintAllowance(account, amount);
61+
}
62+
63+
function _useMintAllowance(address account, uint256 amount) internal {
64+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
65+
66+
require(
67+
s._mintAllowance[account] >= amount,
68+
"MintAllowance: not allowed to mint more than allowed"
69+
);
70+
71+
s._mintAllowance[account] -= amount;
72+
73+
emit MintAllowance(account, s._mintAllowance[account]);
74+
}
75+
76+
function getMaxMintAllowance() public view returns (uint256) {
77+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
78+
return s._maxMintAllowance;
79+
}
80+
81+
function _setMaxMintAllowance(uint256 amount) internal {
82+
MintAllowanceStorage storage s = _getMintAllowanceStorage();
83+
84+
s._maxMintAllowance = amount;
85+
86+
emit MaxMintAllowance(amount);
87+
}
88+
}

0 commit comments

Comments
 (0)