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

LpSugar: added Lp.root. #90

Merged
merged 10 commits into from
Nov 15, 2024
Merged

LpSugar: added Lp.root. #90

merged 10 commits into from
Nov 15, 2024

Conversation

stas
Copy link
Collaborator

@stas stas commented Oct 30, 2024

Added Lp.root representing root (placeholder) pool address, for (non-canonical) leaf chain pools.

Copy link
Contributor

@pedrovalido pedrovalido left a comment

Choose a reason for hiding this comment

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

lgtm, just left one tiny nit

contracts/modules/lp_shared.vy Outdated Show resolved Hide resolved
@stas stas force-pushed the root_pool branch 6 times, most recently from ec382c7 to b120fdf Compare November 3, 2024 16:28
)
)


Copy link
Collaborator Author

@stas stas Nov 4, 2024

Choose a reason for hiding this comment

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

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)


salt: bytes32 = empty(bytes32)

if _type < 1:
Copy link

@pcaversaccio pcaversaccio Nov 4, 2024

Choose a reason for hiding this comment

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

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.

@stas stas force-pushed the root_pool branch 2 times, most recently from 08e29c2 to 4989852 Compare November 7, 2024 13:10
@stas stas force-pushed the root_pool branch 2 times, most recently from 84ae874 to 96fa367 Compare November 13, 2024 17:11
@stas stas merged commit 4b5827c into v3 Nov 15, 2024
7 of 8 checks passed
@stas stas deleted the root_pool branch November 15, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants