Skip to content

Commit

Permalink
refactor: harmonize callbacks interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Aug 10, 2023
1 parent b04316d commit 6e556cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ contract Blue is IBlue {

emit Supply(id, msg.sender, onBehalf, amount, shares);

if (data.length > 0) IBlueSupplyCallback(msg.sender).onBlueSupply(amount, data);
if (data.length > 0) IBlueSupplyCallback(msg.sender).onBlueSupply(market.borrowableAsset, amount, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), amount);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ contract Blue is IBlue {

emit Repay(id, msg.sender, onBehalf, amount, shares);

if (data.length > 0) IBlueRepayCallback(msg.sender).onBlueRepay(amount, data);
if (data.length > 0) IBlueRepayCallback(msg.sender).onBlueRepay(market.borrowableAsset, amount, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), amount);
}
Expand All @@ -262,7 +262,9 @@ contract Blue is IBlue {

emit SupplyCollateral(id, msg.sender, onBehalf, amount);

if (data.length > 0) IBlueSupplyCollateralCallback(msg.sender).onBlueSupplyCollateral(amount, data);
if (data.length > 0) {
IBlueSupplyCollateralCallback(msg.sender).onBlueSupplyCollateral(market.collateralAsset, amount, data);
}

IERC20(market.collateralAsset).safeTransferFrom(msg.sender, address(this), amount);
}
Expand Down Expand Up @@ -326,7 +328,7 @@ contract Blue is IBlue {

emit Liquidate(id, msg.sender, borrower, repaid, repaidShares, seized, badDebtShares);

if (data.length > 0) IBlueLiquidateCallback(msg.sender).onBlueLiquidate(seized, repaid, data);
if (data.length > 0) IBlueLiquidateCallback(msg.sender).onBlueLiquidate(market.borrowableAsset, repaid, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), repaid);
}
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/IBlueCallbacks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
pragma solidity >=0.5.0;

interface IBlueLiquidateCallback {
function onBlueLiquidate(uint256 seized, uint256 repaid, bytes calldata data) external;
function onBlueLiquidate(address token, uint256 amount, bytes calldata data) external;
}

interface IBlueRepayCallback {
function onBlueRepay(uint256 amount, bytes calldata data) external;
function onBlueRepay(address token, uint256 amount, bytes calldata data) external;
}

interface IBlueSupplyCallback {
function onBlueSupply(uint256 amount, bytes calldata data) external;
function onBlueSupply(address token, uint256 amount, bytes calldata data) external;
}

interface IBlueSupplyCollateralCallback {
function onBlueSupplyCollateral(uint256 amount, bytes calldata data) external;
function onBlueSupplyCollateral(address token, uint256 amount, bytes calldata data) external;
}

interface IBlueFlashLoanCallback {
Expand Down
16 changes: 8 additions & 8 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -991,21 +991,21 @@ contract BlueTest is

// Callback functions.

function onBlueSupply(uint256 amount, bytes memory data) external {
function onBlueSupply(address token, uint256 amount, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
(selector, data) = abi.decode(data, (bytes4, bytes));
if (selector == this.testSupplyCallback.selector) {
borrowableAsset.approve(address(blue), amount);
ERC20(token).approve(address(blue), amount);
}
}

function onBlueSupplyCollateral(uint256 amount, bytes memory data) external {
function onBlueSupplyCollateral(address token, uint256 amount, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
(selector, data) = abi.decode(data, (bytes4, bytes));
if (selector == this.testSupplyCollateralCallback.selector) {
collateralAsset.approve(address(blue), amount);
ERC20(token).approve(address(blue), amount);
} else if (selector == this.testFlashActions.selector) {
uint256 toBorrow = abi.decode(data, (uint256));
collateralAsset.setBalance(address(this), amount);
Expand All @@ -1014,24 +1014,24 @@ contract BlueTest is
}
}

function onBlueRepay(uint256 amount, bytes memory data) external {
function onBlueRepay(address token, uint256 amount, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
(selector, data) = abi.decode(data, (bytes4, bytes));
if (selector == this.testRepayCallback.selector) {
borrowableAsset.approve(address(blue), amount);
ERC20(token).approve(address(blue), amount);
} else if (selector == this.testFlashActions.selector) {
uint256 toWithdraw = abi.decode(data, (uint256));
blue.withdrawCollateral(market, toWithdraw, address(this), address(this));
}
}

function onBlueLiquidate(uint256, uint256 repaid, bytes memory data) external {
function onBlueLiquidate(address token, uint256 amount, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
(selector, data) = abi.decode(data, (bytes4, bytes));
if (selector == this.testLiquidateCallback.selector) {
borrowableAsset.approve(address(blue), repaid);
ERC20(token).approve(address(blue), amount);
}
}

Expand Down

0 comments on commit 6e556cf

Please sign in to comment.