@mezo-org/passport 0.5.2-dev.3 → 0.5.2-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js +0 -2
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.js +9 -36
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +0 -15
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
- package/dist/src/hooks/useBorrowData.js +3 -25
- package/dist/src/hooks/useBorrowData.js.map +1 -1
- package/dist/src/hooks/useCollateralPrice.d.ts +17 -0
- package/dist/src/hooks/useCollateralPrice.d.ts.map +1 -0
- package/dist/src/hooks/useCollateralPrice.js +56 -0
- package/dist/src/hooks/useCollateralPrice.js.map +1 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
- package/dist/src/hooks/useTokensBalances.js +0 -7
- package/dist/src/hooks/useTokensBalances.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +1 -1
- package/dist/src/lib/contracts/index.d.ts.map +1 -1
- package/dist/src/lib/contracts/index.js +0 -1
- package/dist/src/lib/contracts/index.js.map +1 -1
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Dropdown/Root/AccountMusdListing.tsx +0 -2
- package/src/hooks/useAssetsConversionRates.ts +10 -43
- package/src/hooks/useBorrowData.ts +5 -27
- package/src/hooks/useCollateralPrice.ts +64 -0
- package/src/hooks/useTokensBalances.ts +0 -9
- package/src/lib/contracts/index.ts +0 -2
- package/src/utils/numbers.test.ts +0 -1
- package/dist/src/hooks/useTokensBalances copy.d.ts +0 -74
- package/dist/src/hooks/useTokensBalances copy.d.ts.map +0 -1
- package/dist/src/hooks/useTokensBalances copy.js +0 -206
- package/dist/src/hooks/useTokensBalances copy.js.map +0 -1
- package/dist/src/lib/contracts/priceOracle.d.ts +0 -43
- package/dist/src/lib/contracts/priceOracle.d.ts.map +0 -1
- package/dist/src/lib/contracts/priceOracle.js +0 -52
- package/dist/src/lib/contracts/priceOracle.js.map +0 -1
- package/dist/src/utils/chain.d.ts +0 -2
- package/dist/src/utils/chain.d.ts.map +0 -1
- package/dist/src/utils/chain.js +0 -5
- package/dist/src/utils/chain.js.map +0 -1
- package/dist/src/utils/number2.d.ts +0 -106
- package/dist/src/utils/number2.d.ts.map +0 -1
- package/dist/src/utils/number2.js +0 -289
- package/dist/src/utils/number2.js.map +0 -1
- package/dist/src/utils/number2.test.d.ts +0 -2
- package/dist/src/utils/number2.test.d.ts.map +0 -1
- package/dist/src/utils/number2.test.js +0 -223
- package/dist/src/utils/number2.test.js.map +0 -1
- package/src/hooks/useTokensBalances copy.ts +0 -289
- package/src/lib/contracts/priceOracle.ts +0 -53
- package/src/utils/chain.ts +0 -5
- package/src/utils/number2.test.ts +0 -309
- package/src/utils/number2.ts +0 -419
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useReadContract } from "wagmi"
|
|
2
|
+
import { useMemo } from "react"
|
|
3
|
+
import { ONE_MINUTE_MS } from "../utils/time"
|
|
4
|
+
import {
|
|
5
|
+
mainnetBorrowContracts,
|
|
6
|
+
testnetBorrowContracts,
|
|
7
|
+
} from "../lib/contracts"
|
|
8
|
+
import { usePassportContext } from "./usePassportContext"
|
|
9
|
+
import { CHAIN_ID } from "../constants"
|
|
10
|
+
import useWalletAccount from "./useWalletAccount"
|
|
11
|
+
|
|
12
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
13
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
14
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
15
|
+
// be asserted types from.
|
|
16
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
17
|
+
|
|
18
|
+
const PRICE_FEED_ABI = [
|
|
19
|
+
{
|
|
20
|
+
inputs: [],
|
|
21
|
+
name: "fetchPrice",
|
|
22
|
+
outputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: "uint256",
|
|
25
|
+
name: "",
|
|
26
|
+
type: "uint256",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
stateMutability: "view",
|
|
30
|
+
type: "function",
|
|
31
|
+
},
|
|
32
|
+
] as const
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Query hook for getting borrow data. Returns collateral and trove debt for the
|
|
36
|
+
* connected account, based on it's evm address.
|
|
37
|
+
* @param queryOptions Query options passed to the underlying `useQuery` hook.
|
|
38
|
+
*/
|
|
39
|
+
export function useCollateralPrice(queryOptions = {}) {
|
|
40
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
41
|
+
const walletAccount = useWalletAccount()
|
|
42
|
+
|
|
43
|
+
const priceFeedContractAddress = useMemo(() => {
|
|
44
|
+
if (environment === "mainnet") {
|
|
45
|
+
return mainnetBorrowContracts.PriceFeed.address
|
|
46
|
+
}
|
|
47
|
+
return testnetBorrowContracts.PriceFeed.address
|
|
48
|
+
}, [environment])
|
|
49
|
+
|
|
50
|
+
const chainId = CHAIN_ID[environment]
|
|
51
|
+
|
|
52
|
+
return useReadContract({
|
|
53
|
+
abi: PRICE_FEED_ABI,
|
|
54
|
+
address: priceFeedContractAddress,
|
|
55
|
+
functionName: "fetchPrice",
|
|
56
|
+
chainId,
|
|
57
|
+
query: {
|
|
58
|
+
enabled: !!walletAccount.accountAddress,
|
|
59
|
+
staleTime: 5 * ONE_MINUTE_MS,
|
|
60
|
+
retry: 1,
|
|
61
|
+
...queryOptions,
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
}
|
|
@@ -21,7 +21,6 @@ import { convertToUsd } from "../utils/currency"
|
|
|
21
21
|
import { CHAIN_ID, mezoMainnet, mezoTestnet } from "../constants"
|
|
22
22
|
import { useAssetsConversionRates } from "./useAssetsConversionRates"
|
|
23
23
|
import { normalizePrecision } from "../utils/numbers"
|
|
24
|
-
import { isMezoChain } from "../utils/chain"
|
|
25
24
|
import { usePassportContext } from "./usePassportContext"
|
|
26
25
|
|
|
27
26
|
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
@@ -119,14 +118,6 @@ export function useTokensBalances<T extends MezoChainToken[]>(
|
|
|
119
118
|
|
|
120
119
|
const chainId = environment === "testnet" ? mezoTestnet.id : mezoMainnet.id
|
|
121
120
|
|
|
122
|
-
const isMezoChainId = isMezoChain(config.state.chainId)
|
|
123
|
-
|
|
124
|
-
console.log("walletAccount?.accountAddress: ", walletAccount?.accountAddress)
|
|
125
|
-
console.log("conversionRatesData: ", conversionRatesData)
|
|
126
|
-
console.log("isMezoChainId: ", isMezoChainId)
|
|
127
|
-
console.log("chainId: ", config.state.chainId)
|
|
128
|
-
console.log("real chain id right now: ", chainId)
|
|
129
|
-
|
|
130
121
|
return useQuery({
|
|
131
122
|
queryKey: [
|
|
132
123
|
TOKEN_BALANCES_QUERY_KEY,
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
-
import { MezoChainToken } from "../lib/contracts";
|
|
3
|
-
export declare const BALANCE_OF_ABI: readonly [{
|
|
4
|
-
readonly inputs: readonly [{
|
|
5
|
-
readonly internalType: "address";
|
|
6
|
-
readonly name: "account";
|
|
7
|
-
readonly type: "address";
|
|
8
|
-
}];
|
|
9
|
-
readonly name: "balanceOf";
|
|
10
|
-
readonly outputs: readonly [{
|
|
11
|
-
readonly internalType: "uint256";
|
|
12
|
-
readonly name: "";
|
|
13
|
-
readonly type: "uint256";
|
|
14
|
-
}];
|
|
15
|
-
readonly stateMutability: "view";
|
|
16
|
-
readonly type: "function";
|
|
17
|
-
}];
|
|
18
|
-
type UseMezoChainTokensBalancesOptions<T extends MezoChainToken[]> = {
|
|
19
|
-
tokens?: T;
|
|
20
|
-
queryOptions?: Omit<UseQueryOptions<Record<T[number], TokenBalance>>, "queryKey" | "queryFn" | "select" | "enabled">;
|
|
21
|
-
};
|
|
22
|
-
export type TokenBalance = {
|
|
23
|
-
decimals: number;
|
|
24
|
-
symbol: string;
|
|
25
|
-
value: bigint;
|
|
26
|
-
usd: {
|
|
27
|
-
value: number;
|
|
28
|
-
formatted: string;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Hook to get the balance of a list of Mezo tokens for the current account
|
|
33
|
-
* @param options.tokens The list of tokens to get the balance for. It will
|
|
34
|
-
* fallback to all tokens if not provided.
|
|
35
|
-
* @param options.queryOptions The query options to pass to the
|
|
36
|
-
* `useReadContracts`
|
|
37
|
-
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
38
|
-
* current account in form of typesafe object with token names as keys
|
|
39
|
-
* and balances as values.
|
|
40
|
-
* @example
|
|
41
|
-
* const mezoTokensBalance = useTokensBalances({
|
|
42
|
-
* tokens: ["mT", "mxSolvBTC"],
|
|
43
|
-
* })
|
|
44
|
-
* // Assuming the status is "success"
|
|
45
|
-
* console.log(mezoTokensBalance.data.mT) // Eg. { value: 0n ... }
|
|
46
|
-
* console.log(Object.keys(mezoTokensBalance.data)) // ["mT", "mxSolvBTC"]
|
|
47
|
-
*/
|
|
48
|
-
export declare function useTokensBalances<T extends MezoChainToken[]>(options?: UseMezoChainTokensBalancesOptions<T>): import("@tanstack/react-query").UseQueryResult<Record<"BTC" | T[number], TokenBalance>, Error>;
|
|
49
|
-
/**
|
|
50
|
-
* Hook for invalidating current user's token balances. Can be used to
|
|
51
|
-
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
52
|
-
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
53
|
-
* @example
|
|
54
|
-
* const { invalidateTokenBalances } = useInvalidateTokensBalances()
|
|
55
|
-
* (...)
|
|
56
|
-
* await invalidateTokenBalances()
|
|
57
|
-
*/
|
|
58
|
-
export declare function useInvalidateTokensBalances(): {
|
|
59
|
-
invalidateTokensBalances: () => Promise<void>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Hook for resetting current user's token balances. Can be used to reset the
|
|
63
|
-
* balances manually, which forces the data to be re-fetched.
|
|
64
|
-
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
65
|
-
* @example
|
|
66
|
-
* const { resetTokenBalances } = useResetTokensBalances()
|
|
67
|
-
* (...)
|
|
68
|
-
* await resetTokenBalances()
|
|
69
|
-
*/
|
|
70
|
-
export declare function useResetTokensBalances(): {
|
|
71
|
-
resetTokenBalances: () => Promise<void>;
|
|
72
|
-
};
|
|
73
|
-
export {};
|
|
74
|
-
//# sourceMappingURL=useTokensBalances%20copy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTokensBalances copy.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTokensBalances copy.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,cAAc,EAEf,MAAM,kBAAkB,CAAA;AAwBzB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;EAoBH,CAAA;AAgBxB,KAAK,iCAAiC,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI;IACnE,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,YAAY,CAAC,EAAE,IAAI,CACjB,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,EAChD,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAC9C,CAAA;CACF,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAAE,EAC1D,OAAO,GAAE,iCAAiC,CAAC,CAAC,CAAM,kGA0InD;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B;;EAS1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB;;EASrC"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { useConfig } from "wagmi";
|
|
2
|
-
import { useQuery, useQueryClient, } from "@tanstack/react-query";
|
|
3
|
-
import { getBalance, readContracts } from "wagmi/actions";
|
|
4
|
-
import { mainnetTokenContracts, testnetTokenContracts, } from "../lib/contracts";
|
|
5
|
-
import useWalletAccount from "./useWalletAccount";
|
|
6
|
-
import { getAsset, isBitcoinLikeCryptoAsset, isTTokenCryptoAsset, } from "../utils/assets";
|
|
7
|
-
import { convertToUsd } from "../utils/currency";
|
|
8
|
-
import { CHAIN_ID } from "../constants";
|
|
9
|
-
import { useAssetsConversionRates } from "./useAssetsConversionRates";
|
|
10
|
-
import { isMezoChain } from "../utils/chain";
|
|
11
|
-
import { amountAsUSD, bigIntToFloat, floatToHumanReadableFormat, } from "../utils/number2";
|
|
12
|
-
import { useBorrowData } from "./useBorrowData";
|
|
13
|
-
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
14
|
-
// support importing JSON as const yet so types cannot be inferred from the
|
|
15
|
-
// imported contract. As a workaround there is minimal ABI definition that can
|
|
16
|
-
// be asserted types from.
|
|
17
|
-
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
18
|
-
export const BALANCE_OF_ABI = [
|
|
19
|
-
{
|
|
20
|
-
inputs: [
|
|
21
|
-
{
|
|
22
|
-
internalType: "address",
|
|
23
|
-
name: "account",
|
|
24
|
-
type: "address",
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
name: "balanceOf",
|
|
28
|
-
outputs: [
|
|
29
|
-
{
|
|
30
|
-
internalType: "uint256",
|
|
31
|
-
name: "",
|
|
32
|
-
type: "uint256",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
stateMutability: "view",
|
|
36
|
-
type: "function",
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
const BALANCE_TOKENS = [
|
|
40
|
-
"mcbBTC",
|
|
41
|
-
"mDAI",
|
|
42
|
-
"mFBTC",
|
|
43
|
-
"mSolvBTC",
|
|
44
|
-
"mswBTC",
|
|
45
|
-
"mT",
|
|
46
|
-
"mUSDC",
|
|
47
|
-
"mUSDe",
|
|
48
|
-
"mUSDT",
|
|
49
|
-
"mxSolvBTC",
|
|
50
|
-
"MUSD",
|
|
51
|
-
];
|
|
52
|
-
const TOKEN_BALANCES_QUERY_KEY = "passport.tokenBalances";
|
|
53
|
-
/**
|
|
54
|
-
* Hook to get the balance of a list of Mezo tokens for the current account
|
|
55
|
-
* @param options.tokens The list of tokens to get the balance for. It will
|
|
56
|
-
* fallback to all tokens if not provided.
|
|
57
|
-
* @param options.queryOptions The query options to pass to the
|
|
58
|
-
* `useReadContracts`
|
|
59
|
-
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
60
|
-
* current account in form of typesafe object with token names as keys
|
|
61
|
-
* and balances as values.
|
|
62
|
-
* @example
|
|
63
|
-
* const mezoTokensBalance = useTokensBalances({
|
|
64
|
-
* tokens: ["mT", "mxSolvBTC"],
|
|
65
|
-
* })
|
|
66
|
-
* // Assuming the status is "success"
|
|
67
|
-
* console.log(mezoTokensBalance.data.mT) // Eg. { value: 0n ... }
|
|
68
|
-
* console.log(Object.keys(mezoTokensBalance.data)) // ["mT", "mxSolvBTC"]
|
|
69
|
-
*/
|
|
70
|
-
export function useTokensBalances(options = {}) {
|
|
71
|
-
const { tokens = BALANCE_TOKENS, ...restQueryOptions } = options;
|
|
72
|
-
const walletAccount = useWalletAccount();
|
|
73
|
-
const config = useConfig();
|
|
74
|
-
const { data: conversionRatesData } = useAssetsConversionRates();
|
|
75
|
-
const isMezoChainId = isMezoChain(config.state.chainId);
|
|
76
|
-
const { data: borrowData } = useBorrowData();
|
|
77
|
-
return useQuery({
|
|
78
|
-
queryKey: [
|
|
79
|
-
TOKEN_BALANCES_QUERY_KEY,
|
|
80
|
-
walletAccount?.accountAddress,
|
|
81
|
-
options.tokens,
|
|
82
|
-
config.state.chainId,
|
|
83
|
-
borrowData?.collateral.value.toString(),
|
|
84
|
-
],
|
|
85
|
-
enabled: !!walletAccount?.accountAddress &&
|
|
86
|
-
!!conversionRatesData &&
|
|
87
|
-
isMezoChainId &&
|
|
88
|
-
!!borrowData?.collateral.value,
|
|
89
|
-
queryFn: async () => {
|
|
90
|
-
const { chainId } = config.state;
|
|
91
|
-
const isMainnet = chainId === CHAIN_ID.mainnet;
|
|
92
|
-
const contractsMap = isMainnet
|
|
93
|
-
? mainnetTokenContracts
|
|
94
|
-
: testnetTokenContracts;
|
|
95
|
-
const accountAddress = walletAccount?.accountAddress;
|
|
96
|
-
if (!accountAddress) {
|
|
97
|
-
throw new Error("Account address is not available.");
|
|
98
|
-
}
|
|
99
|
-
const tokenContracts = tokens.map((token) => {
|
|
100
|
-
const { address } = contractsMap[token];
|
|
101
|
-
return {
|
|
102
|
-
address,
|
|
103
|
-
abi: BALANCE_OF_ABI,
|
|
104
|
-
functionName: "balanceOf",
|
|
105
|
-
args: [accountAddress],
|
|
106
|
-
chainId,
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
return Promise.all([
|
|
110
|
-
getBalance(config, { address: accountAddress }),
|
|
111
|
-
readContracts(config, {
|
|
112
|
-
contracts: tokenContracts,
|
|
113
|
-
}),
|
|
114
|
-
]);
|
|
115
|
-
},
|
|
116
|
-
select: (data) => {
|
|
117
|
-
const [btcBalance, tokensBalancesData] = data;
|
|
118
|
-
if (!conversionRatesData) {
|
|
119
|
-
throw new Error("Conversion rates data is not available.");
|
|
120
|
-
}
|
|
121
|
-
const parsedBtcBalance = {
|
|
122
|
-
...btcBalance,
|
|
123
|
-
symbol: getAsset("BTC").symbol,
|
|
124
|
-
usd: convertToUsd(btcBalance.value, btcBalance.decimals, BigInt(conversionRatesData.rates.BTC), conversionRatesData.decimals),
|
|
125
|
-
};
|
|
126
|
-
const parsedTokensBalances = tokensBalancesData.map((item, index) => {
|
|
127
|
-
const token = tokens[index];
|
|
128
|
-
const { decimals, symbol } = getAsset(token);
|
|
129
|
-
if (item.status === "failure") {
|
|
130
|
-
throw new Error(`Failed to fetch balance of ${token} for ${walletAccount?.accountAddress}.`);
|
|
131
|
-
}
|
|
132
|
-
const floatAmount = bigIntToFloat({
|
|
133
|
-
amount: item.result,
|
|
134
|
-
decimals,
|
|
135
|
-
});
|
|
136
|
-
// const formatted =
|
|
137
|
-
// Number(floatAmount) * getTokenUsdPrice(token as SupportedTokenName)
|
|
138
|
-
const tokenBalance = {
|
|
139
|
-
value: item.result,
|
|
140
|
-
decimals,
|
|
141
|
-
symbol,
|
|
142
|
-
};
|
|
143
|
-
let value = Number(item.result);
|
|
144
|
-
let usd = {
|
|
145
|
-
value,
|
|
146
|
-
formatted: floatToHumanReadableFormat(amountAsUSD({ amount: value })),
|
|
147
|
-
};
|
|
148
|
-
if (isBitcoinLikeCryptoAsset(tokenBalance.symbol)) {
|
|
149
|
-
// TODO: had to add number for rates to avoid red underline
|
|
150
|
-
value = Number(floatAmount) * Number(conversionRatesData.rates.BTC);
|
|
151
|
-
usd = {
|
|
152
|
-
value,
|
|
153
|
-
formatted: floatToHumanReadableFormat(amountAsUSD({ amount: value })),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (isTTokenCryptoAsset(tokenBalance.symbol)) {
|
|
157
|
-
// TODO: had to add number for rates to avoid red underline
|
|
158
|
-
value = Number(floatAmount) * Number(conversionRatesData.rates.mT);
|
|
159
|
-
usd = {
|
|
160
|
-
value,
|
|
161
|
-
formatted: floatToHumanReadableFormat(amountAsUSD({ amount: value })),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return { ...tokenBalance, usd };
|
|
165
|
-
});
|
|
166
|
-
return [parsedBtcBalance, ...parsedTokensBalances].reduce((acc, token) => ({
|
|
167
|
-
...acc,
|
|
168
|
-
[token.symbol]: token,
|
|
169
|
-
}), {});
|
|
170
|
-
},
|
|
171
|
-
...restQueryOptions,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Hook for invalidating current user's token balances. Can be used to
|
|
176
|
-
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
177
|
-
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
178
|
-
* @example
|
|
179
|
-
* const { invalidateTokenBalances } = useInvalidateTokensBalances()
|
|
180
|
-
* (...)
|
|
181
|
-
* await invalidateTokenBalances()
|
|
182
|
-
*/
|
|
183
|
-
export function useInvalidateTokensBalances() {
|
|
184
|
-
const queryClient = useQueryClient();
|
|
185
|
-
const invalidateTokensBalancesHandler = () => queryClient.invalidateQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] });
|
|
186
|
-
return {
|
|
187
|
-
invalidateTokensBalances: invalidateTokensBalancesHandler,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Hook for resetting current user's token balances. Can be used to reset the
|
|
192
|
-
* balances manually, which forces the data to be re-fetched.
|
|
193
|
-
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
194
|
-
* @example
|
|
195
|
-
* const { resetTokenBalances } = useResetTokensBalances()
|
|
196
|
-
* (...)
|
|
197
|
-
* await resetTokenBalances()
|
|
198
|
-
*/
|
|
199
|
-
export function useResetTokensBalances() {
|
|
200
|
-
const queryClient = useQueryClient();
|
|
201
|
-
const resetTokenBalancesHandler = () => queryClient.resetQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] });
|
|
202
|
-
return {
|
|
203
|
-
resetTokenBalances: resetTokenBalancesHandler,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
//# sourceMappingURL=useTokensBalances%20copy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTokensBalances copy.js","sourceRoot":"","sources":["../../../src/hooks/useTokensBalances copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EACL,QAAQ,EACR,cAAc,GAEf,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EACL,qBAAqB,EAErB,qBAAqB,GACtB,MAAM,kBAAkB,CAAA;AACzB,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,QAAQ,EACR,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EACL,WAAW,EACX,aAAa,EACb,0BAA0B,GAC3B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,yEAAyE;AACzE,2EAA2E;AAC3E,8EAA8E;AAC9E,0BAA0B;AAC1B,qEAAqE;AAErE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM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
|
3
|
-
address: Address;
|
|
4
|
-
abi: readonly [{
|
|
5
|
-
readonly inputs: readonly [];
|
|
6
|
-
readonly name: "decimals";
|
|
7
|
-
readonly outputs: readonly [{
|
|
8
|
-
readonly internalType: "uint8";
|
|
9
|
-
readonly name: "";
|
|
10
|
-
readonly type: "uint8";
|
|
11
|
-
}];
|
|
12
|
-
readonly stateMutability: "view";
|
|
13
|
-
readonly type: "function";
|
|
14
|
-
}, {
|
|
15
|
-
readonly inputs: readonly [];
|
|
16
|
-
readonly name: "latestRoundData";
|
|
17
|
-
readonly outputs: readonly [{
|
|
18
|
-
readonly internalType: "uint80";
|
|
19
|
-
readonly name: "roundId";
|
|
20
|
-
readonly type: "uint80";
|
|
21
|
-
}, {
|
|
22
|
-
readonly internalType: "int256";
|
|
23
|
-
readonly name: "answer";
|
|
24
|
-
readonly type: "int256";
|
|
25
|
-
}, {
|
|
26
|
-
readonly internalType: "uint256";
|
|
27
|
-
readonly name: "startedAt";
|
|
28
|
-
readonly type: "uint256";
|
|
29
|
-
}, {
|
|
30
|
-
readonly internalType: "uint256";
|
|
31
|
-
readonly name: "updatedAt";
|
|
32
|
-
readonly type: "uint256";
|
|
33
|
-
}, {
|
|
34
|
-
readonly internalType: "uint80";
|
|
35
|
-
readonly name: "answeredInRound";
|
|
36
|
-
readonly type: "uint80";
|
|
37
|
-
}];
|
|
38
|
-
readonly stateMutability: "view";
|
|
39
|
-
readonly type: "function";
|
|
40
|
-
}];
|
|
41
|
-
};
|
|
42
|
-
export default _default;
|
|
43
|
-
//# sourceMappingURL=priceOracle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"priceOracle.d.ts","sourceRoot":"","sources":["../../../../src/lib/contracts/priceOracle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;;aAG6B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AADlE,wBAkDC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
address: "0x7b7c000000000000000000000000000000000015",
|
|
3
|
-
abi: [
|
|
4
|
-
{
|
|
5
|
-
inputs: [],
|
|
6
|
-
name: "decimals",
|
|
7
|
-
outputs: [
|
|
8
|
-
{
|
|
9
|
-
internalType: "uint8",
|
|
10
|
-
name: "",
|
|
11
|
-
type: "uint8",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
stateMutability: "view",
|
|
15
|
-
type: "function",
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
inputs: [],
|
|
19
|
-
name: "latestRoundData",
|
|
20
|
-
outputs: [
|
|
21
|
-
{
|
|
22
|
-
internalType: "uint80",
|
|
23
|
-
name: "roundId",
|
|
24
|
-
type: "uint80",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
internalType: "int256",
|
|
28
|
-
name: "answer",
|
|
29
|
-
type: "int256",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
internalType: "uint256",
|
|
33
|
-
name: "startedAt",
|
|
34
|
-
type: "uint256",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
internalType: "uint256",
|
|
38
|
-
name: "updatedAt",
|
|
39
|
-
type: "uint256",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
internalType: "uint80",
|
|
43
|
-
name: "answeredInRound",
|
|
44
|
-
type: "uint80",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
stateMutability: "view",
|
|
48
|
-
type: "function",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=priceOracle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"priceOracle.js","sourceRoot":"","sources":["../../../../src/lib/contracts/priceOracle.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,OAAO,EAAE,4CAAuD;IAChE,GAAG,EAAE;QACH;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,OAAO;oBACrB,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,OAAO;iBACd;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;QACD;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,iBAAiB;oBACvB,IAAI,EAAE,QAAQ;iBACf;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;KACO;CACX,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/utils/chain.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,WAE1C"}
|
package/dist/src/utils/chain.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/utils/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE9D,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,KAAK,WAAW,CAAC,EAAE,IAAI,OAAO,KAAK,WAAW,CAAC,EAAE,CAAA;AACjE,CAAC"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export declare const FLOATING_POINT_REGEX: RegExp;
|
|
2
|
-
/** PUBLIC HELPER FUNCTIONS for calculations */
|
|
3
|
-
/**
|
|
4
|
-
* Multiplies a bigint with a decimal number, taking into account the decimal places.
|
|
5
|
-
*
|
|
6
|
-
* @param bigint - The bigint value to multiply.
|
|
7
|
-
* @param number - The decimal number to multiply with.
|
|
8
|
-
* @returns The result of the multiplication as a bigint.
|
|
9
|
-
*/
|
|
10
|
-
export declare const multiplyBigIntWithDecimal: (bigint: bigint, number: number) => bigint;
|
|
11
|
-
/**
|
|
12
|
-
* Converts a fixed-point number to another fixed-point number with a different decimal precision.
|
|
13
|
-
* @param args The arguments for the conversion.
|
|
14
|
-
* - amount: required, the fixed-point number to convert.
|
|
15
|
-
* - decimals: required, the current decimal precision of the number.
|
|
16
|
-
* - targetDecimals: required, the target decimal precision for the conversion.
|
|
17
|
-
* @returns The converted fixed-point number.
|
|
18
|
-
*/
|
|
19
|
-
export declare const convertDecimals: ({ amount, decimals, targetDecimals, }: {
|
|
20
|
-
amount: bigint;
|
|
21
|
-
decimals: number;
|
|
22
|
-
targetDecimals: number;
|
|
23
|
-
}) => bigint;
|
|
24
|
-
/** Helper functions for input components */
|
|
25
|
-
/**
|
|
26
|
-
* Trims decimal places to a specified precision - NO ROUNDING!
|
|
27
|
-
* @param value The value to trim
|
|
28
|
-
* @param precision The number of decimal places to keep
|
|
29
|
-
* @returns The trimmed value
|
|
30
|
-
*/
|
|
31
|
-
export declare const trimDecimals: (value: string, precision: number) => string;
|
|
32
|
-
/**
|
|
33
|
-
* Trims integer part to a specified length - NO ROUNDING!
|
|
34
|
-
* @param value The value to trim
|
|
35
|
-
* @param precision The number of integer places to keep
|
|
36
|
-
* @returns The trimmed value
|
|
37
|
-
* @deprecated just compare the value to the max allowed value in the input component
|
|
38
|
-
*/
|
|
39
|
-
export declare const trimBeforeDecimals: (value: string, precision: number) => string;
|
|
40
|
-
/**
|
|
41
|
-
* Normalizes a decimal number input by removing invalid characters and preventing multiple dots.
|
|
42
|
-
* @param value The value to normalize
|
|
43
|
-
* @returns The normalized value
|
|
44
|
-
*/
|
|
45
|
-
export declare const normalizeDecimalNumber: (value: string) => string;
|
|
46
|
-
/**
|
|
47
|
-
* CONVERSION FUNCTIONS
|
|
48
|
-
* These functions convert between floating-point numbers and big integers as well as
|
|
49
|
-
* provide human-readable formats.
|
|
50
|
-
*
|
|
51
|
-
* They are used to ensure that numbers are correctly formatted for display and calculations
|
|
52
|
-
* and should be used in the UI and business logic to ensure correct number formatting.
|
|
53
|
-
*/
|
|
54
|
-
/** Basic conversion bigint <-> float */
|
|
55
|
-
/**
|
|
56
|
-
* Converts a floating-point number to a big integer representation.
|
|
57
|
-
* @param args The arguments for the conversion.
|
|
58
|
-
* - amount: required, the floating-point number to convert.
|
|
59
|
-
* - decimals: optional, the number of decimal places to consider.
|
|
60
|
-
* @returns The big integer representation of the floating-point number.
|
|
61
|
-
*/
|
|
62
|
-
export declare const floatToBigInt: ({ amount, decimals, }: {
|
|
63
|
-
amount: string | number;
|
|
64
|
-
decimals?: number;
|
|
65
|
-
}) => bigint;
|
|
66
|
-
/**
|
|
67
|
-
* Converts a big integer representation to a floating-point number.
|
|
68
|
-
* @param args The arguments for the conversion.
|
|
69
|
-
* - amount: required, the big integer representation to convert.
|
|
70
|
-
* - decimals: optional, the number of decimal places to consider.
|
|
71
|
-
* - desiredDecimals: optional, the desired number of decimal places for the output.
|
|
72
|
-
* @returns The floating-point representation of the big integer.
|
|
73
|
-
*/
|
|
74
|
-
export declare const bigIntToFloat: ({ amount, decimals, desiredDecimals, }: {
|
|
75
|
-
amount: bigint;
|
|
76
|
-
decimals?: number;
|
|
77
|
-
desiredDecimals?: number;
|
|
78
|
-
}) => string;
|
|
79
|
-
/** Human-readable formats */
|
|
80
|
-
type AmountAsHumanReadableArguments<T extends number | string | bigint> = {
|
|
81
|
-
amount: T;
|
|
82
|
-
desiredDecimals?: number;
|
|
83
|
-
minDecimals?: number;
|
|
84
|
-
decimals?: number;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Helpers for setting correct arguments and getting unified human-readable
|
|
88
|
-
* formats across the app with _toHumanReadableFormat functions.
|
|
89
|
-
*/
|
|
90
|
-
export declare const amountAsUSD: <T extends number | string | bigint>(args: AmountAsHumanReadableArguments<T>) => AmountAsHumanReadableArguments<T>;
|
|
91
|
-
export declare const amountAsToken: <T extends number | string | bigint>(args: AmountAsHumanReadableArguments<T>) => AmountAsHumanReadableArguments<T>;
|
|
92
|
-
export declare const amountAsMusd: <T extends number | string | bigint>(args: AmountAsHumanReadableArguments<T>) => AmountAsHumanReadableArguments<T>;
|
|
93
|
-
export declare const amountAsMats: <T extends number | string | bigint>(args: AmountAsHumanReadableArguments<T>) => AmountAsHumanReadableArguments<T>;
|
|
94
|
-
/**
|
|
95
|
-
* Converts a floating-point number to a human-readable format - with thousands
|
|
96
|
-
* separators and specified decimal places.
|
|
97
|
-
* @param args The arguments for the conversion.
|
|
98
|
-
* - amount: required, the floating-point number to convert.
|
|
99
|
-
* - desiredDecimals: optional, the desired number of decimal places for the output.
|
|
100
|
-
* - minDecimals: optional, the minimum number of decimal places.
|
|
101
|
-
* @returns The human-readable format of the floating-point number.
|
|
102
|
-
*/
|
|
103
|
-
export declare const floatToHumanReadableFormat: ({ amount, desiredDecimals, minDecimals, }: AmountAsHumanReadableArguments<number | string>) => string;
|
|
104
|
-
export declare const bigIntToHumanReadableFormat: ({ amount, decimals, desiredDecimals, minDecimals, }: AmountAsHumanReadableArguments<bigint>) => string;
|
|
105
|
-
export {};
|
|
106
|
-
//# sourceMappingURL=number2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number2.d.ts","sourceRoot":"","sources":["../../../src/utils/number2.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,oBAAoB,QAAsC,CAAA;AAuFvE,+CAA+C;AA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