From 595e9fd6d3e7715d13f4d9095b9af8eadb1c97d1 Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Tue, 9 May 2023 10:17:00 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=91=B7=20Added=20onlyGovernance=20mod?= =?UTF-8?q?ifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/EscrowIssuer.sol | 15 ++++++++++++++- test/foundry/EscrowIssuer.t.sol | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/contracts/EscrowIssuer.sol b/contracts/EscrowIssuer.sol index 48be9c659..1e8945c9e 100644 --- a/contracts/EscrowIssuer.sol +++ b/contracts/EscrowIssuer.sol @@ -12,6 +12,18 @@ contract EscrowIssuer is ERC20 { /// @notice rewards escrow contract IRewardEscrow public immutable rewardEscrow; + /// @notice governance address + address public governance; + + /// @notice access control modifier for EscrowIssuer + modifier onlyGovernance() { + require( + msg.sender == address(governance), + "Only the Governance can perform this action" + ); + _; + } + constructor( string memory _name, string memory _symbol, @@ -20,6 +32,7 @@ contract EscrowIssuer is ERC20 { ) ERC20(_name, _symbol) { kwenta = IKwenta(_kwenta); rewardEscrow = IRewardEscrow(_rewardEscrowAddr); + governance = msg.sender; } /** @@ -27,7 +40,7 @@ contract EscrowIssuer is ERC20 { * redeemable escrowed Kwenta and give * to user. */ - function issueRedeemable4YR(uint amount) public payable { + function issueRedeemable4YR(uint amount) public payable onlyGovernance { require( kwenta.transferFrom(msg.sender, address(this), amount), "Token transfer failed" diff --git a/test/foundry/EscrowIssuer.t.sol b/test/foundry/EscrowIssuer.t.sol index d629dc046..3a346a6b3 100644 --- a/test/foundry/EscrowIssuer.t.sol +++ b/test/foundry/EscrowIssuer.t.sol @@ -97,4 +97,15 @@ contract EscrowIssuerTest is Test { vm.prank(user); escrowIssuer.redeemEscrow4YR(10); } + + /** + test when non-governance tries to call issue redeemable + should revert + */ + function testIssueRedeemableNonGovernance() public { + vm.startPrank(user); + kwenta.approve(address(escrowIssuer), 10); + vm.expectRevert(); + escrowIssuer.issueRedeemable4YR(10); + } } From 860500e2fbccc34c36d35f22aee473b7530255b1 Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Tue, 9 May 2023 10:23:14 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9A=20Rename=20governance=20to=20t?= =?UTF-8?q?reasury?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/EscrowIssuer.sol | 14 +++++++------- test/foundry/EscrowIssuer.t.sol | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contracts/EscrowIssuer.sol b/contracts/EscrowIssuer.sol index 1e8945c9e..0c79fae91 100644 --- a/contracts/EscrowIssuer.sol +++ b/contracts/EscrowIssuer.sol @@ -12,14 +12,14 @@ contract EscrowIssuer is ERC20 { /// @notice rewards escrow contract IRewardEscrow public immutable rewardEscrow; - /// @notice governance address - address public governance; + /// @notice treasury address + address public treasury; /// @notice access control modifier for EscrowIssuer - modifier onlyGovernance() { + modifier onlyTreasury() { require( - msg.sender == address(governance), - "Only the Governance can perform this action" + msg.sender == address(treasury), + "Only the Treasury can perform this action" ); _; } @@ -32,7 +32,7 @@ contract EscrowIssuer is ERC20 { ) ERC20(_name, _symbol) { kwenta = IKwenta(_kwenta); rewardEscrow = IRewardEscrow(_rewardEscrowAddr); - governance = msg.sender; + treasury = msg.sender; } /** @@ -40,7 +40,7 @@ contract EscrowIssuer is ERC20 { * redeemable escrowed Kwenta and give * to user. */ - function issueRedeemable4YR(uint amount) public payable onlyGovernance { + function issueRedeemable4YR(uint amount) public payable onlyTreasury { require( kwenta.transferFrom(msg.sender, address(this), amount), "Token transfer failed" diff --git a/test/foundry/EscrowIssuer.t.sol b/test/foundry/EscrowIssuer.t.sol index 3a346a6b3..02d9aa8dc 100644 --- a/test/foundry/EscrowIssuer.t.sol +++ b/test/foundry/EscrowIssuer.t.sol @@ -99,10 +99,10 @@ contract EscrowIssuerTest is Test { } /** - test when non-governance tries to call issue redeemable + test when non-treasury tries to call issue redeemable should revert */ - function testIssueRedeemableNonGovernance() public { + function testIssueRedeemableNonTreasury() public { vm.startPrank(user); kwenta.approve(address(escrowIssuer), 10); vm.expectRevert(); From e9f88636fd4638c0070c0b1c5b2bfd0d632d8f98 Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Tue, 9 May 2023 11:08:07 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=91=B7=20Change=20treasury=20address?= =?UTF-8?q?=20to=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/EscrowIssuer.sol | 5 +++-- test/foundry/EscrowIssuer.t.sol | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/EscrowIssuer.sol b/contracts/EscrowIssuer.sol index 0c79fae91..bbf994068 100644 --- a/contracts/EscrowIssuer.sol +++ b/contracts/EscrowIssuer.sol @@ -28,11 +28,12 @@ contract EscrowIssuer is ERC20 { string memory _name, string memory _symbol, address _kwenta, - address _rewardEscrowAddr + address _rewardEscrowAddr, + address _treasury ) ERC20(_name, _symbol) { kwenta = IKwenta(_kwenta); rewardEscrow = IRewardEscrow(_rewardEscrowAddr); - treasury = msg.sender; + treasury = _treasury; } /** diff --git a/test/foundry/EscrowIssuer.t.sol b/test/foundry/EscrowIssuer.t.sol index 02d9aa8dc..53e1cb8fb 100644 --- a/test/foundry/EscrowIssuer.t.sol +++ b/test/foundry/EscrowIssuer.t.sol @@ -39,7 +39,8 @@ contract EscrowIssuerTest is Test { "EscIss", "EIS", address(kwenta), - address(rewardEscrow) + address(rewardEscrow), + address(this) ); } From 73d27441d5998e407abaff1810049fc1f9e04083 Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Tue, 9 May 2023 11:09:21 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=85=20Specified=20exceptRevert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/foundry/EscrowIssuer.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/foundry/EscrowIssuer.t.sol b/test/foundry/EscrowIssuer.t.sol index 53e1cb8fb..09b989423 100644 --- a/test/foundry/EscrowIssuer.t.sol +++ b/test/foundry/EscrowIssuer.t.sol @@ -106,7 +106,7 @@ contract EscrowIssuerTest is Test { function testIssueRedeemableNonTreasury() public { vm.startPrank(user); kwenta.approve(address(escrowIssuer), 10); - vm.expectRevert(); + vm.expectRevert("Only the Treasury can perform this action"); escrowIssuer.issueRedeemable4YR(10); } }