balancednetwork / balanced-backend

Backend to balanced stats page and other services
Apache License 2.0
0 stars 1 forks source link

Estimate for cross-chain collateral deposit breakdown #61

Open hetfly opened 4 months ago

hetfly commented 4 months ago

There are cross-chain collateral types now, ie ETH. It's represented by a single token on ICON network, but can be deposited from multiple chains. Can we track how much was deposited from which chain? It would have to be read from xCalls executeCall method, I think, that confirms the deposit to Balanced Loans contract from the spoke chain.

robcxyz commented 4 months ago

Can you give me an address(es) so I can start poking around?

It doesn't sound like you need to hit other chains and can do this all through inspecting the logs from ICON. If this requires hitting other chains though then this is going to take a while.

hetfly commented 4 months ago

cxa07f426062a1384bdd762afa6a87d123fbc81c75 is the xCall address, I'd probably start with looking for CallExecuted, if it's successful, check it's request id, find CallMessage with the same id and see the data there

robcxyz commented 2 months ago

Ok so as I understand it, a CallMessage event will be emitted which has a request ID (_reqId) which then needs to joined with the request ID of the associated CallExecuted event which may or may not exist depending on if the transaction went through.

So no matter what it seems like this contract needs a full index of these two events which will then be joined on _reqId and then in turn there will be a lookup based on some key to associate the message with a given pool - not sure how that is done (_sn? or _to / _from) and only then can we associate the transaction volume to the spoke chain.

Does this seem right? This is only after some cursory investigations and definitely would want to run this by Andell to see if this all makes sense. Definitely will need a full index of the CallMessage and CallExecuted events but then after that it seems like there could be a couple ways to join the data from the two events. Then after that associating the event with the spoke chain hopefully is simple. Would need to stage the data in a table and then create a view on top of that to sum up the values.

Hope I am not making this too complex in my understanding but it seems very non-trivial to do this properly. Also seems like various incantations of this indexing pattern will show up in multiple places with xcall Txs.

Could this be done instead by simply tracking the balances of contrcts themselves or do we need to associate the balance with this type of Tx to get the right data?

CyrusVorwald commented 2 weeks ago

xcallscan api might support this @kryptopoo