Skip to content

Commit

Permalink
feat: aave misc js exports (#210)
Browse files Browse the repository at this point in the history
* feat: misc js exports

* fix: generator and some cleanup

* fix: missing import
  • Loading branch information
brotherlymite authored Aug 24, 2023
1 parent a220f6a commit 4112844
Show file tree
Hide file tree
Showing 18 changed files with 993 additions and 715 deletions.
82 changes: 82 additions & 0 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,42 @@ export interface Token {
variableDebtTokenAddress: Hex;
}

export interface Misc {
ECOSYSTEM_RESERVE: Hex;
AAVE_ECOSYSTEM_RESERVE_CONTROLLER: Hex;
TRANSPARENT_PROXY_FACTORY_ETHEREUM: Hex;
PROXY_ADMIN_ETHEREUM: Hex;
PROXY_ADMIN_ETHEREUM_LONG: Hex;
TRANSPARENT_PROXY_FACTORY_POLYGON: Hex;
PROXY_ADMIN_POLYGON: Hex;
TRANSPARENT_PROXY_FACTORY_AVALANCHE: Hex;
PROXY_ADMIN_AVALANCHE: Hex;
TRANSPARENT_PROXY_FACTORY_OPTIMISM: Hex;
PROXY_ADMIN_OPTIMISM: Hex;
TRANSPARENT_PROXY_FACTORY_ARBITRUM: Hex;
PROXY_ADMIN_ARBITRUM: Hex;
TRANSPARENT_PROXY_FACTORY_METIS: Hex;
PROXY_ADMIN_METIS: Hex;
}

export interface GovernanceV2 {
GOV: Hex;
GOV_STRATEGY: Hex;
SHORT_EXECUTOR: Hex;
LONG_EXECUTOR: Hex;
ARC_TIMELOCK: Hex;
POLYGON_BRIDGE_EXECUTOR: Hex;
OPTIMISM_BRIDGE_EXECUTOR: Hex;
ARBITRUM_BRIDGE_EXECUTOR: Hex;
METIS_BRIDGE_EXECUTOR: Hex;
BASE_BRIDGE_EXECUTOR: Hex;
CROSSCHAIN_FORWARDER_POLYGON: Hex;
CROSSCHAIN_FORWARDER_OPTIMISM: Hex;
CROSSCHAIN_FORWARDER_ARBITRUM: Hex;
CROSSCHAIN_FORWARDER_METIS: Hex;
CROSSCHAIN_FORWARDER_BASE: Hex;
}

export const pools = [
{
name: 'AaveV2Ethereum',
Expand Down Expand Up @@ -685,3 +721,49 @@ export const pools = [
return acc;
}, {} as {[key: string]: Hex}) as Pool['additionalAddresses'],
})) as Pool[];

export const governanceV2 = Object.fromEntries(
Object.entries(
{
GOV: '0xEC568fffba86c094cf06b22134B23074DFE2252c',
GOV_STRATEGY: '0xb7e383ef9B1E9189Fc0F71fb30af8aa14377429e',
SHORT_EXECUTOR: '0xEE56e2B3D491590B5b31738cC34d5232F378a8D5',
LONG_EXECUTOR: '0x79426A1c24B2978D90d7A5070a46C65B07bC4299',
ARC_TIMELOCK: '0xAce1d11d836cb3F51Ef658FD4D353fFb3c301218',
POLYGON_BRIDGE_EXECUTOR: '0xdc9A35B16DB4e126cFeDC41322b3a36454B1F772',
OPTIMISM_BRIDGE_EXECUTOR: '0x7d9103572bE58FfE99dc390E8246f02dcAe6f611',
ARBITRUM_BRIDGE_EXECUTOR: '0x7d9103572bE58FfE99dc390E8246f02dcAe6f611',
METIS_BRIDGE_EXECUTOR: '0x8EC77963068474a45016938Deb95E603Ca82a029',
BASE_BRIDGE_EXECUTOR: '0xA9F30e6ED4098e9439B2ac8aEA2d3fc26BcEbb45',
CROSSCHAIN_FORWARDER_POLYGON: '0x158a6bC04F0828318821baE797f50B0A1299d45b',
CROSSCHAIN_FORWARDER_OPTIMISM: '0x5f5C02875a8e9B5A26fbd09040ABCfDeb2AA6711',
CROSSCHAIN_FORWARDER_ARBITRUM: '0xd1B3E25fD7C8AE7CADDC6F71b461b79CD4ddcFa3',
CROSSCHAIN_FORWARDER_METIS: '0x2fE52eF191F0BE1D98459BdaD2F1d3160336C08f',
CROSSCHAIN_FORWARDER_BASE: '0x3215225538da1546FE0DA88ee13019f402078942'
} as GovernanceV2
).map(
([key, value]) => [key, getAddress(value)]
)
) as unknown as GovernanceV2;

