Skip to content

VerisLabs/NFTBatchTransfers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Unlockd logo

figma typescript solidity google-cloud

Unlockd is a decentralized non-custodial NFT lending protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized fashion, using NFTs as collaterl.

NFTBatchTransfer enables bulk transfers of ERC721 tokens and CryptoPunks, streamlining transactions for efficiency. Callers are responsible for input validation.


πŸ—‚οΈ Index

πŸ“ Documentation

Overview

The NFTBatchTransfer contract is designed to facilitate the batch transfer of NFTs (Non-Fungible Tokens) in a single transaction. This not only reduces gas costs but also enhances the efficiency of multiple transfers. The contract is compatible with the standard ERC721 token protocol and is specifically tailored to work with the CryptoPunks contract.

Key Features:

  • Batch Transfer: Allows for multiple NFTs to be transferred in one transaction.
  • Gas Efficiency: Optimized to minimize gas usage during batch transfers.
  • CryptoPunks Special Handling: Special methods for handling the unique nature of CryptoPunks transfers.

Contract Structure

Public Variables:

punkContract: Holds the immutable address of the CryptoPunks contract. This address is set during deployment and cannot be altered afterward.

Struct:

NftTransfer: A struct used to encapsulate the details of an NFT transfer. It contains:
    contractAddress: The address of the ERC721 contract.
    tokenId: The specific ID of the token to be transferred.

Constructor:

NFTBatchTransfer(address _punkContract): Initializes the contract with the address of the CryptoPunks contract.

Main Functions:

batchTransferFrom(NftTransfer[] calldata nftTransfers, address to):

Allows for the batch transfer of standard ERC721 NFTs.
Requires the details of the NFTs to be transferred in the form of NftTransfer struct array and the recipient's address.
Uses dynamic calls to invoke the transferFrom method on target ERC721 contracts.


batchPunkTransferFrom(NftTransfer[] calldata nftTransfers, address to):

Orchestrates a batch transfer for CryptoPunks alongside other standard ERC721 NFTs.
Distinguishes between CryptoPunks and standard ERC721 tokens, applying special handling for CryptoPunks.
For CryptoPunks, the contract first buys the punk (if necessary) and then executes the transfer.

Fallback and Receive Functions:

fallback(): A fallback function that rejects any Ether sent to the contract.

receive(): Explicitly rejects any Ether transferred to the contract.

Important Note on Address ZERO:

For optimization and simplicity purposes, the batchTransferFrom and batchPunkTransferFrom functions in the NFTBatchTransfer contract do not internally validate the supplied addresses for zero address (0x0000000000000000000000000000000000000000).

This design choice was made to keep the contract functions lean and efficient. It is the responsibility of the caller to ensure that they do not provide the zero address when invoking these functions. Providing the zero address may result in the loss of NFTs, as they would be sent to an unrecoverable address.

Always double-check and validate addresses before calling the functions to prevent any unintended transfers.

🎬 Setup

You will need to have Foundry installed in your machine, I recomend to check https://book.getfoundry.sh/

Install

$ forge install

Build

$ forge build

πŸ§ͺ Test

Tests

$ forge test

Check coverage and create a report

$ mkdir coverage && forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

πŸš€ Deployments

This contract is deployed on:

Sepolia: 0xAbA905EbA39b9a55FD0f910a6415BA91c3E9353d

Mainnet: 0x0c331e00703a9857819fa1Eb72aA3d4DE0f6f725

These addresses are added on both deploy scripts:

Mainnet CryptoPunksMarket Address: "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"

Unlockd Mock CryptoPunksMarket Goerli Address: "0x3aFE908110e5c5275Bc96a9e42DB1B322590bDa4"

Unlockd Mock CryptoPunksMarket Sepolia Address: "0x720b094Ab68D7306d1545AD615fDE974fA6D86D9"

Deploy

Mainnet

$ forge script script/DeployNFTBatchTransfer.s.sol:DeployNFTBatchTransfer --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast -vvvv

Verify

If you prefer you can flatten the files so all solidity files in your contract (imports) will become a single file, making it easier to verify.

forge forge flatten <solidity file path> > <flattened file path>
forge verify-contract --num-of-optimizations 200 <deployed_address> src/NFTBatchTransferFlattened.sol:NFTBatchTransfer --etherscan-api-key <etherscan_api_key> --chain <chainId>

About

A public contract to batch NFT transfers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •