-
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
Improve accuracy of userReserves calculations #493
Comments
You can just do multiple queries to the same height, no? |
That's only true for backend applications, and if we can guarantee the API config of full nodes running the REST API (which I assumed we could not because we don't control all the nodes, but possibly we can just enforce the configuration on the node that we control?). The REST API nodes need to whitelist
If we can guarantee that config for the API that the web app will use then yes, I could send those headers and avoid needing this data from the same endpoint. |
Issue
At the moment it is not possible to guarantee that we know how many Duality Dex reserves a user's wallet holds.
this is because:
Indicative user reserves calculations
We use
indicativeReserves
as a fundamental state to calculating a user's accurateuserReserves
in the app.indicativeReserves
can be calculated fromuserReserves = (sharesOwned / totalShares) * tickReserves
at any point in time (but will only be "accurate" whentotalShares
andtickReserves
are fetched from the same block height as they may change every/any block height,sharesOwned
only changes with user actions).These values can be currently collected from:
sharesOwned
from/cosmos/bank/v1beta1/balances/{address}
/dualitylabs/duality/dex/user/deposits/{address}
ifpoolID
was returned onDepositRecord
, but it is not so this is not recommend after the update of duality-labs/duality@9ede0f2totalShares
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}
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:
/duality/dex/user/deposits/{address}
:indicativeReservesAsToken0
andindicativeReservesAsToken1
directly/duality/dex/pool/{poolID}
and/or/duality/dex/pool/{pairID}/{tickIndex}/{fee}
:totalShares
onQueryPoolResponse
or thePool
type/duality/dex/user/deposits/{address}
/duality/dex/user/deposits/{address}
should returnpoolID
if only the/duality/dex/pool/{poolID}
endpoint will contain thetotalShares
information./cosmos/bank/v1beta1/balances/{address}
but this endpoint will no longer give an indication of which pools belong to which token pair (without fetching metadata for each pool)/duality/dex/user/deposits/{address}
would be more beneficial./duality/dex/user/deposits/{address}/{poolID}
indicativeReserves
for a single pool. which would be a typical request after the users makes a Dex action that causes a banktransfer
action to occur against their wallet address.indicativeReserves
to the/duality/dex/user/deposits/{address}
endpoint. If we addtotalShares
there instead the required data to update the app state for a single pool will be available on the/duality/dex/pool/{poolID}
and/or/duality/dex/pool/{pairID}/{tickIndex}/{fee}
endpoints if thetotalShares
information is added there.Conclusion
Therefore I think my recommendation is to add
Option 1
Pool
type (https://github.com/neutron-org/neutron/blob/v2.0.0/proto/neutron/dex/pool.proto#L10-L14):totalShares
lowerReserves0
andupperReserves1
Pool
type suitable for calculating accurate indicative reserves for the app/duality/dex/user/deposits/{address}
response typeDepositRecord
https://github.com/neutron-org/neutron/blob/v2.0.0/proto/neutron/dex/deposit_record.proto#L8-L20pool
(ofPool
type with newtotalShares
info)This allows the app to
/duality/dex/user/deposits/{address}
on app start / address changeaccurateUserReserves
andestimatedUserReserves
) in one network request./duality/dex/pool/{poolID}
upon anybank.transfer
updates to the user's bankOption 2
or if we don't want to modify the common
Pool
type to add to the responses:DepositRecord
https://github.com/neutron-org/neutron/blob/v2.0.0/proto/neutron/dex/deposit_record.proto#L8-L20totalShares
pool
(to addpoolID
,lowerReserves
, andupperReserves
all at once)QueryPoolResponse
https://github.com/neutron-org/neutron/blob/v2.0.0/proto/neutron/dex/query.proto#L304-L306totalShares
/duality/dex/pool/{poolID}
and/duality/dex/pool/{pairID}/{tickIndex}/{fee}
suitable for calculating accurate indicative reserves on individual pools for the appOption 3
or instead of modifying
QueryPoolResponse
(because of concerns for returning too much unrelated(?) information for these endpoints)/duality/dex/user/deposits/{address}/{poolID}
endpoint to return individual DepositRecords for individual Pool IDs would enable easy accurate user reserve queries for partial updates.For all options
For applications other than the web app, adding
totalShares
,lowerReserves
, andupperReserves
to the user deposits response may be very helpful. The ability to continually fetch/duality/dex/user/deposits/{address}
whenever to get an accurate total of the user's reserves at the current point in time could be very helpful in building simple applications.The text was updated successfully, but these errors were encountered: