[Oracle][Price] Keep only the anticipated currency pairs
Closed this issue · 2 comments
The PaymentGroup contains all Lease, PaymentOnly, Lpn, and Nls currencies.
Currently, the swap tree and fed prices might include any combination of payment currencies, leading to many monomorphized functions. For example, with 27 payment currencies we get 27*27*3 = 2187
Price::checked_add and Price::lossy_mul functions, reported by cargo llvm-lines
.
The solution is to limit the valid currency combinations to the ones connected to existing pools at the Dex. To limit the number further we shall keep the currencies' order as defined by the Dex provider, eliminating one of (A, B) or (B, A).
Design-wise, PriceDTO should represent such a price, and the currency resolution to Price<B, Q> should eliminate going over all currencies. Specifically, Q
should be selected only among the currencies that implement InPoolWith<B>
that the protocol generation tool would generate as per the info from topology.json
amm_pools
object.
As a result, the protocol limitation would not be 26 max number of currencies (this generates a Wasm file within the limit of 10_000 total function arguments imposed by cosmwasm-check
). The protocol limit would be measured in the number of pools, expecting to get to around 26*26 = 676 total pools per protocol, which is much more permissive and opens a room for more than 26 currencies.
[update on 16.09] The planned design described above has been implemented.
The results were not as good as we had expected. A thorough analysis has revealed that two more functions offer a pair of currency definitions to currency type resolution. Specifically, they are both in mod currency::with_price
.
Moving this task to the next release.
done and shipped with 0.7.3