Skip to content

Commit

Permalink
contract for airdrop token erc1155
Browse files Browse the repository at this point in the history
  • Loading branch information
jollyjoker992 committed Jan 11, 2024
1 parent ea09322 commit 8905805
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 106 deletions.
106 changes: 106 additions & 0 deletions contracts/FeralFileAirdropV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "./Authorizable.sol";

contract FeralFileAirdropV1 is ERC1155, Authorizable {
enum Type {
Fungible,
NonFungible
}

// Version
string public constant version = "v1";

// Airdropped addresses
mapping(address => bool) public airdroppedAddresses;

// already ended flag
bool private _ended;

// Token type
Type public tokenType;

constructor(Type tokenType_, string memory tokenURI_) ERC1155(tokenURI_) {
tokenType = tokenType_;
}

// @notice check if the airdrop is ended
function isEnded() external view returns (bool) {
return _ended;
}

// @notice end the airdrop
function end() external onlyOwner {
require(_ended == false, "FeralFileTokenAirdrop: already ended");
_ended = true;
}

/// @notice Mint tokens to the contract
/// @param tokenID token ID
/// @param amount_ amount of tokens to mint
function mint(uint256 tokenID, uint256 amount_) external onlyAuthorized {
require(_ended == false, "FeralFileTokenAirdrop: already ended");
require(
(tokenType == Type.Fungible && amount_ > 0) ||
(tokenType == Type.NonFungible && amount_ == 1),
"FeralFileTokenAirdrop: amount mismatch"
);
_mint(address(this), tokenID, amount_, "");
}

/// @notice airdrop tokens to a list of addresses
/// @param tokenID token ID
/// @param to_ list of addresses to airdrop to
function airdrop(
uint256 tokenID,
address[] calldata to_
) external onlyAuthorized {
require(_ended == false, "FeralFileTokenAirdrop: already ended");
require(
(tokenType == Type.Fungible && to_.length > 0) ||
(tokenType == Type.NonFungible && to_.length == 1),
"FeralFileTokenAirdrop: amount mismatch"
);

uint256[] memory _tokenIDs = new uint256[](1);
_tokenIDs[0] = tokenID;

for (uint256 i = 0; i < to_.length; i++) {
require(
airdroppedAddresses[to_[i]] == false,
"FeralFileTokenAirdrop: already airdropped"
);

uint256[] memory _amounts = new uint256[](1);
_amounts[0] = 1; // 1 token for each address

_safeBatchTransferFrom(
address(this),
to_[i],
_tokenIDs,
_amounts,
""
);

airdroppedAddresses[to_[i]] = true;
}
}

/// @notice burn remaining tokens
/// @param tokenID token ID
function burnRemaining(uint256 tokenID) external onlyOwner {
_burn(address(this), tokenID, balanceOf(address(this), tokenID));
}

function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public pure returns (bytes4) {
return this.onERC1155Received.selector;
}
}
14 changes: 14 additions & 0 deletions migrations/310_feralfile_airdrop_v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const FeralFileAirdropV1 = artifacts.require("FeralFileAirdropV1");

const argv = require("minimist")(process.argv.slice(2), {
string: ["token_uri", "type"],
});

module.exports = function (deployer) {
let token_uri =
argv.token_uri ||
"https://ipfs.bitmark.com/ipfs/QmNVdQSp1AvZonLwHzTbbZDPLgbpty15RMQrbPEWd4ooTU/{id}";
let type = argv.type || 0;

deployer.deploy(FeralFileAirdropV1, type, token_uri);
};
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"solidity-coverage": "^0.7.22",
"truffle": "^5.9.2",
"truffle-flattener": "^1.6.0",
"truffle-plugin-verify": "^0.5.28"
"truffle-plugin-verify": "^0.5.33"
}
}
Loading

0 comments on commit 8905805

Please sign in to comment.