Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)',
];
2 changes: 2 additions & 0 deletions packages/smart-contracts/scripts-create2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const getArtifact = (contract: string): artifacts.ContractArtifact<Contra
return artifacts.batchConversionPaymentsArtifact;
case 'ERC20TransferableReceivable':
return artifacts.erc20TransferableReceivableArtifact;
case 'SingleRequestProxyFactory':
return artifacts.singleRequestProxyFactoryArtifact;
default:
throw new Error('Contract unknown');
}
Expand Down
Loading