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 1 commit
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
11 changes: 10 additions & 1 deletion scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export enum ChainId {
}

const RPC_PROVIDERS = {
[ChainId.mainnet]: "https://rpc.flashbots.net",
[ChainId.mainnet]: 'https://rpc.tenderly.co/fork/1e8e167f-4a45-4ac5-8ce1-4045b07a0faf',//"https://rpc.flashbots.net",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is the rationale of this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to get the addresses on the v3.0.1 deployed on tenderly.

[ChainId.goerli]: "https://eth-goerli.public.blastapi.io",
[ChainId.mumbai]: "https://polygon-testnet.public.blastapi.io",
[ChainId.polygon]: "https://polygon-rpc.com",
Expand Down Expand Up @@ -289,6 +289,15 @@ export const pools: Pool[] = [
FAUCET: "0xC52eA1F19C22E5a3725105BC0cf4988614e84D98",
},
},
{
name: "AaveV3Ethereum",
chainId: ChainId.mainnet,
addressProvider: "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e",
version: 3,
// additionalAddresses: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need added here all the extra addresses that are on deployment but we cant bia rpc right now

// WETH_GATEWAY: "0x6f7f2440006221F893c587b88f01afc42B6F8d2e",
// },
},
].map((m) => ({
...m,
// fix checksum
Expand Down
233 changes: 151 additions & 82 deletions scripts/generator_v3.ts
Original file line number Diff line number Diff line change
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 @@ -165,12 +169,12 @@ export async function generatePoolV3(pool: Pool): Promise<PoolV3WithAddresses> {

address internal constant EMISSION_MANAGER = ${emissionManager};
}\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 +191,89 @@ 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;

return {
pool: poolAddress,
poolConfigurator,
oracle,
aclAdmin,
aclManager,
poolDataProvider,
collectorController,
collector,
...pool,
};
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});

address internal constant ACL_ADMIN = ${aclAdmin};

}\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
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";
28 changes: 28 additions & 0 deletions src/AaveV3Ethereum.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 AaveV3Ethereum {
IPoolAddressesProvider internal constant POOL_ADDRESSES_PROVIDER =
IPoolAddressesProvider(0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e);

IPool internal constant POOL =
IPool(0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2);

IPoolConfigurator internal constant POOL_CONFIGURATOR =
IPoolConfigurator(0x64b761D848206f447Fe2dd461b0c635Ec39EbB27);

IAaveOracle internal constant ORACLE =
IAaveOracle(0x54586bE62E3c3580375aE3723C145253060Ca0C2);

IPoolDataProvider internal constant AAVE_PROTOCOL_DATA_PROVIDER =
IPoolDataProvider(0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3);

IACLManager internal constant ACL_MANAGER =
IACLManager(0xc2aaCf6553D20d1e9d78E365AAba8032af9c85b0);

address internal constant ACL_ADMIN =
0xEE56e2B3D491590B5b31738cC34d5232F378a8D5;
}
1 change: 1 addition & 0 deletions src/ts/AaveAddressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * as AaveV3Fantom from "./AaveV3Fantom";
export * as AaveV3Harmony from "./AaveV3Harmony";
export * as AaveV3Optimism from "./AaveV3Optimism";
export * as AaveV3OptimismGoerli from "./AaveV3OptimismGoerli";
export * as AaveV3Ethereum from "./AaveV3Ethereum";
11 changes: 11 additions & 0 deletions src/ts/AaveV3Ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// AUTOGENERATED - DON'T MANUALLY CHANGE
export const POOL_ADDRESSES_PROVIDER =
"0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e";
export const POOL = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2";
export const POOL_CONFIGURATOR = "0x64b761D848206f447Fe2dd461b0c635Ec39EbB27";
export const ORACLE = "0x54586bE62E3c3580375aE3723C145253060Ca0C2";
export const AAVE_PROTOCOL_DATA_PROVIDER =
"0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3";
export const ACL_MANAGER = "0xc2aaCf6553D20d1e9d78E365AAba8032af9c85b0";
export const ACL_ADMIN = "0xEE56e2B3D491590B5b31738cC34d5232F378a8D5";
export const CHAIN_ID = 1;