Skip to content

Commit

Permalink
feat: price oracle
Browse files Browse the repository at this point in the history
* feat: getLatest
* feat: getTimeWeightedAverage
* feat: add error for invalid pairs
* test: add test for samples
* docs: update enum docs
* lint: forge fmt
* test: setup scaffold and infra
* test: testGetInstantValue_NotInitialized
* test: findNearestSample
* test: more error test cases
* test: introduce wrapper for QueryProcessor
* test: getPastAccumulator
* test: extrapolating
* test: interpolating
* test: fix logic error
* refactor: no longer passing struct to lib function
* feat: add `unchecked` to arithmetic operations
* lint: forge fmt
* test: getTimeWeightedAverage
* fix: make `updateOracle` emit an event
* test: wip adding tests
* test: `block.basefee`
* docs: update comment for using `block.basefee`
* refactor: move function around
* chore: import euler's `IPriceOracle`
* feat: introduce `Utils`
* test: furnish cases
* feat: reentrancy guard for certain functions
* fix: change max price deviation threshold to 10%
* refactor: change func sig for `updatePrice`
* docs: note idea
* fix: rm `name` function from interface
* feat: `ReservoirPriceCache::setRoute`
* test: complete `ReservoirPriceCache::setRoute` test suite
* refactor: use base class for test
* fix: extra step in test setUp
* fix: updating logic for `_getQuote`
* test: use `deployCodeTo` to have contracts at known addresses
* wip: multiple hops for getQuote
* docs: add docs for storage variables
* refactor: avoiding repeating hardcoded values
* fix: price inversion logic
* fix: rm `isPriceUpdateIncentivized` function
* refactor: make tests inherit from `BaseTest`
* test: furnish many more cases for `updatePrice`
* test: some cases for `ReservoirPriceOracle`
* test: `getLatest`
* test: `getPastAccumulators`
* refactor: select all for using directive
* test: getTimeWeightedAverage
* doc: add todo
* fix: merge `ReservoirPriceCache` and `ReservoirPriceOracle`
* fix: logic optimizations
* fix: change error message
* test: address todo and add assert conditions
* fix: rm unused error
* fix: PR comments
* fix: update interface after euler's vault kit release
* feat: `SLOAD` optimized route and price
* wip: `setRoute` and `clearRoute`
* refactor: use `_calculateSlot` internal function
* fix: emit event for `clearRoute`
* fix: route between last and second last token
* test: fix order of `expectEmit`
* feat: `route`
* refactor: use `_route` internal function
* feat: new implementation for price cache
* feat: new implementation for `_getQuote`
* fix: rm console2 import
* feat: complete `clearRoute`
* feat: allow `updatePrice` to specify address(0) when not seeking reward
* docs: rm comment
* fix: do not shift address by 88 bits
* docs: improve docs on assembly
* refactor: streamline logic for populating intermediate routes
* refactor: re-use shared variable
* docs: add comment
* docs: update comments
* docs: update comment
* wip: integrating decimal diff into data structure
* fix: make `_priceCache` return the decimal diff as well
* fix: price calculation works now
* wip: squeezing route data into two words
* refactor: store decimal differences in the second byte instead combining with route flag in the first
* feat: packing a 3 hop route within two words
* test: update req condition
* fix: handle price when any hop's price is zero
* docs: clarify comment on receiving ether as reward
* test: fuzz everything one hop
* test: randomize all 2 hop route
* fix: decimal bug for intermediate route
* test: finish 2 hop randomize everything test
* forge install: solady
v0.0.201
* test: use `EnumerableSetLib` to keep track of existing addresses
* test: 3 hop test working
* test: tighten assert condition
* ci: enable `via-ir` to make test run
* test: rm scratch tests
* feat: return original amount for same base quote scenario
* fix: handle case where `updatePrice` gives a price out of range
* chore: rm unused reentrancy modifiers
* refactor: put all errors into the `OracleErrors` lib
* fix: calculate using intermediate amounts
* fix: do not support reverse order of token for `getTimeWeightedAverage`
* chore: upgrade solidity version to 0.8.26
* fix: use sequenced mul and div instead of inverting prices
* feat: save 1 sload for 2 hop routes
* refactor: move packing and bit shifting operations into lib
* chore: change solc target back to 0.8.25
* docs: add safety comments for unchecked arithmetic
* feat: introduce `MAX_SUPPORTED_PRICE` and `MAX_AMOUNT_IN`
* ci: change solc target to 0.8.26
* fix: enforce only ordered token for raw oracle query
* lint: forge fmt
* docs: update safety comment on unchecked math
* chore: update license to GPL 3.0
  • Loading branch information
xenide authored Jun 6, 2024
1 parent 5847fcd commit 97a47ab
Show file tree
Hide file tree
Showing 23 changed files with 2,629 additions and 285 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/amm-core"]
path = lib/amm-core
url = https://github.com/reservoir-labs/amm-core
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
solc = "0.8.23"
solc = "0.8.26"
#via_ir = true
bytecode_hash = "ipfs"
optimizer_runs = 1_000_000
Expand All @@ -8,10 +8,10 @@ remappings = [
"amm-core/=lib/amm-core/src/"
]
match_path = "test/unit/*.sol"
block_base_fee_per_gas = 10_000_000 # set to arbitrum's base fee of 0.01 gwei
verbosity = 3
fs_permissions = [
{ access = "write", path = "./script/optimized-deployer-meta" },
{ access = "write", path = "./script/unoptimized-deployer-meta" },
{ access = "read", path = "./out" }
]
ignored_error_codes = []

Expand Down
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at 183a5c
13 changes: 6 additions & 7 deletions src/Enums.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

// The two values that can be queried:
//
// - PAIR_PRICE: the price of the tokens in the Pool, expressed as the price of the second token in units of the
// - RAW_PRICE: the price of the tokens in the Pool, expressed as the price of the second token in units of the
// first token. For example, if token A is worth $2, and token B is worth $4, the pair price will be 2.0.
// Note that the price is computed *including* the tokens decimals. This means that the pair price of a Pool with
// DAI and USDC will be close to 1.0, despite DAI having 18 decimals and USDC 6.
//
// - BPT_PRICE: the price of the Pool share token (BPT), in units of the first token.
// Note that the price is computed *including* the tokens decimals. This means that the BPT price of a Pool with
// USDC in which BPT is worth $5 will be 5.0, despite the BPT having 18 decimals and USDC 6.
//
// - INVARIANT: the value of the Pool's invariant, which serves as a measure of its liquidity.
// - CLAMPED_PRICE: the clamped price of the tokens in the Pool, in units of the first token. Clamping is necessary as
// as a countermeasure to oracle manipulation attempts.
// Refer to `maxChangeRate` and `maxChangePerTrade` in `ReservoirPair` and the `Observation` struct
// Note that the price is computed *including* the tokens decimals, just like the raw price.
enum Variable {
RAW_PRICE,
CLAMPED_PRICE
Expand Down
9 changes: 0 additions & 9 deletions src/Errors.sol

This file was deleted.

174 changes: 0 additions & 174 deletions src/ReservoirPriceCache.sol

This file was deleted.

Loading

0 comments on commit 97a47ab

Please sign in to comment.