@rozoai/intent-common 0.0.29 → 0.0.31-beta.1
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/fee.d.ts +36 -0
- package/dist/api/fee.js +43 -0
- package/dist/api/fee.js.map +1 -0
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +11 -2
- package/dist/bridge.js.map +1 -1
- package/dist/daimoPay.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/supportedChains.d.ts +28 -0
- package/dist/supportedChains.js +51 -0
- package/dist/supportedChains.js.map +1 -0
- package/package.json +1 -1
- package/src/api/README.md +324 -45
- package/src/api/fee.ts +80 -0
- package/src/bridge.ts +12 -2
- package/src/index.ts +1 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ApiResponse } from "./base";
|
|
2
|
+
/**
|
|
3
|
+
* Fee response data type (success case)
|
|
4
|
+
*/
|
|
5
|
+
export interface FeeResponseData {
|
|
6
|
+
appId: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
fee: number;
|
|
10
|
+
feePercentage: string;
|
|
11
|
+
minimumFee: string;
|
|
12
|
+
amount_out: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Fee error response data type
|
|
16
|
+
*/
|
|
17
|
+
export interface FeeErrorData {
|
|
18
|
+
error: string;
|
|
19
|
+
message: string;
|
|
20
|
+
received: number;
|
|
21
|
+
maxAllowed: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Fee request parameters
|
|
25
|
+
*/
|
|
26
|
+
export interface GetFeeParams {
|
|
27
|
+
amount: number;
|
|
28
|
+
appId?: string;
|
|
29
|
+
currency?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets fee calculation for a payment amount
|
|
33
|
+
* @param params - Fee calculation parameters (amount is required)
|
|
34
|
+
* @returns Promise with fee response or error
|
|
35
|
+
*/
|
|
36
|
+
export declare const getFee: (params: GetFeeParams) => Promise<ApiResponse<FeeResponseData>>;
|
package/dist/api/fee.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFee = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Gets fee calculation for a payment amount
|
|
6
|
+
* @param params - Fee calculation parameters (amount is required)
|
|
7
|
+
* @returns Promise with fee response or error
|
|
8
|
+
*/
|
|
9
|
+
const getFee = async (params) => {
|
|
10
|
+
const { amount, appId = "rozodemo", currency = "USDC" } = params;
|
|
11
|
+
try {
|
|
12
|
+
const queryParams = new URLSearchParams({
|
|
13
|
+
amount: amount.toString(),
|
|
14
|
+
appId,
|
|
15
|
+
currency,
|
|
16
|
+
});
|
|
17
|
+
const response = await fetch(`https://intentapi.rozo.ai/getFee?${queryParams.toString()}`);
|
|
18
|
+
const data = (await response.json());
|
|
19
|
+
// Check if response contains an error
|
|
20
|
+
if (!response.ok || "error" in data) {
|
|
21
|
+
const errorData = data;
|
|
22
|
+
return {
|
|
23
|
+
data: null,
|
|
24
|
+
error: new Error(errorData.message || errorData.error),
|
|
25
|
+
status: response.status,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
data: data,
|
|
30
|
+
error: null,
|
|
31
|
+
status: response.status,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
data: null,
|
|
37
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
38
|
+
status: null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.getFee = getFee;
|
|
43
|
+
//# sourceMappingURL=fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.js","sourceRoot":"","sources":["../../src/api/fee.ts"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
CHANGED
|
@@ -30,11 +30,11 @@ export interface DestinationConfig {
|
|
|
30
30
|
* the complexity of multi-chain payments by:
|
|
31
31
|
*
|
|
32
32
|
* 1. **Preferred Payment Method**: Identifies which chain/token the user will pay from
|
|
33
|
-
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, and BSC USDT
|
|
33
|
+
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, Worldchain USDC, and BSC USDT
|
|
34
34
|
* - Sets appropriate chain ID and token address for the source transaction
|
|
35
35
|
*
|
|
36
36
|
* 2. **Destination Configuration**: Determines where funds will be received
|
|
37
|
-
* - Supports Base, Solana, and
|
|
37
|
+
* - Supports Base, Solana, Stellar, and Worldchain as destination chains
|
|
38
38
|
* - Handles special address formats for Solana and Stellar addresses
|
|
39
39
|
* - Defaults to Base USDC when no special destination is specified
|
|
40
40
|
*
|
package/dist/bridge.js
CHANGED
|
@@ -12,11 +12,11 @@ const _1 = require(".");
|
|
|
12
12
|
* the complexity of multi-chain payments by:
|
|
13
13
|
*
|
|
14
14
|
* 1. **Preferred Payment Method**: Identifies which chain/token the user will pay from
|
|
15
|
-
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, and BSC USDT
|
|
15
|
+
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, Worldchain USDC, and BSC USDT
|
|
16
16
|
* - Sets appropriate chain ID and token address for the source transaction
|
|
17
17
|
*
|
|
18
18
|
* 2. **Destination Configuration**: Determines where funds will be received
|
|
19
|
-
* - Supports Base, Solana, and
|
|
19
|
+
* - Supports Base, Solana, Stellar, and Worldchain as destination chains
|
|
20
20
|
* - Handles special address formats for Solana and Stellar addresses
|
|
21
21
|
* - Defaults to Base USDC when no special destination is specified
|
|
22
22
|
*
|
|
@@ -123,6 +123,15 @@ function createPaymentBridgeConfig({ toChain = _1.baseUSDC.chainId, toToken = _1
|
|
|
123
123
|
preferredTokenAddress: `USDC:${_1.rozoStellarUSDC.token}`,
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
+
// Pay In USDC Worldchain
|
|
127
|
+
else if (payInTokenAddress === _1.worldchainUSDC.token) {
|
|
128
|
+
log?.(`[Payment Bridge] Pay In USDC Worldchain`);
|
|
129
|
+
preferred = {
|
|
130
|
+
preferredChain: String(_1.worldchainUSDC.chainId),
|
|
131
|
+
preferredToken: "USDC",
|
|
132
|
+
preferredTokenAddress: _1.worldchainUSDC.token,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
126
135
|
// Pay In USDT BSC
|
|
127
136
|
else if (payInTokenAddress === _1.bscUSDT.token) {
|
|
128
137
|
log?.(`[Payment Bridge] Pay In USDT BSC`);
|
package/dist/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":";;AAkHA,8DAgHC;AAoED,sEAoGC;AA1YD,+BAAkC;AAClC,wBAgBW;AA4BX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,SAAgB,yBAAyB,CAAC,EACxC,OAAO,GAAG,WAAQ,CAAC,OAAO,EAC1B,OAAO,GAAG,WAAQ,CAAC,KAAK,EACxB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,iBAAiB,EACjB,GAAG,GACiB;IAIpB,+CAA+C;IAC/C,IAAI,SAAS,GAA2B;QACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC;QAC/B,cAAc,EAAE,MAAM;KACvB,CAAC;IAEF,IAAI,WAAW,GAAsB;QACnC,kBAAkB,EAAE,SAAS;QAC7B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,MAAM;QACnB,YAAY,EAAE,OAAO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B,IAAI,EAAE,UAAU;SACjB;KACF,CAAC;AACJ,CAAC"}
|
package/dist/daimoPay.d.ts
CHANGED
|
@@ -44,11 +44,11 @@ export declare const zBridgeTokenOutOptions: z.ZodArray<z.ZodObject<{
|
|
|
44
44
|
token: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
45
45
|
amount: z.ZodEffects<z.ZodEffects<z.ZodString, `${bigint}`, string>, bigint, string>;
|
|
46
46
|
}, "strip", z.ZodTypeAny, {
|
|
47
|
-
token: `0x${string}`;
|
|
48
47
|
amount: bigint;
|
|
48
|
+
token: `0x${string}`;
|
|
49
49
|
}, {
|
|
50
|
-
token: string;
|
|
51
50
|
amount: string;
|
|
51
|
+
token: string;
|
|
52
52
|
}>, "many">;
|
|
53
53
|
export type BridgeTokenOutOptions = z.infer<typeof zBridgeTokenOutOptions>;
|
|
54
54
|
export declare const zRozoPayOrderMetadata: z.ZodObject<{
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api/fee"), exports);
|
|
17
18
|
__exportStar(require("./api/payment"), exports);
|
|
18
19
|
__exportStar(require("./assert"), exports);
|
|
19
20
|
__exportStar(require("./bridge"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Token } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the list of currently active chains and tokens in wallet payment options,
|
|
4
|
+
* with dynamic logic for including BSC/Worldchain based on appId or preferences.
|
|
5
|
+
*
|
|
6
|
+
* CURRENTLY SUPPORTED CHAINS/TOKENS:
|
|
7
|
+
* - Base (8453) - USDC
|
|
8
|
+
* - Polygon (137) - USDC
|
|
9
|
+
* - BSC (56) - USDT (only for MugglePay apps/pref)
|
|
10
|
+
* - Worldchain (480) - USDC (only for World apps/pref)
|
|
11
|
+
*
|
|
12
|
+
* @param {string} appId - The Rozo appId; can affect which chains are enabled.
|
|
13
|
+
* @param {number[]} [preferredChains=[]] - Preferred chain IDs (may enable Worldchain).
|
|
14
|
+
* @returns {{
|
|
15
|
+
* chains: Array<{ chainId: number; [k: string]: any }>;
|
|
16
|
+
* tokens: Token[];
|
|
17
|
+
* }} An object with arrays of supported chains and supported token addresses.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { chains, tokens } = getSupportedChains("MP_demo", [8453, 56]);
|
|
21
|
+
*/
|
|
22
|
+
export declare function getSupportedChains(appId: string, preferredChains?: number[]): {
|
|
23
|
+
chains: Array<{
|
|
24
|
+
chainId: number;
|
|
25
|
+
[k: string]: any;
|
|
26
|
+
}>;
|
|
27
|
+
tokens: Token[];
|
|
28
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSupportedChains = getSupportedChains;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const supportedChainsList = [_1.base, _1.polygon];
|
|
6
|
+
const supportedTokens = [_1.baseUSDC, _1.polygonUSDC];
|
|
7
|
+
/**
|
|
8
|
+
* Returns the list of currently active chains and tokens in wallet payment options,
|
|
9
|
+
* with dynamic logic for including BSC/Worldchain based on appId or preferences.
|
|
10
|
+
*
|
|
11
|
+
* CURRENTLY SUPPORTED CHAINS/TOKENS:
|
|
12
|
+
* - Base (8453) - USDC
|
|
13
|
+
* - Polygon (137) - USDC
|
|
14
|
+
* - BSC (56) - USDT (only for MugglePay apps/pref)
|
|
15
|
+
* - Worldchain (480) - USDC (only for World apps/pref)
|
|
16
|
+
*
|
|
17
|
+
* @param {string} appId - The Rozo appId; can affect which chains are enabled.
|
|
18
|
+
* @param {number[]} [preferredChains=[]] - Preferred chain IDs (may enable Worldchain).
|
|
19
|
+
* @returns {{
|
|
20
|
+
* chains: Array<{ chainId: number; [k: string]: any }>;
|
|
21
|
+
* tokens: Token[];
|
|
22
|
+
* }} An object with arrays of supported chains and supported token addresses.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const { chains, tokens } = getSupportedChains("MP_demo", [8453, 56]);
|
|
26
|
+
*/
|
|
27
|
+
function getSupportedChains(appId, preferredChains = []) {
|
|
28
|
+
const showBSCUSDT = appId.includes("MP");
|
|
29
|
+
const showWorldchainUSDC = typeof appId === "string" && appId.toLowerCase().includes("world")
|
|
30
|
+
? true
|
|
31
|
+
: Array.isArray(preferredChains) &&
|
|
32
|
+
preferredChains.includes(_1.worldchain.chainId);
|
|
33
|
+
// Build chains array - always includes base and polygon, conditionally includes BSC and Worldchain
|
|
34
|
+
const chains = [
|
|
35
|
+
...supportedChainsList,
|
|
36
|
+
...(showBSCUSDT && _1.bsc ? [_1.bsc] : []),
|
|
37
|
+
...(showWorldchainUSDC && _1.worldchain ? [_1.worldchain] : []),
|
|
38
|
+
].filter(Boolean);
|
|
39
|
+
// Build tokens array - always includes base and polygon, conditionally includes BSC and Worldchain
|
|
40
|
+
// Ensure we always have at least base and polygon tokens
|
|
41
|
+
const tokens = [
|
|
42
|
+
...supportedTokens,
|
|
43
|
+
...(showBSCUSDT && _1.bscUSDT ? [_1.bscUSDT] : []),
|
|
44
|
+
...(showWorldchainUSDC && _1.worldchainUSDC ? [_1.worldchainUSDC] : []),
|
|
45
|
+
].filter(Boolean);
|
|
46
|
+
return {
|
|
47
|
+
chains,
|
|
48
|
+
tokens,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=supportedChains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportedChains.js","sourceRoot":"","sources":["../src/supportedChains.ts"],"names":[],"mappings":";;AAmCA,gDAiCC;AApED,wBAUW;AAEX,MAAM,mBAAmB,GAAG,CAAC,OAAI,EAAE,UAAO,CAAC,CAAC;AAC5C,MAAM,eAAe,GAAG,CAAC,WAAQ,EAAE,cAAW,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,kBAAkB,CAChC,KAAa,EACb,kBAA4B,EAAE;IAK9B,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,kBAAkB,GACtB,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;QAChE,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;YAC9B,eAAe,CAAC,QAAQ,CAAC,aAAU,CAAC,OAAO,CAAC,CAAC;IAEnD,mGAAmG;IACnG,MAAM,MAAM,GAAG;QACb,GAAG,mBAAmB;QACtB,GAAG,CAAC,WAAW,IAAI,MAAG,CAAC,CAAC,CAAC,CAAC,MAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,GAAG,CAAC,kBAAkB,IAAI,aAAU,CAAC,CAAC,CAAC,CAAC,aAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,mGAAmG;IACnG,yDAAyD;IACzD,MAAM,MAAM,GAAY;QACtB,GAAG,eAAe;QAClB,GAAG,CAAC,WAAW,IAAI,UAAO,CAAC,CAAC,CAAC,CAAC,UAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,GAAG,CAAC,kBAAkB,IAAI,iBAAc,CAAC,CAAC,CAAC,CAAC,iBAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO;QACL,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/api/README.md
CHANGED
|
@@ -30,7 +30,7 @@ These defaults are automatically used by the API client, so you can start making
|
|
|
30
30
|
```bash
|
|
31
31
|
api/
|
|
32
32
|
├── base.ts # Core API client functionality
|
|
33
|
-
├──
|
|
33
|
+
├── fee.ts # Fee calculation endpoint
|
|
34
34
|
├── payment.ts # Payment-specific endpoints
|
|
35
35
|
└── README.md # Documentation
|
|
36
36
|
```
|
|
@@ -67,83 +67,313 @@ const response = await apiClient.get("/some-endpoint", {
|
|
|
67
67
|
|
|
68
68
|
## Using Payment API
|
|
69
69
|
|
|
70
|
-
The payment module provides typed functions for payment operations
|
|
70
|
+
The payment module provides typed functions for payment operations. The `createRozoPayment` function is the core method for creating cross-chain payments.
|
|
71
|
+
|
|
72
|
+
### Creating a Payment
|
|
73
|
+
|
|
74
|
+
The `createRozoPayment` function requires a `PaymentRequestData` object with the following structure:
|
|
71
75
|
|
|
72
76
|
```typescript
|
|
73
77
|
import {
|
|
74
78
|
createRozoPayment,
|
|
75
79
|
getRozoPayment,
|
|
76
|
-
|
|
80
|
+
createPaymentBridgeConfig,
|
|
81
|
+
mergedMetadata,
|
|
82
|
+
PaymentRequestData,
|
|
77
83
|
} from "@rozoai/intent-common";
|
|
78
84
|
|
|
79
|
-
//
|
|
85
|
+
// Basic payment creation
|
|
80
86
|
const handleSubmitPayment = async () => {
|
|
81
|
-
|
|
87
|
+
// First, create payment bridge configuration
|
|
88
|
+
// This determines the preferred payment method and destination
|
|
89
|
+
// payInTokenAddress can be: USDC Base, USDC Polygon, USDC Solana, USDC Stellar, or USDT BNB
|
|
90
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
91
|
+
toChain: 8453, // Base chain
|
|
92
|
+
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
93
|
+
toAddress: "0x1234567890123456789012345678901234567890",
|
|
94
|
+
toUnits: "1000000", // 1 USDC (6 decimals)
|
|
95
|
+
payInTokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Construct payment data
|
|
99
|
+
const paymentData: PaymentRequestData = {
|
|
82
100
|
appId: "your-app-id",
|
|
83
101
|
display: {
|
|
84
102
|
intent: "Pay for product",
|
|
85
|
-
paymentValue: "
|
|
103
|
+
paymentValue: "1.00", // Display value in USD
|
|
86
104
|
currency: "USD",
|
|
87
105
|
},
|
|
88
106
|
destination: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
destinationAddress: destination.destinationAddress,
|
|
108
|
+
chainId: destination.chainId,
|
|
109
|
+
amountUnits: destination.amountUnits,
|
|
110
|
+
tokenSymbol: destination.tokenSymbol,
|
|
111
|
+
tokenAddress: destination.tokenAddress,
|
|
93
112
|
},
|
|
94
|
-
|
|
113
|
+
// Spread preferred payment configuration
|
|
114
|
+
...preferred,
|
|
115
|
+
// Optional: external ID for tracking
|
|
116
|
+
externalId: "order-123",
|
|
117
|
+
// Optional: metadata
|
|
118
|
+
metadata: {
|
|
119
|
+
preferredChain: preferred.preferredChain,
|
|
120
|
+
preferredToken: preferred.preferredToken,
|
|
121
|
+
preferredTokenAddress: preferred.preferredTokenAddress,
|
|
122
|
+
// Merge additional metadata
|
|
123
|
+
...mergedMetadata({
|
|
124
|
+
customField: "value",
|
|
125
|
+
}),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
95
128
|
|
|
129
|
+
// Create the payment
|
|
96
130
|
const response = await createRozoPayment(paymentData);
|
|
97
131
|
|
|
98
132
|
if (response.data) {
|
|
99
133
|
console.log("Payment created:", response.data.id);
|
|
134
|
+
console.log("Payment status:", response.data.status);
|
|
135
|
+
console.log("Payment URL:", response.data.url);
|
|
100
136
|
} else if (response.error) {
|
|
101
137
|
console.error("Error creating payment:", response.error.message);
|
|
102
138
|
}
|
|
103
139
|
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Example: Pay Out to Stellar
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// Paying out to a Stellar address
|
|
146
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
147
|
+
toStellarAddress: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // REQUIRED: Stellar address
|
|
148
|
+
toAddress: "0x1234567890123456789012345678901234567890", // REQUIRED: any valid EVM address
|
|
149
|
+
// toChain and toToken are optional (default to USDC Base)
|
|
150
|
+
toUnits: "1000000", // 1 USDC
|
|
151
|
+
payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const paymentData: PaymentRequestData = {
|
|
155
|
+
appId: "your-app-id",
|
|
156
|
+
display: {
|
|
157
|
+
intent: "Pay to Stellar wallet",
|
|
158
|
+
paymentValue: "1.00",
|
|
159
|
+
currency: "USD",
|
|
160
|
+
},
|
|
161
|
+
...preferred,
|
|
162
|
+
destination,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const response = await createRozoPayment(paymentData);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Example: Pay Out to Solana
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Paying out to a Solana address
|
|
172
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
173
|
+
toSolanaAddress: "So11111111111111111111111111111111111111112", // REQUIRED: Solana address
|
|
174
|
+
toAddress: "0x1234567890123456789012345678901234567890", // REQUIRED: any valid EVM address
|
|
175
|
+
// toChain and toToken are optional (default to USDC Base)
|
|
176
|
+
toUnits: "1000000", // 1 USDC
|
|
177
|
+
payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const paymentData: PaymentRequestData = {
|
|
181
|
+
appId: "your-app-id",
|
|
182
|
+
display: {
|
|
183
|
+
intent: "Pay to Solana wallet",
|
|
184
|
+
paymentValue: "1.00",
|
|
185
|
+
currency: "USD",
|
|
186
|
+
},
|
|
187
|
+
...preferred,
|
|
188
|
+
destination,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const response = await createRozoPayment(paymentData);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Payment Request Data Structure
|
|
195
|
+
|
|
196
|
+
The `PaymentRequestData` interface includes:
|
|
197
|
+
|
|
198
|
+
- **`appId`** (required): Your application identifier
|
|
199
|
+
- **`display`** (required): Payment display information
|
|
200
|
+
- `intent`: Description of the payment
|
|
201
|
+
- `paymentValue`: Amount as a string (e.g., "100.00")
|
|
202
|
+
- `currency`: Currency code (e.g., "USD")
|
|
203
|
+
- **`destination`** (required): Payment destination configuration
|
|
204
|
+
- `destinationAddress`: Recipient address
|
|
205
|
+
- `chainId`: Destination chain ID as string
|
|
206
|
+
- `amountUnits`: Amount in smallest token unit (as string)
|
|
207
|
+
- `tokenSymbol`: Token symbol (e.g., "USDC")
|
|
208
|
+
- `tokenAddress`: Token contract address
|
|
209
|
+
- **`preferredChain`** (optional): Preferred source chain ID
|
|
210
|
+
- **`preferredToken`** (optional): Preferred source token symbol
|
|
211
|
+
- **`preferredTokenAddress`** (optional): Preferred source token address
|
|
212
|
+
- **`externalId`** (optional): External identifier for tracking
|
|
213
|
+
- **`metadata`** (optional): Additional metadata object
|
|
214
|
+
|
|
215
|
+
### Using createPaymentBridgeConfig
|
|
216
|
+
|
|
217
|
+
The `createPaymentBridgeConfig` helper function simplifies cross-chain payment configuration. It determines the preferred payment method based on the `payInTokenAddress` parameter.
|
|
218
|
+
|
|
219
|
+
**Important Notes:**
|
|
220
|
+
|
|
221
|
+
- **For EVM chain payouts (Base, Polygon, etc.)**: Provide `toAddress` with the destination EVM address. `toChain` and `toToken` are optional but default to USDC Base.
|
|
222
|
+
- **For Stellar payouts**: You **must** provide `toStellarAddress` with the Stellar address. You **must** also provide `toAddress` with any valid EVM address (required for internal routing). `toChain` and `toToken` are optional but default to USDC Base.
|
|
223
|
+
- **For Solana payouts**: You **must** provide `toSolanaAddress` with the Solana address. You **must** also provide `toAddress` with any valid EVM address (required for internal routing). `toChain` and `toToken` are optional but default to USDC Base.
|
|
224
|
+
|
|
225
|
+
**Supported `payInTokenAddress` values:**
|
|
226
|
+
|
|
227
|
+
- **USDC Base** - Base chain USDC token
|
|
228
|
+
- **USDC Polygon** - Polygon chain USDC token
|
|
229
|
+
- **USDC Solana** - Solana USDC token
|
|
230
|
+
- **USDC Stellar** - Stellar USDC token (format: `USDC:issuerPK` or issuer public key)
|
|
231
|
+
- **USDT BNB** - BSC (Binance Smart Chain) USDT token
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { createPaymentBridgeConfig } from "@rozoai/intent-common";
|
|
235
|
+
|
|
236
|
+
// Example: User pays with Polygon USDC, receives on Base
|
|
237
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
238
|
+
toChain: 8453, // Base
|
|
239
|
+
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
240
|
+
toAddress: "0x...",
|
|
241
|
+
toUnits: "1000000", // 1 USDC
|
|
242
|
+
payInTokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// preferred contains: preferredChain, preferredToken, preferredTokenAddress
|
|
246
|
+
// destination contains: destinationAddress, chainId, amountUnits, tokenSymbol, tokenAddress
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**More examples:**
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// Pay with Base USDC
|
|
253
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
254
|
+
toChain: 8453,
|
|
255
|
+
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
256
|
+
toAddress: "0x...",
|
|
257
|
+
toUnits: "1000000",
|
|
258
|
+
payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Pay with Solana USDC - Pay Out to Solana
|
|
262
|
+
// Note: toSolanaAddress is REQUIRED, toAddress is REQUIRED (any valid EVM address)
|
|
263
|
+
// toChain and toToken are optional (default to USDC Base)
|
|
264
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
265
|
+
toSolanaAddress: "So11111111111111111111111111111111111111112", // Solana destination address
|
|
266
|
+
toAddress: "0x1234567890123456789012345678901234567890", // Required: any valid EVM address
|
|
267
|
+
// toChain and toToken are optional, default to USDC Base
|
|
268
|
+
toUnits: "1000000",
|
|
269
|
+
payInTokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // Solana USDC
|
|
270
|
+
});
|
|
104
271
|
|
|
105
|
-
//
|
|
272
|
+
// Pay with Stellar USDC - Pay Out to Stellar
|
|
273
|
+
// Note: toStellarAddress is REQUIRED, toAddress is REQUIRED (any valid EVM address)
|
|
274
|
+
// toChain and toToken are optional (default to USDC Base)
|
|
275
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
276
|
+
toStellarAddress: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar destination address
|
|
277
|
+
toAddress: "0x1234567890123456789012345678901234567890", // Required: any valid EVM address
|
|
278
|
+
// toChain and toToken are optional, default to USDC Base
|
|
279
|
+
toUnits: "1000000",
|
|
280
|
+
payInTokenAddress:
|
|
281
|
+
"USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// Pay with BSC USDT
|
|
285
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
286
|
+
toChain: 8453,
|
|
287
|
+
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
288
|
+
toAddress: "0x...",
|
|
289
|
+
toUnits: "1000000",
|
|
290
|
+
payInTokenAddress: "0x55d398326f99059fF775485246999027B3197955", // BSC USDT
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Getting Payment Details
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// Get payment by ID
|
|
106
298
|
const fetchPaymentDetails = async (paymentId: string) => {
|
|
107
299
|
const response = await getRozoPayment(paymentId);
|
|
108
300
|
|
|
109
301
|
if (response.data) {
|
|
110
302
|
console.log("Payment status:", response.data.status);
|
|
303
|
+
console.log("Payment intent:", response.data.display.intent);
|
|
304
|
+
console.log(
|
|
305
|
+
"Destination address:",
|
|
306
|
+
response.data.destination.destinationAddress
|
|
307
|
+
);
|
|
308
|
+
console.log("Transaction hash:", response.data.destination.txHash);
|
|
309
|
+
} else if (response.error) {
|
|
310
|
+
console.error("Error fetching payment:", response.error.message);
|
|
111
311
|
}
|
|
112
312
|
};
|
|
113
313
|
```
|
|
114
314
|
|
|
315
|
+
### Real-World Usage Pattern
|
|
316
|
+
|
|
317
|
+
In the SDK, `createRozoPayment` is typically used within payment flow effects:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// Example from paymentEffects.ts
|
|
321
|
+
const paymentData: PaymentRequestData = {
|
|
322
|
+
appId: payParams?.rozoAppId ?? payParams?.appId ?? DEFAULT_ROZO_APP_ID,
|
|
323
|
+
display: {
|
|
324
|
+
intent: order?.metadata?.intent ?? "",
|
|
325
|
+
paymentValue: String(toUnits),
|
|
326
|
+
currency: "USD",
|
|
327
|
+
},
|
|
328
|
+
...preferred, // Spread preferred config from createPaymentBridgeConfig
|
|
329
|
+
destination, // Destination config from createPaymentBridgeConfig
|
|
330
|
+
externalId: order?.externalId ?? "",
|
|
331
|
+
metadata: {
|
|
332
|
+
preferredChain: preferred.preferredChain,
|
|
333
|
+
preferredToken: preferred.preferredToken,
|
|
334
|
+
preferredTokenAddress: preferred.preferredTokenAddress,
|
|
335
|
+
...mergedMetadata({
|
|
336
|
+
...(payParams?.metadata ?? {}),
|
|
337
|
+
...(order?.metadata ?? {}),
|
|
338
|
+
...(order.userMetadata ?? {}),
|
|
339
|
+
}),
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const rozoPayment = await createRozoPayment(paymentData);
|
|
344
|
+
if (!rozoPayment?.data?.id) {
|
|
345
|
+
throw new Error(rozoPayment?.error?.message ?? "Payment creation failed");
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
115
349
|
## React Hooks
|
|
116
350
|
|
|
117
|
-
React hooks for these APIs are available in the `@rozoai/intent-pay` package:
|
|
351
|
+
React hooks for these APIs are available in the `@rozoai/intent-pay` package. The SDK handles payment creation internally through the payment state machine, but you can access payment state using hooks:
|
|
118
352
|
|
|
119
353
|
```typescript
|
|
120
354
|
// In @rozoai/intent-pay
|
|
121
|
-
import {
|
|
122
|
-
useCreateRozoPayment,
|
|
123
|
-
useRozoPayment,
|
|
124
|
-
useRozoPayments
|
|
125
|
-
} from '@rozoai/intent-pay';
|
|
355
|
+
import { useRozoPay, useRozoPayStatus, useRozoPayUI } from "@rozoai/intent-pay";
|
|
126
356
|
|
|
127
357
|
// Use in React components
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
};
|
|
358
|
+
const PaymentComponent = () => {
|
|
359
|
+
const { createPreviewOrder, payWallet } = useRozoPay();
|
|
360
|
+
const { paymentStatus } = useRozoPayStatus();
|
|
361
|
+
const { isOpen, openRozoPay, closeRozoPay } = useRozoPayUI();
|
|
362
|
+
|
|
363
|
+
// Payment creation is handled internally by the SDK
|
|
364
|
+
// when using RozoPayButton or calling createPreviewOrder
|
|
365
|
+
// The SDK automatically uses createRozoPayment under the hood
|
|
138
366
|
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
367
|
+
if (paymentStatus === "payment_completed") {
|
|
368
|
+
return <div>Payment successful!</div>;
|
|
369
|
+
}
|
|
142
370
|
|
|
143
|
-
return <
|
|
371
|
+
return <RozoPayButton {...paymentProps} />;
|
|
144
372
|
};
|
|
145
373
|
```
|
|
146
374
|
|
|
375
|
+
Note: The SDK's payment flow automatically handles `createRozoPayment` calls internally. You typically don't need to call it directly when using the SDK components.
|
|
376
|
+
|
|
147
377
|
## Error Handling
|
|
148
378
|
|
|
149
379
|
All API responses include standardized error handling:
|
|
@@ -181,17 +411,25 @@ const response: ApiResponse<PaymentResponseData> = await getRozoPayment(
|
|
|
181
411
|
The API client is pre-configured with production RozoAI settings, so you can use it immediately:
|
|
182
412
|
|
|
183
413
|
```typescript
|
|
184
|
-
import {
|
|
414
|
+
import {
|
|
415
|
+
createRozoPayment,
|
|
416
|
+
createPaymentBridgeConfig,
|
|
417
|
+
} from "@rozoai/intent-common";
|
|
185
418
|
|
|
186
419
|
// Works out of the box with default configuration
|
|
420
|
+
const { preferred, destination } = createPaymentBridgeConfig({
|
|
421
|
+
toChain: 8453,
|
|
422
|
+
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
423
|
+
toAddress: "0x...",
|
|
424
|
+
toUnits: "10000000",
|
|
425
|
+
payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
426
|
+
});
|
|
427
|
+
|
|
187
428
|
const response = await createRozoPayment({
|
|
188
429
|
appId: "your-app-id",
|
|
189
430
|
display: { intent: "Payment", paymentValue: "10.00", currency: "USD" },
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
amountUnits: "10000000",
|
|
193
|
-
tokenSymbol: "USDC",
|
|
194
|
-
},
|
|
431
|
+
...preferred,
|
|
432
|
+
destination,
|
|
195
433
|
});
|
|
196
434
|
```
|
|
197
435
|
|
|
@@ -256,15 +494,56 @@ setApiConfig({
|
|
|
256
494
|
});
|
|
257
495
|
```
|
|
258
496
|
|
|
497
|
+
## Using Fee API
|
|
498
|
+
|
|
499
|
+
The fee module provides a function to calculate fees for payment amounts:
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import { getFee } from "@rozoai/intent-common";
|
|
503
|
+
|
|
504
|
+
// Get fee calculation (only amount is required)
|
|
505
|
+
const calculateFee = async () => {
|
|
506
|
+
const response = await getFee({
|
|
507
|
+
amount: 0.1,
|
|
508
|
+
// Optional parameters with defaults:
|
|
509
|
+
// appId: "rozodemo",
|
|
510
|
+
// currency: "USDC"
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
if (response.data) {
|
|
514
|
+
console.log("Fee:", response.data.fee);
|
|
515
|
+
console.log("Fee Percentage:", response.data.feePercentage);
|
|
516
|
+
console.log("Amount Out:", response.data.amount_out);
|
|
517
|
+
console.log("Minimum Fee:", response.data.minimumFee);
|
|
518
|
+
} else if (response.error) {
|
|
519
|
+
console.error("Error calculating fee:", response.error.message);
|
|
520
|
+
// Error response includes details like max allowed amount
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// With custom appId and currency
|
|
525
|
+
const response = await getFee({
|
|
526
|
+
amount: 100,
|
|
527
|
+
appId: "myapp",
|
|
528
|
+
currency: "USDC",
|
|
529
|
+
});
|
|
530
|
+
```
|
|
531
|
+
|
|
259
532
|
## Available Payment Functions
|
|
260
533
|
|
|
261
|
-
-
|
|
262
|
-
|
|
263
|
-
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
-
|
|
534
|
+
- **`createRozoPayment(paymentData: PaymentRequestData)`** - Create a new cross-chain payment. Requires `appId`, `display`, and `destination`. Use `createPaymentBridgeConfig` to generate `preferred` and `destination` configurations. Returns `ApiResponse<PaymentResponseData>` with payment ID, status, and URL.
|
|
535
|
+
|
|
536
|
+
- **`getRozoPayment(paymentId: string)`** - Get payment details by ID. Automatically handles both standard payment IDs and MugglePay order IDs. Returns `ApiResponse<PaymentResponseData>` with full payment information including status, destination, and transaction hashes.
|
|
537
|
+
|
|
538
|
+
### Helper Functions
|
|
539
|
+
|
|
540
|
+
- **`createPaymentBridgeConfig(config: PaymentBridgeConfig)`** - Creates payment bridge configuration for cross-chain payments. Determines preferred payment method (source chain/token) and destination configuration. The `payInTokenAddress` parameter supports: USDC Base, USDC Polygon, USDC Solana, USDC Stellar, and USDT BNB. Returns `{ preferred: PreferredPaymentConfig, destination: DestinationConfig }`.
|
|
541
|
+
|
|
542
|
+
- **`mergedMetadata(...metadataObjects)`** - Utility function to merge multiple metadata objects while handling conflicts and filtering sensitive fields.
|
|
543
|
+
|
|
544
|
+
## Available Fee Functions
|
|
545
|
+
|
|
546
|
+
- `getFee(params)` - Calculate fee for a payment amount (amount required, appId and currency optional)
|
|
268
547
|
|
|
269
548
|
## Best Practices
|
|
270
549
|
|
package/src/api/fee.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ApiResponse } from "./base";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fee response data type (success case)
|
|
5
|
+
*/
|
|
6
|
+
export interface FeeResponseData {
|
|
7
|
+
appId: string;
|
|
8
|
+
amount: number;
|
|
9
|
+
currency: string;
|
|
10
|
+
fee: number;
|
|
11
|
+
feePercentage: string;
|
|
12
|
+
minimumFee: string;
|
|
13
|
+
amount_out: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fee error response data type
|
|
18
|
+
*/
|
|
19
|
+
export interface FeeErrorData {
|
|
20
|
+
error: string;
|
|
21
|
+
message: string;
|
|
22
|
+
received: number;
|
|
23
|
+
maxAllowed: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fee request parameters
|
|
28
|
+
*/
|
|
29
|
+
export interface GetFeeParams {
|
|
30
|
+
amount: number;
|
|
31
|
+
appId?: string;
|
|
32
|
+
currency?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets fee calculation for a payment amount
|
|
37
|
+
* @param params - Fee calculation parameters (amount is required)
|
|
38
|
+
* @returns Promise with fee response or error
|
|
39
|
+
*/
|
|
40
|
+
export const getFee = async (
|
|
41
|
+
params: GetFeeParams
|
|
42
|
+
): Promise<ApiResponse<FeeResponseData>> => {
|
|
43
|
+
const { amount, appId = "rozodemo", currency = "USDC" } = params;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const queryParams = new URLSearchParams({
|
|
47
|
+
amount: amount.toString(),
|
|
48
|
+
appId,
|
|
49
|
+
currency,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const response = await fetch(
|
|
53
|
+
`https://intentapi.rozo.ai/getFee?${queryParams.toString()}`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const data = (await response.json()) as FeeResponseData | FeeErrorData;
|
|
57
|
+
|
|
58
|
+
// Check if response contains an error
|
|
59
|
+
if (!response.ok || "error" in data) {
|
|
60
|
+
const errorData = data as FeeErrorData;
|
|
61
|
+
return {
|
|
62
|
+
data: null,
|
|
63
|
+
error: new Error(errorData.message || errorData.error),
|
|
64
|
+
status: response.status,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
data: data as FeeResponseData,
|
|
70
|
+
error: null,
|
|
71
|
+
status: response.status,
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
data: null,
|
|
76
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
77
|
+
status: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
package/src/bridge.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
rozoSolanaUSDC,
|
|
15
15
|
rozoStellar,
|
|
16
16
|
rozoStellarUSDC,
|
|
17
|
+
worldchainUSDC,
|
|
17
18
|
} from ".";
|
|
18
19
|
import type { PaymentResponseData } from "./api/payment";
|
|
19
20
|
|
|
@@ -50,11 +51,11 @@ export interface DestinationConfig {
|
|
|
50
51
|
* the complexity of multi-chain payments by:
|
|
51
52
|
*
|
|
52
53
|
* 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
|
+
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, Worldchain USDC, and BSC USDT
|
|
54
55
|
* - Sets appropriate chain ID and token address for the source transaction
|
|
55
56
|
*
|
|
56
57
|
* 2. **Destination Configuration**: Determines where funds will be received
|
|
57
|
-
* - Supports Base, Solana, and
|
|
58
|
+
* - Supports Base, Solana, Stellar, and Worldchain as destination chains
|
|
58
59
|
* - Handles special address formats for Solana and Stellar addresses
|
|
59
60
|
* - Defaults to Base USDC when no special destination is specified
|
|
60
61
|
*
|
|
@@ -177,6 +178,15 @@ export function createPaymentBridgeConfig({
|
|
|
177
178
|
preferredTokenAddress: `USDC:${rozoStellarUSDC.token}`,
|
|
178
179
|
};
|
|
179
180
|
}
|
|
181
|
+
// Pay In USDC Worldchain
|
|
182
|
+
else if (payInTokenAddress === worldchainUSDC.token) {
|
|
183
|
+
log?.(`[Payment Bridge] Pay In USDC Worldchain`);
|
|
184
|
+
preferred = {
|
|
185
|
+
preferredChain: String(worldchainUSDC.chainId),
|
|
186
|
+
preferredToken: "USDC",
|
|
187
|
+
preferredTokenAddress: worldchainUSDC.token,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
180
190
|
// Pay In USDT BSC
|
|
181
191
|
else if (payInTokenAddress === bscUSDT.token) {
|
|
182
192
|
log?.(`[Payment Bridge] Pay In USDT BSC`);
|
package/src/index.ts
CHANGED