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

New tree #11

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading