Skip to content

Commit

Permalink
move network addresses to the hardhat config file and add optimism ne…
Browse files Browse the repository at this point in the history
…twork config
  • Loading branch information
yuanaichi committed Apr 18, 2024
1 parent f332706 commit 25ab90d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 71 deletions.
48 changes: 48 additions & 0 deletions basic/21-aave-uni-loan/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ module.exports = {
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
optimism: {
url: "https://optimism-mainnet.infura.io/v3/" + process.env.INFURA_ID,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
}
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
Expand Down Expand Up @@ -90,5 +95,48 @@ module.exports = {
},
mocha: {
timeout: 80000
},

networkAddressMapping: {
matic: {
daiAddress: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063',
wmaticAddress: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
wethAddress: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',

lendingPoolAddressesProviderAddress: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
uniswapRouterAddress: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
wethGatewayAddress: '0xC1E320966c485ebF2A0A2A6d3c0Dc860A156eB1B',
aaveApeAddress: '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA',
},
optimism: {
daiAddress: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
wmaticAddress: '',
wethAddress: '0x4200000000000000000000000000000000000006',

lendingPoolAddressesProviderAddress: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
uniswapRouterAddress: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
wethGatewayAddress: '0xe9E52021f4e11DEAD8661812A0A6c8627abA2a54',
aaveApeAddress: '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA',
},
mainnet: {
daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
wmaticAddress: '',
wethAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',

lendingPoolAddressesProviderAddress: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
uniswapRouterAddress: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
wethGatewayAddress: '0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9',
aaveApeAddress: '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA',
},
localhost: {
daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
wmaticAddress: '',
wethAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',

lendingPoolAddressesProviderAddress: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
uniswapRouterAddress: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
wethGatewayAddress: '0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9',
aaveApeAddress: '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA',
}
}
};
6 changes: 0 additions & 6 deletions basic/21-aave-uni-loan/ignition/eth-mainnet.json

This file was deleted.

6 changes: 0 additions & 6 deletions basic/21-aave-uni-loan/ignition/matic.json

This file was deleted.

18 changes: 10 additions & 8 deletions basic/21-aave-uni-loan/ignition/modules/AaveApe.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
const { network, config } = require("hardhat");

