@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/README.md +104 -36
- package/dist/actions.d.ts +8 -8
- package/dist/actions.js +8 -8
- package/dist/admin.d.ts +16 -36
- package/dist/admin.js +26 -57
- package/dist/chains.d.ts +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.js +19 -3
- package/dist/fees.js +2 -24
- package/dist/fpool.d.ts +10 -6
- package/dist/fpool.js +15 -25
- package/dist/generated.d.ts +1611 -2189
- package/dist/generated.js +947 -1224
- package/dist/history.d.ts +1 -1
- package/dist/history.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/indexer.d.ts +1 -1
- package/dist/indexer.js +5 -12
- package/dist/keys.d.ts +39 -52
- package/dist/keys.js +59 -38
- package/dist/liquidity.d.ts +2 -24
- package/dist/liquidity.js +7 -33
- package/dist/pools.d.ts +23 -14
- package/dist/pools.js +36 -28
- package/dist/positions.d.ts +2 -7
- package/dist/positions.js +6 -25
- package/package.json +1 -1
- package/src/actions.ts +12 -12
- package/src/admin.ts +42 -85
- package/src/chains.ts +1 -1
- package/src/client.ts +21 -5
- package/src/fees.ts +2 -22
- package/src/fpool.ts +19 -26
- package/src/generated.ts +951 -1228
- package/src/history.ts +2 -2
- package/src/index.ts +1 -2
- package/src/indexer.ts +6 -13
- package/src/keys.ts +80 -74
- package/src/liquidity.ts +7 -47
- package/src/pools.ts +45 -33
- package/src/positions.ts +7 -27
- package/dist/views.d.ts +0 -281
- package/dist/views.js +0 -188
- package/src/views.ts +0 -480
package/dist/fees.js
CHANGED
|
@@ -13,23 +13,6 @@
|
|
|
13
13
|
import { managerC } from "./client.js";
|
|
14
14
|
import { managerCAbi } from "./generated.js";
|
|
15
15
|
import { getEventLogs } from "./history.js";
|
|
16
|
-
import { swapFlows } from "./views.js";
|
|
17
|
-
/** A C market's swap fees over [fromBlock, toBlock] from the indexer's swap_flow view; null when the indexer cannot answer. */
|
|
18
|
-
async function windowFromView(c, indexer, poolId, fromBlock, toBlock) {
|
|
19
|
-
try {
|
|
20
|
-
const rows = await swapFlows(indexer, {
|
|
21
|
-
condition: { side: "C", poolId: poolId.toLowerCase(), manager: managerC(c).toLowerCase() },
|
|
22
|
-
filter: { blockNumber: { greaterThanOrEqualTo: fromBlock.toString(), lessThanOrEqualTo: toBlock.toString() } },
|
|
23
|
-
});
|
|
24
|
-
let fees = 0n;
|
|
25
|
-
for (const r of rows)
|
|
26
|
-
fees += r.feeQuote;
|
|
27
|
-
return { fees, swaps: rows.length };
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return null; // the view is a cache: the Swap rows answer the same
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
16
|
const WAD = 10n ** 18n;
|
|
34
17
|
const YEAR_SECONDS = 31_536_000;
|
|
35
18
|
/**
|
|
@@ -106,16 +89,11 @@ export async function swapFees(c, m, opts = {}) {
|
|
|
106
89
|
const ev = managerCAbi.find((x) => x.type === "event" && x.name === "Swap");
|
|
107
90
|
if (!ev)
|
|
108
91
|
throw new Error("logswap: Swap event missing from the generated ABI");
|
|
109
|
-
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from
|
|
110
|
-
// the indexer's swap_flow view carries the same figure per swap (`feeQuote`, C)
|
|
92
|
+
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ
|
|
111
93
|
let fees = 0n;
|
|
112
94
|
let swaps = 0;
|
|
113
95
|
const indexer = opts.indexer ?? c.indexerUrl;
|
|
114
|
-
|
|
115
|
-
if (viewed) {
|
|
116
|
-
({ fees, swaps } = viewed);
|
|
117
|
-
}
|
|
118
|
-
else if (fromBlock <= toBlock) {
|
|
96
|
+
if (fromBlock <= toBlock) {
|
|
119
97
|
const { logs } = await getEventLogs(c, { indexer, address: managerC(c), event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
|
|
120
98
|
for (const l of logs)
|
|
121
99
|
fees += l.args.fee;
|
package/dist/fpool.d.ts
CHANGED
|
@@ -420,13 +420,15 @@ export declare function fPoolHarvest(c: LogswapClient, a: {
|
|
|
420
420
|
account: Address;
|
|
421
421
|
}): Promise<`0x${string}`>;
|
|
422
422
|
/**
|
|
423
|
-
* Pull
|
|
423
|
+
* Pull an owner's settled dividend on a generation's shares without moving them;
|
|
424
424
|
* anyone with shares. `gen` defaults to the live generation; a retired generation's harvests
|
|
425
|
-
* stay claimable under its own id.
|
|
425
|
+
* stay claimable under its own id. By owner (F 42), as {@link fPoolBurn} and {@link fPoolRedeem}: the account claims its
|
|
426
|
+
* own, and an ERC-6909 operator may pass another `owner`. Paid to `to` (the account by default).
|
|
426
427
|
*/
|
|
427
428
|
export declare function fPoolClaim(c: LogswapClient, a: {
|
|
428
429
|
poolId: Hex;
|
|
429
430
|
gen?: bigint | number;
|
|
431
|
+
owner?: Address;
|
|
430
432
|
to?: Address;
|
|
431
433
|
account: Address;
|
|
432
434
|
}): Promise<`0x${string}`>;
|
|
@@ -1084,6 +1086,8 @@ export interface DiscoveredFPool {
|
|
|
1084
1086
|
policy: Address;
|
|
1085
1087
|
/** The key's salt: zero under an open policy. */
|
|
1086
1088
|
salt: Hex;
|
|
1089
|
+
/** The account that created the pool (`PoolCreated.creator`, F 42): the one the policy judged. Not a key field. */
|
|
1090
|
+
creator: Address;
|
|
1087
1091
|
/** The block the pool was initialized in — its age, for annualising realized income. */
|
|
1088
1092
|
block: bigint;
|
|
1089
1093
|
/** Whether `deployLiquidity` has run; an unfunded pool has no floor and no float, so nothing to show. */
|
|
@@ -1100,7 +1104,7 @@ export interface DiscoveredFPool {
|
|
|
1100
1104
|
}
|
|
1101
1105
|
/**
|
|
1102
1106
|
* Every F pool ever created, from `PoolCreated` logs alone — plus the terms of each distinct policy, read once and cached.
|
|
1103
|
-
* Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) — the poolId is a hash and
|
|
1107
|
+
* Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) and the creator — the poolId is a hash and
|
|
1104
1108
|
* could never be inverted; contracts PR #17 exists for exactly this call. With `indexer`, the logs come from it (the node
|
|
1105
1109
|
* when it fails): a scan from block 0 per call is what made the first load wait on the node.
|
|
1106
1110
|
*/
|
|
@@ -1128,9 +1132,9 @@ export declare function fPoolsControlledBy(c: LogswapClient, who: Address, opts?
|
|
|
1128
1132
|
/**
|
|
1129
1133
|
* Every holder of a pool's shares, from the ERC-6909 Transfer stream — the id is an indexed
|
|
1130
1134
|
* topic, so one filtered log query aggregates the whole ledger. The 0xdead entry is the
|
|
1131
|
-
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the
|
|
1132
|
-
* prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1133
|
-
* holder minted before the cut.
|
|
1135
|
+
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the Transfer rows come from
|
|
1136
|
+
* its tables — a node prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1137
|
+
* holder minted before the cut. (The indexer's derived views are read by the app's `@logswap/base`, not here.)
|
|
1134
1138
|
*/
|
|
1135
1139
|
export declare function fPoolShareHolders(c: LogswapClient, poolIdHex: Hex, opts?: {
|
|
1136
1140
|
fromBlock?: bigint;
|
package/dist/fpool.js
CHANGED
|
@@ -43,10 +43,10 @@ import { managerFAbi, lensFAbi, routerFAbi, policyFAbi, policyRegistryAbi } from
|
|
|
43
43
|
*/
|
|
44
44
|
export { managerFAbi, policyFAbi };
|
|
45
45
|
import { clientChainId } from "./client.js";
|
|
46
|
+
import { FEE_LIST, FEE_LIST_BP } from "./keys.js";
|
|
46
47
|
import { findQuoteResult } from "./quote.js";
|
|
47
48
|
import { fallBackUnlessRejected, signerFor } from "./write.js";
|
|
48
49
|
import { getEventLogs } from "./history.js";
|
|
49
|
-
import { poolHolders } from "./views.js";
|
|
50
50
|
const WAD = 10n ** 18n;
|
|
51
51
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
52
52
|
/**
|
|
@@ -299,8 +299,9 @@ export async function fPoolSwapBaseForBase(c, a) {
|
|
|
299
299
|
export async function fPoolMint(c,
|
|
300
300
|
/** `maxQuoteIn` is required: the quote leg is Q·dL/L at landing, and Q moves with every swap. */
|
|
301
301
|
a) {
|
|
302
|
-
// shares go to `to` (the account by default); on a gated pool `to` must be allowed
|
|
303
|
-
|
|
302
|
+
// shares go to `to` (the account by default); on a gated pool `to` must be allowed. `payer` (F 42, decision 107) is the
|
|
303
|
+
// account the caller declares as funding the mint, read by `SharesMinted` alone: on this direct call, the sender itself.
|
|
304
|
+
return writeFPool(c, a.poolId, "mint", [a.account, a.to ?? a.account, a.dL, a.maxQuoteIn], a.account);
|
|
304
305
|
}
|
|
305
306
|
/**
|
|
306
307
|
* Burn shares for the pro-rata slice of every reserve. Available at any Q, and after dissolution.
|
|
@@ -431,13 +432,14 @@ export async function fPoolHarvest(c, a) {
|
|
|
431
432
|
return writeFPool(c, a.poolId, "harvest", [a.extra ?? 0n, a.to ?? a.account], a.account);
|
|
432
433
|
}
|
|
433
434
|
/**
|
|
434
|
-
* Pull
|
|
435
|
+
* Pull an owner's settled dividend on a generation's shares without moving them;
|
|
435
436
|
* anyone with shares. `gen` defaults to the live generation; a retired generation's harvests
|
|
436
|
-
* stay claimable under its own id.
|
|
437
|
+
* stay claimable under its own id. By owner (F 42), as {@link fPoolBurn} and {@link fPoolRedeem}: the account claims its
|
|
438
|
+
* own, and an ERC-6909 operator may pass another `owner`. Paid to `to` (the account by default).
|
|
437
439
|
*/
|
|
438
440
|
export async function fPoolClaim(c, a) {
|
|
439
441
|
const gen = a.gen ?? (await fPoolGen(c, a.poolId));
|
|
440
|
-
return writeFPool(c, a.poolId, "claim", [BigInt(gen), a.to ?? a.account], a.account);
|
|
442
|
+
return writeFPool(c, a.poolId, "claim", [BigInt(gen), a.owner ?? a.account, a.to ?? a.account], a.account);
|
|
441
443
|
}
|
|
442
444
|
/**
|
|
443
445
|
* A holder's claimable dividend as of now on generation `gen` (the live one by default) — banked
|
|
@@ -719,9 +721,9 @@ export async function fPoolQuoteSwap(c, a) {
|
|
|
719
721
|
const ZERO_SALT = `0x${"0".repeat(64)}`;
|
|
720
722
|
// ─── the fee list (policy.md §6) ──────────────────────────────────────────────
|
|
721
723
|
/** `FeeParams.FEE_LIST` in bp: the eight swap fees an F pool may be born with. The key carries the index. */
|
|
722
|
-
export const F_FEE_LIST_BP =
|
|
724
|
+
export const F_FEE_LIST_BP = FEE_LIST_BP;
|
|
723
725
|
/** The list in WAD (1 bp = 1e14). No zero: the fee-free pool cannot be born. */
|
|
724
|
-
export const F_FEE_LIST =
|
|
726
|
+
export const F_FEE_LIST = FEE_LIST;
|
|
725
727
|
/** The fee at `idx` of the list, WAD. Throws off the list. */
|
|
726
728
|
export function fFeeOf(idx) {
|
|
727
729
|
const fee = Number.isInteger(idx) ? F_FEE_LIST[idx] : undefined;
|
|
@@ -1332,7 +1334,7 @@ export async function fPoolTransferShares(c, a) {
|
|
|
1332
1334
|
}
|
|
1333
1335
|
/**
|
|
1334
1336
|
* Every F pool ever created, from `PoolCreated` logs alone — plus the terms of each distinct policy, read once and cached.
|
|
1335
|
-
* Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) — the poolId is a hash and
|
|
1337
|
+
* Possible only because the event carries the full key (quote, policy, bases, swapFeeIdx, salt) and the creator — the poolId is a hash and
|
|
1336
1338
|
* could never be inverted; contracts PR #17 exists for exactly this call. With `indexer`, the logs come from it (the node
|
|
1337
1339
|
* when it fails): a scan from block 0 per call is what made the first load wait on the node.
|
|
1338
1340
|
*/
|
|
@@ -1371,6 +1373,7 @@ export async function discoverFPools(c, opts = {}) {
|
|
|
1371
1373
|
kind,
|
|
1372
1374
|
policy: a.policy,
|
|
1373
1375
|
salt: a.salt,
|
|
1376
|
+
creator: a.creator,
|
|
1374
1377
|
block: l.blockNumber,
|
|
1375
1378
|
seeded: g0 !== undefined,
|
|
1376
1379
|
q0: g0?.q0 ?? 0n,
|
|
@@ -1400,28 +1403,15 @@ export async function fPoolsControlledBy(c, who, opts = {}) {
|
|
|
1400
1403
|
/**
|
|
1401
1404
|
* Every holder of a pool's shares, from the ERC-6909 Transfer stream — the id is an indexed
|
|
1402
1405
|
* topic, so one filtered log query aggregates the whole ledger. The 0xdead entry is the
|
|
1403
|
-
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the
|
|
1404
|
-
* prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1405
|
-
* holder minted before the cut.
|
|
1406
|
+
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: the Transfer rows come from
|
|
1407
|
+
* its tables — a node prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1408
|
+
* holder minted before the cut. (The indexer's derived views are read by the app's `@logswap/base`, not here.)
|
|
1406
1409
|
*/
|
|
1407
1410
|
export async function fPoolShareHolders(c, poolIdHex, opts = {}) {
|
|
1408
1411
|
const ev = managerFAbi.find((x) => x.type === "event" && x.name === "Transfer");
|
|
1409
1412
|
if (!ev)
|
|
1410
1413
|
throw new Error("logswap: 6909 Transfer event missing from the generated ABI");
|
|
1411
1414
|
const gen = opts.gen ?? (await fPoolGen(c, poolIdHex));
|
|
1412
|
-
const indexer = opts.indexer ?? c.indexerUrl;
|
|
1413
|
-
if (indexer) {
|
|
1414
|
-
try {
|
|
1415
|
-
const rows = await poolHolders(indexer, { condition: { side: "F", poolId: poolIdHex.toLowerCase(), gen: Number(gen), manager: c.addresses.managerF.toLowerCase() } });
|
|
1416
|
-
return rows
|
|
1417
|
-
.filter((r) => r.balance > 0n)
|
|
1418
|
-
.map((r) => ({ holder: r.holder, shares: r.balance }))
|
|
1419
|
-
.sort((a, b) => (b.shares > a.shares ? 1 : -1));
|
|
1420
|
-
}
|
|
1421
|
-
catch {
|
|
1422
|
-
/* the view is a cache: the Transfer replay below answers the same */
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
1415
|
const id = fPoolShareId(poolIdHex, gen);
|
|
1426
1416
|
const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.managerF, event: ev, args: { id }, fromBlock: opts.fromBlock });
|
|
1427
1417
|
const bal = new Map();
|