Skip to content

Commit

Permalink
+package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Okavango committed Jun 23, 2021
1 parent 367b8fe commit 1493da5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"big.js": "^5.2.2",
"decimal.js-light": "^2.5.0",
"jsbi": "^3.1.1",
"lowdash": "^1.2.0",
"tiny-invariant": "^1.1.0",
"tiny-warning": "^1.0.3",
"toformat": "^2.0.0"
Expand Down
14 changes: 1 addition & 13 deletions src/MultiRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ function findBestDistributionIdealParams(
function findBestDistributionIdeal(
amountIn: number,
pools: Pool[],
tokenInPriceBase: number,
tokenOutPriceBase: number,
gasPriceGWeiBase: number
): Route | [number, number[][]]{
Expand All @@ -302,7 +301,6 @@ function findBestDistributionIdeal(
const poolsSorted = distrSorted.map(a => pools[a[0]]);

// TODO: Use more fast search instead
let bestPoolNumber = pools.length;
let bestOut = params.amountOut - pools.length*legPriceInTokenOut;
let bestParams = params;
for (let i = pools.length-1; i >= 1; --i) {
Expand All @@ -312,7 +310,6 @@ function findBestDistributionIdeal(
if (out < bestOut){
//break; // TODO: uncomment?
} else {
bestPoolNumber = i;
bestOut = out;
bestParams = p;
}
Expand All @@ -326,7 +323,6 @@ function findBestDistributionIdeal(
function findBestDistribution2 (
amountIn: number,
pools: Pool[],
tokenInPriceBase: number,
tokenOutPriceBase: number,
gasPriceGWeiBase: number
): Route | [number, number[][]]{
Expand Down Expand Up @@ -363,7 +359,6 @@ function findBestDistribution2 (
function findBestDistribution3 (
amountIn: number,
pools: Pool[],
tokenInPriceBase: number,
tokenOutPriceBase: number,
gasPriceGWeiBase: number
): Route | [number, number[][]]{
Expand All @@ -374,22 +369,17 @@ function findBestDistribution3 (
const order = out.map((o, i) => [i, o/sum]).sort((a,b) => b[1] - a[1]);

let bestGroup = order;
let bestOut = -legPriceInTokenOut*pools.length*2;
let flagDown = false;

let bestOut = -legPriceInTokenOut*pools.length*2;

for (let i = pools.length; i >= 1; --i) {
const group = order.slice(0, i);
const sum = group.reduce((a, b) => a+b[1], 0);
const out = group.map(p => calcOutByIn(pools[p[0]], p[1]/sum*amountIn)).reduce((a, b) => a+b, 0) - legPriceInTokenOut*i;

if (out > bestOut) {
// commented because assertion triggers too often
// console.assert(flagDown == false, "flagDown at " + amountIn);
bestOut = out;
bestGroup = group.map(([n, v]) => [n, v/sum]);
} else {
flagDown = true;
// break; // TODO: unconmment?
}
}
Expand Down Expand Up @@ -429,7 +419,6 @@ function findBestDistributionWithoutTransactionCost(
function findBestDistribution(
amountIn: number,
pools: Pool[],
tokenInPriceBase: number,
tokenOutPriceBase: number,
gasPriceGWeiBase: number
): Route | [number, number[][]]{
Expand Down Expand Up @@ -491,7 +480,6 @@ function findBesChaintDistributionWithoutTransactionCost(
function findBestChainDistribution(
amountIn: number,
poolChains: Pool[][],
tokenInPriceBase: number,
tokenOutPriceBase: number,
gasPriceGWeiBase: number
): Route | [number, number[][]]{
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4327,6 +4327,11 @@ loose-envify@^1.0.0, loose-envify@^1.4.0:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

lowdash@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/lowdash/-/lowdash-1.2.0.tgz#d807b966da490ce449324a066b61dd2ff31089fa"
integrity sha512-oHdShh4q1SmsUkLBa9ITyi4x3ObxUxFeGNu7GCGta8b9jq0IAmZ/Zeapd/Ex7/OuA8tN96izhRdQlUcMe40Ing==

lower-case@^1.1.1:
version "1.1.4"
resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac"
Expand Down

0 comments on commit 1493da5

Please sign in to comment.