@swapnet-finance/sdk

Swapnet Lite SDK


Keywords
swapnet, lite, defi, ethereum
License
MIT
Install
npm install @swapnet-finance/sdk@0.0.1

Documentation

Introduction

Swapnet Lite is a protocol that enables fixed rate, fixed term borrowing and lending of crypto-native assets. Swapnet Lite was designed to be simple where possible, and rigorous where necessary. The protocol gives users the ability to borrow or lend Dai at a fixed rate for their choice of a set of different maturities. Once a user chooses a maturity and initiates the loan, the interest rate is fixed for the entire term - goodbye interest rate volatility!

Lending on Swapnet Lite is easy. Pick the maturity and interest rate that you like the most and exchange your Dai for “future Dai” (more on this below). Once that future Dai matures just redeem it on Swapnet Lite for your principal + interest!

Borrowing on Swapnet Lite is simple too. First deposit ETH as collateral for your loan and then pick your maturity. Initiate your borrowing and monitor your collateralization level over the course of the loan, topping up where necessary. When the loan comes due, either deposit the principal + interest on Swapnet Lite and settle your loan, or Swapnet Lite will liquidate your collateral and settle the loan on your behalf.

System Mechanics

Swapnet Lite achieves fixed rate borrowing and lending with the help of a few core constructs. It starts with future cash. Future cash is a construct that allows the protocol to define and manipulate movements of value, or cash flows, at exact points in the future. This concept enables users to create and trade entitlements to receive value and obligations to supply value in the future.

Future Cash

Future cash refers to a class of ERC1155 tokens defined on Swapnet Lite. A future cash token is defined by an underlying collateral token, a maturity block, and a binary Payer/Receiver flag. For example, "Dai_1000_receiver" refers to future Dai receiver tokens that mature on block 1000. A Dai_1000_receiver token has the following essential property: it is redeemable on the Swapnet Lite platform for one Dai token at any time after or on block 1000.

Future Cash Payers vs Future Cash Receivers

The concept of future cash is split into two sub-categories, future cash payers and future cash receivers. A future cash receiver is a token that entitles its owner to one underlying collateral token upon maturity. A future cash payer is the offsetting token - it obligates its owner to supply one underlying collateral token to the protocol upon maturity.

Swapnet Lite ensures the redeemability of future cash receiver tokens by maintaining one-to-one balance between future cash receivers and future cash payers, and proper collateralization of all future cash payers. Whenever a future cash receiver token is minted, an offsetting future cash payer is also minted. Whenever a future cash receiver is redeemed, an offsetting future cash payer is burned..

Current Cash

Swapnet Lite uses an internal accounting concept called current cash. Current cash refers to an underlying collateral currency like Dai. One current cash token is redeemable for one token of its underlying collateral currency on Swapnet Lite at any time.

Lending

A user can lend on Swapnet Lite by depositing collateral and exchanging it for future cash. Consider the following example:

A user deposits 100 Dai onto Swapnet Lite and exchanges that Dai for 101 future Dai maturing in 175,000 blocks (approximately one month). This user is therefore guaranteed to receive 101 Dai in one month's time. In other words, they have just lent 100 Dai for a term of one month at an annualized interest rate of 12%.

Borrowing

A user can borrow on Swapnet Lite by depositing collateral, generating a future cash token pair, and then exchanging the future cash receiver for collateral. Consider the following example:

A user deposits 2 ETH onto Swapnet Lite and mints 100 future Dai payers and receivers maturing in 175,000 blocks (approximately one month). The user is sufficiently collateralized because the current ETH/Dai exchange rate is 100 (see Collateralization below). The user then exchanges their 100 future Dai receivers for 99 Dai and withdraws those Dai from the system. This user is then left with 100 future Dai payers and 2 ETH to collateralize that obligation. This is equivalent to borrowing 99 Dai for one month at an annualized interest rate of approximately 12.1%.

Trading

