@seer-pm/lens 1.0.0 → 1.1.0
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/dist/chunk-BW3R2UBK.js +69 -0
- package/dist/chunk-BW3R2UBK.js.map +1 -0
- package/dist/client.cjs +264 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +40 -0
- package/dist/client.d.ts +7 -5
- package/dist/client.js +172 -148
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +99 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +82 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +18 -63
- package/dist/index.js.map +1 -0
- package/package.json +21 -7
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var AMM = /* @__PURE__ */ ((AMM2) => {
|
|
3
|
+
AMM2[AMM2["UNI_V3"] = 0] = "UNI_V3";
|
|
4
|
+
AMM2[AMM2["UNI_V4"] = 1] = "UNI_V4";
|
|
5
|
+
AMM2[AMM2["UNI_V4_HOOKED"] = 2] = "UNI_V4_HOOKED";
|
|
6
|
+
AMM2[AMM2["SWAPR_V3"] = 3] = "SWAPR_V3";
|
|
7
|
+
return AMM2;
|
|
8
|
+
})(AMM || {});
|
|
9
|
+
var AMM_NAMES = {
|
|
10
|
+
[0 /* UNI_V3 */]: "Uniswap V3",
|
|
11
|
+
[1 /* UNI_V4 */]: "Uniswap V4",
|
|
12
|
+
[2 /* UNI_V4_HOOKED */]: "Uniswap V4 Hooked",
|
|
13
|
+
[3 /* SWAPR_V3 */]: "Swapr V3"
|
|
14
|
+
};
|
|
15
|
+
var LENS_QUOTER_ABI = [
|
|
16
|
+
"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
17
|
+
"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
18
|
+
"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)",
|
|
19
|
+
"function V3_SWAP_ROUTER() view returns (address)",
|
|
20
|
+
"function V4_ROUTER() view returns (address)",
|
|
21
|
+
"function SWAPR_SWAP_ROUTER() view returns (address)",
|
|
22
|
+
"function V4_QUOTER() view returns (address)"
|
|
23
|
+
];
|
|
24
|
+
var CHAINS = {
|
|
25
|
+
1: {
|
|
26
|
+
lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA",
|
|
27
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
28
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
29
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
30
|
+
wnative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
31
|
+
},
|
|
32
|
+
10: {
|
|
33
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
34
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
35
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
36
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
37
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
38
|
+
},
|
|
39
|
+
100: {
|
|
40
|
+
lensQuoter: "0xEe7596551a8339674d9Ee4B05b1A8E49cf738825",
|
|
41
|
+
v3SwapRouter: "0x0000000000000000000000000000000000000000",
|
|
42
|
+
v4Router: "0x0000000000000000000000000000000000000000",
|
|
43
|
+
swaprSwapRouter: "0xfFB643E73f280B97809A8b41f7232AB401a04ee1",
|
|
44
|
+
wnative: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"
|
|
45
|
+
},
|
|
46
|
+
8453: {
|
|
47
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
48
|
+
v3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
|
|
49
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
50
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
51
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var ETH = "0x0000000000000000000000000000000000000000";
|
|
55
|
+
var GNOSIS_sDAI = "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
56
|
+
function defaultDeadline() {
|
|
57
|
+
return BigInt(Math.trunc(Date.now() / 1e3) + 300);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
AMM,
|
|
62
|
+
AMM_NAMES,
|
|
63
|
+
LENS_QUOTER_ABI,
|
|
64
|
+
CHAINS,
|
|
65
|
+
ETH,
|
|
66
|
+
GNOSIS_sDAI,
|
|
67
|
+
defaultDeadline
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-BW3R2UBK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Lens SDK — Core constants, ABIs, types, token list (zero dependencies)\n\n// ---- Chain config ----\n\n/** Unified AMM enum (same ordinals on every chain). */\nexport enum AMM {\n UNI_V3 = 0,\n UNI_V4 = 1,\n UNI_V4_HOOKED = 2,\n SWAPR_V3 = 3,\n}\n\nexport const AMM_NAMES: Record<AMM, string> = {\n [AMM.UNI_V3]: \"Uniswap V3\",\n [AMM.UNI_V4]: \"Uniswap V4\",\n [AMM.UNI_V4_HOOKED]: \"Uniswap V4 Hooked\",\n [AMM.SWAPR_V3]: \"Swapr V3\",\n};\n\n/** Shared LensQuoter ABI for the unified contract on all chains. */\nexport const LENS_QUOTER_ABI = [\n \"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)\",\n \"function V3_SWAP_ROUTER() view returns (address)\",\n \"function V4_ROUTER() view returns (address)\",\n \"function SWAPR_SWAP_ROUTER() view returns (address)\",\n \"function V4_QUOTER() view returns (address)\",\n] as const;\n\n/** Per-chain LensQuoter, official DEX routers, and wrapped native. */\nexport const CHAINS = {\n 1: {\n lensQuoter: \"0xae300296486a63621f7f31E1B94aD22d32347deA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\",\n },\n 10: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n 100: {\n lensQuoter: \"0xEe7596551a8339674d9Ee4B05b1A8E49cf738825\",\n v3SwapRouter: \"0x0000000000000000000000000000000000000000\",\n v4Router: \"0x0000000000000000000000000000000000000000\",\n swaprSwapRouter: \"0xfFB643E73f280B97809A8b41f7232AB401a04ee1\",\n wnative: \"0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d\",\n },\n 8453: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x2626664c2603336E57B271c5C0b26F421741e481\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n} as const;\n\nexport type ChainId = keyof typeof CHAINS;\n\nexport const ETH = \"0x0000000000000000000000000000000000000000\" as const;\n\n/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */\nexport const GNOSIS_sDAI = \"0xaf204776c7245bF4147c2612BF6e5972Ee483701\" as const;\n\n// ---- Types ----\n\nexport interface QuoteResult {\n amountIn: bigint;\n amountOut: bigint;\n /** Official DEX router to call. */\n target: string;\n /** Ready-to-send calldata for `target`. */\n data: string;\n msgValue: bigint;\n isTwoHop: boolean;\n sourceA: string;\n sourceB: string | null;\n}\n\nexport interface BaseQuoteParams {\n tokenIn: string;\n tokenOut: string;\n amount: bigint;\n}\n\nexport interface QuoteParams extends BaseQuoteParams {\n recipient: string;\n slippageBps?: number;\n deadline?: bigint;\n /** false = exactIn (default); true = exactOut. `amount` is amountIn or desired amountOut accordingly. */\n exactOut?: boolean;\n /** Optional V4 hooked-pool candidate (exactIn; can beat the primary route). */\n hookPoolFee?: number;\n hookTickSpacing?: number;\n hookAddress?: string;\n /**\n * Intermediate token for two-hop routes (`buildBestSwapViaToken`).\n * When set, skips the native/ERC20 cascade. On Gnosis, native/WXDAI↔ERC20\n * already defaults to ViaToken(sDAI); use this only to force a different mid.\n */\n intermediate?: string;\n}\n\n// ---- Helpers ----\n\nexport function defaultDeadline(): bigint {\n return BigInt(Math.trunc(Date.now() / 1000) + 300);\n}\n"],"mappings":";AAKO,IAAK,MAAL,kBAAKA,SAAL;AACL,EAAAA,UAAA,YAAS,KAAT;AACA,EAAAA,UAAA,YAAS,KAAT;AACA,EAAAA,UAAA,mBAAgB,KAAhB;AACA,EAAAA,UAAA,cAAW,KAAX;AAJU,SAAAA;AAAA,GAAA;AAOL,IAAM,YAAiC;AAAA,EAC5C,CAAC,cAAU,GAAG;AAAA,EACd,CAAC,cAAU,GAAG;AAAA,EACd,CAAC,qBAAiB,GAAG;AAAA,EACrB,CAAC,gBAAY,GAAG;AAClB;AAGO,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,SAAS;AAAA,EACpB,GAAG;AAAA,IACD,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,IAAI;AAAA,IACF,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,KAAK;AAAA,IACH,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,MAAM;AAAA,IACJ,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AACF;AAIO,IAAM,MAAM;AAGZ,IAAM,cAAc;AA2CpB,SAAS,kBAA0B;AACxC,SAAO,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI,GAAG;AACnD;","names":["AMM"]}
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
AMM: () => AMM,
|
|
24
|
+
AMM_NAMES: () => AMM_NAMES,
|
|
25
|
+
CHAINS: () => CHAINS,
|
|
26
|
+
ETH: () => ETH,
|
|
27
|
+
GNOSIS_sDAI: () => GNOSIS_sDAI,
|
|
28
|
+
LENS_QUOTER_ABI: () => LENS_QUOTER_ABI,
|
|
29
|
+
Lens: () => Lens,
|
|
30
|
+
defaultDeadline: () => defaultDeadline
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(client_exports);
|
|
33
|
+
var import_viem = require("viem");
|
|
34
|
+
|
|
35
|
+
// src/index.ts
|
|
36
|
+
var AMM = /* @__PURE__ */ ((AMM2) => {
|
|
37
|
+
AMM2[AMM2["UNI_V3"] = 0] = "UNI_V3";
|
|
38
|
+
AMM2[AMM2["UNI_V4"] = 1] = "UNI_V4";
|
|
39
|
+
AMM2[AMM2["UNI_V4_HOOKED"] = 2] = "UNI_V4_HOOKED";
|
|
40
|
+
AMM2[AMM2["SWAPR_V3"] = 3] = "SWAPR_V3";
|
|
41
|
+
return AMM2;
|
|
42
|
+
})(AMM || {});
|
|
43
|
+
var AMM_NAMES = {
|
|
44
|
+
[0 /* UNI_V3 */]: "Uniswap V3",
|
|
45
|
+
[1 /* UNI_V4 */]: "Uniswap V4",
|
|
46
|
+
[2 /* UNI_V4_HOOKED */]: "Uniswap V4 Hooked",
|
|
47
|
+
[3 /* SWAPR_V3 */]: "Swapr V3"
|
|
48
|
+
};
|
|
49
|
+
var LENS_QUOTER_ABI = [
|
|
50
|
+
"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
51
|
+
"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
52
|
+
"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)",
|
|
53
|
+
"function V3_SWAP_ROUTER() view returns (address)",
|
|
54
|
+
"function V4_ROUTER() view returns (address)",
|
|
55
|
+
"function SWAPR_SWAP_ROUTER() view returns (address)",
|
|
56
|
+
"function V4_QUOTER() view returns (address)"
|
|
57
|
+
];
|
|
58
|
+
var CHAINS = {
|
|
59
|
+
1: {
|
|
60
|
+
lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA",
|
|
61
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
62
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
63
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
64
|
+
wnative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
65
|
+
},
|
|
66
|
+
10: {
|
|
67
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
68
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
69
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
70
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
71
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
72
|
+
},
|
|
73
|
+
100: {
|
|
74
|
+
lensQuoter: "0xEe7596551a8339674d9Ee4B05b1A8E49cf738825",
|
|
75
|
+
v3SwapRouter: "0x0000000000000000000000000000000000000000",
|
|
76
|
+
v4Router: "0x0000000000000000000000000000000000000000",
|
|
77
|
+
swaprSwapRouter: "0xfFB643E73f280B97809A8b41f7232AB401a04ee1",
|
|
78
|
+
wnative: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"
|
|
79
|
+
},
|
|
80
|
+
8453: {
|
|
81
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
82
|
+
v3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
|
|
83
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
84
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
85
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var ETH = "0x0000000000000000000000000000000000000000";
|
|
89
|
+
var GNOSIS_sDAI = "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
90
|
+
function defaultDeadline() {
|
|
91
|
+
return BigInt(Math.trunc(Date.now() / 1e3) + 300);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/client.ts
|
|
95
|
+
var QUOTE_TUPLE = "tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut)";
|
|
96
|
+
var QUOTE_STRUCT = "struct Quote { uint8 source; uint256 feeBps; uint256 amountIn; uint256 amountOut; }";
|
|
97
|
+
var toQuoterAbi = (lines) => (0, import_viem.parseAbi)([QUOTE_STRUCT, ...lines.map((l) => l.split(QUOTE_TUPLE).join("Quote"))]);
|
|
98
|
+
var quoterAbi = toQuoterAbi(LENS_QUOTER_ABI);
|
|
99
|
+
var DEFAULT_SLIPPAGE = 50;
|
|
100
|
+
function ammName(source) {
|
|
101
|
+
return AMM_NAMES[source] || `AMM #${source}`;
|
|
102
|
+
}
|
|
103
|
+
function mapViaResult(value) {
|
|
104
|
+
const [a, b, target, data, msgValue] = value;
|
|
105
|
+
const isTwoHop = b.amountOut > 0n;
|
|
106
|
+
return {
|
|
107
|
+
amountIn: a.amountIn,
|
|
108
|
+
amountOut: isTwoHop ? b.amountOut : a.amountOut,
|
|
109
|
+
target,
|
|
110
|
+
data,
|
|
111
|
+
msgValue: msgValue ?? 0n,
|
|
112
|
+
isTwoHop,
|
|
113
|
+
sourceA: ammName(a.source),
|
|
114
|
+
sourceB: isTwoHop ? ammName(b.source) : null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function involvesNativeOrWnative(tokenIn, tokenOut, wnative) {
|
|
118
|
+
return (0, import_viem.isAddressEqual)(tokenIn, import_viem.zeroAddress) || (0, import_viem.isAddressEqual)(tokenOut, import_viem.zeroAddress) || (0, import_viem.isAddressEqual)(tokenIn, wnative) || (0, import_viem.isAddressEqual)(tokenOut, wnative);
|
|
119
|
+
}
|
|
120
|
+
var Lens = class {
|
|
121
|
+
client;
|
|
122
|
+
chainId;
|
|
123
|
+
lensQuoter;
|
|
124
|
+
wnative;
|
|
125
|
+
quoterAbi;
|
|
126
|
+
/**
|
|
127
|
+
* @param client - viem public client for the target chain
|
|
128
|
+
* @param chainId - chain id (`1` | `10` | `100` | `8453`)
|
|
129
|
+
* @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`
|
|
130
|
+
*/
|
|
131
|
+
constructor(client, chainId, lensQuoter) {
|
|
132
|
+
this.client = client;
|
|
133
|
+
this.chainId = chainId;
|
|
134
|
+
const chain = CHAINS[chainId];
|
|
135
|
+
this.lensQuoter = lensQuoter ?? chain.lensQuoter;
|
|
136
|
+
this.wnative = chain.wnative;
|
|
137
|
+
this.quoterAbi = quoterAbi;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Builds calldata for a two-hop (or one-hop if mid is unused) route via a
|
|
141
|
+
* mid token — used when the caller sets `intermediate`, or as the default
|
|
142
|
+
* Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).
|
|
143
|
+
*/
|
|
144
|
+
async viaToken(params) {
|
|
145
|
+
return this.client.readContract({
|
|
146
|
+
address: this.lensQuoter,
|
|
147
|
+
abi: this.quoterAbi,
|
|
148
|
+
functionName: "buildBestSwapViaToken",
|
|
149
|
+
args: [
|
|
150
|
+
params.recipient,
|
|
151
|
+
params.exactOut,
|
|
152
|
+
params.tokenIn,
|
|
153
|
+
params.tokenOut,
|
|
154
|
+
params.amount,
|
|
155
|
+
BigInt(params.slippageBps),
|
|
156
|
+
params.deadline,
|
|
157
|
+
params.hookPoolFee,
|
|
158
|
+
params.hookTickSpacing,
|
|
159
|
+
params.hookAddress,
|
|
160
|
+
params.mid
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Finds a swap route via LensQuoter and returns amounts plus ready-to-send
|
|
166
|
+
* calldata for an official DEX router.
|
|
167
|
+
*
|
|
168
|
+
* Route selection by request shape:
|
|
169
|
+
* - `intermediate` set → `buildBestSwapViaToken(mid)` only
|
|
170
|
+
* - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;
|
|
171
|
+
* elsewhere `buildBestSwapViaETH`
|
|
172
|
+
* - ERC20 ↔ ERC20 → `buildBestSwap` only
|
|
173
|
+
*/
|
|
174
|
+
async quote(params) {
|
|
175
|
+
const {
|
|
176
|
+
tokenIn,
|
|
177
|
+
tokenOut,
|
|
178
|
+
amount,
|
|
179
|
+
recipient,
|
|
180
|
+
slippageBps = DEFAULT_SLIPPAGE,
|
|
181
|
+
deadline = defaultDeadline(),
|
|
182
|
+
exactOut = false,
|
|
183
|
+
hookPoolFee = 0,
|
|
184
|
+
hookTickSpacing = 0,
|
|
185
|
+
hookAddress = import_viem.zeroAddress,
|
|
186
|
+
intermediate
|
|
187
|
+
} = params;
|
|
188
|
+
const routeArgs = {
|
|
189
|
+
recipient,
|
|
190
|
+
exactOut,
|
|
191
|
+
tokenIn,
|
|
192
|
+
tokenOut,
|
|
193
|
+
amount,
|
|
194
|
+
slippageBps,
|
|
195
|
+
deadline,
|
|
196
|
+
hookPoolFee,
|
|
197
|
+
hookTickSpacing,
|
|
198
|
+
hookAddress
|
|
199
|
+
};
|
|
200
|
+
if (intermediate) {
|
|
201
|
+
return mapViaResult(await this.viaToken({ ...routeArgs, mid: intermediate }));
|
|
202
|
+
}
|
|
203
|
+
const useViaEth = involvesNativeOrWnative(tokenIn, tokenOut, this.wnative);
|
|
204
|
+
if (useViaEth) {
|
|
205
|
+
if (this.chainId === 100) {
|
|
206
|
+
return mapViaResult(await this.viaToken({ ...routeArgs, mid: GNOSIS_sDAI }));
|
|
207
|
+
}
|
|
208
|
+
const value = await this.client.readContract({
|
|
209
|
+
address: this.lensQuoter,
|
|
210
|
+
abi: this.quoterAbi,
|
|
211
|
+
functionName: "buildBestSwapViaETH",
|
|
212
|
+
args: [
|
|
213
|
+
recipient,
|
|
214
|
+
exactOut,
|
|
215
|
+
tokenIn,
|
|
216
|
+
tokenOut,
|
|
217
|
+
amount,
|
|
218
|
+
BigInt(slippageBps),
|
|
219
|
+
deadline,
|
|
220
|
+
hookPoolFee,
|
|
221
|
+
hookTickSpacing,
|
|
222
|
+
hookAddress
|
|
223
|
+
]
|
|
224
|
+
});
|
|
225
|
+
return mapViaResult(value);
|
|
226
|
+
}
|
|
227
|
+
const [best, target, callData, _amountLimit, msgValue] = await this.client.readContract({
|
|
228
|
+
address: this.lensQuoter,
|
|
229
|
+
abi: this.quoterAbi,
|
|
230
|
+
functionName: "buildBestSwap",
|
|
231
|
+
args: [
|
|
232
|
+
recipient,
|
|
233
|
+
exactOut,
|
|
234
|
+
tokenIn,
|
|
235
|
+
tokenOut,
|
|
236
|
+
amount,
|
|
237
|
+
BigInt(slippageBps),
|
|
238
|
+
deadline
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
amountIn: best.amountIn,
|
|
243
|
+
amountOut: best.amountOut,
|
|
244
|
+
target,
|
|
245
|
+
data: callData,
|
|
246
|
+
msgValue: msgValue ?? 0n,
|
|
247
|
+
isTwoHop: false,
|
|
248
|
+
sourceA: ammName(best.source),
|
|
249
|
+
sourceB: null
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
254
|
+
0 && (module.exports = {
|
|
255
|
+
AMM,
|
|
256
|
+
AMM_NAMES,
|
|
257
|
+
CHAINS,
|
|
258
|
+
ETH,
|
|
259
|
+
GNOSIS_sDAI,
|
|
260
|
+
LENS_QUOTER_ABI,
|
|
261
|
+
Lens,
|
|
262
|
+
defaultDeadline
|
|
263
|
+
});
|
|
264
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"sourcesContent":["// Lens SDK — client\n\nimport { parseAbi, isAddressEqual, zeroAddress } from \"viem\";\nimport type { PublicClient, Address, Abi } from \"viem\";\nimport {\n CHAINS, GNOSIS_sDAI,\n LENS_QUOTER_ABI,\n AMM_NAMES,\n defaultDeadline,\n type ChainId,\n type QuoteParams,\n type QuoteResult,\n} from \"./index.js\";\n\n// viem's parseAbi (abitype) doesn't support inline `tuple(...)` syntax,\n// so rewrite the shared quoter ABI strings to use a named struct.\nconst QUOTE_TUPLE = \"tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut)\";\nconst QUOTE_STRUCT = \"struct Quote { uint8 source; uint256 feeBps; uint256 amountIn; uint256 amountOut; }\";\n\n/** Rewrites inline `tuple(...)` quoter ABI lines to a named `Quote` struct for `parseAbi`. */\nconst toQuoterAbi = (lines: readonly string[]): Abi =>\n parseAbi([QUOTE_STRUCT, ...lines.map((l) => l.split(QUOTE_TUPLE).join(\"Quote\"))]);\n\nconst quoterAbi = toQuoterAbi(LENS_QUOTER_ABI);\n\nexport {\n ETH, GNOSIS_sDAI, AMM, AMM_NAMES,\n CHAINS,\n LENS_QUOTER_ABI, defaultDeadline,\n} from \"./index.js\";\nexport type { QuoteResult, BaseQuoteParams, QuoteParams, ChainId } from \"./index.js\";\n\nconst DEFAULT_SLIPPAGE = 50; // 0.5%\n\ntype QuoteStruct = { source: number; feeBps: bigint; amountIn: bigint; amountOut: bigint };\ntype BestSwapResult = readonly [\n QuoteStruct,\n QuoteStruct,\n Address,\n `0x${string}`,\n bigint,\n];\ntype BuildBestSwapResult = readonly [QuoteStruct, Address, `0x${string}`, bigint, bigint];\n\n/** Resolves a human-readable AMM name from an on-chain `source` id. */\nfunction ammName(source: number): string {\n return (AMM_NAMES as Record<number, string>)[source] || `AMM #${source}`;\n}\n\n/**\n * Maps a `buildBestSwapViaETH` / `buildBestSwapViaToken` return value to `QuoteResult`.\n * Hop B is zeroed for single-hop; `b.amountOut > 0` means a real two-hop\n * route, so final `amountOut` comes from hop B.\n */\nfunction mapViaResult(value: BestSwapResult): QuoteResult {\n const [a, b, target, data, msgValue] = value;\n const isTwoHop = b.amountOut > 0n;\n return {\n amountIn: a.amountIn,\n amountOut: isTwoHop ? b.amountOut : a.amountOut,\n target: target as string,\n data: data as string,\n msgValue: msgValue ?? 0n,\n isTwoHop,\n sourceA: ammName(a.source),\n sourceB: isTwoHop ? ammName(b.source) : null,\n };\n}\n\n/**\n * True when either endpoint is native (`address(0)`) or the chain's wrapped native.\n * On non-Gnosis those pairs use ViaETH; on Gnosis they use ViaToken(sDAI).\n * Pure ERC20↔ERC20 uses `buildBestSwap`.\n */\nfunction involvesNativeOrWnative(\n tokenIn: string,\n tokenOut: string,\n wnative: Address,\n): boolean {\n return (\n isAddressEqual(tokenIn as Address, zeroAddress)\n || isAddressEqual(tokenOut as Address, zeroAddress)\n || isAddressEqual(tokenIn as Address, wnative)\n || isAddressEqual(tokenOut as Address, wnative)\n );\n}\n\n/**\n * Lens SDK client: quotes best routes via the unified on-chain LensQuoter\n * and builds ready-to-send txs for official DEX routers.\n */\nexport class Lens {\n private client: PublicClient;\n private chainId: ChainId;\n private lensQuoter: Address;\n private wnative: Address;\n private quoterAbi: Abi;\n\n /**\n * @param client - viem public client for the target chain\n * @param chainId - chain id (`1` | `10` | `100` | `8453`)\n * @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`\n */\n constructor(client: PublicClient, chainId: ChainId, lensQuoter?: Address) {\n this.client = client;\n this.chainId = chainId;\n const chain = CHAINS[chainId];\n this.lensQuoter = lensQuoter ?? (chain.lensQuoter as Address);\n this.wnative = chain.wnative as Address;\n this.quoterAbi = quoterAbi;\n }\n\n /**\n * Builds calldata for a two-hop (or one-hop if mid is unused) route via a\n * mid token — used when the caller sets `intermediate`, or as the default\n * Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).\n */\n private async viaToken(\n params: {\n recipient: string;\n exactOut: boolean;\n tokenIn: string;\n tokenOut: string;\n amount: bigint;\n slippageBps: number;\n deadline: bigint;\n hookPoolFee: number;\n hookTickSpacing: number;\n hookAddress: string;\n mid: string;\n },\n ): Promise<BestSwapResult> {\n return this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwapViaToken\",\n args: [\n params.recipient as Address,\n params.exactOut,\n params.tokenIn as Address,\n params.tokenOut as Address,\n params.amount,\n BigInt(params.slippageBps),\n params.deadline,\n params.hookPoolFee,\n params.hookTickSpacing,\n params.hookAddress as Address,\n params.mid as Address,\n ],\n }) as Promise<BestSwapResult>;\n }\n\n /**\n * Finds a swap route via LensQuoter and returns amounts plus ready-to-send\n * calldata for an official DEX router.\n *\n * Route selection by request shape:\n * - `intermediate` set → `buildBestSwapViaToken(mid)` only\n * - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;\n * elsewhere `buildBestSwapViaETH`\n * - ERC20 ↔ ERC20 → `buildBestSwap` only\n */\n async quote(params: QuoteParams): Promise<QuoteResult> {\n const {\n tokenIn, tokenOut, amount, recipient,\n slippageBps = DEFAULT_SLIPPAGE, deadline = defaultDeadline(),\n exactOut = false,\n hookPoolFee = 0, hookTickSpacing = 0, hookAddress = zeroAddress,\n intermediate,\n } = params;\n\n const routeArgs = {\n recipient, exactOut, tokenIn, tokenOut, amount,\n slippageBps, deadline, hookPoolFee, hookTickSpacing, hookAddress,\n };\n\n // Caller forced a mid token: skip native/ERC20 cascade.\n if (intermediate) {\n return mapViaResult(await this.viaToken({ ...routeArgs, mid: intermediate }));\n }\n\n const useViaEth = involvesNativeOrWnative(tokenIn, tokenOut, this.wnative);\n\n if (useViaEth) {\n // Gnosis (Seer): outcomes trade vs sDAI — skip ViaETH entirely.\n if (this.chainId === 100) {\n return mapViaResult(await this.viaToken({ ...routeArgs, mid: GNOSIS_sDAI }));\n }\n\n // Other chains: single-hop ViaETH (router wrap/unwrap).\n const value = await this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwapViaETH\",\n args: [\n recipient as Address, exactOut,\n tokenIn as Address, tokenOut as Address,\n amount, BigInt(slippageBps), deadline,\n hookPoolFee, hookTickSpacing, hookAddress as Address,\n ],\n }) as BestSwapResult;\n return mapViaResult(value);\n }\n\n // Pure ERC20 ↔ ERC20: direct single-hop only.\n const [best, target, callData, _amountLimit, msgValue] = await this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwap\",\n args: [\n recipient as Address, exactOut,\n tokenIn as Address, tokenOut as Address,\n amount, BigInt(slippageBps), deadline,\n ],\n }) as BuildBestSwapResult;\n\n return {\n amountIn: best.amountIn,\n amountOut: best.amountOut,\n target: target as string,\n data: callData as string,\n msgValue: msgValue ?? 0n,\n isTwoHop: false,\n sourceA: ammName(best.source),\n sourceB: null,\n };\n }\n}\n","// Lens SDK — Core constants, ABIs, types, token list (zero dependencies)\n\n// ---- Chain config ----\n\n/** Unified AMM enum (same ordinals on every chain). */\nexport enum AMM {\n UNI_V3 = 0,\n UNI_V4 = 1,\n UNI_V4_HOOKED = 2,\n SWAPR_V3 = 3,\n}\n\nexport const AMM_NAMES: Record<AMM, string> = {\n [AMM.UNI_V3]: \"Uniswap V3\",\n [AMM.UNI_V4]: \"Uniswap V4\",\n [AMM.UNI_V4_HOOKED]: \"Uniswap V4 Hooked\",\n [AMM.SWAPR_V3]: \"Swapr V3\",\n};\n\n/** Shared LensQuoter ABI for the unified contract on all chains. */\nexport const LENS_QUOTER_ABI = [\n \"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)\",\n \"function V3_SWAP_ROUTER() view returns (address)\",\n \"function V4_ROUTER() view returns (address)\",\n \"function SWAPR_SWAP_ROUTER() view returns (address)\",\n \"function V4_QUOTER() view returns (address)\",\n] as const;\n\n/** Per-chain LensQuoter, official DEX routers, and wrapped native. */\nexport const CHAINS = {\n 1: {\n lensQuoter: \"0xae300296486a63621f7f31E1B94aD22d32347deA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\",\n },\n 10: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n 100: {\n lensQuoter: \"0xEe7596551a8339674d9Ee4B05b1A8E49cf738825\",\n v3SwapRouter: \"0x0000000000000000000000000000000000000000\",\n v4Router: \"0x0000000000000000000000000000000000000000\",\n swaprSwapRouter: \"0xfFB643E73f280B97809A8b41f7232AB401a04ee1\",\n wnative: \"0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d\",\n },\n 8453: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x2626664c2603336E57B271c5C0b26F421741e481\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n} as const;\n\nexport type ChainId = keyof typeof CHAINS;\n\nexport const ETH = \"0x0000000000000000000000000000000000000000\" as const;\n\n/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */\nexport const GNOSIS_sDAI = \"0xaf204776c7245bF4147c2612BF6e5972Ee483701\" as const;\n\n// ---- Types ----\n\nexport interface QuoteResult {\n amountIn: bigint;\n amountOut: bigint;\n /** Official DEX router to call. */\n target: string;\n /** Ready-to-send calldata for `target`. */\n data: string;\n msgValue: bigint;\n isTwoHop: boolean;\n sourceA: string;\n sourceB: string | null;\n}\n\nexport interface BaseQuoteParams {\n tokenIn: string;\n tokenOut: string;\n amount: bigint;\n}\n\nexport interface QuoteParams extends BaseQuoteParams {\n recipient: string;\n slippageBps?: number;\n deadline?: bigint;\n /** false = exactIn (default); true = exactOut. `amount` is amountIn or desired amountOut accordingly. */\n exactOut?: boolean;\n /** Optional V4 hooked-pool candidate (exactIn; can beat the primary route). */\n hookPoolFee?: number;\n hookTickSpacing?: number;\n hookAddress?: string;\n /**\n * Intermediate token for two-hop routes (`buildBestSwapViaToken`).\n * When set, skips the native/ERC20 cascade. On Gnosis, native/WXDAI↔ERC20\n * already defaults to ViaToken(sDAI); use this only to force a different mid.\n */\n intermediate?: string;\n}\n\n// ---- Helpers ----\n\nexport function defaultDeadline(): bigint {\n return BigInt(Math.trunc(Date.now() / 1000) + 300);\n}\n"],"mappings":"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","names":["AMM"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PublicClient, Address } from 'viem';
|
|
2
|
+
import { ChainId, QuoteParams, QuoteResult } from './index.cjs';
|
|
3
|
+
export { AMM, AMM_NAMES, BaseQuoteParams, CHAINS, ETH, GNOSIS_sDAI, LENS_QUOTER_ABI, defaultDeadline } from './index.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lens SDK client: quotes best routes via the unified on-chain LensQuoter
|
|
7
|
+
* and builds ready-to-send txs for official DEX routers.
|
|
8
|
+
*/
|
|
9
|
+
declare class Lens {
|
|
10
|
+
private client;
|
|
11
|
+
private chainId;
|
|
12
|
+
private lensQuoter;
|
|
13
|
+
private wnative;
|
|
14
|
+
private quoterAbi;
|
|
15
|
+
/**
|
|
16
|
+
* @param client - viem public client for the target chain
|
|
17
|
+
* @param chainId - chain id (`1` | `10` | `100` | `8453`)
|
|
18
|
+
* @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`
|
|
19
|
+
*/
|
|
20
|
+
constructor(client: PublicClient, chainId: ChainId, lensQuoter?: Address);
|
|
21
|
+
/**
|
|
22
|
+
* Builds calldata for a two-hop (or one-hop if mid is unused) route via a
|
|
23
|
+
* mid token — used when the caller sets `intermediate`, or as the default
|
|
24
|
+
* Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).
|
|
25
|
+
*/
|
|
26
|
+
private viaToken;
|
|
27
|
+
/**
|
|
28
|
+
* Finds a swap route via LensQuoter and returns amounts plus ready-to-send
|
|
29
|
+
* calldata for an official DEX router.
|
|
30
|
+
*
|
|
31
|
+
* Route selection by request shape:
|
|
32
|
+
* - `intermediate` set → `buildBestSwapViaToken(mid)` only
|
|
33
|
+
* - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;
|
|
34
|
+
* elsewhere `buildBestSwapViaETH`
|
|
35
|
+
* - ERC20 ↔ ERC20 → `buildBestSwap` only
|
|
36
|
+
*/
|
|
37
|
+
quote(params: QuoteParams): Promise<QuoteResult>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { ChainId, Lens, QuoteParams, QuoteResult };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
|
|
1
|
+
import { PublicClient, Address } from 'viem';
|
|
2
|
+
import { ChainId, QuoteParams, QuoteResult } from './index.js';
|
|
3
|
+
export { AMM, AMM_NAMES, BaseQuoteParams, CHAINS, ETH, GNOSIS_sDAI, LENS_QUOTER_ABI, defaultDeadline } from './index.js';
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* Lens SDK client: quotes best routes via the unified on-chain LensQuoter
|
|
7
7
|
* and builds ready-to-send txs for official DEX routers.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
declare class Lens {
|
|
10
10
|
private client;
|
|
11
11
|
private chainId;
|
|
12
12
|
private lensQuoter;
|
|
@@ -36,3 +36,5 @@ export declare class Lens {
|
|
|
36
36
|
*/
|
|
37
37
|
quote(params: QuoteParams): Promise<QuoteResult>;
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
export { ChainId, Lens, QuoteParams, QuoteResult };
|
package/dist/client.js
CHANGED
|
@@ -1,157 +1,181 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
AMM,
|
|
3
|
+
AMM_NAMES,
|
|
4
|
+
CHAINS,
|
|
5
|
+
ETH,
|
|
6
|
+
GNOSIS_sDAI,
|
|
7
|
+
LENS_QUOTER_ABI,
|
|
8
|
+
defaultDeadline
|
|
9
|
+
} from "./chunk-BW3R2UBK.js";
|
|
10
|
+
|
|
11
|
+
// src/client.ts
|
|
2
12
|
import { parseAbi, isAddressEqual, zeroAddress } from "viem";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Rewrites inline `tuple(...)` quoter ABI lines to a named `Quote` struct for `parseAbi`. */
|
|
9
|
-
const toQuoterAbi = (lines) => parseAbi([QUOTE_STRUCT, ...lines.map((l) => l.split(QUOTE_TUPLE).join("Quote"))]);
|
|
10
|
-
const quoterAbi = toQuoterAbi(LENS_QUOTER_ABI);
|
|
11
|
-
export { ETH, GNOSIS_sDAI, AMM, AMM_NAMES, CHAINS, LENS_QUOTER_ABI, defaultDeadline, } from "./index.js";
|
|
12
|
-
const DEFAULT_SLIPPAGE = 50; // 0.5%
|
|
13
|
-
/** Resolves a human-readable AMM name from an on-chain `source` id. */
|
|
13
|
+
var QUOTE_TUPLE = "tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut)";
|
|
14
|
+
var QUOTE_STRUCT = "struct Quote { uint8 source; uint256 feeBps; uint256 amountIn; uint256 amountOut; }";
|
|
15
|
+
var toQuoterAbi = (lines) => parseAbi([QUOTE_STRUCT, ...lines.map((l) => l.split(QUOTE_TUPLE).join("Quote"))]);
|
|
16
|
+
var quoterAbi = toQuoterAbi(LENS_QUOTER_ABI);
|
|
17
|
+
var DEFAULT_SLIPPAGE = 50;
|
|
14
18
|
function ammName(source) {
|
|
15
|
-
|
|
19
|
+
return AMM_NAMES[source] || `AMM #${source}`;
|
|
16
20
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Maps a `buildBestSwapViaETH` / `buildBestSwapViaToken` return value to `QuoteResult`.
|
|
19
|
-
* Hop B is zeroed for single-hop; `b.amountOut > 0` means a real two-hop
|
|
20
|
-
* route, so final `amountOut` comes from hop B.
|
|
21
|
-
*/
|
|
22
21
|
function mapViaResult(value) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
const [a, b, target, data, msgValue] = value;
|
|
23
|
+
const isTwoHop = b.amountOut > 0n;
|
|
24
|
+
return {
|
|
25
|
+
amountIn: a.amountIn,
|
|
26
|
+
amountOut: isTwoHop ? b.amountOut : a.amountOut,
|
|
27
|
+
target,
|
|
28
|
+
data,
|
|
29
|
+
msgValue: msgValue ?? 0n,
|
|
30
|
+
isTwoHop,
|
|
31
|
+
sourceA: ammName(a.source),
|
|
32
|
+
sourceB: isTwoHop ? ammName(b.source) : null
|
|
33
|
+
};
|
|
35
34
|
}
|
|
36
|
-
/**
|
|
37
|
-
* True when either endpoint is native (`address(0)`) or the chain's wrapped native.
|
|
38
|
-
* On non-Gnosis those pairs use ViaETH; on Gnosis they use ViaToken(sDAI).
|
|
39
|
-
* Pure ERC20↔ERC20 uses `buildBestSwap`.
|
|
40
|
-
*/
|
|
41
35
|
function involvesNativeOrWnative(tokenIn, tokenOut, wnative) {
|
|
42
|
-
|
|
43
|
-
|| isAddressEqual(tokenOut, zeroAddress)
|
|
44
|
-
|| isAddressEqual(tokenIn, wnative)
|
|
45
|
-
|| isAddressEqual(tokenOut, wnative));
|
|
36
|
+
return isAddressEqual(tokenIn, zeroAddress) || isAddressEqual(tokenOut, zeroAddress) || isAddressEqual(tokenIn, wnative) || isAddressEqual(tokenOut, wnative);
|
|
46
37
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
38
|
+
var Lens = class {
|
|
39
|
+
client;
|
|
40
|
+
chainId;
|
|
41
|
+
lensQuoter;
|
|
42
|
+
wnative;
|
|
43
|
+
quoterAbi;
|
|
44
|
+
/**
|
|
45
|
+
* @param client - viem public client for the target chain
|
|
46
|
+
* @param chainId - chain id (`1` | `10` | `100` | `8453`)
|
|
47
|
+
* @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`
|
|
48
|
+
*/
|
|
49
|
+
constructor(client, chainId, lensQuoter) {
|
|
50
|
+
this.client = client;
|
|
51
|
+
this.chainId = chainId;
|
|
52
|
+
const chain = CHAINS[chainId];
|
|
53
|
+
this.lensQuoter = lensQuoter ?? chain.lensQuoter;
|
|
54
|
+
this.wnative = chain.wnative;
|
|
55
|
+
this.quoterAbi = quoterAbi;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Builds calldata for a two-hop (or one-hop if mid is unused) route via a
|
|
59
|
+
* mid token — used when the caller sets `intermediate`, or as the default
|
|
60
|
+
* Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).
|
|
61
|
+
*/
|
|
62
|
+
async viaToken(params) {
|
|
63
|
+
return this.client.readContract({
|
|
64
|
+
address: this.lensQuoter,
|
|
65
|
+
abi: this.quoterAbi,
|
|
66
|
+
functionName: "buildBestSwapViaToken",
|
|
67
|
+
args: [
|
|
68
|
+
params.recipient,
|
|
69
|
+
params.exactOut,
|
|
70
|
+
params.tokenIn,
|
|
71
|
+
params.tokenOut,
|
|
72
|
+
params.amount,
|
|
73
|
+
BigInt(params.slippageBps),
|
|
74
|
+
params.deadline,
|
|
75
|
+
params.hookPoolFee,
|
|
76
|
+
params.hookTickSpacing,
|
|
77
|
+
params.hookAddress,
|
|
78
|
+
params.mid
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Finds a swap route via LensQuoter and returns amounts plus ready-to-send
|
|
84
|
+
* calldata for an official DEX router.
|
|
85
|
+
*
|
|
86
|
+
* Route selection by request shape:
|
|
87
|
+
* - `intermediate` set → `buildBestSwapViaToken(mid)` only
|
|
88
|
+
* - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;
|
|
89
|
+
* elsewhere `buildBestSwapViaETH`
|
|
90
|
+
* - ERC20 ↔ ERC20 → `buildBestSwap` only
|
|
91
|
+
*/
|
|
92
|
+
async quote(params) {
|
|
93
|
+
const {
|
|
94
|
+
tokenIn,
|
|
95
|
+
tokenOut,
|
|
96
|
+
amount,
|
|
97
|
+
recipient,
|
|
98
|
+
slippageBps = DEFAULT_SLIPPAGE,
|
|
99
|
+
deadline = defaultDeadline(),
|
|
100
|
+
exactOut = false,
|
|
101
|
+
hookPoolFee = 0,
|
|
102
|
+
hookTickSpacing = 0,
|
|
103
|
+
hookAddress = zeroAddress,
|
|
104
|
+
intermediate
|
|
105
|
+
} = params;
|
|
106
|
+
const routeArgs = {
|
|
107
|
+
recipient,
|
|
108
|
+
exactOut,
|
|
109
|
+
tokenIn,
|
|
110
|
+
tokenOut,
|
|
111
|
+
amount,
|
|
112
|
+
slippageBps,
|
|
113
|
+
deadline,
|
|
114
|
+
hookPoolFee,
|
|
115
|
+
hookTickSpacing,
|
|
116
|
+
hookAddress
|
|
117
|
+
};
|
|
118
|
+
if (intermediate) {
|
|
119
|
+
return mapViaResult(await this.viaToken({ ...routeArgs, mid: intermediate }));
|
|
94
120
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (this.chainId === 100) {
|
|
119
|
-
return mapViaResult(await this.viaToken({ ...routeArgs, mid: GNOSIS_sDAI }));
|
|
120
|
-
}
|
|
121
|
-
// Other chains: single-hop ViaETH (router wrap/unwrap).
|
|
122
|
-
const value = await this.client.readContract({
|
|
123
|
-
address: this.lensQuoter,
|
|
124
|
-
abi: this.quoterAbi,
|
|
125
|
-
functionName: "buildBestSwapViaETH",
|
|
126
|
-
args: [
|
|
127
|
-
recipient, exactOut,
|
|
128
|
-
tokenIn, tokenOut,
|
|
129
|
-
amount, BigInt(slippageBps), deadline,
|
|
130
|
-
hookPoolFee, hookTickSpacing, hookAddress,
|
|
131
|
-
],
|
|
132
|
-
});
|
|
133
|
-
return mapViaResult(value);
|
|
134
|
-
}
|
|
135
|
-
// Pure ERC20 ↔ ERC20: direct single-hop only.
|
|
136
|
-
const [best, target, callData, _amountLimit, msgValue] = await this.client.readContract({
|
|
137
|
-
address: this.lensQuoter,
|
|
138
|
-
abi: this.quoterAbi,
|
|
139
|
-
functionName: "buildBestSwap",
|
|
140
|
-
args: [
|
|
141
|
-
recipient, exactOut,
|
|
142
|
-
tokenIn, tokenOut,
|
|
143
|
-
amount, BigInt(slippageBps), deadline,
|
|
144
|
-
],
|
|
145
|
-
});
|
|
146
|
-
return {
|
|
147
|
-
amountIn: best.amountIn,
|
|
148
|
-
amountOut: best.amountOut,
|
|
149
|
-
target: target,
|
|
150
|
-
data: callData,
|
|
151
|
-
msgValue: msgValue ?? 0n,
|
|
152
|
-
isTwoHop: false,
|
|
153
|
-
sourceA: ammName(best.source),
|
|
154
|
-
sourceB: null,
|
|
155
|
-
};
|
|
121
|
+
const useViaEth = involvesNativeOrWnative(tokenIn, tokenOut, this.wnative);
|
|
122
|
+
if (useViaEth) {
|
|
123
|
+
if (this.chainId === 100) {
|
|
124
|
+
return mapViaResult(await this.viaToken({ ...routeArgs, mid: GNOSIS_sDAI }));
|
|
125
|
+
}
|
|
126
|
+
const value = await this.client.readContract({
|
|
127
|
+
address: this.lensQuoter,
|
|
128
|
+
abi: this.quoterAbi,
|
|
129
|
+
functionName: "buildBestSwapViaETH",
|
|
130
|
+
args: [
|
|
131
|
+
recipient,
|
|
132
|
+
exactOut,
|
|
133
|
+
tokenIn,
|
|
134
|
+
tokenOut,
|
|
135
|
+
amount,
|
|
136
|
+
BigInt(slippageBps),
|
|
137
|
+
deadline,
|
|
138
|
+
hookPoolFee,
|
|
139
|
+
hookTickSpacing,
|
|
140
|
+
hookAddress
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
return mapViaResult(value);
|
|
156
144
|
}
|
|
157
|
-
|
|
145
|
+
const [best, target, callData, _amountLimit, msgValue] = await this.client.readContract({
|
|
146
|
+
address: this.lensQuoter,
|
|
147
|
+
abi: this.quoterAbi,
|
|
148
|
+
functionName: "buildBestSwap",
|
|
149
|
+
args: [
|
|
150
|
+
recipient,
|
|
151
|
+
exactOut,
|
|
152
|
+
tokenIn,
|
|
153
|
+
tokenOut,
|
|
154
|
+
amount,
|
|
155
|
+
BigInt(slippageBps),
|
|
156
|
+
deadline
|
|
157
|
+
]
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
amountIn: best.amountIn,
|
|
161
|
+
amountOut: best.amountOut,
|
|
162
|
+
target,
|
|
163
|
+
data: callData,
|
|
164
|
+
msgValue: msgValue ?? 0n,
|
|
165
|
+
isTwoHop: false,
|
|
166
|
+
sourceA: ammName(best.source),
|
|
167
|
+
sourceB: null
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
export {
|
|
172
|
+
AMM,
|
|
173
|
+
AMM_NAMES,
|
|
174
|
+
CHAINS,
|
|
175
|
+
ETH,
|
|
176
|
+
GNOSIS_sDAI,
|
|
177
|
+
LENS_QUOTER_ABI,
|
|
178
|
+
Lens,
|
|
179
|
+
defaultDeadline
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["// Lens SDK — client\n\nimport { parseAbi, isAddressEqual, zeroAddress } from \"viem\";\nimport type { PublicClient, Address, Abi } from \"viem\";\nimport {\n CHAINS, GNOSIS_sDAI,\n LENS_QUOTER_ABI,\n AMM_NAMES,\n defaultDeadline,\n type ChainId,\n type QuoteParams,\n type QuoteResult,\n} from \"./index.js\";\n\n// viem's parseAbi (abitype) doesn't support inline `tuple(...)` syntax,\n// so rewrite the shared quoter ABI strings to use a named struct.\nconst QUOTE_TUPLE = \"tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut)\";\nconst QUOTE_STRUCT = \"struct Quote { uint8 source; uint256 feeBps; uint256 amountIn; uint256 amountOut; }\";\n\n/** Rewrites inline `tuple(...)` quoter ABI lines to a named `Quote` struct for `parseAbi`. */\nconst toQuoterAbi = (lines: readonly string[]): Abi =>\n parseAbi([QUOTE_STRUCT, ...lines.map((l) => l.split(QUOTE_TUPLE).join(\"Quote\"))]);\n\nconst quoterAbi = toQuoterAbi(LENS_QUOTER_ABI);\n\nexport {\n ETH, GNOSIS_sDAI, AMM, AMM_NAMES,\n CHAINS,\n LENS_QUOTER_ABI, defaultDeadline,\n} from \"./index.js\";\nexport type { QuoteResult, BaseQuoteParams, QuoteParams, ChainId } from \"./index.js\";\n\nconst DEFAULT_SLIPPAGE = 50; // 0.5%\n\ntype QuoteStruct = { source: number; feeBps: bigint; amountIn: bigint; amountOut: bigint };\ntype BestSwapResult = readonly [\n QuoteStruct,\n QuoteStruct,\n Address,\n `0x${string}`,\n bigint,\n];\ntype BuildBestSwapResult = readonly [QuoteStruct, Address, `0x${string}`, bigint, bigint];\n\n/** Resolves a human-readable AMM name from an on-chain `source` id. */\nfunction ammName(source: number): string {\n return (AMM_NAMES as Record<number, string>)[source] || `AMM #${source}`;\n}\n\n/**\n * Maps a `buildBestSwapViaETH` / `buildBestSwapViaToken` return value to `QuoteResult`.\n * Hop B is zeroed for single-hop; `b.amountOut > 0` means a real two-hop\n * route, so final `amountOut` comes from hop B.\n */\nfunction mapViaResult(value: BestSwapResult): QuoteResult {\n const [a, b, target, data, msgValue] = value;\n const isTwoHop = b.amountOut > 0n;\n return {\n amountIn: a.amountIn,\n amountOut: isTwoHop ? b.amountOut : a.amountOut,\n target: target as string,\n data: data as string,\n msgValue: msgValue ?? 0n,\n isTwoHop,\n sourceA: ammName(a.source),\n sourceB: isTwoHop ? ammName(b.source) : null,\n };\n}\n\n/**\n * True when either endpoint is native (`address(0)`) or the chain's wrapped native.\n * On non-Gnosis those pairs use ViaETH; on Gnosis they use ViaToken(sDAI).\n * Pure ERC20↔ERC20 uses `buildBestSwap`.\n */\nfunction involvesNativeOrWnative(\n tokenIn: string,\n tokenOut: string,\n wnative: Address,\n): boolean {\n return (\n isAddressEqual(tokenIn as Address, zeroAddress)\n || isAddressEqual(tokenOut as Address, zeroAddress)\n || isAddressEqual(tokenIn as Address, wnative)\n || isAddressEqual(tokenOut as Address, wnative)\n );\n}\n\n/**\n * Lens SDK client: quotes best routes via the unified on-chain LensQuoter\n * and builds ready-to-send txs for official DEX routers.\n */\nexport class Lens {\n private client: PublicClient;\n private chainId: ChainId;\n private lensQuoter: Address;\n private wnative: Address;\n private quoterAbi: Abi;\n\n /**\n * @param client - viem public client for the target chain\n * @param chainId - chain id (`1` | `10` | `100` | `8453`)\n * @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`\n */\n constructor(client: PublicClient, chainId: ChainId, lensQuoter?: Address) {\n this.client = client;\n this.chainId = chainId;\n const chain = CHAINS[chainId];\n this.lensQuoter = lensQuoter ?? (chain.lensQuoter as Address);\n this.wnative = chain.wnative as Address;\n this.quoterAbi = quoterAbi;\n }\n\n /**\n * Builds calldata for a two-hop (or one-hop if mid is unused) route via a\n * mid token — used when the caller sets `intermediate`, or as the default\n * Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).\n */\n private async viaToken(\n params: {\n recipient: string;\n exactOut: boolean;\n tokenIn: string;\n tokenOut: string;\n amount: bigint;\n slippageBps: number;\n deadline: bigint;\n hookPoolFee: number;\n hookTickSpacing: number;\n hookAddress: string;\n mid: string;\n },\n ): Promise<BestSwapResult> {\n return this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwapViaToken\",\n args: [\n params.recipient as Address,\n params.exactOut,\n params.tokenIn as Address,\n params.tokenOut as Address,\n params.amount,\n BigInt(params.slippageBps),\n params.deadline,\n params.hookPoolFee,\n params.hookTickSpacing,\n params.hookAddress as Address,\n params.mid as Address,\n ],\n }) as Promise<BestSwapResult>;\n }\n\n /**\n * Finds a swap route via LensQuoter and returns amounts plus ready-to-send\n * calldata for an official DEX router.\n *\n * Route selection by request shape:\n * - `intermediate` set → `buildBestSwapViaToken(mid)` only\n * - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;\n * elsewhere `buildBestSwapViaETH`\n * - ERC20 ↔ ERC20 → `buildBestSwap` only\n */\n async quote(params: QuoteParams): Promise<QuoteResult> {\n const {\n tokenIn, tokenOut, amount, recipient,\n slippageBps = DEFAULT_SLIPPAGE, deadline = defaultDeadline(),\n exactOut = false,\n hookPoolFee = 0, hookTickSpacing = 0, hookAddress = zeroAddress,\n intermediate,\n } = params;\n\n const routeArgs = {\n recipient, exactOut, tokenIn, tokenOut, amount,\n slippageBps, deadline, hookPoolFee, hookTickSpacing, hookAddress,\n };\n\n // Caller forced a mid token: skip native/ERC20 cascade.\n if (intermediate) {\n return mapViaResult(await this.viaToken({ ...routeArgs, mid: intermediate }));\n }\n\n const useViaEth = involvesNativeOrWnative(tokenIn, tokenOut, this.wnative);\n\n if (useViaEth) {\n // Gnosis (Seer): outcomes trade vs sDAI — skip ViaETH entirely.\n if (this.chainId === 100) {\n return mapViaResult(await this.viaToken({ ...routeArgs, mid: GNOSIS_sDAI }));\n }\n\n // Other chains: single-hop ViaETH (router wrap/unwrap).\n const value = await this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwapViaETH\",\n args: [\n recipient as Address, exactOut,\n tokenIn as Address, tokenOut as Address,\n amount, BigInt(slippageBps), deadline,\n hookPoolFee, hookTickSpacing, hookAddress as Address,\n ],\n }) as BestSwapResult;\n return mapViaResult(value);\n }\n\n // Pure ERC20 ↔ ERC20: direct single-hop only.\n const [best, target, callData, _amountLimit, msgValue] = await this.client.readContract({\n address: this.lensQuoter,\n abi: this.quoterAbi,\n functionName: \"buildBestSwap\",\n args: [\n recipient as Address, exactOut,\n tokenIn as Address, tokenOut as Address,\n amount, BigInt(slippageBps), deadline,\n ],\n }) as BuildBestSwapResult;\n\n return {\n amountIn: best.amountIn,\n amountOut: best.amountOut,\n target: target as string,\n data: callData as string,\n msgValue: msgValue ?? 0n,\n isTwoHop: false,\n sourceA: ammName(best.source),\n sourceB: null,\n };\n }\n}\n"],"mappings":"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","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AMM: () => AMM,
|
|
24
|
+
AMM_NAMES: () => AMM_NAMES,
|
|
25
|
+
CHAINS: () => CHAINS,
|
|
26
|
+
ETH: () => ETH,
|
|
27
|
+
GNOSIS_sDAI: () => GNOSIS_sDAI,
|
|
28
|
+
LENS_QUOTER_ABI: () => LENS_QUOTER_ABI,
|
|
29
|
+
defaultDeadline: () => defaultDeadline
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var AMM = /* @__PURE__ */ ((AMM2) => {
|
|
33
|
+
AMM2[AMM2["UNI_V3"] = 0] = "UNI_V3";
|
|
34
|
+
AMM2[AMM2["UNI_V4"] = 1] = "UNI_V4";
|
|
35
|
+
AMM2[AMM2["UNI_V4_HOOKED"] = 2] = "UNI_V4_HOOKED";
|
|
36
|
+
AMM2[AMM2["SWAPR_V3"] = 3] = "SWAPR_V3";
|
|
37
|
+
return AMM2;
|
|
38
|
+
})(AMM || {});
|
|
39
|
+
var AMM_NAMES = {
|
|
40
|
+
[0 /* UNI_V3 */]: "Uniswap V3",
|
|
41
|
+
[1 /* UNI_V4 */]: "Uniswap V4",
|
|
42
|
+
[2 /* UNI_V4_HOOKED */]: "Uniswap V4 Hooked",
|
|
43
|
+
[3 /* SWAPR_V3 */]: "Swapr V3"
|
|
44
|
+
};
|
|
45
|
+
var LENS_QUOTER_ABI = [
|
|
46
|
+
"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
47
|
+
"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
48
|
+
"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)",
|
|
49
|
+
"function V3_SWAP_ROUTER() view returns (address)",
|
|
50
|
+
"function V4_ROUTER() view returns (address)",
|
|
51
|
+
"function SWAPR_SWAP_ROUTER() view returns (address)",
|
|
52
|
+
"function V4_QUOTER() view returns (address)"
|
|
53
|
+
];
|
|
54
|
+
var CHAINS = {
|
|
55
|
+
1: {
|
|
56
|
+
lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA",
|
|
57
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
58
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
59
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
60
|
+
wnative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
61
|
+
},
|
|
62
|
+
10: {
|
|
63
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
64
|
+
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
65
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
66
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
67
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
68
|
+
},
|
|
69
|
+
100: {
|
|
70
|
+
lensQuoter: "0xEe7596551a8339674d9Ee4B05b1A8E49cf738825",
|
|
71
|
+
v3SwapRouter: "0x0000000000000000000000000000000000000000",
|
|
72
|
+
v4Router: "0x0000000000000000000000000000000000000000",
|
|
73
|
+
swaprSwapRouter: "0xfFB643E73f280B97809A8b41f7232AB401a04ee1",
|
|
74
|
+
wnative: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"
|
|
75
|
+
},
|
|
76
|
+
8453: {
|
|
77
|
+
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
78
|
+
v3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
|
|
79
|
+
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
80
|
+
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
81
|
+
wnative: "0x4200000000000000000000000000000000000006"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var ETH = "0x0000000000000000000000000000000000000000";
|
|
85
|
+
var GNOSIS_sDAI = "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
86
|
+
function defaultDeadline() {
|
|
87
|
+
return BigInt(Math.trunc(Date.now() / 1e3) + 300);
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
AMM,
|
|
92
|
+
AMM_NAMES,
|
|
93
|
+
CHAINS,
|
|
94
|
+
ETH,
|
|
95
|
+
GNOSIS_sDAI,
|
|
96
|
+
LENS_QUOTER_ABI,
|
|
97
|
+
defaultDeadline
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Lens SDK — Core constants, ABIs, types, token list (zero dependencies)\n\n// ---- Chain config ----\n\n/** Unified AMM enum (same ordinals on every chain). */\nexport enum AMM {\n UNI_V3 = 0,\n UNI_V4 = 1,\n UNI_V4_HOOKED = 2,\n SWAPR_V3 = 3,\n}\n\nexport const AMM_NAMES: Record<AMM, string> = {\n [AMM.UNI_V3]: \"Uniswap V3\",\n [AMM.UNI_V4]: \"Uniswap V4\",\n [AMM.UNI_V4_HOOKED]: \"Uniswap V4 Hooked\",\n [AMM.SWAPR_V3]: \"Swapr V3\",\n};\n\n/** Shared LensQuoter ABI for the unified contract on all chains. */\nexport const LENS_QUOTER_ABI = [\n \"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)\",\n \"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)\",\n \"function V3_SWAP_ROUTER() view returns (address)\",\n \"function V4_ROUTER() view returns (address)\",\n \"function SWAPR_SWAP_ROUTER() view returns (address)\",\n \"function V4_QUOTER() view returns (address)\",\n] as const;\n\n/** Per-chain LensQuoter, official DEX routers, and wrapped native. */\nexport const CHAINS = {\n 1: {\n lensQuoter: \"0xae300296486a63621f7f31E1B94aD22d32347deA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\",\n },\n 10: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n 100: {\n lensQuoter: \"0xEe7596551a8339674d9Ee4B05b1A8E49cf738825\",\n v3SwapRouter: \"0x0000000000000000000000000000000000000000\",\n v4Router: \"0x0000000000000000000000000000000000000000\",\n swaprSwapRouter: \"0xfFB643E73f280B97809A8b41f7232AB401a04ee1\",\n wnative: \"0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d\",\n },\n 8453: {\n lensQuoter: \"0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA\",\n v3SwapRouter: \"0x2626664c2603336E57B271c5C0b26F421741e481\",\n v4Router: \"0x00000000000044a361Ae3cAc094c9D1b14Eece97\",\n swaprSwapRouter: \"0x0000000000000000000000000000000000000000\",\n wnative: \"0x4200000000000000000000000000000000000006\",\n },\n} as const;\n\nexport type ChainId = keyof typeof CHAINS;\n\nexport const ETH = \"0x0000000000000000000000000000000000000000\" as const;\n\n/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */\nexport const GNOSIS_sDAI = \"0xaf204776c7245bF4147c2612BF6e5972Ee483701\" as const;\n\n// ---- Types ----\n\nexport interface QuoteResult {\n amountIn: bigint;\n amountOut: bigint;\n /** Official DEX router to call. */\n target: string;\n /** Ready-to-send calldata for `target`. */\n data: string;\n msgValue: bigint;\n isTwoHop: boolean;\n sourceA: string;\n sourceB: string | null;\n}\n\nexport interface BaseQuoteParams {\n tokenIn: string;\n tokenOut: string;\n amount: bigint;\n}\n\nexport interface QuoteParams extends BaseQuoteParams {\n recipient: string;\n slippageBps?: number;\n deadline?: bigint;\n /** false = exactIn (default); true = exactOut. `amount` is amountIn or desired amountOut accordingly. */\n exactOut?: boolean;\n /** Optional V4 hooked-pool candidate (exactIn; can beat the primary route). */\n hookPoolFee?: number;\n hookTickSpacing?: number;\n hookAddress?: string;\n /**\n * Intermediate token for two-hop routes (`buildBestSwapViaToken`).\n * When set, skips the native/ERC20 cascade. On Gnosis, native/WXDAI↔ERC20\n * already defaults to ViaToken(sDAI); use this only to force a different mid.\n */\n intermediate?: string;\n}\n\n// ---- Helpers ----\n\nexport function defaultDeadline(): bigint {\n return BigInt(Math.trunc(Date.now() / 1000) + 300);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAK,MAAL,kBAAKA,SAAL;AACL,EAAAA,UAAA,YAAS,KAAT;AACA,EAAAA,UAAA,YAAS,KAAT;AACA,EAAAA,UAAA,mBAAgB,KAAhB;AACA,EAAAA,UAAA,cAAW,KAAX;AAJU,SAAAA;AAAA,GAAA;AAOL,IAAM,YAAiC;AAAA,EAC5C,CAAC,cAAU,GAAG;AAAA,EACd,CAAC,cAAU,GAAG;AAAA,EACd,CAAC,qBAAiB,GAAG;AAAA,EACrB,CAAC,gBAAY,GAAG;AAClB;AAGO,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,SAAS;AAAA,EACpB,GAAG;AAAA,IACD,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,IAAI;AAAA,IACF,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,KAAK;AAAA,IACH,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AAAA,EACA,MAAM;AAAA,IACJ,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,SAAS;AAAA,EACX;AACF;AAIO,IAAM,MAAM;AAGZ,IAAM,cAAc;AA2CpB,SAAS,kBAA0B;AACxC,SAAO,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI,GAAG;AACnD;","names":["AMM"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Unified AMM enum (same ordinals on every chain). */
|
|
2
|
+
declare enum AMM {
|
|
3
|
+
UNI_V3 = 0,
|
|
4
|
+
UNI_V4 = 1,
|
|
5
|
+
UNI_V4_HOOKED = 2,
|
|
6
|
+
SWAPR_V3 = 3
|
|
7
|
+
}
|
|
8
|
+
declare const AMM_NAMES: Record<AMM, string>;
|
|
9
|
+
/** Shared LensQuoter ABI for the unified contract on all chains. */
|
|
10
|
+
declare const LENS_QUOTER_ABI: readonly ["function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)", "function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)", "function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)", "function V3_SWAP_ROUTER() view returns (address)", "function V4_ROUTER() view returns (address)", "function SWAPR_SWAP_ROUTER() view returns (address)", "function V4_QUOTER() view returns (address)"];
|
|
11
|
+
/** Per-chain LensQuoter, official DEX routers, and wrapped native. */
|
|
12
|
+
declare const CHAINS: {
|
|
13
|
+
readonly 1: {
|
|
14
|
+
readonly lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA";
|
|
15
|
+
readonly v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";
|
|
16
|
+
readonly v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97";
|
|
17
|
+
readonly swaprSwapRouter: "0x0000000000000000000000000000000000000000";
|
|
18
|
+
readonly wnative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
19
|
+
};
|
|
20
|
+
readonly 10: {
|
|
21
|
+
readonly lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA";
|
|
22
|
+
readonly v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";
|
|
23
|
+
readonly v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97";
|
|
24
|
+
readonly swaprSwapRouter: "0x0000000000000000000000000000000000000000";
|
|
25
|
+
readonly wnative: "0x4200000000000000000000000000000000000006";
|
|
26
|
+
};
|
|
27
|
+
readonly 100: {
|
|
28
|
+
readonly lensQuoter: "0xEe7596551a8339674d9Ee4B05b1A8E49cf738825";
|
|
29
|
+
readonly v3SwapRouter: "0x0000000000000000000000000000000000000000";
|
|
30
|
+
readonly v4Router: "0x0000000000000000000000000000000000000000";
|
|
31
|
+
readonly swaprSwapRouter: "0xfFB643E73f280B97809A8b41f7232AB401a04ee1";
|
|
32
|
+
readonly wnative: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d";
|
|
33
|
+
};
|
|
34
|
+
readonly 8453: {
|
|
35
|
+
readonly lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA";
|
|
36
|
+
readonly v3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481";
|
|
37
|
+
readonly v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97";
|
|
38
|
+
readonly swaprSwapRouter: "0x0000000000000000000000000000000000000000";
|
|
39
|
+
readonly wnative: "0x4200000000000000000000000000000000000006";
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
type ChainId = keyof typeof CHAINS;
|
|
43
|
+
declare const ETH: "0x0000000000000000000000000000000000000000";
|
|
44
|
+
/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */
|
|
45
|
+
declare const GNOSIS_sDAI: "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
46
|
+
interface QuoteResult {
|
|
47
|
+
amountIn: bigint;
|
|
48
|
+
amountOut: bigint;
|
|
49
|
+
/** Official DEX router to call. */
|
|
50
|
+
target: string;
|
|
51
|
+
/** Ready-to-send calldata for `target`. */
|
|
52
|
+
data: string;
|
|
53
|
+
msgValue: bigint;
|
|
54
|
+
isTwoHop: boolean;
|
|
55
|
+
sourceA: string;
|
|
56
|
+
sourceB: string | null;
|
|
57
|
+
}
|
|
58
|
+
interface BaseQuoteParams {
|
|
59
|
+
tokenIn: string;
|
|
60
|
+
tokenOut: string;
|
|
61
|
+
amount: bigint;
|
|
62
|
+
}
|
|
63
|
+
interface QuoteParams extends BaseQuoteParams {
|
|
64
|
+
recipient: string;
|
|
65
|
+
slippageBps?: number;
|
|
66
|
+
deadline?: bigint;
|
|
67
|
+
/** false = exactIn (default); true = exactOut. `amount` is amountIn or desired amountOut accordingly. */
|
|
68
|
+
exactOut?: boolean;
|
|
69
|
+
/** Optional V4 hooked-pool candidate (exactIn; can beat the primary route). */
|
|
70
|
+
hookPoolFee?: number;
|
|
71
|
+
hookTickSpacing?: number;
|
|
72
|
+
hookAddress?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Intermediate token for two-hop routes (`buildBestSwapViaToken`).
|
|
75
|
+
* When set, skips the native/ERC20 cascade. On Gnosis, native/WXDAI↔ERC20
|
|
76
|
+
* already defaults to ViaToken(sDAI); use this only to force a different mid.
|
|
77
|
+
*/
|
|
78
|
+
intermediate?: string;
|
|
79
|
+
}
|
|
80
|
+
declare function defaultDeadline(): bigint;
|
|
81
|
+
|
|
82
|
+
export { AMM, AMM_NAMES, type BaseQuoteParams, CHAINS, type ChainId, ETH, GNOSIS_sDAI, LENS_QUOTER_ABI, type QuoteParams, type QuoteResult, defaultDeadline };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Unified AMM enum (same ordinals on every chain). */
|
|
2
|
-
|
|
2
|
+
declare enum AMM {
|
|
3
3
|
UNI_V3 = 0,
|
|
4
4
|
UNI_V4 = 1,
|
|
5
5
|
UNI_V4_HOOKED = 2,
|
|
6
6
|
SWAPR_V3 = 3
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
declare const AMM_NAMES: Record<AMM, string>;
|
|
9
9
|
/** Shared LensQuoter ABI for the unified contract on all chains. */
|
|
10
|
-
|
|
10
|
+
declare const LENS_QUOTER_ABI: readonly ["function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)", "function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)", "function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)", "function V3_SWAP_ROUTER() view returns (address)", "function V4_ROUTER() view returns (address)", "function SWAPR_SWAP_ROUTER() view returns (address)", "function V4_QUOTER() view returns (address)"];
|
|
11
11
|
/** Per-chain LensQuoter, official DEX routers, and wrapped native. */
|
|
12
|
-
|
|
12
|
+
declare const CHAINS: {
|
|
13
13
|
readonly 1: {
|
|
14
14
|
readonly lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA";
|
|
15
15
|
readonly v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";
|
|
@@ -39,11 +39,11 @@ export declare const CHAINS: {
|
|
|
39
39
|
readonly wnative: "0x4200000000000000000000000000000000000006";
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
type ChainId = keyof typeof CHAINS;
|
|
43
|
+
declare const ETH: "0x0000000000000000000000000000000000000000";
|
|
44
44
|
/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
declare const GNOSIS_sDAI: "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
46
|
+
interface QuoteResult {
|
|
47
47
|
amountIn: bigint;
|
|
48
48
|
amountOut: bigint;
|
|
49
49
|
/** Official DEX router to call. */
|
|
@@ -55,12 +55,12 @@ export interface QuoteResult {
|
|
|
55
55
|
sourceA: string;
|
|
56
56
|
sourceB: string | null;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
interface BaseQuoteParams {
|
|
59
59
|
tokenIn: string;
|
|
60
60
|
tokenOut: string;
|
|
61
61
|
amount: bigint;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
interface QuoteParams extends BaseQuoteParams {
|
|
64
64
|
recipient: string;
|
|
65
65
|
slippageBps?: number;
|
|
66
66
|
deadline?: bigint;
|
|
@@ -77,4 +77,6 @@ export interface QuoteParams extends BaseQuoteParams {
|
|
|
77
77
|
*/
|
|
78
78
|
intermediate?: string;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
declare function defaultDeadline(): bigint;
|
|
81
|
+
|
|
82
|
+
export { AMM, AMM_NAMES, type BaseQuoteParams, CHAINS, type ChainId, ETH, GNOSIS_sDAI, LENS_QUOTER_ABI, type QuoteParams, type QuoteResult, defaultDeadline };
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import {
|
|
2
|
+
AMM,
|
|
3
|
+
AMM_NAMES,
|
|
4
|
+
CHAINS,
|
|
5
|
+
ETH,
|
|
6
|
+
GNOSIS_sDAI,
|
|
7
|
+
LENS_QUOTER_ABI,
|
|
8
|
+
defaultDeadline
|
|
9
|
+
} from "./chunk-BW3R2UBK.js";
|
|
10
|
+
export {
|
|
11
|
+
AMM,
|
|
12
|
+
AMM_NAMES,
|
|
13
|
+
CHAINS,
|
|
14
|
+
ETH,
|
|
15
|
+
GNOSIS_sDAI,
|
|
16
|
+
LENS_QUOTER_ABI,
|
|
17
|
+
defaultDeadline
|
|
16
18
|
};
|
|
17
|
-
|
|
18
|
-
export const LENS_QUOTER_ABI = [
|
|
19
|
-
"function buildBestSwapViaETH(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
20
|
-
"function buildBestSwapViaToken(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline, uint24 hookPoolFee, int24 hookTickSpacing, address hookAddress, address mid) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, address target, bytes data, uint256 msgValue)",
|
|
21
|
-
"function buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) best, address target, bytes callData, uint256 amountLimit, uint256 msgValue)",
|
|
22
|
-
"function V3_SWAP_ROUTER() view returns (address)",
|
|
23
|
-
"function V4_ROUTER() view returns (address)",
|
|
24
|
-
"function SWAPR_SWAP_ROUTER() view returns (address)",
|
|
25
|
-
"function V4_QUOTER() view returns (address)",
|
|
26
|
-
];
|
|
27
|
-
/** Per-chain LensQuoter, official DEX routers, and wrapped native. */
|
|
28
|
-
export const CHAINS = {
|
|
29
|
-
1: {
|
|
30
|
-
lensQuoter: "0xae300296486a63621f7f31E1B94aD22d32347deA",
|
|
31
|
-
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
32
|
-
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
33
|
-
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
34
|
-
wnative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
35
|
-
},
|
|
36
|
-
10: {
|
|
37
|
-
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
38
|
-
v3SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
39
|
-
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
40
|
-
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
41
|
-
wnative: "0x4200000000000000000000000000000000000006",
|
|
42
|
-
},
|
|
43
|
-
100: {
|
|
44
|
-
lensQuoter: "0xEe7596551a8339674d9Ee4B05b1A8E49cf738825",
|
|
45
|
-
v3SwapRouter: "0x0000000000000000000000000000000000000000",
|
|
46
|
-
v4Router: "0x0000000000000000000000000000000000000000",
|
|
47
|
-
swaprSwapRouter: "0xfFB643E73f280B97809A8b41f7232AB401a04ee1",
|
|
48
|
-
wnative: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
|
|
49
|
-
},
|
|
50
|
-
8453: {
|
|
51
|
-
lensQuoter: "0xcBBbABD15895ae7b2e28BE6f250729098F1c69FA",
|
|
52
|
-
v3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
|
|
53
|
-
v4Router: "0x00000000000044a361Ae3cAc094c9D1b14Eece97",
|
|
54
|
-
swaprSwapRouter: "0x0000000000000000000000000000000000000000",
|
|
55
|
-
wnative: "0x4200000000000000000000000000000000000006",
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
export const ETH = "0x0000000000000000000000000000000000000000";
|
|
59
|
-
/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */
|
|
60
|
-
export const GNOSIS_sDAI = "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
61
|
-
// ---- Helpers ----
|
|
62
|
-
export function defaultDeadline() {
|
|
63
|
-
return BigInt(Math.trunc(Date.now() / 1000) + 300);
|
|
64
|
-
}
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seer-pm/lens",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "TypeScript SDK for Seer market swaps (collateral ↔ outcome) via LensQuoter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,16 +10,29 @@
|
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://github.com/seer-pm/lens/tree/main/sdk#readme",
|
|
12
12
|
"type": "module",
|
|
13
|
-
"main": "./dist/index.
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
14
15
|
"types": "./dist/index.d.ts",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
|
-
"
|
|
18
|
-
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
}
|
|
19
26
|
},
|
|
20
27
|
"./client": {
|
|
21
|
-
"
|
|
22
|
-
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/client.d.ts",
|
|
30
|
+
"default": "./dist/client.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/client.d.cts",
|
|
34
|
+
"default": "./dist/client.cjs"
|
|
35
|
+
}
|
|
23
36
|
}
|
|
24
37
|
},
|
|
25
38
|
"peerDependencies": {
|
|
@@ -31,7 +44,7 @@
|
|
|
31
44
|
}
|
|
32
45
|
},
|
|
33
46
|
"scripts": {
|
|
34
|
-
"build": "
|
|
47
|
+
"build": "tsup",
|
|
35
48
|
"prepublishOnly": "npm run build",
|
|
36
49
|
"test:integration": "vitest run --config vitest.config.ts"
|
|
37
50
|
},
|
|
@@ -49,6 +62,7 @@
|
|
|
49
62
|
"ethers": "^5.7.2",
|
|
50
63
|
"graphql": "^17.0.2",
|
|
51
64
|
"graphql-tag": "^2.12.7",
|
|
65
|
+
"tsup": "^8.5.1",
|
|
52
66
|
"typescript": "^5.0.0",
|
|
53
67
|
"viem": "^2.0.0",
|
|
54
68
|
"vitest": "^3.2.4"
|