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

feat: create ERC20OverwriteFactory utils #12

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

tamaralipows
Copy link
Contributor

@tamaralipows tamaralipows force-pushed the tnl/ENG-3750-erc20-overwrite-factory branch from 7a80cd3 to 86457cf Compare October 19, 2024 18:14
Copy link
Contributor

@louise-poole louise-poole left a comment

Choose a reason for hiding this comment

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

Nice! A couple of things that need addressing, but for the most part this looks good 👍

Comment on lines 214 to 217
let code = format!(
"0x{}",
hex::encode(get_contract_bytecode(erc20_abi_path.to_str().unwrap()).unwrap())
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with the unwraps. We also need to decide if we want the program to just panic and terminate if this fails (which will happen with unwrap and expect etc.) or do we want the user to decide how to handle the error. If we want the user to be able to handle the error we need to return a Result and propagate these internal errors instead of panicking.
I personally think we should return a Result... the user might want to skip that simulation that this is making fail, but keep their program running and simulating non-vm pools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I agree with you - I'm thinking about the scenarios where this fails:

  • malformed ERC20.abi file
  • malformed directory structure

And I am not sure it's beneficial to return a result here - these are not really expected errors that one can just skip for one simulation and expect that the next simulation will be okay. If any one of those things is wrong - it's truly game over for all sims. I do think in this case it's more beneficial to use expect.

Let me know if I'm missing something!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... yeah, I agree with you in terms of vm only simulations. But in rust I tend to lean towards giving the call site/user the power to choose.
E.g. If I'm a small solver that mainly uses native protocols I might decide to just handle this error by ignoring vm protocols and just logging a warning. To me my focus is on keeping my native simulations going.
On the other side, if I rely on vm simulations I can then choose to panic on this error.
I like having the choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes more sense! I'll add that in then :)

TAMARA LIPOWSKI added 2 commits October 21, 2024 10:18
unwrap should not be used in production code - this hides the true error.

Other readability fixes:
- Remove redundant comments
- Don't use TxHash type alias: introduce SlotHash type alias for readability
- Introduce Overwrites alias - since this type will be repeated a lot.
- Fix struct docs (the comment should be preceded by a /// and go on top of the attribute)
- Adapted from the python docs.
- Made mods public so they can actually be imported (noticed this discrepancy when writing the docs). Not sure if there is a downside to this.
Comment on lines 214 to 217
let code = format!(
"0x{}",
hex::encode(get_contract_bytecode(erc20_abi_path.to_str().unwrap()).unwrap())
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... yeah, I agree with you in terms of vm only simulations. But in rust I tend to lean towards giving the call site/user the power to choose.
E.g. If I'm a small solver that mainly uses native protocols I might decide to just handle this error by ignoring vm protocols and just logging a warning. To me my focus is on keeping my native simulations going.
On the other side, if I rely on vm simulations I can then choose to panic on this error.
I like having the choice.

@tamaralipows
Copy link
Contributor Author

Just realized I should probably also move this to its own file - will do tomorrow!

Copy link
Collaborator

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

I think this looks good! (hard to review deeply rn because I'm still getting back to this) After the open comments are addressed this is good to goooo 🚀

TAMARA LIPOWSKI added 2 commits October 22, 2024 11:58
- Consider the case of supporting both native and vm protocols. If I'm a small solver that mainly uses native protocols I might decide to just handle this error by ignoring vm protocols and just logging a warning. To me my focus is on keeping my native simulations going.

Other changes:
- Abolish SlotHash: An outside user will more readily know what type H256 needs from them than our arb type SlotHash.
- Docstrings: We are able to get the slot index of any H160 - not just address
TAMARA LIPOWSKI added 2 commits October 22, 2024 13:55
We want:
- Familiar types for the user (H160, H256)
- Custom types for us internally (SlotHash, Address)

This makes life easier for both us and the user, as everyone is working with something that is clearer to them.
Copy link
Collaborator

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

Thank you 🙏🏼

@tamaralipows tamaralipows merged commit 8f7f022 into main Oct 23, 2024
3 checks passed
@tamaralipows tamaralipows deleted the tnl/ENG-3750-erc20-overwrite-factory branch October 23, 2024 13:44
@propellerci
Copy link

propellerci bot commented Oct 24, 2024

This PR is included in version 0.24.0 🎉

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

Successfully merging this pull request may close these issues.

3 participants