From 2ed875bef7f9113a96cbe4999cfb9d168e6fcd6f Mon Sep 17 00:00:00 2001 From: scnale Date: Fri, 24 Mar 2023 15:04:02 -0300 Subject: [PATCH] Updates prices in `RelayProvider` in batch. (#122) --- ethereum/ts-scripts/helpers/env.ts | 2 +- .../relayProvider/configureRelayProvider.ts | 52 ++++++++++++++----- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/ethereum/ts-scripts/helpers/env.ts b/ethereum/ts-scripts/helpers/env.ts index 7ba4897..93283be 100644 --- a/ethereum/ts-scripts/helpers/env.ts +++ b/ethereum/ts-scripts/helpers/env.ts @@ -1,4 +1,4 @@ -import { ChainId, Network } from "@certusone/wormhole-sdk" +import type { ChainId, Network } from "@certusone/wormhole-sdk" import { ethers, Signer } from "ethers" import fs from "fs" import { diff --git a/ethereum/ts-scripts/relayProvider/configureRelayProvider.ts b/ethereum/ts-scripts/relayProvider/configureRelayProvider.ts index 51d3376..2963b5c 100644 --- a/ethereum/ts-scripts/relayProvider/configureRelayProvider.ts +++ b/ethereum/ts-scripts/relayProvider/configureRelayProvider.ts @@ -1,3 +1,5 @@ +import type { ChainId } from "@certusone/wormhole-sdk" +import type { BigNumberish } from "ethers" import { init, loadChains, @@ -7,6 +9,26 @@ import { } from "../helpers/env" import { wait } from "../helpers/utils" +/** + * Meant for `config.pricingInfo` + */ +interface PricingInfo { + chainId: ChainId + deliverGasOverhead: BigNumberish + updatePriceGas: BigNumberish + updatePriceNative: BigNumberish + maximumBudget: BigNumberish +} + +/** + * Must match `RelayProviderStructs.UpdatePrice` + */ +interface UpdatePrice { + chainId: ChainId + gasPrice: BigNumberish + nativeCurrencyPrice: BigNumberish +} + const processName = "configureRelayProvider" init() const chains = loadChains() @@ -45,33 +67,39 @@ async function configureChainsRelayProvider(chain: ChainInfo) { await relayProvider.updateApprovedSender(address, approved).then(wait) } - //TODO refactor to use the batch price update, probably console.log("Set gas and native prices...") - for (let i = 0; i < chains.length; i++) { + + // Batch update prices + const pricingUpdates: UpdatePrice[] = (config.pricingInfo as PricingInfo[]).map((info) => { + return { + chainId: info.chainId, + gasPrice: info.updatePriceGas, + nativeCurrencyPrice: info.updatePriceNative, + } + }) + await relayProvider.updatePrices(pricingUpdates).then(wait) + + // Set the rest of the relay provider configuration + for (const targetChain of chains) { const targetChainPriceUpdate = config.pricingInfo.find( - (x: any) => x.chainId == chains[i].chainId + (x: any) => x.chainId == targetChain.chainId ) if (!targetChainPriceUpdate) { - throw new Error("Failed to find pricingInfo for chain " + chains[i].chainId) + throw new Error("Failed to find pricingInfo for chain " + targetChain.chainId) } //delivery addresses are not done by this script, but rather the register chains script. await relayProvider .updateDeliverGasOverhead( - chains[i].chainId, + targetChain.chainId, targetChainPriceUpdate.deliverGasOverhead ) .then(wait) await relayProvider - .updatePrice( - chains[i].chainId, - targetChainPriceUpdate.updatePriceGas, - targetChainPriceUpdate.updatePriceNative - ) + .updateMaximumBudget(targetChain.chainId, targetChainPriceUpdate.maximumBudget) .then(wait) await relayProvider - .updateMaximumBudget(chains[i].chainId, targetChainPriceUpdate.maximumBudget) + .updateAssetConversionBuffer(targetChain.chainId, 5, 100) .then(wait) - await relayProvider.updateAssetConversionBuffer(chains[i].chainId, 5, 100).then(wait) } console.log("done with registrations on " + chain.chainId)