Skip to content

Commit

Permalink
New tree (#11)
Browse files Browse the repository at this point in the history
* add withdrawalAddress to merkle tree

* 1.8.7

* show restake logic

* 1.8.8

* add withdrawalAddress props

* 1.8.9
  • Loading branch information
dfkadyr authored Jul 23, 2024
1 parent f4b3869 commit 8f4325e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.6",
"version": "1.8.9",
"main": "dist/index.js",
"name": "@stakewise/v3-deposit-data-parser",
"description": "v3-deposit-data-parser",
Expand Down
13 changes: 6 additions & 7 deletions src/parser/getDepositData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ export type DepositDataInput = {
const getDepositData = async (values: DepositDataInput): Promise<DepositData> => {
const { pubkey, vaultAddress, withdrawalAddress, network } = values

// TODO: use withdrawalCredentialAddress instead of vaultAddress after restake logic is implemented
// const isRestakeVault = await requests.checkIsRestakeVault(vaultAddress, network)
//
// const withdrawalCredentialAddress = isRestakeVault
// ? await getEigenPodAddress({ vaultAddress, withdrawalAddress, network })
// : vaultAddress
const isRestakeVault = await requests.checkIsRestakeVault(vaultAddress, network)

const withdrawalCredentialAddress = isRestakeVault
? await getEigenPodAddress({ vaultAddress, withdrawalAddress, network })
: vaultAddress

try {
const withdrawalCredentials = getWithdrawalCredentials(vaultAddress)
const withdrawalCredentials = getWithdrawalCredentials(withdrawalCredentialAddress)

const depositData = {
amount: getAmount(network),
Expand Down
17 changes: 12 additions & 5 deletions src/parser/getTreeLeaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export type TreeLeafInput = {
pubkey: string
signature: string
depositData: DepositData
withdrawalAddress?: string
}

// Creates an array concatenating pubkey, signature, and hashTreeRoot for a given deposit data
// Creates an array concatenating pubkey, signature, hashTreeRoot and withdrawalAddress for a given deposit data
// This array is used to create a Merkle tree and load it into IPFS
const getTreeLeaf = (values: TreeLeafInput): Uint8Array => {
const { depositData, pubkey, signature } = values
const { depositData, pubkey, signature, withdrawalAddress } = values

try {
// Calculate the hash tree root for the given deposit data and signature
Expand All @@ -20,12 +21,18 @@ const getTreeLeaf = (values: TreeLeafInput): Uint8Array => {
signature: getBytes(prefix0x.add(signature)),
})

const leave = Buffer.concat([
const leafParts = [
getBytes(prefix0x.add(pubkey)),
getBytes(prefix0x.add(signature)),
])
hashTreeRoot,
]

const treeLeaf = Buffer.concat([ leave, hashTreeRoot ])
// Optionally add the withdrawal address if it exists
if (withdrawalAddress) {
leafParts.push(getBytes(prefix0x.add(withdrawalAddress)))
}

const treeLeaf = Buffer.concat(leafParts)

return treeLeaf
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const depositDataParser = async (input: ParserInput) => {

verifySignature({ bls, pubkey, signature, depositData, network })

const treeLeaf = getTreeLeaf({ pubkey, signature, depositData })
const treeLeaf = getTreeLeaf({ pubkey, signature, depositData, withdrawalAddress: withdrawal_address })

pubkeySet.add(pubkey)
treeLeaves.push(treeLeaf)
Expand Down

0 comments on commit 8f4325e

Please sign in to comment.