otomato-sdk 2.0.463 → 2.0.465

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.
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = '2.0.463';
1
+ export const SDK_VERSION = '2.0.465';
2
2
  export function compareVersions(v1, v2) {
3
3
  // Split the version strings into parts
4
4
  const v1Parts = v1.split('.').map(Number);
@@ -717,6 +717,85 @@ export function formatPriceWithDecimals(price, decimals) {
717
717
  }
718
718
  return price.toFixed(decimals);
719
719
  }
720
+ /**
721
+ * Format a price for display using magnitude-based rules with standard mathematical rounding.
722
+ *
723
+ * Rules:
724
+ * price >= 1000 → 0 decimal places
725
+ * price >= 100 → 1 decimal place
726
+ * price >= 10 → 2 decimal places
727
+ * price < 10 → 2 meaningful (non-zero) digits after leading zeros, rounded
728
+ *
729
+ * Unlike `formatNonZeroDecimals`, this function rounds instead of truncating.
730
+ *
731
+ * @param price - The price value to format.
732
+ * @returns The formatted price string.
733
+ */
734
+ export function formatDisplayPrice(price) {
735
+ if (!isFinite(price) || isNaN(price)) {
736
+ return String(price);
737
+ }
738
+ const absPrice = Math.abs(price);
739
+ const sign = price < 0 ? '-' : '';
740
+ if (absPrice === 0) {
741
+ return '0';
742
+ }
743
+ // Apply magnitude-based formatting, then re-check in case rounding
744
+ // pushes the value into a higher tier (e.g. 999.95 → "1000.0" should become "1000").
745
+ const formatted = formatByMagnitude(absPrice);
746
+ const rounded = parseFloat(formatted);
747
+ let result = formatted;
748
+ if (rounded !== absPrice && getMagnitudeTier(rounded) !== getMagnitudeTier(absPrice)) {
749
+ result = formatByMagnitude(rounded);
750
+ }
751
+ return sign + stripTrailingZeros(result);
752
+ }
753
+ function stripTrailingZeros(value) {
754
+ if (!value.includes('.'))
755
+ return value;
756
+ let result = value.replace(/0+$/, '');
757
+ if (result.endsWith('.'))
758
+ result = result.slice(0, -1);
759
+ return result;
760
+ }
761
+ function getMagnitudeTier(value) {
762
+ if (value >= 1000)
763
+ return 3;
764
+ if (value >= 100)
765
+ return 2;
766
+ if (value >= 10)
767
+ return 1;
768
+ return 0;
769
+ }
770
+ function formatByMagnitude(absPrice) {
771
+ if (absPrice >= 1000) {
772
+ return Math.round(absPrice).toString();
773
+ }
774
+ if (absPrice >= 100) {
775
+ return absPrice.toFixed(1);
776
+ }
777
+ if (absPrice >= 10) {
778
+ return absPrice.toFixed(2);
779
+ }
780
+ // For prices < 10: count leading zeros after decimal, then show 2 meaningful digits
781
+ const str = absPrice.toString();
782
+ const decimalIndex = str.indexOf('.');
783
+ if (decimalIndex === -1) {
784
+ return str;
785
+ }
786
+ const decimalPart = str.substring(decimalIndex + 1);
787
+ let leadingZeros = 0;
788
+ for (let i = 0; i < decimalPart.length; i++) {
789
+ if (decimalPart[i] === '0') {
790
+ leadingZeros++;
791
+ }
792
+ else {
793
+ break;
794
+ }
795
+ }
796
+ const decimals = leadingZeros + 2;
797
+ return absPrice.toFixed(decimals);
798
+ }
720
799
  /**
721
800
  * Rearrange token pair so stablecoin or gas asset is the quote token.
722
801
  */
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "2.0.463";
1
+ export declare const SDK_VERSION = "2.0.465";
2
2
  export declare function compareVersions(v1: string, v2: string): number;
@@ -203,6 +203,21 @@ export declare function formatPriceRange(price1: number | null | undefined, pric
203
203
  * Format a price with a specific number of decimal places.
204
204
  */
205
205
  export declare function formatPriceWithDecimals(price: number | null | undefined, decimals: number): string | null;
206
+ /**
207
+ * Format a price for display using magnitude-based rules with standard mathematical rounding.
208
+ *
209
+ * Rules:
210
+ * price >= 1000 → 0 decimal places
211
+ * price >= 100 → 1 decimal place
212
+ * price >= 10 → 2 decimal places
213
+ * price < 10 → 2 meaningful (non-zero) digits after leading zeros, rounded
214
+ *
215
+ * Unlike `formatNonZeroDecimals`, this function rounds instead of truncating.
216
+ *
217
+ * @param price - The price value to format.
218
+ * @returns The formatted price string.
219
+ */
220
+ export declare function formatDisplayPrice(price: number): string;
206
221
  export interface TokenPairInfo {
207
222
  symbol: string;
208
223
  address?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "2.0.463",
3
+ "version": "2.0.465",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "repository": {
6
6
  "type": "git",