Skip to content

Commit

Permalink
add delegate deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Oct 22, 2024
1 parent 8424f8c commit 5d0ce49
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 5 deletions.
196 changes: 196 additions & 0 deletions .openzeppelin/unknown-4690.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"address": "0x6958142D4509eD76cE37B1190030aa1d2B94c075",
"txHash": "0xa90ad2cdaa645bdb849ff403a9d46242ecb426615dccfc47554ddfda84597dea",
"kind": "transparent"
},
{
"address": "0xf23FFA0B676299456c0B73d889CC34Fdec1f0764",
"txHash": "0x3dd4d25f89b743f7c8ec7bc2edf5dfbabe8970e9218302c8518b3d24e8c60241",
"kind": "transparent"
}
],
"impls": {
Expand Down Expand Up @@ -2208,6 +2213,197 @@
},
"namespaces": {}
}
},
"44b1505b2ba86b70485f3a117dfeaba9dbf07e3ed8334fd73d40ad552d903df7": {
"address": "0x1E9E7e7b0462cAD0058C77b50d68e28363315B23",
"txHash": "0x577d3b8a3588195879f836b67b5293d9ec1b8ae20429aece8ea9875753d7fd11",
"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": "_owner",
"offset": 0,
"slot": "51",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "52",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "_status",
"offset": 0,
"slot": "101",
"type": "t_uint256",
"contract": "ReentrancyGuardUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:38"
},
{
"label": "__gap",
"offset": 0,
"slot": "102",
"type": "t_array(t_uint256)49_storage",
"contract": "ReentrancyGuardUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol:88"
},
{
"label": "weightNFT",
"offset": 0,
"slot": "151",
"type": "t_contract(IWeightedNFT)21644",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:27"
},
{
"label": "accTokenPerShare",
"offset": 0,
"slot": "152",
"type": "t_uint256",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:29"
},
{
"label": "lastRewardBlock",
"offset": 0,
"slot": "153",
"type": "t_uint256",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:31"
},
{
"label": "rewardPerBlock",
"offset": 0,
"slot": "154",
"type": "t_uint256",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:33"
},
{
"label": "totalStakedWeight",
"offset": 0,
"slot": "155",
"type": "t_uint256",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:35"
},
{
"label": "userInfo",
"offset": 0,
"slot": "156",
"type": "t_mapping(t_address,t_struct(UserInfo)19115_storage)",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:37"
},
{
"label": "tokenStaker",
"offset": 0,
"slot": "157",
"type": "t_mapping(t_uint256,t_address)",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:40"
},
{
"label": "tokenWeight",
"offset": 0,
"slot": "158",
"type": "t_mapping(t_uint256,t_uint256)",
"contract": "FixedRewardPool",
"src": "contracts/gauges/FixedRewardPool.sol:42"
}
],
"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_contract(IWeightedNFT)21644": {
"label": "contract IWeightedNFT",
"numberOfBytes": "20"
},
"t_mapping(t_address,t_struct(UserInfo)19115_storage)": {
"label": "mapping(address => struct FixedRewardPool.UserInfo)",
"numberOfBytes": "32"
},
"t_mapping(t_uint256,t_address)": {
"label": "mapping(uint256 => address)",
"numberOfBytes": "32"
},
"t_mapping(t_uint256,t_uint256)": {
"label": "mapping(uint256 => uint256)",
"numberOfBytes": "32"
},
"t_struct(UserInfo)19115_storage": {
"label": "struct FixedRewardPool.UserInfo",
"members": [
{
"label": "amount",
"type": "t_uint256",
"offset": 0,
"slot": "0"
},
{
"label": "rewardDebt",
"type": "t_uint256",
"offset": 0,
"slot": "1"
}
],
"numberOfBytes": "64"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
14 changes: 9 additions & 5 deletions contracts/gauges/FixedRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ contract FixedRewardPool is OwnableUpgradeable, ReentrancyGuardUpgradeable, ERC7
rewardPerBlock = _rewardPerBlock;
}

function deposit(uint256 _tokenId) external nonReentrant {
UserInfo storage user = userInfo[msg.sender];
function deposit(uint256 _tokenId, address _recipient) public nonReentrant {
UserInfo storage user = userInfo[_recipient];
_updatePool();

uint256 _pending = 0;
if (user.amount > 0) {
_pending = (user.amount * accTokenPerShare) / PRECISION_FACTOR - user.rewardDebt;
if (_pending > 0) {
(bool success, ) = msg.sender.call{value: _pending}("");
(bool success, ) = _recipient.call{value: _pending}("");
require(success, "Failed to send reward");
}
}
Expand All @@ -69,14 +69,18 @@ contract FixedRewardPool is OwnableUpgradeable, ReentrancyGuardUpgradeable, ERC7
if (_amount > 0) {
user.amount = user.amount + _amount;
IERC721(weightNFT.nft()).safeTransferFrom(msg.sender, address(this), _tokenId);
tokenStaker[_tokenId] = msg.sender;
tokenStaker[_tokenId] = _recipient;
tokenWeight[_tokenId] = _amount;
totalStakedWeight = totalStakedWeight + _amount;
}

user.rewardDebt = (user.amount * accTokenPerShare) / PRECISION_FACTOR;

emit Deposit(msg.sender, _tokenId, _pending, _amount);
emit Deposit(_recipient, _tokenId, _pending, _amount);
}

function deposit(uint256 _tokenId) external {
deposit(_tokenId, msg.sender);
}

function withdraw(uint256 _tokenId) external nonReentrant {
Expand Down

0 comments on commit 5d0ce49

Please sign in to comment.