Skip to content

Commit 71fdd5c

Browse files
committed
clarify evaa flow, add pyth connector flow
Signed-off-by: master_jedy <[email protected]>
1 parent d254752 commit 71fdd5c

File tree

1 file changed

+103
-24
lines changed
  • pages/price-feeds/use-real-time-data

1 file changed

+103
-24
lines changed

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

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Choose the pattern that best fits your use case and how you want to handle asset
149149
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.
150150

151151
### Pyth proxy: Success
152+
#### EVAA flow
152153
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.
153154

154155
```mermaid
@@ -158,18 +159,45 @@ sequenceDiagram
158159
participant P as Pyth Contract
159160
participant M as EVAA Master
160161
161-
note over M: master.fc:121 — received from Pyth (op 5)
162-
U->>P: request (0x3 liquidate_master or 0x4 supply_withdraw_master)
163-
P-->>M: op 5 parse_price_feed_updates (prices)
164-
note over M: Master accepts and processes the transaction
162+
note over M: master.fc:121 — received from Pyth (op 0x5)
163+
U->>P: op 0x5 parse_price_feed_updates (price feeds + update data)<br/>payload (op 0x3 liquidate_master | 0x4 supply_withdraw_master)
164+
note right of U: send request to Pyth Contract with update data and operation payload<br/>destination address is EVAA Master contract
165+
P-->>M: op 0x5 parse_price_feed_updates (price feeds + prices)<br/>payload (op 0x3 liquidate_master | 0x4 supply_withdraw_master)
166+
note right of P: Pyth Contract validates update data and <br/> sends prices with payload to EVAA Master contract
167+
note over M: EVAA Master validates sender <br/> parses payload and <br/> processes the transaction
165168
```
166169

