diff --git a/index.html b/index.html new file mode 100644 index 0000000..b93494d --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/parallelSwapLogic.js b/parallelSwapLogic.js new file mode 100644 index 0000000..7ffde2b --- /dev/null +++ b/parallelSwapLogic.js @@ -0,0 +1,236 @@ +//import Big from 'big.js'; +//import allPools from 'testPools.js'; + +Big.DP = 40; +Big.strict = false; + +// Steps. + +// Choose pair of tokens: +inputToken = 'wrap.testnet' +outputToken = 'banana.ft-fin.testnet' + +// Choose input token amount: + inputAmount = '10000000000' + +// Query all Pools to find ones that match the chosen inputToken/outputToken pair. +filteredPools = filterPoolsByTokenPair(allPools, inputToken, outputToken) + + function getAllTokens(allPools) { + // Note, here we should plumb in a function that requests all tokens from the Dexie Database. + // For now, it just scans the global allPools. + allTokens = []; + for (var i=0;i 0){ + let numerator = new Big(totalDeltaX); + let denominator = new Big(0); + for (var i=0; i < pools.length; i++) { + let p = formatPool(pools[i],inputToken); + let numAdd = new Big(p.x).times(10000).div(p.gamma_bps); + numerator = numerator.plus(numAdd); + let denomAdd = new Big(p.x).times(p.y).div(p.gamma_bps).sqrt().times(100); + denominator = denominator.plus(denomAdd); + } + + const mu = new Big(numerator).div(denominator); + return mu; + } + else { + console.log('ERROR - could not find pools that satisfy token pair') + const mu = NaN; + return mu; + } +}; + + + +function getAllocationsAndOutputs(totalInput, filteredPoolStructList,inputToken) { + // let totalInput = BigInt(totalInput); + // let totalInput = Big(totalInput); + let algPools = filteredPoolStructList; + let allocations = calculateOptimalOutput(algPools, totalInput, inputToken); + let dyReturns = []; + for (var i=0; i=0) { + goodIndices.push(i) + } + } + if (goodIndices.length < 1) { + console.log("ERROR OCCURRED -- ALL DX VALUES WERE NEGATIVE") + return dxArray; + } + let newPools = []; + for (var j=0; j