Skip to content

Commit

Permalink
wip(tests): removing mintAllowance in favor of rateLimits
Browse files Browse the repository at this point in the history
  • Loading branch information
KristenPire committed Jun 28, 2024
1 parent 0087e24 commit b2b225c
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 46 deletions.
12 changes: 7 additions & 5 deletions script/batchMint.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ contract BatchMint is Script {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address tokenAddress = 0xd58C5Db52B5B3Eb24EE38AF287d2cb0F424172A5;
address targetAddress = 0xd58C5Db52B5B3Eb24EE38AF287d2cb0F424172A5;
address[1] memory recipients = [0xd58C5Db52B5B3Eb24EE38AF287d2cb0F424172A5];
address[1] memory recipients = [
0xd58C5Db52B5B3Eb24EE38AF287d2cb0F424172A5
];

vm.startBroadcast(deployerPrivateKey);

// Assuming Token and SmartController are already deployed and their ABIs are known
Token token = Token(tokenAddress);
ERC20 target = ERC20(targetAddress);

token.setMaxMintAllowance(target.totalSupply());
token.setMintAllowance(targetAddress, target.totalSupply());
// token.setMaxMintAllowance(target.totalSupply());
// token.setMintAllowance(targetAddress, target.totalSupply());
console.log("mint allowance set successfully.");

for (uint256 i = 0; i < recipients.length; i++) {
token.mint(recipients[i], target.balanceOf(recipients[i]));
}

console.log("minting completed successfully.");
bool success = token.getMintAllowance(targetAddress) == 0;
console.log("mint allowance is 0: ", success);
// bool success = token.getMintAllowance(targetAddress) == 0;
// console.log("mint allowance is 0: ", success);
vm.stopBroadcast();
}
}
Expand Down
8 changes: 2 additions & 6 deletions script/configureToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ contract All is Script {
token.addAdminAccount(admin);
console.log("Admin account added successfully.");

token.addSystemAccount(system);
console.log("System account added successfully.");

token.setMaxMintAllowance(allowance);
console.log("Max mint allowance set successfully.");
token.addMinterAndBurner(system, allowance);

token.addAdminAccount(devKey);
token.setMintAllowance(system, allowance);
token.setLimits(system, allowance, 0);
console.log("mint allowance set successfully.");
token.removeAdminAccount(devKey);
vm.stopBroadcast();
Expand Down
2 changes: 1 addition & 1 deletion script/setMintAllowance.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract All is Script {
// Assuming Token and SmartController are already deployed and their ABIs are known
Token token = Token(tokenAddress);

token.setMintAllowance(system, allowance);
token.setLimits(system, allowance, 0);
console.log("Mint allowance set successfully for system as owner.");

vm.stopBroadcast();
Expand Down
2 changes: 1 addition & 1 deletion src/ControllerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ contract ControllerToken is Token {
address to,
uint256 amount
) external onlyFrontend onlySystemAccount(caller) returns (bool) {
_useMintAllowance(caller, amount);
_useMinterLimits(_msgSender(), amount);
_mint(to, amount);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/EthereumControllerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract EthereumControllerToken is Token {
address to,
uint256 amount
) external onlyFrontend onlySystemAccount(caller) returns (bool) {
_useMintAllowance(caller, amount);
_useMinterLimits(_msgSender(), amount);
_mint(to, amount);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/GnosisControllerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract GnosisControllerToken is Token {
address to,
uint256 amount
) external onlyFrontend onlySystemAccount(caller) returns (bool) {
_useMintAllowance(caller, amount);
_useMinterLimits(_msgSender(), amount);
_mint(to, amount);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/PolygonControllerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract PolygonControllerToken is Token {
address to,
uint256 amount
) external onlyFrontend onlySystemAccount(caller) returns (bool) {
_useMintAllowance(caller, amount);
_useMinterLimits(_msgSender(), amount);
_mint(to, amount);

return true;
Expand Down
15 changes: 0 additions & 15 deletions src/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ contract Token is
Initializable,
ERC20PermitUpgradeable,
UUPSUpgradeable,
MintAllowanceUpgradeable,
RateLimitsUpgradeable,
SystemRoleUpgradeable,
IXERC20
Expand Down Expand Up @@ -73,7 +72,6 @@ contract Token is
) internal override onlyOwner {}

function mint(address to, uint256 amount) public onlySystemAccounts {
_useMintAllowance(_msgSender(), amount);
_useMinterLimits(_msgSender(), amount);
_mint(to, amount);
}
Expand Down Expand Up @@ -151,19 +149,6 @@ contract Token is
return super.transferFrom(from, to, amount);
}

// setMaxMintAllowance is only callable by the owner
function setMaxMintAllowance(uint256 amount) public onlyOwner {
_setMaxMintAllowance(amount);
}

// setMintAllowance is only callable by the admins
function setMintAllowance(
address account,
uint256 amount
) public onlyAdminAccounts {
_setMintAllowance(account, amount);
}

/**
* @notice Returns the max limit of a minter
*
Expand Down
2 changes: 0 additions & 2 deletions test/Blacklist.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ contract BlackListValidatorTest is Test {
token.addAdminAccount(admin);
assertTrue(token.isSystemAccount(system));
assertTrue(token.isAdminAccount(admin));
token.setMaxMintAllowance(2e18);
token.addMinterAndBurner(system, 2e18);
vm.startPrank(admin);
token.setLimits(system, 2e18, 2e18);
token.setMintAllowance(system, 2e18);
vm.stopPrank();
vm.startPrank(system);
token.mint(user1, 1e18);
Expand Down
2 changes: 0 additions & 2 deletions test/ControllerToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ contract ControllerTokenTest is Test {
token.addAdminAccount(admin);
assertTrue(token.isSystemAccount(system));
assertTrue(token.isAdminAccount(admin));
token.setMaxMintAllowance(3e18);
token.addMinterAndBurner(system, 3e18);
vm.startPrank(admin);
token.setMintAllowance(system, 3e18);
token.setLimits(system, 3e18, 3e18);
vm.stopPrank();
vm.startPrank(system);
Expand Down
2 changes: 0 additions & 2 deletions test/Deployment.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ contract DeploymentTest is Test {
token.addAdminAccount(admin);
assertTrue(token.isSystemAccount(system));
assertTrue(token.isAdminAccount(admin));
token.setMaxMintAllowance(amount * 3);
token.addMinterAndBurner(system, amount * 3);
vm.startPrank(admin);
token.setMintAllowance(system, amount * 3);
token.setLimits(system, amount * 3, amount * 3);
vm.stopPrank();
vm.startPrank(system);
Expand Down
2 changes: 0 additions & 2 deletions test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ contract ERC20TokenTest is Test {
token.addAdminAccount(admin);
assertTrue(token.isSystemAccount(system));
assertTrue(token.isAdminAccount(admin));
token.setMaxMintAllowance(1e18);
token.addMinterAndBurner(system, 1e18);
vm.startPrank(admin);
token.setMintAllowance(system, 1e18);
token.setLimits(system, 1e18, 1e18);
vm.stopPrank();
}
Expand Down
13 changes: 6 additions & 7 deletions test/Mintable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ contract MintableTokenTest is Test {
}

function test_owner_can_set_max_mint_allowance() public {
token.setMaxMintAllowance(1000);
token.addMinterAndBurner(system, 1000);
assertEq(token.getMaxMintAllowance(), 1000);
assertEq(token.mintingMaxLimitOf(system), 1000);
}

/*
function test_non_owner_cannot_set_max_mint_allowance() public {
vm.startPrank(user1);
vm.expectRevert(
Expand All @@ -60,19 +60,18 @@ contract MintableTokenTest is Test {
);
token.setMaxMintAllowance(1000);
vm.stopPrank();
}
}*/

function test_admin_can_set_mint_allowance() public {
test_owner_can_set_max_mint_allowance();
token.addAdminAccount(admin);
vm.startPrank(admin);
token.setMintAllowance(system, 500);
token.setLimits(system, 500, 500);
vm.stopPrank();

assertEq(token.getMintAllowance(system), 500);
assertEq(token.mintingCurrentLimitOf(system), 500);
}

/*
function test_admin_cannot_set_mint_allowance_above_max_mint_allowance()
public
{
Expand All @@ -83,7 +82,7 @@ contract MintableTokenTest is Test {
token.setMintAllowance(system, 1500);
vm.stopPrank();
}

*/
function test_non_admin_cannot_set_mint_allowance() public {
vm.expectRevert("SystemRole: caller is not an admin account");
token.setMintAllowance(user1, 500);
Expand Down

0 comments on commit b2b225c

Please sign in to comment.