import {
  validateDto
} from "./chunk-MOME3JHZ.mjs";
import {
  GetTokenListsDto
} from "./chunk-5YDEIS4W.mjs";
import {
  GetTransactionStatusDto
} from "./chunk-GZPQDG5N.mjs";
import {
  GetTransactionDto
} from "./chunk-KP2K45EE.mjs";
import {
  GetTransactionsDto
} from "./chunk-COLUB3R4.mjs";
import {
  GetExchangeOffersDto
} from "./chunk-U6ULOGB4.mjs";
import {
  GetExchangeSupportedAssetsDto
} from "./chunk-Z3R6YZ4Z.mjs";
import {
  GetNftListDto
} from "./chunk-7FRLPXUA.mjs";
import {
  GetQuotesDto
} from "./chunk-I5VZJ76X.mjs";
import {
  GetStepTransactionsLiFiDto
} from "./chunk-7GGGAJSW.mjs";
import {
  GetSupportedAssetsDto
} from "./chunk-6CIRRYH7.mjs";
import {
  GetTokenListDto
} from "./chunk-7W6QEWUT.mjs";
import {
  DataModule
} from "./chunk-QCLH3UIP.mjs";
import {
  GetAdvanceRoutesLiFiDto
} from "./chunk-3NBGLOUD.mjs";
import {
  GetAccountBalancesDto
} from "./chunk-OWQ2V6GF.mjs";
import {
  BigNumber
} from "./chunk-DEX5RLI7.mjs";

