Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions tasks/estimateFees.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
module.exports = async function (taskArgs, hre, runSuper) {
let Endpoint = await ethers.getContractFactory("Endpoint")
let endpoint = await Endpoint.attach(taskArgs.endpoint)
let estimatedFees = await endpoint.estimateFees(
taskArgs.dstChainId,
taskArgs.ua,
taskArgs.payload,
false, // payInZro
taskArgs.relayerParams
)
console.log(`estimatedFees: ${estimatedFees}`)
}
try {
// Проверка, что все необходимые аргументы переданы
if (!taskArgs.endpoint || !ethers.utils.isAddress(taskArgs.endpoint)) {
throw new Error("Неверный или отсутствующий адрес endpoint.");
}

if (!taskArgs.ua || !ethers.utils.isAddress(taskArgs.ua)) {
throw new Error("Неверный или отсутствующий адрес user application.");
}

// Получаем контракт Endpoint
let Endpoint = await ethers.getContractFactory("Endpoint");
let endpoint = await Endpoint.attach(taskArgs.endpoint);

// Оценка комиссии
let estimatedFees = await endpoint.estimateFees(
taskArgs.dstChainId,
taskArgs.ua,
taskArgs.payload,
false, // payInZro
taskArgs.relayerParams
);

// Форматируем и выводим оценочные комиссии в удобном виде (например, в ETH)
let formattedFees = ethers.utils.formatEther(estimatedFees[0]); // Преобразуем wei в ETH
console.log(`Оценочные комиссии для цепочки ${taskArgs.dstChainId}: ${formattedFees} ETH`);

} catch (error) {
// Обрабатываем ошибки и выводим их в консоль
console.error("Произошла ошибка при оценке комиссий:", error.message);
}
};