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

feat: added mint to initMessage in jetton-minter #95

Open
wants to merge 1 commit into
base: main
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
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

WALLET_ADDRESS="0QA5pv0UuiPvhQaaetD5IQ2qEVFB68bXWsG4A0RkR4sB4tyb"

TESTNET=1
DEPLOYER_WALLET=org.ton.wallets.v3r2
DEPLOYER_MNEMONIC="gloom panda ..."

TOTAL_SUPPLY=0
AMOUNT_TO_MINT=100

JETTON_NAME="Funy Girl"
JETTON_SYMBOL="FNG"
JETTON_IMAGE="https://FunyGirl.github.io/website/logo.png"
JETTON_DESCRIPTION="This is Contract Address for Funny Girl Description"
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"typescript.tsdk": "node_modules/typescript/lib",
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 100
}
}
6 changes: 4 additions & 2 deletions build/_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function main() {
// initialize globals
const client = new TonClient({ endpoint: `https://${isTestnet ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` });
const deployerWalletType = "org.ton.wallets.v3.r2"; // also see WalletV3R2Source class used below
const newContractFunding = toNano(0.02); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent
const newContractFunding = toNano(0.25); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent
const workchain = 0; // normally 0, only special contracts should be deployed to masterchain (-1)

// make sure we have a wallet mnemonic to deploy from (or create one if not found)
Expand All @@ -56,7 +56,7 @@ async function main() {
const walletContract = WalletContract.create(client, WalletV3R2Source.create({ publicKey: walletKey.publicKey, workchain }));
console.log(` - Wallet address used to deploy from is: ${walletContract.address.toFriendly()}`);
const walletBalance = await client.getBalance(walletContract.address);
if (walletBalance.lt(toNano(0.2))) {
if (walletBalance.lt(toNano(0.25))) {
console.log(` - ERROR: Wallet has less than 0.2 TON for gas (${fromNano(walletBalance)} TON), please send some TON for gas first`);
process.exit(1);
} else {
Expand Down Expand Up @@ -158,4 +158,6 @@ async function performPostDeploymentTest(rootContract: string, deployInitScript:
}
console.log(` - Running a post deployment test:`);
await deployInitScript.postDeployTest(walletContract, secretKey, newContractAddress);

console.log("finished.......")
}
58 changes: 50 additions & 8 deletions build/jetton-minter.deploy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Cell, beginCell, Address, WalletContract, beginDict, Slice } from "ton";
import { Cell, beginCell, Address, WalletContract, beginDict, Slice, toNano } from "ton";

import walletHex from "./jetton-wallet.compiled.json";
import minterHex from "./jetton-minter.compiled.json";
import { Sha256 } from "@aws-crypto/sha256-js";
import BN from "bn.js";
import { OPS } from "../lib/ops";
import { toDecimalsBN } from "../lib/utils";


export const JETTON_WALLET_CODE = Cell.fromBoc(walletHex.hex)[0];
export const JETTON_MINTER_CODE = Cell.fromBoc(minterHex.hex)[0]; // code cell from build output
Expand All @@ -15,13 +18,15 @@ const SNAKE_PREFIX = 0x00;
// - Data is stored on-chain (except for the image data itself)
// - Owner should usually be the deploying wallet's address.
const jettonParams = {
owner: Address.parse("EQD4gS-Nj2Gjr2FYtg-s3fXUvjzKbzHGZ5_1Xe_V0-GCp0p2"),
name: "MyJetton",
symbol: "JET1",
image: "https://www.linkpicture.com/q/download_183.png", // Image url
description: "My jetton",
owner: Address.parse(`${process.env.WALLET_ADDRESS}`),
name: `${process.env.JETTON_NAME}`,
symbol: `${process.env.JETTON_SYMBOL}`,
image: `${process.env.JETTON_IMAGE}`,
description: `${process.env.JETTON_DESCRIPTION}`
};



export type JettonMetaDataKeys = "name" | "description" | "image" | "symbol";

const jettonOnChainMetadataSpec: {
Expand Down Expand Up @@ -122,7 +127,7 @@ export function jettonMinterInitData(
metadata: { [s in JettonMetaDataKeys]?: string }
): Cell {
return beginCell()
.storeCoins(0)
.storeCoins(toNano(`${process.env.TOTAL_SUPPLY}`))
.storeAddress(owner)
.storeRef(buildTokenMetadataCell(metadata))
.storeRef(JETTON_WALLET_CODE)
Expand All @@ -139,9 +144,46 @@ export function initData() {
});
}

// return the init Cell of the mint for deploy- first time
export function mintBody(
owner: Address,
jettonValue: BN,
transferToJWallet: BN,
queryId: number,
): Cell {

console.log("minting for deploy...");

return beginCell()
.storeUint(OPS.Mint, 32)
.storeUint(queryId, 64) // queryid
.storeAddress(owner)
.storeCoins(transferToJWallet)
.storeRef(
// internal transfer message
beginCell()
.storeUint(OPS.InternalTransfer, 32)
.storeUint(0, 64)
.storeCoins(jettonValue)
.storeAddress(null)
.storeAddress(owner)
.storeCoins(toNano(0.001))
.storeBit(false) // forward_payload in this slice, not separate cell
.endCell(),
)
.endCell();
}


// return the op that should be sent to the contract on deployment, can be "null" to send an empty message
export function initMessage() {
return null; // TODO?
//return null;
return initMint();
}

export function initMint() {
const amountToMint = toDecimalsBN(Number(`${process.env.AMOUNT_TO_MINT}`), 9);
return mintBody(Address.parse(`${process.env.WALLET_ADDRESS}`), amountToMint, toNano(0.2), 10);
}

// optional end-to-end sanity test for the actual on-chain contract to see it is actually working on-chain
Expand Down
16 changes: 16 additions & 0 deletions lib/ops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum OPS {
// Transfer = 0xf8a7ea5,
// Transfer_notification = 0x7362d09c,
// Internal_transfer = 0x178d4519,
// Excesses = 0xd53276db,
// Burn = 0x595f07bc,
// Burn_notification = 0x7bdd97de,
// ClaimRewards = 0x5a3e000,
// ClaimRewardsNotification = 0x5a3e001,
//ChangeAdmin = 3,
//ReplaceMetadata = 4,
Mint = 21,
InternalTransfer = 0x178d4519,
Transfer = 0xf8a7ea5,
Burn = 0x595f07bc
}
8 changes: 8 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import BigNumber from "bignumber.js";
import BN from "bn.js";

const ten = new BigNumber(10);

export function toDecimalsBN(num: number | string, decimals: number | string) {
return new BN(BigNumber(num).multipliedBy(ten.pow(decimals)).toFixed(0));
}
Loading
Loading