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
This commit is contained in:
derpy-duck 2023-06-30 14:13:36 -04:00 committed by GitHub
parent 7de46f68b4
commit 9b9c5eac5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 29 deletions

View File

@ -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",

View File

@ -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]

View File

@ -39,7 +39,6 @@ export type InfoRequestParams = {
wormholeRelayerAddresses?: Map<ChainName, string>;
};
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

View File

@ -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(