This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
contracts/ionic/strategies/flywheel/FlywheelBorrowBooster.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
contracts/ionic/strategies/flywheel/IFlywheelBorrowBooster.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
contracts/ionic/strategies/flywheel/IonicBorrowFlywheel.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |