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 }; [key in Network]: { [key in ChainName]?: string };
} = { } = {
MAINNET: { MAINNET: {
ethereum: process.env.ETH_RPC, ethereum: "https://rpc.ankr.com/eth",
bsc: process.env.BSC_RPC || "https://bsc-dataseed2.defibit.io", bsc: "https://bsc-dataseed2.defibit.io",
polygon: "https://rpc.ankr.com/polygon", polygon: "https://rpc.ankr.com/polygon",
avalanche: "https://rpc.ankr.com/avalanche", avalanche: "https://rpc.ankr.com/avalanche",
oasis: "https://emerald.oasis.dev", oasis: "https://emerald.oasis.dev",
@ -154,13 +154,13 @@ export const RPCS_BY_CHAIN: {
terra2: "https://phoenix-lcd.terra.dev", terra2: "https://phoenix-lcd.terra.dev",
terra: "https://columbus-fcd.terra.dev", terra: "https://columbus-fcd.terra.dev",
injective: "https://k8s.mainnet.lcd.injective.network", 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: { TESTNET: {
solana: "https://api.devnet.solana.com", solana: "https://api.devnet.solana.com",
terra: "https://bombay-lcd.terra.dev", terra: "https://bombay-lcd.terra.dev",
ethereum: "https://rpc.ankr.com/eth_goerli", 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", polygon: "https://rpc.ankr.com/polygon_mumbai",
avalanche: "https://rpc.ankr.com/avalanche_fuji", avalanche: "https://rpc.ankr.com/avalanche_fuji",
oasis: "https://testnet.emerald.oasis.dev", oasis: "https://testnet.emerald.oasis.dev",

View File

@ -21,6 +21,7 @@ import {
VaaKey, VaaKey,
DeliveryOverrideArgs, DeliveryOverrideArgs,
parseForwardFailureError, parseForwardFailureError,
parseRefundStatus
} from "../structs"; } from "../structs";
import { import {
DeliveryProvider, DeliveryProvider,
@ -269,7 +270,7 @@ async function transformDeliveryEvents(
sourceVaaSequence: x.args[2], sourceVaaSequence: x.args[2],
sourceChain, sourceChain,
gasUsed: BigNumber.from(x.args[5]), gasUsed: BigNumber.from(x.args[5]),
refundStatus: x.args[6], refundStatus: parseRefundStatus(x.args[6]),
revertString: revertString:
status == DeliveryStatus.ReceiverFailure status == DeliveryStatus.ReceiverFailure
? x.args[7] ? x.args[7]

View File

@ -39,7 +39,6 @@ export type InfoRequestParams = {
wormholeRelayerAddresses?: Map<ChainName, string>; wormholeRelayerAddresses?: Map<ChainName, string>;
}; };
export type GetPriceOptParams = { export type GetPriceOptParams = {
environment?: Network; environment?: Network;
receiverValue?: ethers.BigNumberish; receiverValue?: ethers.BigNumberish;
@ -235,9 +234,15 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string {
instruction.extraReceiverValue instruction.extraReceiverValue
); );
stringifiedInfo += totalReceiverValue.gt(0) 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.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` }\n`
: ``; : ``;
@ -245,8 +250,19 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string {
instruction.encodedExecutionInfo, instruction.encodedExecutionInfo,
0 0
); );
stringifiedInfo += `Gas limit: ${executionInfo.gasLimit} ${targetChainName} gas\n\n`; stringifiedInfo += `Gas limit: ${executionInfo.gasLimit} ${targetChainName} gas\n`;
stringifiedInfo += `Refund rate: ${executionInfo.targetChainRefundPerGasUnused} of ${targetChainName} wei per unit of gas unused\n\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 stringifiedInfo += info.targetChainStatus.events
.map( .map(
@ -263,9 +279,19 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string {
: e.revertString : e.revertString
}\n` }\n`
: "" : ""
}Gas used: ${e.gasUsed.toString()}\nTransaction fee used: ${executionInfo.targetChainRefundPerGasUnused }Gas used: ${e.gasUsed.toString()}\nTransaction fee used: ${ethers.utils.formatEther(
.mul(e.gasUsed) executionInfo.targetChainRefundPerGasUnused.mul(e.gasUsed)
.toString()} wei of ${targetChainName} currency\n}` )} 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"); .join("\n");
} else if ( } else if (
@ -279,11 +305,11 @@ export function stringifyWormholeRelayerInfo(info: DeliveryInfo): string {
const targetChainName = const targetChainName =
CHAIN_ID_TO_NAME[instruction.targetChainId as ChainId]; CHAIN_ID_TO_NAME[instruction.targetChainId as ChainId];
stringifiedInfo += `\nA refund of ${ stringifiedInfo += `\nA refund of ${ethers.utils.formatEther(
instruction.extraReceiverValue 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" "hex"
)}`; )}\n\n`;
stringifiedInfo += info.targetChainStatus.events stringifiedInfo += info.targetChainStatus.events

View File

@ -22,11 +22,20 @@ export enum DeliveryStatus {
} }
export enum RefundStatus { export enum RefundStatus {
RefundSent, RefundSent = "Refund Sent",
RefundFail, RefundFail = "Refund Fail",
CrossChainRefundSent, CrossChainRefundSent = "Cross Chain Refund Sent",
CrossChainRefundFailProviderNotSupported, CrossChainRefundFailProviderNotSupported = "Cross Chain Refund Fail - Provider does not support the refund chain",
CrossChainRefundFailNotEnough 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 { export interface VaaKey {
@ -348,15 +357,24 @@ export function parseForwardFailureError(
bytes: Buffer bytes: Buffer
): string { ): string {
let idx = 4; let idx = 4;
console.log(bytes.length);
const amountOfFunds = ethers.BigNumber.from(
Uint8Array.prototype.subarray.call(bytes, idx, idx + 32)
);
idx += 32; idx += 32;
const amountOfFundsNeeded = ethers.BigNumber.from( if(bytes.length <= idx) {
Uint8Array.prototype.subarray.call(bytes, idx, idx + 32) return `Delivery Provider failed in performing forward`
); }
return `Not enough funds leftover for forward: Had ${amountOfFunds.toString()} wei and needed ${amountOfFundsNeeded.toString()} wei.` 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( export function parseOverrideInfoFromDeliveryEvent(