diff --git a/packages/augur-simplified/src/modules/constants.ts b/packages/augur-simplified/src/modules/constants.ts index 576880caac0..1c9117dc238 100644 --- a/packages/augur-simplified/src/modules/constants.ts +++ b/packages/augur-simplified/src/modules/constants.ts @@ -47,6 +47,7 @@ export const MILLION = THOUSAND.times(THOUSAND); export const BILLION = MILLION.times(THOUSAND); export const TRILLION = BILLION.times(THOUSAND); export const SEC_IN_YEAR = createBigNumber(86400).times(createBigNumber(365)); +export const NUM_TICKS_Y_N = 1000; // # Asset Types export const ETH = 'ETH'; diff --git a/packages/augur-simplified/src/modules/types.ts b/packages/augur-simplified/src/modules/types.ts index ad8c627d6a0..7ab14d2b345 100644 --- a/packages/augur-simplified/src/modules/types.ts +++ b/packages/augur-simplified/src/modules/types.ts @@ -218,6 +218,8 @@ export interface MarketOutcome { isFinalNumerator?: boolean; payoutNumerator?: string; name: string; + isInvalid: boolean; + isWinner: boolean; } export interface AmmOutcome { diff --git a/packages/augur-simplified/src/utils/contract-calls.ts b/packages/augur-simplified/src/utils/contract-calls.ts index e12c452b11b..f533305c130 100644 --- a/packages/augur-simplified/src/utils/contract-calls.ts +++ b/packages/augur-simplified/src/utils/contract-calls.ts @@ -11,7 +11,7 @@ import { import { TransactionResponse, Web3Provider } from '@ethersproject/providers' import { convertDisplayCashAmountToOnChainCashAmount, convertDisplayShareAmountToOnChainShareAmount, convertOnChainCashAmountToDisplayCashAmount, convertOnChainSharesToDisplayShareAmount, isSameAddress } from './format-number'; import { augurSdkLite } from './augurlitesdk'; -import { ETH, NO_OUTCOME_ID, NULL_ADDRESS, USDC, YES_NO_OUTCOMES_NAMES, YES_OUTCOME_ID, INVALID_OUTCOME_ID, MARKET_STATUS } from '../modules/constants'; +import { ETH, NO_OUTCOME_ID, NULL_ADDRESS, USDC, YES_NO_OUTCOMES_NAMES, YES_OUTCOME_ID, INVALID_OUTCOME_ID, MARKET_STATUS, NUM_TICKS_Y_N } from '../modules/constants'; import { getProviderOrSigner } from '../modules/ConnectAccount/utils'; import { createBigNumber } from './create-big-number'; @@ -878,7 +878,7 @@ const getInitPositionValues = (trades: UserTrades, amm: AmmExchange, isYesOutcom const netShareAmounts = allInputShareAmounts.minus(sharesExited.shares); const netCashAmounts = allInputCashAmounts.minus(sharesExited.cashAmount); const cost = convertOnChainSharesToDisplayShareAmount(netCashAmounts, amm.cash.decimals).times(new BN(cashPrice)); - const avgPrice = netShareAmounts.gt(0) ? new BN(1).minus(netCashAmounts.div(netShareAmounts)) : new BN(0); + const avgPrice = netShareAmounts.gt(0) ? netCashAmounts.div(netShareAmounts) : new BN(0); const positionFromRemoveLiquidity = hasPositionFromRemoveLiquidity(amm.transactions, account); return { avgPrice: String(avgPrice), initCostUsd: String(cost), positionFromLiquidity, positionFromRemoveLiquidity } } @@ -897,16 +897,15 @@ const accumLpSharesPrice = (transactions: AmmTransaction[], isYesOutcome: boolea const result = transactions.filter(t => isSameAddress(t.sender, account) && (t.tx_type === TransactionTypes.ADD_LIQUIDITY || t.tx_type === TransactionTypes.REMOVE_LIQUIDITY)).reduce((p, t) => { const yesShares = new BN(t.yesShares); const noShares = new BN(t.noShares); - // TODO, convert cash to share cash, needed to combine with user's positions - const cashValue = new BN(t.cashValue).div(10000); + const cashValue = new BN(t.cash).minus(new BN(t.cashValue)).div(NUM_TICKS_Y_N); if (isYesOutcome) { const netYesShares = noShares.minus(yesShares) if (netYesShares.lte(new BN(0))) return p; - return { shares: p.shares.plus(netYesShares), cashAmount: p.cashAmount.plus(new BN(cashValue)) } + return { shares: p.shares.plus(t.netShares), cashAmount: p.cashAmount.plus(new BN(cashValue)) } } const netNoShares = yesShares.minus(noShares) if (netNoShares.lte(new BN(0))) return p; - return { shares: p.shares.plus(netNoShares), cashAmount: p.cashAmount.plus(new BN(cashValue)) } + return { shares: p.shares.plus(t.netShares), cashAmount: p.cashAmount.plus(new BN(cashValue)) } }, { shares: new BN(0), cashAmount: new BN(0) }); diff --git a/packages/augur-simplified/src/utils/process-data.ts b/packages/augur-simplified/src/utils/process-data.ts index c42205665e8..32049c407bd 100644 --- a/packages/augur-simplified/src/utils/process-data.ts +++ b/packages/augur-simplified/src/utils/process-data.ts @@ -234,6 +234,7 @@ const shapeOutcomes = (graphOutcomes: GraphMarketOutcome[]): MarketOutcome[] => payoutNumerator: g.payoutNumerator, name: g.value, isInvalid: g.id.indexOf('-0') > -1, + isWinner: Boolean(Number(g.payoutNumerator)), })); const shapeAmmExchange = (