add absorb script and upgrade script

This commit is contained in:
2026-01-06 15:57:36 +08:00
parent b1b3b07b21
commit eecae142a4
33 changed files with 3614 additions and 3070 deletions

View File

@@ -0,0 +1,109 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 Configurator 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 Configurator 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-lending.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const network = await ethers.provider.getNetwork();
const chainId = network.chainId.toString();
const allDeployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
const deployments = allDeployments[chainId];
if (!deployments) {
throw new Error(`未找到网络 ${chainId} 的部署信息`);
}
console.log("📋 当前部署的合约:");
console.log(" Configurator Proxy:", deployments.configuratorProxy);
console.log(" Configurator Impl: ", deployments.configuratorImpl);
console.log("");
// ========== 升级 Configurator ==========
console.log("🔄 Phase 1: 升级 Configurator 合约");
console.log(" 当前 Configurator Proxy:", deployments.configuratorProxy);
console.log(" 当前 Configurator Implementation:", deployments.configuratorImpl);
// 获取新的 Configurator 合约工厂
const ConfiguratorV2 = await ethers.getContractFactory("Configurator");
console.log("\n 正在验证新实现合约...");
const upgradedConfigurator = await upgrades.upgradeProxy(
deployments.configuratorProxy,
ConfiguratorV2,
{
kind: "uups",
// unsafeSkipStorageCheck: true // 跳过存储布局检查(请确保你了解风险)
}
);
await upgradedConfigurator.waitForDeployment();
console.log(" ✅ Configurator 已升级!");
// 获取新的实现合约地址
const upgradedConfiguratorAddress = await upgradedConfigurator.getAddress();
const newConfiguratorImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedConfiguratorAddress);
console.log(" 新 Configurator Implementation:", newConfiguratorImplAddress);
// 验证升级
console.log("\n 验证升级结果:");
console.log(" Configurator Proxy (不变):", upgradedConfiguratorAddress);
console.log(" Owner:", await upgradedConfigurator.owner());
// 保存升级历史
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "Configurator",
oldImplementation: deployments.configuratorImpl,
newImplementation: newConfiguratorImplAddress,
upgrader: deployer.address
});
// 保存新的实现地址
deployments.configuratorImpl = newConfiguratorImplAddress;
deployments.configuratorUpgradeTimestamp = new Date().toISOString();
allDeployments[chainId] = deployments;
fs.writeFileSync(deploymentsPath, JSON.stringify(allDeployments, null, 2));
console.log("\n✅ Configurator 升级完成!");
console.log("=====================================");
console.log("旧实现:", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("新实现:", newConfiguratorImplAddress);
console.log("=====================================\n");
console.log("💾 升级信息已保存到:", deploymentsPath);
console.log("");
console.log("📌 重要提示:");
console.log(" 1. 代理地址保持不变,用户无需更改合约地址");
console.log(" 2. 所有状态数据已保留");
console.log(" 3. 建议运行验证脚本确认升级成功");
console.log(" 4. 建议在测试网充分测试后再升级主网\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,114 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 Lending 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 Lending 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-lending.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const network = await ethers.provider.getNetwork();
const chainId = network.chainId.toString();
const allDeployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
const deployments = allDeployments[chainId];
if (!deployments) {
throw new Error(`未找到网络 ${chainId} 的部署信息`);
}
if (!deployments.lendingProxy) {
throw new Error("未找到 Lending Proxy 地址,请先运行配置脚本");
}
console.log("📋 当前部署的合约:");
console.log(" Lending Proxy:", deployments.lendingProxy);
console.log(" Lending Impl: ", deployments.lendingImpl);
console.log("");
// ========== 升级 Lending ==========
console.log("🔄 Phase 1: 升级 Lending 合约");
console.log(" 当前 Lending Proxy:", deployments.lendingProxy);
console.log(" 当前 Lending Implementation:", deployments.lendingImpl);
// 获取新的 Lending 合约工厂
const LendingV2 = await ethers.getContractFactory("Lending");
console.log("\n 正在验证新实现合约...");
// upgrades.upgradeProxy 会自动验证存储布局兼容性
const upgradedLending = await upgrades.upgradeProxy(
deployments.lendingProxy,
LendingV2,
{
kind: "uups"
}
);
await upgradedLending.waitForDeployment();
console.log(" ✅ Lending 已升级!");
// 获取新的实现合约地址
const upgradedLendingAddress = await upgradedLending.getAddress();
const newLendingImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedLendingAddress);
console.log(" 新 Lending Implementation:", newLendingImplAddress);
// 验证升级
console.log("\n 验证升级结果:");
console.log(" Lending Proxy (不变):", upgradedLendingAddress);
console.log(" Owner:", await upgradedLending.owner());
console.log(" Base Token:", await upgradedLending.baseToken());
// 保存升级历史
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "Lending",
oldImplementation: deployments.lendingImpl,
newImplementation: newLendingImplAddress,
upgrader: deployer.address
});
// 保存新的实现地址
deployments.lendingImpl = newLendingImplAddress;
deployments.lendingUpgradeTimestamp = new Date().toISOString();
allDeployments[chainId] = deployments;
fs.writeFileSync(deploymentsPath, JSON.stringify(allDeployments, null, 2));
console.log("\n✅ Lending 升级完成!");
console.log("=====================================");
console.log("旧实现:", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("新实现:", newLendingImplAddress);
console.log("=====================================\n");
console.log("💾 升级信息已保存到:", deploymentsPath);
console.log("");
console.log("📌 重要提示:");
console.log(" 1. 代理地址保持不变,用户无需更改合约地址");
console.log(" 2. 所有状态数据已保留");
console.log(" 3. 建议运行验证脚本确认升级成功");
console.log(" 4. 建议在测试网充分测试后再升级主网\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,117 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 LendingPriceFeed 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 LendingPriceFeed 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-lending.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const network = await ethers.provider.getNetwork();
const chainId = network.chainId.toString();
const allDeployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
const deployments = allDeployments[chainId];
if (!deployments) {
throw new Error(`未找到网络 ${chainId} 的部署信息`);
}
if (!deployments.lendingPriceFeed) {
throw new Error("未找到 LendingPriceFeed Proxy 地址,请先运行部署脚本");
}
console.log("📋 当前部署的合约:");
console.log(" LendingPriceFeed Proxy:", deployments.lendingPriceFeed);
if (deployments.lendingPriceFeedImpl) {
console.log(" LendingPriceFeed Impl: ", deployments.lendingPriceFeedImpl);
}
console.log("");
// ========== 升级 LendingPriceFeed ==========
console.log("🔄 Phase 1: 升级 LendingPriceFeed 合约");
console.log(" 当前 LendingPriceFeed Proxy:", deployments.lendingPriceFeed);
if (deployments.lendingPriceFeedImpl) {
console.log(" 当前 LendingPriceFeed Implementation:", deployments.lendingPriceFeedImpl);
}
// 获取新的 LendingPriceFeed 合约工厂
const LendingPriceFeedV2 = await ethers.getContractFactory("LendingPriceFeed");
console.log("\n 正在验证新实现合约...");
const upgradedPriceFeed = await upgrades.upgradeProxy(
deployments.lendingPriceFeed,
LendingPriceFeedV2,
{
kind: "uups"
}
);
await upgradedPriceFeed.waitForDeployment();
console.log(" ✅ LendingPriceFeed 已升级!");
// 获取新的实现合约地址
const upgradedPriceFeedAddress = await upgradedPriceFeed.getAddress();
const newPriceFeedImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedPriceFeedAddress);
console.log(" 新 LendingPriceFeed Implementation:", newPriceFeedImplAddress);
// 验证升级
console.log("\n 验证升级结果:");
console.log(" LendingPriceFeed Proxy (不变):", upgradedPriceFeedAddress);
console.log(" Owner:", await upgradedPriceFeed.owner());
console.log(" USDC Address:", await upgradedPriceFeed.usdcAddress());
// 保存升级历史
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "LendingPriceFeed",
oldImplementation: deployments.lendingPriceFeedImpl || "未记录",
newImplementation: newPriceFeedImplAddress,
upgrader: deployer.address
});
// 保存新的实现地址
deployments.lendingPriceFeedImpl = newPriceFeedImplAddress;
deployments.lastUpgradeTime = new Date().toISOString();
allDeployments[chainId] = deployments;
fs.writeFileSync(deploymentsPath, JSON.stringify(allDeployments, null, 2));
console.log("\n✅ LendingPriceFeed 升级完成!");
console.log("=====================================");
console.log("旧实现:", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("新实现:", newPriceFeedImplAddress);
console.log("=====================================\n");
console.log("💾 升级信息已保存到:", deploymentsPath);
console.log("");
console.log("📌 重要提示:");
console.log(" 1. 代理地址保持不变,用户无需更改合约地址");
console.log(" 2. 所有状态数据已保留");
console.log(" 3. 建议运行验证脚本确认升级成功");
console.log(" 4. 建议在测试网充分测试后再升级主网\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,113 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 USDY 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 USDY 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.USDY?.proxy) {
throw new Error("未找到 USDY 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" USDY Proxy: ", deployments.contracts.USDY.proxy);
console.log(" USDY Implementation: ", deployments.contracts.USDY.implementation);
console.log("");
// ========== 升级 USDY ==========
console.log("🔄 Phase 1: 升级 USDY 代理合约");
// 获取新的 USDY 合约工厂
const USDYV2 = await ethers.getContractFactory("USDY");
console.log(" 正在验证新实现合约...");
const upgradedUSDY = await upgrades.upgradeProxy(
deployments.contracts.USDY.proxy,
USDYV2,
{
kind: "uups"
}
);
await upgradedUSDY.waitForDeployment();
console.log(" ✅ USDY 已升级!");
// 获取新的实现合约地址
const upgradedUSDYAddress = await upgradedUSDY.getAddress();
const newUSDYImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedUSDYAddress);
console.log(" 新 USDY Implementation:", newUSDYImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" USDY Proxy (不变):", upgradedUSDYAddress);
console.log(" Name:", await upgradedUSDY.name());
console.log(" Symbol:", await upgradedUSDY.symbol());
console.log(" Total Supply:", ethers.formatUnits(await upgradedUSDY.totalSupply(), 6));
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "USDY",
oldImplementation: deployments.contracts.USDY.implementation,
newImplementation: newUSDYImplAddress,
upgrader: deployer.address
});
deployments.contracts.USDY.implementation = newUSDYImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 USDY Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 USDY Implementation:");
console.log(" ", newUSDYImplAddress);
console.log("");
console.log("USDY Proxy (不变):");
console.log(" ", deployments.contracts.USDY.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!");
console.log("");
console.log("📌 重要提示:");
console.log(" 1. USDY 代理地址保持不变");
console.log(" 2. 所有状态数据已保留");
console.log(" 3. 建议运行验证脚本确认升级成功");
console.log(" 4. 主网升级前务必充分测试\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,125 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTAssetFactory 合约
*
* 升级步骤:
* 1. 部署新的 YTAssetFactory 实现合约
* 2. 使用 upgrades.upgradeProxy() 进行 UUPS 升级
* 3. 验证新功能
*
* 注意:
* - 这是 UUPS 代理升级,代理地址保持不变
* - 所有状态数据已保留
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTAssetFactory 系统");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-vault-system.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件 deployments-vault-system.json请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTAssetFactory?.proxy) {
throw new Error("未找到 YTAssetFactory 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTAssetFactory Proxy: ", deployments.contracts.YTAssetFactory.proxy);
console.log(" YTAssetFactory Implementation: ", deployments.contracts.YTAssetFactory.implementation);
console.log("");
// ========== Phase 1: 升级 YTAssetFactory ==========
console.log("🔄 Phase 1: 升级 YTAssetFactory 代理合约");
console.log(" 当前 YTAssetFactory Proxy:", deployments.contracts.YTAssetFactory.proxy);
console.log(" 当前 YTAssetFactory Implementation:", deployments.contracts.YTAssetFactory.implementation);
// 获取新的 YTAssetFactory 合约工厂
const YTAssetFactoryV2 = await ethers.getContractFactory("YTAssetFactory");
console.log("\n 正在验证新实现合约...");
const upgradedFactory = await upgrades.upgradeProxy(
deployments.contracts.YTAssetFactory.proxy,
YTAssetFactoryV2,
{
kind: "uups"
}
);
await upgradedFactory.waitForDeployment();
console.log(" ✅ YTAssetFactory 已升级!");
// 获取新的实现合约地址
const upgradedFactoryAddress = await upgradedFactory.getAddress();
const newFactoryImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedFactoryAddress);
console.log(" 新 YTAssetFactory Implementation:", newFactoryImplAddress);
console.log("");
// ========== Phase 2: 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTAssetFactory Proxy (不变):", upgradedFactoryAddress);
console.log(" Owner:", await upgradedFactory.owner());
console.log(" Vault Implementation:", await upgradedFactory.vaultImplementation());
console.log(" USDC Address:", await upgradedFactory.usdcAddress());
console.log("");
// ========== 保存更新的部署信息 ==========
// 保存旧的实现地址作为历史记录
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTAssetFactory",
oldImplementation: deployments.contracts.YTAssetFactory.implementation,
newImplementation: newFactoryImplAddress,
upgrader: deployer.address
});
// 更新当前实现地址
deployments.contracts.YTAssetFactory.implementation = newFactoryImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTAssetFactory Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTAssetFactory Implementation:");
console.log(" ", newFactoryImplAddress);
console.log("");
console.log("Factory Proxy (不变):");
console.log(" ", deployments.contracts.YTAssetFactory.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!");
console.log("");
console.log("📌 重要提示:");
console.log(" 1. YTAssetFactory 代理地址保持不变");
console.log(" 2. 所有状态数据已保留");
console.log(" 3. 建议运行验证脚本确认升级成功");
console.log(" 4. 主网升级前务必充分测试\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,107 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTLPToken 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTLPToken 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTLPToken?.proxy) {
throw new Error("未找到 YTLPToken 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTLPToken Proxy: ", deployments.contracts.YTLPToken.proxy);
console.log(" YTLPToken Implementation: ", deployments.contracts.YTLPToken.implementation);
console.log("");
// ========== 升级 YTLPToken ==========
console.log("🔄 Phase 1: 升级 YTLPToken 代理合约");
// 获取新的 YTLPToken 合约工厂
const YTLPTokenV2 = await ethers.getContractFactory("YTLPToken");
console.log(" 正在验证新实现合约...");
const upgradedYTLPToken = await upgrades.upgradeProxy(
deployments.contracts.YTLPToken.proxy,
YTLPTokenV2,
{
kind: "uups"
}
);
await upgradedYTLPToken.waitForDeployment();
console.log(" ✅ YTLPToken 已升级!");
// 获取新的实现合约地址
const upgradedYTLPTokenAddress = await upgradedYTLPToken.getAddress();
const newYTLPTokenImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedYTLPTokenAddress);
console.log(" 新 YTLPToken Implementation:", newYTLPTokenImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTLPToken Proxy (不变):", upgradedYTLPTokenAddress);
console.log(" Name:", await upgradedYTLPToken.name());
console.log(" Symbol:", await upgradedYTLPToken.symbol());
console.log(" Total Supply:", ethers.formatEther(await upgradedYTLPToken.totalSupply()));
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTLPToken",
oldImplementation: deployments.contracts.YTLPToken.implementation,
newImplementation: newYTLPTokenImplAddress,
upgrader: deployer.address
});
deployments.contracts.YTLPToken.implementation = newYTLPTokenImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTLPToken Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTLPToken Implementation:");
console.log(" ", newYTLPTokenImplAddress);
console.log("");
console.log("YTLPToken Proxy (不变):");
console.log(" ", deployments.contracts.YTLPToken.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,105 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTPoolManager 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTPoolManager 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTPoolManager?.proxy) {
throw new Error("未找到 YTPoolManager 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTPoolManager Proxy: ", deployments.contracts.YTPoolManager.proxy);
console.log(" YTPoolManager Implementation: ", deployments.contracts.YTPoolManager.implementation);
console.log("");
// ========== 升级 YTPoolManager ==========
console.log("🔄 Phase 1: 升级 YTPoolManager 代理合约");
// 获取新的 YTPoolManager 合约工厂
const YTPoolManagerV2 = await ethers.getContractFactory("YTPoolManager");
console.log(" 正在验证新实现合约...");
const upgradedYTPoolManager = await upgrades.upgradeProxy(
deployments.contracts.YTPoolManager.proxy,
YTPoolManagerV2,
{
kind: "uups"
}
);
await upgradedYTPoolManager.waitForDeployment();
console.log(" ✅ YTPoolManager 已升级!");
// 获取新的实现合约地址
const upgradedYTPoolManagerAddress = await upgradedYTPoolManager.getAddress();
const newYTPoolManagerImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedYTPoolManagerAddress);
console.log(" 新 YTPoolManager Implementation:", newYTPoolManagerImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTPoolManager Proxy (不变):", upgradedYTPoolManagerAddress);
console.log(" Owner:", await upgradedYTPoolManager.owner());
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTPoolManager",
oldImplementation: deployments.contracts.YTPoolManager.implementation,
newImplementation: newYTPoolManagerImplAddress,
upgrader: deployer.address
});
deployments.contracts.YTPoolManager.implementation = newYTPoolManagerImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTPoolManager Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTPoolManager Implementation:");
console.log(" ", newYTPoolManagerImplAddress);
console.log("");
console.log("YTPoolManager Proxy (不变):");
console.log(" ", deployments.contracts.YTPoolManager.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,105 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTPriceFeed 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTPriceFeed 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTPriceFeed?.proxy) {
throw new Error("未找到 YTPriceFeed 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTPriceFeed Proxy: ", deployments.contracts.YTPriceFeed.proxy);
console.log(" YTPriceFeed Implementation: ", deployments.contracts.YTPriceFeed.implementation);
console.log("");
// ========== 升级 YTPriceFeed ==========
console.log("🔄 Phase 1: 升级 YTPriceFeed 代理合约");
// 获取新的 YTPriceFeed 合约工厂
const YTPriceFeedV2 = await ethers.getContractFactory("YTPriceFeed");
console.log(" 正在验证新实现合约...");
const upgradedYTPriceFeed = await upgrades.upgradeProxy(
deployments.contracts.YTPriceFeed.proxy,
YTPriceFeedV2,
{
kind: "uups"
}
);
await upgradedYTPriceFeed.waitForDeployment();
console.log(" ✅ YTPriceFeed 已升级!");
// 获取新的实现合约地址
const upgradedYTPriceFeedAddress = await upgradedYTPriceFeed.getAddress();
const newYTPriceFeedImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedYTPriceFeedAddress);
console.log(" 新 YTPriceFeed Implementation:", newYTPriceFeedImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTPriceFeed Proxy (不变):", upgradedYTPriceFeedAddress);
console.log(" Owner:", await upgradedYTPriceFeed.owner());
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTPriceFeed",
oldImplementation: deployments.contracts.YTPriceFeed.implementation,
newImplementation: newYTPriceFeedImplAddress,
upgrader: deployer.address
});
deployments.contracts.YTPriceFeed.implementation = newYTPriceFeedImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTPriceFeed Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTPriceFeed Implementation:");
console.log(" ", newYTPriceFeedImplAddress);
console.log("");
console.log("YTPriceFeed Proxy (不变):");
console.log(" ", deployments.contracts.YTPriceFeed.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,105 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTRewardRouter 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTRewardRouter 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTRewardRouter?.proxy) {
throw new Error("未找到 YTRewardRouter 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTRewardRouter Proxy: ", deployments.contracts.YTRewardRouter.proxy);
console.log(" YTRewardRouter Implementation: ", deployments.contracts.YTRewardRouter.implementation);
console.log("");
// ========== 升级 YTRewardRouter ==========
console.log("🔄 Phase 1: 升级 YTRewardRouter 代理合约");
// 获取新的 YTRewardRouter 合约工厂
const YTRewardRouterV2 = await ethers.getContractFactory("YTRewardRouter");
console.log(" 正在验证新实现合约...");
const upgradedYTRewardRouter = await upgrades.upgradeProxy(
deployments.contracts.YTRewardRouter.proxy,
YTRewardRouterV2,
{
kind: "uups"
}
);
await upgradedYTRewardRouter.waitForDeployment();
console.log(" ✅ YTRewardRouter 已升级!");
// 获取新的实现合约地址
const upgradedYTRewardRouterAddress = await upgradedYTRewardRouter.getAddress();
const newYTRewardRouterImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedYTRewardRouterAddress);
console.log(" 新 YTRewardRouter Implementation:", newYTRewardRouterImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTRewardRouter Proxy (不变):", upgradedYTRewardRouterAddress);
console.log(" Owner:", await upgradedYTRewardRouter.owner());
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTRewardRouter",
oldImplementation: deployments.contracts.YTRewardRouter.implementation,
newImplementation: newYTRewardRouterImplAddress,
upgrader: deployer.address
});
deployments.contracts.YTRewardRouter.implementation = newYTRewardRouterImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTRewardRouter Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTRewardRouter Implementation:");
console.log(" ", newYTRewardRouterImplAddress);
console.log("");
console.log("YTRewardRouter Proxy (不变):");
console.log(" ", deployments.contracts.YTRewardRouter.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,105 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 升级 YTVault 合约
* 使用 upgrades.upgradeProxy() 进行 UUPS 升级
*/
async function main() {
const [deployer] = await ethers.getSigners();
console.log("\n==========================================");
console.log("🔄 升级 YTVault 合约");
console.log("==========================================");
console.log("升级账户:", deployer.address);
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-ytlp.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件,请先运行部署脚本");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
if (!deployments.contracts?.YTVault?.proxy) {
throw new Error("未找到 YTVault 部署信息");
}
console.log("📋 当前部署的合约:");
console.log(" YTVault Proxy: ", deployments.contracts.YTVault.proxy);
console.log(" YTVault Implementation: ", deployments.contracts.YTVault.implementation);
console.log("");
// ========== 升级 YTVault ==========
console.log("🔄 Phase 1: 升级 YTVault 代理合约");
// 获取新的 YTVault 合约工厂
const YTVaultV2 = await ethers.getContractFactory("YTVault");
console.log(" 正在验证新实现合约...");
const upgradedYTVault = await upgrades.upgradeProxy(
deployments.contracts.YTVault.proxy,
YTVaultV2,
{
kind: "uups"
}
);
await upgradedYTVault.waitForDeployment();
console.log(" ✅ YTVault 已升级!");
// 获取新的实现合约地址
const upgradedYTVaultAddress = await upgradedYTVault.getAddress();
const newYTVaultImplAddress = await upgrades.erc1967.getImplementationAddress(upgradedYTVaultAddress);
console.log(" 新 YTVault Implementation:", newYTVaultImplAddress);
console.log("");
// ========== 验证升级结果 ==========
console.log("🔄 Phase 2: 验证升级结果");
console.log(" YTVault Proxy (不变):", upgradedYTVaultAddress);
console.log(" Owner:", await upgradedYTVault.owner());
console.log("");
// ========== 保存更新的部署信息 ==========
if (!deployments.upgradeHistory) {
deployments.upgradeHistory = [];
}
deployments.upgradeHistory.push({
timestamp: new Date().toISOString(),
contract: "YTVault",
oldImplementation: deployments.contracts.YTVault.implementation,
newImplementation: newYTVaultImplAddress,
upgrader: deployer.address
});
deployments.contracts.YTVault.implementation = newYTVaultImplAddress;
deployments.lastUpdate = new Date().toISOString();
fs.writeFileSync(deploymentsPath, JSON.stringify(deployments, null, 2));
console.log("💾 升级信息已保存到:", deploymentsPath);
// ========== 升级总结 ==========
console.log("\n🎉 升级总结:");
console.log("=====================================");
console.log("旧 YTVault Implementation:");
console.log(" ", deployments.upgradeHistory[deployments.upgradeHistory.length - 1].oldImplementation);
console.log("");
console.log("新 YTVault Implementation:");
console.log(" ", newYTVaultImplAddress);
console.log("");
console.log("YTVault Proxy (不变):");
console.log(" ", deployments.contracts.YTVault.proxy);
console.log("=====================================\n");
console.log("✅ 升级完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -1,182 +0,0 @@
import { ethers, upgrades } from "hardhat";
import * as fs from "fs";
import * as path from "path";
/**
* 验证 YTAssetVault 升级结果
*
* 功能:
* 1. 检查 Factory 的实现地址是否已更新
* 2. 验证现有 Vault 的实现地址
* 3. 测试新功能是否可用
*/
async function main() {
console.log("\n==========================================");
console.log("🔍 验证 YTAssetVault 升级结果");
console.log("==========================================\n");
// ========== 读取部署信息 ==========
const deploymentsPath = path.join(__dirname, "../../deployments-vault-system.json");
if (!fs.existsSync(deploymentsPath)) {
throw new Error("未找到部署信息文件");
}
const deployments = JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"));
const factory = await ethers.getContractAt(
"YTAssetFactory",
deployments.contracts.YTAssetFactory.proxy
);
// ========== 验证 Factory ==========
console.log("📋 验证 Factory 配置");
console.log("=====================================");
const currentImplInFactory = await factory.vaultImplementation();
const expectedImpl = deployments.contracts.YTAssetVault.implementation;
console.log("Factory Proxy: ", deployments.contracts.YTAssetFactory.proxy);
console.log("当前 vaultImplementation:", currentImplInFactory);
console.log("配置文件中的实现: ", expectedImpl);
if (currentImplInFactory.toLowerCase() === expectedImpl.toLowerCase()) {
console.log("✅ Factory 配置正确!\n");
} else {
console.log("❌ Factory 配置不匹配!\n");
}
// ========== 验证已部署的 Vaults ==========
const vaults = deployments.vaults || [];
if (vaults.length === 0) {
console.log(" 没有已部署的 Vault\n");
return;
}
console.log("📋 验证已部署的 Vaults");
console.log("=====================================");
console.log(`发现 ${vaults.length} 个 Vault\n`);
const results: any[] = [];
for (let i = 0; i < vaults.length; i++) {
const vaultInfo = vaults[i];
console.log(`[${i + 1}/${vaults.length}] 检查 ${vaultInfo.symbol} (${vaultInfo.address})`);
try {
// 获取实现地址
const implAddress = await upgrades.erc1967.getImplementationAddress(vaultInfo.address);
const isUpgraded = implAddress.toLowerCase() === expectedImpl.toLowerCase();
console.log(` 实现地址: ${implAddress}`);
console.log(` 状态: ${isUpgraded ? '✅ 已升级' : '⏸️ 未升级'}`);
// 如果已升级,测试新功能
if (isUpgraded) {
const vault = await ethers.getContractAt("YTAssetVault", vaultInfo.address);
try {
// 测试新增的状态变量
const pendingCount = await vault.pendingRequestsCount();
const requestIdCounter = await vault.requestIdCounter();
const processedUpToIndex = await vault.processedUpToIndex();
console.log(` 新功能验证:`);
console.log(` - pendingRequestsCount: ${pendingCount}`);
console.log(` - requestIdCounter: ${requestIdCounter}`);
console.log(` - processedUpToIndex: ${processedUpToIndex}`);
// 测试新增的查询函数
const queueProgress = await vault.getQueueProgress();
console.log(` - 队列进度: ${queueProgress[0]}/${queueProgress[1]} (待处理: ${queueProgress[2]})`);
console.log(` ✅ 新功能工作正常`);
results.push({
index: i,
symbol: vaultInfo.symbol,
address: vaultInfo.address,
upgraded: true,
functional: true
});
} catch (error: any) {
console.log(` ⚠️ 新功能测试失败: ${error.message}`);
results.push({
index: i,
symbol: vaultInfo.symbol,
address: vaultInfo.address,
upgraded: true,
functional: false,
error: error.message
});
}
} else {
results.push({
index: i,
symbol: vaultInfo.symbol,
address: vaultInfo.address,
upgraded: false,
functional: false
});
}
} catch (error: any) {
console.log(` ❌ 检查失败: ${error.message}`);
results.push({
index: i,
symbol: vaultInfo.symbol,
address: vaultInfo.address,
upgraded: false,
functional: false,
error: error.message
});
}
console.log("");
}
// ========== 验证总结 ==========
console.log("📊 验证总结");
console.log("=====================================");
const upgraded = results.filter(r => r.upgraded);
const functional = results.filter(r => r.functional);
const needsUpgrade = results.filter(r => !r.upgraded);
console.log(`总 Vaults 数量: ${results.length}`);
console.log(`已升级: ${upgraded.length}`);
console.log(`功能正常: ${functional.length}`);
console.log(`待升级: ${needsUpgrade.length} ${needsUpgrade.length > 0 ? '⏸️' : ''}`);
console.log("");
if (needsUpgrade.length > 0) {
console.log("⏸️ 待升级的 Vaults:");
needsUpgrade.forEach(v => {
console.log(` [${v.index}] ${v.symbol}: ${v.address}`);
});
console.log("");
console.log("💡 升级命令:");
console.log(` factory.upgradeVault("vaultAddress", "${expectedImpl}")`);
console.log("");
}
// ========== 升级历史 ==========
if (deployments.upgradeHistory && deployments.upgradeHistory.length > 0) {
console.log("📜 升级历史");
console.log("=====================================");
deployments.upgradeHistory.forEach((h: any, idx: number) => {
console.log(`[${idx + 1}] ${h.timestamp}`);
console.log(` 升级者: ${h.upgrader}`);
console.log(` 旧实现: ${h.oldImplementation}`);
console.log(` 新实现: ${h.newImplementation}`);
});
console.log("");
}
console.log("✅ 验证完成!\n");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});