Skip to content

Commit 81b08de

Browse files
max-supply-check
1 parent 36b10b9 commit 81b08de

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

packages/game-passes/contracts/GamePasses.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ contract SandboxPasses1155Upgradeable is
7272
string metadata;
7373
uint256 maxPerWallet; // max tokens that can be minted per wallet
7474
address treasuryWallet; // specific treasury wallet for this token
75+
uint256 totalMinted; // total tokens already minted
7576
mapping(address => uint256) mintedPerWallet; // track mints per wallet
7677
mapping(address => bool) transferWhitelist; // whitelist for transfers
7778
}
@@ -1189,10 +1190,12 @@ contract SandboxPasses1155Upgradeable is
11891190
* - Token has a max supply (> 0) and
11901191
* - Current supply + amount would exceed max supply
11911192
*/
1192-
function _checkMaxSupply(uint256 tokenId, uint256 amount) private view {
1193+
function _checkMaxSupply(uint256 tokenId, uint256 amount) private {
11931194
TokenConfig storage config = _tokenStorage().tokenConfigs[tokenId];
1195+
// update the config total minted and check if it exceeds the max supply
1196+
config.totalMinted += amount;
11941197
if (config.maxSupply > 0) {
1195-
if (totalSupply(tokenId) + amount > config.maxSupply) {
1198+
if (config.totalMinted > config.maxSupply) {
11961199
revert MaxSupplyExceeded(tokenId);
11971200
}
11981201
}

packages/game-passes/test/GamePasses.test.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,47 @@ describe('SandboxPasses1155Upgradeable', function () {
415415
'AccessControlUnauthorizedAccount',
416416
);
417417
});
418+
419+
it('should not allow adminBatchMint to exceed max supply with duplicate token IDs', async function () {
420+
const {sandboxPasses, admin, TOKEN_ID_1} =
421+
await loadFixture(runCreateTestSetup);
422+
423+
// Let's assume TOKEN_ID_1 has a max supply of 100 (from test setup)
424+
// First mint 90 tokens
425+
await sandboxPasses
426+
.connect(admin)
427+
.adminMint(admin.address, TOKEN_ID_1, 90);
428+
429+
// Now try to mint the same token ID twice in a batch (5 + 6 = 11)
430+
// This would exceed the max supply of 100 (90 + 11 > 100)
431+
await expect(
432+
sandboxPasses
433+
.connect(admin)
434+
.adminBatchMint(admin.address, [TOKEN_ID_1, TOKEN_ID_1], [5, 6]),
435+
).to.be.revertedWithCustomError(sandboxPasses, 'MaxSupplyExceeded');
436+
});
437+
438+
it('should not allow adminMultiRecipientMint to exceed max supply with duplicate token IDs', async function () {
439+
const {sandboxPasses, admin, user1, TOKEN_ID_1} =
440+
await loadFixture(runCreateTestSetup);
441+
442+
// First mint 90 tokens
443+
await sandboxPasses
444+
.connect(admin)
445+
.adminMint(admin.address, TOKEN_ID_1, 90);
446+
447+
// Now try to mint the same token ID to different recipients (6 + 5 = 11)
448+
// This would exceed the max supply of 100 (90 + 11 > 100)
449+
await expect(
450+
sandboxPasses
451+
.connect(admin)
452+
.adminMultiRecipientMint(
453+
[admin.address, user1.address],
454+
[TOKEN_ID_1, TOKEN_ID_1],
455+
[6, 5],
456+
),
457+
).to.be.revertedWithCustomError(sandboxPasses, 'MaxSupplyExceeded');
458+
});
418459
});
419460

