Composable Pricing Logic

How Arcadia values complex composed assets on-chain using recursive decomposition. The Registry coordinates pricing by breaking composed tokens into underlying assets via Asset Modules, each implement

Source: Arcadia Finance Blogarrow-up-right

Borrowing against Staked vAMM USDC/AERO? Possible with Arcadia Finance! But how do we value such complex and composed assets? Spoiler alert, we purposely use Reentrance! Let's dive in!

With Arcadia Finance, we have built infrastructure and tooling to manage and collateralise active on-chain assets (composed tokens).

In order to use these active assets as collateral, we must know their value on-chain, 24/7. Unfortunately, directly using e.g. Chainlink oracles for these assets is not feasible. There are already 684,243 Liquidity Positions for Uniswap V3 on mainnet alone, these cannot all have their own price feed.

Instead, Arcadia relies on the composability of DeFi and uses a recursive process to break down each composed asset in its underlying assets.

Before we go into detail how this is done, a brief 101 on what composability actually is.

Composability

Composed protocols

Composability in DeFi refers to the ability of different financial protocols to integrate seamlessly and interact atomically with one another.

Developers can create new financial products by combining existing protocols, without needing any permissions or modifications of the underlying protocols. It is for this reason that DeFi protocols are sometimes referred to as financial lego blocks.

Take as example a lending protocol (e.g. Aave) and a Decentralised exchange (e.g. Uniswap). For both, a WETH - USDC market exists (to borrow one against the other, or to swap one into the other). We can combine both and create a new protocol, which is composed of both underlying protocols, where users can take leveraged positions (e.g. DeFi Saver).

Composed assets

Similarly, tokens (ERC20, ERC721, ERC4626...) can be composed of other tokens. When you deposit two ERC20 tokens in a Uniswap V2 Liquidity pool, you receive LP-tokens (ERC20) in return, representing the total share of liquidity of the pool you own.

These can be further deposited in for instance staking contracts, to incentivise Liquidity Providers with additional staking rewards. The staked position is non-fungible (when you stake two equal amounts of LP tokens at different times, a different amount of staking rewards will be earned) and can be represented with an ERC721 token.

The resulting staked position could in turn be used by third protocols and so forth (money legos right...).

Arcadia's Approach: Simplifying DeFi

All interactions with DeFi protocols can be simplified as the conversion of one set of tokens into another set of tokens. We can use this to abstract any DeFi protocol as a deterministic transformation: f()f(), that converts "Token(s) In" into "Token(s) Out".

Hence for composed assets, we can use the inverse of this transformation: f1()f^{-1}(), to calculate what the underlying "Token(s) In" are, for a given "Token Out".

In Arcadia we use this process recursively to break down an asset in its underlying assets, which, in turn, can be further broken down into their underlying assets and so on. The recursion stops when the underlying asset cannot be further broken down.

Example: a staked Aerodrome WETH-USDC pool:

The staked position has as underlying assets the Liquidity position and the AERO rewards (a Primary Asset). The Liquidity position is further composed of both WETH and USDC (two primary assets).

Arcadia Registry and Asset Modules

The Arcadia Protocol consists of a main coordinating smart contract (The Arcadia Registry) and multiple append-only Modules.

The Arcadia Registry coordinates the recursion to value assets. It knows for each asset which Asset Module to use.

Each Asset Module is a separate smart contract, with the pricing logic for a specific Asset type (e.g. a Uniswap V3 Liquidity Position, A-tokens...).

To value a certain amount of a composed asset, the Asset Module has to:

  1. Decompose the asset in its underlying assets (the inverse transformation f1()f^{-1}() as previously defined).

  2. Calculate the values of the corresponding underlying asset amounts.

  3. Sum the values of its underlying assets.

The Asset Module luckily does not have to implement the pricing logic for each Underlying Asset, it can just ask the Arcadia Registry what the values are for each of the Underlying Assets — long live Reentrance!

This goes on until the underlying asset is not composed of any other assets (also referred to as Primary Assets), and we use an on-chain Oracle to determine its value.

While this recursive process may look complex, only one function per Asset Module (no matter what type of asset) has to be implemented: the conversion f1()f^{-1}() of an amount of the composed token into the amounts of its underlying tokens.

All other steps are orchestrated by the Registry, and had to be implemented just once!

Benefits

  • No need to duplicate logic (and introduce bugs) when an asset is an underlying asset for multiple composed assets.

  • Multiple layers of composability add no extra work/complexity. If we can value Uniswap V3, Aave pools and USDC, we can immediately value aUSDC-USDC liquidity pools.

  • Scales with assets that have a lot of valid combinations of underlying assets (e.g. per two ERC20 tokens there are 4 valid Uniswap V3 pools) since we do not have to add all individual pools.

Downsides

  • Gas usage: Asset modules have to adhere to a fixed standard, additional overhead in many cases. Only deployable on L2s (post Dencun). Sometimes the same logic/calculations are done redundantly.

  • Layering risks: Every additional underlying asset increases the potential of bugs and rounding errors will multiply with every additional layer. Each Creditor can set a maximum to the number of recursive calls made.

To summarise, when we want to add assets of a new protocol, we have to develop a new Asset Module. To value the assets, we just have to implement a single function: the conversion of an amount of the composed token into the amounts of its underlying tokens.

In reality Asset Modules do more than pricing assets, they also do some risk management e.g. ensuring that LPs are not over-exposed to certain assets or protocols.

Last updated