|
|
|
const subcommand = require('subcommand');
|
|
|
|
|
|
|
|
const { deployTONB, deposit, withdraw, transfer, blacklistAddress, getTONBOpen, getFoundationOpen, changeTONBOwner, createBlacklistVote, castVote, finishVote, requestUnstake, collectProfit } = require('./utils/interactions');
|
|
|
|
const { wallet_data, client, client4, staking_addr } = 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.w));
|
|
|
|
let tonb_addr = (await getTONBOpen(undefined, staking_addr)).address;
|
|
|
|
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.w));
|
|
|
|
let tonb_addr = (await getTONBOpen(undefined, staking_addr)).address;
|
|
|
|
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 getTONBOpen(undefined, staking_addr)).address;
|
|
|
|
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.w));
|
|
|
|
let tonb_addr = (await getTONBOpen(undefined, staking_addr)).address;
|
|
|
|
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(undefined, staking_addr);
|
|
|
|
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(undefined, staking_addr)).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));
|
|
|
|
await createBlacklistVote(my_wallet, secretKey, foundation.address,
|
|
|
|
addr, 40n, adminIndex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'get-vote',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'vote-id'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'foundation-address',
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
async command(opts) {
|
|
|
|
let foundation = await getFoundationOpen((await getTONBOpen(undefined, staking_addr)).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(undefined, staking_addr)).address);
|
|
|
|
if (opts._[2]) {
|
|
|
|
let foundation_addr = Address.parse(opts._[2]);
|
|
|
|
foundation = client.open(Foundation.fromAddress(foundation_addr));
|
|
|
|
}
|
|
|
|
let adminIndex = BigInt(parseInt(opts.w));
|
|
|
|
await castVote(my_wallet, secretKey, foundation.address, parseInt(opts._[0]), parseInt(opts._[1]), adminIndex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'finish-vote',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'vote-id'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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(undefined, staking_addr)).address);
|
|
|
|
if (opts._[1]) {
|
|
|
|
let foundation_addr = Address.parse(opts._[1]);
|
|
|
|
foundation = client.open(Foundation.fromAddress(foundation_addr));
|
|
|
|
}
|
|
|
|
let adminIndex = BigInt(parseInt(opts.w));
|
|
|
|
await finishVote(my_wallet, secretKey, foundation.address, parseInt(opts._[0]), adminIndex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'request-unstake',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'foundation-address',
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
async command(opts) {
|
|
|
|
let foundation = await getFoundationOpen((await getTONBOpen(undefined, staking_addr)).address);
|
|
|
|
if (opts._[0]) {
|
|
|
|
let foundation_addr = Address.parse(opts._[0]);
|
|
|
|
foundation = client.open(Foundation.fromAddress(foundation_addr));
|
|
|
|
}
|
|
|
|
let { my_wallet, secretKey } = await wallet_data();
|
|
|
|
await requestUnstake(my_wallet, secretKey, foundation.address, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'collect-profit',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'foundation-address',
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
wal_opt
|
|
|
|
],
|
|
|
|
async command(opts) {
|
|
|
|
let foundation = await getFoundationOpen((await getTONBOpen(undefined, staking_addr)).address);
|
|
|
|
if (opts._[0]) {
|
|
|
|
let foundation_addr = Address.parse(opts._[0]);
|
|
|
|
foundation = client.open(Foundation.fromAddress(foundation_addr));
|
|
|
|
}
|
|
|
|
let { my_wallet, secretKey } = await wallet_data(parseInt(opts.w));
|
|
|
|
await collectProfit(my_wallet, secretKey, foundation.address, parseInt(opts.w));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
const argv = process.argv.slice(2);
|
|
|
|
|
|
|
|
let opts = match(argv);
|
|
|
|
|