@aave/react 4.0.0-next.16 → 4.0.0-next.17
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 +110 -2
- package/dist/index.d.ts +110 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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 u({document:e,variables:s,suspense:r,pause:a,selector:t=types.identity,pollInterval:n=0,batch:o=true}){let[c,R]=O.useState(true),[{fetching:d,data:f,error:E},M]=urql.useQuery({query:e,variables:s,pause:a,context:O.useMemo(()=>({batch:o,suspense:r}),[o,r])});if(O.useEffect(()=>{a||d||R(false);},[d,a]),O.useEffect(()=>{if(n<=0||d||a)return;let v=setTimeout(()=>{M({requestPolicy:"network-only",batch:false});},n);return ()=>clearTimeout(v)},[d,M,n,a]),a)return T.Paused(f?t(f.value):void 0,E?client.UnexpectedError.from(E):void 0);if(!r&&c)return T.Loading();if(E){let v=client.UnexpectedError.from(E);if(r)throw v;return T.Failure(v)}return types.invariant(f,"No data returned"),T.Success(t(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,a]=O.useState(_.Idle()),t=O.useRef(false),n=O.useCallback(e,s);return [O.useCallback(c=>{types.invariant(!t.current,"Cannot execute a task while another is in progress."),t.current=true;let R;a(d=>(R=d,{called:true,loading:true,data:d.data,error:void 0}));try{let d=n(c);return d.match(f=>{t.current=!1,a(_.Success(f));},f=>{t.current=!1,a(_.Failed(f));}),d}catch(d){throw t.current=false,a(types.nonNullable(R)),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:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.HubQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function yr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.HubsQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function dr({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.HubAssetsQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function Sr({suspense:e=false,pause:s=false,...r}){return u({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 u({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 u({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 a=p();return u({document:graphql.ExchangeRateQuery,variables:{request:r},suspense:e,pause:s,pollInterval:r.at?0:a.context.environment.exchangeRateInterval})}function Qr(){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:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.AssetQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function Wr({suspense:e=false,pause:s=false,...r}){return u({document:graphql.AssetPriceHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Or({suspense:e=false,pause:s=false,...r}){return u({document:graphql.AssetSupplyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function _r({suspense:e=false,pause:s=false,...r}){return u({document:graphql.AssetBorrowHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Dr({suspense:e=false,pause:s=false,...r}){return u({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:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.ReserveQuery,variables:{request:t,currency:r,timeWindow:a},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:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,selector:t,...n}){return u({document:graphql.ReservesQuery,variables:{request:n,currency:r,timeWindow:a},suspense:e,pause:s,selector:t||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 u({document:graphql.BorrowApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function Jr({suspense:e=false,pause:s=false,...r}){return u({document:graphql.SupplyApyHistoryQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function st({suspense:e=false,pause:s=false,...r}){return u({document:graphql.SpokeQuery,variables:{request:r},suspense:e,pause:s})}function rt({suspense:e=false,pause:s=false,...r}){return u({document:graphql.SpokesQuery,variables:{request:r},suspense:e,pause:s})}function tt({suspense:e=false,pause:s=false,...r}){return u({document:graphql.SpokePositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function at({suspense:e=false,pause:s=false,...r}){return u({document:graphql.SpokeUserPositionManagersQuery,variables:{request:r},suspense:e,pause:s})}function Z(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,...a}){return u({document:graphql.TokenSwapQuoteQuery,variables:{request:{market:a},currency:r},selector:Z,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(Z),[s,e.currency])}function gt({suspense:e=false,pause:s=false,...r}){return u({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:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserSwapsQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function ft({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.SupplySwapQuoteQuery,variables:{request:a,currency:r},selector:t=>t.quote,suspense:e,pause:s})}function bt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.BorrowSwapQuoteQuery,variables:{request:a,currency:r},selector:t=>t.quote,suspense:e,pause:s})}function B(e){return {with:s=>e.approvals.reduce((r,a)=>r.andThen(t=>s(a,{cancel:l}).map(n=>{switch(a.__typename){case "PositionSwapAdapterContractApproval":t.adapterContractSignature=types.isSignature(n)?n:null;break;case "PositionSwapPositionManagerApproval":t.positionManagerSignature=types.isSignature(n)?n:null;break}return t})),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 At(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.supplySwapQuote(s,a,{currency:r}).andThen(t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),B(t).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(o=>(types.invariant(o.__typename==="SwapByIntent",`Unsupported swap plan: ${o.__typename}. Upgrade to a newer version of the @aave/react package.`),o))).andThen(n=>e(n,{cancel:l}).map(o=>(types.invariant(types.isSignature(o),"Expected signature, got an object instead."),o))).andThen(n=>C(s,{quoteId:t.quote.quoteId,signature:n})))),[s,e])}function wt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.borrowSwapQuote(s,a,{currency:r}).andThen(t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),B(t).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(o=>(types.invariant(o.__typename==="SwapByIntent",`Unsupported swap plan: ${o.__typename}. Upgrade to a newer version of the @aave/react package.`),o))).andThen(n=>e(n,{cancel:l}).map(o=>(types.invariant(types.isSignature(o),"Expected signature, got an object instead."),o))).andThen(n=>C(s,{quoteId:t.quote.quoteId,signature:n})))),[s,e])}function Pt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.RepayWithSupplyQuoteQuery,variables:{request:a,currency:r},selector:t=>t.quote,suspense:e,pause:s})}function Tt(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.repayWithSupplyQuote(s,a,{currency:r}).andThen(t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),B(t).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(o=>(types.invariant(o.__typename==="SwapByIntent",`Unsupported swap plan: ${o.__typename}. Upgrade to a newer version of the @aave/react package.`),o))).andThen(n=>e(n,{cancel:l}).map(o=>(types.invariant(types.isSignature(o),"Expected signature, got an object instead."),o))).andThen(n=>C(s,{quoteId:t.quote.quoteId,signature:n})))),[s,e])}function xt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.WithdrawSwapQuoteQuery,variables:{request:a,currency:r},selector:t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),t.quote),suspense:e,pause:s})}function ht(e){let s=p();return i(({currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a})=>actions.withdrawSwapQuote(s,a,{currency:r}).andThen(t=>(types.invariant(t.__typename==="PositionSwapByIntentApprovalsRequired",`Unsupported swap plan: ${t.__typename}. Upgrade to a newer version of the @aave/react package.`),B(t).with(e).andThen(n=>actions.preparePositionSwap(s,n,{currency:r}).map(o=>(types.invariant(o.__typename==="SwapByIntent",`Unsupported swap plan: ${o.__typename}. Upgrade to a newer version of the @aave/react package.`),o))).andThen(n=>e(n,{cancel:l}).map(o=>(types.invariant(types.isSignature(o),"Expected signature, got an object instead."),o))).andThen(n=>C(s,{quoteId:t.quote.quoteId,signature:n})))),[s,e])}function kt(e){let s=p(),r=O.useCallback(a=>{switch(a.__typename){case "SwapTransactionRequest":return e(a,{cancel:l}).map(P.ensure).andThen(t=>t.wait()).andThen(()=>types.okAsync(a.orderReceipt));case "InsufficientBalanceError":return client.ValidationError.fromGqlNode(a).asResultAsync();case "SwapReceipt":return types.okAsync(a);default:return new core.UnexpectedError(`Unsupported swap plan: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}},[e]);return i(({currency:a=client.DEFAULT_QUERY_OPTIONS.currency,...t})=>actions.tokenSwapQuote(s,t,{currency:a}).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(o=>(types.invariant(types.isSignature(o),"Invalid signature"),o)).andThen(o=>actions.swap(s,{intent:{quoteId:n.quote.quoteId,signature:o}})).andThen(r);case "SwapByIntentWithApprovalRequired":return e(n.approval,{cancel:l}).andThen(o=>graphql.isERC20PermitSignature(o)?actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId,permitSig:o.value}):P.isInstanceOf(o)?o.wait().andThen(()=>actions.prepareTokenSwap(s,{quoteId:n.quote.quoteId})):core.UnexpectedError.from(o).asResultAsync()).andThen(o=>{switch(o.__typename){case "SwapByIntent":return e(o.data,{cancel:l});case "InsufficientBalanceError":return client.ValidationError.fromGqlNode(o).asResultAsync();default:return new core.UnexpectedError(`Unsupported swap plan: ${o.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}}).map(o=>(types.invariant(types.isSignature(o),"Invalid signature"),o)).andThen(o=>actions.swap(s,{intent:{quoteId:n.quote.quoteId,signature:o}})).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 Et(e){let s=p();return i(r=>actions.swapStatus(s,{id:r.id}).andThen(a=>{switch(a.__typename){case "SwapOpen":case "SwapPendingSignature":return actions.prepareSwapCancel(s,r).andThen(t=>e(t.data,{cancel:l})).map(t=>(types.invariant(types.isSignature(t),"Invalid signature"),t)).andThen(t=>actions.cancelSwap(s,{intent:{id:r.id,signature:t}})).andThen(t=>t.__typename==="SwapCancelled"?types.okAsync(t):e(t,{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(a);case "SwapExpired":return new q("Swap cannot longer be cancelled").asResultAsync();default:return new core.UnexpectedError(`Unsupported swap status: ${a.__typename}. Upgrade to a newer version of the @aave/react package.`).asResultAsync()}}),[s,e])}function W(e,s){let{chainId:r,spoke:a}=graphql.decodeReserveId(s.reserve);return async()=>Promise.all([await e.refreshQueryWhere(graphql.UserPositionsQuery,(t,n)=>t.request.user===s.sender&&n.some(o=>o.spoke.chain.chainId===r&&o.spoke.address===a)),await e.refreshQueryWhere(graphql.UserPositionQuery,(t,n)=>n?.spoke.chain.chainId===r&&n?.spoke.address===a&&n.user===s.sender),await e.refreshQueryWhere(graphql.UserSummaryQuery,t=>t.request.user===s.sender&&graphql.isSpokeInputVariant(t.request.filter)?t.request.filter.spoke.chainId===r&&t.request.filter.spoke.address===a:graphql.isChainIdsVariant(t.request.filter)?t.request.filter.chainIds.some(n=>n===r):false),await e.refreshQueryWhere(graphql.ReservesQuery,(t,n)=>n.some(o=>o.id===s.reserve)),await e.refreshQueryWhere(graphql.SpokesQuery,(t,n)=>n.some(o=>o.chain.chainId===r&&o.address===a)),await e.refreshQueryWhere(graphql.UserBalancesQuery,t=>t.request.user===s.sender),await e.refreshQueryWhere(graphql.HubsQuery,t=>graphql.isChainIdsVariant(t.request)&&t.request.chainIds.some(n=>n===r))])}function Ot(e){let s=p();return i(r=>actions.supply(s,r).andThen(a=>{switch(a.__typename){case "TransactionRequest":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(()=>e(a.originalTransaction,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(a))}}).andTee(W(s,r)),[s,e])}function _t(e){let s=p();return i(r=>actions.borrow(s,r).andThen(a=>{switch(a.__typename){case "TransactionRequest":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(()=>e(a.originalTransaction,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(a))}}).andTee(W(s,r)),[s,e])}function Dt(e){let s=p();return i(r=>actions.repay(s,r).andThen(a=>{switch(a.__typename){case "TransactionRequest":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(()=>e(a.originalTransaction,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(a))}}).andTee(W(s,r)),[s,e])}function Nt(e){let s=p();return i(r=>actions.withdraw(s,r).andThen(a=>{switch(a.__typename){case "TransactionRequest":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(()=>e(a.originalTransaction,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(a))}}).andTee(W(s,r)),[s,e])}function Mt(e){let s=p();return i(r=>actions.renounceSpokeUserPositionManager(s,r).andThen(a=>e(a,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,a=>a.request.spoke===r.spoke)),[s,e])}function Vt(e){let s=p();return i(r=>actions.updateUserPositionConditions(s,r).andThen(a=>e(a,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction).andTee(async()=>{let{userPositionId:a}=r;return Promise.all([s.refreshQueryWhere(graphql.UserPositionsQuery,(t,n)=>n.some(o=>o.id===a)),s.refreshQueryWhere(graphql.UserPositionQuery,(t,n)=>n?.id===a)])}),[s,e])}function Ft(e){let s=p();return i(r=>{let a=r.changes.map(n=>n.reserve),t=a.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([...t.map(({chainId:n,spoke:o})=>s.refreshQueryWhere(graphql.UserPositionsQuery,(c,R)=>c.request.user===r.sender&&R.some(d=>d.spoke.chain.chainId===n&&d.spoke.address===o))),...t.map(({chainId:n,spoke:o})=>s.refreshQueryWhere(graphql.UserPositionQuery,(c,R)=>R?.spoke.chain.chainId===n&&R?.spoke.address===o&&R.user===r.sender)),...t.map(({chainId:n,spoke:o})=>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===o:graphql.isChainIdsVariant(c.request.filter)?c.request.filter.chainIds.some(R=>R===n):false)),s.refreshQueryWhere(graphql.ReservesQuery,(n,o)=>o.some(c=>a.includes(c.id))),...t.map(({chainId:n,spoke:o})=>s.refreshQueryWhere(graphql.SpokesQuery,(c,R)=>R.some(d=>d.chain.chainId===n&&d.address===o))),...t.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubsQuery,o=>graphql.isChainIdsVariant(o.request.query)?o.request.query.chainIds.some(c=>c===n):o.request.query.tokens.some(c=>c.chainId===n))),...t.map(({chainId:n})=>s.refreshQueryWhere(graphql.HubQuery,o=>graphql.isHubInputVariant(o.request.query)?o.request.query.hubInput.chainId===n:graphql.decodeHubId(o.request.query.hubId).chainId===n))]))},[s,e])}function Lt(e){let s=p();return i(r=>actions.liquidatePosition(s,r).andThen(a=>{switch(a.__typename){case "TransactionRequest":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "Erc20ApprovalRequired":case "PreContractActionRequired":return e(a,{cancel:l}).andThen(t=>t.wait()).andThen(()=>e(a.originalTransaction,{cancel:l})).andThen(t=>t.wait()).andThen(s.waitForTransaction);case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(a))}}),[s,e])}function $t(e){let s=p();return i(r=>actions.setSpokeUserPositionManager(s,r).andThen(a=>e(a,{cancel:l})).andThen(a=>a.wait()).andThen(s.waitForTransaction).andTee(()=>s.refreshQueryWhere(graphql.SpokePositionManagersQuery,a=>a.request.spoke===r.spoke)),[s,e])}function Gt(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.preview(s,r,{currency:e.currency}),[s,e.currency])}function Yt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.PreviewQuery,variables:{request:a,currency:r},suspense:e,pause:s})}function jt({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.ActivitiesQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function Kt(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 ra({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserSuppliesQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function ta(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 aa({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserBorrowsQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function na(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 oa({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserSummaryQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function ua({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserPositionsQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function pa(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 ia({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,timeWindow:a=client.DEFAULT_QUERY_OPTIONS.timeWindow,...t}){return u({document:graphql.UserPositionQuery,variables:{request:t,currency:r,timeWindow:a},suspense:e,pause:s})}function la({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.UserBalancesQuery,variables:{request:a,currency:r},suspense:e,pause:s})}function ca({suspense:e=false,pause:s=false,...r}){return u({document:graphql.UserRiskPremiumBreakdownQuery,variables:{request:r},suspense:e,pause:s,batch:false})}function ya(e=client.DEFAULT_QUERY_OPTIONS){let s=p();return i(r=>actions.userBalances(s,r,{currency:e.currency}),[s,e.currency])}function da({suspense:e=false,pause:s=false,currency:r=client.DEFAULT_QUERY_OPTIONS.currency,...a}){return u({document:graphql.UserSummaryHistoryQuery,variables:{request:a,currency:r},suspense:e,pause:s,batch:false})}exports.AaveProvider=$s;exports.CannotCancelSwapError=q;exports.useAaveClient=p;exports.useActivities=jt;exports.useActivitiesAction=Kt;exports.useAsset=Ir;exports.useAssetBorrowHistory=_r;exports.useAssetPriceHistory=Wr;exports.useAssetSupplyHistory=Or;exports.useBorrow=_t;exports.useBorrowApyHistory=zr;exports.useBorrowSwap=wt;exports.useBorrowSwapQuote=bt;exports.useCancelSwap=Et;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=Lt;exports.usePermitTypedDataAction=Qr;exports.usePreview=Yt;exports.usePreviewAction=Gt;exports.useProtocolHistory=Dr;exports.useRenounceSpokeUserPositionManager=Mt;exports.useRepay=Dt;exports.useRepayWithSupply=Tt;exports.useRepayWithSupplyQuote=Pt;exports.useReserve=Gr;exports.useReserveAction=Yr;exports.useReserves=jr;exports.useReservesAction=Kr;exports.useSetSpokeUserPositionManager=$t;exports.useSetUserSuppliesAsCollateral=Ft;exports.useSpoke=st;exports.useSpokePositionManagers=tt;exports.useSpokeUserPositionManagers=at;exports.useSpokes=rt;exports.useSupply=Ot;exports.useSupplyApyHistory=Jr;exports.useSupplySwap=At;exports.useSupplySwapQuote=ft;exports.useSwappableTokens=gt;exports.useTokenSwap=kt;exports.useTokenSwapQuote=Rt;exports.useTokenSwapQuoteAction=Ut;exports.useUpdateUserPositionConditions=Vt;exports.useUserBalances=la;exports.useUserBalancesAction=ya;exports.useUserBorrows=aa;exports.useUserBorrowsAction=na;exports.useUserPosition=ia;exports.useUserPositions=ua;exports.useUserPositionsAction=pa;exports.useUserRiskPremiumBreakdown=ca;exports.useUserSummary=oa;exports.useUserSummaryHistory=da;exports.useUserSupplies=ra;exports.useUserSuppliesAction=ta;exports.useUserSwaps=mt;exports.useWithdraw=Nt;exports.useWithdrawSwap=ht;exports.useWithdrawSwapQuote=xt;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'),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
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|