-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-core): zksync custom create2 address (#39)
## Description zksync-ethers use ethers 6, but our stack still uses ethers 5 across the board. We are not ready to upgrade our stack to use ethers 6, so we will implement zksync-ethers [create2Address](https://github.com/zksync-sdk/zksync-ethers/blob/main/src/utils.ts#L368) within our sdk-core ## How Has This Been Tested? I tested via a custom v3 pool address unit test written local, and address are the same without considering the case sensitivity https://app.warp.dev/block/sVW55KB4ifZKwbxC7jZs4m ## Are there any breaking changes? No ## (Optional) Feedback Focus No ## (Optional) Follow Ups
- Loading branch information
Showing
3 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getAddress } from '@ethersproject/address' | ||
import { BytesLike, concat, hexZeroPad } from '@ethersproject/bytes' | ||
import { keccak256 } from '@ethersproject/keccak256' | ||
import { toUtf8Bytes } from '@ethersproject/strings' | ||
|
||
export function computeZksyncCreate2Address( | ||
sender: string, | ||
bytecodeHash: BytesLike, | ||
salt: BytesLike, | ||
input: BytesLike = '0x' | ||
) { | ||
const prefix = keccak256(toUtf8Bytes('zksyncCreate2')) | ||
const inputHash = keccak256(input) | ||
const addressBytes = keccak256(concat([prefix, hexZeroPad(sender, 32), salt, bytecodeHash, inputHash])).slice(26) | ||
return getAddress(addressBytes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters