otomato-sdk 2.0.364 → 2.0.365
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.
|
@@ -78,9 +78,10 @@ export function getComputeERC20Variable(amount, chainId, contractAddress) {
|
|
|
78
78
|
*
|
|
79
79
|
* @param value - The number to format.
|
|
80
80
|
* @param nonZeroDecimals - The number of non-zero decimal digits to show (default is 2).
|
|
81
|
+
* @param maxLeadingZeros - The maximum number of leading zeros after decimal point before rounding (default is -1 for no limit).
|
|
81
82
|
* @returns string - The formatted number as a string.
|
|
82
83
|
*/
|
|
83
|
-
export function formatNonZeroDecimals(value, nonZeroDecimals = 2) {
|
|
84
|
+
export function formatNonZeroDecimals(value, nonZeroDecimals = 2, maxLeadingZeros = -1) {
|
|
84
85
|
if (value === 0) {
|
|
85
86
|
return "0";
|
|
86
87
|
}
|
|
@@ -104,17 +105,28 @@ export function formatNonZeroDecimals(value, nonZeroDecimals = 2) {
|
|
|
104
105
|
}
|
|
105
106
|
const integerPart = str.substring(0, decimalIndex);
|
|
106
107
|
const decimalPart = str.substring(decimalIndex + 1);
|
|
107
|
-
|
|
108
|
-
let
|
|
108
|
+
// Count leading zeros after decimal point
|
|
109
|
+
let leadingZeros = 0;
|
|
109
110
|
for (let i = 0; i < decimalPart.length; i++) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
nonZeroCount++;
|
|
113
|
-
if (nonZeroCount === nonZeroDecimals) {
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
111
|
+
if (decimalPart[i] === '0') {
|
|
112
|
+
leadingZeros++;
|
|
116
113
|
}
|
|
114
|
+
else {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// If leading zeros exceed threshold, round the number
|
|
119
|
+
if (maxLeadingZeros !== -1 && leadingZeros > maxLeadingZeros) {
|
|
120
|
+
const rounded = Math.round(absValue);
|
|
121
|
+
return sign + rounded.toString();
|
|
117
122
|
}
|
|
123
|
+
let result = integerPart + ".";
|
|
124
|
+
// Add leading zeros
|
|
125
|
+
result += decimalPart.substring(0, leadingZeros);
|
|
126
|
+
// Take up to nonZeroDecimals non-zero decimal places after leading zeros
|
|
127
|
+
const remainingDigits = decimalPart.substring(leadingZeros);
|
|
128
|
+
const maxDigits = Math.min(nonZeroDecimals, remainingDigits.length);
|
|
129
|
+
result += remainingDigits.substring(0, maxDigits);
|
|
118
130
|
// Remove trailing zeros and decimal point if needed
|
|
119
131
|
result = result.replace(/\.?0+$/, '');
|
|
120
132
|
if (result.endsWith('.')) {
|
|
@@ -123,6 +135,12 @@ export function formatNonZeroDecimals(value, nonZeroDecimals = 2) {
|
|
|
123
135
|
return sign + result;
|
|
124
136
|
}
|
|
125
137
|
export const getTokenPrice = async (chainId, contractAddress) => {
|
|
138
|
+
if (chainId === 999) {
|
|
139
|
+
const tokenPriceList = await fetch(`https://li.quest/v1/tokens?chains=999`);
|
|
140
|
+
const tokenPriceListJson = await tokenPriceList.json();
|
|
141
|
+
const tokenPrice = tokenPriceListJson.tokens?.[999]?.find((token) => token.address === contractAddress);
|
|
142
|
+
return tokenPrice?.priceUSD;
|
|
143
|
+
}
|
|
126
144
|
const tokenPrice = await fetch(`https://api.odos.xyz/pricing/token/${chainId}/${contractAddress}`);
|
|
127
145
|
const tokenPriceJson = await tokenPrice.json();
|
|
128
146
|
return tokenPriceJson?.price;
|
|
@@ -144,7 +162,8 @@ export const getETHAlternativeTokensSymbols = () => {
|
|
|
144
162
|
146: "WETH",
|
|
145
163
|
56: "ETH",
|
|
146
164
|
250: "ETH",
|
|
147
|
-
252: "frxETH"
|
|
165
|
+
252: "frxETH",
|
|
166
|
+
999: "ETH"
|
|
148
167
|
};
|
|
149
168
|
};
|
|
150
169
|
/**
|
|
@@ -436,3 +455,18 @@ export const jsonStringifyCircularObject = async (obj) => {
|
|
|
436
455
|
console.log("[obj] Could not inspect obj object due to:", err);
|
|
437
456
|
}
|
|
438
457
|
};
|
|
458
|
+
export const callWithRetry = async (callback, maxRetries = 3, retryDelayMs = 1000) => {
|
|
459
|
+
let retryCount = 0;
|
|
460
|
+
while (retryCount <= maxRetries) {
|
|
461
|
+
try {
|
|
462
|
+
return await callback();
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
retryCount++;
|
|
466
|
+
if (retryCount >= maxRetries) {
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
await new Promise(resolve => setTimeout(resolve, retryDelayMs));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.365";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -31,9 +31,10 @@ export declare function getComputeERC20Variable(amount: string, chainId: any, co
|
|
|
31
31
|
*
|
|
32
32
|
* @param value - The number to format.
|
|
33
33
|
* @param nonZeroDecimals - The number of non-zero decimal digits to show (default is 2).
|
|
34
|
+
* @param maxLeadingZeros - The maximum number of leading zeros after decimal point before rounding (default is -1 for no limit).
|
|
34
35
|
* @returns string - The formatted number as a string.
|
|
35
36
|
*/
|
|
36
|
-
export declare function formatNonZeroDecimals(value: number, nonZeroDecimals?: number): string;
|
|
37
|
+
export declare function formatNonZeroDecimals(value: number, nonZeroDecimals?: number, maxLeadingZeros?: number): string;
|
|
37
38
|
export declare const getTokenPrice: (chainId: number, contractAddress: string) => Promise<number>;
|
|
38
39
|
export declare const getETHAlternativeTokensSymbols: () => {
|
|
39
40
|
1: string;
|
|
@@ -52,6 +53,7 @@ export declare const getETHAlternativeTokensSymbols: () => {
|
|
|
52
53
|
56: string;
|
|
53
54
|
250: string;
|
|
54
55
|
252: string;
|
|
56
|
+
999: string;
|
|
55
57
|
};
|
|
56
58
|
/**
|
|
57
59
|
* Formats a period in seconds into a human-readable string with days, hours, minutes, and seconds.
|
|
@@ -122,3 +124,4 @@ export declare const getComparisonString: (condition: string, comparisonValue: s
|
|
|
122
124
|
export declare const findNewElements: (oldArray: string[], newArray: string[]) => string[];
|
|
123
125
|
export declare const createEthersContract: (chainId: number, contractAddress: string, abi: any[], rpcUrl?: string) => ethers.Contract;
|
|
124
126
|
export declare const jsonStringifyCircularObject: (obj: any) => Promise<void>;
|
|
127
|
+
export declare const callWithRetry: (callback: () => Promise<any>, maxRetries?: number, retryDelayMs?: number) => Promise<any>;
|