Skip to content

(feat) Add delayed settlement section #396

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

Merged
merged 6 commits into from
Aug 26, 2024
Merged

Conversation

aditya520
Copy link
Member

@aditya520 aditya520 commented Aug 12, 2024

It can be converted to a guide when we move towards solution based document sections. In the meantime, we can share this to our existing perps.

Copy link

vercel bot commented Aug 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 3:19pm

@@ -70,6 +73,18 @@ This analogy suggests two simple solutions to races:
The protocol can require a short delay between the two transactions, and the user's request gets fulfilled at the Pyth price as of the second transaction.
This technique gives the protocol extra time to observe price changes, giving it a head start in the latency race.

### Latency Mitigations for Derivative Protocols

To mitigate the risk of latency, derivative protocols should consider the following strategies:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good if you emphasize why even the slightest latency can affect derivatives. (leveraged markets)

Also, "derivative protocols are encouraged to consider the following strategies"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mentioned above in the latency section.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple suggestions for improvements here

@@ -70,6 +73,18 @@ This analogy suggests two simple solutions to races:
The protocol can require a short delay between the two transactions, and the user's request gets fulfilled at the Pyth price as of the second transaction.
This technique gives the protocol extra time to observe price changes, giving it a head start in the latency race.

### Latency Mitigations for Derivative Protocols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why derivatives in particular? I think these tips are applicable to any protocol right?

Copy link
Member Author

@aditya520 aditya520 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe derivatives are getting impacted by this issue the most.

1. **Use a Delayed Settlement**: Derivative protocols can introduce a delay between the time a ordere is created and the time it is executed. This delay gives the protocol time to observe price changes and reject trades/transactions that profit over latency.
Moreover, As mentioned above the protocol can introduce a short delay (~5 seconds) between the time a user submits the tx to the application and the keeper submits the tx to the blockchain.
The keeper can use Pyth Benchmark to get the price of `t - 5` seconds, where `t` is the current time and `t - 5` is the time when the user submitted the tx to the dApp.
Now the keeper can use [`parsePriceFeedUpdates()`](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) to parse the prices and submit to prevent price frontrunning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description of delayed settlement is confusing. The core idea of delayed settlement is that when a user places an order at time t, the trade executes using the pyth price at time t. (Now, this price is only available from pyth after a short delay, hence the name.) We should explain delayed settlement in these terms though because it's much clearer why this works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote it. Still feel it could be better. 🤔

Now the keeper can use [`parsePriceFeedUpdates()`](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) to parse the prices and submit to prevent price frontrunning.

1. **Use a Confidence Interval**: Pyth provides a confidence interval for each price update. Derivative protocols can use this confidence interval to determine the range in which the true price probably lies.
By using the lower bound of the confidence interval, derivative protocols can protect themselves from price manipulation that drives the price down. By using the upper bound of the confidence interval, derivative protocols can protect themselves from price manipulation that drives the price up.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other mitigations we should list? I've seen some protocols that require positions to be held for X minutes or something. Do we think that's a good idea?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having to hold position for X minutes is a feature that some protocols want to have, so I believe we shouldn't mention that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well i think that's also a good measurement against potentially other things and it's definitely good to mention it, but probably not here.

@aditya520 aditya520 merged commit 96d88d6 into main Aug 26, 2024
4 checks passed
@aditya520 aditya520 deleted the (feat)-add-delayed-settlement branch August 26, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants