@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.
@@ -1,15 +1,9 @@
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.AlgorandService = void 0;
7
- const algosdk_1 = __importDefault(require("algosdk"));
8
- const algokit_utils_1 = require("@algorandfoundation/algokit-utils");
9
- const client_manager_1 = require("@algorandfoundation/algokit-utils/types/client-manager");
10
- const apiHelpers_1 = require("../helpers/apiHelpers");
11
- const utils_1 = require("../utils");
12
- class AlgorandService {
1
+ import algosdk from "algosdk";
2
+ import { AlgorandClient } from "@algorandfoundation/algokit-utils";
3
+ import { ClientManager } from "@algorandfoundation/algokit-utils/types/client-manager";
4
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
5
+ import { formatAlgo, formatAlgorandAsset, getAssetDecimals, parseAlgo, parseAlgorandAsset, } from "../utils";
6
+ export class AlgorandService {
13
7
  wallet;
14
8
  apiConfig;
15
9
  algodClient;
@@ -20,11 +14,11 @@ class AlgorandService {
20
14
  this.wallet = wallet;
21
15
  this.apiConfig = apiConfig;
22
16
  this.network = sdkOptions?.sandbox ? "testnet" : "mainnet";
23
- this.algodClient = client_manager_1.ClientManager.getAlgodClient(client_manager_1.ClientManager.getAlgoNodeConfig(this.network, "algod"));
24
- this.algorandClient = algokit_utils_1.AlgorandClient.fromClients({
17
+ this.algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig(this.network, "algod"));
18
+ this.algorandClient = AlgorandClient.fromClients({
25
19
  algod: this.algodClient,
26
20
  });
27
- this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
21
+ this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
28
22
  }
29
23
  /**
30
24
  * Fetches a quote for Bitcoin transfer.
@@ -51,23 +45,23 @@ class AlgorandService {
51
45
  */
52
46
  async transferAlgo(config) {
53
47
  try {
54
- const parsedAmount = (0, utils_1.parseAlgo)(config.amount);
48
+ const parsedAmount = parseAlgo(config.amount);
55
49
  // Check if sender has sufficient balance
56
50
  const senderBalance = await this.getAccountBalanceInMicroAlgo(this.wallet.address);
57
- const minBalance = (0, utils_1.parseAlgo)(0.1); // Minimum account balance
51
+ const minBalance = parseAlgo(0.1); // Minimum account balance
58
52
  if (senderBalance < parsedAmount + minBalance) {
59
- throw new Error(`Insufficient balance. Need ${(0, utils_1.formatAlgo)(parsedAmount + minBalance)} ALGO, have ${(0, utils_1.formatAlgo)(senderBalance)} ALGO`);
53
+ throw new Error(`Insufficient balance. Need ${formatAlgo(parsedAmount + minBalance)} ALGO, have ${formatAlgo(senderBalance)} ALGO`);
60
54
  }
61
55
  const vault = await this.fetchVault("ALGO");
62
56
  const recipientAddress = vault.address;
63
57
  // Validate recipient address
64
- if (!algosdk_1.default.isValidAddress(recipientAddress)) {
58
+ if (!algosdk.isValidAddress(recipientAddress)) {
65
59
  throw new Error("Invalid recipient address");
66
60
  }
67
61
  // Get suggested transaction parameters
68
62
  const suggestedParams = await this.algodClient.getTransactionParams().do();
69
63
  // Create payment transaction
70
- const paymentTxn = algosdk_1.default.makePaymentTxnWithSuggestedParamsFromObject({
64
+ const paymentTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
71
65
  sender: this.wallet.address,
72
66
  receiver: recipientAddress,
73
67
  amount: parsedAmount,
@@ -90,24 +84,24 @@ class AlgorandService {
90
84
  */
91
85
  async transferAsset(config) {
92
86
  try {
93
- const assetDecimals = await (0, utils_1.getAssetDecimals)(this.algodClient, config.assetId);
87
+ const assetDecimals = await getAssetDecimals(this.algodClient, config.assetId);
94
88
  // const usdcConfig = USDC_ASSET_CONFIG[this.network];
95
- const parsedAmount = (0, utils_1.parseAlgorandAsset)(config.amount, assetDecimals);
89
+ const parsedAmount = parseAlgorandAsset(config.amount, assetDecimals);
96
90
  // Check if sender has sufficient USDC balance
97
91
  const senderAssetBalance = await this.getAssetBalanceInMicroUnit(this.wallet.address, config.assetId);
98
92
  if (senderAssetBalance < parsedAmount) {
99
- throw new Error(`Insufficient Asset balance. Need ${(0, utils_1.formatAlgorandAsset)(parsedAmount, assetDecimals)} Asset, have ${(0, utils_1.formatAlgorandAsset)(senderAssetBalance, assetDecimals)} Asset`);
93
+ throw new Error(`Insufficient Asset balance. Need ${formatAlgorandAsset(parsedAmount, assetDecimals)} Asset, have ${formatAlgorandAsset(senderAssetBalance, assetDecimals)} Asset`);
100
94
  }
101
95
  // Check if sender has sufficient ALGO for transaction fees
102
96
  const senderAlgoBalance = await this.getAccountBalanceInMicroAlgo(this.wallet.address);
103
- const minAlgoForFees = (0, utils_1.parseAlgo)(0.002); // Minimum ALGO for transaction fees
97
+ const minAlgoForFees = parseAlgo(0.002); // Minimum ALGO for transaction fees
104
98
  if (senderAlgoBalance < minAlgoForFees) {
105
- throw new Error(`Insufficient ALGO for transaction fees. Need at least ${(0, utils_1.formatAlgo)(minAlgoForFees)} ALGO for fees`);
99
+ throw new Error(`Insufficient ALGO for transaction fees. Need at least ${formatAlgo(minAlgoForFees)} ALGO for fees`);
106
100
  }
107
101
  const vault = await this.fetchVault("ALGO-USDC");
108
102
  const recipientAddress = vault.address;
109
103
  // Validate recipient address
110
- if (!algosdk_1.default.isValidAddress(recipientAddress)) {
104
+ if (!algosdk.isValidAddress(recipientAddress)) {
111
105
  throw new Error("Invalid recipient address");
112
106
  }
113
107
  // // Check if recipient is opted into USDC asset
@@ -118,7 +112,7 @@ class AlgorandService {
118
112
  // Get suggested transaction parameters
119
113
  const suggestedParams = await this.algodClient.getTransactionParams().do();
120
114
  // Create asset transfer transaction
121
- const assetTransferTxn = algosdk_1.default.makeAssetTransferTxnWithSuggestedParamsFromObject({
115
+ const assetTransferTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
122
116
  sender: this.wallet.address,
123
117
  receiver: recipientAddress,
124
118
  amount: parsedAmount,
@@ -170,8 +164,8 @@ class AlgorandService {
170
164
  }
171
165
  async getAssetBalance(walletAddress, assetId) {
172
166
  const balance = await this.getAssetBalanceInMicroUnit(walletAddress, assetId);
173
- const decimals = await (0, utils_1.getAssetDecimals)(this.algodClient, assetId);
174
- return (0, utils_1.formatAlgorandAsset)(balance, decimals);
167
+ const decimals = await getAssetDecimals(this.algodClient, assetId);
168
+ return formatAlgorandAsset(balance, decimals);
175
169
  }
176
170
  async getAssetsBalance(walletAddress, assetIds) {
177
171
  const map = new Map(Array.from(assetIds.map((id) => [id, "0"])));
@@ -184,8 +178,8 @@ class AlgorandService {
184
178
  await Promise.all(assetIds.map(async (id) => {
185
179
  const asset = assets.find((asset) => asset.assetId === BigInt(id));
186
180
  if (asset) {
187
- const decimals = await (0, utils_1.getAssetDecimals)(this.algodClient, id);
188
- const amount = (0, utils_1.formatAlgorandAsset)(asset.amount, decimals);
181
+ const decimals = await getAssetDecimals(this.algodClient, id);
182
+ const amount = formatAlgorandAsset(asset.amount, decimals);
189
183
  map.set(id, amount);
190
184
  }
191
185
  }));
@@ -203,7 +197,7 @@ class AlgorandService {
203
197
  */
204
198
  async getAccountBalance(address) {
205
199
  const amount = await this.getAccountBalanceInMicroAlgo(address);
206
- return (0, utils_1.formatAlgo)(amount);
200
+ return formatAlgo(amount);
207
201
  }
208
202
  /**
209
203
  * Get account balance in microAlgos (for internal calculations)
@@ -215,4 +209,3 @@ class AlgorandService {
215
209
  return accountInfo.amount;
216
210
  }
217
211
  }
218
- exports.AlgorandService = AlgorandService;
@@ -1,47 +1,8 @@
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 {
1
+ import axios from "axios";
2
+ import * as bitcoin from "bitcoinjs-lib";
3
+ import { BITCOIN_ENDPOINTS } from "../constants";
4
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
5
+ export class BitcoinService {
45
6
  wallet;
46
7
  apiService;
47
8
  network;
@@ -49,9 +10,9 @@ class BitcoinService {
49
10
  constructor(wallet, apiConfig, sdkOptions) {
50
11
  this.wallet = wallet;
51
12
  const sandbox = sdkOptions?.sandbox ?? false;
52
- this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
13
+ this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
53
14
  this.network = sandbox ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
54
- this.apiEndpoint = sandbox ? constants_1.BITCOIN_ENDPOINTS.Sandbox : constants_1.BITCOIN_ENDPOINTS.Production;
15
+ this.apiEndpoint = sandbox ? BITCOIN_ENDPOINTS.Sandbox : BITCOIN_ENDPOINTS.Production;
55
16
  }
56
17
  /**
57
18
  * Fetches a quote for Bitcoin transfer.
@@ -72,10 +33,10 @@ class BitcoinService {
72
33
  return data;
73
34
  }
74
35
  async getUTXOs() {
75
- const response = await axios_1.default.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
36
+ const response = await axios.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
76
37
  console.log("utxos:", response.data);
77
38
  return Promise.all(response.data.map(async (utxo) => {
78
- const rawTx = await axios_1.default.get(`${this.apiEndpoint}/tx/${utxo.txid}/hex`);
39
+ const rawTx = await axios.get(`${this.apiEndpoint}/tx/${utxo.txid}/hex`);
79
40
  console.log("txHex:", rawTx.data);
80
41
  if (!rawTx.data) {
81
42
  throw new Error("Transaction not found");
@@ -90,7 +51,7 @@ class BitcoinService {
90
51
  }));
91
52
  }
92
53
  async getBalance() {
93
- const response = await axios_1.default.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
54
+ const response = await axios.get(`${this.apiEndpoint}/address/${this.wallet.address}/utxo`);
94
55
  const utxos = response.data;
95
56
  return utxos.reduce((sum, utxo) => sum + utxo.value, 0);
96
57
  }
@@ -192,4 +153,3 @@ class BitcoinService {
192
153
  }
193
154
  }
194
155
  }
195
- exports.BitcoinService = BitcoinService;
@@ -4,3 +4,4 @@ export * from "./nearService";
4
4
  export * from "./algorandService";
5
5
  export * from "./xdbService";
6
6
  export * from "./octaService";
7
+ export * from "./zanoService";
@@ -1,23 +1,8 @@
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
1
  // export * from "./bitcoinService";
18
- __exportStar(require("./stellarService"), exports);
19
- __exportStar(require("./xrplService"), exports);
20
- __exportStar(require("./nearService"), exports);
21
- __exportStar(require("./algorandService"), exports);
22
- __exportStar(require("./xdbService"), exports);
23
- __exportStar(require("./octaService"), exports);
2
+ export * from "./stellarService";
3
+ export * from "./xrplService";
4
+ export * from "./nearService";
5
+ export * from "./algorandService";
6
+ export * from "./xdbService";
7
+ export * from "./octaService";
8
+ export * from "./zanoService";
@@ -1,16 +1,9 @@
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");
1
+ import assert from "assert";
2
+ import { BigNumber } from "bignumber.js";
3
+ import { JsonRpcProvider } from "@near-js/providers";
4
+ import { parseNearAmount } from "@near-js/utils";
5
+ import { NEAR_RPC_URL } from "../constants";
6
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
14
7
  /**
15
8
  * Makes action payload for function call in near contract
16
9
  * @param methodName method name
@@ -18,7 +11,7 @@ const apiHelpers_1 = require("../helpers/apiHelpers");
18
11
  * @param gas gas fee
19
12
  * @param deposit deposit amount
20
13
  */
21
- function createFunctionCall(methodName, args, gas, deposit) {
14
+ export function createFunctionCall(methodName, args, gas, deposit) {
22
15
  return {
23
16
  type: "FunctionCall",
24
17
  params: {
@@ -29,16 +22,16 @@ function createFunctionCall(methodName, args, gas, deposit) {
29
22
  },
30
23
  };
31
24
  }
32
- class NearService {
25
+ export class NearService {
33
26
  wallet;
34
27
  apiService;
35
28
  provider;
36
29
  constructor(wallet, apiConfig, options) {
37
30
  this.wallet = wallet;
38
31
  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 });
32
+ this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
33
+ const url = sandbox ? NEAR_RPC_URL.Sandbox : NEAR_RPC_URL.Production;
34
+ this.provider = new JsonRpcProvider({ url });
42
35
  }
43
36
  /**
44
37
  * Fetches a quote for Bitcoin transfer.
@@ -63,8 +56,8 @@ class NearService {
63
56
  const fetchVault = await this.fetchVault();
64
57
  const destination = fetchVault.address;
65
58
  console.debug("destination:", destination);
66
- const parsedAmount = (0, utils_1.parseNearAmount)(params.amount);
67
- (0, assert_1.default)(parsedAmount, "Amount might be missing.");
59
+ const parsedAmount = parseNearAmount(params.amount);
60
+ assert(parsedAmount, "Amount might be missing.");
68
61
  const action = {
69
62
  type: "Transfer",
70
63
  params: {
@@ -100,7 +93,7 @@ class NearService {
100
93
  console.debug("storageBalance:", storageBalance);
101
94
  const GAS = "30000000000000";
102
95
  if (!storageBalance ||
103
- (0, bignumber_js_1.BigNumber)(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
96
+ BigNumber(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
104
97
  const action = createFunctionCall("storage_deposit", {
105
98
  account_id: signerId,
106
99
  registration_only: false,
@@ -141,7 +134,7 @@ class NearService {
141
134
  const storageBalance = JSON.parse(Buffer.from(storageBalanceResult.result).toString());
142
135
  console.debug("storageBalance:", storageBalance);
143
136
  if (!storageBalance ||
144
- (0, bignumber_js_1.BigNumber)(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
137
+ BigNumber(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
145
138
  const action = createFunctionCall("storage_deposit", {
146
139
  account_id: destination,
147
140
  registration_only: false,
@@ -157,8 +150,8 @@ class NearService {
157
150
  });
158
151
  const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
159
152
  const tokenDecimals = metadata.decimals;
160
- const parsedAmount = (0, bignumber_js_1.BigNumber)(params.amount)
161
- .times((0, bignumber_js_1.BigNumber)(10).pow(tokenDecimals))
153
+ const parsedAmount = BigNumber(params.amount)
154
+ .times(BigNumber(10).pow(tokenDecimals))
162
155
  .toFixed(0);
163
156
  const secutityDeposit = "1";
164
157
  const transferAction = createFunctionCall("ft_transfer", {
@@ -204,7 +197,6 @@ class NearService {
204
197
  const metadata = JSON.parse(Buffer.from(metadataResult.result).toString());
205
198
  const decimals = metadata.decimals;
206
199
  const data = JSON.parse(Buffer.from(result.result).toString());
207
- return (0, bignumber_js_1.BigNumber)(data).div((0, bignumber_js_1.BigNumber)(10).pow(decimals)).toFixed();
200
+ return BigNumber(data).div(BigNumber(10).pow(decimals)).toFixed();
208
201
  }
209
202
  }
210
- exports.NearService = NearService;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OctaService = void 0;
4
- const ethers_1 = require("ethers");
5
- const constants_1 = require("../constants");
6
- const apiHelpers_1 = require("../helpers/apiHelpers");
7
- class OctaService {
1
+ import { parseEther } from "ethers";
2
+ import { DEFAULT_EVM_GAS_LIMIT } from "../constants";
3
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
+ export class OctaService {
8
5
  signer;
9
6
  apiConfig;
10
7
  apiService;
11
8
  constructor(signer, apiConfig, sdkOptions) {
12
9
  this.signer = signer;
13
10
  this.apiConfig = apiConfig;
14
- this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
11
+ this.apiService = new ZebecCardAPIService(apiConfig, sdkOptions?.sandbox || false);
15
12
  }
16
13
  /**
17
14
  * Fetches a quote for Bitcoin transfer.
@@ -32,7 +29,7 @@ class OctaService {
32
29
  return data;
33
30
  }
34
31
  async transferOcta(params) {
35
- const parsedAmount = (0, ethers_1.parseEther)(params.amount.toString());
32
+ const parsedAmount = parseEther(params.amount.toString());
36
33
  const provider = this.signer.provider;
37
34
  const vault = await this.fetchVault();
38
35
  const recipientAddress = vault.address;
@@ -45,7 +42,7 @@ class OctaService {
45
42
  }
46
43
  const overides = {
47
44
  ...params.overrides,
48
- gasLimit: constants_1.DEFAULT_EVM_GAS_LIMIT,
45
+ gasLimit: DEFAULT_EVM_GAS_LIMIT,
49
46
  };
50
47
  const response = await this.signer.sendTransaction({
51
48
  ...overides,
@@ -59,4 +56,3 @@ class OctaService {
59
56
  return receipt;
60
57
  }
61
58
  }
62
- exports.OctaService = OctaService;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StellarService = void 0;
4
- const stellar_sdk_1 = require("@stellar/stellar-sdk");
5
- const constants_1 = require("../constants");
6
- const apiHelpers_1 = require("../helpers/apiHelpers");
7
- class StellarService {
1
+ import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
2
+ import { STELLAR_RPC_URL, STELLAR_USDC_ISSUER } from "../constants";
3
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
+ export class StellarService {
8
5
  wallet;
9
6
  apiService;
10
7
  server;
@@ -19,8 +16,8 @@ class StellarService {
19
16
  constructor(wallet, apiConfig, sdkOptions) {
20
17
  this.wallet = wallet;
21
18
  const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
22
- this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
23
- this.server = new stellar_sdk_1.Horizon.Server(sandbox ? constants_1.STELLAR_RPC_URL.Sandbox : constants_1.STELLAR_RPC_URL.Production);
19
+ this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
20
+ this.server = new Horizon.Server(sandbox ? STELLAR_RPC_URL.Sandbox : STELLAR_RPC_URL.Production);
24
21
  this.sandbox = sandbox;
25
22
  }
26
23
  /**
@@ -56,28 +53,28 @@ class StellarService {
56
53
  // Prepare transaction
57
54
  const account = await this.server.loadAccount(this.wallet.address);
58
55
  const fee = await this.server.fetchBaseFee();
59
- const memo = stellar_sdk_1.Memo.id(vault.tag?.toString() || "");
56
+ const memo = Memo.id(vault.tag?.toString() || "");
60
57
  // Check Wallet balance
61
58
  const balance = await this.getWalletBalance(this.wallet.address);
62
59
  if (Number(balance) < Number(amount)) {
63
60
  throw new Error("Insufficient balance");
64
61
  }
65
62
  // Build and submit transaction
66
- const transaction = new stellar_sdk_1.TransactionBuilder(account, {
63
+ const transaction = new TransactionBuilder(account, {
67
64
  fee: fee.toString(),
68
- networkPassphrase: this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC,
65
+ networkPassphrase: this.sandbox ? Networks.TESTNET : Networks.PUBLIC,
69
66
  })
70
- .addOperation(stellar_sdk_1.Operation.payment({
67
+ .addOperation(Operation.payment({
71
68
  destination: vault.address,
72
- asset: stellar_sdk_1.Asset.native(),
69
+ asset: Asset.native(),
73
70
  amount,
74
71
  }))
75
72
  .addMemo(memo)
76
- .setTimeout(stellar_sdk_1.TimeoutInfinite)
73
+ .setTimeout(TimeoutInfinite)
77
74
  .build();
78
75
  // Sign the transaction
79
76
  const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
80
- const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC);
77
+ const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? Networks.TESTNET : Networks.PUBLIC);
81
78
  let retries = 0;
82
79
  const maxRetries = 5;
83
80
  let delay = 1000;
@@ -116,27 +113,27 @@ class StellarService {
116
113
  const account = await this.server.loadAccount(this.wallet.address);
117
114
  const fee = await this.server.fetchBaseFee();
118
115
  // Create USDC asset object
119
- const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.STELLAR_USDC_ISSUER.Sandbox : constants_1.STELLAR_USDC_ISSUER.Production);
116
+ const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
120
117
  // Check Wallet balance
121
118
  const balance = await this.getTokenBalance(this.wallet.address, usdcAsset);
122
119
  if (Number(balance) < Number(amount)) {
123
120
  throw new Error("Insufficient USDC balance");
124
121
  }
125
122
  // Build and submit transaction
126
- const transaction = new stellar_sdk_1.TransactionBuilder(account, {
123
+ const transaction = new TransactionBuilder(account, {
127
124
  fee: fee.toString(),
128
- networkPassphrase: this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC,
125
+ networkPassphrase: this.sandbox ? Networks.TESTNET : Networks.PUBLIC,
129
126
  })
130
- .addOperation(stellar_sdk_1.Operation.payment({
127
+ .addOperation(Operation.payment({
131
128
  destination: vault.address,
132
129
  asset: usdcAsset,
133
130
  amount,
134
131
  }))
135
- .setTimeout(stellar_sdk_1.TimeoutInfinite)
132
+ .setTimeout(TimeoutInfinite)
136
133
  .build();
137
134
  // Sign the transaction
138
135
  const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
139
- const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC);
136
+ const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? Networks.TESTNET : Networks.PUBLIC);
140
137
  let retries = 0;
141
138
  const maxRetries = 5;
142
139
  let delay = 1000;
@@ -193,7 +190,6 @@ class StellarService {
193
190
  }
194
191
  }
195
192
  async getAsset(assetCode, assetIssuer) {
196
- return new stellar_sdk_1.Asset(assetCode, assetIssuer);
193
+ return new Asset(assetCode, assetIssuer);
197
194
  }
198
195
  }
199
- exports.StellarService = StellarService;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.XDBService = void 0;
4
- const stellar_sdk_1 = require("@stellar/stellar-sdk");
5
- const constants_1 = require("../constants");
6
- const apiHelpers_1 = require("../helpers/apiHelpers");
7
- class XDBService {
1
+ import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
2
+ import { XDB_NETWORK, XDB_RPC_URL } from "../constants";
3
+ import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
+ export class XDBService {
8
5
  wallet;
9
6
  apiService;
10
7
  server;
@@ -19,8 +16,8 @@ class XDBService {
19
16
  constructor(wallet, apiConfig, sdkOptions) {
20
17
  this.wallet = wallet;
21
18
  const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
22
- this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
23
- this.server = new stellar_sdk_1.Horizon.Server(sandbox ? constants_1.XDB_RPC_URL.Sandbox : constants_1.XDB_RPC_URL.Production);
19
+ this.apiService = new ZebecCardAPIService(apiConfig, sandbox);
20
+ this.server = new Horizon.Server(sandbox ? XDB_RPC_URL.Sandbox : XDB_RPC_URL.Production);
24
21
  this.sandbox = sandbox;
25
22
  }
26
23
  /**
@@ -57,28 +54,28 @@ class XDBService {
57
54
  // Prepare transaction
58
55
  const account = await this.server.loadAccount(this.wallet.address);
59
56
  const fee = await this.server.fetchBaseFee();
60
- const memo = stellar_sdk_1.Memo.id(tag);
57
+ const memo = Memo.id(tag);
61
58
  // Check Wallet balance
62
59
  const balance = await this.getNativeBalance(this.wallet.address);
63
60
  if (Number(balance) < Number(amount)) {
64
61
  throw new Error("Insufficient balance");
65
62
  }
66
63
  // Build and submit transaction
67
- const transaction = new stellar_sdk_1.TransactionBuilder(account, {
64
+ const transaction = new TransactionBuilder(account, {
68
65
  fee: fee.toString(),
69
- networkPassphrase: this.sandbox ? constants_1.XDB_NETWORK.TESTNET : constants_1.XDB_NETWORK.PUBLIC,
66
+ networkPassphrase: this.sandbox ? XDB_NETWORK.TESTNET : XDB_NETWORK.PUBLIC,
70
67
  })
71
- .addOperation(stellar_sdk_1.Operation.payment({
68
+ .addOperation(Operation.payment({
72
69
  destination: recipientAddress,
73
- asset: stellar_sdk_1.Asset.native(),
70
+ asset: Asset.native(),
74
71
  amount,
75
72
  }))
76
73
  .addMemo(memo)
77
- .setTimeout(stellar_sdk_1.TimeoutInfinite)
74
+ .setTimeout(TimeoutInfinite)
78
75
  .build();
79
76
  // Sign the transaction
80
77
  const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
81
- const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? constants_1.XDB_NETWORK.TESTNET : constants_1.XDB_NETWORK.PUBLIC);
78
+ const tx = TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? XDB_NETWORK.TESTNET : XDB_NETWORK.PUBLIC);
82
79
  let retries = 0;
83
80
  const maxRetries = 5;
84
81
  let delay = 1000;
@@ -135,7 +132,6 @@ class XDBService {
135
132
  }
136
133
  }
137
134
  getAsset(assetCode, assetIssuer) {
138
- return new stellar_sdk_1.Asset(assetCode, assetIssuer);
135
+ return new Asset(assetCode, assetIssuer);
139
136
  }
140
137
  }
141
- exports.XDBService = XDBService;