From c07a3220b0c9ee296db92466bc3e9345d45f3d20 Mon Sep 17 00:00:00 2001 From: Ignacio Tirabasso Date: Thu, 3 Mar 2022 08:23:06 -0300 Subject: [PATCH] add custom token uri for crucibles --- contracts/crucible/CrucibleFactory.sol | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contracts/crucible/CrucibleFactory.sol b/contracts/crucible/CrucibleFactory.sol index 96fc407..7c02635 100644 --- a/contracts/crucible/CrucibleFactory.sol +++ b/contracts/crucible/CrucibleFactory.sol @@ -3,6 +3,7 @@ pragma solidity 0.7.6; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; +import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {IFactory} from "../factory/IFactory.sol"; import {IInstanceRegistry} from "../factory/InstanceRegistry.sol"; @@ -13,10 +14,12 @@ import {IUniversalVault} from "./Crucible.sol"; /// @title CrucibleFactory contract CrucibleFactory is Ownable, IFactory, IInstanceRegistry, ERC721 { address private immutable _template; + using Strings for uint256; constructor(address template) ERC721("Alchemist Crucible v1", "CRUCIBLE-V1") Ownable() { require(template != address(0), "CrucibleFactory: invalid template"); _template = template; + _setBaseURI('https://crucible.alchemist.wtf/nft/'); } /* registry functions */ @@ -83,4 +86,26 @@ contract CrucibleFactory is Ownable, IFactory, IInstanceRegistry, ERC721 { function getTemplate() external view returns (address template) { return _template; } + + /** + * @dev See {IERC721Metadata-tokenURI}. + */ + function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { + require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); + + string memory base = baseURI(); + + uint256 id; + assembly { + id := chainid() + } + + // concatenate the tokenID and chain id to the baseURI + return string(abi.encodePacked( + base, + tokenId.toString(), + '?network=', + chainId.toString() + )); + } }