Skip to content

Commit

Permalink
feat: add nonce argument to JettonMaster contructor (#28)
Browse files Browse the repository at this point in the history
**Changes summary**:
Updated initial parameters of this contract to make possible mint
multiple jettons using single TON wallet. Second argument was added to
contructor. Previously `JettonMaster` constructor takes one argument -
owner address. It means that only one jetton could be minted per owner
address. Now users will set it random or as current UTC timestamp to
avoid contract address collision
  • Loading branch information
ya7on authored Jan 5, 2025
1 parent 6fa2563 commit a73b720
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contracts/jetton/master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract JettonMaster with TEP74JettonMaster, TEP89JettonDiscoverable, Deployabl
// Is token initialized (to avoid double init)
deployed: Bool = false;

init(owner: Address){
init(owner: Address, nonce: Int){
self.owner = owner;
let init = initOf JettonWallet(myAddress(), myAddress());
let data = init.data.beginParse();
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployJettonMaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JettonMaster } from '../wrappers/JettonMaster';
import { NetworkProvider } from '@ton/blueprint';

export async function run(provider: NetworkProvider) {
const jettonMaster = provider.open(await JettonMaster.fromInit(provider.sender().address!!));
const jettonMaster = provider.open(await JettonMaster.fromInit(provider.sender().address!!, 0n));

await jettonMaster.send(
provider.sender(),
Expand Down
12 changes: 10 additions & 2 deletions tests/JettonMaster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('JettonMaster', () => {
deployer = await blockchain.treasury('deployer');
other = await blockchain.treasury("other");

jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address));
jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));
jettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, deployer.address));
otherJettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, other.address));

Expand Down Expand Up @@ -66,6 +66,14 @@ describe('JettonMaster', () => {
});
});

it('should mint multiple jettons per wallet', async () => {
const jettonMasterSameNonce = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));;
expect(jettonMasterSameNonce.address).toEqualAddress(jettonMaster.address);

const jettonMasterDiffNonce = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 1n));;
expect(jettonMasterDiffNonce.address).not.toEqualAddress(jettonMaster.address);
});

it('should handle big strings', async () => {
const LONG_JETTON_NAME = JETTON_NAME.repeat(100);
const LONG_JETTON_DESCRIPTION = JETTON_DESCRIPTION.repeat(20);
Expand All @@ -75,7 +83,7 @@ describe('JettonMaster', () => {
expect(LONG_JETTON_DESCRIPTION.length).toBeGreaterThan(1024);
expect(LONG_JETTON_SYMBOL.length).toBeGreaterThan(1024);

const otherJettonMaster = blockchain.openContract(await JettonMaster.fromInit(other.address));
const otherJettonMaster = blockchain.openContract(await JettonMaster.fromInit(other.address, 0n));
await otherJettonMaster.send(
other.getSender(),
{
Expand Down
2 changes: 1 addition & 1 deletion tests/JettonWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('JettonMaster', () => {
deployer = await blockchain.treasury('deployer');
other = await blockchain.treasury("other");

jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address));
jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));
jettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, deployer.address));
otherJettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, other.address));

Expand Down
2 changes: 1 addition & 1 deletion tests/MaxSupply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('MaxSupply - Unlimited', () => {
deployer = await blockchain.treasury('deployer');
other = await blockchain.treasury("other");

jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address));
jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));
jettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, deployer.address));
otherJettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, other.address));

Expand Down
2 changes: 1 addition & 1 deletion tests/Mintable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Mintable', () => {
deployer = await blockchain.treasury('deployer');
other = await blockchain.treasury("other");

jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address));
jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));
jettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, deployer.address));
otherJettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, other.address));

Expand Down
2 changes: 1 addition & 1 deletion tests/Ownership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('OwnerShip', () => {
deployer = await blockchain.treasury('deployer');
other = await blockchain.treasury("other");

jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address));
jettonMaster = blockchain.openContract(await JettonMaster.fromInit(deployer.address, 0n));
jettonWallet = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, deployer.address));
jettonWallet2 = blockchain.openContract(await JettonWallet.fromInit(jettonMaster.address, other.address));

Expand Down

0 comments on commit a73b720

Please sign in to comment.