Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Liquidate like tiran #32

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Next Next commit
test env
  • Loading branch information
yaronvel committed Oct 20, 2021
commit 7606a7ddb1f006ef27f8248a8295ff606f1e30d2
37 changes: 37 additions & 0 deletions contracts/BKashiPair.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: UNLICENSED


pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "./KashiPair.sol";

contract BKashiPair is KashiPair {
address public bprotocol;

event BProtocol(address bprotocol_);

/// @notice The constructor is only used for the initial master contract. Subsequent clones are initialised via `init`.
constructor(IBentoBoxV1 bentoBox_) public KashiPair(bentoBox_) {}

function setBProtocol(address bprotocol_) public onlyOwner {
require(bprotocol == address(0x0)/*, "BKashiPair: bprotocol alread initialized"*/);
bprotocol = bprotocol_;
emit BProtocol(bprotocol_);
}

function liquidate(
address[] calldata users,
uint256[] calldata maxBorrowParts,
address to,
ISwapper swapper,
bool open
) public
override
{
if(bprotocol != address(0x0) && bprotocol != address(0xdead)) {
require(msg.sender == bprotocol, "liquidate: not bprotocol");
}

super.liquidate(users, maxBorrowParts, to, swapper, open);
}
}
8 changes: 5 additions & 3 deletions contracts/KashiPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ contract KashiPair is ERC20, BoringOwnable, IMasterContract {
callData = abi.encodePacked(callData, value1, value2);
}

require(callee != address(bentoBox) && callee != address(this), "KashiPair: can't call");
require(callee != address(bentoBox) && callee != address(this));

(bool success, bytes memory returnData) = callee.call{value: value}(callData);
require(success, "KashiPair: call failed");
require(success);
return (returnData, returnValues);
}

Expand Down Expand Up @@ -607,7 +607,9 @@ contract KashiPair is ERC20, BoringOwnable, IMasterContract {
address to,
ISwapper swapper,
bool open
) public {
) public
virtual
{
// Oracle can fail but we still need to allow liquidations
(, uint256 _exchangeRate) = updateExchangeRate();
accrue();
Expand Down
20 changes: 19 additions & 1 deletion contracts/mocks/KashiPairMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@sushiswap/bentobox-sdk/contracts/IBentoBoxV1.sol";
import "../KashiPair.sol";
import "../BKashiPair.sol";

contract KashiPairMock is KashiPair {
contract KashiPairMock is KashiPair {
constructor(IBentoBoxV1 bentoBox) public KashiPair(bentoBox) {
return;
}
Expand All @@ -14,3 +15,20 @@ contract KashiPairMock is KashiPair {
accrue();
}
}

contract BKashiPairMock is BKashiPair {
constructor(IBentoBoxV1 bentoBox) public BKashiPair(bentoBox) {
return;
}

function accrueTwice() public {
accrue();
accrue();
}

function setBProtocolMock(address bprotocol_) public {
require(bprotocol == address(0x0)/*, "BKashiPair: bprotocol alread initialized"*/);
bprotocol = bprotocol_;
emit BProtocol(bprotocol_);
}
}