From 2e3ff3dc7767ab73dceb620c65065c91a8bf755f Mon Sep 17 00:00:00 2001 From: alpanaca Date: Mon, 6 May 2024 13:48:20 +0700 Subject: [PATCH 1/5] fix: handle proper deposit --- .../xALPACAv2Rewarder.sol | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol b/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol index b46f999..1fe339d 100644 --- a/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol +++ b/contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol @@ -96,32 +96,13 @@ contract xALPACAv2Rewarder is IxALPACAv2Rewarder, OwnableUpgradeable, Reentrancy PoolInfo memory pool = _updatePool(_previousStakingReserve); UserInfo storage user = userInfo[_user]; - // calculate new staked amount - // example: if user deposit another 500 shares - // - user.amount = 100 => from previous deposit - // - _newAmount = 600 => updated staking amount from xALPACAv2RevenueDistributor - // _amount = _newAmount - user.amount = 600 - 100 = 500 - uint256 _amount = _newAmount - user.amount; + uint256 _depositedAmount = _newAmount - _previousAmount; user.amount = _newAmount; - // update user rewardDebt to separate new deposit share amount from pending reward in the pool - // example: - // - accRewardPerShare = 250 - // - _receivedAmount = 100 - // - pendingRewardReward = 25,000 - // rewardDebt = previousRewardDebt + (_receivedAmount * accRewardPerShare)= 100 + (100 * 250) = 25,100 - // This means newly deposit share does not eligible for 25,100 pending rewards - - // handle if user already has deposited - // reward users supposed to get will be accounted here first - if (user.rewardDebt == 0 && _previousAmount > 0) { - user.rewardDebt = - user.rewardDebt - - (((_previousAmount * pool.accRewardPerShare) / ACC_REWARD_PRECISION)).toInt256(); - } - user.rewardDebt = user.rewardDebt + ((_amount * pool.accRewardPerShare) / ACC_REWARD_PRECISION).toInt256(); - emit LogOnDeposit(_user, _amount); + user.rewardDebt = user.rewardDebt + ((_depositedAmount * pool.accRewardPerShare) / ACC_REWARD_PRECISION).toInt256(); + + emit LogOnDeposit(_user, _depositedAmount); } /// @notice Hook Withdraw action from xALPACAv2RevenueDistributor. From a64d0107f6b8e27c5a150ace3c5c54a05c846cd4 Mon Sep 17 00:00:00 2001 From: wow-alpaca Date: Mon, 6 May 2024 16:57:21 +0700 Subject: [PATCH 2/5] chore: add fault check script --- .../config/find-pending-tokens.ts | 59 +++++++++++++++++++ package.json | 1 + 2 files changed, 60 insertions(+) create mode 100644 deploy/exec/xalpaca-v2-rewarder/config/find-pending-tokens.ts diff --git a/deploy/exec/xalpaca-v2-rewarder/config/find-pending-tokens.ts b/deploy/exec/xalpaca-v2-rewarder/config/find-pending-tokens.ts new file mode 100644 index 0000000..e9d34d8 --- /dev/null +++ b/deploy/exec/xalpaca-v2-rewarder/config/find-pending-tokens.ts @@ -0,0 +1,59 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { ethers } from "hardhat"; +import { XALPACAv2Rewarder__factory } from "../../../../typechain"; +import { ConfigEntity } from "../../../entities"; +import { getDeployer } from "../../../../utils/deployer-helper"; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + interface IRewarder { + NAME: string; + AMOUNT: string; + DECIMAL: number; + } + /* + ░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ + ░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ + ░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░ + ░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗ + ░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝ + ░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░ + Check all variables below before execute the deployment script + */ + + const config = ConfigEntity.getConfig(); + + const REWARDER_NAME = "PYTH"; + const accounts: string[] = []; + + const rewarder = config.xALPACAv2Rewarders.find((rw) => rw.name === REWARDER_NAME); + if (!rewarder) { + console.log(`>> ${REWARDER_NAME} Rewarder not found`); + return; + } + + const rewarderContract = XALPACAv2Rewarder__factory.connect(rewarder.address, ethers.provider); + + let counter: number = 0; + const badAccounts: string[] = []; + + for (const account of accounts) { + await rewarderContract.pendingToken(account).catch((e) => { + console.log(">> Error:", account); + badAccounts.push(account); + }); + counter++; + } + + if (counter !== accounts.length) { + console.log(`>> Exited before checking all accounts. ${counter} of ${accounts.length} checked.`); + } + + console.log(`>> ${REWARDER_NAME} Rewarder bad accounts: ${badAccounts.length}`); + console.log(badAccounts); + + console.log(`✅ Done`); +}; + +export default func; +func.tags = ["FindPendingTokens"]; diff --git a/package.json b/package.json index 3b3a11e..43d55c5 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:find-pending-tokens": "hardhat --network mainnet deploy --no-compile --reset --tags FindPendingTokens", "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", From 73d25b9a67cba7cd43abffae6fe14b16e36ccda4 Mon Sep 17 00:00:00 2001 From: alpanaca Date: Tue, 7 May 2024 14:13:12 +0700 Subject: [PATCH 3/5] chore: edit script --- .../config/force-set-reward-debt.ts | 80 +++++++++++++++++-- .../upgrade/xalpaca-v2-rewarder.ts | 16 ++-- 2 files changed, 81 insertions(+), 15 deletions(-) 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 index b29d15f..10f423f 100644 --- a/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts +++ b/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts @@ -7,6 +7,10 @@ import { getDeployer } from "../../../../utils/deployer-helper"; import { BigNumber } from "ethers"; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + interface IUserInfo { + user: string; + rewardDebt: number; + } /* ░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ ░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ @@ -17,9 +21,68 @@ 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 USERLIST: Array = [ + { + user: "0x1300dedfb2f9671b6435dd4cb7ac40a5a3be51ff", + rewardDebt: 154288683, + }, + { + user: "0x04938ffb0c749a11fcda6d5138a95b1cd76791d0", + rewardDebt: 240483, + }, + { + user: "0xa25ad78e8bf1ff9e5872662934ec4984b92611ff", + rewardDebt: 929, + }, + { + user: "0x08943873222ce63ec48f8907757928dcb06af388", + rewardDebt: 389259, + }, + { + user: "0xc3fd2bcb524af31963b3e3bb670f28ba14718244", + rewardDebt: 4027249, + }, + { + user: "0x8bc888a4738f1e4291e041cbb225156da8f42059", + rewardDebt: 1083460, + }, + { + user: "0xc8d5aca8fd339846d98bd246aee47f767daa1075", + rewardDebt: 21643899, + }, + { + user: "0x0567d99a4420b8da0fd91c5ecba78955c04974f0", + rewardDebt: 1713434087, + }, + { + user: "0x539ec9fe37320828cdf639c2de93cbf1d1e5d257", + rewardDebt: 2087504, + }, + { + user: "0xc110c1cd06e00273a770ef1555d2a8497aadff41", + rewardDebt: 13441254, + }, + { + user: "0x736b9564c98325df57e3251d405a883fa85918fd", + rewardDebt: 1715939580, + }, + { + user: "0x902736ba2f6558332efbadb4a731af786e55f4b9", + rewardDebt: 37602, + }, + { + user: "0xcffb39005a8dab478ef4188ae1b912f6e28ee3d3", + rewardDebt: 15207029, + }, + { + user: "0x8674b6f34aa08aa8fa3d09551688e8cec70540ae", + rewardDebt: 150005014, + }, + { + user: "0xbe68b3a1b22e84a89a8b3d47bcec8fba3fe0cc75", + rewardDebt: 1023506, + }, + ]; const deployer = await getDeployer(); const config = ConfigEntity.getConfig(); @@ -30,12 +93,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { 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); + for (const user of USERLIST) { + console.log( + `>> Setting ${user.rewardDebt} as a new reward debt for ${user.user} at Rewarder ${rewarder.name} at ${rewarder.address}` + ); + await rewarderAsDeployer.forceSetUserRewardDebt(user.user, user.rewardDebt); + } console.log(`✅ Done`); }; diff --git a/deploy/exec/xalpaca-v2-rewarder/upgrade/xalpaca-v2-rewarder.ts b/deploy/exec/xalpaca-v2-rewarder/upgrade/xalpaca-v2-rewarder.ts index b6f0620..97aa013 100644 --- a/deploy/exec/xalpaca-v2-rewarder/upgrade/xalpaca-v2-rewarder.ts +++ b/deploy/exec/xalpaca-v2-rewarder/upgrade/xalpaca-v2-rewarder.ts @@ -55,11 +55,11 @@ async function main() { console.log("✅ Done"); } -main() - .then(() => { - process.exit(0); - }) - .catch((error) => { - console.error(error); - process.exit(1); - }); +// main() +// .then(() => { +// process.exit(0); +// }) +// .catch((error) => { +// console.error(error); +// process.exit(1); +// }); From b5fac68c983d8c65c1774c3dec3098ece526fb50 Mon Sep 17 00:00:00 2001 From: alpanaca Date: Tue, 7 May 2024 15:25:45 +0700 Subject: [PATCH 4/5] fix: script --- deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 10f423f..43c44ed 100644 --- a/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts +++ b/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts @@ -28,7 +28,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { }, { user: "0x04938ffb0c749a11fcda6d5138a95b1cd76791d0", - rewardDebt: 240483, + rewardDebt: 0, }, { user: "0xa25ad78e8bf1ff9e5872662934ec4984b92611ff", From 86550001985c96b5d7ab97f885e29baa9d4cb618 Mon Sep 17 00:00:00 2001 From: alpanaca Date: Tue, 7 May 2024 15:59:07 +0700 Subject: [PATCH 5/5] fix: wrong cal --- .../exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 43c44ed..aacea97 100644 --- a/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts +++ b/deploy/exec/xalpaca-v2-rewarder/config/force-set-reward-debt.ts @@ -52,7 +52,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { }, { user: "0x0567d99a4420b8da0fd91c5ecba78955c04974f0", - rewardDebt: 1713434087, + rewardDebt: 3094379, }, { user: "0x539ec9fe37320828cdf639c2de93cbf1d1e5d257", @@ -64,7 +64,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { }, { user: "0x736b9564c98325df57e3251d405a883fa85918fd", - rewardDebt: 1715939580, + rewardDebt: 16235119, }, { user: "0x902736ba2f6558332efbadb4a731af786e55f4b9",