@zebec-network/exchange-card-sdk 1.2.0 → 1.2.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.
|
@@ -59,9 +59,8 @@ class AlgorandService {
|
|
|
59
59
|
if (senderBalance < parsedAmount + minBalance) {
|
|
60
60
|
throw new Error(`Insufficient balance. Need ${microAlgoToAlgo(parsedAmount + minBalance)} ALGO, have ${microAlgoToAlgo(senderBalance)} ALGO`);
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const recipientAddress = "K6ZWFT3XZ2YJK6XOUNPK4PP6PUX6CN2QMEY22EBDYXMKMLYRDEHSMSCNYM";
|
|
62
|
+
const vault = await this.fetchVault("ALGO");
|
|
63
|
+
const recipientAddress = vault.address;
|
|
65
64
|
// Validate recipient address
|
|
66
65
|
if (!algosdk_1.default.isValidAddress(recipientAddress)) {
|
|
67
66
|
throw new Error("Invalid recipient address");
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Asset } from "@stellar/stellar-sdk";
|
|
1
|
+
import { Asset, Horizon } from "@stellar/stellar-sdk";
|
|
3
2
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
4
3
|
import { Quote } from "../types";
|
|
4
|
+
export interface StellarWallet {
|
|
5
|
+
address: string;
|
|
6
|
+
signTransaction: (txXdr: string) => Promise<string>;
|
|
7
|
+
}
|
|
5
8
|
export declare class StellarService {
|
|
6
|
-
readonly
|
|
9
|
+
readonly wallet: StellarWallet;
|
|
7
10
|
private apiService;
|
|
8
|
-
|
|
11
|
+
readonly server: Horizon.Server;
|
|
9
12
|
private sandbox;
|
|
10
13
|
/**
|
|
11
14
|
* Constructs an instance of the service.
|
|
@@ -14,7 +17,7 @@ export declare class StellarService {
|
|
|
14
17
|
* @param {APIConfig} apiConfig - The configuration object for the API.
|
|
15
18
|
* @param sdkOptions - Optional configuration for the SDK.
|
|
16
19
|
*/
|
|
17
|
-
constructor(
|
|
20
|
+
constructor(wallet: StellarWallet, apiConfig: APIConfig, sdkOptions?: {
|
|
18
21
|
sandbox?: boolean;
|
|
19
22
|
apiKey?: string;
|
|
20
23
|
});
|
|
@@ -5,7 +5,7 @@ const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const apiHelpers_1 = require("../helpers/apiHelpers");
|
|
7
7
|
class StellarService {
|
|
8
|
-
|
|
8
|
+
wallet;
|
|
9
9
|
apiService;
|
|
10
10
|
server;
|
|
11
11
|
sandbox;
|
|
@@ -16,8 +16,8 @@ class StellarService {
|
|
|
16
16
|
* @param {APIConfig} apiConfig - The configuration object for the API.
|
|
17
17
|
* @param sdkOptions - Optional configuration for the SDK.
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
19
|
+
constructor(wallet, apiConfig, sdkOptions) {
|
|
20
|
+
this.wallet = wallet;
|
|
21
21
|
const sandbox = sdkOptions?.sandbox ? sdkOptions.sandbox : false;
|
|
22
22
|
this.apiService = new apiHelpers_1.ZebecCardAPIService(apiConfig, sandbox);
|
|
23
23
|
this.server = new stellar_sdk_1.Horizon.Server(sandbox ? constants_1.STELLAR_RPC_URL.Sandbox : constants_1.STELLAR_RPC_URL.Production);
|
|
@@ -62,13 +62,12 @@ class StellarService {
|
|
|
62
62
|
async transferXLM(amount) {
|
|
63
63
|
// Fetch deposit address
|
|
64
64
|
const vault = await this.fetchVault();
|
|
65
|
-
const accountAddress = await this.kit.getAddress();
|
|
66
65
|
// Prepare transaction
|
|
67
|
-
const account = await this.server.loadAccount(
|
|
66
|
+
const account = await this.server.loadAccount(this.wallet.address);
|
|
68
67
|
const fee = await this.server.fetchBaseFee();
|
|
69
68
|
const memo = stellar_sdk_1.Memo.id(vault.tag?.toString() || "");
|
|
70
69
|
// Check Wallet balance
|
|
71
|
-
const balance = await this.getWalletBalance(
|
|
70
|
+
const balance = await this.getWalletBalance(this.wallet.address);
|
|
72
71
|
if (Number(balance) < Number(amount)) {
|
|
73
72
|
throw new Error("Insufficient balance");
|
|
74
73
|
}
|
|
@@ -86,7 +85,7 @@ class StellarService {
|
|
|
86
85
|
.setTimeout(stellar_sdk_1.TimeoutInfinite)
|
|
87
86
|
.build();
|
|
88
87
|
// Sign the transaction
|
|
89
|
-
const
|
|
88
|
+
const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
|
|
90
89
|
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC);
|
|
91
90
|
let retries = 0;
|
|
92
91
|
const maxRetries = 5;
|
|
@@ -122,14 +121,13 @@ class StellarService {
|
|
|
122
121
|
async transferUSDC(amount) {
|
|
123
122
|
// Fetch deposit address
|
|
124
123
|
const vault = await this.fetchUSDCVault();
|
|
125
|
-
const accountAddress = await this.kit.getAddress();
|
|
126
124
|
// Prepare transaction
|
|
127
|
-
const account = await this.server.loadAccount(
|
|
125
|
+
const account = await this.server.loadAccount(this.wallet.address);
|
|
128
126
|
const fee = await this.server.fetchBaseFee();
|
|
129
127
|
// Create USDC asset object
|
|
130
128
|
const usdcAsset = new stellar_sdk_1.Asset("USDC", this.sandbox ? constants_1.STELLAR_USDC_ISSUER.Sandbox : constants_1.STELLAR_USDC_ISSUER.Production);
|
|
131
129
|
// Check Wallet balance
|
|
132
|
-
const balance = await this.getTokenBalance(
|
|
130
|
+
const balance = await this.getTokenBalance(this.wallet.address, usdcAsset);
|
|
133
131
|
if (Number(balance) < Number(amount)) {
|
|
134
132
|
throw new Error("Insufficient USDC balance");
|
|
135
133
|
}
|
|
@@ -146,7 +144,7 @@ class StellarService {
|
|
|
146
144
|
.setTimeout(stellar_sdk_1.TimeoutInfinite)
|
|
147
145
|
.build();
|
|
148
146
|
// Sign the transaction
|
|
149
|
-
const
|
|
147
|
+
const signedTxXdr = await this.wallet.signTransaction(transaction.toXDR());
|
|
150
148
|
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, this.sandbox ? stellar_sdk_1.Networks.TESTNET : stellar_sdk_1.Networks.PUBLIC);
|
|
151
149
|
let retries = 0;
|
|
152
150
|
const maxRetries = 5;
|
|
@@ -51,15 +51,12 @@ class XDBService {
|
|
|
51
51
|
*/
|
|
52
52
|
async transferXDB(amount) {
|
|
53
53
|
// Fetch deposit address
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const tag = "Zebec Card Purchase"; // Example tag, replace with actual vault tag if needed
|
|
58
|
-
const recipientAddress = "GCSD36EP7FILL5D3SFL7ZYLGI3I5SFJTYZBV6OPJKYLS74VD6WBSCBKO"; // Example address, replace with actual vault address
|
|
54
|
+
const vault = await this.fetchVault("XDB");
|
|
55
|
+
const recipientAddress = vault.address;
|
|
56
|
+
const tag = vault.tag || "0";
|
|
59
57
|
// Prepare transaction
|
|
60
58
|
const account = await this.server.loadAccount(this.wallet.address);
|
|
61
59
|
const fee = await this.server.fetchBaseFee();
|
|
62
|
-
// const memo = Memo.id(vault.tag?.toString() || "");
|
|
63
60
|
const memo = stellar_sdk_1.Memo.id(tag);
|
|
64
61
|
// Check Wallet balance
|
|
65
62
|
const balance = await this.getNativeBalance(this.wallet.address);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@algorandfoundation/algokit-utils": "^9.1.1",
|
|
39
|
-
"@creit.tech/stellar-wallets-kit": "^1.7.1",
|
|
40
39
|
"@mempool/mempool.js": "^3.0.0",
|
|
41
40
|
"@near-js/crypto": "^2.0.1",
|
|
42
41
|
"@near-js/providers": "^2.0.1",
|