const subcommand = require('subcommand'); const { deployTONB, deposit, withdraw, transfer, blacklistAddress, getTONBOpen, getFoundationOpen, changeTONBOwner, createBlacklistVote } = require('./utils/interactions'); const { wallet_data, client, client4 } = require('./utils/config'); const { randomAddress, TON } = require('./utils/helpers'); const { toNano, Address } = require('ton'); const { TONB } = require('./output/jetton_TONB'); const { Foundation } = require('./output/jetton_Foundation'); const wal_opt = { name: 'wallet', abbr: 'w', default: '0', required: false }; const match = subcommand([ { name: 'deposit', options: [ { name: 'amount', help: 'Amount of TON to deposit', default: '0.45' }, { name: 'wallet', abbr: 'w', default: '0', required: false } ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts._[1])); let tonb_addr = await deployTONB(undefined, true); await deposit(my_wallet, secretKey, parseFloat(opts._[0]) * 1000000000, tonb_addr); } }, { name: 'withdraw', options: [ { name: 'amount', abbr: 'a', help: 'Amount of TON to withdraw', default: '0.2' }, { name: 'wallet', abbr: 'w', default: '0', required: false } ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts._[1])); let tonb_addr = await deployTONB(undefined, true); await withdraw(my_wallet, secretKey, parseFloat(opts._[0]) * 1000000000, tonb_addr); } }, { name: 'transfer', options: [ { name: 'amount', help: 'Amount of TON to transfer', default: '0.2' }, { name: 'address', help: 'Address to transfer TON to', default: randomAddress() }], async command(opts) { let { my_wallet, secretKey } = await wallet_data(); let tonb_addr = await deployTONB(undefined, true); await transfer(my_wallet, secretKey, parseFloat(opts._[0]) * 1000000000, tonb_addr, opts._[1]); } }, { name: 'blacklist', options: [ { name: 'address', }, { name: 'wallet', abbr: 'w', default: '0', required: false } ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts._[1])); let tonb_addr = await deployTONB(undefined, true); if (!opts._[0]) { opts._[0] = 'kQD7zbEMaWC2yMgSJXmIF7HbLr1yuBo2GnZF_CJNkUiGSVZ8'// my_wallet.address; } let addr = Address.parse(opts._[0]); await blacklistAddress(my_wallet, secretKey, tonb_addr, addr); } }, { name: 'change-tonb-owner', options: [ { name: 'address', }, { name: 'tonb', required: false }, wal_opt ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts.w)); let tonb = await getTONBOpen(); let addr = Address.parse(opts._[0]); if (opts._[1]) { let tonb_addr = Address.parse(opts._[1]); tonb = client4.open(TONB.fromAddress(tonb_addr)); } await changeTONBOwner(my_wallet, secretKey, tonb.address, addr); // await tonb.send(my_wallet, { value: toNano('0.1') }, { // $$type: 'SetOwner', owner: addr }); } }, { name: 'create-blacklist-vote', options: [ { name: 'address', }, { name: 'foundation-address', required: false }, wal_opt ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts.w)); let foundation = await getFoundationOpen((await getTONBOpen()).address); if (opts._[1]) { let foundation_addr = Address.parse(opts._[1]); foundation = client.open(Foundation.fromAddress(foundation_addr)); } let addr = Address.parse(opts._[0]); let adminIndex = BigInt(parseInt(opts.w)); // let msg = { // $$type: 'InitiateBlacklistVote', wallet: addr, // vote_time: 10n, quorum_percent: 50n, adminIndex // An admin has to create the vote // }; // await foundation.send(my_wallet, { value: toNano('1.1') }, msg); await createBlacklistVote(my_wallet, secretKey, foundation.address, addr, 10n, adminIndex); } }, { name: 'get-vote', options: [ { name: 'vote-id' }, { name: 'foundation-address', required: false } ], async command(opts) { let foundation = await getFoundationOpen((await getTONBOpen()).address); if (opts._[1]) { let foundation_addr = Address.parse(opts._[1]); foundation = client4.open(Foundation.fromAddress(foundation_addr)); } let vote = await foundation.getNthVote(opts._[0]); console.log(vote); } }, { name: 'vote', options: [ { name: 'vote-id' }, { name: 'vote', abbr: 'v', help: 'Vote for or against the proposal (1 - for, 2 - against)', }, { name: 'foundation-address', required: false }, wal_opt ], async command(opts) { let { my_wallet, secretKey } = await wallet_data(parseInt(opts.w)); let foundation = await getFoundationOpen((await getTONBOpen()).address); if (opts._[2]) { let foundation_addr = Address.parse(opts._[2]); foundation = client.open(Foundation.fromAddress(foundation_addr)); } await foundation.send(my_wallet, { value: toNano('0.1') }, { $$type: 'VoteMsg', voteId: opts._[0], vote: opts._[1], adminIndex: BigInt(parseInt(opts.w)) }); } } ]); const argv = process.argv.slice(2); let opts = match(argv);