@logswap/sdk 0.5.102 → 0.5.104

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 (64) hide show
  1. package/README.md +14 -418
  2. package/dist/actions.d.ts +0 -39
  3. package/dist/actions.js +0 -39
  4. package/dist/admin.d.ts +0 -106
  5. package/dist/admin.js +1 -96
  6. package/dist/chains.d.ts +0 -49
  7. package/dist/chains.js +0 -30
  8. package/dist/claims.d.ts +0 -32
  9. package/dist/claims.js +0 -30
  10. package/dist/client.d.ts +0 -116
  11. package/dist/client.js +1 -231
  12. package/dist/fees.d.ts +1 -45
  13. package/dist/fees.js +0 -44
  14. package/dist/fpool.d.ts +4 -612
  15. package/dist/fpool.js +14 -490
  16. package/dist/generated.js +0 -30
  17. package/dist/history.d.ts +0 -61
  18. package/dist/history.js +5 -74
  19. package/dist/ids.d.ts +0 -30
  20. package/dist/ids.js +0 -31
  21. package/dist/index.d.ts +0 -7
  22. package/dist/index.js +0 -7
  23. package/dist/indexer.d.ts +0 -68
  24. package/dist/indexer.js +1 -77
  25. package/dist/keys.d.ts +0 -50
  26. package/dist/keys.js +0 -35
  27. package/dist/liquidity.d.ts +0 -128
  28. package/dist/liquidity.js +1 -107
  29. package/dist/onboard.d.ts +0 -52
  30. package/dist/onboard.js +1 -59
  31. package/dist/pools.d.ts +3 -157
  32. package/dist/pools.js +1 -164
  33. package/dist/positions.d.ts +0 -102
  34. package/dist/positions.js +1 -90
  35. package/dist/quote.d.ts +0 -14
  36. package/dist/quote.js +0 -14
  37. package/dist/swap.d.ts +0 -31
  38. package/dist/swap.js +5 -37
  39. package/dist/tokencache.d.ts +0 -48
  40. package/dist/tokencache.js +1 -73
  41. package/dist/write.d.ts +1 -87
  42. package/dist/write.js +1 -87
  43. package/package.json +3 -8
  44. package/src/actions.ts +0 -208
  45. package/src/admin.ts +0 -350
  46. package/src/chains.ts +0 -278
  47. package/src/claims.ts +0 -111
  48. package/src/client.ts +0 -436
  49. package/src/fees.ts +0 -138
  50. package/src/fpool.ts +0 -2049
  51. package/src/generated.ts +0 -4345
  52. package/src/history.ts +0 -383
  53. package/src/ids.ts +0 -78
  54. package/src/index.ts +0 -26
  55. package/src/indexer.ts +0 -264
  56. package/src/keys.ts +0 -138
  57. package/src/liquidity.ts +0 -456
  58. package/src/onboard.ts +0 -253
  59. package/src/pools.ts +0 -465
  60. package/src/positions.ts +0 -297
  61. package/src/quote.ts +0 -36
  62. package/src/swap.ts +0 -181
  63. package/src/tokencache.ts +0 -178
  64. package/src/write.ts +0 -236
package/dist/actions.js CHANGED
@@ -1,32 +1,10 @@
1
- /**
2
- * actions.ts — the router's transaction: a BATCH.
3
- *
4
- * `execute(actions, settle)` runs a list of actions — mint, burn, update, claim, swap, path, in any
5
- * order, across any C markets — under ONE manager lock. Each action accrues deltas on the router
6
- * and settles nothing; the batch settles once per token in `settle.tokens`, pulling at most
7
- * `maxIn[i]` from the caller and taking at least `minOut[i]` to `settle.to`. A touched token
8
- * left off the list fails the manager's own close (`TokensNotSettled`), so the list is also the
9
- * caller's statement of which tokens may move.
10
- *
11
- * `OPEN_DELTA` as a swap amount means "the router's open delta of that token": what earlier
12
- * actions left it holding (exact-in, path) or owing (exact-out). It is what lets action i+1
13
- * consume action i's proceeds — a harvest funds a buy, a burn exits to one asset, a deepen is paid
14
- * in base — each moving ONE token.
15
- *
16
- * Payloads are `abi.encode` of the router's `*Act` structs. Their tuple types are read from the
17
- * generated ABI (the router's pure `encode*` helpers exist for exactly this), so nothing here is
18
- * hand-written and a struct change is a `tsc`/vector failure, not a runtime surprise.
19
- */
20
1
  import { encodeAbiParameters } from "viem";
21
2
  import { routerCAbi, routerActionsAbi } from "./generated.js";
22
3
  import { poolId as keyId } from "./keys.js";
23
4
  import { NO_CAP } from "./ids.js";
24
5
  import { resolveDeadline, resolveRecipient, sendRouterWriteWithPermits, simulateRouterWrite } from "./write.js";
25
- /** "The router's open delta of that token" — the swap-amount sentinel. `type(uint256).max`. */
26
6
  export const OPEN_DELTA = (1n << 256n) - 1n;
27
- /** No bound. The same word as the sentinel, kept apart because it means something else. */
28
7
  export const UNBOUNDED = (1n << 256n) - 1n;
29
- /** The router's op tags — `OpType` in `RouterOps.sol`, C actions only (the F ops have their own lock). */
30
8
  export var Op;
31
9
  (function (Op) {
32
10
  Op[Op["MintBlended"] = 0] = "MintBlended";
@@ -37,7 +15,6 @@ export var Op;
37
15
  Op[Op["Update"] = 5] = "Update";
38
16
  Op[Op["Path"] = 6] = "Path";
39
17
  })(Op || (Op = {}));
40
- /* payload encoding ========================================================== */
41
18
  function payloadType(encoder) {
42
19
  const f = routerActionsAbi.find((x) => x.type === "function" && x.name === encoder);
43
20
  if (!f?.inputs)
@@ -45,32 +22,26 @@ function payloadType(encoder) {
45
22
  return f.inputs;
46
23
  }
47
24
  const enc = (encoder, value) => encodeAbiParameters(payloadType(encoder), [value]);
48
- /** Mint exposure `L` at `targetFloor` (off-grid blends the two adjacent rungs), `cap` optional. */
49
25
  export function mintAction(a) {
50
26
  return { op: Op.MintBlended, data: enc("encodeMint", { poolId: keyId(a.key), targetFloor: a.targetFloor, cap: a.cap ?? NO_CAP, L: a.L }) };
51
27
  }
52
- /** Burn `shares[i]` of `ids[i]`; accrued fees are swept into the same batch. Needs the operator grant. */
53
28
  export function burnAction(a) {
54
29
  if (a.ids.length !== a.shares.length)
55
30
  throw new Error("logswap: ids and shares length mismatch");
56
31
  return { op: Op.Burn, data: enc("encodeBurn", { poolId: keyId(a.key), ids: a.ids, shares: a.shares }) };
57
32
  }
58
- /** Exact-in swap. `amountIn` may be `OPEN_DELTA`: the input an earlier action left the router holding. */
59
33
  export function swapExactInAction(a) {
60
34
  return { op: Op.SwapExactIn, data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseIn, amount: a.amountIn, limit: a.minOut ?? 0n }) };
61
35
  }
62
- /** Exact-out swap. `amountOut` may be `OPEN_DELTA`: the output an earlier action left the router owing. */
63
36
  export function swapExactOutAction(a) {
64
37
  return {
65
38
  op: Op.SwapExactOut,
66
39
  data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseOut, amount: a.amountOut, limit: a.maxIn ?? UNBOUNDED }),
67
40
  };
68
41
  }
69
- /** Collect the caller's fees on `ids`; positions untouched. */
70
42
  export function claimAction(a) {
71
43
  return { op: Op.Claim, data: enc("encodeClaim", { poolId: keyId(a.key), ids: a.ids }) };
72
44
  }
73
- /** The general edit — set `shares` of `fromId` to (`toFloor`, `toCap`, `newL`); `newL = 0` exits. */
74
45
  export function updateAction(a) {
75
46
  return {
76
47
  op: Op.Update,
@@ -84,14 +55,11 @@ export function updateAction(a) {
84
55
  }),
85
56
  };
86
57
  }
87
- /** Multi-hop exact-in route; `amountIn` may be `OPEN_DELTA`. Intermediate tokens never move. */
88
58
  export function pathAction(a) {
89
59
  if (a.hops.length === 0)
90
60
  throw new Error("logswap: empty path");
91
61
  return { op: Op.Path, data: enc("encodePath", { hops: a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })), amountIn: a.amountIn, minOut: a.minOut ?? 0n }) };
92
62
  }
