Skip to content
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
9 changes: 3 additions & 6 deletions api/_dexes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export type CrossSwapQuotes = {
};

export type OriginSwapEntryPointContract = {
name: "UniversalSwapAndBridge" | "SpokePoolPeriphery" | "SvmSpoke";
name: "SpokePoolPeriphery" | "SvmSpoke";
address: string;
dex?: SupportedDex;
};
Expand Down Expand Up @@ -251,14 +251,11 @@ export type QuoteFetchOpts = Partial<{
splitSlippage: boolean;
}>;

export type OriginEntryPointContractName =
| "SpokePoolPeriphery"
| "UniversalSwapAndBridge"
| "SvmSpoke";
export type OriginEntryPointContractName = "SpokePoolPeriphery" | "SvmSpoke";

export type OriginEntryPoints = {
originSwapInitialRecipient: {
name: "UniversalSwapAndBridge" | "SwapProxy" | "SvmSpoke";
name: "SwapProxy" | "SvmSpoke";
address: string;
};
swapAndBridge: OriginSwapEntryPointContract;
Expand Down
23 changes: 3 additions & 20 deletions api/_dexes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
TransferType,
getSwapProxyAddress,
} from "../_spoke-pool-periphery";
import { getUniversalSwapAndBridgeAddress } from "../_swap-and-bridge";
import { getFillDeadline } from "../_fill-deadline";
import { encodeActionCalls } from "../swap/_utils";
import { InvalidParamError } from "../_errors";
Expand Down Expand Up @@ -89,8 +88,8 @@ export type QuoteFetchPrioritizationMode =
*
* @example
* {
* default: [getSwapRouter02Strategy("UniversalSwapAndBridge", "trading-api")],
* [CHAIN_IDs.MAINNET]: [getSwapRouter02Strategy("UniversalSwapAndBridge", "sdk")],
* default: [getSwapRouter02Strategy("SpokePoolPeriphery", "trading-api")],
* [CHAIN_IDs.MAINNET]: [getSwapRouter02Strategy("SpokePoolPeriphery", "sdk")],
* }
*/
export type QuoteFetchStrategies = Partial<{
Expand Down Expand Up @@ -148,7 +147,7 @@ export const defaultQuoteFetchStrategies: QuoteFetchStrategies = {
mode: "priority-speed",
priorityChunkSize: 1,
},
default: [getSwapRouter02Strategy("UniversalSwapAndBridge")],
default: [getSwapRouter02Strategy("SpokePoolPeriphery")],
};

