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

Feat/moving mid #79

Merged
merged 21 commits into from
Jan 18, 2021
Merged

Feat/moving mid #79

merged 21 commits into from
Jan 18, 2021

Conversation

jacob-eliosoff
Copy link
Collaborator

This is a bunch of changes related to the two big new features. Not ready to merge or even test yet, I'll update this PR when it is. I am trying to make each commit reasonably legible and bite-sized.

  1. "Moving mid", ie, mints/burns/funds/defunds move the USM contract's mid ETH/USD price separately from oracle updates. (When a fresh oracle price comes in, the USM mid is reset to the oracle's mid; this change is about what happens to the mid between oracle updates.)

    In plain English, the behavior we're targeting here is: "A short-ETH op (mint/defund) pushes the system's mid ETH price down, and pushes the price you actually sell at down even more." And of course the reverse for the long-ETH ops, burn and fund.

  2. New sliding-price math, based on % change in ETH pool, rather than on % change in debt ratio. Eg, suppose the pool contains 200 ETH, and the user calls mint(10 ETH), increasing the pool by 5% = a factor of 1.05×. Then our new math says:

  • The ETH mid decreases by 1/sqrt(1.05) = 0.9759×. ("Decreases" because minting amounts to selling ETH for USD, so it pushes the ETH price down.)
  • The buy-sell adjustment also decreases, by the same factor, 1/sqrt(1.05) = 0.9759×. That is, as the mid price drops, your sell price gets further below mid, too.
  • So, combined, the user's ETH sell price decreases (ie, USM buy price increases) by the product of these factors: 1/sqrt(1.05) × 1/sqrt(1.05) = 1/1.05 = 0.9524×.

    This math is actually all straightforward: the hairy part is how to translate this for fund/defund... More on that soon.

…s in USMTemplate, should have zero behavior change.
…, storedPrice, distinct from the oracle's mid, latestPrice(). But USMTemplate doesn't actually modify storedPrice yet: that change is coming up...
…ere view-only users (eg Alex's stats webpage) go for stats based on "pretty recent" prices; those needing the very latest prices/stats need to call usm.refreshPrice().
@jacob-eliosoff jacob-eliosoff self-assigned this Jan 14, 2021
1. Made USMTemplate store and update its own price.
2. Calculate sliding prices based on new math: % change in ETH pool, rather than % change in debt ratio.
3. Major updates to tests, especially test 3, plus removing proxy test 5 (redundant with test 4).
… TWAPs: needed to make test 3's sample TWAP observations > 10 min apart. That said I still don't fully understand why it was breaking...
…with test 3's, and compatible with 10-minute TWAPs.
…m Oracle. Now it has an Oracle member instead, like a sane person would do, and it only seems to cost ~1-2k gas per operation? Surprisingly few lines changed too.
@jacob-eliosoff
Copy link
Collaborator Author

OK, this is now feature-complete, the tests pass, and I think it's good to merge! I need to add/update quite a few comments, and I expect there are some little bugs left, this is hot off the presses. But I'm not aware of any gaping holes.

I propose we get this up on kovan and fool around with it (but not announce the testnet version publicly yet because it's too raw - may need to redeploy).

Also, don't deploy until reading my next comment here...

@jacob-eliosoff
Copy link
Collaborator Author

See also #85, which is just this codebase but with the additional undoing of the inheritance hack. I think #85 is what we should be merging and deploying to testnet.

@alcueca alcueca merged commit cef0aa9 into master Jan 18, 2021
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.

2 participants