From a871e152fa6651f39a732046d9346d97bef1d8b3 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 1 Feb 2022 12:09:44 +0100 Subject: [PATCH] Added a spread bound check in the setSpread function (#9252) ### 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_ --- packages/protocol/contracts/stability/Exchange.sol | 4 ++++ packages/protocol/test/stability/exchange.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/Exchange.sol b/packages/protocol/contracts/stability/Exchange.sol index 074c838222b..9e1268c3e75 100644 --- a/packages/protocol/contracts/stability/Exchange.sol +++ b/packages/protocol/contracts/stability/Exchange.sol @@ -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); } diff --git a/packages/protocol/test/stability/exchange.ts b/packages/protocol/test/stability/exchange.ts index dce03c8e37e..de340307265 100644 --- a/packages/protocol/test/stability/exchange.ts +++ b/packages/protocol/test/stability/exchange.ts @@ -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) @@ -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')