diff --git a/basic/21-aave-uni-loan/hardhat.config.js b/basic/21-aave-uni-loan/hardhat.config.js index 27420e3da..d2ff3ea45 100644 --- a/basic/21-aave-uni-loan/hardhat.config.js +++ b/basic/21-aave-uni-loan/hardhat.config.js @@ -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, @@ -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', + } } }; diff --git a/basic/21-aave-uni-loan/ignition/eth-mainnet.json b/basic/21-aave-uni-loan/ignition/eth-mainnet.json deleted file mode 100644 index da05f0d3c..000000000 --- a/basic/21-aave-uni-loan/ignition/eth-mainnet.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "AaveApe": { - "lendingPoolAddressesProvider": "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e", - "uniswapRouterAddress": "0xE592427A0AEce92De3Edee1F18E0157C05861564" - } -} \ No newline at end of file diff --git a/basic/21-aave-uni-loan/ignition/matic.json b/basic/21-aave-uni-loan/ignition/matic.json deleted file mode 100644 index 601ef42fe..000000000 --- a/basic/21-aave-uni-loan/ignition/matic.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "AaveApe": { - "lendingPoolAddressesProvider": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb", - "uniswapRouterAddress": "0xE592427A0AEce92De3Edee1F18E0157C05861564" - } -} \ No newline at end of file diff --git a/basic/21-aave-uni-loan/ignition/modules/AaveApe.js b/basic/21-aave-uni-loan/ignition/modules/AaveApe.js index 3155e6b2c..f25ac6c4e 100644 --- a/basic/21-aave-uni-loan/ignition/modules/AaveApe.js +++ b/basic/21-aave-uni-loan/ignition/modules/AaveApe.js @@ -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 }; }); \ No newline at end of file diff --git a/basic/21-aave-uni-loan/scripts/loan.js b/basic/21-aave-uni-loan/scripts/loan.js index 759ba1f90..86af29a95 100644 --- a/basic/21-aave-uni-loan/scripts/loan.js +++ b/basic/21-aave-uni-loan/scripts/loan.js @@ -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); diff --git a/basic/21-aave-uni-loan/scripts/query.js b/basic/21-aave-uni-loan/scripts/query.js index 7ca95d474..79d5127b6 100644 --- a/basic/21-aave-uni-loan/scripts/query.js +++ b/basic/21-aave-uni-loan/scripts/query.js @@ -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(); @@ -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) => { @@ -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); diff --git a/basic/21-aave-uni-loan/test/test.js b/basic/21-aave-uni-loan/test/test.js index 728d5df53..37efbb8d6 100644 --- a/basic/21-aave-uni-loan/test/test.js +++ b/basic/21-aave-uni-loan/test/test.js @@ -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))