-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/oracle-struct' into feat/max-clamp-per-trade
- Loading branch information
Showing
7 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"constant_product_hash": "0xadeb5412c0cc65b7731f7190a28411dee2e89236f5e304ae49d1f90501134e06", | ||
"factory_hash": "0x4e6ccdb29abe10d6374353935f08b1c008defaddab9aab32c6531161a3ed7826", | ||
"oracle_caller_hash": "0xf31d810e0940d59eb76303615744d1837449efb8575274db894f243eddb2c304", | ||
"stable_hash": "0xca90854439397b4f6bbaac64acdaaa1538802c2bc6c9951ac4a161e7c60a4528" | ||
"constant_product_hash": "0x5c457dc7ab8cc4db0c7088c12fb2c35971517bc18be0788a37a31551f3acfb3c", | ||
"factory_hash": "0xef85bf001813a3ca09b7d4c95f39f3d733812fcf381a373bd5beb89a748ddc5b", | ||
"oracle_caller_hash": "0xb747bec5b4d21e05eff52d57f42c366b975aa81f8626d91205c6a3b31b853dc7", | ||
"stable_hash": "0xe466a25862b9f9c9c3183f4c99f73af1e647bdd2feea892aff546338cccba39e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
pragma solidity ^0.8.0; | ||
|
||
library Buffer { | ||
// The buffer is a circular storage structure with 2048 (2 ** 11) slots. | ||
uint16 public constant SIZE = 2048; | ||
|
||
/** | ||
* @dev Returns the index of the element before the one pointed by `index`. | ||
*/ | ||
function prev(uint16 index) internal pure returns (uint16) { | ||
return sub(index, 1); | ||
} | ||
|
||
/** | ||
* @dev Returns the index of the element after the one pointed by `index`. | ||
*/ | ||
function next(uint16 index) internal pure returns (uint16) { | ||
return add(index, 1); | ||
} | ||
|
||
/** | ||
* @dev Returns the index of an element `offset` slots after the one pointed by `index`. | ||
*/ | ||
function add(uint16 index, uint16 offset) internal pure returns (uint16) { | ||
unchecked { | ||
return (index + offset) % SIZE; | ||
} | ||
} | ||
|
||
/** | ||
* @dev Returns the index of an element `offset` slots before the one pointed by `index`. | ||
*/ | ||
function sub(uint16 index, uint16 offset) internal pure returns (uint16) { | ||
unchecked { | ||
return (index + SIZE - offset) % SIZE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { Buffer } from "src/libraries/Buffer.sol"; | ||
|
||
contract BufferTest is Test { | ||
using Buffer for uint16; | ||
|
||
function testPrev_AtLimit() external { | ||
// arrange | ||
uint16 lIndex = 0; | ||
|
||
// act & assert | ||
assertEq(lIndex.prev(), Buffer.SIZE - 1); | ||
} | ||
|
||
function testNext_AtLimit() external { | ||
// arrange | ||
uint16 lLimit = Buffer.SIZE - 1; | ||
|
||
// act & assert | ||
assertEq(lLimit.next(), 0); | ||
} | ||
|
||
function testNext_GreaterThanBufferSize(uint16 aStartingIndex) external { | ||
// assume | ||
uint16 lStartingIndex = uint16(bound(aStartingIndex, Buffer.SIZE, type(uint16).max)); | ||
|
||
// act & assert | ||
unchecked { | ||
assertEq(lStartingIndex.next(), (lStartingIndex + 1) % Buffer.SIZE); | ||
} | ||
assertLt(lStartingIndex.next(), Buffer.SIZE); // index returned always within bounds of Buffer.SIZE | ||
} | ||
|
||
function testAdd_IndexGreaterThanBufferSize(uint16 aStartingIndex, uint16 aOffset) external { | ||
// assume | ||
uint16 lStartingIndex = uint16(bound(aStartingIndex, Buffer.SIZE, type(uint16).max)); | ||
|
||
// act | ||
uint16 lResult = lStartingIndex.add(aOffset); | ||
|
||
// assert | ||
assertLt(lResult, Buffer.SIZE); | ||
} | ||
|
||
function testSub_IndexGreaterThanBufferSize(uint16 aStartingIndex, uint16 aOffset) external { | ||
// assume | ||
uint16 lStartingIndex = uint16(bound(aStartingIndex, Buffer.SIZE, type(uint16).max)); | ||
|
||
// act | ||
uint16 lResult = lStartingIndex.sub(aOffset); | ||
|
||
// assert | ||
assertLt(lResult, Buffer.SIZE); | ||
} | ||
} |