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

Use snekmate for root address calculation #93

Open
stas opened this issue Nov 15, 2024 · 1 comment
Open

Use snekmate for root address calculation #93

stas opened this issue Nov 15, 2024 · 1 comment
Assignees

Comments

@stas
Copy link
Collaborator

stas commented Nov 15, 2024

TODO: replace all below with
https://github.com/pcaversaccio/snekmate/blob/main/src/snekmate/utils/create2_address.vy#L49-L76

Consider:

from snekmate.utils import create2_address

@internal
@view
def _root_lp_address(
  _factory: address,
  _token0: address,
  _token1: address,
  _type: int24
) -> address:
...
create2_address._compute_address(salt, init_hash, _factory)

Originally posted by @stas in #90 (comment)

@stas
Copy link
Collaborator Author

stas commented Nov 15, 2024

You could rewrite the if-else block like this:

common: Bytes[72] = concat(convert(chain.id, bytes32), convert(_token0, bytes20), convert(_token1, bytes20))
salt = keccak256(concat(common, 0x00)) if (_type == 0) else keccak256(concat(common, convert(_type, bytes3)))

Probably the recommended approach consumes slightly more gas, but is definitely more readable imo.

Originally posted by @pcaversaccio in #90 (comment)

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

No branches or pull requests

1 participant