Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions contracts/NFT1155V3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import "./base/NFT1155ContractURIdentifiable.sol";
import "./base/NFTStaticCallProxy.sol";

contract NFT1155V3 is NFT1155V2, NFT1155ContractURIdentifiable, NFTStaticCallProxy {
function factory() public view override(NFT1155V0, NFT1155ContractURIdentifiable) returns (address) {
return NFT1155V0.factory();
function contractURI() external view override returns (string memory) {
if (bytes(_contractURI).length > 0) {
return _contractURI;
} else {
string memory baseURI = _baseURI;
if (bytes(baseURI).length == 0) {
baseURI = ITokenFactory(_factory).baseURI1155();
}
return string(abi.encodePacked(baseURI, Strings.toHexString(uint160(address(this)), 20), ".json"));
}
}
}
12 changes: 10 additions & 2 deletions contracts/NFT721V2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import "./base/NFT721ContractURIdentifiable.sol";
import "./base/NFTStaticCallProxy.sol";

contract NFT721V2 is NFT721V1, NFT721ContractURIdentifiable, NFTStaticCallProxy {
function factory() public view override(NFT721V0, NFT721ContractURIdentifiable) returns (address) {
return NFT721V0.factory();
function contractURI() external view override returns (string memory) {
if (bytes(_contractURI).length > 0) {
return _contractURI;
} else {
string memory baseURI = __baseURI;
if (bytes(baseURI).length == 0) {
baseURI = ITokenFactory(_factory).baseURI721();
}
return string(abi.encodePacked(baseURI, Strings.toHexString(uint160(address(this)), 20), ".json"));
}
}
}
15 changes: 1 addition & 14 deletions contracts/base/NFT1155ContractURIdentifiable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,13 @@

pragma solidity =0.8.3;

import "@openzeppelin/contracts/utils/Strings.sol";

import "../interfaces/INFTContractURIdentifiable.sol";
import "../interfaces/ITokenFactory.sol";
import "./OwnableInitializable.sol";

abstract contract NFT1155ContractURIdentifiable is OwnableInitializable, INFTContractURIdentifiable {
string internal _contractURI;

function factory() public view virtual returns (address);

function contractURI() external view override returns (string memory) {
if (bytes(_contractURI).length > 0) {
return _contractURI;
} else {
string memory baseURI = ITokenFactory(factory()).baseURI1155();
string memory addy = Strings.toHexString(uint160(address(this)), 20);
return string(abi.encodePacked(baseURI, addy, ".json"));
}
}
function contractURI() external view virtual override returns (string memory);

function setContractURI(string memory uri) external override onlyOwner {
_contractURI = uri;
Expand Down
15 changes: 1 addition & 14 deletions contracts/base/NFT721ContractURIdentifiable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,13 @@

pragma solidity =0.8.3;

import "@openzeppelin/contracts/utils/Strings.sol";

import "../interfaces/INFTContractURIdentifiable.sol";
import "../interfaces/ITokenFactory.sol";
import "./OwnableInitializable.sol";

abstract contract NFT721ContractURIdentifiable is OwnableInitializable, INFTContractURIdentifiable {
string internal _contractURI;

function factory() public view virtual returns (address);

function contractURI() external view override returns (string memory) {
if (bytes(_contractURI).length > 0) {
return _contractURI;
} else {
string memory baseURI = ITokenFactory(factory()).baseURI721();
string memory addy = Strings.toHexString(uint160(address(this)), 20);
return string(abi.encodePacked(baseURI, addy, ".json"));
}
}
function contractURI() external view virtual override returns (string memory);

function setContractURI(string memory uri) external override onlyOwner {
_contractURI = uri;
Expand Down
9 changes: 9 additions & 0 deletions test/NFT1155.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ describe("NFT part of NFT1155", () => {
expect(await nft1155_0.uri(2)).to.be.not.equal(await URI1155(nft1155_0, 2));
expect(await nft1155_0.uri(4)).to.be.not.equal(await URI1155(nft1155_0, 4));
expect(await nft1155_0.uri(7)).to.be.not.equal(await URI1155(nft1155_0, 7));

expect(await nft1155_0.contractURI()).to.be.equal(`https://foo.bar/${nft1155_0.address.toLowerCase()}.json`);
await expect(nft1155_0.connect(bob).setContractURI("https://foo.bar/contractUri/")).to.be.revertedWith("SHOYU: FORBIDDEN");
await nft1155_0.connect(alice).setContractURI("https://foo.bar/contractUri/");
expect(await nft1155_0.contractURI()).to.be.equal("https://foo.bar/contractUri/");

await factory.deployNFT1155AndMintBatch(alice.address, [10], [3], royaltyVault.address, 10);
const nft1155_1 = await getNFT1155(factory);
expect(await nft1155_1.contractURI()).to.be.equal(`https://nft1155.sushi.com/${nft1155_1.address.toLowerCase()}.json`);
});

it("should be that mint/mintBatch functions work well", async () => {
Expand Down
10 changes: 10 additions & 0 deletions test/NFT721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ describe("NFT part of NFT721", () => {
expect(await nft721_0.tokenURI(2)).to.be.not.equal(await URI721(nft721_0, 2));
expect(await nft721_0.tokenURI(4)).to.be.not.equal(await URI721(nft721_0, 4));
expect(await nft721_0.tokenURI(7)).to.be.not.equal(await URI721(nft721_0, 7));

expect(await nft721_0.contractURI()).to.be.equal(`https://foo.bar/${nft721_0.address.toLowerCase()}.json`);
await expect(nft721_0.connect(bob).setContractURI("https://foo.bar/contractUri/")).to.be.revertedWith("SHOYU: FORBIDDEN");
await nft721_0.connect(alice).setContractURI("https://foo.bar/contractUri/");
expect(await nft721_0.contractURI()).to.be.equal("https://foo.bar/contractUri/");

await factory.deployNFT721AndPark(alice.address, "Name", "Symbol", 10, royaltyVault.address, 10);
const nft721_1 = await getNFT721(factory);
expect(await nft721_1.contractURI()).to.be.equal(`https://nft721.sushi.com/${nft721_1.address.toLowerCase()}.json`);

});

it("should be that parkTokenIds func work well", async () => {
Expand Down
Loading