PWN LOAN

1. Summary

PWN LOAN is a PWN contextual extension of a standard ERC-1155 token. Each LOAN is defined as an ERC-1155 NFT. The PWN LOAN contract allows for reading the contextual information of the loans (like status, expirations, etc.) but all of its contract features can only be called through the PWN contract.

3. Contract Details

  • PWNLOAN.sol contract is written in Solidity version 0.8.4

LOAN token lifecycle

The PWN LOAN token is a tokenized representation of a loan that can aquire different states:

  • Dead/None - Loan is not created or has been claimed and can be burned.

  • Running - Loan is created by passing offer data and offer signature signed by a lender.

  • Paid back - Loan has been fully paid back before the expiration date. The LOAN owner is able to claim lent credit + interest.

  • Expired - Loan had not been fully paid back before expiration date. LOAN owner is able to claim collateral.

State diagram

Loan token struct

Each LOAN token is defined by the LOAN token struct.

LOAN token struct has the following properties:

TypeNameComment

uint8

status

address

borrower

Address of the borrower - stays the same for entire lifespan of the token

uint32

duration

Loan duration in seconds

uint40

expiration

Unix timestamp (in seconds) setting up the default deadline

MultiToken.Asset (see Asset struct)

collateral

Asset used as a loan collateral. Consisting of another Asset struct defined in the MultiToken library

MultiToken.Asset (see Asset struct)

asset

Asset to be borrowed by lender to borrower. Consisting of another Asset struct defined in the MultiToken library

uint256

loanRepayAmount

Amount of LOAN asset to be repaid

Functions

This contract inherits from the ERC-1155 token standard. This comes with all of the ERC-1155 functionalities like transfers etc. Please read the ERC-1155 specification for more details.

View functions

Functions that don't modify the state of the contract. These functions are used to get information about the LOAN token.

getStatus

Returns LOAN status number. To understand what different status means please refer to state diagram above.

This function takes one argument:

  • uint256_loanId - Loan id

getExpiration

Returns the exact expiration time of a particular LOAN as a unix timestamp in seconds.

This function takes one argument:

  • uint256_loanId - Loan id

getDuration

Returns loan duration period of particular LOAN in seconds.

This function takes one argument:

  • uint256_loanId - Loan id

getBorrower

Returns borrower address of particular LOAN.

This function takes one argument:

  • uint256_loanId - Loan id

getCollateral

Returns collateral asset of a particular LOAN. By asset we mean Asset struct described in MultiToken.

This function takes one argument:

  • uint256_loanId - Loan id

getLoanAsset

Returns loan asset of particular LOAN. By asset we mean Asset struct described in MultiToken.

This function takes one argument:

  • uint256_loanId - Loan id

getLoanRepayAmout

Returns loan repay amount of a particular LOAN.

This function takes one argument:

  • uint256_loanId - Loan id

isRevoked

Utility function to find out if offer is revoked. Returns a boolean.

This function takes one argument:

  • bytes32_offerHash - Hash of the offer struct

Events

PWNLOAN contract defines four events and no custom errors.

event LOANCreated(uint256 indexed loanId, address indexed lender, bytes32 indexed offerHash);
event OfferRevoked(bytes32 indexed offerHash);
event PaidBack(uint256 loanId);
event LOANClaimed(uint256 loanId);

LOANCreated

LOANCreated event is emitted when a borrower accepts an offer.

This event has three parameters:

  • uint256 indexedloanId - The ID of the LOAN token

  • address indexedlender - Address of the lender

  • bytes32 indexedofferHash - EIP-712 computed hash of the offer struct

OfferRevoked

OfferRevoked event is emitted when a lender decides to revoke an offer.

This event has one parameter:

  • bytes32 indexedofferHash - EIP-712 computed hash of the offer struct

PaidBack

PaidBack event is emitted when a borrower repays a loan.

This event has one parameter:

  • uint256loanId - The ID of the LOAN token

Lenders can listen to this event to get notified when their loan has been paid back.

LOANClaimed

LOANClaimed event is emitted when a lender claims the repaid amount or loan underlying collateral in case of a default.

This event has one parameter:

  • uint256loanId - The ID of the LOAN token

Last updated