-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuseUtilizationRatio.ts
37 lines (35 loc) · 1.13 KB
/
useUtilizationRatio.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { HyperdriveConfig } from "@hyperdrive/appconfig";
import { calculateRatio } from "src/base/calculateRatio";
import { useLpShares } from "src/ui/hyperdrive/lp/hooks/useLpShares";
import { usePreviewRemoveLiquidity } from "src/ui/hyperdrive/lp/hooks/usePreviewRemoveLiquidity";
import { Address } from "viem";
export function useUtilizationRatio({
hyperdrive,
account,
}: {
hyperdrive: HyperdriveConfig;
account: Address | undefined;
}): bigint | undefined {
const { lpShares } = useLpShares({
hyperdriveAddress: hyperdrive.address,
account,
});
const { withdrawalShares } = usePreviewRemoveLiquidity({
hyperdriveAddress: hyperdrive.address,
lpSharesIn: lpShares,
minOutputPerShare: 1n,
destination: account,
// Set asBase to false because we just need the withdrawal shares amount and
// it should always be possible to withdraw as shares
asBase: false,
});
const utilizationRatio =
!!withdrawalShares && !!lpShares
? calculateRatio({
a: withdrawalShares,
b: lpShares,
decimals: hyperdrive.decimals,
})
: undefined;
return utilizationRatio;
}