Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JettonMaster getJettonData #46

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions src/jetton/JettonMaster.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Whales Corp.
* Copyright (c) Whales Corp.
* All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
Expand All @@ -11,18 +11,44 @@ import { createTestClient } from "../utils/createTestClient";
import { JettonMaster } from "./JettonMaster";
import { JettonWallet } from "./JettonWallet";

describe('JettonMaster', () => {
it('should resolve jetton wallet address', async () => {
let client = createTestClient('mainnet');
let master = client.open(JettonMaster.create(Address.parse('EQDQoc5M3Bh8eWFephi9bClhevelbZZvWhkqdo80XuY_0qXv')));
let walletAddress = await master.getWalletAddress(Address.parse('EQCo6VT63H1vKJTiUo6W4M8RrTURCyk5MdbosuL5auEqpz-C'));
let jettonData = await master.getJettonData();
expect(walletAddress.equals(Address.parse('EQDslTlGmbLTFi0j4MPT7UVggWR7XRDI2bW6vmNG6Tc_FBDE'))).toBe(true);
expect(jettonData.mintable).toBe(true);
expect(jettonData.adminAddress.equals(Address.parse('EQCppzUtmGSMg3FIRlFLzhToqbaC0xjmjzOn0o7H4M8Aua1t'))).toBe(true);

let wallet = client.open(JettonWallet.create(walletAddress));
let balance = await wallet.getBalance();
expect(balance).toBe(0n);
});
});
describe("JettonMaster", () => {
it("should resolve jetton wallet address", async () => {
let client = createTestClient("mainnet");
let master = client.open(
JettonMaster.create(
Address.parse("EQDQoc5M3Bh8eWFephi9bClhevelbZZvWhkqdo80XuY_0qXv")
)
);
let walletAddress = await master.getWalletAddress(
Address.parse("EQCo6VT63H1vKJTiUo6W4M8RrTURCyk5MdbosuL5auEqpz-C")
);
let jettonData = await master.getJettonData();
expect(
walletAddress.equals(
Address.parse("EQDslTlGmbLTFi0j4MPT7UVggWR7XRDI2bW6vmNG6Tc_FBDE")
)
).toBe(true);
expect(jettonData.mintable).toBe(true);
expect(
jettonData.adminAddress?.equals(
Address.parse("EQCppzUtmGSMg3FIRlFLzhToqbaC0xjmjzOn0o7H4M8Aua1t")
)
).toBe(true);

let wallet = client.open(JettonWallet.create(walletAddress));
let balance = await wallet.getBalance();
expect(balance).toBe(0n);
});
it("should resolve jetton master data", async () => {
let client = createTestClient("mainnet");
let master = client.open(
JettonMaster.create(
Address.parse("EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO")
)
);
let jettonData = await master.getJettonData();

expect(jettonData.mintable).toBe(true);
expect(jettonData.adminAddress).toBe(null);
});
});
67 changes: 35 additions & 32 deletions src/jetton/JettonMaster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Whales Corp.
* Copyright (c) Whales Corp.
* All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
Expand All @@ -9,35 +9,38 @@
import { Address, beginCell, Contract, ContractProvider } from "@ton/core";

export class JettonMaster implements Contract {
static create(address: Address) {
return new JettonMaster(address);
}

static create(address: Address) {
return new JettonMaster(address);
}

readonly address: Address;

constructor(address: Address) {
this.address = address;
}

async getWalletAddress(provider: ContractProvider, owner: Address) {
let res = await provider.get('get_wallet_address', [{ type: 'slice', cell: beginCell().storeAddress(owner).endCell() }]);
return res.stack.readAddress();
}

async getJettonData(provider: ContractProvider) {
let res = await provider.get('get_jetton_data', []);
let totalSupply = res.stack.readBigNumber();
let mintable = res.stack.readBoolean();
let adminAddress = res.stack.readAddress();
let content = res.stack.readCell();
let walletCode = res.stack.readCell();
return {
totalSupply,
mintable,
adminAddress,
content,
walletCode
};
}
}
readonly address: Address;

constructor(address: Address) {
this.address = address;
}

async getWalletAddress(provider: ContractProvider, owner: Address) {
let res = await provider.get("get_wallet_address", [
{ type: "slice", cell: beginCell().storeAddress(owner).endCell() },
]);
return res.stack.readAddress();
}

async getJettonData(provider: ContractProvider) {
let res = await provider.get("get_jetton_data", []);

const totalSupply = res.stack.readBigNumber();
const mintable = res.stack.readBoolean();
const adminAddress = res.stack.readAddressOpt();
const content = res.stack.readCell();
const walletCode = res.stack.readCell();

return {
totalSupply,
mintable,
adminAddress,
content,
walletCode,
};
}
}