Skip to content

Commit

Permalink
onchain svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
cblanquera committed Mar 9, 2022
1 parent c5b8ff9 commit b697c39
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 21 deletions.
153 changes: 134 additions & 19 deletions contracts/Gryph/GryphNamespaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,8 @@ error InvalidName();
error InvalidAmountSent();

contract GryphNamespaces is ERC721Base, Ownable, ReentrancyGuard {
using Strings for uint16;
using Counters for Counters.Counter;
// ============ Immutable ============

uint256[] public PRICES = [
0.192 ether, //4 letters
0.096 ether, //5 letters
0.048 ether, //6 letters
0.024 ether, //7 letters
0.012 ether, //8 letters
0.006 ether, //9 letters
0.003 ether //10 letters or more
];

string private DESCRIPTION = "GRY.PH is a cross chain NFT marketplace. Holders of this collection namespace have the rights to customize its contents";

// ============ Storage ============

Expand Down Expand Up @@ -83,9 +71,8 @@ contract GryphNamespaces is ERC721Base, Ownable, ReentrancyGuard {
"data:application/json;base64,",
Base64.encode(bytes(abi.encodePacked(
'{"name":"', name, '.gry.ph",',
'"description": "', DESCRIPTION, '",',
'"animation_url": "', _baseURI, '/namespace?', name, '",',
'"image":"', _baseURI, '/gryph-water.svg"}'
'"description": "', _description(), '",',
'"image":"data:image/svg+xml;base64,', _svg64(name), '"}'
)))
)
);
Expand All @@ -101,13 +88,15 @@ contract GryphNamespaces is ERC721Base, Ownable, ReentrancyGuard {
uint256 length = bytes(name).length;
//disallow length length less than 4
if (length < 4) revert InvalidName();
//get prices
uint64[7] memory prices = _prices();
//get index
uint256 index = length - 4;
if (index >= PRICES.length) {
index = PRICES.length - 1;
if (index >= prices.length) {
index = prices.length - 1;
}
//check price
if (msg.value < PRICES[index]) revert InvalidAmountSent();
if (msg.value < prices[index]) revert InvalidAmountSent();
//okay to mint
_nameMint(recipient, name);
}
Expand Down Expand Up @@ -169,6 +158,132 @@ contract GryphNamespaces is ERC721Base, Ownable, ReentrancyGuard {

// ============ Internal Methods ============

function _prices() internal pure returns(uint64[7] memory) {
return [
0.192 ether, //4 letters
0.096 ether, //5 letters
0.048 ether, //6 letters
0.024 ether, //7 letters
0.012 ether, //8 letters
0.006 ether, //9 letters
0.003 ether //10 letters or more
];
}

function _description() internal pure returns(string memory) {
return "GRY.PH is a cross chain NFT marketplace. Holders of this collection namespace have the rights to customize its contents";
}

function _grid() internal pure returns(uint16[5][73] memory) {
return [
[uint16(25), 25, 13, 125, 0],
[uint16(50), 25, 38, 100, 0],
[uint16(75), 25, 88, 75, 0],
[uint16(25), 25, 163, 50, 0],
[uint16(25), 25, 188, 25, 0],
[uint16(25), 25, 213, 0, 0],
[uint16(25), 25, 288, 75, 0],
[uint16(25), 25, 263, 50, 0],
[uint16(25), 25, 238, 25, 0],
[uint16(25), 50, 338, 75, 0],
[uint16(25), 25, 363, 125, 0],
[uint16(25), 25, 388, 150, 0],
[uint16(25), 25, 413, 175, 0],
[uint16(25), 75, 438, 200, 0],
[uint16(50), 25, 38, 150, 0],
[uint16(25), 25, 113, 175, 0],
[uint16(25), 75, 88, 200, 0],
[uint16(25), 25, 113, 275, 0],
[uint16(25), 25, 13, 325, 0],
[uint16(50), 25, 38, 300, 0],
[uint16(50), 25, 38, 350, 0],
[uint16(75), 25, 88, 375, 0],
[uint16(25), 25, 163, 400, 0],
[uint16(25), 25, 188, 425, 0],
[uint16(25), 25, 213, 450, 0],
[uint16(25), 25, 288, 375, 0],
[uint16(25), 25, 263, 400, 0],
[uint16(25), 25, 238, 425, 0],
[uint16(25), 50, 338, 350, 0],
[uint16(25), 25, 363, 325, 0],
[uint16(25), 25, 388, 300, 0],
[uint16(25), 25, 413, 275, 0],
[uint16(50), 25, 38, 125, 1],
[uint16(50), 25, 38, 325, 1],
[uint16(50), 25, 88, 150, 1],
[uint16(75), 25, 88, 100, 1],
[uint16(75), 25, 88, 350, 1],
[uint16(50), 25, 88, 300, 1],
[uint16(25), 75, 113, 200, 1],
[uint16(25), 25, 163, 75, 1],
[uint16(75), 25, 188, 50, 1],
[uint16(25), 25, 213, 25, 1],
[uint16(25), 25, 263, 75, 1],
[uint16(25), 25, 138, 175, 1],
[uint16(25), 25, 138, 275, 1],
[uint16(75), 25, 188, 400, 1],
[uint16(25), 25, 213, 425, 1],
[uint16(25), 25, 263, 375, 1],
[uint16(25), 25, 163, 375, 1],
[uint16(25), 25, 88, 125, 2],
[uint16(25), 25, 88, 325, 2],
[uint16(25), 50, 213, 100, 2],
[uint16(25), 50, 238, 125, 2],
[uint16(25), 50, 238, 300, 2],
[uint16(25), 25, 288, 175, 2],
[uint16(25), 25, 288, 275, 2],
[uint16(25), 50, 213, 325, 2],
[uint16(25), 25, 213, 200, 2],
[uint16(25), 25, 213, 250, 2],
[uint16(25), 25, 363, 150, 2],
[uint16(25), 25, 363, 300, 2],
[uint16(25), 125, 388, 175, 2],
[uint16(75), 75, 238, 200, 3],
[uint16(25), 25, 263, 175, 3],
[uint16(25), 25, 263, 275, 3],
[uint16(25), 25, 288, 150, 3],
[uint16(25), 25, 288, 300, 3],
[uint16(25), 50, 313, 75, 3],
[uint16(50), 50, 313, 125, 3],
[uint16(75), 125, 313, 175, 3],
[uint16(50), 50, 313, 300, 3],
[uint16(25), 50, 313, 350, 3],
[uint16(25), 75, 413, 200, 3]
];
}

function _svg64(string memory name) internal pure returns(string memory) {
bytes memory svg = abi.encodePacked(
'<svg width="475" height="475" xmlns="http://www.w3.org/2000/svg"><g><rect height="475" width="475" fill="#ffffff"/>'
);

string[4] memory color = [
'D0D0D0',
'F5F5F5',
'EDEDED',
'DBDBDB'
];

uint16[5][73] memory grid = _grid();
for (uint8 i = 0; i < grid.length; i++) {
svg = abi.encodePacked(svg,
'<rect height="', grid[i][0].toString(),
'" width="', grid[i][1].toString(),
'" y="', grid[i][2].toString(),
'" x="', grid[i][3].toString(),
'" fill="#', color[grid[i][4]],'"/>'
);
}

svg = abi.encodePacked(svg,
'<text font-family="', "'Courier New'", '" font-weight="bold" font-size="30" y="60%" x="50%" fill="#444" dominant-baseline="middle" text-anchor="middle">gry.ph</text>',
'<text id="name" font-family="', "'Courier New'", '" font-weight="bold" font-size="30" y="50%" x="50%" fill="#000" dominant-baseline="middle" text-anchor="middle">', name,'</text>',
'</g></svg>'
);

return Base64.encode(svg);
}

function _nameMint(address recipient, string memory name) internal {
//already reserved or blacklisted
if (reserved[name] > 0 || blacklisted[name]) revert InvalidName();
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy-gns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const nft = await NFT.deploy(uri)
await nft.deployed()
console.log('NFT contract deployed to (update .env):', nft.address)
console.log('npx hardhat verify --network', hardhat.config.defaultNetwork, nft.address)
console.log('npx hardhat verify --network', hardhat.config.defaultNetwork, nft.address, `"${uri}"`)
}

// We recommend this pattern to be able to use async/await everywhere
Expand All @@ -21,5 +21,5 @@ main().then(() => process.exit(0)).catch(error => {
process.exit(1)
});

//$ npx hardhat verify --network testnet 0x5773Fe8CE26FAA9F6d9EeD99283188141C341d4C
//$ npx hardhat verify --network testnet 0xCFe522301C7246401387003156dFb7cd4826Bd3b "https://ipfs.io/ipfs/bafkreicw32mefimobvabviirb7rao45r3kpy5zdudiputyubcmp2gag4xa"
//$ npx hardhat verify --network mainnet

0 comments on commit b697c39

Please sign in to comment.