@logswap/sdk 0.5.91 → 0.5.93
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 +61 -18
- package/dist/admin.d.ts +48 -871
- package/dist/admin.js +55 -110
- package/dist/chains.d.ts +4 -4
- package/dist/chains.js +2 -3
- package/dist/client.d.ts +6 -7
- package/dist/client.js +12 -1
- package/dist/fpool.d.ts +298 -801
- package/dist/fpool.js +312 -336
- package/dist/generated.d.ts +1707 -3843
- package/dist/generated.js +982 -2248
- package/dist/history.js +7 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/write.js +2 -2
- package/package.json +1 -1
- package/src/admin.ts +66 -169
- package/src/chains.ts +6 -7
- package/src/client.ts +17 -7
- package/src/fpool.ts +449 -510
- package/src/generated.ts +938 -2210
- package/src/history.ts +5 -7
- package/src/index.ts +1 -1
- package/src/write.ts +2 -2
package/dist/history.js
CHANGED
|
@@ -36,8 +36,8 @@ 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`). Every policy is one factory-tracked contract, `Policy`:
|
|
40
|
-
*
|
|
39
|
+
* (logswap-be `devnet/indexer/rindexer.yaml`). Every policy is one factory-tracked contract, `Policy`: the four F policies are
|
|
40
|
+
* one contract (`PolicyF`, F 41) and share its events, so no policy event needs a prefix.
|
|
41
41
|
*/
|
|
42
42
|
function contractName(c, address, event) {
|
|
43
43
|
const a = address.toLowerCase();
|
|
@@ -54,21 +54,17 @@ function contractName(c, address, event) {
|
|
|
54
54
|
return "PolicyRegistry";
|
|
55
55
|
if (is(d.tokenFactory))
|
|
56
56
|
return "TokenFactory";
|
|
57
|
-
if (is(d.publicPolicy) || is(d.privatePolicy) || is(d.
|
|
58
|
-
return indexedContractOf("
|
|
59
|
-
if (is(d.
|
|
60
|
-
return indexedContractOf("
|
|
61
|
-
if (is(d.padPolicy))
|
|
62
|
-
return indexedContractOf("pad", event);
|
|
63
|
-
if (is(d.orphanPolicy))
|
|
64
|
-
return indexedContractOf("orphan", event);
|
|
57
|
+
if (is(d.publicPolicy) || is(d.privatePolicy) || is(d.polPolicy) || is(d.padPolicy))
|
|
58
|
+
return indexedContractOf("public", event);
|
|
59
|
+
if (is(d.publicPolicyC))
|
|
60
|
+
return indexedContractOf("public", event);
|
|
65
61
|
return null;
|
|
66
62
|
}
|
|
67
63
|
/**
|
|
68
64
|
* 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.
|
|
69
65
|
*/
|
|
70
66
|
export function indexedContractOf(kind, event) {
|
|
71
|
-
void kind; //
|
|
67
|
+
void kind; // one contract serves every F kind (F 41) and the C sponsored policy's events do not clash with its: every policy event is unshared
|
|
72
68
|
return "Policy";
|
|
73
69
|
}
|
|
74
70
|
/** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
|
package/dist/index.d.ts
CHANGED
|
@@ -23,5 +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 { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi,
|
|
26
|
+
export { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi, policyFAbi, policyRegistryAbi, sponsorPolicyCAbi } from "./generated.js";
|
|
27
27
|
export * from "./admin.js";
|
package/dist/index.js
CHANGED
|
@@ -23,5 +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 { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi,
|
|
26
|
+
export { managerCAbi, managerFAbi, lensCAbi, lensFAbi, routerCAbi, routerFAbi, routerActionsAbi, policyFAbi, policyRegistryAbi, sponsorPolicyCAbi } from "./generated.js";
|
|
27
27
|
export * from "./admin.js";
|
package/dist/write.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* what you have — but the bound is what ships.
|
|
14
14
|
*/
|
|
15
15
|
import { routerOf } from "./client.js";
|
|
16
|
-
import { managerCAbi, managerFAbi,
|
|
16
|
+
import { managerCAbi, managerFAbi, policyFAbi } from "./generated.js";
|
|
17
17
|
/** Disables the deadline check. Deliberate opt-out, never a default. */
|
|
18
18
|
export const NEVER = (1n << 256n) - 1n;
|
|
19
19
|
/** Default deadline window: 20 minutes, the same order as every major DEX front end. */
|
|
@@ -90,7 +90,7 @@ const errorKey = (e) => `${e.name}(${e.inputs.map((i) => i.type).join(",")})`;
|
|
|
90
90
|
export const routerRevertErrors = (() => {
|
|
91
91
|
const seen = new Set();
|
|
92
92
|
const out = [];
|
|
93
|
-
for (const x of [...managerCAbi, ...managerFAbi, ...
|
|
93
|
+
for (const x of [...managerCAbi, ...managerFAbi, ...policyFAbi, ...permit2Errors]) {
|
|
94
94
|
if (x.type !== "error")
|
|
95
95
|
continue;
|
|
96
96
|
const e = x;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logswap/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.93",
|
|
4
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",
|
package/src/admin.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* admin — the protocol's writes: the policies a pool may be born
|
|
3
|
-
* creation modes
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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`.
|
|
10
12
|
*
|
|
11
|
-
* The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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`.
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
|
-
import type { Address, Hash
|
|
18
|
+
import type { Address, Hash } from "viem";
|
|
17
19
|
import { poolId as keyId, type PoolKey } from "./keys.js";
|
|
18
20
|
import { managerC, routerC, type LogswapClient, type Side } from "./client.js";
|
|
19
21
|
import { getPool } from "./pools.js";
|
|
20
|
-
import { managerCAbi, managerFAbi,
|
|
21
|
-
import { bytes32ToText,
|
|
22
|
+
import { managerCAbi, managerFAbi, policyFAbi, policyRegistryAbi, sponsorPolicyCAbi } from "./generated.js";
|
|
23
|
+
import { bytes32ToText, fFeeListed, fPoolKindOfPolicy, fPolicyTermsOf, textToBytes32, type FPoolKind } from "./fpool.js";
|
|
22
24
|
|
|
23
25
|
function wallet(c: LogswapClient) {
|
|
24
26
|
if (!c.wallet) throw new Error("a wallet client is required");
|
|
@@ -72,11 +74,12 @@ export async function policyApproved(c: LogswapClient, policy: Address): Promise
|
|
|
72
74
|
return c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "isApproved", args: [policy] } as never) as Promise<boolean>;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
/** One policy on the registry's list, with what it
|
|
77
|
+
/** One policy on the registry's list, with what it is. */
|
|
76
78
|
export interface RegistryEntry {
|
|
77
79
|
policy: Address;
|
|
78
|
-
/** The policy's
|
|
79
|
-
kind: FPoolKind;
|
|
80
|
+
/** 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 (the C sponsored policy). */
|
|
81
|
+
kind: FPoolKind | null;
|
|
82
|
+
/** The name recorded at approval (`approve(policy, name)`). */
|
|
80
83
|
name: string;
|
|
81
84
|
/** The time (unix seconds) it closes to new pools from; 0 = open. A block number before F version 29. */
|
|
82
85
|
until: bigint;
|
|
@@ -85,9 +88,9 @@ export interface RegistryEntry {
|
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
/**
|
|
88
|
-
* Every policy listed, sunset ones included — one flat list, each with the kind
|
|
89
|
-
*
|
|
90
|
-
* with no registry.
|
|
91
|
+
* Every policy listed, sunset ones included — one flat list, each with the kind its terms spell; `kind` narrows it to one,
|
|
92
|
+
* 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`
|
|
93
|
+
* `null`. Empty with no registry.
|
|
91
94
|
*/
|
|
92
95
|
export async function registryPolicies(c: LogswapClient, kind?: FPoolKind): Promise<RegistryEntry[]> {
|
|
93
96
|
const registry = await policyRegistryOf(c);
|
|
@@ -99,7 +102,7 @@ export async function registryPolicies(c: LogswapClient, kind?: FPoolKind): Prom
|
|
|
99
102
|
list.map(async (policy) => {
|
|
100
103
|
const [[listed, until, , name], tag] = await Promise.all([
|
|
101
104
|
c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "entries", args: [policy] } as never) as Promise<[boolean, bigint, number, `0x${string}`]>,
|
|
102
|
-
fPoolKindOfPolicy(c, policy),
|
|
105
|
+
fPoolKindOfPolicy(c, policy).catch(() => null), // a C policy answers no F terms
|
|
103
106
|
]);
|
|
104
107
|
return { policy, kind: tag, name: bytes32ToText(name), until, approved: listed && (until === 0n || now < until) };
|
|
105
108
|
}),
|
|
@@ -170,165 +173,51 @@ export const registryAcceptOwner = acceptLogAuthority;
|
|
|
170
173
|
* {@link registryApprove} under the policy's own tag as its name, false is {@link registryRevoke}.
|
|
171
174
|
*/
|
|
172
175
|
export async function setPolicyApproved(c: LogswapClient, policy: Address, approved: boolean): Promise<Hash> {
|
|
173
|
-
return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy)) : registryRevoke(c, policy);
|
|
176
|
+
return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy).catch(() => "policy")) : registryRevoke(c, policy);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* policy
|
|
180
|
+
* The name the registry recorded for `policy` at approval (`kindOf`, F version 20: `approve(policy, name)`'s word) — refreshed
|
|
181
|
+
* on re-approval and kept after a revoke. The LOG's own instances are approved as `public`, `private`, `pol`, `pad`; what a
|
|
182
|
+
* policy IS is its terms ({@link fPolicyTermsOf}). "" for a policy the registry never approved (or a deployment with no registry).
|
|
180
183
|
*/
|
|
181
|
-
export
|
|
182
|
-
swapMode?: FPoolSwapMode;
|
|
183
|
-
/** The pool's operator under the new policy; zero (the default) appoints none. Required for `operator` mode. */
|
|
184
|
-
operator?: Address;
|
|
185
|
-
/** The mint gate: only the authority and the operator mint. */
|
|
186
|
-
mintGated?: boolean;
|
|
187
|
-
/** Accounts added to the swap whitelist. */
|
|
188
|
-
listed?: readonly Address[];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function permissionsArg(p: MigrationPermissions = {}) {
|
|
192
|
-
return { swapMode: fPoolSwapModes.indexOf(p.swapMode ?? "open"), operator: p.operator ?? ZERO, mintGated: p.mintGated ?? false, listed: p.listed ?? [] };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Move a pool to another approved policy of the same kind: the LOG Authority's alone, a forced move
|
|
197
|
-
* (adoption at regeneration by the pool authority's consent is specified, not built — logswap-docs
|
|
198
|
-
* `specs/governance/policy-adoption.md`), orchestrated on the registry — `migrate(manager, key, to, permissions)`
|
|
199
|
-
* (decision 098; `migratePrivate` is gone). The registry checks the key against the manager (`NoPool`), the manager is its
|
|
200
|
-
* own (`WrongManager`), the two policies' tags recorded at approval ({@link registryKindOf}; every sponsored policy shares
|
|
201
|
-
* `"sponsor"`), the creation mode against the pool's authority (`SponsorOnly`: a sponsor's pool moves only under a policy of
|
|
202
|
-
* the same sponsor, or one open to anyone) and that the pool never held the target (`AlreadyHeld`). The new policy is
|
|
203
|
-
* brought the authority and the name (read off the old policy defensively, the key's creator standing in when it cannot
|
|
204
|
-
* answer); `permissions` installs the pool's swap mode, operator, mint gate and whitelist under it in the same transaction ({@link MigrationPermissions});
|
|
205
|
-
* the key, its fees and its id are untouched; no swap lands in the block. F only until C ships a `setPolicy`.
|
|
206
|
-
*
|
|
207
|
-
* Pass the pool's `key` when in hand. Given only `poolId`, the key is rebuilt from the pool's
|
|
208
|
-
* `PoolCreated` log ({@link fPoolKeyOfPool}) with `salt` (zero by default) and checked against
|
|
209
|
-
* the id — the log does not carry the salt, so a salted pool needs it named.
|
|
210
|
-
*/
|
|
211
|
-
export async function fPoolMigrate(
|
|
212
|
-
c: LogswapClient,
|
|
213
|
-
a: { to: Address; permissions?: MigrationPermissions } & ({ key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint }),
|
|
214
|
-
): Promise<Hash> {
|
|
215
|
-
const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
|
|
216
|
-
return registryWrite(c, "migrate", [c.addresses.managerF, key, a.to, permissionsArg(a.permissions)]);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* `PolicyRegistry.orphan(manager, key)` (decision 098): move a pool whose sponsor went rogue or lost its key to the manager's orphan policy
|
|
221
|
-
* ({@link registryOrphanPolicyOf}) — no owner and no setting; swap and mint open; `deployLiquidity`, `harvest`, `close` and the generation
|
|
222
|
-
* step refused; income tax zero. The LOG Authority's alone, needing no consent, and FINAL: a pool never leaves the orphan policy (`Orphaned`).
|
|
223
|
-
* `key` as in {@link fPoolMigrate}.
|
|
224
|
-
*/
|
|
225
|
-
export async function fPoolOrphan(
|
|
226
|
-
c: LogswapClient,
|
|
227
|
-
a: { key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint },
|
|
228
|
-
): Promise<Hash> {
|
|
229
|
-
const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
|
|
230
|
-
return registryWrite(c, "orphan", [c.addresses.managerF, key]);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** The orphan policy registered for a manager (`orphanPolicy(manager)`): F's by default; zero when none is registered or the deployment has no registry. */
|
|
234
|
-
export async function registryOrphanPolicyOf(c: LogswapClient, side: Side = "F"): Promise<Address> {
|
|
235
|
-
const registry = await policyRegistryOf(c);
|
|
236
|
-
if (registry === ZERO) return ZERO;
|
|
237
|
-
const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
|
|
238
|
-
return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "orphanPolicy", args: [mgr] } as never)) as Address;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** `PolicyRegistry.setOrphanPolicy(manager, policy)`: register the approved policy tagged `"orphan"` that answers `manager` (F's by default). The LOG Authority's. */
|
|
242
|
-
export async function registrySetOrphanPolicy(c: LogswapClient, policy: Address, side: Side = "F"): Promise<Hash> {
|
|
243
|
-
const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
|
|
244
|
-
return registryWrite(c, "setOrphanPolicy", [mgr, policy]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* The kind tag the registry recorded for `policy` at approval (`kindOf`, F version 20) — refreshed
|
|
249
|
-
* on re-approval and kept after a revoke; what `migrate` compares, never the policy's live
|
|
250
|
-
* answer. "" for a policy the registry never approved (or a deployment with no registry).
|
|
251
|
-
*/
|
|
252
|
-
export async function registryKindOf(c: LogswapClient, policy: Address): Promise<FPoolKind | ""> {
|
|
184
|
+
export async function registryKindOf(c: LogswapClient, policy: Address): Promise<string> {
|
|
253
185
|
const registry = await policyRegistryOf(c);
|
|
254
186
|
if (registry === ZERO) return "";
|
|
255
187
|
const word = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "kindOf", args: [policy] } as never)) as `0x${string}`;
|
|
256
|
-
return bytes32ToText(word)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// ─── the policies' numbers: immutable since decision 098, so read-only here ─────
|
|
260
|
-
// A pad's schedule, its income tax rate, a POL's reserve ratio and a sponsored policy's tiers, quotes, spacings and tax are
|
|
261
|
-
// constructor immutables of the policy the LOG deploys; the setters (`setSchedule`, `setThresholdBase`, `setIncomeTaxRate`,
|
|
262
|
-
// `setMinQuoteRatio`, `setQuoteListed`, `setFeeListed`, `setSwapFeeTax`, …) and their wrappers are gone.
|
|
263
|
-
|
|
264
|
-
/** A pad policy's `T(0)` in one quote (decision 070): `set` false means no pad can be born on that quote. */
|
|
265
|
-
export interface PadThresholdBase {
|
|
266
|
-
quote: Address;
|
|
267
|
-
set: boolean;
|
|
268
|
-
/** In the quote's units; 0 when not set. */
|
|
269
|
-
base: bigint;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/** `PadPolicy.thresholdSet(quote)` and `thresholdBaseOf(quote)` for each quote asked (decision 070). */
|
|
273
|
-
export async function padThresholdBases(c: LogswapClient, policy: Address, quotes: readonly Address[]): Promise<PadThresholdBase[]> {
|
|
274
|
-
const rd = <T>(functionName: string, quote: Address) =>
|
|
275
|
-
c.public.readContract({ address: policy, abi: padPolicyAbi, functionName, args: [quote] } as never) as Promise<T>;
|
|
276
|
-
return Promise.all(
|
|
277
|
-
quotes.map(async (quote) => {
|
|
278
|
-
const [set, base] = await Promise.all([rd<boolean>("thresholdSet", quote), rd<bigint>("thresholdBaseOf", quote)]);
|
|
279
|
-
return { quote, set, base };
|
|
280
|
-
}),
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** `PadPolicy.thresholdOf(quote, rung)` (decision 070): the income a pad quoted in `quote` must bank to climb `rung` (0 reads `T(0)`). */
|
|
285
|
-
export async function padThresholdOf(c: LogswapClient, policy: Address, quote: Address, rung: bigint | number = 0n): Promise<bigint> {
|
|
286
|
-
return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "thresholdOf", args: [quote, BigInt(rung)] } as never)) as bigint;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/** `PadPolicy.threshold(poolId, rung)` (decision 070): the income pad `poolId` must bank to climb `rung`, in its own quote. */
|
|
290
|
-
export async function padThreshold(c: LogswapClient, policy: Address, poolId: Hex, rung: bigint | number): Promise<bigint> {
|
|
291
|
-
return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "threshold", args: [poolId, BigInt(rung)] } as never)) as bigint;
|
|
188
|
+
return bytes32ToText(word);
|
|
292
189
|
}
|
|
293
190
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
creatorShareMin: bigint;
|
|
298
|
-
creatorShareMax: bigint;
|
|
299
|
-
}
|
|
191
|
+
// ─── the F policy's lists: immutable, so read-only here (policy.md §4.1) ─────
|
|
192
|
+
// 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
|
|
193
|
+
// policy the LOG deploys. The whole set of numbers is `fPolicyTermsOf`; these answer one candidate.
|
|
300
194
|
|
|
301
|
-
/**
|
|
302
|
-
export async function
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
195
|
+
/** 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. */
|
|
196
|
+
export async function policyQuoteAllowed(c: LogswapClient, policy: Address, quote: Address): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
|
|
197
|
+
const [curated, listed] = await Promise.all([
|
|
198
|
+
c.public.readContract({ address: policy, abi: policyFAbi, functionName: "quoteCurated" } as never) as Promise<boolean>,
|
|
199
|
+
c.public.readContract({ address: policy, abi: policyFAbi, functionName: "quoteListed", args: [quote] } as never) as Promise<boolean>,
|
|
200
|
+
]);
|
|
201
|
+
return { curated, listed, allowed: !curated || listed };
|
|
306
202
|
}
|
|
307
203
|
|
|
308
|
-
/** Whether `
|
|
309
|
-
export async function
|
|
204
|
+
/** Whether `base` passes an F `policy`'s birth check now: it curates bases (`baseCurated`) and lists it, or it does not curate. */
|
|
205
|
+
export async function policyBaseAllowed(c: LogswapClient, policy: Address, base: Address): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
|
|
310
206
|
const [curated, listed] = await Promise.all([
|
|
311
|
-
c.public.readContract({ address: policy, abi:
|
|
312
|
-
c.public.readContract({ address: policy, abi:
|
|
207
|
+
c.public.readContract({ address: policy, abi: policyFAbi, functionName: "baseCurated" } as never) as Promise<boolean>,
|
|
208
|
+
c.public.readContract({ address: policy, abi: policyFAbi, functionName: "baseListed", args: [base] } as never) as Promise<boolean>,
|
|
313
209
|
]);
|
|
314
210
|
return { curated, listed, allowed: !curated || listed };
|
|
315
211
|
}
|
|
316
212
|
|
|
317
213
|
/**
|
|
318
|
-
* Whether
|
|
319
|
-
*
|
|
214
|
+
* Whether the swap fee at `swapFeeIdx` of the F fee list passes `policy`'s birth check now (`feeMask`, policy.md §6). `curated` is true
|
|
215
|
+
* 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.
|
|
320
216
|
*/
|
|
321
|
-
export async function policyFeeAllowed(
|
|
322
|
-
c
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
kind: "swap" | "mint" = "swap",
|
|
326
|
-
): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
|
|
327
|
-
const [tiers, listed] = await Promise.all([
|
|
328
|
-
c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapTiers" : "mintTiers" } as never) as Promise<bigint>,
|
|
329
|
-
c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapFeeListed" : "mintFeeListed", args: [fee] } as never) as Promise<boolean>,
|
|
330
|
-
]);
|
|
331
|
-
return { curated: tiers !== 0n, listed, allowed: listed };
|
|
217
|
+
export async function policyFeeAllowed(c: LogswapClient, policy: Address, swapFeeIdx: number): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
|
|
218
|
+
const { feeMask } = await fPolicyTermsOf(c, policy);
|
|
219
|
+
const listed = fFeeListed(feeMask, swapFeeIdx);
|
|
220
|
+
return { curated: feeMask !== 0, listed, allowed: listed };
|
|
332
221
|
}
|
|
333
222
|
|
|
334
223
|
/** `PolicyRegistry.CreationMode` (decisions 073, 098): who may create under a policy. Open = 0, SponsorOnly = 1 (the policy's own immutable sponsor, who must also be the key's creator). `Restricted` and the initializer list are gone. */
|
|
@@ -442,16 +331,24 @@ export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator?:
|
|
|
442
331
|
}
|
|
443
332
|
|
|
444
333
|
/**
|
|
445
|
-
* Every refusal a birth can meet at a
|
|
446
|
-
* failed simulation: the sponsored C policy's errors
|
|
447
|
-
*
|
|
334
|
+
* Every refusal a birth can meet at a policy or the registry (064, 065, 098; policy.md §4.4), for `decodeErrorResult` on a
|
|
335
|
+
* failed simulation: the sponsored C policy's errors, the F policy's (`Refused`, `NotCanonical`, `FeeNotListed`, `QuoteNotListed`,
|
|
336
|
+
* `BaseNotListed`, `TooManyLegs`, `AlreadyHeld`, …) and the registry's admission errors. One entry per distinct signature.
|
|
448
337
|
*/
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
] as
|
|
338
|
+
type AbiError = { type: "error"; name: string; inputs: readonly { type: string; name?: string }[] };
|
|
339
|
+
const isAbiError = (x: { type: string }): x is AbiError => x.type === "error";
|
|
340
|
+
export const gateErrorAbi: readonly AbiError[] = (() => {
|
|
341
|
+
const seen = new Set<string>();
|
|
342
|
+
const sig = (x: AbiError) => `${x.name}(${x.inputs.map((i) => i.type).join(",")})`;
|
|
343
|
+
const all = (abi: readonly unknown[]) => (abi as readonly { type: string }[]).filter(isAbiError);
|
|
344
|
+
const errors: AbiError[] = [
|
|
345
|
+
...all(sponsorPolicyCAbi),
|
|
346
|
+
...all(policyFAbi),
|
|
347
|
+
// creation admission is the registry's (F 33 / C 10, 073): a refusal there surfaces through the manager's birth
|
|
348
|
+
...all(policyRegistryAbi).filter((x) => ["SponsorOnly", "InvalidForwardedUser", "NotListed"].includes(x.name)),
|
|
349
|
+
];
|
|
350
|
+
return errors.filter((x) => (seen.has(sig(x)) ? false : (seen.add(sig(x)), true)));
|
|
351
|
+
})();
|
|
455
352
|
|
|
456
353
|
// ─── the LOG Treasury (066): receives, administers nothing ───────────────────
|
|
457
354
|
|
package/src/chains.ts
CHANGED
|
@@ -160,16 +160,16 @@ export interface LogswapDeployment {
|
|
|
160
160
|
managerC?: Address;
|
|
161
161
|
routerC?: Address;
|
|
162
162
|
lensC?: Address;
|
|
163
|
-
/** The LOG's open
|
|
163
|
+
/** The LOG's open F policy (`PolicyF`, `open`: anyone creates at salt zero, no gate ever; policy.md). */
|
|
164
164
|
publicPolicy: Address;
|
|
165
|
-
/** The LOG's
|
|
165
|
+
/** The LOG's desk on F (`PolicyF`, closed: the LOG creates, gates by pool). The artifact key predates 098 and is kept. */
|
|
166
166
|
privatePolicy: Address;
|
|
167
|
+
/** The LOG's POL policy on F (`PolicyF`: one base, a bid buffer, an income tax). */
|
|
167
168
|
polPolicy: Address;
|
|
169
|
+
/** The LOG's pad policy on F (`PolicyF`, `seedToDead`: income-only harvests, never closes). */
|
|
168
170
|
padPolicy: Address;
|
|
169
171
|
/** The LOG's open sponsored instance on C (`SponsorPolicyC`). Absent while the chain has no C stack. */
|
|
170
172
|
publicPolicyC?: Address;
|
|
171
|
-
/** F's orphan policy (`OrphanPolicyF`, decision 098): where `PolicyRegistry.orphan` moves a pool. Absent on an artifact that predates it. */
|
|
172
|
-
orphanPolicy?: Address;
|
|
173
173
|
/** The devnet's token factory; local deployments only. */
|
|
174
174
|
tokenFactory?: Address;
|
|
175
175
|
}
|
|
@@ -201,8 +201,8 @@ const REQUIRED_ADDRESSES = [
|
|
|
201
201
|
"padPolicy",
|
|
202
202
|
] as const;
|
|
203
203
|
const OPTIONAL_ADDRESSES = ["createX", "tokenFactory"] as const;
|
|
204
|
-
/** Policies an artifact may carry as `address(0)` (no C stack
|
|
205
|
-
const OPTIONAL_POLICIES = ["publicPolicyC"
|
|
204
|
+
/** Policies an artifact may carry as `address(0)` (no C stack): zero is absent. An `orphanPolicy` key on an older artifact is ignored (F 41 has none). */
|
|
205
|
+
const OPTIONAL_POLICIES = ["publicPolicyC"] as const;
|
|
206
206
|
/** The C stack: all three, or none (`address(0)` — the chain has not opted into C yet). */
|
|
207
207
|
const C_STACK = ["managerC", "routerC", "lensC"] as const;
|
|
208
208
|
|
|
@@ -271,7 +271,6 @@ export function addressesOfDeployment(d: LogswapDeployment): LogswapAddresses {
|
|
|
271
271
|
polPolicy: d.polPolicy,
|
|
272
272
|
padPolicy: d.padPolicy,
|
|
273
273
|
...(d.publicPolicyC ? { publicPolicyC: d.publicPolicyC } : {}),
|
|
274
|
-
...(d.orphanPolicy ? { orphanPolicy: d.orphanPolicy } : {}),
|
|
275
274
|
policyRegistry: d.policyRegistry,
|
|
276
275
|
permit2: d.permit2,
|
|
277
276
|
...(d.tokenFactory ? { tokenFactory: d.tokenFactory } : {}),
|
package/src/client.ts
CHANGED
|
@@ -32,10 +32,11 @@ export interface LogswapAddresses {
|
|
|
32
32
|
/** C's read-only lens: ladder derivations and views. */
|
|
33
33
|
lensC?: Address;
|
|
34
34
|
/**
|
|
35
|
-
* The LOG's policies (decision 098: immutable, deployed by the LOG): every pool names one in its key, and the pool's
|
|
36
|
-
* roles, gates and terms live on it.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
* The LOG's policies (decision 098: immutable, deployed by the LOG): every pool names one in its key for life, and the pool's
|
|
36
|
+
* roles, gates and terms live on it. On F the four are instances of one contract, `PolicyF` (F 41, policy.md), told apart by
|
|
37
|
+
* their immutables: `publicPolicy` is the open one (anyone creates at salt zero, no gate ever), `privatePolicy` the LOG's desk
|
|
38
|
+
* (closed, gates by pool), `polPolicy` and `padPolicy` the treasury's and the launch's. The artifact keys predate 098 and are
|
|
39
|
+
* kept. A deployment predating the policies carries none.
|
|
39
40
|
*/
|
|
40
41
|
publicPolicy?: Address;
|
|
41
42
|
privatePolicy?: Address;
|
|
@@ -43,8 +44,6 @@ export interface LogswapAddresses {
|
|
|
43
44
|
padPolicy?: Address;
|
|
44
45
|
/** The LOG's open sponsored instance on C (`SponsorPolicyC`): the policy of a public market. Absent with no C stack. */
|
|
45
46
|
publicPolicyC?: Address;
|
|
46
|
-
/** F's orphan policy (`OrphanPolicyF`, kind `"orphan"`): the policy `PolicyRegistry.orphan` moves a pool to. */
|
|
47
|
-
orphanPolicy?: Address;
|
|
48
47
|
/**
|
|
49
48
|
* The policy registry: what a pool of each kind may be born under, and the
|
|
50
49
|
* owner that may move a pool between policies. Read from the F manager (`registry()`) when
|
|
@@ -352,7 +351,18 @@ export const EXPECTED_VERSION = 16n;
|
|
|
352
351
|
// `Pool.flags` (`GATE_SWAP` 1, `GATE_MINT` 2, `SEED_TO_DEAD` 4) and `Pool.operator` caches the operator; `setPermissions` /
|
|
353
352
|
// `PermissionsSet` are `setGates` / `GatesSet`; the registry's `migrate(manager, key, to, permissions)` replaces `migratePrivate`,
|
|
354
353
|
// `orphan(manager, key)` moves a pool to `OrphanPolicyF`. No pool id moved.
|
|
355
|
-
|
|
354
|
+
// 41 (policy.md): one policy contract, `PolicyF`, whose kinds are parameter sets — `SponsorPolicyF`, `PolPolicy`, `PadPolicy` and
|
|
355
|
+
// `OrphanPolicyF` are gone. The AUTHORITY is the policy's (immutable) and appoints each pool's OPERATOR, who funds, harvests, closes
|
|
356
|
+
// and sets the modes and the name. `PoolKeyF` is `(quote, bases, swapFeeIdx, policy, salt)` — no creator, no mint fee: the swap fee is
|
|
357
|
+
// an index into `FEE_LIST` (1, 2, 5, 10, 20, 50, 100, 200 bp) and the mint fee the next entry — so EVERY POOL ID MOVED.
|
|
358
|
+
// `deployLiquidity(poolId, baseAssets, quoteAmount, lnCapOverSeed)` on an inactive pool only (no `to`: the operator holds the
|
|
359
|
+
// shares); `harvest(poolId, extra, to)` takes the income and `extra` capital; `close(poolId, to)` at any bid, harvesting first,
|
|
360
|
+
// refused on a pad; `regenerate` is gone (`multicall(close, redeem, deployLiquidity)`); the registry's `migrate`, `orphan` and
|
|
361
|
+
// `setOrphanPolicy` are gone, `sunset` also refuses `deployLiquidity`. `PoolCreated(poolId, quote, policy, bases, swapFeeIdx, salt)`;
|
|
362
|
+
// `IncomeHarvested(poolId, to, gen, income, capital, tax, toOperator, Q)`; `GenerationFrozen` from `close` alone; `IncomeReleased` and
|
|
363
|
+
// `PolicyMigrated` are gone. The policy's name is an event (`NameSet`), its lists are per policy (`setRights`, `RightsSet`), its
|
|
364
|
+
// modes per pool (`setSwapMode` / `setMintMode`, each Open < Listed < Operator with `mintMode ≥ swapMode`).
|
|
365
|
+
export const EXPECTED_F_VERSION = 41n;
|
|
356
366
|
|
|
357
367
|
export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
|
|
358
368
|
const { managerCAbi, managerFAbi } = await import("./generated.js");
|