import { Cell, Address, internal, beginCell, contractAddress, toNano, fromNano, SendMode } from "ton"; import { storeDeposit, storeWithdraw, storeTokenTransfer, storeBlacklistWallet } 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, sendMode: SendMode.PAY_GAS_SEPARATLY + SendMode.IGNORE_ERRORS, 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_body = msg_body_b.storeUint(0x8999b164, 32).storeUint(value, 257).endCell(); let msg_value = value as bigint + toNano('0.1'); 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 = toNano('0.11'); await sendMessage(wallet, secretKey, { value: msg_value, to: tonb, body: msg_body }); } export async function transfer(wallet: any, secretKey: Buffer, value_: bigint | number, tonb: Address, to: Address) { let value = BigInt(value_); let msg_body_b = beginCell(); storeTokenTransfer({ amount: value as bigint, destination: to, queryId: 0n, forwardTonAmount: 0n, $$type: 'TokenTransfer', forwardPayload: beginCell().endCell(), responseDestination: null, customPayload: null })(msg_body_b); let msg_body = msg_body_b.endCell(); let msg_value = toNano('0.11'); let wallet_addr = await getWalletAddress(tonb, wallet.address); // log about the transfer with the wallet address, amount, and emojis console.log('📤Sending transfer message to ', wallet_addr, ' with value ', value_, '💎TON'); await sendMessage(wallet, secretKey, { value: msg_value, to: wallet_addr, body: msg_body }); } export async function blacklistAddress(wallet: any, secretKey: Buffer, tonb: Address, address: Address) { let msg_body_b = beginCell(); storeBlacklistWallet({ wallet: address, $$type: 'BlacklistWallet' })(msg_body_b); let msg_body = msg_body_b.endCell(); let msg_value = toNano('0.11'); await sendMessage(wallet, secretKey, { value: msg_value, to: tonb, body: msg_body }); } export async function getTONBState(tonb_content?: any) { if (!tonb_content) { tonb_content = default_content; } return await TONB.init(owner, tonb_content); } export async function getTONB(tonb_content?: any) { if (!tonb_content) { tonb_content = default_content; } return await TONB.fromInit(owner, tonb_content); } export async function deployTONB(tonb_content?: any, cancel: boolean = false) { let { my_wallet, secretKey, keyPair } = await wallet_data(); // Get deployment wallet balance let balance: bigint = await my_wallet.getBalance(); let init = await getTONBState(tonb_content); // Compute init data for deployment let destination_address = contractAddress(workchain, init); let deployAmount = toNano('0.1'); 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()); if (cancel) { return destination_address; } 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 getWalletAddress(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)); }