@fileverse-dev/formulajs 4.4.12-mod-3-patch-1 → 4.4.12-mod-5
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 +162 -142
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +133 -114
- package/lib/esm/index.mjs +133 -114
- package/package.json +1 -1
- package/types/cjs/index.d.cts +1 -1
- package/types/esm/index.d.mts +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -1271,7 +1271,6 @@ function ROWS(array) {
|
|
|
1271
1271
|
* @returns
|
|
1272
1272
|
*/
|
|
1273
1273
|
function SORT(array, sort_index = 1, sort_order = 1, by_col = false) {
|
|
1274
|
-
// Accept multiple sort keys like Google Sheets: SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
|
|
1275
1274
|
if (!array || !Array.isArray(array)) {
|
|
1276
1275
|
return na
|
|
1277
1276
|
}
|
|
@@ -1280,104 +1279,37 @@ function SORT(array, sort_index = 1, sort_order = 1, by_col = false) {
|
|
|
1280
1279
|
return 0
|
|
1281
1280
|
}
|
|
1282
1281
|
|
|
1283
|
-
|
|
1284
|
-
if (
|
|
1285
|
-
return name
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
// Collect sort keys (index and order). First key comes from sort_index/sort_order.
|
|
1289
|
-
const sortKeys = [];
|
|
1290
|
-
|
|
1291
|
-
const normalizeOrder = (o) => {
|
|
1292
|
-
// Try boolean first (TRUE -> ascending)
|
|
1293
|
-
const b = parseBool(o);
|
|
1294
|
-
if (typeof b === 'boolean') {
|
|
1295
|
-
return b ? 1 : -1
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
const n = parseNumber(o);
|
|
1299
|
-
if (n === 1 || n === -1) {
|
|
1300
|
-
return n
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
return null
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
|
-
const firstIndex = parseNumber(sort_index);
|
|
1307
|
-
if (!firstIndex || firstIndex < 1) {
|
|
1282
|
+
sort_index = parseNumber(sort_index);
|
|
1283
|
+
if (!sort_index || sort_index < 1) {
|
|
1308
1284
|
return value
|
|
1309
1285
|
}
|
|
1310
1286
|
|
|
1311
|
-
|
|
1312
|
-
if (
|
|
1287
|
+
sort_order = parseNumber(sort_order);
|
|
1288
|
+
if (sort_order !== 1 && sort_order !== -1) {
|
|
1313
1289
|
return value
|
|
1314
1290
|
}
|
|
1315
1291
|
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
if (arguments.length > 4) {
|
|
1320
|
-
// arguments: 0=array,1=sort_index,2=sort_order,3=by_col,4=nextIndex,5=nextOrder,...
|
|
1321
|
-
for (let i = 4; i < arguments.length; i += 2) {
|
|
1322
|
-
const idx = parseNumber(arguments[i]);
|
|
1323
|
-
if (!idx || idx < 1) {
|
|
1324
|
-
return value
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
const ordArg = i + 1 < arguments.length ? arguments[i + 1] : 1;
|
|
1328
|
-
const ord = normalizeOrder(ordArg);
|
|
1329
|
-
if (ord === null) {
|
|
1330
|
-
return value
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
sortKeys.push({ index: idx, order: ord });
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
const matrix = fillMatrix(array);
|
|
1338
|
-
const working = by_col ? transpose(matrix) : matrix;
|
|
1339
|
-
|
|
1340
|
-
// Validate that all sort indexes are within column bounds
|
|
1341
|
-
const numCols = working[0] ? working[0].length : 0;
|
|
1342
|
-
for (const k of sortKeys) {
|
|
1343
|
-
if (k.index < 1 || k.index > numCols) {
|
|
1344
|
-
return value
|
|
1345
|
-
}
|
|
1292
|
+
by_col = parseBool(by_col);
|
|
1293
|
+
if (typeof by_col !== 'boolean') {
|
|
1294
|
+
return name
|
|
1346
1295
|
}
|
|
1347
1296
|
|
|
1348
|
-
const
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
if (typeof num === 'number' && !Number.isNaN(num)) return num
|
|
1353
|
-
return parseString(val)
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
const comparator = (aRow, bRow) => {
|
|
1357
|
-
for (const k of sortKeys) {
|
|
1358
|
-
const aVal = parseForCompare(aRow[k.index - 1]);
|
|
1359
|
-
const bVal = parseForCompare(bRow[k.index - 1]);
|
|
1297
|
+
const sortArray = (arr) =>
|
|
1298
|
+
arr.sort((a, b) => {
|
|
1299
|
+
a = parseString(a[sort_index - 1]);
|
|
1300
|
+
b = parseString(b[sort_index - 1]);
|
|
1360
1301
|
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
// Numeric comparison if both are numbers
|
|
1364
|
-
if (typeof aVal === 'number' && typeof bVal === 'number') {
|
|
1365
|
-
return (aVal < bVal ? -1 : 1) * k.order
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
// String comparison
|
|
1369
|
-
const aStr = String(aVal).toLowerCase();
|
|
1370
|
-
const bStr = String(bVal).toLowerCase();
|
|
1371
|
-
return aStr.localeCompare(bStr) * k.order
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
return 0
|
|
1375
|
-
};
|
|
1302
|
+
return sort_order === 1 ? (a < b ? sort_order * -1 : sort_order) : a > b ? sort_order : sort_order * -1
|
|
1303
|
+
});
|
|
1376
1304
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1305
|
+
const matrix = fillMatrix(array);
|
|
1306
|
+
const result = by_col ? transpose(matrix) : matrix;
|
|
1379
1307
|
|
|
1380
|
-
return
|
|
1308
|
+
return sort_index >= 1 && sort_index <= result[0].length
|
|
1309
|
+
? by_col
|
|
1310
|
+
? transpose(sortArray(result))
|
|
1311
|
+
: sortArray(result)
|
|
1312
|
+
: value
|
|
1381
1313
|
}
|
|
1382
1314
|
|
|
1383
1315
|
/**
|
|
@@ -18576,11 +18508,44 @@ async function TALLY() {
|
|
|
18576
18508
|
}
|
|
18577
18509
|
}
|
|
18578
18510
|
|
|
18579
|
-
const
|
|
18580
|
-
|
|
18581
|
-
|
|
18511
|
+
const historicalPrices = stringType()
|
|
18512
|
+
.regex(/^\s*(\d{1,2})(\s*,\s*\d{1,2}){0,2}\s*$/, "Up to 3 comma-separated hour offsets")
|
|
18513
|
+
.refine((s) => s.split(",").map((x) => +x.trim()).every((n) => n >= 1 && n <= 24), {
|
|
18514
|
+
message: "Each offset must be between 1 and 24",
|
|
18515
|
+
});
|
|
18516
|
+
|
|
18517
|
+
|
|
18518
|
+
|
|
18519
|
+
const activity = objectType({
|
|
18520
|
+
type: literalType("activity"),
|
|
18521
|
+
input1: stringType().nonempty(), // wallet address / ens name
|
|
18522
|
+
input2: stringType().optional(), // chain id. / name
|
|
18523
|
+
input3: numberType().int().min(1).max(100).optional(), // limit
|
|
18524
|
+
});
|
|
18525
|
+
|
|
18526
|
+
const tokenHolders = objectType({
|
|
18527
|
+
type: literalType("token_holders"),
|
|
18528
|
+
input1: stringType().nonempty(), // expects token address
|
|
18529
|
+
input2: stringType().nonempty(), // chain id / name
|
|
18530
|
+
input3: numberType().int().min(1).max(500).optional() // limit
|
|
18582
18531
|
});
|
|
18583
18532
|
|
|
18533
|
+
|
|
18534
|
+
const price = objectType({
|
|
18535
|
+
type: literalType("price"),
|
|
18536
|
+
input1: stringType().nonempty(), // chain name / id
|
|
18537
|
+
input2: historicalPrices.optional(), // history prices
|
|
18538
|
+
input3: stringType().optional(), // contract address
|
|
18539
|
+
input4: numberType().int().min(1).max(500).optional() // limit
|
|
18540
|
+
});
|
|
18541
|
+
|
|
18542
|
+
|
|
18543
|
+
const duneSimParamsSchema = discriminatedUnionType("type", [
|
|
18544
|
+
activity,
|
|
18545
|
+
price,
|
|
18546
|
+
tokenHolders
|
|
18547
|
+
]);
|
|
18548
|
+
|
|
18584
18549
|
function flattenObject(obj, parentKey = '', res = {}) {
|
|
18585
18550
|
for (let key in obj) {
|
|
18586
18551
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
@@ -18603,47 +18568,101 @@ function flattenObject(obj, parentKey = '', res = {}) {
|
|
|
18603
18568
|
return res;
|
|
18604
18569
|
}
|
|
18605
18570
|
|
|
18606
|
-
|
|
18571
|
+
const SUPPORTED_TOKEN_NAMES = {
|
|
18572
|
+
"eth": 1, // Ethereum Mainnet
|
|
18573
|
+
"base": 8453, // Base
|
|
18574
|
+
"polygon": 137, // Polygon
|
|
18575
|
+
"arbitrum": 42161, // Arbitrum One
|
|
18576
|
+
"optimism": 10, // Optimism
|
|
18577
|
+
"gnosis": 100, // Gnosis Chain (xDai)
|
|
18578
|
+
"bsc": 56, // Binance Smart Chain
|
|
18579
|
+
"avalanche": 43114, // Avalanche C-Chain
|
|
18580
|
+
"fantom": 250, // Fantom Opera
|
|
18581
|
+
"scroll": 534352, // Scroll
|
|
18582
|
+
"linea": 59144 // Linea
|
|
18583
|
+
};
|
|
18607
18584
|
|
|
18608
18585
|
|
|
18609
18586
|
|
|
18587
|
+
async function DUNESIM() {
|
|
18588
|
+
try {
|
|
18589
|
+
const [type, input1, input2, input3, input4] = argsToArray(arguments);
|
|
18590
|
+
|
|
18591
|
+
validateParams(duneSimParamsSchema, { type, input1, input2, input3, input4 });
|
|
18610
18592
|
|
|
18593
|
+
let route = "";
|
|
18611
18594
|
|
|
18595
|
+
// Helper to assemble query pieces
|
|
18596
|
+
const buildQuery = (pairs) => {
|
|
18597
|
+
const parts = pairs
|
|
18598
|
+
// eslint-disable-next-line no-unused-vars
|
|
18599
|
+
.filter(([_, v]) => v !== undefined && v !== '')
|
|
18600
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`);
|
|
18601
|
+
return parts.length ? `?${parts.join('&')}` : '';
|
|
18602
|
+
};
|
|
18612
18603
|
|
|
18604
|
+
if (type === 'activity') {
|
|
18605
|
+
const address = await fromEnsNameToAddress$1.validateAndGetAddress(input1);
|
|
18606
|
+
const qs = buildQuery([['chain_ids', SUPPORTED_TOKEN_NAMES[input2] || input2], ['limit', input3]]);
|
|
18607
|
+
route = `activity/${address}${qs}`;
|
|
18608
|
+
}
|
|
18613
18609
|
|
|
18614
|
-
|
|
18615
|
-
|
|
18616
|
-
|
|
18610
|
+
if (type === 'price') {
|
|
18611
|
+
const chain = SUPPORTED_TOKEN_NAMES[input1] || input2;
|
|
18612
|
+
const qs = buildQuery([
|
|
18613
|
+
['chain_ids', chain],
|
|
18614
|
+
['historical_prices', input3],
|
|
18615
|
+
['limit', input4],
|
|
18616
|
+
]);
|
|
18617
|
+
route = `token-info/native${qs}`;
|
|
18618
|
+
}
|
|
18619
|
+
|
|
18620
|
+
if (type === 'token_holders') {
|
|
18621
|
+
const qs = buildQuery([['limit', input3]]);
|
|
18622
|
+
const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
|
|
18623
|
+
route = `token-holders/${chain}/${input1}${qs}`;
|
|
18624
|
+
}
|
|
18617
18625
|
|
|
18618
|
-
validateParams(duneSimParamsSchema, { wallet, type });
|
|
18619
|
-
const address = await fromEnsNameToAddress$1.validateAndGetAddress(wallet);
|
|
18620
18626
|
const apiKey = window.localStorage.getItem(SERVICES_API_KEY.DuneSim);
|
|
18621
|
-
const url = `https://api.sim.dune.com/v1/evm
|
|
18627
|
+
const url = `https://api.sim.dune.com/v1/evm/${route}`;
|
|
18622
18628
|
|
|
18623
18629
|
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18624
|
-
url
|
|
18625
|
-
|
|
18626
|
-
'X-Sim-Api-Key': apiKey,
|
|
18627
|
-
}
|
|
18628
|
-
|
|
18630
|
+
url, serviceName: "DuneSim",
|
|
18631
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18629
18632
|
});
|
|
18630
18633
|
|
|
18631
|
-
const
|
|
18632
|
-
|
|
18633
|
-
headers: HEADERS,
|
|
18634
|
-
});
|
|
18635
|
-
if (!response.ok) {
|
|
18636
|
-
throw new NetworkError(SERVICES_API_KEY.DuneSim, response.status)
|
|
18637
|
-
}
|
|
18634
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18635
|
+
if (!res.ok) throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
|
|
18638
18636
|
|
|
18639
|
-
const json = await
|
|
18640
|
-
const
|
|
18641
|
-
|
|
18637
|
+
const json = await res.json();
|
|
18638
|
+
const data =
|
|
18639
|
+
type === "activity" ? json?.activity ?? json ?? [] :
|
|
18640
|
+
type === "token_holders" ? json?.holders ?? json ?? [] :
|
|
18641
|
+
type === "price" ? json?.tokens ?? json ?? [] :
|
|
18642
|
+
json ?? [];
|
|
18643
|
+
const result = data.map((item) => flattenObject(item));
|
|
18644
|
+
console.log({result});
|
|
18645
|
+
return result
|
|
18642
18646
|
} catch (err) {
|
|
18643
|
-
return errorMessageHandler(err,
|
|
18647
|
+
return errorMessageHandler(err, "DUNESIM");
|
|
18644
18648
|
}
|
|
18645
18649
|
}
|
|
18646
18650
|
|
|
18651
|
+
|
|
18652
|
+
// (async () => {
|
|
18653
|
+
// // Example: activity
|
|
18654
|
+
// // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
|
|
18655
|
+
// // console.log('Activity result:', res1, res1.length);
|
|
18656
|
+
|
|
18657
|
+
// // // Example: price (token-info)
|
|
18658
|
+
// // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
|
|
18659
|
+
// // console.log('Price result:', res2);
|
|
18660
|
+
|
|
18661
|
+
// // // Example: token holders
|
|
18662
|
+
// const res3 = await DUNESIM('token_holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "8453", 5);
|
|
18663
|
+
// console.log('Holders result:', res3, res3.length);
|
|
18664
|
+
// })();
|
|
18665
|
+
|
|
18647
18666
|
// export {GNOSISPAY} from './gnosispay/gnosispay.js'
|
|
18648
18667
|
|
|
18649
18668
|
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1269,7 +1269,6 @@ function ROWS(array) {
|
|
|
1269
1269
|
* @returns
|
|
1270
1270
|
*/
|
|
1271
1271
|
function SORT(array, sort_index = 1, sort_order = 1, by_col = false) {
|
|
1272
|
-
// Accept multiple sort keys like Google Sheets: SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
|
|
1273
1272
|
if (!array || !Array.isArray(array)) {
|
|
1274
1273
|
return na
|
|
1275
1274
|
}
|
|
@@ -1278,104 +1277,37 @@ function SORT(array, sort_index = 1, sort_order = 1, by_col = false) {
|
|
|
1278
1277
|
return 0
|
|
1279
1278
|
}
|
|
1280
1279
|
|
|
1281
|
-
|
|
1282
|
-
if (
|
|
1283
|
-
return name
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
// Collect sort keys (index and order). First key comes from sort_index/sort_order.
|
|
1287
|
-
const sortKeys = [];
|
|
1288
|
-
|
|
1289
|
-
const normalizeOrder = (o) => {
|
|
1290
|
-
// Try boolean first (TRUE -> ascending)
|
|
1291
|
-
const b = parseBool(o);
|
|
1292
|
-
if (typeof b === 'boolean') {
|
|
1293
|
-
return b ? 1 : -1
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
const n = parseNumber(o);
|
|
1297
|
-
if (n === 1 || n === -1) {
|
|
1298
|
-
return n
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
return null
|
|
1302
|
-
};
|
|
1303
|
-
|
|
1304
|
-
const firstIndex = parseNumber(sort_index);
|
|
1305
|
-
if (!firstIndex || firstIndex < 1) {
|
|
1280
|
+
sort_index = parseNumber(sort_index);
|
|
1281
|
+
if (!sort_index || sort_index < 1) {
|
|
1306
1282
|
return value
|
|
1307
1283
|
}
|
|
1308
1284
|
|
|
1309
|
-
|
|
1310
|
-
if (
|
|
1285
|
+
sort_order = parseNumber(sort_order);
|
|
1286
|
+
if (sort_order !== 1 && sort_order !== -1) {
|
|
1311
1287
|
return value
|
|
1312
1288
|
}
|
|
1313
1289
|
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
if (arguments.length > 4) {
|
|
1318
|
-
// arguments: 0=array,1=sort_index,2=sort_order,3=by_col,4=nextIndex,5=nextOrder,...
|
|
1319
|
-
for (let i = 4; i < arguments.length; i += 2) {
|
|
1320
|
-
const idx = parseNumber(arguments[i]);
|
|
1321
|
-
if (!idx || idx < 1) {
|
|
1322
|
-
return value
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
const ordArg = i + 1 < arguments.length ? arguments[i + 1] : 1;
|
|
1326
|
-
const ord = normalizeOrder(ordArg);
|
|
1327
|
-
if (ord === null) {
|
|
1328
|
-
return value
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
sortKeys.push({ index: idx, order: ord });
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
const matrix = fillMatrix(array);
|
|
1336
|
-
const working = by_col ? transpose(matrix) : matrix;
|
|
1337
|
-
|
|
1338
|
-
// Validate that all sort indexes are within column bounds
|
|
1339
|
-
const numCols = working[0] ? working[0].length : 0;
|
|
1340
|
-
for (const k of sortKeys) {
|
|
1341
|
-
if (k.index < 1 || k.index > numCols) {
|
|
1342
|
-
return value
|
|
1343
|
-
}
|
|
1290
|
+
by_col = parseBool(by_col);
|
|
1291
|
+
if (typeof by_col !== 'boolean') {
|
|
1292
|
+
return name
|
|
1344
1293
|
}
|
|
1345
1294
|
|
|
1346
|
-
const
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
if (typeof num === 'number' && !Number.isNaN(num)) return num
|
|
1351
|
-
return parseString(val)
|
|
1352
|
-
};
|
|
1353
|
-
|
|
1354
|
-
const comparator = (aRow, bRow) => {
|
|
1355
|
-
for (const k of sortKeys) {
|
|
1356
|
-
const aVal = parseForCompare(aRow[k.index - 1]);
|
|
1357
|
-
const bVal = parseForCompare(bRow[k.index - 1]);
|
|
1295
|
+
const sortArray = (arr) =>
|
|
1296
|
+
arr.sort((a, b) => {
|
|
1297
|
+
a = parseString(a[sort_index - 1]);
|
|
1298
|
+
b = parseString(b[sort_index - 1]);
|
|
1358
1299
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
// Numeric comparison if both are numbers
|
|
1362
|
-
if (typeof aVal === 'number' && typeof bVal === 'number') {
|
|
1363
|
-
return (aVal < bVal ? -1 : 1) * k.order
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
// String comparison
|
|
1367
|
-
const aStr = String(aVal).toLowerCase();
|
|
1368
|
-
const bStr = String(bVal).toLowerCase();
|
|
1369
|
-
return aStr.localeCompare(bStr) * k.order
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
return 0
|
|
1373
|
-
};
|
|
1300
|
+
return sort_order === 1 ? (a < b ? sort_order * -1 : sort_order) : a > b ? sort_order : sort_order * -1
|
|
1301
|
+
});
|
|
1374
1302
|
|
|
1375
|
-
|
|
1376
|
-
|
|
1303
|
+
const matrix = fillMatrix(array);
|
|
1304
|
+
const result = by_col ? transpose(matrix) : matrix;
|
|
1377
1305
|
|
|
1378
|
-
return
|
|
1306
|
+
return sort_index >= 1 && sort_index <= result[0].length
|
|
1307
|
+
? by_col
|
|
1308
|
+
? transpose(sortArray(result))
|
|
1309
|
+
: sortArray(result)
|
|
1310
|
+
: value
|
|
1379
1311
|
}
|
|
1380
1312
|
|
|
1381
1313
|
/**
|
|
@@ -18574,11 +18506,44 @@ async function TALLY() {
|
|
|
18574
18506
|
}
|
|
18575
18507
|
}
|
|
18576
18508
|
|
|
18577
|
-
const
|
|
18578
|
-
|
|
18579
|
-
|
|
18509
|
+
const historicalPrices = stringType()
|
|
18510
|
+
.regex(/^\s*(\d{1,2})(\s*,\s*\d{1,2}){0,2}\s*$/, "Up to 3 comma-separated hour offsets")
|
|
18511
|
+
.refine((s) => s.split(",").map((x) => +x.trim()).every((n) => n >= 1 && n <= 24), {
|
|
18512
|
+
message: "Each offset must be between 1 and 24",
|
|
18513
|
+
});
|
|
18514
|
+
|
|
18515
|
+
|
|
18516
|
+
|
|
18517
|
+
const activity = objectType({
|
|
18518
|
+
type: literalType("activity"),
|
|
18519
|
+
input1: stringType().nonempty(), // wallet address / ens name
|
|
18520
|
+
input2: stringType().optional(), // chain id. / name
|
|
18521
|
+
input3: numberType().int().min(1).max(100).optional(), // limit
|
|
18522
|
+
});
|
|
18523
|
+
|
|
18524
|
+
const tokenHolders = objectType({
|
|
18525
|
+
type: literalType("token_holders"),
|
|
18526
|
+
input1: stringType().nonempty(), // expects token address
|
|
18527
|
+
input2: stringType().nonempty(), // chain id / name
|
|
18528
|
+
input3: numberType().int().min(1).max(500).optional() // limit
|
|
18580
18529
|
});
|
|
18581
18530
|
|
|
18531
|
+
|
|
18532
|
+
const price = objectType({
|
|
18533
|
+
type: literalType("price"),
|
|
18534
|
+
input1: stringType().nonempty(), // chain name / id
|
|
18535
|
+
input2: historicalPrices.optional(), // history prices
|
|
18536
|
+
input3: stringType().optional(), // contract address
|
|
18537
|
+
input4: numberType().int().min(1).max(500).optional() // limit
|
|
18538
|
+
});
|
|
18539
|
+
|
|
18540
|
+
|
|
18541
|
+
const duneSimParamsSchema = discriminatedUnionType("type", [
|
|
18542
|
+
activity,
|
|
18543
|
+
price,
|
|
18544
|
+
tokenHolders
|
|
18545
|
+
]);
|
|
18546
|
+
|
|
18582
18547
|
function flattenObject(obj, parentKey = '', res = {}) {
|
|
18583
18548
|
for (let key in obj) {
|
|
18584
18549
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
@@ -18601,47 +18566,101 @@ function flattenObject(obj, parentKey = '', res = {}) {
|
|
|
18601
18566
|
return res;
|
|
18602
18567
|
}
|
|
18603
18568
|
|
|
18604
|
-
|
|
18569
|
+
const SUPPORTED_TOKEN_NAMES = {
|
|
18570
|
+
"eth": 1, // Ethereum Mainnet
|
|
18571
|
+
"base": 8453, // Base
|
|
18572
|
+
"polygon": 137, // Polygon
|
|
18573
|
+
"arbitrum": 42161, // Arbitrum One
|
|
18574
|
+
"optimism": 10, // Optimism
|
|
18575
|
+
"gnosis": 100, // Gnosis Chain (xDai)
|
|
18576
|
+
"bsc": 56, // Binance Smart Chain
|
|
18577
|
+
"avalanche": 43114, // Avalanche C-Chain
|
|
18578
|
+
"fantom": 250, // Fantom Opera
|
|
18579
|
+
"scroll": 534352, // Scroll
|
|
18580
|
+
"linea": 59144 // Linea
|
|
18581
|
+
};
|
|
18605
18582
|
|
|
18606
18583
|
|
|
18607
18584
|
|
|
18585
|
+
async function DUNESIM() {
|
|
18586
|
+
try {
|
|
18587
|
+
const [type, input1, input2, input3, input4] = argsToArray(arguments);
|
|
18588
|
+
|
|
18589
|
+
validateParams(duneSimParamsSchema, { type, input1, input2, input3, input4 });
|
|
18608
18590
|
|
|
18591
|
+
let route = "";
|
|
18609
18592
|
|
|
18593
|
+
// Helper to assemble query pieces
|
|
18594
|
+
const buildQuery = (pairs) => {
|
|
18595
|
+
const parts = pairs
|
|
18596
|
+
// eslint-disable-next-line no-unused-vars
|
|
18597
|
+
.filter(([_, v]) => v !== undefined && v !== '')
|
|
18598
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`);
|
|
18599
|
+
return parts.length ? `?${parts.join('&')}` : '';
|
|
18600
|
+
};
|
|
18610
18601
|
|
|
18602
|
+
if (type === 'activity') {
|
|
18603
|
+
const address = await fromEnsNameToAddress$1.validateAndGetAddress(input1);
|
|
18604
|
+
const qs = buildQuery([['chain_ids', SUPPORTED_TOKEN_NAMES[input2] || input2], ['limit', input3]]);
|
|
18605
|
+
route = `activity/${address}${qs}`;
|
|
18606
|
+
}
|
|
18611
18607
|
|
|
18612
|
-
|
|
18613
|
-
|
|
18614
|
-
|
|
18608
|
+
if (type === 'price') {
|
|
18609
|
+
const chain = SUPPORTED_TOKEN_NAMES[input1] || input2;
|
|
18610
|
+
const qs = buildQuery([
|
|
18611
|
+
['chain_ids', chain],
|
|
18612
|
+
['historical_prices', input3],
|
|
18613
|
+
['limit', input4],
|
|
18614
|
+
]);
|
|
18615
|
+
route = `token-info/native${qs}`;
|
|
18616
|
+
}
|
|
18617
|
+
|
|
18618
|
+
if (type === 'token_holders') {
|
|
18619
|
+
const qs = buildQuery([['limit', input3]]);
|
|
18620
|
+
const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
|
|
18621
|
+
route = `token-holders/${chain}/${input1}${qs}`;
|
|
18622
|
+
}
|
|
18615
18623
|
|
|
18616
|
-
validateParams(duneSimParamsSchema, { wallet, type });
|
|
18617
|
-
const address = await fromEnsNameToAddress$1.validateAndGetAddress(wallet);
|
|
18618
18624
|
const apiKey = window.localStorage.getItem(SERVICES_API_KEY.DuneSim);
|
|
18619
|
-
const url = `https://api.sim.dune.com/v1/evm
|
|
18625
|
+
const url = `https://api.sim.dune.com/v1/evm/${route}`;
|
|
18620
18626
|
|
|
18621
18627
|
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18622
|
-
url
|
|
18623
|
-
|
|
18624
|
-
'X-Sim-Api-Key': apiKey,
|
|
18625
|
-
}
|
|
18626
|
-
|
|
18628
|
+
url, serviceName: "DuneSim",
|
|
18629
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18627
18630
|
});
|
|
18628
18631
|
|
|
18629
|
-
const
|
|
18630
|
-
|
|
18631
|
-
headers: HEADERS,
|
|
18632
|
-
});
|
|
18633
|
-
if (!response.ok) {
|
|
18634
|
-
throw new NetworkError(SERVICES_API_KEY.DuneSim, response.status)
|
|
18635
|
-
}
|
|
18632
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18633
|
+
if (!res.ok) throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
|
|
18636
18634
|
|
|
18637
|
-
const json = await
|
|
18638
|
-
const
|
|
18639
|
-
|
|
18635
|
+
const json = await res.json();
|
|
18636
|
+
const data =
|
|
18637
|
+
type === "activity" ? json?.activity ?? json ?? [] :
|
|
18638
|
+
type === "token_holders" ? json?.holders ?? json ?? [] :
|
|
18639
|
+
type === "price" ? json?.tokens ?? json ?? [] :
|
|
18640
|
+
json ?? [];
|
|
18641
|
+
const result = data.map((item) => flattenObject(item));
|
|
18642
|
+
console.log({result});
|
|
18643
|
+
return result
|
|
18640
18644
|
} catch (err) {
|
|
18641
|
-
return errorMessageHandler(err,
|
|
18645
|
+
return errorMessageHandler(err, "DUNESIM");
|
|
18642
18646
|
}
|
|
18643
18647
|
}
|
|
18644
18648
|
|
|
18649
|
+
|
|
18650
|
+
// (async () => {
|
|
18651
|
+
// // Example: activity
|
|
18652
|
+
// // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
|
|
18653
|
+
// // console.log('Activity result:', res1, res1.length);
|
|
18654
|
+
|
|
18655
|
+
// // // Example: price (token-info)
|
|
18656
|
+
// // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
|
|
18657
|
+
// // console.log('Price result:', res2);
|
|
18658
|
+
|
|
18659
|
+
// // // Example: token holders
|
|
18660
|
+
// const res3 = await DUNESIM('token_holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "8453", 5);
|
|
18661
|
+
// console.log('Holders result:', res3, res3.length);
|
|
18662
|
+
// })();
|
|
18663
|
+
|
|
18645
18664
|
// export {GNOSISPAY} from './gnosispay/gnosispay.js'
|
|
18646
18665
|
|
|
18647
18666
|
|
package/package.json
CHANGED
package/types/cjs/index.d.cts
CHANGED
|
@@ -3788,7 +3788,7 @@ export function SMARTCONTRACT(...args: any[]): Promise<any>;
|
|
|
3788
3788
|
* @param {*} by_col Optional. A logical value indicating the desired sort direction; FALSE to sort by row (default), TRUE to sort by column
|
|
3789
3789
|
* @returns
|
|
3790
3790
|
*/
|
|
3791
|
-
export function SORT(array: any, sort_index?: any, sort_order?: any, by_col?: any
|
|
3791
|
+
export function SORT(array: any, sort_index?: any, sort_order?: any, by_col?: any): any;
|
|
3792
3792
|
/**
|
|
3793
3793
|
* Returns a positive square root.
|
|
3794
3794
|
*
|
package/types/esm/index.d.mts
CHANGED
|
@@ -3788,7 +3788,7 @@ export function SMARTCONTRACT(...args: any[]): Promise<any>;
|
|
|
3788
3788
|
* @param {*} by_col Optional. A logical value indicating the desired sort direction; FALSE to sort by row (default), TRUE to sort by column
|
|
3789
3789
|
* @returns
|
|
3790
3790
|
*/
|
|
3791
|
-
export function SORT(array: any, sort_index?: any, sort_order?: any, by_col?: any
|
|
3791
|
+
export function SORT(array: any, sort_index?: any, sort_order?: any, by_col?: any): any;
|
|
3792
3792
|
/**
|
|
3793
3793
|
* Returns a positive square root.
|
|
3794
3794
|
*
|