-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into chore/enable-zap-fee
- Loading branch information
Showing
62 changed files
with
2,995 additions
and
2,697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 27 additions & 5 deletions
32
apps/web/src/app/(networks)/(evm)/[chainId]/(trade)/cross-chain-swap/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import { Container } from '@sushiswap/ui' | ||
'use client' | ||
|
||
import { Container, classNames } from '@sushiswap/ui' | ||
import { useSidebar } from 'src/ui/sidebar' | ||
import { CrossChainSwapRouteSelector } from 'src/ui/swap/cross-chain/cross-chain-swap-route-selector' | ||
import { CrossChainSwapWidget } from 'src/ui/swap/cross-chain/cross-chain-swap-widget' | ||
import { useCrossChainTradeRoutes } from 'src/ui/swap/cross-chain/derivedstate-cross-chain-swap-provider' | ||
|
||
export default function CrossChainSwapPage() { | ||
const { isLoading, isFetched } = useCrossChainTradeRoutes() | ||
const { isOpen: isSidebarOpen } = useSidebar() | ||
|
||
const showRouteSelector = isLoading || isFetched | ||
|
||
export default async function CrossChainSwapPage() { | ||
return ( | ||
<Container maxWidth="lg" className="px-4"> | ||
<CrossChainSwapWidget /> | ||
</Container> | ||
<div | ||
className={classNames( | ||
'flex justify-center flex-wrap gap-y-4 h-full', | ||
showRouteSelector && isSidebarOpen ? 'lg:ml-56' : '', | ||
)} | ||
> | ||
<Container maxWidth="lg" className="px-4 !mx-[unset]"> | ||
<CrossChainSwapWidget /> | ||
</Container> | ||
{showRouteSelector ? ( | ||
<Container maxWidth="lg" className="px-4 !mx-[unset] flex items-center"> | ||
<CrossChainSwapRouteSelector /> | ||
</Container> | ||
) : null} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
apps/web/src/app/(networks)/(evm)/api/cross-chain/route.ts
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
apps/web/src/app/(networks)/(evm)/api/cross-chain/routes/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { NextRequest } from 'next/server' | ||
import { isXSwapSupportedChainId } from 'src/config' | ||
import { isAddress } from 'viem' | ||
import { z } from 'zod' | ||
|
||
const schema = z.object({ | ||
fromChainId: z.coerce | ||
.number() | ||
.refine((chainId) => isXSwapSupportedChainId(chainId), { | ||
message: `fromChainId must exist in XSwapChainId`, | ||
}), | ||
fromAmount: z.string(), | ||
fromTokenAddress: z.string().refine((token) => isAddress(token), { | ||
message: 'fromTokenAddress does not conform to Address', | ||
}), | ||
toChainId: z.coerce | ||
.number() | ||
.refine((chainId) => isXSwapSupportedChainId(chainId), { | ||
message: `toChainId must exist in XSwapChainId`, | ||
}), | ||
toTokenAddress: z.string().refine((token) => isAddress(token), { | ||
message: 'toTokenAddress does not conform to Address', | ||
}), | ||
fromAddress: z | ||
.string() | ||
.refine((address) => isAddress(address), { | ||
message: 'fromAddress does not conform to Address', | ||
}) | ||
.optional(), | ||
toAddress: z | ||
.string() | ||
.refine((address) => isAddress(address), { | ||
message: 'toAddress does not conform to Address', | ||
}) | ||
.optional(), | ||
slippage: z.coerce.number(), // decimal | ||
order: z.enum(['CHEAPEST', 'FASTEST']).optional(), | ||
}) | ||
|
||
export const revalidate = 20 | ||
|
||
export async function GET(request: NextRequest) { | ||
const params = Object.fromEntries(request.nextUrl.searchParams.entries()) | ||
|
||
const { slippage, order = 'CHEAPEST', ...parsedParams } = schema.parse(params) | ||
|
||
const url = new URL('https://li.quest/v1/advanced/routes') | ||
|
||
const options = { | ||
method: 'POST', | ||
headers: { | ||
accept: 'application/json', | ||
'content-type': 'application/json', | ||
...(process.env.LIFI_API_KEY && { | ||
'x-lifi-api-key': process.env.LIFI_API_KEY, | ||
}), | ||
}, | ||
body: JSON.stringify({ | ||
...parsedParams, | ||
options: { | ||
slippage, | ||
order, | ||
integrator: 'sushi', | ||
exchanges: { allow: ['sushiswap'] }, | ||
allowSwitchChain: false, | ||
allowDestinationCall: true, | ||
// fee: // TODO: must set up feeReceiver w/ lifi | ||
}, | ||
}), | ||
} | ||
|
||
const response = await fetch(url, options) | ||
|
||
return Response.json(await response.json(), { | ||
status: response.status, | ||
headers: { | ||
'Cache-Control': 's-maxage=15, stale-while-revalidate=20', | ||
}, | ||
}) | ||
} |
Oops, something went wrong.