@net-protocol/score 0.1.0
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/dist/index.d.mts +188 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.js +2152 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2120 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +86 -0
- package/dist/react.d.ts +86 -0
- package/dist/react.js +296 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +289 -0
- package/dist/react.mjs.map +1 -0
- package/dist/scoreKeyUtils-DIjbizO-.d.mts +135 -0
- package/dist/scoreKeyUtils-DIjbizO-.d.ts +135 -0
- package/package.json +93 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/abis/upvote-app.json","../src/constants.ts","../src/hooks/useUpvotes.ts","../src/utils/strategyUtils.ts","../src/utils/scoreKeyUtils.ts","../src/hooks/useUpvotesBatch.ts","../src/hooks/useTokenUpvotes.ts"],"names":["useReadContract","useMemo"],"mappings":";;;;;;;;AAAA,IAAA,kBAAA,GAAA;AAAA,EACE,EAAE,IAAA,EAAQ,aAAA,EAAe,QAAU,EAAC,EAAG,iBAAmB,YAAA,EAAa;AAAA,EACvE;AAAA,IACE,IAAA,EAAQ,UAAA;AAAA,IACR,IAAA,EAAQ,eAAA;AAAA,IACR,QAAU,EAAC;AAAA,IACX,OAAA,EAAW;AAAA,MACT,EAAE,IAAA,EAAQ,EAAA,EAAI,IAAA,EAAQ,SAAA,EAAW,cAAgB,gBAAA;AAAiB,KACpE;AAAA,IACA,eAAA,EAAmB;AAAA,GACrB;AAAA,EACA;AAAA,IACE,IAAA,EAAQ,UAAA;AAAA,IACR,IAAA,EAAQ,iBAAA;AAAA,IACR,QAAU,EAAC;AAAA,IACX,OAAA,EAAW;AAAA,MACT;AAAA,QACE,IAAA,EAAQ,EAAA;AAAA,QACR,IAAA,EAAQ,SAAA;AAAA,QACR,YAAA,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ACjDO,SAAS,eAAA,CAAgB;AAAA,EAC9B,OAAA;AAAA,EACA,KAAA;AAAA,EACA,UAAA,GAAa,sBAAA;AAAA,EACb,OAAA,GAAU;AACZ,CAAA,EAA2B;AACzB,EAAA,MAAM,SAAA,GAAY,OAAA;AAAA,IAChB,MAAM,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAS,WAAA,CAAY,IAAI,CAAC,CAAA;AAAA,IAC3C,CAAC,KAAK;AAAA,GACR;AAEA,EAAA,MAAM,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,OAAA,KAAYA,eAAAA,CAAgB;AAAA,IAC1D,SAAS,UAAA,CAAW,OAAA;AAAA,IACpB,KAAK,UAAA,CAAW,GAAA;AAAA,IAChB,YAAA,EAAc,sBAAA;AAAA,IACd,IAAA,EAAM,CAAC,SAAA,EAAW,UAAU,CAAA;AAAA,IAC5B,OAAA;AAAA,IACA,OAAO,EAAE,OAAA,EAAS,OAAA,IAAW,SAAA,CAAU,SAAS,CAAA;AAAE,GACnD,CAAA;AAED,EAAA,OAAO;AAAA,IACL,YAAA,EAAc,MAAM,OAAA,CAAQ,IAAI,IAAK,IAAA,CAAkB,GAAA,CAAI,MAAM,CAAA,GAAI,EAAC;AAAA,IACtE,SAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF;AC/BO,SAAS,eAAA,CAAgB;AAAA,EAC9B,OAAA;AAAA,EACA,YAAA;AAAA,EACA,OAAA,GAAU;AACZ,CAAA,EAA2B;AACzB,EAAA,MAAM,QAAA,GAAWC,OAAAA;AAAA,IACf,MAAM,iBAAiB,YAAY,CAAA;AAAA,IACnC,CAAC,YAAY;AAAA,GACf;AAEA,EAAA,OAAO,UAAA,CAAW,EAAE,OAAA,EAAS,QAAA,EAAU,SAAS,CAAA;AAClD","file":"react.mjs","sourcesContent":["[\n { \"type\": \"constructor\", \"inputs\": [], \"stateMutability\": \"nonpayable\" },\n {\n \"type\": \"function\",\n \"name\": \"CORE_CONTRACT\",\n \"inputs\": [],\n \"outputs\": [\n { \"name\": \"\", \"type\": \"address\", \"internalType\": \"contract Score\" }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"LEGACY_CONTRACT\",\n \"inputs\": [],\n \"outputs\": [\n {\n \"name\": \"\",\n \"type\": \"address\",\n \"internalType\": \"contract ILegacyUpvoteContract\"\n }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"getUpvotesWithLegacy\",\n \"inputs\": [\n {\n \"name\": \"upvoteKeys\",\n \"type\": \"bytes32[]\",\n \"internalType\": \"bytes32[]\"\n },\n {\n \"name\": \"strategies\",\n \"type\": \"address[]\",\n \"internalType\": \"address[]\"\n }\n ],\n \"outputs\": [\n { \"name\": \"counts\", \"type\": \"uint256[]\", \"internalType\": \"uint256[]\" }\n ],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"name\",\n \"inputs\": [],\n \"outputs\": [{ \"name\": \"\", \"type\": \"string\", \"internalType\": \"string\" }],\n \"stateMutability\": \"pure\"\n },\n {\n \"type\": \"function\",\n \"name\": \"owner\",\n \"inputs\": [],\n \"outputs\": [{ \"name\": \"\", \"type\": \"address\", \"internalType\": \"address\" }],\n \"stateMutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"renounceOwnership\",\n \"inputs\": [],\n \"outputs\": [],\n \"stateMutability\": \"nonpayable\"\n },\n {\n \"type\": \"function\",\n \"name\": \"transferOwnership\",\n \"inputs\": [\n { \"name\": \"newOwner\", \"type\": \"address\", \"internalType\": \"address\" }\n ],\n \"outputs\": [],\n \"stateMutability\": \"nonpayable\"\n },\n {\n \"type\": \"function\",\n \"name\": \"upvote\",\n \"inputs\": [\n {\n \"name\": \"strategy\",\n \"type\": \"address\",\n \"internalType\": \"contract IScoreStrategy\"\n },\n { \"name\": \"scoreKey\", \"type\": \"bytes32\", \"internalType\": \"bytes32\" },\n { \"name\": \"scoreDelta\", \"type\": \"uint256\", \"internalType\": \"uint256\" },\n {\n \"name\": \"scoreStoredContext\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n },\n {\n \"name\": \"scoreUnstoredContext\",\n \"type\": \"bytes\",\n \"internalType\": \"bytes\"\n }\n ],\n \"outputs\": [],\n \"stateMutability\": \"payable\"\n },\n {\n \"type\": \"function\",\n \"name\": \"withdrawETH\",\n \"inputs\": [{ \"name\": \"to\", \"type\": \"address\", \"internalType\": \"address\" }],\n \"outputs\": [],\n \"stateMutability\": \"nonpayable\"\n },\n {\n \"type\": \"function\",\n \"name\": \"withdrawErc20\",\n \"inputs\": [\n { \"name\": \"to\", \"type\": \"address\", \"internalType\": \"address\" },\n { \"name\": \"token\", \"type\": \"address\", \"internalType\": \"address\" },\n { \"name\": \"amount\", \"type\": \"uint256\", \"internalType\": \"uint256\" }\n ],\n \"outputs\": [],\n \"stateMutability\": \"nonpayable\"\n },\n {\n \"type\": \"event\",\n \"name\": \"OwnershipTransferred\",\n \"inputs\": [\n {\n \"name\": \"previousOwner\",\n \"type\": \"address\",\n \"indexed\": true,\n \"internalType\": \"address\"\n },\n {\n \"name\": \"newOwner\",\n \"type\": \"address\",\n \"indexed\": true,\n \"internalType\": \"address\"\n }\n ],\n \"anonymous\": false\n },\n {\n \"type\": \"error\",\n \"name\": \"OwnableInvalidOwner\",\n \"inputs\": [\n { \"name\": \"owner\", \"type\": \"address\", \"internalType\": \"address\" }\n ]\n },\n {\n \"type\": \"error\",\n \"name\": \"OwnableUnauthorizedAccount\",\n \"inputs\": [\n { \"name\": \"account\", \"type\": \"address\", \"internalType\": \"address\" }\n ]\n },\n { \"type\": \"error\", \"name\": \"WithdrawFailed\", \"inputs\": [] }\n]\n","import type { Abi, Address } from \"viem\";\nimport scoreAbi from \"./abis/score.json\";\nimport upvoteAppAbi from \"./abis/upvote-app.json\";\nimport upvoteStorageAppAbi from \"./abis/upvote-storage-app.json\";\nimport pureAlphaStrategyAbi from \"./abis/pure-alpha-strategy.json\";\nimport univ234PoolsStrategyAbi from \"./abis/univ234-pools-strategy.json\";\nimport dynamicSplitStrategyAbi from \"./abis/dynamic-split-strategy.json\";\n\n// Score core contract (v2 strategy)\nexport const SCORE_CONTRACT = {\n address: \"0x0000000fa09b022e5616e5a173b4b67fa2fbcf28\" as Address,\n abi: scoreAbi as Abi,\n} as const;\n\n// UpvoteApp contract\nexport const UPVOTE_APP = {\n address: \"0x00000001f0b8173316a016a5067ad74e8cea47bf\" as Address,\n abi: upvoteAppAbi as Abi,\n} as const;\n\n// UpvoteStorageApp contract\nexport const UPVOTE_STORAGE_APP = {\n address: \"0x000000060CEB69D023227DF64CfB75eC37c75B62\" as Address,\n abi: upvoteStorageAppAbi as Abi,\n} as const;\n\n// UpvotePureAlphaStrategy contract\nexport const PURE_ALPHA_STRATEGY = {\n address: \"0x00000001b1bcdeddeafd5296aaf4f3f3e21ae876\" as Address,\n abi: pureAlphaStrategyAbi as Abi,\n} as const;\n\n// UpvoteUniv234PoolsStrategy (handles Uniswap V2, V3, V4 pools)\nexport const UNIV234_POOLS_STRATEGY = {\n address: \"0x000000063f84e07a3e7a7ee578b42704ee6d22c9\" as Address,\n abi: univ234PoolsStrategyAbi as Abi,\n} as const;\n\n// UpvoteDynamicSplitUniv234PoolsStrategy (configurable token/alpha split for Uni V2/V3/V4 pools)\nexport const DYNAMIC_SPLIT_STRATEGY = {\n address: \"0x0000000869160f0b2a213adefb46a7ea7e62ac7a\" as Address,\n abi: dynamicSplitStrategyAbi as Abi,\n} as const;\n\n// All strategy addresses for batch queries\nexport const ALL_STRATEGY_ADDRESSES: Address[] = [\n UNIV234_POOLS_STRATEGY.address,\n PURE_ALPHA_STRATEGY.address,\n DYNAMIC_SPLIT_STRATEGY.address,\n];\n\n// Legacy upvote contract addresses (v1 and v2, before Score system)\nexport const LEGACY_UPVOTE_V1_ADDRESS =\n \"0x0ada882dbbdc12388a1f9ca85d2d847088f747df\" as Address;\n\nexport const LEGACY_UPVOTE_V2_ADDRESS =\n \"0x9027dcad0a3dca5835895e14fbc022a1e5ea909b\" as Address;\n\n// Chains where the Score system is deployed\nexport const SUPPORTED_SCORE_CHAINS = [8453] as const;\n","import { useReadContract } from \"wagmi\";\nimport { UPVOTE_APP, ALL_STRATEGY_ADDRESSES } from \"../constants\";\nimport type { UseUpvotesOptions } from \"../types\";\n\n/**\n * React hook for fetching the upvote count for a single score key.\n * Uses UpvoteApp.getUpvotesWithLegacy, which aggregates across legacy contracts and strategies.\n *\n * @param options - Upvote query options\n * @param options.chainId - Chain ID to query\n * @param options.scoreKey - The bytes32 score key to look up\n * @param options.strategies - Strategy addresses to include (default: all strategies)\n * @param options.enabled - Whether the query is enabled (default: true)\n * @returns Object with upvotes count, isLoading, error, and refetch\n *\n * @example\n * ```tsx\n * const { upvotes, isLoading } = useUpvotes({\n * chainId: 8453,\n * scoreKey: getTokenScoreKey(tokenAddress),\n * });\n * ```\n */\nexport function useUpvotes({\n chainId,\n scoreKey,\n strategies = ALL_STRATEGY_ADDRESSES,\n enabled = true,\n}: UseUpvotesOptions) {\n const { data, isLoading, error, refetch } = useReadContract({\n address: UPVOTE_APP.address,\n abi: UPVOTE_APP.abi,\n functionName: \"getUpvotesWithLegacy\",\n args: [[scoreKey], strategies],\n chainId,\n query: { enabled },\n });\n\n return {\n upvotes: Array.isArray(data) && data.length > 0 ? Number(data[0]) : 0,\n isLoading,\n error,\n refetch,\n };\n}\n","import { decodeAbiParameters, type Address } from \"viem\";\nimport {\n PURE_ALPHA_STRATEGY,\n UNIV234_POOLS_STRATEGY,\n DYNAMIC_SPLIT_STRATEGY,\n} from \"../constants\";\nimport type {\n PureAlphaMetadata,\n PoolStrategyMetadata,\n DecodedStrategyMetadata,\n PoolKey,\n} from \"../types\";\n\n/**\n * Convert token address to bytes32 upvote key.\n */\nexport const encodeUpvoteKey = (tokenAddress: string): `0x${string}` => {\n return `0x${BigInt(`0x${tokenAddress.slice(2)}`)\n .toString(16)\n .padStart(64, \"0\")}`;\n};\n\n/**\n * Convert token address to upvote key string format.\n * Strips leading zeros to match Solidity's Strings.toHexString(uint256(scoreKey)).\n */\nexport function tokenAddressToUpvoteKeyString(tokenAddress: string): string {\n const lower = tokenAddress.toLowerCase();\n const withoutPrefix = lower.slice(2);\n const stripped = withoutPrefix.replace(/^0+/, \"\") || \"0\";\n return \"0x\" + stripped;\n}\n\n/**\n * Check if a topic string represents a strategy message.\n */\nexport function isStrategyMessage(topic: string): boolean {\n return topic.startsWith(\"s\") && topic.length > 43;\n}\n\n/**\n * Check if a topic string represents a user upvote message.\n */\nexport function isUserUpvoteMessage(topic: string): boolean {\n return topic.startsWith(\"t\");\n}\n\n/**\n * Extracts strategy address from topic string.\n * Handles both new format and legacy format.\n */\nexport function extractStrategyAddress(topic: string): string {\n try {\n if (topic.startsWith(\"t\")) {\n return topic.slice(1);\n }\n\n if (topic.startsWith(\"s\")) {\n return topic.slice(1, 43);\n }\n\n if (topic.startsWith(\"t-\")) {\n return topic.slice(2);\n }\n\n const parts = topic.split(\"-\");\n if (parts.length >= 2) {\n return parts[0];\n }\n\n return \"\";\n } catch {\n return \"\";\n }\n}\n\nexport function isPureAlphaStrategy(strategyAddress: string): boolean {\n return (\n strategyAddress.toLowerCase() ===\n PURE_ALPHA_STRATEGY.address.toLowerCase()\n );\n}\n\nexport function isUniv234PoolsStrategy(strategyAddress: string): boolean {\n return (\n strategyAddress.toLowerCase() ===\n UNIV234_POOLS_STRATEGY.address.toLowerCase()\n );\n}\n\nexport function isDynamicSplitStrategy(strategyAddress: string): boolean {\n return (\n strategyAddress.toLowerCase() ===\n DYNAMIC_SPLIT_STRATEGY.address.toLowerCase()\n );\n}\n\n/**\n * Decode strategy-specific metadata from ABI-encoded bytes.\n */\nexport const decodeStrategyMetadata = (\n metadata: `0x${string}`,\n strategyAddress: string\n): DecodedStrategyMetadata => {\n try {\n if (isPureAlphaStrategy(strategyAddress)) {\n const [alphaAmount, alphaWethPrice, wethUsdcPrice, userAlphaBalance] =\n decodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n ],\n metadata\n );\n return {\n alphaAmount,\n alphaWethPrice,\n wethUsdcPrice,\n userAlphaBalance,\n } as PureAlphaMetadata;\n } else if (\n isUniv234PoolsStrategy(strategyAddress) ||\n isDynamicSplitStrategy(strategyAddress)\n ) {\n const [\n tokenAmount,\n tokenWethPrice,\n wethUsdcPrice,\n alphaWethPrice,\n userTokenBalance,\n ] = decodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n ],\n metadata\n );\n return {\n tokenAmount,\n tokenWethPrice,\n wethUsdcPrice,\n alphaWethPrice,\n userTokenBalance,\n } as PoolStrategyMetadata;\n } else {\n return null;\n }\n } catch {\n return null;\n }\n};\n\n/**\n * Decode the full Score storage blob.\n */\nexport const decodeUpvoteStorageBlob = (value: `0x${string}`) => {\n try {\n const [\n scoreKey,\n scoreDelta,\n originalSender,\n appAddress,\n strategyAddress,\n timestamp,\n scoreStoredContext,\n scoreUnstoredContext,\n metadata,\n ] = decodeAbiParameters(\n [\n { type: \"bytes32\" },\n { type: \"int256\" },\n { type: \"address\" },\n { type: \"address\" },\n { type: \"address\" },\n { type: \"uint256\" },\n { type: \"bytes\" },\n { type: \"bytes\" },\n { type: \"bytes\" },\n ],\n value\n );\n\n const decodedMetadata = decodeStrategyMetadata(\n metadata as `0x${string}`,\n strategyAddress as string\n );\n\n return {\n scoreKey: scoreKey as `0x${string}`,\n scoreDelta: Number(scoreDelta),\n originalSender: originalSender as Address,\n appAddress: appAddress as Address,\n strategyAddress: strategyAddress as Address,\n timestamp: Number(timestamp),\n scoreStoredContext: scoreStoredContext as `0x${string}`,\n scoreUnstoredContext: scoreUnstoredContext as `0x${string}`,\n decodedMetadata,\n };\n } catch {\n return null;\n }\n};\n\n/**\n * Select the appropriate strategy based on pool key validity.\n * Returns PURE_ALPHA if no valid pool key; DYNAMIC_SPLIT otherwise.\n */\nexport const selectStrategy = (poolKey?: PoolKey | null): Address => {\n if (!poolKey || !isValidPoolKey(poolKey)) {\n return PURE_ALPHA_STRATEGY.address;\n }\n return DYNAMIC_SPLIT_STRATEGY.address;\n};\n\nfunction isValidPoolKey(poolKey: PoolKey): boolean {\n return (\n poolKey.fee !== undefined ||\n poolKey.tickSpacing !== undefined ||\n poolKey.currency0 !== undefined\n );\n}\n\n/**\n * Decode an upvote message from Net protocol into a consistent format.\n * Handles both legacy and strategy message formats.\n */\nexport function decodeUpvoteMessage(msg: {\n topic: string;\n data: `0x${string}`;\n text: string;\n}) {\n try {\n if (msg.topic === \"t\") {\n if (!msg.data || msg.data === \"0x\" || msg.data.length < 32) {\n return null;\n }\n\n try {\n const [\n numUpvotesDecoded,\n tokenWethPrice,\n wethUsdcPrice,\n alphaWethPrice,\n userTokenBalance,\n ] = decodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n ],\n msg.data\n );\n\n return {\n scoreDelta: Number(numUpvotesDecoded),\n tokenWethPrice: Number(tokenWethPrice),\n wethUsdcPrice: Number(wethUsdcPrice),\n alphaWethPrice: Number(alphaWethPrice),\n userTokenBalance: Number(userTokenBalance),\n tokenAddress: msg.text,\n messageType: \"legacy\" as const,\n };\n } catch {\n return null;\n }\n } else if (\n (msg.topic.startsWith(\"0x\") && msg.topic.length === 42) ||\n msg.topic.startsWith(\"p-\")\n ) {\n const [\n numUpvotesDecoded,\n tokenWethPrice,\n wethUsdcPrice,\n alphaWethPrice,\n userTokenBalance,\n ] = decodeAbiParameters(\n [\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n ],\n msg.data\n );\n\n return {\n scoreDelta: Number(numUpvotesDecoded),\n tokenWethPrice: Number(tokenWethPrice),\n wethUsdcPrice: Number(wethUsdcPrice),\n alphaWethPrice: Number(alphaWethPrice),\n userTokenBalance: Number(userTokenBalance),\n tokenAddress: msg.topic,\n messageType: \"legacy\" as const,\n };\n } else if (msg.topic.startsWith(\"app-\") && msg.topic.endsWith(\"-first\")) {\n const topicParts = msg.topic.split(\"-\");\n\n if (topicParts.length === 3) {\n // \"app-{addr}-first\"\n return {\n appAddress: topicParts[1],\n messageType: \"app-first\" as const,\n };\n } else if (topicParts.length === 5 && topicParts[2] === \"strategy\") {\n // \"app-{addr}-strategy-{strat}-first\"\n return {\n appAddress: topicParts[1],\n strategyAddress: topicParts[3],\n messageType: \"app-strategy-first\" as const,\n };\n } else if (topicParts.length === 5 && topicParts[2] === \"user\") {\n // \"app-{addr}-user-{user}-first\"\n return {\n appAddress: topicParts[1],\n userAddress: topicParts[3],\n tokenAddress: msg.text,\n messageType: \"app-user-first\" as const,\n };\n } else if (\n topicParts.length === 7 &&\n topicParts[2] === \"strategy\" &&\n topicParts[4] === \"user\"\n ) {\n // \"app-{addr}-strategy-{strat}-user-{user}-first\"\n return {\n appAddress: topicParts[1],\n strategyAddress: topicParts[3],\n userAddress: topicParts[5],\n tokenAddress: msg.text,\n messageType: \"app-strategy-user-first\" as const,\n };\n }\n }\n\n return null;\n } catch {\n return null;\n }\n}\n","import {\n type Address,\n encodeAbiParameters,\n keccak256,\n encodePacked,\n getAddress,\n} from \"viem\";\nimport { getStorageKeyBytes } from \"@net-protocol/storage\";\nimport { encodeUpvoteKey } from \"./strategyUtils\";\nimport type { ScoreItem, FeedMessage } from \"../types\";\n\n/**\n * Generate score key for token upvotes.\n * Pads the token address into a bytes32 value.\n */\nexport const getTokenScoreKey = (tokenAddress: string): `0x${string}` => {\n return encodeUpvoteKey(tokenAddress);\n};\n\n/**\n * Generate score key for storage upvotes.\n * keccak256(encodePacked(storageKeyBytes32, operatorAddress))\n */\nexport const getStorageScoreKey = (\n operatorAddress: string,\n storageKey: string\n): `0x${string}` => {\n const bytes32Key = getStorageKeyBytes(storageKey) as `0x${string}`;\n return keccak256(\n encodePacked(\n [\"bytes32\", \"address\"],\n [bytes32Key, operatorAddress as Address]\n )\n );\n};\n\n/**\n * Generate content-based key for feed posts.\n * Uses all message content to create a unique identifier that's\n * independent of query filter (works regardless of how messages are fetched).\n *\n * Two messages with identical content will share the same key (and upvotes),\n * which is semantically correct - they are the same content.\n */\nexport const getFeedContentKey = (message: FeedMessage): `0x${string}` => {\n return keccak256(\n encodePacked(\n [\"address\", \"string\", \"address\", \"uint256\", \"string\", \"bytes\"],\n [\n message.app,\n message.topic,\n message.sender,\n message.timestamp,\n message.text,\n message.data,\n ]\n )\n );\n};\n\n/**\n * Get score key for any ScoreItem type.\n */\nexport const getScoreKey = (item: ScoreItem): `0x${string}` => {\n switch (item.type) {\n case \"token\":\n return getTokenScoreKey(item.tokenAddress);\n case \"storage\":\n return getStorageScoreKey(item.operatorAddress, item.storageKey);\n case \"feed\": {\n const contentKey = getFeedContentKey(item.message);\n return getStorageScoreKey(\n item.message.sender,\n contentKey\n );\n }\n }\n};\n\n/**\n * Check if a score key represents a token upvote (zero-padded address)\n * vs a hash-based key (storage/feed).\n */\nexport const isTokenScoreKey = (scoreKey: string): boolean => {\n return scoreKey.startsWith(\"0x000000000000000000000000\");\n};\n\n/**\n * Extract and validate token address from a token score key.\n * Returns the checksummed address or null if invalid.\n */\nexport const extractTokenAddressFromScoreKey = (\n scoreKey: string\n): string | null => {\n if (!isTokenScoreKey(scoreKey)) {\n return null;\n }\n\n const tokenAddress = `0x${scoreKey.slice(26)}`;\n\n if (tokenAddress.startsWith(\"0x\") && tokenAddress.length === 42) {\n try {\n return getAddress(tokenAddress);\n } catch {\n return null;\n }\n }\n\n return null;\n};\n\n/**\n * Generate upvote stored context for storage upvotes.\n * ABI-encodes (bytes32 storageKeyBytes, address operatorAddress).\n */\nexport const getStorageUpvoteContext = (\n operatorAddress: string,\n storageKey: string\n): `0x${string}` => {\n const bytes32Key = getStorageKeyBytes(storageKey) as `0x${string}`;\n return encodeAbiParameters(\n [{ type: \"bytes32\" }, { type: \"address\" }],\n [bytes32Key, operatorAddress as Address]\n );\n};\n","import { useMemo } from \"react\";\nimport { useReadContract } from \"wagmi\";\nimport { UPVOTE_APP, ALL_STRATEGY_ADDRESSES } from \"../constants\";\nimport { getScoreKey } from \"../utils/scoreKeyUtils\";\nimport type { UseUpvotesBatchOptions } from \"../types\";\n\n/**\n * React hook for fetching upvote counts for multiple ScoreItems in a single contract call.\n * Uses UpvoteApp.getUpvotesWithLegacy with batched score keys.\n *\n * @param options - Batch upvote query options\n * @param options.chainId - Chain ID to query\n * @param options.items - Array of ScoreItems (token, storage, or feed) to get counts for\n * @param options.strategies - Strategy addresses to include (default: all strategies)\n * @param options.enabled - Whether the query is enabled (default: true)\n * @returns Object with upvoteCounts array, isLoading, error, and refetch\n *\n * @example\n * ```tsx\n * const { upvoteCounts, isLoading } = useUpvotesBatch({\n * chainId: 8453,\n * items: [\n * { type: \"token\", tokenAddress: \"0x...\" },\n * { type: \"storage\", operatorAddress: \"0x...\", storageKey: \"my-key\" },\n * ],\n * });\n * ```\n */\nexport function useUpvotesBatch({\n chainId,\n items,\n strategies = ALL_STRATEGY_ADDRESSES,\n enabled = true,\n}: UseUpvotesBatchOptions) {\n const scoreKeys = useMemo(\n () => items.map((item) => getScoreKey(item)),\n [items]\n );\n\n const { data, isLoading, error, refetch } = useReadContract({\n address: UPVOTE_APP.address,\n abi: UPVOTE_APP.abi,\n functionName: \"getUpvotesWithLegacy\",\n args: [scoreKeys, strategies],\n chainId,\n query: { enabled: enabled && scoreKeys.length > 0 },\n });\n\n return {\n upvoteCounts: Array.isArray(data) ? (data as bigint[]).map(Number) : [],\n isLoading,\n error,\n refetch,\n };\n}\n","import { useMemo } from \"react\";\nimport { useUpvotes } from \"./useUpvotes\";\nimport { getTokenScoreKey } from \"../utils/scoreKeyUtils\";\nimport type { UseTokenUpvotesOptions } from \"../types\";\n\n/**\n * Convenience React hook for fetching upvotes for a single token address.\n * Wraps useUpvotes with automatic token score key generation.\n *\n * @param options - Token upvote query options\n * @param options.chainId - Chain ID to query\n * @param options.tokenAddress - The token contract address\n * @param options.enabled - Whether the query is enabled (default: true)\n * @returns Object with upvotes count, isLoading, error, and refetch\n *\n * @example\n * ```tsx\n * const { upvotes, isLoading } = useTokenUpvotes({\n * chainId: 8453,\n * tokenAddress: \"0x...\",\n * });\n * ```\n */\nexport function useTokenUpvotes({\n chainId,\n tokenAddress,\n enabled = true,\n}: UseTokenUpvotesOptions) {\n const scoreKey = useMemo(\n () => getTokenScoreKey(tokenAddress),\n [tokenAddress]\n );\n\n return useUpvotes({ chainId, scoreKey, enabled });\n}\n"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
type ScoreItem = {
|
|
4
|
+
type: "token";
|
|
5
|
+
tokenAddress: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "storage";
|
|
8
|
+
operatorAddress: string;
|
|
9
|
+
storageKey: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: "feed";
|
|
12
|
+
message: FeedMessage;
|
|
13
|
+
};
|
|
14
|
+
type FeedMessage = {
|
|
15
|
+
app: Address;
|
|
16
|
+
sender: Address;
|
|
17
|
+
timestamp: bigint;
|
|
18
|
+
data: `0x${string}`;
|
|
19
|
+
text: string;
|
|
20
|
+
topic: string;
|
|
21
|
+
};
|
|
22
|
+
type PoolKey = {
|
|
23
|
+
currency0: string;
|
|
24
|
+
currency1: string;
|
|
25
|
+
fee: number;
|
|
26
|
+
tickSpacing: number;
|
|
27
|
+
hooks: string;
|
|
28
|
+
};
|
|
29
|
+
type PureAlphaMetadata = {
|
|
30
|
+
alphaAmount: bigint;
|
|
31
|
+
alphaWethPrice: bigint;
|
|
32
|
+
wethUsdcPrice: bigint;
|
|
33
|
+
userAlphaBalance: bigint;
|
|
34
|
+
};
|
|
35
|
+
type PoolStrategyMetadata = {
|
|
36
|
+
tokenAmount: bigint;
|
|
37
|
+
tokenWethPrice: bigint;
|
|
38
|
+
wethUsdcPrice: bigint;
|
|
39
|
+
alphaWethPrice: bigint;
|
|
40
|
+
userTokenBalance: bigint;
|
|
41
|
+
};
|
|
42
|
+
type DecodedStrategyMetadata = PureAlphaMetadata | PoolStrategyMetadata | null;
|
|
43
|
+
type DecodedUpvoteBlob = {
|
|
44
|
+
scoreKey: `0x${string}`;
|
|
45
|
+
scoreDelta: number;
|
|
46
|
+
originalSender: Address;
|
|
47
|
+
appAddress: Address;
|
|
48
|
+
strategyAddress: Address;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
scoreStoredContext: `0x${string}`;
|
|
51
|
+
scoreUnstoredContext: `0x${string}`;
|
|
52
|
+
decodedMetadata: DecodedStrategyMetadata;
|
|
53
|
+
} | null;
|
|
54
|
+
type ScoreClientOptions = {
|
|
55
|
+
chainId: number;
|
|
56
|
+
overrides?: {
|
|
57
|
+
scoreAddress?: Address;
|
|
58
|
+
upvoteAppAddress?: Address;
|
|
59
|
+
rpcUrls?: string[];
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
type GetUpvotesOptions = {
|
|
63
|
+
scoreKeys: `0x${string}`[];
|
|
64
|
+
strategies?: Address[];
|
|
65
|
+
};
|
|
66
|
+
type GetUpvotesForItemsOptions = {
|
|
67
|
+
items: ScoreItem[];
|
|
68
|
+
strategies?: Address[];
|
|
69
|
+
};
|
|
70
|
+
type GetStrategyKeyScoresOptions = {
|
|
71
|
+
strategy: Address;
|
|
72
|
+
scoreKeys: `0x${string}`[];
|
|
73
|
+
};
|
|
74
|
+
type GetAppKeyScoresOptions = {
|
|
75
|
+
app: Address;
|
|
76
|
+
scoreKeys: `0x${string}`[];
|
|
77
|
+
};
|
|
78
|
+
type UseUpvotesOptions = {
|
|
79
|
+
chainId: number;
|
|
80
|
+
scoreKey: `0x${string}`;
|
|
81
|
+
strategies?: Address[];
|
|
82
|
+
enabled?: boolean;
|
|
83
|
+
};
|
|
84
|
+
type UseUpvotesBatchOptions = {
|
|
85
|
+
chainId: number;
|
|
86
|
+
items: ScoreItem[];
|
|
87
|
+
strategies?: Address[];
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
};
|
|
90
|
+
type UseTokenUpvotesOptions = {
|
|
91
|
+
chainId: number;
|
|
92
|
+
tokenAddress: string;
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate score key for token upvotes.
|
|
98
|
+
* Pads the token address into a bytes32 value.
|
|
99
|
+
*/
|
|
100
|
+
declare const getTokenScoreKey: (tokenAddress: string) => `0x${string}`;
|
|
101
|
+
/**
|
|
102
|
+
* Generate score key for storage upvotes.
|
|
103
|
+
* keccak256(encodePacked(storageKeyBytes32, operatorAddress))
|
|
104
|
+
*/
|
|
105
|
+
declare const getStorageScoreKey: (operatorAddress: string, storageKey: string) => `0x${string}`;
|
|
106
|
+
/**
|
|
107
|
+
* Generate content-based key for feed posts.
|
|
108
|
+
* Uses all message content to create a unique identifier that's
|
|
109
|
+
* independent of query filter (works regardless of how messages are fetched).
|
|
110
|
+
*
|
|
111
|
+
* Two messages with identical content will share the same key (and upvotes),
|
|
112
|
+
* which is semantically correct - they are the same content.
|
|
113
|
+
*/
|
|
114
|
+
declare const getFeedContentKey: (message: FeedMessage) => `0x${string}`;
|
|
115
|
+
/**
|
|
116
|
+
* Get score key for any ScoreItem type.
|
|
117
|
+
*/
|
|
118
|
+
declare const getScoreKey: (item: ScoreItem) => `0x${string}`;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a score key represents a token upvote (zero-padded address)
|
|
121
|
+
* vs a hash-based key (storage/feed).
|
|
122
|
+
*/
|
|
123
|
+
declare const isTokenScoreKey: (scoreKey: string) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Extract and validate token address from a token score key.
|
|
126
|
+
* Returns the checksummed address or null if invalid.
|
|
127
|
+
*/
|
|
128
|
+
declare const extractTokenAddressFromScoreKey: (scoreKey: string) => string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Generate upvote stored context for storage upvotes.
|
|
131
|
+
* ABI-encodes (bytes32 storageKeyBytes, address operatorAddress).
|
|
132
|
+
*/
|
|
133
|
+
declare const getStorageUpvoteContext: (operatorAddress: string, storageKey: string) => `0x${string}`;
|
|
134
|
+
|
|
135
|
+
export { type DecodedStrategyMetadata as D, type FeedMessage as F, type GetUpvotesOptions as G, type PoolKey as P, type ScoreClientOptions as S, type UseUpvotesOptions as U, type GetUpvotesForItemsOptions as a, type GetStrategyKeyScoresOptions as b, type GetAppKeyScoresOptions as c, getStorageScoreKey as d, getFeedContentKey as e, getScoreKey as f, getTokenScoreKey as g, extractTokenAddressFromScoreKey as h, isTokenScoreKey as i, getStorageUpvoteContext as j, type ScoreItem as k, type PureAlphaMetadata as l, type PoolStrategyMetadata as m, type DecodedUpvoteBlob as n, type UseUpvotesBatchOptions as o, type UseTokenUpvotesOptions as p };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
type ScoreItem = {
|
|
4
|
+
type: "token";
|
|
5
|
+
tokenAddress: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "storage";
|
|
8
|
+
operatorAddress: string;
|
|
9
|
+
storageKey: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: "feed";
|
|
12
|
+
message: FeedMessage;
|
|
13
|
+
};
|
|
14
|
+
type FeedMessage = {
|
|
15
|
+
app: Address;
|
|
16
|
+
sender: Address;
|
|
17
|
+
timestamp: bigint;
|
|
18
|
+
data: `0x${string}`;
|
|
19
|
+
text: string;
|
|
20
|
+
topic: string;
|
|
21
|
+
};
|
|
22
|
+
type PoolKey = {
|
|
23
|
+
currency0: string;
|
|
24
|
+
currency1: string;
|
|
25
|
+
fee: number;
|
|
26
|
+
tickSpacing: number;
|
|
27
|
+
hooks: string;
|
|
28
|
+
};
|
|
29
|
+
type PureAlphaMetadata = {
|
|
30
|
+
alphaAmount: bigint;
|
|
31
|
+
alphaWethPrice: bigint;
|
|
32
|
+
wethUsdcPrice: bigint;
|
|
33
|
+
userAlphaBalance: bigint;
|
|
34
|
+
};
|
|
35
|
+
type PoolStrategyMetadata = {
|
|
36
|
+
tokenAmount: bigint;
|
|
37
|
+
tokenWethPrice: bigint;
|
|
38
|
+
wethUsdcPrice: bigint;
|
|
39
|
+
alphaWethPrice: bigint;
|
|
40
|
+
userTokenBalance: bigint;
|
|
41
|
+
};
|
|
42
|
+
type DecodedStrategyMetadata = PureAlphaMetadata | PoolStrategyMetadata | null;
|
|
43
|
+
type DecodedUpvoteBlob = {
|
|
44
|
+
scoreKey: `0x${string}`;
|
|
45
|
+
scoreDelta: number;
|
|
46
|
+
originalSender: Address;
|
|
47
|
+
appAddress: Address;
|
|
48
|
+
strategyAddress: Address;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
scoreStoredContext: `0x${string}`;
|
|
51
|
+
scoreUnstoredContext: `0x${string}`;
|
|
52
|
+
decodedMetadata: DecodedStrategyMetadata;
|
|
53
|
+
} | null;
|
|
54
|
+
type ScoreClientOptions = {
|
|
55
|
+
chainId: number;
|
|
56
|
+
overrides?: {
|
|
57
|
+
scoreAddress?: Address;
|
|
58
|
+
upvoteAppAddress?: Address;
|
|
59
|
+
rpcUrls?: string[];
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
type GetUpvotesOptions = {
|
|
63
|
+
scoreKeys: `0x${string}`[];
|
|
64
|
+
strategies?: Address[];
|
|
65
|
+
};
|
|
66
|
+
type GetUpvotesForItemsOptions = {
|
|
67
|
+
items: ScoreItem[];
|
|
68
|
+
strategies?: Address[];
|
|
69
|
+
};
|
|
70
|
+
type GetStrategyKeyScoresOptions = {
|
|
71
|
+
strategy: Address;
|
|
72
|
+
scoreKeys: `0x${string}`[];
|
|
73
|
+
};
|
|
74
|
+
type GetAppKeyScoresOptions = {
|
|
75
|
+
app: Address;
|
|
76
|
+
scoreKeys: `0x${string}`[];
|
|
77
|
+
};
|
|
78
|
+
type UseUpvotesOptions = {
|
|
79
|
+
chainId: number;
|
|
80
|
+
scoreKey: `0x${string}`;
|
|
81
|
+
strategies?: Address[];
|
|
82
|
+
enabled?: boolean;
|
|
83
|
+
};
|
|
84
|
+
type UseUpvotesBatchOptions = {
|
|
85
|
+
chainId: number;
|
|
86
|
+
items: ScoreItem[];
|
|
87
|
+
strategies?: Address[];
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
};
|
|
90
|
+
type UseTokenUpvotesOptions = {
|
|
91
|
+
chainId: number;
|
|
92
|
+
tokenAddress: string;
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate score key for token upvotes.
|
|
98
|
+
* Pads the token address into a bytes32 value.
|
|
99
|
+
*/
|
|
100
|
+
declare const getTokenScoreKey: (tokenAddress: string) => `0x${string}`;
|
|
101
|
+
/**
|
|
102
|
+
* Generate score key for storage upvotes.
|
|
103
|
+
* keccak256(encodePacked(storageKeyBytes32, operatorAddress))
|
|
104
|
+
*/
|
|
105
|
+
declare const getStorageScoreKey: (operatorAddress: string, storageKey: string) => `0x${string}`;
|
|
106
|
+
/**
|
|
107
|
+
* Generate content-based key for feed posts.
|
|
108
|
+
* Uses all message content to create a unique identifier that's
|
|
109
|
+
* independent of query filter (works regardless of how messages are fetched).
|
|
110
|
+
*
|
|
111
|
+
* Two messages with identical content will share the same key (and upvotes),
|
|
112
|
+
* which is semantically correct - they are the same content.
|
|
113
|
+
*/
|
|
114
|
+
declare const getFeedContentKey: (message: FeedMessage) => `0x${string}`;
|
|
115
|
+
/**
|
|
116
|
+
* Get score key for any ScoreItem type.
|
|
117
|
+
*/
|
|
118
|
+
declare const getScoreKey: (item: ScoreItem) => `0x${string}`;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a score key represents a token upvote (zero-padded address)
|
|
121
|
+
* vs a hash-based key (storage/feed).
|
|
122
|
+
*/
|
|
123
|
+
declare const isTokenScoreKey: (scoreKey: string) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Extract and validate token address from a token score key.
|
|
126
|
+
* Returns the checksummed address or null if invalid.
|
|
127
|
+
*/
|
|
128
|
+
declare const extractTokenAddressFromScoreKey: (scoreKey: string) => string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Generate upvote stored context for storage upvotes.
|
|
131
|
+
* ABI-encodes (bytes32 storageKeyBytes, address operatorAddress).
|
|
132
|
+
*/
|
|
133
|
+
declare const getStorageUpvoteContext: (operatorAddress: string, storageKey: string) => `0x${string}`;
|
|
134
|
+
|
|
135
|
+
export { type DecodedStrategyMetadata as D, type FeedMessage as F, type GetUpvotesOptions as G, type PoolKey as P, type ScoreClientOptions as S, type UseUpvotesOptions as U, type GetUpvotesForItemsOptions as a, type GetStrategyKeyScoresOptions as b, type GetAppKeyScoresOptions as c, getStorageScoreKey as d, getFeedContentKey as e, getScoreKey as f, getTokenScoreKey as g, extractTokenAddressFromScoreKey as h, isTokenScoreKey as i, getStorageUpvoteContext as j, type ScoreItem as k, type PureAlphaMetadata as l, type PoolStrategyMetadata as m, type DecodedUpvoteBlob as n, type UseUpvotesBatchOptions as o, type UseTokenUpvotesOptions as p };
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@net-protocol/score",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Score/upvoting functionality for Net Protocol - on-chain scoring system",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
"*": {
|
|
11
|
+
"react": [
|
|
12
|
+
"./dist/react.d.ts"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./react": {
|
|
23
|
+
"types": "./dist/react.d.ts",
|
|
24
|
+
"import": "./dist/react.mjs",
|
|
25
|
+
"require": "./dist/react.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"build:watch": "tsup --watch",
|
|
35
|
+
"clean": "rm -rf dist",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"prepack": "../../scripts/prepack-modify-deps.sh",
|
|
38
|
+
"prepublishOnly": "yarn build",
|
|
39
|
+
"postpublish": "../../scripts/postpublish-restore-deps.sh",
|
|
40
|
+
"test": "vitest --run",
|
|
41
|
+
"test:watch": "vitest --watch",
|
|
42
|
+
"test:ui": "vitest --ui"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@net-protocol/core": "^0.1.8",
|
|
46
|
+
"@net-protocol/storage": "^0.1.12",
|
|
47
|
+
"viem": "^2.31.4"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@tanstack/react-query": "^5.0.0",
|
|
51
|
+
"@testing-library/react": "^14.0.0",
|
|
52
|
+
"@types/node": "^20.0.0",
|
|
53
|
+
"@types/react": "^18.0.0",
|
|
54
|
+
"@vitest/ui": "^1.0.0",
|
|
55
|
+
"jsdom": "^24.0.0",
|
|
56
|
+
"react-dom": "^18.0.0",
|
|
57
|
+
"tsup": "^8.0.0",
|
|
58
|
+
"typescript": "^5.0.0",
|
|
59
|
+
"vitest": "^1.0.0",
|
|
60
|
+
"wagmi": "^2.15.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"react": "^18.0.0",
|
|
64
|
+
"wagmi": "^2.15.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"react": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"wagmi": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public",
|
|
76
|
+
"registry": "https://registry.npmjs.org/"
|
|
77
|
+
},
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "https://github.com/stuckinaboot/net-public.git",
|
|
81
|
+
"directory": "packages/net-score"
|
|
82
|
+
},
|
|
83
|
+
"keywords": [
|
|
84
|
+
"net",
|
|
85
|
+
"protocol",
|
|
86
|
+
"blockchain",
|
|
87
|
+
"ethereum",
|
|
88
|
+
"score",
|
|
89
|
+
"upvote",
|
|
90
|
+
"voting"
|
|
91
|
+
],
|
|
92
|
+
"license": "MIT"
|
|
93
|
+
}
|