Conversation
…-agg merge conflict resolved
d026a6a to
0c77ff0
Compare
|
@santy311 I think moving forward with an on-chain mapping system for mint-to-index conversion and getting decimal info is a good idea. Would this be an added instruction that's called for this case, if it needs to call out to an external program to get the index for the mint? |
@tracy-codes I was thinking of maintaining a separate program that will take care of the mapping. The oracle prices also contains tokens which are not required for our case like, ETH/USD and so on. So we have better control over the tokens needed. So answering to the question, we will be passing just two accounts, Scope which has the oracle data and the registry account (maintained by us). I do not think we need an added ix. |
|
@tracy-codes moving this to WIP |
There was a problem hiding this comment.
A couple of general questions / comments:
- Can we implement oracle price staleness checks? This way we can reject if the oracle price for an asset is stale as it's no longer trustworthy
- Is there a need for a test case that covers if there's multiple oracle limits? Just want to ensure if there's multiple, they don't cause any weird effects.
- This branch needs to be updated against main / merge conflicts resolved please.
|
Regarding
|
Scope is a price oracle aggregator. It's one of three oracle options alongside Pyth and Switchboard. It has an account which can support around 500 token price pair.
The major problem is that it does not have on-chain mapping. It is diabolical as they have so many oracle prices but we need to maintain the mapping somehow on chain.
So, looking into how Klend solves this, there is something call the price chain system
price_chain: [u16; 4]array of token IDs[1, 2, 0, 0]means Token → USDC → USD conversionhere Kamino does a clever way of getting the price of a token through hops, the price chain contains the mapping of the token.
For example there is some shitCoin and the oracle exists for shitCoin/Sol in the scope, then price_chain will be something like this
[32, 0, u16::MAX, u16::MAX]
The 32 is the index for shitCoin/Sol price in the scope account. Now, the second index is 0 which will give the index Sol/USD. skip for the next ones.
The problem is for each reserve in the lending, a separate config is maintained. In short:
ScopeConfigurationupdate_reserve_configWhenever a new reserve is created, some admin guy from Kamino calls the update_reserve instruction to set the price feed account
Now, for the oracle we need not keep track of multiple acounts but we need to keep track of the index.
The Problem
There is no on-chain mapping from mint addresses to Scope token index. Also we need to get the decimal of the mint as we only have the ATAs which does not contain the decimal info.
The reason why we need decimals, for example I buy 100 Trump coin but the swig knows 1 trump coin is 8 dollars. But in the program we recv something like 10_000_000, but we cannot get the price of the 100 Trump without the decimal of Trump.
I'll update the proposed solution section to address both the mapping and decimal problems comprehensively.
Proposed Solutions
We can create an on-chain mapping system (separate program) that handles both the mint-to-index mapping and decimal information. As using Kamino’s reserve for our use case to fetch the mapping will be very messy and we need to have better control over it.
Design
Also we have to add, so that when a new oracle price feed is added, we can add it to our mapping.