@funkit/api-base 1.5.0 → 1.5.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @funkit/api-base
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1e4114a: refactor: deprecate getOpsOfGroup
8
+ - 1e4114a: refactor: migrate OperationApis
9
+ - 68a03ee: refactor: migrate UserApis
10
+ - 4ebe545: refactor: migrate InfoApis
11
+ - 4ebe545: refactor: reorganize getTokenInfo -> getTokenAddressBySymbolAndChainId
12
+ - Updated dependencies [125fd75]
13
+ - Updated dependencies [8032902]
14
+ - @funkit/utils@1.0.4
15
+
3
16
  ## 1.5.0
4
17
 
5
18
  ### Minor Changes
package/dist/index.js CHANGED
@@ -31,6 +31,12 @@ var DEFAULT_RETRY_OPTIONS = {
31
31
  calculateDelay: null
32
32
  };
33
33
 
34
+ // src/consts/customers.ts
35
+ var DEGEN_API_KEY = "m4iHIILHcL4gN8EXCMzGe8zIdhuCXxck49mWajzJ";
36
+ var DYDX_API_KEY = "NJq0CGrsE19xBbP1vHyBOp8xJvzYo9kayJHqDFP5";
37
+ var POLYMARKET_API_KEY = "Y53dikxXdT4E3afI1l8BMBSWgyhKvf65k6Dut1k6";
38
+ var DEV_API_KEY = "Z9SZaOwpmE40KX61mUKWm5hrpGh7WHVkaTvQJpQk";
39
+
34
40
  // src/utils/checkout.ts
35
41
  import { toHex } from "viem";
36
42
  function randomBytes(length) {
@@ -66,14 +72,14 @@ var stringifyWithBigIntSanitization = (object) => {
66
72
  // return everything else unchanged
67
73
  );
68
74
  };
