Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- [x] `IexecPoco2Delegate.sol`

### Features
- Migrate to Ethers v6:
- Deployment scripts (#187)
- Migrate scripts to TypeScript: (#184)
- `getFunctionSignatures.js`, `common-test-snapshot.js`, `test-storage.js`, `timelock.js`
- Migrated utility files to TypeScript : (#183)
Expand Down
36 changes: 17 additions & 19 deletions deploy/0_deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import hre, { ethers } from 'hardhat';
import {
AppRegistry__factory,
Expand Down Expand Up @@ -53,26 +53,26 @@ const CONFIG = require('../config/config.json');
*/
export default async function deploy() {
console.log('Deploying PoCo..');
const chainId = (await ethers.provider.getNetwork()).chainId;
const chainId = Number((await ethers.provider.getNetwork()).chainId);
const [owner] = await hre.ethers.getSigners();
const deploymentOptions = CONFIG.chains[chainId] || CONFIG.chains.default;
const salt = process.env.SALT || deploymentOptions.v5.salt || ethers.constants.HashZero;
const salt = process.env.SALT || deploymentOptions.v5.salt || ethers.ZeroHash;
const factoryDeployer = new FactoryDeployerHelper(owner, salt);
// Deploy RLC
const isTokenMode = deploymentOptions.asset == 'Token';
let rlcInstanceAddress = isTokenMode
? await getOrDeployRlc(deploymentOptions.token, owner) // token
: ethers.constants.AddressZero; // native
: ethers.ZeroAddress; // native
console.log(`RLC: ${rlcInstanceAddress}`);
// Deploy ERC1538 proxy contracts
const erc1538UpdateAddress = await factoryDeployer.deployWithFactory(
new ERC1538UpdateDelegate__factory(),
);
const transferOwnershipCall = await Ownable__factory.connect(
ethers.constants.AddressZero, // any is fine
ethers.ZeroAddress, // any is fine
owner, // any is fine
)
.populateTransaction.transferOwnership(owner.address)
.transferOwnership.populateTransaction(owner.address)
.then((tx) => tx.data)
.catch(() => {
throw new Error('Failed to prepare transferOwnership data');
Expand All @@ -83,7 +83,7 @@ export default async function deploy() {
transferOwnershipCall,
);
const erc1538: ERC1538Update = ERC1538Update__factory.connect(erc1538ProxyAddress, owner);
console.log(`IexecInstance found at address: ${erc1538.address}`);
console.log(`IexecInstance found at address: ${await erc1538.getAddress()}`);
// Deploy library & modules
const iexecLibOrdersAddress = await factoryDeployer.deployWithFactory(
new IexecLibOrders_v5__factory(),
Expand Down Expand Up @@ -122,7 +122,7 @@ export default async function deploy() {
);
const functionCount = await erc1538QueryInstance.totalFunctions();
console.log(`The deployed ERC1538Proxy now supports ${functionCount} functions:`);
for (let i = 0; i < functionCount.toNumber(); i++) {
for (let i = 0; i < Number(functionCount); i++) {
const [method, , contract] = await erc1538QueryInstance.functionByIndex(i);
console.log(`[${i}] ${contract} ${method}`);
}
Expand Down Expand Up @@ -155,21 +155,21 @@ export default async function deploy() {
// Check if registries have been initialized and set base URIs
if (!(await appRegistryInstance.initialized())) {
await appRegistryInstance
.initialize(deploymentOptions.v3.AppRegistry || ethers.constants.AddressZero)
.initialize(deploymentOptions.v3.AppRegistry || ethers.ZeroAddress)
.then((tx) => tx.wait());
await appRegistryInstance.setBaseURI(`${baseURIApp}/${chainId}/`).then((tx) => tx.wait());
}
if (!(await datasetRegistryInstance.initialized())) {
await datasetRegistryInstance
.initialize(deploymentOptions.v3.DatasetRegistry || ethers.constants.AddressZero)
.initialize(deploymentOptions.v3.DatasetRegistry || ethers.ZeroAddress)
.then((tx) => tx.wait());
await datasetRegistryInstance
.setBaseURI(`${baseURIDataset}/${chainId}/`)
.then((tx) => tx.wait());
}
if (!(await workerpoolRegistryInstance.initialized())) {
await workerpoolRegistryInstance
.initialize(deploymentOptions.v3.WorkerpoolRegistry || ethers.constants.AddressZero)
.initialize(deploymentOptions.v3.WorkerpoolRegistry || ethers.ZeroAddress)
.then((tx) => tx.wait());
await workerpoolRegistryInstance
.setBaseURI(`${baseURIWorkerpool}/${chainId}/`)
Expand All @@ -179,7 +179,7 @@ export default async function deploy() {
// Set main configuration
const iexecAccessorsInstance = IexecAccessors__factory.connect(erc1538ProxyAddress, owner);
const iexecInitialized =
(await iexecAccessorsInstance.eip712domain_separator()) != ethers.constants.HashZero;
(await iexecAccessorsInstance.eip712domain_separator()) != ethers.ZeroHash;
if (!iexecInitialized) {
await IexecMaintenanceDelegate__factory.connect(erc1538ProxyAddress, owner)
.configure(
Expand All @@ -190,14 +190,14 @@ export default async function deploy() {
appRegistryAddress,
datasetRegistryAddress,
workerpoolRegistryAddress,
ethers.constants.AddressZero,
ethers.ZeroAddress,
)
.then((tx) => tx.wait());
}
// Set categories
const catCountBefore = await iexecAccessorsInstance.countCategory();
const categories = CONFIG.categories as Category[];
for (let i = catCountBefore.toNumber(); i < categories.length; i++) {
for (let i = Number(catCountBefore); i < categories.length; i++) {
const category = categories[i];
await IexecCategoryManager__factory.connect(erc1538ProxyAddress, owner)
.createCategory(
Expand All @@ -209,7 +209,7 @@ export default async function deploy() {
}
const catCountAfter = await iexecAccessorsInstance.countCategory();
console.log(`countCategory is now: ${catCountAfter} (was ${catCountBefore})`);
for (let i = 0; i < catCountAfter.toNumber(); i++) {
for (let i = 0; i < Number(catCountAfter); i++) {
console.log(`Category ${i}: ${await iexecAccessorsInstance.viewCategory(i)}`);
}
}
Expand All @@ -220,8 +220,6 @@ async function getOrDeployRlc(token: string, owner: SignerWithAddress) {
: await new RLC__factory()
.connect(owner)
.deploy()
.then((contract) => {
contract.deployed();
return contract.address;
});
.then((contract) => contract.waitForDeployment())
.then((contract) => contract.getAddress());
}
44 changes: 23 additions & 21 deletions deploy/1_deploy-ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ export default async function deployEns() {
const datasetRegistryAddress = await iexecAccessorsInstance.datasetregistry();
const workerpoolRegistryAddress = await iexecAccessorsInstance.workerpoolregistry();
const ens = (await deploy(new ENSRegistry__factory(), owner, [])) as ENS;
const ensAddress = await ens.getAddress();
const resolver = (await deploy(new PublicResolver__factory(), owner, [
ens.address,
ensAddress,
])) as PublicResolver;
const resolverAddress = await resolver.getAddress();
const reverseRegistrar = (await deploy(new ReverseRegistrar__factory(), owner, [
ens.address,
resolver.address,
ensAddress,
resolverAddress,
])) as ReverseRegistrar;
const registrars: { [name: string]: FIFSRegistrar } = {};
// root registrar
await registerDomain('');
await registrars[''].register(labelhash('reverse'), owner.address).then((tx) => tx.wait());
await ens
.setSubnodeOwner(
ethers.utils.namehash('reverse'),
ethers.namehash('reverse'),
labelhash('addr'),
reverseRegistrar.address,
await reverseRegistrar.getAddress(),
)
.then((tx) => tx.wait());
await registerDomain('eth');
Expand All @@ -71,31 +73,31 @@ export default async function deployEns() {
/**
* Register domain on ENS.
*/
async function registerDomain(label: string, domain: string = '') {
async function registerDomain(label: string, domain: string = ''): Promise<FIFSRegistrar> {
const name = domain ? `${label}.${domain}` : `${label}`;
const labelHash = label ? labelhash(label) : ethers.constants.HashZero;
const nameHash = name ? ethers.utils.namehash(name) : ethers.constants.HashZero;
const labelHash = label ? labelhash(label) : ethers.ZeroHash;
const nameHash = name ? ethers.namehash(name) : ethers.ZeroHash;
const existingRegistrarAddress = await ens.owner(nameHash);
let registrar;
let registrarAddress;
if ((await ethers.provider.getCode(existingRegistrarAddress)) == '0x') {
registrar = (await deploy(
new FIFSRegistrar__factory(),
owner,
[ens.address, nameHash],
{ quiet: true },
)) as FIFSRegistrar;
registrar = (await deploy(new FIFSRegistrar__factory(), owner, [ensAddress, nameHash], {
quiet: true,
})) as FIFSRegistrar;
registrarAddress = await registrar.getAddress();
if (!!name) {
await registrars[domain]
.register(labelHash, registrar.address)
.register(labelHash, registrarAddress)
.then((tx) => tx.wait());
} else {
await ens.setOwner(nameHash, registrar.address).then((tx) => tx.wait());
await ens.setOwner(nameHash, registrarAddress).then((tx) => tx.wait());
}
} else {
registrar = FIFSRegistrar__factory.connect(existingRegistrarAddress, ethers.provider);
registrarAddress = await registrar.getAddress();
}
registrars[name] = registrar;
console.log(`FIFSRegistrar for domain ${name}: ${registrars[name].address}`);
console.log(`FIFSRegistrar for domain ${name}: ${registrarAddress}`);
return registrar;
}

Expand All @@ -105,7 +107,7 @@ export default async function deployEns() {
async function registerAddress(label: string, domain: string, address: string) {
const name = `${label}.${domain}`;
const labelHash = labelhash(label);
const nameHash = ethers.utils.namehash(name);
const nameHash = ethers.namehash(name);
// register as subdomain
await registrars[domain]
.connect(owner)
Expand All @@ -114,7 +116,7 @@ export default async function deployEns() {
// link to ens (resolver & addr)
await ens
.connect(owner)
.setResolver(nameHash, resolver.address)
.setResolver(nameHash, resolverAddress)
.then((tx) => tx.wait());
await resolver
.connect(owner)
Expand All @@ -127,7 +129,7 @@ export default async function deployEns() {
*/
async function setReverseName(contractAddress: string, name: string) {
await ENSIntegration__factory.connect(contractAddress, owner)
.setName(ens.address, name)
.setName(ensAddress, name)
.then((tx) => tx.wait());
}

Expand All @@ -136,6 +138,6 @@ export default async function deployEns() {
* See: https://docs.ens.domains/resolution/names#labelhash
*/
function labelhash(label: string) {
return ethers.utils.id(label.toLowerCase());
return ethers.id(label.toLowerCase());
}
}
Loading
Loading