@logswap/sdk 0.5.90 → 0.5.91

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.
Files changed (59) hide show
  1. package/README.md +74 -12
  2. package/dist/actions.js +4 -3
  3. package/dist/admin.d.ts +213 -219
  4. package/dist/admin.js +118 -144
  5. package/dist/chains.d.ts +13 -4
  6. package/dist/chains.js +23 -9
  7. package/dist/claims.d.ts +1 -1
  8. package/dist/claims.js +11 -9
  9. package/dist/client.d.ts +43 -20
  10. package/dist/client.js +75 -26
  11. package/dist/fees.d.ts +1 -1
  12. package/dist/fees.js +5 -4
  13. package/dist/fpool.d.ts +170 -460
  14. package/dist/fpool.js +175 -218
  15. package/dist/generated.d.ts +5549 -6027
  16. package/dist/generated.js +2580 -3153
  17. package/dist/history.js +13 -11
  18. package/dist/index.d.ts +5 -7
  19. package/dist/index.js +5 -7
  20. package/dist/indexer.d.ts +2 -2
  21. package/dist/indexer.js +12 -9
  22. package/dist/keys.d.ts +15 -3
  23. package/dist/keys.js +5 -1
  24. package/dist/liquidity.d.ts +1 -1
  25. package/dist/liquidity.js +16 -9
  26. package/dist/onboard.d.ts +16 -11
  27. package/dist/onboard.js +27 -21
  28. package/dist/pools.d.ts +2 -0
  29. package/dist/pools.js +21 -13
  30. package/dist/positions.d.ts +1 -1
  31. package/dist/positions.js +18 -17
  32. package/dist/quote.d.ts +15 -0
  33. package/dist/quote.js +36 -0
  34. package/dist/swap.d.ts +7 -9
  35. package/dist/swap.js +40 -25
  36. package/dist/views.d.ts +1 -1
  37. package/dist/write.d.ts +7 -2
  38. package/dist/write.js +10 -7
  39. package/package.json +3 -3
  40. package/src/actions.ts +4 -3
  41. package/src/admin.ts +168 -171
  42. package/src/chains.ts +33 -13
  43. package/src/claims.ts +11 -10
  44. package/src/client.ts +101 -39
  45. package/src/fees.ts +6 -6
  46. package/src/fpool.ts +240 -272
  47. package/src/generated.ts +2525 -3094
  48. package/src/history.ts +11 -9
  49. package/src/index.ts +5 -7
  50. package/src/indexer.ts +13 -11
  51. package/src/keys.ts +19 -3
  52. package/src/liquidity.ts +16 -10
  53. package/src/onboard.ts +29 -21
  54. package/src/pools.ts +23 -15
  55. package/src/positions.ts +18 -18
  56. package/src/quote.ts +36 -0
  57. package/src/swap.ts +46 -25
  58. package/src/views.ts +1 -2
  59. package/src/write.ts +11 -10
