Skip to content

Commit

Permalink
Merge pull request #2383 from zeitgeistpm/tr-new-asset-system
Browse files Browse the repository at this point in the history
New asset systems fixes + New indexer schema
  • Loading branch information
Robiquet authored Apr 18, 2024
2 parents eb07bcf + c9554f8 commit 9212fe8
Show file tree
Hide file tree
Showing 26 changed files with 564 additions and 1,028 deletions.
59 changes: 17 additions & 42 deletions components/assets/AssetActionButtons/PoolShareButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import LiquidityModal from "components/liquidity/LiquidityModal";
import SecondaryButton from "components/ui/SecondaryButton";
import { usePool } from "lib/hooks/queries/usePool";
import { useState } from "react";
import { MarketStatus, FullMarketFragment } from "@zeitgeistpm/indexer";
import { useExtrinsic } from "lib/hooks/useExtrinsic";
import { useNotifications } from "lib/state/notifications";
import { useSdkv2 } from "lib/hooks/useSdkv2";
import { FullMarketFragment } from "@zeitgeistpm/indexer";
import {
IOBaseAssetId,
IOCategoricalAssetId,
getIndexOf,
isRpcSdk,
parseAssetId,
} from "@zeitgeistpm/sdk";
import { useChainConstants } from "lib/hooks/queries/useChainConstants";
import { useBalance } from "lib/hooks/queries/useBalance";
import { useWallet } from "lib/state/wallet";
import SecondaryButton from "components/ui/SecondaryButton";
import Decimal from "decimal.js";
import { DEFAULT_SLIPPAGE_PERCENTAGE } from "lib/constants";
import { useAccountPoolAssetBalances } from "lib/hooks/queries/useAccountPoolAssetBalances";
import { useBalance } from "lib/hooks/queries/useBalance";
import { useChainConstants } from "lib/hooks/queries/useChainConstants";
import { usePool } from "lib/hooks/queries/usePool";
import { usePoolBaseBalance } from "lib/hooks/queries/usePoolBaseBalance";
import { DEFAULT_SLIPPAGE_PERCENTAGE } from "lib/constants";
import { useTotalIssuance } from "lib/hooks/queries/useTotalIssuance";
import Decimal from "decimal.js";
import { useTotalIssuanceForPools } from "lib/hooks/queries/useTotalIssuanceForPools";
import { useExtrinsic } from "lib/hooks/useExtrinsic";
import { useSdkv2 } from "lib/hooks/useSdkv2";
import { useNotifications } from "lib/state/notifications";
import { useWallet } from "lib/state/wallet";
import { parseAssetIdString } from "lib/util/parse-asset-id";

const RedeemPoolButton = ({
Expand All @@ -43,12 +41,11 @@ const RedeemPoolButton = ({
pool,
);
const { data: poolBaseBalance } = usePoolBaseBalance(poolId);
const { data: totalPoolSharesIssuance } = useTotalIssuance({
PoolShare: poolId,
});
const poolsTotalIssuance = useTotalIssuanceForPools([poolId]);
const { data: totalPoolSharesIssuance } = poolsTotalIssuance[poolId];
const userPercentageOwnership =
userPoolShares && totalPoolSharesIssuance
? userPoolShares.div(totalPoolSharesIssuance)
userPoolShares && totalPoolSharesIssuance?.totalIssuance
? userPoolShares.div(totalPoolSharesIssuance.totalIssuance.toNumber())
: new Decimal(0);

// filter out non-winning assets as they are deleted on chain
Expand Down Expand Up @@ -144,29 +141,7 @@ const PoolShareButtons = ({
poolId: number;
market: FullMarketFragment;
}) => {
const [manageLiquidityOpen, setManageLiquidityOpen] = useState(false);

return (
<>
{market.status === MarketStatus.Resolved ? (
<RedeemPoolButton poolId={poolId} market={market} />
) : (
<>
<SecondaryButton
onClick={() => setManageLiquidityOpen(true)}
className="ml-auto max-w-[160px]"
>
Manage Liquidity
</SecondaryButton>
<LiquidityModal
poolId={poolId}
open={manageLiquidityOpen}
onClose={() => setManageLiquidityOpen(false)}
/>
</>
)}
</>
);
return <RedeemPoolButton poolId={poolId} market={market} />;
};

export default PoolShareButtons;
10 changes: 6 additions & 4 deletions components/assets/AssetActionButtons/RedeemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const RedeemButtonByAssetId = ({

const balance = getAccountAssetBalance(realAddress, resolvedAssetId)?.data
?.balance;
return new Decimal(balance?.free.toString() ?? 0).div(ZTG);
return balance?.div(ZTG);
} else {
const shortBalance = getAccountAssetBalance(realAddress, {
ScalarOutcome: [market.marketId as MarketId, "Short"],
Expand All @@ -107,13 +107,15 @@ export const RedeemButtonByAssetId = ({
lowerBound,
upperBound,
new Decimal(resolvedNumber).div(ZTG),
new Decimal(shortBalance.free.toNumber()).div(ZTG),
new Decimal(longBalance.free.toNumber()).div(ZTG),
shortBalance.div(ZTG),
longBalance.div(ZTG),
);
}
}, [market, assetId, isLoadingAssetBalance, getAccountAssetBalance]);

return <RedeemButtonByValue market={market} value={value} />;
return (
<RedeemButtonByValue market={market} value={value ?? new Decimal(0)} />
);
};

const RedeemButtonByValue = ({
Expand Down
274 changes: 0 additions & 274 deletions components/liquidity/ExitPoolForm.tsx

This file was deleted.

Loading

0 comments on commit 9212fe8

Please sign in to comment.