Skip to content

Commit 9a80b6b

Browse files
committed
envio fixes
1 parent 6ded6bd commit 9a80b6b

15 files changed

Lines changed: 127 additions & 386 deletions

app/src/providers/validatorsProvider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { gnosisBatch } from '@/src/constants/config/rpc-providers'
88
import { fromSubgraphTimestamp } from '@/src/utils/date'
99
import { Chains, chainsConfig } from '@/src/constants/config/chains'
1010
import cloneDeep from 'lodash/cloneDeep'
11+
import { ValidatorStatusTypes } from '@/src/constants/types'
1112
import {
1213
TELEPATHY_VALIDATOR_ADDRESS,
1314
TELEPATHY_VALIDATOR_ADDRESS_REPLACED,
@@ -55,9 +56,9 @@ const fetcher = async () => {
5556
const validator: Validator = {
5657
address: v.address.toLowerCase(),
5758
name,
58-
bridgeType: (v.bridgeType || (staticVal?.bridgeType as any) || '') as any,
59+
bridgeType: String(v.bridgeType || staticVal?.bridgeType || ''),
5960
shortName,
60-
status: undefined as any,
61+
status: ValidatorStatusTypes.default,
6162
lastSeen: fromSubgraphTimestamp(v.lastActivity),
6263
signed: Array.isArray(v.signed) ? v.signed.length : 0,
6364
executed: Array.isArray(v.executed) ? v.executed.length : 0,

app/src/queries/validators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const VALIDATORS_QUERY = gql`
2222

2323
export const ENVIO_VALIDATORS_QUERY = `
2424
query EnvioValidators {
25-
Validator(where: { removed: { _eq: false }, hashAdded: { _is_null: false } }) {
25+
Validator(where: { removed: { _eq: false } }) {
2626
id
2727
name
2828
bridgeType
@@ -36,7 +36,7 @@ export const ENVIO_VALIDATORS_QUERY = `
3636

3737
export const ENVIO_VALIDATORS_ACTIVITY_QUERY = `
3838
query EnvioValidatorsActivity($after: numeric!) {
39-
Validator(where: { removed: { _eq: false }, hashAdded: { _is_null: false } }) {
39+
Validator(where: { removed: { _eq: false } }) {
4040
address
4141
name
4242
bridgeType

app/src/utils/validators.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,16 @@ export const getValidationsStatus = (transaction: Transaction, _validators: Vali
110110

111111
export const fetchHomeValidators = async (filter?: ValidatorsQueryVariables) => {
112112
if (isEnvioBackend()) {
113-
const request = getEnvioGraphqlClient<{ Validator: Array<any> }>()
113+
type EnvioValidatorRow = {
114+
id?: string
115+
name?: string | null
116+
bridgeType?: string | null
117+
address: string
118+
lastActivity?: number | null
119+
signed?: Array<{ id: string }>
120+
executed?: Array<{ id: string }>
121+
}
122+
const request = getEnvioGraphqlClient<{ Validator: EnvioValidatorRow[] }>()
114123
const res = await request(ENVIO_VALIDATORS_QUERY, {})
115124
return res.Validator
116125
}
@@ -151,12 +160,19 @@ export const fetchSignedTransactions = async (bridge: BridgesValues, afterDate:
151160
const validators = VALIDATORS_BY_BRIDGE[bridgeValue]
152161

153162
if (isEnvioBackend()) {
154-
const request = getEnvioGraphqlClient<{ Validator: Array<any> }>()
163+
type EnvioValidatorRow = {
164+
address: string
165+
name?: string | null
166+
bridgeType?: string | null
167+
signed?: Array<{ id: string }>
168+
executed?: Array<{ id: string }>
169+
}
170+
const request = getEnvioGraphqlClient<{ Validator: EnvioValidatorRow[] }>()
155171
const res = await request(ENVIO_VALIDATORS_ACTIVITY_QUERY, { after: String(afterDate) })
156172
const rows = (res.Validator || []).filter(
157-
(v) => String(v.bridgeType || '').toUpperCase() === bridgeValue,
173+
(v: EnvioValidatorRow) => String(v.bridgeType || '').toUpperCase() === bridgeValue,
158174
)
159-
return rows.map((v: any) => ({
175+
return rows.map((v: EnvioValidatorRow) => ({
160176
name: v.name || v.address,
161177
value: Array.isArray(v.signed) ? v.signed.length : 0,
162178
}))
@@ -196,12 +212,19 @@ export const fetchExecutedTransactions = async (bridge: BridgesValues, afterDate
196212
const validators = VALIDATORS_BY_BRIDGE[bridgeValue]
197213

198214
if (isEnvioBackend()) {
199-
const request = getEnvioGraphqlClient<{ Validator: Array<any> }>()
215+
type EnvioValidatorRow = {
216+
address: string
217+
name?: string | null
218+
bridgeType?: string | null
219+
signed?: Array<{ id: string }>
220+
executed?: Array<{ id: string }>
221+
}
222+
const request = getEnvioGraphqlClient<{ Validator: EnvioValidatorRow[] }>()
200223
const res = await request(ENVIO_VALIDATORS_ACTIVITY_QUERY, { after: String(afterDate) })
201224
const rows = (res.Validator || []).filter(
202-
(v) => String(v.bridgeType || '').toUpperCase() === bridgeValue,
225+
(v: EnvioValidatorRow) => String(v.bridgeType || '').toUpperCase() === bridgeValue,
203226
)
204-
return rows.map((v: any) => ({
227+
return rows.map((v: EnvioValidatorRow) => ({
205228
name: v.name || v.address,
206229
value: Array.isArray(v.executed) ? v.executed.length : 0,
207230
}))

envio-indexer/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# To create or update a token visit https://envio.dev/app/api-tokens
1+
ENVIO_RPC_HOME=

envio-indexer/config.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ raw_events: true
77
networks:
88
# [Home] (Gnosis)
99
- id: 100
10-
start_block: 7904944
10+
start_block: 39568341
11+
1112
contracts:
1213
- name: XDAIHome
1314
address:
1415
- 0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6
15-
start_block: 39567805
1616
handler: src/eventHandlers/XDAI/index.ts
1717
events:
1818
# [XDAI Home -> Foreign]
@@ -71,7 +71,6 @@ networks:
7171
- name: AMBHome
7272
address:
7373
- 0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59
74-
start_block: 39567805
7574
handler: src/eventHandlers/AMB/index.ts
7675
events:
7776
# [AMB Home -> Foreign]
@@ -122,7 +121,7 @@ networks:
122121
- 0xbe20f60339b06db32c319d46cf3bc9bacc0694ab
123122
- 0x68a64df7458a8eb2677991e657508fe00205332d
124123
- 0x5f0fe58709639a39c193521d919afaef02e570f7
125-
start_block: 39567805
124+
# start_block: 39567805
126125
handler: src/eventHandlers/AMB/index.ts
127126
events:
128127
- event: TokensBridgingInitiated(address indexed token, address indexed sender, uint256 value, bytes32 indexed messageId)
@@ -131,7 +130,6 @@ networks:
131130
- name: XDAIBridgeValidators
132131
address:
133132
- 0xB289f0e6fBDFf8EEE340498a56e1787B303F1B6D
134-
start_block: 7904944
135133
handler: src/eventHandlers/validator.ts
136134
events:
137135
- event: ValidatorAdded(address indexed validator)
@@ -146,7 +144,6 @@ networks:
146144
- name: AMBBridgeValidators
147145
address:
148146
- 0xA280feD8D7CaD9a76C8b50cA5c33c2534fFa5008
149-
start_block: 7904944
150147
handler: src/eventHandlers/validator.ts
151148
events:
152149
- event: ValidatorAdded(address indexed validator)

envio-indexer/src/blockHandler.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

envio-indexer/src/effects/getAmbMessageByHash.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

envio-indexer/src/effects/getInitiatorFromReceipt.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

envio-indexer/src/effects/getHomeMessageByHash.ts renamed to envio-indexer/src/effects/getMessageByHash.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import { S, experimental_createEffect } from "envio";
22
import { createPublicClient, http } from "viem";
33
import { gnosis } from "viem/chains";
4-
import HomeBridgeAbi from "../../abi/HomeBridgeErcToNative.json";
4+
import HomeXDAIAbi from "../../abi/HomeBridgeErcToNative.json";
5+
import HomeAMBAbi from "../../abi/HomeAMB.json";
6+
import { BridgeTypeEnum } from "../const";
57

6-
export const getHomeMessageByHash = experimental_createEffect(
8+
export const getMessageByHash = experimental_createEffect(
79
{
8-
name: "getHomeMessageByHash",
10+
name: "getMessageByHash",
911
input: {
1012
address: S.string,
1113
messageHash: S.string,
14+
bridge: S.string,
1215
},
1316
output: S.union([S.string, null]),
1417
cache: true,
1518
},
1619
async ({ input }) => {
17-
const rpc = process.env.RPC_GNOSIS as `http${string}` | undefined;
20+
const rpc = process.env.ENVIO_RPC_HOME as `http${string}` | undefined;
1821
if (!rpc) return null;
1922

2023
const client = createPublicClient({ chain: gnosis, transport: http(rpc) });
21-
2224
try {
2325
const bytes = await client.readContract({
2426
address: input.address as `0x${string}`,
25-
abi: HomeBridgeAbi as any,
27+
abi: input.bridge === BridgeTypeEnum.XDAI ? HomeXDAIAbi as any : HomeAMBAbi as any,
2628
functionName: "message",
2729
args: [input.messageHash as `0x${string}`],
2830
});

envio-indexer/src/eventHandlers/AMB/foreignToHome.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AMBForeign, AMBHome } from "generated";
22
import { BridgeTypeEnum, CHAIN, TransactionStatusEnum } from "../../const";
33
import { getValidator } from "../../utils/getValidator";
44
import { isOmniBridgeUsage, extractReceiverFromEncodedData, parseMessageIdFromEncodedData } from "../../utils/omnibridge";
5-
import { getAmbMessageByHash } from "../../effects/getAmbMessageByHash";
5+
import { getMessageByHash } from "../../effects/getMessageByHash";
66

77
/**
88
* AMB Foreign -> Home (ETH -> GC)
@@ -61,9 +61,9 @@ AMBForeign.UserRequestForAffirmation.handler(async ({ event, context }) => {
6161
// 2. Validation. Validators sign transaction (update validator lastActivity)
6262
AMBHome.SignedForAffirmation.handler(async ({ event, context }) => {
6363
const signer = event.params.signer.toLowerCase();
64-
const validator = await getValidator(context, signer);
64+
const validator = await getValidator(context, signer, BridgeTypeEnum.AMB);
6565
if (!validator) {
66-
context.log.error(`AMB: SignedForAffirmation - Validator ${signer} not found`);
66+
context.log.error(`AMB: SignedForAffirmation - Validator ${signer} not found, tx hash: ${event.transaction.hash}`);
6767
return;
6868
}
6969
context.Validator.set({ ...validator, lastActivity: BigInt(event.block.timestamp) });
@@ -76,9 +76,10 @@ AMBHome.SignedForAffirmation.handler(async ({ event, context }) => {
7676
if (cached?.messageId) {
7777
messageId = cached.messageId;
7878
} else {
79-
const encoded = await context.effect(getAmbMessageByHash, {
79+
const encoded = await context.effect(getMessageByHash, {
8080
address: event.srcAddress,
8181
messageHash,
82+
bridge: BridgeTypeEnum.AMB,
8283
});
8384
messageId = typeof encoded === "string" ? parseMessageIdFromEncodedData(encoded) : undefined;
8485
if (messageId) {
@@ -139,11 +140,13 @@ AMBHome.AffirmationCompleted.handler(async ({ event, context }) => {
139140
let executorId: string | undefined = undefined;
140141
let executorAddress: string | undefined = undefined;
141142
if (executorAddr) {
142-
const validator = await getValidator(context, executorAddr);
143+
const validator = await getValidator(context, executorAddr, BridgeTypeEnum.AMB);
143144
if (validator) {
144145
context.Validator.set({ ...validator, lastActivity: BigInt(timestamp) });
145146
executorId = validator.id;
146147
executorAddress = validator.address;
148+
} else {
149+
context.log.error(`AMB: AffirmationCompleted - Validator ${executorAddr} not found, tx hash: ${event.transaction.hash}`);
147150
}
148151
}
149152

0 commit comments

Comments
 (0)