Skip to content

Commit

Permalink
chore: ETHConversion proxy ownership transferred (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
yomarion committed Mar 24, 2022
1 parent e421092 commit 8924aa5
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 53 deletions.
135 changes: 92 additions & 43 deletions packages/smart-contracts/scripts/deploy-payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { ChainlinkConversionPath } from '../src/types/ChainlinkConversionPath';
// eslint-disable-next-line
// @ts-ignore Cannot find module
import { ERC20SwapToConversion } from '../src/types/ERC20SwapToConversion';
// eslint-disable-next-line
// @ts-ignore Cannot find module
import { EthConversionProxy } from '../src/types/EthConversionProxy';
import { CurrencyManager } from '@requestnetwork/currency';
import { RequestLogicTypes } from '@requestnetwork/types';
import { HardhatRuntimeEnvironmentExtended } from '../scripts-create2/types';
Expand Down Expand Up @@ -109,6 +112,19 @@ export async function deployAllPaymentContracts(
simulationSuccess = simulationSuccess ?? true;
}
};

/* Returns true if the nonce is <= targetNonce, and switches to simulation if != targetNonce */
const nonceReady = async (targetNonce: number) => {
const currentNonce = await deployer.getTransactionCount();
if (currentNonce !== targetNonce && currentNonce > 17) {
console.warn(`Warning: got nonce ${currentNonce} instead of ${targetNonce}`);
switchToSimulation();
}
if (currentNonce === targetNonce) {
return true;
}
return false;
};
// #endregion

// #region BATCH DEFINITIONS
Expand Down Expand Up @@ -182,7 +198,8 @@ export async function deployAllPaymentContracts(
);
}
if (args.simulate === false) {
await chainlinkInstance.addWhitelistAdmin(process.env.ADMIN_WALLET_ADDRESS);
const tx = await chainlinkInstance.addWhitelistAdmin(process.env.ADMIN_WALLET_ADDRESS);
await tx.wait(1);
} else {
console.log('[i] Simulating addWhitelistAdmin to chainlinkInstance');
}
Expand All @@ -195,7 +212,7 @@ export async function deployAllPaymentContracts(
switchToSimulation();
}
}
return chainlinkInstance;
return { chainlinkInstance, ethConversionResult };
};

