import { addPosition, buyYes, calculateLPCost, fromProb, getSwap3Probability, grossLiquidity, noShares, sortedTickStates, Swap3Pool, toProb, yesShares, } from 'common/calculate-swap3' import { formatPercent } from 'common/util/format' import { useState } from 'react' import { LiquidityGraph } from 'web/components/contract/liquidity-graph' import { Col } from 'web/components/layout/col' import { Row } from 'web/components/layout/row' import { addLiquidity } from 'web/lib/firebase/fn-call' const users: Record = { 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 ( {Object.keys(users).map((user) => ( ))}
User M YES NO
{user} {users[user].M} {users[user].YES} {users[user].NO}
) } /* Show the values in pool */ function PoolTable(props: { pool: Swap3Pool }) { const { pool } = props return ( <>
{formatPercent(getSwap3Probability(pool))}
{pool.liquidity}
{pool.tick}
{yesShares(pool).toFixed(2)}
{noShares(pool).toFixed(2)}
{/* Render each tickState as another row in a table */} {sortedTickStates(pool).map((tickState, i) => ( ))}
Tick Prob Net Liquidity Gross Liquidity
{tickState.tick} {formatPercent(toProb(tickState.tick))} {tickState.liquidityNet} {tickState.liquidityGross}
) } function Graph(props: { pool: Swap3Pool; previewMarker?: number }) { const { pool, previewMarker } = props const points = [] let lastGross = 0 for (const tickState of sortedTickStates(pool)) { const { tick, liquidityGross } = tickState points.push({ x: toProb(tick), y: lastGross }) points.push({ x: toProb(tick), y: liquidityGross }) lastGross = liquidityGross } return ( ) } function LiquidityPanel(props: { pool: Swap3Pool setPool: (pool: Swap3Pool) => void }) { const { pool, setPool } = props const [minTick, setMinTick] = useState(0) const [maxTick, setMaxTick] = useState(0) const [deltaL, setDeltaL] = useState(100) const { requiredN, requiredY } = calculateLPCost( pool.tick, minTick, maxTick, deltaL ) return (

Add liquidity

{/* */} setMinTick(inputPercentToTick(e))} /> {/* Min Tick: {minTick} */} setMaxTick(inputPercentToTick(e))} /> {/* Max Tick: {maxTick} */} setDeltaL(parseFloat(e.target.value))} />
Y required: {requiredY.toFixed(2)}
N required: {requiredN.toFixed(2)}
{' '}
) } export default function Swap() { // Set up an initial pool with 100 liquidity from 0% to 100% // TODO: Not sure why maxTick of 2**23 breaks it, but 2**20 is okay... let INIT_POOL: Swap3Pool = { liquidity: 0, tick: fromProb(0.3), tickStates: [], } INIT_POOL = addPosition(INIT_POOL, -(2 ** 23), 2 ** 20, 100) INIT_POOL = addPosition(INIT_POOL, fromProb(0.32), fromProb(0.35), 100) INIT_POOL = grossLiquidity(INIT_POOL) const [pool, setPool] = useState(INIT_POOL) const [buyAmount, setBuyAmount] = useState(0) const { newPoolTick, yesPurchased } = buyYes(pool, buyAmount) return ( {/* */} { pool.tick = inputPercentToTick(e) setPool({ ...pool }) }} />

Limit Order

TODO

Buy Shares

{/* */} setBuyAmount(parseFloat(e.target.value))} />
Y shares purchaseable: {yesPurchased.toFixed(2)}
New Tick: {newPoolTick}
New prob: {formatPercent(toProb(newPoolTick))}
{/* */} ) } function inputPercentToTick(event: React.ChangeEvent) { return fromProb(parseFloat(event.target.value) / 100) }