Skip to content

Commit

Permalink
chore: upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-alpaca committed Mar 19, 2024
1 parent 95b778f commit 2083ba6
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers, upgrades } from "hardhat";
import { getConfig } from "../../../utils/config";
import { MaybeMultisigTimelock } from "../../../utils/maybe-multisig";
import { ProxyAdmin__factory } from "../../../../typechain";
import { compareAddress } from "../../../utils/address";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const config = getConfig();
const networkInfo = await ethers.provider.getNetwork();

const TARGET_ADDRESS = config.MarketOrderRouter;

const EXACT_ETA = 0;

const deployer = (await ethers.getSigners())[0];

const marketOrderRouter = await ethers.getContractFactory(
"MarketOrderRouter",
deployer
);

console.log(`> Preparing to upgrade MarketOrderRouter`);
const newMarketOrderRouter = await upgrades.prepareUpgrade(
TARGET_ADDRESS,
marketOrderRouter
);

console.log(
`> New MarketOrderRouter Implementation address: ${newMarketOrderRouter}`
);
const proxyAdmin = ProxyAdmin__factory.connect(config.ProxyAdmin, deployer);

if (!compareAddress(await proxyAdmin.owner(), config.Timelock)) {
const upgradeTx = await upgrades.upgradeProxy(
TARGET_ADDRESS,
marketOrderRouter
);
console.log(`> ⛓ Tx is submitted: ${upgradeTx.deployTransaction.hash}`);
console.log(`> Waiting for tx to be mined...`);
await upgradeTx.deployTransaction.wait();

console.log(`> Tx is mined!`);
} else {
const timelock = new MaybeMultisigTimelock(networkInfo.chainId, deployer);

console.log(`> Queue tx on Timelock to upgrade the implementation`);
await timelock.queueTransaction(
`Upgrade MarketOrderRouter`,
config.ProxyAdmin,
"0",
"upgrade(address,address)",
["address", "address"],
[TARGET_ADDRESS, newMarketOrderRouter],
EXACT_ETA
);
}

console.log("> ✅ Done");
};

export default func;
func.tags = ["UpgradeMarketOrderRouter"];
16 changes: 2 additions & 14 deletions deploy/periphery/orderbook/upgrade/upgrade-orderbook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers, upgrades, tenderly } from "hardhat";
import { ethers, upgrades } from "hardhat";
import { getConfig } from "../../../utils/config";
import { getImplementationAddress } from "@openzeppelin/upgrades-core";
import { MaybeMultisigTimelock } from "../../../utils/maybe-multisig";
import { ProxyAdmin__factory } from "../../../../typechain";
import { compareAddress } from "../../../utils/address";
Expand Down Expand Up @@ -45,22 +44,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
"0",
"upgrade(address,address)",
["address", "address"],
[config.Pools.ALP.orderbook, newOrderbook02],
[TARGET_ADDRESS, newOrderbook02],
EXACT_ETA
);
}

const implAddress = await getImplementationAddress(
ethers.provider,
TARGET_ADDRESS
);

console.log(`> Verify contract on Tenderly`);
await tenderly.verify({
address: implAddress,
name: "Orderbook02",
});

console.log("> ✅ Done");
};

Expand Down
1 change: 0 additions & 1 deletion deploy/trade-mining/paradeen-feed-pyth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const weeklyTradingVolume = await ap.weeklyTotalSupply(weekCursor);
const tradingFeeCollected = weeklyTradingVolume
.mul(tradingFeeBps)
.mul(2) // account closing volume assure
.div(MAX_BPS);
const pythPrice = await getCoinGeckoPriceUSD("pyth-network");

Expand Down
64 changes: 64 additions & 0 deletions deploy/trade-mining/upgrade/upgrade-trade-mining-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers, upgrades, tenderly } from "hardhat";
import { getConfig } from "../../utils/config";
import { ProxyAdmin__factory } from "../../../typechain";
import { compareAddress } from "../../utils/address";
import { MaybeMultisigTimelock } from "../../utils/maybe-multisig";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const config = getConfig();
const networkInfo = await ethers.provider.getNetwork();

const TARGET_ADDRESS = config.TradeMining.tradeMiningManager;

