From 60cad7e18ae051132e5428cb537621c40b0ea6be Mon Sep 17 00:00:00 2001 From: Medet Ahmetson Date: Thu, 30 Nov 2023 22:46:11 +0700 Subject: [PATCH] Pass the name and symbol to the Linked NFT --- packages/hardhat/contracts/LinkedNft.sol | 2 +- packages/hardhat/contracts/Registrar.sol | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/hardhat/contracts/LinkedNft.sol b/packages/hardhat/contracts/LinkedNft.sol index 7cf0266..862d4ed 100644 --- a/packages/hardhat/contracts/LinkedNft.sol +++ b/packages/hardhat/contracts/LinkedNft.sol @@ -13,7 +13,7 @@ contract LinkedNft is ERC721URIStorage { address public registrar; address public source; - constructor(address _source, string memory _name, string memory _symbol) ERC721(_name, _symbol) { + constructor(address _source, string memory _name, string memory _symbol) ERC721(string.concat("Linked ", _name), string.concat("l", _symbol)) { registrar = msg.sender; source = _source; } diff --git a/packages/hardhat/contracts/Registrar.sol b/packages/hardhat/contracts/Registrar.sol index 31e6779..98fddc5 100644 --- a/packages/hardhat/contracts/Registrar.sol +++ b/packages/hardhat/contracts/Registrar.sol @@ -109,7 +109,7 @@ contract Registrar is Ownable, CCIPReceiver { require(deployTx == 0, "todo: Fetch from chainlink function the creator"); } - address wrappedNft = calculateAddress(block.chainid, nftAddr); + address wrappedNft = address(new WrappedNft{salt: generateSalt(address(this), nftAddr)}(nftAddr)); // First let's deploy the wrappedNft // Deploy the wrapped nft. @@ -125,7 +125,8 @@ contract Registrar is Ownable, CCIPReceiver { // args = block.chainid, nftAddr, wrappedNft, nftSupportedChains // todo make sure to re-calculate the wrapped nft in the destination. - bytes memory data = abi.encodeWithSignature("xSetup(address,address,uint256[])", nftAddr, wrappedNft, nftSupportedChains[nftAddr]); + bytes memory data = abi.encodeWithSignature("xSetup(address,address,uint256[],string memory,string memory)", + nftAddr, wrappedNft, nftSupportedChains[nftAddr], WrappedNft(wrappedNft).originalName(), WrappedNft(wrappedNft).originalSymbol()); uint256 totalFee = 0; uint256[] memory fees = new uint256[](chainIds.length); Client.EVM2AnyMessage[] memory messages = new Client.EVM2AnyMessage[](chainIds.length); @@ -158,9 +159,6 @@ contract Registrar is Ownable, CCIPReceiver { emit X_Setup(chainIds[i], nftAddr, messageId); } - - address deployedWrappedNft = address(new WrappedNft{salt: generateSalt(address(this), nftAddr)}(nftAddr)); - require(deployedWrappedNft == wrappedNft, "mismatch"); } // If your NFT wants to support new chains, call this. @@ -213,7 +211,12 @@ contract Registrar is Ownable, CCIPReceiver { require(success); } - function xSetup(address nftAddr, address wrappedNft, uint256[] calldata chainIds) private { + function xSetup( + address nftAddr, + address wrappedNft, uint256[] calldata chainIds, + string memory name, + string memory symbol + ) private { wrappedNft = calculateAddress(tempChainId, nftAddr); // First let's deploy the wrappedNft @@ -230,7 +233,7 @@ contract Registrar is Ownable, CCIPReceiver { nftSupportedChains[nftAddr].push(chainIds[i]); if (chainIds[i] == block.chainid) { - deployedAddr = address(new LinkedNft{salt: generateSalt(address(this), nftAddr)}(nftAddr, "", "")); + deployedAddr = address(new LinkedNft{salt: generateSalt(address(this), nftAddr)}(nftAddr, name, symbol)); require(deployedAddr == linkedNfts[chainIds[i]][nftAddr], "mismatch"); } }