@aave/react 4.0.0-next.17 → 4.0.0-next.19
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var client=require('@aave/client'),O=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 O__default=/*#__PURE__*/_interopDefault(O);var V=O__default.default.createContext(null);function F({children:e,client:s}){return O__default.default.createElement(V.Provider,{value:s},O__default.default.createElement(urql.Provider,{value:s.urql},e))}function p(){let e=O.useContext(V);return types.invariant(e,"Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>"),e}function $s({children:e,client:s}){return O__default.default.createElement(F,{client:s},e)}var T={Loading:()=>({data:void 0,error:void 0,loading:true,paused:false}),Success:e=>({data:e,error:void 0,loading:false,paused:false}),Failure:e=>({data:void 0,error:e,loading:false,paused:false}),Paused:(e,s)=>({data:e,error:s,loading:false,paused:true})};function o({document:e,variables:s,suspense:r,pause:t,selector:a=types.identity,pollInterval:n=0,batch:u=true}){let[c,U]=O.useState(true),[{fetching:d,data:f,error:Q},M]=urql.useQuery({query:e,variables:s,pause:t,context:O.useMemo(()=>({batch:u,suspense:r}),[u,r])});if(O.useEffect(()=>{t||d||U(false);},[d,t]),O.useEffect(()=>{if(n<=0||d||t)return;let E=setTimeout(()=>{M({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(E)},[d,M,n,t]),t)return T.Paused(f?a(f.value):void 0,Q?client.UnexpectedError.from(Q):void 0);if(!r&&c)return T.Loading();if(Q){let E=client.UnexpectedError.from(Q);if(r)throw E;return T.Failure(E)}return types.invariant(f,"No data returned"),T.Success(a(f.value))}var _={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,s){let[r,t]=O.useState(_.Idle()),a=O.useRef(false),n=O.useCallback(e,s);return [O.useCallback(c=>{types.invariant(!a.current,"Cannot execute a task while another is in progress."),a.current=true;let U;t(d=>(U=d,{called:true,loading:true,data:d.data,error:void 0}));try{let d=n(c);return d.match(f=>{a.current=!1,t(_.Success(f));},f=>{a.current=!1,t(_.Failed(f));}),d}catch(d){throw a.current=false,t(types.nonNullable(U)),d}},[n]),r]}var l=e=>core.CancelError.from(e).asResultAsync(),P=class e{constructor(s){this.wait=s;}static isInstanceOf(s){return s instanceof e}static ensure(s){return types.invariant(e.isInstanceOf(s),"Expected PendingTransaction"),s}};function cr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function yr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function dr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubAssetsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Sr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.HubSummaryHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Rr(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.hubs(s,r,{currency:e.currency}),[s,e.currency])}function wr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.ChainQuery,variables:{request:r},suspense:e,pause:s})}function Pr({suspense:e=false,pause:s=false,...r}={query:{filter:graphql.ChainsFilter.ALL}}){return o({document:graphql.ChainsQuery,variables:{request:r},suspense:e,pause:s})}function Tr(){let e=p();return i(s=>actions.exchangeRate(e,s),[e])}function xr({suspense:e=false,pause:s=false,...r}){let t=p();return o({document:graphql.ExchangeRateQuery,variables:{request:r},suspense:e,pause:s,pollInterval:r.at?0:t.context.environment.exchangeRateInterval})}function vr(){let e=p();return i(s=>actions.permitTypedData(e,s),[e])}function Ir({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.AssetQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Wr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetPriceHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Or({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetSupplyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function _r({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetBorrowHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Dr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.ProtocolHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Gr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.ReserveQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Yr(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.reserve(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function jr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,selector:a,...n}){return o({document:graphql.ReservesQuery,variables:{request:n,currency:r,timeWindow:t},suspense:e,pause:s,selector:a||void 0})}function Kr(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.reserves(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function zr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.BorrowApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Jr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SupplyApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function st({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokeQuery,variables:{request:r},suspense:e,pause:s})}function rt({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokesQuery,variables:{request:r},suspense:e,pause:s})}function tt({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokePositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function at({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokeUserPositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function te(e){switch(e.__typename){case "SwapByIntent":return e.quote;case "SwapByIntentWithApprovalRequired":return e.quote;case "SwapByTransaction":return e.quote;default:types.never(`Unsupported swap quote result: ${e.__typename}. Upgrade to a newer version of the @aave/react package.`);}}function Rt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.TokenSwapQuoteQuery,variables:{request:{market:t},currency:r},selector:te,suspense:e,pause:s})}function Ut(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.tokenSwapQuote(s,{market:r},{currency:e.currency}).map(te),[s,e.currency])}function gt({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SwappableTokensQuery,variables:{request:r},suspense:e,pause:s})}function mt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSwapsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ft({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.SupplySwapQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function At(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.supplySwapQuote(s,{market:r},{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function bt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.BorrowSwapQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function wt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.borrowSwapQuote(s,{market:r},{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function B(e){return {with:s=>e.approvals.reduce((r,t)=>r.andThen(a=>s(t,{cancel:l}).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 C(e,s){return actions.swap(e,{intent:s}).andThen(r=>{switch(r.__typename){case "SwapReceipt":return types.okAsync(r);default:return core.UnexpectedError.from(r).asResultAsync()}})}function Pt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.supplySwapQuote(s,t,{currency:r}).andThen(a=>(types.invariant(a.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`),B(a).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(u=>(types.invariant(u.__typename==="SwapByIntent",`Unsupported swap plan: ${u.__typename}. Upgrade to a newer version of the @aave/react package.`),u))).andThen(n=>e(n,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n})))),[s,e])}function Tt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.borrowSwapQuote(s,t,{currency:r}).andThen(a=>(types.invariant(a.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`),B(a).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(u=>(types.invariant(u.__typename==="SwapByIntent",`Unsupported swap plan: ${u.__typename}. Upgrade to a newer version of the @aave/react package.`),u))).andThen(n=>e(n,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n})))),[s,e])}function xt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function ht(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.repayWithSupplyQuote(s,{market:r},{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function kt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.repayWithSupplyQuote(s,t,{currency:r}).andThen(a=>(types.invariant(a.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`),B(a).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(u=>(types.invariant(u.__typename==="SwapByIntent",`Unsupported swap plan: ${u.__typename}. Upgrade to a newer version of the @aave/react package.`),u))).andThen(n=>e(n,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n})))),[s,e])}function Qt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.WithdrawSwapQuoteQuery,variables:{request:t,currency:r},selector:a=>(types.invariant(a.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`),a.quote),suspense:e,pause:s})}function Et(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.withdrawSwapQuote(s,{market:r},{currency:e.currency}).map(t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),t.quote)),[s,e.currency])}function vt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.withdrawSwapQuote(s,t,{currency:r}).andThen(a=>(types.invariant(a.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`),B(a).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(u=>(types.invariant(u.__typename==="SwapByIntent",`Unsupported swap plan: ${u.__typename}. Upgrade to a newer version of the @aave/react package.`),u))).andThen(n=>e(n,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n})))),[s,e])}function qt(e){let s=p(),r=O.useCallback(t=>{switch(t.__typename){case "SwapTransactionRequest":return e(t,{cancel:l}).map(P.ensure).andThen(a=>a.wait()).andThen(()=>types.okAsync(t.orderReceipt));case "InsufficientBalanceError":return client.ValidationError.fromGqlNode(t).asResultAsync();case "SwapReceipt":return types.okAsync(t);default:return new core.UnexpectedError(`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}},[e]);return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.tokenSwapQuote(s,a,{currency:t}).andThen(n=>{switch(n.__typename){case "SwapByTransaction":return actions.swap(s,{transaction:{quoteId:n.quote.quoteId}}).andThen(r);case "SwapByIntent":return e(n.data,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Invalid signature"),u)).andThen(u=>actions.swap(s,{intent:{quoteId:n.quote.quoteId,signature:u}})).andThen(r);case "SwapByIntentWithApprovalRequired":return e(n.approval,{cancel:l}).andThen(u=>graphql.isERC20PermitSignature(u)?actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId,permitSig:u}):P.isInstanceOf(u)?u.wait().andThen(()=>actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId})):core.UnexpectedError.from(u).asResultAsync()).andThen(u=>{switch(u.__typename){case "SwapByIntent":return e(u.data,{cancel:l});case "InsufficientBalanceError":return client.ValidationError.fromGqlNode(u).asResultAsync();default:return new core.UnexpectedError(`Unsupported swap plan: ${u.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}}).map(u=>(types.invariant(types.isSignature(u),"Invalid signature"),u)).andThen(u=>actions.swap(s,{intent:{quoteId:n.quote.quoteId,signature:u}})).andThen(r);default:types.never(`Unsupported swap quote result: ${n.__typename}. To be removed from API soon.`);}}),[s,e,r])}var q=class extends types.ResultAwareError{name="CannotCancelSwapError"};function Ht(e){let s=p();return i(r=>actions.swapStatus(s,{id:r.id}).andThen(t=>{switch(t.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(s,r).andThen(a=>e(a.data,{cancel:l})).map(a=>(types.invariant(types.isSignature(a),"Invalid signature"),a)).andThen(a=>actions.cancelSwap(s,{intent:{id:r.id,signature:a}})).andThen(a=>a.__typename==="SwapCancelled"?types.okAsync(a):e(a,{cancel:l}).map(P.ensure).andThen(n=>n.wait()).andThen(()=>actions.swapStatus(s,{id:r.id})).andThen(n=>n.__typename==="SwapCancelled"?types.okAsync(n):new q("Failed to cancel swap").asResultAsync()));case "SwapCancelled":return types.okAsync(t);case "SwapExpired":return new q("Swap cannot longer be cancelled").asResultAsync();default:return new core.UnexpectedError(`Unsupported swap status: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}}),[s,e])}function W(e,s){let{chainId:r,spoke:t}=graphql.decodeReserveId(s.reserve);return async()=>Promise.all([await e.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>a.request.user===s.sender&&n.some(u=>u.spoke.chain.chainId===r&&u.spoke.address===t)),await e.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n?.spoke.chain.chainId===r&&n?.spoke.address===t&&n.user===s.sender),await e.refreshQueryWhere(graphql.UserSummaryQuery,a=>a.request.user===s.sender&&graphql.isSpokeInputVariant(a.request.filter)?a.request.filter.spoke.chainId===r&&a.request.filter.spoke.address===t:graphql.isChainIdsVariant(a.request.filter)?a.request.filter.chainIds.some(n=>n===r):false),await e.refreshQueryWhere(graphql.ReservesQuery,(a,n)=>n.some(u=>u.id===s.reserve)),await e.refreshQueryWhere(graphql.SpokesQuery,(a,n)=>n.some(u=>u.chain.chainId===r&&u.address===t)),await e.refreshQueryWhere(graphql.UserBalancesQuery,a=>a.request.user===s.sender),await e.refreshQueryWhere(graphql.HubsQuery,a=>graphql.isChainIdsVariant(a.request)&&a.request.chainIds.some(n=>n===r))])}function Mt(e){let s=p();return i(r=>actions.supply(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(W(s,r)),[s,e])}function Vt(e){let s=p();return i(r=>actions.borrow(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(W(s,r)),[s,e])}function Ft(e){let s=p();return i(r=>actions.repay(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(W(s,r)),[s,e])}function Lt(e){let s=p();return i(r=>actions.withdraw(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(W(s,r)),[s,e])}function $t(e){let s=p();return i(r=>actions.renounceSpokeUserPositionManager(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,t=>t.request.spoke===r.spoke)),[s,e])}function Gt(e){let s=p();return i(r=>actions.updateUserPositionConditions(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(async()=>{let{userPositionId:t}=r;return Promise.all([s.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>n.some(u=>u.id===t)),s.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n?.id===t)])}),[s,e])}function Yt(e){let s=p();return i(r=>{let t=r.changes.map(n=>n.reserve),a=t.map(n=>graphql.decodeReserveId(n));return actions.setUserSuppliesAsCollateral(s,r).andThen(n=>e(n,{cancel:l})).andThen(n=>n.wait()).andThen(s.waitForTransaction).andTee(()=>Promise.all([...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserPositionsQuery,(c,U)=>c.request.user===r.sender&&U.some(d=>d.spoke.chain.chainId===n&&d.spoke.address===u))),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserPositionQuery,(c,U)=>U?.spoke.chain.chainId===n&&U?.spoke.address===u&&U.user===r.sender)),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserSummaryQuery,c=>c.request.user===r.sender&&graphql.isSpokeInputVariant(c.request.filter)?c.request.filter.spoke.chainId===n&&c.request.filter.spoke.address===u:graphql.isChainIdsVariant(c.request.filter)?c.request.filter.chainIds.some(U=>U===n):false)),s.refreshQueryWhere(graphql.ReservesQuery,(n,u)=>u.some(c=>t.includes(c.id))),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.SpokesQuery,(c,U)=>U.some(d=>d.chain.chainId===n&&d.address===u))),...a.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubsQuery,u=>graphql.isChainIdsVariant(u.request.query)?u.request.query.chainIds.some(c=>c===n):u.request.query.tokens.some(c=>c.chainId===n))),...a.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubQuery,u=>graphql.isHubInputVariant(u.request.query)?u.request.query.hubInput.chainId===n:graphql.decodeHubId(u.request.query.hubId).chainId===n))]))},[s,e])}function jt(e){let s=p();return i(r=>actions.liquidatePosition(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}),[s,e])}function Kt(e){let s=p();return i(r=>actions.setSpokeUserPositionManager(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,t=>t.request.spoke===r.spoke)),[s,e])}function zt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.preview(s,r,{currency:e.currency}),[s,e.currency])}function Jt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.PreviewQuery,variables:{request:t,currency:r},suspense:e,pause:s})}function Xt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.ActivitiesQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Zt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.activities(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function ua({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSuppliesQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function oa(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userSupplies(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function pa({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserBorrowsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ia(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userBorrows(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function la({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSummaryQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ca({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserPositionsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ya(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userPositions(s,r,{currency:e.currency,timeWindow:e.timeWindow}),[s,e.currency,e.timeWindow])}function da({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserPositionQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Sa({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.UserBalancesQuery,variables:{request:t,currency:r},suspense:e,pause:s})}function Ra({suspense:e=false,pause:s=false,...r}){return o({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Ua(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userBalances(s,r,{currency:e.currency}),[s,e.currency])}function ga({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.UserSummaryHistoryQuery,variables:{request:t,currency:r},suspense:e,pause:s,batch:false})}exports.AaveProvider=$s;exports.CannotCancelSwapError=q;exports.useAaveClient=p;exports.useActivities=Xt;exports.useActivitiesAction=Zt;exports.useAsset=Ir;exports.useAssetBorrowHistory=_r;exports.useAssetPriceHistory=Wr;exports.useAssetSupplyHistory=Or;exports.useBorrow=Vt;exports.useBorrowApyHistory=zr;exports.useBorrowSwap=Tt;exports.useBorrowSwapQuote=bt;exports.useBorrowSwapQuoteAction=wt;exports.useCancelSwap=Ht;exports.useChain=wr;exports.useChains=Pr;exports.useExchangeRate=xr;exports.useExchangeRateAction=Tr;exports.useHub=cr;exports.useHubAssets=dr;exports.useHubSummaryHistory=Sr;exports.useHubs=yr;exports.useHubsAction=Rr;exports.useLiquidatePosition=jt;exports.usePermitTypedDataAction=vr;exports.usePreview=Jt;exports.usePreviewAction=zt;exports.useProtocolHistory=Dr;exports.useRenounceSpokeUserPositionManager=$t;exports.useRepay=Ft;exports.useRepayWithSupply=kt;exports.useRepayWithSupplyQuote=xt;exports.useRepayWithSupplyQuoteAction=ht;exports.useReserve=Gr;exports.useReserveAction=Yr;exports.useReserves=jr;exports.useReservesAction=Kr;exports.useSetSpokeUserPositionManager=Kt;exports.useSetUserSuppliesAsCollateral=Yt;exports.useSpoke=st;exports.useSpokePositionManagers=tt;exports.useSpokeUserPositionManagers=at;exports.useSpokes=rt;exports.useSupply=Mt;exports.useSupplyApyHistory=Jr;exports.useSupplySwap=Pt;exports.useSupplySwapQuote=ft;exports.useSupplySwapQuoteAction=At;exports.useSwappableTokens=gt;exports.useTokenSwap=qt;exports.useTokenSwapQuote=Rt;exports.useTokenSwapQuoteAction=Ut;exports.useUpdateUserPositionConditions=Gt;exports.useUserBalances=Sa;exports.useUserBalancesAction=Ua;exports.useUserBorrows=pa;exports.useUserBorrowsAction=ia;exports.useUserPosition=da;exports.useUserPositions=ca;exports.useUserPositionsAction=ya;exports.useUserRiskPremiumBreakdown=Ra;exports.useUserSummary=la;exports.useUserSummaryHistory=ga;exports.useUserSupplies=ua;exports.useUserSuppliesAction=oa;exports.useUserSwaps=mt;exports.useWithdraw=Lt;exports.useWithdrawSwap=vt;exports.useWithdrawSwapQuote=Qt;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'),W=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 W__default=/*#__PURE__*/_interopDefault(W);var _=W__default.default.createContext(null);function F({children:e,client:s}){return W__default.default.createElement(_.Provider,{value:s},W__default.default.createElement(urql.Provider,{value:s.urql},e))}function p(){let e=W.useContext(_);return types.invariant(e,"Could not find Aave SDK context, ensure your code is wrapped in a <AaveProvider>"),e}function Ls({children:e,client:s}){return W__default.default.createElement(F,{client:s},e)}var T={Loading:()=>({data:void 0,error:void 0,loading:true,paused:false}),Success:e=>({data:e,error:void 0,loading:false,paused:false}),Failure:e=>({data:void 0,error:e,loading:false,paused:false}),Paused:(e,s)=>({data:e,error:s,loading:false,paused:true})};function o({document:e,variables:s,suspense:r,pause:t,selector:a=types.identity,pollInterval:n=0,batch:u=true}){let[c,R]=W.useState(true),[{fetching:d,data:f,error:k},V]=urql.useQuery({query:e,variables:s,pause:t,context:W.useMemo(()=>({batch:u,suspense:r}),[u,r])});if(W.useEffect(()=>{t||d||R(false);},[d,t]),W.useEffect(()=>{if(n<=0||d||t)return;let Q=setTimeout(()=>{V({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(Q)},[d,V,n,t]),t)return T.Paused(f?a(f.value):void 0,k?client.UnexpectedError.from(k):void 0);if(!r&&c)return T.Loading();if(k){let Q=client.UnexpectedError.from(k);if(r)throw Q;return T.Failure(Q)}return types.invariant(f,"No data returned"),T.Success(a(f.value))}var O={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,s){let[r,t]=W.useState(O.Idle()),a=W.useRef(false),n=W.useCallback(e,s);return [W.useCallback(c=>{types.invariant(!a.current,"Cannot execute a task while another is in progress."),a.current=true;let R;t(d=>(R=d,{called:true,loading:true,data:d.data,error:void 0}));try{let d=n(c);return d.match(f=>{a.current=!1,t(O.Success(f));},f=>{a.current=!1,t(O.Failed(f));}),d}catch(d){throw a.current=false,t(types.nonNullable(R)),d}},[n]),r]}var l=e=>core.CancelError.from(e).asResultAsync(),w=class e{constructor(s){this.wait=s;}static isInstanceOf(s){return s instanceof e}static ensure(s){return types.invariant(e.isInstanceOf(s),"Expected PendingTransaction"),s}};function lr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function cr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function yr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.HubAssetsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function dr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.HubSummaryHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Sr(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.hubs(s,r,{currency:e.currency}),[s,e.currency])}function Ar({suspense:e=false,pause:s=false,...r}){return o({document:graphql.ChainQuery,variables:{request:r},suspense:e,pause:s})}function Pr({suspense:e=false,pause:s=false,...r}={query:{filter:graphql.ChainsFilter.ALL}}){return o({document:graphql.ChainsQuery,variables:{request:r},suspense:e,pause:s})}function wr(){let e=p();return i(s=>actions.exchangeRate(e,s),[e])}function Tr({suspense:e=false,pause:s=false,...r}){let t=p();return o({document:graphql.ExchangeRateQuery,variables:{request:r},suspense:e,pause:s,pollInterval:r.at?0:t.context.environment.exchangeRateInterval})}function Er(){let e=p();return i(s=>actions.permitTypedData(e,s),[e])}function Br({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.AssetQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Ir({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetPriceHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Wr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetSupplyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Or({suspense:e=false,pause:s=false,...r}){return o({document:graphql.AssetBorrowHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Dr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.ProtocolHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Yr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.ReserveQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Gr(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.reserve(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function jr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,selector:a,...n}){return o({document:graphql.ReservesQuery,variables:{request:n,currency:r,timeWindow:t},suspense:e,pause:s,selector:a||void 0})}function $r(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.reserves(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function Kr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.BorrowApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function zr({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SupplyApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function et({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokeQuery,variables:{request:r},suspense:e,pause:s})}function st({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokesQuery,variables:{request:r},suspense:e,pause:s})}function rt({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokePositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function tt({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SpokeUserPositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function se(e){switch(e.__typename){case "SwapByIntent":case "SwapByIntentWithApprovalRequired":case "SwapByTransaction":return e.quote;default:throw core.UnexpectedError.upgradeRequired(`Unsupported swap quote result: ${e.__typename}`)}}function St({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.TokenSwapQuoteQuery,variables:{request:{market:t},currency:r},selector:se,suspense:e,pause:s})}function Rt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.tokenSwapQuote(s,{market:r},{currency:e.currency}).map(se),[s,e.currency])}function Ut({suspense:e=false,pause:s=false,...r}){return o({document:graphql.SwappableTokensQuery,variables:{request:r},suspense:e,pause:s})}function gt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSwapsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ft({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.SupplySwapQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function bt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.supplySwapQuote(s,r,{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function mt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.BorrowSwapQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function At(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.borrowSwapQuote(s,r,{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function H(e){return {with:s=>e.approvals.reduce((r,t)=>r.andThen(a=>s(t,{cancel:l}).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 C(e,s){return actions.swap(e,{intent:s}).andThen(r=>{switch(r.__typename){case "SwapReceipt":return types.okAsync(r);default:return core.UnexpectedError.from(r).asResultAsync()}})}function Pt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.supplySwapQuote(s,t,{currency:r}).andThen(a=>H(a).with(e).andThen(n=>actions.preparePositionSwap(s,n)).andThen(n=>e(n.data,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n}))),[s,e])}function wt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.borrowSwapQuote(s,t,{currency:r}).andThen(a=>H(a).with(e).andThen(n=>actions.preparePositionSwap(s,n)).andThen(n=>e(n.data,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n}))),[s,e])}function Tt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function xt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.repayWithSupplyQuote(s,r,{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function ht(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.repayWithSupplyQuote(s,t,{currency:r}).andThen(a=>H(a).with(e).andThen(n=>actions.preparePositionSwap(s,n)).andThen(n=>e(n.data,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n}))),[s,e])}function kt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.WithdrawSwapQuoteQuery,variables:{request:t,currency:r},selector:a=>a.quote,suspense:e,pause:s})}function Qt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.withdrawSwapQuote(s,r,{currency:e.currency}).map(t=>t.quote),[s,e.currency])}function Et(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.withdrawSwapQuote(s,t,{currency:r}).andThen(a=>H(a).with(e).andThen(n=>actions.preparePositionSwap(s,n)).andThen(n=>e(n.data,{cancel:l}).map(u=>(types.invariant(types.isSignature(u),"Expected signature, got an object instead."),u))).andThen(n=>C(s,{quoteId:a.quote.quoteId,signature:n}))),[s,e])}function qt(e){let s=p(),r=W.useCallback(t=>actions.swap(s,t).andThen(a=>{switch(a.__typename){case "SwapTransactionRequest":return e(a,{cancel:l}).map(w.ensure).andThen(n=>n.wait()).andThen(()=>types.okAsync(a.orderReceipt));case "SwapReceipt":return types.okAsync(a)}}),[s,e]);return i(({currency:t=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.tokenSwapQuote(s,a,{currency:t}).andThen(n=>{switch(n.__typename){case "SwapByTransaction":return r({transaction:{quoteId:n.quote.quoteId}});case "SwapByIntent":return actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId}).andThen(u=>e(u.data,{cancel:l}).map(c=>(types.invariant(types.isSignature(c),"Invalid signature"),c)).andThen(c=>r({intent:{quoteId:u.newQuoteId,signature:c}})));case "SwapByIntentWithApprovalRequired":return e(n.approval,{cancel:l}).andThen(u=>graphql.isERC20PermitSignature(u)?actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId,permitSig:u}):w.isInstanceOf(u)?u.wait().andThen(()=>actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId})):core.UnexpectedError.from(u).asResultAsync()).andThen(u=>e(u.data,{cancel:l}).map(c=>(types.invariant(types.isSignature(c),"Invalid signature"),c)).andThen(c=>r({intent:{quoteId:n.quote.quoteId,signature:c}})));default:types.never(`Unsupported swap quote result: ${n.__typename}. To be removed from API soon.`);}}),[s,e,r])}var E=class extends types.ResultAwareError{name="CannotCancelSwapError"};function vt(e){let s=p();return i(r=>actions.swapStatus(s,{id:r.id}).andThen(t=>{switch(t.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(s,r).andThen(a=>e(a.data,{cancel:l})).map(a=>(types.invariant(types.isSignature(a),"Invalid signature"),a)).andThen(a=>actions.cancelSwap(s,{intent:{id:r.id,signature:a}})).andThen(a=>a.__typename==="SwapCancelled"?types.okAsync(a):e(a,{cancel:l}).map(w.ensure).andThen(n=>n.wait()).andThen(()=>actions.swapStatus(s,{id:r.id})).andThen(n=>n.__typename==="SwapCancelled"?types.okAsync(n):new E("Failed to cancel swap").asResultAsync()));case "SwapCancelled":return types.okAsync(t);case "SwapExpired":return new E("Swap cannot longer be cancelled").asResultAsync();default:return core.UnexpectedError.upgradeRequired(`Unsupported swap status: ${t.__typename}`).asResultAsync()}}),[s,e])}function I(e,s){let{chainId:r,spoke:t}=graphql.decodeReserveId(s.reserve);return async()=>Promise.all([await e.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>a.request.user===s.sender&&n.some(u=>u.spoke.chain.chainId===r&&u.spoke.address===t)),await e.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n?.spoke.chain.chainId===r&&n?.spoke.address===t&&n.user===s.sender),await e.refreshQueryWhere(graphql.UserSummaryQuery,a=>a.request.user===s.sender&&graphql.isSpokeInputVariant(a.request.filter)?a.request.filter.spoke.chainId===r&&a.request.filter.spoke.address===t:graphql.isChainIdsVariant(a.request.filter)?a.request.filter.chainIds.some(n=>n===r):false),await e.refreshQueryWhere(graphql.ReservesQuery,(a,n)=>n.some(u=>u.id===s.reserve)),await e.refreshQueryWhere(graphql.SpokesQuery,(a,n)=>n.some(u=>u.chain.chainId===r&&u.address===t)),await e.refreshQueryWhere(graphql.UserBalancesQuery,a=>a.request.user===s.sender),await e.refreshQueryWhere(graphql.HubsQuery,a=>graphql.isChainIdsVariant(a.request)&&a.request.chainIds.some(n=>n===r))])}function Mt(e){let s=p();return i(r=>actions.supply(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(I(s,r)),[s,e])}function Vt(e){let s=p();return i(r=>actions.borrow(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(I(s,r)),[s,e])}function _t(e){let s=p();return i(r=>actions.repay(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(I(s,r)),[s,e])}function Ft(e){let s=p();return i(r=>actions.withdraw(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}).andTee(I(s,r)),[s,e])}function Lt(e){let s=p();return i(r=>actions.renounceSpokeUserPositionManager(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,t=>t.request.spoke===r.spoke)),[s,e])}function Yt(e){let s=p();return i(r=>actions.updateUserPositionConditions(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(async()=>{let{userPositionId:t}=r;return Promise.all([s.refreshQueryWhere(graphql.UserPositionsQuery,(a,n)=>n.some(u=>u.id===t)),s.refreshQueryWhere(graphql.UserPositionQuery,(a,n)=>n?.id===t)])}),[s,e])}function Gt(e){let s=p();return i(r=>{let t=r.changes.map(n=>n.reserve),a=t.map(n=>graphql.decodeReserveId(n));return actions.setUserSuppliesAsCollateral(s,r).andThen(n=>e(n,{cancel:l})).andThen(n=>n.wait()).andThen(s.waitForTransaction).andTee(()=>Promise.all([...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserPositionsQuery,(c,R)=>c.request.user===r.sender&&R.some(d=>d.spoke.chain.chainId===n&&d.spoke.address===u))),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserPositionQuery,(c,R)=>R?.spoke.chain.chainId===n&&R?.spoke.address===u&&R.user===r.sender)),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.UserSummaryQuery,c=>c.request.user===r.sender&&graphql.isSpokeInputVariant(c.request.filter)?c.request.filter.spoke.chainId===n&&c.request.filter.spoke.address===u:graphql.isChainIdsVariant(c.request.filter)?c.request.filter.chainIds.some(R=>R===n):false)),s.refreshQueryWhere(graphql.ReservesQuery,(n,u)=>u.some(c=>t.includes(c.id))),...a.map(({chainId:n,spoke:u})=>s.refreshQueryWhere(graphql.SpokesQuery,(c,R)=>R.some(d=>d.chain.chainId===n&&d.address===u))),...a.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubsQuery,u=>graphql.isChainIdsVariant(u.request.query)?u.request.query.chainIds.some(c=>c===n):u.request.query.tokens.some(c=>c.chainId===n))),...a.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubQuery,u=>graphql.isHubInputVariant(u.request.query)?u.request.query.hubInput.chainId===n:graphql.decodeHubId(u.request.query.hubId).chainId===n))]))},[s,e])}function jt(e){let s=p();return i(r=>actions.liquidatePosition(s,r).andThen(t=>{switch(t.__typename){case "TransactionRequest":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(t,{cancel:l}).andThen(a=>a.wait()).andThen(()=>e(t.originalTransaction,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(t))}}),[s,e])}function $t(e){let s=p();return i(r=>actions.setSpokeUserPositionManager(s,r).andThen(t=>e(t,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,t=>t.request.spoke===r.spoke)),[s,e])}function Kt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.preview(s,r,{currency:e.currency}),[s,e.currency])}function zt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.PreviewQuery,variables:{request:t,currency:r},suspense:e,pause:s})}function Jt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.ActivitiesQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function Xt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.activities(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function na({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSuppliesQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ua(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userSupplies(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function oa({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserBorrowsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function pa(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userBorrows(s,r,{currency:e.currency??client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:e.timeWindow??client.DEFAULT_QUERY_OPTIONS.timeWindow}),[s,e.currency,e.timeWindow])}function ia({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserSummaryQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function la({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserPositionsQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function ca(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userPositions(s,r,{currency:e.currency,timeWindow:e.timeWindow}),[s,e.currency,e.timeWindow])}function ya({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:t=client.DEFAULT_QUERY_OPTIONS.timeWindow,...a}){return o({document:graphql.UserPositionQuery,variables:{request:a,currency:r,timeWindow:t},suspense:e,pause:s})}function da({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.UserBalancesQuery,variables:{request:t,currency:r},suspense:e,pause:s})}function Sa({suspense:e=false,pause:s=false,...r}){return o({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Ra(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userBalances(s,r,{currency:e.currency}),[s,e.currency])}function Ua({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...t}){return o({document:graphql.UserSummaryHistoryQuery,variables:{request:t,currency:r},suspense:e,pause:s,batch:false})}exports.AaveProvider=Ls;exports.CannotCancelSwapError=E;exports.useAaveClient=p;exports.useActivities=Jt;exports.useActivitiesAction=Xt;exports.useAsset=Br;exports.useAssetBorrowHistory=Or;exports.useAssetPriceHistory=Ir;exports.useAssetSupplyHistory=Wr;exports.useBorrow=Vt;exports.useBorrowApyHistory=Kr;exports.useBorrowSwap=wt;exports.useBorrowSwapQuote=mt;exports.useBorrowSwapQuoteAction=At;exports.useCancelSwap=vt;exports.useChain=Ar;exports.useChains=Pr;exports.useExchangeRate=Tr;exports.useExchangeRateAction=wr;exports.useHub=lr;exports.useHubAssets=yr;exports.useHubSummaryHistory=dr;exports.useHubs=cr;exports.useHubsAction=Sr;exports.useLiquidatePosition=jt;exports.usePermitTypedDataAction=Er;exports.usePreview=zt;exports.usePreviewAction=Kt;exports.useProtocolHistory=Dr;exports.useRenounceSpokeUserPositionManager=Lt;exports.useRepay=_t;exports.useRepayWithSupply=ht;exports.useRepayWithSupplyQuote=Tt;exports.useRepayWithSupplyQuoteAction=xt;exports.useReserve=Yr;exports.useReserveAction=Gr;exports.useReserves=jr;exports.useReservesAction=$r;exports.useSetSpokeUserPositionManager=$t;exports.useSetUserSuppliesAsCollateral=Gt;exports.useSpoke=et;exports.useSpokePositionManagers=rt;exports.useSpokeUserPositionManagers=tt;exports.useSpokes=st;exports.useSupply=Mt;exports.useSupplyApyHistory=zr;exports.useSupplySwap=Pt;exports.useSupplySwapQuote=ft;exports.useSupplySwapQuoteAction=bt;exports.useSwappableTokens=Ut;exports.useTokenSwap=qt;exports.useTokenSwapQuote=St;exports.useTokenSwapQuoteAction=Rt;exports.useUpdateUserPositionConditions=Yt;exports.useUserBalances=da;exports.useUserBalancesAction=Ra;exports.useUserBorrows=oa;exports.useUserBorrowsAction=pa;exports.useUserPosition=ya;exports.useUserPositions=la;exports.useUserPositionsAction=ca;exports.useUserRiskPremiumBreakdown=Sa;exports.useUserSummary=ia;exports.useUserSummaryHistory=Ua;exports.useUserSupplies=na;exports.useUserSuppliesAction=ua;exports.useUserSwaps=gt;exports.useWithdraw=Ft;exports.useWithdrawSwap=Et;exports.useWithdrawSwapQuote=kt;exports.useWithdrawSwapQuoteAction=Qt;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
|