reservoir-labs / oracle

GNU General Public License v3.0
0 stars 0 forks source link

feat: `SLOAD` optimized route and price #3

Closed xenide closed 6 months ago

xenide commented 7 months ago

Currently

best case scenario:

worst case scenario:

Implemented solution

best case scenario:

Worst case scenario:

Potential Further improvements

  1. we can split some addresses over two words
    • i.e. storing 11 bytes in the previous word and then 9 bytes in the next word
    • e.g. 3 hop route (total 63 bytes of data)
      • instead of reading 3 slots for the route, we only have to read 2 slots
      • so we save 1 SLOAD
  2. Storing the decimal multipliers in the unused bits in the slot
    • if we do this then we won't be able to do improvement no.1

Alternatives tried

  1. Tried using the following:
mapping(address token0 => mapping(address token1 => bytes wtv))

Doesn't work because the the bytes will track length. So that's one more SLOAD

  1. also tried
mapping(address token0 => mapping(address token1 => bytes wtv))[0:32]

doesn't even compile