@usdctofiat/offramp 0.2.1 → 1.0.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/README.md +37 -85
- package/dist/{chunk-AGP66RQ5.js → chunk-2UENKRGX.js} +219 -444
- package/dist/chunk-2UENKRGX.js.map +1 -0
- package/dist/errors-A8NBr_Iw.d.cts +101 -0
- package/dist/errors-A8NBr_Iw.d.ts +101 -0
- package/dist/index.cjs +265 -470
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -64
- package/dist/index.d.ts +24 -64
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +254 -398
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +5 -20
- package/dist/react.d.ts +5 -20
- package/dist/react.js +10 -27
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-AGP66RQ5.js.map +0 -1
- package/dist/errors-DQqv1xfX.d.cts +0 -124
- package/dist/errors-DQqv1xfX.d.ts +0 -124
package/README.md
CHANGED
|
@@ -3,61 +3,55 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@usdctofiat/offramp)
|
|
4
4
|
[](https://github.com/ADWilkinson/galleonlabs-zkp2p/blob/main/packages/offramp-sdk/LICENSE)
|
|
5
5
|
|
|
6
|
-
USDC-to-fiat offramp SDK for Base.
|
|
6
|
+
USDC-to-fiat offramp SDK for Base. 3 functions + 2 const objects.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
|
|
11
|
+
bun add @usdctofiat/offramp
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Quick Start
|
|
15
15
|
|
|
16
16
|
```typescript
|
|
17
|
-
import {
|
|
17
|
+
import { offramp, PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const result = await offramp.createDeposit(walletClient, {
|
|
19
|
+
const result = await offramp(walletClient, {
|
|
22
20
|
amount: "100",
|
|
23
|
-
platform:
|
|
21
|
+
platform: PLATFORMS.REVOLUT,
|
|
24
22
|
currency: CURRENCIES.EUR,
|
|
25
23
|
identifier: "alice",
|
|
26
24
|
});
|
|
27
|
-
|
|
28
|
-
console.log(result.depositId, result.txHash);
|
|
25
|
+
// { depositId: "362", txHash: "0x...", resumed: false }
|
|
29
26
|
```
|
|
30
27
|
|
|
31
28
|
## Deposit Management
|
|
32
29
|
|
|
33
30
|
```typescript
|
|
34
|
-
|
|
35
|
-
const deposits = await offramp.getDeposits("0xYourAddress");
|
|
36
|
-
// [{ depositId, status, remainingUsdc, fulfilledIntents, delegated, ... }]
|
|
31
|
+
import { deposits, close } from "@usdctofiat/offramp";
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
const list = await deposits("0xYourAddress");
|
|
34
|
+
await close(walletClient, "361");
|
|
40
35
|
```
|
|
41
36
|
|
|
42
37
|
## React
|
|
43
38
|
|
|
44
39
|
```typescript
|
|
45
40
|
import { useOfframp } from "@usdctofiat/offramp/react";
|
|
41
|
+
import { PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
46
42
|
|
|
47
|
-
function SellButton({ walletClient }) {
|
|
48
|
-
const {
|
|
43
|
+
function SellButton({ walletClient }: { walletClient: WalletClient }) {
|
|
44
|
+
const { offramp, step, isLoading } = useOfframp();
|
|
49
45
|
|
|
50
46
|
return (
|
|
51
47
|
<button
|
|
52
48
|
disabled={isLoading}
|
|
53
|
-
onClick={() =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
}
|
|
49
|
+
onClick={() => offramp(walletClient, {
|
|
50
|
+
amount: "100",
|
|
51
|
+
platform: PLATFORMS.REVOLUT,
|
|
52
|
+
currency: CURRENCIES.EUR,
|
|
53
|
+
identifier: "alice",
|
|
54
|
+
})}
|
|
61
55
|
>
|
|
62
56
|
{step ?? "Sell USDC"}
|
|
63
57
|
</button>
|
|
@@ -65,55 +59,26 @@ function SellButton({ walletClient }) {
|
|
|
65
59
|
}
|
|
66
60
|
```
|
|
67
61
|
|
|
68
|
-
##
|
|
62
|
+
## Platform & Currency Data
|
|
69
63
|
|
|
70
64
|
```typescript
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
import { PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
66
|
+
|
|
67
|
+
PLATFORMS.REVOLUT.name // "Revolut"
|
|
68
|
+
PLATFORMS.REVOLUT.currencies // ["USD", "EUR", "GBP", ...]
|
|
69
|
+
PLATFORMS.REVOLUT.identifier.label // "Revtag"
|
|
70
|
+
PLATFORMS.REVOLUT.identifier.placeholder // "revtag (no @)"
|
|
71
|
+
PLATFORMS.REVOLUT.identifier.help // "Revtag without @ (must be public)"
|
|
72
|
+
PLATFORMS.REVOLUT.validate("@alice") // { valid: true, normalized: "alice" }
|
|
73
|
+
|
|
74
|
+
CURRENCIES.EUR.symbol // "€"
|
|
75
|
+
CURRENCIES.EUR.name // "Euro"
|
|
76
|
+
CURRENCIES.EUR.countryCode // "eu"
|
|
76
77
|
```
|
|
77
78
|
|
|
78
|
-
##
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { PAYMENT_PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
82
|
-
|
|
83
|
-
// Platforms with currencies, labels, and format requirements
|
|
84
|
-
offramp.getPlatforms();
|
|
85
|
-
// [{ id: "revolut", name: "Revolut", currencies: ["USD","EUR",...], identifierLabel: "Revtag", helperText: "Revtag without @", ... }]
|
|
86
|
-
|
|
87
|
-
// Currencies for a platform
|
|
88
|
-
offramp.getCurrencies(PAYMENT_PLATFORMS.WISE);
|
|
89
|
-
// ["USD", "EUR", "GBP", "AUD", ...]
|
|
79
|
+
## Resumable
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
offramp.getCurrencyInfo(CURRENCIES.EUR);
|
|
93
|
-
// { code: "EUR", name: "Euro", symbol: "€", countryCode: "eu" }
|
|
94
|
-
|
|
95
|
-
offramp.getAllCurrencies();
|
|
96
|
-
// [{ code: "AED", name: "UAE Dirham", symbol: "د.إ", countryCode: "ae" }, ...]
|
|
97
|
-
|
|
98
|
-
// Validate and normalize identifiers (strips @, $, validates format)
|
|
99
|
-
offramp.validateIdentifier(PAYMENT_PLATFORMS.REVOLUT, "@alice");
|
|
100
|
-
// { valid: true, normalized: "alice" }
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Supported Platforms
|
|
104
|
-
|
|
105
|
-
| Platform | Currencies | Identifier |
|
|
106
|
-
|----------|-----------|-----------|
|
|
107
|
-
| Revolut | 23 currencies | Revtag |
|
|
108
|
-
| Wise | 30+ currencies | Wisetag |
|
|
109
|
-
| PayPal | 7 currencies | Email |
|
|
110
|
-
| Venmo | USD | Username |
|
|
111
|
-
| Cash App | USD | Cashtag |
|
|
112
|
-
| Zelle | USD | Email |
|
|
113
|
-
| Monzo | GBP | Username |
|
|
114
|
-
| N26 | EUR | IBAN |
|
|
115
|
-
| Chime | USD | ChimeSign |
|
|
116
|
-
| Mercado Pago | ARS | CVU |
|
|
81
|
+
`offramp()` is idempotent. If an undelegated deposit exists for the wallet, it skips straight to delegation. Handles browser crashes, failed delegation, and retries automatically. Just call `offramp()` again.
|
|
117
82
|
|
|
118
83
|
## Error Handling
|
|
119
84
|
|
|
@@ -121,31 +86,18 @@ offramp.validateIdentifier(PAYMENT_PLATFORMS.REVOLUT, "@alice");
|
|
|
121
86
|
import { OfframpError } from "@usdctofiat/offramp";
|
|
122
87
|
|
|
123
88
|
try {
|
|
124
|
-
await offramp
|
|
89
|
+
await offramp(walletClient, params);
|
|
125
90
|
} catch (err) {
|
|
126
91
|
if (err instanceof OfframpError) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
console.log(err.txHash); // Available if deposit was created on-chain
|
|
130
|
-
console.log(err.depositId); // Available if deposit was confirmed but delegation failed
|
|
92
|
+
if (err.code === "USER_CANCELLED") return;
|
|
93
|
+
// For any failure: call offramp() again to resume
|
|
131
94
|
}
|
|
132
95
|
}
|
|
133
96
|
```
|
|
134
97
|
|
|
135
98
|
## How It Works
|
|
136
99
|
|
|
137
|
-
Every deposit
|
|
138
|
-
|
|
139
|
-
1. **Delegated** to the USDCtoFiat Delegate vault for rate management
|
|
140
|
-
2. **Market-tracking** via oracle-based pricing
|
|
141
|
-
3. **Auto-closing** when fully filled
|
|
142
|
-
4. **Attributed** to Galleon Labs via ERC-8021
|
|
143
|
-
|
|
144
|
-
## Requirements
|
|
145
|
-
|
|
146
|
-
- Base network (chain ID 8453)
|
|
147
|
-
- viem `WalletClient` with an account
|
|
148
|
-
- USDC balance on Base
|
|
100
|
+
Every deposit is automatically delegated to the Delegate vault for oracle-based rate management, auto-closes when filled, and is attributed to Galleon Labs via ERC-8021.
|
|
149
101
|
|
|
150
102
|
## Links
|
|
151
103
|
|