contract status scripts
This commit is contained in:
parent
8b0a776946
commit
6cf8f489c2
|
@ -23,6 +23,7 @@
|
|||
"typechain": "bash ../sdk/scripts/make_ethers_types.sh",
|
||||
"flatten": "mkdir -p node_modules/@poanet/solidity-flattener/contracts && cp -r contracts/* node_modules/@poanet/solidity-flattener/contracts/ && poa-solidity-flattener",
|
||||
"deployAndConfigureTilt": "ENV=tilt bash ./ts-scripts/shell/deployConfigureTest.sh",
|
||||
"readContractsTestnet": "ENV=testnet bash ./ts-scripts/shell/readContractStatus.sh",
|
||||
"size": "forge build --sizes --force"
|
||||
},
|
||||
"author": "",
|
||||
|
|
|
@ -4,7 +4,6 @@ const processName = "checkNetworks"
|
|||
|
||||
init()
|
||||
const chains = loadChains()
|
||||
const privateKey = loadPrivateKey()
|
||||
|
||||
async function main() {
|
||||
console.log(`Env: ${env}`)
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
import { tryNativeToHexString } from "@certusone/wormhole-sdk"
|
||||
import { BigNumber } from "ethers"
|
||||
|
||||
import {
|
||||
init,
|
||||
loadChains,
|
||||
ChainInfo,
|
||||
getCoreRelayerAddress,
|
||||
getRelayProvider,
|
||||
getRelayProviderAddress,
|
||||
getProvider,
|
||||
writeOutputFiles,
|
||||
getCoreRelayer,
|
||||
} from "../helpers/env"
|
||||
import { wait } from "../helpers/utils"
|
||||
|
||||
const processName = "readRelayProviderContractState"
|
||||
init()
|
||||
const chains = loadChains()
|
||||
|
||||
async function run() {
|
||||
console.log("Start! " + processName)
|
||||
|
||||
const states: any = []
|
||||
|
||||
for (let i = 0; i < chains.length; i++) {
|
||||
const state = await readState(chains[i])
|
||||
if (state) {
|
||||
printState(state)
|
||||
states.push(state)
|
||||
}
|
||||
}
|
||||
|
||||
writeOutputFiles(states, processName)
|
||||
}
|
||||
|
||||
type CoreRelayerContractState = {
|
||||
chainId: number
|
||||
contractAddress: string
|
||||
defaultProvider: string
|
||||
registeredContracts: { chainId: number; contract: string }[]
|
||||
}
|
||||
|
||||
async function readState(chain: ChainInfo): Promise<CoreRelayerContractState | null> {
|
||||
console.log("Gathering core relayer contract status for chain " + chain.chainId)
|
||||
|
||||
try {
|
||||
const coreRelayer = getCoreRelayer(chain, getProvider(chain))
|
||||
const contractAddress = getCoreRelayerAddress(chain)
|
||||
const defaultProvider = await coreRelayer.getDefaultRelayProvider()
|
||||
const registeredContracts: { chainId: number; contract: string }[] = []
|
||||
|
||||
for (const chainInfo of chains) {
|
||||
registeredContracts.push({
|
||||
chainId: chainInfo.chainId,
|
||||
contract: (
|
||||
await coreRelayer.registeredCoreRelayerContract(chain.chainId)
|
||||
).toString(),
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
chainId: chain.chainId,
|
||||
contractAddress,
|
||||
defaultProvider,
|
||||
registeredContracts,
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.log("Failed to gather status for chain " + chain.chainId)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function printState(state: CoreRelayerContractState) {
|
||||
console.log("")
|
||||
console.log("CoreRelayer: ")
|
||||
printFixed("Chain ID: ", state.chainId.toString())
|
||||
printFixed("Contract Address:", state.contractAddress)
|
||||
printFixed("Default Provider:", state.defaultProvider)
|
||||
|
||||
console.log("")
|
||||
|
||||
printFixed("Registered CoreRelayers", "")
|
||||
state.registeredContracts.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.contract)
|
||||
})
|
||||
console.log("")
|
||||
}
|
||||
|
||||
function printFixed(title: string, content: string) {
|
||||
const length = 80
|
||||
const spaces = length - title.length - content.length
|
||||
let str = ""
|
||||
if (spaces > 0) {
|
||||
for (let i = 0; i < spaces; i++) {
|
||||
str = str + " "
|
||||
}
|
||||
}
|
||||
console.log(title + str + content)
|
||||
}
|
||||
|
||||
run().then(() => console.log("Done! " + processName))
|
|
@ -66,6 +66,16 @@ export function loadChains(): ChainInfo[] {
|
|||
return chains.chains
|
||||
}
|
||||
|
||||
export function getChain(chain: ChainId): ChainInfo {
|
||||
const chains = loadChains()
|
||||
const output = chains.find((x) => x.chainId == chain)
|
||||
if (!output) {
|
||||
throw Error("bad chain ID")
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
export function loadPrivateKey(): string {
|
||||
const privateKey = get_env_var("WALLET_KEY")
|
||||
if (!privateKey) {
|
||||
|
@ -175,6 +185,14 @@ export function getSigner(chain: ChainInfo): Signer {
|
|||
return signer
|
||||
}
|
||||
|
||||
export function getProvider(chain: ChainInfo): ethers.providers.StaticJsonRpcProvider {
|
||||
let provider = new ethers.providers.StaticJsonRpcProvider(
|
||||
loadChains().find((x: any) => x.chainId == chain.chainId)?.rpc || ""
|
||||
)
|
||||
|
||||
return provider
|
||||
}
|
||||
|
||||
export function getRelayProviderAddress(chain: ChainInfo): string {
|
||||
const thisChainsProvider = loadRelayProviders().find(
|
||||
(x: any) => x.chainId == chain.chainId
|
||||
|
@ -187,9 +205,15 @@ export function getRelayProviderAddress(chain: ChainInfo): string {
|
|||
return thisChainsProvider
|
||||
}
|
||||
|
||||
export function getRelayProvider(chain: ChainInfo): RelayProvider {
|
||||
export function getRelayProvider(
|
||||
chain: ChainInfo,
|
||||
provider?: ethers.providers.StaticJsonRpcProvider
|
||||
): RelayProvider {
|
||||
const thisChainsProvider = getRelayProviderAddress(chain)
|
||||
const contract = RelayProvider__factory.connect(thisChainsProvider, getSigner(chain))
|
||||
const contract = RelayProvider__factory.connect(
|
||||
thisChainsProvider,
|
||||
provider || getSigner(chain)
|
||||
)
|
||||
return contract
|
||||
}
|
||||
|
||||
|
@ -205,9 +229,15 @@ export function getCoreRelayerAddress(chain: ChainInfo): string {
|
|||
return thisChainsRelayer
|
||||
}
|
||||
|
||||
export function getCoreRelayer(chain: ChainInfo): CoreRelayer {
|
||||
export function getCoreRelayer(
|
||||
chain: ChainInfo,
|
||||
provider?: ethers.providers.StaticJsonRpcProvider
|
||||
): CoreRelayer {
|
||||
const thisChainsRelayer = getCoreRelayerAddress(chain)
|
||||
const contract = CoreRelayer__factory.connect(thisChainsRelayer, getSigner(chain))
|
||||
const contract = CoreRelayer__factory.connect(
|
||||
thisChainsRelayer,
|
||||
provider || getSigner(chain)
|
||||
)
|
||||
return contract
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
import { tryNativeToHexString } from "@certusone/wormhole-sdk"
|
||||
import { BigNumber } from "ethers"
|
||||
|
||||
import {
|
||||
init,
|
||||
loadChains,
|
||||
ChainInfo,
|
||||
getCoreRelayerAddress,
|
||||
getRelayProvider,
|
||||
getRelayProviderAddress,
|
||||
getProvider,
|
||||
writeOutputFiles,
|
||||
} from "../helpers/env"
|
||||
import { wait } from "../helpers/utils"
|
||||
|
||||
const processName = "readRelayProviderContractState"
|
||||
init()
|
||||
const chains = loadChains()
|
||||
|
||||
async function run() {
|
||||
console.log("Start! " + processName)
|
||||
|
||||
const states: any = []
|
||||
|
||||
for (let i = 0; i < chains.length; i++) {
|
||||
const state = await readState(chains[i])
|
||||
if (state) {
|
||||
printState(state)
|
||||
states.push(state)
|
||||
}
|
||||
}
|
||||
|
||||
writeOutputFiles(states, processName)
|
||||
}
|
||||
|
||||
type RelayProviderContractState = {
|
||||
chainId: number
|
||||
contractAddress: string
|
||||
rewardAddress: string
|
||||
providerAddresses: { chainId: number; providerAddress: string }[]
|
||||
deliveryOverheads: { chainId: number; deliveryOverhead: BigNumber }[]
|
||||
maximumBudgets: { chainId: number; maximumBudget: BigNumber }[]
|
||||
gasPrices: { chainId: number; gasPrice: BigNumber }[]
|
||||
usdPrices: { chainId: number; usdPrice: BigNumber }[]
|
||||
assetConversionBuffers: {
|
||||
chainId: number
|
||||
tolerance: number
|
||||
toleranceDenominator: number
|
||||
}[]
|
||||
owner: string
|
||||
}
|
||||
|
||||
async function readState(chain: ChainInfo): Promise<RelayProviderContractState | null> {
|
||||
console.log("Gathering relay provider contract status for chain " + chain.chainId)
|
||||
|
||||
try {
|
||||
const relayProvider = getRelayProvider(chain, getProvider(chain))
|
||||
const contractAddress = getRelayProviderAddress(chain)
|
||||
const rewardAddress = await relayProvider.getRewardAddress()
|
||||
const providerAddresses: { chainId: number; providerAddress: string }[] = []
|
||||
const deliveryOverheads: { chainId: number; deliveryOverhead: BigNumber }[] = []
|
||||
const maximumBudgets: { chainId: number; maximumBudget: BigNumber }[] = []
|
||||
const gasPrices: { chainId: number; gasPrice: BigNumber }[] = []
|
||||
const usdPrices: { chainId: number; usdPrice: BigNumber }[] = []
|
||||
const assetConversionBuffers: {
|
||||
chainId: number
|
||||
tolerance: number
|
||||
toleranceDenominator: number
|
||||
}[] = []
|
||||
const owner: string = await relayProvider.owner()
|
||||
|
||||
for (const chainInfo of chains) {
|
||||
providerAddresses.push({
|
||||
chainId: chainInfo.chainId,
|
||||
providerAddress: (
|
||||
await relayProvider.getDeliveryAddress(chainInfo.chainId)
|
||||
).toString(),
|
||||
})
|
||||
deliveryOverheads.push({
|
||||
chainId: chainInfo.chainId,
|
||||
deliveryOverhead: await relayProvider.quoteDeliveryOverhead(chainInfo.chainId),
|
||||
})
|
||||
maximumBudgets.push({
|
||||
chainId: chainInfo.chainId,
|
||||
maximumBudget: await relayProvider.quoteMaximumBudget(chainInfo.chainId),
|
||||
})
|
||||
gasPrices.push({
|
||||
chainId: chainInfo.chainId,
|
||||
gasPrice: await relayProvider.quoteGasPrice(chainInfo.chainId),
|
||||
})
|
||||
usdPrices.push({
|
||||
chainId: chainInfo.chainId,
|
||||
usdPrice: await relayProvider.quoteAssetPrice(chainInfo.chainId),
|
||||
})
|
||||
const buffer = await relayProvider.getAssetConversionBuffer(chainInfo.chainId)
|
||||
assetConversionBuffers.push({
|
||||
chainId: chainInfo.chainId,
|
||||
tolerance: buffer.tolerance,
|
||||
toleranceDenominator: buffer.toleranceDenominator,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
chainId: chain.chainId,
|
||||
contractAddress,
|
||||
rewardAddress,
|
||||
providerAddresses,
|
||||
deliveryOverheads,
|
||||
maximumBudgets,
|
||||
gasPrices,
|
||||
usdPrices,
|
||||
assetConversionBuffers,
|
||||
owner,
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.log("Failed to gather status for chain " + chain.chainId)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function printState(state: RelayProviderContractState) {
|
||||
console.log("")
|
||||
console.log("RelayProvider: ")
|
||||
printFixed("Chain ID: ", state.chainId.toString())
|
||||
printFixed("Contract Address:", state.contractAddress)
|
||||
printFixed("Owner Address:", state.owner)
|
||||
printFixed("Reward Address:", state.rewardAddress)
|
||||
|
||||
console.log("")
|
||||
|
||||
printFixed("Registered Providers", "")
|
||||
state.providerAddresses.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.providerAddress)
|
||||
})
|
||||
console.log("")
|
||||
|
||||
printFixed("Delivery Overheads", "")
|
||||
state.deliveryOverheads.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.deliveryOverhead.toString())
|
||||
})
|
||||
console.log("")
|
||||
|
||||
printFixed("Gas Prices", "")
|
||||
state.gasPrices.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.gasPrice.toString())
|
||||
})
|
||||
console.log("")
|
||||
|
||||
printFixed("USD Prices", "")
|
||||
state.usdPrices.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.usdPrice.toString())
|
||||
})
|
||||
console.log("")
|
||||
|
||||
printFixed("Maximum Budgets", "")
|
||||
state.maximumBudgets.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, x.maximumBudget.toString())
|
||||
})
|
||||
console.log("")
|
||||
|
||||
printFixed("Asset Conversion Buffers", "")
|
||||
state.assetConversionBuffers.forEach((x) => {
|
||||
printFixed(" Chain: " + x.chainId, "")
|
||||
printFixed(" Tolerance: ", x.tolerance.toString())
|
||||
printFixed(" Denominator: ", x.toleranceDenominator.toString())
|
||||
})
|
||||
console.log("")
|
||||
}
|
||||
|
||||
function printFixed(title: string, content: string) {
|
||||
const length = 80
|
||||
const spaces = length - title.length - content.length
|
||||
let str = ""
|
||||
if (spaces > 0) {
|
||||
for (let i = 0; i < spaces; i++) {
|
||||
str = str + " "
|
||||
}
|
||||
}
|
||||
console.log(title + str + content)
|
||||
}
|
||||
|
||||
run().then(() => console.log("Done! " + processName))
|
|
@ -0,0 +1 @@
|
|||
ts-node ./ts-scripts/relayProvider/readRelayProviderContractState.ts
|
Loading…
Reference in New Issue