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 { ethers, Signer } from "ethers"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import type { ChainId } from "@certusone/wormhole-sdk"
|
||||||
|
import type { BigNumberish } from "ethers"
|
||||||
import {
|
import {
|
||||||
init,
|
init,
|
||||||
loadChains,
|
loadChains,
|
||||||
|
@ -7,6 +9,26 @@ import {
|
||||||
} from "../helpers/env"
|
} from "../helpers/env"
|
||||||
import { wait } from "../helpers/utils"
|
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"
|
const processName = "configureRelayProvider"
|
||||||
init()
|
init()
|
||||||
const chains = loadChains()
|
const chains = loadChains()
|
||||||
|
@ -45,33 +67,39 @@ async function configureChainsRelayProvider(chain: ChainInfo) {
|
||||||
await relayProvider.updateApprovedSender(address, approved).then(wait)
|
await relayProvider.updateApprovedSender(address, approved).then(wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO refactor to use the batch price update, probably
|
|
||||||
console.log("Set gas and native prices...")
|
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(
|
const targetChainPriceUpdate = config.pricingInfo.find(
|
||||||
(x: any) => x.chainId == chains[i].chainId
|
(x: any) => x.chainId == targetChain.chainId
|
||||||
)
|
)
|
||||||
if (!targetChainPriceUpdate) {
|
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.
|
//delivery addresses are not done by this script, but rather the register chains script.
|
||||||
await relayProvider
|
await relayProvider
|
||||||
.updateDeliverGasOverhead(
|
.updateDeliverGasOverhead(
|
||||||
chains[i].chainId,
|
targetChain.chainId,
|
||||||
targetChainPriceUpdate.deliverGasOverhead
|
targetChainPriceUpdate.deliverGasOverhead
|
||||||
)
|
)
|
||||||
.then(wait)
|
.then(wait)
|
||||||
await relayProvider
|
await relayProvider
|
||||||
.updatePrice(
|
.updateMaximumBudget(targetChain.chainId, targetChainPriceUpdate.maximumBudget)
|
||||||
chains[i].chainId,
|
|
||||||
targetChainPriceUpdate.updatePriceGas,
|
|
||||||
targetChainPriceUpdate.updatePriceNative
|
|
||||||
)
|
|
||||||
.then(wait)
|
.then(wait)
|
||||||
await relayProvider
|
await relayProvider
|
||||||
.updateMaximumBudget(chains[i].chainId, targetChainPriceUpdate.maximumBudget)
|
.updateAssetConversionBuffer(targetChain.chainId, 5, 100)
|
||||||
.then(wait)
|
.then(wait)
|
||||||
await relayProvider.updateAssetConversionBuffer(chains[i].chainId, 5, 100).then(wait)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("done with registrations on " + chain.chainId)
|
console.log("done with registrations on " + chain.chainId)
|
||||||
|
|
Loading…
Reference in New Issue