Skip to content

Commit

Permalink
add contractURI, use safeTransferFrom instead of safeBatchTransferFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
jollyjoker992 committed Jan 12, 2024
1 parent e630832 commit 8d99851
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
21 changes: 7 additions & 14 deletions contracts/FeralFileAirdropV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract FeralFileAirdropV1 is ERC1155, Authorizable {
}

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

// Airdropped addresses
mapping(address => bool) public airdroppedAddresses;
Expand All @@ -25,15 +25,20 @@ contract FeralFileAirdropV1 is ERC1155, Authorizable {
// Bridgeable flag
bool public bridgeable;

// Contract URI
string public contractURI;

// Ended flag
bool private _ended;

constructor(
Type tokenType_,
string memory tokenURI_,
string memory contractURI_,
bool burnable_,
bool bridgeable_
) ERC1155(tokenURI_) {
contractURI = contractURI_;
tokenType = tokenType_;
burnable = burnable_;
bridgeable = bridgeable_;
Expand Down Expand Up @@ -69,25 +74,13 @@ contract FeralFileAirdropV1 is ERC1155, Authorizable {
require(!_ended, "FeralFileAirdropV1: already ended");
_checkProperTokenAmount(to_.length); // to_ length is the amount of tokens to airdrop

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

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

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

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

airdroppedAddresses[to_[i]] = true;
}
Expand Down
12 changes: 11 additions & 1 deletion migrations/310_feralfile_airdrop_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ module.exports = function (deployer) {
let token_uri =
argv.token_uri ||
"https://ipfs.bitmark.com/ipfs/QmNVdQSp1AvZonLwHzTbbZDPLgbpty15RMQrbPEWd4ooTU/{id}";
let contract_uri =
argv.contract_uri ||
"ipfs://QmaQegRqExfFx8zuR6yscxzUwQJUc96LuNNQiAMK9BsUQe";
let type = argv.type || 0;
let burnable = argv.burnable || true;
let bridgeable = argv.bridgeable || true;

deployer.deploy(FeralFileAirdropV1, type, token_uri, burnable, bridgeable);
deployer.deploy(
FeralFileAirdropV1,
type,
token_uri,
contract_uri,
burnable,
bridgeable
);
};
6 changes: 5 additions & 1 deletion test/feralfile_airdrop_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const FeralFileAirdropV1 = artifacts.require("FeralFileAirdropV1");
const TOKEN_URI =
"https://ipfs.bitmark.com/ipfs/QmNVdQSp1AvZonLwHzTbbZDPLgbpty15RMQrbPEWd4ooTU/{id}";
const TOKEN_ID = 999;
const CONTRACT_URI = "ipfs://QmaQegRqExfFx8zuR6yscxzUwQJUc96LuNNQiAMK9BsUQe";
const TOKEN_TYPE_FUNGIBLE = 0;
const TOKEN_TYPE_NON_FUNGIBLE = 1;
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
Expand All @@ -21,6 +22,7 @@ contract("FeralFileAirdropV1", async (accounts) => {
let fungibleContract = await FeralFileAirdropV1.new(
TOKEN_TYPE_FUNGIBLE,
TOKEN_URI,
CONTRACT_URI,
burnable,
bridgeable
);
Expand All @@ -30,6 +32,7 @@ contract("FeralFileAirdropV1", async (accounts) => {
let nonFungibleContract = await FeralFileAirdropV1.new(
TOKEN_TYPE_NON_FUNGIBLE,
TOKEN_URI,
CONTRACT_URI,
burnable,
bridgeable
);
Expand All @@ -47,8 +50,9 @@ contract("FeralFileAirdropV1", async (accounts) => {
let contracts = this.contracts[0];
for (let i = 0; i < contracts.length; i++) {
let contract = contracts[i];
assert.equal(await contract.version(), "v1");
assert.equal(await contract.codeVersion(), "FeralFileAirdropV1");
assert.equal(await contract.uri(TOKEN_ID), TOKEN_URI);
assert.equal(await contract.contractURI(), CONTRACT_URI);
assert.equal(await contract.isEnded(), false);
assert.equal(await contract.tokenType(), i);
}
Expand Down

0 comments on commit 8d99851

Please sign in to comment.