420461
describe('Signature-Based Minting', function () {
@@ -1306,6 +1347,69 @@ describe('SandboxPasses1155Upgradeable', function () {
13061347
),
13071348
).to.be.revertedWithCustomError(sandboxPasses, 'InvalidSigner');
13081349
});
1350+
1351+
it('should not allow batchMint to exceed max supply with duplicate token IDs', async function () {
1352+
const {
1353+
sandboxPasses,
1354+
signer,
1355+
user1,
1356+
admin,
1357+
paymentToken,
1358+
TOKEN_ID_1,
1359+
createMintSignature,
1360+
} = await loadFixture(runCreateTestSetup);
1361+
1362+
// First mint 90 tokens
1363+
await sandboxPasses
1364+
.connect(admin)
1365+
.adminMint(admin.address, TOKEN_ID_1, 95);
1366+
1367+
const price = ethers.parseEther('0.1');
1368+
const deadline = (await time.latest()) + 3600;
1369+
const nonce1 = 0;
1370+
const nonce2 = 1;
1371+
1372+
// Approve payment token
1373+
await paymentToken
1374+
.connect(user1)
1375+
.approve(await sandboxPasses.getAddress(), price * 2n);
1376+
1377+
// Create signatures for the same token ID
1378+
const signature1 = await createMintSignature(
1379+
signer,
1380+
user1.address,
1381+
TOKEN_ID_1,
1382+
3,
1383+
price,
1384+
deadline,
1385+
nonce1,
1386+
);
1387+
1388+
const signature2 = await createMintSignature(
1389+
signer,
1390+
user1.address,
1391+
TOKEN_ID_1,
1392+
3,
1393+
price,
1394+
deadline,
1395+
nonce2,
1396+
);
1397+
1398+
// Try to batch mint the same token ID twice (6 + 5 = 11)
1399+
// This would exceed the max supply of 100 (90 + 11 > 100)
1400+
await expect(
1401+
sandboxPasses
1402+
.connect(user1)
1403+
.batchMint(
1404+
user1.address,
1405+
[TOKEN_ID_1, TOKEN_ID_1],
1406+
[3, 3],
1407+
[price, price],
1408+
[deadline, deadline],
1409+
[signature1, signature2],
1410+
),
1411+
).to.be.revertedWithCustomError(sandboxPasses, 'MaxSupplyExceeded');
1412+
});
13091413
});
13101414

13111415
describe('Burn and Mint Operations', function () {
@@ -1485,6 +1589,36 @@ describe('SandboxPasses1155Upgradeable', function () {
14851589
3,
14861590
);
14871591
});
1592+
1593+
it('should not allow operatorBatchBurnAndMint to exceed max supply with duplicate token IDs', async function () {
1594+
const {sandboxPasses, operator, admin, TOKEN_ID_1, TOKEN_ID_2} =
1595+
await loadFixture(runCreateTestSetup);
1596+
1597+
// First mint some tokens of TOKEN_ID_2 to burn
1598+
await sandboxPasses
1599+
.connect(admin)
1600+
.adminMint(admin.address, TOKEN_ID_2, 10);
1601+
1602+
// Then mint 90 tokens of TOKEN_ID_1
1603+
await sandboxPasses
1604+
.connect(admin)
1605+
.adminMint(admin.address, TOKEN_ID_1, 90);
1606+
1607+
// Try to mint the same token ID twice in a batch mint (6 + 5 = 11)
1608+
// This would exceed the max supply of 100 (90 + 11 > 100)
1609+
await expect(
1610+
sandboxPasses
1611+
.connect(operator)
1612+
.operatorBatchBurnAndMint(
1613+
admin.address,
1614+
admin.address,
1615+
[TOKEN_ID_2, TOKEN_ID_2],
1616+
[5, 5],
1617+
[TOKEN_ID_1, TOKEN_ID_1],
1618+
[6, 5],
1619+
),
1620+
).to.be.revertedWithCustomError(sandboxPasses, 'MaxSupplyExceeded');
1621+
});
14881622
});
14891623

14901624
describe('Burn and Mint Signature Validation', function () {

0 commit comments

Comments
 (0)