"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const token_math_1 = require("@melonproject/token-math");
const transactionFactory_1 = require("../../../utils/solidity/transactionFactory");
const getContract_1 = require("../../../utils/solidity/getContract");
const ensure_1 = require("../../../utils/guards/ensure");
const Contracts_1 = require("../../../Contracts");
const guard = (environment, params, engineAddress) => __awaiter(this, void 0, void 0, function* () {
    const engine = getContract_1.getContract(environment, Contracts_1.Contracts.Engine, engineAddress);
    // // TODO: Fix that check
    // const lastThaw = new BigInteger(await engine.methods.lastThaw().call());
    // const thawingDelay = new BigInteger(
    //   await engine.methods.THAWING_DELAY().call(),
    // );
    // const now = new BigInteger(Math.floor(new Date().getTime() / 1000));
    // console.log(
    //   now.toString(),
    //   lastThaw.toString(),
    //   thawingDelay.toString(),
    //   add(thawingDelay, lastThaw),
    //   );
    //   ensure(
    //     greaterThan(now, add(thawingDelay, lastThaw)),
    //     'Not enough time has passed since the last thaw',
    //     );
    const frozenEther = yield engine.methods.frozenEther().call();
    ensure_1.ensure(token_math_1.greaterThan(new token_math_1.BigInteger(frozenEther), new token_math_1.BigInteger(0)), 'No frozen ether to thaw');
});
exports.thaw = transactionFactory_1.transactionFactory('thaw', Contracts_1.Contracts.Engine, guard);
