Skip to content

Commit

Permalink
Merge pull request #683 from aave/fix/675-return-backing-amount
Browse files Browse the repository at this point in the history
fix: Return real backing amount when backUnbacked
  • Loading branch information
The-3D authored Aug 8, 2022
2 parents 5097bc5 + 526a1e6 commit a818243
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ interface IPool {
event MintedToTreasury(address indexed reserve, uint256 amountMinted);

/**
* @dev Mints an `amount` of aTokens to the `onBehalfOf`
* @notice Mints an `amount` of aTokens to the `onBehalfOf`
* @param asset The address of the underlying asset to mint
* @param amount The amount to mint
* @param onBehalfOf The address that will receive the aTokens
Expand All @@ -226,16 +226,17 @@ interface IPool {
) external;

/**
* @dev Back the current unbacked underlying with `amount` and pay `fee`.
* @notice Back the current unbacked underlying with `amount` and pay `fee`.
* @param asset The address of the underlying asset to back
* @param amount The amount to back
* @param fee The amount paid in fees
* @return The backed amount
**/
function backUnbacked(
address asset,
uint256 amount,
uint256 fee
) external;
) external returns (uint256);

/**
* @notice Supplies an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
Expand Down
6 changes: 5 additions & 1 deletion contracts/protocol/libraries/logic/BridgeLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,22 @@ library BridgeLogic {

/**
* @notice Back the current unbacked with `amount` and pay `fee`.
* @dev It is not possible to back more than the existing unbacked amount of the reserve
* @dev Emits the `BackUnbacked` event
* @param reserve The reserve to back unbacked for
* @param asset The address of the underlying asset to repay
* @param amount The amount to back
* @param fee The amount paid in fees
* @param protocolFeeBps The fraction of fees in basis points paid to the protocol
* @return The backed amount
**/
function executeBackUnbacked(
DataTypes.ReserveData storage reserve,
address asset,
uint256 amount,
uint256 fee,
uint256 protocolFeeBps
) external {
) external returns (uint256) {
DataTypes.ReserveCache memory reserveCache = reserve.cache();

reserve.updateState(reserveCache);
Expand All @@ -137,5 +139,7 @@ library BridgeLogic {
IERC20(asset).safeTransferFrom(msg.sender, reserveCache.aTokenAddress, added);

emit BackUnbacked(asset, msg.sender, backingAmount, fee);

return backingAmount;
}
}
5 changes: 3 additions & 2 deletions contracts/protocol/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
address asset,
uint256 amount,
uint256 fee
) external virtual override onlyBridge {
BridgeLogic.executeBackUnbacked(_reserves[asset], asset, amount, fee, _bridgeProtocolFee);
) external virtual override onlyBridge returns (uint256) {
return
BridgeLogic.executeBackUnbacked(_reserves[asset], asset, amount, fee, _bridgeProtocolFee);
}

/// @inheritdoc IPool
Expand Down

0 comments on commit a818243

Please sign in to comment.