-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add withdrawal address checkers, validate restake vault * 1.8.0 * add getOperatorAddress tests * 1.8.1 * update README * 1.8.2 * 1.8.3 * improve logic, add gqlRequest helper * 1.8.4 * code style improves * 1.8.5
- Loading branch information
Showing
16 changed files
with
246 additions
and
25 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,68 @@ | ||
import { getEigenPods } from './requests' | ||
import ParserError, { ErrorTypes } from './errors' | ||
import getEigenPodAddress from './getEigenPodAddress' | ||
import type { GetEigenPodAddressInput } from './getEigenPodAddress' | ||
|
||
|
||
type MockGetEigenPods = jest.MockedFunction<typeof getEigenPods> | ||
|
||
jest.mock('./requests/getEigenPods') | ||
|
||
describe('getEigenPodAddress', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should return the correct operator address for valid input', async () => { | ||
const input: GetEigenPodAddressInput = { | ||
vaultAddress: '0xe05d8895e8b3ba51ce4f89b337c621889d3f38bf', | ||
withdrawalAddress: '0x6B8c2EBf69aE6c7ae583F219D464637Bd1b6bFa3', | ||
network: 'holesky', | ||
}; | ||
|
||
(getEigenPods as MockGetEigenPods).mockResolvedValue([ | ||
{ address: '0x6B8c2EBf69aE6c7ae583F219D464637Bd1b6bFa3' }, | ||
]) | ||
|
||
const result = await getEigenPodAddress(input) | ||
expect(result).toBe('0x6B8c2EBf69aE6c7ae583F219D464637Bd1b6bFa3') | ||
}) | ||
|
||
it('should throw an error if withdrawalAddress is missing', async () => { | ||
const input = { | ||
vaultAddress: '0xe05d8895e8b3ba51ce4f89b337c621889d3f38bf', | ||
network: 'holesky', | ||
} as GetEigenPodAddressInput | ||
|
||
const errorText = new ParserError(ErrorTypes.MISSING_FIELDS, { fields: [ 'withdrawal_address' ] }) | ||
await expect(getEigenPodAddress(input)).rejects.toThrow(errorText) | ||
}) | ||
|
||
it('should throw an error if eigenPods is empty', async () => { | ||
const input = { | ||
vaultAddress: '0xe05d8895e8b3ba51ce4f89b337c621889d3f38bf', | ||
withdrawalAddress: '0x6B8c2EBf69aE6c7ae583F219D464637Bd1b6bFa3', | ||
network: 'holesky', | ||
} as GetEigenPodAddressInput | ||
|
||
(getEigenPods as MockGetEigenPods).mockResolvedValue([]) | ||
|
||
const errorText = new ParserError(ErrorTypes.EIGEN_PODS_EMPTY) | ||
await expect(getEigenPodAddress(input)).rejects.toThrow(errorText) | ||
}) | ||
|
||
it('should throw an error if operator address is not found in eigenPods', async () => { | ||
const input = { | ||
vaultAddress: '0xe05d8895e8b3ba51ce4f89b337c621889d3f38bf', | ||
withdrawalAddress: '0x6B8c2EBf69aE6c7ae583F219D464637Bd1b6bFa3', | ||
network: 'holesky', | ||
} as GetEigenPodAddressInput | ||
|
||
(getEigenPods as MockGetEigenPods).mockResolvedValue([ | ||
{ address: '0xe05d8895e8b3ba51ce4f89b337c621889d3f38bf' }, | ||
]) | ||
|
||
const errorText = new ParserError(ErrorTypes.INVALID_WITHDRAW_ADDRESS) | ||
await expect(getEigenPodAddress(input)).rejects.toThrow(errorText) | ||
}) | ||
}) |
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,35 @@ | ||
import { getEigenPods } from './requests' | ||
import { SupportedNetworks } from '../types' | ||
import ParserError, { ErrorTypes } from './errors' | ||
|
||
|
||
export type GetEigenPodAddressInput = { | ||
vaultAddress: string | ||
withdrawalAddress?: string | ||
network: SupportedNetworks | ||
} | ||
|
||
const getEigenPodAddress = async (values: GetEigenPodAddressInput): Promise<string> => { | ||
const { vaultAddress, withdrawalAddress, network } = values | ||
|
||
if (!withdrawalAddress) { | ||
throw new ParserError(ErrorTypes.MISSING_FIELDS, { fields: [ 'withdrawal_address' ] }) | ||
} | ||
|
||
const eigenPods = await getEigenPods(vaultAddress, network) | ||
|
||
if (!eigenPods?.length) { | ||
throw new ParserError(ErrorTypes.EIGEN_PODS_EMPTY) | ||
} | ||
|
||
const eigenPod = eigenPods.find((eigenPod) => eigenPod.address === withdrawalAddress) | ||
|
||
if (!eigenPod) { | ||
throw new ParserError(ErrorTypes.INVALID_WITHDRAW_ADDRESS) | ||
} | ||
|
||
return eigenPod.address | ||
} | ||
|
||
|
||
export default getEigenPodAddress |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export { getBytes } from './getBytes' | ||
export * as requests from './requests' | ||
export { default as prefix0x } from './prefix0x' | ||
export { default as mockData } from './mockData' | ||
export { default as getAmount } from './getAmount' | ||
export { default as containers } from './containers' | ||
export { default as computeDomain } from './computeDomain' | ||
export { default as getForkVersion } from './getForkVersion' | ||
export { default as getEigenPodAddress } from './getEigenPodAddress' | ||
export { default as ParserError, ErrorMessages, ErrorTypes } from './errors' | ||
export { default as getWithdrawalCredentials } from './getWithdrawalCredentials' |
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,20 @@ | ||
import gqlRequest from './gqlRequest' | ||
import { SupportedNetworks } from '../../types' | ||
|
||
|
||
const checkIsRestakeVault = async (vaultId: string, network: SupportedNetworks) => { | ||
const query = `query Vault($vaultId: ID!) { vault(id: $vaultId) { isRestake }}` | ||
const variables = { vaultId: vaultId.toLowerCase() } | ||
|
||
try { | ||
const data = await gqlRequest({ query, variables }, network) | ||
|
||
return data?.vault?.isRestake | ||
} | ||
catch (error) { | ||
console.error('Error fetching isRestake:', error) | ||
} | ||
} | ||
|
||
|
||
export default checkIsRestakeVault |
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,22 @@ | ||
import gqlRequest from './gqlRequest' | ||
import { SupportedNetworks } from '../../types' | ||
|
||
|
||
type EigenPods = { address: string }[] | ||
|
||
const getEigenPods = async (vaultId: string, network: SupportedNetworks) => { | ||
const query = `query EigenPods($vaultId: ID!) { eigenPods(where: { vault: $vaultId }) { address }}` | ||
const variables = { vaultId: vaultId.toLowerCase() } | ||
|
||
try { | ||
const data = await gqlRequest({ query, variables }, network) | ||
|
||
return data?.eigenPods as EigenPods | ||
} | ||
catch (error) { | ||
console.error('Error fetching EigenPods:', error) | ||
} | ||
} | ||
|
||
|
||
export default getEigenPods |
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,42 @@ | ||
import { urls } from './urls' | ||
import { SupportedNetworks } from '../../types' | ||
|
||
|
||
type GqlRequestOptions = { | ||
query: string | ||
variables?: Record<string, any> | ||
} | ||
|
||
const gqlRequest = async (options: GqlRequestOptions, network: SupportedNetworks) => { | ||
try { | ||
const response = await fetch(urls[network], { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: options.query, | ||
variables: options.variables, | ||
}), | ||
}) | ||
|
||
if (response?.status !== 200) { | ||
throw new Error(`API request failed: ${response?.url}`) | ||
} | ||
|
||
const result = await response.json() | ||
|
||
if (result?.errors) { | ||
throw new Error(result.errors[0].message) | ||
} | ||
|
||
return result?.data | ||
} | ||
catch (error) { | ||
console.error('Error in gqlRequest:', error) | ||
throw error | ||
} | ||
} | ||
|
||
|
||
export default gqlRequest |
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,2 @@ | ||
export { default as getEigenPods } from './getEigenPods' | ||
export { default as checkIsRestakeVault } from './checkIsRestakeVault' |
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,9 @@ | ||
import type { SupportedNetworks } from 'parser/types' | ||
|
||
|
||
export const urls: Record<SupportedNetworks, string> = { | ||
'holesky': 'https://holesky-graph.stakewise.io/subgraphs/name/stakewise/stakewise', | ||
'mainnet': 'https://mainnet-graph.stakewise.io/subgraphs/name/stakewise/stakewise', | ||
'gnosis': 'https://graph-gno.stakewise.io/subgraphs/name/stakewise/stakewise', | ||
'chiado': 'https://chiado-graph.stakewise.io/subgraphs/name/stakewise/stakewise', | ||
} |
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
Oops, something went wrong.