@provex/utils 1.0.16 → 1.2.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.
Files changed (149) hide show
  1. package/dist/chain.d.ts +446 -0
  2. package/dist/chain.js +98 -0
  3. package/dist/chain.test.js +112 -0
  4. package/dist/contracts.d.ts +206 -0
  5. package/dist/contracts.js +292 -0
  6. package/dist/contracts.test.js +243 -0
  7. package/dist/conversionRates.d.ts +215 -0
  8. package/dist/{src/conversionRates.js → conversionRates.js} +74 -4
  9. package/dist/conversionRates.test.js +473 -0
  10. package/dist/currencies.d.ts +248 -0
  11. package/dist/{src/currencies.js → currencies.js} +119 -38
  12. package/dist/currencies.test.js +343 -0
  13. package/dist/data/countries.json +1099 -0
  14. package/dist/deposit.d.ts +69 -0
  15. package/dist/deposit.js +52 -0
  16. package/dist/depositKeys.d.ts +154 -0
  17. package/dist/depositKeys.js +104 -0
  18. package/dist/depositKeys.test.d.ts +1 -0
  19. package/dist/depositKeys.test.js +231 -0
  20. package/dist/events.d.ts +41 -0
  21. package/dist/events.js +92 -0
  22. package/dist/events.test.d.ts +1 -0
  23. package/dist/events.test.js +111 -0
  24. package/dist/fees.d.ts +136 -0
  25. package/dist/fees.js +178 -0
  26. package/dist/fees.test.d.ts +1 -0
  27. package/dist/fees.test.js +165 -0
  28. package/dist/ids.d.ts +175 -0
  29. package/dist/ids.js +231 -0
  30. package/dist/ids.test.d.ts +1 -0
  31. package/dist/ids.test.js +607 -0
  32. package/dist/index.d.ts +45 -0
  33. package/dist/index.js +45 -0
  34. package/dist/input.d.ts +26 -0
  35. package/dist/{src/input.js → input.js} +23 -4
  36. package/dist/intent.d.ts +50 -0
  37. package/dist/intent.js +28 -0
  38. package/dist/intent.test.d.ts +1 -0
  39. package/dist/intent.test.js +119 -0
  40. package/dist/json.d.ts +55 -0
  41. package/dist/json.js +80 -0
  42. package/dist/participants.d.ts +22 -0
  43. package/dist/participants.js +28 -0
  44. package/dist/payment.d.ts +481 -0
  45. package/dist/payment.js +1149 -0
  46. package/dist/payment.test.d.ts +1 -0
  47. package/dist/payment.test.js +272 -0
  48. package/dist/peer-types.d.ts +327 -0
  49. package/dist/peer-types.js +169 -0
  50. package/dist/profit.d.ts +49 -0
  51. package/dist/profit.js +57 -0
  52. package/dist/profit.test.d.ts +1 -0
  53. package/dist/profit.test.js +315 -0
  54. package/dist/reputation.d.ts +125 -0
  55. package/dist/reputation.js +188 -0
  56. package/dist/reputation.test.d.ts +1 -0
  57. package/dist/reputation.test.js +156 -0
  58. package/dist/sort.d.ts +75 -0
  59. package/dist/sort.js +70 -0
  60. package/dist/sort.test.d.ts +1 -0
  61. package/dist/sort.test.js +216 -0
  62. package/dist/stateKey.d.ts +35 -0
  63. package/dist/stateKey.js +36 -0
  64. package/dist/stats.d.ts +61 -0
  65. package/dist/stats.js +53 -0
  66. package/dist/stats.test.d.ts +1 -0
  67. package/dist/stats.test.js +104 -0
  68. package/dist/time.d.ts +104 -0
  69. package/dist/time.js +162 -0
  70. package/dist/time.test.d.ts +1 -0
  71. package/dist/time.test.js +231 -0
  72. package/dist/tokens.d.ts +15502 -0
  73. package/dist/{src/tokens.js → tokens.js} +98 -17
  74. package/dist/tokens.test.d.ts +1 -0
  75. package/dist/tokens.test.js +193 -0
  76. package/dist/units.d.ts +200 -0
  77. package/dist/units.js +279 -0
  78. package/dist/units.test.d.ts +1 -0
  79. package/dist/units.test.js +327 -0
  80. package/package.json +119 -29
  81. package/dist/scripts/convert-svg.js +0 -17
  82. package/dist/src/chain.d.ts +0 -14
  83. package/dist/src/chain.js +0 -18
  84. package/dist/src/contracts.d.ts +0 -30
  85. package/dist/src/contracts.js +0 -64
  86. package/dist/src/conversionRates.d.ts +0 -124
  87. package/dist/src/currencies.d.ts +0 -144
  88. package/dist/src/data/countries.json +0 -1099
  89. package/dist/src/deposit.d.ts +0 -1
  90. package/dist/src/events.d.ts +0 -3
  91. package/dist/src/events.js +0 -16
  92. package/dist/src/ids.d.ts +0 -72
  93. package/dist/src/ids.js +0 -81
  94. package/dist/src/index.d.ts +0 -16
  95. package/dist/src/index.js +0 -16
  96. package/dist/src/input.d.ts +0 -7
  97. package/dist/src/intent.d.ts +0 -14
  98. package/dist/src/json.d.ts +0 -18
  99. package/dist/src/json.js +0 -44
  100. package/dist/src/participants.d.ts +0 -7
  101. package/dist/src/participants.js +0 -13
  102. package/dist/src/payment.d.ts +0 -164
  103. package/dist/src/payment.js +0 -439
  104. package/dist/src/profit.d.ts +0 -28
  105. package/dist/src/profit.js +0 -34
  106. package/dist/src/sort.d.ts +0 -36
  107. package/dist/src/sort.js +0 -39
  108. package/dist/src/stats.d.ts +0 -7
  109. package/dist/src/stats.js +0 -8
  110. package/dist/src/time.d.ts +0 -54
  111. package/dist/src/time.js +0 -106
  112. package/dist/src/tokens.d.ts +0 -3675
  113. package/dist/src/units.d.ts +0 -17
  114. package/dist/src/units.js +0 -79
  115. package/dist/src/zkp2p-types.d.ts +0 -48
  116. package/dist/tsconfig.tsbuildinfo +0 -1
  117. package/scripts/convert-svg.ts +0 -22
  118. package/src/chain.ts +0 -27
  119. package/src/contracts.ts +0 -89
  120. package/src/conversionRates.ts +0 -356
  121. package/src/currencies.ts +0 -286
  122. package/src/data/countries.json +0 -1099
  123. package/src/deposit.ts +0 -2
  124. package/src/events.ts +0 -21
  125. package/src/flags/eur.svg +0 -4
  126. package/src/flags/usd.svg +0 -25
  127. package/src/flags.ts +0 -4
  128. package/src/global.d.ts +0 -9
  129. package/src/ids.ts +0 -137
  130. package/src/index.ts +0 -16
  131. package/src/input.ts +0 -35
  132. package/src/intent.ts +0 -15
  133. package/src/json.ts +0 -42
  134. package/src/participants.ts +0 -14
  135. package/src/payment.ts +0 -573
  136. package/src/profit.ts +0 -55
  137. package/src/sort.ts +0 -49
  138. package/src/stats.ts +0 -10
  139. package/src/time.ts +0 -123
  140. package/src/tokens.ts +0 -159
  141. package/src/units.ts +0 -120
  142. package/src/zkp2p-types.ts +0 -55
  143. package/tsconfig.json +0 -18
  144. /package/dist/{scripts/convert-svg.d.ts → chain.test.d.ts} +0 -0
  145. /package/dist/{src/deposit.js → contracts.test.d.ts} +0 -0
  146. /package/dist/{src/intent.js → conversionRates.test.d.ts} +0 -0
  147. /package/dist/{src/zkp2p-types.js → currencies.test.d.ts} +0 -0
  148. /package/dist/{src/flags.d.ts → flags.d.ts} +0 -0
  149. /package/dist/{src/flags.js → flags.js} +0 -0
