Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
rebase on top of contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeHowarth committed Mar 24, 2023
1 parent a1250dc commit d8f1223
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 82 deletions.
10 changes: 3 additions & 7 deletions relayer-engine-v2/pkgs/sdk/src/main/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type InfoRequest = {
sourceChainProvider?: ethers.providers.Provider
targetChainProviders?: Map<number, ethers.providers.Provider>
targetChainBlockRanges?: Map<number, [ethers.providers.BlockTag, ethers.providers.BlockTag]>
sourceNonce?: number
coreRelayerWhMessageIndex?: number
}

Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
73 changes: 48 additions & 25 deletions relayer-engine-v2/pkgs/sdk/src/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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

Expand All @@ -165,29 +184,33 @@ 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,
executionParameters,
}
}

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 }
}

Expand Down
73 changes: 48 additions & 25 deletions relayer_engine/pkgs/sdk/src/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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

Expand All @@ -165,29 +184,33 @@ 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,
executionParameters,
}
}

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 }
}

Expand Down
Loading

0 comments on commit d8f1223

Please sign in to comment.