@rozoai/intent-common 0.1.0-beta.1 → 0.1.0-beta.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/api/payment.d.ts +264 -139
- package/dist/api/payment.js +95 -89
- package/dist/api/payment.js.map +1 -1
- package/dist/{bridge.d.ts → bridge-utils.d.ts} +37 -55
- package/dist/{bridge.js → bridge-utils.js} +55 -132
- package/dist/bridge-utils.js.map +1 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +16 -0
- package/dist/format.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/{daimoPay.js → rozoPay.js} +1 -1
- package/dist/rozoPay.js.map +1 -0
- package/dist/token.js +2 -0
- package/dist/token.js.map +1 -1
- package/package.json +1 -1
- package/src/api/payment.ts +336 -174
- package/src/{bridge.ts → bridge-utils.ts} +58 -140
- package/src/format.ts +30 -0
- package/src/index.ts +2 -3
- package/src/token.ts +3 -0
- package/test/bridge.test.ts +4 -1
- package/dist/api/new-payment.d.ts +0 -319
- package/dist/api/new-payment.js +0 -140
- package/dist/api/new-payment.js.map +0 -1
- package/dist/bridge.js.map +0 -1
- package/dist/daimoPay.js.map +0 -1
- package/src/api/README.md +0 -554
- package/src/api/new-payment.ts +0 -433
- package/dist/{daimoPay.d.ts → rozoPay.d.ts} +8 -8
- /package/src/{daimoPay.ts → rozoPay.ts} +0 -0
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
rozoStellarUSDC,
|
|
17
17
|
validateAddressForChain,
|
|
18
18
|
} from ".";
|
|
19
|
-
import type { PaymentResponseData } from "./api/payment";
|
|
20
19
|
|
|
21
20
|
export interface PaymentBridgeConfig {
|
|
22
21
|
toChain: number;
|
|
@@ -176,10 +175,11 @@ export function createPaymentBridgeConfig({
|
|
|
176
175
|
);
|
|
177
176
|
}
|
|
178
177
|
|
|
178
|
+
const preferredChainData = getChainById(preferredChain);
|
|
179
179
|
const tokenConfig = getKnownToken(preferredChain, preferredTokenAddress);
|
|
180
180
|
if (!tokenConfig) {
|
|
181
181
|
throw new Error(
|
|
182
|
-
`Unknown token ${preferredTokenAddress} for chain ${
|
|
182
|
+
`Unknown token ${preferredTokenAddress} for chain ${preferredChainData.name} (${preferredChain})`
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -235,114 +235,78 @@ export function createPaymentBridgeConfig({
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
|
-
*
|
|
238
|
+
* Converts a RozoAI payment API response to a fully hydrated RozoPay order.
|
|
239
239
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
240
|
+
* This utility transforms the low-level {@link PaymentResponse} object returned by the RozoAI Intent Pay API
|
|
241
|
+
* into a {@link RozoPayHydratedOrderWithOrg}, containing all values needed for UI display, order tracking,
|
|
242
|
+
* and multi-chain cross-payment logic. Fields are normalized and token metadata is resolved in order to
|
|
243
|
+
* standardize data from different chains and token types.
|
|
243
244
|
*
|
|
244
|
-
*
|
|
245
|
+
* Key steps performed:
|
|
245
246
|
*
|
|
246
|
-
* 1. **Token
|
|
247
|
-
*
|
|
248
|
-
*
|
|
247
|
+
* 1. **Token Metadata Lookup**: Uses {@link getKnownToken} to identify the correct token
|
|
248
|
+
* for the payment, including decimals, symbol, logo, and chain details.
|
|
249
|
+
* Special handling is applied for Stellar and Solana tokens based on how they're encoded in the backend.
|
|
249
250
|
*
|
|
250
|
-
* 2. **Order
|
|
251
|
-
*
|
|
252
|
-
* - Sets up intent, handoff, and contract addresses
|
|
253
|
-
* - Configures bridge token options and destination amounts
|
|
251
|
+
* 2. **Order Hydration**: Generates a unique (random BigInt) internal order ID for frontend usage, sets the
|
|
252
|
+
* payment mode as HYDRATED, and resolves all destination call and amount fields from the payment response.
|
|
254
253
|
*
|
|
255
|
-
* 3. **Status Initialization**:
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* - Intent status: UNPAID (payment not initiated)
|
|
254
|
+
* 3. **Status Initialization**: Initializes the payment, source, and destination status fields
|
|
255
|
+
* with their correct values based on the payment's progress in the state machine. The returned object is
|
|
256
|
+
* ready for status tracking and user notification.
|
|
259
257
|
*
|
|
260
|
-
* 4. **Metadata
|
|
261
|
-
*
|
|
262
|
-
* - Preserves external ID and organization information
|
|
258
|
+
* 4. **Metadata Consolidation**: Merges core order metadata, user metadata (if provided by the payer),
|
|
259
|
+
* and any external references such as org info. Ensures all details needed for order display and analytics are available.
|
|
263
260
|
*
|
|
264
|
-
* @param order -
|
|
265
|
-
* @param
|
|
266
|
-
* @param order.destination - Destination configuration (chain, token, amount, address)
|
|
267
|
-
* @param order.source - Source transaction info (if payment has been initiated)
|
|
268
|
-
* @param order.orgId - Organization ID for the payment
|
|
269
|
-
* @param order.externalId - External reference ID (if provided by merchant)
|
|
261
|
+
* @param order - Low-level API payment response (from RozoAI Intent Pay backend)
|
|
262
|
+
* @param feeType - Optional: Fee deduction mode (ExactIn/ExactOut); determines which side's amount is shown as source. Defaults to ExactIn.
|
|
270
263
|
*
|
|
271
|
-
* @returns
|
|
272
|
-
*
|
|
273
|
-
* @returns mode - Order mode (HYDRATED)
|
|
274
|
-
* @returns sourceStatus - Source transaction status
|
|
275
|
-
* @returns destStatus - Destination transaction status
|
|
276
|
-
* @returns intentStatus - Overall payment intent status
|
|
277
|
-
* @returns metadata - Merged metadata from all sources
|
|
278
|
-
* @returns org - Organization information
|
|
264
|
+
* @returns {RozoPayHydratedOrderWithOrg} A normalized, display-ready order representation containing all tracking, status,
|
|
265
|
+
* token, org, and routing information for frontend use.
|
|
279
266
|
*
|
|
280
267
|
* @example
|
|
281
268
|
* ```typescript
|
|
282
|
-
* const paymentResponse = await
|
|
283
|
-
*
|
|
284
|
-
* const hydratedOrder = formatPaymentResponseDataToHydratedOrder(
|
|
285
|
-
* paymentResponse.data,
|
|
286
|
-
* 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'
|
|
287
|
-
* );
|
|
288
|
-
*
|
|
269
|
+
* const paymentResponse = await getPayment(paymentId);
|
|
270
|
+
* const hydratedOrder = formatPaymentResponseToHydratedOrder(paymentResponse.data);
|
|
289
271
|
* console.log(hydratedOrder.sourceStatus); // 'WAITING_PAYMENT'
|
|
290
272
|
* console.log(hydratedOrder.destFinalCallTokenAmount.token.symbol); // 'USDC'
|
|
291
273
|
* console.log(hydratedOrder.usdValue); // 10.00
|
|
292
274
|
* ```
|
|
293
275
|
*
|
|
294
|
-
* @
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
276
|
+
* @remarks
|
|
277
|
+
* - The returned `id` (BigInt) is generated randomly and is client-side only; always use
|
|
278
|
+
* `order.orderId` or the API reference for backend/server reconciliation.
|
|
279
|
+
* - The expiration timestamp and org info are carried over if present on the API response.
|
|
280
|
+
* - Decimals, token symbol, and display metadata for the amount and destination chain
|
|
281
|
+
* are resolved so the result is immediately usable for UI.
|
|
298
282
|
*
|
|
299
|
-
* @see
|
|
283
|
+
* @see PaymentResponse
|
|
300
284
|
* @see RozoPayHydratedOrderWithOrg
|
|
301
285
|
* @see getKnownToken
|
|
302
286
|
*/
|
|
303
|
-
export function
|
|
304
|
-
order:
|
|
287
|
+
export function formatPaymentResponseToHydratedOrder(
|
|
288
|
+
order: PaymentResponse
|
|
305
289
|
): RozoPayHydratedOrderWithOrg {
|
|
306
|
-
|
|
290
|
+
// Source amount is in the same units as the destination amount without fee
|
|
291
|
+
const sourceAmountUnits = order.source?.amount ?? "0";
|
|
292
|
+
|
|
293
|
+
// Destination address is where the payment will be received
|
|
294
|
+
const destAddress = order.source?.receiverAddress;
|
|
307
295
|
|
|
308
|
-
|
|
296
|
+
// Determine the chain from metadata or default to the source chain
|
|
297
|
+
const requiredChain = order.source?.chainId || baseUSDC.chainId;
|
|
309
298
|
|
|
310
299
|
const token = getKnownToken(
|
|
311
300
|
Number(requiredChain),
|
|
312
301
|
Number(requiredChain) === rozoStellarUSDC.chainId
|
|
313
302
|
? rozoStellarUSDC.token
|
|
314
|
-
: order.
|
|
303
|
+
: order.source?.tokenAddress || ""
|
|
315
304
|
);
|
|
316
305
|
|
|
317
306
|
return {
|
|
318
307
|
id: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
319
308
|
mode: RozoPayOrderMode.HYDRATED,
|
|
320
|
-
intentAddr: destAddress,
|
|
321
|
-
// @TODO: use correct destination token
|
|
322
|
-
// bridgeTokenOutOptions: [
|
|
323
|
-
// {
|
|
324
|
-
// token: {
|
|
325
|
-
// chainId: baseUSDC.chainId,
|
|
326
|
-
// token: baseUSDC.token,
|
|
327
|
-
// symbol: baseUSDC.symbol,
|
|
328
|
-
// usd: 1,
|
|
329
|
-
// priceFromUsd: 1,
|
|
330
|
-
// decimals: baseUSDC.decimals,
|
|
331
|
-
// displayDecimals: 2,
|
|
332
|
-
// logoSourceURI: baseUSDC.logoSourceURI,
|
|
333
|
-
// logoURI: baseUSDC.logoURI,
|
|
334
|
-
// maxAcceptUsd: 100000,
|
|
335
|
-
// maxSendUsd: 0,
|
|
336
|
-
// },
|
|
337
|
-
// amount: parseUnits(
|
|
338
|
-
// order.destination.amountUnits,
|
|
339
|
-
// baseUSDC.decimals
|
|
340
|
-
// ).toString() as `${bigint}`,
|
|
341
|
-
// usd: Number(order.destination.amountUnits),
|
|
342
|
-
// },
|
|
343
|
-
// ],
|
|
344
|
-
// selectedBridgeTokenOutAddr: null,
|
|
345
|
-
// selectedBridgeTokenOutAmount: null,
|
|
309
|
+
intentAddr: destAddress ?? "",
|
|
346
310
|
destFinalCallTokenAmount: {
|
|
347
311
|
token: {
|
|
348
312
|
chainId: token ? token.chainId : baseUSDC.chainId,
|
|
@@ -358,90 +322,44 @@ export function formatResponseToHydratedOrder(
|
|
|
358
322
|
maxSendUsd: 0,
|
|
359
323
|
},
|
|
360
324
|
amount: parseUnits(
|
|
361
|
-
|
|
325
|
+
sourceAmountUnits,
|
|
362
326
|
token ? token.decimals : baseUSDC.decimals
|
|
363
327
|
).toString() as `${bigint}`,
|
|
364
|
-
usd: Number(
|
|
328
|
+
usd: Number(sourceAmountUnits),
|
|
365
329
|
},
|
|
366
|
-
usdValue: Number(
|
|
330
|
+
usdValue: Number(sourceAmountUnits),
|
|
367
331
|
destFinalCall: {
|
|
368
|
-
to: destAddress,
|
|
332
|
+
to: destAddress ?? "",
|
|
369
333
|
value: BigInt("0"),
|
|
370
334
|
data: "0x",
|
|
371
335
|
},
|
|
372
|
-
refundAddr: (order.source?.
|
|
373
|
-
nonce: order.nonce
|
|
336
|
+
refundAddr: (order.source?.senderAddress as `0x${string}`) || null,
|
|
337
|
+
nonce: BigInt(order.nonce ?? 0),
|
|
374
338
|
sourceFulfillerAddr: null,
|
|
375
339
|
sourceTokenAmount: null,
|
|
376
340
|
sourceInitiateTxHash: null,
|
|
377
|
-
// sourceStartTxHash: null,
|
|
378
341
|
sourceStatus: RozoPayOrderStatusSource.WAITING_PAYMENT,
|
|
379
342
|
destStatus: RozoPayOrderStatusDest.PENDING,
|
|
380
343
|
intentStatus: RozoPayIntentStatus.UNPAID,
|
|
381
344
|
destFastFinishTxHash: null,
|
|
382
345
|
destClaimTxHash: null,
|
|
383
346
|
redirectUri: null,
|
|
384
|
-
createdAt: Math.floor(Date.
|
|
385
|
-
lastUpdatedAt: Math.floor(Date.
|
|
386
|
-
orgId: order.orgId
|
|
347
|
+
createdAt: Math.floor(new Date(order.createdAt).getTime() / 1000),
|
|
348
|
+
lastUpdatedAt: Math.floor(new Date(order.updatedAt).getTime() / 1000),
|
|
349
|
+
orgId: order.orgId ?? "",
|
|
387
350
|
metadata: {
|
|
388
351
|
...(order?.metadata ?? {}),
|
|
389
|
-
|
|
390
|
-
|
|
352
|
+
receivingAddress: order.source?.receiverAddress,
|
|
353
|
+
memo: order.source?.receiverMemo ?? null,
|
|
391
354
|
} as any,
|
|
392
|
-
externalId: order.externalId
|
|
355
|
+
externalId: order.externalId ?? null,
|
|
393
356
|
userMetadata: order.userMetadata as RozoPayUserMetadata | null,
|
|
394
|
-
expirationTs:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
new Date(String(order.expiresAt)).getTime() / 1000
|
|
398
|
-
).toString()
|
|
399
|
-
)
|
|
400
|
-
: BigInt(Math.floor(Date.now() / 1000 + 5 * 60).toString()),
|
|
357
|
+
expirationTs: BigInt(
|
|
358
|
+
Math.floor(new Date(order.expiresAt).getTime() / 1000).toString()
|
|
359
|
+
),
|
|
401
360
|
org: {
|
|
402
|
-
orgId: order.orgId
|
|
361
|
+
orgId: order.orgId ?? "",
|
|
403
362
|
name: "",
|
|
404
363
|
},
|
|
405
364
|
};
|
|
406
365
|
}
|
|
407
|
-
|
|
408
|
-
export function formatPaymentResponseToHydratedOrder(
|
|
409
|
-
order: PaymentResponse
|
|
410
|
-
): RozoPayHydratedOrderWithOrg {
|
|
411
|
-
// Source amount is in the same units as the destination amount without fee
|
|
412
|
-
const sourceAmountUnits = order.source?.amount ?? "0";
|
|
413
|
-
|
|
414
|
-
return formatResponseToHydratedOrder({
|
|
415
|
-
id: order.id,
|
|
416
|
-
expiresAt: new Date(order.expiresAt).toISOString(),
|
|
417
|
-
updatedAt: new Date(order.updatedAt).toISOString(),
|
|
418
|
-
createdAt: new Date(order.createdAt).toISOString(),
|
|
419
|
-
status: RozoPayOrderMode.HYDRATED,
|
|
420
|
-
display: order.display,
|
|
421
|
-
metadata: {
|
|
422
|
-
...order.metadata,
|
|
423
|
-
receivingAddress: order.source?.receiverAddress,
|
|
424
|
-
memo: order.source?.receiverMemo ?? null,
|
|
425
|
-
} as any,
|
|
426
|
-
destination: {
|
|
427
|
-
destinationAddress: order.destination?.receiverAddress ?? "",
|
|
428
|
-
chainId: String(order.destination?.chainId ?? ""),
|
|
429
|
-
amountUnits: sourceAmountUnits,
|
|
430
|
-
tokenSymbol: order.destination?.tokenSymbol ?? "",
|
|
431
|
-
tokenAddress: order.destination?.tokenAddress ?? "",
|
|
432
|
-
txHash: order.destination?.txHash ?? null,
|
|
433
|
-
},
|
|
434
|
-
source: {
|
|
435
|
-
sourceAddress: order.source?.senderAddress ?? undefined,
|
|
436
|
-
chainId: String(order.source?.chainId ?? ""),
|
|
437
|
-
amountUnits: sourceAmountUnits,
|
|
438
|
-
tokenSymbol: order.source?.tokenSymbol ?? "",
|
|
439
|
-
tokenAddress: order.source?.tokenAddress ?? "",
|
|
440
|
-
},
|
|
441
|
-
url: order.url,
|
|
442
|
-
externalId: order.externalId,
|
|
443
|
-
userMetadata: order.userMetadata,
|
|
444
|
-
nonce: order.nonce,
|
|
445
|
-
orgId: order.orgId,
|
|
446
|
-
});
|
|
447
|
-
}
|
package/src/format.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getChainName } from "./chain";
|
|
2
|
+
import { getKnownToken } from "./token";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Contract an Ethereum address to a shorter string.
|
|
3
6
|
*
|
|
@@ -33,3 +36,30 @@ export function generateEVMDeepLink({
|
|
|
33
36
|
}): string {
|
|
34
37
|
return `ethereum:${tokenAddress}@${chainId}/transfer?address=${recipientAddress}&uint256=${amountUnits}`;
|
|
35
38
|
}
|
|
39
|
+
|
|
40
|
+
export function generateIntentTitle({
|
|
41
|
+
toChainId,
|
|
42
|
+
toTokenAddress,
|
|
43
|
+
preferredChainId,
|
|
44
|
+
preferredTokenAddress,
|
|
45
|
+
}: {
|
|
46
|
+
toChainId: number;
|
|
47
|
+
toTokenAddress: string;
|
|
48
|
+
preferredChainId: number;
|
|
49
|
+
preferredTokenAddress: string;
|
|
50
|
+
}): string {
|
|
51
|
+
const toChainName = getChainName(toChainId);
|
|
52
|
+
const preferredChainName = getChainName(preferredChainId);
|
|
53
|
+
const toToken = getKnownToken(toChainId, toTokenAddress);
|
|
54
|
+
const preferredToken = getKnownToken(preferredChainId, preferredTokenAddress);
|
|
55
|
+
|
|
56
|
+
if (!toToken || !preferredToken) {
|
|
57
|
+
return "Pay";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (toToken.chainId === preferredToken.chainId) {
|
|
61
|
+
return `Pay with ${preferredToken.symbol} (${preferredChainName})`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return `Pay with ${preferredToken.symbol} (${preferredChainName}) to ${toToken.symbol} (${toChainName})`;
|
|
65
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export * from "./api/fee";
|
|
2
|
-
export * from "./api/new-payment";
|
|
3
2
|
export * from "./api/payment";
|
|
4
3
|
export * from "./assert";
|
|
5
|
-
export * from "./bridge";
|
|
4
|
+
export * from "./bridge-utils";
|
|
6
5
|
export * from "./chain";
|
|
7
|
-
export * from "./daimoPay";
|
|
8
6
|
export * from "./debug";
|
|
9
7
|
export * from "./format";
|
|
10
8
|
export * from "./primitiveTypes";
|
|
11
9
|
export * from "./retryBackoff";
|
|
10
|
+
export * from "./rozoPay";
|
|
12
11
|
export * from "./token";
|
|
13
12
|
export * from "./try";
|
|
14
13
|
export * from "./validation";
|
package/src/token.ts
CHANGED
|
@@ -893,10 +893,13 @@ export const supportedTokens: Map<number, Token[]> = new Map([
|
|
|
893
893
|
[arbitrum.chainId, [arbitrumUSDC, arbitrumUSDT]],
|
|
894
894
|
[avalanche.chainId, [avalancheUSDC, avalancheUSDT]],
|
|
895
895
|
[base.chainId, [baseUSDC]],
|
|
896
|
+
[bsc.chainId, [bscUSDC, bscUSDT]],
|
|
896
897
|
[ethereum.chainId, [ethereumUSDC, ethereumUSDT]],
|
|
897
898
|
[gnosis.chainId, [gnosisUSDC, gnosisUSDT]],
|
|
898
899
|
[optimism.chainId, [optimismUSDC, optimismUSDT]],
|
|
899
900
|
[polygon.chainId, [polygonUSDC, polygonUSDT]],
|
|
901
|
+
[worldchain.chainId, [worldchainUSDC]],
|
|
902
|
+
|
|
900
903
|
[rozoSolana.chainId, [rozoSolanaUSDC, rozoSolanaUSDT]],
|
|
901
904
|
[rozoStellar.chainId, [rozoStellarUSDC]],
|
|
902
905
|
]);
|
package/test/bridge.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import test from "tape";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createPaymentBridgeConfig,
|
|
4
|
+
PaymentBridgeConfig,
|
|
5
|
+
} from "../src/bridge-utils";
|
|
3
6
|
import { base, polygon, rozoSolana, rozoStellar } from "../src/chain";
|
|
4
7
|
import {
|
|
5
8
|
baseUSDC,
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { ApiResponse } from "./base";
|
|
2
|
-
/**
|
|
3
|
-
* FeeType, Fee calculation type:
|
|
4
|
-
* - exactIn (default): Fee deducted from input, recipient receives amount - fee
|
|
5
|
-
* - exactOut: Fee added to input, recipient receives exact amount
|
|
6
|
-
*/
|
|
7
|
-
export declare enum FeeType {
|
|
8
|
-
ExactIn = "exactIn",
|
|
9
|
-
ExactOut = "exactOut"
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* PaymentStatus, Payment status
|
|
13
|
-
*/
|
|
14
|
-
export declare enum PaymentStatus {
|
|
15
|
-
PaymentBounced = "payment_bounced",
|
|
16
|
-
PaymentCompleted = "payment_completed",
|
|
17
|
-
PaymentExpired = "payment_expired",
|
|
18
|
-
PaymentPayinCompleted = "payment_payin_completed",
|
|
19
|
-
PaymentPayoutCompleted = "payment_payout_completed",
|
|
20
|
-
PaymentRefunded = "payment_refunded",
|
|
21
|
-
PaymentStarted = "payment_started",
|
|
22
|
-
PaymentUnpaid = "payment_unpaid"
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* PaymentErrorCode, Error code (only present when status is payment_bounced)
|
|
26
|
-
*/
|
|
27
|
-
export declare enum PaymentErrorCode {
|
|
28
|
-
AmountTooHigh = "amountTooHigh",
|
|
29
|
-
AmountTooLow = "amountTooLow",
|
|
30
|
-
ChainUnavailable = "chainUnavailable",
|
|
31
|
-
InsufficientLiquidity = "insufficientLiquidity",
|
|
32
|
-
InvalidRecipient = "invalidRecipient",
|
|
33
|
-
MissingTrustline = "missingTrustline",
|
|
34
|
-
NetworkError = "networkError",
|
|
35
|
-
ProviderError = "providerError",
|
|
36
|
-
ServiceMaintenance = "serviceMaintenance"
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* DestinationRequest
|
|
40
|
-
*/
|
|
41
|
-
export interface DestinationRequest {
|
|
42
|
-
/**
|
|
43
|
-
* Receive amount (required for type=exactOut).
|
|
44
|
-
* For exactIn, this field is omitted in request and calculated in response.
|
|
45
|
-
*/
|
|
46
|
-
amount?: string;
|
|
47
|
-
chainId: number;
|
|
48
|
-
/**
|
|
49
|
-
* Final recipient's wallet address
|
|
50
|
-
*/
|
|
51
|
-
receiverAddress: string;
|
|
52
|
-
/**
|
|
53
|
-
* Memo for Stellar/Solana destinations
|
|
54
|
-
*/
|
|
55
|
-
receiverMemo?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Override default token address
|
|
58
|
-
*/
|
|
59
|
-
tokenAddress?: string;
|
|
60
|
-
tokenSymbol: string;
|
|
61
|
-
[property: string]: any;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* DisplayInfo
|
|
65
|
-
*/
|
|
66
|
-
export interface DisplayInfo {
|
|
67
|
-
/**
|
|
68
|
-
* Display currency
|
|
69
|
-
*/
|
|
70
|
-
currency: string;
|
|
71
|
-
/**
|
|
72
|
-
* Detailed description
|
|
73
|
-
*/
|
|
74
|
-
description?: string;
|
|
75
|
-
/**
|
|
76
|
-
* Short title
|
|
77
|
-
*/
|
|
78
|
-
title: string;
|
|
79
|
-
[property: string]: any;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* SourceRequest
|
|
83
|
-
*/
|
|
84
|
-
export interface SourceRequest {
|
|
85
|
-
/**
|
|
86
|
-
* Pay-in amount (required for type=exactIn).
|
|
87
|
-
* For exactOut, this field is omitted in request and calculated in response.
|
|
88
|
-
*/
|
|
89
|
-
amount?: string;
|
|
90
|
-
chainId: number;
|
|
91
|
-
/**
|
|
92
|
-
* Override default token address
|
|
93
|
-
*/
|
|
94
|
-
tokenAddress?: string;
|
|
95
|
-
tokenSymbol: string;
|
|
96
|
-
[property: string]: any;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* PaymentRequest
|
|
100
|
-
*/
|
|
101
|
-
export interface CreatePaymentRequest {
|
|
102
|
-
/**
|
|
103
|
-
* Your application ID
|
|
104
|
-
*/
|
|
105
|
-
appId: string;
|
|
106
|
-
destination: DestinationRequest;
|
|
107
|
-
display: DisplayInfo;
|
|
108
|
-
/**
|
|
109
|
-
* Custom metadata (max 4 KB recommended)
|
|
110
|
-
*/
|
|
111
|
-
metadata?: {
|
|
112
|
-
[key: string]: any;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Your order reference ID (for idempotency)
|
|
116
|
-
*/
|
|
117
|
-
orderId?: string;
|
|
118
|
-
source: SourceRequest;
|
|
119
|
-
type?: FeeType;
|
|
120
|
-
/**
|
|
121
|
-
* Secret for HMAC-SHA256 signature verification.
|
|
122
|
-
* If not provided, a unique secret is auto-generated.
|
|
123
|
-
* The secret is returned in the response for you to store and use for verification.
|
|
124
|
-
*/
|
|
125
|
-
webhookSecret?: string;
|
|
126
|
-
/**
|
|
127
|
-
* URL to receive payment status updates
|
|
128
|
-
*/
|
|
129
|
-
webhookUrl?: string;
|
|
130
|
-
[property: string]: any;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* DestinationResponse
|
|
134
|
-
*/
|
|
135
|
-
export interface DestinationResponse {
|
|
136
|
-
/**
|
|
137
|
-
* Amount to be sent to recipient
|
|
138
|
-
*/
|
|
139
|
-
amount?: string;
|
|
140
|
-
chainId?: number;
|
|
141
|
-
/**
|
|
142
|
-
* Withdrawal confirmation time
|
|
143
|
-
*/
|
|
144
|
-
confirmedAt?: Date;
|
|
145
|
-
/**
|
|
146
|
-
* Final recipient's wallet
|
|
147
|
-
*/
|
|
148
|
-
receiverAddress?: string;
|
|
149
|
-
/**
|
|
150
|
-
* Memo for Stellar/Solana
|
|
151
|
-
*/
|
|
152
|
-
receiverMemo?: string;
|
|
153
|
-
/**
|
|
154
|
-
* Token contract address
|
|
155
|
-
*/
|
|
156
|
-
tokenAddress?: string;
|
|
157
|
-
tokenSymbol?: string;
|
|
158
|
-
/**
|
|
159
|
-
* Withdrawal transaction hash
|
|
160
|
-
*/
|
|
161
|
-
txHash?: string;
|
|
162
|
-
[property: string]: any;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* SourceResponse
|
|
166
|
-
*/
|
|
167
|
-
export interface SourceResponse {
|
|
168
|
-
/**
|
|
169
|
-
* Amount payer must send
|
|
170
|
-
*/
|
|
171
|
-
amount?: string;
|
|
172
|
-
/**
|
|
173
|
-
* Actual amount received
|
|
174
|
-
*/
|
|
175
|
-
amountReceived?: string;
|
|
176
|
-
chainId?: number;
|
|
177
|
-
/**
|
|
178
|
-
* Deposit confirmation time
|
|
179
|
-
*/
|
|
180
|
-
confirmedAt?: Date;
|
|
181
|
-
/**
|
|
182
|
-
* Fee amount
|
|
183
|
-
*/
|
|
184
|
-
fee?: string;
|
|
185
|
-
/**
|
|
186
|
-
* Deposit address (where payer sends funds)
|
|
187
|
-
*/
|
|
188
|
-
receiverAddress?: string;
|
|
189
|
-
/**
|
|
190
|
-
* Memo for Stellar/Solana deposits
|
|
191
|
-
*/
|
|
192
|
-
receiverMemo?: string;
|
|
193
|
-
/**
|
|
194
|
-
* Payer's wallet address (populated after deposit)
|
|
195
|
-
*/
|
|
196
|
-
senderAddress?: string;
|
|
197
|
-
/**
|
|
198
|
-
* Token contract address
|
|
199
|
-
*/
|
|
200
|
-
tokenAddress?: string;
|
|
201
|
-
tokenSymbol?: string;
|
|
202
|
-
/**
|
|
203
|
-
* Deposit transaction hash
|
|
204
|
-
*/
|
|
205
|
-
txHash?: string;
|
|
206
|
-
[property: string]: any;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* PaymentResponse
|
|
210
|
-
*/
|
|
211
|
-
export interface PaymentResponse {
|
|
212
|
-
/**
|
|
213
|
-
* Your application ID
|
|
214
|
-
*/
|
|
215
|
-
appId: string;
|
|
216
|
-
/**
|
|
217
|
-
* ISO 8601 timestamp
|
|
218
|
-
*/
|
|
219
|
-
createdAt: Date;
|
|
220
|
-
destination: DestinationResponse;
|
|
221
|
-
display: DisplayInfo;
|
|
222
|
-
errorCode: PaymentErrorCode | null;
|
|
223
|
-
/**
|
|
224
|
-
* ISO 8601 timestamp (when payment expires)
|
|
225
|
-
*/
|
|
226
|
-
expiresAt: Date;
|
|
227
|
-
/**
|
|
228
|
-
* Payment ID
|
|
229
|
-
*/
|
|
230
|
-
id: string;
|
|
231
|
-
metadata: {
|
|
232
|
-
[key: string]: any;
|
|
233
|
-
} | null;
|
|
234
|
-
/**
|
|
235
|
-
* Your order reference ID
|
|
236
|
-
*/
|
|
237
|
-
orderId: string | null;
|
|
238
|
-
source: SourceResponse;
|
|
239
|
-
status: PaymentStatus;
|
|
240
|
-
type: FeeType;
|
|
241
|
-
/**
|
|
242
|
-
* ISO 8601 timestamp
|
|
243
|
-
*/
|
|
244
|
-
updatedAt: Date;
|
|
245
|
-
/**
|
|
246
|
-
* Secret for webhook signature verification.
|
|
247
|
-
* Only present when webhookUrl was provided in the request.
|
|
248
|
-
* Store this securely to verify incoming webhook signatures.
|
|
249
|
-
*/
|
|
250
|
-
webhookSecret: string | null;
|
|
251
|
-
[property: string]: any;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Parameters for creating a new payment using the new backend interface
|
|
255
|
-
*/
|
|
256
|
-
export interface CreateNewPaymentParams {
|
|
257
|
-
/** App ID for authentication */
|
|
258
|
-
appId: string;
|
|
259
|
-
/** Destination chain ID (e.g., 8453 for Base, 900 for Solana, 1500 for Stellar) */
|
|
260
|
-
toChain: number;
|
|
261
|
-
/** Destination token address */
|
|
262
|
-
toToken: string;
|
|
263
|
-
/** Destination address - Can be EVM, Solana, or Stellar address */
|
|
264
|
-
toAddress: string;
|
|
265
|
-
/** Chain ID where user will pay from (e.g., 137 for Polygon, 8453 for Base) */
|
|
266
|
-
preferredChain: number;
|
|
267
|
-
/** Token address user will pay with */
|
|
268
|
-
preferredTokenAddress: string;
|
|
269
|
-
/** Amount in human-readable units (e.g., "1" for 1 USDC, "0.5" for half a USDC) */
|
|
270
|
-
toUnits?: string;
|
|
271
|
-
/** Additional metadata to include */
|
|
272
|
-
metadata?: Record<string, unknown>;
|
|
273
|
-
/** Display title for the payment */
|
|
274
|
-
title?: string;
|
|
275
|
-
/** Display description for the payment */
|
|
276
|
-
description?: string;
|
|
277
|
-
/** Order reference ID (for idempotency) */
|
|
278
|
-
orderId?: string;
|
|
279
|
-
/** Fee calculation type (exactIn or exactOut) */
|
|
280
|
-
type?: FeeType;
|
|
281
|
-
/** Webhook URL to receive payment status updates */
|
|
282
|
-
webhookUrl?: string;
|
|
283
|
-
/** Secret for HMAC-SHA256 signature verification */
|
|
284
|
-
webhookSecret?: string;
|
|
285
|
-
/** Memo for Stellar/Solana destinations */
|
|
286
|
-
receiverMemo?: string;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Creates a payment using the new backend interface
|
|
290
|
-
*
|
|
291
|
-
* This function creates a payment using the new backend API structure with
|
|
292
|
-
* separate source and destination objects, enum-based chain IDs and token symbols.
|
|
293
|
-
*
|
|
294
|
-
* @param params - Payment creation parameters
|
|
295
|
-
* @returns Promise resolving to the payment response data
|
|
296
|
-
* @throws Error if payment creation fails or required parameters are missing
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```typescript
|
|
300
|
-
* // Simple same-chain payment
|
|
301
|
-
* const payment = await createNewPayment({
|
|
302
|
-
* toChain: 8453, // Base
|
|
303
|
-
* toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
304
|
-
* toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
305
|
-
* preferredChain: 8453, // User pays from Base
|
|
306
|
-
* preferredTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
307
|
-
* toUnits: "1", // 1 USDC
|
|
308
|
-
* appId: "my-app-id",
|
|
309
|
-
* title: "Payment",
|
|
310
|
-
* });
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
|
-
export declare function createNewPayment(params: CreateNewPaymentParams): Promise<PaymentResponse>;
|
|
314
|
-
/**
|
|
315
|
-
* Gets payment details by ID using the new backend API
|
|
316
|
-
* @param paymentId - Payment ID
|
|
317
|
-
* @returns Promise with payment response
|
|
318
|
-
*/
|
|
319
|
-
export declare const getNewPayment: (paymentId: string) => Promise<ApiResponse<PaymentResponse>>;
|