Skip to content

Commit

Permalink
Return amount repaid in repayDebt and amount take in take (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek105 authored Oct 12, 2023
1 parent 5784b62 commit 2151d67
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/ERC20Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,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
Expand Down Expand Up @@ -253,6 +253,8 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool {
// move collateral from pool to address specified as collateral receiver
_transferCollateral(collateralReceiver_, collateralAmountToPull_);
}

amountRepaid_ = result.quoteTokenToRepay;
}

/*********************************/
Expand Down Expand Up @@ -376,7 +378,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);
Expand Down Expand Up @@ -410,6 +412,8 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool {
}

_transferQuoteTokenFrom(msg.sender, result.quoteTokenAmount);

collateralTaken_ = result.collateralAmount;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/ERC721Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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
Expand Down Expand Up @@ -268,6 +268,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;
}

/*********************************/
Expand Down Expand Up @@ -430,7 +432,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(
Expand Down Expand Up @@ -471,6 +473,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;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/pool/commons/IPoolTakerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***/
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/pool/erc20/IERC20PoolBorrowerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ 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_,
uint256 maxQuoteTokenAmountToRepay_,
uint256 collateralAmountToPull_,
address recipient_,
uint256 limitIndex_
) external;
) external returns (uint256 amountRepaid_);
}
3 changes: 2 additions & 1 deletion src/interfaces/pool/erc721/IERC721PoolBorrowerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ 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_,
uint256 maxQuoteTokenAmountToRepay_,
uint256 noOfNFTsToPull_,
address recipient_,
uint256 limitIndex_
) external;
) external returns (uint256 amountRepaid_);
}

0 comments on commit 2151d67

Please sign in to comment.