Skip to content

Commit

Permalink
fix: update all chainlink conversion path version (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoslr authored Nov 4, 2022
1 parent 796d3f4 commit 202eeb4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const chainlinkConversionPath = new ContractArtifact<ChainlinkConversionP
address: '0x70bE16E6B7F465bED2237Cf609341A29C019B3bf',
creationBlockNumber: 7108894,
},
// v0.1.0 Used by Erc20Conversion / Erc20SwapConversion
matic: {
address: '0xEEc4790306C43DC00cebbE4D0c36Fadf8634B533',
creationBlockNumber: 17427745,
Expand All @@ -42,6 +43,7 @@ export const chainlinkConversionPath = new ContractArtifact<ChainlinkConversionP
address: '0xEEc4790306C43DC00cebbE4D0c36Fadf8634B533',
creationBlockNumber: 11540176,
},
// v0.1.0 Used by Erc20Conversion / Erc20SwapConversion
fantom: {
address: '0xEEc4790306C43DC00cebbE4D0c36Fadf8634B533',
creationBlockNumber: 20061324,
Expand All @@ -63,11 +65,6 @@ 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 All @@ -76,10 +73,26 @@ export const chainlinkConversionPath = new ContractArtifact<ChainlinkConversionP
address: '0x70bE16E6B7F465bED2237Cf609341A29C019B3bf',
creationBlockNumber: 7108894,
},
// v0.1.0 contract - v0.2.0 is not required for mainnet
mainnet: {
address: '0xC5519f3fcECC8EC85caaF8836563dEe9a00080f9',
creationBlockNumber: 12225729,
},
// v0.2.0 used by Batch / EthConversion
matic: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 25999509,
},
// v0.2.0 used by Batch / EthConversion
fantom: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 28548259,
},
// v0.1.0 contract - v0.2.0 required if/when we support EthConversionProxy on this chain
xdai: {
address: '0xEEc4790306C43DC00cebbE4D0c36Fadf8634B533',
creationBlockNumber: 18326897,
},
'arbitrum-one': {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 5317970,
Expand Down Expand Up @@ -111,14 +124,14 @@ export const chainlinkConversionPath = new ContractArtifact<ChainlinkConversionP
},
},
*/
// Unused conversion path contract that messes up with the toolbox
// Not used, 0.1.0 is only bugged for other networks
/*
'0.2.0': {
matic: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 25999509,
},
},
'0.2.0': {
mainnet: {
address: '0x0818Ad7016138f0A40DFAe30F64a923c2A8F61bA',
creationBlockNumber: 14448210,
},
}
*/
'0.2.0',
);
70 changes: 45 additions & 25 deletions packages/toolbox/src/commands/chainlink/contractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,36 @@ export const runUpdate = async <T extends 'updateAggregator' | 'updateAggregator
params: Parameters<ChainlinkConversionPath['functions'][T]>,
args: SharedOptions,
): Promise<void> => {
const contract = connectChainlinkContract(args);
const contractsWithVersion = connectChainlinkContracts(args);
const dryRunText = args.dryRun ? '[dry-run] ' : '';

console.log(`${dryRunText} will call ${method} on ${contract.address} (${args.network}))`);
console.log(JSON.stringify(params));
if (args.dryRun) {
process.exit();
}
// TS hack to fix params type
const neverParams = params as [never, never, never];
for (const { version, contract } of contractsWithVersion) {
console.log(
`${dryRunText} will call ${method} on chainlinkConversionPath version ${version} at ${contract.address} (${args.network}))`,
);
console.log(JSON.stringify(params));
if (args.dryRun) {
process.exit();
}
// TS hack to fix params type
const neverParams = params as [never, never, never];

try {
const gas = await contract.estimateGas[method](...neverParams);
console.log(`Gas Estimation: ${utils.formatUnits(gas, 'gwei')} gwei`);
} catch (e) {
console.log('Cannot estimate gas');
}
const { proceed } = await inquirer.prompt([
{ name: 'proceed', type: 'confirm', message: 'Proceed?' },
]);
if (!proceed) {
process.exit();
}
try {
const gas = await contract.estimateGas[method](...neverParams);
console.log(`Gas Estimation: ${utils.formatUnits(gas, 'gwei')} gwei`);
} catch (e) {
console.log('Cannot estimate gas');
}
const { proceed } = await inquirer.prompt([
{ name: 'proceed', type: 'confirm', message: 'Proceed?' },
]);
if (!proceed) {
process.exit();
}

const tx = await contract.functions[method](...neverParams);
console.log(`Transaction: ${tx.hash}`);
const tx = await contract.functions[method](...neverParams);
console.log(`Transaction: ${tx.hash}`);
}
};

export type SharedOptions = {
Expand All @@ -43,12 +47,18 @@ export type SharedOptions = {
dryRun?: boolean;
network: string;
};
const connectChainlinkContract = ({

type ChainlinkContractWithVersion = {
version: string;
contract: ChainlinkConversionPath;
};

const connectChainlinkContracts = ({
privateKey,
mnemonic,
dryRun,
network,
}: SharedOptions): ChainlinkConversionPath => {
}: SharedOptions): ChainlinkContractWithVersion[] => {
const provider = getDefaultProvider(network);

const wallet = privateKey
Expand All @@ -62,5 +72,15 @@ const connectChainlinkContract = ({
if (!wallet) {
throw new Error('one of mnemonic or privateKey is mandatory when dryRun is false');
}
return chainlinkConversionPath.connect(network, wallet as any) as any; // TODO
const versions = chainlinkConversionPath
.getAllAddresses(network)
.filter((x) => !!x.address)
.map((x) => x.version);

return versions.map((version) => {
return {
version,
contract: chainlinkConversionPath.connect(network, wallet as any, version) as any, // TODO}
};
});
};

0 comments on commit 202eeb4

Please sign in to comment.