@provex/utils 1.0.16

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 (75) hide show
  1. package/README.md +287 -0
  2. package/dist/scripts/convert-svg.d.ts +1 -0
  3. package/dist/scripts/convert-svg.js +17 -0
  4. package/dist/src/chain.d.ts +14 -0
  5. package/dist/src/chain.js +18 -0
  6. package/dist/src/contracts.d.ts +30 -0
  7. package/dist/src/contracts.js +64 -0
  8. package/dist/src/conversionRates.d.ts +124 -0
  9. package/dist/src/conversionRates.js +219 -0
  10. package/dist/src/currencies.d.ts +144 -0
  11. package/dist/src/currencies.js +234 -0
  12. package/dist/src/data/countries.json +1099 -0
  13. package/dist/src/deposit.d.ts +1 -0
  14. package/dist/src/deposit.js +1 -0
  15. package/dist/src/events.d.ts +3 -0
  16. package/dist/src/events.js +16 -0
  17. package/dist/src/flags.d.ts +2 -0
  18. package/dist/src/flags.js +3 -0
  19. package/dist/src/ids.d.ts +72 -0
  20. package/dist/src/ids.js +81 -0
  21. package/dist/src/index.d.ts +16 -0
  22. package/dist/src/index.js +16 -0
  23. package/dist/src/input.d.ts +7 -0
  24. package/dist/src/input.js +35 -0
  25. package/dist/src/intent.d.ts +14 -0
  26. package/dist/src/intent.js +1 -0
  27. package/dist/src/json.d.ts +18 -0
  28. package/dist/src/json.js +44 -0
  29. package/dist/src/participants.d.ts +7 -0
  30. package/dist/src/participants.js +13 -0
  31. package/dist/src/payment.d.ts +164 -0
  32. package/dist/src/payment.js +439 -0
  33. package/dist/src/profit.d.ts +28 -0
  34. package/dist/src/profit.js +34 -0
  35. package/dist/src/sort.d.ts +36 -0
  36. package/dist/src/sort.js +39 -0
  37. package/dist/src/stats.d.ts +7 -0
  38. package/dist/src/stats.js +8 -0
  39. package/dist/src/time.d.ts +54 -0
  40. package/dist/src/time.js +106 -0
  41. package/dist/src/tokens.d.ts +3675 -0
  42. package/dist/src/tokens.js +134 -0
  43. package/dist/src/units.d.ts +17 -0
  44. package/dist/src/units.js +79 -0
  45. package/dist/src/zkp2p-types.d.ts +48 -0
  46. package/dist/src/zkp2p-types.js +1 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -0
  48. package/package.json +45 -0
  49. package/scripts/convert-svg.ts +22 -0
  50. package/src/chain.ts +27 -0
  51. package/src/contracts.ts +89 -0
  52. package/src/conversionRates.ts +356 -0
  53. package/src/currencies.ts +286 -0
  54. package/src/data/countries.json +1099 -0
  55. package/src/deposit.ts +2 -0
  56. package/src/events.ts +21 -0
  57. package/src/flags/eur.svg +4 -0
  58. package/src/flags/usd.svg +25 -0
  59. package/src/flags.ts +4 -0
  60. package/src/global.d.ts +9 -0
  61. package/src/ids.ts +137 -0
  62. package/src/index.ts +16 -0
  63. package/src/input.ts +35 -0
  64. package/src/intent.ts +15 -0
  65. package/src/json.ts +42 -0
  66. package/src/participants.ts +14 -0
  67. package/src/payment.ts +573 -0
  68. package/src/profit.ts +55 -0
  69. package/src/sort.ts +49 -0
  70. package/src/stats.ts +10 -0
  71. package/src/time.ts +123 -0
  72. package/src/tokens.ts +159 -0
  73. package/src/units.ts +120 -0
  74. package/src/zkp2p-types.ts +55 -0
  75. package/tsconfig.json +18 -0
