Skip to content

Commit

Permalink
review: initial feedback and questions (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk authored Jun 20, 2024
1 parent 0c71bb1 commit 26353de
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 154 deletions.
128 changes: 64 additions & 64 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
FlagsLibTest:testGetDecimalDifference() (gas: 3974)
FlagsLibTest:testIsCompositeRoute() (gas: 4341)
FlagsLibTest:testPackSimplePrice(int8,uint256) (runs: 256, μ: 7791, ~: 7555)
QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 64954402, ~: 72638370)
QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 65183381, ~: 74353868)
QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 66028796, ~: 73578593)
QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 65574840, ~: 74107585)
QueryProcessorTest:testFindNearestSample_NotInitialized() (gas: 8937393461068805977)
QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 80330, ~: 80360)
QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 80329, ~: 80360)
QueryProcessorTest:testGetInstantValue() (gas: 124248)
QueryProcessorTest:testGetInstantValue_NotInitialized(uint256) (runs: 256, μ: 19397, ~: 19397)
QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 68389670, ~: 68389600)
QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 27026, ~: 27087)
QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 71445048, ~: 79233749)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 70305328, ~: 78329546)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 70335354, ~: 78361146)
QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 65156996, ~: 74325443)
QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 65191146, ~: 74359876)
QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 65148574, ~: 74317294)
QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 65160165, ~: 74326834)
QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 103403746, ~: 113055688)
QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 68389651, ~: 68389600)
QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 27030, ~: 27087)
QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 71569162, ~: 78616628)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69854170, ~: 78381550)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69884111, ~: 78413074)
QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 65548439, ~: 74079107)
QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 65582491, ~: 74113593)
QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 65540049, ~: 74070132)
QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 65551512, ~: 74080359)
QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 105204511, ~: 113027711)
QueryProcessorTest:testGetTimeWeightedAverage_BadSecs() (gas: 10995)
ReservoirPriceOracleTest:testClearRoute() (gas: 52319)
ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 155404)
ReservoirPriceOracleTest:testDesignatePair() (gas: 29102)
ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21222)
ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17553)
ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30740)
ReservoirPriceOracleTest:testClearRoute() (gas: 52160)
ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 155162)
ReservoirPriceOracleTest:testDesignatePair() (gas: 29119)
ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21206)
ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17531)
ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30802)
ReservoirPriceOracleTest:testGasBountyAvailable(uint256) (runs: 256, μ: 9885, ~: 9881)
ReservoirPriceOracleTest:testGasBountyAvailable_Zero() (gas: 8939)
ReservoirPriceOracleTest:testGetLargestSafeQueryWindow() (gas: 8412)
ReservoirPriceOracleTest:testGetLatest(uint32) (runs: 256, μ: 92856, ~: 92787)
ReservoirPriceOracleTest:testGetLatest_Inverted() (gas: 96864)
ReservoirPriceOracleTest:testGetPastAccumulators() (gas: 196417)
ReservoirPriceOracleTest:testGetPastAccumulators_Inverted() (gas: 156850)
ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 35792, ~: 35904)
ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 12985)
ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 445074, ~: 444837)
ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10353280)
ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 37978, ~: 38149)
ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 114609)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 114842)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 127427)
ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 16112)
ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 16519)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5328074, ~: 5328117)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10493915, ~: 10493914)
ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 8985, ~: 8985)
ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 37825)
ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 39322)
ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 33348, ~: 33460)
ReservoirPriceOracleTest:testGetTimeWeightedAverage() (gas: 142014)
ReservoirPriceOracleTest:testGetTimeWeightedAverage_Inverted() (gas: 121185)
ReservoirPriceOracleTest:testGetLargestSafeQueryWindow() (gas: 8390)
ReservoirPriceOracleTest:testGetLatest(uint32) (runs: 256, μ: 92808, ~: 92737)
ReservoirPriceOracleTest:testGetLatest_Inverted() (gas: 96792)
ReservoirPriceOracleTest:testGetPastAccumulators() (gas: 196359)
ReservoirPriceOracleTest:testGetPastAccumulators_Inverted() (gas: 156800)
ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 35815, ~: 35927)
ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 13030)
ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 418332, ~: 418079)
ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10353271)
ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 37979, ~: 38148)
ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 114566)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 114799)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 127407)
ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 21074)
ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 16564)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5328103, ~: 5328201)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10493966, ~: 10494003)
ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 9030, ~: 9030)
ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38776)
ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 39390)
ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 33326, ~: 33438)
ReservoirPriceOracleTest:testGetTimeWeightedAverage() (gas: 141789)
ReservoirPriceOracleTest:testGetTimeWeightedAverage_Inverted() (gas: 120964)
ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 11003)
ReservoirPriceOracleTest:testSetRoute() (gas: 58936)
ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 18049)
ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 17655)
ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 196333)
ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 12117)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 162732)
ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 12070)
ReservoirPriceOracleTest:testUndesignatePair() (gas: 30318)
ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 15288)
ReservoirPriceOracleTest:testUpdatePriceDeviationThreshold(uint256) (runs: 256, μ: 21390, ~: 21152)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold() (gas: 216785)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold_InsufficientReward(uint256) (runs: 256, μ: 205829, ~: 205771)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold_ZeroRecipient() (gas: 198455)
ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 205996)
ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 15872304)
ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5355619)
ReservoirPriceOracleTest:testUpdatePrice_WithinThreshold() (gas: 207028)
ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 19033)
ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 11006)
ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21815, ~: 21892)
ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17894, ~: 18208)
ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30058, ~: 29821)
ReservoirPriceOracleTest:testSetRoute() (gas: 58848)
ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 18005)
ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 17611)
ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 196135)
ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 12095)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 162578)
ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 12048)
ReservoirPriceOracleTest:testUndesignatePair() (gas: 30357)
ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 15332)
ReservoirPriceOracleTest:testUpdatePriceDeviationThreshold(uint256) (runs: 256, μ: 21334, ~: 21085)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold() (gas: 215402)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold_InsufficientReward(uint256) (runs: 256, μ: 204437, ~: 204648)
ReservoirPriceOracleTest:testUpdatePrice_BeyondThreshold_ZeroRecipient() (gas: 197028)
ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 204525)
ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 15869132)
ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5354102)
ReservoirPriceOracleTest:testUpdatePrice_WithinThreshold() (gas: 205557)
ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 19055)
ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 10984)
ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21793, ~: 21870)
ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17858, ~: 18164)
ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30030, ~: 29777)
SamplesTest:testAccumulator() (gas: 3959)
SamplesTest:testAccumulator_BadVariableRequest() (gas: 3523)
SamplesTest:testInstant() (gas: 3909)
Expand Down
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Reservoir Price Oracle

