@fileverse-dev/formulajs 4.4.11-mod-66 → 4.4.11-mod-67
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/lib/browser/formula.js +1106 -795
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +535 -238
- package/lib/esm/crypto-constants.mjs +41 -51
- package/lib/esm/index.mjs +536 -238
- package/package.json +5 -3
- package/types/cjs/index.d.cts +11 -21
- package/types/esm/index.d.mts +11 -21
package/lib/cjs/index.cjs
CHANGED
|
@@ -13118,15 +13118,19 @@ const SAFE_CHAIN_MAP = {
|
|
|
13118
13118
|
};
|
|
13119
13119
|
|
|
13120
13120
|
const ERROR_MESSAGES_FLAG = {
|
|
13121
|
-
INVALID_API_KEY: '
|
|
13122
|
-
RATE_LIMIT: '
|
|
13123
|
-
DEFAULT: '
|
|
13124
|
-
MISSING_KEY: '
|
|
13125
|
-
INVALID_CHAIN: '
|
|
13126
|
-
INVALID_TYPE: '
|
|
13127
|
-
INVALID_ADDRESS: '
|
|
13128
|
-
INVALID_PARAM: '
|
|
13129
|
-
MAX_PAGE_LIMIT: '
|
|
13121
|
+
INVALID_API_KEY: 'INVALID_API_KEY',
|
|
13122
|
+
RATE_LIMIT: 'RATE_LIMIT',
|
|
13123
|
+
DEFAULT: 'DEFAULT',
|
|
13124
|
+
MISSING_KEY: 'MISSING_KEY',
|
|
13125
|
+
INVALID_CHAIN: 'INVALID_CHAIN',
|
|
13126
|
+
INVALID_TYPE: 'INVALID_TYPE',
|
|
13127
|
+
INVALID_ADDRESS: 'INVALID_ADDRESS',
|
|
13128
|
+
INVALID_PARAM: 'INVALID_PARAM',
|
|
13129
|
+
MAX_PAGE_LIMIT: 'MAX_PAGE_LIMIT',
|
|
13130
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
13131
|
+
ENS: 'ENS',
|
|
13132
|
+
CUSTOM: 'CUSTOM',
|
|
13133
|
+
MISSING_PARAM: 'MISSING_PARAM'
|
|
13130
13134
|
};
|
|
13131
13135
|
|
|
13132
13136
|
const UTILITY = {
|
|
@@ -13134,16 +13138,16 @@ const UTILITY = {
|
|
|
13134
13138
|
};
|
|
13135
13139
|
const MAX_PAGE_LIMIT = 250;
|
|
13136
13140
|
|
|
13137
|
-
const
|
|
13138
|
-
Etherscan: '
|
|
13139
|
-
Coingecko: '
|
|
13140
|
-
Safe: '
|
|
13141
|
-
Basescan: '
|
|
13142
|
-
Gnosisscan: '
|
|
13143
|
-
Firefly: '
|
|
13144
|
-
GnosisPay: '
|
|
13145
|
-
Neynar: '
|
|
13146
|
-
Defillama: '
|
|
13141
|
+
const SERVICES_API_KEY = {
|
|
13142
|
+
Etherscan: 'Etherscan',
|
|
13143
|
+
Coingecko: 'Coingecko',
|
|
13144
|
+
Safe: 'Safe',
|
|
13145
|
+
Basescan: 'Basescan',
|
|
13146
|
+
Gnosisscan: 'Gnosisscan',
|
|
13147
|
+
Firefly: 'Firefly',
|
|
13148
|
+
GnosisPay: 'GnosisPay',
|
|
13149
|
+
Neynar: 'Neynar',
|
|
13150
|
+
Defillama: 'Defillama'
|
|
13147
13151
|
};
|
|
13148
13152
|
|
|
13149
13153
|
const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
|
|
@@ -13156,6 +13160,10 @@ if(!timestamp || !chain || !apiKey) return
|
|
|
13156
13160
|
|
|
13157
13161
|
};
|
|
13158
13162
|
|
|
13163
|
+
var fromTimestampToBlock = {
|
|
13164
|
+
fromTimeStampToBlock
|
|
13165
|
+
};
|
|
13166
|
+
|
|
13159
13167
|
function toTimestamp(dateStr) {
|
|
13160
13168
|
// Expecting format: "DD/MM/YYYY"
|
|
13161
13169
|
const [day, month, year] = dateStr.split("/").map(Number);
|
|
@@ -13167,6 +13175,16 @@ const isAddress = (input) => {
|
|
|
13167
13175
|
return (/^0x[a-fA-F0-9]{40}$/.test(input))
|
|
13168
13176
|
};
|
|
13169
13177
|
|
|
13178
|
+
var isAddress$1 = {
|
|
13179
|
+
isAddress
|
|
13180
|
+
};
|
|
13181
|
+
|
|
13182
|
+
/* global document */
|
|
13183
|
+
/* global window */
|
|
13184
|
+
/* global ethers */
|
|
13185
|
+
|
|
13186
|
+
|
|
13187
|
+
|
|
13170
13188
|
async function fromEnsNameToAddress(name) {
|
|
13171
13189
|
if (typeof ethers === 'undefined') {
|
|
13172
13190
|
await new Promise((resolve, reject) => {
|
|
@@ -13194,33 +13212,170 @@ async function fromEnsNameToAddress(name) {
|
|
|
13194
13212
|
}
|
|
13195
13213
|
}
|
|
13196
13214
|
|
|
13215
|
+
var fromEnsNameToAddress$1 = {
|
|
13216
|
+
fromEnsNameToAddress
|
|
13217
|
+
};
|
|
13218
|
+
|
|
13219
|
+
const errorMessageHandler = (errorFlag, input, functionName) => {
|
|
13220
|
+
if (!functionName) {
|
|
13221
|
+
const stack = new Error().stack?.split('\n')[2];
|
|
13222
|
+
const match = stack?.match(/at (.+?) \(/);
|
|
13223
|
+
const rawFnName = match?.[1];
|
|
13224
|
+
functionName = rawFnName?.split('.').pop() || '[unable to detect function name]';
|
|
13225
|
+
}
|
|
13226
|
+
|
|
13227
|
+
switch (errorFlag) {
|
|
13228
|
+
case ERROR_MESSAGES_FLAG.INVALID_ADDRESS:
|
|
13229
|
+
return {
|
|
13230
|
+
message: `${input} is not a supported address`,
|
|
13231
|
+
functionName,
|
|
13232
|
+
type: errorFlag
|
|
13233
|
+
}
|
|
13234
|
+
|
|
13235
|
+
case ERROR_MESSAGES_FLAG.INVALID_PARAM: {
|
|
13236
|
+
const key = Object.keys(input)[0];
|
|
13237
|
+
const value = input[key];
|
|
13238
|
+
return {
|
|
13239
|
+
message: `${value} is an invalid value for ${key}`,
|
|
13240
|
+
functionName,
|
|
13241
|
+
type: errorFlag
|
|
13242
|
+
}
|
|
13243
|
+
}
|
|
13244
|
+
|
|
13245
|
+
case ERROR_MESSAGES_FLAG.INVALID_CHAIN:
|
|
13246
|
+
return {
|
|
13247
|
+
message: `${input} is not a supported chain for this function `,
|
|
13248
|
+
functionName,
|
|
13249
|
+
type: errorFlag
|
|
13250
|
+
}
|
|
13251
|
+
|
|
13252
|
+
case ERROR_MESSAGES_FLAG.RATE_LIMIT:
|
|
13253
|
+
return {
|
|
13254
|
+
message: `Rate limit for ${input || functionName || 'this api'} has been reached`,
|
|
13255
|
+
functionName,
|
|
13256
|
+
type: errorFlag
|
|
13257
|
+
}
|
|
13258
|
+
|
|
13259
|
+
case ERROR_MESSAGES_FLAG.MISSING_KEY:
|
|
13260
|
+
return {
|
|
13261
|
+
message: `Api key for ${input || functionName || 'this api'} is missing`,
|
|
13262
|
+
functionName,
|
|
13263
|
+
type: errorFlag
|
|
13264
|
+
}
|
|
13265
|
+
|
|
13266
|
+
case ERROR_MESSAGES_FLAG.NETWORK_ERROR:
|
|
13267
|
+
if (input === 429) {
|
|
13268
|
+
return {
|
|
13269
|
+
message: `Rate limit for ${functionName || 'this function'} has been reached`,
|
|
13270
|
+
functionName,
|
|
13271
|
+
type: ERROR_MESSAGES_FLAG.RATE_LIMIT
|
|
13272
|
+
}
|
|
13273
|
+
}
|
|
13274
|
+
return {
|
|
13275
|
+
message: `Api failed with status code ${input}`,
|
|
13276
|
+
functionName,
|
|
13277
|
+
type: errorFlag
|
|
13278
|
+
}
|
|
13279
|
+
|
|
13280
|
+
case ERROR_MESSAGES_FLAG.MISSING_PARAM:
|
|
13281
|
+
return {
|
|
13282
|
+
message: `Missing param: ${input}`,
|
|
13283
|
+
functionName,
|
|
13284
|
+
type: errorFlag
|
|
13285
|
+
}
|
|
13286
|
+
|
|
13287
|
+
case ERROR_MESSAGES_FLAG.ENS:
|
|
13288
|
+
return {
|
|
13289
|
+
message: `${input} is not a supported ens name`,
|
|
13290
|
+
functionName,
|
|
13291
|
+
type: errorFlag
|
|
13292
|
+
}
|
|
13293
|
+
|
|
13294
|
+
case ERROR_MESSAGES_FLAG.CUSTOM:
|
|
13295
|
+
return {
|
|
13296
|
+
message: input.message,
|
|
13297
|
+
functionName,
|
|
13298
|
+
type: errorFlag,
|
|
13299
|
+
reason: input.reason || input.message
|
|
13300
|
+
}
|
|
13301
|
+
|
|
13302
|
+
case ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT:
|
|
13303
|
+
return {
|
|
13304
|
+
message: `Max page limit is ${MAX_PAGE_LIMIT}`,
|
|
13305
|
+
functionName,
|
|
13306
|
+
type: errorFlag
|
|
13307
|
+
}
|
|
13308
|
+
|
|
13309
|
+
case ERROR_MESSAGES_FLAG.INVALID_API_KEY:
|
|
13310
|
+
return {
|
|
13311
|
+
message: `${input}: Invalid API key`,
|
|
13312
|
+
functionName,
|
|
13313
|
+
type: errorFlag
|
|
13314
|
+
}
|
|
13315
|
+
|
|
13316
|
+
default:
|
|
13317
|
+
return {
|
|
13318
|
+
message: 'An unexpected error occured',
|
|
13319
|
+
functionName,
|
|
13320
|
+
type: errorFlag,
|
|
13321
|
+
reason: input
|
|
13322
|
+
}
|
|
13323
|
+
}
|
|
13324
|
+
};
|
|
13325
|
+
|
|
13326
|
+
|
|
13327
|
+
|
|
13328
|
+
|
|
13329
|
+
|
|
13330
|
+
const checkRequiredParams = (inputMap) => {
|
|
13331
|
+
for (const key in inputMap) {
|
|
13332
|
+
if (!inputMap[key]) {
|
|
13333
|
+
const stack = new Error().stack?.split('\n')[2];
|
|
13334
|
+
|
|
13335
|
+
const match = stack?.match(/at (.+?) \(/);
|
|
13336
|
+
const rawFnName = match?.[1];
|
|
13337
|
+
const parentFunctionName = rawFnName?.split('.').pop() || '[unable to detect function name]';
|
|
13338
|
+
|
|
13339
|
+
const paramName = key;
|
|
13340
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_PARAM, paramName, parentFunctionName);
|
|
13341
|
+
}
|
|
13342
|
+
}
|
|
13343
|
+
};
|
|
13344
|
+
|
|
13197
13345
|
async function handleScanRequest({
|
|
13198
|
-
scanKey,
|
|
13199
|
-
baseUrl,
|
|
13200
13346
|
type,
|
|
13201
|
-
chain,
|
|
13202
13347
|
address,
|
|
13203
13348
|
startDate,
|
|
13204
13349
|
endDate,
|
|
13205
13350
|
page = 1,
|
|
13206
|
-
offset = 10
|
|
13351
|
+
offset = 10,
|
|
13352
|
+
apiKey,
|
|
13353
|
+
functionName,
|
|
13354
|
+
chainId,
|
|
13355
|
+
network
|
|
13207
13356
|
}) {
|
|
13208
|
-
const
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
}
|
|
13214
|
-
|
|
13215
|
-
let chainId = CHAIN_ID_MAP[chain?.toLowerCase()];
|
|
13216
|
-
if (!chainId) return `${scanKey}${ERROR_MESSAGES_FLAG.INVALID_CHAIN}`
|
|
13357
|
+
const API_INFO_MAP = {
|
|
13358
|
+
BASE: { url: 'https://api.basescan.org/api', apiKeyName: SERVICES_API_KEY.Basescan },
|
|
13359
|
+
ETHERSCAN: { url: 'https://api.etherscan.io/v2/api', apiKeyName: SERVICES_API_KEY.Etherscan },
|
|
13360
|
+
GNOSIS: { url: 'https://api.gnosisscan.io/api', apiKeyName: SERVICES_API_KEY.Gnosisscan }
|
|
13361
|
+
};
|
|
13217
13362
|
|
|
13218
|
-
if (!isAddress(address)) {
|
|
13219
|
-
|
|
13363
|
+
if (!isAddress$1.isAddress(address)) {
|
|
13364
|
+
const ensName = address;
|
|
13365
|
+
address = await fromEnsNameToAddress$1.fromEnsNameToAddress(address);
|
|
13366
|
+
if (!address) {
|
|
13367
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.ENS, ensName, functionName)
|
|
13368
|
+
}
|
|
13220
13369
|
}
|
|
13221
13370
|
|
|
13222
|
-
|
|
13223
|
-
|
|
13371
|
+
const apiInfo = API_INFO_MAP[functionName];
|
|
13372
|
+
const baseUrl = apiInfo?.url;
|
|
13373
|
+
|
|
13374
|
+
if (!baseUrl) {
|
|
13375
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13376
|
+
message: 'Api not found',
|
|
13377
|
+
reason: ` Api not found for: ${functionName}`
|
|
13378
|
+
}, functionName)
|
|
13224
13379
|
}
|
|
13225
13380
|
|
|
13226
13381
|
const ACTION_MAP = {
|
|
@@ -13231,41 +13386,40 @@ async function handleScanRequest({
|
|
|
13231
13386
|
};
|
|
13232
13387
|
|
|
13233
13388
|
const action = ACTION_MAP[type];
|
|
13234
|
-
if (!action) return
|
|
13235
|
-
|
|
13236
|
-
if (scanKey === SERVICE_API_KEY.Basescan) chainId = 'base';
|
|
13237
|
-
if (scanKey === SERVICE_API_KEY.Gnosisscan) chainId = 'gnosis';
|
|
13389
|
+
if (!action) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { type }, functionName)
|
|
13238
13390
|
|
|
13239
|
-
let url = `${baseUrl}?chainid=${chainId}&module=account&action=${action}&apikey=${
|
|
13391
|
+
let url = `${baseUrl}?chainid=${chainId}&module=account&action=${action}&apikey=${apiKey}`;
|
|
13240
13392
|
|
|
13241
13393
|
if (['all-txns', 'token-txns', 'nft-txns'].includes(type)) {
|
|
13242
|
-
if (!address) return `${scanKey}${ERROR_MESSAGES_FLAG.INVALID_ADDRESS}`
|
|
13243
13394
|
url += `&address=${address}&startblock=0&endblock=99999999&sort=asc`;
|
|
13244
13395
|
|
|
13245
13396
|
if (!isNaN(startDate) && !isNaN(endDate)) {
|
|
13246
13397
|
const [startBlock, endBlock] = await Promise.all([
|
|
13247
|
-
fromTimeStampToBlock(toTimestamp(startDate),
|
|
13248
|
-
fromTimeStampToBlock(toTimestamp(endDate),
|
|
13398
|
+
fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(startDate), network, apiKey),
|
|
13399
|
+
fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(endDate), network, apiKey)
|
|
13249
13400
|
]);
|
|
13250
|
-
url += `&startblock=${startBlock}&endblock=${endBlock}`;
|
|
13401
|
+
url += `&startblock=${startBlock || '0'}&endblock=${endBlock || '99999999'}`;
|
|
13251
13402
|
}
|
|
13252
13403
|
url += `&page=${page}&offset=${offset}`;
|
|
13253
13404
|
}
|
|
13254
13405
|
|
|
13255
13406
|
try {
|
|
13256
13407
|
const res = await fetch(url);
|
|
13257
|
-
if (!res.ok)
|
|
13408
|
+
if (!res.ok) {
|
|
13409
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status, functionName)
|
|
13410
|
+
}
|
|
13258
13411
|
const json = await res.json();
|
|
13259
13412
|
|
|
13260
13413
|
if (typeof json.result === 'string') {
|
|
13261
|
-
if (json.result.includes('Invalid API Key'))
|
|
13262
|
-
|
|
13414
|
+
if (json.result.includes('Invalid API Key'))
|
|
13415
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, apiInfo.apiKeyName, functionName)
|
|
13416
|
+
if (json.result.includes('Max rate limit reached'))
|
|
13417
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.RATE_LIMIT, apiInfo.apiKeyName, functionName)
|
|
13263
13418
|
}
|
|
13264
13419
|
|
|
13265
13420
|
return json.result
|
|
13266
13421
|
} catch (err) {
|
|
13267
|
-
|
|
13268
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
13422
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err, functionName)
|
|
13269
13423
|
}
|
|
13270
13424
|
}
|
|
13271
13425
|
|
|
@@ -13283,6 +13437,9 @@ const fromUsernameToFid = async (username, apiKey) => {
|
|
|
13283
13437
|
const user = users.find(user => user.username === username);
|
|
13284
13438
|
return user && user.fid || null;
|
|
13285
13439
|
};
|
|
13440
|
+
var fromUsernameToFid$1 = {
|
|
13441
|
+
fromUsernameToFid
|
|
13442
|
+
};
|
|
13286
13443
|
|
|
13287
13444
|
// remove nested structure from the response
|
|
13288
13445
|
const removeNestedStructure = (json) => {
|
|
@@ -13297,13 +13454,22 @@ const removeNestedStructure = (json) => {
|
|
|
13297
13454
|
});
|
|
13298
13455
|
};
|
|
13299
13456
|
|
|
13457
|
+
/* global window */
|
|
13458
|
+
|
|
13300
13459
|
async function FIREFLY() {
|
|
13301
13460
|
const [platform, contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13461
|
+
const missingParamsError = checkRequiredParams({ platform, contentType, identifier });
|
|
13462
|
+
|
|
13463
|
+
if (missingParamsError) {
|
|
13464
|
+
return missingParamsError
|
|
13465
|
+
}
|
|
13466
|
+
|
|
13302
13467
|
if (end > MAX_PAGE_LIMIT) {
|
|
13303
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13468
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13304
13469
|
}
|
|
13305
|
-
|
|
13306
|
-
|
|
13470
|
+
|
|
13471
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Firefly);
|
|
13472
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Firefly)
|
|
13307
13473
|
|
|
13308
13474
|
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13309
13475
|
const headers = { 'x-api-key': API_KEY };
|
|
@@ -13319,10 +13485,14 @@ async function FIREFLY() {
|
|
|
13319
13485
|
replies: 'lenspostid'
|
|
13320
13486
|
}
|
|
13321
13487
|
};
|
|
13322
|
-
|
|
13323
|
-
|
|
13324
|
-
|
|
13325
|
-
|
|
13488
|
+
const platformType = typeMap[platform];
|
|
13489
|
+
if (!platformType) {
|
|
13490
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { platform })
|
|
13491
|
+
}
|
|
13492
|
+
const platformContentType = platformType[contentType];
|
|
13493
|
+
if (!platformContentType) {
|
|
13494
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13495
|
+
}
|
|
13326
13496
|
const query = identifier
|
|
13327
13497
|
.split(',')
|
|
13328
13498
|
.map((s) => s.trim())
|
|
@@ -13337,7 +13507,7 @@ async function FIREFLY() {
|
|
|
13337
13507
|
|
|
13338
13508
|
try {
|
|
13339
13509
|
const res = await fetch(url.toString(), { headers });
|
|
13340
|
-
if (!res.ok)
|
|
13510
|
+
if (!res.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13341
13511
|
|
|
13342
13512
|
const json = await res.json();
|
|
13343
13513
|
if (!Array.isArray(json?.data)) return []
|
|
@@ -13353,19 +13523,21 @@ async function FIREFLY() {
|
|
|
13353
13523
|
return flat
|
|
13354
13524
|
})
|
|
13355
13525
|
} catch (err) {
|
|
13356
|
-
|
|
13357
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
13526
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13358
13527
|
}
|
|
13359
13528
|
}
|
|
13360
13529
|
|
|
13361
13530
|
async function LENS() {
|
|
13362
13531
|
const [contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13363
|
-
const
|
|
13364
|
-
if (
|
|
13365
|
-
|
|
13532
|
+
const missingParamsError = checkRequiredParams({ contentType, identifier });
|
|
13533
|
+
if (missingParamsError) {
|
|
13534
|
+
return missingParamsError
|
|
13535
|
+
}
|
|
13366
13536
|
if (end > MAX_PAGE_LIMIT) {
|
|
13367
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13537
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13368
13538
|
}
|
|
13539
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Firefly);
|
|
13540
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Firefly)
|
|
13369
13541
|
|
|
13370
13542
|
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13371
13543
|
const headers = { 'x-api-key': API_KEY };
|
|
@@ -13374,10 +13546,10 @@ async function LENS() {
|
|
|
13374
13546
|
posts: 'lensid',
|
|
13375
13547
|
replies: 'lenspostid'
|
|
13376
13548
|
};
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
|
|
13549
|
+
const platformContentType = typeMap[contentType];
|
|
13550
|
+
if (!platformContentType) {
|
|
13551
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13552
|
+
}
|
|
13381
13553
|
const query = identifier
|
|
13382
13554
|
.split(',')
|
|
13383
13555
|
.map((s) => s.trim())
|
|
@@ -13386,13 +13558,15 @@ async function LENS() {
|
|
|
13386
13558
|
|
|
13387
13559
|
const url = new URL(baseUrl);
|
|
13388
13560
|
url.searchParams.set('query', query);
|
|
13389
|
-
url.searchParams.set('type',
|
|
13561
|
+
url.searchParams.set('type', platformContentType);
|
|
13390
13562
|
url.searchParams.set('start', String(start));
|
|
13391
13563
|
url.searchParams.set('end', String(end));
|
|
13392
13564
|
|
|
13393
13565
|
try {
|
|
13394
13566
|
const res = await fetch(url.toString(), { headers });
|
|
13395
|
-
if (!res.ok)
|
|
13567
|
+
if (!res.ok) {
|
|
13568
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13569
|
+
}
|
|
13396
13570
|
|
|
13397
13571
|
const json = await res.json();
|
|
13398
13572
|
if (!Array.isArray(json?.data)) return []
|
|
@@ -13408,18 +13582,21 @@ async function LENS() {
|
|
|
13408
13582
|
return flat
|
|
13409
13583
|
})
|
|
13410
13584
|
} catch (err) {
|
|
13411
|
-
|
|
13412
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
13585
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13413
13586
|
}
|
|
13414
13587
|
}
|
|
13415
13588
|
|
|
13416
13589
|
async function FARCASTER() {
|
|
13417
13590
|
const [contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13418
|
-
const
|
|
13419
|
-
if (
|
|
13591
|
+
const missingParamsError = checkRequiredParams({ contentType, identifier });
|
|
13592
|
+
if (missingParamsError) {
|
|
13593
|
+
return missingParamsError
|
|
13594
|
+
}
|
|
13420
13595
|
if (end > MAX_PAGE_LIMIT) {
|
|
13421
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13596
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13422
13597
|
}
|
|
13598
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Firefly);
|
|
13599
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Firefly)
|
|
13423
13600
|
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13424
13601
|
const headers = { 'x-api-key': API_KEY };
|
|
13425
13602
|
|
|
@@ -13429,9 +13606,10 @@ async function FARCASTER() {
|
|
|
13429
13606
|
channels: 'farcasterchannels'
|
|
13430
13607
|
};
|
|
13431
13608
|
|
|
13432
|
-
const
|
|
13433
|
-
if (!
|
|
13434
|
-
|
|
13609
|
+
const platformContentType = typeMap[contentType];
|
|
13610
|
+
if (!platformContentType) {
|
|
13611
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13612
|
+
}
|
|
13435
13613
|
const query = identifier
|
|
13436
13614
|
.split(',')
|
|
13437
13615
|
.map((s) => s.trim())
|
|
@@ -13440,13 +13618,13 @@ async function FARCASTER() {
|
|
|
13440
13618
|
|
|
13441
13619
|
const url = new URL(baseUrl);
|
|
13442
13620
|
url.searchParams.set('query', query);
|
|
13443
|
-
url.searchParams.set('type',
|
|
13621
|
+
url.searchParams.set('type', platformContentType);
|
|
13444
13622
|
url.searchParams.set('start', String(start));
|
|
13445
13623
|
url.searchParams.set('end', String(end));
|
|
13446
13624
|
|
|
13447
13625
|
try {
|
|
13448
13626
|
const res = await fetch(url.toString(), { headers });
|
|
13449
|
-
if (!res.ok)
|
|
13627
|
+
if (!res.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13450
13628
|
|
|
13451
13629
|
const json = await res.json();
|
|
13452
13630
|
if (!Array.isArray(json?.data)) return []
|
|
@@ -13462,24 +13640,24 @@ async function FARCASTER() {
|
|
|
13462
13640
|
return flat
|
|
13463
13641
|
})
|
|
13464
13642
|
} catch (err) {
|
|
13465
|
-
|
|
13466
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
13643
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13467
13644
|
}
|
|
13468
13645
|
}
|
|
13469
13646
|
|
|
13470
13647
|
async function BLOCKSCOUT() {
|
|
13471
13648
|
let [address, type, chain, startTimestamp, endTimestamp, page = 1, offset = 10] = argsToArray(arguments);
|
|
13649
|
+
const missingParamsError = checkRequiredParams({ address, type });
|
|
13650
|
+
|
|
13651
|
+
if (missingParamsError) {
|
|
13652
|
+
return missingParamsError
|
|
13653
|
+
}
|
|
13472
13654
|
if (offset > MAX_PAGE_LIMIT) {
|
|
13473
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13655
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13474
13656
|
}
|
|
13475
13657
|
if (!chain) {
|
|
13476
13658
|
chain = 'ethereum';
|
|
13477
13659
|
}
|
|
13478
13660
|
|
|
13479
|
-
if (!type) {
|
|
13480
|
-
return 'TYPE_MISSING'
|
|
13481
|
-
}
|
|
13482
|
-
|
|
13483
13661
|
if (!startTimestamp) {
|
|
13484
13662
|
const currentTimestamp = Date.now();
|
|
13485
13663
|
startTimestamp = currentTimestamp - 30 * 24 * 60 * 60 * 1000;
|
|
@@ -13494,16 +13672,19 @@ async function BLOCKSCOUT() {
|
|
|
13494
13672
|
endTimestamp = toTimestamp(endTimestamp);
|
|
13495
13673
|
}
|
|
13496
13674
|
|
|
13497
|
-
if (!isAddress(address)) {
|
|
13498
|
-
|
|
13675
|
+
if (!isAddress$1.isAddress(address)) {
|
|
13676
|
+
const ensName = address;
|
|
13677
|
+
address = await fromEnsNameToAddress$1.fromEnsNameToAddress(address);
|
|
13678
|
+
if (!address) {
|
|
13679
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.ENS, ensName)
|
|
13680
|
+
}
|
|
13499
13681
|
}
|
|
13682
|
+
const hostname = BLOCKSCOUT_CHAINS_MAP[chain];
|
|
13500
13683
|
|
|
13501
|
-
if (!
|
|
13502
|
-
return
|
|
13684
|
+
if (!hostname) {
|
|
13685
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
13503
13686
|
}
|
|
13504
13687
|
|
|
13505
|
-
const hostname = BLOCKSCOUT_CHAINS_MAP[chain];
|
|
13506
|
-
|
|
13507
13688
|
let requestUrl;
|
|
13508
13689
|
|
|
13509
13690
|
switch (type) {
|
|
@@ -13517,22 +13698,26 @@ async function BLOCKSCOUT() {
|
|
|
13517
13698
|
requestUrl = `${hostname}/api?module=account&action=tokenlist&address=${address}`;
|
|
13518
13699
|
break
|
|
13519
13700
|
default:
|
|
13520
|
-
return
|
|
13701
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { type })
|
|
13521
13702
|
}
|
|
13522
13703
|
try {
|
|
13523
13704
|
const response = await fetch(requestUrl);
|
|
13524
13705
|
|
|
13525
13706
|
if (!response.ok) {
|
|
13526
|
-
|
|
13707
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13527
13708
|
}
|
|
13528
13709
|
const json = await response.json();
|
|
13529
|
-
|
|
13530
|
-
console.log(json);
|
|
13531
13710
|
if (json?.result?.includes('Invalid parameter(s)')) {
|
|
13532
|
-
return
|
|
13711
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13712
|
+
message: 'Invalid parameters',
|
|
13713
|
+
reason: json.result
|
|
13714
|
+
})
|
|
13533
13715
|
}
|
|
13534
13716
|
if (json?.result?.includes('Not found')) {
|
|
13535
|
-
return
|
|
13717
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13718
|
+
message: 'Address information not found',
|
|
13719
|
+
reason: json.result
|
|
13720
|
+
})
|
|
13536
13721
|
}
|
|
13537
13722
|
|
|
13538
13723
|
if (type === 'stat') {
|
|
@@ -13552,52 +13737,75 @@ async function BLOCKSCOUT() {
|
|
|
13552
13737
|
*/
|
|
13553
13738
|
return json.result
|
|
13554
13739
|
} catch (error) {
|
|
13555
|
-
return
|
|
13740
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, error)
|
|
13556
13741
|
}
|
|
13557
13742
|
}
|
|
13558
13743
|
|
|
13559
13744
|
async function BASE() {
|
|
13560
|
-
const [type,
|
|
13745
|
+
const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
|
|
13746
|
+
const missingParamsError = checkRequiredParams({ type, address });
|
|
13747
|
+
|
|
13748
|
+
if (missingParamsError) {
|
|
13749
|
+
return missingParamsError
|
|
13750
|
+
}
|
|
13751
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Basescan);
|
|
13752
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Basescan)
|
|
13753
|
+
if (limit > MAX_PAGE_LIMIT) {
|
|
13754
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13755
|
+
}
|
|
13561
13756
|
return handleScanRequest({
|
|
13562
|
-
scanKey: SERVICE_API_KEY.Basescan,
|
|
13563
|
-
baseUrl: 'https://api.basescan.org/api',
|
|
13564
13757
|
type,
|
|
13565
|
-
chain,
|
|
13566
13758
|
address,
|
|
13567
13759
|
startDate,
|
|
13568
13760
|
endDate,
|
|
13569
13761
|
page,
|
|
13570
|
-
offset: limit
|
|
13762
|
+
offset: limit,
|
|
13763
|
+
apiKey: API_KEY,
|
|
13764
|
+
functionName: 'BASE',
|
|
13765
|
+
chainId: CHAIN_ID_MAP.base,
|
|
13766
|
+
network: 'base'
|
|
13571
13767
|
})
|
|
13572
13768
|
}
|
|
13573
13769
|
async function GNOSIS() {
|
|
13574
|
-
const [type,
|
|
13770
|
+
const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
|
|
13771
|
+
const missingParamsError = checkRequiredParams({ type, address });
|
|
13772
|
+
|
|
13773
|
+
if (missingParamsError) {
|
|
13774
|
+
return missingParamsError
|
|
13775
|
+
}
|
|
13776
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Gnosisscan);
|
|
13777
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Gnosisscan)
|
|
13778
|
+
if (limit > MAX_PAGE_LIMIT) {
|
|
13779
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13780
|
+
}
|
|
13575
13781
|
return handleScanRequest({
|
|
13576
|
-
scanKey: SERVICE_API_KEY.Gnosisscan,
|
|
13577
|
-
baseUrl: 'https://api.gnosisscan.io/api',
|
|
13578
13782
|
type,
|
|
13579
|
-
|
|
13783
|
+
network: 'gnosis',
|
|
13580
13784
|
address,
|
|
13581
13785
|
startDate,
|
|
13582
13786
|
endDate,
|
|
13583
13787
|
page,
|
|
13584
|
-
|
|
13788
|
+
apiKey: API_KEY,
|
|
13789
|
+
offset: limit,
|
|
13790
|
+
chainId: CHAIN_ID_MAP.gnosis,
|
|
13791
|
+
functionName: 'GNOSIS'
|
|
13585
13792
|
})
|
|
13586
13793
|
}
|
|
13587
13794
|
|
|
13588
13795
|
async function NEYNAR() {
|
|
13589
13796
|
const [username] = argsToArray(arguments);
|
|
13590
|
-
const
|
|
13591
|
-
if (!API_KEY) return `${SERVICE_API_KEY.Neynar}${ERROR_MESSAGES_FLAG.MISSING_KEY}`
|
|
13797
|
+
const missingParamsError = checkRequiredParams({ username });
|
|
13592
13798
|
|
|
13593
|
-
if (
|
|
13594
|
-
return
|
|
13799
|
+
if (missingParamsError) {
|
|
13800
|
+
return missingParamsError
|
|
13595
13801
|
}
|
|
13802
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Neynar);
|
|
13803
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Neynar)
|
|
13596
13804
|
|
|
13597
|
-
const fid = await fromUsernameToFid(username, API_KEY);
|
|
13805
|
+
const fid = await fromUsernameToFid$1.fromUsernameToFid(username, API_KEY);
|
|
13598
13806
|
|
|
13599
13807
|
if (!fid) {
|
|
13600
|
-
return
|
|
13808
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { username })
|
|
13601
13809
|
}
|
|
13602
13810
|
|
|
13603
13811
|
const url = `https://api.neynar.com/v2/farcaster/followers?fid=${fid}`;
|
|
@@ -13609,7 +13817,9 @@ async function NEYNAR() {
|
|
|
13609
13817
|
'x-neynar-experimental': 'false'
|
|
13610
13818
|
}
|
|
13611
13819
|
});
|
|
13612
|
-
if (!response.ok)
|
|
13820
|
+
if (!response.ok) {
|
|
13821
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13822
|
+
}
|
|
13613
13823
|
const json = await response.json();
|
|
13614
13824
|
if (!json?.users?.length) return []
|
|
13615
13825
|
|
|
@@ -13621,83 +13831,108 @@ async function NEYNAR() {
|
|
|
13621
13831
|
city: user.profile?.location?.address?.city || ''
|
|
13622
13832
|
}))
|
|
13623
13833
|
} catch (err) {
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13834
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13835
|
+
}
|
|
13836
|
+
}
|
|
13837
|
+
// export async function GNOSISPAY({
|
|
13838
|
+
// cardId,
|
|
13839
|
+
// startDate,
|
|
13840
|
+
// endDate,
|
|
13841
|
+
// limit = 20,
|
|
13842
|
+
// offset = 0,
|
|
13843
|
+
// }) {
|
|
13844
|
+
// const apiKeyKey = SERVICES_API_KEY.GnosisPay
|
|
13845
|
+
// const API_KEY = window.localStorage.getItem(apiKeyKey);
|
|
13846
|
+
// if (!API_KEY) return `${apiKeyKey}${ERROR_MESSAGES_FLAG.MISSING_KEY}`;
|
|
13847
|
+
// if (!cardId) return `${apiKeyKey}${ERROR_MESSAGES_FLAG.INVALID_PARAM}`;
|
|
13848
|
+
// if(limit > MAX_PAGE_LIMIT){
|
|
13849
|
+
// return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13850
|
+
// }
|
|
13640
13851
|
|
|
13641
|
-
|
|
13642
|
-
|
|
13643
|
-
|
|
13852
|
+
// const url = new URL(`https://api.gnosispay.com/cards/${cardId}/transactions`);
|
|
13853
|
+
// url.searchParams.set('limit', limit.toString());
|
|
13854
|
+
// url.searchParams.set('offset', offset.toString());
|
|
13644
13855
|
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13856
|
+
// if (!isNaN(toTimestamp(startDate))) {
|
|
13857
|
+
// url.searchParams.set('startDate', new Date(startDate * 1000).toISOString());
|
|
13858
|
+
// }
|
|
13648
13859
|
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
Authorization: `Bearer ${API_KEY}`,
|
|
13653
|
-
'Content-Type': 'application/json'
|
|
13654
|
-
}
|
|
13655
|
-
});
|
|
13860
|
+
// if (!isNaN(toTimestamp(endDate))) {
|
|
13861
|
+
// url.searchParams.set('endDate', new Date(endDate * 1000).toISOString());
|
|
13862
|
+
// }
|
|
13656
13863
|
|
|
13657
|
-
|
|
13864
|
+
// try {
|
|
13865
|
+
// const res = await fetch(url.toString(), {
|
|
13866
|
+
// headers: {
|
|
13867
|
+
// Authorization: `Bearer ${API_KEY}`,
|
|
13868
|
+
// 'Content-Type': 'application/json',
|
|
13869
|
+
// },
|
|
13870
|
+
// });
|
|
13871
|
+
|
|
13872
|
+
// if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`);
|
|
13873
|
+
|
|
13874
|
+
// const json = await res.json();
|
|
13875
|
+
|
|
13876
|
+
// if (!Array.isArray(json)) return [];
|
|
13877
|
+
|
|
13878
|
+
// return json.map(tx => ({
|
|
13879
|
+
// createdAt: tx.createdAt,
|
|
13880
|
+
// clearedAt: tx.clearedAt,
|
|
13881
|
+
// country: tx.country,
|
|
13882
|
+
// merchant: tx.merchant,
|
|
13883
|
+
// billingAmount: tx.billingAmount,
|
|
13884
|
+
// billingCurrency: tx.billingCurrency,
|
|
13885
|
+
// transactionAmount: tx.transactionAmount,
|
|
13886
|
+
// transactionCurrency: tx.transactionCurrency,
|
|
13887
|
+
// transactionType: tx.transactionType,
|
|
13888
|
+
// kind: tx.kind,
|
|
13889
|
+
// status: tx.status || null,
|
|
13890
|
+
// mcc: tx.mcc,
|
|
13891
|
+
// }));
|
|
13892
|
+
// } catch (err) {
|
|
13893
|
+
// console.error('GNOSISPAY_CARD_TXNS error:', err);
|
|
13894
|
+
// return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13895
|
+
// }
|
|
13896
|
+
// }
|
|
13658
13897
|
|
|
13659
|
-
|
|
13898
|
+
async function ETHERSCAN(...args) {
|
|
13899
|
+
const [type, chain, address, startDate, endDate, page, limit] = args;
|
|
13900
|
+
const missingParamsError = checkRequiredParams({ type, address, chain });
|
|
13660
13901
|
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
return json.map((tx) => ({
|
|
13664
|
-
createdAt: tx.createdAt,
|
|
13665
|
-
clearedAt: tx.clearedAt,
|
|
13666
|
-
country: tx.country,
|
|
13667
|
-
merchant: tx.merchant,
|
|
13668
|
-
billingAmount: tx.billingAmount,
|
|
13669
|
-
billingCurrency: tx.billingCurrency,
|
|
13670
|
-
transactionAmount: tx.transactionAmount,
|
|
13671
|
-
transactionCurrency: tx.transactionCurrency,
|
|
13672
|
-
transactionType: tx.transactionType,
|
|
13673
|
-
kind: tx.kind,
|
|
13674
|
-
status: tx.status || null,
|
|
13675
|
-
mcc: tx.mcc
|
|
13676
|
-
}))
|
|
13677
|
-
} catch (err) {
|
|
13678
|
-
console.error('GNOSISPAY_CARD_TXNS error:', err);
|
|
13679
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
13902
|
+
if (missingParamsError) {
|
|
13903
|
+
return missingParamsError
|
|
13680
13904
|
}
|
|
13681
|
-
}
|
|
13682
13905
|
|
|
13683
|
-
|
|
13684
|
-
|
|
13906
|
+
const chainId = CHAIN_ID_MAP[chain];
|
|
13907
|
+
|
|
13908
|
+
if (!chainId?.toString()) {
|
|
13909
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
13910
|
+
}
|
|
13911
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
|
|
13912
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Etherscan)
|
|
13685
13913
|
return handleScanRequest({
|
|
13686
|
-
scanKey: SERVICE_API_KEY.Etherscan,
|
|
13687
|
-
baseUrl: 'https://api.etherscan.io/v2/api',
|
|
13688
13914
|
type,
|
|
13689
|
-
chain,
|
|
13690
13915
|
address,
|
|
13691
13916
|
startDate,
|
|
13692
13917
|
endDate,
|
|
13693
13918
|
page,
|
|
13694
|
-
offset: limit
|
|
13919
|
+
offset: limit,
|
|
13920
|
+
chainId,
|
|
13921
|
+
network: chain,
|
|
13922
|
+
functionName: 'ETHERSCAN',
|
|
13923
|
+
apiKey: API_KEY
|
|
13695
13924
|
})
|
|
13696
13925
|
}
|
|
13697
13926
|
|
|
13698
|
-
async function COINGECKO(
|
|
13699
|
-
const
|
|
13700
|
-
|
|
13927
|
+
async function COINGECKO() {
|
|
13928
|
+
const [category, param1, param2] = argsToArray(arguments);
|
|
13929
|
+
const missingParamsError = checkRequiredParams({ category, param1 });
|
|
13930
|
+
|
|
13931
|
+
if (missingParamsError) {
|
|
13932
|
+
return missingParamsError
|
|
13933
|
+
}
|
|
13934
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Coingecko);
|
|
13935
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Coingecko)
|
|
13701
13936
|
|
|
13702
13937
|
const headers = {
|
|
13703
13938
|
accept: 'application/json',
|
|
@@ -13705,14 +13940,14 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13705
13940
|
};
|
|
13706
13941
|
|
|
13707
13942
|
let url = '';
|
|
13708
|
-
const lowerCategory = (category || '').toLowerCase();
|
|
13943
|
+
const lowerCategory = (category || '').toLowerCase?.();
|
|
13709
13944
|
|
|
13710
13945
|
switch (lowerCategory) {
|
|
13711
13946
|
case 'price': {
|
|
13712
13947
|
const token = param1;
|
|
13713
13948
|
const vsCurrencies = param2;
|
|
13714
13949
|
if (!token) {
|
|
13715
|
-
return
|
|
13950
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { param1 })
|
|
13716
13951
|
}
|
|
13717
13952
|
url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vsCurrencies ? vsCurrencies : 'usd'}&symbols=${token}`;
|
|
13718
13953
|
break
|
|
@@ -13761,7 +13996,7 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13761
13996
|
}
|
|
13762
13997
|
|
|
13763
13998
|
default:
|
|
13764
|
-
return
|
|
13999
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
13765
14000
|
}
|
|
13766
14001
|
|
|
13767
14002
|
try {
|
|
@@ -13770,12 +14005,10 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13770
14005
|
|
|
13771
14006
|
if (!response.ok) {
|
|
13772
14007
|
const message = json?.status?.error_message || '';
|
|
13773
|
-
if (response.status === 429) {
|
|
13774
|
-
return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
|
|
13775
|
-
}
|
|
13776
14008
|
if (message.includes('API Key Missing')) {
|
|
13777
|
-
return
|
|
14009
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, SERVICES_API_KEY.Coingecko)
|
|
13778
14010
|
}
|
|
14011
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13779
14012
|
}
|
|
13780
14013
|
|
|
13781
14014
|
if (lowerCategory === 'price') {
|
|
@@ -13828,18 +14061,27 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13828
14061
|
return flat
|
|
13829
14062
|
})
|
|
13830
14063
|
} catch (error) {
|
|
13831
|
-
|
|
13832
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
14064
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, error)
|
|
13833
14065
|
}
|
|
13834
14066
|
}
|
|
13835
14067
|
|
|
13836
14068
|
async function EOA() {
|
|
13837
|
-
const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
|
|
13838
|
-
if (!API_KEY) return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.MISSING_KEY}`
|
|
13839
14069
|
let [addresses, category, chains, startTime, endTime, page = 1, offset = 10] = argsToArray(arguments);
|
|
14070
|
+
|
|
14071
|
+
const optionalParams = category === 'balance' ? {} : {startTime, endTime};
|
|
14072
|
+
|
|
14073
|
+
const missingParamsError = checkRequiredParams({ addresses, category, chains, ...optionalParams });
|
|
14074
|
+
|
|
14075
|
+
if (missingParamsError) {
|
|
14076
|
+
return missingParamsError
|
|
14077
|
+
}
|
|
14078
|
+
|
|
13840
14079
|
if (offset > MAX_PAGE_LIMIT) {
|
|
13841
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
14080
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13842
14081
|
}
|
|
14082
|
+
|
|
14083
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
|
|
14084
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Etherscan)
|
|
13843
14085
|
const INPUTS = addresses
|
|
13844
14086
|
.split(',')
|
|
13845
14087
|
.map((a) => a.trim())
|
|
@@ -13852,21 +14094,21 @@ async function EOA() {
|
|
|
13852
14094
|
// Map: finalAddress => ENS name (if applicable)
|
|
13853
14095
|
const ADDRESS_MAP = {};
|
|
13854
14096
|
for (const input of INPUTS) {
|
|
13855
|
-
if (isAddress(input)) {
|
|
14097
|
+
if (isAddress$1.isAddress(input)) {
|
|
13856
14098
|
ADDRESS_MAP[input.toLowerCase()] = null; // it's a direct address
|
|
13857
14099
|
} else {
|
|
13858
14100
|
try {
|
|
13859
|
-
const resolved = await fromEnsNameToAddress(input); // ENS -> address
|
|
14101
|
+
const resolved = await fromEnsNameToAddress$1.fromEnsNameToAddress(input); // ENS -> address
|
|
13860
14102
|
if (resolved) ADDRESS_MAP[resolved.toLowerCase()] = input;
|
|
13861
14103
|
} catch {
|
|
13862
|
-
return
|
|
14104
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { addresses })
|
|
13863
14105
|
}
|
|
13864
14106
|
}
|
|
13865
14107
|
}
|
|
13866
14108
|
const ADDRS = Object.keys(ADDRESS_MAP);
|
|
13867
14109
|
for (const chain of CHAINS) {
|
|
13868
14110
|
const chainId = CHAIN_ID_MAP[chain];
|
|
13869
|
-
if (!chainId) return ERROR_MESSAGES_FLAG.
|
|
14111
|
+
if (!chainId) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
13870
14112
|
if (category === 'balance') {
|
|
13871
14113
|
for (let i = 0; i < ADDRS.length; i += 20) {
|
|
13872
14114
|
const slice = ADDRS.slice(i, i + 20).join(',');
|
|
@@ -13875,8 +14117,8 @@ async function EOA() {
|
|
|
13875
14117
|
`https://api.etherscan.io/v2/api?chainid=${chainId}` +
|
|
13876
14118
|
`&module=account&action=${action}&address=${slice}` +
|
|
13877
14119
|
`&page=${page}&offset=100&apikey=${API_KEY}`;
|
|
13878
|
-
const data = await fetchJSON(url);
|
|
13879
|
-
if (
|
|
14120
|
+
const data = await fetchJSON(url, 'EOA');
|
|
14121
|
+
if (!Array.isArray(data)) return data
|
|
13880
14122
|
data.forEach((tx) =>
|
|
13881
14123
|
out.push({
|
|
13882
14124
|
chain,
|
|
@@ -13889,16 +14131,22 @@ async function EOA() {
|
|
|
13889
14131
|
continue
|
|
13890
14132
|
}
|
|
13891
14133
|
if (category === 'txns') {
|
|
13892
|
-
const startBlock = await fromTimeStampToBlock(toTimestamp(startTime), chain, API_KEY);
|
|
13893
|
-
const endBlock = await fromTimeStampToBlock(toTimestamp(endTime), chain, API_KEY);
|
|
14134
|
+
const startBlock = await fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(startTime), chain, API_KEY);
|
|
14135
|
+
const endBlock = await fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(endTime), chain, API_KEY);
|
|
14136
|
+
if (!startBlock?.toString()) {
|
|
14137
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { startTime })
|
|
14138
|
+
}
|
|
14139
|
+
if (!endBlock?.toString()) {
|
|
14140
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { endTime })
|
|
14141
|
+
}
|
|
13894
14142
|
for (const addr of ADDRS) {
|
|
13895
14143
|
const url =
|
|
13896
14144
|
`https://api.etherscan.io/v2/api?chainid=${chainId}` +
|
|
13897
14145
|
`&module=account&action=tokentx&address=${addr}` +
|
|
13898
14146
|
`&startblock=${startBlock}&endblock=${endBlock}` +
|
|
13899
14147
|
`&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
|
|
13900
|
-
const data = await fetchJSON(url);
|
|
13901
|
-
if (
|
|
14148
|
+
const data = await fetchJSON(url, 'EOA');
|
|
14149
|
+
if (!Array.isArray(data)) return data
|
|
13902
14150
|
data.forEach((tx) =>
|
|
13903
14151
|
out.push({
|
|
13904
14152
|
chain,
|
|
@@ -13910,29 +14158,35 @@ async function EOA() {
|
|
|
13910
14158
|
}
|
|
13911
14159
|
continue
|
|
13912
14160
|
}
|
|
13913
|
-
return ERROR_MESSAGES_FLAG.
|
|
14161
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
13914
14162
|
}
|
|
13915
14163
|
|
|
13916
14164
|
return out
|
|
13917
14165
|
|
|
13918
|
-
async function fetchJSON(url) {
|
|
14166
|
+
async function fetchJSON(url, fnName) {
|
|
13919
14167
|
try {
|
|
13920
14168
|
const res = await fetch(url);
|
|
13921
|
-
if (!res.ok)
|
|
14169
|
+
if (!res.ok) {
|
|
14170
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status, fnName)
|
|
14171
|
+
}
|
|
13922
14172
|
|
|
13923
14173
|
const json = await res.json();
|
|
13924
14174
|
|
|
13925
14175
|
if (json.result?.includes?.('Invalid API Key'))
|
|
13926
|
-
return
|
|
14176
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, SERVICES_API_KEY.Etherscan, fnName)
|
|
13927
14177
|
|
|
13928
14178
|
if (json.result?.includes?.('Max rate limit reached'))
|
|
13929
|
-
return
|
|
14179
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.RATE_LIMIT, SERVICES_API_KEY.Etherscan, fnName)
|
|
13930
14180
|
|
|
13931
|
-
if (json.status === '0' && json.message !== 'No transactions found')
|
|
14181
|
+
if (json.status === '0' && json.message !== 'No transactions found')
|
|
14182
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
14183
|
+
message: 'Api Error',
|
|
14184
|
+
reason: json?.result || 'json.status === "0" && json.message !== "No transactions found"'
|
|
14185
|
+
}, fnName)
|
|
13932
14186
|
|
|
13933
14187
|
return json.result
|
|
13934
|
-
} catch {
|
|
13935
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
14188
|
+
} catch (err) {
|
|
14189
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err, fnName)
|
|
13936
14190
|
}
|
|
13937
14191
|
}
|
|
13938
14192
|
}
|
|
@@ -13948,25 +14202,38 @@ async function FLVURL(token, vs_currencies) {
|
|
|
13948
14202
|
async function SAFE() {
|
|
13949
14203
|
let [address, utility, chain, limit = 10, offset = 0] = argsToArray(arguments);
|
|
13950
14204
|
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
if (
|
|
13954
|
-
|
|
13955
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
14205
|
+
const missingParamsError = checkRequiredParams({ address, utility, chain });
|
|
14206
|
+
|
|
14207
|
+
if (missingParamsError) {
|
|
14208
|
+
return missingParamsError
|
|
13956
14209
|
}
|
|
13957
14210
|
|
|
13958
|
-
|
|
13959
|
-
|
|
14211
|
+
if (offset > MAX_PAGE_LIMIT) {
|
|
14212
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
14213
|
+
}
|
|
14214
|
+
|
|
14215
|
+
const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Safe);
|
|
13960
14216
|
|
|
13961
|
-
if (!apiKey) return
|
|
13962
|
-
if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED'
|
|
14217
|
+
if (!apiKey) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Safe)
|
|
13963
14218
|
|
|
13964
|
-
if (
|
|
13965
|
-
|
|
14219
|
+
if (typeof limit !== 'number' || limit < 0) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { limit })
|
|
14220
|
+
if (typeof offset !== 'number' || offset < 0)
|
|
14221
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { offset })
|
|
14222
|
+
if (utility !== 'txns') return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { utility })
|
|
14223
|
+
if (limit > MAX_PAGE_LIMIT) {
|
|
14224
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13966
14225
|
}
|
|
13967
14226
|
|
|
13968
|
-
|
|
13969
|
-
|
|
14227
|
+
const chainIdentifier = SAFE_CHAIN_MAP[chain];
|
|
14228
|
+
|
|
14229
|
+
if (!chainIdentifier) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
14230
|
+
|
|
14231
|
+
if (!isAddress$1.isAddress(address)) {
|
|
14232
|
+
const ensName = address;
|
|
14233
|
+
address = await fromEnsNameToAddress$1.fromEnsNameToAddress(address);
|
|
14234
|
+
if (!address) {
|
|
14235
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.ENS, ensName)
|
|
14236
|
+
}
|
|
13970
14237
|
}
|
|
13971
14238
|
|
|
13972
14239
|
const url = `https://api.safe.global/tx-service/${chainIdentifier}/api/v2/safes/${address}/multisig-transactions?limit=${limit}&offset=${offset}`;
|
|
@@ -13976,23 +14243,29 @@ async function SAFE() {
|
|
|
13976
14243
|
Authorization: `Bearer ${apiKey}`
|
|
13977
14244
|
}
|
|
13978
14245
|
});
|
|
13979
|
-
if (!response.ok)
|
|
14246
|
+
if (!response.ok) {
|
|
14247
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
14248
|
+
}
|
|
13980
14249
|
const json = await response.json();
|
|
13981
14250
|
if (!Array.isArray(json.results)) {
|
|
13982
|
-
return '
|
|
14251
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, { message: 'Invalid API response' })
|
|
13983
14252
|
}
|
|
13984
14253
|
// remove nested structure from the response
|
|
13985
14254
|
return json.results.map(({ confirmations, dataDecoded, ...rest }) => rest)
|
|
13986
14255
|
} catch (e) {
|
|
13987
|
-
|
|
13988
|
-
return 'ERROR IN FETCHING'
|
|
14256
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, e)
|
|
13989
14257
|
}
|
|
13990
14258
|
}
|
|
13991
14259
|
|
|
13992
14260
|
async function DEFILLAMA() {
|
|
13993
14261
|
let [category] = argsToArray(arguments);
|
|
13994
|
-
const
|
|
13995
|
-
|
|
14262
|
+
const missingParamsError = checkRequiredParams({ category });
|
|
14263
|
+
|
|
14264
|
+
if (missingParamsError) {
|
|
14265
|
+
return missingParamsError
|
|
14266
|
+
}
|
|
14267
|
+
const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Defillama);
|
|
14268
|
+
if (!apiKey) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Defillama)
|
|
13996
14269
|
const categoryList = ['protocols', 'yields', 'dex', 'fees'];
|
|
13997
14270
|
const categoryMap = {
|
|
13998
14271
|
[categoryList[0]]: 'https://api.llama.fi/protocols',
|
|
@@ -14004,9 +14277,13 @@ async function DEFILLAMA() {
|
|
|
14004
14277
|
};
|
|
14005
14278
|
let url = categoryMap[category];
|
|
14006
14279
|
|
|
14280
|
+
if (!url) {
|
|
14281
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
14282
|
+
}
|
|
14283
|
+
|
|
14007
14284
|
try {
|
|
14008
14285
|
const response = await fetch(url);
|
|
14009
|
-
if (!response.ok)
|
|
14286
|
+
if (!response.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
14010
14287
|
let json = await response.json();
|
|
14011
14288
|
switch (category) {
|
|
14012
14289
|
case categoryList[0]: {
|
|
@@ -14031,38 +14308,59 @@ async function DEFILLAMA() {
|
|
|
14031
14308
|
|
|
14032
14309
|
return removeNestedStructure(Array.isArray(json) ? json : [json])
|
|
14033
14310
|
} catch (e) {
|
|
14034
|
-
|
|
14035
|
-
return 'ERROR IN FETCHING'
|
|
14311
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, e)
|
|
14036
14312
|
}
|
|
14037
14313
|
}
|
|
14038
14314
|
|
|
14039
14315
|
async function UNISWAP() {
|
|
14040
14316
|
const [graphType, category, param1, param2] = argsToArray(arguments);
|
|
14317
|
+
const missingParamsError = checkRequiredParams({ graphType, category, param1 });
|
|
14318
|
+
|
|
14319
|
+
if (missingParamsError) {
|
|
14320
|
+
return missingParamsError
|
|
14321
|
+
}
|
|
14041
14322
|
const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
|
|
14042
14323
|
try {
|
|
14043
14324
|
const url = `${baseUrl}?service=uniswap&graphType=${graphType}&category=${category}&input1=${param1}&input2=${param2}`;
|
|
14044
14325
|
const res = await fetch(url);
|
|
14045
|
-
if (!res.ok)
|
|
14326
|
+
if (!res.ok) {
|
|
14327
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
14328
|
+
}
|
|
14046
14329
|
const json = await res.json();
|
|
14047
|
-
|
|
14330
|
+
if(Array.isArray(json)){
|
|
14331
|
+
return removeNestedStructure(json)
|
|
14332
|
+
} else {
|
|
14333
|
+
return json
|
|
14334
|
+
}
|
|
14335
|
+
|
|
14048
14336
|
} catch (err) {
|
|
14049
|
-
|
|
14050
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
14337
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
14051
14338
|
}
|
|
14052
14339
|
}
|
|
14053
14340
|
|
|
14054
14341
|
async function AAVE() {
|
|
14055
14342
|
const [graphType, category, param1, param2] = argsToArray(arguments);
|
|
14343
|
+
const missingParamsError = checkRequiredParams({ graphType, category, param1 });
|
|
14344
|
+
|
|
14345
|
+
if (missingParamsError) {
|
|
14346
|
+
return missingParamsError
|
|
14347
|
+
}
|
|
14056
14348
|
const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
|
|
14057
14349
|
try {
|
|
14058
14350
|
const url = `${baseUrl}?service=aave&graphType=${graphType}&category=${category}&input1=${param1}&input2=${param2}`;
|
|
14059
14351
|
const res = await fetch(url);
|
|
14060
|
-
if (!res.ok)
|
|
14352
|
+
if (!res.ok) {
|
|
14353
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
14354
|
+
}
|
|
14061
14355
|
const json = await res.json();
|
|
14062
|
-
|
|
14356
|
+
if(Array.isArray(json)){
|
|
14357
|
+
return removeNestedStructure(json)
|
|
14358
|
+
} else {
|
|
14359
|
+
return json
|
|
14360
|
+
}
|
|
14361
|
+
|
|
14063
14362
|
} catch (err) {
|
|
14064
|
-
|
|
14065
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
14363
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
14066
14364
|
}
|
|
14067
14365
|
}
|
|
14068
14366
|
|
|
@@ -14259,7 +14557,6 @@ exports.GCD = GCD;
|
|
|
14259
14557
|
exports.GEOMEAN = GEOMEAN;
|
|
14260
14558
|
exports.GESTEP = GESTEP;
|
|
14261
14559
|
exports.GNOSIS = GNOSIS;
|
|
14262
|
-
exports.GNOSISPAY = GNOSISPAY;
|
|
14263
14560
|
exports.GROWTH = GROWTH;
|
|
14264
14561
|
exports.HARMEAN = HARMEAN;
|
|
14265
14562
|
exports.HEX2BIN = HEX2BIN;
|