@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
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @fileoverview Deposit status definitions and types.
3
+ *
4
+ * This module defines the possible states for escrow deposits and provides
5
+ * the canonical type definitions used across the indexer and UI.
6
+ *
7
+ * @remarks
8
+ * **Status Lifecycle:**
9
+ *
10
+ * V2 Deposits:
11
+ * - active: Deposit has funds available for matching
12
+ * - underfunded: Deposit exists but balance is too low
13
+ * - withdrawn: All funds removed, deposit empty
14
+ * - closed: Explicitly closed by depositor (terminal state)
15
+ *
16
+ * V3 Deposits:
17
+ * - active: Deposit has funds and is accepting intents
18
+ * - underfunded: Deposit exists but balance is too low
19
+ * - withdrawn: All funds removed, deposit empty
20
+ * - paused: Deposit has funds but acceptingIntents = false
21
+ *
22
+ * @see {@link indexer/depositStatus} for status derivation logic
23
+ */
24
+ /**
25
+ * Deposit status mapping - single source of truth for all deposit statuses.
26
+ * Used across the indexer and UI for consistent status handling.
27
+ *
28
+ * V2 statuses: active, underfunded, withdrawn, closed
29
+ * V3 statuses: active, underfunded, withdrawn, paused (V3 has no 'closed' state)
30
+ */
31
+ export declare const depositStatuses: {
32
+ readonly ACTIVE: "active";
33
+ readonly CLOSED: "closed";
34
+ readonly PAUSED: "paused";
35
+ readonly WITHDRAWN: "withdrawn";
36
+ readonly UNDERFUNDED: "underfunded";
37
+ };
38
+ /**
39
+ * Union type of all valid deposit status values.
40
+ */
41
+ export type DepositStatus = (typeof depositStatuses)[keyof typeof depositStatuses];
42
+ /**
43
+ * Array of deposit status values for use with onchainEnum in ponder.schema.ts.
44
+ */
45
+ export declare const DEPOSIT_STATUSES: readonly DepositStatus[];
46
+ /**
47
+ * Actions that can mutate a deposit's status.
48
+ * - deposit: Adding funds
49
+ * - withdrawal: Removing funds
50
+ * - exchange: Intent fulfilled, funds exchanged
51
+ * - closed: V2 only - explicitly closing the deposit
52
+ * - paused: V3 only - toggling acceptingIntents
53
+ */
54
+ export type StatusMutatingAction = 'deposit' | 'withdrawal' | 'closed' | 'exchange' | 'paused';
55
+ /**
56
+ * Escrow version mapping - single source of truth for escrow contract versions.
57
+ */
58
+ export declare const escrowVersions: {
59
+ readonly V2: "v2";
60
+ readonly V3: "v3";
61
+ };
62
+ /**
63
+ * Union type of all valid escrow version values.
64
+ */
65
+ export type EscrowVersion = (typeof escrowVersions)[keyof typeof escrowVersions];
66
+ /**
67
+ * Array of escrow version values for use with onchainEnum in ponder.schema.ts.
68
+ */
69
+ export declare const ESCROW_VERSIONS: readonly EscrowVersion[];
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Deposit status definitions and types.
3
+ *
4
+ * This module defines the possible states for escrow deposits and provides
5
+ * the canonical type definitions used across the indexer and UI.
6
+ *
7
+ * @remarks
8
+ * **Status Lifecycle:**
9
+ *
10
+ * V2 Deposits:
11
+ * - active: Deposit has funds available for matching
12
+ * - underfunded: Deposit exists but balance is too low
13
+ * - withdrawn: All funds removed, deposit empty
14
+ * - closed: Explicitly closed by depositor (terminal state)
15
+ *
16
+ * V3 Deposits:
17
+ * - active: Deposit has funds and is accepting intents
18
+ * - underfunded: Deposit exists but balance is too low
19
+ * - withdrawn: All funds removed, deposit empty
20
+ * - paused: Deposit has funds but acceptingIntents = false
21
+ *
22
+ * @see {@link indexer/depositStatus} for status derivation logic
23
+ */
24
+ /**
25
+ * Deposit status mapping - single source of truth for all deposit statuses.
26
+ * Used across the indexer and UI for consistent status handling.
27
+ *
28
+ * V2 statuses: active, underfunded, withdrawn, closed
29
+ * V3 statuses: active, underfunded, withdrawn, paused (V3 has no 'closed' state)
30
+ */
31
+ export const depositStatuses = {
32
+ ACTIVE: 'active',
33
+ CLOSED: 'closed', // V2 only - terminal state when deposit is explicitly closed
34
+ PAUSED: 'paused', // V3 only - deposit is paused (acceptingIntents = false)
35
+ WITHDRAWN: 'withdrawn',
36
+ UNDERFUNDED: 'underfunded',
37
+ };
38
+ /**
39
+ * Array of deposit status values for use with onchainEnum in ponder.schema.ts.
40
+ */
41
+ export const DEPOSIT_STATUSES = Object.values(depositStatuses);
42
+ /**
43
+ * Escrow version mapping - single source of truth for escrow contract versions.
44
+ */
45
+ export const escrowVersions = {
46
+ V2: 'v2',
47
+ V3: 'v3',
48
+ };
49
+ /**
50
+ * Array of escrow version values for use with onchainEnum in ponder.schema.ts.
51
+ */
52
+ export const ESCROW_VERSIONS = Object.values(escrowVersions);
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @fileoverview Compound key utilities for deposit and related entity identification.
3
+ *
4
+ * Deposits are uniquely identified by a compound key of (escrow, localId, chainId).
5
+ * This module provides types and utilities for creating, serializing, and
6
+ * converting these compound keys for use in database operations and event handling.
7
+ *
8
+ * @remarks
9
+ * The compound key approach allows deposits to be uniquely identified across:
10
+ * - Multiple chains (Base, Pulsechain)
11
+ * - Multiple escrow contract versions (V2, V3)
12
+ * - Different deposit IDs within each escrow
13
+ *
14
+ * @see {@link ids} for ID serialization utilities
15
+ */
16
+ import { type Hex } from "viem";
17
+ import type { ChainId } from "./chain.js";
18
+ /**
19
+ * Compound key uniquely identifying a deposit across all chains and escrows.
20
+ *
21
+ * @remarks
22
+ * This is the primary key structure used by the indexer to track deposits.
23
+ * A deposit can only be uniquely identified by all three fields together.
24
+ */
25
+ export type DepositKey = {
26
+ /** Escrow contract address */
27
+ escrow: Hex;
28
+ /** Deposit ID within the escrow contract (per-escrow counter) */
29
+ localId: bigint;
30
+ /** Chain ID where the deposit exists */
31
+ chainId: bigint;
32
+ };
33
+ /**
34
+ * Creates a deposit compound key from blockchain event data.
35
+ *
36
+ * @param params - Event data containing escrow address, deposit ID, and chain ID
37
+ * @returns DepositKey for database operations
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const key = makeDepositKey({
42
+ * escrow: '0x2f121CDDCA6d652f35e8B3E560f9760898888888',
43
+ * depositId: 42n,
44
+ * chainId: 8453
45
+ * })
46
+ * ```
47
+ */
48
+ export declare const makeDepositKey: ({ escrow, depositId, chainId }: {
49
+ escrow: Hex;
50
+ depositId: bigint;
51
+ chainId: ChainId;
52
+ }) => DepositKey;
53
+ /**
54
+ * Serializes a deposit compound key into a single hex string.
55
+ * Format: [escrow (20 bytes)][localId (8 bytes)][chainId (4 bytes)] = 32 bytes
56
+ *
57
+ * @param depositKey - The deposit compound key to serialize
58
+ * @returns 32-byte hex string representation
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const hex = serializeDepositKey({ escrow, localId: 42n, chainId: 8453n })
63
+ * // '0x2f121CDDCA6d652f35e8B3E560f976089888888800000000000000002a00002105'
64
+ * ```
65
+ */
66
+ export declare const serializeDepositKey: ({ escrow, localId, chainId }: DepositKey) => Hex;
67
+ /**
68
+ * Converts a deposit key to foreign key field names for database relations.
69
+ * Used when inserting records that reference a deposit.
70
+ *
71
+ * @param depositKey - The deposit compound key
72
+ * @returns Object with depositEscrow, depositLocalId, depositChainId fields
73
+ */
74
+ export declare const toDepositForeignKey: (depositKey: DepositKey) => {
75
+ readonly depositEscrow: `0x${string}`;
76
+ readonly depositLocalId: bigint;
77
+ readonly depositChainId: bigint;
78
+ };
79
+ /**
80
+ * Compound key for deposit payment method (verifier) associations.
81
+ * Extends deposit key with payment method identification.
82
+ */
83
+ export type DepositVerifierAddedKey = {
84
+ depositEscrow: Hex;
85
+ depositLocalId: bigint;
86
+ depositChainId: bigint;
87
+ paymentMethodId: Hex;
88
+ };
89
+ /**
90
+ * Compound key for deposit currency support associations.
91
+ * Extends verifier key with currency identification.
92
+ */
93
+ export type DepositCurrencyAddedKey = {
94
+ depositEscrow: Hex;
95
+ depositLocalId: bigint;
96
+ depositChainId: bigint;
97
+ paymentMethodId: Hex;
98
+ currency: Hex;
99
+ };
100
+ /**
101
+ * Compound key for conversion rate update tracking.
102
+ * Extends currency key with a change counter for historical tracking.
103
+ */
104
+ export type DepositConversionRateUpdatedKey = {
105
+ depositEscrow: Hex;
106
+ depositLocalId: bigint;
107
+ depositChainId: bigint;
108
+ paymentMethodId: Hex;
109
+ currency: Hex;
110
+ changeId: number;
111
+ };
112
+ /**
113
+ * Creates a depositVerifierAdded compound key
114
+ */
115
+ export declare const makeDepositVerifierAddedKey: ({ depositKey, paymentMethodId }: {
116
+ depositKey: DepositKey;
117
+ paymentMethodId: Hex;
118
+ }) => DepositVerifierAddedKey;
119
+ /**
120
+ * Creates a depositCurrencyAdded compound key
121
+ */
122
+ export declare const makeDepositCurrencyAddedKey: ({ depositKey, paymentMethodId, currency }: {
123
+ depositKey: DepositKey;
124
+ paymentMethodId: Hex;
125
+ currency: Hex;
126
+ }) => DepositCurrencyAddedKey;
127
+ /**
128
+ * Creates a depositConversionRateUpdated compound key
129
+ */
130
+ export declare const makeDepositConversionRateUpdatedKey: ({ depositKey, paymentMethodId, currency, changeId }: {
131
+ depositKey: DepositKey;
132
+ paymentMethodId: Hex;
133
+ currency: Hex;
134
+ changeId: number;
135
+ }) => DepositConversionRateUpdatedKey;
136
+ /**
137
+ * Compound key for payment method active status changes.
138
+ * Tracks when a payment method is enabled/disabled on a deposit.
139
+ */
140
+ export type DepositPaymentMethodActiveUpdatedKey = {
141
+ depositEscrow: Hex;
142
+ depositLocalId: bigint;
143
+ depositChainId: bigint;
144
+ paymentMethodId: Hex;
145
+ changeId: number;
146
+ };
147
+ /**
148
+ * Creates a depositPaymentMethodActiveUpdated compound key
149
+ */
150
+ export declare const makeDepositPaymentMethodActiveUpdatedKey: ({ depositKey, paymentMethodId, changeId, }: {
151
+ depositKey: DepositKey;
152
+ paymentMethodId: Hex;
153
+ changeId: number;
154
+ }) => DepositPaymentMethodActiveUpdatedKey;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @fileoverview Compound key utilities for deposit and related entity identification.
3
+ *
4
+ * Deposits are uniquely identified by a compound key of (escrow, localId, chainId).
5
+ * This module provides types and utilities for creating, serializing, and
6
+ * converting these compound keys for use in database operations and event handling.
7
+ *
8
+ * @remarks
9
+ * The compound key approach allows deposits to be uniquely identified across:
10
+ * - Multiple chains (Base, Pulsechain)
11
+ * - Multiple escrow contract versions (V2, V3)
12
+ * - Different deposit IDs within each escrow
13
+ *
14
+ * @see {@link ids} for ID serialization utilities
15
+ */
16
+ import { concatHex, numberToHex } from "viem";
17
+ /**
18
+ * Creates a deposit compound key from blockchain event data.
19
+ *
20
+ * @param params - Event data containing escrow address, deposit ID, and chain ID
21
+ * @returns DepositKey for database operations
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const key = makeDepositKey({
26
+ * escrow: '0x2f121CDDCA6d652f35e8B3E560f9760898888888',
27
+ * depositId: 42n,
28
+ * chainId: 8453
29
+ * })
30
+ * ```
31
+ */
32
+ export const makeDepositKey = ({ escrow, depositId, chainId }) => ({
33
+ escrow,
34
+ localId: depositId,
35
+ chainId: BigInt(chainId),
36
+ });
37
+ /**
38
+ * Serializes a deposit compound key into a single hex string.
39
+ * Format: [escrow (20 bytes)][localId (8 bytes)][chainId (4 bytes)] = 32 bytes
40
+ *
41
+ * @param depositKey - The deposit compound key to serialize
42
+ * @returns 32-byte hex string representation
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const hex = serializeDepositKey({ escrow, localId: 42n, chainId: 8453n })
47
+ * // '0x2f121CDDCA6d652f35e8B3E560f976089888888800000000000000002a00002105'
48
+ * ```
49
+ */
50
+ export const serializeDepositKey = ({ escrow, localId, chainId }) => {
51
+ return concatHex([escrow, numberToHex(localId, { size: 8 }), numberToHex(chainId, { size: 4 })]);
52
+ };
53
+ /**
54
+ * Converts a deposit key to foreign key field names for database relations.
55
+ * Used when inserting records that reference a deposit.
56
+ *
57
+ * @param depositKey - The deposit compound key
58
+ * @returns Object with depositEscrow, depositLocalId, depositChainId fields
59
+ */
60
+ export const toDepositForeignKey = (depositKey) => ({
61
+ depositEscrow: depositKey.escrow,
62
+ depositLocalId: depositKey.localId,
63
+ depositChainId: depositKey.chainId,
64
+ });
65
+ /**
66
+ * Creates a depositVerifierAdded compound key
67
+ */
68
+ export const makeDepositVerifierAddedKey = ({ depositKey, paymentMethodId }) => ({
69
+ depositEscrow: depositKey.escrow,
70
+ depositLocalId: depositKey.localId,
71
+ depositChainId: depositKey.chainId,
72
+ paymentMethodId,
73
+ });
74
+ /**
75
+ * Creates a depositCurrencyAdded compound key
76
+ */
77
+ export const makeDepositCurrencyAddedKey = ({ depositKey, paymentMethodId, currency }) => ({
78
+ depositEscrow: depositKey.escrow,
79
+ depositLocalId: depositKey.localId,
80
+ depositChainId: depositKey.chainId,
81
+ paymentMethodId,
82
+ currency,
83
+ });
84
+ /**
85
+ * Creates a depositConversionRateUpdated compound key
86
+ */
87
+ export const makeDepositConversionRateUpdatedKey = ({ depositKey, paymentMethodId, currency, changeId }) => ({
88
+ depositEscrow: depositKey.escrow,
89
+ depositLocalId: depositKey.localId,
90
+ depositChainId: depositKey.chainId,
91
+ paymentMethodId,
92
+ currency,
93
+ changeId,
94
+ });
95
+ /**
96
+ * Creates a depositPaymentMethodActiveUpdated compound key
97
+ */
98
+ export const makeDepositPaymentMethodActiveUpdatedKey = ({ depositKey, paymentMethodId, changeId, }) => ({
99
+ depositEscrow: depositKey.escrow,
100
+ depositLocalId: depositKey.localId,
101
+ depositChainId: depositKey.chainId,
102
+ paymentMethodId,
103
+ changeId,
104
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,231 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { makeDepositKey, serializeDepositKey, toDepositForeignKey, makeDepositVerifierAddedKey, makeDepositCurrencyAddedKey, makeDepositConversionRateUpdatedKey, makeDepositPaymentMethodActiveUpdatedKey, } from './depositKeys.js';
4
+ describe('depositKeys', () => {
5
+ const TEST_ESCROW = '0x1234567890123456789012345678901234567890';
6
+ const TEST_PAYMENT_METHOD = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd';
7
+ const TEST_CURRENCY = '0x5553440000000000000000000000000000000000000000000000000000000000';
8
+ const TEST_CHAIN_ID = 8453;
9
+ describe('makeDepositKey', () => {
10
+ it('creates a deposit key from event data', () => {
11
+ const key = makeDepositKey({
12
+ escrow: TEST_ESCROW,
13
+ depositId: 123n,
14
+ chainId: TEST_CHAIN_ID,
15
+ });
16
+ assert.equal(key.escrow, TEST_ESCROW);
17
+ assert.equal(key.localId, 123n);
18
+ assert.equal(key.chainId, BigInt(TEST_CHAIN_ID));
19
+ });
20
+ it('converts numeric chainId to bigint', () => {
21
+ const key = makeDepositKey({
22
+ escrow: TEST_ESCROW,
23
+ depositId: 1n,
24
+ chainId: 369,
25
+ });
26
+ assert.equal(key.chainId, 369n);
27
+ });
28
+ });
29
+ describe('serializeDepositKey', () => {
30
+ it('serializes deposit key to hex string', () => {
31
+ const key = {
32
+ escrow: TEST_ESCROW,
33
+ localId: 1n,
34
+ chainId: 8453n,
35
+ };
36
+ const serialized = serializeDepositKey(key);
37
+ assert.ok(serialized.startsWith('0x'));
38
+ // escrow (20 bytes) + localId (8 bytes) + chainId (4 bytes) = 32 bytes = 64 hex chars + 0x
39
+ assert.equal(serialized.length, 66);
40
+ });
41
+ it('produces consistent results', () => {
42
+ const key = {
43
+ escrow: TEST_ESCROW,
44
+ localId: 42n,
45
+ chainId: 8453n,
46
+ };
47
+ const s1 = serializeDepositKey(key);
48
+ const s2 = serializeDepositKey(key);
49
+ assert.equal(s1, s2);
50
+ });
51
+ });
52
+ describe('toDepositForeignKey', () => {
53
+ it('converts deposit key to foreign key fields', () => {
54
+ const key = {
55
+ escrow: TEST_ESCROW,
56
+ localId: 5n,
57
+ chainId: 8453n,
58
+ };
59
+ const fk = toDepositForeignKey(key);
60
+ assert.equal(fk.depositEscrow, TEST_ESCROW);
61
+ assert.equal(fk.depositLocalId, 5n);
62
+ assert.equal(fk.depositChainId, 8453n);
63
+ });
64
+ });
65
+ describe('makeDepositVerifierAddedKey', () => {
66
+ it('creates compound key with deposit and payment method', () => {
67
+ const depositKey = {
68
+ escrow: TEST_ESCROW,
69
+ localId: 10n,
70
+ chainId: 8453n,
71
+ };
72
+ const key = makeDepositVerifierAddedKey({
73
+ depositKey,
74
+ paymentMethodId: TEST_PAYMENT_METHOD,
75
+ });
76
+ assert.equal(key.depositEscrow, TEST_ESCROW);
77
+ assert.equal(key.depositLocalId, 10n);
78
+ assert.equal(key.depositChainId, 8453n);
79
+ assert.equal(key.paymentMethodId, TEST_PAYMENT_METHOD);
80
+ });
81
+ });
82
+ describe('makeDepositCurrencyAddedKey', () => {
83
+ it('creates compound key with deposit, payment method, and currency', () => {
84
+ const depositKey = {
85
+ escrow: TEST_ESCROW,
86
+ localId: 20n,
87
+ chainId: 8453n,
88
+ };
89
+ const key = makeDepositCurrencyAddedKey({
90
+ depositKey,
91
+ paymentMethodId: TEST_PAYMENT_METHOD,
92
+ currency: TEST_CURRENCY,
93
+ });
94
+ assert.equal(key.depositEscrow, TEST_ESCROW);
95
+ assert.equal(key.depositLocalId, 20n);
96
+ assert.equal(key.depositChainId, 8453n);
97
+ assert.equal(key.paymentMethodId, TEST_PAYMENT_METHOD);
98
+ assert.equal(key.currency, TEST_CURRENCY);
99
+ });
100
+ });
101
+ describe('makeDepositConversionRateUpdatedKey', () => {
102
+ it('creates compound key with changeId', () => {
103
+ const depositKey = {
104
+ escrow: TEST_ESCROW,
105
+ localId: 30n,
106
+ chainId: 8453n,
107
+ };
108
+ const key = makeDepositConversionRateUpdatedKey({
109
+ depositKey,
110
+ paymentMethodId: TEST_PAYMENT_METHOD,
111
+ currency: TEST_CURRENCY,
112
+ changeId: 0,
113
+ });
114
+ assert.equal(key.depositEscrow, TEST_ESCROW);
115
+ assert.equal(key.depositLocalId, 30n);
116
+ assert.equal(key.depositChainId, 8453n);
117
+ assert.equal(key.paymentMethodId, TEST_PAYMENT_METHOD);
118
+ assert.equal(key.currency, TEST_CURRENCY);
119
+ assert.equal(key.changeId, 0);
120
+ });
121
+ it('handles sequential changeIds', () => {
122
+ const depositKey = {
123
+ escrow: TEST_ESCROW,
124
+ localId: 30n,
125
+ chainId: 8453n,
126
+ };
127
+ const key0 = makeDepositConversionRateUpdatedKey({
128
+ depositKey,
129
+ paymentMethodId: TEST_PAYMENT_METHOD,
130
+ currency: TEST_CURRENCY,
131
+ changeId: 0,
132
+ });
133
+ const key1 = makeDepositConversionRateUpdatedKey({
134
+ depositKey,
135
+ paymentMethodId: TEST_PAYMENT_METHOD,
136
+ currency: TEST_CURRENCY,
137
+ changeId: 1,
138
+ });
139
+ assert.equal(key0.changeId, 0);
140
+ assert.equal(key1.changeId, 1);
141
+ assert.notDeepEqual(key0, key1);
142
+ });
143
+ });
144
+ describe('makeDepositPaymentMethodActiveUpdatedKey', () => {
145
+ it('creates compound key with all fields', () => {
146
+ const depositKey = {
147
+ escrow: TEST_ESCROW,
148
+ localId: 40n,
149
+ chainId: 8453n,
150
+ };
151
+ const key = makeDepositPaymentMethodActiveUpdatedKey({
152
+ depositKey,
153
+ paymentMethodId: TEST_PAYMENT_METHOD,
154
+ changeId: 0,
155
+ });
156
+ assert.equal(key.depositEscrow, TEST_ESCROW);
157
+ assert.equal(key.depositLocalId, 40n);
158
+ assert.equal(key.depositChainId, 8453n);
159
+ assert.equal(key.paymentMethodId, TEST_PAYMENT_METHOD);
160
+ assert.equal(key.changeId, 0);
161
+ });
162
+ it('increments changeId correctly', () => {
163
+ const depositKey = {
164
+ escrow: TEST_ESCROW,
165
+ localId: 40n,
166
+ chainId: 8453n,
167
+ };
168
+ const key0 = makeDepositPaymentMethodActiveUpdatedKey({
169
+ depositKey,
170
+ paymentMethodId: TEST_PAYMENT_METHOD,
171
+ changeId: 0,
172
+ });
173
+ const key1 = makeDepositPaymentMethodActiveUpdatedKey({
174
+ depositKey,
175
+ paymentMethodId: TEST_PAYMENT_METHOD,
176
+ changeId: 1,
177
+ });
178
+ const key2 = makeDepositPaymentMethodActiveUpdatedKey({
179
+ depositKey,
180
+ paymentMethodId: TEST_PAYMENT_METHOD,
181
+ changeId: 2,
182
+ });
183
+ assert.equal(key0.changeId, 0);
184
+ assert.equal(key1.changeId, key0.changeId + 1);
185
+ assert.equal(key2.changeId, key1.changeId + 1);
186
+ });
187
+ it('creates different keys for different payment methods', () => {
188
+ const depositKey = {
189
+ escrow: TEST_ESCROW,
190
+ localId: 40n,
191
+ chainId: 8453n,
192
+ };
193
+ const pm1 = '0x1111111111111111111111111111111111111111111111111111111111111111';
194
+ const pm2 = '0x2222222222222222222222222222222222222222222222222222222222222222';
195
+ const key1 = makeDepositPaymentMethodActiveUpdatedKey({
196
+ depositKey,
197
+ paymentMethodId: pm1,
198
+ changeId: 0,
199
+ });
200
+ const key2 = makeDepositPaymentMethodActiveUpdatedKey({
201
+ depositKey,
202
+ paymentMethodId: pm2,
203
+ changeId: 0,
204
+ });
205
+ assert.notEqual(key1.paymentMethodId, key2.paymentMethodId);
206
+ });
207
+ it('creates different keys for different deposits', () => {
208
+ const depositKey1 = {
209
+ escrow: TEST_ESCROW,
210
+ localId: 1n,
211
+ chainId: 8453n,
212
+ };
213
+ const depositKey2 = {
214
+ escrow: TEST_ESCROW,
215
+ localId: 2n,
216
+ chainId: 8453n,
217
+ };
218
+ const key1 = makeDepositPaymentMethodActiveUpdatedKey({
219
+ depositKey: depositKey1,
220
+ paymentMethodId: TEST_PAYMENT_METHOD,
221
+ changeId: 0,
222
+ });
223
+ const key2 = makeDepositPaymentMethodActiveUpdatedKey({
224
+ depositKey: depositKey2,
225
+ paymentMethodId: TEST_PAYMENT_METHOD,
226
+ changeId: 0,
227
+ });
228
+ assert.notEqual(key1.depositLocalId, key2.depositLocalId);
229
+ });
230
+ });
231
+ });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview Event type definitions for the Provex indexer.
3
+ *
4
+ * This module defines all blockchain event types in their display order.
5
+ * The order determines how events are sorted in the UI when viewing
6
+ * deposit history - deposit creation events come first, followed by
7
+ * intent events, then close/withdrawal events.
8
+ *
9
+ * @remarks
10
+ * The eventOrderId map assigns each event a numeric ID used in orderId
11
+ * serialization for consistent cross-chain ordering.
12
+ *
13
+ * @see {@link ids} for orderId serialization
14
+ * @see {@link indexer} for event handlers
15
+ */
16
+ /**
17
+ * Ordered list of all event types supported by the indexer.
18
+ * The order determines the display sort priority in the UI.
19
+ *
20
+ * Event categories:
21
+ * 1. Deposit open events (creation, configuration)
22
+ * 2. Intent lifecycle events (signal, lock, verify, fulfill)
23
+ * 3. Deposit close events (withdrawal, close)
24
+ * 4. Protocol configuration events (dust, fees, registries)
25
+ */
26
+ export declare const eventOrder: readonly ["deposit_received", "deposit_payment_method_added", "deposit_payment_method_active_updated", "deposit_currency_added", "deposit_delegate_set", "deposit_delegate_removed", "deposit_conversion_rate_updated", "deposit_accepting_intents_updated", "deposit_intent_amount_range_updated", "deposit_funds_added", "intent_signaled", "funds_locked", "payment_verified", "funds_unlocked_and_transferred", "intent_fulfilled", "intent_pruned", "funds_unlocked", "intent_expiry_extended", "funds_removed", "deposit_withdrawn", "deposit_closed", "dust_collected", "dust_recipient_updated", "dust_threshold_updated", "deposit_retain_on_empty_updated", "payment_method_currency_added", "payment_method_currency_removed", "payment_method_added", "payment_method_removed", "allow_multiple_intents_updated", "escrow_registry_updated", "post_intent_hook_registry_updated", "protocol_fee_recipient_updated", "protocol_fee_updated", "relayer_registry_updated", "unpaused", "paused", "intent_expiration_period_updated", "max_intents_per_deposit_updated", "min_deposit_amount_set", "orchestrator_updated", "ownership_transferred", "payment_verifier_registry_updated", "provider_hash_added", "provider_hash_removed"];
27
+ /**
28
+ * Union type of all valid event type names.
29
+ * Use this when filtering or handling specific event types.
30
+ */
31
+ export type EventType = (typeof eventOrder)[number];
32
+ /**
33
+ * Map from event type name to its numeric order ID.
34
+ * Used in orderId serialization to maintain consistent ordering.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const id = eventOrderId.get('intent_signaled') // 9
39
+ * ```
40
+ */
41
+ export declare const eventOrderId: Map<"paused" | "deposit_received" | "deposit_payment_method_added" | "deposit_payment_method_active_updated" | "deposit_currency_added" | "deposit_delegate_set" | "deposit_delegate_removed" | "deposit_conversion_rate_updated" | "deposit_accepting_intents_updated" | "deposit_intent_amount_range_updated" | "deposit_funds_added" | "intent_signaled" | "funds_locked" | "payment_verified" | "funds_unlocked_and_transferred" | "intent_fulfilled" | "intent_pruned" | "funds_unlocked" | "intent_expiry_extended" | "funds_removed" | "deposit_withdrawn" | "deposit_closed" | "dust_collected" | "dust_recipient_updated" | "dust_threshold_updated" | "deposit_retain_on_empty_updated" | "payment_method_currency_added" | "payment_method_currency_removed" | "payment_method_added" | "payment_method_removed" | "allow_multiple_intents_updated" | "escrow_registry_updated" | "post_intent_hook_registry_updated" | "protocol_fee_recipient_updated" | "protocol_fee_updated" | "relayer_registry_updated" | "unpaused" | "intent_expiration_period_updated" | "max_intents_per_deposit_updated" | "min_deposit_amount_set" | "orchestrator_updated" | "ownership_transferred" | "payment_verifier_registry_updated" | "provider_hash_added" | "provider_hash_removed", number>;