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

RToken Oracle #849

Merged
merged 12 commits into from
Jun 29, 2023
Merged

RToken Oracle #849

merged 12 commits into from
Jun 29, 2023

Conversation

akshatmittal
Copy link
Member

@akshatmittal akshatmittal commented Jun 19, 2023

Oracle implementation for RTokens based on internal pricing logic.

Base automatically changed from add-tenderly-plugin to 3.0.0-rc3 June 20, 2023 13:37
@akshatmittal
Copy link
Member Author

Sample RToken Oracle Result

Block      eUSD Price             USDT Price   USDC Price   saUSDT refPerTok       saUSDT Price           saUSDC refPerTok       saUSDC Price           cUSDT refPerTok        cUSDT Price            cUSDC refPerTok        cUSDC Price
---------- ---------------------- ------------ ------------ ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ----------------------
16800000   1.000250342681174615   0.9999       1.00019      1.10547420591119908    1.105705021302881661   1.084044927184019098   1.084269534947387058   0.022157627739154103   0.022161751463684806   0.022758692953304188   0.022767779928116612  
16809885   0.99269244900339515    1.01184855   0.97353412   1.107985696048975189   1.121116938092315611   1.084154047747082093   1.055461559995242234   0.022190489498328311   0.022453425877459063   0.022769414782605548   0.022166813294419589  
16809886   0.992692486669796829   1.01184855   0.97353412   1.107985696048975189   1.12111710039361259    1.084154047747082093   1.055461564529608879   0.022190489498328311   0.022453425877459063   0.022769414782605548   0.022166813294419589  
16809887   0.992692506321832487   1.01184855   0.97353412   1.107985696048975189   1.121117185072550144   1.084154047747082093   1.05546156689536539    0.022190489498328311   0.022453425877459063   0.022769414782605548   0.022166813294419589  
16809888   0.992692525973868145   1.01184855   0.97353412   1.107985696048975189   1.121117269751487699   1.084154047747082093   1.0554615692611219     0.022190489498328311   0.022453425877459063   0.022769414782605548   0.022166813294419589  
16809889   1.011848808371396789   1.01184855   0.97353412   1.107991712209447232   1.121120390542746293   1.084154222275613383   1.055461656369231622   0.022190585953692956   0.02245352347572884    0.022769419567304363   0.022166817952489474  
16809890   1.011848827477798178   1.01184855   0.97353412   1.107991712209447232   1.121120475221683847   1.084154222275613383   1.055461658734988133   0.022190585953692956   0.02245352347572884    0.022769419567304363   0.022166817952489474  
16810000   1.01185040884643707    1.01184855   0.97311829   1.107996552866929661   1.121132381840858883   1.084154362644172535   1.055011162781325371   0.022190660362541147   0.022453598766251729   0.022769423258359572   0.022157353331839992  
16811000   1.009307648131856939   1.0092701    0.9543403    1.107996552866929661   1.118359782393752088   1.084154362644172535   1.034655791720626423   0.022190660362541147   0.022397860509610995   0.022769423258359572   0.021729859412096084  
16812000   1.006785938072538056   1.00671336   0.95760273   1.107996552866929661   1.115624472020322386   1.084154362644172535   1.038196004009276585   0.022190660362541147   0.022342280430609519   0.022769423258359572   0.021804198443637033  
16813030   1.011834283249403886   1.0118313    0.9599       1.108575246332241756   1.12169996026351226    1.084173133695876552   1.04069850853564569    0.022199139568712232   0.022461872378528762   0.022769843187161643   0.02185678343107462   
16813147   1.011833567770177913   1.0118313    0.95992      1.108600867093938615   1.121726550479492694   1.084173764382247998   1.040720788834726027   0.022199470544165756   0.022462130399163422   0.022769859710697619   0.021857254689447236  
16813277   1.011833475972424008   1.0118313    0.95992      1.108631747157302395   1.121757389078986728   1.084174446913703388   1.040721444665331581   0.022199834974629126   0.022462499141497766   0.022769877914625015   0.021857272163769981  
16813289   1.011833790386843828   1.0118313    0.95992      1.108631747157302395   1.121758783358217037   1.084174446913703388   1.040721474846413318   0.022199834974629126   0.022462499141497766   0.022769877914625015   0.021857272163769981  
16813290   1.011833814238989445   1.0118313    0.95992      1.108631747157302395   1.121758889131200512   1.084174446913703388   1.040721477135872556   0.022199834974629126   0.022462499141497766   0.022769877914625015   0.021857272163769981  
16813290   1.011833814238989445   1.0118313    0.95992      1.108631747157302395   1.121758889131200512   1.084174446913703388   1.040721477135872556   0.022199834974629126   0.022462499141497766   0.022769877914625015   0.021857272163769981  
16813291   1.011833840259511937   1.0118313    0.95992      1.108631747157302395   1.121759004519909758   1.084174446913703388   1.040721479633464453   0.022199834974629126   0.022462499141497766   0.022769877914625015   0.021857272163769981  
16814000   1.01487072595285407    1.01483783   0.96917081   1.108631747157302395   1.125171974271140208   1.084174446913703388   1.050753722646727017   0.022199834974629126   0.02253034051524861    0.022769877914625015   0.022067965972665251  
16880480   1.001858545000116404   1.00185812   0.9994       1.111089902242004766   1.113155348411938116   1.084820825373113824   1.084170681195919965   0.022238534602691859   0.022279876104437028   0.022783480747085269   0.022769822072016024  
16880619   1.001858449478586048   1.00185812   0.9994       1.111091189027740366   1.113156636141044776   1.084821593878118378   1.08417144946999273    0.022238573667432694   0.022279906773744464   0.022783513551221265   0.022769854856485971  
16880732   1.001858450706144475   1.00185812   0.9994       1.111092235459096264   1.113157689973371879   1.084822208116132834   1.084172063239306459   0.022238605425132736   0.022279938590470072   0.022783540237800279   0.022769881527066406  
16880882   1.001858564941964647   1.00185812   0.9994       1.111093639985209353   1.113159097111535137   1.084823024035121355   1.084172878756058806   0.02223864758148338    0.022279990986951621   0.022783575662521054   0.022769924502175286  
16984306   1.000124869429813756   1.0003       0.99994849   1.111915386763003251   1.11224976785284967    1.085582734533068118   1.085527651839608789   0.022259955956781983   0.022266645104730443   0.022800088750732049   0.022799941332140961  
16984426   1.000124869415112326   1.0003       0.99994849   1.11191621156448123    1.112250592922140917   1.085583700669525296   1.085528617843899198   0.022259976361153779   0.022266665515233781   0.022800088750732049   0.02279995012922695   
16984617   1.000124869468389132   1.0003       0.99994849   1.111917518199075748   1.112251899995961885   1.08558523122457589    1.085530148507442908   0.022260009008261532   0.022266698172152035   0.022800088750732049   0.022799964181678947  
16985434   1.000124869185355718   1.0003       0.99994849   1.111923028080522831   1.112257411458802728   1.085591686296998864   1.085536602097077678   0.022260147335256005   0.022266836540713965   0.022800088750732049   0.022800021509663299  
16985558   1.00012490479506135    1.0003       0.99994849   1.111923872650852316   1.112258253255987271   1.085592672175450652   1.085537582424218088   0.02226016871004753    0.022266858517337979   0.022800088750732049   0.022800032427607533  
16985697   1.000124868372536145   1.0003       0.99994849   1.111924816207084162   1.11225920012845089    1.085593764729787389   1.08553867688961144    0.02226019245998188    0.022266881678999883   0.022800088750732049   0.022800038570948615  
16985817   1.000124868509209396   1.0003       0.99994849   1.1119256146008188     1.112259999037803219   1.085594685349879486   1.085539597787478182   0.022260212477842462   0.02226690170287586    0.022800088750732049   0.022800046121033502  
16985977   1.000124868428143205   1.0003       0.99994849   1.111926690134592003   1.112261074661263909   1.085595925922614886   1.085540838173458935   0.022260239620783019   0.022266928853972908   0.022800088750732049   0.022800056324268744  
17089550   1.000085695949809968   1.00017      1.0          1.112942710411420033   1.113132869051685547   1.086504685386935671   1.086505685070103166   0.022286188905897708   0.022289988730874135   0.022800088750732049   0.022809078165266379  
17316734   0.999976763684192206   1.00013      0.99982217   1.115267944732087706   1.115413834418985884   1.089152717221935539   1.088959984446859312   0.022337561630069432   0.022340476711250878   0.022800088750732049   0.022825599074065711  
17430275   1.000157940908972468   1.0003347    0.99997979   1.116448130090694911   1.11682280695386752    1.090401714287536225   1.090380640944273585   0.022362110303654334   0.022369606114743625   0.022800088750732049   0.022839340978278067  
17526157   0.999987083719414892   0.99974555   1.00021167   1.117508679795495629   1.117233297030881168   1.091649364003208049   1.0918903082402599     0.022385266458522356   0.022379812635882932   0.022800088750732049   0.022852600573942559

