Sept. 6, 2022: curve-stablecoin.js π¦π΅
What we can infer about $crvUSD from the newly public Curve repo
Livestream at 8:30 AM PT
The $crvUSD Javascript library, which will connect a frontend to the smart contract infrastructure, is finally public. This gives us the most information yet about $crvUSD, although the backend has yet to launch.
Along with a well documented README file, the repository includes tests for common actions and two ABIs for backend contracts. These ABIs in particular give us the best glimpse into the backend.
Sleuths have already ripped through the codebase and unpacked the details:
Hereβs a list of six things from the codebase that caught our eye.
LLAMMA
The engimatic LLAMMA [sic] reasserts itself prominently in this repo. The name was first leaked by 0xLlam4, where it featured prominently in the redacted copy of the yet-to-be-released white paper.
Yesterday we also received confirmation LLAMMA is an acronym for βLending-Liquidating AMM Algorithm.β
LLAMMA appears frequently throughout the codebase, so we know itβs central to the operation. The repository also contains the full ABI for the actual LLAMMA contract. While we donβt know whatβs going on inside the black box, we know the public endpoints in the contractβs interface.
Of the 44 functions, 9 are state modifying, the remainder are views. These view functions contain a lot of heavy math⦠functions like rate_mul
, get_y_up
, get_sum_xy
, get_dxdy
, sqrt_band_ratio
β¦ we can surmise Curveβs trademark advanced math will be quite prominent within the LLAMMA-verse.
Among the functions that modify the state are:
constructor
initialize
deposit_range
withdraw
exchange
set_rate
set_fee
set_admin_fee
set_price_oracle
In the codebase, this. is abstracted by calling crvUSD.getLlamma(id)
on the crvUSD stablecoin object.
Note the llamma
object has a unique Controller
address. This references the other ABI included in the repository.
The controller contract contains far more modifying functions, and the sorts of functions one might expect from a typical lending protocol: ie create_loan
, add_collateral
, borrow_more
, repay
, liquidate
, et al. When users directly create or manage the loan, they generally do so through the Controller
contract, not directly to the Llamma
contract.
One can extrapolate an architecture in which each form of collateral has a Llamma
contract that runs the higher level math aggregated across all positions. Users can manage their specific position within this Llamma
contract using its associated Controller
contract.
Lending
The first βLβ in llama stands for βLending.β What is being lent?
The only asset referenced throughout this codebase is eth
. Does this mean that $crvUSD will only be backed by Ethereum?
Based on some context clues in the codebase, there is reason to suspect it actually supports a wider range of assets than just ETH. If $crvUSD only accepted ETH, there would be no reason to specify an id
, it would just be hard-coded. The βcollateral tokenβ is a value set in the Controller
constructor, which implies multiple contracts may be deployed and instantiated with different collateral.
Further, we also see a reference in the Controller
contract ABI to a tokens_to_liquidate
function. Such a function might be unnecessary if ETH was the only token to liquidate. Finally, the Curve saave
pool is referenced in the README in what appears to be a typo, possibly a Freudian slip.
The opposing case would be that the functionality to include multiple different LLAMMA ids was included simply to allow room for future expansion. The contract could plausibly launch with ETH as its only collateral, and task the DAO or devs with other future sources.
Otherwise, we see from the README, tests, and Controller
ABI that this functions like a normal lending protocol⦠functions to create a loan, add collateral, borrow more, repay, or check loan health.
Thereβs also a function in the Controller
ABI called βset_monetary_policyβ that sounds interesting but is not referenced elsewhere.
Liquidation
Previous leaks describe that the stablecoin will feature a βnovel liquidation mechanism.β Yesterdayβs code drop doesnβt provide too much detail on liquidation mechanics, but we can note at least two liquidation mechanisms.
First is triggering a liquidation externally. The example demonstrates a random account triggering a liquidation on an account with 2751 $crvUSD and >$3K in debt. The liquidator appears to be any account that closes the position and receives the collateral.
The other liquidation mechanism described is βself-liquidation,β in which the user deposits the missing balance and receives their collateral.
Several other protocols use such mechanisms, so this doesnβt yet fit the category of βnovelβ liquidation mechanism. However, perhaps the next functionality detailed offers a bit of a clue.
Swap
One feature that may be unique to the $crvUSD functionality is the fact that it includes a native βswapβ feature. This is demonstrated in which a user calls a series of swap functions which adjusts their stablecoin/collateral balance:
This appears to be a prominent feature, in that thereβs significant functionality built into the ABIs and the frontend to manage this. This includes functions for measuring the price impact of making these swaps, calculating the outputs, and protecting against possible slippage.
Here we start to see how an AMM fits into LLAMMA.
Oracle
Curve has never relied on external price oracles, but several times throughout the codebase the LLAMMA is referencing oracle prices or setting oracle contracts. Both ABIs reference an oracle. The templates pay particular attention to whether the oracle price is increasing or decreasing.
Will Curve be utilizing Chainlink for oracle pricing? Curve v2 pools? A new mechanic? Very unclear at this point.
Ticks/Bands
Throughout the repository we see frequent references to βticksβ and βbands.β The LLAMMA ABI has a function to allow you to βdeposit_range.β This concept is quite fundamental to establishing a loan:
We observe in the stats the bands (perhaps a related concept):
Observe above band 11 all balances are fully collateral. The active band (11) has a mix of collateral and stablecoin.
This seems to evoke Uniswap v3 price ranges, and may offer a clue about some of the mechanics under the hood. Carving up prices into ranges may be a core feature of $crvUSD to keep an eye on going forward.
Disclaimers! Note: Although author has seen the full white paper, this article contains no alfa beyond what has been presented publicly. Author also hates Javascript, so may have butchered some details.