From d8f1223d7b15f7b75d230df302b14ebb8f3dd371 Mon Sep 17 00:00:00 2001 From: Joe Howarth Date: Fri, 24 Mar 2023 13:48:04 -0500 Subject: [PATCH] rebase on top of contract changes --- relayer-engine-v2/pkgs/sdk/src/main/status.ts | 10 +-- relayer-engine-v2/pkgs/sdk/src/structs.ts | 73 ++++++++++++------- relayer_engine/pkgs/sdk/src/structs.ts | 73 ++++++++++++------- sdk/src/structs.ts | 73 ++++++++++++------- 4 files changed, 147 insertions(+), 82 deletions(-) diff --git a/relayer-engine-v2/pkgs/sdk/src/main/status.ts b/relayer-engine-v2/pkgs/sdk/src/main/status.ts index 5e658da7..f6ee5343 100644 --- a/relayer-engine-v2/pkgs/sdk/src/main/status.ts +++ b/relayer-engine-v2/pkgs/sdk/src/main/status.ts @@ -58,7 +58,6 @@ type InfoRequest = { sourceChainProvider?: ethers.providers.Provider targetChainProviders?: Map targetChainBlockRanges?: Map - sourceNonce?: number coreRelayerWhMessageIndex?: number } @@ -113,10 +112,10 @@ export function stringifyInfo(info: DeliveryInfo | RedeliveryInfo): string { stringifiedInfo += (`Found Redelivery request in transaction ${info.redeliverySourceTransactionHash} on ${printChain(info.redeliverySourceChainId)}\n`) stringifiedInfo += (`Original Delivery Source Chain: ${printChain(info.redeliveryInstruction.sourceChain)}\n`) stringifiedInfo += (`Original Delivery Source Transaction Hash: 0x${info.redeliveryInstruction.sourceTxHash.toString("hex")}\n`) - stringifiedInfo += (`Original Delivery Source Nonce: ${info.redeliveryInstruction.sourceNonce}\n`) + //stringifiedInfo += (`Original Delivery Source Nonce: ${info.redeliveryInstruction.sourceNonce}\n`) stringifiedInfo += (`Target Chain: ${printChain(info.redeliveryInstruction.targetChain)}\n`) stringifiedInfo += (`multisendIndex: ${info.redeliveryInstruction.multisendIndex}\n`) - stringifiedInfo += (`deliveryIndex: ${info.redeliveryInstruction.deliveryIndex}\n`) + //stringifiedInfo += (`deliveryIndex: ${info.redeliveryInstruction.deliveryIndex}\n`) stringifiedInfo += (`New max amount (in target chain currency) to use for gas: ${info.redeliveryInstruction.newMaximumRefundTarget}\n`) stringifiedInfo += (`New amount (in target chain currency) to pass into target address: ${info.redeliveryInstruction.newMaximumRefundTarget}\n`) stringifiedInfo += (`New target chain gas limit: ${info.redeliveryInstruction.executionParameters.gasLimit}\n`) @@ -175,7 +174,6 @@ export async function getDeliveryInfoBySourceTx( bridgeAddress, tryNativeToHexString(coreRelayerAddress, "ethereum"), infoRequest.coreRelayerWhMessageIndex ? infoRequest.coreRelayerWhMessageIndex : 0, - infoRequest.sourceNonce?.toString() ) const { type, parsed } = parseWormholeLog(deliveryLog.log) @@ -318,7 +316,6 @@ export function findLog( bridgeAddress: string, emitterAddress: string, index: number, - nonce?: string ): { log: ethers.providers.Log; sequence: string } { const bridgeLogs = receipt.logs.filter((l) => { return l.address === bridgeAddress @@ -340,8 +337,7 @@ export function findLog( const filtered = parsed.filter( (x) => - x.emitterAddress == emitterAddress.toLowerCase() && - (!nonce || x.nonce == nonce.toLowerCase()) + x.emitterAddress == emitterAddress.toLowerCase() ) if (filtered.length == 0) { diff --git a/relayer-engine-v2/pkgs/sdk/src/structs.ts b/relayer-engine-v2/pkgs/sdk/src/structs.ts index 714cc282..c1c197ab 100644 --- a/relayer-engine-v2/pkgs/sdk/src/structs.ts +++ b/relayer-engine-v2/pkgs/sdk/src/structs.ts @@ -14,10 +14,16 @@ export interface DeliveryInstructionsContainer { messages: MessageInfo[] } +export enum MessageInfoType { + EmitterSequence = 0, + VaaHash = 1, +} + export interface MessageInfo { - emitterAddress: Buffer - sequence: BigNumber - vaaHash: Buffer + payloadType: MessageInfoType + emitterAddress?: Buffer + sequence?: BigNumber + vaaHash?: Buffer } export interface DeliveryInstruction { @@ -39,9 +45,8 @@ export interface RedeliveryByTxHashInstruction { payloadId: number //2 sourceChain: number sourceTxHash: Buffer - sourceNonce: BigNumber + deliveryVaaSequence: BigNumber targetChain: number - deliveryIndex: number multisendIndex: number newMaximumRefundTarget: BigNumber newReceiverValueTarget: BigNumber @@ -92,7 +97,7 @@ export function parseDeliveryInstructionsContainer( Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) ) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 instructions.push( // dumb typechain format @@ -106,19 +111,15 @@ export function parseDeliveryInstructionsContainer( } ) } - const messages = [] as MessageInfo[] + + // parse the manifest const numMessages = bytes.readUInt8(idx) idx += 1 + + const idxPtr: [number] = [idx] + const messages = [] as MessageInfo[] for (let i = 0; i < numMessages; ++i) { - const emitterAddress = bytes.slice(idx, idx + 32) - idx += 32 - const sequence = ethers.BigNumber.from( - Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) - ) - idx += 8 - const vaaHash = bytes.slice(idx, idx + 32) - idx += 32 - messages.push({ emitterAddress, sequence, vaaHash }) + messages.push(parseMessageInfo(bytes, idxPtr)) } return { payloadId, @@ -128,6 +129,27 @@ export function parseDeliveryInstructionsContainer( } } +function parseMessageInfo(bytes: Buffer, idxPtr: [number]): MessageInfo { + let idx = idxPtr[0] + const payloadType = bytes.readUInt8(idx) as MessageInfoType + switch (payloadType) { + case MessageInfoType.EmitterSequence: + const emitterAddress = bytes.slice(idx, idx + 32) + idx += 32 + const sequence = ethers.BigNumber.from( + Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) + ) + idx += 8 + idxPtr[0] = idx + return { emitterAddress, sequence, payloadType } + case MessageInfoType.VaaHash: + const vaaHash = bytes.slice(idx, idx + 32) + idx += 32 + idxPtr[0] = idx + return { vaaHash, payloadType } + } +} + export function parseRedeliveryByTxHashInstruction( bytes: Buffer ): RedeliveryByTxHashInstruction { @@ -146,15 +168,12 @@ export function parseRedeliveryByTxHashInstruction( const sourceTxHash = bytes.slice(idx, idx + 32) idx += 32 - const sourceNonce = BigNumber.from(bytes.slice(idx, idx + 4)) - idx += 4 + const deliveryVaaSequence = BigNumber.from(bytes.slice(idx, idx + 8)) + idx += 8 const targetChain = bytes.readUInt16BE(idx) idx += 2 - const deliveryIndex = bytes.readUint8(idx) - idx += 1 - const multisendIndex = bytes.readUint8(idx) idx += 1 @@ -165,15 +184,14 @@ export function parseRedeliveryByTxHashInstruction( const newReceiverValueTarget = BigNumber.from(bytes.slice(idx, idx + 32)) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 return { payloadId, sourceChain, sourceTxHash, - sourceNonce, + deliveryVaaSequence, targetChain, - deliveryIndex, multisendIndex, newMaximumRefundTarget, newReceiverValueTarget, @@ -181,13 +199,18 @@ export function parseRedeliveryByTxHashInstruction( } } -function parseExecutionParameters(bytes: Buffer, idx: number = 0): ExecutionParameters { +function parseExecutionParameters( + bytes: Buffer, + idxPtr: [number] = [0] +): ExecutionParameters { + let idx = idxPtr[0] const version = bytes.readUInt8(idx) idx += 1 const gasLimit = bytes.readUint32BE(idx) idx += 4 const providerDeliveryAddress = bytes.slice(idx, idx + 32) idx += 32 + idxPtr[0] = idx return { version, gasLimit, providerDeliveryAddress } } diff --git a/relayer_engine/pkgs/sdk/src/structs.ts b/relayer_engine/pkgs/sdk/src/structs.ts index 714cc282..c1c197ab 100644 --- a/relayer_engine/pkgs/sdk/src/structs.ts +++ b/relayer_engine/pkgs/sdk/src/structs.ts @@ -14,10 +14,16 @@ export interface DeliveryInstructionsContainer { messages: MessageInfo[] } +export enum MessageInfoType { + EmitterSequence = 0, + VaaHash = 1, +} + export interface MessageInfo { - emitterAddress: Buffer - sequence: BigNumber - vaaHash: Buffer + payloadType: MessageInfoType + emitterAddress?: Buffer + sequence?: BigNumber + vaaHash?: Buffer } export interface DeliveryInstruction { @@ -39,9 +45,8 @@ export interface RedeliveryByTxHashInstruction { payloadId: number //2 sourceChain: number sourceTxHash: Buffer - sourceNonce: BigNumber + deliveryVaaSequence: BigNumber targetChain: number - deliveryIndex: number multisendIndex: number newMaximumRefundTarget: BigNumber newReceiverValueTarget: BigNumber @@ -92,7 +97,7 @@ export function parseDeliveryInstructionsContainer( Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) ) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 instructions.push( // dumb typechain format @@ -106,19 +111,15 @@ export function parseDeliveryInstructionsContainer( } ) } - const messages = [] as MessageInfo[] + + // parse the manifest const numMessages = bytes.readUInt8(idx) idx += 1 + + const idxPtr: [number] = [idx] + const messages = [] as MessageInfo[] for (let i = 0; i < numMessages; ++i) { - const emitterAddress = bytes.slice(idx, idx + 32) - idx += 32 - const sequence = ethers.BigNumber.from( - Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) - ) - idx += 8 - const vaaHash = bytes.slice(idx, idx + 32) - idx += 32 - messages.push({ emitterAddress, sequence, vaaHash }) + messages.push(parseMessageInfo(bytes, idxPtr)) } return { payloadId, @@ -128,6 +129,27 @@ export function parseDeliveryInstructionsContainer( } } +function parseMessageInfo(bytes: Buffer, idxPtr: [number]): MessageInfo { + let idx = idxPtr[0] + const payloadType = bytes.readUInt8(idx) as MessageInfoType + switch (payloadType) { + case MessageInfoType.EmitterSequence: + const emitterAddress = bytes.slice(idx, idx + 32) + idx += 32 + const sequence = ethers.BigNumber.from( + Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) + ) + idx += 8 + idxPtr[0] = idx + return { emitterAddress, sequence, payloadType } + case MessageInfoType.VaaHash: + const vaaHash = bytes.slice(idx, idx + 32) + idx += 32 + idxPtr[0] = idx + return { vaaHash, payloadType } + } +} + export function parseRedeliveryByTxHashInstruction( bytes: Buffer ): RedeliveryByTxHashInstruction { @@ -146,15 +168,12 @@ export function parseRedeliveryByTxHashInstruction( const sourceTxHash = bytes.slice(idx, idx + 32) idx += 32 - const sourceNonce = BigNumber.from(bytes.slice(idx, idx + 4)) - idx += 4 + const deliveryVaaSequence = BigNumber.from(bytes.slice(idx, idx + 8)) + idx += 8 const targetChain = bytes.readUInt16BE(idx) idx += 2 - const deliveryIndex = bytes.readUint8(idx) - idx += 1 - const multisendIndex = bytes.readUint8(idx) idx += 1 @@ -165,15 +184,14 @@ export function parseRedeliveryByTxHashInstruction( const newReceiverValueTarget = BigNumber.from(bytes.slice(idx, idx + 32)) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 return { payloadId, sourceChain, sourceTxHash, - sourceNonce, + deliveryVaaSequence, targetChain, - deliveryIndex, multisendIndex, newMaximumRefundTarget, newReceiverValueTarget, @@ -181,13 +199,18 @@ export function parseRedeliveryByTxHashInstruction( } } -function parseExecutionParameters(bytes: Buffer, idx: number = 0): ExecutionParameters { +function parseExecutionParameters( + bytes: Buffer, + idxPtr: [number] = [0] +): ExecutionParameters { + let idx = idxPtr[0] const version = bytes.readUInt8(idx) idx += 1 const gasLimit = bytes.readUint32BE(idx) idx += 4 const providerDeliveryAddress = bytes.slice(idx, idx + 32) idx += 32 + idxPtr[0] = idx return { version, gasLimit, providerDeliveryAddress } } diff --git a/sdk/src/structs.ts b/sdk/src/structs.ts index 714cc282..c1c197ab 100644 --- a/sdk/src/structs.ts +++ b/sdk/src/structs.ts @@ -14,10 +14,16 @@ export interface DeliveryInstructionsContainer { messages: MessageInfo[] } +export enum MessageInfoType { + EmitterSequence = 0, + VaaHash = 1, +} + export interface MessageInfo { - emitterAddress: Buffer - sequence: BigNumber - vaaHash: Buffer + payloadType: MessageInfoType + emitterAddress?: Buffer + sequence?: BigNumber + vaaHash?: Buffer } export interface DeliveryInstruction { @@ -39,9 +45,8 @@ export interface RedeliveryByTxHashInstruction { payloadId: number //2 sourceChain: number sourceTxHash: Buffer - sourceNonce: BigNumber + deliveryVaaSequence: BigNumber targetChain: number - deliveryIndex: number multisendIndex: number newMaximumRefundTarget: BigNumber newReceiverValueTarget: BigNumber @@ -92,7 +97,7 @@ export function parseDeliveryInstructionsContainer( Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) ) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 instructions.push( // dumb typechain format @@ -106,19 +111,15 @@ export function parseDeliveryInstructionsContainer( } ) } - const messages = [] as MessageInfo[] + + // parse the manifest const numMessages = bytes.readUInt8(idx) idx += 1 + + const idxPtr: [number] = [idx] + const messages = [] as MessageInfo[] for (let i = 0; i < numMessages; ++i) { - const emitterAddress = bytes.slice(idx, idx + 32) - idx += 32 - const sequence = ethers.BigNumber.from( - Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) - ) - idx += 8 - const vaaHash = bytes.slice(idx, idx + 32) - idx += 32 - messages.push({ emitterAddress, sequence, vaaHash }) + messages.push(parseMessageInfo(bytes, idxPtr)) } return { payloadId, @@ -128,6 +129,27 @@ export function parseDeliveryInstructionsContainer( } } +function parseMessageInfo(bytes: Buffer, idxPtr: [number]): MessageInfo { + let idx = idxPtr[0] + const payloadType = bytes.readUInt8(idx) as MessageInfoType + switch (payloadType) { + case MessageInfoType.EmitterSequence: + const emitterAddress = bytes.slice(idx, idx + 32) + idx += 32 + const sequence = ethers.BigNumber.from( + Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) + ) + idx += 8 + idxPtr[0] = idx + return { emitterAddress, sequence, payloadType } + case MessageInfoType.VaaHash: + const vaaHash = bytes.slice(idx, idx + 32) + idx += 32 + idxPtr[0] = idx + return { vaaHash, payloadType } + } +} + export function parseRedeliveryByTxHashInstruction( bytes: Buffer ): RedeliveryByTxHashInstruction { @@ -146,15 +168,12 @@ export function parseRedeliveryByTxHashInstruction( const sourceTxHash = bytes.slice(idx, idx + 32) idx += 32 - const sourceNonce = BigNumber.from(bytes.slice(idx, idx + 4)) - idx += 4 + const deliveryVaaSequence = BigNumber.from(bytes.slice(idx, idx + 8)) + idx += 8 const targetChain = bytes.readUInt16BE(idx) idx += 2 - const deliveryIndex = bytes.readUint8(idx) - idx += 1 - const multisendIndex = bytes.readUint8(idx) idx += 1 @@ -165,15 +184,14 @@ export function parseRedeliveryByTxHashInstruction( const newReceiverValueTarget = BigNumber.from(bytes.slice(idx, idx + 32)) idx += 32 - const executionParameters = parseExecutionParameters(bytes, idx) + const executionParameters = parseExecutionParameters(bytes, [idx]) idx += 37 return { payloadId, sourceChain, sourceTxHash, - sourceNonce, + deliveryVaaSequence, targetChain, - deliveryIndex, multisendIndex, newMaximumRefundTarget, newReceiverValueTarget, @@ -181,13 +199,18 @@ export function parseRedeliveryByTxHashInstruction( } } -function parseExecutionParameters(bytes: Buffer, idx: number = 0): ExecutionParameters { +function parseExecutionParameters( + bytes: Buffer, + idxPtr: [number] = [0] +): ExecutionParameters { + let idx = idxPtr[0] const version = bytes.readUInt8(idx) idx += 1 const gasLimit = bytes.readUint32BE(idx) idx += 4 const providerDeliveryAddress = bytes.slice(idx, idx + 32) idx += 32 + idxPtr[0] = idx return { version, gasLimit, providerDeliveryAddress } }