@aave/react 4.0.0-next.47 → 4.0.0-next.48
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/chunk-IHI6MHZW.js +2 -0
- package/dist/chunk-IHI6MHZW.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{misc-rpxVotZV.d.cts → misc-CLtLR-vZ.d.cts} +51 -4
- package/dist/{misc-BqyLi2XD.d.ts → misc-CfqYr0kO.d.ts} +51 -4
- package/dist/privy.js +1 -1
- package/dist/viem/index.cjs +1 -1
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +1 -1
- package/dist/viem/index.d.ts +1 -1
- package/dist/viem/index.js +1 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-WQZMMTVR.js +0 -2
- package/dist/chunk-WQZMMTVR.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'./chunk-4NA4FB6K.js';import {a}from'./chunk-4LHXPD6N.js';import {chain,exchangeRate}from'@aave/client/actions';import {ChainsFilter,ChainQuery,ChainsQuery,ExchangeRateQuery}from'@aave/graphql';import {UnexpectedError}from'@aave/client';import {ok,invariant}from'@aave/types';import {useState,useMemo,useEffect}from'react';import {createRequest,useQuery}from'urql';var n={Loading:e=>({data:void 0,error:void 0,loading:true,paused:false,reloading:false,metadata:e}),Success:(e,a,t=false)=>({data:e,error:void 0,loading:false,paused:false,reloading:t,metadata:a}),Failure:(e,a,t=false)=>({data:void 0,error:e,loading:false,paused:false,reloading:t,metadata:a}),Paused:(e,a,t)=>({data:e,error:a,loading:false,paused:true,reloading:false,metadata:t})};function y({document:e,variables:a,suspense:t,pause:s,selector:S=ok,pollInterval:b=0,batch:h=true}){let[u,E]=useState({operationKey:0,resultOperationKey:void 0}),[m,Q]=useState(true),P=useMemo(()=>createRequest(e,a).key,[e,a]),[{fetching:o,data:l,error:d,stale:R},A]=useQuery({query:e,variables:a,pause:s,context:useMemo(()=>({batch:h,suspense:t}),[h,t])});if(useEffect(()=>{E(r=>({...r,operationKey:P}));},[P]),useEffect(()=>{s||o||Q(false);},[o,s]),useEffect(()=>{s||o||E(r=>({...r,resultOperationKey:l&&!R?r.operationKey:r.resultOperationKey}));},[s,o,l,R]),useEffect(()=>{if(b<=0||o||s)return;let r=setTimeout(()=>{A({requestPolicy:"network-only",batch:false});},b);return ()=>clearTimeout(r)},[o,A,b,s]),s){let r=d?UnexpectedError.from(d):void 0;if(!l)return n.Paused(void 0,r,u);let x=S(l.value);return x.isErr()?n.Paused(void 0,x.error,u):n.Paused(x.value,r,u)}if(!t&&m)return n.Loading(u);let f=R||!m&&o;if(d){let r=UnexpectedError.from(d);if(t)throw r;return n.Failure(r,u,f)}invariant(l,"No data returned");let i=S(l.value);if(i.isErr()){if(t)throw i.error;return n.Failure(i.error,u,f)}return n.Success(i.value,u,f)}function Z({suspense:e=false,pause:a=false,...t}){return y({document:ChainQuery,variables:{request:t},suspense:e,pause:a})}function _(){let e=b();return a(a=>chain(e,a,{batch:false,requestPolicy:"cache-first"}),[e])}function $({suspense:e=false,pause:a=false,...t}={query:{filter:ChainsFilter.ALL}}){return y({document:ChainsQuery,variables:{request:t},suspense:e,pause:a})}function ee(){let e=b();return a(a=>exchangeRate(e,a,{requestPolicy:"network-only"}),[e])}function ae({suspense:e=false,pause:a=false,...t}){let s=b();return y({document:ExchangeRateQuery,variables:{request:t},suspense:e,pause:a,pollInterval:t.at?0:s.context.environment.exchangeRateInterval})}export{n as a,y as b,Z as c,_ as d,$ as e,ee as f,ae as g};//# sourceMappingURL=chunk-IHI6MHZW.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-IHI6MHZW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/results.ts","../src/helpers/reads.ts","../src/misc.ts"],"names":["ReadResult","metadata","data","reloading","error","useSuspendableQuery","document","variables","suspense","pause","selector","ok","pollInterval","batch","setMetadata","useState","loading","setLoading","operationId","useMemo","createRequest","fetching","stale","executeQuery","useQuery","useEffect","current","timerId","unexpectedError","UnexpectedError","selected","unexpected","invariant","useChain","request","ChainQuery","useChainAction","client","useAaveClient","useAsyncTask","fetchChain","useChains","ChainsFilter","ChainsQuery","useExchangeRateAction","exchangeRate","useExchangeRate","ExchangeRateQuery"],"mappings":"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","file":"chunk-IHI6MHZW.js","sourcesContent":["import type { UnexpectedError } from '@aave/client';\n\n/**\n * @internal\n */\nexport type QueryMetadata = {\n operationKey: number;\n resultOperationKey: number | undefined;\n};\n\n/**\n * A read hook result.\n *\n * It's a discriminated union of the possible results of a read operation:\n * - Rely on the `loading` value to determine if the `data` or `error` can be evaluated.\n * - If `error` is `undefined`, then `data` value will be available.\n */\nexport type ReadResult<T, E = UnexpectedError> =\n | {\n data: undefined;\n error: undefined;\n loading: true;\n reloading: false;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n data: T;\n error: undefined;\n loading: false;\n reloading: boolean;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n data: undefined;\n error: E;\n loading: false;\n reloading: boolean;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n };\n\n/**\n * A read hook result that supports pausing.\n */\nexport type PausableReadResult<T, E = UnexpectedError> =\n | {\n data: T | undefined;\n error: E | undefined;\n loading: false;\n paused: true;\n reloading: false;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n data: undefined;\n error: undefined;\n loading: true;\n paused: false;\n reloading: false;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n data: T;\n error: undefined;\n loading: false;\n paused: false;\n reloading: boolean;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n data: undefined;\n error: E;\n loading: false;\n paused: false;\n reloading: boolean;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n };\n\n/**\n * @internal\n */\nexport const ReadResult = {\n Loading: <T, E = UnexpectedError>(\n metadata: QueryMetadata,\n ): PausableReadResult<T, E> => ({\n data: undefined,\n error: undefined,\n loading: true,\n paused: false,\n reloading: false,\n metadata,\n }),\n Success: <T, E = UnexpectedError>(\n data: T,\n metadata: QueryMetadata,\n reloading = false,\n ): PausableReadResult<T, E> => ({\n data,\n error: undefined,\n loading: false,\n paused: false,\n reloading,\n metadata,\n }),\n Failure: <T, E = UnexpectedError>(\n error: E,\n metadata: QueryMetadata,\n reloading = false,\n ): PausableReadResult<T, E> => ({\n data: undefined,\n error,\n loading: false,\n paused: false,\n reloading,\n metadata,\n }),\n Paused: <T, E = UnexpectedError>(\n data: T | undefined,\n error: E | undefined,\n metadata: QueryMetadata,\n ): PausableReadResult<T, E> => ({\n data,\n error,\n loading: false,\n paused: true,\n reloading: false,\n metadata,\n }),\n};\n\n/**\n * A read hook result that supports React Suspense.\n */\nexport type SuspenseResult<T> = {\n data: T;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n};\n\n/**\n * A read hook result that supports React Suspense and can be paused.\n */\nexport type PausableSuspenseResult<T> =\n | {\n paused: true;\n data: undefined;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n }\n | {\n paused: false;\n data: T;\n /**\n * @internal\n */\n metadata: QueryMetadata;\n };\n\nexport type SuspendableResult<T, E = UnexpectedError> =\n | ReadResult<T, E>\n | SuspenseResult<T>\n | PausableReadResult<T, E>\n | PausableSuspenseResult<T>;\n","import { type StandardData, UnexpectedError } from '@aave/client';\nimport {\n type AnyVariables,\n invariant,\n type NullishDeep,\n ok,\n type Prettify,\n type Result,\n} from '@aave/types';\nimport { useEffect, useMemo, useState } from 'react';\nimport { createRequest, type TypedDocumentNode, useQuery } from 'urql';\nimport {\n type PausableReadResult,\n type PausableSuspenseResult,\n type QueryMetadata,\n ReadResult,\n type SuspendableResult,\n type SuspenseResult,\n} from './results';\n\nexport type Selector<ResponseValue, SelectorData, SelectorError> = (\n data: ResponseValue,\n) => Result<SelectorData, SelectorError>;\n\nexport type Pausable<T, WhenPaused = NullishDeep<T>> = Prettify<\n WhenPaused & {\n /**\n * Prevents the hook from automatically executing GraphQL query operations.\n *\n * @experimental This is an experimental feature and may change in the future.\n *\n * @remarks\n * `pause` may be set to `true` to stop the query operation from executing\n * automatically. The hook will stop receiving updates and won't execute the query\n * operation until it's set to `false`.\n */\n pause: boolean;\n }\n>;\n\nexport type Suspendable = { suspense: true };\n\n/**\n * @internal\n */\nexport type UseSuspendableQueryArgs<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables extends AnyVariables,\n Suspense extends boolean,\n Pause extends boolean = never,\n> = {\n document: TypedDocumentNode<StandardData<ResponseValue>, Variables>;\n variables?: Pause extends boolean ? NullishDeep<Variables> : Variables;\n suspense: Suspense;\n selector?: Selector<ResponseValue, SelectorData, SelectorError>;\n pollInterval?: number;\n batch?: boolean;\n pause?: Pause;\n};\n\n/**\n * @internal\n */\nexport function useSuspendableQuery<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables extends AnyVariables,\n Pausable extends boolean = never,\n>({\n document,\n variables,\n suspense,\n pause,\n}: UseSuspendableQueryArgs<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables,\n false,\n Pausable\n>):\n | ReadResult<SelectorData, SelectorError | UnexpectedError>\n | PausableReadResult<SelectorData, SelectorError | UnexpectedError>;\n/**\n * @internal\n */\nexport function useSuspendableQuery<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables extends AnyVariables,\n Pausable extends boolean = never,\n>({\n document,\n variables,\n suspense,\n pause,\n}: UseSuspendableQueryArgs<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables,\n true,\n Pausable\n>): SuspenseResult<SelectorData> | PausableSuspenseResult<SelectorData>;\n/**\n * @internal\n */\nexport function useSuspendableQuery<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables extends AnyVariables,\n Pausable extends boolean = never,\n>({\n document,\n variables,\n suspense,\n pause,\n}: UseSuspendableQueryArgs<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables,\n boolean,\n Pausable\n>): SuspendableResult<SelectorData, SelectorError | UnexpectedError>;\n/**\n * Implementation.\n */\nexport function useSuspendableQuery<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables extends AnyVariables,\n>({\n document,\n variables,\n suspense,\n pause,\n selector = ok as Selector<ResponseValue, SelectorData, SelectorError>,\n pollInterval = 0,\n batch = true,\n}: UseSuspendableQueryArgs<\n ResponseValue,\n SelectorData,\n SelectorError,\n Variables,\n boolean,\n boolean\n>): SuspendableResult<SelectorData, SelectorError | UnexpectedError> {\n const [metadata, setMetadata] = useState<QueryMetadata>({\n operationKey: 0,\n resultOperationKey: undefined,\n });\n const [loading, setLoading] = useState(true);\n const operationId = useMemo(\n () => createRequest(document, variables as Variables).key,\n [document, variables],\n );\n const [{ fetching, data, error, stale }, executeQuery] = useQuery({\n query: document,\n variables: variables as Variables,\n pause,\n context: useMemo(\n () => ({\n batch,\n suspense,\n }),\n [batch, suspense],\n ),\n });\n\n useEffect(() => {\n setMetadata((current) => ({\n ...current,\n operationKey: operationId,\n }));\n }, [operationId]);\n\n useEffect(() => {\n if (pause) return;\n\n if (!fetching) {\n setLoading(false);\n }\n }, [fetching, pause]);\n\n useEffect(() => {\n if (pause || fetching) {\n return;\n }\n\n setMetadata((current) => ({\n ...current,\n resultOperationKey:\n data && !stale ? current.operationKey : current.resultOperationKey,\n }));\n }, [pause, fetching, data, stale]);\n\n useEffect(() => {\n if (pollInterval <= 0 || fetching || pause) return undefined;\n\n const timerId = setTimeout(() => {\n executeQuery({\n requestPolicy: 'network-only',\n batch: false, // never batch, run now!\n });\n }, pollInterval);\n\n return () => clearTimeout(timerId);\n }, [fetching, executeQuery, pollInterval, pause]);\n\n if (pause) {\n const unexpectedError = error ? UnexpectedError.from(error) : undefined;\n\n if (!data) {\n return ReadResult.Paused<SelectorData, SelectorError | UnexpectedError>(\n undefined,\n unexpectedError,\n metadata,\n );\n }\n\n const selected = selector(data.value);\n\n if (selected.isErr()) {\n return ReadResult.Paused<SelectorData, SelectorError>(\n undefined,\n selected.error,\n metadata,\n );\n }\n\n return ReadResult.Paused<SelectorData, UnexpectedError>(\n selected.value,\n unexpectedError,\n metadata,\n );\n }\n\n if (!suspense && loading) {\n return ReadResult.Loading(metadata);\n }\n\n // stale indicates that the useQuery is fetching new data because the variables changed\n // !loading && fetching indicates that a re-fetch is happening as consequence of calling executeQuery (e.g., polling)\n const reloading = stale || (!loading && fetching);\n\n if (error) {\n const unexpected = UnexpectedError.from(error);\n if (suspense) {\n throw unexpected;\n }\n\n return ReadResult.Failure(unexpected, metadata, reloading);\n }\n\n invariant(data, 'No data returned');\n\n const selected = selector(data.value);\n\n if (selected.isErr()) {\n if (suspense) {\n throw selected.error;\n }\n return ReadResult.Failure(selected.error, metadata, reloading);\n }\n\n return ReadResult.Success(selected.value, metadata, reloading);\n}\n","import type { CurrencyQueryOptions } from '@aave/client';\nimport { exchangeRate, chain as fetchChain } from '@aave/client/actions';\nimport type { UnexpectedError } from '@aave/core';\nimport type { Chain, ExchangeAmount, ExchangeRateRequest } from '@aave/graphql';\nimport {\n type ActivityItem,\n ChainQuery,\n type ChainRequest,\n ChainsFilter,\n ChainsQuery,\n type ChainsRequest,\n ExchangeRateQuery,\n type NativeAmount,\n type PreviewAction,\n} from '@aave/graphql';\nimport type { NullishDeep, Prettify } from '@aave/types';\nimport { useAaveClient } from './context';\nimport {\n type Pausable,\n type PausableReadResult,\n type PausableSuspenseResult,\n type ReadResult,\n type Suspendable,\n type SuspendableResult,\n type SuspenseResult,\n useSuspendableQuery,\n} from './helpers';\nimport { type UseAsyncTask, useAsyncTask } from './helpers/tasks';\n\nexport type UseChainArgs = ChainRequest;\n\n/**\n * Fetch a specific chain by chain ID.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useChain({\n * chainId: chainId(1),\n * suspense: true,\n * });\n * // data will be Chain | null\n * ```\n */\nexport function useChain(\n args: UseChainArgs & Suspendable,\n): SuspenseResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useChain({\n * chainId: chainId(1),\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useChain(\n args: Pausable<UseChainArgs> & Suspendable,\n): PausableSuspenseResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * ```tsx\n * const { data, error, loading } = useChain({\n * chainId: chainId(1),\n * });\n * // data will be Chain | null\n * ```\n */\nexport function useChain(args: UseChainArgs): ReadResult<Chain | null>;\n/**\n * Fetch a specific chain by chain ID.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useChain({\n * chainId: chainId(1),\n * pause: true,\n * });\n * ```\n */\nexport function useChain(\n args: Pausable<UseChainArgs>,\n): PausableReadResult<Chain | null>;\n\nexport function useChain({\n suspense = false,\n pause = false,\n ...request\n}: NullishDeep<UseChainArgs> & {\n suspense?: boolean;\n pause?: boolean;\n}): SuspendableResult<Chain | null, UnexpectedError> {\n return useSuspendableQuery({\n document: ChainQuery,\n variables: {\n request,\n },\n suspense,\n pause,\n });\n}\n\n/**\n * Low-level hook to execute a {@link chain} action directly.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n * @remarks\n * This hook **does not** actively watch for updated data on the chain.\n * Use this hook to retrieve data on demand as part of a larger workflow\n * (e.g., in an event handler in order to move to the next step).\n *\n * ```ts\n * const [execute, { called, data, error, loading }] = useChainAction();\n *\n * // …\n *\n * const result = await execute({\n * chainId: chainId(1),\n * });\n *\n * if (result.isOk()) {\n * console.log(result.value); // Chain | null\n * } else {\n * console.error(result.error);\n * }\n * ```\n */\nexport function useChainAction(): UseAsyncTask<\n ChainRequest,\n Chain | null,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: ChainRequest) =>\n fetchChain(client, request, {\n batch: false,\n requestPolicy: 'cache-first',\n }),\n [client],\n );\n}\n\nexport type UseChainsArgs = ChainsRequest;\n/**\n * Fetches the list of supported chains.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * suspense: true,\n * });\n * ```\n */\nexport function useChains(\n args: UseChainsArgs & Suspendable,\n): SuspenseResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useChains(\n args: Pausable<UseChainsArgs> & Suspendable,\n): PausableSuspenseResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * ```tsx\n * const { data, error, loading } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * });\n * ```\n */\nexport function useChains(args?: UseChainsArgs): ReadResult<Chain[]>;\n/**\n * Fetches the list of supported chains.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useChains({\n * query: { filter: ChainsFilter.ALL },\n * pause: true,\n * });\n * ```\n */\nexport function useChains(\n args?: Pausable<UseChainsArgs>,\n): PausableReadResult<Chain[]>;\n\nexport function useChains(\n {\n suspense = false,\n pause = false,\n ...request\n }: NullishDeep<UseChainsArgs> & {\n suspense?: boolean;\n pause?: boolean;\n } = { query: { filter: ChainsFilter.ALL } },\n): SuspendableResult<Chain[], UnexpectedError> {\n return useSuspendableQuery({\n document: ChainsQuery,\n variables: { request },\n suspense,\n pause,\n });\n}\n\n/**\n * Fetches exchange rates between tokens and fiat currencies.\n *\n * ```tsx\n * const [getExchangeRate, gettingRate] = useExchangeRateAction();\n *\n * const loading = gettingRate.loading;\n * const error = gettingRate.error;\n *\n * // …\n *\n * const result = await getExchangeRate({\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('Exchange rate:', result.value);\n * ```\n */\nexport function useExchangeRateAction(): UseAsyncTask<\n ExchangeRateRequest,\n ExchangeAmount,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: ExchangeRateRequest) =>\n exchangeRate(client, request, { requestPolicy: 'network-only' }),\n [client],\n );\n}\n\nexport type UseExchangeRateArgs = ExchangeRateRequest;\n\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * suspense: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: UseExchangeRateArgs & Suspendable,\n): SuspenseResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * suspense: true,\n * pause: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: Pausable<UseExchangeRateArgs> & Suspendable,\n): PausableSuspenseResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * ```tsx\n * const { data, error, loading } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * });\n *\n * <Component value={somewhere} fxRate={data} />\n * ```\n */\nexport function useExchangeRate(\n args: UseExchangeRateArgs,\n): ReadResult<ExchangeAmount>;\n/**\n * Fetches exchange rates between tokens and fiat currencies with automatic polling.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useExchangeRate({\n * from: {\n * erc20: {\n * chainId: chainId(1),\n * address: evmAddress('0xA0b86a33E6...')\n * }\n * },\n * to: Currency.Usd,\n * pause: true,\n * });\n * ```\n */\nexport function useExchangeRate(\n args: Pausable<UseExchangeRateArgs>,\n): PausableReadResult<ExchangeAmount>;\n\nexport function useExchangeRate({\n suspense = false,\n pause = false,\n ...request\n}: NullishDeep<UseExchangeRateArgs> & {\n suspense?: boolean;\n pause?: boolean;\n}): SuspendableResult<ExchangeAmount, UnexpectedError> {\n const client = useAaveClient();\n\n return useSuspendableQuery({\n document: ExchangeRateQuery,\n variables: { request },\n suspense,\n pause,\n pollInterval: request.at\n ? 0\n : client.context.environment.exchangeRateInterval,\n });\n}\n\nexport type UseNetworkFeeRequestQuery =\n | {\n activity: ActivityItem;\n }\n | {\n estimate: PreviewAction;\n };\n\nexport type UseNetworkFeeArgs = Prettify<\n {\n query: UseNetworkFeeRequestQuery;\n } & CurrencyQueryOptions\n>;\n\ntype PausableUseNetworkFeeArgs = Partial<\n {\n query: Partial<UseNetworkFeeRequestQuery>;\n } & CurrencyQueryOptions\n>;\n\n/**\n * Fetch the network fee for an ActivityItem.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n */\nexport type UseNetworkFee<T extends NativeAmount = NativeAmount> =\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * This signature supports React Suspense:\n *\n * ```tsx\n * const { data } = useNetworkFee({\n * query: { activity },\n * suspense: true,\n * });\n *\n * data: NativeAmount\n * ```\n */\n ((args: UseNetworkFeeArgs & Suspendable) => SuspenseResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * Pausable suspense mode.\n *\n * ```tsx\n * const { data, paused } = useNetworkFee({\n * query: { activity },\n * suspense: true,\n * pause: true,\n * });\n *\n * data: NativeAmount | undefined\n * ```\n */\n ((\n args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs> &\n Suspendable,\n ) => PausableSuspenseResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * ```tsx\n * const { data, error, loading } = useNetworkFee({\n * query: { activity },\n * });\n * ```\n */\n ((args: UseNetworkFeeArgs) => ReadResult<T>) &\n /**\n * Fetches the network fee for a past ActivityItem.\n *\n * Pausable loading state mode.\n *\n * ```tsx\n * const { data, error, loading, paused } = useNetworkFee({\n * query: { activity },\n * pause: true,\n * });\n *\n * data: NativeAmount | undefined\n * ```\n */\n ((\n args: Pausable<UseNetworkFeeArgs, PausableUseNetworkFeeArgs>,\n ) => PausableReadResult<T>);\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var client=require('@aave/client'),j=require('react'),types=require('@aave/types'),urql=require('urql'),actions=require('@aave/client/actions'),graphql=require('@aave/graphql'),core=require('@aave/core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var j__default=/*#__PURE__*/_interopDefault(j);var re=j__default.default.createContext(null);function se({children:e,client:r}){return j__default.default.createElement(re.Provider,{value:r},j__default.default.createElement(urql.Provider,{value:r.urql},e))}function o(){let e=j.useContext(re);return types.invariant(e,"Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>"),e}function ca({children:e,client:r}){return j__default.default.createElement(se,{client:r},e)}function lr(e){if("userSpoke"in e)return e.userSpoke.user;if("userToken"in e)return e.userToken.user;if("userChains"in e)return e.userChains.user;if("userHub"in e)return e.userHub.user;let{user:r}=graphql.decodeUserPositionId(e.userPositionId);return r}function cr(e){if("userSpoke"in e)return e.userSpoke.user;if("userToken"in e)return e.userToken.user;if("userChains"in e)return e.userChains.user;if("userHub"in e)return e.userHub.user;let{user:r}=graphql.decodeUserPositionId(e.userPositionId);return r}function k(e,r){return e.refreshQueryWhere(graphql.UserBalancesQuery,s=>s.request.user===r)}function q(e,r){return e.refreshQueryWhere(graphql.UserSuppliesQuery,s=>lr(s.request.query)===r)}function B(e,r){return e.refreshQueryWhere(graphql.UserBorrowsQuery,s=>cr(s.request.query)===r)}function G(e,r,s){let t=a=>a.spoke.chain.chainId===s.chainId&&a.spoke.address===s.address&&a.user===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>n.some(t)),e.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n!==null&&t(n))])}function $(e,r){let s=t=>r.includes(t.id);return types.ResultAsync.combine([e.refreshQueryWhere(graphql.ReserveQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.ReservesQuery,(t,a)=>a.some(s))])}function K(e,r,s){return e.refreshQueryWhere(graphql.UserSummaryQuery,t=>t.request.user===r&&(graphql.isSpokeInputVariant(t.request.filter)?t.request.filter.spoke.chainId===s.chainId&&t.request.filter.spoke.address===s.address:graphql.isChainIdsVariant(t.request.filter)?t.request.filter.chainIds.some(a=>a===s.chainId):false))}function z(e,r){let s=t=>t.chain.chainId===r.chainId&&t.address===r.address;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.SpokeQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.SpokesQuery,(t,a)=>a.some(s))])}function J(e,r){let s=t=>t.chain.chainId===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.HubQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.HubsQuery,(t,a)=>a.some(s))])}function N(e,r){return e.refreshQueryWhere(graphql.SpokePositionManagersQuery,s=>s.request.spoke===r)}function oe(e,r){return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(s,t)=>t.some(a=>a.id===r)),e.refreshQueryWhere(graphql.UserPositionQuery,(s,t)=>t?.id===r)])}function T(e,r){let{chainId:s,spoke:t}=graphql.decodeReserveId(r.reserve),a={chainId:s,address:t};return types.ResultAsync.combine([G(e,r.sender,a),K(e,r.sender,a),$(e,[r.reserve]),z(e,a),k(e,r.sender),q(e,r.sender),B(e,r.sender),J(e,s)])}function ue(e,r){return k(e,r)}function ie(e,r){return types.ResultAsync.combine([q(e,r),k(e,r)])}function pe(e,r){return types.ResultAsync.combine([B(e,r),k(e,r)])}function le(e,r){return types.ResultAsync.combine([q(e,r),B(e,r),k(e,r)])}function ce(e,r){return types.ResultAsync.combine([q(e,r),k(e,r)])}var x={Loading:()=>({data:void 0,error:void 0,loading:true,paused:false,reloading:false}),Success:(e,r=false)=>({data:e,error:void 0,loading:false,paused:false,reloading:r}),Failure:(e,r=false)=>({data:void 0,error:e,loading:false,paused:false,reloading:r}),Paused:(e,r)=>({data:e,error:r,loading:false,paused:true,reloading:false})};function i({document:e,variables:r,suspense:s,pause:t,selector:a=types.ok,pollInterval:n=0,batch:l=true}){let[d,f]=j.useState(true),[{fetching:R,data:A,error:b,stale:L},ee]=urql.useQuery({query:e,variables:r,pause:t,context:j.useMemo(()=>({batch:l,suspense:s}),[l,s])});if(j.useEffect(()=>{t||R||f(false);},[R,t]),j.useEffect(()=>{if(n<=0||R||t)return;let v=setTimeout(()=>{ee({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(v)},[R,ee,n,t]),t){let v=b?client.UnexpectedError.from(b):void 0;if(!A)return x.Paused(void 0,v);let Y=a(A.value);return Y.isErr()?x.Paused(void 0,Y.error):x.Paused(Y.value,v)}if(!s&&d)return x.Loading();let M=L||!d&&R;if(b){let v=client.UnexpectedError.from(b);if(s)throw v;return x.Failure(v,M)}types.invariant(A,"No data returned");let D=a(A.value);if(D.isErr()){if(s)throw D.error;return x.Failure(D.error,M)}return x.Success(D.value,M)}var X={Idle:()=>({called:false,loading:false,data:void 0,error:void 0}),Loading:e=>({called:true,loading:true,data:e,error:void 0}),Success:e=>({called:true,loading:false,data:e,error:void 0}),Failed:e=>({called:true,loading:false,data:void 0,error:e})};function u(e,r){let[s,t]=j.useState(X.Idle()),a=j.useRef(false),n=j.useRef(true);j.useEffect(()=>()=>{n.current=false;},[]);let l=j.useCallback(e,r);return [j.useCallback(f=>{types.invariant(n.current,"Cannot execute a task on an unmounted component."),types.invariant(!a.current,"Cannot execute a task while another is in progress."),a.current=true;let R;t(A=>(R=A,{called:true,loading:true,data:A.data,error:void 0}));try{let A=l(f);return A.match(b=>{a.current=!1,t(X.Success(b));},b=>{a.current=!1,t(X.Failed(b));}),A}catch(A){throw a.current=false,R&&t(R),A}},[l]),s]}var p=e=>core.CancelError.from(e).asResultAsync(),y=class e{constructor(r){this.wait=r;}static isInstanceOf(r){return r instanceof e}static tryFrom(r){return e.isInstanceOf(r)?types.okAsync(r):core.UnexpectedError.from(r).asResultAsync()}};function U(e){return types.isSignature(e)?types.okAsync(e):core.UnexpectedError.from(`Expected Signature, but got ${String(e)}`).asResultAsync()}function Ia({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Ba({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Wa({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubAssetsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Oa({suspense:e=false,pause:r=false,...s}){return i({document:graphql.HubSummaryHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Da(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.hubs(r,s,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function Ya({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ChainQuery,variables:{request:s},suspense:e,pause:r})}function ja(){let e=o();return u(r=>actions.chain(e,r,{batch:false,requestPolicy:"cache-first"}),[e])}function Ga({suspense:e=false,pause:r=false,...s}={query:{filter:graphql.ChainsFilter.ALL}}){return i({document:graphql.ChainsQuery,variables:{request:s},suspense:e,pause:r})}function $a(){let e=o();return u(r=>actions.exchangeRate(e,r,{requestPolicy:"network-only"}),[e])}function Ka({suspense:e=false,pause:r=false,...s}){let t=o();return i({document:graphql.ExchangeRateQuery,variables:{request:s},suspense:e,pause:r,pollInterval:s.at?0:t.context.environment.exchangeRateInterval})}function en({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function rn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.AssetPriceHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function sn({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetSupplyHistoryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r,batch:false})}function tn({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetBorrowHistoryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r,batch:false})}function an({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ProtocolHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function yn({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ReserveQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function dn(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.reserve(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function Sn({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ReservesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function mn(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.reserves(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function fn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.BorrowApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Rn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SupplyApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function bn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserClaimableRewardsQuery,variables:{request:s},suspense:e,pause:r})}function Tn(){let e=o();return u(r=>actions.userClaimableRewards(e,r,{requestPolicy:"cache-first"}),[e])}function vn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeQuery,variables:{request:s},suspense:e,pause:r})}function Qn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokesQuery,variables:{request:s},suspense:e,pause:r})}function kn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokePositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function qn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeUserPositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function m(e){switch(e.__typename){case "PositionSwapByIntentApprovalsRequired":return types.ok(e.quote);case "InsufficientLiquidityError":return types.err(core.ValidationError.fromGqlNode(e));default:return types.err(core.UnexpectedError.upgradeRequired(`Unsupported position swap quote result: ${e.__typename}`))}}function V(e){return e.__typename==="SwapFulfilled"||e.__typename==="SwapCancelled"||e.__typename==="SwapExpired"}function E(e){return {with:r=>e.approvals.reduce((s,t)=>s.andThen(a=>r(t,{cancel:p}).map(n=>{switch(t.__typename){case "PositionSwapAdapterContractApproval":a.adapterContractSignature=types.isSignature(n)?n:null;break;case "PositionSwapPositionManagerApproval":a.positionManagerSignature=types.isSignature(n)?n:null;break}return a})),types.okAsync({quoteId:e.quote.quoteId,adapterContractSignature:null,positionManagerSignature:null}))}}function h(e,r){return actions.swap(e,{intent:r}).andThen(s=>{switch(s.__typename){case "SwapReceipt":return types.okAsync(s);default:return core.UnexpectedError.from(s).asResultAsync()}})}function es(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.borrowSwapQuote(r,t,{currency:s}).andThen(a=>E(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(U).andThen(l=>h(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function be(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function ss({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:be(t,graphql.QuoteAccuracy.Fast),currency:s},selector:m,suspense:e,pause:r,batch:false}),l=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:be(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:m,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data?l:n}function ts(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.borrowSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(m),[r,e.currency])}function Ee(e){return {__typename:"SwapCancelledResult",swapId:e.swapId,createdAt:e.createdAt,cancelledAt:e.cancelledAt,explorerUrl:e.explorerUrl}}var W=class extends types.ResultAwareError{name="CannotCancelSwapError"};function us(e){let r=o();return u(s=>actions.swapStatus(r,{id:s.id}).andThen(t=>{if(t===null)return core.UnexpectedError.from("Swap not found").asResultAsync();switch(t.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(r,s).andThen(a=>e(a.data,{cancel:p})).andThen(U).andThen(a=>actions.cancelSwap(r,{intent:{id:s.id,signature:a}})).andThen(a=>a.__typename==="SwapCancelledResult"?types.okAsync(a):e(a,{cancel:p}).andThen(y.tryFrom).andThen(n=>n.wait()).andThen(()=>actions.swapStatus(r,{id:s.id})).andThen(n=>n?.__typename==="SwapCancelled"?types.okAsync(Ee(n)):new W("Failed to cancel swap").asResultAsync()));case "SwapCancelled":return types.okAsync(Ee(t));case "SwapExpired":return new W("Swap cannot longer be cancelled").asResultAsync();default:return core.UnexpectedError.upgradeRequired(`Unsupported swap status: ${t.__typename}`).asResultAsync()}}),[r,e])}function ls(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.repayWithSupplyQuote(r,t,{currency:s}).andThen(a=>E(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(U).andThen(l=>h(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Qe(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function ys({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Qe(t,graphql.QuoteAccuracy.Fast),currency:s},selector:m,suspense:e,pause:r,batch:false}),l=i({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Qe(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:m,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data?l:n}function ds(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.repayWithSupplyQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(m),[r,e.currency])}function fs(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.supplySwapQuote(r,t,{currency:s}).andThen(a=>E(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(U).andThen(l=>h(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Ce(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function As({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.SupplySwapQuoteQuery,variables:{request:Ce(t,graphql.QuoteAccuracy.Fast),currency:s},selector:m,suspense:e,pause:r,batch:false}),l=i({document:graphql.SupplySwapQuoteQuery,variables:{request:Ce(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:m,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data?l:n}function Us(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.supplySwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(m),[r,e.currency])}function gs({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SwappableTokensQuery,variables:{request:s},suspense:e,pause:r})}function xs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,d]=j.useState(false),f=i({document:graphql.SwapStatusQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval});return j.useEffect(()=>{f.data&&V(f.data)&&d(true);},[f.data]),f}function Cs(e){let r=o(),s=j.useCallback(t=>actions.swap(r,t).andThen(a=>{switch(a.__typename){case "SwapTransactionRequest":return e(a,{cancel:p}).andThen(y.tryFrom).andThen(n=>n.wait()).andThen(()=>types.okAsync(a.orderReceipt));case "SwapReceipt":return types.okAsync(a)}}),[r,e]);return u(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.tokenSwapQuote(r,a,{currency:t}).andThen(n=>{switch(n.__typename){case "SwapByTransaction":return s({transaction:{quoteId:n.quote.quoteId}});case "SwapByIntent":return actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId}).andThen(l=>e(l.data,{cancel:p}).andThen(U).andThen(d=>s({intent:{quoteId:l.newQuoteId,signature:d}})));case "SwapByIntentWithApprovalRequired":if(client.supportsPermit(n)){let l=n.approvals[0];return e(l,{cancel:p}).andThen(d=>types.isSignature(d)?actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId,permitSig:{deadline:l.bySignature.message.deadline,value:d}}):y.isInstanceOf(d)?d.wait().andThen(()=>actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId})):core.UnexpectedError.from(d).asResultAsync()).andThen(d=>e(d.data,{cancel:p}).andThen(U).andThen(f=>s({intent:{quoteId:d.newQuoteId,signature:f}})))}return n.approvals.reduce((l,d)=>l.andThen(()=>e({...d,bySignature:null},{cancel:p}).andThen(y.tryFrom).andThen(f=>f.wait())),types.okAsync(void 0)).andThen(()=>actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId})).andThen(l=>e(l.data,{cancel:p})).andThen(U).andThen(l=>s({intent:{quoteId:n.quote.quoteId,signature:l}}));default:types.never(`Unsupported swap quote result: ${n.__typename}. To be removed from API soon.`);}}),[r,e,s])}function Z(e){switch(e.__typename){case "SwapByIntent":case "SwapByIntentWithApprovalRequired":case "SwapByTransaction":return types.ok(e.quote);case "InsufficientLiquidityError":return types.err(core.ValidationError.fromGqlNode(e));default:return types.err(core.UnexpectedError.upgradeRequired(`Unsupported swap quote result: ${e.__typename}`))}}function Oe(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function Os({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.TokenSwapQuoteQuery,variables:{request:Oe(t,graphql.QuoteAccuracy.Fast),currency:s},selector:Z,suspense:e,pause:r,batch:false}),l=i({document:graphql.TokenSwapQuoteQuery,variables:{request:Oe(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:Z,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data?l:n}function Ds(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.tokenSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(Z),[r,e.currency])}function Ls(e,r){let s=new Map(r.map(t=>[t.swapId,t.__typename]));return e.filter(t=>t.__typename==="SwapFulfilled"&&s.get(t.swapId)!=="SwapFulfilled")}function Ms({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,d]=j.useState(false),f=i({document:graphql.UserSwapsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval}),R=f.data?.items??[],A=j.useDeferredValue(R);return j.useEffect(()=>{if(R.length===0)return;R.every(V)&&d(true);for(let L of Ls(R,A))switch(L.operation.__typename){case "TokenSwap":a.user&&ue(n,a.user);break;case "BorrowSwap":a.user&&pe(n,a.user);break;case "RepayWithSupply":a.user&&le(n,a.user);break;case "SupplySwap":a.user&&ie(n,a.user);break;case "WithdrawSwap":a.user&&ce(n,a.user);break}},[R,A,n,a.user]),f}function Gs(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.withdrawSwapQuote(r,t,{currency:s}).andThen(a=>E(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(U).andThen(l=>h(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Ve(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function Ks({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ve(t,graphql.QuoteAccuracy.Fast),currency:s},selector:m,suspense:e,pause:r,batch:false}),l=i({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ve(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:m,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data?l:n}function zs(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.withdrawSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(m),[r,e.currency])}function Zs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ActivitiesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function et(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.activities(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function nt(e){let r=o();return u(s=>actions.borrow(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "PreContractActionRequired":return e(t,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t));case "Erc20ApprovalRequired":return client.UnexpectedError.from(t).asResultAsync()}}).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>T(r,s)),[r,e])}function it(e){let r=o();return u(s=>actions.claimRewards(r,s).andThen(t=>e(t,{cancel:p})).andThen(y.tryFrom).andThen(t=>t.wait()).map(t=>client.transactionReceipt(t.txHash)),[r,e])}function yt(e,r){return {deadline:r.message.deadline,value:e}}function H(e,r){return e.approvals.reduce((s,t)=>s.andThen(()=>r({...t,bySignature:null},{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait())),types.okAsync(void 0)).map(()=>e.originalTransaction)}function I(e,r,s){let t=e.approvals[0];return r(t,{cancel:p}).andThen(a=>types.isSignature(a)?s(yt(a,t.bySignature)).map(types.expectTypename("TransactionRequest")):a.wait().map(()=>e.originalTransaction))}function ft(e,r){return e}function Rt(e){let r=o();return u(s=>actions.liquidatePosition(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?I(t,e,a=>actions.liquidatePosition(r,ft(s))).andThen(a=>e(a,{cancel:p})):H(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(y.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction),[r,e])}function wt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.preview(r,s,{currency:e.currency,requestPolicy:"network-only"}),[r,e.currency])}function gt({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.PreviewQuery,variables:{request:t,currency:s},suspense:e,pause:r})}function bt(e){let r=o();return u(s=>actions.renounceSpokeUserPositionManager(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>N(r,s.spoke)),[r,e])}function ht(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function vt(e){let r=o();return u(s=>actions.repay(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?I(t,e,a=>actions.repay(r,ht(s,a))).andThen(a=>e(a,{cancel:p})):H(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(y.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>T(r,s)),[r,e])}function kt(e){let r=o();return u(s=>actions.setSpokeUserPositionManager(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>N(r,s.spoke)),[r,e])}function It(e){let r=o();return u(s=>{let t=s.changes.map(n=>n.reserve),a=t.map(n=>graphql.decodeReserveId(n));return actions.setUserSuppliesAsCollateral(r,s).andThen(n=>e(n,{cancel:p})).andThen(n=>n.wait()).andThen(r.waitForTransaction).andThrough(()=>types.ResultAsync.combine([q(r,s.sender),B(r,s.sender),...a.flatMap(({chainId:n,spoke:l})=>[G(r,s.sender,{chainId:n,address:l}),K(r,s.sender,{chainId:n,address:l}),z(r,{chainId:n,address:l})]),$(r,t),...a.map(({chainId:n})=>J(r,n))]))},[r,e])}function Dt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Nt(e){let r=o();return u(s=>actions.supply(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?I(t,e,a=>actions.supply(r,Dt(s,a))).andThen(a=>e(a,{cancel:p})):H(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(y.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>T(r,s)),[r,e])}function Vt(e){let r=o();return u(s=>actions.updateUserPositionConditions(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>oe(r,s.userPositionId)),[r,e])}function jt(e){let r=o();return u(s=>actions.withdraw(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "PreContractActionRequired":return e(t,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t));case "Erc20ApprovalRequired":return client.UnexpectedError.from(t).asResultAsync()}}).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>T(r,s)),[r,e])}function Up({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserSuppliesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function wp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userSupplies(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function gp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserBorrowsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Pp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userBorrows(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function bp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserSummaryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Tp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserPositionsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function xp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userPositions(r,s,{currency:e.currency,timeWindow:e.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function Ep({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserPositionQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function hp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.UserBalancesQuery,variables:{request:t,currency:s},suspense:e,pause:r})}function vp({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Qp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userBalances(r,s,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function kp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.UserSummaryHistoryQuery,variables:{request:t,currency:s},suspense:e,pause:r,batch:false})}exports.AaveProvider=ca;exports.CannotCancelSwapError=W;exports.useAaveClient=o;exports.useActivities=Zs;exports.useActivitiesAction=et;exports.useAsset=en;exports.useAssetBorrowHistory=tn;exports.useAssetPriceHistory=rn;exports.useAssetSupplyHistory=sn;exports.useBorrow=nt;exports.useBorrowApyHistory=fn;exports.useBorrowSwap=es;exports.useBorrowSwapQuote=ss;exports.useBorrowSwapQuoteAction=ts;exports.useCancelSwap=us;exports.useChain=Ya;exports.useChainAction=ja;exports.useChains=Ga;exports.useClaimRewards=it;exports.useExchangeRate=Ka;exports.useExchangeRateAction=$a;exports.useHub=Ia;exports.useHubAssets=Wa;exports.useHubSummaryHistory=Oa;exports.useHubs=Ba;exports.useHubsAction=Da;exports.useLiquidatePosition=Rt;exports.usePreview=gt;exports.usePreviewAction=wt;exports.useProtocolHistory=an;exports.useRenounceSpokeUserPositionManager=bt;exports.useRepay=vt;exports.useRepayWithSupply=ls;exports.useRepayWithSupplyQuote=ys;exports.useRepayWithSupplyQuoteAction=ds;exports.useReserve=yn;exports.useReserveAction=dn;exports.useReserves=Sn;exports.useReservesAction=mn;exports.useSetSpokeUserPositionManager=kt;exports.useSetUserSuppliesAsCollateral=It;exports.useSpoke=vn;exports.useSpokePositionManagers=kn;exports.useSpokeUserPositionManagers=qn;exports.useSpokes=Qn;exports.useSupply=Nt;exports.useSupplyApyHistory=Rn;exports.useSupplySwap=fs;exports.useSupplySwapQuote=As;exports.useSupplySwapQuoteAction=Us;exports.useSwapStatus=xs;exports.useSwappableTokens=gs;exports.useTokenSwap=Cs;exports.useTokenSwapQuote=Os;exports.useTokenSwapQuoteAction=Ds;exports.useUpdateUserPositionConditions=Vt;exports.useUserBalances=hp;exports.useUserBalancesAction=Qp;exports.useUserBorrows=gp;exports.useUserBorrowsAction=Pp;exports.useUserClaimableRewards=bn;exports.useUserClaimableRewardsAction=Tn;exports.useUserPosition=Ep;exports.useUserPositions=Tp;exports.useUserPositionsAction=xp;exports.useUserRiskPremiumBreakdown=vp;exports.useUserSummary=bp;exports.useUserSummaryHistory=kp;exports.useUserSupplies=Up;exports.useUserSuppliesAction=wp;exports.useUserSwaps=Ms;exports.useWithdraw=jt;exports.useWithdrawSwap=Gs;exports.useWithdrawSwapQuote=Ks;exports.useWithdrawSwapQuoteAction=zs;Object.keys(client).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return client[k]}})});//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var client=require('@aave/client'),z=require('react'),types=require('@aave/types'),urql=require('urql'),actions=require('@aave/client/actions'),graphql=require('@aave/graphql'),core=require('@aave/core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var z__default=/*#__PURE__*/_interopDefault(z);var ne=z__default.default.createContext(null);function oe({children:e,client:r}){return z__default.default.createElement(ne.Provider,{value:r},z__default.default.createElement(urql.Provider,{value:r.urql},e))}function o(){let e=z.useContext(ne);return types.invariant(e,"Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>"),e}function ma({children:e,client:r}){return z__default.default.createElement(oe,{client:r},e)}function mr(e){if("userSpoke"in e)return e.userSpoke.user;if("userToken"in e)return e.userToken.user;if("userChains"in e)return e.userChains.user;if("userHub"in e)return e.userHub.user;let{user:r}=graphql.decodeUserPositionId(e.userPositionId);return r}function fr(e){if("userSpoke"in e)return e.userSpoke.user;if("userToken"in e)return e.userToken.user;if("userChains"in e)return e.userChains.user;if("userHub"in e)return e.userHub.user;let{user:r}=graphql.decodeUserPositionId(e.userPositionId);return r}function C(e,r){return e.refreshQueryWhere(graphql.UserBalancesQuery,s=>s.request.user===r)}function H(e,r){return e.refreshQueryWhere(graphql.UserSuppliesQuery,s=>mr(s.request.query)===r)}function O(e,r){return e.refreshQueryWhere(graphql.UserBorrowsQuery,s=>fr(s.request.query)===r)}function J(e,r,s){let t=a=>a.spoke.chain.chainId===s.chainId&&a.spoke.address===s.address&&a.user===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>n.some(t)),e.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n!==null&&t(n))])}function X(e,r){let s=t=>r.includes(t.id);return types.ResultAsync.combine([e.refreshQueryWhere(graphql.ReserveQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.ReservesQuery,(t,a)=>a.some(s))])}function Z(e,r,s){return e.refreshQueryWhere(graphql.UserSummaryQuery,t=>t.request.user===r&&(graphql.isSpokeInputVariant(t.request.filter)?t.request.filter.spoke.chainId===s.chainId&&t.request.filter.spoke.address===s.address:graphql.isChainIdsVariant(t.request.filter)?t.request.filter.chainIds.some(a=>a===s.chainId):false))}function ee(e,r){let s=t=>t.chain.chainId===r.chainId&&t.address===r.address;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.SpokeQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.SpokesQuery,(t,a)=>a.some(s))])}function re(e,r){let s=t=>t.chain.chainId===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.HubQuery,(t,a)=>a!==null&&s(a)),e.refreshQueryWhere(graphql.HubsQuery,(t,a)=>a.some(s))])}function V(e,r){return e.refreshQueryWhere(graphql.SpokePositionManagersQuery,s=>s.request.spoke===r)}function le(e,r){return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(s,t)=>t.some(a=>a.id===r)),e.refreshQueryWhere(graphql.UserPositionQuery,(s,t)=>t?.id===r)])}function x(e,r){let{chainId:s,spoke:t}=graphql.decodeReserveId(r.reserve),a={chainId:s,address:t};return types.ResultAsync.combine([J(e,r.sender,a),Z(e,r.sender,a),X(e,[r.reserve]),ee(e,a),C(e,r.sender),H(e,r.sender),O(e,r.sender),re(e,s)])}function ce(e,r){return C(e,r)}function ye(e,r){return types.ResultAsync.combine([H(e,r),C(e,r)])}function de(e,r){return types.ResultAsync.combine([O(e,r),C(e,r)])}function Se(e,r){return types.ResultAsync.combine([H(e,r),O(e,r),C(e,r)])}function me(e,r){return types.ResultAsync.combine([H(e,r),C(e,r)])}var E={Loading:e=>({data:void 0,error:void 0,loading:true,paused:false,reloading:false,metadata:e}),Success:(e,r,s=false)=>({data:e,error:void 0,loading:false,paused:false,reloading:s,metadata:r}),Failure:(e,r,s=false)=>({data:void 0,error:e,loading:false,paused:false,reloading:s,metadata:r}),Paused:(e,r,s)=>({data:e,error:r,loading:false,paused:true,reloading:false,metadata:s})};function i({document:e,variables:r,suspense:s,pause:t,selector:a=types.ok,pollInterval:n=0,batch:l=true}){let[c,m]=z.useState({operationKey:0,resultOperationKey:void 0}),[U,w]=z.useState(true),Q=z.useMemo(()=>urql.createRequest(e,r).key,[e,r]),[{fetching:T,data:q,error:_,stale:j},ae]=urql.useQuery({query:e,variables:r,pause:t,context:z.useMemo(()=>({batch:l,suspense:s}),[l,s])});if(z.useEffect(()=>{m(A=>({...A,operationKey:Q}));},[Q]),z.useEffect(()=>{t||T||w(false);},[T,t]),z.useEffect(()=>{t||T||m(A=>({...A,resultOperationKey:q&&!j?A.operationKey:A.resultOperationKey}));},[t,T,q,j]),z.useEffect(()=>{if(n<=0||T||t)return;let A=setTimeout(()=>{ae({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(A)},[T,ae,n,t]),t){let A=_?client.UnexpectedError.from(_):void 0;if(!q)return E.Paused(void 0,A,c);let $=a(q.value);return $.isErr()?E.Paused(void 0,$.error,c):E.Paused($.value,A,c)}if(!s&&U)return E.Loading(c);let G=j||!U&&T;if(_){let A=client.UnexpectedError.from(_);if(s)throw A;return E.Failure(A,c,G)}types.invariant(q,"No data returned");let F=a(q.value);if(F.isErr()){if(s)throw F.error;return E.Failure(F.error,c,G)}return E.Success(F.value,c,G)}var se={Idle:()=>({called:false,loading:false,data:void 0,error:void 0}),Loading:e=>({called:true,loading:true,data:e,error:void 0}),Success:e=>({called:true,loading:false,data:e,error:void 0}),Failed:e=>({called:true,loading:false,data:void 0,error:e})};function u(e,r){let[s,t]=z.useState(se.Idle()),a=z.useRef(false),n=z.useRef(true);z.useEffect(()=>()=>{n.current=false;},[]);let l=z.useCallback(e,r);return [z.useCallback(m=>{types.invariant(n.current,"Cannot execute a task on an unmounted component."),types.invariant(!a.current,"Cannot execute a task while another is in progress."),a.current=true;let U;t(w=>(U=w,{called:true,loading:true,data:w.data,error:void 0}));try{let w=l(m);return w.match(Q=>{a.current=!1,t(se.Success(Q));},Q=>{a.current=!1,t(se.Failed(Q));}),w}catch(w){throw a.current=false,U&&t(U),w}},[l]),s]}var p=e=>core.CancelError.from(e).asResultAsync(),d=class e{constructor(r){this.wait=r;}static isInstanceOf(r){return r instanceof e}static tryFrom(r){return e.isInstanceOf(r)?types.okAsync(r):core.UnexpectedError.from(r).asResultAsync()}};function R(e){return types.isSignature(e)?types.okAsync(e):core.UnexpectedError.from(`Expected Signature, but got ${String(e)}`).asResultAsync()}function Da({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Na({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function _a({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.HubAssetsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Fa({suspense:e=false,pause:r=false,...s}){return i({document:graphql.HubSummaryHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Va(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.hubs(r,s,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function $a({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ChainQuery,variables:{request:s},suspense:e,pause:r})}function za(){let e=o();return u(r=>actions.chain(e,r,{batch:false,requestPolicy:"cache-first"}),[e])}function Ja({suspense:e=false,pause:r=false,...s}={query:{filter:graphql.ChainsFilter.ALL}}){return i({document:graphql.ChainsQuery,variables:{request:s},suspense:e,pause:r})}function Xa(){let e=o();return u(r=>actions.exchangeRate(e,r,{requestPolicy:"network-only"}),[e])}function Za({suspense:e=false,pause:r=false,...s}){let t=o();return i({document:graphql.ExchangeRateQuery,variables:{request:s},suspense:e,pause:r,pollInterval:s.at?0:t.context.environment.exchangeRateInterval})}function an({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function nn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.AssetPriceHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function on({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetSupplyHistoryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r,batch:false})}function un({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.AssetBorrowHistoryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r,batch:false})}function pn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ProtocolHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function fn({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ReserveQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Rn(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.reserve(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function An({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ReservesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Un(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.reserves(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function wn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.BorrowApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Pn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SupplyApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function hn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserClaimableRewardsQuery,variables:{request:s},suspense:e,pause:r})}function vn(){let e=o();return u(r=>actions.userClaimableRewards(e,r,{requestPolicy:"cache-first"}),[e])}function Cn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeQuery,variables:{request:s},suspense:e,pause:r})}function Hn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokesQuery,variables:{request:s},suspense:e,pause:r})}function In({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokePositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function Bn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeUserPositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function f(e){switch(e.__typename){case "PositionSwapByIntentApprovalsRequired":return types.ok(e.quote);case "InsufficientLiquidityError":return types.err(core.ValidationError.fromGqlNode(e));default:return types.err(core.UnexpectedError.upgradeRequired(`Unsupported position swap quote result: ${e.__typename}`))}}function K(e){return e.__typename==="SwapFulfilled"||e.__typename==="SwapCancelled"||e.__typename==="SwapExpired"}function h(e){return {with:r=>e.approvals.reduce((s,t)=>s.andThen(a=>r(t,{cancel:p}).map(n=>{switch(t.__typename){case "PositionSwapAdapterContractApproval":a.adapterContractSignature=types.isSignature(n)?n:null;break;case "PositionSwapPositionManagerApproval":a.positionManagerSignature=types.isSignature(n)?n:null;break}return a})),types.okAsync({quoteId:e.quote.quoteId,adapterContractSignature:null,positionManagerSignature:null}))}}function v(e,r){return actions.swap(e,{intent:r}).andThen(s=>{switch(s.__typename){case "SwapReceipt":return types.okAsync(s);default:return core.UnexpectedError.from(s).asResultAsync()}})}function as(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.borrowSwapQuote(r,t,{currency:s}).andThen(a=>h(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>v(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function ve(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function os({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:ve(t,graphql.QuoteAccuracy.Fast),currency:s},selector:f,suspense:e,pause:r,batch:false}),l=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:ve(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:f,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data&&l.metadata.resultOperationKey===l.metadata.operationKey?l:n}function us(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.borrowSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(f),[r,e.currency])}function qe(e){return {__typename:"SwapCancelledResult",swapId:e.swapId,createdAt:e.createdAt,cancelledAt:e.cancelledAt,explorerUrl:e.explorerUrl}}var D=class extends types.ResultAwareError{name="CannotCancelSwapError"};function cs(e){let r=o();return u(s=>actions.swapStatus(r,{id:s.id}).andThen(t=>{if(t===null)return core.UnexpectedError.from("Swap not found").asResultAsync();switch(t.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(r,s).andThen(a=>e(a.data,{cancel:p})).andThen(R).andThen(a=>actions.cancelSwap(r,{intent:{id:s.id,signature:a}})).andThen(a=>a.__typename==="SwapCancelledResult"?types.okAsync(a):e(a,{cancel:p}).andThen(d.tryFrom).andThen(n=>n.wait()).andThen(()=>actions.swapStatus(r,{id:s.id})).andThen(n=>n?.__typename==="SwapCancelled"?types.okAsync(qe(n)):new D("Failed to cancel swap").asResultAsync()));case "SwapCancelled":return types.okAsync(qe(t));case "SwapExpired":return new D("Swap cannot longer be cancelled").asResultAsync();default:return core.UnexpectedError.upgradeRequired(`Unsupported swap status: ${t.__typename}`).asResultAsync()}}),[r,e])}function Ss(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.repayWithSupplyQuote(r,t,{currency:s}).andThen(a=>h(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>v(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Ie(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function fs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Ie(t,graphql.QuoteAccuracy.Fast),currency:s},selector:f,suspense:e,pause:r,batch:false}),l=i({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Ie(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:f,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data&&l.metadata.resultOperationKey===l.metadata.operationKey?l:n}function Rs(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.repayWithSupplyQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(f),[r,e.currency])}function ws(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.supplySwapQuote(r,t,{currency:s}).andThen(a=>h(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>v(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Oe(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function gs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.SupplySwapQuoteQuery,variables:{request:Oe(t,graphql.QuoteAccuracy.Fast),currency:s},selector:f,suspense:e,pause:r,batch:false}),l=i({document:graphql.SupplySwapQuoteQuery,variables:{request:Oe(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:f,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data&&l.metadata.resultOperationKey===l.metadata.operationKey?l:n}function bs(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.supplySwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(f),[r,e.currency])}function xs({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SwappableTokensQuery,variables:{request:s},suspense:e,pause:r})}function Qs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,c]=z.useState(false),m=i({document:graphql.SwapStatusQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval});return z.useEffect(()=>{m.data&&K(m.data)&&c(true);},[m.data]),m}function Ws(e){let r=o(),s=z.useCallback(t=>actions.swap(r,t).andThen(a=>{switch(a.__typename){case "SwapTransactionRequest":return e(a,{cancel:p}).andThen(d.tryFrom).andThen(n=>n.wait()).andThen(()=>types.okAsync(a.orderReceipt));case "SwapReceipt":return types.okAsync(a)}}),[r,e]);return u(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.tokenSwapQuote(r,a,{currency:t}).andThen(n=>{switch(n.__typename){case "SwapByTransaction":return s({transaction:{quoteId:n.quote.quoteId}});case "SwapByIntent":return actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId}).andThen(l=>e(l.data,{cancel:p}).andThen(R).andThen(c=>s({intent:{quoteId:l.newQuoteId,signature:c}})));case "SwapByIntentWithApprovalRequired":if(client.supportsPermit(n)){let l=n.approvals[0];return e(l,{cancel:p}).andThen(c=>types.isSignature(c)?actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId,permitSig:{deadline:l.bySignature.message.deadline,value:c}}):d.isInstanceOf(c)?c.wait().andThen(()=>actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId})):core.UnexpectedError.from(c).asResultAsync()).andThen(c=>e(c.data,{cancel:p}).andThen(R).andThen(m=>s({intent:{quoteId:c.newQuoteId,signature:m}})))}return n.approvals.reduce((l,c)=>l.andThen(()=>e({...c,bySignature:null},{cancel:p}).andThen(d.tryFrom).andThen(m=>m.wait())),types.okAsync(void 0)).andThen(()=>actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId})).andThen(l=>e(l.data,{cancel:p})).andThen(R).andThen(l=>s({intent:{quoteId:n.quote.quoteId,signature:l}}));default:types.never(`Unsupported swap quote result: ${n.__typename}. To be removed from API soon.`);}}),[r,e,s])}function te(e){switch(e.__typename){case "SwapByIntent":case "SwapByIntentWithApprovalRequired":case "SwapByTransaction":return types.ok(e.quote);case "InsufficientLiquidityError":return types.err(core.ValidationError.fromGqlNode(e));default:return types.err(core.UnexpectedError.upgradeRequired(`Unsupported swap quote result: ${e.__typename}`))}}function Ve(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function Fs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.TokenSwapQuoteQuery,variables:{request:Ve(t,graphql.QuoteAccuracy.Fast),currency:s},selector:te,suspense:e,pause:r,batch:false}),l=i({document:graphql.TokenSwapQuoteQuery,variables:{request:Ve(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:te,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data&&l.metadata.resultOperationKey===l.metadata.operationKey?l:n}function Vs(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.tokenSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(te),[r,e.currency])}function js(e,r){let s=new Map(r.map(t=>[t.swapId,t.__typename]));return e.filter(t=>t.__typename==="SwapFulfilled"&&s.get(t.swapId)!=="SwapFulfilled")}function Gs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,c]=z.useState(false),m=i({document:graphql.UserSwapsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval}),U=m.data?.items??[],w=z.useDeferredValue(U);return z.useEffect(()=>{if(U.length===0)return;U.every(K)&&c(true);for(let T of js(U,w))switch(T.operation.__typename){case "TokenSwap":a.user&&ce(n,a.user);break;case "BorrowSwap":a.user&&de(n,a.user);break;case "RepayWithSupply":a.user&&Se(n,a.user);break;case "SupplySwap":a.user&&ye(n,a.user);break;case "WithdrawSwap":a.user&&me(n,a.user);break}},[U,w,n,a.user]),m}function Js(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.withdrawSwapQuote(r,t,{currency:s}).andThen(a=>h(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>v(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function Ye(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function Zs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ye(t,graphql.QuoteAccuracy.Fast),currency:s},selector:f,suspense:e,pause:r,batch:false}),l=i({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ye(t,graphql.QuoteAccuracy.Accurate),currency:s},selector:f,suspense:false,pause:r||e&&!n.data,pollInterval:a.context.environment.swapQuoteInterval,batch:false});return l.data&&l.metadata.resultOperationKey===l.metadata.operationKey?l:n}function et(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.withdrawSwapQuote(r,s,{currency:e.currency,requestPolicy:"network-only"}).andThen(f),[r,e.currency])}function tt({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.ActivitiesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function at(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.activities(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function pt(e){let r=o();return u(s=>actions.borrow(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "PreContractActionRequired":return e(t,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t));case "Erc20ApprovalRequired":return client.UnexpectedError.from(t).asResultAsync()}}).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>x(r,s)),[r,e])}function yt(e){let r=o();return u(s=>actions.claimRewards(r,s).andThen(t=>e(t,{cancel:p})).andThen(d.tryFrom).andThen(t=>t.wait()).map(t=>client.transactionReceipt(t.txHash)),[r,e])}function ft(e,r){return {deadline:r.message.deadline,value:e}}function B(e,r){return e.approvals.reduce((s,t)=>s.andThen(()=>r({...t,bySignature:null},{cancel:p}).andThen(d.tryFrom).andThen(a=>a.wait())),types.okAsync(void 0)).map(()=>e.originalTransaction)}function W(e,r,s){let t=e.approvals[0];return r(t,{cancel:p}).andThen(a=>types.isSignature(a)?s(ft(a,t.bySignature)).map(types.expectTypename("TransactionRequest")):a.wait().map(()=>e.originalTransaction))}function wt(e,r){return "exact"in e.amount&&e.amount.exact?{...e,amount:{exact:{...e.amount.exact,permitSig:r}}}:e}function Pt(e){let r=o();return u(s=>actions.liquidatePosition(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?W(t,e,a=>actions.liquidatePosition(r,wt(s,a))).andThen(a=>e(a,{cancel:p})):B(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(d.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(d.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction),[r,e])}function Tt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.preview(r,s,{currency:e.currency,requestPolicy:"network-only"}),[r,e.currency])}function xt({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.PreviewQuery,variables:{request:t,currency:s},suspense:e,pause:r})}function ht(e){let r=o();return u(s=>actions.renounceSpokeUserPositionManager(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>V(r,s.spoke)),[r,e])}function qt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Ct(e){let r=o();return u(s=>actions.repay(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?W(t,e,a=>actions.repay(r,qt(s,a))).andThen(a=>e(a,{cancel:p})):B(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(d.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(d.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>x(r,s)),[r,e])}function It(e){let r=o();return u(s=>actions.setSpokeUserPositionManager(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>V(r,s.spoke)),[r,e])}function Dt(e){let r=o();return u(s=>{let t=s.changes.map(n=>n.reserve),a=t.map(n=>graphql.decodeReserveId(n));return actions.setUserSuppliesAsCollateral(r,s).andThen(n=>e(n,{cancel:p})).andThen(n=>n.wait()).andThen(r.waitForTransaction).andThrough(()=>types.ResultAsync.combine([H(r,s.sender),O(r,s.sender),...a.flatMap(({chainId:n,spoke:l})=>[J(r,s.sender,{chainId:n,address:l}),Z(r,s.sender,{chainId:n,address:l}),ee(r,{chainId:n,address:l})]),X(r,t),...a.map(({chainId:n})=>re(r,n))]))},[r,e])}function Vt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Mt(e){let r=o();return u(s=>actions.supply(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(t)?W(t,e,a=>actions.supply(r,Vt(s,a))).andThen(a=>e(a,{cancel:p})):B(t,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(t,{cancel:p}).andThen(d.tryFrom).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andThen(d.tryFrom).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>x(r,s)),[r,e])}function Kt(e){let r=o();return u(s=>actions.updateUserPositionConditions(r,s).andThen(t=>e(t,{cancel:p})).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>le(r,s.userPositionId)),[r,e])}function zt(e){let r=o();return u(s=>actions.withdraw(r,s).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:p});case "PreContractActionRequired":return e(t,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t));case "Erc20ApprovalRequired":return client.UnexpectedError.from(t).asResultAsync()}}).andThen(t=>t.wait()).andThen(r.waitForTransaction).andThrough(()=>x(r,s)),[r,e])}function bp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserSuppliesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Tp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userSupplies(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function xp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserBorrowsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Ep(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userBorrows(r,s,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function hp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserSummaryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function vp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserPositionsQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Qp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userPositions(r,s,{currency:e.currency,timeWindow:e.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function kp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return i({document:graphql.UserPositionQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function qp({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.UserBalancesQuery,variables:{request:t,currency:s},suspense:e,pause:r})}function Cp({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Hp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.userBalances(r,s,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function Ip({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.UserSummaryHistoryQuery,variables:{request:t,currency:s},suspense:e,pause:r,batch:false})}exports.AaveProvider=ma;exports.CannotCancelSwapError=D;exports.useAaveClient=o;exports.useActivities=tt;exports.useActivitiesAction=at;exports.useAsset=an;exports.useAssetBorrowHistory=un;exports.useAssetPriceHistory=nn;exports.useAssetSupplyHistory=on;exports.useBorrow=pt;exports.useBorrowApyHistory=wn;exports.useBorrowSwap=as;exports.useBorrowSwapQuote=os;exports.useBorrowSwapQuoteAction=us;exports.useCancelSwap=cs;exports.useChain=$a;exports.useChainAction=za;exports.useChains=Ja;exports.useClaimRewards=yt;exports.useExchangeRate=Za;exports.useExchangeRateAction=Xa;exports.useHub=Da;exports.useHubAssets=_a;exports.useHubSummaryHistory=Fa;exports.useHubs=Na;exports.useHubsAction=Va;exports.useLiquidatePosition=Pt;exports.usePreview=xt;exports.usePreviewAction=Tt;exports.useProtocolHistory=pn;exports.useRenounceSpokeUserPositionManager=ht;exports.useRepay=Ct;exports.useRepayWithSupply=Ss;exports.useRepayWithSupplyQuote=fs;exports.useRepayWithSupplyQuoteAction=Rs;exports.useReserve=fn;exports.useReserveAction=Rn;exports.useReserves=An;exports.useReservesAction=Un;exports.useSetSpokeUserPositionManager=It;exports.useSetUserSuppliesAsCollateral=Dt;exports.useSpoke=Cn;exports.useSpokePositionManagers=In;exports.useSpokeUserPositionManagers=Bn;exports.useSpokes=Hn;exports.useSupply=Mt;exports.useSupplyApyHistory=Pn;exports.useSupplySwap=ws;exports.useSupplySwapQuote=gs;exports.useSupplySwapQuoteAction=bs;exports.useSwapStatus=Qs;exports.useSwappableTokens=xs;exports.useTokenSwap=Ws;exports.useTokenSwapQuote=Fs;exports.useTokenSwapQuoteAction=Vs;exports.useUpdateUserPositionConditions=Kt;exports.useUserBalances=qp;exports.useUserBalancesAction=Hp;exports.useUserBorrows=xp;exports.useUserBorrowsAction=Ep;exports.useUserClaimableRewards=hn;exports.useUserClaimableRewardsAction=vn;exports.useUserPosition=kp;exports.useUserPositions=vp;exports.useUserPositionsAction=Qp;exports.useUserRiskPremiumBreakdown=Cp;exports.useUserSummary=hp;exports.useUserSummaryHistory=Ip;exports.useUserSupplies=bp;exports.useUserSuppliesAction=Tp;exports.useUserSwaps=Gs;exports.useWithdraw=zt;exports.useWithdrawSwap=Js;exports.useWithdrawSwapQuote=Zs;exports.useWithdrawSwapQuoteAction=et;Object.keys(client).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return client[k]}})});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|