-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize user state queries using new API endpoints #414
Comments
Suggestions for improvements to the API: New logicOn the app I would like to make a distinction between "accurateUserReserves" and "estimatedUserReserves" with an implementation of maybe both using React hooks. Accurate user reserves"accurateUserReserves" is for pages that require accurate detail such as the Pool Management pages with show the user deposits in real-time. "accurateUserReserves" would require knowing the users reserves calculated correctly at each block, as we currently lack this same-block guarantee, accurate reserves cannot be calculated. Estimated user reserves"estimatedUserReserves" can be for pages that do not show individual user deposits but aggregated user deposit values such as the Portfolio page which sums a user's reserve value in each pair. "estimatedUserReserves" requires knowing the number of user's reserves (exact or approximate) at a recent point in time, and then assuming what the reserves are at the current point in time assuming that the token pair pools are perfectly arbitraged at the current point in time (which is likely not true but the calculated result should be approximately correct for pools with enough liquidity) Indicative user reservesboth "accurateUserReserves" and "estimatedUserReserves" can be calculated from a new concept "indicativeUserReserves" which contains for each pool:
where the Estimated user reserves calculationsUsing Accurate user reserves calculationsUsing accurate Indicative user reserves calculations"indicativeReserves" can be calculated from These values can be currently collected from:
but if would be better if they could be collected from one place, allowing the app to have an "accurate" (numbers from the same height) version of the user's indicative reserves:
ConclusionTherefore I think my recommendation is to add:
This allows the app to
Additionally for other applications: the ability to continually fetch |
The previous comment has been expanded out into separate issues: |
This work should follow on from the changes made to use the user state endpoints in:
Discussion
With the introduction of the endpoint
/dualitylabs/duality/dex/pool/{pairID}/{tickIndex}/{fee}
in duality-labs/duality#446 (which is included in Duality v0.4.0)User queries from the front end can now look up their own data from
/dualitylabs/duality/dex/user/positions/{address}
/dualitylabs/duality/dex/user/deposits/{address}
/dualitylabs/duality/dex/user/limit_orders/{address}
and use these known center tick indexes and fees to find the reserves of both
lower_tick0
andupper_tick1
of a center tick at the same time (and avoid having a404 not found
error on empty upper or lower tick requests).This should help the front end:
Unexpected developments
When requesting this feature I was asking for (importantly this data is from the same block height) an endpoint to return a pool's
This I wanted to combine with the user data of
/dualitylabs/duality/dex/user/deposits/{address}
which returns the user's shares insharesOwned
, to calculate a user's holding in terms of reserves, ie.userReserves0 = (sharesOwned / totalShares) * lowerTickReserves
userReserves1 = (sharesOwned / totalShares) * upperTickReserves
However the new endpoint returns only
Which does not have enough information to piece together the amount of reserves that a user holds at a certain block in time. Because the requests for this information must still be made in at least two separate requests we cannot guarantee that the data is from the same height, so the calculated user reserves remain an estimation.
Conclusion
So while this endpoint does serve to reduce the number of network requests from 3 to 2 per user deposit, It is not particularly helpful.
requests used previously per user deposit:
totalShares
from/cosmos/bank/v1beta1/supply/{denom}
lowerReserves
from/dualitylabs/duality/dex/pool_reserves/{pairID}/{tokenIn}/{tickIndex}/{fee}
upperReserves
from/dualitylabs/duality/dex/pool_reserves/{pairID}/{tokenIn}/{tickIndex}/{fee}
requests used after new endpoint per user deposit:
totalShares
from/cosmos/bank/v1beta1/supply/{denom}
lowerReserves
andupperReserves
from/dualitylabs/duality/dex/pool/{pairID}/{tickIndex}/{fee}
The endpoint as is may be used to reduce network calls, but I don't think this is a priority compared to other issues such as the guarantee that this calculation is accurate by guaranteeing that the data is from the same block height.
The text was updated successfully, but these errors were encountered: