@zebec-network/exchange-card-sdk 1.1.3 → 1.1.5

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 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.
@@ -7,6 +7,10 @@ export declare const TON_RPC_URL: Record<"Production" | "Sandbox", string>;
7
7
  export declare const DIGITALBITS_RPC_URL: Record<"Production" | "Sandbox", string>;
8
8
  export declare const XDB_PASSPHRASE: Record<"Production" | "Sandbox", string>;
9
9
  export declare const STELLAR_RPC_URL: Record<"Production" | "Sandbox", string>;
10
+ export declare const USDC_ISSUER: {
11
+ TESTNET: string;
12
+ MAINNET: string;
13
+ };
10
14
  export declare const COUNTRIES_WITH_CCA3: readonly [{
11
15
  readonly name: {
12
16
  readonly common: "South Georgia";
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.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.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;
4
4
  const chains_1 = require("./chains");
5
5
  exports.ZEBEC_CARD_ADDRESS = {
6
6
  [chains_1.SupportedChain.Sepolia]: "0x00d90625CcaB01eA0e589DFd3C99972180CE609A",
@@ -52,6 +52,11 @@ exports.STELLAR_RPC_URL = {
52
52
  Production: "https://stellar-mainnet.liquify.com/api=41EEWAH79Y5OCGI7/mainnet",
53
53
  Sandbox: "https://horizon-testnet.stellar.org",
54
54
  };
55
+ // Add USDC asset constants
56
+ exports.USDC_ISSUER = {
57
+ TESTNET: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
58
+ MAINNET: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
59
+ };
55
60
  exports.COUNTRIES_WITH_CCA3 = [
56
61
  {
57
62
  name: {
@@ -1,4 +1,5 @@
1
1
  import { StellarWalletsKit } from "@creit.tech/stellar-wallets-kit";
2
+ import { Asset } from "@stellar/stellar-sdk";
2
3
  import { APIConfig } from "../helpers/apiHelpers";
3
4
  import { Quote } from "../types";
4
5
  export declare class StellarService {
@@ -42,6 +43,14 @@ export declare class StellarService {
42
43
  * @throws {Error} If the quote is invalid or expired, if there is not enough balance, or if the transaction fails.
43
44
  */
44
45
  transferXLM(amount: string): Promise<string>;
46
+ /**
47
+ * Transfers USDC tokens.
48
+ *
49
+ * @param {string} amount - The amount of USDC to transfer.
50
+ * @returns {Promise<string>} A promise that resolves to the transaction hash.
51
+ * @throws {Error} If there is not enough USDC balance or if the transaction fails.
52
+ */
53
+ transferUSDC(amount: string): Promise<string>;
45
54
  /**
46
55
  * Retrieves the balance of the specified wallet.
47
56
  *
@@ -49,4 +58,12 @@ export declare class StellarService {
49
58
  * @returns {Promise<string>} - A promise that resolves to the balance of the wallet.
50
59
  */
51
60
  getWalletBalance(wallet: string): Promise<string>;
61
+ /**
62
+ * Retrieves the balance of a specific token for the specified wallet.
63
+ *
64
+ * @param {string} wallet - The public key of the wallet to get the token balance for.
65
+ * @param {Asset} asset - The asset object representing the token.
66
+ * @returns {Promise<string>} - A promise that resolves to the balance of the token.
67
+ */
68
+ getTokenBalance(wallet: string, asset: Asset): Promise<string>;
52
69
  }
@@ -103,6 +103,68 @@ class StellarService {
103
103
  }
104
104
  throw new Error("Max retries reached");
105
105
  }
106
+ /**
107
+ * Transfers USDC tokens.
108
+ *
109
+ * @param {string} amount - The amount of USDC to transfer.
110
+ * @returns {Promise<string>} A promise that resolves to the transaction hash.
111
+ * @throws {Error} If there is not enough USDC balance or if the transaction fails.
112
+ */
113
+ async transferUSDC(amount) {
114
+ // Fetch deposit address
115
+ const vault = await this.fetchVault();
116
+ const accountAddress = await this.kit.getAddress();
117
+ // Prepare transaction
118
+ const account = await this.server.loadAccount(accountAddress.address);
119
+ const fee = await this.server.fetchBaseFee();
120
+ const memo = stellar_sdk_1.Memo.id(vault.tag?.toString() || "");
121
+ // Create USDC asset object
122
+ const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.USDC_ISSUER.TESTNET : constants_1.USDC_ISSUER.MAINNET);
123
+ // Check Wallet balance
124
+ const balance = await this.getTokenBalance(accountAddress.address, usdcAsset);
125
+ if (Number(balance) < Number(amount)) {
126
+ throw new Error("Insufficient USDC balance");
127
+ }
128
+ // Build and submit transaction
129
+ const transaction = new stellar_sdk_1.TransactionBuilder(account, {
130
+ fee: fee.toString(),
131
+ networkPassphrase: this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC,
132
+ })
133
+ .addOperation(stellar_sdk_1.Operation.payment({
134
+ destination: vault.address,
135
+ asset: usdcAsset,
136
+ amount,
137
+ }))
138
+ .addMemo(memo)
139
+ .setTimeout(stellar_sdk_1.TimeoutInfinite)
140
+ .build();
141
+ // Sign the transaction
142
+ const { signedTxXdr } = await this.kit.signTransaction(transaction.toXDR());
143
+ const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC);
144
+ let retries = 0;
145
+ const maxRetries = 5;
146
+ let delay = 1000;
147
+ while (retries < maxRetries) {
148
+ try {
149
+ const transactionResult = await this.server.submitTransaction(tx, {
150
+ skipMemoRequiredCheck: false,
151
+ });
152
+ const txHash = transactionResult.hash;
153
+ return txHash;
154
+ }
155
+ catch (error) {
156
+ console.debug("error: ", error);
157
+ if (retries >= maxRetries) {
158
+ throw error;
159
+ }
160
+ retries += 1;
161
+ console.debug(`Retrying in ${delay / 1000} seconds...`);
162
+ await new Promise((resolve) => setTimeout(resolve, delay));
163
+ delay *= 2; // Exponential backoff
164
+ }
165
+ }
166
+ throw new Error("Max retries reached");
167
+ }
106
168
  /**
107
169
  * Retrieves the balance of the specified wallet.
108
170
  *
@@ -114,5 +176,25 @@ class StellarService {
114
176
  const nativeBalance = account.balances.find((balance) => balance.asset_type === "native");
115
177
  return nativeBalance ? nativeBalance.balance : "0";
116
178
  }
179
+ /**
180
+ * Retrieves the balance of a specific token for the specified wallet.
181
+ *
182
+ * @param {string} wallet - The public key of the wallet to get the token balance for.
183
+ * @param {Asset} asset - The asset object representing the token.
184
+ * @returns {Promise<string>} - A promise that resolves to the balance of the token.
185
+ */
186
+ async getTokenBalance(wallet, asset) {
187
+ const account = await this.server.loadAccount(wallet);
188
+ try {
189
+ const balance = account.balances.find((b) => b.asset_type !== "native" &&
190
+ b.asset_type !== "liquidity_pool_shares" &&
191
+ b.asset_code === asset.getCode())?.balance || "0";
192
+ return balance;
193
+ }
194
+ catch (error) {
195
+ console.debug(`Error fetching ${asset.getCode()} balance:`, error);
196
+ return "0";
197
+ }
198
+ }
117
199
  }
118
200
  exports.StellarService = StellarService;
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
- {
2
- "name": "@zebec-network/exchange-card-sdk",
3
- "version": "1.1.3",
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
- "@typechain/ethers-v6": "^0.5.1",
21
- "@types/jsonwebtoken": "^9.0.7",
22
- "@types/mocha": "^10.0.9",
23
- "@types/node": "^22.7.9",
24
- "dotenv": "^16.4.5",
25
- "mocha": "^10.7.3",
26
- "prettier": "^3.3.3",
27
- "rimraf": "^6.0.1",
28
- "ts-mocha": "^10.0.0",
29
- "ts-node": "^10.9.2",
30
- "typechain": "^8.3.2",
31
- "typescript": "^5.6.3"
32
- },
33
- "dependencies": {
34
- "@creit.tech/stellar-wallets-kit": "^1.7.1",
35
- "@polkadot/api": "^14.3.1",
36
- "@polkadot/types": "^14.3.1",
37
- "@polkadot/util": "^13.2.3",
38
- "@stellar/stellar-sdk": "^13.1.0",
39
- "@tonconnect/sdk": "^3.0.6",
40
- "axios": "^1.7.7",
41
- "ethers": "^6.13.4",
42
- "tonweb": "^0.0.66",
43
- "xdb-digitalbits-sdk": "^8.2.2"
44
- },
45
- "repository": {
46
- "type": "git",
47
- "url": "git+https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git"
48
- },
49
- "homepage": "https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git#README",
50
- "keywords": [
51
- "zebec",
52
- "zebec fintech",
53
- "zebec instant card"
54
- ],
55
- "publishConfig": {
56
- "access": "public"
57
- }
58
- }
1
+ {
2
+ "name": "@zebec-network/exchange-card-sdk",
3
+ "version": "1.1.5",
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
+ "@typechain/ethers-v6": "^0.5.1",
21
+ "@types/jsonwebtoken": "^9.0.7",
22
+ "@types/mocha": "^10.0.9",
23
+ "@types/node": "^22.7.9",
24
+ "dotenv": "^16.4.5",
25
+ "mocha": "^10.7.3",
26
+ "prettier": "^3.3.3",
27
+ "rimraf": "^6.0.1",
28
+ "ts-mocha": "^10.0.0",
29
+ "ts-node": "^10.9.2",
30
+ "typechain": "^8.3.2",
31
+ "typescript": "^5.6.3"
32
+ },
33
+ "dependencies": {
34
+ "@creit.tech/stellar-wallets-kit": "^1.7.1",
35
+ "@polkadot/api": "^14.3.1",
36
+ "@polkadot/types": "^14.3.1",
37
+ "@polkadot/util": "^13.2.3",
38
+ "@stellar/stellar-sdk": "^13.1.0",
39
+ "@tonconnect/sdk": "^3.0.6",
40
+ "axios": "^1.7.7",
41
+ "ethers": "^6.13.4",
42
+ "tonweb": "^0.0.66",
43
+ "xdb-digitalbits-sdk": "^8.2.2"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git"
48
+ },
49
+ "homepage": "https://github.com/Zebec-Fintech-Labs/zebec-card-minimal-sdk.git#README",
50
+ "keywords": [
51
+ "zebec",
52
+ "zebec fintech",
53
+ "zebec instant card"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }