@sardis/ramp 0.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/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-01-27
9
+
10
+ ### Added
11
+
12
+ - Initial release of the Sardis Fiat Ramp SDK
13
+ - `SardisFiatRamp` class for fiat on/off ramp operations
14
+ - Wallet funding from fiat sources:
15
+ - Bank transfer (ACH) support
16
+ - Wire transfer support
17
+ - Card payment support
18
+ - Crypto deposit support
19
+ - Bank withdrawal (off-ramp) functionality:
20
+ - ACH payouts
21
+ - Policy validation before withdrawal
22
+ - Merchant fiat payments:
23
+ - Direct merchant payments in USD
24
+ - Approval workflow for high-value transactions
25
+ - Policy-based spending controls
26
+ - Transfer status tracking:
27
+ - Funding status monitoring
28
+ - Withdrawal status monitoring
29
+ - Full TypeScript support with exported types
30
+ - Error classes for precise error handling:
31
+ - `RampError` base class
32
+ - `PolicyViolation` for policy rejections
33
+ - Environment support (sandbox/production)
34
+ - Custom URL configuration for enterprise deployments
35
+
36
+ ### Features
37
+
38
+ - ESM and CommonJS bundle support
39
+ - Full TypeScript type definitions
40
+ - Integration with Bridge.xyz for fiat rails
41
+ - Multi-chain support (Base, Polygon, Ethereum, Arbitrum, Optimism)
42
+ - USDC as primary stablecoin
43
+
44
+ [0.1.0]: https://github.com/sardis-network/sardis/releases/tag/ramp-v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sardis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,466 @@
1
+ # Sardis Fiat Ramp SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@sardis/ramp.svg)](https://www.npmjs.com/package/@sardis/ramp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@sardis/ramp.svg)](https://www.npmjs.com/package/@sardis/ramp)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
+
8
+ Bridge crypto wallets to traditional banking with fiat on/off ramp functionality. Enable AI agents and applications to fund wallets from bank accounts and withdraw to fiat.
9
+
10
+ **Supports multiple providers:**
11
+ - **Onramper** - Aggregator with 100+ payment providers (Moonpay, Transak, Ramp, Simplex, etc.)
12
+ - **Bridge.xyz** - Direct integration for ACH/wire transfers
13
+
14
+ ## Table of Contents
15
+
16
+ - [Installation](#installation)
17
+ - [Quick Start](#quick-start)
18
+ - [Onramper Integration](#onramper-integration)
19
+ - [Bridge Integration](#bridge-integration)
20
+ - [API Reference](#api-reference)
21
+ - [Configuration](#configuration)
22
+ - [Error Handling](#error-handling)
23
+ - [TypeScript Support](#typescript-support)
24
+ - [License](#license)
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @sardis/ramp
30
+ # or
31
+ yarn add @sardis/ramp
32
+ # or
33
+ pnpm add @sardis/ramp
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ### Option 1: Onramper (Recommended)
39
+
40
+ Onramper aggregates 100+ payment providers, offering the best rates and widest coverage.
41
+
42
+ ```typescript
43
+ import { SardisOnramper } from '@sardis/ramp';
44
+
45
+ const onramper = new SardisOnramper({
46
+ apiKey: 'your-onramper-api-key',
47
+ sardisKey: 'your-sardis-api-key',
48
+ mode: 'production',
49
+ });
50
+
51
+ // Get widget URL to fund a Sardis wallet
52
+ const { widgetUrl } = await onramper.fundWallet({
53
+ walletId: 'wallet_123',
54
+ fiatAmount: 100,
55
+ fiatCurrency: 'USD',
56
+ });
57
+
58
+ // Open widget in new window or embed in iframe
59
+ window.open(widgetUrl, '_blank');
60
+
61
+ // Or get the best quote programmatically
62
+ const quote = await onramper.getBestQuote({
63
+ sourceCurrency: 'USD',
64
+ destinationCurrency: 'USDC',
65
+ amount: 100,
66
+ network: 'base',
67
+ });
68
+
69
+ console.log(`Best rate: $100 → ${quote.destinationAmount} USDC via ${quote.provider}`);
70
+ ```
71
+
72
+ ### Option 2: Bridge.xyz (Direct)
73
+
74
+ For direct ACH/wire transfers with predictable fees.
75
+
76
+ ```typescript
77
+ import { SardisFiatRamp } from '@sardis/ramp';
78
+
79
+ const ramp = new SardisFiatRamp({
80
+ sardisKey: 'your-sardis-api-key',
81
+ bridgeKey: 'your-bridge-api-key',
82
+ environment: 'sandbox',
83
+ });
84
+
85
+ // Fund a wallet from a bank account
86
+ const funding = await ramp.fundWallet({
87
+ walletId: 'wallet_123',
88
+ amountUsd: 100,
89
+ method: 'bank',
90
+ });
91
+
92
+ console.log('ACH Instructions:', funding.achInstructions);
93
+ console.log('Estimated arrival:', funding.estimatedArrival);
94
+ ```
95
+
96
+ ## Onramper Integration
97
+
98
+ ### Widget Integration
99
+
100
+ The easiest way to integrate fiat on-ramp is via the Onramper widget:
101
+
102
+ ```typescript
103
+ import { SardisOnramper } from '@sardis/ramp';
104
+
105
+ const onramper = new SardisOnramper({
106
+ apiKey: process.env.ONRAMPER_API_KEY,
107
+ sardisKey: process.env.SARDIS_API_KEY,
108
+ });
109
+
110
+ // Generate widget URL
111
+ const url = onramper.getWidgetUrl({
112
+ walletAddress: '0x...',
113
+ network: 'base',
114
+ fiatCurrency: 'USD',
115
+ cryptoCurrency: 'USDC',
116
+ fiatAmount: 100,
117
+ darkMode: true,
118
+ color: 'FF6B35', // Sardis orange
119
+ });
120
+
121
+ // Or get iframe HTML
122
+ const iframe = onramper.getWidgetIframe({
123
+ walletAddress: '0x...',
124
+ network: 'base',
125
+ fiatAmount: 100,
126
+ width: '400px',
127
+ height: '600px',
128
+ });
129
+ ```
130
+
131
+ ### Get Quotes
132
+
133
+ Compare rates from all providers:
134
+
135
+ ```typescript
136
+ // Get all quotes
137
+ const quotes = await onramper.getQuotes({
138
+ sourceCurrency: 'EUR',
139
+ destinationCurrency: 'USDC',
140
+ amount: 200,
141
+ network: 'base',
142
+ });
143
+
144
+ quotes.forEach(q => {
145
+ console.log(`${q.provider}: €200 → ${q.destinationAmount} USDC (fee: €${q.fees.total})`);
146
+ });
147
+
148
+ // Or get just the best quote
149
+ const best = await onramper.getBestQuote({
150
+ sourceCurrency: 'TRY',
151
+ destinationCurrency: 'USDC',
152
+ amount: 5000,
153
+ network: 'base',
154
+ });
155
+ ```
156
+
157
+ ### Supported Assets
158
+
159
+ ```typescript
160
+ // Get supported fiat currencies
161
+ const fiats = await onramper.getSupportedFiats();
162
+ // ['USD', 'EUR', 'GBP', 'TRY', ...]
163
+
164
+ // Get supported crypto on a network
165
+ const cryptos = await onramper.getSupportedCryptos('base');
166
+ // ['USDC', 'ETH', 'USDT', ...]
167
+
168
+ // Get payment methods for a country
169
+ const methods = await onramper.getSupportedPaymentMethods('TR');
170
+ // ['creditCard', 'bankTransfer', ...]
171
+ ```
172
+
173
+ ### Webhooks
174
+
175
+ Handle transaction updates:
176
+
177
+ ```typescript
178
+ // In your webhook handler
179
+ app.post('/webhooks/onramper', (req, res) => {
180
+ const signature = req.headers['x-onramper-signature'];
181
+
182
+ if (!onramper.verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET)) {
183
+ return res.status(401).send('Invalid signature');
184
+ }
185
+
186
+ const { event, transaction } = onramper.parseWebhookPayload(req.body);
187
+
188
+ if (event === 'transaction.completed') {
189
+ console.log(`Received ${transaction.destinationAmount} USDC`);
190
+ // Credit user account, send notification, etc.
191
+ }
192
+
193
+ res.status(200).send('OK');
194
+ });
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Bridge Integration
200
+
201
+ ### Fund Wallets (On-Ramp)
202
+
203
+ Fund Sardis wallets from fiat sources including bank transfers, wire transfers, and cards.
204
+
205
+ ```typescript
206
+ // Fund via bank transfer (ACH)
207
+ const bankFunding = await ramp.fundWallet({
208
+ walletId: 'wallet_123',
209
+ amountUsd: 500,
210
+ method: 'bank',
211
+ });
212
+
213
+ // Returns ACH deposit instructions
214
+ console.log(bankFunding.achInstructions);
215
+ // {
216
+ // accountNumber: '...',
217
+ // routingNumber: '...',
218
+ // bankName: '...',
219
+ // accountHolder: '...',
220
+ // reference: '...'
221
+ // }
222
+
223
+ // Fund via crypto (direct deposit)
224
+ const cryptoFunding = await ramp.fundWallet({
225
+ walletId: 'wallet_123',
226
+ amountUsd: 1000,
227
+ method: 'crypto',
228
+ });
229
+
230
+ console.log('Deposit to:', cryptoFunding.depositAddress);
231
+ console.log('Chain:', cryptoFunding.chain);
232
+ ```
233
+
234
+ ### Withdraw to Bank (Off-Ramp)
235
+
236
+ Withdraw funds from crypto wallets to traditional bank accounts.
237
+
238
+ ```typescript
239
+ const withdrawal = await ramp.withdrawToBank({
240
+ walletId: 'wallet_123',
241
+ amountUsd: 250,
242
+ bankAccount: {
243
+ accountHolderName: 'John Doe',
244
+ accountNumber: '1234567890',
245
+ routingNumber: '021000021',
246
+ accountType: 'checking', // or 'savings'
247
+ },
248
+ });
249
+
250
+ console.log('Transaction hash:', withdrawal.txHash);
251
+ console.log('Payout ID:', withdrawal.payoutId);
252
+ console.log('Estimated arrival:', withdrawal.estimatedArrival);
253
+ console.log('Fee:', withdrawal.fee);
254
+ ```
255
+
256
+ ### Pay Merchants in Fiat
257
+
258
+ Pay merchants and vendors in USD directly from crypto wallets.
259
+
260
+ ```typescript
261
+ const payment = await ramp.payMerchantFiat({
262
+ walletId: 'wallet_123',
263
+ amountUsd: 99.99,
264
+ merchant: {
265
+ name: 'ACME Corp',
266
+ bankAccount: {
267
+ accountHolderName: 'ACME Corp',
268
+ accountNumber: '9876543210',
269
+ routingNumber: '021000021',
270
+ },
271
+ category: 'software', // Optional: for policy validation
272
+ },
273
+ });
274
+
275
+ if (payment.status === 'completed') {
276
+ console.log('Payment ID:', payment.paymentId);
277
+ console.log('Merchant received:', payment.merchantReceived);
278
+ } else if (payment.status === 'pending_approval') {
279
+ console.log('Requires approval:', payment.approvalRequest);
280
+ }
281
+ ```
282
+
283
+ ### Check Transfer Status
284
+
285
+ Monitor the status of funding and withdrawal operations.
286
+
287
+ ```typescript
288
+ // Check funding status
289
+ const fundingStatus = await ramp.getFundingStatus('transfer_abc123');
290
+
291
+ // Check withdrawal status
292
+ const withdrawalStatus = await ramp.getWithdrawalStatus('payout_xyz789');
293
+ ```
294
+
295
+ ## API Reference
296
+
297
+ ### `SardisFiatRamp`
298
+
299
+ #### Constructor
300
+
301
+ ```typescript
302
+ new SardisFiatRamp(config: RampConfig)
303
+ ```
304
+
305
+ | Parameter | Type | Required | Description |
306
+ |-----------|------|----------|-------------|
307
+ | `sardisKey` | `string` | Yes | Your Sardis API key |
308
+ | `bridgeKey` | `string` | Yes | Your Bridge API key |
309
+ | `environment` | `'sandbox' \| 'production'` | No | Environment (default: sandbox) |
310
+ | `sardisUrl` | `string` | No | Custom Sardis API URL |
311
+ | `bridgeUrl` | `string` | No | Custom Bridge API URL |
312
+ | `timeout` | `number` | No | Request timeout in ms (default: 30000) |
313
+
314
+ #### Methods
315
+
316
+ | Method | Description |
317
+ |--------|-------------|
318
+ | `fundWallet(params)` | Fund a wallet from fiat sources |
319
+ | `withdrawToBank(params)` | Withdraw funds to a bank account |
320
+ | `payMerchantFiat(params)` | Pay a merchant in USD |
321
+ | `getWallet(walletId)` | Get wallet details |
322
+ | `getFundingStatus(transferId)` | Check funding transfer status |
323
+ | `getWithdrawalStatus(payoutId)` | Check withdrawal payout status |
324
+
325
+ ### Types
326
+
327
+ ```typescript
328
+ type FundingMethod = 'bank' | 'card' | 'crypto';
329
+
330
+ interface BankAccount {
331
+ accountHolderName: string;
332
+ accountNumber: string;
333
+ routingNumber: string;
334
+ accountType?: 'checking' | 'savings';
335
+ bankName?: string;
336
+ // For international wires
337
+ swiftCode?: string;
338
+ iban?: string;
339
+ bankAddress?: string;
340
+ }
341
+
342
+ interface FundingResult {
343
+ type: 'crypto' | 'fiat';
344
+ // For crypto deposits
345
+ depositAddress?: string;
346
+ chain?: string;
347
+ token?: string;
348
+ // For fiat deposits
349
+ paymentLink?: string;
350
+ achInstructions?: ACHDetails;
351
+ wireInstructions?: WireDetails;
352
+ estimatedArrival?: Date;
353
+ feePercent?: number;
354
+ transferId?: string;
355
+ }
356
+
357
+ interface WithdrawalResult {
358
+ txHash: string;
359
+ payoutId: string;
360
+ estimatedArrival: Date;
361
+ fee: number;
362
+ status: 'pending' | 'processing' | 'completed' | 'failed';
363
+ }
364
+
365
+ interface PaymentResult {
366
+ status: 'completed' | 'pending_approval' | 'failed';
367
+ paymentId?: string;
368
+ merchantReceived?: number;
369
+ fee?: number;
370
+ txHash?: string;
371
+ approvalRequest?: Record<string, unknown>;
372
+ error?: string;
373
+ }
374
+ ```
375
+
376
+ ## Configuration
377
+
378
+ ### Environment Variables
379
+
380
+ You can also configure the SDK using environment variables:
381
+
382
+ ```bash
383
+ SARDIS_API_KEY=your-sardis-key
384
+ BRIDGE_API_KEY=your-bridge-key
385
+ SARDIS_ENVIRONMENT=sandbox
386
+ ```
387
+
388
+ ### Custom URLs
389
+
390
+ For enterprise deployments or testing, you can specify custom API URLs:
391
+
392
+ ```typescript
393
+ const ramp = new SardisFiatRamp({
394
+ sardisKey: 'your-key',
395
+ bridgeKey: 'your-bridge-key',
396
+ sardisUrl: 'https://api.custom-sardis.example.com/v2',
397
+ bridgeUrl: 'https://api.custom-bridge.example.com/v0',
398
+ });
399
+ ```
400
+
401
+ ## Error Handling
402
+
403
+ The SDK provides typed errors for common failure cases:
404
+
405
+ ```typescript
406
+ import { SardisFiatRamp, RampError, PolicyViolation } from '@sardis/ramp';
407
+
408
+ try {
409
+ const result = await ramp.withdrawToBank({
410
+ walletId: 'wallet_123',
411
+ amountUsd: 10000,
412
+ bankAccount: { ... },
413
+ });
414
+ } catch (error) {
415
+ if (error instanceof PolicyViolation) {
416
+ console.error('Policy violation:', error.message);
417
+ // Handle policy rejection (e.g., spending limit exceeded)
418
+ } else if (error instanceof RampError) {
419
+ console.error(`Ramp error [${error.code}]:`, error.message);
420
+ // Handle other ramp-specific errors
421
+ } else {
422
+ console.error('Unexpected error:', error);
423
+ }
424
+ }
425
+ ```
426
+
427
+ ### Error Types
428
+
429
+ | Error | Description |
430
+ |-------|-------------|
431
+ | `RampError` | Base error class for all ramp errors |
432
+ | `PolicyViolation` | Payment violates wallet spending policy |
433
+
434
+ ## TypeScript Support
435
+
436
+ This package is written in TypeScript and exports all types:
437
+
438
+ ```typescript
439
+ import type {
440
+ RampConfig,
441
+ FundingMethod,
442
+ FundingResult,
443
+ WithdrawalResult,
444
+ PaymentResult,
445
+ BankAccount,
446
+ MerchantAccount,
447
+ ACHDetails,
448
+ WireDetails,
449
+ Wallet,
450
+ } from '@sardis/ramp';
451
+ ```
452
+
453
+ ## Requirements
454
+
455
+ - Node.js 18.0.0 or higher
456
+ - TypeScript 4.7+ (optional, for type definitions)
457
+
458
+ ## Support
459
+
460
+ - [Documentation](https://docs.sardis.network)
461
+ - [GitHub Issues](https://github.com/sardis-network/sardis/issues)
462
+ - [Discord Community](https://discord.gg/sardis)
463
+
464
+ ## License
465
+
466
+ MIT - see [LICENSE](./LICENSE) for details.