@logswap/sdk 0.5.79 → 0.5.80

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/dist/fpool.js CHANGED
@@ -102,7 +102,7 @@ export async function getFPool(c, poolId) {
102
102
  compositeX: v.compositeX,
103
103
  unharvested: v.unharvested,
104
104
  lnCapOverFloor: Number(p.lnCapOverFloor),
105
- bigSigma: p.bigSigma,
105
+ realizedVariance: p.realizedVariance,
106
106
  policy: p.policy,
107
107
  asks: Number(p.asks),
108
108
  name,
@@ -159,6 +159,7 @@ export function fPoolPolicyFor(c, kind) {
159
159
  export async function fPoolPolicyOf(c, poolId) {
160
160
  return (await rawFPool(c, poolId)).policy;
161
161
  }
162
+ const SWAP_MODES = ["open", "listed", "executor"];
162
163
  /** Read a pool's roles from its policy. `state` saves the `getPool` round trip when already in hand. */
163
164
  export async function getFPoolRoles(c, poolId, state) {
164
165
  const s = state ?? (await getFPool(c, poolId));
@@ -170,15 +171,11 @@ export async function getFPoolRoles(c, poolId, state) {
170
171
  rdPolicy(fPolicyBaseAbi, "maxHarvest"),
171
172
  ]);
172
173
  const desk = s.kind === "private";
173
- const [operator, pendingOperator, gateMint, gateSwap] = desk
174
- ? await Promise.all([
175
- rdPolicy(privatePolicyAbi, "operator"),
176
- rdPolicy(privatePolicyAbi, "pendingOperator"),
177
- rdPolicy(privatePolicyAbi, "gateMint"),
178
- rdPolicy(privatePolicyAbi, "gateSwap"),
179
- ])
180
- : [ZERO_ADDRESS, ZERO_ADDRESS, false, false];
181
- return { policy: s.policy, creator, authority, pendingAuthority, operator, pendingOperator, gateMint, gateSwap, maxHarvest };
174
+ const permissions = desk
175
+ ? (await c.public.readContract({ address: s.policy, abi: privatePolicyAbi, functionName: "permissionsOf", args: [poolId] }))
176
+ : undefined;
177
+ const [mode, swapExecutor, gateMint, , operator] = permissions ?? [0, ZERO_ADDRESS, false, ZERO_ADDRESS, ZERO_ADDRESS];
178
+ return { policy: s.policy, creator, authority, pendingAuthority, operator, gateMint, swapMode: SWAP_MODES[Number(mode)] ?? "open", swapExecutor, maxHarvest };
182
179
  }
183
180
  export async function describeFPool(c, s) {
184
181
  // an unseeded pool has no L: nothing earned, nothing to harvest, no pot. The bid is the
@@ -423,7 +420,7 @@ export async function fPoolLienOf(c, poolId, owner, gen) {
423
420
  */
424
421
  export async function fPoolLock(c, a) {
425
422
  const g = a.gen ?? (await fPoolGen(c, a.poolId));
426
- return writeFPool0(c, "lock", [fPoolShareId(a.poolId, g), a.owner, a.amount], a.account);
423
+ return writeFPool0(c, "lienLock", [fPoolShareId(a.poolId, g), a.owner, a.amount], a.account);
427
424
  }
428
425
  /**
429
426
  * The locker's `unlock`: `amount` of the lien lifted with its share of the lien's dividend, credited
@@ -432,7 +429,7 @@ export async function fPoolLock(c, a) {
432
429
  */
433
430
  export async function fPoolUnlock(c, a) {
434
431
  const g = a.gen ?? (await fPoolGen(c, a.poolId));
435
- return writeFPool0(c, "unlock", [fPoolShareId(a.poolId, g), a.owner, a.amount, a.to], a.account);
432
+ return writeFPool0(c, "lienUnlock", [fPoolShareId(a.poolId, g), a.owner, a.amount, a.to], a.account);
436
433
  }
437
434
  /** Bank the owner's pending into the lien now — `unlock(id, owner, 0, owner)`: dividends bank lazily. The locker's. */
438
435
  export async function fPoolBankLien(c, a) {
@@ -800,7 +797,7 @@ export async function fPoolKeyOfPool(c, poolId, opts = {}) {
800
797
  if (fPoolIdOfKey(key).toLowerCase() !== poolId.toLowerCase() && opts.salt === undefined) {
801
798
  // a pad's salt carries its split (decisions 056): rebuild it from the policy's record with the default nonce
802
799
  try {
803
- const [creatorShare] = (await c.public.readContract({ address: a.policy, abi: padPolicyAbi, functionName: "splitOf", args: [poolId] }));
800
+ const creatorShare = BigInt((await c.public.readContract({ address: a.policy, abi: padPolicyAbi, functionName: "creatorShareOf", args: [poolId] })));
804
801
  const padKey = { ...key, salt: padSalt({ creatorShare }) };
805
802
  if (fPoolIdOfKey(padKey).toLowerCase() === poolId.toLowerCase())
806
803
  return padKey;
@@ -927,7 +924,7 @@ export async function fPoolRetire(c, a) {
927
924
  * `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no treasury
928
925
  * there is no cut). `[]` when the bid is already empty. Throws on a pad (F version 21: a pad
929
926
  * never retires, whatever its bid), and when the pool's policy keeps a floor on the bid
930
- * (`PolPolicy.keepQuote`): a `retire` under that policy waits for the market.
927
+ * (`PolPolicy.minQuoteRatio`): a `retire` under that policy waits for the market.
931
928
  */
932
929
  export async function fPoolEmptyingHarvests(c, poolId) {
933
930
  const s = await getFPool(c, poolId);
@@ -1116,7 +1113,7 @@ export async function fPoolWalletBatchesAtomically(c, account) {
1116
1113
  export async function fPoolDeskOpening(c, a) {
1117
1114
  const policy = a.policy ?? fPoolPolicyFor(c, "private");
1118
1115
  return [
1119
- await fPoolSetGates(c, { poolId: a.poolId, gateMint: true, gateSwap: false, account: a.account, policy }),
1116
+ await fPoolSetMintGate(c, { poolId: a.poolId, gated: true, account: a.account, policy }),
1120
1117
  await fPoolSetMinters(c, { poolId: a.poolId, who: [a.account], allowed: true, account: a.account, policy }),
1121
1118
  ];
1122
1119
  }
@@ -1211,9 +1208,17 @@ export async function fPoolAcceptAuthority(c, a) {
1211
1208
  return writePolicy(c, fPolicyBaseAbi, a, "acceptAuthority", []);
1212
1209
  }
1213
1210
  // ─── the desk's controls (PrivatePolicy) ───────────────────────────────
1214
- /** Turn the mint / swap gates on or off (the authority, on the desk's policy). `burn` is never gated. */
1215
- export async function fPoolSetGates(c, a) {
1216
- return writePolicy(c, privatePolicyAbi, a, "setGates", [a.gateMint, a.gateSwap]);
1211
+ /**
1212
+ * Set the desk's swap admission (the authority, on the desk's policy; decision 073): `open`, `listed` (the minters and takers
1213
+ * lists) or `executor` (one address, cached on the manager, no policy call per swap). `executor` is required in `executor` mode
1214
+ * and must be omitted otherwise. Preserves mint admission. `burn` is never gated.
1215
+ */
1216
+ export async function fPoolSetSwapMode(c, a) {
1217
+ return writePolicy(c, privatePolicyAbi, a, "setSwapMode", [SWAP_MODES.indexOf(a.mode), a.executor ?? ZERO_ADDRESS]);
1218
+ }
1219
+ /** Turn mint admission on or off (the authority, on the desk's policy), preserving the swap mode and its executor. */
1220
+ export async function fPoolSetMintGate(c, a) {
1221
+ return writePolicy(c, privatePolicyAbi, a, "setMintGate", [a.gated]);
1217
1222
  }
1218
1223
  /**
1219
1224
  * Add to or remove from the pool's MINTERS — who may mint, and swap (a zap in is both under one
@@ -1285,21 +1290,17 @@ async function registryAddress(c) {
1285
1290
  throw new Error("logswap: this deployment carries no policy registry");
1286
1291
  return registry;
1287
1292
  }
1288
- /** Who runs the pool: the appointed operator, or the authority until one is. */
1289
- export function fPoolOperatorOf(s) {
1290
- return s.operator === ZERO_ADDRESS ? s.authority : s.operator;
1293
+ /** Who may run the pool (decision 073): the authority always, and the optional delegate. */
1294
+ export function fPoolRunners(s) {
1295
+ return s.operator === ZERO_ADDRESS ? [s.authority] : [s.authority, s.operator];
1291
1296
  }
1292
1297
  /**
1293
- * Propose the operator (the authority, on the desk's policy) — the hot key that runs the pool:
1294
- * `harvest`, `retire`, `regenerate`, `setLegs`. Two-step: the proposed address takes the role with
1295
- * {@link fPoolAcceptOperator}. The zero address clears at once — the role returns to the authority.
1298
+ * Grant, replace or revoke the pool operator (the authority, on the desk's policy; decision 073): one optional delegate who may
1299
+ * `harvest`, `retire`, `regenerate` and `setLegs` besides the authority. Immediate, with no acceptance step, so check the
1300
+ * address; the zero address revokes. A handover or a policy move clears it.
1296
1301
  */
1297
- export async function fPoolAppointOperator(c, a) {
1298
- return writePolicy(c, privatePolicyAbi, a, "appointOperator", [a.operator]);
1299
- }
1300
- /** The proposed operator takes the role. */
1301
- export async function fPoolAcceptOperator(c, a) {
1302
- return writePolicy(c, privatePolicyAbi, a, "acceptOperator", []);
1302
+ export async function fPoolSetPoolOperator(c, a) {
1303
+ return writePolicy(c, privatePolicyAbi, a, "setPoolOperator", [a.operator]);
1303
1304
  }
1304
1305
  /**
1305
1306
  * The next generation's composition (operator; private pools only; ONLY while the pool is
@@ -1402,29 +1403,27 @@ export async function getFPoolRules(c, s, roles) {
1402
1403
  case "pad": {
1403
1404
  // the rung is the manager's generation (F version 21): a move carries it, nothing to ask the policy
1404
1405
  const gen = s.gen;
1405
- const [split, pot, threshold, protocolNow, creatorShareMin, creatorShareMax] = await Promise.all([
1406
- rd(padPolicyAbi, "splitOf", [s.poolId]),
1406
+ const [creatorShare, pot, threshold, incomeFeeRate, creatorShareMin, creatorShareMax] = await Promise.all([
1407
+ rd(padPolicyAbi, "creatorShareOf", [s.poolId]).then(BigInt),
1407
1408
  fPoolDividendOf(c, s.poolId, DEAD_ADDRESS, gen),
1408
1409
  rd(padPolicyAbi, "threshold", [s.poolId, BigInt(gen)]),
1409
- rd(padPolicyAbi, "protocolShare"),
1410
+ rd(padPolicyAbi, "incomeFeeRate"),
1410
1411
  rd(padPolicyAbi, "creatorShareMin"),
1411
1412
  rd(padPolicyAbi, "creatorShareMax"),
1412
1413
  ]);
1413
- const [creatorShare, protocolShare] = split;
1414
- const ranges = { protocolShare: protocolNow, creatorShareMin, creatorShareMax };
1415
- return { kind: "pad", gen, rung: gen, threshold, pot, creatorShare, protocolShare, ranges };
1414
+ const ranges = { creatorShareMin, creatorShareMax };
1415
+ return { kind: "pad", gen, rung: gen, threshold, pot, creatorShare, incomeFeeRate, ranges };
1416
1416
  }
1417
1417
  case "pol": {
1418
- const [keepQuote, minQuoteAtSeed] = await Promise.all([rd(polPolicyAbi, "keepQuote"), rd(polPolicyAbi, "minQuoteAtSeed")]);
1419
- return { kind: "pol", keepQuote, minQuoteAtSeed };
1418
+ const [minQuoteRatio, incomeFeeRate] = await Promise.all([rd(polPolicyAbi, "minQuoteRatio"), rd(polPolicyAbi, "incomeFeeRate")]);
1419
+ return { kind: "pol", minQuoteRatio, incomeFeeRate };
1420
1420
  }
1421
1421
  case "public": {
1422
- const curated = await rd(publicPolicyAbi, "curated");
1423
- return { kind: "public", curated };
1422
+ return { kind: "public" };
1424
1423
  }
1425
1424
  case "private": {
1426
1425
  const r = roles ?? (await getFPoolRoles(c, s.poolId, s));
1427
- return { kind: "private", gateMint: r.gateMint, gateSwap: r.gateSwap, operator: fPoolOperatorOf(r) };
1426
+ return { kind: "private", gateMint: r.gateMint, swapMode: r.swapMode, swapExecutor: r.swapExecutor, operator: r.operator };
1428
1427
  }
1429
1428
  }
1430
1429
  }
@@ -1489,7 +1488,7 @@ export async function fPoolShareHolders(c, poolIdHex, opts = {}) {
1489
1488
  .map(([holder, shares]) => ({ holder: holder, shares }))
1490
1489
  .sort((a, b) => (b.shares > a.shares ? 1 : -1));
1491
1490
  }
1492
- /** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n, restructureTime, asks, lnCapOverFloor, Q, bigSigma, L, shares, refLogFloor). */
1491
+ /** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n, restructureTime, asks, lnCapOverFloor, Q, realizedVariance, L, shares, refLogFloor). */
1493
1492
  export async function getFPoolsRaw(c, poolIds) {
1494
1493
  const { logswapLensAbi } = await import("./generated.js");
1495
1494
  return (await c.public.readContract({ address: c.addresses.lens, abi: logswapLensAbi, functionName: "getFPools", args: [poolIds] }));