* 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>
124 lines
3.1 KiB
Protocol Buffer
124 lines
3.1 KiB
Protocol Buffer
syntax = "proto3";
|
|
|
|
package uniswap.v4;
|
|
|
|
message Pool {
|
|
// // The pool address.
|
|
bytes id = 1;
|
|
// The token0 address.
|
|
bytes currency0 = 2;
|
|
// The token1 address.
|
|
bytes currency1 = 3;
|
|
// The transaction where the pool was created.
|
|
bytes created_tx_hash = 4;
|
|
}
|
|
|
|
// A struct describing a transaction.
|
|
message Transaction {
|
|
// The transaction hash.
|
|
bytes hash = 1;
|
|
// The sender of the transaction.
|
|
bytes from = 2;
|
|
// The receiver of the transaction.
|
|
bytes to = 3;
|
|
// The transactions index within the block.
|
|
uint64 index = 4;
|
|
}
|
|
|
|
// A change to a pool's tick.
|
|
message TickDelta {
|
|
// The address of the pool.
|
|
bytes pool_address = 1;
|
|
// The index of the tick.
|
|
int32 tick_index = 2;
|
|
// The liquidity net delta of this tick. Bigint encoded as signed little endian bytes.
|
|
bytes liquidity_net_delta = 3;
|
|
// Used to determine the order of the balance changes. Necessary for the balance store.
|
|
uint64 ordinal = 4;
|
|
Transaction transaction = 5;
|
|
}
|
|
|
|
// A group of TickDelta
|
|
message TickDeltas {
|
|
repeated TickDelta deltas = 1;
|
|
}
|
|
|
|
// A change to a pool's liquidity.
|
|
message LiquidityChange {
|
|
// The address of the pool.
|
|
bytes pool_address = 1;
|
|
// The liquidity changed amount. Bigint encoded as signed little endian bytes.
|
|
bytes value = 2;
|
|
// The type of update, can be absolute or delta.
|
|
LiquidityChangeType change_type = 3;
|
|
// Used to determine the order of the balance changes. Necessary for the balance store.
|
|
uint64 ordinal = 4;
|
|
Transaction transaction = 5;
|
|
}
|
|
|
|
// A group of LiquidityChange
|
|
message LiquidityChanges {
|
|
repeated LiquidityChange changes = 1;
|
|
}
|
|
|
|
|
|
enum LiquidityChangeType {
|
|
DELTA = 0;
|
|
ABSOLUTE = 1;
|
|
}
|
|
|
|
message Events {
|
|
repeated PoolEvent pool_events = 3;
|
|
|
|
message PoolEvent {
|
|
oneof type {
|
|
Initialize initialize = 1;
|
|
ModifyLiquidity modify_liquidity = 2;
|
|
Swap swap = 3;
|
|
Donate donate = 4;
|
|
ProtocolFeeUpdated protocol_fee_updated = 5;
|
|
}
|
|
uint64 log_ordinal = 100;
|
|
string pool_id = 102; // Changed from pool_address to pool_id as V4 uses PoolId
|
|
string currency0 = 103; // Changed from token0 to currency0
|
|
string currency1 = 104; // Changed from token1 to currency1
|
|
Transaction transaction = 105;
|
|
|
|
message Initialize {
|
|
string sqrt_price_x96 = 1;
|
|
int32 tick = 2;
|
|
uint32 fee = 3;
|
|
int32 tick_spacing = 4;
|
|
string hooks = 5; // Address of the hooks contract
|
|
}
|
|
|
|
message ModifyLiquidity {
|
|
string sender = 1;
|
|
int32 tick_lower = 2;
|
|
int32 tick_upper = 3;
|
|
string liquidity_delta = 4; // Changed to support signed integers
|
|
string salt = 5; // Added salt field
|
|
}
|
|
|
|
message Swap {
|
|
string sender = 1;
|
|
string amount0 = 2; // Signed int128
|
|
string amount1 = 3; // Signed int128
|
|
string sqrt_price_x96 = 4;
|
|
string liquidity = 5;
|
|
int32 tick = 6;
|
|
uint32 fee = 7; // Added fee field
|
|
}
|
|
|
|
message Donate {
|
|
string sender = 1;
|
|
string amount0 = 2;
|
|
string amount1 = 3;
|
|
}
|
|
|
|
message ProtocolFeeUpdated {
|
|
string pool_id = 1;
|
|
uint32 protocol_fee = 2;
|
|
}
|
|
}
|
|
} |