Skip to content

Commit

Permalink
feat(sdk-core): zksync custom create2 address (#39)
Browse files Browse the repository at this point in the history
## 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
jsy1218 authored Jun 6, 2024
1 parent 9cd39ed commit c58412e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdks/sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
"dependencies": {
"@ethersproject/address": "^5.0.2",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/keccak256": "5.7.0",
"@ethersproject/strings": "5.7.0",
"big.js": "^5.2.2",
"decimal.js-light": "^2.5.0",
"jsbi": "^3.1.4",
Expand Down
16 changes: 16 additions & 0 deletions sdks/sdk-core/src/utils/computeZksyncCreate2Address.ts
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)
}
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4649,6 +4649,9 @@ __metadata:
resolution: "@uniswap/sdk-core@workspace:sdks/sdk-core"
dependencies:
"@ethersproject/address": ^5.0.2
"@ethersproject/bytes": ^5.7.0
"@ethersproject/keccak256": 5.7.0
"@ethersproject/strings": 5.7.0
"@types/big.js": ^4.0.5
"@types/jest": ^24.0.25
big.js: ^5.2.2
Expand Down

0 comments on commit c58412e

Please sign in to comment.