From f79fc4e444c13d221e2d985e21b45634e6a8f229 Mon Sep 17 00:00:00 2001 From: Harsh Pandey Date: Mon, 2 Sep 2024 23:49:40 +0530 Subject: [PATCH] chore: misc files --- .gitignore | 2 + Makefile | 4 -- diff.js | 124 -------------------------------- diff_config.js | 187 ------------------------------------------------- package.json | 8 +-- 5 files changed, 3 insertions(+), 322 deletions(-) delete mode 100644 diff.js delete mode 100644 diff_config.js diff --git a/.gitignore b/.gitignore index e5d4595b..92845bde 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ out/ # artifacts reports/ +diffs/ +downloads/ # editors .idea diff --git a/Makefile b/Makefile index 9d6b56d6..f46c33c3 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,3 @@ download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${a git-diff : @mkdir -p diffs @printf '%s\n%s\n%s\n' "\`\`\`diff" "$$(git diff --no-index --diff-algorithm=patience --ignore-space-at-eol ${before} ${after})" "\`\`\`" > diffs/${out}.md - -diff-mainnet-etherfi :; - mkdir -p diffs/MAINNET_ETHERFI - node ./diff.js MAINNET ETHERFI diff --git a/diff.js b/diff.js deleted file mode 100644 index d507b924..00000000 --- a/diff.js +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env node - -import { ethers } from "ethers"; -import { CONTRACTS, PROXIES, CHAIN_ID } from "./diff_config.js"; -import child_process from "child_process"; -import dotenv from "dotenv"; -import fs from "fs"; -dotenv.config(); - -function runCmd(cmd) { - var resp = child_process.execSync(cmd); - var result = resp.toString("UTF8"); - return result; -} - -const API_KEYS = { - mainnet: process.env.ETHERSCAN_API_KEY_MAINNET, -}; - -function download(network, contractName, address) { - if (!fs.existsSync(`downloads/${network}/${contractName}`)) { - console.log("downloading", contractName); - runCmd( - `cast etherscan-source --chain-id ${CHAIN_ID[network]} -d downloads/${network}/${contractName} ${address} --etherscan-api-key ${API_KEYS.mainnet}` - ); - } -} - -function getImpl(network, address) { - return ethers.toQuantity( - runCmd( - `cast storage --rpc-url mainnet ${address} 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` - ).replace("\n", ""), - 32 - ); -} - -function diffContracts(commonContracts, network1, network2) { - try { - commonContracts.map((contractName) => { - PROXIES.includes(contractName) && (contractName = contractName + "_IMPL"); - const sourcePathNetwork1 = - network1 != "FACTORY_LOCAL" - ? `./downloads/${network1}/${contractName}.sol` - : `./downloads/FACTORY_LOCAL/${contractName}.sol`; - const sourcePathNetwork2 = - network2 != "FACTORY_LOCAL" - ? `./downloads/${network2}/${contractName}.sol` - : `./downloads/FACTORY_LOCAL/${contractName}.sol`; - const outPath = `${network1}_${network2}/${contractName}_DIFF`; - runCmd( - `make git-diff before=${sourcePathNetwork1} after=${sourcePathNetwork2} out=${outPath}` - ); - }); - } catch (e) { - console.log(e); - throw new Error("oops... failed to diff contracts"); - } -} - -function flatten(network, name, path) { - console.log("flattening contract", name); - const sourcePath = - network != "FACTORY_LOCAL" - ? `./downloads/${network}/${name}/${path}` - : `./${path}`; - const outPath = - network != "FACTORY_LOCAL" - ? `./downloads/${network}/${name}.sol` - : `./downloads/FACTORY_LOCAL/${name}.sol`; - runCmd(`forge flatten ${sourcePath} --output ${outPath}`); -} - -function downloadContracts(commonContracts, network) { - commonContracts.map((key) => { - const isProxy = PROXIES.includes(key); - const contractName = isProxy ? `${key}_IMPL` : key; - const address = isProxy - ? getImpl(network.toLowerCase(), CONTRACTS[network][key].address) - : CONTRACTS[network][key].address; - download(network, contractName, address); - }); -} - -function flattenContracts(commonContracts, network) { - commonContracts.map((key) => { - const isProxy = PROXIES.includes(key); - const contractName = isProxy ? `${key}_IMPL` : key; - flatten(network, contractName, CONTRACTS[network][key].path); - }); -} - -function prettifyContracts() { - runCmd(`npm run lint:fix`); -} - -async function main() { - // get networks to diff against from the command line input - const network1 = process.argv[2]; - const network2 = process.argv[3]; - - console.log(`comparing diffs between ${network1}, ${network2}`); - - // find all the common contracts to compare between both the networks. - const commonContracts = Object.keys(CONTRACTS[network1]).filter((key) => - CONTRACTS[network2].hasOwnProperty(key) - ); - - if (network1 != "FACTORY_LOCAL") { - downloadContracts(commonContracts, network1); - } - if (network2 != "FACTORY_LOCAL") { - downloadContracts(commonContracts, network2); - } - - flattenContracts(commonContracts, network1); - flattenContracts(commonContracts, network2); - - prettifyContracts(); - - diffContracts(commonContracts, network1, network2); -} - -main(); diff --git a/diff_config.js b/diff_config.js deleted file mode 100644 index f531800a..00000000 --- a/diff_config.js +++ /dev/null @@ -1,187 +0,0 @@ -import { - AaveV3Ethereum, - AaveV3EthereumEtherFi, -} from "@bgd-labs/aave-address-book"; - -const CONTRACTS = { - MAINNET: { - POOL_ADDRESSES_PROVIDER: { - name: "PoolAddressesProvider", - path: "PoolAddressesProvider/@aave/core-v3/contracts/protocol/configuration/PoolAddressesProvider.sol", - address: AaveV3Ethereum.POOL_ADDRESSES_PROVIDER, - }, - POOL: { - name: "Pool", - path: "PoolInstanceWithCustomInitialize/src/contracts/PoolInstanceWithCustomInitialize.sol", - address: AaveV3Ethereum.POOL, - }, - POOL_CONFIGURATOR: { - name: "PoolConfigurator", - path: "PoolConfiguratorInstance/lib/aave-v3-origin/src/core/instances/PoolConfiguratorInstance.sol", - address: AaveV3Ethereum.POOL_CONFIGURATOR, - }, - ORACLE: { - name: "AaveOracle", - path: "AaveOracle/@aave/core-v3/contracts/misc/AaveOracle.sol", - address: AaveV3Ethereum.ORACLE, - }, - AAVE_PROTOCOL_DATA_PROVIDER: { - name: "AaveProtocolDataProvider", - path: "AaveProtocolDataProvider/lib/aave-v3-origin/src/core/contracts/misc/AaveProtocolDataProvider.sol", - address: AaveV3Ethereum.AAVE_PROTOCOL_DATA_PROVIDER, - }, - ACL_MANAGER: { - name: "ACLManager", - path: "ACLManager/@aave/core-v3/contracts/protocol/configuration/ACLManager.sol", - address: AaveV3Ethereum.ACL_MANAGER, - }, - DEFAULT_A_TOKEN_IMPL: { - name: "AToken", - path: "AToken/@aave/core-v3/contracts/protocol/tokenization/AToken.sol", - address: AaveV3Ethereum.DEFAULT_A_TOKEN_IMPL_REV_1, - }, - DEFAULT_VARIABLE_DEBT_TOKEN_IMPL: { - name: "VariableDebtToken", - path: "VariableDebtToken/@aave/core-v3/contracts/protocol/tokenization/VariableDebtToken.sol", - address: AaveV3Ethereum.DEFAULT_VARIABLE_DEBT_TOKEN_IMPL_REV_1, - }, - DEFAULT_STABLE_DEBT_TOKEN_IMPL: { - name: "StableDebtToken", - path: "StableDebtToken/@aave/core-v3/contracts/protocol/tokenization/StableDebtToken.sol", - address: AaveV3Ethereum.DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_1, - }, - WETH_GATEWAY: { - name: "WrappedTokenGatewayV3", - path: "WrappedTokenGatewayV3/src/contracts/WrappedTokenGatewayV3.sol", - address: AaveV3Ethereum.WETH_GATEWAY, - }, - UI_POOL_DATA_PROVIDER: { - name: "UiPoolDataProviderV3", - path: "UiPoolDataProviderV3/src/periphery/contracts/misc/UiPoolDataProviderV3.sol", - address: AaveV3Ethereum.UI_POOL_DATA_PROVIDER, - }, - CONFIG_ENGINE: { - name: "AaveV3ConfigEngine", - path: "AaveV3ConfigEngine/src/periphery/contracts/v3-config-engine/AaveV3ConfigEngine.sol", - address: AaveV3Ethereum.CONFIG_ENGINE, - }, - REPAY_WITH_COLLATERAL_ADAPTER: { - name: "ParaSwapRepayAdapter", - path: "ParaSwapRepayAdapter/@aave/periphery-v3/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol", - address: AaveV3Ethereum.REPAY_WITH_COLLATERAL_ADAPTER, - }, - WITHDRAW_SWAP_ADAPTER: { - name: "ParaSwapWithdrawSwapAdapter", - path: "ParaSwapWithdrawSwapAdapter/@aave/periphery-v3/contracts/adapters/paraswap/ParaSwapWithdrawSwapAdapter.sol", - address: AaveV3Ethereum.WITHDRAW_SWAP_ADAPTER, - }, - SWAP_COLLATERAL_ADAPTER: { - name: "ParaSwapLiquiditySwapAdapter", - path: "ParaSwapLiquiditySwapAdapter/@aave/periphery-v3/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol", - address: AaveV3Ethereum.SWAP_COLLATERAL_ADAPTER, - }, - STATIC_A_TOKEN_FACTORY: { - name: "StaticATokenFactory", - path: "StaticATokenFactory/src/StaticATokenFactory.sol", - address: AaveV3Ethereum.STATIC_A_TOKEN_FACTORY, - }, - }, - ETHERFI: { - POOL_ADDRESSES_PROVIDER: { - name: "PoolAddressesProvider", - path: "PoolAddressesProvider/src/core/contracts/protocol/configuration/PoolAddressesProvider.sol", - address: AaveV3EthereumEtherFi.POOL_ADDRESSES_PROVIDER, - }, - POOL: { - name: "Pool", - path: "PoolInstance/src/core/instances/PoolInstance.sol", - address: AaveV3EthereumEtherFi.POOL, - }, - POOL_CONFIGURATOR: { - name: "PoolConfigurator", - path: "PoolConfiguratorInstance/lib/aave-v3-origin/src/core/instances/PoolConfiguratorInstance.sol", - address: AaveV3EthereumEtherFi.POOL_CONFIGURATOR, - }, - ORACLE: { - name: "AaveOracle", - path: "AaveOracle/src/core/contracts/misc/AaveOracle.sol", - address: AaveV3EthereumEtherFi.ORACLE, - }, - AAVE_PROTOCOL_DATA_PROVIDER: { - name: "AaveProtocolDataProvider", - path: "AaveProtocolDataProvider/src/core/contracts/misc/AaveProtocolDataProvider.sol", - address: AaveV3EthereumEtherFi.AAVE_PROTOCOL_DATA_PROVIDER, - }, - ACL_MANAGER: { - name: "ACLManager", - path: "ACLManager/src/core/contracts/protocol/configuration/ACLManager.sol", - address: AaveV3EthereumEtherFi.ACL_MANAGER, - }, - DEFAULT_A_TOKEN_IMPL: { - name: "AToken", - path: "ATokenInstance/src/core/instances/ATokenInstance.sol", - address: AaveV3EthereumEtherFi.DEFAULT_A_TOKEN_IMPL_REV_1, - }, - DEFAULT_VARIABLE_DEBT_TOKEN_IMPL: { - name: "VariableDebtToken", - path: "VariableDebtTokenInstance/src/core/instances/VariableDebtTokenInstance.sol", - address: AaveV3EthereumEtherFi.DEFAULT_VARIABLE_DEBT_TOKEN_IMPL_REV_1, - }, - DEFAULT_STABLE_DEBT_TOKEN_IMPL: { - name: "StableDebtToken", - path: "StableDebtTokenInstance/src/core/instances/StableDebtTokenInstance.sol", - address: AaveV3EthereumEtherFi.DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_1, - }, - WETH_GATEWAY: { - name: "WrappedTokenGatewayV3", - path: "WrappedTokenGatewayV3/src/periphery/contracts/misc/WrappedTokenGatewayV3.sol", - address: AaveV3EthereumEtherFi.WETH_GATEWAY, - }, - UI_POOL_DATA_PROVIDER: { - name: "UiPoolDataProviderV3", - path: "UiPoolDataProviderV3/src/periphery/contracts/misc/UiPoolDataProviderV3.sol", - address: AaveV3EthereumEtherFi.UI_POOL_DATA_PROVIDER, - }, - CONFIG_ENGINE: { - name: "AaveV3ConfigEngine", - path: "AaveV3ConfigEngine/src/periphery/contracts/v3-config-engine/AaveV3ConfigEngine.sol", - address: AaveV3EthereumEtherFi.CONFIG_ENGINE, - }, - REPAY_WITH_COLLATERAL_ADAPTER: { - name: "ParaSwapRepayAdapter", - path: "ParaSwapRepayAdapter/src/periphery/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol", - address: AaveV3EthereumEtherFi.REPAY_WITH_COLLATERAL_ADAPTER, - }, - WITHDRAW_SWAP_ADAPTER: { - name: "ParaSwapWithdrawSwapAdapter", - path: "ParaSwapWithdrawSwapAdapter/src/periphery/contracts/adapters/paraswap/ParaSwapWithdrawSwapAdapter.sol", - address: AaveV3EthereumEtherFi.WITHDRAW_SWAP_ADAPTER, - }, - SWAP_COLLATERAL_ADAPTER: { - name: "ParaSwapLiquiditySwapAdapter", - path: "ParaSwapLiquiditySwapAdapter/src/periphery/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol", - address: AaveV3EthereumEtherFi.SWAP_COLLATERAL_ADAPTER, - }, - STATIC_A_TOKEN_FACTORY: { - name: "StaticATokenFactory", - path: "StaticATokenFactory/src/periphery/contracts/static-a-token/StaticATokenFactory.sol", - address: AaveV3EthereumEtherFi.STATIC_A_TOKEN_FACTORY, - }, - }, -}; - -const PROXIES = [ - "DEFAULT_INCENTIVES_CONTROLLER", - "POOL", - "POOL_CONFIGURATOR", - "L2_POOL", - "COLLECTOR", - "STATIC_A_TOKEN_FACTORY", -]; - -const CHAIN_ID = { - MAINNET: 1, - ETHERFI: 1, -}; - -export { CONTRACTS, PROXIES, CHAIN_ID }; diff --git a/package.json b/package.json index 0d1f5438..c151c49a 100644 --- a/package.json +++ b/package.json @@ -18,16 +18,10 @@ "homepage": "https://github.com/aave-dao/aave-v3-origin#readme", "type": "module", "devDependencies": { - "@types/bluebird": "^3.5.38", - "@types/node-fetch": "^2.6.3", - "bluebird": "^3.7.2", - "ethers": "^6.6.2", "prettier": "^2.8.3", - "prettier-plugin-solidity": "^1.1.1", - "typescript": "^5.1.6" + "prettier-plugin-solidity": "^1.1.1" }, "dependencies": { - "@bgd-labs/aave-address-book": "^3.2.1", "@bgd-labs/aave-cli": "^0.16.2", "catapulta-verify": "^1.1.1" }