@vleap/warps-adapter-fastset 0.1.0-alpha.16 → 0.1.0-alpha.18

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpDataLoaderOptions, WarpChainAction, AdapterWarpExecutor, WarpExecutable, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
1
+ import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
2
2
  import * as _mysten_bcs from '@mysten/bcs';
3
3
 
4
4
  declare const WarpFastsetConstants: {};
@@ -224,6 +224,7 @@ interface FastsetClientConfig {
224
224
  declare class FastsetClient {
225
225
  private config;
226
226
  constructor(config?: FastsetClientConfig);
227
+ private handleRpcCall;
227
228
  getAccountInfo(address: string): Promise<FastsetAccountInfo | null>;
228
229
  getNextNonce(senderAddress: string): Promise<number>;
229
230
  getAssetBalance(accountId: string, assetId: string): Promise<FastsetAssetBalance | null>;
@@ -304,6 +305,8 @@ declare class WarpFastsetDataLoader implements AdapterWarpDataLoader {
304
305
  constructor(config: WarpClientConfig, chain: WarpChainInfo);
305
306
  getAccount(address: string): Promise<WarpChainAccount>;
306
307
  getAccountAssets(address: string): Promise<WarpChainAsset[]>;
308
+ getAsset(identifier: string): Promise<WarpChainAsset | null>;
309
+ getAction(identifier: string, awaitCompleted?: boolean): Promise<WarpChainAction | null>;
307
310
  getAccountActions(address: string, options?: WarpDataLoaderOptions): Promise<WarpChainAction[]>;
308
311
  getAccountInfo(address: string): Promise<FastsetAccountData | null>;
309
312
  getTransactionInfo(txHash: string): Promise<FastsetTransactionData | null>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpDataLoaderOptions, WarpChainAction, AdapterWarpExecutor, WarpExecutable, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
1
+ import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
2
2
  import * as _mysten_bcs from '@mysten/bcs';
3
3
 
4
4
  declare const WarpFastsetConstants: {};
@@ -224,6 +224,7 @@ interface FastsetClientConfig {
224
224
  declare class FastsetClient {
225
225
  private config;
226
226
  constructor(config?: FastsetClientConfig);
227
+ private handleRpcCall;
227
228
  getAccountInfo(address: string): Promise<FastsetAccountInfo | null>;
228
229
  getNextNonce(senderAddress: string): Promise<number>;
229
230
  getAssetBalance(accountId: string, assetId: string): Promise<FastsetAssetBalance | null>;
@@ -304,6 +305,8 @@ declare class WarpFastsetDataLoader implements AdapterWarpDataLoader {
304
305
  constructor(config: WarpClientConfig, chain: WarpChainInfo);
305
306
  getAccount(address: string): Promise<WarpChainAccount>;
306
307
  getAccountAssets(address: string): Promise<WarpChainAsset[]>;
308
+ getAsset(identifier: string): Promise<WarpChainAsset | null>;
309
+ getAction(identifier: string, awaitCompleted?: boolean): Promise<WarpChainAction | null>;
307
310
  getAccountActions(address: string, options?: WarpDataLoaderOptions): Promise<WarpChainAction[]>;
308
311
  getAccountInfo(address: string): Promise<FastsetAccountData | null>;
309
312
  getTransactionInfo(txHash: string): Promise<FastsetTransactionData | null>;
package/dist/index.js CHANGED
@@ -268,7 +268,7 @@ var Wallet = class _Wallet {
268
268
  BigInt.prototype.toJSON = function() {
269
269
  return Number(this);
270
270
  };
271
- var FASTSET_VALIDATOR_URL = "http://157.90.201.117:8765";
271
+ var FASTSET_VALIDATOR_URL = "https://rpc.fastset.xyz";
272
272
  var FASTSET_PROXY_URL = "http://136.243.61.168:44444";
273
273
  var FastsetClient = class {
274
274
  constructor(config) {
@@ -277,56 +277,55 @@ var FastsetClient = class {
277
277
  proxyUrl: FASTSET_PROXY_URL
278
278
  };
279
279
  }
280
- async getAccountInfo(address) {
280
+ // Generic error handling wrapper for RPC calls
281
+ async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
281
282
  try {
282
- const addressBytes = Wallet.decodeBech32Address(address);
283
- const response = await this.requestValidator("set_getAccountInfo", {
284
- address: Array.from(addressBytes)
285
- });
283
+ const response = useProxy ? await this.requestProxy(method, params) : await this.requestValidator(method, params);
284
+ console.log(`RPC call to ${method} successful:`, response.result);
286
285
  return response.result;
287
286
  } catch (error) {
287
+ console.error(`${errorMessage}:`, error);
288
+ if (!allowNull) throw error;
288
289
  return null;
289
290
  }
290
291
  }
292
+ async getAccountInfo(address) {
293
+ const addressBytes = Wallet.decodeBech32Address(address);
294
+ return this.handleRpcCall("set_getAccountInfo", [Array.from(addressBytes)], `Failed to get account info for address ${address}`);
295
+ }
291
296
  async getNextNonce(senderAddress) {
292
297
  const accountInfo = await this.getAccountInfo(senderAddress);
293
298
  return accountInfo?.next_nonce ?? 0;
294
299
  }
295
300
  async getAssetBalance(accountId, assetId) {
296
- try {
297
- const response = await this.requestValidator("vsl_getAssetBalance", {
298
- account_id: accountId,
299
- assert_id: assetId
300
- });
301
- return response.result;
302
- } catch (error) {
303
- return null;
304
- }
301
+ return this.handleRpcCall(
302
+ "vsl_getAssetBalance",
303
+ [accountId, assetId],
304
+ `Failed to get asset balance for account ${accountId}, asset ${assetId}`
305
+ );
305
306
  }
306
307
  async getAssetBalances(accountId) {
307
- try {
308
- const response = await this.requestValidator("vsl_getAssetBalances", {
309
- account_id: accountId
310
- });
311
- return response.result;
312
- } catch (error) {
313
- return null;
314
- }
308
+ return this.handleRpcCall("vsl_getAssetBalances", [accountId], `Failed to get asset balances for account ${accountId}`);
315
309
  }
316
310
  async fundFromFaucet(recipientAddress, amount) {
317
311
  const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
318
- const response = await this.requestProxy("faucetDrip", {
319
- recipient: Array.from(recipientBytes),
320
- amount
321
- });
322
- return response.result;
312
+ return this.handleRpcCall(
313
+ "faucetDrip",
314
+ [Array.from(recipientBytes), amount],
315
+ `Failed to fund from faucet for address ${recipientAddress}`,
316
+ true,
317
+ false
318
+ );
323
319
  }
324
320
  async submitTransaction(request) {
325
- const response = await this.requestValidator("set_submitTransaction", {
326
- transaction: request.transaction,
327
- signature: Array.from(request.signature)
328
- });
329
- const result = response.result;
321
+ const response = await this.handleRpcCall(
322
+ "set_submitTransaction",
323
+ [request.transaction, Array.from(request.signature)],
324
+ "Failed to submit transaction",
325
+ false,
326
+ false
327
+ );
328
+ const result = response;
330
329
  return {
331
330
  transaction_hash: new Uint8Array(result.transaction_hash),
332
331
  validator: new Uint8Array(result.validator),
@@ -334,93 +333,105 @@ var FastsetClient = class {
334
333
  };
335
334
  }
336
335
  async submitCertificate(request) {
337
- await this.requestValidator("set_submitTransactionCertificate", {
338
- transaction: request.transaction,
339
- signature: Array.from(request.signature),
340
- validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
341
- });
336
+ await this.handleRpcCall(
337
+ "set_submitTransactionCertificate",
338
+ [
339
+ request.transaction,
340
+ Array.from(request.signature),
341
+ request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
342
+ ],
343
+ "Failed to submit certificate",
344
+ false,
345
+ false
346
+ );
342
347
  }
343
348
  async executeTransfer(senderPrivateKey, recipient, amount, userData) {
344
- const senderPublicKey = await (0, import_ed255192.getPublicKey)(senderPrivateKey);
345
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
346
- const nonce = await this.getNextNonce(senderAddress);
347
- const recipientBytes = Wallet.decodeBech32Address(recipient);
348
- const transaction = {
349
- sender: senderPublicKey,
350
- nonce,
351
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
352
- claim: {
353
- Transfer: {
354
- recipient: { FastSet: recipientBytes },
355
- amount,
356
- user_data: userData ?? null
349
+ try {
350
+ console.log(`Executing transfer from sender to ${recipient} for amount ${amount}`);
351
+ const senderPublicKey = (0, import_ed255192.getPublicKey)(senderPrivateKey);
352
+ const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
353
+ console.log(`Sender address: ${senderAddress}`);
354
+ const nonce = await this.getNextNonce(senderAddress);
355
+ console.log(`Using nonce: ${nonce}`);
356
+ const recipientBytes = Wallet.decodeBech32Address(recipient);
357
+ console.log(`Recipient decoded successfully`);
358
+ const transaction = {
359
+ sender: senderPublicKey,
360
+ nonce,
361
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
362
+ claim: {
363
+ Transfer: {
364
+ recipient: { FastSet: recipientBytes },
365
+ amount,
366
+ user_data: userData ?? null
367
+ }
357
368
  }
358
- }
359
- };
360
- const signature = await this.signTransaction(transaction, senderPrivateKey);
361
- const submitResponse = await this.submitTransaction({
362
- transaction,
363
- signature
364
- });
365
- await this.submitCertificate({
366
- transaction,
367
- signature,
368
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
369
- });
370
- return submitResponse.transaction_hash;
369
+ };
370
+ console.log("Signing transaction...");
371
+ const signature = await this.signTransaction(transaction, senderPrivateKey);
372
+ console.log("Submitting transaction...");
373
+ const submitResponse = await this.submitTransaction({
374
+ transaction,
375
+ signature
376
+ });
377
+ console.log("Submitting certificate...");
378
+ await this.submitCertificate({
379
+ transaction,
380
+ signature,
381
+ validator_signatures: [[submitResponse.validator, submitResponse.signature]]
382
+ });
383
+ console.log(`Transfer executed successfully. Transaction hash: ${submitResponse.transaction_hash}`);
384
+ return submitResponse.transaction_hash;
385
+ } catch (error) {
386
+ console.error(`Failed to execute transfer to ${recipient}:`, error);
387
+ throw error;
388
+ }
371
389
  }
372
390
  async submitClaim(senderPrivateKey, claim) {
373
- const senderPublicKey = await (0, import_ed255192.getPublicKey)(senderPrivateKey);
374
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
375
- const nonce = await this.getNextNonce(senderAddress);
376
- const transaction = {
377
- sender: senderPublicKey,
378
- nonce,
379
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
380
- claim
381
- };
382
- const signature = await this.signTransaction(transaction, senderPrivateKey);
383
- const submitResponse = await this.submitTransaction({
384
- transaction,
385
- signature
386
- });
387
- await this.submitCertificate({
388
- transaction,
389
- signature,
390
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
391
- });
392
- return submitResponse.transaction_hash;
391
+ try {
392
+ console.log("Submitting claim...");
393
+ const senderPublicKey = await (0, import_ed255192.getPublicKey)(senderPrivateKey);
394
+ const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
395
+ console.log(`Claim sender address: ${senderAddress}`);
396
+ const nonce = await this.getNextNonce(senderAddress);
397
+ console.log(`Using nonce: ${nonce}`);
398
+ const transaction = {
399
+ sender: senderPublicKey,
400
+ nonce,
401
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
402
+ claim
403
+ };
404
+ console.log("Signing claim transaction...");
405
+ const signature = await this.signTransaction(transaction, senderPrivateKey);
406
+ console.log("Submitting claim transaction...");
407
+ const submitResponse = await this.submitTransaction({
408
+ transaction,
409
+ signature
410
+ });
411
+ console.log("Submitting claim certificate...");
412
+ await this.submitCertificate({
413
+ transaction,
414
+ signature,
415
+ validator_signatures: [[submitResponse.validator, submitResponse.signature]]
416
+ });
417
+ console.log(`Claim submitted successfully. Transaction hash: ${submitResponse.transaction_hash}`);
418
+ return submitResponse.transaction_hash;
419
+ } catch (error) {
420
+ console.error("Failed to submit claim:", error);
421
+ throw error;
422
+ }
393
423
  }
394
424
  async signTransaction(transaction, privateKey) {
395
425
  return await TransactionSigner.signTransaction(transaction, privateKey);
396
426
  }
397
427
  async getTransactionStatus(txHash) {
398
- try {
399
- const response = await this.requestValidator("set_getTransactionStatus", {
400
- hash: txHash
401
- });
402
- return response.result;
403
- } catch (error) {
404
- return null;
405
- }
428
+ return this.handleRpcCall("set_getTransactionStatus", [txHash], `Failed to get transaction status for hash ${txHash}`);
406
429
  }
407
430
  async getTransactionInfo(txHash) {
408
- try {
409
- const response = await this.requestValidator("set_getTransactionInfo", {
410
- hash: txHash
411
- });
412
- return response.result;
413
- } catch (error) {
414
- return null;
415
- }
431
+ return this.handleRpcCall("set_getTransactionInfo", [txHash], `Failed to get transaction info for hash ${txHash}`);
416
432
  }
417
433
  async getNetworkInfo() {
418
- try {
419
- const response = await this.requestValidator("set_getNetworkInfo", {});
420
- return response.result;
421
- } catch (error) {
422
- return null;
423
- }
434
+ return this.handleRpcCall("set_getNetworkInfo", [], "Failed to get network info");
424
435
  }
425
436
  async requestValidator(method, params) {
426
437
  return this.request(this.config.validatorUrl, method, params);
@@ -430,27 +441,45 @@ var FastsetClient = class {
430
441
  }
431
442
  async request(url, method, params) {
432
443
  try {
444
+ if (params !== null && params !== void 0) {
445
+ if (Array.isArray(params)) {
446
+ for (let i = 0; i < params.length; i++) {
447
+ if (params[i] === void 0) {
448
+ throw new Error(`Parameter at index ${i} is undefined`);
449
+ }
450
+ }
451
+ } else if (typeof params === "object") {
452
+ const paramObj = params;
453
+ for (const [key, value] of Object.entries(paramObj)) {
454
+ if (value === void 0) {
455
+ throw new Error(`Parameter '${key}' is undefined`);
456
+ }
457
+ }
458
+ }
459
+ }
433
460
  const request = {
434
461
  jsonrpc: "2.0",
435
462
  id: 1,
436
463
  method,
437
464
  params
438
465
  };
466
+ console.log(`Making RPC request to ${method} with params:`, params);
439
467
  const response = await fetch(url, {
440
468
  method: "POST",
441
469
  headers: { "Content-Type": "application/json" },
442
470
  body: JSON.stringify(request, this.jsonReplacer)
443
471
  });
444
472
  if (!response.ok) {
445
- throw new Error(`HTTP request failed: ${response.statusText}`);
473
+ throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`);
446
474
  }
447
475
  const jsonResponse = await response.json();
448
476
  if (jsonResponse.error) {
449
- throw new Error(`RPC error: ${jsonResponse.error.message}`);
477
+ throw new Error(`RPC error: ${jsonResponse.error.message} (code: ${jsonResponse.error.code})`);
450
478
  }
479
+ console.log(`RPC request to ${method} successful:`, jsonResponse.result);
451
480
  return jsonResponse;
452
481
  } catch (error) {
453
- console.error(`Fastset RPC request failed: ${error}`);
482
+ console.error(`Fastset RPC request failed for method ${method}:`, error);
454
483
  throw error;
455
484
  }
456
485
  }
@@ -518,6 +547,12 @@ var WarpFastsetDataLoader = class {
518
547
  }
519
548
  return assets;
520
549
  }
550
+ async getAsset(identifier) {
551
+ return null;
552
+ }
553
+ async getAction(identifier, awaitCompleted = false) {
554
+ return null;
555
+ }
521
556
  async getAccountActions(address, options) {
522
557
  return [];
523
558
  }