mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Added getAllReservesTokens for AaveProtocolTestHelpers.
This commit is contained in:
parent
0453a49f8f
commit
18e19b4f84
|
@ -2,13 +2,14 @@ pragma solidity ^0.6.8;
|
|||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ILendingPoolAddressesProvider} from "../interfaces/ILendingPoolAddressesProvider.sol";
|
||||
import {IERC20Detailed} from "../interfaces/IERC20Detailed.sol";
|
||||
import {LendingPoolCore} from "../lendingpool/LendingPool.sol";
|
||||
import {AToken} from "../tokenization/AToken.sol";
|
||||
|
||||
contract AaveProtocolTestHelpers {
|
||||
struct ATokenData {
|
||||
struct TokenData {
|
||||
string symbol;
|
||||
address aTokenAddress;
|
||||
address tokenAddress;
|
||||
}
|
||||
|
||||
ILendingPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
|
||||
|
@ -17,15 +18,28 @@ contract AaveProtocolTestHelpers {
|
|||
ADDRESSES_PROVIDER = addressesProvider;
|
||||
}
|
||||
|
||||
function getAllATokens() external view returns(ATokenData[] memory) {
|
||||
function getAllReservesTokens() external view returns(TokenData[] memory) {
|
||||
LendingPoolCore core = LendingPoolCore(ADDRESSES_PROVIDER.getLendingPoolCore());
|
||||
address[] memory reserves = core.getReserves();
|
||||
ATokenData[] memory aTokens = new ATokenData[](reserves.length);
|
||||
TokenData[] memory reservesTokens = new TokenData[](reserves.length);
|
||||
for (uint256 i = 0; i < reserves.length; i++) {
|
||||
reservesTokens[i] = TokenData({
|
||||
symbol: (reserves[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) ? "ETH" : IERC20Detailed(reserves[i]).symbol(),
|
||||
tokenAddress: reserves[i]
|
||||
});
|
||||
}
|
||||
return reservesTokens;
|
||||
}
|
||||
|
||||
function getAllATokens() external view returns(TokenData[] memory) {
|
||||
LendingPoolCore core = LendingPoolCore(ADDRESSES_PROVIDER.getLendingPoolCore());
|
||||
address[] memory reserves = core.getReserves();
|
||||
TokenData[] memory aTokens = new TokenData[](reserves.length);
|
||||
for (uint256 i = 0; i < reserves.length; i++) {
|
||||
address aTokenAddress = core.getReserveATokenAddress(reserves[i]);
|
||||
aTokens[i] = ATokenData({
|
||||
aTokens[i] = TokenData({
|
||||
symbol: AToken(aTokenAddress).symbol(),
|
||||
aTokenAddress: aTokenAddress
|
||||
tokenAddress: aTokenAddress
|
||||
});
|
||||
}
|
||||
return aTokens;
|
||||
|
|
|
@ -35,6 +35,9 @@ import {MockFlashLoanReceiver} from "../types/MockFlashLoanReceiver";
|
|||
import {WalletBalanceProvider} from "../types/WalletBalanceProvider";
|
||||
import {AToken} from "../types/AToken";
|
||||
import {AaveProtocolTestHelpers} from "../types/AaveProtocolTestHelpers";
|
||||
import {MOCK_ETH_ADDRESS} from "./constants";
|
||||
import BigNumber from "bignumber.js";
|
||||
import {Ierc20Detailed} from "../types/Ierc20Detailed";
|
||||
|
||||
export const registerContractInJsonDb = async (
|
||||
contractId: string,
|
||||
|
@ -414,6 +417,30 @@ export const getAToken = async (address?: tEthereumAddress) => {
|
|||
);
|
||||
};
|
||||
|
||||
export const getMintableErc20 = async (address?: tEthereumAddress) => {
|
||||
return await getContract<MintableErc20>(
|
||||
eContractid.MintableERC20,
|
||||
address ||
|
||||
(
|
||||
await getDb()
|
||||
.get(`${eContractid.MintableERC20}.${BRE.network.name}`)
|
||||
.value()
|
||||
).address
|
||||
);
|
||||
};
|
||||
|
||||
export const getIErc20Detailed = async (address?: tEthereumAddress) => {
|
||||
return await getContract<Ierc20Detailed>(
|
||||
eContractid.IERC20Detailed,
|
||||
address ||
|
||||
(
|
||||
await getDb()
|
||||
.get(`${eContractid.IERC20Detailed}.${BRE.network.name}`)
|
||||
.value()
|
||||
).address
|
||||
);
|
||||
};
|
||||
|
||||
export const getAaveProtocolTestHelpers = async (
|
||||
address?: tEthereumAddress
|
||||
) => {
|
||||
|
@ -482,3 +509,38 @@ export const getParamPerPool = <T>(
|
|||
return proto;
|
||||
}
|
||||
};
|
||||
|
||||
export const convertToCurrencyDecimals = async (
|
||||
tokenAddress: tEthereumAddress,
|
||||
amount: string
|
||||
) => {
|
||||
const isEth = tokenAddress === MOCK_ETH_ADDRESS;
|
||||
let decimals = new BigNumber(18);
|
||||
|
||||
if (!isEth) {
|
||||
const token = await getIErc20Detailed(tokenAddress);
|
||||
decimals = new BigNumber(await token.decimals());
|
||||
}
|
||||
|
||||
const currencyUnit = new BigNumber(10).pow(decimals);
|
||||
const amountInCurrencyDecimals = new BigNumber(amount).multipliedBy(
|
||||
currencyUnit
|
||||
);
|
||||
return amountInCurrencyDecimals.toFixed();
|
||||
};
|
||||
|
||||
export const convertToCurrencyUnits = async (
|
||||
tokenAddress: string,
|
||||
amount: string
|
||||
) => {
|
||||
const isEth = tokenAddress === MOCK_ETH_ADDRESS;
|
||||
|
||||
let decimals = new BigNumber(18);
|
||||
if (!isEth) {
|
||||
const token = await getIErc20Detailed(tokenAddress);
|
||||
decimals = new BigNumber(await token.decimals());
|
||||
}
|
||||
const currencyUnit = new BigNumber(10).pow(decimals);
|
||||
const amountInCurrencyUnits = new BigNumber(amount).div(currencyUnit);
|
||||
return amountInCurrencyUnits.toFixed();
|
||||
};
|
||||
|
|
|
@ -39,6 +39,7 @@ export enum eContractid {
|
|||
WalletBalanceProvider = "WalletBalanceProvider",
|
||||
AToken = "AToken",
|
||||
AaveProtocolTestHelpers = "AaveProtocolTestHelpers",
|
||||
IERC20Detailed = "IERC20Detailed"
|
||||
}
|
||||
|
||||
export type tEthereumAddress = string;
|
||||
|
|
|
@ -20,7 +20,7 @@ describe("AToken: Modifiers", () => {
|
|||
|
||||
const aDAIAddress = (await testHelpers.getAllATokens()).find(
|
||||
(aToken) => aToken.symbol === "aDAI"
|
||||
)?.aTokenAddress;
|
||||
)?.tokenAddress;
|
||||
if (!aDAIAddress) {
|
||||
console.log(`atoken-modifiers.spec: aDAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
|
|
|
@ -1,190 +1,245 @@
|
|||
// import { ITestEnvWithoutInstances, RateMode} from '../utils/types';
|
||||
// import {
|
||||
// ATokenInstance,
|
||||
// LendingPoolInstance,
|
||||
// MintableERC20Instance,
|
||||
// LendingPoolCoreInstance,
|
||||
// } from '../utils/typechain-types/truffle-contracts';
|
||||
// import {testEnvProviderWithoutInstances} from '../utils/truffle/dlp-tests-env';
|
||||
// import {convertToCurrencyDecimals} from '../utils/misc-utils';
|
||||
// import {APPROVAL_AMOUNT_LENDING_POOL_CORE, ETHEREUM_ADDRESS, oneEther, NIL_ADDRESS, MAX_UINT_AMOUNT} from '../utils/constants';
|
||||
import {MockProvider} from "ethereum-waffle";
|
||||
import {evmRevert, BRE} from "../helpers/misc-utils";
|
||||
import {
|
||||
TEST_SNAPSHOT_ID,
|
||||
APPROVAL_AMOUNT_LENDING_POOL_CORE,
|
||||
} from "../helpers/constants";
|
||||
import {AToken} from "../types/AToken";
|
||||
import {MintableErc20} from "../types/MintableErc20";
|
||||
import {LendingPool} from "../types/LendingPool";
|
||||
import {LendingPoolCore} from "../types/LendingPoolCore";
|
||||
import {
|
||||
getAaveProtocolTestHelpers,
|
||||
getMintableErc20,
|
||||
getAToken,
|
||||
convertToCurrencyDecimals,
|
||||
getEthersSigners,
|
||||
getLendingPoolCoreProxy,
|
||||
getLendingPoolProxy,
|
||||
} from "../helpers/contracts-helpers";
|
||||
import {expect} from "chai";
|
||||
import {ethers, Wallet, Signer} from "ethers";
|
||||
// @ts-ignore
|
||||
import {accounts} from "../test-wallets.js";
|
||||
|
||||
describe("AToken: Transfer", () => {
|
||||
let wallets: Signer[];
|
||||
let deployer: Signer;
|
||||
let users: Signer[];
|
||||
let _aDai = {} as AToken;
|
||||
let _dai = {} as MintableErc20;
|
||||
let _lendingPool = {} as LendingPool;
|
||||
let _lendingPoolCore = {} as LendingPoolCore;
|
||||
const NOT_LENDING_POOL_MSG =
|
||||
"The caller of this function must be a lending pool";
|
||||
|
||||
before(async () => {
|
||||
await evmRevert(TEST_SNAPSHOT_ID);
|
||||
|
||||
const [_deployer, ..._users] = await getEthersSigners();
|
||||
deployer = _deployer;
|
||||
users = _users;
|
||||
|
||||
_lendingPool = await getLendingPoolProxy();
|
||||
_lendingPoolCore = await getLendingPoolCoreProxy();
|
||||
|
||||
const testHelpers = await getAaveProtocolTestHelpers();
|
||||
|
||||
const aDaiAddress = (await testHelpers.getAllATokens()).find(
|
||||
(aToken) => aToken.symbol === "aDAI"
|
||||
)?.tokenAddress;
|
||||
|
||||
const daiAddress = (await testHelpers.getAllReservesTokens()).find(
|
||||
(token) => token.symbol === "DAI"
|
||||
)?.tokenAddress;
|
||||
if (!aDaiAddress) {
|
||||
console.log(`atoken-modifiers.spec: aDAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!daiAddress) {
|
||||
console.log(`atoken-modifiers.spec: DAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// const expectRevert = require('@openzeppelin/test-helpers').expectRevert;
|
||||
_aDai = await getAToken(aDaiAddress);
|
||||
_dai = await getMintableErc20(daiAddress);
|
||||
});
|
||||
|
||||
// contract('AToken: Transfer', async ([deployer, ...users]) => {
|
||||
// let _testEnvProvider: ITestEnvWithoutInstances;
|
||||
// let _aDAI: ATokenInstance;
|
||||
// let _DAI: MintableERC20Instance;
|
||||
// let _lendingPoolInstance: LendingPoolInstance;
|
||||
// let _lendingPoolCoreInstance: LendingPoolCoreInstance;
|
||||
it("User 0 deposits 1000 DAI, transfers to user 1", async () => {
|
||||
await _dai
|
||||
.connect(users[0])
|
||||
.mint(await convertToCurrencyDecimals(_dai.address, "1000"));
|
||||
|
||||
// before('Initializing test variables', async () => {
|
||||
// console.time('setup-test');
|
||||
// _testEnvProvider = await testEnvProviderWithoutInstances(
|
||||
// artifacts,
|
||||
// [deployer, ...users]
|
||||
// );
|
||||
console.log(_lendingPoolCore.address);
|
||||
|
||||
// const {
|
||||
// getLendingPoolInstance,
|
||||
// getLendingPoolCoreInstance,
|
||||
// getAllAssetsInstances,
|
||||
// getATokenInstances
|
||||
// } = _testEnvProvider;
|
||||
// const instances = await Promise.all([
|
||||
// getATokenInstances(), getAllAssetsInstances(), getLendingPoolInstance(), getLendingPoolCoreInstance()
|
||||
// ])
|
||||
await _dai
|
||||
.connect(users[0])
|
||||
.approve(_lendingPoolCore.address, APPROVAL_AMOUNT_LENDING_POOL_CORE);
|
||||
|
||||
// _aDAI = instances[0].aDAI
|
||||
// _DAI = instances[1].DAI
|
||||
// _lendingPoolInstance = instances[2];
|
||||
// _lendingPoolCoreInstance = instances[3]
|
||||
//user 1 deposits 1000 DAI
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(
|
||||
_dai.address,
|
||||
"1000"
|
||||
);
|
||||
|
||||
// console.timeEnd('setup-test');
|
||||
// });
|
||||
await _lendingPool
|
||||
.connect(users[0])
|
||||
.deposit(_dai.address, amountDAItoDeposit, "0");
|
||||
|
||||
// it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
|
||||
// await _DAI.mint(await convertToCurrencyDecimals(_DAI.address, '1000'), {
|
||||
// from: users[0],
|
||||
// });
|
||||
// console.log(users[0])
|
||||
// console.log(await users[0].getAddress())
|
||||
// await _aDai
|
||||
// .connect(users[0])
|
||||
// .transfer(await users[1].getAddress(), amountDAItoDeposit);
|
||||
|
||||
// await _DAI.approve(_lendingPoolCoreInstance.address, APPROVAL_AMOUNT_LENDING_POOL_CORE, {
|
||||
// from: users[0],
|
||||
// });
|
||||
// const fromBalance = await _aDai.balanceOf(await users[0].getAddress());
|
||||
// const toBalance = await _aDai.balanceOf(await users[1].getAddress());
|
||||
|
||||
// //user 1 deposits 1000 DAI
|
||||
// const amountDAItoDeposit = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
// expect(fromBalance.toString()).to.be.equal(
|
||||
// "0",
|
||||
// "Invalid from balance after transfer"
|
||||
// );
|
||||
// expect(toBalance.toString()).to.be.equal(
|
||||
// amountDAItoDeposit.toString(),
|
||||
// "Invalid to balance after transfer"
|
||||
// );
|
||||
});
|
||||
|
||||
// await _lendingPoolInstance.deposit(_DAI.address, amountDAItoDeposit, '0', {
|
||||
// from: users[0],
|
||||
// });
|
||||
// it('User 1 redirects interest to user 2, transfers 500 DAI back to user 0', async () => {
|
||||
|
||||
// await _aDAI.transfer(users[1], amountDAItoDeposit, {from: users[0]})
|
||||
// await _aDAI.redirectInterestStream(users[2], {from: users[1]});
|
||||
|
||||
// const fromBalance = await _aDAI.balanceOf(users[0])
|
||||
// const toBalance = await _aDAI.balanceOf(users[1])
|
||||
// const aDAIRedirected = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
|
||||
// expect(fromBalance.toString()).to.be.equal("0", "Invalid from balance after transfer")
|
||||
// expect(toBalance.toString()).to.be.equal(amountDAItoDeposit.toString(), "Invalid to balance after transfer")
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
|
||||
// });
|
||||
// const user2RedirectedBalanceBefore = await _aDAI.getRedirectedBalance(users[2])
|
||||
// expect(user2RedirectedBalanceBefore.toString()).to.be.equal(aDAIRedirected, "Invalid redirected balance for user 2 before transfer")
|
||||
|
||||
// await _aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]})
|
||||
|
||||
// it('User 1 redirects interest to user 2, transfers 500 DAI back to user 0', async () => {
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// const user1RedirectionAddress = await _aDAI.getInterestRedirectionAddress(users[1])
|
||||
|
||||
// await _aDAI.redirectInterestStream(users[2], {from: users[1]});
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(aDAItoTransfer, "Invalid redirected balance for user 2 after transfer")
|
||||
// expect(user1RedirectionAddress.toString()).to.be.equal(users[2], "Invalid redirection address for user 1")
|
||||
|
||||
// });
|
||||
|
||||
// const aDAIRedirected = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
// it('User 0 transfers back to user 1', async () => {
|
||||
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
|
||||
|
||||
// const user2RedirectedBalanceBefore = await _aDAI.getRedirectedBalance(users[2])
|
||||
// expect(user2RedirectedBalanceBefore.toString()).to.be.equal(aDAIRedirected, "Invalid redirected balance for user 2 before transfer")
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
|
||||
// await _aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]})
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
|
||||
// const user1BalanceAfter = await _aDAI.balanceOf(users[1])
|
||||
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// const user1RedirectionAddress = await _aDAI.getInterestRedirectionAddress(users[1])
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(user1BalanceAfter.toString(), "Invalid redirected balance for user 2 after transfer")
|
||||
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(aDAItoTransfer, "Invalid redirected balance for user 2 after transfer")
|
||||
// expect(user1RedirectionAddress.toString()).to.be.equal(users[2], "Invalid redirection address for user 1")
|
||||
// });
|
||||
|
||||
// });
|
||||
// it('User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)', async () => {
|
||||
|
||||
// it('User 0 transfers back to user 1', async () => {
|
||||
// await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, oneEther, '0', {
|
||||
// from: users[0],
|
||||
// value: oneEther.toFixed(0)
|
||||
// });
|
||||
|
||||
// await expectRevert(_lendingPoolInstance.borrow(ETHEREUM_ADDRESS, await convertToCurrencyDecimals(ETHEREUM_ADDRESS,"0.1"), RateMode.Stable, "0", {from: users[1]}), "The collateral balance is 0")
|
||||
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
// });
|
||||
|
||||
// it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => {
|
||||
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
// await _lendingPoolInstance.setUserUseReserveAsCollateral(_DAI.address, true, {from: users[1]})
|
||||
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// await _lendingPoolInstance.borrow(ETHEREUM_ADDRESS, await convertToCurrencyDecimals(ETHEREUM_ADDRESS,"0.1"), RateMode.Stable, "0", {from: users[1]})
|
||||
|
||||
// const user1BalanceAfter = await _aDAI.balanceOf(users[1])
|
||||
// await expectRevert(_aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]}), "Transfer cannot be allowed.")
|
||||
// });
|
||||
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(user1BalanceAfter.toString(), "Invalid redirected balance for user 2 after transfer")
|
||||
// it('User 0 tries to transfer 0 balance (revert expected)', async () => {
|
||||
// await expectRevert(_aDAI.transfer(users[1], "0", {from: users[0]}), "Transferred amount needs to be greater than zero")
|
||||
// });
|
||||
|
||||
// });
|
||||
// it('User 1 repays the borrow, transfers aDAI back to user 0', async () => {
|
||||
|
||||
// await _lendingPoolInstance.repay(ETHEREUM_ADDRESS, MAX_UINT_AMOUNT, users[1], {from: users[1], value: oneEther.toFixed(0)})
|
||||
|
||||
// it('User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)', async () => {
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
|
||||
// await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, oneEther, '0', {
|
||||
// from: users[0],
|
||||
// value: oneEther.toFixed(0)
|
||||
// });
|
||||
// await _aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]})
|
||||
|
||||
|
||||
// await expectRevert(_lendingPoolInstance.borrow(ETHEREUM_ADDRESS, await convertToCurrencyDecimals(ETHEREUM_ADDRESS,"0.1"), RateMode.Stable, "0", {from: users[1]}), "The collateral balance is 0")
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
|
||||
// });
|
||||
// const user1RedirectionAddress = await _aDAI.getInterestRedirectionAddress(users[1])
|
||||
|
||||
// it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => {
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal("0", "Invalid redirected balance for user 2 after transfer")
|
||||
|
||||
// await _lendingPoolInstance.setUserUseReserveAsCollateral(_DAI.address, true, {from: users[1]})
|
||||
// expect(user1RedirectionAddress.toString()).to.be.equal(NIL_ADDRESS, "Invalid redirected address for user 1")
|
||||
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
// });
|
||||
|
||||
// await _lendingPoolInstance.borrow(ETHEREUM_ADDRESS, await convertToCurrencyDecimals(ETHEREUM_ADDRESS,"0.1"), RateMode.Stable, "0", {from: users[1]})
|
||||
// it('User 0 redirects interest to user 2, transfers 500 aDAI to user 1. User 1 redirects to user 3. User 0 transfers another 100 aDAI', async () => {
|
||||
|
||||
// await expectRevert(_aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]}), "Transfer cannot be allowed.")
|
||||
// });
|
||||
// let aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
|
||||
|
||||
// it('User 0 tries to transfer 0 balance (revert expected)', async () => {
|
||||
// await expectRevert(_aDAI.transfer(users[1], "0", {from: users[0]}), "Transferred amount needs to be greater than zero")
|
||||
// });
|
||||
// await _aDAI.redirectInterestStream(users[2], {from: users[0]})
|
||||
|
||||
// it('User 1 repays the borrow, transfers aDAI back to user 0', async () => {
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
|
||||
// await _lendingPoolInstance.repay(ETHEREUM_ADDRESS, MAX_UINT_AMOUNT, users[1], {from: users[1], value: oneEther.toFixed(0)})
|
||||
// await _aDAI.redirectInterestStream(users[3], {from: users[1]})
|
||||
|
||||
// const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '1000');
|
||||
// aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '100');
|
||||
|
||||
// await _aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]})
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// const user3RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[3])
|
||||
|
||||
// const user1RedirectionAddress = await _aDAI.getInterestRedirectionAddress(users[1])
|
||||
// const expectedUser2Redirected = await convertToCurrencyDecimals(_DAI.address, "400")
|
||||
// const expectedUser3Redirected = await convertToCurrencyDecimals(_DAI.address, "600")
|
||||
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal("0", "Invalid redirected balance for user 2 after transfer")
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(expectedUser2Redirected, "Invalid redirected balance for user 2 after transfer")
|
||||
// expect(user3RedirectedBalanceAfter.toString()).to.be.equal(expectedUser3Redirected, "Invalid redirected balance for user 3 after transfer")
|
||||
|
||||
// expect(user1RedirectionAddress.toString()).to.be.equal(NIL_ADDRESS, "Invalid redirected address for user 1")
|
||||
// });
|
||||
});
|
||||
|
||||
// });
|
||||
// // contract('AToken: Transfer', async ([deployer, ...users]) => {
|
||||
// // let _testEnvProvider: ITestEnvWithoutInstances;
|
||||
// // let _aDAI: ATokenInstance;
|
||||
// // let _DAI: MintableERC20Instance;
|
||||
// // let _lendingPoolInstance: LendingPoolInstance;
|
||||
// // let _lendingPoolCoreInstance: LendingPoolCoreInstance;
|
||||
|
||||
// it('User 0 redirects interest to user 2, transfers 500 aDAI to user 1. User 1 redirects to user 3. User 0 transfers another 100 aDAI', async () => {
|
||||
// // before('Initializing test variables', async () => {
|
||||
// // console.time('setup-test');
|
||||
// // _testEnvProvider = await testEnvProviderWithoutInstances(
|
||||
// // artifacts,
|
||||
// // [deployer, ...users]
|
||||
// // );
|
||||
|
||||
|
||||
// let aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500');
|
||||
// // const {
|
||||
// // getLendingPoolInstance,
|
||||
// // getLendingPoolCoreInstance,
|
||||
// // getAllAssetsInstances,
|
||||
// // getATokenInstances
|
||||
// // } = _testEnvProvider;
|
||||
// // const instances = await Promise.all([
|
||||
// // getATokenInstances(), getAllAssetsInstances(), getLendingPoolInstance(), getLendingPoolCoreInstance()
|
||||
// // ])
|
||||
|
||||
// await _aDAI.redirectInterestStream(users[2], {from: users[0]})
|
||||
// // _aDAI = instances[0].aDAI
|
||||
// // _DAI = instances[1].DAI
|
||||
// // _lendingPoolInstance = instances[2];
|
||||
// // _lendingPoolCoreInstance = instances[3]
|
||||
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
// // console.timeEnd('setup-test');
|
||||
// // });
|
||||
|
||||
// await _aDAI.redirectInterestStream(users[3], {from: users[1]})
|
||||
|
||||
// aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '100');
|
||||
|
||||
// await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]})
|
||||
|
||||
|
||||
// const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2])
|
||||
// const user3RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[3])
|
||||
|
||||
// const expectedUser2Redirected = await convertToCurrencyDecimals(_DAI.address, "400")
|
||||
// const expectedUser3Redirected = await convertToCurrencyDecimals(_DAI.address, "600")
|
||||
|
||||
// expect(user2RedirectedBalanceAfter.toString()).to.be.equal(expectedUser2Redirected, "Invalid redirected balance for user 2 after transfer")
|
||||
// expect(user3RedirectedBalanceAfter.toString()).to.be.equal(expectedUser3Redirected, "Invalid redirected balance for user 3 after transfer")
|
||||
|
||||
|
||||
// });
|
||||
|
||||
|
||||
// });
|
||||
// // });
|
||||
|
|
16
types/AaveProtocolTestHelpers.d.ts
vendored
16
types/AaveProtocolTestHelpers.d.ts
vendored
|
@ -15,6 +15,8 @@ interface AaveProtocolTestHelpersInterface extends Interface {
|
|||
ADDRESSES_PROVIDER: TypedFunctionDescription<{ encode([]: []): string }>;
|
||||
|
||||
getAllATokens: TypedFunctionDescription<{ encode([]: []): string }>;
|
||||
|
||||
getAllReservesTokens: TypedFunctionDescription<{ encode([]: []): string }>;
|
||||
};
|
||||
|
||||
events: {};
|
||||
|
@ -45,14 +47,22 @@ export class AaveProtocolTestHelpers extends Contract {
|
|||
ADDRESSES_PROVIDER(): Promise<string>;
|
||||
|
||||
getAllATokens(): Promise<
|
||||
{ symbol: string; aTokenAddress: string; 0: string; 1: string }[]
|
||||
{ symbol: string; tokenAddress: string; 0: string; 1: string }[]
|
||||
>;
|
||||
|
||||
getAllReservesTokens(): Promise<
|
||||
{ symbol: string; tokenAddress: string; 0: string; 1: string }[]
|
||||
>;
|
||||
};
|
||||
|
||||
ADDRESSES_PROVIDER(): Promise<string>;
|
||||
|
||||
getAllATokens(): Promise<
|
||||
{ symbol: string; aTokenAddress: string; 0: string; 1: string }[]
|
||||
{ symbol: string; tokenAddress: string; 0: string; 1: string }[]
|
||||
>;
|
||||
|
||||
getAllReservesTokens(): Promise<
|
||||
{ symbol: string; tokenAddress: string; 0: string; 1: string }[]
|
||||
>;
|
||||
|
||||
filters: {};
|
||||
|
@ -61,5 +71,7 @@ export class AaveProtocolTestHelpers extends Contract {
|
|||
ADDRESSES_PROVIDER(): Promise<BigNumber>;
|
||||
|
||||
getAllATokens(): Promise<BigNumber>;
|
||||
|
||||
getAllReservesTokens(): Promise<BigNumber>;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -83,11 +83,36 @@ const _abi = [
|
|||
},
|
||||
{
|
||||
internalType: "address",
|
||||
name: "aTokenAddress",
|
||||
name: "tokenAddress",
|
||||
type: "address"
|
||||
}
|
||||
],
|
||||
internalType: "struct AaveProtocolTestHelpers.ATokenData[]",
|
||||
internalType: "struct AaveProtocolTestHelpers.TokenData[]",
|
||||
name: "",
|
||||
type: "tuple[]"
|
||||
}
|
||||
],
|
||||
stateMutability: "view",
|
||||
type: "function"
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: "getAllReservesTokens",
|
||||
outputs: [
|
||||
{
|
||||
components: [
|
||||
{
|
||||
internalType: "string",
|
||||
name: "symbol",
|
||||
type: "string"
|
||||
},
|
||||
{
|
||||
internalType: "address",
|
||||
name: "tokenAddress",
|
||||
type: "address"
|
||||
}
|
||||
],
|
||||
internalType: "struct AaveProtocolTestHelpers.TokenData[]",
|
||||
name: "",
|
||||
type: "tuple[]"
|
||||
}
|
||||
|
@ -98,4 +123,4 @@ const _abi = [
|
|||
];
|
||||
|
||||
const _bytecode =
|
||||
"0x60a060405234801561001057600080fd5b5060405161064338038061064383398101604081905261002f91610044565b60601b6001600160601b031916608052610072565b600060208284031215610055578081fd5b81516001600160a01b038116811461006b578182fd5b9392505050565b60805160601c6105b16100926000398060705280609852506105b16000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80630542975c1461003b578063f561ae4114610059575b600080fd5b61004361006e565b6040516100509190610468565b60405180910390f35b610061610092565b604051610050919061047c565b7f000000000000000000000000000000000000000000000000000000000000000081565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ed6ff7606040518163ffffffff1660e01b815260040160206040518083038186803b1580156100ef57600080fd5b505afa158015610103573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610127919061030e565b90506060816001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160006040518083038186803b15801561016457600080fd5b505afa158015610178573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526101a09190810190610331565b9050606060005b82518110156102f5576000846001600160a01b03166334b3beee8584815181106101cd57fe5b60200260200101516040518263ffffffff1660e01b81526004016101f19190610468565b60206040518083038186803b15801561020957600080fd5b505afa15801561021d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610241919061030e565b90506040518060400160405280826001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561028757600080fd5b505afa15801561029b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526102c391908101906103dc565b8152602001826001600160a01b03168152508383815181106102e157fe5b6020908102919091010152506001016101a7565b509250505090565b805161030881610563565b92915050565b60006020828403121561031f578081fd5b815161032a81610563565b9392505050565b60006020808385031215610343578182fd5b825167ffffffffffffffff8082111561035a578384fd5b81850186601f82011261036b578485fd5b805192508183111561037b578485fd5b838302915061038b84830161050c565b8381528481019082860184840187018a10156103a5578788fd5b8794505b858510156103cf576103bb8a826102fd565b8352600194909401939186019186016103a9565b5098975050505050505050565b6000602082840312156103ed578081fd5b815167ffffffffffffffff80821115610404578283fd5b81840185601f820112610415578384fd5b8051925081831115610425578384fd5b610438601f8401601f191660200161050c565b915082825285602084830101111561044e578384fd5b61045f836020840160208401610533565b50949350505050565b6001600160a01b0391909116815260200190565b60208082528251828201819052600091906040908185019080840286018301878501865b838110156104fe57603f19898403018552815180518785528051808987015260606104d0828289018d8601610533565b928a01516001600160a01b0316868b015296890196601f01601f1916909401019250908601906001016104a0565b509098975050505050505050565b60405181810167ffffffffffffffff8111828210171561052b57600080fd5b604052919050565b60005b8381101561054e578181015183820152602001610536565b8381111561055d576000848401525b50505050565b6001600160a01b038116811461057857600080fd5b5056fea264697066735822122050960433c8f7ac57690ddc920d782498bf0717738735870b68637df5806b8e8f64736f6c63430006080033";
|
||||
"0x60a060405234801561001057600080fd5b5060405161092738038061092783398101604081905261002f91610044565b60601b6001600160601b031916608052610072565b600060208284031215610055578081fd5b81516001600160a01b038116811461006b578182fd5b9392505050565b60805160601c610890610097600039806083528060ab52806102fd52506108906000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80630542975c14610046578063b316ff8914610064578063f561ae4114610079575b600080fd5b61004e610081565b60405161005b919061073f565b60405180910390f35b61006c6100a5565b60405161005b9190610753565b61006c6102f7565b7f000000000000000000000000000000000000000000000000000000000000000081565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ed6ff7606040518163ffffffff1660e01b815260040160206040518083038186803b15801561010257600080fd5b505afa158015610116573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061013a91906105d8565b90506060816001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160006040518083038186803b15801561017757600080fd5b505afa15801561018b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526101b391908101906105fb565b90506060815167ffffffffffffffff811180156101cf57600080fd5b5060405190808252806020026020018201604052801561020957816020015b6101f66105af565b8152602001906001900390816101ee5790505b50905060005b82518110156102ef57604051806040016040528084838151811061022f57fe5b60200260200101516001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561026f57600080fd5b505afa158015610283573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526102ab91908101906106a6565b81526020018483815181106102bc57fe5b60200260200101516001600160a01b03168152508282815181106102dc57fe5b602090810291909101015260010161020f565b509250505090565b606060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ed6ff7606040518163ffffffff1660e01b815260040160206040518083038186803b15801561035457600080fd5b505afa158015610368573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038c91906105d8565b90506060816001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160006040518083038186803b1580156103c957600080fd5b505afa1580156103dd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261040591908101906105fb565b90506060815167ffffffffffffffff8111801561042157600080fd5b5060405190808252806020026020018201604052801561045b57816020015b6104486105af565b8152602001906001900390816104405790505b50905060005b82518110156102ef576000846001600160a01b03166334b3beee85848151811061048757fe5b60200260200101516040518263ffffffff1660e01b81526004016104ab919061073f565b60206040518083038186803b1580156104c357600080fd5b505afa1580156104d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104fb91906105d8565b90506040518060400160405280826001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561054157600080fd5b505afa158015610555573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261057d91908101906106a6565b8152602001826001600160a01b031681525083838151811061059b57fe5b602090810291909101015250600101610461565b60408051808201909152606081526000602082015290565b80516105d281610842565b92915050565b6000602082840312156105e9578081fd5b81516105f481610842565b9392505050565b6000602080838503121561060d578182fd5b825167ffffffffffffffff80821115610624578384fd5b81850186601f820112610635578485fd5b8051925081831115610645578485fd5b83830291506106558483016107eb565b8381528481019082860184840187018a101561066f578788fd5b8794505b85851015610699576106858a826105c7565b835260019490940193918601918601610673565b5098975050505050505050565b6000602082840312156106b7578081fd5b815167ffffffffffffffff808211156106ce578283fd5b81840185601f8201126106df578384fd5b80519250818311156106ef578384fd5b610702601f8401601f19166020016107eb565b9150828252856020848301011115610718578384fd5b610729836020840160208401610812565b50949350505050565b6001600160a01b03169052565b6001600160a01b0391909116815260200190565b60208082528251828201819052600091906040908185019080840286018301878501865b838110156107dd57603f19898403018552815180518785528051808987015260606107a7828289018d8601610812565b8a84015192506107b98b880184610732565b978a0197601f91909101601f19169590950190940193505090860190600101610777565b509098975050505050505050565b60405181810167ffffffffffffffff8111828210171561080a57600080fd5b604052919050565b60005b8381101561082d578181015183820152602001610815565b8381111561083c576000848401525b50505050565b6001600160a01b038116811461085757600080fd5b5056fea2646970667358221220967f9120944e2fb9b6967de3a3d8bdd8112cda206fef4ad213f58723df99cb4264736f6c63430006080033";
|
||||
|
|
Loading…
Reference in New Issue
Block a user