-
Neplend Contract can be defined as autonomous and decentralized platform which is used for loan agreement between parties.
-
Neplend is developed to solve the problem which is decrease in credit investment.Thus, it can build healty relationship between parties.
-
NLP token is used for colleteral in the loan agreement. Borrower gives it to platform as a colleteral, if borrower does not pay back this loan within specified time, token will be given to lender automatically.
-
Borrower: Specifes borrower person. She creates loan request.
-
Lender: Specifes lender person. She can funds a loan request.
-
loanId: Id of a loan which is created by borrower.
-
borrowedAsset: The type of asset which is demanded by borrower. (smart contract only supports neo)
-
borrowedAmount: Amount of borrowing.
-
collateralAmount: Amount of NPL tokens which will be pledged as collateral by the borrower. (This amount is locked by the smart contract, after the loan has been funded)
-
premiumAmount: The amount will be paid in addition to the borrowedAmount.
-
daysToLend: Specified time period for the repayment of loan.
-
Borrower creates loan request. Borrower must specify loanId, borrowedloanId, borrowedAsset, borrow amount, premium amount, collateral amount and daysToLend parameters.
-
If the borrower has sufficient NPL tokens for that request, her NPL tokens will be pledges as colleteral.
-
The loan is funded by the lender. After the fund transaction completed, the loan request can not be canceled by the borrower. The collateral tokens remain in the locked status until borrower repays the loan.
-
There are 2 different situations for this step:
-
If the borrower repays the loan, the NPL tokens which has been pledged as collateral will return to the borrower’s account.
-
If the borrower can not repay the loan within specified time period, the NPL tokens which has been pledged as collateral will go to the lender's account.
Status Diagram of the Loan Request in Smart Contract
I made a simple script to explain invoking step by step.
Usage Video https://www.youtube.com/watch?v=1bB2wiDYALQ
Firstly, you should make sure that there are two accounts for borrower and lender. Both of them should have sufficient neo and gas assets. We will invoke smart contract with a nodejs application which uses neon-js
library.
To start invoking, go into nodejs application folder (neplend-node
) and install dependencies.
$ cd neplend-node
$ npm install
Before the following steps, you should change the wif keys of account1(borrower) and account2(lender).
Borrower account should mint NPL tokens for creating loan request. Borrower execute invocationTX with attached neo for minting NPL tokens.
InvocationParameters
operation="mintTokens"
args=[]
Mints 400 NPL Tokens
It creates new loan request.
Invoke Parameters
operation="createLoanRequest"
args=[loadIdHexStr, reverseHexOfBorrowerScriptHash, reverseHexBorrowAssetId, amountBorrowed, amountCollateral, amountPremium, daysToLendUnixTime]
The calling upper function creates a new loan request with the following properties.
BorrowedAsset: Neo
Borrow amount: 6
Collateral NPL Token Amount: 220 NPL
Premium: 1 Neo,
DaysToLend: Specifies time period for the repayment of loan with Unix time format. 86400 seconds equals 1 day.
Note:
- After completion of invocation, take note of the loanId. It can be found in terminal output.
- collateralAmount parameter MUST HAVE zeros in its decimals. For instance, if you want to use 220 NPL as collateral, you should set parameter value to 22000000000. (8 decimals)
The borrower's tokens should be pledges as colleteral.
Invoke Parameters
operation="lockCollateralForLoan"
args=[loanIdHexStr, reverseHexOfBorrowerScriptHash]
Loan can be funded by the lender. A sufficient amount of assets must be sent within a single transaction.
Invoke Parameters
operation="fundLoan"
args=[loanIdHexStr, reverseHexOfLenderScriptHash]
If the borrower wants to repay loan, she must invoke the following invocationTx. Borrower must send required amount (borrowed+premium) asset to the lender. For repaying the loan, borrower must send to required amount within single transaction.
Invoke Parameters
operation="repayLoan"
args=[loanIdHexStr, reverseHexOfBorrowerScriptHash]
account1(borrower), account2(lender)
If the borrower can not repay the loan in the specified time period, the lender put in a claim for collaterals and take them to her account.
Invoke Parameters
operation="claimCollateral"
args=[loanIdHexStr, reverseHexOfLenderScriptHash]
Invoke Parameters
operation="cancelLoan"
args=[loanIdHexStr, reverseHexOfBorrowerScriptHash]
Gets balance of account
Prints loan status
Outputs
Registered:20, CollateralLocked:21, Funded:22, Cancelled:23, CollateralClaimed:24, LoanRepaid:25
The MIT License (MIT)
Copyright (c) 2018 Oguzhan ERGIN
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.