// src/sdk/dataUtils.ts
import "reflect-metadata";
var DataUtils = class {
  constructor(apiKey) {
    this.defaultDataApiKey = "eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjI4ZWJiMGQ5YTMxYjQ3MmY4NmU4MWY2YTVhYzBhMzE1IiwiaCI6Im11cm11cjEyOCJ9";
    this.dataModule = new DataModule(apiKey || this.defaultDataApiKey);
  }
  /**
  * gets account balances
  * @param dto
  * @return Promise<AccountBalances>
  */
  async getAccountBalances(dto) {
    const { account, tokens, chainId, provider } = await validateDto(dto, GetAccountBalancesDto, {
      addressKeys: ["account", "tokens"]
    });
    return this.dataModule.getAccountBalances(
      account,
      chainId,
      tokens,
      provider
    );
  }
  /**
  * gets transaction
  * @param dto
  * @return Promise<Transaction>
  */
  async getTransaction(dto) {
    const { hash, chainId } = await validateDto(dto, GetTransactionDto);
    return this.dataModule.getTransaction(hash, chainId);
  }
  /**
  * gets transactions
  * @param dto
  * @return Promise<Transactions>
  */
  async getTransactions(dto) {
    const { account, chainId, page, limit } = await validateDto(dto, GetTransactionsDto, {
      addressKeys: ["account"]
    });
    return this.dataModule.getTransactions(
      account,
      chainId,
      page,
      limit
    );
  }
  /**
  * gets NFT list belonging to account
  * @param dto
  * @return Promise<NftList>
  */
  async getNftList(dto) {
    const { account, chainId } = await validateDto(dto, GetNftListDto, {
      addressKeys: ["account"]
    });
    return this.dataModule.getNftList(
      account,
      chainId
    );
  }
  /**
  * gets advance routes from LIFI
  * @param dto
  * @return Promise<AdvanceRoutesLiFi>
  */
  async getAdvanceRoutesLiFi(dto) {
    const {
      fromChainId,
      toChainId,
      fromTokenAddress,
      toTokenAddress,
      fromAmount,
      allowSwitchChain,
      showZeroUsd,
      fromAddress
    } = await validateDto(dto, GetAdvanceRoutesLiFiDto, {
      addressKeys: ["fromTokenAddress", "toTokenAddress", "fromAddress"]
    });
    let { toAddress } = dto;
    if (!toAddress) toAddress = fromAddress;
    const data = await this.dataModule.getAdvanceRoutesLiFi(
      fromTokenAddress,
      toTokenAddress,
      fromChainId,
      toChainId,
      fromAmount,
      toAddress,
      allowSwitchChain,
      fromAddress,
      showZeroUsd
    );
    return data;
  }
  /**
  * gets step transactions from LIFI
  * @param dto
  * @return Promise<StepTransactions>
  */
  async getStepTransaction(dto) {
    const { route, account } = await validateDto(dto, GetStepTransactionsLiFiDto, {
      addressKeys: ["account"]
    });
    return this.dataModule.getStepTransaction(route, account);
  }
  /**
  * gets exchange supported tokens
  * @param dto
  * @return Promise<PaginatedTokens>
  */
  async getExchangeSupportedAssets(dto) {
    const { page, limit, chainId, account } = await validateDto(dto, GetExchangeSupportedAssetsDto, {
      addressKeys: ["account"]
    });
    return this.dataModule.getExchangeSupportedAssets(page, limit, chainId, account);
  }
  /**
  * gets exchange offers
  * @param dto
  * @return Promise<ExchangeOffer[]>
  */
  async getExchangeOffers(dto) {
    const { fromTokenAddress, toTokenAddress, fromAmount, fromChainId, showZeroUsd, fromAddress } = await validateDto(dto, GetExchangeOffersDto, {
      addressKeys: ["fromTokenAddress", "toTokenAddress", "fromAddress"]
    });
    let { toAddress } = dto;
    if (!toAddress) toAddress = fromAddress;
    return this.dataModule.getExchangeOffers(
      fromTokenAddress,
      toTokenAddress,
      BigNumber.from(fromAmount),
      fromChainId,
      fromAddress,
      toAddress,
      showZeroUsd
    );
  }
  /**
  * gets token lists
  * @param dto
  * @return Promise<TokenList[]>
  */
  async getTokenLists(dto) {
    const { chainId } = await validateDto(dto, GetTokenListsDto);
    return this.dataModule.getTokenLists(chainId);
  }
  /**
  * gets token list tokens
  * @param dto
  * @return Promise<TokenListToken[]>
  */
  async getTokenListTokens(dto) {
    const { chainId, name } = await validateDto(dto, GetTokenListDto);
    return this.dataModule.getTokenListTokens(chainId, name);
  }
  /**
  * fetch exchange rates of tokens
  * @param dto
  * @return Promise<RateData>
  */
  async fetchExchangeRates(dto) {
    const { tokens, chainId } = dto;
    let data;
    const promises = [];
    const batches = [...Array(Math.ceil(tokens.length / 50))].map(() => tokens.splice(0, 50));
    batches.forEach((batch) => {
      promises.push(this.dataModule.fetchExchangeRates(batch, chainId));
    });
    await Promise.allSettled(promises).then(
      (response) => response?.forEach((result) => {
        if (result?.status === "fulfilled") {
          !data ? data = result.value ? result.value : {} : data.items = result?.value?.items ? [...data.items, ...result.value.items] : [...data.items];
        }
      })
    );
    if (data && data.items && data.items.length) {
      data.error = "";
      data.errored = false;
      data.items = [...new Map(data.items.map((item) => [item["address"], item])).values()];
    } else {
      data.items = [];
    }
    return data;
  }
  /**
  * gets supported tokens
  * @param dto
  * @return Promise<Token[]>
  */
  async getSupportedAssets(dto) {
    const { chainId, provider } = await validateDto(dto, GetSupportedAssetsDto);
    return this.dataModule.getSupportedAssets(chainId, provider);
  }
  /**
  * gets quote transactions
  * @param dto
  * @return Promise<Quote[]>
  */
  async getQuotes(dto) {
    const {
      fromAddress,
      toAddress,
      fromChainId,
      toChainId,
      fromToken,
      fromAmount,
      slippage,
      provider
    } = await validateDto(dto, GetQuotesDto, {
      addressKeys: ["fromAddress", "toAddress", "fromToken"]
    });
    return this.dataModule.getQuotes(
      fromAddress,
      toAddress,
      fromChainId,
      toChainId,
      fromToken,
      BigNumber.from(fromAmount),
      slippage,
      provider
    );
  }
  /**
  * gets transaction status
  * @param dto
  * @return Promise<TransactionStatus>
  */
  async getTransactionStatus(dto) {
    const { fromChainId, toChainId, transactionHash, provider } = await validateDto(dto, GetTransactionStatusDto);
    return this.dataModule.getTransactionStatus(fromChainId, toChainId, transactionHash, provider);
  }
};

export {
  DataUtils
};
//# sourceMappingURL=chunk-ZAVVPZRT.mjs.map