@net-protocol/score 0.1.2 → 0.1.4

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/react.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { useReadContract } from 'wagmi';
1
+ import { useReadContract, useWriteContract } from 'wagmi';
2
2
  import { useMemo } from 'react';
3
- import { keccak256, encodePacked } from 'viem';
3
+ import { keccak256, encodePacked, formatEther } from 'viem';
4
4
  import { getStorageKeyBytes } from '@net-protocol/storage';
5
+ import { getBaseDataSuffix } from '@net-protocol/core';
5
6
 
6
7
  // src/hooks/useUpvotes.ts
7
8
 
@@ -159,6 +160,467 @@ var upvote_app_default = [
159
160
  { type: "error", name: "WithdrawFailed", inputs: [] }
160
161
  ];
161
162
 
163
+ // src/abis/user-upvote.json
164
+ var user_upvote_default = [
165
+ {
166
+ type: "constructor",
167
+ inputs: [
168
+ { name: "_alphaToken", type: "address", internalType: "address" },
169
+ { name: "_erc20TokenGatedChat", type: "address", internalType: "address" },
170
+ { name: "_net", type: "address", internalType: "address" },
171
+ { name: "_swapRouter", type: "address", internalType: "address" },
172
+ { name: "_weth", type: "address", internalType: "address" },
173
+ { name: "_upvotePrice", type: "uint256", internalType: "uint256" },
174
+ { name: "_feeBps", type: "uint256", internalType: "uint256" }
175
+ ],
176
+ stateMutability: "nonpayable"
177
+ },
178
+ {
179
+ type: "function",
180
+ name: "ALPHA_TOKEN",
181
+ inputs: [],
182
+ outputs: [{ name: "", type: "address", internalType: "address" }],
183
+ stateMutability: "view"
184
+ },
185
+ {
186
+ type: "function",
187
+ name: "ERC20_TOKEN_GATED_CHAT",
188
+ inputs: [],
189
+ outputs: [{ name: "", type: "address", internalType: "address" }],
190
+ stateMutability: "view"
191
+ },
192
+ {
193
+ type: "function",
194
+ name: "ETH_USDC_POOL",
195
+ inputs: [],
196
+ outputs: [{ name: "", type: "address", internalType: "address" }],
197
+ stateMutability: "view"
198
+ },
199
+ {
200
+ type: "function",
201
+ name: "MAX_TOKENS_PER_USER",
202
+ inputs: [],
203
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
204
+ stateMutability: "view"
205
+ },
206
+ {
207
+ type: "function",
208
+ name: "NET",
209
+ inputs: [],
210
+ outputs: [{ name: "", type: "address", internalType: "address" }],
211
+ stateMutability: "view"
212
+ },
213
+ {
214
+ type: "function",
215
+ name: "SWAP_ROUTER",
216
+ inputs: [],
217
+ outputs: [{ name: "", type: "address", internalType: "address" }],
218
+ stateMutability: "view"
219
+ },
220
+ {
221
+ type: "function",
222
+ name: "UNISWAP_V3_FACTORY",
223
+ inputs: [],
224
+ outputs: [{ name: "", type: "address", internalType: "address" }],
225
+ stateMutability: "view"
226
+ },
227
+ {
228
+ type: "function",
229
+ name: "WETH",
230
+ inputs: [],
231
+ outputs: [{ name: "", type: "address", internalType: "address" }],
232
+ stateMutability: "view"
233
+ },
234
+ {
235
+ type: "function",
236
+ name: "addTokenToList",
237
+ inputs: [
238
+ { name: "token", type: "address", internalType: "address" },
239
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
240
+ ],
241
+ outputs: [],
242
+ stateMutability: "nonpayable"
243
+ },
244
+ {
245
+ type: "function",
246
+ name: "feeBps",
247
+ inputs: [],
248
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
249
+ stateMutability: "view"
250
+ },
251
+ {
252
+ type: "function",
253
+ name: "getTokenFeeTier",
254
+ inputs: [
255
+ { name: "user", type: "address", internalType: "address" },
256
+ { name: "token", type: "address", internalType: "address" }
257
+ ],
258
+ outputs: [{ name: "", type: "uint24", internalType: "uint24" }],
259
+ stateMutability: "view"
260
+ },
261
+ {
262
+ type: "function",
263
+ name: "getTotalUpvotesPerToken",
264
+ inputs: [
265
+ { name: "token", type: "address", internalType: "address" }
266
+ ],
267
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
268
+ stateMutability: "view"
269
+ },
270
+ {
271
+ type: "function",
272
+ name: "getUserTokenCount",
273
+ inputs: [
274
+ { name: "user", type: "address", internalType: "address" }
275
+ ],
276
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
277
+ stateMutability: "view"
278
+ },
279
+ {
280
+ type: "function",
281
+ name: "getUserTokensInRange",
282
+ inputs: [
283
+ { name: "user", type: "address", internalType: "address" },
284
+ { name: "startIndex", type: "uint256", internalType: "uint256" },
285
+ { name: "endIndex", type: "uint256", internalType: "uint256" }
286
+ ],
287
+ outputs: [
288
+ {
289
+ name: "",
290
+ type: "tuple[]",
291
+ internalType: "struct UserUpvoteContract.TokenInfo[]",
292
+ components: [
293
+ { name: "token", type: "address", internalType: "address" },
294
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
295
+ ]
296
+ }
297
+ ],
298
+ stateMutability: "view"
299
+ },
300
+ {
301
+ type: "function",
302
+ name: "getUserUpvotesGiven",
303
+ inputs: [
304
+ { name: "user", type: "address", internalType: "address" }
305
+ ],
306
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
307
+ stateMutability: "view"
308
+ },
309
+ {
310
+ type: "function",
311
+ name: "getUserUpvotesGivenPerToken",
312
+ inputs: [
313
+ { name: "user", type: "address", internalType: "address" },
314
+ { name: "token", type: "address", internalType: "address" }
315
+ ],
316
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
317
+ stateMutability: "view"
318
+ },
319
+ {
320
+ type: "function",
321
+ name: "getUserUpvotesGivenPerTokenBatch",
322
+ inputs: [
323
+ { name: "user", type: "address", internalType: "address" },
324
+ { name: "tokens", type: "address[]", internalType: "address[]" }
325
+ ],
326
+ outputs: [
327
+ { name: "", type: "uint256[]", internalType: "uint256[]" }
328
+ ],
329
+ stateMutability: "view"
330
+ },
331
+ {
332
+ type: "function",
333
+ name: "getUserUpvotesReceived",
334
+ inputs: [
335
+ { name: "user", type: "address", internalType: "address" }
336
+ ],
337
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
338
+ stateMutability: "view"
339
+ },
340
+ {
341
+ type: "function",
342
+ name: "getUserUpvotesReceivedPerToken",
343
+ inputs: [
344
+ { name: "user", type: "address", internalType: "address" },
345
+ { name: "token", type: "address", internalType: "address" }
346
+ ],
347
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
348
+ stateMutability: "view"
349
+ },
350
+ {
351
+ type: "function",
352
+ name: "getUserUpvotesReceivedPerTokenBatch",
353
+ inputs: [
354
+ { name: "user", type: "address", internalType: "address" },
355
+ { name: "tokens", type: "address[]", internalType: "address[]" }
356
+ ],
357
+ outputs: [
358
+ { name: "", type: "uint256[]", internalType: "uint256[]" }
359
+ ],
360
+ stateMutability: "view"
361
+ },
362
+ {
363
+ type: "function",
364
+ name: "isTokenInUserList",
365
+ inputs: [
366
+ { name: "user", type: "address", internalType: "address" },
367
+ { name: "token", type: "address", internalType: "address" }
368
+ ],
369
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
370
+ stateMutability: "view"
371
+ },
372
+ {
373
+ type: "function",
374
+ name: "owner",
375
+ inputs: [],
376
+ outputs: [{ name: "", type: "address", internalType: "address" }],
377
+ stateMutability: "view"
378
+ },
379
+ {
380
+ type: "function",
381
+ name: "removeTokenFromList",
382
+ inputs: [
383
+ { name: "token", type: "address", internalType: "address" }
384
+ ],
385
+ outputs: [],
386
+ stateMutability: "nonpayable"
387
+ },
388
+ {
389
+ type: "function",
390
+ name: "renounceOwnership",
391
+ inputs: [],
392
+ outputs: [],
393
+ stateMutability: "nonpayable"
394
+ },
395
+ {
396
+ type: "function",
397
+ name: "setFeeBps",
398
+ inputs: [
399
+ { name: "newFeeBps", type: "uint256", internalType: "uint256" }
400
+ ],
401
+ outputs: [],
402
+ stateMutability: "nonpayable"
403
+ },
404
+ {
405
+ type: "function",
406
+ name: "setUpvotePrice",
407
+ inputs: [
408
+ { name: "newUpvotePrice", type: "uint256", internalType: "uint256" }
409
+ ],
410
+ outputs: [],
411
+ stateMutability: "nonpayable"
412
+ },
413
+ {
414
+ type: "function",
415
+ name: "totalUpvotesPerToken",
416
+ inputs: [{ name: "", type: "address", internalType: "address" }],
417
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
418
+ stateMutability: "view"
419
+ },
420
+ {
421
+ type: "function",
422
+ name: "transferOwnership",
423
+ inputs: [
424
+ { name: "newOwner", type: "address", internalType: "address" }
425
+ ],
426
+ outputs: [],
427
+ stateMutability: "nonpayable"
428
+ },
429
+ {
430
+ type: "function",
431
+ name: "upvotePrice",
432
+ inputs: [],
433
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
434
+ stateMutability: "view"
435
+ },
436
+ {
437
+ type: "function",
438
+ name: "upvoteUser",
439
+ inputs: [
440
+ { name: "userToUpvote", type: "address", internalType: "address" },
441
+ { name: "token", type: "address", internalType: "address" },
442
+ { name: "numUpvotes", type: "uint256", internalType: "uint256" },
443
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
444
+ ],
445
+ outputs: [],
446
+ stateMutability: "payable"
447
+ },
448
+ {
449
+ type: "function",
450
+ name: "userTokenCount",
451
+ inputs: [{ name: "", type: "address", internalType: "address" }],
452
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
453
+ stateMutability: "view"
454
+ },
455
+ {
456
+ type: "function",
457
+ name: "userTokenExists",
458
+ inputs: [
459
+ { name: "", type: "address", internalType: "address" },
460
+ { name: "", type: "address", internalType: "address" }
461
+ ],
462
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
463
+ stateMutability: "view"
464
+ },
465
+ {
466
+ type: "function",
467
+ name: "userTokenFeeTiers",
468
+ inputs: [
469
+ { name: "", type: "address", internalType: "address" },
470
+ { name: "", type: "address", internalType: "address" }
471
+ ],
472
+ outputs: [{ name: "", type: "uint24", internalType: "uint24" }],
473
+ stateMutability: "view"
474
+ },
475
+ {
476
+ type: "function",
477
+ name: "userTokenSeen",
478
+ inputs: [
479
+ { name: "", type: "address", internalType: "address" },
480
+ { name: "", type: "address", internalType: "address" }
481
+ ],
482
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
483
+ stateMutability: "view"
484
+ },
485
+ {
486
+ type: "function",
487
+ name: "userTokens",
488
+ inputs: [
489
+ { name: "", type: "address", internalType: "address" },
490
+ { name: "", type: "uint256", internalType: "uint256" }
491
+ ],
492
+ outputs: [
493
+ { name: "token", type: "address", internalType: "address" },
494
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
495
+ ],
496
+ stateMutability: "view"
497
+ },
498
+ {
499
+ type: "function",
500
+ name: "userUpvotesGiven",
501
+ inputs: [{ name: "", type: "address", internalType: "address" }],
502
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
503
+ stateMutability: "view"
504
+ },
505
+ {
506
+ type: "function",
507
+ name: "userUpvotesGivenPerToken",
508
+ inputs: [
509
+ { name: "", type: "address", internalType: "address" },
510
+ { name: "", type: "address", internalType: "address" }
511
+ ],
512
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
513
+ stateMutability: "view"
514
+ },
515
+ {
516
+ type: "function",
517
+ name: "userUpvotesReceived",
518
+ inputs: [{ name: "", type: "address", internalType: "address" }],
519
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
520
+ stateMutability: "view"
521
+ },
522
+ {
523
+ type: "function",
524
+ name: "userUpvotesReceivedPerToken",
525
+ inputs: [
526
+ { name: "", type: "address", internalType: "address" },
527
+ { name: "", type: "address", internalType: "address" }
528
+ ],
529
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
530
+ stateMutability: "view"
531
+ },
532
+ {
533
+ type: "function",
534
+ name: "withdrawErc20",
535
+ inputs: [
536
+ { name: "to", type: "address", internalType: "address" },
537
+ { name: "token", type: "address", internalType: "address" }
538
+ ],
539
+ outputs: [],
540
+ stateMutability: "nonpayable"
541
+ },
542
+ {
543
+ type: "event",
544
+ name: "OwnershipTransferred",
545
+ inputs: [
546
+ { name: "previousOwner", type: "address", indexed: true, internalType: "address" },
547
+ { name: "newOwner", type: "address", indexed: true, internalType: "address" }
548
+ ],
549
+ anonymous: false
550
+ },
551
+ {
552
+ type: "event",
553
+ name: "TokenAddedToList",
554
+ inputs: [
555
+ { name: "user", type: "address", indexed: true, internalType: "address" },
556
+ { name: "token", type: "address", indexed: true, internalType: "address" },
557
+ { name: "feeTier", type: "uint24", indexed: false, internalType: "uint24" }
558
+ ],
559
+ anonymous: false
560
+ },
561
+ {
562
+ type: "event",
563
+ name: "TokenRemovedFromList",
564
+ inputs: [
565
+ { name: "user", type: "address", indexed: true, internalType: "address" },
566
+ { name: "token", type: "address", indexed: true, internalType: "address" }
567
+ ],
568
+ anonymous: false
569
+ },
570
+ {
571
+ type: "event",
572
+ name: "UserUpvoted",
573
+ inputs: [
574
+ { name: "upvoter", type: "address", indexed: true, internalType: "address" },
575
+ { name: "upvotedUser", type: "address", indexed: true, internalType: "address" },
576
+ { name: "token", type: "address", indexed: true, internalType: "address" },
577
+ { name: "numUpvotes", type: "uint256", indexed: false, internalType: "uint256" }
578
+ ],
579
+ anonymous: false
580
+ },
581
+ { type: "error", name: "IncorrectEthSent", inputs: [] },
582
+ { type: "error", name: "MaxTokensReached", inputs: [] },
583
+ { type: "error", name: "NoAlphaToWithdraw", inputs: [] },
584
+ {
585
+ type: "error",
586
+ name: "OwnableInvalidOwner",
587
+ inputs: [{ name: "owner", type: "address", internalType: "address" }]
588
+ },
589
+ {
590
+ type: "error",
591
+ name: "OwnableUnauthorizedAccount",
592
+ inputs: [{ name: "account", type: "address", internalType: "address" }]
593
+ },
594
+ {
595
+ type: "error",
596
+ name: "PoolNotFound",
597
+ inputs: [
598
+ { name: "tokenA", type: "address", internalType: "address" },
599
+ { name: "tokenB", type: "address", internalType: "address" },
600
+ { name: "feeTier", type: "uint24", internalType: "uint24" }
601
+ ]
602
+ },
603
+ { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] },
604
+ {
605
+ type: "error",
606
+ name: "Slot0ReadFailed",
607
+ inputs: [{ name: "pool", type: "address", internalType: "address" }]
608
+ },
609
+ {
610
+ type: "error",
611
+ name: "StringsInsufficientHexLength",
612
+ inputs: [
613
+ { name: "value", type: "uint256", internalType: "uint256" },
614
+ { name: "length", type: "uint256", internalType: "uint256" }
615
+ ]
616
+ },
617
+ { type: "error", name: "TokenAlreadyInList", inputs: [] },
618
+ { type: "error", name: "TokenNotInUserList", inputs: [] },
619
+ { type: "error", name: "UserCannotUpvoteSelf", inputs: [] },
620
+ { type: "error", name: "WithdrawFailed", inputs: [] },
621
+ { type: "error", name: "ZeroUpvotes", inputs: [] }
622
+ ];
623
+
162
624
  // src/constants.ts
163
625
  var UPVOTE_APP = {
164
626
  address: "0x00000001f0b8173316a016a5067ad74e8cea47bf",
@@ -175,6 +637,11 @@ var ALL_STRATEGY_ADDRESSES = [
175
637
  PURE_ALPHA_STRATEGY.address,
176
638
  DYNAMIC_SPLIT_STRATEGY.address
177
639
  ];
640
+ var NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
641
+ var USER_UPVOTE_CONTRACT = {
642
+ address: "0xa4bc2c63dd0157692fd5f409389e5032e37d8895",
643
+ abi: user_upvote_default
644
+ };
178
645
 
179
646
  // src/hooks/useUpvotes.ts
180
647
  function useUpvotes({
@@ -283,7 +750,130 @@ function useTokenUpvotes({
283
750
  );
284
751
  return useUpvotes({ chainId, scoreKey, enabled });
285
752
  }
753
+ function useUserUpvotesGiven({
754
+ chainId,
755
+ userAddress,
756
+ enabled = true
757
+ }) {
758
+ const { data, isLoading, error, refetch } = useReadContract({
759
+ address: USER_UPVOTE_CONTRACT.address,
760
+ abi: USER_UPVOTE_CONTRACT.abi,
761
+ functionName: "getUserUpvotesGiven",
762
+ args: [userAddress],
763
+ chainId,
764
+ query: { enabled: enabled && !!userAddress }
765
+ });
766
+ return {
767
+ upvotes: typeof data === "bigint" ? Number(data) : 0,
768
+ isLoading,
769
+ error,
770
+ refetch
771
+ };
772
+ }
773
+ function useUserUpvotesReceived({
774
+ chainId,
775
+ userAddress,
776
+ enabled = true
777
+ }) {
778
+ const { data, isLoading, error, refetch } = useReadContract({
779
+ address: USER_UPVOTE_CONTRACT.address,
780
+ abi: USER_UPVOTE_CONTRACT.abi,
781
+ functionName: "getUserUpvotesReceived",
782
+ args: [userAddress],
783
+ chainId,
784
+ query: { enabled: enabled && !!userAddress }
785
+ });
786
+ return {
787
+ upvotes: typeof data === "bigint" ? Number(data) : 0,
788
+ isLoading,
789
+ error,
790
+ refetch
791
+ };
792
+ }
793
+ function useUserUpvotesGivenPerTokenBatch({
794
+ chainId,
795
+ userAddress,
796
+ tokenAddresses,
797
+ enabled = true
798
+ }) {
799
+ const { data, isLoading, error, refetch } = useReadContract({
800
+ address: USER_UPVOTE_CONTRACT.address,
801
+ abi: USER_UPVOTE_CONTRACT.abi,
802
+ functionName: "getUserUpvotesGivenPerTokenBatch",
803
+ args: [userAddress, tokenAddresses],
804
+ chainId,
805
+ query: { enabled: enabled && tokenAddresses.length > 0 }
806
+ });
807
+ return {
808
+ upvoteCounts: Array.isArray(data) ? data.map(Number) : [],
809
+ isLoading,
810
+ error,
811
+ refetch
812
+ };
813
+ }
814
+ function useUserUpvotesReceivedPerTokenBatch({
815
+ chainId,
816
+ userAddress,
817
+ tokenAddresses,
818
+ enabled = true
819
+ }) {
820
+ const { data, isLoading, error, refetch } = useReadContract({
821
+ address: USER_UPVOTE_CONTRACT.address,
822
+ abi: USER_UPVOTE_CONTRACT.abi,
823
+ functionName: "getUserUpvotesReceivedPerTokenBatch",
824
+ args: [userAddress, tokenAddresses],
825
+ chainId,
826
+ query: { enabled: enabled && tokenAddresses.length > 0 }
827
+ });
828
+ return {
829
+ upvoteCounts: Array.isArray(data) ? data.map(Number) : [],
830
+ isLoading,
831
+ error,
832
+ refetch
833
+ };
834
+ }
835
+ function useUpvoteUser({ chainId }) {
836
+ const { writeContractAsync, isPending, isSuccess, error, data: hash, reset } = useWriteContract();
837
+ const upvoteUser = async (params) => {
838
+ return writeContractAsync({
839
+ address: USER_UPVOTE_CONTRACT.address,
840
+ abi: USER_UPVOTE_CONTRACT.abi,
841
+ functionName: "upvoteUser",
842
+ args: [
843
+ params.userToUpvote,
844
+ params.token ?? NULL_ADDRESS,
845
+ BigInt(params.numUpvotes),
846
+ BigInt(params.feeTier ?? 0)
847
+ ],
848
+ value: params.value,
849
+ chainId,
850
+ dataSuffix: getBaseDataSuffix(chainId)
851
+ });
852
+ };
853
+ return { upvoteUser, isPending, isSuccess, error, hash, reset };
854
+ }
855
+ function useUpvotePrice({
856
+ chainId,
857
+ enabled = true
858
+ }) {
859
+ const { data, isLoading, error, refetch } = useReadContract({
860
+ address: USER_UPVOTE_CONTRACT.address,
861
+ abi: USER_UPVOTE_CONTRACT.abi,
862
+ functionName: "upvotePrice",
863
+ chainId,
864
+ query: { enabled }
865
+ });
866
+ const price = typeof data === "bigint" ? data : 0n;
867
+ const priceInEth = price > 0n ? Number(formatEther(price)) : 0;
868
+ return {
869
+ price,
870
+ priceInEth,
871
+ isLoading,
872
+ error,
873
+ refetch
874
+ };
875
+ }
286
876
 
287
- export { getScoreKey, getStorageScoreKey, getTokenScoreKey, useTokenUpvotes, useUpvotes, useUpvotesBatch };
877
+ export { getScoreKey, getStorageScoreKey, getTokenScoreKey, useTokenUpvotes, useUpvotePrice, useUpvoteUser, useUpvotes, useUpvotesBatch, useUserUpvotesGiven, useUserUpvotesGivenPerTokenBatch, useUserUpvotesReceived, useUserUpvotesReceivedPerTokenBatch };
288
878
  //# sourceMappingURL=react.mjs.map
289
879
  //# sourceMappingURL=react.mjs.map