@zebec-network/exchange-card-sdk 1.11.5 → 1.12.0

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 CHANGED
@@ -24,7 +24,7 @@ Every service can be toggled between mainnet (production) and testnet via the `s
24
24
  npm i @zebec-network/exchange-card-sdk
25
25
  ```
26
26
 
27
- Peer/runtime dependencies you may need depending on which service you use: `ethers`, `algosdk`, `xrpl`, `quais`, `@near-js/*`, `@provablehq/sdk`, `@zebec-fintech/stellar-sdk`.
27
+ Peer/runtime dependencies you may need depending on which service you use: `ethers`, `algosdk`, `xrpl`, `quais`, `@near-js/*`, `@provablehq/sdk`, `@stellar/stellar-sdk`.
28
28
 
29
29
  ## Common Concepts
30
30
 
@@ -67,9 +67,9 @@ await boba.transferBobaEth({ amount: "0.01" });
67
67
 
68
68
  // ERC‑20 token on Boba
69
69
  await boba.transferToken({
70
- amount: "10",
71
- symbol: "BOBA-USDC",
72
- tokenAddress: "0x...",
70
+ amount: "10",
71
+ symbol: "BOBA-USDC",
72
+ tokenAddress: "0x...",
73
73
  });
74
74
  ```
75
75
 
@@ -91,11 +91,11 @@ await octa.transferOcta({ amount: "1.5" });
91
91
  import { QuaiService, QuaiWallet } from "@zebec-network/exchange-card-sdk";
92
92
 
93
93
  const wallet: QuaiWallet = {
94
- address: "0x...",
95
- signAndSendTransaction: async (tx) => {
96
- /* sign & submit */
97
- return "0xhash";
98
- },
94
+ address: "0x...",
95
+ signAndSendTransaction: async (tx) => {
96
+ /* sign & submit */
97
+ return "0xhash";
98
+ },
99
99
  };
100
100
 
101
101
  const quai = new QuaiService(wallet, { sandbox: false });
@@ -108,10 +108,10 @@ const txHash = await quai.transferQuai({ amount: "2.0" });
108
108
  import { NearService, NearWallet } from "@zebec-network/exchange-card-sdk";
109
109
 
110
110
  const wallet: NearWallet = {
111
- signerId: "alice.near",
112
- signAndSendTransaction: async (transaction) => {
113
- /* submit via near-api-js or wallet selector */
114
- },
111
+ signerId: "alice.near",
112
+ signAndSendTransaction: async (transaction) => {
113
+ /* submit via near-api-js or wallet selector */
114
+ },
115
115
  };
116
116
 
117
117
  const near = new NearService(wallet, { sandbox: false });
@@ -121,8 +121,8 @@ await near.transferNear({ amount: "1.25" });
121
121
 
122
122
  // NEP‑141 token (e.g. USDC)
123
123
  await near.transferTokens({
124
- amount: "10",
125
- tokenContractId: "usdc.fakes.testnet",
124
+ amount: "10",
125
+ tokenContractId: "usdc.fakes.testnet",
126
126
  });
127
127
  ```
128
128
 
