From fd9d7d7dace86b295e960de50e4bd2296eda329e Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Tue, 4 Feb 2025 10:03:53 +0100 Subject: [PATCH 1/5] Replace web3 with ethers in module upgrade scripts --- scripts/module_upgrade.js | 23 +++++++++------------ scripts/upgrades/5_0_0-to-5_1_0.js | 23 +++++++++------------ scripts/upgrades/5_1_0-to-5_2_0.js | 33 +++++++++++++----------------- 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/scripts/module_upgrade.js b/scripts/module_upgrade.js index e580e7d3d..120dfd0a9 100644 --- a/scripts/module_upgrade.js +++ b/scripts/module_upgrade.js @@ -1,14 +1,12 @@ // SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -const assert = require('assert'); const CONFIG = require('../config/config.json'); +const { ethers } = require('ethers'); var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); -// TODO replace `web3` by `ethers`. - /***************************************************************************** * Configuration * *****************************************************************************/ @@ -69,8 +67,8 @@ async function factoryDeployer(contract, options = {}) { contract.bytecode, ); const argsCode = constructorABI - ? web3.eth.abi - .encodeParameters( + ? ethers.utils.defaultAbiCoder + .encode( constructorABI.inputs.map((e) => e.type), options.args || [], ) @@ -84,7 +82,7 @@ async function factoryDeployer(contract, options = {}) { ? await factory.predictAddressWithCall(code, salt, options.call) : await factory.predictAddress(code, salt); - if ((await web3.eth.getCode(contract.address)) == '0x') { + if ((await ethers.provider.getCode(contract.address)) == '0x') { console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); options.call ? await factory.createContractAndCall(code, salt, options.call) @@ -101,15 +99,14 @@ async function factoryDeployer(contract, options = {}) { *****************************************************************************/ module.exports = async (callback) => { try { - console.log('# web3 version:', web3.version); - const chainid = await web3.eth.net.getId(); - const chaintype = await web3.eth.net.getNetworkType(); - console.log('Chainid is:', chainid); - console.log('Chaintype is:', chaintype); + const network = await ethers.provider.getNetwork(); + console.log('# ethers version:', ethers.version); + console.log('Chainid is:', network.chainId); + console.log('Network name is:', network.name); // Load config - const deploymentOptions = CONFIG.chains[chainid] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || web3.utils.randomHex(32) }; + const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; + const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; // Load core const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); diff --git a/scripts/upgrades/5_0_0-to-5_1_0.js b/scripts/upgrades/5_0_0-to-5_1_0.js index db66306b8..3ab4b4ed2 100644 --- a/scripts/upgrades/5_0_0-to-5_1_0.js +++ b/scripts/upgrades/5_0_0-to-5_1_0.js @@ -1,14 +1,12 @@ // SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -const assert = require('assert'); const CONFIG = require('../../config/config.json'); +const { ethers } = require('ethers'); var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); -// TODO replace `web3` by `ethers`. - /***************************************************************************** * Configuration * *****************************************************************************/ @@ -71,8 +69,8 @@ async function factoryDeployer(contract, options = {}) { contract.bytecode, ); const argsCode = constructorABI - ? web3.eth.abi - .encodeParameters( + ? ethers.utils.defaultAbiCoder + .encode( constructorABI.inputs.map((e) => e.type), options.args || [], ) @@ -86,7 +84,7 @@ async function factoryDeployer(contract, options = {}) { ? await factory.predictAddressWithCall(code, salt, options.call) : await factory.predictAddress(code, salt); - if ((await web3.eth.getCode(contract.address)) == '0x') { + if ((await ethers.provider.getCode(contract.address)) == '0x') { console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); options.call ? await factory.createContractAndCall(code, salt, options.call) @@ -103,15 +101,14 @@ async function factoryDeployer(contract, options = {}) { *****************************************************************************/ module.exports = async (callback) => { try { - console.log('# web3 version:', web3.version); - const chainid = await web3.eth.net.getId(); - const chaintype = await web3.eth.net.getNetworkType(); - console.log('Chainid is:', chainid); - console.log('Chaintype is:', chaintype); + const network = await ethers.provider.getNetwork(); + console.log('# ethers version:', ethers.version); + console.log('Chainid is:', network.chainId); + console.log('Network name is:', network.name); // Load config - const deploymentOptions = CONFIG.chains[chainid] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || web3.utils.randomHex(32) }; + const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; + const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; // Load core const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); diff --git a/scripts/upgrades/5_1_0-to-5_2_0.js b/scripts/upgrades/5_1_0-to-5_2_0.js index 74942d884..a43b7c794 100644 --- a/scripts/upgrades/5_1_0-to-5_2_0.js +++ b/scripts/upgrades/5_1_0-to-5_2_0.js @@ -1,16 +1,12 @@ // SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -const assert = require('assert'); const CONFIG = require('../../config/config.json'); +const { ethers } = require('ethers'); var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); -// TODO replace `web3` by `ethers`. - -const { ethers } = require('ethers'); - /***************************************************************************** * Configuration * *****************************************************************************/ @@ -65,8 +61,8 @@ async function factoryDeployer(contract, options = {}) { contract.bytecode, ); const argsCode = constructorABI - ? web3.eth.abi - .encodeParameters( + ? ethers.utils.defaultAbiCoder + .encode( constructorABI.inputs.map((e) => e.type), options.args || [], ) @@ -80,7 +76,7 @@ async function factoryDeployer(contract, options = {}) { ? await factory.predictAddressWithCall(code, salt, options.call) : await factory.predictAddress(code, salt); - if ((await web3.eth.getCode(contract.address)) == '0x') { + if ((await ethers.provider.getCode(contract.address)) == '0x') { console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); options.call ? await factory.createContractAndCall(code, salt, options.call) @@ -97,15 +93,14 @@ async function factoryDeployer(contract, options = {}) { *****************************************************************************/ module.exports = async (callback) => { try { - console.log('# web3 version:', web3.version); - const chainid = await web3.eth.net.getId(); - const chaintype = await web3.eth.net.getNetworkType(); - console.log('Chainid is:', chainid); - console.log('Chaintype is:', chaintype); + const network = await ethers.provider.getNetwork(); + console.log('# ethers version:', ethers.version); + console.log('Chainid is:', network.chainId); + console.log('Network name is:', network.name); // Load config - const deploymentOptions = CONFIG.chains[chainid] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || web3.utils.randomHex(32) }; + const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; + const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; // Load core const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); @@ -171,9 +166,9 @@ module.exports = async (callback) => { // )) // .forEach((details, i) => console.log(`[${i}] ${details.delegate} ${details.signature}`)); - const accounts = await web3.eth.getAccounts(); + const accounts = await ethers.provider.listAccounts(); console.log('Before:'); - console.log('- ETH balance: ', await web3.eth.getBalance(iexec.address)); + console.log('- ETH balance: ', await ethers.provider.getBalance(iexec.address)); console.log('- RLC balance: ', (await rlc.balanceOf(iexec.address)).toString()); console.log('- Total supply: ', (await iexec.totalSupply()).toString()); @@ -278,7 +273,7 @@ module.exports = async (callback) => { await iexec.manageWorkerpoolOrder({ order: workerpoolorder, operation: 0, sign: '0x' }); await iexec.manageRequestOrder({ order: requestorder, operation: 0, sign: '0x' }); - // const tx = await web3.eth.sendTransaction({ from: accounts[0], to: iexec.address, value: "100000000000000000" }); + // const tx = await ethers.provider.getSigner(accounts[0]).sendTransaction({ to: iexec.address, value: ethers.utils.parseEther("0.1") }); // const tx = await iexec.depositEth({ value: "10000000000000000" }) // const tx = await iexec.withdrawEth(126492) // const tx = await iexec.requestToken(10, { value: "10000000000000000" }) @@ -300,7 +295,7 @@ module.exports = async (callback) => { }); console.log('After:'); - console.log('- ETH balance: ', await web3.eth.getBalance(iexec.address)); + console.log('- ETH balance: ', await ethers.provider.getBalance(iexec.address)); console.log('- RLC balance: ', (await rlc.balanceOf(iexec.address)).toString()); console.log('- Total supply: ', (await iexec.totalSupply()).toString()); } From 1b9169af83bc5f54ae1f5e290f66a75872a8313b Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Thu, 6 Feb 2025 14:48:42 +0100 Subject: [PATCH 2/5] Remove unused ENS tools module --- utils/ens-tools.js | 49 ---------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 utils/ens-tools.js diff --git a/utils/ens-tools.js b/utils/ens-tools.js deleted file mode 100644 index b2e5c5dbc..000000000 --- a/utils/ens-tools.js +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -var ENSRegistry = artifacts.require('@ensdomains/ens-contracts/contracts/registry/ENSRegistry'); -var PublicResolver = artifacts.require( - '@ensdomains/ens-contracts/contracts/resolvers/PublicResolver', -); - -// TODO remove. - -module.exports = { - labelhash: function (label) { - return web3.utils.keccak256(label.toLowerCase()); - }, - - compose: function (labelHash, rootHash) { - return web3.utils.keccak256( - web3.eth.abi.encodeParameters(['bytes32', 'bytes32'], [rootHash, labelHash]), - ); - }, - - namehash: function (domain) { - return domain - .split('.') - .reverse() - .reduce( - (hash, label) => this.compose(this.labelhash(label), hash), - '0x0000000000000000000000000000000000000000000000000000000000000000', - ); - }, - - resolve: async function (name) { - node = this.namehash(name); - registry = await ENSRegistry.deployed(); - resolveraddr = await registry.resolver(node); - resolver = await PublicResolver.at(resolveraddr); - addr = await resolver.addr(node); - return addr; - }, - - lookup: async function (addr) { - node = this.namehash(`${addr.substring(2)}.addr.reverse`); - registry = await ENSRegistry.deployed(); - resolveraddr = await registry.resolver(node); - resolver = await PublicResolver.at(resolveraddr); - name = await resolver.name(node); - return name; - }, -}; From 73846bfe0d1ee8745e68de1fbfcb146f783a7019 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Thu, 6 Feb 2025 15:16:23 +0100 Subject: [PATCH 3/5] Refactor odb-tools.js: remove unused functions and update copyright year --- utils/odb-tools.js | 254 +-------------------------------------------- 1 file changed, 1 insertion(+), 253 deletions(-) diff --git a/utils/odb-tools.js b/utils/odb-tools.js index dc638e3fb..80423553a 100644 --- a/utils/odb-tools.js +++ b/utils/odb-tools.js @@ -1,12 +1,8 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH +// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -const constants = require('./constants'); const ethers = require('ethers'); -// TODO remove except `signStruct` and `hashStruct` -// both used in createOrders.ts. - const TYPES = { EIP712Domain: [ { type: 'string', name: 'name' }, @@ -81,16 +77,6 @@ const TYPES = { ], }; -function eth_sign(hash, wallet) { - return new Promise((resolve, reject) => { - if (wallet.sign) { - resolve(wallet.sign(hash).signature); - } else { - web3.eth.sign(hash, wallet.address).then(resolve).catch(reject); - } - }); -} - function buildTypes(primaryType) { const OPERATION = 'Operation'; const types = { @@ -132,13 +118,6 @@ function eth_signTypedData(primaryType, message, domain, wallet) { }); } -function signMessage(obj, hash, wallet) { - return eth_sign(hash, wallet).then((sign) => { - obj.sign = sign; - return obj; - }); -} - function signStruct(primaryType, message, domain, wallet) { return eth_signTypedData(primaryType, message, domain, wallet).then((sign) => { message.sign = sign; @@ -160,243 +139,12 @@ function hashStruct(primaryType, message, domain) { return ethers.utils._TypedDataEncoder.hash(typedDataDomain, types, message); } -/* NOT EIP712 compliant */ -function hashAuthorization(authorization) { - return web3.utils.soliditySha3( - { t: 'address', v: authorization.worker }, - { t: 'bytes32', v: authorization.taskid }, - { t: 'address', v: authorization.enclave }, - ); -} - -/* NOT EIP712 compliant */ -function hashContribution(result) { - return web3.utils.soliditySha3( - { t: 'bytes32', v: result.hash }, - { t: 'bytes32', v: result.seal }, - ); -} - -function signAuthorization(obj, wallet) { - return signMessage(obj, hashAuthorization(obj), wallet); -} - -function signContribution(obj, wallet) { - return signMessage(obj, hashContribution(obj), wallet); -} - -function hashByteResult(taskid, byteresult) { - return { - digest: byteresult, - hash: web3.utils.soliditySha3({ t: 'bytes32', v: taskid }, { t: 'bytes32', v: byteresult }), - }; -} - -function sealByteResult(taskid, byteresult, address) { - return { - digest: byteresult, - hash: web3.utils.soliditySha3({ t: 'bytes32', v: taskid }, { t: 'bytes32', v: byteresult }), - seal: web3.utils.soliditySha3( - { t: 'address', v: address }, - { t: 'bytes32', v: taskid }, - { t: 'bytes32', v: byteresult }, - ), - }; -} - -function hashResult(taskid, result) { - return hashByteResult(taskid, web3.utils.soliditySha3({ t: 'string', v: result })); -} - -function sealResult(taskid, result, address) { - return sealByteResult(taskid, web3.utils.soliditySha3({ t: 'string', v: result }), address); -} - -async function requestToDeal(IexecClerk, requestHash) { - let idx = 0; - let dealids = []; - while (true) { - let dealid = web3.utils.soliditySha3( - { t: 'bytes32', v: requestHash }, - { t: 'uint256', v: idx }, - ); - let deal = await IexecClerk.viewDeal(dealid); - if (deal.botSize == 0) { - return dealids; - } else { - dealids.push(dealid); - idx += deal.botSize; - } - } -} - -/***************************************************************************** - * MOCK AGENT * - *****************************************************************************/ -class iExecAgent { - constructor(iexec, account) { - this.iexec = iexec; - this.wallet = account ? { address: account } : web3.eth.accounts.create(); - this.address = this.wallet.address; - } - async domain() { - return await this.iexec.domain(); - } - async signMessage(obj, hash) { - return signMessage(obj, hash, this.wallet); - } - async signAppOrder(struct) { - return signStruct('AppOrder', struct, await this.domain(), this.wallet); - } - async signDatasetOrder(struct) { - return signStruct('DatasetOrder', struct, await this.domain(), this.wallet); - } - async signWorkerpoolOrder(struct) { - return signStruct('WorkerpoolOrder', struct, await this.domain(), this.wallet); - } - async signRequestOrder(struct) { - return signStruct('RequestOrder', struct, await this.domain(), this.wallet); - } - async signAppOrderOperation(struct) { - return signStruct('AppOrderOperation', struct, await this.domain(), this.wallet); - } - async signDatasetOrderOperation(struct) { - return signStruct('DatasetOrderOperation', struct, await this.domain(), this.wallet); - } - async signWorkerpoolOrderOperation(struct) { - return signStruct('WorkerpoolOrderOperation', struct, await this.domain(), this.wallet); - } - async signRequestOrderOperation(struct) { - return signStruct('RequestOrderOperation', struct, await this.domain(), this.wallet); - } - - async viewAccount() { - return Object.extract(await this.iexec.viewAccount(this.wallet.address), [ - 'stake', - 'locked', - ]).map((bn) => Number(bn)); - } - async viewScore() { - return Number(await this.iexec.viewScore(this.wallet.address)); - } -} -/***************************************************************************** - * MOCK BROKER * - *****************************************************************************/ -class Broker extends iExecAgent { - constructor(iexec) { - super(iexec); - } - - async initialize() { - await this.iexec.setTeeBroker(this.wallet.address); - } - - async signAuthorization(preauth) { - const task = await this.iexec.viewTask(preauth.taskid); - const deal = await this.iexec.viewDeal(task.dealid); - const signer = web3.eth.accounts.recover(hashAuthorization(preauth), preauth.sign); - if (signer == deal.workerpool.owner) { - const enclaveWallet = web3.eth.accounts.create(); - const auth = await signAuthorization( - { ...preauth, enclave: enclaveWallet.address }, - this.wallet, - ); - return [auth, enclaveWallet]; - } else { - return [null, null]; - } - } -} -/***************************************************************************** - * MOCK SCHEDULER * - *****************************************************************************/ -class Scheduler extends iExecAgent { - constructor(iexec, wallet) { - super(iexec, wallet); - } - - async signPreAuthorization(taskid, worker) { - return await signAuthorization( - { taskid, worker, enclave: constants.NULL.ADDRESS }, - this.wallet, - ); - } -} -/***************************************************************************** - * MOCK WORKER * - *****************************************************************************/ -class Worker extends iExecAgent { - constructor(iexec, wallet) { - super(iexec, wallet); - } - - async run(auth, enclaveWallet, result, callback) { - const contribution = sealByteResult( - auth.taskid, - callback - ? web3.utils.soliditySha3({ t: 'bytes', v: callback }) - : web3.utils.soliditySha3({ t: 'string', v: result }), - this.wallet.address, - ); - if (auth.enclave == constants.NULL.ADDRESS) { - // Classic - contribution.sign = constants.NULL.SIGNATURE; - } // TEE - else { - await signContribution(contribution, enclaveWallet); - } - return contribution; - } -} - /***************************************************************************** * MODULE * *****************************************************************************/ module.exports = { - /* mocks */ - iExecAgent, - Scheduler, - Broker, - Worker, - /* utils */ utils: { signStruct, hashStruct, - signMessage, - hashAuthorization, - hashContribution, - signAuthorization, - signContribution, - hashByteResult, - sealByteResult, - hashResult, - sealResult, - hashConsensus: hashResult, - hashAppOrder: function (domain, struct) { - return hashStruct('AppOrder', struct, domain); - }, - hashDatasetOrder: function (domain, struct) { - return hashStruct('DatasetOrder', struct, domain); - }, - hashWorkerpoolOrder: function (domain, struct) { - return hashStruct('WorkerpoolOrder', struct, domain); - }, - hashRequestOrder: function (domain, struct) { - return hashStruct('RequestOrder', struct, domain); - }, - hashAppOrderOperation: function (domain, struct) { - return hashStruct('AppOrderOperation', struct, domain); - }, - hashDatasetOrderOperation: function (domain, struct) { - return hashStruct('DatasetOrderOperation', struct, domain); - }, - hashWorkerpoolOrderOperation: function (domain, struct) { - return hashStruct('WorkerpoolOrderOperation', struct, domain); - }, - hashRequestOrderOperation: function (domain, struct) { - return hashStruct('RequestOrderOperation', struct, domain); - }, - requestToDeal, }, }; From 492a95c55b2eef3c91f1cbf5eed3e670ef48fbc2 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Thu, 6 Feb 2025 15:44:31 +0100 Subject: [PATCH 4/5] Update Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d54a00803..6c2ced08f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - [x] `IexecPoco2Delegate.sol` ### Features -- Purge Truffle leftovers (#180, #181) +- Purge Truffle leftovers (#180, #181, #182) - Sunset Jenkins pipeline (#178) - Re-use variable in `IexecPoco2Delegate` in `contribute(...)` function. (#168) - Remove unnecessary back and forth transfers in `IexecPoco2Delegate` happening during `claim(..)`. (#167) From 451e0260745e5de1616cd9e6686553e8d6f56df6 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Thu, 6 Feb 2025 16:28:33 +0100 Subject: [PATCH 5/5] It's cleaning time i guess --- scripts/module_upgrade.js | 149 ----------- scripts/upgrades/5_0_0-to-5_1_0.js | 151 ----------- scripts/upgrades/5_1_0-to-5_2_0.ethers.js | 158 ----------- scripts/upgrades/5_1_0-to-5_2_0.js | 307 ---------------------- 4 files changed, 765 deletions(-) delete mode 100644 scripts/module_upgrade.js delete mode 100644 scripts/upgrades/5_0_0-to-5_1_0.js delete mode 100644 scripts/upgrades/5_1_0-to-5_2_0.ethers.js delete mode 100644 scripts/upgrades/5_1_0-to-5_2_0.js diff --git a/scripts/module_upgrade.js b/scripts/module_upgrade.js deleted file mode 100644 index 120dfd0a9..000000000 --- a/scripts/module_upgrade.js +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const CONFIG = require('../config/config.json'); -const { ethers } = require('ethers'); -var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); -var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); -var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); - -/***************************************************************************** - * Configuration * - *****************************************************************************/ -const LIBRARIES = [ - // artifacts.require('IexecLibOrders_v5'), -]; - -const MODULES = [ - // { module: artifacts.require('IexecAccessorsDelegate'), methods: [ 'viewTask', 'resultFor' ] }, // result separation update - // { module: artifacts.require('IexecPocoDelegate'), methods: [ 'finalize', 'contributeAndFinalize' ] }, // result separation update - // { module: artifacts.require('IexecEscrowTokenDelegate'), methods: null }, // escrow upgrade (uniswap) - // { module: artifacts.require('IexecEscrowTokenSwapDelegate'), methods: null }, // escrow upgrade (uniswap) -]; - -const FUNCTIONS = [ - // { func: 'finalize(bytes32,bytes);', address: '0x0000000000000000000000000000000000000000' }, // result separation update - // { func: 'contributeAndFinalize(bytes32,bytes32,bytes,address,bytes,bytes);', address: '0x0000000000000000000000000000000000000000' }, // result separation update -]; - -/***************************************************************************** - * Tools * - *****************************************************************************/ -function getSerializedObject(entry) { - return entry.type == 'tuple' - ? `(${entry.components.map(getSerializedObject).join(',')})` - : entry.type; -} - -function getFunctionSignatures(abi) { - return ( - abi - .filter((entry) => entry.type == 'function') - .map((entry) => `${entry.name}(${entry.inputs.map(getSerializedObject).join(',')});`) - .join('') + - (abi.some((entry) => entry.type == 'receive') ? 'receive;' : '') + - (abi.some((entry) => entry.type == 'fallback') ? 'fallback;' : '') - ); -} - -async function factoryDeployer(contract, options = {}) { - console.log(`[factoryDeployer] ${contract.contractName}`); - const factory = await GenericFactory.deployed(); - const libraryAddresses = await Promise.all( - LIBRARIES.filter(({ contractName }) => contract.bytecode.search(contractName) != -1).map( - async ({ contractName, deployed }) => ({ - pattern: new RegExp( - `__${contractName}${'_'.repeat(38 - contractName.length)}`, - 'g', - ), - ...(await deployed()), - }), - ), - ); - - const constructorABI = contract._json.abi.find((e) => e.type == 'constructor'); - const coreCode = libraryAddresses.reduce( - (code, { pattern, address }) => code.replace(pattern, address.slice(2).toLowerCase()), - contract.bytecode, - ); - const argsCode = constructorABI - ? ethers.utils.defaultAbiCoder - .encode( - constructorABI.inputs.map((e) => e.type), - options.args || [], - ) - .slice(2) - : ''; - const code = coreCode + argsCode; - const salt = - options.salt || '0x0000000000000000000000000000000000000000000000000000000000000000'; - - contract.address = options.call - ? await factory.predictAddressWithCall(code, salt, options.call) - : await factory.predictAddress(code, salt); - - if ((await ethers.provider.getCode(contract.address)) == '0x') { - console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); - options.call - ? await factory.createContractAndCall(code, salt, options.call) - : await factory.createContract(code, salt); - console.log( - `[factory] ${contract.contractName} successfully deployed at ${contract.address}`, - ); - } else { - console.log(`[factory] ${contract.contractName} already deployed`); - } -} -/***************************************************************************** - * Main * - *****************************************************************************/ -module.exports = async (callback) => { - try { - const network = await ethers.provider.getNetwork(); - console.log('# ethers version:', ethers.version); - console.log('Chainid is:', network.chainId); - console.log('Network name is:', network.name); - - // Load config - const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; - - // Load core - const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); - console.log('Deploying to proxy:', proxy.address); - - // Module updates - for ([i, { module, methods }] of Object.entries(MODULES.filter(Boolean))) { - console.log(`[${i}] ERC1538 link: ${module.contractName}`); - // deploy module - if (deploymentOptions.v5.usefactory) { - await factoryDeployer(module, factoryOptions); - } else { - await deployer.deploy(module); - } - // update proxy - await proxy.updateContract( - (await module.deployed()).address, - getFunctionSignatures( - module.abi.filter((entry) => !methods || methods.indexOf(entry.name) != -1), - ), - `Linking module ${module.contractName}`, - ); - } - - // Function updates - for ([i, { func, address }] of Object.entries(FUNCTIONS.filter(Boolean))) { - // format, add ';' if needed. - if (!func.endsWith(';')) { - func += ';'; - } - // update proxy - console.log(`[${i}] Linking function: ${func} → ${address}`); - await proxy.updateContract(address, func, `Updating function ${func}`); - } - } catch (e) { - callback(e); - } finally { - callback(); - } -}; diff --git a/scripts/upgrades/5_0_0-to-5_1_0.js b/scripts/upgrades/5_0_0-to-5_1_0.js deleted file mode 100644 index 3ab4b4ed2..000000000 --- a/scripts/upgrades/5_0_0-to-5_1_0.js +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const CONFIG = require('../../config/config.json'); -const { ethers } = require('ethers'); -var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); -var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); -var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); - -/***************************************************************************** - * Configuration * - *****************************************************************************/ -const LIBRARIES = [artifacts.require('IexecLibOrders_v5')]; - -const MODULES = [ - { module: artifacts.require('IexecAccessorsDelegate'), methods: ['viewTask', 'resultFor'] }, // result separation update - { - module: artifacts.require('IexecPocoDelegate'), - methods: ['finalize', 'contributeAndFinalize'], - }, // result separation update -]; - -const FUNCTIONS = [ - { func: 'finalize(bytes32,bytes);', address: '0x0000000000000000000000000000000000000000' }, // result separation update - { - func: 'contributeAndFinalize(bytes32,bytes32,bytes,address,bytes,bytes);', - address: '0x0000000000000000000000000000000000000000', - }, // result separation update -]; - -/***************************************************************************** - * Tools * - *****************************************************************************/ -function getSerializedObject(entry) { - return entry.type == 'tuple' - ? `(${entry.components.map(getSerializedObject).join(',')})` - : entry.type; -} - -function getFunctionSignatures(abi) { - return ( - abi - .filter((entry) => entry.type == 'function') - .map((entry) => `${entry.name}(${entry.inputs.map(getSerializedObject).join(',')});`) - .join('') + - (abi.some((entry) => entry.type == 'receive') ? 'receive;' : '') + - (abi.some((entry) => entry.type == 'fallback') ? 'fallback;' : '') - ); -} - -async function factoryDeployer(contract, options = {}) { - console.log(`[factoryDeployer] ${contract.contractName}`); - const factory = await GenericFactory.deployed(); - const libraryAddresses = await Promise.all( - LIBRARIES.filter(({ contractName }) => contract.bytecode.search(contractName) != -1).map( - async ({ contractName, deployed }) => ({ - pattern: new RegExp( - `__${contractName}${'_'.repeat(38 - contractName.length)}`, - 'g', - ), - ...(await deployed()), - }), - ), - ); - - const constructorABI = contract._json.abi.find((e) => e.type == 'constructor'); - const coreCode = libraryAddresses.reduce( - (code, { pattern, address }) => code.replace(pattern, address.slice(2).toLowerCase()), - contract.bytecode, - ); - const argsCode = constructorABI - ? ethers.utils.defaultAbiCoder - .encode( - constructorABI.inputs.map((e) => e.type), - options.args || [], - ) - .slice(2) - : ''; - const code = coreCode + argsCode; - const salt = - options.salt || '0x0000000000000000000000000000000000000000000000000000000000000000'; - - contract.address = options.call - ? await factory.predictAddressWithCall(code, salt, options.call) - : await factory.predictAddress(code, salt); - - if ((await ethers.provider.getCode(contract.address)) == '0x') { - console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); - options.call - ? await factory.createContractAndCall(code, salt, options.call) - : await factory.createContract(code, salt); - console.log( - `[factory] ${contract.contractName} successfully deployed at ${contract.address}`, - ); - } else { - console.log(`[factory] ${contract.contractName} already deployed`); - } -} -/***************************************************************************** - * Main * - *****************************************************************************/ -module.exports = async (callback) => { - try { - const network = await ethers.provider.getNetwork(); - console.log('# ethers version:', ethers.version); - console.log('Chainid is:', network.chainId); - console.log('Network name is:', network.name); - - // Load config - const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; - - // Load core - const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); - console.log('Deploying to proxy:', proxy.address); - - // Module updates - for ([i, { module, methods }] of Object.entries(MODULES.filter(Boolean))) { - console.log(`[${i}] ERC1538 link: ${module.contractName}`); - // deploy module - if (deploymentOptions.v5.usefactory) { - await factoryDeployer(module, factoryOptions); - } else { - await deployer.deploy(module); - } - // update proxy - await proxy.updateContract( - (await module.deployed()).address, - getFunctionSignatures( - module.abi.filter((entry) => !methods || methods.indexOf(entry.name) != -1), - ), - `Linking module ${module.contractName}`, - ); - } - - // Function updates - for ([i, { func, address }] of Object.entries(FUNCTIONS.filter(Boolean))) { - // format, add ';' if needed. - if (!func.endsWith(';')) { - func += ';'; - } - // update proxy - console.log(`[${i}] Linking function: ${func} → ${address}`); - await proxy.updateContract(address, func, `Updating function ${func}`); - } - } catch (e) { - callback(e); - } finally { - callback(); - } -}; diff --git a/scripts/upgrades/5_1_0-to-5_2_0.ethers.js b/scripts/upgrades/5_1_0-to-5_2_0.ethers.js deleted file mode 100644 index 82529639d..000000000 --- a/scripts/upgrades/5_1_0-to-5_2_0.ethers.js +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const { ethers } = require('ethers'); -const CONFIG = require('../../config/config.json'); - -artifacts = { - require: (name) => { - try { - return require(`${process.cwd()}/build/contracts/${name}.json`); - } catch {} - try { - return require(`${process.cwd()}/node_modules/${name}.json`); - } catch {} - }, -}; - -const GenericFactory = artifacts.require('GenericFactory'); -const ERC1538Proxy = artifacts.require('ERC1538Proxy'); -const ERC1538Update = artifacts.require('ERC1538UpdateDelegate'); - -const LIBRARIES = [artifacts.require('IexecLibOrders_v5')]; - -const MODULES = [ - // { module: artifacts.require('IexecEscrowNativeDelegate'), methods: null }, - { module: artifacts.require('IexecEscrowTokenDelegate'), methods: null }, - { module: artifacts.require('IexecEscrowTokenSwapDelegate'), methods: null }, -]; - -const FUNCTIONS = [ - // -]; - -/***************************************************************************** - * Tools * - *****************************************************************************/ -function getSerializedObject(entry) { - return entry.type == 'tuple' - ? `(${entry.components.map(getSerializedObject).join(',')})` - : entry.type; -} - -function getFunctionSignatures(abi) { - return ( - abi - .filter((entry) => entry.type == 'function') - .map((entry) => `${entry.name}(${entry.inputs.map(getSerializedObject).join(',')});`) - .join('') + - (abi.some((entry) => entry.type == 'receive') ? 'receive;' : '') + - (abi.some((entry) => entry.type == 'fallback') ? 'fallback;' : '') - ); -} - -class FactoryDeployer { - constructor(artefact, options) { - this._address = artefact.networks[options.chainid].address; - this._factory = new ethers.Contract(this._address, artefact.abi, options.wallet); - this._salt = options.salt || ethers.utils.randomBytes(32); - } - - async deploy(artefact, options = {}) { - console.log(`[factoryDeployer] ${artefact.contractName}`); - const libraryAddresses = await Promise.all( - LIBRARIES.filter( - ({ contractName }) => artefact.bytecode.search(contractName) != -1, - ).map(({ contractName, networks }) => ({ - pattern: new RegExp( - `__${contractName}${'_'.repeat(38 - contractName.length)}`, - 'g', - ), - address: networks[options.chainid].address, - })), - ); - - const constructorABI = artefact.abi.find((e) => e.type == 'constructor'); - const coreCode = libraryAddresses.reduce( - (code, { pattern, address }) => code.replace(pattern, address.slice(2).toLowerCase()), - artefact.bytecode, - ); - const argsCode = constructorABI - ? ethers.utils.defaultAbiCoder - .encode( - constructorABI.inputs.map((e) => e.type), - options.args || [], - ) - .slice(2) - : ''; - const code = coreCode + argsCode; - const salt = options.salt || this._salt || ethers.constants.HashZero; - const predicted = options.call - ? await this._factory.predictAddressWithCall(code, salt, options.call) - : await this._factory.predictAddress(code, salt); - - if ((await this._factory.provider.getCode(predicted)) == '0x') { - console.log(`[factory] Preparing to deploy ${artefact.contractName} ...`); - options.call - ? await this._factory.createContractAndCall(code, salt, options.call) - : await this._factory.createContract(code, salt); - console.log(`[factory] ${artefact.contractName} successfully deployed at ${predicted}`); - } else { - console.log(`[factory] ${artefact.contractName} already deployed at ${predicted}`); - } - artefact.networks[await this._factory.signer.getChainId()] = { address: predicted }; - } -} - -(async () => { - const provider = new ethers.providers.JsonRpcProvider(process.env.NODE); - const wallet = new ethers.Wallet(process.env.MNEMONIC, provider); - const chainid = await wallet.getChainId(); - const deploymentOptions = CONFIG.chains[chainid] || CONFIG.chains.default; - - // Deployer - const deployer = new FactoryDeployer(GenericFactory, { - wallet, - chainid, - salt: deploymentOptions.v5.salt, - }); - - // Load core - const proxy = new ethers.Contract( - ERC1538Proxy.networks[chainid].address, - ERC1538Update.abi, - wallet, - ); - console.log(`Connecting to proxy at ${proxy.address}`); - - // Module updates - for ([i, { module, methods }] of Object.entries(MODULES.filter(Boolean))) { - console.log(`[${i}] ERC1538 link: ${module.contractName}`); - // deploy module - if (deploymentOptions.v5.usefactory) { - await deployer.deploy(module); - } else { - throw 'not supported'; - } - - // update proxy - await proxy.updateContract( - module.networks[chainid].address, - getFunctionSignatures( - module.abi.filter((entry) => !methods || methods.indexOf(entry.name) != -1), - ), - `Linking module ${module.contractName}`, - ); - } - - // Function updates - for ([i, { func, address }] of Object.entries(FUNCTIONS.filter(Boolean))) { - // format, add ';' if needed. - if (!func.endsWith(';')) { - func += ';'; - } - // update proxy - console.log(`[${i}] Linking function: ${func} → ${address}`); - await proxy.updateContract(address, func, `Updating function ${func}`); - } -})().catch(console.error); diff --git a/scripts/upgrades/5_1_0-to-5_2_0.js b/scripts/upgrades/5_1_0-to-5_2_0.js deleted file mode 100644 index a43b7c794..000000000 --- a/scripts/upgrades/5_1_0-to-5_2_0.js +++ /dev/null @@ -1,307 +0,0 @@ -// SPDX-FileCopyrightText: 2020 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const CONFIG = require('../../config/config.json'); -const { ethers } = require('ethers'); -var GenericFactory = artifacts.require('@iexec/solidity/GenericFactory'); -var ERC1538Proxy = artifacts.require('@iexec/solidity/ERC1538Proxy'); -var ERC1538Update = artifacts.require('@iexec/solidity/ERC1538UpdateDelegate'); - -/***************************************************************************** - * Configuration * - *****************************************************************************/ -const LIBRARIES = [artifacts.require('IexecLibOrders_v5')]; - -const MODULES = [ - // { module: artifacts.require('IexecEscrowNativeDelegate'), methods: null }, - // { module: artifacts.require('IexecEscrowTokenDelegate'), methods: null }, - { module: artifacts.require('IexecEscrowTokenSwapDelegate'), methods: null }, -]; - -const FUNCTIONS = []; - -/***************************************************************************** - * Tools * - *****************************************************************************/ -function getSerializedObject(entry) { - return entry.type == 'tuple' - ? `(${entry.components.map(getSerializedObject).join(',')})` - : entry.type; -} - -function getFunctionSignatures(abi) { - return ( - abi - .filter((entry) => entry.type == 'function') - .map((entry) => `${entry.name}(${entry.inputs.map(getSerializedObject).join(',')});`) - .join('') + - (abi.some((entry) => entry.type == 'receive') ? 'receive;' : '') + - (abi.some((entry) => entry.type == 'fallback') ? 'fallback;' : '') - ); -} - -async function factoryDeployer(contract, options = {}) { - console.log(`[factoryDeployer] ${contract.contractName}`); - const factory = await GenericFactory.deployed(); - const libraryAddresses = await Promise.all( - LIBRARIES.filter(({ contractName }) => contract.bytecode.search(contractName) != -1).map( - async ({ contractName, deployed }) => ({ - pattern: new RegExp( - `__${contractName}${'_'.repeat(38 - contractName.length)}`, - 'g', - ), - ...(await deployed()), - }), - ), - ); - - const constructorABI = contract._json.abi.find((e) => e.type == 'constructor'); - const coreCode = libraryAddresses.reduce( - (code, { pattern, address }) => code.replace(pattern, address.slice(2).toLowerCase()), - contract.bytecode, - ); - const argsCode = constructorABI - ? ethers.utils.defaultAbiCoder - .encode( - constructorABI.inputs.map((e) => e.type), - options.args || [], - ) - .slice(2) - : ''; - const code = coreCode + argsCode; - const salt = - options.salt || '0x0000000000000000000000000000000000000000000000000000000000000000'; - - contract.address = options.call - ? await factory.predictAddressWithCall(code, salt, options.call) - : await factory.predictAddress(code, salt); - - if ((await ethers.provider.getCode(contract.address)) == '0x') { - console.log(`[factory] Preparing to deploy ${contract.contractName} ...`); - options.call - ? await factory.createContractAndCall(code, salt, options.call) - : await factory.createContract(code, salt); - console.log( - `[factory] ${contract.contractName} successfully deployed at ${contract.address}`, - ); - } else { - console.log(`[factory] ${contract.contractName} already deployed`); - } -} -/***************************************************************************** - * Main * - *****************************************************************************/ -module.exports = async (callback) => { - try { - const network = await ethers.provider.getNetwork(); - console.log('# ethers version:', ethers.version); - console.log('Chainid is:', network.chainId); - console.log('Network name is:', network.name); - - // Load config - const deploymentOptions = CONFIG.chains[network.chainId] || CONFIG.chains.default; - const factoryOptions = { salt: deploymentOptions.v5.salt || ethers.utils.randomBytes(32) }; - - // Load core - const proxy = await ERC1538Update.at((await ERC1538Proxy.deployed()).address); - console.log('Deploying to proxy:', proxy.address); - - // Module updates - for ([i, { module, methods }] of Object.entries(MODULES.filter(Boolean))) { - console.log(`[${i}] ERC1538 link: ${module.contractName}`); - // deploy module - if (deploymentOptions.v5.usefactory) { - await factoryDeployer(module, factoryOptions); - } else { - await deployer.deploy(module); - } - // update proxy - await proxy.updateContract( - (await module.deployed()).address, - getFunctionSignatures( - module.abi.filter((entry) => !methods || methods.indexOf(entry.name) != -1), - ), - `Linking module ${module.contractName}`, - ); - } - - // Function updates - for ([i, { func, address }] of Object.entries(FUNCTIONS.filter(Boolean))) { - // format, add ';' if needed. - if (!func.endsWith(';')) { - func += ';'; - } - // update proxy - console.log(`[${i}] Linking function: ${func} → ${address}`); - await proxy.updateContract(address, func, `Updating function ${func}`); - } - - /************************************************************************* - ************************************************************************* - ** TESTING ** - ************************************************************************* - *************************************************************************/ - - if (process.env.TEST) { - const query = await artifacts - .require('@iexec/solidity/ERC1538QueryDelegate') - .at(proxy.address); - const iexec = await artifacts.require('IexecInterfaceToken').at(proxy.address); - const rlc = await artifacts.require('IERC20').at(await iexec.token()); - const apps = await artifacts.require('AppRegistry').at(await iexec.appregistry()); - const datasets = await artifacts - .require('DatasetRegistry') - .at(await iexec.datasetregistry()); - const workerpools = await artifacts - .require('WorkerpoolRegistry') - .at(await iexec.workerpoolregistry()); - - console.log('Using proxy at: ', proxy.address); - console.log('owner: ', await iexec.owner()); - console.log('totalSupply: ', (await iexec.totalSupply()).toString()); - console.log('active methods count: ', (await query.totalFunctions()).toString()); - - // (await Promise.all( - // Array((await query.totalFunctions()).toNumber()).fill().map((_, i) => query.functionByIndex(i)) - // )) - // .forEach((details, i) => console.log(`[${i}] ${details.delegate} ${details.signature}`)); - - const accounts = await ethers.provider.listAccounts(); - console.log('Before:'); - console.log('- ETH balance: ', await ethers.provider.getBalance(iexec.address)); - console.log('- RLC balance: ', (await rlc.balanceOf(iexec.address)).toString()); - console.log('- Total supply: ', (await iexec.totalSupply()).toString()); - - if ((await apps.balanceOf(accounts[0])) == 0) { - console.log('deploy fake app'); - await apps.createApp( - accounts[0], - 'FakeApp', - 'DOCKER', - '0x', - ethers.constants.HashZero, - '0x', - ); - } - if ((await datasets.balanceOf(accounts[0])) == 0) { - console.log('deploy fake dataset'); - await datasets.createDataset( - accounts[0], - 'FakeDataset', - '0x', - ethers.constants.HashZero, - ); - } - if ((await workerpools.balanceOf(accounts[0])) == 0) { - console.log('deploy fake workerpool'); - await workerpools.createWorkerpool(accounts[0], 'FakeWorkerpool'); - } - - const app = ethers.utils.hexZeroPad( - ethers.BigNumber.from((await apps.tokenOfOwnerByIndex(accounts[0], 0)).toString()), - 20, - ); - const dataset = ethers.utils.hexZeroPad( - ethers.BigNumber.from( - (await datasets.tokenOfOwnerByIndex(accounts[0], 0)).toString(), - ), - 20, - ); - const workerpool = ethers.utils.hexZeroPad( - ethers.BigNumber.from( - (await workerpools.tokenOfOwnerByIndex(accounts[0], 0)).toString(), - ), - 20, - ); - - const apporder = { - app, - appprice: 20, - volume: 1000, - tag: ethers.constants.HashZero, - datasetrestrict: ethers.constants.AddressZero, - workerpoolrestrict: ethers.constants.AddressZero, - requesterrestrict: ethers.constants.AddressZero, - salt: ethers.utils.randomBytes(32), - sign: '0x', - }; - const datasetorder = { - dataset, - datasetprice: 60, - volume: 1000, - tag: ethers.constants.HashZero, - apprestrict: ethers.constants.AddressZero, - workerpoolrestrict: ethers.constants.AddressZero, - requesterrestrict: ethers.constants.AddressZero, - salt: ethers.utils.randomBytes(32), - sign: '0x', - }; - const workerpoolorder = { - workerpool, - workerpoolprice: 0, - volume: 3, - category: 4, - trust: ethers.constants.Zero, - tag: ethers.constants.AddressZero, - apprestrict: ethers.constants.AddressZero, - datasetrestrict: ethers.constants.AddressZero, - requesterrestrict: ethers.constants.AddressZero, - salt: ethers.utils.randomBytes(32), - sign: '0x', - }; - const requestorder = { - app, - appmaxprice: 100, - dataset, - datasetmaxprice: 100, - workerpool, - workerpoolmaxprice: 100, - volume: 10, // CHANGE FOR BOT - category: 4, - trust: ethers.constants.Zero, - tag: ethers.constants.HashZero, - requester: accounts[0], - beneficiary: accounts[0], - callback: ethers.constants.AddressZero, - params: '', - salt: ethers.utils.randomBytes(32), - sign: '0x', - }; - - await iexec.manageAppOrder({ order: apporder, operation: 0, sign: '0x' }); - await iexec.manageDatasetOrder({ order: datasetorder, operation: 0, sign: '0x' }); - await iexec.manageWorkerpoolOrder({ order: workerpoolorder, operation: 0, sign: '0x' }); - await iexec.manageRequestOrder({ order: requestorder, operation: 0, sign: '0x' }); - - // const tx = await ethers.provider.getSigner(accounts[0]).sendTransaction({ to: iexec.address, value: ethers.utils.parseEther("0.1") }); - // const tx = await iexec.depositEth({ value: "10000000000000000" }) - // const tx = await iexec.withdrawEth(126492) - // const tx = await iexec.requestToken(10, { value: "10000000000000000" }) - const tx = await iexec.matchOrdersWithEth( - apporder, - datasetorder, - workerpoolorder, - requestorder, - { value: '10000000000000000', from: accounts[1] }, - ); - - tx.logs - .filter(({ event }) => event == 'Transfer') - .forEach(({ address, event, args }) => { - console.log(`[ ${address} | ${event} ]`); - console.log(args.from.toString()); - console.log(args.to.toString()); - console.log(args.value.toString()); - }); - - console.log('After:'); - console.log('- ETH balance: ', await ethers.provider.getBalance(iexec.address)); - console.log('- RLC balance: ', (await rlc.balanceOf(iexec.address)).toString()); - console.log('- Total supply: ', (await iexec.totalSupply()).toString()); - } - } catch (e) { - callback(e); - } finally { - callback(); - } -};