|
1 | 1 | // SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <[email protected]> |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import { deployments, ethers } from 'hardhat'; |
5 | | -import { IexecAccessors__factory, IexecConfigurationFacet__factory } from '../typechain'; |
| 4 | +// Usage: CALLBACK_GAS=<value> npx hardhat run scripts/set-callback-gas.ts --network <network> |
| 5 | + |
| 6 | +import { ethers } from 'hardhat'; |
| 7 | +import { IexecInterfaceToken__factory } from '../typechain'; |
| 8 | +import config from '../utils/config'; |
6 | 9 |
|
7 | 10 | (async () => { |
8 | 11 | const requestedCallbackGas = Number(process.env.CALLBACK_GAS); |
9 | 12 | if (!requestedCallbackGas) { |
10 | | - console.error('`CALLBACK_GAS` env variable is missing. Aborting.'); |
11 | | - process.exit(1); |
| 13 | + throw new Error('`CALLBACK_GAS` env variable is missing or invalid.'); |
12 | 14 | } |
13 | | - console.log(`Setting callback-gas to ${requestedCallbackGas.toLocaleString()} ..`); |
| 15 | + const { chainId, name: chainName } = await ethers.provider.getNetwork(); |
| 16 | + console.log(`Network: ${chainName} (${chainId})`); |
| 17 | + const proxyAddress = config.getChainConfig(chainId).v5.DiamondProxy; |
| 18 | + if (!proxyAddress) { |
| 19 | + throw new Error('Diamond proxy address is required'); |
| 20 | + } |
| 21 | + console.log(`Diamond proxy address: ${proxyAddress}`); |
14 | 22 | const [owner] = await ethers.getSigners(); |
15 | | - const diamondProxyAddress = (await deployments.get('Diamond')).address; |
16 | | - const viewCallbackGas = async () => |
17 | | - (await IexecAccessors__factory.connect(diamondProxyAddress, owner).callbackgas()) |
18 | | - .toNumber() |
19 | | - .toLocaleString(); |
20 | | - const callbackGasBefore = await viewCallbackGas(); |
21 | | - await IexecConfigurationFacet__factory.connect(diamondProxyAddress, owner) |
22 | | - .setCallbackGas(requestedCallbackGas) |
23 | | - .then((tx) => tx.wait()); |
24 | | - console.log(`Changed callback-gas from ${callbackGasBefore} to ${await viewCallbackGas()}`); |
25 | | -})().catch((error) => console.log(error)); |
| 23 | + const iexecPoCo = IexecInterfaceToken__factory.connect(proxyAddress, owner); |
| 24 | + if ((await iexecPoCo.owner()) !== owner.address) { |
| 25 | + throw new Error(`Sender account ${owner.address} is not the PoCo owner.`); |
| 26 | + } |
| 27 | + console.log(`Setting callback-gas to ${requestedCallbackGas.toLocaleString()} ..`); |
| 28 | + const callbackGasBefore = (await iexecPoCo.callbackgas()).toLocaleString(); |
| 29 | + await iexecPoCo.setCallbackGas(requestedCallbackGas).then((tx) => tx.wait()); |
| 30 | + const callbackGasAfter = (await iexecPoCo.callbackgas()).toLocaleString(); |
| 31 | + console.log(`Changed callback-gas from ${callbackGasBefore} to ${callbackGasAfter}`); |
| 32 | +})().catch((error) => { |
| 33 | + console.log(error); |
| 34 | + process.exitCode = 1; |
| 35 | +}); |
0 commit comments