/*
Expand All @@ -208,8 +225,9 @@ export async function deployAllPaymentContracts(
chainlinkInstance: ChainlinkConversionPath,
erc20FeeProxyAddress: string,
erc20SwapConversionInstance: ERC20SwapToConversion,
ethConversionResultInstance?: EthConversionProxy,
) => {
const NONCE_BATCH_5 = 13;
const NONCE_BATCH_5 = 15;
await jumpToNonce(args, hre, NONCE_BATCH_5);
let chainlinkConversionPathAddress = chainlinkInstance?.address;
if (!chainlinkConversionPathAddress) {
Expand All @@ -231,26 +249,21 @@ export async function deployAllPaymentContracts(

// 5.b ERC20ConversionProxy.transferOwnership

let currentNonce = await deployer.getTransactionCount();
const erc20ConversionAdminNonce = NONCE_BATCH_5 + 1;
if (currentNonce === erc20ConversionAdminNonce && erc20ConversionResult) {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(
'ADMIN_WALLET_ADDRESS missing for: ERC20ConversionProxy.transferOwnership',
);
}
if (args.simulate === false) {
await erc20ConversionResult.instance.transferOwnership(process.env.ADMIN_WALLET_ADDRESS);
if (await nonceReady(NONCE_BATCH_5 + 1)) {
if (erc20ConversionResult) {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(
'ADMIN_WALLET_ADDRESS missing for: ERC20ConversionProxy.transferOwnership',
);
}
if (args.simulate === false) {
await erc20ConversionResult.instance.transferOwnership(
process.env.ADMIN_WALLET_ADDRESS,
);
} else {
console.log('[i] Simulating transferOwnership to ERC20ConversionProxy');
}
} else {
console.log('[i] Simulating transferOwnership to ERC20ConversionProxy');
}
} else {
if (currentNonce < erc20ConversionAdminNonce) {
console.warn(
`Warning: got nonce ${currentNonce} instead of ${erc20ConversionAdminNonce}`,
);
switchToSimulation();
} else if (!erc20ConversionResult) {
console.warn(
`Warning: the ERC20ConversionProxy contract instance is not ready, consider retrying.`,
);
Expand All @@ -259,25 +272,60 @@ export async function deployAllPaymentContracts(
}

// 5.c ERC20SwapConversion.setPaymentProxy
currentNonce = await deployer.getTransactionCount();
const erc20SwapConversionAdminNonce = NONCE_BATCH_5 + 2;
if (currentNonce === erc20SwapConversionAdminNonce && erc20ConversionResult) {
if (args.simulate === false) {
await erc20SwapConversionInstance.setPaymentProxy(erc20ConversionResult?.address);
} else {
console.log('[i] Simulating setPaymentProxy to ERC20SwapConversion');
// Ignore if the ERC20 conversion proxy is already live and used, until it gets deprecated
const IGNORE_SET_PAYMENT_PROXY = true;
console.warn(
`DOUBLE-CHECK: ${
IGNORE_SET_PAYMENT_PROXY ? '' : 'not '
}ignoring erc20SwapConversionInstance.setPaymentProxy on ${
erc20SwapConversionInstance.address
}`,
);

if (!IGNORE_SET_PAYMENT_PROXY) {
if (await nonceReady(NONCE_BATCH_5 + 2)) {
if (erc20ConversionResult) {
if (args.simulate === false) {
await erc20SwapConversionInstance.setPaymentProxy(erc20ConversionResult?.address);
} else {
console.log('[i] Simulating setPaymentProxy to ERC20SwapConversion');
}
} else {
console.warn(
`Warning: the ERC20ConversionProxy contract instance is not ready for ERC20SwapConversion update, consider retrying.`,
);
switchToSimulation();
}
}
} else {
if (currentNonce < erc20SwapConversionAdminNonce) {
console.warn(
`Warning: got nonce ${currentNonce} instead of ${erc20SwapConversionAdminNonce}`,
);
switchToSimulation();
} else if (!erc20ConversionResult) {
console.warn(
`Warning: the ERC20ConversionProxy contract instance is not ready for ERC20SwapConversion update, consider retrying.`,
);
switchToSimulation();
}
const ethConversionAdminNonce = NONCE_BATCH_5 + 3;
await jumpToNonce(args, hre, ethConversionAdminNonce);

// 5.d ETHConversion.transferOwnership
if (await nonceReady(ethConversionAdminNonce)) {
if (ethConversionResultInstance) {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(
'ADMIN_WALLET_ADDRESS missing, cannot addWhitelistAdmin on ETHConversion.',
);
}
if (args.simulate === false) {
const tx = await ethConversionResultInstance.addWhitelistAdmin(
process.env.ADMIN_WALLET_ADDRESS,
);
await tx.wait(1);
} else {
console.log(
`[i] Simulating addWhitelistAdmin to ETHConversion at ${ethConversionResultInstance.address}`,
);
}
} else {
if (!ethConversionResultInstance) {
console.warn(
`Warning: the ETHConversion contract instance is not ready for ETHConversion update, consider retrying.`,
);
switchToSimulation();
}
}
}
};
Expand Down Expand Up @@ -329,13 +377,16 @@ export async function deployAllPaymentContracts(
);

// Batch 4
const chainlinkInstance = await runDeploymentBatch_4(ethFeeProxyAddress);
const { chainlinkInstance, ethConversionResult } = await runDeploymentBatch_4(
ethFeeProxyAddress,
);

// Batch 5
await runDeploymentBatch_5(
chainlinkInstance,
erc20FeeProxyAddress,
swapConversionResult.instance,
ethConversionResult?.instance as EthConversionProxy,
);

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -368,8 +419,6 @@ export async function deployAllPaymentContracts(
`* CRITICAL: update src/lib/artifacts files, and push changes NOW !`,
`* IMPORTANT: execute updateAggregatorsList() on conversionPaths`,
`* : then update the lib with chainlinkPath util in toolbox and push changes`,
`* OTHER: run \`yarn hardhat prepare-live-payments --network ${hre.network.name}\``,
`* OTHER: execute administration tasks: approveRouterToSpend(), approvePaymentProxyToSpend() on swaps`,
`* OTHER: deploy subgraphes where needed`,
].join('\r\n'),
);
Expand Down
12 changes: 7 additions & 5 deletions packages/smart-contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ export const uniswapV2RouterAddresses: Record<string, string> = {
*/
export const jumpToNonce = async (args: any, hre: HardhatRuntimeEnvironment, nonce: number) => {
const [deployer] = await hre.ethers.getSigners();
let nextNonce = await deployer.getTransactionCount();
if (args.simulate) {
const currentNonce = await deployer.getTransactionCount();
if (currentNonce < nonce) {
console.log(`Simulating a jump to nonce ${nonce} (current: ${currentNonce})`);
if (nextNonce < nonce) {
console.log(`Simulating a jump to nonce ${nonce} (current: ${nextNonce})`);
}
return;
}
while ((await deployer.getTransactionCount()) < nonce) {
while (nextNonce < nonce) {
// Atificially increase nonce if needed
await deployer.sendTransaction({ to: deployer.address });
const tx = await deployer.sendTransaction({ to: deployer.address, nonce: nextNonce });
await tx.wait(1);
nextNonce = await deployer.getTransactionCount();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const chainlinkConversionPath = new ContractArtifact<ChainlinkConversionP
address: '0x4e71920b7330515faf5EA0c690f1aD06a85fB60c',
creationBlockNumber: 0,
},
// Not used, 0.1.0 is only bugged for other networks
mainnet: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 14448210,
},
rinkeby: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 10023414,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ export const erc20ConversionProxy = new ContractArtifact<Erc20ConversionProxy>(
address: '0xdE5491f774F0Cb009ABcEA7326342E105dbb1B2E',
creationBlockNumber: 0,
},
// Not used on mainnet
mainnet: {
address: '0x1550A8C4F4E5afC67Ea07e8ac590fdcAdB4bBfb1',
creationBlockNumber: 14448345,
},
/**
* The contract on networks below is used as ABI 0.1.0 (cf. above)
* */
'arbitrum-one': {
address: '0xA5186dec7dC1ec85B42A3cd2Dc8289e248530B07',
creationBlockNumber: 5321045,
},
avalanche: {
address: '0xA5186dec7dC1ec85B42A3cd2Dc8289e248530B07',
creationBlockNumber: 11671967,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const ethConversionArtifact = new ContractArtifact<EthConversionProxy>(
address: '0x8273e4B8ED6c78e252a9fCa5563Adfcc75C91b2A',
creationBlockNumber: 0,
},
mainnet: {
address: '0x7Ebf48a26253810629C191b56C3212Fd0D211c26',
creationBlockNumber: 14448211,
},
rinkeby: {
address: '0x7Ebf48a26253810629C191b56C3212Fd0D211c26',
creationBlockNumber: 10023415,
Expand All @@ -67,11 +71,6 @@ export const ethConversionArtifact = new ContractArtifact<EthConversionProxy>(
address: '0x7Ebf48a26253810629C191b56C3212Fd0D211c26',
creationBlockNumber: 11969006,
},
/* All the contracts below have not been updated with 0.2.0 yet */
mainnet: {
address: '0xCa3353a15fCb5C83a1Ff64BFf055781aC5c4d2F4',
creationBlockNumber: 13765042,
},
},
},
},
Expand Down

0 comments on commit 8924aa5

Please sign in to comment.