From f229d140325cc55c3d9da3d13d7ffb03721bf6b2 Mon Sep 17 00:00:00 2001 From: Mihaela-Ioana Mot <32430018+mmioana@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:30:32 +0100 Subject: [PATCH] Refactor: Updates for wormholeInfo used values and types Refactor: Updates for wormholeInfo used values and types --- .../proxyColonies/proxyColonyRequested.ts | 12 ++---------- .../proxyColonies/proxyColonyDeployed.ts | 16 +++++++++------- packages/clients/src/types.ts | 19 +++++++++++++++++++ packages/clients/src/wormholeClient.ts | 12 ++++++++---- packages/graphql/src/generated.ts | 14 +++++++------- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.ts b/apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.ts index ef81eb7f..15414f4b 100644 --- a/apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.ts +++ b/apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.ts @@ -43,9 +43,6 @@ export const handleProxyColonyRequested = async ( ContractEventsSignatures.ProxyColonyRequested === event?.signature, ); - // @NOTE remove this log once we know for sure which data we need from the events - console.log(wormholeEvent, proxyRequestedEvent); - if (!wormholeEvent || !proxyRequestedEvent) { output( `ProxyColonyRequested or LogMessagePublished are not present in the same block`, @@ -57,13 +54,9 @@ export const handleProxyColonyRequested = async ( const { sender, sequence } = wormholeEvent.args; const emitterAddress = sender.toString(); const emitterSequence = sequence.toString(); - // @TODO this needs to be updated to the correct value - const emitterChainId = destinationChainId.toNumber(); - if (!emitterChainId || !emitterAddress || !sequence) { - output( - 'Missing arguments on the ProxyColonyRequested and the LogMessagePublished events', - ); + if (!emitterAddress || !sequence) { + output('Missing arguments on the LogMessagePublished events'); return; } @@ -74,7 +67,6 @@ export const handleProxyColonyRequested = async ( completed: false, targetChainId: destinationChainId.toNumber(), wormholeInfo: { - emitterChainId, sequence: emitterSequence, emitterAddress, }, diff --git a/apps/proxy-chain/src/handlers/proxyColonies/proxyColonyDeployed.ts b/apps/proxy-chain/src/handlers/proxyColonies/proxyColonyDeployed.ts index 667102d2..18ade121 100644 --- a/apps/proxy-chain/src/handlers/proxyColonies/proxyColonyDeployed.ts +++ b/apps/proxy-chain/src/handlers/proxyColonies/proxyColonyDeployed.ts @@ -68,9 +68,6 @@ export const handleProxyColonyDeployed = async ( return; } - // @NOTE remove these logs once we know for sure which data we need from the events - console.log(wormholeEvent, proxyDeployedEvent); - console.log(`RPC provider chain id`, rpcProvider.getChainId()); console.log( `Mapped wormhole chain id`, @@ -83,20 +80,20 @@ export const handleProxyColonyDeployed = async ( let isDeploymentCompleted = false; try { - const multiChainBridgeOperationsResponse = + const multiChainBridgeOperationsData = await multiChainBridgeClient.fetchOperationDetails({ emitterAddress, emitterChainId, sequence, }); - const multiChainBridgeOperationsData = - await multiChainBridgeOperationsResponse.json(); sourceChainTxHash = multiChainBridgeOperationsData?.sourceChain?.transaction?.txHash; const sourceChainOperationStatus = multiChainBridgeOperationsData?.sourceChain?.status; - isDeploymentCompleted = sourceChainOperationStatus === 'confirmed'; // @TODO need to check what values are available + isDeploymentCompleted = + sourceChainOperationStatus === + multiChainBridgeClient.REQ_STATUS.CONFIRMED; } catch (error) { output( `Error while fetching multi-chain bridge operations details: ${ @@ -150,6 +147,11 @@ export const handleProxyColonyDeployed = async ( multiChainInfo: { ...actionData.multiChainInfo, completed: isDeploymentCompleted, + wormholeInfo: { + emitterAddress: emitterAddress.toString(), + emitterChainId, + sequence: sequence.toString(), + }, }, }, }); diff --git a/packages/clients/src/types.ts b/packages/clients/src/types.ts index b5d86141..1a2bea64 100644 --- a/packages/clients/src/types.ts +++ b/packages/clients/src/types.ts @@ -1 +1,20 @@ export type ChainID = string; + +export type WormholeOperationsDetailsReturn = + | { + sourceChain: { + chainId: string; + transaction?: { + txHash: string; + }; + status: string; + }; + targetChain: { + chainId: string; + transaction?: { + txHash: string; + }; + status: string; + }; + } + | undefined; diff --git a/packages/clients/src/wormholeClient.ts b/packages/clients/src/wormholeClient.ts index 011385b3..9aab3158 100644 --- a/packages/clients/src/wormholeClient.ts +++ b/packages/clients/src/wormholeClient.ts @@ -1,11 +1,15 @@ import { BigNumber } from 'ethers'; -import { ChainID } from './types'; +import { ChainID, WormholeOperationsDetailsReturn } from './types'; import { NetworkId } from '@colony/colony-js'; import { output } from '@joincolony/utils'; export class WormholeClient { private readonly bridgeEndpoint: string; + public REQ_STATUS = { + CONFIRMED: 'confirmed', + }; + constructor(bridgeEndpoint: string) { this.bridgeEndpoint = bridgeEndpoint; } @@ -77,18 +81,18 @@ export class WormholeClient { * @param args - The operation parameters including emitterChainId, emitterAddress, and sequence. * @returns The response from the bridge API. */ - // @TODO type this public async fetchOperationDetails(args: { emitterChainId: number; emitterAddress: string; sequence: BigNumber; - }): Promise { + }): Promise { const { emitterChainId, emitterAddress, sequence } = args; const paddedEmitterAddress = this.padHexToByteLength(emitterAddress); const sequenceString = this.bigNumberToString(sequence); const url = `${this.bridgeEndpoint}/v1/operations/${emitterChainId}/${paddedEmitterAddress}/${sequenceString}`; - return fetch(url); + const request = await fetch(url); + return request.json(); } } diff --git a/packages/graphql/src/generated.ts b/packages/graphql/src/generated.ts index f9784644..1c922b5d 100644 --- a/packages/graphql/src/generated.ts +++ b/packages/graphql/src/generated.ts @@ -31,13 +31,13 @@ export type Scalars = { export type ActionWormholeInfo = { __typename?: 'ActionWormholeInfo'; emitterAddress: Scalars['String']; - emitterChainId: Scalars['Int']; + emitterChainId?: Maybe; sequence: Scalars['String']; }; export type ActionWormholeInfoInput = { emitterAddress: Scalars['String']; - emitterChainId: Scalars['Int']; + emitterChainId?: InputMaybe; sequence: Scalars['String']; }; @@ -10092,7 +10092,7 @@ export type MultiChainInfoFragment = { completed: boolean; wormholeInfo?: { __typename?: 'ActionWormholeInfo'; - emitterChainId: number; + emitterChainId?: number | null; emitterAddress: string; sequence: string; } | null; @@ -10162,7 +10162,7 @@ export type ActionMetadataInfoFragment = { completed: boolean; wormholeInfo?: { __typename?: 'ActionWormholeInfo'; - emitterChainId: number; + emitterChainId?: number | null; emitterAddress: string; sequence: string; } | null; @@ -11176,7 +11176,7 @@ export type GetActionInfoQuery = { completed: boolean; wormholeInfo?: { __typename?: 'ActionWormholeInfo'; - emitterChainId: number; + emitterChainId?: number | null; emitterAddress: string; sequence: string; } | null; @@ -11952,7 +11952,7 @@ export type GetColonyActionByMotionIdQuery = { completed: boolean; wormholeInfo?: { __typename?: 'ActionWormholeInfo'; - emitterChainId: number; + emitterChainId?: number | null; emitterAddress: string; sequence: string; } | null; @@ -12133,7 +12133,7 @@ export type GetColonyActionByMultiSigIdQuery = { completed: boolean; wormholeInfo?: { __typename?: 'ActionWormholeInfo'; - emitterChainId: number; + emitterChainId?: number | null; emitterAddress: string; sequence: string; } | null;