Files
tycho-protocol-sdk/substreams/ethereum-uniswap-v4/ethereum-uniswap-v4.yaml
tvinagre af8643ecb4 feat: Implement UniswapV4 Native integration (#125)
* feat: initial data structure + ABI & buf models

* feat: initial modules: identify new pools and events

* feat: map liquidity and balance changes, introduce balance delta calculation from liquidity

* feat: map tick deltas

* chore: undo weird formatting

* chore: undo weird formatting

* feat: map fee changes and aggregate data to final block structure

* feat: reimplement math natively, remove alloy and univ3sdk dependencies

* chore: make clippy happy + misc improvements

* chore: add rust generated files from buf & ABI

* chore: make clippy happy

* feat: add all modules to ethereum-uniswap-v4.yaml

* chore: update yaml file to skip unnecessary buf paths

* fix: update pb mod.rs

* fix: fix hex / utf-8 encoding. working version

* fix: simplify error handling, rename yaml file to match chain & formatting

* fix: fix ChangeType for sqrt_price_x96 on Initialization

* fix: make fee a non-static attribute

* fix: add balance_owner to univ4 pool

* feat: add uniswap-v4 mainnet yaml

* fix(uniswap-v4): miscellaneous fixes for UniswapV4 (#147)

* fix(uniswap-v4): correctly decode swap event deltas.

Deltas are given from a user debt perspective by the event (negative if received by the pool, positive if sent by the pool). In our usecase we need the opposite of this. This commit uses `.neg()` on the amount to apply them correctly.

* fix(uniswap-v4): correctly compute token amounts.

We were using `get_sqrt_ratio_at_tick` at the current tick to compute the amounts. This was incorrect because it provides the price at the tick boundary, but we might be mid-tick, which could lead to erroneous balances.

We now track the current price (updated by `initialization` and `swap` events) and use it when calculating the amounts.

* fix(uniswapv4): do not account for fees in swaps.

Previously we were adding fees as balances. But they are actually not part of the TVL and we aren't accounting for fees in the position changes (withdrawals). This commit addresses this and remove the fees from the token balances.

* refactor: fix pb mod.rs

* refactor: bump version and update sepolia config

* ci: make clippy happy

* refactor: clean unimath tests

* refactor: make logic clearer and improve docstrings

---------

Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>

---------

Co-authored-by: Zizou <111426680+zizou0x@users.noreply.github.com>
Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
2025-02-05 14:19:09 +01:00

139 lines
2.9 KiB
YAML

specVersion: v0.1.0
package:
name: "ethereum_uniswap_v4"
version: v0.1.1
protobuf:
files:
- tycho/evm/v1/entity.proto
- tycho/evm/v1/common.proto
- tycho/evm/v1/utils.proto
- uniswap.proto
importPaths:
- ../../proto
- ./proto
excludePaths:
- sf/ethereum
- sf/substreams
- google
binaries:
default:
type: wasm/rust-v1
file: ../target/wasm32-unknown-unknown/release/ethereum_uniswap_v4.wasm
modules:
- name: map_pools_created
kind: map
initialBlock: 21688329
inputs:
- params: string
- source: sf.ethereum.type.v2.Block
output:
type: proto:tycho.evm.v1.BlockEntityChanges
- name: store_pools
kind: store
initialBlock: 21688329
updatePolicy: set_if_not_exists
valueType: proto:uniswap.v4.Pool
inputs:
- map: map_pools_created
- name: map_events
kind: map
initialBlock: 21688329
inputs:
- source: sf.ethereum.type.v2.Block
- store: store_pools
output:
type: proto:uniswap.v4.Events
- name: store_pool_current_tick
kind: store
initialBlock: 21688329
updatePolicy: set
valueType: int64
inputs:
- map: map_events
- name: store_pool_current_sqrt_price
kind: store
initialBlock: 21688329
updatePolicy: set
valueType: bigint
inputs:
- map: map_events
- name: map_balance_changes
kind: map
initialBlock: 21688329
inputs:
- map: map_events
- store: store_pool_current_sqrt_price
output:
type: proto:tycho.evm.v1.BlockBalanceDeltas
- name: store_pools_balances
kind: store
initialBlock: 21688329
updatePolicy: add
valueType: bigint
inputs:
- map: map_balance_changes
- name: map_ticks_changes
kind: map
initialBlock: 21688329
inputs:
- map: map_events
output:
type: proto:uniswap.v4.TickDeltas
- name: store_ticks_liquidity
kind: store
initialBlock: 21688329
updatePolicy: add
valueType: bigint
inputs:
- map: map_ticks_changes
- name: map_liquidity_changes
kind: map
initialBlock: 21688329
inputs:
- map: map_events
- store: store_pool_current_tick
output:
type: proto:uniswap.v4.LiquidityChanges
- name: store_liquidity
kind: store
initialBlock: 21688329
updatePolicy: set_sum
valueType: bigint
inputs:
- map: map_liquidity_changes
- name: map_protocol_changes
kind: map
initialBlock: 21688329
inputs:
- source: sf.ethereum.type.v2.Block
- map: map_pools_created
- map: map_events
- map: map_balance_changes
- store: store_pools_balances
mode: deltas
- map: map_ticks_changes
- store: store_ticks_liquidity
mode: deltas
- map: map_liquidity_changes
- store: store_liquidity
mode: deltas
output:
type: proto:tycho.evm.v1.BlockChanges
params:
map_pools_created: "000000000004444c5dc75cB358380D2e3dE08A90"