Skip to content

Commit

Permalink
Merge pull request #87 from agoric-labs/fix/reveal-liquidation-graph
Browse files Browse the repository at this point in the history
fix: show liquidation graph again
  • Loading branch information
frazarshad authored Jun 27, 2024
2 parents e57b86c + 0982a70 commit d7fdcee
Show file tree
Hide file tree
Showing 5 changed files with 6,188 additions and 41 deletions.
30 changes: 15 additions & 15 deletions src/components/LiquidatedVaultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ export const columns: DataColumn<Row>[] = [
type: 'number',
header: 'IST Debt Amount',
},
// {
// accessorKey: 'liquidation_margin_avg',
// type: 'percent',
// header: 'Liquidation Ratio',
// },
// {
// accessorKey: 'liquidating_rate',
// type: 'usd',
// header: 'Liquidation Price',
// },
{
accessorKey: 'liquidation_margin_avg',
type: 'percent',
header: 'Liquidation Ratio',
},
{
accessorKey: 'liquidating_rate',
type: 'usd',
header: 'Liquidation Price',
},
{
accessorKey: 'liquidated_return_amount',
type: 'number',
header: 'Collateral Returned Amount',
},
// {
// accessorKey: 'liquidated_return_amount_usd',
// type: 'usd',
// header: 'Collateral Returned ($USD)',
// },
{
accessorKey: 'liquidated_return_amount_usd',
type: 'usd',
header: 'Collateral Returned ($USD)',
},
];

export function LiquidatedVaultsTable({ data }: Props) {
Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const VBANK_RESERVE_ACCOUNT = 'vbank/reserve';
export const GRAPH_DAYS = 90;

export const SUBQUERY_URL = 'https://api.subquery.network/sq/agoric-labs/agoric-mainnet-v2';
export const SUBQUERY_STAGING_URL = 'https://api.subquery.network/sq/agoric-labs/agoric-mainnet-v2';

export const enum VAULT_STATES {
ACTIVE = 'active',
Expand Down
46 changes: 21 additions & 25 deletions src/pages/Liquidated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { VaultStatesChart } from '@/widgets/VaultStatesChart';
import { populateMissingDays, subQueryFetcher } from '@/utils';
import { LIQUIDATIONS_DASHBOARD, VAULT_STATE_DAILIES_QUERY } from '@/queries';
import { GraphData, LiquidationDashboardResponse, VaultStateDailyResponse } from '@/types/liquidation-types';
import { GRAPH_DAYS, SUBQUERY_STAGING_URL } from '@/constants';
import { GRAPH_DAYS } from '@/constants';
import { ErrorAlert } from '@/components/ErrorAlert';

export function Liquidated() {
const { data, isLoading, error } = useSWR<AxiosResponse, AxiosError>(LIQUIDATIONS_DASHBOARD, (query: string) =>
subQueryFetcher(query),
);
const { data, isLoading, error } = useSWR<AxiosResponse, AxiosError>(LIQUIDATIONS_DASHBOARD, subQueryFetcher);
const response: LiquidationDashboardResponse = data?.data?.data;

const boardAuxes: { [key: string]: number } = response?.boardAuxes?.nodes?.reduce(
Expand All @@ -28,28 +26,26 @@ export function Liquidated() {
};

// Queries for graph
// const {
// data: vaultStateDailyData,
// isLoading: graphDataIsLoading,
// error: graphDataError,
// } = useSWR<AxiosResponse, AxiosError>(VAULT_STATE_DAILIES_QUERY, (query: string) =>
// subQueryFetcher(query, SUBQUERY_STAGING_URL),
// );
// const vaultStateDailyResponse: VaultStateDailyResponse = vaultStateDailyData?.data?.data;
// const graphDataMap: { [key: number]: GraphData } = {};
// vaultStateDailyResponse?.vaultStatesDailies.nodes?.forEach((vaultState) => {
// graphDataMap[Number(vaultState.id)] = {
// x: vaultState.blockTimeLast?.split('T')[0],
// key: Number(vaultState.id),
// active: Number(vaultState.active),
// liquidated: Number(vaultState.liquidated) + Number(vaultState.liquidatedClosed),
// closed: Number(vaultState.closed),
// };
// });
const {
data: vaultStateDailyData,
isLoading: graphDataIsLoading,
error: graphDataError,
} = useSWR<AxiosResponse, AxiosError>(VAULT_STATE_DAILIES_QUERY, subQueryFetcher);
const vaultStateDailyResponse: VaultStateDailyResponse = vaultStateDailyData?.data?.data;
const graphDataMap: { [key: number]: GraphData } = {};
vaultStateDailyResponse?.vaultStatesDailies.nodes?.forEach((vaultState) => {
graphDataMap[Number(vaultState.id)] = {
x: vaultState.blockTimeLast?.split('T')[0],
key: Number(vaultState.id),
active: Number(vaultState.active),
liquidated: Number(vaultState.liquidated) + Number(vaultState.liquidatedClosed),
closed: Number(vaultState.closed),
};
});

// const graphDataList = populateMissingDays(graphDataMap, GRAPH_DAYS);
const graphDataList = populateMissingDays(graphDataMap, GRAPH_DAYS);

const errorMessage = error;
const errorMessage = error || graphDataError;
if (errorMessage) {
return <ErrorAlert value={errorMessage} title="Request Error" />;
}
Expand All @@ -61,7 +57,7 @@ export function Liquidated() {
<ValueCardGrid>
<LiquidatedVaultCountCard data={response?.vaultManagerMetrics?.nodes} isLoading={isLoading} />
</ValueCardGrid>
{/* <VaultStatesChart data={graphDataList} isLoading={graphDataIsLoading} /> */}
<VaultStatesChart data={graphDataList} isLoading={graphDataIsLoading} />
<hr className="my-5" />
<LiquidatedVaults data={liquidationDashboardData} boardAuxes={boardAuxes} isLoading={isLoading} />
</PageContent>
Expand Down
2 changes: 2 additions & 0 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ query {
state
balance
blockTime
oraclePrice
vaultManagerGovernance
currentState {
id
denom
Expand Down
Loading

0 comments on commit d7fdcee

Please sign in to comment.