Skip to content

Commit 4c076bd

Browse files
committed
feat: implements useBorrowSwapQuote
1 parent 60ca113 commit 4c076bd

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

.changeset/spotty-ideas-brake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aave/graphql": patch
3+
"@aave/react": patch
4+
---
5+
6+
**feat:** new `useBorrowSwapQuote` hook.

packages/graphql/src/fragments/swaps.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ export const PrepareSupplySwapResultFragment: FragmentDocumentFor<
451451
[PositionSwapByIntentApprovalsRequiredFragment],
452452
);
453453

454+
export type PrepareBorrowSwapResult = PositionSwapByIntentApprovalsRequired;
455+
456+
export const PrepareBorrowSwapResultFragment: FragmentDocumentFor<
457+
PrepareBorrowSwapResult,
458+
'PrepareBorrowSwapResult'
459+
> = graphql(
460+
`fragment PrepareBorrowSwapResult on PrepareBorrowSwapResult {
461+
__typename
462+
... on PositionSwapByIntentApprovalsRequired {
463+
...PositionSwapByIntentApprovalsRequired
464+
}
465+
}`,
466+
[PositionSwapByIntentApprovalsRequiredFragment],
467+
);
468+
454469
export type PreparePositionSwapResult = SwapByIntent;
455470

456471
export const PreparePositionSwapResultFragment: FragmentDocumentFor<

packages/graphql/src/swaps.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CancelSwapExecutionPlanFragment,
33
PaginatedUserSwapsResultFragment,
4+
PrepareBorrowSwapResultFragment,
45
PreparePositionSwapResultFragment,
56
PrepareSupplySwapResultFragment,
67
PrepareSwapCancelResultFragment,
@@ -129,6 +130,19 @@ export const SupplySwapQuoteQuery = graphql(
129130
);
130131
export type PrepareSupplySwapRequest = RequestOf<typeof SupplySwapQuoteQuery>;
131132

133+
/**
134+
* @internal
135+
*/
136+
export const BorrowSwapQuoteQuery = graphql(
137+
`query BorrowSwapQuote($request: PrepareBorrowSwapRequest!, $currency: Currency!) {
138+
value: borrowSwapQuote(request: $request) {
139+
...PrepareBorrowSwapResult
140+
}
141+
}`,
142+
[PrepareBorrowSwapResultFragment],
143+
);
144+
export type PrepareBorrowSwapRequest = RequestOf<typeof BorrowSwapQuoteQuery>;
145+
132146
/**
133147
* @internal
134148
*/

packages/react/src/swap.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ import type {
3636
UserSwapsRequest,
3737
} from '@aave/graphql';
3838
import {
39+
BorrowSwapQuoteQuery,
3940
type ERC20PermitSignature,
4041
type PositionSwapByIntentApprovalsRequired,
42+
type PrepareBorrowSwapRequest,
4143
type PreparePositionSwapRequest,
4244
type PrepareTokenSwapRequest,
4345
SupplySwapQuoteQuery,
@@ -512,6 +514,116 @@ export function useSupplySwapQuote({
512514

513515
// ------------------------------------------------------------
514516

517+
export type UseBorrowSwapQuoteArgs = Prettify<
518+
PrepareBorrowSwapRequest & CurrencyQueryOptions
519+
>;
520+
521+
/**
522+
* @experimental
523+
* Fetch a quote for a borrow swap operation with the specified parameters.
524+
*
525+
* This signature supports React Suspense:
526+
*
527+
* ```tsx
528+
* const { data } = useBorrowSwapQuote({
529+
* market: {
530+
* sellPosition: userBorrowItem.id,
531+
* buyReserve: reserve.id,
532+
* amount: bigDecimal('1000'),
533+
* user: evmAddress('0x742d35cc…'),
534+
* },
535+
* suspense: true,
536+
* });
537+
* ```
538+
*/
539+
export function useBorrowSwapQuote(
540+
args: UseBorrowSwapQuoteArgs & Suspendable,
541+
): SuspenseResult<SwapQuote>;
542+
/**
543+
* @experimental
544+
* Fetch a quote for a borrow swap operation with the specified parameters.
545+
*
546+
* Pausable suspense mode.
547+
*
548+
* ```tsx
549+
* const { data } = useBorrowSwapQuote({
550+
* market: {
551+
* sellPosition: userBorrowItem.id,
552+
* buyReserve: reserve.id,
553+
* amount: bigDecimal('1000'),
554+
* user: evmAddress('0x742d35cc…'),
555+
* },
556+
* suspense: true,
557+
* pause: true,
558+
* });
559+
* ```
560+
*/
561+
export function useBorrowSwapQuote(
562+
args: Pausable<UseBorrowSwapQuoteArgs> & Suspendable,
563+
): PausableSuspenseResult<SwapQuote>;
564+
/**
565+
* @experimental
566+
* Fetch a quote for a borrow swap operation with the specified parameters.
567+
*
568+
* ```tsx
569+
* const { data, error, loading } = useBorrowSwapQuote({
570+
* market: {
571+
* sellPosition: userBorrowItem.id,
572+
* buyReserve: reserve.id,
573+
* amount: bigDecimal('1000'),
574+
* user: evmAddress('0x742d35cc…'),
575+
* },
576+
* });
577+
* ```
578+
*/
579+
export function useBorrowSwapQuote(
580+
args: UseBorrowSwapQuoteArgs,
581+
): ReadResult<SwapQuote>;
582+
/**
583+
* @experimental
584+
* Fetch a quote for a borrow swap operation with the specified parameters.
585+
*
586+
* Pausable loading state mode.
587+
*
588+
* ```tsx
589+
* const { data, error, loading, paused } = useBorrowSwapQuote({
590+
* market: {
591+
* sellPosition: userBorrowItem.id,
592+
* buyReserve: reserve.id,
593+
* amount: bigDecimal('1000'),
594+
* user: evmAddress('0x742d35cc…'),
595+
* },
596+
* pause: true,
597+
* });
598+
* ```
599+
*/
600+
export function useBorrowSwapQuote(
601+
args: Pausable<UseBorrowSwapQuoteArgs>,
602+
): PausableReadResult<SwapQuote>;
603+
604+
export function useBorrowSwapQuote({
605+
suspense = false,
606+
pause = false,
607+
currency = DEFAULT_QUERY_OPTIONS.currency,
608+
...request
609+
}: NullishDeep<UseBorrowSwapQuoteArgs> & {
610+
suspense?: boolean;
611+
pause?: boolean;
612+
}): SuspendableResult<SwapQuote, UnexpectedError> {
613+
return useSuspendableQuery({
614+
document: BorrowSwapQuoteQuery,
615+
variables: {
616+
request,
617+
currency,
618+
},
619+
selector: (data) => data.quote,
620+
suspense,
621+
pause,
622+
});
623+
}
624+
625+
// ------------------------------------------------------------
626+
515627
export type SwapHandlerOptions = {
516628
cancel: CancelOperation;
517629
};

0 commit comments

Comments
 (0)