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