简体中文
如何在绑定阶段进行买卖、费用和阈值。
// 先获取报价 const quote = await token.getAmountOfTokensToBuy( parseEther("1") // 1 ETH ); console.log(`将收到:${formatEther(quote)} 代币`); // 执行购买并保护滑点 const minTokens = quote * 0.95n; // 5% 滑点 await token.buy(minTokens, "1");
// 检查余额并获取报价 const balance = await token.balanceOf(userAddress); const sellAmount = balance / 2n; // 卖出一半 const quote = await token.getAmountOfEthToReceive( sellAmount ); console.log(`将收到:${formatEther(quote)} ETH`); // 执行销售并保护滑点 const minEth = quote * 0.95n; // 5% 滑点 await token.sell(sellAmount, minEth);
购买费用
// 用户发送 1 ETH // 费用:0.05 ETH // 曲线接收:0.95 ETH // 基于 0.95 ETH 铸造代币
出售费用
// 曲线上代币价值 1 ETH // 费用:0.05 ETH // 用户收到:0.95 ETH // 曲线下降 1 ETH
费用分配
feeRecipient
// 监控目标进度 async function trackProgress(token: BondkitToken) { const progress = await token.getBondingProgress(); if (progress.progress < 0.5) { console.log("🌱 早期阶段 - 最佳价格可用"); } else if (progress.progress < 0.8) { console.log("🚀 动力构建中 - 考虑购买"); } else if (progress.progress < 1.0) { console.log("🔥 几乎完成 - 迁移即将到来"); } else { console.log("✅ 达到目标 - 准备迁移!"); } const remaining = progress.threshold - progress.raised; console.log(`还需要 ${formatEther(remaining)} ETH`); }
目标:100 ETH 当前:99.5 ETH 用户发送:2 ETH 结果: - 接受 0.5 ETH(准确达到 100 ETH) - 退还 1.5 ETH - 用户获得 0.5 ETH 的代币 - 现在可进行迁移
event BondingCurveBuy( address indexed payer, address indexed recipient, uint256 tradingTokenIn, uint256 tokensOut, uint256 fee, uint256 totalRaisedBonding );
token.onBuy((event) => { console.log({ 买家: event.payer, 花费的 ETH: formatEther(event.tradingTokenIn), 收到的代币: formatEther(event.tokensOut), 支付的费用: formatEther(event.fee), 总筹集: formatEther(event.totalRaisedBonding) }); });
// 完整的监控设置 class BondingMonitor { constructor(private token: BondkitToken) {} async start() { // 初始状态 const progress = await this.token.getBondingProgress(); console.log(`开始于 ${(progress.progress * 100).toFixed(2)}%`); // 监控购买 this.token.onBuy(async (event) => { const newProgress = await this.token.getBondingProgress(); console.log(`购买:${formatEther(event.tokensOut)} 代币`); console.log(`进度:${(newProgress.progress * 100).toFixed(2)}%`); if (newProgress.progress >= 1.0) { console.log("🎆 达到目标!可进行迁移。"); } }); // 监控出售 this.token.onSell(async (event) => { const newProgress = await this.token.getBondingProgress(); console.log(`出售:${formatEther(event.tokensIn)} 代币`); console.log(`进度:${(newProgress.progress * 100).toFixed(2)}%`); }); } } // 使用 const monitor = new BondingMonitor(token); await monitor.start();
migrateToDex()