Skip to content

Commit

Permalink
Merge pull request #118 from onflow/enable-symbol-updates
Browse files Browse the repository at this point in the history
Add the ability to update symbols in bridged ERC20/721 contracts
  • Loading branch information
sisyphusSmiling authored Sep 3, 2024
2 parents ce09dd2 + 8902cab commit ca95d45
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cadence/args/deploy-erc20-deployer-args.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cadence/args/deploy-erc721-deployer-args.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cadence/tests/test_helpers.cdc

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions solidity/src/templates/FlowEVMBridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ contract FlowEVMBridgedERC20 is ERC165, ERC20, ERC20Burnable, ERC20Permit, Ownab
string public cadenceTokenIdentifier;
string public contractMetadata;

string private _customSymbol;

constructor(
address owner,
string memory name,
string memory symbol,
string memory name_,
string memory symbol_,
string memory _cadenceTokenAddress,
string memory _cadenceTokenIdentifier,
string memory _contractMetadata
) ERC20(name, symbol) Ownable(owner) ERC20Permit(name) {
) ERC20(name_, symbol_) Ownable(owner) ERC20Permit(name_) {
_customSymbol = symbol_;
cadenceTokenAddress = _cadenceTokenAddress;
cadenceTokenIdentifier = _cadenceTokenIdentifier;
contractMetadata = _contractMetadata;
Expand All @@ -36,17 +39,33 @@ contract FlowEVMBridgedERC20 is ERC165, ERC20, ERC20Burnable, ERC20Permit, Ownab
return cadenceTokenIdentifier;
}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
function symbol() public view override returns (string memory) {
return _customSymbol;
}

function contractURI() public view returns (string memory) {
return contractMetadata;
}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}

function setSymbol(string memory newSymbol) public onlyOwner {
_setSymbol(newSymbol);
}

function setContractURI(string memory newContractURI) public onlyOwner {
contractMetadata = newContractURI;
}

function supportsInterface(bytes4 interfaceId) public view override(ERC165) returns (bool) {
return interfaceId == type(IERC20).interfaceId || interfaceId == type(ERC20Burnable).interfaceId
|| interfaceId == type(Ownable).interfaceId || interfaceId == type(ERC20Permit).interfaceId
|| interfaceId == type(ICrossVM).interfaceId || super.supportsInterface(interfaceId);
}

function _setSymbol(string memory newSymbol) internal {
_customSymbol = newSymbol;
}
}
21 changes: 18 additions & 3 deletions solidity/src/templates/FlowEVMBridgedERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ contract FlowEVMBridgedERC721 is ERC721, ERC721URIStorage, ERC721Burnable, ERC72
string public cadenceNFTIdentifier;
string public contractMetadata;

string private _customSymbol;

constructor(
address owner,
string memory name,
string memory symbol,
string memory name_,
string memory symbol_,
string memory _cadenceNFTAddress,
string memory _cadenceNFTIdentifier,
string memory _contractMetadata
) ERC721(name, symbol) Ownable(owner) {
) ERC721(name_, symbol_) Ownable(owner) {
_customSymbol = symbol_;
cadenceNFTAddress = _cadenceNFTAddress;
cadenceNFTIdentifier = _cadenceNFTIdentifier;
contractMetadata = _contractMetadata;
Expand All @@ -39,6 +42,10 @@ contract FlowEVMBridgedERC721 is ERC721, ERC721URIStorage, ERC721Burnable, ERC72
return cadenceNFTIdentifier;
}

function symbol() public view override returns (string memory) {
return _customSymbol;
}

function safeMint(address to, uint256 tokenId, string memory uri) public onlyOwner {
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
Expand All @@ -48,6 +55,10 @@ contract FlowEVMBridgedERC721 is ERC721, ERC721URIStorage, ERC721Burnable, ERC72
_setTokenURI(tokenId, uri);
}

function setSymbol(string memory newSymbol) public onlyOwner {
_setSymbol(newSymbol);
}

function contractURI() public view returns (string memory) {
return contractMetadata;
}
Expand All @@ -72,6 +83,10 @@ contract FlowEVMBridgedERC721 is ERC721, ERC721URIStorage, ERC721Burnable, ERC72
return _ownerOf(tokenId) != address(0);
}

function _setSymbol(string memory newSymbol) internal {
_customSymbol = newSymbol;
}

function _update(address to, uint256 tokenId, address auth)
internal
override(ERC721, ERC721Enumerable)
Expand Down
22 changes: 22 additions & 0 deletions solidity/test/FlowBridgeFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,26 @@ contract FlowBridgeFactoryTest is Test {
uint256 balance = deployedERC20Contract.balanceOf(recipient);
assertEq(balance, amount);
}

function test_UpdateERC721Symbol() public {
string memory _symbol = deployedERC721Contract.symbol();
assertEq(_symbol, symbol);

string memory newSymbol = "NEW_SYMBOL";
deployedERC721Contract.setSymbol(newSymbol);

_symbol = deployedERC721Contract.symbol();
assertEq(_symbol, newSymbol);
}

function test_UpdateERC20Symbol() public {
string memory _symbol = deployedERC20Contract.symbol();
assertEq(_symbol, symbol);

string memory newSymbol = "NEW_SYMBOL";
deployedERC20Contract.setSymbol(newSymbol);

_symbol = deployedERC20Contract.symbol();
assertEq(_symbol, newSymbol);
}
}

0 comments on commit ca95d45

Please sign in to comment.