|
| 1 | +import { ethers, run } from "hardhat"; |
| 2 | +import { FtsoV2ConsumerContract } from "../typechain-types"; |
| 3 | + |
| 4 | +const FtsoV2Consumer = artifacts.require("FtsoV2Consumer"); |
| 5 | + |
| 6 | +async function verifyContract(address: string) { |
| 7 | + console.log("\nVerifying contract..."); |
| 8 | + try { |
| 9 | + await run("verify:verify", { address }); |
| 10 | + console.log("Contract verified successfully"); |
| 11 | + } catch (error) { |
| 12 | + console.error("Error verifying contract:", error); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +async function callGetFlrUsdPrice(ftsoV2Consumer: FtsoV2ConsumerContract) { |
| 17 | + console.log("\nCalling getFlrUsdPrice..."); |
| 18 | + try { |
| 19 | + const result = await ftsoV2Consumer.getFlrUsdPrice(); |
| 20 | + console.log("FLR/USD Price Data:"); |
| 21 | + console.log(" Price:", result[0].toString()); |
| 22 | + console.log(" Decimals:", result[1].toString()); |
| 23 | + console.log( |
| 24 | + " Timestamp:", |
| 25 | + new Date(result[2].toNumber() * 1000).toISOString(), |
| 26 | + ); |
| 27 | + } catch (error) { |
| 28 | + console.error("Error calling getFlrUsdPrice:", error); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +async function callGetFlrUsdPriceWei(ftsoV2Consumer: FtsoV2ConsumerContract) { |
| 33 | + console.log("\nCalling getFlrUsdPriceWei..."); |
| 34 | + try { |
| 35 | + const resultWei = await ftsoV2Consumer.getFlrUsdPriceWei(); |
| 36 | + console.log("FLR/USD Price Data (Wei):"); |
| 37 | + console.log(" Price (Wei):", resultWei[0].toString()); |
| 38 | + console.log( |
| 39 | + " Timestamp:", |
| 40 | + new Date(resultWei[1].toNumber() * 1000).toISOString(), |
| 41 | + ); |
| 42 | + } catch (error) { |
| 43 | + console.error("Error calling getFlrUsdPriceWei:", error); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +async function callFtsoV2CurrentFeedValues( |
| 48 | + ftsoV2Consumer: FtsoV2ConsumerContract, |
| 49 | +) { |
| 50 | + console.log("\nCalling getFtsoV2CurrentFeedValues..."); |
| 51 | + try { |
| 52 | + const feedValuesResult = await ftsoV2Consumer.getFtsoV2CurrentFeedValues(); |
| 53 | + console.log("Current Feed Values (FLR/USD, BTC/USD, ETH/USD):"); |
| 54 | + const feedIds = ["FLR/USD", "BTC/USD", "ETH/USD"]; // Match order in contract |
| 55 | + for (let i = 0; i < feedValuesResult[0].length; i++) { |
| 56 | + console.log(` Feed ${feedIds[i]}:`); |
| 57 | + console.log(` Price: ${feedValuesResult[0][i].toString()}`); |
| 58 | + console.log(` Decimals: ${feedValuesResult[1][i].toString()}`); |
| 59 | + } |
| 60 | + console.log( |
| 61 | + ` Timestamp: ${new Date(feedValuesResult[2].toNumber() * 1000).toISOString()}`, |
| 62 | + ); |
| 63 | + } catch (error) { |
| 64 | + console.error("Error calling getFtsoV2CurrentFeedValues:", error); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +async function callContractFunctions(ftsoV2Consumer: FtsoV2ConsumerContract) { |
| 69 | + await callGetFlrUsdPrice(ftsoV2Consumer); |
| 70 | + await callGetFlrUsdPriceWei(ftsoV2Consumer); |
| 71 | + await callFtsoV2CurrentFeedValues(ftsoV2Consumer); |
| 72 | +} |
| 73 | + |
| 74 | +// --- Main Deployment Script --- |
| 75 | + |
| 76 | +async function main() { |
| 77 | + const [deployer] = await ethers.getSigners(); |
| 78 | + |
| 79 | + console.log("Deploying contracts with the account:", deployer.address); |
| 80 | + |
| 81 | + // Deploy FtsoV2Consumer |
| 82 | + const ftsoV2Consumer: FtsoV2ConsumerContract = await FtsoV2Consumer.new( |
| 83 | + "0x01464c522f55534400000000000000000000000000", // Deploying contract with FLR Feed (see more feeds here: https://dev.flare.network/ftso/feeds) |
| 84 | + ); |
| 85 | + await ftsoV2Consumer.deployed(); |
| 86 | + console.log("FtsoV2Consumer deployed to:", ftsoV2Consumer.address); |
| 87 | + |
| 88 | + // Verify the contract |
| 89 | + await verifyContract(ftsoV2Consumer.address); |
| 90 | + |
| 91 | + // Call the contract functions |
| 92 | + await callContractFunctions(ftsoV2Consumer); |
| 93 | + |
| 94 | + console.log("\nDeployment and calling script finished."); |
| 95 | +} |
| 96 | + |
| 97 | +main() |
| 98 | + .then(() => process.exit(0)) |
| 99 | + .catch((error) => { |
| 100 | + console.error("Unhandled error in main execution:", error); |
| 101 | + process.exit(1); |
| 102 | + }); |
0 commit comments