@fileverse-dev/formulajs 4.4.11-mod-21 → 4.4.11-mod-21-patch-2

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/cjs/index.cjs CHANGED
@@ -5226,6 +5226,75 @@ Z.TEST = (array, x, sigma) => {
5226
5226
  return 1 - NORM.S.DIST((AVERAGE(array) - x) / (sigma / Math.sqrt(n)), true)
5227
5227
  };
5228
5228
 
5229
+ function PNL() {
5230
+ const [A, B] = argsToArray(arguments);
5231
+
5232
+ const toNumberOrThrow = (val) => {
5233
+ const num = Number(val);
5234
+ if (isNaN(num)) throw new Error(`Invalid number value: ${val}`);
5235
+ return num;
5236
+ };
5237
+
5238
+ // Single numbers
5239
+ if (typeof A === "number" && typeof B === "number") {
5240
+ return A - B;
5241
+ }
5242
+
5243
+ // 1D arrays
5244
+ if (Array.isArray(A) && Array.isArray(B) && typeof A[0] !== "object") {
5245
+ const maxLen = Math.max(A.length, B.length);
5246
+ let total = 0;
5247
+ for (let i = 0; i < maxLen; i++) {
5248
+ const aVal = i < A.length ? toNumberOrThrow(A[i]) : 0;
5249
+ const bVal = i < B.length ? toNumberOrThrow(B[i]) : 0;
5250
+ total += aVal - bVal;
5251
+ }
5252
+ return total;
5253
+ }
5254
+
5255
+ // 2D arrays
5256
+ if (Array.isArray(A[0]) && typeof A[0][0] !== "object") {
5257
+ let total = 0;
5258
+ const maxRows = Math.max(A.length, B.length);
5259
+ for (let i = 0; i < maxRows; i++) {
5260
+ const rowA = A[i] || [];
5261
+ const rowB = B[i] || [];
5262
+ const maxCols = Math.max(rowA.length, rowB.length);
5263
+ for (let j = 0; j < maxCols; j++) {
5264
+ const aVal = j < rowA.length ? toNumberOrThrow(rowA[j]) : 0;
5265
+ const bVal = j < rowB.length ? toNumberOrThrow(rowB[j]) : 0;
5266
+ total += aVal - bVal;
5267
+ }
5268
+ }
5269
+ return total;
5270
+ }
5271
+
5272
+ // 3D arrays
5273
+ if (Array.isArray(A[0][0])) {
5274
+ let total = 0;
5275
+ const maxX = Math.max(A.length, B.length);
5276
+ for (let i = 0; i < maxX; i++) {
5277
+ const matA = A[i] || [];
5278
+ const matB = B[i] || [];
5279
+ const maxY = Math.max(matA.length, matB.length);
5280
+ for (let j = 0; j < maxY; j++) {
5281
+ const rowA = matA[j] || [];
5282
+ const rowB = matB[j] || [];
5283
+ const maxZ = Math.max(rowA.length, rowB.length);
5284
+ for (let k = 0; k < maxZ; k++) {
5285
+ const aVal = k < rowA.length ? toNumberOrThrow(rowA[k]) : 0;
5286
+ const bVal = k < rowB.length ? toNumberOrThrow(rowB[k]) : 0;
5287
+ total += aVal - bVal;
5288
+ }
5289
+ }
5290
+ }
5291
+ return total;
5292
+ }
5293
+
5294
+ throw new Error("Unsupported or mismatched structure");
5295
+ }
5296
+
5297
+
5229
5298
  /**
5230
5299
  * Returns the absolute value of a number.
5231
5300
  *
@@ -13011,13 +13080,25 @@ function SWITCH() {
13011
13080
  const SERVICE_API_KEY = {
13012
13081
  Etherscan: "ETHERSCAN_API_KEY",
13013
13082
  Coingecko: "COINGECKO_API_KEY",
13083
+ Safe: "SAFE_API_KEY",
13014
13084
  };
13015
13085
 
13016
13086
  const CHAIN_ID_MAP = {
13017
- ethereum: 1,
13018
- gnosis: 100,
13019
- base: 8453,
13020
- };
13087
+ ethereum: 1,
13088
+ gnosis: 100,
13089
+ base: 8453,
13090
+ };
13091
+
13092
+ const SAFE_CHAIN_MAP = {
13093
+ ethereum: 'eth',
13094
+ gnosis: 'gno',
13095
+ };
13096
+
13097
+ const ERROR_MESSAGES_FLAG = {
13098
+ INVALID_API_KEY: '_MISSING',
13099
+ RATE_LIMIT: '_RATE_LIMIT_REACHED',
13100
+ DEFAULT: 'FETCH_ERROR'
13101
+ };
13021
13102
 
13022
13103
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
13023
13104
  if(!timestamp || !chain || !apiKey) return
@@ -13030,28 +13111,32 @@ if(!timestamp || !chain || !apiKey) return
13030
13111
  };
13031
13112
 
13032
13113
  async function ETHERSCAN(address, page, offset) {
13033
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
13034
- const url = `https://api.etherscan.io/v2/api?chainid=1&module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page || 1}&offset=${offset || 10}&sort=asc&apikey=${API_KEY}`;
13035
-
13036
- try {
13037
- const response = await fetch(url);
13038
- if (!response.ok) {
13039
- throw new Error(`HTTP error! Status: ${response.status}`)
13040
- }
13041
- const json = await response.json();
13042
- if (json.result.includes("Invalid API Key")) {
13043
- return `${SERVICE_API_KEY.Etherscan}_MISSING`
13044
- }
13045
- /*
13046
- [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
13047
- */
13048
- return json.result;
13049
- } catch (error) {
13050
- return "ERROR IN FETCHING"
13051
- }
13052
- }
13053
-
13054
- async function GETPRICE(token, vs_currencies) {
13114
+ return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13115
+ // const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
13116
+ // const url = `https://api.etherscan.io/v2/api?chainid=1&module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page || 1}&offset=${offset || 10}&sort=asc&apikey=${API_KEY}`
13117
+
13118
+ // try {
13119
+ // const response = await fetch(url)
13120
+ // if (!response.ok) {
13121
+ // throw new Error(`HTTP error! Status: ${response.status}`)
13122
+ // }
13123
+ // const json = await response.json()
13124
+ // if (json.result.includes("Invalid API Key")) {
13125
+ // return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.INVALID_API_KEY}`
13126
+ // }
13127
+ // if(json.result.includes('Max rate limit reached')){
13128
+ // return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13129
+ // }
13130
+ // /*
13131
+ // [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
13132
+ // */
13133
+ // return json.result;
13134
+ // } catch (error) {
13135
+ // return ERROR_MESSAGES_FLAG.DEFAULT
13136
+ // }
13137
+ }
13138
+
13139
+ async function COINGECKO(token, vs_currencies) {
13055
13140
  const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
13056
13141
  const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
13057
13142
 
@@ -13065,7 +13150,10 @@ async function GETPRICE(token, vs_currencies) {
13065
13150
  if (!response.ok) {
13066
13151
  const json = await response.json();
13067
13152
  if (json.status.error_message.includes("API Key Missing")) {
13068
- return `${SERVICE_API_KEY.Coingecko}_MISSING`
13153
+ return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.INVALID_API_KEY}`
13154
+ }
13155
+ if(response.status === 429){
13156
+ return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13069
13157
  }
13070
13158
  }
13071
13159
  const jsonResponse = await response.json();
@@ -13084,7 +13172,7 @@ async function GETPRICE(token, vs_currencies) {
13084
13172
  */
13085
13173
  return [output];
13086
13174
  } catch (error) {
13087
- return "ERROR IN FETCHING"
13175
+ return ERROR_MESSAGES_FLAG.DEFAULT
13088
13176
  }
13089
13177
  }
13090
13178
 
@@ -13100,12 +13188,12 @@ async function EOA(address, categories, chain, startTime, endTime) {
13100
13188
 
13101
13189
  let action = '';
13102
13190
  if (categories === 'txns') action = 'account.txlist';
13103
- else {action = 'account.balance';} let timeQuery = '';
13104
- if(!isNaN(startTime) && !isNaN(endTime)){
13105
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13106
- const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13191
+ else { action = 'account.balance'; } let timeQuery = '';
13192
+ if (!isNaN(startTime) && !isNaN(endTime)) {
13193
+ const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13194
+ const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13107
13195
  timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13108
- } else if(categories === 'balance') {
13196
+ } else if (categories === 'balance') {
13109
13197
  timeQuery = `&tag=latest`;
13110
13198
  } else {
13111
13199
  throw new Error('Start and End Time is required for querying transaction list ')
@@ -13118,91 +13206,62 @@ async function EOA(address, categories, chain, startTime, endTime) {
13118
13206
  if (json.result?.includes?.("Invalid API Key")) {
13119
13207
  return `${SERVICE_API_KEY[chain.charAt(0).toUpperCase() + chain.slice(1)]}_MISSING`;
13120
13208
  }
13209
+ if(json.result.includes('Max rate limit reached')){
13210
+ return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13211
+ }
13121
13212
  return json.result;
13122
13213
  } catch (e) {
13123
13214
  console.log(e);
13124
- return "ERROR IN FETCHING";
13215
+ return ERROR_MESSAGES_FLAG.DEFAULT;
13125
13216
  }
13126
13217
  }
13127
13218
 
13128
13219
 
13129
- function PNL() {
13130
- const [A, B] = argsToArray(arguments);
13131
-
13132
- const toNumberOrThrow = (val) => {
13133
- const num = Number(val);
13134
- if (isNaN(num)) throw new Error(`Invalid number value: ${val}`);
13135
- return num;
13136
- };
13137
-
13138
- // Single numbers
13139
- if (typeof A === "number" && typeof B === "number") {
13140
- return A - B;
13141
- }
13142
-
13143
- // 1D arrays
13144
- if (Array.isArray(A) && Array.isArray(B) && typeof A[0] !== "object") {
13145
- const maxLen = Math.max(A.length, B.length);
13146
- let total = 0;
13147
- for (let i = 0; i < maxLen; i++) {
13148
- const aVal = i < A.length ? toNumberOrThrow(A[i]) : 0;
13149
- const bVal = i < B.length ? toNumberOrThrow(B[i]) : 0;
13150
- total += aVal - bVal;
13151
- }
13152
- return total;
13153
- }
13154
-
13155
- // 2D arrays
13156
- if (Array.isArray(A[0]) && typeof A[0][0] !== "object") {
13157
- let total = 0;
13158
- const maxRows = Math.max(A.length, B.length);
13159
- for (let i = 0; i < maxRows; i++) {
13160
- const rowA = A[i] || [];
13161
- const rowB = B[i] || [];
13162
- const maxCols = Math.max(rowA.length, rowB.length);
13163
- for (let j = 0; j < maxCols; j++) {
13164
- const aVal = j < rowA.length ? toNumberOrThrow(rowA[j]) : 0;
13165
- const bVal = j < rowB.length ? toNumberOrThrow(rowB[j]) : 0;
13166
- total += aVal - bVal;
13167
- }
13168
- }
13169
- return total;
13170
- }
13171
-
13172
- // 3D arrays
13173
- if (Array.isArray(A[0][0])) {
13174
- let total = 0;
13175
- const maxX = Math.max(A.length, B.length);
13176
- for (let i = 0; i < maxX; i++) {
13177
- const matA = A[i] || [];
13178
- const matB = B[i] || [];
13179
- const maxY = Math.max(matA.length, matB.length);
13180
- for (let j = 0; j < maxY; j++) {
13181
- const rowA = matA[j] || [];
13182
- const rowB = matB[j] || [];
13183
- const maxZ = Math.max(rowA.length, rowB.length);
13184
- for (let k = 0; k < maxZ; k++) {
13185
- const aVal = k < rowA.length ? toNumberOrThrow(rowA[k]) : 0;
13186
- const bVal = k < rowB.length ? toNumberOrThrow(rowB[k]) : 0;
13187
- total += aVal - bVal;
13188
- }
13189
- }
13190
- }
13191
- return total;
13192
- }
13193
13220
 
13194
- throw new Error("Unsupported or mismatched structure");
13195
- }
13196
13221
 
13197
13222
 
13198
13223
  async function FLVURL(token, vs_currencies) {
13199
13224
  return new Promise((resolve) => {
13200
13225
  setTimeout(() => {
13201
- resolve([{"Yoo": "gotcha"}]);
13226
+ resolve([{ "Yoo": "gotcha" }]);
13202
13227
  }, 10000);
13203
13228
  });
13204
13229
  }
13205
13230
 
13231
+ async function SAFE(address, utility, chain, limit, offset) {
13232
+
13233
+ if (typeof limit !== 'number' || limit < 0) return 'INVALID_LIMIT';
13234
+ if (typeof offset !== 'number' || offset < 0) return 'INVALID_OFFSET';
13235
+ if (utility !== 'txns') return 'UTILITY IS NOT SUPPORTED';
13236
+
13237
+ const apiKey = window.localStorage.getItem(SERVICE_API_KEY.Safe);
13238
+ const chainIdentifier = SAFE_CHAIN_MAP[chain];
13239
+
13240
+ if (!apiKey) return `${SERVICE_API_KEY.Safe}_MISSING`;
13241
+ if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED';
13242
+
13243
+ const url = `https://api.safe.global/tx-service/${chainIdentifier}/api/v2/safes/${address}/multisig-transactions?limit=${limit}&offset=${offset}`;
13244
+ try {
13245
+ const response = await fetch(url,
13246
+ {
13247
+ headers: {
13248
+ 'Authorization': `Bearer ${apiKey}`,
13249
+ },
13250
+ }
13251
+ );
13252
+ if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
13253
+ const json = await response.json();
13254
+ if (!Array.isArray(json.results)) {
13255
+ return "INVALID API RESPONSE";
13256
+ }
13257
+ // remove nested structure from the response
13258
+ return json.results.map(({ confirmations, dataDecoded, ...rest }) => rest);
13259
+ } catch (e) {
13260
+ console.log(e);
13261
+ return "ERROR IN FETCHING";
13262
+ }
13263
+ }
13264
+
13206
13265
  const utils = { errors, symbols, date };
13207
13266
 
13208
13267
  exports.ABS = ABS;
@@ -13255,6 +13314,7 @@ exports.CHITEST = CHITEST;
13255
13314
  exports.CHOOSE = CHOOSE;
13256
13315
  exports.CLEAN = CLEAN;
13257
13316
  exports.CODE = CODE;
13317
+ exports.COINGECKO = COINGECKO;
13258
13318
  exports.COLUMN = COLUMN;
13259
13319
  exports.COLUMNS = COLUMNS;
13260
13320
  exports.COMBIN = COMBIN;
@@ -13360,7 +13420,6 @@ exports.GAUSS = GAUSS;
13360
13420
  exports.GCD = GCD;
13361
13421
  exports.GEOMEAN = GEOMEAN;
13362
13422
  exports.GESTEP = GESTEP;
13363
- exports.GETPRICE = GETPRICE;
13364
13423
  exports.GROWTH = GROWTH;
13365
13424
  exports.HARMEAN = HARMEAN;
13366
13425
  exports.HEX2BIN = HEX2BIN;
@@ -13522,6 +13581,7 @@ exports.ROW = ROW;
13522
13581
  exports.ROWS = ROWS;
13523
13582
  exports.RRI = RRI;
13524
13583
  exports.RSQ = RSQ;
13584
+ exports.SAFE = SAFE;
13525
13585
  exports.SEARCH = SEARCH;
13526
13586
  exports.SEC = SEC;
13527
13587
  exports.SECH = SECH;
@@ -1,7 +1,8 @@
1
1
  // src/crypto-constants.js
2
2
  var SERVICE_API_KEY = {
3
3
  Etherscan: "ETHERSCAN_API_KEY",
4
- Coingecko: "COINGECKO_API_KEY"
4
+ Coingecko: "COINGECKO_API_KEY",
5
+ Safe: "SAFE_API_KEY"
5
6
  };
6
7
  var FUNCTION_LOCALE = [
7
8
  {
@@ -83,7 +84,7 @@ var FUNCTION_LOCALE = [
83
84
  ]
84
85
  },
85
86
  {
86
- n: "GETPRICE",
87
+ n: "COINGECKO",
87
88
  t: 20,
88
89
  API_KEY: SERVICE_API_KEY.Coingecko,
89
90
  d: "Query the prices of one or more coins by using their unique Coin API IDs, symbols, or names.",
@@ -123,6 +124,46 @@ var FUNCTION_LOCALE = [
123
124
  }
124
125
  ]
125
126
  },
127
+ {
128
+ n: "SAFE",
129
+ t: 20,
130
+ d: "Query the list of transactions performed by a Safe address, with optional pagination.",
131
+ a: "Query the list of transactions performed by a Safe address, with optional pagination.",
132
+ p: [
133
+ {
134
+ name: "address",
135
+ detail: "The address to query, in hexadecimal format.",
136
+ example: `"0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC"`,
137
+ require: "m"
138
+ },
139
+ {
140
+ name: "utility",
141
+ detail: "The utility to query, supported values: 'txns'.",
142
+ example: `"txns"`,
143
+ require: "m"
144
+ },
145
+ {
146
+ name: "chain",
147
+ detail: "The chain to query, supported values: 'ethereum', 'gnosis'.",
148
+ example: `"ethereum"`,
149
+ require: "m"
150
+ },
151
+ {
152
+ name: "limit",
153
+ detail: "The number of transactions to return, default is 100.",
154
+ example: `100`,
155
+ require: "o",
156
+ repeat: "n"
157
+ },
158
+ {
159
+ name: "offset",
160
+ detail: "The number of transactions to skip, default is 0.",
161
+ example: `0`,
162
+ require: "o",
163
+ repeat: "n"
164
+ }
165
+ ]
166
+ },
126
167
  {
127
168
  n: "PNL",
128
169
  t: 20,