-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea09322
commit 8905805
Showing
6 changed files
with
491 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.