paj_ramp 1.2.4 → 1.2.5
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 +19 -0
- 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
|
@@ -310,6 +310,25 @@ Response:
|
|
|
310
310
|
}*/
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
+
### Get Token Value from Amount and Mint Token
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { getRate } from 'paj_ramp';
|
|
317
|
+
|
|
318
|
+
const tokenValue = await getRate(
|
|
319
|
+
50000,
|
|
320
|
+
'token_mint_address'
|
|
321
|
+
);
|
|
322
|
+
/*
|
|
323
|
+
Response:
|
|
324
|
+
{
|
|
325
|
+
amount: number, // requested token amount
|
|
326
|
+
usdcValue: number, // USD value of the token amount
|
|
327
|
+
mint: string // token mint address
|
|
328
|
+
}
|
|
329
|
+
*/
|
|
330
|
+
```
|
|
331
|
+
|
|
313
332
|
### Get Rate by Rate Type
|
|
314
333
|
|
|
315
334
|
```typescript
|
|
@@ -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';
|