@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/chains.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chains.ts — the chains log(swap) runs on, and their deployments.
|
|
3
|
+
*
|
|
4
|
+
* The release chains carry the contracts at ONE address each (CREATE3 through CreateX, contracts
|
|
5
|
+
* decision 069): the same `LogswapAddresses` on every chain. What differs per chain is the deploy
|
|
6
|
+
* block, the quote tokens, the explorer and the indexer. An address therefore names a contract only
|
|
7
|
+
* together with a chain id; every cache and every indexer URL in this SDK is per chain.
|
|
8
|
+
*/
|
|
9
|
+
import { defineChain, getAddress, isAddress } from "viem";
|
|
10
|
+
import { arbitrum, base, foundry, mainnet, robinhood, robinhoodTestnet } from "viem/chains";
|
|
11
|
+
/** The logswap devnet (anvil, persisted with `--state`). No public RPC. */
|
|
12
|
+
export const logswapDevnet = defineChain({
|
|
13
|
+
id: 31339,
|
|
14
|
+
name: "log(swap) devnet",
|
|
15
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
16
|
+
rpcUrls: { default: { http: [] } },
|
|
17
|
+
testnet: true,
|
|
18
|
+
});
|
|
19
|
+
/** Default block span per `eth_getLogs` call: public endpoints refuse wider ranges (or cap the result). */
|
|
20
|
+
export const DEFAULT_MAX_LOG_RANGE = 2000n;
|
|
21
|
+
/** A local node answers any range. */
|
|
22
|
+
const LOCAL_MAX_LOG_RANGE = 1000000n;
|
|
23
|
+
const USDC = (address) => ({ symbol: "USDC", address, decimals: 6 });
|
|
24
|
+
const WETH = (address) => ({ symbol: "WETH", address, decimals: 18 });
|
|
25
|
+
function entry(chain, e) {
|
|
26
|
+
return {
|
|
27
|
+
chainId: chain.id,
|
|
28
|
+
name: chain.name,
|
|
29
|
+
chain,
|
|
30
|
+
nativeCurrency: chain.nativeCurrency,
|
|
31
|
+
testnet: chain.testnet ?? false,
|
|
32
|
+
maxLogRange: DEFAULT_MAX_LOG_RANGE,
|
|
33
|
+
...e,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Every chain this SDK knows, by chain id. */
|
|
37
|
+
export const LOGSWAP_CHAINS = Object.freeze({
|
|
38
|
+
1: entry(mainnet, {
|
|
39
|
+
network: "mainnet",
|
|
40
|
+
explorer: "https://etherscan.io",
|
|
41
|
+
publicRpc: "https://ethereum-rpc.publicnode.com",
|
|
42
|
+
devnet: false,
|
|
43
|
+
quotes: [USDC("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"), WETH("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")],
|
|
44
|
+
padQuote: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
45
|
+
}),
|
|
46
|
+
8453: entry(base, {
|
|
47
|
+
network: "base",
|
|
48
|
+
explorer: "https://basescan.org",
|
|
49
|
+
publicRpc: "https://mainnet.base.org",
|
|
50
|
+
devnet: false,
|
|
51
|
+
quotes: [USDC("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), WETH("0x4200000000000000000000000000000000000006")],
|
|
52
|
+
padQuote: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
53
|
+
}),
|
|
54
|
+
42161: entry(arbitrum, {
|
|
55
|
+
network: "arbitrum",
|
|
56
|
+
explorer: "https://arbiscan.io",
|
|
57
|
+
publicRpc: "https://arb1.arbitrum.io/rpc",
|
|
58
|
+
devnet: false,
|
|
59
|
+
quotes: [USDC("0xaf88d065e77c8cC2239327C5EDb3A432268e5831"), WETH("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1")],
|
|
60
|
+
padQuote: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
61
|
+
}),
|
|
62
|
+
// no native USDC: USDG is the dollar quote
|
|
63
|
+
4663: entry(robinhood, {
|
|
64
|
+
network: "robinhood",
|
|
65
|
+
explorer: "https://robinhoodchain.blockscout.com",
|
|
66
|
+
publicRpc: "https://rpc.mainnet.chain.robinhood.com",
|
|
67
|
+
devnet: false,
|
|
68
|
+
quotes: [{ symbol: "USDG", address: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168", decimals: 6 }, WETH("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73")],
|
|
69
|
+
padQuote: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
|
|
70
|
+
}),
|
|
71
|
+
46630: entry(robinhoodTestnet, {
|
|
72
|
+
network: "robinhood-testnet",
|
|
73
|
+
explorer: robinhoodTestnet.blockExplorers.default.url,
|
|
74
|
+
publicRpc: robinhoodTestnet.rpcUrls.default.http[0],
|
|
75
|
+
devnet: false,
|
|
76
|
+
quotes: [],
|
|
77
|
+
}),
|
|
78
|
+
31337: entry(foundry, { network: "local", publicRpc: "http://127.0.0.1:8545", devnet: true, quotes: [], maxLogRange: LOCAL_MAX_LOG_RANGE }),
|
|
79
|
+
31339: entry(logswapDevnet, { network: "devnet", devnet: true, quotes: [], maxLogRange: LOCAL_MAX_LOG_RANGE }),
|
|
80
|
+
});
|
|
81
|
+
/** The production chains, in release order. */
|
|
82
|
+
export const RELEASE_CHAIN_IDS = [1, 8453, 42161, 4663];
|
|
83
|
+
/** The registry entry for `chainId`, or undefined for a chain this SDK does not list. */
|
|
84
|
+
export function logswapChain(chainId) {
|
|
85
|
+
return LOGSWAP_CHAINS[chainId];
|
|
86
|
+
}
|
|
87
|
+
/** A quote of `chainId` by symbol (case-insensitive), or undefined. */
|
|
88
|
+
export function quoteOf(chainId, symbol) {
|
|
89
|
+
const s = symbol.toLowerCase();
|
|
90
|
+
return LOGSWAP_CHAINS[chainId]?.quotes.find((q) => q.symbol.toLowerCase() === s);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The published deployments, by chain id. Empty until the release chains are deployed; a
|
|
94
|
+
* deployment is added here from its artifact in the release that ships it.
|
|
95
|
+
*/
|
|
96
|
+
export const LOGSWAP_DEPLOYMENTS = Object.freeze({});
|
|
97
|
+
/** The published deployment on `chainId`, or undefined. */
|
|
98
|
+
export function deploymentFor(chainId) {
|
|
99
|
+
return LOGSWAP_DEPLOYMENTS[chainId];
|
|
100
|
+
}
|
|
101
|
+
const REQUIRED_ADDRESSES = [
|
|
102
|
+
"deployer",
|
|
103
|
+
"logAuthority",
|
|
104
|
+
"logTreasury",
|
|
105
|
+
"permit2",
|
|
106
|
+
"multicall3",
|
|
107
|
+
"policyRegistry",
|
|
108
|
+
"fPoolManager",
|
|
109
|
+
"cPoolManager",
|
|
110
|
+
"publicPolicy",
|
|
111
|
+
"privatePolicy",
|
|
112
|
+
"polPolicy",
|
|
113
|
+
"padPolicy",
|
|
114
|
+
"router",
|
|
115
|
+
"lens",
|
|
116
|
+
];
|
|
117
|
+
const OPTIONAL_ADDRESSES = ["createX", "tokenFactory"];
|
|
118
|
+
function uint(o, k) {
|
|
119
|
+
const v = o[k];
|
|
120
|
+
if (typeof v === "bigint" && v >= 0n)
|
|
121
|
+
return v;
|
|
122
|
+
if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0)
|
|
123
|
+
return BigInt(v);
|
|
124
|
+
if (typeof v === "string" && /^(0x[0-9a-fA-F]+|\d+)$/.test(v))
|
|
125
|
+
return BigInt(v);
|
|
126
|
+
throw new Error(`logswap: deployment artifact: "${k}" is ${JSON.stringify(v)}, expected a non-negative integer`);
|
|
127
|
+
}
|
|
128
|
+
function address(o, k) {
|
|
129
|
+
const v = o[k];
|
|
130
|
+
if (typeof v !== "string" || !isAddress(v, { strict: false })) {
|
|
131
|
+
throw new Error(`logswap: deployment artifact: "${k}" is ${JSON.stringify(v)}, expected an address`);
|
|
132
|
+
}
|
|
133
|
+
return getAddress(v);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Validate a deployment artifact (parsed JSON) and return it typed. Throws on a missing or
|
|
137
|
+
* malformed field, and on a `chainId` other than `opts.chainId` when given: one address set is valid
|
|
138
|
+
* on every release chain, so an artifact read for the wrong chain would otherwise load cleanly and
|
|
139
|
+
* scan from the wrong `deployBlock`.
|
|
140
|
+
*/
|
|
141
|
+
export function deploymentFromArtifact(json, opts = {}) {
|
|
142
|
+
if (typeof json !== "object" || json === null || Array.isArray(json))
|
|
143
|
+
throw new Error("logswap: deployment artifact is not a JSON object");
|
|
144
|
+
const o = json;
|
|
145
|
+
const chainId = Number(uint(o, "chainId"));
|
|
146
|
+
if (opts.chainId !== undefined && chainId !== opts.chainId) {
|
|
147
|
+
throw new Error(`logswap: deployment artifact is for chain ${chainId}, expected chain ${opts.chainId}`);
|
|
148
|
+
}
|
|
149
|
+
const network = o.network;
|
|
150
|
+
if (typeof network !== "string" || network === "")
|
|
151
|
+
throw new Error(`logswap: deployment artifact: "network" is ${JSON.stringify(network)}`);
|
|
152
|
+
const d = {
|
|
153
|
+
chainId,
|
|
154
|
+
network,
|
|
155
|
+
deployBlock: uint(o, "deployBlock"),
|
|
156
|
+
cVersion: uint(o, "cVersion"),
|
|
157
|
+
fVersion: uint(o, "fVersion"),
|
|
158
|
+
};
|
|
159
|
+
if (o.deployTag !== undefined) {
|
|
160
|
+
if (typeof o.deployTag !== "string")
|
|
161
|
+
throw new Error(`logswap: deployment artifact: "deployTag" is ${JSON.stringify(o.deployTag)}`);
|
|
162
|
+
d.deployTag = o.deployTag;
|
|
163
|
+
}
|
|
164
|
+
for (const k of REQUIRED_ADDRESSES)
|
|
165
|
+
d[k] = address(o, k);
|
|
166
|
+
for (const k of OPTIONAL_ADDRESSES)
|
|
167
|
+
if (o[k] !== undefined)
|
|
168
|
+
d[k] = address(o, k);
|
|
169
|
+
return d;
|
|
170
|
+
}
|
|
171
|
+
/** The client's address set from a deployment. */
|
|
172
|
+
export function addressesOfDeployment(d) {
|
|
173
|
+
return {
|
|
174
|
+
cPoolManager: d.cPoolManager,
|
|
175
|
+
router: d.router,
|
|
176
|
+
lens: d.lens,
|
|
177
|
+
fPoolManager: d.fPoolManager,
|
|
178
|
+
publicPolicy: d.publicPolicy,
|
|
179
|
+
privatePolicy: d.privatePolicy,
|
|
180
|
+
polPolicy: d.polPolicy,
|
|
181
|
+
padPolicy: d.padPolicy,
|
|
182
|
+
policyRegistry: d.policyRegistry,
|
|
183
|
+
permit2: d.permit2,
|
|
184
|
+
...(d.tokenFactory ? { tokenFactory: d.tokenFactory } : {}),
|
|
185
|
+
};
|
|
186
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* the protocol, not configuration that grows.
|
|
9
9
|
*/
|
|
10
10
|
import type { Address, PublicClient, WalletClient } from "viem";
|
|
11
|
+
import { type LogswapDeployment } from "./chains.js";
|
|
11
12
|
export interface LogswapAddresses {
|
|
12
13
|
/** The C singleton — a floor per position, on a tick ladder. ERC-6909 positions and token
|
|
13
14
|
* claims live here. */
|
|
@@ -44,12 +45,35 @@ export interface LogswapClient {
|
|
|
44
45
|
public: PublicClient;
|
|
45
46
|
wallet?: WalletClient;
|
|
46
47
|
addresses: LogswapAddresses;
|
|
48
|
+
/** The chain the client reads: the deployment's, else the public client's. Unset when neither says. */
|
|
49
|
+
chainId?: number;
|
|
50
|
+
/** The deployment's first block: the default `fromBlock` of every log scan. */
|
|
51
|
+
deployBlock?: bigint;
|
|
52
|
+
/** Block span of one `eth_getLogs` call on the chain path; wider scans are split. {@link DEFAULT_MAX_LOG_RANGE} when unset. */
|
|
53
|
+
maxLogRange?: bigint;
|
|
54
|
+
/**
|
|
55
|
+
* The rindexer GraphQL endpoint of THIS chain's indexer: the default `indexer` of every history
|
|
56
|
+
* read. The contracts sit at one address on every release chain, so an indexer's rows carry no
|
|
57
|
+
* chain a reader could filter on: one URL per chain.
|
|
58
|
+
*/
|
|
59
|
+
indexerUrl?: string;
|
|
47
60
|
}
|
|
48
|
-
export
|
|
61
|
+
export interface CreateLogswapClientArgs {
|
|
49
62
|
public: PublicClient;
|
|
50
63
|
wallet?: WalletClient;
|
|
51
|
-
addresses
|
|
52
|
-
|
|
64
|
+
/** The addresses; derived from `deployment` when absent. One of the two is required. */
|
|
65
|
+
addresses?: LogswapAddresses;
|
|
66
|
+
/** A deployment ({@link deploymentFromArtifact}, {@link deploymentFor}): addresses, chain and deploy block. */
|
|
67
|
+
deployment?: LogswapDeployment;
|
|
68
|
+
/** Overrides the deployment's. */
|
|
69
|
+
deployBlock?: bigint;
|
|
70
|
+
/** Overrides the chain's default ({@link LogswapChain.maxLogRange}, else {@link DEFAULT_MAX_LOG_RANGE}). */
|
|
71
|
+
maxLogRange?: bigint;
|
|
72
|
+
indexerUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
export declare function createLogswapClient(args: CreateLogswapClientArgs): LogswapClient;
|
|
75
|
+
/** The chain id the client reads: set at construction when known, else asked of the node. */
|
|
76
|
+
export declare function clientChainId(c: LogswapClient): Promise<number>;
|
|
53
77
|
/**
|
|
54
78
|
* Assert the deployment matches the ABI this build was generated against.
|
|
55
79
|
*
|
|
@@ -84,8 +108,15 @@ export declare function createLogswapClient(args: {
|
|
|
84
108
|
* fee (`swapFeeOf` and `DEFAULT_FEE` are gone); the mint fee is the market's, proposed at
|
|
85
109
|
* `initialize` / `createMarket` and answered by the gate; the gate (`gate`, `setGate`) is the
|
|
86
110
|
* public policy, set at construction. No pool id moved.
|
|
111
|
+
*
|
|
112
|
+
* **8** since 2026-10-13 (logswap-contract decision 066): the collector is split into two roles —
|
|
113
|
+
* `feeCollector` / `proposeCollector` / `acceptCollector` are `treasury` / `proposeTreasury` (the
|
|
114
|
+
* LOG Authority's) / `acceptTreasury`; `setSwapFeeTax` and `setGate` leave the manager: the tax is
|
|
115
|
+
* each market's, answered by the gate (`PublicPolicy.swapFeeTax`, the LOG Authority's) at birth and
|
|
116
|
+
* read as `getPool(key).swapFeeTax`; the gate is fixed at construction; `collectProtocolFees(key)` is
|
|
117
|
+
* permissionless and pays the treasury. No pool id moved.
|
|
87
118
|
*/
|
|
88
|
-
export declare const EXPECTED_VERSION =
|
|
119
|
+
export declare const EXPECTED_VERSION = 8n;
|
|
89
120
|
/**
|
|
90
121
|
* The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
|
|
91
122
|
* 4 was the income-only harvest cut).
|
|
@@ -97,7 +128,7 @@ export declare const EXPECTED_VERSION = 7n;
|
|
|
97
128
|
* passes it; when one lands, raise this constant in the same change, which is the discipline
|
|
98
129
|
* `EXPECTED_VERSION` enforces mechanically and this one asks for.
|
|
99
130
|
*/
|
|
100
|
-
export declare const EXPECTED_F_VERSION =
|
|
131
|
+
export declare const EXPECTED_F_VERSION = 29n;
|
|
101
132
|
export declare function assertVersion(c: LogswapClient, expected?: bigint): Promise<void>;
|
|
102
133
|
/**
|
|
103
134
|
* The versions say the managers are the right code; this says the rest of the addresses belong
|
package/dist/client.js
CHANGED
|
@@ -7,8 +7,34 @@
|
|
|
7
7
|
* and a market is an `initialize(key, x0)` call rather than a deployment. So this is a constant of
|
|
8
8
|
* the protocol, not configuration that grows.
|
|
9
9
|
*/
|
|
10
|
+
import { addressesOfDeployment, DEFAULT_MAX_LOG_RANGE, logswapChain } from "./chains.js";
|
|
10
11
|
export function createLogswapClient(args) {
|
|
11
|
-
|
|
12
|
+
const d = args.deployment;
|
|
13
|
+
const addresses = args.addresses ?? (d && addressesOfDeployment(d));
|
|
14
|
+
if (!addresses)
|
|
15
|
+
throw new Error("logswap: createLogswapClient needs `addresses` or `deployment`");
|
|
16
|
+
const readChain = args.public.chain?.id;
|
|
17
|
+
if (d && readChain !== undefined && readChain !== d.chainId) {
|
|
18
|
+
throw new Error(`logswap: the deployment is on chain ${d.chainId} but the public client reads chain ${readChain}`);
|
|
19
|
+
}
|
|
20
|
+
const chainId = d?.chainId ?? readChain;
|
|
21
|
+
const maxLogRange = args.maxLogRange ?? (chainId !== undefined ? logswapChain(chainId)?.maxLogRange : undefined) ?? DEFAULT_MAX_LOG_RANGE;
|
|
22
|
+
if (maxLogRange <= 0n)
|
|
23
|
+
throw new Error("logswap: maxLogRange must be positive");
|
|
24
|
+
const deployBlock = args.deployBlock ?? d?.deployBlock;
|
|
25
|
+
return {
|
|
26
|
+
public: args.public,
|
|
27
|
+
wallet: args.wallet && guardChain(args.wallet, args.public),
|
|
28
|
+
addresses,
|
|
29
|
+
maxLogRange,
|
|
30
|
+
...(chainId !== undefined ? { chainId } : {}),
|
|
31
|
+
...(deployBlock !== undefined ? { deployBlock } : {}),
|
|
32
|
+
...(args.indexerUrl ? { indexerUrl: args.indexerUrl } : {}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The chain id the client reads: set at construction when known, else asked of the node. */
|
|
36
|
+
export async function clientChainId(c) {
|
|
37
|
+
return c.chainId ?? c.public.chain?.id ?? (await c.public.getChainId());
|
|
12
38
|
}
|
|
13
39
|
/**
|
|
14
40
|
* The wallet, with every signing call first checking that it is on the chain the reads come from.
|
|
@@ -76,8 +102,15 @@ function guardChain(wallet, pub) {
|
|
|
76
102
|
* fee (`swapFeeOf` and `DEFAULT_FEE` are gone); the mint fee is the market's, proposed at
|
|
77
103
|
* `initialize` / `createMarket` and answered by the gate; the gate (`gate`, `setGate`) is the
|
|
78
104
|
* public policy, set at construction. No pool id moved.
|
|
105
|
+
*
|
|
106
|
+
* **8** since 2026-10-13 (logswap-contract decision 066): the collector is split into two roles —
|
|
107
|
+
* `feeCollector` / `proposeCollector` / `acceptCollector` are `treasury` / `proposeTreasury` (the
|
|
108
|
+
* LOG Authority's) / `acceptTreasury`; `setSwapFeeTax` and `setGate` leave the manager: the tax is
|
|
109
|
+
* each market's, answered by the gate (`PublicPolicy.swapFeeTax`, the LOG Authority's) at birth and
|
|
110
|
+
* read as `getPool(key).swapFeeTax`; the gate is fixed at construction; `collectProtocolFees(key)` is
|
|
111
|
+
* permissionless and pays the treasury. No pool id moved.
|
|
79
112
|
*/
|
|
80
|
-
export const EXPECTED_VERSION =
|
|
113
|
+
export const EXPECTED_VERSION = 8n;
|
|
81
114
|
/**
|
|
82
115
|
* The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
|
|
83
116
|
* 4 was the income-only harvest cut).
|
|
@@ -149,16 +182,25 @@ export const EXPECTED_VERSION = 7n;
|
|
|
149
182
|
// `harvestCut`, `setHarvestCut` are gone; a pad's split (creator's cut, token burn) rides in the key's salt.
|
|
150
183
|
// 24 (logswap-contract#58): the pot splits in quote — `Terms.burn` is quote spent on a buy-and-burn, the
|
|
151
184
|
// rest deepens the bid, no buy-in, `Regenerated` is (pot, payee, toPayee, cut, burnt, deepened), a pad's
|
|
152
|
-
// salt carries `burnShare` of the pot (057); the mint fee all to the
|
|
185
|
+
// salt carries `burnShare` of the pot (057); the mint fee all to the treasury (058, 066); `phi` → `swapFee`,
|
|
153
186
|
// `MINT_FEE()` → `mintFee()`, the policies' fee tiers, a canonical public pool (059).
|
|
154
187
|
// 25 (logswap-contract#59): the views moved behind `extsload` (062) — this SDK reads them through the
|
|
155
|
-
// lens (`fPool`, `getFPools`, `fBundleOf`, `fDividendOf`, `fLienOf`); the capped F pool, `FPoolKey.cap`
|
|
188
|
+
// lens (`fPool`, `getFPools`, `fBundleOf`, `fDividendOf`, `fLienOf`); the capped F pool, `FPoolKey.cap` (`lnCapOverFloor` since 27)
|
|
156
189
|
// appended so every pool id moved (061); the lien, `lock` / `unlock` (063); θ is `logFloor`, θ₀ `refLogFloor`.
|
|
157
190
|
// 26 (logswap-contract#60): the mint fee is per pool, proposed at `initialize(key, mintFee)` and answered
|
|
158
191
|
// by the policy's `onInitialize` from its menu (065); `MINT_FEE` is gone; a fee of 0 is no fee; the
|
|
159
192
|
// policies curate creators, a public pool is uncapped, one pad per base (064). No pool id moved.
|
|
193
|
+
// 27 (decision 066): `FPoolKey.cap` → `lnCapOverFloor` (a name: no id moved); `feeCollector` → `treasury` (proposed by the LOG Authority, accepted by itself);
|
|
194
|
+
// the registry's `owner` → `logAuthority`, administering every policy's lists and numbers; a public pool
|
|
195
|
+
// is born to the LOG Authority. No pool id moved.
|
|
196
|
+
// 28 (decision 067): no buy-and-burn — `Terms` is four words, `Regenerated` loses `burnt`; on a pad the manager caps the
|
|
197
|
+
// payee at `PAYEE_CUT_MAX` and carries only the dead shares, and refuses `retire`; `PadPolicy.pack(creatorShare, nonce)`,
|
|
198
|
+
// `setSchedule` without a burn range, `splitOf` → (creatorShare, protocolShare). No pool id moved.
|
|
199
|
+
// 29 (decision 068): the restructure guard and the registry's sunset read `block.timestamp` —
|
|
200
|
+
// `Pool.restructureBlock` is `restructureTime` (unix seconds, same slot), `PolicyRegistry.sunset(policy, untilTime)`.
|
|
201
|
+
// Names only: no pool id moved.
|
|
160
202
|
// A breaking bump: raised in the same change.
|
|
161
|
-
export const EXPECTED_F_VERSION =
|
|
203
|
+
export const EXPECTED_F_VERSION = 29n;
|
|
162
204
|
export async function assertVersion(c, expected = EXPECTED_VERSION) {
|
|
163
205
|
const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");
|
|
164
206
|
// three independent reads: one round trip, not three in a row
|
package/dist/fees.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare function blockAtOrAfter(c: LogswapClient, t: bigint, lo: bigint,
|
|
|
55
55
|
export declare function swapFees(c: LogswapClient, m: DiscoveredMarket, opts?: {
|
|
56
56
|
since?: bigint;
|
|
57
57
|
fromBlock?: bigint;
|
|
58
|
-
toBlock?: bigint; /** The rindexer GraphQL endpoint: the Swap rows
|
|
58
|
+
toBlock?: bigint; /** The rindexer GraphQL endpoint: the window from its swap_flow view (the Swap rows as fallback), the node otherwise. */
|
|
59
59
|
indexer?: string;
|
|
60
60
|
}): Promise<SwapFeeWindow>;
|
|
61
61
|
/**
|
package/dist/fees.js
CHANGED
|
@@ -12,6 +12,23 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { cPoolManagerAbi } from "./generated.js";
|
|
14
14
|
import { getEventLogs } from "./history.js";
|
|
15
|
+
import { swapFlows } from "./views.js";
|
|
16
|
+
/** A C market's swap fees over [fromBlock, toBlock] from the indexer's swap_flow view; null when the indexer cannot answer. */
|
|
17
|
+
async function windowFromView(c, indexer, poolId, fromBlock, toBlock) {
|
|
18
|
+
try {
|
|
19
|
+
const rows = await swapFlows(indexer, {
|
|
20
|
+
condition: { side: "C", poolId: poolId.toLowerCase(), manager: c.addresses.cPoolManager.toLowerCase() },
|
|
21
|
+
filter: { blockNumber: { greaterThanOrEqualTo: fromBlock.toString(), lessThanOrEqualTo: toBlock.toString() } },
|
|
22
|
+
});
|
|
23
|
+
let fees = 0n;
|
|
24
|
+
for (const r of rows)
|
|
25
|
+
fees += r.feeQuote;
|
|
26
|
+
return { fees, swaps: rows.length };
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null; // the view is a cache: the Swap rows answer the same
|
|
30
|
+
}
|
|
31
|
+
}
|
|
15
32
|
const WAD = 10n ** 18n;
|
|
16
33
|
const YEAR_SECONDS = 31_536_000;
|
|
17
34
|
/**
|
|
@@ -88,15 +105,23 @@ export async function swapFees(c, m, opts = {}) {
|
|
|
88
105
|
const ev = cPoolManagerAbi.find((x) => x.type === "event" && x.name === "Swap");
|
|
89
106
|
if (!ev)
|
|
90
107
|
throw new Error("logswap: Swap event missing from the generated ABI");
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
: (await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.cPoolManager, event: ev, args: { poolId: m.poolId }, fromBlock, toBlock })).logs;
|
|
94
|
-
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ
|
|
108
|
+
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ;
|
|
109
|
+
// the indexer's swap_flow view carries the same figure per swap (`feeQuote`, C)
|
|
95
110
|
let fees = 0n;
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
let swaps = 0;
|
|
112
|
+
const indexer = opts.indexer ?? c.indexerUrl;
|
|
113
|
+
const viewed = fromBlock > toBlock || !indexer ? null : await windowFromView(c, indexer, m.poolId, fromBlock, toBlock);
|
|
114
|
+
if (viewed) {
|
|
115
|
+
({ fees, swaps } = viewed);
|
|
116
|
+
}
|
|
117
|
+
else if (fromBlock <= toBlock) {
|
|
118
|
+
const { logs } = await getEventLogs(c, { indexer, address: c.addresses.cPoolManager, event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
|
|
119
|
+
for (const l of logs)
|
|
120
|
+
fees += l.args.fee;
|
|
121
|
+
swaps = logs.length;
|
|
122
|
+
}
|
|
98
123
|
const to = last.timestamp;
|
|
99
|
-
return { fromBlock, toBlock, from, to, seconds: to > from ? to - from : 0n, swapFees: fees, swaps
|
|
124
|
+
return { fromBlock, toBlock, from, to, seconds: to > from ? to - from : 0n, swapFees: fees, swaps };
|
|
100
125
|
}
|
|
101
126
|
/**
|
|
102
127
|
* The window's swap fees over the market's CURRENT active L, annualised linearly over the window.
|