Merge branch 'feat/104-withdraw-to' into 'master'

Added `to` to withdraw()

Closes #104

See merge request aave-tech/protocol-v2!113
This commit is contained in:
The-3D 2020-10-30 12:25:12 +00:00
commit 38b579b44a
4 changed files with 32 additions and 11 deletions

View File

@ -27,9 +27,10 @@ interface ILendingPool {
* @dev emitted during a withdraw action. * @dev emitted during a withdraw action.
* @param reserve the address of the reserve * @param reserve the address of the reserve
* @param user the address of the user * @param user the address of the user
* @param to address that will receive the underlying
* @param amount the amount to be withdrawn * @param amount the amount to be withdrawn
**/ **/
event Withdraw(address indexed reserve, address indexed user, uint256 amount); event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);
event BorrowAllowanceDelegated( event BorrowAllowanceDelegated(
address indexed asset, address indexed asset,
@ -188,8 +189,13 @@ interface ILendingPool {
* @dev withdraws the assets of user. * @dev withdraws the assets of user.
* @param reserve the address of the reserve * @param reserve the address of the reserve
* @param amount the underlying amount to be redeemed * @param amount the underlying amount to be redeemed
* @param to address that will receive the underlying
**/ **/
function withdraw(address reserve, uint256 amount) external; function withdraw(
address reserve,
uint256 amount,
address to
) external;
/** /**
* @dev Sets allowance to borrow on a certain type of debt asset for a certain user address * @dev Sets allowance to borrow on a certain type of debt asset for a certain user address

View File

@ -120,8 +120,13 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @dev withdraws the _reserves of user. * @dev withdraws the _reserves of user.
* @param asset the address of the reserve * @param asset the address of the reserve
* @param amount the underlying amount to be redeemed * @param amount the underlying amount to be redeemed
* @param to address that will receive the underlying
**/ **/
function withdraw(address asset, uint256 amount) external override { function withdraw(
address asset,
uint256 amount,
address to
) external override {
_whenNotPaused(); _whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
@ -155,9 +160,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false); _usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false);
} }
IAToken(aToken).burn(msg.sender, msg.sender, amountToWithdraw, reserve.liquidityIndex); IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex);
emit Withdraw(asset, msg.sender, amountToWithdraw); emit Withdraw(asset, msg.sender, to, amountToWithdraw);
} }
/** /**

View File

@ -231,7 +231,7 @@ export const withdraw = async (
if (expectedResult === 'success') { if (expectedResult === 'success') {
const txResult = await waitForTx( const txResult = await waitForTx(
await pool.connect(user.signer).withdraw(reserve, amountToWithdraw) await pool.connect(user.signer).withdraw(reserve, amountToWithdraw, user.address)
); );
const { const {
@ -269,8 +269,10 @@ export const withdraw = async (
// ); // );
// }); // });
} else if (expectedResult === 'revert') { } else if (expectedResult === 'revert') {
await expect(pool.connect(user.signer).withdraw(reserve, amountToWithdraw), revertMessage).to.be await expect(
.reverted; pool.connect(user.signer).withdraw(reserve, amountToWithdraw, user.address),
revertMessage
).to.be.reverted;
} }
}; };

View File

@ -116,7 +116,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// user tries to burn // user tries to burn
await expect( await expect(
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit) pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit, users[0].address)
).to.revertedWith(IS_PAUSED); ).to.revertedWith(IS_PAUSED);
// Configurator unpauses the pool // Configurator unpauses the pool
@ -187,7 +187,15 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
await expect( await expect(
pool pool
.connect(caller.signer) .connect(caller.signer)
.flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, caller.address, '0x10', '0') .flashLoan(
_mockFlashLoanReceiver.address,
[weth.address],
[flashAmount],
1,
caller.address,
'0x10',
'0'
)
).revertedWith(IS_PAUSED); ).revertedWith(IS_PAUSED);
// Unpause pool // Unpause pool