@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.
- package/dist/chain.d.ts +446 -0
- package/dist/chain.js +98 -0
- package/dist/chain.test.js +112 -0
- package/dist/contracts.d.ts +206 -0
- package/dist/contracts.js +292 -0
- package/dist/contracts.test.js +243 -0
- package/dist/conversionRates.d.ts +215 -0
- package/dist/{src/conversionRates.js → conversionRates.js} +74 -4
- package/dist/conversionRates.test.js +473 -0
- package/dist/currencies.d.ts +248 -0
- package/dist/{src/currencies.js → currencies.js} +119 -38
- package/dist/currencies.test.js +343 -0
- package/dist/data/countries.json +1099 -0
- package/dist/deposit.d.ts +69 -0
- package/dist/deposit.js +52 -0
- package/dist/depositKeys.d.ts +154 -0
- package/dist/depositKeys.js +104 -0
- package/dist/depositKeys.test.d.ts +1 -0
- package/dist/depositKeys.test.js +231 -0
- package/dist/events.d.ts +41 -0
- package/dist/events.js +92 -0
- package/dist/events.test.d.ts +1 -0
- package/dist/events.test.js +111 -0
- package/dist/fees.d.ts +136 -0
- package/dist/fees.js +178 -0
- package/dist/fees.test.d.ts +1 -0
- package/dist/fees.test.js +165 -0
- package/dist/ids.d.ts +175 -0
- package/dist/ids.js +231 -0
- package/dist/ids.test.d.ts +1 -0
- package/dist/ids.test.js +607 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +45 -0
- package/dist/input.d.ts +26 -0
- package/dist/{src/input.js → input.js} +23 -4
- package/dist/intent.d.ts +50 -0
- package/dist/intent.js +28 -0
- package/dist/intent.test.d.ts +1 -0
- package/dist/intent.test.js +119 -0
- package/dist/json.d.ts +55 -0
- package/dist/json.js +80 -0
- package/dist/participants.d.ts +22 -0
- package/dist/participants.js +28 -0
- package/dist/payment.d.ts +481 -0
- package/dist/payment.js +1149 -0
- package/dist/payment.test.d.ts +1 -0
- package/dist/payment.test.js +272 -0
- package/dist/peer-types.d.ts +327 -0
- package/dist/peer-types.js +169 -0
- package/dist/profit.d.ts +49 -0
- package/dist/profit.js +57 -0
- package/dist/profit.test.d.ts +1 -0
- package/dist/profit.test.js +315 -0
- package/dist/reputation.d.ts +125 -0
- package/dist/reputation.js +188 -0
- package/dist/reputation.test.d.ts +1 -0
- package/dist/reputation.test.js +156 -0
- package/dist/sort.d.ts +75 -0
- package/dist/sort.js +70 -0
- package/dist/sort.test.d.ts +1 -0
- package/dist/sort.test.js +216 -0
- package/dist/stateKey.d.ts +35 -0
- package/dist/stateKey.js +36 -0
- package/dist/stats.d.ts +61 -0
- package/dist/stats.js +53 -0
- package/dist/stats.test.d.ts +1 -0
- package/dist/stats.test.js +104 -0
- package/dist/time.d.ts +104 -0
- package/dist/time.js +162 -0
- package/dist/time.test.d.ts +1 -0
- package/dist/time.test.js +231 -0
- package/dist/tokens.d.ts +15502 -0
- package/dist/{src/tokens.js → tokens.js} +98 -17
- package/dist/tokens.test.d.ts +1 -0
- package/dist/tokens.test.js +193 -0
- package/dist/units.d.ts +200 -0
- package/dist/units.js +279 -0
- package/dist/units.test.d.ts +1 -0
- package/dist/units.test.js +327 -0
- package/package.json +119 -29
- package/dist/scripts/convert-svg.js +0 -17
- package/dist/src/chain.d.ts +0 -14
- package/dist/src/chain.js +0 -18
- package/dist/src/contracts.d.ts +0 -30
- package/dist/src/contracts.js +0 -64
- package/dist/src/conversionRates.d.ts +0 -124
- package/dist/src/currencies.d.ts +0 -144
- package/dist/src/data/countries.json +0 -1099
- package/dist/src/deposit.d.ts +0 -1
- package/dist/src/events.d.ts +0 -3
- package/dist/src/events.js +0 -16
- package/dist/src/ids.d.ts +0 -72
- package/dist/src/ids.js +0 -81
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.js +0 -16
- package/dist/src/input.d.ts +0 -7
- package/dist/src/intent.d.ts +0 -14
- package/dist/src/json.d.ts +0 -18
- package/dist/src/json.js +0 -44
- package/dist/src/participants.d.ts +0 -7
- package/dist/src/participants.js +0 -13
- package/dist/src/payment.d.ts +0 -164
- package/dist/src/payment.js +0 -439
- package/dist/src/profit.d.ts +0 -28
- package/dist/src/profit.js +0 -34
- package/dist/src/sort.d.ts +0 -36
- package/dist/src/sort.js +0 -39
- package/dist/src/stats.d.ts +0 -7
- package/dist/src/stats.js +0 -8
- package/dist/src/time.d.ts +0 -54
- package/dist/src/time.js +0 -106
- package/dist/src/tokens.d.ts +0 -3675
- package/dist/src/units.d.ts +0 -17
- package/dist/src/units.js +0 -79
- package/dist/src/zkp2p-types.d.ts +0 -48
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/scripts/convert-svg.ts +0 -22
- package/src/chain.ts +0 -27
- package/src/contracts.ts +0 -89
- package/src/conversionRates.ts +0 -356
- package/src/currencies.ts +0 -286
- package/src/data/countries.json +0 -1099
- package/src/deposit.ts +0 -2
- package/src/events.ts +0 -21
- package/src/flags/eur.svg +0 -4
- package/src/flags/usd.svg +0 -25
- package/src/flags.ts +0 -4
- package/src/global.d.ts +0 -9
- package/src/ids.ts +0 -137
- package/src/index.ts +0 -16
- package/src/input.ts +0 -35
- package/src/intent.ts +0 -15
- package/src/json.ts +0 -42
- package/src/participants.ts +0 -14
- package/src/payment.ts +0 -573
- package/src/profit.ts +0 -55
- package/src/sort.ts +0 -49
- package/src/stats.ts +0 -10
- package/src/time.ts +0 -123
- package/src/tokens.ts +0 -159
- package/src/units.ts +0 -120
- package/src/zkp2p-types.ts +0 -55
- package/tsconfig.json +0 -18
- /package/dist/{scripts/convert-svg.d.ts → chain.test.d.ts} +0 -0
- /package/dist/{src/deposit.js → contracts.test.d.ts} +0 -0
- /package/dist/{src/intent.js → conversionRates.test.d.ts} +0 -0
- /package/dist/{src/zkp2p-types.js → currencies.test.d.ts} +0 -0
- /package/dist/{src/flags.d.ts → flags.d.ts} +0 -0
- /package/dist/{src/flags.js → flags.js} +0 -0
package/dist/src/units.d.ts
DELETED
|
@@ -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
|
-
};
|