The Reservoir Price Oracle is designed to work with
[Euler Vault Kit](https://github.com/euler-xyz/euler-vault-kit) by implementing
the `IPriceOracle` interface.

This oracle provides a geometric mean price between two assets, averaged across
a period. The geometric mean has a useful property whereby we can get the
inverse price by simply taking the reciprocal. Something that arithmetic mean
prices do not provide.

Powered the built-in on-chain price oracle of Reservoir's [AMM](https://github.com/reservoir-labs/amm-core).

## Interfaces

For more information on the `IPriceOracle` interface, refer to Euler's [documentation](https://github.com/euler-xyz/euler-price-oracle?tab=readme-ov-file#ipriceoracle).

For direct usages of the oracle, refer to
[IReservoirPriceOracle.sol](src/interfaces/IReservoirPriceOracle.sol) for
methods to obtain raw data from the AMM pairs.

## Usage

### Install

To install Price Oracles in a [Foundry](https://github.com/foundry-rs/foundry) project:

```sh
forge install reservoir-labs/oracle
```

### Development

Clone the repo:

```sh
git clone https://github.com/reservoir-labs/oracle.git && cd oracle
```

Install forge dependencies:

```sh
forge install
```

[Optional] Install Node.js dependencies:

```sh
npm install
```

Compile the contracts:

```sh
forge build
```

### Testing

The repo contains 3 types of tests: unit, large, and integration.

To run all tests:

```sh
npm run test:all
```

### Linting

To run lint on solidity, json, and markdown, run:

```sh
npm run lint
```

Separate `.solhint.json` files exist for `src/` and `test/`.

## Security vulnerability disclosure

Please report suspected security vulnerabilities in private to
[[email protected]]([email protected]). Please do NOT create publicly
viewable issues for suspected security vulnerabilities.

## Audits

These contracts have been audited by TBD and TBD auditing firm.

## License

The Euler Price Oracles code is licensed under the [GPL-3.0-or-later](LICENSE) license.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"submodule:check": "cd lib && find . -mindepth 1 -maxdepth 1 -type d -exec bash -c 'cd \"{}\" && pwd && ../../scripts/git-master-diff.sh && echo' \\;",
"submodule:reset": "git submodule update --recursive",
"test": "npm run test:unit",
"test:all": "npm run test:unit && npm run test:integration",
"test:all": "npm run test:unit && npm run test:unit-large && npm run test:integration",
"test:integration": "export FOUNDRY_PROFILE=integration && forge test",
"test:unit": "forge test",
"test:unit-large": "export FOUNDRY_PROFILE=large-test && forge test"
Expand Down
Loading

0 comments on commit 26353de

Please sign in to comment.