93
- /* settlement builders ======================================================= */
94
- /** A settlement over explicit tokens; missing bounds default to unbounded in, zero out. */
95
63
  export function settlement(a) {
96
64
  const n = a.tokens.length;
97
65
  const maxIn = a.maxIn ?? a.tokens.map(() => UNBOUNDED);
@@ -100,7 +68,6 @@ export function settlement(a) {
100
68
  throw new Error("logswap: settlement bounds length mismatch");
101
69
  return { tokens: a.tokens, maxIn, minOut, to: a.to };
102
70
  }
103
- /** Settle both of a market's tokens, in kind. */
104
71
  export function settleInKind(key, to, b = {}) {
105
72
  return settlement({
106
73
  tokens: [key.base, key.quote],
@@ -109,10 +76,6 @@ export function settleInKind(key, to, b = {}) {
109
76
  to,
110
77
  });
111
78
  }
112
- /**
113
- * Settle in ONE of a market's tokens: the other is bound to zero both ways, so the batch must have
114
- * netted it — which is what a trailing `OPEN_DELTA` swap does.
115
- */
116
79
  export function settleOnly(key, to, side, b = {}) {
117
80
  const base = side === "base";
118
81
  return settlement({
@@ -122,13 +85,11 @@ export function settleOnly(key, to, side, b = {}) {
122
85
  to,
123
86
  });
124
87
  }
125
- /** Run a batch: one lock, one settlement per token, one transaction (Permit2 signatures ride inside). */
126
88
  export async function execute(c, a) {
127
89
  const settle = { ...a.settle, to: a.settle.to ?? resolveRecipient(c, a) };
128
90
  const pull = a.pullTokens ?? settle.tokens.filter((_, i) => settle.maxIn[i] > 0n);
129
91
  return sendRouterWriteWithPermits(c, { side: "C", abi: routerCAbi, functionName: "execute", args: [a.actions, settle, resolveDeadline(a)] }, [...pull]);
130
92
  }
131
- /** Simulate a batch: the per-action returns and the signed flows (+ = paid in), without sending. */
132
93
  export async function simulateExecute(c, a) {
133
94
  const settle = { ...a.settle, to: a.settle.to ?? a.account ?? resolveRecipient(c, a) };
134
95
  const [results, flows] = await simulateRouterWrite(c, {
package/dist/admin.d.ts CHANGED
@@ -1,165 +1,71 @@
1
- /**
2
- * admin — the protocol's writes: the policies a pool may be born under (the registry's list, its sunsets), the C manager's
3
- * creation modes, the two roles' two-step handovers (decision 066): the LOG Authority (the registry's `logAuthority`)
4
- * administers the registry and both managers; the LOG Treasury (`treasury` on each manager) only receives, and is replaced by
5
- * the authority's `proposeTreasury`. Plain writes to the managers and the registry; no router.
6
- *
7
- * The policies are immutable and deployed by the LOG (decision 098; policy.md): a policy has no setter of its numbers — its fee
8
- * mask, quotes, bases, buffer, tax and cap bound are constructor immutables — so there is no wrapper that writes one. A change is
9
- * a new policy, approved ({@link registryApprove}); the old one is sunset ({@link registrySunset}) and its pools run to their next
10
- * close. The key's policy is the pool's for life: the registry's `migrate` and `orphan` are gone (F 41). What remains here for the
11
- * policies is reading their numbers; their per-pool settings are in `fpool.ts`.
12
- *
13
- * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee is the protocol's on both
14
- * managers. A harvest has no cut (056); the protocol's share of a harvest's income is the policy's `incomeTaxRate` on the
15
- * payer's slice, capped by the manager at `INCOME_TAX_MAX`.
16
- */
17
1
  import type { Address, Hash } from "viem";
18
2
  import { type PoolKey } from "./keys.js";
19
3
  import { type LogswapClient, type Side } from "./client.js";
20
4
  import { type FPoolKind } from "./fpool.js";
21
- /**
22
- * The C swap-fee tax (decisions 060, 066, 098): the protocol's share of every swap fee a C position is
23
- * paid (claims and the burn's auto-claim), WAD. `tax` is the level a market born under `policy` (default: the deployment's
24
- * `publicPolicyC`) is given — the policy's immutable `swapFeeTax`; each market keeps the level of its birth for
25
- * life — read it with {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. A different level is a different policy.
26
- * `max` is the manager's bound.
27
- */
28
5
  export declare function cSwapFeeTax(c: LogswapClient, policy?: Address): Promise<{
29
6
  tax: bigint;
30
7
  max: bigint;
31
8
  }>;
32
- /** One C market's swap-fee tax, recorded at its birth (066). */
33
9
  export declare function cMarketSwapFeeTax(c: LogswapClient, key: PoolKey): Promise<bigint>;
34
- /**
35
- * The policy registry the F manager asks at every birth — `addresses.policyRegistry` when the
36
- * deployment carries it, else read once from the manager. The zero address is a deployment with
37
- * no registry: it asks nobody, and nothing here can be written.
38
- */
39
10
  export declare function policyRegistryOf(c: LogswapClient): Promise<Address>;
40
- /** Whether `policy` is approved now — listed and not yet sunset. True everywhere on a deployment with no registry. */
41
11
  export declare function policyApproved(c: LogswapClient, policy: Address): Promise<boolean>;
42
- /** One policy on the registry's list, with what it is. */
43
12
  export interface RegistryEntry {
44
13
  policy: Address;
45
- /** The label the policy's terms spell ({@link fPolicyTermsOf}) — what a pool born under it is; `null` for a policy that answers no F terms (a `PolicyC`). */
46
14
  kind: FPoolKind | null;
47
- /** The name recorded at approval (`approve(policy, name)`). */
48
15
  name: string;
49
- /** The time (unix seconds) it closes to new pools from; 0 = open. A block number before F version 29. */
50
16
  until: bigint;
51
- /** Approved now: listed and not yet sunset. */
52
17
  approved: boolean;
53
18
  }
54
- /**
55
- * Every policy listed, sunset ones included — one flat list, each with the kind its terms spell; `kind` narrows it to one,
56
- * which is what a create form's dropdown reads. The registry is one list for both managers: a C policy is on it with `kind`
57
- * `null`. Empty with no registry.
58
- */
59
19
  export declare function registryPolicies(c: LogswapClient, kind?: FPoolKind): Promise<RegistryEntry[]>;
60
- /**
61
- * The LOG Authority (decision 066) — the registry's `logAuthority`, which administers the registry, both
62
- * managers and every protocol policy — and the proposed next one. Zero with no registry: nothing on
63
- * the deployment can be administered.
64
- */
65
20
  export declare function logAuthority(c: LogswapClient): Promise<{
66
21
  authority: Address;
67
22
  pending: Address;
68
23
  }>;
69
- /** @deprecated F version 27 renamed the registry's `owner` to `authority`: use {@link logAuthority}. */
70
24
  export declare function registryOwner(c: LogswapClient): Promise<{
71
25
  owner: Address;
72
26
  pending: Address;
73
27
  }>;
74
- /** `PolicyRegistry.approve`: list `policy` under `name` (at most 31 bytes). Again renames it and clears its sunset. The LOG Authority's. */
75
28
  export declare function registryApprove(c: LogswapClient, policy: Address, name: string): Promise<Hash>;
76
- /** `PolicyRegistry.sunset`: close `policy` to new pools from `untilTime` (unix seconds, F version 29) on; 0 reopens. The LOG Authority's. */
77
29
  export declare function registrySunset(c: LogswapClient, policy: Address, untilTime: bigint): Promise<Hash>;
78
- /** `PolicyRegistry.revoke`: remove `policy` from the list at once. Live pools are untouched. The LOG Authority's. */
79
30
  export declare function registryRevoke(c: LogswapClient, policy: Address): Promise<Hash>;
80
- /**
81
- * The LOG Authority's two-step handover (066): the authority proposes, the proposed address accepts
82
- * by its own call (a Safe or a timelock sends `acceptLogAuthority` itself). One handover moves the
83
- * administration of the registry, both managers and every policy; the treasury is a separate role.
84
- */
85
31
  export declare function proposeLogAuthority(c: LogswapClient, next: Address): Promise<Hash>;
86
32
  export declare function acceptLogAuthority(c: LogswapClient): Promise<Hash>;
87
- /** @deprecated use {@link proposeLogAuthority}. */
88
33
  export declare const registryProposeOwner: typeof proposeLogAuthority;
89
- /** @deprecated use {@link acceptLogAuthority}. */
90
34
  export declare const registryAcceptOwner: typeof acceptLogAuthority;
91
- /**
92
- * Approve or revoke, the F version 15–16 shape kept for callers: `approved` true is
93
- * {@link registryApprove} under the policy's own tag as its name, false is {@link registryRevoke}.
94
- */
95
35
  export declare function setPolicyApproved(c: LogswapClient, policy: Address, approved: boolean): Promise<Hash>;
96
- /**
97
- * The name the registry recorded for `policy` at approval (`kindOf`, F version 20: `approve(policy, name)`'s word) — refreshed
98
- * on re-approval and kept after a revoke. The LOG's own instances are approved as `public`, `private`, `pol`, `pad`; what a
99
- * policy IS is its terms ({@link fPolicyTermsOf}). "" for a policy the registry never approved (or a deployment with no registry).
100
- */
101
36
  export declare function registryKindOf(c: LogswapClient, policy: Address): Promise<string>;
102
- /** Whether `quote` passes an F `policy`'s birth check now: it curates quotes (`quoteCurated`, a non-empty list set in the constructor) and lists it, or it does not curate. */
103
37
  export declare function policyQuoteAllowed(c: LogswapClient, policy: Address, quote: Address): Promise<{
104
38
  curated: boolean;
105
39
  listed: boolean;
106
40
  allowed: boolean;
107
41
  }>;
108
- /** Whether `base` passes an F `policy`'s birth check now: it curates bases (`baseCurated`) and lists it, or it does not curate. */
109
42
  export declare function policyBaseAllowed(c: LogswapClient, policy: Address, base: Address): Promise<{
110
43
  curated: boolean;
111
44
  listed: boolean;
112
45
  allowed: boolean;
113
46
  }>;
114
- /**
115
- * Whether the swap fee at `swapFeeIdx` of the F fee list passes `policy`'s birth check now (`feeMask`, policy.md §6). `curated` is true
116
- * when the policy masks the list (a non-zero mask); with none, every entry is allowed. The mint fee follows the swap fee and is not asked.
117
- */
118
47
  export declare function policyFeeAllowed(c: LogswapClient, policy: Address, swapFeeIdx: number): Promise<{
119
48
  curated: boolean;
120
49
  listed: boolean;
121
50
  allowed: boolean;
122
51
  }>;
123
- /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
124
52
  export declare function registrySetForwarderTrusted(c: LogswapClient, forwarder: Address, trusted: boolean): Promise<Hash>;
125
- /**
126
- * `PolicyRegistry.userOf(caller)` (C 15, decision 097): the account a caller acts for — the user a trusted forwarder
127
- * (a router) names, else the caller itself. The account a manager names as a pool's creator and asks its policy about at a birth.
128
- */
129
53
  export declare function registryUserOf(c: LogswapClient, caller: Address): Promise<Address>;
130
54
  export interface CGateRules {
131
- /** The policy admits `creator` (`PolicyBase._admitBirth`): anyone on an open policy, the policy's authority on a closed one (`Refused`). */
132
55
  creatorOk: boolean;
133
- /** The quote is on the policy's list, or the policy lists none (`quoteCurated`). */
134
56
  quoteOk: boolean;
135
- /** The base is on the policy's list, or the policy lists none (`baseCurated`; `BaseNotListed`). */
136
57
  baseOk: boolean;
137
- /** The swap fee's index is on the policy's `feeMask` (an empty mask lists all eight; `FeeNotListed`). The mint fee follows it. */
138
58
  feeOk: boolean;
139
- /** An open policy needs `salt` zero (`NotCanonical`); a closed one may run several markets of one shape. */
140
59
  saltOk: boolean;
141
- /** The registry lists the policy and its sunset has not passed (`PolicyNotApproved`); true on a deployment with no registry. */
142
60
  policyOk: boolean;
143
- /** This exact market (the key's id) is already initialized: another is a different key. */
144
61
  exists: boolean;
145
- /** Every check passes: the policy would admit this market from this creator (the manager checks the two indices, `BadParam`). */
146
62
  admitted: boolean;
147
63
  }
148
- /**
149
- * A C policy's birth checks for one candidate market and creator, in one round of reads — what the create form shows before a
150
- * wallet is asked (C 18, decisions 099, 100: `PolicyC.mayInit`). The policy is `key.policy`; `creator` is the account that will call
151
- * {@link initializeMarket}. The spacing is the manager's list ({@link SPACING_LIST}) and none of the policy's.
152
- */
153
64
  export declare function cGateRules(c: LogswapClient, a: {
154
65
  key: PoolKey;
155
66
  creator: Address;
156
67
  gate?: Address;
157
68
  }): Promise<CGateRules>;
158
- /**
159
- * Every refusal a birth can meet at a policy or the registry (064, 065, 098; policy.md §4.4), for `decodeErrorResult` on a
160
- * failed simulation: the C policy's errors, the F policy's (`Refused`, `NotCanonical`, `FeeNotListed`, `QuoteNotListed`,
161
- * `BaseNotListed`, `TooManyLegs`, `AlreadyHeld`, …) and the registry's `NotListed`. One entry per distinct signature.
162
- */
163
69
  type AbiError = {
164
70
  type: "error";
165
71
  name: string;
@@ -169,25 +75,13 @@ type AbiError = {
169
75
  }[];
170
76
  };
171
77
  export declare const gateErrorAbi: readonly AbiError[];
172
- /** A manager's treasury — where its protocol revenue goes — and the proposed next one. */
173
78
  export declare function logTreasury(c: LogswapClient, side: Side): Promise<{
174
79
  treasury: Address;
175
80
  pending: Address;
176
81
  }>;
177
- /**
178
- * Propose a manager's next treasury: the LOG Authority's call, never the treasury's own, so a
179
- * treasury that can no longer act is replaced without it. Nothing the old treasury holds moves.
180
- */
181
82
  export declare function proposeTreasury(c: LogswapClient, side: Side, next: Address): Promise<Hash>;
182
- /** The proposed treasury takes the role, sending from its own address. */
183
83
  export declare function acceptTreasury(c: LogswapClient, side: Side): Promise<Hash>;
184
- /** @deprecated the collector became the treasury (066), proposed by the LOG Authority: use {@link proposeTreasury}. */
185
84
  export declare const proposeCollector: typeof proposeTreasury;
186
- /** @deprecated use {@link acceptTreasury}. */
187
85
  export declare const acceptCollector: typeof acceptTreasury;
188
- /**
189
- * `ManagerC.collectProtocolFees(poolId)`: pay one market's `protocolOwed` (mint fees and swap-fee
190
- * tax) to the treasury. Anyone may send it (066); the destination is fixed.
191
- */
192
86
  export declare function collectCProtocolFees(c: LogswapClient, key: PoolKey): Promise<Hash>;
193
87
  export {};
package/dist/admin.js CHANGED
@@ -1,19 +1,3 @@
1
- /**
2
- * admin — the protocol's writes: the policies a pool may be born under (the registry's list, its sunsets), the C manager's
3
- * creation modes, the two roles' two-step handovers (decision 066): the LOG Authority (the registry's `logAuthority`)
4
- * administers the registry and both managers; the LOG Treasury (`treasury` on each manager) only receives, and is replaced by
5
- * the authority's `proposeTreasury`. Plain writes to the managers and the registry; no router.
6
- *
7
- * The policies are immutable and deployed by the LOG (decision 098; policy.md): a policy has no setter of its numbers — its fee
8
- * mask, quotes, bases, buffer, tax and cap bound are constructor immutables — so there is no wrapper that writes one. A change is
9
- * a new policy, approved ({@link registryApprove}); the old one is sunset ({@link registrySunset}) and its pools run to their next
10
- * close. The key's policy is the pool's for life: the registry's `migrate` and `orphan` are gone (F 41). What remains here for the
11
- * policies is reading their numbers; their per-pool settings are in `fpool.ts`.
12
- *
13
- * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee is the protocol's on both
14
- * managers. A harvest has no cut (056); the protocol's share of a harvest's income is the policy's `incomeTaxRate` on the
15
- * payer's slice, capped by the manager at `INCOME_TAX_MAX`.
16
- */
17
1
  import { poolId as keyId, FEE_LIST } from "./keys.js";
18
2
  import { managerC } from "./client.js";
19
3
  import { getPool } from "./pools.js";
@@ -27,13 +11,6 @@ function wallet(c) {
27
11
  function write(c, address, abi, functionName, args) {
28
12
  return wallet(c).writeContract({ address, abi, functionName, args, chain: c.wallet.chain, account: c.wallet.account });
29
13
  }
30
- /**
31
- * The C swap-fee tax (decisions 060, 066, 098): the protocol's share of every swap fee a C position is
32
- * paid (claims and the burn's auto-claim), WAD. `tax` is the level a market born under `policy` (default: the deployment's
33
- * `publicPolicyC`) is given — the policy's immutable `swapFeeTax`; each market keeps the level of its birth for
34
- * life — read it with {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. A different level is a different policy.
35
- * `max` is the manager's bound.
36
- */
37
14
  export async function cSwapFeeTax(c, policy) {
38
15
  const address = policy ?? c.addresses.publicPolicyC;
39
16
  if (!address)
@@ -44,55 +21,36 @@ export async function cSwapFeeTax(c, policy) {
44
21
  ]);
45
22
  return { tax, max };
46
23
  }
47
- /** One C market's swap-fee tax, recorded at its birth (066). */
48
24
  export async function cMarketSwapFeeTax(c, key) {
49
25
  return (await getPool(c, key)).swapFeeTax;
50
26
  }
51
- // ─── the registry: the LOG Authority's (046, 066) ───────────────────────────
52
27
  const ZERO = "0x0000000000000000000000000000000000000000";
53
- /**
54
- * The policy registry the F manager asks at every birth — `addresses.policyRegistry` when the
55
- * deployment carries it, else read once from the manager. The zero address is a deployment with
56
- * no registry: it asks nobody, and nothing here can be written.
57
- */
58
28
  export async function policyRegistryOf(c) {
59
29
  if (c.addresses.policyRegistry)
60
30
  return c.addresses.policyRegistry;
61
31
  return (await c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "registry" }));
62
32
  }
63
- /** Whether `policy` is approved now — listed and not yet sunset. True everywhere on a deployment with no registry. */
64
33
  export async function policyApproved(c, policy) {
65
34
  const registry = await policyRegistryOf(c);
66
35
  if (registry === ZERO)
67
36
  return true;
68
37
  return c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "isApproved", args: [policy] });
69
38
  }
70
- /**
71
- * Every policy listed, sunset ones included — one flat list, each with the kind its terms spell; `kind` narrows it to one,
72
- * which is what a create form's dropdown reads. The registry is one list for both managers: a C policy is on it with `kind`
73
- * `null`. Empty with no registry.
74
- */
75
39
  export async function registryPolicies(c, kind) {
76
40
  const registry = await policyRegistryOf(c);
77
41
  if (registry === ZERO)
78
42
  return [];
79
43
  const list = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "policies" }));