Trading on Swapnet Lite is done via Uniswap-like pools. Swapnet Lite will host a trading pool between an underlying collateral currency and future cash receiver tokens for each maturity within the accepted maturity set. This is how future cash receiver tokens are exchanged for collateral during the course of borrowing or lending on Swapnet Lite.

Collateralization

Swapnet Lite enables users to commit to making payments at specified times in the future. The protocol uses a collateralization framework to ensure that these commitments are credible.

Haircuts

When calculating the value of an account’s holdings for the purposes of collateralization checks, the protocol will apply a discount to every collateral asset that reflects the riskiness of that asset, or the magnitude by which its value relative to Dai is likely to change. This discount is known as a haircut. Haircuts ensure that there is ample time for an account to be liquidated before a market move pushes it into insolvency.

Free Collateral

A core concept in Swapnet Lite is free collateral. Free collateral is defined as any excess value that an account holds beyond what it needs to collateralize its obligations. Consider the following example:

Account holdings

  • 1 ETH
  • 165 Dai_1000_receivers
  • 180 Dai_2000_payers

Exchange rates

  • Dai/Dai_1000 - 1.1
  • Dai/Dai_2000 - 1.2
  • ETH/Dai - 100

Haircuts

  • Dai_1000 - 1%
  • ETH - 30%

Dai Value of Assets Post-Haircut

  • ETH - 70 (100 * .7)
  • Dai_1000 - 148.5 (165 / 1.1 * .99)

Dai Value of Liabilities

  • Dai_2000 - 150 (180 / 1.2)

Free Collateral = 68.5 (218.5 - 150)

Liquidation

When an account’s free collateral drops below 0 it can be liquidated. Swapnet Lite’s liquidation procedure reduces an account’s obligations until it returns the account back to sufficient collateralization levels. Let’s reprise the above example with slightly different values:

Account holdings

  • .65 ETH
  • 110 Dai_1000_receivers
  • 180 Dai_2000_payers

Exchange rates

  • Dai/Dai_1000 - 1.1
  • Dai/Dai_2000 - 1.2
  • ETH/Dai - 100

Haircuts

  • Dai_1000 - 1%
  • ETH - 30%

Dai Value of Assets Post-Haircut

  • ETH - 45.5 (65 * .7)
  • Dai_1000 - 99 (110 / 1.1 * .99)

Dai Value of Liabilities

  • Dai_2000 - 150 (180 / 1.2)

Free Collateral = -5.5 (144.5 - 150)

Now this account is under-collateralized and can be liquidated.

Liquidation Procedure

When an account is liquidated, Swapnet Lite calculates the account's collateral shortfall (denominated in Dai) and proceeds to sell off its assets to cover that shortfall. The protocol first liquidates the account's ETH and then proceeds to liqudate the account's future cash and liquidity tokens if the the protocol was unable to raise sufficient Dai from the account's ETH.

Settlement

Settlement describes the process of transforming future cash to current cash and current cash to collateral.

Settling Future Cash to Current Cash

The first step in the settlement process is to transform future cash that has matured into current cash. The “settle” function iterates through an account’s portfolio and removes any future cash or liquidity tokens that have matured and updates the account’s current cash balance accordingly.

Settling Current Cash to Collateral

The second step is to settle current cash to collateral. An account with a positive (negative) current cash balance must find an account that has an offsetting negative (positive) cash balance to settle against. Such an account will exist - by construction all cash balances net out to zero on a system-wide basis. It will be incumbent on the user to find an offsetting account.

The user will call “settleCash” and specify an account with an offsetting cash balance. This function will transfer collateral between the accounts and update their current cash balances accordingly.

Providing Liquidity

Users can provide liquidity on Swapnet Lite similar to how they would on Uniswap. Simply deposit Dai and Swapnet Lite will issue the user liquidity tokens in return. These liquidity tokens entitle users to transaction fees generated via borrowing and lending on the Swapnet Lite platform.