Skip to content
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

feat: Rebate on distribution #383

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
3 changes: 2 additions & 1 deletion script/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ abstract contract DeployBase is Script {
CSFeeDistributor feeDistributorImpl = new CSFeeDistributor({
stETH: locator.lido(),
accounting: address(accounting),
oracle: address(oracle)
oracle: address(oracle),
rebateRecipient: config.aragonAgent
});
feeDistributor = CSFeeDistributor(
_deployProxy(config.proxyAdmin, address(feeDistributorImpl))
Expand Down
3 changes: 2 additions & 1 deletion script/DeployImplementationsBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ abstract contract DeployImplementationsBase is DeployBase {
CSFeeDistributor feeDistributorImpl = new CSFeeDistributor({
stETH: locator.lido(),
accounting: address(accounting),
oracle: address(oracle)
oracle: address(oracle),
rebateRecipient: config.aragonAgent
});

verifier = new CSVerifier({
Expand Down
21 changes: 18 additions & 3 deletions src/CSFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract CSFeeDistributor is
IStETH public immutable STETH;
address public immutable ACCOUNTING;
address public immutable ORACLE;
address public immutable REBATE_RECIPIENT;

/// @notice The latest Merkle Tree root
bytes32 public treeRoot;
Expand All @@ -46,14 +47,21 @@ contract CSFeeDistributor is
/// @notice The number of _distributionDataHistory records
uint256 public distributionDataHistoryCount;

constructor(address stETH, address accounting, address oracle) {
constructor(
address stETH,
address accounting,
address oracle,
address rebateRecipient
) {
if (accounting == address(0)) revert ZeroAccountingAddress();
if (oracle == address(0)) revert ZeroOracleAddress();
if (stETH == address(0)) revert ZeroStEthAddress();
if (rebateRecipient == address(0)) revert ZeroRebateRecipientAddress();

ACCOUNTING = accounting;
STETH = IStETH(stETH);
ORACLE = oracle;
REBATE_RECIPIENT = rebateRecipient;

_disableInitializers();
}
Expand Down Expand Up @@ -97,11 +105,12 @@ contract CSFeeDistributor is
string calldata _treeCid,
string calldata _logCid,
uint256 _distributedShares,
uint256 rebateShares,
uint256 refSlot
) external {
if (msg.sender != ORACLE) revert NotOracle();
if (
totalClaimableShares + _distributedShares >
totalClaimableShares + _distributedShares + rebateShares >
STETH.sharesOf(address(this))
) {
revert InvalidShares();
Expand Down Expand Up @@ -131,6 +140,11 @@ contract CSFeeDistributor is

emit ModuleFeeDistributed(_distributedShares);

if (rebateShares > 0) {
STETH.transferShares(REBATE_RECIPIENT, rebateShares);
emit RebateTransferred(rebateShares);
}

// NOTE: Make sure off-chain tooling provides a distinct CID of a log even for empty reports, e.g. by mixing
// in a frame identifier such as reference slot to a file.
if (bytes(_logCid).length == 0) revert InvalidLogCID();
Expand All @@ -147,7 +161,8 @@ contract CSFeeDistributor is
treeRoot: treeRoot,
treeCid: treeCid,
logCid: _logCid,
distributed: _distributedShares
distributed: _distributedShares,
rebate: rebateShares
});

unchecked {
Expand Down
1 change: 1 addition & 0 deletions src/CSFeeOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ contract CSFeeOracle is
_treeCid: data.treeCid,
_logCid: data.logCid,
_distributedShares: data.distributed,
rebateShares: data.rebate,
refSlot: data.refSlot
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/ICSFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ interface ICSFeeDistributor is IAssetRecovererLib {
string logCid;
/// @notice Total amount of fees distributed in the report.
uint256 distributed;
/// @notice Amount of the rebate shares in the report
uint256 rebate;
}

/// @dev Emitted when fees are distributed
Expand All @@ -42,10 +44,14 @@ interface ICSFeeDistributor is IAssetRecovererLib {
/// @dev It logs how many shares were distributed in the latest report
event ModuleFeeDistributed(uint256 shares);

/// @dev Emitted when rebate is transferred
event RebateTransferred(uint256 shares);

error ZeroAccountingAddress();
error ZeroStEthAddress();
error ZeroAdminAddress();
error ZeroOracleAddress();
error ZeroRebateRecipientAddress();
error NotAccounting();
error NotOracle();

Expand All @@ -65,6 +71,8 @@ interface ICSFeeDistributor is IAssetRecovererLib {

function ORACLE() external view returns (address);

function REBATE_RECIPIENT() external view returns (address);

function treeRoot() external view returns (bytes32);

function treeCid() external view returns (string calldata);
Expand Down Expand Up @@ -102,12 +110,14 @@ interface ICSFeeDistributor is IAssetRecovererLib {
/// @param _treeCid an IPFS CID of the tree
/// @param _logCid an IPFS CID of the log
/// @param _distributedShares an amount of the distributed shares
/// @param rebateShares an amount of the rebate shares
/// @param refSlot refSlot of the report
function processOracleReport(
bytes32 _treeRoot,
string calldata _treeCid,
string calldata _logCid,
uint256 _distributedShares,
uint256 rebateShares,
uint256 refSlot
) external;

Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/ICSFeeOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface ICSFeeOracle is IAssetRecovererLib {
string logCid;
/// @notice Total amount of fees distributed in the report.
uint256 distributed;
/// @notice Amount of the rebate shares in the report
uint256 rebate;
}

/// @dev Emitted when a new fee distributor contract is set
Expand Down
Loading
Loading