import {
calculateLPCost,
fromProb,
getSwap3Probability,
Swap3Pool,
} from 'common/calculate-swap3'
import { formatPercent } from 'common/util/format'
import { useState } from 'react'
import { Col } from 'web/components/layout/col'
import { Row } from 'web/components/layout/row'
const users = {
alice: {
M: 100,
YES: 0,
NO: 0,
},
bob: {
M: 200,
YES: 0,
NO: 0,
},
kipply: {
M: 300,
YES: 0,
NO: 0,
},
}
function BalanceTable() {
/* Display all users current M, YES, and NO in a table */
return (
User |
M |
YES |
NO |
{Object.keys(users).map((user) => (
{user} |
{users[user].M} |
{users[user].YES} |
{users[user].NO} |
))}
)
}
/* Show the values in pool */
function PoolTable(props: { pool: Swap3Pool }) {
const { pool } = props
return (
{pool.liquidity}
{pool.sqrtRatio}
{pool.tick}
{pool.liquidity * pool.sqrtRatio}
{pool.liquidity / pool.sqrtRatio}
{formatPercent(getSwap3Probability(pool))}
)
}
export default function Swap() {
const [pool, setPool] = useState({
liquidity: 100,
sqrtRatio: 2,
tick: fromProb(0.3),
ticks: [],
})
const [minTick, setMinTick] = useState(0)
const [maxTick, setMaxTick] = useState(0)
const { requiredN, requiredY } = calculateLPCost(
pool.tick,
minTick,
maxTick,
100 // deltaL
)
return (
setPool((p) => ({
...p,
tick: inputPercentToTick(e),
}))
}
/>
Alice: Add liquidity
setMinTick(inputPercentToTick(e))}
/>
Min Tick: {minTick}
setMaxTick(inputPercentToTick(e))}
/>
Max Tick: {maxTick}
Y required: {requiredY}
N required: {requiredN}
{' '}
Bob: Buy Tokens
{/* */}
)
}
function inputPercentToTick(event: React.ChangeEvent) {
return fromProb(parseFloat(event.target.value) / 100)
}