PWN LOAN

1. Summary

The PWNLOAN.sol contract is an ERC-721 that represents a loan in the PWN protocol. The PWN LOAN token is shared between all loan contracts.

3. Contract details

  • PWNLOAN.sol is written in Solidity version 0.8.16

Features

  • Minting and burning of the LOAN token

Inherited contracts, implemented Interfaces and ERCs

Functions

mint

Overview

When a loan is started in the PWN Protocol the Loan contract mints a LOAN token for the lender.

Only Loan contracts that are tagged as active in the PWN Hub can mint new LOAN tokens.

This function takes one argument supplied by the caller:

  • addressowner - Address of the LOAN token receiver

Implementation

function mint(address owner) external onlyActiveLoan returns (uint256 loanId) {
    loanId = ++lastLoanId;
    loanContract[loanId] = msg.sender;
    _mint(owner, loanId);
    emit LOANMinted(loanId, msg.sender, owner);
}
burn

Overview

A Loan contract calls this function when a lender claims repayment or defaulted collateral.

This function takes one argument supplied by the caller:

  • uint256loanId - ID of the LOAN token to be burned

Implementation

function burn(uint256 loanId) external {
    if (loanContract[loanId] != msg.sender)
        revert InvalidLoanContractCaller();

    delete loanContract[loanId];
    _burn(loanId);
    emit LOANBurned(loanId);
}

View Functions

tokenURI

Overview

Returns URI for a supplied token ID based on the Loan contract that minted the token.

This function takes one argument supplied by the caller:

  • uint256tokenId - ID of the LOAN token to get a token URI for

Implementation

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
    _requireMinted(tokenId);

    return IPWNLoanMetadataProvider(loanContract[tokenId]).loanMetadataUri();
}
getStateFingerprint

Overview

This function returns the current token state fingerprint for a supplied token ID. See ERC-5646 standard specification for more detailed information.

This function takes one argument supplied by the caller:

  • uint256tokenId - ID of the LOAN token to get a fingerprint for

Implementation

function getStateFingerprint(uint256 tokenId) external view virtual override returns (bytes32) {
    address _loanContract = loanContract[tokenId];

    if (_loanContract == address(0))
        return bytes32(0);

    return IERC5646(_loanContract).getStateFingerprint(tokenId);
}

Events

The PWN Safe Factory contract defines one event and no custom errors.

event LOANMinted(uint256 indexed loanId, address indexed loanContract, address indexed owner);
event LOANBurned(uint256 indexed loanId);
LOANMinted

LOANMinted event is emitted when a new LOAN token is minted.

This event has three parameters:

  • uint256 indexedloanId - ID of the minted LOAN token

  • address indexedloanContract - Address of the loan contract that minted this LOAN token

  • address indexedowner - Address of the minted LOAN token receiver

LOANBurned

LOANBurned event is emitted when a LOAN token is burned.

This event has one parameter:

  • uint256 indexedloanId - ID of the burned LOAN token

Last updated