|
|
|
|
@@ -8,22 +8,20 @@ import { getRelayerRegistry } from '@/contracts'
|
|
|
|
|
import { DEPLOYED_BLOCK, GRAPHQL_LIMIT, RELAYER_SUBGRAPH_LIST, errors, numbers } from '@/constants'
|
|
|
|
|
import { ensService, tornadoRelayerService } from '@/services'
|
|
|
|
|
import { errorParser, fromWei, toDecimalsPlaces } from '@/utilities'
|
|
|
|
|
import { getAddress, parseEther } from 'ethers/lib/utils'
|
|
|
|
|
import { BigNumber } from 'ethers'
|
|
|
|
|
import { getAddress } from 'ethers/lib/utils'
|
|
|
|
|
|
|
|
|
|
interface GraphRelayer {
|
|
|
|
|
id: string
|
|
|
|
|
address: string
|
|
|
|
|
ensName: string
|
|
|
|
|
ensHash: string
|
|
|
|
|
|
|
|
|
|
workers: string[]
|
|
|
|
|
stakeBalance: string
|
|
|
|
|
blockRegistration: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GraphRelayerFormatted extends Omit<GraphRelayer, 'stakeBalance' | 'blockRegistration'> {
|
|
|
|
|
stakeBalance: BigNumber
|
|
|
|
|
interface GraphRelayerFormatted extends Omit<GraphRelayer, 'id' | 'blockRegistration'> {
|
|
|
|
|
registerBlock: number
|
|
|
|
|
registerTx: string
|
|
|
|
|
registerLogIndex: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
@@ -69,6 +67,9 @@ export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* todo: add worker events to relayer registry subgraph
|
|
|
|
|
*/
|
|
|
|
|
async getRelayersFromGraph({ getters }) {
|
|
|
|
|
try {
|
|
|
|
|
const { chainId } = getters.dependencies
|
|
|
|
|
@@ -84,12 +85,10 @@ export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
query: `
|
|
|
|
|
query getRelayers($first: Int) {
|
|
|
|
|
relayers(first: $first, orderBy: blockRegistration, orderDirection: asc) {
|
|
|
|
|
id
|
|
|
|
|
address
|
|
|
|
|
ensName
|
|
|
|
|
ensHash
|
|
|
|
|
|
|
|
|
|
workers
|
|
|
|
|
stakeBalance
|
|
|
|
|
blockRegistration
|
|
|
|
|
}
|
|
|
|
|
_meta {
|
|
|
|
|
@@ -116,22 +115,22 @@ export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
throw new Error(`Error from graph: ${JSON.stringify(errors)}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
if (data?._meta?.hasIndexingErrors) {
|
|
|
|
|
throw new Error('Subgraph has indexing errors')
|
|
|
|
|
throw new Error('Subgraph has indexing errors');
|
|
|
|
|
}
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
return (data.relayers as GraphRelayer[]).map(({ address, ensName, ensHash, workers, stakeBalance, blockRegistration }) => {
|
|
|
|
|
if (!workers.includes(address)) {
|
|
|
|
|
workers.push(getAddress(address))
|
|
|
|
|
}
|
|
|
|
|
return (data.relayers as GraphRelayer[]).map(({ id, address, ensName, ensHash, blockRegistration }) => {
|
|
|
|
|
const [registerTx, registerLogIndex] = id.split('-')
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
address: getAddress(address),
|
|
|
|
|
ensName,
|
|
|
|
|
ensHash,
|
|
|
|
|
workers,
|
|
|
|
|
stakeBalance: parseEther(stakeBalance),
|
|
|
|
|
registerBlock: Number(blockRegistration),
|
|
|
|
|
registerTx,
|
|
|
|
|
registerLogIndex: Number(registerLogIndex),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
@@ -164,8 +163,9 @@ export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
|
|
|
|
|
async getRelayers({ getters, commit, dispatch }) {
|
|
|
|
|
try {
|
|
|
|
|
const { walletAddress } = getters.dependencies
|
|
|
|
|
const { walletAddress, chainId } = getters.dependencies
|
|
|
|
|
|
|
|
|
|
// todo: add worker data
|
|
|
|
|
const relayers = (await dispatch('getRelayersFromGraph')) as GraphRelayerFormatted[]
|
|
|
|
|
|
|
|
|
|
const relayer = relayers.find((r) => r.address === walletAddress)
|
|
|
|
|
@@ -174,8 +174,13 @@ export const actions: ActionTree<RelayerState, RootState> = {
|
|
|
|
|
throw new Error(`No relayer found for ${walletAddress}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commit(RelayerMutation.SET_WORKERS, relayer.workers)
|
|
|
|
|
commit(RelayerMutation.SET_BALANCE, relayer.stakeBalance)
|
|
|
|
|
const registryContract = getRelayerRegistry(chainId)
|
|
|
|
|
|
|
|
|
|
const { balance } = await registryContract.callStatic.relayers(walletAddress)
|
|
|
|
|
|
|
|
|
|
// todo: add worker data
|
|
|
|
|
commit(RelayerMutation.SET_WORKERS, [walletAddress])
|
|
|
|
|
commit(RelayerMutation.SET_BALANCE, balance)
|
|
|
|
|
|
|
|
|
|
await dispatch('getRelayerENSData', relayer.ensName)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|