@net-protocol/score 0.1.8 → 0.1.10
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 +30 -0
- package/dist/index.d.mts +107 -28
- package/dist/index.d.ts +107 -28
- package/dist/index.js +474 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +475 -39
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +3 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +3 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{scoreKeyUtils-BjMpyhyX.d.mts → scoreKeyUtils-BQl5oCSc.d.mts} +1 -1
- package/dist/{scoreKeyUtils-BjMpyhyX.d.ts → scoreKeyUtils-BQl5oCSc.d.ts} +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ Net Score is a decentralized on-chain scoring system built on Net Protocol. It a
|
|
|
25
25
|
- **Decode upvote messages** from Net protocol (legacy and strategy formats)
|
|
26
26
|
- **Decode strategy metadata** to inspect vote weight details
|
|
27
27
|
- **Select strategies** automatically based on pool key availability
|
|
28
|
+
- **Compute token leaderboards** with `getTokenRankings()` — the same time-decayed ranking that powers the website's `/token/<chain>/trending` page (`trending` / `recent` / `top` sorts)
|
|
28
29
|
|
|
29
30
|
This package provides both React hooks (for UI) and a client class (for non-React code).
|
|
30
31
|
|
|
@@ -128,6 +129,29 @@ const appCounts = await client.getAppKeyScores({
|
|
|
128
129
|
});
|
|
129
130
|
```
|
|
130
131
|
|
|
132
|
+
### Token Rankings
|
|
133
|
+
|
|
134
|
+
`getTokenRankings()` returns the same leaderboard that powers the website's
|
|
135
|
+
`/token/<chain>/trending` page — read live from chain with no off-chain index.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { getTokenRankings } from "@net-protocol/score";
|
|
139
|
+
|
|
140
|
+
const tokens = await getTokenRankings({
|
|
141
|
+
chainId: 8453,
|
|
142
|
+
sort: "trending", // "trending" | "recent" | "top"
|
|
143
|
+
maxTokens: 50,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
for (const t of tokens) {
|
|
147
|
+
console.log(t.symbol, t.upvotes, t.fdv, t.priceInUsdc);
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Each call performs ~8 RPC reads. Production callers should cache via HTTP
|
|
152
|
+
`Cache-Control` headers or an edge cache. Only Base (chainId 8453) is
|
|
153
|
+
supported today; other chains throw synchronously.
|
|
154
|
+
|
|
131
155
|
## API Reference
|
|
132
156
|
|
|
133
157
|
### ScoreClient
|
|
@@ -139,6 +163,12 @@ const appCounts = await client.getAppKeyScores({
|
|
|
139
163
|
| `getStrategyKeyScores(opts)` | Get scores for keys from a specific strategy |
|
|
140
164
|
| `getAppKeyScores(opts)` | Get scores for keys from a specific app |
|
|
141
165
|
|
|
166
|
+
### Token Rankings
|
|
167
|
+
|
|
168
|
+
| Function | Description |
|
|
169
|
+
|----------|-------------|
|
|
170
|
+
| `getTokenRankings(opts)` | Compute a token leaderboard ranked by upvote activity (`trending` / `recent` / `top`). Mirrors the website's `/token/<chain>/trending` page. |
|
|
171
|
+
|
|
142
172
|
### React Hooks
|
|
143
173
|
|
|
144
174
|
| Hook | Description |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions,
|
|
2
|
-
export { f as DecodedUpvoteBlob, F as FeedMessage, g as PoolStrategyMetadata, h as PureAlphaMetadata, i as ScoreItem, U as UseTokenUpvotesOptions, j as UseUpvotePriceOptions, k as UseUpvoteUserOptions, l as UseUpvotesBatchOptions, m as UseUpvotesOptions, n as UseUserUpvotesGivenOptions, o as UseUserUpvotesGivenPerTokenBatchOptions, p as UseUserUpvotesReceivedOptions, q as UseUserUpvotesReceivedPerTokenBatchOptions, r as extractTokenAddressFromScoreKey, s as getFeedContentKey, t as getScoreKey, u as getStorageScoreKey, v as getStorageUpvoteContext, w as getTokenScoreKey, x as isTokenScoreKey } from './scoreKeyUtils-
|
|
1
|
+
import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, P as PoolDiscoveryPair, d as PoolDiscoveryResult, D as DecodedStrategyMetadata, e as PoolKey } from './scoreKeyUtils-BQl5oCSc.mjs';
|
|
2
|
+
export { f as DecodedUpvoteBlob, F as FeedMessage, g as PoolStrategyMetadata, h as PureAlphaMetadata, i as ScoreItem, U as UseTokenUpvotesOptions, j as UseUpvotePriceOptions, k as UseUpvoteUserOptions, l as UseUpvotesBatchOptions, m as UseUpvotesOptions, n as UseUserUpvotesGivenOptions, o as UseUserUpvotesGivenPerTokenBatchOptions, p as UseUserUpvotesReceivedOptions, q as UseUserUpvotesReceivedPerTokenBatchOptions, r as extractTokenAddressFromScoreKey, s as getFeedContentKey, t as getScoreKey, u as getStorageScoreKey, v as getStorageUpvoteContext, w as getTokenScoreKey, x as isTokenScoreKey } from './scoreKeyUtils-BQl5oCSc.mjs';
|
|
3
3
|
import { Address, WalletClient, PublicClient, Abi } from 'viem';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -149,6 +149,106 @@ declare class UserUpvoteClient {
|
|
|
149
149
|
}): Promise<`0x${string}`>;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
|
|
154
|
+
*/
|
|
155
|
+
declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
|
|
156
|
+
/**
|
|
157
|
+
* Discover the best Uniswap pools for multiple token pairs.
|
|
158
|
+
* Makes two on-chain calls: pool discovery + pool info retrieval.
|
|
159
|
+
*/
|
|
160
|
+
declare function discoverPools({ publicClient, pairs, chainId, }: {
|
|
161
|
+
publicClient: PublicClient;
|
|
162
|
+
pairs: PoolDiscoveryPair[];
|
|
163
|
+
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
164
|
+
chainId?: number;
|
|
165
|
+
}): Promise<PoolDiscoveryResult[]>;
|
|
166
|
+
/**
|
|
167
|
+
* Discover the best WETH pool for a single token.
|
|
168
|
+
* Convenience wrapper around discoverPools.
|
|
169
|
+
*/
|
|
170
|
+
declare function discoverTokenPool({ publicClient, tokenAddress, chainId, }: {
|
|
171
|
+
publicClient: PublicClient;
|
|
172
|
+
tokenAddress: string;
|
|
173
|
+
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
174
|
+
chainId?: number;
|
|
175
|
+
}): Promise<PoolDiscoveryResult | null>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* How to rank tokens by upvote activity.
|
|
179
|
+
*
|
|
180
|
+
* - `trending`: time-decayed score, recent upvotes weighted higher.
|
|
181
|
+
* Matches the website's "Hot" / default tab on /token/<chain>/trending.
|
|
182
|
+
* - `recent`: latest upvote timestamp
|
|
183
|
+
* - `top`: aggregate upvote count (via UpvoteApp.getUpvotesWithLegacy)
|
|
184
|
+
*/
|
|
185
|
+
type RankingSort = "trending" | "recent" | "top";
|
|
186
|
+
interface RankedToken {
|
|
187
|
+
address: Address;
|
|
188
|
+
name?: string;
|
|
189
|
+
symbol?: string;
|
|
190
|
+
decimals?: number;
|
|
191
|
+
/** Fully Diluted Valuation in USDC, when price + supply are available */
|
|
192
|
+
fdv?: number;
|
|
193
|
+
/** Token price in USDC, derived from the best token/WETH pool and WETH/USDC */
|
|
194
|
+
priceInUsdc?: number;
|
|
195
|
+
/** Aggregate upvote count from UpvoteApp.getUpvotesWithLegacy across all strategies */
|
|
196
|
+
upvotes: number;
|
|
197
|
+
/** Unix timestamp (seconds) of the most recent upvote event seen in the scan window */
|
|
198
|
+
latestUpvoteTimestamp: number;
|
|
199
|
+
}
|
|
200
|
+
interface GetTokenRankingsOptions {
|
|
201
|
+
chainId: number;
|
|
202
|
+
/**
|
|
203
|
+
* Maximum number of tokens to return. The function fetches and ranks more
|
|
204
|
+
* tokens than this internally to account for filtering. Default: 50 (matches
|
|
205
|
+
* the website's /token/<chain>/trending page).
|
|
206
|
+
*/
|
|
207
|
+
maxTokens?: number;
|
|
208
|
+
/** Default: "trending" */
|
|
209
|
+
sort?: RankingSort;
|
|
210
|
+
/**
|
|
211
|
+
* Number of recent messages to scan per contract (legacy + 3 strategies).
|
|
212
|
+
* Larger = more historical coverage, more RPC cost. Default: 150.
|
|
213
|
+
*/
|
|
214
|
+
messageScanWindow?: number;
|
|
215
|
+
/**
|
|
216
|
+
* Two-tier filtering thresholds, copied from the website defaults. Tokens
|
|
217
|
+
* that meet at least one of these qualify for the top slots; others fill
|
|
218
|
+
* remaining slots up to `maxTokens`.
|
|
219
|
+
*/
|
|
220
|
+
thresholds?: {
|
|
221
|
+
/** Minimum aggregate upvotes to qualify for the top slots. Default: 500 */
|
|
222
|
+
minUpvotes?: number;
|
|
223
|
+
/** Minimum FDV (USDC) to qualify for the top slots. Default: 40_000 */
|
|
224
|
+
minMarketCap?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Tokens below `minMarketCap` are dropped entirely if they have no
|
|
227
|
+
* upvotes within this many hours. Default: 48
|
|
228
|
+
*/
|
|
229
|
+
recencyHours?: number;
|
|
230
|
+
};
|
|
231
|
+
/** Optional RPC URL override. If omitted, uses the package's defaults for the chain. */
|
|
232
|
+
rpcUrl?: string | string[];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Compute a token leaderboard ranked by upvote activity, mirroring the
|
|
237
|
+
* /token/<chain>/trending page on netprotocol.app.
|
|
238
|
+
*
|
|
239
|
+
* Reads recent Net Protocol upvote messages for the legacy upvote contract
|
|
240
|
+
* and the three strategy contracts, aggregates them into per-token events,
|
|
241
|
+
* scores them by the chosen sort, then enriches the top results with ERC20
|
|
242
|
+
* metadata, Uniswap pool pricing, and aggregate upvote counts.
|
|
243
|
+
*
|
|
244
|
+
* All reads are live from chain — no off-chain index. Callers should cache
|
|
245
|
+
* results (e.g. HTTP `Cache-Control`) since each call performs ~8 RPC reads.
|
|
246
|
+
*
|
|
247
|
+
* Currently supports only chains in SUPPORTED_SCORE_CHAINS (Base mainnet).
|
|
248
|
+
* Throws synchronously for any other chain.
|
|
249
|
+
*/
|
|
250
|
+
declare function getTokenRankings(options: GetTokenRankingsOptions): Promise<RankedToken[]>;
|
|
251
|
+
|
|
152
252
|
/**
|
|
153
253
|
* Convert token address to bytes32 upvote key.
|
|
154
254
|
*/
|
|
@@ -268,31 +368,6 @@ declare function decodeUpvoteMessage(msg: {
|
|
|
268
368
|
*/
|
|
269
369
|
declare const encodePoolKey: (poolKey?: PoolKey | null) => `0x${string}`;
|
|
270
370
|
|
|
271
|
-
/**
|
|
272
|
-
* Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
|
|
273
|
-
*/
|
|
274
|
-
declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
|
|
275
|
-
/**
|
|
276
|
-
* Discover the best Uniswap pools for multiple token pairs.
|
|
277
|
-
* Makes two on-chain calls: pool discovery + pool info retrieval.
|
|
278
|
-
*/
|
|
279
|
-
declare function discoverPools({ publicClient, pairs, chainId, }: {
|
|
280
|
-
publicClient: PublicClient;
|
|
281
|
-
pairs: PoolDiscoveryPair[];
|
|
282
|
-
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
283
|
-
chainId?: number;
|
|
284
|
-
}): Promise<PoolDiscoveryResult[]>;
|
|
285
|
-
/**
|
|
286
|
-
* Discover the best WETH pool for a single token.
|
|
287
|
-
* Convenience wrapper around discoverPools.
|
|
288
|
-
*/
|
|
289
|
-
declare function discoverTokenPool({ publicClient, tokenAddress, chainId, }: {
|
|
290
|
-
publicClient: PublicClient;
|
|
291
|
-
tokenAddress: string;
|
|
292
|
-
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
293
|
-
chainId?: number;
|
|
294
|
-
}): Promise<PoolDiscoveryResult | null>;
|
|
295
|
-
|
|
296
371
|
declare const SCORE_CONTRACT: {
|
|
297
372
|
readonly address: Address;
|
|
298
373
|
readonly abi: Abi;
|
|
@@ -339,6 +414,10 @@ declare const USER_UPVOTE_CONTRACT: {
|
|
|
339
414
|
readonly address: Address;
|
|
340
415
|
readonly abi: Abi;
|
|
341
416
|
};
|
|
417
|
+
declare const ERC20_BULK_INFO_HELPER_CONTRACT: {
|
|
418
|
+
readonly address: Address;
|
|
419
|
+
readonly abi: Abi;
|
|
420
|
+
};
|
|
342
421
|
|
|
343
422
|
/**
|
|
344
423
|
* Parse a Net protocol message from the user upvote contract.
|
|
@@ -400,4 +479,4 @@ declare function buildUserUpvoteReceived(parsed: ParsedUserUpvoteMessage, upvote
|
|
|
400
479
|
decimals: number;
|
|
401
480
|
}): UserUpvoteReceived;
|
|
402
481
|
|
|
403
|
-
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, type ParsedUserUpvoteMessage, PoolDiscoveryPair, PoolDiscoveryResult, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, type TokenAddressExtraction, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, USER_UPVOTE_CONTRACT, type UserUpvote, UserUpvoteClient, type UserUpvoteClientOptions, type UserUpvoteNetMessage, type UserUpvoteReceived, buildUserUpvote, buildUserUpvoteReceived, calculatePriceFromSqrtPriceX96, calculatePriceInUsdc, calculateUpvoteCost, calculateUserTokenBalance, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressesFromMessages, getWethAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, parseUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString, validateUpvoteParams, validateUserUpvoteMessage };
|
|
482
|
+
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, ERC20_BULK_INFO_HELPER_CONTRACT, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, type GetTokenRankingsOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, type ParsedUserUpvoteMessage, PoolDiscoveryPair, PoolDiscoveryResult, PoolKey, type RankedToken, type RankingSort, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, type TokenAddressExtraction, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, USER_UPVOTE_CONTRACT, type UserUpvote, UserUpvoteClient, type UserUpvoteClientOptions, type UserUpvoteNetMessage, type UserUpvoteReceived, buildUserUpvote, buildUserUpvoteReceived, calculatePriceFromSqrtPriceX96, calculatePriceInUsdc, calculateUpvoteCost, calculateUserTokenBalance, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressesFromMessages, getTokenRankings, getWethAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, parseUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString, validateUpvoteParams, validateUserUpvoteMessage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions,
|
|
2
|
-
export { f as DecodedUpvoteBlob, F as FeedMessage, g as PoolStrategyMetadata, h as PureAlphaMetadata, i as ScoreItem, U as UseTokenUpvotesOptions, j as UseUpvotePriceOptions, k as UseUpvoteUserOptions, l as UseUpvotesBatchOptions, m as UseUpvotesOptions, n as UseUserUpvotesGivenOptions, o as UseUserUpvotesGivenPerTokenBatchOptions, p as UseUserUpvotesReceivedOptions, q as UseUserUpvotesReceivedPerTokenBatchOptions, r as extractTokenAddressFromScoreKey, s as getFeedContentKey, t as getScoreKey, u as getStorageScoreKey, v as getStorageUpvoteContext, w as getTokenScoreKey, x as isTokenScoreKey } from './scoreKeyUtils-
|
|
1
|
+
import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, P as PoolDiscoveryPair, d as PoolDiscoveryResult, D as DecodedStrategyMetadata, e as PoolKey } from './scoreKeyUtils-BQl5oCSc.js';
|
|
2
|
+
export { f as DecodedUpvoteBlob, F as FeedMessage, g as PoolStrategyMetadata, h as PureAlphaMetadata, i as ScoreItem, U as UseTokenUpvotesOptions, j as UseUpvotePriceOptions, k as UseUpvoteUserOptions, l as UseUpvotesBatchOptions, m as UseUpvotesOptions, n as UseUserUpvotesGivenOptions, o as UseUserUpvotesGivenPerTokenBatchOptions, p as UseUserUpvotesReceivedOptions, q as UseUserUpvotesReceivedPerTokenBatchOptions, r as extractTokenAddressFromScoreKey, s as getFeedContentKey, t as getScoreKey, u as getStorageScoreKey, v as getStorageUpvoteContext, w as getTokenScoreKey, x as isTokenScoreKey } from './scoreKeyUtils-BQl5oCSc.js';
|
|
3
3
|
import { Address, WalletClient, PublicClient, Abi } from 'viem';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -149,6 +149,106 @@ declare class UserUpvoteClient {
|
|
|
149
149
|
}): Promise<`0x${string}`>;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
|
|
154
|
+
*/
|
|
155
|
+
declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
|
|
156
|
+
/**
|
|
157
|
+
* Discover the best Uniswap pools for multiple token pairs.
|
|
158
|
+
* Makes two on-chain calls: pool discovery + pool info retrieval.
|
|
159
|
+
*/
|
|
160
|
+
declare function discoverPools({ publicClient, pairs, chainId, }: {
|
|
161
|
+
publicClient: PublicClient;
|
|
162
|
+
pairs: PoolDiscoveryPair[];
|
|
163
|
+
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
164
|
+
chainId?: number;
|
|
165
|
+
}): Promise<PoolDiscoveryResult[]>;
|
|
166
|
+
/**
|
|
167
|
+
* Discover the best WETH pool for a single token.
|
|
168
|
+
* Convenience wrapper around discoverPools.
|
|
169
|
+
*/
|
|
170
|
+
declare function discoverTokenPool({ publicClient, tokenAddress, chainId, }: {
|
|
171
|
+
publicClient: PublicClient;
|
|
172
|
+
tokenAddress: string;
|
|
173
|
+
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
174
|
+
chainId?: number;
|
|
175
|
+
}): Promise<PoolDiscoveryResult | null>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* How to rank tokens by upvote activity.
|
|
179
|
+
*
|
|
180
|
+
* - `trending`: time-decayed score, recent upvotes weighted higher.
|
|
181
|
+
* Matches the website's "Hot" / default tab on /token/<chain>/trending.
|
|
182
|
+
* - `recent`: latest upvote timestamp
|
|
183
|
+
* - `top`: aggregate upvote count (via UpvoteApp.getUpvotesWithLegacy)
|
|
184
|
+
*/
|
|
185
|
+
type RankingSort = "trending" | "recent" | "top";
|
|
186
|
+
interface RankedToken {
|
|
187
|
+
address: Address;
|
|
188
|
+
name?: string;
|
|
189
|
+
symbol?: string;
|
|
190
|
+
decimals?: number;
|
|
191
|
+
/** Fully Diluted Valuation in USDC, when price + supply are available */
|
|
192
|
+
fdv?: number;
|
|
193
|
+
/** Token price in USDC, derived from the best token/WETH pool and WETH/USDC */
|
|
194
|
+
priceInUsdc?: number;
|
|
195
|
+
/** Aggregate upvote count from UpvoteApp.getUpvotesWithLegacy across all strategies */
|
|
196
|
+
upvotes: number;
|
|
197
|
+
/** Unix timestamp (seconds) of the most recent upvote event seen in the scan window */
|
|
198
|
+
latestUpvoteTimestamp: number;
|
|
199
|
+
}
|
|
200
|
+
interface GetTokenRankingsOptions {
|
|
201
|
+
chainId: number;
|
|
202
|
+
/**
|
|
203
|
+
* Maximum number of tokens to return. The function fetches and ranks more
|
|
204
|
+
* tokens than this internally to account for filtering. Default: 50 (matches
|
|
205
|
+
* the website's /token/<chain>/trending page).
|
|
206
|
+
*/
|
|
207
|
+
maxTokens?: number;
|
|
208
|
+
/** Default: "trending" */
|
|
209
|
+
sort?: RankingSort;
|
|
210
|
+
/**
|
|
211
|
+
* Number of recent messages to scan per contract (legacy + 3 strategies).
|
|
212
|
+
* Larger = more historical coverage, more RPC cost. Default: 150.
|
|
213
|
+
*/
|
|
214
|
+
messageScanWindow?: number;
|
|
215
|
+
/**
|
|
216
|
+
* Two-tier filtering thresholds, copied from the website defaults. Tokens
|
|
217
|
+
* that meet at least one of these qualify for the top slots; others fill
|
|
218
|
+
* remaining slots up to `maxTokens`.
|
|
219
|
+
*/
|
|
220
|
+
thresholds?: {
|
|
221
|
+
/** Minimum aggregate upvotes to qualify for the top slots. Default: 500 */
|
|
222
|
+
minUpvotes?: number;
|
|
223
|
+
/** Minimum FDV (USDC) to qualify for the top slots. Default: 40_000 */
|
|
224
|
+
minMarketCap?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Tokens below `minMarketCap` are dropped entirely if they have no
|
|
227
|
+
* upvotes within this many hours. Default: 48
|
|
228
|
+
*/
|
|
229
|
+
recencyHours?: number;
|
|
230
|
+
};
|
|
231
|
+
/** Optional RPC URL override. If omitted, uses the package's defaults for the chain. */
|
|
232
|
+
rpcUrl?: string | string[];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Compute a token leaderboard ranked by upvote activity, mirroring the
|
|
237
|
+
* /token/<chain>/trending page on netprotocol.app.
|
|
238
|
+
*
|
|
239
|
+
* Reads recent Net Protocol upvote messages for the legacy upvote contract
|
|
240
|
+
* and the three strategy contracts, aggregates them into per-token events,
|
|
241
|
+
* scores them by the chosen sort, then enriches the top results with ERC20
|
|
242
|
+
* metadata, Uniswap pool pricing, and aggregate upvote counts.
|
|
243
|
+
*
|
|
244
|
+
* All reads are live from chain — no off-chain index. Callers should cache
|
|
245
|
+
* results (e.g. HTTP `Cache-Control`) since each call performs ~8 RPC reads.
|
|
246
|
+
*
|
|
247
|
+
* Currently supports only chains in SUPPORTED_SCORE_CHAINS (Base mainnet).
|
|
248
|
+
* Throws synchronously for any other chain.
|
|
249
|
+
*/
|
|
250
|
+
declare function getTokenRankings(options: GetTokenRankingsOptions): Promise<RankedToken[]>;
|
|
251
|
+
|
|
152
252
|
/**
|
|
153
253
|
* Convert token address to bytes32 upvote key.
|
|
154
254
|
*/
|
|
@@ -268,31 +368,6 @@ declare function decodeUpvoteMessage(msg: {
|
|
|
268
368
|
*/
|
|
269
369
|
declare const encodePoolKey: (poolKey?: PoolKey | null) => `0x${string}`;
|
|
270
370
|
|
|
271
|
-
/**
|
|
272
|
-
* Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
|
|
273
|
-
*/
|
|
274
|
-
declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
|
|
275
|
-
/**
|
|
276
|
-
* Discover the best Uniswap pools for multiple token pairs.
|
|
277
|
-
* Makes two on-chain calls: pool discovery + pool info retrieval.
|
|
278
|
-
*/
|
|
279
|
-
declare function discoverPools({ publicClient, pairs, chainId, }: {
|
|
280
|
-
publicClient: PublicClient;
|
|
281
|
-
pairs: PoolDiscoveryPair[];
|
|
282
|
-
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
283
|
-
chainId?: number;
|
|
284
|
-
}): Promise<PoolDiscoveryResult[]>;
|
|
285
|
-
/**
|
|
286
|
-
* Discover the best WETH pool for a single token.
|
|
287
|
-
* Convenience wrapper around discoverPools.
|
|
288
|
-
*/
|
|
289
|
-
declare function discoverTokenPool({ publicClient, tokenAddress, chainId, }: {
|
|
290
|
-
publicClient: PublicClient;
|
|
291
|
-
tokenAddress: string;
|
|
292
|
-
/** Chain ID used to resolve the WETH address. Defaults to Base (8453). */
|
|
293
|
-
chainId?: number;
|
|
294
|
-
}): Promise<PoolDiscoveryResult | null>;
|
|
295
|
-
|
|
296
371
|
declare const SCORE_CONTRACT: {
|
|
297
372
|
readonly address: Address;
|
|
298
373
|
readonly abi: Abi;
|
|
@@ -339,6 +414,10 @@ declare const USER_UPVOTE_CONTRACT: {
|
|
|
339
414
|
readonly address: Address;
|
|
340
415
|
readonly abi: Abi;
|
|
341
416
|
};
|
|
417
|
+
declare const ERC20_BULK_INFO_HELPER_CONTRACT: {
|
|
418
|
+
readonly address: Address;
|
|
419
|
+
readonly abi: Abi;
|
|
420
|
+
};
|
|
342
421
|
|
|
343
422
|
/**
|
|
344
423
|
* Parse a Net protocol message from the user upvote contract.
|
|
@@ -400,4 +479,4 @@ declare function buildUserUpvoteReceived(parsed: ParsedUserUpvoteMessage, upvote
|
|
|
400
479
|
decimals: number;
|
|
401
480
|
}): UserUpvoteReceived;
|
|
402
481
|
|
|
403
|
-
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, type ParsedUserUpvoteMessage, PoolDiscoveryPair, PoolDiscoveryResult, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, type TokenAddressExtraction, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, USER_UPVOTE_CONTRACT, type UserUpvote, UserUpvoteClient, type UserUpvoteClientOptions, type UserUpvoteNetMessage, type UserUpvoteReceived, buildUserUpvote, buildUserUpvoteReceived, calculatePriceFromSqrtPriceX96, calculatePriceInUsdc, calculateUpvoteCost, calculateUserTokenBalance, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressesFromMessages, getWethAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, parseUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString, validateUpvoteParams, validateUserUpvoteMessage };
|
|
482
|
+
export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, ERC20_BULK_INFO_HELPER_CONTRACT, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, type GetTokenRankingsOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, MULTI_VERSION_UNISWAP_BULK_POOL_FINDER, MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER, NULL_ADDRESS, PURE_ALPHA_STRATEGY, type ParsedUserUpvoteMessage, PoolDiscoveryPair, PoolDiscoveryResult, PoolKey, type RankedToken, type RankingSort, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, type TokenAddressExtraction, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, USER_UPVOTE_CONTRACT, type UserUpvote, UserUpvoteClient, type UserUpvoteClientOptions, type UserUpvoteNetMessage, type UserUpvoteReceived, buildUserUpvote, buildUserUpvoteReceived, calculatePriceFromSqrtPriceX96, calculatePriceInUsdc, calculateUpvoteCost, calculateUserTokenBalance, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, extractTokenAddressesFromMessages, getTokenRankings, getWethAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, parseUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString, validateUpvoteParams, validateUserUpvoteMessage };
|