Developer Docs
AppGitHub
  • Welcome!
  • Smart contracts
    • Core
      • Introduction
      • Deep Dive
      • Smart Contract Reference
        • PWN Hub
          • Tags
        • PWN Config
        • PWN Vault
        • Loan Types
          • Simple Loan
        • Proposals
          • Simple Loan Proposal
            • Simple Proposal
            • List Proposal
            • Elastic Proposal
            • Elastic Chainlink Proposal
            • Dutch Proposal
        • PWN Utilized Credit
        • PWN LOAN
        • PWN Revoked Nonce
        • Peripheral Contracts
          • Acceptor Controller
            • World ID
          • State Fingerprint Computer
            • UniV3
            • Chicken Bonds
          • Pool Adapter
            • Aave
            • Compound
            • ERC4626
        • Miscellaneous
          • PWN Fee Calculator
          • PWN Signature Checker
          • PWN Errors
          • PWN Periphery
          • Timelock
    • PWN DAO
      • Governance
        • Optimistic
        • Token
      • Tokens
        • PWN
        • stPWN
        • vePWN
          • Stake
          • Power
          • Metadata
      • Epoch Clock
      • Miscellaneous
        • Errors
        • EpochPowerLib
    • Tools
      • PWN Safe
        • Architecture
        • Security considerations
        • Smart Contract Reference
          • PWN Safe Factory
          • ATR Module
            • Tokenized Asset Manager
            • Recipient Permission Manager
          • Whitelist
          • ATR Guard
            • Operators context
      • Token Bundler
      • PWN Deployer
    • Libraries
      • MultiToken
    • Contract Addresses
  • More documentation
    • PWN Docs
    • FAQ
    • Audits
    • Using PWN without front-end
  • Deprecated
    • PWN Beta
      • Architecture
      • PWN
        • Off-chain signed offer
        • Offer types
      • PWN Vault
      • PWN LOAN
Powered by GitBook
On this page
  • 1. Summary
  • 2. Important links
  • 3. Contract details
  • Features
  • Inherited contracts, implemented Interfaces and ERCs
  • Functions
  • View Functions
  • Events
  • Errors
Edit on GitHub
  1. Smart contracts
  2. Core
  3. Smart Contract Reference

PWN LOAN

PreviousPWN Utilized CreditNextPWN Revoked Nonce

Last updated 9 months ago

1. Summary

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

2. Important links

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 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 PWNLOAN contract defines two events and two 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

Errors

error InvalidLoanContractCaller();
error CallerMissingHubTag(bytes32 tag);
InvalidLoanContractCaller

This error doesn't have any parameters.

CallerMissingHubTag

This error has one parameter:

  • bytes32tag

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

A InvalidLoanContractCaller error is thrown when function caller is not a loan contract that minted the LOAN token.

A CallerMissingHubTag error is thrown when caller is missing a tag.

IERC5646
ERC721
ERC-5646
PWN Hub
burn
ERC-721
pwn_contracts/PWNLOAN.sol at master · PWNFinance/pwn_contractsGitHub
Logo
180KB
PWNLOAN.json