-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hardhat tasks to lint factories and registrars
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { task } from "hardhat/config"; | ||
import { chainIds, contractAddress, supportedNetworkParams, zeroAddr } from "../scripts/params"; | ||
|
||
type Args = { | ||
chainId: string; | ||
selector: string; | ||
factory: string; | ||
}; | ||
|
||
task("set-factory") | ||
.setDescription("Lints the factories to the Registrar") | ||
.setAction(async function (taskArgs, hre) { | ||
const chainId = await hre.getChainId(); | ||
|
||
const Registrar = await hre.ethers.getContractFactory("Registrar", { | ||
libraries: { | ||
SourceNftLib: contractAddress(chainId, "SourceNftLib"), | ||
}, | ||
}); | ||
const registrarAddr = contractAddress(chainId, "Registrar"); | ||
if (registrarAddr.length === 0) { | ||
throw `No 'Registrar' found in ${chainId}`; | ||
} | ||
const registrar = Registrar.attach(registrarAddr); | ||
console.log(`Registrar '${registrarAddr}' in ${chainId}`); | ||
|
||
const destFactories = chainIds(chainId).reduce<Args[]>((destFactories, destChainId) => { | ||
const addr = contractAddress(destChainId, "LinkedFactory"); | ||
if (addr.length == 0) { | ||
return destFactories; | ||
} | ||
const destArg: Args = { | ||
chainId: destChainId, | ||
selector: supportedNetworkParams[destChainId].selector, | ||
factory: addr, | ||
}; | ||
destFactories.push(destArg); | ||
return destFactories; | ||
}, []); | ||
|
||
if (destFactories.length === 0) { | ||
console.log(`No factories to set`); | ||
return; | ||
} | ||
console.log(`There are ${destFactories.length} factories to set`); | ||
for (const factory of destFactories) { | ||
const networkParams = await registrar.functions["destNetworks"](factory.selector); | ||
if (networkParams.factory !== zeroAddr) { | ||
console.log(`Skipping ${factory.chainId} chain's factory as set`); | ||
continue; | ||
} | ||
const tx = await registrar.functions["setFactory(uint64,address)"](factory.selector, factory.factory); | ||
console.log(`Setting factory for ${factory.chainId}, deploying ${tx.hash}...`); | ||
await tx.wait(); | ||
console.log(`Setting factory for ${factory.chainId} completed!`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { task } from "hardhat/config"; | ||
import { chainIds, contractAddress, supportedNetworkParams, zeroAddr } from "../scripts/params"; | ||
|
||
type Args = { | ||
chainId: string; | ||
selector: string; | ||
registrar: string; | ||
}; | ||
|
||
task("set-registrar") | ||
.setDescription("Lints the registrar to the LinkedFactory") | ||
.setAction(async function (taskArgs, hre) { | ||
const chainId = await hre.getChainId(); | ||
|
||
const LinkedFactory = await hre.ethers.getContractFactory("LinkedFactory", {}); | ||
const linkedFactoryAddr = contractAddress(chainId, "LinkedFactory"); | ||
if (linkedFactoryAddr.length === 0) { | ||
throw `No 'LinkedFactory' found in ${chainId}`; | ||
} | ||
const linkedFactory = LinkedFactory.attach(linkedFactoryAddr); | ||
console.log(`LinkedFactory '${linkedFactoryAddr}' in ${chainId}`); | ||
|
||
const destRegistrars = chainIds(chainId).reduce<Args[]>((destRegistrars, destChainId) => { | ||
const addr = contractAddress(destChainId, "Registrar"); | ||
if (addr.length == 0) { | ||
return destRegistrars; | ||
} | ||
const destArg: Args = { | ||
chainId: destChainId, | ||
selector: supportedNetworkParams[destChainId].selector, | ||
registrar: addr, | ||
}; | ||
destRegistrars.push(destArg); | ||
return destRegistrars; | ||
}, []); | ||
|
||
if (destRegistrars.length === 0) { | ||
console.log(`No registrars to set`); | ||
return; | ||
} | ||
console.log(`There are ${destRegistrars.length} registrars to set`); | ||
for (const registrar of destRegistrars) { | ||
const networkParams = await linkedFactory.functions["destNetworks"](registrar.selector); | ||
if (networkParams.registrar !== zeroAddr) { | ||
console.log(`Skipping ${registrar.chainId} chain's factory as set`); | ||
continue; | ||
} | ||
const tx = await linkedFactory.functions["setRegistrar(uint64,address)"](registrar.selector, registrar.registrar); | ||
console.log(`Setting registrar for ${registrar.chainId}, deploying ${tx.hash}...`); | ||
await tx.wait(); | ||
console.log(`Setting registrar for ${registrar.chainId} completed!`); | ||
} | ||
}); |