@rozoai/intent-common 0.0.28-beta.2 → 0.0.28-beta.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.
@@ -0,0 +1,215 @@
1
+ /**
2
+ * RozoAI API Configuration Constants
3
+ */
4
+ export const ROZO_API_URL = "https://intentapiv2.rozo.ai/functions/v1";
5
+ export const ROZO_API_TOKEN =
6
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ4Y3Zmb2xobmNtdXZmYXp1cXViIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTI4Mzg2NjYsImV4cCI6MjA2ODQxNDY2Nn0.B4dV5y_-zCMKSNm3_qyCbAvCPJmoOGv_xB783LfAVUA";
7
+
8
+ // HTTP methods type
9
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
10
+
11
+ // Request options type
12
+ export interface RequestOptions {
13
+ method?: HttpMethod;
14
+ headers?: Record<string, string>;
15
+ body?: any;
16
+ params?: Record<string, string>;
17
+ signal?: AbortSignal;
18
+ }
19
+
20
+ // Response type with generic data
21
+ export interface ApiResponse<T = any> {
22
+ data: T | null;
23
+ error: Error | null;
24
+ status: number | null;
25
+ }
26
+
27
+ // Request state for hooks (used in connectkit)
28
+ export interface RequestState<T = any> extends ApiResponse<T> {
29
+ isLoading: boolean;
30
+ isError: boolean;
31
+ isSuccess: boolean;
32
+ }
33
+
34
+ /**
35
+ * API Configuration
36
+ */
37
+ export interface ApiConfig {
38
+ baseUrl: string;
39
+ apiToken: string;
40
+ }
41
+
42
+ // Default configuration (can be overridden via setApiConfig)
43
+ let apiConfig: ApiConfig = {
44
+ baseUrl: ROZO_API_URL,
45
+ apiToken: ROZO_API_TOKEN,
46
+ };
47
+
48
+ /**
49
+ * Set API configuration
50
+ * @param config - API configuration
51
+ */
52
+ export const setApiConfig = (config: Partial<ApiConfig>) => {
53
+ apiConfig = { ...apiConfig, ...config };
54
+ };
55
+
56
+ /**
57
+ * Get current API configuration
58
+ * @returns Current API configuration
59
+ */
60
+ export const getApiConfig = (): ApiConfig => {
61
+ return apiConfig;
62
+ };
63
+
64
+ /**
65
+ * Creates a URL with query parameters
66
+ * @param url - Base URL
67
+ * @param params - Query parameters
68
+ * @returns Full URL with query parameters
69
+ */
70
+ const createUrl = (url: string, params?: Record<string, string>): string => {
71
+ const fullUrl = url.startsWith("/")
72
+ ? `${apiConfig.baseUrl}${url}`
73
+ : `${apiConfig.baseUrl}/${url}`;
74
+
75
+ if (!params) return fullUrl;
76
+
77
+ const queryParams = new URLSearchParams();
78
+ Object.entries(params).forEach(([key, value]) => {
79
+ if (value !== undefined && value !== null) {
80
+ queryParams.append(key, value);
81
+ }
82
+ });
83
+
84
+ const queryString = queryParams.toString();
85
+ return queryString ? `${fullUrl}?${queryString}` : fullUrl;
86
+ };
87
+
88
+ /**
89
+ * Core fetch function for making API requests
90
+ * @param url - API endpoint path
91
+ * @param options - Request options
92
+ * @returns Promise with response data
93
+ */
94
+ export const fetchApi = async <T = any>(
95
+ url: string,
96
+ options: RequestOptions = {}
97
+ ): Promise<ApiResponse<T>> => {
98
+ const { method = "GET", headers = {}, body, params, signal } = options;
99
+
100
+ try {
101
+ const fullUrl = createUrl(url, params);
102
+
103
+ const requestHeaders: Record<string, string> = {
104
+ "Content-Type": "application/json",
105
+ ...headers,
106
+ Authorization: `Bearer ${apiConfig.apiToken}`,
107
+ };
108
+
109
+ const requestOptions: {
110
+ method: string;
111
+ headers: Record<string, string>;
112
+ signal?: AbortSignal;
113
+ body?: string;
114
+ } = {
115
+ method,
116
+ headers: requestHeaders,
117
+ signal,
118
+ };
119
+
120
+ if (body && method !== "GET") {
121
+ requestOptions.body = JSON.stringify(body);
122
+ }
123
+
124
+ const response = await fetch(fullUrl, requestOptions);
125
+ const status = response.status;
126
+
127
+ // Handle non-JSON responses
128
+ const contentType = response.headers.get("content-type");
129
+ let data: T | null = null;
130
+
131
+ if (contentType && contentType.includes("application/json")) {
132
+ data = (await response.json()) as T;
133
+ } else if (contentType && contentType.includes("text/")) {
134
+ data = (await response.text()) as unknown as T;
135
+ }
136
+
137
+ if (!response.ok) {
138
+ throw new Error(data ? JSON.stringify(data) : response.statusText);
139
+ }
140
+
141
+ return { data, error: null, status };
142
+ } catch (error) {
143
+ return {
144
+ data: null,
145
+ error: error instanceof Error ? error : new Error(String(error)),
146
+ status: null,
147
+ };
148
+ }
149
+ };
150
+
151
+ /**
152
+ * API client with methods for different HTTP verbs
153
+ */
154
+ export const apiClient = {
155
+ /**
156
+ * GET request
157
+ * @param url - API endpoint path
158
+ * @param options - Request options
159
+ * @returns Promise with response data
160
+ */
161
+ get: <T = any>(
162
+ url: string,
163
+ options: Omit<RequestOptions, "method" | "body"> = {}
164
+ ) => fetchApi<T>(url, { ...options, method: "GET" }),
165
+
166
+ /**
167
+ * POST request
168
+ * @param url - API endpoint path
169
+ * @param body - Request body
170
+ * @param options - Additional request options
171
+ * @returns Promise with response data
172
+ */
173
+ post: <T = any>(
174
+ url: string,
175
+ body: any,
176
+ options: Omit<RequestOptions, "method" | "body"> = {}
177
+ ) => fetchApi<T>(url, { ...options, method: "POST", body }),
178
+
179
+ /**
180
+ * PUT request
181
+ * @param url - API endpoint path
182
+ * @param body - Request body
183
+ * @param options - Additional request options
184
+ * @returns Promise with response data
185
+ */
186
+ put: <T = any>(
187
+ url: string,
188
+ body: any,
189
+ options: Omit<RequestOptions, "method" | "body"> = {}
190
+ ) => fetchApi<T>(url, { ...options, method: "PUT", body }),
191
+
192
+ /**
193
+ * PATCH request
194
+ * @param url - API endpoint path
195
+ * @param body - Request body
196
+ * @param options - Additional request options
197
+ * @returns Promise with response data
198
+ */
199
+ patch: <T = any>(
200
+ url: string,
201
+ body: any,
202
+ options: Omit<RequestOptions, "method" | "body"> = {}
203
+ ) => fetchApi<T>(url, { ...options, method: "PATCH", body }),
204
+
205
+ /**
206
+ * DELETE request
207
+ * @param url - API endpoint path
208
+ * @param options - Request options
209
+ * @returns Promise with response data
210
+ */
211
+ delete: <T = any>(
212
+ url: string,
213
+ options: Omit<RequestOptions, "method"> = {}
214
+ ) => fetchApi<T>(url, { ...options, method: "DELETE" }),
215
+ };
@@ -0,0 +1,112 @@
1
+ import { apiClient, ApiResponse } from "./base";
2
+
3
+ /**
4
+ * Payment display information
5
+ */
6
+ export interface PaymentDisplay {
7
+ intent: string;
8
+ paymentValue: string;
9
+ currency: string;
10
+ }
11
+
12
+ /**
13
+ * Payment destination information
14
+ */
15
+ export interface PaymentDestination {
16
+ destinationAddress?: string;
17
+ chainId: string;
18
+ amountUnits: string;
19
+ tokenSymbol: string;
20
+ tokenAddress?: string;
21
+ txHash?: string | null;
22
+ }
23
+
24
+ /**
25
+ * Payment source information
26
+ */
27
+ export interface PaymentSource {
28
+ sourceAddress?: string;
29
+ [key: string]: unknown;
30
+ }
31
+
32
+ /**
33
+ * Payment request data type
34
+ */
35
+ export interface PaymentRequestData {
36
+ appId: string;
37
+ display: PaymentDisplay;
38
+ destination: PaymentDestination;
39
+ externalId?: string;
40
+ metadata?: Record<string, unknown>;
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ /**
45
+ * Payment response data type
46
+ */
47
+ export interface PaymentResponseData {
48
+ id: string;
49
+ status: "payment_unpaid" | string;
50
+ createdAt: string;
51
+ display: {
52
+ intent: string;
53
+ currency: string;
54
+ paymentValue?: string;
55
+ };
56
+ source: PaymentSource | null;
57
+ destination: {
58
+ destinationAddress: string;
59
+ txHash: string | null;
60
+ chainId: string;
61
+ amountUnits: string;
62
+ tokenSymbol: string;
63
+ tokenAddress: string;
64
+ };
65
+ metadata: {
66
+ daimoOrderId?: string;
67
+ intent: string;
68
+ items: unknown[];
69
+ payer: Record<string, unknown>;
70
+ appId: string;
71
+ orderDate: string;
72
+ webhookUrl: string;
73
+ provider: string;
74
+ receivingAddress: string;
75
+ memo: string | null;
76
+ payinchainid: string;
77
+ payintokenaddress: string;
78
+ preferredChain: string;
79
+ preferredToken: string;
80
+ preferredTokenAddress: string;
81
+ source_tx_hash?: string;
82
+ [key: string]: unknown;
83
+ };
84
+ url: string;
85
+ [key: string]: unknown;
86
+ }
87
+
88
+ /**
89
+ * Creates a new payment
90
+ * @param paymentData - Payment data to send
91
+ * @returns Promise with payment response
92
+ */
93
+ export const createRozoPayment = (
94
+ paymentData: PaymentRequestData
95
+ ): Promise<ApiResponse<PaymentResponseData>> => {
96
+ return apiClient.post<PaymentResponseData>("/payment-api", paymentData);
97
+ };
98
+
99
+ /**
100
+ * Gets payment details by ID
101
+ * @param paymentId - Payment ID
102
+ * @returns Promise with payment response
103
+ */
104
+ export const getRozoPayment = (
105
+ paymentId: string
106
+ ): Promise<ApiResponse<PaymentResponseData>> => {
107
+ const isMugglePay = paymentId.includes("mugglepay_order");
108
+ const endpoint = isMugglePay
109
+ ? `payment-api/${paymentId}`
110
+ : `payment/id/${paymentId}`;
111
+ return apiClient.get<PaymentResponseData>(endpoint);
112
+ };
package/src/bridge.ts ADDED
@@ -0,0 +1,382 @@
1
+ import { parseUnits } from "viem";
2
+ import {
3
+ base,
4
+ baseUSDC,
5
+ bscUSDT,
6
+ getKnownToken,
7
+ polygonUSDC,
8
+ RozoPayHydratedOrderWithOrg,
9
+ RozoPayIntentStatus,
10
+ RozoPayOrderMode,
11
+ RozoPayOrderStatusDest,
12
+ RozoPayOrderStatusSource,
13
+ RozoPayUserMetadata,
14
+ rozoSolanaUSDC,
15
+ rozoStellar,
16
+ rozoStellarUSDC,
17
+ } from ".";
18
+ import type { PaymentResponseData } from "./api/payment";
19
+
20
+ export interface PaymentBridgeConfig {
21
+ toChain?: number;
22
+ toToken?: string;
23
+ toAddress: string;
24
+ toStellarAddress?: string;
25
+ toSolanaAddress?: string;
26
+ toUnits: string;
27
+ payInTokenAddress: string;
28
+ log?: (msg: string) => void;
29
+ }
30
+
31
+ export interface PreferredPaymentConfig {
32
+ preferredChain: string;
33
+ preferredToken: "USDC" | "USDT" | "XLM";
34
+ preferredTokenAddress?: string;
35
+ }
36
+
37
+ export interface DestinationConfig {
38
+ destinationAddress?: string;
39
+ chainId: string;
40
+ amountUnits: string;
41
+ tokenSymbol: string;
42
+ tokenAddress: string;
43
+ }
44
+
45
+ /**
46
+ * Creates payment bridge configuration for cross-chain payment routing
47
+ *
48
+ * Determines the optimal payment routing based on the destination chain/token
49
+ * and the wallet payment option selected by the user. This function handles
50
+ * the complexity of multi-chain payments by:
51
+ *
52
+ * 1. **Preferred Payment Method**: Identifies which chain/token the user will pay from
53
+ * - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, and BSC USDT
54
+ * - Sets appropriate chain ID and token address for the source transaction
55
+ *
56
+ * 2. **Destination Configuration**: Determines where funds will be received
57
+ * - Supports Base, Solana, and Stellar as destination chains
58
+ * - Handles special address formats for Solana and Stellar addresses
59
+ * - Defaults to Base USDC when no special destination is specified
60
+ *
61
+ * 3. **Cross-Chain Bridging**: Configures the payment bridge parameters
62
+ * - Maps user's selected wallet/token to the appropriate payment method
63
+ * - Sets up destination chain and token configuration
64
+ * - Handles token address formatting (e.g., Stellar's `USDC:issuerPK` format)
65
+ *
66
+ * @param config - Payment bridge configuration parameters
67
+ * @param config.toChain - Destination chain ID (defaults to Base: 8453)
68
+ * @param config.toToken - Destination token address (defaults to Base USDC)
69
+ * @param config.toAddress - Standard EVM destination address
70
+ * @param config.toStellarAddress - Stellar-specific destination address (if paying to Stellar)
71
+ * @param config.toSolanaAddress - Solana-specific destination address (if paying to Solana)
72
+ * @param config.toUnits - Amount in token units (smallest denomination)
73
+ * @param config.payInTokenAddress - Token address user selected to pay with
74
+ * @param config.log - Optional logging function for debugging
75
+ *
76
+ * @returns Payment routing configuration
77
+ * @returns preferred - Source payment configuration (chain, token user will pay from)
78
+ * @returns destination - Destination payment configuration (chain, token user will receive)
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // User wants to pay with Polygon USDC to receive on Base
83
+ * const { preferred, destination } = createPaymentBridgeConfig({
84
+ * toChain: 8453, // Base
85
+ * toToken: baseUSDC.token,
86
+ * toAddress: '0x123...',
87
+ * toUnits: '1000000', // 1 USDC
88
+ * payInTokenAddress: polygonUSDC.token,
89
+ * log: console.log
90
+ * });
91
+ *
92
+ * // preferred = { preferredChain: '137', preferredToken: 'USDC', preferredTokenAddress: '0x2791...' }
93
+ * // destination = { destinationAddress: '0x123...', chainId: '8453', amountUnits: '1000000', ... }
94
+ * ```
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // User wants to pay to a Stellar address
99
+ * const { preferred, destination } = createPaymentBridgeConfig({
100
+ * toStellarAddress: 'GDZS...',
101
+ * toUnits: '1000000',
102
+ * payInTokenAddress: baseUSDC.token,
103
+ * });
104
+ *
105
+ * // destination will be configured for Stellar chain with USDC:issuerPK format
106
+ * ```
107
+ *
108
+ * @note Currently only supports Base USDC and Stellar USDC as destination chains.
109
+ * Support for additional destination chains is planned.
110
+ *
111
+ * @see PreferredPaymentConfig
112
+ * @see DestinationConfig
113
+ */
114
+ export function createPaymentBridgeConfig({
115
+ toChain = baseUSDC.chainId,
116
+ toToken = baseUSDC.token,
117
+ toAddress,
118
+ toStellarAddress,
119
+ toSolanaAddress,
120
+ toUnits,
121
+ payInTokenAddress,
122
+ log,
123
+ }: PaymentBridgeConfig): {
124
+ preferred: PreferredPaymentConfig;
125
+ destination: DestinationConfig;
126
+ } {
127
+ // Default configuration for Base USDC payments
128
+ let preferred: PreferredPaymentConfig = {
129
+ preferredChain: String(toChain),
130
+ preferredToken: "USDC",
131
+ };
132
+
133
+ let destination: DestinationConfig = {
134
+ destinationAddress: toAddress,
135
+ chainId: String(toChain),
136
+ amountUnits: toUnits,
137
+ tokenSymbol: "USDC",
138
+ tokenAddress: toToken,
139
+ };
140
+
141
+ /**
142
+ * IMPORTANT: Because we only support PAY OUT USDC BASE & STELLAR
143
+ * So, We force toChain and toToken to Base USDC as default PayParams
144
+ *
145
+ * @TODO: Adjust this when we support another PAY OUT chain
146
+ */
147
+ if (toChain === base.chainId && toToken === baseUSDC.token) {
148
+ // Determine preferred payment method based on wallet selection
149
+ if (payInTokenAddress) {
150
+ // Pay In USDC Polygon
151
+ if (payInTokenAddress === polygonUSDC.token) {
152
+ log?.(`[Payment Bridge] Pay In USDC Polygon`);
153
+ preferred = {
154
+ preferredChain: String(polygonUSDC.chainId),
155
+ preferredToken: "USDC",
156
+ preferredTokenAddress: polygonUSDC.token,
157
+ };
158
+ }
159
+ // Pay In USDC Solana
160
+ else if (payInTokenAddress === rozoSolanaUSDC.token) {
161
+ log?.(`[Payment Bridge] Pay In USDC Solana`);
162
+ preferred = {
163
+ preferredChain: String(rozoSolanaUSDC.chainId),
164
+ preferredToken: "USDC",
165
+ preferredTokenAddress: rozoSolanaUSDC.token,
166
+ };
167
+ }
168
+ // Pay In USDC Stellar
169
+ else if (payInTokenAddress === rozoStellarUSDC.token) {
170
+ log?.(`[Payment Bridge] Pay In USDC Stellar`);
171
+ preferred = {
172
+ preferredChain: String(rozoStellarUSDC.chainId),
173
+ preferredToken: "USDC",
174
+ preferredTokenAddress: `USDC:${rozoStellarUSDC.token}`,
175
+ };
176
+ }
177
+ // Pay In USDT BSC
178
+ else if (payInTokenAddress === bscUSDT.token) {
179
+ log?.(`[Payment Bridge] Pay In USDT BSC`);
180
+ preferred = {
181
+ preferredChain: String(bscUSDT.chainId),
182
+ preferredToken: "USDT",
183
+ preferredTokenAddress: bscUSDT.token,
184
+ };
185
+ }
186
+ }
187
+
188
+ // Determine destination based on special address types
189
+ if (toStellarAddress) {
190
+ log?.(`[Payment Bridge] Pay Out USDC Stellar`);
191
+ destination = {
192
+ destinationAddress: toStellarAddress,
193
+ chainId: String(rozoStellar.chainId),
194
+ amountUnits: toUnits,
195
+ tokenSymbol: "USDC",
196
+ tokenAddress: `USDC:${rozoStellarUSDC.token}`,
197
+ };
198
+ } else if (toSolanaAddress) {
199
+ log?.(`[Payment Bridge] Pay Out USDC Solana`);
200
+ destination = {
201
+ destinationAddress: toSolanaAddress,
202
+ chainId: String(rozoSolanaUSDC.chainId),
203
+ amountUnits: toUnits,
204
+ tokenSymbol: "USDC",
205
+ tokenAddress: rozoSolanaUSDC.token,
206
+ };
207
+ } else {
208
+ log?.(`[Payment Bridge] Pay Out USDC Base`);
209
+ // Keep default Base configuration
210
+ }
211
+ }
212
+
213
+ return { preferred, destination };
214
+ }
215
+
216
+ /**
217
+ * Transforms a payment API response into a fully hydrated order object
218
+ *
219
+ * Converts the payment response data from the RozoAI payment API into a complete
220
+ * `RozoPayHydratedOrderWithOrg` object that contains all the information needed
221
+ * to display order status, track payments, and handle cross-chain transactions.
222
+ *
223
+ * This function performs several key transformations:
224
+ *
225
+ * 1. **Token Resolution**: Identifies the correct token based on chain and address
226
+ * - Uses `getKnownToken()` to resolve token metadata (decimals, symbol, logo, etc.)
227
+ * - Handles special cases for Stellar tokens using issuer public key
228
+ *
229
+ * 2. **Order Structure**: Creates a complete order with all required fields
230
+ * - Generates random order ID for internal tracking
231
+ * - Sets up intent, handoff, and contract addresses
232
+ * - Configures bridge token options and destination amounts
233
+ *
234
+ * 3. **Status Initialization**: Sets initial payment statuses
235
+ * - Source status: WAITING_PAYMENT (awaiting user transaction)
236
+ * - Destination status: PENDING (not yet received)
237
+ * - Intent status: UNPAID (payment not initiated)
238
+ *
239
+ * 4. **Metadata Merge**: Combines various metadata sources
240
+ * - Merges order metadata, user metadata, and custom metadata
241
+ * - Preserves external ID and organization information
242
+ *
243
+ * @param order - Payment response data from the RozoAI payment API
244
+ * @param order.metadata - Payment metadata including chain, token, and routing info
245
+ * @param order.destination - Destination configuration (chain, token, amount, address)
246
+ * @param order.source - Source transaction info (if payment has been initiated)
247
+ * @param order.orgId - Organization ID for the payment
248
+ * @param order.externalId - External reference ID (if provided by merchant)
249
+ *
250
+ * @returns Complete hydrated order object with all payment tracking information
251
+ * @returns id - Unique order identifier (random BigInt)
252
+ * @returns mode - Order mode (HYDRATED)
253
+ * @returns sourceStatus - Source transaction status
254
+ * @returns destStatus - Destination transaction status
255
+ * @returns intentStatus - Overall payment intent status
256
+ * @returns metadata - Merged metadata from all sources
257
+ * @returns org - Organization information
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * const paymentResponse = await getRozoPayment(paymentId);
262
+ *
263
+ * const hydratedOrder = formatPaymentResponseDataToHydratedOrder(
264
+ * paymentResponse.data,
265
+ * 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'
266
+ * );
267
+ *
268
+ * console.log(hydratedOrder.sourceStatus); // 'WAITING_PAYMENT'
269
+ * console.log(hydratedOrder.destFinalCallTokenAmount.token.symbol); // 'USDC'
270
+ * console.log(hydratedOrder.usdValue); // 10.00
271
+ * ```
272
+ *
273
+ * @note The generated order ID is random and intended for client-side tracking only.
274
+ * Use `externalId` or the API payment ID for server-side reference.
275
+ *
276
+ * @note The function sets a 5-minute expiration timestamp from the current time.
277
+ *
278
+ * @see PaymentResponseData
279
+ * @see RozoPayHydratedOrderWithOrg
280
+ * @see getKnownToken
281
+ */
282
+ export function formatResponseToHydratedOrder(
283
+ order: PaymentResponseData
284
+ ): RozoPayHydratedOrderWithOrg {
285
+ const destAddress = order.metadata.receivingAddress as `0x${string}`;
286
+
287
+ const requiredChain = order.metadata.preferredChain || baseUSDC.chainId;
288
+
289
+ const chain = getKnownToken(
290
+ Number(requiredChain),
291
+ Number(requiredChain) === rozoStellar.chainId
292
+ ? rozoStellarUSDC.token
293
+ : order.metadata.preferredTokenAddress
294
+ );
295
+
296
+ return {
297
+ id: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
298
+ mode: RozoPayOrderMode.HYDRATED,
299
+ intentAddr: destAddress,
300
+ handoffAddr: destAddress,
301
+ escrowContractAddress: destAddress,
302
+ bridgerContractAddress: destAddress,
303
+ // @TODO: use correct destination token
304
+ bridgeTokenOutOptions: [
305
+ {
306
+ token: {
307
+ chainId: baseUSDC.chainId,
308
+ token: baseUSDC.token,
309
+ symbol: baseUSDC.symbol,
310
+ usd: 1,
311
+ priceFromUsd: 1,
312
+ decimals: baseUSDC.decimals,
313
+ displayDecimals: 2,
314
+ logoSourceURI: baseUSDC.logoSourceURI,
315
+ logoURI: baseUSDC.logoURI,
316
+ maxAcceptUsd: 100000,
317
+ maxSendUsd: 0,
318
+ },
319
+ amount: parseUnits(
320
+ order.destination.amountUnits,
321
+ baseUSDC.decimals
322
+ ).toString() as `${bigint}`,
323
+ usd: Number(order.destination.amountUnits),
324
+ },
325
+ ],
326
+ selectedBridgeTokenOutAddr: null,
327
+ selectedBridgeTokenOutAmount: null,
328
+ destFinalCallTokenAmount: {
329
+ token: {
330
+ chainId: chain ? chain.chainId : baseUSDC.chainId,
331
+ token: chain ? chain.token : baseUSDC.token,
332
+ symbol: chain ? chain.symbol : baseUSDC.symbol,
333
+ usd: 1,
334
+ priceFromUsd: 1,
335
+ decimals: chain ? chain.decimals : baseUSDC.decimals,
336
+ displayDecimals: 2,
337
+ logoSourceURI: chain ? chain.logoSourceURI : baseUSDC.logoSourceURI,
338
+ logoURI: chain ? chain.logoURI : baseUSDC.logoURI,
339
+ maxAcceptUsd: 100000,
340
+ maxSendUsd: 0,
341
+ },
342
+ amount: parseUnits(
343
+ order.destination.amountUnits,
344
+ chain ? chain.decimals : baseUSDC.decimals
345
+ ).toString() as `${bigint}`,
346
+ usd: Number(order.destination.amountUnits),
347
+ },
348
+ usdValue: Number(order.destination.amountUnits),
349
+ destFinalCall: {
350
+ to: destAddress,
351
+ value: BigInt("0"),
352
+ data: "0x",
353
+ },
354
+ refundAddr: (order.source?.sourceAddress as `0x${string}`) || null,
355
+ nonce: order.nonce as unknown as bigint,
356
+ sourceTokenAmount: null,
357
+ sourceFulfillerAddr: null,
358
+ sourceInitiateTxHash: null,
359
+ sourceStartTxHash: null,
360
+ sourceStatus: RozoPayOrderStatusSource.WAITING_PAYMENT,
361
+ destStatus: RozoPayOrderStatusDest.PENDING,
362
+ intentStatus: RozoPayIntentStatus.UNPAID,
363
+ destFastFinishTxHash: null,
364
+ destClaimTxHash: null,
365
+ redirectUri: null,
366
+ createdAt: Math.floor(Date.now() / 1000),
367
+ lastUpdatedAt: Math.floor(Date.now() / 1000),
368
+ orgId: order.orgId as string,
369
+ metadata: {
370
+ ...(order?.metadata ?? {}),
371
+ ...(order.userMetadata ?? {}),
372
+ ...(order.metadata ?? {}),
373
+ } as any,
374
+ externalId: order.externalId as string | null,
375
+ userMetadata: order.userMetadata as RozoPayUserMetadata | null,
376
+ expirationTs: BigInt(Math.floor(Date.now() / 1000 + 5 * 60).toString()),
377
+ org: {
378
+ orgId: order.orgId as string,
379
+ name: "Pay Rozo",
380
+ },
381
+ };
382
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
+ export * from "./api/payment";
1
2
  export * from "./assert";
3
+ export * from "./bridge";
2
4
  export * from "./chain";
3
5
  export * from "./daimoPay";
4
6
  export * from "./debug";