From 05778f498545ee1adbf765fbc81d68d47a68395e Mon Sep 17 00:00:00 2001 From: BokkyPooBah Date: Thu, 3 Oct 2024 13:52:10 +1000 Subject: [PATCH] ui wip --- docs/tradeFungibles.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/tradeFungibles.js b/docs/tradeFungibles.js index f6441e2..9770192 100644 --- a/docs/tradeFungibles.js +++ b/docs/tradeFungibles.js @@ -2116,12 +2116,15 @@ data: {{ data }} } maxTokens = maxTokens.sub(tokens); } - if (tokensFromMaxWeth != null) { - if (tokens.gt(tokensFromMaxWeth)) { - tokens = tokensFromMaxWeth; + if (tokensFromWethFromTokensFromMaxWeth != null) { + console.log("tokens: " + ethers.utils.formatEther(tokens) + ", tokensFromWethFromTokensFromMaxWeth: " + ethers.utils.formatEther(tokensFromWethFromTokensFromMaxWeth)); + if (tokens.gt(tokensFromWethFromTokensFromMaxWeth)) { + tokens = tokensFromWethFromTokensFromMaxWeth; } const wethsToSubtract = tokens.mul(price_).div(TENPOW18); + console.log("tokens: " + ethers.utils.formatEther(tokens) + ", wethsToSubtract: " + ethers.utils.formatEther(wethsToSubtract)); maxWeth = maxWeth.sub(wethsToSubtract); + console.log("maxWeth: " + ethers.utils.formatEther(maxWeth)); } // weths = tokens.mul(price_).div(TENPOW18); // if (maxWeth != null) { @@ -3887,18 +3890,22 @@ function testIt() { const tokensFromWethsFromTokens = wethsFromTokens.mul(TENPOW18).div(price); // price = weth x 10^18 / tokens const averagePrice = tokensFromWethsFromTokens.gt(0) ? wethsFromTokens.mul(TENPOW18).div(tokensFromWethsFromTokens) : 0; + // weth = tokens x price / 10^18 + const wethsFromTokensFromWethsFromTokens = tokensFromWethsFromTokens.mul(price).div(TENPOW18); // price: 0.0019 1900000000000000 // weths: 0.001 1000000000000000 // tokens: 0.52631578947368421 526315789473684210 // wethsFromTokens: 0.000999999999999999 999999999999999 // tokensFromWethsFromTokens: 0.526315789473683684 526315789473683684 + // wethsFromTokensFromWethsFromTokens: 0.000999999999999998 999999999999998 // averagePrice: 0.0019 1900000000000000 console.log("price: " + ethers.utils.formatEther(price) + " " + price.toString()); console.log("weths: " + ethers.utils.formatEther(weths) + " " + weths.toString()); console.log("tokens: " + ethers.utils.formatEther(tokens) + " " + tokens.toString()); console.log("wethsFromTokens: " + ethers.utils.formatEther(wethsFromTokens) + " " + wethsFromTokens.toString()); console.log("tokensFromWethsFromTokens: " + ethers.utils.formatEther(tokensFromWethsFromTokens) + " " + tokensFromWethsFromTokens.toString()); + console.log("wethsFromTokensFromWethsFromTokens: " + ethers.utils.formatEther(wethsFromTokensFromWethsFromTokens) + " " + wethsFromTokensFromWethsFromTokens.toString()); console.log("averagePrice: " + ethers.utils.formatEther(averagePrice) + " " + averagePrice.toString()); }