Skip to main content

Multiswap Safe Operations Cheat Sheet

· 5 min read
Eric Forgy
Founder of CavalRe

Scope: The operation classes below describe mathematical safety results. Current contracts expose Reserve Asset swaps and proportional LP liquidity; general coefficient updates and unequal liquidity baskets are not public operations. See Liquidity Operations.

This is the compact safety reference for the exact-arithmetic, claim-free Multiswap Reserve--LP system.

1. State

Derivation: native state and elasticity, followed by the normalized Reserve--LP identity.

For Reserve Asset ii,

si=ciaies,Pi=ciaieP,eP=1es,s_i=c_i a_i^{e_s}, \qquad P_i=c_i a_i^{-e_P}, \qquad e_P=1-e_s,

with 0<es<10<e_s<1. The LP Token is derived:

s0=isi,P0=s0a0,c0=s0a0es.s_0=\sum_i s_i, \qquad P_0=\frac{s_0}{a_0}, \qquad c_0=\frac{s_0}{a_0^{e_s}}.

Therefore

sis0=cic0(aia0)es.\boxed{ \frac{s_i}{s_0} =\frac{c_i}{c_0} \left(\frac{a_i}{a_0}\right)^{e_s}. }

2. Safety test

Derivation: Gauge-Invariant Safety.

An atomic action is projectively safe when

cic0cic0i.\boxed{ \frac{c_i'}{c_0'} \le\frac{c_i}{c_0} \quad\forall i. }

The test is unchanged by a common positive rescaling of every scale and coefficient.

3. Economic consequence

Derivation: Why the Condition Protects LP Backing.

The ratio test and the normalized balance identity imply

iPiaia0iPiaia0.\boxed{ \frac{\sum_i P_i a_i'}{a_0'} \ge\frac{\sum_i P_i a_i}{a_0}. }

The ending Reserve basket per LP Token cannot be worth less at opening Reserve prices.

The proof uses

1isis0(ai/a0ai/a0)es1 \le \sum_i\frac{s_i}{s_0} \left(\frac{a_i'/a_0'}{a_i/a_0}\right)^{e_s}

and Jensen's inequality for the concave function xesx^{e_s}.

4. Composition

Derivation: Composition.

If every primitive action satisfies the ratio test, then every finite sequence satisfies

cifinalc0finalciinitialc0initial\frac{c_i^{\mathrm{final}}}{c_0^{\mathrm{final}}} \le \frac{c_i^{\mathrm{initial}}}{c_0^{\mathrm{initial}}}

for every Reserve Asset. This covers splits, round trips, and subsequent actions within the same closed state model.

5. Operation classifier

Derivations: supported closed-system operations and general externally owned Surplus safety.

OperationEndpoint behaviorResult
Atomic mm-to-nn swap, m+nNm+n\le NReserve coefficients fixed; a0a_0 fixed; derived s0s_0 does not decreaseSafe
Proportional m1m\leftrightarrow1 liquidity, m<Nm<NParticipating ratios unchanged; complement ratios multiply by 0<λ<10<\lambda<1Safe
Admissible unequal m1m\leftrightarrow1 liquidity, m<Nm<NSame ratio behavior when the dispersion condition gives λ>0\lambda>0Safe
Proportional N1N\leftrightarrow1 liquidityEvery ai/a0a_i/a_0 and ci/c0c_i/c_0 is unchangedSafe
Pure externally owned Surplus saleNo price-forming coordinate changesNeutral
Mixed externally owned Surplus saleIndependent Reserve fractionsTest the complete Reserve endpoint

6. Swap check

Derivations: post-trade value flow and finite-step scale accretion.

For a swap, every Reserve coefficient remains fixed and LP Token supply does not change. Post-trade value flow gives

idaiPi=0.\sum_i da_iP_i'=0.

Concavity gives

s0=ici(ai)esiciaies=s0.s_0'=\sum_i c_i(a_i')^{e_s}\ge\sum_i c_i a_i^{e_s}=s_0.

Thus c0c_0' does not fall while every cic_i is fixed, so every ci/c0c_i/c_0 satisfies the safety test.

7. Liquidity check

Derivations: LP Token liquidity actions, liquidity admissibility and dispersion, and partial multi-asset liquidity.

For an m1m\leftrightarrow1 liquidity action, participating Reserve Assets and the LP Token remain on their elastic curves:

ci=cic_i'=c_i

for participating ii, and

c0=c0.c_0'=c_0.

When m<Nm<N, every nonparticipating Reserve Asset receives the common complement multiplier

cj=λcj.c_j'=\lambda c_j.

Admissibility requires

λ>0.\lambda>0.

For a proper participating subset, an admissible nontrivial action has λ<1\lambda<1. Participating ratios are unchanged and every complement ratio decreases.

For proportional participating deposits or withdrawals,

r1=r2==rm,r_1=r_2=\cdots=r_m,

and every proper subset m<Nm<N satisfies the dispersion condition. This enables proportional mm-to-11 liquidity provision without requiring all NN Reserve Assets.

When m=Nm=N, admissibility requires full proportionality. Every Reserve and LP Token amount changes by the same factor, so every projective coordinate is unchanged. Absolute prices may move together, but relative LP Token prices

P0,i=P0PiP_{0,i}=\frac{P_0}{P_i}

remain unchanged.

8. Journal-entry gate

Derivation: Per-Entry Safety Procedure.

Before applying the ratio test:

  1. write every equal-amount debit and credit inside its own token ledger;
  2. identify entries touching (ai,si)(a_i,s_i) for every ii, including i=0i=0;
  3. retain all journals, but remove exact same-token matched price-taking asset--liability pairs from the repricing calculation;
  4. calculate one complete atomic endpoint; and
  5. enforce positivity, operation-specific admissibility, and the ratio inequalities.

Accounting balance is mandatory but does not determine the safety direction by itself.

9. Scope

The proof applies directly to the exact-arithmetic claim-free Reserve--LP system and to open actions whose external accounts cancel as exact same-token matched pairs. Independently priced claims, unmatched liabilities, administrative changes to price-forming state, fees, and fixed-point rounding require explicit extensions and tests.