Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onlyTreasury modifier for issueRedeemable4YR() #199

Merged
merged 4 commits into from
May 9, 2023
Merged
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
18 changes: 16 additions & 2 deletions contracts/EscrowIssuer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,36 @@ contract EscrowIssuer is ERC20 {
/// @notice rewards escrow contract
IRewardEscrow public immutable rewardEscrow;

/// @notice treasury address
address public treasury;

/// @notice access control modifier for EscrowIssuer
modifier onlyTreasury() {
require(
msg.sender == address(treasury),
"Only the Treasury can perform this action"
);
_;
}

constructor(
string memory _name,
string memory _symbol,
address _kwenta,
address _rewardEscrowAddr
address _rewardEscrowAddr,
address _treasury
) ERC20(_name, _symbol) {
kwenta = IKwenta(_kwenta);
rewardEscrow = IRewardEscrow(_rewardEscrowAddr);
treasury = _treasury;
}

/**
* Receive Kwenta from user, then mint
* redeemable escrowed Kwenta and give
* to user.
*/
function issueRedeemable4YR(uint amount) public payable {
function issueRedeemable4YR(uint amount) public payable onlyTreasury {
require(
kwenta.transferFrom(msg.sender, address(this), amount),
"Token transfer failed"
Expand Down
14 changes: 13 additions & 1 deletion test/foundry/EscrowIssuer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ contract EscrowIssuerTest is Test {
"EscIss",
"EIS",
address(kwenta),
address(rewardEscrow)
address(rewardEscrow),
address(this)
);
}

Expand Down Expand Up @@ -97,4 +98,15 @@ contract EscrowIssuerTest is Test {
vm.prank(user);
escrowIssuer.redeemEscrow4YR(10);
}

/**
test when non-treasury tries to call issue redeemable
should revert
*/
function testIssueRedeemableNonTreasury() public {
vm.startPrank(user);
kwenta.approve(address(escrowIssuer), 10);
jcmonte marked this conversation as resolved.
Show resolved Hide resolved
vm.expectRevert("Only the Treasury can perform this action");
escrowIssuer.issueRedeemable4YR(10);
jcmonte marked this conversation as resolved.
Show resolved Hide resolved
}
}