-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat(docs): add support for hardhat FTSO guide and fix FTSO interfaces #608
Open
AmadiaFlare
wants to merge
8
commits into
flare-foundation:main
Choose a base branch
from
AmadiaFlare:hardhat-ftso
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3cac60b
feat(docs): add support for hardhat FTSO guide and fix FTSO interfaces
AmadiaFlare 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
AmadiaFlare 4ab621e
Merge branch 'hardhat-ftso' of https://github.com/AmadiaFlare/develop…
AmadiaFlare 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 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
53 changes: 53 additions & 0 deletions
53
examples/developer-hub-javascript/FTSOV2FeedConsumer_hardhat.js
This file contains 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,53 @@ | ||
import { artifacts, ethers } from "hardhat"; | ||
import { expect } from "chai"; | ||
import { deployFlareContractRegistry } from "../lib/utils"; | ||
|
||
const FtsoV2FeedConsumer = artifacts.require("FtsoV2FeedConsumer"); | ||
|
||
describe("FtsoV2FeedConsumer", () => { | ||
let ftsoConsumer; | ||
const mockFtsoV2Address = "0x1234567890123456789012345678901234567890"; | ||
const mockFeeCalcAddress = "0x2345678901234567890123456789012345678901"; | ||
const mockFlrUsdId = "0x0123456789012345678901234567890123456789012345"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic numbers? |
||
|
||
beforeEach(async () => { | ||
// Deploy mock Flare Contract Registry | ||
await deployFlareContractRegistry(); | ||
|
||
// Deploy the FtsoV2FeedConsumer contract | ||
ftsoConsumer = await FtsoV2FeedConsumer.new( | ||
mockFtsoV2Address, | ||
mockFeeCalcAddress, | ||
mockFlrUsdId, | ||
); | ||
}); | ||
|
||
describe("Constructor", () => { | ||
it("should set the initial values correctly", async () => { | ||
const storedFlrUsdId = await ftsoConsumer.flrUsdId(); | ||
expect(storedFlrUsdId).to.equal(mockFlrUsdId); | ||
|
||
const feedIds = await ftsoConsumer.feedIds(0); | ||
expect(feedIds).to.equal(mockFlrUsdId); | ||
}); | ||
}); | ||
|
||
describe("checkFees", () => { | ||
it("should update and return the fee", async () => { | ||
// Since we're using mocks, we'll just verify the function can be called | ||
const fee = await ftsoConsumer.fee(); | ||
|
||
expect(fee).to.be.a("number"); | ||
}); | ||
}); | ||
|
||
describe("getFlrUsdPrice", () => { | ||
it("should revert if fee does not match msg.value", async () => { | ||
const fee = ethers.parseEther("1.0"); | ||
await ftsoConsumer.checkFees(); | ||
|
||
await expect(ftsoConsumer.getFlrUsdPrice({ value: fee + 1n })).to.be | ||
.reverted; | ||
}); | ||
}); | ||
}); |
This file contains 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,42 @@ | ||
import { artifacts, ethers } from "hardhat"; | ||
import { FtsoV2FeedConsumerInstance } from "../typechain-types"; | ||
|
||
const FtsoV2FeedConsumer = artifacts.require("FtsoV2FeedConsumer"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which contract does this one refer to? |
||
|
||
async function main() { | ||
const [deployer] = await ethers.getSigners(); | ||
|
||
console.log("Deploying contracts with the account:", deployer.address); | ||
|
||
// Deploy FtsoV2FeedConsumer | ||
const ftsoConsumer: FtsoV2FeedConsumerInstance = await FtsoV2FeedConsumer.new( | ||
"0x01464c522f55534400000000000000000000000000", | ||
); | ||
console.log("FtsoV2FeedConsumer deployed to:", ftsoConsumer.address); | ||
|
||
// Test the contract functions | ||
try { | ||
// Test getFLRUSDPrice | ||
const result = await ftsoConsumer.getFlrUsdPrice(); | ||
console.log("\nFLR/USD Price Data:"); | ||
console.log("Price:", result[0].toString()); | ||
console.log("Decimals:", result[1].toString()); | ||
console.log( | ||
"Timestamp:", | ||
new Date(result[2].toNumber() * 1000).toISOString(), | ||
); | ||
|
||
// Test checkFees | ||
const fees = await ftsoConsumer.checkFees(); | ||
console.log("\nFees:", fees.toString()); | ||
} catch (error) { | ||
console.error("Error testing contract:", error); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this live?