Skip to content

Commit

Permalink
make remaining scoring rule changes backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Robiquet committed May 29, 2024
1 parent e5ebb85 commit f2163ea
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
22 changes: 9 additions & 13 deletions components/assets/AssetActionButtons/AssetTradingButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ const AssetTradingButtons = ({
{tradeItem && (
<Modal open={isOpen} onClose={() => setIsOpen(false)}>
<Dialog.Panel className="w-full max-w-[564px] rounded-[10px] bg-white">
{market?.scoringRule === ScoringRule.AmmCdaHybrid ? (
<Amm2TradeForm
marketId={marketId}
initialAsset={assetId}
selectedTab={
tradeItem.action === "buy"
? TradeTabType.Buy
: TradeTabType.Sell
}
/>
) : (
<TradeForm />
)}
<Amm2TradeForm
marketId={marketId}
initialAsset={assetId}
selectedTab={
tradeItem.action === "buy"
? TradeTabType.Buy
: TradeTabType.Sell
}
/>
</Dialog.Panel>
</Modal>
)}
Expand Down
5 changes: 1 addition & 4 deletions components/liquidity/MarketLiquiditySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export const MarketLiquiditySection = ({
market: FullMarketFragment;
poll?: boolean;
}) => {
const marketHasPool =
(market?.scoringRule === ScoringRule.Cpmm && market.pool != null) ||
(market?.scoringRule === ScoringRule.AmmCdaHybrid &&
market.neoPool != null);
const marketHasPool = market.neoPool != null;

return (
<>
Expand Down
3 changes: 2 additions & 1 deletion lib/hooks/queries/useMarketSpotPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const useMarketSpotPrices = (
if (!enabled) return;
const spotPrices: MarketPrices =
market?.status !== "Resolved"
? market.scoringRule === ScoringRule.AmmCdaHybrid
? market.scoringRule === ScoringRule.AmmCdaHybrid ||
market.scoringRule === ScoringRule.Lmsr
? calcMarketPricesAmm2(amm2Pool!)
: calcMarketPrices(market, basePoolBalance!, balances!)
: calcResolvedMarketPrices(market);
Expand Down
11 changes: 9 additions & 2 deletions lib/hooks/queries/usePortfolioPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ export const usePortfolioPositions = (
const pools = usePoolsByIds(filter);
const markets = useMarketsByIds(filter);
const amm2MarketIds = markets.data
?.filter((market) => market.scoringRule === ScoringRule.AmmCdaHybrid)
?.filter(
(market) =>
market.scoringRule === ScoringRule.AmmCdaHybrid ||
market.scoringRule === ScoringRule.Lmsr,
)
.map((m) => m.marketId);

const { data: amm2SpotPrices } = useAmm2MarketSpotPrices(amm2MarketIds);
Expand Down Expand Up @@ -318,7 +322,10 @@ export const usePortfolioPositions = (
price = calcResolvedMarketPrices(market).get(getIndexOf(assetId));
price24HoursAgo = price;
} else {
if (market.scoringRule === ScoringRule.AmmCdaHybrid) {
if (
market.scoringRule === ScoringRule.AmmCdaHybrid ||
market.scoringRule === ScoringRule.Lmsr
) {
price = lookupAssetPrice(assetId, amm2SpotPrices);

price24HoursAgo = lookupAssetPrice(
Expand Down
3 changes: 2 additions & 1 deletion lib/util/calc-resolved-market-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const calcResolvedMarketPrices = (
market: FullMarketFragment,
): MarketPrices => {
const assetIds = (
market.scoringRule === ScoringRule.AmmCdaHybrid
market.scoringRule === ScoringRule.AmmCdaHybrid ||
market.scoringRule === ScoringRule.Lmsr
? market.neoPool?.account.balances.map((b) =>
parseAssetIdString(b.assetId),
)
Expand Down
9 changes: 2 additions & 7 deletions pages/markets/[marketid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,7 @@ const Market: NextPage<MarketPageProps> = ({
const hasLiveTwitchStream =
hasLiveTwitchStreamClient || hasLiveTwitchStreamServer;

const marketHasPool =
(market?.scoringRule === ScoringRule.Cpmm &&
poolId != null &&
poolIdLoading === false) ||
(market?.scoringRule === ScoringRule.AmmCdaHybrid &&
market.neoPool != null);
const marketHasPool = market.neoPool != null;

const poolCreationDate = new Date(
indexedMarket.pool?.createdAt ?? indexedMarket.neoPool?.createdAt ?? "",
Expand Down Expand Up @@ -396,7 +391,7 @@ const Market: NextPage<MarketPageProps> = ({

<Tab
key="twitch"
className="flex items-center gap-2 rounded-md border-1 border-twitch-purple px-2 py-1 text-twitch-purple ui-selected:border-transparent ui-selected:bg-twitch-purple ui-selected:text-twitch-gray"
className="border-twitch-purple text-twitch-purple ui-selected:bg-twitch-purple ui-selected:text-twitch-gray flex items-center gap-2 rounded-md border-1 px-2 py-1 ui-selected:border-transparent"
>
<FaTwitch size={16} />
Twitch Stream
Expand Down

0 comments on commit f2163ea

Please sign in to comment.