From a583a5fb08143e9a9035fb50516ff434ba5fda32 Mon Sep 17 00:00:00 2001 From: Jawad <38837406+JDawg287@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:34:34 -0500 Subject: [PATCH] chore: remove check for existing tokens (#114) Signed-off-by: Jawad Tariq --- contracts/examples/ERC20Messaging.sol | 52 +++++++++----------------- scripts/test/send-token.ts | 3 +- test/topos-core/ToposMessaging.test.ts | 37 ++---------------- test/topos-core/shared/utils/common.ts | 5 +-- 4 files changed, 24 insertions(+), 73 deletions(-) diff --git a/contracts/examples/ERC20Messaging.sol b/contracts/examples/ERC20Messaging.sol index 285fa17..a15175d 100644 --- a/contracts/examples/ERC20Messaging.sol +++ b/contracts/examples/ERC20Messaging.sol @@ -36,42 +36,26 @@ contract ERC20Messaging is IERC20Messaging, ToposMessaging { _tokenDeployerAddr = tokenDeployerAddr; } - /// @notice Deploy/register a token - /// @param params Encoded token params for deploying/registering a token + /// @notice Deploy an internal token + /// @param params Encoded token params for deploying an internal token function deployToken(bytes calldata params) external { - ( - string memory name, - string memory symbol, - uint256 cap, - address tokenAddress, - uint256 dailyMintLimit, - uint256 initialSupply - ) = abi.decode(params, (string, string, uint256, address, uint256, uint256)); - - // Ensure that this token does not exist already. - bytes32 tokenKey = _getTokenKey(tokenAddress); - if (tokenSet.exists(tokenKey)) revert TokenAlreadyExists(tokenAddress); - - if (tokenAddress == address(0)) { - // If token address is no specified, it indicates a request to deploy one. - bytes32 salt = keccak256(abi.encodePacked(msg.sender, symbol)); - - // Deploy the token contract - tokenAddress = ITokenDeployer(_tokenDeployerAddr).deployToken( - name, - symbol, - cap, - initialSupply, - msg.sender, - address(this), - salt - ); - _setTokenType(tokenAddress, TokenType.InternalBurnableFrom); - } else { - revert UnsupportedTokenType(); - // _setTokenType(tokenAddress, TokenType.External); - } + (string memory name, string memory symbol, uint256 cap, uint256 dailyMintLimit, uint256 initialSupply) = abi + .decode(params, (string, string, uint256, uint256, uint256)); + + bytes32 salt = keccak256(abi.encodePacked(msg.sender, symbol)); + // Deploy the token contract + // The tx will revert if the token already exists because the salt will be the same + address tokenAddress = ITokenDeployer(_tokenDeployerAddr).deployToken( + name, + symbol, + cap, + initialSupply, + msg.sender, + address(this), + salt + ); + _setTokenType(tokenAddress, TokenType.InternalBurnableFrom); _setTokenAddress(symbol, tokenAddress); _setTokenDailyMintLimit(dailyMintLimit, tokenAddress); diff --git a/scripts/test/send-token.ts b/scripts/test/send-token.ts index 03e9177..d8456e5 100644 --- a/scripts/test/send-token.ts +++ b/scripts/test/send-token.ts @@ -1,4 +1,4 @@ -import { Contract, providers, utils, Wallet, constants } from 'ethers' +import { Contract, providers, utils, Wallet } from 'ethers' import { keccak256 } from '@ethersproject/keccak256' import { toUtf8Bytes } from '@ethersproject/strings' @@ -59,7 +59,6 @@ const main = async function (...args: string[]) { tc.TOKEN_NAME, tc.TOKEN_SYMBOL_X, tc.MINT_CAP_100_000_000, - constants.AddressZero, tc.DAILY_MINT_LIMIT_100, tc.INITIAL_SUPPLY_10_000_000 ) diff --git a/test/topos-core/ToposMessaging.test.ts b/test/topos-core/ToposMessaging.test.ts index 78b8d4b..c24bfbe 100644 --- a/test/topos-core/ToposMessaging.test.ts +++ b/test/topos-core/ToposMessaging.test.ts @@ -42,7 +42,6 @@ describe('ToposMessaging', () => { tc.TOKEN_NAME, tc.TOKEN_SYMBOL_X, tc.MINT_CAP_100_000_000, - ethers.constants.AddressZero, tc.DAILY_MINT_LIMIT_100, tc.INITIAL_SUPPLY_10_000_000 ) @@ -116,7 +115,6 @@ describe('ToposMessaging', () => { tc.TOKEN_NAME, tc.TOKEN_SYMBOL_Y, tc.MINT_CAP_100_000_000, - ethers.constants.AddressZero, tc.DAILY_MINT_LIMIT_100, tc.INITIAL_SUPPLY_10_000_000 ) @@ -151,38 +149,10 @@ describe('ToposMessaging', () => { const { defaultToken, erc20Messaging } = await loadFixture( deployERC20MessagingFixture ) - const tx = await erc20Messaging.deployToken(defaultToken) - const txReceipt = await tx.wait() - const logs = txReceipt.events?.find((e) => e.event === 'TokenDeployed') - const tokenAddress = logs?.args?.tokenAddress - const token = testUtils.encodeTokenParam( - tc.TOKEN_NAME, - tc.TOKEN_SYMBOL_X, - tc.MINT_CAP_100_000_000, - tokenAddress, - tc.DAILY_MINT_LIMIT_100, - tc.INITIAL_SUPPLY_10_000_000 - ) - await expect( - erc20Messaging.deployToken(token) - ).to.be.revertedWithCustomError(erc20Messaging, 'TokenAlreadyExists') - }) - - it('reverts if the token is an external token', async () => { - const [extToken] = await ethers.getSigners() - const { erc20Messaging } = await loadFixture(deployERC20MessagingFixture) - const token = testUtils.encodeTokenParam( - tc.TOKEN_NAME, - tc.TOKEN_SYMBOL_X, - tc.MINT_CAP_100_000_000, - extToken.address, - tc.DAILY_MINT_LIMIT_100, - tc.INITIAL_SUPPLY_10_000_000 - ) + await erc20Messaging.deployToken(defaultToken) await expect( - erc20Messaging.deployToken(token) - ).to.be.revertedWithCustomError(erc20Messaging, 'UnsupportedTokenType') - expect(await erc20Messaging.getTokenCount()).to.equal(0) + erc20Messaging.deployToken(erc20Messaging.deployToken(defaultToken)) + ).to.be.reverted }) it('allows two separate deployers to deploy tokens with same symbol', async () => { @@ -231,7 +201,6 @@ describe('ToposMessaging', () => { tc.TOKEN_NAME, tc.TOKEN_SYMBOL_X, tc.MINT_CAP_100_000_000, - ethers.constants.AddressZero, 0, tc.INITIAL_SUPPLY_10_000_000 ) diff --git a/test/topos-core/shared/utils/common.ts b/test/topos-core/shared/utils/common.ts index 9b16922..e7c2ca6 100644 --- a/test/topos-core/shared/utils/common.ts +++ b/test/topos-core/shared/utils/common.ts @@ -44,13 +44,12 @@ function encodeTokenParam( tokenName: string, tokenSymbol: string, mintCap: number, - address: string, dailyMintLimit: number, initialSupply: number ) { return ethers.utils.defaultAbiCoder.encode( - ['string', 'string', 'uint256', 'address', 'uint256', 'uint256'], - [tokenName, tokenSymbol, mintCap, address, dailyMintLimit, initialSupply] + ['string', 'string', 'uint256', 'uint256', 'uint256'], + [tokenName, tokenSymbol, mintCap, dailyMintLimit, initialSupply] ) }