paj_ramp 1.2.8 → 1.2.9
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 +8 -8
- package/dist/lib/off_ramp/getAllRate.d.ts +27 -0
- package/dist/lib/off_ramp/getAllRate.js +20 -0
- package/dist/lib/off_ramp/getRateByAmount.d.ts +27 -0
- package/dist/lib/off_ramp/getRateByAmount.js +23 -0
- package/dist/lib/off_ramp/getRateByType.d.ts +21 -0
- package/dist/lib/off_ramp/getRateByType.js +24 -0
- package/dist/lib/off_ramp/getTokenValue.d.ts +20 -0
- package/dist/lib/off_ramp/getTokenValue.js +24 -0
- package/dist/sdk.d.ts +5 -2
- package/dist/sdk.js +5 -2
- package/lib/off_ramp/getAllRate.ts +39 -0
- package/lib/off_ramp/getRateByAmount.ts +38 -0
- package/lib/off_ramp/getRateByType.ts +33 -0
- package/lib/off_ramp/getTokenValue.ts +36 -0
- package/package.json +1 -1
- package/sdk.ts +8 -2
- package/lib/off_ramp/getRate.ts +0 -173
package/README.md
CHANGED
|
@@ -60,9 +60,9 @@ const verified = await verify(
|
|
|
60
60
|
**_Get All Rate_**
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
import {
|
|
63
|
+
import { getAllRate } from 'paj_ramp';
|
|
64
64
|
|
|
65
|
-
const rate = await
|
|
65
|
+
const rate = await getAllRate();
|
|
66
66
|
/*
|
|
67
67
|
Response:
|
|
68
68
|
{
|
|
@@ -86,9 +86,9 @@ Response:
|
|
|
86
86
|
**_Get Rate by Amount_**
|
|
87
87
|
|
|
88
88
|
```typescript
|
|
89
|
-
import {
|
|
89
|
+
import { getRateByAmount } from 'paj_ramp';
|
|
90
90
|
|
|
91
|
-
const rate = await
|
|
91
|
+
const rate = await getRateByAmount(50000);
|
|
92
92
|
/*
|
|
93
93
|
Response:
|
|
94
94
|
{
|
|
@@ -109,9 +109,9 @@ Response:
|
|
|
109
109
|
**_Get Rate by Rate Type_**
|
|
110
110
|
|
|
111
111
|
```typescript
|
|
112
|
-
import {
|
|
112
|
+
import { getRateByType, RateType } from 'paj_ramp';
|
|
113
113
|
|
|
114
|
-
const rate = await
|
|
114
|
+
const rate = await getRateByType(RateType.offRamp); // or RateType.onRamp
|
|
115
115
|
|
|
116
116
|
/*
|
|
117
117
|
Response:
|
|
@@ -127,9 +127,9 @@ Response:
|
|
|
127
127
|
**_Get Token Value from Amount and Mint Token_**
|
|
128
128
|
|
|
129
129
|
```typescript
|
|
130
|
-
import {
|
|
130
|
+
import { getTokenValue } from 'paj_ramp';
|
|
131
131
|
|
|
132
|
-
const tokenValue = await
|
|
132
|
+
const tokenValue = await getTokenValue(50000, 'token_mint_address');
|
|
133
133
|
/*
|
|
134
134
|
Response:
|
|
135
135
|
{
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type AllRateResponseType = {
|
|
2
|
+
onRampRate: {
|
|
3
|
+
baseCurrency: string;
|
|
4
|
+
targetCurrency: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
rate: number;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
offRampRate: {
|
|
10
|
+
baseCurrency: string;
|
|
11
|
+
targetCurrency: string;
|
|
12
|
+
isActive: boolean;
|
|
13
|
+
rate: number;
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This TypeScript function asynchronously fetches all rates from a specified URL and handles any
|
|
19
|
+
* errors that may occur.
|
|
20
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
21
|
+
* function call, which is fetching rate data from the specified URL '/pub/rate'. The function is using
|
|
22
|
+
* async/await syntax to handle asynchronous operations and is catching any errors that occur during
|
|
23
|
+
* the fetch operation. If successful, the function will return the rate data, and if an error occurs,
|
|
24
|
+
* it
|
|
25
|
+
*/
|
|
26
|
+
export declare const getAllRate: () => Promise<AllRateResponseType>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* This TypeScript function asynchronously fetches all rates from a specified URL and handles any
|
|
4
|
+
* errors that may occur.
|
|
5
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
6
|
+
* function call, which is fetching rate data from the specified URL '/pub/rate'. The function is using
|
|
7
|
+
* async/await syntax to handle asynchronous operations and is catching any errors that occur during
|
|
8
|
+
* the fetch operation. If successful, the function will return the rate data, and if an error occurs,
|
|
9
|
+
* it
|
|
10
|
+
*/
|
|
11
|
+
export const getAllRate = async () => {
|
|
12
|
+
const url = '/pub/rate';
|
|
13
|
+
try {
|
|
14
|
+
return await get(url);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.error('Error fetching Rate:', err);
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type RateByAmountType = {
|
|
2
|
+
rate: {
|
|
3
|
+
baseCurrency: string;
|
|
4
|
+
targetCurrency: string;
|
|
5
|
+
rate: number;
|
|
6
|
+
};
|
|
7
|
+
amounts: {
|
|
8
|
+
userTax: number;
|
|
9
|
+
merchantTax: number;
|
|
10
|
+
amountUSD: number;
|
|
11
|
+
userAmountFiat: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount asynchronously.
|
|
16
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
17
|
+
* representing the amount for which you want to retrieve the rate. This function makes an asynchronous
|
|
18
|
+
* request to the `/pub/rate` endpoint with the specified amount to fetch the rate information. If
|
|
19
|
+
* successful, it returns the rate
|
|
20
|
+
* @returns The `getRateByAmount` function is returning a Promise that resolves to the rate for a
|
|
21
|
+
* specific amount. The rate is fetched from the specified URL endpoint `/pub/rate` with the provided
|
|
22
|
+
* amount as a parameter. If the rate is successfully fetched, it will be returned. If there is an
|
|
23
|
+
* error during the fetching process, an error message will be logged to the console and the error will
|
|
24
|
+
* be
|
|
25
|
+
*/
|
|
26
|
+
export declare const getRateByAmount: (amount: number) => Promise<RateByAmountType>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount asynchronously.
|
|
4
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
5
|
+
* representing the amount for which you want to retrieve the rate. This function makes an asynchronous
|
|
6
|
+
* request to the `/pub/rate` endpoint with the specified amount to fetch the rate information. If
|
|
7
|
+
* successful, it returns the rate
|
|
8
|
+
* @returns The `getRateByAmount` function is returning a Promise that resolves to the rate for a
|
|
9
|
+
* specific amount. The rate is fetched from the specified URL endpoint `/pub/rate` with the provided
|
|
10
|
+
* amount as a parameter. If the rate is successfully fetched, it will be returned. If there is an
|
|
11
|
+
* error during the fetching process, an error message will be logged to the console and the error will
|
|
12
|
+
* be
|
|
13
|
+
*/
|
|
14
|
+
export const getRateByAmount = async (amount) => {
|
|
15
|
+
const url = '/pub/rate';
|
|
16
|
+
try {
|
|
17
|
+
return await get(`${url}/${amount}`);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.error('Error fetching Rate by Amount:', err);
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type RateByType = {
|
|
2
|
+
baseCurrency: string;
|
|
3
|
+
targetCurrency: string;
|
|
4
|
+
isActive: true;
|
|
5
|
+
rate: number;
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
export declare enum RateType {
|
|
9
|
+
onRamp = "onRamp",
|
|
10
|
+
offRamp = "offRamp"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This function fetches a rate based on a specified rate type asynchronously.
|
|
14
|
+
* @param {RateType} rateType - RateType is a type that specifies the type of rate being requested,
|
|
15
|
+
* such as 'standard', 'premium', 'discount', etc.
|
|
16
|
+
* @returns The `getRateByType` function is returning a Promise that resolves to a `RateByType` object
|
|
17
|
+
* fetched from the specified URL based on the `rateType` parameter. If an error occurs during the
|
|
18
|
+
* fetching process, the function will log an error message and rethrow the error.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getRateByType: (rateType: RateType) => Promise<RateByType>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
export var RateType;
|
|
3
|
+
(function (RateType) {
|
|
4
|
+
RateType["onRamp"] = "onRamp";
|
|
5
|
+
RateType["offRamp"] = "offRamp";
|
|
6
|
+
})(RateType || (RateType = {}));
|
|
7
|
+
/**
|
|
8
|
+
* This function fetches a rate based on a specified rate type asynchronously.
|
|
9
|
+
* @param {RateType} rateType - RateType is a type that specifies the type of rate being requested,
|
|
10
|
+
* such as 'standard', 'premium', 'discount', etc.
|
|
11
|
+
* @returns The `getRateByType` function is returning a Promise that resolves to a `RateByType` object
|
|
12
|
+
* fetched from the specified URL based on the `rateType` parameter. If an error occurs during the
|
|
13
|
+
* fetching process, the function will log an error message and rethrow the error.
|
|
14
|
+
*/
|
|
15
|
+
export const getRateByType = async (rateType) => {
|
|
16
|
+
const url = '/pub/rate';
|
|
17
|
+
try {
|
|
18
|
+
return await get(`${url}/${rateType}`);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.error('Error fetching Rate by Rate Type:', err);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type TokenValueType = {
|
|
2
|
+
amount: number;
|
|
3
|
+
usdcValue: number;
|
|
4
|
+
mint: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the specified
|
|
8
|
+
* amount and token mint.
|
|
9
|
+
* @param {number} amount - The `amount` parameter is a number representing the quantity of tokens for
|
|
10
|
+
* which you want to retrieve the value.
|
|
11
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
12
|
+
* the unique identifier for a specific token. It is used to specify which token you are interested in
|
|
13
|
+
* when fetching its value.
|
|
14
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function call with the
|
|
15
|
+
* URL `/value?amount=&mint=` as its argument. The `get` function is likely
|
|
16
|
+
* making an HTTP request to fetch the token value based on the provided amount and mint token. If
|
|
17
|
+
* successful, the function will return the token value. If there is an error during
|
|
18
|
+
*/
|
|
19
|
+
export declare const getTokenValue: (amount: number, mint_token: string) => Promise<TokenValueType>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the specified
|
|
4
|
+
* amount and token mint.
|
|
5
|
+
* @param {number} amount - The `amount` parameter is a number representing the quantity of tokens for
|
|
6
|
+
* which you want to retrieve the value.
|
|
7
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
8
|
+
* the unique identifier for a specific token. It is used to specify which token you are interested in
|
|
9
|
+
* when fetching its value.
|
|
10
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function call with the
|
|
11
|
+
* URL `/value?amount=&mint=` as its argument. The `get` function is likely
|
|
12
|
+
* making an HTTP request to fetch the token value based on the provided amount and mint token. If
|
|
13
|
+
* successful, the function will return the token value. If there is an error during
|
|
14
|
+
*/
|
|
15
|
+
export const getTokenValue = async (amount, mint_token) => {
|
|
16
|
+
const url = '/pub/rate';
|
|
17
|
+
try {
|
|
18
|
+
return await get(`${url}/value?amount=${amount}&mint=${mint_token}`);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.log('Error fetching Token Value:', err);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
};
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const initializeSDK: (env: "staging" | "production") => void;
|
|
2
|
-
export {
|
|
2
|
+
export { getAllRate } from './lib/off_ramp/getAllRate.js';
|
|
3
|
+
export { getRateByAmount } from './lib/off_ramp/getRateByAmount.js';
|
|
4
|
+
export { getRateByType } from './lib/off_ramp/getRateByType.js';
|
|
5
|
+
export { getTokenValue } from './lib/off_ramp/getTokenValue.js';
|
|
3
6
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
4
7
|
export { verify } from './lib/off_ramp/verify.js';
|
|
5
8
|
export { getBanks } from './lib/off_ramp/getBanks.js';
|
|
@@ -8,4 +11,4 @@ export { addBankAccount } from './lib/off_ramp/addBankAccount.js';
|
|
|
8
11
|
export { getBankAccounts } from './lib/off_ramp/getBankAccounts.js';
|
|
9
12
|
export { offRampCreateOrder } from './lib/direct_off_ramp/directCreateOrder.js';
|
|
10
13
|
export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
11
|
-
export { RateType } from './lib/off_ramp/
|
|
14
|
+
export { RateType } from './lib/off_ramp/getRateByType.js';
|
package/dist/sdk.js
CHANGED
|
@@ -12,7 +12,10 @@ export const initializeSDK = (env) => {
|
|
|
12
12
|
// OFF RAMP
|
|
13
13
|
// Wallet Info
|
|
14
14
|
// export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
|
|
15
|
-
export {
|
|
15
|
+
export { getAllRate } from './lib/off_ramp/getAllRate.js';
|
|
16
|
+
export { getRateByAmount } from './lib/off_ramp/getRateByAmount.js';
|
|
17
|
+
export { getRateByType } from './lib/off_ramp/getRateByType.js';
|
|
18
|
+
export { getTokenValue } from './lib/off_ramp/getTokenValue.js';
|
|
16
19
|
// Session Management
|
|
17
20
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
18
21
|
export { verify } from './lib/off_ramp/verify.js';
|
|
@@ -33,4 +36,4 @@ export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
|
33
36
|
// Observe Order Socket.IO
|
|
34
37
|
// export { observeOrder } from './lib/on_ramp/observeOrder.js';
|
|
35
38
|
// Types
|
|
36
|
-
export { RateType } from './lib/off_ramp/
|
|
39
|
+
export { RateType } from './lib/off_ramp/getRateByType.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
|
|
3
|
+
type AllRateResponseType = {
|
|
4
|
+
onRampRate: {
|
|
5
|
+
baseCurrency: string;
|
|
6
|
+
targetCurrency: string;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
rate: number;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
offRampRate: {
|
|
12
|
+
baseCurrency: string;
|
|
13
|
+
targetCurrency: string;
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
rate: number;
|
|
16
|
+
type: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This TypeScript function asynchronously fetches all rates from a specified URL and handles any
|
|
23
|
+
* errors that may occur.
|
|
24
|
+
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
25
|
+
* function call, which is fetching rate data from the specified URL '/pub/rate'. The function is using
|
|
26
|
+
* async/await syntax to handle asynchronous operations and is catching any errors that occur during
|
|
27
|
+
* the fetch operation. If successful, the function will return the rate data, and if an error occurs,
|
|
28
|
+
* it
|
|
29
|
+
*/
|
|
30
|
+
export const getAllRate = async () => {
|
|
31
|
+
const url: string = '/pub/rate';
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
return await get<AllRateResponseType>(url);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('Error fetching Rate:', err);
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
|
|
3
|
+
type RateByAmountType = {
|
|
4
|
+
rate: {
|
|
5
|
+
baseCurrency: string;
|
|
6
|
+
targetCurrency: string;
|
|
7
|
+
rate: number;
|
|
8
|
+
};
|
|
9
|
+
amounts: {
|
|
10
|
+
userTax: number;
|
|
11
|
+
merchantTax: number;
|
|
12
|
+
amountUSD: number;
|
|
13
|
+
userAmountFiat: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The function `getRateByAmount` fetches a rate based on a specified amount asynchronously.
|
|
19
|
+
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
20
|
+
* representing the amount for which you want to retrieve the rate. This function makes an asynchronous
|
|
21
|
+
* request to the `/pub/rate` endpoint with the specified amount to fetch the rate information. If
|
|
22
|
+
* successful, it returns the rate
|
|
23
|
+
* @returns The `getRateByAmount` function is returning a Promise that resolves to the rate for a
|
|
24
|
+
* specific amount. The rate is fetched from the specified URL endpoint `/pub/rate` with the provided
|
|
25
|
+
* amount as a parameter. If the rate is successfully fetched, it will be returned. If there is an
|
|
26
|
+
* error during the fetching process, an error message will be logged to the console and the error will
|
|
27
|
+
* be
|
|
28
|
+
*/
|
|
29
|
+
export const getRateByAmount = async (amount: number) => {
|
|
30
|
+
const url: string = '/pub/rate';
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
return await get<RateByAmountType>(`${url}/${amount}`);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error('Error fetching Rate by Amount:', err);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
|
|
3
|
+
type RateByType = {
|
|
4
|
+
baseCurrency: string;
|
|
5
|
+
targetCurrency: string;
|
|
6
|
+
isActive: true;
|
|
7
|
+
rate: number;
|
|
8
|
+
type: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export enum RateType {
|
|
12
|
+
onRamp = 'onRamp',
|
|
13
|
+
offRamp = 'offRamp',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This function fetches a rate based on a specified rate type asynchronously.
|
|
18
|
+
* @param {RateType} rateType - RateType is a type that specifies the type of rate being requested,
|
|
19
|
+
* such as 'standard', 'premium', 'discount', etc.
|
|
20
|
+
* @returns The `getRateByType` function is returning a Promise that resolves to a `RateByType` object
|
|
21
|
+
* fetched from the specified URL based on the `rateType` parameter. If an error occurs during the
|
|
22
|
+
* fetching process, the function will log an error message and rethrow the error.
|
|
23
|
+
*/
|
|
24
|
+
export const getRateByType = async (rateType: RateType) => {
|
|
25
|
+
const url: string = '/pub/rate';
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
return await get<RateByType>(`${url}/${rateType}`);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error('Error fetching Rate by Rate Type:', err);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { get } from '../../utils/api.js';
|
|
2
|
+
|
|
3
|
+
type TokenValueType = {
|
|
4
|
+
amount: number;
|
|
5
|
+
usdcValue: number;
|
|
6
|
+
mint: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The function `getTokenValue` asynchronously fetches the value of a token based on the specified
|
|
11
|
+
* amount and token mint.
|
|
12
|
+
* @param {number} amount - The `amount` parameter is a number representing the quantity of tokens for
|
|
13
|
+
* which you want to retrieve the value.
|
|
14
|
+
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
15
|
+
* the unique identifier for a specific token. It is used to specify which token you are interested in
|
|
16
|
+
* when fetching its value.
|
|
17
|
+
* @returns The `getTokenValue` function is returning the result of the `get` function call with the
|
|
18
|
+
* URL `/value?amount=&mint=` as its argument. The `get` function is likely
|
|
19
|
+
* making an HTTP request to fetch the token value based on the provided amount and mint token. If
|
|
20
|
+
* successful, the function will return the token value. If there is an error during
|
|
21
|
+
*/
|
|
22
|
+
export const getTokenValue = async (
|
|
23
|
+
amount: number,
|
|
24
|
+
mint_token: string
|
|
25
|
+
) => {
|
|
26
|
+
const url: string = '/pub/rate';
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
return await get<TokenValueType>(
|
|
30
|
+
`${url}/value?amount=${amount}&mint=${mint_token}`
|
|
31
|
+
);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.log('Error fetching Token Value:', err);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
};
|
package/package.json
CHANGED
package/sdk.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// Switch Environment: "staging" | "production"
|
|
4
4
|
import { setBaseUrl } from './utils/axios.js';
|
|
5
|
+
import { getRateByAmount } from './lib/off_ramp/getRateByAmount';
|
|
6
|
+
import { getRateByRateType } from './dist/lib/off_ramp/getRate';
|
|
7
|
+
import { getTokenValue } from './lib/off_ramp/getTokenValue';
|
|
5
8
|
|
|
6
9
|
export const initializeSDK = (env: 'staging' | 'production') => {
|
|
7
10
|
if (env === 'staging') {
|
|
@@ -15,7 +18,10 @@ export const initializeSDK = (env: 'staging' | 'production') => {
|
|
|
15
18
|
|
|
16
19
|
// Wallet Info
|
|
17
20
|
// export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
|
|
18
|
-
export {
|
|
21
|
+
export { getAllRate } from './lib/off_ramp/getAllRate.js';
|
|
22
|
+
export { getRateByAmount } from './lib/off_ramp/getRateByAmount.js';
|
|
23
|
+
export { getRateByType } from './lib/off_ramp/getRateByType.js';
|
|
24
|
+
export { getTokenValue } from './lib/off_ramp/getTokenValue.js';
|
|
19
25
|
|
|
20
26
|
// Session Management
|
|
21
27
|
export { initiate } from './lib/off_ramp/initiate.js';
|
|
@@ -44,4 +50,4 @@ export { createOrder } from './lib/on_ramp/createOrder.js';
|
|
|
44
50
|
// export { observeOrder } from './lib/on_ramp/observeOrder.js';
|
|
45
51
|
|
|
46
52
|
// Types
|
|
47
|
-
export { RateType } from './lib/off_ramp/
|
|
53
|
+
export { RateType } from './lib/off_ramp/getRateByType.js';
|
package/lib/off_ramp/getRate.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { get } from '../../utils/api.js';
|
|
2
|
-
|
|
3
|
-
type AllRateResponseType = {
|
|
4
|
-
onRampRate: {
|
|
5
|
-
baseCurrency: string;
|
|
6
|
-
targetCurrency: string;
|
|
7
|
-
isActive: boolean;
|
|
8
|
-
rate: number;
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
offRampRate: {
|
|
12
|
-
baseCurrency: string;
|
|
13
|
-
targetCurrency: string;
|
|
14
|
-
isActive: boolean;
|
|
15
|
-
rate: number;
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type RateByAmountType = {
|
|
21
|
-
rate: {
|
|
22
|
-
baseCurrency: string;
|
|
23
|
-
targetCurrency: string;
|
|
24
|
-
rate: number;
|
|
25
|
-
};
|
|
26
|
-
amounts: {
|
|
27
|
-
userTax: number;
|
|
28
|
-
merchantTax: number;
|
|
29
|
-
amountUSD: number;
|
|
30
|
-
userAmountFiat: number;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type RateByRateTypeType = {
|
|
35
|
-
baseCurrency: string;
|
|
36
|
-
targetCurrency: string;
|
|
37
|
-
isActive: true;
|
|
38
|
-
rate: number;
|
|
39
|
-
type: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type TokenValueType = {
|
|
43
|
-
amount: number;
|
|
44
|
-
usdcValue: number;
|
|
45
|
-
mint: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export enum RateType {
|
|
49
|
-
onRamp = 'onRamp',
|
|
50
|
-
offRamp = 'offRamp',
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
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:
|
|
63
|
-
*/
|
|
64
|
-
export function getRate(): Promise<AllRateResponseType>;
|
|
65
|
-
export function getRate(
|
|
66
|
-
param: number,
|
|
67
|
-
mint_token: string
|
|
68
|
-
): Promise<TokenValueType>;
|
|
69
|
-
export function getRate(param: number): Promise<RateByAmountType>;
|
|
70
|
-
export function getRate(param: RateType): Promise<RateByRateTypeType>;
|
|
71
|
-
export async function getRate(param?: number | RateType, mint_token?: string) {
|
|
72
|
-
try {
|
|
73
|
-
const url = '/pub/rate';
|
|
74
|
-
|
|
75
|
-
if (!param) {
|
|
76
|
-
return getAllRate(url);
|
|
77
|
-
} else if (typeof param === 'number') {
|
|
78
|
-
if (mint_token) return getTokenValue(url, param, mint_token);
|
|
79
|
-
return getRateByAmount(url, param);
|
|
80
|
-
} else {
|
|
81
|
-
return getRateByRateType(url, param);
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
console.error('Error fetching Rate:', err);
|
|
85
|
-
throw err;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The function `getAllRate` fetches all rates from a specified URL and handles any errors that occur
|
|
91
|
-
* during the process.
|
|
92
|
-
* @param {string} url - The `url` parameter in the `getAllRate` function is a string representing the
|
|
93
|
-
* URL from which the rate data will be fetched.
|
|
94
|
-
* @returns The `getAllRate` function is returning the result of the `get<AllRateResponseType>(url)`
|
|
95
|
-
* function call, which is fetching rate data from the specified URL. If successful, it will return the
|
|
96
|
-
* rate data. If an error occurs during the fetching process, it will log the error message and rethrow
|
|
97
|
-
* the error.
|
|
98
|
-
*/
|
|
99
|
-
export const getAllRate = async (url: string) => {
|
|
100
|
-
try {
|
|
101
|
-
return await get<AllRateResponseType>(url);
|
|
102
|
-
} catch (err) {
|
|
103
|
-
console.error('Error fetching Rate:', err);
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* The function `getRateByAmount` fetches a rate based on a specified amount from a given URL.
|
|
110
|
-
* @param {string} url - The `url` parameter is a string that represents the URL endpoint where the
|
|
111
|
-
* rate information is fetched from.
|
|
112
|
-
* @param {number} amount - The `amount` parameter in the `getRateByAmount` function is a number
|
|
113
|
-
* representing the amount for which you want to fetch the rate. This amount will be used in the URL to
|
|
114
|
-
* make a request to the specified endpoint to get the rate information for that specific amount.
|
|
115
|
-
* @returns The function `getRateByAmount` is returning a Promise that resolves to a `RateByAmountType`
|
|
116
|
-
* object fetched from the specified URL with the provided amount.
|
|
117
|
-
*/
|
|
118
|
-
export const getRateByAmount = async (url: string, amount: number) => {
|
|
119
|
-
try {
|
|
120
|
-
return await get<RateByAmountType>(`${url}/${amount}`);
|
|
121
|
-
} catch (err) {
|
|
122
|
-
console.error('Error fetching Rate by Amount:', err);
|
|
123
|
-
throw err;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* The function `getRateByRateType` fetches a rate based on a specified rate type from a given URL.
|
|
129
|
-
* @param {string} url - The `url` parameter is a string representing the base URL used to fetch data.
|
|
130
|
-
* @param {RateType} rateType - RateType is a type that represents the different types of rates that
|
|
131
|
-
* can be fetched. It is used as a parameter in the getRateByRateType function to specify the type of
|
|
132
|
-
* rate to retrieve from the provided URL.
|
|
133
|
-
* @returns The `getRateByRateType` function is returning a Promise that resolves to a
|
|
134
|
-
* `RateByRateTypeType` object fetched from the specified URL with the provided rate type.
|
|
135
|
-
*/
|
|
136
|
-
export const getRateByRateType = async (url: string, rateType: RateType) => {
|
|
137
|
-
try {
|
|
138
|
-
return await get<RateByRateTypeType>(`${url}/${rateType}`);
|
|
139
|
-
} catch (err) {
|
|
140
|
-
console.error('Error fetching Rate by Rate Type:', err);
|
|
141
|
-
throw err;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The function `getTokenValue` asynchronously fetches the value of a token based on the provided URL,
|
|
147
|
-
* amount, and mint token.
|
|
148
|
-
* @param {string} url - The `url` parameter is a string representing the base URL for the API endpoint
|
|
149
|
-
* where you can fetch the token value.
|
|
150
|
-
* @param {number} amount - The `amount` parameter in the `getTokenValue` function represents the
|
|
151
|
-
* quantity or number of tokens for which you want to retrieve the value. It is a numeric value
|
|
152
|
-
* (number) indicating the amount of tokens for which you are querying the value.
|
|
153
|
-
* @param {string} mint_token - The `mint_token` parameter in the `getTokenValue` function represents
|
|
154
|
-
* the unique identifier for a specific token. It is used to specify which token's value you want to
|
|
155
|
-
* retrieve based on the provided `amount`.
|
|
156
|
-
* @returns The `getTokenValue` function is returning the result of the `get` function called with the
|
|
157
|
-
* URL `/value?amount=&mint=`. The `get` function is likely making an HTTP
|
|
158
|
-
* request to that URL to fetch some data. The return value is expected to be of type `TokenValueType`.
|
|
159
|
-
* If an error occurs during the fetch operation, an error message will
|
|
160
|
-
*/
|
|
161
|
-
export const getTokenValue = async (
|
|
162
|
-
url: string,
|
|
163
|
-
amount: number,
|
|
164
|
-
mint_token: string
|
|
165
|
-
) => {
|
|
166
|
-
try {
|
|
167
|
-
return await get<TokenValueType>(
|
|
168
|
-
`${url}/value?amount=${amount}&mint=${mint_token}`
|
|
169
|
-
);
|
|
170
|
-
} catch (err) {
|
|
171
|
-
console.log('Error fetching Token Value:', err);
|
|
172
|
-
}
|
|
173
|
-
};
|