@zebec-network/exchange-card-sdk 1.1.10-beta.2 → 1.1.10
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/dist/constants.d.ts +2 -8
- package/dist/constants.js +5 -34
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/nearService.d.ts +123 -0
- package/dist/services/nearService.js +145 -0
- package/dist/services/stellarService.js +1 -1
- package/dist/services/xrplService.d.ts +10 -5
- package/dist/services/xrplService.js +17 -32
- package/package.json +10 -8
package/dist/constants.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { SupportedChain } from "./chains";
|
|
2
|
-
export declare const ZEBEC_CARD_ADDRESS: Record<SupportedChain, string>;
|
|
3
|
-
export declare const USDC_ADDRESS: Record<SupportedChain, string>;
|
|
4
1
|
export declare const CARD_API_URL: Record<"Production" | "Sandbox", string>;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const TON_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
7
|
-
export declare const DIGITALBITS_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
2
|
+
export declare const NEAR_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
8
3
|
export declare const XRPL_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
9
|
-
export declare const XDB_PASSPHRASE: Record<"Production" | "Sandbox", string>;
|
|
10
4
|
export declare const STELLAR_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
11
|
-
export declare const
|
|
5
|
+
export declare const STELLAR_USDC_ISSUER: {
|
|
12
6
|
readonly Sandbox: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
|
|
13
7
|
readonly Production: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
|
|
14
8
|
};
|
package/dist/constants.js
CHANGED
|
@@ -1,53 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PLATFORM_FEE = exports.COUNTRIES_WITH_CCA3 = exports.BITCOIN_ENDPOINTS = exports.
|
|
4
|
-
const chains_1 = require("./chains");
|
|
5
|
-
exports.ZEBEC_CARD_ADDRESS = {
|
|
6
|
-
[chains_1.SupportedChain.Sepolia]: "0x00d90625CcaB01eA0e589DFd3C99972180CE609A",
|
|
7
|
-
[chains_1.SupportedChain.Base]: "0x1bF6419D8555EafaE79142D309534e8aBd54aBa3",
|
|
8
|
-
[chains_1.SupportedChain.Mainnet]: "0xB4f6E946E12200F4E0ba3B352B8DbF0a66635b53",
|
|
9
|
-
[chains_1.SupportedChain.Bsc]: "0x1bF6419D8555EafaE79142D309534e8aBd54aBa3",
|
|
10
|
-
[chains_1.SupportedChain.BscTestnet]: "0x9061E6eB59890D33C94B9f517c3dba30621fAB2f",
|
|
11
|
-
[chains_1.SupportedChain.Polygon]: "",
|
|
12
|
-
};
|
|
13
|
-
exports.USDC_ADDRESS = {
|
|
14
|
-
[chains_1.SupportedChain.Sepolia]: "0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8",
|
|
15
|
-
[chains_1.SupportedChain.Base]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
16
|
-
[chains_1.SupportedChain.Mainnet]: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
17
|
-
[chains_1.SupportedChain.Bsc]: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
18
|
-
[chains_1.SupportedChain.BscTestnet]: "0xF8Dc6f35a10244213096D86c376491042594a84e",
|
|
19
|
-
[chains_1.SupportedChain.Polygon]: "",
|
|
20
|
-
};
|
|
3
|
+
exports.PLATFORM_FEE = exports.COUNTRIES_WITH_CCA3 = exports.BITCOIN_ENDPOINTS = exports.STELLAR_USDC_ISSUER = exports.STELLAR_RPC_URL = exports.XRPL_RPC_URL = exports.NEAR_RPC_URL = exports.CARD_API_URL = void 0;
|
|
21
4
|
exports.CARD_API_URL = {
|
|
22
5
|
Production: "https://cex.card.zebec.io",
|
|
23
6
|
Sandbox: "https://cex.card.zebec.io",
|
|
24
7
|
};
|
|
25
|
-
exports.
|
|
26
|
-
Production: "
|
|
27
|
-
Sandbox: "
|
|
28
|
-
};
|
|
29
|
-
exports.TON_RPC_URL = {
|
|
30
|
-
Production: "https://toncenter.com/api/v2/jsonRPC",
|
|
31
|
-
Sandbox: "https://testnet.toncenter.com/api/v2/jsonRPC",
|
|
32
|
-
};
|
|
33
|
-
exports.DIGITALBITS_RPC_URL = {
|
|
34
|
-
Production: "https://horizon.livenet.xdbchain.com",
|
|
35
|
-
Sandbox: "https://horizon.futurenet.xdbchain.com",
|
|
8
|
+
exports.NEAR_RPC_URL = {
|
|
9
|
+
Production: process.env.NEAR_RPC_URL ? process.env.NEAR_RPC_URL : "https://rpc.mainnet.near.org",
|
|
10
|
+
Sandbox: "https://rpc.testnet.near.org",
|
|
36
11
|
};
|
|
37
12
|
exports.XRPL_RPC_URL = {
|
|
38
13
|
Production: "wss://xrplcluster.com",
|
|
39
14
|
Sandbox: "wss://s.altnet.rippletest.net:51233",
|
|
40
15
|
};
|
|
41
|
-
exports.XDB_PASSPHRASE = {
|
|
42
|
-
Production: "LiveNet Global XDBChain Network ; November 2023",
|
|
43
|
-
Sandbox: "Futurenet XDBChain Network ; October 2023",
|
|
44
|
-
};
|
|
45
16
|
exports.STELLAR_RPC_URL = {
|
|
46
17
|
Production: "https://horizon.stellar.org",
|
|
47
18
|
Sandbox: "https://horizon-testnet.stellar.org",
|
|
48
19
|
};
|
|
49
20
|
// Add USDC asset constants
|
|
50
|
-
exports.
|
|
21
|
+
exports.STELLAR_USDC_ISSUER = {
|
|
51
22
|
Sandbox: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
|
|
52
23
|
Production: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
|
|
53
24
|
};
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Provider } from "@near-js/providers";
|
|
2
|
+
import { FinalExecutionOutcome } from "@near-js/types";
|
|
3
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
4
|
+
import { Quote } from "../types";
|
|
5
|
+
export interface CreateAccountAction {
|
|
6
|
+
type: "CreateAccount";
|
|
7
|
+
}
|
|
8
|
+
export interface DeployContractAction {
|
|
9
|
+
type: "DeployContract";
|
|
10
|
+
params: {
|
|
11
|
+
code: Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface FunctionCallAction {
|
|
15
|
+
type: "FunctionCall";
|
|
16
|
+
params: {
|
|
17
|
+
methodName: string;
|
|
18
|
+
args: object;
|
|
19
|
+
gas: string;
|
|
20
|
+
deposit: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface TransferAction {
|
|
24
|
+
type: "Transfer";
|
|
25
|
+
params: {
|
|
26
|
+
deposit: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface StakeAction {
|
|
30
|
+
type: "Stake";
|
|
31
|
+
params: {
|
|
32
|
+
stake: string;
|
|
33
|
+
publicKey: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export type AddKeyPermission = "FullAccess" | {
|
|
37
|
+
receiverId: string;
|
|
38
|
+
methodNames: Array<string>;
|
|
39
|
+
allowance?: string;
|
|
40
|
+
};
|
|
41
|
+
export interface AddKeyAction {
|
|
42
|
+
type: "AddKey";
|
|
43
|
+
params: {
|
|
44
|
+
publicKey: string;
|
|
45
|
+
accessKey: {
|
|
46
|
+
nonce?: number;
|
|
47
|
+
permission: AddKeyPermission;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface DeleteKeyAction {
|
|
52
|
+
type: "DeleteKey";
|
|
53
|
+
params: {
|
|
54
|
+
publicKey: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface DeleteAccountAction {
|
|
58
|
+
type: "DeleteAccount";
|
|
59
|
+
params: {
|
|
60
|
+
beneficiaryId: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export type Action = CreateAccountAction | DeployContractAction | FunctionCallAction | TransferAction | StakeAction | AddKeyAction | DeleteKeyAction | DeleteAccountAction;
|
|
64
|
+
export type ActionType = Action["type"];
|
|
65
|
+
/**
|
|
66
|
+
* Makes action payload for function call in near contract
|
|
67
|
+
* @param methodName method name
|
|
68
|
+
* @param args an object that will be passed as argument to method
|
|
69
|
+
* @param gas gas fee
|
|
70
|
+
* @param deposit deposit amount
|
|
71
|
+
*/
|
|
72
|
+
export declare function createFunctionCall(methodName: string, args: object, gas: string, deposit: string): FunctionCallAction;
|
|
73
|
+
export interface Transaction {
|
|
74
|
+
signerId: string;
|
|
75
|
+
receiverId: string;
|
|
76
|
+
actions: Array<Action>;
|
|
77
|
+
}
|
|
78
|
+
export interface NearWallet {
|
|
79
|
+
signerId: string;
|
|
80
|
+
signAndSendTransaction: (transaction: Transaction) => Promise<FinalExecutionOutcome>;
|
|
81
|
+
}
|
|
82
|
+
export declare class NearService {
|
|
83
|
+
readonly wallet: NearWallet;
|
|
84
|
+
private apiService;
|
|
85
|
+
readonly provider: Provider;
|
|
86
|
+
constructor(wallet: NearWallet, apiConfig: APIConfig, options?: {
|
|
87
|
+
sandbox?: boolean;
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* Fetches a quote for Bitcoin transfer.
|
|
91
|
+
*
|
|
92
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
93
|
+
*/
|
|
94
|
+
fetchQuote(symbol?: string): Promise<Quote>;
|
|
95
|
+
/**
|
|
96
|
+
* Fetches the Bitcoin vault address.
|
|
97
|
+
*
|
|
98
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
99
|
+
*/
|
|
100
|
+
fetchVault(symbol?: string): Promise<{
|
|
101
|
+
address: string;
|
|
102
|
+
tag?: string;
|
|
103
|
+
}>;
|
|
104
|
+
transferNear(params: {
|
|
105
|
+
signerId?: string;
|
|
106
|
+
amount: string;
|
|
107
|
+
}): Promise<FinalExecutionOutcome>;
|
|
108
|
+
transferTokens(params: {
|
|
109
|
+
signerId?: string;
|
|
110
|
+
amount: string;
|
|
111
|
+
tokenContractId: string;
|
|
112
|
+
}): Promise<FinalExecutionOutcome>;
|
|
113
|
+
getNearBalance(params: {
|
|
114
|
+
signerId?: string;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
block_height: import("@near-js/types").BlockHeight;
|
|
117
|
+
block_hash: import("@near-js/types").BlockHash;
|
|
118
|
+
}>;
|
|
119
|
+
getTokenBalance(params: {
|
|
120
|
+
tokenContractId: string;
|
|
121
|
+
signerId?: string;
|
|
122
|
+
}): Promise<string>;
|
|
123
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NearService = void 0;
|
|
7
|
+
exports.createFunctionCall = createFunctionCall;
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
10
|
+
const providers_1 = require("@near-js/providers");
|
|
11
|
+
const utils_1 = require("@near-js/utils");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
14
|
+
/**
|
|
15
|
+
* Makes action payload for function call in near contract
|
|
16
|
+
* @param methodName method name
|
|
17
|
+
* @param args an object that will be passed as argument to method
|
|
18
|
+
* @param gas gas fee
|
|
19
|
+
* @param deposit deposit amount
|
|
20
|
+
*/
|
|
21
|
+
function createFunctionCall(methodName, args, gas, deposit) {
|
|
22
|
+
return {
|
|
23
|
+
type: "FunctionCall",
|
|
24
|
+
params: {
|
|
25
|
+
args,
|
|
26
|
+
deposit,
|
|
27
|
+
gas,
|
|
28
|
+
methodName,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
class NearService {
|
|
33
|
+
wallet;
|
|
34
|
+
apiService;
|
|
35
|
+
provider;
|
|
36
|
+
constructor(wallet, apiConfig, options) {
|
|
37
|
+
this.wallet = wallet;
|
|
38
|
+
const sandbox = options?.sandbox ? options.sandbox : false;
|
|
39
|
+
this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
|
|
40
|
+
const url = sandbox ? constants_1.NEAR_RPC_URL.Sandbox : constants_1.NEAR_RPC_URL.Production;
|
|
41
|
+
this.provider = new providers_1.JsonRpcProvider({ url });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetches a quote for Bitcoin transfer.
|
|
45
|
+
*
|
|
46
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
47
|
+
*/
|
|
48
|
+
async fetchQuote(symbol = "NEAR") {
|
|
49
|
+
const res = await this.apiService.fetchQuote(symbol);
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetches the Bitcoin vault address.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
56
|
+
*/
|
|
57
|
+
async fetchVault(symbol = "NEAR") {
|
|
58
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
async transferNear(params) {
|
|
62
|
+
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
63
|
+
const fetchVault = await this.fetchVault();
|
|
64
|
+
const destination = fetchVault.address;
|
|
65
|
+
console.debug("destination:", destination);
|
|
66
|
+
const parsedAmount = (0, utils_1.parseNearAmount)(params.amount);
|
|
67
|
+
(0, assert_1.default)(parsedAmount, "Amount might be missing.");
|
|
68
|
+
const action = {
|
|
69
|
+
type: "Transfer",
|
|
70
|
+
params: {
|
|
71
|
+
deposit: parsedAmount,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const outcome = await this.wallet.signAndSendTransaction({
|
|
75
|
+
signerId: signerId,
|
|
76
|
+
receiverId: destination,
|
|
77
|
+
actions: [action],
|
|
78
|
+
});
|
|
79
|
+
return outcome;
|
|
80
|
+
}
|
|
81
|
+
async transferTokens(params) {
|
|
82
|
+
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
83
|
+
const fetchVault = await this.fetchVault("NEAR-USDC");
|
|
84
|
+
const destination = fetchVault.address;
|
|
85
|
+
console.debug("destination:", destination);
|
|
86
|
+
const metadataResult = await this.provider.query({
|
|
87
|
+
request_type: "call_function",
|
|
88
|
+
finality: "final",
|
|
89
|
+
account_id: params.tokenContractId,
|
|
90
|
+
method_name: "ft_metadata",
|
|
91
|
+
args_base64: Buffer.from(JSON.stringify({})).toString("base64"),
|
|
92
|
+
});
|
|
93
|
+
const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
|
|
94
|
+
const tokenDecimals = metadata.decimals;
|
|
95
|
+
const parsedAmount = (0, bignumber_js_1.BigNumber)(params.amount)
|
|
96
|
+
.times((0, bignumber_js_1.BigNumber)(10).pow(tokenDecimals))
|
|
97
|
+
.toFixed(0);
|
|
98
|
+
const GAS = "30000000000000";
|
|
99
|
+
const secutityDeposit = "1";
|
|
100
|
+
const action = createFunctionCall("ft_transfer", {
|
|
101
|
+
receiver_id: destination,
|
|
102
|
+
amount: parsedAmount,
|
|
103
|
+
memo: null,
|
|
104
|
+
}, GAS, secutityDeposit);
|
|
105
|
+
const outcome = await this.wallet.signAndSendTransaction({
|
|
106
|
+
signerId: signerId,
|
|
107
|
+
receiverId: params.tokenContractId,
|
|
108
|
+
actions: [action],
|
|
109
|
+
});
|
|
110
|
+
return outcome;
|
|
111
|
+
}
|
|
112
|
+
async getNearBalance(params) {
|
|
113
|
+
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
114
|
+
const result = await this.provider.query({
|
|
115
|
+
request_type: "view_account",
|
|
116
|
+
account_id: signerId,
|
|
117
|
+
finality: "final",
|
|
118
|
+
});
|
|
119
|
+
return { ...result };
|
|
120
|
+
}
|
|
121
|
+
async getTokenBalance(params) {
|
|
122
|
+
const signerId = params.signerId ? params.signerId : this.wallet.signerId;
|
|
123
|
+
const metadataResult = await this.provider.query({
|
|
124
|
+
request_type: "call_function",
|
|
125
|
+
finality: "final",
|
|
126
|
+
account_id: params.tokenContractId,
|
|
127
|
+
method_name: "ft_metadata",
|
|
128
|
+
args_base64: Buffer.from(JSON.stringify({})).toString("base64"),
|
|
129
|
+
});
|
|
130
|
+
const result = await this.provider.query({
|
|
131
|
+
request_type: "call_function",
|
|
132
|
+
finality: "final",
|
|
133
|
+
account_id: params.tokenContractId,
|
|
134
|
+
method_name: "ft_balance_of",
|
|
135
|
+
args_base64: Buffer.from(JSON.stringify({
|
|
136
|
+
account_id: signerId,
|
|
137
|
+
})).toString("base64"),
|
|
138
|
+
});
|
|
139
|
+
const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
|
|
140
|
+
const decimals = metadata.decimals;
|
|
141
|
+
const data = JSON.parse(Buffer.from(result.result).toString());
|
|
142
|
+
return (0, bignumber_js_1.BigNumber)(data).div((0, bignumber_js_1.BigNumber)(10).pow(decimals)).toFixed();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.NearService = NearService;
|
|
@@ -127,7 +127,7 @@ class StellarService {
|
|
|
127
127
|
const account = await this.server.loadAccount(accountAddress.address);
|
|
128
128
|
const fee = await this.server.fetchBaseFee();
|
|
129
129
|
// Create USDC asset object
|
|
130
|
-
const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.
|
|
130
|
+
const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.STELLAR_USDC_ISSUER.Sandbox : constants_1.STELLAR_USDC_ISSUER.Production);
|
|
131
131
|
// Check Wallet balance
|
|
132
132
|
const balance = await this.getTokenBalance(accountAddress.address, usdcAsset);
|
|
133
133
|
if (Number(balance) < Number(amount)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseTransaction, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
1
|
+
import { BaseTransaction, Client, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
2
2
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
3
|
import { Quote } from "../types";
|
|
4
4
|
export interface XRPLWallet {
|
|
@@ -8,7 +8,7 @@ export interface XRPLWallet {
|
|
|
8
8
|
export declare class XRPLService {
|
|
9
9
|
readonly wallet: XRPLWallet;
|
|
10
10
|
private apiService;
|
|
11
|
-
|
|
11
|
+
readonly client: Client;
|
|
12
12
|
constructor(wallet: XRPLWallet, apiConfig: APIConfig, options?: {
|
|
13
13
|
sandbox?: boolean;
|
|
14
14
|
});
|
|
@@ -37,14 +37,19 @@ export declare class XRPLService {
|
|
|
37
37
|
token: {
|
|
38
38
|
currency: string;
|
|
39
39
|
issuer: string;
|
|
40
|
-
ticker: number;
|
|
41
40
|
};
|
|
42
41
|
}): Promise<TxResponse<Transaction>>;
|
|
43
|
-
|
|
42
|
+
createTrustLine(params: {
|
|
43
|
+
walletAddress?: string;
|
|
44
|
+
amount: string;
|
|
45
|
+
token: {
|
|
46
|
+
currency: string;
|
|
47
|
+
issuer: string;
|
|
48
|
+
};
|
|
49
|
+
}): Promise<TxResponse<Transaction>>;
|
|
44
50
|
getTokenBalances(walletAddress?: string): Promise<{
|
|
45
51
|
value: string;
|
|
46
52
|
currency: string;
|
|
47
53
|
issuer?: string | undefined;
|
|
48
54
|
}[]>;
|
|
49
|
-
getDecimalsOfCurrency(currencyHolder: string, currency: string): Promise<number>;
|
|
50
55
|
}
|
|
@@ -78,16 +78,13 @@ class XRPLService {
|
|
|
78
78
|
if (!(0, xrpl_1.isValidAddress)(destination)) {
|
|
79
79
|
throw new Error("Invalid destination address");
|
|
80
80
|
}
|
|
81
|
-
const amount = BigNumber(params.amount)
|
|
82
|
-
.times(BigNumber(10).pow(params.token.ticker))
|
|
83
|
-
.toFixed(0);
|
|
84
81
|
const transaction = {
|
|
85
82
|
TransactionType: "Payment",
|
|
86
83
|
Account: walletAddress,
|
|
87
84
|
Destination: destination,
|
|
88
85
|
Amount: {
|
|
89
86
|
currency: params.token.currency,
|
|
90
|
-
value: amount,
|
|
87
|
+
value: params.amount,
|
|
91
88
|
issuer: params.token.issuer,
|
|
92
89
|
},
|
|
93
90
|
};
|
|
@@ -105,17 +102,26 @@ class XRPLService {
|
|
|
105
102
|
await this.client.disconnect();
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
async
|
|
109
|
-
const
|
|
110
|
-
if (!(0, xrpl_1.isValidAddress)(
|
|
105
|
+
async createTrustLine(params) {
|
|
106
|
+
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
107
|
+
if (!(0, xrpl_1.isValidAddress)(walletAddress)) {
|
|
111
108
|
throw new Error("Invalid wallet address");
|
|
112
109
|
}
|
|
110
|
+
const transaction = {
|
|
111
|
+
TransactionType: "TrustSet",
|
|
112
|
+
Account: walletAddress,
|
|
113
|
+
LimitAmount: {
|
|
114
|
+
currency: params.token.currency,
|
|
115
|
+
issuer: params.token.issuer,
|
|
116
|
+
value: params.amount,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
113
119
|
await this.client.connect();
|
|
114
120
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return
|
|
121
|
+
const preparedTx = await this.client.autofill(transaction);
|
|
122
|
+
const signedTx = await this.wallet.signTransaction(preparedTx);
|
|
123
|
+
const response = await this.client.submitAndWait(signedTx);
|
|
124
|
+
return response;
|
|
119
125
|
}
|
|
120
126
|
catch (error) {
|
|
121
127
|
throw error;
|
|
@@ -143,26 +149,5 @@ class XRPLService {
|
|
|
143
149
|
await this.client.disconnect();
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
async getDecimalsOfCurrency(currencyHolder, currency) {
|
|
147
|
-
await this.client.connect();
|
|
148
|
-
try {
|
|
149
|
-
const response = await this.client.getBalances(currencyHolder, {
|
|
150
|
-
ledger_index: "validated",
|
|
151
|
-
});
|
|
152
|
-
const row = response.find((l) => l.currency === currency);
|
|
153
|
-
if (!row) {
|
|
154
|
-
throw new Error("Currency not found in holders account");
|
|
155
|
-
}
|
|
156
|
-
// just a work around. change this if found a better way to get decimals
|
|
157
|
-
const splits = row.value.split(".");
|
|
158
|
-
return splits.length === 2 ? splits[1].length : 0; // if it returns zero, then it is a whole number and it's a problem !!!
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
await this.client.disconnect();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
152
|
}
|
|
168
153
|
exports.XRPLService = XRPLService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.1.10
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "An sdk for purchasing silver card in zebec",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@dashevo/dapi-client": "^1.8.0",
|
|
21
|
+
"@near-js/accounts": "^2.0.1",
|
|
22
|
+
"@near-js/keystores": "^2.0.1",
|
|
23
|
+
"@near-js/signers": "^2.0.1",
|
|
21
24
|
"@typechain/ethers-v6": "^0.5.1",
|
|
22
25
|
"@types/jsonwebtoken": "^9.0.7",
|
|
23
26
|
"@types/mocha": "^10.0.9",
|
|
@@ -34,16 +37,15 @@
|
|
|
34
37
|
"dependencies": {
|
|
35
38
|
"@creit.tech/stellar-wallets-kit": "^1.7.1",
|
|
36
39
|
"@mempool/mempool.js": "^3.0.0",
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
+
"@near-js/crypto": "^2.0.1",
|
|
41
|
+
"@near-js/providers": "^2.0.1",
|
|
42
|
+
"@near-js/transactions": "^2.0.1",
|
|
43
|
+
"@near-js/types": "^2.0.1",
|
|
44
|
+
"@near-js/utils": "^2.0.1",
|
|
40
45
|
"@stellar/stellar-sdk": "^13.1.0",
|
|
41
|
-
"@tonconnect/sdk": "^3.0.6",
|
|
42
46
|
"axios": "^1.7.7",
|
|
47
|
+
"bignumber.js": "^9.3.0",
|
|
43
48
|
"bitcoinjs-lib": "^6.1.7",
|
|
44
|
-
"ethers": "^6.13.4",
|
|
45
|
-
"tonweb": "^0.0.66",
|
|
46
|
-
"xdb-digitalbits-sdk": "^8.2.2",
|
|
47
49
|
"xrpl": "^4.2.5"
|
|
48
50
|
},
|
|
49
51
|
"repository": {
|