@vleap/warps-adapter-fastset 0.1.0-alpha.17 → 0.1.0-alpha.19
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +146 -124
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable,
|
|
1
|
+
import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, 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>;
|
|
@@ -327,7 +328,6 @@ declare class WarpFastsetExecutor implements AdapterWarpExecutor {
|
|
|
327
328
|
createTransferTransaction(executable: WarpExecutable): Promise<any>;
|
|
328
329
|
createContractCallTransaction(executable: WarpExecutable): Promise<any>;
|
|
329
330
|
executeQuery(executable: WarpExecutable): Promise<any>;
|
|
330
|
-
preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
|
|
331
331
|
signMessage(message: string, privateKey: string): Promise<string>;
|
|
332
332
|
executeTransfer(executable: WarpExecutable): Promise<any>;
|
|
333
333
|
executeTransferWithKey(executable: WarpExecutable, privateKey: string): Promise<any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable,
|
|
1
|
+
import { WarpChainAsset, AdapterFactory, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, AdapterWarpExplorer, AdapterWarpResults, Warp, WarpExecution, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, 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>;
|
|
@@ -327,7 +328,6 @@ declare class WarpFastsetExecutor implements AdapterWarpExecutor {
|
|
|
327
328
|
createTransferTransaction(executable: WarpExecutable): Promise<any>;
|
|
328
329
|
createContractCallTransaction(executable: WarpExecutable): Promise<any>;
|
|
329
330
|
executeQuery(executable: WarpExecutable): Promise<any>;
|
|
330
|
-
preprocessInput(chain: WarpChainInfo, input: string, type: WarpActionInputType, value: string): Promise<string>;
|
|
331
331
|
signMessage(message: string, privateKey: string): Promise<string>;
|
|
332
332
|
executeTransfer(executable: WarpExecutable): Promise<any>;
|
|
333
333
|
executeTransferWithKey(executable: WarpExecutable, privateKey: string): Promise<any>;
|
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 = "
|
|
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
|
-
|
|
280
|
+
// Generic error handling wrapper for RPC calls
|
|
281
|
+
async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
|
|
281
282
|
try {
|
|
282
|
-
const
|
|
283
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
amount
|
|
321
|
-
|
|
322
|
-
|
|
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.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
nonce
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
sender:
|
|
378
|
-
nonce
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
transaction
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
482
|
+
console.error(`Fastset RPC request failed for method ${method}:`, error);
|
|
454
483
|
throw error;
|
|
455
484
|
}
|
|
456
485
|
}
|
|
@@ -490,14 +519,7 @@ var WarpFastsetDataLoader = class {
|
|
|
490
519
|
const [account, assetBalances] = await Promise.all([accountReq, assetBalancesReq]);
|
|
491
520
|
const assets = [];
|
|
492
521
|
if (account.balance > 0) {
|
|
493
|
-
assets.push({
|
|
494
|
-
chain: this.chain.name,
|
|
495
|
-
identifier: this.chain.nativeToken?.identifier || "SET",
|
|
496
|
-
name: this.chain.nativeToken?.name || "SET",
|
|
497
|
-
decimals: this.chain.nativeToken?.decimals || 6,
|
|
498
|
-
amount: account.balance,
|
|
499
|
-
logoUrl: this.chain.nativeToken?.logoUrl
|
|
500
|
-
});
|
|
522
|
+
assets.push({ ...this.chain.nativeToken, amount: account.balance });
|
|
501
523
|
}
|
|
502
524
|
if (assetBalances) {
|
|
503
525
|
for (const [assetId, assetBalance] of Object.entries(assetBalances)) {
|
|
@@ -507,10 +529,11 @@ var WarpFastsetDataLoader = class {
|
|
|
507
529
|
assets.push({
|
|
508
530
|
chain: this.chain.name,
|
|
509
531
|
identifier: assetId,
|
|
532
|
+
symbol: "TODO: SYMBOL",
|
|
510
533
|
name: assetBalance.name || assetId,
|
|
511
534
|
decimals: assetBalance.decimals || 6,
|
|
512
|
-
|
|
513
|
-
|
|
535
|
+
logoUrl: assetBalance.logo_url,
|
|
536
|
+
amount
|
|
514
537
|
});
|
|
515
538
|
}
|
|
516
539
|
}
|
|
@@ -584,10 +607,11 @@ var WarpFastsetDataLoader = class {
|
|
|
584
607
|
return {
|
|
585
608
|
chain: this.chain.name,
|
|
586
609
|
identifier: assetId,
|
|
610
|
+
symbol: "TODO: SYMBOL",
|
|
587
611
|
name: assetBalance.name || assetId,
|
|
588
612
|
decimals: assetBalance.decimals || 6,
|
|
589
|
-
|
|
590
|
-
|
|
613
|
+
logoUrl: assetBalance.logo_url,
|
|
614
|
+
amount
|
|
591
615
|
};
|
|
592
616
|
}
|
|
593
617
|
};
|
|
@@ -808,9 +832,6 @@ var WarpFastsetExecutor = class {
|
|
|
808
832
|
};
|
|
809
833
|
}
|
|
810
834
|
}
|
|
811
|
-
async preprocessInput(chain, input, type, value) {
|
|
812
|
-
return value;
|
|
813
|
-
}
|
|
814
835
|
async signMessage(message, privateKey) {
|
|
815
836
|
throw new Error("Not implemented");
|
|
816
837
|
}
|
|
@@ -1000,6 +1021,7 @@ var NativeTokenSet = {
|
|
|
1000
1021
|
chain: import_warps4.WarpChainName.Fastset,
|
|
1001
1022
|
identifier: "SET",
|
|
1002
1023
|
name: "SET",
|
|
1024
|
+
symbol: "SET",
|
|
1003
1025
|
decimals: 6,
|
|
1004
1026
|
logoUrl: "https://vleap.ai/images/tokens/set.svg"
|
|
1005
1027
|
};
|