diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol
index 96a69d8..956882d 100644
--- a/contracts/FleekERC721.sol
+++ b/contracts/FleekERC721.sol
@@ -26,7 +26,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
struct App {
string name; // Name of the site
string description; // Description about the site
- string image; // Preview Image IPFS Link
string externalURL; // Site URL
string ENS; // ENS ID
uint256 currentBuild; // The current build number (Increments by one with each change, starts at zero)
@@ -57,6 +56,40 @@ contract FleekERC721 is ERC721, FleekAccessControl {
_;
}
+ /**
+ * @dev Generates a SVG image.
+ */
+ function _generateSVG(string memory name, string memory ENS) internal view returns (string memory) {
+ return (
+ string(
+ abi.encodePacked(
+ _baseURI(),
+ Base64.encode(
+ abi.encodePacked(
+ '"
+ )
+ )
+ )
+ )
+ );
+ }
+
/**
* @dev Mints a token and returns a tokenId.
*
@@ -71,7 +104,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
address to,
string memory name,
string memory description,
- string memory image,
string memory externalURL,
string memory ENS,
string memory commitHash,
@@ -84,7 +116,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
App storage app = _apps[tokenId];
app.name = name;
app.description = description;
- app.image = image;
app.externalURL = externalURL;
app.ENS = ENS;
@@ -117,7 +148,7 @@ contract FleekERC721 is ERC721, FleekAccessControl {
'"description":"', app.description, '",',
'"owner":"', Strings.toHexString(uint160(owner), 20), '",',
'"external_url":"', app.externalURL, '",',
- '"image":"', app.image, '",',
+ '"image":"', _generateSVG(app.name, app.ENS), '",',
'"attributes": [',
'{"trait_type": "ENS", "value":"', app.ENS,'"},',
'{"trait_type": "Commit Hash", "value":"', app.builds[app.currentBuild].commitHash,'"},',
@@ -247,26 +278,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
emit NewTokenDescription(tokenId, _tokenDescription, msg.sender);
}
- /**
- * @dev Updates the `image` metadata field of a minted `tokenId`.
- *
- * May emit a {NewTokenImage} event.
- *
- * Requirements:
- *
- * - the tokenId must be minted and valid.
- * - the sender must have the `tokenController` role.
- *
- */
- function setTokenImage(
- uint256 tokenId,
- string memory _tokenImage
- ) public virtual requireTokenRole(tokenId, Roles.Controller) {
- _requireMinted(tokenId);
- _apps[tokenId].image = _tokenImage;
- emit NewTokenImage(tokenId, _tokenImage, msg.sender);
- }
-
/**
* @dev Adds a new build to a minted `tokenId`'s builds mapping.
*
diff --git a/hardhat.config.ts b/hardhat.config.ts
index d33d74e..d8bf1ac 100644
--- a/hardhat.config.ts
+++ b/hardhat.config.ts
@@ -52,11 +52,17 @@ const config: HardhatUserConfig = {
},
},
solidity: {
- compilers: [
- {
- version: '0.8.7',
+ version: '0.8.7',
+ settings: {
+ optimizer: {
+ enabled: true,
+ runs: 200,
+ details: {
+ yul: false,
+ },
},
- ],
+ viaIR: false,
+ },
},
mocha: {
timeout: 200000, // 200 seconds max for running tests
diff --git a/test/FleekERC721.ts b/test/FleekERC721.ts
index 7445f70..482763a 100644
--- a/test/FleekERC721.ts
+++ b/test/FleekERC721.ts
@@ -59,7 +59,6 @@ describe('FleekERC721', () => {
owner.address,
MINT_PARAMS.name,
MINT_PARAMS.description,
- MINT_PARAMS.image,
MINT_PARAMS.externalUrl,
MINT_PARAMS.ens,
MINT_PARAMS.commitHash,
@@ -80,7 +79,6 @@ describe('FleekERC721', () => {
otherAccount.address,
MINT_PARAMS.name,
MINT_PARAMS.description,
- MINT_PARAMS.image,
MINT_PARAMS.externalUrl,
MINT_PARAMS.ens,
MINT_PARAMS.commitHash,
@@ -98,7 +96,6 @@ describe('FleekERC721', () => {
owner.address,
MINT_PARAMS.name,
MINT_PARAMS.description,
- MINT_PARAMS.image,
MINT_PARAMS.externalUrl,
MINT_PARAMS.ens,
MINT_PARAMS.commitHash,
@@ -132,7 +129,6 @@ describe('FleekERC721', () => {
fixture.owner.address,
MINT_PARAMS.name,
MINT_PARAMS.description,
- MINT_PARAMS.image,
MINT_PARAMS.externalUrl,
MINT_PARAMS.ens,
MINT_PARAMS.commitHash,
@@ -153,11 +149,35 @@ describe('FleekERC721', () => {
const parsedURI = JSON.parse(tokenURIDecoded);
+ const imageDecoded = Buffer.from(
+ parsedURI.image.replace('data:application/json;base64,', ''),
+ 'base64'
+ ).toString('ascii');
+
+ parsedURI.image = imageDecoded;
+
expect(parsedURI).to.eql({
owner: fixture.owner.address.toLowerCase(),
name: MINT_PARAMS.name,
description: MINT_PARAMS.description,
- image: MINT_PARAMS.image,
+ image:
+ '',
external_url: MINT_PARAMS.externalUrl,
attributes: [
{
@@ -193,7 +213,6 @@ describe('FleekERC721', () => {
fixture.owner.address,
MINT_PARAMS.name,
MINT_PARAMS.description,
- MINT_PARAMS.image,
MINT_PARAMS.externalUrl,
MINT_PARAMS.ens,
MINT_PARAMS.commitHash,
diff --git a/test/foundry/apps.t.sol b/test/foundry/apps.t.sol
index 27a267e..5689423 100644
--- a/test/foundry/apps.t.sol
+++ b/test/foundry/apps.t.sol
@@ -25,7 +25,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -41,7 +40,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -52,7 +50,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -68,7 +65,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -81,7 +77,6 @@ contract FleekTest is Test {
"Foundry Test App 2",
"This is a test application submitted by foundry tests [2].",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -96,7 +91,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -109,7 +103,6 @@ contract FleekTest is Test {
"Foundry Test App 2",
"This is a test application submitted by foundry tests[2].",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -118,14 +111,47 @@ contract FleekTest is Test {
assertEq(second_mint, 1);
}
+ function _generateSVG(string memory name, string memory ENS) internal pure returns (string memory) {
+ return (
+ string(
+ abi.encodePacked(
+ "data:application/json;base64,",
+ Base64.encode(
+ abi.encodePacked(
+ '"
+ )
+ )
+ )
+ )
+ );
+ }
+
function testTokenURI() public {
+ string memory name = "Foundry Test App";
+ string memory ens = "fleek_xyz";
+
uint256 mint = fleekContract.mint(
DEPLOYER,
- "Foundry Test App",
+ name,
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
- "fleek_xyz",
+ ens,
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
);
@@ -136,15 +162,21 @@ contract FleekTest is Test {
bytes memory dataURI = abi.encodePacked(
"{",
- '"name":"Foundry Test App",',
+ '"name":"',
+ name,
+ '",',
'"description":"This is a test application submitted by foundry tests.",',
'"owner":"',
Strings.toHexString(uint160(DEPLOYER), 20),
'",',
'"external_url":"https://fleek.xyz",',
- '"image":"https://fleek.xyz",',
+ '"image":"',
+ _generateSVG(name, ens),
+ '",',
'"attributes": [',
- '{"trait_type": "ENS", "value":"fleek_xyz"},',
+ '{"trait_type": "ENS", "value":"',
+ ens,
+ '"},',
'{"trait_type": "Commit Hash", "value":"afff3f6"},',
'{"trait_type": "Repository", "value":"https://github.com/fleekxyz/non-fungible-apps"},',
'{"trait_type": "Version", "value":"0"}',
@@ -161,7 +193,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -171,7 +202,6 @@ contract FleekTest is Test {
fleekContract.setTokenName(mint, "Foundry Test App 2");
fleekContract.setTokenDescription(mint, "This is a test application submitted by foundry tests. 2");
- fleekContract.setTokenImage(mint, "https://fleek2.xyz");
fleekContract.setTokenExternalURL(mint, "https://fleek2.xyz");
fleekContract.setTokenENS(mint, "fleek_xyz2");
fleekContract.setTokenBuild(mint, "afff3f62", "https://github.com/fleekxyz/non-fungible-apps2");
@@ -186,7 +216,9 @@ contract FleekTest is Test {
Strings.toHexString(uint160(DEPLOYER), 20),
'",',
'"external_url":"https://fleek2.xyz",',
- '"image":"https://fleek2.xyz",',
+ '"image":"',
+ _generateSVG("Foundry Test App 2", "fleek_xyz2"),
+ '",',
'"attributes": [',
'{"trait_type": "ENS", "value":"fleek_xyz2"},',
'{"trait_type": "Commit Hash", "value":"afff3f62"},',
@@ -205,7 +237,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -217,7 +248,6 @@ contract FleekTest is Test {
fleekContract.setTokenName(mint, "Foundry Test App 2");
fleekContract.setTokenDescription(mint, "This is a test application submitted by foundry tests. 2");
- fleekContract.setTokenImage(mint, "https://fleek2.xyz");
fleekContract.setTokenExternalURL(mint, "https://fleek2.xyz");
fleekContract.setTokenENS(mint, "fleek_xyz2");
fleekContract.setTokenBuild(mint, "afff3f62", "https://github.com/fleekxyz/non-fungible-apps2");
@@ -232,7 +262,9 @@ contract FleekTest is Test {
Strings.toHexString(uint160(DEPLOYER), 20),
'",',
'"external_url":"https://fleek2.xyz",',
- '"image":"https://fleek2.xyz",',
+ '"image":"',
+ _generateSVG("Foundry Test App 2", "fleek_xyz2"),
+ '",',
'"attributes": [',
'{"trait_type": "ENS", "value":"fleek_xyz2"},',
'{"trait_type": "Commit Hash", "value":"afff3f62"},',
@@ -276,7 +308,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -297,7 +328,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -316,7 +346,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -341,7 +370,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -358,7 +386,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -377,7 +404,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -394,7 +420,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -407,49 +432,12 @@ contract FleekTest is Test {
fleekContract.setTokenDescription(mint, "NEW TOKEN NAME!");
}
- function testSetTokenImage() public {
- uint256 mint = fleekContract.mint(
- DEPLOYER,
- "Foundry Test App",
- "This is a test application submitted by foundry tests.",
- "https://fleek.xyz",
- "https://fleek.xyz",
- "fleek_xyz",
- "afff3f6",
- "https://github.com/fleekxyz/non-fungible-apps"
- );
-
- assertEq(mint, 0);
-
- fleekContract.setTokenImage(mint, "https://ethereum.org");
- }
-
- function testFailSetTokenImageOnAnotherUsersTokenWithoutAccess() public {
- uint256 mint = fleekContract.mint(
- DEPLOYER,
- "Foundry Test App",
- "This is a test application submitted by foundry tests.",
- "https://fleek.xyz",
- "https://fleek.xyz",
- "fleek_xyz",
- "afff3f6",
- "https://github.com/fleekxyz/non-fungible-apps"
- );
-
- assertEq(mint, 0);
-
- vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
-
- fleekContract.setTokenImage(mint, "https://ethereum.org");
- }
-
function testSetTokenExternalURL() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -466,7 +454,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -485,7 +472,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -502,7 +488,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -521,7 +506,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -538,7 +522,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -557,7 +540,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -578,7 +560,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -601,7 +582,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -627,7 +607,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -653,7 +632,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -680,7 +658,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -711,7 +688,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -740,7 +716,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"
@@ -765,7 +740,6 @@ contract FleekTest is Test {
"Foundry Test App",
"This is a test application submitted by foundry tests.",
"https://fleek.xyz",
- "https://fleek.xyz",
"fleek_xyz",
"afff3f6",
"https://github.com/fleekxyz/non-fungible-apps"