1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 17:24:51 +01:00

formula update

This commit is contained in:
Matthias Kretschmann 2020-10-26 18:48:08 +01:00
parent 77e1d08a08
commit 2c27d955d9
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -13,6 +13,7 @@ import { useFormikContext } from 'formik'
import { PriceOptionsMarket } from '../../../../../@types/MetaData'
import { DDO } from '@oceanprotocol/lib'
import Price from './Price'
import Decimal from 'decimal.js'
export default function Dynamic({
ddo,
@ -32,7 +33,9 @@ export default function Dynamic({
price,
weightOnDataToken,
weightOnOcean,
swapFee
swapFee,
dtAmount,
oceanAmount
} = values as PriceOptionsMarket
const [error, setError] = useState<string>()
@ -40,14 +43,16 @@ export default function Dynamic({
// Calculate firstPrice whenever
useEffect(() => {
const tokenAmountOut = 1
const weightRatio = Decimal(weightOnDataToken).div(Decimal(weightOnOcean))
const diff = Decimal(dtBalance).minus(tokenAmountOut)
const y = Decimal(dtBalance).div(diff)
const foo = y.pow(weightRatio).minus(Decimal(1))
const tokenAmountIn = Decimal(oceanBalance)
const weightRatio = new Decimal(weightOnDataToken).div(
new Decimal(weightOnOcean)
)
const diff = new Decimal(dtAmount).minus(tokenAmountOut)
const y = new Decimal(dtAmount).div(diff)
const foo = y.pow(weightRatio).minus(new Decimal(1))
const tokenAmountIn = new Decimal(oceanAmount)
.times(foo)
.div(Decimal(1).minus(Decimal(swapFee)))
setFirstPrice(tokenAmountIn)
.div(new Decimal(1).minus(new Decimal(swapFee)))
setFirstPrice(`${tokenAmountIn}`)
}, [swapFee, weightOnOcean, weightOnDataToken])
// Check: account, network & insufficient balance