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

fix: adds v3 ethereum protocol addresses. adds patch to take into acc… #49

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ export const pools: Pool[] = [
FAUCET: "0xC52eA1F19C22E5a3725105BC0cf4988614e84D98",
},
},
{
name: "AaveV3Ethereum",
chainId: ChainId.mainnet,
addressProvider: "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e",
version: 3,
additionalAddresses: {
WETH_GATEWAY: "0x694d4cFdaeE639239df949b6E24Ff8576A00d1f2",
EMISSION_MANAGER: "0xcAA448c8066f741C3137cEa9758dF3fB377CBF4E",
COLLECTOR_CONTROLLER: "0x3d569673dAa0575c936c7c67c4E6AedA69CC630C",
COLLECTOR: "0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c",
DEFAULT_VARIABLE_DEBT_TOKEN_IMPL_REV_1: "0x801934c604aBA0C8C46454c67F88A4a45a766a91",
DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_1: "0x2688a209086Ae56e7b3598Ec68A0Cba3B965CD06",
DEFAULT_A_TOKEN_IMPL_REV_1: "0xca21517bac12053E7fD6C326EDF89C5cc60d813f",
DEFAULT_INCENTIVES_CONTROLLER: "0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb"

},
},
].map((m) => ({
...m,
// fix checksum
Expand Down
5 changes: 4 additions & 1 deletion scripts/generator_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import lendingPoolV2ABI from "./abi/lending_pool_v2_abi.json";
import aTokenV2ABI from "./abi/aToken_v2_abi.json";
import collectorV2ABI from "./abi/collector_v2_abi.json";
import prettier from "prettier";
import { generateAdditionalAddresses } from "./helpers";
import {generateAdditionalAddresses, generateAdditionalAddressesSol} from "./helpers";

export interface PoolV2WithAddresses extends Pool {
lendingPool: string;
Expand Down Expand Up @@ -106,6 +106,9 @@ export async function generatePoolV2(pool: Pool): Promise<PoolV2WithAddresses> {
address internal constant COLLECTOR = ${collector};

address internal constant COLLECTOR_CONTROLLER = ${collectorController};

${generateAdditionalAddressesSol(pool)}

}\r\n`;
fs.writeFileSync(
`./src/${pool.name}.sol`,
Expand Down
240 changes: 157 additions & 83 deletions scripts/generator_v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rewardsControllerABI from "./abi/rewardsController_v3_abi.json";
import prettier from "prettier";
import {
bytes32toAddress,
generateAdditionalAddresses,
generateAdditionalAddresses, generateAdditionalAddressesSol,
getImplementationStorageSlot,
sleep,
} from "./helpers";
Expand Down Expand Up @@ -51,80 +51,84 @@ export async function generatePoolV3(pool: Pool): Promise<PoolV3WithAddresses> {
pool.provider
);
const reserves: string[] = await lendingPoolContract.getReservesList();
const data = await lendingPoolContract.getReserveData(reserves[0]);

/**
* While the reserve treasury address is per token in most cases it will be the same address, so for the sake of the address-book we assume it always is.
*/
const aTokenContract = new ethers.Contract(
data.aTokenAddress,
aTokenV3ABI,
pool.provider
);
if (reserves.length > 0) {
const data = await lendingPoolContract.getReserveData(reserves[0]);

/**
* While the reserve treasury address is per token in most cases it will be the same address, so for the sake of the address-book we assume it always is.
*/
const aTokenContract = new ethers.Contract(
data.aTokenAddress,
aTokenV3ABI,
pool.provider
);

const collector = await aTokenContract.RESERVE_TREASURY_ADDRESS();
const collector = await aTokenContract.RESERVE_TREASURY_ADDRESS();

const defaultIncentivesController =
await aTokenContract.getIncentivesController();
const defaultIncentivesController =
await aTokenContract.getIncentivesController();

const defaultATokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(pool.provider, data.aTokenAddress)
);

const aTokenRevision = await aTokenContract.ATOKEN_REVISION();
const defaultATokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(pool.provider, data.aTokenAddress)
);

await sleep(1000);
const aTokenRevision = await aTokenContract.ATOKEN_REVISION();

const defaultVariableDebtTokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(
pool.provider,
data.variableDebtTokenAddress
)
);
await sleep(1000);

const variableDebtTokenRevision = await new ethers.Contract(
data.variableDebtTokenAddress,
variableDebtTokenV3ABI,
pool.provider
).DEBT_TOKEN_REVISION();
const defaultVariableDebtTokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(
pool.provider,
data.variableDebtTokenAddress
)
);

const defaultStableDebtTokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(
pool.provider,
data.stableDebtTokenAddress
)
);
const variableDebtTokenRevision = await new ethers.Contract(
data.variableDebtTokenAddress,
variableDebtTokenV3ABI,
pool.provider
).DEBT_TOKEN_REVISION();

const stableDebtTokenRevision = await new ethers.Contract(
data.stableDebtTokenAddress,
stableDebtTokenV3ABI,
pool.provider
).DEBT_TOKEN_REVISION();
const defaultStableDebtTokenImplementation = bytes32toAddress(
await getImplementationStorageSlot(
pool.provider,
data.stableDebtTokenAddress
)
);

const collectorContract = new ethers.Contract(
collector,
collectorV3ABI,
pool.provider
);
const stableDebtTokenRevision = await new ethers.Contract(
data.stableDebtTokenAddress,
stableDebtTokenV3ABI,
pool.provider
).DEBT_TOKEN_REVISION();

let emissionManager = "0x0000000000000000000000000000000000000000";
try {
const incentivesControllerContract = await new ethers.Contract(
defaultIncentivesController,
rewardsControllerABI,
const collectorContract = new ethers.Contract(
collector,
collectorV3ABI,
pool.provider
);
emissionManager = await incentivesControllerContract.getEmissionManager();
} catch (e) {
console.log(
`old version of incentives controller deployed on ${pool.name}`
);
}

const collectorController = await collectorContract.getFundsAdmin();
console.timeEnd(pool.name);
let emissionManager = "0x0000000000000000000000000000000000000000";
try {
const incentivesControllerContract = await new ethers.Contract(
defaultIncentivesController,
rewardsControllerABI,
pool.provider
);
emissionManager = await incentivesControllerContract.getEmissionManager();
} catch (e) {
console.log(
`old version of incentives controller deployed on ${pool.name}`
);
}

const collectorController = await collectorContract.getFundsAdmin();


console.timeEnd(pool.name);

const templateV3 = `// SPDX-License-Identifier: MIT

const templateV3 = `// SPDX-License-Identifier: MIT
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;

Expand Down Expand Up @@ -164,13 +168,16 @@ export async function generatePoolV3(pool: Pool): Promise<PoolV3WithAddresses> {
address internal constant DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_${stableDebtTokenRevision} = ${defaultStableDebtTokenImplementation};

address internal constant EMISSION_MANAGER = ${emissionManager};

${generateAdditionalAddressesSol(pool)}

}\r\n`;
fs.writeFileSync(
`./src/${pool.name}.sol`,
prettier.format(templateV3, { filepath: `./src/${pool.name}.sol` })
);
fs.writeFileSync(
`./src/${pool.name}.sol`,
prettier.format(templateV3, {filepath: `./src/${pool.name}.sol`})
);

const templateV3Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
const templateV3Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
export const POOL_ADDRESSES_PROVIDER = "${addressProvider}";
export const POOL = "${poolAddress}";
export const POOL_CONFIGURATOR = "${poolConfigurator}";
Expand All @@ -187,24 +194,91 @@ export const DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_${stableDebtTokenRevision} = "${
export const CHAIN_ID = ${pool.chainId};
export const EMISSION_MANAGER = "${emissionManager}";
${generateAdditionalAddresses(pool)}`;
fs.writeFileSync(
`./src/ts/${pool.name}.ts`,
prettier.format(templateV3Js, {
filepath: `./src/ts/${pool.name}.ts`,
})
);
fs.writeFileSync(
`./src/ts/${pool.name}.ts`,
prettier.format(templateV3Js, {
filepath: `./src/ts/${pool.name}.ts`,
})
);

return {
pool: poolAddress,
poolConfigurator,
oracle,
aclAdmin,
aclManager,
poolDataProvider,
collectorController,
collector,
...pool,
};
} else {
console.timeEnd(pool.name);

const templateV3 = `// SPDX-License-Identifier: MIT
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;

import {IPoolAddressesProvider, IPool, IPoolConfigurator, IAaveOracle, IPoolDataProvider, IACLManager, ICollector} from "./AaveV3.sol";

library ${pool.name} {
IPoolAddressesProvider internal constant POOL_ADDRESSES_PROVIDER =
IPoolAddressesProvider(
${addressProvider}
);

IPool internal constant POOL =
IPool(${poolAddress});

IPoolConfigurator internal constant POOL_CONFIGURATOR =
IPoolConfigurator(${poolConfigurator});

IAaveOracle internal constant ORACLE =
IAaveOracle(${oracle});

IPoolDataProvider internal constant AAVE_PROTOCOL_DATA_PROVIDER = IPoolDataProvider(${poolDataProvider});

IACLManager internal constant ACL_MANAGER = IACLManager(${aclManager});

return {
pool: poolAddress,
poolConfigurator,
oracle,
aclAdmin,
aclManager,
poolDataProvider,
collectorController,
collector,
...pool,
};
address internal constant ACL_ADMIN = ${aclAdmin};

${generateAdditionalAddressesSol(pool)}

}\r\n`;
fs.writeFileSync(
`./src/${pool.name}.sol`,
prettier.format(templateV3, {filepath: `./src/${pool.name}.sol`})
);

const templateV3Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
export const POOL_ADDRESSES_PROVIDER = "${addressProvider}";
export const POOL = "${poolAddress}";
export const POOL_CONFIGURATOR = "${poolConfigurator}";
export const ORACLE = "${oracle}";
export const AAVE_PROTOCOL_DATA_PROVIDER = "${poolDataProvider}";
export const ACL_MANAGER = "${aclManager}";
export const ACL_ADMIN = "${aclAdmin}";
export const CHAIN_ID = ${pool.chainId};
${generateAdditionalAddresses(pool)}`;
fs.writeFileSync(
`./src/ts/${pool.name}.ts`,
prettier.format(templateV3Js, {
filepath: `./src/ts/${pool.name}.ts`,
})
);

return {
pool: poolAddress,
poolConfigurator,
oracle,
aclAdmin,
aclManager,
poolDataProvider,
collectorController: '',
collector: '',
...pool,
};
}
} catch (error: any) {
throw new Error(
JSON.stringify({ message: error.message, pool, stack: error.stack })
Expand Down
12 changes: 12 additions & 0 deletions scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ export const generateAdditionalAddresses = (pool: Pool): string => {
return "";
};

export const generateAdditionalAddressesSol = (pool: Pool): string => {
if (pool.additionalAddresses) {
return Object.keys(pool.additionalAddresses).reduce((acc, key) => {
acc += `address internal constant ${key} = ${
pool.additionalAddresses![key as keyof typeof pool.additionalAddresses]
};\r\n`;
return acc;
}, "");
}
return "";
};

export async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
1 change: 1 addition & 0 deletions src/AaveAddressBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {AaveV3Fantom} from "./AaveV3Fantom.sol";
import {AaveV3Harmony} from "./AaveV3Harmony.sol";
import {AaveV3Optimism} from "./AaveV3Optimism.sol";
import {AaveV3OptimismGoerli} from "./AaveV3OptimismGoerli.sol";
import {AaveV3Ethereum} from "./AaveV3Ethereum.sol";

import {AaveGovernanceV2, IGovernanceStrategy} from "./AaveGovernanceV2.sol";
import {IAaveEcosystemReserveController, AaveMisc} from "./AaveMisc.sol";
7 changes: 7 additions & 0 deletions src/AaveV2Avalanche.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ library AaveV2Avalanche {
0x467b92aF281d14cB6809913AD016a607b5ba8A36;

address internal constant COLLECTOR_CONTROLLER = address(0);

address internal constant WETH_GATEWAY =
0xC27d4dBefc2C0CE57916a699971b58a3BD9C7d5b;
address internal constant SWAP_COLLATERAL_ADAPTER =
0x2EcF2a2e74B19Aab2a62312167aFF4B78E93B6C5;
address internal constant REPAY_WITH_COLLATERAL_ADAPTER =
0x935b362EE3E1f342cc48118C528AAbee5118F6e6;
}
7 changes: 7 additions & 0 deletions src/AaveV2Ethereum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ library AaveV2Ethereum {

address internal constant COLLECTOR_CONTROLLER =
0x3d569673dAa0575c936c7c67c4E6AedA69CC630C;

address internal constant WETH_GATEWAY =
0xEFFC18fC3b7eb8E676dac549E0c693ad50D1Ce31;
address internal constant REPAY_WITH_COLLATERAL_ADAPTER =
0x80Aca0C645fEdABaa20fd2Bf0Daf57885A309FE6;
address internal constant SWAP_COLLATERAL_ADAPTER =
0x135896DE8421be2ec868E0b811006171D9df802A;
}
7 changes: 7 additions & 0 deletions src/AaveV2EthereumAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ library AaveV2EthereumAMM {

address internal constant COLLECTOR_CONTROLLER =
0x3d569673dAa0575c936c7c67c4E6AedA69CC630C;

address internal constant WETH_GATEWAY =
0x1C4a4e31231F71Fc34867D034a9E68f6fC798249;
address internal constant WALLET_BALANCE_PROVIDER =
0x8E8dAd5409E0263a51C0aB5055dA66Be28cFF922;
address internal constant UI_POOL_DATA_PROVIDER =
0x30375522F67a6308630d49A694ca1491fA2D3BC6;
}
Loading