Created
February 16, 2021 08:33
-
-
Save danoctavian/c0449eb5ab2f19d089396a1dac2250b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateNxmForEth (Vt0, ethIn, mcrEth, stepSize) { | |
let previousV; | |
let currentV = Vt0; | |
let previousPrice; | |
let totalTokens = Decimal(0); | |
while (ethIn.gt('0')) { | |
const mcrPercentage = currentV.div(mcrEth); | |
const currentPrice = getSpotPrice(mcrPercentage, mcrEth); | |
if (previousPrice && previousV) { | |
const averagePrice = currentPrice.add(previousPrice).div(2); | |
const deltaTokens = currentV.sub(previousV).div(averagePrice); | |
totalTokens = totalTokens.add(deltaTokens); | |
} | |
previousV = currentV; | |
previousPrice = currentPrice; | |
currentV = currentV.add(stepSize); | |
ethIn = ethIn.sub(stepSize); | |
} | |
return totalTokens; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment