From 9b9c5eac5ae180e738bfcb9af46b7ec17b7de0c8 Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:13:36 -0400 Subject: [PATCH] sdk: improvements for relayer status function (#3157) * sdk: improvements for relayer status function * Fix boolean * Remove clients/js changes * Remove file * RPC change for bsc * sdk change * Remove info comments - add newline * sdk: improvements for relayer status function * Fix boolean * Remove clients/js changes * Remove file * RPC change for bsc * sdk change * Remove info comments - add newline * Prettier --- sdk/js/src/relayer/consts.ts | 8 ++--- sdk/js/src/relayer/relayer/helpers.ts | 3 +- sdk/js/src/relayer/relayer/info.ts | 48 +++++++++++++++++++++------ sdk/js/src/relayer/structs.ts | 44 ++++++++++++++++-------- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/sdk/js/src/relayer/consts.ts b/sdk/js/src/relayer/consts.ts index a5959b772..809a5c467 100644 --- a/sdk/js/src/relayer/consts.ts +++ b/sdk/js/src/relayer/consts.ts @@ -133,8 +133,8 @@ export const RPCS_BY_CHAIN: { [key in Network]: { [key in ChainName]?: string }; } = { MAINNET: { - ethereum: process.env.ETH_RPC, - bsc: process.env.BSC_RPC || "https://bsc-dataseed2.defibit.io", + ethereum: "https://rpc.ankr.com/eth", + bsc: "https://bsc-dataseed2.defibit.io", polygon: "https://rpc.ankr.com/polygon", avalanche: "https://rpc.ankr.com/avalanche", oasis: "https://emerald.oasis.dev", @@ -154,13 +154,13 @@ export const RPCS_BY_CHAIN: { terra2: "https://phoenix-lcd.terra.dev", terra: "https://columbus-fcd.terra.dev", injective: "https://k8s.mainnet.lcd.injective.network", - solana: process.env.SOLANA_RPC ?? "https://api.mainnet-beta.solana.com", + solana: "https://api.mainnet-beta.solana.com", }, TESTNET: { solana: "https://api.devnet.solana.com", terra: "https://bombay-lcd.terra.dev", ethereum: "https://rpc.ankr.com/eth_goerli", - bsc: "https://data-seed-prebsc-1-s1.binance.org:8545", + bsc: "https://bsc-testnet.publicnode.com", polygon: "https://rpc.ankr.com/polygon_mumbai", avalanche: "https://rpc.ankr.com/avalanche_fuji", oasis: "https://testnet.emerald.oasis.dev", diff --git a/sdk/js/src/relayer/relayer/helpers.ts b/sdk/js/src/relayer/relayer/helpers.ts index 42e66c3b9..2a865cfec 100644 --- a/sdk/js/src/relayer/relayer/helpers.ts +++ b/sdk/js/src/relayer/relayer/helpers.ts @@ -21,6 +21,7 @@ import { VaaKey, DeliveryOverrideArgs, parseForwardFailureError, + parseRefundStatus } from "../structs"; import { DeliveryProvider, @@ -269,7 +270,7 @@ async function transformDeliveryEvents( sourceVaaSequence: x.args[2], sourceChain, gasUsed: BigNumber.from(x.args[5]), - refundStatus: x.args[6], + refundStatus: parseRefundStatus(x.args[6]), revertString: status == DeliveryStatus.ReceiverFailure ? x.args[7] diff --git a/sdk/js/src/relayer/relayer/info.ts b/sdk/js/src/relayer/relayer/info.ts index 7d2668189..692e8fa73 100644 --- a/sdk/js/src/relayer/relayer/info.ts +++ b/sdk/js/src/relayer/relayer/info.ts @@ -39,7 +39,6 @@ export type InfoRequestParams = { wormholeRelayerAddresses?: Map; }; - export type GetPriceOptParams = { environment?: Network; receiverValue?: ethers.BigNumberish; @@ -235,9 +234,15 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string { instruction.extraReceiverValue ); stringifiedInfo += totalReceiverValue.gt(0) - ? `Amount to pass into target address: ${totalReceiverValue} wei of ${targetChainName} currency ${ + ? `Amount to pass into target address: ${ethers.utils.formatEther( + totalReceiverValue + )} of ${targetChainName} currency ${ instruction.extraReceiverValue.gt(0) - ? `${instruction.requestedReceiverValue} requested, ${instruction.extraReceiverValue} additionally paid for` + ? `\n${ethers.utils.formatEther( + instruction.requestedReceiverValue + )} requested, ${ethers.utils.formatEther( + instruction.extraReceiverValue + )} additionally paid for` : "" }\n` : ``; @@ -245,8 +250,19 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string { instruction.encodedExecutionInfo, 0 ); - stringifiedInfo += `Gas limit: ${executionInfo.gasLimit} ${targetChainName} gas\n\n`; - stringifiedInfo += `Refund rate: ${executionInfo.targetChainRefundPerGasUnused} of ${targetChainName} wei per unit of gas unused\n\n`; + stringifiedInfo += `Gas limit: ${executionInfo.gasLimit} ${targetChainName} gas\n`; + + const refundAddressChosen = + instruction.refundAddress !== instruction.refundDeliveryProvider; + if (refundAddressChosen) { + stringifiedInfo += `Refund rate: ${ethers.utils.formatEther( + executionInfo.targetChainRefundPerGasUnused + )} of ${targetChainName} currency per unit of gas unused\n`; + stringifiedInfo += `Refund address: ${instruction.refundAddress.toString( + "hex" + )}\n`; + } + stringifiedInfo += `\n`; stringifiedInfo += info.targetChainStatus.events .map( @@ -263,9 +279,19 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string { : e.revertString }\n` : "" - }Gas used: ${e.gasUsed.toString()}\nTransaction fee used: ${executionInfo.targetChainRefundPerGasUnused - .mul(e.gasUsed) - .toString()} wei of ${targetChainName} currency\n}` + }Gas used: ${e.gasUsed.toString()}\nTransaction fee used: ${ethers.utils.formatEther( + executionInfo.targetChainRefundPerGasUnused.mul(e.gasUsed) + )} of ${targetChainName} currency\n${ + !refundAddressChosen || e.status === "Forward Request Success" + ? "" + : `Refund amount: ${ethers.utils.formatEther( + executionInfo.targetChainRefundPerGasUnused.mul( + executionInfo.gasLimit.sub(e.gasUsed) + ) + )} of ${targetChainName} currency \nRefund status: ${ + e.refundStatus + }\n` + }` ) .join("\n"); } else if ( @@ -279,11 +305,11 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string { const targetChainName = CHAIN_ID_TO_NAME[instruction.targetChainId as ChainId]; - stringifiedInfo += `\nA refund of ${ + stringifiedInfo += `\nA refund of ${ethers.utils.formatEther( instruction.extraReceiverValue - } ${targetChainName} wei was requested to be sent to ${targetChainName}, address 0x${info.deliveryInstruction.refundAddress.toString( + )} ${targetChainName} currency was requested to be sent to ${targetChainName}, address 0x${info.deliveryInstruction.refundAddress.toString( "hex" - )}`; + )}\n\n`; stringifiedInfo += info.targetChainStatus.events diff --git a/sdk/js/src/relayer/structs.ts b/sdk/js/src/relayer/structs.ts index 43eb77a78..f9bbc2caa 100644 --- a/sdk/js/src/relayer/structs.ts +++ b/sdk/js/src/relayer/structs.ts @@ -22,11 +22,20 @@ export enum DeliveryStatus { } export enum RefundStatus { - RefundSent, - RefundFail, - CrossChainRefundSent, - CrossChainRefundFailProviderNotSupported, - CrossChainRefundFailNotEnough + RefundSent = "Refund Sent", + RefundFail = "Refund Fail", + CrossChainRefundSent = "Cross Chain Refund Sent", + CrossChainRefundFailProviderNotSupported = "Cross Chain Refund Fail - Provider does not support the refund chain", + CrossChainRefundFailNotEnough = "Cross Chain Refund Fail - Refund too low for cross chain refund" +} + +export function parseRefundStatus(index: number) { + return index === 0 ? RefundStatus.RefundSent + : index === 1 ? RefundStatus.RefundFail + : index === 2 ? RefundStatus.CrossChainRefundSent + : index === 3 ? RefundStatus.CrossChainRefundFailProviderNotSupported + : index === 4 ? RefundStatus.CrossChainRefundFailNotEnough + : RefundStatus.CrossChainRefundFailProviderNotSupported; } export interface VaaKey { @@ -348,15 +357,24 @@ export function parseForwardFailureError( bytes: Buffer ): string { let idx = 4; - console.log(bytes.length); - const amountOfFunds = ethers.BigNumber.from( - Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) - ); idx += 32; - const amountOfFundsNeeded = ethers.BigNumber.from( - Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) - ); - return `Not enough funds leftover for forward: Had ${amountOfFunds.toString()} wei and needed ${amountOfFundsNeeded.toString()} wei.` + if(bytes.length <= idx) { + return `Delivery Provider failed in performing forward` + } + try { + const amountOfFunds = ethers.BigNumber.from( + Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) + ); + idx += 32; + const amountOfFundsNeeded = ethers.BigNumber.from( + Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) + ); + return `Not enough funds leftover for forward: Had ${ethers.utils.formatEther(amountOfFunds)} and needed ${ethers.utils.formatEther(amountOfFundsNeeded)}.` + + } catch (err) { + return `Delivery Provider unexpectedly failed in performing forward` + } + } export function parseOverrideInfoFromDeliveryEvent(