WETH Gateway
Last updated
Last updated
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.
function isCallerInWhitelist(address caller) external view returns (bool)
Checks if the caller is whitelisted.
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
function getWETHAddress() external view returns (address)
Returns the WETH address currently set in the WETH Gateway.
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
.
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.
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
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
.
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.value
amount. 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
.
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
.
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
.
function authorizeLendPoolNFT(address[] calldata nftAssets) external nonReentrant onlyOwner
Approves the LendPool for the given NFT assets
function authorizeCallerWhitelist(address[] calldata callers, bool flag) external nonReentrant onlyOwner
Authorizes/unauthorizes a list of callers for the whitelist
function buyoutETH(address nftAsset, uint256 nftTokenId, address onBehalfOf) external payable override nonReentrant
Allows the user to do a buyout on an auction using ETH.
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.
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.
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Amount | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Amount |
---|---|---|
Type | Amount |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
caller
address
The address to be checked
bool
Returns true
if the caller is whitelisted, false
otherwise
address
The WETH address
onBehalfOf
address
address whom will receive the uWETH.
Use msg.sender
when the uTokens should be sent to the caller.
referralCode
uint16
Referral code. The referral program is currently in development. Therefore, referralCode
must be set to 0.
amount
uint256
The amount to be withdrawn
to
address
address that will receive the unwrapped ETH
amount
uint256
Amount to be borrowed, expressed in wei units
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
onBehalfOf
address
address of user who will incur the debt.
Use msg.sender
when not calling on behalf of a different user.
referralCode
uint16
Referral code. The referral program is currently in development. Therefore, referralCode
must be set to 0.
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
amount
uint256
Amount to be repaid, expressed in wei units
accAmount
uint256
The accumulated amount
uint256
The paid amount
bool
true
if the total amount is repaid or false
if partially paid.
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
onBehalfOf
address
address of user who will incur the auction.
Use msg.sender
when not calling on behalf of a different user.
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
amount
uint256
Amount to be redeemed, expressed in wei units
bidFine
uint256
Amount to be paid as bid fine, expressed in wei units
uint256
The total payback (amount redeemed plus the bid fine)
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
uint256
The extra debt amount (in case there is one) paid due to last bid price can not cover the borrow amount
nftAssets
address[]
The array of NFT assets
callers
address[]
The array of callers to be authorized
flag
bool
The flag to authorize/unauthorize
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
onBehalfOf
address
address of user who will incur the buyout.
Use msg.sender
when not calling on behalf of a different user.
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
onBehalfOf
address
address of user who will incur the buyDebt.
Use msg.sender
when not calling on behalf of a different user.
nftAsset
address
The NFT contract address
nftTokenId
uint256
The NFT token Id
onBehalfOf
address
address of user who will incur the bidDebt.
Use msg.sender
when not calling on behalf of a different user.