@logswap/sdk 0.5.90 → 0.5.92
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 +136 -31
- package/dist/actions.js +4 -3
- package/dist/admin.d.ts +96 -925
- package/dist/admin.js +113 -194
- package/dist/chains.d.ts +13 -4
- package/dist/chains.js +22 -9
- package/dist/claims.d.ts +1 -1
- package/dist/claims.js +11 -9
- package/dist/client.d.ts +42 -20
- package/dist/client.js +86 -26
- package/dist/fees.d.ts +1 -1
- package/dist/fees.js +5 -4
- package/dist/fpool.d.ts +327 -1120
- package/dist/fpool.js +408 -475
- package/dist/generated.d.ts +5017 -7631
- package/dist/generated.js +3040 -4879
- package/dist/history.js +12 -14
- package/dist/index.d.ts +5 -7
- package/dist/index.js +5 -7
- package/dist/indexer.d.ts +2 -2
- package/dist/indexer.js +12 -9
- package/dist/keys.d.ts +15 -3
- package/dist/keys.js +5 -1
- package/dist/liquidity.d.ts +1 -1
- package/dist/liquidity.js +16 -9
- package/dist/onboard.d.ts +16 -11
- package/dist/onboard.js +27 -21
- package/dist/pools.d.ts +2 -0
- package/dist/pools.js +21 -13
- package/dist/positions.d.ts +1 -1
- package/dist/positions.js +18 -17
- package/dist/quote.d.ts +15 -0
- package/dist/quote.js +36 -0
- package/dist/swap.d.ts +7 -9
- package/dist/swap.js +40 -25
- package/dist/views.d.ts +1 -1
- package/dist/write.d.ts +7 -2
- package/dist/write.js +10 -7
- package/package.json +3 -3
- package/src/actions.ts +4 -3
- package/src/admin.ts +143 -249
- package/src/chains.ts +32 -13
- package/src/claims.ts +11 -10
- package/src/client.ts +111 -39
- package/src/fees.ts +6 -6
- package/src/fpool.ts +555 -648
- package/src/generated.ts +3063 -4904
- package/src/history.ts +11 -11
- package/src/index.ts +5 -7
- package/src/indexer.ts +13 -11
- package/src/keys.ts +19 -3
- package/src/liquidity.ts +16 -10
- package/src/onboard.ts +29 -21
- package/src/pools.ts +23 -15
- package/src/positions.ts +18 -18
- package/src/quote.ts +36 -0
- package/src/swap.ts +46 -25
- package/src/views.ts +1 -2
- package/src/write.ts +11 -10
package/dist/pools.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* conversion is. Prefer comparing in log space when precision matters.
|
|
13
13
|
*/
|
|
14
14
|
import { formatUnits } from "viem";
|
|
15
|
-
import {
|
|
16
|
-
import { clientChainId } from "./client.js";
|
|
15
|
+
import { lensCAbi, managerCAbi } from "./generated.js";
|
|
16
|
+
import { lensC, managerC, clientChainId } from "./client.js";
|
|
17
17
|
import { signerFor } from "./write.js";
|
|
18
18
|
import { readCachedToken, registerCacheClear, writeCachedToken } from "./tokencache.js";
|
|
19
19
|
import { poolId } from "./keys.js";
|
|
@@ -21,8 +21,8 @@ import { getEventLogs } from "./history.js";
|
|
|
21
21
|
/** Read a market's full state by key, through the lens (`getPools`; C version 7). All zero, `initialized` false, for a market nobody opened. */
|
|
22
22
|
export async function getPool(c, key) {
|
|
23
23
|
const v = (await c.public.readContract({
|
|
24
|
-
address: c
|
|
25
|
-
abi:
|
|
24
|
+
address: lensC(c),
|
|
25
|
+
abi: lensCAbi,
|
|
26
26
|
functionName: "getPools",
|
|
27
27
|
args: [[poolId(key)]],
|
|
28
28
|
}));
|
|
@@ -109,16 +109,17 @@ export function lpEdge(state) {
|
|
|
109
109
|
* `deployBlock` unless `fromBlock` says otherwise.
|
|
110
110
|
*/
|
|
111
111
|
export async function discoverMarkets(c, opts = {}) {
|
|
112
|
-
const ev =
|
|
112
|
+
const ev = managerCAbi.find((x) => x.type === "event" && x.name === "PoolCreated");
|
|
113
113
|
if (!ev)
|
|
114
114
|
throw new Error("logswap: PoolCreated event missing from the generated ABI");
|
|
115
115
|
const args = {};
|
|
116
|
-
// `quote` is an indexed topic (C 13: `PoolCreated(poolId, quote, creator, base, …)`); `base` no longer is, so it filters below
|
|
116
|
+
// `quote` is an indexed topic (C 13: `PoolCreated(poolId, quote, creator, base, …)`); `base` no longer is, so it filters below.
|
|
117
|
+
// C 15 (decision 097): the event ends with the key's `salt`, so the whole key — `creator` and `salt` included — is rebuilt from the log.
|
|
117
118
|
if (opts.quote)
|
|
118
119
|
args.quote = opts.quote;
|
|
119
120
|
const { logs } = await getEventLogs(c, {
|
|
120
121
|
indexer: opts.indexer,
|
|
121
|
-
address: c
|
|
122
|
+
address: managerC(c),
|
|
122
123
|
event: ev,
|
|
123
124
|
args,
|
|
124
125
|
fromBlock: opts.fromBlock, // the client's deployBlock when absent
|
|
@@ -132,6 +133,8 @@ export async function discoverMarkets(c, opts = {}) {
|
|
|
132
133
|
quote: a.quote,
|
|
133
134
|
tickSpacing: a.tickSpacing,
|
|
134
135
|
policy: a.policy,
|
|
136
|
+
creator: a.creator,
|
|
137
|
+
salt: a.salt,
|
|
135
138
|
swapFee: a.swapFee,
|
|
136
139
|
mintFee: a.mintFee,
|
|
137
140
|
};
|
|
@@ -154,8 +157,8 @@ export async function discoverMarkets(c, opts = {}) {
|
|
|
154
157
|
*/
|
|
155
158
|
export async function liveFloors(c, key) {
|
|
156
159
|
return c.public.readContract({
|
|
157
|
-
address: c
|
|
158
|
-
abi:
|
|
160
|
+
address: lensC(c),
|
|
161
|
+
abi: lensCAbi,
|
|
159
162
|
functionName: "liveTicks",
|
|
160
163
|
args: [poolId(key)],
|
|
161
164
|
});
|
|
@@ -163,8 +166,8 @@ export async function liveFloors(c, key) {
|
|
|
163
166
|
/** Is this floor on the market's grid, and inside `MAX_ABS_FLOOR`? Pure — no RPC on the manager. */
|
|
164
167
|
export async function isValidFloor(c, key, floor) {
|
|
165
168
|
return c.public.readContract({
|
|
166
|
-
address: c
|
|
167
|
-
abi:
|
|
169
|
+
address: lensC(c),
|
|
170
|
+
abi: lensCAbi,
|
|
168
171
|
functionName: "isValidFloor",
|
|
169
172
|
args: [poolId(key), floor],
|
|
170
173
|
});
|
|
@@ -341,15 +344,20 @@ export async function marketOpenedAt(c, m) {
|
|
|
341
344
|
}
|
|
342
345
|
/**
|
|
343
346
|
* Create a C market: `initialize(key, initialLogPrice)` on the manager — a call, not a deployment, and no funds move. The
|
|
347
|
+
* caller must BE the key's `creator` (C 15, decision 097: `NotCreator`; the registry resolves a routed caller to its user), and only
|
|
348
|
+
* the creator may make the first mint, which seeds the backstop. The
|
|
344
349
|
* creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
|
|
345
350
|
* preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
|
|
346
351
|
* CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its
|
|
347
352
|
* user to the gate and mints the backstop in the same transaction (064).
|
|
348
353
|
*/
|
|
349
354
|
export async function initializeMarket(c, a) {
|
|
355
|
+
if (a.account.toLowerCase() !== a.key.creator.toLowerCase()) {
|
|
356
|
+
throw new Error(`logswap: the key's creator ${a.key.creator} must be the account that initializes it (${a.account}) — NotCreator`);
|
|
357
|
+
}
|
|
350
358
|
const { request } = await c.public.simulateContract({
|
|
351
|
-
address: c
|
|
352
|
-
abi:
|
|
359
|
+
address: managerC(c),
|
|
360
|
+
abi: managerCAbi,
|
|
353
361
|
functionName: "initialize",
|
|
354
362
|
args: [a.key, a.initialLogPrice],
|
|
355
363
|
account: signerFor(c, a.account),
|
package/dist/positions.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* accounts holding the same class can have different claimable amounts.
|
|
7
7
|
*/
|
|
8
8
|
import type { Address } from "viem";
|
|
9
|
-
import type
|
|
9
|
+
import { type LogswapClient } from "./client.js";
|
|
10
10
|
import { type PoolKey } from "./keys.js";
|
|
11
11
|
/** A class's aggregate state — the whole class, not one holder's slice. */
|
|
12
12
|
export interface PositionClass {
|
package/dist/positions.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* accounts holding the same class can have different claimable amounts.
|
|
7
7
|
*/
|
|
8
8
|
import { encodeAbiParameters, keccak256, parseAbiItem } from "viem";
|
|
9
|
-
import {
|
|
9
|
+
import { lensCAbi, managerCAbi } from "./generated.js";
|
|
10
|
+
import { managerC, lensC } from "./client.js";
|
|
10
11
|
import { MINT_FEE_MAX, poolId } from "./keys.js";
|
|
11
12
|
/** `CPoolState.POSITIONS_SLOT`: the manager's `positions` mapping (`forge inspect CPoolManager storageLayout`). */
|
|
12
13
|
const C_POSITIONS_SLOT = 4n;
|
|
@@ -23,8 +24,8 @@ import { poolHolders } from "./views.js";
|
|
|
23
24
|
export async function getPositionClass(c, id) {
|
|
24
25
|
const slot = keccak256(encodeAbiParameters([{ type: "uint256" }, { type: "uint256" }], [id, C_POSITIONS_SLOT]));
|
|
25
26
|
const w = (await c.public.readContract({
|
|
26
|
-
address: c
|
|
27
|
-
abi:
|
|
27
|
+
address: managerC(c),
|
|
28
|
+
abi: managerCAbi,
|
|
28
29
|
functionName: "extsload",
|
|
29
30
|
args: [slot, 2n],
|
|
30
31
|
}));
|
|
@@ -35,8 +36,8 @@ export async function getPositionClass(c, id) {
|
|
|
35
36
|
/** A holder's share balance in a class. */
|
|
36
37
|
export async function balanceOf(c, owner, id) {
|
|
37
38
|
return c.public.readContract({
|
|
38
|
-
address: c
|
|
39
|
-
abi:
|
|
39
|
+
address: managerC(c),
|
|
40
|
+
abi: managerCAbi,
|
|
40
41
|
functionName: "balanceOf",
|
|
41
42
|
args: [owner, id],
|
|
42
43
|
});
|
|
@@ -49,8 +50,8 @@ export async function balanceOf(c, owner, id) {
|
|
|
49
50
|
*/
|
|
50
51
|
export async function feesOf(c, id, owner) {
|
|
51
52
|
return c.public.readContract({
|
|
52
|
-
address: c
|
|
53
|
-
abi:
|
|
53
|
+
address: lensC(c),
|
|
54
|
+
abi: lensCAbi,
|
|
54
55
|
functionName: "feesOfById",
|
|
55
56
|
args: [id, owner],
|
|
56
57
|
});
|
|
@@ -91,8 +92,8 @@ export async function getHolderPosition(c, key, owner, floor, cap = NO_CAP) {
|
|
|
91
92
|
*/
|
|
92
93
|
export async function describeId(c, id, tickSpacing) {
|
|
93
94
|
const r = (await c.public.readContract({
|
|
94
|
-
address: c
|
|
95
|
-
abi:
|
|
95
|
+
address: lensC(c),
|
|
96
|
+
abi: lensCAbi,
|
|
96
97
|
functionName: "unpack",
|
|
97
98
|
args: [id],
|
|
98
99
|
}));
|
|
@@ -174,8 +175,8 @@ export function mintFee(p, x, rate) {
|
|
|
174
175
|
}
|
|
175
176
|
export async function positionsOf(c, key, owner) {
|
|
176
177
|
const rows = (await c.public.readContract({
|
|
177
|
-
address: c
|
|
178
|
-
abi:
|
|
178
|
+
address: lensC(c),
|
|
179
|
+
abi: lensCAbi,
|
|
179
180
|
functionName: "positionsOf",
|
|
180
181
|
args: [poolId(key), owner],
|
|
181
182
|
}));
|
|
@@ -185,7 +186,7 @@ const ID_REGISTERED = parseAbiItem("event ClassRegistered(uint256 indexed id, by
|
|
|
185
186
|
/** The class ids `owner` holds in `pool`, from the indexer's `pool_holder` view; null when the indexer cannot answer. */
|
|
186
187
|
async function heldIdsFromView(c, indexer, pool, owner) {
|
|
187
188
|
try {
|
|
188
|
-
const rows = await poolHolders(indexer, { condition: { side: "C", poolId: pool.toLowerCase(), holder: owner.toLowerCase(), manager: c.
|
|
189
|
+
const rows = await poolHolders(indexer, { condition: { side: "C", poolId: pool.toLowerCase(), holder: owner.toLowerCase(), manager: managerC(c).toLowerCase() } });
|
|
189
190
|
return rows.filter((r) => r.balance > 0n && !r.isBackstop).map((r) => r.id);
|
|
190
191
|
}
|
|
191
192
|
catch {
|
|
@@ -194,7 +195,7 @@ async function heldIdsFromView(c, indexer, pool, owner) {
|
|
|
194
195
|
}
|
|
195
196
|
/** Every class id ever registered in `pool` (`ClassRegistered`), from the indexer's table or the node. */
|
|
196
197
|
async function registeredIds(c, pool, fromBlock, indexer) {
|
|
197
|
-
const { logs } = await getEventLogs(c, { indexer, address: c
|
|
198
|
+
const { logs } = await getEventLogs(c, { indexer, address: managerC(c), event: ID_REGISTERED, args: { poolId: pool }, fromBlock });
|
|
198
199
|
return logs.map((l) => l.args.id ?? 0n).filter((id) => id !== 0n);
|
|
199
200
|
}
|
|
200
201
|
/**
|
|
@@ -215,8 +216,8 @@ export async function holdingsOf(c, key, owner, fromBlock, opts = {}) {
|
|
|
215
216
|
return [];
|
|
216
217
|
// one lens call: balance, class L, fees, floor and cap for every id the owner holds
|
|
217
218
|
const rows = (await c.public.readContract({
|
|
218
|
-
address: c
|
|
219
|
-
abi:
|
|
219
|
+
address: lensC(c),
|
|
220
|
+
abi: lensCAbi,
|
|
220
221
|
functionName: "heldByIds",
|
|
221
222
|
args: [poolId(key), owner, ids],
|
|
222
223
|
}));
|
|
@@ -226,8 +227,8 @@ export async function holdingsOf(c, key, owner, fromBlock, opts = {}) {
|
|
|
226
227
|
* value = base·p + quote + fees in quote units — L + quote + fees for an uncapped active class. */
|
|
227
228
|
export async function legsOf(c, key, id, holder) {
|
|
228
229
|
const [base, quote, fees, value] = (await c.public.readContract({
|
|
229
|
-
address: c
|
|
230
|
-
abi:
|
|
230
|
+
address: lensC(c),
|
|
231
|
+
abi: lensCAbi,
|
|
231
232
|
functionName: "legsOf",
|
|
232
233
|
args: [poolId(key), id, holder],
|
|
233
234
|
}));
|
package/dist/quote.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* quote.ts — reading a revert-quoter's answer.
|
|
3
|
+
*
|
|
4
|
+
* Both managers' quoters are the router's (`Router.quoteSwap`, F: decision 049, C: decision 092): the real swap runs
|
|
5
|
+
* in the manager's lock and the contract reverts with `QuoteResult(uint256)`. The value is therefore decoded out of the
|
|
6
|
+
* revert, not returned. There is no second pricing path to drift from the first.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* `QuoteResult(uint256)` — selector then one word. viem nests the revert data several layers deep
|
|
10
|
+
* depending on the transport, so walk for it rather than guessing the shape.
|
|
11
|
+
*
|
|
12
|
+
* The selector is DERIVED, not written down. A hardcoded one is wrong silently: the decode simply
|
|
13
|
+
* never matches and every quote rethrows as if the swap had failed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findQuoteResult(err: unknown): bigint | null;
|
package/dist/quote.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* quote.ts — reading a revert-quoter's answer.
|
|
3
|
+
*
|
|
4
|
+
* Both managers' quoters are the router's (`Router.quoteSwap`, F: decision 049, C: decision 092): the real swap runs
|
|
5
|
+
* in the manager's lock and the contract reverts with `QuoteResult(uint256)`. The value is therefore decoded out of the
|
|
6
|
+
* revert, not returned. There is no second pricing path to drift from the first.
|
|
7
|
+
*/
|
|
8
|
+
import { toFunctionSelector } from "viem";
|
|
9
|
+
/**
|
|
10
|
+
* `QuoteResult(uint256)` — selector then one word. viem nests the revert data several layers deep
|
|
11
|
+
* depending on the transport, so walk for it rather than guessing the shape.
|
|
12
|
+
*
|
|
13
|
+
* The selector is DERIVED, not written down. A hardcoded one is wrong silently: the decode simply
|
|
14
|
+
* never matches and every quote rethrows as if the swap had failed.
|
|
15
|
+
*/
|
|
16
|
+
export function findQuoteResult(err) {
|
|
17
|
+
const SELECTOR = toFunctionSelector("QuoteResult(uint256)");
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
const walk = (e) => {
|
|
20
|
+
if (!e || typeof e !== "object" || seen.has(e))
|
|
21
|
+
return null;
|
|
22
|
+
seen.add(e);
|
|
23
|
+
const anyE = e;
|
|
24
|
+
const data = anyE.data;
|
|
25
|
+
if (typeof data === "string" && data.startsWith(SELECTOR) && data.length >= 10 + 64) {
|
|
26
|
+
return BigInt("0x" + data.slice(10, 10 + 64));
|
|
27
|
+
}
|
|
28
|
+
for (const k of ["cause", "walk", "error", "details"]) {
|
|
29
|
+
const found = walk(anyE[k]);
|
|
30
|
+
if (found !== null)
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
return walk(err);
|
|
36
|
+
}
|
package/dist/swap.d.ts
CHANGED
|
@@ -5,20 +5,18 @@
|
|
|
5
5
|
* merged `swap(key, baseSide, amount, limit)` uses a NEGATIVE amount for exact-out; that convention
|
|
6
6
|
* is deliberately not exposed here — callers say `swapExactOut`.
|
|
7
7
|
*/
|
|
8
|
-
import type
|
|
9
|
-
import type
|
|
8
|
+
import { type Address, type Hash } from "viem";
|
|
9
|
+
import { type LogswapClient } from "./client.js";
|
|
10
10
|
import { type PoolKey } from "./keys.js";
|
|
11
11
|
import { type WriteOptions } from "./write.js";
|
|
12
12
|
/**
|
|
13
|
-
* Quote an exact-in swap. Exact, not approximate — the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `simulate`, not a plain read: the function is non-view by construction.
|
|
13
|
+
* Quote an exact-in swap. Exact, not approximate — the router runs the real swap and reverts with the result, so
|
|
14
|
+
* what it returns is what execution returns, bit for bit (including the dynamic fee, even across a block boundary
|
|
15
|
+
* with the variance fold pending).
|
|
18
16
|
*/
|
|
19
|
-
export declare function quoteExactIn(c: LogswapClient, key: PoolKey, baseIn: boolean, amountIn: bigint): Promise<bigint>;
|
|
17
|
+
export declare function quoteExactIn(c: LogswapClient, key: PoolKey, baseIn: boolean, amountIn: bigint, taker?: Address): Promise<bigint>;
|
|
20
18
|
/** Quote an exact-out swap: how much input it will cost. Exact, same mechanism as above. */
|
|
21
|
-
export declare function quoteExactOut(c: LogswapClient, key: PoolKey, baseOut: boolean, amountOut: bigint): Promise<bigint>;
|
|
19
|
+
export declare function quoteExactOut(c: LogswapClient, key: PoolKey, baseOut: boolean, amountOut: bigint, taker?: Address): Promise<bigint>;
|
|
22
20
|
export interface SwapExactInArgs extends WriteOptions {
|
|
23
21
|
key: PoolKey;
|
|
24
22
|
/** true = base in, quote out (price falls). false = quote in, base out (price rises). */
|
package/dist/swap.js
CHANGED
|
@@ -5,38 +5,51 @@
|
|
|
5
5
|
* merged `swap(key, baseSide, amount, limit)` uses a NEGATIVE amount for exact-out; that convention
|
|
6
6
|
* is deliberately not exposed here — callers say `swapExactOut`.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { zeroAddress } from "viem";
|
|
9
|
+
import { routerCAbi } from "./generated.js";
|
|
10
|
+
import { routerC } from "./client.js";
|
|
9
11
|
import { poolId as keyId } from "./keys.js";
|
|
12
|
+
import { findQuoteResult } from "./quote.js";
|
|
10
13
|
import { resolveDeadline, resolveRecipient, sendRouterWrite, sendRouterWriteWithPermits } from "./write.js";
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `simulate`, not a plain read: the function is non-view by construction.
|
|
15
|
+
* The C quoter (C 14, decision 092): `Router.quoteSwap` runs the real swap in the manager's lock for `taker` and reverts
|
|
16
|
+
* with `QuoteResult`, so the answer is decoded out of the revert. `baseSide` says whether the SPECIFIED token is the base.
|
|
17
|
+
* The taker matters only on a gated market (the router must then be the taker's ERC-6909 operator, as for the swap):
|
|
18
|
+
* the connected account, or the zero address.
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
async function quoteSwapC(c, key, exactIn, baseSide, amount, taker) {
|
|
21
|
+
try {
|
|
22
|
+
await c.public.simulateContract({
|
|
23
|
+
address: routerC(c),
|
|
24
|
+
abi: routerCAbi,
|
|
25
|
+
functionName: "quoteSwap",
|
|
26
|
+
args: [keyId(key), exactIn, baseSide, amount, taker ?? c.wallet?.account?.address ?? zeroAddress],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
const hit = findQuoteResult(err);
|
|
31
|
+
if (hit !== null)
|
|
32
|
+
return hit;
|
|
33
|
+
throw err; // a real revert — no liquidity, a gate, a bad amount — belongs to the caller
|
|
34
|
+
}
|
|
35
|
+
throw new Error("logswap: quoteSwap returned without reverting, which it must never do");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Quote an exact-in swap. Exact, not approximate — the router runs the real swap and reverts with the result, so
|
|
39
|
+
* what it returns is what execution returns, bit for bit (including the dynamic fee, even across a block boundary
|
|
40
|
+
* with the variance fold pending).
|
|
41
|
+
*/
|
|
42
|
+
export async function quoteExactIn(c, key, baseIn, amountIn, taker) {
|
|
43
|
+
return quoteSwapC(c, key, true, baseIn, amountIn, taker);
|
|
26
44
|
}
|
|
27
45
|
/** Quote an exact-out swap: how much input it will cost. Exact, same mechanism as above. */
|
|
28
|
-
export async function quoteExactOut(c, key, baseOut, amountOut) {
|
|
29
|
-
|
|
30
|
-
address: c.addresses.lens,
|
|
31
|
-
abi: lensAbi,
|
|
32
|
-
functionName: "previewSwapExactOut",
|
|
33
|
-
args: [keyId(key), baseOut, amountOut],
|
|
34
|
-
});
|
|
35
|
-
return result;
|
|
46
|
+
export async function quoteExactOut(c, key, baseOut, amountOut, taker) {
|
|
47
|
+
return quoteSwapC(c, key, false, baseOut, amountOut, taker);
|
|
36
48
|
}
|
|
37
49
|
export async function swapExactIn(c, a) {
|
|
38
50
|
return sendRouterWriteWithPermits(c, {
|
|
39
|
-
|
|
51
|
+
side: "C",
|
|
52
|
+
abi: routerCAbi,
|
|
40
53
|
functionName: "swapExactIn",
|
|
41
54
|
args: [
|
|
42
55
|
keyId(a.key),
|
|
@@ -52,7 +65,8 @@ export async function swapExactIn(c, a) {
|
|
|
52
65
|
}
|
|
53
66
|
export async function swapExactOut(c, a) {
|
|
54
67
|
return sendRouterWriteWithPermits(c, {
|
|
55
|
-
|
|
68
|
+
side: "C",
|
|
69
|
+
abi: routerCAbi,
|
|
56
70
|
functionName: "swapExactOut",
|
|
57
71
|
args: [
|
|
58
72
|
keyId(a.key),
|
|
@@ -78,7 +92,8 @@ export async function swapExactInPath(c, a) {
|
|
|
78
92
|
if (a.hops.length === 0)
|
|
79
93
|
throw new Error("logswap: empty path");
|
|
80
94
|
return sendRouterWrite(c, {
|
|
81
|
-
|
|
95
|
+
side: "C",
|
|
96
|
+
abi: routerCAbi,
|
|
82
97
|
functionName: "swapExactInPath",
|
|
83
98
|
args: [
|
|
84
99
|
a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })),
|
package/dist/views.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* keep their node path as the fallback.
|
|
18
18
|
*/
|
|
19
19
|
import { type Address, type Hex } from "viem";
|
|
20
|
+
import type { Side } from "./client.js";
|
|
20
21
|
/** What a view query takes: postgraphile's `condition` (equality), `filter` (the connection-filter plugin's operators), an `orderBy` of the view's enum names, a row cap. */
|
|
21
22
|
export interface ViewQuery {
|
|
22
23
|
condition?: Record<string, unknown>;
|
|
@@ -27,7 +28,6 @@ export interface ViewQuery {
|
|
|
27
28
|
first?: number;
|
|
28
29
|
signal?: AbortSignal;
|
|
29
30
|
}
|
|
30
|
-
export type Side = "C" | "F";
|
|
31
31
|
/** A pool of either manager: C markets are kind `market`; F pools carry their policy's registry name (`public`, `private`, `pol`, `pad`). */
|
|
32
32
|
export interface PoolDirectoryRow {
|
|
33
33
|
side: Side;
|
package/dist/write.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* what you have — but the bound is what ships.
|
|
14
14
|
*/
|
|
15
15
|
import type { Address, Hash, Hex } from "viem";
|
|
16
|
-
import type
|
|
16
|
+
import { type LogswapClient, type Side } from "./client.js";
|
|
17
17
|
/** Disables the deadline check. Deliberate opt-out, never a default. */
|
|
18
18
|
export declare const NEVER: bigint;
|
|
19
19
|
/** Default deadline window: 20 minutes, the same order as every major DEX front end. */
|
|
@@ -91,7 +91,10 @@ export declare function revertName(e: unknown): string | undefined;
|
|
|
91
91
|
* since the last touch. An exact `eth_estimateGas` can therefore OutOfGas one block later. Every
|
|
92
92
|
* write goes through here.
|
|
93
93
|
*/
|
|
94
|
-
export declare function sendRouterWrite(c: LogswapClient,
|
|
94
|
+
export declare function sendRouterWrite(c: LogswapClient,
|
|
95
|
+
/** `side` picks the router (decision 096: one per manager, each its own Permit2 spender). */
|
|
96
|
+
args: {
|
|
97
|
+
side: Side;
|
|
95
98
|
abi: readonly unknown[];
|
|
96
99
|
functionName: string;
|
|
97
100
|
args: readonly unknown[];
|
|
@@ -111,6 +114,7 @@ export declare function isUserRejection(e: unknown): boolean;
|
|
|
111
114
|
export declare function fallBackUnlessRejected(e: unknown): Hex[];
|
|
112
115
|
/** Simulate a router write and return its decoded result, without sending. */
|
|
113
116
|
export declare function simulateRouterWrite<T>(c: LogswapClient, args: {
|
|
117
|
+
side: Side;
|
|
114
118
|
abi: readonly unknown[];
|
|
115
119
|
functionName: string;
|
|
116
120
|
args: readonly unknown[];
|
|
@@ -123,6 +127,7 @@ export declare function simulateRouterWrite<T>(c: LogswapClient, args: {
|
|
|
123
127
|
* when nothing is missing or Permit2 is not wired.
|
|
124
128
|
*/
|
|
125
129
|
export declare function sendRouterWriteWithPermits(c: LogswapClient, args: {
|
|
130
|
+
side: Side;
|
|
126
131
|
abi: readonly unknown[];
|
|
127
132
|
functionName: string;
|
|
128
133
|
args: readonly unknown[];
|
package/dist/write.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* raw `minOut`/`maxIn` the contract wants. `withSlippage()` derives one from a quote when that is
|
|
13
13
|
* what you have — but the bound is what ships.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import { routerOf } from "./client.js";
|
|
16
|
+
import { managerCAbi, managerFAbi, policyFAbi } from "./generated.js";
|
|
16
17
|
/** Disables the deadline check. Deliberate opt-out, never a default. */
|
|
17
18
|
export const NEVER = (1n << 256n) - 1n;
|
|
18
19
|
/** Default deadline window: 20 minutes, the same order as every major DEX front end. */
|
|
@@ -89,7 +90,7 @@ const errorKey = (e) => `${e.name}(${e.inputs.map((i) => i.type).join(",")})`;
|
|
|
89
90
|
export const routerRevertErrors = (() => {
|
|
90
91
|
const seen = new Set();
|
|
91
92
|
const out = [];
|
|
92
|
-
for (const x of [...
|
|
93
|
+
for (const x of [...managerCAbi, ...managerFAbi, ...policyFAbi, ...permit2Errors]) {
|
|
93
94
|
if (x.type !== "error")
|
|
94
95
|
continue;
|
|
95
96
|
const e = x;
|
|
@@ -133,10 +134,12 @@ export function revertName(e) {
|
|
|
133
134
|
* since the last touch. An exact `eth_estimateGas` can therefore OutOfGas one block later. Every
|
|
134
135
|
* write goes through here.
|
|
135
136
|
*/
|
|
136
|
-
export async function sendRouterWrite(c,
|
|
137
|
+
export async function sendRouterWrite(c,
|
|
138
|
+
/** `side` picks the router (decision 096: one per manager, each its own Permit2 spender). */
|
|
139
|
+
args) {
|
|
137
140
|
const { account } = requireWallet(c);
|
|
138
141
|
const params = {
|
|
139
|
-
address: c.
|
|
142
|
+
address: routerOf(c, args.side),
|
|
140
143
|
abi: withRevertErrors(args.abi),
|
|
141
144
|
functionName: args.functionName,
|
|
142
145
|
args: args.args,
|
|
@@ -176,7 +179,7 @@ export function fallBackUnlessRejected(e) {
|
|
|
176
179
|
export async function simulateRouterWrite(c, args) {
|
|
177
180
|
const account = args.account ?? c.wallet?.account?.address;
|
|
178
181
|
const { result } = await c.public.simulateContract({
|
|
179
|
-
address: c.
|
|
182
|
+
address: routerOf(c, args.side),
|
|
180
183
|
abi: withRevertErrors(args.abi),
|
|
181
184
|
functionName: args.functionName,
|
|
182
185
|
args: args.args,
|
|
@@ -192,10 +195,10 @@ export async function simulateRouterWrite(c, args) {
|
|
|
192
195
|
*/
|
|
193
196
|
export async function sendRouterWriteWithPermits(c, args, pullTokens) {
|
|
194
197
|
const { permit2SigCalls } = await import("./onboard.js");
|
|
195
|
-
const sigCalls = await permit2SigCalls(c, pullTokens).catch(fallBackUnlessRejected);
|
|
198
|
+
const sigCalls = await permit2SigCalls(c, args.side, pullTokens).catch(fallBackUnlessRejected);
|
|
196
199
|
if (sigCalls.length === 0)
|
|
197
200
|
return sendRouterWrite(c, args);
|
|
198
201
|
const { encodeFunctionData } = await import("viem");
|
|
199
202
|
const inner = encodeFunctionData({ abi: args.abi, functionName: args.functionName, args: args.args });
|
|
200
|
-
return sendRouterWrite(c, { abi: args.abi, functionName: "multicall", args: [[...sigCalls, inner]], bufferPct: args.bufferPct });
|
|
203
|
+
return sendRouterWrite(c, { side: args.side, abi: args.abi, functionName: "multicall", args: [[...sigCalls, inner]], bufferPct: args.bufferPct });
|
|
201
204
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logswap/sdk",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the
|
|
3
|
+
"version": "0.5.92",
|
|
4
|
+
"description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the ManagerF / ManagerC, RouterF / RouterC and LensF / LensC surface.",
|
|
5
5
|
"license": "GPL-2.0-or-later",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"contracts:sync": "bash scripts/sync-contracts.sh",
|
|
22
|
-
"codegen": "npm run contracts:sync &&
|
|
22
|
+
"codegen": "npm run contracts:sync && wagmi generate",
|
|
23
23
|
"vectors": "bash scripts/gen-vectors.sh",
|
|
24
24
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
25
25
|
"typecheck": "tsc --noEmit",
|
package/src/actions.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import { encodeAbiParameters, type Address, type Hash, type Hex } from "viem";
|
|
22
|
-
import {
|
|
22
|
+
import { routerCAbi, routerActionsAbi } from "./generated.js";
|
|
23
23
|
import type { LogswapClient } from "./client.js";
|
|
24
24
|
import { poolId as keyId, type PoolKey } from "./keys.js";
|
|
25
25
|
import { NO_CAP } from "./ids.js";
|
|
@@ -186,7 +186,7 @@ export async function execute(c: LogswapClient, a: ExecuteArgs): Promise<Hash> {
|
|
|
186
186
|
const pull = a.pullTokens ?? settle.tokens.filter((_, i) => settle.maxIn[i]! > 0n);
|
|
187
187
|
return sendRouterWriteWithPermits(
|
|
188
188
|
c,
|
|
189
|
-
{ abi:
|
|
189
|
+
{ side: "C", abi: routerCAbi, functionName: "execute", args: [a.actions, settle, resolveDeadline(a)] },
|
|
190
190
|
[...pull],
|
|
191
191
|
);
|
|
192
192
|
}
|
|
@@ -198,7 +198,8 @@ export async function simulateExecute(
|
|
|
198
198
|
): Promise<{ results: readonly Hex[]; flows: readonly bigint[] }> {
|
|
199
199
|
const settle: Settle = { ...a.settle, recipient: a.settle.recipient ?? a.account ?? resolveRecipient(c, a) };
|
|
200
200
|
const [results, flows] = await simulateRouterWrite<readonly [readonly Hex[], readonly bigint[]]>(c, {
|
|
201
|
-
|
|
201
|
+
side: "C",
|
|
202
|
+
abi: routerCAbi,
|
|
202
203
|
functionName: "execute",
|
|
203
204
|
args: [a.actions, settle, resolveDeadline(a)],
|
|
204
205
|
account: a.account,
|