Skip to content

Commit 887867f

Browse files
committed
Simplify tokens
1 parent d970ae2 commit 887867f

File tree

3 files changed

+40
-68
lines changed

3 files changed

+40
-68
lines changed

contracts/src/TokenManager.sol

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ contract TokenManager is IProtocolHandler {
2222
struct TokenInfo {
2323
address tokenContract;
2424
bytes32 deployTxHash;
25-
string protocol;
2625
string tick;
2726
uint256 maxSupply;
2827
uint256 mintAmount;
@@ -133,14 +132,41 @@ contract TokenManager is IProtocolHandler {
133132
// Revert if token already exists
134133
if (token.deployTxHash != bytes32(0)) revert TokenAlreadyDeployed();
135134

136-
_deployToken(
137-
txHash,
138-
tickKey,
139-
protocolName(),
140-
deployOp.tick,
141-
deployOp.maxSupply,
142-
deployOp.mintAmount
135+
// Validate deployment parameters
136+
if (deployOp.maxSupply == 0) revert InvalidMaxSupply();
137+
if (deployOp.mintAmount == 0) revert InvalidMintAmount();
138+
if (deployOp.maxSupply % deployOp.mintAmount != 0) revert MaxSupplyNotDivisibleByMintAmount();
139+
140+
// Deploy ERC20 clone with CREATE2 using tickKey as salt for deterministic address
141+
address tokenAddress = erc20Template.cloneDeterministic(tickKey);
142+
143+
// Initialize the clone
144+
string memory name = string.concat(protocolName(), " ", deployOp.tick);
145+
string memory symbol = LibString.upper(deployOp.tick);
146+
147+
// Initialize with max supply in 18 decimals
148+
// User maxSupply "1000000" means 1000000 * 10^18 smallest units
149+
EthscriptionsERC20(tokenAddress).initialize(
150+
name,
151+
symbol,
152+
deployOp.maxSupply * 10**18,
153+
txHash
143154
);
155+
156+
// Store token info
157+
tokensByTick[tickKey] = TokenInfo({
158+
tokenContract: tokenAddress,
159+
deployTxHash: txHash,
160+
tick: deployOp.tick,
161+
maxSupply: deployOp.maxSupply,
162+
mintAmount: deployOp.mintAmount,
163+
totalMinted: 0
164+
});
165+
166+
// Map deploy hash to tick key for lookups
167+
deployToTick[txHash] = tickKey;
168+
169+
emit TokenDeployed(txHash, tokenAddress, deployOp.tick, deployOp.maxSupply, deployOp.mintAmount);
144170
}
145171

146172
/// @notice Handle mint operation
@@ -302,56 +328,4 @@ contract TokenManager is IProtocolHandler {
302328
// Use the protocol name from this handler
303329
return keccak256(abi.encode("erc-20", tick));
304330
}
305-
306-
/// @notice Deploy a new token
307-
/// @param deployTxHash The deployment transaction hash
308-
/// @param tickKey The tick key for storage
309-
/// @param protocol The protocol name
310-
/// @param tick The token tick symbol
311-
/// @param maxSupply The maximum supply (in user units)
312-
/// @param mintAmount The amount per mint (in user units)
313-
function _deployToken(
314-
bytes32 deployTxHash,
315-
bytes32 tickKey,
316-
string memory protocol,
317-
string memory tick,
318-
uint256 maxSupply,
319-
uint256 mintAmount
320-
) private {
321-
if (maxSupply == 0) revert InvalidMaxSupply();
322-
if (mintAmount == 0) revert InvalidMintAmount();
323-
if (maxSupply % mintAmount != 0) revert MaxSupplyNotDivisibleByMintAmount();
324-
325-
// Deploy ERC20 clone with CREATE2 using tickKey as salt for deterministic address
326-
address tokenAddress = erc20Template.cloneDeterministic(tickKey);
327-
328-
// Initialize the clone
329-
string memory name = string.concat(protocol, " ", tick);
330-
string memory symbol = LibString.upper(tick);
331-
332-
// Initialize with max supply in 18 decimals
333-
// User maxSupply "1000000" means 1000000 * 10^18 smallest units
334-
EthscriptionsERC20(tokenAddress).initialize(
335-
name,
336-
symbol,
337-
maxSupply * 10**18,
338-
deployTxHash
339-
);
340-
341-
// Store token info
342-
tokensByTick[tickKey] = TokenInfo({
343-
tokenContract: tokenAddress,
344-
deployTxHash: deployTxHash,
345-
protocol: protocol,
346-
tick: tick,
347-
maxSupply: maxSupply,
348-
mintAmount: mintAmount,
349-
totalMinted: 0
350-
});
351-
352-
// Map deploy hash to tick key for lookups
353-
deployToTick[deployTxHash] = tickKey;
354-
355-
emit TokenDeployed(deployTxHash, tokenAddress, tick, maxSupply, mintAmount);
356-
}
357331
}

contracts/test/EthscriptionsToken.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ contract EthscriptionsTokenTest is TestSetup {
8787
// Verify token was deployed
8888
TokenManager.TokenInfo memory tokenInfo = tokenManager.getTokenInfo(DEPLOY_TX_HASH);
8989

90-
assertEq(tokenInfo.protocol, "erc-20");
9190
assertEq(tokenInfo.tick, "TEST");
9291
assertEq(tokenInfo.maxSupply, 1000000);
9392
assertEq(tokenInfo.mintAmount, 1000);

lib/token_reader.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,23 @@ def self.get_token(tick, block_tag: 'latest')
4747
# struct TokenInfo {
4848
# address tokenContract;
4949
# bytes32 deployTxHash;
50-
# string protocol;
5150
# string tick;
5251
# uint256 maxSupply;
5352
# uint256 mintAmount;
5453
# uint256 totalMinted;
5554
# }
56-
output_types = ['(address,bytes32,string,string,uint256,uint256,uint256)']
55+
output_types = ['(address,bytes32,string,uint256,uint256,uint256)']
5756
decoded = Eth::Abi.decode(output_types, [result.delete_prefix('0x')].pack('H*'))
5857
token_tuple = decoded[0]
5958

6059
{
6160
tokenContract: token_tuple[0],
6261
deployTxHash: '0x' + token_tuple[1].unpack1('H*'),
63-
protocol: token_tuple[2],
64-
tick: token_tuple[3],
65-
maxSupply: token_tuple[4],
66-
mintLimit: token_tuple[5], # mintAmount field is used as mintLimit
67-
totalMinted: token_tuple[6],
62+
protocol: 'erc-20', # Always erc-20 for TokenManager
63+
tick: token_tuple[2],
64+
maxSupply: token_tuple[3],
65+
mintLimit: token_tuple[4], # mintAmount field is used as mintLimit
66+
totalMinted: token_tuple[5],
6867
# For backwards compatibility, add deployer field (not available in TokenInfo)
6968
deployer: nil,
7069
ethscriptionId: '0x' + token_tuple[1].unpack1('H*') # deployTxHash is the ethscriptionId

0 commit comments

Comments
 (0)