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

Commit d4b4eca

Browse files
committed
Add borrow Flywheel and booster
1 parent 1ef956d commit d4b4eca

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity 0.8.10;
3+
4+
import { ICErc20 } from "../../../compound/CTokenInterfaces.sol";
5+
import "./IFlywheelBorrowBooster.sol";
6+
7+
contract FlywheelBorrowBooster is IFlywheelBorrowBooster {
8+
string public constant BOOSTER_TYPE = "FlywheelBorrowBooster";
9+
10+
/**
11+
@notice calculate the boosted supply of a strategy.
12+
@param strategy the strategy to calculate boosted supply of
13+
@return the boosted supply
14+
*/
15+
function boostedTotalSupply(ICErc20 strategy) external view returns (uint256) {
16+
return strategy.totalBorrows();
17+
}
18+
19+
/**
20+
@notice calculate the boosted balance of a user in a given strategy.
21+
@param strategy the strategy to calculate boosted balance of
22+
@param user the user to calculate boosted balance of
23+
@return the boosted balance
24+
*/
25+
function boostedBalanceOf(ICErc20 strategy, address user) external view returns (uint256) {
26+
return strategy.borrowBalanceCurrent(user);
27+
}
28+
}
29+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity 0.8.10;
3+
4+
import { ICErc20 } from "../../../compound/CTokenInterfaces.sol";
5+
6+
/**
7+
@title Balance Booster Module for Flywheel
8+
@notice Flywheel is a general framework for managing token incentives.
9+
It takes reward streams to various *strategies* such as staking LP tokens and divides them among *users* of those strategies.
10+
11+
The Booster module is an optional module for virtually boosting or otherwise transforming user balances.
12+
If a booster is not configured, the strategies ERC-20 balanceOf/totalSupply will be used instead.
13+
14+
Boosting logic can be associated with referrals, vote-escrow, or other strategies.
15+
16+
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.
17+
This prevents gaming of the reward calculation function by using manipulated balances when accruing.
18+
*/
19+
interface IFlywheelBorrowBooster {
20+
/**
21+
@notice calculate the boosted supply of a strategy.
22+
@param strategy the strategy to calculate boosted supply of
23+
@return the boosted supply
24+
*/
25+
function boostedTotalSupply(ICErc20 strategy) external view returns (uint256);
26+
27+
/**
28+
@notice calculate the boosted balance of a user in a given strategy.
29+
@param strategy the strategy to calculate boosted balance of
30+
@param user the user to calculate boosted balance of
31+
@return the boosted balance
32+
*/
33+
function boostedBalanceOf(ICErc20 strategy, address user) external view returns (uint256);
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity 0.8.10;
3+
4+
import { ERC20 } from "solmate/tokens/ERC20.sol";
5+
import { IonicFlywheelCore } from "./IonicFlywheelCore.sol";
6+
import "./IIonicFlywheel.sol";
7+
8+
contract IonicBorrowFlywheel is IonicFlywheelCore, IIonicFlywheel {
9+
bool public constant isRewardsDistributor = true;
10+
bool public constant isFlywheel = true;
11+
12+
function flywheelPreSupplierAction(address market, address supplier) external {}
13+
14+
function flywheelPreBorrowerAction(address market, address borrower) external {
15+
accrue(ERC20(market), borrower);
16+
}
17+
18+
function flywheelPreTransferAction(
19+
address market,
20+
address src,
21+
address dst
22+
) external {}
23+
24+
function compAccrued(address user) external view returns (uint256) {
25+
return _rewardsAccrued[user];
26+
}
27+
28+
function addMarketForRewards(ERC20 strategy) external onlyOwner {
29+
_addStrategyForRewards(strategy);
30+
}
31+
32+
// TODO remove
33+
function marketState(ERC20 strategy) external view returns (uint224, uint32) {
34+
return (_strategyState[strategy].index, _strategyState[strategy].lastUpdatedTimestamp);
35+
}
36+
}

0 commit comments

Comments
 (0)