@zebec-network/exchange-card-sdk 1.1.9-beta.2 → 1.1.10-beta.1
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/LICENSE +21 -21
- package/dist/chains.d.ts +2 -7
- package/dist/chains.js +10 -7
- package/dist/constants.d.ts +7 -2
- package/dist/constants.js +13 -15
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/services/EvmService.d.ts +1 -1
- package/dist/services/EvmService.js +3 -3
- package/dist/services/TaoService.d.ts +2 -2
- package/dist/services/TaoService.js +2 -3
- package/dist/services/XdbService.d.ts +1 -1
- package/dist/services/XdbService.js +3 -3
- package/dist/services/bitcoinService.d.ts +56 -0
- package/dist/services/bitcoinService.js +195 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.js +23 -0
- package/dist/services/stellarService.js +1 -3
- package/dist/services/xrplService.d.ts +50 -0
- package/dist/services/xrplService.js +168 -0
- package/package.json +62 -58
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Zebec Fintech Labs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Zebec Fintech Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/chains.d.ts
CHANGED
|
@@ -7,12 +7,7 @@ export declare enum SupportedChain {
|
|
|
7
7
|
Base = 8453,
|
|
8
8
|
Bsc = 56,
|
|
9
9
|
BscTestnet = 97,
|
|
10
|
-
|
|
11
|
-
BittensorTestnet = 559,
|
|
12
|
-
Ton = -239,
|
|
13
|
-
TonTestnet = -3,
|
|
14
|
-
XdbChain = -4,
|
|
15
|
-
Stellar = -5
|
|
10
|
+
Polygon = 137
|
|
16
11
|
}
|
|
17
|
-
export declare const TESTNET_CHAINIDS:
|
|
12
|
+
export declare const TESTNET_CHAINIDS: SupportedChain[];
|
|
18
13
|
export declare function parseSupportedChain(chainId: number): SupportedChain;
|
package/dist/chains.js
CHANGED
|
@@ -13,14 +13,15 @@ var SupportedChain;
|
|
|
13
13
|
SupportedChain[SupportedChain["Base"] = 8453] = "Base";
|
|
14
14
|
SupportedChain[SupportedChain["Bsc"] = 56] = "Bsc";
|
|
15
15
|
SupportedChain[SupportedChain["BscTestnet"] = 97] = "BscTestnet";
|
|
16
|
-
SupportedChain[SupportedChain["
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
SupportedChain[SupportedChain["Polygon"] = 137] = "Polygon";
|
|
17
|
+
// Bittensor = 558,
|
|
18
|
+
// BittensorTestnet = 559,
|
|
19
|
+
// Ton = -239,
|
|
20
|
+
// TonTestnet = -3,
|
|
21
|
+
// XdbChain = -4,
|
|
22
|
+
// Stellar = -5,
|
|
22
23
|
})(SupportedChain || (exports.SupportedChain = SupportedChain = {}));
|
|
23
|
-
exports.TESTNET_CHAINIDS = [
|
|
24
|
+
exports.TESTNET_CHAINIDS = [SupportedChain.Sepolia, SupportedChain.BscTestnet];
|
|
24
25
|
function parseSupportedChain(chainId) {
|
|
25
26
|
switch (chainId) {
|
|
26
27
|
case 1:
|
|
@@ -33,6 +34,8 @@ function parseSupportedChain(chainId) {
|
|
|
33
34
|
return SupportedChain.Bsc;
|
|
34
35
|
case 97:
|
|
35
36
|
return SupportedChain.BscTestnet;
|
|
37
|
+
case 137:
|
|
38
|
+
return SupportedChain.Polygon;
|
|
36
39
|
default:
|
|
37
40
|
throw new errors_1.UnsupportedChainError(chainId);
|
|
38
41
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,11 +5,16 @@ export declare const CARD_API_URL: Record<"Production" | "Sandbox", string>;
|
|
|
5
5
|
export declare const TAO_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
6
6
|
export declare const TON_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
7
7
|
export declare const DIGITALBITS_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
8
|
+
export declare const XRPL_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
8
9
|
export declare const XDB_PASSPHRASE: Record<"Production" | "Sandbox", string>;
|
|
9
10
|
export declare const STELLAR_RPC_URL: Record<"Production" | "Sandbox", string>;
|
|
10
11
|
export declare const USDC_ISSUER: {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
readonly Sandbox: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
|
|
13
|
+
readonly Production: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
|
|
14
|
+
};
|
|
15
|
+
export declare const BITCOIN_ENDPOINTS: {
|
|
16
|
+
readonly Sandbox: "https://mempool.space/testnet/api";
|
|
17
|
+
readonly Production: "https://mempool.space/api";
|
|
13
18
|
};
|
|
14
19
|
export declare const COUNTRIES_WITH_CCA3: readonly [{
|
|
15
20
|
readonly name: {
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PLATFORM_FEE = exports.COUNTRIES_WITH_CCA3 = exports.USDC_ISSUER = exports.STELLAR_RPC_URL = exports.XDB_PASSPHRASE = exports.DIGITALBITS_RPC_URL = exports.TON_RPC_URL = exports.TAO_RPC_URL = exports.CARD_API_URL = exports.USDC_ADDRESS = exports.ZEBEC_CARD_ADDRESS = void 0;
|
|
3
|
+
exports.PLATFORM_FEE = exports.COUNTRIES_WITH_CCA3 = exports.BITCOIN_ENDPOINTS = exports.USDC_ISSUER = exports.STELLAR_RPC_URL = exports.XDB_PASSPHRASE = exports.XRPL_RPC_URL = exports.DIGITALBITS_RPC_URL = exports.TON_RPC_URL = exports.TAO_RPC_URL = exports.CARD_API_URL = exports.USDC_ADDRESS = exports.ZEBEC_CARD_ADDRESS = void 0;
|
|
4
4
|
const chains_1 = require("./chains");
|
|
5
5
|
exports.ZEBEC_CARD_ADDRESS = {
|
|
6
6
|
[chains_1.SupportedChain.Sepolia]: "0x00d90625CcaB01eA0e589DFd3C99972180CE609A",
|
|
@@ -8,12 +8,7 @@ exports.ZEBEC_CARD_ADDRESS = {
|
|
|
8
8
|
[chains_1.SupportedChain.Mainnet]: "0xB4f6E946E12200F4E0ba3B352B8DbF0a66635b53",
|
|
9
9
|
[chains_1.SupportedChain.Bsc]: "0x1bF6419D8555EafaE79142D309534e8aBd54aBa3",
|
|
10
10
|
[chains_1.SupportedChain.BscTestnet]: "0x9061E6eB59890D33C94B9f517c3dba30621fAB2f",
|
|
11
|
-
[chains_1.SupportedChain.
|
|
12
|
-
[chains_1.SupportedChain.BittensorTestnet]: "",
|
|
13
|
-
[chains_1.SupportedChain.Ton]: "",
|
|
14
|
-
[chains_1.SupportedChain.TonTestnet]: "",
|
|
15
|
-
[chains_1.SupportedChain.XdbChain]: "",
|
|
16
|
-
[chains_1.SupportedChain.Stellar]: "",
|
|
11
|
+
[chains_1.SupportedChain.Polygon]: "",
|
|
17
12
|
};
|
|
18
13
|
exports.USDC_ADDRESS = {
|
|
19
14
|
[chains_1.SupportedChain.Sepolia]: "0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8",
|
|
@@ -21,12 +16,7 @@ exports.USDC_ADDRESS = {
|
|
|
21
16
|
[chains_1.SupportedChain.Mainnet]: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
22
17
|
[chains_1.SupportedChain.Bsc]: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
23
18
|
[chains_1.SupportedChain.BscTestnet]: "0xF8Dc6f35a10244213096D86c376491042594a84e",
|
|
24
|
-
[chains_1.SupportedChain.
|
|
25
|
-
[chains_1.SupportedChain.BittensorTestnet]: "",
|
|
26
|
-
[chains_1.SupportedChain.Ton]: "",
|
|
27
|
-
[chains_1.SupportedChain.TonTestnet]: "",
|
|
28
|
-
[chains_1.SupportedChain.XdbChain]: "",
|
|
29
|
-
[chains_1.SupportedChain.Stellar]: "",
|
|
19
|
+
[chains_1.SupportedChain.Polygon]: "",
|
|
30
20
|
};
|
|
31
21
|
exports.CARD_API_URL = {
|
|
32
22
|
Production: "https://cex.card.zebec.io",
|
|
@@ -44,6 +34,10 @@ exports.DIGITALBITS_RPC_URL = {
|
|
|
44
34
|
Production: "https://horizon.livenet.xdbchain.com",
|
|
45
35
|
Sandbox: "https://horizon.futurenet.xdbchain.com",
|
|
46
36
|
};
|
|
37
|
+
exports.XRPL_RPC_URL = {
|
|
38
|
+
Production: "wss://xrplcluster.com",
|
|
39
|
+
Sandbox: "wss://s.altnet.rippletest.net:51233",
|
|
40
|
+
};
|
|
47
41
|
exports.XDB_PASSPHRASE = {
|
|
48
42
|
Production: "LiveNet Global XDBChain Network ; November 2023",
|
|
49
43
|
Sandbox: "Futurenet XDBChain Network ; October 2023",
|
|
@@ -54,8 +48,12 @@ exports.STELLAR_RPC_URL = {
|
|
|
54
48
|
};
|
|
55
49
|
// Add USDC asset constants
|
|
56
50
|
exports.USDC_ISSUER = {
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
Sandbox: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
|
|
52
|
+
Production: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
|
|
53
|
+
};
|
|
54
|
+
exports.BITCOIN_ENDPOINTS = {
|
|
55
|
+
Sandbox: "https://mempool.space/testnet/api",
|
|
56
|
+
Production: "https://mempool.space/api",
|
|
59
57
|
};
|
|
60
58
|
exports.COUNTRIES_WITH_CCA3 = [
|
|
61
59
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ export * from "./artifacts";
|
|
|
2
2
|
export * from "./chains";
|
|
3
3
|
export * from "./constants";
|
|
4
4
|
export * from "./errors";
|
|
5
|
-
export * from "./services
|
|
6
|
-
export * from "./services/TaoService";
|
|
7
|
-
export * from "./services/TonService";
|
|
8
|
-
export * from "./services/stellarService";
|
|
5
|
+
export * from "./services";
|
|
9
6
|
export * from "./types";
|
|
10
7
|
export * from "./utils";
|
package/dist/index.js
CHANGED
|
@@ -18,9 +18,6 @@ __exportStar(require("./artifacts"), exports);
|
|
|
18
18
|
__exportStar(require("./chains"), exports);
|
|
19
19
|
__exportStar(require("./constants"), exports);
|
|
20
20
|
__exportStar(require("./errors"), exports);
|
|
21
|
-
__exportStar(require("./services
|
|
22
|
-
__exportStar(require("./services/TaoService"), exports);
|
|
23
|
-
__exportStar(require("./services/TonService"), exports);
|
|
24
|
-
__exportStar(require("./services/stellarService"), exports);
|
|
21
|
+
__exportStar(require("./services"), exports);
|
|
25
22
|
__exportStar(require("./types"), exports);
|
|
26
23
|
__exportStar(require("./utils"), exports);
|
|
@@ -2,8 +2,8 @@ import { AxiosResponse } from "axios";
|
|
|
2
2
|
import { ethers } from "ethers";
|
|
3
3
|
import { ERC20, ZebecCard } from "../artifacts";
|
|
4
4
|
import { SupportedChain } from "../chains";
|
|
5
|
-
import { Quote, Recipient } from "../types";
|
|
6
5
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
6
|
+
import { Quote, Recipient } from "../types";
|
|
7
7
|
export declare class ZebecCardService {
|
|
8
8
|
readonly signer: ethers.Signer;
|
|
9
9
|
readonly zebecCard: ZebecCard;
|
|
@@ -7,9 +7,9 @@ const artifacts_1 = require("../artifacts");
|
|
|
7
7
|
const chains_1 = require("../chains");
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
const errors_1 = require("../errors");
|
|
10
|
+
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
10
11
|
const types_1 = require("../types");
|
|
11
12
|
const utils_1 = require("../utils");
|
|
12
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
13
13
|
class ZebecCardService {
|
|
14
14
|
signer;
|
|
15
15
|
zebecCard;
|
|
@@ -19,12 +19,12 @@ class ZebecCardService {
|
|
|
19
19
|
constructor(signer, chainId, apiConfig, sdkOptions) {
|
|
20
20
|
this.signer = signer;
|
|
21
21
|
const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
|
|
22
|
-
|
|
22
|
+
this.chainId = (0, chains_1.parseSupportedChain)(chainId);
|
|
23
|
+
const isTesnetChainId = chains_1.TESTNET_CHAINIDS.includes(this.chainId);
|
|
23
24
|
if ((sandbox && !isTesnetChainId) || (!sandbox && isTesnetChainId)) {
|
|
24
25
|
throw new Error("Only testnet chains are allowed in sandbox environment");
|
|
25
26
|
}
|
|
26
27
|
this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
|
|
27
|
-
this.chainId = (0, chains_1.parseSupportedChain)(chainId);
|
|
28
28
|
const zebecCardAddress = constants_1.ZEBEC_CARD_ADDRESS[this.chainId];
|
|
29
29
|
const usdcAddress = constants_1.USDC_ADDRESS[this.chainId];
|
|
30
30
|
this.zebecCard = artifacts_1.ZebecCard__factory.connect(zebecCardAddress, signer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Quote } from "../types";
|
|
2
|
-
import { Signer } from "@polkadot/types/types";
|
|
3
1
|
import { KeyringPair } from "@polkadot/keyring/types";
|
|
2
|
+
import { Signer } from "@polkadot/types/types";
|
|
4
3
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
4
|
+
import { Quote } from "../types";
|
|
5
5
|
export declare class ZebecCardTAOService {
|
|
6
6
|
readonly signer: Signer | KeyringPair;
|
|
7
7
|
private apiService;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZebecCardTAOService = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
4
|
const api_1 = require("@polkadot/api");
|
|
6
|
-
const
|
|
5
|
+
const constants_1 = require("../constants");
|
|
7
6
|
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
8
7
|
class ZebecCardTAOService {
|
|
9
8
|
signer;
|
|
@@ -54,7 +53,7 @@ class ZebecCardTAOService {
|
|
|
54
53
|
async transferTAO(params) {
|
|
55
54
|
// Connect to TAO network
|
|
56
55
|
const provider = new api_1.WsProvider(this.taoRPC);
|
|
57
|
-
const api = await
|
|
56
|
+
const api = await api_1.ApiPromise.create({ provider });
|
|
58
57
|
try {
|
|
59
58
|
// Calculate total amount with proper decimal places
|
|
60
59
|
const totalAmount = Math.floor(params.amount * 10 ** 9);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StellarWalletsKit } from "@creit.tech/stellar-wallets-kit";
|
|
2
2
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
3
|
import { Quote } from "../types";
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class XDBService {
|
|
5
5
|
readonly kit: StellarWalletsKit;
|
|
6
6
|
private apiService;
|
|
7
7
|
private server;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.XDBService = void 0;
|
|
4
4
|
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class
|
|
7
|
+
class XDBService {
|
|
8
8
|
kit;
|
|
9
9
|
apiService;
|
|
10
10
|
server;
|
|
@@ -115,4 +115,4 @@ class StellarService {
|
|
|
115
115
|
return nativeBalance ? nativeBalance.balance : "0";
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
exports.
|
|
118
|
+
exports.XDBService = XDBService;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
2
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
|
+
import { Quote } from "../types";
|
|
4
|
+
interface BitcoinWallet {
|
|
5
|
+
address: string;
|
|
6
|
+
signTransaction: (psbt: bitcoin.Psbt) => Promise<bitcoin.Psbt>;
|
|
7
|
+
broadcastTransaction: (tx: string) => Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
export declare class BitcoinService {
|
|
10
|
+
readonly wallet: BitcoinWallet;
|
|
11
|
+
private apiService;
|
|
12
|
+
private network;
|
|
13
|
+
private apiEndpoint;
|
|
14
|
+
constructor(wallet: BitcoinWallet, apiConfig: APIConfig, sdkOptions?: {
|
|
15
|
+
sandbox?: boolean;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Fetches a quote for Bitcoin transfer.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
22
|
+
*/
|
|
23
|
+
fetchQuote(): Promise<Quote>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the Bitcoin vault address.
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
28
|
+
*/
|
|
29
|
+
fetchVault(): Promise<{
|
|
30
|
+
address: string;
|
|
31
|
+
tag?: string;
|
|
32
|
+
}>;
|
|
33
|
+
getUTXOs(): Promise<Array<{
|
|
34
|
+
txid: string;
|
|
35
|
+
vout: number;
|
|
36
|
+
value: number;
|
|
37
|
+
rawTx: Buffer;
|
|
38
|
+
}>>;
|
|
39
|
+
private getBalance;
|
|
40
|
+
/**
|
|
41
|
+
* Transfers Bitcoin to the vault address.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} amount - The amount of BTC to transfer in BTC units
|
|
44
|
+
* @param {number} feeRate - Fee rate in satoshis per byte
|
|
45
|
+
* @returns {Promise<string>} - A promise that resolves to the transaction hash
|
|
46
|
+
* @throws {Error} If there is not enough balance or if the transaction fails.
|
|
47
|
+
*/
|
|
48
|
+
transferBTC(amount: string, feeRate?: number): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the balance of the Bitcoin wallet.
|
|
51
|
+
*
|
|
52
|
+
* @returns {Promise<string>} - A promise that resolves to the wallet balance in BTC
|
|
53
|
+
*/
|
|
54
|
+
getWalletBalance(): Promise<string>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.BitcoinService = void 0;
|
|
40
|
+
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
42
|
+
const constants_1 = require("../constants");
|
|
43
|
+
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
44
|
+
class BitcoinService {
|
|
45
|
+
wallet;
|
|
46
|
+
apiService;
|
|
47
|
+
network;
|
|
48
|
+
apiEndpoint;
|
|
49
|
+
constructor(wallet, apiConfig, sdkOptions) {
|
|
50
|
+
this.wallet = wallet;
|
|
51
|
+
const sandbox = sdkOptions?.sandbox ?? false;
|
|
52
|
+
this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
|
|
53
|
+
this.network = sandbox ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
54
|
+
this.apiEndpoint = sandbox ? constants_1.BITCOIN_ENDPOINTS.Sandbox : constants_1.BITCOIN_ENDPOINTS.Production;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetches a quote for Bitcoin transfer.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
60
|
+
*/
|
|
61
|
+
async fetchQuote() {
|
|
62
|
+
const res = await this.apiService.fetchQuote("BTC");
|
|
63
|
+
return res;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Fetches the Bitcoin vault address.
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
69
|
+
*/
|
|
70
|
+
async fetchVault() {
|
|
71
|
+
const data = await this.apiService.fetchVault("BTC");
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
async getUTXOs() {
|
|
75
|
+
const response = await axios_1.default.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
|
|
76
|
+
console.log("utxos:", response.data);
|
|
77
|
+
return Promise.all(response.data.map(async (utxo) => {
|
|
78
|
+
const rawTx = await axios_1.default.get(`${this.apiEndpoint}/tx/${utxo.txid}/hex`);
|
|
79
|
+
console.log("txHex:", rawTx.data);
|
|
80
|
+
if (!rawTx.data) {
|
|
81
|
+
throw new Error("Transaction not found");
|
|
82
|
+
}
|
|
83
|
+
// const scriptPubKey = txResponse.data.vout[utxo.vout].scriptpubkey;
|
|
84
|
+
return {
|
|
85
|
+
txid: utxo.txid,
|
|
86
|
+
vout: utxo.vout,
|
|
87
|
+
value: utxo.value,
|
|
88
|
+
rawTx: Buffer.from(rawTx.data, "hex"),
|
|
89
|
+
};
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
async getBalance() {
|
|
93
|
+
const response = await axios_1.default.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
|
|
94
|
+
const utxos = response.data;
|
|
95
|
+
return utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Transfers Bitcoin to the vault address.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} amount - The amount of BTC to transfer in BTC units
|
|
101
|
+
* @param {number} feeRate - Fee rate in satoshis per byte
|
|
102
|
+
* @returns {Promise<string>} - A promise that resolves to the transaction hash
|
|
103
|
+
* @throws {Error} If there is not enough balance or if the transaction fails.
|
|
104
|
+
*/
|
|
105
|
+
async transferBTC(amount, feeRate = 10) {
|
|
106
|
+
// Convert BTC to satoshis
|
|
107
|
+
const satoshisToSend = Math.floor(Number(amount) * 100_000_000);
|
|
108
|
+
// Fetch deposit address
|
|
109
|
+
const vault = await this.fetchVault();
|
|
110
|
+
console.log({ vault });
|
|
111
|
+
let retries = 0;
|
|
112
|
+
const maxRetries = 5;
|
|
113
|
+
let delay = 1000;
|
|
114
|
+
const psbt = new bitcoin.Psbt({ network: this.network });
|
|
115
|
+
const utxos = await this.getUTXOs();
|
|
116
|
+
let inputAmount = 0;
|
|
117
|
+
for (const utxo of utxos) {
|
|
118
|
+
const transaction = bitcoin.Transaction.fromBuffer(utxo.rawTx);
|
|
119
|
+
const script = transaction.outs[utxo.vout].script;
|
|
120
|
+
const value = transaction.outs[utxo.vout].value;
|
|
121
|
+
inputAmount += value;
|
|
122
|
+
psbt.addInput({
|
|
123
|
+
hash: utxo.txid,
|
|
124
|
+
index: utxo.vout,
|
|
125
|
+
// nonWitnessUtxo: utxo.rawTx,
|
|
126
|
+
witnessUtxo: {
|
|
127
|
+
script: script,
|
|
128
|
+
value: value,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
if (inputAmount >= satoshisToSend)
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (inputAmount < satoshisToSend) {
|
|
135
|
+
throw new Error("Insufficient UTXO amount");
|
|
136
|
+
}
|
|
137
|
+
// Add output for payment
|
|
138
|
+
psbt.addOutput({
|
|
139
|
+
// address: vault.address,
|
|
140
|
+
address: "tb1q6h8w53xzj74n28kg8qq3d78xxgrch8zd2km97d",
|
|
141
|
+
value: satoshisToSend,
|
|
142
|
+
});
|
|
143
|
+
// Add change output if necessary
|
|
144
|
+
const estimatedFee = Math.ceil(psbt.toBuffer().length * feeRate);
|
|
145
|
+
// Check wallet balance
|
|
146
|
+
const balance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
147
|
+
if (balance < satoshisToSend + estimatedFee) {
|
|
148
|
+
throw new Error("Insufficient balance");
|
|
149
|
+
}
|
|
150
|
+
const changeAmount = inputAmount - satoshisToSend - estimatedFee;
|
|
151
|
+
if (changeAmount > 0) {
|
|
152
|
+
psbt.addOutput({
|
|
153
|
+
address: this.wallet.address,
|
|
154
|
+
value: changeAmount,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
console.log("psbt:", JSON.stringify(psbt));
|
|
158
|
+
// Sign transaction
|
|
159
|
+
const signedPsbt = await this.wallet.signTransaction(psbt);
|
|
160
|
+
const tx = signedPsbt.finalizeAllInputs().extractTransaction();
|
|
161
|
+
while (retries < maxRetries) {
|
|
162
|
+
try {
|
|
163
|
+
// Broadcast transaction
|
|
164
|
+
return this.wallet.broadcastTransaction(tx.toHex());
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.debug("error: ", error);
|
|
168
|
+
if (retries >= maxRetries) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
retries += 1;
|
|
172
|
+
console.debug(`Retrying in ${delay / 1000} seconds...`);
|
|
173
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
174
|
+
delay *= 2; // Exponential backoff
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
throw new Error("Max retries reached");
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Gets the balance of the Bitcoin wallet.
|
|
181
|
+
*
|
|
182
|
+
* @returns {Promise<string>} - A promise that resolves to the wallet balance in BTC
|
|
183
|
+
*/
|
|
184
|
+
async getWalletBalance() {
|
|
185
|
+
try {
|
|
186
|
+
const balanceSats = await this.getBalance();
|
|
187
|
+
return (balanceSats / 100_000_000).toString();
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.debug("Error fetching BTC balance:", error);
|
|
191
|
+
return "0";
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.BitcoinService = BitcoinService;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// export * from "./bitcoinService";
|
|
18
|
+
// export * from "./EvmService";
|
|
19
|
+
__exportStar(require("./stellarService"), exports);
|
|
20
|
+
__exportStar(require("./TaoService"), exports);
|
|
21
|
+
__exportStar(require("./TonService"), exports);
|
|
22
|
+
__exportStar(require("./XdbService"), exports);
|
|
23
|
+
__exportStar(require("./xrplService"), exports);
|
|
@@ -126,10 +126,8 @@ class StellarService {
|
|
|
126
126
|
// Prepare transaction
|
|
127
127
|
const account = await this.server.loadAccount(accountAddress.address);
|
|
128
128
|
const fee = await this.server.fetchBaseFee();
|
|
129
|
-
console.log("vault address: ", vault.address);
|
|
130
|
-
// const memo = Memo.id(vault.tag?.toString() || "");
|
|
131
129
|
// Create USDC asset object
|
|
132
|
-
const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.USDC_ISSUER.
|
|
130
|
+
const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.USDC_ISSUER.Sandbox : constants_1.USDC_ISSUER.Production);
|
|
133
131
|
// Check Wallet balance
|
|
134
132
|
const balance = await this.getTokenBalance(accountAddress.address, usdcAsset);
|
|
135
133
|
if (Number(balance) < Number(amount)) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseTransaction, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
2
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
|
+
import { Quote } from "../types";
|
|
4
|
+
export interface XRPLWallet {
|
|
5
|
+
address: string;
|
|
6
|
+
signTransaction: (transaction: SubmittableTransaction | BaseTransaction) => Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
export declare class XRPLService {
|
|
9
|
+
readonly wallet: XRPLWallet;
|
|
10
|
+
private apiService;
|
|
11
|
+
private client;
|
|
12
|
+
constructor(wallet: XRPLWallet, apiConfig: APIConfig, options?: {
|
|
13
|
+
sandbox?: boolean;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Fetches a quote for Bitcoin transfer.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
19
|
+
*/
|
|
20
|
+
fetchQuote(symbol?: string): Promise<Quote>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetches the Bitcoin vault address.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
25
|
+
*/
|
|
26
|
+
fetchVault(symbol?: string): Promise<{
|
|
27
|
+
address: string;
|
|
28
|
+
tag?: string;
|
|
29
|
+
}>;
|
|
30
|
+
transferXRP(params: {
|
|
31
|
+
walletAddress?: string;
|
|
32
|
+
amount: string;
|
|
33
|
+
}): Promise<TxResponse<Transaction>>;
|
|
34
|
+
transferTokens(params: {
|
|
35
|
+
walletAddress?: string;
|
|
36
|
+
amount: string;
|
|
37
|
+
token: {
|
|
38
|
+
currency: string;
|
|
39
|
+
issuer: string;
|
|
40
|
+
ticker: number;
|
|
41
|
+
};
|
|
42
|
+
}): Promise<TxResponse<Transaction>>;
|
|
43
|
+
getXRPBalance(walletAddress?: string): Promise<number>;
|
|
44
|
+
getTokenBalances(walletAddress?: string): Promise<{
|
|
45
|
+
value: string;
|
|
46
|
+
currency: string;
|
|
47
|
+
issuer?: string | undefined;
|
|
48
|
+
}[]>;
|
|
49
|
+
getDecimalsOfCurrency(currencyHolder: string, currency: string): Promise<number>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XRPLService = void 0;
|
|
4
|
+
const xrpl_1 = require("xrpl");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
+
class XRPLService {
|
|
8
|
+
wallet;
|
|
9
|
+
apiService;
|
|
10
|
+
client;
|
|
11
|
+
constructor(wallet, apiConfig, options) {
|
|
12
|
+
this.wallet = wallet;
|
|
13
|
+
const sandbox = options?.sandbox ? options.sandbox : false;
|
|
14
|
+
this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
|
|
15
|
+
const xrplNetwork = sandbox ? constants_1.XRPL_RPC_URL.Sandbox : constants_1.XRPL_RPC_URL.Production;
|
|
16
|
+
this.client = new xrpl_1.Client(xrplNetwork);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetches a quote for Bitcoin transfer.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
22
|
+
*/
|
|
23
|
+
async fetchQuote(symbol = "XRP") {
|
|
24
|
+
const res = await this.apiService.fetchQuote(symbol);
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetches the Bitcoin vault address.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
31
|
+
*/
|
|
32
|
+
async fetchVault(symbol = "XRP") {
|
|
33
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
async transferXRP(params) {
|
|
37
|
+
console.debug("walletAddress:", params.walletAddress);
|
|
38
|
+
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
39
|
+
if (!(0, xrpl_1.isValidAddress)(walletAddress)) {
|
|
40
|
+
throw new Error("Invalid wallet address");
|
|
41
|
+
}
|
|
42
|
+
const fetchVault = await this.fetchVault();
|
|
43
|
+
const destination = fetchVault.address;
|
|
44
|
+
console.debug("destination:", destination);
|
|
45
|
+
if (!(0, xrpl_1.isValidAddress)(destination)) {
|
|
46
|
+
throw new Error("Invalid destination address");
|
|
47
|
+
}
|
|
48
|
+
const amountInDrops = (0, xrpl_1.xrpToDrops)(params.amount);
|
|
49
|
+
const transaction = {
|
|
50
|
+
TransactionType: "Payment",
|
|
51
|
+
Account: walletAddress,
|
|
52
|
+
Destination: destination,
|
|
53
|
+
Amount: amountInDrops,
|
|
54
|
+
};
|
|
55
|
+
await this.client.connect();
|
|
56
|
+
try {
|
|
57
|
+
const preparedTx = await this.client.autofill(transaction);
|
|
58
|
+
const signedTx = await this.wallet.signTransaction(preparedTx);
|
|
59
|
+
const response = await this.client.submitAndWait(signedTx);
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await this.client.disconnect();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async transferTokens(params) {
|
|
70
|
+
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
71
|
+
console.log("walletAddress:", params.walletAddress);
|
|
72
|
+
if (!(0, xrpl_1.isValidAddress)(walletAddress)) {
|
|
73
|
+
throw new Error("Invalid wallet address");
|
|
74
|
+
}
|
|
75
|
+
const fetchVault = await this.fetchVault("RLUSD");
|
|
76
|
+
const destination = fetchVault.address;
|
|
77
|
+
console.log("destination:", destination);
|
|
78
|
+
if (!(0, xrpl_1.isValidAddress)(destination)) {
|
|
79
|
+
throw new Error("Invalid destination address");
|
|
80
|
+
}
|
|
81
|
+
const amount = BigNumber(params.amount)
|
|
82
|
+
.times(BigNumber(10).pow(params.token.ticker))
|
|
83
|
+
.toFixed(0);
|
|
84
|
+
const transaction = {
|
|
85
|
+
TransactionType: "Payment",
|
|
86
|
+
Account: walletAddress,
|
|
87
|
+
Destination: destination,
|
|
88
|
+
Amount: {
|
|
89
|
+
currency: params.token.currency,
|
|
90
|
+
value: amount,
|
|
91
|
+
issuer: params.token.issuer,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
await this.client.connect();
|
|
95
|
+
try {
|
|
96
|
+
const preparedTx = await this.client.autofill(transaction);
|
|
97
|
+
const signedTx = await this.wallet.signTransaction(preparedTx);
|
|
98
|
+
const response = await this.client.submitAndWait(signedTx);
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
await this.client.disconnect();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async getXRPBalance(walletAddress) {
|
|
109
|
+
const address = walletAddress ? walletAddress : this.wallet.address;
|
|
110
|
+
if (!(0, xrpl_1.isValidAddress)(address)) {
|
|
111
|
+
throw new Error("Invalid wallet address");
|
|
112
|
+
}
|
|
113
|
+
await this.client.connect();
|
|
114
|
+
try {
|
|
115
|
+
const balance = await this.client.getXrpBalance(address, {
|
|
116
|
+
ledger_hash: "validated",
|
|
117
|
+
});
|
|
118
|
+
return balance;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
await this.client.disconnect();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async getTokenBalances(walletAddress) {
|
|
128
|
+
const address = walletAddress ? walletAddress : this.wallet.address;
|
|
129
|
+
if (!(0, xrpl_1.isValidAddress)(address)) {
|
|
130
|
+
throw new Error("Invalid wallet address");
|
|
131
|
+
}
|
|
132
|
+
await this.client.connect();
|
|
133
|
+
try {
|
|
134
|
+
const balances = await this.client.getBalances(address, {
|
|
135
|
+
ledger_index: "validated",
|
|
136
|
+
});
|
|
137
|
+
return balances;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await this.client.disconnect();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
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
|
+
}
|
|
168
|
+
exports.XRPLService = XRPLService;
|
package/package.json
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "An sdk for purchasing silver card in zebec",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"author": "Ashish Sapkota",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "npm run clean && tsc",
|
|
14
|
-
"clean": "rimraf dist",
|
|
15
|
-
"format": "prettier --write .",
|
|
16
|
-
"test": "ts-mocha -p ./tsconfig.json -t 1000000",
|
|
17
|
-
"gen:typechain": "typechain --target ethers-v6 --out-dir \"src/artifacts/typechain-types\" \"src/artifacts/abi/*.json\""
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@types/
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"ts-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@polkadot/
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
"zebec"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
+
"version": "1.1.10-beta.1",
|
|
4
|
+
"description": "An sdk for purchasing silver card in zebec",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "Ashish Sapkota",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run clean && tsc",
|
|
14
|
+
"clean": "rimraf dist",
|
|
15
|
+
"format": "prettier --write .",
|
|
16
|
+
"test": "ts-mocha -p ./tsconfig.json -t 1000000",
|
|
17
|
+
"gen:typechain": "typechain --target ethers-v6 --out-dir \"src/artifacts/typechain-types\" \"src/artifacts/abi/*.json\""
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@dashevo/dapi-client": "^1.8.0",
|
|
21
|
+
"@typechain/ethers-v6": "^0.5.1",
|
|
22
|
+
"@types/jsonwebtoken": "^9.0.7",
|
|
23
|
+
"@types/mocha": "^10.0.9",
|
|
24
|
+
"@types/node": "^22.7.9",
|
|
25
|
+
"dotenv": "^16.4.5",
|
|
26
|
+
"mocha": "11.2.2",
|
|
27
|
+
"prettier": "^3.3.3",
|
|
28
|
+
"rimraf": "^6.0.1",
|
|
29
|
+
"ts-mocha": "11.1.0",
|
|
30
|
+
"ts-node": "^10.9.2",
|
|
31
|
+
"typechain": "^8.3.2",
|
|
32
|
+
"typescript": "^5.6.3"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@creit.tech/stellar-wallets-kit": "^1.7.1",
|
|
36
|
+
"@mempool/mempool.js": "^3.0.0",
|
|
37
|
+
"@polkadot/api": "15.9.3",
|
|
38
|
+
"@polkadot/types": "15.9.3",
|
|
39
|
+
"@polkadot/util": "^13.2.3",
|
|
40
|
+
"@stellar/stellar-sdk": "^13.1.0",
|
|
41
|
+
"@tonconnect/sdk": "^3.0.6",
|
|
42
|
+
"axios": "^1.7.7",
|
|
43
|
+
"bitcoinjs-lib": "^6.1.7",
|
|
44
|
+
"ethers": "^6.13.4",
|
|
45
|
+
"tonweb": "^0.0.66",
|
|
46
|
+
"xdb-digitalbits-sdk": "^8.2.2",
|
|
47
|
+
"xrpl": "^4.2.5"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git#README",
|
|
54
|
+
"keywords": [
|
|
55
|
+
"zebec",
|
|
56
|
+
"zebec fintech",
|
|
57
|
+
"zebec instant card"
|
|
58
|
+
],
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
62
|
+
}
|