Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maoueh/substreams-eth-absrel
Showcase how one can solve two series of events, one emitting relative values the other absolute
https://github.com/maoueh/substreams-eth-absrel
Last synced: 2 days ago
JSON representation
Showcase how one can solve two series of events, one emitting relative values the other absolute
- Host: GitHub
- URL: https://github.com/maoueh/substreams-eth-absrel
- Owner: maoueh
- Created: 2024-05-07T01:04:21.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-05-07T01:08:41.000Z (5 months ago)
- Last Synced: 2024-05-07T02:27:50.552Z (5 months ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Substreams Ethereum - Absolute/Relative Problem
It happens that some contracts specifies events to report delta values and on other event using absolute values to represent a single entity.
Uniswap V3 Pool contract is an example of this. The `Mint` and `Burn` events are emitting relative values while `Swap` event emits absolute values for the same entity, one of the pool's token.
### Solution
To achieve that in Substreams, accumulate all the relative values in one store, accumulate all the "latest" value in another store. Then in a mapper/store that depends on those 2 stores, reconcile both values by adding the summed up relative values against the latest value.
- See [store_mint_burn_liquidity](./src/lib.rs#L41-L69) for accumulation of Mint/Burn relative values.
- See [store_swap_liquidity](./src/lib.rs#L72-86) for accumulation of Swap absolute values.
- See [map_output](./src/lib.rs#L89-103) for merging of relative values with absolute values to from a single store value.