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.
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:
address
owner
- 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:
uint256
loanId
- 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:
uint256
tokenId
- 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:
uint256
tokenId
- 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 indexed
loanId
- ID of the minted LOAN tokenaddress indexed
loanContract
- Address of the loan contract that minted this LOAN tokenaddress indexed
owner
- Address of the minted LOAN token receiver
LOANBurned
LOANBurned event is emitted when a LOAN token is burned.
This event has one parameter:
uint256 indexed
loanId
- ID of the burned LOAN token
Errors
error InvalidLoanContractCaller();
error CallerMissingHubTag(bytes32 tag);
InvalidLoanContractCaller
A InvalidLoanContractCaller error is thrown when burn function caller is not a loan contract that minted the LOAN token.
This error doesn't have any parameters.
CallerMissingHubTag
A CallerMissingHubTag error is thrown when caller is missing a PWN Hub tag.
This error has one parameter:
bytes32
tag