@vleap/warps-adapter-fastset 0.1.0-alpha.15 → 0.1.0-alpha.17

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/dist/index.mjs CHANGED
@@ -211,9 +211,14 @@ var Wallet = class _Wallet {
211
211
  BigInt.prototype.toJSON = function() {
212
212
  return Number(this);
213
213
  };
214
+ var FASTSET_VALIDATOR_URL = "http://157.90.201.117:8765";
215
+ var FASTSET_PROXY_URL = "http://136.243.61.168:44444";
214
216
  var FastsetClient = class {
215
217
  constructor(config) {
216
- this.config = config;
218
+ this.config = config || {
219
+ validatorUrl: FASTSET_VALIDATOR_URL,
220
+ proxyUrl: FASTSET_PROXY_URL
221
+ };
217
222
  }
218
223
  async getAccountInfo(address) {
219
224
  try {
@@ -221,9 +226,6 @@ var FastsetClient = class {
221
226
  const response = await this.requestValidator("set_getAccountInfo", {
222
227
  address: Array.from(addressBytes)
223
228
  });
224
- if (response.error) {
225
- return null;
226
- }
227
229
  return response.result;
228
230
  } catch (error) {
229
231
  return null;
@@ -233,15 +235,33 @@ var FastsetClient = class {
233
235
  const accountInfo = await this.getAccountInfo(senderAddress);
234
236
  return accountInfo?.next_nonce ?? 0;
235
237
  }
238
+ async getAssetBalance(accountId, assetId) {
239
+ try {
240
+ const response = await this.requestValidator("vsl_getAssetBalance", {
241
+ account_id: accountId,
242
+ assert_id: assetId
243
+ });
244
+ return response.result;
245
+ } catch (error) {
246
+ return null;
247
+ }
248
+ }
249
+ async getAssetBalances(accountId) {
250
+ try {
251
+ const response = await this.requestValidator("vsl_getAssetBalances", {
252
+ account_id: accountId
253
+ });
254
+ return response.result;
255
+ } catch (error) {
256
+ return null;
257
+ }
258
+ }
236
259
  async fundFromFaucet(recipientAddress, amount) {
237
260
  const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
238
261
  const response = await this.requestProxy("faucetDrip", {
239
262
  recipient: Array.from(recipientBytes),
240
263
  amount
241
264
  });
242
- if (response.error) {
243
- throw new Error(`Faucet request failed: ${response.error.message}`);
244
- }
245
265
  return response.result;
246
266
  }
247
267
  async submitTransaction(request) {
@@ -249,9 +269,6 @@ var FastsetClient = class {
249
269
  transaction: request.transaction,
250
270
  signature: Array.from(request.signature)
251
271
  });
252
- if (response.error) {
253
- throw new Error(`Transaction submission failed: ${response.error.message}`);
254
- }
255
272
  const result = response.result;
256
273
  return {
257
274
  transaction_hash: new Uint8Array(result.transaction_hash),
@@ -260,14 +277,11 @@ var FastsetClient = class {
260
277
  };
261
278
  }
262
279
  async submitCertificate(request) {
263
- const response = await this.requestValidator("set_submitTransactionCertificate", {
280
+ await this.requestValidator("set_submitTransactionCertificate", {
264
281
  transaction: request.transaction,
265
282
  signature: Array.from(request.signature),
266
283
  validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
267
284
  });
268
- if (response.error) {
269
- throw new Error(`Certificate submission failed: ${response.error.message}`);
270
- }
271
285
  }
272
286
  async executeTransfer(senderPrivateKey, recipient, amount, userData) {
273
287
  const senderPublicKey = await getPublicKey(senderPrivateKey);
@@ -328,9 +342,6 @@ var FastsetClient = class {
328
342
  const response = await this.requestValidator("set_getTransactionStatus", {
329
343
  hash: txHash
330
344
  });
331
- if (response.error) {
332
- return null;
333
- }
334
345
  return response.result;
335
346
  } catch (error) {
336
347
  return null;
@@ -341,9 +352,6 @@ var FastsetClient = class {
341
352
  const response = await this.requestValidator("set_getTransactionInfo", {
342
353
  hash: txHash
343
354
  });
344
- if (response.error) {
345
- return null;
346
- }
347
355
  return response.result;
348
356
  } catch (error) {
349
357
  return null;
@@ -352,9 +360,6 @@ var FastsetClient = class {
352
360
  async getNetworkInfo() {
353
361
  try {
354
362
  const response = await this.requestValidator("set_getNetworkInfo", {});
355
- if (response.error) {
356
- return null;
357
- }
358
363
  return response.result;
359
364
  } catch (error) {
360
365
  return null;
@@ -367,21 +372,30 @@ var FastsetClient = class {
367
372
  return this.request(this.config.proxyUrl, method, params);
368
373
  }
369
374
  async request(url, method, params) {
370
- const request = {
371
- jsonrpc: "2.0",
372
- id: 1,
373
- method,
374
- params
375
- };
376
- const response = await fetch(url, {
377
- method: "POST",
378
- headers: { "Content-Type": "application/json" },
379
- body: JSON.stringify(request, this.jsonReplacer)
380
- });
381
- if (!response.ok) {
382
- throw new Error(`HTTP request failed: ${response.statusText}`);
375
+ try {
376
+ const request = {
377
+ jsonrpc: "2.0",
378
+ id: 1,
379
+ method,
380
+ params
381
+ };
382
+ const response = await fetch(url, {
383
+ method: "POST",
384
+ headers: { "Content-Type": "application/json" },
385
+ body: JSON.stringify(request, this.jsonReplacer)
386
+ });
387
+ if (!response.ok) {
388
+ throw new Error(`HTTP request failed: ${response.statusText}`);
389
+ }
390
+ const jsonResponse = await response.json();
391
+ if (jsonResponse.error) {
392
+ throw new Error(`RPC error: ${jsonResponse.error.message}`);
393
+ }
394
+ return jsonResponse;
395
+ } catch (error) {
396
+ console.error(`Fastset RPC request failed: ${error}`);
397
+ throw error;
383
398
  }
384
- return response.json();
385
399
  }
386
400
  jsonReplacer(key, value) {
387
401
  if (value instanceof Uint8Array) {
@@ -396,108 +410,100 @@ var WarpFastsetDataLoader = class {
396
410
  constructor(config, chain) {
397
411
  this.config = config;
398
412
  this.chain = chain;
399
- const validatorUrl = this.chain.defaultApiUrl;
400
- const proxyUrl = this.chain.defaultApiUrl;
401
- this.client = new FastsetClient({
402
- validatorUrl,
403
- proxyUrl
404
- });
413
+ this.client = new FastsetClient();
405
414
  }
406
415
  async getAccount(address) {
407
- try {
408
- const accountInfo = await this.client.getAccountInfo(address);
409
- if (!accountInfo) {
410
- return {
411
- chain: this.chain.name,
412
- address,
413
- balance: BigInt(0)
414
- };
415
- }
416
- return {
417
- chain: this.chain.name,
418
- address,
419
- balance: BigInt(parseInt(accountInfo.balance, 16))
420
- };
421
- } catch (error) {
416
+ const accountInfo = await this.client.getAccountInfo(address);
417
+ if (!accountInfo) {
422
418
  return {
423
419
  chain: this.chain.name,
424
420
  address,
425
421
  balance: BigInt(0)
426
422
  };
427
423
  }
424
+ return {
425
+ chain: this.chain.name,
426
+ address,
427
+ balance: BigInt(parseInt(accountInfo.balance, 16))
428
+ };
428
429
  }
429
430
  async getAccountAssets(address) {
430
- try {
431
- const account = await this.getAccount(address);
432
- if (account.balance > 0) {
433
- return [
434
- {
435
- chain: this.chain.name,
436
- identifier: this.chain.nativeToken?.identifier || "SET",
437
- name: this.chain.nativeToken?.name || "SET",
438
- decimals: this.chain.nativeToken?.decimals || 6,
439
- amount: account.balance,
440
- logoUrl: this.chain.nativeToken?.logoUrl
431
+ const accountReq = this.getAccount(address);
432
+ const assetBalancesReq = this.client.getAssetBalances(address);
433
+ const [account, assetBalances] = await Promise.all([accountReq, assetBalancesReq]);
434
+ const assets = [];
435
+ if (account.balance > 0) {
436
+ assets.push({
437
+ chain: this.chain.name,
438
+ identifier: this.chain.nativeToken?.identifier || "SET",
439
+ name: this.chain.nativeToken?.name || "SET",
440
+ decimals: this.chain.nativeToken?.decimals || 6,
441
+ amount: account.balance,
442
+ logoUrl: this.chain.nativeToken?.logoUrl
443
+ });
444
+ }
445
+ if (assetBalances) {
446
+ for (const [assetId, assetBalance] of Object.entries(assetBalances)) {
447
+ if (assetBalance.balance) {
448
+ const amount = BigInt(assetBalance.balance);
449
+ if (amount > 0) {
450
+ assets.push({
451
+ chain: this.chain.name,
452
+ identifier: assetId,
453
+ name: assetBalance.name || assetId,
454
+ decimals: assetBalance.decimals || 6,
455
+ amount,
456
+ logoUrl: assetBalance.logo_url
457
+ });
441
458
  }
442
- ];
459
+ }
443
460
  }
444
- return [];
445
- } catch (error) {
446
- return [];
447
461
  }
462
+ return assets;
463
+ }
464
+ async getAsset(identifier) {
465
+ return null;
466
+ }
467
+ async getAction(identifier, awaitCompleted = false) {
468
+ return null;
448
469
  }
449
470
  async getAccountActions(address, options) {
450
471
  return [];
451
472
  }
452
473
  async getAccountInfo(address) {
453
- try {
454
- const accountInfo = await this.client.getAccountInfo(address);
455
- if (!accountInfo) {
456
- return null;
457
- }
458
- const balanceDecimal = parseInt(accountInfo.balance, 16);
459
- return {
460
- address,
461
- balance: accountInfo.balance,
462
- balanceDecimal,
463
- nextNonce: accountInfo.next_nonce,
464
- sequenceNumber: accountInfo.sequence_number
465
- };
466
- } catch (error) {
467
- console.error("Error getting account info:", error);
474
+ const accountInfo = await this.client.getAccountInfo(address);
475
+ if (!accountInfo) {
468
476
  return null;
469
477
  }
478
+ const balanceDecimal = parseInt(accountInfo.balance, 16);
479
+ return {
480
+ address,
481
+ balance: accountInfo.balance,
482
+ balanceDecimal,
483
+ nextNonce: accountInfo.next_nonce,
484
+ sequenceNumber: accountInfo.sequence_number
485
+ };
470
486
  }
471
487
  async getTransactionInfo(txHash) {
472
- try {
473
- return {
488
+ return {
489
+ hash: txHash,
490
+ hashHex: txHash.startsWith("0x") ? txHash.slice(2) : txHash,
491
+ status: "submitted",
492
+ details: {
474
493
  hash: txHash,
475
- hashHex: txHash.startsWith("0x") ? txHash.slice(2) : txHash,
476
- status: "submitted",
477
- details: {
478
- hash: txHash,
479
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
480
- }
481
- };
482
- } catch (error) {
483
- console.error("Error getting transaction info:", error);
484
- return null;
485
- }
494
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
495
+ }
496
+ };
486
497
  }
487
498
  async checkTransferStatus(fromAddress, toAddress, amount) {
488
- try {
489
- const fromAccount = await this.getAccountInfo(fromAddress);
490
- const toAccount = await this.getAccountInfo(toAddress);
491
- if (!fromAccount || !toAccount) {
492
- return false;
493
- }
494
- const transferAmount = parseInt(amount);
495
- const fromBalance = fromAccount.balanceDecimal;
496
- return fromBalance < transferAmount;
497
- } catch (error) {
498
- console.error("Error checking transfer status:", error);
499
+ const fromAccount = await this.getAccountInfo(fromAddress);
500
+ const toAccount = await this.getAccountInfo(toAddress);
501
+ if (!fromAccount || !toAccount) {
499
502
  return false;
500
503
  }
504
+ const transferAmount = parseInt(amount);
505
+ const fromBalance = fromAccount.balanceDecimal;
506
+ return fromBalance < transferAmount;
501
507
  }
502
508
  async getAccountBalance(address) {
503
509
  const accountInfo = await this.getAccountInfo(address);
@@ -509,6 +515,24 @@ var WarpFastsetDataLoader = class {
509
515
  balanceDecimal: accountInfo.balanceDecimal
510
516
  };
511
517
  }
518
+ async getAssetBalance(address, assetId) {
519
+ const assetBalance = await this.client.getAssetBalance(address, assetId);
520
+ if (!assetBalance || !assetBalance.balance) {
521
+ return null;
522
+ }
523
+ const amount = BigInt(assetBalance.balance);
524
+ if (amount === 0n) {
525
+ return null;
526
+ }
527
+ return {
528
+ chain: this.chain.name,
529
+ identifier: assetId,
530
+ name: assetBalance.name || assetId,
531
+ decimals: assetBalance.decimals || 6,
532
+ amount,
533
+ logoUrl: assetBalance.logo_url
534
+ };
535
+ }
512
536
  };
513
537
 
514
538
  // src/WarpFastsetExecutor.ts