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

fix(contracts): rename OverflowSafeComparator #149

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion contracts/Ticket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "./libraries/OverflowSafeComparator.sol";
import "./libraries/TwabLib.sol";
import "./interfaces/ITicket.sol";
import "./ControlledToken.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/ObservationLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity 0.8.6;

import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "./OverflowSafeComparator.sol";
import "./OverflowSafeComparatorLib.sol";
import "./RingBuffer.sol";

/// @title Observation Library
/// @notice This library allows one to store an array of timestamped values and efficiently binary search them.
/// @dev Largely pulled from Uniswap V3 Oracle.sol: https://github.com/Uniswap/v3-core/blob/c05a0e2c8c08c460fb4d05cfdda30b3ad8deeaac/contracts/libraries/Oracle.sol
/// @author PoolTogether Inc.
library ObservationLib {
using OverflowSafeComparator for uint32;
using OverflowSafeComparatorLib for uint32;
using SafeCast for uint256;

/// @notice The maximum number of observations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

pragma solidity 0.8.6;

/// @title OverflowSafeComparator library to share comparator functions between contracts
/// @title OverflowSafeComparatorLib library to share comparator functions between contracts
/// @dev Code taken from Uniswap V3 Oracle.sol: https://github.com/Uniswap/v3-core/blob/3e88af408132fc957e3e406f65a0ce2b1ca06c3d/contracts/libraries/Oracle.sol
/// @author PoolTogether Inc.
library OverflowSafeComparator {
library OverflowSafeComparatorLib {
/// @notice 32-bit timestamps comparator.
/// @dev safe for 0 or 1 overflows, `_a` and `_b` must be chronologically before or equal to time.
/// @param _a A comparison timestamp from which to determine the relative position of `_timestamp`.
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/TwabLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ pragma solidity 0.8.6;
import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "./ExtendedSafeCast.sol";
import "./OverflowSafeComparator.sol";
import "./OverflowSafeComparatorLib.sol";
import "./RingBuffer.sol";
import "./ObservationLib.sol";

/// @title Time-Weighted Average Balance Library
/// @notice This library allows you to efficiently track a user's historic balance.
/// @author PoolTogether Inc.
library TwabLib {
using OverflowSafeComparator for uint32;
using OverflowSafeComparatorLib for uint32;
using ExtendedSafeCast for uint256;

/// @notice The maximum number of twab entries
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/TwabLibraryExposed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity 0.8.6;
import "../libraries/TwabLib.sol";
import "../libraries/RingBuffer.sol";

/// @title OverflowSafeComparator library to share comparator functions between contracts
/// @title TwabLibExposed contract to test TwabLib library
/// @author PoolTogether Inc.
contract TwabLibExposed {
uint24 public constant MAX_CARDINALITY = 16777215;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

pragma solidity 0.8.6;

import "../../libraries/OverflowSafeComparator.sol";
import "../../libraries/OverflowSafeComparatorLib.sol";

contract OverflowSafeComparatorHarness {
using OverflowSafeComparator for uint32;
contract OverflowSafeComparatorLibHarness {
using OverflowSafeComparatorLib for uint32;

function ltHarness(
uint32 _a,
Expand Down
36 changes: 18 additions & 18 deletions test/libraries/OverflowSafeComparator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { ethers } from 'hardhat';

const { provider } = ethers;

describe('overflowSafeComparator', () => {
let overflowSafeComparator: Contract;
describe('overflowSafeComparatorLib', () => {
let overflowSafeComparatorLib: Contract;
let currentTimestamp: number;

beforeEach(async () => {
currentTimestamp = (await provider.getBlock('latest')).timestamp;

const overflowSafeComparatorFactory: ContractFactory = await ethers.getContractFactory(
'OverflowSafeComparatorHarness',
const overflowSafeComparatorLibFactory: ContractFactory = await ethers.getContractFactory(
'OverflowSafeComparatorLibHarness',
);
overflowSafeComparator = await overflowSafeComparatorFactory.deploy();
overflowSafeComparatorLib = await overflowSafeComparatorLibFactory.deploy();
});

describe('lt()', () => {
Expand All @@ -23,7 +23,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp - 100;

expect(
await overflowSafeComparator.ltHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.ltHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});

Expand All @@ -32,7 +32,7 @@ describe('overflowSafeComparator', () => {
const timestampB = timestampA;

expect(
await overflowSafeComparator.ltHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.ltHarness(timestampA, timestampB, currentTimestamp),
).to.equal(false);
});

Expand All @@ -41,7 +41,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp + 1000;

expect(
await overflowSafeComparator.ltHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.ltHarness(timestampA, timestampB, currentTimestamp),
).to.equal(false);
});

Expand All @@ -50,7 +50,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp - 1000;

expect(
await overflowSafeComparator.ltHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.ltHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});

Expand All @@ -59,7 +59,7 @@ describe('overflowSafeComparator', () => {
const timestampB = timestampA;

expect(
await overflowSafeComparator.ltHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.ltHarness(timestampA, timestampB, currentTimestamp),
).to.equal(false);
});
});
Expand All @@ -70,7 +70,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp - 100;

expect(
await overflowSafeComparator.lteHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.lteHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});

Expand All @@ -79,7 +79,7 @@ describe('overflowSafeComparator', () => {
const timestampB = timestampA;

expect(
await overflowSafeComparator.lteHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.lteHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});

Expand All @@ -88,7 +88,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp + 1000;

expect(
await overflowSafeComparator.lteHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.lteHarness(timestampA, timestampB, currentTimestamp),
).to.equal(false);
});

Expand All @@ -97,7 +97,7 @@ describe('overflowSafeComparator', () => {
const timestampB = currentTimestamp - 1000;

expect(
await overflowSafeComparator.lteHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.lteHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});

Expand All @@ -106,14 +106,14 @@ describe('overflowSafeComparator', () => {
const timestampB = timestampA;

expect(
await overflowSafeComparator.lteHarness(timestampA, timestampB, currentTimestamp),
await overflowSafeComparatorLib.lteHarness(timestampA, timestampB, currentTimestamp),
).to.equal(true);
});
});

describe('checkedSub()', () => {
it('should calculate normally', async () => {
expect(await overflowSafeComparator.checkedSub(10, 4, 10)).to.equal(6);
expect(await overflowSafeComparatorLib.checkedSub(10, 4, 10)).to.equal(6);
});

it('should handle overflow of a', async () => {
Expand All @@ -122,7 +122,7 @@ describe('overflowSafeComparator', () => {
const firstTimestamp = 2 ** 32 + (secondTimestamp - 1); // just before the answer overflows

expect(
await overflowSafeComparator.checkedSub(
await overflowSafeComparatorLib.checkedSub(
firstTimestamp,
secondTimestamp,
firstTimestamp,
Expand All @@ -136,7 +136,7 @@ describe('overflowSafeComparator', () => {
const firstTimestamp = 2 ** 32 + 200;

expect(
await overflowSafeComparator.checkedSub(
await overflowSafeComparatorLib.checkedSub(
firstTimestamp,
secondTimestamp,
firstTimestamp,
Expand Down