import { loadContractArtifact } from '@aztec/stdlib/abi';
import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/stdlib/hash';
import FeeJuiceJson from '../../artifacts/FeeJuice.json' with {
    type: 'json'
};
import { makeProtocolContract } from '../make_protocol_contract.js';
import { ProtocolContractAddress } from '../protocol_contract_data.js';
export const FeeJuiceArtifact = loadContractArtifact(FeeJuiceJson);
let protocolContract;
/** Returns the canonical deployment of the contract. */ export function getCanonicalFeeJuice() {
    if (!protocolContract) {
        protocolContract = makeProtocolContract('FeeJuice', FeeJuiceArtifact);
    }
    return Promise.resolve(protocolContract);
}
/**
 * Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
 */ export function computeFeePayerBalanceStorageSlot(feePayer) {
    return deriveStorageSlotInMap(FeeJuiceArtifact.storageLayout.balances.slot, feePayer);
}
/**
 * Computes the leaf slot in the public data tree for the balance of the fee payer in the Fee Juice.
 */ export async function computeFeePayerBalanceLeafSlot(feePayer) {
    const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
    return computePublicDataTreeLeafSlot(ProtocolContractAddress.FeeJuice, balanceSlot);
}
