Skip to content

Commit

Permalink
implement mergeable contract
Browse files Browse the repository at this point in the history
  • Loading branch information
hvthhien committed Jun 19, 2024
1 parent 02ab0ad commit f2fcc66
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ merge: sol-merger-check
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralfileArtworkV3.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralfileArtworkV4_1.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralfileArtworkV4_2.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralfileArtworkV4_3.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralfileEnglishAuction.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/FeralFileAirdropV1.sol /tmp/sol-merger && \
sol-merger --export-plugin SPDXLicenseRemovePlugin ./contracts/OwnerData.sol /tmp/sol-merger && \
Expand All @@ -45,6 +46,8 @@ build-contract: check
jq -r ".abi" build/contracts/FeralfileExhibitionV4_1.json > ./build/FeralfileExhibitionV4.abi && \
jq -r ".bytecode" build/contracts/FeralfileExhibitionV4_2.json > ./build/FeralfileExhibitionV4_2.bin && \
jq -r ".abi" build/contracts/FeralfileExhibitionV4_2.json > ./build/FeralfileExhibitionV4_2.abi && \
jq -r ".bytecode" build/contracts/FeralfileExhibitionV4_3.json > ./build/FeralfileExhibitionV4_3.bin && \
jq -r ".abi" build/contracts/FeralfileExhibitionV4_3.json > ./build/FeralfileExhibitionV4_3.abi && \
jq -r ".bytecode" build/contracts/FeralfileEnglishAuction.json > ./build/FeralfileEnglishAuction.bin && \
jq -r ".abi" build/contracts/FeralfileEnglishAuction.json > ./build/FeralfileEnglishAuction.abi && \
jq -r ".bytecode" build/contracts/FeralFileAirdropV1.json > ./build/FeralFileAirdropV1.bin && \
Expand All @@ -57,13 +60,15 @@ build: build-contract
mkdir -p ./go-binding/feralfile-exhibition-v3 && \
mkdir -p ./go-binding/feralfile-exhibition-v4 && \
mkdir -p ./go-binding/feralfile-exhibition-v4_2 && \
mkdir -p ./go-binding/feralfile-exhibition-v4_3 && \
mkdir -p ./go-binding/feralfile-english-auction && \
mkdir -p ./go-binding/feralfile-airdrop-v1 && \
mkdir -p ./go-binding/owner-data && \
abigen --abi ./build/FeralfileExhibitionV2.abi --bin ./build/FeralfileExhibitionV2.bin --pkg feralfilev2 -type FeralfileExhibitionV2 --out ./go-binding/feralfile-exhibition-v2/abi.go
abigen --abi ./build/FeralfileExhibitionV3.abi --bin ./build/FeralfileExhibitionV3.bin --pkg feralfilev3 -type FeralfileExhibitionV3 --out ./go-binding/feralfile-exhibition-v3/abi.go
abigen --abi ./build/FeralfileExhibitionV4.abi --bin ./build/FeralfileExhibitionV4.bin --pkg feralfilev4 -type FeralfileExhibitionV4 --out ./go-binding/feralfile-exhibition-v4/abi.go
abigen --abi ./build/FeralfileExhibitionV4_2.abi --bin ./build/FeralfileExhibitionV4_2.bin --pkg feralfilev4_2 -type FeralfileExhibitionV4_2 --out ./go-binding/feralfile-exhibition-v4_2/abi.go
abigen --abi ./build/FeralfileExhibitionV4_3.abi --bin ./build/FeralfileExhibitionV4_3.bin --pkg feralfilev4_2 -type FeralfileExhibitionV4_3 --out ./go-binding/feralfile-exhibition-v4_3/abi.go
abigen --abi ./build/FeralfileEnglishAuction.abi --bin ./build/FeralfileEnglishAuction.bin --pkg english_auction -type FeralfileEnglishAuction --out ./go-binding/feralfile-english-auction/abi.go
abigen --abi ./build/FeralFileAirdropV1.abi --bin ./build/FeralFileAirdropV1.bin --pkg airdropv1 -type FeralFileAirdropV1 --out ./go-binding/feralfile-airdrop-v1/abi.go && \
abigen --abi ./build/OwnerData.abi --bin ./build/OwnerData.bin --pkg ownerdata -type OwnerData --out ./go-binding/owner-data/abi.go
11 changes: 5 additions & 6 deletions contracts/FeralfileArtworkV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ contract FeralfileExhibitionV4 is

// initialize max supply map
for (uint256 i = 0; i < seriesIds_.length; i++) {
// Check duplicate with others
for (uint256 j = i + 1; j < seriesIds_.length; j++) {
if (seriesIds_[i] == seriesIds_[j]) {
revert("FeralfileExhibitionV4: duplicate seriesId");
}
}
require(
_seriesMaxSupplies[i] == 0,
"FeralfileExhibitionV4: duplicate seriesId"
);

require(
seriesMaxSupplies_[i] > 0,
"FeralfileExhibitionV4: zero max supply"
Expand Down
81 changes: 81 additions & 0 deletions contracts/FeralfileArtworkV4_3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {FeralfileExhibitionV4_1} from "./FeralfileArtworkV4_1.sol";

contract FeralfileExhibitionV4_3 is FeralfileExhibitionV4_1 {
error InvalidOwner();
error TokenIsNonMergeable();
error InvalidLength();

struct MergeArtworkInfo {
uint256 singleSeriesId;
uint256 mergedSeriesId;
uint256 nextTokenId;
}
MergeArtworkInfo private mergeArtworkInfo;

constructor(
string memory name_,
string memory symbol_,
bool burnable_,
bool bridgeable_,
address signer_,
address vault_,
address costReceiver_,
string memory contractURI_,
uint256[] memory seriesIds_,
uint256[] memory seriesMaxSupplies_,
MergeArtworkInfo memory mergeArtworkInfo_
)
FeralfileExhibitionV4_1(
name_,
symbol_,
burnable_,
bridgeable_,
signer_,
vault_,
costReceiver_,
contractURI_,
seriesIds_,
seriesMaxSupplies_
)
{
mergeArtworkInfo = mergeArtworkInfo_;
}

/// @notice burns multiples mergeable artworks and mint a new artworks
/// @param tokenIds - list of tokenIds to be burned
function mergeArtworks(uint256[] calldata tokenIds) external {
if (tokenIds.length < 2) {
revert InvalidLength();
}

// Burn artworks
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
Artwork memory artwork = _allArtworks[tokenId];

if (
artwork.seriesId != mergeArtworkInfo.singleSeriesId &&
artwork.seriesId != mergeArtworkInfo.mergedSeriesId
) {
revert TokenIsNonMergeable();
}

if (ownerOf(tokenId) != _msgSender()) {
revert InvalidOwner();
}

_burnArtwork(tokenId);
}

// Mint new artwork
_mintArtwork(
mergeArtworkInfo.mergedSeriesId,
mergeArtworkInfo.nextTokenId,
_msgSender()
);
mergeArtworkInfo.nextTokenId++;
}
}

0 comments on commit f2fcc66

Please sign in to comment.