export const misc = Object.fromEntries(Object.entries(
{
ECOSYSTEM_RESERVE: '0x25F2226B597E8F9514B3F68F00f494cF4f286491',
AAVE_ECOSYSTEM_RESERVE_CONTROLLER: '0x3d569673dAa0575c936c7c67c4E6AedA69CC630C',
TRANSPARENT_PROXY_FACTORY_ETHEREUM: '0xB4e496f70602fE2AC6Ae511D028BA4D194773B29',
PROXY_ADMIN_ETHEREUM: '0xD3cF979e676265e4f6379749DECe4708B9A22476',
PROXY_ADMIN_ETHEREUM_LONG: '0x86C3FfeE349A7cFf7cA88C449717B1b133bfb517',
TRANSPARENT_PROXY_FACTORY_POLYGON: '0xB4e496f70602fE2AC6Ae511D028BA4D194773B29',
PROXY_ADMIN_POLYGON: '0xD3cF979e676265e4f6379749DECe4708B9A22476',
TRANSPARENT_PROXY_FACTORY_AVALANCHE: '0xB4e496f70602fE2AC6Ae511D028BA4D194773B29',
PROXY_ADMIN_AVALANCHE: '0xD3cF979e676265e4f6379749DECe4708B9A22476',
TRANSPARENT_PROXY_FACTORY_OPTIMISM: '0xB4e496f70602fE2AC6Ae511D028BA4D194773B29',
PROXY_ADMIN_OPTIMISM: '0xD3cF979e676265e4f6379749DECe4708B9A22476',
TRANSPARENT_PROXY_FACTORY_ARBITRUM: '0xB4e496f70602fE2AC6Ae511D028BA4D194773B29',
PROXY_ADMIN_ARBITRUM: '0xD3cF979e676265e4f6379749DECe4708B9A22476',
TRANSPARENT_PROXY_FACTORY_METIS: '0x1dad86dC5990BCE5bFe3A150A4E0ece990d6EBcB',
PROXY_ADMIN_METIS: '0x1CabD986cBAbDf12E00128DFf03C80ee62C4fd97',
TRANSPARENT_PROXY_FACTORY_BASE: '0x05225Cd708bCa9253789C1374e4337a019e99D56',
PROXY_ADMIN_BASE: '0xc85b1E333aecc99340b2320493Fe2d22b8734795',
} as Misc
).map(([key, value]) => [key, getAddress(value)])) as unknown as Misc;
16 changes: 8 additions & 8 deletions scripts/generateAssetsLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ export function appendAssetsLibraryJs(name: string, reserves: ReserveData[]) {
const templateV3Assets = reserves
.map((reserve) => {
const symbol = fixSymbol(reserve.symbol, reserve.underlyingAsset);
let result = `export const ${name}Assets_${symbol}_UNDERLYING = "${reserve.underlyingAsset}";
export const ${name}Assets_${symbol}_A_TOKEN = "${reserve.aTokenAddress}";
export const ${name}Assets_${symbol}_V_TOKEN = "${reserve.variableDebtTokenAddress}";
export const ${name}Assets_${symbol}_S_TOKEN = "${reserve.stableDebtTokenAddress}";
export const ${name}Assets_${symbol}_ORACLE = "${reserve.priceOracle}";
export const ${name}Assets_${symbol}_INTEREST_RATE_STRATEGY = "${reserve.interestRateStrategyAddress}";`;
let result = `export const ${name}Assets_${symbol}_UNDERLYING = '${reserve.underlyingAsset}';
export const ${name}Assets_${symbol}_A_TOKEN = '${reserve.aTokenAddress}';
export const ${name}Assets_${symbol}_V_TOKEN = '${reserve.variableDebtTokenAddress}';
export const ${name}Assets_${symbol}_S_TOKEN = '${reserve.stableDebtTokenAddress}';
export const ${name}Assets_${symbol}_ORACLE = '${reserve.priceOracle}';
export const ${name}Assets_${symbol}_INTEREST_RATE_STRATEGY = '${reserve.interestRateStrategyAddress}';`;
if (reserve.staticATokenAddress && reserve.staticATokenAddress != zeroAddress)
result += ` export const ${name}Assets_${symbol}_STATA_TOKEN = "${reserve.staticATokenAddress}";`;
result += ` export const ${name}Assets_${symbol}_STATA_TOKEN = '${reserve.staticATokenAddress}';`;
return result;
})
.join('\n\n');
fs.writeFileSync(`./src/ts/${name}Assets.ts`, templateV3Assets);
fs.appendFileSync(
`./src/ts/AaveAddressBook.ts`,
`export * as ${name}Assets from "./${name}Assets";\r\n`
`export * as ${name}Assets from './${name}Assets';\r\n`
);
}
27 changes: 19 additions & 8 deletions scripts/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'fs';

