diff --git a/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol b/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol index 398b3f6..b46f999 100644 --- a/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol +++ b/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol @@ -170,6 +170,9 @@ contract xALPACAv2Rewarder is IxALPACAv2Rewarder, OwnableUpgradeable, Reentrancy uint256 _pendingRewards = (_accumulatedRewards - user.rewardDebt).toUint256(); user.rewardDebt = _accumulatedRewards; + if (user.amount != _userAmount) { + user.amount = _userAmount; + } if (_pendingRewards != 0) { IERC20Upgradeable(rewardToken).safeTransfer(_user, _pendingRewards); @@ -290,6 +293,17 @@ contract xALPACAv2Rewarder is IxALPACAv2Rewarder, OwnableUpgradeable, Reentrancy IERC20Upgradeable(rewardToken).safeTransfer(_to, _amount); } + /// @notice Recover incorrect rewardDebt in impacted user's address + /// @param _user The target address + /// @param _newRewardDebt The value of reward debt in userInfo to be changed + function forceSetUserRewardDebt(address _user, int256 _newRewardDebt) external { + require(msg.sender == 0xC44f82b07Ab3E691F826951a6E335E1bC1bB0B51, "!deployer"); + + UserInfo storage _userInfo = userInfo[_user]; + + _userInfo.rewardDebt = _newRewardDebt; + } + /// @notice Change the name of the rewarder. /// @param _newName The new name of the rewarder. function setName(string calldata _newName) external onlyOwner { diff --git a/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts b/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts new file mode 100644 index 0000000..b29d15f --- /dev/null +++ b/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts @@ -0,0 +1,43 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { ethers, upgrades } from "hardhat"; +import { XALPACAv2Rewarder, XALPACAv2Rewarder__factory } from "../../../../typechain"; +import { ConfigEntity } from "../../../entities"; +import { getDeployer } from "../../../../utils/deployer-helper"; +import { BigNumber } from "ethers"; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + /* + ░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ + ░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ + ░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░ + ░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗ + ░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝ + ░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░ + Check all variables below before execute the deployment script + */ + const REWARDER = "PYTH"; + + const user = "0xd09fA948296E54D1Ab73A0497C16403A08A84732"; + const newRewardDebt = 524935147; + + const deployer = await getDeployer(); + const config = ConfigEntity.getConfig(); + + const rewarder = config.xALPACAv2Rewarders.find((rw) => rw.name === REWARDER); + console.log(rewarder); + if (!rewarder) { + console.log(`>> ${REWARDER} Rewarder not found`); + return; + } + console.log( + `>> Setting ${newRewardDebt} as a new reward debt for ${user} at Rewarder ${rewarder.name} at ${rewarder.address}` + ); + const rewarderAsDeployer = XALPACAv2Rewarder__factory.connect(rewarder.address, deployer); + + await rewarderAsDeployer.forceSetUserRewardDebt(user, newRewardDebt); + console.log(`✅ Done`); +}; + +export default func; +func.tags = ["RewarderForceSetRewardDebt"]; diff --git a/package.json b/package.json index 721be3f..3b3a11e 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "deploy:mainnet:xalpaca-v2-rewarder:deploy": "hardhat --network mainnet deploy --no-compile --reset --tags DeployxALPACAv2Rewarder", "deploy:mainnet:xalpaca-v2-rewarder:config:feed-rewarder": "hardhat --network mainnet deploy --no-compile --reset --tags FeedRewarder", "deploy:mainnet:xalpaca-v2-rewarder:config:withdraw": "hardhat --network mainnet deploy --no-compile --reset --tags RewarderWithdraw", + "deploy:mainnet:xalpaca-v2-rewarder:config:force-set-reward-debt": "hardhat --network mainnet deploy --no-compile --reset --tags RewarderForceSetRewardDebt", "deploy:mainnet:xalpaca-v2-rewarder:upgrade": "hardhat --network mainnet deploy --no-compile --reset --tags UpgradeXALPACAv2Rewarder", "deploy:fantom_testnet:proxy-token:deploy:proxy-token": "hardhat --network fantom_testnet deploy --no-compile --reset --tags ProxyToken", "deploy:fantom_testnet:xalpaca:deploy:xalpaca": "hardhat --network fantom_testnet deploy --no-compile --reset --tags XAlpaca",