eliotstock / dro

Uniswap v3 dynamic range orders
0 stars 1 forks source link

Assess performance of re-ranging functions #25

Closed eliotstock closed 2 years ago

eliotstock commented 2 years ago

We often re-range in a fast moving market. We should aim to minimise the time elapsed between determining the optimal swap amount and adding liquidity in the new position. The longer this takes, the more value we're left with in our account after the add liquidity transaction, at least in a fast moving market.

eg:

[480] Unclaimed fees: 727.86 USD
[480] removeLiquidity() Total gas cost: 67.24 [wrong, because of a restart]
Result:
{ stmt: Statement { stmt: undefined }, lastID: 0, changes: 1 }
Balances: USDC 44925.11, WETH 0.0954, ETH 0.1184
[480] Range: 3,442.65 <-> 3,611.91
04-03-22:03:20 #14515699 67.9 gwei 3,535.80 USDC
[480] swapOptimally() Input token is USDC, price: 0.0003 WETH, input balance: 44925.11 USDC, output balance: 0.0954 WETH, zeroForOne: true
04-03-22:03:23 #14515700 70.0 gwei 3,536.50 USDC
[480] swapOptimally() Optimal ratio from AlphaRouter: 0.0000000045021049
[480] swapOptimally() Optimal swap is from 19602.471178 USDC
04-03-22:03:44 #14515703 58.6 gwei 3,538.27 USDC
[480] topUpEth() Running low on ETH. Unwrapping some WETH to top up.
Unwrapping 0.0746 WETH to ETH
04-03-22:04:11 #14515706 56.9 gwei 3,539.33 USDC
[480] addLiquidity() Position URL: https://app.uniswap.org/#/pool/217169
Balances: USDC 0.0, WETH 0.2594, ETH 0.1379

Time between the swap and the add looks like about a minute here.

Look at parallelising some awaits in the code.

One re-range out of three on average we're also unwrapping some WETH to ETH to cover tx costs. Could this be done after the re-range?

eliotstock commented 2 years ago

Added some logging for this. Will watch it.

eliotstock commented 2 years ago

This is typical for L1 so far:

[600] Remove/swap/add roundtrip took 89s

eliotstock commented 2 years ago

Now looking at how much of that time is spent awaiting transactions.

eliotstock commented 2 years ago

I merged lots of performance optimisations from the refactor branch into main today. Waiting on the first re-range on L1 with these changes in to see how things have improved.

eliotstock commented 2 years ago

L1 roundtrip now taking about 80s. Done.