Created
October 6, 2021 22:05
-
-
Save vlzhr/3c70bb34d61b7635c60add3aa469e421 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
// calculate amountOut for puzzle swap | |
// coef = 0.98 (excludes fee) | |
calculateAmountOut(coef: number) { | |
const tokenOut = this.state.tokenOut | |
const tokenIn = this.getTokenIn(); | |
const BalanceIn = this.state.data.get("global_"+[this.poolData.tokenIds[tokenIn]]+"_balance") | |
const BalanceOut = this.state.data.get("global_"+[this.poolData.tokenIds[tokenOut]]+"_balance") | |
const amountOut = BalanceOut / this.poolData.tokenDecimals[tokenOut] * | |
(1 - (BalanceIn / (BalanceIn + this.poolData.tokenDecimals[tokenIn] * this.state.amountIn)) | |
** (this.poolData.tokenShares[tokenIn] / this.poolData.tokenShares[tokenOut])) | |
return Math.floor(amountOut * this.poolData.tokenDecimals[tokenOut] * coef) / this.poolData.tokenDecimals[tokenOut] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment