You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.4 KiB

import { Cell, Address, internal, beginCell, contractAddress, toNano, fromNano } from "ton";
import { storeDeposit, storeWithdraw } from "../output/jetton_TONB";
import { TON } from "./helpers";
import { wallet_data, owner, default_content, workchain } from './config';
import {TONB} from "../output/jetton_TONB";
import { TONBWallet } from '../output/jetton_TONBWallet';
export async function sendMessage(wallet: any, secretKey: Buffer, msg: {value: string | bigint, to: Address, bounce?: boolean, init?: {code?: Cell, data?: Cell}, body?: any}) {
let seqno: number = await wallet.getSeqno();
return await wallet.sendTransfer({
seqno,
secretKey,
messages: [internal(msg)]
});
}
export async function deposit(wallet: any, secretKey: Buffer, value_: bigint | number, tonb: Address) {
console.log('📤Sending deposit message to ', tonb, ' with value ', value_, '💎TON');
let value = BigInt(value_);
let msg_body_b = beginCell();
storeDeposit({amount: value as bigint, $$type: 'Deposit'})(msg_body_b);
let msg_body = msg_body_b.endCell();
let msg_value = value as bigint + BigInt(0.1 * TON());
let res = await sendMessage(wallet, secretKey, {value: msg_value, to: tonb, body: msg_body});
console.log(res);
console.log('======deposit message sent ======');
}
export async function withdraw(wallet: any, secretKey: Buffer, value_: bigint | number, tonb: Address) {
let value = BigInt(value_);
let msg_body_b = beginCell();
storeWithdraw({amount: value as bigint, $$type: 'Withdraw'})(msg_body_b);
let msg_body = msg_body_b.endCell();
let msg_value = BigInt(0.1 * TON());
await sendMessage(wallet, secretKey, {value: msg_value, to: tonb, body: msg_body});
}
export async function deployTONB(tonb_content?: any) {
if (!tonb_content) {
tonb_content = default_content;
}
let {my_wallet, secretKey, keyPair} = await wallet_data();
// Get deployment wallet balance
let balance: bigint = await my_wallet.getBalance();
// Compute init data for deployment
let init = await TONB.init(owner, tonb_content);
let destination_address = contractAddress(workchain, init);
let deployAmount = toNano('0.5');
let supply = 500;
let amount = BigInt(supply * Math.pow(10, 9));
// send a message on new address contract to deploy it
let seqno: number = await my_wallet.getSeqno();
console.log('🛠Preparing new outgoing massage from deployment wallet. Seqno = ', seqno, ', wallet = ', my_wallet.address);
console.log('Current deployment wallet balance = ', fromNano(balance).toString(), '💎TON');
// console.log('Totally supply for deployed Token = ', supply, ', amount = ', amount.toString());
let res = await my_wallet.sendTransfer({
seqno,
secretKey,
messages: [internal({
value: deployAmount,
to: destination_address,
init: {
code : init.code,
data : init.data
}
})]
});
console.log('======deployment message sent to ', destination_address, ' ======');
console.log(res);
return destination_address;
}
export async function getAddress(master_: string | Address, owner_: string | Address) {
let master = typeof master_ === 'string' ? Address.parse(master_) : master_;
let owner = typeof owner_ === 'string' ? Address.parse(owner_) : owner_;
return contractAddress(workchain, await TONBWallet.init(master, owner));
}