Issue a simple loan on the deployed ACTUS Protocol contracts and progess its state
Scenario
This guide covers a simple workflow for off-chain order creation and on-chain issuance & settlement. The creator forges "orders" that represent offers to go into contractual relationship with a counterparty under specified terms. These orders could be used to create a simple OTC market.
In the scenario we have a creator, which is the lender and a counterparty which takes the role of the debtor. An order for a loan of 1000 DAI at 5% annual interest is created. The debtor countersigns the order and submits it to the blockchain.
In this guide you will:
Define the terms of the asset
Issue the asset through ACTUS Protocol
Service the asset by paying the principal of the loan to the debtor (counterparty)
First, set yourself as the creator, optionally set the address for the counterparty (the party that will take out the loan) if you know it in advance and choose a template from the available templates.
import{AP}from'@atpar/protocol';// -------------------------------------------------------------// refer to the "Getting started" section for initializing ap.js// -------------------------------------------------------------constcreator= (awaitweb3.eth.getAccounts())[0];constcounterparty;// address of counterpartyconstanyone= (awaitweb3.eth.getAccounts())[2] // used to make calls that could be made by any address// Terms for a simple PAM-based loan with monthly interest paymentsconstPAMTerms=require('./terms.json');constterms={...PAMTerms,currency:'<ADDRESS>'// address of ERC20 token to use as settlement currency}
Set up the asset initialization parameters:
Use the appropriate Asset Actor contract (in our case the PAMActor) to initialize and register the new asset on chain:
Maintaining the asset
Now the lender has to pay the principal of the loan to the debtor. The lender has to set sufficient allowance for the AssetActor, such that the Actor contract can transfer the principal amount to the borrower on the lenders behalf. If the AssetActor is not able to transfer the principal (e.g. due to insufficient allowance or insufficient funds) the Actor contract will transition the asset to non-performing (risking additional penalty payments or contract default).
// set up ownership structure
const ownership = {
creatorObligor: creator, // has to fulfill all obligations for the creator side
creatorBeneficiary: creator, // receives all positive cash flow of the creator side
counterpartyObligor: counterparty, // has to fulfill all obligations for the counterparty
counterpartyBeneficiary: counterparty, // receives all positive cash flow for the counterparty
}