-
Notifications
You must be signed in to change notification settings - Fork 255
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
Connecting to offchain data - Updated Oracles lesson #495
Connecting to offchain data - Updated Oracles lesson #495
Conversation
… into fix-connecting-to-offchain-data-oracles
… into fix-connecting-to-offchain-data-oracles
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.
Just small changes and formatting, plus I need some help understanding the tests. See. above.
Solana has a rich ecosystem of oracle providers. Some notable ones include | ||
[Pyth Network](https://pyth.network), [Switchboard](https://switchboard.xyz), | ||
[Chainlink](https://chain.link), and | ||
[DIA](https://www.diadata.org/solana-price-oracles/). Two of the most well-known | ||
are [Pyth](https://pyth.network) and [Switchboard](https://switchboard.xyz), | ||
each with unique design choices. |
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.
There's some duplication here from the old text. I suggest:
Solana has a rich ecosystem of oracle providers. Some notable ones include:
- [**Pyth**](https://www.pyth.network/price-feeds) ...
- [**Switchboard**](https://example.com) ...
- [**Chainlink**](https://example.com) ...
- [DIA](https://www.diadata.org/solana-price-oracles/) ...
We'll use Switchboard in this lesson, but the concepts are common to most oracles and you should pick the oracle that best meets your needs.
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.
Yes resolved as per suggestion.
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.
Sorry @0xCipherCoder I should be more specific.
Don't do:
some text
- Pyth
- Switchboard
- Chainlink
- Dia
some text
- Pyth
- Switchboard
Instead, replace all of that with:
some text
- Pyth
- Switchboard
- Chainlink
- Dia
I hope that makes sense.
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.
Just curious should we then remove description that has been given again for Pyth and Switchboard? Just keep the original oneliner description then go ahead with switchboard.
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.
Remove the second list, keep all the information (including more detailed explanations for Python and switchboard) but use a single list.
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.
Updated content list as per suggestion.
// derive escrow address | ||
const [escrowState] = await anchor.web3.PublicKey.findProgramAddressSync( | ||
[Buffer.from("MICHAEL BURRY"), payer.publicKey.toBuffer()], | ||
it("fails to withdraw while price is below UnlockPrice", async () => { |
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.
I don't understand how this works, precisely how we are simulating the current price of SOL to be able to test this. Can you explain it to me?
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.
@mikemaccana Here is the explainer - Anchor Toml reference -
The test environment clones the Switchboard SOL/USD
price feed from the devnet to the local test validator.
This cloned feed maintains its last known state, providing a fixed, realistic SOL price for the tests.
Then tests interact with this local copy of the feed, fetching the SOL price as if it were live data.
While the price doesn't update in real time, it allows consistent testing against a known SOL price point. In essence, we are working with a "snapshot" of the real SOL price feed, frozen at the time of cloning when we start testing with anchor test
command. For this to work we have added an additional config in Anchor.toml
file -
[test]
startup_wait = 5000
shutdown_wait = 2000
upgradeable = false
[test.validator]
bind_address = "0.0.0.0"
url = "https://api.devnet.solana.com"
ledger = ".anchor/test-ledger"
rpc_port = 8899
[[test.validator.clone]] # switchboard-solana devnet programID
address = "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
[[test.validator.clone]] # switchboard-solana devnet IDL
address = "Fi8vncGpNKbq62gPo56G4toCehWNy77GgqGkTaAF5Lkk"
# This clones the SOL/USD price feed from devnet to local test validator.
[[test.validator.clone]] # switchboard-solana SOL/USD Feed
address = "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
This PublicKey used in tests corresponds to the cloned feed in a local environment.
const SOL_USD_SWITCHBOARD_FEED = new PublicKey(
"GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
);
Let me know if you still have doubts.
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.
I understand account cloning, but I don't understand why
it withdraws from escrow
and it fails to withdraw while price is below UnlockPrice
both pass when SOL_USD_SWITCHBOARD_FEED
is not changing.
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.
Okay got the concerns. Although SOL_USD_SWITCHBOARD_FEED
is not changing we are changing the price in test as given below to simulate the escrow behaviour.
const unlockPrice = solPrice.plus(PRICE_OFFSET).toNumber();
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.
Aha! Can you please add a comment in the tests to say this?
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.
Yes added comments in both tests.
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.
Getting very close, see two comments below.
Solana has a rich ecosystem of oracle providers. Some notable ones include | ||
[Pyth Network](https://pyth.network), [Switchboard](https://switchboard.xyz), | ||
[Chainlink](https://chain.link), and | ||
[DIA](https://www.diadata.org/solana-price-oracles/). Two of the most well-known | ||
are [Pyth](https://pyth.network) and [Switchboard](https://switchboard.xyz), | ||
each with unique design choices. |
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.
Sorry @0xCipherCoder I should be more specific.
Don't do:
some text
- Pyth
- Switchboard
- Chainlink
- Dia
some text
- Pyth
- Switchboard
Instead, replace all of that with:
some text
- Pyth
- Switchboard
- Chainlink
- Dia
I hope that makes sense.
// derive escrow address | ||
const [escrowState] = await anchor.web3.PublicKey.findProgramAddressSync( | ||
[Buffer.from("MICHAEL BURRY"), payer.publicKey.toBuffer()], | ||
it("fails to withdraw while price is below UnlockPrice", async () => { |
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.
I understand account cloning, but I don't understand why
it withdraws from escrow
and it fails to withdraw while price is below UnlockPrice
both pass when SOL_USD_SWITCHBOARD_FEED
is not changing.
Thanks @0xCipherCoder ! |
Problem
Summary of Changes
Fixes #
Unboxed PRs
Burry Escrow code updated - solana-developers/burry-escrow#4
@mikemaccana I need your help in creating an additional branch for the challenge solution.