@net-protocol/score 0.1.0 → 0.1.1

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 ADDED
@@ -0,0 +1,229 @@
1
+ # @net-protocol/score
2
+
3
+ **Status: In Development** - This package is under active development. APIs may change without notice.
4
+
5
+ SDK for the Net Score system - an on-chain scoring/upvoting system for tokens, storage entries, and feed posts on Net Protocol.
6
+
7
+ ## What is Net Score?
8
+
9
+ Net Score is a decentralized on-chain scoring system built on Net Protocol. It allows users to upvote content (tokens, storage entries, feed posts) using strategy-based voting where vote weight is derived from on-chain holdings.
10
+
11
+ **Key features:**
12
+ - **Token Upvotes**: Upvote tokens by address
13
+ - **Storage Upvotes**: Upvote storage entries by operator and key
14
+ - **Feed Upvotes**: Upvote feed posts by content
15
+ - **Strategy-Based Voting**: Vote weight is determined by on-chain strategies (Alpha holdings, Uniswap pool positions, or configurable splits)
16
+ - **Legacy Support**: Aggregates scores across legacy upvote contracts and current strategies
17
+
18
+ ## What can you do with this package?
19
+
20
+ - **Read upvote counts** for tokens, storage entries, and feed posts
21
+ - **Batch-read upvotes** for multiple items in a single contract call
22
+ - **Query scores by strategy** to see per-strategy breakdowns
23
+ - **Query scores by app** for app-specific score data
24
+ - **Generate score keys** for any scoreable item type
25
+ - **Decode upvote messages** from Net protocol (legacy and strategy formats)
26
+ - **Decode strategy metadata** to inspect vote weight details
27
+ - **Select strategies** automatically based on pool key availability
28
+
29
+ This package provides both React hooks (for UI) and a client class (for non-React code).
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ npm install @net-protocol/score @net-protocol/core @net-protocol/storage viem
35
+ # or
36
+ yarn add @net-protocol/score @net-protocol/core @net-protocol/storage viem
37
+ ```
38
+
39
+ For React hooks, also install:
40
+ ```bash
41
+ npm install react wagmi @tanstack/react-query
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### React Hooks
47
+
48
+ ```typescript
49
+ import { useTokenUpvotes, useUpvotes, useUpvotesBatch } from "@net-protocol/score/react";
50
+ import { getTokenScoreKey, getStorageScoreKey } from "@net-protocol/score/react";
51
+
52
+ // Get upvotes for a single token
53
+ function TokenScore({ tokenAddress }: { tokenAddress: string }) {
54
+ const { upvotes, isLoading } = useTokenUpvotes({
55
+ chainId: 8453,
56
+ tokenAddress,
57
+ });
58
+
59
+ if (isLoading) return <div>Loading...</div>;
60
+ return <div>Upvotes: {upvotes}</div>;
61
+ }
62
+
63
+ // Get upvotes for a single score key
64
+ function ScoreKeyUpvotes({ scoreKey }: { scoreKey: `0x${string}` }) {
65
+ const { upvotes, isLoading } = useUpvotes({
66
+ chainId: 8453,
67
+ scoreKey,
68
+ });
69
+
70
+ return <div>{isLoading ? "..." : upvotes}</div>;
71
+ }
72
+
73
+ // Batch-read upvotes for multiple items
74
+ function BatchScores() {
75
+ const { upvoteCounts, isLoading } = useUpvotesBatch({
76
+ chainId: 8453,
77
+ items: [
78
+ { type: "token", tokenAddress: "0x..." },
79
+ { type: "storage", operatorAddress: "0x...", storageKey: "my-key" },
80
+ ],
81
+ });
82
+
83
+ return (
84
+ <div>
85
+ {upvoteCounts.map((count, i) => (
86
+ <div key={i}>Item {i}: {count} upvotes</div>
87
+ ))}
88
+ </div>
89
+ );
90
+ }
91
+ ```
92
+
93
+ ### ScoreClient (Non-React)
94
+
95
+ ```typescript
96
+ import { ScoreClient } from "@net-protocol/score";
97
+ import { getTokenScoreKey, getStorageScoreKey } from "@net-protocol/score";
98
+
99
+ const client = new ScoreClient({ chainId: 8453 });
100
+
101
+ // Get upvote counts for token score keys
102
+ const tokenKey = getTokenScoreKey("0x...");
103
+ const counts = await client.getUpvotesWithLegacy({
104
+ scoreKeys: [tokenKey],
105
+ });
106
+ console.log("Upvotes:", counts[0]);
107
+
108
+ // Batch upvotes for mixed item types
109
+ const batchCounts = await client.getUpvotesForItems({
110
+ items: [
111
+ { type: "token", tokenAddress: "0x..." },
112
+ { type: "storage", operatorAddress: "0x...", storageKey: "my-key" },
113
+ ],
114
+ });
115
+
116
+ // Query scores from a specific strategy
117
+ import { PURE_ALPHA_STRATEGY } from "@net-protocol/score";
118
+
119
+ const strategyCounts = await client.getStrategyKeyScores({
120
+ strategy: PURE_ALPHA_STRATEGY.address,
121
+ scoreKeys: [tokenKey],
122
+ });
123
+
124
+ // Query scores from a specific app
125
+ const appCounts = await client.getAppKeyScores({
126
+ app: "0x...",
127
+ scoreKeys: [tokenKey],
128
+ });
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ ### ScoreClient
134
+
135
+ | Method | Description |
136
+ |--------|-------------|
137
+ | `getUpvotesWithLegacy(opts)` | Get upvote counts for score keys, aggregated across legacy contracts and strategies |
138
+ | `getUpvotesForItems(opts)` | Get upvote counts for an array of `ScoreItem` objects |
139
+ | `getStrategyKeyScores(opts)` | Get scores for keys from a specific strategy |
140
+ | `getAppKeyScores(opts)` | Get scores for keys from a specific app |
141
+
142
+ ### React Hooks
143
+
144
+ | Hook | Description |
145
+ |------|-------------|
146
+ | `useTokenUpvotes(opts)` | Get upvote count for a single token address |
147
+ | `useUpvotes(opts)` | Get upvote count for a single score key |
148
+ | `useUpvotesBatch(opts)` | Get upvote counts for multiple items in one call |
149
+
150
+ ### Score Key Utilities
151
+
152
+ | Function | Description |
153
+ |----------|-------------|
154
+ | `getTokenScoreKey(tokenAddress)` | Generate score key for a token |
155
+ | `getStorageScoreKey(operatorAddress, storageKey)` | Generate score key for a storage entry |
156
+ | `getFeedContentKey(message)` | Generate content key for a feed post |
157
+ | `getScoreKey(item)` | Generate score key for any `ScoreItem` |
158
+ | `isTokenScoreKey(scoreKey)` | Check if a score key represents a token |
159
+ | `extractTokenAddressFromScoreKey(scoreKey)` | Extract token address from a token score key |
160
+ | `getStorageUpvoteContext(operatorAddress, storageKey)` | Generate upvote stored context for storage upvotes |
161
+
162
+ ### Strategy Utilities
163
+
164
+ | Function | Description |
165
+ |----------|-------------|
166
+ | `selectStrategy(poolKey?)` | Select appropriate strategy based on pool key |
167
+ | `decodeStrategyMetadata(metadata, strategyAddress)` | Decode strategy-specific metadata |
168
+ | `decodeUpvoteStorageBlob(value)` | Decode a full Score storage blob |
169
+ | `decodeUpvoteMessage(msg)` | Decode an upvote message (legacy and strategy formats) |
170
+ | `encodePoolKey(poolKey?)` | Encode a PoolKey struct to bytes |
171
+
172
+ ### Types
173
+
174
+ ```typescript
175
+ // Scoreable item (discriminated union)
176
+ type ScoreItem =
177
+ | { type: "token"; tokenAddress: string }
178
+ | { type: "storage"; operatorAddress: string; storageKey: string }
179
+ | { type: "feed"; message: FeedMessage };
180
+
181
+ type FeedMessage = {
182
+ app: Address;
183
+ sender: Address;
184
+ timestamp: bigint;
185
+ data: `0x${string}`;
186
+ text: string;
187
+ topic: string;
188
+ };
189
+
190
+ // Client options
191
+ type ScoreClientOptions = {
192
+ chainId: number;
193
+ overrides?: {
194
+ scoreAddress?: Address;
195
+ upvoteAppAddress?: Address;
196
+ rpcUrls?: string[];
197
+ };
198
+ };
199
+ ```
200
+
201
+ ### Strategies
202
+
203
+ The Score system supports multiple voting strategies that determine vote weight:
204
+
205
+ | Strategy | Constant | Description |
206
+ |----------|----------|-------------|
207
+ | Pure Alpha | `PURE_ALPHA_STRATEGY` | Vote weight based on Alpha token holdings |
208
+ | Uni V2/V3/V4 Pools | `UNIV234_POOLS_STRATEGY` | Vote weight based on Uniswap pool positions |
209
+ | Dynamic Split | `DYNAMIC_SPLIT_STRATEGY` | Configurable token/alpha split for pool positions |
210
+
211
+ ### Constants
212
+
213
+ | Constant | Description |
214
+ |----------|-------------|
215
+ | `SCORE_CONTRACT` | Score core contract address and ABI |
216
+ | `UPVOTE_APP` | UpvoteApp contract address and ABI |
217
+ | `UPVOTE_STORAGE_APP` | UpvoteStorageApp contract address and ABI |
218
+ | `ALL_STRATEGY_ADDRESSES` | Array of all strategy contract addresses |
219
+ | `SUPPORTED_SCORE_CHAINS` | Chains where Score is deployed |
220
+
221
+ ## Supported Chains
222
+
223
+ | Chain | Chain ID | Status |
224
+ |-------|----------|--------|
225
+ | Base | 8453 | Supported |
226
+
227
+ ## License
228
+
229
+ MIT
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, D as DecodedStrategyMetadata, P as PoolKey } from './scoreKeyUtils-DIjbizO-.mjs';
2
- export { n as DecodedUpvoteBlob, F as FeedMessage, m as PoolStrategyMetadata, l as PureAlphaMetadata, k as ScoreItem, p as UseTokenUpvotesOptions, o as UseUpvotesBatchOptions, U as UseUpvotesOptions, h as extractTokenAddressFromScoreKey, e as getFeedContentKey, f as getScoreKey, d as getStorageScoreKey, j as getStorageUpvoteContext, g as getTokenScoreKey, i as isTokenScoreKey } from './scoreKeyUtils-DIjbizO-.mjs';
3
- import { Address, Abi } from 'viem';
1
+ import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, D as DecodedStrategyMetadata, P as PoolKey, d as PoolDiscoveryResult } from './scoreKeyUtils-Dn43l8hQ.mjs';
2
+ export { o as DecodedUpvoteBlob, F as FeedMessage, n as PoolStrategyMetadata, m as PureAlphaMetadata, l as ScoreItem, q as UseTokenUpvotesOptions, p as UseUpvotesBatchOptions, U as UseUpvotesOptions, j as extractTokenAddressFromScoreKey, f as getFeedContentKey, h as getScoreKey, e as getStorageScoreKey, k as getStorageUpvoteContext, g as getTokenScoreKey, i as isTokenScoreKey } from './scoreKeyUtils-Dn43l8hQ.mjs';
3
+ import { Address, PublicClient, Abi } from 'viem';
4
4
 
5
5
  /**
6
6
  * ScoreClient - Client for interacting with Net protocol scoring/upvote system
@@ -156,6 +156,30 @@ declare function decodeUpvoteMessage(msg: {
156
156
  */
157
157
  declare const encodePoolKey: (poolKey?: PoolKey | null) => `0x${string}`;
158
158
 
159
+ /**
160
+ * Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
161
+ */
162
+ declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
163
+ /**
164
+ * Discover the best Uniswap pools for multiple token pairs.
165
+ * Makes two on-chain calls: pool discovery + pool info retrieval.
166
+ */
167
+ declare function discoverPools({ publicClient, pairs, }: {
168
+ publicClient: PublicClient;
169
+ pairs: {
170
+ tokenAddress: string;
171
+ baseTokenAddress?: string;
172
+ }[];
173
+ }): Promise<PoolDiscoveryResult[]>;
174
+ /**
175
+ * Discover the best WETH pool for a single token.
176
+ * Convenience wrapper around discoverPools.
177
+ */
178
+ declare function discoverTokenPool({ publicClient, tokenAddress, }: {
179
+ publicClient: PublicClient;
180
+ tokenAddress: string;
181
+ }): Promise<PoolDiscoveryResult | null>;
182
+
159
183
  declare const SCORE_CONTRACT: {
160
184
  readonly address: Address;
161
185
  readonly abi: Abi;
@@ -184,5 +208,16 @@ declare const ALL_STRATEGY_ADDRESSES: Address[];
184
208
  declare const LEGACY_UPVOTE_V1_ADDRESS: Address;
185
209
  declare const LEGACY_UPVOTE_V2_ADDRESS: Address;
186
210
  declare const SUPPORTED_SCORE_CHAINS: readonly [8453];
211
+ declare const MULTI_VERSION_UNISWAP_BULK_POOL_FINDER: {
212
+ readonly address: Address;
213
+ readonly abi: Abi;
214
+ };
215
+ declare const MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER: {
216
+ readonly address: Address;
217
+ readonly abi: Abi;
218
+ };
219
+ declare const WETH_ADDRESS: Address;
220
+ declare const NULL_ADDRESS: Address;
221
+ declare const UPVOTE_PRICE_ETH = 0.000025;
187
222
 
188
- export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, PURE_ALPHA_STRATEGY, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_STORAGE_APP, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
223
+ 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, PoolDiscoveryResult, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, WETH_ADDRESS, calculatePriceFromSqrtPriceX96, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, D as DecodedStrategyMetadata, P as PoolKey } from './scoreKeyUtils-DIjbizO-.js';
2
- export { n as DecodedUpvoteBlob, F as FeedMessage, m as PoolStrategyMetadata, l as PureAlphaMetadata, k as ScoreItem, p as UseTokenUpvotesOptions, o as UseUpvotesBatchOptions, U as UseUpvotesOptions, h as extractTokenAddressFromScoreKey, e as getFeedContentKey, f as getScoreKey, d as getStorageScoreKey, j as getStorageUpvoteContext, g as getTokenScoreKey, i as isTokenScoreKey } from './scoreKeyUtils-DIjbizO-.js';
3
- import { Address, Abi } from 'viem';
1
+ import { S as ScoreClientOptions, G as GetUpvotesOptions, a as GetUpvotesForItemsOptions, b as GetStrategyKeyScoresOptions, c as GetAppKeyScoresOptions, D as DecodedStrategyMetadata, P as PoolKey, d as PoolDiscoveryResult } from './scoreKeyUtils-Dn43l8hQ.js';
2
+ export { o as DecodedUpvoteBlob, F as FeedMessage, n as PoolStrategyMetadata, m as PureAlphaMetadata, l as ScoreItem, q as UseTokenUpvotesOptions, p as UseUpvotesBatchOptions, U as UseUpvotesOptions, j as extractTokenAddressFromScoreKey, f as getFeedContentKey, h as getScoreKey, e as getStorageScoreKey, k as getStorageUpvoteContext, g as getTokenScoreKey, i as isTokenScoreKey } from './scoreKeyUtils-Dn43l8hQ.js';
3
+ import { Address, PublicClient, Abi } from 'viem';
4
4
 
5
5
  /**
6
6
  * ScoreClient - Client for interacting with Net protocol scoring/upvote system
@@ -156,6 +156,30 @@ declare function decodeUpvoteMessage(msg: {
156
156
  */
157
157
  declare const encodePoolKey: (poolKey?: PoolKey | null) => `0x${string}`;
158
158
 
159
+ /**
160
+ * Calculate price from sqrtPriceX96 for Uniswap V3/V4 pools.
161
+ */
162
+ declare function calculatePriceFromSqrtPriceX96(sqrtPriceX96: bigint, token0Decimals: number, token1Decimals: number, isToken0: boolean): number;
163
+ /**
164
+ * Discover the best Uniswap pools for multiple token pairs.
165
+ * Makes two on-chain calls: pool discovery + pool info retrieval.
166
+ */
167
+ declare function discoverPools({ publicClient, pairs, }: {
168
+ publicClient: PublicClient;
169
+ pairs: {
170
+ tokenAddress: string;
171
+ baseTokenAddress?: string;
172
+ }[];
173
+ }): Promise<PoolDiscoveryResult[]>;
174
+ /**
175
+ * Discover the best WETH pool for a single token.
176
+ * Convenience wrapper around discoverPools.
177
+ */
178
+ declare function discoverTokenPool({ publicClient, tokenAddress, }: {
179
+ publicClient: PublicClient;
180
+ tokenAddress: string;
181
+ }): Promise<PoolDiscoveryResult | null>;
182
+
159
183
  declare const SCORE_CONTRACT: {
160
184
  readonly address: Address;
161
185
  readonly abi: Abi;
@@ -184,5 +208,16 @@ declare const ALL_STRATEGY_ADDRESSES: Address[];
184
208
  declare const LEGACY_UPVOTE_V1_ADDRESS: Address;
185
209
  declare const LEGACY_UPVOTE_V2_ADDRESS: Address;
186
210
  declare const SUPPORTED_SCORE_CHAINS: readonly [8453];
211
+ declare const MULTI_VERSION_UNISWAP_BULK_POOL_FINDER: {
212
+ readonly address: Address;
213
+ readonly abi: Abi;
214
+ };
215
+ declare const MULTI_VERSION_UNISWAP_POOL_INFO_RETRIEVER: {
216
+ readonly address: Address;
217
+ readonly abi: Abi;
218
+ };
219
+ declare const WETH_ADDRESS: Address;
220
+ declare const NULL_ADDRESS: Address;
221
+ declare const UPVOTE_PRICE_ETH = 0.000025;
187
222
 
188
- export { ALL_STRATEGY_ADDRESSES, DYNAMIC_SPLIT_STRATEGY, DecodedStrategyMetadata, GetAppKeyScoresOptions, GetStrategyKeyScoresOptions, GetUpvotesForItemsOptions, GetUpvotesOptions, LEGACY_UPVOTE_V1_ADDRESS, LEGACY_UPVOTE_V2_ADDRESS, PURE_ALPHA_STRATEGY, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_STORAGE_APP, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };
223
+ 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, PoolDiscoveryResult, PoolKey, SCORE_CONTRACT, SUPPORTED_SCORE_CHAINS, ScoreClient, ScoreClientOptions, UNIV234_POOLS_STRATEGY, UPVOTE_APP, UPVOTE_PRICE_ETH, UPVOTE_STORAGE_APP, WETH_ADDRESS, calculatePriceFromSqrtPriceX96, decodeStrategyMetadata, decodeUpvoteMessage, decodeUpvoteStorageBlob, discoverPools, discoverTokenPool, encodePoolKey, encodeUpvoteKey, extractStrategyAddress, isDynamicSplitStrategy, isPureAlphaStrategy, isStrategyMessage, isUniv234PoolsStrategy, isUserUpvoteMessage, selectStrategy, tokenAddressToUpvoteKeyString };