Skip to content

Commit

Permalink
fix: update metadata storing
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Oct 28, 2024
1 parent 63cadcf commit e9cacf1
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 124 deletions.
4 changes: 1 addition & 3 deletions contracts/errors.tact
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ const ERROR_CODE_NOT_ENOUGH_BALANCE: Int = 6901;
const ERROR_CODE_NEED_FEE: Int = 6902;
// Jetton already initialized
const ERROR_JETTON_INITIALIZED: Int = 6903;
// Jetton already initialized
const ERROR_JETTON_UNKNOWN_PARAMETER: Int = 6904;
// Jetton max supply exceeded
const ERROR_MAX_SUPPLY_EXCEEDED: Int = 6905;
const ERROR_MAX_SUPPLY_EXCEEDED: Int = 6904;
36 changes: 12 additions & 24 deletions contracts/jetton/master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,41 @@ contract JettonMaster with TEP74JettonMaster, TEP89JettonDiscoverable, Deployabl
jetton_wallet_code: Cell;
// System cell of jetton wallet contract (Tact feature)
jetton_wallet_system: Cell;
// Jetton name field in metadata
jetton_name: String = "Default name";
// Jetton description field in metadata
jetton_description: String = "Jetton default description";
// Jetton symbol field in metadata
jetton_symbol: String = "JETTON";
// Jetton metadata
metadata: OnchainMetadata;
// Is token initialized (to avoid double init)
deployed: Bool = false;
init(owner: Address){
self.owner = owner;
let init = initOf JettonWallet(myAddress(), myAddress());
let data = init.data.beginParse();
let metadata = newMetadata();
metadata.set("name", "Default name..".asSlice());
metadata.set("description", "Jetton default description".asSlice());
metadata.set("symbol", "JETTON".asSlice());
self.metadata = metadata;
self.jetton_wallet_code = init.code;
self.jetton_wallet_system = data.loadRef();
}

receive(msg: JettonInit){
self.requireOwner();
nativeThrowIf(ERROR_JETTON_INITIALIZED, self.deployed);
self.jetton_name = msg.jetton_name;
self.jetton_description = msg.jetton_description;
self.jetton_symbol = msg.jetton_symbol;
self.metadata.set("name", msg.jetton_name);
self.metadata.set("description", msg.jetton_description);
self.metadata.set("symbol", msg.jetton_symbol);
self.max_supply = msg.max_supply;
self.notify(JettonInitOk{query_id: msg.query_id}.toCell());
self.deployed = true;
}

receive(msg: JettonSetParameter){
self.requireOwner();
let updated = false;
if (msg.key == "jetton_name") {
updated = true;
self.jetton_name = msg.value.asString();
}
if (msg.key == "jetton_description") {
updated = true;
self.jetton_description = msg.value.asString();
}
if (msg.key == "jetton_symbol") {
updated = true;
self.jetton_symbol = msg.value.asString();
}
if (msg.key == "max_supply") {
updated = true;
self.max_supply = msg.value.loadCoins();
return;
}
nativeThrowUnless(ERROR_JETTON_UNKNOWN_PARAMETER, updated);
self.metadata.set(msg.key, msg.value);
}

receive(msg: JettonMint){
Expand Down
6 changes: 3 additions & 3 deletions contracts/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ message(0xd1735400) TakeWalletAddress {
}
message(0x133701) JettonInit {
query_id: Int as uint64;
jetton_name: String;
jetton_description: String;
jetton_symbol: String;
jetton_name: Slice;
jetton_description: Slice;
jetton_symbol: Slice;
max_supply: Int as coins;
}
message(0x133702) JettonInitOk {
Expand Down
16 changes: 6 additions & 10 deletions contracts/teps/tep64.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,23 @@ fun newMetadata(): OnchainMetadata {
// Add new key/value pair to metadata

mutates extends fun set(self: OnchainMetadata, key: String, value: Slice) {
self.inner.set(sha256(key), beginCell().storeSlice(value).endCell());
self.inner.set(sha256(key), beginCell().storeUint(0, 8).storeSlice(value).endCell());
}

// Build `Cell` from metadata that corresponds with standard

extends fun toCell(self: OnchainMetadata): Cell {
mutates extends fun buildCell(self: OnchainMetadata): Cell {
return beginCell().storeUint(0, 8).storeDict(self.inner.asCell()!!).endCell();
}

// Trait for creating onchain metadata
// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md

trait TEP64Metadata {
metadata: OnchainMetadata;

// Create jetton master onchain metadata
fun jetton_master_metadata(name: String, description: String, symbol: String): Cell {
let metadata = newMetadata();
metadata.set("name", name.asSlice());
let d = beginTailString();
d.append(description);
metadata.set("description", description.asSlice());
metadata.set("symbol", symbol.asSlice());
return metadata.toCell();
fun get_metadata(): Cell {
return self.metadata.buildCell();
}
}
11 changes: 3 additions & 8 deletions contracts/teps/tep74.tact
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ trait TEP74JettonMaster with TEP64Metadata, DiscoverWalletAddress {
jetton_wallet_code: Cell;
// System cell of jetton wallet contract (Tact feature)
jetton_wallet_system: Cell;
// Jetton name field in metadata
jetton_name: String;
// Jetton description field in metadata
jetton_description: String;
// Jetton symbol field in metadata
jetton_symbol: String;
// Jetton metadata
metadata: OnchainMetadata;

receive(msg: JettonBurnInternal){
let ctx = context();
Expand All @@ -48,13 +44,12 @@ trait TEP74JettonMaster with TEP64Metadata, DiscoverWalletAddress {
}

get fun get_jetton_data(): JettonMasterData {
let jetton_content = self.jetton_master_metadata(self.jetton_name, self.jetton_description, self.jetton_symbol);
return
JettonMasterData{
total_supply: self.current_supply,
mintable: (self.max_supply - self.current_supply) > 0,
owner: self.owner,
jetton_content: jetton_content,
jetton_content: self.get_metadata(),
jetton_wallet_code: self.jetton_wallet_code
};
}
Expand Down
31 changes: 28 additions & 3 deletions scripts/deployJettonMaster.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { toNano } from '@ton/core';
import { Builder, toNano } from '@ton/core';
import { JettonMaster } from '../wrappers/JettonMaster';
import { NetworkProvider } from '@ton/blueprint';

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

await jettonMaster.send(
provider.sender(),
Expand All @@ -18,5 +18,30 @@ export async function run(provider: NetworkProvider) {

await provider.waitForDeploy(jettonMaster.address);

// run methods on `jettonMaster`
await jettonMaster.send(
provider.sender(),
{
value: toNano('0.05'),
},
{
$$type: 'JettonInit',
query_id: 0n,
jetton_name: new Builder().storeStringTail('Jetton name').asSlice(),
jetton_description: new Builder().storeStringTail('Long' + ' long '.repeat(1) + 'description').asSlice(),
jetton_symbol: new Builder().storeStringTail('SMBL').asSlice(),
max_supply: toNano(1337),
}
);
await jettonMaster.send(
provider.sender(),
{
value: toNano('0.05'),
},
{
$$type: 'JettonMint',
query_id: 0n,
destination: provider.sender().address!!,
amount: toNano("10"),
}
);
}
Loading

0 comments on commit e9cacf1

Please sign in to comment.