-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: - The eMode exports on the js side now contain the full eMode configuration with the decoded bitmaps. - abis are exported via /abis to no longer mix with the addresses - removing tokenlist from ts exports as there's no good reason to use it from here (integrations work with the toplevel json)
- Loading branch information
Showing
91 changed files
with
3,570 additions
and
8,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as addressBook from '../../src/ts/AaveAddressBook'; | ||
|
||
export function getGovernance(chainId: number) { | ||
for (const [name, lib] of Object.entries(addressBook)) { | ||
if (name.startsWith('GovernanceV3') && lib.CHAIN_ID === chainId) return lib; | ||
} | ||
} | ||
|
||
export function getMisc(chainId: number) { | ||
for (const [name, lib] of Object.entries(addressBook)) { | ||
if (name.startsWith('Misc') && lib.CHAIN_ID === chainId) return lib; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {getContract} from 'viem'; | ||
import {CHAIN_ID_CLIENT_MAP} from '../clients'; | ||
import {IOwnable_ABI} from '../../src/ts/abis/IOwnable'; | ||
import {getGovernance} from './utils'; | ||
|
||
export async function check(addresses: Record<string, any>) { | ||
if (addresses.WETH_GATEWAY) { | ||
const client = CHAIN_ID_CLIENT_MAP[addresses.CHAIN_ID]; | ||
// on testnets owners are usually not governance | ||
if (!client.chain?.testnet) { | ||
const gateway = getContract({ | ||
abi: IOwnable_ABI, | ||
address: addresses.WETH_GATEWAY, | ||
client, | ||
}); | ||
const owner = await gateway.read.owner(); | ||
const governance = getGovernance(addresses.CHAIN_ID); | ||
if (!governance) { | ||
console.log( | ||
'SANITY_GATEWAY: Skipped due to missing governance on chainId: ${addresses.CHAIN_ID}', | ||
); | ||
} else { | ||
const l1Executor = (governance as any).EXECUTOR_LVL_1; | ||
// prettier would be to check against executor lvl_1 | ||
if (owner !== l1Executor) { | ||
throw new Error( | ||
`SANITY_GATEWAY: OWNER MISMATCH ${addresses.POOL}.${addresses.WETH_GATEWAY}:${owner} != ${l1Executor}`, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
scripts/generator/protocol-v2-generator/fetchPoolAddresses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {Address, Client, getContract, zeroAddress} from 'viem'; | ||
import {PoolConfig} from '../../configs/types'; | ||
import {bytes32toAddress, getImplementationStorageSlot} from '../utils'; | ||
import {ILendingPoolAddressesProvider_ABI} from '../../../src/ts/abis/ILendingPoolAddressesProvider'; | ||
import {mainnetAmmV2Pool} from '../../configs/pools/ethereum'; | ||
|
||
export async function fetchPoolAddresses(client: Client, poolConfig: PoolConfig) { | ||
const addressProviderContract = getContract({ | ||
address: poolConfig.POOL_ADDRESSES_PROVIDER, | ||
abi: ILendingPoolAddressesProvider_ABI, | ||
client, | ||
}); | ||
|
||
const [ | ||
POOL, | ||
LENDING_RATE_ORACLE, | ||
POOL_CONFIGURATOR, | ||
ORACLE, | ||
POOL_ADMIN, | ||
EMERGENCY_ADMIN, | ||
AAVE_PROTOCOL_DATA_PROVIDER, | ||
LENDING_POOL_COLLATERAL_MANAGER, | ||
] = await Promise.all([ | ||
addressProviderContract.read.getLendingPool(), | ||
addressProviderContract.read.getLendingRateOracle(), | ||
addressProviderContract.read.getLendingPoolConfigurator(), | ||
addressProviderContract.read.getPriceOracle(), | ||
addressProviderContract.read.getPoolAdmin(), | ||
addressProviderContract.read.getEmergencyAdmin(), | ||
addressProviderContract.read.getAddress([ | ||
poolConfig.name === mainnetAmmV2Pool.name | ||
? '0x1000000000000000000000000000000000000000000000000000000000000000' | ||
: '0x0100000000000000000000000000000000000000000000000000000000000000', | ||
]), | ||
addressProviderContract.read.getLendingPoolCollateralManager(), | ||
]); | ||
|
||
const [POOL_IMPL, POOL_CONFIGURATOR_IMPL] = await Promise.all([ | ||
getImplementationStorageSlot(client, POOL), | ||
getImplementationStorageSlot(client, POOL_CONFIGURATOR), | ||
]); | ||
|
||
return { | ||
POOL_ADDRESSES_PROVIDER: { | ||
value: poolConfig.POOL_ADDRESSES_PROVIDER, | ||
type: 'ILendingPoolAddressesProvider', | ||
}, | ||
POOL: {value: POOL, type: 'ILendingPool'}, | ||
POOL_IMPL: bytes32toAddress(POOL_IMPL), | ||
POOL_CONFIGURATOR: { | ||
value: POOL_CONFIGURATOR, | ||
type: 'ILendingPoolConfigurator', | ||
}, | ||
POOL_CONFIGURATOR_IMPL: bytes32toAddress(POOL_CONFIGURATOR_IMPL), | ||
ORACLE: { | ||
value: ORACLE, | ||
type: 'IAaveOracle', | ||
}, | ||
LENDING_RATE_ORACLE: {value: LENDING_RATE_ORACLE, type: 'ILendingRateOracle'}, | ||
AAVE_PROTOCOL_DATA_PROVIDER: { | ||
value: AAVE_PROTOCOL_DATA_PROVIDER, | ||
type: 'IAaveProtocolDataProvider', | ||
}, | ||
LENDING_POOL_COLLATERAL_MANAGER, | ||
POOL_ADMIN, | ||
EMERGENCY_ADMIN, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {Address, Client, getContract, zeroAddress} from 'viem'; | ||
import {fetchPoolAddresses} from './fetchPoolAddresses'; | ||
import {ILendingPool_ABI} from '../../../src/ts/abis/ILendingPool'; | ||
import {ReserveData} from '../../configs/types'; | ||
import {IERC20Detailed_ABI} from '../../../src/ts/abis/IERC20Detailed'; | ||
import {IAaveOracle_ABI} from '../../../src/ts/abis/IAaveOracle'; | ||
import {A_TOKEN_V2_ABI} from '../../abi/aToken_v2_abi'; | ||
import {INCENTIVES_CONTROLLER_ABI} from '../../abi/incentivesController_abi'; | ||
|
||
export async function fetchTokens( | ||
client: Client, | ||
poolAddresses: Awaited<ReturnType<typeof fetchPoolAddresses>>, | ||
) { | ||
const poolContract = getContract({ | ||
address: poolAddresses.POOL.value, | ||
abi: ILendingPool_ABI, | ||
client, | ||
}); | ||
const reserves = await poolContract.read.getReservesList(); | ||
const oracleContract = getContract({ | ||
address: poolAddresses.ORACLE.value, | ||
abi: IAaveOracle_ABI, | ||
client, | ||
}); | ||
const reservesData: ReserveData[] = await Promise.all( | ||
reserves.map(async (reserve) => { | ||
const erc20Contract = getContract({address: reserve, abi: IERC20Detailed_ABI, client}); | ||
const [data, symbol, decimals, oracle] = await Promise.all([ | ||
poolContract.read.getReserveData([reserve]), | ||
reserve === '0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2' | ||
? 'MKR' | ||
: erc20Contract.read.symbol(), | ||
erc20Contract.read.decimals(), | ||
oracleContract.read.getSourceOfAsset([reserve]), | ||
]); | ||
return { | ||
symbol: reserve === '0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2' ? 'MKR' : symbol, | ||
decimals: decimals, | ||
id: data.id, | ||
UNDERLYING: reserve, | ||
A_TOKEN: data.aTokenAddress, | ||
V_TOKEN: data.variableDebtTokenAddress, | ||
INTEREST_RATE_STRATEGY: data.interestRateStrategyAddress, | ||
ORACLE: oracle, | ||
}; | ||
}), | ||
); | ||
return reservesData; | ||
} | ||
|
||
export async function inferAdditionalTokenInfo( | ||
client: Client, | ||
reservesData: Awaited<ReturnType<typeof fetchTokens>>, | ||
) { | ||
if (reservesData.length > 0) { | ||
const aTokenContract = getContract({ | ||
address: reservesData[0].A_TOKEN, | ||
abi: A_TOKEN_V2_ABI, | ||
client, | ||
}); | ||
const DEFAULT_INCENTIVES_CONTROLLER = await aTokenContract.read.getIncentivesController(); | ||
const COLLECTOR = await aTokenContract.read.RESERVE_TREASURY_ADDRESS(); | ||
|
||
let EMISSION_MANAGER: Address = zeroAddress; | ||
try { | ||
const incentivesControllerContract = getContract({ | ||
address: DEFAULT_INCENTIVES_CONTROLLER, | ||
abi: INCENTIVES_CONTROLLER_ABI, | ||
client, | ||
}); | ||
EMISSION_MANAGER = await incentivesControllerContract.read.EMISSION_MANAGER(); | ||
} catch (e) { | ||
console.log(`old version of incentives controller deployed`); | ||
} | ||
|
||
return { | ||
COLLECTOR: {value: COLLECTOR, type: 'ICollector'}, | ||
DEFAULT_INCENTIVES_CONTROLLER, | ||
EMISSION_MANAGER, | ||
}; | ||
} | ||
} |
Oops, something went wrong.