Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 16ed2bf

Browse files
committed
add more info about patterns
Signed-off-by: master_jedy <[email protected]>
1 parent 5e32248 commit 16ed2bf

File tree

1 file changed

+95
-13
lines changed
  • pages/price-feeds/use-real-time-data

1 file changed

+95
-13
lines changed

pages/price-feeds/use-real-time-data/ton.mdx

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,109 @@ This code snippet does the following:
124124
4. Prepares the update data and calculates the update fee.
125125
5. Updates the price feeds on the TON contract.
126126

127-
When providing Pyth data to your contract, there are typically two main scenarios: either you call a method supplying TON, or you transfer jettons.
127+
128+
# Patterns for Providing Pyth Data to Your Contract
129+
130+
There are typically two main scenarios: either you call a method supplying TON, or you transfer jettons.
131+
132+
- **TON proxy**: `User → Pyth → EVAA Master → ... (further processing)`
133+
Use this method if you only need to send TON to your contract or simply call a contract method, without involving jettons.
134+
135+
- **Jetton on-chain getter**: `User → Jetton Wallet → EVAA Master → Pyth → EVAA Master → ... (further processing)`
136+
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.
137+
This approach is useful when you want to transfer jettons to your contract while also providing price data.
138+
*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.*
128139

129140
They both are demonstrated in the [Pyth Connector example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/pyth-connector).
141+
These same patterns are also used in the [EVAA Protocol code](https://github.com/evaafi/contracts/tree/v8).
130142

131-
These same patterns are also used in the
132-
[EVAA Protocol code](https://github.com/evaafi/contracts/tree/v8).
143+
Choose the pattern that best fits your use case and how you want to handle assets and price updates in your application.
133144

134-
1. **Pyth Proxy Call Pattern**
135-
**Flow:** *User → Pyth → Your-Contract*
145+
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.
136146

137-
Use this method if you only need to send TON to your contract or simply call a contract method, without involving jettons.
147+
## Pyth proxy: Success
148+
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.
138149

139-
2. **Onchain Getter Pattern**
140-
**Flow:** *User → User-JW → Your-Contract-JW → Your-Contract → Pyth → Your-Contract*
141-
142-
> JW = Jetton Wallet
150+
```mermaid
151+
sequenceDiagram
152+
autonumber
153+
participant "U" as "User"
154+
participant "P" as "Pyth Contract"
155+
participant "M" as "EVAA Master"
143156
144-
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.
145-
This approach is useful when you want to transfer jettons to your contract while also providing price data.
157+
note over "M": master.fc:121 — received from Pyth (op 5)
158+
"U"->>"P": request (0x3 liquidate_master or 0x4 supply_withdraw_master)
159+
"P"-->>"M": op 5 parse_price_feed_updates (prices)
160+
note over "M": Master accepts and processes the transaction
161+
```
162+
163+
- Related code (GitHub):
164+
- [master.fc: entry for Pyth message](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
165+
- [Pyth proxy: supply_withdraw (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L192-L211)
166+
- [Pyth proxy: liquidate (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L171-L190)
167+
168+
169+
## Pyth proxy: Error handling
170+
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.
171+
172+
```mermaid
173+
sequenceDiagram
174+
autonumber
175+
participant "U" as "User"
176+
participant "P" as "Pyth Contract"
177+
178+
"U"->>"P": request
179+
"P"-->>"U": response_error (op 0x10002) with error_code and query_id
180+
```
181+
182+
183+
## Pyth onchain-getter: Success
184+
185+
```mermaid
186+
sequenceDiagram
187+
autonumber
188+
participant "U" as "User"
189+
participant "JW" as "Jetton Wallet"
190+
participant "M" as "EVAA Master"
191+
participant "P" as "Pyth Contract"
192+
193+
"U"->>"JW": transfer with forward_payload
194+
note right of "U": op: liquidate_master or supply_withdraw_master_jetton
195+
"JW"->>"M": transfer_notification
196+
"M"->>"P": op 5 parse_price_feed_updates<br/>+ update_data + target_feeds<br/>+ op_payload(liquidate_master_jetton_process / supply_withdraw_master_jetton)
197+
"P"-->>"M": op 5 parse_price_feed_updates<br/>(prices, pyth_sender = M)
198+
note over "M": Master accepts and processes the transaction
199+
```
200+
201+
- Related code (GitHub):
202+
- [Entry: master.fc (pyth_parse_price_feed_updates)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
203+
- [Onchain-getter branches: liquidate jetton and supply_withdraw jetton](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L131-L167)
204+
- [Request to Pyth (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L728-L742)
205+
- [Request to Pyth (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L446-L461)
206+
207+
## Pyth onchain-getter: Pyth error
208+
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.
209+
210+
```mermaid
211+
sequenceDiagram
212+
autonumber
213+
participant "U" as "User"
214+
participant "JW" as "Jetton Wallet"
215+
participant "M" as "EVAA Master"
216+
participant "P" as "Pyth Contract"
217+
218+
"U"->>"JW": transfer with forward_payload
219+
"JW"->>"M": transfer_notification
220+
"M"->>"P": request (op 5 parse_price_feed_updates)
221+
"P"-->>"M": response_error (op 0x10002)
222+
"M"-->>"U": refund with error code
223+
```
224+
225+
- Related code (GitHub):
226+
- [Error entry: master.fc (pyth_response_error)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L92-L119)
227+
- [Refund (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L753-L786)
228+
- [Refund (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L899-L935)
146229

147-
Choose the pattern that best fits your use case and how you want to handle assets and price updates in your application.
148230

149231
## Additional Resources
150232

0 commit comments

Comments
 (0)