WETH Gateway

If you need to use native ETH in the protocol, it must first be wrapped into WETH. The WETH Gateway contract is a helper contract to easily wrap and unwrap ETH as necessary when interacting with the protocol, since only ERC20 is used within protocol interactions. This allows users to interact with the LendPool seamlessly without previously wrapping ETH themselves.

The source code of the WETH Gateway can be found on Github.

View methods

isCallerInWhitelist

function isCallerInWhitelist(address caller) external view returns (bool)

Checks if the caller is whitelisted.

Call params

Return values

getWETHAddress

function getWETHAddress() external view returns (address)

Returns the WETH address currently set in the WETH Gateway.

Return values

Write methods

depositETH

function depositETH(address onBehalfOf, uint16 referralCode) external payable override nonReentrant

Deposits the user-chosen amount of ETH into the protocol, minting the same amount passed as msg.value of corresponding uTokens, and transferring them to the onBehalfOf address.

Example: Bob deposits 100 ETH into Unlockd, and gets 100 uWETH in return as proof of the deposited amount.

The referral program is coded but inactive. You can pass a 0 as referralCode.

Ensure that the depositETH() transaction also includes the amount of ETH you are depositing in the msg.value.

Call params

withdrawETH

function withdrawETH(uint256 amount, address to) external override nonReentrant

Withdraws amount of the WETH, unwraps it to ETH, and transfers the ETH to the to address.

Example: Bob withdraws 10 ETH. Bob will get 10 ETH and will burn the same amount in uTokens.

Ensure you set the relevant ERC20 allowance of uWETH, before calling this function, so the WETHGateway contract can burn the associated uWETH.

Call params

borrowETH

function borrowETH(uint256 amount, address nftAsset, uint256 nftTokenId, address onBehalfOf, uint16 referralCode) external override nonReentrant

Borrows amount of ETH, sending the amount of unwrapped WETH to msg.sender.

Example: Alice borrows 10 ETH using her Lockey NFT with tokenid 1 as collateral.

The referral program is coded but inactive. You can pass a 0 as referralCode.

The borrowing can only be done if your NFT is configured on the protocol.

To do this, the triggerUserCollateral needs to be called first. Also, there's a _timeFrame variable configured that will validate the time between configuring the NFT and the borrow. If the time is exceeded, it will revert.

The _timeFrame can be checked with the getTimeframe() function in the LendPool contract

Call params

repayETH

function _repayETH( address nftAsset, uint256 nftTokenId, uint256 amount, uint256 accAmount ) internal returns (uint256, bool)

Repays a borrowed amount equal to or less than the amount owed from the specified collateral, nftAsset. It will burn the same amount of debt tokens.

Example: Alice decides to pay 2 ETH from the borrowed amount. Alice will use her uNFT to identify the loan, will give 2 ETH and will burn the same amount in debt tokens.

Ensure that the repayETH() transaction also includes the amount of ETH you are repaying in the msg.value.

Call params

Return values

auctionETH

function auctionETH(address nftAsset, uint256 nftTokenId, address onBehalfOf ) external payable override nonReentrant

Places a bid for an NFT whose current health factor is below one. The users can trigger an auction if they want to buy the collateral asset, placing a bid for the msg.valueamount. New bids should always be higher than the loan borrowed amount, and 1% higher than the previous bid (in case there is one). The first user to bid will always receive a 2.5% bid incentive for being the first bidder.

Example: Alice's NFT price went down, together with her loan's health factor (HF), which is now below 1. Bob decides to bid for that NFT. If there's a second bid, Bob's bid will be cancelled and the new bid will the the current winning bid. Bob will still receive a 2.5% reward fee for being the first bidder. The bidFine will also be paid if Alice decides to redeem part of the debt and make the HF go above one.

Ensure that the auctionETH() transaction also includes the amount of ETH you are bidding for in the msg.value.

Call params

redeemETH

function redeemETH( address nftAsset, uint256 nftTokenId, uint256 amount, uint256 bidFine ) external payable override nonReentrant returns (uint256)

Allows a borrower to increase his loan's Health Factor in case it is below 1. In order to redeem, a bidFine should be paid by the borrower to the current loan bidder (in case there is one).

Example: Alice's NFT price went down, together with her loan's health factor (HF), which is now below 1. Bob decides to bid for that NFT. After Bob's bid, Alice decides to redeem her NFT in order to increase her loan's HF and avoid getting liquidated. Bob will receive his bidding amount back, plus a bidFine reward fee for being the first bidder.

The redeem amount needs to be higher than the (borrowAmount * redeemThreshold)/100

Ensure that theredeemETH() transaction also includes the amount of ETH you are redeeming, as well as the bid fine you are transferring in the msg.value.

Call params

Return values

liquidateETH

function liquidateETH(address nftAsset, uint256 nftTokenId) external payable override nonReentrant returns (uint256)

Allows an auction winner to liquidate the position and get the NFT.

Example: Bob wins the auction. He can call this function to get his collateral (NFT) into his wallet.

The msg.value amount is the amount to be sent in case the bid price can't cover the borrow amount (for example, if a user takes a long time to redeem and the borrow amount needed to be paid has increased substantially due to interest rates)

Ensure that theredeemETH() transaction also includes the amount of ETH you want to add as amount to liquidate as msg.value.

Call params

Return values

authorizeLendPoolNFT

function authorizeLendPoolNFT(address[] calldata nftAssets) external nonReentrant onlyOwner

Approves the LendPool for the given NFT assets

Call params

authorizeCallerWhitelist

function authorizeCallerWhitelist(address[] calldata callers, bool flag) external nonReentrant onlyOwner

Authorizes/unauthorizes a list of callers for the whitelist

Call params

buyoutETH

function buyoutETH(address nftAsset, uint256 nftTokenId, address onBehalfOf) external payable override nonReentrant

Allows the user to do a buyout on an auction using ETH.

Call Params

buyDebtETH

function buyDebtETH(address nftAsset, uint256 nftTokenId, address onBehalfOf) external payable nonReentrant loanReserveShouldBeWETH(nftAsset, nftTokenId)

This will allow the buyer to buy a debt listing directly using ETH.

Call Params

bidDebtETH

function bidDebtEth(address nftAsset, uint256 nftTokenId, address onBehalfOf) external payable override nonReentrant loanReserveShouldBeWETH(nftAsset, nftTokenId)

Allows the user to bid on the debt market directly using ETH.

Call Params

Last updated