import { keccak256 } from "ethers/lib/utils";
import { isNativeDenom } from "../terra";
import { CHAIN_ID_COSMOSHUB, CHAIN_ID_EVMOS, CHAIN_ID_WORMCHAIN, CHAIN_ID_INJECTIVE, CHAIN_ID_SEI, CHAIN_ID_XPLA, coalesceCosmWasmChainId, isTerraChain, CHAIN_ID_KUJIRA, CHAIN_ID_OSMOSIS, CHAIN_ID_CELESTIA, } from "../utils";
export const isNativeDenomInjective = (denom) => denom === "inj";
export const isNativeDenomXpla = (denom) => denom === "axpla";
export const isNativeDenomSei = (denom) => denom === "usei";
export const isNativeDenomWormchain = (denom) => denom === "uworm";
export const isNativeDenomOsmosis = (denom) => denom === "uosmo";
export const isNativeDenomCosmosHub = (denom) => denom === "uatom";
export const isNativeDenomEvmos = (denom) => denom === "aevmos" || denom === "atevmos";
export const isNativeDenomKujira = (denom) => denom === "ukuji";
export const isNativeDenomCelestia = (denom) => denom === "utia";
export function isNativeCosmWasmDenom(chainId, address) {
    return ((isTerraChain(chainId) && isNativeDenom(address)) ||
        (chainId === CHAIN_ID_INJECTIVE && isNativeDenomInjective(address)) ||
        (chainId === CHAIN_ID_XPLA && isNativeDenomXpla(address)) ||
        (chainId === CHAIN_ID_SEI && isNativeDenomSei(address)) ||
        (chainId === CHAIN_ID_WORMCHAIN && isNativeDenomWormchain(address)) ||
        (chainId === CHAIN_ID_OSMOSIS && isNativeDenomOsmosis(address)) ||
        (chainId === CHAIN_ID_COSMOSHUB && isNativeDenomCosmosHub(address)) ||
        (chainId === CHAIN_ID_EVMOS && isNativeDenomEvmos(address)) ||
        (chainId === CHAIN_ID_KUJIRA && isNativeDenomKujira(address)) ||
        (chainId === CHAIN_ID_CELESTIA && isNativeDenomCelestia(address)));
}
export function buildTokenId(chain, address) {
    const chainId = coalesceCosmWasmChainId(chain);
    return ((isNativeCosmWasmDenom(chainId, address) ? "01" : "00") +
        keccak256(Buffer.from(address, "utf-8")).substring(4));
}