167170
- Related code (GitHub):
168-
- [master.fc: entry for Pyth message](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
169-
- [Pyth proxy: supply_withdraw (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L192-L211)
170-
- [Pyth proxy: liquidate (TON) in master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L171-L190)
171+
- [entry for the Pyth message: master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
172+
- [process the supply_withdraw operation (TON): master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L192-L211)
173+
- [process the liquidate operation (TON): master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L171-L190)
171174

172175

176+
#### Pyth Connector flow
177+
The Pyth Connector example also has a similar flow. It has two main operations: proxy and onchain-getter.
178+
They have no practical purpose other than to demonstrate the patterns described above.
179+
The data flow is practically the same as the EVAA protocol, only operation codes are different.
180+
181+
```mermaid
182+
sequenceDiagram
183+
autonumber
184+
participant U as User
185+
participant P as Pyth Contract
186+
participant M as Pyth Connector
187+
188+
note over M: pyth_connector.fc:78 — received from Pyth (op 0x5)
189+
U->>P: op 0x5 parse_price_feed_updates (price feeds + update data)<br/>payload (op 0x4 connector_proxy_operation)
190+
note right of U: send request to the Pyth Contract with update data and operation payload<br/>destination address is the Pyth Connector contract
191+
P-->>M: op 0x5 parse_price_feed_updates (price feeds + prices)<br/>payload (op 0x4 connector_proxy_operation)
192+
note right of P: Pyth Contract validates update data and <br/> sends prices with payload to Pyth Connector contract
193+
note over M: Pyth Connector validates sender <br/> parses payload and <br/> processes the transaction
194+
```
195+
196+
- Related code (GitHub):
197+
- [entry for the Pyth message: pyth-connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L78)
198+
- [detect the connector_proxy_operation: pyth-connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L97)
199+
- [process the connector_proxy_operation: proxy_operation.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/operations/proxy_operation.fc#L17-L40)
200+
173201
### Pyth proxy: Error handling
174202
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.
175203

@@ -183,9 +211,8 @@ sequenceDiagram
183211
P-->>U: response_error (op 0x10002) with error_code and query_id
184212
```
185213

186-
187214
### Pyth onchain-getter: Success
188-
215+
#### EVAA flow
189216
```mermaid
190217
sequenceDiagram
191218
autonumber
@@ -194,22 +221,55 @@ sequenceDiagram
194221
participant M as EVAA Master
195222
participant P as Pyth Contract
196223
197-
U->>JW: transfer with forward_payload
198-
note right of U: op: liquidate_master or supply_withdraw_master_jetton
199-
JW->>M: transfer_notification
200-
M->>P: op 5 parse_price_feed_updates<br/>+ update_data + target_feeds<br/>+ op_payload(liquidate_master_jetton_process / supply_withdraw_master_jetton)
201-
P-->>M: op 5 parse_price_feed_updates<br/>(prices, pyth_sender = M)
202-
note over M: Master accepts and processes the transaction
224+
U->>JW: op transfer_jetton, forward_payload<br/>(liquidate_master_jetton | supply_withdraw_master_jetton)
225+
note right of U: transfer jetton with forward payload:
226+
JW->>M: op transfer_notification, forward_payload<br/>(liquidate_master_jetton | supply_withdraw_master_jetton)
227+
note right of JW: transfer notification with forward payload:
228+
M->>P: op 0x5 parse_price_feed_updates + update data + target feeds<br/>+ payload(liquidate_master_jetton_process | supply_withdraw_master_jetton_process)
229+
P-->>M: op 0x5 parse_price_feed_updates(price feeds + prices)<br/>+ payload(liquidate_master_jetton_process | supply_withdraw_master_jetton_process)
230+
note over P: Pyth Contract validates update data and <br/> sends prices with payload to EVAA Master contract
231+
note over M: EVAA Master validates sender <br/> parses payload and <br/> processes the transaction
203232
```
204233

205234
- Related code (GitHub):
206-
- [Entry: master.fc (pyth_parse_price_feed_updates)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
207-
- [Onchain-getter branches: liquidate jetton and supply_withdraw jetton](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L131-L167)
208-
- [Request to Pyth (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L728-L742)
209-
- [Request to Pyth (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L446-L461)
235+
- [entry for jetton-transfer notification: master.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L502)
236+
- [request to Pyth (op liquidate_jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L728-L742)
237+
- [request to Pyth (op supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L446-L461)
238+
- [entry point for Pyth response: master.fc (op pyth_parse_price_feed_updates)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L121)
239+
- [handle pyth response: liquidate_jetton and supply_withdraw_jetton](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L131-L167)
240+
241+
#### Pyth Connector flow
242+
Pyth Connector's onchain-getter operation has a simplified flow compared to the EVAA protocol.
243+
244+
```mermaid
245+
sequenceDiagram
246+
autonumber
247+
participant U as User
248+
participant JW as Jetton Wallet
249+
participant M as Pyth Connector
250+
participant P as Pyth Contract
251+
252+
U->>JW: op transfer_jetton, forward_payload: (onchain_getter_operation)
253+
note right of U: transfer jetton with forward payload
254+
JW->>M: op transfer_notification, forward_payload: (onchain_getter_operation)
255+
note right of JW: transfer notification with forward payload
256+
M->>P: op 0x5 parse_price_feed_updates + update data + target feeds<br/>+ payload(onchain_getter_operation)
257+
P-->>M: op 0x5 parse_price_feed_updates(price feeds + prices)<br/>+ payload(onchain_getter_operation)
258+
note over P: Pyth Contract validates update data and <br/> sends prices with payload to Pyth Connector contract
259+
note over M: Pyth Connector validates sender <br/> parses payload and <br/> processes the transaction
260+
```
261+
- Related code (GitHub):
262+
- [entry for jetton-transfer notification: pyth_connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L109)
263+
- [onchain_getter_operation request: pyth-connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L126)
264+
- [send request to the Pyth Contract: onchain_getter_operation.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/operations/onchain_getter_operation.fc#L71)
265+
- [entry for the Pyth response: pyth-connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L78)
266+
- [onchain_getter_operation process: pyth-connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L90)
210267

211268
### Pyth onchain-getter: Pyth error
212-
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.
269+
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 to handle the failure and refund the user if necessary.
270+
271+
#### EVAA flow
272+
The error response is sent directly back to the user who initiated the transaction, not to a contract. This is different from the proxy case, where the error is returned to the EVAA Master contract for further handling and potential refund logic. In the onchain-getter 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.
213273

214274
```mermaid
215275
sequenceDiagram
@@ -221,16 +281,35 @@ sequenceDiagram
221281
222282
U->>JW: transfer with forward_payload
223283
JW->>M: transfer_notification
224-
M->>P: request (op 5 parse_price_feed_updates)
284+
M->>P: request (op 0x5 parse_price_feed_updates)
225285
P-->>M: response_error (op 0x10002)
226286
M-->>U: refund with error code
227287
```
228288

229289
- Related code (GitHub):
230-
- [Error entry: master.fc (pyth_response_error)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L92-L119)
231-
- [Refund (liquidate jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L753-L786)
232-
- [Refund (supply_withdraw jetton)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L899-L935)
290+
- [entry point for the Pyth error message: master.fc (pyth_response_error)](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/master.fc#L92-L119)
291+
- [refund the liquidate jetton operation: master-liquidate.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L753-L786)
292+
- [refund the supply_withdraw_jetton operation: master-supply-withdrawal.fc](https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply-withdrawal.fc#L899-L935)
233293

294+
#### Pyth Connector
295+
The Pyth Connector error handling flow looks the same as the EVAA protocol.
296+
```mermaid
297+
sequenceDiagram
298+
autonumber
299+
participant U as User
300+
participant JW as Jetton Wallet
301+
participant M as Pyth Connector
302+
participant P as Pyth Contract
303+
304+
U->>JW: transfer with forward_payload
305+
JW->>M: transfer_notification
306+
M->>P: request (op 0x5 parse_price_feed_updates)
307+
P-->>M: response_error (op 0x10002)
308+
M-->>U: refund with error code
309+
```
310+
- [entry point for the Pyth error message: pyth_connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L31)
311+
- [validate sender and detect onchain_getter_operation: pyth_connector.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/pyth_connector.fc#L32-L43)
312+
- [handle the operation failure, refund jettons: onchain_getter_operation.fc](https://github.com/pyth-network/pyth-examples/blob/main/price_feeds/ton/pyth-connector/contracts/PythConnector/operations/onchain_getter_operation.fc#L21-L35)
234313

235314
## Additional Resources
236315

0 commit comments

Comments
 (0)