Skip to content

Commit 2279f2d

Browse files
committed
Update token mint logic
1 parent 5dcdcf2 commit 2279f2d

File tree

3 files changed

+126
-5
lines changed

3 files changed

+126
-5
lines changed

config/derive_ethscriptions_blocks.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,9 @@ module Clockwork
176176
exit 1
177177

178178
rescue EthBlockImporter::ValidationStalledError => e
179-
# Validation is behind - wait longer and keep trying
180179
Rails.logger.info "[#{Time.now}] ⏸️ VALIDATION BEHIND: #{e.message}"
181-
puts "[#{Time.now}] ⏸️ Validation is behind - waiting #{import_interval * 2}s for validation to catch up..."
182-
sleep import_interval * 2 # Wait longer when validation is behind
183-
# Don't exit - continue the loop to retry
184-
180+
puts "[#{Time.now}] ⏸️ Validation is behind - waiting #{import_interval}s for validation to catch up..."
181+
# Don't sleep here - the loop's sleep at line 192 will handle it
185182
rescue => e
186183
Rails.logger.error "Import error: #{e.class} - #{e.message}"
187184
Rails.logger.error e.backtrace.first(20).join("\n")

contracts/src/TokenManager.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ contract TokenManager is IProtocolHandler {
123123
// Validate mint amount matches token's configured limit
124124
require(mintOp.amount == token.mintAmount, "amt mismatch");
125125

126+
// Validate mint ID is within valid range (1 to maxId)
127+
// maxId = maxSupply / mintAmount (both are in user units, not 18 decimals)
128+
uint256 maxId = token.maxSupply / token.mintAmount;
129+
require(mintOp.id >= 1 && mintOp.id <= maxId, "Invalid mint ID");
130+
126131
// Track this ethscription as a token item
127132
tokenItems[txHash] = TokenItem({
128133
deployTxHash: token.deployTxHash,

contracts/test/EthscriptionsToken.t.sol

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,123 @@ contract EthscriptionsTokenTest is TestSetup {
394394
assertEq(token.name(), "erc-20 TEST"); // Token name format is "protocol tick"
395395
assertEq(token.cap(), 1000000 ether); // Original cap, not the duplicate's
396396
}
397+
398+
function testMintWithInvalidIdZero() public {
399+
// Deploy the token first
400+
testTokenDeploy();
401+
402+
// Try to mint with ID 0 (invalid - must be >= 1)
403+
vm.prank(bob);
404+
string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"0","amt":"1000"}';
405+
406+
TokenManager.MintOperation memory mintOp = TokenManager.MintOperation({
407+
tick: "TEST",
408+
id: 0, // Invalid ID - should be >= 1
409+
amount: 1000
410+
});
411+
412+
bytes32 invalidMintHash = bytes32(uint256(0xDEAD));
413+
Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams(
414+
invalidMintHash,
415+
bob,
416+
mintContent,
417+
"erc-20",
418+
"mint",
419+
abi.encode(mintOp)
420+
);
421+
422+
// Create the ethscription - mint should fail due to invalid ID
423+
uint256 tokenId = ethscriptions.createEthscription(mintParams);
424+
425+
// Ethscription should still be created (but mint failed)
426+
assertEq(ethscriptions.ownerOf(tokenId), bob);
427+
428+
// Verify no tokens were minted due to invalid ID
429+
address tokenAddr = tokenManager.getTokenAddressByTick("TEST");
430+
EthscriptionsERC20 token = EthscriptionsERC20(tokenAddr);
431+
assertEq(token.balanceOf(bob), 0); // Bob should have no tokens
432+
433+
// Verify total minted didn't increase
434+
TokenManager.TokenInfo memory info = tokenManager.getTokenInfo(DEPLOY_TX_HASH);
435+
assertEq(info.totalMinted, 0);
436+
}
437+
438+
function testMintWithIdTooHigh() public {
439+
// Deploy the token first
440+
testTokenDeploy();
441+
442+
// Try to mint with ID beyond maxId (maxSupply/mintAmount = 1000000/1000 = 1000)
443+
vm.prank(bob);
444+
string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"1001","amt":"1000"}';
445+
446+
TokenManager.MintOperation memory mintOp = TokenManager.MintOperation({
447+
tick: "TEST",
448+
id: 1001, // Invalid ID - maxId is 1000
449+
amount: 1000
450+
});
451+
452+
bytes32 invalidMintHash = bytes32(uint256(0xBEEF));
453+
Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams(
454+
invalidMintHash,
455+
bob,
456+
mintContent,
457+
"erc-20",
458+
"mint",
459+
abi.encode(mintOp)
460+
);
461+
462+
// Create the ethscription - mint should fail due to ID too high
463+
uint256 tokenId = ethscriptions.createEthscription(mintParams);
464+
465+
// Ethscription should still be created (but mint failed)
466+
assertEq(ethscriptions.ownerOf(tokenId), bob);
467+
468+
// Verify no tokens were minted due to invalid ID
469+
address tokenAddr = tokenManager.getTokenAddressByTick("TEST");
470+
EthscriptionsERC20 token = EthscriptionsERC20(tokenAddr);
471+
assertEq(token.balanceOf(bob), 0); // Bob should have no tokens
472+
473+
// Verify total minted didn't increase
474+
TokenManager.TokenInfo memory info = tokenManager.getTokenInfo(DEPLOY_TX_HASH);
475+
assertEq(info.totalMinted, 0);
476+
}
477+
478+
function testMintWithMaxValidId() public {
479+
// Deploy the token first
480+
testTokenDeploy();
481+
482+
// Mint with the maximum valid ID (maxSupply/mintAmount = 1000000/1000 = 1000)
483+
vm.prank(bob);
484+
string memory mintContent = 'data:,{"p":"erc-20","op":"mint","tick":"TEST","id":"1000","amt":"1000"}';
485+
486+
TokenManager.MintOperation memory mintOp = TokenManager.MintOperation({
487+
tick: "TEST",
488+
id: 1000, // Maximum valid ID
489+
amount: 1000
490+
});
491+
492+
bytes32 validMintHash = bytes32(uint256(0xCAFE));
493+
Ethscriptions.CreateEthscriptionParams memory mintParams = createTokenParams(
494+
validMintHash,
495+
bob,
496+
mintContent,
497+
"erc-20",
498+
"mint",
499+
abi.encode(mintOp)
500+
);
501+
502+
uint256 tokenId = ethscriptions.createEthscription(mintParams);
503+
504+
// Verify Bob owns the mint ethscription NFT
505+
assertEq(ethscriptions.ownerOf(tokenId), bob);
506+
507+
// Verify Bob has the tokens (1000 * 10^18 with 18 decimals)
508+
address tokenAddr = tokenManager.getTokenAddressByTick("TEST");
509+
EthscriptionsERC20 token = EthscriptionsERC20(tokenAddr);
510+
assertEq(token.balanceOf(bob), 1000 ether); // Should have tokens
511+
512+
// Verify total minted increased
513+
TokenManager.TokenInfo memory info = tokenManager.getTokenInfo(DEPLOY_TX_HASH);
514+
assertEq(info.totalMinted, 1000);
515+
}
397516
}

0 commit comments

Comments
 (0)