import { BatchCall } from '@aztec/aztec.js/contracts';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
export async function deployToken(wallet, admin, initialAdminBalance, logger) {
    logger.info(`Deploying Token contract...`);
    const { receipt: { contract, instance } } = await TokenContract.deploy(wallet, admin, 'TokenName', 'TokenSymbol', 18).send({
        from: admin,
        wait: {
            returnReceipt: true
        }
    });
    if (initialAdminBalance > 0n) {
        await mintTokensToPrivate(contract, admin, admin, initialAdminBalance);
    }
    logger.info('L2 contract deployed');
    return {
        contract,
        instance
    };
}
export async function mintTokensToPrivate(token, minter, recipient, amount, additionalScopes) {
    await token.methods.mint_to_private(recipient, amount).send({
        from: minter,
        additionalScopes
    });
}
export async function expectTokenBalance(wallet, token, owner, expectedBalance, logger) {
    // Then check the balance
    const contractWithWallet = TokenContract.at(token.address, wallet);
    const { result: balance } = await contractWithWallet.methods.balance_of_private(owner).simulate({
        from: owner
    });
    logger.info(`Account ${owner} balance: ${balance}`);
    expect(balance).toBe(expectedBalance);
}
export async function mintNotes(wallet, minter, recipient, asset, noteAmounts) {
    // We can only mint 5 notes at a time, since that's the maximum number of calls our entrypoints allow
    // TODO(#13024): mint as many notes as possible in a single tx
    const notesPerIteration = 5;
    for(let mintedNotes = 0; mintedNotes < noteAmounts.length; mintedNotes += notesPerIteration){
        const toMint = noteAmounts.slice(mintedNotes, mintedNotes + notesPerIteration);
        const actions = toMint.map((amt)=>asset.methods.mint_to_private(recipient, amt));
        await new BatchCall(wallet, actions).send({
            from: minter
        });
    }
    return noteAmounts.reduce((prev, curr)=>prev + curr, 0n);
}
