@primuslabs/fund-js-sdk 0.1.13 → 0.1.15
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 +386 -137
- package/dist/index.mjs +386 -137
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -175,9 +175,7 @@ var Contract = class {
|
|
|
175
175
|
try {
|
|
176
176
|
console.log("sendTransaction params:", functionName, ...functionParams);
|
|
177
177
|
const tx = await this.contractInstance[functionName](...functionParams);
|
|
178
|
-
|
|
179
|
-
console.log("txreceipt", txreceipt);
|
|
180
|
-
resolve(txreceipt);
|
|
178
|
+
resolve(tx.hash);
|
|
181
179
|
} catch (error) {
|
|
182
180
|
console.log("sendTransaction error:", error);
|
|
183
181
|
const errStr = error?.message || error?.toString()?.toLowerCase() || "";
|
|
@@ -193,7 +191,7 @@ var Contract = class {
|
|
|
193
191
|
if (isNoPendingWithdrawals) {
|
|
194
192
|
return reject("no pending withdrawals");
|
|
195
193
|
}
|
|
196
|
-
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS"];
|
|
194
|
+
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS", "The caller does not have enough funds for value transfer."];
|
|
197
195
|
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
198
196
|
if (isInsufficientBalance) {
|
|
199
197
|
return reject("insufficient balance");
|
|
@@ -595,7 +593,11 @@ var abi_default = [
|
|
|
595
593
|
type: "function",
|
|
596
594
|
name: "addBatchIdSource",
|
|
597
595
|
inputs: [
|
|
598
|
-
{
|
|
596
|
+
{
|
|
597
|
+
name: "sourceName_",
|
|
598
|
+
type: "string[]",
|
|
599
|
+
internalType: "string[]"
|
|
600
|
+
},
|
|
599
601
|
{ name: "url_", type: "string[]", internalType: "string[]" },
|
|
600
602
|
{ name: "jsonPath_", type: "string[]", internalType: "string[]" }
|
|
601
603
|
],
|
|
@@ -612,15 +614,27 @@ var abi_default = [
|
|
|
612
614
|
type: "tuple[]",
|
|
613
615
|
internalType: "struct Attestation[]",
|
|
614
616
|
components: [
|
|
615
|
-
{
|
|
617
|
+
{
|
|
618
|
+
name: "recipient",
|
|
619
|
+
type: "address",
|
|
620
|
+
internalType: "address"
|
|
621
|
+
},
|
|
616
622
|
{
|
|
617
623
|
name: "request",
|
|
618
624
|
type: "tuple",
|
|
619
625
|
internalType: "struct AttNetworkRequest",
|
|
620
626
|
components: [
|
|
621
627
|
{ name: "url", type: "string", internalType: "string" },
|
|
622
|
-
{
|
|
623
|
-
|
|
628
|
+
{
|
|
629
|
+
name: "header",
|
|
630
|
+
type: "string",
|
|
631
|
+
internalType: "string"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "method",
|
|
635
|
+
type: "string",
|
|
636
|
+
internalType: "string"
|
|
637
|
+
},
|
|
624
638
|
{ name: "body", type: "string", internalType: "string" }
|
|
625
639
|
]
|
|
626
640
|
},
|
|
@@ -629,7 +643,11 @@ var abi_default = [
|
|
|
629
643
|
type: "tuple[]",
|
|
630
644
|
internalType: "struct AttNetworkResponseResolve[]",
|
|
631
645
|
components: [
|
|
632
|
-
{
|
|
646
|
+
{
|
|
647
|
+
name: "keyName",
|
|
648
|
+
type: "string",
|
|
649
|
+
internalType: "string"
|
|
650
|
+
},
|
|
633
651
|
{
|
|
634
652
|
name: "parseType",
|
|
635
653
|
type: "string",
|
|
@@ -667,7 +685,11 @@ var abi_default = [
|
|
|
667
685
|
{ name: "url", type: "string", internalType: "string" }
|
|
668
686
|
]
|
|
669
687
|
},
|
|
670
|
-
{
|
|
688
|
+
{
|
|
689
|
+
name: "signatures",
|
|
690
|
+
type: "bytes[]",
|
|
691
|
+
internalType: "bytes[]"
|
|
692
|
+
}
|
|
671
693
|
]
|
|
672
694
|
}
|
|
673
695
|
],
|
|
@@ -684,15 +706,27 @@ var abi_default = [
|
|
|
684
706
|
type: "tuple",
|
|
685
707
|
internalType: "struct Attestation",
|
|
686
708
|
components: [
|
|
687
|
-
{
|
|
709
|
+
{
|
|
710
|
+
name: "recipient",
|
|
711
|
+
type: "address",
|
|
712
|
+
internalType: "address"
|
|
713
|
+
},
|
|
688
714
|
{
|
|
689
715
|
name: "request",
|
|
690
716
|
type: "tuple",
|
|
691
717
|
internalType: "struct AttNetworkRequest",
|
|
692
718
|
components: [
|
|
693
719
|
{ name: "url", type: "string", internalType: "string" },
|
|
694
|
-
{
|
|
695
|
-
|
|
720
|
+
{
|
|
721
|
+
name: "header",
|
|
722
|
+
type: "string",
|
|
723
|
+
internalType: "string"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
name: "method",
|
|
727
|
+
type: "string",
|
|
728
|
+
internalType: "string"
|
|
729
|
+
},
|
|
696
730
|
{ name: "body", type: "string", internalType: "string" }
|
|
697
731
|
]
|
|
698
732
|
},
|
|
@@ -701,7 +735,11 @@ var abi_default = [
|
|
|
701
735
|
type: "tuple[]",
|
|
702
736
|
internalType: "struct AttNetworkResponseResolve[]",
|
|
703
737
|
components: [
|
|
704
|
-
{
|
|
738
|
+
{
|
|
739
|
+
name: "keyName",
|
|
740
|
+
type: "string",
|
|
741
|
+
internalType: "string"
|
|
742
|
+
},
|
|
705
743
|
{
|
|
706
744
|
name: "parseType",
|
|
707
745
|
type: "string",
|
|
@@ -739,7 +777,11 @@ var abi_default = [
|
|
|
739
777
|
{ name: "url", type: "string", internalType: "string" }
|
|
740
778
|
]
|
|
741
779
|
},
|
|
742
|
-
{
|
|
780
|
+
{
|
|
781
|
+
name: "signatures",
|
|
782
|
+
type: "bytes[]",
|
|
783
|
+
internalType: "bytes[]"
|
|
784
|
+
}
|
|
743
785
|
]
|
|
744
786
|
}
|
|
745
787
|
],
|
|
@@ -748,94 +790,105 @@ var abi_default = [
|
|
|
748
790
|
},
|
|
749
791
|
{
|
|
750
792
|
type: "function",
|
|
751
|
-
name: "
|
|
793
|
+
name: "claimFee",
|
|
794
|
+
inputs: [],
|
|
795
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
796
|
+
stateMutability: "view"
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
type: "function",
|
|
800
|
+
name: "feeRecipient",
|
|
801
|
+
inputs: [],
|
|
802
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
803
|
+
stateMutability: "view"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
type: "function",
|
|
807
|
+
name: "getTipRecords",
|
|
752
808
|
inputs: [
|
|
753
|
-
{ name: "idSource", type: "string", internalType: "string" },
|
|
754
809
|
{
|
|
755
|
-
name: "
|
|
810
|
+
name: "tipRecipient",
|
|
756
811
|
type: "tuple",
|
|
757
|
-
internalType: "struct
|
|
812
|
+
internalType: "struct TipRecipient",
|
|
758
813
|
components: [
|
|
759
|
-
{ name: "
|
|
814
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
815
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
816
|
+
]
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
outputs: [
|
|
820
|
+
{
|
|
821
|
+
name: "",
|
|
822
|
+
type: "tuple[]",
|
|
823
|
+
internalType: "struct TipRecord[]",
|
|
824
|
+
components: [
|
|
825
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
760
826
|
{
|
|
761
|
-
name: "
|
|
827
|
+
name: "tipToken",
|
|
762
828
|
type: "tuple",
|
|
763
|
-
internalType: "struct
|
|
764
|
-
components: [
|
|
765
|
-
{ name: "url", type: "string", internalType: "string" },
|
|
766
|
-
{ name: "header", type: "string", internalType: "string" },
|
|
767
|
-
{ name: "method", type: "string", internalType: "string" },
|
|
768
|
-
{ name: "body", type: "string", internalType: "string" }
|
|
769
|
-
]
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
name: "reponseResolve",
|
|
773
|
-
type: "tuple[]",
|
|
774
|
-
internalType: "struct AttNetworkResponseResolve[]",
|
|
829
|
+
internalType: "struct TipToken",
|
|
775
830
|
components: [
|
|
776
|
-
{ name: "keyName", type: "string", internalType: "string" },
|
|
777
831
|
{
|
|
778
|
-
name: "
|
|
779
|
-
type: "
|
|
780
|
-
internalType: "
|
|
832
|
+
name: "tokenType",
|
|
833
|
+
type: "uint32",
|
|
834
|
+
internalType: "uint32"
|
|
781
835
|
},
|
|
782
836
|
{
|
|
783
|
-
name: "
|
|
784
|
-
type: "
|
|
785
|
-
internalType: "
|
|
837
|
+
name: "tokenAddress",
|
|
838
|
+
type: "address",
|
|
839
|
+
internalType: "address"
|
|
786
840
|
}
|
|
787
841
|
]
|
|
788
842
|
},
|
|
789
|
-
{ name: "data", type: "string", internalType: "string" },
|
|
790
|
-
{
|
|
791
|
-
name: "attConditions",
|
|
792
|
-
type: "string",
|
|
793
|
-
internalType: "string"
|
|
794
|
-
},
|
|
795
843
|
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
844
|
+
{ name: "tipper", type: "address", internalType: "address" },
|
|
796
845
|
{
|
|
797
|
-
name: "
|
|
798
|
-
type: "
|
|
799
|
-
internalType: "
|
|
800
|
-
}
|
|
801
|
-
{
|
|
802
|
-
name: "attestors",
|
|
803
|
-
type: "tuple[]",
|
|
804
|
-
internalType: "struct Attestor[]",
|
|
805
|
-
components: [
|
|
806
|
-
{
|
|
807
|
-
name: "attestorAddr",
|
|
808
|
-
type: "address",
|
|
809
|
-
internalType: "address"
|
|
810
|
-
},
|
|
811
|
-
{ name: "url", type: "string", internalType: "string" }
|
|
812
|
-
]
|
|
813
|
-
},
|
|
814
|
-
{ name: "signatures", type: "bytes[]", internalType: "bytes[]" }
|
|
846
|
+
name: "nftIds",
|
|
847
|
+
type: "uint256[]",
|
|
848
|
+
internalType: "uint256[]"
|
|
849
|
+
}
|
|
815
850
|
]
|
|
816
|
-
}
|
|
817
|
-
{ name: "index", type: "uint32", internalType: "uint32" }
|
|
851
|
+
}
|
|
818
852
|
],
|
|
819
|
-
|
|
820
|
-
stateMutability: "payable"
|
|
853
|
+
stateMutability: "view"
|
|
821
854
|
},
|
|
822
855
|
{
|
|
823
856
|
type: "function",
|
|
824
|
-
name: "
|
|
825
|
-
inputs: [
|
|
857
|
+
name: "getTipRecordsLength",
|
|
858
|
+
inputs: [
|
|
859
|
+
{
|
|
860
|
+
name: "tipRecipient",
|
|
861
|
+
type: "tuple",
|
|
862
|
+
internalType: "struct TipRecipient",
|
|
863
|
+
components: [
|
|
864
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
865
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
866
|
+
]
|
|
867
|
+
}
|
|
868
|
+
],
|
|
826
869
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
827
870
|
stateMutability: "view"
|
|
828
871
|
},
|
|
829
872
|
{
|
|
830
873
|
type: "function",
|
|
831
|
-
name: "
|
|
832
|
-
inputs: [
|
|
833
|
-
|
|
874
|
+
name: "getTipRecordsNativeAmount",
|
|
875
|
+
inputs: [
|
|
876
|
+
{
|
|
877
|
+
name: "tipRecipient",
|
|
878
|
+
type: "tuple",
|
|
879
|
+
internalType: "struct TipRecipient",
|
|
880
|
+
components: [
|
|
881
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
882
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
883
|
+
]
|
|
884
|
+
}
|
|
885
|
+
],
|
|
886
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
834
887
|
stateMutability: "view"
|
|
835
888
|
},
|
|
836
889
|
{
|
|
837
890
|
type: "function",
|
|
838
|
-
name: "
|
|
891
|
+
name: "getTipRecordsPaginated",
|
|
839
892
|
inputs: [
|
|
840
893
|
{
|
|
841
894
|
name: "tipRecipient",
|
|
@@ -845,7 +898,9 @@ var abi_default = [
|
|
|
845
898
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
846
899
|
{ name: "id", type: "string", internalType: "string" }
|
|
847
900
|
]
|
|
848
|
-
}
|
|
901
|
+
},
|
|
902
|
+
{ name: "offset", type: "uint256", internalType: "uint256" },
|
|
903
|
+
{ name: "limit", type: "uint256", internalType: "uint256" }
|
|
849
904
|
],
|
|
850
905
|
outputs: [
|
|
851
906
|
{
|
|
@@ -873,7 +928,11 @@ var abi_default = [
|
|
|
873
928
|
},
|
|
874
929
|
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
875
930
|
{ name: "tipper", type: "address", internalType: "address" },
|
|
876
|
-
{
|
|
931
|
+
{
|
|
932
|
+
name: "nftIds",
|
|
933
|
+
type: "uint256[]",
|
|
934
|
+
internalType: "uint256[]"
|
|
935
|
+
}
|
|
877
936
|
]
|
|
878
937
|
}
|
|
879
938
|
],
|
|
@@ -899,7 +958,11 @@ var abi_default = [
|
|
|
899
958
|
type: "address",
|
|
900
959
|
internalType: "contract IPrimusZKTLS"
|
|
901
960
|
},
|
|
902
|
-
{
|
|
961
|
+
{
|
|
962
|
+
name: "feeRecipient_",
|
|
963
|
+
type: "address",
|
|
964
|
+
internalType: "address"
|
|
965
|
+
},
|
|
903
966
|
{ name: "claimFee_", type: "uint256", internalType: "uint256" }
|
|
904
967
|
],
|
|
905
968
|
outputs: [],
|
|
@@ -917,7 +980,11 @@ var abi_default = [
|
|
|
917
980
|
name: "primusZKTLS",
|
|
918
981
|
inputs: [],
|
|
919
982
|
outputs: [
|
|
920
|
-
{
|
|
983
|
+
{
|
|
984
|
+
name: "",
|
|
985
|
+
type: "address",
|
|
986
|
+
internalType: "contract IPrimusZKTLS"
|
|
987
|
+
}
|
|
921
988
|
],
|
|
922
989
|
stateMutability: "view"
|
|
923
990
|
},
|
|
@@ -941,7 +1008,11 @@ var abi_default = [
|
|
|
941
1008
|
type: "function",
|
|
942
1009
|
name: "setFeeRecipient",
|
|
943
1010
|
inputs: [
|
|
944
|
-
{
|
|
1011
|
+
{
|
|
1012
|
+
name: "feeRecipient_",
|
|
1013
|
+
type: "address",
|
|
1014
|
+
internalType: "address"
|
|
1015
|
+
}
|
|
945
1016
|
],
|
|
946
1017
|
outputs: [],
|
|
947
1018
|
stateMutability: "nonpayable"
|
|
@@ -993,7 +1064,11 @@ var abi_default = [
|
|
|
993
1064
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
994
1065
|
{ name: "id", type: "string", internalType: "string" },
|
|
995
1066
|
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
996
|
-
{
|
|
1067
|
+
{
|
|
1068
|
+
name: "nftIds",
|
|
1069
|
+
type: "uint256[]",
|
|
1070
|
+
internalType: "uint256[]"
|
|
1071
|
+
}
|
|
997
1072
|
]
|
|
998
1073
|
}
|
|
999
1074
|
],
|
|
@@ -1025,7 +1100,11 @@ var abi_default = [
|
|
|
1025
1100
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
1026
1101
|
{ name: "id", type: "string", internalType: "string" },
|
|
1027
1102
|
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
1028
|
-
{
|
|
1103
|
+
{
|
|
1104
|
+
name: "nftIds",
|
|
1105
|
+
type: "uint256[]",
|
|
1106
|
+
internalType: "uint256[]"
|
|
1107
|
+
}
|
|
1029
1108
|
]
|
|
1030
1109
|
}
|
|
1031
1110
|
],
|
|
@@ -1043,7 +1122,11 @@ var abi_default = [
|
|
|
1043
1122
|
components: [
|
|
1044
1123
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
1045
1124
|
{ name: "id", type: "string", internalType: "string" },
|
|
1046
|
-
{
|
|
1125
|
+
{
|
|
1126
|
+
name: "tipTimestamp",
|
|
1127
|
+
type: "uint64",
|
|
1128
|
+
internalType: "uint64"
|
|
1129
|
+
}
|
|
1047
1130
|
]
|
|
1048
1131
|
}
|
|
1049
1132
|
],
|
|
@@ -1117,6 +1200,18 @@ var abi_default = [
|
|
|
1117
1200
|
type: "uint64",
|
|
1118
1201
|
indexed: false,
|
|
1119
1202
|
internalType: "uint64"
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
name: "tokenType",
|
|
1206
|
+
type: "uint32",
|
|
1207
|
+
indexed: false,
|
|
1208
|
+
internalType: "uint32"
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
name: "nftIds",
|
|
1212
|
+
type: "uint256[]",
|
|
1213
|
+
indexed: false,
|
|
1214
|
+
internalType: "uint256[]"
|
|
1120
1215
|
}
|
|
1121
1216
|
],
|
|
1122
1217
|
anonymous: false
|
|
@@ -1192,6 +1287,18 @@ var abi_default = [
|
|
|
1192
1287
|
type: "uint64",
|
|
1193
1288
|
indexed: false,
|
|
1194
1289
|
internalType: "uint64"
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
name: "tokenType",
|
|
1293
|
+
type: "uint32",
|
|
1294
|
+
indexed: false,
|
|
1295
|
+
internalType: "uint32"
|
|
1296
|
+
},
|
|
1297
|
+
{
|
|
1298
|
+
name: "nftIds",
|
|
1299
|
+
type: "uint256[]",
|
|
1300
|
+
indexed: false,
|
|
1301
|
+
internalType: "uint256[]"
|
|
1195
1302
|
}
|
|
1196
1303
|
],
|
|
1197
1304
|
anonymous: false
|
|
@@ -1241,6 +1348,18 @@ var abi_default = [
|
|
|
1241
1348
|
type: "uint64",
|
|
1242
1349
|
indexed: false,
|
|
1243
1350
|
internalType: "uint64"
|
|
1351
|
+
},
|
|
1352
|
+
{
|
|
1353
|
+
name: "tokenType",
|
|
1354
|
+
type: "uint32",
|
|
1355
|
+
indexed: false,
|
|
1356
|
+
internalType: "uint32"
|
|
1357
|
+
},
|
|
1358
|
+
{
|
|
1359
|
+
name: "nftIds",
|
|
1360
|
+
type: "uint256[]",
|
|
1361
|
+
indexed: false,
|
|
1362
|
+
internalType: "uint256[]"
|
|
1244
1363
|
}
|
|
1245
1364
|
],
|
|
1246
1365
|
anonymous: false
|
|
@@ -1449,6 +1568,7 @@ var Erc721Contract = class {
|
|
|
1449
1568
|
var Erc721Contract_default = Erc721Contract;
|
|
1450
1569
|
|
|
1451
1570
|
// src/classes/Fund.ts
|
|
1571
|
+
var defaultDecimals = 18;
|
|
1452
1572
|
var { parseUnits: parseUnits2, formatUnits: formatUnits2 } = ethers3.utils;
|
|
1453
1573
|
var Fund = class {
|
|
1454
1574
|
fundContract;
|
|
@@ -1478,7 +1598,7 @@ var Fund = class {
|
|
|
1478
1598
|
try {
|
|
1479
1599
|
const recipientInfos = [];
|
|
1480
1600
|
recipientInfos[0] = recipientInfo;
|
|
1481
|
-
let decimals =
|
|
1601
|
+
let decimals = defaultDecimals;
|
|
1482
1602
|
let params = [];
|
|
1483
1603
|
if (tokenInfo.tokenType === 0) {
|
|
1484
1604
|
await this.approve(tokenInfo, recipientInfos);
|
|
@@ -1519,7 +1639,7 @@ var Fund = class {
|
|
|
1519
1639
|
try {
|
|
1520
1640
|
const recipientInfos = [];
|
|
1521
1641
|
recipientInfos[0] = recipientInfo;
|
|
1522
|
-
let decimals =
|
|
1642
|
+
let decimals = defaultDecimals;
|
|
1523
1643
|
let params = [];
|
|
1524
1644
|
if (tokenInfo.tokenType === 0) {
|
|
1525
1645
|
const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
|
|
@@ -1580,7 +1700,7 @@ var Fund = class {
|
|
|
1580
1700
|
async fundBatch(tokenInfo, recipientInfoList) {
|
|
1581
1701
|
return new Promise(async (resolve, reject) => {
|
|
1582
1702
|
try {
|
|
1583
|
-
let decimals =
|
|
1703
|
+
let decimals = defaultDecimals;
|
|
1584
1704
|
let params = [];
|
|
1585
1705
|
if (tokenInfo.tokenType === 0) {
|
|
1586
1706
|
await this.approve(tokenInfo, recipientInfoList);
|
|
@@ -1731,6 +1851,51 @@ var Fund = class {
|
|
|
1731
1851
|
}
|
|
1732
1852
|
});
|
|
1733
1853
|
}
|
|
1854
|
+
async _formatTipRecords(fundRecords) {
|
|
1855
|
+
console.log("fundRecords", fundRecords);
|
|
1856
|
+
let formatRecords = [];
|
|
1857
|
+
for (const record of fundRecords) {
|
|
1858
|
+
const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
|
|
1859
|
+
let decimals = defaultDecimals;
|
|
1860
|
+
let symbol = "";
|
|
1861
|
+
let tokenId = null;
|
|
1862
|
+
let nftInfo = null;
|
|
1863
|
+
if (tokenType === 0) {
|
|
1864
|
+
const tokenContract = new Erc20Contract_default(this.provider, tokenAddress);
|
|
1865
|
+
decimals = await tokenContract.decimals();
|
|
1866
|
+
symbol = await tokenContract.symbol();
|
|
1867
|
+
} else if (tokenType === 1) {
|
|
1868
|
+
symbol = NATIVETOKENS[this.chainId];
|
|
1869
|
+
} else if (tokenType === 2) {
|
|
1870
|
+
decimals = 0;
|
|
1871
|
+
tokenId = parseInt(nftIds[0]);
|
|
1872
|
+
const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
|
|
1873
|
+
nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
|
|
1874
|
+
}
|
|
1875
|
+
let fundToken = {
|
|
1876
|
+
tokenType,
|
|
1877
|
+
// tokenAmount: formatUnits(amount, decimals),
|
|
1878
|
+
decimals,
|
|
1879
|
+
symbol,
|
|
1880
|
+
chainName: CHAINNAMES[this.chainId],
|
|
1881
|
+
chainId: this.chainId
|
|
1882
|
+
};
|
|
1883
|
+
if (tokenType === 0) {
|
|
1884
|
+
fundToken.tokenAddress = tokenAddress;
|
|
1885
|
+
}
|
|
1886
|
+
if (tokenType === 2) {
|
|
1887
|
+
Object.assign(fundToken, nftInfo ?? {});
|
|
1888
|
+
}
|
|
1889
|
+
formatRecords.push({
|
|
1890
|
+
funder: tipper,
|
|
1891
|
+
fundToken,
|
|
1892
|
+
amount: formatUnits2(amount, decimals),
|
|
1893
|
+
timestamp: timestamp.toNumber()
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
console.log("formatRecords", formatRecords);
|
|
1897
|
+
return formatRecords;
|
|
1898
|
+
}
|
|
1734
1899
|
async getTipRecords(getFundRecordsParams) {
|
|
1735
1900
|
return new Promise(async (resolve, reject) => {
|
|
1736
1901
|
try {
|
|
@@ -1741,48 +1906,62 @@ var Fund = class {
|
|
|
1741
1906
|
};
|
|
1742
1907
|
});
|
|
1743
1908
|
const fundRecords = await this.fundContract.callMethod("getTipRecords", formatGetFundRecordsParams);
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
} else if (tokenType === 2) {
|
|
1759
|
-
decimals = 0;
|
|
1760
|
-
tokenId = parseInt(nftIds[0]);
|
|
1761
|
-
const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
|
|
1762
|
-
nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
|
|
1763
|
-
}
|
|
1764
|
-
let fundToken = {
|
|
1765
|
-
tokenType,
|
|
1766
|
-
// tokenAmount: formatUnits(amount, decimals),
|
|
1767
|
-
decimals,
|
|
1768
|
-
symbol,
|
|
1769
|
-
chainName: CHAINNAMES[this.chainId],
|
|
1770
|
-
chainId: this.chainId
|
|
1909
|
+
let formatRecords = await this._formatTipRecords(fundRecords);
|
|
1910
|
+
return resolve(formatRecords);
|
|
1911
|
+
} catch (error) {
|
|
1912
|
+
return reject(error);
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
async getTipRecordsNativeAmount(getFundRecordsParams) {
|
|
1917
|
+
return new Promise(async (resolve, reject) => {
|
|
1918
|
+
try {
|
|
1919
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1920
|
+
return {
|
|
1921
|
+
idSource: item.socialPlatform,
|
|
1922
|
+
id: item.userIdentifier
|
|
1771
1923
|
};
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1924
|
+
});
|
|
1925
|
+
const fundNativeTokenAmount = await this.fundContract.callMethod("getTipRecordsNativeAmount", formatGetFundRecordsParams);
|
|
1926
|
+
const amount = formatUnits2(fundNativeTokenAmount, defaultDecimals);
|
|
1927
|
+
console.log("fundNativeTokenAmount", amount);
|
|
1928
|
+
return resolve(amount);
|
|
1929
|
+
} catch (error) {
|
|
1930
|
+
return reject(error);
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
async getTipRecordsLength(getFundRecordsParams) {
|
|
1935
|
+
return new Promise(async (resolve, reject) => {
|
|
1936
|
+
try {
|
|
1937
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1938
|
+
return {
|
|
1939
|
+
idSource: item.socialPlatform,
|
|
1940
|
+
id: item.userIdentifier
|
|
1941
|
+
};
|
|
1942
|
+
});
|
|
1943
|
+
const fundRecordsLen = await this.fundContract.callMethod("getTipRecordsLength", formatGetFundRecordsParams);
|
|
1944
|
+
const len = fundRecordsLen.toNumber();
|
|
1945
|
+
console.log("fundRecordsLength", len);
|
|
1946
|
+
return resolve(len);
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
return reject(error);
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
async getTipRecordsPaginated(getFundRecordsParams, pageNum, pageSize) {
|
|
1953
|
+
return new Promise(async (resolve, reject) => {
|
|
1954
|
+
try {
|
|
1955
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1956
|
+
return {
|
|
1957
|
+
idSource: item.socialPlatform,
|
|
1958
|
+
id: item.userIdentifier
|
|
1959
|
+
};
|
|
1960
|
+
});
|
|
1961
|
+
let params = [...formatGetFundRecordsParams, pageNum, pageSize];
|
|
1962
|
+
const fundRecords = await this.fundContract.callMethod("getTipRecordsPaginated", params);
|
|
1963
|
+
let formatRecords = await this._formatTipRecords(fundRecords);
|
|
1964
|
+
console.log("fundRecordsPaginated", formatRecords);
|
|
1786
1965
|
return resolve(formatRecords);
|
|
1787
1966
|
} catch (error) {
|
|
1788
1967
|
return reject(error);
|
|
@@ -2660,6 +2839,7 @@ var ZktlsSdk = class {
|
|
|
2660
2839
|
};
|
|
2661
2840
|
|
|
2662
2841
|
// src/index.ts
|
|
2842
|
+
console.log("SUPPORTEDCHAINIDS", SUPPORTEDCHAINIDS);
|
|
2663
2843
|
var PrimusFund = class {
|
|
2664
2844
|
supportedChainIds = SUPPORTEDCHAINIDS;
|
|
2665
2845
|
supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
|
|
@@ -2880,25 +3060,31 @@ var PrimusFund = class {
|
|
|
2880
3060
|
}
|
|
2881
3061
|
});
|
|
2882
3062
|
}
|
|
3063
|
+
_formatGetFundRecordsParams(queryList) {
|
|
3064
|
+
const socialPlatforms = [];
|
|
3065
|
+
const userIdentifiers = [];
|
|
3066
|
+
for (let i = 0; i < queryList.length; i++) {
|
|
3067
|
+
socialPlatforms[i] = queryList[i].socialPlatform.toLowerCase();
|
|
3068
|
+
userIdentifiers[i] = queryList[i].userIdentifier;
|
|
3069
|
+
if (socialPlatforms[i] === "x" && userIdentifiers[i].startsWith("@")) {
|
|
3070
|
+
queryList[i].userIdentifier = queryList[i].userIdentifier.slice(1);
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
return queryList;
|
|
3074
|
+
}
|
|
2883
3075
|
async getFundRecords(getFundRecordsParams) {
|
|
2884
|
-
|
|
3076
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3077
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3078
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
2885
3079
|
return new Promise(async (resolve, reject) => {
|
|
2886
3080
|
if (!queryList || queryList?.length === 0) {
|
|
2887
3081
|
const error = new Error("getFundRecordsParams is empty");
|
|
2888
3082
|
return reject(error);
|
|
2889
3083
|
}
|
|
2890
|
-
|
|
2891
|
-
const userIdentifiers = [];
|
|
2892
|
-
for (let i = 0; i < queryList.length; i++) {
|
|
2893
|
-
socialPlatforms[i] = queryList[i].socialPlatform.toLowerCase();
|
|
2894
|
-
userIdentifiers[i] = queryList[i].userIdentifier;
|
|
2895
|
-
if (socialPlatforms[i] === "x" && userIdentifiers[i].startsWith("@")) {
|
|
2896
|
-
queryList[i].userIdentifier = queryList[i].userIdentifier.slice(1);
|
|
2897
|
-
}
|
|
2898
|
-
}
|
|
2899
|
-
if (socialPlatforms.length !== userIdentifiers.length) {
|
|
3084
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
2900
3085
|
return reject(`getFundRecordsParams is wrong`);
|
|
2901
3086
|
}
|
|
3087
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
2902
3088
|
try {
|
|
2903
3089
|
const result = await this._fund?.getTipRecords(queryList);
|
|
2904
3090
|
resolve(result);
|
|
@@ -2907,6 +3093,69 @@ var PrimusFund = class {
|
|
|
2907
3093
|
}
|
|
2908
3094
|
});
|
|
2909
3095
|
}
|
|
3096
|
+
async getFundRecordsNativeAmount(getFundRecordsParams) {
|
|
3097
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3098
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3099
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3100
|
+
return new Promise(async (resolve, reject) => {
|
|
3101
|
+
if (!queryList || queryList?.length === 0) {
|
|
3102
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3103
|
+
return reject(error);
|
|
3104
|
+
}
|
|
3105
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3106
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3107
|
+
}
|
|
3108
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3109
|
+
try {
|
|
3110
|
+
const result = await this._fund?.getTipRecordsNativeAmount(queryList);
|
|
3111
|
+
resolve(result);
|
|
3112
|
+
} catch (error) {
|
|
3113
|
+
return reject(error);
|
|
3114
|
+
}
|
|
3115
|
+
});
|
|
3116
|
+
}
|
|
3117
|
+
async getFundRecordsLen(getFundRecordsParams) {
|
|
3118
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3119
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3120
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3121
|
+
return new Promise(async (resolve, reject) => {
|
|
3122
|
+
if (!queryList || queryList?.length === 0) {
|
|
3123
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3124
|
+
return reject(error);
|
|
3125
|
+
}
|
|
3126
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3127
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3128
|
+
}
|
|
3129
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3130
|
+
try {
|
|
3131
|
+
const result = await this._fund?.getTipRecordsLength(queryList);
|
|
3132
|
+
resolve(result);
|
|
3133
|
+
} catch (error) {
|
|
3134
|
+
return reject(error);
|
|
3135
|
+
}
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
async getFundRecordsPaginated(getFundRecordsParams, pageNum, pageSize) {
|
|
3139
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3140
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3141
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3142
|
+
return new Promise(async (resolve, reject) => {
|
|
3143
|
+
if (!queryList || queryList?.length === 0) {
|
|
3144
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3145
|
+
return reject(error);
|
|
3146
|
+
}
|
|
3147
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3148
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3149
|
+
}
|
|
3150
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3151
|
+
try {
|
|
3152
|
+
const result = await this._fund?.getTipRecordsPaginated(queryList, pageNum, pageSize);
|
|
3153
|
+
resolve(result);
|
|
3154
|
+
} catch (error) {
|
|
3155
|
+
return reject(error);
|
|
3156
|
+
}
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
2910
3159
|
async fundForRedPacket(fundParam) {
|
|
2911
3160
|
return new Promise(async (resolve, reject) => {
|
|
2912
3161
|
try {
|