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 (250) #250

Merged
merged 3 commits into from
Aug 11, 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
4 changes: 2 additions & 2 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,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(repaid, data);

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

emit FlashLoan(msg.sender, token, amount);

IBlueFlashLoanCallback(msg.sender).onBlueFlashLoan(token, amount, data);
IBlueFlashLoanCallback(msg.sender).onBlueFlashLoan(amount, data);

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

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

interface IBlueRepayCallback {
Expand All @@ -18,5 +18,5 @@ interface IBlueSupplyCollateralCallback {
}

interface IBlueFlashLoanCallback {
function onBlueFlashLoan(address token, uint256 amount, bytes calldata data) external;
function onBlueFlashLoan(uint256 amount, bytes calldata data) external;
}
3 changes: 2 additions & 1 deletion src/mocks/FlashBorrowerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ contract FlashBorrowerMock is IBlueFlashLoanCallback {
BLUE.flashLoan(token, amount, data);
}

function onBlueFlashLoan(address token, uint256 amount, bytes calldata) external {
function onBlueFlashLoan(uint256 amount, bytes calldata data) external {
require(msg.sender == address(BLUE));
address token = abi.decode(data, (address));
ERC20(token).safeApprove(address(BLUE), amount);
}
}
6 changes: 3 additions & 3 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ contract BlueTest is
}
}

function onBlueLiquidate(uint256, uint256 repaid, bytes memory data) external {
function onBlueLiquidate(uint256 repaid, bytes memory data) external {
require(msg.sender == address(blue));
bytes4 selector;
(selector, data) = abi.decode(data, (bytes4, bytes));
Expand All @@ -985,8 +985,8 @@ contract BlueTest is
}
}

function onBlueFlashLoan(address token, uint256 amount, bytes calldata) external {
ERC20(token).approve(address(blue), amount);
function onBlueFlashLoan(uint256 amount, bytes calldata) external {
borrowableAsset.approve(address(blue), amount);
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/hardhat/Blue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe("Blue", () => {

await blue.connect(user).supply(market, amount, user.address, "0x");

await flashBorrower.flashLoan(borrowable.address, amount.div(2), []);
const data = defaultAbiCoder.encode(["address"], [borrowable.address]);
await flashBorrower.flashLoan(borrowable.address, amount.div(2), data);
});
});