Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Add borrow Flywheel and booster
Browse files Browse the repository at this point in the history
  • Loading branch information
antisaa committed Jul 8, 2024
1 parent 1ef956d commit d4b4eca
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contracts/ionic/strategies/flywheel/FlywheelBorrowBooster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;

import { ICErc20 } from "../../../compound/CTokenInterfaces.sol";
import "./IFlywheelBorrowBooster.sol";

contract FlywheelBorrowBooster is IFlywheelBorrowBooster {
string public constant BOOSTER_TYPE = "FlywheelBorrowBooster";

/**
@notice calculate the boosted supply of a strategy.
@param strategy the strategy to calculate boosted supply of
@return the boosted supply
*/
function boostedTotalSupply(ICErc20 strategy) external view returns (uint256) {
return strategy.totalBorrows();
}

/**
@notice calculate the boosted balance of a user in a given strategy.
@param strategy the strategy to calculate boosted balance of
@param user the user to calculate boosted balance of
@return the boosted balance
*/
function boostedBalanceOf(ICErc20 strategy, address user) external view returns (uint256) {
return strategy.borrowBalanceCurrent(user);
}
}

34 changes: 34 additions & 0 deletions contracts/ionic/strategies/flywheel/IFlywheelBorrowBooster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;

import { ICErc20 } from "../../../compound/CTokenInterfaces.sol";

/**
@title Balance Booster Module for Flywheel
@notice Flywheel is a general framework for managing token incentives.
It takes reward streams to various *strategies* such as staking LP tokens and divides them among *users* of those strategies.
The Booster module is an optional module for virtually boosting or otherwise transforming user balances.
If a booster is not configured, the strategies ERC-20 balanceOf/totalSupply will be used instead.
Boosting logic can be associated with referrals, vote-escrow, or other strategies.
SECURITY NOTE: similar to how Core needs to be notified any time the strategy user composition changes, the booster would need to be notified of any conditions which change the boosted balances atomically.
This prevents gaming of the reward calculation function by using manipulated balances when accruing.
*/
interface IFlywheelBorrowBooster {
/**
@notice calculate the boosted supply of a strategy.
@param strategy the strategy to calculate boosted supply of
@return the boosted supply
*/
function boostedTotalSupply(ICErc20 strategy) external view returns (uint256);

/**
@notice calculate the boosted balance of a user in a given strategy.
@param strategy the strategy to calculate boosted balance of
@param user the user to calculate boosted balance of
@return the boosted balance
*/
function boostedBalanceOf(ICErc20 strategy, address user) external view returns (uint256);
}
36 changes: 36 additions & 0 deletions contracts/ionic/strategies/flywheel/IonicBorrowFlywheel.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;

import { ERC20 } from "solmate/tokens/ERC20.sol";
import { IonicFlywheelCore } from "./IonicFlywheelCore.sol";
import "./IIonicFlywheel.sol";

contract IonicBorrowFlywheel is IonicFlywheelCore, IIonicFlywheel {
bool public constant isRewardsDistributor = true;
bool public constant isFlywheel = true;

function flywheelPreSupplierAction(address market, address supplier) external {}

function flywheelPreBorrowerAction(address market, address borrower) external {
accrue(ERC20(market), borrower);
}

function flywheelPreTransferAction(
address market,
address src,
address dst
) external {}

function compAccrued(address user) external view returns (uint256) {
return _rewardsAccrued[user];
}

function addMarketForRewards(ERC20 strategy) external onlyOwner {
_addStrategyForRewards(strategy);
}

// TODO remove
function marketState(ERC20 strategy) external view returns (uint224, uint32) {
return (_strategyState[strategy].index, _strategyState[strategy].lastUpdatedTimestamp);
}
}

0 comments on commit d4b4eca

Please sign in to comment.