change WUSD payment to USDC
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
import { ethers, upgrades } from "hardhat";
|
||||
|
||||
/**
|
||||
* 部署WUSD代币
|
||||
*/
|
||||
async function main() {
|
||||
console.log("开始部署WUSD代币...\n");
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log("部署账户:", deployer.address);
|
||||
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
|
||||
|
||||
// ===== 部署WUSD (可升级) =====
|
||||
console.log("===== 部署WUSD (可升级) =====");
|
||||
const WUSD = await ethers.getContractFactory("WUSD");
|
||||
|
||||
console.log("部署WUSD代理...");
|
||||
const wusd = await upgrades.deployProxy(
|
||||
WUSD,
|
||||
["Wrapped USD", "WUSD"],
|
||||
{
|
||||
initializer: "initialize",
|
||||
kind: "uups",
|
||||
}
|
||||
);
|
||||
await wusd.waitForDeployment();
|
||||
const wusdAddress = await wusd.getAddress();
|
||||
console.log("✅ WUSD代理部署到:", wusdAddress);
|
||||
|
||||
const wusdImplAddress = await upgrades.erc1967.getImplementationAddress(wusdAddress);
|
||||
console.log("✅ WUSD实现地址:", wusdImplAddress);
|
||||
|
||||
// 验证部署
|
||||
const name = await wusd.name();
|
||||
const symbol = await wusd.symbol();
|
||||
const decimals = await wusd.decimals();
|
||||
console.log("\n代币信息:");
|
||||
console.log(" 名称:", name);
|
||||
console.log(" 符号:", symbol);
|
||||
console.log(" 精度:", decimals.toString());
|
||||
|
||||
// ===== 显示部署摘要 =====
|
||||
console.log("\n===== 部署摘要 =====");
|
||||
console.log("WUSD代理:", wusdAddress);
|
||||
console.log("WUSD实现:", wusdImplAddress);
|
||||
|
||||
// 保存到JSON文件
|
||||
const deploymentInfo = {
|
||||
network: (await ethers.provider.getNetwork()).name,
|
||||
chainId: (await ethers.provider.getNetwork()).chainId.toString(),
|
||||
deployer: deployer.address,
|
||||
timestamp: new Date().toISOString(),
|
||||
contracts: {
|
||||
WUSD: {
|
||||
proxy: wusdAddress,
|
||||
implementation: wusdImplAddress,
|
||||
name: name,
|
||||
symbol: symbol,
|
||||
decimals: Number(decimals)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const fs = require("fs");
|
||||
fs.writeFileSync(
|
||||
"./deployments-wusd.json",
|
||||
JSON.stringify(deploymentInfo, null, 2)
|
||||
);
|
||||
console.log("\n✅ 部署信息已保存到 deployments-wusd.json");
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
139
scripts/deploy/01-prepareUSDC.ts
Normal file
139
scripts/deploy/01-prepareUSDC.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { ethers } from "hardhat";
|
||||
import * as fs from "fs";
|
||||
|
||||
/**
|
||||
* 准备USDC和Chainlink配置
|
||||
* USDC是已存在的代币,无需部署
|
||||
*/
|
||||
async function main() {
|
||||
console.log("准备USDC和Chainlink配置...\n");
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log("操作账户:", deployer.address);
|
||||
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
|
||||
|
||||
// 获取当前网络
|
||||
const network = await ethers.provider.getNetwork();
|
||||
const chainId = network.chainId;
|
||||
|
||||
console.log("网络:", network.name);
|
||||
console.log("Chain ID:", chainId.toString());
|
||||
|
||||
// ===== 根据网络配置USDC和Chainlink地址 =====
|
||||
let usdcAddress: string;
|
||||
let usdcPriceFeedAddress: string;
|
||||
|
||||
if (chainId === 56n) {
|
||||
// BSC 主网
|
||||
console.log("\n检测到 BSC 主网");
|
||||
usdcAddress = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
|
||||
usdcPriceFeedAddress = "0x51597f405303C4377E36123cBc172b13269EA163";
|
||||
console.log("✅ USDC地址 (BSC):", usdcAddress);
|
||||
console.log("✅ Chainlink USDC/USD (BSC):", usdcPriceFeedAddress);
|
||||
} else if (chainId === 421614n) {
|
||||
// Arbitrum 测试网
|
||||
console.log("\n检测到 Arbitrum 测试网");
|
||||
usdcAddress = "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d";
|
||||
usdcPriceFeedAddress = "0x0153002d20B96532C639313c2d54c3dA09109309";
|
||||
console.log("✅ USDC地址 (Arbitrum):", usdcAddress);
|
||||
console.log("✅ Chainlink USDC/USD (Arbitrum):", usdcPriceFeedAddress);
|
||||
} else {
|
||||
throw new Error(`不支持的网络: ${chainId}`);
|
||||
}
|
||||
|
||||
// ===== 验证合约是否存在 =====
|
||||
console.log("\n===== 验证合约 =====");
|
||||
|
||||
if (usdcAddress !== "0x0000000000000000000000000000000000000000") {
|
||||
const usdcCode = await ethers.provider.getCode(usdcAddress);
|
||||
if (usdcCode === "0x") {
|
||||
console.log("❌ USDC合约不存在于该地址");
|
||||
} else {
|
||||
console.log("✅ USDC合约验证通过");
|
||||
|
||||
// 尝试读取USDC信息
|
||||
try {
|
||||
const usdc = await ethers.getContractAt(
|
||||
["function name() view returns (string)", "function symbol() view returns (string)", "function decimals() view returns (uint8)"],
|
||||
usdcAddress
|
||||
);
|
||||
const name = await usdc.name();
|
||||
const symbol = await usdc.symbol();
|
||||
const decimals = await usdc.decimals();
|
||||
|
||||
console.log(" 名称:", name);
|
||||
console.log(" 符号:", symbol);
|
||||
console.log(" 精度:", decimals.toString());
|
||||
} catch (e) {
|
||||
console.log(" ⚠️ 无法读取USDC信息(可能是接口不匹配)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (usdcPriceFeedAddress !== "0x0000000000000000000000000000000000000000") {
|
||||
const priceFeedCode = await ethers.provider.getCode(usdcPriceFeedAddress);
|
||||
if (priceFeedCode === "0x") {
|
||||
console.log("❌ Chainlink价格预言机不存在于该地址");
|
||||
} else {
|
||||
console.log("✅ Chainlink价格预言机验证通过");
|
||||
|
||||
// 尝试读取最新价格
|
||||
try {
|
||||
const priceFeed = await ethers.getContractAt(
|
||||
["function latestRoundData() view returns (uint80, int256, uint256, uint256, uint80)"],
|
||||
usdcPriceFeedAddress
|
||||
);
|
||||
const [, price] = await priceFeed.latestRoundData();
|
||||
console.log(" 当前USDC价格:", ethers.formatUnits(price, 8), "USD (精度1e8)");
|
||||
} catch (e) {
|
||||
console.log(" ⚠️ 无法读取价格数据");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 保存配置 =====
|
||||
const configInfo = {
|
||||
network: network.name,
|
||||
chainId: chainId.toString(),
|
||||
deployer: deployer.address,
|
||||
timestamp: new Date().toISOString(),
|
||||
contracts: {
|
||||
USDC: {
|
||||
address: usdcAddress,
|
||||
description: "USDC代币地址(已存在的合约)"
|
||||
},
|
||||
ChainlinkUSDCPriceFeed: {
|
||||
address: usdcPriceFeedAddress,
|
||||
description: "Chainlink USDC/USD 价格预言机",
|
||||
precision: "1e8"
|
||||
}
|
||||
},
|
||||
notes: {
|
||||
bsc: "BSC主网的USDC是18位精度",
|
||||
arbSepolia: "Arbitrum Sepolia的USDC是6位精度",
|
||||
}
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
"./deployments-usdc-config.json",
|
||||
JSON.stringify(configInfo, null, 2)
|
||||
);
|
||||
|
||||
// ===== 显示摘要 =====
|
||||
console.log("\n===== 配置摘要 =====");
|
||||
console.log("USDC地址: ", usdcAddress);
|
||||
console.log("Chainlink价格预言机: ", usdcPriceFeedAddress);
|
||||
console.log("\n✅ 配置已保存到 deployments-usdc-config.json");
|
||||
|
||||
console.log("\n💡 下一步:");
|
||||
console.log("1. 运行 02-deployYTLp.ts 部署YTLp系统");
|
||||
console.log("2. 运行 03-deployAsset.ts 部署YTAssetFactory系统");
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -39,21 +39,29 @@ async function main() {
|
||||
// ==================== 2. 部署核心合约 ====================
|
||||
console.log("\n===== 2. 部署核心合约 =====");
|
||||
|
||||
if (!fs.existsSync("./deployments-wusd.json")) {
|
||||
throw new Error("未找到 deployments-wusd.json,请先运行 deployWUSD.ts");
|
||||
// 读取USDC配置
|
||||
if (!fs.existsSync("./deployments-usdc-config.json")) {
|
||||
throw new Error("未找到 deployments-usdc-config.json,请先运行 01-prepareUSDC.ts");
|
||||
}
|
||||
|
||||
const wusdDeployment = JSON.parse(fs.readFileSync("./deployments-wusd.json", "utf8"));
|
||||
const wusdAddress = wusdDeployment.contracts.WUSD.proxy;
|
||||
const usdcConfig = JSON.parse(fs.readFileSync("./deployments-usdc-config.json", "utf8"));
|
||||
const usdcAddress = usdcConfig.contracts.USDC.address;
|
||||
const usdcPriceFeedAddress = usdcConfig.contracts.ChainlinkUSDCPriceFeed.address;
|
||||
|
||||
console.log("USDC地址: ", usdcAddress);
|
||||
console.log("Chainlink价格预言机: ", usdcPriceFeedAddress);
|
||||
|
||||
// 部署YTPriceFeed (可升级)
|
||||
console.log("部署YTPriceFeed...");
|
||||
// 部署YTPriceFeed (可升级) - 传入USDC和Chainlink地址
|
||||
console.log("\n部署YTPriceFeed...");
|
||||
const YTPriceFeed = await ethers.getContractFactory("YTPriceFeed");
|
||||
const priceFeed = await upgrades.deployProxy(YTPriceFeed, [wusdAddress], {
|
||||
kind: "uups",
|
||||
initializer: "initialize"
|
||||
});
|
||||
const priceFeed = await upgrades.deployProxy(
|
||||
YTPriceFeed,
|
||||
[usdcAddress, usdcPriceFeedAddress], // 传入两个参数
|
||||
{
|
||||
kind: "uups",
|
||||
initializer: "initialize"
|
||||
}
|
||||
);
|
||||
await priceFeed.waitForDeployment();
|
||||
const priceFeedAddress = await priceFeed.getAddress();
|
||||
console.log("✅ YTPriceFeed deployed to:", priceFeedAddress);
|
||||
|
||||
@@ -10,14 +10,14 @@ async function main() {
|
||||
console.log("部署账户:", deployer.address);
|
||||
console.log("账户余额:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "ETH\n");
|
||||
|
||||
// WUSD地址(需要提前部署或使用已知地址)
|
||||
// const WUSD_ADDRESS = "0x7Cd017ca5ddb86861FA983a34b5F495C6F898c41";
|
||||
if (!fs.existsSync("./deployments-wusd.json")) {
|
||||
throw new Error("未找到 deployments-wusd.json,请先运行 deployWUSD.ts");
|
||||
// 读取USDC配置
|
||||
if (!fs.existsSync("./deployments-usdc-config.json")) {
|
||||
throw new Error("未找到 deployments-usdc-config.json,请先运行 01-prepareUSDC.ts");
|
||||
}
|
||||
|
||||
const wusdDeployment = JSON.parse(fs.readFileSync("./deployments-wusd.json", "utf8"));
|
||||
const WUSD_ADDRESS = wusdDeployment.contracts.WUSD.proxy;
|
||||
const usdcConfig = JSON.parse(fs.readFileSync("./deployments-usdc-config.json", "utf8"));
|
||||
const USDC_ADDRESS = usdcConfig.contracts.USDC.address;
|
||||
const USDC_PRICE_FEED_ADDRESS = usdcConfig.contracts.ChainlinkUSDCPriceFeed.address;
|
||||
|
||||
// ===== 1. 部署YTAssetVault实现合约 =====
|
||||
console.log("===== 1. 部署YTAssetVault实现合约 =====");
|
||||
@@ -53,11 +53,12 @@ async function main() {
|
||||
|
||||
// ===== 3. 显示部署摘要 =====
|
||||
console.log("\n===== 部署摘要 =====");
|
||||
console.log("WUSD地址: ", WUSD_ADDRESS);
|
||||
console.log("YTAssetVault实现: ", vaultImplAddress);
|
||||
console.log("YTAssetFactory代理: ", vaultFactoryAddress);
|
||||
console.log("YTAssetFactory实现: ", vaultFactoryImplAddress);
|
||||
console.log("默认硬顶: ", ethers.formatEther(defaultHardCap), "tokens");
|
||||
console.log("USDC地址: ", USDC_ADDRESS);
|
||||
console.log("Chainlink价格预言机: ", USDC_PRICE_FEED_ADDRESS);
|
||||
console.log("YTAssetVault实现: ", vaultImplAddress);
|
||||
console.log("YTAssetFactory代理: ", vaultFactoryAddress);
|
||||
console.log("YTAssetFactory实现: ", vaultFactoryImplAddress);
|
||||
console.log("默认硬顶: ", ethers.formatEther(defaultHardCap), "tokens");
|
||||
|
||||
// 保存到JSON文件
|
||||
const deploymentInfo = {
|
||||
@@ -65,7 +66,8 @@ async function main() {
|
||||
chainId: (await ethers.provider.getNetwork()).chainId.toString(),
|
||||
deployer: deployer.address,
|
||||
timestamp: new Date().toISOString(),
|
||||
wusdAddress: WUSD_ADDRESS,
|
||||
usdcAddress: USDC_ADDRESS,
|
||||
usdcPriceFeedAddress: USDC_PRICE_FEED_ADDRESS,
|
||||
defaultHardCap: defaultHardCap.toString(),
|
||||
contracts: {
|
||||
YTAssetVault: {
|
||||
|
||||
@@ -19,10 +19,12 @@ async function main() {
|
||||
|
||||
const vaultDeployment = JSON.parse(fs.readFileSync("./deployments-vault-system.json", "utf8"));
|
||||
const factoryAddress = vaultDeployment.contracts.YTAssetFactory.proxy;
|
||||
const wusdAddress = vaultDeployment.wusdAddress;
|
||||
const usdcAddress = vaultDeployment.usdcAddress;
|
||||
const usdcPriceFeedAddress = vaultDeployment.usdcPriceFeedAddress;
|
||||
|
||||
console.log("YTAssetFactory:", factoryAddress);
|
||||
console.log("WUSD地址:", wusdAddress);
|
||||
console.log("YTAssetFactory: ", factoryAddress);
|
||||
console.log("USDC地址: ", usdcAddress);
|
||||
console.log("Chainlink价格预言机: ", usdcPriceFeedAddress);
|
||||
|
||||
const factory = await ethers.getContractAt("YTAssetFactory", factoryAddress);
|
||||
|
||||
@@ -37,7 +39,6 @@ async function main() {
|
||||
manager: deployer.address,
|
||||
hardCap: ethers.parseEther("10000000"), // 1000万
|
||||
redemptionTime: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60, // 1年后
|
||||
initialWusdPrice: PRICE_PRECISION, // $1.00 (精度1e30)
|
||||
initialYtPrice: PRICE_PRECISION // $1.00 (精度1e30)
|
||||
},
|
||||
{
|
||||
@@ -46,7 +47,6 @@ async function main() {
|
||||
manager: deployer.address,
|
||||
hardCap: ethers.parseEther("10000000"),
|
||||
redemptionTime: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60,
|
||||
initialWusdPrice: PRICE_PRECISION, // $1.00 (精度1e30)
|
||||
initialYtPrice: PRICE_PRECISION // $1.00 (精度1e30)
|
||||
},
|
||||
{
|
||||
@@ -55,7 +55,6 @@ async function main() {
|
||||
manager: deployer.address,
|
||||
hardCap: ethers.parseEther("10000000"),
|
||||
redemptionTime: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60,
|
||||
initialWusdPrice: PRICE_PRECISION, // $1.00 (精度1e30)
|
||||
initialYtPrice: PRICE_PRECISION // $1.00 (精度1e30)
|
||||
}
|
||||
];
|
||||
@@ -69,18 +68,19 @@ async function main() {
|
||||
console.log(`\n创建 ${params.name} (${params.symbol})...`);
|
||||
|
||||
// 价格已经是1e30精度,直接使用
|
||||
const wusdPrice = params.initialWusdPrice;
|
||||
const ytPrice = params.initialYtPrice;
|
||||
|
||||
// 新的createVault签名:
|
||||
// createVault(name, symbol, manager, hardCap, usdc, redemptionTime, ytPrice, usdcPriceFeed)
|
||||
const tx = await factory.createVault(
|
||||
params.name,
|
||||
params.symbol,
|
||||
params.manager,
|
||||
params.hardCap,
|
||||
wusdAddress,
|
||||
usdcAddress, // USDC地址
|
||||
params.redemptionTime,
|
||||
wusdPrice,
|
||||
ytPrice
|
||||
ytPrice, // 只需要ytPrice
|
||||
usdcPriceFeedAddress // Chainlink价格预言机地址
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
@@ -117,7 +117,6 @@ async function main() {
|
||||
manager: params.manager,
|
||||
hardCap: params.hardCap.toString(),
|
||||
redemptionTime: params.redemptionTime,
|
||||
wusdPrice: wusdPrice.toString(),
|
||||
ytPrice: ytPrice.toString()
|
||||
});
|
||||
}
|
||||
@@ -146,9 +145,9 @@ async function main() {
|
||||
|
||||
console.log("\n💡 下一步:");
|
||||
console.log("1. 在YTLp系统中将这些vault添加到白名单");
|
||||
console.log("2. 为YTPriceFeed设置价格来源(使用第一个vault)");
|
||||
console.log("3. 为每个vault设置初始价格");
|
||||
console.log("4. 开始使用!");
|
||||
console.log("2. 为每个vault设置初始价格");
|
||||
console.log("3. 开始使用!");
|
||||
console.log("\n注意: USDC价格自动从Chainlink获取,无需手动设置");
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -84,16 +84,9 @@ async function main() {
|
||||
// ==================== 3. 配置YTPriceFeed ====================
|
||||
console.log("\n===== 3. 配置YTPriceFeed =====");
|
||||
|
||||
// 设置WUSD价格来源(如果有YTAssetVault)
|
||||
if (firstVaultAddress) {
|
||||
console.log("设置WUSD价格来源...");
|
||||
await priceFeed.setWusdPriceSource(firstVaultAddress);
|
||||
console.log(" ✅ WUSD价格来源:", firstVaultAddress);
|
||||
} else {
|
||||
console.log(" ⚠️ 未找到YTAssetVault,跳过WUSD价格来源设置");
|
||||
console.log(" 💡 提示: 请在创建YTAssetVault后,手动调用 priceFeed.setWusdPriceSource()");
|
||||
}
|
||||
|
||||
// USDC价格从Chainlink获取,无需设置价格来源
|
||||
console.log("✅ USDC价格从Chainlink自动获取");
|
||||
|
||||
// 设置keeper权限(默认设置deployer为keeper)
|
||||
console.log("设置Keeper权限...");
|
||||
await priceFeed.setKeeper(deployer.address, true);
|
||||
@@ -132,9 +125,7 @@ async function main() {
|
||||
console.log("✅ YTVault swapper: YTRewardRouter");
|
||||
console.log("✅ YTPoolManager handler: YTRewardRouter");
|
||||
console.log("✅ YTPriceFeed keeper:", deployer.address);
|
||||
if (firstVaultAddress) {
|
||||
console.log("✅ YTPriceFeed wusdPriceSource:", firstVaultAddress);
|
||||
}
|
||||
console.log("✅ USDC价格: 从Chainlink自动获取");
|
||||
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
|
||||
console.log("\n📋 参数配置:");
|
||||
@@ -158,7 +149,7 @@ async function main() {
|
||||
vaultSwappers: [routerAddress],
|
||||
poolManagerHandlers: [routerAddress],
|
||||
priceFeedKeepers: [deployer.address],
|
||||
priceFeedWusdSource: firstVaultAddress || "未设置"
|
||||
usdcPriceSource: "Chainlink (自动)"
|
||||
},
|
||||
parameters: {
|
||||
dynamicFees: true,
|
||||
@@ -175,10 +166,10 @@ async function main() {
|
||||
console.log("\n✅ 配置信息已保存到 deployments-ytlp-config.json");
|
||||
|
||||
console.log("\n💡 下一步:");
|
||||
console.log("1. 通过YTAssetFactory创建YTAssetVault代币");
|
||||
console.log("2. 将YTAssetVault添加到YTVault的白名单");
|
||||
console.log("3. 为YTAssetVault设置价格");
|
||||
console.log("4. 开始使用协议!");
|
||||
console.log("1. 运行 04-createVault.ts 通过YTAssetFactory创建YTAssetVault代币");
|
||||
console.log("2. 运行 06-addVaultToWhitelist.ts 将YTAssetVault添加到白名单");
|
||||
console.log("3. 开始使用协议!");
|
||||
console.log("\n注意: USDC价格自动从Chainlink获取,无需手动设置");
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -34,6 +34,11 @@ async function main() {
|
||||
console.log(` ${i + 1}. ${v.name} (${v.symbol}): ${v.address}`);
|
||||
});
|
||||
|
||||
// 读取USDC配置
|
||||
const usdcConfig = JSON.parse(fs.readFileSync("./deployments-usdc-config.json", "utf8"));
|
||||
const usdcAddress = usdcConfig.contracts.USDC.address;
|
||||
console.log("\nUSDC地址:", usdcAddress);
|
||||
|
||||
// 获取合约实例
|
||||
const priceFeed = await ethers.getContractAt("YTPriceFeed", priceFeedAddress);
|
||||
const vault = await ethers.getContractAt("YTVault", vaultAddress);
|
||||
@@ -42,25 +47,26 @@ async function main() {
|
||||
console.log("\n===== 2. 添加到白名单 =====");
|
||||
|
||||
// 配置参数(可根据需要调整)
|
||||
// 注意:总权重 = 4000 + 3000 + 2000 = 9000
|
||||
// 注意:总权重 = 4000 + 3000 + 2000 + 1000 = 10000
|
||||
const whitelistParams = [
|
||||
{
|
||||
weight: 4000, // 4000/9000 = 44.44%
|
||||
weight: 4000, // 4000/10000 = 40%
|
||||
maxUsdyAmount: ethers.parseEther("45000000"), // 4500万
|
||||
isStable: false
|
||||
},
|
||||
{
|
||||
weight: 3000, // 3000/9000 = 33.33%
|
||||
weight: 3000, // 3000/10000 = 30%
|
||||
maxUsdyAmount: ethers.parseEther("35000000"), // 3500万
|
||||
isStable: false
|
||||
},
|
||||
{
|
||||
weight: 2000, // 2000/9000 = 22.22%
|
||||
weight: 2000, // 2000/10000 = 20%
|
||||
maxUsdyAmount: ethers.parseEther("25000000"), // 2500万
|
||||
isStable: false
|
||||
}
|
||||
];
|
||||
|
||||
// 添加YT代币到白名单
|
||||
for (let i = 0; i < vaults.length && i < whitelistParams.length; i++) {
|
||||
const v = vaults[i];
|
||||
const params = whitelistParams[i];
|
||||
@@ -81,8 +87,29 @@ async function main() {
|
||||
console.log(" ✅ 是否稳定币:", params.isStable);
|
||||
}
|
||||
|
||||
// ==================== 3. 设置价格 ====================
|
||||
console.log("\n===== 3. 设置价格 =====");
|
||||
// 添加USDC到白名单
|
||||
console.log("\n添加 USDC 到白名单...");
|
||||
const usdcParams = {
|
||||
weight: 1000, // 1000/10000 = 10%
|
||||
maxUsdyAmount: ethers.parseUnits("30000000", 6), // 3000万 USDC
|
||||
isStable: true // USDC是稳定币
|
||||
};
|
||||
|
||||
const usdcTx = await vault.setWhitelistedToken(
|
||||
usdcAddress,
|
||||
6, // Todo USDC在Arbitrum测试网是6位精度
|
||||
usdcParams.weight,
|
||||
usdcParams.maxUsdyAmount,
|
||||
usdcParams.isStable
|
||||
);
|
||||
await usdcTx.wait();
|
||||
|
||||
console.log(" ✅ 权重:", usdcParams.weight);
|
||||
console.log(" ✅ 最大USDY:", ethers.formatEther(usdcParams.maxUsdyAmount));
|
||||
console.log(" ✅ 是否稳定币:", usdcParams.isStable);
|
||||
|
||||
// ==================== 3. 设置YT价格 ====================
|
||||
console.log("\n===== 3. 设置YT价格 =====");
|
||||
|
||||
for (const v of vaults) {
|
||||
console.log(`\n设置 ${v.name} (${v.symbol}) 价格...`);
|
||||
@@ -96,23 +123,13 @@ async function main() {
|
||||
);
|
||||
await tx.wait();
|
||||
|
||||
console.log(" ✅ 价格已设置:", ethers.formatUnits(price, 30), "(精度1e30)");
|
||||
console.log(" ✅ YT价格已设置:", ethers.formatUnits(price, 30), "(精度1e30)");
|
||||
}
|
||||
|
||||
// ==================== 4. 设置WUSD价格来源 ====================
|
||||
console.log("\n===== 4. 设置WUSD价格来源 =====");
|
||||
console.log("\n✅ USDC价格从Chainlink自动获取,无需手动设置");
|
||||
|
||||
// 使用第一个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. 验证配置 =====");
|
||||
// ==================== 4. 验证配置 ====================
|
||||
console.log("\n===== 4. 验证配置 =====");
|
||||
|
||||
for (const v of vaults) {
|
||||
const isWhitelisted = await vault.whitelistedTokens(v.address);
|
||||
@@ -125,33 +142,60 @@ async function main() {
|
||||
console.log(" 价格:", ethers.formatUnits(price, 30));
|
||||
}
|
||||
|
||||
// 验证USDC
|
||||
const usdcWhitelisted = await vault.whitelistedTokens(usdcAddress);
|
||||
const usdcWeight = await vault.tokenWeights(usdcAddress);
|
||||
const usdcIsStable = await vault.stableTokens(usdcAddress);
|
||||
const usdcPrice = await priceFeed.getPrice(usdcAddress, true);
|
||||
|
||||
console.log("\nUSDC:");
|
||||
console.log(" 白名单:", usdcWhitelisted ? "✅" : "❌");
|
||||
console.log(" 权重:", usdcWeight.toString());
|
||||
console.log(" 价格:", ethers.formatUnits(usdcPrice, 30), "(从Chainlink获取)");
|
||||
console.log(" 稳定币:", usdcIsStable ? "✅" : "❌");
|
||||
|
||||
const totalWeight = await vault.totalTokenWeights();
|
||||
console.log("\n总权重:", totalWeight.toString());
|
||||
|
||||
const wusdPriceSource = await priceFeed.wusdPriceSource();
|
||||
console.log("WUSD价格来源:", wusdPriceSource);
|
||||
|
||||
// ==================== 6. 输出摘要 ====================
|
||||
// ==================== 5. 输出摘要 ====================
|
||||
console.log("\n===== 配置完成!=====");
|
||||
console.log("\n✅ 已添加", vaults.length, "个vault到白名单");
|
||||
console.log("✅ 已为所有vault设置初始价格");
|
||||
console.log("✅ 已设置WUSD价格来源");
|
||||
console.log("\n✅ 已添加", vaults.length, "个YT代币到白名单");
|
||||
console.log("✅ 已添加 USDC 到白名单(稳定币)");
|
||||
console.log("✅ 已为所有YT代币设置初始价格");
|
||||
console.log("✅ USDC价格从Chainlink自动更新");
|
||||
console.log("\n📋 池子组成: USDC/YT-A/YT-B/YT-C");
|
||||
console.log(" • USDC: 10% (稳定币, 手续费0.04%)");
|
||||
console.log(" • YT-A: 40% (YT代币, 手续费0.3%)");
|
||||
console.log(" • YT-B: 30% (YT代币, 手续费0.3%)");
|
||||
console.log(" • YT-C: 20% (YT代币, 手续费0.3%)");
|
||||
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
|
||||
})),
|
||||
whitelistedTokens: {
|
||||
ytTokens: 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,
|
||||
isStable: false
|
||||
})),
|
||||
usdc: {
|
||||
name: "USDC",
|
||||
symbol: "USDC",
|
||||
address: usdcAddress,
|
||||
weight: usdcParams.weight,
|
||||
maxUsdyAmount: usdcParams.maxUsdyAmount.toString(),
|
||||
priceSource: "Chainlink (自动)",
|
||||
isStable: true
|
||||
}
|
||||
},
|
||||
totalWeight: totalWeight.toString(),
|
||||
wusdPriceSource: wusdPriceSource
|
||||
poolComposition: "USDC/YT-A/YT-B/YT-C"
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
|
||||
Reference in New Issue
Block a user