Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add task to update the SingleRequestProxyFactory fee proxy ad…
Browse files Browse the repository at this point in the history
…dresses
aimensahnoun committed Oct 30, 2024
1 parent a194821 commit 69d7b4c
Showing 2 changed files with 97 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import { tenderlyImportAll } from './scripts-create2/tenderly';
import { updateContractsFromList } from './scripts-create2/update-contracts-setup';
import deployStorage from './scripts/deploy-storage';
import { transferOwnership } from './scripts-create2/transfer-ownership';
import { updateFeeProxies } from './scripts-create2/contract-setup/update-fee-proxies';

config();

@@ -403,3 +404,14 @@ subtask(DEPLOYER_KEY_GUARD, 'prevent usage of the deployer master key').setActio
throw new Error('The deployer master key should not be used for this action');
}
});

task(
'update-fee-proxies-for-single-request-proxy-factory',
'Update the proxy addresses in SingleRequestProxyFactory',
)
.addFlag('eoa', 'Is the update to be performed in an EOA context')
.setAction(async (args, hre) => {
const signWithEoa = args.eoa ?? false;
await hre.run(DEPLOYER_KEY_GUARD);
await updateFeeProxies(hre as HardhatRuntimeEnvironmentExtended, signWithEoa);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
singleRequestProxyFactoryArtifact,
erc20FeeProxyArtifact,
ethereumFeeProxyArtifact,
} from '../../src/lib';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import { getSignerAndGasFees } from './adminTasks';
import { EvmChains } from '@requestnetwork/currency';
import { executeContractMethod } from './execute-contract-method';
import { Contract } from 'ethers';

/**
* Update the proxy addresses in the SingleRequestProxyFactory contract
* @param hre Hardhat runtime environment
* @param signWithEoa Are transactions to be signed by an EOA
*/
export const updateFeeProxies = async (
hre: HardhatRuntimeEnvironmentExtended,
signWithEoa: boolean,
): Promise<void> => {
for (const network of hre.config.xdeploy.networks) {
try {
EvmChains.assertChainSupported(network);

const factoryAddress = singleRequestProxyFactoryArtifact.getAddress(network);
const erc20ProxyAddress = erc20FeeProxyArtifact.getAddress(network);
const ethereumProxyAddress = ethereumFeeProxyArtifact.getAddress(network);

if (!factoryAddress || !erc20ProxyAddress || !ethereumProxyAddress) {
console.info(`Missing contract deployment on ${network}`);
continue;
}

const { signer, txOverrides } = await getSignerAndGasFees(network, hre);

const factory = new Contract(factoryAddress, factoryAbi, signer);

// Check current values
const currentErc20Proxy = await factory.erc20FeeProxy();
const currentEthereumProxy = await factory.ethereumFeeProxy();

// Update ERC20 proxy if needed
if (currentErc20Proxy.toLowerCase() !== erc20ProxyAddress.toLowerCase()) {
await executeContractMethod({
network,
contract: factory,
method: 'setERC20FeeProxy',
props: [erc20ProxyAddress],
txOverrides,
signer,
signWithEoa,
});
console.log(`Updated ERC20FeeProxy to ${erc20ProxyAddress} on ${network}`);
} else {
console.log(`ERC20FeeProxy is already set to ${erc20ProxyAddress} on ${network}`);
}

// Update Ethereum proxy if needed
if (currentEthereumProxy.toLowerCase() !== ethereumProxyAddress.toLowerCase()) {
await executeContractMethod({
network,
contract: factory,
method: 'setEthereumFeeProxy',
props: [ethereumProxyAddress],
txOverrides,
signer,
signWithEoa,
});
console.log(`Updated EthereumFeeProxy to ${ethereumProxyAddress} on ${network}`);
} else {
console.log(`EthereumFeeProxy is already set to ${ethereumProxyAddress} on ${network}`);
}
} catch (err) {
console.warn(`An error occurred updating proxies on ${network}`);
console.warn(err);
}
}
};

const factoryAbi = [
'function erc20FeeProxy() view returns (address)',
'function ethereumFeeProxy() view returns (address)',
'function setERC20FeeProxy(address _newERC20FeeProxy)',
'function setEthereumFeeProxy(address _newEthereumFeeProxy)',
];

0 comments on commit 69d7b4c

Please sign in to comment.