Skip to content

Commit

Permalink
Refactor: Updates for wormholeInfo used values and types
Browse files Browse the repository at this point in the history
Refactor: Updates for wormholeInfo used values and types
  • Loading branch information
mmioana committed Dec 11, 2024
1 parent 5f78d20 commit f229d14
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
12 changes: 2 additions & 10 deletions apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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;
}

Expand All @@ -74,7 +67,6 @@ export const handleProxyColonyRequested = async (
completed: false,
targetChainId: destinationChainId.toNumber(),
wormholeInfo: {
emitterChainId,
sequence: emitterSequence,
emitterAddress,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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: ${
Expand Down Expand Up @@ -150,6 +147,11 @@ export const handleProxyColonyDeployed = async (
multiChainInfo: {
...actionData.multiChainInfo,
completed: isDeploymentCompleted,
wormholeInfo: {
emitterAddress: emitterAddress.toString(),
emitterChainId,
sequence: sequence.toString(),
},
},
},
});
Expand Down
19 changes: 19 additions & 0 deletions packages/clients/src/types.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 8 additions & 4 deletions packages/clients/src/wormholeClient.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down Expand Up @@ -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<Response> {
}): Promise<WormholeOperationsDetailsReturn> {
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();
}
}
14 changes: 7 additions & 7 deletions packages/graphql/src/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export type Scalars = {
export type ActionWormholeInfo = {
__typename?: 'ActionWormholeInfo';
emitterAddress: Scalars['String'];
emitterChainId: Scalars['Int'];
emitterChainId?: Maybe<Scalars['Int']>;
sequence: Scalars['String'];
};

export type ActionWormholeInfoInput = {
emitterAddress: Scalars['String'];
emitterChainId: Scalars['Int'];
emitterChainId?: InputMaybe<Scalars['Int']>;
sequence: Scalars['String'];
};

Expand Down Expand Up @@ -10092,7 +10092,7 @@ export type MultiChainInfoFragment = {
completed: boolean;
wormholeInfo?: {
__typename?: 'ActionWormholeInfo';
emitterChainId: number;
emitterChainId?: number | null;
emitterAddress: string;
sequence: string;
} | null;
Expand Down Expand Up @@ -10162,7 +10162,7 @@ export type ActionMetadataInfoFragment = {
completed: boolean;
wormholeInfo?: {
__typename?: 'ActionWormholeInfo';
emitterChainId: number;
emitterChainId?: number | null;
emitterAddress: string;
sequence: string;
} | null;
Expand Down Expand Up @@ -11176,7 +11176,7 @@ export type GetActionInfoQuery = {
completed: boolean;
wormholeInfo?: {
__typename?: 'ActionWormholeInfo';
emitterChainId: number;
emitterChainId?: number | null;
emitterAddress: string;
sequence: string;
} | null;
Expand Down Expand Up @@ -11952,7 +11952,7 @@ export type GetColonyActionByMotionIdQuery = {
completed: boolean;
wormholeInfo?: {
__typename?: 'ActionWormholeInfo';
emitterChainId: number;
emitterChainId?: number | null;
emitterAddress: string;
sequence: string;
} | null;
Expand Down Expand Up @@ -12133,7 +12133,7 @@ export type GetColonyActionByMultiSigIdQuery = {
completed: boolean;
wormholeInfo?: {
__typename?: 'ActionWormholeInfo';
emitterChainId: number;
emitterChainId?: number | null;
emitterAddress: string;
sequence: string;
} | null;
Expand Down

0 comments on commit f229d14

Please sign in to comment.