pendulum-chain / oracle-pallet

The Unlicense
0 stars 0 forks source link

Add support for AMPE token to batching server #10

Closed ebma closed 9 months ago

ebma commented 1 year ago

We want to have the latest price of the AMPE token on-chain. So far, we are feeding the AMPE price manually once per week and we set it to a fixed price of 1$. However, we should add support for the AMPE token to the batching server so that the latest price of the AMPE token is updated on every block and we don't need to feed it manually anymore.

TODO

We need to change the logic of the batching server to:

GraphQL

For the graphql queries, we should use some crate like graphql-client. The schema can be found here.

To be done

ebma commented 1 year ago

@pendulum-chain/product This ticket is about adding changes to our price-feeding service such that we don't have to manually feed a price on Foucoco/Amplitude once per week anymore. Please prioritize as you see fit.

prayagd commented 1 year ago

Hey team! Please add your planning poker estimate with Zenhub @adelarja @b-yap @ebma @TorstenStueber

vadaynujra commented 11 months ago

@annatekl add to epic after current one for Spacewalk launch on Amplitude.

TorstenStueber commented 11 months ago

@ebma what is the batching server?

What is the flow of data here: the batching server should request the price from the squid, which gets the price from the chain and then feed it into the chain? Isn't that circular?

ebma commented 11 months ago

The batching server is the service that provides prices from the DIA price feed to the off-chain worker. So on every block the offchain worker tries to get the latest prices of the designated assets from the batching server.

The difficulty here is how we derive the AMPE price. AMPE is not listed on a CEX so DIA has no data for it. What we decided to do instead is to base the AMPE price on the ratio of the liquidity in the AMPE/KSM pool. So we check how many AMPE are 'equal' to 1 KSM according to the current pool ratio and then use the latest dollar price of KSM to define the AMPE price.

The ticket describes that the batching server should query the price from the indexer because the indexer does this price derivation on each block. However, we can also change the batching server to connect to Amplitude and query the on-chain ratio of the AMPE/KSM pool and then do the price derivation locally. IMO querying it from the indexer is easier and faster.

TorstenStueber commented 11 months ago

Makes perfect sense now and I also do remember what the batching server is now. Thanks for the explanation.

ebma commented 10 months ago

@pendulum-chain/product I realized that implementing this ticket has an implication for Spacewalk issue requests on Amplitude. At the moment we manually feed a price for AMPE of $0.1 to Amplitude. Once we support the 'actual price' represented by the Zenlink pool, the value of the AMPE token will be around $0.0042. Thus, users will have to lock twice as many AMPE as griefing collateral for issue requests than they have to lock right now. Just FYI. This is not a flaw but important for the overall bridge security.

vadaynujra commented 10 months ago

Makes sense @ebma and how it is expected to work.

prayagd commented 10 months ago

@b-yap does this require any runtime upgrade or root transaction?

ebma commented 10 months ago

No it does not.