@funkit/api-base 1.0.2-next.0 → 1.0.2-next.2

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.js +1763 -20
  3. package/dist/index.js.map +7 -1
  4. package/package.json +7 -4
  5. package/dist/src/consts/api.js +0 -13
  6. package/dist/src/consts/api.js.map +0 -1
  7. package/dist/src/consts/index.js +0 -20
  8. package/dist/src/consts/index.js.map +0 -1
  9. package/dist/src/consts/request.js +0 -3
  10. package/dist/src/consts/request.js.map +0 -1
  11. package/dist/src/consts/retry.js +0 -19
  12. package/dist/src/consts/retry.js.map +0 -1
  13. package/dist/src/errors/BaseError.js +0 -24
  14. package/dist/src/errors/BaseError.js.map +0 -1
  15. package/dist/src/errors/ClientError.js +0 -76
  16. package/dist/src/errors/ClientError.js.map +0 -1
  17. package/dist/src/errors/ServerError.js +0 -18
  18. package/dist/src/errors/ServerError.js.map +0 -1
  19. package/dist/src/errors/errors.json +0 -626
  20. package/dist/src/errors/index.js +0 -21
  21. package/dist/src/errors/index.js.map +0 -1
  22. package/dist/src/errors/types.js +0 -51
  23. package/dist/src/errors/types.js.map +0 -1
  24. package/dist/src/services/assets/endpoints.js +0 -94
  25. package/dist/src/services/assets/endpoints.js.map +0 -1
  26. package/dist/src/services/assets/index.js +0 -19
  27. package/dist/src/services/assets/index.js.map +0 -1
  28. package/dist/src/services/assets/types.js +0 -3
  29. package/dist/src/services/assets/types.js.map +0 -1
  30. package/dist/src/services/checkout/endpoints.js +0 -202
  31. package/dist/src/services/checkout/endpoints.js.map +0 -1
  32. package/dist/src/services/checkout/index.js +0 -19
  33. package/dist/src/services/checkout/index.js.map +0 -1
  34. package/dist/src/services/checkout/types.js +0 -22
  35. package/dist/src/services/checkout/types.js.map +0 -1
  36. package/dist/src/services/faucet/endpoints.js +0 -12
  37. package/dist/src/services/faucet/endpoints.js.map +0 -1
  38. package/dist/src/services/faucet/index.js +0 -19
  39. package/dist/src/services/faucet/index.js.map +0 -1
  40. package/dist/src/services/faucet/types.js +0 -3
  41. package/dist/src/services/faucet/types.js.map +0 -1
  42. package/dist/src/services/index.js +0 -25
  43. package/dist/src/services/index.js.map +0 -1
  44. package/dist/src/services/mesh/endpoints.js +0 -128
  45. package/dist/src/services/mesh/endpoints.js.map +0 -1
  46. package/dist/src/services/mesh/index.js +0 -19
  47. package/dist/src/services/mesh/index.js.map +0 -1
  48. package/dist/src/services/mesh/types.js +0 -23
  49. package/dist/src/services/mesh/types.js.map +0 -1
  50. package/dist/src/services/moonpay/endpoints.js +0 -82
  51. package/dist/src/services/moonpay/endpoints.js.map +0 -1
  52. package/dist/src/services/moonpay/index.js +0 -19
  53. package/dist/src/services/moonpay/index.js.map +0 -1
  54. package/dist/src/services/moonpay/types.js +0 -3
  55. package/dist/src/services/moonpay/types.js.map +0 -1
  56. package/dist/src/services/stripe/endpoints.js +0 -58
  57. package/dist/src/services/stripe/endpoints.js.map +0 -1
  58. package/dist/src/services/stripe/index.js +0 -19
  59. package/dist/src/services/stripe/index.js.map +0 -1
  60. package/dist/src/services/stripe/types.js +0 -3
  61. package/dist/src/services/stripe/types.js.map +0 -1
  62. package/dist/src/services/support/endpoints.js +0 -20
  63. package/dist/src/services/support/endpoints.js.map +0 -1
  64. package/dist/src/services/support/index.js +0 -19
  65. package/dist/src/services/support/index.js.map +0 -1
  66. package/dist/src/services/support/types.js +0 -3
  67. package/dist/src/services/support/types.js.map +0 -1
  68. package/dist/src/services/turnkey/endpoints.js +0 -26
  69. package/dist/src/services/turnkey/endpoints.js.map +0 -1
  70. package/dist/src/services/turnkey/index.js +0 -19
  71. package/dist/src/services/turnkey/index.js.map +0 -1
  72. package/dist/src/services/turnkey/types.js +0 -3
  73. package/dist/src/services/turnkey/types.js.map +0 -1
  74. package/dist/src/utils/checkout.js +0 -20
  75. package/dist/src/utils/checkout.js.map +0 -1
  76. package/dist/src/utils/error.js +0 -13
  77. package/dist/src/utils/error.js.map +0 -1
  78. package/dist/src/utils/index.js +0 -20
  79. package/dist/src/utils/index.js.map +0 -1
  80. package/dist/src/utils/request.js +0 -104
  81. package/dist/src/utils/request.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,21 +1,1764 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ // src/consts/api.ts
