From 0726bd7b9f9798ca5a059eea1663f6d03fc0220a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20G=C3=A1mez=20Franco?= Date: Thu, 5 Feb 2026 16:43:50 +0100 Subject: [PATCH] feat: update cowswap adapter --- .../Aggregator/adapters/cowswap/index.ts | 96 +++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/src/components/Aggregator/adapters/cowswap/index.ts b/src/components/Aggregator/adapters/cowswap/index.ts index 0acd0918..08004c9b 100644 --- a/src/components/Aggregator/adapters/cowswap/index.ts +++ b/src/components/Aggregator/adapters/cowswap/index.ts @@ -9,44 +9,63 @@ import { config } from '../../../WalletProvider'; import { chainsMap } from '../../constants'; import { ABI } from './abi'; +// https://docs.cow.fi/cow-protocol/tutorials/solvers/local_test export const chainToId = { - ethereum: 'https://api.cow.fi/mainnet', - gnosis: 'https://api.cow.fi/xdai', arbitrum: 'https://api.cow.fi/arbitrum_one', - base: 'https://api.cow.fi/base', avax: 'https://api.cow.fi/avalanche', - polygon: 'https://api.cow.fi/polygon' -}; + base: 'https://api.cow.fi/base', + bsc: 'https://api.cow.fi/bnb', + ethereum: 'https://api.cow.fi/mainnet', + gnosis: 'https://api.cow.fi/xdai', + ink: 'https://api.cow.fi/ink', + linea: 'https://api.cow.fi/linea', + plasma: 'https://api.cow.fi/plasma', + polygon: 'https://api.cow.fi/polygon', +} as const; + +type CowSwapSupportedChainId = keyof typeof chainToId; export const cowSwapEthFlowSlippagePerChain = { - ethereum: 2, - gnosis: 0.5, arbitrum: 0.5, - base: 0.5, avax: 0.5, - polygon: 0.5 -}; + base: 0.5, + bsc: 0.5, + ethereum: 2, + gnosis: 0.5, + ink: 0.5, + linea: 0.5, + plasma: 0.5, + polygon: 0.5, +} as const satisfies Record; const wrappedTokens = { - ethereum: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', - gnosis: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', arbitrum: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', - base: '0x4200000000000000000000000000000000000006', avax: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', - polygon: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270' -}; + base: '0x4200000000000000000000000000000000000006', + bsc: '0x2170ed0880ac9a755fd29b2688956bd959f933f8', + ethereum: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', + gnosis: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', + ink: '0x4200000000000000000000000000000000000006', + linea: '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f', + plasma: '0x9895d81bb462a195b4922ed7de0e3acd007c32cb', + polygon: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', +} as const satisfies Record; const cowContractAddress = '0xC92E8bdf79f0507f65a392b0ab4667716BFE0110'; const cowSwapEthFlowContractAddress = '0xba3cb449bd2b4adddbc894d8697f5170800eadec'; const nativeSwapAddress = { - ethereum: cowSwapEthFlowContractAddress, - gnosis: cowSwapEthFlowContractAddress, arbitrum: cowSwapEthFlowContractAddress, - base: cowSwapEthFlowContractAddress, avax: cowSwapEthFlowContractAddress, - polygon: cowSwapEthFlowContractAddress -}; + base: cowSwapEthFlowContractAddress, + bsc: cowSwapEthFlowContractAddress, + ethereum: cowSwapEthFlowContractAddress, + gnosis: cowSwapEthFlowContractAddress, + ink: cowSwapEthFlowContractAddress, + linea: cowSwapEthFlowContractAddress, + plasma: cowSwapEthFlowContractAddress, + polygon: cowSwapEthFlowContractAddress, +} as const satisfies Record; export const name = 'CowSwap'; export const token = 'COW'; @@ -56,6 +75,7 @@ export const isOutputAvailable = true; export function approvalAddress() { return cowContractAddress; } + const nativeToken = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; const feeRecipientAddress = '0x1713B79e3dbb8A76D80e038CA701A4a781AC69eB'; @@ -87,26 +107,26 @@ function buildAppData(slippage: string) { const waitForOrder = ({ uid, trader, chain }) => - (onSuccess) => { - const unwatch = watchContractEvent(config, { - address: '0x9008D19f58AAbD9eD0D60971565AA8510560ab41', - abi: ABI.settlement, - eventName: 'Trade', - args: { owner: trader }, - chainId: chainsMap[chain], - onLogs(logs) { - const trade = logs.find((log) => log.data.includes(uid.substring(2))); - if (trade) { - onSuccess(); + (onSuccess) => { + const unwatch = watchContractEvent(config, { + address: '0x9008D19f58AAbD9eD0D60971565AA8510560ab41', + abi: ABI.settlement, + eventName: 'Trade', + args: { owner: trader }, + chainId: chainsMap[chain], + onLogs(logs) { + const trade = logs.find((log) => log.data.includes(uid.substring(2))); + if (trade) { + onSuccess(); + unwatch(); + } + }, + onError(error) { + console.log('Error confirming order status', error); unwatch(); } - }, - onError(error) { - console.log('Error confirming order status', error); - unwatch(); - } - }); - }; + }); + }; // https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/2.-query-the-fee-endpoint export async function getQuote(chain: string, from: string, to: string, amount: string, extra: ExtraData) {