paj_ramp 1.2.4 → 1.2.6
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 +204 -295
- package/dist/lib/direct_off_ramp/directCreateOrder.d.ts +1 -1
- package/dist/lib/off_ramp/getRate.d.ts +67 -45
- package/dist/lib/off_ramp/getRate.js +69 -57
- package/dist/sdk.d.ts +2 -1
- package/dist/sdk.js +3 -1
- package/lib/direct_off_ramp/directCreateOrder.ts +1 -1
- package/lib/off_ramp/getRate.ts +95 -68
- package/package.json +1 -1
- package/sdk.ts +5 -1
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# PAJ Ramp SDK
|
|
2
2
|
|
|
3
|
-
A comprehensive SDK for PAJ Ramp onramp and offramp operations with real-time transaction updates using
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Onramp Operations**: Create orders and observe real-time updates
|
|
8
|
-
- **Offramp Operations**: Complete offramp workflow with bank account management
|
|
9
|
-
- **Real-time Updates**: Socket.IO integration for live transaction status updates
|
|
10
|
-
- **TypeScript Support**: Full TypeScript definitions included
|
|
11
|
-
- **Functional API**: Clean functional approach for better composability
|
|
3
|
+
A comprehensive SDK for PAJ Ramp onramp and offramp operations with real-time transaction updates using webhooks.
|
|
12
4
|
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
@@ -20,9 +12,9 @@ npm install paj_ramp
|
|
|
20
12
|
yarn add paj_ramp
|
|
21
13
|
```
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
## Getting Started
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
### Initialize SDK (select environment: "staging" | "production")
|
|
26
18
|
|
|
27
19
|
```typescript
|
|
28
20
|
import { initializeSDK } from 'paj_ramp';
|
|
@@ -31,10 +23,208 @@ import { initializeSDK } from 'paj_ramp';
|
|
|
31
23
|
initializeSDK('staging'); // or production
|
|
32
24
|
```
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
### Initiate Session
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { initiate } from 'paj_ramp';
|
|
30
|
+
|
|
31
|
+
const initiated = await initiate('your_email@gmail.com', 'business_api_key');
|
|
32
|
+
// Response: { email: string }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Verify Session
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { verify } from 'paj_ramp';
|
|
39
|
+
|
|
40
|
+
const verified = await verify(
|
|
41
|
+
'your_email@gmail.com',
|
|
42
|
+
'otp',
|
|
43
|
+
{
|
|
44
|
+
uuid: string,
|
|
45
|
+
device: string,
|
|
46
|
+
//optionL ↓↓↓↓↓
|
|
47
|
+
os: string, //IOS
|
|
48
|
+
browser: string, //chrome
|
|
49
|
+
ip: string,
|
|
50
|
+
},
|
|
51
|
+
'business_api_key'
|
|
52
|
+
);
|
|
53
|
+
// Response: { email: string, isActive: string, expiresAt: string, token: string }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Utility Endpoints
|
|
57
|
+
|
|
58
|
+
### Handle Rate:
|
|
59
|
+
|
|
60
|
+
**_Get All Rate_**
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { getRate } from 'paj_ramp';
|
|
64
|
+
|
|
65
|
+
const rate = await getRate();
|
|
66
|
+
/*
|
|
67
|
+
Response:
|
|
68
|
+
{
|
|
69
|
+
"onRampRate": {
|
|
70
|
+
"baseCurrency": "USD",
|
|
71
|
+
"targetCurrency": "NGN",
|
|
72
|
+
"isActive": true,
|
|
73
|
+
"rate": 1510,
|
|
74
|
+
"type": "onRamp"
|
|
75
|
+
},
|
|
76
|
+
"offRampRate": {
|
|
77
|
+
"baseCurrency": "USD",
|
|
78
|
+
"targetCurrency": "NGN",
|
|
79
|
+
"isActive": true,
|
|
80
|
+
"rate": 1525,
|
|
81
|
+
"type": "offRamp"
|
|
82
|
+
}
|
|
83
|
+
}*/
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**_Get Rate by Amount_**
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { getRate } from 'paj_ramp';
|
|
90
|
+
|
|
91
|
+
const rate = await getRate(50000);
|
|
92
|
+
/*
|
|
93
|
+
Response:
|
|
94
|
+
{
|
|
95
|
+
rate: {
|
|
96
|
+
baseCurrency: string,
|
|
97
|
+
targetCurrency: string,
|
|
98
|
+
rate: number
|
|
99
|
+
},
|
|
100
|
+
amounts: {
|
|
101
|
+
userTax": number,
|
|
102
|
+
merchantTax": number,
|
|
103
|
+
amountUSD": number,
|
|
104
|
+
userAmountFiat": number
|
|
105
|
+
}
|
|
106
|
+
}*/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**_Get Rate by Rate Type_**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { getRate, RateType } from 'paj_ramp';
|
|
113
|
+
|
|
114
|
+
const rate = await getRate(RateType.offRamp); // or RateType.onRamp
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
Response:
|
|
118
|
+
"offRampRate": {
|
|
119
|
+
"baseCurrency": "USD",
|
|
120
|
+
"targetCurrency": "NGN",
|
|
121
|
+
"isActive": true,
|
|
122
|
+
"rate": 1525,
|
|
123
|
+
"type": "offRamp"
|
|
124
|
+
}*/
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**_Get Token Value from Amount and Mint Token_**
|
|
35
128
|
|
|
36
|
-
|
|
129
|
+
```typescript
|
|
130
|
+
import { getRate } from 'paj_ramp';
|
|
131
|
+
|
|
132
|
+
const tokenValue = await getRate(50000, 'token_mint_address');
|
|
133
|
+
/*
|
|
134
|
+
Response:
|
|
135
|
+
{
|
|
136
|
+
amount: number, // requested token amount
|
|
137
|
+
usdcValue: number, // USDC value of the token amount
|
|
138
|
+
mint: string // token mint address
|
|
139
|
+
}
|
|
140
|
+
*/
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Handle Banks:
|
|
144
|
+
|
|
145
|
+
**_Get Banks_**
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { getBanks } from 'paj_ramp';
|
|
149
|
+
|
|
150
|
+
const banks = await getBanks('token');
|
|
151
|
+
// Response: [ { id: string, name: string, country: string } ]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**_Resolve Bank Account_**
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { resolveBankAccount } from 'paj_ramp';
|
|
158
|
+
|
|
159
|
+
const resolvedBankAccount = await resolveBankAccount(
|
|
160
|
+
'token',
|
|
161
|
+
'bank_id',
|
|
162
|
+
'account_number'
|
|
163
|
+
);
|
|
164
|
+
// Response: { accountName: string, accountNumber: string, bank: { id: string, name: string, code: string, country: string } }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**_Add Bank Account_**
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { addBankAccount } from 'paj_ramp';
|
|
171
|
+
|
|
172
|
+
const addedBankAccount = await addBankAccount(
|
|
173
|
+
'token',
|
|
174
|
+
'bank_id',
|
|
175
|
+
'account_number'
|
|
176
|
+
);
|
|
177
|
+
// Response: { id: string, accountName: string, accountNumber: string, bank: string }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**_Get Bank Accounts_**
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { getBankAccounts } from 'paj_ramp';
|
|
184
|
+
|
|
185
|
+
const accounts = await getBankAccounts('token');
|
|
186
|
+
// Response: [ { id: string, accountName: string, accountNumber: string, bank: string } ]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Offramp Webhook (Direct Offramp)
|
|
37
190
|
|
|
191
|
+
### Usage Example
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { offRampCreateOrder } from 'paj_ramp';
|
|
195
|
+
|
|
196
|
+
const createOrder = await offRampCreateOrder(
|
|
197
|
+
'token',
|
|
198
|
+
'bank_id',
|
|
199
|
+
'account_number',
|
|
200
|
+
'NGN', // Currency
|
|
201
|
+
10000, // amount
|
|
202
|
+
'token_mint_address'
|
|
203
|
+
'webhook_url'
|
|
204
|
+
);
|
|
205
|
+
// Response: { id: string, address: string, signature?: string, mint: string, currency: Currency, amount: number, usdcAmount: number, fiatAmount: number, sender: string, receipiant: string, rate: number, status: TransactionStatus, transactionType: TransactionType }
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Onramp Webhook: Creates a new onramp order and sends status to the webhook url.
|
|
209
|
+
|
|
210
|
+
### Usage Example
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { createOrder } from 'paj_ramp';
|
|
214
|
+
|
|
215
|
+
const order = await createOrder({
|
|
216
|
+
fiatAmount: 10000,
|
|
217
|
+
currency: 'NGN',
|
|
218
|
+
recipient: 'wallet_address_here',
|
|
219
|
+
mint: 'token_mint_address_here',
|
|
220
|
+
chain: 'SOLANA', //ethereum, polygon, etc
|
|
221
|
+
webhookURL: 'your_webhook_url',
|
|
222
|
+
token: 'token_from_verification',
|
|
223
|
+
});
|
|
224
|
+
// Response: { id: string, accountNumber: string, accountName: string, fiatAmount: number, bank: string }
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
<!--
|
|
38
228
|
## Quick Start
|
|
39
229
|
|
|
40
230
|
### Real-time Order Observation
|
|
@@ -142,45 +332,6 @@ Common error messages:
|
|
|
142
332
|
- `"Connection failed"`
|
|
143
333
|
- `"Socket timeout"`
|
|
144
334
|
|
|
145
|
-
### createOrder(orderData)
|
|
146
|
-
|
|
147
|
-
Creates a new onramp order.
|
|
148
|
-
|
|
149
|
-
**Parameters:**
|
|
150
|
-
|
|
151
|
-
- `orderData` (object, required): Order creation data
|
|
152
|
-
- `orderData.fiatAmount` (number, required): Order amount
|
|
153
|
-
- `orderData.currency` (string, required): Currency code (e.g., 'USD', 'NGN')
|
|
154
|
-
- `orderData.recipient` (string, required): Wallet address to receive tokens
|
|
155
|
-
- `orderData.mint` (string, required): Token mint address
|
|
156
|
-
- `orderData.chain` (Chain, required): Blockchain network ('solana', 'ethereum', 'polygon')
|
|
157
|
-
- `orderData.token` (string, required): Verification token
|
|
158
|
-
|
|
159
|
-
**Returns:**
|
|
160
|
-
|
|
161
|
-
- `id` (string): Unique order identifier
|
|
162
|
-
- `accountNumber` (string): Bank account number for payment
|
|
163
|
-
- `accountName` (string): Bank account holder name
|
|
164
|
-
- `fiatAmount` (number): Order amount in fiat currency
|
|
165
|
-
- `bank` (string): Bank name
|
|
166
|
-
|
|
167
|
-
**Example:**
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
import { createOrder } from 'paj_ramp';
|
|
171
|
-
|
|
172
|
-
const order = await createOrder({
|
|
173
|
-
fiatAmount: 10000,
|
|
174
|
-
currency: 'NGN',
|
|
175
|
-
recipient: 'wallet_address_here',
|
|
176
|
-
mint: 'token_mint_address_here',
|
|
177
|
-
chain: 'SOLANA',
|
|
178
|
-
webhookURL: 'webhook_url',
|
|
179
|
-
token: 'token_from_verification',
|
|
180
|
-
});
|
|
181
|
-
// Response: { id: string, accountNumber: string, accountName: string, fiatAmount: number, bank: string }
|
|
182
|
-
```
|
|
183
|
-
|
|
184
335
|
### Usage Example
|
|
185
336
|
|
|
186
337
|
```typescript
|
|
@@ -240,251 +391,9 @@ const order = await createOrder({
|
|
|
240
391
|
|
|
241
392
|
await example(order.id);
|
|
242
393
|
// Response: { id: string, fiatAmount: string, currency: string, , recipient: string, mint: string, chain: Chain, amount: number, status: OnRampStatus }
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
---
|
|
246
|
-
|
|
247
|
-
# Offramp SDK
|
|
248
|
-
|
|
249
|
-
## Overview
|
|
250
|
-
|
|
251
|
-
The Offramp SDK provides a set of functions to help users convert Solana-based digital assets to fiat and transfer the resulting funds to traditional bank accounts. It includes session management, rate queries, bank account management, and wallet operations.
|
|
252
|
-
|
|
253
|
-
## Usage Examples
|
|
254
|
-
|
|
255
|
-
<!-- ### Get TX Pool Address
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
import { getTXPoolAddress } from "paj_ramp";
|
|
259
|
-
|
|
260
|
-
const txpooladdress = await getTXPoolAddress();
|
|
261
|
-
// Response: { address: string }
|
|
262
394
|
``` -->
|
|
263
395
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
import { getRate } from 'paj_ramp';
|
|
268
|
-
|
|
269
|
-
const rate = await getRate();
|
|
270
|
-
/*
|
|
271
|
-
Response:
|
|
272
|
-
{
|
|
273
|
-
"onRampRate": {
|
|
274
|
-
"baseCurrency": "USD",
|
|
275
|
-
"targetCurrency": "NGN",
|
|
276
|
-
"isActive": true,
|
|
277
|
-
"rate": 1510,
|
|
278
|
-
"type": "onRamp"
|
|
279
|
-
},
|
|
280
|
-
"offRampRate": {
|
|
281
|
-
"baseCurrency": "USD",
|
|
282
|
-
"targetCurrency": "NGN",
|
|
283
|
-
"isActive": true,
|
|
284
|
-
"rate": 1525,
|
|
285
|
-
"type": "offRamp"
|
|
286
|
-
}
|
|
287
|
-
}*/
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Get Rate by Amount
|
|
291
|
-
|
|
292
|
-
```typescript
|
|
293
|
-
import { getRate } from 'paj_ramp';
|
|
294
|
-
|
|
295
|
-
const rate = await getRate(50000);
|
|
296
|
-
/*
|
|
297
|
-
Response:
|
|
298
|
-
{
|
|
299
|
-
rate: {
|
|
300
|
-
baseCurrency: string,
|
|
301
|
-
targetCurrency: string,
|
|
302
|
-
rate: number
|
|
303
|
-
},
|
|
304
|
-
amounts: {
|
|
305
|
-
userTax": number,
|
|
306
|
-
merchantTax": number,
|
|
307
|
-
amountUSD": number,
|
|
308
|
-
userAmountFiat": number
|
|
309
|
-
}
|
|
310
|
-
}*/
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Get Rate by Rate Type
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
import { getRate, RateType } from 'paj_ramp';
|
|
317
|
-
|
|
318
|
-
const rate = await getRate(RateType.offRamp); // or RateType.onRamp
|
|
319
|
-
|
|
320
|
-
/*
|
|
321
|
-
Response:
|
|
322
|
-
"offRampRate": {
|
|
323
|
-
"baseCurrency": "USD",
|
|
324
|
-
"targetCurrency": "NGN",
|
|
325
|
-
"isActive": true,
|
|
326
|
-
"rate": 1525,
|
|
327
|
-
"type": "offRamp"
|
|
328
|
-
}*/
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### Initiate Session
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
import { initiate } from 'paj_ramp';
|
|
335
|
-
|
|
336
|
-
const initiated = await initiate('your_email@gmail.com', 'business_api_key');
|
|
337
|
-
// Response: { email: string }
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
### Verify Session
|
|
341
|
-
|
|
342
|
-
```typescript
|
|
343
|
-
import { verify } from 'paj_ramp';
|
|
344
|
-
|
|
345
|
-
const verified = await verify(
|
|
346
|
-
'your_email@gmail.com',
|
|
347
|
-
'otp',
|
|
348
|
-
{
|
|
349
|
-
uuid: string,
|
|
350
|
-
device: string,
|
|
351
|
-
//optionL ↓↓↓↓↓
|
|
352
|
-
os: string, //IOS
|
|
353
|
-
browser: string, //chrome
|
|
354
|
-
ip: string,
|
|
355
|
-
},
|
|
356
|
-
'business_api_key'
|
|
357
|
-
);
|
|
358
|
-
// Response: { email: string, isActive: string, expiresAt: string, token: string }
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### Get Banks
|
|
362
|
-
|
|
363
|
-
```typescript
|
|
364
|
-
import { getBanks } from 'paj_ramp';
|
|
365
|
-
|
|
366
|
-
const banks = await getBanks('token');
|
|
367
|
-
// Response: [ { id: string, name: string, country: string } ]
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
### Resolve Bank Account
|
|
371
|
-
|
|
372
|
-
```typescript
|
|
373
|
-
import { resolveBankAccount } from 'paj_ramp';
|
|
374
|
-
|
|
375
|
-
const resolvedBankAccount = await resolveBankAccount(
|
|
376
|
-
'token',
|
|
377
|
-
'bank_id',
|
|
378
|
-
'account_number'
|
|
379
|
-
);
|
|
380
|
-
// Response: { accountName: string, accountNumber: string, bank: { id: string, name: string, code: string, country: string } }
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
### Add Bank Account
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
import { addBankAccount } from 'paj_ramp';
|
|
387
|
-
|
|
388
|
-
const addedBankAccount = await addBankAccount(
|
|
389
|
-
'token',
|
|
390
|
-
'bank_id',
|
|
391
|
-
'account_number'
|
|
392
|
-
);
|
|
393
|
-
// Response: { id: string, accountName: string, accountNumber: string, bank: string }
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### Get Bank Accounts
|
|
397
|
-
|
|
398
|
-
```typescript
|
|
399
|
-
import { getBankAccounts } from 'paj_ramp';
|
|
400
|
-
|
|
401
|
-
const accounts = await getBankAccounts('token');
|
|
402
|
-
// Response: [ { id: string, accountName: string, accountNumber: string, bank: string } ]
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
# Offramp 2 (Direct Offramp)
|
|
406
|
-
|
|
407
|
-
## Usage Examples
|
|
408
|
-
|
|
409
|
-
### Create Order
|
|
410
|
-
|
|
411
|
-
```typescript
|
|
412
|
-
import { offRampCreateOrder } from 'paj_ramp';
|
|
413
|
-
|
|
414
|
-
const createOrder = await offRampCreateOrder(
|
|
415
|
-
'token',
|
|
416
|
-
'bank_id',
|
|
417
|
-
'account_number',
|
|
418
|
-
'NGN', // Currency
|
|
419
|
-
10000, // amount
|
|
420
|
-
'token_mint_address'
|
|
421
|
-
'webhook_url'
|
|
422
|
-
);
|
|
423
|
-
// Response: { id: string, address: string, signature?: string, mint: string, currency: Currency, amount: number, usdcAmount: number, fiatAmount: number, sender: string, receipiant: string, rate: number, status: TransactionStatus, transactionType: TransactionType }
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
<!--
|
|
427
|
-
### Get Wallet Info
|
|
428
|
-
|
|
429
|
-
```typescript
|
|
430
|
-
import { getWallet } from 'paj_ramp';
|
|
431
|
-
|
|
432
|
-
const wallet = await getWallet('wallet public key');
|
|
433
|
-
// Response: { id: string, publicKey: string, bankAccount: { id: string, accountName: string, accountNumber: string, bank: string } }
|
|
434
|
-
``` -->
|
|
435
|
-
<!--
|
|
436
|
-
### Add Wallet
|
|
437
|
-
|
|
438
|
-
```typescript
|
|
439
|
-
import { addWallet } from 'paj_ramp';
|
|
440
|
-
|
|
441
|
-
// To create wallet.json file with an array of 64 numbers
|
|
442
|
-
// npm install @solana/web3.js then run this code
|
|
443
|
-
import { Keypair } from '@solana/web3.js';
|
|
444
|
-
import fs from 'fs';
|
|
445
|
-
|
|
446
|
-
const keypair = Keypair.generate();
|
|
447
|
-
const secretKey = Array.from(keypair.secretKey);
|
|
448
|
-
|
|
449
|
-
fs.writeFileSync('wallet.json', JSON.stringify(secretKey));
|
|
450
|
-
console.log('✅ wallets.json generated successfully');
|
|
451
|
-
|
|
452
|
-
// To get secret key
|
|
453
|
-
import * as fs from 'fs';
|
|
454
|
-
import { fileURLToPath } from 'url';
|
|
455
|
-
import { dirname, resolve } from 'path';
|
|
456
|
-
|
|
457
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
458
|
-
const __dirname = dirname(__filename);
|
|
459
|
-
|
|
460
|
-
// wallet.json that you created with an array of 64 numbers
|
|
461
|
-
const walletPath = resolve(__dirname, './wallet.json');
|
|
462
|
-
const secretKeyRaw = fs.readFileSync(walletPath, 'utf8');
|
|
463
|
-
const secretKeyArray = JSON.parse(secretKeyRaw);
|
|
464
|
-
|
|
465
|
-
if (!Array.isArray(secretKeyArray) || secretKeyArray.length !== 64) {
|
|
466
|
-
throw new Error('Invalid secret key: must be an array of 64 numbers.');
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const secretKey = Uint8Array.from(secretKeyArray);
|
|
470
|
-
|
|
471
|
-
const addedWallet = await addWallet('token', 'bank account id', secretKey);
|
|
472
|
-
// Response: { id: string, publicKey: string, bankAccount: { id: string, accountName: string, accountNumber: string, bank: string } }
|
|
473
|
-
``` -->
|
|
474
|
-
<!--
|
|
475
|
-
### Switch Bank Account on Wallet
|
|
476
|
-
|
|
477
|
-
```typescript
|
|
478
|
-
import { switchWalletBankAccount } from 'paj_ramp';
|
|
479
|
-
|
|
480
|
-
const switchedWallet = await switchWalletBankAccount(
|
|
481
|
-
'token',
|
|
482
|
-
'bank account id to switch to',
|
|
483
|
-
'wallet id',
|
|
484
|
-
'secret key'
|
|
485
|
-
);
|
|
486
|
-
// Response: { id: string, publicKey: string, bankAccount: { id: string, accountName: string, accountNumber: string, bank: string } }
|
|
487
|
-
``` -->
|
|
396
|
+
---
|
|
488
397
|
|
|
489
398
|
## License
|
|
490
399
|
|
|
@@ -15,5 +15,5 @@ type offRampCreateOrderResponse = {
|
|
|
15
15
|
status: string;
|
|
16
16
|
webhookURL: string;
|
|
17
17
|
};
|
|
18
|
-
export declare const offRampCreateOrder: (token: string, bank: string, accountNumber: string, currency:
|
|
18
|
+
export declare const offRampCreateOrder: (token: string, bank: string, accountNumber: string, currency: string, amount: number, mint: string, webhookURL: string) => Promise<offRampCreateOrderResponse>;
|
|
19
19
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
type AllRateResponseType = {
|
|
2
2
|
onRampRate: {
|
|
3
|
-
baseCurrency:
|
|
4
|
-
targetCurrency:
|
|
3
|
+
baseCurrency: 'USD';
|
|
4
|
+
targetCurrency: 'NGN';
|
|
5
5
|
isActive: true;
|
|
6
6
|
rate: 1510;
|
|
7
|
-
type:
|
|
7
|
+
type: 'onRamp';
|
|
8
8
|
};
|
|
9
9
|
offRampRate: {
|
|
10
|
-
baseCurrency:
|
|
11
|
-
targetCurrency:
|
|
10
|
+
baseCurrency: 'USD';
|
|
11
|
+
targetCurrency: 'NGN';
|
|
12
12
|
isActive: true;
|
|
13
13
|
rate: 1525;
|
|
14
|
-
type:
|
|
14
|
+
type: 'offRamp';
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
type RateByAmountType = {
|
|
@@ -28,58 +28,80 @@ type RateByAmountType = {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
type RateByRateTypeType = {
|
|
31
|
-
baseCurrency:
|
|
32
|
-
targetCurrency:
|
|
31
|
+
baseCurrency: 'USD';
|
|
32
|
+
targetCurrency: 'NGN';
|
|
33
33
|
isActive: true;
|
|
34
34
|
rate: 1525;
|
|
35
|
-
type:
|
|
35
|
+
type: 'offRamp';
|
|
36
|
+
};
|
|
37
|
+
type TokenValueType = {
|
|
38
|
+
amount: number;
|
|
39
|
+
usdcValue: number;
|
|
40
|
+
mint: string;
|
|
36
41
|
};
|
|
37
42
|
export declare enum RateType {
|
|
38
43
|
onRamp = "onRamp",
|
|
39
44
|
offRamp = "offRamp"
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
* The function `getRate` in TypeScript is an asynchronous function that retrieves rate information
|
|
48
|
+
* based on different parameters such as amount, rate type, and mint token.
|
|
49
|
+
* @param {number | RateType} param - The `param` parameter in the `getRate` function can be either a
|
|
50
|
+
* number or a `RateType`.
|
|
51
|
+
* @param {string} [mint_token] - The `mint_token` parameter is an optional string parameter that
|
|
52
|
+
* represents a token used for minting. It is used in the `getRate` function to calculate the rate
|
|
53
|
+
* based on the specified token value.
|
|
54
|
+
* @returns The `getRate` function returns different values based on the conditions inside the
|
|
55
|
+
* function:
|
|
56
|
+
*/
|
|
57
|
+
export declare const getRate: (param: number | RateType, mint_token?: string) => Promise<AllRateResponseType | RateByAmountType | RateByRateTypeType | TokenValueType | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* The function `getAllRate` fetches all rates from a specified URL and handles any errors that occur
|
|
60
|
+
* during the process.
|
|
61
|
+
* @param {string} url - The `url` parameter in the `getAllRate` function is a string representing the
|
|
62
|
+
* URL from which the rate data will be fetched.
|
|
63
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
64
|
+
* function call, which is fetching rate data from the specified URL. If successful, it will return the
|
|
65
|
+
* rate data. If an error occurs during the fetching process, it will log the error message and rethrow
|
|
66
|
+
* the error.
|
|
53
67
|
*/
|
|
54
|
-
export declare const
|
|
68
|
+
export declare const getAllRate: (url: string) => Promise<AllRateResponseType>;
|
|
55
69
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* A promise resolving to the rate and amount details for the specified value.
|
|
65
|
-
*
|
|
66
|
-
* Raises:
|
|
67
|
-
* Throws an error if the rate information cannot be fetched.
|
|
70
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount from a given URL.
|
|
71
|
+
* @param {string} url - The `url` parameter is a string that represents the URL endpoint where the
|
|
72
|
+
* rate information is fetched from.
|
|
73
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
74
|
+
* representing the amount for which you want to fetch the rate. This amount will be used in the URL to
|
|
75
|
+
* make a request to the specified endpoint to get the rate information for that specific amount.
|
|
76
|
+
* @returns The function `getRateByAmount` is returning a Promise that resolves to a `RateByAmountType`
|
|
77
|
+
* object fetched from the specified URL with the provided amount.
|
|
68
78
|
*/
|
|
69
79
|
export declare const getRateByAmount: (url: string, amount: number) => Promise<RateByAmountType>;
|
|
70
80
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* Returns:
|
|
79
|
-
* A promise resolving to the rate details for the specified rate type.
|
|
80
|
-
*
|
|
81
|
-
* Raises:
|
|
82
|
-
* Throws an error if the rate information cannot be fetched.
|
|
81
|
+
* The function `getRateByRateType` fetches a rate based on a specified rate type from a given URL.
|
|
82
|
+
* @param {string} url - The `url` parameter is a string representing the base URL used to fetch data.
|
|
83
|
+
* @param {RateType} rateType - RateType is a type that represents the different types of rates that
|
|
84
|
+
* can be fetched. It is used as a parameter in the getRateByRateType function to specify the type of
|
|
85
|
+
* rate to retrieve from the provided URL.
|
|
86
|
+
* @returns The `getRateByRateType` function is returning a Promise that resolves to a
|
|
87
|
+
* `RateByRateTypeType` object fetched from the specified URL with the provided rate type.
|
|
83
88
|
*/
|
|
84
89
|
export declare const getRateByRateType: (url: string, rateType: RateType) => Promise<RateByRateTypeType>;
|
|
90
|
+
/**
|
|
91
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the provided URL,
|
|
92
|
+
* amount, and mint token.
|
|
93
|
+
* @param {string} url - The `url` parameter is a string representing the base URL for the API endpoint
|
|
94
|
+
* where you can fetch the token value.
|
|
95
|
+
* @param {number} amount - The `amount` parameter in the `getTokenValue` function represents the
|
|
96
|
+
* quantity or number of tokens for which you want to retrieve the value. It is a numeric value
|
|
97
|
+
* (number) indicating the amount of tokens for which you are querying the value.
|
|
98
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
99
|
+
* the unique identifier for a specific token. It is used to specify which token's value you want to
|
|
100
|
+
* retrieve based on the provided `amount`.
|
|
101
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function called with the
|
|
102
|
+
* URL `/value?amount=&mint=`. The `get` function is likely making an HTTP
|
|
103
|
+
* request to that URL to fetch some data. The return value is expected to be of type `TokenValueType`.
|
|
104
|
+
* If an error occurs during the fetch operation, an error message will
|
|
105
|
+
*/
|
|
106
|
+
export declare const getTokenValue: (url: string, amount: number, mint_token: string) => Promise<TokenValueType | undefined>;
|
|
85
107
|
export {};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { get } from
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
2
|
export var RateType;
|
|
3
3
|
(function (RateType) {
|
|
4
4
|
RateType["onRamp"] = "onRamp";
|
|
5
5
|
RateType["offRamp"] = "offRamp";
|
|
6
6
|
})(RateType || (RateType = {}));
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Raises:
|
|
18
|
-
* Throws an error if the rate information cannot be fetched.
|
|
8
|
+
* The function `getRate` in TypeScript is an asynchronous function that retrieves rate information
|
|
9
|
+
* based on different parameters such as amount, rate type, and mint token.
|
|
10
|
+
* @param {number | RateType} param - The `param` parameter in the `getRate` function can be either a
|
|
11
|
+
* number or a `RateType`.
|
|
12
|
+
* @param {string} [mint_token] - The `mint_token` parameter is an optional string parameter that
|
|
13
|
+
* represents a token used for minting. It is used in the `getRate` function to calculate the rate
|
|
14
|
+
* based on the specified token value.
|
|
15
|
+
* @returns The `getRate` function returns different values based on the conditions inside the
|
|
16
|
+
* function:
|
|
19
17
|
*/
|
|
20
|
-
export const getRate = async (param) => {
|
|
18
|
+
export const getRate = async (param, mint_token) => {
|
|
21
19
|
try {
|
|
22
|
-
const url =
|
|
20
|
+
const url = '/pub/rate';
|
|
23
21
|
if (!param) {
|
|
24
22
|
return getAllRate(url);
|
|
25
23
|
}
|
|
26
|
-
else if (typeof param ===
|
|
24
|
+
else if (typeof param === 'number') {
|
|
25
|
+
if (mint_token)
|
|
26
|
+
return getTokenValue(url, param, mint_token);
|
|
27
27
|
return getRateByAmount(url, param);
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
@@ -31,75 +31,87 @@ export const getRate = async (param) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
catch (err) {
|
|
34
|
-
console.error(
|
|
34
|
+
console.error('Error fetching Rate:', err);
|
|
35
35
|
throw err;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Raises:
|
|
49
|
-
* Throws an error if the rate information cannot be fetched.
|
|
39
|
+
* The function `getAllRate` fetches all rates from a specified URL and handles any errors that occur
|
|
40
|
+
* during the process.
|
|
41
|
+
* @param {string} url - The `url` parameter in the `getAllRate` function is a string representing the
|
|
42
|
+
* URL from which the rate data will be fetched.
|
|
43
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
44
|
+
* function call, which is fetching rate data from the specified URL. If successful, it will return the
|
|
45
|
+
* rate data. If an error occurs during the fetching process, it will log the error message and rethrow
|
|
46
|
+
* the error.
|
|
50
47
|
*/
|
|
51
|
-
const getAllRate = async (url) => {
|
|
48
|
+
export const getAllRate = async (url) => {
|
|
52
49
|
try {
|
|
53
50
|
return await get(url);
|
|
54
51
|
}
|
|
55
52
|
catch (err) {
|
|
56
|
-
console.error(
|
|
53
|
+
console.error('Error fetching Rate:', err);
|
|
57
54
|
throw err;
|
|
58
55
|
}
|
|
59
56
|
};
|
|
60
57
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* A promise resolving to the rate and amount details for the specified value.
|
|
70
|
-
*
|
|
71
|
-
* Raises:
|
|
72
|
-
* Throws an error if the rate information cannot be fetched.
|
|
58
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount from a given URL.
|
|
59
|
+
* @param {string} url - The `url` parameter is a string that represents the URL endpoint where the
|
|
60
|
+
* rate information is fetched from.
|
|
61
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
62
|
+
* representing the amount for which you want to fetch the rate. This amount will be used in the URL to
|
|
63
|
+
* make a request to the specified endpoint to get the rate information for that specific amount.
|
|
64
|
+
* @returns The function `getRateByAmount` is returning a Promise that resolves to a `RateByAmountType`
|
|
65
|
+
* object fetched from the specified URL with the provided amount.
|
|
73
66
|
*/
|
|
74
67
|
export const getRateByAmount = async (url, amount) => {
|
|
75
68
|
try {
|
|
76
|
-
return await get(
|
|
69
|
+
return await get(`${url}/${amount}`);
|
|
77
70
|
}
|
|
78
71
|
catch (err) {
|
|
79
|
-
console.error(
|
|
72
|
+
console.error('Error fetching Rate by Amount:', err);
|
|
80
73
|
throw err;
|
|
81
74
|
}
|
|
82
75
|
};
|
|
83
76
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* Returns:
|
|
92
|
-
* A promise resolving to the rate details for the specified rate type.
|
|
93
|
-
*
|
|
94
|
-
* Raises:
|
|
95
|
-
* Throws an error if the rate information cannot be fetched.
|
|
77
|
+
* The function `getRateByRateType` fetches a rate based on a specified rate type from a given URL.
|
|
78
|
+
* @param {string} url - The `url` parameter is a string representing the base URL used to fetch data.
|
|
79
|
+
* @param {RateType} rateType - RateType is a type that represents the different types of rates that
|
|
80
|
+
* can be fetched. It is used as a parameter in the getRateByRateType function to specify the type of
|
|
81
|
+
* rate to retrieve from the provided URL.
|
|
82
|
+
* @returns The `getRateByRateType` function is returning a Promise that resolves to a
|
|
83
|
+
* `RateByRateTypeType` object fetched from the specified URL with the provided rate type.
|
|
96
84
|
*/
|
|
97
85
|
export const getRateByRateType = async (url, rateType) => {
|
|
98
86
|
try {
|
|
99
|
-
return await get(
|
|
87
|
+
return await get(`${url}/${rateType}`);
|
|
100
88
|
}
|
|
101
89
|
catch (err) {
|
|
102
|
-
console.error(
|
|
90
|
+
console.error('Error fetching Rate by Rate Type:', err);
|
|
103
91
|
throw err;
|
|
104
92
|
}
|
|
105
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the provided URL,
|
|
96
|
+
* amount, and mint token.
|
|
97
|
+
* @param {string} url - The `url` parameter is a string representing the base URL for the API endpoint
|
|
98
|
+
* where you can fetch the token value.
|
|
99
|
+
* @param {number} amount - The `amount` parameter in the `getTokenValue` function represents the
|
|
100
|
+
* quantity or number of tokens for which you want to retrieve the value. It is a numeric value
|
|
101
|
+
* (number) indicating the amount of tokens for which you are querying the value.
|
|
102
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
103
|
+
* the unique identifier for a specific token. It is used to specify which token's value you want to
|
|
104
|
+
* retrieve based on the provided `amount`.
|
|
105
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function called with the
|
|
106
|
+
* URL `/value?amount=&mint=`. The `get` function is likely making an HTTP
|
|
107
|
+
* request to that URL to fetch some data. The return value is expected to be of type `TokenValueType`.
|
|
108
|
+
* If an error occurs during the fetch operation, an error message will
|
|
109
|
+
*/
|
|
110
|
+
export const getTokenValue = async (url, amount, mint_token) => {
|
|
111
|
+
try {
|
|
112
|
+
return await get(`${url}/value?amount=${amount}&mint=${mint_token}`);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
console.log('Error fetching Token Value:', err);
|
|
116
|
+
}
|
|
117
|
+
};
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const initializeSDK: (env: "staging" | "production") => void;
|
|
2
|
-
export { getRate
|
|
2
|
+
export { getRate } from './lib/off_ramp/getRate.js';
|
|
3
3
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
4
4
|
export { verify } from './lib/off_ramp/verify.js';
|
|
5
5
|
export { getBanks } from "./lib/off_ramp/getBanks.js";
|
|
@@ -9,3 +9,4 @@ export { getBankAccounts } from "./lib/off_ramp/getBankAccounts.js";
|
|
|
9
9
|
export { offRampCreateOrder } from './lib/direct_off_ramp/directCreateOrder.js';
|
|
10
10
|
export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
11
11
|
export { observeOrder } from './lib/on_ramp/observeOrder.js';
|
|
12
|
+
export { RateType } from './lib/off_ramp/getRate.js';
|
package/dist/sdk.js
CHANGED
|
@@ -12,7 +12,7 @@ export const initializeSDK = (env) => {
|
|
|
12
12
|
// OFF RAMP
|
|
13
13
|
// Wallet Info
|
|
14
14
|
// export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
|
|
15
|
-
export { getRate
|
|
15
|
+
export { getRate } from './lib/off_ramp/getRate.js';
|
|
16
16
|
// Session Management
|
|
17
17
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
18
18
|
export { verify } from './lib/off_ramp/verify.js';
|
|
@@ -32,3 +32,5 @@ export { offRampCreateOrder } from './lib/direct_off_ramp/directCreateOrder.js';
|
|
|
32
32
|
export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
33
33
|
// Observe Order Socket.IO
|
|
34
34
|
export { observeOrder } from './lib/on_ramp/observeOrder.js';
|
|
35
|
+
// Types
|
|
36
|
+
export { RateType } from './lib/off_ramp/getRate.js';
|
package/lib/off_ramp/getRate.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { get } from
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
2
|
|
|
3
3
|
type AllRateResponseType = {
|
|
4
4
|
onRampRate: {
|
|
5
|
-
baseCurrency:
|
|
6
|
-
targetCurrency:
|
|
5
|
+
baseCurrency: 'USD';
|
|
6
|
+
targetCurrency: 'NGN';
|
|
7
7
|
isActive: true;
|
|
8
8
|
rate: 1510;
|
|
9
|
-
type:
|
|
9
|
+
type: 'onRamp';
|
|
10
10
|
};
|
|
11
11
|
offRampRate: {
|
|
12
|
-
baseCurrency:
|
|
13
|
-
targetCurrency:
|
|
12
|
+
baseCurrency: 'USD';
|
|
13
|
+
targetCurrency: 'NGN';
|
|
14
14
|
isActive: true;
|
|
15
15
|
rate: 1525;
|
|
16
|
-
type:
|
|
16
|
+
type: 'offRamp';
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -32,112 +32,139 @@ type RateByAmountType = {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
type RateByRateTypeType = {
|
|
35
|
-
baseCurrency:
|
|
36
|
-
targetCurrency:
|
|
35
|
+
baseCurrency: 'USD';
|
|
36
|
+
targetCurrency: 'NGN';
|
|
37
37
|
isActive: true;
|
|
38
38
|
rate: 1525;
|
|
39
|
-
type:
|
|
39
|
+
type: 'offRamp';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type TokenValueType = {
|
|
43
|
+
amount: number;
|
|
44
|
+
usdcValue: number;
|
|
45
|
+
mint: string;
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
export enum RateType {
|
|
43
|
-
onRamp =
|
|
44
|
-
offRamp =
|
|
49
|
+
onRamp = 'onRamp',
|
|
50
|
+
offRamp = 'offRamp',
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Raises:
|
|
58
|
-
* Throws an error if the rate information cannot be fetched.
|
|
54
|
+
* The function `getRate` in TypeScript is an asynchronous function that retrieves rate information
|
|
55
|
+
* based on different parameters such as amount, rate type, and mint token.
|
|
56
|
+
* @param {number | RateType} param - The `param` parameter in the `getRate` function can be either a
|
|
57
|
+
* number or a `RateType`.
|
|
58
|
+
* @param {string} [mint_token] - The `mint_token` parameter is an optional string parameter that
|
|
59
|
+
* represents a token used for minting. It is used in the `getRate` function to calculate the rate
|
|
60
|
+
* based on the specified token value.
|
|
61
|
+
* @returns The `getRate` function returns different values based on the conditions inside the
|
|
62
|
+
* function:
|
|
59
63
|
*/
|
|
60
|
-
export const getRate = async (
|
|
64
|
+
export const getRate = async (
|
|
65
|
+
param: number | RateType,
|
|
66
|
+
mint_token?: string
|
|
67
|
+
) => {
|
|
61
68
|
try {
|
|
62
|
-
const url =
|
|
69
|
+
const url = '/pub/rate';
|
|
63
70
|
|
|
64
71
|
if (!param) {
|
|
65
72
|
return getAllRate(url);
|
|
66
|
-
} else if (typeof param ===
|
|
73
|
+
} else if (typeof param === 'number') {
|
|
74
|
+
if (mint_token) return getTokenValue(url, param, mint_token);
|
|
67
75
|
return getRateByAmount(url, param);
|
|
68
76
|
} else {
|
|
69
77
|
return getRateByRateType(url, param);
|
|
70
78
|
}
|
|
71
79
|
} catch (err) {
|
|
72
|
-
console.error(
|
|
80
|
+
console.error('Error fetching Rate:', err);
|
|
73
81
|
throw err;
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
|
|
77
85
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* Raises:
|
|
88
|
-
* Throws an error if the rate information cannot be fetched.
|
|
86
|
+
* The function `getAllRate` fetches all rates from a specified URL and handles any errors that occur
|
|
87
|
+
* during the process.
|
|
88
|
+
* @param {string} url - The `url` parameter in the `getAllRate` function is a string representing the
|
|
89
|
+
* URL from which the rate data will be fetched.
|
|
90
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
91
|
+
* function call, which is fetching rate data from the specified URL. If successful, it will return the
|
|
92
|
+
* rate data. If an error occurs during the fetching process, it will log the error message and rethrow
|
|
93
|
+
* the error.
|
|
89
94
|
*/
|
|
90
|
-
const getAllRate = async (url: string) => {
|
|
95
|
+
export const getAllRate = async (url: string) => {
|
|
91
96
|
try {
|
|
92
97
|
return await get<AllRateResponseType>(url);
|
|
93
98
|
} catch (err) {
|
|
94
|
-
console.error(
|
|
99
|
+
console.error('Error fetching Rate:', err);
|
|
95
100
|
throw err;
|
|
96
101
|
}
|
|
97
102
|
};
|
|
98
103
|
|
|
99
104
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* A promise resolving to the rate and amount details for the specified value.
|
|
109
|
-
*
|
|
110
|
-
* Raises:
|
|
111
|
-
* Throws an error if the rate information cannot be fetched.
|
|
105
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount from a given URL.
|
|
106
|
+
* @param {string} url - The `url` parameter is a string that represents the URL endpoint where the
|
|
107
|
+
* rate information is fetched from.
|
|
108
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
109
|
+
* representing the amount for which you want to fetch the rate. This amount will be used in the URL to
|
|
110
|
+
* make a request to the specified endpoint to get the rate information for that specific amount.
|
|
111
|
+
* @returns The function `getRateByAmount` is returning a Promise that resolves to a `RateByAmountType`
|
|
112
|
+
* object fetched from the specified URL with the provided amount.
|
|
112
113
|
*/
|
|
113
114
|
export const getRateByAmount = async (url: string, amount: number) => {
|
|
114
115
|
try {
|
|
115
|
-
return await get<RateByAmountType>(
|
|
116
|
+
return await get<RateByAmountType>(`${url}/${amount}`);
|
|
116
117
|
} catch (err) {
|
|
117
|
-
console.error(
|
|
118
|
+
console.error('Error fetching Rate by Amount:', err);
|
|
118
119
|
throw err;
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
|
|
123
|
+
|
|
122
124
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* Returns:
|
|
131
|
-
* A promise resolving to the rate details for the specified rate type.
|
|
132
|
-
*
|
|
133
|
-
* Raises:
|
|
134
|
-
* Throws an error if the rate information cannot be fetched.
|
|
125
|
+
* The function `getRateByRateType` fetches a rate based on a specified rate type from a given URL.
|
|
126
|
+
* @param {string} url - The `url` parameter is a string representing the base URL used to fetch data.
|
|
127
|
+
* @param {RateType} rateType - RateType is a type that represents the different types of rates that
|
|
128
|
+
* can be fetched. It is used as a parameter in the getRateByRateType function to specify the type of
|
|
129
|
+
* rate to retrieve from the provided URL.
|
|
130
|
+
* @returns The `getRateByRateType` function is returning a Promise that resolves to a
|
|
131
|
+
* `RateByRateTypeType` object fetched from the specified URL with the provided rate type.
|
|
135
132
|
*/
|
|
136
133
|
export const getRateByRateType = async (url: string, rateType: RateType) => {
|
|
137
134
|
try {
|
|
138
|
-
return await get<RateByRateTypeType>(
|
|
135
|
+
return await get<RateByRateTypeType>(`${url}/${rateType}`);
|
|
139
136
|
} catch (err) {
|
|
140
|
-
console.error(
|
|
137
|
+
console.error('Error fetching Rate by Rate Type:', err);
|
|
141
138
|
throw err;
|
|
142
139
|
}
|
|
143
140
|
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the provided URL,
|
|
144
|
+
* amount, and mint token.
|
|
145
|
+
* @param {string} url - The `url` parameter is a string representing the base URL for the API endpoint
|
|
146
|
+
* where you can fetch the token value.
|
|
147
|
+
* @param {number} amount - The `amount` parameter in the `getTokenValue` function represents the
|
|
148
|
+
* quantity or number of tokens for which you want to retrieve the value. It is a numeric value
|
|
149
|
+
* (number) indicating the amount of tokens for which you are querying the value.
|
|
150
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
151
|
+
* the unique identifier for a specific token. It is used to specify which token's value you want to
|
|
152
|
+
* retrieve based on the provided `amount`.
|
|
153
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function called with the
|
|
154
|
+
* URL `/value?amount=&mint=`. The `get` function is likely making an HTTP
|
|
155
|
+
* request to that URL to fetch some data. The return value is expected to be of type `TokenValueType`.
|
|
156
|
+
* If an error occurs during the fetch operation, an error message will
|
|
157
|
+
*/
|
|
158
|
+
export const getTokenValue = async (
|
|
159
|
+
url: string,
|
|
160
|
+
amount: number,
|
|
161
|
+
mint_token: string
|
|
162
|
+
) => {
|
|
163
|
+
try {
|
|
164
|
+
return await get<TokenValueType>(
|
|
165
|
+
`${url}/value?amount=${amount}&mint=${mint_token}`
|
|
166
|
+
);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
console.log('Error fetching Token Value:', err);
|
|
169
|
+
}
|
|
170
|
+
};
|
package/package.json
CHANGED
package/sdk.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const initializeSDK = (env: 'staging' | 'production') => {
|
|
|
15
15
|
|
|
16
16
|
// Wallet Info
|
|
17
17
|
// export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
|
|
18
|
-
export { getRate
|
|
18
|
+
export { getRate } from './lib/off_ramp/getRate.js';
|
|
19
19
|
|
|
20
20
|
// Session Management
|
|
21
21
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
@@ -35,6 +35,7 @@ export { getBankAccounts } from "./lib/off_ramp/getBankAccounts.js";
|
|
|
35
35
|
// DIRECT OFF RAMP
|
|
36
36
|
export { offRampCreateOrder } from './lib/direct_off_ramp/directCreateOrder.js';
|
|
37
37
|
|
|
38
|
+
|
|
38
39
|
// ON RAMP
|
|
39
40
|
|
|
40
41
|
// Create Order
|
|
@@ -42,3 +43,6 @@ export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
|
42
43
|
|
|
43
44
|
// Observe Order Socket.IO
|
|
44
45
|
export { observeOrder } from './lib/on_ramp/observeOrder.js';
|
|
46
|
+
|
|
47
|
+
// Types
|
|
48
|
+
export { RateType } from './lib/off_ramp/getRate.js';
|