69
- var sendRequest = async ({
75
+ async function sendRequest({
70
76
  uri,
71
77
  method,
72
78
  apiKey,
73
79
  body = {},
74
80
  retryOptions = {},
75
81
  signal
76
- }) => {
82
+ }) {
77
83
  try {
78
84
  const headers = {
79
85
  "Content-Type": "application/json",
@@ -140,7 +146,8 @@ var sendRequest = async ({
140
146
  if (errorCode === ErrorCode.UserOpFailureError) {
141
147
  throw new UserOpFailureError2(
142
148
  ErrorCode.UserOpFailureError,
143
- `server failure ${JSON.stringify(json)}`,
149
+ JSON.stringify(json),
150
+ // UserOpFailureError may JSON.parse this! Do not modify!
144
151
  errorMsg,
145
152
  { body },
146
153
  "fix user op failure. Most of the time this is due to invalid parameters",
@@ -188,7 +195,7 @@ var sendRequest = async ({
188
195
  "https://docs.fun.xyz"
189
196
  );
190
197
  }
191
- };
198
+ }
192
199
  async function sendGetRequest({
193
200
  uri,
194
201
  apiKey,
@@ -263,6 +270,17 @@ async function getAssetPriceInfo({
263
270
  });
264
271
  return priceInfo;
265
272
  }
273
+ async function getAssetErc20ByChainAndSymbol({
274
+ chainId,
275
+ symbol,
276
+ apiKey
277
+ }) {
278
+ return await sendGetRequest({
279
+ uri: `${API_BASE_URL}/asset/erc20/${chainId}/${symbol}`,
280
+ apiKey,
281
+ retryOptions: { maxAttempts: 2 }
282
+ });
283
+ }
266
284
  async function getAllWalletTokens({
267
285
  walletAddress,
268
286
  onlyVerifiedTokens,
@@ -433,7 +451,7 @@ async function getCheckoutQuote({
433
451
  };
434
452
  } catch (err) {
435
453
  throw new Error(
436
- `An error occured trying to generate a checkout quote: ${err.message}`
454
+ `An error occured trying to generate a checkout quote: ${err instanceof Error ? err.message : JSON.stringify(err)}`
437
455
  );
438
456
  }
439
457
  }
@@ -639,6 +657,198 @@ async function getGroups({
639
657
  })).groups;
640
658
  }
641
659
 
660
+ // src/services/fw-info/endpoints.ts
661
+ async function getChainFromId({
662
+ chainId,
663
+ apiKey
664
+ }) {
665
+ const res = await sendGetRequest({
666
+ uri: `${API_BASE_URL}/chain-info/${chainId}`,
667
+ apiKey
668
+ });
669
+ if (!res) {
670
+ throw new Error(JSON.stringify(res));
671
+ }
672
+ return res;
673
+ }
674
+ async function getChainFromName({
675
+ name,
676
+ apiKey
677
+ }) {
678
+ const res = await sendGetRequest({
679
+ uri: `${API_BASE_URL}/chain-info?name=${name}`,
680
+ apiKey
681
+ });
682
+ if (!res) {
683
+ throw new Error(JSON.stringify(res));
684
+ }
685
+ return res;
686
+ }
687
+
688
+ // src/services/fw-operation/endpoints.ts
689
+ async function createOp({
690
+ op,
691
+ apiKey
692
+ }) {
693
+ return (await sendPostRequest({
694
+ uri: `${API_BASE_URL}/operation`,
695
+ body: { ...op },
696
+ apiKey
697
+ })).opId;
698
+ }
699
+ async function getOpsOfWallet({
700
+ walletAddr,
701
+ chainId,
702
+ apiKey,
703
+ status
704
+ }) {
705
+ const endpoint = status ? `${API_BASE_URL}/operation/wallet/${walletAddr}/chain/${chainId}?status=${status}` : `${API_BASE_URL}/operation/wallet/${walletAddr}/chain/${chainId}`;
706
+ return (await sendGetRequest({ uri: endpoint, apiKey })).operations;
707
+ }
708
+ async function getOps({
709
+ opIds,
710
+ chainId,
711
+ apiKey
712
+ }) {
713
+ return (await sendPostRequest({
714
+ uri: `${API_BASE_URL}/operation/get-operations`,
715
+ body: {
716
+ opIds,
717
+ chainId
718
+ },
719
+ apiKey
720
+ })).operations;
721
+ }
722
+ async function deleteOp({
723
+ opId,
724
+ chainId,
725
+ apiKey
726
+ }) {
727
+ await sendDeleteRequest({
728
+ uri: `${API_BASE_URL}/operation/${opId}/chain/${chainId}`,
729
+ apiKey
730
+ });
731
+ }
732
+ async function signOp({
733
+ opId,
734
+ chainId,
735
+ signature,
736
+ signedBy,
737
+ apiKey,
738
+ threshold
739
+ }) {
740
+ await sendPostRequest({
741
+ uri: `${API_BASE_URL}/operation/sign`,
742
+ body: {
743
+ opId,
744
+ chainId,
745
+ signature,
746
+ signedBy,
747
+ threshold
748
+ },
749
+ apiKey
750
+ });
751
+ }
752
+ async function executeOp({
753
+ input,
754
+ apiKey
755
+ }) {
756
+ return await sendPostRequest({
757
+ uri: `${API_BASE_URL}/operation/execute`,
758
+ body: input,
759
+ apiKey
760
+ });
761
+ }
762
+ async function estimateOp({
763
+ apiKey,
764
+ input
765
+ }) {
766
+ return await sendPostRequest({
767
+ uri: `${API_BASE_URL}/operation/estimate`,
768
+ body: input,
769
+ apiKey
770
+ });
771
+ }
772
+ async function scheduleOp({
773
+ input,
774
+ apiKey
775
+ }) {
776
+ await sendPostRequest({
777
+ uri: `${API_BASE_URL}/operation/schedule`,
778
+ body: input,
779
+ apiKey
780
+ });
781
+ }
782
+ var getFullReceipt = async ({
783
+ opId,
784
+ chainId,
785
+ userOpHash,
786
+ apiKey
787
+ }) => {
788
+ const retries = 20;
789
+ let result = {
790
+ status: "pending"
791
+ };
792
+ for (let i = 0; i < retries; i++) {
793
+ try {
794
+ result = await sendGetRequest({
795
+ uri: `${API_BASE_URL}/operation/${opId}/chain/${chainId}/receipt?userOpHash=${userOpHash}`,
796
+ apiKey
797
+ });
798
+ if (result.status === "included") {
799
+ break;
800
+ }
801
+ } catch (_err) {
802
+ }
803
+ await new Promise((resolve) => setTimeout(resolve, 2500));
804
+ }
805
+ if (!result.receipt) {
806
+ result.receipt = {
807
+ // TODO: this is obviously wrong but it was what we had before
808
+ txId: "Failed to find.",
809
+ gasUsed: "Failed to find.",
810
+ opFeeUSD: "Failed to find.",
811
+ opFee: "Failed to find.",
812
+ userOpHash: "Failed to find."
813
+ };
814
+ }
815
+ return {
816
+ ...result.receipt
817
+ };
818
+ };
819
+ var getUserOpGasPrice = async ({
820
+ chainId,
821
+ apiKey
822
+ }) => {
823
+ return await sendGetRequest({
824
+ uri: `${API_BASE_URL}/operation/chain/${chainId}/gas-price`,
825
+ apiKey
826
+ });
827
+ };
828
+
829
+ // src/services/fw-operation/types.ts
830
+ var OperationStatus = /* @__PURE__ */ ((OperationStatus2) => {
831
+ OperationStatus2["ALL"] = "";
832
+ OperationStatus2["PENDING_APPROVED"] = "PENDING_APPROVED";
833
+ OperationStatus2["APPROVED"] = "APPROVED";
834
+ OperationStatus2["PENDING"] = "PENDING";
835
+ OperationStatus2["OP_SUCCEED"] = "OP_SUCCEED";
836
+ OperationStatus2["OP_REVERTED"] = "OP_REVERTED";
837
+ OperationStatus2["SCHEDULED"] = "SCHEDULED";
838
+ return OperationStatus2;
839
+ })(OperationStatus || {});
840
+ var AuthType = /* @__PURE__ */ ((AuthType2) => {
841
+ AuthType2[AuthType2["ECDSA"] = 0] = "ECDSA";
842
+ AuthType2[AuthType2["MULTI_SIG"] = 1] = "MULTI_SIG";
843
+ return AuthType2;
844
+ })(AuthType || {});
845
+ var OperationType = /* @__PURE__ */ ((OperationType2) => {
846
+ OperationType2["SINGLE_OPERATION"] = "SINGLE_OPERATION";
847
+ OperationType2["GROUP_OPERATION"] = "GROUP_OPERATION";
848
+ OperationType2["REJECTION"] = "REJECTION";
849
+ return OperationType2;
850
+ })(OperationType || {});
851
+
642
852
  // src/services/fw-paymaster/endpoints.ts
643
853
  async function addTransaction({
644
854
  chainId,
@@ -675,38 +885,112 @@ var PaymasterType = /* @__PURE__ */ ((PaymasterType2) => {
675
885
  return PaymasterType2;
676
886
  })(PaymasterType || {});
677
887
 
888
+ // src/services/fw-user/endpoints.ts
889
+ import { ResourceNotFoundError as ResourceNotFoundError4 } from "@funkit/utils";
890
+ import { InvalidParameterError as InvalidParameterError3 } from "viem";
891
+ async function createUser({
892
+ authId,
893
+ addr,
894
+ method,
895
+ userUniqueId,
896
+ apiKey
897
+ }) {
898
+ await sendPostRequest({
899
+ uri: `${API_BASE_URL}/user`,
900
+ body: {
901
+ authId,
902
+ addr,
903
+ method,
904
+ userUniqueId
905
+ },
906
+ apiKey
907
+ });
908
+ }
909
+ async function getUserUniqueId({
910
+ authId,
911
+ apiKey
912
+ }) {
913
+ try {
914
+ return (await sendGetRequest({
915
+ uri: `${API_BASE_URL}/user/auth/${authId}/unique-id`,
916
+ apiKey
917
+ })).userUniqueId;
918
+ } catch (err) {
919
+ if (err instanceof ResourceNotFoundError4) {
920
+ return "";
921
+ }
922
+ throw err;
923
+ }
924
+ }
925
+ async function getUserWalletsByAddr({
926
+ addr,
927
+ apiKey,
928
+ chainId
929
+ }) {
930
+ const endpoint = chainId ? `${API_BASE_URL}/user/addr/${addr}/wallets?chainId=${chainId}` : `${API_BASE_URL}/user/addr/${addr}/wallets`;
931
+ return (await sendGetRequest({ uri: endpoint, apiKey })).wallets;
932
+ }
933
+ async function addUserToWallet({
934
+ authId,
935
+ chainId,
936
+ walletAddr,
937
+ userIds,
938
+ apiKey,
939
+ walletUniqueId
940
+ }) {
941
+ try {
942
+ await sendPostRequest({
943
+ uri: `${API_BASE_URL}/user/auth/${authId}/chain/${chainId}/wallet`,
944
+ body: { walletAddr, userIds, walletUniqueId },
945
+ apiKey
946
+ });
947
+ } catch (err) {
948
+ if (err instanceof InvalidParameterError3) {
949
+ return;
950
+ }
951
+ }
952
+ }
953
+ async function getUserWalletIdentities({
954
+ authId,
955
+ chainId,
956
+ walletAddr,
957
+ apiKey
958
+ }) {
959
+ return (await sendGetRequest({
960
+ uri: `${API_BASE_URL}/user/auth/${authId}/chain/${chainId}/wallet/${walletAddr}/identities`,
961
+ apiKey
962
+ })).ids ?? [];
963
+ }
964
+
678
965
  // src/services/mesh/endpoints.ts
679
966
  async function meshGetCryptocurrencyHoldings({
680
967
  authToken,
681
968
  type,
682
969
  apiKey
683
970
  }) {
684
- const res = await sendPostRequest({
971
+ return sendPostRequest({
685
972
  uri: `${API_BASE_URL}/mesh/holdings/get`,
686
973
  body: { authToken, type },
687
974
  apiKey
688
975
  });
689
- return res;
690
976
  }
691
977
  async function meshGetCryptocurrencyHoldingsProxy({
692
978
  apiKey,
693
979
  ...props
694
980
  }) {
695
- const res = await sendPostRequest({
981
+ return sendPostRequest({
696
982
  uri: `${MESH_API_BASE_URL}/mesh/holdings/get`,
697
983
  body: { ...props },
698
984
  apiKey
699
985
  });
700
- return res;
701
986
  }
702
987
  async function meshGetTransferIntegrations({
703
988
  apiKey
704
989
  }) {
705
- const res = await sendGetRequest({
990
+ return sendGetRequest({
706
991
  uri: `${API_BASE_URL}/mesh/transfers/managed/integrations`,
707
992
  apiKey
708
993
  });
709
- return res;
710
994
  }
711
995
  async function meshGetLinkToken({
712
996
  userId,
@@ -721,12 +1005,11 @@ async function meshGetLinkToken({
721
1005
  ...restrictMultipleAccounts && { restrictMultipleAccounts },
722
1006
  ...transferOptions && { transferOptions }
723
1007
  };
724
- const res = await sendPostRequest({
1008
+ return sendPostRequest({
725
1009
  uri: `${API_BASE_URL}/mesh/linktoken`,
726
1010
  body,
727
1011
  apiKey
728
1012
  });
729
- return res;
730
1013
  }
731
1014
  async function meshPreviewTransfer({
732
1015
  fromAuthToken,
@@ -753,26 +1036,24 @@ async function meshPreviewTransfer({
753
1036
  ...amountInFiat && { amountInFiat },
754
1037
  ...fiatCurrency && { fiatCurrency }
755
1038
  };
756
- const res = await sendPostRequest({
1039
+ return sendPostRequest({
757
1040
  uri: `${API_BASE_URL}/mesh/transfers/managed/preview`,
758
1041
  body,
759
1042
  apiKey,
760
1043
  retryOptions: { maxAttempts: 1 }
761
1044
  });
762
- return res;
763
1045
  }
764
1046
  async function meshPreviewTransferProxy({
765
1047
  apiKey,
766
1048
  ...props
767
1049
  }) {
768
1050
  const body = { ...props };
769
- const res = await sendPostRequest({
1051
+ return sendPostRequest({
770
1052
  uri: `${MESH_API_BASE_URL}/mesh/transfers/managed/preview`,
771
1053
  body,
772
1054
  apiKey,
773
1055
  retryOptions: { maxAttempts: 1 }
774
1056
  });
775
- return res;
776
1057
  }
777
1058
  async function meshExecuteTransfer({
778
1059
  fromAuthToken,
@@ -787,36 +1068,33 @@ async function meshExecuteTransfer({
787
1068
  previewId,
788
1069
  ...mfaCode && { mfaCode }
789
1070
  };
790
- const res = await sendPostRequest({
1071
+ return sendPostRequest({
791
1072
  uri: `${API_BASE_URL}/mesh/transfers/managed/execute`,
792
1073
  body,
793
1074
  apiKey
794
1075
  });
795
- return res;
796
1076
  }
797
1077
  async function meshExecuteTransferProxy({
798
1078
  apiKey,
799
1079
  ...props
800
1080
  }) {
801
1081
  const body = { ...props };
802
- const res = await sendPostRequest({
1082
+ return sendPostRequest({
803
1083
  uri: `${MESH_API_BASE_URL}/mesh/transfers/managed/execute`,
804
1084
  body,
805
1085
  apiKey
806
1086
  });
807
- return res;
808
1087
  }
809
1088
  async function saveTokensToMeshProxy({
810
1089
  apiKey,
811
1090
  ...props
812
1091
  }) {
813
1092
  const body = { ...props };
814
- const res = await sendPostRequest({
1093
+ return sendPostRequest({
815
1094
  uri: `${MESH_API_BASE_URL}/api/tokens`,
816
1095
  body,
817
1096
  apiKey
818
1097
  });
819
- return res;
820
1098
  }
821
1099
  async function removeTokensFromMeshProxy({
822
1100
  apiKey,
@@ -892,12 +1170,11 @@ async function getMoonpayBuyQuoteForCreditCard({
892
1170
  ...extraFeePercentage == null ? {} : { extraFeePercentage: extraFeePercentage.toString() },
893
1171
  ...areFeesIncluded == null ? {} : { areFeesIncluded: areFeesIncluded.toString() }
894
1172
  }).toString();
895
- const res = await sendGetRequest({
1173
+ return sendGetRequest({
896
1174
  uri: `${API_BASE_URL}/on-ramp/moonpay-buy-quote?${params}`,
897
1175
  apiKey,
898
1176
  retryOptions: { maxAttempts: 1 }
899
1177
  });
900
- return res;
901
1178
  }
902
1179
 
903
1180
  // src/services/stripe/endpoints.ts
@@ -992,40 +1269,63 @@ async function sendSupportMessage({
992
1269
  }
993
1270
  export {
994
1271
  API_BASE_URL,
1272
+ AuthType,
995
1273
  CheckoutState,
996
1274
  DEFAULT_RETRY_OPTIONS,
1275
+ DEGEN_API_KEY,
1276
+ DEV_API_KEY,
1277
+ DYDX_API_KEY,
997
1278
  FUN_FAUCET_URL,
998
1279
  MESH_API_BASE_URL,
999
1280
  MeshExecuteTransferMfaType,
1000
1281
  MeshExecuteTransferStatus,
1282
+ OperationStatus,
1283
+ OperationType,
1284
+ POLYMARKET_API_KEY,
1001
1285
  PaymasterType,
1002
1286
  addTransaction,
1287
+ addUserToWallet,
1003
1288
  checkWalletAccessInitialization,
1289
+ createOp,
1004
1290
  createStripeBuySession,
1291
+ createUser,
1005
1292
  deactivateCheckout,
1293
+ deleteOp,
1006
1294
  errorAbortHandler,
1295
+ estimateOp,
1296
+ executeOp,
1007
1297
  generateRandomCheckoutSalt,
1008
1298
  getAllWalletNFTs,
1009
1299
  getAllWalletNFTsByChainId,
1010
1300
  getAllWalletTokens,
1011
1301
  getAllWalletTokensByChainId,
1012
1302
  getAllowedAssets,
1303
+ getAssetErc20ByChainAndSymbol,
1013
1304
  getAssetFromFaucet,
1014
1305
  getAssetPriceInfo,
1306
+ getChainFromId,
1307
+ getChainFromName,
1015
1308
  getCheckoutByDepositAddress,
1016
1309
  getCheckoutQuote,
1017
1310
  getCheckoutsByFunWalletAddress,
1018
1311
  getCheckoutsByRecipientAddress,
1019
1312
  getCheckoutsByUserId,
1313
+ getFullReceipt,
1020
1314
  getGroups,
1021
1315
  getMoonpayBuyQuoteForCreditCard,
1022
1316
  getMoonpayUrlSignature,
1023
1317
  getNftAddress,
1024
1318
  getNftName,
1319
+ getOps,
1320
+ getOpsOfWallet,
1025
1321
  getPaymasterDataForCheckoutSponsoredTransfer,
1026
1322
  getRiskAssessmentForAddress,
1027
1323
  getStripeBuyQuote,
1028
1324
  getStripeBuySession,
1325
+ getUserOpGasPrice,
1326
+ getUserUniqueId,
1327
+ getUserWalletIdentities,
1328
+ getUserWalletsByAddr,
1029
1329
  getWalletLidoWithdrawalsByChainId,
1030
1330
  initializeCheckout,
1031
1331
  initializeCheckoutTokenTransferAddress,
@@ -1042,11 +1342,13 @@ export {
1042
1342
  removeTokensFromMeshProxy,
1043
1343
  roundToNearestBottomTenth,
1044
1344
  saveTokensToMeshProxy,
1345
+ scheduleOp,
1045
1346
  sendDeleteRequest,
1046
1347
  sendGetRequest,
1047
1348
  sendPostRequest,
1048
1349
  sendPutRequest,
1049
1350
  sendRequest,
1050
- sendSupportMessage
1351
+ sendSupportMessage,
1352
+ signOp
1051
1353
  };
1052
1354
  //# sourceMappingURL=index.js.map