ytLending supports USDC as the base token

This commit is contained in:
2025-12-26 13:23:50 +08:00
parent e21ee7a5df
commit 9a92c81aec
37 changed files with 4298 additions and 3064 deletions

View File

@@ -4,7 +4,7 @@ import * as path from "path";
/**
* 部署 Lending 借贷池系统
* 包含LendingFactory, Configurator, Lending 实现和代理
* 包含LendingFactory, Configurator, LendingPriceFeed, Lending 实现和代理
*/
async function main() {
const [deployer] = await ethers.getSigners();
@@ -16,6 +16,30 @@ async function main() {
const deployments: any = {};
// ========== 读取配置参数 ==========
console.log("📋 读取配置参数...");
const network = await ethers.provider.getNetwork();
const chainId = network.chainId.toString();
let USDC_ADDRESS: string;
let USDC_PRICE_FEED: string;
if (chainId === "421614") {
// Arbitrum 测试网
USDC_ADDRESS = "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d";
USDC_PRICE_FEED = "0x0153002d20B96532C639313c2d54c3dA09109309"; // USDC/USD
} else if (chainId === "56") {
// BSC 主网
USDC_ADDRESS = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
USDC_PRICE_FEED = "0x51597f405303C4377E36123cBc172b13269EA163"; // USDC/USD
} else {
throw new Error(`不支持的网络: ${chainId}`);
}
console.log(" USDC 地址:", USDC_ADDRESS);
console.log(" USDC Price Feed:", USDC_PRICE_FEED, "\n");
// ========== 第一阶段:部署工厂合约 ==========
console.log("📦 Phase 1: 部署 LendingFactory...");
const LendingFactory = await ethers.getContractFactory("LendingFactory");
@@ -25,8 +49,38 @@ async function main() {
console.log("✅ LendingFactory 已部署:", lendingFactoryAddress);
deployments.lendingFactory = lendingFactoryAddress;
// ========== 第二阶段:部署 Configurator ==========
console.log("\n📦 Phase 2: 部署 Configurator (UUPS 代理)...");
// ========== 第二阶段:部署 LendingPriceFeed (UUPS 代理) ==========
console.log("\n📦 Phase 2: 部署 LendingPriceFeed (UUPS 代理)...");
const LendingPriceFeed = await ethers.getContractFactory("LendingPriceFeed");
// 使用 upgrades 插件部署 UUPS 代理
const lendingPriceFeed = await upgrades.deployProxy(
LendingPriceFeed,
[USDC_ADDRESS, USDC_PRICE_FEED],
{
kind: "uups",
initializer: "initialize"
}
);
await lendingPriceFeed.waitForDeployment();
const lendingPriceFeedProxyAddress = await lendingPriceFeed.getAddress();
console.log("✅ LendingPriceFeed Proxy:", lendingPriceFeedProxyAddress);
deployments.lendingPriceFeedProxy = lendingPriceFeedProxyAddress;
deployments.lendingPriceFeed = lendingPriceFeedProxyAddress; // 兼容旧字段
// 获取实现合约地址
const lendingPriceFeedImplAddress = await upgrades.erc1967.getImplementationAddress(lendingPriceFeedProxyAddress);
console.log("✅ LendingPriceFeed Implementation:", lendingPriceFeedImplAddress);
deployments.lendingPriceFeedImpl = lendingPriceFeedImplAddress;
// 验证价格获取
const usdcPrice = await lendingPriceFeed.getPrice(USDC_ADDRESS);
console.log("✅ USDC 价格 (1e30 精度):", usdcPrice.toString());
console.log("✅ LendingPriceFeed Owner:", await lendingPriceFeed.owner());
// ========== 第三阶段:部署 Configurator ==========
console.log("\n📦 Phase 3: 部署 Configurator (UUPS 代理)...");
const Configurator = await ethers.getContractFactory("Configurator");
// 使用 upgrades 插件部署 UUPS 代理
@@ -51,8 +105,8 @@ async function main() {
console.log("✅ Configurator Owner:", await configurator.owner());
// ========== 第阶段:部署 Lending 实现合约 ==========
console.log("\n📦 Phase 3: 通过工厂部署 Lending 实现合约...");
// ========== 第阶段:部署 Lending 实现合约 ==========
console.log("\n📦 Phase 4: 通过工厂部署 Lending 实现合约...");
const deployTx = await lendingFactory.deploy();
const deployReceipt = await deployTx.wait();
@@ -77,8 +131,8 @@ async function main() {
console.log("✅ Lending Implementation:", lendingImplAddress);
deployments.lendingImpl = lendingImplAddress;
// ========== 第阶段:准备部署 Lending 代理 ==========
console.log("\n📦 Phase 4: 准备部署 Lending 代理(需要先配置参数)");
// ========== 第阶段:准备部署 Lending 代理 ==========
console.log("\n📦 Phase 5: 准备部署 Lending 代理(需要先配置参数)");
console.log("⚠️ 请运行配置脚本 08-configureLending.ts 来完成配置和代理部署");
// ========== 保存部署信息 ==========
@@ -87,11 +141,11 @@ async function main() {
? JSON.parse(fs.readFileSync(deploymentsPath, "utf-8"))
: {};
const network = await ethers.provider.getNetwork();
const chainId = network.chainId.toString();
existingDeployments[chainId] = {
...existingDeployments[chainId],
...deployments,
usdcAddress: USDC_ADDRESS,
usdcPriceFeed: USDC_PRICE_FEED,
deployTimestamp: new Date().toISOString(),
deployer: deployer.address
};
@@ -102,11 +156,23 @@ async function main() {
// ========== 部署总结 ==========
console.log("\n🎉 部署总结:");
console.log("=====================================");
console.log("LendingFactory: ", deployments.lendingFactory);
console.log("Configurator (Proxy): ", deployments.configuratorProxy);
console.log("Configurator (Impl): ", deployments.configuratorImpl);
console.log("Lending (Impl): ", deployments.lendingImpl);
console.log("=====================================\n");
console.log("📍 外部依赖:");
console.log(" USDC Address: ", USDC_ADDRESS);
console.log(" USDC Price Feed: ", USDC_PRICE_FEED);
console.log("\n📦 已部署合约:");
console.log(" LendingFactory: ", deployments.lendingFactory);
console.log("\n📊 LendingPriceFeed (UUPS):");
console.log(" Proxy: ", deployments.lendingPriceFeedProxy);
console.log(" Implementation: ", deployments.lendingPriceFeedImpl);
console.log("\n⚙ Configurator (UUPS):");
console.log(" Proxy: ", deployments.configuratorProxy);
console.log(" Implementation: ", deployments.configuratorImpl);
console.log("\n🏦 Lending:");
console.log(" Implementation: ", deployments.lendingImpl);
console.log(" Proxy: ", "待配置");
console.log("=====================================");
console.log("\n💡 下一步:");
console.log(" 运行 08-configureLending.ts 来创建 Lending 市场\n");
}
main()