From e75cedd21f98d1eff9696094d7e28e48ee7ac1d6 Mon Sep 17 00:00:00 2001 From: Sebastian Pape <0xneo11@gmail.com> Date: Thu, 26 Dec 2024 21:41:30 +0100 Subject: [PATCH] v13.15.1: fixes uniswapV3 liquidity check for smaller amounts --- dist/esm/index.evm.js | 4 ++-- dist/esm/index.js | 4 ++-- dist/umd/index.evm.js | 4 ++-- dist/umd/index.js | 4 ++-- package.evm.json | 2 +- package.json | 2 +- package.solana.json | 2 +- src/platforms/evm/uniswap_v3.js | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 255e09a..3248bee 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -2083,14 +2083,14 @@ const getBestPool = async ({ blockchain, exchange, path, amountIn, amountOut, bl const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.BigNumber.from(amountIn).mul(ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } else { amount = await getInputAmount({ exchange, pool, outputAmount: amountOut }); const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.BigNumber.from(amountOut).mul(ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } diff --git a/dist/esm/index.js b/dist/esm/index.js index f8da0d4..e01b9a4 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -4675,14 +4675,14 @@ const getBestPool = async ({ blockchain, exchange, path, amountIn, amountOut, bl const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.BigNumber.from(amountIn).mul(ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } else { amount = await getInputAmount({ exchange, pool, outputAmount: amountOut }); const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.BigNumber.from(amountOut).mul(ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index d10210a..d4cefcb 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -2089,14 +2089,14 @@ const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.ethers.BigNumber.from(amountIn).mul(ethers.ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.ethers.BigNumber.from(100)).mul(ethers.ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.ethers.BigNumber.from(5)).div(ethers.ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } else { amount = await getInputAmount({ exchange, pool, outputAmount: amountOut }); const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.ethers.BigNumber.from(amountOut).mul(ethers.ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.ethers.BigNumber.from(100)).mul(ethers.ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.ethers.BigNumber.from(5)).div(ethers.ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } diff --git a/dist/umd/index.js b/dist/umd/index.js index 4689c42..a73d567 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -4680,14 +4680,14 @@ const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.ethers.BigNumber.from(amountIn).mul(ethers.ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.ethers.BigNumber.from(100)).mul(ethers.ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.ethers.BigNumber.from(5)).div(ethers.ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } else { amount = await getInputAmount({ exchange, pool, outputAmount: amountOut }); const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.ethers.BigNumber.from(amountOut).mul(ethers.ethers.BigNumber.from(10)).toString() }); const amountScaledDown = amountScaled.div(ethers.ethers.BigNumber.from(10)); const difference = amountScaledDown.sub(amount).abs(); - const enoughLiquidity = !difference.gt(amount.div(ethers.ethers.BigNumber.from(100)).mul(ethers.ethers.BigNumber.from(5))); // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.ethers.BigNumber.from(5)).div(ethers.ethers.BigNumber.from(100))); // up to 5% diff allowed if(!enoughLiquidity) { return } } diff --git a/package.evm.json b/package.evm.json index 9733e64..76f2b28 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-exchanges-evm", "moduleName": "Web3Exchanges", - "version": "13.15.0", + "version": "13.15.1", "description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index f9bb210..1fc84d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-exchanges", "moduleName": "Web3Exchanges", - "version": "13.15.0", + "version": "13.15.1", "description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 26e0f10..e7140d0 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-exchanges-solana", "moduleName": "Web3Exchanges", - "version": "13.15.0", + "version": "13.15.1", "description": "JavaScript library simplifying decentralized web3 exchange routing for multiple blockchains and exchanges.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/platforms/evm/uniswap_v3.js b/src/platforms/evm/uniswap_v3.js index b13960a..05790b9 100644 --- a/src/platforms/evm/uniswap_v3.js +++ b/src/platforms/evm/uniswap_v3.js @@ -119,14 +119,14 @@ const getBestPool = async ({ blockchain, exchange, path, amountIn, amountOut, bl const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.BigNumber.from(amountIn).mul(ethers.BigNumber.from(10)).toString() }) const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)) const difference = amountScaledDown.sub(amount).abs() - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))) // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))) // up to 5% diff allowed if(!enoughLiquidity) { return } } else { amount = await getInputAmount({ exchange, pool, outputAmount: amountOut }) const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.BigNumber.from(amountOut).mul(ethers.BigNumber.from(10)).toString() }) const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10)) const difference = amountScaledDown.sub(amount).abs() - const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)).mul(ethers.BigNumber.from(5))) // up to 5% diff allowed + const enoughLiquidity = !difference.gt(amount.mul(ethers.BigNumber.from(5)).div(ethers.BigNumber.from(100))) // up to 5% diff allowed if(!enoughLiquidity) { return } }