const EXACT_ETA = 0;

const deployer = (await ethers.getSigners())[0];

const tradeMiningManager = await ethers.getContractFactory(
"TradeMiningManager",
deployer
);

console.log(`> Preparing to upgrade TradeMiningManager`);
const newTradeMiningManager = await upgrades.prepareUpgrade(
TARGET_ADDRESS,
tradeMiningManager
);

console.log(
`> New TradeMiningManager Implementation address: ${newTradeMiningManager}`
);
const proxyAdmin = ProxyAdmin__factory.connect(config.ProxyAdmin, deployer);

if (!compareAddress(await proxyAdmin.owner(), config.Timelock)) {
const upgradeTx = await upgrades.upgradeProxy(
TARGET_ADDRESS,
tradeMiningManager
);
console.log(`> ⛓ Tx is submitted: ${upgradeTx.deployTransaction.hash}`);
console.log(`> Waiting for tx to be mined...`);
await upgradeTx.deployTransaction.wait();

console.log(`> Tx is mined!`);
} else {
const timelock = new MaybeMultisigTimelock(networkInfo.chainId, deployer);

console.log(`> Queue tx on Timelock to upgrade the implementation`);
await timelock.queueTransaction(
`Upgrade TrademiningManager`,
config.ProxyAdmin,
"0",
"upgrade(address,address)",
["address", "address"],
[TARGET_ADDRESS, newTradeMiningManager],
EXACT_ETA
);
}

console.log("> ✅ Done");
};

export default func;
func.tags = ["UpgradeTradeMiningManager"];
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@
"deploy:mainnet:trade-mining:set_miner_manager_point": "hardhat --network mainnet deploy --no-compile --reset --tags SetMiningManagerPoint",
"deploy:mainnet:trade-mining:set_miner_manager_period": "hardhat --network mainnet deploy --no-compile --reset --tags SetMiningManagerPeriod",
"deploy:mainnet:trade-mining:set_ap_token_minter": "hardhat --network mainnet deploy --no-compile --reset --tags SetAPTokenMinter",
"deploy:mainnet:trade-mining:upgrade:trade-mining-manager": "npx hardhat --network mainnet deploy --no-compile --reset --tags UpgradeTradeMiningManager",
"deploy:mainnet:orderbook:set-min-execution-fee": "npx hardhat --network mainnet deploy --no-compile --reset --tags SetMinExecutionFee",
"deploy:mainnet:periphery:liquidation-routers:deploy:liquidation-router01": "npx hardhat --network mainnet deploy --no-compile --reset --tags DeployLiquidationRouter01",
"deploy:mainnet:periphery:liquidation-routers:config:set-liquidator": "npx hardhat --network mainnet deploy --no-compile --reset --tags LiquidationRouter01SetLiquidator",
"deploy:mainnet:periphery:market-order-router:deploy:market-order-router": "npx hardhat --network mainnet deploy --no-compile --reset --tags MarketOrderRouter_Deploy",
"deploy:mainnet:periphery:market-order-router:config:set-delay-values": "npx hardhat --network mainnet deploy --no-compile --reset --tags MarketOrderRouter_SetDelayValues",
"deploy:mainnet:periphery:market-order-router:config:set-min-execution-fee": "npx hardhat --network mainnet deploy --no-compile --reset --tags MarketOrderRouter_SetMinExecutionFee",
"deploy:mainnet:periphery:market-order-executor:deploy:market-order-executor": "npx hardhat --network mainnet deploy --no-compile --reset --tags MarketOrderExecutor_Deploy",
"deploy:mainnet:periphery:market-order-router:upgrade:market-order-router": "npx hardhat --network mainnet deploy --no-compile --reset --tags UpgradeMarketOrderRouter",
"----------Script Tenderly Fork & Non Configuration Update-------------": "----------Simulate Tenderly Fork-------------",
"script:tenderly:simulate_add_liquidity": "hardhat --network tenderly invoke:simulate_add_liquidity",
"script:tenderly:simulate_open_position": "hardhat --network tenderly invoke:simulate_open_position",
Expand Down

0 comments on commit 2083ba6

Please sign in to comment.