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 errors with same pattern #10

Closed
tcong-aa opened this issue Jun 16, 2023 · 8 comments
Closed

decode errors with same pattern #10

tcong-aa opened this issue Jun 16, 2023 · 8 comments

Comments

@Elnaril
Copy link
Owner

Elnaril commented Jun 16, 2023

Hello!

Here is the decoded input for the first transaction (0x8b02d0ac0c11da014e04a027eaa49ddf7913e64eef29fcb64f9595d277425f46) :

{'commands': b'\x00\x00\x08',
 'inputs': [(<Function V3_SWAP_EXACT_IN(address,uint256,uint256,bytes,bool)>,
   {'recipient': '0x0000000000000000000000000000000000000001',
    'amountIn': 539689947,
    'amountOutMin': 22539188087083765897187811,
    'path': b"\xda\xc1\x7f\x95\x8d.\xe5#\xa2 b\x06\x99E\x97\xc1=\x83\x1e\xc7\x00\x0b\xb8\xc0*\xaa9\xb2#\xfe\x8d\n\x0e\\O'\xea\xd9\x08<ul\xc2\x00'\x10}\x81F\xcf!\xe8\xd7\xcb\xe4`T\xe0\x15\x88 {Q\x19\x87)",
    'payerIsSender': True}),
  (<Function V3_SWAP_EXACT_IN(address,uint256,uint256,bytes,bool)>,
   {'recipient': '0xbe8BC29765E11894f803906Ee1055a344fDf2511',
    'amountIn': 4857209527,
    'amountOutMin': 0,
    'path': b"\xda\xc1\x7f\x95\x8d.\xe5#\xa2 b\x06\x99E\x97\xc1=\x83\x1e\xc7\x00\x01\xf4\xc0*\xaa9\xb2#\xfe\x8d\n\x0e\\O'\xea\xd9\x08<ul\xc2",
    'payerIsSender': True}),
  (<Function V2_SWAP_EXACT_IN(address,uint256,uint256,address[],bool)>,
   {'recipient': '0x0000000000000000000000000000000000000001',
    'amountIn': 57896044618658097711785492504343953926634992332820282019728792003956564819968,
    'amountOutMin': 201706613530196448705261836,
    'path': ['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
     '0x7D8146cf21e8D7cbe46054e01588207b51198729'],
    'payerIsSender': False})],
 'deadline': 1686896447}

Are you talking about the amountIn for the V2 swap ? Otherwise, can you please describe your issue ?

@tcong-aa
Copy link
Author

tcong-aa commented Jun 16, 2023

yes, the amoutIn in V2_SWAP_EXACT_IN is not right

@Elnaril
Copy link
Owner

Elnaril commented Jun 16, 2023

You say it is not right because this amount (2**255) is obviously way too big to be the exact amount of weth used in the swap ? Or because you have encoded the input data (or you know it has been encoded) with another number ?

@tcong-aa
Copy link
Author

tcong-aa commented Jun 16, 2023

image

this is the real weth amountIn of the transaction above,
but the number decoded is 57896044618658097711785492504343953926634992332820282019728792003956564819968

also you can find out that all txs I pasted decoded result have a same ether amountIn:
57896044618658097711785492504343953926634992332820282019728792003956564819968

@Elnaril
Copy link
Owner

Elnaril commented Jun 16, 2023

Ok, thanks.
The amountIn for the V2_SWAP_EXACT_IN transaction comes from a V3_SWAP_EXACT_IN amountOutMin. So there is no way to be sure what is going to be the exact output amount at the moment the transaction is encoded.

To handle that, you can set the amountIn to 2**255 which is the constant CONTRACT_BALANCE defined here.
It instructs the router to use all its balance for the in_token.
Since the router received ~2.9 WETH from the V3_SWAP_EXACT_IN swap, it uses the exact same amount for the V2_SWAP_EXACT_IN swap.

Does it make sense ?

PS: The amount you underlined in your screenshot, along with all the data in the "Transaction Action" section, comes from the trx logs, not from the input data.

@Elnaril
Copy link
Owner

Elnaril commented Jun 16, 2023

Closing as there is no error from the decoder.
Feel free to re-open it otherwise.

And thank you for your interest in this lib! :)

@Elnaril Elnaril closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
@tcong-aa
Copy link
Author

thanks man, this is a very useful lib :)

@Elnaril
Copy link
Owner

Elnaril commented Jun 17, 2023

Thanks for your feedback!! :)
Happy coding!

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

No branches or pull requests

2 participants