@logswap/sdk 0.5.75 → 0.5.77
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 +91 -1
- package/dist/admin.d.ts +116 -39
- package/dist/admin.js +151 -59
- package/dist/chains.d.ts +155 -0
- package/dist/chains.js +186 -0
- package/dist/client.d.ts +36 -5
- package/dist/client.js +47 -5
- package/dist/fees.d.ts +1 -1
- package/dist/fees.js +32 -7
- package/dist/fpool.d.ts +72 -46
- package/dist/fpool.js +91 -47
- package/dist/generated.d.ts +321 -271
- package/dist/generated.js +282 -243
- package/dist/history.d.ts +10 -1
- package/dist/history.js +35 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/indexer.d.ts +1 -1
- package/dist/indexer.js +1 -1
- package/dist/pools.d.ts +5 -3
- package/dist/pools.js +5 -4
- package/dist/positions.d.ts +1 -1
- package/dist/positions.js +20 -4
- package/dist/tokencache.d.ts +2 -10
- package/dist/tokencache.js +14 -6
- package/dist/views.d.ts +285 -0
- package/dist/views.js +188 -0
- package/dist/write.d.ts +2 -1
- package/dist/write.js +4 -3
- package/package.json +1 -1
- package/src/admin.ts +182 -73
- package/src/chains.ts +259 -0
- package/src/client.ts +71 -8
- package/src/fees.ts +30 -8
- package/src/fpool.ts +129 -73
- package/src/generated.ts +282 -243
- package/src/history.ts +40 -12
- package/src/index.ts +2 -0
- package/src/indexer.ts +1 -1
- package/src/pools.ts +7 -5
- package/src/positions.ts +21 -4
- package/src/tokencache.ts +15 -6
- package/src/views.ts +485 -0
- package/src/write.ts +4 -3
package/dist/fpool.d.ts
CHANGED
|
@@ -320,7 +320,7 @@ export declare const fPolicyBaseAbi: readonly [{
|
|
|
320
320
|
readonly internalType: "bytes32";
|
|
321
321
|
readonly type: "bytes32";
|
|
322
322
|
}, {
|
|
323
|
-
readonly name: "
|
|
323
|
+
readonly name: "lnCapOverFloor";
|
|
324
324
|
readonly internalType: "uint24";
|
|
325
325
|
readonly type: "uint24";
|
|
326
326
|
}];
|
|
@@ -431,10 +431,6 @@ export declare const fPolicyBaseAbi: readonly [{
|
|
|
431
431
|
readonly name: "protocolCut";
|
|
432
432
|
readonly internalType: "uint256";
|
|
433
433
|
readonly type: "uint256";
|
|
434
|
-
}, {
|
|
435
|
-
readonly name: "burn";
|
|
436
|
-
readonly internalType: "uint256";
|
|
437
|
-
readonly type: "uint256";
|
|
438
434
|
}, {
|
|
439
435
|
readonly name: "carried";
|
|
440
436
|
readonly internalType: "address";
|
|
@@ -831,7 +827,7 @@ export declare const fPolicyBaseAbi: readonly [{
|
|
|
831
827
|
}, {
|
|
832
828
|
readonly type: "error";
|
|
833
829
|
readonly inputs: readonly [];
|
|
834
|
-
readonly name: "
|
|
830
|
+
readonly name: "NotLogAuthority";
|
|
835
831
|
}, {
|
|
836
832
|
readonly type: "error";
|
|
837
833
|
readonly inputs: readonly [];
|
|
@@ -861,7 +857,7 @@ export declare const fPolicyBaseAbi: readonly [{
|
|
|
861
857
|
readonly inputs: readonly [];
|
|
862
858
|
readonly name: "Refused";
|
|
863
859
|
}];
|
|
864
|
-
import type
|
|
860
|
+
import { type LogswapClient } from "./client.js";
|
|
865
861
|
/** The optional questions a policy declared at birth, as bits of `Pool.asks`. */
|
|
866
862
|
export declare const ASK_SWAP = 1;
|
|
867
863
|
export declare const ASK_MINT = 2;
|
|
@@ -892,10 +888,11 @@ export interface FPoolState {
|
|
|
892
888
|
/** This generation's income still in the pool, quote: L·(θ₀ − θ). */
|
|
893
889
|
unharvested: bigint;
|
|
894
890
|
/**
|
|
895
|
-
* The common cap (decisions 061):
|
|
896
|
-
* 0 is uncapped. Leverage at the floor is 1/(1 − e^{−
|
|
891
|
+
* The common cap as a log distance (decisions 061): ln(cap price / floor price) in 1e-6 log units,
|
|
892
|
+
* the key's `lnCapOverFloor`; 0 is uncapped (cap ∞). Leverage at the floor is 1/(1 − e^{−value}):
|
|
893
|
+
* {@link fPoolLeverageOfCap}.
|
|
897
894
|
*/
|
|
898
|
-
|
|
895
|
+
lnCapOverFloor: number;
|
|
899
896
|
/** Σ = ∫ Σ_j w_j (dx_j)², accrued even though the fee is fixed — the kernel stays calculable. */
|
|
900
897
|
bigSigma: bigint;
|
|
901
898
|
/**
|
|
@@ -908,8 +905,8 @@ export interface FPoolState {
|
|
|
908
905
|
asks: number;
|
|
909
906
|
/** The sponsor's own label for this pool — the policy's word, mutable and never identity. "" when unnamed. */
|
|
910
907
|
name: string;
|
|
911
|
-
/** The
|
|
912
|
-
|
|
908
|
+
/** The time (unix seconds) of the last harvest / composition action: no swap runs at that timestamp (F version 29; a block number before). */
|
|
909
|
+
restructureTime: number;
|
|
913
910
|
/** What the pool is — its POLICY's self-description; see {@link FPoolKind}. */
|
|
914
911
|
kind: FPoolKind;
|
|
915
912
|
/** False before the first seed — and between a retire and the next one. */
|
|
@@ -936,7 +933,7 @@ export declare function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolSt
|
|
|
936
933
|
/**
|
|
937
934
|
* The kind of pool — the POLICY's self-description (the manager knows no kind; the
|
|
938
935
|
* policy the key names is the kind, and what it promises is its code). `public`: the protocol's
|
|
939
|
-
* own pool — its policy requires the
|
|
936
|
+
* own pool — its policy requires the LOG Authority as creator; no gate, no operator. `private`, the
|
|
940
937
|
* desk: the one whose policy may gate swaps and mints, with an operator that reshapes the legs
|
|
941
938
|
* between generations. `pol`, a treasury's pool, one base: composition and access fixed at
|
|
942
939
|
* birth. `pad`, a launch, one base: its policy answers income only at every harvest and declared
|
|
@@ -1333,10 +1330,15 @@ export interface FPoolCreateArgs {
|
|
|
1333
1330
|
*/
|
|
1334
1331
|
mintFee?: bigint;
|
|
1335
1332
|
/**
|
|
1336
|
-
* The common cap (decisions 061):
|
|
1337
|
-
* 0 or absent is uncapped.
|
|
1333
|
+
* The common cap as a log distance (decisions 061): ln(cap price / floor price) in 1e-6 log units,
|
|
1334
|
+
* the key's `lnCapOverFloor`; 0 or absent is uncapped (cap ∞). Pass `lnCapOverFloor` or `leverage`, not both.
|
|
1338
1335
|
*/
|
|
1339
|
-
|
|
1336
|
+
lnCapOverFloor?: number;
|
|
1337
|
+
/**
|
|
1338
|
+
* The leverage at the floor λ (decisions 061), converted to `lnCapOverFloor` by {@link fPoolCapOfLeverage}:
|
|
1339
|
+
* 1 is uncapped (cap ∞, `lnCapOverFloor` 0), 2 puts the cap at twice the floor price.
|
|
1340
|
+
*/
|
|
1341
|
+
leverage?: number;
|
|
1340
1342
|
/**
|
|
1341
1343
|
* Which of the protocol's four the pool is — see {@link FPoolKind}. NOT a key field (decisions
|
|
1342
1344
|
* 049: the manager knows no kind): it selects the deployment's policy of that kind when `policy`
|
|
@@ -1385,8 +1387,8 @@ export interface FPoolKey {
|
|
|
1385
1387
|
policy: Address;
|
|
1386
1388
|
creator: Address;
|
|
1387
1389
|
salt: Hex;
|
|
1388
|
-
/** The common cap,
|
|
1389
|
-
|
|
1390
|
+
/** The common cap as ln(cap price / floor price), in 1e-6 log units; 0 uncapped, cap ∞ (decisions 061). Appended in F version 25 as `cap`; renamed in F version 27 (no id moved). */
|
|
1391
|
+
lnCapOverFloor: number;
|
|
1390
1392
|
}
|
|
1391
1393
|
/**
|
|
1392
1394
|
* An F pool's id: `keccak256(abi.encode(key))`, offline — what `initialize` computes inline. The
|
|
@@ -1428,11 +1430,36 @@ export declare function fPoolReserveAt(Lj: bigint, x: bigint, k?: number): bigin
|
|
|
1428
1430
|
* 0 on an uncapped pool. Throws when the seed would be priced at or above its cap (Q0/L0 ≥ d), which
|
|
1429
1431
|
* the manager refuses.
|
|
1430
1432
|
*/
|
|
1431
|
-
export declare function fPoolCapK(
|
|
1432
|
-
/**
|
|
1433
|
+
export declare function fPoolCapK(lnCapOverFloor: number, Q0: bigint, L0: bigint): number;
|
|
1434
|
+
/**
|
|
1435
|
+
* The key's `lnCapOverFloor` = ln(cap/floor) (1e-6 log units) for a leverage λ at the floor: ln(λ/(λ − 1))
|
|
1436
|
+
* (decisions 061), so λ = 1/(1 − floor/cap) and the cap sits λ/(λ − 1) × the floor — λ = 2 puts it at twice.
|
|
1437
|
+
* **λ = 1 is uncapped**: cap ∞, `lnCapOverFloor` 0. A λ under 1, or one so close to
|
|
1438
|
+
* 1 (or so large) that d leaves a uint24 of 1e-6 units, is refused.
|
|
1439
|
+
*/
|
|
1433
1440
|
export declare function fPoolCapOfLeverage(lambda: number): number;
|
|
1434
|
-
/** The leverage at the floor λ = 1/(1 − e^{−
|
|
1435
|
-
export declare function fPoolLeverageOfCap(
|
|
1441
|
+
/** The leverage at the floor λ = 1/(1 − e^{−x}) for x = `lnCapOverFloor` (1e-6 log units); 1 for an uncapped pool (cap ∞). */
|
|
1442
|
+
export declare function fPoolLeverageOfCap(lnCapOverFloor: number): number;
|
|
1443
|
+
/** A pool's leverage, ready to tag: `capped` false and `capOverFloor` Infinity for an uncapped pool. */
|
|
1444
|
+
export interface FPoolLeverage {
|
|
1445
|
+
/** λ at the floor; exactly 1 when uncapped. */
|
|
1446
|
+
lambda: number;
|
|
1447
|
+
capped: boolean;
|
|
1448
|
+
/** The cap's price over the floor's, e^d = λ/(λ − 1): 2 at λ = 2; Infinity when uncapped. */
|
|
1449
|
+
capOverFloor: number;
|
|
1450
|
+
/** "1×" uncapped; otherwise λ to two decimals, trailing zeros dropped ("2×", "1.5×"), never "1×" for a capped pool ("1.01×" at least shown as "≈1×"). */
|
|
1451
|
+
label: string;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* The leverage tag of a pool from its key's `lnCapOverFloor` (decisions 061): `1×` means no cap — the only way a tag
|
|
1455
|
+
* reads 1× — and a capped pool always reads above it, so the two can never be confused on screen.
|
|
1456
|
+
*/
|
|
1457
|
+
export declare function fPoolLeverage(lnCapOverFloor: number): FPoolLeverage;
|
|
1458
|
+
/** The key's `lnCapOverFloor` from creation args: as given, else from `leverage`, else 0 (uncapped, cap ∞). Both given and disagreeing is refused. */
|
|
1459
|
+
export declare function fPoolCapOfArgs(a: {
|
|
1460
|
+
lnCapOverFloor?: number;
|
|
1461
|
+
leverage?: number;
|
|
1462
|
+
}): number;
|
|
1436
1463
|
/**
|
|
1437
1464
|
* Arm the pool: deposit `r0[j]` of each base plus `Q0` of quote against exposure `L0`. Pass either
|
|
1438
1465
|
* the reserves outright (`r0`) or the marks the pool should open at (`x0`, converted here with
|
|
@@ -1476,7 +1503,7 @@ export declare function fPoolRetire(c: LogswapClient, a: {
|
|
|
1476
1503
|
/**
|
|
1477
1504
|
* The harvests that empty an unlocked pool's bid, in order — what a relaunch sends before its
|
|
1478
1505
|
* `retire` (a retire needs an empty bid on every pool). Since F version 14 one
|
|
1479
|
-
* `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no
|
|
1506
|
+
* `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no treasury
|
|
1480
1507
|
* there is no cut). `[]` when the bid is already empty. Throws on a pad (F version 21: a pad
|
|
1481
1508
|
* never retires, whatever its bid), and when the pool's policy keeps a floor on the bid
|
|
1482
1509
|
* (`PolPolicy.keepQuote`): a `retire` under that policy waits for the market.
|
|
@@ -1494,11 +1521,11 @@ export declare function fPoolEmptyingHarvests(c: LogswapClient, poolId: Hex): Pr
|
|
|
1494
1521
|
* and redeems it with {@link fPoolRedeem} / rolls it with {@link fPoolRollIn} (`gen: g`); their
|
|
1495
1522
|
* dividends on `g` stay claimable ({@link fPoolClaim} with `gen: g`). {@link fPoolClaimsOf}
|
|
1496
1523
|
* lists them;
|
|
1497
|
-
* - the pot, all in quote (decisions 057): `toPayee` to the payee, `protocolCut` to the
|
|
1524
|
+
* - the pot, all in quote (decisions 057): `toPayee` to the payee, `protocolCut` to the treasury,
|
|
1498
1525
|
* `burn` spent buying base at the curve and burning it (the price up, the floor held), and the
|
|
1499
1526
|
* rest into the bid (the floor down). No share is minted; L does not move.
|
|
1500
1527
|
*
|
|
1501
|
-
* A pad's gate is `threshold(gen)
|
|
1528
|
+
* A pad's gate is `threshold(poolId, gen)`, in its quote (`PadPolicy.NotGraduated` below it); POL and private carry the
|
|
1502
1529
|
* authority and send it the whole pot; a public pool refuses (`Refused`). A carried holder with no
|
|
1503
1530
|
* share is `BadTerms`. Whoever runs the pool.
|
|
1504
1531
|
*/
|
|
@@ -1805,8 +1832,8 @@ export interface DiscoveredFPool {
|
|
|
1805
1832
|
bases: Address[];
|
|
1806
1833
|
weights: bigint[];
|
|
1807
1834
|
swapFee: bigint;
|
|
1808
|
-
/** The common cap,
|
|
1809
|
-
|
|
1835
|
+
/** The common cap as ln(cap price / floor price), in 1e-6 log units; 0 uncapped, cap ∞ (decisions 061). */
|
|
1836
|
+
lnCapOverFloor: number;
|
|
1810
1837
|
kind: FPoolKind;
|
|
1811
1838
|
/** The pool's policy AT BIRTH — the contract the key names. The LIVE one is {@link getFPool}'s `policy`: the registry's owner may have moved the pool (046, `PolicyMigrated`). */
|
|
1812
1839
|
policy: Address;
|
|
@@ -1829,7 +1856,7 @@ export interface DiscoveredFPool {
|
|
|
1829
1856
|
/**
|
|
1830
1857
|
* Every F pool ever created, from `Initialize` logs alone — plus one `kind()` read per distinct
|
|
1831
1858
|
* policy, cached. Possible only because the event carries the full key preimage (bases,
|
|
1832
|
-
* weights, swapFee, policy,
|
|
1859
|
+
* weights, swapFee, policy, lnCapOverFloor) — the poolId is a hash and could never be inverted; contracts PR #17
|
|
1833
1860
|
* exists for exactly this call. With `indexer`, the logs come from it (the node when it fails):
|
|
1834
1861
|
* a scan from block 0 per call is what made the first load wait on the node.
|
|
1835
1862
|
*/
|
|
@@ -1853,14 +1880,13 @@ export type FPoolRules = {
|
|
|
1853
1880
|
gen: number;
|
|
1854
1881
|
/** @deprecated Equal to {@link gen} since F version 21, kept for callers; read `gen`. */
|
|
1855
1882
|
rung: number;
|
|
1856
|
-
/** The pot the next graduation needs: `PadPolicy.threshold(gen)
|
|
1883
|
+
/** The pot the next graduation needs, in the pad's quote: `PadPolicy.threshold(poolId, gen)` (T(0) is per quote, decision 070). */
|
|
1857
1884
|
threshold: bigint;
|
|
1858
1885
|
pot: bigint;
|
|
1859
|
-
/** This pad's split, recorded at its birth from the key's salt and never changed (decisions 056, 057): the creator's cut of the pot
|
|
1886
|
+
/** This pad's split, recorded at its birth from the key's salt and never changed (decisions 056, 057, 067): the creator's cut of the pot and the protocol's, fractions of the pot. The rest deepens the bid; nothing is bought or burnt (067). */
|
|
1860
1887
|
creatorShare: bigint;
|
|
1861
1888
|
protocolShare: bigint;
|
|
1862
|
-
|
|
1863
|
-
/** The ranges the collector's policy holds NOW for the pads born after this read: what a new creator may choose. */
|
|
1889
|
+
/** The ranges the LOG Authority set on the policy NOW for the pads born after this read: what a new creator may choose. */
|
|
1864
1890
|
ranges: PadRanges;
|
|
1865
1891
|
} | {
|
|
1866
1892
|
kind: "pol";
|
|
@@ -1875,26 +1901,26 @@ export type FPoolRules = {
|
|
|
1875
1901
|
gateSwap: boolean;
|
|
1876
1902
|
operator: Address;
|
|
1877
1903
|
};
|
|
1878
|
-
/** The
|
|
1904
|
+
/** The LOG Authority's range on a pad's creator choice (`PadPolicy`, decisions 056, 067), WAD fractions of the pot. */
|
|
1879
1905
|
export interface PadRanges {
|
|
1880
1906
|
/** The protocol's share of the pot, recorded into each pad at birth. */
|
|
1881
1907
|
protocolShare: bigint;
|
|
1882
1908
|
creatorShareMin: bigint;
|
|
1909
|
+
/** At most the F manager's `PAYEE_CUT_MAX` (50%), which bounds a pad's payee whatever the policy (067). */
|
|
1883
1910
|
creatorShareMax: bigint;
|
|
1884
|
-
burnMin: bigint;
|
|
1885
|
-
burnMax: bigint;
|
|
1886
1911
|
}
|
|
1887
1912
|
/**
|
|
1888
|
-
* The salt that carries a pad's split (`PadPolicy.pack`, decisions 056,
|
|
1889
|
-
*
|
|
1890
|
-
*
|
|
1913
|
+
* The salt that carries a pad's split (`PadPolicy.pack(creatorShare, nonce)`, decisions 056, 067): `creatorShare` in the top 64
|
|
1914
|
+
* bits (a WAD fraction of the pot), zero in the next 64 — the burn share's place before F version 28, refused by the policy if
|
|
1915
|
+
* set — and a nonce in the low 128 that tells two otherwise identical pads apart. It is part of the pool's identity, so it is
|
|
1916
|
+
* chosen at launch (`FPoolLaunchArgs.salt`) and never changes; the policy refuses a cut outside its range.
|
|
1891
1917
|
*/
|
|
1892
1918
|
export declare function padSalt(s: {
|
|
1893
1919
|
creatorShare: bigint;
|
|
1894
|
-
|
|
1895
|
-
|
|
1920
|
+
nonce?: bigint; /** @deprecated F version 28 has no burn (067): only 0 is accepted. */
|
|
1921
|
+
burnShare?: bigint;
|
|
1896
1922
|
}): Hex;
|
|
1897
|
-
/** The inverse of {@link padSalt}. */
|
|
1923
|
+
/** The inverse of {@link padSalt}. `burnShare` is the old field's bits, nonzero only on a salt the F version 28 policy refuses. */
|
|
1898
1924
|
export declare function padSplitOfSalt(salt: Hex): {
|
|
1899
1925
|
creatorShare: bigint;
|
|
1900
1926
|
burnShare: bigint;
|
|
@@ -1914,7 +1940,7 @@ export declare function fPoolsControlledBy(c: LogswapClient, who: Address, opts?
|
|
|
1914
1940
|
/**
|
|
1915
1941
|
* Every holder of a pool's shares, from the ERC-6909 Transfer stream — the id is an indexed
|
|
1916
1942
|
* topic, so one filtered log query aggregates the whole ledger. The 0xdead entry is the
|
|
1917
|
-
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: a node
|
|
1943
|
+
* 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
|
|
1918
1944
|
* prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1919
1945
|
* holder minted before the cut.
|
|
1920
1946
|
*/
|
|
@@ -1927,17 +1953,17 @@ export declare function fPoolShareHolders(c: LogswapClient, poolIdHex: Hex, opts
|
|
|
1927
1953
|
shares: bigint;
|
|
1928
1954
|
}>>;
|
|
1929
1955
|
/**
|
|
1930
|
-
* What a policy answers `onRegenerate` with: `IFPolicy.Terms
|
|
1931
|
-
* carries beside the dead shares;
|
|
1956
|
+
* What a policy answers `onRegenerate` with: `IFPolicy.Terms` — four words, exactly 128 bytes since F version 28 (decision 067
|
|
1957
|
+
* removed `burn`). `carried` is the holder the next generation carries beside the dead shares; on a pad the manager requires
|
|
1958
|
+
* `0xdead` and caps `toPayee` at `PAYEE_CUT_MAX` of the pot.
|
|
1932
1959
|
*/
|
|
1933
1960
|
export interface FPolicyTerms {
|
|
1934
1961
|
payee: Address;
|
|
1935
1962
|
toPayee: bigint;
|
|
1936
1963
|
protocolCut: bigint;
|
|
1937
|
-
burn: bigint;
|
|
1938
1964
|
carried: Address;
|
|
1939
1965
|
}
|
|
1940
|
-
/** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n,
|
|
1966
|
+
/** 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). */
|
|
1941
1967
|
export declare function getFPoolsRaw(c: LogswapClient, poolIds: Hex[]): Promise<readonly unknown[]>;
|
|
1942
1968
|
/** Share value from the lens — (L + Q)/shares, WAD per share — the same figure as `fPoolShareValue`, from one source. */
|
|
1943
1969
|
export declare function shareValueOnChain(c: LogswapClient, poolId: Hex): Promise<bigint>;
|
package/dist/fpool.js
CHANGED
|
@@ -45,8 +45,10 @@ export { fPoolManagerAbi, padPolicyAbi, polPolicyAbi, privatePolicyAbi, publicPo
|
|
|
45
45
|
* in for the base — a call through it to any of the four policies decodes the base's functions.
|
|
46
46
|
*/
|
|
47
47
|
export const fPolicyBaseAbi = polPolicyAbi;
|
|
48
|
+
import { clientChainId } from "./client.js";
|
|
48
49
|
import { fallBackUnlessRejected, signerFor } from "./write.js";
|
|
49
50
|
import { getEventLogs } from "./history.js";
|
|
51
|
+
import { poolHolders } from "./views.js";
|
|
50
52
|
import { presetMintFee } from "./positions.js";
|
|
51
53
|
const WAD = 10n ** 18n;
|
|
52
54
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
@@ -99,12 +101,12 @@ export async function getFPool(c, poolId) {
|
|
|
99
101
|
logFloor: v.logFloor,
|
|
100
102
|
compositeX: v.compositeX,
|
|
101
103
|
unharvested: v.unharvested,
|
|
102
|
-
|
|
104
|
+
lnCapOverFloor: Number(p.lnCapOverFloor),
|
|
103
105
|
bigSigma: p.bigSigma,
|
|
104
106
|
policy: p.policy,
|
|
105
107
|
asks: Number(p.asks),
|
|
106
108
|
name,
|
|
107
|
-
|
|
109
|
+
restructureTime: Number(p.restructureTime),
|
|
108
110
|
kind,
|
|
109
111
|
seeded: p.seeded,
|
|
110
112
|
gen: Number(p.gen),
|
|
@@ -123,8 +125,9 @@ const kindCache = new Map();
|
|
|
123
125
|
* chain: a pool's kind is its policy's word, never the manager's. An unknown tag
|
|
124
126
|
* (a policy that is not one of the protocol's four shapes) throws; the app has no screen for it.
|
|
125
127
|
*/
|
|
126
|
-
export function fPoolKindOfPolicy(c, policy) {
|
|
127
|
-
|
|
128
|
+
export async function fPoolKindOfPolicy(c, policy) {
|
|
129
|
+
// the chain id is part of the key: the policies sit at one address on every release chain
|
|
130
|
+
const key = `${await clientChainId(c)}:${policy.toLowerCase()}`;
|
|
128
131
|
let hit = kindCache.get(key);
|
|
129
132
|
if (!hit) {
|
|
130
133
|
hit = c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "kind" }).then((word) => {
|
|
@@ -205,7 +208,7 @@ export function fPoolShareValue(s) {
|
|
|
205
208
|
if (s.totalSupply === 0n)
|
|
206
209
|
return 0n;
|
|
207
210
|
let v = s.L + s.Q;
|
|
208
|
-
if (s.
|
|
211
|
+
if (s.lnCapOverFloor !== 0) {
|
|
209
212
|
v = s.Q;
|
|
210
213
|
for (let j = 0; j < s.reserves.length; j++) {
|
|
211
214
|
const rv = s.virtualReserves[j];
|
|
@@ -721,7 +724,7 @@ const F_POOL_KEY_ABI = [
|
|
|
721
724
|
{ name: "policy", type: "address" },
|
|
722
725
|
{ name: "creator", type: "address" },
|
|
723
726
|
{ name: "salt", type: "bytes32" },
|
|
724
|
-
{ name: "
|
|
727
|
+
{ name: "lnCapOverFloor", type: "uint24" },
|
|
725
728
|
],
|
|
726
729
|
},
|
|
727
730
|
];
|
|
@@ -744,7 +747,7 @@ export function fPoolKeyOf(c, a) {
|
|
|
744
747
|
policy: a.policy ?? fPoolPolicyFor(c, a.kind),
|
|
745
748
|
creator: a.creator,
|
|
746
749
|
salt: a.salt ?? ZERO_SALT,
|
|
747
|
-
|
|
750
|
+
lnCapOverFloor: fPoolCapOfArgs(a),
|
|
748
751
|
};
|
|
749
752
|
}
|
|
750
753
|
/** Create the pool (no funds move — `seed` arms it). Returns the tx hash; read the id with `fPoolIdOf`. */
|
|
@@ -779,7 +782,7 @@ export async function fPoolIdOf(c, a) {
|
|
|
779
782
|
*/
|
|
780
783
|
export async function fPoolKeyOfPool(c, poolId, opts = {}) {
|
|
781
784
|
const ev = fPoolManagerAbi.find((x) => x.type === "event" && x.name === "FInitialize");
|
|
782
|
-
const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager, event: ev, args: { poolId }, fromBlock: opts.fromBlock
|
|
785
|
+
const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager, event: ev, args: { poolId }, fromBlock: opts.fromBlock });
|
|
783
786
|
const l = logs[0];
|
|
784
787
|
if (!l)
|
|
785
788
|
throw new Error(`logswap: no FInitialize for F pool ${poolId}`);
|
|
@@ -792,13 +795,13 @@ export async function fPoolKeyOfPool(c, poolId, opts = {}) {
|
|
|
792
795
|
policy: a.policy,
|
|
793
796
|
creator: a.creator,
|
|
794
797
|
salt: opts.salt ?? ZERO_SALT,
|
|
795
|
-
|
|
798
|
+
lnCapOverFloor: Number(a.lnCapOverFloor ?? a.cap ?? 0), // `cap` before F version 27
|
|
796
799
|
};
|
|
797
800
|
if (fPoolIdOfKey(key).toLowerCase() !== poolId.toLowerCase() && opts.salt === undefined) {
|
|
798
801
|
// a pad's salt carries its split (decisions 056): rebuild it from the policy's record with the default nonce
|
|
799
802
|
try {
|
|
800
|
-
const [creatorShare
|
|
801
|
-
const padKey = { ...key, salt: padSalt({ creatorShare
|
|
803
|
+
const [creatorShare] = (await c.public.readContract({ address: a.policy, abi: padPolicyAbi, functionName: "splitOf", args: [poolId] }));
|
|
804
|
+
const padKey = { ...key, salt: padSalt({ creatorShare }) };
|
|
802
805
|
if (fPoolIdOfKey(padKey).toLowerCase() === poolId.toLowerCase())
|
|
803
806
|
return padKey;
|
|
804
807
|
}
|
|
@@ -829,26 +832,52 @@ export function fPoolReserveAt(Lj, x, k = 0) {
|
|
|
829
832
|
* 0 on an uncapped pool. Throws when the seed would be priced at or above its cap (Q0/L0 ≥ d), which
|
|
830
833
|
* the manager refuses.
|
|
831
834
|
*/
|
|
832
|
-
export function fPoolCapK(
|
|
833
|
-
if (
|
|
835
|
+
export function fPoolCapK(lnCapOverFloor, Q0, L0) {
|
|
836
|
+
if (lnCapOverFloor === 0)
|
|
834
837
|
return 0;
|
|
835
|
-
const e = Number((Q0 * WAD) / L0) / 1e18 -
|
|
838
|
+
const e = Number((Q0 * WAD) / L0) / 1e18 - lnCapOverFloor / 1e6;
|
|
836
839
|
if (e >= 0)
|
|
837
|
-
throw new Error(`logswap: a seed with Q0/L0 = ${Number((Q0 * WAD) / L0) / 1e18} is at or above its cap
|
|
840
|
+
throw new Error(`logswap: a seed with Q0/L0 = ${Number((Q0 * WAD) / L0) / 1e18} is at or above its cap, ln(cap/floor) = ${lnCapOverFloor / 1e6}`);
|
|
838
841
|
return Math.exp(e);
|
|
839
842
|
}
|
|
840
|
-
/**
|
|
843
|
+
/**
|
|
844
|
+
* The key's `lnCapOverFloor` = ln(cap/floor) (1e-6 log units) for a leverage λ at the floor: ln(λ/(λ − 1))
|
|
845
|
+
* (decisions 061), so λ = 1/(1 − floor/cap) and the cap sits λ/(λ − 1) × the floor — λ = 2 puts it at twice.
|
|
846
|
+
* **λ = 1 is uncapped**: cap ∞, `lnCapOverFloor` 0. A λ under 1, or one so close to
|
|
847
|
+
* 1 (or so large) that d leaves a uint24 of 1e-6 units, is refused.
|
|
848
|
+
*/
|
|
841
849
|
export function fPoolCapOfLeverage(lambda) {
|
|
842
|
-
if (
|
|
843
|
-
|
|
850
|
+
if (lambda === 1)
|
|
851
|
+
return 0;
|
|
852
|
+
if (!(lambda > 1) || !Number.isFinite(lambda))
|
|
853
|
+
throw new Error(`logswap: leverage must be 1 (uncapped) or a finite number above 1, got ${lambda}`);
|
|
844
854
|
const d = Math.round(Math.log(lambda / (lambda - 1)) * 1e6);
|
|
845
855
|
if (d < 1 || d > 0xffffff)
|
|
846
856
|
throw new Error(`logswap: leverage ${lambda} needs a cap outside a uint24 of 1e-6 units`);
|
|
847
857
|
return d;
|
|
848
858
|
}
|
|
849
|
-
/** The leverage at the floor λ = 1/(1 − e^{−
|
|
850
|
-
export function fPoolLeverageOfCap(
|
|
851
|
-
return
|
|
859
|
+
/** The leverage at the floor λ = 1/(1 − e^{−x}) for x = `lnCapOverFloor` (1e-6 log units); 1 for an uncapped pool (cap ∞). */
|
|
860
|
+
export function fPoolLeverageOfCap(lnCapOverFloor) {
|
|
861
|
+
return lnCapOverFloor === 0 ? 1 : 1 / (1 - Math.exp(-lnCapOverFloor / 1e6));
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* The leverage tag of a pool from its key's `lnCapOverFloor` (decisions 061): `1×` means no cap — the only way a tag
|
|
865
|
+
* reads 1× — and a capped pool always reads above it, so the two can never be confused on screen.
|
|
866
|
+
*/
|
|
867
|
+
export function fPoolLeverage(lnCapOverFloor) {
|
|
868
|
+
if (lnCapOverFloor === 0)
|
|
869
|
+
return { lambda: 1, capped: false, capOverFloor: Infinity, label: "1×" };
|
|
870
|
+
const lambda = fPoolLeverageOfCap(lnCapOverFloor);
|
|
871
|
+
const rounded = Math.round(lambda * 100) / 100;
|
|
872
|
+
const label = rounded <= 1 ? "≈1×" : `${String(rounded)}×`;
|
|
873
|
+
return { lambda, capped: true, capOverFloor: Math.exp(lnCapOverFloor / 1e6), label };
|
|
874
|
+
}
|
|
875
|
+
/** The key's `lnCapOverFloor` from creation args: as given, else from `leverage`, else 0 (uncapped, cap ∞). Both given and disagreeing is refused. */
|
|
876
|
+
export function fPoolCapOfArgs(a) {
|
|
877
|
+
const fromLeverage = a.leverage === undefined ? undefined : fPoolCapOfLeverage(a.leverage);
|
|
878
|
+
if (a.lnCapOverFloor !== undefined && fromLeverage !== undefined && a.lnCapOverFloor !== fromLeverage)
|
|
879
|
+
throw new Error(`logswap: lnCapOverFloor ${a.lnCapOverFloor} and leverage ${a.leverage} (${fromLeverage}) disagree — pass one`);
|
|
880
|
+
return a.lnCapOverFloor ?? fromLeverage ?? 0;
|
|
852
881
|
}
|
|
853
882
|
/**
|
|
854
883
|
* Arm the pool: deposit `r0[j]` of each base plus `Q0` of quote against exposure `L0`. Pass either
|
|
@@ -862,7 +891,7 @@ export async function fPoolSeed(c, a) {
|
|
|
862
891
|
if ("r0" in a)
|
|
863
892
|
r0 = a.r0;
|
|
864
893
|
else {
|
|
865
|
-
const k = fPoolCapK(Number((await rawFPool(c, a.poolId)).
|
|
894
|
+
const k = fPoolCapK(Number((await rawFPool(c, a.poolId)).lnCapOverFloor), a.Q0, a.L0);
|
|
866
895
|
r0 = a.x0.map((x, j) => fPoolReserveAt((a.weights[j] * a.L0) / 10n ** 18n, x, k));
|
|
867
896
|
}
|
|
868
897
|
return writeFPool(c, a.poolId, "seed", [a.L0, r0, a.Q0], a.account);
|
|
@@ -895,7 +924,7 @@ export async function fPoolRetire(c, a) {
|
|
|
895
924
|
/**
|
|
896
925
|
* The harvests that empty an unlocked pool's bid, in order — what a relaunch sends before its
|
|
897
926
|
* `retire` (a retire needs an empty bid on every pool). Since F version 14 one
|
|
898
|
-
* `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no
|
|
927
|
+
* `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no treasury
|
|
899
928
|
* there is no cut). `[]` when the bid is already empty. Throws on a pad (F version 21: a pad
|
|
900
929
|
* never retires, whatever its bid), and when the pool's policy keeps a floor on the bid
|
|
901
930
|
* (`PolPolicy.keepQuote`): a `retire` under that policy waits for the market.
|
|
@@ -925,11 +954,11 @@ export async function fPoolEmptyingHarvests(c, poolId) {
|
|
|
925
954
|
* and redeems it with {@link fPoolRedeem} / rolls it with {@link fPoolRollIn} (`gen: g`); their
|
|
926
955
|
* dividends on `g` stay claimable ({@link fPoolClaim} with `gen: g`). {@link fPoolClaimsOf}
|
|
927
956
|
* lists them;
|
|
928
|
-
* - the pot, all in quote (decisions 057): `toPayee` to the payee, `protocolCut` to the
|
|
957
|
+
* - the pot, all in quote (decisions 057): `toPayee` to the payee, `protocolCut` to the treasury,
|
|
929
958
|
* `burn` spent buying base at the curve and burning it (the price up, the floor held), and the
|
|
930
959
|
* rest into the bid (the floor down). No share is minted; L does not move.
|
|
931
960
|
*
|
|
932
|
-
* A pad's gate is `threshold(gen)
|
|
961
|
+
* A pad's gate is `threshold(poolId, gen)`, in its quote (`PadPolicy.NotGraduated` below it); POL and private carry the
|
|
933
962
|
* authority and send it the whole pot; a public pool refuses (`Refused`). A carried holder with no
|
|
934
963
|
* share is `BadTerms`. Whoever runs the pool.
|
|
935
964
|
*/
|
|
@@ -951,7 +980,7 @@ export async function fPoolRegenerate(c, a) {
|
|
|
951
980
|
export async function fPoolRelaunch(c, a) {
|
|
952
981
|
const [raw, harvests] = await Promise.all([rawFPool(c, a.poolId), fPoolEmptyingHarvests(c, a.poolId)]);
|
|
953
982
|
const gen = Number(raw.gen);
|
|
954
|
-
const k = "r0" in a ? 0 : fPoolCapK(Number(raw.
|
|
983
|
+
const k = "r0" in a ? 0 : fPoolCapK(Number(raw.lnCapOverFloor), a.Q0, a.L0);
|
|
955
984
|
const r0 = "r0" in a ? a.r0 : a.x0.map((x, j) => (a.weights[j] === 0n ? 0n : fPoolReserveAt((a.weights[j] * a.L0) / WAD, x, k)));
|
|
956
985
|
const enc = (functionName, args) => encodeFunctionData({ abi: fPoolManagerAbi, functionName, args });
|
|
957
986
|
const calls = [
|
|
@@ -978,14 +1007,14 @@ export function fPoolLaunchCalls(poolId, a) {
|
|
|
978
1007
|
const sum = a.weights.reduce((x, y) => x + y, 0n);
|
|
979
1008
|
if (sum !== WAD)
|
|
980
1009
|
throw new Error(`logswap: weights sum to ${sum}, expected 1e18`);
|
|
981
|
-
const k = "r0" in a ? 0 : fPoolCapK(a
|
|
1010
|
+
const k = "r0" in a ? 0 : fPoolCapK(fPoolCapOfArgs(a), a.Q0, a.L0);
|
|
982
1011
|
const given = "r0" in a ? a.r0 : a.x0.map((x, j) => fPoolReserveAt((a.weights[j] * a.L0) / WAD, x, k));
|
|
983
1012
|
if (given.length !== a.bases.length)
|
|
984
1013
|
throw new Error(`logswap: ${given.length} reserves for ${a.bases.length} legs`);
|
|
985
1014
|
const { bases, companions } = sortFPoolLegs(a.bases, a.weights, given);
|
|
986
1015
|
if (!a.policy)
|
|
987
1016
|
throw new Error("logswap: fPoolLaunchCalls needs the key's policy — fPoolLaunch fills it from the deployment");
|
|
988
|
-
const key = { quote: a.quote, bases, weights: companions[0], swapFee: a.swapFee, policy: a.policy, creator: a.creator, salt: a.salt ?? ZERO_SALT,
|
|
1017
|
+
const key = { quote: a.quote, bases, weights: companions[0], swapFee: a.swapFee, policy: a.policy, creator: a.creator, salt: a.salt ?? ZERO_SALT, lnCapOverFloor: fPoolCapOfArgs(a) };
|
|
989
1018
|
const enc = (functionName, args) => encodeFunctionData({ abi: fPoolManagerAbi, functionName, args });
|
|
990
1019
|
const calls = [];
|
|
991
1020
|
if (!a.initialized)
|
|
@@ -1303,7 +1332,7 @@ export async function fPoolTransferShares(c, a) {
|
|
|
1303
1332
|
/**
|
|
1304
1333
|
* Every F pool ever created, from `Initialize` logs alone — plus one `kind()` read per distinct
|
|
1305
1334
|
* policy, cached. Possible only because the event carries the full key preimage (bases,
|
|
1306
|
-
* weights, swapFee, policy,
|
|
1335
|
+
* weights, swapFee, policy, lnCapOverFloor) — the poolId is a hash and could never be inverted; contracts PR #17
|
|
1307
1336
|
* exists for exactly this call. With `indexer`, the logs come from it (the node when it fails):
|
|
1308
1337
|
* a scan from block 0 per call is what made the first load wait on the node.
|
|
1309
1338
|
*/
|
|
@@ -1332,7 +1361,7 @@ export async function discoverFPools(c, opts = {}) {
|
|
|
1332
1361
|
bases: [...a.bases],
|
|
1333
1362
|
weights: [...a.weights],
|
|
1334
1363
|
swapFee: a.swapFee,
|
|
1335
|
-
|
|
1364
|
+
lnCapOverFloor: Number(a.lnCapOverFloor ?? a.cap ?? 0), // `cap` before F version 27
|
|
1336
1365
|
kind,
|
|
1337
1366
|
policy: a.policy,
|
|
1338
1367
|
creator: a.creator,
|
|
@@ -1346,19 +1375,22 @@ export async function discoverFPools(c, opts = {}) {
|
|
|
1346
1375
|
const MAX_U64 = (1n << 64n) - 1n;
|
|
1347
1376
|
const MAX_U128 = (1n << 128n) - 1n;
|
|
1348
1377
|
/**
|
|
1349
|
-
* The salt that carries a pad's split (`PadPolicy.pack`, decisions 056,
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1378
|
+
* The salt that carries a pad's split (`PadPolicy.pack(creatorShare, nonce)`, decisions 056, 067): `creatorShare` in the top 64
|
|
1379
|
+
* bits (a WAD fraction of the pot), zero in the next 64 — the burn share's place before F version 28, refused by the policy if
|
|
1380
|
+
* set — and a nonce in the low 128 that tells two otherwise identical pads apart. It is part of the pool's identity, so it is
|
|
1381
|
+
* chosen at launch (`FPoolLaunchArgs.salt`) and never changes; the policy refuses a cut outside its range.
|
|
1352
1382
|
*/
|
|
1353
1383
|
export function padSalt(s) {
|
|
1354
1384
|
const nonce = s.nonce ?? 0n;
|
|
1355
|
-
if (s.
|
|
1356
|
-
throw new Error("logswap: a pad
|
|
1385
|
+
if (s.burnShare !== undefined && s.burnShare !== 0n)
|
|
1386
|
+
throw new Error("logswap: a pad has no burn share since F version 28 (decision 067)");
|
|
1387
|
+
if (s.creatorShare < 0n || s.creatorShare > MAX_U64)
|
|
1388
|
+
throw new Error("logswap: a pad's creator share is a WAD fraction that fits 64 bits");
|
|
1357
1389
|
if (nonce < 0n || nonce > MAX_U128)
|
|
1358
1390
|
throw new Error("logswap: a pad salt's nonce fits 128 bits");
|
|
1359
|
-
return `0x${((s.creatorShare << 192n) |
|
|
1391
|
+
return `0x${((s.creatorShare << 192n) | nonce).toString(16).padStart(64, "0")}`;
|
|
1360
1392
|
}
|
|
1361
|
-
/** The inverse of {@link padSalt}. */
|
|
1393
|
+
/** The inverse of {@link padSalt}. `burnShare` is the old field's bits, nonzero only on a salt the F version 28 policy refuses. */
|
|
1362
1394
|
export function padSplitOfSalt(salt) {
|
|
1363
1395
|
const v = BigInt(salt);
|
|
1364
1396
|
return { creatorShare: v >> 192n, burnShare: (v >> 128n) & MAX_U64, nonce: v & MAX_U128 };
|
|
@@ -1370,19 +1402,17 @@ export async function getFPoolRules(c, s, roles) {
|
|
|
1370
1402
|
case "pad": {
|
|
1371
1403
|
// the rung is the manager's generation (F version 21): a move carries it, nothing to ask the policy
|
|
1372
1404
|
const gen = s.gen;
|
|
1373
|
-
const [split, pot, threshold, protocolNow, creatorShareMin, creatorShareMax
|
|
1405
|
+
const [split, pot, threshold, protocolNow, creatorShareMin, creatorShareMax] = await Promise.all([
|
|
1374
1406
|
rd(padPolicyAbi, "splitOf", [s.poolId]),
|
|
1375
1407
|
fPoolDividendOf(c, s.poolId, DEAD_ADDRESS, gen),
|
|
1376
|
-
rd(padPolicyAbi, "threshold", [BigInt(gen)]),
|
|
1408
|
+
rd(padPolicyAbi, "threshold", [s.poolId, BigInt(gen)]),
|
|
1377
1409
|
rd(padPolicyAbi, "protocolShare"),
|
|
1378
1410
|
rd(padPolicyAbi, "creatorShareMin"),
|
|
1379
1411
|
rd(padPolicyAbi, "creatorShareMax"),
|
|
1380
|
-
rd(padPolicyAbi, "burnMin"),
|
|
1381
|
-
rd(padPolicyAbi, "burnMax"),
|
|
1382
1412
|
]);
|
|
1383
|
-
const [creatorShare,
|
|
1384
|
-
const ranges = { protocolShare: protocolNow, creatorShareMin, creatorShareMax
|
|
1385
|
-
return { kind: "pad", gen, rung: gen, threshold, pot, creatorShare, protocolShare,
|
|
1413
|
+
const [creatorShare, protocolShare] = split;
|
|
1414
|
+
const ranges = { protocolShare: protocolNow, creatorShareMin, creatorShareMax };
|
|
1415
|
+
return { kind: "pad", gen, rung: gen, threshold, pot, creatorShare, protocolShare, ranges };
|
|
1386
1416
|
}
|
|
1387
1417
|
case "pol": {
|
|
1388
1418
|
const [keepQuote, minQuoteAtSeed] = await Promise.all([rd(polPolicyAbi, "keepQuote"), rd(polPolicyAbi, "minQuoteAtSeed")]);
|
|
@@ -1422,7 +1452,7 @@ export async function fPoolsControlledBy(c, who, opts = {}) {
|
|
|
1422
1452
|
/**
|
|
1423
1453
|
* Every holder of a pool's shares, from the ERC-6909 Transfer stream — the id is an indexed
|
|
1424
1454
|
* topic, so one filtered log query aggregates the whole ledger. The 0xdead entry is the
|
|
1425
|
-
* MIN_SHARES lock from seeding; callers usually label rather than hide it. Pass `indexer`: a node
|
|
1455
|
+
* 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
|
|
1426
1456
|
* prunes its logs (anvil keeps about a day), and a ledger rebuilt from a pruned stream loses every
|
|
1427
1457
|
* holder minted before the cut.
|
|
1428
1458
|
*/
|
|
@@ -1430,7 +1460,21 @@ export async function fPoolShareHolders(c, poolIdHex, opts = {}) {
|
|
|
1430
1460
|
const ev = fPoolManagerAbi.find((x) => x.type === "event" && x.name === "Transfer");
|
|
1431
1461
|
if (!ev)
|
|
1432
1462
|
throw new Error("logswap: 6909 Transfer event missing from the generated ABI");
|
|
1433
|
-
const
|
|
1463
|
+
const gen = opts.gen ?? (await fPoolGen(c, poolIdHex));
|
|
1464
|
+
const indexer = opts.indexer ?? c.indexerUrl;
|
|
1465
|
+
if (indexer) {
|
|
1466
|
+
try {
|
|
1467
|
+
const rows = await poolHolders(indexer, { condition: { side: "F", poolId: poolIdHex.toLowerCase(), gen: Number(gen), manager: c.addresses.fPoolManager.toLowerCase() } });
|
|
1468
|
+
return rows
|
|
1469
|
+
.filter((r) => r.balance > 0n)
|
|
1470
|
+
.map((r) => ({ holder: r.holder, shares: r.balance }))
|
|
1471
|
+
.sort((a, b) => (b.shares > a.shares ? 1 : -1));
|
|
1472
|
+
}
|
|
1473
|
+
catch {
|
|
1474
|
+
/* the view is a cache: the Transfer replay below answers the same */
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
const id = fPoolShareId(poolIdHex, gen);
|
|
1434
1478
|
const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager, event: ev, args: { id }, fromBlock: opts.fromBlock });
|
|
1435
1479
|
const bal = new Map();
|
|
1436
1480
|
for (const l of logs) {
|
|
@@ -1445,7 +1489,7 @@ export async function fPoolShareHolders(c, poolIdHex, opts = {}) {
|
|
|
1445
1489
|
.map(([holder, shares]) => ({ holder: holder, shares }))
|
|
1446
1490
|
.sort((a, b) => (b.shares > a.shares ? 1 : -1));
|
|
1447
1491
|
}
|
|
1448
|
-
/** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n,
|
|
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). */
|
|
1449
1493
|
export async function getFPoolsRaw(c, poolIds) {
|
|
1450
1494
|
const { logswapLensAbi } = await import("./generated.js");
|
|
1451
1495
|
return (await c.public.readContract({ address: c.addresses.lens, abi: logswapLensAbi, functionName: "getFPools", args: [poolIds] }));
|