diff --git a/packages/smart-contracts/scripts-create2/contract-setup/adminTasks.ts b/packages/smart-contracts/scripts-create2/contract-setup/adminTasks.ts index 16be222ba..12b134668 100644 --- a/packages/smart-contracts/scripts-create2/contract-setup/adminTasks.ts +++ b/packages/smart-contracts/scripts-create2/contract-setup/adminTasks.ts @@ -1,7 +1,7 @@ import { chainlinkConversionPath } from '../../src/lib'; import { uniswapV2RouterAddresses } from '../../scripts/utils'; import * as artifacts from '../../src/lib'; -import { BigNumber, Overrides, Wallet, Contract } from 'ethers'; +import { BigNumber, Overrides, Wallet, Contract, ethers } from 'ethers'; import { HardhatRuntimeEnvironmentExtended } from '../types'; import { parseUnits } from 'ethers/lib/utils'; import { @@ -411,3 +411,73 @@ export const getSignerAndGasFees = async ( txOverrides, }; }; + +/** + * Updates the ERC20 fee proxy address in the SingleRequestProxyFactory contract + * @param contract SingleRequestProxyFactory contract + * @param network The network used + * @param txOverrides information related to gas fees + * @param signer Who is performing the updating + * @param signWithEoa Is the transaction to be signed by an EOA + */ +export const updateSRPFERC20FeeProxyAddress = async ( + contract: Contract, + network: CurrencyTypes.EvmChainName, + txOverrides: Overrides, + signer: Wallet, + signWithEoa: boolean, +): Promise => { + const erc20ProxyAddress = artifacts.erc20FeeProxyArtifact.getAddress(network); + const currentErc20Proxy = await contract.erc20FeeProxy(); + + if (ethers.utils.getAddress(currentErc20Proxy) !== ethers.utils.getAddress(erc20ProxyAddress)) { + await executeContractMethod({ + network, + contract, + 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}`); + } +}; + +/** + * Updates the Ethereum fee proxy address in the SingleRequestProxyFactory contract + * @param contract SingleRequestProxyFactory contract + * @param network The network used + * @param txOverrides information related to gas fees + * @param signer Who is performing the updating + * @param signWithEoa Is the transaction to be signed by an EOA + */ +export const updateSRPFEthereumFeeProxyAddress = async ( + contract: Contract, + network: CurrencyTypes.EvmChainName, + txOverrides: Overrides, + signer: Wallet, + signWithEoa: boolean, +): Promise => { + const ethereumProxyAddress = artifacts.ethereumFeeProxyArtifact.getAddress(network); + const currentEthereumProxy = await contract.ethereumFeeProxy(); + + if ( + ethers.utils.getAddress(currentEthereumProxy) !== ethers.utils.getAddress(ethereumProxyAddress) + ) { + await executeContractMethod({ + network, + contract, + 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}`); + } +}; diff --git a/packages/smart-contracts/scripts-create2/contract-setup/setupSingleRequestProxyFactory.ts b/packages/smart-contracts/scripts-create2/contract-setup/setupSingleRequestProxyFactory.ts new file mode 100644 index 000000000..61f16c0d9 --- /dev/null +++ b/packages/smart-contracts/scripts-create2/contract-setup/setupSingleRequestProxyFactory.ts @@ -0,0 +1,69 @@ +import { EvmChains } from '@requestnetwork/currency'; +import { singleRequestProxyFactoryArtifact } from '../../src/lib'; +import { HardhatRuntimeEnvironmentExtended } from '../types'; +import { + getSignerAndGasFees, + updateSRPFERC20FeeProxyAddress, + updateSRPFEthereumFeeProxyAddress, +} from './adminTasks'; + +/** + * Setup the SingleRequestProxyFactory values once deployed + * @param contractAddress address of the SingleRequestProxyFactory contract + * If not provided fallback to the latest deployment address + * @param hre Hardhat runtime environment + * @param signWithEoa Are transactions to be signed by an EOA + */ +export const setupSRPF = async ({ + contractAddress, + hre, + signWithEoa, +}: { + contractAddress?: string; + hre: HardhatRuntimeEnvironmentExtended; + signWithEoa: boolean; +}): Promise => { + await Promise.all( + hre.config.xdeploy.networks.map(async (network: string) => { + try { + EvmChains.assertChainSupported(network); + if (!contractAddress) { + contractAddress = singleRequestProxyFactoryArtifact.getAddress(network); + } + if (!contractAddress) { + console.warn(`Missing SingleRequestProxyFactory deployment on ${network}`); + return; + } + + const factory = new hre.ethers.Contract( + contractAddress, + singleRequestProxyFactoryArtifact.getContractAbi(), + ); + const { signer, txOverrides } = await getSignerAndGasFees(network, hre); + const factoryConnected = factory.connect(signer); + + await updateSRPFERC20FeeProxyAddress( + factoryConnected, + network, + txOverrides, + signer, + signWithEoa, + ); + await updateSRPFEthereumFeeProxyAddress( + factoryConnected, + network, + txOverrides, + signer, + signWithEoa, + ); + + console.log(`Setup of SingleRequestProxyFactory successful on ${network}`); + } catch (err) { + console.warn( + `An error occurred during the setup of SingleRequestProxyFactory on ${network}`, + ); + console.warn(err); + } + }), + ); +}; diff --git a/packages/smart-contracts/scripts-create2/contract-setup/setups.ts b/packages/smart-contracts/scripts-create2/contract-setup/setups.ts index 4a8dac327..943178528 100644 --- a/packages/smart-contracts/scripts-create2/contract-setup/setups.ts +++ b/packages/smart-contracts/scripts-create2/contract-setup/setups.ts @@ -5,6 +5,7 @@ import { setupERC20SwapToConversion } from './setupERC20SwapToConversion'; import { setupERC20SwapToPay } from './setupERC20SwapToPay'; import { setupChainlinkConversionPath } from './setupChainlinkConversionPath'; import { setupErc20ConversionProxy } from './setupErc20ConversionProxy'; +import { setupSRPF } from './setupSingleRequestProxyFactory'; /** * Administrate the specified contract at the specified address @@ -50,6 +51,10 @@ export const setupContract = async ({ await setupBatchConversionPayments({ contractAddress, hre, signWithEoa }); break; } + case 'SingleRequestProxyFactory': { + await setupSRPF({ contractAddress, hre, signWithEoa }); + break; + } default: { console.log(`No setup to perform for contract ${contractName}`); break; diff --git a/packages/smart-contracts/scripts-create2/utils.ts b/packages/smart-contracts/scripts-create2/utils.ts index 90db473d0..b71761ae8 100644 --- a/packages/smart-contracts/scripts-create2/utils.ts +++ b/packages/smart-contracts/scripts-create2/utils.ts @@ -57,6 +57,8 @@ export const getArtifact = (contract: string): artifacts.ContractArtifact