From 59fe289eba9e6bfb830cb5ce048c6d2d15a2f276 Mon Sep 17 00:00:00 2001 From: Piotr Dyraga Date: Tue, 26 Apr 2022 11:43:33 +0200 Subject: [PATCH] Added reward-related functions to IApplication interface The interface is minimal and does not enforce any specific requirements on how the rewards are actually accrued. `function withdrawRewards(address stakingProvider) external` withdraws application rewards for the given staking provider. Rewards are withdrawn to the staking provider's beneficiary address set in the staking contract. Function emits `RewardsWithdrawn(address indexed stakingProvider, uint96 amount)` so that applications can easily track the total amount of rewards accrued so far. `function availableRewards(address stakingProvider)` Returns the amount of application rewards available for withdrawal for the given staking provider. --- contracts/staking/IApplication.sol | 16 ++++++++++++++++ contracts/test/TokenStakingTestSet.sol | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/contracts/staking/IApplication.sol b/contracts/staking/IApplication.sol index e55ce206..c241c52a 100644 --- a/contracts/staking/IApplication.sol +++ b/contracts/staking/IApplication.sol @@ -22,6 +22,15 @@ pragma solidity 0.8.9; /// staking provider are eligible to slash the stake delegated to that /// staking provider. interface IApplication { + /// @dev Event emitted by `withdrawRewards` function. + event RewardsWithdrawn(address indexed stakingProvider, uint96 amount); + + /// @notice Withdraws application rewards for the given staking provider. + /// Rewards are withdrawn to the staking provider's beneficiary + /// address set in the staking contract. + /// @dev Emits `RewardsWithdrawn` event. + function withdrawRewards(address stakingProvider) external; + /// @notice Used by T staking contract to inform the application that the /// authorized amount for the given staking provider increased. /// The application may do any necessary housekeeping. The @@ -57,6 +66,13 @@ interface IApplication { uint96 toAmount ) external; + /// @notice Returns the amount of application rewards available for + /// withdrawal for the given staking provider. + function availableRewards(address stakingProvider) + external + view + returns (uint96); + /// @notice The minimum authorization amount required for the staking /// provider so that they can participate in the application. function minimumAuthorization() external view returns (uint96); diff --git a/contracts/test/TokenStakingTestSet.sol b/contracts/test/TokenStakingTestSet.sol index 954e3c8f..36c1e143 100644 --- a/contracts/test/TokenStakingTestSet.sol +++ b/contracts/test/TokenStakingTestSet.sol @@ -209,6 +209,10 @@ contract ApplicationMock is IApplication { tokenStaking = _tokenStaking; } + function withdrawRewards(address) external { + // does nothing + } + function authorizationIncreased( address stakingProvider, uint96, @@ -272,7 +276,11 @@ contract ApplicationMock is IApplication { stakingProviderStruct.authorized = toAmount; } - function minimumAuthorization() external view returns (uint96) { + function availableRewards(address) external pure returns (uint96) { + return 0; + } + + function minimumAuthorization() external pure returns (uint96) { return 0; } }