Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dohaki committed Nov 8, 2024
1 parent fd1bc01 commit 943877c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 48 deletions.
25 changes: 8 additions & 17 deletions api/_dexes/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Token as AcrossToken,
Swap,
} from "./types";
import { getSwapAndBridgeAddress } from "./utils";
import { getSwapAndBridgeAddress, NoSwapRouteError } from "./utils";

// Maps testnet chain IDs to their main counterparts. Used to get the mainnet token
// info for testnet tokens.
Expand Down Expand Up @@ -44,7 +44,8 @@ export async function getUniswapQuoteForOriginSwapExactInput(
});

if (!route.methodParameters) {
throw new NoUniswapRouteError({
throw new NoSwapRouteError({
dex: "uniswap",
tokenInSymbol: swap.tokenIn.symbol,
tokenOutSymbol: swap.tokenOut.symbol,
chainId: swap.chainId,
Expand Down Expand Up @@ -85,6 +86,9 @@ export async function getUniswapQuote(swap: Swap) {
const quoteCurrency =
swap.type === "EXACT_INPUT" ? swap.tokenOut : swap.tokenIn;

console.log("amountCurrency", amountCurrency);
console.log("quoteCurrency", quoteCurrency);

const route = await router.route(
CurrencyAmount.fromRawAmount(
new Token(
Expand All @@ -106,7 +110,8 @@ export async function getUniswapQuote(swap: Swap) {
);

if (!route || !route.methodParameters) {
throw new NoUniswapRouteError({
throw new NoSwapRouteError({
dex: "uniswap",
tokenInSymbol: swap.tokenIn.symbol,
tokenOutSymbol: swap.tokenOut.symbol,
chainId: swap.chainId,
Expand Down Expand Up @@ -162,17 +167,3 @@ function getMainnetToken(token: AcrossToken) {
address: mainnetTokenAddress,
};
}

class NoUniswapRouteError extends Error {
constructor(args: {
tokenInSymbol: string;
tokenOutSymbol: string;
chainId: number;
swapType: string;
}) {
super(
`No Uniswap swap route found for '${args.swapType}' ${args.tokenInSymbol} to ${args.tokenOutSymbol} on chain ${args.chainId}`
);
this.name = "NoSwapRouteError";
}
}
26 changes: 25 additions & 1 deletion api/_dexes/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ENABLED_ROUTES } from "../_utils";
import { ENABLED_ROUTES, getTokenByAddress } from "../_utils";

Check warning on line 1 in api/_dexes/utils.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

'getTokenByAddress' is defined but never used

export class UnsupportedDex extends Error {
constructor(dex: string) {
Expand All @@ -12,6 +12,20 @@ export class UnsupportedDexOnChain extends Error {
}
}

export class NoSwapRouteError extends Error {
constructor(args: {
dex: string;
tokenInSymbol: string;
tokenOutSymbol: string;
chainId: number;
swapType: string;
}) {
super(
`No ${args.dex} swap route found for '${args.swapType}' ${args.tokenInSymbol} to ${args.tokenOutSymbol} on chain ${args.chainId}`
);
}
}

export const swapAndBridgeDexes = Object.keys(
ENABLED_ROUTES.swapAndBridgeAddresses
);
Expand All @@ -30,6 +44,16 @@ export function getSwapAndBridgeAddress(dex: string, chainId: number) {
return address;
}

export function getAcrossSwapType(params: {

Check warning on line 47 in api/_dexes/utils.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

'params' is defined but never used. Allowed unused args must match /^_/u
inputToken: string;
originChainId: number;
outputToken: string;
destinationChainId: number;
}) {
// TODO: Implement this function
return "majorToMajor";
}

function _isDexSupported(
dex: string
): dex is keyof typeof ENABLED_ROUTES.swapAndBridgeAddresses {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@sentry/react": "^7.37.2",
"@tanstack/react-query": "v4",
"@tanstack/react-query-devtools": "v4",
"@uniswap/sdk-core": "^4.2.0",
"@uniswap/sdk-core": "^5.9.0",
"@uniswap/smart-order-router": "^4.7.8",
"@uniswap/v3-sdk": "^3.11.0",
"@uniswap/v3-sdk": "^3.18.1",
"@vercel/kv": "^2.0.0",
"@web3-onboard/coinbase": "^2.4.1",
"@web3-onboard/core": "^2.21.2",
Expand Down
30 changes: 2 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@
"@ethersproject/properties" "^5.5.0"
"@ethersproject/strings" "^5.5.0"

"@ethersproject/[email protected]", "@ethersproject/abi@^5.0.12", "@ethersproject/abi@^5.1.2", "@ethersproject/abi@^5.4.0", "@ethersproject/abi@^5.5.0", "@ethersproject/abi@^5.6.3", "@ethersproject/abi@^5.7.0":
"@ethersproject/[email protected]", "@ethersproject/abi@^5.1.2", "@ethersproject/abi@^5.4.0", "@ethersproject/abi@^5.5.0", "@ethersproject/abi@^5.6.3", "@ethersproject/abi@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.7.0.tgz#b3f3e045bbbeed1af3947335c247ad625a44e449"
integrity sha512-351ktp42TiRcYB3H1OP8yajPeAQstMW/yCFokj/AthP9bLHzQFPlOrxOcwYEDkUAICmOHljvN4K39OMTMUa9RA==
Expand Down Expand Up @@ -7415,18 +7415,6 @@
"@uniswap/v3-sdk" "^3.17.0"
"@uniswap/v4-sdk" "^1.10.3"

"@uniswap/sdk-core@^4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-4.2.0.tgz#9930f133baec9c1118d891ebf8fcba7f7efc153d"
integrity sha512-yXAMLHZRYYuh6KpN2nOlLTYBjGiopmI9WUB4Z0tyNkW4ZZub54cUt22eibpGbZAhRAMxclox9IPIs6wwrM3soQ==
dependencies:
"@ethersproject/address" "^5.0.2"
big.js "^5.2.2"
decimal.js-light "^2.5.0"
jsbi "^3.1.4"
tiny-invariant "^1.1.0"
toformat "^2.0.0"

"@uniswap/sdk-core@^5.0.0", "@uniswap/sdk-core@^5.3.1", "@uniswap/sdk-core@^5.8.0", "@uniswap/sdk-core@^5.8.1", "@uniswap/sdk-core@^5.8.2", "@uniswap/sdk-core@^5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-5.9.0.tgz#8f1edf4d0e94b314f4394fa5abe0bf5fc9c5a79a"
Expand Down Expand Up @@ -7474,7 +7462,7 @@
node-cache "^5.1.2"
stats-lite "^2.2.0"

"@uniswap/swap-router-contracts@^1.2.1", "@uniswap/swap-router-contracts@^1.3.0", "@uniswap/swap-router-contracts@^1.3.1":
"@uniswap/swap-router-contracts@^1.3.0", "@uniswap/swap-router-contracts@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@uniswap/swap-router-contracts/-/swap-router-contracts-1.3.1.tgz#0ebbb93eb578625618ed9489872de381f9c66fb4"
integrity sha512-mh/YNbwKb7Mut96VuEtL+Z5bRe0xVIbjjiryn+iMMrK2sFKhR4duk/86mEz0UO5gSx4pQIw9G5276P5heY/7Rg==
Expand Down Expand Up @@ -7591,20 +7579,6 @@
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"

"@uniswap/v3-sdk@^3.11.0":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-3.11.0.tgz#328309fbafddd8c618b7b6850bb99cacf6733a79"
integrity sha512-gz6Q6SlN34AXvxhyz181F90D4OuIkxLnzBAucEzB9Fv3Z+3orHZY/SpGaD02nP1VsNQVu/DQvOsdkPUDGn1Y9Q==
dependencies:
"@ethersproject/abi" "^5.0.12"
"@ethersproject/solidity" "^5.0.9"
"@uniswap/sdk-core" "^4.2.0"
"@uniswap/swap-router-contracts" "^1.2.1"
"@uniswap/v3-periphery" "^1.1.1"
"@uniswap/v3-staker" "1.0.0"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"

"@uniswap/v3-sdk@^3.17.0", "@uniswap/v3-sdk@^3.17.1", "@uniswap/v3-sdk@^3.18.1":
version "3.18.1"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-3.18.1.tgz#cb714b252336ba662a3298c0525f6668101b0fef"
Expand Down

0 comments on commit 943877c

Please sign in to comment.