@provex/utils 1.0.16 → 1.2.3
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/src/chain.d.ts +436 -4
- package/dist/src/chain.js +80 -0
- package/dist/src/chain.test.d.ts +1 -0
- package/dist/src/chain.test.js +112 -0
- package/dist/src/contracts.d.ts +196 -20
- package/dist/src/contracts.js +245 -17
- package/dist/src/contracts.test.d.ts +1 -0
- package/dist/src/contracts.test.js +243 -0
- package/dist/src/conversionRates.d.ts +99 -8
- package/dist/src/conversionRates.js +74 -4
- package/dist/src/conversionRates.test.d.ts +1 -0
- package/dist/src/conversionRates.test.js +473 -0
- package/dist/src/currencies.d.ts +113 -9
- package/dist/src/currencies.js +119 -38
- package/dist/src/currencies.test.d.ts +1 -0
- package/dist/src/currencies.test.js +343 -0
- package/dist/src/data/countries.json +166 -166
- package/dist/src/deposit.d.ts +69 -1
- package/dist/src/deposit.js +52 -1
- package/dist/src/depositKeys.d.ts +154 -0
- package/dist/src/depositKeys.js +104 -0
- package/dist/src/depositKeys.test.d.ts +1 -0
- package/dist/src/depositKeys.test.js +231 -0
- package/dist/src/endpoints.d.ts +51 -0
- package/dist/src/endpoints.js +70 -0
- package/dist/src/endpoints.test.d.ts +1 -0
- package/dist/src/endpoints.test.js +54 -0
- package/dist/src/events.d.ts +40 -2
- package/dist/src/events.js +86 -10
- package/dist/src/events.test.d.ts +1 -0
- package/dist/src/events.test.js +111 -0
- package/dist/src/fees.d.ts +136 -0
- package/dist/src/fees.js +178 -0
- package/dist/src/fees.test.d.ts +1 -0
- package/dist/src/fees.test.js +165 -0
- package/dist/src/ids.d.ts +125 -22
- package/dist/src/ids.js +211 -61
- package/dist/src/ids.test.d.ts +1 -0
- package/dist/src/ids.test.js +607 -0
- package/dist/src/index.d.ts +30 -1
- package/dist/src/index.js +30 -1
- package/dist/src/input.d.ts +23 -4
- package/dist/src/input.js +23 -4
- package/dist/src/intent.d.ts +38 -2
- package/dist/src/intent.js +28 -1
- package/dist/src/intent.test.d.ts +1 -0
- package/dist/src/intent.test.js +119 -0
- package/dist/src/json.d.ts +38 -1
- package/dist/src/json.js +38 -2
- package/dist/src/normalization.d.ts +224 -0
- package/dist/src/normalization.js +119 -0
- package/dist/src/normalization.test.d.ts +1 -0
- package/dist/src/normalization.test.js +284 -0
- package/dist/src/participants.d.ts +19 -4
- package/dist/src/participants.js +19 -4
- package/dist/src/payment.d.ts +333 -16
- package/dist/src/payment.js +768 -58
- package/dist/src/payment.test.d.ts +1 -0
- package/dist/src/payment.test.js +272 -0
- package/dist/src/peer-types.d.ts +327 -0
- package/dist/src/peer-types.js +169 -0
- package/dist/src/profit.d.ts +26 -5
- package/dist/src/profit.js +31 -8
- package/dist/src/profit.test.d.ts +1 -0
- package/dist/src/profit.test.js +315 -0
- package/dist/src/reputation.d.ts +125 -0
- package/dist/src/reputation.js +188 -0
- package/dist/src/reputation.test.d.ts +1 -0
- package/dist/src/reputation.test.js +156 -0
- package/dist/src/sort.d.ts +49 -10
- package/dist/src/sort.js +40 -9
- package/dist/src/sort.test.d.ts +1 -0
- package/dist/src/sort.test.js +216 -0
- package/dist/src/stateKey.d.ts +35 -0
- package/dist/src/stateKey.js +36 -0
- package/dist/src/stats.d.ts +55 -1
- package/dist/src/stats.js +46 -1
- package/dist/src/stats.test.d.ts +1 -0
- package/dist/src/stats.test.js +104 -0
- package/dist/src/time.d.ts +59 -9
- package/dist/src/time.js +71 -15
- package/dist/src/time.test.d.ts +1 -0
- package/dist/src/time.test.js +231 -0
- package/dist/src/tokens.d.ts +11972 -145
- package/dist/src/tokens.js +98 -17
- package/dist/src/tokens.test.d.ts +1 -0
- package/dist/src/tokens.test.js +193 -0
- package/dist/src/units.d.ts +183 -0
- package/dist/src/units.js +206 -6
- package/dist/src/units.test.d.ts +1 -0
- package/dist/src/units.test.js +327 -0
- package/dist/src/zkp2p-types.d.ts +273 -4
- package/dist/src/zkp2p-types.js +169 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +116 -26
- 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/src/deposit.d.ts
CHANGED
|
@@ -1 +1,69 @@
|
|
|
1
|
-
|
|
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[];
|
package/dist/src/deposit.js
CHANGED
|
@@ -1 +1,52 @@
|
|
|
1
|
-
|
|
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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service endpoint URLs for the Provex platform.
|
|
3
|
+
*
|
|
4
|
+
* Each URL resolves at module load time using this priority:
|
|
5
|
+
* 1. Vite env (`import.meta.env.VITE_<NAME>`)
|
|
6
|
+
* 2. Node env (`process.env.<NAME>` or `process.env.VITE_<NAME>`)
|
|
7
|
+
* 3. Hardcoded production default
|
|
8
|
+
*
|
|
9
|
+
* Override any URL by setting the corresponding environment variable
|
|
10
|
+
* before the module is imported.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // In .env or shell
|
|
14
|
+
* VITE_SPONSOR_SERVER_URL=http://localhost:3001
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Base URL for the gas-sponsorship relay server.
|
|
18
|
+
*
|
|
19
|
+
* The sponsor server wraps user operations in a sponsored transaction
|
|
20
|
+
* so end-users never need native gas tokens.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue `https://sponsor.provex.xyz`
|
|
23
|
+
*/
|
|
24
|
+
export declare const SPONSOR_SERVER_URL: string;
|
|
25
|
+
/**
|
|
26
|
+
* WebSocket URL for the Reclaim Protocol attestor node.
|
|
27
|
+
*
|
|
28
|
+
* Used during the ZK proof generation flow to obtain a TLS attestation
|
|
29
|
+
* of payment-provider API responses.
|
|
30
|
+
*
|
|
31
|
+
* @defaultValue `wss://attestor.reclaimprotocol.org/ws`
|
|
32
|
+
*/
|
|
33
|
+
export declare const ATTESTOR_WS_URL: string;
|
|
34
|
+
/**
|
|
35
|
+
* GraphQL endpoint for the Provex indexer.
|
|
36
|
+
*
|
|
37
|
+
* Serves deposit listings, intent history, and on-chain event data
|
|
38
|
+
* consumed by the UI and analytics dashboard.
|
|
39
|
+
*
|
|
40
|
+
* @defaultValue `https://indexer.provex.xyz/graphql`
|
|
41
|
+
*/
|
|
42
|
+
export declare const INDEXER_GRAPHQL_URL: string;
|
|
43
|
+
/**
|
|
44
|
+
* Base URL for the attestation verification service.
|
|
45
|
+
*
|
|
46
|
+
* Validates TLS attestations produced by the attestor before they
|
|
47
|
+
* are submitted on-chain as proof of payment.
|
|
48
|
+
*
|
|
49
|
+
* @defaultValue `https://attestation.provex.xyz`
|
|
50
|
+
*/
|
|
51
|
+
export declare const ATTESTATION_SERVICE_URL: string;
|