80
- // the registry compares `until` with block.timestamp (F version 29)
81
44
  const now = (await c.public.getBlock({ blockTag: "latest" })).timestamp;
82
45
  const all = await Promise.all(list.map(async (policy) => {
83
46
  const [[listed, until, , name], tag] = await Promise.all([
84
47
  c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "entries", args: [policy] }),
85
- fPoolKindOfPolicy(c, policy).catch(() => null), // a C policy answers no F terms
48
+ fPoolKindOfPolicy(c, policy).catch(() => null),
86
49
  ]);
87
50
  return { policy, kind: tag, name: bytes32ToText(name), until, approved: listed && (until === 0n || now < until) };
88
51
  }));
89
52
  return kind ? all.filter((e) => e.kind === kind) : all;
90
53
  }
91
- /**
92
- * The LOG Authority (decision 066) — the registry's `logAuthority`, which administers the registry, both
93
- * managers and every protocol policy — and the proposed next one. Zero with no registry: nothing on
94
- * the deployment can be administered.
95
- */
96
54
  export async function logAuthority(c) {
97
55
  const registry = await policyRegistryOf(c);
98
56
  if (registry === ZERO)
@@ -103,7 +61,6 @@ export async function logAuthority(c) {
103
61
  ]);
104
62
  return { authority, pending };
