@net-protocol/score 0.1.3 → 0.1.5

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.js CHANGED
@@ -1934,6 +1934,467 @@ var multi_version_uniswap_pool_info_retriever_default = [
1934
1934
  }
1935
1935
  ];
1936
1936
 
1937
+ // src/abis/user-upvote.json
1938
+ var user_upvote_default = [
1939
+ {
1940
+ type: "constructor",
1941
+ inputs: [
1942
+ { name: "_alphaToken", type: "address", internalType: "address" },
1943
+ { name: "_erc20TokenGatedChat", type: "address", internalType: "address" },
1944
+ { name: "_net", type: "address", internalType: "address" },
1945
+ { name: "_swapRouter", type: "address", internalType: "address" },
1946
+ { name: "_weth", type: "address", internalType: "address" },
1947
+ { name: "_upvotePrice", type: "uint256", internalType: "uint256" },
1948
+ { name: "_feeBps", type: "uint256", internalType: "uint256" }
1949
+ ],
1950
+ stateMutability: "nonpayable"
1951
+ },
1952
+ {
1953
+ type: "function",
1954
+ name: "ALPHA_TOKEN",
1955
+ inputs: [],
1956
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1957
+ stateMutability: "view"
1958
+ },
1959
+ {
1960
+ type: "function",
1961
+ name: "ERC20_TOKEN_GATED_CHAT",
1962
+ inputs: [],
1963
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1964
+ stateMutability: "view"
1965
+ },
1966
+ {
1967
+ type: "function",
1968
+ name: "ETH_USDC_POOL",
1969
+ inputs: [],
1970
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1971
+ stateMutability: "view"
1972
+ },
1973
+ {
1974
+ type: "function",
1975
+ name: "MAX_TOKENS_PER_USER",
1976
+ inputs: [],
1977
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
1978
+ stateMutability: "view"
1979
+ },
1980
+ {
1981
+ type: "function",
1982
+ name: "NET",
1983
+ inputs: [],
1984
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1985
+ stateMutability: "view"
1986
+ },
1987
+ {
1988
+ type: "function",
1989
+ name: "SWAP_ROUTER",
1990
+ inputs: [],
1991
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1992
+ stateMutability: "view"
1993
+ },
1994
+ {
1995
+ type: "function",
1996
+ name: "UNISWAP_V3_FACTORY",
1997
+ inputs: [],
1998
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1999
+ stateMutability: "view"
2000
+ },
2001
+ {
2002
+ type: "function",
2003
+ name: "WETH",
2004
+ inputs: [],
2005
+ outputs: [{ name: "", type: "address", internalType: "address" }],
2006
+ stateMutability: "view"
2007
+ },
2008
+ {
2009
+ type: "function",
2010
+ name: "addTokenToList",
2011
+ inputs: [
2012
+ { name: "token", type: "address", internalType: "address" },
2013
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
2014
+ ],
2015
+ outputs: [],
2016
+ stateMutability: "nonpayable"
2017
+ },
2018
+ {
2019
+ type: "function",
2020
+ name: "feeBps",
2021
+ inputs: [],
2022
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2023
+ stateMutability: "view"
2024
+ },
2025
+ {
2026
+ type: "function",
2027
+ name: "getTokenFeeTier",
2028
+ inputs: [
2029
+ { name: "user", type: "address", internalType: "address" },
2030
+ { name: "token", type: "address", internalType: "address" }
2031
+ ],
2032
+ outputs: [{ name: "", type: "uint24", internalType: "uint24" }],
2033
+ stateMutability: "view"
2034
+ },
2035
+ {
2036
+ type: "function",
2037
+ name: "getTotalUpvotesPerToken",
2038
+ inputs: [
2039
+ { name: "token", type: "address", internalType: "address" }
2040
+ ],
2041
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2042
+ stateMutability: "view"
2043
+ },
2044
+ {
2045
+ type: "function",
2046
+ name: "getUserTokenCount",
2047
+ inputs: [
2048
+ { name: "user", type: "address", internalType: "address" }
2049
+ ],
2050
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2051
+ stateMutability: "view"
2052
+ },
2053
+ {
2054
+ type: "function",
2055
+ name: "getUserTokensInRange",
2056
+ inputs: [
2057
+ { name: "user", type: "address", internalType: "address" },
2058
+ { name: "startIndex", type: "uint256", internalType: "uint256" },
2059
+ { name: "endIndex", type: "uint256", internalType: "uint256" }
2060
+ ],
2061
+ outputs: [
2062
+ {
2063
+ name: "",
2064
+ type: "tuple[]",
2065
+ internalType: "struct UserUpvoteContract.TokenInfo[]",
2066
+ components: [
2067
+ { name: "token", type: "address", internalType: "address" },
2068
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
2069
+ ]
2070
+ }
2071
+ ],
2072
+ stateMutability: "view"
2073
+ },
2074
+ {
2075
+ type: "function",
2076
+ name: "getUserUpvotesGiven",
2077
+ inputs: [
2078
+ { name: "user", type: "address", internalType: "address" }
2079
+ ],
2080
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2081
+ stateMutability: "view"
2082
+ },
2083
+ {
2084
+ type: "function",
2085
+ name: "getUserUpvotesGivenPerToken",
2086
+ inputs: [
2087
+ { name: "user", type: "address", internalType: "address" },
2088
+ { name: "token", type: "address", internalType: "address" }
2089
+ ],
2090
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2091
+ stateMutability: "view"
2092
+ },
2093
+ {
2094
+ type: "function",
2095
+ name: "getUserUpvotesGivenPerTokenBatch",
2096
+ inputs: [
2097
+ { name: "user", type: "address", internalType: "address" },
2098
+ { name: "tokens", type: "address[]", internalType: "address[]" }
2099
+ ],
2100
+ outputs: [
2101
+ { name: "", type: "uint256[]", internalType: "uint256[]" }
2102
+ ],
2103
+ stateMutability: "view"
2104
+ },
2105
+ {
2106
+ type: "function",
2107
+ name: "getUserUpvotesReceived",
2108
+ inputs: [
2109
+ { name: "user", type: "address", internalType: "address" }
2110
+ ],
2111
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2112
+ stateMutability: "view"
2113
+ },
2114
+ {
2115
+ type: "function",
2116
+ name: "getUserUpvotesReceivedPerToken",
2117
+ inputs: [
2118
+ { name: "user", type: "address", internalType: "address" },
2119
+ { name: "token", type: "address", internalType: "address" }
2120
+ ],
2121
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2122
+ stateMutability: "view"
2123
+ },
2124
+ {
2125
+ type: "function",
2126
+ name: "getUserUpvotesReceivedPerTokenBatch",
2127
+ inputs: [
2128
+ { name: "user", type: "address", internalType: "address" },
2129
+ { name: "tokens", type: "address[]", internalType: "address[]" }
2130
+ ],
2131
+ outputs: [
2132
+ { name: "", type: "uint256[]", internalType: "uint256[]" }
2133
+ ],
2134
+ stateMutability: "view"
2135
+ },
2136
+ {
2137
+ type: "function",
2138
+ name: "isTokenInUserList",
2139
+ inputs: [
2140
+ { name: "user", type: "address", internalType: "address" },
2141
+ { name: "token", type: "address", internalType: "address" }
2142
+ ],
2143
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
2144
+ stateMutability: "view"
2145
+ },
2146
+ {
2147
+ type: "function",
2148
+ name: "owner",
2149
+ inputs: [],
2150
+ outputs: [{ name: "", type: "address", internalType: "address" }],
2151
+ stateMutability: "view"
2152
+ },
2153
+ {
2154
+ type: "function",
2155
+ name: "removeTokenFromList",
2156
+ inputs: [
2157
+ { name: "token", type: "address", internalType: "address" }
2158
+ ],
2159
+ outputs: [],
2160
+ stateMutability: "nonpayable"
2161
+ },
2162
+ {
2163
+ type: "function",
2164
+ name: "renounceOwnership",
2165
+ inputs: [],
2166
+ outputs: [],
2167
+ stateMutability: "nonpayable"
2168
+ },
2169
+ {
2170
+ type: "function",
2171
+ name: "setFeeBps",
2172
+ inputs: [
2173
+ { name: "newFeeBps", type: "uint256", internalType: "uint256" }
2174
+ ],
2175
+ outputs: [],
2176
+ stateMutability: "nonpayable"
2177
+ },
2178
+ {
2179
+ type: "function",
2180
+ name: "setUpvotePrice",
2181
+ inputs: [
2182
+ { name: "newUpvotePrice", type: "uint256", internalType: "uint256" }
2183
+ ],
2184
+ outputs: [],
2185
+ stateMutability: "nonpayable"
2186
+ },
2187
+ {
2188
+ type: "function",
2189
+ name: "totalUpvotesPerToken",
2190
+ inputs: [{ name: "", type: "address", internalType: "address" }],
2191
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2192
+ stateMutability: "view"
2193
+ },
2194
+ {
2195
+ type: "function",
2196
+ name: "transferOwnership",
2197
+ inputs: [
2198
+ { name: "newOwner", type: "address", internalType: "address" }
2199
+ ],
2200
+ outputs: [],
2201
+ stateMutability: "nonpayable"
2202
+ },
2203
+ {
2204
+ type: "function",
2205
+ name: "upvotePrice",
2206
+ inputs: [],
2207
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2208
+ stateMutability: "view"
2209
+ },
2210
+ {
2211
+ type: "function",
2212
+ name: "upvoteUser",
2213
+ inputs: [
2214
+ { name: "userToUpvote", type: "address", internalType: "address" },
2215
+ { name: "token", type: "address", internalType: "address" },
2216
+ { name: "numUpvotes", type: "uint256", internalType: "uint256" },
2217
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
2218
+ ],
2219
+ outputs: [],
2220
+ stateMutability: "payable"
2221
+ },
2222
+ {
2223
+ type: "function",
2224
+ name: "userTokenCount",
2225
+ inputs: [{ name: "", type: "address", internalType: "address" }],
2226
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2227
+ stateMutability: "view"
2228
+ },
2229
+ {
2230
+ type: "function",
2231
+ name: "userTokenExists",
2232
+ inputs: [
2233
+ { name: "", type: "address", internalType: "address" },
2234
+ { name: "", type: "address", internalType: "address" }
2235
+ ],
2236
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
2237
+ stateMutability: "view"
2238
+ },
2239
+ {
2240
+ type: "function",
2241
+ name: "userTokenFeeTiers",
2242
+ inputs: [
2243
+ { name: "", type: "address", internalType: "address" },
2244
+ { name: "", type: "address", internalType: "address" }
2245
+ ],
2246
+ outputs: [{ name: "", type: "uint24", internalType: "uint24" }],
2247
+ stateMutability: "view"
2248
+ },
2249
+ {
2250
+ type: "function",
2251
+ name: "userTokenSeen",
2252
+ inputs: [
2253
+ { name: "", type: "address", internalType: "address" },
2254
+ { name: "", type: "address", internalType: "address" }
2255
+ ],
2256
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
2257
+ stateMutability: "view"
2258
+ },
2259
+ {
2260
+ type: "function",
2261
+ name: "userTokens",
2262
+ inputs: [
2263
+ { name: "", type: "address", internalType: "address" },
2264
+ { name: "", type: "uint256", internalType: "uint256" }
2265
+ ],
2266
+ outputs: [
2267
+ { name: "token", type: "address", internalType: "address" },
2268
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
2269
+ ],
2270
+ stateMutability: "view"
2271
+ },
2272
+ {
2273
+ type: "function",
2274
+ name: "userUpvotesGiven",
2275
+ inputs: [{ name: "", type: "address", internalType: "address" }],
2276
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2277
+ stateMutability: "view"
2278
+ },
2279
+ {
2280
+ type: "function",
2281
+ name: "userUpvotesGivenPerToken",
2282
+ inputs: [
2283
+ { name: "", type: "address", internalType: "address" },
2284
+ { name: "", type: "address", internalType: "address" }
2285
+ ],
2286
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2287
+ stateMutability: "view"
2288
+ },
2289
+ {
2290
+ type: "function",
2291
+ name: "userUpvotesReceived",
2292
+ inputs: [{ name: "", type: "address", internalType: "address" }],
2293
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2294
+ stateMutability: "view"
2295
+ },
2296
+ {
2297
+ type: "function",
2298
+ name: "userUpvotesReceivedPerToken",
2299
+ inputs: [
2300
+ { name: "", type: "address", internalType: "address" },
2301
+ { name: "", type: "address", internalType: "address" }
2302
+ ],
2303
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2304
+ stateMutability: "view"
2305
+ },
2306
+ {
2307
+ type: "function",
2308
+ name: "withdrawErc20",
2309
+ inputs: [
2310
+ { name: "to", type: "address", internalType: "address" },
2311
+ { name: "token", type: "address", internalType: "address" }
2312
+ ],
2313
+ outputs: [],
2314
+ stateMutability: "nonpayable"
2315
+ },
2316
+ {
2317
+ type: "event",
2318
+ name: "OwnershipTransferred",
2319
+ inputs: [
2320
+ { name: "previousOwner", type: "address", indexed: true, internalType: "address" },
2321
+ { name: "newOwner", type: "address", indexed: true, internalType: "address" }
2322
+ ],
2323
+ anonymous: false
2324
+ },
2325
+ {
2326
+ type: "event",
2327
+ name: "TokenAddedToList",
2328
+ inputs: [
2329
+ { name: "user", type: "address", indexed: true, internalType: "address" },
2330
+ { name: "token", type: "address", indexed: true, internalType: "address" },
2331
+ { name: "feeTier", type: "uint24", indexed: false, internalType: "uint24" }
2332
+ ],
2333
+ anonymous: false
2334
+ },
2335
+ {
2336
+ type: "event",
2337
+ name: "TokenRemovedFromList",
2338
+ inputs: [
2339
+ { name: "user", type: "address", indexed: true, internalType: "address" },
2340
+ { name: "token", type: "address", indexed: true, internalType: "address" }
2341
+ ],
2342
+ anonymous: false
2343
+ },
2344
+ {
2345
+ type: "event",
2346
+ name: "UserUpvoted",
2347
+ inputs: [
2348
+ { name: "upvoter", type: "address", indexed: true, internalType: "address" },
2349
+ { name: "upvotedUser", type: "address", indexed: true, internalType: "address" },
2350
+ { name: "token", type: "address", indexed: true, internalType: "address" },
2351
+ { name: "numUpvotes", type: "uint256", indexed: false, internalType: "uint256" }
2352
+ ],
2353
+ anonymous: false
2354
+ },
2355
+ { type: "error", name: "IncorrectEthSent", inputs: [] },
2356
+ { type: "error", name: "MaxTokensReached", inputs: [] },
2357
+ { type: "error", name: "NoAlphaToWithdraw", inputs: [] },
2358
+ {
2359
+ type: "error",
2360
+ name: "OwnableInvalidOwner",
2361
+ inputs: [{ name: "owner", type: "address", internalType: "address" }]
2362
+ },
2363
+ {
2364
+ type: "error",
2365
+ name: "OwnableUnauthorizedAccount",
2366
+ inputs: [{ name: "account", type: "address", internalType: "address" }]
2367
+ },
2368
+ {
2369
+ type: "error",
2370
+ name: "PoolNotFound",
2371
+ inputs: [
2372
+ { name: "tokenA", type: "address", internalType: "address" },
2373
+ { name: "tokenB", type: "address", internalType: "address" },
2374
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
2375
+ ]
2376
+ },
2377
+ { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] },
2378
+ {
2379
+ type: "error",
2380
+ name: "Slot0ReadFailed",
2381
+ inputs: [{ name: "pool", type: "address", internalType: "address" }]
2382
+ },
2383
+ {
2384
+ type: "error",
2385
+ name: "StringsInsufficientHexLength",
2386
+ inputs: [
2387
+ { name: "value", type: "uint256", internalType: "uint256" },
2388
+ { name: "length", type: "uint256", internalType: "uint256" }
2389
+ ]
2390
+ },
2391
+ { type: "error", name: "TokenAlreadyInList", inputs: [] },
2392
+ { type: "error", name: "TokenNotInUserList", inputs: [] },
2393
+ { type: "error", name: "UserCannotUpvoteSelf", inputs: [] },
2394
+ { type: "error", name: "WithdrawFailed", inputs: [] },
2395
+ { type: "error", name: "ZeroUpvotes", inputs: [] }
2396
+ ];
2397
+
1937
2398
  // src/constants.ts
1938
2399
  var SCORE_CONTRACT = {
1939
2400
  address: "0x0000000fa09b022e5616e5a173b4b67fa2fbcf28",
@@ -1990,6 +2451,10 @@ function getWethAddress(chainId) {
1990
2451
  }
1991
2452
  var NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
1992
2453
  var UPVOTE_PRICE_ETH = 25e-6;
2454
+ var USER_UPVOTE_CONTRACT = {
2455
+ address: "0xa4bc2c63dd0157692fd5f409389e5032e37d8895",
2456
+ abi: user_upvote_default
2457
+ };
1993
2458
  var encodeUpvoteKey = (tokenAddress) => {
1994
2459
  return `0x${BigInt(`0x${tokenAddress.slice(2)}`).toString(16).padStart(64, "0")}`;
1995
2460
  };
@@ -2381,6 +2846,280 @@ var ScoreClient = class {
2381
2846
  return [];
2382
2847
  }
2383
2848
  };
2849
+ function parseUserUpvoteMessage(message, topic) {
2850
+ try {
2851
+ if (topic.startsWith("ub-")) {
2852
+ const [
2853
+ upvotedUserString,
2854
+ actualToken,
2855
+ numUpvotes,
2856
+ tokenWethPrice,
2857
+ wethUsdcPrice,
2858
+ alphaWethPrice,
2859
+ userTokenBalance
2860
+ ] = viem.decodeAbiParameters(
2861
+ [
2862
+ { type: "string" },
2863
+ { type: "address" },
2864
+ { type: "uint256" },
2865
+ { type: "uint256" },
2866
+ { type: "uint256" },
2867
+ { type: "uint256" },
2868
+ { type: "uint256" }
2869
+ ],
2870
+ message.data
2871
+ );
2872
+ return {
2873
+ upvotedUserString,
2874
+ actualToken,
2875
+ numUpvotes: Number(numUpvotes),
2876
+ tokenWethPrice,
2877
+ wethUsdcPrice,
2878
+ alphaWethPrice,
2879
+ userTokenBalance
2880
+ };
2881
+ } else {
2882
+ const [
2883
+ upvotedUserString,
2884
+ actualToken,
2885
+ numUpvotes,
2886
+ tokenWethPrice,
2887
+ wethUsdcPrice,
2888
+ alphaWethPrice
2889
+ ] = viem.decodeAbiParameters(
2890
+ [
2891
+ { type: "string" },
2892
+ { type: "address" },
2893
+ { type: "uint256" },
2894
+ { type: "uint256" },
2895
+ { type: "uint256" },
2896
+ { type: "uint256" }
2897
+ ],
2898
+ message.data
2899
+ );
2900
+ return {
2901
+ upvotedUserString,
2902
+ actualToken,
2903
+ numUpvotes: Number(numUpvotes),
2904
+ tokenWethPrice,
2905
+ wethUsdcPrice,
2906
+ alphaWethPrice
2907
+ };
2908
+ }
2909
+ } catch {
2910
+ return null;
2911
+ }
2912
+ }
2913
+ function extractTokenAddressesFromMessages(messages, topic) {
2914
+ const tokenSet = /* @__PURE__ */ new Set();
2915
+ const validMessages = [];
2916
+ for (const message of messages) {
2917
+ const parsed = parseUserUpvoteMessage(message, topic);
2918
+ if (parsed) {
2919
+ tokenSet.add(parsed.actualToken.toLowerCase());
2920
+ validMessages.push(parsed);
2921
+ }
2922
+ }
2923
+ return {
2924
+ tokenAddresses: Array.from(tokenSet),
2925
+ validMessages
2926
+ };
2927
+ }
2928
+ function validateUserUpvoteMessage(message, topic) {
2929
+ return parseUserUpvoteMessage(message, topic) !== null;
2930
+ }
2931
+ function calculatePriceInUsdc(parsedMessage, tokenDecimals = 18) {
2932
+ const { tokenWethPrice, wethUsdcPrice } = parsedMessage;
2933
+ if (tokenWethPrice > 0n && wethUsdcPrice > 0n) {
2934
+ const scale = 10 ** (36 - tokenDecimals);
2935
+ const tokenWethPriceNum = Number(tokenWethPrice) / scale;
2936
+ const wethUsdcPriceNum = Number(wethUsdcPrice) / 1e6;
2937
+ return tokenWethPriceNum * wethUsdcPriceNum;
2938
+ }
2939
+ return void 0;
2940
+ }
2941
+ function calculateUserTokenBalance(rawBalance, tokenDecimals = 18) {
2942
+ return Number(rawBalance) / Math.pow(10, tokenDecimals);
2943
+ }
2944
+ function validateUpvoteParams(params) {
2945
+ if (viem.isAddressEqual(params.sender, params.userToUpvote)) {
2946
+ return { valid: false, error: "Cannot upvote yourself" };
2947
+ }
2948
+ if (!Number.isInteger(params.numUpvotes)) {
2949
+ return { valid: false, error: "Number of upvotes must be a whole number" };
2950
+ }
2951
+ if (params.numUpvotes <= 0) {
2952
+ return { valid: false, error: "Number of upvotes must be greater than zero" };
2953
+ }
2954
+ return { valid: true };
2955
+ }
2956
+ function calculateUpvoteCost(numUpvotes, upvotePrice) {
2957
+ return BigInt(numUpvotes) * upvotePrice;
2958
+ }
2959
+ function computeEnrichedFields(parsed, tokenInfo) {
2960
+ const decimals = tokenInfo?.decimals ?? 18;
2961
+ const priceInUsdc = calculatePriceInUsdc(parsed, decimals);
2962
+ const userTokenBalance = parsed.userTokenBalance ? calculateUserTokenBalance(parsed.userTokenBalance, decimals) : 0;
2963
+ const userTokenBalanceUsdValue = priceInUsdc !== void 0 && userTokenBalance > 0 ? priceInUsdc * userTokenBalance : void 0;
2964
+ return { priceInUsdc, userTokenBalance, userTokenBalanceUsdValue };
2965
+ }
2966
+ function buildUserUpvote(parsed, timestamp, tokenInfo) {
2967
+ return {
2968
+ tokenAddress: parsed.actualToken,
2969
+ numUpvotes: parsed.numUpvotes,
2970
+ timestamp,
2971
+ ...computeEnrichedFields(parsed, tokenInfo),
2972
+ upvotedUserAddress: parsed.upvotedUserString,
2973
+ tokenInfo
2974
+ };
2975
+ }
2976
+ function buildUserUpvoteReceived(parsed, upvoterAddress, timestamp, tokenInfo) {
2977
+ return {
2978
+ upvoterAddress,
2979
+ tokenAddress: parsed.actualToken,
2980
+ numUpvotes: parsed.numUpvotes,
2981
+ timestamp,
2982
+ ...computeEnrichedFields(parsed, tokenInfo),
2983
+ tokenInfo
2984
+ };
2985
+ }
2986
+
2987
+ // src/user-upvote/UserUpvoteClient.ts
2988
+ var UserUpvoteClient = class {
2989
+ constructor(params) {
2990
+ this.chainId = params.chainId;
2991
+ this.client = core.getPublicClient({
2992
+ chainId: params.chainId,
2993
+ rpcUrl: params.overrides?.rpcUrls
2994
+ });
2995
+ this.contractAddress = params.overrides?.contractAddress ?? USER_UPVOTE_CONTRACT.address;
2996
+ }
2997
+ async getUserUpvotesGiven({ user }) {
2998
+ const data = await actions.readContract(this.client, {
2999
+ address: this.contractAddress,
3000
+ abi: USER_UPVOTE_CONTRACT.abi,
3001
+ functionName: "getUserUpvotesGiven",
3002
+ args: [user]
3003
+ });
3004
+ return data;
3005
+ }
3006
+ async getUserUpvotesReceived({ user }) {
3007
+ const data = await actions.readContract(this.client, {
3008
+ address: this.contractAddress,
3009
+ abi: USER_UPVOTE_CONTRACT.abi,
3010
+ functionName: "getUserUpvotesReceived",
3011
+ args: [user]
3012
+ });
3013
+ return data;
3014
+ }
3015
+ async getUserUpvotesGivenPerTokenBatch({
3016
+ user,
3017
+ tokens
3018
+ }) {
3019
+ const data = await actions.readContract(this.client, {
3020
+ address: this.contractAddress,
3021
+ abi: USER_UPVOTE_CONTRACT.abi,
3022
+ functionName: "getUserUpvotesGivenPerTokenBatch",
3023
+ args: [user, tokens]
3024
+ });
3025
+ return data;
3026
+ }
3027
+ async getUserUpvotesReceivedPerTokenBatch({
3028
+ user,
3029
+ tokens
3030
+ }) {
3031
+ const data = await actions.readContract(this.client, {
3032
+ address: this.contractAddress,
3033
+ abi: USER_UPVOTE_CONTRACT.abi,
3034
+ functionName: "getUserUpvotesReceivedPerTokenBatch",
3035
+ args: [user, tokens]
3036
+ });
3037
+ return data;
3038
+ }
3039
+ async getTotalUpvotesPerToken({
3040
+ token
3041
+ }) {
3042
+ const data = await actions.readContract(this.client, {
3043
+ address: this.contractAddress,
3044
+ abi: USER_UPVOTE_CONTRACT.abi,
3045
+ functionName: "getTotalUpvotesPerToken",
3046
+ args: [token]
3047
+ });
3048
+ return data;
3049
+ }
3050
+ async getUserTokensInRange({
3051
+ user,
3052
+ startIndex,
3053
+ endIndex
3054
+ }) {
3055
+ const data = await actions.readContract(this.client, {
3056
+ address: this.contractAddress,
3057
+ abi: USER_UPVOTE_CONTRACT.abi,
3058
+ functionName: "getUserTokensInRange",
3059
+ args: [user, BigInt(startIndex), BigInt(endIndex)]
3060
+ });
3061
+ return data.map((item) => ({
3062
+ token: item.token,
3063
+ feeTier: Number(item.feeTier)
3064
+ }));
3065
+ }
3066
+ async getUserTokenCount({ user }) {
3067
+ const data = await actions.readContract(this.client, {
3068
+ address: this.contractAddress,
3069
+ abi: USER_UPVOTE_CONTRACT.abi,
3070
+ functionName: "getUserTokenCount",
3071
+ args: [user]
3072
+ });
3073
+ return Number(data);
3074
+ }
3075
+ async isTokenInUserList({
3076
+ user,
3077
+ token
3078
+ }) {
3079
+ const data = await actions.readContract(this.client, {
3080
+ address: this.contractAddress,
3081
+ abi: USER_UPVOTE_CONTRACT.abi,
3082
+ functionName: "isTokenInUserList",
3083
+ args: [user, token]
3084
+ });
3085
+ return data;
3086
+ }
3087
+ async getUpvotePrice() {
3088
+ const data = await actions.readContract(this.client, {
3089
+ address: this.contractAddress,
3090
+ abi: USER_UPVOTE_CONTRACT.abi,
3091
+ functionName: "upvotePrice"
3092
+ });
3093
+ return data;
3094
+ }
3095
+ async upvoteUser({
3096
+ walletClient,
3097
+ userToUpvote,
3098
+ token = NULL_ADDRESS,
3099
+ numUpvotes,
3100
+ feeTier = 0,
3101
+ value: providedValue
3102
+ }) {
3103
+ const sender = walletClient.account?.address;
3104
+ if (sender) {
3105
+ const validation = validateUpvoteParams({ sender, userToUpvote, numUpvotes });
3106
+ if (!validation.valid) {
3107
+ throw new Error(validation.error);
3108
+ }
3109
+ }
3110
+ const value = providedValue ?? calculateUpvoteCost(numUpvotes, await this.getUpvotePrice());
3111
+ const hash = await walletClient.writeContract({
3112
+ address: this.contractAddress,
3113
+ abi: USER_UPVOTE_CONTRACT.abi,
3114
+ functionName: "upvoteUser",
3115
+ args: [userToUpvote, token, BigInt(numUpvotes), BigInt(feeTier)],
3116
+ value,
3117
+ chain: null,
3118
+ dataSuffix: core.getBaseDataSuffix(this.chainId)
3119
+ });
3120
+ return hash;
3121
+ }
3122
+ };
2384
3123
  var encodePoolKey = (poolKey) => {
2385
3124
  if (!poolKey || !isValidPoolKey2(poolKey)) {
2386
3125
  return "0x";
@@ -2809,7 +3548,14 @@ exports.UNIV234_POOLS_STRATEGY = UNIV234_POOLS_STRATEGY;
2809
3548
  exports.UPVOTE_APP = UPVOTE_APP;
2810
3549
  exports.UPVOTE_PRICE_ETH = UPVOTE_PRICE_ETH;
2811
3550
  exports.UPVOTE_STORAGE_APP = UPVOTE_STORAGE_APP;
3551
+ exports.USER_UPVOTE_CONTRACT = USER_UPVOTE_CONTRACT;
3552
+ exports.UserUpvoteClient = UserUpvoteClient;
3553
+ exports.buildUserUpvote = buildUserUpvote;
3554
+ exports.buildUserUpvoteReceived = buildUserUpvoteReceived;
2812
3555
  exports.calculatePriceFromSqrtPriceX96 = calculatePriceFromSqrtPriceX96;
3556
+ exports.calculatePriceInUsdc = calculatePriceInUsdc;
3557
+ exports.calculateUpvoteCost = calculateUpvoteCost;
3558
+ exports.calculateUserTokenBalance = calculateUserTokenBalance;
2813
3559
  exports.decodeStrategyMetadata = decodeStrategyMetadata;
2814
3560
  exports.decodeUpvoteMessage = decodeUpvoteMessage;
2815
3561
  exports.decodeUpvoteStorageBlob = decodeUpvoteStorageBlob;
@@ -2819,6 +3565,7 @@ exports.encodePoolKey = encodePoolKey;
2819
3565
  exports.encodeUpvoteKey = encodeUpvoteKey;
2820
3566
  exports.extractStrategyAddress = extractStrategyAddress;
2821
3567
  exports.extractTokenAddressFromScoreKey = extractTokenAddressFromScoreKey;
3568
+ exports.extractTokenAddressesFromMessages = extractTokenAddressesFromMessages;
2822
3569
  exports.getFeedContentKey = getFeedContentKey;
2823
3570
  exports.getScoreKey = getScoreKey;
2824
3571
  exports.getStorageScoreKey = getStorageScoreKey;
@@ -2831,7 +3578,10 @@ exports.isStrategyMessage = isStrategyMessage;
2831
3578
  exports.isTokenScoreKey = isTokenScoreKey;
2832
3579
  exports.isUniv234PoolsStrategy = isUniv234PoolsStrategy;
2833
3580
  exports.isUserUpvoteMessage = isUserUpvoteMessage;
3581
+ exports.parseUserUpvoteMessage = parseUserUpvoteMessage;
2834
3582
  exports.selectStrategy = selectStrategy;
2835
3583
  exports.tokenAddressToUpvoteKeyString = tokenAddressToUpvoteKeyString;
3584
+ exports.validateUpvoteParams = validateUpvoteParams;
3585
+ exports.validateUserUpvoteMessage = validateUserUpvoteMessage;
2836
3586
  //# sourceMappingURL=index.js.map
2837
3587
  //# sourceMappingURL=index.js.map