@logswap/sdk 0.5.99 → 0.5.101

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/src/fees.ts CHANGED
@@ -15,22 +15,6 @@ import { managerC, type LogswapClient } from "./client.js";
15
15
  import { managerCAbi } from "./generated.js";
16
16
  import type { DiscoveredMarket } from "./pools.js";
17
17
  import { getEventLogs } from "./history.js";
18
- import { swapFlows } from "./views.js";
19
-
20
- /** A C market's swap fees over [fromBlock, toBlock] from the indexer's swap_flow view; null when the indexer cannot answer. */
21
- async function windowFromView(c: LogswapClient, indexer: string, poolId: string, fromBlock: bigint, toBlock: bigint): Promise<{ fees: bigint; swaps: number } | null> {
22
- try {
23
- const rows = await swapFlows(indexer, {
24
- condition: { side: "C", poolId: poolId.toLowerCase(), manager: managerC(c).toLowerCase() },
25
- filter: { blockNumber: { greaterThanOrEqualTo: fromBlock.toString(), lessThanOrEqualTo: toBlock.toString() } },
26
- });
27
- let fees = 0n;
28
- for (const r of rows) fees += r.feeQuote;
29
- return { fees, swaps: rows.length };
30
- } catch {
31
- return null; // the view is a cache: the Swap rows answer the same
32
- }
33
- }
34
18
 
35
19
  const WAD = 10n ** 18n;
36
20
  const YEAR_SECONDS = 31_536_000;
