Risk Marketplace

DEX providing liquidity for the SMART Tokens

The Risk Marketplace is a weighted constant product automated market maker (AMM) that enables decentralized token trading. It is a fork of Balancer V1, significantly modified for the specific use case of The Risk Protocol. The DEX supports two main types of swaps: standard swaps and split-and-swap operations.

1. Types of Swaps

  • Standard Swap: Users can trade between underlying assets and the SMART tokens within customized elastic supply pools.

  • Split and Swap: This function allows users to deposit the underlying token and simultaneously swap one of the resulting SMART tokens for the other in a single, atomic transaction. This is particularly useful for traders who prefer to hold only one type of SMART token.

2. Core Mechanism

The Risk Marketplace uses a weighted constant product invariant to determine token prices and swap outputs. Unlike traditional constant product AMMs (x × y = k), it extends the formula to support multiple tokens with customizable weights:

i=1nBiWi=k\prod_{i=1}^{n} B_i^{W_i} = k

Where:

  • BiB_i = Balance of token (i) in the pool

  • WiW_i = Normalized weight of token (i)

  • kk = Invariant (remains constant during swaps)

This design allows pools to hold 2-8 tokens with arbitrary weight distributions (e.g., 80/20, 60/20/20), enabling more capital-efficient exposure to specific assets.


Spot Price

The spot price between any two tokens in the pool is derived from their balance and weight ratios:

SPio=Bi/WiBo/Wo11LPFeeSP_{i}^{o} = \frac{B_i / W_i}{B_o / W_o} \cdot \frac{1}{1 - LPFee}

Where:

  • BiB_i: Balance of token i, the token being sold by the trader (going into the pool).

  • BoB_o: Balance of token o, the token being bought by the trader (coming out of the pool).

  • WiW_i: Weight of token i.

  • WoW_o: Weight of token o.


3. Swap Calculations

3. a) Output Given Input (Exact In)

When a user specifies an exact input amount, the output is calculated as:

Ao=Bo(1(BiBi+Ai(1LPFee))WiWo)A_o = B_o \cdot \left(1 - \left(\frac{B_i}{B_i + A_i \cdot (1 - \text{LPFee})}\right)^{\frac{W_i}{W_o}}\right)

Where:

  • AoA_o: Output token amount

  • AiA_i: Input token amount

  • Bi,BoB_i, B_o: Pool balances for tokens (i) and (o), respectively

  • Wi,WoW_i, W_o: Weights of tokens (i) and (o)

3. b) Input Given Output (Exact Out)

When a user specifies an exact output amount, the required input is:

Ai=Bi((BoBoAo)WoWi1)1LPFeeA_i = \frac{B_i \cdot \left(\left(\frac{B_o}{B_o - A_o}\right)^{\frac{W_o}{W_i}} - 1\right)}{1 - \text{LPFee}}

Where:

  • AiA_i: Input token amount needed

  • AoA_o: Desired output token amount

  • Bi,BoB_i, B_o: Pool balances for tokens (i) and (o), respectively

  • Wi,WoW_i, W_o: Weights of tokens (i) and (o)

Last updated