@@ -1,17 +0,0 @@
1
- import type { TokenInfo } from './tokens.js';
2
- export declare const oneEther: bigint;
3
- export declare function addThousandsSeparator(numberString: string, delimiter?: string): string;
4
- export interface FormatRateDisplayOptions {
5
- decimals: number;
6
- truncateDecimals?: number;
7
- padDecimals?: number;
8
- cutoff?: bigint;
9
- delimiter?: string;
10
- roundUp?: boolean;
11
- }
12
- export declare const parseUnits: (amount: string, options: Pick<FormatRateDisplayOptions, "decimals" | "delimiter">) => bigint;
13
- export declare function formatUnits(amount: bigint, options: FormatRateDisplayOptions): string;
14
- export declare function formatTokenAmountForDisplay(amount: bigint, options: FormatRateDisplayOptions): string;
15
- export declare function parseIntegerSafe(value: string): number | null;
16
- export declare function timestampToDate(timestamp: string | number | bigint | undefined | null): Date | null;
17
- export declare const formatAmount: (token: TokenInfo, amount: bigint | null, options?: Partial<FormatRateDisplayOptions>) => string | null;
package/dist/src/units.js DELETED
@@ -1,79 +0,0 @@
1
- import { formatUnits as viemFormatUnits, parseUnits as viemParseUnits } from 'viem';
2
- export const oneEther = 10n ** 18n;
3
- // Add thousands separators to a number string
4
- export function addThousandsSeparator(numberString, delimiter = ',') {
5
- let [integerPart, fractionalPart] = numberString.split('.');
6
- integerPart = integerPart || '0';
7
- fractionalPart = fractionalPart || '';
8
- // Add thousands separators to integer part
9
- const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, delimiter);
10
- // Return with fractional part if it exists
11
- return fractionalPart ? `${formattedInteger}.${fractionalPart}` : formattedInteger;
12
- }
13
- export const parseUnits = (amount, options) => {
14
- return viemParseUnits(amount.split(options.delimiter ?? ',').join(''), options.decimals);
15
- };
16
- // Format exchange rates with natural precision, minimum 2 decimal places and thousands separators
17
- export function formatUnits(amount, options) {
18
- const { decimals, truncateDecimals, padDecimals = 0, delimiter = ',', cutoff, roundUp = false } = options;
19
- if (cutoff && amount < cutoff) {
20
- return `<${formatUnits(cutoff, { ...options, truncateDecimals: 0, cutoff: undefined })}`;
21
- }
22
- if (roundUp && truncateDecimals !== undefined) {
23
- // const minimumDecimal = decimals - truncateDecimals
24
- const minimumDecimal = BigInt(decimals - truncateDecimals);
25
- const minimalMod = amount % (10n ** minimumDecimal);
26
- const halfMinimalDecimal = (10n ** minimumDecimal) / 2n;
27
- if (minimalMod >= halfMinimalDecimal) {
28
- amount = amount + (10n ** minimumDecimal) - minimalMod;
29
- }
30
- }
31
- const formatted = viemFormatUnits(amount, decimals);
32
- const [integerPart, fractionalPart = ''] = formatted.split('.');
33
- // If truncateDecimals is specified, limit decimal places
34
- let finalFractionalPart = fractionalPart;
35
- if (truncateDecimals !== undefined) {
36
- finalFractionalPart = fractionalPart.slice(0, truncateDecimals);
37
- }
38
- // Always pad to at least 2 decimal places (or padDecimals)
39
- if (finalFractionalPart.length < padDecimals) {
40
- finalFractionalPart = finalFractionalPart.padEnd(padDecimals, '0');
41
- }
42
- // If there are no decimals, still show .00
43
- const numberString = `${integerPart}.${finalFractionalPart}`;
44
- return addThousandsSeparator(numberString, delimiter);
45
- }
46
- export function formatTokenAmountForDisplay(amount, options) {
47
- return formatUnits(amount, { truncateDecimals: 2, ...options });
48
- }
49
- // Safe integer parsing without using Number()
50
- export function parseIntegerSafe(value) {
51
- // Use parseInt instead of Number() for integer parsing
52
- const parsed = parseInt(value, 10);
53
- return isNaN(parsed) ? null : parsed;
54
- }
55
- // // Get display title for limits (shows original user limits on hover)
56
- // export function getLimitsDisplayTitle(deposit: { formattedMinAmount: string; formattedMaxAmount: string }): string {
57
- // return `User set: ${deposit.formattedMinAmount} - ${deposit.formattedMaxAmount}`
58
- // }
59
- // Convert blockchain timestamp (seconds) to Date object
60
- export function timestampToDate(timestamp) {
61
- if (!timestamp)
62
- return null;
63
- // Convert seconds to milliseconds for Date constructor
64
- const timestampMs = Number(timestamp) * 1000;
65
- return new Date(timestampMs);
66
- }
67
- // export function formatTokenAmountForDisplay(amount: bigint, tokenInfo: TokenInfo): string {
68
- // return formatUnits(amount, { decimals: tokenInfo.decimals })
69
- // }
70
- export const formatAmount = (token, amount, options = {}) => {
71
- if (!amount)
72
- return null;
73
- return formatUnits(amount, {
74
- decimals: token.decimals,
75
- truncateDecimals: Math.min(token.decimals - 4, 8),
76
- padDecimals: 2,
77
- ...options,
78
- });
79
- };
@@ -1,48 +0,0 @@
1
- import type { Hex } from "viem";
2
- import type { ProviderKey, ValidationDepositData } from "./payment.js";
3
- export type ValidationOptions = {
4
- providerKey: ProviderKey;
5
- telegramHandle: string;
6
- providerId: string;
7
- };
8
- export type Zkp2pResponse<T> = {
9
- success: boolean;
10
- message: string;
11
- statusCode: number;
12
- responseObject: T;
13
- };
14
- export type CreateResponse = {
15
- id: number;
16
- processorName: string;
17
- depositData: string;
18
- hashedOnchainId: Hex;
19
- createdAt: string;
20
- };
21
- export type PayeeDetails = {
22
- id: number;
23
- processorName: string;
24
- createdAt: string;
25
- hashedOnchainId: Hex;
26
- depositData: ValidationDepositData;
27
- };
28
- export type IntentValidationOptions = {
29
- processorName: ProviderKey;
30
- depositId: string;
31
- tokenAmount: string;
32
- payeeDetails: Hex;
33
- toAddress: Hex;
34
- fiatCurrencyCode: Hex;
35
- chainId: string;
36
- };
37
- export type IntentValidation = {
38
- signedIntent: Hex;
39
- intentData: {
40
- depositId: string;
41
- tokenAmount: string;
42
- recipientAddress: Hex;
43
- verifierAddress: Hex;
44
- currencyCodeHash: Hex;
45
- gatingServiceSignature: Hex;
46
- };
47
- depositData: ValidationDepositData;
48
- };