Skip to content

Commit

Permalink
bookkeeper tracks kicks
Browse files Browse the repository at this point in the history
  • Loading branch information
funderbrker committed Jul 13, 2023
1 parent c156252 commit f4e2be4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Bookkeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ contract Bookkeeper is Tractor, ReentrancyGuard {
string public constant PROTOCOL_NAME = "pharos";
string public constant PROTOCOL_VERSION = "0.1.0";

// AUDIT: reading/writing uint256 more efficient than bool?
// Map indicating if a position has already been kicked.
mapping(bytes32 => uint256) kicked; // blueprintHash => 0/1 bool

event OrderFilled(SignedBlueprint agreement, bytes32 orderBlueprintHash, address taker);
event LiquidationKicked(address liquidator, address position);

Expand Down Expand Up @@ -137,15 +141,20 @@ contract Bookkeeper is Tractor, ReentrancyGuard {
position.transferContract(msg.sender);
}

// NOTE will need to implement an unkick function to enable soft or partial liquidations.
function kick(
SignedBlueprint calldata agreementBlueprint
) external nonReentrant verifySignature(agreementBlueprint) {
(, bytes memory blueprintData) = unpackDataField(agreementBlueprint.blueprint.data);
// require(blueprintDataType == bytes1(uint8(BlueprintDataType.AGREEMENT)), "BKKIBDT"); // decoding will fail
Agreement memory agreement = abi.decode(blueprintData, (Agreement));
IPosition position = IPosition(agreement.position.addr);
if (kicked[agreementBlueprint.blueprintHash] > 0) {
revert("kick: already kicked");
}
kicked[agreementBlueprint.blueprintHash] = 1;

require(LibBookkeeper.isLiquidatable(agreement), "kick: Position not liquidatable");
require(LibBookkeeper.isLiquidatable(agreement), "kick: not liquidatable");

IAccount(agreement.borrowerAccount.addr).unloadToPosition(
agreement.position.addr,
Expand Down

0 comments on commit f4e2be4

Please sign in to comment.