package/dist/history.js CHANGED
@@ -36,43 +36,45 @@ export async function getEventLogs(c, q) {
36
36
  // ─── the indexer path ────────────────────────────────────────────────────────
37
37
  /**
38
38
  * What the rindexer deployment calls each contract — the prefix of a table two contracts share
39
- * (logswap-be `devnet/indexer/rindexer.yaml`). The four policies are one factory-tracked contract,
40
- * `Policy`, except `Listed`, whose two signatures are two contracts (`PublicPolicy`, `PrivatePolicy`).
39
+ * (logswap-be `devnet/indexer/rindexer.yaml`). Every policy is one factory-tracked contract, `Policy`: since decision
40
+ * 098 `Listed` has one signature (the sponsored policies', F and C), so no policy event needs a prefix.
41
41
  */
42
42
  function contractName(c, address, event) {
43
43
  const a = address.toLowerCase();
44
44
  const is = (x) => x !== undefined && a === x.toLowerCase();
45
45
  const { addresses: d } = c;
46
- if (is(d.cPoolManager))
46
+ // the indexer's own labels for the contracts (its `rindexer.yaml`), not the contracts' names (decision 096): ManagerC / ManagerF / RouterC / RouterF
47
+ if (is(d.managerC))
47
48
  return "CPoolManager";
48
- if (is(d.fPoolManager))
49
+ if (is(d.managerF))
49
50
  return "FPoolManager";
50
- if (is(d.router))
51
+ if (is(d.routerF) || is(d.routerC))
51
52
  return "LogswapRouter";
52
53
  if (is(d.policyRegistry))
53
54
  return "PolicyRegistry";
54
55
  if (is(d.tokenFactory))
55
56
  return "TokenFactory";
56
- if (is(d.publicPolicy))
57
- return indexedContractOf("public", event);
58
- if (is(d.privatePolicy))
59
- return indexedContractOf("private", event);
57
+ if (is(d.publicPolicy) || is(d.privatePolicy) || is(d.publicPolicyC))
58
+ return indexedContractOf("sponsor", event);
60
59
  if (is(d.polPolicy))
61
60
  return indexedContractOf("pol", event);
62
61
  if (is(d.padPolicy))
63
62
  return indexedContractOf("pad", event);
63
+ if (is(d.orphanPolicy))
64
+ return indexedContractOf("orphan", event);
64
65
  return null;
65
66
  }
66
67
  /**
67
68
  * A policy's name in the indexer for one of its events: `Policy`. Pass it as {@link EventLogsQuery.contract} for a policy outside the artifact.
68
69
  */
69
70
  export function indexedContractOf(kind, event) {
70
- void kind; // `Listed` was the public and the private policy's since 064; the public policy dropped its asset list in F 33 (073), so it is unshared
71
+ void kind; // `Listed` was two contracts' (the public and the private policy) until decision 098; now every policy event is unshared
71
72
  return "Policy";
72
73
  }
73
74
  /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
74
75
  // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
75
- const SHARED = new Set(["PoolCreated", "Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
76
+ // `SwapState` (was `CSwapState` / `FSwapState`) and `GatesSet` (`PermissionsSet` before decision 098) are `ManagerBase`'s: declared once, emitted by both managers (decisions 096, #112).
77
+ const SHARED = new Set(["PoolCreated", "Swap", "SwapState", "GatesSet", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
76
78
  const plural = (n) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
77
79
  /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
78
80
  const column = (name) => name[0].toLowerCase() + name.slice(1);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Logswap SDK — typed, offline-first helpers over the CPoolManager / Router / Lens surface.
2
+ * log(swap) SDK — typed, offline-first helpers over the ManagerF / ManagerC, RouterF / RouterC and LensF / LensC surface.
3
3
  *
4
- * The manager/router/lens split is an EIP-170 artifact, not a design boundary, so it is hidden
5
- * here: callers address markets by `PoolKey` and never choose a contract. A future re-homing of
6
- * a function is then an SDK patch rather than a breaking change (docs/app.md, tier 2).
4
+ * The manager/router/lens split is hidden here: callers address markets by `PoolKey` (C) and pool id (F) and
5
+ * never choose a contract. What a caller does choose is the SIDE (`"F"` or `"C"`) where a router is the
6
+ * spender (decision 096: one router per manager, each its own Permit2 spender) — see `onboard.ts`.
7
7
  */
8
8
  export * from "./keys.js";
9
9
  export * from "./ids.js";
@@ -23,7 +23,5 @@ export * from "./fpool.js";
23
23
  export * from "./fees.js";
24
24
  export * from "./history.js";
25
25
  export * from "./views.js";
26
- export { cPoolManagerAbi, fPoolManagerAbi, lensAbi, routerAbi, routerActionsAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, privatePolicyAbi, publicPolicyAbi } from "./generated.js";
27
- /** @deprecated the `Logswap` prefix is gone (decision 091): use `routerAbi` / `lensAbi`. Removed in the next minor. */
28
- export { routerAbi as logswapRouterAbi, lensAbi as logswapLensAbi } from "./generated.js";
26
+ export { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi, orphanPolicyFAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, sponsorPolicyCAbi, sponsorPolicyFAbi } from "./generated.js";
29
27
  export * from "./admin.js";
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Logswap SDK — typed, offline-first helpers over the CPoolManager / Router / Lens surface.
2
+ * log(swap) SDK — typed, offline-first helpers over the ManagerF / ManagerC, RouterF / RouterC and LensF / LensC surface.
3
3
  *
4
- * The manager/router/lens split is an EIP-170 artifact, not a design boundary, so it is hidden
5
- * here: callers address markets by `PoolKey` and never choose a contract. A future re-homing of
6
- * a function is then an SDK patch rather than a breaking change (docs/app.md, tier 2).
4
+ * The manager/router/lens split is hidden here: callers address markets by `PoolKey` (C) and pool id (F) and
5
+ * never choose a contract. What a caller does choose is the SIDE (`"F"` or `"C"`) where a router is the
6
+ * spender (decision 096: one router per manager, each its own Permit2 spender) — see `onboard.ts`.
7
7
  */
8
8
  export * from "./keys.js";
9
9
  export * from "./ids.js";
@@ -23,7 +23,5 @@ export * from "./fpool.js";
23
23
  export * from "./fees.js";
24
24
  export * from "./history.js";
25
25
  export * from "./views.js";
26
- export { cPoolManagerAbi, fPoolManagerAbi, lensAbi, routerAbi, routerActionsAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, privatePolicyAbi, publicPolicyAbi } from "./generated.js";
27
- /** @deprecated the `Logswap` prefix is gone (decision 091): use `routerAbi` / `lensAbi`. Removed in the next minor. */
28
- export { routerAbi as logswapRouterAbi, lensAbi as logswapLensAbi } from "./generated.js";
26
+ export { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi, orphanPolicyFAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, sponsorPolicyCAbi, sponsorPolicyFAbi } from "./generated.js";
29
27
  export * from "./admin.js";
package/dist/indexer.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * is read on-chain, rather than trusting a number that was true at index time.
9
9
  */
10
10
  import type { Hex } from "viem";
11
- import type { LogswapClient } from "./client.js";
11
+ import { type LogswapClient } from "./client.js";
12
12
  import { type DiscoveredMarket } from "./pools.js";
13
13
  import { type PoolKey } from "./keys.js";
14
14
  export interface IndexerError {
@@ -82,7 +82,7 @@ export declare function indexerHealthy(url: string, signal?: AbortSignal): Promi
82
82
  * the more durable path and should be preferred wherever an indexer is configured, with the log
83
83
  * scan as the fallback for when it is not.
84
84
  *
85
- * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
85
+ * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` since C 12, `creator` and `salt` since C 15), so the key is rebuilt exactly and `poolId` is
86
86
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
87
87
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
88
88
  */
package/dist/indexer.js CHANGED
@@ -7,7 +7,8 @@
7
7
  * changes with every mint, burn and harvest afterwards. So ids come from here and the current `L`
8
8
  * is read on-chain, rather than trusting a number that was true at index time.
9
9
  */
10
- import { cPoolManagerAbi } from "./generated.js";
10
+ import { managerC, lensC } from "./client.js";
11
+ import { managerCAbi } from "./generated.js";
11
12
  import { getPositionClass } from "./positions.js";
12
13
  import { discoverMarkets } from "./pools.js";
13
14
  import { poolId } from "./keys.js";
@@ -133,18 +134,20 @@ export async function indexerHealthy(url, signal) {
133
134
  * the more durable path and should be preferred wherever an indexer is configured, with the log
134
135
  * scan as the fallback for when it is not.
135
136
  *
136
- * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
137
+ * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` since C 12, `creator` and `salt` since C 15), so the key is rebuilt exactly and `poolId` is
137
138
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
138
139
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
139
140
  */
140
141
  export async function discoverMarketsIndexed(url, signal) {
141
- const nodes = await gqlAll(url, "allCPoolManagerPoolCreateds", "poolId base quote tickSpacing swapFee mintFee policy initialLogPrice blockNumber txHash contractAddress", { signal });
142
+ const nodes = await gqlAll(url, "allCPoolManagerPoolCreateds", "poolId base quote creator salt tickSpacing swapFee mintFee policy initialLogPrice blockNumber txHash contractAddress", { signal });
142
143
  return nodes.map((n) => {
143
144
  const key = {
144
145
  base: n.base,
145
146
  quote: n.quote,
146
147
  tickSpacing: BigInt(n.tickSpacing),
147
148
  policy: n.policy,
149
+ creator: n.creator, // a key field since C 15 (097): the event carries it, and the salt
150
+ salt: n.salt,
148
151
  swapFee: BigInt(n.swapFee), // rindexer names the column after the event's field: `swapFee` since C version 6 (logswap-be #40)
149
152
  mintFee: BigInt(n.mintFee), // a key field since C 12 (078): the event carries it
150
153
  };
@@ -173,7 +176,7 @@ export async function discoverMarketsBest(c, url = c.indexerUrl, signal) {
173
176
  // read revert, refresh-proof. Each row names the manager that emitted it, so keep only the
174
177
  // rows of the manager this client is pointed at — no read per row. None left means the
175
178
  // indexer has not seen this deployment: the chain scan is the answer.
176
- const mine = c.addresses.cPoolManager.toLowerCase();
179
+ const mine = managerC(c).toLowerCase();
177
180
  const alive = markets.filter((m) => m.manager?.toLowerCase() === mine);
178
181
  if (alive.length)
179
182
  return { markets: alive, source: "indexer" };
@@ -191,18 +194,18 @@ export async function discoverMarketsBest(c, url = c.indexerUrl, signal) {
191
194
  * use the indexed `poolPositions` and fall back to this when the indexer is missing or stale.
192
195
  */
193
196
  export async function poolPositionsFromChain(c, key, x) {
194
- const { lensAbi } = await import("./generated.js");
197
+ const { lensCAbi } = await import("./generated.js");
195
198
  const floors = (await c.public.readContract({
196
- address: c.addresses.lens,
197
- abi: lensAbi,
199
+ address: lensC(c),
200
+ abi: lensCAbi,
198
201
  functionName: "liveTicks",
199
202
  args: [poolId(key)],
200
203
  }));
201
204
  const pool = poolId(key);
202
205
  const rows = await Promise.all([...floors].map(async (floor) => {
203
206
  const id = (await c.public.readContract({
204
- address: c.addresses.cPoolManager,
205
- abi: cPoolManagerAbi,
207
+ address: managerC(c),
208
+ abi: managerCAbi,
206
209
  functionName: "idOf",
207
210
  args: [pool, floor],
208
211
  }));
package/dist/keys.d.ts CHANGED
@@ -18,7 +18,7 @@ import { type Address, type Hex } from "viem";
18
18
  * The mint fee lives in the same domain. The F manager no longer answers
19
19
  * `FEE_MIN()` / `FEE_MAX()` (F version 21 cut the getters for bytecode); every F policy still
20
20
  * checks φ against these at `onInitialize`, and the C side re-exposes them through the lens's
21
- * `cParams()`. Constants here, so a create form bounds φ with no read.
21
+ * `params()` (`LensC`, decision 096). Constants here, so a create form bounds φ with no read.
22
22
  */
23
23
  export declare const FEE_MIN: bigint;
24
24
  export declare const FEE_MAX: bigint;
@@ -33,8 +33,8 @@ export declare function minMintFee(swapFee: bigint): bigint;
33
33
  /** Is `mintFee` inside the domain for this `swapFee`? Pure; the managers enforce the same bound. */
34
34
  export declare function isValidMintFee(swapFee: bigint, mintFee: bigint): boolean;
35
35
  /**
36
- * The economic tuple that IS the market. Field order is load-bearing: it is the ABI encoding order,
37
- * so it must match `src/types/CPoolKey.sol` exactly.
36
+ * The tuple that IS the market (`PoolKeyC`: base, quote, tickSpacing, policy, creator, salt, swapFee, mintFee). Field order is load-bearing: it is the ABI encoding order,
37
+ * so it must match `src/types/PoolKeyC.sol` exactly.
38
38
  */
39
39
  export interface PoolKey {
40
40
  base: Address;
@@ -47,6 +47,18 @@ export interface PoolKey {
47
47
  * `address(0)` is a bare deployment with no registry.
48
48
  */
49
49
  policy: Address;
50
+ /**
51
+ * Who started the market (C 15, decision 097): the caller of `initialize`, checked by the manager and the registry
52
+ * (`NotCreator`). It prices the market at birth and is the only account that may make the FIRST mint, which seeds
53
+ * the backstop; after that, minting is open. Part of the id: two creators' markets of one shape are two markets.
54
+ * On a router-routed call the creator is the trusted forwarder's user (the connected account), not the router.
55
+ */
56
+ creator: Address;
57
+ /**
58
+ * A creator's way to open a second market of the same shape (C 15, decision 097). Part of the id. Zero on the
59
+ * public policy, which refuses any other value (`NotCanonical`): a public market is canonical per exact key.
60
+ */
61
+ salt: Hex;
50
62
  /**
51
63
  * The swap fee, WAD, fixed for the life of the market: {@link FEE_MIN} (1 bp) ≤ φ ≤ {@link FEE_MAX} (1%),
52
64
  * or `0n`, which since C version 7 is NO fee (decisions 065; `DEFAULT_FEE` is gone). The gate
package/dist/keys.js CHANGED
@@ -18,7 +18,7 @@ import { encodeAbiParameters, keccak256 } from "viem";
18
18
  * The mint fee lives in the same domain. The F manager no longer answers
19
19
  * `FEE_MIN()` / `FEE_MAX()` (F version 21 cut the getters for bytecode); every F policy still
20
20
  * checks φ against these at `onInitialize`, and the C side re-exposes them through the lens's
21
- * `cParams()`. Constants here, so a create form bounds φ with no read.
21
+ * `params()` (`LensC`, decision 096). Constants here, so a create form bounds φ with no read.
22
22
  */
23
23
  export const FEE_MIN = 10n ** 14n;
24
24
  export const FEE_MAX = 10n ** 16n;
@@ -44,6 +44,8 @@ const POOL_KEY_ABI = [
44
44
  { name: "quote", type: "address" },
45
45
  { name: "tickSpacing", type: "int256" },
46
46
  { name: "policy", type: "address" },
47
+ { name: "creator", type: "address" },
48
+ { name: "salt", type: "bytes32" },
47
49
  { name: "swapFee", type: "uint256" },
48
50
  { name: "mintFee", type: "uint256" },
49
51
  ],
@@ -63,6 +65,8 @@ export function poolId(key) {
63
65
  quote: key.quote,
64
66
  tickSpacing: key.tickSpacing,
65
67
  policy: key.policy,
68
+ creator: key.creator,
69
+ salt: key.salt,
66
70
  swapFee: key.swapFee,
67
71
  mintFee: key.mintFee,
68
72
  },
@@ -22,7 +22,7 @@
22
22
  * apply.
23
23
  */
24
24
  import type { Address, Hash } from "viem";
25
- import type { LogswapClient } from "./client.js";
25
+ import { type LogswapClient } from "./client.js";
26
26
  import { type PoolKey } from "./keys.js";
27
27
  import { type PairBounds } from "./actions.js";
28
28
  import { type WriteOptions } from "./write.js";
package/dist/liquidity.js CHANGED
@@ -21,7 +21,8 @@
21
21
  * the exact flows, mint fee and swept fees included — and is what an editor shows before its one
22
22
  * apply.
23
23
  */
24
- import { lensAbi, routerAbi } from "./generated.js";
24
+ import { lensCAbi, routerCAbi } from "./generated.js";
25
+ import { lensC } from "./client.js";
25
26
  import { poolId as keyId } from "./keys.js";
26
27
  import { NO_CAP } from "./ids.js";
27
28
  import { describeId, getPositionClass } from "./positions.js";
@@ -40,7 +41,8 @@ import { quoteExactIn, quoteExactOut } from "./swap.js";
40
41
  */
41
42
  export async function mint(c, a) {
42
43
  return sendRouterWriteWithPermits(c, {
43
- abi: routerAbi,
44
+ side: "C",
45
+ abi: routerCAbi,
44
46
  functionName: "mintBlended",
45
47
  args: [
46
48
  keyId(a.key),
@@ -68,7 +70,8 @@ export async function mint(c, a) {
68
70
  */
69
71
  export async function createMarket(c, a) {
70
72
  return sendRouterWriteWithPermits(c, {
71
- abi: routerAbi,
73
+ side: "C",
74
+ abi: routerCAbi,
72
75
  functionName: "createMarket",
73
76
  args: [
74
77
  a.key,
@@ -92,7 +95,8 @@ export async function createMarket(c, a) {
92
95
  */
93
96
  export async function zapIn(c, a) {
94
97
  return sendRouterWriteWithPermits(c, {
95
- abi: routerAbi,
98
+ side: "C",
99
+ abi: routerCAbi,
96
100
  functionName: "zapIn",
97
101
  args: [
98
102
  keyId(a.key),
@@ -113,7 +117,8 @@ export async function zapIn(c, a) {
113
117
  /** The primitive, through the router's named entry: resize and reposition in one call, in kind. */
114
118
  export async function update(c, a) {
115
119
  return sendRouterWriteWithPermits(c, {
116
- abi: routerAbi,
120
+ side: "C",
121
+ abi: routerCAbi,
117
122
  functionName: "update",
118
123
  args: [
119
124
  keyId(a.key),
@@ -140,7 +145,8 @@ export async function update(c, a) {
140
145
  */
141
146
  export async function move(c, a) {
142
147
  return sendRouterWrite(c, {
143
- abi: routerAbi,
148
+ side: "C",
149
+ abi: routerCAbi,
144
150
  functionName: "move",
145
151
  args: [
146
152
  keyId(a.key),
@@ -161,8 +167,8 @@ export async function move(c, a) {
161
167
  export async function previewEdit(c, a) {
162
168
  const holder = a.holder ?? requireWallet(c).address;
163
169
  const r = (await c.public.readContract({
164
- address: c.addresses.lens,
165
- abi: lensAbi,
170
+ address: lensC(c),
171
+ abi: lensCAbi,
166
172
  functionName: "previewUpdate",
167
173
  args: [keyId(a.key), a.fromId, holder, a.shares, a.toFloor, a.toCap ?? NO_CAP, a.newL],
168
174
  }));
@@ -323,7 +329,8 @@ export async function burn(c, a) {
323
329
  if (a.ids.length !== a.shares.length)
324
330
  throw new Error("logswap: ids and shares length mismatch");
325
331
  return sendRouterWrite(c, {
326
- abi: routerAbi,
332
+ side: "C",
333
+ abi: routerCAbi,
327
334
  functionName: "burn",
328
335
  args: [
329
336
  keyId(a.key),
package/dist/onboard.d.ts CHANGED
@@ -12,9 +12,14 @@
12
12
  * ERC-20 to the *router* is not enough and not used — the pull goes through Permit2, and the
13
13
  * failure is `NotAllowed()` from Permit2 rather than anything naming an allowance. Approving the
14
14
  * router directly looks correct and does nothing.
15
+ *
16
+ * **One router per manager** (decision 096), and each is its own Permit2 spender: step 1 is shared by
17
+ * both (the ERC-20 goes to Permit2 once per token), steps 2 and 3 are per `side` — a wallet that trades
18
+ * on both singletons signs one Permit2 allowance per router, and grants the operator on each manager.
19
+ * Every helper here that depends on the router takes the `side` (`"F"` or `"C"`) right after the client.
15
20
  */
16
21
  import { type Address, type Hash, type Hex } from "viem";
17
- import type { LogswapClient } from "./client.js";
22
+ import { type LogswapClient, type Side } from "./client.js";
18
23
  export declare const MAX_UINT256: bigint;
19
24
  export declare const MAX_UINT160: bigint;
20
25
  export declare const MAX_UINT48: bigint;
@@ -31,37 +36,37 @@ export declare const permit2Expiry: () => bigint;
31
36
  export declare const permit2Covers: (amount: bigint, expiration: number, need: bigint) => boolean;
32
37
  /** Is this deployment's router wired to Permit2? Decides which approval path applies. */
33
38
  export declare function usesPermit2(c: LogswapClient): boolean;
34
- /** The contract that will actually pull tokens: Permit2 when wired, otherwise the router. */
35
- export declare function spenderFor(c: LogswapClient): Address;
39
+ /** The contract that will actually pull tokens: Permit2 when wired, otherwise the `side`'s router. */
40
+ export declare function spenderFor(c: LogswapClient, side: Side): Address;
36
41
  /** Step 1 — approve the *puller* on an ERC-20. Once per token. */
37
- export declare function approveToken(c: LogswapClient, token: Address, amount?: bigint): Promise<Hash>;
42
+ export declare function approveToken(c: LogswapClient, side: Side, token: Address, amount?: bigint): Promise<Hash>;
38
43
  /**
39
- * Step 2 — the standing Permit2 allowance for the router.
44
+ * Step 2 — the standing Permit2 allowance for the `side`'s router.
40
45
  *
41
46
  * No-op when the deployment has no Permit2. Prefer the signature flow (`applyPermit2` on the
42
47
  * router, bundled through `multicall`) in production; this transaction form is what a test or a
43
48
  * simple UI wants.
44
49
  */
45
- export declare function approvePermit2ForRouter(c: LogswapClient, token: Address, amount?: bigint, expiration?: bigint): Promise<Hash | null>;
50
+ export declare function approvePermit2ForRouter(c: LogswapClient, side: Side, token: Address, amount?: bigint, expiration?: bigint): Promise<Hash | null>;
46
51
  /**
47
52
  * Both token-side steps in order, skipping any already satisfied.
48
53
  *
49
54
  * Returns the hashes actually sent, so a UI can report "2 approvals" honestly rather than always
50
55
  * prompting twice.
51
56
  */
52
- export declare function onboardToken(c: LogswapClient, token: Address, need: bigint): Promise<Hash[]>;
57
+ export declare function onboardToken(c: LogswapClient, side: Side, token: Address, need: bigint): Promise<Hash[]>;
53
58
  /** What still stands between this wallet and a working write. */
54
59
  export interface TokenReadiness {
55
60
  usesPermit2: boolean;
56
- /** ERC-20 allowance to whoever pulls (Permit2 when wired, else the router). */
61
+ /** ERC-20 allowance to whoever pulls (Permit2 when wired, else the side's router). */
57
62
  needsTokenApproval: boolean;
58
- /** Permit2's standing allowance for the router. Always false when Permit2 is not wired. */
63
+ /** Permit2's standing allowance for the side's router. Always false when Permit2 is not wired. */
59
64
  needsPermit2Approval: boolean;
60
65
  }
61
- export declare function checkTokenReadiness(c: LogswapClient, token: Address, owner: Address, need: bigint): Promise<TokenReadiness>;
66
+ export declare function checkTokenReadiness(c: LogswapClient, side: Side, token: Address, owner: Address, need: bigint): Promise<TokenReadiness>;
62
67
  /**
63
68
  * For each token whose Permit2→router allowance is missing: read the nonce, have the wallet SIGN
64
69
  * a PermitSingle (a signature prompt, not a transaction), and return the encoded `applyPermit2`
65
70
  * calls ready to ride in a router multicall. Tokens already allowed produce nothing.
66
71
  */
67
- export declare function permit2SigCalls(c: LogswapClient, tokens: Address[]): Promise<Hex[]>;
72
+ export declare function permit2SigCalls(c: LogswapClient, side: Side, tokens: Address[]): Promise<Hex[]>;
package/dist/onboard.js CHANGED
@@ -12,8 +12,14 @@
12
12
  * ERC-20 to the *router* is not enough and not used — the pull goes through Permit2, and the
13
13
  * failure is `NotAllowed()` from Permit2 rather than anything naming an allowance. Approving the
14
14
  * router directly looks correct and does nothing.
15
+ *
16
+ * **One router per manager** (decision 096), and each is its own Permit2 spender: step 1 is shared by
17
+ * both (the ERC-20 goes to Permit2 once per token), steps 2 and 3 are per `side` — a wallet that trades
18
+ * on both singletons signs one Permit2 allowance per router, and grants the operator on each manager.
19
+ * Every helper here that depends on the router takes the `side` (`"F"` or `"C"`) right after the client.
15
20
  */
16
21
  import { parseAbi, zeroAddress } from "viem";
22
+ import { routerOf } from "./client.js";
17
23
  import { requireWallet } from "./write.js";
18
24
  export const MAX_UINT256 = (1n << 256n) - 1n;
19
25
  export const MAX_UINT160 = (1n << 160n) - 1n;
@@ -45,30 +51,30 @@ const PERMIT2 = parseAbi([
45
51
  export function usesPermit2(c) {
46
52
  return !!c.addresses.permit2 && c.addresses.permit2 !== zeroAddress;
47
53
  }
48
- /** The contract that will actually pull tokens: Permit2 when wired, otherwise the router. */
49
- export function spenderFor(c) {
50
- return usesPermit2(c) ? c.addresses.permit2 : c.addresses.router;
54
+ /** The contract that will actually pull tokens: Permit2 when wired, otherwise the `side`'s router. */
55
+ export function spenderFor(c, side) {
56
+ return usesPermit2(c) ? c.addresses.permit2 : routerOf(c, side);
51
57
  }
52
58
  /** Step 1 — approve the *puller* on an ERC-20. Once per token. */
53
- export async function approveToken(c, token, amount = MAX_UINT256) {
59
+ export async function approveToken(c, side, token, amount = MAX_UINT256) {
54
60
  const { account } = requireWallet(c);
55
61
  return c.wallet.writeContract({
56
62
  address: token,
57
63
  abi: ERC20,
58
64
  functionName: "approve",
59
- args: [spenderFor(c), amount],
65
+ args: [spenderFor(c, side), amount],
60
66
  account,
61
67
  chain: c.wallet.chain,
62
68
  });
63
69
  }
64
70
  /**
65
- * Step 2 — the standing Permit2 allowance for the router.
71
+ * Step 2 — the standing Permit2 allowance for the `side`'s router.
66
72
  *
67
73
  * No-op when the deployment has no Permit2. Prefer the signature flow (`applyPermit2` on the
68
74
  * router, bundled through `multicall`) in production; this transaction form is what a test or a
69
75
  * simple UI wants.
70
76
  */
71
- export async function approvePermit2ForRouter(c, token, amount = MAX_UINT160, expiration = permit2Expiry()) {
77
+ export async function approvePermit2ForRouter(c, side, token, amount = MAX_UINT160, expiration = permit2Expiry()) {
72
78
  if (!usesPermit2(c))
73
79
  return null;
74
80
  const { account } = requireWallet(c);
@@ -76,7 +82,7 @@ export async function approvePermit2ForRouter(c, token, amount = MAX_UINT160, ex
76
82
  address: c.addresses.permit2,
77
83
  abi: PERMIT2,
78
84
  functionName: "approve",
79
- args: [token, c.addresses.router, amount, Number(expiration)],
85
+ args: [token, routerOf(c, side), amount, Number(expiration)],
80
86
  account,
81
87
  chain: c.wallet.chain,
82
88
  });
@@ -87,7 +93,7 @@ export async function approvePermit2ForRouter(c, token, amount = MAX_UINT160, ex
87
93
  * Returns the hashes actually sent, so a UI can report "2 approvals" honestly rather than always
88
94
  * prompting twice.
89
95
  */
90
- export async function onboardToken(c, token, need) {
96
+ export async function onboardToken(c, side, token, need) {
91
97
  // The address, not the account object: these two are READS. Signing paths take the object.
92
98
  const { address } = requireWallet(c);
93
99
  const sent = [];
@@ -95,10 +101,10 @@ export async function onboardToken(c, token, need) {
95
101
  address: token,
96
102
  abi: ERC20,
97
103
  functionName: "allowance",
98
- args: [address, spenderFor(c)],
104
+ args: [address, spenderFor(c, side)],
99
105
  }));
100
106
  if (allowance < need) {
101
- const h = await approveToken(c, token);
107
+ const h = await approveToken(c, side, token);
102
108
  await c.public.waitForTransactionReceipt({ hash: h });
103
109
  sent.push(h);
104
110
  }
@@ -107,10 +113,10 @@ export async function onboardToken(c, token, need) {
107
113
  address: c.addresses.permit2,
108
114
  abi: PERMIT2,
109
115
  functionName: "allowance",
110
- args: [address, token, c.addresses.router],
116
+ args: [address, token, routerOf(c, side)],
111
117
  }));
112
118
  if (!permit2Covers(amt, expiration, need)) {
113
- const h = await approvePermit2ForRouter(c, token);
119
+ const h = await approvePermit2ForRouter(c, side, token);
114
120
  if (h) {
115
121
  await c.public.waitForTransactionReceipt({ hash: h });
116
122
  sent.push(h);
@@ -119,12 +125,12 @@ export async function onboardToken(c, token, need) {
119
125
  }
120
126
  return sent;
121
127
  }
122
- export async function checkTokenReadiness(c, token, owner, need) {
128
+ export async function checkTokenReadiness(c, side, token, owner, need) {
123
129
  const allowance = (await c.public.readContract({
124
130
  address: token,
125
131
  abi: ERC20,
126
132
  functionName: "allowance",
127
- args: [owner, spenderFor(c)],
133
+ args: [owner, spenderFor(c, side)],
128
134
  }));
129
135
  let needsPermit2Approval = false;
130
136
  if (usesPermit2(c)) {
@@ -132,7 +138,7 @@ export async function checkTokenReadiness(c, token, owner, need) {
132
138
  address: c.addresses.permit2,
133
139
  abi: PERMIT2,
134
140
  functionName: "allowance",
135
- args: [owner, token, c.addresses.router],
141
+ args: [owner, token, routerOf(c, side)],
136
142
  }));
137
143
  needsPermit2Approval = !permit2Covers(amt, expiration, need);
138
144
  }
@@ -163,7 +169,7 @@ const PERMIT2_TYPES = {
163
169
  * a PermitSingle (a signature prompt, not a transaction), and return the encoded `applyPermit2`
164
170
  * calls ready to ride in a router multicall. Tokens already allowed produce nothing.
165
171
  */
166
- export async function permit2SigCalls(c, tokens) {
172
+ export async function permit2SigCalls(c, side, tokens) {
167
173
  if (!usesPermit2(c))
168
174
  return [];
169
175
  const { account, address: owner } = requireWallet(c);
@@ -174,13 +180,13 @@ export async function permit2SigCalls(c, tokens) {
174
180
  address: c.addresses.permit2,
175
181
  abi: PERMIT2,
176
182
  functionName: "allowance",
177
- args: [owner, token, c.addresses.router],
183
+ args: [owner, token, routerOf(c, side)],
178
184
  }));
179
185
  if (permit2Covers(amt, expiration, 1n << 120n))
180
186
  continue; // effectively unlimited, and not lapsing
181
187
  const message = {
182
188
  details: { token, amount: MAX_UINT160, expiration: Number(permit2Expiry()), nonce },
183
- spender: c.addresses.router,
189
+ spender: routerOf(c, side),
184
190
  sigDeadline: BigInt(Math.floor(Date.now() / 1000)) + 1800n,
185
191
  };
186
192
  const signature = await c.wallet.signTypedData({
@@ -191,9 +197,9 @@ export async function permit2SigCalls(c, tokens) {
191
197
  message,
192
198
  });
193
199
  const { encodeFunctionData } = await import("viem");
194
- const { routerAbi } = await import("./generated.js");
200
+ const { routerCAbi, routerFAbi } = await import("./generated.js");
195
201
  calls.push(encodeFunctionData({
196
- abi: routerAbi,
202
+ abi: side === "F" ? routerFAbi : routerCAbi,
197
203
  functionName: "applyPermit2",
198
204
  args: [owner, message, signature],
199
205
  }));
package/dist/pools.d.ts CHANGED
@@ -210,6 +210,8 @@ export declare function annualise(perUnitL: bigint, elapsedSeconds: bigint): num
210
210
  export declare function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): Promise<bigint>;
211
211
  /**
212
212
  * Create a C market: `initialize(key, initialLogPrice)` on the manager — a call, not a deployment, and no funds move. The
213
+ * caller must BE the key's `creator` (C 15, decision 097: `NotCreator`; the registry resolves a routed caller to its user), and only
214
+ * the creator may make the first mint, which seeds the backstop. The
213
215
  * creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
214
216
  * preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
215
217
  * CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its