Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add returns for take and repayDebt #947

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/ERC20Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool {
uint256 collateralAmountToPull_,
address collateralReceiver_,
uint256 limitIndex_
) external nonReentrant {
) external nonReentrant returns (uint256 amountRepaid_) {
MikeHathaway marked this conversation as resolved.
Show resolved Hide resolved
PoolState memory poolState = _accruePoolInterest();

// ensure accounting is performed using the appropriate token scale
Expand Down Expand Up @@ -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;
}

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

/*********************************/
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

/**
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_);
}
Loading