@seer-pm/lens 1.0.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/README.md +141 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.js +157 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +64 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @seer-pm/lens
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for **trading Seer market tokens** — outcome ERC20s vs Seer collateral — on Ethereum, Optimism, Gnosis, and Base. Wraps the on-chain LensQuoter to pick the best route on Seer’s venues (UniV3, UniV4 with/without hooks, Swapr) and returns ready-to-send calldata for **official** DEX routers.
|
|
4
|
+
|
|
5
|
+
Typical trades: **collateral ↔ outcome** (`sDAI` / `sUSDS` ↔ outcome). On Gnosis, **native (xDAI) or WXDAI ↔ outcome** routes via `sDAI`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @seer-pm/lens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
Outcome addresses come from [Seer markets](https://app.seer.pm). Collateral is chain-specific (`sDAI` on Gnosis, `sUSDS` on Optimism/Base).
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Lens, ETH, GNOSIS_sDAI } from "@seer-pm/lens/client";
|
|
19
|
+
import { createPublicClient, http, parseEther } from "viem";
|
|
20
|
+
import { gnosis } from "viem/chains";
|
|
21
|
+
|
|
22
|
+
const publicClient = createPublicClient({ chain: gnosis, transport: http() });
|
|
23
|
+
const lens = new Lens(publicClient, 100);
|
|
24
|
+
|
|
25
|
+
// Collateral → outcome (single-hop on Swapr)
|
|
26
|
+
const q = await lens.quote({
|
|
27
|
+
tokenIn: GNOSIS_sDAI,
|
|
28
|
+
tokenOut: outcomeToken, // from a Seer market
|
|
29
|
+
amount: parseEther("10"),
|
|
30
|
+
recipient: account.address,
|
|
31
|
+
slippageBps: 100,
|
|
32
|
+
});
|
|
33
|
+
// q.amountOut — show to user / check before send
|
|
34
|
+
// Approve the venue router (q.target) for tokenIn first if needed.
|
|
35
|
+
await walletClient.sendTransaction({
|
|
36
|
+
to: q.target,
|
|
37
|
+
data: q.data,
|
|
38
|
+
value: q.msgValue,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Same pattern on Optimism (`10`) or Base (`8453`) with that chain’s collateral (`sUSDS`) and Uni V3/V4 venues.
|
|
43
|
+
|
|
44
|
+
### Native / WXDAI → outcome (Gnosis)
|
|
45
|
+
|
|
46
|
+
On Gnosis, **native (xDAI) or WXDAI ↔ ERC20** uses `ViaToken(sDAI)` directly — typically a two-hop `WXDAI ↔ sDAI ↔ outcome` on Swapr (single-hop when sDAI is already an endpoint). Pure ERC20 ↔ ERC20 (e.g. sDAI → outcome) uses `buildBestSwap` only. Pass `intermediate` only to force a different mid. Two-hop routes use same-venue path encoding on the official Swapr router; `slippageBps` applies once to the final minOut/maxIn.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Lens, ETH } from "@seer-pm/lens/client";
|
|
50
|
+
|
|
51
|
+
const quote = await lens.quote({
|
|
52
|
+
tokenIn: ETH, // xDAI
|
|
53
|
+
tokenOut: outcomeToken,
|
|
54
|
+
amount: parseEther("1"),
|
|
55
|
+
recipient: account.address,
|
|
56
|
+
});
|
|
57
|
+
// quote.isTwoHop === true → WXDAI → sDAI → outcome
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires a LensQuoter that exposes `buildBestSwapViaToken`.
|
|
61
|
+
|
|
62
|
+
### Constants Only
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { CHAINS, LENS_QUOTER_ABI, AMM, ETH, GNOSIS_sDAI } from "@seer-pm/lens";
|
|
66
|
+
|
|
67
|
+
CHAINS[10].v3SwapRouter; // Optimism SwapRouter02
|
|
68
|
+
CHAINS[10].lensQuoter;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## API
|
|
72
|
+
|
|
73
|
+
### `Lens` class
|
|
74
|
+
|
|
75
|
+
Exported from `@seer-pm/lens/client`.
|
|
76
|
+
|
|
77
|
+
#### `constructor(client, chainId)`
|
|
78
|
+
|
|
79
|
+
- **client**: a viem `PublicClient`
|
|
80
|
+
- **chainId**: `1` | `10` | `100` | `8453`
|
|
81
|
+
|
|
82
|
+
#### `quote(params): Promise<QuoteResult>`
|
|
83
|
+
|
|
84
|
+
Builds official-router calldata for Seer trade shapes:
|
|
85
|
+
|
|
86
|
+
- **collateral ↔ outcome** (ERC20 ↔ ERC20) → direct `buildBestSwap`
|
|
87
|
+
- **native / wrapped-native ↔ outcome** → on Gnosis, `ViaToken(sDAI)` directly; elsewhere `buildBestSwapViaETH`
|
|
88
|
+
- **`intermediate` set** → two-hop (or one-hop) via that mid (`buildBestSwapViaToken`)
|
|
89
|
+
|
|
90
|
+
Pass `exactOut: true` for exact-out quotes (`amount` = desired output; `result.amountIn` = required input). Optional hook args enable a V4 hooked-pool candidate (exactIn).
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const result = await lens.quote({
|
|
94
|
+
tokenIn: ETH, // xDAI on Gnosis
|
|
95
|
+
tokenOut: outcomeToken,
|
|
96
|
+
amount: parseEther("1"),
|
|
97
|
+
recipient: "0x...",
|
|
98
|
+
slippageBps: 50,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
result.amountIn;
|
|
102
|
+
result.amountOut;
|
|
103
|
+
result.target; // official DEX router
|
|
104
|
+
result.data;
|
|
105
|
+
result.msgValue;
|
|
106
|
+
result.isTwoHop;
|
|
107
|
+
result.sourceA;
|
|
108
|
+
|
|
109
|
+
await walletClient.sendTransaction({
|
|
110
|
+
to: result.target,
|
|
111
|
+
data: result.data,
|
|
112
|
+
value: result.msgValue,
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Supported venues
|
|
117
|
+
|
|
118
|
+
Venues match Seer’s liquidity per chain: Swapr on Gnosis; Uniswap V3/V4 on Ethereum, Optimism, and Base.
|
|
119
|
+
|
|
120
|
+
| Chain | UniV3 | UniV4 | UniV4 hooked | Swapr |
|
|
121
|
+
|---|---|---|---|---|
|
|
122
|
+
| Ethereum / Base / Optimism | yes | yes | via hook args | no |
|
|
123
|
+
| Gnosis | no | no | no | yes |
|
|
124
|
+
|
|
125
|
+
## Exports
|
|
126
|
+
|
|
127
|
+
| Import | Contents |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `@seer-pm/lens` | Constants, ABIs, types, `CHAINS`, `ETH`, `GNOSIS_sDAI` |
|
|
130
|
+
| `@seer-pm/lens/client` | `Lens` + re-exports (peer: viem ^2) |
|
|
131
|
+
|
|
132
|
+
## Contracts
|
|
133
|
+
|
|
134
|
+
`CHAINS.lensQuoter` points at the deployed quoter. After a new deploy, update `sdk/src/index.ts` and rebuild.
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
forge script script/Deploy.s.sol:Deploy --rpc-url ethereum --broadcast
|
|
138
|
+
forge script script/Deploy.s.sol:Deploy --rpc-url op --broadcast
|
|
139
|
+
forge script script/Deploy.s.sol:Deploy --rpc-url base --broadcast
|
|
140
|
+
forge script script/Deploy.s.sol:Deploy --rpc-url gnosis --broadcast
|
|
141
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { PublicClient, Address } from "viem";
|
|
2
|
+
import { type ChainId, type QuoteParams, type QuoteResult } from "./index.js";
|
|
3
|
+
export { ETH, GNOSIS_sDAI, AMM, AMM_NAMES, CHAINS, LENS_QUOTER_ABI, defaultDeadline, } from "./index.js";
|
|
4
|
+
export type { QuoteResult, BaseQuoteParams, QuoteParams, ChainId } from "./index.js";
|
|
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
|
+
export 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
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Lens SDK — client
|
|
2
|
+
import { parseAbi, isAddressEqual, zeroAddress } from "viem";
|
|
3
|
+
import { CHAINS, GNOSIS_sDAI, LENS_QUOTER_ABI, AMM_NAMES, defaultDeadline, } from "./index.js";
|
|
4
|
+
// viem's parseAbi (abitype) doesn't support inline `tuple(...)` syntax,
|
|
5
|
+
// so rewrite the shared quoter ABI strings to use a named struct.
|
|
6
|
+
const QUOTE_TUPLE = "tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut)";
|
|
7
|
+
const QUOTE_STRUCT = "struct Quote { uint8 source; uint256 feeBps; uint256 amountIn; uint256 amountOut; }";
|
|
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. */
|
|
14
|
+
function ammName(source) {
|
|
15
|
+
return AMM_NAMES[source] || `AMM #${source}`;
|
|
16
|
+
}
|
|
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
|
+
function mapViaResult(value) {
|
|
23
|
+
const [a, b, target, data, msgValue] = value;
|
|
24
|
+
const isTwoHop = b.amountOut > 0n;
|
|
25
|
+
return {
|
|
26
|
+
amountIn: a.amountIn,
|
|
27
|
+
amountOut: isTwoHop ? b.amountOut : a.amountOut,
|
|
28
|
+
target: target,
|
|
29
|
+
data: data,
|
|
30
|
+
msgValue: msgValue ?? 0n,
|
|
31
|
+
isTwoHop,
|
|
32
|
+
sourceA: ammName(a.source),
|
|
33
|
+
sourceB: isTwoHop ? ammName(b.source) : null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
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
|
+
function involvesNativeOrWnative(tokenIn, tokenOut, wnative) {
|
|
42
|
+
return (isAddressEqual(tokenIn, zeroAddress)
|
|
43
|
+
|| isAddressEqual(tokenOut, zeroAddress)
|
|
44
|
+
|| isAddressEqual(tokenIn, wnative)
|
|
45
|
+
|| isAddressEqual(tokenOut, wnative));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lens SDK client: quotes best routes via the unified on-chain LensQuoter
|
|
49
|
+
* and builds ready-to-send txs for official DEX routers.
|
|
50
|
+
*/
|
|
51
|
+
export class Lens {
|
|
52
|
+
client;
|
|
53
|
+
chainId;
|
|
54
|
+
lensQuoter;
|
|
55
|
+
wnative;
|
|
56
|
+
quoterAbi;
|
|
57
|
+
/**
|
|
58
|
+
* @param client - viem public client for the target chain
|
|
59
|
+
* @param chainId - chain id (`1` | `10` | `100` | `8453`)
|
|
60
|
+
* @param lensQuoter - optional LensQuoter address; defaults to `CHAINS[chainId].lensQuoter`
|
|
61
|
+
*/
|
|
62
|
+
constructor(client, chainId, lensQuoter) {
|
|
63
|
+
this.client = client;
|
|
64
|
+
this.chainId = chainId;
|
|
65
|
+
const chain = CHAINS[chainId];
|
|
66
|
+
this.lensQuoter = lensQuoter ?? chain.lensQuoter;
|
|
67
|
+
this.wnative = chain.wnative;
|
|
68
|
+
this.quoterAbi = quoterAbi;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Builds calldata for a two-hop (or one-hop if mid is unused) route via a
|
|
72
|
+
* mid token — used when the caller sets `intermediate`, or as the default
|
|
73
|
+
* Gnosis path for native/WXDAI↔ERC20 (`mid = GNOSIS_sDAI`).
|
|
74
|
+
*/
|
|
75
|
+
async viaToken(params) {
|
|
76
|
+
return this.client.readContract({
|
|
77
|
+
address: this.lensQuoter,
|
|
78
|
+
abi: this.quoterAbi,
|
|
79
|
+
functionName: "buildBestSwapViaToken",
|
|
80
|
+
args: [
|
|
81
|
+
params.recipient,
|
|
82
|
+
params.exactOut,
|
|
83
|
+
params.tokenIn,
|
|
84
|
+
params.tokenOut,
|
|
85
|
+
params.amount,
|
|
86
|
+
BigInt(params.slippageBps),
|
|
87
|
+
params.deadline,
|
|
88
|
+
params.hookPoolFee,
|
|
89
|
+
params.hookTickSpacing,
|
|
90
|
+
params.hookAddress,
|
|
91
|
+
params.mid,
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Finds a swap route via LensQuoter and returns amounts plus ready-to-send
|
|
97
|
+
* calldata for an official DEX router.
|
|
98
|
+
*
|
|
99
|
+
* Route selection by request shape:
|
|
100
|
+
* - `intermediate` set → `buildBestSwapViaToken(mid)` only
|
|
101
|
+
* - native / WNATIVE ↔ ERC20 → on Gnosis, `ViaToken(sDAI)` directly;
|
|
102
|
+
* elsewhere `buildBestSwapViaETH`
|
|
103
|
+
* - ERC20 ↔ ERC20 → `buildBestSwap` only
|
|
104
|
+
*/
|
|
105
|
+
async quote(params) {
|
|
106
|
+
const { tokenIn, tokenOut, amount, recipient, slippageBps = DEFAULT_SLIPPAGE, deadline = defaultDeadline(), exactOut = false, hookPoolFee = 0, hookTickSpacing = 0, hookAddress = zeroAddress, intermediate, } = params;
|
|
107
|
+
const routeArgs = {
|
|
108
|
+
recipient, exactOut, tokenIn, tokenOut, amount,
|
|
109
|
+
slippageBps, deadline, hookPoolFee, hookTickSpacing, hookAddress,
|
|
110
|
+
};
|
|
111
|
+
// Caller forced a mid token: skip native/ERC20 cascade.
|
|
112
|
+
if (intermediate) {
|
|
113
|
+
return mapViaResult(await this.viaToken({ ...routeArgs, mid: intermediate }));
|
|
114
|
+
}
|
|
115
|
+
const useViaEth = involvesNativeOrWnative(tokenIn, tokenOut, this.wnative);
|
|
116
|
+
if (useViaEth) {
|
|
117
|
+
// Gnosis (Seer): outcomes trade vs sDAI — skip ViaETH entirely.
|
|
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
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Unified AMM enum (same ordinals on every chain). */
|
|
2
|
+
export declare enum AMM {
|
|
3
|
+
UNI_V3 = 0,
|
|
4
|
+
UNI_V4 = 1,
|
|
5
|
+
UNI_V4_HOOKED = 2,
|
|
6
|
+
SWAPR_V3 = 3
|
|
7
|
+
}
|
|
8
|
+
export declare const AMM_NAMES: Record<AMM, string>;
|
|
9
|
+
/** Shared LensQuoter ABI for the unified contract on all chains. */
|
|
10
|
+
export 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
|
+
export 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
|
+
export type ChainId = keyof typeof CHAINS;
|
|
43
|
+
export declare const ETH: "0x0000000000000000000000000000000000000000";
|
|
44
|
+
/** Gnosis sDAI — default ViaToken mid for native/WXDAI↔ERC20 on Gnosis (Seer). */
|
|
45
|
+
export declare const GNOSIS_sDAI: "0xaf204776c7245bF4147c2612BF6e5972Ee483701";
|
|
46
|
+
export 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
|
+
export interface BaseQuoteParams {
|
|
59
|
+
tokenIn: string;
|
|
60
|
+
tokenOut: string;
|
|
61
|
+
amount: bigint;
|
|
62
|
+
}
|
|
63
|
+
export 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
|
+
export declare function defaultDeadline(): bigint;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Lens SDK — Core constants, ABIs, types, token list (zero dependencies)
|
|
2
|
+
// ---- Chain config ----
|
|
3
|
+
/** Unified AMM enum (same ordinals on every chain). */
|
|
4
|
+
export var AMM;
|
|
5
|
+
(function (AMM) {
|
|
6
|
+
AMM[AMM["UNI_V3"] = 0] = "UNI_V3";
|
|
7
|
+
AMM[AMM["UNI_V4"] = 1] = "UNI_V4";
|
|
8
|
+
AMM[AMM["UNI_V4_HOOKED"] = 2] = "UNI_V4_HOOKED";
|
|
9
|
+
AMM[AMM["SWAPR_V3"] = 3] = "SWAPR_V3";
|
|
10
|
+
})(AMM || (AMM = {}));
|
|
11
|
+
export const AMM_NAMES = {
|
|
12
|
+
[AMM.UNI_V3]: "Uniswap V3",
|
|
13
|
+
[AMM.UNI_V4]: "Uniswap V4",
|
|
14
|
+
[AMM.UNI_V4_HOOKED]: "Uniswap V4 Hooked",
|
|
15
|
+
[AMM.SWAPR_V3]: "Swapr V3",
|
|
16
|
+
};
|
|
17
|
+
/** Shared LensQuoter ABI for the unified contract on all chains. */
|
|
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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seer-pm/lens",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for Seer market swaps (collateral ↔ outcome) via LensQuoter",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/seer-pm/lens.git",
|
|
9
|
+
"directory": "sdk"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/seer-pm/lens/tree/main/sdk#readme",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./dist/client.d.ts",
|
|
22
|
+
"import": "./dist/client.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"viem": "^2.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"viem": {
|
|
30
|
+
"optional": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
36
|
+
"test:integration": "vitest run --config vitest.config.ts"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@swapr/sdk": "github:seer-pm/swapr-sdk#e4db9435d06604748cb51b3682025939e213c0af",
|
|
46
|
+
"@uniswap/sdk-core": "^7.7.2",
|
|
47
|
+
"@uniswap/v3-sdk": "^3.19.0",
|
|
48
|
+
"@uniswap/v4-sdk": "^1.20.0",
|
|
49
|
+
"ethers": "^5.7.2",
|
|
50
|
+
"graphql": "^17.0.2",
|
|
51
|
+
"graphql-tag": "^2.12.7",
|
|
52
|
+
"typescript": "^5.0.0",
|
|
53
|
+
"viem": "^2.0.0",
|
|
54
|
+
"vitest": "^3.2.4"
|
|
55
|
+
}
|
|
56
|
+
}
|