import {Pool, pools} from './config';
import {Pool, pools, governanceV2, GovernanceV2, misc, Misc} from './config';
import {PoolV2WithAddresses, fetchPoolV2Addresses, writeV2Templates} from './generator_v2';
import {PoolV3WithAddresses, fetchPoolV3Addresses, writeV3Templates} from './generator_v3';
import {writeGovV2Templates} from './generator_gov_v2';
import {writeMiscTemplates} from './generator_misc';

async function generateV2Pools(pools: Pool[]) {
let generatedPools: PoolV2WithAddresses[] = [];
Expand Down Expand Up @@ -36,16 +38,24 @@ async function generateV3Pools(pools: Pool[]) {
});
}

generatedPools.map((addresses) => writeV3Templates(addresses));
return generatedPools.map((addresses) => writeV3Templates(addresses));
}

async function generatePools() {
async function generateGovernanceV2(governanceV2: GovernanceV2) {
return writeGovV2Templates(governanceV2);
}

async function generateMisc(misc: Misc) {
return writeMiscTemplates(misc);
}

async function generateAddresses() {
// Create the test for the specified pool
const aaveAddressBookSolidityTemplate = `// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
${pools.reduce((acc, pool) => {
acc += `import {${pool.name}} from "./${pool.name}.sol";\r\n`;
acc += `import {${pool.name}} from './${pool.name}.sol';\r\n`;
return acc;
}, '')}
Expand All @@ -54,19 +64,20 @@ import {IAaveEcosystemReserveController, AaveMisc} from './AaveMisc.sol';
\r\n`;
fs.writeFileSync(`./src/AaveAddressBook.sol`, aaveAddressBookSolidityTemplate);

const aaveAddressBookJsTemplate = `export * as AaveGovernanceV2 from "./AaveGovernanceV2";
export * as AaveSafetyModule from "./AaveSafetyModule";
const aaveAddressBookJsTemplate = `export * as AaveSafetyModule from './AaveSafetyModule';
// autogenerated entrypoints\n`;
fs.writeFileSync(`./src/ts/AaveAddressBook.ts`, aaveAddressBookJsTemplate);
await Promise.all([
generateV2Pools(pools.filter((pool) => pool.version === 2)),
generateV3Pools(pools.filter((pool) => pool.version === 3)),
generateGovernanceV2(governanceV2),
generateMisc(misc)
]);
}

generatePools()
generateAddresses()
.then(() => {
console.log('pools successfully generated');
console.log('addresses successfully generated');
process.exit(0);
})
.catch((error) => {
Expand Down
29 changes: 29 additions & 0 deletions scripts/generator_gov_v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as fs from 'fs';
import {
generateGovV2Addresses,
generateGovV2AddressesSol,
} from './helpers';
import {GovernanceV2} from './config';

export function writeGovV2Templates(govV2Addresses: GovernanceV2): void {
const templateGovV2Solidity = `// SPDX-License-Identifier: MIT
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;
import {IGovernanceStrategy} from './common/IGovernanceStrategy.sol';
import {IAaveGovernanceV2} from './common/IAaveGovernanceV2.sol';
library AaveGovernanceV2 {
${generateGovV2AddressesSol(govV2Addresses)}
}
`;

fs.writeFileSync(`./src/AaveGovernanceV2.sol`, templateGovV2Solidity);

const templateGovV2Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
${generateGovV2Addresses(govV2Addresses)}`;

fs.writeFileSync(`./src/ts/AaveGovernanceV2.ts`, templateGovV2Js);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as AaveGovernanceV2 from './AaveGovernanceV2';\r\n`);
}
28 changes: 28 additions & 0 deletions scripts/generator_misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as fs from 'fs';
import {
generateMiscAddressesSol,
generateMiscAddresses,
} from './helpers';
import {Misc} from './config';

export function writeMiscTemplates(miscAddresses: Misc): void {
const templateGovV2Solidity = `// SPDX-License-Identifier: MIT
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;
import {IAaveEcosystemReserveController} from './common/IAaveEcosystemReserveController.sol';
import {IStreamable} from './common/IStreamable.sol';
library AaveMisc {
${generateMiscAddressesSol(miscAddresses)}
}
`;

fs.writeFileSync(`./src/AaveMisc.sol`, templateGovV2Solidity);

const templateGovV2Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
${generateMiscAddresses(miscAddresses)}`;

fs.writeFileSync(`./src/ts/AaveMisc.ts`, templateGovV2Js);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as AaveMisc from './AaveMisc';\r\n`);
}
28 changes: 14 additions & 14 deletions scripts/generator_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export function writeV2Templates({
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;
import {ILendingPoolAddressesProvider, ILendingPool, ILendingPoolConfigurator, IAaveOracle, IAaveProtocolDataProvider, ILendingRateOracle} from "./AaveV2.sol";
import {ICollector} from "./common/ICollector.sol";
import {ILendingPoolAddressesProvider, ILendingPool, ILendingPoolConfigurator, IAaveOracle, IAaveProtocolDataProvider, ILendingRateOracle} from './AaveV2.sol';
import {ICollector} from './common/ICollector.sol';
library ${name} {
ILendingPoolAddressesProvider internal constant POOL_ADDRESSES_PROVIDER =
Expand Down Expand Up @@ -195,21 +195,21 @@ export function writeV2Templates({
}

const templateV2Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
export const POOL_ADDRESSES_PROVIDER = "${addressProvider}";
export const POOL = "${lendingPool}";
export const POOL_CONFIGURATOR = "${lendingPoolConfigurator}";
export const LENDING_RATE_ORACLE = "${lendingRateOracle}";
export const ORACLE = "${oracle}";
export const AAVE_PROTOCOL_DATA_PROVIDER = "${poolDataProvider}";
export const POOL_ADMIN = "${admin}";
export const EMERGENCY_ADMIN = "${emergencyAdmin}";
export const COLLECTOR = "${collector}";
export const DEFAULT_INCENTIVES_CONTROLLER = "${defaultIncentivesController}";
export const EMISSION_MANAGER = "${emissionManager}";
export const POOL_ADDRESSES_PROVIDER = '${addressProvider}';
export const POOL = '${lendingPool}';
export const POOL_CONFIGURATOR = '${lendingPoolConfigurator}';
export const LENDING_RATE_ORACLE = '${lendingRateOracle}';
export const ORACLE = '${oracle}';
export const AAVE_PROTOCOL_DATA_PROVIDER = '${poolDataProvider}';
export const POOL_ADMIN = '${admin}';
export const EMERGENCY_ADMIN = '${emergencyAdmin}';
export const COLLECTOR = '${collector}';
export const DEFAULT_INCENTIVES_CONTROLLER = '${defaultIncentivesController}';
export const EMISSION_MANAGER = '${emissionManager}';
export const CHAIN_ID = ${chainId};
${generateAdditionalAddresses(additionalAddresses)}`;
fs.writeFileSync(`./src/ts/${name}.ts`, templateV2Js);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as ${name} from "./${name}";\r\n`);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as ${name} from './${name}';\r\n`);

if (reservesData.length) {
appendAssetsLibraryJs(name, reservesData);
Expand Down
34 changes: 17 additions & 17 deletions scripts/generator_v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ export function writeV3Templates({
// AUTOGENERATED - DON'T MANUALLY CHANGE
pragma solidity >=0.6.0;
import {IPoolAddressesProvider, IPool, IPoolConfigurator, IAaveOracle, IPoolDataProvider, IACLManager} from "./AaveV3.sol";
import {ICollector} from "./common/ICollector.sol";
import {IPoolAddressesProvider, IPool, IPoolConfigurator, IAaveOracle, IPoolDataProvider, IACLManager} from './AaveV3.sol';
import {ICollector} from './common/ICollector.sol';
library ${name} {
IPoolAddressesProvider internal constant POOL_ADDRESSES_PROVIDER =
Expand Down Expand Up @@ -303,24 +303,24 @@ export function writeV3Templates({
}

const templateV3Js = `// AUTOGENERATED - DON'T MANUALLY CHANGE
export const POOL_ADDRESSES_PROVIDER = "${addressProvider}";
export const POOL = "${pool}";
export const POOL_CONFIGURATOR = "${poolConfigurator}";
export const ORACLE = "${oracle}";
export const PRICE_ORACLE_SENTINEL = "${oracleSentinel}";
export const AAVE_PROTOCOL_DATA_PROVIDER = "${poolDataProvider}";
export const ACL_MANAGER = "${aclManager}";
export const ACL_ADMIN = "${aclAdmin}";
export const COLLECTOR = "${collector}";
export const DEFAULT_INCENTIVES_CONTROLLER = "${defaultIncentivesController}";
export const DEFAULT_A_TOKEN_IMPL_REV_${aTokenRevision} = "${defaultATokenImplementation}";
export const DEFAULT_VARIABLE_DEBT_TOKEN_IMPL_REV_${variableDebtTokenRevision} = "${defaultVariableDebtTokenImplementation}";
export const DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_${stableDebtTokenRevision} = "${defaultStableDebtTokenImplementation}";
export const POOL_ADDRESSES_PROVIDER = '${addressProvider}';
export const POOL = '${pool}';
export const POOL_CONFIGURATOR = '${poolConfigurator}';
export const ORACLE = '${oracle}';
export const PRICE_ORACLE_SENTINEL = '${oracleSentinel}';
export const AAVE_PROTOCOL_DATA_PROVIDER = '${poolDataProvider}';
export const ACL_MANAGER = '${aclManager}';
export const ACL_ADMIN = '${aclAdmin}';
export const COLLECTOR = '${collector}';
export const DEFAULT_INCENTIVES_CONTROLLER = '${defaultIncentivesController}';
export const DEFAULT_A_TOKEN_IMPL_REV_${aTokenRevision} = '${defaultATokenImplementation}';
export const DEFAULT_VARIABLE_DEBT_TOKEN_IMPL_REV_${variableDebtTokenRevision} = '${defaultVariableDebtTokenImplementation}';
export const DEFAULT_STABLE_DEBT_TOKEN_IMPL_REV_${stableDebtTokenRevision} = '${defaultStableDebtTokenImplementation}';
export const CHAIN_ID = ${chainId};
export const EMISSION_MANAGER = "${emissionManager}";
export const EMISSION_MANAGER = '${emissionManager}';
${generateAdditionalAddresses(additionalAddresses)}`;
fs.writeFileSync(`./src/ts/${name}.ts`, templateV3Js);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as ${name} from "./${name}";\r\n`);
fs.appendFileSync(`./src/ts/AaveAddressBook.ts`, `export * as ${name} from './${name}';\r\n`);

if (reservesData.length) {
appendAssetsLibraryJs(name, reservesData);
Expand Down
Loading

0 comments on commit 4112844

Please sign in to comment.