Skip to content

Commit

Permalink
Burn functions - ERC1155Drop base contract (#290)
Browse files Browse the repository at this point in the history
* add burn functions to ERC1155Drop base contract

* v3.2.8
  • Loading branch information
kumaryash90 authored Dec 9, 2022
1 parent 8a7c67f commit 312a7b6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
48 changes: 48 additions & 0 deletions contracts/base/ERC1155Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,54 @@ contract ERC1155Drop is
interfaceId == type(IERC2981).interfaceId; // ERC165 ID for ERC2981
}

/*//////////////////////////////////////////////////////////////
Minting/burning logic
//////////////////////////////////////////////////////////////*/

/**
* @notice Lets an owner or approved operator burn NFTs of the given tokenId.
*
* @param _owner The owner of the NFT to burn.
* @param _tokenId The tokenId of the NFT to burn.
* @param _amount The amount of the NFT to burn.
*/
function burn(
address _owner,
uint256 _tokenId,
uint256 _amount
) external virtual {
address caller = msg.sender;

require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");
require(balanceOf[_owner][_tokenId] >= _amount, "Not enough tokens owned");

_burn(_owner, _tokenId, _amount);
}

/**
* @notice Lets an owner or approved operator burn NFTs of the given tokenIds.
*
* @param _owner The owner of the NFTs to burn.
* @param _tokenIds The tokenIds of the NFTs to burn.
* @param _amounts The amounts of the NFTs to burn.
*/
function burnBatch(
address _owner,
uint256[] memory _tokenIds,
uint256[] memory _amounts
) external virtual {
address caller = msg.sender;

require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");
require(_tokenIds.length == _amounts.length, "Length mismatch");

for (uint256 i = 0; i < _tokenIds.length; i += 1) {
require(balanceOf[_owner][_tokenIds[i]] >= _amounts[i], "Not enough tokens owned");
}

_burnBatch(_owner, _tokenIds, _amounts);
}

/*///////////////////////////////////////////////////////////////
Overriden metadata logic
//////////////////////////////////////////////////////////////*/
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/contracts",
"description": "Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI",
"version": "3.2.8-0",
"version": "3.2.8",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
36 changes: 36 additions & 0 deletions docs/ERC1155Drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ function balanceOfBatch(address[] accounts, uint256[] ids) external view returns
|---|---|---|
| _0 | uint256[] | undefined |

### burn

```solidity
function burn(address _owner, uint256 _tokenId, uint256 _amount) external nonpayable
```

Lets an owner or approved operator burn NFTs of the given tokenId.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _owner | address | The owner of the NFT to burn. |
| _tokenId | uint256 | The tokenId of the NFT to burn. |
| _amount | uint256 | The amount of the NFT to burn. |

### burnBatch

```solidity
function burnBatch(address _owner, uint256[] _tokenIds, uint256[] _amounts) external nonpayable
```

Lets an owner or approved operator burn NFTs of the given tokenIds.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _owner | address | The owner of the NFTs to burn. |
| _tokenIds | uint256[] | The tokenIds of the NFTs to burn. |
| _amounts | uint256[] | The amounts of the NFTs to burn. |

### claim

```solidity
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std

0 comments on commit 312a7b6

Please sign in to comment.