@usdctofiat/offramp 0.1.4 → 0.2.0
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/README.md +27 -6
- package/dist/{chunk-BJNSLI3D.js → chunk-E4AJU3FA.js} +98 -40
- package/dist/chunk-E4AJU3FA.js.map +1 -0
- package/dist/{types-DjkNvO-k.d.cts → errors-DQqv1xfX.d.cts} +18 -1
- package/dist/{types-DjkNvO-k.d.ts → errors-DQqv1xfX.d.ts} +18 -1
- package/dist/index.cjs +125 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -22
- package/dist/index.d.ts +40 -22
- package/dist/index.js +1 -1
- package/dist/react.cjs +120 -70
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +9 -2
- package/dist/react.d.ts +9 -2
- package/dist/react.js +12 -17
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BJNSLI3D.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,31 +1,62 @@
|
|
|
1
1
|
import { WalletClient } from 'viem';
|
|
2
|
-
import { O as OfframpParams, a as OnProgress, b as OfframpResult, D as DepositInfo, P as PlatformInfo, c as Platform, C as CurrencyInfo
|
|
3
|
-
export {
|
|
2
|
+
import { O as OfframpParams, a as OnProgress, b as OfframpResult, D as DepositInfo, P as PlatformInfo, c as Platform, C as CurrencyInfo } from './errors-DQqv1xfX.cjs';
|
|
3
|
+
export { d as CURRENCIES, e as Currency, f as DepositStatus, g as OfframpError, h as OfframpErrorCode, i as OfframpProgress, j as OfframpStep, k as PAYMENT_PLATFORMS, S as SUPPORTED_CURRENCIES } from './errors-DQqv1xfX.cjs';
|
|
4
4
|
|
|
5
5
|
declare class Offramp {
|
|
6
6
|
/**
|
|
7
7
|
* Create an offramp deposit: approve USDC, register payee, create deposit,
|
|
8
8
|
* confirm on-chain, and delegate to the vault. All in one call.
|
|
9
|
+
*
|
|
10
|
+
* @param walletClient - viem WalletClient with an account
|
|
11
|
+
* @param params - Deposit parameters (amount, platform, currency, identifier)
|
|
12
|
+
* @param onProgress - Optional callback for step-by-step progress updates
|
|
9
13
|
*/
|
|
10
14
|
createDeposit(walletClient: WalletClient, params: OfframpParams, onProgress?: OnProgress): Promise<OfframpResult>;
|
|
11
15
|
/**
|
|
12
|
-
* Fetch deposits for a wallet address.
|
|
13
|
-
* sorted by status
|
|
16
|
+
* Fetch all deposits for a wallet address. Read-only, no wallet needed.
|
|
17
|
+
* Returns active, empty, and closed deposits sorted by status then recency.
|
|
14
18
|
*/
|
|
15
19
|
getDeposits(walletAddress: string): Promise<DepositInfo[]>;
|
|
16
20
|
/**
|
|
17
|
-
*
|
|
21
|
+
* Find a deposit by its transaction hash. Useful for recovering from
|
|
22
|
+
* CONFIRMATION_FAILED errors where you have a txHash but no depositId.
|
|
23
|
+
*
|
|
24
|
+
* @param walletAddress - The depositor's wallet address
|
|
25
|
+
* @param txHash - The transaction hash from createDeposit
|
|
26
|
+
*/
|
|
27
|
+
getDepositByTxHash(walletAddress: string, txHash: string): Promise<DepositInfo | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Delegate an existing deposit to the Delegate vault. Use this to:
|
|
30
|
+
* - Retry after a DELEGATION_FAILED error
|
|
31
|
+
* - Delegate a deposit created outside the SDK
|
|
32
|
+
* - Delegate a deposit created via usdctofiat.xyz
|
|
33
|
+
*
|
|
34
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
35
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
36
|
+
*/
|
|
37
|
+
delegateDeposit(walletClient: WalletClient, depositId: string, escrowAddress?: string): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Withdraw remaining USDC and close a deposit.
|
|
40
|
+
*
|
|
41
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
42
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
18
43
|
*/
|
|
19
44
|
withdrawDeposit(walletClient: WalletClient, depositId: string, escrowAddress?: string): Promise<string>;
|
|
20
|
-
/** List available payment platforms and
|
|
45
|
+
/** List available payment platforms with currencies, labels, and format requirements. */
|
|
21
46
|
getPlatforms(): PlatformInfo[];
|
|
22
47
|
/** Get supported currencies for a specific platform. */
|
|
23
48
|
getCurrencies(platform: Platform): string[];
|
|
24
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Get currency metadata for UI rendering.
|
|
51
|
+
* @returns Symbol (€), full name (Euro), and country code (eu), or null if unsupported.
|
|
52
|
+
*/
|
|
25
53
|
getCurrencyInfo(code: string): CurrencyInfo | null;
|
|
26
54
|
/** Get all supported currencies with metadata. */
|
|
27
55
|
getAllCurrencies(): CurrencyInfo[];
|
|
28
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Validate and normalize a payment identifier for a platform.
|
|
58
|
+
* Strips leading @/$ characters, validates format (email, IBAN, etc).
|
|
59
|
+
*/
|
|
29
60
|
validateIdentifier(platform: Platform, identifier: string): {
|
|
30
61
|
valid: boolean;
|
|
31
62
|
normalized: string;
|
|
@@ -33,17 +64,4 @@ declare class Offramp {
|
|
|
33
64
|
};
|
|
34
65
|
}
|
|
35
66
|
|
|
36
|
-
|
|
37
|
-
declare class OfframpError extends Error {
|
|
38
|
-
readonly code: OfframpErrorCode;
|
|
39
|
-
readonly step?: OfframpStep;
|
|
40
|
-
readonly cause?: unknown;
|
|
41
|
-
readonly txHash?: string;
|
|
42
|
-
readonly depositId?: string;
|
|
43
|
-
constructor(message: string, code: OfframpErrorCode, step?: OfframpStep, cause?: unknown, details?: {
|
|
44
|
-
txHash?: string;
|
|
45
|
-
depositId?: string;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { CurrencyInfo, DepositInfo, Offramp, OfframpError, type OfframpErrorCode, OfframpParams, OfframpResult, OfframpStep, OnProgress, Platform, PlatformInfo };
|
|
67
|
+
export { CurrencyInfo, DepositInfo, Offramp, OfframpParams, OfframpResult, OnProgress, Platform, PlatformInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,62 @@
|
|
|
1
1
|
import { WalletClient } from 'viem';
|
|
2
|
-
import { O as OfframpParams, a as OnProgress, b as OfframpResult, D as DepositInfo, P as PlatformInfo, c as Platform, C as CurrencyInfo
|
|
3
|
-
export {
|
|
2
|
+
import { O as OfframpParams, a as OnProgress, b as OfframpResult, D as DepositInfo, P as PlatformInfo, c as Platform, C as CurrencyInfo } from './errors-DQqv1xfX.js';
|
|
3
|
+
export { d as CURRENCIES, e as Currency, f as DepositStatus, g as OfframpError, h as OfframpErrorCode, i as OfframpProgress, j as OfframpStep, k as PAYMENT_PLATFORMS, S as SUPPORTED_CURRENCIES } from './errors-DQqv1xfX.js';
|
|
4
4
|
|
|
5
5
|
declare class Offramp {
|
|
6
6
|
/**
|
|
7
7
|
* Create an offramp deposit: approve USDC, register payee, create deposit,
|
|
8
8
|
* confirm on-chain, and delegate to the vault. All in one call.
|
|
9
|
+
*
|
|
10
|
+
* @param walletClient - viem WalletClient with an account
|
|
11
|
+
* @param params - Deposit parameters (amount, platform, currency, identifier)
|
|
12
|
+
* @param onProgress - Optional callback for step-by-step progress updates
|
|
9
13
|
*/
|
|
10
14
|
createDeposit(walletClient: WalletClient, params: OfframpParams, onProgress?: OnProgress): Promise<OfframpResult>;
|
|
11
15
|
/**
|
|
12
|
-
* Fetch deposits for a wallet address.
|
|
13
|
-
* sorted by status
|
|
16
|
+
* Fetch all deposits for a wallet address. Read-only, no wallet needed.
|
|
17
|
+
* Returns active, empty, and closed deposits sorted by status then recency.
|
|
14
18
|
*/
|
|
15
19
|
getDeposits(walletAddress: string): Promise<DepositInfo[]>;
|
|
16
20
|
/**
|
|
17
|
-
*
|
|
21
|
+
* Find a deposit by its transaction hash. Useful for recovering from
|
|
22
|
+
* CONFIRMATION_FAILED errors where you have a txHash but no depositId.
|
|
23
|
+
*
|
|
24
|
+
* @param walletAddress - The depositor's wallet address
|
|
25
|
+
* @param txHash - The transaction hash from createDeposit
|
|
26
|
+
*/
|
|
27
|
+
getDepositByTxHash(walletAddress: string, txHash: string): Promise<DepositInfo | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Delegate an existing deposit to the Delegate vault. Use this to:
|
|
30
|
+
* - Retry after a DELEGATION_FAILED error
|
|
31
|
+
* - Delegate a deposit created outside the SDK
|
|
32
|
+
* - Delegate a deposit created via usdctofiat.xyz
|
|
33
|
+
*
|
|
34
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
35
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
36
|
+
*/
|
|
37
|
+
delegateDeposit(walletClient: WalletClient, depositId: string, escrowAddress?: string): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Withdraw remaining USDC and close a deposit.
|
|
40
|
+
*
|
|
41
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
42
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
18
43
|
*/
|
|
19
44
|
withdrawDeposit(walletClient: WalletClient, depositId: string, escrowAddress?: string): Promise<string>;
|
|
20
|
-
/** List available payment platforms and
|
|
45
|
+
/** List available payment platforms with currencies, labels, and format requirements. */
|
|
21
46
|
getPlatforms(): PlatformInfo[];
|
|
22
47
|
/** Get supported currencies for a specific platform. */
|
|
23
48
|
getCurrencies(platform: Platform): string[];
|
|
24
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Get currency metadata for UI rendering.
|
|
51
|
+
* @returns Symbol (€), full name (Euro), and country code (eu), or null if unsupported.
|
|
52
|
+
*/
|
|
25
53
|
getCurrencyInfo(code: string): CurrencyInfo | null;
|
|
26
54
|
/** Get all supported currencies with metadata. */
|
|
27
55
|
getAllCurrencies(): CurrencyInfo[];
|
|
28
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Validate and normalize a payment identifier for a platform.
|
|
58
|
+
* Strips leading @/$ characters, validates format (email, IBAN, etc).
|
|
59
|
+
*/
|
|
29
60
|
validateIdentifier(platform: Platform, identifier: string): {
|
|
30
61
|
valid: boolean;
|
|
31
62
|
normalized: string;
|
|
@@ -33,17 +64,4 @@ declare class Offramp {
|
|
|
33
64
|
};
|
|
34
65
|
}
|
|
35
66
|
|
|
36
|
-
|
|
37
|
-
declare class OfframpError extends Error {
|
|
38
|
-
readonly code: OfframpErrorCode;
|
|
39
|
-
readonly step?: OfframpStep;
|
|
40
|
-
readonly cause?: unknown;
|
|
41
|
-
readonly txHash?: string;
|
|
42
|
-
readonly depositId?: string;
|
|
43
|
-
constructor(message: string, code: OfframpErrorCode, step?: OfframpStep, cause?: unknown, details?: {
|
|
44
|
-
txHash?: string;
|
|
45
|
-
depositId?: string;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { CurrencyInfo, DepositInfo, Offramp, OfframpError, type OfframpErrorCode, OfframpParams, OfframpResult, OfframpStep, OnProgress, Platform, PlatformInfo };
|
|
67
|
+
export { CurrencyInfo, DepositInfo, Offramp, OfframpParams, OfframpResult, OnProgress, Platform, PlatformInfo };
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -31,6 +31,20 @@ var import_react = require("react");
|
|
|
31
31
|
var import_viem2 = require("viem");
|
|
32
32
|
var import_sdk4 = require("@zkp2p/sdk");
|
|
33
33
|
|
|
34
|
+
// src/types.ts
|
|
35
|
+
var PLATFORMS = [
|
|
36
|
+
"venmo",
|
|
37
|
+
"cashapp",
|
|
38
|
+
"chime",
|
|
39
|
+
"revolut",
|
|
40
|
+
"wise",
|
|
41
|
+
"mercadopago",
|
|
42
|
+
"zelle",
|
|
43
|
+
"paypal",
|
|
44
|
+
"monzo",
|
|
45
|
+
"n26"
|
|
46
|
+
];
|
|
47
|
+
|
|
34
48
|
// src/deposit.ts
|
|
35
49
|
var import_viem = require("viem");
|
|
36
50
|
var import_chains = require("viem/chains");
|
|
@@ -61,22 +75,6 @@ var PAYEE_REGISTRATION_TIMEOUT_MS = 8e3;
|
|
|
61
75
|
// src/platforms.ts
|
|
62
76
|
var import_sdk2 = require("@zkp2p/sdk");
|
|
63
77
|
var import_zod = require("zod");
|
|
64
|
-
|
|
65
|
-
// src/types.ts
|
|
66
|
-
var PLATFORMS = [
|
|
67
|
-
"venmo",
|
|
68
|
-
"cashapp",
|
|
69
|
-
"chime",
|
|
70
|
-
"revolut",
|
|
71
|
-
"wise",
|
|
72
|
-
"mercadopago",
|
|
73
|
-
"zelle",
|
|
74
|
-
"paypal",
|
|
75
|
-
"monzo",
|
|
76
|
-
"n26"
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
// src/platforms.ts
|
|
80
78
|
var ZELLE_HASH_LOOKUP_NAMES = ["zelle", "zelle-bofa", "zelle-chase", "zelle-citi"];
|
|
81
79
|
var PAYMENT_CATALOG = (0, import_sdk2.getPaymentMethodsCatalog)(BASE_CHAIN_ID, RUNTIME_ENV);
|
|
82
80
|
var FALLBACK_CURRENCIES = {
|
|
@@ -590,6 +588,14 @@ async function createOfframpDeposit(walletClient, params, onProgress) {
|
|
|
590
588
|
}
|
|
591
589
|
|
|
592
590
|
// src/client.ts
|
|
591
|
+
var indexerClient = null;
|
|
592
|
+
function getIndexerService() {
|
|
593
|
+
if (!indexerClient) {
|
|
594
|
+
const client = new import_sdk4.IndexerClient(`${API_BASE_URL.replace(/\/+$/, "")}`);
|
|
595
|
+
indexerClient = new import_sdk4.IndexerDepositService(client);
|
|
596
|
+
}
|
|
597
|
+
return indexerClient;
|
|
598
|
+
}
|
|
593
599
|
function toBigInt(value) {
|
|
594
600
|
try {
|
|
595
601
|
return BigInt(value || "0");
|
|
@@ -609,7 +615,7 @@ function resolveMethodNames(hashes) {
|
|
|
609
615
|
const names = /* @__PURE__ */ new Set();
|
|
610
616
|
for (const { paymentMethodHash } of hashes) {
|
|
611
617
|
const normalized = paymentMethodHash.toLowerCase();
|
|
612
|
-
for (const platform of
|
|
618
|
+
for (const platform of PLATFORMS) {
|
|
613
619
|
const platformHashes = getPaymentMethodHashes(platform);
|
|
614
620
|
if (platformHashes.some((h) => h.toLowerCase() === normalized)) {
|
|
615
621
|
names.add(getPlatformConfig(platform).name);
|
|
@@ -619,60 +625,104 @@ function resolveMethodNames(hashes) {
|
|
|
619
625
|
}
|
|
620
626
|
return Array.from(names);
|
|
621
627
|
}
|
|
628
|
+
function mapDeposit(d) {
|
|
629
|
+
const delegationState = (0, import_sdk4.classifyDelegationState)(
|
|
630
|
+
d.rateManagerId ?? void 0,
|
|
631
|
+
d.rateManagerAddress ?? void 0,
|
|
632
|
+
DELEGATE_RATE_MANAGER_ID,
|
|
633
|
+
RATE_MANAGER_REGISTRY_ADDRESS
|
|
634
|
+
);
|
|
635
|
+
return {
|
|
636
|
+
depositId: d.depositId,
|
|
637
|
+
compositeId: d.id,
|
|
638
|
+
txHash: d.txHash,
|
|
639
|
+
status: resolveStatus(d),
|
|
640
|
+
remainingUsdc: toUsdc(d.remainingDeposits),
|
|
641
|
+
outstandingUsdc: toUsdc(d.outstandingIntentAmount),
|
|
642
|
+
totalTakenUsdc: toUsdc(d.totalAmountTaken),
|
|
643
|
+
fulfilledIntents: d.fulfilledIntents ?? 0,
|
|
644
|
+
paymentMethods: resolveMethodNames(d.paymentMethods),
|
|
645
|
+
currencies: d.currencies.map((c) => {
|
|
646
|
+
const info = (0, import_sdk4.getCurrencyInfoFromHash)(c.currencyCode);
|
|
647
|
+
return info?.currencyCode ?? c.currencyCode;
|
|
648
|
+
}),
|
|
649
|
+
rateSource: d.currencies[0]?.rateSource || "unknown",
|
|
650
|
+
delegated: delegationState === "delegated_here",
|
|
651
|
+
escrowAddress: d.escrowAddress
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function extractTxHash(result) {
|
|
655
|
+
if (typeof result === "string") return result;
|
|
656
|
+
if (result && typeof result === "object" && "hash" in result) return result.hash;
|
|
657
|
+
if (result && typeof result === "object" && "transactionHash" in result) return result.transactionHash;
|
|
658
|
+
throw new Error("Unexpected transaction result format");
|
|
659
|
+
}
|
|
622
660
|
var Offramp = class {
|
|
623
661
|
/**
|
|
624
662
|
* Create an offramp deposit: approve USDC, register payee, create deposit,
|
|
625
663
|
* confirm on-chain, and delegate to the vault. All in one call.
|
|
664
|
+
*
|
|
665
|
+
* @param walletClient - viem WalletClient with an account
|
|
666
|
+
* @param params - Deposit parameters (amount, platform, currency, identifier)
|
|
667
|
+
* @param onProgress - Optional callback for step-by-step progress updates
|
|
626
668
|
*/
|
|
627
669
|
async createDeposit(walletClient, params, onProgress) {
|
|
628
670
|
return createOfframpDeposit(walletClient, params, onProgress);
|
|
629
671
|
}
|
|
630
672
|
/**
|
|
631
|
-
* Fetch deposits for a wallet address.
|
|
632
|
-
* sorted by status
|
|
673
|
+
* Fetch all deposits for a wallet address. Read-only, no wallet needed.
|
|
674
|
+
* Returns active, empty, and closed deposits sorted by status then recency.
|
|
633
675
|
*/
|
|
634
676
|
async getDeposits(walletAddress) {
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
{ account: void 0, chain: void 0, transport: void 0 }
|
|
638
|
-
);
|
|
639
|
-
const raw = await client.indexer.getDepositsWithRelations(
|
|
677
|
+
const service = getIndexerService();
|
|
678
|
+
const raw = await service.fetchDepositsWithRelations(
|
|
640
679
|
{ depositor: walletAddress },
|
|
641
680
|
{ limit: 100 }
|
|
642
681
|
);
|
|
643
682
|
const statusOrder = { active: 0, empty: 1, closed: 2 };
|
|
644
|
-
return (raw || []).map((
|
|
645
|
-
const delegationState = (0, import_sdk4.classifyDelegationState)(
|
|
646
|
-
d.rateManagerId ?? void 0,
|
|
647
|
-
d.rateManagerAddress ?? void 0,
|
|
648
|
-
DELEGATE_RATE_MANAGER_ID,
|
|
649
|
-
RATE_MANAGER_REGISTRY_ADDRESS
|
|
650
|
-
);
|
|
651
|
-
return {
|
|
652
|
-
depositId: d.depositId,
|
|
653
|
-
compositeId: d.id,
|
|
654
|
-
status: resolveStatus(d),
|
|
655
|
-
remainingUsdc: toUsdc(d.remainingDeposits),
|
|
656
|
-
outstandingUsdc: toUsdc(d.outstandingIntentAmount),
|
|
657
|
-
totalTakenUsdc: toUsdc(d.totalAmountTaken),
|
|
658
|
-
fulfilledIntents: d.fulfilledIntents ?? 0,
|
|
659
|
-
paymentMethods: resolveMethodNames(d.paymentMethods),
|
|
660
|
-
currencies: d.currencies.map((c) => {
|
|
661
|
-
const info = (0, import_sdk4.getCurrencyInfoFromHash)(c.currencyCode);
|
|
662
|
-
return info?.currencyCode ?? c.currencyCode;
|
|
663
|
-
}),
|
|
664
|
-
rateSource: d.currencies[0]?.rateSource || "unknown",
|
|
665
|
-
delegated: delegationState === "delegated_here",
|
|
666
|
-
escrowAddress: d.escrowAddress
|
|
667
|
-
};
|
|
668
|
-
}).sort((a, b) => {
|
|
683
|
+
return (raw || []).map(mapDeposit).sort((a, b) => {
|
|
669
684
|
const diff = statusOrder[a.status] - statusOrder[b.status];
|
|
670
685
|
if (diff !== 0) return diff;
|
|
671
686
|
return Number(BigInt(b.depositId) - BigInt(a.depositId));
|
|
672
687
|
});
|
|
673
688
|
}
|
|
674
689
|
/**
|
|
675
|
-
*
|
|
690
|
+
* Find a deposit by its transaction hash. Useful for recovering from
|
|
691
|
+
* CONFIRMATION_FAILED errors where you have a txHash but no depositId.
|
|
692
|
+
*
|
|
693
|
+
* @param walletAddress - The depositor's wallet address
|
|
694
|
+
* @param txHash - The transaction hash from createDeposit
|
|
695
|
+
*/
|
|
696
|
+
async getDepositByTxHash(walletAddress, txHash) {
|
|
697
|
+
const deposits = await this.getDeposits(walletAddress);
|
|
698
|
+
const normalized = txHash.toLowerCase();
|
|
699
|
+
return deposits.find((d) => d.txHash?.toLowerCase() === normalized) ?? null;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Delegate an existing deposit to the Delegate vault. Use this to:
|
|
703
|
+
* - Retry after a DELEGATION_FAILED error
|
|
704
|
+
* - Delegate a deposit created outside the SDK
|
|
705
|
+
* - Delegate a deposit created via usdctofiat.xyz
|
|
706
|
+
*
|
|
707
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
708
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
709
|
+
*/
|
|
710
|
+
async delegateDeposit(walletClient, depositId, escrowAddress) {
|
|
711
|
+
const client = createSdkClient(walletClient);
|
|
712
|
+
const result = await client.setRateManager({
|
|
713
|
+
depositId: BigInt(depositId),
|
|
714
|
+
rateManagerAddress: RATE_MANAGER_REGISTRY_ADDRESS,
|
|
715
|
+
rateManagerId: DELEGATE_RATE_MANAGER_ID,
|
|
716
|
+
escrowAddress: escrowAddress || ESCROW_ADDRESS,
|
|
717
|
+
txOverrides: { referrer: [REFERRER] }
|
|
718
|
+
});
|
|
719
|
+
return extractTxHash(result);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Withdraw remaining USDC and close a deposit.
|
|
723
|
+
*
|
|
724
|
+
* @param walletClient - viem WalletClient with the deposit owner's account
|
|
725
|
+
* @param depositId - The numeric deposit ID (not the composite escrow_id format)
|
|
676
726
|
*/
|
|
677
727
|
async withdrawDeposit(walletClient, depositId, escrowAddress) {
|
|
678
728
|
const client = createSdkClient(walletClient);
|
|
@@ -681,9 +731,9 @@ var Offramp = class {
|
|
|
681
731
|
escrowAddress: escrowAddress || ESCROW_ADDRESS,
|
|
682
732
|
txOverrides: { referrer: [REFERRER] }
|
|
683
733
|
});
|
|
684
|
-
return
|
|
734
|
+
return extractTxHash(result);
|
|
685
735
|
}
|
|
686
|
-
/** List available payment platforms and
|
|
736
|
+
/** List available payment platforms with currencies, labels, and format requirements. */
|
|
687
737
|
getPlatforms() {
|
|
688
738
|
return getPlatforms();
|
|
689
739
|
}
|
|
@@ -691,7 +741,10 @@ var Offramp = class {
|
|
|
691
741
|
getCurrencies(platform) {
|
|
692
742
|
return getCurrencies(platform);
|
|
693
743
|
}
|
|
694
|
-
/**
|
|
744
|
+
/**
|
|
745
|
+
* Get currency metadata for UI rendering.
|
|
746
|
+
* @returns Symbol (€), full name (Euro), and country code (eu), or null if unsupported.
|
|
747
|
+
*/
|
|
695
748
|
getCurrencyInfo(code) {
|
|
696
749
|
const info = import_sdk4.currencyInfo[code];
|
|
697
750
|
if (!info) return null;
|
|
@@ -708,7 +761,10 @@ var Offramp = class {
|
|
|
708
761
|
return this.getCurrencyInfo(code);
|
|
709
762
|
}).filter(Boolean);
|
|
710
763
|
}
|
|
711
|
-
/**
|
|
764
|
+
/**
|
|
765
|
+
* Validate and normalize a payment identifier for a platform.
|
|
766
|
+
* Strips leading @/$ characters, validates format (email, IBAN, etc).
|
|
767
|
+
*/
|
|
712
768
|
validateIdentifier(platform, identifier) {
|
|
713
769
|
return validateIdentifier(platform, identifier);
|
|
714
770
|
}
|
|
@@ -739,7 +795,7 @@ function useOfframp() {
|
|
|
739
795
|
}, []);
|
|
740
796
|
const createDeposit = (0, import_react.useCallback)(
|
|
741
797
|
async (walletClient, params) => {
|
|
742
|
-
if (lockRef.current) throw new
|
|
798
|
+
if (lockRef.current) throw new OfframpError("Deposit already in progress", "VALIDATION");
|
|
743
799
|
lockRef.current = true;
|
|
744
800
|
setIsLoading(true);
|
|
745
801
|
setError(null);
|
|
@@ -756,8 +812,8 @@ function useOfframp() {
|
|
|
756
812
|
setTxHash(result.txHash);
|
|
757
813
|
return result;
|
|
758
814
|
} catch (err) {
|
|
759
|
-
const
|
|
760
|
-
setError(
|
|
815
|
+
const offrampError = err instanceof OfframpError ? err : new OfframpError(err instanceof Error ? err.message : "Offramp failed", "DEPOSIT_FAILED");
|
|
816
|
+
setError(offrampError);
|
|
761
817
|
throw err;
|
|
762
818
|
} finally {
|
|
763
819
|
setIsLoading(false);
|
|
@@ -766,15 +822,7 @@ function useOfframp() {
|
|
|
766
822
|
},
|
|
767
823
|
[]
|
|
768
824
|
);
|
|
769
|
-
const
|
|
770
|
-
return getOfframp().getDeposits(walletAddress);
|
|
771
|
-
}, []);
|
|
772
|
-
const withdrawDeposit = (0, import_react.useCallback)(
|
|
773
|
-
async (walletClient, id, escrowAddress) => {
|
|
774
|
-
return getOfframp().withdrawDeposit(walletClient, id, escrowAddress);
|
|
775
|
-
},
|
|
776
|
-
[]
|
|
777
|
-
);
|
|
825
|
+
const o = getOfframp();
|
|
778
826
|
return {
|
|
779
827
|
step,
|
|
780
828
|
txHash,
|
|
@@ -782,13 +830,15 @@ function useOfframp() {
|
|
|
782
830
|
error,
|
|
783
831
|
isLoading,
|
|
784
832
|
createDeposit,
|
|
785
|
-
getDeposits,
|
|
786
|
-
|
|
833
|
+
getDeposits: (0, import_react.useCallback)((addr) => o.getDeposits(addr), [o]),
|
|
834
|
+
getDepositByTxHash: (0, import_react.useCallback)((addr, hash) => o.getDepositByTxHash(addr, hash), [o]),
|
|
835
|
+
delegateDeposit: (0, import_react.useCallback)((wc, id, esc) => o.delegateDeposit(wc, id, esc), [o]),
|
|
836
|
+
withdrawDeposit: (0, import_react.useCallback)((wc, id, esc) => o.withdrawDeposit(wc, id, esc), [o]),
|
|
787
837
|
reset,
|
|
788
838
|
getPlatforms,
|
|
789
839
|
getCurrencies,
|
|
790
|
-
getCurrencyInfo: (code) =>
|
|
791
|
-
getAllCurrencies: () =>
|
|
840
|
+
getCurrencyInfo: (0, import_react.useCallback)((code) => o.getCurrencyInfo(code), [o]),
|
|
841
|
+
getAllCurrencies: (0, import_react.useCallback)(() => o.getAllCurrencies(), [o]),
|
|
792
842
|
validateIdentifier
|
|
793
843
|
};
|
|
794
844
|
}
|