@logswap/sdk 0.5.99 → 0.5.100
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 +46 -31
- package/dist/actions.d.ts +8 -8
- package/dist/actions.js +8 -8
- package/dist/client.d.ts +2 -2
- package/dist/client.js +11 -2
- package/dist/fees.js +2 -24
- package/dist/fpool.d.ts +10 -6
- package/dist/fpool.js +12 -23
- package/dist/generated.d.ts +84 -47
- package/dist/generated.js +88 -37
- package/dist/history.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/liquidity.d.ts +2 -1
- package/dist/liquidity.js +2 -1
- package/dist/positions.js +2 -13
- package/package.json +1 -1
- package/src/actions.ts +12 -12
- package/src/client.ts +11 -2
- package/src/fees.ts +2 -22
- package/src/fpool.ts +16 -24
- package/src/generated.ts +88 -37
- package/src/history.ts +1 -1
- package/src/index.ts +0 -1
- package/src/liquidity.ts +2 -1
- package/src/positions.ts +3 -14
- package/dist/views.d.ts +0 -281
- package/dist/views.js +0 -188
- package/src/views.ts +0 -480
package/dist/views.d.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* views.ts — the indexer's derived views (indexing phase 2, logswap-be `devnet/VIEWS.md`).
|
|
3
|
-
*
|
|
4
|
-
* The indexer records events and the snapshotter samples state; these views join the two in
|
|
5
|
-
* Postgres: holders, a wallet's positions and flows, per-swap volume and fee, price points and
|
|
6
|
-
* candles, TVL by the hour, the pools table's 24 h / 7 d figures, the generation steps and pad
|
|
7
|
-
* status, protocol revenue by day, and who did each routed action. Each reader returns typed rows:
|
|
8
|
-
*
|
|
9
|
-
* - **amounts** (Postgres `numeric`, GraphQL BigFloat strings) as `bigint`. The views floor every
|
|
10
|
-
* amount they compute, so the integer part is the value;
|
|
11
|
-
* - **prices, APYs, progress** (`double precision`) as `number`. `priceRaw` is quote wei per base
|
|
12
|
-
* wei: scale by 10^(baseDecimals − quoteDecimals) to display;
|
|
13
|
-
* - **times** as unix seconds (`number`), **addresses** checksummed, pool ids lowercase `0x…`.
|
|
14
|
-
*
|
|
15
|
-
* A view is a cache like any indexed table: the readers throw when the indexer cannot answer, and
|
|
16
|
-
* the SDK functions that use them ({@link holdingsOf}, {@link swapFees}, {@link fPoolShareHolders})
|
|
17
|
-
* keep their node path as the fallback.
|
|
18
|
-
*/
|
|
19
|
-
import { type Address, type Hex } from "viem";
|
|
20
|
-
import type { Side } from "./client.js";
|
|
21
|
-
/** What a view query takes: postgraphile's `condition` (equality), `filter` (the connection-filter plugin's operators), an `orderBy` of the view's enum names, a row cap. */
|
|
22
|
-
export interface ViewQuery {
|
|
23
|
-
condition?: Record<string, unknown>;
|
|
24
|
-
filter?: Record<string, unknown>;
|
|
25
|
-
/** e.g. `["BLOCK_NUMBER_ASC"]`, `["VOLUME_24H_DESC"]`: the column's CONSTANT_CASE name and a direction. */
|
|
26
|
-
orderBy?: string[];
|
|
27
|
-
/** At most this many rows (one page up to 1000). All rows when omitted. */
|
|
28
|
-
first?: number;
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
}
|
|
31
|
-
/** A pool of either manager: C markets are kind `market`; F pools carry their policy's registry name (`public`, `private`, `pol`, `pad`). */
|
|
32
|
-
export interface PoolDirectoryRow {
|
|
33
|
-
side: Side;
|
|
34
|
-
poolId: Hex;
|
|
35
|
-
manager: Address;
|
|
36
|
-
kind: string;
|
|
37
|
-
quote: Address;
|
|
38
|
-
bases: Address[];
|
|
39
|
-
swapFee: bigint;
|
|
40
|
-
/** C only. */
|
|
41
|
-
tickSpacing: bigint | null;
|
|
42
|
-
/** F only. */
|
|
43
|
-
policy: Address | null;
|
|
44
|
-
creator: Address | null;
|
|
45
|
-
birthBlock: bigint;
|
|
46
|
-
birthTime: number;
|
|
47
|
-
/** F only: the pool's share-id key (the id's bits above the generation). */
|
|
48
|
-
shareKey: bigint | null;
|
|
49
|
-
}
|
|
50
|
-
export declare function poolDirectory(url: string, q?: ViewQuery): Promise<PoolDirectoryRow[]>;
|
|
51
|
-
/** A manager event and who did it: the router's caller when the transaction went through the router (`viaRouter`), else the address the event names (`actor`). */
|
|
52
|
-
export interface EventUserRow {
|
|
53
|
-
side: Side;
|
|
54
|
-
/** `Swap` `Mint` `Burn` `Update` `Claim` (C); `FSwap` `FMint` `FBurn` `Harvest` `DividendClaimed` `Redeem` (F). */
|
|
55
|
-
event: string;
|
|
56
|
-
poolId: Hex;
|
|
57
|
-
actor: Address;
|
|
58
|
-
viaRouter: boolean;
|
|
59
|
-
user: Address;
|
|
60
|
-
txHash: Hex;
|
|
61
|
-
logIndex: number;
|
|
62
|
-
blockNumber: bigint;
|
|
63
|
-
blockTimestamp: number;
|
|
64
|
-
manager: Address;
|
|
65
|
-
}
|
|
66
|
-
export declare function eventUsers(url: string, q?: ViewQuery): Promise<EventUserRow[]>;
|
|
67
|
-
/** A current ERC-6909 balance: C ids resolve to their class (floor, cap), F ids to their pool and generation. C's backstop lock is held by address(0) (`isBackstop`), F's dead shares by 0xdead (`isDead`). */
|
|
68
|
-
export interface PoolHolderRow {
|
|
69
|
-
side: Side;
|
|
70
|
-
manager: Address;
|
|
71
|
-
id: bigint;
|
|
72
|
-
poolId: Hex | null;
|
|
73
|
-
/** F only. */
|
|
74
|
-
gen: number | null;
|
|
75
|
-
/** C only. */
|
|
76
|
-
floor: bigint | null;
|
|
77
|
-
cap: bigint | null;
|
|
78
|
-
capped: boolean | null;
|
|
79
|
-
holder: Address;
|
|
80
|
-
balance: bigint;
|
|
81
|
-
isBackstop: boolean;
|
|
82
|
-
isDead: boolean;
|
|
83
|
-
}
|
|
84
|
-
export declare function poolHolders(url: string, q?: ViewQuery): Promise<PoolHolderRow[]>;
|
|
85
|
-
/** A wallet's holding (backstop and dead excluded). `valueQuote`: an F share of the live generation at the latest snapshot's share value, a retired one at its bundle's quote per share; NULL for C (a lens read: {@link legsOf}). */
|
|
86
|
-
export interface WalletPositionRow {
|
|
87
|
-
side: Side;
|
|
88
|
-
manager: Address;
|
|
89
|
-
wallet: Address;
|
|
90
|
-
poolId: Hex | null;
|
|
91
|
-
kind: string | null;
|
|
92
|
-
quote: Address | null;
|
|
93
|
-
bases: Address[];
|
|
94
|
-
id: bigint;
|
|
95
|
-
gen: number | null;
|
|
96
|
-
floor: bigint | null;
|
|
97
|
-
cap: bigint | null;
|
|
98
|
-
capped: boolean | null;
|
|
99
|
-
shares: bigint;
|
|
100
|
-
valueQuote: bigint | null;
|
|
101
|
-
/** `live` / `retired` / `unknown` (F), `class` (C). */
|
|
102
|
-
status: string;
|
|
103
|
-
valuedAtBlock: bigint | null;
|
|
104
|
-
}
|
|
105
|
-
export declare function walletPositions(url: string, q?: ViewQuery): Promise<WalletPositionRow[]>;
|
|
106
|
-
/** A wallet's flows in a pool, from its own events: what it put in and took out, fees and dividends realised. F mints and burns carry the quote leg only. C `Update` is not counted (it repeats its Burn and Mint). */
|
|
107
|
-
export interface WalletPoolFlowRow {
|
|
108
|
-
side: Side;
|
|
109
|
-
manager: Address;
|
|
110
|
-
wallet: Address;
|
|
111
|
-
poolId: Hex;
|
|
112
|
-
baseIn: bigint;
|
|
113
|
-
quoteIn: bigint;
|
|
114
|
-
baseOut: bigint;
|
|
115
|
-
quoteOut: bigint;
|
|
116
|
-
feesRealised: bigint;
|
|
117
|
-
dividendsClaimed: bigint;
|
|
118
|
-
redeemedQuote: bigint;
|
|
119
|
-
entries: number;
|
|
120
|
-
exits: number;
|
|
121
|
-
firstTime: number;
|
|
122
|
-
lastTime: number;
|
|
123
|
-
}
|
|
124
|
-
export declare function walletPoolFlows(url: string, q?: ViewQuery): Promise<WalletPoolFlowRow[]>;
|
|
125
|
-
/** A swap's volume and fee in quote, the app's definitions (C: the quote leg and the event's fee; F: see VIEWS.md). F rows carry the traded legs and their L_j = w_j·L. */
|
|
126
|
-
export interface SwapFlowRow {
|
|
127
|
-
side: Side;
|
|
128
|
-
manager: Address;
|
|
129
|
-
poolId: Hex;
|
|
130
|
-
txHash: Hex;
|
|
131
|
-
logIndex: number;
|
|
132
|
-
blockNumber: bigint;
|
|
133
|
-
blockTimestamp: number;
|
|
134
|
-
volumeQuote: bigint;
|
|
135
|
-
feeQuote: bigint;
|
|
136
|
-
tokenIn: Address | null;
|
|
137
|
-
tokenOut: Address | null;
|
|
138
|
-
reserveIn: bigint | null;
|
|
139
|
-
reserveOut: bigint | null;
|
|
140
|
-
lIn: bigint | null;
|
|
141
|
-
lOut: bigint | null;
|
|
142
|
-
}
|
|
143
|
-
export declare function swapFlows(url: string, q?: ViewQuery): Promise<SwapFlowRow[]>;
|
|
144
|
-
/** A price point per (pool, base) after a swap: C e^newX, F the traded leg's mark L_j / R_j. Quote wei per base wei. */
|
|
145
|
-
export interface PriceTickRow {
|
|
146
|
-
side: Side;
|
|
147
|
-
poolId: Hex;
|
|
148
|
-
base: Address;
|
|
149
|
-
blockNumber: bigint;
|
|
150
|
-
blockTimestamp: number;
|
|
151
|
-
logIndex: number;
|
|
152
|
-
priceRaw: number;
|
|
153
|
-
volumeQuote: bigint;
|
|
154
|
-
feeQuote: bigint;
|
|
155
|
-
}
|
|
156
|
-
export declare function priceTicks(url: string, q?: ViewQuery): Promise<PriceTickRow[]>;
|
|
157
|
-
/** OHLC per (pool, base, UTC bucket). A base → base F swap counts in both legs' candles; pool totals come from {@link poolSummaries}. */
|
|
158
|
-
export interface CandleRow {
|
|
159
|
-
side: Side;
|
|
160
|
-
poolId: Hex;
|
|
161
|
-
base: Address;
|
|
162
|
-
/** Bucket start, unix seconds. */
|
|
163
|
-
bucket: number;
|
|
164
|
-
open: number;
|
|
165
|
-
high: number;
|
|
166
|
-
low: number;
|
|
167
|
-
close: number;
|
|
168
|
-
volumeQuote: bigint;
|
|
169
|
-
feeQuote: bigint;
|
|
170
|
-
swaps: number;
|
|
171
|
-
}
|
|
172
|
-
export type CandleInterval = "minute" | "hour" | "day";
|
|
173
|
-
export declare function candles(url: string, interval: CandleInterval, q?: ViewQuery): Promise<CandleRow[]>;
|
|
174
|
-
/** The hour's last snapshot per pool (forward-fill hours with none). `liquidity` is C's active L or F's L. */
|
|
175
|
-
export interface PoolTvlHourRow {
|
|
176
|
-
side: Side;
|
|
177
|
-
poolId: Hex;
|
|
178
|
-
bucket: number;
|
|
179
|
-
blockNumber: bigint;
|
|
180
|
-
tvlQuote: bigint | null;
|
|
181
|
-
liquidity: bigint | null;
|
|
182
|
-
/** C only. */
|
|
183
|
-
priceRaw: number | null;
|
|
184
|
-
feeGrowth: bigint | null;
|
|
185
|
-
/** F only. */
|
|
186
|
-
shareValue: bigint | null;
|
|
187
|
-
gen: number | null;
|
|
188
|
-
}
|
|
189
|
-
export declare function poolTvlHours(url: string, q?: ViewQuery): Promise<PoolTvlHourRow[]>;
|
|
190
|
-
/**
|
|
191
|
-
* A pool's trailing 24 h / 7 d figures and its latest state. APY, as the app shows it: the window's
|
|
192
|
-
* swap fees over the pool's current L, annualised over the window measured (clipped to the pool's
|
|
193
|
-
* birth) — `fees / L × 31 536 000 / seconds`; the same formula as {@link swapFeeApy}.
|
|
194
|
-
*/
|
|
195
|
-
export interface PoolSummaryRow {
|
|
196
|
-
side: Side;
|
|
197
|
-
poolId: Hex;
|
|
198
|
-
kind: string;
|
|
199
|
-
quote: Address;
|
|
200
|
-
bases: Address[];
|
|
201
|
-
swapFee: bigint;
|
|
202
|
-
birthTime: number;
|
|
203
|
-
volume24h: bigint;
|
|
204
|
-
fees24h: bigint;
|
|
205
|
-
swaps24h: number;
|
|
206
|
-
volume7d: bigint;
|
|
207
|
-
fees7d: bigint;
|
|
208
|
-
volumeAll: bigint;
|
|
209
|
-
feesAll: bigint;
|
|
210
|
-
lastSwap: number | null;
|
|
211
|
-
tvlQuote: bigint | null;
|
|
212
|
-
liquidity: bigint | null;
|
|
213
|
-
priceRaw: number | null;
|
|
214
|
-
shareValue: bigint | null;
|
|
215
|
-
gen: number | null;
|
|
216
|
-
stateBlock: bigint | null;
|
|
217
|
-
seconds24h: number;
|
|
218
|
-
seconds7d: number;
|
|
219
|
-
apy24h: number | null;
|
|
220
|
-
apy7d: number | null;
|
|
221
|
-
}
|
|
222
|
-
export declare function poolSummaries(url: string, q?: ViewQuery): Promise<PoolSummaryRow[]>;
|
|
223
|
-
/** A generation step (`regenerate` or a live-pool `deployLiquidity`): the income released and its split (the payee, the rest deepening the bid); a pad's `rung` from `Graduated`. */
|
|
224
|
-
export interface GenerationStepRow {
|
|
225
|
-
kind: string | null;
|
|
226
|
-
poolId: Hex;
|
|
227
|
-
/** The pool's generation after this step. */
|
|
228
|
-
genAfter: number;
|
|
229
|
-
income: bigint;
|
|
230
|
-
payee: Address;
|
|
231
|
-
toPayee: bigint;
|
|
232
|
-
deepened: bigint;
|
|
233
|
-
rung: number | null;
|
|
234
|
-
txHash: Hex;
|
|
235
|
-
blockNumber: bigint;
|
|
236
|
-
blockTimestamp: number;
|
|
237
|
-
}
|
|
238
|
-
export declare function generationSteps(url: string, q?: ViewQuery): Promise<GenerationStepRow[]>;
|
|
239
|
-
/** Every pad and POL now: the latest snapshot's state, the next graduation's threshold (pads) and the income's progress to it, and the steps so far. */
|
|
240
|
-
export interface PadStatusRow {
|
|
241
|
-
kind: string;
|
|
242
|
-
poolId: Hex;
|
|
243
|
-
quote: Address;
|
|
244
|
-
bases: Address[];
|
|
245
|
-
creator: Address | null;
|
|
246
|
-
birthTime: number;
|
|
247
|
-
gen: number | null;
|
|
248
|
-
income: bigint | null;
|
|
249
|
-
unharvested: bigint | null;
|
|
250
|
-
l: bigint | null;
|
|
251
|
-
q: bigint | null;
|
|
252
|
-
tvlQuote: bigint | null;
|
|
253
|
-
shareValue: bigint | null;
|
|
254
|
-
threshold: bigint | null;
|
|
255
|
-
/** income / threshold, a fraction; null without a threshold. */
|
|
256
|
-
progress: number | null;
|
|
257
|
-
stateBlock: bigint | null;
|
|
258
|
-
stateTime: number | null;
|
|
259
|
-
steps: number;
|
|
260
|
-
paidTotal: bigint;
|
|
261
|
-
deepenedTotal: bigint;
|
|
262
|
-
lastStep: number | null;
|
|
263
|
-
}
|
|
264
|
-
export declare function padStatuses(url: string, q?: ViewQuery): Promise<PadStatusRow[]>;
|
|
265
|
-
/**
|
|
266
|
-
* Protocol revenue per UTC day, side, source and token. Sources: F `mint_fee` (shares minted to the
|
|
267
|
-
* treasury, valued at the share value) and `income_tax` (the income tax taken at harvest); C `accrued` (the swap-fee tax and the mint fee
|
|
268
|
-
* together, from the snapshots) and `collected` — basis `collected`, cash moved, not revenue on top
|
|
269
|
-
* of `accrued`.
|
|
270
|
-
*/
|
|
271
|
-
export interface ProtocolRevenueDayRow {
|
|
272
|
-
day: number;
|
|
273
|
-
side: Side;
|
|
274
|
-
source: string;
|
|
275
|
-
basis: "earned" | "collected";
|
|
276
|
-
token: Address;
|
|
277
|
-
amount: bigint;
|
|
278
|
-
amountQuote: bigint;
|
|
279
|
-
events: number;
|
|
280
|
-
}
|
|
281
|
-
export declare function protocolRevenueDays(url: string, q?: ViewQuery): Promise<ProtocolRevenueDayRow[]>;
|
package/dist/views.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* views.ts — the indexer's derived views (indexing phase 2, logswap-be `devnet/VIEWS.md`).
|
|
3
|
-
*
|
|
4
|
-
* The indexer records events and the snapshotter samples state; these views join the two in
|
|
5
|
-
* Postgres: holders, a wallet's positions and flows, per-swap volume and fee, price points and
|
|
6
|
-
* candles, TVL by the hour, the pools table's 24 h / 7 d figures, the generation steps and pad
|
|
7
|
-
* status, protocol revenue by day, and who did each routed action. Each reader returns typed rows:
|
|
8
|
-
*
|
|
9
|
-
* - **amounts** (Postgres `numeric`, GraphQL BigFloat strings) as `bigint`. The views floor every
|
|
10
|
-
* amount they compute, so the integer part is the value;
|
|
11
|
-
* - **prices, APYs, progress** (`double precision`) as `number`. `priceRaw` is quote wei per base
|
|
12
|
-
* wei: scale by 10^(baseDecimals − quoteDecimals) to display;
|
|
13
|
-
* - **times** as unix seconds (`number`), **addresses** checksummed, pool ids lowercase `0x…`.
|
|
14
|
-
*
|
|
15
|
-
* A view is a cache like any indexed table: the readers throw when the indexer cannot answer, and
|
|
16
|
-
* the SDK functions that use them ({@link holdingsOf}, {@link swapFees}, {@link fPoolShareHolders})
|
|
17
|
-
* keep their node path as the fallback.
|
|
18
|
-
*/
|
|
19
|
-
import { getAddress } from "viem";
|
|
20
|
-
import { gql } from "./indexer.js";
|
|
21
|
-
const PAGE = 1000; // postgraphile's cap
|
|
22
|
-
const MAX_PAGES = 200;
|
|
23
|
-
const PARALLEL_PAGES = 8;
|
|
24
|
-
/** Every row of a view, paged by offset (a view has no primary key to page a cursor on). */
|
|
25
|
-
async function viewRows(url, field, type, selection, q) {
|
|
26
|
-
for (const o of q.orderBy ?? [])
|
|
27
|
-
if (!/^[A-Z0-9_]+$/.test(o))
|
|
28
|
-
throw new Error(`views: orderBy ${JSON.stringify(o)} is not an enum name`);
|
|
29
|
-
const hasCondition = q.condition !== undefined && Object.keys(q.condition).length > 0;
|
|
30
|
-
const hasFilter = q.filter !== undefined && Object.keys(q.filter).length > 0;
|
|
31
|
-
const pageSize = Math.min(q.first ?? PAGE, PAGE);
|
|
32
|
-
// postgraphile refuses a null or empty condition/filter: each appears only when it has content
|
|
33
|
-
const decl = `$offset: Int${hasCondition ? `, $condition: ${type}Condition` : ""}${hasFilter ? `, $filter: ${type}Filter` : ""}`;
|
|
34
|
-
const args = [
|
|
35
|
-
`first: ${pageSize}`,
|
|
36
|
-
"offset: $offset",
|
|
37
|
-
q.orderBy?.length ? `orderBy: [${q.orderBy.join(", ")}]` : "",
|
|
38
|
-
hasCondition ? "condition: $condition" : "",
|
|
39
|
-
hasFilter ? "filter: $filter" : "",
|
|
40
|
-
].filter(Boolean).join(", ");
|
|
41
|
-
const query = `query View(${decl}) { ${field}(${args}) { totalCount nodes { ${selection} } } }`;
|
|
42
|
-
const page = async (offset) => (await gql(url, query, { offset, ...(hasCondition ? { condition: q.condition } : {}), ...(hasFilter ? { filter: q.filter } : {}) }, q.signal))[field];
|
|
43
|
-
const first = await page(0);
|
|
44
|
-
const rows = [...first.nodes];
|
|
45
|
-
if (q.first === undefined && first.totalCount > first.nodes.length) {
|
|
46
|
-
const pages = Math.ceil(first.totalCount / PAGE);
|
|
47
|
-
if (pages > MAX_PAGES)
|
|
48
|
-
throw new Error(`views: ${field} has more than ${PAGE * MAX_PAGES} rows; narrow the query`);
|
|
49
|
-
const offsets = Array.from({ length: pages - 1 }, (_, i) => (i + 1) * PAGE);
|
|
50
|
-
for (let i = 0; i < offsets.length; i += PARALLEL_PAGES) {
|
|
51
|
-
for (const g of await Promise.all(offsets.slice(i, i + PARALLEL_PAGES).map(page)))
|
|
52
|
-
rows.push(...g.nodes);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (q.first !== undefined && q.first > PAGE) {
|
|
56
|
-
// a cap above one page: the next pages up to it
|
|
57
|
-
for (let offset = PAGE; offset < Math.min(q.first, first.totalCount); offset += PAGE)
|
|
58
|
-
rows.push(...(await page(offset)).nodes);
|
|
59
|
-
rows.length = Math.min(rows.length, q.first);
|
|
60
|
-
}
|
|
61
|
-
return rows;
|
|
62
|
-
}
|
|
63
|
-
// ─── column parsers ──────────────────────────────────────────────────────────
|
|
64
|
-
/** A numeric / bigint column (BigFloat or BigInt string, or a number) → bigint; the integer part. */
|
|
65
|
-
function big(v) {
|
|
66
|
-
if (typeof v === "bigint")
|
|
67
|
-
return v;
|
|
68
|
-
if (typeof v === "number")
|
|
69
|
-
return BigInt(Math.trunc(v));
|
|
70
|
-
if (typeof v !== "string" || v === "")
|
|
71
|
-
throw new Error(`views: not a number: ${JSON.stringify(v)}`);
|
|
72
|
-
return BigInt(v.split(".")[0]);
|
|
73
|
-
}
|
|
74
|
-
const bigOr = (v) => (v === null || v === undefined ? null : big(v));
|
|
75
|
-
const num = (v) => Number(v);
|
|
76
|
-
const numOr = (v) => (v === null || v === undefined ? null : Number(v));
|
|
77
|
-
const intOr = (v) => (v === null || v === undefined ? null : Number(v));
|
|
78
|
-
const addr = (v) => getAddress(String(v));
|
|
79
|
-
const addrOr = (v) => (v === null || v === undefined ? null : getAddress(String(v)));
|
|
80
|
-
const secs = (v) => Date.parse(String(v)) / 1000;
|
|
81
|
-
const secsOr = (v) => (v === null || v === undefined ? null : secs(v));
|
|
82
|
-
const hex = (v) => String(v).toLowerCase();
|
|
83
|
-
const addrs = (v) => (v ?? []).map(addr);
|
|
84
|
-
export async function poolDirectory(url, q = {}) {
|
|
85
|
-
const rows = await viewRows(url, "allPoolDirectories", "PoolDirectory", "side poolId manager kind quote bases swapFee tickSpacing policy creator birthBlock birthTime shareKey", q);
|
|
86
|
-
return rows.map((r) => ({
|
|
87
|
-
side: r.side, poolId: hex(r.poolId), manager: addr(r.manager), kind: String(r.kind), quote: addr(r.quote), bases: addrs(r.bases),
|
|
88
|
-
swapFee: big(r.swapFee), tickSpacing: bigOr(r.tickSpacing), policy: addrOr(r.policy), creator: addrOr(r.creator),
|
|
89
|
-
birthBlock: big(r.birthBlock), birthTime: secs(r.birthTime), shareKey: bigOr(r.shareKey),
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
export async function eventUsers(url, q = {}) {
|
|
93
|
-
const rows = await viewRows(url, "allEventUsers", "EventUser", "side event poolId actor viaRouter user txHash logIndex blockNumber blockTimestamp manager", q);
|
|
94
|
-
return rows.map((r) => ({
|
|
95
|
-
side: r.side, event: String(r.event), poolId: hex(r.poolId), actor: addr(r.actor), viaRouter: Boolean(r.viaRouter), user: addr(r.user),
|
|
96
|
-
txHash: hex(r.txHash), logIndex: num(r.logIndex), blockNumber: big(r.blockNumber), blockTimestamp: secs(r.blockTimestamp), manager: addr(r.manager),
|
|
97
|
-
}));
|
|
98
|
-
}
|
|
99
|
-
export async function poolHolders(url, q = {}) {
|
|
100
|
-
const rows = await viewRows(url, "allPoolHolders", "PoolHolder", "side manager id poolId gen floor cap capped holder balance isBackstop isDead", q);
|
|
101
|
-
return rows.map((r) => ({
|
|
102
|
-
side: r.side, manager: addr(r.manager), id: big(r.id), poolId: r.poolId == null ? null : hex(r.poolId), gen: intOr(r.gen),
|
|
103
|
-
floor: bigOr(r.floor), cap: bigOr(r.cap), capped: r.capped == null ? null : Boolean(r.capped),
|
|
104
|
-
holder: addr(r.holder), balance: big(r.balance), isBackstop: Boolean(r.isBackstop), isDead: Boolean(r.isDead),
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
export async function walletPositions(url, q = {}) {
|
|
108
|
-
const rows = await viewRows(url, "allWalletPositions", "WalletPosition", "side manager wallet poolId kind quote bases id gen floor cap capped shares valueQuote status valuedAtBlock", q);
|
|
109
|
-
return rows.map((r) => ({
|
|
110
|
-
side: r.side, manager: addr(r.manager), wallet: addr(r.wallet), poolId: r.poolId == null ? null : hex(r.poolId), kind: r.kind == null ? null : String(r.kind),
|
|
111
|
-
quote: addrOr(r.quote), bases: addrs(r.bases), id: big(r.id), gen: intOr(r.gen), floor: bigOr(r.floor), cap: bigOr(r.cap),
|
|
112
|
-
capped: r.capped == null ? null : Boolean(r.capped), shares: big(r.shares), valueQuote: bigOr(r.valueQuote), status: String(r.status), valuedAtBlock: bigOr(r.valuedAtBlock),
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
export async function walletPoolFlows(url, q = {}) {
|
|
116
|
-
const rows = await viewRows(url, "allWalletPoolFlows", "WalletPoolFlow", "side manager wallet poolId baseIn quoteIn baseOut quoteOut feesRealised dividendsClaimed redeemedQuote entries exits firstTime lastTime", q);
|
|
117
|
-
return rows.map((r) => ({
|
|
118
|
-
side: r.side, manager: addr(r.manager), wallet: addr(r.wallet), poolId: hex(r.poolId),
|
|
119
|
-
baseIn: big(r.baseIn), quoteIn: big(r.quoteIn), baseOut: big(r.baseOut), quoteOut: big(r.quoteOut),
|
|
120
|
-
feesRealised: big(r.feesRealised), dividendsClaimed: big(r.dividendsClaimed), redeemedQuote: big(r.redeemedQuote),
|
|
121
|
-
entries: num(r.entries), exits: num(r.exits), firstTime: secs(r.firstTime), lastTime: secs(r.lastTime),
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
export async function swapFlows(url, q = {}) {
|
|
125
|
-
const rows = await viewRows(url, "allSwapFlows", "SwapFlow", "side manager poolId txHash logIndex blockNumber blockTimestamp volumeQuote feeQuote tokenIn tokenOut reserveIn reserveOut lIn lOut", q);
|
|
126
|
-
return rows.map((r) => ({
|
|
127
|
-
side: r.side, manager: addr(r.manager), poolId: hex(r.poolId), txHash: hex(r.txHash), logIndex: num(r.logIndex),
|
|
128
|
-
blockNumber: big(r.blockNumber), blockTimestamp: secs(r.blockTimestamp), volumeQuote: big(r.volumeQuote), feeQuote: big(r.feeQuote),
|
|
129
|
-
tokenIn: addrOr(r.tokenIn), tokenOut: addrOr(r.tokenOut), reserveIn: bigOr(r.reserveIn), reserveOut: bigOr(r.reserveOut), lIn: bigOr(r.lIn), lOut: bigOr(r.lOut),
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
export async function priceTicks(url, q = {}) {
|
|
133
|
-
const rows = await viewRows(url, "allPriceTicks", "PriceTick", "side poolId base blockNumber blockTimestamp logIndex priceRaw volumeQuote feeQuote", q);
|
|
134
|
-
return rows.map((r) => ({
|
|
135
|
-
side: r.side, poolId: hex(r.poolId), base: addr(r.base), blockNumber: big(r.blockNumber), blockTimestamp: secs(r.blockTimestamp),
|
|
136
|
-
logIndex: num(r.logIndex), priceRaw: num(r.priceRaw), volumeQuote: big(r.volumeQuote), feeQuote: big(r.feeQuote),
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
const CANDLE = { minute: ["allCandleMinutes", "CandleMinute"], hour: ["allCandleHours", "CandleHour"], day: ["allCandleDays", "CandleDay"] };
|
|
140
|
-
export async function candles(url, interval, q = {}) {
|
|
141
|
-
const [field, type] = CANDLE[interval];
|
|
142
|
-
const rows = await viewRows(url, field, type, "side poolId base bucket open high low close volumeQuote feeQuote swaps", q);
|
|
143
|
-
return rows.map((r) => ({
|
|
144
|
-
side: r.side, poolId: hex(r.poolId), base: addr(r.base), bucket: secs(r.bucket), open: num(r.open), high: num(r.high), low: num(r.low), close: num(r.close),
|
|
145
|
-
volumeQuote: big(r.volumeQuote), feeQuote: big(r.feeQuote), swaps: num(r.swaps),
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
export async function poolTvlHours(url, q = {}) {
|
|
149
|
-
const rows = await viewRows(url, "allPoolTvlHours", "PoolTvlHour", "side poolId bucket blockNumber tvlQuote liquidity priceRaw feeGrowth shareValue gen", q);
|
|
150
|
-
return rows.map((r) => ({
|
|
151
|
-
side: r.side, poolId: hex(r.poolId), bucket: secs(r.bucket), blockNumber: big(r.blockNumber), tvlQuote: bigOr(r.tvlQuote),
|
|
152
|
-
liquidity: bigOr(r.liquidity), priceRaw: numOr(r.priceRaw), feeGrowth: bigOr(r.feeGrowth), shareValue: bigOr(r.shareValue), gen: intOr(r.gen),
|
|
153
|
-
}));
|
|
154
|
-
}
|
|
155
|
-
export async function poolSummaries(url, q = {}) {
|
|
156
|
-
const rows = await viewRows(url, "allPoolSummaries", "PoolSummary", "side poolId kind quote bases swapFee birthTime volume24H fees24H swaps24H volume7D fees7D volumeAll feesAll lastSwap tvlQuote liquidity priceRaw shareValue gen stateBlock seconds24H seconds7D apy24H apy7D", q);
|
|
157
|
-
return rows.map((r) => ({
|
|
158
|
-
side: r.side, poolId: hex(r.poolId), kind: String(r.kind), quote: addr(r.quote), bases: addrs(r.bases), swapFee: big(r.swapFee), birthTime: secs(r.birthTime),
|
|
159
|
-
volume24h: big(r.volume24H), fees24h: big(r.fees24H), swaps24h: num(r.swaps24H), volume7d: big(r.volume7D), fees7d: big(r.fees7D),
|
|
160
|
-
volumeAll: big(r.volumeAll), feesAll: big(r.feesAll), lastSwap: secsOr(r.lastSwap), tvlQuote: bigOr(r.tvlQuote), liquidity: bigOr(r.liquidity),
|
|
161
|
-
priceRaw: numOr(r.priceRaw), shareValue: bigOr(r.shareValue), gen: intOr(r.gen), stateBlock: bigOr(r.stateBlock),
|
|
162
|
-
seconds24h: num(r.seconds24H), seconds7d: num(r.seconds7D), apy24h: numOr(r.apy24H), apy7d: numOr(r.apy7D),
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
export async function generationSteps(url, q = {}) {
|
|
166
|
-
const rows = await viewRows(url, "allGenerationSteps", "GenerationStep", "kind poolId genAfter income payee toPayee deepened rung txHash blockNumber blockTimestamp", q);
|
|
167
|
-
return rows.map((r) => ({
|
|
168
|
-
kind: r.kind == null ? null : String(r.kind), poolId: hex(r.poolId), genAfter: num(r.genAfter), income: big(r.income), payee: addr(r.payee),
|
|
169
|
-
toPayee: big(r.toPayee), deepened: big(r.deepened), rung: intOr(r.rung),
|
|
170
|
-
txHash: hex(r.txHash), blockNumber: big(r.blockNumber), blockTimestamp: secs(r.blockTimestamp),
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
export async function padStatuses(url, q = {}) {
|
|
174
|
-
const rows = await viewRows(url, "allPadStatuses", "PadStatus", "kind poolId quote bases creator birthTime gen income unharvested l q tvlQuote shareValue threshold progress stateBlock stateTime steps paidTotal deepenedTotal lastStep", q);
|
|
175
|
-
return rows.map((r) => ({
|
|
176
|
-
kind: String(r.kind), poolId: hex(r.poolId), quote: addr(r.quote), bases: addrs(r.bases), creator: addrOr(r.creator), birthTime: secs(r.birthTime),
|
|
177
|
-
gen: intOr(r.gen), income: bigOr(r.income), unharvested: bigOr(r.unharvested), l: bigOr(r.l), q: bigOr(r.q), tvlQuote: bigOr(r.tvlQuote),
|
|
178
|
-
shareValue: bigOr(r.shareValue), threshold: bigOr(r.threshold), progress: numOr(r.progress), stateBlock: bigOr(r.stateBlock), stateTime: secsOr(r.stateTime),
|
|
179
|
-
steps: num(r.steps), paidTotal: big(r.paidTotal), deepenedTotal: big(r.deepenedTotal), lastStep: secsOr(r.lastStep),
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
export async function protocolRevenueDays(url, q = {}) {
|
|
183
|
-
const rows = await viewRows(url, "allProtocolRevenueDays", "ProtocolRevenueDay", "day side source basis token amount amountQuote events", q);
|
|
184
|
-
return rows.map((r) => ({
|
|
185
|
-
day: secs(r.day), side: r.side, source: String(r.source), basis: r.basis, token: addr(r.token),
|
|
186
|
-
amount: big(r.amount), amountQuote: big(r.amountQuote), events: num(r.events),
|
|
187
|
-
}));
|
|
188
|
-
}
|