Skip to content

A simple algorithmic stablecoin that prioritizes price accuracy

Notifications You must be signed in to change notification settings

JonahGroendal/inverse-trs

Repository files navigation

Inverse Total Return Swap

A simple crypto derivatives contract for creating fully-collateralized synthetic assets (aka stablecoins) on Ethereum.

Using The Contract

To gain exposure to the denominating asset (e.g. USD), simply buy into the protection buyer pool with buyHedge(amount, to).
To gain leveraged exposure to the reference asset (e.g. ETH), buy into the protection seller pool with buyLeverage(amount, to).
Each operation requires payment in the reference asset and returns a synthetic asset representing your stake in the pool.
You can sell out of either pool at any time with sellHedge(amount, to) and sellLeverage(amount, to).

Deployments

Arbitrum:
  ETH/USD (uses WETH as underlying asset):
    swap: 0x841fA73a7c8CA0B513c60B3DeEEd498dd3b546Ca
    USDᵉᵗʰ (hedge token): 0x77431bce81FD447729713DA82C5aD2aBE9E9a472
    ETHUSD (leverage token): 0xE183a13E641a51c4671dbeE49B3f588A805CADD0

Risks

Not Audited

The code is not audited. Despite the contract's minimal attack surface, I can't guarantee it's safe to use.

Administered

The Swap and Token contracts are administered and upgradeable by me, but they're behind a one-week timelock. This enforces that I must schedule any parameter changes or upgrades a week in advance, giving participants time to exit the system.

Nomenclature

The swap contract is defined by its reference asset and its denominating asset, for example "ETH/USD".

The symbol for the synthetic asset representing the protection buyer pool is its target asset followed by its collateralizing asset in superscript. For the protection seller pool, it's the reference asset followed by the denominating asset.

For example,
ETH/USD hedge token:       USDᵉᵗʰ, or Ether-collateralized synthetic USD
ETH/USD leverage token:  ETHUSD, or Leveraged Ether (USD)

How It Works

The core of the system is the Swap contract. It works similarly to a total return swap in traditional finance, where cashflows are exchanged between two parties based on the performance of a reference asset and a floating interest rate. But rather than the two counterparties being individual companies or people, they're represented as two stake pools, each with its own token.
In addition,

  1. The two stake pools, representing the protection buyers and protection sellers, can be permissionlessly entered into or exited out of at any time.
  2. Payments and collateral (on both sides) are in the reference asset.
  3. Losses and gains are automatically taken from or added to collateral as the price of the reference asset changes.
  4. The contract is reset (i.e. payments are made between stake pools) continuously as the price changes, rather than on predetermined dates (In reality, payments are never "made", but pool sizes are recalculated for each buy or sell). The value of the contract itself is always 0.
  5. The notional principal changes as traders enter or exit the protection buyer pool and as interest payments are made.
  6. The interest rate is a function of the relative size of the two stake pools (i.e. the collateral ratio) rather than an external index such as LIBOR.
  7. The reference asset is an ERC20 token such as WETH or WBTC.
  8. The asset denominating the notinal principal can be any currency, equity, index, etc for which a price feed exists.

Interest Rate

Interest payments are made from the protection seller pool to the protection buyer pool on an hourly basis. Each swap contract has its own variable interest rate, used to target a collateralization ratio by changing the relative demand for the two tokens. Interest payments are automatically reinvested.

Currently, the annual rate (R) is proportional to the contract's collateral ratio (C), and targets a 140-160% collateral ratio at a 0-4% interest rate:

R = 0.2 * C - 0.28

This interest rate model or its parameters may change in the future.

Fees

There's a 0.1% fee on all buys and sells that goes to existing stakeholders. The fee is put into the protection seller pool and, in turn, factored into the interest rate paid to the protection buyer pool via market forces.

Value is conserved within each swap contract. No disbursements of any kind are transferred out.

The fees serve to prevent soft frontrunning, where traders may have advance knowledge of price oracle updates.

Calculating leverage

L = C / (C - 1)

where

L = leverage of the leveraged coin
C = collateralization ratio

and

C = (E + P) / P

where

E = value of protection seller pool
P = The Notional principal / value of protection buyer pool

Composing swaps

The synthetic assets created in one swap can be used as the reference equity/underlying asset in other swaps. In other words, the token outputs of one swap can be used as the token input to others.

Shorting

E.g. use the USDᵉᵗʰ from the ETH/USD swap to create a USDᵉᵗʰ/ETH swap
Creates ETHᵘˢᵈ (USDᵉᵗʰ-collateralized synthetic ETH) and USDETH (Shorted ETH (USD))

ETH -> ETHUSD
              USDᵉᵗʰ -> ETHᵘˢᵈ
                             USDETH

Squaring

E.g. use the ETHUSD created from the ETH/USD swap to create a ETHUSD/USD swap
Creates USDᵉᵗʰᵘˢᵈ and ETHUSD²
Gives more leverage

Multi-Collateral Stablecoin

Create a USDᵇˡᵉⁿᵈ/USD swap where USDᵇˡᵉⁿᵈ is a blend of different synthetic USD assests, such as ones with different collateral types or collateralization ratios.
For example, combine USDᵉᵗʰ and USDˡⁱⁿᵏ into a single USDᵇˡᵉⁿᵈ, and use that as the underlying asset in a USDᵇˡᵉⁿᵈ/USD swap. The resulting USDᵘˢᵈ will be able to hold its peg even if USDˡⁱⁿᵏ or USDᵉᵗʰ (and thus USDᵇˡᵉⁿᵈ) lose their pegs.

Possible Attack Vectors

Frontrunning / Sandwiching

A successful frontrunning attack could steal gains from or, magnify losses of, honest participants, so it's imperative that it's never possible.

Frontrunning Price Oracle Updates

This involves an attacker watching the mempool for a price oracle update then using a MEV auction to insert a buy or sell transaction infront of it to make a risk-free profit from the price change. Because of this possibility, the contrats cannot be deployed on Ethereum L1. Instead they are deployed on Arbitrum One, an L2 where transactions are executed in the order they are received by the sequencer(s).

Soft Frontrunning

In theory it's possible for an attacker to predict a price orace update before the transaction is sent to the sequencer by looking at off-chain data such as prices on centralized exchanges. Trading on this advance price knowledge is sometimes called "soft frontrunning". To mitigate this, every buy or sell has an associated fee that makes a price change of a given amount unprofitable. If, for example, the fee were set to 0.1%, the price would need to change by more than 0.1% for gains to be greater than the trade's fee.

Behavior in Event of Undercollateralization

If the value of the protection seller pool drops to zero, the remaining collateral in the protection buyer pool is split among stablecoin holders. Protection seller tokens can't be minted or burned during this time.

About

A simple algorithmic stablecoin that prioritizes price accuracy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published