tezos-checker / checker

An in-development "robocoin" system for the Tezos blockchain
24 stars 16 forks source link

Single source of truth for circulating kit and liquidity #136

Closed gkaracha closed 3 years ago

gkaracha commented 3 years ago

To conform to TZIP-012 we need a total_supply view which provides the total supply of kit and liquidity tokens. Currently the former is stored as part of the parameters (parameters.circulating_kit) and the latter as part of the cfmm state (cfmm.lqt). Furthermore, the kit owned by the cfmm is currently tracked in the cfmm (cfmm.kit), but not on the ledger. To avoid inconsistencies it would be better to have a single source of truth: the ledger in the fa2_state.

Related: #133.

gkaracha commented 3 years ago

If we are gonna keep track of what checker owns as well, I guess we should be thorough.

So, some thoughts on who owns what: a) Checker holds/owns cfmm.kit (with 1mukit of that being immovable). b) Checker holds/owns 1n of liquidity (which is immovable). c) Liquidity providers hold/own parts of cfmm.lqt adding up to cfmm.lqt - 1n. Right now I think that the FA2 ledger keeps track of ( c ), but it does not keep track of either ( a ) or ( b ).

And some of my thoughts on how the amounts change and move, per entrypoint:

Any thoughts? (excuse the wall of text :upside_down_face:)

gkaracha commented 3 years ago

Just leaving a note here: the reason I didn't close this issue when #141 got merged is because I am still not entirely convinced about our current treatment of excess_kit. I overall still think that we should go about this more or less as I describe above

entrypoint_burn_kit destroys kit owned by the owner. Currently we remove it in its entirety from both the total circulating and the total outstanding. Some of that kit might end up as burrow.excess_kit but the only way to make that kit visible again is via minting, so it would get re-added then to the circulating and outstanding. I am not entirely sure it is OK to consider the parts of the amount that end up in the excess_kit field burned (that's what we are doing right now, because I thought it was OK, but I doubt it now). Probably we should instead treat each part separately:

kit = up_to_outstanding + to_be_stored_as_excess

The up_to_outstanding really should be removed from both the total kit in circulation and from the total outstanding kit. However, the excess should not really affect the total outstanding kit; we still need just as much kit to close all the other burrows. We probably shouldn't remove it from circulation either, because the burrow owner can "mint" it for free really, so I'd say it's pretty liquid. A big question is then: who owns the excess (as far as the fa2 ledger is concerned, I mean).

But I haven't gotten around to tweaking the current logic to separate the two amounts.