mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Support custom aToken deployments
This commit is contained in:
parent
2231452bac
commit
4034c75536
|
@ -288,7 +288,7 @@ export const deployMintableDelegationERC20 = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
export const deployDefaultReserveInterestRateStrategy = async (
|
export const deployDefaultReserveInterestRateStrategy = async (
|
||||||
args: [tEthereumAddress, string, string, string, string, string],
|
args: [tEthereumAddress, string, string, string, string, string, string],
|
||||||
verify: boolean
|
verify: boolean
|
||||||
) =>
|
) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types';
|
import { eContractid, iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types';
|
||||||
import { AaveProtocolDataProvider } from '../types/AaveProtocolDataProvider';
|
import { AaveProtocolDataProvider } from '../types/AaveProtocolDataProvider';
|
||||||
import { chunk, waitForTx } from './misc-utils';
|
import { chunk, waitForTx } from './misc-utils';
|
||||||
import {
|
import {
|
||||||
|
@ -11,11 +11,23 @@ import { BigNumberish } from 'ethers';
|
||||||
import {
|
import {
|
||||||
deployDefaultReserveInterestRateStrategy,
|
deployDefaultReserveInterestRateStrategy,
|
||||||
deployDelegationAwareAToken,
|
deployDelegationAwareAToken,
|
||||||
|
deployGenericAToken,
|
||||||
deployStableDebtToken,
|
deployStableDebtToken,
|
||||||
deployVariableDebtToken,
|
deployVariableDebtToken,
|
||||||
} from './contracts-deployments';
|
} from './contracts-deployments';
|
||||||
import { ZERO_ADDRESS } from './constants';
|
import { ZERO_ADDRESS } from './constants';
|
||||||
|
|
||||||
|
const chooseATokenDeployment = (id: eContractid) => {
|
||||||
|
switch (id) {
|
||||||
|
case eContractid.AToken:
|
||||||
|
return deployGenericAToken;
|
||||||
|
case eContractid.DelegationAwareAToken:
|
||||||
|
return deployDelegationAwareAToken;
|
||||||
|
default:
|
||||||
|
throw Error(`Missing aToken deployment script for: ${id}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const initReservesByHelper = async (
|
export const initReservesByHelper = async (
|
||||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||||
tokenAddresses: { [symbol: string]: tEthereumAddress },
|
tokenAddresses: { [symbol: string]: tEthereumAddress },
|
||||||
|
@ -36,9 +48,11 @@ export const initReservesByHelper = async (
|
||||||
const tokensChunks = 4;
|
const tokensChunks = 4;
|
||||||
const initChunks = 6;
|
const initChunks = 6;
|
||||||
|
|
||||||
// Deploy tokens and rates in chunks
|
// Deploy tokens and rates that uses common aToken in chunks
|
||||||
const reservesChunks = chunk(
|
const reservesChunks = chunk(
|
||||||
Object.entries(reservesParams) as [string, IReserveParams][],
|
Object.entries(reservesParams).filter(
|
||||||
|
([_, { aTokenImpl }]) => aTokenImpl === eContractid.AToken
|
||||||
|
) as [string, IReserveParams][],
|
||||||
tokensChunks
|
tokensChunks
|
||||||
);
|
);
|
||||||
// Initialize variables for future reserves initialization
|
// Initialize variables for future reserves initialization
|
||||||
|
@ -70,10 +84,6 @@ export const initReservesByHelper = async (
|
||||||
const reservesDecimals: string[] = [];
|
const reservesDecimals: string[] = [];
|
||||||
|
|
||||||
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
|
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
|
||||||
// Skip UNI due is aDelegatedToken
|
|
||||||
if (assetSymbol === 'UNI') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||||
(value) => value === assetSymbol
|
(value) => value === assetSymbol
|
||||||
);
|
);
|
||||||
|
@ -146,43 +156,56 @@ export const initReservesByHelper = async (
|
||||||
reserveSymbols = [...reserveSymbols, ...symbols];
|
reserveSymbols = [...reserveSymbols, ...symbols];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy UNI token due is delegated aToken
|
// Deploy delegated aware reserves tokens
|
||||||
if (tokenAddresses.UNI) {
|
const delegatedAwareReserves = Object.entries(reservesParams).filter(
|
||||||
console.log(' - Deploy UNI delegated aToken, debts tokens, and strategy');
|
([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken
|
||||||
|
) as [string, IReserveParams][];
|
||||||
|
|
||||||
|
for (let [symbol, params] of delegatedAwareReserves) {
|
||||||
|
console.log(` - Deploy ${symbol} delegation await aToken, debts tokens, and strategy`);
|
||||||
const {
|
const {
|
||||||
|
optimalUtilizationRate,
|
||||||
baseVariableBorrowRate,
|
baseVariableBorrowRate,
|
||||||
variableRateSlope1,
|
variableRateSlope1,
|
||||||
variableRateSlope2,
|
variableRateSlope2,
|
||||||
stableRateSlope1,
|
stableRateSlope1,
|
||||||
stableRateSlope2,
|
stableRateSlope2,
|
||||||
} = reservesParams.UNI;
|
} = params;
|
||||||
const aTokenUNI = await deployDelegationAwareAToken(
|
const deployCustomAToken = chooseATokenDeployment(params.aTokenImpl);
|
||||||
[poolAddress, tokenAddresses.UNI, 'Aave interest bearing UNI', 'aUNI', ZERO_ADDRESS],
|
const aToken = await deployCustomAToken(
|
||||||
verify
|
|
||||||
);
|
|
||||||
const stableDebtUNI = await deployStableDebtToken(
|
|
||||||
[
|
[
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenAddresses.UNI,
|
tokenAddresses[symbol],
|
||||||
'Aave stable debt bearing UNI',
|
`Aave interest bearing ${symbol}`,
|
||||||
'stableDebtUNI',
|
`a${symbol}`,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
],
|
],
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
const variableDebtUNI = await deployVariableDebtToken(
|
const stableDebt = await deployStableDebtToken(
|
||||||
[
|
[
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenAddresses.UNI,
|
tokenAddresses[symbol],
|
||||||
'Aave variable debt bearing UNI',
|
`Aave stable debt bearing ${symbol}`,
|
||||||
'variableDebtUNI',
|
`stableDebt${symbol}`,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
],
|
],
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
const ratesUNI = await deployDefaultReserveInterestRateStrategy(
|
const variableDebt = await deployVariableDebtToken(
|
||||||
[
|
[
|
||||||
tokenAddresses.UNI,
|
poolAddress,
|
||||||
|
tokenAddresses[symbol],
|
||||||
|
`Aave variable debt bearing ${symbol}`,
|
||||||
|
`variableDebt${symbol}`,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
],
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
const rates = await deployDefaultReserveInterestRateStrategy(
|
||||||
|
[
|
||||||
|
tokenAddresses[symbol],
|
||||||
|
optimalUtilizationRate,
|
||||||
baseVariableBorrowRate,
|
baseVariableBorrowRate,
|
||||||
variableRateSlope1,
|
variableRateSlope1,
|
||||||
variableRateSlope2,
|
variableRateSlope2,
|
||||||
|
@ -192,13 +215,13 @@ export const initReservesByHelper = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
deployedStableTokens.push(stableDebtUNI.address);
|
deployedStableTokens.push(stableDebt.address);
|
||||||
deployedVariableTokens.push(variableDebtUNI.address);
|
deployedVariableTokens.push(variableDebt.address);
|
||||||
deployedATokens.push(aTokenUNI.address);
|
deployedATokens.push(aToken.address);
|
||||||
deployedRates.push(ratesUNI.address);
|
deployedRates.push(rates.address);
|
||||||
reserveInitDecimals.push(reservesParams.UNI.reserveDecimals);
|
reserveInitDecimals.push(params.reserveDecimals);
|
||||||
reserveTokens.push(tokenAddresses.UNI);
|
reserveTokens.push(tokenAddresses[symbol]);
|
||||||
reserveSymbols.push('UNI');
|
reserveSymbols.push(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy init reserves per chunks
|
// Deploy init reserves per chunks
|
||||||
|
|
|
@ -260,7 +260,9 @@ export enum TokenContractId {
|
||||||
ENJ = 'ENJ',
|
ENJ = 'ENJ',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {}
|
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
|
||||||
|
aTokenImpl: eContractid;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IReserveBorrowParams {
|
export interface IReserveBorrowParams {
|
||||||
optimalUtilizationRate: string;
|
optimalUtilizationRate: string;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import {oneRay} from '../../helpers/constants';
|
import { oneRay } from '../../helpers/constants';
|
||||||
import {IReserveParams} from '../../helpers/types';
|
import { eContractid, IReserveParams } from '../../helpers/types';
|
||||||
|
|
||||||
export const strategyBase: IReserveParams = {
|
export const strategyBase: IReserveParams = {
|
||||||
optimalUtilizationRate: new BigNumber(0.8).multipliedBy(oneRay).toFixed(),
|
optimalUtilizationRate: new BigNumber(0.8).multipliedBy(oneRay).toFixed(),
|
||||||
|
@ -15,6 +15,7 @@ export const strategyBase: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stablecoinStrategyBase: IReserveParams = {
|
export const stablecoinStrategyBase: IReserveParams = {
|
||||||
|
@ -30,6 +31,7 @@ export const stablecoinStrategyBase: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stablecoinStrategyCentralized: IReserveParams = {
|
export const stablecoinStrategyCentralized: IReserveParams = {
|
||||||
|
@ -45,6 +47,7 @@ export const stablecoinStrategyCentralized: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '6',
|
reserveDecimals: '6',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyGovernanceTokens: IReserveParams = {
|
export const strategyGovernanceTokens: IReserveParams = {
|
||||||
|
@ -132,6 +135,7 @@ export const stablecoinStrategySUSD: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: false,
|
stableBorrowRateEnabled: false,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategySNX: IReserveParams = {
|
export const strategySNX: IReserveParams = {
|
||||||
|
@ -159,6 +163,7 @@ export const stablecoinStrategyTUSD: IReserveParams = {
|
||||||
export const strategyUNI: IReserveParams = {
|
export const strategyUNI: IReserveParams = {
|
||||||
...strategyGovernanceTokens,
|
...strategyGovernanceTokens,
|
||||||
stableBorrowRateEnabled: false,
|
stableBorrowRateEnabled: false,
|
||||||
|
aTokenImpl: eContractid.DelegationAwareAToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stablecoinStrategyUSDC: IReserveParams = {
|
export const stablecoinStrategyUSDC: IReserveParams = {
|
||||||
|
@ -190,6 +195,7 @@ export const strategyWBTC: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '8',
|
reserveDecimals: '8',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyWETH: IReserveParams = {
|
export const strategyWETH: IReserveParams = {
|
||||||
|
@ -205,6 +211,7 @@ export const strategyWETH: IReserveParams = {
|
||||||
borrowingEnabled: true,
|
borrowingEnabled: true,
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
|
aTokenImpl: eContractid.AToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyYFI: IReserveParams = {
|
export const strategyYFI: IReserveParams = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user