-
Notifications
You must be signed in to change notification settings - Fork 258
Presentation compare continuous time swaps
⚠ This file is automatically generated from this org file using this script.
The exported presentation can be accessed via this githack link.
REVISIONS:
Date | Notes |
2024-04-04 | EthereumZuri.ch 2024 presentation |
- Why you should trade time-continously.
- What the different designs of decentralized exchange are.
- Beneath the surface: functional reactive programming.
- Reference: https://advisor.visualcapitalist.com/cost-of-trying-to-time-the-market/
- Reference: https://advisor.visualcapitalist.com/cost-of-trying-to-time-the-market/
- user: a normal ethereum user who sends transactions.
- searcher: advanced ethereum user specialized in finding MEV opportunities and sending advanced transaction types like bundles.
- builder: party specialized in the construction of ethereum execution payloads using transactions received from users and searchers (trusted by searchers and users for fair inclusion).
- validator: party which signs and submits a beacon block to the network. It is also called proposer, hence the term PBS (Proposer Builder Separation).
(courtesy to https://flashbots.mirror.xyz/)
This is possible because the transaction is transparent through out the supply chain (with PBS, where 95% of validators are utilizing it.)
Let swaps happen (virtually) every block, modeled with continuous-time:
- avoid market timing.
- minimize single-block MEV.
SageMath is a free open-source mathematics software system licensed under the GPL.
from sage.all import var, assume, function, solve
def CLP(x, y, x_prime, y_prime):
"""Constant Liquidity Product Swap"""
return x * y == x_prime * y_prime
def CLP(x, y, x_prime, y_prime):
"""Constant Liquidity Product Swap"""
return x * y == x_prime * y_prime
def solve_clp_a4b():
print("# Solve CLP equation for selling A for B instantly\n")
v_a = var("a_Δ")
v_b = var("b_Δ")
clp = CLP(
L_a,
L_b,
L_a + v_a,
L_b + v_b
)
sols = solve(clp, v_b)
assert(len(sols) == 1)
print(sols[0])
print("\n")
Constant (Liquidity) Product Formula: $$LbΔ = \frac{L_b * a_Δ}{L_a + a_Δ}$$
def CLP(x, y, x_prime, y_prime):
"""Constant Liquidity Product Swap"""
return x * y == x_prime * y_prime
def solve_rclp_rtb_bidir():
print("# Solve Reactive CLP rtb_bidir equation\n")
cf_a = r_a * (t - t_0)
cf_b = r_b * (t - t_0)
q = var("q")
clp = CLP(
L_a,
L_b,
L_a + cf_a + q * cf_b,
L_b + cf_b + 1/q * cf_a
)
sols = solve(clp, q)
print("L_{flowswap_a} =", (1/q * cf_a).subs(sols[0]))
print("L_{flowswap_b} =", (q * cf_b).subs(sols[0]))
print("\n")
“Reactified” Constant (Liquidity) Product Formula: $$Lflowswap_a = \frac{-(r_b * t_Δ - L_b) * r_a * t_Δ}{r_a * t_Δ + L_a}$$
- Liquidity bootstrap required (TVL == funds at risk): Yes
- LP Complexity: almost same as Uniswap V2
- Single-block MEV: safe
Like an “Aqueduct” that routes money streams.
- Liquidity bootstrap required (TVL == funds at risk): No
- LP Complexity: high complexity with an unconventional model
- Single-block MEV: safe
- TWAP stands for “Time Weighted Average Price”. TWAP was added in Uniswap v2 and improved in Uniswap v3.
- A price cumulative is re-calibrated with each swap, its value changes per each block.
- One can observe price cumulatives of two time points, and calculate the average price of that time window.
Note: Uniswap V3 differs in using geometric mean instead.
Comparing two weeks data of OP-USDC spot prices (from Yahoo Finance) and the average prices sinces the last observation (green dots):
- Liquidity bootstrap required (TVL == funds at risk): No
- LP Complexity: simple (one benchmark price), flexible (agnostic liquidity source) and competitive
- Single-block MEV: safe for traders, leaving the challenges to competitive liquidity movers.
- Reference: https://www.paradigm.xyz/2021/07/twamm
- “The Time-Weighted Average Market Maker (TWAMM) provides the on-chain equivalent of the TWAP order.”
- “Because it processes trades in between blocks, it is also less susceptible to sandwich attacks.”
Without it, these designs cannot be implemented effectively.
- ERC20 compatible.
- Wrapping existing ERC20 tokens (upgrade) or pure super tokens.
- Providing programmable money streams.
- Composable, hence the “just-in-time” liquidity that minimizes idle liquidity.
Design | Liquidity Bootstrap Required | LP Complexity | MEV Safety |
“FlowSwap” | Yes | Same as Uniswap V2 | Safe |
Zero-intermediate-liquidity Market Maker | No | High and unconventional | Safe |
Twap-ORacle EXange (TOREX) | No | simple, flexiby and competitive | Safe* |
(*) Liquidity movers must mitigate the challenge themselves to compete.
- Modeling a problem domain explicitly with time is also called functional reactive programming (FRP).
- The original formulation of functional reactive programming can be found in the ICFP 97 paper Functional Reactive Animation by Conal Elliott and Paul Hudak.
- Hence, we also call exchanges that do continuous-time swaps “reactive exchanges.”
Following the progress of TOREX implementation on:
- https://warpcast.com/superboring
- https://warpcast.com/superfluid
The source of this slide is available from https://github.com/superfluid-finance/protocol-monorepo/wiki by searching “continuous time swaps” Presentation-compare-continuous-time-swaps/source-from-github-wiki.png
- Governance Overview
- For Contributors
- Development Process
- Protocol EVMv1 Operations
- Protocol EVMv1 Technical Notes
- Protocol EVMv1 Core Subgraph