@akshatmittal akshatmittal changed the title RToken Oracle Testing RToken Oracle Jun 22, 2023
Copy link
Collaborator

@tbrent tbrent left a comment

Choose a reason for hiding this comment

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

Re-reviewed all the non-FixLib stuff

will also need lint attention before going in

contracts/interfaces/IRTokenOracle.sol Show resolved Hide resolved
contracts/interfaces/IRTokenOracle.sol Outdated Show resolved Hide resolved
/// @param a First to multiply
/// @param b Second to multiply
/// @param c Denominator
function safeMulDiv(
Copy link
Collaborator

Choose a reason for hiding this comment

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

other reviewers, this is the function that needs your eyes

Copy link
Contributor

@jankjr jankjr Jun 27, 2023

Choose a reason for hiding this comment

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

As far as I can see safeMulDivonly diviates from mulDiv in the overflow case if (hi >= c) return FIX_MAX; - as is the intention.

I don't see any unintended behaviour introduced. LGTM

contracts/p1/BasketHandler.sol Show resolved Hide resolved
contracts/p1/BasketHandler.sol Outdated Show resolved Hide resolved
contracts/plugins/assets/RTokenAsset.sol Outdated Show resolved Hide resolved
contracts/plugins/assets/RTokenAsset.sol Outdated Show resolved Hide resolved
return;
}

(uint192 low, uint192 high) = price();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Noting out loud that when we bring the lotPrice changes over to this repo this should stay price() and should not change to lotPrice().

Copy link
Collaborator

@pmckelvy1 pmckelvy1 left a comment

Choose a reason for hiding this comment

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

uint256 result_256;
unchecked {
(uint256 hi, uint256 lo) = fullMul(a, b);
if (hi >= c) return FIX_MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line and L595 are the only 2 that feel a bit odd to me, but we already follow a similar pattern in safeMul, so i think this is correct to return FIX_MAX instead of erroring.

@akshatmittal akshatmittal merged commit a507747 into 3.0.0-rc3 Jun 29, 2023
8 checks passed
@akshatmittal akshatmittal deleted the rtoken-oracle branch June 29, 2023 16:31
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.

4 participants