-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from euler-xyz/feat/reward_streams-integration
[WIP]Feat: reward streams integration
- Loading branch information
Showing
10 changed files
with
324 additions
and
10 deletions.
There are no files selected for viewing
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
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
Submodule reward-streams
added at
66aafc
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
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,68 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
import {IBalanceForwarder} from "./interface/IBalanceForwarder.sol"; | ||
import {IBalanceTracker} from "./interface/IBalanceTracker.sol"; | ||
|
||
/// @title BalanceForwarderModule | ||
/// @custom:security-contact [email protected] | ||
/// @author Euler Labs (https://www.eulerlabs.com/) | ||
/// @notice A generic contract to integrate with https://github.com/euler-xyz/reward-streams | ||
abstract contract BalanceForwarder is IBalanceForwarder { | ||
error NotSupported(); | ||
|
||
IBalanceTracker public immutable balanceTracker; | ||
|
||
mapping(address => bool) internal isBalanceForwarderEnabled; | ||
|
||
event EnableBalanceForwarder(address indexed _user); | ||
event DisableBalanceForwarder(address indexed _user); | ||
|
||
constructor(address _balanceTracker) { | ||
balanceTracker = IBalanceTracker(_balanceTracker); | ||
} | ||
|
||
/// @notice Enables balance forwarding for the authenticated account | ||
/// @dev Only the authenticated account can enable balance forwarding for itself | ||
/// @dev Should call the IBalanceTracker hook with the current account's balance | ||
function enableBalanceForwarder() external virtual; | ||
|
||
/// @notice Disables balance forwarding for the authenticated account | ||
/// @dev Only the authenticated account can disable balance forwarding for itself | ||
/// @dev Should call the IBalanceTracker hook with the account's balance of 0 | ||
function disableBalanceForwarder() external virtual; | ||
|
||
/// @notice Retrieve the address of rewards contract, tracking changes in account's balances | ||
/// @return The balance tracker address | ||
function balanceTrackerAddress() external view returns (address) { | ||
return address(balanceTracker); | ||
} | ||
|
||
/// @notice Retrieves boolean indicating if the account opted in to forward balance changes to the rewards contract | ||
/// @param _account Address to query | ||
/// @return True if balance forwarder is enabled | ||
function balanceForwarderEnabled(address _account) external view returns (bool) { | ||
return isBalanceForwarderEnabled[_account]; | ||
} | ||
|
||
function _enableBalanceForwarder(address _sender, uint256 _senderBalance) internal { | ||
if (address(balanceTracker) == address(0)) revert NotSupported(); | ||
|
||
isBalanceForwarderEnabled[_sender] = true; | ||
IBalanceTracker(balanceTracker).balanceTrackerHook(_sender, _senderBalance, false); | ||
|
||
emit EnableBalanceForwarder(_sender); | ||
} | ||
|
||
/// @notice Disables balance forwarding for the authenticated account | ||
/// @dev Only the authenticated account can disable balance forwarding for itself | ||
/// @dev Should call the IBalanceTracker hook with the account's balance of 0 | ||
function _disableBalanceForwarder(address _sender) internal { | ||
if (address(balanceTracker) == address(0)) revert NotSupported(); | ||
|
||
isBalanceForwarderEnabled[_sender] = false; | ||
IBalanceTracker(balanceTracker).balanceTrackerHook(_sender, 0, false); | ||
|
||
emit DisableBalanceForwarder(_sender); | ||
} | ||
} |
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
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,12 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
interface IBalanceForwarder { | ||
function balanceTrackerAddress() external view returns (address); | ||
|
||
function balanceForwarderEnabled(address account) external view returns (bool); | ||
|
||
function enableBalanceForwarder() external; | ||
|
||
function disableBalanceForwarder() external; | ||
} |
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,19 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/// @title IBalanceTracker | ||
/// @author Euler Labs (https://www.eulerlabs.com/) | ||
/// @notice Provides an interface for tracking the balance of accounts. | ||
interface IBalanceTracker { | ||
/// @notice Executes the balance tracking hook for an account. | ||
/// @dev This function is called by the Balance Forwarder contract which was enabled for the account. This function | ||
/// must be called with the current balance of the account when enabling the balance forwarding for it. This | ||
/// function must be called with 0 balance of the account when disabling the balance forwarding for it. This | ||
/// function allows to be called on zero balance transfers, when the newAccountBalance is the same as the previous | ||
/// one. To prevent DOS attacks, forfeitRecentReward should be used appropriately. | ||
/// @param account The account address to execute the hook for. | ||
/// @param newAccountBalance The new balance of the account. | ||
/// @param forfeitRecentReward Whether to forfeit the most recent reward and not update the accumulator. | ||
function balanceTrackerHook(address account, uint256 newAccountBalance, bool forfeitRecentReward) external; | ||
} |
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
Oops, something went wrong.