Skip to content

feat: version 3.1 #5

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions .github/workflows/forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Forge

on:
push:
branches:
- "main"
branches: ["main", "next"]
pull_request:
branches:
- "main"
branches: ["main", "next"]

env:
HUSKY: 0
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Release

on:
push:
branches:
- "main"
branches: ["main", "next"]

env:
HUSKY: 0
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules/

# Compiler files
forge-out/
out/
cache/

# Dotenv file
Expand Down
16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/@openzeppelin"]
path = lib/@openzeppelin
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/@1inch/solidity-utils"]
path = lib/@1inch/solidity-utils
url = https://github.com/1inch/solidity-utils
[submodule "lib/@gearbox-protocol/sdk-gov"]
path = lib/@gearbox-protocol/sdk-gov
url = https://github.com/Gearbox-protocol/sdk-gov
[submodule "lib/@gearbox-protocol/core-v3"]
path = lib/@gearbox-protocol/core-v3
url = https://github.com/Gearbox-protocol/core-v3
branch = next
5 changes: 5 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"branches": [
{
"name": "main"
},
{
"name": "next",
"channel": "next",
"prerelease": "next"
}
],
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
},
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "node_modules",
"solidity.compileUsingRemoteVersion": "v0.8.17",
"solidity.packageDefaultDependenciesDirectory": "lib",
"solidity.compileUsingRemoteVersion": "v0.8.23",
}
202 changes: 106 additions & 96 deletions contracts/bots/PartialLiquidationBotV3.sol

Large diffs are not rendered by default.

63 changes: 13 additions & 50 deletions contracts/interfaces/IPartialLiquidationBotV3.sol
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;
pragma solidity ^0.8.23;

import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol";
import {IBot} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IBot.sol";
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";

/// @title Partial liquidation bot V3
/// @author Gearbox Foundation
interface IPartialLiquidationBotV3 is IVersion {
// ----- //
// TYPES //
// ----- //

/// @notice Update params for an on-demand price feed in the price oracle
/// @param token Token to update the price for
/// @param reserve Whether main or reserve feed should be updated
/// @param data Update data
struct PriceUpdate {
address token;
bool reserve;
bytes data;
}

interface IPartialLiquidationBotV3 is IBot {
// ------ //
// EVENTS //
// ------ //
Expand All @@ -30,13 +18,15 @@ interface IPartialLiquidationBotV3 is IVersion {
/// @param creditManager Credit manager an account was liquidated in
/// @param creditAccount Liquidated credit account
/// @param token Collateral token seized from `creditAccount`
/// @param liquidator Liquidator that called the bot
/// @param repaidDebt Amount of `creditAccount`'s debt repaid
/// @param seizedCollateral Amount of `token` seized from `creditAccount`
/// @param fee Amount of underlying sent to the treasury as liqudiation fee
event LiquidatePartial(
event PartiallyLiquidate(
address indexed creditManager,
address indexed creditAccount,
address indexed token,
address liquidator,
uint256 repaidDebt,
uint256 seizedCollateral,
uint256 fee
Expand All @@ -52,9 +42,6 @@ interface IPartialLiquidationBotV3 is IVersion {
/// @notice Thrown when health factor after liquidation is greater than maximum allowed
error LiquidatedMoreThanNeededException();

/// @notice Thrown when amount of underlying repaid is greater than allowed
error RepaidMoreThanAllowedException();

/// @notice Thrown when amount of collateral seized is less than required
error SeizedLessThanRequiredException();

Expand Down Expand Up @@ -86,45 +73,21 @@ interface IPartialLiquidationBotV3 is IVersion {
/// @param repaidAmount Amount of underlying to repay
/// @param minSeizedAmount Minimum amount of `token` to seize from `creditAccount`
/// @param to Address to send seized `token` to
/// @param priceUpdates On-demand price feed updates to apply before calculations, see `PriceUpdate` for details
/// @param priceUpdates On-demand price feed updates to apply before calculations
/// @return seizedAmount Amount of `token` seized
/// @dev Requires underlying token approval from caller to this contract
/// @dev Reverts if `creditAccount`'s credit manager is not registered
/// @dev Reverts if `token` is underlying
/// @dev Reverts if `priceUpdates` contains updates of unknown feeds
/// @dev Reverts if `token` is underlying or if `token` is a phantom token and its `depositedToken` is underlying
/// @dev Reverts if `creditAccount`'s health factor is not less than `minHealthFactor` before liquidation
/// @dev Reverts if amount of `token` to be seized is less than `minSeizedAmount`
/// @dev Reverts if `creditAccount`'s health factor is not within allowed range after liquidation
function liquidateExactDebt(
/// @dev If `token` is a phantom token, it's withdrawn first, and its `depositedToken` is then sent to the liquidator.
/// Both `seizedAmount` and `minSeizedAmount` refer to `depositedToken` in this case.
function partiallyLiquidate(
address creditAccount,
address token,
uint256 repaidAmount,
uint256 minSeizedAmount,
address to,
PriceUpdate[] calldata priceUpdates
) external returns (uint256 seizedAmount);

/// @notice Liquidates credit account by repaying its debt in exchange for the given amount of discounted collateral
/// @param creditAccount Credit account to liquidate
/// @param token Collateral token to seize
/// @param seizedAmount Amount of `token` to seize from `creditAccount`
/// @param maxRepaidAmount Maxiumum amount of underlying to repay
/// @param to Address to send seized `token` to
/// @param priceUpdates On-demand price feed updates to apply before calculations, see `PriceUpdate` for details
/// @return repaidAmount Amount of underlying repaid
/// @dev Requires underlying token approval from caller to this contract
/// @dev Reverts if `creditAccount`'s credit manager is not registered
/// @dev Reverts if `token` is underlying
/// @dev Reverts if `priceUpdates` contains updates of unknown feeds
/// @dev Reverts if `creditAccount`'s health factor is not less than `minHealthFactor` before liquidation
/// @dev Reverts if amount of underlying to be repaid is greater than `maxRepaidAmount`
/// @dev Reverts if `creditAccount`'s health factor is not within allowed range after liquidation
function liquidateExactCollateral(
address creditAccount,
address token,
uint256 seizedAmount,
uint256 maxRepaidAmount,
address to,
PriceUpdate[] calldata priceUpdates
) external returns (uint256 repaidAmount);
}
Loading
Loading