import { HookType } from '@hyperlane-xyz/provider-sdk/altvm';
import { decodeIgpAccount, decodeIgpProgramDataAccount, decodeOverheadIgpAccount, } from '../accounts/token.js';
import { deriveIgpAccountPda, deriveIgpProgramDataPda, deriveOverheadIgpAccountPda, } from '../pda.js';
import { fetchAccountDataRaw } from '../rpc.js';
export const decodeHookAccount = {
    igpProgramData: decodeIgpProgramDataAccount,
    igp: decodeIgpAccount,
    overheadIgp: decodeOverheadIgpAccount,
};
export async function fetchIgpProgramData(rpc, programId) {
    const { address: programDataPda } = await deriveIgpProgramDataPda(programId);
    const raw = await fetchAccountDataRaw(rpc, programDataPda);
    if (!raw || raw.length === 0)
        return null;
    return decodeIgpProgramDataAccount(raw);
}
export async function fetchIgpAccount(rpc, programId, salt) {
    const { address: igpPda } = await deriveIgpAccountPda(programId, salt);
    const raw = await fetchAccountDataRaw(rpc, igpPda);
    if (!raw || raw.length === 0)
        return null;
    return decodeIgpAccount(raw);
}
export async function fetchOverheadIgpAccount(rpc, programId, salt) {
    const { address: overheadIgpPda } = await deriveOverheadIgpAccountPda(programId, salt);
    const raw = await fetchAccountDataRaw(rpc, overheadIgpPda);
    if (!raw || raw.length === 0)
        return null;
    return decodeOverheadIgpAccount(raw);
}
export async function detectHookType(rpc, address) {
    const igpProgramData = await fetchIgpProgramData(rpc, address);
    if (igpProgramData !== null) {
        return HookType.INTERCHAIN_GAS_PAYMASTER;
    }
    return null;
}
export function remoteGasDataToConfig(gasOracle) {
    const data = gasOracle.value;
    return {
        gasPrice: data.gasPrice.toString(),
        tokenExchangeRate: data.tokenExchangeRate.toString(),
        tokenDecimals: data.tokenDecimals,
    };
}
//# sourceMappingURL=hook-query.js.map