Links

PWN

The core interface

1. Summary

PWN is the core interface that users are expected to use. It is the only interactive contract allowing for permissionless external calls. The contract defines the workflow functionality and handles the market making.

3. Contract Details

  • PWN.sol contract is written in Solidity version 0.8.4

Features

Functions

createLoan

A borrower can accept an existing signed off-chain offer by calling the createLoan function.
The diagram below shows the high-level logic of the function.
This function takes two arguments supplied by the caller (borrower):
  • PWNLOAN.Offer memory_offer - Offer struct with plain offer data. For more information, see basic offer
  • bytes memory_signature - EIP-712 raw signature of the offer typed struct signed by the lender
Note that a borrowed asset has to be an ERC-20 token, otherwise, the transaction will revert.
It's recommended to check the lender's balance to make sure that the loan can be created.

createFlexibleLoan

This function allows for accepting flexible offers (see Flexible offers).
The internal logic is similar as with createLoan, but this function takes one more argument:
  • PWNLOAN.FlexibleOffer memory_offer - Offer struct with flexible offer data. For more information see flexible offer struct.
  • PWNLOAN.FlexibleOfferValues memory_offerValues - Concrete values of a flexible offer set by the borrower. For more information see flexible offer values.
  • bytes memory_signature - EIP-712 raw signature of the offer typed struct signed by the lender
Note that a borrowed asset has to be an ERC-20 token, otherwise, the transaction will revert.
It's recommended to check the lender's balance to make sure that the loan can be created.

repayLoan

The repayLoan function allows for repaying a loan by anyone. This enables users to take a loan from one address and repay the loan from another address. The loan's underlying collateral will be transferred back to the original borrower's address and not to the address which repaid the loan.
This function assumes approval of all used assets to PWN Vault. If any of the used assets are not approved the function will revert.
The diagram below shows the high-level logic of the function.
This function takes one argument supplied by the caller:
  • uint256_loanId - ID of the LOAN being paid back

claimLoan

The owner of a LOAN token (usually the lender) can call this function to claim assets if the loan was expired or has been paid back.
The diagram below shows the high-level logic of the function.
This function takes one argument supplied by the caller:
  • uint256_loanId - ID of the LOAN to be claimed

revokeOffer

If a lender has signed an off-chain offer, they can revoke the offer by calling the revokeOffer function.
This function takes two arguments supplied by the caller:

Events

The PWN contract does not define any events or custom errors. All events relevant to the PWN protocol are emitted by the PWN Vault and PWN LOAN contracts.