105
63
  }
106
- /** @deprecated F version 27 renamed the registry's `owner` to `authority`: use {@link logAuthority}. */
107
64
  export async function registryOwner(c) {
108
65
  const { authority, pending } = await logAuthority(c);
109
66
  return { owner: authority, pending };
@@ -114,45 +71,26 @@ async function registryWrite(c, functionName, args) {
114
71
  throw new Error("logswap: this deployment carries no policy registry");
115
72
  return write(c, registry, policyRegistryAbi, functionName, args);
116
73
  }
117
- /** `PolicyRegistry.approve`: list `policy` under `name` (at most 31 bytes). Again renames it and clears its sunset. The LOG Authority's. */
118
74
  export async function registryApprove(c, policy, name) {
119
75
  return registryWrite(c, "approve", [policy, textToBytes32(name)]);
120
76
  }
121
- /** `PolicyRegistry.sunset`: close `policy` to new pools from `untilTime` (unix seconds, F version 29) on; 0 reopens. The LOG Authority's. */
122
77
  export async function registrySunset(c, policy, untilTime) {
123
78
  return registryWrite(c, "sunset", [policy, untilTime]);
124
79
  }
125
- /** `PolicyRegistry.revoke`: remove `policy` from the list at once. Live pools are untouched. The LOG Authority's. */
126
80
  export async function registryRevoke(c, policy) {
127
81
  return registryWrite(c, "revoke", [policy]);
128
82
  }
129
- /**
130
- * The LOG Authority's two-step handover (066): the authority proposes, the proposed address accepts
131
- * by its own call (a Safe or a timelock sends `acceptLogAuthority` itself). One handover moves the
132
- * administration of the registry, both managers and every policy; the treasury is a separate role.
133
- */
134
83
  export async function proposeLogAuthority(c, next) {
135
84
  return registryWrite(c, "proposeLogAuthority", [next]);
136
85
  }
137
86
  export async function acceptLogAuthority(c) {
138
87
  return registryWrite(c, "acceptLogAuthority", []);
139
88
  }
140
- /** @deprecated use {@link proposeLogAuthority}. */
141
89
  export const registryProposeOwner = proposeLogAuthority;
142
- /** @deprecated use {@link acceptLogAuthority}. */
143
90
  export const registryAcceptOwner = acceptLogAuthority;
144
- /**
145
- * Approve or revoke, the F version 15–16 shape kept for callers: `approved` true is
146
- * {@link registryApprove} under the policy's own tag as its name, false is {@link registryRevoke}.
147
- */
148
91
  export async function setPolicyApproved(c, policy, approved) {
149
92
  return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy).catch(() => "policy")) : registryRevoke(c, policy);
