CompassLabs / dojo_examples

A gallery of dojo examples
14 stars 5 forks source link

Example requests for dojo #15

Closed wwklsq closed 1 year ago

wwklsq commented 1 year ago

Hi Team dojo,

I am a beginner with dojo package and struggled a little bit with creating an example script using dojo to provide liquidity and inspect the fees earned in a backtesting manner. So far, I have set up the environment and successfully executed run.py both in notebook as well as in script. Here are the problems I faced today:

Thanks for the great work in general, I hope I can get supports for questions above and more examples from compass labs side regarding this project.

Best regards, Wwk

0xprofessooor commented 1 year ago

New version released, some more changes include:

Still looking into the final edge case, will update with progress :)

wwklsq commented 1 year ago

Hi @09tangriro,

Testing with latest version of dojo, I had follow-up questions:

0xprofessooor commented 1 year ago

We've also found a speed improvement 🎉 The first edge case (STF) in the list now runs successfully for me in 282s (not yet in release).

wwklsq commented 1 year ago

Hi @09tangriro,

Thanks for the quick update, I switch now to local backend type.

[{'start_time': Timestamp('2023-08-17 07:43:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-08-18 10:34:00+0000', tz='UTC'),
  'deposit_token0': 574.861008,
  'deposit_token1': 574.861008,
  'lower_price': 0.0005261,
  'upper_price': 0.00058962,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 3000,
  'dojo_fees_collected_token0': '2.804471',
  'real_fees_collected_token0': 0.581423,
  'dojo_fees_collected_token1': '0.001909294938952954',
  'real_fees_collected_token1': 0.0013293,
  'pool_desc': 'USDC/WETH-0.3',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/551745'},
 {'start_time': Timestamp('2023-04-02 20:13:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-04-04 12:13:00+0000', tz='UTC'),
  'deposit_token0': 39539.1375,
  'deposit_token1': 39539.1375,
  'lower_price': 0.00053565,
  'upper_price': 0.00058962,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 3000,
  'dojo_fees_collected_token0': '304.511513',
  'real_fees_collected_token0': 152.703298,
  'dojo_fees_collected_token1': '0.104557025810633318',
  'real_fees_collected_token1': 0.05234959,
  'pool_desc': 'USDC/WETH-0.3',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/481049'},
 {'start_time': Timestamp('2023-09-15 00:26:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-16 01:34:00+0000', tz='UTC'),
  'deposit_token0': 71236.007076,
  'deposit_token1': 71236.007076,
  'lower_price': 0.00061491,
  'upper_price': 0.00062608,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '180.910437',
  'real_fees_collected_token0': 97.614772,
  'dojo_fees_collected_token1': '0.116631441591324158',
  'real_fees_collected_token1': 0.05905205,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/564394'},
 {'start_time': Timestamp('2023-09-18 13:20:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-19 15:02:00+0000', tz='UTC'),
  'deposit_token0': 2653.713952,
  'deposit_token1': 2653.713952,
  'lower_price': 0.00057506,
  'upper_price': 0.00060576,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '16.987608',
  'real_fees_collected_token0': 7.21048,
  'dojo_fees_collected_token1': '0.010694034637289168',
  'real_fees_collected_token1': 0.00515498,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/565818'},
 {'start_time': Timestamp('2023-09-14 23:57:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-16 06:53:00+0000', tz='UTC'),
  'deposit_token0': 21032.118402,
  'deposit_token1': 21032.118402,
  'lower_price': 0.00060274,
  'upper_price': 0.00061491,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '941.429875',
  'real_fees_collected_token0': 4282.51329,
  'dojo_fees_collected_token1': '0.584749281867812615',
  'real_fees_collected_token1': 2.44181838,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': '[https://revert.finance/#/unis](https://revert.finance/#/uniswap-position/mainnet/564389)
{'start_time': Timestamp('2023-09-11 12:17:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-12 21:49:00+0000', tz='UTC'),
  'deposit_token0': 10153.796168,
  'deposit_token1': 10153.796168,
  'lower_price': 0.00062859,
  'upper_price': 0.00072958,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '1.013681',
  'real_fees_collected_token0': 20.268507,
  'dojo_fees_collected_token1': '0.000594838674044158',
  'real_fees_collected_token1': 0.01295848,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/562977'},
 {'start_time': Timestamp('2023-09-27 11:37:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-28 21:40:00+0000', tz='UTC'),
  'deposit_token0': 9266.97624,
  'deposit_token1': 9266.97624,
  'lower_price': 0.00061001,
  'upper_price': 0.00062047,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '83.143482',
  'real_fees_collected_token0': 53.968819,
  'dojo_fees_collected_token1': '0.050544862935275553',
  'real_fees_collected_token1': 0.03040056,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/570290'},
 {'start_time': Timestamp('2023-09-06 06:10:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-07 18:05:00+0000', tz='UTC'),
  'deposit_token0': 45300.0,
  'deposit_token1': 45300.0,
  'lower_price': 0.00058844,
  'upper_price': 0.00061491,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '1012.024289',
  'real_fees_collected_token0': 2575.259249,
  'dojo_fees_collected_token1': '0.633466098131261847',
  'real_fees_collected_token1': 1.4826215,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/560570'},
 {'start_time': Timestamp('2023-09-10 18:06:00+0000', tz='UTC'),
  'end_time': Timestamp('2023-09-12 09:49:00+0000', tz='UTC'),
  'deposit_token0': 2040.61717,
  'deposit_token1': 2040.61717,
  'lower_price': 0.00061062,
  'upper_price': 0.00062922,
  'token0': 'USDC',
  'token1': 'WETH',
  'fee_tier': 500,
  'dojo_fees_collected_token0': '24.323339',
  'real_fees_collected_token0': 7.348751,
  'dojo_fees_collected_token1': '0.014223481288578276',
  'real_fees_collected_token1': 0.00521725,
  'pool_desc': 'USDC/WETH-0.05',
  'position_nft': 'https://revert.finance/#/uniswap-position/mainnet/562571'}]
0xprofessooor commented 1 year ago

Cool, we'll have a look :)

0xprofessooor commented 1 year ago

Interesting, so the forked backend recovers the true result:

https://revert.finance/#/uniswap-position/mainnet/551745 Screenshot 2023-10-23 at 11 44 47

But the local backend gives incorrect fees as you mention. I'll continue debugging it but in the meantime, for these smaller simulation lengths, the forked backend should suffice.

wwklsq commented 1 year ago

Just noticed, the deposit_token1 is identical to deposit_token0 in my previous commit. It´s a typo. U can probably find the information in the link though.

0xprofessooor commented 1 year ago

Yeah nw, I've been using the link like you said :)

So quick update, I've identified why the local backend was diverging and think I've implemented a fix, am testing now but will update here when I have it working

0xprofessooor commented 1 year ago

Ok so I think that's a confirmed fix now 🎉, will release a new version soon. This will have quite a few changes actually, the interface you will use has also changes so you use UniV3Trade, UniV3Quote etc. rather than UniV3Action, which I hope is a bit more intuitive. I'll do the release soon but updating the docs at dojo.compasslabs.ai might take a bit longer.

wwklsq commented 1 year ago

Ok so I think that's a confirmed fix now 🎉, will release a new version soon. This will have quite a few changes actually, the interface you will use has also changes so you use UniV3Trade, UniV3Quote etc. rather than UniV3Action, which I hope is a bit more intuitive. I'll do the release soon but updating the docs at dojo.compasslabs.ai might take a bit longer.

Hi @09tangriro , thanks for the quick fix. Can I assume that dojo has now fixed all the problematic positions that I listed above, so the result from dojo in local mode now matches exactly with the groundtruth from revert?

0xprofessooor commented 1 year ago

I believe so, just did a release now, you'll need to edit your code slightly to use the new format for actions though (https://readthedocs.compasslabs.ai/dojo.actions.html#dojo.actions.uniswapV3.UniV3Quote)

0xprofessooor commented 1 year ago

Thanks for giving dojo a try, closing the issue now :)