-
Notifications
You must be signed in to change notification settings - Fork 39
add pyth patterns info in the pyth-connector example #828
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
Open
masterjedy
wants to merge
6
commits into
pyth-network:main
Choose a base branch
from
masterjedy:doc/add-rtdata-example-info
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eff9a2d
add pyth patterns info
masterjedy 5e32248
fix minor issues
masterjedy 16ed2bf
add more info about patterns
masterjedy ce855c0
minor fix
masterjedy 41c0c96
fix review issues
masterjedy d254752
remove trailing whitespaces
masterjedy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,112 @@ This code snippet does the following: | |
| 4. Prepares the update data and calculates the update fee. | ||
| 5. Updates the price feeds on the TON contract. | ||
|
|
||
|
|
||
| # Patterns for Providing Pyth Data to Your Contract | ||
|
|
||
| There are typically two main scenarios: either you call a method supplying TON, or you transfer jettons. | ||
|
|
||
| - **TON proxy**: `User → Pyth → EVAA Master → ... (further processing)` | ||
| Use this method if you only need to send TON to your contract or simply call a contract method, without involving jettons. | ||
|
|
||
| - **Jetton on-chain getter**: `User → Jetton Wallet → EVAA Master → Pyth → EVAA Master → ... (further processing)` | ||
| In this pattern, your contract first receives the Pyth data, then forwards it to the Pyth contract for validation, and finally gets the validated prices back. | ||
| This approach is useful when you want to transfer jettons to your contract while also providing price data. | ||
| *Note: This diagram is simplified. In reality, the "Jetton Wallet" step consists of a sequence of transactions: User's jetton wallet → EVAA jetton wallet → EVAA master. These internal details are omitted here to highlight the main flow and the interaction with Pyth.* | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| They both are demonstrated in the [Pyth Connector example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/pyth-connector). <br/> | ||
| These same patterns are also used in the [EVAA Protocol code](https://github.com/evaafi/contracts/tree/v8) for implementing following operations: | ||
| - Pyth proxy pattern: liquidate TON / supply_withdraw TON. | ||
| - Onchain-getter pattern: liquidate jetton / supply_withdraw jetton. | ||
|
|
||
| Choose the pattern that best fits your use case and how you want to handle assets and price updates in your application. | ||
|
|
||
| Each operation described above can result in either a successful outcome or an error. It is important to consider and handle both scenarios for every pattern. | ||
|
|
||
| ## Pyth proxy: Success | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| In the EVAA protocol, the operations that implement the Pyth proxy pattern are <b>`liquidate (TON)`</b> and <b>`supply_withdraw (TON)`</b>. In these cases, the user sends a request to the Pyth contract using the native TON asset. As a result of the operation, the user may receive either TON or JETTON tokens back, depending on the outcome of the transaction. | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| autonumber | ||
| participant "U" as "User" | ||
| participant "P" as "Pyth Contract" | ||
| participant "M" as "EVAA Master" | ||
|
|
||
| note over "M": master.fc:121 — received from Pyth (op 5) | ||
| "U"->>"P": request (0x3 liquidate_master or 0x4 supply_withdraw_master) | ||
| "P"-->>"M": op 5 parse_price_feed_updates (prices) | ||
| note over "M": Master accepts and processes the transaction | ||
| ``` | ||
|
|
||
| - Related code (GitHub): | ||
| - [master.fc: entry for Pyth message](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121) | ||
| - [Pyth proxy: supply_withdraw (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L192-L211) | ||
| - [Pyth proxy: liquidate (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L171-L190) | ||
|
Comment on lines
+167
to
+170
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. Can we pls refer pyth-connector as we discussed earlier, I guess the code has been merged now. @masterjedy 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. yes, soon |
||
|
|
||
|
|
||
| ## Pyth proxy: Error handling | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| In the Pyth proxy pattern, when an error occurs (i.e., Pyth cannot process the request and sends a `response_error` with op 0x10002), the error report is sent directly back to the user who initiated the transaction, not to a contract. This is different from the on-chain getter pattern, where the error is returned to the EVAA Master contract for further handling and potential refund logic. In the proxy case, the user receives the error response from the Pyth contract, including the error code and the original query ID, allowing the user to identify and handle the failure on their side. | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| autonumber | ||
| participant "U" as "User" | ||
| participant "P" as "Pyth Contract" | ||
|
|
||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "U"->>"P": request | ||
| "P"-->>"U": response_error (op 0x10002) with error_code and query_id | ||
| ``` | ||
|
|
||
|
|
||
| ## Pyth onchain-getter: Success | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| autonumber | ||
| participant "U" as "User" | ||
| participant "JW" as "Jetton Wallet" | ||
| participant "M" as "EVAA Master" | ||
| participant "P" as "Pyth Contract" | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| "U"->>"JW": transfer with forward_payload | ||
| note right of "U": op: liquidate_master or supply_withdraw_master_jetton | ||
| "JW"->>"M": transfer_notification | ||
| "M"->>"P": op 5 parse_price_feed_updates<br/>+ update_data + target_feeds<br/>+ op_payload(liquidate_master_jetton_process / supply_withdraw_master_jetton) | ||
| "P"-->>"M": op 5 parse_price_feed_updates<br/>(prices, pyth_sender = M) | ||
| note over "M": Master accepts and processes the transaction | ||
| ``` | ||
|
|
||
| - Related code (GitHub): | ||
| - [Entry: master.fc (pyth_parse_price_feed_updates)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121) | ||
| - [Onchain-getter branches: liquidate jetton and supply_withdraw jetton](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L131-L167) | ||
| - [Request to Pyth (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L728-L742) | ||
| - [Request to Pyth (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L446-L461) | ||
|
|
||
| ## Pyth onchain-getter: Pyth error | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Pyth sends an error response (`response_error`, op 0x10002) when it cannot process the price feed update request. This can happen if the request is malformed, contains invalid or outdated feed data, or if the requested feeds are unavailable. In such cases, the error response includes an error code and the original operation payload, allowing the original sender (EVAA Master contract) to handle the failure and refund the user if necessary. | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| autonumber | ||
| participant "U" as "User" | ||
| participant "JW" as "Jetton Wallet" | ||
| participant "M" as "EVAA Master" | ||
| participant "P" as "Pyth Contract" | ||
nidhi-singh02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| "U"->>"JW": transfer with forward_payload | ||
| "JW"->>"M": transfer_notification | ||
| "M"->>"P": request (op 5 parse_price_feed_updates) | ||
| "P"-->>"M": response_error (op 0x10002) | ||
| "M"-->>"U": refund with error code | ||
| ``` | ||
|
|
||
| - Related code (GitHub): | ||
| - [Error entry: master.fc (pyth_response_error)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L92-L119) | ||
| - [Refund (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L753-L786) | ||
| - [Refund (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L899-L935) | ||
|
|
||
|
|
||
| ## Additional Resources | ||
|
|
||
| You may find these additional resources helpful for developing your TON application: | ||
|
|
@@ -134,3 +240,5 @@ You may find these additional resources helpful for developing your TON applicat | |
| - [Pyth TON SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/sdk) | ||
| - [Pyth TON SDK Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/sdk_js_usage) | ||
| - [Pyth TON Send USD Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/send_usd) | ||
| - [Pyth Connector Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/pyth-connector) | ||
| - [EVAA Protocol Code](https://github.com/evaafi/contracts/tree/v8) | ||
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.