"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignerWithAddress = exports.Impersonator = exports.setBalance = exports.mineBlock = exports.setNextBlockTimestamp = exports.setMiningMode = void 0;
const ethers_1 = require("ethers");
const setMiningMode = async (active, provider) => {
    await provider.send('evm_setAutomine', [active]);
};
exports.setMiningMode = setMiningMode;
const setNextBlockTimestamp = async (minutes, provider) => {
    await provider.send('evm_increaseTime', [minutes * 60]);
};
exports.setNextBlockTimestamp = setNextBlockTimestamp;
const mineBlock = async (provider) => {
    await provider.send('evm_mine', []);
};
exports.mineBlock = mineBlock;
async function setBalance(address, amount, provider) {
    await provider.send('hardhat_setBalance', [address, ethers_1.ethers.utils.parseEther(amount).toHexString()]);
}
exports.setBalance = setBalance;
class Impersonator {
    constructor(address) {
        this.address = address;
    }
    async impersonate(provider) {
        await provider.send('hardhat_impersonateAccount', [this.address]);
        return SignerWithAddress.create(provider.getSigner(this.address));
    }
    async stopImpersonate(provider) {
        await provider.send('hardhat_stopImpersonatingAccount', [this.address]);
    }
}
exports.Impersonator = Impersonator;
class SignerWithAddress extends ethers_1.ethers.Signer {
    constructor(address, _signer) {
        super();
        this.address = address;
        this._signer = _signer;
        this.provider = _signer.provider;
    }
    static async create(signer) {
        return new SignerWithAddress(await signer.getAddress(), signer);
    }
    async getAddress() {
        return this.address;
    }
    signMessage(message) {
        return this._signer.signMessage(message);
    }
    signTransaction(transaction) {
        return this._signer.signTransaction(transaction);
    }
    sendTransaction(transaction) {
        return this._signer.sendTransaction(transaction);
    }
    connect(provider) {
        return new SignerWithAddress(this.address, this._signer.connect(provider));
    }
    _signTypedData(...params) {
        return this._signer._signTypedData(...params);
    }
    toJSON() {
        return `<SignerWithAddress ${this.address}>`;
    }
}
exports.SignerWithAddress = SignerWithAddress;
