tezos-checker / checker

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

Use a flatter curve for the CFMM when tracking_type is set to token #318

Closed gkaracha closed 2 years ago

gkaracha commented 2 years ago

This is the continuation of https://github.com/tezos-checker/checker/issues/263.

When we are tracking a token on chain (i.e., when tracking_type: token in checker.yaml) it is desirable for the CFMM to use a flatter curve with less slippage, like the one currently used by ctez (branch next_next). See here and here. The most straightforward way to implement this is probably to have two CFMM implementations (indexCfmm.ml.jinja and tokenCfmm.ml.jinja, for the CPMM and the flat one, respectively) and copy/generate the appropriate cfmm.ml at build time.

gkaracha commented 2 years ago

After investigating further I realized that there's another obstacle in addressing this one. The flat curve implementation requires parameters.target, which our default cfmm implementation does not need. This affects %buy_kit and %sell_kit (as far as I can tell %add_liquidity and %remove_liquidity use more-or-less the same formulas in both implementations).

A way to address this lack of uniformity is perhaps to change the signatures of %buy_kit and %sell_kit to take that target as an input in both cases, and ignore it in the index case. Note that this would affect a bazillion tests as well, which would now require an (unused) value for the target to be passed.

gkaracha commented 2 years ago

Note also that the same issue applies to the relevant offline views (cfmm_view_min_kit_expected_buy_kit and cfmm_view_min_ctok_expected_cfmm_sell_kit).