2

Introducing NFT Flash Loans

 3 years ago
source link: https://medium.com/nft20/introducing-nft-flash-loans-97ff8c9298d4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introducing NFT Flash Loans

Today we are happy to talk about a new feature on the NFT20 protocol: NFT Flash Loans. As NFT utility grows, there will be more use cases to buy and sell NFTs programatically, or even use them for play and earn games and new use cases.

You can now take out a flashloan on any of our pools and use any of the up to 18k NFTs locked in our platform, at the moment there is no fee for taking a flashloan, but in the future there could be.

Designed for developers, Flash Loans makes it easy and instant to borrow without collateral once liquidity is returned to the pool within a single trading block. If this is not done, the entire transaction will revert and the actions taken up to that point will be effectively revoked. This guarantees the security of the funds in the pool.

Examples of use include arbitrage, claiming NFTs rewards while they accrue in a pool, and anything up to your own imagination...

Flashloans gave to the DeFi ecosystem infinite use cases and we’re excited to see what builders create on top of this feature in the NFT landscape.

To guide you on getting started with flashloans and create the spark we created a little example of Flasloans.

The first ever NFT Flashloan

Hashmasks is a living digital art collectible created by over 70 artists globally. By holding the artwork, you accumulate the NCT token on a daily basis, which allows you to choose a name for your portrait on the Ethereum blockchain.

The NCT Token also has value on the market: $0.17 per NCT at the time of writing. The NFT20 Hashmask pool currently hold 164 items.

We implemented (with the help of wafflemakr) the first smart contract that can in one transaction:

  • Borrow a set of Hashmasks from our NFT20pool.
  • Claim the accumulated NCT token accumulated while sitting in the pool
  • Sell those NCT token for ETH
  • Give back the Hashmasks to the pool.

We set up a frontend at https://nft20.io/hashmaskflash that will fetch the 20 most profitable HashMasks in our pool and automatically loan them and claim their NCTs. The NCTs will be converted to ETH and sent back to the caller with (10% goingto our DAO wallet). This is currently not profitable considering the price of NCT and gas price but was profitable a few days ago during our tests.

The code for this operation is really light:

1*YpUTLkQmLGaYw9Q-qkyAWw.png?q=20
introducing-nft-flash-loans-97ff8c9298d4

In order for a contract to properly handle the return of the borrowed asset you’ll need to make sure it executes at least once the setApprovalForAll function: in our case it’s done in the constructor:

1*7cb6R1mV5dvqQRQcN7e3Zw.png?q=20
introducing-nft-flash-loans-97ff8c9298d4

Once implemented, you just have to call the flashloan function on the NFT20 pair of your choice, passing the ids of the NFT you want to borrow, the address of the contract that will receive the assets and use them & an additional data field you for additional parameters:

1*EZEivB2UsfS9z6HTi4QMZw.png?q=20
introducing-nft-flash-loans-97ff8c9298d4

The way the flashloan is imlemented is really similar to Aave one, so if you’re already familiar with their implementation you won’t be lost with ours.

We’ll write some more documentation in the following days. In the meantime you can join our Discord channel if you need any help building on our protocol: flashloans/swap/tokenization of NFTs and soon maybe a P2P marketplace.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK