@fileverse-dev/formulajs 4.4.12-mod-8 → 4.4.12-mod-9
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 +214 -53
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +59 -5
- package/lib/esm/index.mjs +59 -5
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -18594,6 +18594,23 @@ function formatNumber(raw, decimals) {
|
|
|
18594
18594
|
}).format(normalized);
|
|
18595
18595
|
}
|
|
18596
18596
|
|
|
18597
|
+
let cachedChains = null;
|
|
18598
|
+
async function getChainName(chainId){
|
|
18599
|
+
try {
|
|
18600
|
+
if (!cachedChains) {
|
|
18601
|
+
const res = await fetch("https://chainid.network/chains_mini.json");
|
|
18602
|
+
if (!res.ok) throw new Error("Failed to fetch chains.json");
|
|
18603
|
+
cachedChains = await res.json();
|
|
18604
|
+
}
|
|
18605
|
+
|
|
18606
|
+
const chain = cachedChains.find(c => c.chainId === chainId);
|
|
18607
|
+
return chain ? chain.name : chainId;
|
|
18608
|
+
} catch (error) {
|
|
18609
|
+
console.log(error);
|
|
18610
|
+
return chainId
|
|
18611
|
+
}
|
|
18612
|
+
}
|
|
18613
|
+
|
|
18597
18614
|
|
|
18598
18615
|
|
|
18599
18616
|
async function DUNESIM() {
|
|
@@ -18653,7 +18670,13 @@ async function DUNESIM() {
|
|
|
18653
18670
|
type === "token-holders" ? json?.holders ?? json ?? [] :
|
|
18654
18671
|
type === "price" ? json?.tokens ?? json ?? [] :
|
|
18655
18672
|
json ?? [];
|
|
18656
|
-
const result = (Array.isArray(data) ? data : [data])
|
|
18673
|
+
const result = (Array.isArray(data) ? data : [data]);
|
|
18674
|
+
|
|
18675
|
+
const final = [];
|
|
18676
|
+
|
|
18677
|
+
let globalDecimals;
|
|
18678
|
+
|
|
18679
|
+
for(let item of result){
|
|
18657
18680
|
if(item?.decimals){
|
|
18658
18681
|
if(item?.total_supply){
|
|
18659
18682
|
item.total_supply = formatNumber(item?.total_supply, item.decimals);
|
|
@@ -18676,9 +18699,40 @@ async function DUNESIM() {
|
|
|
18676
18699
|
item[key] = price;
|
|
18677
18700
|
});
|
|
18678
18701
|
}
|
|
18679
|
-
|
|
18680
|
-
|
|
18681
|
-
|
|
18702
|
+
|
|
18703
|
+
if(type === 'price'){
|
|
18704
|
+
delete item["chain_id"];
|
|
18705
|
+
delete item["decimals"];
|
|
18706
|
+
delete item["logo"];
|
|
18707
|
+
}
|
|
18708
|
+
if(type === 'activity'){
|
|
18709
|
+
item.chain_id = await getChainName(item.chain_id);
|
|
18710
|
+
}
|
|
18711
|
+
if(type === 'token-holders'){
|
|
18712
|
+
if(item.balance){
|
|
18713
|
+
if(!globalDecimals){
|
|
18714
|
+
try {
|
|
18715
|
+
const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
|
|
18716
|
+
const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
|
|
18717
|
+
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18718
|
+
url, serviceName: "DuneSim",
|
|
18719
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18720
|
+
});
|
|
18721
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18722
|
+
const resData = await res.json();
|
|
18723
|
+
const decimals = resData.tokens[0]?.decimals;
|
|
18724
|
+
globalDecimals = decimals;
|
|
18725
|
+
} catch (error) {
|
|
18726
|
+
console.log(error);
|
|
18727
|
+
}
|
|
18728
|
+
}
|
|
18729
|
+
item.balance = formatNumber(item.balance, globalDecimals);
|
|
18730
|
+
}
|
|
18731
|
+
}
|
|
18732
|
+
final.push(flattenObject(item));
|
|
18733
|
+
|
|
18734
|
+
}
|
|
18735
|
+
return final
|
|
18682
18736
|
} catch (err) {
|
|
18683
18737
|
return errorMessageHandler(err, "DUNESIM");
|
|
18684
18738
|
}
|
|
@@ -18695,7 +18749,7 @@ async function DUNESIM() {
|
|
|
18695
18749
|
// console.log('Price result:', res2);
|
|
18696
18750
|
|
|
18697
18751
|
// // Example: token holders
|
|
18698
|
-
// const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base",
|
|
18752
|
+
// const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 1);
|
|
18699
18753
|
// console.log('Holders result:', res3, res3.length);
|
|
18700
18754
|
})();
|
|
18701
18755
|
|
package/lib/esm/index.mjs
CHANGED
|
@@ -18592,6 +18592,23 @@ function formatNumber(raw, decimals) {
|
|
|
18592
18592
|
}).format(normalized);
|
|
18593
18593
|
}
|
|
18594
18594
|
|
|
18595
|
+
let cachedChains = null;
|
|
18596
|
+
async function getChainName(chainId){
|
|
18597
|
+
try {
|
|
18598
|
+
if (!cachedChains) {
|
|
18599
|
+
const res = await fetch("https://chainid.network/chains_mini.json");
|
|
18600
|
+
if (!res.ok) throw new Error("Failed to fetch chains.json");
|
|
18601
|
+
cachedChains = await res.json();
|
|
18602
|
+
}
|
|
18603
|
+
|
|
18604
|
+
const chain = cachedChains.find(c => c.chainId === chainId);
|
|
18605
|
+
return chain ? chain.name : chainId;
|
|
18606
|
+
} catch (error) {
|
|
18607
|
+
console.log(error);
|
|
18608
|
+
return chainId
|
|
18609
|
+
}
|
|
18610
|
+
}
|
|
18611
|
+
|
|
18595
18612
|
|
|
18596
18613
|
|
|
18597
18614
|
async function DUNESIM() {
|
|
@@ -18651,7 +18668,13 @@ async function DUNESIM() {
|
|
|
18651
18668
|
type === "token-holders" ? json?.holders ?? json ?? [] :
|
|
18652
18669
|
type === "price" ? json?.tokens ?? json ?? [] :
|
|
18653
18670
|
json ?? [];
|
|
18654
|
-
const result = (Array.isArray(data) ? data : [data])
|
|
18671
|
+
const result = (Array.isArray(data) ? data : [data]);
|
|
18672
|
+
|
|
18673
|
+
const final = [];
|
|
18674
|
+
|
|
18675
|
+
let globalDecimals;
|
|
18676
|
+
|
|
18677
|
+
for(let item of result){
|
|
18655
18678
|
if(item?.decimals){
|
|
18656
18679
|
if(item?.total_supply){
|
|
18657
18680
|
item.total_supply = formatNumber(item?.total_supply, item.decimals);
|
|
@@ -18674,9 +18697,40 @@ async function DUNESIM() {
|
|
|
18674
18697
|
item[key] = price;
|
|
18675
18698
|
});
|
|
18676
18699
|
}
|
|
18677
|
-
|
|
18678
|
-
|
|
18679
|
-
|
|
18700
|
+
|
|
18701
|
+
if(type === 'price'){
|
|
18702
|
+
delete item["chain_id"];
|
|
18703
|
+
delete item["decimals"];
|
|
18704
|
+
delete item["logo"];
|
|
18705
|
+
}
|
|
18706
|
+
if(type === 'activity'){
|
|
18707
|
+
item.chain_id = await getChainName(item.chain_id);
|
|
18708
|
+
}
|
|
18709
|
+
if(type === 'token-holders'){
|
|
18710
|
+
if(item.balance){
|
|
18711
|
+
if(!globalDecimals){
|
|
18712
|
+
try {
|
|
18713
|
+
const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
|
|
18714
|
+
const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
|
|
18715
|
+
const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
|
|
18716
|
+
url, serviceName: "DuneSim",
|
|
18717
|
+
headers: { "X-Sim-Api-Key": apiKey },
|
|
18718
|
+
});
|
|
18719
|
+
const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
|
|
18720
|
+
const resData = await res.json();
|
|
18721
|
+
const decimals = resData.tokens[0]?.decimals;
|
|
18722
|
+
globalDecimals = decimals;
|
|
18723
|
+
} catch (error) {
|
|
18724
|
+
console.log(error);
|
|
18725
|
+
}
|
|
18726
|
+
}
|
|
18727
|
+
item.balance = formatNumber(item.balance, globalDecimals);
|
|
18728
|
+
}
|
|
18729
|
+
}
|
|
18730
|
+
final.push(flattenObject(item));
|
|
18731
|
+
|
|
18732
|
+
}
|
|
18733
|
+
return final
|
|
18680
18734
|
} catch (err) {
|
|
18681
18735
|
return errorMessageHandler(err, "DUNESIM");
|
|
18682
18736
|
}
|
|
@@ -18693,7 +18747,7 @@ async function DUNESIM() {
|
|
|
18693
18747
|
// console.log('Price result:', res2);
|
|
18694
18748
|
|
|
18695
18749
|
// // Example: token holders
|
|
18696
|
-
// const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base",
|
|
18750
|
+
// const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 1);
|
|
18697
18751
|
// console.log('Holders result:', res3, res3.length);
|
|
18698
18752
|
})();
|
|
18699
18753
|
|