Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to add/update required filters. #241

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Changes from all 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
151 changes: 151 additions & 0 deletions deployment/10_patch_filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* global artifacts */
global.web3 = web3;
global.artifacts = artifacts;

const ethers = require("ethers");
const childProcess = require("child_process");

const DappRegistry = artifacts.require("DappRegistry");
const MultiSig = artifacts.require("MultiSigWallet");

const CompoundFilter = artifacts.require("CompoundCTokenFilter");
const ParaswapFilter = artifacts.require("ParaswapFilter");
const UniswapV2Filter = artifacts.require("UniswapV2UniZapFilter");
const WethFilter = artifacts.require("WethFilter");
const ParaswapUniV2RouterFilter = artifacts.require("ParaswapUniV2RouterFilter");
const TokenRegistry = artifacts.require("TokenRegistry");

const deployManager = require("../utils/deploy-manager.js");
const MultisigExecutor = require("../utils/multisigexecutor.js");

const main = async () => {
const { deploymentAccount, configurator } = await deployManager.getProps();

// //////////////////////////////////
// Setup
// //////////////////////////////////

const { config } = configurator;
const DappRegistryWrapper = await DappRegistry.at(config.contracts.DappRegistry);
const TokenRegistryWrapper = await TokenRegistry.at(config.contracts.TokenRegistry);
const MultiSigWrapper = await MultiSig.at(config.contracts.MultiSigWallet);
const multisigExecutor = new MultisigExecutor(MultiSigWrapper, deploymentAccount, config.multisig.autosign);

// //////////////////////////////////
// Change DappREgistry ownership
// //////////////////////////////////

console.log("Setting the deployment account as the owner of default registry");
await multisigExecutor.executeCall(DappRegistryWrapper, "changeOwner", [0, deploymentAccount]);

// //////////////////////////////////
// Update existing filters to Argent Registry
// //////////////////////////////////

const filters = {...config.filters};

//
// Compound
//
for (const [underlying, cToken] of Object.entries(config.defi.compound.markets)) {
if (underlying === "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359" || underlying === "0x1985365e9f78359a9B6AD760e32412f4a445E862") {
// remove SAI and REP filter
console.log(`Removing filter for Compound Underlying ${underlying}`);
await DappRegistryWrapper.removeDapp(0, cToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we remove the corresponding filters from the filters.CompoundFilter array?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝

} else if (underlying === "0xdAC17F958D2ee523a2206206994597C13D831ec7" || underlying === "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984") {
// add USDT and UNI filter
console.log(`Deploying filter for Compound Underlying ${underlying}`);
const CompoundFilterWrapper = await CompoundFilter.new(underlying);
console.log(`Deployed filter for Compound Underlying ${underlying} at ${CompoundFilterWrapper.address}`);
filters.CompoundFilter.push(CompoundFilterWrapper.address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will only work if filters has been initialized, see comment above ^

console.log(`Adding filter for Compound Underlying ${underlying}`);
await DappRegistryWrapper.addDapp(0, cToken, CompoundFilterWrapper.address);
}
}

//
// WETH
//
console.log("Deploying WethFilter");
const WethFilterWrapper = await WethFilter.new();
console.log(`Deployed WethFilter at ${WethFilterWrapper.address}`);
filters.WethFilter = WethFilterWrapper.address;
await DappRegistryWrapper.addDapp(0, config.defi.weth, WethFilterWrapper.address);

//
// Uniswap V2
//
console.log("Deploying UniswapV2Filter");
const UniswapV2FilterWrapper = await UniswapV2Filter.new(
TokenRegistryWrapper.address,
config.defi.uniswap.factoryV2,
config.defi.uniswap.initCodeV2,
config.defi.weth
);
console.log(`Deployed UniswapV2Filter at ${UniswapV2FilterWrapper.address}`);
filters.UniswapV2UniZapFilter = UniswapV2FilterWrapper.address;
await DappRegistryWrapper.requestFilterUpdate(0, config.defi.uniswap.unizap, UniswapV2FilterWrapper.address);

//
// Paraswap
//
console.log("Deploying ParaswapFilter");
const ParaswapFilterWrapper = await ParaswapFilter.new(
TokenRegistryWrapper.address,
DappRegistryWrapper.address,
config.defi.paraswap.contract,
config.defi.paraswap.uniswapProxy,
config.defi.paraswap.uniswapForks.map((f) => f.factory),
config.defi.paraswap.uniswapForks.map((f) => f.initCode),
[
config.defi.paraswap.adapters.uniswap || ethers.constants.AddressZero,
config.defi.paraswap.adapters.uniswapV2 || ethers.constants.AddressZero,
config.defi.paraswap.adapters.sushiswap || ethers.constants.AddressZero,
config.defi.paraswap.adapters.linkswap || ethers.constants.AddressZero,
config.defi.paraswap.adapters.defiswap || ethers.constants.AddressZero,
config.defi.paraswap.adapters.zeroexV2 || ethers.constants.AddressZero,
config.defi.paraswap.adapters.zeroexV4 || ethers.constants.AddressZero,
config.defi.paraswap.adapters.curve || ethers.constants.AddressZero,
config.defi.paraswap.adapters.weth || ethers.constants.AddressZero,
],
[].concat(...Object.values(config.defi.paraswap.targetExchanges || {})), // flattened targetExchanges values
config.defi.paraswap.marketMakers || [],
);
console.log(`Deployed ParaswapFilter at ${ParaswapFilterWrapper.address}`);
filters.ParaswapFilter = ParaswapFilterWrapper.address;
await DappRegistryWrapper.requestFilterUpdate(0, config.defi.paraswap.contract, ParaswapFilterWrapper.address);

console.log("Deploying ParaswapUniV2RouterFilter");
filters.ParaswapUniV2RouterFilter = [];
const ParaswapUniV2RouterFilterWrapper = await ParaswapUniV2RouterFilter.new(
TokenRegistryWrapper.address,
config.defi.uniswap.factoryV2,
config.defi.uniswap.initCodeV2,
config.defi.weth
);
console.log(`Deployed ParaswapUniV2RouterFilter at ${ParaswapUniV2RouterFilterWrapper.address}`);
filters.ParaswapUniV2RouterFilter.push(ParaswapUniV2RouterFilterWrapper.address);
await DappRegistryWrapper.requestFilterUpdate(0, config.defi.uniswap.paraswapUniV2Router, ParaswapUniV2RouterFilterWrapper.address);

// //////////////////////////////////
// Change DappREgistry ownership
// //////////////////////////////////

console.log("Setting the MultiSig as the owner of default registry");
await DappRegistryWrapper.changeOwner(0, config.contracts.MultiSigWallet);

// /////////////////////////////////////////////////
// Update config and Upload ABIs
// /////////////////////////////////////////////////

configurator.updateFilterAddresses(filters);

const gitHash = childProcess.execSync("git rev-parse HEAD").toString("utf8").replace(/\n$/, "");
configurator.updateGitHash(gitHash);

console.log("Saving new config");
await configurator.save();
};

// For truffle exec
module.exports = (cb) => main().then(cb).catch(cb);