let maticConfig = {
lendingPoolAddressesProvider: "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
//uniswap
uniswapRouterAddress: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
const networkAddressMapping = config.networkAddressMapping;

// check addressMapping has the network
if (!networkAddressMapping[network.name]) {
throw new Error('network ' + network.name + ' dont config in the addressMapping, please add it');
}

let contractParams = maticConfig;
const {
lendingPoolAddressesProviderAddress,
uniswapRouterAddress
} = networkAddressMapping[network.name];

module.exports = buildModule("AaveApe", (m) => {
const lendingPoolAddressesProviderAddress = m.getParameter("lendingPoolAddressesProvider", contractParams.lendingPoolAddressesProvider);
const uniswapRouterAddress = m.getParameter("uniswapRouterAddress", contractParams.uniswapRouterAddress);

const aaveApe = m.contract("AaveApe", [lendingPoolAddressesProviderAddress, uniswapRouterAddress]);
return { aaveApe };
});
38 changes: 14 additions & 24 deletions basic/21-aave-uni-loan/scripts/loan.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/ethereum-mainnet
// let daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
// let wethAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; //weth
// let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174';
const {network, config} = require('hardhat');

// let lendingPoolAddressesProviderAddress = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
const networkAddressMapping = config.networkAddressMapping;

// //uniswap v3 router
// let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564';
// check addressMapping has the network
if (!networkAddressMapping[network.name]) {
throw new Error('network ' + network.name + ' dont config in the addressMapping, please add it');
}

// let wethGatewayAddress = '0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9'; //WrappedTokenGatewayV3
const {
daiAddress,
wethAddress,

// // Fill in your address
// const aaveApeAddress = '0x90A3B384F62f43Ba07938EA43aEEc35c2aBfeCa2';
lendingPoolAddressesProviderAddress,
uniswapRouterAddress,
wethGatewayAddress,
aaveApeAddress
} = networkAddressMapping[network.name];

//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/polygon
let daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063';
let wethAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'; //wmatic
let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174';

let lendingPoolAddressesProviderAddress = '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb';

//uniswap v3 router
let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564';

let wethGatewayAddress = '0xC1E320966c485ebF2A0A2A6d3c0Dc860A156eB1B'; //WrappedTokenGatewayV3

// Fill in your address
const aaveApeAddress = '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA';

const depositEthInAave = async (pooladdress, _userAddress, _amount) => {
const ethGateway = await ethers.getContractAt('IWrappedTokenGatewayV3', wethGatewayAddress);
Expand Down
38 changes: 18 additions & 20 deletions basic/21-aave-uni-loan/scripts/query.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
const axios = require('axios')
const axios = require('axios');
const { network, config } = require('hardhat');
require("dotenv").config();

let exp = BigInt(10 ** 18);
let exp1 = BigInt(10 ** 27);
const exp = BigInt(10 ** 18);
const exp1 = BigInt(10 ** 27);

// matic address
//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/polygon
let daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063';
let wmaticAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'; //wmatic
let wethAddress = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'; //weth
let wbtcAddress = '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6'; //wbtc
let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174';
const networkAddressMapping = config.networkAddressMapping;

let lendingPoolAddressesProviderAddress = '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb';

//sushi
let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564';

let wethGatewayAddress = '0xC1E320966c485ebF2A0A2A6d3c0Dc860A156eB1B';

// Fill in your address
const aaveApeAddress = '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA';
// check addressMapping has the network
if (!networkAddressMapping[network.name]) {
throw new Error('network ' + network.name + ' dont config in the addressMapping, please add it');
}

const {
daiAddress,
wmaticAddress,
wethAddress,
lendingPoolAddressesProviderAddress,
aaveApeAddress
} = networkAddressMapping[network.name];

const getAToken = async (_asset) => {
let lendingPool = await getLendingPool();
Expand Down Expand Up @@ -96,6 +93,7 @@ const querySql = `
const url = {
matic: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3-polygon',
mainnet: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3',
optimism: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3-optimism'
}

const getInterest = async (url, graphQuery,variables,interestRateMode) => {
Expand Down Expand Up @@ -210,7 +208,7 @@ main = async () => {
console.log('user available borrow dai: %f USD', Number(result * BigInt(1000) / exp) / 1000);


let aToken = await getAToken(wmaticAddress);
let aToken = await getAToken(network.name == 'matic' ? wmaticAddress: wethAddress);
// let aTokenbtc = await getAToken(wbtcAddress);
// console.log("aToken: ", aToken)
let debtToken = await getDebtToken(daiAddress, interestRateMode, true);
Expand Down
21 changes: 14 additions & 7 deletions basic/21-aave-uni-loan/test/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const { expect } = require("chai");
const {network, config} = require('hardhat');

// ethereum mainnet addresses
let daiAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
let wethAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
let usdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
const networkAddressMapping = config.networkAddressMapping;

let lendingPoolAddressesProviderAddress = "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e"
let uniswapRouterAddress = "0xE592427A0AEce92De3Edee1F18E0157C05861564"
// check addressMapping has the network
if (!networkAddressMapping[network.name]) {
throw new Error('network ' + network.name + ' dont config in the addressMapping, please add it');
}

let wethGatewayAddress = "0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9"
const {
daiAddress,
wethAddress,

lendingPoolAddressesProviderAddress,
uniswapRouterAddress,
wethGatewayAddress
} = networkAddressMapping[network.name];

const depositEthInAave = async (_poolAddress, _userAddress, _amount) => {
// console.log("isAddressable", _poolAddress, _userAddress, ethers.isAddressable(_poolAddress), ethers.isAddressable(_userAddress))
Expand Down

0 comments on commit 25ab90d

Please sign in to comment.