@@ -0,0 +1 @@
1
+ export type StatusMutatingAction = "deposit" | "withdrawal" | "closed" | "exchange";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const eventOrder: readonly ["deposit", "verifier_added", "currency_added", "rate_update", "intent", "exchange", "pruned", "withdrawal", "closed"];
2
+ export type EventType = (typeof eventOrder)[number];
3
+ export declare const eventOrderId: Map<"deposit" | "withdrawal" | "closed" | "exchange" | "verifier_added" | "currency_added" | "rate_update" | "intent" | "pruned", number>;
@@ -0,0 +1,16 @@
1
+ export const eventOrder = [
2
+ // deposit open events
3
+ 'deposit',
4
+ 'verifier_added',
5
+ 'currency_added',
6
+ // configuration events
7
+ 'rate_update',
8
+ // intent events
9
+ 'intent',
10
+ 'exchange',
11
+ 'pruned',
12
+ // deposit close events
13
+ 'withdrawal',
14
+ 'closed',
15
+ ];
16
+ export const eventOrderId = new Map(eventOrder.map((event, index) => [event, index]));
@@ -0,0 +1,2 @@
1
+ export declare const USD_FLAG_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"1235\" height=\"650\" viewBox=\"0 0 7410 3900\"> <path d=\"M0,0h7410v3900H0\" fill=\"#b31942\"/> <path d=\"M0,450H7410m0,600H0m0,600H7410m0,600H0m0,600H7410m0,600H0\" stroke=\"#FFF\" stroke-width=\"300\"/> <path d=\"M0,0h2964v2100H0\" fill=\"#0a3161\"/> <g fill=\"#FFF\"> <g id=\"s18\"> <g id=\"s9\"> <g id=\"s5\"> <g id=\"s4\"> <path id=\"s\" d=\"M247,90 317.534230,307.082039 132.873218,172.917961H361.126782L176.465770,307.082039z\"/> <use xlink:href=\"#s\" y=\"420\"/> <use xlink:href=\"#s\" y=\"840\"/> <use xlink:href=\"#s\" y=\"1260\"/> </g> <use xlink:href=\"#s\" y=\"1680\"/> </g> <use xlink:href=\"#s4\" x=\"247\" y=\"210\"/> </g> <use xlink:href=\"#s9\" x=\"494\"/> </g> <use xlink:href=\"#s18\" x=\"988\"/> <use xlink:href=\"#s9\" x=\"1976\"/> <use xlink:href=\"#s5\" x=\"2470\"/> </g> </svg>";
2
+ export declare const EUR_FLAG_SVG = "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=\"810\" height=\"540\"><desc>European flag</desc> <defs><g id=\"s\"><g id=\"c\"><path id=\"t\" d=\"M0,0v1h0.5z\" transform=\"translate(0,-1)rotate(18)\"/><use xlink:href=\"#t\" transform=\"scale(-1,1)\"/></g><g id=\"a\"><use xlink:href=\"#c\" transform=\"rotate(72)\"/><use xlink:href=\"#c\" transform=\"rotate(144)\"/></g><use xlink:href=\"#a\" transform=\"scale(-1,1)\"/></g></defs> <rect fill=\"#039\" width=\"810\" height=\"540\"/><g fill=\"#fc0\" transform=\"scale(30)translate(13.5,9)\"><use xlink:href=\"#s\" y=\"-6\"/><use xlink:href=\"#s\" y=\"6\"/><g id=\"l\"><use xlink:href=\"#s\" x=\"-6\"/><use xlink:href=\"#s\" transform=\"rotate(150)translate(0,6)rotate(66)\"/><use xlink:href=\"#s\" transform=\"rotate(120)translate(0,6)rotate(24)\"/><use xlink:href=\"#s\" transform=\"rotate(60)translate(0,6)rotate(12)\"/><use xlink:href=\"#s\" transform=\"rotate(30)translate(0,6)rotate(42)\"/></g><use xlink:href=\"#l\" transform=\"scale(-1,1)\"/></g> </svg>";
@@ -0,0 +1,3 @@
1
+ // Auto-generated from SVG files
2
+ export const USD_FLAG_SVG = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1235" height="650" viewBox="0 0 7410 3900"> <path d="M0,0h7410v3900H0" fill="#b31942"/> <path d="M0,450H7410m0,600H0m0,600H7410m0,600H0m0,600H7410m0,600H0" stroke="#FFF" stroke-width="300"/> <path d="M0,0h2964v2100H0" fill="#0a3161"/> <g fill="#FFF"> <g id="s18"> <g id="s9"> <g id="s5"> <g id="s4"> <path id="s" d="M247,90 317.534230,307.082039 132.873218,172.917961H361.126782L176.465770,307.082039z"/> <use xlink:href="#s" y="420"/> <use xlink:href="#s" y="840"/> <use xlink:href="#s" y="1260"/> </g> <use xlink:href="#s" y="1680"/> </g> <use xlink:href="#s4" x="247" y="210"/> </g> <use xlink:href="#s9" x="494"/> </g> <use xlink:href="#s18" x="988"/> <use xlink:href="#s9" x="1976"/> <use xlink:href="#s5" x="2470"/> </g> </svg>';
3
+ export const EUR_FLAG_SVG = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="810" height="540"><desc>European flag</desc> <defs><g id="s"><g id="c"><path id="t" d="M0,0v1h0.5z" transform="translate(0,-1)rotate(18)"/><use xlink:href="#t" transform="scale(-1,1)"/></g><g id="a"><use xlink:href="#c" transform="rotate(72)"/><use xlink:href="#c" transform="rotate(144)"/></g><use xlink:href="#a" transform="scale(-1,1)"/></g></defs> <rect fill="#039" width="810" height="540"/><g fill="#fc0" transform="scale(30)translate(13.5,9)"><use xlink:href="#s" y="-6"/><use xlink:href="#s" y="6"/><g id="l"><use xlink:href="#s" x="-6"/><use xlink:href="#s" transform="rotate(150)translate(0,6)rotate(66)"/><use xlink:href="#s" transform="rotate(120)translate(0,6)rotate(24)"/><use xlink:href="#s" transform="rotate(60)translate(0,6)rotate(12)"/><use xlink:href="#s" transform="rotate(30)translate(0,6)rotate(42)"/></g><use xlink:href="#l" transform="scale(-1,1)"/></g> </svg>';
@@ -0,0 +1,72 @@
1
+ import { type Hex } from "viem";
2
+ import { type EventType } from "./events.js";
3
+ import { type TimeResolutionKey } from "./time.js";
4
+ import type { StatAction } from "./stats.js";
5
+ export type DepositVerifierInputs = {
6
+ verifier: Hex;
7
+ depositId: Hex;
8
+ };
9
+ export type DepositCurrencyInputs = DepositVerifierInputs & {
10
+ currency: Hex;
11
+ };
12
+ export type ConversionRateUpdatedInputs = DepositCurrencyInputs & {
13
+ changeId: number;
14
+ };
15
+ export type ProviderHashInputs = {
16
+ chainId: bigint | number;
17
+ hash: Hex;
18
+ };
19
+ export type OnChainHashInputs = {
20
+ chainId: bigint | number;
21
+ hash: Hex;
22
+ };
23
+ export type OnChainAddressInputs = {
24
+ chainId: bigint | number;
25
+ address: Hex;
26
+ };
27
+ export declare const onChainHash: ({ chainId, hash }: OnChainHashInputs) => `0x${string}`;
28
+ export declare const onChainAddress: ({ chainId, address }: OnChainAddressInputs) => `0x${string}`;
29
+ export declare const ids: {
30
+ block: ({ chainId, hash }: OnChainHashInputs) => `0x${string}`;
31
+ transaction: ({ chainId, hash }: OnChainHashInputs) => `0x${string}`;
32
+ participant: ({ chainId, address }: OnChainAddressInputs) => `0x${string}`;
33
+ providerHash: ({ chainId, hash }: OnChainHashInputs) => `0x${string}`;
34
+ verifier: ({ chainId, address }: OnChainAddressInputs) => `0x${string}`;
35
+ depositVerifierAdded: ({ depositId, verifier }: DepositVerifierInputs) => `0x${string}`;
36
+ depositCurrencyAdded: ({ depositId, currency, verifier }: DepositCurrencyInputs) => `0x${string}`;
37
+ depositConversionRateUpdated: ({ currency, verifier, depositId, changeId }: ConversionRateUpdatedInputs) => `0x${string}`;
38
+ };
39
+ export type OrderIdInputs = {
40
+ timestamp: bigint;
41
+ chainId: bigint;
42
+ };
43
+ export type OrderIdTransactionInputs = OrderIdInputs & {
44
+ transactionIndex: bigint;
45
+ };
46
+ export type OrderIdLogInputs = OrderIdTransactionInputs & {
47
+ logIndex: bigint;
48
+ };
49
+ export type OrderIdOrderInputs = OrderIdLogInputs & {
50
+ name: EventType;
51
+ };
52
+ export type DepositIdInputs = {
53
+ chainId: bigint | number;
54
+ depositId: bigint | number;
55
+ };
56
+ export type LogStatsIdInputs = {
57
+ timestamp: bigint;
58
+ type: TimeResolutionKey;
59
+ action: StatAction;
60
+ currency: Hex | null;
61
+ token: Hex;
62
+ verifier: Hex;
63
+ chainId: bigint | number;
64
+ };
65
+ export declare const orderId: {
66
+ deposit: ({ chainId, depositId }: DepositIdInputs) => `0x${string}`;
67
+ block: ({ timestamp, chainId }: OrderIdInputs) => `0x${string}`;
68
+ transaction: ({ timestamp, chainId, transactionIndex }: OrderIdTransactionInputs) => `0x${string}`;
69
+ log: ({ timestamp, chainId, transactionIndex, logIndex }: OrderIdLogInputs) => `0x${string}`;
70
+ order: ({ timestamp, chainId, transactionIndex, logIndex, name }: OrderIdOrderInputs) => `0x${string}`;
71
+ stat: ({ timestamp, type, action, currency, verifier, token, chainId }: LogStatsIdInputs) => `0x${string}`;
72
+ };
@@ -0,0 +1,81 @@
1
+ import { concatHex, keccak256, numberToHex, stringToHex } from "viem";
2
+ import { eventOrderId } from "./events.js";
3
+ import { interval } from "./time.js";
4
+ export const onChainHash = ({ chainId, hash }) => (keccak256(concatHex([
5
+ numberToHex(chainId, { size: 8 }),
6
+ hash,
7
+ ])));
8
+ export const onChainAddress = ({ chainId, address }) => (onChainHash({ chainId, hash: address }));
9
+ export const ids = {
10
+ block: onChainHash,
11
+ transaction: onChainHash,
12
+ participant: onChainAddress,
13
+ providerHash: onChainHash,
14
+ verifier: onChainAddress,
15
+ depositVerifierAdded: ({ depositId, verifier }) => {
16
+ return keccak256(concatHex([depositId, verifier]));
17
+ },
18
+ depositCurrencyAdded: ({ depositId, currency, verifier }) => {
19
+ return keccak256(concatHex([
20
+ ids.depositVerifierAdded({ verifier, depositId }),
21
+ currency,
22
+ ]));
23
+ },
24
+ depositConversionRateUpdated: ({ currency, verifier, depositId, changeId }) => {
25
+ return concatHex([
26
+ ids.depositCurrencyAdded({ currency, verifier, depositId }),
27
+ numberToHex(changeId, { size: 4 }),
28
+ ]);
29
+ },
30
+ };
31
+ const hourFactor = BigInt(interval.hour) / BigInt(interval.second);
32
+ const dayFactor = BigInt(interval.day) / BigInt(interval.second);
33
+ const monthFactor = BigInt(interval.month) / BigInt(interval.second);
34
+ export const orderId = {
35
+ deposit: ({ chainId, depositId }) => concatHex([
36
+ numberToHex(depositId, { size: 8 }),
37
+ numberToHex(chainId, { size: 4 }),
38
+ ]),
39
+ block: ({ timestamp, chainId }) => concatHex([
40
+ numberToHex(timestamp, { size: 8 }),
41
+ numberToHex(chainId, { size: 4 }),
42
+ ]),
43
+ transaction: ({ timestamp, chainId, transactionIndex }) => concatHex([
44
+ numberToHex(timestamp, { size: 8 }),
45
+ numberToHex(transactionIndex, { size: 4 }),
46
+ numberToHex(chainId, { size: 4 }),
47
+ ]),
48
+ log: ({ timestamp, chainId, transactionIndex, logIndex }) => concatHex([
49
+ numberToHex(timestamp, { size: 8 }),
50
+ numberToHex(transactionIndex, { size: 4 }),
51
+ numberToHex(logIndex, { size: 4 }),
52
+ numberToHex(chainId, { size: 4 }),
53
+ ]),
54
+ order: ({ timestamp, chainId, transactionIndex, logIndex, name }) => concatHex([
55
+ numberToHex(timestamp, { size: 8 }),
56
+ numberToHex(transactionIndex, { size: 4 }),
57
+ numberToHex(eventOrderId.get(name), { size: 1 }),
58
+ numberToHex(logIndex, { size: 4 }),
59
+ numberToHex(chainId, { size: 4 }),
60
+ ]),
61
+ stat: ({ timestamp, type, action, currency, verifier, token, chainId }) => {
62
+ const hour = (timestamp / hourFactor) * hourFactor;
63
+ const day = (timestamp / dayFactor) * dayFactor;
64
+ const month = (timestamp / monthFactor) * monthFactor;
65
+ let time = timestamp;
66
+ if (type === "hour") {
67
+ time = hour;
68
+ }
69
+ if (type === "day") {
70
+ time = day;
71
+ }
72
+ if (type === "month") {
73
+ time = month;
74
+ }
75
+ return concatHex([
76
+ numberToHex(time, { size: 8 }),
77
+ `0x${keccak256(concatHex([stringToHex(type), stringToHex(action), token, currency ?? '0x', verifier])).slice(26)}`,
78
+ numberToHex(chainId, { size: 4 }),
79
+ ]);
80
+ },
81
+ };
@@ -0,0 +1,16 @@
1
+ export * from './currencies.js';
2
+ export * from './units.js';
3
+ export * from './contracts.js';
4
+ export * from './participants.js';
5
+ export * from './chain.js';
6
+ export * from './intent.js';
7
+ export * from './conversionRates.js';
8
+ export * from './payment.js';
9
+ export * from './sort.js';
10
+ export * from './time.js';
11
+ export * from './tokens.js';
12
+ export * from './stats.js';
13
+ export * from './deposit.js';
14
+ export * from './ids.js';
15
+ export * from './events.js';
16
+ export * from './zkp2p-types.js';
@@ -0,0 +1,16 @@
1
+ export * from './currencies.js';
2
+ export * from './units.js';
3
+ export * from './contracts.js';
4
+ export * from './participants.js';
5
+ export * from './chain.js';
6
+ export * from './intent.js';
7
+ export * from './conversionRates.js';
8
+ export * from './payment.js';
9
+ export * from './sort.js';
10
+ export * from './time.js';
11
+ export * from './tokens.js';
12
+ export * from './stats.js';
13
+ export * from './deposit.js';
14
+ export * from './ids.js';
15
+ export * from './events.js';
16
+ export * from './zkp2p-types.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Adjust the lowest decimal place directly on the string, preserving all trailing zeros
3
+ * @param inputVal - The input value
4
+ * @param direction - The direction to adjust the decimal place
5
+ * @returns The adjusted value
6
+ */
7
+ export declare const adjustLowestDecimal: (inputVal: string, direction: 1 | -1) => string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Adjust the lowest decimal place directly on the string, preserving all trailing zeros
3
+ * @param inputVal - The input value
4
+ * @param direction - The direction to adjust the decimal place
5
+ * @returns The adjusted value
6
+ */
7
+ export const adjustLowestDecimal = (inputVal, direction) => {
8
+ let [whole, decimal = ''] = inputVal.split('.');
9
+ // truncate the decimal to 18 decimals
10
+ decimal = decimal.slice(0, 18);
11
+ // If no decimals, treat as zero decimals
12
+ const originalDecimals = decimal.length;
13
+ // Pad to 18 decimals for calculation
14
+ const paddedDecimals = (decimal + '0'.repeat(18)).slice(0, 18);
15
+ // Compose the full number as a string
16
+ const fullNumberStr = whole + paddedDecimals;
17
+ let value = BigInt(fullNumberStr);
18
+ // Determine which decimal place to operate on (last entered, or 18th if maxed)
19
+ // idx will be -1 if it should be incrementing the whole number
20
+ const idx = originalDecimals - 1;
21
+ // The amount to increment/decrement at the correct decimal place
22
+ const delta = 10n ** BigInt(17 - idx);
23
+ if (direction === 1) {
24
+ value += delta;
25
+ }
26
+ else if (value >= delta) {
27
+ value -= delta;
28
+ }
29
+ // Convert back to string, pad with zeros if needed
30
+ let valueStr = value.toString().padStart(whole.length + 18, '0');
31
+ let newWhole = BigInt(valueStr.slice(0, valueStr.length - 18) || '0').toString();
32
+ let newDecimal = valueStr.slice(-18, -18 + originalDecimals);
33
+ // If originalDecimals was 0, don't add a decimal point
34
+ return originalDecimals > 0 ? `${newWhole}.${newDecimal}` : newWhole;
35
+ };
@@ -0,0 +1,14 @@
1
+ import type { Hex } from "viem";
2
+ /**
3
+ * Structure for an intent
4
+ */
5
+ export interface IntentStruct {
6
+ owner: Hex;
7
+ to: Hex;
8
+ depositId: bigint;
9
+ amount: bigint;
10
+ timestamp: bigint;
11
+ paymentVerifier: Hex;
12
+ fiatCurrency: Hex;
13
+ conversionRate: bigint;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * JSON serializer
3
+ */
4
+ export declare const jsonSerializer: {
5
+ /**
6
+ * Parse a JSON string
7
+ * @param str - The JSON string to parse
8
+ * @returns The parsed object
9
+ */
10
+ parse: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
11
+ /**
12
+ * Stringify an object
13
+ * @param obj - The object to stringify
14
+ * @returns The stringified object
15
+ */
16
+ stringify: (obj: unknown) => string;
17
+ };
18
+ export declare function mapBigIntFields<T>(obj: T, fields: string[]): T;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * JSON serializer
3
+ */
4
+ export const jsonSerializer = {
5
+ /**
6
+ * Parse a JSON string
7
+ * @param str - The JSON string to parse
8
+ * @returns The parsed object
9
+ */
10
+ parse: JSON.parse,
11
+ /**
12
+ * Stringify an object
13
+ * @param obj - The object to stringify
14
+ * @returns The stringified object
15
+ */
16
+ stringify: (obj) => JSON.stringify(obj, (_key, value) => {
17
+ if (typeof value === 'bigint') {
18
+ return value.toString();
19
+ }
20
+ return value;
21
+ })
22
+ };
23
+ // Recursively convert specified fields to BigInt in an object or array
24
+ export function mapBigIntFields(obj, fields) {
25
+ if (Array.isArray(obj)) {
26
+ return obj.map(item => mapBigIntFields(item, fields));
27
+ }
28
+ if (obj && typeof obj === 'object') {
29
+ const result = {};
30
+ for (const [key, value] of Object.entries(obj)) {
31
+ if (fields.includes(key) && typeof value === 'string' && value.match(/^-?\d+$/)) {
32
+ result[key] = BigInt(value);
33
+ }
34
+ else if (Array.isArray(value) || (value && typeof value === 'object')) {
35
+ result[key] = mapBigIntFields(value, fields);
36
+ }
37
+ else {
38
+ result[key] = value;
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ return obj;
44
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generate a participantId from chainId and address using the same logic as the indexer
3
+ * @param chainId - The chain ID
4
+ * @param address - The address
5
+ * @returns The participant ID
6
+ */
7
+ export declare function generateParticipantId(chainId: number | bigint, address: string): string;
@@ -0,0 +1,13 @@
1
+ import { concatHex, keccak256, numberToHex } from 'viem';
2
+ /**
3
+ * Generate a participantId from chainId and address using the same logic as the indexer
4
+ * @param chainId - The chain ID
5
+ * @param address - The address
6
+ * @returns The participant ID
7
+ */
8
+ export function generateParticipantId(chainId, address) {
9
+ return keccak256(concatHex([
10
+ numberToHex(chainId, { size: 8 }),
11
+ address
12
+ ]));
13
+ }
@@ -0,0 +1,164 @@
1
+ import { type Hex } from "viem";
2
+ import type { TokenInfo } from "./tokens.js";
3
+ import type { ConversionRateInfo, ProviderRates } from "./conversionRates.js";
4
+ import { ChainId } from "./chain.js";
5
+ /**
6
+ * Payment providers, including manual
7
+ */
8
+ export declare const providers: {
9
+ readonly VENMO: "venmo";
10
+ readonly ZELLE: "zelle";
11
+ readonly CASHAPP: "cashapp";
12
+ readonly REVOLUT: "revolut";
13
+ readonly WISE: "wise";
14
+ readonly MERCADOPAGO: "mercadopago";
15
+ readonly MANUAL: "manual";
16
+ readonly PAYPAL: "paypal";
17
+ readonly MONZO: "monzo";
18
+ };
19
+ export type ProviderKey = typeof providers[keyof typeof providers];
20
+ /** Distinct keys for payment sub-providers (currently only used by Zelle) */
21
+ export declare const subProviders: {
22
+ readonly CHASE: "chase";
23
+ readonly BANK_OF_AMERICA: "bank_of_america";
24
+ readonly CITI: "citi";
25
+ };
26
+ /** Sub-provider key (providers within providers) */
27
+ export type SubProviderKey = typeof subProviders[keyof typeof subProviders];
28
+ /** Action type for a provider */
29
+ export type ProviderKeyActionType = 'transfer' | 'send';
30
+ /** Validatable provider key */
31
+ export type ValidatableProviderKey = Exclude<ProviderKey, typeof providers.MANUAL>;
32
+ /** Transparent platforms */
33
+ export type TransparentPlatforms = typeof providers.ZELLE;
34
+ /** Platform key */
35
+ export type PlatformKey = Exclude<ValidatableProviderKey, TransparentPlatforms> | SubProviderKey;
36
+ /** Action type */
37
+ export type ActionType = `${ProviderKeyActionType}_${ProviderKey}`;
38
+ /** Provider key to validation key */
39
+ export declare const providerKeyToValidationKey: Record<ValidatableProviderKey, string>;
40
+ /** Validation key */
41
+ export type ValidationKey = typeof providerKeyToValidationKey[keyof typeof providerKeyToValidationKey];
42
+ /** Limits for a payment method */
43
+ export type Limits = {
44
+ min: number;
45
+ };
46
+ /** Send link options */
47
+ export type SendLinkOptions = {
48
+ username: string;
49
+ amount: bigint;
50
+ subProvider?: SubProviderKey;
51
+ qrCode?: boolean;
52
+ };
53
+ /** Send link */
54
+ export type SendLink = (options: SendLinkOptions) => string | null;
55
+ /** Payment sub-provider config */
56
+ export type PaymentSubProviderConfig = {
57
+ key: SubProviderKey;
58
+ name: string;
59
+ icon?: string;
60
+ color?: string;
61
+ usernameType?: string;
62
+ verifiers: (chain: ChainId) => Hex[];
63
+ sendLink: SendLink;
64
+ paymentMethod: number;
65
+ };
66
+ /** Payment config */
67
+ export type PaymentConfig = {
68
+ icon: string;
69
+ key: ProviderKey;
70
+ name: string;
71
+ color: string;
72
+ usernameType: string;
73
+ validationKey: ValidationKey | null;
74
+ verifiers: string[];
75
+ limits: Limits;
76
+ /**
77
+ * Set of sub-provider keys that this payment method supports. Empty when none.
78
+ */
79
+ subProviders: Set<PaymentSubProviderConfig>;
80
+ list: Hex[];
81
+ sendLink?: SendLink;
82
+ };
83
+ /** Validation deposit data payment identifier */
84
+ export type ValidationDepositDataPaymentIdentifier = Partial<{
85
+ [key in Exclude<ValidationKey, null>]: string;
86
+ }>;
87
+ /** Validation deposit data */
88
+ export type ValidationDepositData = ValidationDepositDataPaymentIdentifier & {
89
+ telegramUsername: string;
90
+ };
91
+ /** Data encoding for zelle urls */
92
+ export declare const dataEncoding: (data: string) => string;
93
+ /** Default Zelle send link */
94
+ export declare const defaultZelleSendLink: (options: SendLinkOptions) => string | null;
95
+ /** Global configuration for all supported sub-providers. Other modules can import this directly. */
96
+ export declare const subProviderConfigs: Partial<Record<ProviderKey, Record<SubProviderKey, PaymentSubProviderConfig>>>;
97
+ /** Payment method icon mappings */
98
+ export declare const providerConfigs: (chainId: ChainId) => Record<ProviderKey, PaymentConfig>;
99
+ /** Payment verifier to key map */
100
+ export declare const paymentVerifierToKey: (chainId: ChainId | null) => Map<string, ProviderKey>;
101
+ /** Provider key to verifiers map */
102
+ export declare const providerKeyToVerifiersMap: (chainId: ChainId) => Map<ProviderKey, `0x${string}`[]>;
103
+ /** Provider key to verifiers */
104
+ export declare const providerKeyToVerifiers: (chainId: ChainId, providerKey: ProviderKey) => Hex[] | null;
105
+ /** Verifier gets key */
106
+ export declare const verifierGetsKey: (chainId: ChainId | null, verifierAddress: string) => ProviderKey;
107
+ /**
108
+ * Utility function to get payment method icon
109
+ * @param key - The provider key
110
+ * @returns The icon string used for iconify
111
+ */
112
+ export declare const getPaymentIcon: (chainId: ChainId | null, key: ProviderKey) => string;
113
+ /**
114
+ * Utility function to get payment method configuration by verifier address
115
+ * @param verifierAddress - The verifier address
116
+ * @returns The payment method configuration
117
+ */
118
+ export declare const getPaymentMethodConfig: (chainId: ChainId | null, verifierAddress: string) => PaymentConfig | null;
119
+ /**
120
+ * Utility function to get payment method minimum limit by verifier address
121
+ * @param key - The provider key
122
+ * @returns The minimum limit
123
+ */
124
+ export declare const getPaymentMethodMinimum: (chainId: ChainId | null, key: ProviderKey) => number;
125
+ /**
126
+ * Utility function to get payment method name by verifier address
127
+ */
128
+ export declare const getPaymentMethodName: (chainId: ChainId | null, verifierAddress: string | ProviderKey) => string;
129
+ /**
130
+ * Calculate effective minimum amount (higher of user minimum or payment provider minimum)
131
+ * @param userMinAmountWei - The user minimum amount
132
+ * @param tokenInfo - The token info
133
+ * @param providerRates - The provider rates
134
+ * @returns The effective minimum amount
135
+ */
136
+ export declare function calculateEffectiveMinimum(chainId: ChainId, userMinAmountWei: string | bigint, tokenInfo: TokenInfo, providerRates?: ProviderRates<ConversionRateInfo>): {
137
+ userMinAmountWei: bigint;
138
+ providerMinAmountWei: bigint;
139
+ effectiveMinAmountWei: bigint;
140
+ formattedEffectiveMin: string;
141
+ };
142
+ /**
143
+ * Helper function to get payment provider minimum limit (returns decimal number for config)
144
+ * @param key - The provider key
145
+ * @returns The minimum limit
146
+ */
147
+ export declare function getPaymentProviderMinimum(chainId: ChainId, key: ProviderKey): number;
148
+ /**
149
+ * Check if a payment method is known
150
+ * @param chainId - The chain ID
151
+ * @param verifierAddress - The verifier address
152
+ * @returns True if the payment method is known, false otherwise
153
+ */
154
+ export declare const isPaymentMethodKnown: (chainId: ChainId | null, verifierAddress: string) => boolean;
155
+ /**
156
+ * Get all payment methods
157
+ * @returns All payment methods
158
+ */
159
+ export declare const getAllPaymentMethods: (chainId: ChainId) => ProviderKey[];
160
+ /**
161
+ * Get all verifiable payment methods
162
+ * @returns All verifiable payment methods
163
+ */
164
+ export declare const verifiablePaymentMethods: (chainId: ChainId) => ProviderKey[];