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

👷 KSX - Remove escrow on inflationary rewards and remove staking cooldown #252

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
62462f1
👷 remove staking cooldown
Flocqst Jul 2, 2024
6006911
👷 update interface
Flocqst Jul 2, 2024
1052a6d
✅ Adapt test suite to staking cooldown removal
Flocqst Jul 2, 2024
5142e90
📚 update doc
Flocqst Jul 2, 2024
1735867
👷 Remove escrow on inflationary rewards
Flocqst Jul 5, 2024
43300af
📚 @custom:todo adjust tests to non escrowed rewards
Flocqst Jul 8, 2024
371f847
👷 Adjust compound rewards to newly non escrowed rewards
Flocqst Jul 8, 2024
b4b69a7
👷 adjust for compounding on behalf
Flocqst Jul 16, 2024
d33ee53
✅ Adjust tests to non escrowed rewards
Flocqst Jul 16, 2024
9dee0eb
✅ fix fork test
Flocqst Jul 16, 2024
fb03e81
✅ Add unstakeEscrowAdmin tests
Flocqst Jul 17, 2024
6336698
✅ rename function helper
Flocqst Jul 17, 2024
7ff1a0a
📚 Add author handle
Flocqst Jul 17, 2024
15eea33
👷 fix updateReward modifier for compoundOnBehalf
Flocqst Jul 22, 2024
9cb9509
🔀 Resolved conflicts after merging main into staking-cooldown
Flocqst Aug 27, 2024
427134b
🔀 Resolved conflicts after merging main into remove-inflation-escrow
Flocqst Aug 27, 2024
827e85c
✅ Adjust stake Escrow on behalf tests
Flocqst Aug 27, 2024
e4d6166
Merge branch 'staking-cooldown' into remove-inflation-escrow
Flocqst Aug 27, 2024
48a2b16
✅ Adjust precision delta usdc reward calculation
Flocqst Aug 27, 2024
0d173e7
👷 Remove uses of userLastStakeTime
Flocqst Sep 11, 2024
0f1db85
👷 Refactor processReward
Flocqst Sep 11, 2024
c9e48f6
👷 add updateReward(_account) modifier to _processReward()
cmontecoding Oct 28, 2024
bf210e9
✅ test_compound add assert
cmontecoding Oct 28, 2024
c6d26b6
✅ add asserts to test_compoundOnBehalf
cmontecoding Oct 28, 2024
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
75 changes: 25 additions & 50 deletions contracts/StakingRewardsV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ contract StakingRewardsV2 is
}

/// @inheritdoc IStakingRewardsV2
function unstake(uint256 _amount)
public
whenNotPaused
updateReward(msg.sender)
{
function unstake(uint256 _amount) public whenNotPaused updateReward(msg.sender) {
if (_amount == 0) revert AmountZero();
uint256 nonEscrowedBalance = nonEscrowedBalanceOf(msg.sender);
if (_amount > nonEscrowedBalance) revert InsufficientBalance(nonEscrowedBalance);
Expand Down Expand Up @@ -293,10 +289,7 @@ contract StakingRewardsV2 is
}

/// @inheritdoc IStakingRewardsV2
function unstakeEscrowAdmin(address _account, uint256 _amount)
external
onlyRewardEscrow
{
function unstakeEscrowAdmin(address _account, uint256 _amount) external onlyRewardEscrow {
_unstakeEscrow(_account, _amount);
}

Expand Down Expand Up @@ -345,61 +338,43 @@ contract StakingRewardsV2 is
whenNotPaused
updateReward(_account)
{
uint256 reward = rewards[_account];
if (reward > 0) {
// update state (first)
rewards[_account] = 0;

// emit reward claimed event and index account
emit RewardPaid(_account, reward);

// transfer token from this contract to the account
// as newly issued rewards from inflation are now issued as non-escrowed
kwenta.transfer(_to, reward);
}

uint256 rewardUSDC = rewardsUSDC[_account] / PRECISION;
if (rewardUSDC > 0) {
// update state (first)
rewardsUSDC[_account] = 0;

// emit reward claimed event and index account
emit RewardPaidUSDC(_account, rewardUSDC);

// transfer token from this contract to the account
// as newly issued rewards from inflation are now issued as non-escrowed
usdc.transfer(_to, rewardUSDC);
}
_processReward(_account, _to, true);
}

/// @notice Get the reward of the given account for compounding.
/// @dev Retrieves the Kwenta reward without transferring it, as it will be staked immediately after.
function _getRewardCompounding(address _account)
/// @notice Process KWENTA and USDC rewards
/// @dev transferKwenta is set to false when compounding KWENTA rewards
/// @param _account The address of the account to process rewards for
/// @param _to The address to transfer rewards to
/// @param transferKwenta Boolean flag to determine if Kwenta should be transferred
/// @return kwentaReward The amount of Kwenta reward processed
function _processReward(address _account, address _to, bool transferKwenta)
internal
whenNotPaused
updateReward(_account)
returns (uint256 reward)
returns (uint256 kwentaReward)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem you're using kwentaReward outside of _processReward, but for consistency sake you should either return both kwenta and USDC reward as a tuple or return neither.

{
reward = rewards[_account];
if (reward > 0) {
// Process Kwenta reward
kwentaReward = rewards[_account];
if (kwentaReward > 0) {
// update state (first)
rewards[_account] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if transferKwenta is set to false meaning they want to compound their rewards then doesnt this line ruin that?

their rewards are set to 0 but they dont get transferred their kwenta, so next time this is called again (im assuming after they waited for it to compound in this contract), then their rewards will be 0 or close to 0 and therefore they lost their kwenta entirely?

if im understanding this correctly then this rewards[_account] = 0; line shouldnt apply if transferKwenta == false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh upon further look, kwentaReward is extrapolating this value? and it hopefully gets relogged when calling _stake in _compound?


// emit reward claimed event and index account
emit RewardPaid(_account, reward);
emit RewardPaid(_account, kwentaReward);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other event is called RewardPaidUSDC

this should be called RewardPaidKwenta to match


if (transferKwenta) {
kwenta.transfer(_to, kwentaReward);
}
}

uint256 rewardUSDC = rewardsUSDC[_account] / PRECISION;
if (rewardUSDC > 0) {
// Process USDC reward
uint256 usdcReward = rewardsUSDC[_account] / PRECISION;
if (usdcReward > 0) {
// update state (first)
rewardsUSDC[_account] = 0;

// emit reward claimed event and index account
emit RewardPaidUSDC(_account, rewardUSDC);
emit RewardPaidUSDC(_account, usdcReward);

// transfer token from this contract to the account
// as newly issued rewards from inflation are now issued as non-escrowed
usdc.transfer(_account, rewardUSDC);
usdc.transfer(_to, usdcReward);
}
}

Expand All @@ -411,7 +386,7 @@ contract StakingRewardsV2 is
/// @dev internal helper to compound for a given account
/// @param _account the account to compound for
function _compound(address _account) internal {
uint256 reward = _getRewardCompounding(_account);
uint256 reward = _processReward(_account, _account, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will reward be 0 here?

_stake(_account, reward);
}

Expand Down
Loading