Skip to content

Commit

Permalink
feat: add remaining rewards for w3bstream reward pool
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Jan 17, 2025
1 parent ee36bcf commit d288c47
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 1 deletion.
190 changes: 190 additions & 0 deletions .openzeppelin/unknown-4689.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"address": "0x4277A2f1ba30cBc6fD0F8987e55000b027d1F59E",
"txHash": "0x08d865967fcb89f423c0fdf158031fa505054ba252ba8706d66fb96f7fb711bd",
"kind": "transparent"
},
{
"address": "0x2b0EE27BE3F973810397671630784f53FF7bc84F",
"txHash": "0xada66618c7344ad6058bd3fea243f1b6d2f9c12124ac3895c702c7eed0f30585",
"kind": "transparent"
}
],
"impls": {
Expand Down Expand Up @@ -1279,6 +1284,191 @@
},
"namespaces": {}
}
},
"eb2ff46badc44d97b26ee22ccb749e5529344de390ffaeb8e9534b79c03a05e2": {
"address": "0x81c4e90431274A02cf08E48A1a4600254fbEE3eE",
"txHash": "0x0ea45c04819bd6facca28509b177ae6aa073b233ffe4f1f3493ba3094abec4b9",
"layout": {
"solcVersion": "0.8.19",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40"
},
{
"label": "__gap",
"offset": 0,
"slot": "51",
"type": "t_array(t_uint256)50_storage",
"contract": "MulticallUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol:51"
},
{
"label": "_owner",
"offset": 0,
"slot": "101",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "102",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "remainingRewards",
"offset": 0,
"slot": "151",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:37"
},
{
"label": "rewardPeriod",
"offset": 0,
"slot": "152",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:38"
},
{
"label": "activePeriodLimit",
"offset": 0,
"slot": "153",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:39"
},
{
"label": "rewardPerPeriod",
"offset": 0,
"slot": "154",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:40"
},
{
"label": "projectId",
"offset": 0,
"slot": "155",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:41"
},
{
"label": "dApp",
"offset": 0,
"slot": "156",
"type": "t_address",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:42"
},
{
"label": "validCount",
"offset": 0,
"slot": "157",
"type": "t_mapping(t_address,t_mapping(t_uint256,t_uint256))",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:44"
},
{
"label": "receivedPeriod",
"offset": 0,
"slot": "158",
"type": "t_mapping(t_address,t_mapping(t_uint256,t_bool))",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:45"
},
{
"label": "lastTickTimestamp",
"offset": 0,
"slot": "159",
"type": "t_mapping(t_address,t_uint256)",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:46"
},
{
"label": "pendingRewards",
"offset": 0,
"slot": "160",
"type": "t_mapping(t_address,t_uint256)",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:47"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_mapping(t_address,t_mapping(t_uint256,t_bool))": {
"label": "mapping(address => mapping(uint256 => bool))",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_mapping(t_uint256,t_uint256))": {
"label": "mapping(address => mapping(uint256 => uint256))",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_uint256)": {
"label": "mapping(address => uint256)",
"numberOfBytes": "32"
},
"t_mapping(t_uint256,t_bool)": {
"label": "mapping(uint256 => bool)",
"numberOfBytes": "32"
},
"t_mapping(t_uint256,t_uint256)": {
"label": "mapping(uint256 => uint256)",
"numberOfBytes": "32"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
21 changes: 20 additions & 1 deletion contracts/gauges/W3bstreamCountRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
event ChangeActivePeriodLimit(uint256 activePeriodLimit);
event ChangeRewardPerPeriod(uint256 rewardPerPeriod);
event ChangeDApp(address indexed dApp);
event IncreaseRewards(uint256 rewards);

/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IioIDRegistry public immutable ioIDRegistry;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable MIN_INTERNAL;

uint256 public remainingRewards;
uint256 public rewardPeriod;
uint256 public activePeriodLimit;
uint256 public rewardPerPeriod;
Expand All @@ -51,6 +53,7 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
}

function initialize(
uint256 _cap,
uint256 _rewardPeriod,
uint256 _activePeriodLimit,
uint256 _rewardPerPeriod,
Expand All @@ -63,6 +66,7 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
__Multicall_init();
__Ownable_init();

remainingRewards = _cap;
rewardPeriod = _rewardPeriod;
activePeriodLimit = _activePeriodLimit;
rewardPerPeriod = _rewardPerPeriod;
Expand All @@ -83,10 +87,18 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
lastTickTimestamp[_device] = block.timestamp;

if (
rewardPerPeriod > 0 && !receivedPeriod[_device][_period] && validCount[_device][_period] >= activePeriodLimit
rewardPerPeriod > 0 &&
remainingRewards > 0 &&
!receivedPeriod[_device][_period] &&
validCount[_device][_period] >= activePeriodLimit
) {
address _owner = ioID.ownerOf(ioIDRegistry.deviceTokenId(_device));
uint256 _rewardPerPeriod = rewardPerPeriod;
if (_rewardPerPeriod > remainingRewards) {
_rewardPerPeriod = remainingRewards;
}
remainingRewards -= _rewardPerPeriod;

uint256 _pendingRewards = pendingRewards[_owner] + _rewardPerPeriod;
receivedPeriod[_device][_period] = true;
emit ReceiveRewards(_owner, _device, _rewardPerPeriod);
Expand Down Expand Up @@ -158,5 +170,12 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
emit ChangeDApp(_dApp);
}

function increaseRewards(uint256 _rewards) external onlyOwner {
require(_rewards > 0, "zero reward");

remainingRewards += _rewards;
emit IncreaseRewards(_rewards);
}

receive() external payable {}
}
5 changes: 5 additions & 0 deletions script/13_deploy_w3bstream_count_reward_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ async function main() {
console.log(`Please provide IOID_REGISTRY address`);
return;
}
if (!process.env.CAP) {
console.log(`Please provide CAP (unit: IOTX)`);
return;
}
if (!process.env.REWARD_PERIOD) {
console.log(`Please provide REWARD_PERIOD (unit: second)`);
return;
Expand Down Expand Up @@ -34,6 +38,7 @@ async function main() {
const pool = await upgrades.deployProxy(
await ethers.getContractFactory('W3bstreamCountRewardPool'),
[
ethers.parseEther(process.env.CAP),
process.env.REWARD_PERIOD,
process.env.ACTIVE_PERIOD_LIMIT,
ethers.parseEther(process.env.REWARD_PER_PERIOD),
Expand Down

0 comments on commit d288c47

Please sign in to comment.