Skip to content

Commit

Permalink
feat: add dai-weth pair (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbertenasco committed Nov 19, 2020
1 parent 54fcef4 commit 05b41a6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example.config.json
Expand Up @@ -16,7 +16,7 @@
"address": "0x220c33Bb71D3b6A6a6EA2036AbDb1C9449447afc"
},
"uniswapV2Router": {
"address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"
"address": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
},
"uniswapHandler": {
"address": "0x293aC14CB38E2443d9c95C185A25b8EA6f2f18A2"
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
url: `https://eth-mainnet.alchemyapi.io/v2/${config.alchemy.mainnet.apiKey}`,
accounts: mainnetAccounts,
gasMultiplier: 1.1,
gasPrice: 30000000000, // 30 gwei
gasPrice: 55000000000, // 55 gwei
}
},
solidity: {
Expand Down
66 changes: 66 additions & 0 deletions scripts/deploy/02-governance-swap-set-dai-eth.js
@@ -0,0 +1,66 @@
const Confirm = require('prompt-confirm');
const hre = require('hardhat');
const ethers = hre.ethers;
const config = require('../../.config.json');
const { e18 } = require('../../utils/web3-utils');

const prompt = new Confirm('Do you wish to add default dai/weth governance handler and data?');

async function main() {
await hre.run('compile');

await promptAndSubmit();
}

function promptAndSubmit() {
return new Promise(async (resolve) => {
try {
const [owner] = await ethers.getSigners();
console.log('owner:', owner.address);
prompt.ask(async (answer) => {
if (answer) {

const governanceSwap = await ethers.getContractAt('GovernanceSwap', config.contracts.mainnet.governanceSwap.address);
const uniswapDexHandler = await ethers.getContractAt('UniswapV2DexHandler', config.contracts.mainnet.uniswapHandler.address);
const uniswapV2Address = config.contracts.mainnet.uniswapV2Router.address;

const daiAddress = config.contracts.mainnet.dai.address;
const wethAddress = config.contracts.mainnet.weth.address;
const path = [daiAddress, wethAddress];
const defaultSwapData = await uniswapDexHandler.callStatic.customSwapData(
0, // _amount
0, // _min
path, // _path
owner.address, // _to
0// _expire
);
await governanceSwap.setPairDefaults(daiAddress, wethAddress, uniswapV2Address, defaultSwapData);
const pairDefaultDex = await governanceSwap.callStatic.getPairDefaultDex(daiAddress, wethAddress);
console.log('dex is the same', config.contracts.mainnet.uniswapV2Router.address == pairDefaultDex)
const pairDefaultDexHandler = await governanceSwap.callStatic.getPairDefaultDexHandler(daiAddress, wethAddress);
console.log('handler is the same', config.contracts.mainnet.uniswapHandler.address == pairDefaultDexHandler)
const pairDefaultData = await governanceSwap.callStatic.getPairDefaultData(daiAddress, wethAddress);
const customDecodeData = await uniswapDexHandler.callStatic.customDecodeData(pairDefaultData);
console.log('path is the same', JSON.stringify(path) == JSON.stringify(customDecodeData._path));

resolve();
} else {
console.error('Aborted!');
resolve();
}
});
} catch (err) {
reject(err);
}
});
}


// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});

0 comments on commit 05b41a6

Please sign in to comment.