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

[Feature Request] getCreate2Address & pack #1101

Closed
matthewlilley opened this issue Oct 25, 2021 · 4 comments
Closed

[Feature Request] getCreate2Address & pack #1101

matthewlilley opened this issue Oct 25, 2021 · 4 comments

Comments

@matthewlilley
Copy link

matthewlilley commented Oct 25, 2021

It would be useful to be able to have available some common functions like getCreate2Address and pack to reduce calls where computation maybe a valid approach instead.

References:

https://github.com/ethers-io/ethers.js/blob/master/packages/address/src.ts/index.ts#L143
https://github.com/ethers-io/ethers.js/blob/master/packages/solidity/src.ts/index.ts#L84

@LufyCZ
Copy link

LufyCZ commented Jan 26, 2022

The code is a bit ugly, but it's tested and works like a charm

export default function getCreate2Address(
  from: Bytes,
  salt: Bytes,
  initCodeHash: Bytes
): Bytes {
  return Bytes.fromHexString(
    Bytes.fromByteArray(
      crypto.keccak256(
        Bytes.fromHexString(
          "0xff" +
            from.toHexString().slice(2) +
            salt.toHexString().slice(2) +
            initCodeHash.toHexString().slice(2)
        )
      )
    )
      .toHexString()
      .slice(26)
  ) as Bytes;
}

@matthewlilley
Copy link
Author

The code is a bit ugly, but it's tested and works like a charm

export default function getCreate2Address(
  from: Bytes,
  salt: Bytes,
  initCodeHash: Bytes
): Bytes {
  return Bytes.fromHexString(
    Bytes.fromByteArray(
      crypto.keccak256(
        Bytes.fromHexString(
          "0xff" +
            from.toHexString().slice(2) +
            salt.toHexString().slice(2) +
            initCodeHash.toHexString().slice(2)
        )
      )
    )
      .toHexString()
      .slice(26)
  ) as Bytes;
}

Just reimplemented our exchange subgraph and made use of this, like Lufy said, works like a charm.

@dotansimha dotansimha transferred this issue from graphprotocol/graph-ts Feb 23, 2023
@schmidsi
Copy link
Member

schmidsi commented Jun 6, 2023

@saihaj this is done, no?

@saihaj
Copy link
Member

saihaj commented Jun 6, 2023

I didn't get to do pack but create2 is available now!

@saihaj saihaj closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

5 participants