@@ -134,10 +134,10 @@ await near.transferTokens({
134
134
  import { XRPLService, XRPLWallet } from "@zebec-network/exchange-card-sdk";
135
135
 
136
136
  const wallet: XRPLWallet = {
137
- address: "r...",
138
- signTransaction: async (tx) => {
139
- /* sign with xrpl.js Wallet or a wallet extension */
140
- },
137
+ address: "r...",
138
+ signTransaction: async (tx) => {
139
+ /* sign with xrpl.js Wallet or a wallet extension */
140
+ },
141
141
  };
142
142
 
143
143
  const xrpl = new XRPLService(wallet, { sandbox: true });
@@ -147,12 +147,12 @@ await xrpl.transferXRP({ amount: "5" });
147
147
 
148
148
  // Issued token (requires a trust line)
149
149
  await xrpl.createTrustLine({
150
- amount: "1000000",
151
- token: { currency: "USD", issuer: "rIssuer..." },
150
+ amount: "1000000",
151
+ token: { currency: "USD", issuer: "rIssuer..." },
152
152
  });
153
153
  await xrpl.transferTokens({
154
- amount: "10",
155
- token: { currency: "USD", issuer: "rIssuer..." },
154
+ amount: "10",
155
+ token: { currency: "USD", issuer: "rIssuer..." },
156
156
  });
157
157
  ```
158
158
 
@@ -163,10 +163,10 @@ import algosdk from "algosdk";
163
163
  import { AlgorandService, AlgorandWallet } from "@zebec-network/exchange-card-sdk";
164
164
 
165
165
  const wallet: AlgorandWallet = {
166
- address: "ALGO_ADDRESS",
167
- signAndSendTransaction: async (txn) => {
168
- /* sign and submit, return tx id */
169
- },
166
+ address: "ALGO_ADDRESS",
167
+ signAndSendTransaction: async (txn) => {
168
+ /* sign and submit, return tx id */
169
+ },
170
170
  };
171
171
 
172
172
  const algo = new AlgorandService(wallet, { sandbox: true });
@@ -184,10 +184,10 @@ await algo.transferAsset({ assetId: 10458941, amount: "10" });
184
184
  import { StellarService, StellarWallet } from "@zebec-network/exchange-card-sdk";
185
185
 
186
186
  const wallet: StellarWallet = {
187
- address: "G...",
188
- signTransaction: async (xdr) => {
189
- /* sign and return signed xdr */
190
- },
187
+ address: "G...",
188
+ signTransaction: async (xdr) => {
189
+ /* sign and return signed xdr */
190
+ },
191
191
  };
192
192
 
193
193
  const stellar = new StellarService(wallet, { sandbox: true });
@@ -204,10 +204,10 @@ await stellar.transferUSDC("10");
204
204
  import { XDBService, XDBWalletInterface } from "@zebec-network/exchange-card-sdk";
205
205
 
206
206
  const wallet: XDBWalletInterface = {
207
- address: "G...",
208
- signTransaction: async (xdr) => {
209
- /* sign and return signed xdr */
210
- },
207
+ address: "G...",
208
+ signTransaction: async (xdr) => {
209
+ /* sign and return signed xdr */
210
+ },
211
211
  };
212
212
 
213
213
  const xdb = new XDBService(wallet, { sandbox: false });
@@ -220,16 +220,16 @@ await xdb.transferXDB("100");
220
220
  import { AleoService, AleoWallet } from "@zebec-network/exchange-card-sdk";
221
221
 
222
222
  const wallet: AleoWallet = {
223
- address: "aleo1...",
224
- decrypt: async (ciphertext) => {
225
- /* decrypt record ciphertext */
226
- },
227
- requestRecords: async (program, includePlaintext) => {
228
- /* fetch records from wallet */
229
- },
230
- executeTransaction: async (opts) => {
231
- /* execute program tx */
232
- },
223
+ address: "aleo1...",
224
+ decrypt: async (ciphertext) => {
225
+ /* decrypt record ciphertext */
226
+ },
227
+ requestRecords: async (program, includePlaintext) => {
228
+ /* fetch records from wallet */
229
+ },
230
+ executeTransaction: async (opts) => {
231
+ /* execute program tx */
232
+ },
233
233
  };
234
234
 
235
235
  const aleo = new AleoService(wallet, undefined, { sandbox: false });
@@ -239,9 +239,9 @@ await aleo.transferCredit({ amount: "1.5", transferType: "public" });
239
239
 
240
240
  // Stablecoin (USAD / USDCX) — supports public and compliant private transfers
241
241
  await aleo.transferStableCoin({
242
- programId: "usad_stablecoin.aleo",
243
- amount: "10",
244
- transferType: "private",
242
+ programId: "usad_stablecoin.aleo",
243
+ amount: "10",
244
+ transferType: "private",
245
245
  });
246
246
  ```
247
247
 
@@ -3,8 +3,23 @@ export declare class ZebecCardAPIService {
3
3
  private readonly api;
4
4
  constructor(sandbox?: boolean);
5
5
  ping(): Promise<boolean>;
6
+ /**
7
+ * @deprecated Use {@link fetchVaultByTokenAddress} instead
8
+ *
9
+ * @param symbol Token symbol
10
+ * @returns An object containing address and tag (optional)
11
+ */
6
12
  fetchVault(symbol: string): Promise<{
7
13
  address: string;
8
14
  tag?: string;
9
15
  }>;
16
+ /**
17
+ *
18
+ * @param address mint address
19
+ * @returns An object containing address and tag (optional)
20
+ */
21
+ fetchVaultByTokenAddress(address: string): Promise<{
22
+ address: string;
23
+ tag?: string;
24
+ }>;
10
25
  }
@@ -13,12 +13,46 @@ export class ZebecCardAPIService {
13
13
  await this.api.get("/health");
14
14
  return true;
15
15
  }
16
- catch (error) {
16
+ catch (_) {
17
17
  throw new Error("Card service is down. Please try again later.");
18
18
  }
19
19
  }
20
+ /**
21
+ * @deprecated Use {@link fetchVaultByTokenAddress} instead
22
+ *
23
+ * @param symbol Token symbol
24
+ * @returns An object containing address and tag (optional)
25
+ */
20
26
  async fetchVault(symbol) {
21
- const { data } = await this.api.get(`/tokens/deposit-address`, { params: { symbol } });
27
+ const { data } = await this.api.get(`/tokens/deposit-address`, {
28
+ params: { symbol },
29
+ });
30
+ return data.data;
31
+ }
32
+ /**
33
+ *
34
+ * @param address mint address
35
+ * @returns An object containing address and tag (optional)
36
+ */
37
+ async fetchVaultByTokenAddress(address) {
38
+ const response = await this.api.get(`/tokens/deposit-address`, {
39
+ params: {
40
+ mintAddress: address,
41
+ },
42
+ });
43
+ const data = response.data;
44
+ if (!data ||
45
+ typeof data !== "object" ||
46
+ !("data" in data) ||
47
+ !data.data ||
48
+ typeof data.data !== "object" ||
49
+ !("address" in data.data) ||
50
+ typeof data.data.address !== "string") {
51
+ throw new Error(`Invalid response shape for fetching vault address by mint address. data:\n${String(data)}`);
52
+ }
53
+ if ("tag" in data.data && data.data.tag && typeof data.data.tag !== "string") {
54
+ throw new Error(`Invalid response shape for fetching vault address by mint address. data:\n${String(data)}`);
55
+ }
22
56
  return data.data;
23
57
  }
24
58
  }
@@ -105,7 +105,7 @@ export declare class AleoService {
105
105
  *
106
106
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
107
107
  */
108
- fetchVault(symbol?: string): Promise<{
108
+ fetchVaultByTokenAddress(address: string): Promise<{
109
109
  address: string;
110
110
  tag?: string;
111
111
  }>;
@@ -54,8 +54,8 @@ export class AleoService {
54
54
  *
55
55
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
56
56
  */
57
- async fetchVault(symbol = "ALEO") {
58
- const data = await this.apiService.fetchVault(symbol);
57
+ async fetchVaultByTokenAddress(address) {
58
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
59
59
  return data;
60
60
  }
61
61
  /**
@@ -126,7 +126,7 @@ export class AleoService {
126
126
  recipient = params.recipient;
127
127
  }
128
128
  else {
129
- const vault = await this.fetchVault("ALEO");
129
+ const vault = await this.fetchVaultByTokenAddress("credits.aleo");
130
130
  if (!vault) {
131
131
  throw new Error("Failed to fetch vault address");
132
132
  }
@@ -163,14 +163,14 @@ export class AleoService {
163
163
  const privateFee = params?.privateFee || false;
164
164
  const fee = toMicroUnits(params.fee || 0.1, 6);
165
165
  const programId = this.sandbox ? `test_${params.programId}` : params.programId;
166
- const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "USAD" : "USDCX";
166
+ const tokenSymbol = params.programId === "usad_stablecoin.aleo" ? "usad" : "usdcx";
167
167
  const functionName = transferType === "public" ? "transfer_public" : "transfer_private";
168
168
  let recipient;
169
169
  if (params.recipient) {
170
170
  recipient = params.recipient;
171
171
  }
172
172
  else {
173
- const vault = await this.fetchVault(tokenSymbol);
173
+ const vault = await this.fetchVaultByTokenAddress(params.programId);
174
174
  if (!vault) {
175
175
  throw new Error("Failed to fetch vault address");
176
176
  }
@@ -186,7 +186,7 @@ export class AleoService {
186
186
  // For private transfer, we need to find a record with sufficient balance
187
187
  const [record, complianceProof] = await Promise.all([
188
188
  this._getRecord(programId),
189
- this._getComplianceProof(tokenSymbol.toLowerCase(), this.wallet.address, this.sandbox ? Network.TESTNET : Network.MAINNET),
189
+ this._getComplianceProof(tokenSymbol, this.wallet.address, this.sandbox ? Network.TESTNET : Network.MAINNET),
190
190
  ]);
191
191
  inputs = [recipient, amountInMicroUnits, record, complianceProof];
192
192
  break;
@@ -31,7 +31,7 @@ export declare class AlgorandService {
31
31
  *
32
32
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
33
33
  */
34
- fetchVault(symbol?: string): Promise<{
34
+ fetchVaultByAssetId(assetId: string): Promise<{
35
35
  address: string;
36
36
  tag?: string;
37
37
  }>;
@@ -17,8 +17,8 @@ export class AlgorandService {
17
17
  *
18
18
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
19
19
  */
20
- async fetchVault(symbol = "ALGO") {
21
- const data = await this.apiService.fetchVault(symbol);
20
+ async fetchVaultByAssetId(assetId) {
21
+ const data = await this.apiService.fetchVaultByTokenAddress(assetId);
22
22
  return data;
23
23
  }
24
24
  /**
@@ -35,7 +35,7 @@ export class AlgorandService {
35
35
  if (senderBalance < parsedAmount + minBalance) {
36
36
  throw new Error(`Insufficient balance. Need ${formatAlgo(parsedAmount + minBalance)} ALGO, have ${formatAlgo(senderBalance)} ALGO`);
37
37
  }
38
- const vault = await this.fetchVault("ALGO");
38
+ const vault = await this.fetchVaultByAssetId("algo");
39
39
  const recipientAddress = vault.address;
40
40
  // Validate recipient address
41
41
  if (!algosdk.isValidAddress(recipientAddress)) {
@@ -81,7 +81,7 @@ export class AlgorandService {
81
81
  if (senderAlgoBalance < minAlgoForFees) {
82
82
  throw new Error(`Insufficient ALGO for transaction fees. Need at least ${formatAlgo(minAlgoForFees)} ALGO for fees`);
83
83
  }
84
- const vault = await this.fetchVault("ALGO-USDC");
84
+ const vault = await this.fetchVaultByAssetId(config.assetId.toString());
85
85
  const recipientAddress = vault.address;
86
86
  // Validate recipient address
87
87
  if (!algosdk.isValidAddress(recipientAddress)) {
@@ -7,7 +7,6 @@ export type TransferBobaParams = {
7
7
  export type TransferTokenParams = {
8
8
  amount: string | number;
9
9
  tokenAddress: string;
10
- symbol: string;
11
10
  overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
12
11
  };
13
12
  export declare class BobaService {
@@ -23,7 +22,7 @@ export declare class BobaService {
23
22
  *
24
23
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
25
24
  */
26
- fetchVault(symbol: string): Promise<{
25
+ fetchVaultByTokenAddress(address: string): Promise<{
27
26
  address: string;
28
27
  tag?: string;
29
28
  }>;
@@ -18,14 +18,14 @@ export class BobaService {
18
18
  *
19
19
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
20
20
  */
21
- async fetchVault(symbol) {
22
- const data = await this.apiService.fetchVault(symbol);
21
+ async fetchVaultByTokenAddress(address) {
22
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
23
23
  return data;
24
24
  }
25
25
  async transferBobaEth(params) {
26
26
  const parsedAmount = ethers.parseEther(params.amount.toString());
27
27
  const provider = this.signer.provider;
28
- const vault = await this.fetchVault("BOBA-ETH");
28
+ const vault = await this.fetchVaultByTokenAddress("boba-eth");
29
29
  const recipientAddress = vault.address;
30
30
  if (!provider) {
31
31
  throw new Error("There is no provider in signer instance.");
@@ -53,7 +53,7 @@ export class BobaService {
53
53
  const tokenContract = ERC20__factory.connect(params.tokenAddress, this.signer);
54
54
  const tokenDecimals = await tokenContract.decimals();
55
55
  const parsedAmount = ethers.parseUnits(params.amount.toString(), tokenDecimals);
56
- const vault = await this.fetchVault(params.symbol);
56
+ const vault = await this.fetchVaultByTokenAddress(params.tokenAddress);
57
57
  const recipientAddress = vault.address;
58
58
  const senderBalance = await tokenContract.balanceOf(this.signer);
59
59
  if (senderBalance < parsedAmount) {
@@ -1,5 +1,5 @@
1
- import { Provider } from "@near-js/providers";
2
- import { FinalExecutionOutcome } from "@near-js/types";
1
+ import { type Provider } from "@near-js/providers";
2
+ import type { FinalExecutionOutcome } from "@near-js/types";
3
3
  export interface CreateAccountAction {
4
4
  type: "CreateAccount";
5
5
  }
@@ -89,7 +89,7 @@ export declare class NearService {
89
89
  *
90
90
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
91
91
  */
92
- fetchVault(symbol?: string): Promise<{
92
+ fetchVaultByTokenAddress(address: string): Promise<{
93
93
  address: string;
94
94
  tag?: string;
95
95
  }>;
@@ -1,7 +1,7 @@
1
- import assert from "assert";
2
- import { BigNumber } from "bignumber.js";
3
1
  import { JsonRpcProvider } from "@near-js/providers";
4
2
  import { parseNearAmount } from "@near-js/utils";
3
+ import assert from "assert";
4
+ import { BigNumber } from "bignumber.js";
5
5
  import { NEAR_RPC_URL } from "../constants";
6
6
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
7
7
  /**
@@ -38,13 +38,13 @@ export class NearService {
38
38
  *
39
39
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
40
40
  */
41
- async fetchVault(symbol = "NEAR") {
42
- const data = await this.apiService.fetchVault(symbol);
41
+ async fetchVaultByTokenAddress(address) {
42
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
43
43
  return data;
44
44
  }
45
45
  async transferNear(params) {
46
46
  const signerId = params.signerId ? params.signerId : this.wallet.signerId;
47
- const fetchVault = await this.fetchVault();
47
+ const fetchVault = await this.fetchVaultByTokenAddress("near");
48
48
  const destination = fetchVault.address;
49
49
  console.debug("destination:", destination);
50
50
  const parsedAmount = parseNearAmount(params.amount);
@@ -101,10 +101,10 @@ export class NearService {
101
101
  async transferTokens(params) {
102
102
  const signerId = params.signerId ? params.signerId : this.wallet.signerId;
103
103
  console.log("signerId:", signerId);
104
- const fetchVault = await this.fetchVault("NEAR-USDC");
104
+ const fetchVault = await this.fetchVaultByTokenAddress(params.tokenContractId);
105
105
  const destination = fetchVault.address;
106
106
  console.debug("destination:", destination);
107
- let actions = [];
107
+ const actions = [];
108
108
  const GAS = "30000000000000";
109
109
  const storageBalanceBoundsResult = await this.provider.query({
110
110
  request_type: "call_function",
@@ -1,4 +1,4 @@
1
- import { ethers } from "ethers";
1
+ import { type ethers } from "ethers";
2
2
  export type TransferOctaParams = {
3
3
  amount: string | number;
4
4
  overrides?: Omit<ethers.Overrides, "from" | "value" | "chainId">;
@@ -14,7 +14,7 @@ export declare class OctaService {
14
14
  *
15
15
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
16
16
  */
17
- fetchVault(symbol?: string): Promise<{
17
+ fetchVaultByTokenAddress(address: string): Promise<{
18
18
  address: string;
19
19
  tag?: string;
20
20
  }>;
@@ -13,14 +13,14 @@ export class OctaService {
13
13
  *
14
14
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
15
15
  */
16
- async fetchVault(symbol = "OCTA") {
17
- const data = await this.apiService.fetchVault(symbol);
16
+ async fetchVaultByTokenAddress(address) {
17
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
18
18
  return data;
19
19
  }
20
20
  async transferOcta(params) {
21
21
  const parsedAmount = parseEther(params.amount.toString());
22
22
  const provider = this.signer.provider;
23
- const vault = await this.fetchVault();
23
+ const vault = await this.fetchVaultByTokenAddress("octa-native");
24
24
  const recipientAddress = vault.address;
25
25
  if (!provider) {
26
26
  throw new Error("There is no provider in signer instance.");
@@ -1,4 +1,4 @@
1
- import { QuaiTransactionRequest } from "quais/providers";
1
+ import type { QuaiTransactionRequest } from "quais/providers";
2
2
  export type TransferQuaiParams = {
3
3
  amount: string | number;
4
4
  overrides?: Omit<QuaiTransactionRequest, "from" | "value" | "chainId">;
@@ -18,7 +18,7 @@ export declare class QuaiService {
18
18
  *
19
19
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
20
20
  */
21
- fetchVault(symbol: string): Promise<{
21
+ fetchVaultByTokenAddress(address: string): Promise<{
22
22
  address: string;
23
23
  tag?: string;
24
24
  }>;
@@ -13,13 +13,13 @@ export class QuaiService {
13
13
  *
14
14
  * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
15
15
  */
16
- async fetchVault(symbol) {
17
- const data = await this.apiService.fetchVault(symbol);
16
+ async fetchVaultByTokenAddress(address) {
17
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
18
18
  return data;
19
19
  }
20
20
  async transferQuai(params) {
21
21
  const parsedAmount = parseQuai(params.amount.toString());
22
- const vault = await this.fetchVault("QUAI");
22
+ const vault = await this.fetchVaultByTokenAddress("quai");
23
23
  const recipientAddress = vault.address;
24
24
  const request = {
25
25
  ...params.overrides,
@@ -1,4 +1,4 @@
1
- import { Asset, Horizon } from "@zebec-fintech/stellar-sdk";
1
+ import { Asset, Horizon } from "@stellar/stellar-sdk";
2
2
  export interface StellarWallet {
3
3
  address: string;
4
4
  signTransaction: (txXdr: string) => Promise<string>;
@@ -22,42 +22,42 @@ export declare class StellarService {
22
22
  /**
23
23
  * Fetches the Vault address.
24
24
  *
25
- * @returns {Promise<string>} A promise that resolves to the Vault address.
25
+ * @returns A promise that resolves to the Vault address.
26
26
  */
27
- fetchVault(symbol?: string): Promise<{
27
+ fetchVaultByAsset(asset: string): Promise<{
28
28
  address: string;
29
29
  tag?: string;
30
30
  }>;
31
31
  /**
32
32
  * Purchases a card by transferring XDB tokens.
33
33
  *
34
- * @param params - The parameters required to purchase a card.
34
+ * @param amount - The amount required to purchase a card.
35
35
  * @returns A promise that resolves to an array containing the transaction details and the API response.
36
- * @throws {InvalidEmailError} If the recipient's email address is invalid.
37
- * @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
36
+ * @throws If the recipient's email address is invalid.
37
+ * @throws If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
38
38
  */
39
39
  transferXLM(amount: string): Promise<string>;
40
40
  /**
41
41
  * Transfers USDC tokens.
42
42
  *
43
- * @param {string} amount - The amount of USDC to transfer.
44
- * @returns {Promise<string>} A promise that resolves to the transaction hash.
45
- * @throws {Error} If there is not enough USDC balance or if the transaction fails.
43
+ * @param amount - The amount of USDC to transfer.
44
+ * @returns A promise that resolves to the transaction hash.
45
+ * @throws If there is not enough USDC balance or if the transaction fails.
46
46
  */
47
47
  transferUSDC(amount: string): Promise<string>;
48
48
  /**
49
49
  * Retrieves the balance of the specified wallet.
50
50
  *
51
- * @param {string} wallet - The public key of the wallet to get the balance for.
52
- * @returns {Promise<string>} - A promise that resolves to the balance of the wallet.
51
+ * @param wallet - The public key of the wallet to get the balance for.
52
+ * @returns - A promise that resolves to the balance of the wallet.
53
53
  */
54
54
  getWalletBalance(wallet: string): Promise<string>;
55
55
  /**
56
56
  * Retrieves the balance of a specific token for the specified wallet.
57
57
  *
58
- * @param {string} wallet - The public key of the wallet to get the token balance for.
59
- * @param {Asset} asset - The asset object representing the token.
60
- * @returns {Promise<string>} - A promise that resolves to the balance of the token.
58
+ * @param wallet - The public key of the wallet to get the token balance for.
59
+ * @param asset - The asset object representing the token.
60
+ * @returns A promise that resolves to the balance of the token.
61
61
  */
62
62
  getTokenBalance(wallet: string, asset: Asset): Promise<string>;
63
63
  getAsset(assetCode: string, assetIssuer: string): Promise<Asset>;
@@ -1,4 +1,4 @@
1
- import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@zebec-fintech/stellar-sdk";
1
+ import { Asset, Horizon, Memo, Networks, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
2
2
  import { STELLAR_RPC_URL, STELLAR_USDC_ISSUER } from "../constants";
3
3
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
4
  export class StellarService {
@@ -23,27 +23,27 @@ export class StellarService {
23
23
  /**
24
24
  * Fetches the Vault address.
25
25
  *
26
- * @returns {Promise<string>} A promise that resolves to the Vault address.
26
+ * @returns A promise that resolves to the Vault address.
27
27
  */
28
- async fetchVault(symbol = "XLM") {
29
- const data = await this.apiService.fetchVault(symbol);
28
+ async fetchVaultByAsset(asset) {
29
+ const data = await this.apiService.fetchVaultByTokenAddress(asset);
30
30
  return data;
31
31
  }
32
32
  /**
33
33
  * Purchases a card by transferring XDB tokens.
34
34
  *
35
- * @param params - The parameters required to purchase a card.
35
+ * @param amount - The amount required to purchase a card.
36
36
  * @returns A promise that resolves to an array containing the transaction details and the API response.
37
- * @throws {InvalidEmailError} If the recipient's email address is invalid.
38
- * @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
37
+ * @throws If the recipient's email address is invalid.
38
+ * @throws If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
39
39
  */
40
40
  async transferXLM(amount) {
41
41
  // Fetch deposit address
42
- const vault = await this.fetchVault();
42
+ const vault = await this.fetchVaultByAsset("CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA");
43
43
  // Prepare transaction
44
44
  const account = await this.server.loadAccount(this.wallet.address);
45
45
  const fee = await this.server.fetchBaseFee();
46
- const memo = Memo.id(vault.tag?.toString() || "");
46
+ const memo = Memo.id(vault.tag?.toString() || "0");
47
47
  // Check Wallet balance
48
48
  const balance = await this.getWalletBalance(this.wallet.address);
49
49
  if (Number(balance) < Number(amount)) {
@@ -92,18 +92,18 @@ export class StellarService {
92
92
  /**
93
93
  * Transfers USDC tokens.
94
94
  *
95
- * @param {string} amount - The amount of USDC to transfer.
96
- * @returns {Promise<string>} A promise that resolves to the transaction hash.
97
- * @throws {Error} If there is not enough USDC balance or if the transaction fails.
95
+ * @param amount - The amount of USDC to transfer.
96
+ * @returns A promise that resolves to the transaction hash.
97
+ * @throws If there is not enough USDC balance or if the transaction fails.
98
98
  */
99
99
  async transferUSDC(amount) {
100
+ // Create USDC asset object
101
+ const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
100
102
  // Fetch deposit address
101
- const vault = await this.fetchVault("XLM-USDC");
103
+ const vault = await this.fetchVaultByAsset(`${usdcAsset.code}:${usdcAsset.issuer}`);
102
104
  // Prepare transaction
103
105
  const account = await this.server.loadAccount(this.wallet.address);
104
106
  const fee = await this.server.fetchBaseFee();
105
- // Create USDC asset object
106
- const usdcAsset = new Asset("USDC", this.sandbox ? STELLAR_USDC_ISSUER.Sandbox : STELLAR_USDC_ISSUER.Production);
107
107
  // Check Wallet balance
108
108
  const balance = await this.getTokenBalance(this.wallet.address, usdcAsset);
109
109
  if (Number(balance) < Number(amount)) {
@@ -151,8 +151,8 @@ export class StellarService {
151
151
  /**
152
152
  * Retrieves the balance of the specified wallet.
153
153
  *
154
- * @param {string} wallet - The public key of the wallet to get the balance for.
155
- * @returns {Promise<string>} - A promise that resolves to the balance of the wallet.
154
+ * @param wallet - The public key of the wallet to get the balance for.
155
+ * @returns - A promise that resolves to the balance of the wallet.
156
156
  */
157
157
  async getWalletBalance(wallet) {
158
158
  const account = await this.server.loadAccount(wallet);
@@ -162,9 +162,9 @@ export class StellarService {
162
162
  /**
163
163
  * Retrieves the balance of a specific token for the specified wallet.
164
164
  *
165
- * @param {string} wallet - The public key of the wallet to get the token balance for.
166
- * @param {Asset} asset - The asset object representing the token.
167
- * @returns {Promise<string>} - A promise that resolves to the balance of the token.
165
+ * @param wallet - The public key of the wallet to get the token balance for.
166
+ * @param asset - The asset object representing the token.
167
+ * @returns A promise that resolves to the balance of the token.
168
168
  */
169
169
  async getTokenBalance(wallet, asset) {
170
170
  const account = await this.server.loadAccount(wallet);
@@ -1,4 +1,4 @@
1
- import { Asset, Horizon } from "@zebec-fintech/stellar-sdk";
1
+ import { Asset, Horizon } from "@stellar/stellar-sdk";
2
2
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
3
3
  export interface XDBWalletInterface {
4
4
  address: string;
@@ -25,7 +25,7 @@ export declare class XDBService {
25
25
  *
26
26
  * @returns {Promise<string>} A promise that resolves to the Vault address.
27
27
  */
28
- fetchVault(symbol?: string): Promise<{
28
+ fetchVaultByAsset(asset: string): Promise<{
29
29
  address: string;
30
30
  tag?: string;
31
31
  }>;
@@ -34,23 +34,22 @@ export declare class XDBService {
34
34
  *
35
35
  * @param params - The parameters required to purchase a card.
36
36
  * @returns A promise that resolves to an array containing the transaction details and the API response.
37
- * @throws {InvalidEmailError} If the recipient's email address is invalid.
38
- * @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
37
+ * @throws `Error` If there is not enough balance, or if the transaction fails.
39
38
  */
40
39
  transferXDB(amount: string): Promise<string>;
41
40
  /**
42
41
  * Retrieves the balance of the specified wallet.
43
42
  *
44
- * @param {string} wallet - The public key of the wallet to get the balance for.
45
- * @returns {Promise<string>} - A promise that resolves to the balance of the wallet.
43
+ * @param wallet - The public key of the wallet to get the balance for.
44
+ * @returns - A promise that resolves to the balance of the wallet.
46
45
  */
47
46
  getNativeBalance(wallet: string): Promise<string>;
48
47
  /**
49
48
  * Retrieves the balance of a specific token for the specified wallet.
50
49
  *
51
- * @param {string} wallet - The public key of the wallet to get the token balance for.
52
- * @param {Asset} asset - The asset object representing the token.
53
- * @returns {Promise<string>} - A promise that resolves to the balance of the token.
50
+ * @param wallet - The public key of the wallet to get the token balance for.
51
+ * @param asset - The asset object representing the token.
52
+ * @returns - A promise that resolves to the balance of the token.
54
53
  */
55
54
  getTokenBalance(wallet: string, asset: Asset): Promise<string>;
56
55
  getAsset(assetCode: string, assetIssuer: string): Asset;
@@ -1,4 +1,4 @@
1
- import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@zebec-fintech/stellar-sdk";
1
+ import { Asset, Horizon, Memo, Operation, TimeoutInfinite, TransactionBuilder, } from "@stellar/stellar-sdk";
2
2
  import { XDB_NETWORK, XDB_RPC_URL } from "../constants";
3
3
  import { ZebecCardAPIService } from "../helpers/apiHelpers";
4
4
  export class XDBService {
@@ -25,8 +25,8 @@ export class XDBService {
25
25
  *
26
26
  * @returns {Promise<string>} A promise that resolves to the Vault address.
27
27
  */
28
- async fetchVault(symbol = "XDB") {
29
- const data = await this.apiService.fetchVault(symbol);
28
+ async fetchVaultByAsset(asset) {
29
+ const data = await this.apiService.fetchVaultByTokenAddress(asset);
30
30
  return data;
31
31
  }
32
32
  /**
@@ -34,12 +34,11 @@ export class XDBService {
34
34
  *
35
35
  * @param params - The parameters required to purchase a card.
36
36
  * @returns A promise that resolves to an array containing the transaction details and the API response.
37
- * @throws {InvalidEmailError} If the recipient's email address is invalid.
38
- * @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
37
+ * @throws `Error` If there is not enough balance, or if the transaction fails.
39
38
  */
40
39
  async transferXDB(amount) {
41
40
  // Fetch deposit address
42
- const vault = await this.fetchVault("XDB");
41
+ const vault = await this.fetchVaultByAsset("xdb");
43
42
  const recipientAddress = vault.address;
44
43
  const tag = vault.tag || "0";
45
44
  // Prepare transaction
@@ -94,8 +93,8 @@ export class XDBService {
94
93
  /**
95
94
  * Retrieves the balance of the specified wallet.
96
95
  *
97
- * @param {string} wallet - The public key of the wallet to get the balance for.
98
- * @returns {Promise<string>} - A promise that resolves to the balance of the wallet.
96
+ * @param wallet - The public key of the wallet to get the balance for.
97
+ * @returns - A promise that resolves to the balance of the wallet.
99
98
  */
100
99
  async getNativeBalance(wallet) {
101
100
  const account = await this.server.loadAccount(wallet);
@@ -105,9 +104,9 @@ export class XDBService {
105
104
  /**
106
105
  * Retrieves the balance of a specific token for the specified wallet.
107
106
  *
108
- * @param {string} wallet - The public key of the wallet to get the token balance for.
109
- * @param {Asset} asset - The asset object representing the token.
110
- * @returns {Promise<string>} - A promise that resolves to the balance of the token.
107
+ * @param wallet - The public key of the wallet to get the token balance for.
108
+ * @param asset - The asset object representing the token.
109
+ * @returns - A promise that resolves to the balance of the token.
111
110
  */
112
111
  async getTokenBalance(wallet, asset) {
113
112
  const account = await this.server.loadAccount(wallet);
@@ -1,4 +1,4 @@
1
- import { BaseTransaction, Client, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
1
+ import { type BaseTransaction, Client, type SubmittableTransaction, type Transaction, type TxResponse } from "xrpl";
2
2
  export interface XRPLWallet {
3
3
  address: string;
4
4
  signTransaction: (transaction: SubmittableTransaction | BaseTransaction) => Promise<string>;
@@ -11,11 +11,11 @@ export declare class XRPLService {
11
11
  sandbox?: boolean;
12
12
  });
13
13
  /**
14
- * Fetches the Bitcoin vault address.
14
+ * Fetches the xrpl vault address.
15
15
  *
16
- * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
16
+ * @returns A promise that resolves to the vault address.
17
17
  */
18
- fetchVault(symbol?: string): Promise<{
18
+ fetchVaultByTokenAddress(address: string): Promise<{
19
19
  address: string;
20
20
  tag?: string;
21
21
  }>;
@@ -13,12 +13,12 @@ export class XRPLService {
13
13
  this.client = new Client(xrplNetwork);
14
14
  }
15
15
  /**
16
- * Fetches the Bitcoin vault address.
16
+ * Fetches the xrpl vault address.
17
17
  *
18
- * @returns {Promise<{ address: string }>} A promise that resolves to the vault address.
18
+ * @returns A promise that resolves to the vault address.
19
19
  */
20
- async fetchVault(symbol = "XRP") {
21
- const data = await this.apiService.fetchVault(symbol);
20
+ async fetchVaultByTokenAddress(address) {
21
+ const data = await this.apiService.fetchVaultByTokenAddress(address);
22
22
  return data;
23
23
  }
24
24
  async transferXRP(params) {
@@ -27,13 +27,13 @@ export class XRPLService {
27
27
  if (!isValidAddress(walletAddress)) {
28
28
  throw new Error("Invalid wallet address");
29
29
  }
30
- const { address: destination, tag } = await this.fetchVault();
30
+ const { address: destination, tag } = await this.fetchVaultByTokenAddress("xrp");
31
31
  console.debug("destination:", destination);
32
32
  console.debug("tag:", tag);
33
33
  if (!isValidAddress(destination)) {
34
34
  throw new Error("Invalid destination address");
35
35
  }
36
- const destinationTag = tag && tag !== "" ? parseInt(tag) : undefined;
36
+ const destinationTag = tag && tag !== "" ? parseInt(tag, 10) : undefined;
37
37
  const amountInDrops = xrpToDrops(params.amount);
38
38
  const transaction = {
39
39
  TransactionType: "Payment",
@@ -49,9 +49,6 @@ export class XRPLService {
49
49
  const response = await this.client.submitAndWait(signedTx);
50
50
  return response;
51
51
  }
52
- catch (error) {
53
- throw error;
54
- }
55
52
  finally {
56
53
  await this.client.disconnect();
57
54
  }
@@ -62,13 +59,13 @@ export class XRPLService {
62
59
  if (!isValidAddress(walletAddress)) {
63
60
  throw new Error("Invalid wallet address");
64
61
  }
65
- const { address: destination, tag } = await this.fetchVault();
62
+ const { address: destination, tag } = await this.fetchVaultByTokenAddress(params.token.currency);
66
63
  console.debug("destination:", destination);
67
64
  console.debug("tag:", tag);
68
65
  if (!isValidAddress(destination)) {
69
66
  throw new Error("Invalid destination address");
70
67
  }
71
- const destinationTag = tag && tag !== "" ? parseInt(tag) : undefined;
68
+ const destinationTag = tag && tag !== "" ? parseInt(tag, 10) : undefined;
72
69
  const transaction = {
73
70
  TransactionType: "Payment",
74
71
  Account: walletAddress,
@@ -87,9 +84,6 @@ export class XRPLService {
87
84
  const response = await this.client.submitAndWait(signedTx);
88
85
  return response;
89
86
  }
90
- catch (error) {
91
- throw error;
92
- }
93
87
  finally {
94
88
  await this.client.disconnect();
95
89
  }
@@ -115,9 +109,6 @@ export class XRPLService {
115
109
  const response = await this.client.submitAndWait(signedTx);
116
110
  return response;
117
111
  }
118
- catch (error) {
119
- throw error;
120
- }
121
112
  finally {
122
113
  await this.client.disconnect();
123
114
  }
@@ -134,9 +125,6 @@ export class XRPLService {
134
125
  });
135
126
  return balances;
136
127
  }
137
- catch (error) {
138
- throw error;
139
- }
140
128
  finally {
141
129
  await this.client.disconnect();
142
130
  }
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "@near-js/transactions": "^2.5.1",
7
7
  "@near-js/types": "^2.5.1",
8
8
  "@near-js/utils": "^2.5.1",
9
- "@provablehq/sdk": "^0.10.5",
10
- "@zebec-fintech/stellar-sdk": "^15.0.2",
9
+ "@provablehq/sdk": "^0.11.0",
10
+ "@stellar/stellar-sdk": "^15.1.0",
11
11
  "algosdk": "^3.5.2",
12
12
  "axios": "^1.16.0",
13
13
  "bignumber.js": "^11.1.1",
@@ -63,5 +63,5 @@
63
63
  },
64
64
  "type": "module",
65
65
  "types": "dist/index.d.ts",
66
- "version": "1.11.5"
66
+ "version": "1.12.0"
67
67
  }