rps-project/scripts/6.withdrawToUser.ts
2024-09-10 11:46:05 +03:00

19 lines
979 B
TypeScript

import { Address, toNano } from '@ton/core';
import { MainBalance } from '../wrappers/MainBalance';
import { compile, NetworkProvider } from '@ton/blueprint';
import contractConfig from '../config/contract.config';
import { calcPercent, getMainBalanceContract } from './utils';
export async function run(provider: NetworkProvider) {
const ui = provider.ui();
const mainBalance = await getMainBalanceContract(provider);
const depositAddress = contractConfig.script.depositAddress;
const depositAmount = contractConfig.script.depositAmount;
const withdrawAmount = depositAmount - calcPercent(depositAmount, contractConfig.totalFee);
ui.write(`Current contract balance: ${await mainBalance.getBalance()}`);
await mainBalance.sendWithdraw(provider.sender(), Address.parse(depositAddress), toNano(withdrawAmount))
ui.write(`${depositAmount} - ${contractConfig.totalFee}% = ${withdrawAmount} TON was withdrawn to user address: ${depositAddress}`);
}