2021-01-27 14:43:34 +00:00
|
|
|
import { APPROVAL_AMOUNT_LENDING_POOL, MAX_UINT_AMOUNT, ZERO_ADDRESS } from '../helpers/constants';
|
|
|
|
import { convertToCurrencyDecimals } from '../helpers/contracts-helpers';
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import { ethers } from 'ethers';
|
|
|
|
import { RateMode, ProtocolErrors } from '../helpers/types';
|
|
|
|
import { makeSuite, TestEnv } from './helpers/make-suite';
|
|
|
|
import { CommonsConfig } from '../markets/aave/commons';
|
2020-08-25 15:15:27 +00:00
|
|
|
|
|
|
|
const AAVE_REFERRAL = CommonsConfig.ProtocolGlobalParams.AaveReferral;
|
2020-07-13 08:54:08 +00:00
|
|
|
|
|
|
|
makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
|
2020-06-12 08:39:42 +00:00
|
|
|
const {
|
|
|
|
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
|
|
|
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
2020-10-14 09:03:32 +00:00
|
|
|
VL_TRANSFER_NOT_ALLOWED,
|
2020-06-12 08:39:42 +00:00
|
|
|
} = ProtocolErrors;
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const { users, pool, dai, aDai } = testEnv;
|
2020-06-10 15:01:32 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
await dai.connect(users[0].signer).mint(await convertToCurrencyDecimals(dai.address, '1000'));
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-09 09:11:19 +00:00
|
|
|
//user 1 deposits 1000 DAI
|
2020-07-13 08:54:08 +00:00
|
|
|
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-09-09 10:47:27 +00:00
|
|
|
await pool
|
|
|
|
.connect(users[0].signer)
|
|
|
|
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit);
|
2020-06-09 14:36:33 +00:00
|
|
|
|
2020-10-28 17:39:19 +00:00
|
|
|
const name = await aDai.name();
|
|
|
|
|
|
|
|
expect(name).to.be.equal('Aave interest bearing DAI');
|
|
|
|
|
2020-06-12 07:41:30 +00:00
|
|
|
const fromBalance = await aDai.balanceOf(users[0].address);
|
|
|
|
const toBalance = await aDai.balanceOf(users[1].address);
|
2020-06-09 14:36:33 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
expect(fromBalance.toString()).to.be.equal('0', INVALID_FROM_BALANCE_AFTER_TRANSFER);
|
2020-06-09 14:36:33 +00:00
|
|
|
expect(toBalance.toString()).to.be.equal(
|
|
|
|
amountDAItoDeposit.toString(),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_TO_BALANCE_AFTER_TRANSFER
|
2020-06-09 14:36:33 +00:00
|
|
|
);
|
2020-06-09 09:11:19 +00:00
|
|
|
});
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-10-29 10:57:43 +00:00
|
|
|
it('User 0 deposits 1 WETH and user 1 tries to borrow the WETH with the received DAI as collateral', async () => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const { users, pool, weth, helpersContract } = testEnv;
|
2020-09-09 10:47:27 +00:00
|
|
|
const userAddress = await pool.signer.getAddress();
|
2020-06-10 15:01:32 +00:00
|
|
|
|
2020-08-13 17:25:29 +00:00
|
|
|
await weth.connect(users[0].signer).mint(await convertToCurrencyDecimals(weth.address, '1'));
|
|
|
|
|
|
|
|
await weth.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
2020-08-25 15:15:27 +00:00
|
|
|
|
2020-09-09 10:47:27 +00:00
|
|
|
await pool
|
|
|
|
.connect(users[0].signer)
|
|
|
|
.deposit(weth.address, ethers.utils.parseEther('1.0'), userAddress, '0');
|
2020-06-10 15:01:32 +00:00
|
|
|
await pool
|
|
|
|
.connect(users[1].signer)
|
2020-09-09 12:33:05 +00:00
|
|
|
.borrow(
|
|
|
|
weth.address,
|
|
|
|
ethers.utils.parseEther('0.1'),
|
|
|
|
RateMode.Stable,
|
|
|
|
AAVE_REFERRAL,
|
|
|
|
users[1].address
|
|
|
|
);
|
2020-06-10 11:46:42 +00:00
|
|
|
|
2020-10-30 12:40:06 +00:00
|
|
|
const userReserveData = await helpersContract.getUserReserveData(
|
|
|
|
weth.address,
|
|
|
|
users[1].address
|
|
|
|
);
|
|
|
|
|
2020-10-29 10:57:43 +00:00
|
|
|
expect(userReserveData.currentStableDebt.toString()).to.be.eq(ethers.utils.parseEther('0.1'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('User 1 tries to transfer all the DAI used as collateral back to user 0 (revert expected)', async () => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const { users, pool, aDai, dai, weth } = testEnv;
|
2020-10-29 10:57:43 +00:00
|
|
|
|
|
|
|
const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '1000');
|
2020-10-30 12:40:06 +00:00
|
|
|
|
2020-06-10 11:46:42 +00:00
|
|
|
await expect(
|
2020-06-12 07:41:30 +00:00
|
|
|
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
|
2020-10-14 09:03:32 +00:00
|
|
|
VL_TRANSFER_NOT_ALLOWED
|
|
|
|
).to.be.revertedWith(VL_TRANSFER_NOT_ALLOWED);
|
2020-07-14 12:43:43 +00:00
|
|
|
});
|
2020-10-29 10:57:43 +00:00
|
|
|
|
|
|
|
it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const { users, pool, aDai, dai, weth } = testEnv;
|
2020-10-29 10:57:43 +00:00
|
|
|
|
|
|
|
const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '100');
|
2020-10-30 12:40:06 +00:00
|
|
|
|
2020-10-29 10:57:43 +00:00
|
|
|
await aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer);
|
|
|
|
|
|
|
|
const user0Balance = await aDai.balanceOf(users[0].address);
|
|
|
|
|
|
|
|
expect(user0Balance.toString()).to.be.eq(aDAItoTransfer.toString());
|
2020-10-30 12:40:06 +00:00
|
|
|
});
|
2020-06-09 09:11:19 +00:00
|
|
|
});
|