Skip to content

Loan and Decentralized Tokenization

Jouzo edited this page Dec 15, 2021 · 20 revisions

Interacting with Defichain loans requires multiple steps. Please refer to the pinkpaper to understand the different concepts such as :

  • Collateral requirements
  • Liquidation
  • Auctions

This tutorial will teach you how to create a vault, take and payback a loan, and bid on an auction through the command line interface.

Create a vault

Prerequisites

  • 2 DFI as UTXO in wallet required
  • 1 DFI fee for vault creation, 1 converted to collateral transparently, which is reclaimed on closevault.
defi-cli createvault <ownerAddress> <loanSchemeId>

List collaterals

defi-cli listcollateraltokens

Send collaterals to address

defi-cli utxostoaccount '{"<address>":"<amount(`value@token`)>"}'

Deposit to vault

Prerequisites

  • Any DFI address with collaterals
defi-cli deposittovault <vaultId> <address> <amount(`value@token`)>

List loan tokens

List all available tokens to take a loan from.

defi-cli listloantokens 

Take a loan

Prerequisites

defi-cli takeloan '{"vaultId":"<vaultId>", "amounts":"<amount(`value@token`)>"}'

Payback loan

Prerequisite

  • Any DFI address with enough loan tokens to payback loan
defi-cli paybackloan '{"vaultId":"<vaultId>", "from":"<DFI Address>","amounts":"<amount(`value@token`)>"}'

Withdraw collaterals from vault

Prerequisite

  • Enought collaterals to keep collateralization ratio above the one defined by the chosen loan scheme after withdrawal
  • To withdraw all collaterals, there should not be any active loans in vault
defi-cli withdrawfromvault <vaultId> <address> <amount(`value@token`)>

Loan utility functions

Get general loan informations

defi-cli getloaninfo

List collateral tokens

defi-cli listcollateraltokens     

List loan tokens

defi-cli listloantokens

List all available loan schemes

defi-cli listloanschemes

Get loan scheme

defi-cli getloanscheme <loanSchemeId>

Get interest info

defi-cli getinterest <loanSchemeId>

Vault utility functions

Get a vault

defi-cli getvault <vaultId>

Update a vault

defi-cli updatevault <vaultId> '{"ownerAddress":"<address>", "loanSchemeId":"<loanSchemeId>"}'

List vaults

Use listvaults to get all vaults owned by an address

defi-cli listvaults '{"ownerAddress":"<address>"}'

Close vault

Prerequisites

  • Any DFI address to receive collaterals (if any) and half of creation fee back (other half is burnt).
defi-cli closevault <vaultId> <address>

Auctions

List available auctions

defi-cli listauctions

Bid on an auction

Prerequisite

  • An address with same loan token as the auction to bid on.
  • For the first bid, enough loan token to pay the 5% penalty.
  • For subsequent bid, enough loan token to bid 1% more than previous bid.

Choose an available auction from listauctions and select a batch to bid on.

defi-cli <vaultId> <batchIndex> <address> <amount(`value@token`)>

Example

defi-cli listauctions
[
  {
    "vaultId": "0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad",
    "liquidationHeight": 688140,
    "batchCount": 6,
    "liquidationPenalty": 5.00000000,
    "batches": [
      {
        "index": 0,
        "collaterals": [
          "2499.99985521@DFI"
        ],
        "loan": "7.73944830@TSLA"
      },
      {
        "index": 1,
        "collaterals": [
          "2499.99985521@DFI"
        ],
        "loan": "7.73944830@TSLA"
      },
      {
        "index": 2,
        "collaterals": [
          "2499.99985521@DFI"
        ],
        "loan": "7.73944830@TSLA"
      },
      {
        "index": 3,
        "collaterals": [
          "2499.99985521@DFI"
        ],
        "loan": "7.73944830@TSLA"
      },
      {
        "index": 4,
        "collaterals": [
          "2499.99985521@DFI"
        ],
        "loan": "7.73944830@TSLA"
      },
      {
        "index": 5,
        "collaterals": [
          "2359.00072395@DFI"
        ],
        "loan": "7.30294608@TSLA"
      }
    ]
  }
]

Select the vault on which you want to bid on. In that case, 0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad. You can now call getvault to limit information about the vault you are bidding on.

defi-cli getvault 0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad
{
  "vaultId": "0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad",
  "loanSchemeId": "C150",
  "ownerAddress": "tmMQoUP9tvyFXQyV24jzzBB9yxdWjUkoqP",
  "isUnderLiquidation": true,
  "invalidPrice": false,
  "batches": [
    {
      "index": 0,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 1,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 2,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 3,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 4,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 5,
      "collaterals": [
        "2359.00072395@DFI"
      ],
      "loan": "7.30294608@TSLA"
    }
  ]
}

Choose the first batch to bid on. Loan value is 7.73944830@TSLA so first bid should be at least 8.12642071@TSLA(7.73944830 * 1.05) to pay for the 5% penalty.

defi-cli placeauctionbid 0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad 0 tmMQoUP9tvyFXQyV24jzzBB9yxdWjUkoqP "8.12642071@TSLA"

You can now call getvault again to check your bid. In order to check that your bid went through and not someone else's, you have to check that highestBid.owner corresponds to the address in your last placeauctionbid.

defi-cli getvault 0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad
{
  "vaultId": "0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad",
  "loanSchemeId": "C150",
  "ownerAddress": "tmMQoUP9tvyFXQyV24jzzBB9yxdWjUkoqP",
  "isUnderLiquidation": true,
  "invalidPrice": false,
  "batches": [
    {
      "index": 0,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA",
      "highestBid": {
         "owner":"tmMQoUP9tvyFXQyV24jzzBB9yxdWjUkoqP",
         "amount": "8.12642071@TSLA"
       }
    },
    {
      "index": 1,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 2,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 3,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 4,
      "collaterals": [
        "2499.99985521@DFI"
      ],
      "loan": "7.73944830@TSLA"
    },
    {
      "index": 5,
      "collaterals": [
        "2359.00072395@DFI"
      ],
      "loan": "7.30294608@TSLA"
    }
  ]
}

On subsequent bid, you have to bid at least 1% more than the previous bid. In that case, 8.20768491@TSLA (8.12642071 * 1.01)

defi-cli placeauctionbid 0e192e78919f947a6a45f5bad1c679402612d1e5e6541333874089d9d238b2ad 0 tmMQoUP9tvyFXQyV24jzzBB9yxdWjUkoqP "8.20768491@TSLA"

Once the auction period is over, you can call listauctionhistory to check your won auctions.

defi-cli listauctionhistory