Skip to content

Commit

Permalink
feat: change to auto send reward
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Dec 24, 2024
1 parent 612f0ed commit ee36bcf
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 2 deletions.
177 changes: 177 additions & 0 deletions .openzeppelin/unknown-4690.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,183 @@
},
"namespaces": {}
}
},
"855733973314156c96bfe72ef689085299f8cb02af2da785ebec0020fa72f0ad": {
"address": "0xc73Ce4E0B310f623ff1160E83fAaEB4FF57bE400",
"txHash": "0x24f0bd13f4d94b6a4dbf2e923820a009ae7f03ad2ff8969af0a6b22295adab7e",
"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": "rewardPeriod",
"offset": 0,
"slot": "151",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:36"
},
{
"label": "activePeriodLimit",
"offset": 0,
"slot": "152",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:37"
},
{
"label": "rewardPerPeriod",
"offset": 0,
"slot": "153",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:38"
},
{
"label": "projectId",
"offset": 0,
"slot": "154",
"type": "t_uint256",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:39"
},
{
"label": "dApp",
"offset": 0,
"slot": "155",
"type": "t_address",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:40"
},
{
"label": "validCount",
"offset": 0,
"slot": "156",
"type": "t_mapping(t_address,t_mapping(t_uint256,t_uint256))",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:42"
},
{
"label": "receivedPeriod",
"offset": 0,
"slot": "157",
"type": "t_mapping(t_address,t_mapping(t_uint256,t_bool))",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:43"
},
{
"label": "lastTickTimestamp",
"offset": 0,
"slot": "158",
"type": "t_mapping(t_address,t_uint256)",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:44"
},
{
"label": "pendingRewards",
"offset": 0,
"slot": "159",
"type": "t_mapping(t_address,t_uint256)",
"contract": "W3bstreamCountRewardPool",
"src": "contracts/gauges/W3bstreamCountRewardPool.sol:45"
}
],
"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": {}
}
}
}
}
13 changes: 11 additions & 2 deletions contracts/gauges/W3bstreamCountRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,19 @@ contract W3bstreamCountRewardPool is MulticallUpgradeable, OwnableUpgradeable {
) {
address _owner = ioID.ownerOf(ioIDRegistry.deviceTokenId(_device));
uint256 _rewardPerPeriod = rewardPerPeriod;
pendingRewards[_owner] += _rewardPerPeriod;
uint256 _pendingRewards = pendingRewards[_owner] + _rewardPerPeriod;
receivedPeriod[_device][_period] = true;

emit ReceiveRewards(_owner, _device, _rewardPerPeriod);

if (_pendingRewards > 0 && address(this).balance >= _pendingRewards) {
pendingRewards[_owner] = 0;
(bool success, ) = _owner.call{value: _pendingRewards}("");
require(success, "fail claim");

emit ClaimRewards(_owner, _pendingRewards);
} else {
pendingRewards[_owner] = _pendingRewards;
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions script/14_upgrade_w3bstream_count_reward_pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ethers, upgrades } from 'hardhat';
import { W3bstreamCountRewardPool } from '../src/types';
require('dotenv').config();

async function main() {
if (!process.env.REWARD_POOL) {
console.log(`Please provide REWARD_POOL address`);
return;
}

const poolFactory = await ethers.getContractFactory('W3bstreamCountRewardPool');
const old = poolFactory.attach(process.env.REWARD_POOL) as W3bstreamCountRewardPool;

const pool = await upgrades.upgradeProxy(process.env.REWARD_POOL, poolFactory, {
redeployImplementation: 'always',
constructorArgs: [await old.ioIDRegistry(), await old.MIN_INTERNAL()],
});
await pool.waitForDeployment();

console.log(`W3bstreamCountRewardPool ${process.env.REWARD_POOL} upgraded`);
}

main().catch(err => {
console.error(err);
process.exitCode = 1;
});

0 comments on commit ee36bcf

Please sign in to comment.