mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Tentative fix in init-helpers for light deployment
This commit is contained in:
parent
57996bd5b8
commit
221c19c910
|
@ -12,6 +12,7 @@ import {
|
||||||
getAToken,
|
getAToken,
|
||||||
getATokensAndRatesHelper,
|
getATokensAndRatesHelper,
|
||||||
getLendingPoolAddressesProvider,
|
getLendingPoolAddressesProvider,
|
||||||
|
getLendingPoolConfiguratorProxy,
|
||||||
getStableAndVariableTokensHelper,
|
getStableAndVariableTokensHelper,
|
||||||
} from './contracts-getters';
|
} from './contracts-getters';
|
||||||
import { rawInsertContractAddressInDb } from './contracts-helpers';
|
import { rawInsertContractAddressInDb } from './contracts-helpers';
|
||||||
|
@ -26,6 +27,7 @@ import {
|
||||||
import { ZERO_ADDRESS } from './constants';
|
import { ZERO_ADDRESS } from './constants';
|
||||||
import { isZeroAddress } from 'ethereumjs-util';
|
import { isZeroAddress } from 'ethereumjs-util';
|
||||||
import { addGas } from '../gas-tracker';
|
import { addGas } from '../gas-tracker';
|
||||||
|
import { getTreasuryAddress } from './configuration';
|
||||||
|
|
||||||
const chooseATokenDeployment = (id: eContractid) => {
|
const chooseATokenDeployment = (id: eContractid) => {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
@ -77,11 +79,32 @@ export const initReservesByHelper = async (
|
||||||
let reserveInitDecimals: string[] = [];
|
let reserveInitDecimals: string[] = [];
|
||||||
let reserveSymbols: string[] = [];
|
let reserveSymbols: string[] = [];
|
||||||
|
|
||||||
|
// TEST START
|
||||||
|
let initInputParams: {
|
||||||
|
aTokenImpl: string,
|
||||||
|
stableDebtTokenImpl: string,
|
||||||
|
variableDebtTokenImpl: string,
|
||||||
|
underlyingAssetDecimals: BigNumberish,
|
||||||
|
interestRateStrategyAddress: string,
|
||||||
|
underlyingAsset: string,
|
||||||
|
treasury: string,
|
||||||
|
incentivesController: string,
|
||||||
|
underlyingAssetName: string,
|
||||||
|
aTokenName: string,
|
||||||
|
aTokenSymbol: string,
|
||||||
|
variableDebtTokenName: string,
|
||||||
|
variableDebtTokenSymbol: string,
|
||||||
|
stableDebtTokenName: string,
|
||||||
|
stableDebtTokenSymbol: string,
|
||||||
|
}[] = [];
|
||||||
|
// TEST END
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`- Token deployments in ${reservesChunks.length * 2} txs instead of ${
|
`- Token deployments in ${reservesChunks.length * 2} txs instead of ${
|
||||||
Object.entries(reservesParams).length * 4
|
Object.entries(reservesParams).length * 4
|
||||||
} txs`
|
} txs`
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let reservesChunk of reservesChunks) {
|
for (let reservesChunk of reservesChunks) {
|
||||||
// Prepare data
|
// Prepare data
|
||||||
const tokens: string[] = [];
|
const tokens: string[] = [];
|
||||||
|
@ -95,7 +118,7 @@ export const initReservesByHelper = async (
|
||||||
BigNumberish
|
BigNumberish
|
||||||
][] = [];
|
][] = [];
|
||||||
const reservesDecimals: string[] = [];
|
const reservesDecimals: string[] = [];
|
||||||
// TEST
|
// TEST START
|
||||||
const inputParams: {
|
const inputParams: {
|
||||||
asset: string,
|
asset: string,
|
||||||
rates: [
|
rates: [
|
||||||
|
@ -107,7 +130,7 @@ export const initReservesByHelper = async (
|
||||||
BigNumberish
|
BigNumberish
|
||||||
]
|
]
|
||||||
}[] = [];
|
}[] = [];
|
||||||
// TEST
|
// TEST END
|
||||||
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
|
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
|
||||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||||
(value) => value === assetSymbol
|
(value) => value === assetSymbol
|
||||||
|
@ -143,7 +166,7 @@ export const initReservesByHelper = async (
|
||||||
]);
|
]);
|
||||||
reservesDecimals.push(reserveDecimals);
|
reservesDecimals.push(reserveDecimals);
|
||||||
|
|
||||||
// TEST
|
// TEST START
|
||||||
inputParams.push({
|
inputParams.push({
|
||||||
asset: tokenAddress,
|
asset: tokenAddress,
|
||||||
rates: [
|
rates: [
|
||||||
|
@ -155,7 +178,7 @@ export const initReservesByHelper = async (
|
||||||
stableRateSlope2
|
stableRateSlope2
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
// TEST
|
// TEST END
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx1 and tx2 gas is accounted for later.
|
// tx1 and tx2 gas is accounted for later.
|
||||||
|
@ -181,7 +204,7 @@ export const initReservesByHelper = async (
|
||||||
console.log(' * gasUsed: debtTokens batch', tx1.gasUsed.toString());
|
console.log(' * gasUsed: debtTokens batch', tx1.gasUsed.toString());
|
||||||
console.log(' * gasUsed: aTokens and Strategy batch', tx2.gasUsed.toString());
|
console.log(' * gasUsed: aTokens and Strategy batch', tx2.gasUsed.toString());
|
||||||
gasUsage = gasUsage.add(tx1.gasUsed).add(tx2.gasUsed);
|
gasUsage = gasUsage.add(tx1.gasUsed).add(tx2.gasUsed);
|
||||||
addGas(gasUsage);
|
|
||||||
const stableTokens: string[] = tx1.events?.map((e) => e.args?.stableToken) || [];
|
const stableTokens: string[] = tx1.events?.map((e) => e.args?.stableToken) || [];
|
||||||
const variableTokens: string[] = tx1.events?.map((e) => e.args?.variableToken) || [];
|
const variableTokens: string[] = tx1.events?.map((e) => e.args?.variableToken) || [];
|
||||||
const aTokens: string[] = tx2.events?.map((e) => e.args?.aToken) || [];
|
const aTokens: string[] = tx2.events?.map((e) => e.args?.aToken) || [];
|
||||||
|
@ -196,6 +219,29 @@ export const initReservesByHelper = async (
|
||||||
reserveSymbols = [...reserveSymbols, ...symbols];
|
reserveSymbols = [...reserveSymbols, ...symbols];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEST START
|
||||||
|
for (let i = 0; i < deployedATokens.length; i ++) {
|
||||||
|
initInputParams.push({
|
||||||
|
aTokenImpl: deployedATokens[i],
|
||||||
|
stableDebtTokenImpl: deployedStableTokens[i],
|
||||||
|
variableDebtTokenImpl: deployedVariableTokens[i],
|
||||||
|
underlyingAssetDecimals: reserveInitDecimals[i],
|
||||||
|
interestRateStrategyAddress: deployedRates[i],
|
||||||
|
underlyingAsset: reserveTokens[i],
|
||||||
|
treasury: treasuryAddress,
|
||||||
|
incentivesController: ZERO_ADDRESS,
|
||||||
|
underlyingAssetName: reserveSymbols[i],
|
||||||
|
aTokenName: `Aave Interest Bearing ${reserveSymbols[i]}`,
|
||||||
|
aTokenSymbol: `a${reserveSymbols[i]}`,
|
||||||
|
variableDebtTokenName: `Aave Variable Debt ${reserveSymbols[i]}`,
|
||||||
|
variableDebtTokenSymbol: `variableDebt${reserveSymbols[i]}`,
|
||||||
|
stableDebtTokenName: `Aave Stable Debt ${reserveSymbols[i]}`,
|
||||||
|
stableDebtTokenSymbol: `stableDebt${reserveSymbols[i]}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// TEST END
|
||||||
|
|
||||||
|
|
||||||
// Deploy delegated aware reserves tokens
|
// Deploy delegated aware reserves tokens
|
||||||
const delegatedAwareReserves = Object.entries(reservesParams).filter(
|
const delegatedAwareReserves = Object.entries(reservesParams).filter(
|
||||||
([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken
|
([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken
|
||||||
|
@ -273,24 +319,34 @@ export const initReservesByHelper = async (
|
||||||
const chunkedDecimals = chunk(reserveInitDecimals, initChunks);
|
const chunkedDecimals = chunk(reserveInitDecimals, initChunks);
|
||||||
const chunkedSymbols = chunk(reserveSymbols, initChunks);
|
const chunkedSymbols = chunk(reserveSymbols, initChunks);
|
||||||
|
|
||||||
|
// TEST START
|
||||||
|
const configurator = await getLendingPoolConfiguratorProxy();
|
||||||
|
await waitForTx(await addressProvider.setPoolAdmin(admin));
|
||||||
|
|
||||||
|
const chunkedInitInputParams = chunk(initInputParams, initChunks);
|
||||||
|
// TEST END
|
||||||
console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`);
|
console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`);
|
||||||
for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) {
|
for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) {
|
||||||
const tx3 = await waitForTx(
|
const tx3 = await waitForTx(
|
||||||
await atokenAndRatesDeployer.initReserve(
|
// await atokenAndRatesDeployer.initReserve(
|
||||||
chunkedStableTokens[chunkIndex],
|
// chunkedStableTokens[chunkIndex],
|
||||||
chunkedVariableTokens[chunkIndex],
|
// chunkedVariableTokens[chunkIndex],
|
||||||
chunkedAtokens[chunkIndex],
|
// chunkedAtokens[chunkIndex],
|
||||||
chunkedRates[chunkIndex],
|
// chunkedRates[chunkIndex],
|
||||||
chunkedDecimals[chunkIndex]
|
// chunkedDecimals[chunkIndex]
|
||||||
)
|
// )
|
||||||
|
await configurator.batchInitReserve(chunkedInitInputParams[chunkIndex])
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`);
|
console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`);
|
||||||
console.log(' * gasUsed', tx3.gasUsed.toString());
|
console.log(' * gasUsed', tx3.gasUsed.toString());
|
||||||
gasUsage = gasUsage.add(tx3.gasUsed);
|
gasUsage = gasUsage.add(tx3.gasUsed);
|
||||||
}
|
}
|
||||||
|
addGas(gasUsage);
|
||||||
|
|
||||||
// Set deployer back as admin
|
// Set deployer back as admin
|
||||||
|
addGas(await addressProvider.estimateGas.setPoolAdmin(admin));
|
||||||
await waitForTx(await addressProvider.setPoolAdmin(admin));
|
await waitForTx(await addressProvider.setPoolAdmin(admin));
|
||||||
return gasUsage;
|
return gasUsage;
|
||||||
};
|
};
|
||||||
|
@ -337,7 +393,7 @@ export const configureReservesByHelper = async (
|
||||||
const liquidationBonuses: string[] = [];
|
const liquidationBonuses: string[] = [];
|
||||||
const reserveFactors: string[] = [];
|
const reserveFactors: string[] = [];
|
||||||
const stableRatesEnabled: boolean[] = [];
|
const stableRatesEnabled: boolean[] = [];
|
||||||
// TEST
|
// TEST START
|
||||||
const inputParams : {
|
const inputParams : {
|
||||||
asset: string;
|
asset: string;
|
||||||
baseLTV: BigNumberish;
|
baseLTV: BigNumberish;
|
||||||
|
@ -346,7 +402,7 @@ export const configureReservesByHelper = async (
|
||||||
reserveFactor: BigNumberish;
|
reserveFactor: BigNumberish;
|
||||||
stableBorrowingEnabled: boolean;
|
stableBorrowingEnabled: boolean;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
// TEST
|
// TEST END
|
||||||
|
|
||||||
for (const [
|
for (const [
|
||||||
assetSymbol,
|
assetSymbol,
|
||||||
|
@ -376,7 +432,7 @@ export const configureReservesByHelper = async (
|
||||||
}
|
}
|
||||||
// Push data
|
// Push data
|
||||||
|
|
||||||
// TEST
|
// TEST START
|
||||||
inputParams.push({
|
inputParams.push({
|
||||||
asset: tokenAddress,
|
asset: tokenAddress,
|
||||||
baseLTV: baseLTVAsCollateral,
|
baseLTV: baseLTVAsCollateral,
|
||||||
|
@ -385,7 +441,7 @@ export const configureReservesByHelper = async (
|
||||||
reserveFactor: reserveFactor,
|
reserveFactor: reserveFactor,
|
||||||
stableBorrowingEnabled: stableBorrowRateEnabled
|
stableBorrowingEnabled: stableBorrowRateEnabled
|
||||||
});
|
});
|
||||||
// TEST
|
// TEST END
|
||||||
|
|
||||||
tokens.push(tokenAddress);
|
tokens.push(tokenAddress);
|
||||||
symbols.push(assetSymbol);
|
symbols.push(assetSymbol);
|
||||||
|
@ -410,9 +466,9 @@ export const configureReservesByHelper = async (
|
||||||
const chunkedReserveFactors = chunk(reserveFactors, enableChunks);
|
const chunkedReserveFactors = chunk(reserveFactors, enableChunks);
|
||||||
const chunkedStableRatesEnabled = chunk(stableRatesEnabled, enableChunks);
|
const chunkedStableRatesEnabled = chunk(stableRatesEnabled, enableChunks);
|
||||||
|
|
||||||
// TEST
|
// TEST START
|
||||||
const chunkedInputParams = chunk(inputParams, enableChunks);
|
const chunkedInputParams = chunk(inputParams, enableChunks);
|
||||||
// TEST
|
// TEST END
|
||||||
|
|
||||||
|
|
||||||
console.log(`- Configure reserves in ${chunkedTokens.length} txs`);
|
console.log(`- Configure reserves in ${chunkedTokens.length} txs`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user