150
93
  }
151
- /**
152
- * The name the registry recorded for `policy` at approval (`kindOf`, F version 20: `approve(policy, name)`'s word) — refreshed
153
- * on re-approval and kept after a revoke. The LOG's own instances are approved as `public`, `private`, `pol`, `pad`; what a
154
- * policy IS is its terms ({@link fPolicyTermsOf}). "" for a policy the registry never approved (or a deployment with no registry).
155
- */
156
94
  export async function registryKindOf(c, policy) {
157
95
  const registry = await policyRegistryOf(c);
158
96
  if (registry === ZERO)
@@ -160,10 +98,6 @@ export async function registryKindOf(c, policy) {
160
98
  const word = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "kindOf", args: [policy] }));
161
99
  return bytes32ToText(word);
162
100
  }
163
- // ─── the F policy's lists: immutable, so read-only here (policy.md §4.1) ─────
164
- // The quotes a pool may be born on, the bases it may hold and the fee entries it may use are constructor values of the
165
- // policy the LOG deploys. The whole set of numbers is `fPolicyTermsOf`; these answer one candidate.
166
- /** Whether `quote` passes an F `policy`'s birth check now: it curates quotes (`quoteCurated`, a non-empty list set in the constructor) and lists it, or it does not curate. */
167
101
  export async function policyQuoteAllowed(c, policy, quote) {
168
102
  const [curated, listed] = await Promise.all([
169
103
  c.public.readContract({ address: policy, abi: policyFAbi, functionName: "quoteCurated" }),
@@ -171,7 +105,6 @@ export async function policyQuoteAllowed(c, policy, quote) {
171
105
  ]);
172
106
  return { curated, listed, allowed: !curated || listed };
173
107
  }
174
- /** Whether `base` passes an F `policy`'s birth check now: it curates bases (`baseCurated`) and lists it, or it does not curate. */
175
108
  export async function policyBaseAllowed(c, policy, base) {
176
109
  const [curated, listed] = await Promise.all([
177
110
  c.public.readContract({ address: policy, abi: policyFAbi, functionName: "baseCurated" }),
@@ -179,34 +112,20 @@ export async function policyBaseAllowed(c, policy, base) {
179
112
  ]);
180
113
  return { curated, listed, allowed: !curated || listed };
181
114
  }
182
- /**
183
- * Whether the swap fee at `swapFeeIdx` of the F fee list passes `policy`'s birth check now (`feeMask`, policy.md §6). `curated` is true
184
- * when the policy masks the list (a non-zero mask); with none, every entry is allowed. The mint fee follows the swap fee and is not asked.
185
- */
186
115
  export async function policyFeeAllowed(c, policy, swapFeeIdx) {
187
116
  const { feeMask } = await fPolicyTermsOf(c, policy);
188
117
  const listed = fFeeListed(feeMask, swapFeeIdx);
189
118
  return { curated: feeMask !== 0, listed, allowed: listed };
190
119
  }
191
- /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
192
120
  export async function registrySetForwarderTrusted(c, forwarder, trusted) {
193
121
  return registryWrite(c, "setForwarderTrusted", [forwarder, trusted]);
194
122
  }
195
- /**
196
- * `PolicyRegistry.userOf(caller)` (C 15, decision 097): the account a caller acts for — the user a trusted forwarder
197
- * (a router) names, else the caller itself. The account a manager names as a pool's creator and asks its policy about at a birth.
198
- */
199
123
  export async function registryUserOf(c, caller) {
200
124
  const registry = await policyRegistryOf(c);
201
125
  if (registry === ZERO)
202
126
  return caller;
203
127
  return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "userOf", args: [caller] }));
