Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart swap #269

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain-registry
Submodule chain-registry updated 159 files
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@sentry/nextjs": "^7.99.0",
"@skip-router/core": "^3.0.1",
"@skip-router/core": "4.0.0",
"@solana/spl-token": "^0.4.1",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-wallets": "^0.19.31",
Expand Down
2 changes: 1 addition & 1 deletion src/components/PreviewRoute/ChainStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export const ChainStep = ({
)}
</div>
<div className="flex flex-1 flex-col space-y-0">
{swapAction && signRequired && !isSource ? (
{swapAction && signRequired && (!isSource || (isSource && route.chainIDs.length === 1)) ? (
<AssetSwap
in={{
amount: swapAction.amountIn,
Expand Down
43 changes: 13 additions & 30 deletions src/components/PreviewRoute/make-actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BridgeType, RouteResponse, SwapVenue } from "@skip-router/core";
import { BridgeType, RouteResponse } from "@skip-router/core";

export interface TransferAction {
type: "TRANSFER";
Expand All @@ -19,7 +19,6 @@ export interface SwapAction {
denomIn: string;
denomOut: string;
chainID: string;
swapVenue: SwapVenue;
id: string;
signRequired: boolean;
amountIn: string;
Expand Down Expand Up @@ -48,34 +47,18 @@ export const makeActions = ({ route }: { route: RouteResponse }): Action[] => {
})();

if ("swap" in operation) {
if ("swapIn" in operation.swap) {
_actions.push({
type: "SWAP",
denomIn: operation.swap.denomIn,
denomOut: operation.swap.denomOut,
chainID: operation.swap.chainID,
id: `swap-${swapCount}-${transferCount}-${i}`,
swapVenue: operation.swap.swapIn.swapVenue,
signRequired,
amountIn: operation.amountIn,
amountOut: operation.amountOut,
txIndex: operation.txIndex,
});
}
if ("swapOut" in operation.swap) {
_actions.push({
type: "SWAP",
denomIn: operation.swap.denomIn,
denomOut: operation.swap.denomOut,
chainID: operation.swap.chainID,
id: `swap-${swapCount}-${transferCount}-${i}`,
swapVenue: operation.swap.swapOut.swapVenue,
signRequired,
amountIn: operation.amountIn,
amountOut: operation.amountOut,
txIndex: operation.txIndex,
});
}
_actions.push({
type: "SWAP",
denomIn: operation.swap.denomIn,
denomOut: operation.swap.denomOut,
chainID: operation.swap.chainID,
id: `swap-${swapCount}-${transferCount}-${i}`,
signRequired,
amountIn: operation.amountIn,
amountOut: operation.amountOut,
txIndex: operation.txIndex,
});

swapCount++;
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/solve/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export function useRoute({
allowUnsafe: true,
experimentalFeatures,
smartRelay: true,
smartSwapOptions: {
splitRoutes: true,
},
}
: {
amountOut: amount,
Expand All @@ -145,6 +148,9 @@ export function useRoute({
allowUnsafe: true,
experimentalFeatures,
smartRelay: true,
smartSwapOptions: {
splitRoutes: true,
},
},
);

Expand Down
Loading