Skip to content

Commit

Permalink
add swaptype to response (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns authored Feb 22, 2024
1 parent 7aa3fd5 commit 78bf304
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/sor/sor.gql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type GqlSorGetSwapPaths {
The token address of the tokenOut provided
"""
tokenOut: String!
swapType: GqlSorSwapType!
swaps: [GqlSorSwap!]! #used by cowswap
paths: [GqlSorPath!]! #used by b-sdk
tokenInAmount: AmountHumanReadable!
Expand Down
5 changes: 5 additions & 0 deletions modules/sor/sorV2/sorV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export class SorV2Service implements SwapService {
return {
vaultVersion: 2,
paths: paths,
swapType: this.mapSwapKindToSwapType(swap.swapKind),
swaps: this.mapSwaps(swap.swaps, swap.assets),
tokenIn: replaceZeroAddressWithEth(inputAmount.token.address),
tokenOut: replaceZeroAddressWithEth(outputAmount.token.address),
Expand All @@ -227,6 +228,10 @@ export class SorV2Service implements SwapService {
return swapType === 'EXACT_IN' ? SwapKind.GivenIn : SwapKind.GivenOut;
}

private mapSwapKindToSwapType(swapKind: SwapKind): GqlSorSwapType {
return swapKind === SwapKind.GivenIn ? 'EXACT_IN' : 'EXACT_OUT';
}

private mapSwaps(swaps: BatchSwapStep[] | SingleSwap, assets: string[]): GqlSorSwap[] {
if (Array.isArray(swaps)) {
return swaps.map((swap) => {
Expand Down
1 change: 1 addition & 0 deletions modules/sor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const swapPathsZeroResponse = (tokenIn: string, tokenOut: string): GqlSor
return {
swaps: [],
paths: [],
swapType: 'EXACT_IN',
vaultVersion: 2,
tokenIn: replaceZeroAddressWithEth(tokenIn),
tokenOut: replaceZeroAddressWithEth(tokenOut),
Expand Down

0 comments on commit 78bf304

Please sign in to comment.