@@ -127,15 +111,11 @@ export async function swapFees(
127
111
  const ev = managerCAbi.find((x): x is Ev => x.type === "event" && x.name === "Swap");
128
112
  if (!ev) throw new Error("logswap: Swap event missing from the generated ABI");
129
113
 
130
- // the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ;
131
- // the indexer's swap_flow view carries the same figure per swap (`feeQuote`, C)
114
+ // the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ
132
115
  let fees = 0n;
133
116
  let swaps = 0;
134
117
  const indexer = opts.indexer ?? c.indexerUrl;
135
- const viewed = fromBlock > toBlock || !indexer ? null : await windowFromView(c, indexer, m.poolId, fromBlock, toBlock);
136
- if (viewed) {
137
- ({ fees, swaps } = viewed);
138
- } else if (fromBlock <= toBlock) {
118
+ if (fromBlock <= toBlock) {
139
119
  const { logs } = await getEventLogs<{ fee: bigint }>(c, { indexer, address: managerC(c), event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
140
120
  for (const l of logs) fees += l.args.fee;
141
121
  swaps = logs.length;
package/src/fpool.ts CHANGED
@@ -45,10 +45,10 @@ import { managerFAbi, lensFAbi, routerFAbi, policyFAbi, policyRegistryAbi } from
45
45
  */
46
46
  export { managerFAbi, policyFAbi };
47
47
  import { clientChainId, type LogswapClient } from "./client.js";
48
+ import { FEE_LIST, FEE_LIST_BP } from "./keys.js";
48
49
  import { findQuoteResult } from "./quote.js";
49
50
  import { fallBackUnlessRejected, signerFor } from "./write.js";
50
51
  import { getEventLogs } from "./history.js";
51
- import { poolHolders } from "./views.js";
52
52
 
53
53
  const WAD = 10n ** 18n;
54
54
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
@@ -508,8 +508,9 @@ export async function fPoolMint(
508
508
  /** `maxQuoteIn` is required: the quote leg is Q·dL/L at landing, and Q moves with every swap. */
509
509
  a: { poolId: Hex; dL: bigint; maxQuoteIn: bigint; account: Address; to?: Address },
510
510
  ) {
511
- // shares go to `to` (the account by default); on a gated pool `to` must be allowed
512
- return writeFPool(c, a.poolId, "mint", [a.to ?? a.account, a.dL, a.maxQuoteIn], a.account);
511
+ // shares go to `to` (the account by default); on a gated pool `to` must be allowed. `payer` (F 42, decision 107) is the
512
+ // account the caller declares as funding the mint, read by `SharesMinted` alone: on this direct call, the sender itself.
513
+ return writeFPool(c, a.poolId, "mint", [a.account, a.to ?? a.account, a.dL, a.maxQuoteIn], a.account);
513
514
  }
514
515
 
515
516
  /**
@@ -698,13 +699,14 @@ export async function fPoolHarvest(c: LogswapClient, a: { poolId: Hex; extra?: b
698
699
  }
699
700
 
700
701
  /**
701
- * Pull one's settled dividend on a generation's shares without moving them;
702
+ * Pull an owner's settled dividend on a generation's shares without moving them;
702
703
  * anyone with shares. `gen` defaults to the live generation; a retired generation's harvests
703
- * stay claimable under its own id.
704
+ * stay claimable under its own id. By owner (F 42), as {@link fPoolBurn} and {@link fPoolRedeem}: the account claims its
705
+ * own, and an ERC-6909 operator may pass another `owner`. Paid to `to` (the account by default).
704
706
  */
705
- export async function fPoolClaim(c: LogswapClient, a: { poolId: Hex; gen?: bigint | number; to?: Address; account: Address }) {
707
+ export async function fPoolClaim(c: LogswapClient, a: { poolId: Hex; gen?: bigint | number; owner?: Address; to?: Address; account: Address }) {
706
708
  const gen = a.gen ?? (await fPoolGen(c, a.poolId));
707
- return writeFPool(c, a.poolId, "claim", [BigInt(gen), a.to ?? a.account], a.account);
709
+ return writeFPool(c, a.poolId, "claim", [BigInt(gen), a.owner ?? a.account, a.to ?? a.account], a.account);
708
710
  }
709
711
 
710
712
  /**
@@ -1093,9 +1095,9 @@ const ZERO_SALT = `0x${"0".repeat(64)}` as const;
1093
1095
  // ─── the fee list (policy.md §6) ──────────────────────────────────────────────
1094
1096
 
1095
1097
  /** `FeeParams.FEE_LIST` in bp: the eight swap fees an F pool may be born with. The key carries the index. */
1096
- export const F_FEE_LIST_BP = [1, 2, 5, 10, 20, 50, 100, 200] as const;
1098
+ export const F_FEE_LIST_BP = FEE_LIST_BP;
1097
1099
  /** The list in WAD (1 bp = 1e14). No zero: the fee-free pool cannot be born. */
1098
- export const F_FEE_LIST: readonly bigint[] = F_FEE_LIST_BP.map((bp) => BigInt(bp) * 10n ** 14n);
1100
+ export const F_FEE_LIST: readonly bigint[] = FEE_LIST;
1099
1101
 
1100
1102
  /** The fee at `idx` of the list, WAD. Throws off the list. */
1101
1103
  export function fFeeOf(idx: number): bigint {
@@ -1893,6 +1895,8 @@ export interface DiscoveredFPool {
1893
1895
  policy: Address;
1894
1896
  /** The key's salt: zero under an open policy. */
1895
1897
  salt: Hex;
1898
+ /** The account that created the pool (`PoolCreated.creator`, F 42): the one the policy judged. Not a key field. */
1899
+ creator: Address;
1896
1900
  /** The block the pool was initialized in — its age, for annualising realized income. */
1897
1901
  block: bigint;
1898
1902
  /** Whether `deployLiquidity` has run; an unfunded pool has no floor and no float, so nothing to show. */
@@ -1910,7 +1914,7 @@ export interface DiscoveredFPool {
1910
1914
 
1911
1915
  /**
1912
1916
  * Every F pool ever created, from `PoolCreated` logs alone — plus the terms of each distinct policy, read once and cached.
1913
- * Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) — the poolId is a hash and
1917
+ * Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) and the creator — the poolId is a hash and
1914
1918
  * could never be inverted; contracts PR #17 exists for exactly this call. With `indexer`, the logs come from it (the node
1915
1919
  * when it fails): a scan from block 0 per call is what made the first load wait on the node.
1916
1920
  */
@@ -1937,7 +1941,7 @@ export async function discoverFPools(
1937
1941
  }
1938
1942
  return Promise.all(
1939
1943
  logs.map(async (l) => {
1940
- const a = l.args as { poolId: Hex; quote: Address; policy: Address; bases: readonly Address[]; swapFeeIdx: number | bigint; salt: Hex };
1944
+ const a = l.args as { poolId: Hex; quote: Address; creator: Address; policy: Address; bases: readonly Address[]; swapFeeIdx: number | bigint; salt: Hex };
1941
1945
  const g0 = first.get(a.poolId.toLowerCase());
1942
1946
  const kind = await fPoolKindOfPolicy(c, a.policy); // one read per distinct policy, cached
1943
1947
  const swapFeeIdx = Number(a.swapFeeIdx);
@@ -1953,6 +1957,7 @@ export async function discoverFPools(
1953
1957
  kind,
1954
1958
  policy: a.policy,
1955
1959
  salt: a.salt,
1960
+ creator: a.creator,
1956
1961
  block: l.blockNumber,
1957
1962
  seeded: g0 !== undefined,
1958
1963
  q0: g0?.q0 ?? 0n,
@@ -2004,9 +2009,9 @@ export async function fPoolsControlledBy(
2004
2009
  /**
2005
2010
  * Every holder of a pool's shares, from the ERC-6909 Transfer stream — the id is an indexed
2006
2011
  * topic, so one filtered log query aggregates the whole ledger. The 0xdead entry is the
2007
- * MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the indexer's `pool_holder` view answers directly (the Transfer replay is the fallback) — a node
2008
- * prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
2009
- * holder minted before the cut.
2012
+ * MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the Transfer rows come from
2013
+ * its tables — a node prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
2014
+ * holder minted before the cut. (The indexer's derived views are read by the app's `@logswap/base`, not here.)
2010
2015
  */
2011
2016
  export async function fPoolShareHolders(
2012
2017
  c: LogswapClient,
@@ -2017,18 +2022,6 @@ export async function fPoolShareHolders(
2017
2022
  const ev = managerFAbi.find((x): x is Ev => x.type === "event" && x.name === "Transfer");
2018
2023
  if (!ev) throw new Error("logswap: 6909 Transfer event missing from the generated ABI");
2019
2024
  const gen = opts.gen ?? (await fPoolGen(c, poolIdHex));
2020
- const indexer = opts.indexer ?? c.indexerUrl;
2021
- if (indexer) {
2022
- try {
2023
- const rows = await poolHolders(indexer, { condition: { side: "F", poolId: poolIdHex.toLowerCase(), gen: Number(gen), manager: c.addresses.managerF.toLowerCase() } });
2024
- return rows
2025
- .filter((r) => r.balance > 0n)
2026
- .map((r) => ({ holder: r.holder, shares: r.balance }))
2027
- .sort((a, b) => (b.shares > a.shares ? 1 : -1));
2028
- } catch {
2029
- /* the view is a cache: the Transfer replay below answers the same */
2030
- }
2031
- }
2032
2025
  const id = fPoolShareId(poolIdHex, gen);
2033
2026
  const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.managerF, event: ev, args: { id }, fromBlock: opts.fromBlock });
2034
2027
  const bal = new Map<string, bigint>();