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

reintroduce stake adjustment for PAYG reward #431

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
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
28 changes: 19 additions & 9 deletions contracts/RewardsPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ contract RewardsPool is IRewardsPool, Initializable, OwnableUpgradeable, SQParam
/// @notice the denominator of the alpha
int32 public alphaDenominator;

/// @notice Adjustment for Era Rewards Pools: era => deployment => adjustment
mapping(uint256 => mapping(bytes32 => uint256)) public poolAdjustments;

/// @dev ### EVENTS
/// @notice Emitted when update the alpha for cobb-douglas function
event Alpha(int32 alphaNumerator, int32 alphaDenominator);
Expand Down Expand Up @@ -291,7 +294,8 @@ contract RewardsPool is IRewardsPool, Initializable, OwnableUpgradeable, SQParam
pool.totalReward,
pool.labor[runner],
pool.stake[runner],
pool.totalStake
pool.totalStake,
poolAdjustments[era][deploymentId]
);

address rewardDistributer = settings.getContractAddress(SQContracts.RewardsDistributor);
Expand Down Expand Up @@ -319,15 +323,20 @@ contract RewardsPool is IRewardsPool, Initializable, OwnableUpgradeable, SQParam
delete pool.stake[runner];

if (pool.unclaimTotalLabor == 0) {
// burn the remained
// don't burn the remained, instead, move to latest era
if (pool.unclaimReward > 0) {
address treasury = settings.getContractAddress(SQContracts.Treasury);
IERC20(settings.getContractAddress(SQContracts.SQToken)).safeTransfer(
treasury,
pool.unclaimReward
);
uint256 latestEra = IEraManager(
ISettings(settings).getContractAddress(SQContracts.EraManager)
).safeUpdateAndGetEra();
require(latestEra > era, 'RP006');
// EraPool storage latestEraPool = pools[latestEra];
// Pool storage latestPool = latestEraPool.pools[deploymentId];
// latestPool.totalReward += pool.unclaimReward;
pools[latestEra].pools[deploymentId].unclaimReward += pool.unclaimReward;
poolAdjustments[latestEra][deploymentId] += pool.unclaimReward;
}

delete poolAdjustments[era][deploymentId];
delete eraPool.pools[deploymentId];
eraPool.totalUnclaimedDeployment -= 1;

Expand All @@ -353,7 +362,8 @@ contract RewardsPool is IRewardsPool, Initializable, OwnableUpgradeable, SQParam
uint256 reward,
uint256 myLabor,
uint256 myStake,
uint256 totalStake
uint256 totalStake,
uint256 adjustment
) private view returns (uint256) {
if (myStake == totalStake) {
return reward;
Expand Down Expand Up @@ -382,6 +392,6 @@ contract RewardsPool is IRewardsPool, Initializable, OwnableUpgradeable, SQParam
// depending on the choice we made earlier.
n = feeRatio <= stakeRatio ? FixedMath.mul(stakeRatio, n) : FixedMath.div(stakeRatio, n);
// Multiply the above with reward.
return FixedMath.uintMul(n, reward);
return FixedMath.uintMul(n, reward + adjustment);
}
}
45 changes: 23 additions & 22 deletions contracts/StateChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -557,31 +557,32 @@ contract StateChannel is Initializable, OwnableUpgradeable, SQParameter {
if (amount > 0) {
address indexer = state.indexer;
bytes32 deploymentId = state.deploymentId;
// rewards pool is deprecated
// address rewardPoolAddress = settings.getContractAddress(SQContracts.RewardsPool);
// IERC20(settings.getContractAddress(SQContracts.SQToken)).approve(
// rewardPoolAddress,
// amount
// );
// IRewardsPool rewardsPool = IRewardsPool(rewardPoolAddress);
// rewardsPool.labor(deploymentId, indexer, amount);

IRewardsDistributor rewardsDistributor = IRewardsDistributor(
ISettings(settings).getContractAddress(SQContracts.RewardsDistributor)
);
IEraManager eraManager = IEraManager(
ISettings(settings).getContractAddress(SQContracts.EraManager)
);
// rewards pool is reactivated
address rewardPoolAddress = settings.getContractAddress(SQContracts.RewardsPool);
IERC20(settings.getContractAddress(SQContracts.SQToken)).safeIncreaseAllowance(
address(rewardsDistributor),
rewardPoolAddress,
amount
);
rewardsDistributor.addInstantRewards(
indexer,
address(this),
amount,
eraManager.safeUpdateAndGetEra()
);
IRewardsPool rewardsPool = IRewardsPool(rewardPoolAddress);
rewardsPool.labor(deploymentId, indexer, amount);

// disable instant rewards
// IRewardsDistributor rewardsDistributor = IRewardsDistributor(
// ISettings(settings).getContractAddress(SQContracts.RewardsDistributor)
// );
// IEraManager eraManager = IEraManager(
// ISettings(settings).getContractAddress(SQContracts.EraManager)
// );
// IERC20(settings.getContractAddress(SQContracts.SQToken)).safeIncreaseAllowance(
// address(rewardsDistributor),
// amount
// );
// rewardsDistributor.addInstantRewards(
// indexer,
// address(this),
// amount,
// eraManager.safeUpdateAndGetEra()
// );
emit ChannelLabor2(channelId, deploymentId, indexer, amount);
}

Expand Down
24 changes: 24 additions & 0 deletions publish/ABI/RewardsPool.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,30 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "poolAdjustments",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
Expand Down
18 changes: 9 additions & 9 deletions publish/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@
"lastUpdate": "Thu, 01 Aug 2024 08:55:43 GMT"
},
"RewardsDistributor": {
"innerAddress": "0xe42A85e38017cE848eEa220CF53f2D0fb772c6E0",
"innerAddress": "0x9eC4A8a31f6545002Ca1d5F7e4d7045aa36e6791",
"address": "0x5c0d1F22C4D7aaF35Ade34CA7c7491dBB0A91Cb7",
"bytecodeHash": "d6772ec56699815859ee19fdd98fe548c8632b434b5ab933abb6305434fda96b",
"lastUpdate": "Wed, 11 Sep 2024 11:31:24 GMT"
"bytecodeHash": "381e3fab7024f94442d22d91cbb1a4ae4ecc0dbe39670ea54d1ca080217db295",
"lastUpdate": "Fri, 24 Jan 2025 06:59:04 GMT"
},
"RewardsPool": {
"innerAddress": "0x6C7F6Cd6A4295D74897ae19Ab01Ea04821979d80",
Expand All @@ -153,10 +153,10 @@
"lastUpdate": "Fri, 09 Feb 2024 05:52:35 GMT"
},
"StateChannel": {
"innerAddress": "0x48e657895d8DEc38558d095d9f5f7825AA7Da1E2",
"innerAddress": "0x8F40E8bC3C10DfAdbc2a3c4261aB01e6CABBd28E",
"address": "0x8C3d312291CC666757daFbb6eD20874Ae573C895",
"bytecodeHash": "4bd7790e735b8f973d4c84bf46c7a6b5aea1352bb0271dfb75a46e630a63e8a8",
"lastUpdate": "Wed, 11 Sep 2024 11:32:13 GMT"
"bytecodeHash": "c0391673bb6d0d96beca30bc98e709aefa5edd9f60a95e6afaf0437fd90e64d2",
"lastUpdate": "Fri, 24 Jan 2025 06:59:37 GMT"
},
"ConsumerHost": {
"innerAddress": "0x07B1C6beeF0455135C37F8680f136bbE9aE8a9Ad",
Expand Down Expand Up @@ -195,10 +195,10 @@
"lastUpdate": "Tue, 21 May 2024 22:04:33 GMT"
},
"RewardsBooster": {
"innerAddress": "0x438bD56449Cd044F65C607EbdbB9a4Ede0c936b7",
"innerAddress": "0x2106495Cfe4c9E6857970CD458F6Ba3dF2a97E0e",
"address": "0x4f6A1045A56EeD1D2795b5f6F6713972B67C09C2",
"bytecodeHash": "10ded472cbfa2afbcfd1ac3a8b44414e12339fdd8018fcfd4c47a5b338e08af9",
"lastUpdate": "Tue, 08 Oct 2024 23:50:39 GMT"
"bytecodeHash": "63f4764276f728e8a3afe784074d7468f5a0294fa56c36bf8bd802ba3d62162c",
"lastUpdate": "Fri, 24 Jan 2025 06:59:19 GMT"
},
"StakingAllocation": {
"innerAddress": "0xfbeB402CADFCDB28407E86f5F20Ee719f5F6F430",
Expand Down
Loading
Loading