@vleap/warps-adapter-fastset 0.1.0-alpha.2 → 0.1.0-alpha.4
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.mts +174 -23
- package/dist/index.d.ts +174 -23
- package/dist/index.js +380 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +359 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -20,20 +20,38 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
Address: () => Address,
|
|
24
|
+
Amount: () => Amount,
|
|
25
|
+
Bytes32: () => Bytes32,
|
|
26
|
+
ClaimType: () => ClaimType,
|
|
27
|
+
FastsetClient: () => FastsetClient,
|
|
28
|
+
Nonce: () => Nonce,
|
|
29
|
+
PublicKey: () => PublicKey,
|
|
30
|
+
Transaction: () => Transaction,
|
|
31
|
+
Transfer: () => Transfer,
|
|
32
|
+
UserData: () => UserData,
|
|
23
33
|
WarpFastsetBuilder: () => WarpFastsetBuilder,
|
|
24
34
|
WarpFastsetConstants: () => WarpFastsetConstants,
|
|
25
35
|
WarpFastsetExecutor: () => WarpFastsetExecutor,
|
|
26
36
|
WarpFastsetExplorer: () => WarpFastsetExplorer,
|
|
27
37
|
WarpFastsetResults: () => WarpFastsetResults,
|
|
28
38
|
WarpFastsetSerializer: () => WarpFastsetSerializer,
|
|
29
|
-
|
|
39
|
+
decimalToHex: () => decimalToHex,
|
|
40
|
+
fromBase64: () => fromBase64,
|
|
41
|
+
getFastsetAdapter: () => getFastsetAdapter,
|
|
42
|
+
hexToDecimal: () => hexToDecimal2,
|
|
43
|
+
isValidFastsetAddress: () => isValidFastsetAddress,
|
|
44
|
+
normalizeAmount: () => normalizeAmount,
|
|
45
|
+
toBase64String: () => toBase64String,
|
|
46
|
+
toHexString: () => toHexString,
|
|
47
|
+
validateAmount: () => validateAmount,
|
|
48
|
+
validatePrivateKey: () => validatePrivateKey,
|
|
49
|
+
validatePublicKey: () => validatePublicKey
|
|
30
50
|
});
|
|
31
51
|
module.exports = __toCommonJS(index_exports);
|
|
32
52
|
|
|
33
53
|
// src/constants.ts
|
|
34
54
|
var WarpFastsetConstants = {
|
|
35
|
-
ChainName: "fastset",
|
|
36
|
-
ChainPrefix: "fastset",
|
|
37
55
|
Pi: {
|
|
38
56
|
Identifier: "PI",
|
|
39
57
|
DisplayName: "Pi",
|
|
@@ -57,23 +75,6 @@ var WarpFastsetConstants = {
|
|
|
57
75
|
High: "50000000000"
|
|
58
76
|
// 50 gwei
|
|
59
77
|
},
|
|
60
|
-
Network: {
|
|
61
|
-
Mainnet: {
|
|
62
|
-
ChainId: "1",
|
|
63
|
-
Name: "Fastset Mainnet",
|
|
64
|
-
BlockTime: 12
|
|
65
|
-
},
|
|
66
|
-
Testnet: {
|
|
67
|
-
ChainId: "11155111",
|
|
68
|
-
Name: "Fastset Testnet",
|
|
69
|
-
BlockTime: 12
|
|
70
|
-
},
|
|
71
|
-
Devnet: {
|
|
72
|
-
ChainId: "1337",
|
|
73
|
-
Name: "Fastset Devnet",
|
|
74
|
-
BlockTime: 12
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
78
|
Validation: {
|
|
78
79
|
AddressLength: 42,
|
|
79
80
|
HexPrefix: "0x",
|
|
@@ -213,28 +214,31 @@ var import_warps2 = require("@vleap/warps");
|
|
|
213
214
|
var FASTSET_CHAIN_CONFIGS = {
|
|
214
215
|
fastset: {
|
|
215
216
|
mainnet: {
|
|
216
|
-
apiUrl: "
|
|
217
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
218
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
217
219
|
explorerUrl: "https://explorer.fastset.com",
|
|
218
220
|
chainId: "1",
|
|
219
221
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
220
222
|
nativeToken: "PI",
|
|
221
|
-
blockTime:
|
|
223
|
+
blockTime: 12e3
|
|
222
224
|
},
|
|
223
225
|
testnet: {
|
|
224
|
-
apiUrl: "
|
|
226
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
227
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
225
228
|
explorerUrl: "https://testnet-explorer.fastset.com",
|
|
226
229
|
chainId: "11155111",
|
|
227
230
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
228
231
|
nativeToken: "PI",
|
|
229
|
-
blockTime:
|
|
232
|
+
blockTime: 12e3
|
|
230
233
|
},
|
|
231
234
|
devnet: {
|
|
232
|
-
apiUrl: "http://
|
|
235
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
236
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
233
237
|
explorerUrl: "http://localhost:4000",
|
|
234
238
|
chainId: "1337",
|
|
235
239
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
236
240
|
nativeToken: "PI",
|
|
237
|
-
blockTime:
|
|
241
|
+
blockTime: 12e3
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
244
|
};
|
|
@@ -253,6 +257,238 @@ var getFastsetChainConfig = (chain = DEFAULT_CHAIN, env) => {
|
|
|
253
257
|
var getFastsetApiUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
254
258
|
return getFastsetChainConfig(chain, env).apiUrl;
|
|
255
259
|
};
|
|
260
|
+
var getFastsetProxyUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
261
|
+
return getFastsetChainConfig(chain, env).proxyUrl;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/sdk/FastsetClient.ts
|
|
265
|
+
var import_ed25519 = require("@noble/ed25519");
|
|
266
|
+
|
|
267
|
+
// src/sdk/types.ts
|
|
268
|
+
var import_bcs = require("@mysten/bcs");
|
|
269
|
+
BigInt.prototype.toJSON = function() {
|
|
270
|
+
return Number(this);
|
|
271
|
+
};
|
|
272
|
+
var Bytes32 = import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8());
|
|
273
|
+
var PublicKey = Bytes32;
|
|
274
|
+
var Address = import_bcs.bcs.enum("Address", {
|
|
275
|
+
External: PublicKey,
|
|
276
|
+
FastSet: PublicKey
|
|
277
|
+
});
|
|
278
|
+
var Amount = import_bcs.bcs.u256().transform({
|
|
279
|
+
input: (val) => hexToDecimal(val.toString()),
|
|
280
|
+
output: (value) => value
|
|
281
|
+
});
|
|
282
|
+
var UserData = import_bcs.bcs.option(Bytes32);
|
|
283
|
+
var Nonce = import_bcs.bcs.u64();
|
|
284
|
+
var Transfer = import_bcs.bcs.struct("Transfer", {
|
|
285
|
+
recipient: Address,
|
|
286
|
+
amount: Amount,
|
|
287
|
+
user_data: UserData
|
|
288
|
+
});
|
|
289
|
+
var ClaimType = import_bcs.bcs.enum("ClaimType", {
|
|
290
|
+
Transfer
|
|
291
|
+
});
|
|
292
|
+
var Transaction = import_bcs.bcs.struct("Transaction", {
|
|
293
|
+
sender: PublicKey,
|
|
294
|
+
nonce: Nonce,
|
|
295
|
+
timestamp_nanos: import_bcs.bcs.u128(),
|
|
296
|
+
claim: ClaimType
|
|
297
|
+
});
|
|
298
|
+
function hexToDecimal(hex) {
|
|
299
|
+
return BigInt(`0x${hex}`).toString();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/sdk/FastsetClient.ts
|
|
303
|
+
var FastsetClient = class {
|
|
304
|
+
constructor(config) {
|
|
305
|
+
this.config = config;
|
|
306
|
+
}
|
|
307
|
+
async getAccountInfo(address) {
|
|
308
|
+
try {
|
|
309
|
+
const response = await this.requestValidator("set_getAccountInfo", {
|
|
310
|
+
address: Array.from(address)
|
|
311
|
+
});
|
|
312
|
+
if (response.error) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
return response.result;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async getNextNonce(senderAddress) {
|
|
321
|
+
const accountInfo = await this.getAccountInfo(senderAddress);
|
|
322
|
+
return accountInfo?.next_nonce ?? 0;
|
|
323
|
+
}
|
|
324
|
+
async fundFromFaucet(request) {
|
|
325
|
+
const response = await this.requestProxy("faucetDrip", {
|
|
326
|
+
recipient: Array.from(request.recipient),
|
|
327
|
+
amount: request.amount
|
|
328
|
+
});
|
|
329
|
+
if (response.error) {
|
|
330
|
+
throw new Error(`Faucet request failed: ${response.error.message}`);
|
|
331
|
+
}
|
|
332
|
+
return response.result;
|
|
333
|
+
}
|
|
334
|
+
async submitTransaction(request) {
|
|
335
|
+
const response = await this.requestValidator("set_submitTransaction", {
|
|
336
|
+
transaction: this.serializeTransaction(request.transaction),
|
|
337
|
+
signature: Array.from(request.signature)
|
|
338
|
+
});
|
|
339
|
+
if (response.error) {
|
|
340
|
+
throw new Error(`Transaction submission failed: ${response.error.message}`);
|
|
341
|
+
}
|
|
342
|
+
const result = response.result;
|
|
343
|
+
return {
|
|
344
|
+
transaction_hash: new Uint8Array(result.transaction_hash),
|
|
345
|
+
validator: new Uint8Array(result.validator),
|
|
346
|
+
signature: new Uint8Array(result.signature)
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
async submitCertificate(request) {
|
|
350
|
+
const response = await this.requestValidator("set_submitTransactionCertificate", {
|
|
351
|
+
transaction: this.serializeTransaction(request.transaction),
|
|
352
|
+
signature: Array.from(request.signature),
|
|
353
|
+
validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
|
|
354
|
+
});
|
|
355
|
+
if (response.error) {
|
|
356
|
+
throw new Error(`Certificate submission failed: ${response.error.message}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async executeTransfer(senderPrivateKey, recipient, amount, userData) {
|
|
360
|
+
const senderPublicKey = await (0, import_ed25519.getPublicKey)(senderPrivateKey);
|
|
361
|
+
const nonce = await this.getNextNonce(senderPublicKey);
|
|
362
|
+
const transaction = {
|
|
363
|
+
sender: senderPublicKey,
|
|
364
|
+
nonce,
|
|
365
|
+
timestamp_nanos: BigInt(Date.now()) * 1000000n,
|
|
366
|
+
claim: {
|
|
367
|
+
Transfer: {
|
|
368
|
+
recipient: { FastSet: recipient },
|
|
369
|
+
amount,
|
|
370
|
+
user_data: userData ?? null
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
const signature = await this.signTransaction(transaction, senderPrivateKey);
|
|
375
|
+
const submitResponse = await this.submitTransaction({
|
|
376
|
+
transaction,
|
|
377
|
+
signature
|
|
378
|
+
});
|
|
379
|
+
await this.submitCertificate({
|
|
380
|
+
transaction,
|
|
381
|
+
signature,
|
|
382
|
+
validator_signatures: [[submitResponse.validator, submitResponse.signature]]
|
|
383
|
+
});
|
|
384
|
+
return submitResponse.transaction_hash;
|
|
385
|
+
}
|
|
386
|
+
async signTransaction(transaction, privateKey) {
|
|
387
|
+
const msg = Transaction.serialize(transaction);
|
|
388
|
+
const msgBytes = msg.toBytes();
|
|
389
|
+
const prefix = new TextEncoder().encode("Transaction::");
|
|
390
|
+
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
391
|
+
dataToSign.set(prefix, 0);
|
|
392
|
+
dataToSign.set(msgBytes, prefix.length);
|
|
393
|
+
return (0, import_ed25519.sign)(dataToSign, privateKey);
|
|
394
|
+
}
|
|
395
|
+
serializeTransaction(transaction) {
|
|
396
|
+
return JSON.stringify(transaction, this.jsonReplacer);
|
|
397
|
+
}
|
|
398
|
+
async requestValidator(method, params) {
|
|
399
|
+
return this.request(this.config.validatorUrl, method, params);
|
|
400
|
+
}
|
|
401
|
+
async requestProxy(method, params) {
|
|
402
|
+
return this.request(this.config.proxyUrl, method, params);
|
|
403
|
+
}
|
|
404
|
+
async request(url, method, params) {
|
|
405
|
+
const request = {
|
|
406
|
+
jsonrpc: "2.0",
|
|
407
|
+
id: 1,
|
|
408
|
+
method,
|
|
409
|
+
params
|
|
410
|
+
};
|
|
411
|
+
const response = await fetch(url, {
|
|
412
|
+
method: "POST",
|
|
413
|
+
headers: { "Content-Type": "application/json" },
|
|
414
|
+
body: JSON.stringify(request, this.jsonReplacer)
|
|
415
|
+
});
|
|
416
|
+
if (!response.ok) {
|
|
417
|
+
throw new Error(`HTTP request failed: ${response.statusText}`);
|
|
418
|
+
}
|
|
419
|
+
return response.json();
|
|
420
|
+
}
|
|
421
|
+
jsonReplacer(key, value) {
|
|
422
|
+
if (value instanceof Uint8Array) {
|
|
423
|
+
return Array.from(value);
|
|
424
|
+
}
|
|
425
|
+
return value;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// src/sdk/utils.ts
|
|
430
|
+
var import_bcs2 = require("@mysten/bcs");
|
|
431
|
+
function isValidFastsetAddress(address) {
|
|
432
|
+
if (typeof address !== "string" || address.length === 0) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
if (address.startsWith("fs") || address.startsWith("pi")) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
const decoded = fromBase64(address);
|
|
440
|
+
return decoded.length === 32;
|
|
441
|
+
} catch {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function fromBase64(base64) {
|
|
446
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
447
|
+
}
|
|
448
|
+
function toBase64String(bytes) {
|
|
449
|
+
return (0, import_bcs2.toBase64)(bytes);
|
|
450
|
+
}
|
|
451
|
+
function toHexString(bytes) {
|
|
452
|
+
return (0, import_bcs2.toHex)(bytes);
|
|
453
|
+
}
|
|
454
|
+
function hexToDecimal2(hex) {
|
|
455
|
+
return BigInt(`0x${hex}`).toString();
|
|
456
|
+
}
|
|
457
|
+
function decimalToHex(decimal) {
|
|
458
|
+
return BigInt(decimal).toString(16);
|
|
459
|
+
}
|
|
460
|
+
function validateAmount(amount) {
|
|
461
|
+
try {
|
|
462
|
+
const bigInt = BigInt(amount);
|
|
463
|
+
return bigInt >= 0;
|
|
464
|
+
} catch {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function normalizeAmount(amount) {
|
|
469
|
+
try {
|
|
470
|
+
const bigInt = BigInt(amount);
|
|
471
|
+
return bigInt.toString(16);
|
|
472
|
+
} catch {
|
|
473
|
+
throw new Error(`Invalid amount format: ${amount}`);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function validatePrivateKey(privateKey) {
|
|
477
|
+
try {
|
|
478
|
+
const key = typeof privateKey === "string" ? fromBase64(privateKey) : privateKey;
|
|
479
|
+
return key.length === 32;
|
|
480
|
+
} catch {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function validatePublicKey(publicKey) {
|
|
485
|
+
try {
|
|
486
|
+
const key = typeof publicKey === "string" ? fromBase64(publicKey) : publicKey;
|
|
487
|
+
return key.length === 32;
|
|
488
|
+
} catch {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
256
492
|
|
|
257
493
|
// src/WarpFastsetSerializer.ts
|
|
258
494
|
var import_warps = require("@vleap/warps");
|
|
@@ -361,63 +597,69 @@ var WarpFastsetExecutor = class {
|
|
|
361
597
|
constructor(config) {
|
|
362
598
|
this.config = config;
|
|
363
599
|
this.serializer = new WarpFastsetSerializer();
|
|
600
|
+
this.fastsetClient = new FastsetClient({
|
|
601
|
+
validatorUrl: getFastsetApiUrl(this.config.env, "fastset"),
|
|
602
|
+
proxyUrl: getFastsetProxyUrl(this.config.env, "fastset")
|
|
603
|
+
});
|
|
364
604
|
}
|
|
365
605
|
async createTransaction(executable) {
|
|
366
606
|
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
607
|
+
switch (action.type) {
|
|
608
|
+
case "transfer":
|
|
609
|
+
return this.createTransferTransaction(executable);
|
|
610
|
+
case "contract":
|
|
611
|
+
return this.createContractCallTransaction(executable);
|
|
612
|
+
case "query":
|
|
613
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
614
|
+
case "collect":
|
|
615
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
616
|
+
default:
|
|
617
|
+
throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
618
|
+
}
|
|
379
619
|
}
|
|
380
620
|
async createTransferTransaction(executable) {
|
|
381
|
-
const userWallet = this.config.user?.wallets?.[executable.chain
|
|
621
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
382
622
|
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
383
|
-
if (!
|
|
623
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
384
624
|
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
385
625
|
}
|
|
386
626
|
if (executable.value < 0) {
|
|
387
627
|
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
388
628
|
}
|
|
629
|
+
const recipientAddress = fromBase64(executable.destination);
|
|
630
|
+
const amount = normalizeAmount(executable.value.toString());
|
|
631
|
+
const userData = executable.data ? fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
|
|
389
632
|
return {
|
|
390
633
|
type: "fastset-transfer",
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
// TODO: Add Fastset-specific transaction fields
|
|
634
|
+
recipient: recipientAddress,
|
|
635
|
+
amount,
|
|
636
|
+
userData,
|
|
637
|
+
chain: executable.chain
|
|
396
638
|
};
|
|
397
639
|
}
|
|
398
640
|
async createContractCallTransaction(executable) {
|
|
399
|
-
const userWallet = this.config.user?.wallets?.[executable.chain
|
|
641
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
400
642
|
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
401
643
|
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
402
644
|
if (!action || !("func" in action) || !action.func) {
|
|
403
645
|
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
404
646
|
}
|
|
405
|
-
if (!
|
|
647
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
406
648
|
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
407
649
|
}
|
|
408
650
|
if (executable.value < 0) {
|
|
409
651
|
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
410
652
|
}
|
|
411
653
|
try {
|
|
654
|
+
const contractAddress = fromBase64(executable.destination);
|
|
412
655
|
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
413
656
|
return {
|
|
414
657
|
type: "fastset-contract-call",
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
value: executable.value,
|
|
658
|
+
contract: contractAddress,
|
|
659
|
+
function: action.func,
|
|
418
660
|
data: encodedData,
|
|
419
|
-
|
|
420
|
-
|
|
661
|
+
value: executable.value,
|
|
662
|
+
chain: executable.chain
|
|
421
663
|
};
|
|
422
664
|
} catch (error) {
|
|
423
665
|
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
@@ -431,21 +673,22 @@ var WarpFastsetExecutor = class {
|
|
|
431
673
|
if (!action.func) {
|
|
432
674
|
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
433
675
|
}
|
|
434
|
-
if (!
|
|
676
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
435
677
|
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
436
678
|
}
|
|
437
679
|
try {
|
|
438
|
-
const
|
|
680
|
+
const contractAddress = fromBase64(executable.destination);
|
|
681
|
+
const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
|
|
439
682
|
return {
|
|
440
683
|
success: true,
|
|
441
|
-
result
|
|
442
|
-
|
|
684
|
+
result,
|
|
685
|
+
chain: executable.chain
|
|
443
686
|
};
|
|
444
687
|
} catch (error) {
|
|
445
688
|
return {
|
|
446
689
|
success: false,
|
|
447
|
-
error: error instanceof Error ? error.message : String(error)
|
|
448
|
-
|
|
690
|
+
error: error instanceof Error ? error.message : String(error),
|
|
691
|
+
chain: executable.chain
|
|
449
692
|
};
|
|
450
693
|
}
|
|
451
694
|
}
|
|
@@ -453,29 +696,32 @@ var WarpFastsetExecutor = class {
|
|
|
453
696
|
const typedValue = this.serializer.stringToTyped(value);
|
|
454
697
|
switch (type) {
|
|
455
698
|
case "address":
|
|
456
|
-
if (!
|
|
699
|
+
if (!isValidFastsetAddress(typedValue)) {
|
|
457
700
|
throw new Error(`Invalid Fastset address format: ${typedValue}`);
|
|
458
701
|
}
|
|
459
702
|
return typedValue;
|
|
703
|
+
case "hex":
|
|
704
|
+
const hexValue = typedValue.startsWith("0x") ? typedValue.slice(2) : typedValue;
|
|
705
|
+
if (!/^[0-9a-fA-F]+$/.test(hexValue)) {
|
|
706
|
+
throw new Error(`Invalid hex format: ${typedValue}`);
|
|
707
|
+
}
|
|
708
|
+
return typedValue;
|
|
460
709
|
case "number":
|
|
461
710
|
const numValue = Number(typedValue);
|
|
462
711
|
if (isNaN(numValue)) {
|
|
463
712
|
throw new Error(`Invalid number format: ${typedValue}`);
|
|
464
713
|
}
|
|
465
714
|
return numValue.toString();
|
|
466
|
-
case "
|
|
715
|
+
case "biguint":
|
|
467
716
|
const bigIntValue = BigInt(typedValue);
|
|
468
717
|
if (bigIntValue < 0) {
|
|
469
|
-
throw new Error(`Negative value not allowed
|
|
718
|
+
throw new Error(`Negative value not allowed`);
|
|
470
719
|
}
|
|
471
720
|
return bigIntValue.toString();
|
|
472
721
|
default:
|
|
473
722
|
return String(typedValue);
|
|
474
723
|
}
|
|
475
724
|
}
|
|
476
|
-
isValidFastsetAddress(address) {
|
|
477
|
-
return typeof address === "string" && address.length > 0;
|
|
478
|
-
}
|
|
479
725
|
encodeFunctionData(functionName, args) {
|
|
480
726
|
return JSON.stringify({
|
|
481
727
|
function: functionName,
|
|
@@ -489,7 +735,7 @@ var WarpFastsetExecutor = class {
|
|
|
489
735
|
"Content-Type": "application/json"
|
|
490
736
|
},
|
|
491
737
|
body: JSON.stringify({
|
|
492
|
-
contract: contractAddress,
|
|
738
|
+
contract: Array.from(contractAddress),
|
|
493
739
|
function: functionName,
|
|
494
740
|
arguments: args
|
|
495
741
|
})
|
|
@@ -502,32 +748,59 @@ var WarpFastsetExecutor = class {
|
|
|
502
748
|
async signMessage(message, privateKey) {
|
|
503
749
|
throw new Error("Not implemented");
|
|
504
750
|
}
|
|
751
|
+
async executeTransfer(executable) {
|
|
752
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
753
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
754
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
755
|
+
return {
|
|
756
|
+
success: true,
|
|
757
|
+
transaction,
|
|
758
|
+
chain: executable.chain,
|
|
759
|
+
message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async executeTransferWithKey(executable, privateKey) {
|
|
763
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
764
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
765
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
766
|
+
const privateKeyBytes = fromBase64(privateKey);
|
|
767
|
+
const transactionHash = await this.fastsetClient.executeTransfer(
|
|
768
|
+
privateKeyBytes,
|
|
769
|
+
transaction.recipient,
|
|
770
|
+
transaction.amount,
|
|
771
|
+
transaction.userData
|
|
772
|
+
);
|
|
773
|
+
return {
|
|
774
|
+
success: true,
|
|
775
|
+
transactionHash: Array.from(transactionHash),
|
|
776
|
+
chain: executable.chain
|
|
777
|
+
};
|
|
778
|
+
}
|
|
505
779
|
};
|
|
506
780
|
|
|
507
781
|
// src/WarpFastsetExplorer.ts
|
|
508
782
|
var WarpFastsetExplorer = class {
|
|
509
|
-
constructor(chainInfo
|
|
783
|
+
constructor(chainInfo) {
|
|
510
784
|
this.chainInfo = chainInfo;
|
|
511
|
-
this.chainName = chainName;
|
|
512
785
|
}
|
|
513
786
|
getAccountUrl(address) {
|
|
514
|
-
const baseUrl = this.
|
|
787
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
515
788
|
return `${baseUrl}/address/${address}`;
|
|
516
789
|
}
|
|
517
790
|
getTransactionUrl(hash) {
|
|
518
|
-
const baseUrl = this.
|
|
791
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
519
792
|
return `${baseUrl}/tx/${hash}`;
|
|
520
793
|
}
|
|
521
794
|
getBlockUrl(blockNumber) {
|
|
522
|
-
const baseUrl = this.
|
|
795
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
523
796
|
return `${baseUrl}/block/${blockNumber}`;
|
|
524
797
|
}
|
|
525
798
|
getContractUrl(address) {
|
|
526
|
-
const baseUrl = this.
|
|
799
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
527
800
|
return `${baseUrl}/contract/${address}`;
|
|
528
801
|
}
|
|
529
802
|
getTokenUrl(address) {
|
|
530
|
-
const baseUrl = this.
|
|
803
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
531
804
|
return `${baseUrl}/token/${address}`;
|
|
532
805
|
}
|
|
533
806
|
getDefaultExplorerUrl() {
|
|
@@ -620,29 +893,60 @@ var WarpFastsetResults = class {
|
|
|
620
893
|
};
|
|
621
894
|
|
|
622
895
|
// src/main.ts
|
|
896
|
+
var ChainName = "fastset";
|
|
623
897
|
var getFastsetAdapter = (config, fallback) => {
|
|
624
898
|
if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
|
|
899
|
+
const chainInfo = {
|
|
900
|
+
name: ChainName,
|
|
901
|
+
displayName: "FastSet",
|
|
902
|
+
chainId: "1",
|
|
903
|
+
blockTime: 100,
|
|
904
|
+
addressHrp: "set",
|
|
905
|
+
apiUrl: "TODO",
|
|
906
|
+
nativeToken: "SET"
|
|
907
|
+
};
|
|
625
908
|
return {
|
|
626
|
-
chain:
|
|
627
|
-
|
|
909
|
+
chain: ChainName,
|
|
910
|
+
chainInfo,
|
|
911
|
+
prefix: "fastset",
|
|
628
912
|
builder: () => new WarpFastsetBuilder(config),
|
|
629
913
|
executor: new WarpFastsetExecutor(config),
|
|
630
914
|
results: new WarpFastsetResults(config),
|
|
631
915
|
serializer: new WarpFastsetSerializer(),
|
|
632
916
|
registry: fallback.registry,
|
|
633
|
-
explorer:
|
|
917
|
+
explorer: new WarpFastsetExplorer(chainInfo),
|
|
634
918
|
abiBuilder: () => fallback.abiBuilder(),
|
|
635
919
|
brandBuilder: () => fallback.brandBuilder()
|
|
636
920
|
};
|
|
637
921
|
};
|
|
638
922
|
// Annotate the CommonJS export names for ESM import in node:
|
|
639
923
|
0 && (module.exports = {
|
|
924
|
+
Address,
|
|
925
|
+
Amount,
|
|
926
|
+
Bytes32,
|
|
927
|
+
ClaimType,
|
|
928
|
+
FastsetClient,
|
|
929
|
+
Nonce,
|
|
930
|
+
PublicKey,
|
|
931
|
+
Transaction,
|
|
932
|
+
Transfer,
|
|
933
|
+
UserData,
|
|
640
934
|
WarpFastsetBuilder,
|
|
641
935
|
WarpFastsetConstants,
|
|
642
936
|
WarpFastsetExecutor,
|
|
643
937
|
WarpFastsetExplorer,
|
|
644
938
|
WarpFastsetResults,
|
|
645
939
|
WarpFastsetSerializer,
|
|
646
|
-
|
|
940
|
+
decimalToHex,
|
|
941
|
+
fromBase64,
|
|
942
|
+
getFastsetAdapter,
|
|
943
|
+
hexToDecimal,
|
|
944
|
+
isValidFastsetAddress,
|
|
945
|
+
normalizeAmount,
|
|
946
|
+
toBase64String,
|
|
947
|
+
toHexString,
|
|
948
|
+
validateAmount,
|
|
949
|
+
validatePrivateKey,
|
|
950
|
+
validatePublicKey
|
|
647
951
|
});
|
|
648
952
|
//# sourceMappingURL=index.js.map
|