-
Notifications
You must be signed in to change notification settings - Fork 0
rm transfer user #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.13; | ||
|
|
||
| import {Script} from "forge-std/Script.sol"; | ||
|
|
||
| import {JsonReadWriter, Environment} from "./helpers.sol"; | ||
|
|
||
| import {YelayStaking} from "src/YelayStaking.sol"; | ||
| import {sYLAY} from "src/sYLAY.sol"; | ||
| import {IYelayOwner} from "src/interfaces/IYelayOwner.sol"; | ||
|
|
||
| /** | ||
| * source .env && FOUNDRY_PROFILE=mainnet forge script script/TransferUserRemovalUpgrade.s.sol:TransferUserRemovalUpgrade --slow --broadcast --legacy --etherscan-api-key $ETHERSCAN_API_KEY --verify | ||
| */ | ||
| contract TransferUserRemovalUpgrade is Script { | ||
| function run() external { | ||
| Environment.setRpc(vm); | ||
|
|
||
| JsonReadWriter json = new JsonReadWriter(vm, Environment.getContractsPath(vm)); | ||
|
|
||
| vm.startBroadcast(Environment.getPrivateKey(vm)); | ||
| YelayStaking yelayStaking = new YelayStaking( | ||
| json.getAddress(".YLAY.proxy"), | ||
| json.getAddress(".sYLAY.proxy"), | ||
| json.getAddress(".sYLAYRewards.proxy"), | ||
| json.getAddress(".YelayRewardsDistributor.proxy"), | ||
| json.getAddress(".YelayOwner") | ||
| ); | ||
| sYLAY sylay = new sYLAY(IYelayOwner(json.getAddress(".YelayOwner"))); | ||
| vm.stopBroadcast(); | ||
|
|
||
| json.addProxy("YelayStaking", address(yelayStaking), json.getAddress(".YelayStaking.proxy")); | ||
| json.addProxy("sYLAY", address(sylay), json.getAddress(".sYLAY.proxy")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.13; | ||
|
|
||
| import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol"; | ||
| import {EIP712} from "openzeppelin-contracts/utils/cryptography/draft-EIP712.sol"; | ||
| import "openzeppelin-contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; | ||
| import "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
|
||
|
|
@@ -25,7 +23,7 @@ import "./interfaces/IRewardDistributor.sol"; | |
| * At stake, gradual sYLAY (Yelay Voting Token) is minted and accumulated every week. | ||
| * At unstake all sYLAY is burned. The maturing process of sYLAY restarts. | ||
| */ | ||
| contract YelayStaking is ReentrancyGuardUpgradeable, YelayOwnable, IYelayStaking, EIP712 { | ||
| contract YelayStaking is ReentrancyGuardUpgradeable, YelayOwnable, IYelayStaking { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| /* ========== STRUCTS ========== */ | ||
|
|
@@ -91,8 +89,6 @@ contract YelayStaking is ReentrancyGuardUpgradeable, YelayOwnable, IYelayStaking | |
| /// @notice Account YLAY locked balance. subset of balances | ||
| mapping(address => uint256) public locked; | ||
|
|
||
| bytes32 private constant _TRANSFER_USER_TYPEHASH = keccak256("TransferUser(address from, uint256 deadline)"); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constant, not a storage - can be removed. |
||
|
|
||
| /* ========== CONSTRUCTOR ========== */ | ||
|
|
||
| /** | ||
|
|
@@ -110,7 +106,7 @@ contract YelayStaking is ReentrancyGuardUpgradeable, YelayOwnable, IYelayStaking | |
| address _sYlayRewards, | ||
| address _rewardDistributor, | ||
| address _yelayOwner | ||
| ) YelayOwnable(IYelayOwner(_yelayOwner)) EIP712("YelayStaking", "1.0.1") { | ||
| ) YelayOwnable(IYelayOwner(_yelayOwner)) { | ||
| stakingToken = IERC20(_stakingToken); | ||
| sYlay = IsYLAY(_sYlay); | ||
| sYlayRewards = IsYLAYRewards(_sYlayRewards); | ||
|
|
@@ -158,63 +154,8 @@ contract YelayStaking is ReentrancyGuardUpgradeable, YelayOwnable, IYelayStaking | |
| return rewardTokens.length; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the domain separator for the current chain. | ||
| */ | ||
| function domainSeparatorV4() external view returns (bytes32) { | ||
| return _domainSeparatorV4(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the struct hash for hashTypedDataV4 | ||
| */ | ||
| function structHash(address from, uint256 deadline) public pure returns (bytes32) { | ||
| return keccak256(abi.encode(_TRANSFER_USER_TYPEHASH, from, deadline)); | ||
| } | ||
|
|
||
| /* ========== MUTATIVE FUNCTIONS ========== */ | ||
|
|
||
| /** | ||
| * @notice Transfers the staking balance and rewards of one user to another. | ||
| * @dev This function is non-reentrant and updates rewards before transferring. | ||
| * @param to The address of the recipient to whom the staking data is transferred. | ||
| */ | ||
| function transferUser(address to, uint256 deadline, bytes memory signature) | ||
| external | ||
| nonReentrant | ||
| updateRewards(msg.sender) | ||
| { | ||
| require(deadline > block.timestamp, "YelayStaking::transferUser: deadline has passed"); | ||
|
|
||
| bytes32 hash_ = _hashTypedDataV4(structHash(msg.sender, deadline)); | ||
| address signer = ECDSA.recover(hash_, signature); | ||
|
|
||
| require(signer == to, "YelayStaking::transferUser: invalid signature"); | ||
|
|
||
| balances[to] = balances[msg.sender]; | ||
| stakedBy[to] = stakedBy[msg.sender]; | ||
| locked[to] = locked[msg.sender]; | ||
| canStakeFor[to] = false; | ||
|
|
||
| delete balances[msg.sender]; | ||
| delete stakedBy[msg.sender]; | ||
| delete locked[msg.sender]; | ||
| delete canStakeFor[msg.sender]; | ||
|
|
||
| uint256 _rewardTokensCount = rewardTokens.length; | ||
| for (uint256 i; i < _rewardTokensCount; i++) { | ||
| RewardConfiguration storage config = rewardConfiguration[rewardTokens[i]]; | ||
|
|
||
| config.rewards[to] = config.rewards[msg.sender]; | ||
| config.userRewardPerTokenPaid[to] = config.userRewardPerTokenPaid[msg.sender]; | ||
|
|
||
| delete config.rewards[msg.sender]; | ||
| delete config.userRewardPerTokenPaid[msg.sender]; | ||
| } | ||
|
|
||
| sYlay.transferUser(msg.sender, to); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Stake YLAY tokens and start earning sYLAY gradually. | ||
| * @param amount The amount of YLAY to stake. | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since EIP712 does not define any storage variables or storage gaps, it can be safely removed from the inheritance chain.