Skip to content

Commit

Permalink
ui wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Oct 3, 2024
1 parent 5835cab commit 05778f4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/tradeFungibles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit 05778f4

Please sign in to comment.