Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode Liquidity additions & removal for Uniswap(V2 & V3) & Sushiswap #5337

Conversation

prettyirrelevant
Copy link
Contributor

@prettyirrelevant prettyirrelevant commented Jan 2, 2023

Checklist

  • Decode LP additions & removal for Uniswap V3
  • Decode LP additions & removal for Uniswap V2
  • Decode LP additions & removal for Sushiswap

@prettyirrelevant prettyirrelevant force-pushed the decode-uni-sushi-deposit-and-withdrawals branch from 25be8e7 to 378d030 Compare January 6, 2023 18:42
@prettyirrelevant prettyirrelevant marked this pull request as ready for review January 6, 2023 18:43
@prettyirrelevant prettyirrelevant temporarily deployed to test January 6, 2023 18:43 — with GitHub Actions Inactive
@prettyirrelevant prettyirrelevant temporarily deployed to test January 6, 2023 18:44 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Jan 6, 2023

Codecov Report

Merging #5337 (f9065a8) into develop (73b82aa) will decrease coverage by 0.39%.
The diff coverage is 70.23%.

@@             Coverage Diff             @@
##           develop    #5337      +/-   ##
===========================================
- Coverage    71.45%   71.07%   -0.39%     
===========================================
  Files          988     1005      +17     
  Lines        74172    74916     +744     
  Branches      9156     9238      +82     
===========================================
+ Hits         53001    53247     +246     
- Misses       19566    20027     +461     
- Partials      1605     1642      +37     
Flag Coverage Δ
frontend_integration 60.22% <59.45%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ents/accounts/management/types/XpubAccountForm.vue 0.00% <0.00%> (ø)
frontend/app/src/components/dialogs/BigDialog.vue 100.00% <ø> (ø)
...tend/app/src/components/display/AccountDisplay.vue 6.25% <ø> (ø)
frontend/app/src/components/helper/ListItem.vue 90.47% <ø> (ø)
.../components/settings/general/rpc/DotRpcSetting.vue 0.00% <0.00%> (ø)
.../components/settings/general/rpc/KsmRpcSetting.vue 0.00% <0.00%> (ø)
...onents/settings/general/rpc/OptimismRpcSetting.vue 0.00% <0.00%> (ø)
...d/app/src/components/status/update/AssetUpdate.vue 41.33% <ø> (ø)
frontend/app/src/pages/settings/general/index.vue 100.00% <ø> (ø)
frontend/app/src/premium/premium.ts 34.56% <ø> (-1.07%) ⬇️
... and 258 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

to_notes=notes.format(amount, asset.symbol, counterparty, pool_address),
to_counterparty=counterparty,
)
action_items.append(action_item)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach might be frowned upon because I'm directly mutating action_items.

However, this is quite unavoidable because the other decoding method that supports returning a list of ActionItem requires key-value pair of addresses to a decoder function.

The above won't work as we don't keep a store of all UNISWAP lp tokens. We store the ones users encounter, but this would mean that users have to manually re-decode transactions. Terrible UX.

Another option would be to create a new method in DecoderInterface for this use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been checking and I believe it would be better to allow returning events from here. The problem with mutating the action_items list here is that you introduce unexpected behavior in some of the decoders and this will surely be an issue in the future.

This decoding methods are executed here if I'm correct

