@aave/react 4.0.0-next.51 → 4.0.0-next.53

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/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 wa({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 E(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 F(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 h(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),E(e,r.sender),H(e,r.sender),O(e,r.sender),re(e,s)])}function ce(e,r){return E(e,r)}function ye(e,r){return types.ResultAsync.combine([H(e,r),E(e,r)])}function de(e,r){return types.ResultAsync.combine([O(e,r),E(e,r)])}function Se(e,r){return types.ResultAsync.combine([H(e,r),O(e,r),E(e,r)])}function me(e,r){return types.ResultAsync.combine([H(e,r),E(e,r)])}var Q={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:C,error:M,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:C&&!j?A.operationKey:A.resultOperationKey}));},[t,T,C,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=M?client.UnexpectedError.from(M):void 0;if(!C)return Q.Paused(void 0,A,c);let $=a(C.value);return $.isErr()?Q.Paused(void 0,$.error,c):Q.Paused($.value,A,c)}if(!s&&U)return Q.Loading(c);let G=j||!U&&T;if(M){let A=client.UnexpectedError.from(M);if(s)throw A;return Q.Failure(A,c,G)}types.invariant(C!==void 0,`Unexpected empty response from the API for '${core.extractDocumentName(e)??"unknown"}' query`);let Je=C===null?null:C.value,_=a(Je);if(_.isErr()){if(s)throw _.error;return Q.Failure(_.error,c,G)}return Q.Success(_.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 Ka({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 Ya({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 ja({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 Ga({suspense:e=false,pause:r=false,...s}){return i({document:graphql.HubSummaryHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function $a({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return i({document:graphql.HubAssetInterestRateModelQuery,variables:{request:t,currency:s},suspense:e,pause:r,selector:a=>types.ok(a.points)})}function za(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return u(s=>actions.hubAssetInterestRateModel(r,s,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function Ja(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 an({suspense:e=false,pause:r=false,...s}){return i({document:graphql.ChainQuery,variables:{request:s},suspense:e,pause:r})}function nn(){let e=o();return u(r=>actions.chain(e,r,{batch:false,requestPolicy:"cache-first"}),[e])}function on({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 un(){let e=o();return u(r=>actions.exchangeRate(e,r,{requestPolicy:"network-only"}),[e])}function pn({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 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.AssetQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r})}function mn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.AssetPriceHistoryQuery,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.AssetSupplyHistoryQuery,variables:{request:a,currency:s,timeWindow:t},suspense:e,pause:r,batch:false})}function Rn({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 xn({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 En(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 hn({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 Qn(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 vn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.BorrowApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function kn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SupplyApyHistoryQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Wn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserClaimableRewardsQuery,variables:{request:s},suspense:e,pause:r})}function On(){let e=o();return u(r=>actions.userClaimableRewards(e,r,{requestPolicy:"cache-first"}),[e])}function _n({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokeQuery,variables:{request:s},suspense:e,pause:r})}function Fn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokesQuery,variables:{request:s},suspense:e,pause:r})}function Vn({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SpokePositionManagersQuery,variables:{request:s},suspense:e,pause:r})}function Ln({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 k(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 ps(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=>k(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 cs({suspense:e=false,pause:r=false,currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...t}){let a=o(),n=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:Qe(t,graphql.QuoteAccuracy.Fast),currency:s},selector:f,suspense:e,pause:r,batch:false}),l=i({document:graphql.BorrowSwapQuoteQuery,variables:{request:Qe(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 ys(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 fs(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 Us(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=>k(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 Ps({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 gs(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 xs(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=>k(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 hs({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 Qs(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 ks({suspense:e=false,pause:r=false,...s}){return i({document:graphql.SwappableTokensQuery,variables:{request:s},suspense:e,pause:r})}function Is({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 _s(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 Fe(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.TokenSwapQuoteQuery,variables:{request:Fe(t,graphql.QuoteAccuracy.Fast),currency:s},selector:te,suspense:e,pause:r,batch:false}),l=i({document:graphql.TokenSwapQuoteQuery,variables:{request:Fe(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 js(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 Xs(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 Xs(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 st(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=>k(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 at({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 nt(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 it({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 pt(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 St(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(()=>h(r,s)),[r,e])}function Rt(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 Pt(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(Pt(a,t.bySignature)).map(types.expectTypename("TransactionRequest")):a.wait().map(()=>e.originalTransaction))}function xt(e,r){return "exact"in e.amount&&e.amount.exact?{...e,amount:{exact:{...e.amount.exact,permitSig:r}}}:e}function Et(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,xt(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.liquidator)),[r,e])}function vt(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 kt({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 Ct(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(()=>F(r,s.spoke)),[r,e])}function Wt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Ot(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,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).andThrough(()=>h(r,s)),[r,e])}function Nt(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(()=>F(r,s.spoke)),[r,e])}function Vt(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 jt(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Gt(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,jt(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(()=>h(r,s)),[r,e])}function zt(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 ra(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(()=>h(r,s)),[r,e])}function Cp({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 Ip({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 Bp(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 Wp({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 Op({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 Dp(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 Np({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 Mp({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 _p({suspense:e=false,pause:r=false,...s}){return i({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:s},suspense:e,pause:r,batch:false})}function Fp(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 Vp({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=wa;exports.CannotCancelSwapError=D;exports.useAaveClient=o;exports.useActivities=it;exports.useActivitiesAction=pt;exports.useAsset=Sn;exports.useAssetBorrowHistory=Rn;exports.useAssetPriceHistory=mn;exports.useAssetSupplyHistory=fn;exports.useBorrow=St;exports.useBorrowApyHistory=vn;exports.useBorrowSwap=ps;exports.useBorrowSwapQuote=cs;exports.useBorrowSwapQuoteAction=ys;exports.useCancelSwap=fs;exports.useChain=an;exports.useChainAction=nn;exports.useChains=on;exports.useClaimRewards=Rt;exports.useExchangeRate=pn;exports.useExchangeRateAction=un;exports.useHub=Ka;exports.useHubAssetInterestRateModel=$a;exports.useHubAssetInterestRateModelAction=za;exports.useHubAssets=ja;exports.useHubSummaryHistory=Ga;exports.useHubs=Ya;exports.useHubsAction=Ja;exports.useLiquidatePosition=Et;exports.usePreview=kt;exports.usePreviewAction=vt;exports.useProtocolHistory=An;exports.useRenounceSpokeUserPositionManager=Ct;exports.useRepay=Ot;exports.useRepayWithSupply=Us;exports.useRepayWithSupplyQuote=Ps;exports.useRepayWithSupplyQuoteAction=gs;exports.useReserve=xn;exports.useReserveAction=En;exports.useReserves=hn;exports.useReservesAction=Qn;exports.useSetSpokeUserPositionManager=Nt;exports.useSetUserSuppliesAsCollateral=Vt;exports.useSpoke=_n;exports.useSpokePositionManagers=Vn;exports.useSpokeUserPositionManagers=Ln;exports.useSpokes=Fn;exports.useSupply=Gt;exports.useSupplyApyHistory=kn;exports.useSupplySwap=xs;exports.useSupplySwapQuote=hs;exports.useSupplySwapQuoteAction=Qs;exports.useSwapStatus=Is;exports.useSwappableTokens=ks;exports.useTokenSwap=_s;exports.useTokenSwapQuote=Ys;exports.useTokenSwapQuoteAction=js;exports.useUpdateUserPositionConditions=zt;exports.useUserBalances=Mp;exports.useUserBalancesAction=Fp;exports.useUserBorrows=Ip;exports.useUserBorrowsAction=Bp;exports.useUserClaimableRewards=Wn;exports.useUserClaimableRewardsAction=On;exports.useUserPosition=Np;exports.useUserPositions=Op;exports.useUserPositionsAction=Dp;exports.useUserRiskPremiumBreakdown=_p;exports.useUserSummary=Wp;exports.useUserSummaryHistory=Vp;exports.useUserSupplies=Cp;exports.useUserSuppliesAction=Hp;exports.useUserSwaps=Zs;exports.useWithdraw=ra;exports.useWithdrawSwap=st;exports.useWithdrawSwapQuote=at;exports.useWithdrawSwapQuoteAction=nt;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 Ha({children:e,client:r}){return z__default.default.createElement(oe,{client:r},e)}function Ar(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 Ur(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 E(e,r){return e.refreshQueryWhere(graphql.UserBalancesQuery,t=>t.request.user===r)}function B(e,r){return e.refreshQueryWhere(graphql.UserSuppliesQuery,t=>Ar(t.request.query)===r)}function W(e,r){return e.refreshQueryWhere(graphql.UserBorrowsQuery,t=>Ur(t.request.query)===r)}function J(e,r,t){let s=a=>a.spoke.chain.chainId===t.chainId&&a.spoke.address===t.address&&a.user===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>n.some(s)),e.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n!==null&&s(n))])}function X(e,r){let t=s=>r.includes(s.id);return types.ResultAsync.combine([e.refreshQueryWhere(graphql.ReserveQuery,(s,a)=>a!==null&&t(a)),e.refreshQueryWhere(graphql.ReservesQuery,(s,a)=>a.some(t))])}function Z(e,r,t){return e.refreshQueryWhere(graphql.UserSummaryQuery,s=>s.request.user===r&&(graphql.isSpokeInputVariant(s.request.filter)?s.request.filter.spoke.chainId===t.chainId&&s.request.filter.spoke.address===t.address:graphql.isChainIdsVariant(s.request.filter)?s.request.filter.chainIds.some(a=>a===t.chainId):false))}function ee(e,r){let t=s=>s.chain.chainId===r.chainId&&s.address===r.address;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.SpokeQuery,(s,a)=>a!==null&&t(a)),e.refreshQueryWhere(graphql.SpokesQuery,(s,a)=>a.some(t))])}function re(e,r){let t=s=>s.chain.chainId===r;return types.ResultAsync.combine([e.refreshQueryWhere(graphql.HubQuery,(s,a)=>a!==null&&t(a)),e.refreshQueryWhere(graphql.HubsQuery,(s,a)=>a.some(t))])}function _(e,r){return e.refreshQueryWhere(graphql.SpokePositionManagersQuery,t=>t.request.spoke===r)}function le(e,r){return types.ResultAsync.combine([e.refreshQueryWhere(graphql.UserPositionsQuery,(t,s)=>s.some(a=>a.id===r)),e.refreshQueryWhere(graphql.UserPositionQuery,(t,s)=>s?.id===r)])}function h(e,r){let{chainId:t,spoke:s}=graphql.decodeReserveId(r.reserve),a={chainId:t,address:s};return types.ResultAsync.combine([J(e,r.sender,a),Z(e,r.sender,a),X(e,[r.reserve]),ee(e,a),E(e,r.sender),B(e,r.sender),W(e,r.sender),re(e,t)])}function ce(e,r){return E(e,r)}function ye(e,r){return types.ResultAsync.combine([B(e,r),E(e,r)])}function de(e,r){return types.ResultAsync.combine([W(e,r),E(e,r)])}function Se(e,r){return types.ResultAsync.combine([B(e,r),W(e,r),E(e,r)])}function me(e,r){return types.ResultAsync.combine([B(e,r),E(e,r)])}var v={Loading:e=>({data:void 0,error:void 0,loading:true,paused:false,reloading:false,metadata:e}),Success:(e,r,t=false)=>({data:e,error:void 0,loading:false,paused:false,reloading:t,metadata:r}),Failure:(e,r,t=false)=>({data:void 0,error:e,loading:false,paused:false,reloading:t,metadata:r}),Paused:(e,r,t)=>({data:e,error:r,loading:false,paused:true,reloading:false,metadata:t})};function u({document:e,variables:r,suspense:t,pause:s,selector:a=types.ok,pollInterval:n=0,batch:l=true}){let[c,m]=z.useState({operationKey:0,resultOperationKey:void 0}),[A,U]=z.useState(true),H=z.useMemo(()=>urql.createRequest(e,r).key,[e,r]),[{fetching:T,data:I,error:N,stale:j},ae]=urql.useQuery({query:e,variables:r,pause:s,context:z.useMemo(()=>({batch:l,suspense:t}),[l,t])});if(z.useEffect(()=>{m(b=>({...b,operationKey:H}));},[H]),z.useEffect(()=>{s||T||U(false);},[T,s]),z.useEffect(()=>{s||T||m(b=>({...b,resultOperationKey:I&&!j?b.operationKey:b.resultOperationKey}));},[s,T,I,j]),z.useEffect(()=>{if(n<=0||T||s)return;let b=setTimeout(()=>{ae({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(b)},[T,ae,n,s]),s){let b=N?client.UnexpectedError.from(N):void 0;if(!I)return v.Paused(void 0,b,c);let $=a(I.value);return $.isErr()?v.Paused(void 0,$.error,c):v.Paused($.value,b,c)}if(!t&&A)return v.Loading(c);let G=j||!A&&T;if(N){let b=client.UnexpectedError.from(N);if(t)throw b;return v.Failure(b,c,G)}types.invariant(I!==void 0,`Unexpected empty response from the API for '${core.extractDocumentName(e)??"unknown"}' query`);let er=I===null?null:I.value,M=a(er);if(M.isErr()){if(t)throw M.error;return v.Failure(M.error,c,G)}return v.Success(M.value,c,G)}var te={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 i(e,r){let[t,s]=z.useState(te.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 A;s(U=>(A=U,{called:true,loading:true,data:U.data,error:void 0}));try{let U=l(m);return U.match(H=>{a.current=!1,s(te.Success(H));},H=>{a.current=!1,s(te.Failed(H));}),U}catch(U){throw a.current=false,A&&s(A),U}},[l]),t]}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 f(e){return types.isSignature(e)?types.okAsync(e):core.UnexpectedError.from(`Expected Signature, but got ${String(e)}`).asResultAsync()}function an({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.HubQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function nn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.HubsQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function on({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.HubAssetsQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function un({suspense:e=false,pause:r=false,...t}){return u({document:graphql.HubSummaryHistoryQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function pn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){return u({document:graphql.HubAssetInterestRateModelQuery,variables:{request:s,currency:t},suspense:e,pause:r,selector:a=>types.ok(a.points)})}function ln(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.hubAssetInterestRateModel(r,t,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function cn(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.hubs(r,t,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function bn({suspense:e=false,pause:r=false,...t}){return u({document:graphql.ChainQuery,variables:{request:t},suspense:e,pause:r})}function An(){let e=o();return i(r=>actions.chain(e,r,{batch:false,requestPolicy:"cache-first"}),[e])}function Un({suspense:e=false,pause:r=false,...t}={query:{filter:graphql.ChainsFilter.ALL}}){return u({document:graphql.ChainsQuery,variables:{request:t},suspense:e,pause:r})}function gn(){let e=o();return i(r=>actions.exchangeRate(e,r,{requestPolicy:"network-only"}),[e])}function Pn({suspense:e=false,pause:r=false,...t}){let s=o();return u({document:graphql.ExchangeRateQuery,variables:{request:t},suspense:e,pause:r,pollInterval:t.at?0:s.context.environment.exchangeRateInterval})}function hn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.AssetQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function vn({suspense:e=false,pause:r=false,...t}){return u({document:graphql.AssetPriceHistoryQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function Qn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.AssetSupplyHistoryQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r,batch:false})}function kn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.AssetBorrowHistoryQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r,batch:false})}function qn({suspense:e=false,pause:r=false,...t}){return u({document:graphql.ProtocolHistoryQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function Dn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.ReserveQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function On(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.reserve(r,t,{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 Nn({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.ReservesQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function Mn(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.reserves(r,t,{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 _n({suspense:e=false,pause:r=false,...t}){return u({document:graphql.BorrowApyHistoryQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function Fn({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SupplyApyHistoryQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function $n({suspense:e=false,pause:r=false,...t}){return u({document:graphql.UserClaimableRewardsQuery,variables:{request:t},suspense:e,pause:r})}function zn(){let e=o();return i(r=>actions.userClaimableRewards(e,r,{requestPolicy:"cache-first"}),[e])}function eo({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SpokeQuery,variables:{request:t},suspense:e,pause:r})}function ro({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SpokesQuery,variables:{request:t},suspense:e,pause:r})}function to({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SpokePositionManagersQuery,variables:{request:t},suspense:e,pause:r})}function so({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SpokeUserPositionManagersQuery,variables:{request:t},suspense:e,pause:r})}function R(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 Q(e){return {with:r=>e.approvals.reduce((t,s)=>t.andThen(a=>r(s,{cancel:p}).map(n=>{switch(s.__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 k(e,r){return actions.swap(e,{intent:r}).andThen(t=>{switch(t.__typename){case "SwapReceipt":return types.okAsync(t);default:return core.UnexpectedError.from(t).asResultAsync()}})}function yt(e){let r=o();return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s})=>actions.borrowSwapQuote(r,s,{currency:t}).andThen(a=>Q(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(f).andThen(l=>k(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 St({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){let a=o(),n=u({document:graphql.BorrowSwapQuoteQuery,variables:{request:ve(s,graphql.QuoteAccuracy.Fast),currency:t},selector:R,suspense:e,pause:r,batch:false}),l=u({document:graphql.BorrowSwapQuoteQuery,variables:{request:ve(s,graphql.QuoteAccuracy.Accurate),currency:t},selector:R,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 mt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.borrowSwapQuote(r,t,{currency:e.currency,requestPolicy:"network-only"}).andThen(R),[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 At(e){let r=o();return i(t=>actions.swapStatus(r,{id:t.id}).andThen(s=>{if(s===null)return core.UnexpectedError.from("Swap not found").asResultAsync();switch(s.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(r,t).andThen(a=>e(a.data,{cancel:p})).andThen(f).andThen(a=>actions.cancelSwap(r,{intent:{id:t.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:t.id})).andThen(n=>n?.__typename==="SwapCancelled"?types.okAsync(qe(n)):new D("Failed to cancel swap").asResultAsync()));case "SwapCancelled":return types.okAsync(qe(s));case "SwapExpired":return new D("Swap cannot longer be cancelled").asResultAsync();default:return core.UnexpectedError.upgradeRequired(`Unsupported swap status: ${s.__typename}`).asResultAsync()}}),[r,e])}function Pt(e){let r=o();return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s})=>actions.repayWithSupplyQuote(r,s,{currency:t}).andThen(a=>Q(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(f).andThen(l=>k(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 Tt({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){let a=o(),n=u({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Ie(s,graphql.QuoteAccuracy.Fast),currency:t},selector:R,suspense:e,pause:r,batch:false}),l=u({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:Ie(s,graphql.QuoteAccuracy.Accurate),currency:t},selector:R,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 xt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.repayWithSupplyQuote(r,t,{currency:e.currency,requestPolicy:"network-only"}).andThen(R),[r,e.currency])}function vt(e){let r=o();return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s})=>actions.supplySwapQuote(r,s,{currency:t}).andThen(a=>Q(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(f).andThen(l=>k(r,{quoteId:n.newQuoteId,signature:l})))),[r,e])}function We(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function kt({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){let a=o(),n=u({document:graphql.SupplySwapQuoteQuery,variables:{request:We(s,graphql.QuoteAccuracy.Fast),currency:t},selector:R,suspense:e,pause:r,batch:false}),l=u({document:graphql.SupplySwapQuoteQuery,variables:{request:We(s,graphql.QuoteAccuracy.Accurate),currency:t},selector:R,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 qt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.supplySwapQuote(r,t,{currency:e.currency,requestPolicy:"network-only"}).andThen(R),[r,e.currency])}function Ht({suspense:e=false,pause:r=false,...t}){return u({document:graphql.SwappableTokensQuery,variables:{request:t},suspense:e,pause:r})}function Wt({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,c]=z.useState(false),m=u({document:graphql.SwapStatusQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval});return z.useEffect(()=>{m.data&&K(m.data)&&c(true);},[m.data]),m}function Lt(e){let r=o(),t=z.useCallback(s=>actions.swap(r,s).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 i(({currency:s=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.tokenSwapQuote(r,a,{currency:s}).andThen(n=>{switch(n.__typename){case "SwapByTransaction":return t({transaction:{quoteId:n.quote.quoteId}});case "SwapByIntent":return actions.prepareTokenSwap(r,{quoteId:n.quote.quoteId}).andThen(l=>e(l.data,{cancel:p}).andThen(f).andThen(c=>t({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}}):y.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(f).andThen(m=>t({intent:{quoteId:c.newQuoteId,signature:m}})))}return n.approvals.reduce((l,c)=>l.andThen(()=>e({...c,bySignature:null},{cancel:p}).andThen(y.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(f).andThen(l=>t({intent:{quoteId:n.quote.quoteId,signature:l}}));default:types.never(`Unsupported swap quote result: ${n.__typename}. To be removed from API soon.`);}}),[r,e,t])}function se(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 _e(e,r){return "market"in e&&e.market?{market:{...e.market,accuracy:r}}:e}function $t({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){let a=o(),n=u({document:graphql.TokenSwapQuoteQuery,variables:{request:_e(s,graphql.QuoteAccuracy.Fast),currency:t},selector:se,suspense:e,pause:r,batch:false}),l=u({document:graphql.TokenSwapQuoteQuery,variables:{request:_e(s,graphql.QuoteAccuracy.Accurate),currency:t},selector:se,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 zt(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.tokenSwapQuote(r,t,{currency:e.currency,requestPolicy:"network-only"}).andThen(se),[r,e.currency])}function rs(e,r){let t=new Map(r.map(s=>[s.swapId,s.__typename]));return e.filter(s=>s.__typename==="SwapFulfilled"&&t.get(s.swapId)!=="SwapFulfilled")}function ts({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){let n=o(),[l,c]=z.useState(false),m=u({document:graphql.UserSwapsQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r||l,pollInterval:n.context.environment.swapStatusInterval}),A=m.data?.items??[],U=z.useDeferredValue(A);return z.useEffect(()=>{if(A.length===0)return;A.every(K)&&c(true);for(let T of rs(A,U))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}},[A,U,n,a.user]),m}function ns(e){let r=o();return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s})=>actions.withdrawSwapQuote(r,s,{currency:t}).andThen(a=>Q(a).with(e).andThen(n=>actions.preparePositionSwap(r,n)).andThen(n=>e(n.data,{cancel:p}).andThen(f).andThen(l=>k(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 us({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){let a=o(),n=u({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ye(s,graphql.QuoteAccuracy.Fast),currency:t},selector:R,suspense:e,pause:r,batch:false}),l=u({document:graphql.WithdrawSwapQuoteQuery,variables:{request:Ye(s,graphql.QuoteAccuracy.Accurate),currency:t},selector:R,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 is(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.withdrawSwapQuote(r,t,{currency:e.currency,requestPolicy:"network-only"}).andThen(R),[r,e.currency])}function cs({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.ActivitiesQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function ys(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.activities(r,t,{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 fs(e){let r=o();return i(t=>actions.borrow(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "PreContractActionRequired":return e(s,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(s.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s));case "Erc20ApprovalRequired":return client.UnexpectedError.from(s).asResultAsync()}}).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>h(r,t)),[r,e])}function Us(e){let r=o();return i(t=>actions.claimRewards(r,t).andThen(s=>e(s,{cancel:p})).andThen(y.tryFrom).andThen(s=>s.wait()).map(s=>client.transactionReceipt(s.txHash)),[r,e])}function Ts(e,r){return {deadline:r.message.deadline,value:e}}function q(e,r){return e.approvals.reduce((t,s)=>t.andThen(()=>r({...s,bySignature:null},{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait())),types.okAsync(void 0)).map(()=>e.originalTransaction)}function C(e,r,t){let s=e.approvals[0];return r(s,{cancel:p}).andThen(a=>types.isSignature(a)?t(Ts(a,s.bySignature)).map(types.expectTypename("TransactionRequest")):a.wait().map(()=>e.originalTransaction))}function vs(e,r){return "exact"in e.amount&&e.amount.exact?{...e,amount:{exact:{...e.amount.exact,permitSig:r}}}:e}function Qs(e){let r=o();return i(t=>actions.liquidatePosition(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(s)?C(s,e,a=>actions.liquidatePosition(r,vs(t,a))).andThen(a=>e(a,{cancel:p})):q(s,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(s,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(s.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s))}}).andThen(y.tryFrom).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>E(r,t.liquidator)),[r,e])}function Cs(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.preview(r,t,{currency:e.currency,requestPolicy:"network-only"}),[r,e.currency])}function Hs({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){return u({document:graphql.PreviewQuery,variables:{request:s,currency:t},suspense:e,pause:r})}function Bs(e){let r=o();return i(t=>actions.renounceSpokeUserPositionManager(r,t).andThen(s=>e(s,{cancel:p})).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>_(r,t.spoke)),[r,e])}function Os(e,r,t){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permit:{permitSig:r,signedAmount:t}}}}:e}function Ns(e){let r=o();return i(t=>actions.repay(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(s)?C(s,e,a=>actions.repay(r,Os(t,a,s.approvals[0].bySignature.signedAmount))).andThen(a=>e(a,{cancel:p})):q(s,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(s,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(s.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s))}}).andThen(y.tryFrom).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>h(r,t)),[r,e])}function _s(e){let r=o();return i(t=>actions.setSpokeUserPositionManager(r,t).andThen(s=>e(s,{cancel:p})).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>_(r,t.spoke)),[r,e])}function Ys(e){let r=o();return i(t=>{let s=t.changes.map(n=>n.reserve),a=s.map(n=>graphql.decodeReserveId(n));return actions.setUserSuppliesAsCollateral(r,t).andThen(n=>e(n,{cancel:p})).andThen(n=>n.wait()).andThen(r.waitForTransaction).andThrough(()=>types.ResultAsync.combine([B(r,t.sender),W(r,t.sender),...a.flatMap(({chainId:n,spoke:l})=>[J(r,t.sender,{chainId:n,address:l}),Z(r,t.sender,{chainId:n,address:l}),ee(r,{chainId:n,address:l})]),X(r,s),...a.map(({chainId:n})=>re(r,n))]))},[r,e])}function zs(e,r){return "erc20"in e.amount?{...e,amount:{erc20:{...e.amount.erc20,permitSig:r}}}:e}function Js(e){let r=o();return i(t=>actions.supply(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(s)?C(s,e,a=>actions.supply(r,zs(t,a))).andThen(a=>e(a,{cancel:p})):q(s,e).andThen(a=>e(a,{cancel:p}));case "PreContractActionRequired":return e(s,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(()=>e(s.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s))}}).andThen(y.tryFrom).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>h(r,t)),[r,e])}function Zs(e){let r=o();return i(t=>actions.updateUserPositionConditions(r,t).andThen(s=>e(s,{cancel:p})).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>le(r,t.userPositionId)),[r,e])}function aa(e){let r=o();return i(t=>actions.withdraw(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "PreContractActionRequired":return e(s,{cancel:p}).andThen(a=>a.wait()).andThen(()=>e(s.originalTransaction,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s));case "Erc20ApprovalRequired":return client.UnexpectedError.from(s).asResultAsync()}}).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>h(r,t)),[r,e])}function Kp({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.UserSuppliesQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function Yp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.userSupplies(r,t,{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 jp({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.UserBorrowsQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function Gp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.userBorrows(r,t,{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 $p({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.UserSummaryQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function zp({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.UserPositionsQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function Jp(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.userPositions(r,t,{currency:e.currency,timeWindow:e.timeWindow,requestPolicy:"cache-first"}),[r,e.currency,e.timeWindow])}function Xp({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:s=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return u({document:graphql.UserPositionQuery,variables:{request:a,currency:t,timeWindow:s},suspense:e,pause:r})}function Zp({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){return u({document:graphql.UserBalancesQuery,variables:{request:s,currency:t},suspense:e,pause:r})}function el({suspense:e=false,pause:r=false,...t}){return u({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:t},suspense:e,pause:r,batch:false})}function rl(e=client.DEFAULT_QUERY_OPTIONS){let r=o();return i(t=>actions.userBalances(r,t,{currency:e.currency,requestPolicy:"cache-first"}),[r,e.currency])}function tl({suspense:e=false,pause:r=false,currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...s}){return u({document:graphql.UserSummaryHistoryQuery,variables:{request:s,currency:t},suspense:e,pause:r,batch:false})}function Ea(e,r){return {...e,amount:{...e.amount,permitSig:r}}}function yl(e){let r=o();return i(t=>actions.stableVaultDeposit(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "Erc20ApprovalRequired":return client.supportsPermit(s)?C(s,e,a=>actions.stableVaultDeposit(r,Ea(t,a))).andThen(a=>e(a,{cancel:p})):q(s,e).andThen(a=>e(a,{cancel:p}));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(s))}}).andThen(y.tryFrom).andThen(s=>s.wait()).andThen(r.waitForTransaction).andThrough(()=>Ze(r,t.user)),[r,e])}function dl(e){let r=o();return i(t=>actions.stableVaultWithdraw(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(r.waitForTransaction).andThrough(()=>Ze(r,t.user));case "StableVaultWithdrawClaim":return e(s.transaction,{cancel:p}).andThen(y.tryFrom).andThen(a=>a.wait()).andThen(r.waitForTransaction).map(()=>s)}}),[r,e])}function Sl(e){let r=o();return i(t=>actions.stableVaultWithdrawRedeem(r,t).andThen(s=>{switch(s.__typename){case "TransactionRequest":return e(s,{cancel:p});case "StableVaultPendingAvailability":return core.UnexpectedError.from(`Funds not yet available. Please retry after ${s.executableAfter.toLocaleString()}`).asResultAsync()}}).andThen(y.tryFrom).andThen(s=>s.wait()).andThen(r.waitForTransaction),[r,e])}function ml({suspense:e=false,pause:r=false,...t}){let s=o();return u({document:graphql.StableVaultClaimStatusQuery,variables:{request:t},suspense:e,pause:r,pollInterval:s.context.environment.pollingInterval})}function Rl({suspense:e=false,pause:r=false,...t}){return u({document:graphql.StableVaultUserPositionsQuery,variables:{request:t},suspense:e,pause:r})}function fl({suspense:e=false,pause:r=false,...t}){return u({document:graphql.StableVaultQuery,variables:{request:t},suspense:e,pause:r})}function bl({suspense:e=false,pause:r=false,...t}){return u({document:graphql.StableVaultsQuery,variables:{request:t},suspense:e,pause:r})}function Ze(e,r){return e.refreshQueryWhere(graphql.StableVaultUserPositionsQuery,t=>t.request.user===r)}exports.AaveProvider=Ha;exports.CannotCancelSwapError=D;exports.useAaveClient=o;exports.useActivities=cs;exports.useActivitiesAction=ys;exports.useAsset=hn;exports.useAssetBorrowHistory=kn;exports.useAssetPriceHistory=vn;exports.useAssetSupplyHistory=Qn;exports.useBorrow=fs;exports.useBorrowApyHistory=_n;exports.useBorrowSwap=yt;exports.useBorrowSwapQuote=St;exports.useBorrowSwapQuoteAction=mt;exports.useCancelSwap=At;exports.useChain=bn;exports.useChainAction=An;exports.useChains=Un;exports.useClaimRewards=Us;exports.useExchangeRate=Pn;exports.useExchangeRateAction=gn;exports.useHub=an;exports.useHubAssetInterestRateModel=pn;exports.useHubAssetInterestRateModelAction=ln;exports.useHubAssets=on;exports.useHubSummaryHistory=un;exports.useHubs=nn;exports.useHubsAction=cn;exports.useLiquidatePosition=Qs;exports.usePreview=Hs;exports.usePreviewAction=Cs;exports.useProtocolHistory=qn;exports.useRenounceSpokeUserPositionManager=Bs;exports.useRepay=Ns;exports.useRepayWithSupply=Pt;exports.useRepayWithSupplyQuote=Tt;exports.useRepayWithSupplyQuoteAction=xt;exports.useReserve=Dn;exports.useReserveAction=On;exports.useReserves=Nn;exports.useReservesAction=Mn;exports.useSetSpokeUserPositionManager=_s;exports.useSetUserSuppliesAsCollateral=Ys;exports.useSpoke=eo;exports.useSpokePositionManagers=to;exports.useSpokeUserPositionManagers=so;exports.useSpokes=ro;exports.useStableVault=fl;exports.useStableVaultClaimStatus=ml;exports.useStableVaultDeposit=yl;exports.useStableVaultUserPositions=Rl;exports.useStableVaultWithdraw=dl;exports.useStableVaultWithdrawRedeem=Sl;exports.useStableVaults=bl;exports.useSupply=Js;exports.useSupplyApyHistory=Fn;exports.useSupplySwap=vt;exports.useSupplySwapQuote=kt;exports.useSupplySwapQuoteAction=qt;exports.useSwapStatus=Wt;exports.useSwappableTokens=Ht;exports.useTokenSwap=Lt;exports.useTokenSwapQuote=$t;exports.useTokenSwapQuoteAction=zt;exports.useUpdateUserPositionConditions=Zs;exports.useUserBalances=Zp;exports.useUserBalancesAction=rl;exports.useUserBorrows=jp;exports.useUserBorrowsAction=Gp;exports.useUserClaimableRewards=$n;exports.useUserClaimableRewardsAction=zn;exports.useUserPosition=Xp;exports.useUserPositions=zp;exports.useUserPositionsAction=Jp;exports.useUserRiskPremiumBreakdown=el;exports.useUserSummary=$p;exports.useUserSummaryHistory=tl;exports.useUserSupplies=Kp;exports.useUserSuppliesAction=Yp;exports.useUserSwaps=ts;exports.useWithdraw=aa;exports.useWithdrawSwap=ns;exports.useWithdrawSwapQuote=us;exports.useWithdrawSwapQuoteAction=is;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