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

Added a spread bound check in the setSpread function #9252

Merged
merged 7 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions packages/protocol/contracts/stability/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ contract Exchange is
*/
function setSpread(uint256 newSpread) public onlyOwner {
spread = FixidityLib.wrap(newSpread);
require(
FixidityLib.lte(spread, FixidityLib.fixed1()),
"the value of spread must be less than or equal to 1"
);
emit SpreadSet(newSpread);
}

Expand Down
6 changes: 5 additions & 1 deletion packages/protocol/test/stability/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ contract('Exchange', (accounts: string[]) => {

describe('#setSpread', () => {
const newSpread = toFixed(6 / 1000)

it('should set the spread', async () => {
await exchange.setSpread(newSpread)

Expand All @@ -305,6 +304,11 @@ contract('Exchange', (accounts: string[]) => {
assert.isTrue(actualSpread.eq(newSpread))
})

it('the spread should always be less than or equal to 1', async () => {
assert.isTrue(fixed1.gte(newSpread))
ninabarbakadze marked this conversation as resolved.
Show resolved Hide resolved
await assertRevert(exchange.setSpread(toFixed(1001 / 1000)))
})

it('should emit a SpreadSet event', async () => {
const tx = await exchange.setSpread(newSpread)
assert(tx.logs.length === 1, 'Did not receive event')
Expand Down