-
Notifications
You must be signed in to change notification settings - Fork 45
feat(docs): add support for hardhat FTSO guide and fix FTSO interfaces #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dineshpinto
merged 21 commits into
flare-foundation:main
from
0xreflexivity:hardhat-ftso
Apr 24, 2025
Merged
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3cac60b
feat(docs): add support for hardhat FTSO guide and fix FTSO interfaces
0xreflexivity fe0e02e
fix: lint issues
swarna1101 3ff7cfc
add: codeQL check
swarna1101 344634b
fix: v2->v3
swarna1101 435dcc3
fix: codeql script
swarna1101 f092a01
fix: remove the codeQL POC
swarna1101 896a9df
fix(docs): change desc. and hardhat link
0xreflexivity 4ab621e
Merge branch 'hardhat-ftso' of https://github.com/AmadiaFlare/develop…
0xreflexivity cf3659f
Merge branch 'main' into fork/AmadiaFlare/hardhat-ftso
swarna1101 25a0e91
fix: minor change
swarna1101 a1c0eac
Merge branch 'flare-foundation:main' into hardhat-ftso
0xreflexivity d77c7d9
fix(docs): ftso hardhat contract, deploy script, and tests
0xreflexivity 1367cd8
fix(docs): lint inside js directory
0xreflexivity 250cb7e
fix: minor formatting
swarna1101 6365d97
fix(docs): change contract License to MIT
0xreflexivity 139b69b
Merge branch 'hardhat-ftso' of https://github.com/AmadiaFlare/develop…
0xreflexivity 2e31758
fix(docs): clean up
0xreflexivity bc8b44c
fix(docs): clean up
0xreflexivity 8496019
Merge branch 'flare-foundation:main' into hardhat-ftso
0xreflexivity 3481166
feat(doc): match new FTSO script in hardhat-starter
0xreflexivity a78f522
fix(docs): name change
0xreflexivity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
examples/developer-hub-javascript/FTSOV2Consumer_hardhat.ts
0xreflexivity marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { expect } from "chai"; | ||
| import { ethers } from "hardhat"; | ||
| import { FtsoV2Consumer } from "../typechain-types"; // Adjust the path based on your typechain output directory | ||
|
|
||
| describe("FtsoV2Consumer", function () { | ||
| let ftsoV2Consumer: FtsoV2Consumer; | ||
|
|
||
| // Deploy a new instance of the contract before each test | ||
| beforeEach(async function () { | ||
| const FtsoV2ConsumerFactory = | ||
| await ethers.getContractFactory("FtsoV2Consumer"); | ||
| ftsoV2Consumer = await FtsoV2ConsumerFactory.deploy(); | ||
| await ftsoV2Consumer.waitForDeployment(); | ||
| // console.log("FtsoV2Consumer deployed to:", await ftsoV2Consumer.getAddress()); // Optional: log address | ||
| }); | ||
|
|
||
| it("Should return the FLR/USD price, decimals, and timestamp", async function () { | ||
| const [price, decimals, timestamp] = await ftsoV2Consumer.getFlrUsdPrice(); | ||
|
|
||
| // We can't know the exact price, but we can check the types and basic validity | ||
| expect(price).to.be.a("bigint"); | ||
| expect(price).to.be.gt(0); // Price should be greater than 0 | ||
|
|
||
| expect(decimals).to.be.a("number"); | ||
| // Typical FTSO decimals are often 5 for USD pairs, but let's be flexible | ||
| expect(decimals).to.be.within(-128, 127); // Check it's a valid int8 | ||
|
|
||
| expect(timestamp).to.be.a("bigint"); | ||
| expect(timestamp).to.be.gt(0); // Timestamp should be positive | ||
| // Check if the timestamp is reasonably recent (e.g., within the last hour) | ||
| const currentTimestamp = Math.floor(Date.now() / 1000); | ||
| expect(Number(timestamp)).to.be.closeTo(currentTimestamp, 3600); // within 1 hour | ||
| }); | ||
|
|
||
| it("Should return the FLR/USD price in Wei and timestamp", async function () { | ||
| const [priceWei, timestamp] = await ftsoV2Consumer.getFlrUsdPriceWei(); | ||
|
|
||
| expect(priceWei).to.be.a("bigint"); | ||
| expect(priceWei).to.be.gt(0); // Price in Wei should be greater than 0 | ||
|
|
||
| expect(timestamp).to.be.a("bigint"); | ||
| expect(timestamp).to.be.gt(0); // Timestamp should be positive | ||
| const currentTimestamp = Math.floor(Date.now() / 1000); | ||
| expect(Number(timestamp)).to.be.closeTo(currentTimestamp, 3600); // within 1 hour | ||
| }); | ||
|
|
||
| it("Should return current feed values for multiple feeds", async function () { | ||
| const [feedValues, decimals, timestamp] = | ||
| await ftsoV2Consumer.getFtsoV2CurrentFeedValues(); | ||
|
|
||
| // Get the expected number of feeds from the contract's public variable | ||
| const expectedFeedCount = (await ftsoV2Consumer.feedIds()).length; | ||
|
|
||
| expect(feedValues).to.be.an("array"); | ||
| expect(feedValues).to.have.lengthOf(expectedFeedCount); | ||
| feedValues.forEach((value) => { | ||
| expect(value).to.be.a("bigint"); | ||
| expect(value).to.be.gt(0); | ||
| }); | ||
|
|
||
| expect(decimals).to.be.an("array"); | ||
| expect(decimals).to.have.lengthOf(expectedFeedCount); | ||
| decimals.forEach((dec) => { | ||
| expect(dec).to.be.a("number"); | ||
| expect(dec).to.be.within(-128, 127); // Check it's a valid int8 | ||
| }); | ||
|
|
||
| expect(timestamp).to.be.a("bigint"); | ||
| expect(timestamp).to.be.gt(0); // Timestamp should be positive | ||
| const currentTimestamp = Math.floor(Date.now() / 1000); | ||
| expect(Number(timestamp)).to.be.closeTo(currentTimestamp, 3600); // within 1 hour | ||
| }); | ||
|
|
||
| it("Should have the correct constant flrUsdId", async function () { | ||
| const expectedId = "0x01464c522f55534400000000000000000000000000"; // "FLR/USD" | ||
| const actualId = await ftsoV2Consumer.flrUsdId(); | ||
| expect(actualId).to.equal(expectedId); | ||
| }); | ||
|
|
||
| it("Should have the correct initial feedIds array", async function () { | ||
| const expectedIds = [ | ||
| "0x01464c522f55534400000000000000000000000000", // FLR/USD | ||
| "0x014254432f55534400000000000000000000000000", // BTC/USD | ||
| "0x014554482f55534400000000000000000000000000", // ETH/USD | ||
| ]; | ||
| const actualIds = await ftsoV2Consumer.feedIds(); | ||
| expect(actualIds).to.deep.equal(expectedIds); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.