@zebec-network/exchange-card-sdk 1.5.0-beta.1 → 1.5.0-beta.3
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/package.json +7 -7
- package/dist/services/zanoService.d.ts +0 -56
- package/dist/services/zanoService.js +0 -107
package/README.md
CHANGED
|
@@ -23,28 +23,6 @@ Example:
|
|
|
23
23
|
For EVM compatible networks:
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import { ethers } from 'ethers';
|
|
27
|
-
import { ZebecCardService, Recipient, CountryCode } from '@zebec-fintech/silver-card-sdk';
|
|
28
|
-
|
|
29
|
-
const signer: ethers.Signer = ... ; // Signer instance from Wallet Extension
|
|
30
|
-
|
|
31
|
-
const chainId = 11155111; // Sepolia testnet
|
|
32
|
-
const apiKey = process.env.API_KEY!;
|
|
33
|
-
const encryptionKey = process.env.ENCRYPTION_KEY!;
|
|
34
|
-
|
|
35
|
-
const service = new ZebecCardService(
|
|
36
|
-
signer,
|
|
37
|
-
chainId,
|
|
38
|
-
{
|
|
39
|
-
apiKey,
|
|
40
|
-
encryptionKey,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
sandbox: true, // Set to true for development or testing
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
26
|
For Bittensor Network:
|
|
49
27
|
|
|
50
28
|
```typescript
|
|
@@ -76,264 +54,3 @@ Note: The `fetchQuote` method should be called regularly. Make sure to check it'
|
|
|
76
54
|
const amount = "150.55"; // Amount in USD
|
|
77
55
|
const quote = await service.fetchQuote(amount);
|
|
78
56
|
```
|
|
79
|
-
|
|
80
|
-
#### Response
|
|
81
|
-
|
|
82
|
-
The `fetchQuote` method returns a quote object with the following fields:
|
|
83
|
-
|
|
84
|
-
- **id**: Unique quote identifier.
|
|
85
|
-
- **token**: Name or symbol of the token used to purchase the card. (e.g., `"USDC"`, `"TAO"`)
|
|
86
|
-
- **targetCurrency**: Currency code for the amount. (e.g., `"USD"`)
|
|
87
|
-
- **amountRequested**: Amount of USD the card is being purchased for.
|
|
88
|
-
- **pricePerUnitCurrency**: Price of the token per unit USD.
|
|
89
|
-
- **totalPrice**: Total token amount needed for purchase.
|
|
90
|
-
- **platformFee**: Any additional fees charged by the platform.
|
|
91
|
-
- **expiresIn**: Time in milliseconds before the quote expires.
|
|
92
|
-
- **timestamp**: Timestamp when the quote was generated.
|
|
93
|
-
- **status**: Quote status.
|
|
94
|
-
|
|
95
|
-
### Purchase Card
|
|
96
|
-
|
|
97
|
-
The `purchaseCard` method initiates a virtual card purchase. It performs four main operations:
|
|
98
|
-
|
|
99
|
-
1. Approves token spending to the ZebecCard smart contract. (ERC20 tokens only)
|
|
100
|
-
2. Deposits tokens into the user's Zebec vault.
|
|
101
|
-
3. Initiates the card purchase on-chain. (ERC20 tokens only)
|
|
102
|
-
4. Posts transaction data, along with metadata, to the Zebec backend.
|
|
103
|
-
|
|
104
|
-
The method returns a tuple with responses from each stage of the process.
|
|
105
|
-
|
|
106
|
-
#### Code Example
|
|
107
|
-
|
|
108
|
-
For EVM compatible networks:
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
const participantId = "JohnChamling";
|
|
112
|
-
const firstName = "John";
|
|
113
|
-
const lastName = "Chamling";
|
|
114
|
-
const emailAddress = "user@example.com";
|
|
115
|
-
const mobilePhone = "+91 012345678";
|
|
116
|
-
const language = "en-US";
|
|
117
|
-
const city = "Bharatpur";
|
|
118
|
-
const state = "Bagmati";
|
|
119
|
-
const postalCode = "44200";
|
|
120
|
-
const countryCode: CountryCode = "NPL";
|
|
121
|
-
const address1 = "Shittal street, Bharatpur - 10, Chitwan";
|
|
122
|
-
|
|
123
|
-
const recipient = Recipient.create(
|
|
124
|
-
participantId,
|
|
125
|
-
firstName,
|
|
126
|
-
lastName,
|
|
127
|
-
emailAddress,
|
|
128
|
-
mobilePhone,
|
|
129
|
-
language,
|
|
130
|
-
city,
|
|
131
|
-
state,
|
|
132
|
-
postalCode,
|
|
133
|
-
countryCode,
|
|
134
|
-
address1,
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const amount = "150.55";
|
|
138
|
-
const quote = await service.fetchQuote(amount);
|
|
139
|
-
const [depositResponse, buyCardResponse, apiResponse] = await service.purchaseCard({
|
|
140
|
-
amount,
|
|
141
|
-
recipient,
|
|
142
|
-
quote,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
console.log("Deposit Transaction Hash:", depositResponse.hash);
|
|
146
|
-
console.log("Purchase Transaction Hash:", buyCardResponse.hash);
|
|
147
|
-
console.log("Zebec Server Response:", apiResponse.data);
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
For Bittensor Network:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
const participantId = "JohnChamling";
|
|
154
|
-
const firstName = "John";
|
|
155
|
-
const lastName = "Chamling";
|
|
156
|
-
const emailAddress = "user@example.com";
|
|
157
|
-
const mobilePhone = "+91 012345678";
|
|
158
|
-
const language = "en-US";
|
|
159
|
-
const city = "Bharatpur";
|
|
160
|
-
const state = "Bagmati";
|
|
161
|
-
const postalCode = "44200";
|
|
162
|
-
const countryCode: CountryCode = "NPL";
|
|
163
|
-
const address1 = "Shittal street, Bharatpur - 10, Chitwan";
|
|
164
|
-
|
|
165
|
-
const recipient = Recipient.create(
|
|
166
|
-
participantId,
|
|
167
|
-
firstName,
|
|
168
|
-
lastName,
|
|
169
|
-
emailAddress,
|
|
170
|
-
mobilePhone,
|
|
171
|
-
language,
|
|
172
|
-
city,
|
|
173
|
-
state,
|
|
174
|
-
postalCode,
|
|
175
|
-
countryCode,
|
|
176
|
-
address1,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const amount = "150.55"; // Amount in USD
|
|
180
|
-
const quote = await service.fetchQuote(amount);
|
|
181
|
-
const [depositResponse, apiResponse] = await service.purchaseCard({
|
|
182
|
-
walletAddress: signer.address || "<wallet_address>",
|
|
183
|
-
amount,
|
|
184
|
-
recipient,
|
|
185
|
-
quote,
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
console.log(
|
|
189
|
-
`Deposit response: \n BlockHash: ${depositResponse.blockHash} \n TransactionHash: ${depositResponse.txHash}`,
|
|
190
|
-
);
|
|
191
|
-
console.log("Zebec Server Response:", apiResponse.data);
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
## Configuration Parameters
|
|
197
|
-
|
|
198
|
-
### ZebecCardService
|
|
199
|
-
|
|
200
|
-
To create an instance of `ZebecCardService`, you need:
|
|
201
|
-
|
|
202
|
-
- **signer**: An instance of `ethers.Signer`.
|
|
203
|
-
- **chainId**: The ID of the blockchain (see list of supported chains below).
|
|
204
|
-
- **apiConfig**: Object containing `apiKey` and `encryptionKey`.
|
|
205
|
-
- **sdkConfig (optional)**: SDK-specific settings, such as:
|
|
206
|
-
- `sandbox`: Boolean, set to `true` for testnets.
|
|
207
|
-
|
|
208
|
-
### ZebecCardTAOService
|
|
209
|
-
|
|
210
|
-
To create an instance of `ZebecCardTAOService`, you need:
|
|
211
|
-
|
|
212
|
-
- **signer**: An instance of `Keyring` or `Signer`.
|
|
213
|
-
- **apiConfig**: Object containing `apiKey` and `encryptionKey`.
|
|
214
|
-
- **sdkConfig (optional)**: SDK-specific settings, such as:
|
|
215
|
-
- `sandbox`: Boolean, set to `true` for testnets.
|
|
216
|
-
|
|
217
|
-
### EVM Supported Chains
|
|
218
|
-
|
|
219
|
-
| Chain | Chain ID |
|
|
220
|
-
| ------------------- | ------------------------------- |
|
|
221
|
-
| Ethereum | Mainnet (1), Sepolia (11155111) |
|
|
222
|
-
| Binance Smart Chain | Mainnet (56), Testnet (97) |
|
|
223
|
-
| Base | Mainnet (8453) |
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Recipient Fields
|
|
228
|
-
|
|
229
|
-
To create a valid `Recipient` instance, provide the following details:
|
|
230
|
-
|
|
231
|
-
- **participantId** (alphanumeric string): Unique identifier for the buyer end user. 1-20 chars.
|
|
232
|
-
- **firstName**, **lastName** (string): Participant's full name.
|
|
233
|
-
- **emailAddress** (string): Contact email. 1-80 chars
|
|
234
|
-
- **mobilePhone** (string): Mobile number with country code.
|
|
235
|
-
- **language** (string): Language code (e.g., `"en-US"`).
|
|
236
|
-
- **city**, **state**, **postalCode** (string): Location details.
|
|
237
|
-
- **countryCode** (CountryCode enum): ISO 3166-1 alpha-3 country code.
|
|
238
|
-
- **address1** (string): Street address. (max 50 chars)
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## Responses
|
|
243
|
-
|
|
244
|
-
The `purchaseCard` method returns three responses:
|
|
245
|
-
|
|
246
|
-
1. **depositResponse**: Transaction response for token deposit.
|
|
247
|
-
2. **buyCardResponse**: Transaction response for card purchase. (EVM only)
|
|
248
|
-
3. **apiResponse**: API response from Zebec's backend with additional transaction metadata.
|
|
249
|
-
|
|
250
|
-
---
|
|
251
|
-
|
|
252
|
-
## Environment Variables
|
|
253
|
-
|
|
254
|
-
- **API_KEY**: Your Zebec API Key.
|
|
255
|
-
- **ENCRYPTION_KEY**: Your Zebec encryption key for secure data handling.
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
## Supported Countries
|
|
260
|
-
|
|
261
|
-
| Country | Code |
|
|
262
|
-
| -------------------------------- | ---- |
|
|
263
|
-
| Algeria | DZA |
|
|
264
|
-
| Angola | AGO |
|
|
265
|
-
| Argentina | ARG |
|
|
266
|
-
| Australia | AUS |
|
|
267
|
-
| Austria | AUT |
|
|
268
|
-
| Belgium | BEL |
|
|
269
|
-
| Bolivia (Plurinational State of) | BOL |
|
|
270
|
-
| Brazil | BRA |
|
|
271
|
-
| Cameroon | CMR |
|
|
272
|
-
| Canada | CAN |
|
|
273
|
-
| Chile | CHL |
|
|
274
|
-
| Costa Rica | CRI |
|
|
275
|
-
| Cyprus | CYP |
|
|
276
|
-
| Czechia | CZE |
|
|
277
|
-
| Denmark | DNK |
|
|
278
|
-
| Ecuador | ECU |
|
|
279
|
-
| Egypt | EGY |
|
|
280
|
-
| El Salvador | SLV |
|
|
281
|
-
| Estonia | EST |
|
|
282
|
-
| Finland | FIN |
|
|
283
|
-
| France | FRA |
|
|
284
|
-
| Georgia | GEO |
|
|
285
|
-
| Germany | DEU |
|
|
286
|
-
| Ghana | GHA |
|
|
287
|
-
| Greece | GRC |
|
|
288
|
-
| Guatemala | GTM |
|
|
289
|
-
| Honduras | HND |
|
|
290
|
-
| Hungary | HUN |
|
|
291
|
-
| Iceland | ISL |
|
|
292
|
-
| Ireland | IRL |
|
|
293
|
-
| Italy | ITA |
|
|
294
|
-
| Jamaica | JAM |
|
|
295
|
-
| Japan | JPN |
|
|
296
|
-
| Jordan | JOR |
|
|
297
|
-
| Kenya | KEN |
|
|
298
|
-
| Korea, Republic of Korea | KOR |
|
|
299
|
-
| Kuwait | KWT |
|
|
300
|
-
| Lithuania | LTU |
|
|
301
|
-
| Luxembourg | LUX |
|
|
302
|
-
| Malawi | MWI |
|
|
303
|
-
| Malaysia | MYS |
|
|
304
|
-
| Malta | MLT |
|
|
305
|
-
| Mexico | MEX |
|
|
306
|
-
| Morocco | MAR |
|
|
307
|
-
| Mozambique | MOZ |
|
|
308
|
-
| Nepal | NPL |
|
|
309
|
-
| Netherlands | NLD |
|
|
310
|
-
| New Zealand | NZL |
|
|
311
|
-
| Nigeria | NGA |
|
|
312
|
-
| Norway | NOR |
|
|
313
|
-
| Oman | OMN |
|
|
314
|
-
| Pakistan | PAK |
|
|
315
|
-
| Papua New Guinea | PNG |
|
|
316
|
-
| Paraguay | PRY |
|
|
317
|
-
| Peru | PER |
|
|
318
|
-
| Philippines | PHL |
|
|
319
|
-
| Poland | POL |
|
|
320
|
-
| Portugal | PRT |
|
|
321
|
-
| Puerto Rico | PRI |
|
|
322
|
-
| Qatar | QAT |
|
|
323
|
-
| Romania | ROU |
|
|
324
|
-
| Saudi Arabia | SAU |
|
|
325
|
-
| Singapore | SGP |
|
|
326
|
-
| Slovakia | SVK |
|
|
327
|
-
| Slovenia | SVN |
|
|
328
|
-
| Spain | ESP |
|
|
329
|
-
| Sweden | SWE |
|
|
330
|
-
| Taiwan | TWN |
|
|
331
|
-
| Thailand | THA |
|
|
332
|
-
| Trinidad and Tobago | TTO |
|
|
333
|
-
| Tunisia | TUN |
|
|
334
|
-
| Turkey | TUR |
|
|
335
|
-
| United Kingdom | GBR |
|
|
336
|
-
| United States | USA |
|
|
337
|
-
| Uruguay | URY |
|
|
338
|
-
| Vanuatu | VUT |
|
|
339
|
-
| Zambia | ZMB |
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/exchange-card-sdk",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.3",
|
|
4
4
|
"description": "An sdk for purchasing silver card in zebec",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,11 +37,11 @@
|
|
|
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",
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
}
|