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

Event toggle function pause new #357

Merged
merged 5 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract LoanTokenSettingsLowerAdmin is LoanTokenLogicStorage {
/* Events */

event SetTransactionLimits(address[] addresses, uint256[] limits);
event ToggleFunctionPaused(string functionId, bool prevFlag, bool newFlag);

/* Functions */

Expand Down Expand Up @@ -184,6 +185,7 @@ contract LoanTokenSettingsLowerAdmin is LoanTokenLogicStorage {
string memory funcId, /// example: "mint(uint256,uint256)"
bool isPaused
) public {
bool paused;
require(msg.sender == pauser, "onlyPauser");
/// keccak256("iToken_FunctionPause")
bytes32 slot =
Expand All @@ -193,9 +195,14 @@ contract LoanTokenSettingsLowerAdmin is LoanTokenLogicStorage {
uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2)
)
);
assembly {
paused := sload(slot)
}
require(paused != isPaused, "invalid");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the require is not strictly required here, but doesn't hurt either. however, the error message doesn't provide any valuable information. change it to "isPaused is already set to that value" or similar message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assembly {
sstore(slot, isPaused)
}
emit ToggleFunctionPaused(funcId, !isPaused, isPaused);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the event should rather be called
ToggledFunctionPause
(toggle is the verb here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/ILoanTokenModules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface ILoanTokenModules {

event SetTransactionLimits(address[] addresses, uint256[] limits);

event ToggleFunctionPaused(string functionId, bool prevFlag, bool newFlag);

/** INTERFACE */

/** START LOAN TOKEN SETTINGS LOWER ADMIN */
Expand Down
18 changes: 15 additions & 3 deletions tests/loan-token/Administration.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { expect } = require("chai");
const { expectRevert, BN } = require("@openzeppelin/test-helpers");
const { expectRevert, BN, expectEvent } = require("@openzeppelin/test-helpers");
const LoanToken = artifacts.require("LoanToken");
const LoanTokenLogicBeacon = artifacts.require("LoanTokenLogicBeacon");
const LoanTokenLogicProxy = artifacts.require("LoanTokenLogicProxy");
Expand Down Expand Up @@ -131,15 +131,27 @@ contract("LoanTokenAdministration", (accounts) => {
// pause the given function and make sure the function can't be called anymore
let localLoanToken = loanToken;
await localLoanToken.setPauser(accounts[0]);
await localLoanToken.toggleFunctionPause(functionSignature, true);
let tx = await localLoanToken.toggleFunctionPause(functionSignature, true);
expectEvent(tx, "ToggleFunctionPaused", {
functionId: functionSignature,
prevFlag: false,
newFlag: true,
});
await expectRevert(localLoanToken.toggleFunctionPause(functionSignature, true), "invalid");

await expectRevert(open_margin_trade_position(loanToken, RBTC, WRBTC, SUSD, accounts[1]), "unauthorized");

// check if checkPause returns true
assert(localLoanToken.checkPause(functionSignature));

await localLoanToken.setPauser(accounts[0]);
await localLoanToken.toggleFunctionPause(functionSignature, false);
tx = await localLoanToken.toggleFunctionPause(functionSignature, false);
expectEvent(tx, "ToggleFunctionPaused", {
functionId: functionSignature,
prevFlag: true,
newFlag: false,
});
await expectRevert(localLoanToken.toggleFunctionPause(functionSignature, false), "invalid");
await open_margin_trade_position(loanToken, RBTC, WRBTC, SUSD, accounts[1]);

// check if checkPause returns false
Expand Down