import type { Address } from "viem"; import type { Asset } from "../../sdk/index.js"; interface TokenDataSlice { symbol: string; decimals: number; } export interface AssetWithView extends Asset { balanceView: string; } export interface AssetWithAmountInTarget extends Asset { amountInTarget: bigint; } interface NextAssetProps { allowedTokens: Array
; selectedAssets: Array; balances: Record; tokensList: Record; prices?: Record; } export type WrapResult = [Array, bigint, bigint]; /** * Static helper namespace for asset-list transformations and math. * * The constructor is intentionally private to prevent instantiation. */ export declare class AssetUtils { private constructor(); /** * Selects the next candidate token to add to a selected-asset list. * * Flow: * 1) Removes tokens already present in `selectedAssets` * 2) Builds balances for the remaining allowed tokens * 3) Sorts the balances using `CreditAccountDataUtils.sortBalances` * 4) Returns the highest-priority token address, if any * * Addresses are normalized to lowercase for matching. * * @returns The next token address to select, or `undefined` if no candidates remain. */ static nextAsset({ allowedTokens, selectedAssets, balances, tokensList, prices, }: NextAssetProps): Address | undefined; /** * Builds a normalized balance record for a specific token subset. * * Missing balances are defaulted to `0n`. * * @param allowedTokens Tokens to include in the output record. * @param externalBalances Source balances keyed by lowercase address. * @returns A record that contains only `allowedTokens`. */ private static getBalances; /** * Converts an asset array into a token-address keyed record. * * If duplicate token addresses are present, the last occurrence wins. * * @param a Source asset list. * @returns Record keyed by `asset.token`. */ static constructAssetRecord(a: Array): Record<`0x${string}`, A>; /** * Creates a reusable wrapper function that merges "unwrapped" and "wrapped" * token balances into the wrapped token representation. * * The returned function: * - converts non-negative unwrapped balance into wrapped units by price * - adds the converted amount to the wrapped token balance * - removes the unwrapped token from the result list * - leaves input untouched when no unwrapped token is present * * @returns A function producing `[assets, convertedUnwrapped, originalWrapped]`. */ static memoWrap: (unwrappedAddress: Address, wrappedAddress: Address, prices: Record, tokensList: Record) => (assets: Array) => WrapResult; /** * Adds balances from the second asset list into the first list. * * Behavior: * - balances are clamped to non-negative before summation * - tokens found only in `b` are created in the output * - existing asset metadata is preserved from `a` when possible * * @param a Base asset list. * @param b Asset deltas to add. * @returns A merged list containing assets from both inputs. */ static sumAssets(a: Array, b: Array): Array; /** * Adds balances from the second list to matching assets in the first list. * * Behavior: * - balances are clamped to non-negative before summation * - only assets already present in `a` are returned * - no new token entries are created * * @param a Base asset list. * @param b Asset deltas keyed by token. * @returns Updated version of `a` with adjusted balances. */ static addBalances(a: Array, b: Array): Array; /** * Subtracts balances in the second list from matching assets in the first list. * * Behavior: * - both operands are clamped to non-negative before subtraction * - output balances are clamped to non-negative after subtraction * - only assets already present in `a` are returned * * @param a Base asset list. * @param b Asset amounts to subtract by token. * @returns Updated `a` list with non-negative post-subtraction balances. */ static subAssets(a: Array, b: Array): Array; } export {};