How to use the @0x/asset-swapper.SwapQuoterError.InsufficientAssetLiquidity function in @0x/asset-swapper

To help you get started, we’ve selected a few @0x/asset-swapper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / instant / src / util / asset.ts View on Github external
swapQuoterErrorMessage: (asset: Asset, error: Error): string | undefined => {
        if (error.message === SwapQuoterError.InsufficientAssetLiquidity) {
            const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
            if (
                error instanceof InsufficientAssetLiquidityError &&
                error.amountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO)
            ) {
                const unitAmountAvailableToFill =
                    asset.metaData.assetProxyId === AssetProxyId.ERC20
                        ? Web3Wrapper.toUnitAmount(error.amountAvailableToFill, asset.metaData.decimals)
                        : error.amountAvailableToFill;
                const roundedUnitAmountAvailableToFill = unitAmountAvailableToFill.decimalPlaces(
                    2,
                    BigNumber.ROUND_DOWN,
                );

                if (roundedUnitAmountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO)) {
                    return `There are only ${roundedUnitAmountAvailableToFill} ${assetName} available to buy`;