mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'master' into feat/118-kovan-configs
This commit is contained in:
commit
8cd474864b
|
@ -7,6 +7,8 @@ import {eEthereumNetwork} from './helpers/types';
|
|||
import {BUIDLEREVM_CHAINID, COVERAGE_CHAINID} from './helpers/buidler-constants';
|
||||
import {setDRE} from './helpers/misc-utils';
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
usePlugin('@nomiclabs/buidler-ethers');
|
||||
usePlugin('buidler-typechain');
|
||||
usePlugin('solidity-coverage');
|
||||
|
|
|
@ -163,7 +163,7 @@ export const CommonsConfig: ICommonConfiguration = {
|
|||
[eEthereumNetwork.coverage]: '',
|
||||
[eEthereumNetwork.hardhat]: '',
|
||||
[eEthereumNetwork.buidlerevm]: '',
|
||||
[eEthereumNetwork.kovan]: '0xdcde9bb6a49e37fa433990832ab541ae2d4feb4a',
|
||||
[eEthereumNetwork.kovan]: '0xdCde9Bb6a49e37fA433990832AB541AE2d4FEB4a',
|
||||
[eEthereumNetwork.ropsten]: '0x05dcca805a6562c1bdd0423768754acb6993241b',
|
||||
[eEthereumNetwork.main]: '0x4d728a4496e4de35f218d5a214366bde3a62b51c',
|
||||
},
|
||||
|
@ -307,7 +307,7 @@ export const CommonsConfig: ICommonConfiguration = {
|
|||
[eEthereumNetwork.coverage]: '',
|
||||
[eEthereumNetwork.hardhat]: '',
|
||||
[eEthereumNetwork.buidlerevm]: '',
|
||||
[eEthereumNetwork.kovan]: '0x276C4793F2EE3D5Bf18C5b879529dD4270BA4814',
|
||||
[eEthereumNetwork.kovan]: '0xB8bE51E6563BB312Cbb2aa26e352516c25c26ac1',
|
||||
[eEthereumNetwork.ropsten]: '',
|
||||
[eEthereumNetwork.main]: '',
|
||||
},
|
||||
|
|
163
contracts/misc/UiPoolDataProvider.sol
Normal file
163
contracts/misc/UiPoolDataProvider.sol
Normal file
|
@ -0,0 +1,163 @@
|
|||
// SPDX-License-Identifier: agpl-3.0
|
||||
pragma solidity ^0.6.8;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
||||
import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol';
|
||||
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
|
||||
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
|
||||
import {IAToken} from '../tokenization/interfaces/IAToken.sol';
|
||||
import {IVariableDebtToken} from '../tokenization/interfaces/IVariableDebtToken.sol';
|
||||
import {IStableDebtToken} from '../tokenization/interfaces/IStableDebtToken.sol';
|
||||
|
||||
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
|
||||
import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol';
|
||||
import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol';
|
||||
import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol';
|
||||
import {
|
||||
DefaultReserveInterestRateStrategy
|
||||
} from '../lendingpool/DefaultReserveInterestRateStrategy.sol';
|
||||
|
||||
contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||
using WadRayMath for uint256;
|
||||
using ReserveConfiguration for ReserveConfiguration.Map;
|
||||
using UserConfiguration for UserConfiguration.Map;
|
||||
|
||||
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
|
||||
|
||||
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
|
||||
internal
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256
|
||||
)
|
||||
{
|
||||
return (
|
||||
interestRateStrategy.variableRateSlope1(),
|
||||
interestRateStrategy.variableRateSlope2(),
|
||||
interestRateStrategy.stableRateSlope1(),
|
||||
interestRateStrategy.stableRateSlope2()
|
||||
);
|
||||
}
|
||||
|
||||
function getReservesData(ILendingPoolAddressesProvider provider, address user)
|
||||
external
|
||||
override
|
||||
view
|
||||
returns (
|
||||
AggregatedReserveData[] memory,
|
||||
UserReserveData[] memory,
|
||||
uint256
|
||||
)
|
||||
{
|
||||
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||
IPriceOracleGetter oracle = IPriceOracleGetter(provider.getPriceOracle());
|
||||
address[] memory reserves = lendingPool.getReservesList();
|
||||
UserConfiguration.Map memory userConfig = lendingPool.getUserConfiguration(user);
|
||||
|
||||
AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length);
|
||||
UserReserveData[] memory userReservesData = new UserReserveData[](
|
||||
user != address(0) ? reserves.length : 0
|
||||
);
|
||||
|
||||
for (uint256 i = 0; i < reserves.length; i++) {
|
||||
AggregatedReserveData memory reserveData = reservesData[i];
|
||||
reserveData.underlyingAsset = reserves[i];
|
||||
|
||||
// reserve current state
|
||||
ReserveLogic.ReserveData memory baseData = lendingPool.getReserveData(
|
||||
reserveData.underlyingAsset
|
||||
);
|
||||
reserveData.liquidityIndex = baseData.liquidityIndex;
|
||||
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
|
||||
reserveData.liquidityRate = baseData.currentLiquidityRate;
|
||||
reserveData.variableBorrowRate = baseData.currentVariableBorrowRate;
|
||||
reserveData.stableBorrowRate = baseData.currentStableBorrowRate;
|
||||
reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp;
|
||||
reserveData.aTokenAddress = baseData.aTokenAddress;
|
||||
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
|
||||
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
|
||||
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
|
||||
reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset);
|
||||
|
||||
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
|
||||
reserveData.aTokenAddress
|
||||
);
|
||||
(
|
||||
reserveData.totalPrincipalStableDebt,
|
||||
,
|
||||
reserveData.averageStableRate,
|
||||
reserveData.stableDebtLastUpdateTimestamp
|
||||
) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData();
|
||||
reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
|
||||
.scaledTotalSupply();
|
||||
|
||||
// reserve configuration
|
||||
|
||||
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
|
||||
reserveData.symbol = IERC20Detailed(reserveData.aTokenAddress).symbol();
|
||||
reserveData.name = '';
|
||||
|
||||
(
|
||||
reserveData.baseLTVasCollateral,
|
||||
reserveData.reserveLiquidationThreshold,
|
||||
reserveData.reserveLiquidationBonus,
|
||||
reserveData.decimals,
|
||||
reserveData.reserveFactor
|
||||
) = baseData.configuration.getParamsMemory();
|
||||
(
|
||||
reserveData.isActive,
|
||||
reserveData.isFrozen,
|
||||
reserveData.borrowingEnabled,
|
||||
reserveData.stableBorrowRateEnabled
|
||||
) = baseData.configuration.getFlagsMemory();
|
||||
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
|
||||
(
|
||||
reserveData.variableRateSlope1,
|
||||
reserveData.variableRateSlope2,
|
||||
reserveData.stableRateSlope1,
|
||||
reserveData.stableRateSlope2
|
||||
) = getInterestRateStrategySlopes(
|
||||
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
|
||||
);
|
||||
|
||||
if (user != address(0)) {
|
||||
// user reserve data
|
||||
userReservesData[i].underlyingAsset = reserveData.underlyingAsset;
|
||||
userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress)
|
||||
.scaledBalanceOf(user);
|
||||
userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i);
|
||||
|
||||
if (userConfig.isBorrowing(i)) {
|
||||
userReservesData[i].scaledVariableDebt = IVariableDebtToken(
|
||||
reserveData
|
||||
.variableDebtTokenAddress
|
||||
)
|
||||
.scaledBalanceOf(user);
|
||||
userReservesData[i].principalStableDebt = IStableDebtToken(
|
||||
reserveData
|
||||
.stableDebtTokenAddress
|
||||
)
|
||||
.principalBalanceOf(user);
|
||||
if (userReservesData[i].principalStableDebt != 0) {
|
||||
userReservesData[i].stableBorrowRate = IStableDebtToken(
|
||||
reserveData
|
||||
.stableDebtTokenAddress
|
||||
)
|
||||
.getUserStableRate(user);
|
||||
userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
|
||||
reserveData
|
||||
.stableDebtTokenAddress
|
||||
)
|
||||
.getUserLastUpdated(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
|
||||
}
|
||||
}
|
|
@ -96,6 +96,22 @@ contract WETHGateway is IWETHGateway, Ownable {
|
|||
if (msg.value > paybackAmount) _safeTransferETH(msg.sender, msg.value - paybackAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev borrow WETH, unwraps to ETH and send both the ETH and DebtTokens to msg.sender, via `approveDelegation` and onBehalf argument in `LendingPool.borrow`.
|
||||
* @param amount the amount of ETH to borrow
|
||||
* @param interesRateMode the interest rate mode
|
||||
* @param referralCode integrators are assigned a referral code and can potentially receive rewards
|
||||
*/
|
||||
function borrowETH(
|
||||
uint256 amount,
|
||||
uint256 interesRateMode,
|
||||
uint16 referralCode
|
||||
) external override {
|
||||
POOL.borrow(address(WETH), amount, interesRateMode, referralCode, msg.sender);
|
||||
WETH.withdraw(amount);
|
||||
_safeTransferETH(msg.sender, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev transfer ETH to an address, revert if it fails.
|
||||
* @param to recipient of the transfer
|
||||
|
|
|
@ -6,7 +6,7 @@ pragma experimental ABIEncoderV2;
|
|||
import {Address} from '../dependencies/openzeppelin/contracts/Address.sol';
|
||||
import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';
|
||||
|
||||
import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol';
|
||||
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
||||
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||
import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
|
||||
import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol';
|
||||
|
@ -24,9 +24,10 @@ contract WalletBalanceProvider {
|
|||
using SafeERC20 for IERC20;
|
||||
using ReserveConfiguration for ReserveConfiguration.Map;
|
||||
|
||||
LendingPoolAddressesProvider internal immutable _provider;
|
||||
ILendingPoolAddressesProvider internal immutable _provider;
|
||||
address constant MOCK_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
|
||||
constructor(LendingPoolAddressesProvider provider) public {
|
||||
constructor(ILendingPoolAddressesProvider provider) public {
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
|
@ -45,12 +46,13 @@ contract WalletBalanceProvider {
|
|||
- return 0 on non-contract address
|
||||
**/
|
||||
function balanceOf(address user, address token) public view returns (uint256) {
|
||||
// check if token is actually a contract
|
||||
if (token.isContract()) {
|
||||
if (token == MOCK_ETH_ADDRESS) {
|
||||
return user.balance; // ETH balance
|
||||
// check if token is actually a contract
|
||||
} else if (token.isContract()) {
|
||||
return IERC20(token).balanceOf(user);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
revert('INVALID_TOKEN');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,12 +70,7 @@ contract WalletBalanceProvider {
|
|||
|
||||
for (uint256 i = 0; i < users.length; i++) {
|
||||
for (uint256 j = 0; j < tokens.length; j++) {
|
||||
uint256 _offset = i * tokens.length;
|
||||
if (!tokens[j].isContract()) {
|
||||
revert('INVALID_TOKEN');
|
||||
} else {
|
||||
balances[_offset + j] = balanceOf(users[i], tokens[j]);
|
||||
}
|
||||
balances[i * tokens.length + j] = balanceOf(users[i], tokens[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,11 +88,16 @@ contract WalletBalanceProvider {
|
|||
ILendingPool pool = ILendingPool(_provider.getLendingPool());
|
||||
|
||||
address[] memory reserves = pool.getReservesList();
|
||||
address[] memory reservesWithEth = new address[](reserves.length + 1);
|
||||
for (uint256 i = 0; i < reserves.length; i++) {
|
||||
reservesWithEth[i] = reserves[i];
|
||||
}
|
||||
reservesWithEth[reserves.length] = MOCK_ETH_ADDRESS;
|
||||
|
||||
uint256[] memory balances = new uint256[](reserves.length);
|
||||
uint256[] memory balances = new uint256[](reservesWithEth.length);
|
||||
|
||||
for (uint256 j = 0; j < reserves.length; j++) {
|
||||
ReserveConfiguration.Map memory configuration = pool.getConfiguration(reserves[j]);
|
||||
ReserveConfiguration.Map memory configuration = pool.getConfiguration(reservesWithEth[j]);
|
||||
|
||||
(bool isActive, , , ) = configuration.getFlagsMemory();
|
||||
|
||||
|
@ -103,9 +105,10 @@ contract WalletBalanceProvider {
|
|||
balances[j] = 0;
|
||||
continue;
|
||||
}
|
||||
balances[j] = balanceOf(user, reserves[j]);
|
||||
balances[j] = balanceOf(user, reservesWithEth[j]);
|
||||
}
|
||||
balances[reservesWithEth.length] = balanceOf(user, MOCK_ETH_ADDRESS);
|
||||
|
||||
return (reserves, balances);
|
||||
return (reservesWithEth, balances);
|
||||
}
|
||||
}
|
||||
|
|
94
contracts/misc/interfaces/IUiPoolDataProvider.sol
Normal file
94
contracts/misc/interfaces/IUiPoolDataProvider.sol
Normal file
|
@ -0,0 +1,94 @@
|
|||
// SPDX-License-Identifier: agpl-3.0
|
||||
pragma solidity ^0.6.8;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
||||
import {ReserveLogic} from '../../libraries/logic/ReserveLogic.sol';
|
||||
|
||||
interface IUiPoolDataProvider {
|
||||
struct AggregatedReserveData {
|
||||
address underlyingAsset;
|
||||
string name;
|
||||
string symbol;
|
||||
uint256 decimals;
|
||||
uint256 baseLTVasCollateral;
|
||||
uint256 reserveLiquidationThreshold;
|
||||
uint256 reserveLiquidationBonus;
|
||||
uint256 reserveFactor;
|
||||
bool usageAsCollateralEnabled;
|
||||
bool borrowingEnabled;
|
||||
bool stableBorrowRateEnabled;
|
||||
bool isActive;
|
||||
bool isFrozen;
|
||||
// base data
|
||||
uint128 liquidityIndex;
|
||||
uint128 variableBorrowIndex;
|
||||
uint128 liquidityRate;
|
||||
uint128 variableBorrowRate;
|
||||
uint128 stableBorrowRate;
|
||||
uint40 lastUpdateTimestamp;
|
||||
address aTokenAddress;
|
||||
address stableDebtTokenAddress;
|
||||
address variableDebtTokenAddress;
|
||||
address interestRateStrategyAddress;
|
||||
//
|
||||
uint256 availableLiquidity;
|
||||
uint256 totalPrincipalStableDebt;
|
||||
uint256 averageStableRate;
|
||||
uint256 stableDebtLastUpdateTimestamp;
|
||||
uint256 totalScaledVariableDebt;
|
||||
uint256 priceInEth;
|
||||
uint256 variableRateSlope1;
|
||||
uint256 variableRateSlope2;
|
||||
uint256 stableRateSlope1;
|
||||
uint256 stableRateSlope2;
|
||||
}
|
||||
//
|
||||
// struct ReserveData {
|
||||
// uint256 averageStableBorrowRate;
|
||||
// uint256 totalLiquidity;
|
||||
// }
|
||||
|
||||
struct UserReserveData {
|
||||
address underlyingAsset;
|
||||
uint256 scaledATokenBalance;
|
||||
bool usageAsCollateralEnabledOnUser;
|
||||
uint256 stableBorrowRate;
|
||||
uint256 scaledVariableDebt;
|
||||
uint256 principalStableDebt;
|
||||
uint256 stableBorrowLastUpdateTimestamp;
|
||||
}
|
||||
|
||||
//
|
||||
// struct ATokenSupplyData {
|
||||
// string name;
|
||||
// string symbol;
|
||||
// uint8 decimals;
|
||||
// uint256 totalSupply;
|
||||
// address aTokenAddress;
|
||||
// }
|
||||
|
||||
function getReservesData(ILendingPoolAddressesProvider provider, address user)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
AggregatedReserveData[] memory,
|
||||
UserReserveData[] memory,
|
||||
uint256
|
||||
);
|
||||
|
||||
// function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
|
||||
// external
|
||||
// view
|
||||
// returns (UserReserveData[] memory);
|
||||
//
|
||||
// function getAllATokenSupply(ILendingPoolAddressesProvider provider)
|
||||
// external
|
||||
// view
|
||||
// returns (ATokenSupplyData[] memory);
|
||||
//
|
||||
// function getATokenSupply(address[] calldata aTokens)
|
||||
// external
|
||||
// view
|
||||
// returns (ATokenSupplyData[] memory);
|
||||
}
|
|
@ -11,4 +11,10 @@ interface IWETHGateway {
|
|||
uint256 rateMode,
|
||||
address onBehalfOf
|
||||
) external payable;
|
||||
|
||||
function borrowETH(
|
||||
uint256 amount,
|
||||
uint256 interesRateMode,
|
||||
uint16 referralCode
|
||||
) external;
|
||||
}
|
||||
|
|
|
@ -584,4 +584,4 @@
|
|||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,17 +53,6 @@ export const getReservesConfigByPool = (pool: AavePools): iMultiPoolsAssets<IRes
|
|||
pool
|
||||
);
|
||||
|
||||
export const getFeeDistributionParamsCommon = (
|
||||
receiver: tEthereumAddress
|
||||
): iBasicDistributionParams => {
|
||||
const receivers = [receiver, ZERO_ADDRESS];
|
||||
const percentages = ['2000', '8000'];
|
||||
return {
|
||||
receivers,
|
||||
percentages,
|
||||
};
|
||||
};
|
||||
|
||||
export const getGenesisPoolAdmin = async (config: ICommonConfiguration) => {
|
||||
const currentNetwork = DRE.network.name;
|
||||
const targetAddress = getParamPerNetwork(config.PoolAdmin, <eEthereumNetwork>currentNetwork);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import BigNumber from 'bignumber.js';
|
||||
import {MockTokenMap} from './contracts-helpers';
|
||||
|
||||
export interface SymbolMap<T> {
|
||||
[symbol: string]: T;
|
||||
|
@ -60,6 +59,7 @@ export enum eContractid {
|
|||
TokenDistributor = 'TokenDistributor',
|
||||
StableAndVariableTokensHelper = 'StableAndVariableTokensHelper',
|
||||
ATokensAndRatesHelper = 'ATokensAndRatesHelper',
|
||||
UiPoolDataProvider = 'UiPoolDataProvider',
|
||||
WETHGateway = 'WETHGateway',
|
||||
WETH = 'WETH',
|
||||
WETHMocked = 'WETHMocked',
|
||||
|
|
8919
package-lock.json
generated
8919
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -52,7 +52,8 @@
|
|||
"ci:clean": "rm -rf ./artifacts ./cache ./types",
|
||||
"print-contracts:kovan": "npm run hardhat:kovan -- print-contracts",
|
||||
"print-contracts:main": "npm run hardhat:main -- print-contracts",
|
||||
"print-contracts:ropsten": "npm run hardhat:main -- print-contracts"
|
||||
"print-contracts:ropsten": "npm run hardhat:main -- print-contracts",
|
||||
"dev:deployUIProvider": "npm run buidler:kovan deploy-UiPoolDataProvider"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/buidler": "^1.4.7",
|
||||
|
@ -78,6 +79,7 @@
|
|||
"chai": "4.2.0",
|
||||
"chai-bignumber": "3.0.0",
|
||||
"chai-bn": "^0.2.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"eth-sig-util": "2.5.3",
|
||||
"ethereum-waffle": "3.0.2",
|
||||
"ethereumjs-util": "7.0.2",
|
||||
|
|
27
tasks/deployments/deploy-UiPoolDataProvider.ts
Normal file
27
tasks/deployments/deploy-UiPoolDataProvider.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
|
||||
import {UiPoolDataProviderFactory} from '../../types';
|
||||
import {verifyContract} from '../../helpers/etherscan-verification';
|
||||
import {eContractid} from '../../helpers/types';
|
||||
|
||||
task(`deploy-${eContractid.UiPoolDataProvider}`, `Deploys the UiPoolDataProvider contract`)
|
||||
.addFlag('verify', 'Verify UiPoolDataProvider contract via Etherscan API.')
|
||||
.setAction(async ({verify}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
|
||||
if (!localBRE.network.config.chainId) {
|
||||
throw new Error('INVALID_CHAIN_ID');
|
||||
}
|
||||
|
||||
console.log(`\n- UiPoolDataProvider deployment`);
|
||||
|
||||
console.log(`\tDeploying UiPoolDataProvider implementation ...`);
|
||||
const uiPoolDataProvider = await new UiPoolDataProviderFactory(
|
||||
await localBRE.ethers.provider.getSigner()
|
||||
).deploy();
|
||||
await uiPoolDataProvider.deployTransaction.wait();
|
||||
console.log('uiPoolDataProvider.address', uiPoolDataProvider.address);
|
||||
await verifyContract(eContractid.UiPoolDataProvider, uiPoolDataProvider.address, []);
|
||||
|
||||
console.log(`\tFinished UiPoolDataProvider proxy and implementation deployment`);
|
||||
});
|
|
@ -53,4 +53,12 @@ task(
|
|||
if (proxyProvider && proxyProvider !== '') {
|
||||
await waitForTx(await addressesProvider.setPriceOracle(proxyProvider));
|
||||
}
|
||||
|
||||
//register the lending rate oracle
|
||||
const lendingRateOracle = getParamPerNetwork(poolConfig.LendingRateOracle, network);
|
||||
|
||||
if (lendingRateOracle && lendingRateOracle !== '') {
|
||||
await waitForTx(await addressesProvider.setLendingRateOracle(proxyProvider));
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -205,7 +205,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
|||
tokens,
|
||||
aggregators,
|
||||
fallbackOracle.address,
|
||||
mockTokens.WETH.address
|
||||
mockTokens.WETH.address,
|
||||
]);
|
||||
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||
|
||||
|
|
|
@ -1,277 +0,0 @@
|
|||
// import {
|
||||
// ITestEnv,
|
||||
// ContractsInstancesOrigin,
|
||||
// iBasicDistributionParams,
|
||||
// iTokenBalances,
|
||||
// iDistributionParams,
|
||||
// } from '../utils/types';
|
||||
// import {
|
||||
// TokenDistributorInstance,
|
||||
// MintableERC20Instance,
|
||||
// } from '../utils/typechain-types/truffle-contracts';
|
||||
// import {testEnvProvider} from '../utils/truffle/dlp-tests-env';
|
||||
// import {
|
||||
// TOKEN_DISTRIBUTOR_PERCENTAGE_BASE,
|
||||
// ETHEREUM_ADDRESS,
|
||||
// ONE_ADDRESS,
|
||||
// NIL_ADDRESS,
|
||||
// } from '../utils/constants';
|
||||
// import BigNumber from 'bignumber.js';
|
||||
|
||||
// import {expect} from 'chai';
|
||||
|
||||
// const testAndExecMintAndTransferTokens = async (
|
||||
// tokenInstance: MintableERC20Instance,
|
||||
// amount: string,
|
||||
// minter: string,
|
||||
// receiver: string
|
||||
// ) => {
|
||||
// const initialMinterBalance = new BigNumber(await tokenInstance.balanceOf(minter));
|
||||
// const initialReceiverBalance = new BigNumber(await tokenInstance.balanceOf(receiver));
|
||||
// await tokenInstance.mint(amount, {
|
||||
// from: minter,
|
||||
// });
|
||||
|
||||
// expect(initialMinterBalance.plus(amount).toFixed()).to.be.equal(
|
||||
// new BigNumber(await tokenInstance.balanceOf(minter)).toFixed()
|
||||
// );
|
||||
|
||||
// await tokenInstance.transfer(receiver, amount, {from: minter});
|
||||
|
||||
// expect(initialReceiverBalance.plus(amount).toFixed()).to.be.equal(
|
||||
// new BigNumber(await tokenInstance.balanceOf(receiver)).toFixed()
|
||||
// );
|
||||
// };
|
||||
|
||||
// const testAndExecEthTransfer = async (
|
||||
// amount: string,
|
||||
// sender: string,
|
||||
// receiver: string,
|
||||
// web3: Web3
|
||||
// ) => {
|
||||
// const initialReceiverEthBalance = await web3.eth.getBalance(receiver);
|
||||
// await web3.eth.sendTransaction({
|
||||
// from: sender,
|
||||
// to: receiver,
|
||||
// value: amount,
|
||||
// });
|
||||
|
||||
// expect(new BigNumber(initialReceiverEthBalance).plus(amount).toFixed()).to.be.equal(
|
||||
// await web3.eth.getBalance(receiver)
|
||||
// );
|
||||
// };
|
||||
|
||||
// const testAndExecDistributeToken = async (
|
||||
// tokenInstances: MintableERC20Instance[],
|
||||
// tokenToBurnInstance: MintableERC20Instance,
|
||||
// tokenDistributorInstance: TokenDistributorInstance,
|
||||
// distributionParams: iBasicDistributionParams[]
|
||||
// ) => {
|
||||
// const tokenBalancesBefore: iTokenBalances[] = [];
|
||||
// for (const [index, tokenInstance] of tokenInstances.entries()) {
|
||||
// const {receivers} = distributionParams[index];
|
||||
// const tokenBalancesReceiversBefore: string[][] = [[], []];
|
||||
// for (const receiver of receivers) {
|
||||
// if (receiver.toUpperCase() !== NIL_ADDRESS.toUpperCase()) {
|
||||
// tokenBalancesReceiversBefore[index].push(
|
||||
// (await tokenInstance.balanceOf(receiver)).toString()
|
||||
// );
|
||||
// } else {
|
||||
// tokenBalancesReceiversBefore[index].push(
|
||||
// (await tokenToBurnInstance.balanceOf(
|
||||
// await tokenDistributorInstance.recipientBurn()
|
||||
// )).toString()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// tokenBalancesBefore.push({
|
||||
// tokenDistributor: (await tokenInstance.balanceOf(
|
||||
// tokenDistributorInstance.address
|
||||
// )).toString(),
|
||||
// receivers: tokenBalancesReceiversBefore[index],
|
||||
// });
|
||||
// }
|
||||
|
||||
// const tokenDistribution = await tokenDistributorInstance.getDistribution();
|
||||
|
||||
// await tokenDistributorInstance.distribute(
|
||||
// tokenInstances.map(tokenInstance => tokenInstance.address)
|
||||
// );
|
||||
|
||||
// const tokenBalanceOfDistributorAfter: string[] = [];
|
||||
// for (const [indexToken, tokenInstance] of tokenInstances.entries()) {
|
||||
// const newLength = tokenBalanceOfDistributorAfter.push(
|
||||
// (await tokenInstance.balanceOf(tokenDistributorInstance.address)).toString()
|
||||
// );
|
||||
// const receivers = distributionParams[indexToken].receivers;
|
||||
// expect(parseInt(tokenBalanceOfDistributorAfter[newLength - 1])).to.be.within(
|
||||
// 0,
|
||||
// receivers.length - 1
|
||||
// );
|
||||
|
||||
// for (const [indexReceiver, receiver] of receivers.entries()) {
|
||||
// const receiverPercentage = new BigNumber(tokenDistribution[1][indexReceiver]).toFixed();
|
||||
// const tokenAmountToReceiver = new BigNumber(tokenBalancesBefore[indexToken].tokenDistributor)
|
||||
// .multipliedBy(receiverPercentage)
|
||||
// .dividedBy(TOKEN_DISTRIBUTOR_PERCENTAGE_BASE)
|
||||
// .toFixed(0, BigNumber.ROUND_DOWN);
|
||||
// const tokenBalanceOfReceiverAfter = (await tokenInstance.balanceOf(receiver)).toString();
|
||||
// const recipientBurnBalanceAfter = (await tokenToBurnInstance.balanceOf(
|
||||
// await tokenDistributorInstance.recipientBurn()
|
||||
// )).toString();
|
||||
// if (receiver.toUpperCase() !== NIL_ADDRESS.toUpperCase()) {
|
||||
// expect(tokenBalanceOfReceiverAfter).to.be.equal(
|
||||
// new BigNumber(tokenBalancesBefore[indexToken].receivers[indexReceiver])
|
||||
// .plus(tokenAmountToReceiver)
|
||||
// .toFixed()
|
||||
// );
|
||||
// } else {
|
||||
// // 1 ether received from "burning" DAI and 264 AAVE wei received from the 34% of the 777 AAVE amount sent to the token distributor
|
||||
// expect(recipientBurnBalanceAfter).to.be.equal('1000000000000000264');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// const testAndExecDistributeEth = async (
|
||||
// tokenDistributorInstance: TokenDistributorInstance,
|
||||
// tokenToBurnInstance: MintableERC20Instance,
|
||||
// distributionParams: iBasicDistributionParams,
|
||||
// web3: Web3
|
||||
// ) => {
|
||||
// const {receivers} = distributionParams;
|
||||
|
||||
// const ethBalancesReceiversBefore = [];
|
||||
// for (const receiver of receivers) {
|
||||
// if (receiver.toUpperCase() !== NIL_ADDRESS.toUpperCase()) {
|
||||
// ethBalancesReceiversBefore.push(await web3.eth.getBalance(receiver));
|
||||
// } else {
|
||||
// ethBalancesReceiversBefore.push(await web3.eth.getBalance(ONE_ADDRESS));
|
||||
// }
|
||||
// }
|
||||
// const ethBalancesBefore: iTokenBalances = {
|
||||
// tokenDistributor: await web3.eth.getBalance(tokenDistributorInstance.address),
|
||||
// receivers: ethBalancesReceiversBefore,
|
||||
// };
|
||||
|
||||
// const ethDistribution = await tokenDistributorInstance.getDistribution();
|
||||
|
||||
// await tokenDistributorInstance.distribute([ETHEREUM_ADDRESS]);
|
||||
|
||||
// const ethBalanceOfDistributorAfter = await web3.eth.getBalance(tokenDistributorInstance.address);
|
||||
|
||||
// expect(parseInt(ethBalanceOfDistributorAfter)).to.be.within(0, receivers.length - 1);
|
||||
|
||||
// for (const [index, receiver] of receivers.entries()) {
|
||||
// const receiverPercentage = new BigNumber(ethDistribution[1][index]).toFixed();
|
||||
// const ethAmountToReceiver = new BigNumber(ethBalancesBefore.tokenDistributor)
|
||||
// .multipliedBy(receiverPercentage)
|
||||
// .dividedBy(TOKEN_DISTRIBUTOR_PERCENTAGE_BASE)
|
||||
// .toFixed(0, BigNumber.ROUND_DOWN);
|
||||
// const ethBalanceOfReceiverAfter = await web3.eth.getBalance(receiver);
|
||||
// const recipientBurnBalanceAfter = (await tokenToBurnInstance.balanceOf(
|
||||
// await tokenDistributorInstance.recipientBurn()
|
||||
// )).toString();
|
||||
// if (receiver.toUpperCase() !== NIL_ADDRESS.toUpperCase()) {
|
||||
// expect(ethBalanceOfReceiverAfter).to.be.equal(
|
||||
// new BigNumber(ethBalancesBefore.receivers[index]).plus(ethAmountToReceiver).toFixed()
|
||||
// );
|
||||
// } else {
|
||||
// // 1 ether received from "burning" DAI, 1 ether from ETH and 264 AAVE wei received from the 34% of the 777 AAVE amount sent to the token distributor
|
||||
// expect(recipientBurnBalanceAfter).to.be.equal('2000000000000000264');
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// contract('TokenDistributor', async ([deployer, ...users]) => {
|
||||
// // let _testEnvProvider: ITestEnv;
|
||||
// // let _tokenDistributorInstance: TokenDistributorInstance;
|
||||
// // let _tokenInstances: iAavePoolAssets<MintableERC20Instance>;
|
||||
// // let _web3: Web3;
|
||||
// // let _depositorAddress: string;
|
||||
// // let _daiDistributionParams: iDistributionParams;
|
||||
// // let _lendDistributionParams: iDistributionParams;
|
||||
// // let _ethDistributionParams: iDistributionParams;
|
||||
|
||||
// // before('Initializing LendingPoolConfigurator test variables', async () => {
|
||||
// // _testEnvProvider = await testEnvProvider(
|
||||
// // artifacts,
|
||||
// // [deployer, ...users],
|
||||
// // ContractsInstancesOrigin.TruffleArtifacts
|
||||
// // );
|
||||
|
||||
// // const {
|
||||
// // deployedInstances: {tokenDistributorInstance},
|
||||
// // getAllAssetsInstances,
|
||||
// // getWeb3,
|
||||
// // getFirstDepositorAddressOnTests,
|
||||
// // getFeeDistributionParams,
|
||||
// // } = _testEnvProvider;
|
||||
// // _tokenDistributorInstance = tokenDistributorInstance;
|
||||
// // _tokenInstances = await getAllAssetsInstances();
|
||||
// // _web3 = await getWeb3();
|
||||
// // _depositorAddress = await getFirstDepositorAddressOnTests();
|
||||
|
||||
// // const {receivers, percentages} = await getFeeDistributionParams();
|
||||
// // _daiDistributionParams = {
|
||||
// // amountToDistribute: '333',
|
||||
// // receivers,
|
||||
// // percentages,
|
||||
// // };
|
||||
// // _lendDistributionParams = {
|
||||
// // amountToDistribute: '777',
|
||||
// // receivers,
|
||||
// // percentages,
|
||||
// // };
|
||||
// // _ethDistributionParams = {
|
||||
// // amountToDistribute: '2534',
|
||||
// // receivers,
|
||||
// // percentages,
|
||||
// // };
|
||||
// // });
|
||||
|
||||
// // it('Transfers ETH to the TokenDistributor', async () => {
|
||||
// // await testAndExecEthTransfer(
|
||||
// // _ethDistributionParams.amountToDistribute,
|
||||
// // deployer,
|
||||
// // _tokenDistributorInstance.address,
|
||||
// // _web3
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // it('Mints and transfers DAI to the TokenDistributor', async () => {
|
||||
// // await testAndExecMintAndTransferTokens(
|
||||
// // _tokenInstances.DAI,
|
||||
// // _daiDistributionParams.amountToDistribute,
|
||||
// // _depositorAddress,
|
||||
// // _tokenDistributorInstance.address
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // it('Mints and transfers AAVE to the TokenDistributor', async () => {
|
||||
// // await testAndExecMintAndTransferTokens(
|
||||
// // _tokenInstances.AAVE,
|
||||
// // _lendDistributionParams.amountToDistribute,
|
||||
// // _depositorAddress,
|
||||
// // _tokenDistributorInstance.address
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // it('distribute() for the receivers', async () => {
|
||||
// // await testAndExecDistributeToken(
|
||||
// // [_tokenInstances.DAI, _tokenInstances.AAVE],
|
||||
// // _tokenInstances.AAVE,
|
||||
// // _tokenDistributorInstance,
|
||||
// // [_daiDistributionParams, _lendDistributionParams]
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // it('Distributes the ETH to the receivers', async () => {
|
||||
// // await testAndExecDistributeEth(
|
||||
// // _tokenDistributorInstance,
|
||||
// // _tokenInstances.AAVE,
|
||||
// // _ethDistributionParams,
|
||||
// // _web3
|
||||
// // );
|
||||
// // });
|
||||
// });
|
|
@ -1,12 +1,10 @@
|
|||
import {MAX_UINT_AMOUNT} from '../helpers/constants';
|
||||
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
|
||||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||
import {formatEther, parseEther, parseUnits} from 'ethers/lib/utils';
|
||||
import {parseEther} from 'ethers/lib/utils';
|
||||
import {DRE, waitForTx} from '../helpers/misc-utils';
|
||||
import {BigNumber} from 'ethers';
|
||||
import {getStableDebtToken, getVariableDebtToken} from '../helpers/contracts-getters';
|
||||
import {WethGateway} from '../types/WethGateway';
|
||||
import {use} from 'chai';
|
||||
import {deploySelfdestructTransferMock} from '../helpers/contracts-deployments';
|
||||
|
||||
const {expect} = require('chai');
|
||||
|
@ -185,6 +183,48 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
|||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
||||
});
|
||||
|
||||
it('Borrow ETH via delegateApprove ETH and repays back', async () => {
|
||||
const {users, wethGateway, aWETH, weth, helpersContract} = testEnv;
|
||||
const borrowSize = parseEther('1');
|
||||
const user = users[2];
|
||||
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
|
||||
weth.address
|
||||
);
|
||||
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
||||
|
||||
const priorDebtBalance = await varDebtToken.balanceOf(user.address);
|
||||
expect(priorDebtBalance).to.be.eq(zero);
|
||||
|
||||
// Deposit WETH with native ETH
|
||||
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
|
||||
|
||||
const aTokensBalance = await aWETH.balanceOf(user.address);
|
||||
|
||||
expect(aTokensBalance).to.be.gt(zero);
|
||||
expect(aTokensBalance).to.be.gte(depositSize);
|
||||
|
||||
// Delegates borrowing power of WETH to WETHGateway
|
||||
await waitForTx(
|
||||
await varDebtToken.connect(user.signer).approveDelegation(wethGateway.address, borrowSize)
|
||||
);
|
||||
|
||||
// Borrows ETH with WETH as collateral
|
||||
await waitForTx(await wethGateway.connect(user.signer).borrowETH(borrowSize, '2', '0'));
|
||||
|
||||
const debtBalance = await varDebtToken.balanceOf(user.address);
|
||||
|
||||
expect(debtBalance).to.be.gt(zero);
|
||||
|
||||
// Full Repay WETH loan with native ETH
|
||||
await waitForTx(
|
||||
await wethGateway
|
||||
.connect(user.signer)
|
||||
.repayETH(MAX_UINT_AMOUNT, '2', user.address, {value: borrowSize.mul(2)})
|
||||
);
|
||||
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
|
||||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
||||
});
|
||||
|
||||
it('Should revert if receiver function receives Ether if not WETH', async () => {
|
||||
const {users, wethGateway} = testEnv;
|
||||
const user = users[0];
|
||||
|
|
Loading…
Reference in New Issue
Block a user