Skip to content

Commit

Permalink
Merge branch 'main' of github.com-spicysquid168:alpaca-finance/xALPAC…
Browse files Browse the repository at this point in the history
…A-contract
  • Loading branch information
spicysquid168 committed Apr 29, 2024
2 parents 140098b + 353f5ad commit e68fa02
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 43 additions & 0 deletions deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts
Original file line number Diff line number Diff line change
@@ -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"];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e68fa02

Please sign in to comment.