osmosis-labs / isotonic

Smart Contracts for the Lendex Protocol
MIT License
1 stars 0 forks source link

Price Oracle: Return inverse rate if buy/sell denoms matches #45

Closed ueco-jb closed 2 years ago

ueco-jb commented 2 years ago

Currently oracle's query implementation returns only value that is set for given pair of denoms, for example:

ExecuteMsg::SetPrice {
    sell: "ATOM",
    buy: "MOTA",
    rate: 1.1,
},

...then do the query:

QueryMsg::Price { sell: "ATOM", buy: "MOTA" },

which means that selling 1 ATOM you get 1.1 MOTA.

But same query will result NoInfo, if you reverse sell/buy denoms:

QueryMsg::Price { sell: "MOTA", buy: "ATOM" },

where in reality it could return 1/rate, here: 0.9.

ethanfrey commented 2 years ago

That is not necessarily true.

We expect time weighted average price over say last 1 hour, to avoid attacks on the spot price by someone with lots of liquidity. (This is a common DeFi attack vector).

Time weighted average is not the inverse.

mean(2, 3, 4) is not mean(1/2, 1/3, 1/4)

If you want to implement this as a fallback for the demo contract, that could be okay. I would rather not, as we do want tests to ensure we check one side of the pair consistently.

ueco-jb commented 2 years ago

Time weighted average is not the inverse.

Okay, since that's the key factor here then case is closed.