@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.js
CHANGED
|
@@ -199,9 +199,7 @@ var Contract = class {
|
|
|
199
199
|
try {
|
|
200
200
|
console.log("sendTransaction params:", functionName, ...functionParams);
|
|
201
201
|
const tx = await this.contractInstance[functionName](...functionParams);
|
|
202
|
-
|
|
203
|
-
console.log("txreceipt", txreceipt);
|
|
204
|
-
resolve(txreceipt);
|
|
202
|
+
resolve(tx.hash);
|
|
205
203
|
} catch (error) {
|
|
206
204
|
console.log("sendTransaction error:", error);
|
|
207
205
|
const errStr = error?.message || error?.toString()?.toLowerCase() || "";
|
|
@@ -217,7 +215,7 @@ var Contract = class {
|
|
|
217
215
|
if (isNoPendingWithdrawals) {
|
|
218
216
|
return reject("no pending withdrawals");
|
|
219
217
|
}
|
|
220
|
-
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS"];
|
|
218
|
+
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS", "The caller does not have enough funds for value transfer."];
|
|
221
219
|
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
222
220
|
if (isInsufficientBalance) {
|
|
223
221
|
return reject("insufficient balance");
|
|
@@ -619,7 +617,11 @@ var abi_default = [
|
|
|
619
617
|
type: "function",
|
|
620
618
|
name: "addBatchIdSource",
|
|
621
619
|
inputs: [
|
|
622
|
-
{
|
|
620
|
+
{
|
|
621
|
+
name: "sourceName_",
|
|
622
|
+
type: "string[]",
|
|
623
|
+
internalType: "string[]"
|
|
624
|
+
},
|
|
623
625
|
{ name: "url_", type: "string[]", internalType: "string[]" },
|
|
624
626
|
{ name: "jsonPath_", type: "string[]", internalType: "string[]" }
|
|
625
627
|
],
|
|
@@ -636,15 +638,27 @@ var abi_default = [
|
|
|
636
638
|
type: "tuple[]",
|
|
637
639
|
internalType: "struct Attestation[]",
|
|
638
640
|
components: [
|
|
639
|
-
{
|
|
641
|
+
{
|
|
642
|
+
name: "recipient",
|
|
643
|
+
type: "address",
|
|
644
|
+
internalType: "address"
|
|
645
|
+
},
|
|
640
646
|
{
|
|
641
647
|
name: "request",
|
|
642
648
|
type: "tuple",
|
|
643
649
|
internalType: "struct AttNetworkRequest",
|
|
644
650
|
components: [
|
|
645
651
|
{ name: "url", type: "string", internalType: "string" },
|
|
646
|
-
{
|
|
647
|
-
|
|
652
|
+
{
|
|
653
|
+
name: "header",
|
|
654
|
+
type: "string",
|
|
655
|
+
internalType: "string"
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: "method",
|
|
659
|
+
type: "string",
|
|
660
|
+
internalType: "string"
|
|
661
|
+
},
|
|
648
662
|
{ name: "body", type: "string", internalType: "string" }
|
|
649
663
|
]
|
|
650
664
|
},
|
|
@@ -653,7 +667,11 @@ var abi_default = [
|
|
|
653
667
|
type: "tuple[]",
|
|
654
668
|
internalType: "struct AttNetworkResponseResolve[]",
|
|
655
669
|
components: [
|
|
656
|
-
{
|
|
670
|
+
{
|
|
671
|
+
name: "keyName",
|
|
672
|
+
type: "string",
|
|
673
|
+
internalType: "string"
|
|
674
|
+
},
|
|
657
675
|
{
|
|
658
676
|
name: "parseType",
|
|
659
677
|
type: "string",
|
|
@@ -691,7 +709,11 @@ var abi_default = [
|
|
|
691
709
|
{ name: "url", type: "string", internalType: "string" }
|
|
692
710
|
]
|
|
693
711
|
},
|
|
694
|
-
{
|
|
712
|
+
{
|
|
713
|
+
name: "signatures",
|
|
714
|
+
type: "bytes[]",
|
|
715
|
+
internalType: "bytes[]"
|
|
716
|
+
}
|
|
695
717
|
]
|
|
696
718
|
}
|
|
697
719
|
],
|
|
@@ -708,15 +730,27 @@ var abi_default = [
|
|
|
708
730
|
type: "tuple",
|
|
709
731
|
internalType: "struct Attestation",
|
|
710
732
|
components: [
|
|
711
|
-
{
|
|
733
|
+
{
|
|
734
|
+
name: "recipient",
|
|
735
|
+
type: "address",
|
|
736
|
+
internalType: "address"
|
|
737
|
+
},
|
|
712
738
|
{
|
|
713
739
|
name: "request",
|
|
714
740
|
type: "tuple",
|
|
715
741
|
internalType: "struct AttNetworkRequest",
|
|
716
742
|
components: [
|
|
717
743
|
{ name: "url", type: "string", internalType: "string" },
|
|
718
|
-
{
|
|
719
|
-
|
|
744
|
+
{
|
|
745
|
+
name: "header",
|
|
746
|
+
type: "string",
|
|
747
|
+
internalType: "string"
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
name: "method",
|
|
751
|
+
type: "string",
|
|
752
|
+
internalType: "string"
|
|
753
|
+
},
|
|
720
754
|
{ name: "body", type: "string", internalType: "string" }
|
|
721
755
|
]
|
|
722
756
|
},
|
|
@@ -725,7 +759,11 @@ var abi_default = [
|
|
|
725
759
|
type: "tuple[]",
|
|
726
760
|
internalType: "struct AttNetworkResponseResolve[]",
|
|
727
761
|
components: [
|
|
728
|
-
{
|
|
762
|
+
{
|
|
763
|
+
name: "keyName",
|
|
764
|
+
type: "string",
|
|
765
|
+
internalType: "string"
|
|
766
|
+
},
|
|
729
767
|
{
|
|
730
768
|
name: "parseType",
|
|
731
769
|
type: "string",
|
|
@@ -763,7 +801,11 @@ var abi_default = [
|
|
|
763
801
|
{ name: "url", type: "string", internalType: "string" }
|
|
764
802
|
]
|
|
765
803
|
},
|
|
766
|
-
{
|
|
804
|
+
{
|
|
805
|
+
name: "signatures",
|
|
806
|
+
type: "bytes[]",
|
|
807
|
+
internalType: "bytes[]"
|
|
808
|
+
}
|
|
767
809
|
]
|
|
768
810
|
}
|
|
769
811
|
],
|
|
@@ -772,94 +814,105 @@ var abi_default = [
|
|
|
772
814
|
},
|
|
773
815
|
{
|
|
774
816
|
type: "function",
|
|
775
|
-
name: "
|
|
817
|
+
name: "claimFee",
|
|
818
|
+
inputs: [],
|
|
819
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
820
|
+
stateMutability: "view"
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
type: "function",
|
|
824
|
+
name: "feeRecipient",
|
|
825
|
+
inputs: [],
|
|
826
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
827
|
+
stateMutability: "view"
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
type: "function",
|
|
831
|
+
name: "getTipRecords",
|
|
776
832
|
inputs: [
|
|
777
|
-
{ name: "idSource", type: "string", internalType: "string" },
|
|
778
833
|
{
|
|
779
|
-
name: "
|
|
834
|
+
name: "tipRecipient",
|
|
780
835
|
type: "tuple",
|
|
781
|
-
internalType: "struct
|
|
836
|
+
internalType: "struct TipRecipient",
|
|
782
837
|
components: [
|
|
783
|
-
{ name: "
|
|
838
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
839
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
840
|
+
]
|
|
841
|
+
}
|
|
842
|
+
],
|
|
843
|
+
outputs: [
|
|
844
|
+
{
|
|
845
|
+
name: "",
|
|
846
|
+
type: "tuple[]",
|
|
847
|
+
internalType: "struct TipRecord[]",
|
|
848
|
+
components: [
|
|
849
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
784
850
|
{
|
|
785
|
-
name: "
|
|
851
|
+
name: "tipToken",
|
|
786
852
|
type: "tuple",
|
|
787
|
-
internalType: "struct
|
|
788
|
-
components: [
|
|
789
|
-
{ name: "url", type: "string", internalType: "string" },
|
|
790
|
-
{ name: "header", type: "string", internalType: "string" },
|
|
791
|
-
{ name: "method", type: "string", internalType: "string" },
|
|
792
|
-
{ name: "body", type: "string", internalType: "string" }
|
|
793
|
-
]
|
|
794
|
-
},
|
|
795
|
-
{
|
|
796
|
-
name: "reponseResolve",
|
|
797
|
-
type: "tuple[]",
|
|
798
|
-
internalType: "struct AttNetworkResponseResolve[]",
|
|
853
|
+
internalType: "struct TipToken",
|
|
799
854
|
components: [
|
|
800
|
-
{ name: "keyName", type: "string", internalType: "string" },
|
|
801
855
|
{
|
|
802
|
-
name: "
|
|
803
|
-
type: "
|
|
804
|
-
internalType: "
|
|
856
|
+
name: "tokenType",
|
|
857
|
+
type: "uint32",
|
|
858
|
+
internalType: "uint32"
|
|
805
859
|
},
|
|
806
860
|
{
|
|
807
|
-
name: "
|
|
808
|
-
type: "
|
|
809
|
-
internalType: "
|
|
861
|
+
name: "tokenAddress",
|
|
862
|
+
type: "address",
|
|
863
|
+
internalType: "address"
|
|
810
864
|
}
|
|
811
865
|
]
|
|
812
866
|
},
|
|
813
|
-
{ name: "data", type: "string", internalType: "string" },
|
|
814
|
-
{
|
|
815
|
-
name: "attConditions",
|
|
816
|
-
type: "string",
|
|
817
|
-
internalType: "string"
|
|
818
|
-
},
|
|
819
867
|
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
868
|
+
{ name: "tipper", type: "address", internalType: "address" },
|
|
820
869
|
{
|
|
821
|
-
name: "
|
|
822
|
-
type: "
|
|
823
|
-
internalType: "
|
|
824
|
-
}
|
|
825
|
-
{
|
|
826
|
-
name: "attestors",
|
|
827
|
-
type: "tuple[]",
|
|
828
|
-
internalType: "struct Attestor[]",
|
|
829
|
-
components: [
|
|
830
|
-
{
|
|
831
|
-
name: "attestorAddr",
|
|
832
|
-
type: "address",
|
|
833
|
-
internalType: "address"
|
|
834
|
-
},
|
|
835
|
-
{ name: "url", type: "string", internalType: "string" }
|
|
836
|
-
]
|
|
837
|
-
},
|
|
838
|
-
{ name: "signatures", type: "bytes[]", internalType: "bytes[]" }
|
|
870
|
+
name: "nftIds",
|
|
871
|
+
type: "uint256[]",
|
|
872
|
+
internalType: "uint256[]"
|
|
873
|
+
}
|
|
839
874
|
]
|
|
840
|
-
}
|
|
841
|
-
{ name: "index", type: "uint32", internalType: "uint32" }
|
|
875
|
+
}
|
|
842
876
|
],
|
|
843
|
-
|
|
844
|
-
stateMutability: "payable"
|
|
877
|
+
stateMutability: "view"
|
|
845
878
|
},
|
|
846
879
|
{
|
|
847
880
|
type: "function",
|
|
848
|
-
name: "
|
|
849
|
-
inputs: [
|
|
881
|
+
name: "getTipRecordsLength",
|
|
882
|
+
inputs: [
|
|
883
|
+
{
|
|
884
|
+
name: "tipRecipient",
|
|
885
|
+
type: "tuple",
|
|
886
|
+
internalType: "struct TipRecipient",
|
|
887
|
+
components: [
|
|
888
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
889
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
890
|
+
]
|
|
891
|
+
}
|
|
892
|
+
],
|
|
850
893
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
851
894
|
stateMutability: "view"
|
|
852
895
|
},
|
|
853
896
|
{
|
|
854
897
|
type: "function",
|
|
855
|
-
name: "
|
|
856
|
-
inputs: [
|
|
857
|
-
|
|
898
|
+
name: "getTipRecordsNativeAmount",
|
|
899
|
+
inputs: [
|
|
900
|
+
{
|
|
901
|
+
name: "tipRecipient",
|
|
902
|
+
type: "tuple",
|
|
903
|
+
internalType: "struct TipRecipient",
|
|
904
|
+
components: [
|
|
905
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
906
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
907
|
+
]
|
|
908
|
+
}
|
|
909
|
+
],
|
|
910
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
858
911
|
stateMutability: "view"
|
|
859
912
|
},
|
|
860
913
|
{
|
|
861
914
|
type: "function",
|
|
862
|
-
name: "
|
|
915
|
+
name: "getTipRecordsPaginated",
|
|
863
916
|
inputs: [
|
|
864
917
|
{
|
|
865
918
|
name: "tipRecipient",
|
|
@@ -869,7 +922,9 @@ var abi_default = [
|
|
|
869
922
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
870
923
|
{ name: "id", type: "string", internalType: "string" }
|
|
871
924
|
]
|
|
872
|
-
}
|
|
925
|
+
},
|
|
926
|
+
{ name: "offset", type: "uint256", internalType: "uint256" },
|
|
927
|
+
{ name: "limit", type: "uint256", internalType: "uint256" }
|
|
873
928
|
],
|
|
874
929
|
outputs: [
|
|
875
930
|
{
|
|
@@ -897,7 +952,11 @@ var abi_default = [
|
|
|
897
952
|
},
|
|
898
953
|
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
899
954
|
{ name: "tipper", type: "address", internalType: "address" },
|
|
900
|
-
{
|
|
955
|
+
{
|
|
956
|
+
name: "nftIds",
|
|
957
|
+
type: "uint256[]",
|
|
958
|
+
internalType: "uint256[]"
|
|
959
|
+
}
|
|
901
960
|
]
|
|
902
961
|
}
|
|
903
962
|
],
|
|
@@ -923,7 +982,11 @@ var abi_default = [
|
|
|
923
982
|
type: "address",
|
|
924
983
|
internalType: "contract IPrimusZKTLS"
|
|
925
984
|
},
|
|
926
|
-
{
|
|
985
|
+
{
|
|
986
|
+
name: "feeRecipient_",
|
|
987
|
+
type: "address",
|
|
988
|
+
internalType: "address"
|
|
989
|
+
},
|
|
927
990
|
{ name: "claimFee_", type: "uint256", internalType: "uint256" }
|
|
928
991
|
],
|
|
929
992
|
outputs: [],
|
|
@@ -941,7 +1004,11 @@ var abi_default = [
|
|
|
941
1004
|
name: "primusZKTLS",
|
|
942
1005
|
inputs: [],
|
|
943
1006
|
outputs: [
|
|
944
|
-
{
|
|
1007
|
+
{
|
|
1008
|
+
name: "",
|
|
1009
|
+
type: "address",
|
|
1010
|
+
internalType: "contract IPrimusZKTLS"
|
|
1011
|
+
}
|
|
945
1012
|
],
|
|
946
1013
|
stateMutability: "view"
|
|
947
1014
|
},
|
|
@@ -965,7 +1032,11 @@ var abi_default = [
|
|
|
965
1032
|
type: "function",
|
|
966
1033
|
name: "setFeeRecipient",
|
|
967
1034
|
inputs: [
|
|
968
|
-
{
|
|
1035
|
+
{
|
|
1036
|
+
name: "feeRecipient_",
|
|
1037
|
+
type: "address",
|
|
1038
|
+
internalType: "address"
|
|
1039
|
+
}
|
|
969
1040
|
],
|
|
970
1041
|
outputs: [],
|
|
971
1042
|
stateMutability: "nonpayable"
|
|
@@ -1017,7 +1088,11 @@ var abi_default = [
|
|
|
1017
1088
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
1018
1089
|
{ name: "id", type: "string", internalType: "string" },
|
|
1019
1090
|
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
1020
|
-
{
|
|
1091
|
+
{
|
|
1092
|
+
name: "nftIds",
|
|
1093
|
+
type: "uint256[]",
|
|
1094
|
+
internalType: "uint256[]"
|
|
1095
|
+
}
|
|
1021
1096
|
]
|
|
1022
1097
|
}
|
|
1023
1098
|
],
|
|
@@ -1049,7 +1124,11 @@ var abi_default = [
|
|
|
1049
1124
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
1050
1125
|
{ name: "id", type: "string", internalType: "string" },
|
|
1051
1126
|
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
1052
|
-
{
|
|
1127
|
+
{
|
|
1128
|
+
name: "nftIds",
|
|
1129
|
+
type: "uint256[]",
|
|
1130
|
+
internalType: "uint256[]"
|
|
1131
|
+
}
|
|
1053
1132
|
]
|
|
1054
1133
|
}
|
|
1055
1134
|
],
|
|
@@ -1067,7 +1146,11 @@ var abi_default = [
|
|
|
1067
1146
|
components: [
|
|
1068
1147
|
{ name: "idSource", type: "string", internalType: "string" },
|
|
1069
1148
|
{ name: "id", type: "string", internalType: "string" },
|
|
1070
|
-
{
|
|
1149
|
+
{
|
|
1150
|
+
name: "tipTimestamp",
|
|
1151
|
+
type: "uint64",
|
|
1152
|
+
internalType: "uint64"
|
|
1153
|
+
}
|
|
1071
1154
|
]
|
|
1072
1155
|
}
|
|
1073
1156
|
],
|
|
@@ -1141,6 +1224,18 @@ var abi_default = [
|
|
|
1141
1224
|
type: "uint64",
|
|
1142
1225
|
indexed: false,
|
|
1143
1226
|
internalType: "uint64"
|
|
1227
|
+
},
|
|
1228
|
+
{
|
|
1229
|
+
name: "tokenType",
|
|
1230
|
+
type: "uint32",
|
|
1231
|
+
indexed: false,
|
|
1232
|
+
internalType: "uint32"
|
|
1233
|
+
},
|
|
1234
|
+
{
|
|
1235
|
+
name: "nftIds",
|
|
1236
|
+
type: "uint256[]",
|
|
1237
|
+
indexed: false,
|
|
1238
|
+
internalType: "uint256[]"
|
|
1144
1239
|
}
|
|
1145
1240
|
],
|
|
1146
1241
|
anonymous: false
|
|
@@ -1216,6 +1311,18 @@ var abi_default = [
|
|
|
1216
1311
|
type: "uint64",
|
|
1217
1312
|
indexed: false,
|
|
1218
1313
|
internalType: "uint64"
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
name: "tokenType",
|
|
1317
|
+
type: "uint32",
|
|
1318
|
+
indexed: false,
|
|
1319
|
+
internalType: "uint32"
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
name: "nftIds",
|
|
1323
|
+
type: "uint256[]",
|
|
1324
|
+
indexed: false,
|
|
1325
|
+
internalType: "uint256[]"
|
|
1219
1326
|
}
|
|
1220
1327
|
],
|
|
1221
1328
|
anonymous: false
|
|
@@ -1265,6 +1372,18 @@ var abi_default = [
|
|
|
1265
1372
|
type: "uint64",
|
|
1266
1373
|
indexed: false,
|
|
1267
1374
|
internalType: "uint64"
|
|
1375
|
+
},
|
|
1376
|
+
{
|
|
1377
|
+
name: "tokenType",
|
|
1378
|
+
type: "uint32",
|
|
1379
|
+
indexed: false,
|
|
1380
|
+
internalType: "uint32"
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
name: "nftIds",
|
|
1384
|
+
type: "uint256[]",
|
|
1385
|
+
indexed: false,
|
|
1386
|
+
internalType: "uint256[]"
|
|
1268
1387
|
}
|
|
1269
1388
|
],
|
|
1270
1389
|
anonymous: false
|
|
@@ -1473,6 +1592,7 @@ var Erc721Contract = class {
|
|
|
1473
1592
|
var Erc721Contract_default = Erc721Contract;
|
|
1474
1593
|
|
|
1475
1594
|
// src/classes/Fund.ts
|
|
1595
|
+
var defaultDecimals = 18;
|
|
1476
1596
|
var { parseUnits: parseUnits2, formatUnits: formatUnits2 } = import_ethers3.ethers.utils;
|
|
1477
1597
|
var Fund = class {
|
|
1478
1598
|
fundContract;
|
|
@@ -1502,7 +1622,7 @@ var Fund = class {
|
|
|
1502
1622
|
try {
|
|
1503
1623
|
const recipientInfos = [];
|
|
1504
1624
|
recipientInfos[0] = recipientInfo;
|
|
1505
|
-
let decimals =
|
|
1625
|
+
let decimals = defaultDecimals;
|
|
1506
1626
|
let params = [];
|
|
1507
1627
|
if (tokenInfo.tokenType === 0) {
|
|
1508
1628
|
await this.approve(tokenInfo, recipientInfos);
|
|
@@ -1543,7 +1663,7 @@ var Fund = class {
|
|
|
1543
1663
|
try {
|
|
1544
1664
|
const recipientInfos = [];
|
|
1545
1665
|
recipientInfos[0] = recipientInfo;
|
|
1546
|
-
let decimals =
|
|
1666
|
+
let decimals = defaultDecimals;
|
|
1547
1667
|
let params = [];
|
|
1548
1668
|
if (tokenInfo.tokenType === 0) {
|
|
1549
1669
|
const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
|
|
@@ -1604,7 +1724,7 @@ var Fund = class {
|
|
|
1604
1724
|
async fundBatch(tokenInfo, recipientInfoList) {
|
|
1605
1725
|
return new Promise(async (resolve, reject) => {
|
|
1606
1726
|
try {
|
|
1607
|
-
let decimals =
|
|
1727
|
+
let decimals = defaultDecimals;
|
|
1608
1728
|
let params = [];
|
|
1609
1729
|
if (tokenInfo.tokenType === 0) {
|
|
1610
1730
|
await this.approve(tokenInfo, recipientInfoList);
|
|
@@ -1755,6 +1875,51 @@ var Fund = class {
|
|
|
1755
1875
|
}
|
|
1756
1876
|
});
|
|
1757
1877
|
}
|
|
1878
|
+
async _formatTipRecords(fundRecords) {
|
|
1879
|
+
console.log("fundRecords", fundRecords);
|
|
1880
|
+
let formatRecords = [];
|
|
1881
|
+
for (const record of fundRecords) {
|
|
1882
|
+
const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
|
|
1883
|
+
let decimals = defaultDecimals;
|
|
1884
|
+
let symbol = "";
|
|
1885
|
+
let tokenId = null;
|
|
1886
|
+
let nftInfo = null;
|
|
1887
|
+
if (tokenType === 0) {
|
|
1888
|
+
const tokenContract = new Erc20Contract_default(this.provider, tokenAddress);
|
|
1889
|
+
decimals = await tokenContract.decimals();
|
|
1890
|
+
symbol = await tokenContract.symbol();
|
|
1891
|
+
} else if (tokenType === 1) {
|
|
1892
|
+
symbol = NATIVETOKENS[this.chainId];
|
|
1893
|
+
} else if (tokenType === 2) {
|
|
1894
|
+
decimals = 0;
|
|
1895
|
+
tokenId = parseInt(nftIds[0]);
|
|
1896
|
+
const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
|
|
1897
|
+
nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
|
|
1898
|
+
}
|
|
1899
|
+
let fundToken = {
|
|
1900
|
+
tokenType,
|
|
1901
|
+
// tokenAmount: formatUnits(amount, decimals),
|
|
1902
|
+
decimals,
|
|
1903
|
+
symbol,
|
|
1904
|
+
chainName: CHAINNAMES[this.chainId],
|
|
1905
|
+
chainId: this.chainId
|
|
1906
|
+
};
|
|
1907
|
+
if (tokenType === 0) {
|
|
1908
|
+
fundToken.tokenAddress = tokenAddress;
|
|
1909
|
+
}
|
|
1910
|
+
if (tokenType === 2) {
|
|
1911
|
+
Object.assign(fundToken, nftInfo ?? {});
|
|
1912
|
+
}
|
|
1913
|
+
formatRecords.push({
|
|
1914
|
+
funder: tipper,
|
|
1915
|
+
fundToken,
|
|
1916
|
+
amount: formatUnits2(amount, decimals),
|
|
1917
|
+
timestamp: timestamp.toNumber()
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
console.log("formatRecords", formatRecords);
|
|
1921
|
+
return formatRecords;
|
|
1922
|
+
}
|
|
1758
1923
|
async getTipRecords(getFundRecordsParams) {
|
|
1759
1924
|
return new Promise(async (resolve, reject) => {
|
|
1760
1925
|
try {
|
|
@@ -1765,48 +1930,62 @@ var Fund = class {
|
|
|
1765
1930
|
};
|
|
1766
1931
|
});
|
|
1767
1932
|
const fundRecords = await this.fundContract.callMethod("getTipRecords", formatGetFundRecordsParams);
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
} else if (tokenType === 2) {
|
|
1783
|
-
decimals = 0;
|
|
1784
|
-
tokenId = parseInt(nftIds[0]);
|
|
1785
|
-
const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
|
|
1786
|
-
nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
|
|
1787
|
-
}
|
|
1788
|
-
let fundToken = {
|
|
1789
|
-
tokenType,
|
|
1790
|
-
// tokenAmount: formatUnits(amount, decimals),
|
|
1791
|
-
decimals,
|
|
1792
|
-
symbol,
|
|
1793
|
-
chainName: CHAINNAMES[this.chainId],
|
|
1794
|
-
chainId: this.chainId
|
|
1933
|
+
let formatRecords = await this._formatTipRecords(fundRecords);
|
|
1934
|
+
return resolve(formatRecords);
|
|
1935
|
+
} catch (error) {
|
|
1936
|
+
return reject(error);
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
async getTipRecordsNativeAmount(getFundRecordsParams) {
|
|
1941
|
+
return new Promise(async (resolve, reject) => {
|
|
1942
|
+
try {
|
|
1943
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1944
|
+
return {
|
|
1945
|
+
idSource: item.socialPlatform,
|
|
1946
|
+
id: item.userIdentifier
|
|
1795
1947
|
};
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1948
|
+
});
|
|
1949
|
+
const fundNativeTokenAmount = await this.fundContract.callMethod("getTipRecordsNativeAmount", formatGetFundRecordsParams);
|
|
1950
|
+
const amount = formatUnits2(fundNativeTokenAmount, defaultDecimals);
|
|
1951
|
+
console.log("fundNativeTokenAmount", amount);
|
|
1952
|
+
return resolve(amount);
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
return reject(error);
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
async getTipRecordsLength(getFundRecordsParams) {
|
|
1959
|
+
return new Promise(async (resolve, reject) => {
|
|
1960
|
+
try {
|
|
1961
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1962
|
+
return {
|
|
1963
|
+
idSource: item.socialPlatform,
|
|
1964
|
+
id: item.userIdentifier
|
|
1965
|
+
};
|
|
1966
|
+
});
|
|
1967
|
+
const fundRecordsLen = await this.fundContract.callMethod("getTipRecordsLength", formatGetFundRecordsParams);
|
|
1968
|
+
const len = fundRecordsLen.toNumber();
|
|
1969
|
+
console.log("fundRecordsLength", len);
|
|
1970
|
+
return resolve(len);
|
|
1971
|
+
} catch (error) {
|
|
1972
|
+
return reject(error);
|
|
1973
|
+
}
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
async getTipRecordsPaginated(getFundRecordsParams, pageNum, pageSize) {
|
|
1977
|
+
return new Promise(async (resolve, reject) => {
|
|
1978
|
+
try {
|
|
1979
|
+
const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
|
|
1980
|
+
return {
|
|
1981
|
+
idSource: item.socialPlatform,
|
|
1982
|
+
id: item.userIdentifier
|
|
1983
|
+
};
|
|
1984
|
+
});
|
|
1985
|
+
let params = [...formatGetFundRecordsParams, pageNum, pageSize];
|
|
1986
|
+
const fundRecords = await this.fundContract.callMethod("getTipRecordsPaginated", params);
|
|
1987
|
+
let formatRecords = await this._formatTipRecords(fundRecords);
|
|
1988
|
+
console.log("fundRecordsPaginated", formatRecords);
|
|
1810
1989
|
return resolve(formatRecords);
|
|
1811
1990
|
} catch (error) {
|
|
1812
1991
|
return reject(error);
|
|
@@ -2684,6 +2863,7 @@ var ZktlsSdk = class {
|
|
|
2684
2863
|
};
|
|
2685
2864
|
|
|
2686
2865
|
// src/index.ts
|
|
2866
|
+
console.log("SUPPORTEDCHAINIDS", SUPPORTEDCHAINIDS);
|
|
2687
2867
|
var PrimusFund = class {
|
|
2688
2868
|
supportedChainIds = SUPPORTEDCHAINIDS;
|
|
2689
2869
|
supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
|
|
@@ -2904,25 +3084,31 @@ var PrimusFund = class {
|
|
|
2904
3084
|
}
|
|
2905
3085
|
});
|
|
2906
3086
|
}
|
|
3087
|
+
_formatGetFundRecordsParams(queryList) {
|
|
3088
|
+
const socialPlatforms = [];
|
|
3089
|
+
const userIdentifiers = [];
|
|
3090
|
+
for (let i = 0; i < queryList.length; i++) {
|
|
3091
|
+
socialPlatforms[i] = queryList[i].socialPlatform.toLowerCase();
|
|
3092
|
+
userIdentifiers[i] = queryList[i].userIdentifier;
|
|
3093
|
+
if (socialPlatforms[i] === "x" && userIdentifiers[i].startsWith("@")) {
|
|
3094
|
+
queryList[i].userIdentifier = queryList[i].userIdentifier.slice(1);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
return queryList;
|
|
3098
|
+
}
|
|
2907
3099
|
async getFundRecords(getFundRecordsParams) {
|
|
2908
|
-
|
|
3100
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3101
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3102
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
2909
3103
|
return new Promise(async (resolve, reject) => {
|
|
2910
3104
|
if (!queryList || queryList?.length === 0) {
|
|
2911
3105
|
const error = new Error("getFundRecordsParams is empty");
|
|
2912
3106
|
return reject(error);
|
|
2913
3107
|
}
|
|
2914
|
-
|
|
2915
|
-
const userIdentifiers = [];
|
|
2916
|
-
for (let i = 0; i < queryList.length; i++) {
|
|
2917
|
-
socialPlatforms[i] = queryList[i].socialPlatform.toLowerCase();
|
|
2918
|
-
userIdentifiers[i] = queryList[i].userIdentifier;
|
|
2919
|
-
if (socialPlatforms[i] === "x" && userIdentifiers[i].startsWith("@")) {
|
|
2920
|
-
queryList[i].userIdentifier = queryList[i].userIdentifier.slice(1);
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
if (socialPlatforms.length !== userIdentifiers.length) {
|
|
3108
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
2924
3109
|
return reject(`getFundRecordsParams is wrong`);
|
|
2925
3110
|
}
|
|
3111
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
2926
3112
|
try {
|
|
2927
3113
|
const result = await this._fund?.getTipRecords(queryList);
|
|
2928
3114
|
resolve(result);
|
|
@@ -2931,6 +3117,69 @@ var PrimusFund = class {
|
|
|
2931
3117
|
}
|
|
2932
3118
|
});
|
|
2933
3119
|
}
|
|
3120
|
+
async getFundRecordsNativeAmount(getFundRecordsParams) {
|
|
3121
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3122
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3123
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3124
|
+
return new Promise(async (resolve, reject) => {
|
|
3125
|
+
if (!queryList || queryList?.length === 0) {
|
|
3126
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3127
|
+
return reject(error);
|
|
3128
|
+
}
|
|
3129
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3130
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3131
|
+
}
|
|
3132
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3133
|
+
try {
|
|
3134
|
+
const result = await this._fund?.getTipRecordsNativeAmount(queryList);
|
|
3135
|
+
resolve(result);
|
|
3136
|
+
} catch (error) {
|
|
3137
|
+
return reject(error);
|
|
3138
|
+
}
|
|
3139
|
+
});
|
|
3140
|
+
}
|
|
3141
|
+
async getFundRecordsLen(getFundRecordsParams) {
|
|
3142
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3143
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3144
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3145
|
+
return new Promise(async (resolve, reject) => {
|
|
3146
|
+
if (!queryList || queryList?.length === 0) {
|
|
3147
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3148
|
+
return reject(error);
|
|
3149
|
+
}
|
|
3150
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3151
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3152
|
+
}
|
|
3153
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3154
|
+
try {
|
|
3155
|
+
const result = await this._fund?.getTipRecordsLength(queryList);
|
|
3156
|
+
resolve(result);
|
|
3157
|
+
} catch (error) {
|
|
3158
|
+
return reject(error);
|
|
3159
|
+
}
|
|
3160
|
+
});
|
|
3161
|
+
}
|
|
3162
|
+
async getFundRecordsPaginated(getFundRecordsParams, pageNum, pageSize) {
|
|
3163
|
+
let queryList = Array.isArray(getFundRecordsParams) ? getFundRecordsParams : [getFundRecordsParams];
|
|
3164
|
+
const socialPlatformList = queryList.map((i) => i.socialPlatform);
|
|
3165
|
+
const userIdentifierList = queryList.map((i) => i.userIdentifier);
|
|
3166
|
+
return new Promise(async (resolve, reject) => {
|
|
3167
|
+
if (!queryList || queryList?.length === 0) {
|
|
3168
|
+
const error = new Error("getFundRecordsParams is empty");
|
|
3169
|
+
return reject(error);
|
|
3170
|
+
}
|
|
3171
|
+
if (socialPlatformList.length !== userIdentifierList.length) {
|
|
3172
|
+
return reject(`getFundRecordsParams is wrong`);
|
|
3173
|
+
}
|
|
3174
|
+
queryList = this._formatGetFundRecordsParams(queryList);
|
|
3175
|
+
try {
|
|
3176
|
+
const result = await this._fund?.getTipRecordsPaginated(queryList, pageNum, pageSize);
|
|
3177
|
+
resolve(result);
|
|
3178
|
+
} catch (error) {
|
|
3179
|
+
return reject(error);
|
|
3180
|
+
}
|
|
3181
|
+
});
|
|
3182
|
+
}
|
|
2934
3183
|
async fundForRedPacket(fundParam) {
|
|
2935
3184
|
return new Promise(async (resolve, reject) => {
|
|
2936
3185
|
try {
|