-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from alpaca-finance/fix/xalpacav2-rewarder-fix
[main][fix] Pyth Rewarder Fix
- Loading branch information
Showing
9 changed files
with
264 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
deploy/exec/xalpaca-v2-revenue-distributor/upgrade/xalpaca-v2-revenue-distributor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ProxyAdmin__factory } from "@alpaca-finance/alpaca-contract/typechain"; | ||
import { ethers, upgrades } from "hardhat"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { getDeployer, isFork } from "../../../../utils/deployer-helper"; | ||
import { TimelockEntity } from "../../../entities"; | ||
import { getConfig } from "../../../entities/config"; | ||
import { fileService } from "../../../services"; | ||
import { MaybeMultisigTimelock } from "../../../services/timelock/maybe-multisig"; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
/* | ||
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ | ||
░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ | ||
░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░ | ||
░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗ | ||
░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝ | ||
░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░ | ||
Check all variables below before execute the deployment script | ||
*/ | ||
const config = getConfig(); | ||
|
||
const TITLE = "upgrade_xalpacav2_revenue_distributor"; | ||
const EXACT_ETA = "1712314800"; | ||
const TARGET_XALPACAv2REVENUEDISTRIBUTOR_ADDRESS = config.xALPACAv2RevenueDistributor!; | ||
|
||
let nonce = 0; | ||
const deployer = await getDeployer(); | ||
|
||
const timelockTransactions: Array<TimelockEntity.Transaction> = []; | ||
|
||
const proxyAdminOwner = await ProxyAdmin__factory.connect(config.ProxyAdmin, deployer).owner(); | ||
const newImpl = await ethers.getContractFactory("xALPACAv2RevenueDistributor"); | ||
|
||
const preparedNewXALPACAv2RevenueDistributor = await upgrades.prepareUpgrade( | ||
TARGET_XALPACAv2REVENUEDISTRIBUTOR_ADDRESS, | ||
newImpl | ||
); | ||
const networkInfo = await ethers.provider.getNetwork(); | ||
|
||
console.log( | ||
`> Upgrading XALPACA REVENUE DISTRIBUTOR at ${TARGET_XALPACAv2REVENUEDISTRIBUTOR_ADDRESS} through Timelock + ProxyAdmin` | ||
); | ||
console.log("> Prepare upgrade & deploy if needed a new IMPL automatically."); | ||
console.log(`> Implementation address: ${preparedNewXALPACAv2RevenueDistributor}`); | ||
|
||
const timelock = new MaybeMultisigTimelock(networkInfo.chainId, deployer); | ||
|
||
timelockTransactions.push( | ||
await timelock.queueTransaction( | ||
`> Queue tx to upgrade ${TARGET_XALPACAv2REVENUEDISTRIBUTOR_ADDRESS}`, | ||
config.ProxyAdmin, | ||
"0", | ||
"upgrade(address,address)", | ||
["address", "address"], | ||
[TARGET_XALPACAv2REVENUEDISTRIBUTOR_ADDRESS, preparedNewXALPACAv2RevenueDistributor], | ||
EXACT_ETA, | ||
{ nonce: nonce++ } | ||
) | ||
); | ||
|
||
const timestamp = Math.floor(Date.now() / 1000); | ||
const fileName = `${timestamp}_${TITLE}`; | ||
console.log(`> Writing File ${fileName}`); | ||
fileService.writeJson(fileName, timelockTransactions); | ||
console.log("✅ Done"); | ||
}; | ||
|
||
export default func; | ||
func.tags = ["UpgradeXALPACAv2RevenueDistributor"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { ethers, upgrades } from "hardhat"; | ||
import { BEP20__factory, 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) { | ||
interface IRewarder { | ||
NAME: string; | ||
AMOUNT: string; | ||
DECIMAL: number; | ||
} | ||
/* | ||
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ | ||
░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ | ||
░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░ | ||
░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗ | ||
░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝ | ||
░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░ | ||
Check all variables below before execute the deployment script | ||
*/ | ||
const REWARDERS: Array<IRewarder> = [ | ||
{ | ||
NAME: "PYTH", | ||
AMOUNT: "175.26", | ||
DECIMAL: 6, | ||
}, | ||
]; | ||
|
||
const deployer = await getDeployer(); | ||
const config = ConfigEntity.getConfig(); | ||
|
||
for (const rewarderConfig of REWARDERS) { | ||
const rewarder = config.xALPACAv2Rewarders.find((rw) => rw.name === rewarderConfig.NAME); | ||
console.log(rewarder); | ||
if (!rewarder) { | ||
console.log(`>> ${rewarderConfig.NAME} Rewarder not found`); | ||
continue; | ||
} | ||
console.log( | ||
`>> Withdrawing ${rewarderConfig.AMOUNT} ${rewarder.name} from Rewarder ${rewarder.name} at ${rewarder.address}` | ||
); | ||
const rewarderAsDeployer = XALPACAv2Rewarder__factory.connect(rewarder.address, deployer); | ||
|
||
await rewarderAsDeployer.withdrawTo( | ||
deployer.address, | ||
BigNumber.from(Number(rewarderConfig.AMOUNT) * 10 ** rewarderConfig.DECIMAL) | ||
); | ||
console.log(`✅ Done withdraw ${rewarderConfig.AMOUNT} ${rewarder.name} to ${deployer.address}`); | ||
} | ||
}; | ||
|
||
export default func; | ||
func.tags = ["RewarderWithdraw"]; |
72 changes: 72 additions & 0 deletions
72
deploy/exec/xalpaca-v2-rewarder/upgrade/xalpaca-v2-rewarder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ProxyAdmin__factory } from "@alpaca-finance/alpaca-contract/typechain"; | ||
import { ethers, upgrades } from "hardhat"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { getDeployer, isFork } from "../../../../utils/deployer-helper"; | ||
import { TimelockEntity } from "../../../entities"; | ||
import { getConfig } from "../../../entities/config"; | ||
import { fileService } from "../../../services"; | ||
import { MaybeMultisigTimelock } from "../../../services/timelock/maybe-multisig"; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
/* | ||
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░ | ||
░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░ | ||
░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░ | ||
░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗ | ||
░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝ | ||
░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░ | ||
Check all variables below before execute the deployment script | ||
*/ | ||
const config = getConfig(); | ||
|
||
const TITLE = "upgrade_xalpacav2_rewarder"; | ||
const EXACT_ETA = "1712314800"; | ||
const REWARDER_NAME = "PYTH"; | ||
|
||
let nonce = 0; | ||
let rewarder_config = config.xALPACAv2Rewarders.find((rewarder) => rewarder.name === REWARDER_NAME); | ||
|
||
if (!rewarder_config) { | ||
console.log(`Rewarder ${REWARDER_NAME} not found`); | ||
return; | ||
} | ||
|
||
const deployer = await getDeployer(); | ||
|
||
const timelockTransactions: Array<TimelockEntity.Transaction> = []; | ||
|
||
const proxyAdminOwner = await ProxyAdmin__factory.connect(config.ProxyAdmin, deployer).owner(); | ||
const newImpl = await ethers.getContractFactory("xALPACAv2Rewarder"); | ||
|
||
const preparedNewRewarder = await upgrades.prepareUpgrade(rewarder_config.address, newImpl); | ||
const networkInfo = await ethers.provider.getNetwork(); | ||
|
||
console.log(`> Upgrading XALPACA REWARDER at ${rewarder_config.address} through Timelock + ProxyAdmin`); | ||
console.log("> Prepare upgrade & deploy if needed a new IMPL automatically."); | ||
console.log(`> Implementation address: ${preparedNewRewarder}`); | ||
|
||
const timelock = new MaybeMultisigTimelock(networkInfo.chainId, deployer); | ||
|
||
timelockTransactions.push( | ||
await timelock.queueTransaction( | ||
`> Queue tx to upgrade ${rewarder_config.address}`, | ||
config.ProxyAdmin, | ||
"0", | ||
"upgrade(address,address)", | ||
["address", "address"], | ||
[rewarder_config.address, preparedNewRewarder], | ||
EXACT_ETA, | ||
{ nonce: nonce++ } | ||
) | ||
); | ||
|
||
const timestamp = Math.floor(Date.now() / 1000); | ||
const fileName = `${timestamp}_${TITLE}`; | ||
console.log(`> Writing File ${fileName}`); | ||
fileService.writeJson(fileName, timelockTransactions); | ||
console.log("✅ Done"); | ||
}; | ||
|
||
export default func; | ||
func.tags = ["UpgradeXALPACAv2Rewarder"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters