@fileverse-dev/formulajs 4.4.12-mod-3 → 4.4.12-mod-4
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 +106 -31
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +114 -27
- package/lib/esm/index.mjs +114 -27
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -18508,11 +18508,44 @@ async function TALLY() {
|
|
|
18508
18508
|
}
|
|
18509
18509
|
}
|
|
18510
18510
|
|
|
18511
|
-
const
|
|
18512
|
-
|
|
18513
|
-
|
|
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
|
|
18514
18531
|
});
|
|
18515
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
|
+
|
|
18516
18549
|
function flattenObject(obj, parentKey = '', res = {}) {
|
|
18517
18550
|
for (let key in obj) {
|
|
18518
18551
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
@@ -18535,47 +18568,101 @@ function flattenObject(obj, parentKey = '', res = {}) {
|
|
|
18535
18568
|
return res;
|
|
18536
18569
|
}
|
|
18537
18570
|
|
|
18538
|
-
|
|
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
|
+
};
|
|
18539
18584
|
|
|
18540
18585
|
|
|
18541
18586
|
|
|
18587
|
+
async function DUNESIM() {
|
|
18588
|
+
try {
|
|
18589
|
+
const [type, input1, input2, input3, input4] = argsToArray(arguments);
|
|
18542
18590
|
|
|
18591
|
+
validateParams(duneSimParamsSchema, { type, input1, input2, input3, input4 });
|
|
18543
18592
|
|
|
18593
|
+
let route = "";
|
|
18544
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
|
+
};
|
|
18545
18603
|
|
|
18546
|
-
|
|
18547
|
-
|
|
18548
|
-
|
|
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
|
+
}
|
|
18549
18609
|
|
|
18550
|
-
|
|
18551
|
-
|
|
18552
|
-
|
|
18553
|
-
|
|
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
|
+
}
|
|
18625
|
+
|
|
18626
|
+
const apiKey = "sim_pMrywDRiseEAGd6qOWbyMmwLnnlvC5EA";
|
|
18627
|
+
const url = `https://api.sim.dune.com/v1/evm/${route}`;
|
|
18554
18628
|
|
|
18555
18629
|
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18556
|
-
url
|
|
18557
|
-
|
|
18558
|
-
'X-Sim-Api-Key': apiKey,
|
|
18559
|
-
}
|
|
18560
|
-
|
|
18630
|
+
url, serviceName: "DuneSim",
|
|
18631
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18561
18632
|
});
|
|
18562
18633
|
|
|
18563
|
-
const
|
|
18564
|
-
|
|
18565
|
-
headers: HEADERS,
|
|
18566
|
-
});
|
|
18567
|
-
if (!response.ok) {
|
|
18568
|
-
throw new NetworkError(SERVICES_API_KEY.DuneSim, response.status)
|
|
18569
|
-
}
|
|
18634
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18635
|
+
if (!res.ok) throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
|
|
18570
18636
|
|
|
18571
|
-
const json = await
|
|
18572
|
-
const
|
|
18573
|
-
|
|
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
|
|
18574
18646
|
} catch (err) {
|
|
18575
|
-
return errorMessageHandler(err,
|
|
18647
|
+
return errorMessageHandler(err, "DUNESIM");
|
|
18576
18648
|
}
|
|
18577
18649
|
}
|
|
18578
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
|
+
|
|
18579
18666
|
// export {GNOSISPAY} from './gnosispay/gnosispay.js'
|
|
18580
18667
|
|
|
18581
18668
|
|
package/lib/esm/index.mjs
CHANGED
|
@@ -18506,11 +18506,44 @@ async function TALLY() {
|
|
|
18506
18506
|
}
|
|
18507
18507
|
}
|
|
18508
18508
|
|
|
18509
|
-
const
|
|
18510
|
-
|
|
18511
|
-
|
|
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
|
|
18512
18529
|
});
|
|
18513
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
|
+
|
|
18514
18547
|
function flattenObject(obj, parentKey = '', res = {}) {
|
|
18515
18548
|
for (let key in obj) {
|
|
18516
18549
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
@@ -18533,47 +18566,101 @@ function flattenObject(obj, parentKey = '', res = {}) {
|
|
|
18533
18566
|
return res;
|
|
18534
18567
|
}
|
|
18535
18568
|
|
|
18536
|
-
|
|
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
|
+
};
|
|
18537
18582
|
|
|
18538
18583
|
|
|
18539
18584
|
|
|
18585
|
+
async function DUNESIM() {
|
|
18586
|
+
try {
|
|
18587
|
+
const [type, input1, input2, input3, input4] = argsToArray(arguments);
|
|
18540
18588
|
|
|
18589
|
+
validateParams(duneSimParamsSchema, { type, input1, input2, input3, input4 });
|
|
18541
18590
|
|
|
18591
|
+
let route = "";
|
|
18542
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
|
+
};
|
|
18543
18601
|
|
|
18544
|
-
|
|
18545
|
-
|
|
18546
|
-
|
|
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
|
+
}
|
|
18547
18607
|
|
|
18548
|
-
|
|
18549
|
-
|
|
18550
|
-
|
|
18551
|
-
|
|
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
|
+
}
|
|
18623
|
+
|
|
18624
|
+
const apiKey = "sim_pMrywDRiseEAGd6qOWbyMmwLnnlvC5EA";
|
|
18625
|
+
const url = `https://api.sim.dune.com/v1/evm/${route}`;
|
|
18552
18626
|
|
|
18553
18627
|
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18554
|
-
url
|
|
18555
|
-
|
|
18556
|
-
'X-Sim-Api-Key': apiKey,
|
|
18557
|
-
}
|
|
18558
|
-
|
|
18628
|
+
url, serviceName: "DuneSim",
|
|
18629
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18559
18630
|
});
|
|
18560
18631
|
|
|
18561
|
-
const
|
|
18562
|
-
|
|
18563
|
-
headers: HEADERS,
|
|
18564
|
-
});
|
|
18565
|
-
if (!response.ok) {
|
|
18566
|
-
throw new NetworkError(SERVICES_API_KEY.DuneSim, response.status)
|
|
18567
|
-
}
|
|
18632
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18633
|
+
if (!res.ok) throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
|
|
18568
18634
|
|
|
18569
|
-
const json = await
|
|
18570
|
-
const
|
|
18571
|
-
|
|
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
|
|
18572
18644
|
} catch (err) {
|
|
18573
|
-
return errorMessageHandler(err,
|
|
18645
|
+
return errorMessageHandler(err, "DUNESIM");
|
|
18574
18646
|
}
|
|
18575
18647
|
}
|
|
18576
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
|
+
|
|
18577
18664
|
// export {GNOSISPAY} from './gnosispay/gnosispay.js'
|
|
18578
18665
|
|
|
18579
18666
|
|