From 068e9b90bd46e70181ca9bc2c0783005ac21812e Mon Sep 17 00:00:00 2001 From: prateek105 Date: Thu, 7 Sep 2023 19:39:18 +0530 Subject: [PATCH] Return amount repaid in repayDebt and amount take in take --- src/ERC20Pool.sol | 8 ++++++-- src/ERC721Pool.sol | 8 ++++++-- src/interfaces/pool/commons/IPoolTakerActions.sol | 3 ++- src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol | 3 ++- src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol | 3 ++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ERC20Pool.sol b/src/ERC20Pool.sol index 20ee2f00a..c1181a572 100644 --- a/src/ERC20Pool.sol +++ b/src/ERC20Pool.sol @@ -213,7 +213,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { uint256 collateralAmountToPull_, address collateralReceiver_, uint256 limitIndex_ - ) external nonReentrant { + ) external nonReentrant returns (uint256 amountRepaid_) { PoolState memory poolState = _accruePoolInterest(); // ensure accounting is performed using the appropriate token scale @@ -273,6 +273,8 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { // move collateral from pool to address specified as collateral receiver _transferCollateral(collateralReceiver_, collateralAmountToPull_); } + + amountRepaid_ = result.quoteTokenToRepay; } /*********************************/ @@ -396,7 +398,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { uint256 maxAmount_, address callee_, bytes calldata data_ - ) external override nonReentrant { + ) external override nonReentrant returns (uint256 collateralTaken_) { PoolState memory poolState = _accruePoolInterest(); uint256 collateralTokenScale = _getArgUint256(COLLATERAL_SCALE); @@ -430,6 +432,8 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { } _transferQuoteTokenFrom(msg.sender, result.quoteTokenAmount); + + collateralTaken_ = result.collateralAmount; } /** diff --git a/src/ERC721Pool.sol b/src/ERC721Pool.sol index 668980fa5..b20555ead 100644 --- a/src/ERC721Pool.sol +++ b/src/ERC721Pool.sol @@ -229,7 +229,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { uint256 noOfNFTsToPull_, address collateralReceiver_, uint256 limitIndex_ - ) external nonReentrant { + ) external nonReentrant returns (uint256 amountRepaid_) { PoolState memory poolState = _accruePoolInterest(); // ensure accounting is performed using the appropriate token scale @@ -290,6 +290,8 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { // move collateral from pool to address specified as collateral receiver _transferFromPoolToAddress(collateralReceiver_, borrowerTokenIds[msg.sender], noOfNFTsToPull_); } + + amountRepaid_ = result.quoteTokenToRepay; } /*********************************/ @@ -452,7 +454,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { uint256 collateral_, address callee_, bytes calldata data_ - ) external override nonReentrant { + ) external override nonReentrant returns (uint256 collateralTaken_) { PoolState memory poolState = _accruePoolInterest(); TakeResult memory result = TakerActions.take( @@ -493,6 +495,8 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { // transfer from pool to borrower the excess of quote tokens after rounding collateral auctioned if (result.excessQuoteToken != 0) _transferQuoteToken(borrowerAddress_, result.excessQuoteToken); + + collateralTaken_ = result.collateralAmount / 1e18; } /** diff --git a/src/interfaces/pool/commons/IPoolTakerActions.sol b/src/interfaces/pool/commons/IPoolTakerActions.sol index 5d97b5aac..8303392e1 100644 --- a/src/interfaces/pool/commons/IPoolTakerActions.sol +++ b/src/interfaces/pool/commons/IPoolTakerActions.sol @@ -27,13 +27,14 @@ interface IPoolTakerActions { * @param data_ If provided, take will assume the callee implements `IERC*Taker`. Take will send collateral to * callee before passing this data to `IERC*Taker.atomicSwapCallback`. If not provided, * the callback function will not be invoked. + * @return collateralTaken_ Amount of collateral taken from the auction (`WAD` precision for `ERC20` pools, max number of `NFT`s for `ERC721` pools). */ function take( address borrowerAddress_, uint256 maxAmount_, address callee_, bytes calldata data_ - ) external; + ) external returns (uint256 collateralTaken_); /***********************/ /*** Reserve Auction ***/ diff --git a/src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol b/src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol index 666cc95e1..e87e16f39 100644 --- a/src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol +++ b/src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol @@ -30,6 +30,7 @@ interface IERC20PoolBorrowerActions { * @param collateralAmountToPull_ The max amount of collateral to be puled from the pool (`WAD` precision). * @param recipient_ The address to receive amount of pulled collateral. * @param limitIndex_ Ensures `LUP` has not moved far from state when borrower pulls collateral. + * @return amountRepaid_ The amount of quote token repaid (`WAD` precision). */ function repayDebt( address borrowerAddress_, @@ -37,5 +38,5 @@ interface IERC20PoolBorrowerActions { uint256 collateralAmountToPull_, address recipient_, uint256 limitIndex_ - ) external; + ) external returns (uint256 amountRepaid_); } diff --git a/src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol b/src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol index fbaf4b59b..933b4d009 100644 --- a/src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol +++ b/src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol @@ -30,6 +30,7 @@ interface IERC721PoolBorrowerActions { * @param noOfNFTsToPull_ The integer number of `NFT` collateral to be puled from the pool. * @param recipient_ The address to receive amount of pulled collateral. * @param limitIndex_ Ensures `LUP` has not moved far from state when borrower pulls collateral. + * @return amountRepaid_ The amount of quote token repaid (`WAD` precision). */ function repayDebt( address borrowerAddress_, @@ -37,5 +38,5 @@ interface IERC721PoolBorrowerActions { uint256 noOfNFTsToPull_, address recipient_, uint256 limitIndex_ - ) external; + ) external returns (uint256 amountRepaid_); }