@aave/react 4.0.0-next.48 → 4.0.0-next.49

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.
@@ -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 {extractDocumentName}from'@aave/core';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:R=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:b},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&&!b?r.operationKey:r.resultOperationKey}));},[s,o,l,b]),useEffect(()=>{if(R<=0||o||s)return;let r=setTimeout(()=>{A({requestPolicy:"network-only",batch:false});},R);return ()=>clearTimeout(r)},[o,A,R,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=b||!m&&o;if(d){let r=UnexpectedError.from(d);if(t)throw r;return n.Failure(r,u,f)}invariant(l!==void 0,`Unexpected empty response from the API for '${extractDocumentName(e)??"unknown"}' query`);let V=l===null?null:l.value,i=S(V);if(i.isErr()){if(t)throw i.error;return n.Failure(i.error,u,f)}return n.Success(i.value,u,f)}function ee({suspense:e=false,pause:a=false,...t}){return y({document:ChainQuery,variables:{request:t},suspense:e,pause:a})}function ae(){let e=b();return a(a=>chain(e,a,{batch:false,requestPolicy:"cache-first"}),[e])}function te({suspense:e=false,pause:a=false,...t}={query:{filter:ChainsFilter.ALL}}){return y({document:ChainsQuery,variables:{request:t},suspense:e,pause:a})}function re(){let e=b();return a(a=>exchangeRate(e,a,{requestPolicy:"network-only"}),[e])}function se({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,ee as c,ae as d,te as e,re as f,se as g};//# sourceMappingURL=chunk-V6Q6TCNV.js.map
2
+ //# sourceMappingURL=chunk-V6Q6TCNV.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","extractDocumentName","responseValue","useChain","request","ChainQuery","useChainAction","client","useAaveClient","useAsyncTask","fetchChain","useChains","ChainsFilter","ChainsQuery","useExchangeRateAction","exchangeRate","useExchangeRate","ExchangeRateQuery"],"mappings":"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","file":"chunk-V6Q6TCNV.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 { extractDocumentName } from '@aave/core';\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(\n data !== undefined,\n `Unexpected empty response from the API for '${extractDocumentName(document) ?? 'unknown'}' query`,\n );\n\n // GraphQL responses can have `{ \"data\": null }` but urql types don't reflect this\n const responseValue = data === null ? null : data.value;\n const selected = selector(responseValue as ResponseValue);\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'),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
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 Ra({children:e,client:r}){return z__default.default.createElement(oe,{client:r},e)}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 Rr(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 x(e,r){return e.refreshQueryWhere(graphql.UserBalancesQuery,s=>s.request.user===r)}function H(e,r){return e.refreshQueryWhere(graphql.UserSuppliesQuery,s=>fr(s.request.query)===r)}function O(e,r){return e.refreshQueryWhere(graphql.UserBorrowsQuery,s=>Rr(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 E(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),x(e,r.sender),H(e,r.sender),O(e,r.sender),re(e,s)])}function ce(e,r){return x(e,r)}function ye(e,r){return types.ResultAsync.combine([H(e,r),x(e,r)])}function de(e,r){return types.ResultAsync.combine([O(e,r),x(e,r)])}function Se(e,r){return types.ResultAsync.combine([H(e,r),O(e,r),x(e,r)])}function me(e,r){return types.ResultAsync.combine([H(e,r),x(e,r)])}var h={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),k=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:k}));},[k]),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 h.Paused(void 0,A,c);let $=a(q.value);return $.isErr()?h.Paused(void 0,$.error,c):h.Paused($.value,A,c)}if(!s&&U)return h.Loading(c);let G=j||!U&&T;if(_){let A=client.UnexpectedError.from(_);if(s)throw A;return h.Failure(A,c,G)}types.invariant(q!==void 0,`Unexpected empty response from the API for '${core.extractDocumentName(e)??"unknown"}' query`);let Je=q===null?null:q.value,F=a(Je);if(F.isErr()){if(s)throw F.error;return h.Failure(F.error,c,G)}return h.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(k=>{a.current=!1,t(se.Success(k));},k=>{a.current=!1,t(se.Failed(k));}),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 Fa({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 Va({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 Ma({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 La({suspense:e=false,pause:r=false,...s}){return i({document:graphql.HubSummaryHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Ka(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 Xa({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 en({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 rn(){let e=o();return u(r=>actions.exchangeRate(e,r,{requestPolicy:"network-only"}),[e])}function sn({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 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.AssetQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function pn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.AssetPriceHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function ln({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 cn({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 yn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ProtocolHistoryQuery,variables:{request:s},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.ReserveQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function wn(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 Pn({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 gn(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 bn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.BorrowApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Tn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SupplyApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function kn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserClaimableRewardsQuery,variables:{request:s},suspense:e,pause:r})}function qn(){let e=o();return u(r=>actions.userClaimableRewards(e,r,{requestPolicy:"cache-first"}),[e])}function Bn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeQuery,variables:{request:s},suspense:e,pause:r})}function Wn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokesQuery,variables:{request:s},suspense:e,pause:r})}function On({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokePositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function Dn({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 v(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 Q(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 os(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.borrowSwapQuote(r,t,{currency:s}).andThen(a=>v(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>Q(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 is({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 ps(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 ds(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 fs(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.repayWithSupplyQuote(r,t,{currency:s}).andThen(a=>v(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>Q(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 As({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 Us(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 gs(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.supplySwapQuote(r,t,{currency:s}).andThen(a=>v(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>Q(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 Ts({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 xs(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 hs({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 Ds(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 Ms({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 Ls(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 $s(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 zs({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 $s(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 Zs(e){let r=o();return u(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.withdrawSwapQuote(r,t,{currency:s}).andThen(a=>v(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(R).andThen(l=>Q(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 rt({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 st(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 nt({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 ot(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 ct(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(()=>E(r,s)),[r,e])}function St(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 At(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(At(a,t.bySignature)).map(types.expectTypename("TransactionRequest")):a.wait().map(()=>e.originalTransaction))}function gt(e,r){return "exact"in e.amount&&e.amount.exact?{...e,amount:{exact:{...e.amount.exact,permitSig:r}}}:e}function bt(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,gt(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.liquidator)),[r,e])}function Et(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 ht({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 Qt(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 Ht(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function It(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,Ht(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(()=>E(r,s)),[r,e])}function Wt(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 _t(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 Lt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Kt(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,Lt(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(()=>E(r,s)),[r,e])}function jt(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 Xt(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(()=>E(r,s)),[r,e])}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.UserSuppliesQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function hp(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 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.UserBorrowsQuery,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.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 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.UserSummaryQuery,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,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 Cp(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 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.UserPositionQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function Ip({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 Bp({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Wp(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 Op({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=Ra;exports.CannotCancelSwapError=D;exports.useAaveClient=o;exports.useActivities=nt;exports.useActivitiesAction=ot;exports.useAsset=un;exports.useAssetBorrowHistory=cn;exports.useAssetPriceHistory=pn;exports.useAssetSupplyHistory=ln;exports.useBorrow=ct;exports.useBorrowApyHistory=bn;exports.useBorrowSwap=os;exports.useBorrowSwapQuote=is;exports.useBorrowSwapQuoteAction=ps;exports.useCancelSwap=ds;exports.useChain=Xa;exports.useChainAction=Za;exports.useChains=en;exports.useClaimRewards=St;exports.useExchangeRate=sn;exports.useExchangeRateAction=rn;exports.useHub=Fa;exports.useHubAssets=Ma;exports.useHubSummaryHistory=La;exports.useHubs=Va;exports.useHubsAction=Ka;exports.useLiquidatePosition=bt;exports.usePreview=ht;exports.usePreviewAction=Et;exports.useProtocolHistory=yn;exports.useRenounceSpokeUserPositionManager=Qt;exports.useRepay=It;exports.useRepayWithSupply=fs;exports.useRepayWithSupplyQuote=As;exports.useRepayWithSupplyQuoteAction=Us;exports.useReserve=Un;exports.useReserveAction=wn;exports.useReserves=Pn;exports.useReservesAction=gn;exports.useSetSpokeUserPositionManager=Wt;exports.useSetUserSuppliesAsCollateral=_t;exports.useSpoke=Bn;exports.useSpokePositionManagers=On;exports.useSpokeUserPositionManagers=Dn;exports.useSpokes=Wn;exports.useSupply=Kt;exports.useSupplyApyHistory=Tn;exports.useSupplySwap=gs;exports.useSupplySwapQuote=Ts;exports.useSupplySwapQuoteAction=xs;exports.useSwapStatus=qs;exports.useSwappableTokens=hs;exports.useTokenSwap=Ds;exports.useTokenSwapQuote=Ms;exports.useTokenSwapQuoteAction=Ls;exports.useUpdateUserPositionConditions=jt;exports.useUserBalances=Ip;exports.useUserBalancesAction=Wp;exports.useUserBorrows=vp;exports.useUserBorrowsAction=Qp;exports.useUserClaimableRewards=kn;exports.useUserClaimableRewardsAction=qn;exports.useUserPosition=Hp;exports.useUserPositions=qp;exports.useUserPositionsAction=Cp;exports.useUserRiskPremiumBreakdown=Bp;exports.useUserSummary=kp;exports.useUserSummaryHistory=Op;exports.useUserSupplies=Ep;exports.useUserSuppliesAction=hp;exports.useUserSwaps=zs;exports.useWithdraw=Xt;exports.useWithdrawSwap=Zs;exports.useWithdrawSwapQuote=rt;exports.useWithdrawSwapQuoteAction=st;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