2
+ var API_BASE_URL = false ? "https://api.fun.xyz/staging/v1" : false ? "https://api.fun.xyz/testing/v1" : false ? "http://127.0.0.1:3000" : (
3
+ // Production
4
+ "https://api.fun.xyz/v1"
5
+ );
6
+ var FUN_FAUCET_URL = "https://api.fun.xyz/demo-faucet";
7
+
8
+ // src/errors/BaseError.ts
9
+ var discord = "https://discord.gg/mvQunrx6NG";
10
+ var BaseError = class extends Error {
11
+ constructor(baseType, type, code, msg, paramsUsed, fixSuggestion, docLink, isInternal = false) {
12
+ super(`${msg}
13
+
14
+ ${fixSuggestion}
15
+ Docs: ${docLink}
16
+ Discord: ${discord}`);
17
+ this.baseType = baseType;
18
+ this.type = type;
19
+ this.code = code;
20
+ this.paramsUsed = paramsUsed;
21
+ if (isInternal) {
22
+ this.loadEnd();
7
23
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/consts"), exports);
18
- __exportStar(require("./src/errors"), exports);
19
- __exportStar(require("./src/services"), exports);
20
- __exportStar(require("./src/utils"), exports);
21
- //# sourceMappingURL=index.js.map
24
+ this.message += "\n\nTrace:";
25
+ this.timestamp = (/* @__PURE__ */ new Date()).toUTCString();
26
+ }
27
+ loadEnd() {
28
+ this.message += "\n\nThis is an internal sdk error. Please contact the fun team at our Discord for the fastest response.";
29
+ }
30
+ };
31
+
32
+ // src/errors/errors.json
33
+ var errors_default = {
34
+ AA21: {
35
+ info: " Your wallet lacks funds for this transaction.",
36
+ suggestion: "To fix this error, make sure you have enough funds in your wallet to cover the transaction fee."
37
+ },
38
+ FW000: {
39
+ info: " Create3Deployer.requireDeployerOnly() - Signatures were not sorted before being passed in",
40
+ suggestion: "To fix this error, make sure to short sigs before passing them into `requireDeployerOnly`. You can do this by calling `sigs.sort()` before passing them in. It is also possible to run into this error if the hash that was signed was not the correct hash."
41
+ },
42
+ FW001: {
43
+ info: " Create3Deployer.requireDeployerOnly() - Signature failed to be recovered. ercrecover returned the zero address",
44
+ suggestion: "To fix this error, make sure to pass in enough valid signatures that sign the `hash` in the `sigs` array"
45
+ },
46
+ FW002: {
47
+ info: " Create3Deployer.addDeployer() - Invalid Hash",
48
+ suggestion: "To fix this error, make sure `hash` is equal to `hashAddDeployer()`"
49
+ },
50
+ FW003: {
51
+ info: " Create3Deployer.removeDeployer() - Invalid Hash",
52
+ suggestion: "To fix this error, make sure `hash` is equal to `hashRemoveDeployer()`"
53
+ },
54
+ FW004: {
55
+ info: " Create3Deployer.setThreshold() - Threshold must be greater than 1",
56
+ suggestion: "To fix this error, `threshold` is greater than 1"
57
+ },
58
+ FW005: {
59
+ info: " Create3Deployer.setThreshold() - Invalid Hash",
60
+ suggestion: "To fix this error, make sure `hash` is equal to `keccak256(abi.encodePacked(_threshold))`"
61
+ },
62
+ FW006: {
63
+ info: " Create3Deployer.callChild() - Invalid Hash",
64
+ suggestion: "To fix this error, make sure `hash` is equal to `keccak256(abi.encodePacked(child, data, _nonce, block.chainid))`"
65
+ },
66
+ FW007: {
67
+ info: " Create3Deployer.callChild() - Invalid Nonce, nonce must be 1 greater than the current nonce",
68
+ suggestion: "To fix this error, make sure `_nonce` is equal to the current nonce + 1"
69
+ },
70
+ FW008: {
71
+ info: " Create3Deployer.callChild() - call to child failed",
72
+ suggestion: "To fix this error, check to see what is making the call to the child fail"
73
+ },
74
+ FW009: {
75
+ info: " Create3Deployer.deploy() - Invalid Hash",
76
+ suggestion: "To fix this error, make sure `hash` is equal to `keccak256(abi.encodePacked(_salt, _creationCode))`"
77
+ },
78
+ FW010: {
79
+ info: " FunWalletFactory.constructor() - Invalid Address, cannot be the zero address",
80
+ suggestion: "To fix this error, make sure `_deployer` is not equal to the zero address"
81
+ },
82
+ FW011: {
83
+ info: " FunWalletFactory.constructor() - Invalid Address, cannot be the zero address",
84
+ suggestion: "To fix this error, make sure `_funWalletImpAddress` is not equal to the zero address"
85
+ },
86
+ FW012: {
87
+ info: " FunWalletFactory.constructor() - Invalid Address, cannot be the zero address",
88
+ suggestion: "To fix this error, make sure `_feeOracle` is not equal to the zero address"
89
+ },
90
+ FW013: {
91
+ info: " FunWalletFactory.constructor() - Invalid Address, cannot be the zero address",
92
+ suggestion: "To fix this error, make sure `_walletInit` is not equal to the zero address"
93
+ },
94
+ FW014: {
95
+ info: " FunWalletFactory.constructor() - Unable to generate the address from this deployerSalt",
96
+ suggestion: "To fix this error, make sure `FunWalletFactoryV1` has not already been deployed from the given create3deployer contract. If it has been, change `FunWalletFactoryV1` to `FunWalletFactoryV2` or another version."
97
+ },
98
+ FW015: {
99
+ info: " FunWalletFactory.constructor() - Generated the wrong address from this deployerSalt",
100
+ suggestion: "To fix this error, make sure `FunWalletFactoryV1` has not already been deployed from the given create3deployer contract. If it has been, change `FunWalletFactoryV1` to `FunWalletFactoryV2` or another version."
101
+ },
102
+ FW016: {
103
+ info: " FunWalletFactory.createAccount() - Call to initialize failed on the deployed proxy",
104
+ suggestion: "To fix this error, make sure the `initializerCallData` is formatted correctly"
105
+ },
106
+ FW017: {
107
+ info: " FunWalletFactory - Caller must be deployer",
108
+ suggestion: "To fix this error, make sure to call the function from the deployer address"
109
+ },
110
+ FW018: {
111
+ info: " WalletInit.commit() - The previous commit has not expired",
112
+ suggestion: "To fix this error, wait for the previous commit with this `commitKey` to expire. This should take at most 10 minutes."
113
+ },
114
+ FW019: {
115
+ info: " WalletInit.validateSalt() - The hash at the commitKey does not match `keccak256(abi.encode(seed, owner, initializerCallData))`",
116
+ suggestion: "To fix this error, make sure the seed, owner, and initializerCallData are hashed and stored in commits at the corresponding `commitKey`"
117
+ },
118
+ FW020: {
119
+ info: " WalletInit.validateSalt() - The new owner of the funwallet must match data.newFunWalletOwner from loginData",
120
+ suggestion: "To fix this error, make sure the owner set in `loginData` matches the owner address returned from the tweet."
121
+ },
122
+ FW021: {
123
+ info: " WalletInit.setOracle() - The address of the new `_oracle` must not be the zero address",
124
+ suggestion: "To fix this error, make sure `_oracle` is not the zero address"
125
+ },
126
+ FW022: {
127
+ info: " Create3Deployer.deployFromChild() - Invalid Child Address",
128
+ suggestion: "To fix this error, make sure the caller is a contract deployed from the Create3Deployer"
129
+ },
130
+ FW023: {
131
+ info: " ImplementationRegistry.verifyIsValidContractAndImplementation() - Invalid Target Code Hash",
132
+ suggestion: "To fix this error, make sure the caller is a contract targeted is a ERC1967ProxyData contract"
133
+ },
134
+ FW024: {
135
+ info: " ImplementationRegistry.verifyIsValidContractAndImplementation() - Invalid Contract Implementation Address",
136
+ suggestion: "To fix this error, make sure you have the minimun threshold amount of valid signatures."
137
+ },
138
+ FW025: {
139
+ info: " ImplementationRegistry.addImplementation() - Invalid Signature Amount",
140
+ suggestion: "To fix this error, make sure you have the minimun threshold amount of valid signatures."
141
+ },
142
+ FW026: {
143
+ info: " ImplementationRegistry.removeImplementation() - Invalid Signature Amount",
144
+ suggestion: "To fix this error, make sure you have the minimun threshold amount of valid signatures."
145
+ },
146
+ FW027: {
147
+ info: " WalletInit.commit() - Unable to commit with a previously used commit hash",
148
+ suggestion: "To fix this error, make sure you are not reusing someone else's commit hash. If there are conflicts, just regenerate the seed randomly"
149
+ },
150
+ FW028: {
151
+ info: " MultiSigDeployer.constructor() - Threshold can't be greater than deployers length",
152
+ suggestion: "To fix this error, make sure the threshold value is not 0"
153
+ },
154
+ FW029: {
155
+ info: " WalletInit.invalidateUsedSeed() - msg.sender must equal funwalletfactory",
156
+ suggestion: "To fix this error, make sure you are calling this function from the FunWalletFactory contract"
157
+ },
158
+ FW030: {
159
+ info: " WalletInit.setFunWalletFactory() - funwalletfactory address cannot be set to 0",
160
+ suggestion: "To fix this error, make sure you are passing in the valid funwalletfactory address"
161
+ },
162
+ FW031: {
163
+ info: " WalletInit.validateSalt() - seed has already been used",
164
+ suggestion: "To fix this error, make sure you are not using an existing salt"
165
+ },
166
+ FW032: {
167
+ info: " FunWalletFactory.setFeeOracle() - Cannot set the fee oracle address to 0",
168
+ suggestion: "To fix this error, make sure you are using the correct address of the fee oracle"
169
+ },
170
+ FW033: {
171
+ info: " FunWalletFactory.constructor() - Invalid Address, cannot be the zero address",
172
+ suggestion: "To fix this error, make sure `_entryPoint` is not equal to the zero address"
173
+ },
174
+ FW034: {
175
+ info: " Create3Deployer.callChild() - Value not equal to msg.value",
176
+ suggestion: "To fix this error, make sure `msg.value` is equal to the `value` parameter."
177
+ },
178
+ FW100: {
179
+ info: " Module.execute() - execute() needs to be overriden",
180
+ suggestion: "To fix this error, make sure you are overriding the execute method in your module"
181
+ },
182
+ FW101: {
183
+ info: " ApproveAndExec.approveAndExecute() - the approveData's first four bytes must be the approve() function selector",
184
+ suggestion: "To fix this error, change `approveData` such that the first four bytes are `bytes4(keccak256('approve(address,uint256)'))`"
185
+ },
186
+ FW102: {
187
+ info: " ApproveAndSwap.constructor() - `_wethAddr` cannot be the zero address",
188
+ suggestion: "To fix this error, make sure `_wethAddr` is not set to the zero address"
189
+ },
190
+ FW103: {
191
+ info: " ApproveAndSwap.constructor() - `_router` cannot be the zero address",
192
+ suggestion: "To fix this error, make sure `_router` is not set to the zero address"
193
+ },
194
+ FW104: {
195
+ info: " ApproveAndSwap.executeSwapEth() - msg.sender does not have enough weth",
196
+ suggestion: "To fix this error, make sure msg.sender has a weth balance >= `amount`"
197
+ },
198
+ FW105: {
199
+ info: " ApproveAndSwap.\\_internalSwap() - Approve failed",
200
+ suggestion: "To fix this error, make sure you have formatted approve correctly"
201
+ },
202
+ FW106: {
203
+ info: " AaveWithdraw.execute() - Withdrawing a zero balance",
204
+ suggestion: "You are trying to withdraw from aave but don't have a balance"
205
+ },
206
+ FW107: {
207
+ info: " ApproveAndExec.approveAndExecute() - Approve failed",
208
+ suggestion: "The token you tried to approve failed"
209
+ },
210
+ FW108: {
211
+ info: " UniswapV3LimitOrder.execute() - Approval Failed",
212
+ suggestion: "You are trying to withdraw from aave but don't have a balance"
213
+ },
214
+ FW109: {
215
+ info: " UniswapV3LimitOrder.constructor() - Router cannot be address zero",
216
+ suggestion: "Make sure you are not passing in the zero address when initializing the module"
217
+ },
218
+ FW110: {
219
+ info: " UniswapV3LimitOrder.constructor() - Quoter cannot be zero address",
220
+ suggestion: "Make sure you are not passing in the zero address when initializing the module"
221
+ },
222
+ FW200: {
223
+ info: " FeePercentOracle.setValues() - feepercent must be less than or equals to 100%",
224
+ suggestion: "To fix this error, `_feepercent` must be less than or equals to `10 ** _decimals`"
225
+ },
226
+ FW201: {
227
+ info: " FeePercentOracle.withdrawEth() - eth transfer failed",
228
+ suggestion: "To fix this error, investigate why the eth withdrawal failed. This is likely because `amount` was greater than the eth balance in the FeePercentOracle"
229
+ },
230
+ FW202: {
231
+ info: " TokenPriceOracle.getTokenValueOfEth() - chainlink aggregator price must be greater than 0",
232
+ suggestion: "To fix this error, retry the call and make sure price is greater than 0"
233
+ },
234
+ FW203: {
235
+ info: " TokenPriceOracle.getTokenValueOfEth() - chainlink aggregator updatedAt must be greater than 0",
236
+ suggestion: "To fix this error, retry the call and make sure updatedAt is greater than 0"
237
+ },
238
+ FW204: {
239
+ info: " TokenPriceOracle.getTokenValueOfEth() - chainlink aggregator answeredInRound must be greater than or equal to roundId",
240
+ suggestion: "To fix this error, retry the call and make sure answeredInRound must be greater than or equal to roundId"
241
+ },
242
+ FW205: {
243
+ info: " TwitterOracle.batchSetTweet() - socialHandles, loginTypes, seeds, owners length must match in length",
244
+ suggestion: "To fix this error, make sure all arrays passed into this function are the same length."
245
+ },
246
+ FW206: {
247
+ info: " TwitterOracle.setTweet() - the seed from twitter cannot be empty",
248
+ suggestion: "To fix this error, make sure the seed you post on twitter is not empty {}"
249
+ },
250
+ FW207: {
251
+ info: " TwitterOracle.setTweet() - the address from twitter cannot be 0",
252
+ suggestion: "To fix this error, make sure the address you post on twitter for the new owner is not the zero address, otherwise you would be unable to claim ownership of the funwallet"
253
+ },
254
+ FW208: {
255
+ info: " TwitterOracle.batchSetTweet() - the seed from twitter cannot be empty",
256
+ suggestion: "To fix this error, make sure the seed you post on twitter is not empty {}"
257
+ },
258
+ FW209: {
259
+ info: " TwitterOracle.batchSetTweet() - the address from twitter cannot be 0",
260
+ suggestion: "To fix this error, make sure the address you post on twitter for the new owner is not the zero address, otherwise you would be unable to claim ownership of the funwallet"
261
+ },
262
+ FW210: {
263
+ info: " TwitterOracle.fetchTweet() - the seed from twitter cannot be empty",
264
+ suggestion: "To fix this error, make sure the seed you post on twitter is not empty {}"
265
+ },
266
+ FW211: {
267
+ info: " TwitterOracle.fetchTweet() - the address from twitter cannot be 0",
268
+ suggestion: "To fix this error, make sure the address you post on twitter for the new owner is not the zero address, otherwise you would be unable to claim ownership of the funwallet"
269
+ },
270
+ FW300: {
271
+ info: " BasePaymaster.constructor() - entrypoint address cannot be the zero address",
272
+ suggestion: "To fix this error, make sure entrypoint address is not the zero address"
273
+ },
274
+ FW301: {
275
+ info: " BasePaymaster.\\_requireFromEntryPoint() - the msg.sender must be from the entrypoint",
276
+ suggestion: "To fix this error, make sure the msg.sender must be from the entrypoint"
277
+ },
278
+ FW302: {
279
+ info: " GaslessPaymaster.batchActions() - the ith delegate call failed",
280
+ suggestion: "To fix this error, make sure the calldata for `data[i]` is a valid call"
281
+ },
282
+ FW303: {
283
+ info: " GaslessPaymaster.batchActions() - batchActions consumed more eth than `msg.value` allocated",
284
+ suggestion: "To fix this error, increase the amount of msg.value you are passing to this function"
285
+ },
286
+ FW304: {
287
+ info: " GaslessPaymaster.\\_withdrawDepositTo() - the withdrawal has not been unlocked",
288
+ suggestion: "To fix this error, wait till block.number is greater than the unlockBlock for the sender and make sure `unlockBlock[sender]` is nonzero"
289
+ },
290
+ FW305: {
291
+ info: " GaslessPaymaster.\\_withdrawDepositTo() - the balances of the sender must be greater than the withdrawal amount",
292
+ suggestion: "To fix this error, decrease the amount you are trying to withdraw"
293
+ },
294
+ FW306: {
295
+ info: " GaslessPaymaster.\\_validatePaymasterUserOp() - the userOp.paymasterAndData must have a length of 40",
296
+ suggestion: "To fix this error, change the `paymasterAndData` field in the `userOp` such that the length is 40"
297
+ },
298
+ FW307: {
299
+ info: " GaslessPaymaster.\\_validatePaymasterUserOp() - the verificationGasLimit must be greater than the `COST_OF_POST` variable in GaslessPaymaster",
300
+ suggestion: "To fix this error, increase the `verificationGasLimit` in the `userOp`"
301
+ },
302
+ FW308: {
303
+ info: " GaslessPaymaster.\\_validatePaymasterUserOp() - the sponsor's eth is not locked for use",
304
+ suggestion: "To fix this error, make sure the sponsor's eth is locked using `lockDeposit()`"
305
+ },
306
+ FW309: {
307
+ info: " GaslessPaymaster.\\_validatePaymasterUserOp() - The sponsor needs to approve the spender",
308
+ suggestion: "To fix this error, make sure to approve the spender using `setSpenderWhitelistMode()` or `setSpenderBlacklistMode()` and the sponsor's list mode is set to whitelist mode or blacklist mode using `setListMode()"
309
+ },
310
+ FW310: {
311
+ info: " GaslessPaymaster.\\_validatePaymasterUserOp() - The sponsor does not have sufficient eth in the paymaster to cover this operation",
312
+ suggestion: "To fix this error, make sure to stake enough eth from the sponsor's address using `addDepositTo()`"
313
+ },
314
+ FW311: {
315
+ info: " GaslessPaymaster.addDepositTo() - `msg.value` must be greater than or equal to amount",
316
+ suggestion: "To fix this error, make sure `msg.value` must be greater than or equal to amount"
317
+ },
318
+ FW312: {
319
+ info: " TokenPaymaster.batchActions() - the ith delegate call failed",
320
+ suggestion: "To fix this error, make sure the calldata for `data[i]` is a valid call"
321
+ },
322
+ FW313: {
323
+ info: " TokenPaymaster.batchActions() - batchActions consumed more eth than `msg.value` allocated",
324
+ suggestion: "To fix this error, increase the amount of msg.value you are passing to this function"
325
+ },
326
+ FW314: {
327
+ info: " TokenPaymaster.\\_addTokenDepositTo() - token decimals must be greater than 0",
328
+ suggestion: "To fix this error, change the decimals in token using `setTokenData()`"
329
+ },
330
+ FW315: {
331
+ info: " TokenPaymaster.\\_withdrawTokenDepositTo() - token is not unlocked for withdrawal",
332
+ suggestion: "To fix this error, call `unlockTokenDepositAfter()`"
333
+ },
334
+ FW316: {
335
+ info: " TokenPaymaster.\\_withdrawTokenDepositTo() - you are withdrawing more tokens that you have in balance",
336
+ suggestion: "To fix this error, call `getTokenBalance()` to check how many tokens you have and make sure `amount` is less than that"
337
+ },
338
+ FW317: {
339
+ info: " TokenPaymaster.\\_withdrawEthDepositTo() - token is not unlocked for withdrawal",
340
+ suggestion: "To fix this error, call `unlockTokenDepositAfter()` with `ETH` as the token"
341
+ },
342
+ FW318: {
343
+ info: " TokenPaymaster.\\_withdrawEthDepositTo() - you are withdrawing more ether that you have in balance",
344
+ suggestion: "To fix this error, call `getTokenBalance()` with `ETH` as the token to check how many tokens you have and make sure `amount` is less than that"
345
+ },
346
+ FW319: {
347
+ info: " TokenPaymaster.\\_getTokenValueOfEth() - call to token oracle failed",
348
+ suggestion: "To fix this error, check the token oracle and call `setTokenData()` to change the oracle if it is broken"
349
+ },
350
+ FW320: {
351
+ info: " TokenPaymaster.\\_reimbursePaymaster() - failed to reimbursePaymaster with tokens via `permitTransfer()`",
352
+ suggestion: "To fix this **error**, make sure you have permitted the paymaster to spend your tokens"
353
+ },
354
+ FW321: {
355
+ info: " TokenPaymaster.\\_reimbursePaymaster() - spender doesn't have enough tokens",
356
+ suggestion: "To fix this error, make sure to add more tokens to the token paymaster via `addTokenDepositTo()`"
357
+ },
358
+ FW322: {
359
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - `paymasterAndData` length must be 60",
360
+ suggestion: "To fix this error, make sure to set `paymasterAndData` length to be 60"
361
+ },
362
+ FW323: {
363
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - `verificationGasLimit` must be greater than `COST_OF_POST`",
364
+ suggestion: "To fix this error, make sure to set the userOp's `verificationGasLimit` to be greater than `COST_OF_POST`"
365
+ },
366
+ FW324: {
367
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the sponsor must lock their ETH",
368
+ suggestion: "To fix this error, make sure the sponsor has locked their eth by calling `lockTokenDeposit()` from the sponsor address"
369
+ },
370
+ FW325: {
371
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the account must lock their tokens",
372
+ suggestion: "To fix this error, make sure the user of the token paymaster has locked their tokens by calling `lockTokenDeposit()` from their address"
373
+ },
374
+ FW326: {
375
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the sponsor eth balance must be greater than maxCost",
376
+ suggestion: "To fix this error, make sure the sponsor eth balance is greater than maxCost"
377
+ },
378
+ FW327: {
379
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the sponsor must approve the spender",
380
+ suggestion: "To fix this error, make sure the sponsor has approved the spender by calling `setSpenderWhitelistMode()` or `setSpenderBlacklistMode()` and the sponsor's list mode is set to whitelist mode or blacklist mode using `setListMode()`"
381
+ },
382
+ FW328: {
383
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the sponsor must have approved the token to the paymaster",
384
+ suggestion: "To fix this error, make sure the sponsor has approved the spender by calling `setTokenWhitelistMode()` or `setTokenBlacklistMode()` and the sponsor's list mode is set to whitelist mode or blacklist mode using `setTokenListMode()`"
385
+ },
386
+ FW329: {
387
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the permitted token must be equal to the token you are trying to pay with if using permit",
388
+ suggestion: "To fix this error, make sure the permitted token is equal to the token you are trying to pay with if using permit"
389
+ },
390
+ FW330: {
391
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the permitted transfer recipient must be the token paymaster",
392
+ suggestion: "To fix this error, make sure to permit the token paymaster to spend your tokens"
393
+ },
394
+ FW331: {
395
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - the permitted transfer amount must be greater than or equal to the maxTokenCost",
396
+ suggestion: "To fix this error, make sure the permitted transfer amount is greater than or equal to the maxTokenCost"
397
+ },
398
+ FW332: {
399
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - if permit was not used, make sure the tokenPaymaster was approved to spend tokens by the sponsor or enough tokens were deposited into the TokenPaymaster",
400
+ suggestion: "To fix this error, make sure the tokenPaymaster was approved(`approve()`) to spend tokens by the sponsor or enough tokens were deposited into the TokenPaymaster via `addTokenDepositTo()`"
401
+ },
402
+ FW333: {
403
+ info: " TokenPaymaster.addEthDepositTo() - make sure msg.value is greater than or equal to amount",
404
+ suggestion: "To fix this error, make sure that the msg.value is greater than or equal to amount"
405
+ },
406
+ FW334: {
407
+ info: " TokenPaymaster.addTokenDepositTo() - sponsor cannot be the zero address",
408
+ suggestion: "To fix this error, make sure the sponsor is not the zero address"
409
+ },
410
+ FW335: {
411
+ info: " TokenPaymaster.addTokenDepositTo() - target cannot be the zero address",
412
+ suggestion: "To fix this error, make sure the target is not the zero address"
413
+ },
414
+ FW336: {
415
+ info: " TokenPaymaster.addTokenDepositTo() - token address cannot be the zero address",
416
+ suggestion: "To fix this error, make sure the token address is not the zero address"
417
+ },
418
+ FW337: {
419
+ info: " TokenPaymaster.addTokenDepositTo() - spender address cannot be the zero address",
420
+ suggestion: "To fix this error, make sure the spender address is not the zero address"
421
+ },
422
+ FW338: {
423
+ info: " TokenPaymaster.addTokenDepositTo() - the token oracle cannot be the zero address",
424
+ suggestion: "To fix this error, make sure the token oracle is not the zero address"
425
+ },
426
+ FW339: {
427
+ info: " TokenPaymaster.addTokenDepositTo() - the tokenAddress cannot be the zero address",
428
+ suggestion: "To fix this error, make sure the tokenAddress is not the zero address"
429
+ },
430
+ FW340: {
431
+ info: " TokenPaymaster.addTokenDepositTo() - the token decimals must be greater than 0",
432
+ suggestion: "To fix this error, make sure the token decimals is greater than 0"
433
+ },
434
+ FW341: {
435
+ info: " TokenPaymaster.addTokenDepositTo() - the chainlink aggregator cannot be the zero address",
436
+ suggestion: "To fix this error, make sure the chainlink aggregator is not the zero address"
437
+ },
438
+ FW342: {
439
+ info: " TokenPaymaster.removeTokenData() - The token doesn't exist in tokens",
440
+ suggestion: "To fix this error, make sure the token address is not the zero address"
441
+ },
442
+ FW343: {
443
+ info: " TokenPaymaster.removeTokenData() - The tokenListIndex doesn't match with the tokenAddress",
444
+ suggestion: "To fix this error, make sure the token at tokenList[tokenListIndex] is the same as the tokenAddress"
445
+ },
446
+ FW344: {
447
+ info: " GaslessPaymaster.batchActions() - Cannot recursively call batchActions from within batchActions",
448
+ suggestion: "To fix this error, make sure you are not recursively calling batchActions from within batchActions"
449
+ },
450
+ FW345: {
451
+ info: " TokenPaymaster.batchActions() - Cannot recursively call batchActions from within batchActions",
452
+ suggestion: "To fix this error, make sure you are not recursively calling batchActions from within batchActions"
453
+ },
454
+ FW346: {
455
+ info: " TokenPaymaster.postOp() - Invalid Permit transfer amount",
456
+ suggestion: "To fix this error, make sure your permit transfer has transfered the correct amount of tokens"
457
+ },
458
+ FW347: {
459
+ info: " TokenPaymaster.\\_reimbursePaymaster() - Invalid amount of tokens transferred",
460
+ suggestion: "The likely cause of this error is using a deflationary token that charges a tax when you transfer tokens. To fix this error, make sure you are transferring the correct amount of tokens and to account for the tax/deflation."
461
+ },
462
+ FW348: {
463
+ info: " UserAuthentication.init() - groupId count must be equal to groups length",
464
+ suggestion: "Make sure the number of groupIds equals the number of groups."
465
+ },
466
+ FW349: {
467
+ info: " TokenPaymaster.calculatePostOpGas() - Invalid Auth Type",
468
+ suggestion: "Make sure the authtype is correct"
469
+ },
470
+ FW350: {
471
+ info: " TokenPaymaster.\\_validatePaymasterUserOp() - Does not have enough balance of token",
472
+ suggestion: "To fix this error, make sure your has enough tokens to permit transfer"
473
+ },
474
+ FW351: {
475
+ info: " BasePaymaster.\\withdrawStakeFromEntryPoint() - Cannot withdraw to address zero",
476
+ suggestion: "To fix this error, make sure you are not withdrawing to address zero"
477
+ },
478
+ FW401: {
479
+ info: " RoleBasedAccessControl",
480
+ suggestion: "### `FW402`: RoleBasedAccessControl.isValidAction(), isValidActionAndFee() - Invalid Target"
481
+ },
482
+ FW402: {
483
+ info: " RoleBasedAccessControl.isValidAction(), isValidActionAndFee() - Invalid Target",
484
+ suggestion: "To fix this error, make sure the target that you are calling is in the merkle root of allowed targets verified by the rule. If this does not work make sure you are using the correct merkle root implementation."
485
+ },
486
+ FW403: {
487
+ info: " RoleBasedAccessControl",
488
+ suggestion: "To fix this error, make sure the selector that you are calling is in the merkle root of allowed selector verified by the rule. If this does not work make sure you are using the correct merkle root implementation."
489
+ },
490
+ FW404: {
491
+ info: " RoleBasedAccessControl",
492
+ suggestion: "To fix this error, make sure the ownerId is not 0 or an existing owner"
493
+ },
494
+ FW405: {
495
+ info: " RoleBasedAccessControl",
496
+ suggestion: "To fix this error, make sure the ruleId is not 0"
497
+ },
498
+ FW406: {
499
+ info: " RoleBasedAccessControl",
500
+ suggestion: "To fix this error, make sure the rule that you are using has a deadline that has passed."
501
+ },
502
+ FW408: {
503
+ info: " RoleBasedAccessControl",
504
+ suggestion: "### `FW410`: RoleBasedAccessControl: isValidAction(), isValidActionAndFee() - Rule not added to role"
505
+ },
506
+ FW410: {
507
+ info: " RoleBasedAccessControl",
508
+ suggestion: "To fix this error, make sure the rule is added to the role"
509
+ },
510
+ FW411: {
511
+ info: " RoleBasedAccessControl",
512
+ suggestion: "To fix this error, make sure the value for the execution call is less than the limit"
513
+ },
514
+ FW412: {
515
+ info: " RoleBasedAccessControl",
516
+ suggestion: "To fix this error, make sure the fee value for the execution call is less than the limit"
517
+ },
518
+ FW413: {
519
+ info: " RoleBasedAccessControl",
520
+ suggestion: "To fix this error, make sure the fee recipient is in the rule fee merkle root"
521
+ },
522
+ FW414: {
523
+ info: " RoleBasedAccessControl",
524
+ suggestion: "To fix this error, make sure the fee token is in the rule fee merkle root"
525
+ },
526
+ FW417: {
527
+ info: " RoleBasedAccessControl",
528
+ suggestion: "To fix this error, make sure the rule you are using exists"
529
+ },
530
+ FW418: {
531
+ info: " RoleBasedAccessControl",
532
+ suggestion: "To fix this error, make sure the user is in the role"
533
+ },
534
+ FW419: {
535
+ info: " RoleBasedAccessControl",
536
+ suggestion: "To fix this error, make sure the feeRecipientTokenMerkleRootHash is not zero"
537
+ },
538
+ FW420: {
539
+ info: " RoleBasedAccessControl",
540
+ suggestion: "To fix this error, make sure the targetSelectorMerkleRootHash is not zero"
541
+ },
542
+ FW421: {
543
+ info: " RoleBasedAccessControl",
544
+ suggestion: "### `FW422`: RoleBasedAccessControl: init() - Wallet has not been initialized"
545
+ },
546
+ FW422: {
547
+ info: " RoleBasedAccessControl",
548
+ suggestion: "To fix this error, make sure the wallet has not initialized the validation contract"
549
+ },
550
+ FW500: {
551
+ info: " FunWallet.initialize() - the entrypoint cannot be the zero address",
552
+ suggestion: "To fix this error, make sure the entrypoint is not the zero address"
553
+ },
554
+ FW501: {
555
+ info: " FunWallet.initialize() - the msg.sender cannot be the address of the Funwallet contract",
556
+ suggestion: "To fix this error, make sure the msg.sender is not the address of the Funwallet contract"
557
+ },
558
+ FW502: {
559
+ info: " FunWallet.\\_requireFromFunWalletProxy() - the function must be called from the funwallet proxy",
560
+ suggestion: "To fix this error, make sure the msg.sender == funwallet"
561
+ },
562
+ FW503: {
563
+ info: " FunWallet.updateEntryPoint() - the new entrypoint address cannot be the zero address",
564
+ suggestion: "To fix this error, make sure the new entrypoint address is not the zero address"
565
+ },
566
+ FW504: {
567
+ info: " FunWallet.depositToEntryPoint() - not enough eth in the funwallet",
568
+ suggestion: "To fix this error, make sure the funwallet has more than the amount of eth you are trying to deposit"
569
+ },
570
+ FW505: {
571
+ info: " FunWallet.\\_transferEthFromEntrypoint() - withdrawing eth from the entrypoint failed",
572
+ suggestion: "To fix this error, retry the operation and make sure you have greater than amount balance in the entrypoint"
573
+ },
574
+ FW506: {
575
+ info: " FunWallet.\\_requireFromModule() - make sure a funwalletfactory deployed the module",
576
+ suggestion: "To fix this error, make sure the msg.sender is the module"
577
+ },
578
+ FW507: {
579
+ info: " FunWallet.\\_requireFromEntryPoint() - the msg.sender must be the entrypoint",
580
+ suggestion: "To fix this error, make sure the msg.sender is the entrypoint"
581
+ },
582
+ FW508: {
583
+ info: " WalletFee.\\_transferEth() - the eth transfer failed",
584
+ suggestion: "To fix this error, retry the operation and make sure you have greater than amount balance in the wallet"
585
+ },
586
+ FW509: {
587
+ info: " WalletFee.\\_handleFee() - the developer eth transfer failed",
588
+ suggestion: "To fix this error, retry the operation and make sure you have greater than amount balance in the wallet"
589
+ },
590
+ FW510: {
591
+ info: " WalletFee.\\_handleFee() - the funOracle eth transfer failed",
592
+ suggestion: "To fix this error, retry the operation and make sure you have greater than amount balance in the wallet"
593
+ },
594
+ FW511: {
595
+ info: " WalletValidation.initValidations() - the WalletValidations contract has already been initialized",
596
+ suggestion: "Don't call initValidations() more than once"
597
+ },
598
+ FW512: {
599
+ info: " WalletValidation.initValidations() - make sure there are more than zero validations",
600
+ suggestion: "To fix this error, make sure there are more than zero validations and the number of validation contract addresses are equal to the number of `initCallData` elements"
601
+ },
602
+ FW513: {
603
+ info: " WalletValidation.initValidations() - make sure there are no duplicate validation contract addresses",
604
+ suggestion: "To fix this error, make sure there are no duplicate validation contract addresses in `validationData`"
605
+ },
606
+ FW514: {
607
+ info: " WalletValidation.\\_validateUserOp() - make sure the signature length is greater than 0",
608
+ suggestion: "To fix this error, make sure the signature length is greater than 0"
609
+ },
610
+ FW515: {
611
+ info: " WalletValidation.isValidSignature() - make sure the number of validations is greater than zero",
612
+ suggestion: "To fix this error, make sure the number of validations is greater than zero"
613
+ },
614
+ FW516: {
615
+ info: " WalletValidation.\\_requireValidValidation() - the validation failed",
616
+ suggestion: "To fix this error, make sure the validation contract returns true"
617
+ },
618
+ FW517: {
619
+ info: " WalletValidation.\\_requireValidValidationFormat() - the validation was incorrectly formatted",
620
+ suggestion: "To fix this error, make sure the validation contract address is not the zero address and the validation is valid and the address is not the zero address"
621
+ },
622
+ FW518: {
623
+ info: " WalletValidation.\\_requireValidPrevValidation() - the previous validation must be linked to this validation",
624
+ suggestion: "To fix this error, make sure the previous validation is linked to this validation when adding or removing the validation"
625
+ },
626
+ FW519: {
627
+ info: " WalletValidation.getValidations() - you must have more than zero validations to get validations",
628
+ suggestion: "To fix this error, make sure there are a nonzero amount of validations"
629
+ },
630
+ FW520: {
631
+ info: " WalletValidation.addValidation() - The caller must be this wallet.",
632
+ suggestion: "To fix this error, make sure you are calling addValidation() from your funwallet."
633
+ },
634
+ FW521: {
635
+ info: " WalletValidation.removeValidation() - The caller must be this wallet.",
636
+ suggestion: "To fix this error, make sure you are calling removeValidation() from your funwallet."
637
+ },
638
+ FW522: {
639
+ info: " WalletValidation.updateValidation() - The caller must be this wallet.",
640
+ suggestion: "To fix this error, make sure you are calling updateValidation() from your funwallet."
641
+ },
642
+ FW523: {
643
+ info: " WalletModules.permitTransfer() - Invalid Permit Signature.",
644
+ suggestion: "To fix this error, make sure you have a valid permit signature."
645
+ },
646
+ FW524: {
647
+ info: " WalletValidation.getValidations() - No Validations in the wallet",
648
+ suggestion: "To fix this error, make sure the wallet has validation contracts"
649
+ },
650
+ FW600: {
651
+ info: " DataLib",
652
+ suggestion: "To fix this error, make sure you are calling either execFromEntryPoint() or execFromEntryPointWithFee() from your funwallet."
653
+ },
654
+ FW601: {
655
+ info: " Ownable2StepNoRenounce",
656
+ suggestion: "To fix this error, don't call this function."
657
+ }
658
+ };
659
+
660
+ // src/errors/types.ts
661
+ var ErrorBaseType = /* @__PURE__ */ ((ErrorBaseType2) => {
662
+ ErrorBaseType2["ClientError"] = "ClientError";
663
+ ErrorBaseType2["ServerError"] = "ServerError";
664
+ return ErrorBaseType2;
665
+ })(ErrorBaseType || {});
666
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
667
+ ErrorType2["InvalidParameter"] = "InvalidParameter";
668
+ ErrorType2["InternalServerFailure"] = "InternalServerFailure";
669
+ ErrorType2["ResourceNotFound"] = "ResourceNotFound";
670
+ ErrorType2["InvalidAction"] = "InvalidAction";
671
+ ErrorType2["ThrottlingError"] = "ThrottlingError";
672
+ ErrorType2["AccessDeniedError"] = "AccessDeniedError";
673
+ ErrorType2["UserOpFailureError"] = "UserOpFailureError";
674
+ return ErrorType2;
675
+ })(ErrorType || {});
676
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
677
+ ErrorCode2["MissingParameter"] = "MissingParameter";
678
+ ErrorCode2["InvalidParameter"] = "InvalidParameter";
679
+ ErrorCode2["InvalidThreshold"] = "InvalidThreshold";
680
+ ErrorCode2["InvalidChainIdentifier"] = "InvalidChainIdentifier";
681
+ ErrorCode2["InvalidNFTIdentifier"] = "InvalidNFTIdentifier";
682
+ ErrorCode2["InsufficientSignatures"] = "InsufficientSignatures";
683
+ ErrorCode2["InvalidParameterCombination"] = "InvalidParameterCombination";
684
+ ErrorCode2["CheckPointHintsNotFound"] = "CheckPointHintsNotFound";
685
+ ErrorCode2["GroupNotFound"] = "GroupNotFound";
686
+ ErrorCode2["TokenNotFound"] = "TokenNotFound";
687
+ ErrorCode2["AddressNotFound"] = "AddressNotFound";
688
+ ErrorCode2["UserAlreadyExists"] = "UserAlreadyExists";
689
+ ErrorCode2["UserNotFound"] = "UserNotFound";
690
+ ErrorCode2["ChainNotSupported"] = "ChainNotSupported";
691
+ ErrorCode2["ServerMissingData"] = "ServerMissingData";
692
+ ErrorCode2["ServerFailure"] = "ServerFailure";
693
+ ErrorCode2["ServerTimeout"] = "ServerTimeout";
694
+ ErrorCode2["UnknownServerError"] = "UnknownServerError";
695
+ ErrorCode2["ServerConnectionError"] = "ServerConnectionError";
696
+ ErrorCode2["UserOpFailureError"] = "UserOpFailureError";
697
+ ErrorCode2["Unauthorized"] = "Unauthorized";
698
+ ErrorCode2["RequestLimitExceeded"] = "RequestLimitExceeded";
699
+ ErrorCode2["WalletPrefundError"] = "PrefundError";
700
+ ErrorCode2["GasSponsorFundError"] = "GasSponsorFundError";
701
+ ErrorCode2["FunWalletErrorCode"] = "FunWalletErrorCode";
702
+ ErrorCode2["BridgeRouteNotFound"] = "BridgeRouteNotFound";
703
+ ErrorCode2["BridgeAllowanceDataNotFound"] = "BridgeAllowanceDataNotFound";
704
+ ErrorCode2["BridgeApproveTxDataNotFound"] = "BridgeApproveTxDataNotFound";
705
+ ErrorCode2["CheckoutInitDepositAddrNotFound"] = "CheckoutInitDepositAddrNotFound";
706
+ return ErrorCode2;
707
+ })(ErrorCode || {});
708
+
709
+ // src/errors/ClientError.ts
710
+ var ClientError = class extends BaseError {
711
+ constructor(type, code, msg, paramsUsed, fixSuggestion, docLink) {
712
+ super(
713
+ "ClientError" /* ClientError */,
714
+ type,
715
+ code,
716
+ msg,
717
+ paramsUsed,
718
+ fixSuggestion,
719
+ docLink,
720
+ false
721
+ );
722
+ }
723
+ };
724
+ var InvalidParameterError = class extends ClientError {
725
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
726
+ super(
727
+ "InvalidParameter" /* InvalidParameter */,
728
+ code,
729
+ msg,
730
+ paramsUsed,
731
+ fixSuggestion,
732
+ docLink
733
+ );
734
+ }
735
+ };
736
+ var ResourceNotFoundError = class extends ClientError {
737
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
738
+ if (msg.includes("Chain name not found")) {
739
+ const { reqId } = JSON.parse(msg);
740
+ msg = ": Chain name not found or not supported.";
741
+ fixSuggestion = "Change your EnvOptions to the correct chain identifier.";
742
+ super(
743
+ "ResourceNotFound" /* ResourceNotFound */,
744
+ "ChainNotSupported" /* ChainNotSupported */,
745
+ msg,
746
+ { reqId },
747
+ fixSuggestion,
748
+ docLink
749
+ );
750
+ } else {
751
+ super(
752
+ "ResourceNotFound" /* ResourceNotFound */,
753
+ code,
754
+ msg,
755
+ paramsUsed,
756
+ fixSuggestion,
757
+ docLink
758
+ );
759
+ }
760
+ }
761
+ };
762
+ var InvalidActionError = class extends ClientError {
763
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
764
+ super(
765
+ "InvalidAction" /* InvalidAction */,
766
+ code,
767
+ msg,
768
+ paramsUsed,
769
+ fixSuggestion,
770
+ docLink
771
+ );
772
+ }
773
+ };
774
+ var ThrottlingError = class extends ClientError {
775
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
776
+ super(
777
+ "ThrottlingError" /* ThrottlingError */,
778
+ code,
779
+ msg,
780
+ paramsUsed,
781
+ fixSuggestion,
782
+ docLink
783
+ );
784
+ }
785
+ };
786
+ var AccessDeniedError = class extends ClientError {
787
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
788
+ super(
789
+ "AccessDeniedError" /* AccessDeniedError */,
790
+ code,
791
+ msg,
792
+ paramsUsed,
793
+ fixSuggestion,
794
+ docLink
795
+ );
796
+ }
797
+ };
798
+ var UserOpFailureError = class extends ClientError {
799
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
800
+ const FWCode = findFWContractError(msg);
801
+ if (FWCode) {
802
+ const { reqId } = JSON.parse(msg);
803
+ msg = errors_default[FWCode].info;
804
+ fixSuggestion = errors_default[FWCode].suggestion;
805
+ super(
806
+ "UserOpFailureError" /* UserOpFailureError */,
807
+ "FunWalletErrorCode" /* FunWalletErrorCode */,
808
+ msg,
809
+ { reqId },
810
+ fixSuggestion,
811
+ docLink
812
+ );
813
+ } else {
814
+ super(
815
+ "UserOpFailureError" /* UserOpFailureError */,
816
+ code,
817
+ msg,
818
+ paramsUsed,
819
+ fixSuggestion,
820
+ docLink
821
+ );
822
+ }
823
+ }
824
+ };
825
+ var findFWContractError = (msg) => {
826
+ let match = msg.match(/FW\d{3}/);
827
+ if (!match) {
828
+ match = msg.match(/AA\d./);
829
+ }
830
+ return match?.[0];
831
+ };
832
+
833
+ // src/errors/ServerError.ts
834
+ var ServerError = class extends BaseError {
835
+ constructor(type, code, msg, paramsUsed, fixSuggestion, docLink) {
836
+ super(
837
+ "ServerError" /* ServerError */,
838
+ type,
839
+ code,
840
+ msg,
841
+ paramsUsed,
842
+ fixSuggestion,
843
+ docLink,
844
+ true
845
+ );
846
+ }
847
+ };
848
+ var InternalFailureError = class extends ServerError {
849
+ constructor(code, msg, paramsUsed, fixSuggestion, docLink) {
850
+ super(
851
+ "InternalServerFailure" /* InternalServerFailure */,
852
+ code,
853
+ msg,
854
+ paramsUsed,
855
+ fixSuggestion,
856
+ docLink
857
+ );
858
+ }
859
+ };
860
+
861
+ // src/utils/error.ts
862
+ var errorAbortHandler = (err, context) => {
863
+ if (err instanceof ResourceNotFoundError || err instanceof InvalidParameterError || err instanceof UserOpFailureError) {
864
+ context.abort();
865
+ }
866
+ };
867
+
868
+ // src/consts/retry.ts
869
+ var DEFAULT_RETRY_OPTIONS = {
870
+ delay: 100,
871
+ initialDelay: 0,
872
+ maxDelay: 3e3,
873
+ factor: 2,
874
+ maxAttempts: 5,
875
+ timeout: 0,
876
+ jitter: true,
877
+ minDelay: 0,
878
+ handleError: errorAbortHandler,
879
+ handleTimeout: null,
880
+ beforeAttempt: null,
881
+ calculateDelay: null
882
+ };
883
+
884
+ // src/utils/checkout.ts
885
+ import { toHex } from "viem";
886
+ function randomBytes(length) {
887
+ const bytes = new Uint8Array(length);
888
+ for (let i = 0; i < length; i++) {
889
+ bytes[i] = Math.floor(Math.random() * 256);
890
+ }
891
+ return toHex(bytes);
892
+ }
893
+ function generateRandomCheckoutSalt() {
894
+ return toHex(BigInt(randomBytes(32)));
895
+ }
896
+ function roundToNearestBottomTenth(n) {
897
+ return Math.floor(n / 10) * 10;
898
+ }
899
+
900
+ // src/utils/request.ts
901
+ import { retry } from "@lifeomic/attempt";
902
+ import { toHex as toHex2 } from "viem";
903
+ var stringifyWithBigIntSanitization = (object) => {
904
+ return JSON.stringify(
905
+ object,
906
+ (_, value) => typeof value === "bigint" ? toHex2(value) : value
907
+ // return everything else unchanged
908
+ );
909
+ };
910
+ var sendRequest = async ({
911
+ uri,
912
+ method,
913
+ apiKey,
914
+ body = {},
915
+ retryOptions = {}
916
+ }) => {
917
+ try {
918
+ const headers = {
919
+ "Content-Type": "application/json",
920
+ ...apiKey ? { "X-Api-Key": apiKey } : {}
921
+ };
922
+ const finalRetryOptions = {
923
+ ...DEFAULT_RETRY_OPTIONS,
924
+ ...retryOptions || {}
925
+ };
926
+ return retry(async function() {
927
+ const response = await fetch(uri, {
928
+ method,
929
+ headers,
930
+ redirect: "follow",
931
+ body: method !== "GET" ? stringifyWithBigIntSanitization(body) : void 0
932
+ });
933
+ const json = await response.json();
934
+ if (response.ok) {
935
+ return json;
936
+ } else if (response.status === 400) {
937
+ throw new InvalidParameterError(
938
+ "InvalidParameter" /* InvalidParameter */,
939
+ `bad request ${JSON.stringify(json)}`,
940
+ { body },
941
+ "check the api call parameters. its mostly because some call parameters are wrong",
942
+ "https://docs.fun.xyz"
943
+ );
944
+ } else if (response.status === 403) {
945
+ throw new AccessDeniedError(
946
+ "Unauthorized" /* Unauthorized */,
947
+ "Invalid API key or insufficient access.",
948
+ { apiKey },
949
+ "Check your api key at https://app.fun.xyz and check with fun team if you believe something is off",
950
+ "https://docs.fun.xyz"
951
+ );
952
+ } else if (response.status === 404) {
953
+ throw new ResourceNotFoundError(
954
+ "ServerMissingData" /* ServerMissingData */,
955
+ JSON.stringify(json),
956
+ { body },
957
+ "check the api call parameters. its mostly because some call parameters are wrong",
958
+ "https://docs.fun.xyz"
959
+ );
960
+ } else if (response.status === 429) {
961
+ throw new ThrottlingError(
962
+ "RequestLimitExceeded" /* RequestLimitExceeded */,
963
+ `too many requests ${JSON.stringify(json)}`,
964
+ { body },
965
+ "you are making too many requests. please slow down. Reach out to fun team if you need more quota",
966
+ "https://docs.fun.xyz"
967
+ );
968
+ } else if (response.status === 500) {
969
+ if (json.errorCode === "UserOpFailureError" /* UserOpFailureError */) {
970
+ throw new UserOpFailureError(
971
+ "UserOpFailureError" /* UserOpFailureError */,
972
+ JSON.stringify(json),
973
+ { body },
974
+ "fix user op failure. Most of the time this is due to invalid parameters",
975
+ "https://docs.fun.xyz"
976
+ );
977
+ } else {
978
+ throw new InternalFailureError(
979
+ "ServerFailure" /* ServerFailure */,
980
+ `server failure ${JSON.stringify(json)}`,
981
+ { body },
982
+ "retry later. if it still fails, please contact us.",
983
+ "https://docs.fun.xyz"
984
+ );
985
+ }
986
+ } else if (response.status === 504) {
987
+ throw new InternalFailureError(
988
+ "ServerTimeout" /* ServerTimeout */,
989
+ `server timeout failure ${JSON.stringify(json)}`,
990
+ { body },
991
+ "retry later. if it still fails, please contact us.",
992
+ "https://docs.fun.xyz"
993
+ );
994
+ } else if (!response.ok) {
995
+ throw new InternalFailureError(
996
+ "UnknownServerError" /* UnknownServerError */,
997
+ `unknown server failure ${JSON.stringify(json)}`,
998
+ { body },
999
+ "retry later. if it still fails, please contact us.",
1000
+ "https://docs.fun.xyz"
1001
+ );
1002
+ }
1003
+ return {};
1004
+ }, finalRetryOptions);
1005
+ } catch (err) {
1006
+ throw new InternalFailureError(
1007
+ "ServerConnectionError" /* ServerConnectionError */,
1008
+ `Cannot connect to Fun API Service ${err}`,
1009
+ { body },
1010
+ "retry later. if it still fails, please contact us.",
1011
+ "https://docs.fun.xyz"
1012
+ );
1013
+ }
1014
+ };
1015
+ async function sendGetRequest({
1016
+ uri,
1017
+ apiKey,
1018
+ retryOptions
1019
+ }) {
1020
+ return await sendRequest({
1021
+ uri,
1022
+ apiKey,
1023
+ retryOptions,
1024
+ method: "GET"
1025
+ });
1026
+ }
1027
+ async function sendPostRequest({
1028
+ uri,
1029
+ body,
1030
+ apiKey,
1031
+ retryOptions
1032
+ }) {
1033
+ return await sendRequest({
1034
+ uri,
1035
+ apiKey,
1036
+ body,
1037
+ retryOptions,
1038
+ method: "POST"
1039
+ });
1040
+ }
1041
+ async function sendDeleteRequest({
1042
+ uri,
1043
+ apiKey,
1044
+ retryOptions
1045
+ }) {
1046
+ await sendRequest({
1047
+ uri,
1048
+ method: "DELETE",
1049
+ apiKey,
1050
+ retryOptions
1051
+ });
1052
+ }
1053
+ async function sendPutRequest({
1054
+ uri,
1055
+ body,
1056
+ apiKey,
1057
+ retryOptions
1058
+ }) {
1059
+ return await sendRequest({
1060
+ uri,
1061
+ apiKey,
1062
+ body,
1063
+ retryOptions,
1064
+ method: "PUT"
1065
+ });
1066
+ }
1067
+
1068
+ // src/services/assets/endpoints.ts
1069
+ async function getAssetPriceInfo({
1070
+ chainId,
1071
+ assetTokenAddress,
1072
+ apiKey
1073
+ }) {
1074
+ const priceInfo = await sendGetRequest({
1075
+ uri: `${API_BASE_URL}/asset/erc20/price/${chainId}/${assetTokenAddress}`,
1076
+ apiKey,
1077
+ retryOptions: { maxAttempts: 2 }
1078
+ });
1079
+ return priceInfo;
1080
+ }
1081
+ async function getAllWalletTokens({
1082
+ walletAddress,
1083
+ onlyVerifiedTokens,
1084
+ apiKey
1085
+ }) {
1086
+ return await sendGetRequest({
1087
+ uri: `${API_BASE_URL}/assets/erc20s/${walletAddress}?onlyVerifiedTokens=${onlyVerifiedTokens}`,
1088
+ apiKey,
1089
+ retryOptions: { maxAttempts: 2 }
1090
+ });
1091
+ }
1092
+ async function getAllWalletTokensByChainId({
1093
+ chainId,
1094
+ walletAddress,
1095
+ onlyVerifiedTokens,
1096
+ apiKey
1097
+ }) {
1098
+ return await sendGetRequest({
1099
+ uri: `${API_BASE_URL}/assets/erc20s/${walletAddress}/${chainId}?onlyVerifiedTokens=${onlyVerifiedTokens}`,
1100
+ apiKey,
1101
+ retryOptions: { maxAttempts: 2 }
1102
+ });
1103
+ }
1104
+ async function getAllWalletNFTs({
1105
+ walletAddress,
1106
+ apiKey
1107
+ }) {
1108
+ return await sendGetRequest({
1109
+ uri: `${API_BASE_URL}/assets/nfts/${walletAddress}`,
1110
+ apiKey
1111
+ });
1112
+ }
1113
+ async function getAllWalletNFTsByChainId({
1114
+ chainId,
1115
+ walletAddress,
1116
+ apiKey
1117
+ }) {
1118
+ return await sendGetRequest({
1119
+ uri: `${API_BASE_URL}/assets/nfts/${walletAddress}/${chainId}`,
1120
+ apiKey
1121
+ });
1122
+ }
1123
+ async function getWalletLidoWithdrawalsByChainId({
1124
+ chainId,
1125
+ walletAddress,
1126
+ apiKey
1127
+ }) {
1128
+ return await sendGetRequest({
1129
+ uri: `${API_BASE_URL}/assets/lido-withdrawals/${walletAddress}/${chainId}`,
1130
+ apiKey
1131
+ });
1132
+ }
1133
+
1134
+ // src/services/checkout/endpoints.ts
1135
+ import Big from "big.js";
1136
+
1137
+ // src/services/checkout/types.ts
1138
+ var CheckoutState = /* @__PURE__ */ ((CheckoutState2) => {
1139
+ CheckoutState2["FROM_UNFUNDED"] = "FROM_UNFUNDED";
1140
+ CheckoutState2["FROM_FUNDED"] = "FROM_FUNDED";
1141
+ CheckoutState2["FROM_POOLED"] = "FROM_POOLED";
1142
+ CheckoutState2["TO_UNFUNDED"] = "TO_UNFUNDED";
1143
+ CheckoutState2["TO_FUNDED"] = "TO_FUNDED";
1144
+ CheckoutState2["TO_POOLED"] = "TO_POOLED";
1145
+ CheckoutState2["TO_READY"] = "TO_READY";
1146
+ CheckoutState2["PENDING_RECEIVAL"] = "PENDING_RECEIVAL";
1147
+ CheckoutState2["COMPLETED"] = "COMPLETED";
1148
+ CheckoutState2["CHECKOUT_ERROR"] = "CHECKOUT_ERROR";
1149
+ CheckoutState2["EXPIRED"] = "EXPIRED";
1150
+ CheckoutState2["CANCELLED"] = "CANCELLED";
1151
+ return CheckoutState2;
1152
+ })(CheckoutState || {});
1153
+
1154
+ // src/services/checkout/endpoints.ts
1155
+ async function getCheckoutQuote({
1156
+ fromChainId,
1157
+ fromTokenAddress,
1158
+ fromTokenDecimals,
1159
+ toChainId,
1160
+ toTokenAddress,
1161
+ toTokenDecimals,
1162
+ toTokenAmount,
1163
+ expirationTimestampMs,
1164
+ sponsorInitialTransferGasLimit,
1165
+ recipientAddr,
1166
+ needsRefuel,
1167
+ userId,
1168
+ apiKey
1169
+ }) {
1170
+ try {
1171
+ const toMultipler = 10 ** toTokenDecimals;
1172
+ const toAmountBaseUnitBI = BigInt(Math.floor(toTokenAmount * toMultipler));
1173
+ const queryParams = {
1174
+ userId,
1175
+ fromChainId,
1176
+ fromTokenAddress,
1177
+ toChainId,
1178
+ toTokenAddress,
1179
+ toAmountBaseUnit: toAmountBaseUnitBI.toString(),
1180
+ // Only pass in recipientAddr if specified
1181
+ ...recipientAddr ? { recipientAddr } : {},
1182
+ // Rounding nearest tenth second (instead of seconds) to better support backend quote caching feature
1183
+ // Reference: https://vintage-heaven-3cd.notion.site/API-Gateway-Caching-and-Pre-Warming-System-Draft-ee7909d9b85f43c793ce7bd2607bec02?pvs=4
1184
+ // Note: Rounding *down* instead of a regular round to safeguard against edge case of timing passing frontend range validation but failing backend range validation
1185
+ checkoutExpirationTimestampSeconds: roundToNearestBottomTenth(
1186
+ Math.round((Date.now() + expirationTimestampMs) / 1e3)
1187
+ ).toString(),
1188
+ sponsorInitialTransferGasLimit,
1189
+ // @deprecated Not in use
1190
+ refuel: needsRefuel.toString()
1191
+ };
1192
+ const searchParams = new URLSearchParams(queryParams);
1193
+ const quoteRes = await sendGetRequest({
1194
+ uri: `${API_BASE_URL}/checkout/quote?${searchParams}`,
1195
+ apiKey
1196
+ });
1197
+ const fromMultipler = 10 ** fromTokenDecimals;
1198
+ return {
1199
+ quoteId: quoteRes.quoteId,
1200
+ fromTokenAddress: quoteRes.fromTokenAddress,
1201
+ estFeesUsd: quoteRes.estFeesUsd,
1202
+ estSubtotalUsd: quoteRes.estSubtotalUsd,
1203
+ estTotalUsd: quoteRes.estTotalUsd,
1204
+ estCheckoutTimeMs: quoteRes.estCheckoutTimeMs,
1205
+ estTotalFromAmountBaseUnit: quoteRes.estTotalFromAmountBaseUnit,
1206
+ estSubtotalFromAmountBaseUnit: quoteRes.estSubtotalFromAmountBaseUnit,
1207
+ estFeesFromAmountBaseUnit: quoteRes.estFeesFromAmountBaseUnit,
1208
+ // Added fields
1209
+ estFeesFromAmount: new Big(quoteRes.estFeesFromAmountBaseUnit).div(fromMultipler).toString(),
1210
+ estSubtotalFromAmount: new Big(quoteRes.estSubtotalFromAmountBaseUnit).div(fromMultipler).toString(),
1211
+ estTotalFromAmount: new Big(quoteRes.estTotalFromAmountBaseUnit).div(fromMultipler).toString()
1212
+ };
1213
+ } catch (err) {
1214
+ throw new Error(
1215
+ `An error occured trying to generate a checkout quote: ${err.message}`
1216
+ );
1217
+ }
1218
+ }
1219
+ async function initializeCheckout({
1220
+ userOp,
1221
+ quoteId,
1222
+ sourceOfFund,
1223
+ apiKey,
1224
+ clientMetadata
1225
+ }) {
1226
+ const body = {
1227
+ ...userOp ? { userOp } : {},
1228
+ quoteId,
1229
+ sourceOfFund,
1230
+ salt: generateRandomCheckoutSalt(),
1231
+ clientMetadata
1232
+ };
1233
+ const res = await sendPostRequest({
1234
+ uri: `${API_BASE_URL}/checkout`,
1235
+ body,
1236
+ apiKey
1237
+ });
1238
+ if (!res?.depositAddr) {
1239
+ throw new ResourceNotFoundError(
1240
+ "CheckoutInitDepositAddrNotFound" /* CheckoutInitDepositAddrNotFound */,
1241
+ "Unable to initialize checkout",
1242
+ body,
1243
+ "",
1244
+ "https://docs.fun.xyz"
1245
+ );
1246
+ }
1247
+ return res.depositAddr;
1248
+ }
1249
+ async function deactivateCheckout({
1250
+ depositAddress,
1251
+ apiKey
1252
+ }) {
1253
+ try {
1254
+ await sendPostRequest({
1255
+ uri: `${API_BASE_URL}/checkout/update/${depositAddress}`,
1256
+ body: {
1257
+ // Fixed state to cancel the checkout
1258
+ state: "CANCELLED" /* CANCELLED */
1259
+ },
1260
+ apiKey
1261
+ });
1262
+ return true;
1263
+ } catch (err) {
1264
+ throw new Error("Unable to deactivate checkout");
1265
+ }
1266
+ }
1267
+ async function getCheckoutByDepositAddress({
1268
+ depositAddress,
1269
+ apiKey
1270
+ }) {
1271
+ try {
1272
+ return await sendGetRequest({
1273
+ uri: `${API_BASE_URL}/checkout/${depositAddress}`,
1274
+ apiKey
1275
+ });
1276
+ } catch (err) {
1277
+ if (err instanceof ResourceNotFoundError) {
1278
+ return null;
1279
+ }
1280
+ throw err;
1281
+ }
1282
+ }
1283
+ async function getCheckoutsByFunWalletAddress({
1284
+ funWalletAddress,
1285
+ apiKey
1286
+ }) {
1287
+ const res = await sendGetRequest({
1288
+ uri: `${API_BASE_URL}/checkout/fun-wallet/${funWalletAddress}`,
1289
+ apiKey
1290
+ });
1291
+ return res || [];
1292
+ }
1293
+ async function getCheckoutsByRecipientAddress({
1294
+ recipientAddress,
1295
+ apiKey
1296
+ }) {
1297
+ const res = await sendGetRequest({
1298
+ uri: `${API_BASE_URL}/checkout/recipient/${recipientAddress}`,
1299
+ apiKey
1300
+ });
1301
+ return res || [];
1302
+ }
1303
+ async function getCheckoutsByUserId({
1304
+ userId,
1305
+ apiKey
1306
+ }) {
1307
+ const res = await sendGetRequest({
1308
+ uri: `${API_BASE_URL}/checkout/userId/${userId}`,
1309
+ apiKey
1310
+ });
1311
+ return res || [];
1312
+ }
1313
+ async function getPaymasterDataForCheckoutSponsoredTransfer({
1314
+ depositAddress,
1315
+ transferUserOp,
1316
+ apiKey
1317
+ }) {
1318
+ const body = {
1319
+ depositAddress,
1320
+ userOp: transferUserOp
1321
+ };
1322
+ const res = await sendPostRequest({
1323
+ uri: `${API_BASE_URL}/checkout/sponsor-transfer`,
1324
+ body,
1325
+ apiKey
1326
+ });
1327
+ if (!res) {
1328
+ throw new Error("Unable to get sponsorship information");
1329
+ }
1330
+ return res;
1331
+ }
1332
+
1333
+ // src/services/faucet/endpoints.ts
1334
+ async function getAssetFromFaucet({
1335
+ token,
1336
+ chain,
1337
+ walletAddress,
1338
+ apiKey
1339
+ }) {
1340
+ return await sendGetRequest({
1341
+ uri: `${FUN_FAUCET_URL}/get-faucet?token=${token}&testnet=${chain}&addr=${walletAddress}`,
1342
+ apiKey
1343
+ });
1344
+ }
1345
+
1346
+ // src/services/mesh/endpoints.ts
1347
+ async function meshGetCryptocurrencyHoldings({
1348
+ authToken,
1349
+ type,
1350
+ apiKey
1351
+ }) {
1352
+ const res = await sendPostRequest({
1353
+ uri: `${API_BASE_URL}/mesh/holdings/get`,
1354
+ body: { authToken, type },
1355
+ apiKey
1356
+ });
1357
+ return res;
1358
+ }
1359
+ async function meshGetTransferIntegrations({
1360
+ apiKey
1361
+ }) {
1362
+ const res = await sendGetRequest({
1363
+ uri: `${API_BASE_URL}/mesh/transfers/managed/integrations`,
1364
+ apiKey
1365
+ });
1366
+ return res;
1367
+ }
1368
+ async function meshGetLinkToken({
1369
+ userId,
1370
+ integrationId,
1371
+ restrictMultipleAccounts,
1372
+ transferOptions,
1373
+ apiKey
1374
+ }) {
1375
+ let body = { userId };
1376
+ if (integrationId) {
1377
+ body = { ...body, integrationId };
1378
+ }
1379
+ if (restrictMultipleAccounts) {
1380
+ body = { ...body, restrictMultipleAccounts };
1381
+ }
1382
+ if (transferOptions) {
1383
+ body = { ...body, transferOptions };
1384
+ }
1385
+ const res = await sendPostRequest({
1386
+ uri: `${API_BASE_URL}/mesh/linktoken`,
1387
+ body,
1388
+ apiKey
1389
+ });
1390
+ return res;
1391
+ }
1392
+ async function meshPreviewTransfer({
1393
+ fromAuthToken,
1394
+ fromType,
1395
+ toAuthToken,
1396
+ toType,
1397
+ networkId,
1398
+ symbol,
1399
+ toAddress,
1400
+ amount,
1401
+ amountInFiat,
1402
+ fiatCurrency,
1403
+ apiKey
1404
+ }) {
1405
+ let body = { fromAuthToken, fromType };
1406
+ if (toAuthToken) {
1407
+ body = { ...body, toAuthToken };
1408
+ }
1409
+ if (toType) {
1410
+ body = { ...body, toType };
1411
+ }
1412
+ if (networkId) {
1413
+ body = { ...body, networkId };
1414
+ }
1415
+ if (symbol) {
1416
+ body = { ...body, symbol };
1417
+ }
1418
+ if (toAddress) {
1419
+ body = { ...body, toAddress };
1420
+ }
1421
+ if (amount) {
1422
+ body = { ...body, amount };
1423
+ }
1424
+ if (amountInFiat) {
1425
+ body = { ...body, amountInFiat };
1426
+ }
1427
+ if (fiatCurrency) {
1428
+ body = { ...body, fiatCurrency };
1429
+ }
1430
+ const res = await sendPostRequest({
1431
+ uri: `${API_BASE_URL}/mesh/transfers/managed/preview`,
1432
+ body,
1433
+ apiKey,
1434
+ retryOptions: { maxAttempts: 1 }
1435
+ });
1436
+ return res;
1437
+ }
1438
+ async function meshExecuteTransfer({
1439
+ fromAuthToken,
1440
+ fromType,
1441
+ previewId,
1442
+ mfaCode,
1443
+ apiKey
1444
+ }) {
1445
+ let body = { fromAuthToken, fromType, previewId };
1446
+ if (mfaCode) {
1447
+ body = { ...body, mfaCode };
1448
+ }
1449
+ const res = await sendPostRequest({
1450
+ uri: `${API_BASE_URL}/mesh/transfers/managed/execute`,
1451
+ body,
1452
+ apiKey
1453
+ });
1454
+ return res;
1455
+ }
1456
+
1457
+ // src/services/mesh/types.ts
1458
+ var MeshExecuteTransferStatus = /* @__PURE__ */ ((MeshExecuteTransferStatus2) => {
1459
+ MeshExecuteTransferStatus2["succeeded"] = "succeeded";
1460
+ MeshExecuteTransferStatus2["failed"] = "failed";
1461
+ MeshExecuteTransferStatus2["mfaRequired"] = "mfaRequired";
1462
+ MeshExecuteTransferStatus2["emailConfirmationRequired"] = "emailConfirmationRequired";
1463
+ MeshExecuteTransferStatus2["deviceConfirmationRequired"] = "deviceConfirmationRequired";
1464
+ MeshExecuteTransferStatus2["mfaFailed"] = "mfaFailed";
1465
+ MeshExecuteTransferStatus2["addressWhitelistRequired"] = "addressWhitelistRequired";
1466
+ MeshExecuteTransferStatus2["secondMfaRequired"] = "secondMfaRequired";
1467
+ return MeshExecuteTransferStatus2;
1468
+ })(MeshExecuteTransferStatus || {});
1469
+ var MeshExecuteTransferMfaType = /* @__PURE__ */ ((MeshExecuteTransferMfaType2) => {
1470
+ MeshExecuteTransferMfaType2["unspecified"] = "unspecified";
1471
+ MeshExecuteTransferMfaType2["phone"] = "phone";
1472
+ MeshExecuteTransferMfaType2["email"] = "email";
1473
+ MeshExecuteTransferMfaType2["otp"] = "otp";
1474
+ return MeshExecuteTransferMfaType2;
1475
+ })(MeshExecuteTransferMfaType || {});
1476
+
1477
+ // src/services/moonpay/endpoints.ts
1478
+ async function getMoonpayUrlSignature({
1479
+ url,
1480
+ isSandbox,
1481
+ apiKey
1482
+ }) {
1483
+ const signature = await sendPostRequest({
1484
+ uri: `${API_BASE_URL}/on-ramp/moonpay-signature/`,
1485
+ body: { url, isSandbox },
1486
+ apiKey
1487
+ });
1488
+ if (!signature || !signature?.url) {
1489
+ throw new InternalFailureError(
1490
+ "UnknownServerError" /* UnknownServerError */,
1491
+ "No onramp url found.",
1492
+ { url },
1493
+ "This is an internal error, please contact support.",
1494
+ "https://docs.fun.xyz"
1495
+ );
1496
+ }
1497
+ return signature.url;
1498
+ }
1499
+ async function getMoonpayBuyQuoteForCreditCard({
1500
+ currencyCode,
1501
+ baseCurrencyCode,
1502
+ quoteCurrencyAmount,
1503
+ baseCurrencyAmount,
1504
+ extraFeePercentage,
1505
+ areFeesIncluded,
1506
+ apiKey
1507
+ }) {
1508
+ const params = new URLSearchParams({
1509
+ currencyCode,
1510
+ baseCurrencyCode,
1511
+ quoteCurrencyAmount,
1512
+ paymentMethod: "credit_debit_card",
1513
+ ...baseCurrencyAmount == null ? {} : { baseCurrencyAmount: baseCurrencyAmount.toString() },
1514
+ ...extraFeePercentage == null ? {} : { extraFeePercentage: extraFeePercentage.toString() },
1515
+ ...areFeesIncluded == null ? {} : { areFeesIncluded: areFeesIncluded.toString() }
1516
+ }).toString();
1517
+ const res = await sendGetRequest({
1518
+ uri: `${API_BASE_URL}/on-ramp/moonpay-buy-quote?${params}`,
1519
+ apiKey,
1520
+ retryOptions: { maxAttempts: 1 }
1521
+ });
1522
+ return res;
1523
+ }
1524
+ async function getMoonpayOnRampUrl({
1525
+ apiKey,
1526
+ walletAddr,
1527
+ currencyCode
1528
+ }) {
1529
+ const endpoint = `on-ramp/${walletAddr}?provider=moonpay`;
1530
+ if (currencyCode) {
1531
+ endpoint.concat(`&currencyCode=${currencyCode}`);
1532
+ }
1533
+ const url = (await sendGetRequest({
1534
+ uri: `${API_BASE_URL}/${endpoint}`,
1535
+ apiKey
1536
+ }))?.url;
1537
+ if (!url) {
1538
+ throw new InternalFailureError(
1539
+ "UnknownServerError" /* UnknownServerError */,
1540
+ "No onramp url found.",
1541
+ { walletAddr },
1542
+ "This is an internal error, please contact support.",
1543
+ "https://docs.fun.xyz"
1544
+ );
1545
+ }
1546
+ return url;
1547
+ }
1548
+ async function getMoonpayOffRampUrl({
1549
+ walletAddr,
1550
+ apiKey
1551
+ }) {
1552
+ const url = (await sendGetRequest({
1553
+ uri: `${API_BASE_URL}/off-ramp/${walletAddr}?provider=moonpay`,
1554
+ apiKey
1555
+ }))?.url;
1556
+ if (!url) {
1557
+ throw new InternalFailureError(
1558
+ "UnknownServerError" /* UnknownServerError */,
1559
+ "No offramp url found.",
1560
+ { walletAddr },
1561
+ "This is an internal error, please contact support.",
1562
+ "https://docs.fun.xyz"
1563
+ );
1564
+ }
1565
+ return url;
1566
+ }
1567
+ async function getMoonpayOnRampSupportedCurrencies({
1568
+ apiKey
1569
+ }) {
1570
+ const currencies = await sendGetRequest({
1571
+ uri: `${API_BASE_URL}/on-ramp/moonpay-currencies`,
1572
+ apiKey
1573
+ });
1574
+ if (!currencies || !currencies.length) {
1575
+ throw new InternalFailureError(
1576
+ "UnknownServerError" /* UnknownServerError */,
1577
+ "No supported currencies found.",
1578
+ {},
1579
+ "This is an internal error, please contact support.",
1580
+ "https://docs.fun.xyz"
1581
+ );
1582
+ }
1583
+ return currencies;
1584
+ }
1585
+
1586
+ // src/services/stripe/endpoints.ts
1587
+ async function getStripeBuyQuote({
1588
+ sourceCurrency,
1589
+ destinationAmount,
1590
+ destinationCurrency,
1591
+ destinationNetwork,
1592
+ isSandbox,
1593
+ apiKey
1594
+ }) {
1595
+ const params = new URLSearchParams({
1596
+ isSandbox: isSandbox.toString(),
1597
+ sourceCurrency,
1598
+ destinationAmount: destinationAmount.toString(),
1599
+ // Only allow one currency in this SDK
1600
+ destinationCurrencies: destinationCurrency,
1601
+ // Only allow one network in this SDK
1602
+ destinationNetworks: destinationNetwork
1603
+ }).toString();
1604
+ const buyQuoteResp = await sendGetRequest({
1605
+ uri: `${API_BASE_URL}/on-ramp/stripe-buy-quote?${params}`,
1606
+ retryOptions: { maxAttempts: 1 },
1607
+ apiKey
1608
+ });
1609
+ return buyQuoteResp;
1610
+ }
1611
+ async function createStripeBuySession({
1612
+ sourceCurrency,
1613
+ destinationAmount,
1614
+ destinationCurrency,
1615
+ destinationNetwork,
1616
+ walletAddress,
1617
+ customerIpAddress,
1618
+ isSandbox,
1619
+ apiKey
1620
+ }) {
1621
+ const body = {
1622
+ isSandbox: isSandbox.toString(),
1623
+ sourceCurrency,
1624
+ destinationAmount: destinationAmount.toString(),
1625
+ // Only allow one currency in this SDK
1626
+ destinationCurrency,
1627
+ destinationCurrencies: [destinationCurrency],
1628
+ // Only allow one network in this SDK
1629
+ destinationNetwork,
1630
+ destinationNetworks: [destinationNetwork],
1631
+ // Only allow one wallet address in this SDK, and it must correspond to the destination network
1632
+ walletAddresses: {
1633
+ [destinationNetwork]: walletAddress
1634
+ },
1635
+ ...customerIpAddress ? { customerIpAddress } : {}
1636
+ };
1637
+ const newBuySessionResp = await sendPostRequest({
1638
+ uri: `${API_BASE_URL}/on-ramp/stripe-checkout`,
1639
+ body,
1640
+ retryOptions: { maxAttempts: 1 },
1641
+ apiKey
1642
+ });
1643
+ return newBuySessionResp;
1644
+ }
1645
+ async function getStripeBuySession({
1646
+ sessionId,
1647
+ apiKey
1648
+ }) {
1649
+ const buySessionResp = await sendGetRequest({
1650
+ uri: `${API_BASE_URL}/on-ramp/stripe-checkout-session/${sessionId}`,
1651
+ retryOptions: { maxAttempts: 1 },
1652
+ apiKey
1653
+ });
1654
+ return buySessionResp;
1655
+ }
1656
+
1657
+ // src/services/support/endpoints.ts
1658
+ async function sendSupportMessage({
1659
+ title,
1660
+ description,
1661
+ userEmail,
1662
+ apiKey
1663
+ }) {
1664
+ try {
1665
+ await sendPostRequest({
1666
+ uri: `${API_BASE_URL}/support/send-message`,
1667
+ body: { title, description, userEmail },
1668
+ apiKey,
1669
+ retryOptions: { maxAttempts: 1 }
1670
+ });
1671
+ return true;
1672
+ } catch (err) {
1673
+ return false;
1674
+ }
1675
+ }
1676
+
1677
+ // src/services/turnkey/endpoints.ts
1678
+ async function createTurnkeySubOrg({
1679
+ createSubOrgRequest,
1680
+ apiKey
1681
+ }) {
1682
+ const res = await sendPostRequest({
1683
+ uri: `${API_BASE_URL}/turnkey/sub-org`,
1684
+ body: createSubOrgRequest,
1685
+ apiKey
1686
+ });
1687
+ return res;
1688
+ }
1689
+ async function createTurnkeyPrivateKey({
1690
+ signedRequest,
1691
+ apiKey
1692
+ }) {
1693
+ const res = await sendPostRequest({
1694
+ uri: `${API_BASE_URL}/turnkey/private-key`,
1695
+ body: signedRequest,
1696
+ apiKey
1697
+ });
1698
+ return {
1699
+ id: res.id,
1700
+ address: res.address
1701
+ };
1702
+ }
1703
+ export {
1704
+ API_BASE_URL,
1705
+ AccessDeniedError,
1706
+ BaseError,
1707
+ CheckoutState,
1708
+ ClientError,
1709
+ DEFAULT_RETRY_OPTIONS,
1710
+ ErrorBaseType,
1711
+ ErrorCode,
1712
+ ErrorType,
1713
+ FUN_FAUCET_URL,
1714
+ InternalFailureError,
1715
+ InvalidActionError,
1716
+ InvalidParameterError,
1717
+ MeshExecuteTransferMfaType,
1718
+ MeshExecuteTransferStatus,
1719
+ ResourceNotFoundError,
1720
+ ServerError,
1721
+ ThrottlingError,
1722
+ UserOpFailureError,
1723
+ createStripeBuySession,
1724
+ createTurnkeyPrivateKey,
1725
+ createTurnkeySubOrg,
1726
+ deactivateCheckout,
1727
+ errorAbortHandler,
1728
+ generateRandomCheckoutSalt,
1729
+ getAllWalletNFTs,
1730
+ getAllWalletNFTsByChainId,
1731
+ getAllWalletTokens,
1732
+ getAllWalletTokensByChainId,
1733
+ getAssetFromFaucet,
1734
+ getAssetPriceInfo,
1735
+ getCheckoutByDepositAddress,
1736
+ getCheckoutQuote,
1737
+ getCheckoutsByFunWalletAddress,
1738
+ getCheckoutsByRecipientAddress,
1739
+ getCheckoutsByUserId,
1740
+ getMoonpayBuyQuoteForCreditCard,
1741
+ getMoonpayOffRampUrl,
1742
+ getMoonpayOnRampSupportedCurrencies,
1743
+ getMoonpayOnRampUrl,
1744
+ getMoonpayUrlSignature,
1745
+ getPaymasterDataForCheckoutSponsoredTransfer,
1746
+ getStripeBuyQuote,
1747
+ getStripeBuySession,
1748
+ getWalletLidoWithdrawalsByChainId,
1749
+ initializeCheckout,
1750
+ meshExecuteTransfer,
1751
+ meshGetCryptocurrencyHoldings,
1752
+ meshGetLinkToken,
1753
+ meshGetTransferIntegrations,
1754
+ meshPreviewTransfer,
1755
+ randomBytes,
1756
+ roundToNearestBottomTenth,
1757
+ sendDeleteRequest,
1758
+ sendGetRequest,
1759
+ sendPostRequest,
1760
+ sendPutRequest,
1761
+ sendRequest,
1762
+ sendSupportMessage
1763
+ };
1764
+ //# sourceMappingURL=index.js.map