Skip to content

Commit

Permalink
Added a spread bound check in the setSpread function (#9252)
Browse files Browse the repository at this point in the history
### Description

_A few sentences describing the overall effects and goals of the pull request's commits.
What is the current behavior, and what is the updated/expected behavior with this PR?_
I've created a bound check for the spread to make sure that its value never exceeds 1.
### Other changes

_Describe any minor or "drive-by" changes here._

### Tested

_An explanation of how the changes were tested or an explanation as to why they don't need to be._
I've added a condition in the test suite which checks, that the value of spread shouldn't exceed 1.
### Related issues

- Fixes #[issue number here]

### Backwards compatibility

_Brief explanation of why these changes are/are not backwards compatible._

### Documentation

_The set of community facing docs that have been added/modified because of this change_
  • Loading branch information
ninabarbakadze authored Feb 1, 2022
1 parent 0871aec commit a871e15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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
5 changes: 4 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,10 @@ contract('Exchange', (accounts: string[]) => {
assert.isTrue(actualSpread.eq(newSpread))
})

it('the spread should always be less than or equal to 1', async () => {
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

0 comments on commit a871e15

Please sign in to comment.