event = self.try_all_rules(

if you read that function the rules by address returns both events and new action items and then the list of action items is extended in that place. Is for that why I say that mutating here introduces unexpected behavior.

My idea would be that, return both event and new action items and extend in the same way. It shouldn't be a difficult change since we have few of these decoders. What do you think?

@prettyirrelevant prettyirrelevant added the ready for peer review Backend PR ready to be reviewed by colleagues label Jan 6, 2023
@prettyirrelevant prettyirrelevant temporarily deployed to test January 7, 2023 11:18 — with GitHub Actions Inactive
@prettyirrelevant prettyirrelevant temporarily deployed to test January 7, 2023 11:18 — with GitHub Actions Inactive
Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Isaac. Left you some comments and things to improve

rotkehlchen/chain/ethereum/constants.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/uniswap/v2/common.py Outdated Show resolved Hide resolved
to_notes=notes.format(amount, asset.symbol, counterparty, pool_address),
to_counterparty=counterparty,
)
action_items.append(action_item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been checking and I believe it would be better to allow returning events from here. The problem with mutating the action_items list here is that you introduce unexpected behavior in some of the decoders and this will surely be an issue in the future.

This decoding methods are executed here if I'm correct

event = self.try_all_rules(

if you read that function the rules by address returns both events and new action items and then the list of action items is extended in that place. Is for that why I say that mutating here introduces unexpected behavior.

My idea would be that, return both event and new action items and extend in the same way. It shouldn't be a difficult change since we have few of these decoders. What do you think?

rotkehlchen/chain/ethereum/modules/uniswap/v2/common.py Outdated Show resolved Hide resolved
rotkehlchen/tests/unit/decoders/test_uniswapv3.py Outdated Show resolved Hide resolved
rotkehlchen/tests/unit/decoders/test_uniswapv3.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/uniswap/v3/decoder.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/uniswap/v3/decoder.py Outdated Show resolved Hide resolved
@prettyirrelevant prettyirrelevant force-pushed the decode-uni-sushi-deposit-and-withdrawals branch from 12e4596 to c3d1b03 Compare January 11, 2023 12:07
@prettyirrelevant prettyirrelevant added PR review work work on PR review comments and removed ready for peer review Backend PR ready to be reviewed by colleagues labels Jan 11, 2023
@prettyirrelevant prettyirrelevant force-pushed the decode-uni-sushi-deposit-and-withdrawals branch from c3d1b03 to 6cc167f Compare January 12, 2023 12:15
Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small comments but can be addressed later

Comment on lines 27 to 31
ADDY = '0xb63e0C506dDBa7b0dd106d1937d6D13BE2C62aE2'
ADDY_2 = '0xeB312F4921aEbbE99faCaCFE92f22b942Cbd7599'
ADDY_3 = '0xdD84Ce1aDcb3A4908Db61A1dFA3353C3974c5a2B'
ADDY_4 = '0x354304234329A8d2425965C647e701A72d3438e5'
ADDY_5 = '0xa931b486F661540c6D709aE6DfC8BcEF347ea437'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should have string_to_evm_address calls but since we are not checking types is fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still do it please @prettyirrelevant

rotkehlchen/chain/evm/decoding/decoder.py Outdated Show resolved Hide resolved
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

rotkehlchen/chain/ethereum/modules/sushiswap/decoder.py Outdated Show resolved Hide resolved
get_tx_event_type_identifier(HistoryEventType.RECEIVE, HistoryEventSubType.RECEIVE_WRAPPED, CPT_UNISWAP_V2): TxEventSettings( # noqa: E501
taxable=False,
count_entire_amount_spend=False,
count_cost_basis_pnl=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and in all the others why do you count cost basis pnl as False? Doesn't this determine asset spends and counts how much of something you have at any point? Are you not making this for all uniswa/sushiswap pools deposit/withdrawals? Taxable or not the spends should be counted.

Please understand what these are and what they do. Same thing for the reviewer @yabirgb.
Don't just blindly copy paste shit around.

Sidenote: We need tests for these as stated here: #5260
ALL of these accountants should have tests, otherwise you guys are throwing shit at the wall and hope it sticks.

Sidenote2: Need to abstract all those better. We copy too much stuff around to create these accounting rules. Probably there is a better way ... but need to think about it.

Won't leave the same comment in the other accountants. Please understand it applies there too though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite frankly, in as much as the argument names are pretty descriptive, it's still quite difficult to get the hang of how to combine the arguments to suit different types of transactions.

This comment helped though, thanks.

rotkehlchen/chain/ethereum/modules/uniswap/v2/common.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/uniswap/v2/common.py Outdated Show resolved Hide resolved
rotkehlchen/chain/ethereum/modules/uniswap/v2/common.py Outdated Show resolved Hide resolved
Comment on lines +223 to +427
for token, amount in zip(liquidity_pool_position_info[2:4], (amount0_raw, amount1_raw)):
token_with_data: 'CryptoAsset' = get_or_create_evm_token(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this needs refactoring here. I get that it looks and reads nice, but we should not sacrifice speed for readability to such an extent. I was gonna try and come up with a nice alternative but it's more tricky than what I can do at 01:30 at night.

So please think on this a bit and try to find a way to have this read as nicely as this does but also not iterate the events twice.

rotkehlchen/chain/evm/decoding/decoder.py Outdated Show resolved Hide resolved
rotkehlchen/tests/api/test_uniswap.py Show resolved Hide resolved
Comment on lines 27 to 31
ADDY = '0xb63e0C506dDBa7b0dd106d1937d6D13BE2C62aE2'
ADDY_2 = '0xeB312F4921aEbbE99faCaCFE92f22b942Cbd7599'
ADDY_3 = '0xdD84Ce1aDcb3A4908Db61A1dFA3353C3974c5a2B'
ADDY_4 = '0x354304234329A8d2425965C647e701A72d3438e5'
ADDY_5 = '0xa931b486F661540c6D709aE6DfC8BcEF347ea437'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still do it please @prettyirrelevant

rotkehlchen/tests/unit/decoders/test_weth.py Show resolved Hide resolved
@prettyirrelevant prettyirrelevant force-pushed the decode-uni-sushi-deposit-and-withdrawals branch from 6cc167f to 045e821 Compare January 19, 2023 13:23
@prettyirrelevant prettyirrelevant force-pushed the decode-uni-sushi-deposit-and-withdrawals branch from 045e821 to f9065a8 Compare January 19, 2023 13:44
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will merge though I left 2 smaller comments.

IT's too big to leave it out.

@pytest.mark.parametrize('ethereum_accounts', [[ADDY_2]])
def test_sushiswap_v2_remove_liquidity(database, ethereum_inquirer, eth_transactions):
"""
This checks that removing liquidity to Sushiswap V2 pool is decoded properly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This checks that removing liquidity to Sushiswap V2 pool is decoded properly.
This checks that removing liquidity from a Sushiswap V2 pool is decoded properly.

@LefterisJP LefterisJP merged commit 9b59165 into rotki:develop Jan 20, 2023
@gitpoap-bot
Copy link

gitpoap-bot bot commented Jan 20, 2023

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2023 rotki Contributor:

GitPOAP: 2023 rotki Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR review work work on PR review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants