Updates prices in `RelayProvider` in batch. (#122)
This commit is contained in:
parent
9e282508f7
commit
2ed875bef7
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue