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