Skip to content
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

proposal(twap): consider using last spot price instead of zero on error in getSpotPrices #2689

Closed
Tracked by #4622
p0mvn opened this issue Sep 9, 2022 · 5 comments
Closed
Tracked by #4622

Comments

@p0mvn
Copy link
Member

p0mvn commented Sep 9, 2022

Background

Context:

osmosis/x/twap/logic.go

Lines 46 to 54 in 4bbd3fb

// In the event of an error, we just sanity replace empty values with zero values
// so that the numbers can be still be calculated within TWAPs over error values
// TODO: Should we be using the last spot price?
if (sp0 == sdk.Dec{}) {
sp0 = sdk.ZeroDec()
}
if (sp1 == sdk.Dec{}) {
sp1 = sdk.ZeroDec()
}

I think this is a worthwhile improvement to make before v12.

Acceptance Criteria

  • decide if including in v12
@p0mvn p0mvn added discussion C:x/twap Changes to the twap module labels Sep 9, 2022
@p0mvn p0mvn added this to the V12 Blockers milestone Sep 9, 2022
@osmo-bot osmo-bot moved this to Needs Review 🔍 in Osmosis Chain Development Sep 9, 2022
@AlpinYukseloglu
Copy link
Contributor

AlpinYukseloglu commented Sep 10, 2022

I agree with switching to last spot price as this causes TWAPs to level out and stay stable after an error, which is the property that I believe we wanted to protect by leaving TWAPs open after spot price errors

@mattverse
Copy link
Member

Let me think about the possible edge case here, is it going to error when the pool does not have the last spot price? By last spot price, are we referring to the spot price recorded in the previous epoch?

@p0mvn
Copy link
Member Author

p0mvn commented Sep 11, 2022

Let me think about the possible edge case here, is it going to error when the pool does not have the last spot price? By last spot price, are we referring to the spot price recorded in the previous epoch?

Assume that we have a twap record at time t. Then, at t + 1 we have a swap so a new record needs to be created with the updated spot prices. Let us get a spot price error.

Currently, we would set the spot price to 0 at t + 1 since it errored. The problem with that is that it negatively impacts the calculations by diverging them significantly from the true value.

Instead of setting it to zero, we might want to reuse the spot price from the previous record (at time ``t`)

One edge case I can think of is when we get an error but there is no older record.

I don't think it should be hard to implement the change. I will try getting it out before Monday to further discuss

@mattverse
Copy link
Member

Currently, we would set the spot price to 0 at t + 1 since it errored. The problem with that is that it negatively impacts the calculations by diverging them significantly from the true value

If this is the case, I'm definitely for what this issue is proposing! (I wonder if we have a test case showing that rn)

@p0mvn
Copy link
Member Author

p0mvn commented Sep 12, 2022

Decided on the call that this is not v12 blocking but good to have in the future releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants