Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
chore: remove check for existing tokens
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 committed Nov 13, 2023
1 parent 3f82b10 commit 1f72de8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 73 deletions.
52 changes: 18 additions & 34 deletions contracts/examples/ERC20Messaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions scripts/test/send-token.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
)
Expand Down
37 changes: 3 additions & 34 deletions test/topos-core/ToposMessaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 2 additions & 3 deletions test/topos-core/shared/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
}

Expand Down

0 comments on commit 1f72de8

Please sign in to comment.