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.
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.
- 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.
punkContract: Holds the immutable address of the CryptoPunks contract. This address is set during deployment and cannot be altered afterward.
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.
NFTBatchTransfer(address _punkContract): Initializes the contract with the address of the CryptoPunks contract.
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(): A fallback function that rejects any Ether sent to the contract.
receive(): Explicitly rejects any Ether transferred to the contract.
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.
You will need to have Foundry installed in your machine, I recomend to check https://book.getfoundry.sh/
$ forge install$ forge build$ forge test$ mkdir coverage && forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage$ forge fmt$ forge snapshotThis contract is deployed on:
Sepolia: 0xAbA905EbA39b9a55FD0f910a6415BA91c3E9353d
Mainnet: 0x0c331e00703a9857819fa1Eb72aA3d4DE0f6f725
Mainnet CryptoPunksMarket Address: "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"
Unlockd Mock CryptoPunksMarket Goerli Address: "0x3aFE908110e5c5275Bc96a9e42DB1B322590bDa4"
Unlockd Mock CryptoPunksMarket Sepolia Address: "0x720b094Ab68D7306d1545AD615fDE974fA6D86D9"
$ forge script script/DeployNFTBatchTransfer.s.sol:DeployNFTBatchTransfer --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast -vvvvIf 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>