Skip to content

Commit 3481166

Browse files
committed
feat(doc): match new FTSO script in hardhat-starter
1 parent 8496019 commit 3481166

File tree

5 files changed

+134
-95
lines changed

5 files changed

+134
-95
lines changed

examples/developer-hub-javascript/deployFTSO.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
});

examples/developer-hub-solidity/FTSOV2Consumer_hardhat.sol

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity >=0.8.0 <0.9.0;
33

4-
import { TestFtsoV2Interface } from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5-
import { ContractRegistry } from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6-
import { IFeeCalculator } from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
4+
import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5+
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6+
import {IFeeCalculator} from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
77

88
contract FtsoV2Consumer {
9-
bytes21 public constant flrUsdId = 0x01464c522f55534400000000000000000000000000; // "FLR/USD"
9+
bytes21 public constant flrUsdId =
10+
0x01464c522f55534400000000000000000000000000; // "FLR/USD"
1011

1112
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1213
bytes21[] public feedIds = [
@@ -30,11 +31,15 @@ contract FtsoV2Consumer {
3031
function getFtsoV2CurrentFeedValues()
3132
external
3233
view
33-
returns (uint256[] memory _feedValues, int8[] memory _decimals, uint64 _timestamp)
34+
returns (
35+
uint256[] memory _feedValues,
36+
int8[] memory _decimals,
37+
uint64 _timestamp
38+
)
3439
{
3540
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
3641
TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();
3742
/* Your custom feed consumption logic. In this example the values are just returned. */
3843
return ftsoV2.getFeedsById(feedIds);
3944
}
40-
}
45+
}

examples/developer-hub-solidity/FtsoV2Consumer.sol

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity >=0.8.0 <0.9.0;
33

4-
import { TestFtsoV2Interface } from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5-
import { ContractRegistry } from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6-
import { IFeeCalculator } from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
4+
import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5+
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6+
import {IFeeCalculator} from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
77

88
contract FtsoV2Consumer {
9-
bytes21 public constant flrUsdId = 0x01464c522f55534400000000000000000000000000; // "FLR/USD"
9+
bytes21 public constant flrUsdId =
10+
0x01464c522f55534400000000000000000000000000; // "FLR/USD"
1011

1112
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1213
bytes21[] public feedIds = [
@@ -30,7 +31,11 @@ contract FtsoV2Consumer {
3031
function getFtsoV2CurrentFeedValues()
3132
external
3233
view
33-
returns (uint256[] memory _feedValues, int8[] memory _decimals, uint64 _timestamp)
34+
returns (
35+
uint256[] memory _feedValues,
36+
int8[] memory _decimals,
37+
uint64 _timestamp
38+
)
3439
{
3540
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
3641
TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();

examples/developer-hub-solidity/FtsoV2FeedConsumer_foundry.sol

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity >=0.8.0 <0.9.0;
33

4-
import { TestFtsoV2Interface } from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5-
import { ContractRegistry } from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6-
import { IFeeCalculator } from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
4+
import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
5+
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
6+
import {IFeeCalculator} from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";
77

88
contract FtsoV2Consumer {
9-
bytes21 public constant flrUsdId = 0x01464c522f55534400000000000000000000000000; // "FLR/USD"
9+
bytes21 public constant flrUsdId =
10+
0x01464c522f55534400000000000000000000000000; // "FLR/USD"
1011

1112
// Feed IDs, see https://dev.flare.network/ftso/feeds for full list
1213
bytes21[] public feedIds = [
@@ -30,11 +31,15 @@ contract FtsoV2Consumer {
3031
function getFtsoV2CurrentFeedValues()
3132
external
3233
view
33-
returns (uint256[] memory _feedValues, int8[] memory _decimals, uint64 _timestamp)
34+
returns (
35+
uint256[] memory _feedValues,
36+
int8[] memory _decimals,
37+
uint64 _timestamp
38+
)
3439
{
3540
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
3641
TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();
3742
/* Your custom feed consumption logic. In this example the values are just returned. */
3843
return ftsoV2.getFeedsById(feedIds);
3944
}
40-
}
45+
}

0 commit comments

Comments
 (0)