Files
assetxContracts/scripts/deploy/06-addVaultToWhitelist.ts
2025-12-18 13:07:35 +08:00

170 lines
5.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ethers } from "hardhat";
import * as fs from "fs";
/**
* 将YTAssetVault添加到YTVault白名单并设置价格
*/
async function main() {
console.log("开始添加Vault到白名单...\n");
const [deployer] = await ethers.getSigners();
console.log("操作账户:", deployer.address);
// ==================== 1. 读取部署地址 ====================
console.log("\n===== 1. 读取部署地址 =====");
// 读取YTLp系统部署信息
const ytlpDeployment = JSON.parse(fs.readFileSync("./deployments-ytlp.json", "utf8"));
const priceFeedAddress = ytlpDeployment.contracts.YTPriceFeed.proxy;
const vaultAddress = ytlpDeployment.contracts.YTVault.proxy;
console.log("YTPriceFeed:", priceFeedAddress);
console.log("YTVault: ", vaultAddress);
// 读取YTAssetFactory部署信息
const vaultSystemDeployment = JSON.parse(fs.readFileSync("./deployments-vault-system.json", "utf8"));
const vaults = vaultSystemDeployment.vaults;
if (!vaults || vaults.length === 0) {
throw new Error("未找到YTAssetVault请先运行 createVault.ts");
}
console.log("\n找到", vaults.length, "个YTAssetVault:");
vaults.forEach((v: any, i: number) => {
console.log(` ${i + 1}. ${v.name} (${v.symbol}): ${v.address}`);
});
// 获取合约实例
const priceFeed = await ethers.getContractAt("YTPriceFeed", priceFeedAddress);
const vault = await ethers.getContractAt("YTVault", vaultAddress);
// ==================== 2. 添加到白名单 ====================
console.log("\n===== 2. 添加到白名单 =====");
// 配置参数(可根据需要调整)
// 注意:总权重 = 4000 + 3000 + 2000 = 9000
const whitelistParams = [
{
weight: 4000, // 4000/9000 = 44.44%
maxUsdyAmount: ethers.parseEther("45000000"), // 4500万
isStable: false
},
{
weight: 3000, // 3000/9000 = 33.33%
maxUsdyAmount: ethers.parseEther("35000000"), // 3500万
isStable: false
},
{
weight: 2000, // 2000/9000 = 22.22%
maxUsdyAmount: ethers.parseEther("25000000"), // 2500万
isStable: false
}
];
for (let i = 0; i < vaults.length && i < whitelistParams.length; i++) {
const v = vaults[i];
const params = whitelistParams[i];
console.log(`\n添加 ${v.name} (${v.symbol}) 到白名单...`);
const tx = await vault.setWhitelistedToken(
v.address,
18, // decimals
params.weight,
params.maxUsdyAmount,
params.isStable
);
await tx.wait();
console.log(" ✅ 权重:", params.weight);
console.log(" ✅ 最大USDY:", ethers.formatEther(params.maxUsdyAmount));
console.log(" ✅ 是否稳定币:", params.isStable);
}
// ==================== 3. 设置价格 ====================
console.log("\n===== 3. 设置价格 =====");
for (const v of vaults) {
console.log(`\n设置 ${v.name} (${v.symbol}) 价格...`);
// 使用vault中保存的初始价格已经是1e30精度直接使用
const price = v.ytPrice;
const tx = await priceFeed.forceUpdatePrice(
v.address,
price
);
await tx.wait();
console.log(" ✅ 价格已设置:", ethers.formatUnits(price, 30), "(精度1e30)");
}
// ==================== 4. 设置WUSD价格来源 ====================
console.log("\n===== 4. 设置WUSD价格来源 =====");
// 使用第一个vault作为WUSD价格来源
const firstVault = vaults[0];
console.log("设置WUSD价格来源为:", firstVault.name, firstVault.address);
const tx = await priceFeed.setWusdPriceSource(firstVault.address);
await tx.wait();
console.log(" ✅ WUSD价格来源已设置");
// ==================== 5. 验证配置 ====================
console.log("\n===== 5. 验证配置 =====");
for (const v of vaults) {
const isWhitelisted = await vault.whitelistedTokens(v.address);
const weight = await vault.tokenWeights(v.address);
const price = await priceFeed.getPrice(v.address, true);
console.log(`\n${v.name} (${v.symbol}):`);
console.log(" 白名单:", isWhitelisted ? "✅" : "❌");
console.log(" 权重:", weight.toString());
console.log(" 价格:", ethers.formatUnits(price, 30));
}
const totalWeight = await vault.totalTokenWeights();
console.log("\n总权重:", totalWeight.toString());
const wusdPriceSource = await priceFeed.wusdPriceSource();
console.log("WUSD价格来源:", wusdPriceSource);
// ==================== 6. 输出摘要 ====================
console.log("\n===== 配置完成!=====");
console.log("\n✅ 已添加", vaults.length, "个vault到白名单");
console.log("✅ 已为所有vault设置初始价格");
console.log("✅ 已设置WUSD价格来源");
console.log("\n💡 系统已就绪,可以开始使用!");
// 保存配置信息
const configInfo = {
timestamp: new Date().toISOString(),
operator: deployer.address,
whitelistedVaults: vaults.map((v: any, i: number) => ({
name: v.name,
symbol: v.symbol,
address: v.address,
weight: whitelistParams[i]?.weight || 0,
maxUsdyAmount: whitelistParams[i]?.maxUsdyAmount.toString() || "0",
price: v.ytPrice
})),
totalWeight: totalWeight.toString(),
wusdPriceSource: wusdPriceSource
};
fs.writeFileSync(
"./deployments-whitelist-config.json",
JSON.stringify(configInfo, null, 2)
);
console.log("\n✅ 白名单配置信息已保存到 deployments-whitelist-config.json");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});