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

feat: add stablecoins for a2a bridging #1373

Merged
merged 13 commits into from
Jan 15, 2025
14 changes: 12 additions & 2 deletions api/_dexes/cross-swap-service.ts
dohaki marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}

// @TODO: Implement the following function
export async function getCrossSwapQuotesForExactInput(crossSwap: CrossSwap) {

Check warning on line 82 in api/_dexes/cross-swap-service.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

'crossSwap' is defined but never used. Allowed unused args must match /^_/u
throw new Error("Not implemented yet");
}

Expand Down Expand Up @@ -376,7 +376,7 @@
strategies: QuoteFetchStrategies
) {
const preferredBridgeTokens = PREFERRED_BRIDGE_TOKENS;
const bridgeRoutesLimit = 1;
const bridgeRoutesLimit = 3;

const originSwapChainId = crossSwap.inputToken.chainId;
const destinationSwapChainId = crossSwap.outputToken.chainId;
Expand Down Expand Up @@ -409,7 +409,7 @@
);
}

const crossSwapQuotes = await Promise.all(
const crossSwapQuotesResults = await Promise.allSettled(
bridgeRoutesToCompare.map((bridgeRoute) =>
getCrossSwapQuotesForOutputByRouteA2A(
crossSwap,
Expand All @@ -420,6 +420,16 @@
)
);

const crossSwapQuotes = crossSwapQuotesResults
.filter((result) => result.status === "fulfilled")
.map((result) => result.value);

if (crossSwapQuotes.length === 0) {
throw new Error(
`Failed to get quote for ${originSwapChainId} ${crossSwap.inputToken.symbol} -> ${destinationSwapChainId} ${crossSwap.outputToken.symbol}`
);
}

// Compare quotes by lowest input amount
const bestCrossSwapQuote = crossSwapQuotes.reduce((prev, curr) =>
prev.originSwapQuote!.maximumAmountIn.lt(
Expand Down
2 changes: 1 addition & 1 deletion api/_dexes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const CROSS_SWAP_TYPE = {
ANY_TO_ANY: "anyToAny",
} as const;

export const PREFERRED_BRIDGE_TOKENS = ["WETH"];
export const PREFERRED_BRIDGE_TOKENS = ["WETH", "USDC", "USDT", "DAI"];

export const defaultQuoteFetchStrategy: QuoteFetchStrategy =
// This will be our default strategy until the periphery contract is audited
Expand Down
Loading