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

Harmonize callbacks interfaces (260) #260

Closed
wants to merge 1 commit into from
Closed
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
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);
MathisGD marked this conversation as resolved.
Show resolved Hide resolved

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