@usdctofiat/offramp 1.0.0 → 1.1.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 +58 -78
- package/dist/{chunk-WQCLEJWY.js → chunk-ZKIWUJGL.js} +789 -129
- package/dist/chunk-ZKIWUJGL.js.map +1 -0
- package/dist/{errors-A8NBr_Iw.d.cts → errors-Dtzrl98J.d.cts} +5 -1
- package/dist/{errors-A8NBr_Iw.d.ts → errors-Dtzrl98J.d.ts} +5 -1
- package/dist/index.cjs +719 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -3
- package/dist/index.d.ts +36 -3
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +693 -50
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -2
- package/dist/react.js.map +1 -1
- package/package.json +28 -11
- package/dist/chunk-WQCLEJWY.js.map +0 -1
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. 6 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,54 @@ 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
|
+
## OTC Private Orders
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
import { PAYMENT_PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
81
|
+
Restrict a deposit to a single taker wallet. Pass `otcTaker` and the deposit is created, delegated, and restricted in one call:
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
offramp
|
|
85
|
-
// [{ id: "revolut", name: "Revolut", currencies: ["USD","EUR",...], identifierLabel: "Revtag", helperText: "Revtag without @", ... }]
|
|
83
|
+
```typescript
|
|
84
|
+
import { offramp, PLATFORMS, CURRENCIES } from "@usdctofiat/offramp";
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
const { depositId, otcLink } = await offramp(walletClient, {
|
|
87
|
+
amount: "100",
|
|
88
|
+
platform: PLATFORMS.REVOLUT,
|
|
89
|
+
currency: CURRENCIES.EUR,
|
|
90
|
+
identifier: "alice",
|
|
91
|
+
otcTaker: "0xBuyerAddress",
|
|
92
|
+
});
|
|
93
|
+
// otcLink = "https://usdctofiat.xyz/deposit/0x.../362"
|
|
94
|
+
// Share otcLink with the buyer — they open it, connect their wallet, and fill the order.
|
|
95
|
+
```
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
offramp.getCurrencyInfo(CURRENCIES.EUR);
|
|
93
|
-
// { code: "EUR", name: "Euro", symbol: "€", countryCode: "eu" }
|
|
97
|
+
Toggle OTC on existing deposits:
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
```typescript
|
|
100
|
+
import { enableOtc, disableOtc, getOtcLink } from "@usdctofiat/offramp";
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
//
|
|
102
|
+
await enableOtc(walletClient, "362", "0xBuyerAddress");
|
|
103
|
+
await disableOtc(walletClient, "362"); // make public again
|
|
104
|
+
getOtcLink("362"); // just the URL, no tx
|
|
101
105
|
```
|
|
102
106
|
|
|
103
|
-
##
|
|
104
|
-
|
|
105
|
-
|
|
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 |
|
|
107
|
+
## Resumable
|
|
108
|
+
|
|
109
|
+
`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
110
|
|
|
118
111
|
## Error Handling
|
|
119
112
|
|
|
@@ -121,31 +114,18 @@ offramp.validateIdentifier(PAYMENT_PLATFORMS.REVOLUT, "@alice");
|
|
|
121
114
|
import { OfframpError } from "@usdctofiat/offramp";
|
|
122
115
|
|
|
123
116
|
try {
|
|
124
|
-
await offramp
|
|
117
|
+
await offramp(walletClient, params);
|
|
125
118
|
} catch (err) {
|
|
126
119
|
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
|
|
120
|
+
if (err.code === "USER_CANCELLED") return;
|
|
121
|
+
// For any failure: call offramp() again to resume
|
|
131
122
|
}
|
|
132
123
|
}
|
|
133
124
|
```
|
|
134
125
|
|
|
135
126
|
## How It Works
|
|
136
127
|
|
|
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
|
|
128
|
+
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
129
|
|
|
150
130
|
## Links
|
|
151
131
|
|