@zebec-network/exchange-card-sdk 1.4.1 → 1.5.0-beta.2
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 +0 -283
- package/dist/artifacts/abi/index.js +2 -8
- package/dist/artifacts/index.js +2 -18
- package/dist/artifacts/typechain-types/ERC20.js +1 -2
- package/dist/artifacts/typechain-types/common.js +1 -2
- package/dist/artifacts/typechain-types/factories/ERC20__factory.js +4 -8
- package/dist/artifacts/typechain-types/factories/index.js +1 -5
- package/dist/artifacts/typechain-types/index.js +2 -39
- package/dist/constants.js +11 -14
- package/dist/helpers/apiHelpers.js +12 -19
- package/dist/index.js +5 -21
- package/dist/services/algorandService.js +26 -33
- package/dist/services/bitcoinService.js +10 -50
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +7 -22
- package/dist/services/nearService.js +18 -26
- package/dist/services/octaService.js +7 -11
- package/dist/services/stellarService.js +20 -24
- package/dist/services/xdbService.js +14 -18
- package/dist/services/xrplService.js +14 -18
- package/dist/services/zanoService.d.ts +56 -0
- package/dist/services/zanoService.js +107 -0
- package/dist/types.js +1 -2
- package/dist/utils.js +13 -24
- package/package.json +9 -8
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
|
-
class XRPLService {
|
|
1
|
+
import { Client, isValidAddress, xrpToDrops, } from "xrpl";
|
|
2
|
+
import { XRPL_RPC_URL } from "../constants";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class XRPLService {
|
|
8
5
|
wallet;
|
|
9
6
|
apiService;
|
|
10
7
|
client;
|
|
11
8
|
constructor(wallet, apiConfig, options) {
|
|
12
9
|
this.wallet = wallet;
|
|
13
10
|
const sandbox = options?.sandbox ? options.sandbox : false;
|
|
14
|
-
this.apiService = new
|
|
15
|
-
const xrplNetwork = sandbox ?
|
|
16
|
-
this.client = new
|
|
11
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
|
|
12
|
+
const xrplNetwork = sandbox ? XRPL_RPC_URL.Sandbox : XRPL_RPC_URL.Production;
|
|
13
|
+
this.client = new Client(xrplNetwork);
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* Fetches a quote for Bitcoin transfer.
|
|
@@ -36,16 +33,16 @@ class XRPLService {
|
|
|
36
33
|
async transferXRP(params) {
|
|
37
34
|
console.debug("walletAddress:", params.walletAddress);
|
|
38
35
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
39
|
-
if (!
|
|
36
|
+
if (!isValidAddress(walletAddress)) {
|
|
40
37
|
throw new Error("Invalid wallet address");
|
|
41
38
|
}
|
|
42
39
|
const fetchVault = await this.fetchVault();
|
|
43
40
|
const destination = fetchVault.address;
|
|
44
41
|
console.debug("destination:", destination);
|
|
45
|
-
if (!
|
|
42
|
+
if (!isValidAddress(destination)) {
|
|
46
43
|
throw new Error("Invalid destination address");
|
|
47
44
|
}
|
|
48
|
-
const amountInDrops =
|
|
45
|
+
const amountInDrops = xrpToDrops(params.amount);
|
|
49
46
|
const transaction = {
|
|
50
47
|
TransactionType: "Payment",
|
|
51
48
|
Account: walletAddress,
|
|
@@ -69,13 +66,13 @@ class XRPLService {
|
|
|
69
66
|
async transferTokens(params) {
|
|
70
67
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
71
68
|
console.log("walletAddress:", params.walletAddress);
|
|
72
|
-
if (!
|
|
69
|
+
if (!isValidAddress(walletAddress)) {
|
|
73
70
|
throw new Error("Invalid wallet address");
|
|
74
71
|
}
|
|
75
72
|
const fetchVault = await this.fetchVault("RLUSD");
|
|
76
73
|
const destination = fetchVault.address;
|
|
77
74
|
console.log("destination:", destination);
|
|
78
|
-
if (!
|
|
75
|
+
if (!isValidAddress(destination)) {
|
|
79
76
|
throw new Error("Invalid destination address");
|
|
80
77
|
}
|
|
81
78
|
const transaction = {
|
|
@@ -104,7 +101,7 @@ class XRPLService {
|
|
|
104
101
|
}
|
|
105
102
|
async createTrustLine(params) {
|
|
106
103
|
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
107
|
-
if (!
|
|
104
|
+
if (!isValidAddress(walletAddress)) {
|
|
108
105
|
throw new Error("Invalid wallet address");
|
|
109
106
|
}
|
|
110
107
|
const transaction = {
|
|
@@ -132,7 +129,7 @@ class XRPLService {
|
|
|
132
129
|
}
|
|
133
130
|
async getTokenBalances(walletAddress) {
|
|
134
131
|
const address = walletAddress ? walletAddress : this.wallet.address;
|
|
135
|
-
if (!
|
|
132
|
+
if (!isValidAddress(address)) {
|
|
136
133
|
throw new Error("Invalid wallet address");
|
|
137
134
|
}
|
|
138
135
|
await this.client.connect();
|
|
@@ -150,4 +147,3 @@ class XRPLService {
|
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
}
|
|
153
|
-
exports.XRPLService = XRPLService;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { APIAsset, BalanceInfo } from "zano_web3/server";
|
|
2
|
+
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
|
+
import { Quote } from "../types";
|
|
4
|
+
export interface ZanoServiceConfig {
|
|
5
|
+
walletUrl: string;
|
|
6
|
+
daemonUrl: string;
|
|
7
|
+
walletAuthToken: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ZanoTransferParams {
|
|
10
|
+
assetId: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
comment?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ZanoService {
|
|
15
|
+
readonly apiConfig: APIConfig;
|
|
16
|
+
private readonly serverWallet;
|
|
17
|
+
private readonly apiService;
|
|
18
|
+
constructor(config: ZanoServiceConfig, apiConfig: APIConfig, sdkOptions?: {
|
|
19
|
+
sandbox?: boolean;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Fetches a quote for Bitcoin transfer.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
25
|
+
*/
|
|
26
|
+
fetchQuote(symbol?: string): Promise<Quote>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetches the Bitcoin vault address.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
31
|
+
*/
|
|
32
|
+
fetchVault(symbol?: string): Promise<{
|
|
33
|
+
address: string;
|
|
34
|
+
tag?: string;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Send a transfer
|
|
38
|
+
*/
|
|
39
|
+
transferAssets(params: ZanoTransferParams): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Get asset information
|
|
42
|
+
*/
|
|
43
|
+
getAssetDetails(assetId: string): Promise<APIAsset>;
|
|
44
|
+
/**
|
|
45
|
+
* Validate if the amount is valid for the given asset
|
|
46
|
+
*/
|
|
47
|
+
validateAmount(amount: string, decimalPoints: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get wallet balances
|
|
50
|
+
*/
|
|
51
|
+
getBalances(): Promise<BalanceInfo[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get balance for a specific asset
|
|
54
|
+
*/
|
|
55
|
+
getAssetBalance(assetId: string): Promise<BalanceInfo | null>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { ServerWallet } from "zano_web3/server";
|
|
3
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
4
|
+
export class ZanoService {
|
|
5
|
+
apiConfig;
|
|
6
|
+
serverWallet;
|
|
7
|
+
apiService;
|
|
8
|
+
// private readonly network: "mainnet" | "testnet";
|
|
9
|
+
constructor(config, apiConfig, sdkOptions) {
|
|
10
|
+
this.apiConfig = apiConfig;
|
|
11
|
+
// this.network = sdkOptions?.sandbox ? "testnet" : "mainnet";
|
|
12
|
+
this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
|
|
13
|
+
this.serverWallet = new ServerWallet({
|
|
14
|
+
walletUrl: config.walletUrl,
|
|
15
|
+
daemonUrl: config.daemonUrl,
|
|
16
|
+
walletAuthToken: config.walletAuthToken,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetches a quote for Bitcoin transfer.
|
|
21
|
+
*
|
|
22
|
+
* @returns {Promise<Quote>} A promise that resolves to a Quote object.
|
|
23
|
+
*/
|
|
24
|
+
async fetchQuote(symbol = "ZANO") {
|
|
25
|
+
const res = await this.apiService.fetchQuote(symbol);
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetches the Bitcoin vault address.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
|
|
32
|
+
*/
|
|
33
|
+
async fetchVault(symbol = "ZANO") {
|
|
34
|
+
const data = await this.apiService.fetchVault(symbol);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Send a transfer
|
|
39
|
+
*/
|
|
40
|
+
async transferAssets(params) {
|
|
41
|
+
// Check if we have sufficient balance
|
|
42
|
+
const balances = await this.serverWallet.getBalances();
|
|
43
|
+
const assetBalance = balances.find((balance) => balance.asset_info.asset_id === params.assetId);
|
|
44
|
+
if (assetBalance) {
|
|
45
|
+
const availableBalance = BigNumber(assetBalance.unlocked);
|
|
46
|
+
const fee = BigNumber(0.1);
|
|
47
|
+
const transferAmount = BigNumber(params.amount).plus(fee);
|
|
48
|
+
if (transferAmount.isGreaterThan(availableBalance)) {
|
|
49
|
+
throw new Error(`Insufficient balance. Available: ${assetBalance.unlocked} ${assetBalance.ticker || "tokens"}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Sender does not have ${params.assetId} balance.`);
|
|
54
|
+
}
|
|
55
|
+
const vault = await this.fetchVault("ZANO");
|
|
56
|
+
const receiver = vault.address;
|
|
57
|
+
// Send the transfer
|
|
58
|
+
const result = await this.serverWallet.sendTransfer(params.assetId, receiver, params.amount);
|
|
59
|
+
console.debug("result:", result);
|
|
60
|
+
return result.tx_hash;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get asset information
|
|
64
|
+
*/
|
|
65
|
+
async getAssetDetails(assetId) {
|
|
66
|
+
try {
|
|
67
|
+
return await this.serverWallet.getAssetDetails(assetId);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(`Error getting asset info for ${assetId}:`, error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validate if the amount is valid for the given asset
|
|
76
|
+
*/
|
|
77
|
+
validateAmount(amount, decimalPoints) {
|
|
78
|
+
const decimals = BigNumber(amount).decimalPlaces();
|
|
79
|
+
return Boolean(decimals) && decimals == decimalPoints;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get wallet balances
|
|
83
|
+
*/
|
|
84
|
+
async getBalances() {
|
|
85
|
+
try {
|
|
86
|
+
const balances = await this.serverWallet.getBalances();
|
|
87
|
+
return balances;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error("Error getting balances:", error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get balance for a specific asset
|
|
96
|
+
*/
|
|
97
|
+
async getAssetBalance(assetId) {
|
|
98
|
+
try {
|
|
99
|
+
const balances = await this.getBalances();
|
|
100
|
+
return balances.find((balance) => balance.asset_info.asset_id === assetId) || null;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`Error getting balance for asset ${assetId}:`, error);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.hashSHA256 = hashSHA256;
|
|
7
|
-
exports.parseAlgo = parseAlgo;
|
|
8
|
-
exports.formatAlgo = formatAlgo;
|
|
9
|
-
exports.parseAlgorandAsset = parseAlgorandAsset;
|
|
10
|
-
exports.formatAlgorandAsset = formatAlgorandAsset;
|
|
11
|
-
exports.getAssetDecimals = getAssetDecimals;
|
|
12
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
13
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
-
function hashSHA256(input) {
|
|
15
|
-
const hash = crypto_1.default.createHash("sha256");
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
export function hashSHA256(input) {
|
|
4
|
+
const hash = crypto.createHash("sha256");
|
|
16
5
|
hash.update(input);
|
|
17
6
|
const hex = hash.digest("hex");
|
|
18
7
|
return hex;
|
|
@@ -22,16 +11,16 @@ function hashSHA256(input) {
|
|
|
22
11
|
* @param algos Amount in ALGO
|
|
23
12
|
* @returns Amount in microAlgos
|
|
24
13
|
*/
|
|
25
|
-
function parseAlgo(algos) {
|
|
26
|
-
return BigInt(
|
|
14
|
+
export function parseAlgo(algos) {
|
|
15
|
+
return BigInt(BigNumber(algos).times(1_000_000).toFixed(0));
|
|
27
16
|
}
|
|
28
17
|
/**
|
|
29
18
|
* Convert microAlgos to ALGO
|
|
30
19
|
* @param microAlgos Amount in microAlgos
|
|
31
20
|
* @returns Amount in ALGO
|
|
32
21
|
*/
|
|
33
|
-
function formatAlgo(microAlgos) {
|
|
34
|
-
return
|
|
22
|
+
export function formatAlgo(microAlgos) {
|
|
23
|
+
return BigNumber(microAlgos).div(1_000_000).toFixed();
|
|
35
24
|
}
|
|
36
25
|
/**
|
|
37
26
|
* Convert Amount to micro-token amount (base units)
|
|
@@ -39,8 +28,8 @@ function formatAlgo(microAlgos) {
|
|
|
39
28
|
* @param decimals Number of decimals for the asset
|
|
40
29
|
* @returns Amount in micro-token base units
|
|
41
30
|
*/
|
|
42
|
-
function parseAlgorandAsset(amount, decimals) {
|
|
43
|
-
return BigInt(
|
|
31
|
+
export function parseAlgorandAsset(amount, decimals) {
|
|
32
|
+
return BigInt(BigNumber(amount).times(BigNumber(10).pow(decimals)).toFixed(0));
|
|
44
33
|
}
|
|
45
34
|
/**
|
|
46
35
|
* Convert micro-token Amount to Amount
|
|
@@ -48,8 +37,8 @@ function parseAlgorandAsset(amount, decimals) {
|
|
|
48
37
|
* @param decimals Number of decimals for the asset
|
|
49
38
|
* @returns Amount in decimal units
|
|
50
39
|
*/
|
|
51
|
-
function formatAlgorandAsset(microAmount, decimals) {
|
|
52
|
-
return
|
|
40
|
+
export function formatAlgorandAsset(microAmount, decimals) {
|
|
41
|
+
return BigNumber(microAmount).div(BigNumber(10).pow(decimals)).toFixed();
|
|
53
42
|
}
|
|
54
43
|
const ALGORAND_ASSET_DECIMALS_CACHE = new Map();
|
|
55
44
|
/**
|
|
@@ -58,7 +47,7 @@ const ALGORAND_ASSET_DECIMALS_CACHE = new Map();
|
|
|
58
47
|
* @param assetId asset index of Asset
|
|
59
48
|
* @returns
|
|
60
49
|
*/
|
|
61
|
-
async function getAssetDecimals(client, assetId) {
|
|
50
|
+
export async function getAssetDecimals(client, assetId) {
|
|
62
51
|
// Check if we already have this value cached
|
|
63
52
|
if (ALGORAND_ASSET_DECIMALS_CACHE.has(assetId)) {
|
|
64
53
|
return ALGORAND_ASSET_DECIMALS_CACHE.get(assetId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0-beta.2",
|
|
4
4
|
"description": "An sdk for purchasing silver card in zebec",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"clean": "rimraf dist",
|
|
15
15
|
"format": "prettier --write .",
|
|
16
|
-
"test": "ts-mocha -p ./tsconfig.json -t 1000000",
|
|
16
|
+
"test": "ts-mocha -p ./tsconfig.test.json -t 1000000",
|
|
17
17
|
"gen:typechain": "typechain --target ethers-v6 --out-dir \"src/artifacts/typechain-types\" \"src/artifacts/abi/*.json\""
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
@@ -37,18 +37,19 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@algorandfoundation/algokit-utils": "^9.1.1",
|
|
39
39
|
"@mempool/mempool.js": "^3.0.0",
|
|
40
|
-
"@near-js/crypto": "^2.
|
|
41
|
-
"@near-js/providers": "^2.
|
|
42
|
-
"@near-js/transactions": "^2.
|
|
43
|
-
"@near-js/types": "^2.
|
|
44
|
-
"@near-js/utils": "^2.
|
|
40
|
+
"@near-js/crypto": "^2.2.5",
|
|
41
|
+
"@near-js/providers": "^2.2.5",
|
|
42
|
+
"@near-js/transactions": "^2.2.5",
|
|
43
|
+
"@near-js/types": "^2.2.5",
|
|
44
|
+
"@near-js/utils": "^2.2.5",
|
|
45
45
|
"@stellar/stellar-sdk": "^13.1.0",
|
|
46
46
|
"algosdk": "^3.3.1",
|
|
47
47
|
"axios": "^1.7.7",
|
|
48
48
|
"bignumber.js": "^9.3.0",
|
|
49
49
|
"bitcoinjs-lib": "^6.1.7",
|
|
50
50
|
"ethers": "^6.15.0",
|
|
51
|
-
"xrpl": "^4.2.5"
|
|
51
|
+
"xrpl": "^4.2.5",
|
|
52
|
+
"zano_web3": "^9.2.0"
|
|
52
53
|
},
|
|
53
54
|
"repository": {
|
|
54
55
|
"type": "git",
|