204
128
  }
205
- /**
206
- * A C policy's birth checks for one candidate market and creator, in one round of reads — what the create form shows before a
207
- * wallet is asked (C 18, decisions 099, 100: `PolicyC.mayInit`). The policy is `key.policy`; `creator` is the account that will call
208
- * {@link initializeMarket}. The spacing is the manager's list ({@link SPACING_LIST}) and none of the policy's.
209
- */
210
129
  export async function cGateRules(c, a) {
211
130
  const g = a.gate ?? a.key.policy;
212
131
  const rd = (functionName, args = []) => c.public.readContract({ address: g, abi: policyCAbi, functionName, args });
@@ -241,16 +160,13 @@ export const gateErrorAbi = (() => {
241
160
  const errors = [
242
161
  ...all(policyCAbi),
243
162
  ...all(policyFAbi),
244
- // who creates under a policy is the policy's rule (C 18, decision 100); the registry only lists the policy
245
163
  ...all(policyRegistryAbi).filter((x) => x.name === "NotListed"),
246
164
  ];
247
165
  return errors.filter((x) => (seen.has(sig(x)) ? false : (seen.add(sig(x)), true)));
248
166
  })();
249
- // ─── the LOG Treasury (066): receives, administers nothing ───────────────────
250
167
  function manager(c, side) {
251
168
  return side === "C" ? { address: managerC(c), abi: managerCAbi } : { address: c.addresses.managerF, abi: managerFAbi };
252
169
  }
253
- /** A manager's treasury — where its protocol revenue goes — and the proposed next one. */
254
170
  export async function logTreasury(c, side) {
255
171
  const m = manager(c, side);
256
172
  const [treasury, pending] = await Promise.all([
@@ -259,27 +175,16 @@ export async function logTreasury(c, side) {
259
175
  ]);
260
176
  return { treasury, pending };
261
177
  }
262
- /**
263
- * Propose a manager's next treasury: the LOG Authority's call, never the treasury's own, so a
264
- * treasury that can no longer act is replaced without it. Nothing the old treasury holds moves.
265
- */
266
178
  export async function proposeTreasury(c, side, next) {
267
179
  const m = manager(c, side);
268
180
  return write(c, m.address, m.abi, "proposeTreasury", [next]);
269
181
  }
270
- /** The proposed treasury takes the role, sending from its own address. */
271
182
  export async function acceptTreasury(c, side) {
272
183
  const m = manager(c, side);
273
184
  return write(c, m.address, m.abi, "acceptTreasury", []);
274
185
  }
275
- /** @deprecated the collector became the treasury (066), proposed by the LOG Authority: use {@link proposeTreasury}. */
276
186
  export const proposeCollector = proposeTreasury;
277
- /** @deprecated use {@link acceptTreasury}. */
278
187
  export const acceptCollector = acceptTreasury;
279
- /**
280
- * `ManagerC.collectProtocolFees(poolId)`: pay one market's `protocolOwed` (mint fees and swap-fee
281
- * tax) to the treasury. Anyone may send it (066); the destination is fixed.
282
- */
283
188
  export async function collectCProtocolFees(c, key) {
284
189
  return write(c, managerC(c), managerCAbi, "collectProtocolFees", [keyId(key)]);
285
190
  }