@anywalletkit/protocol-swap2-uniswap 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/activity.cjs +83 -4
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.d.cts +1 -1
- package/dist/activity.d.ts +1 -1
- package/dist/activity.js +1 -1
- package/dist/addresses-Du1Qks_b.d.cts +148 -0
- package/dist/addresses-Du1Qks_b.d.ts +148 -0
- package/dist/{chunk-DO56GGE7.js → chunk-BHGKOL3N.js} +82 -2
- package/dist/chunk-BHGKOL3N.js.map +1 -0
- package/dist/{chunk-C6WRMMVL.js → chunk-ND647CPH.js} +3 -10
- package/dist/chunk-ND647CPH.js.map +1 -0
- package/dist/{chunk-DNR52ORY.js → chunk-OPFCIWX7.js} +3 -3
- package/dist/index.cjs +114 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -5
- package/dist/protocol.cjs +111 -41
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +3 -3
- package/dist/provider.cjs +109 -39
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +2 -2
- package/package.json +5 -5
- package/dist/addresses-nWujTUai.d.cts +0 -34
- package/dist/addresses-nWujTUai.d.ts +0 -34
- package/dist/chunk-C6WRMMVL.js.map +0 -1
- package/dist/chunk-DO56GGE7.js.map +0 -1
- /package/dist/{chunk-DNR52ORY.js.map → chunk-OPFCIWX7.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/activity.ts","../src/addresses.ts"],"sourcesContent":["/**\n * Activity recognition for Uniswap v3: a call into the chain's SwapRouter02\n * (the deployment table, or the caller's override) with one of the router's\n * swap entry points → `swap`, \"Swapped A → B\" from the owner's net transfers.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {UNISWAP_V3, type UniswapDeployment} from \"./addresses.js\";\n\nexport const UNISWAP_MODULE = \"@anywalletkit/protocol-swap2-uniswap\";\n\n/** SwapRouter02 entry points (`viem toFunctionSelector`, 2026-10-14). */\nexport const UNISWAP_ROUTER_SELECTORS: ReadonlySet<string> = new Set([\n \"0x5ae401dc\", // multicall(uint256 deadline, bytes[] data)\n \"0xac9650d8\", // multicall(bytes[] data)\n \"0x1f0464d1\", // multicall(bytes32 previousBlockhash, bytes[] data)\n \"0x04e45aaf\", // exactInputSingle((address,address,uint24,address,uint256,uint256,uint160))\n \"0xb858183f\", // exactInput((bytes,address,uint256,uint256))\n \"0x5023b4df\", // exactOutputSingle((address,address,uint24,address,uint256,uint256,uint160))\n \"0x09b81346\", // exactOutput((bytes,address,uint256,uint256))\n]);\n\nexport function describeUniswapActivity(\n tx: ChainTx,\n ctx: DescribeActivityContext,\n deployments: Readonly<Record<number, UniswapDeployment>> = UNISWAP_V3,\n): ActivityItem | null {\n if (!isEvm(tx.chain)) return null;\n const deployment = deployments[evmRef(tx.chain)];\n if (!deployment || !matchesCall(tx, [deployment.router], UNISWAP_ROUTER_SELECTORS)) return null;\n return describeSwapLike(tx, ctx, {protocol: UNISWAP_MODULE, subtitle: `Uniswap v3 · ${chainLabel(tx.chain)}`, kind: \"swap\"});\n}\n","import {decodeFunctionData, getAddress, parseAbi, type Hex} from \"viem\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Quote, QuoteParams, RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * Uniswap v3 deployments this module trusts. Every entry was checked on-chain\n * (2026-10-12): SwapRouter02.factory() and QuoterV2.factory() both return\n * `factory`, and both report `weth` as WETH9. The provider re-checks the same\n * facts once per chain at runtime before quoting (see `verifyDeployment`).\n */\nexport interface UniswapDeployment {\n factory: `0x${string}`;\n quoter: `0x${string}`;\n router: `0x${string}`;\n /** The chain's wrapped native token (WETH, WBNB, WPOL, WAVAX) — on a chain\n * without one (Celo), the hop token used for two-hop routes instead. */\n weth: `0x${string}`;\n /** false: the router has no WETH9 (reports 0x0) — no native in/out, the coin is an ERC-20 there. */\n nativeWrap?: false;\n /** false: a newer QuoterV2 build without WETH9() — only its factory is checked. */\n quoterWeth?: false;\n}\n\nexport const UNISWAP_V3: Readonly<Record<number, UniswapDeployment>> = Object.freeze({\n 1: {factory: \"0x1F98431c8aD98523631AE4a59f267346ea31F984\", quoter: \"0x61fFE014bA17989E743c5F6cB21bF9697530B21e\", router: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\", weth: \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\"},\n 10: {factory: \"0x1F98431c8aD98523631AE4a59f267346ea31F984\", quoter: \"0x61fFE014bA17989E743c5F6cB21bF9697530B21e\", router: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\", weth: \"0x4200000000000000000000000000000000000006\"},\n 56: {factory: \"0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7\", quoter: \"0x78D78E420Da98ad378D7799bE8f4AF69033EB077\", router: \"0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2\", weth: \"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c\"},\n 137: {factory: \"0x1F98431c8aD98523631AE4a59f267346ea31F984\", quoter: \"0x61fFE014bA17989E743c5F6cB21bF9697530B21e\", router: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\", weth: \"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270\"},\n 8453: {factory: \"0x33128a8fC17869897dcE68Ed026d694621f6FDfD\", quoter: \"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a\", router: \"0x2626664c2603336E57B271c5C0b26F421741e481\", weth: \"0x4200000000000000000000000000000000000006\"},\n 42161: {factory: \"0x1F98431c8aD98523631AE4a59f267346ea31F984\", quoter: \"0x61fFE014bA17989E743c5F6cB21bF9697530B21e\", router: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\", weth: \"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1\"},\n // zkSync Era and Celo: addresses from cp0x pi-uniswap-interface, verified on-chain 2026-10-12.\n 324: {factory: \"0x8FdA5a7a8dCA67BBcDd10F02Fa0649A937215422\", quoter: \"0x8Cb537fc92E26d8EBBb760E632c95484b6Ea3e28\", router: \"0x99c56385daBCE3E81d8499d0b8d0257aBC07E8A3\", weth: \"0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91\"},\n 42220: {factory: \"0xAfE208a311B21f13EF87E33A90049fC17A7acDEc\", quoter: \"0x82825d0554fA07f7FC52Ab63c961F330fdEFa8E8\", router: \"0x5615CDAb10dc425a742d643d949a7F474C01abc4\", weth: \"0x471EcE3750Da237f93B8E339c536989b8978a438\", nativeWrap: false},\n // Unichain, Monad, Linea: Uniswap's sdk-core CHAIN_TO_ADDRESSES_MAP, verified on-chain 2026-10-13\n // (router + quoter report the factory; these quoters have no WETH9()).\n 130: {factory: \"0x1F98400000000000000000000000000000000003\", quoter: \"0x565AC8C7863D9bb16d07E809ff49Fe5cD467634C\", router: \"0x73855d06DE49d0fe4A9c42636Ba96c62da12FF9C\", weth: \"0x4200000000000000000000000000000000000006\", quoterWeth: false},\n 143: {factory: \"0x204FAca1764B154221e35c0d20aBb3c525710498\", quoter: \"0x2d01411773c8C24805306e89a41f7855c3C4fE65\", router: \"0xfE31F71C1b106EAc32F1A19239c9a9A72ddfb900\", weth: \"0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A\", quoterWeth: false},\n 59144: {factory: \"0x31FAfd4889FA1269F7a13A66eE0fB458f27D72A9\", quoter: \"0x58EaD433eA99708604c4dD7C9b7E80c70976E202\", router: \"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a\", weth: \"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f\", quoterWeth: false},\n // World Chain, Ink, X Layer: Uniswap's sdk-core CHAIN_TO_ADDRESSES_MAP, verified on-chain 2026-10-13\n // (router + quoter report the factory; X Layer's quoter has no WETH9(), its router wraps WOKB).\n 480: {factory: \"0x7a5028BDa40e7B173C278C5342087826455ea25a\", quoter: \"0x10158D43e6cc414deE1Bd1eB0EfC6a5cBCfF244c\", router: \"0x091AD9e2e6e5eD44c1c66dB50e49A601F9f36cF6\", weth: \"0x4200000000000000000000000000000000000006\"},\n 57073: {factory: \"0x640887A9ba3A9C53Ed27D0F7e8246A4F933f3424\", quoter: \"0x96b572D2d880cf2Fa2563651BD23ADE6f5516652\", router: \"0x177778F19E89dD1012BdBe603F144088A95C4B53\", weth: \"0x4200000000000000000000000000000000000006\"},\n 196: {factory: \"0x4B2ab38DBF28D31D467aA8993f6c2585981D6804\", quoter: \"0x976183AC3d09840D243A88c0268BADb3B3e3259f\", router: \"0x4f0C28f5926AFDA16bf2506D5D9e57Ea190f9bcA\", weth: \"0xe538905cf8410324e03A5A23C1c177a474D59b2b\", quoterWeth: false},\n // Robinhood Chain: addresses from cp0x pi-uniswap-interface (constants/addresses.ts), verified on-chain 2026-10-12.\n 4663: {factory: \"0x1f7d7550B1b028f7571E69A784071F0205FD2EfA\", quoter: \"0x33e885eD0Ec9bF04EcfB19341582aADCb4c8A9E7\", router: \"0xCaf681a66D020601342297493863E78C959E5cb2\", weth: \"0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73\"},\n 43114: {factory: \"0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD\", quoter: \"0xbe0F5544EC67e9B3b2D979aaA43f18Fd87E6257F\", router: \"0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE\", weth: \"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7\"},\n});\n\n/** Pool fee tiers probed for every hop (0.01%, 0.05%, 0.3%, 1%). */\nexport const FEE_TIERS = [100, 500, 3000, 10000] as const;\n/** Two-hop routes go through these (when the catalog knows them on the chain). */\nexport const HOP_SYMBOLS = [\"WETH\", \"USDC\", \"USDT\"] as const;\n/** SwapRouter02 recipient sentinel: \"keep the output in the router\" (then unwrapWETH9). */\nexport const ADDRESS_THIS = \"0x0000000000000000000000000000000000000002\";\n\n/** The SwapRouter02 entry points this module writes (and the deployment probes). */\nexport const ROUTER_ABI = parseAbi([\n \"function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountOut)\",\n \"function exactInput((bytes path, address recipient, uint256 amountIn, uint256 amountOutMinimum) params) payable returns (uint256 amountOut)\",\n \"function unwrapWETH9(uint256 amountMinimum, address recipient) payable\",\n \"function multicall(uint256 deadline, bytes[] data) payable returns (bytes[] results)\",\n \"function factory() view returns (address)\",\n \"function WETH9() view returns (address)\",\n]);\n/** Most pools one `exactInput` path may cross: the provider builds direct and one-hop (two-pool) routes only. */\nconst MAX_PATH_POOLS = 2;\n\n/**\n * The swap a Uniswap quote's router call makes, opened on the client against the app's own request (scan 2026-10-28,\n * F1): one `multicall(deadline, legs)` on the chain's pinned SwapRouter02 whose legs are exactly one `exactInputSingle`\n * or `exactInput` — then `unwrapWETH9` for a native output — selling exactly the input of the source token (WETH for a\n * native input, paid as `value`) for the destination token, with `amountOutMinimum` the quote's minimum, paid to the\n * recipient (or kept in the router and unwrapped to the recipient for that same minimum). `pull`, `sweepToken` and\n * every other router call are refused. The reason it fails, or null.\n */\nexport function uniswapVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n const id = /^eip155:[0-9]+$/.test(params.sourceChain) ? Number(params.sourceChain.slice(7)) : NaN;\n const d = Object.prototype.hasOwnProperty.call(UNISWAP_V3, id) ? UNISWAP_V3[id] : undefined;\n if (!d || params.destChain !== params.sourceChain) return \"not a same-chain swap on a pinned Uniswap deployment\";\n const tx = quote.txRequest;\n if (!tx?.data || !tx.to || tx.serializedTx !== undefined) return \"the quote carries no router call\";\n if (getAddress(tx.to) !== getAddress(d.router)) return `the call targets ${tx.to}, not the SwapRouter`;\n const src = sourceAssetOf(params);\n if (!src) return `unknown source token ${params.sourceToken}`;\n const nativeIn = !src.contract;\n const nativeOut = /^0x0+$/.test(params.destToken);\n if ((nativeIn || nativeOut) && d.nativeWrap === false) return \"this chain's router has no wrapped native\";\n let tokenIn: string, tokenOut: string, recipient: string, amountIn: bigint, minOut: bigint;\n try {\n tokenIn = getAddress(nativeIn ? d.weth : src.contract!);\n tokenOut = getAddress(nativeOut ? d.weth : params.destToken);\n recipient = getAddress(params.destAddress);\n amountIn = BigInt(params.amountIn);\n minOut = BigInt(quote.minDestAmount);\n } catch {\n return \"the request does not name EVM tokens, a recipient and amounts\";\n }\n if (nativeIn ? BigInt(tx.value ?? \"0\") !== amountIn || tx.approvalAddress !== undefined\n : BigInt(tx.value ?? \"0\") !== 0n || !tx.approvalAddress || getAddress(tx.approvalAddress) !== getAddress(d.router)) {\n return nativeIn ? \"a native input is paid as exactly the input in value, with no approval\" : \"a token input attaches no value and approves the SwapRouter\";\n }\n let legs: readonly Hex[];\n try {\n const outer = decodeFunctionData({abi: ROUTER_ABI, data: tx.data as Hex});\n if (outer.functionName !== \"multicall\") return `${outer.functionName} is not multicall(deadline, legs)`;\n legs = outer.args[1];\n } catch {\n return \"the router call is not multicall(deadline, legs)\";\n }\n if (legs.length !== (nativeOut ? 2 : 1)) return `the multicall has ${legs.length} legs, not a swap${nativeOut ? \" and an unwrap\" : \"\"}`;\n const decode = (leg: Hex) => { try { return decodeFunctionData({abi: ROUTER_ABI, data: leg}); } catch { return null; } };\n const swap = decode(legs[0]!);\n const swapTo = nativeOut ? ADDRESS_THIS : recipient;\n if (swap?.functionName === \"exactInputSingle\") {\n const a = swap.args[0];\n if (getAddress(a.tokenIn) !== tokenIn || getAddress(a.tokenOut) !== tokenOut) return \"the swap trades other tokens\";\n if (a.amountIn !== amountIn || a.amountOutMinimum !== minOut || a.sqrtPriceLimitX96 !== 0n) return \"the swap's input, minimum or price limit is not the quote's\";\n if (getAddress(a.recipient) !== getAddress(swapTo)) return `the swap pays ${a.recipient}, not the recipient`;\n } else if (swap?.functionName === \"exactInput\") {\n const a = swap.args[0];\n const path = a.path.slice(2);\n const pools = (path.length / 2 - 20) / 23;\n if (!/^[0-9a-fA-F]*$/.test(path) || !Number.isInteger(pools) || pools < 1 || pools > MAX_PATH_POOLS) return \"the swap path is not 1–2 pools\";\n if (getAddress(`0x${path.slice(0, 40)}`) !== tokenIn || getAddress(`0x${path.slice(-40)}`) !== tokenOut) return \"the swap path trades other tokens\";\n if (a.amountIn !== amountIn || a.amountOutMinimum !== minOut) return \"the swap's input or minimum is not the quote's\";\n if (getAddress(a.recipient) !== getAddress(swapTo)) return `the swap pays ${a.recipient}, not the recipient`;\n } else {\n return `${swap?.functionName ?? \"an unknown call\"} is not exactInputSingle / exactInput`;\n }\n if (nativeOut) {\n const unwrap = decode(legs[1]!);\n if (unwrap?.functionName !== \"unwrapWETH9\") return `${unwrap?.functionName ?? \"an unknown call\"} is not unwrapWETH9`;\n if (unwrap.args[0] !== minOut || getAddress(unwrap.args[1]) !== recipient) return \"the unwrap pays someone else or less than the minimum\";\n }\n return null;\n}\n\n/**\n * The SwapRouter a Uniswap swap calls and approves on a chain (the shipped {@link UNISWAP_V3} table), and\n * {@link uniswapVerifyQuote} — the app's pins for `remoteProvider({name: \"uniswap\", baseUrl, ...uniswapPins})` (scan\n * 2026-10-27 modules, F9; scan 2026-10-28, F1).\n */\nexport const uniswapPins: RemotePins = Object.freeze({\n callTargets: (chain: string): readonly string[] => uniswapRouterFor(chain),\n spenders: (chain: string): readonly string[] => uniswapRouterFor(chain),\n verifyQuote: uniswapVerifyQuote,\n});\nfunction uniswapRouterFor(chain: string): readonly string[] {\n const id = /^eip155:[0-9]+$/.test(chain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AK;AAAA,EACzE,UAAU,CAAC,UAAqC,iBAAiB,KAAK;AAAA,EACtE,aAAa;AACf,CAAC;AACD,SAAS,iBAAiB,OAAkC;AAC1D,QAAM,KAAK,kBAAkB,KAAK,KAAK,IAAI,OAAO,MAAM,MAAM,CAAC,CAAC,IAAI;AACpE,QAAM,IAAI,OAAO,UAAU,eAAe,KAAK,YAAY,EAAE,IAAI,WAAW,EAAE,IAAI;AAClF,SAAO,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;AAC3B;;;AD7IO,IAAM,iBAAiB;AAGvB,IAAM,2BAAgD,oBAAI,IAAI;AAAA,EACnE;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF,CAAC;AAEM,SAAS,wBACd,IACA,KACA,cAA2D,YACtC;AACrB,MAAI,CAAC,MAAM,GAAG,KAAK,EAAG,QAAO;AAC7B,QAAM,aAAa,YAAY,OAAO,GAAG,KAAK,CAAC;AAC/C,MAAI,CAAC,cAAc,CAAC,YAAY,IAAI,CAAC,WAAW,MAAM,GAAG,wBAAwB,EAAG,QAAO;AAC3F,SAAO,iBAAiB,IAAI,KAAK,EAAC,UAAU,gBAAgB,UAAU,mBAAgB,WAAW,GAAG,KAAK,CAAC,IAAI,MAAM,OAAM,CAAC;AAC7H;","names":[]}
|
|
@@ -2,9 +2,10 @@ import {
|
|
|
2
2
|
ADDRESS_THIS,
|
|
3
3
|
FEE_TIERS,
|
|
4
4
|
HOP_SYMBOLS,
|
|
5
|
+
ROUTER_ABI,
|
|
5
6
|
UNISWAP_V3,
|
|
6
7
|
describeUniswapActivity
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BHGKOL3N.js";
|
|
8
9
|
|
|
9
10
|
// src/provider.ts
|
|
10
11
|
import { decodeFunctionResult, encodeFunctionData, encodePacked, getAddress, parseAbi } from "viem";
|
|
@@ -21,14 +22,6 @@ var QUOTER_ABI = parseAbi([
|
|
|
21
22
|
"function factory() view returns (address)",
|
|
22
23
|
"function WETH9() view returns (address)"
|
|
23
24
|
]);
|
|
24
|
-
var ROUTER_ABI = parseAbi([
|
|
25
|
-
"function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountOut)",
|
|
26
|
-
"function exactInput((bytes path, address recipient, uint256 amountIn, uint256 amountOutMinimum) params) payable returns (uint256 amountOut)",
|
|
27
|
-
"function unwrapWETH9(uint256 amountMinimum, address recipient) payable",
|
|
28
|
-
"function multicall(uint256 deadline, bytes[] data) payable returns (bytes[] results)",
|
|
29
|
-
"function factory() view returns (address)",
|
|
30
|
-
"function WETH9() view returns (address)"
|
|
31
|
-
]);
|
|
32
25
|
var RPC_BATCH_MAX = 10;
|
|
33
26
|
function uniswapProvider(config) {
|
|
34
27
|
const deployments = config.deployments ?? UNISWAP_V3;
|
|
@@ -287,4 +280,4 @@ function uniswapProvider(config) {
|
|
|
287
280
|
export {
|
|
288
281
|
uniswapProvider
|
|
289
282
|
};
|
|
290
|
-
//# sourceMappingURL=chunk-
|
|
283
|
+
//# sourceMappingURL=chunk-ND647CPH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import {decodeFunctionResult, encodeFunctionData, encodePacked, getAddress, parseAbi, type Hex} from \"viem\";\nimport {describeUniswapActivity} from \"./activity.js\";\nimport {ccAsset} from \"@anywalletkit/swap2-assets\";\nimport {evmRef, isEvm, timeoutSignal, sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {ADDRESS_THIS, FEE_TIERS, HOP_SYMBOLS, ROUTER_ABI, UNISWAP_V3, type UniswapDeployment} from \"./addresses.js\";\nimport {bigintToNumber} from \"@anywalletkit/core\";\n\n/**\n * Uniswap v3, straight from the contracts — the permissionless swap venue.\n *\n * Quote: QuoterV2 via `eth_call` (one JSON-RPC batch: every fee tier direct,\n * plus two-hop routes through WETH / USDC / USDT). Execution: SwapRouter02\n * `multicall(deadline, …)` — `exactInputSingle` or `exactInput`, native input\n * wrapped by the router (`value`), native output kept in the router and paid\n * out with `unwrapWETH9(min, recipient)`. No API key, no Uniswap frontend, no\n * aggregator: if the pools are live, the swap works.\n *\n * Same-chain only. ERC-20 sources approve exactly the input to the router\n * (`approvalAddress`); the engine handles that leg.\n */\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\nconst DEFAULT_SLIPPAGE_BPS = 50;\n/** The router itself enforces amountOutMinimum and the deadline, and preflight\n * re-quotes the exact route before broadcast — so the quote may outlive an\n * approval being mined (an Ethereum approve + head wait took >30 s live). */\nconst DEFAULT_TTL_MS = 300_000;\nconst DEFAULT_DEADLINE_S = 600;\n\nconst QUOTER_ABI = parseAbi([\n \"function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96) params) returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)\",\n \"function quoteExactInput(bytes path, uint256 amountIn) returns (uint256 amountOut, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)\",\n \"function factory() view returns (address)\",\n \"function WETH9() view returns (address)\",\n]);\n\nexport interface UniswapProviderConfig {\n enabled?: boolean;\n /** JSON-RPC endpoints per EVM chain id, tried in order. A chain without one is not offered. */\n rpcUrls: Readonly<Record<number, readonly string[]>>;\n /** Slippage when the caller names none (bps). Default 50. */\n defaultSlippageBps?: number;\n /** Local quote lifetime (must cover an approval being mined). Default 5 min. */\n quoteTtlMs?: number;\n /** Seconds the router accepts the swap after the quote (multicall deadline). Default 600. */\n deadlineSeconds?: number;\n /** Override the deployments (tests, new chains). Still verified on-chain before use. */\n deployments?: Readonly<Record<number, UniswapDeployment>>;\n}\n\ninterface Route {\n /** Human description for the review / logs. */\n label: string;\n /** The pool fee(s) the route pays — already inside the quoted output. */\n poolFee: string;\n single?: {fee: number};\n path?: Hex;\n}\n\ntype RpcCall = {method: string; params: unknown[]};\n\n/** Largest JSON-RPC batch sent to one node (X Layer's public RPCs refuse more than 10). */\nconst RPC_BATCH_MAX = 10;\n\nexport function uniswapProvider(config: UniswapProviderConfig): CrossChainProvider {\n const deployments = config.deployments ?? UNISWAP_V3;\n const slippageDefault = config.defaultSlippageBps ?? DEFAULT_SLIPPAGE_BPS;\n const ttl = config.quoteTtlMs ?? DEFAULT_TTL_MS;\n const deadlineS = config.deadlineSeconds ?? DEFAULT_DEADLINE_S;\n if (!Number.isInteger(slippageDefault) || slippageDefault <= 0 || slippageDefault >= 5_000) throw new Error(\"uniswap: defaultSlippageBps must be 1..4999\");\n const verified = new Map<number, Promise<void>>();\n\n const chainIdOf = (caip2: string): number | null => {\n if (!isEvm(caip2)) return null;\n const id = evmRef(caip2);\n return deployments[id] && config.rpcUrls[id]?.length ? id : null;\n };\n\n /**\n * JSON-RPC batch with endpoint failover; each slot is the result or null (reverted / errored).\n * Sent in chunks of RPC_BATCH_MAX: some public nodes cap a batch (X Layer's at 10 calls).\n */\n async function rpc(chainId: number, calls: RpcCall[], signal?: AbortSignal): Promise<(unknown | null)[]> {\n if (calls.length <= RPC_BATCH_MAX) return rpcBatch(chainId, calls, signal);\n const chunks: RpcCall[][] = [];\n for (let i = 0; i < calls.length; i += RPC_BATCH_MAX) chunks.push(calls.slice(i, i + RPC_BATCH_MAX));\n return (await Promise.all(chunks.map((c) => rpcBatch(chainId, c, signal)))).flat();\n }\n\n async function rpcBatch(chainId: number, calls: RpcCall[], signal?: AbortSignal): Promise<(unknown | null)[]> {\n let lastErr: unknown;\n for (const url of config.rpcUrls[chainId] ?? []) {\n try {\n const res = await fetch(url, {\n method: \"POST\",\n headers: {\"content-type\": \"application/json\"},\n body: JSON.stringify(calls.map((c, id) => ({jsonrpc: \"2.0\", id, ...c}))),\n signal: signal ?? timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`HTTP ${res.status}`);\n const body = (await res.json()) as {id: number; result?: unknown; error?: unknown}[] | {error?: {message?: string}};\n if (!Array.isArray(body)) throw new Error(body.error?.message ?? \"batch refused\");\n const out: (unknown | null)[] = calls.map(() => null);\n for (const r of body) if (typeof r.id === \"number\" && r.id < out.length && r.error === undefined) out[r.id] = r.result ?? null;\n return out;\n } catch (e) {\n lastErr = e;\n }\n }\n throw new Error(`uniswap: no RPC answered on chain ${chainId} (${lastErr instanceof Error ? lastErr.message : String(lastErr)})`);\n }\n\n const call = (to: string, data: Hex): RpcCall => ({method: \"eth_call\", params: [{to, data}, \"latest\"]});\n\n /** The pinned addresses still describe one deployment (router + quoter agree on factory and WETH). */\n function verifyDeployment(chainId: number): Promise<void> {\n let p = verified.get(chainId);\n if (!p) {\n const d = deployments[chainId]!;\n p = (async () => {\n const f = encodeFunctionData({abi: ROUTER_ABI, functionName: \"factory\"});\n const w = encodeFunctionData({abi: ROUTER_ABI, functionName: \"WETH9\"});\n const [rf, rw, qf, qw] = await rpc(chainId, [call(d.router, f), call(d.router, w), call(d.quoter, f), call(d.quoter, w)]);\n const addr = (r: unknown) => (typeof r === \"string\" && r.length >= 42 ? getAddress(`0x${r.slice(-40)}`) : null);\n const wrapped = d.nativeWrap === false ? getAddress(ZERO) : getAddress(d.weth);\n const ok =\n [rf, qf].every((r) => addr(r) === getAddress(d.factory)) &&\n addr(rw) === wrapped &&\n (d.quoterWeth === false || addr(qw) === wrapped);\n if (!ok) throw new Error(`uniswap: the router/quoter on chain ${chainId} do not match the pinned deployment — refusing`);\n })();\n p.catch(() => verified.delete(chainId));\n verified.set(chainId, p);\n }\n return p;\n }\n\n /** Every candidate route for tokenIn → tokenOut on this chain. */\n function routes(chainId: number, caip2: string, tokenIn: Hex, tokenOut: Hex): Route[] {\n const d = deployments[chainId]!;\n const out: Route[] = FEE_TIERS.map((fee) => ({label: `direct ${fee / 10_000}%`, poolFee: `${fee / 10_000}%`, single: {fee}}));\n const mids = new Set<string>();\n for (const sym of HOP_SYMBOLS) {\n const mid = sym === \"WETH\" ? d.weth : ccAsset(caip2, sym)?.contract;\n if (!mid || !/^0x[0-9a-fA-F]{40}$/.test(mid)) continue;\n const m = getAddress(mid);\n if (m === getAddress(tokenIn) || m === getAddress(tokenOut) || mids.has(m)) continue;\n mids.add(m);\n for (const f1 of [100, 500, 3000]) {\n for (const f2 of [100, 500, 3000]) {\n out.push({label: `via ${sym} ${f1 / 10_000}% → ${f2 / 10_000}%`, poolFee: `${f1 / 10_000}% + ${f2 / 10_000}%`, path: encodePacked([\"address\", \"uint24\", \"address\", \"uint24\", \"address\"], [tokenIn, f1, m, f2, tokenOut])});\n }\n }\n }\n return out;\n }\n\n return {\n name: \"uniswap\",\n describeActivity: (tx, ctx) => describeUniswapActivity(tx, ctx, config.deployments ?? UNISWAP_V3),\n supportsSameChain: true,\n enabled: () => config.enabled ?? true,\n supportsChain: (caip2: string) => chainIdOf(caip2) !== null,\n supportsChainPair: (from: string, to: string) => from === to && chainIdOf(from) !== null,\n supportsRoute(from: Asset, to: Asset): boolean {\n return from.chain === to.chain && chainIdOf(from.chain) !== null;\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const refuse = (why: string): null => {\n params.onRefusal?.(`uniswap: ${why}`);\n return null;\n };\n if (params.flex) return refuse(\"amount-flexible deposits are not supported\");\n if (params.sourceChain !== params.destChain) return refuse(\"same-chain swaps only\");\n const chainId = chainIdOf(params.sourceChain);\n if (chainId === null) return refuse(`no Uniswap v3 deployment or RPC for ${params.sourceChain}`);\n const d = deployments[chainId]!;\n const src = sourceAssetOf(params);\n if (!src) return refuse(`unknown source token ${params.sourceToken}`);\n const nativeIn = !src.contract;\n const nativeOut = /^0x0+$/.test(params.destToken);\n if ((nativeIn || nativeOut) && d.nativeWrap === false) return refuse(\"this chain's router has no wrapped native — swap the coin's ERC-20 instead\");\n if (!nativeOut && !/^0x[0-9a-fA-F]{40}$/.test(params.destToken)) return refuse(\"destination token must be an EVM address\");\n if (!/^0x[0-9a-fA-F]{40}$/.test(params.destAddress)) return refuse(\"recipient must be an EVM address\");\n let amountIn: bigint;\n try {\n amountIn = BigInt(params.amountIn);\n } catch {\n return refuse(\"amount is not an integer\");\n }\n if (amountIn <= 0n) return refuse(\"amount must be positive\");\n const tokenIn = getAddress(nativeIn ? d.weth : src.contract!);\n const tokenOut = getAddress(nativeOut ? d.weth : params.destToken);\n if (tokenIn === tokenOut) return refuse(nativeIn || nativeOut ? \"that is a wrap/unwrap, not a swap\" : \"same token in and out\");\n\n try {\n await verifyDeployment(chainId);\n const candidates = routes(chainId, params.sourceChain, tokenIn, tokenOut);\n const results = await rpc(\n chainId,\n candidates.map((r) =>\n call(\n d.quoter,\n r.single\n ? encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInputSingle\", args: [{tokenIn, tokenOut, amountIn, fee: r.single.fee, sqrtPriceLimitX96: 0n}]})\n : encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInput\", args: [r.path!, amountIn]}),\n ),\n ),\n signal,\n );\n let best: {route: Route; out: bigint; gas: bigint} | null = null;\n results.forEach((raw, i) => {\n if (typeof raw !== \"string\" || raw === \"0x\") return;\n const r = candidates[i]!;\n try {\n const [out, , , gas] = decodeFunctionResult({abi: QUOTER_ABI, functionName: r.single ? \"quoteExactInputSingle\" : \"quoteExactInput\", data: raw as Hex}) as readonly [bigint, unknown, unknown, bigint];\n if (out > 0n && (!best || out > best.out)) best = {route: r, out, gas};\n } catch {\n /* a malformed slot is just not a candidate */\n }\n });\n if (!best) return refuse(\"no Uniswap v3 pool route for this pair and amount\");\n const {route, out, gas} = best as {route: Route; out: bigint; gas: bigint};\n\n // Price impact (SDK-127): a probe 1/1000 the size on the same route gives the pool's\n // marginal rate; the full-size rate's shortfall against it is the impact. Pool fees\n // are paid on both sides, so they cancel. Informational — the Oct 16 run swapped\n // 16.78 USDT into 0.0099 USDT0 through an empty pool and nothing said a word.\n let priceImpactBps: number | undefined;\n const probeIn = amountIn / 1000n;\n if (probeIn > 0n) {\n try {\n const [raw] = await rpc(\n chainId,\n [call(d.quoter, route.single\n ? encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInputSingle\", args: [{tokenIn, tokenOut, amountIn: probeIn, fee: route.single.fee, sqrtPriceLimitX96: 0n}]})\n : encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInput\", args: [route.path!, probeIn]}))],\n signal,\n );\n if (typeof raw === \"string\" && raw !== \"0x\") {\n const [probeOut] = decodeFunctionResult({abi: QUOTER_ABI, functionName: route.single ? \"quoteExactInputSingle\" : \"quoteExactInput\", data: raw as Hex}) as readonly [bigint];\n if (probeOut > 0n) {\n const ratioBps = (out * probeIn * 10_000n) / (probeOut * amountIn); // (out/amountIn) ÷ (probeOut/probeIn), in bps\n priceImpactBps = Math.max(0, bigintToNumber(10_000n - ratioBps));\n }\n }\n } catch {\n /* the quote stands; impact is information, not a gate */\n }\n }\n\n const bps = params.slippageBps ?? slippageDefault;\n const minOut = (out * BigInt(10_000 - bps)) / 10_000n;\n if (params.minAmountOut !== undefined && minOut < BigInt(params.minAmountOut)) {\n return refuse(`floor breach (min=${minOut} < floor=${params.minAmountOut})`);\n }\n const recipient = getAddress(params.destAddress);\n const swapTo = nativeOut ? ADDRESS_THIS : recipient;\n const swap = route.single\n ? encodeFunctionData({abi: ROUTER_ABI, functionName: \"exactInputSingle\", args: [{tokenIn, tokenOut, fee: route.single.fee, recipient: swapTo as Hex, amountIn, amountOutMinimum: minOut, sqrtPriceLimitX96: 0n}]})\n : encodeFunctionData({abi: ROUTER_ABI, functionName: \"exactInput\", args: [{path: route.path!, recipient: swapTo as Hex, amountIn, amountOutMinimum: minOut}]});\n const legs: Hex[] = [swap];\n if (nativeOut) legs.push(encodeFunctionData({abi: ROUTER_ABI, functionName: \"unwrapWETH9\", args: [minOut, recipient]}));\n const deadline = BigInt(Math.floor(Date.now() / 1000) + deadlineS);\n const data = encodeFunctionData({abi: ROUTER_ABI, functionName: \"multicall\", args: [deadline, legs]});\n // Quoter gas covers the pool hops; the router's own overhead and an unwrap ride on top.\n const gasLimit = (gas * 3n) / 2n + 120_000n + (nativeOut ? 40_000n : 0n);\n\n return {\n provider: \"uniswap\",\n intentId: `uniswap:${chainId}`,\n depositAddress: \"\",\n depositMemo: null,\n txRequest: {\n to: d.router,\n data,\n value: nativeIn ? amountIn.toString() : \"0\",\n chainId,\n gasLimit: gasLimit.toString(),\n ...(nativeIn ? {} : {approvalAddress: d.router}),\n },\n sourceAmount: amountIn.toString(),\n destAmount: out.toString(),\n minDestAmount: minOut.toString(),\n feeUsd: 0,\n etaSeconds: 15,\n reliability: 0.98,\n validUntilMs: Date.now() + ttl,\n providerData: {\n route: route.label,\n poolFee: route.poolFee,\n router: d.router,\n tokenIn,\n tokenOut,\n amountIn: amountIn.toString(),\n minOut: minOut.toString(),\n ...(route.single ? {fee: String(route.single.fee)} : {path: route.path!}),\n ...(priceImpactBps !== undefined ? {priceImpactBps: String(priceImpactBps)} : {}),\n },\n };\n } catch (e) {\n return refuse(e instanceof Error ? e.message.replace(/^uniswap: /, \"\") : String(e));\n }\n },\n\n /**\n * Right before broadcast (after any approval): re-quote the SAME route on\n * chain. If the pool now pays less than the signed minimum, the swap would\n * only revert and burn gas — refuse it here with the reason instead.\n */\n async preflightDeposit(quote: Quote): Promise<void> {\n const chainId = Number(quote.intentId.split(\":\")[1]);\n const d = deployments[chainId];\n const pd = quote.providerData ?? {};\n if (!d || !pd.amountIn || !pd.minOut || !pd.tokenIn || !pd.tokenOut) return;\n const data = pd.fee\n ? encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInputSingle\", args: [{tokenIn: pd.tokenIn as Hex, tokenOut: pd.tokenOut as Hex, amountIn: BigInt(pd.amountIn), fee: Number(pd.fee), sqrtPriceLimitX96: 0n}]})\n : encodeFunctionData({abi: QUOTER_ABI, functionName: \"quoteExactInput\", args: [pd.path as Hex, BigInt(pd.amountIn)]});\n const [raw] = await rpc(chainId, [call(d.quoter, data)]);\n if (typeof raw !== \"string\" || raw === \"0x\") throw new Error(\"uniswap: the pool no longer quotes this route — refresh and try again\");\n const [out] = decodeFunctionResult({abi: QUOTER_ABI, functionName: pd.fee ? \"quoteExactInputSingle\" : \"quoteExactInput\", data: raw as Hex}) as readonly [bigint];\n if (out < BigInt(pd.minOut)) {\n throw new Error(`uniswap: price moved — the pool now pays ${out}, under your minimum ${pd.minOut}. Nothing was sent; refresh the quote.`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n const tx = quote.txRequest;\n if (!tx?.to || !tx.data) throw new Error(\"swap2: Uniswap quote has no transaction request\");\n return {\n chain: \"\",\n to: tx.to,\n value: tx.value ?? \"0\",\n data: tx.data,\n ...(tx.chainId !== undefined ? {chainId: tx.chainId} : {}),\n ...(tx.gasLimit ? {gasLimit: tx.gasLimit} : {}),\n ...(tx.approvalAddress ? {approvalAddress: tx.approvalAddress} : {}),\n };\n },\n\n /** Same-chain: the swap is done when its transaction is mined successfully. */\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n if (!ref.sourceTxHash) return {state: \"pending\"};\n const chainId = Number(ref.intentId.split(\":\")[1]);\n if (!deployments[chainId] || !config.rpcUrls[chainId]?.length) return {state: \"pending\"};\n try {\n const [receipt] = (await rpc(chainId, [{method: \"eth_getTransactionReceipt\", params: [ref.sourceTxHash]}])) as [{status?: string} | null];\n if (!receipt) return {state: \"pending\"};\n return receipt.status === \"0x1\" ? {state: \"completed\", destTxHash: ref.sourceTxHash} : {state: \"failed\"};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAQ,sBAAsB,oBAAoB,cAAc,YAAY,gBAAyB;AAErG,SAAQ,eAAc;AACtB,SAAQ,QAAQ,OA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AC,QAAQ,6BAA6B,QAAQ,CAAC,IAAI,YAAY,EAAC,CAAC,CAAC;AACzG,YAAI,CAAC,QAAS,QAAO,EAAC,OAAO,UAAS;AACtC,eAAO,QAAQ,WAAW,QAAQ,EAAC,OAAO,aAAa,YAAY,IAAI,aAAY,IAAI,EAAC,OAAO,SAAQ;AAAA,MACzG,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":["out","gas"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
uniswapProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ND647CPH.js";
|
|
4
4
|
import {
|
|
5
5
|
UNISWAP_V3
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BHGKOL3N.js";
|
|
7
7
|
|
|
8
8
|
// src/protocol.ts
|
|
9
9
|
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
@@ -29,4 +29,4 @@ var UniswapSwap2Protocol = class extends SingleProviderSwap2 {
|
|
|
29
29
|
export {
|
|
30
30
|
UniswapSwap2Protocol
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-OPFCIWX7.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
ADDRESS_THIS: () => ADDRESS_THIS,
|
|
24
24
|
FEE_TIERS: () => FEE_TIERS,
|
|
25
25
|
HOP_SYMBOLS: () => HOP_SYMBOLS,
|
|
26
|
+
ROUTER_ABI: () => ROUTER_ABI,
|
|
26
27
|
UNISWAP_MODULE: () => UNISWAP_MODULE,
|
|
27
28
|
UNISWAP_ROUTER_SELECTORS: () => UNISWAP_ROUTER_SELECTORS,
|
|
28
29
|
UNISWAP_V3: () => UNISWAP_V3,
|
|
@@ -30,11 +31,14 @@ __export(src_exports, {
|
|
|
30
31
|
default: () => UniswapSwap2Protocol,
|
|
31
32
|
describeUniswapActivity: () => describeUniswapActivity,
|
|
32
33
|
uniswapPins: () => uniswapPins,
|
|
33
|
-
uniswapProvider: () => uniswapProvider
|
|
34
|
+
uniswapProvider: () => uniswapProvider,
|
|
35
|
+
uniswapVerifyQuote: () => uniswapVerifyQuote
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(src_exports);
|
|
36
38
|
|
|
37
39
|
// src/addresses.ts
|
|
40
|
+
var import_viem = require("viem");
|
|
41
|
+
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
38
42
|
var UNISWAP_V3 = Object.freeze({
|
|
39
43
|
1: { factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984", quoter: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e", router: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45", weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" },
|
|
40
44
|
10: { factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984", quoter: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e", router: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45", weth: "0x4200000000000000000000000000000000000006" },
|
|
@@ -62,9 +66,85 @@ var UNISWAP_V3 = Object.freeze({
|
|
|
62
66
|
var FEE_TIERS = [100, 500, 3e3, 1e4];
|
|
63
67
|
var HOP_SYMBOLS = ["WETH", "USDC", "USDT"];
|
|
64
68
|
var ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
|
|
69
|
+
var ROUTER_ABI = (0, import_viem.parseAbi)([
|
|
70
|
+
"function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountOut)",
|
|
71
|
+
"function exactInput((bytes path, address recipient, uint256 amountIn, uint256 amountOutMinimum) params) payable returns (uint256 amountOut)",
|
|
72
|
+
"function unwrapWETH9(uint256 amountMinimum, address recipient) payable",
|
|
73
|
+
"function multicall(uint256 deadline, bytes[] data) payable returns (bytes[] results)",
|
|
74
|
+
"function factory() view returns (address)",
|
|
75
|
+
"function WETH9() view returns (address)"
|
|
76
|
+
]);
|
|
77
|
+
var MAX_PATH_POOLS = 2;
|
|
78
|
+
function uniswapVerifyQuote(params, quote) {
|
|
79
|
+
const id = /^eip155:[0-9]+$/.test(params.sourceChain) ? Number(params.sourceChain.slice(7)) : NaN;
|
|
80
|
+
const d = Object.prototype.hasOwnProperty.call(UNISWAP_V3, id) ? UNISWAP_V3[id] : void 0;
|
|
81
|
+
if (!d || params.destChain !== params.sourceChain) return "not a same-chain swap on a pinned Uniswap deployment";
|
|
82
|
+
const tx = quote.txRequest;
|
|
83
|
+
if (!tx?.data || !tx.to || tx.serializedTx !== void 0) return "the quote carries no router call";
|
|
84
|
+
if ((0, import_viem.getAddress)(tx.to) !== (0, import_viem.getAddress)(d.router)) return `the call targets ${tx.to}, not the SwapRouter`;
|
|
85
|
+
const src = (0, import_util.sourceAssetOf)(params);
|
|
86
|
+
if (!src) return `unknown source token ${params.sourceToken}`;
|
|
87
|
+
const nativeIn = !src.contract;
|
|
88
|
+
const nativeOut = /^0x0+$/.test(params.destToken);
|
|
89
|
+
if ((nativeIn || nativeOut) && d.nativeWrap === false) return "this chain's router has no wrapped native";
|
|
90
|
+
let tokenIn, tokenOut, recipient, amountIn, minOut;
|
|
91
|
+
try {
|
|
92
|
+
tokenIn = (0, import_viem.getAddress)(nativeIn ? d.weth : src.contract);
|
|
93
|
+
tokenOut = (0, import_viem.getAddress)(nativeOut ? d.weth : params.destToken);
|
|
94
|
+
recipient = (0, import_viem.getAddress)(params.destAddress);
|
|
95
|
+
amountIn = BigInt(params.amountIn);
|
|
96
|
+
minOut = BigInt(quote.minDestAmount);
|
|
97
|
+
} catch {
|
|
98
|
+
return "the request does not name EVM tokens, a recipient and amounts";
|
|
99
|
+
}
|
|
100
|
+
if (nativeIn ? BigInt(tx.value ?? "0") !== amountIn || tx.approvalAddress !== void 0 : BigInt(tx.value ?? "0") !== 0n || !tx.approvalAddress || (0, import_viem.getAddress)(tx.approvalAddress) !== (0, import_viem.getAddress)(d.router)) {
|
|
101
|
+
return nativeIn ? "a native input is paid as exactly the input in value, with no approval" : "a token input attaches no value and approves the SwapRouter";
|
|
102
|
+
}
|
|
103
|
+
let legs;
|
|
104
|
+
try {
|
|
105
|
+
const outer = (0, import_viem.decodeFunctionData)({ abi: ROUTER_ABI, data: tx.data });
|
|
106
|
+
if (outer.functionName !== "multicall") return `${outer.functionName} is not multicall(deadline, legs)`;
|
|
107
|
+
legs = outer.args[1];
|
|
108
|
+
} catch {
|
|
109
|
+
return "the router call is not multicall(deadline, legs)";
|
|
110
|
+
}
|
|
111
|
+
if (legs.length !== (nativeOut ? 2 : 1)) return `the multicall has ${legs.length} legs, not a swap${nativeOut ? " and an unwrap" : ""}`;
|
|
112
|
+
const decode = (leg) => {
|
|
113
|
+
try {
|
|
114
|
+
return (0, import_viem.decodeFunctionData)({ abi: ROUTER_ABI, data: leg });
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const swap = decode(legs[0]);
|
|
120
|
+
const swapTo = nativeOut ? ADDRESS_THIS : recipient;
|
|
121
|
+
if (swap?.functionName === "exactInputSingle") {
|
|
122
|
+
const a = swap.args[0];
|
|
123
|
+
if ((0, import_viem.getAddress)(a.tokenIn) !== tokenIn || (0, import_viem.getAddress)(a.tokenOut) !== tokenOut) return "the swap trades other tokens";
|
|
124
|
+
if (a.amountIn !== amountIn || a.amountOutMinimum !== minOut || a.sqrtPriceLimitX96 !== 0n) return "the swap's input, minimum or price limit is not the quote's";
|
|
125
|
+
if ((0, import_viem.getAddress)(a.recipient) !== (0, import_viem.getAddress)(swapTo)) return `the swap pays ${a.recipient}, not the recipient`;
|
|
126
|
+
} else if (swap?.functionName === "exactInput") {
|
|
127
|
+
const a = swap.args[0];
|
|
128
|
+
const path = a.path.slice(2);
|
|
129
|
+
const pools = (path.length / 2 - 20) / 23;
|
|
130
|
+
if (!/^[0-9a-fA-F]*$/.test(path) || !Number.isInteger(pools) || pools < 1 || pools > MAX_PATH_POOLS) return "the swap path is not 1\u20132 pools";
|
|
131
|
+
if ((0, import_viem.getAddress)(`0x${path.slice(0, 40)}`) !== tokenIn || (0, import_viem.getAddress)(`0x${path.slice(-40)}`) !== tokenOut) return "the swap path trades other tokens";
|
|
132
|
+
if (a.amountIn !== amountIn || a.amountOutMinimum !== minOut) return "the swap's input or minimum is not the quote's";
|
|
133
|
+
if ((0, import_viem.getAddress)(a.recipient) !== (0, import_viem.getAddress)(swapTo)) return `the swap pays ${a.recipient}, not the recipient`;
|
|
134
|
+
} else {
|
|
135
|
+
return `${swap?.functionName ?? "an unknown call"} is not exactInputSingle / exactInput`;
|
|
136
|
+
}
|
|
137
|
+
if (nativeOut) {
|
|
138
|
+
const unwrap = decode(legs[1]);
|
|
139
|
+
if (unwrap?.functionName !== "unwrapWETH9") return `${unwrap?.functionName ?? "an unknown call"} is not unwrapWETH9`;
|
|
140
|
+
if (unwrap.args[0] !== minOut || (0, import_viem.getAddress)(unwrap.args[1]) !== recipient) return "the unwrap pays someone else or less than the minimum";
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
65
144
|
var uniswapPins = Object.freeze({
|
|
66
145
|
callTargets: (chain) => uniswapRouterFor(chain),
|
|
67
|
-
spenders: (chain) => uniswapRouterFor(chain)
|
|
146
|
+
spenders: (chain) => uniswapRouterFor(chain),
|
|
147
|
+
verifyQuote: uniswapVerifyQuote
|
|
68
148
|
});
|
|
69
149
|
function uniswapRouterFor(chain) {
|
|
70
150
|
const id = /^eip155:[0-9]+$/.test(chain) ? Number(chain.slice(7)) : NaN;
|
|
@@ -73,11 +153,11 @@ function uniswapRouterFor(chain) {
|
|
|
73
153
|
}
|
|
74
154
|
|
|
75
155
|
// src/provider.ts
|
|
76
|
-
var
|
|
156
|
+
var import_viem2 = require("viem");
|
|
77
157
|
|
|
78
158
|
// src/activity.ts
|
|
79
159
|
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
80
|
-
var
|
|
160
|
+
var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
|
|
81
161
|
var UNISWAP_MODULE = "@anywalletkit/protocol-swap2-uniswap";
|
|
82
162
|
var UNISWAP_ROUTER_SELECTORS = /* @__PURE__ */ new Set([
|
|
83
163
|
"0x5ae401dc",
|
|
@@ -96,34 +176,26 @@ var UNISWAP_ROUTER_SELECTORS = /* @__PURE__ */ new Set([
|
|
|
96
176
|
// exactOutput((bytes,address,uint256,uint256))
|
|
97
177
|
]);
|
|
98
178
|
function describeUniswapActivity(tx, ctx, deployments = UNISWAP_V3) {
|
|
99
|
-
if (!(0,
|
|
100
|
-
const deployment = deployments[(0,
|
|
179
|
+
if (!(0, import_util2.isEvm)(tx.chain)) return null;
|
|
180
|
+
const deployment = deployments[(0, import_util2.evmRef)(tx.chain)];
|
|
101
181
|
if (!deployment || !(0, import_activity.matchesCall)(tx, [deployment.router], UNISWAP_ROUTER_SELECTORS)) return null;
|
|
102
182
|
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: UNISWAP_MODULE, subtitle: `Uniswap v3 \xB7 ${(0, import_activity.chainLabel)(tx.chain)}`, kind: "swap" });
|
|
103
183
|
}
|
|
104
184
|
|
|
105
185
|
// src/provider.ts
|
|
106
186
|
var import_swap2_assets = require("@anywalletkit/swap2-assets");
|
|
107
|
-
var
|
|
187
|
+
var import_util3 = require("@anywalletkit/protocol-swap2-core/util");
|
|
108
188
|
var import_core = require("@anywalletkit/core");
|
|
109
189
|
var ZERO = "0x0000000000000000000000000000000000000000";
|
|
110
190
|
var DEFAULT_SLIPPAGE_BPS = 50;
|
|
111
191
|
var DEFAULT_TTL_MS = 3e5;
|
|
112
192
|
var DEFAULT_DEADLINE_S = 600;
|
|
113
|
-
var QUOTER_ABI = (0,
|
|
193
|
+
var QUOTER_ABI = (0, import_viem2.parseAbi)([
|
|
114
194
|
"function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96) params) returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
|
|
115
195
|
"function quoteExactInput(bytes path, uint256 amountIn) returns (uint256 amountOut, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)",
|
|
116
196
|
"function factory() view returns (address)",
|
|
117
197
|
"function WETH9() view returns (address)"
|
|
118
198
|
]);
|
|
119
|
-
var ROUTER_ABI = (0, import_viem.parseAbi)([
|
|
120
|
-
"function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountOut)",
|
|
121
|
-
"function exactInput((bytes path, address recipient, uint256 amountIn, uint256 amountOutMinimum) params) payable returns (uint256 amountOut)",
|
|
122
|
-
"function unwrapWETH9(uint256 amountMinimum, address recipient) payable",
|
|
123
|
-
"function multicall(uint256 deadline, bytes[] data) payable returns (bytes[] results)",
|
|
124
|
-
"function factory() view returns (address)",
|
|
125
|
-
"function WETH9() view returns (address)"
|
|
126
|
-
]);
|
|
127
199
|
var RPC_BATCH_MAX = 10;
|
|
128
200
|
function uniswapProvider(config) {
|
|
129
201
|
const deployments = config.deployments ?? UNISWAP_V3;
|
|
@@ -133,8 +205,8 @@ function uniswapProvider(config) {
|
|
|
133
205
|
if (!Number.isInteger(slippageDefault) || slippageDefault <= 0 || slippageDefault >= 5e3) throw new Error("uniswap: defaultSlippageBps must be 1..4999");
|
|
134
206
|
const verified = /* @__PURE__ */ new Map();
|
|
135
207
|
const chainIdOf = (caip2) => {
|
|
136
|
-
if (!(0,
|
|
137
|
-
const id = (0,
|
|
208
|
+
if (!(0, import_util3.isEvm)(caip2)) return null;
|
|
209
|
+
const id = (0, import_util3.evmRef)(caip2);
|
|
138
210
|
return deployments[id] && config.rpcUrls[id]?.length ? id : null;
|
|
139
211
|
};
|
|
140
212
|
async function rpc(chainId, calls, signal) {
|
|
@@ -151,7 +223,7 @@ function uniswapProvider(config) {
|
|
|
151
223
|
method: "POST",
|
|
152
224
|
headers: { "content-type": "application/json" },
|
|
153
225
|
body: JSON.stringify(calls.map((c, id) => ({ jsonrpc: "2.0", id, ...c }))),
|
|
154
|
-
signal: signal ?? (0,
|
|
226
|
+
signal: signal ?? (0, import_util3.timeoutSignal)(12e3)
|
|
155
227
|
});
|
|
156
228
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
157
229
|
const body = await res.json();
|
|
@@ -171,12 +243,12 @@ function uniswapProvider(config) {
|
|
|
171
243
|
if (!p) {
|
|
172
244
|
const d = deployments[chainId];
|
|
173
245
|
p = (async () => {
|
|
174
|
-
const f = (0,
|
|
175
|
-
const w = (0,
|
|
246
|
+
const f = (0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "factory" });
|
|
247
|
+
const w = (0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "WETH9" });
|
|
176
248
|
const [rf, rw, qf, qw] = await rpc(chainId, [call(d.router, f), call(d.router, w), call(d.quoter, f), call(d.quoter, w)]);
|
|
177
|
-
const addr = (r) => typeof r === "string" && r.length >= 42 ? (0,
|
|
178
|
-
const wrapped = d.nativeWrap === false ? (0,
|
|
179
|
-
const ok = [rf, qf].every((r) => addr(r) === (0,
|
|
249
|
+
const addr = (r) => typeof r === "string" && r.length >= 42 ? (0, import_viem2.getAddress)(`0x${r.slice(-40)}`) : null;
|
|
250
|
+
const wrapped = d.nativeWrap === false ? (0, import_viem2.getAddress)(ZERO) : (0, import_viem2.getAddress)(d.weth);
|
|
251
|
+
const ok = [rf, qf].every((r) => addr(r) === (0, import_viem2.getAddress)(d.factory)) && addr(rw) === wrapped && (d.quoterWeth === false || addr(qw) === wrapped);
|
|
180
252
|
if (!ok) throw new Error(`uniswap: the router/quoter on chain ${chainId} do not match the pinned deployment \u2014 refusing`);
|
|
181
253
|
})();
|
|
182
254
|
p.catch(() => verified.delete(chainId));
|
|
@@ -191,12 +263,12 @@ function uniswapProvider(config) {
|
|
|
191
263
|
for (const sym of HOP_SYMBOLS) {
|
|
192
264
|
const mid = sym === "WETH" ? d.weth : (0, import_swap2_assets.ccAsset)(caip2, sym)?.contract;
|
|
193
265
|
if (!mid || !/^0x[0-9a-fA-F]{40}$/.test(mid)) continue;
|
|
194
|
-
const m = (0,
|
|
195
|
-
if (m === (0,
|
|
266
|
+
const m = (0, import_viem2.getAddress)(mid);
|
|
267
|
+
if (m === (0, import_viem2.getAddress)(tokenIn) || m === (0, import_viem2.getAddress)(tokenOut) || mids.has(m)) continue;
|
|
196
268
|
mids.add(m);
|
|
197
269
|
for (const f1 of [100, 500, 3e3]) {
|
|
198
270
|
for (const f2 of [100, 500, 3e3]) {
|
|
199
|
-
out.push({ label: `via ${sym} ${f1 / 1e4}% \u2192 ${f2 / 1e4}%`, poolFee: `${f1 / 1e4}% + ${f2 / 1e4}%`, path: (0,
|
|
271
|
+
out.push({ label: `via ${sym} ${f1 / 1e4}% \u2192 ${f2 / 1e4}%`, poolFee: `${f1 / 1e4}% + ${f2 / 1e4}%`, path: (0, import_viem2.encodePacked)(["address", "uint24", "address", "uint24", "address"], [tokenIn, f1, m, f2, tokenOut]) });
|
|
200
272
|
}
|
|
201
273
|
}
|
|
202
274
|
}
|
|
@@ -222,7 +294,7 @@ function uniswapProvider(config) {
|
|
|
222
294
|
const chainId = chainIdOf(params.sourceChain);
|
|
223
295
|
if (chainId === null) return refuse(`no Uniswap v3 deployment or RPC for ${params.sourceChain}`);
|
|
224
296
|
const d = deployments[chainId];
|
|
225
|
-
const src = (0,
|
|
297
|
+
const src = (0, import_util3.sourceAssetOf)(params);
|
|
226
298
|
if (!src) return refuse(`unknown source token ${params.sourceToken}`);
|
|
227
299
|
const nativeIn = !src.contract;
|
|
228
300
|
const nativeOut = /^0x0+$/.test(params.destToken);
|
|
@@ -236,8 +308,8 @@ function uniswapProvider(config) {
|
|
|
236
308
|
return refuse("amount is not an integer");
|
|
237
309
|
}
|
|
238
310
|
if (amountIn <= 0n) return refuse("amount must be positive");
|
|
239
|
-
const tokenIn = (0,
|
|
240
|
-
const tokenOut = (0,
|
|
311
|
+
const tokenIn = (0, import_viem2.getAddress)(nativeIn ? d.weth : src.contract);
|
|
312
|
+
const tokenOut = (0, import_viem2.getAddress)(nativeOut ? d.weth : params.destToken);
|
|
241
313
|
if (tokenIn === tokenOut) return refuse(nativeIn || nativeOut ? "that is a wrap/unwrap, not a swap" : "same token in and out");
|
|
242
314
|
try {
|
|
243
315
|
await verifyDeployment(chainId);
|
|
@@ -247,7 +319,7 @@ function uniswapProvider(config) {
|
|
|
247
319
|
candidates.map(
|
|
248
320
|
(r) => call(
|
|
249
321
|
d.quoter,
|
|
250
|
-
r.single ? (0,
|
|
322
|
+
r.single ? (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInputSingle", args: [{ tokenIn, tokenOut, amountIn, fee: r.single.fee, sqrtPriceLimitX96: 0n }] }) : (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInput", args: [r.path, amountIn] })
|
|
251
323
|
)
|
|
252
324
|
),
|
|
253
325
|
signal
|
|
@@ -257,7 +329,7 @@ function uniswapProvider(config) {
|
|
|
257
329
|
if (typeof raw !== "string" || raw === "0x") return;
|
|
258
330
|
const r = candidates[i];
|
|
259
331
|
try {
|
|
260
|
-
const [out2, , , gas2] = (0,
|
|
332
|
+
const [out2, , , gas2] = (0, import_viem2.decodeFunctionResult)({ abi: QUOTER_ABI, functionName: r.single ? "quoteExactInputSingle" : "quoteExactInput", data: raw });
|
|
261
333
|
if (out2 > 0n && (!best || out2 > best.out)) best = { route: r, out: out2, gas: gas2 };
|
|
262
334
|
} catch {
|
|
263
335
|
}
|
|
@@ -270,11 +342,11 @@ function uniswapProvider(config) {
|
|
|
270
342
|
try {
|
|
271
343
|
const [raw] = await rpc(
|
|
272
344
|
chainId,
|
|
273
|
-
[call(d.quoter, route.single ? (0,
|
|
345
|
+
[call(d.quoter, route.single ? (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInputSingle", args: [{ tokenIn, tokenOut, amountIn: probeIn, fee: route.single.fee, sqrtPriceLimitX96: 0n }] }) : (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInput", args: [route.path, probeIn] }))],
|
|
274
346
|
signal
|
|
275
347
|
);
|
|
276
348
|
if (typeof raw === "string" && raw !== "0x") {
|
|
277
|
-
const [probeOut] = (0,
|
|
349
|
+
const [probeOut] = (0, import_viem2.decodeFunctionResult)({ abi: QUOTER_ABI, functionName: route.single ? "quoteExactInputSingle" : "quoteExactInput", data: raw });
|
|
278
350
|
if (probeOut > 0n) {
|
|
279
351
|
const ratioBps = out * probeIn * 10000n / (probeOut * amountIn);
|
|
280
352
|
priceImpactBps = Math.max(0, (0, import_core.bigintToNumber)(10000n - ratioBps));
|
|
@@ -288,13 +360,13 @@ function uniswapProvider(config) {
|
|
|
288
360
|
if (params.minAmountOut !== void 0 && minOut < BigInt(params.minAmountOut)) {
|
|
289
361
|
return refuse(`floor breach (min=${minOut} < floor=${params.minAmountOut})`);
|
|
290
362
|
}
|
|
291
|
-
const recipient = (0,
|
|
363
|
+
const recipient = (0, import_viem2.getAddress)(params.destAddress);
|
|
292
364
|
const swapTo = nativeOut ? ADDRESS_THIS : recipient;
|
|
293
|
-
const swap = route.single ? (0,
|
|
365
|
+
const swap = route.single ? (0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "exactInputSingle", args: [{ tokenIn, tokenOut, fee: route.single.fee, recipient: swapTo, amountIn, amountOutMinimum: minOut, sqrtPriceLimitX96: 0n }] }) : (0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "exactInput", args: [{ path: route.path, recipient: swapTo, amountIn, amountOutMinimum: minOut }] });
|
|
294
366
|
const legs = [swap];
|
|
295
|
-
if (nativeOut) legs.push((0,
|
|
367
|
+
if (nativeOut) legs.push((0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "unwrapWETH9", args: [minOut, recipient] }));
|
|
296
368
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + deadlineS);
|
|
297
|
-
const data = (0,
|
|
369
|
+
const data = (0, import_viem2.encodeFunctionData)({ abi: ROUTER_ABI, functionName: "multicall", args: [deadline, legs] });
|
|
298
370
|
const gasLimit = gas * 3n / 2n + 120000n + (nativeOut ? 40000n : 0n);
|
|
299
371
|
return {
|
|
300
372
|
provider: "uniswap",
|
|
@@ -342,10 +414,10 @@ function uniswapProvider(config) {
|
|
|
342
414
|
const d = deployments[chainId];
|
|
343
415
|
const pd = quote.providerData ?? {};
|
|
344
416
|
if (!d || !pd.amountIn || !pd.minOut || !pd.tokenIn || !pd.tokenOut) return;
|
|
345
|
-
const data = pd.fee ? (0,
|
|
417
|
+
const data = pd.fee ? (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInputSingle", args: [{ tokenIn: pd.tokenIn, tokenOut: pd.tokenOut, amountIn: BigInt(pd.amountIn), fee: Number(pd.fee), sqrtPriceLimitX96: 0n }] }) : (0, import_viem2.encodeFunctionData)({ abi: QUOTER_ABI, functionName: "quoteExactInput", args: [pd.path, BigInt(pd.amountIn)] });
|
|
346
418
|
const [raw] = await rpc(chainId, [call(d.quoter, data)]);
|
|
347
419
|
if (typeof raw !== "string" || raw === "0x") throw new Error("uniswap: the pool no longer quotes this route \u2014 refresh and try again");
|
|
348
|
-
const [out] = (0,
|
|
420
|
+
const [out] = (0, import_viem2.decodeFunctionResult)({ abi: QUOTER_ABI, functionName: pd.fee ? "quoteExactInputSingle" : "quoteExactInput", data: raw });
|
|
349
421
|
if (out < BigInt(pd.minOut)) {
|
|
350
422
|
throw new Error(`uniswap: price moved \u2014 the pool now pays ${out}, under your minimum ${pd.minOut}. Nothing was sent; refresh the quote.`);
|
|
351
423
|
}
|
|
@@ -381,7 +453,7 @@ function uniswapProvider(config) {
|
|
|
381
453
|
|
|
382
454
|
// src/protocol.ts
|
|
383
455
|
var import_single = require("@anywalletkit/protocol-swap2-core/swap2/single");
|
|
384
|
-
var
|
|
456
|
+
var import_util4 = require("@anywalletkit/protocol-swap2-core/util");
|
|
385
457
|
var UniswapSwap2Protocol = class extends import_single.SingleProviderSwap2 {
|
|
386
458
|
provider;
|
|
387
459
|
_rpcUrls;
|
|
@@ -393,7 +465,7 @@ var UniswapSwap2Protocol = class extends import_single.SingleProviderSwap2 {
|
|
|
393
465
|
this._deployments = config.deployments ?? UNISWAP_V3;
|
|
394
466
|
}
|
|
395
467
|
chainSupported(caip2) {
|
|
396
|
-
return (0,
|
|
468
|
+
return (0, import_util4.isEvm)(caip2) && !!this._deployments[(0, import_util4.evmRef)(caip2)] && !!this._rpcUrls[(0, import_util4.evmRef)(caip2)]?.length;
|
|
397
469
|
}
|
|
398
470
|
pairSupported(fromChain, toChain) {
|
|
399
471
|
return fromChain === toChain && this.chainSupported(fromChain);
|