"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForBalance = exports.sleep = void 0;
const decimal_js_1 = __importDefault(require("decimal.js"));
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
exports.sleep = sleep;
const waitForBalance = async (wallet, amount, asset = [], timeoutMs = 1000) => {
    let balance = new decimal_js_1.default(await wallet.getBalance(asset));
    const startingBalance = balance;
    amount = new decimal_js_1.default(amount);
    while (!amount.eq(balance) && balance.sub(startingBalance).abs().lte(startingBalance.sub(amount).abs())) {
        await (0, exports.sleep)(timeoutMs);
        balance = new decimal_js_1.default(await wallet.getBalance(asset));
    }
    return balance;
};
exports.waitForBalance = waitForBalance;
