@fileverse-dev/formulajs 4.4.11-mod-63 → 4.4.11-mod-64-patch-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/formula.js +1103 -795
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +688 -423
- package/lib/esm/crypto-constants.mjs +41 -51
- package/lib/esm/index.mjs +689 -423
- 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
|
@@ -13098,15 +13098,19 @@ const SAFE_CHAIN_MAP = {
|
|
|
13098
13098
|
};
|
|
13099
13099
|
|
|
13100
13100
|
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: '
|
|
13101
|
+
INVALID_API_KEY: 'INVALID_API_KEY',
|
|
13102
|
+
RATE_LIMIT: 'RATE_LIMIT',
|
|
13103
|
+
DEFAULT: 'DEFAULT',
|
|
13104
|
+
MISSING_KEY: 'MISSING_KEY',
|
|
13105
|
+
INVALID_CHAIN: 'INVALID_CHAIN',
|
|
13106
|
+
INVALID_TYPE: 'INVALID_TYPE',
|
|
13107
|
+
INVALID_ADDRESS: 'INVALID_ADDRESS',
|
|
13108
|
+
INVALID_PARAM: 'INVALID_PARAM',
|
|
13109
|
+
MAX_PAGE_LIMIT: 'MAX_PAGE_LIMIT',
|
|
13110
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
13111
|
+
ENS: 'ENS',
|
|
13112
|
+
CUSTOM: 'CUSTOM',
|
|
13113
|
+
MISSING_PARAM: 'MISSING_PARAM'
|
|
13110
13114
|
};
|
|
13111
13115
|
|
|
13112
13116
|
const UTILITY = {
|
|
@@ -13114,16 +13118,16 @@ const UTILITY = {
|
|
|
13114
13118
|
};
|
|
13115
13119
|
const MAX_PAGE_LIMIT = 250;
|
|
13116
13120
|
|
|
13117
|
-
const
|
|
13118
|
-
Etherscan:
|
|
13119
|
-
Coingecko:
|
|
13120
|
-
Safe:
|
|
13121
|
-
Basescan:
|
|
13122
|
-
Gnosisscan:
|
|
13123
|
-
Firefly:
|
|
13124
|
-
GnosisPay: '
|
|
13125
|
-
Neynar: '
|
|
13126
|
-
Defillama: '
|
|
13121
|
+
const SERVICES_API_KEY = {
|
|
13122
|
+
Etherscan: 'Etherscan',
|
|
13123
|
+
Coingecko: 'Coingecko',
|
|
13124
|
+
Safe: 'Safe',
|
|
13125
|
+
Basescan: 'Basescan',
|
|
13126
|
+
Gnosisscan: 'Gnosisscan',
|
|
13127
|
+
Firefly: 'Firefly',
|
|
13128
|
+
GnosisPay: 'GnosisPay',
|
|
13129
|
+
Neynar: 'Neynar',
|
|
13130
|
+
Defillama: 'Defillama'
|
|
13127
13131
|
};
|
|
13128
13132
|
|
|
13129
13133
|
const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
|
|
@@ -13136,6 +13140,10 @@ if(!timestamp || !chain || !apiKey) return
|
|
|
13136
13140
|
|
|
13137
13141
|
};
|
|
13138
13142
|
|
|
13143
|
+
var fromTimestampToBlock = {
|
|
13144
|
+
fromTimeStampToBlock
|
|
13145
|
+
};
|
|
13146
|
+
|
|
13139
13147
|
function toTimestamp(dateStr) {
|
|
13140
13148
|
// Expecting format: "DD/MM/YYYY"
|
|
13141
13149
|
const [day, month, year] = dateStr.split("/").map(Number);
|
|
@@ -13147,11 +13155,21 @@ const isAddress = (input) => {
|
|
|
13147
13155
|
return (/^0x[a-fA-F0-9]{40}$/.test(input))
|
|
13148
13156
|
};
|
|
13149
13157
|
|
|
13158
|
+
var isAddress$1 = {
|
|
13159
|
+
isAddress
|
|
13160
|
+
};
|
|
13161
|
+
|
|
13162
|
+
/* global document */
|
|
13163
|
+
/* global window */
|
|
13164
|
+
/* global ethers */
|
|
13165
|
+
|
|
13166
|
+
|
|
13167
|
+
|
|
13150
13168
|
async function fromEnsNameToAddress(name) {
|
|
13151
|
-
if (typeof ethers ===
|
|
13169
|
+
if (typeof ethers === 'undefined') {
|
|
13152
13170
|
await new Promise((resolve, reject) => {
|
|
13153
|
-
const script = document.createElement(
|
|
13154
|
-
script.src =
|
|
13171
|
+
const script = document.createElement('script');
|
|
13172
|
+
script.src = 'https://cdn.jsdelivr.net/npm/ethers@6.10.0/dist/ethers.umd.min.js';
|
|
13155
13173
|
script.onload = resolve;
|
|
13156
13174
|
script.onerror = reject;
|
|
13157
13175
|
document.head.appendChild(script);
|
|
@@ -13159,94 +13177,225 @@ async function fromEnsNameToAddress(name) {
|
|
|
13159
13177
|
}
|
|
13160
13178
|
|
|
13161
13179
|
const ALCHEMY_KEY = window.localStorage.getItem(UTILITY.ALCHEMY_API_KEY);
|
|
13162
|
-
if(!ALCHEMY_KEY){
|
|
13163
|
-
console.error(
|
|
13180
|
+
if (!ALCHEMY_KEY) {
|
|
13181
|
+
console.error('alchemy api key missing');
|
|
13164
13182
|
return null
|
|
13165
13183
|
}
|
|
13166
|
-
const provider = new ethers.AlchemyProvider(
|
|
13184
|
+
const provider = new ethers.AlchemyProvider('mainnet', ALCHEMY_KEY);
|
|
13167
13185
|
|
|
13168
13186
|
try {
|
|
13169
13187
|
const resolved = await provider.resolveName(name); // ENS ➝ address
|
|
13170
|
-
return resolved || null
|
|
13188
|
+
return resolved || null
|
|
13171
13189
|
} catch (err) {
|
|
13172
|
-
console.error(
|
|
13173
|
-
return null
|
|
13190
|
+
console.error('ENS resolution failed:', err.message);
|
|
13191
|
+
return null
|
|
13174
13192
|
}
|
|
13175
13193
|
}
|
|
13176
13194
|
|
|
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
|
+
|
|
13177
13321
|
async function handleScanRequest({
|
|
13178
|
-
scanKey,
|
|
13179
|
-
baseUrl,
|
|
13180
13322
|
type,
|
|
13181
|
-
chain,
|
|
13182
13323
|
address,
|
|
13183
13324
|
startDate,
|
|
13184
13325
|
endDate,
|
|
13185
13326
|
page = 1,
|
|
13186
13327
|
offset = 10,
|
|
13328
|
+
apiKey,
|
|
13329
|
+
functionName,
|
|
13330
|
+
chainId,
|
|
13331
|
+
network
|
|
13187
13332
|
}) {
|
|
13188
|
-
const
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
}
|
|
13194
|
-
|
|
13195
|
-
let chainId = CHAIN_ID_MAP[chain?.toLowerCase()];
|
|
13196
|
-
if (!chainId) return `${scanKey}${ERROR_MESSAGES_FLAG.INVALID_CHAIN}`;
|
|
13333
|
+
const API_INFO_MAP = {
|
|
13334
|
+
BASE: { url: 'https://api.basescan.org/api', apiKeyName: SERVICES_API_KEY.Basescan },
|
|
13335
|
+
ETHERSCAN: { url: 'https://api.etherscan.io/v2/api', apiKeyName: SERVICES_API_KEY.Etherscan },
|
|
13336
|
+
GNOSIS: { url: 'https://api.gnosisscan.io/api', apiKeyName: SERVICES_API_KEY.Gnosisscan }
|
|
13337
|
+
};
|
|
13197
13338
|
|
|
13198
|
-
if(!isAddress(address)){
|
|
13199
|
-
|
|
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
|
+
}
|
|
13200
13345
|
}
|
|
13201
13346
|
|
|
13202
|
-
|
|
13203
|
-
|
|
13347
|
+
const apiInfo = API_INFO_MAP[functionName];
|
|
13348
|
+
const baseUrl = apiInfo?.url;
|
|
13349
|
+
|
|
13350
|
+
if (!baseUrl) {
|
|
13351
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13352
|
+
message: 'Api not found',
|
|
13353
|
+
reason: ` Api not found for: ${functionName}`
|
|
13354
|
+
}, functionName)
|
|
13204
13355
|
}
|
|
13205
13356
|
|
|
13206
13357
|
const ACTION_MAP = {
|
|
13207
13358
|
'all-txns': 'txlist',
|
|
13208
13359
|
'token-txns': 'tokentx',
|
|
13209
13360
|
'nft-txns': 'tokennfttx',
|
|
13210
|
-
|
|
13361
|
+
gas: 'gastracker'
|
|
13211
13362
|
};
|
|
13212
13363
|
|
|
13213
13364
|
const action = ACTION_MAP[type];
|
|
13214
|
-
if (!action) return
|
|
13215
|
-
|
|
13216
|
-
|
|
13217
|
-
if (scanKey === SERVICE_API_KEY.Basescan) chainId = 'base';
|
|
13218
|
-
if (scanKey === SERVICE_API_KEY.Gnosisscan) chainId = 'gnosis';
|
|
13365
|
+
if (!action) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { type }, functionName)
|
|
13219
13366
|
|
|
13220
|
-
let url = `${baseUrl}?chainid=${chainId}&module=account&action=${action}&apikey=${
|
|
13367
|
+
let url = `${baseUrl}?chainid=${chainId}&module=account&action=${action}&apikey=${apiKey}`;
|
|
13221
13368
|
|
|
13222
13369
|
if (['all-txns', 'token-txns', 'nft-txns'].includes(type)) {
|
|
13223
|
-
if (!address) return `${scanKey}${ERROR_MESSAGES_FLAG.INVALID_ADDRESS}`;
|
|
13224
13370
|
url += `&address=${address}&startblock=0&endblock=99999999&sort=asc`;
|
|
13225
13371
|
|
|
13226
13372
|
if (!isNaN(startDate) && !isNaN(endDate)) {
|
|
13227
13373
|
const [startBlock, endBlock] = await Promise.all([
|
|
13228
|
-
fromTimeStampToBlock(toTimestamp(startDate),
|
|
13229
|
-
fromTimeStampToBlock(toTimestamp(endDate),
|
|
13374
|
+
fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(startDate), network, apiKey),
|
|
13375
|
+
fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(endDate), network, apiKey)
|
|
13230
13376
|
]);
|
|
13231
|
-
url += `&startblock=${startBlock}&endblock=${endBlock}`;
|
|
13377
|
+
url += `&startblock=${startBlock || '0'}&endblock=${endBlock || '99999999'}`;
|
|
13232
13378
|
}
|
|
13233
13379
|
url += `&page=${page}&offset=${offset}`;
|
|
13234
13380
|
}
|
|
13235
13381
|
|
|
13236
13382
|
try {
|
|
13237
13383
|
const res = await fetch(url);
|
|
13238
|
-
if (!res.ok)
|
|
13384
|
+
if (!res.ok) {
|
|
13385
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status, functionName)
|
|
13386
|
+
}
|
|
13239
13387
|
const json = await res.json();
|
|
13240
13388
|
|
|
13241
13389
|
if (typeof json.result === 'string') {
|
|
13242
|
-
if (json.result.includes('Invalid API Key'))
|
|
13243
|
-
|
|
13390
|
+
if (json.result.includes('Invalid API Key'))
|
|
13391
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, apiInfo.apiKeyName, functionName)
|
|
13392
|
+
if (json.result.includes('Max rate limit reached'))
|
|
13393
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.RATE_LIMIT, apiInfo.apiKeyName, functionName)
|
|
13244
13394
|
}
|
|
13245
13395
|
|
|
13246
|
-
return json.result
|
|
13396
|
+
return json.result
|
|
13247
13397
|
} catch (err) {
|
|
13248
|
-
|
|
13249
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13398
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err, functionName)
|
|
13250
13399
|
}
|
|
13251
13400
|
}
|
|
13252
13401
|
|
|
@@ -13264,6 +13413,9 @@ const fromUsernameToFid = async (username, apiKey) => {
|
|
|
13264
13413
|
const user = users.find(user => user.username === username);
|
|
13265
13414
|
return user && user.fid || null;
|
|
13266
13415
|
};
|
|
13416
|
+
var fromUsernameToFid$1 = {
|
|
13417
|
+
fromUsernameToFid
|
|
13418
|
+
};
|
|
13267
13419
|
|
|
13268
13420
|
// remove nested structure from the response
|
|
13269
13421
|
const removeNestedStructure = (json) => {
|
|
@@ -13278,217 +13430,237 @@ const removeNestedStructure = (json) => {
|
|
|
13278
13430
|
});
|
|
13279
13431
|
};
|
|
13280
13432
|
|
|
13433
|
+
/* global window */
|
|
13434
|
+
|
|
13281
13435
|
async function FIREFLY() {
|
|
13282
13436
|
const [platform, contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13283
|
-
|
|
13284
|
-
|
|
13437
|
+
const missingParamsError = checkRequiredParams({ platform, contentType, identifier });
|
|
13438
|
+
|
|
13439
|
+
if (missingParamsError) {
|
|
13440
|
+
return missingParamsError
|
|
13441
|
+
}
|
|
13442
|
+
|
|
13443
|
+
if (end > MAX_PAGE_LIMIT) {
|
|
13444
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13285
13445
|
}
|
|
13286
|
-
const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Firefly);
|
|
13287
|
-
if (!API_KEY) return `${SERVICE_API_KEY.Firefly}${ERROR_MESSAGES_FLAG.MISSING_KEY}`;
|
|
13288
13446
|
|
|
13289
|
-
const
|
|
13290
|
-
|
|
13447
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Firefly);
|
|
13448
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Firefly)
|
|
13449
|
+
|
|
13450
|
+
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13451
|
+
const headers = { 'x-api-key': API_KEY };
|
|
13291
13452
|
|
|
13292
13453
|
const typeMap = {
|
|
13293
13454
|
farcaster: {
|
|
13294
|
-
posts:
|
|
13295
|
-
replies:
|
|
13296
|
-
channels:
|
|
13455
|
+
posts: 'farcasterid',
|
|
13456
|
+
replies: 'farcasterpostid',
|
|
13457
|
+
channels: 'farcasterchannels'
|
|
13297
13458
|
},
|
|
13298
13459
|
lens: {
|
|
13299
|
-
posts:
|
|
13300
|
-
replies:
|
|
13460
|
+
posts: 'lensid',
|
|
13461
|
+
replies: 'lenspostid'
|
|
13301
13462
|
}
|
|
13302
13463
|
};
|
|
13303
|
-
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
|
|
13464
|
+
const platformType = typeMap[platform];
|
|
13465
|
+
if (!platformType) {
|
|
13466
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { platform })
|
|
13467
|
+
}
|
|
13468
|
+
const platformContentType = platformType[contentType];
|
|
13469
|
+
if (!platformContentType) {
|
|
13470
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13471
|
+
}
|
|
13307
13472
|
const query = identifier
|
|
13308
|
-
.split(
|
|
13309
|
-
.map(s => s.trim())
|
|
13473
|
+
.split(',')
|
|
13474
|
+
.map((s) => s.trim())
|
|
13310
13475
|
.filter(Boolean)
|
|
13311
|
-
.join(
|
|
13476
|
+
.join(',');
|
|
13312
13477
|
|
|
13313
13478
|
const url = new URL(baseUrl);
|
|
13314
|
-
url.searchParams.set(
|
|
13315
|
-
url.searchParams.set(
|
|
13316
|
-
url.searchParams.set(
|
|
13317
|
-
url.searchParams.set(
|
|
13479
|
+
url.searchParams.set('query', query);
|
|
13480
|
+
url.searchParams.set('type', platformType);
|
|
13481
|
+
url.searchParams.set('start', String(start));
|
|
13482
|
+
url.searchParams.set('end', String(end));
|
|
13318
13483
|
|
|
13319
13484
|
try {
|
|
13320
13485
|
const res = await fetch(url.toString(), { headers });
|
|
13321
|
-
if (!res.ok)
|
|
13486
|
+
if (!res.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13322
13487
|
|
|
13323
13488
|
const json = await res.json();
|
|
13324
|
-
if (!Array.isArray(json?.data)) return []
|
|
13489
|
+
if (!Array.isArray(json?.data)) return []
|
|
13325
13490
|
|
|
13326
|
-
return json.data.map(item => {
|
|
13491
|
+
return json.data.map((item) => {
|
|
13327
13492
|
const flat = {};
|
|
13328
13493
|
for (const [key, value] of Object.entries(item)) {
|
|
13329
|
-
if (typeof value !==
|
|
13494
|
+
if (typeof value !== 'object' || value === null) {
|
|
13330
13495
|
flat[key] = value;
|
|
13331
13496
|
}
|
|
13332
13497
|
}
|
|
13333
13498
|
flat.platform = platform;
|
|
13334
|
-
return flat
|
|
13335
|
-
})
|
|
13336
|
-
|
|
13499
|
+
return flat
|
|
13500
|
+
})
|
|
13337
13501
|
} catch (err) {
|
|
13338
|
-
|
|
13339
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13502
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13340
13503
|
}
|
|
13341
13504
|
}
|
|
13342
13505
|
|
|
13343
13506
|
async function LENS() {
|
|
13344
13507
|
const [contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13345
|
-
const
|
|
13346
|
-
if (
|
|
13347
|
-
|
|
13348
|
-
|
|
13349
|
-
|
|
13508
|
+
const missingParamsError = checkRequiredParams({ contentType, identifier });
|
|
13509
|
+
if (missingParamsError) {
|
|
13510
|
+
return missingParamsError
|
|
13511
|
+
}
|
|
13512
|
+
if (end > MAX_PAGE_LIMIT) {
|
|
13513
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13350
13514
|
}
|
|
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)
|
|
13351
13517
|
|
|
13352
|
-
const baseUrl =
|
|
13353
|
-
const headers = {
|
|
13518
|
+
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13519
|
+
const headers = { 'x-api-key': API_KEY };
|
|
13354
13520
|
|
|
13355
13521
|
const typeMap = {
|
|
13356
|
-
posts:
|
|
13357
|
-
replies:
|
|
13522
|
+
posts: 'lensid',
|
|
13523
|
+
replies: 'lenspostid'
|
|
13358
13524
|
};
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13525
|
+
const platformContentType = typeMap[contentType];
|
|
13526
|
+
if (!platformContentType) {
|
|
13527
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13528
|
+
}
|
|
13363
13529
|
const query = identifier
|
|
13364
|
-
.split(
|
|
13365
|
-
.map(s => s.trim())
|
|
13530
|
+
.split(',')
|
|
13531
|
+
.map((s) => s.trim())
|
|
13366
13532
|
.filter(Boolean)
|
|
13367
|
-
.join(
|
|
13533
|
+
.join(',');
|
|
13368
13534
|
|
|
13369
13535
|
const url = new URL(baseUrl);
|
|
13370
|
-
url.searchParams.set(
|
|
13371
|
-
url.searchParams.set(
|
|
13372
|
-
url.searchParams.set(
|
|
13373
|
-
url.searchParams.set(
|
|
13536
|
+
url.searchParams.set('query', query);
|
|
13537
|
+
url.searchParams.set('type', platformContentType);
|
|
13538
|
+
url.searchParams.set('start', String(start));
|
|
13539
|
+
url.searchParams.set('end', String(end));
|
|
13374
13540
|
|
|
13375
13541
|
try {
|
|
13376
13542
|
const res = await fetch(url.toString(), { headers });
|
|
13377
|
-
if (!res.ok)
|
|
13543
|
+
if (!res.ok) {
|
|
13544
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13545
|
+
}
|
|
13378
13546
|
|
|
13379
13547
|
const json = await res.json();
|
|
13380
|
-
if (!Array.isArray(json?.data)) return []
|
|
13548
|
+
if (!Array.isArray(json?.data)) return []
|
|
13381
13549
|
|
|
13382
|
-
return json.data.map(item => {
|
|
13550
|
+
return json.data.map((item) => {
|
|
13383
13551
|
const flat = {};
|
|
13384
13552
|
for (const [key, value] of Object.entries(item)) {
|
|
13385
|
-
if (typeof value !==
|
|
13553
|
+
if (typeof value !== 'object' || value === null) {
|
|
13386
13554
|
flat[key] = value;
|
|
13387
13555
|
}
|
|
13388
13556
|
}
|
|
13389
13557
|
flat.platform = 'lens';
|
|
13390
|
-
return flat
|
|
13391
|
-
})
|
|
13392
|
-
|
|
13558
|
+
return flat
|
|
13559
|
+
})
|
|
13393
13560
|
} catch (err) {
|
|
13394
|
-
|
|
13395
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13561
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13396
13562
|
}
|
|
13397
13563
|
}
|
|
13398
13564
|
|
|
13399
13565
|
async function FARCASTER() {
|
|
13400
13566
|
const [contentType, identifier, start = 0, end = 10] = argsToArray(arguments);
|
|
13401
|
-
const
|
|
13402
|
-
if (
|
|
13403
|
-
|
|
13404
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
13567
|
+
const missingParamsError = checkRequiredParams({ contentType, identifier });
|
|
13568
|
+
if (missingParamsError) {
|
|
13569
|
+
return missingParamsError
|
|
13405
13570
|
}
|
|
13406
|
-
|
|
13407
|
-
|
|
13571
|
+
if (end > MAX_PAGE_LIMIT) {
|
|
13572
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13573
|
+
}
|
|
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
|
+
const baseUrl = 'https://openapi.firefly.land/v1/fileverse/fetch';
|
|
13577
|
+
const headers = { 'x-api-key': API_KEY };
|
|
13408
13578
|
|
|
13409
13579
|
const typeMap = {
|
|
13410
|
-
posts:
|
|
13411
|
-
replies:
|
|
13412
|
-
channels:
|
|
13580
|
+
posts: 'farcasterid',
|
|
13581
|
+
replies: 'farcasterpostid',
|
|
13582
|
+
channels: 'farcasterchannels'
|
|
13413
13583
|
};
|
|
13414
13584
|
|
|
13415
|
-
const
|
|
13416
|
-
if (!
|
|
13417
|
-
|
|
13585
|
+
const platformContentType = typeMap[contentType];
|
|
13586
|
+
if (!platformContentType) {
|
|
13587
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { contentType })
|
|
13588
|
+
}
|
|
13418
13589
|
const query = identifier
|
|
13419
|
-
.split(
|
|
13420
|
-
.map(s => s.trim())
|
|
13590
|
+
.split(',')
|
|
13591
|
+
.map((s) => s.trim())
|
|
13421
13592
|
.filter(Boolean)
|
|
13422
|
-
.join(
|
|
13593
|
+
.join(',');
|
|
13423
13594
|
|
|
13424
13595
|
const url = new URL(baseUrl);
|
|
13425
|
-
url.searchParams.set(
|
|
13426
|
-
url.searchParams.set(
|
|
13427
|
-
url.searchParams.set(
|
|
13428
|
-
url.searchParams.set(
|
|
13596
|
+
url.searchParams.set('query', query);
|
|
13597
|
+
url.searchParams.set('type', platformContentType);
|
|
13598
|
+
url.searchParams.set('start', String(start));
|
|
13599
|
+
url.searchParams.set('end', String(end));
|
|
13429
13600
|
|
|
13430
13601
|
try {
|
|
13431
13602
|
const res = await fetch(url.toString(), { headers });
|
|
13432
|
-
if (!res.ok)
|
|
13603
|
+
if (!res.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
13433
13604
|
|
|
13434
13605
|
const json = await res.json();
|
|
13435
|
-
if (!Array.isArray(json?.data)) return []
|
|
13606
|
+
if (!Array.isArray(json?.data)) return []
|
|
13436
13607
|
|
|
13437
|
-
return json.data.map(item => {
|
|
13608
|
+
return json.data.map((item) => {
|
|
13438
13609
|
const flat = {};
|
|
13439
13610
|
for (const [key, value] of Object.entries(item)) {
|
|
13440
|
-
if (typeof value !==
|
|
13611
|
+
if (typeof value !== 'object' || value === null) {
|
|
13441
13612
|
flat[key] = value;
|
|
13442
13613
|
}
|
|
13443
13614
|
}
|
|
13444
|
-
flat.platform =
|
|
13445
|
-
return flat
|
|
13446
|
-
})
|
|
13447
|
-
|
|
13615
|
+
flat.platform = 'farcaster';
|
|
13616
|
+
return flat
|
|
13617
|
+
})
|
|
13448
13618
|
} catch (err) {
|
|
13449
|
-
|
|
13450
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13619
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13451
13620
|
}
|
|
13452
13621
|
}
|
|
13453
13622
|
|
|
13454
13623
|
async function BLOCKSCOUT() {
|
|
13455
|
-
|
|
13456
|
-
|
|
13457
|
-
|
|
13624
|
+
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
|
+
if (offset > MAX_PAGE_LIMIT) {
|
|
13631
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13458
13632
|
}
|
|
13459
13633
|
if (!chain) {
|
|
13460
13634
|
chain = 'ethereum';
|
|
13461
13635
|
}
|
|
13462
13636
|
|
|
13463
|
-
if (!type) {
|
|
13464
|
-
return 'TYPE_MISSING'
|
|
13465
|
-
}
|
|
13466
|
-
|
|
13467
13637
|
if (!startTimestamp) {
|
|
13468
13638
|
const currentTimestamp = Date.now();
|
|
13469
13639
|
startTimestamp = currentTimestamp - 30 * 24 * 60 * 60 * 1000;
|
|
13470
13640
|
startTimestamp = Math.floor(startTimestamp / 1000);
|
|
13471
13641
|
}
|
|
13472
13642
|
|
|
13473
|
-
if(isNaN(startTimestamp)){
|
|
13643
|
+
if (isNaN(startTimestamp)) {
|
|
13474
13644
|
startTimestamp = toTimestamp(startTimestamp);
|
|
13475
13645
|
}
|
|
13476
13646
|
|
|
13477
|
-
|
|
13478
|
-
if(isNaN(endTimestamp) && endTimestamp){
|
|
13647
|
+
if (isNaN(endTimestamp) && endTimestamp) {
|
|
13479
13648
|
endTimestamp = toTimestamp(endTimestamp);
|
|
13480
13649
|
}
|
|
13481
13650
|
|
|
13482
|
-
if(!isAddress(address)){
|
|
13483
|
-
|
|
13651
|
+
if (!isAddress$1.isAddress(address)) {
|
|
13652
|
+
const ensName = address;
|
|
13653
|
+
address = await fromEnsNameToAddress$1.fromEnsNameToAddress(address);
|
|
13654
|
+
if (!address) {
|
|
13655
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.ENS, ensName)
|
|
13656
|
+
}
|
|
13484
13657
|
}
|
|
13658
|
+
const hostname = BLOCKSCOUT_CHAINS_MAP[chain];
|
|
13485
13659
|
|
|
13486
|
-
if(!
|
|
13487
|
-
return
|
|
13660
|
+
if (!hostname) {
|
|
13661
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
13488
13662
|
}
|
|
13489
13663
|
|
|
13490
|
-
const hostname = BLOCKSCOUT_CHAINS_MAP[chain];
|
|
13491
|
-
|
|
13492
13664
|
let requestUrl;
|
|
13493
13665
|
|
|
13494
13666
|
switch (type) {
|
|
@@ -13502,22 +13674,26 @@ async function BLOCKSCOUT() {
|
|
|
13502
13674
|
requestUrl = `${hostname}/api?module=account&action=tokenlist&address=${address}`;
|
|
13503
13675
|
break
|
|
13504
13676
|
default:
|
|
13505
|
-
return
|
|
13677
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { type })
|
|
13506
13678
|
}
|
|
13507
13679
|
try {
|
|
13508
13680
|
const response = await fetch(requestUrl);
|
|
13509
13681
|
|
|
13510
13682
|
if (!response.ok) {
|
|
13511
|
-
|
|
13683
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13512
13684
|
}
|
|
13513
13685
|
const json = await response.json();
|
|
13514
|
-
|
|
13515
|
-
console.log(json);
|
|
13516
13686
|
if (json?.result?.includes('Invalid parameter(s)')) {
|
|
13517
|
-
return
|
|
13687
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13688
|
+
message: 'Invalid parameters',
|
|
13689
|
+
reason: json.result
|
|
13690
|
+
})
|
|
13518
13691
|
}
|
|
13519
13692
|
if (json?.result?.includes('Not found')) {
|
|
13520
|
-
return
|
|
13693
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, {
|
|
13694
|
+
message: 'Address information not found',
|
|
13695
|
+
reason: json.result
|
|
13696
|
+
})
|
|
13521
13697
|
}
|
|
13522
13698
|
|
|
13523
13699
|
if (type === 'stat') {
|
|
@@ -13537,54 +13713,75 @@ async function BLOCKSCOUT() {
|
|
|
13537
13713
|
*/
|
|
13538
13714
|
return json.result
|
|
13539
13715
|
} catch (error) {
|
|
13540
|
-
return
|
|
13716
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, error)
|
|
13541
13717
|
}
|
|
13542
13718
|
}
|
|
13543
13719
|
|
|
13544
13720
|
async function BASE() {
|
|
13545
|
-
const [type,
|
|
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
|
+
}
|
|
13546
13732
|
return handleScanRequest({
|
|
13547
|
-
scanKey: SERVICE_API_KEY.Basescan,
|
|
13548
|
-
baseUrl: 'https://api.basescan.org/api',
|
|
13549
13733
|
type,
|
|
13550
|
-
chain,
|
|
13551
13734
|
address,
|
|
13552
13735
|
startDate,
|
|
13553
13736
|
endDate,
|
|
13554
13737
|
page,
|
|
13555
|
-
offset:limit
|
|
13556
|
-
|
|
13738
|
+
offset: limit,
|
|
13739
|
+
apiKey: API_KEY,
|
|
13740
|
+
functionName: 'BASE',
|
|
13741
|
+
chainId: CHAIN_ID_MAP.base,
|
|
13742
|
+
network: 'base'
|
|
13743
|
+
})
|
|
13557
13744
|
}
|
|
13558
13745
|
async function GNOSIS() {
|
|
13559
|
-
const [type,
|
|
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
|
+
}
|
|
13560
13757
|
return handleScanRequest({
|
|
13561
|
-
scanKey: SERVICE_API_KEY.Gnosisscan,
|
|
13562
|
-
baseUrl: 'https://api.gnosisscan.io/api',
|
|
13563
13758
|
type,
|
|
13564
|
-
|
|
13759
|
+
network: 'gnosis',
|
|
13565
13760
|
address,
|
|
13566
13761
|
startDate,
|
|
13567
13762
|
endDate,
|
|
13568
13763
|
page,
|
|
13569
|
-
|
|
13570
|
-
|
|
13764
|
+
apiKey: API_KEY,
|
|
13765
|
+
offset: limit,
|
|
13766
|
+
chainId: CHAIN_ID_MAP.gnosis,
|
|
13767
|
+
functionName: 'GNOSIS'
|
|
13768
|
+
})
|
|
13571
13769
|
}
|
|
13572
13770
|
|
|
13573
13771
|
async function NEYNAR() {
|
|
13574
|
-
const [
|
|
13575
|
-
|
|
13576
|
-
] = argsToArray(arguments);
|
|
13577
|
-
const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Neynar);
|
|
13578
|
-
if (!API_KEY) return `${SERVICE_API_KEY.Neynar}${ERROR_MESSAGES_FLAG.MISSING_KEY}`;
|
|
13772
|
+
const [username] = argsToArray(arguments);
|
|
13773
|
+
const missingParamsError = checkRequiredParams({ username });
|
|
13579
13774
|
|
|
13580
|
-
if(
|
|
13581
|
-
return
|
|
13775
|
+
if (missingParamsError) {
|
|
13776
|
+
return missingParamsError
|
|
13582
13777
|
}
|
|
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)
|
|
13583
13780
|
|
|
13584
|
-
const fid = await fromUsernameToFid(username, API_KEY);
|
|
13781
|
+
const fid = await fromUsernameToFid$1.fromUsernameToFid(username, API_KEY);
|
|
13585
13782
|
|
|
13586
|
-
if(!fid){
|
|
13587
|
-
return
|
|
13783
|
+
if (!fid) {
|
|
13784
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { username })
|
|
13588
13785
|
}
|
|
13589
13786
|
|
|
13590
13787
|
const url = `https://api.neynar.com/v2/farcaster/followers?fid=${fid}`;
|
|
@@ -13596,9 +13793,11 @@ async function NEYNAR() {
|
|
|
13596
13793
|
'x-neynar-experimental': 'false'
|
|
13597
13794
|
}
|
|
13598
13795
|
});
|
|
13599
|
-
if (!response.ok)
|
|
13796
|
+
if (!response.ok) {
|
|
13797
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13798
|
+
}
|
|
13600
13799
|
const json = await response.json();
|
|
13601
|
-
if (!json?.users?.length) return []
|
|
13800
|
+
if (!json?.users?.length) return []
|
|
13602
13801
|
|
|
13603
13802
|
return json.users.map(({ user }) => ({
|
|
13604
13803
|
username: user.username,
|
|
@@ -13606,98 +13805,114 @@ async function NEYNAR() {
|
|
|
13606
13805
|
follower_count: user.follower_count,
|
|
13607
13806
|
country: user.profile?.location?.address?.country || '',
|
|
13608
13807
|
city: user.profile?.location?.address?.city || ''
|
|
13609
|
-
}))
|
|
13808
|
+
}))
|
|
13610
13809
|
} catch (err) {
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
}
|
|
13629
|
-
|
|
13630
|
-
const url = new URL(`https://api.gnosispay.com/cards/${cardId}/transactions`);
|
|
13631
|
-
url.searchParams.set('limit', limit.toString());
|
|
13632
|
-
url.searchParams.set('offset', offset.toString());
|
|
13810
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13811
|
+
}
|
|
13812
|
+
}
|
|
13813
|
+
// export async function GNOSISPAY({
|
|
13814
|
+
// cardId,
|
|
13815
|
+
// startDate,
|
|
13816
|
+
// endDate,
|
|
13817
|
+
// limit = 20,
|
|
13818
|
+
// offset = 0,
|
|
13819
|
+
// }) {
|
|
13820
|
+
// const apiKeyKey = SERVICES_API_KEY.GnosisPay
|
|
13821
|
+
// const API_KEY = window.localStorage.getItem(apiKeyKey);
|
|
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
|
+
// }
|
|
13633
13827
|
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
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());
|
|
13637
13831
|
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
|
|
13832
|
+
// if (!isNaN(toTimestamp(startDate))) {
|
|
13833
|
+
// url.searchParams.set('startDate', new Date(startDate * 1000).toISOString());
|
|
13834
|
+
// }
|
|
13641
13835
|
|
|
13642
|
-
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
Authorization: `Bearer ${API_KEY}`,
|
|
13646
|
-
'Content-Type': 'application/json',
|
|
13647
|
-
},
|
|
13648
|
-
});
|
|
13836
|
+
// if (!isNaN(toTimestamp(endDate))) {
|
|
13837
|
+
// url.searchParams.set('endDate', new Date(endDate * 1000).toISOString());
|
|
13838
|
+
// }
|
|
13649
13839
|
|
|
13650
|
-
|
|
13840
|
+
// try {
|
|
13841
|
+
// const res = await fetch(url.toString(), {
|
|
13842
|
+
// headers: {
|
|
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
|
+
// }
|
|
13651
13873
|
|
|
13652
|
-
|
|
13874
|
+
async function ETHERSCAN(...args) {
|
|
13875
|
+
const [type, chain, address, startDate, endDate, page, limit] = args;
|
|
13876
|
+
const missingParamsError = checkRequiredParams({ type, address, chain });
|
|
13653
13877
|
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
return json.map(tx => ({
|
|
13657
|
-
createdAt: tx.createdAt,
|
|
13658
|
-
clearedAt: tx.clearedAt,
|
|
13659
|
-
country: tx.country,
|
|
13660
|
-
merchant: tx.merchant,
|
|
13661
|
-
billingAmount: tx.billingAmount,
|
|
13662
|
-
billingCurrency: tx.billingCurrency,
|
|
13663
|
-
transactionAmount: tx.transactionAmount,
|
|
13664
|
-
transactionCurrency: tx.transactionCurrency,
|
|
13665
|
-
transactionType: tx.transactionType,
|
|
13666
|
-
kind: tx.kind,
|
|
13667
|
-
status: tx.status || null,
|
|
13668
|
-
mcc: tx.mcc,
|
|
13669
|
-
}));
|
|
13670
|
-
} catch (err) {
|
|
13671
|
-
console.error('GNOSISPAY_CARD_TXNS error:', err);
|
|
13672
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
13878
|
+
if (missingParamsError) {
|
|
13879
|
+
return missingParamsError
|
|
13673
13880
|
}
|
|
13674
|
-
}
|
|
13675
13881
|
|
|
13882
|
+
const chainId = CHAIN_ID_MAP[chain];
|
|
13676
13883
|
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13884
|
+
if (!chainId?.toString()) {
|
|
13885
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
13886
|
+
}
|
|
13887
|
+
const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
|
|
13888
|
+
if (!API_KEY) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Etherscan)
|
|
13680
13889
|
return handleScanRequest({
|
|
13681
|
-
scanKey: SERVICE_API_KEY.Etherscan,
|
|
13682
|
-
baseUrl: 'https://api.etherscan.io/v2/api',
|
|
13683
13890
|
type,
|
|
13684
|
-
chain,
|
|
13685
13891
|
address,
|
|
13686
13892
|
startDate,
|
|
13687
13893
|
endDate,
|
|
13688
13894
|
page,
|
|
13689
|
-
offset:limit
|
|
13690
|
-
|
|
13895
|
+
offset: limit,
|
|
13896
|
+
chainId,
|
|
13897
|
+
network: chain,
|
|
13898
|
+
functionName: 'ETHERSCAN',
|
|
13899
|
+
apiKey: API_KEY
|
|
13900
|
+
})
|
|
13691
13901
|
}
|
|
13692
13902
|
|
|
13903
|
+
async function COINGECKO() {
|
|
13904
|
+
const [category, param1, param2] = argsToArray(arguments);
|
|
13905
|
+
const missingParamsError = checkRequiredParams({ category, param1 });
|
|
13693
13906
|
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
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)
|
|
13697
13912
|
|
|
13698
13913
|
const headers = {
|
|
13699
13914
|
accept: 'application/json',
|
|
13700
|
-
'x-cg-demo-api-key': API_KEY
|
|
13915
|
+
'x-cg-demo-api-key': API_KEY
|
|
13701
13916
|
};
|
|
13702
13917
|
|
|
13703
13918
|
let url = '';
|
|
@@ -13708,10 +13923,10 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13708
13923
|
const token = param1;
|
|
13709
13924
|
const vsCurrencies = param2;
|
|
13710
13925
|
if (!token) {
|
|
13711
|
-
return
|
|
13926
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { param1 })
|
|
13712
13927
|
}
|
|
13713
|
-
url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vsCurrencies ? vsCurrencies : 'usd'
|
|
13714
|
-
break
|
|
13928
|
+
url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vsCurrencies ? vsCurrencies : 'usd'}&symbols=${token}`;
|
|
13929
|
+
break
|
|
13715
13930
|
}
|
|
13716
13931
|
|
|
13717
13932
|
case 'market': {
|
|
@@ -13725,7 +13940,7 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13725
13940
|
bitcoin: 'bitcoin-ecosystem',
|
|
13726
13941
|
pump: 'pump-ecosystem',
|
|
13727
13942
|
aiagents: 'ai-agents',
|
|
13728
|
-
meme: 'meme-token'
|
|
13943
|
+
meme: 'meme-token'
|
|
13729
13944
|
};
|
|
13730
13945
|
|
|
13731
13946
|
const key = param1?.toLowerCase();
|
|
@@ -13735,17 +13950,15 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13735
13950
|
url = `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&include_tokens=top&page=1&per_page=100`;
|
|
13736
13951
|
if (categoryVal) url += `&category=${categoryVal}`;
|
|
13737
13952
|
if (trend) url += trend;
|
|
13738
|
-
break
|
|
13953
|
+
break
|
|
13739
13954
|
}
|
|
13740
13955
|
|
|
13741
13956
|
case 'stablecoins': {
|
|
13742
|
-
const category = !param1 || param1.toLowerCase() === 'all'
|
|
13743
|
-
? 'stablecoins'
|
|
13744
|
-
: param1.toLowerCase();
|
|
13957
|
+
const category = !param1 || param1.toLowerCase() === 'all' ? 'stablecoins' : param1.toLowerCase();
|
|
13745
13958
|
|
|
13746
13959
|
const trend = param2 ? `&price_change_percentage=${param2}` : '';
|
|
13747
13960
|
url = `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&category=${category}&order=market_cap_desc&page=1&per_page=100${trend}`;
|
|
13748
|
-
break
|
|
13961
|
+
break
|
|
13749
13962
|
}
|
|
13750
13963
|
|
|
13751
13964
|
case 'derivatives': {
|
|
@@ -13755,11 +13968,11 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13755
13968
|
} else {
|
|
13756
13969
|
url = `https://api.coingecko.com/api/v3/derivatives/exchanges/${exchange}?include_tickers=all`;
|
|
13757
13970
|
}
|
|
13758
|
-
break
|
|
13971
|
+
break
|
|
13759
13972
|
}
|
|
13760
13973
|
|
|
13761
13974
|
default:
|
|
13762
|
-
return
|
|
13975
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
13763
13976
|
}
|
|
13764
13977
|
|
|
13765
13978
|
try {
|
|
@@ -13768,12 +13981,10 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13768
13981
|
|
|
13769
13982
|
if (!response.ok) {
|
|
13770
13983
|
const message = json?.status?.error_message || '';
|
|
13771
|
-
if (response.status === 429) {
|
|
13772
|
-
return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`;
|
|
13773
|
-
}
|
|
13774
13984
|
if (message.includes('API Key Missing')) {
|
|
13775
|
-
return
|
|
13985
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, SERVICES_API_KEY.Coingecko)
|
|
13776
13986
|
}
|
|
13987
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
13777
13988
|
}
|
|
13778
13989
|
|
|
13779
13990
|
if (lowerCategory === 'price') {
|
|
@@ -13784,7 +13995,7 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13784
13995
|
output[key] = value;
|
|
13785
13996
|
}
|
|
13786
13997
|
}
|
|
13787
|
-
return [output]
|
|
13998
|
+
return [output]
|
|
13788
13999
|
}
|
|
13789
14000
|
|
|
13790
14001
|
let data = json;
|
|
@@ -13794,7 +14005,7 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13794
14005
|
data = json.slice(0, 200);
|
|
13795
14006
|
}
|
|
13796
14007
|
|
|
13797
|
-
if(param1 !== 'all' && json && json.tickers){
|
|
14008
|
+
if (param1 !== 'all' && json && json.tickers) {
|
|
13798
14009
|
const exchangeDetails = {
|
|
13799
14010
|
exchange_id: param1,
|
|
13800
14011
|
exchange_name: json.name,
|
|
@@ -13803,94 +14014,107 @@ async function COINGECKO(category, param1, param2) {
|
|
|
13803
14014
|
exchange_trade_volume_24h_btc: json.trade_volume_24h_btc,
|
|
13804
14015
|
exchange_number_of_futures_pairs: json.number_of_futures_pairs,
|
|
13805
14016
|
exchange_number_of_perpetual_pairs: json.number_of_perpetual_pairs,
|
|
13806
|
-
exchange_open_interest_btc: json.open_interest_btc
|
|
14017
|
+
exchange_open_interest_btc: json.open_interest_btc
|
|
13807
14018
|
};
|
|
13808
|
-
data = json.tickers.slice(0, 200).map(item => {
|
|
14019
|
+
data = json.tickers.slice(0, 200).map((item) => {
|
|
13809
14020
|
return {
|
|
13810
14021
|
...item,
|
|
13811
14022
|
...exchangeDetails,
|
|
13812
|
-
usd_volume: item.converted_volume && item.converted_volume.usd
|
|
14023
|
+
usd_volume: item.converted_volume && item.converted_volume.usd
|
|
13813
14024
|
}
|
|
13814
14025
|
});
|
|
13815
14026
|
}
|
|
13816
14027
|
}
|
|
13817
14028
|
|
|
13818
14029
|
const flatArray = Array.isArray(data) ? data : [data];
|
|
13819
|
-
return flatArray.map(item => {
|
|
14030
|
+
return flatArray.map((item) => {
|
|
13820
14031
|
const flat = {};
|
|
13821
14032
|
for (const [key, value] of Object.entries(item)) {
|
|
13822
14033
|
if (typeof value !== 'object' || value === null) {
|
|
13823
14034
|
flat[key] = value;
|
|
13824
14035
|
}
|
|
13825
14036
|
}
|
|
13826
|
-
return flat
|
|
13827
|
-
})
|
|
14037
|
+
return flat
|
|
14038
|
+
})
|
|
13828
14039
|
} catch (error) {
|
|
13829
|
-
|
|
13830
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
14040
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, error)
|
|
13831
14041
|
}
|
|
13832
14042
|
}
|
|
13833
14043
|
|
|
13834
14044
|
async function EOA() {
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
13838
|
-
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
const
|
|
13850
|
-
|
|
14045
|
+
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
|
+
if (offset > MAX_PAGE_LIMIT) {
|
|
14056
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
14057
|
+
}
|
|
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
|
+
const INPUTS = addresses
|
|
14062
|
+
.split(',')
|
|
14063
|
+
.map((a) => a.trim())
|
|
14064
|
+
.filter(Boolean);
|
|
14065
|
+
const CHAINS = chains
|
|
14066
|
+
.split(',')
|
|
14067
|
+
.map((c) => c.trim())
|
|
14068
|
+
.filter(Boolean);
|
|
13851
14069
|
const out = [];
|
|
13852
14070
|
// Map: finalAddress => ENS name (if applicable)
|
|
13853
14071
|
const ADDRESS_MAP = {};
|
|
13854
14072
|
for (const input of INPUTS) {
|
|
13855
|
-
if (isAddress(input)) {
|
|
14073
|
+
if (isAddress$1.isAddress(input)) {
|
|
13856
14074
|
ADDRESS_MAP[input.toLowerCase()] = null; // it's a direct address
|
|
13857
14075
|
} else {
|
|
13858
14076
|
try {
|
|
13859
|
-
const resolved = await fromEnsNameToAddress(input); // ENS -> address
|
|
14077
|
+
const resolved = await fromEnsNameToAddress$1.fromEnsNameToAddress(input); // ENS -> address
|
|
13860
14078
|
if (resolved) ADDRESS_MAP[resolved.toLowerCase()] = input;
|
|
13861
14079
|
} catch {
|
|
13862
|
-
return
|
|
14080
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { addresses })
|
|
13863
14081
|
}
|
|
13864
14082
|
}
|
|
13865
14083
|
}
|
|
13866
14084
|
const ADDRS = Object.keys(ADDRESS_MAP);
|
|
13867
14085
|
for (const chain of CHAINS) {
|
|
13868
14086
|
const chainId = CHAIN_ID_MAP[chain];
|
|
13869
|
-
if (!chainId) return ERROR_MESSAGES_FLAG.
|
|
13870
|
-
if (category ===
|
|
14087
|
+
if (!chainId) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
14088
|
+
if (category === 'balance') {
|
|
13871
14089
|
for (let i = 0; i < ADDRS.length; i += 20) {
|
|
13872
|
-
const slice = ADDRS.slice(i, i + 20).join(
|
|
14090
|
+
const slice = ADDRS.slice(i, i + 20).join(',');
|
|
13873
14091
|
const action = 'addresstokenbalance';
|
|
13874
14092
|
const url =
|
|
13875
14093
|
`https://api.etherscan.io/v2/api?chainid=${chainId}` +
|
|
13876
14094
|
`&module=account&action=${action}&address=${slice}` +
|
|
13877
14095
|
`&page=${page}&offset=100&apikey=${API_KEY}`;
|
|
13878
14096
|
const data = await fetchJSON(url);
|
|
13879
|
-
if (
|
|
13880
|
-
data.forEach(tx =>
|
|
14097
|
+
if (!Array.isArray(data)) return data
|
|
14098
|
+
data.forEach((tx) =>
|
|
13881
14099
|
out.push({
|
|
13882
14100
|
chain,
|
|
13883
14101
|
address: ADDRS[i],
|
|
13884
14102
|
name: ADDRESS_MAP[ADDRS[i]],
|
|
13885
|
-
...tx
|
|
13886
|
-
})
|
|
14103
|
+
...tx
|
|
14104
|
+
})
|
|
13887
14105
|
);
|
|
13888
14106
|
}
|
|
13889
|
-
continue
|
|
14107
|
+
continue
|
|
13890
14108
|
}
|
|
13891
|
-
if (category ===
|
|
13892
|
-
const startBlock = await fromTimeStampToBlock(toTimestamp(startTime), chain, API_KEY);
|
|
13893
|
-
const endBlock = await fromTimeStampToBlock(toTimestamp(endTime), chain, API_KEY);
|
|
14109
|
+
if (category === 'txns') {
|
|
14110
|
+
const startBlock = await fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(startTime), chain, API_KEY);
|
|
14111
|
+
const endBlock = await fromTimestampToBlock.fromTimeStampToBlock(toTimestamp(endTime), chain, API_KEY);
|
|
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
|
+
}
|
|
13894
14118
|
for (const addr of ADDRS) {
|
|
13895
14119
|
const url =
|
|
13896
14120
|
`https://api.etherscan.io/v2/api?chainid=${chainId}` +
|
|
@@ -13898,42 +14122,47 @@ async function EOA() {
|
|
|
13898
14122
|
`&startblock=${startBlock}&endblock=${endBlock}` +
|
|
13899
14123
|
`&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
|
|
13900
14124
|
const data = await fetchJSON(url);
|
|
13901
|
-
if (
|
|
13902
|
-
data.forEach(tx =>
|
|
14125
|
+
if (!Array.isArray(data)) return data
|
|
14126
|
+
data.forEach((tx) =>
|
|
13903
14127
|
out.push({
|
|
13904
14128
|
chain,
|
|
13905
14129
|
address: addr,
|
|
13906
14130
|
name: ADDRESS_MAP[addr],
|
|
13907
|
-
...tx
|
|
13908
|
-
})
|
|
14131
|
+
...tx
|
|
14132
|
+
})
|
|
13909
14133
|
);
|
|
13910
14134
|
}
|
|
13911
|
-
continue
|
|
14135
|
+
continue
|
|
13912
14136
|
}
|
|
13913
|
-
return ERROR_MESSAGES_FLAG.
|
|
14137
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
13914
14138
|
}
|
|
13915
14139
|
|
|
13916
|
-
return out
|
|
14140
|
+
return out
|
|
13917
14141
|
|
|
13918
14142
|
async function fetchJSON(url) {
|
|
13919
14143
|
try {
|
|
13920
14144
|
const res = await fetch(url);
|
|
13921
|
-
if (!res.ok)
|
|
14145
|
+
if (!res.ok) {
|
|
14146
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
14147
|
+
}
|
|
13922
14148
|
|
|
13923
14149
|
const json = await res.json();
|
|
13924
14150
|
|
|
13925
|
-
if (json.result?.includes?.(
|
|
13926
|
-
return
|
|
14151
|
+
if (json.result?.includes?.('Invalid API Key'))
|
|
14152
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_API_KEY, SERVICES_API_KEY.Etherscan)
|
|
13927
14153
|
|
|
13928
|
-
if (json.result?.includes?.(
|
|
13929
|
-
return
|
|
14154
|
+
if (json.result?.includes?.('Max rate limit reached'))
|
|
14155
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.RATE_LIMIT, SERVICES_API_KEY.Etherscan)
|
|
13930
14156
|
|
|
13931
|
-
if (json.status ===
|
|
13932
|
-
return ERROR_MESSAGES_FLAG.
|
|
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
|
+
})
|
|
13933
14162
|
|
|
13934
|
-
return json.result
|
|
13935
|
-
} catch {
|
|
13936
|
-
return ERROR_MESSAGES_FLAG.DEFAULT
|
|
14163
|
+
return json.result
|
|
14164
|
+
} catch (err) {
|
|
14165
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
13937
14166
|
}
|
|
13938
14167
|
}
|
|
13939
14168
|
}
|
|
@@ -13941,166 +14170,203 @@ async function EOA() {
|
|
|
13941
14170
|
async function FLVURL(token, vs_currencies) {
|
|
13942
14171
|
return new Promise((resolve) => {
|
|
13943
14172
|
setTimeout(() => {
|
|
13944
|
-
resolve([{
|
|
14173
|
+
resolve([{ Yoo: 'gotcha' }]);
|
|
13945
14174
|
}, 10000);
|
|
13946
|
-
})
|
|
14175
|
+
})
|
|
13947
14176
|
}
|
|
13948
14177
|
|
|
13949
14178
|
async function SAFE() {
|
|
13950
|
-
|
|
13951
14179
|
let [address, utility, chain, limit = 10, offset = 0] = argsToArray(arguments);
|
|
13952
14180
|
|
|
13953
|
-
|
|
13954
|
-
|
|
13955
|
-
if (
|
|
13956
|
-
|
|
13957
|
-
return ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT
|
|
14181
|
+
const missingParamsError = checkRequiredParams({ address, utility, chain });
|
|
14182
|
+
|
|
14183
|
+
if (missingParamsError) {
|
|
14184
|
+
return missingParamsError
|
|
13958
14185
|
}
|
|
13959
14186
|
|
|
13960
|
-
|
|
13961
|
-
|
|
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);
|
|
13962
14192
|
|
|
13963
|
-
if (!apiKey) return
|
|
13964
|
-
if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED';
|
|
14193
|
+
if (!apiKey) return errorMessageHandler(ERROR_MESSAGES_FLAG.MISSING_KEY, SERVICES_API_KEY.Safe)
|
|
13965
14194
|
|
|
13966
|
-
if(
|
|
13967
|
-
|
|
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 })
|
|
14199
|
+
if (limit > MAX_PAGE_LIMIT) {
|
|
14200
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.MAX_PAGE_LIMIT)
|
|
13968
14201
|
}
|
|
13969
14202
|
|
|
13970
|
-
|
|
13971
|
-
|
|
14203
|
+
const chainIdentifier = SAFE_CHAIN_MAP[chain];
|
|
14204
|
+
|
|
14205
|
+
if (!chainIdentifier) return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_CHAIN, chain)
|
|
14206
|
+
|
|
14207
|
+
if (!isAddress$1.isAddress(address)) {
|
|
14208
|
+
const ensName = address;
|
|
14209
|
+
address = await fromEnsNameToAddress$1.fromEnsNameToAddress(address);
|
|
14210
|
+
if (!address) {
|
|
14211
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.ENS, ensName)
|
|
14212
|
+
}
|
|
13972
14213
|
}
|
|
13973
14214
|
|
|
13974
14215
|
const url = `https://api.safe.global/tx-service/${chainIdentifier}/api/v2/safes/${address}/multisig-transactions?limit=${limit}&offset=${offset}`;
|
|
13975
14216
|
try {
|
|
13976
|
-
const response = await fetch(url,
|
|
13977
|
-
{
|
|
13978
|
-
|
|
13979
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
13980
|
-
},
|
|
14217
|
+
const response = await fetch(url, {
|
|
14218
|
+
headers: {
|
|
14219
|
+
Authorization: `Bearer ${apiKey}`
|
|
13981
14220
|
}
|
|
13982
|
-
);
|
|
13983
|
-
if (!response.ok)
|
|
14221
|
+
});
|
|
14222
|
+
if (!response.ok) {
|
|
14223
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
14224
|
+
}
|
|
13984
14225
|
const json = await response.json();
|
|
13985
14226
|
if (!Array.isArray(json.results)) {
|
|
13986
|
-
return
|
|
14227
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.CUSTOM, { message: 'Invalid API response' })
|
|
13987
14228
|
}
|
|
13988
14229
|
// remove nested structure from the response
|
|
13989
|
-
return json.results.map(({ confirmations, dataDecoded, ...rest }) => rest)
|
|
14230
|
+
return json.results.map(({ confirmations, dataDecoded, ...rest }) => rest)
|
|
13990
14231
|
} catch (e) {
|
|
13991
|
-
|
|
13992
|
-
return "ERROR IN FETCHING";
|
|
14232
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, e)
|
|
13993
14233
|
}
|
|
13994
14234
|
}
|
|
13995
14235
|
|
|
13996
14236
|
async function DEFILLAMA() {
|
|
13997
14237
|
let [category] = argsToArray(arguments);
|
|
13998
|
-
const
|
|
13999
|
-
|
|
14238
|
+
const missingParamsError = checkRequiredParams({ category });
|
|
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)
|
|
14000
14245
|
const categoryList = ['protocols', 'yields', 'dex', 'fees'];
|
|
14001
14246
|
const categoryMap = {
|
|
14002
14247
|
[categoryList[0]]: 'https://api.llama.fi/protocols',
|
|
14003
14248
|
[categoryList[1]]: 'https://yields.llama.fi/pools',
|
|
14004
|
-
[categoryList[2]]:
|
|
14005
|
-
|
|
14249
|
+
[categoryList[2]]:
|
|
14250
|
+
'https://api.llama.fi/overview/dexs?excludeTotalDataChart=true&excludeTotalDataChartBreakdown=true',
|
|
14251
|
+
[categoryList[3]]:
|
|
14252
|
+
'https://api.llama.fi/overview/fees?excludeTotalDataChart=true&excludeTotalDataChartBreakdown=true&dataType=dailyFees'
|
|
14006
14253
|
};
|
|
14007
14254
|
let url = categoryMap[category];
|
|
14008
14255
|
|
|
14256
|
+
if (!url) {
|
|
14257
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.INVALID_PARAM, { category })
|
|
14258
|
+
}
|
|
14259
|
+
|
|
14009
14260
|
try {
|
|
14010
14261
|
const response = await fetch(url);
|
|
14011
|
-
if (!response.ok)
|
|
14262
|
+
if (!response.ok) return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, response.status)
|
|
14012
14263
|
let json = await response.json();
|
|
14013
|
-
switch(category){
|
|
14264
|
+
switch (category) {
|
|
14014
14265
|
case categoryList[0]: {
|
|
14015
|
-
if(json.length > 500){
|
|
14266
|
+
if (json.length > 500) {
|
|
14016
14267
|
json = json.slice(0, 500);
|
|
14017
14268
|
}
|
|
14018
|
-
break
|
|
14269
|
+
break
|
|
14019
14270
|
}
|
|
14020
14271
|
case categoryList[1]: {
|
|
14021
14272
|
json = json.data.slice(0, 500);
|
|
14022
|
-
break
|
|
14273
|
+
break
|
|
14023
14274
|
}
|
|
14024
14275
|
case categoryList[2]: {
|
|
14025
14276
|
json = json.protocols.slice(0, 500);
|
|
14026
|
-
break
|
|
14277
|
+
break
|
|
14027
14278
|
}
|
|
14028
14279
|
case categoryList[3]: {
|
|
14029
14280
|
json = json.protocols.slice(0, 500);
|
|
14030
|
-
break
|
|
14281
|
+
break
|
|
14031
14282
|
}
|
|
14032
14283
|
}
|
|
14033
14284
|
|
|
14034
|
-
return removeNestedStructure(Array.isArray(json) ? json : [json])
|
|
14285
|
+
return removeNestedStructure(Array.isArray(json) ? json : [json])
|
|
14035
14286
|
} catch (e) {
|
|
14036
|
-
|
|
14037
|
-
return "ERROR IN FETCHING";
|
|
14287
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, e)
|
|
14038
14288
|
}
|
|
14039
14289
|
}
|
|
14040
14290
|
|
|
14041
14291
|
async function UNISWAP() {
|
|
14042
14292
|
const [graphType, category, param1, param2] = argsToArray(arguments);
|
|
14043
|
-
const
|
|
14293
|
+
const missingParamsError = checkRequiredParams({ graphType, category, param1 });
|
|
14294
|
+
|
|
14295
|
+
if (missingParamsError) {
|
|
14296
|
+
return missingParamsError
|
|
14297
|
+
}
|
|
14298
|
+
const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
|
|
14044
14299
|
try {
|
|
14045
14300
|
const url = `${baseUrl}?service=uniswap&graphType=${graphType}&category=${category}&input1=${param1}&input2=${param2}`;
|
|
14046
14301
|
const res = await fetch(url);
|
|
14047
|
-
if (!res.ok)
|
|
14302
|
+
if (!res.ok) {
|
|
14303
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
14304
|
+
}
|
|
14048
14305
|
const json = await res.json();
|
|
14049
|
-
|
|
14306
|
+
if(Array.isArray(json)){
|
|
14307
|
+
return removeNestedStructure(json)
|
|
14308
|
+
} else {
|
|
14309
|
+
return json
|
|
14310
|
+
}
|
|
14311
|
+
|
|
14050
14312
|
} catch (err) {
|
|
14051
|
-
|
|
14052
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
14313
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
14053
14314
|
}
|
|
14054
14315
|
}
|
|
14055
14316
|
|
|
14056
14317
|
async function AAVE() {
|
|
14057
14318
|
const [graphType, category, param1, param2] = argsToArray(arguments);
|
|
14058
|
-
const
|
|
14319
|
+
const missingParamsError = checkRequiredParams({ graphType, category, param1 });
|
|
14320
|
+
|
|
14321
|
+
if (missingParamsError) {
|
|
14322
|
+
return missingParamsError
|
|
14323
|
+
}
|
|
14324
|
+
const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
|
|
14059
14325
|
try {
|
|
14060
14326
|
const url = `${baseUrl}?service=aave&graphType=${graphType}&category=${category}&input1=${param1}&input2=${param2}`;
|
|
14061
14327
|
const res = await fetch(url);
|
|
14062
|
-
if (!res.ok)
|
|
14328
|
+
if (!res.ok) {
|
|
14329
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.NETWORK_ERROR, res.status)
|
|
14330
|
+
}
|
|
14063
14331
|
const json = await res.json();
|
|
14064
|
-
|
|
14332
|
+
if(Array.isArray(json)){
|
|
14333
|
+
return removeNestedStructure(json)
|
|
14334
|
+
} else {
|
|
14335
|
+
return json
|
|
14336
|
+
}
|
|
14337
|
+
|
|
14065
14338
|
} catch (err) {
|
|
14066
|
-
|
|
14067
|
-
return ERROR_MESSAGES_FLAG.DEFAULT;
|
|
14339
|
+
return errorMessageHandler(ERROR_MESSAGES_FLAG.DEFAULT, err)
|
|
14068
14340
|
}
|
|
14069
14341
|
}
|
|
14070
14342
|
|
|
14071
|
-
|
|
14072
14343
|
function POLYMARKET() {
|
|
14073
|
-
return
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
return
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
}
|
|
14100
|
-
|
|
14101
|
-
function MYANIMELIST() {
|
|
14102
|
-
return "Coming Soon"
|
|
14103
|
-
}
|
|
14344
|
+
return 'Coming Soon'
|
|
14345
|
+
}
|
|
14346
|
+
|
|
14347
|
+
function PRIVACYPOOL() {
|
|
14348
|
+
return 'Coming Soon'
|
|
14349
|
+
}
|
|
14350
|
+
|
|
14351
|
+
function ROTKI() {
|
|
14352
|
+
return 'Coming Soon'
|
|
14353
|
+
}
|
|
14354
|
+
|
|
14355
|
+
function MEERKAT() {
|
|
14356
|
+
return 'Coming Soon'
|
|
14357
|
+
}
|
|
14358
|
+
|
|
14359
|
+
function ARTEMIS() {
|
|
14360
|
+
return 'Coming Soon'
|
|
14361
|
+
}
|
|
14362
|
+
|
|
14363
|
+
function TALLY() {
|
|
14364
|
+
return 'Coming Soon'
|
|
14365
|
+
}
|
|
14366
|
+
|
|
14367
|
+
function MYANIMELIST() {
|
|
14368
|
+
return 'Coming Soon'
|
|
14369
|
+
}
|
|
14104
14370
|
|
|
14105
14371
|
const utils = { errors, symbols, date };
|
|
14106
14372
|
|
|
@@ -14267,7 +14533,6 @@ exports.GCD = GCD;
|
|
|
14267
14533
|
exports.GEOMEAN = GEOMEAN;
|
|
14268
14534
|
exports.GESTEP = GESTEP;
|
|
14269
14535
|
exports.GNOSIS = GNOSIS;
|
|
14270
|
-
exports.GNOSISPAY = GNOSISPAY;
|
|
14271
14536
|
exports.GROWTH = GROWTH;
|
|
14272
14537
|
exports.HARMEAN = HARMEAN;
|
|
14273
14538
|
exports.HEX2BIN = HEX2BIN;
|