export function getPreferredBridgeTokens(
Expand Down Expand Up @@ -1148,22 +1147,6 @@ export function getOriginSwapEntryPoints(
address: getSpokePoolPeripheryAddress(chainId),
},
} as const;
} else if (originSwapEntryPointContractName === "UniversalSwapAndBridge") {
return {
originSwapInitialRecipient: {
name: "UniversalSwapAndBridge",
address: getUniversalSwapAndBridgeAddress(dex, chainId),
},
swapAndBridge: {
name: "UniversalSwapAndBridge",
address: getUniversalSwapAndBridgeAddress(dex, chainId),
dex,
},
deposit: {
name: "SpokePool",
address: getSpokePoolAddress(chainId),
},
} as const;
}
throw new Error(
`Unknown origin swap entry point contract '${originSwapEntryPointContractName}'`
Expand Down
60 changes: 7 additions & 53 deletions api/_swap-and-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
// NOTE: SwapAndBridge and UniverslSwapAndBridge were removed in version 4.1.3 of the contracts repo
// We need version 4.1.1 until we migrate to new SpokePoolPeriphery contracts.
import {
SwapAndBridge__factory,
UniversalSwapAndBridge__factory,
} from "@across-protocol/contracts-v4.1.1";
import { SwapAndBridge__factory } from "@across-protocol/contracts-v4.1.1";

import { ENABLED_ROUTES, getProvider } from "./_utils";

type SwapAndBridgeType = "SwapAndBridge" | "UniversalSwapAndBridge";

export class UnsupportedDex extends Error {
constructor(dex: string, type: SwapAndBridgeType) {
super(`DEX/Aggregator '${dex}' not supported for '${type}'`);
constructor(dex: string) {
super(`DEX/Aggregator '${dex}' not supported for 'SwapAndBridge'`);
}
}

export class UnsupportedDexOnChain extends Error {
constructor(chainId: number, dex: string, type: SwapAndBridgeType) {
constructor(chainId: number, dex: string) {
super(
`DEX/Aggregator '${dex}' not supported on chain ${chainId} for '${type}'`
`DEX/Aggregator '${dex}' not supported on chain ${chainId} for 'SwapAndBridge'`
);
}
}
Expand All @@ -41,37 +34,16 @@ export const swapAndBridgeDexes = Object.keys(
ENABLED_ROUTES.swapAndBridgeAddresses
);

export const universalSwapAndBridgeDexes = Object.keys(
ENABLED_ROUTES.universalSwapAndBridgeAddresses
);

export function getSwapAndBridgeAddress(dex: string, chainId: number) {
if (!_isDexSupportedForSwapAndBridge(dex)) {
throw new UnsupportedDex(dex, "SwapAndBridge");
throw new UnsupportedDex(dex);
}

const address = (
ENABLED_ROUTES.swapAndBridgeAddresses[dex] as Record<string, string>
)?.[chainId];
if (!address) {
throw new UnsupportedDexOnChain(chainId, dex, "SwapAndBridge");
}
return address;
}

export function getUniversalSwapAndBridgeAddress(dex: string, chainId: number) {
if (!_isDexSupportedForUniversalSwapAndBridge(dex)) {
throw new UnsupportedDex(dex, "UniversalSwapAndBridge");
}

const address = (
ENABLED_ROUTES.universalSwapAndBridgeAddresses[dex] as Record<
string,
string
>
)?.[chainId];
if (!address) {
throw new UnsupportedDexOnChain(chainId, dex, "UniversalSwapAndBridge");
throw new UnsupportedDexOnChain(chainId, dex);
}
return address;
}
Expand All @@ -85,26 +57,8 @@ export function getSwapAndBridge(dex: string, chainId: number) {
);
}

export function getUniversalSwapAndBridge(dex: string, chainId: number) {
const universalSwapAndBridgeAddress = getUniversalSwapAndBridgeAddress(
dex,
chainId
);

return UniversalSwapAndBridge__factory.connect(
universalSwapAndBridgeAddress,
getProvider(chainId)
);
}

function _isDexSupportedForSwapAndBridge(
dex: string
): dex is keyof typeof ENABLED_ROUTES.swapAndBridgeAddresses {
return swapAndBridgeDexes.includes(dex);
}

function _isDexSupportedForUniversalSwapAndBridge(
dex: string
): dex is keyof typeof ENABLED_ROUTES.universalSwapAndBridgeAddresses {
return universalSwapAndBridgeDexes.includes(dex);
}
54 changes: 0 additions & 54 deletions api/swap/approval/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { compressTransactionMessageUsingAddressLookupTables } from "@solana/transaction-messages";
import { getAddMemoInstruction } from "@solana-program/memo";

import { CrossSwapQuotes, EvmSwapTxn, isSvmSwapTxn } from "../../_dexes/types";

Check warning on line 16 in api/swap/approval/_utils.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

'EvmSwapTxn' is defined but never used
import {
assertValidIntegratorId,
SWAP_CALLDATA_MARKER,
Expand All @@ -31,7 +31,6 @@
} from "../../_dexes/utils";
import { JupiterSwapIxs } from "../../_dexes/jupiter/utils/api";
import { appendJupiterIxs } from "../../_dexes/jupiter/utils/transaction-builder";
import { getUniversalSwapAndBridge } from "../../_swap-and-bridge";
import { getSVMRpc } from "../../_providers";
import { getFillDeadlineBuffer } from "../../_fill-deadline";
import { getQuoteTimestampArg } from "../../_quote-timestamp";
Expand Down Expand Up @@ -122,59 +121,6 @@
}
);
toAddress = spokePoolPeriphery.address;
}
// NOTE: Left for backwards compatibility with the old `UniversalSwapAndBridge`
// contract. Should be removed once we've migrated to the new `SpokePoolPeriphery`.
else if (originSwapEntryPoint.name === "UniversalSwapAndBridge") {
const universalSwapAndBridge = getUniversalSwapAndBridge(
originSwapEntryPoint.dex || "unknown",
originChainId
);
if (originSwapQuote.swapTxns.length !== 1) {
throw new Error(
"Expected exactly 1 swap transaction for origin swap via `UniversalSwapAndBridge`"
);
}
const swapTxn = originSwapQuote.swapTxns[0] as EvmSwapTxn;
tx = await universalSwapAndBridge.populateTransaction.swapAndBridge(
originSwapQuote.tokenIn.address,
originSwapQuote.tokenOut.address,
swapTxn.data,
originSwapQuote.maximumAmountIn,
originSwapQuote.minAmountOut,
{
...swapAndDepositData.depositData,
depositor: sdk.utils
.toAddressType(
swapAndDepositData.depositData.depositor,
originChainId
)
.toEvmAddress(),
recipient: sdk.utils
.toAddressType(
swapAndDepositData.depositData.recipient,
destinationChainId
)
.toEvmAddress(),
outputToken: sdk.utils
.toAddressType(
swapAndDepositData.depositData.outputToken,
destinationChainId
)
.toEvmAddress(),
exclusiveRelayer: sdk.utils
.toAddressType(
swapAndDepositData.depositData.exclusiveRelayer,
destinationChainId
)
.toEvmAddress(),
exclusivityDeadline:
swapAndDepositData.depositData.exclusivityParameter,
// Typo in the contract
destinationChainid: swapAndDepositData.depositData.destinationChainId,
}
);
toAddress = universalSwapAndBridge.address;
} else {
throw new Error(
`Could not build 'swapAndBridge' tx for unknown entry point contract`
Expand Down
60 changes: 5 additions & 55 deletions scripts/generate-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,51 +122,6 @@ const enabledRoutes = {
[CHAIN_IDs.ARBITRUM]: "0xF633b72A4C2Fb73b77A379bf72864A825aD35b6D",
},
},
// Addresses of `UniversalSwapAndBridge` contracts from deployment:
// https://github.com/across-protocol/contracts/pull/731/commits/6bdbfd38f50b616ac25e49687cbac6fb6bcb543b
universalSwapAndBridgeAddresses: {
"1inch": {
[CHAIN_IDs.ARBITRUM]: "0x81C7601ac0c5825e89F967f9222B977CCD78aD77",
[CHAIN_IDs.BASE]: "0x98285D11B9F7aFec2d475805E5255f26B4490167",
[CHAIN_IDs.OPTIMISM]: "0x7631eA29479Ee265241F13FB48555A2C886d3Bf8",
[CHAIN_IDs.POLYGON]: "0xc2dcb88873e00c9d401de2cbba4c6a28f8a6e2c2",
},
"uniswap-v3/swap-router-02": {
[CHAIN_IDs.ARBITRUM]: "0x2414A759d4EFF700Ad81e257Ab5187d07eCeEbAb",
[CHAIN_IDs.BASE]: "0xed8b9c9aE7aCEf12eb4650d26Eb876005a4752d2",
[CHAIN_IDs.BLAST]: "0x57EE47829369e2EF62fBb423648bec70d0366204",
[CHAIN_IDs.LENS]: "0x793Ff9Cd09819C537500dFcEB6F61861c1B80dCD",
[CHAIN_IDs.MAINNET]: "0x0e84f089B0923EfeA51C6dF91581BFBa66A3484A",
[CHAIN_IDs.OPTIMISM]: "0x04989eaF03547E6583f9d9e42aeD11D2b78A808b",
[CHAIN_IDs.POLYGON]: "0xa55490E20057BD4775618D0FC8D51F59f602FED0",
[CHAIN_IDs.WORLD_CHAIN]: "0x56e2d1b8C7dE8D11B282E1b4C924C32D91f9102B",
[CHAIN_IDs.ZORA]: "0x75b84707e6Bf5bc48DbC3AD883c23192C869AAE4",
[CHAIN_IDs.ZK_SYNC]: "0xdB82479e3903869fbF8B308162E332FED771D51B",
},
gho: {
[CHAIN_IDs.MAINNET]: "0x18d0915ADA0d5969db64CA44A42dB1b51D8421aa",
[CHAIN_IDs.LENS]: "0xDFD7f7AC8F2331C4E83A43E73aB7579e736AC1Bf",
},
"gho-multicall3": {
[CHAIN_IDs.MAINNET]: "0x9736F26C6311701A984A53A0b555f8A20225173A",
},
lifi: {
[CHAIN_IDs.MAINNET]: "0x96804f83B2f77A8F7631b284000F84e5225f8f31",
[CHAIN_IDs.OPTIMISM]: "0xdce5D1a7D52C62E3246117a5657a0306894C1ee8",
[CHAIN_IDs.UNICHAIN]: "0x868041C095cA2b19e462eC0BC8718262bFF1baCD",
[CHAIN_IDs.POLYGON]: "0xDee13c711c91c1ae3A8a1E7b8c983f820AFFBF18",
[CHAIN_IDs.LENS]: "0xD6cdAFd8C8860B664f953d2b23c52AC8c624cB1A",
[CHAIN_IDs.ZK_SYNC]: "0x5a003fA0dae249A31FD4f610fbb3B84A1503a156",
[CHAIN_IDs.WORLD_CHAIN]: "0x53dcB809269AE777fCA05232bb323A9e90feA6b0",
[CHAIN_IDs.LISK]: "0xE0A722530d48aC27eF87596ace5b49629e7DBa5A",
[CHAIN_IDs.SONEIUM]: "0xB6EA3c1a03d842A2E07C48ceF5F2DBd502428406",
[CHAIN_IDs.BASE]: "0x53dcB809269AE777fCA05232bb323A9e90feA6b0",
[CHAIN_IDs.MODE]: "0xBdF9357077B3ED082f0521fA6c726Deca2dcbaB4",
[CHAIN_IDs.ARBITRUM]: "0x6925036403d3e1A5fB6A530f62bA53fe06018522",
[CHAIN_IDs.BLAST]: "0x7593d6394947C9ef0f67575Ce66Be1D529A98886",
[CHAIN_IDs.SCROLL]: "0xBdF9357077B3ED082f0521fA6c726Deca2dcbaB4",
},
},
spokePoolPeripheryAddresses: {
[CHAIN_IDs.ARBITRUM]: "0x89415a82d909a7238d69094C3Dd1dCC1aCbDa85C",
[CHAIN_IDs.BASE]: "0x89415a82d909a7238d69094C3Dd1dCC1aCbDa85C",
Expand Down Expand Up @@ -243,9 +198,6 @@ const enabledRoutes = {
"0x17496824Ba574A4e9De80110A91207c4c63e552a", // Mocked
},
},
universalSwapAndBridgeAddresses: {
"uniswap-v3/swap-router-02": {},
},
spokePoolPeripheryAddresses: {},
swapProxyAddresses: {},
routes: transformChainConfigs(enabledSepoliaChainConfigs, []),
Expand Down Expand Up @@ -432,7 +384,11 @@ function transformChainConfigs(
);

// Handle USDC swap tokens
const usdcSwapTokens = [];
const usdcSwapTokens: {
swapInputTokenSymbol: string;
acrossInputTokenSymbol: string;
acrossOutputTokenSymbol: string;
}[] = [];

const toChain = {
chainId: externalProject.intermediaryChain,
Expand Down Expand Up @@ -660,12 +616,6 @@ async function generateRoutes(hubPoolChainId = 1) {
swapAndBridgeAddresses: checksumAddressesOfNestedMap(
config.swapAndBridgeAddresses as Record<string, Record<string, string>>
),
universalSwapAndBridgeAddresses: checksumAddressesOfNestedMap(
config.universalSwapAndBridgeAddresses as Record<
string,
Record<string, string>
>
),
spokePoolPeripheryAddresses: checksumAddressOfMap(
config.spokePoolPeripheryAddresses as Record<string, string>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"11155420": "0x17496824Ba574A4e9De80110A91207c4c63e552a"
}
},
"universalSwapAndBridgeAddresses": {
"uniswap-v3/swap-router-02": {}
},
"spokePoolPeripheryAddresses": {},
"swapProxyAddresses": {},
"routes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,6 @@
"42161": "0xF633b72A4C2Fb73b77A379bf72864A825aD35b6D"
}
},
"universalSwapAndBridgeAddresses": {
"1inch": {
"10": "0x7631eA29479Ee265241F13FB48555A2C886d3Bf8",
"137": "0xC2dCB88873E00c9d401De2CBBa4C6A28f8A6e2c2",
"8453": "0x98285D11B9F7aFec2d475805E5255f26B4490167",
"42161": "0x81C7601ac0c5825e89F967f9222B977CCD78aD77"
},
"uniswap-v3/swap-router-02": {
"1": "0x0e84f089B0923EfeA51C6dF91581BFBa66A3484A",
"10": "0x04989eaF03547E6583f9d9e42aeD11D2b78A808b",
"137": "0xa55490E20057BD4775618D0FC8D51F59f602FED0",
"232": "0x793Ff9Cd09819C537500dFcEB6F61861c1B80dCD",
"324": "0xdB82479e3903869fbF8B308162E332FED771D51B",
"480": "0x56e2d1b8C7dE8D11B282E1b4C924C32D91f9102B",
"8453": "0xed8b9c9aE7aCEf12eb4650d26Eb876005a4752d2",
"42161": "0x2414A759d4EFF700Ad81e257Ab5187d07eCeEbAb",
"81457": "0x57EE47829369e2EF62fBb423648bec70d0366204",
"7777777": "0x75b84707e6Bf5bc48DbC3AD883c23192C869AAE4"
},
"gho": {
"1": "0x18d0915ADA0d5969db64CA44A42dB1b51D8421aa",
"232": "0xDFD7f7AC8F2331C4E83A43E73aB7579e736AC1Bf"
},
"gho-multicall3": {
"1": "0x9736F26C6311701A984A53A0b555f8A20225173A"
},
"lifi": {
"1": "0x96804f83B2f77A8F7631b284000F84e5225f8f31",
"10": "0xdce5D1a7D52C62E3246117a5657a0306894C1ee8",
"130": "0x868041C095cA2b19e462eC0BC8718262bFF1baCD",
"137": "0xDee13c711c91c1ae3A8a1E7b8c983f820AFFBF18",
"232": "0xD6cdAFd8C8860B664f953d2b23c52AC8c624cB1A",
"324": "0x5a003fA0dae249A31FD4f610fbb3B84A1503a156",
"480": "0x53dcB809269AE777fCA05232bb323A9e90feA6b0",
"1135": "0xE0A722530d48aC27eF87596ace5b49629e7DBa5A",
"1868": "0xB6EA3c1a03d842A2E07C48ceF5F2DBd502428406",
"8453": "0x53dcB809269AE777fCA05232bb323A9e90feA6b0",
"34443": "0xBdF9357077B3ED082f0521fA6c726Deca2dcbaB4",
"42161": "0x6925036403d3e1A5fB6A530f62bA53fe06018522",
"81457": "0x7593d6394947C9ef0f67575Ce66Be1D529A98886",
"534352": "0xBdF9357077B3ED082f0521fA6c726Deca2dcbaB4"
}
},
"spokePoolPeripheryAddresses": {
"1": "0x89415a82d909a7238d69094C3Dd1dCC1aCbDa85C",
"10": "0x89415a82d909a7238d69094C3Dd1dCC1aCbDa85C",
Expand Down
Loading