@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.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
2
|
var WarpFastsetConstants = {
|
|
3
|
-
ChainName: "fastset",
|
|
4
|
-
ChainPrefix: "fastset",
|
|
5
3
|
Pi: {
|
|
6
4
|
Identifier: "PI",
|
|
7
5
|
DisplayName: "Pi",
|
|
@@ -25,23 +23,6 @@ var WarpFastsetConstants = {
|
|
|
25
23
|
High: "50000000000"
|
|
26
24
|
// 50 gwei
|
|
27
25
|
},
|
|
28
|
-
Network: {
|
|
29
|
-
Mainnet: {
|
|
30
|
-
ChainId: "1",
|
|
31
|
-
Name: "Fastset Mainnet",
|
|
32
|
-
BlockTime: 12
|
|
33
|
-
},
|
|
34
|
-
Testnet: {
|
|
35
|
-
ChainId: "11155111",
|
|
36
|
-
Name: "Fastset Testnet",
|
|
37
|
-
BlockTime: 12
|
|
38
|
-
},
|
|
39
|
-
Devnet: {
|
|
40
|
-
ChainId: "1337",
|
|
41
|
-
Name: "Fastset Devnet",
|
|
42
|
-
BlockTime: 12
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
26
|
Validation: {
|
|
46
27
|
AddressLength: 42,
|
|
47
28
|
HexPrefix: "0x",
|
|
@@ -183,28 +164,31 @@ import {
|
|
|
183
164
|
var FASTSET_CHAIN_CONFIGS = {
|
|
184
165
|
fastset: {
|
|
185
166
|
mainnet: {
|
|
186
|
-
apiUrl: "
|
|
167
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
168
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
187
169
|
explorerUrl: "https://explorer.fastset.com",
|
|
188
170
|
chainId: "1",
|
|
189
171
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
190
172
|
nativeToken: "PI",
|
|
191
|
-
blockTime:
|
|
173
|
+
blockTime: 12e3
|
|
192
174
|
},
|
|
193
175
|
testnet: {
|
|
194
|
-
apiUrl: "
|
|
176
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
177
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
195
178
|
explorerUrl: "https://testnet-explorer.fastset.com",
|
|
196
179
|
chainId: "11155111",
|
|
197
180
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
198
181
|
nativeToken: "PI",
|
|
199
|
-
blockTime:
|
|
182
|
+
blockTime: 12e3
|
|
200
183
|
},
|
|
201
184
|
devnet: {
|
|
202
|
-
apiUrl: "http://
|
|
185
|
+
apiUrl: "http://157.90.201.117:8765",
|
|
186
|
+
proxyUrl: "http://136.243.61.168:44444",
|
|
203
187
|
explorerUrl: "http://localhost:4000",
|
|
204
188
|
chainId: "1337",
|
|
205
189
|
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
206
190
|
nativeToken: "PI",
|
|
207
|
-
blockTime:
|
|
191
|
+
blockTime: 12e3
|
|
208
192
|
}
|
|
209
193
|
}
|
|
210
194
|
};
|
|
@@ -223,6 +207,238 @@ var getFastsetChainConfig = (chain = DEFAULT_CHAIN, env) => {
|
|
|
223
207
|
var getFastsetApiUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
224
208
|
return getFastsetChainConfig(chain, env).apiUrl;
|
|
225
209
|
};
|
|
210
|
+
var getFastsetProxyUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
211
|
+
return getFastsetChainConfig(chain, env).proxyUrl;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/sdk/FastsetClient.ts
|
|
215
|
+
import { getPublicKey, sign } from "@noble/ed25519";
|
|
216
|
+
|
|
217
|
+
// src/sdk/types.ts
|
|
218
|
+
import { bcs } from "@mysten/bcs";
|
|
219
|
+
BigInt.prototype.toJSON = function() {
|
|
220
|
+
return Number(this);
|
|
221
|
+
};
|
|
222
|
+
var Bytes32 = bcs.fixedArray(32, bcs.u8());
|
|
223
|
+
var PublicKey = Bytes32;
|
|
224
|
+
var Address = bcs.enum("Address", {
|
|
225
|
+
External: PublicKey,
|
|
226
|
+
FastSet: PublicKey
|
|
227
|
+
});
|
|
228
|
+
var Amount = bcs.u256().transform({
|
|
229
|
+
input: (val) => hexToDecimal(val.toString()),
|
|
230
|
+
output: (value) => value
|
|
231
|
+
});
|
|
232
|
+
var UserData = bcs.option(Bytes32);
|
|
233
|
+
var Nonce = bcs.u64();
|
|
234
|
+
var Transfer = bcs.struct("Transfer", {
|
|
235
|
+
recipient: Address,
|
|
236
|
+
amount: Amount,
|
|
237
|
+
user_data: UserData
|
|
238
|
+
});
|
|
239
|
+
var ClaimType = bcs.enum("ClaimType", {
|
|
240
|
+
Transfer
|
|
241
|
+
});
|
|
242
|
+
var Transaction = bcs.struct("Transaction", {
|
|
243
|
+
sender: PublicKey,
|
|
244
|
+
nonce: Nonce,
|
|
245
|
+
timestamp_nanos: bcs.u128(),
|
|
246
|
+
claim: ClaimType
|
|
247
|
+
});
|
|
248
|
+
function hexToDecimal(hex) {
|
|
249
|
+
return BigInt(`0x${hex}`).toString();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/sdk/FastsetClient.ts
|
|
253
|
+
var FastsetClient = class {
|
|
254
|
+
constructor(config) {
|
|
255
|
+
this.config = config;
|
|
256
|
+
}
|
|
257
|
+
async getAccountInfo(address) {
|
|
258
|
+
try {
|
|
259
|
+
const response = await this.requestValidator("set_getAccountInfo", {
|
|
260
|
+
address: Array.from(address)
|
|
261
|
+
});
|
|
262
|
+
if (response.error) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return response.result;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async getNextNonce(senderAddress) {
|
|
271
|
+
const accountInfo = await this.getAccountInfo(senderAddress);
|
|
272
|
+
return accountInfo?.next_nonce ?? 0;
|
|
273
|
+
}
|
|
274
|
+
async fundFromFaucet(request) {
|
|
275
|
+
const response = await this.requestProxy("faucetDrip", {
|
|
276
|
+
recipient: Array.from(request.recipient),
|
|
277
|
+
amount: request.amount
|
|
278
|
+
});
|
|
279
|
+
if (response.error) {
|
|
280
|
+
throw new Error(`Faucet request failed: ${response.error.message}`);
|
|
281
|
+
}
|
|
282
|
+
return response.result;
|
|
283
|
+
}
|
|
284
|
+
async submitTransaction(request) {
|
|
285
|
+
const response = await this.requestValidator("set_submitTransaction", {
|
|
286
|
+
transaction: this.serializeTransaction(request.transaction),
|
|
287
|
+
signature: Array.from(request.signature)
|
|
288
|
+
});
|
|
289
|
+
if (response.error) {
|
|
290
|
+
throw new Error(`Transaction submission failed: ${response.error.message}`);
|
|
291
|
+
}
|
|
292
|
+
const result = response.result;
|
|
293
|
+
return {
|
|
294
|
+
transaction_hash: new Uint8Array(result.transaction_hash),
|
|
295
|
+
validator: new Uint8Array(result.validator),
|
|
296
|
+
signature: new Uint8Array(result.signature)
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async submitCertificate(request) {
|
|
300
|
+
const response = await this.requestValidator("set_submitTransactionCertificate", {
|
|
301
|
+
transaction: this.serializeTransaction(request.transaction),
|
|
302
|
+
signature: Array.from(request.signature),
|
|
303
|
+
validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
|
|
304
|
+
});
|
|
305
|
+
if (response.error) {
|
|
306
|
+
throw new Error(`Certificate submission failed: ${response.error.message}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async executeTransfer(senderPrivateKey, recipient, amount, userData) {
|
|
310
|
+
const senderPublicKey = await getPublicKey(senderPrivateKey);
|
|
311
|
+
const nonce = await this.getNextNonce(senderPublicKey);
|
|
312
|
+
const transaction = {
|
|
313
|
+
sender: senderPublicKey,
|
|
314
|
+
nonce,
|
|
315
|
+
timestamp_nanos: BigInt(Date.now()) * 1000000n,
|
|
316
|
+
claim: {
|
|
317
|
+
Transfer: {
|
|
318
|
+
recipient: { FastSet: recipient },
|
|
319
|
+
amount,
|
|
320
|
+
user_data: userData ?? null
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const signature = await this.signTransaction(transaction, senderPrivateKey);
|
|
325
|
+
const submitResponse = await this.submitTransaction({
|
|
326
|
+
transaction,
|
|
327
|
+
signature
|
|
328
|
+
});
|
|
329
|
+
await this.submitCertificate({
|
|
330
|
+
transaction,
|
|
331
|
+
signature,
|
|
332
|
+
validator_signatures: [[submitResponse.validator, submitResponse.signature]]
|
|
333
|
+
});
|
|
334
|
+
return submitResponse.transaction_hash;
|
|
335
|
+
}
|
|
336
|
+
async signTransaction(transaction, privateKey) {
|
|
337
|
+
const msg = Transaction.serialize(transaction);
|
|
338
|
+
const msgBytes = msg.toBytes();
|
|
339
|
+
const prefix = new TextEncoder().encode("Transaction::");
|
|
340
|
+
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
341
|
+
dataToSign.set(prefix, 0);
|
|
342
|
+
dataToSign.set(msgBytes, prefix.length);
|
|
343
|
+
return sign(dataToSign, privateKey);
|
|
344
|
+
}
|
|
345
|
+
serializeTransaction(transaction) {
|
|
346
|
+
return JSON.stringify(transaction, this.jsonReplacer);
|
|
347
|
+
}
|
|
348
|
+
async requestValidator(method, params) {
|
|
349
|
+
return this.request(this.config.validatorUrl, method, params);
|
|
350
|
+
}
|
|
351
|
+
async requestProxy(method, params) {
|
|
352
|
+
return this.request(this.config.proxyUrl, method, params);
|
|
353
|
+
}
|
|
354
|
+
async request(url, method, params) {
|
|
355
|
+
const request = {
|
|
356
|
+
jsonrpc: "2.0",
|
|
357
|
+
id: 1,
|
|
358
|
+
method,
|
|
359
|
+
params
|
|
360
|
+
};
|
|
361
|
+
const response = await fetch(url, {
|
|
362
|
+
method: "POST",
|
|
363
|
+
headers: { "Content-Type": "application/json" },
|
|
364
|
+
body: JSON.stringify(request, this.jsonReplacer)
|
|
365
|
+
});
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`HTTP request failed: ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
return response.json();
|
|
370
|
+
}
|
|
371
|
+
jsonReplacer(key, value) {
|
|
372
|
+
if (value instanceof Uint8Array) {
|
|
373
|
+
return Array.from(value);
|
|
374
|
+
}
|
|
375
|
+
return value;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/sdk/utils.ts
|
|
380
|
+
import { toBase64, toHex } from "@mysten/bcs";
|
|
381
|
+
function isValidFastsetAddress(address) {
|
|
382
|
+
if (typeof address !== "string" || address.length === 0) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
if (address.startsWith("fs") || address.startsWith("pi")) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const decoded = fromBase64(address);
|
|
390
|
+
return decoded.length === 32;
|
|
391
|
+
} catch {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function fromBase64(base64) {
|
|
396
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
397
|
+
}
|
|
398
|
+
function toBase64String(bytes) {
|
|
399
|
+
return toBase64(bytes);
|
|
400
|
+
}
|
|
401
|
+
function toHexString(bytes) {
|
|
402
|
+
return toHex(bytes);
|
|
403
|
+
}
|
|
404
|
+
function hexToDecimal2(hex) {
|
|
405
|
+
return BigInt(`0x${hex}`).toString();
|
|
406
|
+
}
|
|
407
|
+
function decimalToHex(decimal) {
|
|
408
|
+
return BigInt(decimal).toString(16);
|
|
409
|
+
}
|
|
410
|
+
function validateAmount(amount) {
|
|
411
|
+
try {
|
|
412
|
+
const bigInt = BigInt(amount);
|
|
413
|
+
return bigInt >= 0;
|
|
414
|
+
} catch {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function normalizeAmount(amount) {
|
|
419
|
+
try {
|
|
420
|
+
const bigInt = BigInt(amount);
|
|
421
|
+
return bigInt.toString(16);
|
|
422
|
+
} catch {
|
|
423
|
+
throw new Error(`Invalid amount format: ${amount}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function validatePrivateKey(privateKey) {
|
|
427
|
+
try {
|
|
428
|
+
const key = typeof privateKey === "string" ? fromBase64(privateKey) : privateKey;
|
|
429
|
+
return key.length === 32;
|
|
430
|
+
} catch {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function validatePublicKey(publicKey) {
|
|
435
|
+
try {
|
|
436
|
+
const key = typeof publicKey === "string" ? fromBase64(publicKey) : publicKey;
|
|
437
|
+
return key.length === 32;
|
|
438
|
+
} catch {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
226
442
|
|
|
227
443
|
// src/WarpFastsetSerializer.ts
|
|
228
444
|
import {
|
|
@@ -333,63 +549,69 @@ var WarpFastsetExecutor = class {
|
|
|
333
549
|
constructor(config) {
|
|
334
550
|
this.config = config;
|
|
335
551
|
this.serializer = new WarpFastsetSerializer();
|
|
552
|
+
this.fastsetClient = new FastsetClient({
|
|
553
|
+
validatorUrl: getFastsetApiUrl(this.config.env, "fastset"),
|
|
554
|
+
proxyUrl: getFastsetProxyUrl(this.config.env, "fastset")
|
|
555
|
+
});
|
|
336
556
|
}
|
|
337
557
|
async createTransaction(executable) {
|
|
338
558
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
559
|
+
switch (action.type) {
|
|
560
|
+
case "transfer":
|
|
561
|
+
return this.createTransferTransaction(executable);
|
|
562
|
+
case "contract":
|
|
563
|
+
return this.createContractCallTransaction(executable);
|
|
564
|
+
case "query":
|
|
565
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
566
|
+
case "collect":
|
|
567
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
568
|
+
default:
|
|
569
|
+
throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
570
|
+
}
|
|
351
571
|
}
|
|
352
572
|
async createTransferTransaction(executable) {
|
|
353
|
-
const userWallet = this.config.user?.wallets?.[executable.chain
|
|
573
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
354
574
|
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
355
|
-
if (!
|
|
575
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
356
576
|
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
357
577
|
}
|
|
358
578
|
if (executable.value < 0) {
|
|
359
579
|
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
360
580
|
}
|
|
581
|
+
const recipientAddress = fromBase64(executable.destination);
|
|
582
|
+
const amount = normalizeAmount(executable.value.toString());
|
|
583
|
+
const userData = executable.data ? fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
|
|
361
584
|
return {
|
|
362
585
|
type: "fastset-transfer",
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// TODO: Add Fastset-specific transaction fields
|
|
586
|
+
recipient: recipientAddress,
|
|
587
|
+
amount,
|
|
588
|
+
userData,
|
|
589
|
+
chain: executable.chain
|
|
368
590
|
};
|
|
369
591
|
}
|
|
370
592
|
async createContractCallTransaction(executable) {
|
|
371
|
-
const userWallet = this.config.user?.wallets?.[executable.chain
|
|
593
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
372
594
|
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
373
595
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
374
596
|
if (!action || !("func" in action) || !action.func) {
|
|
375
597
|
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
376
598
|
}
|
|
377
|
-
if (!
|
|
599
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
378
600
|
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
379
601
|
}
|
|
380
602
|
if (executable.value < 0) {
|
|
381
603
|
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
382
604
|
}
|
|
383
605
|
try {
|
|
606
|
+
const contractAddress = fromBase64(executable.destination);
|
|
384
607
|
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
385
608
|
return {
|
|
386
609
|
type: "fastset-contract-call",
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
value: executable.value,
|
|
610
|
+
contract: contractAddress,
|
|
611
|
+
function: action.func,
|
|
390
612
|
data: encodedData,
|
|
391
|
-
|
|
392
|
-
|
|
613
|
+
value: executable.value,
|
|
614
|
+
chain: executable.chain
|
|
393
615
|
};
|
|
394
616
|
} catch (error) {
|
|
395
617
|
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
@@ -403,21 +625,22 @@ var WarpFastsetExecutor = class {
|
|
|
403
625
|
if (!action.func) {
|
|
404
626
|
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
405
627
|
}
|
|
406
|
-
if (!
|
|
628
|
+
if (!isValidFastsetAddress(executable.destination)) {
|
|
407
629
|
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
408
630
|
}
|
|
409
631
|
try {
|
|
410
|
-
const
|
|
632
|
+
const contractAddress = fromBase64(executable.destination);
|
|
633
|
+
const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
|
|
411
634
|
return {
|
|
412
635
|
success: true,
|
|
413
|
-
result
|
|
414
|
-
|
|
636
|
+
result,
|
|
637
|
+
chain: executable.chain
|
|
415
638
|
};
|
|
416
639
|
} catch (error) {
|
|
417
640
|
return {
|
|
418
641
|
success: false,
|
|
419
|
-
error: error instanceof Error ? error.message : String(error)
|
|
420
|
-
|
|
642
|
+
error: error instanceof Error ? error.message : String(error),
|
|
643
|
+
chain: executable.chain
|
|
421
644
|
};
|
|
422
645
|
}
|
|
423
646
|
}
|
|
@@ -425,29 +648,32 @@ var WarpFastsetExecutor = class {
|
|
|
425
648
|
const typedValue = this.serializer.stringToTyped(value);
|
|
426
649
|
switch (type) {
|
|
427
650
|
case "address":
|
|
428
|
-
if (!
|
|
651
|
+
if (!isValidFastsetAddress(typedValue)) {
|
|
429
652
|
throw new Error(`Invalid Fastset address format: ${typedValue}`);
|
|
430
653
|
}
|
|
431
654
|
return typedValue;
|
|
655
|
+
case "hex":
|
|
656
|
+
const hexValue = typedValue.startsWith("0x") ? typedValue.slice(2) : typedValue;
|
|
657
|
+
if (!/^[0-9a-fA-F]+$/.test(hexValue)) {
|
|
658
|
+
throw new Error(`Invalid hex format: ${typedValue}`);
|
|
659
|
+
}
|
|
660
|
+
return typedValue;
|
|
432
661
|
case "number":
|
|
433
662
|
const numValue = Number(typedValue);
|
|
434
663
|
if (isNaN(numValue)) {
|
|
435
664
|
throw new Error(`Invalid number format: ${typedValue}`);
|
|
436
665
|
}
|
|
437
666
|
return numValue.toString();
|
|
438
|
-
case "
|
|
667
|
+
case "biguint":
|
|
439
668
|
const bigIntValue = BigInt(typedValue);
|
|
440
669
|
if (bigIntValue < 0) {
|
|
441
|
-
throw new Error(`Negative value not allowed
|
|
670
|
+
throw new Error(`Negative value not allowed`);
|
|
442
671
|
}
|
|
443
672
|
return bigIntValue.toString();
|
|
444
673
|
default:
|
|
445
674
|
return String(typedValue);
|
|
446
675
|
}
|
|
447
676
|
}
|
|
448
|
-
isValidFastsetAddress(address) {
|
|
449
|
-
return typeof address === "string" && address.length > 0;
|
|
450
|
-
}
|
|
451
677
|
encodeFunctionData(functionName, args) {
|
|
452
678
|
return JSON.stringify({
|
|
453
679
|
function: functionName,
|
|
@@ -461,7 +687,7 @@ var WarpFastsetExecutor = class {
|
|
|
461
687
|
"Content-Type": "application/json"
|
|
462
688
|
},
|
|
463
689
|
body: JSON.stringify({
|
|
464
|
-
contract: contractAddress,
|
|
690
|
+
contract: Array.from(contractAddress),
|
|
465
691
|
function: functionName,
|
|
466
692
|
arguments: args
|
|
467
693
|
})
|
|
@@ -474,32 +700,59 @@ var WarpFastsetExecutor = class {
|
|
|
474
700
|
async signMessage(message, privateKey) {
|
|
475
701
|
throw new Error("Not implemented");
|
|
476
702
|
}
|
|
703
|
+
async executeTransfer(executable) {
|
|
704
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
705
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
706
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
707
|
+
return {
|
|
708
|
+
success: true,
|
|
709
|
+
transaction,
|
|
710
|
+
chain: executable.chain,
|
|
711
|
+
message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
async executeTransferWithKey(executable, privateKey) {
|
|
715
|
+
const userWallet = this.config.user?.wallets?.[executable.chain];
|
|
716
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
717
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
718
|
+
const privateKeyBytes = fromBase64(privateKey);
|
|
719
|
+
const transactionHash = await this.fastsetClient.executeTransfer(
|
|
720
|
+
privateKeyBytes,
|
|
721
|
+
transaction.recipient,
|
|
722
|
+
transaction.amount,
|
|
723
|
+
transaction.userData
|
|
724
|
+
);
|
|
725
|
+
return {
|
|
726
|
+
success: true,
|
|
727
|
+
transactionHash: Array.from(transactionHash),
|
|
728
|
+
chain: executable.chain
|
|
729
|
+
};
|
|
730
|
+
}
|
|
477
731
|
};
|
|
478
732
|
|
|
479
733
|
// src/WarpFastsetExplorer.ts
|
|
480
734
|
var WarpFastsetExplorer = class {
|
|
481
|
-
constructor(chainInfo
|
|
735
|
+
constructor(chainInfo) {
|
|
482
736
|
this.chainInfo = chainInfo;
|
|
483
|
-
this.chainName = chainName;
|
|
484
737
|
}
|
|
485
738
|
getAccountUrl(address) {
|
|
486
|
-
const baseUrl = this.
|
|
739
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
487
740
|
return `${baseUrl}/address/${address}`;
|
|
488
741
|
}
|
|
489
742
|
getTransactionUrl(hash) {
|
|
490
|
-
const baseUrl = this.
|
|
743
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
491
744
|
return `${baseUrl}/tx/${hash}`;
|
|
492
745
|
}
|
|
493
746
|
getBlockUrl(blockNumber) {
|
|
494
|
-
const baseUrl = this.
|
|
747
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
495
748
|
return `${baseUrl}/block/${blockNumber}`;
|
|
496
749
|
}
|
|
497
750
|
getContractUrl(address) {
|
|
498
|
-
const baseUrl = this.
|
|
751
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
499
752
|
return `${baseUrl}/contract/${address}`;
|
|
500
753
|
}
|
|
501
754
|
getTokenUrl(address) {
|
|
502
|
-
const baseUrl = this.
|
|
755
|
+
const baseUrl = this.getDefaultExplorerUrl();
|
|
503
756
|
return `${baseUrl}/token/${address}`;
|
|
504
757
|
}
|
|
505
758
|
getDefaultExplorerUrl() {
|
|
@@ -596,28 +849,59 @@ var WarpFastsetResults = class {
|
|
|
596
849
|
};
|
|
597
850
|
|
|
598
851
|
// src/main.ts
|
|
852
|
+
var ChainName = "fastset";
|
|
599
853
|
var getFastsetAdapter = (config, fallback) => {
|
|
600
854
|
if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
|
|
855
|
+
const chainInfo = {
|
|
856
|
+
name: ChainName,
|
|
857
|
+
displayName: "FastSet",
|
|
858
|
+
chainId: "1",
|
|
859
|
+
blockTime: 100,
|
|
860
|
+
addressHrp: "set",
|
|
861
|
+
apiUrl: "TODO",
|
|
862
|
+
nativeToken: "SET"
|
|
863
|
+
};
|
|
601
864
|
return {
|
|
602
|
-
chain:
|
|
603
|
-
|
|
865
|
+
chain: ChainName,
|
|
866
|
+
chainInfo,
|
|
867
|
+
prefix: "fastset",
|
|
604
868
|
builder: () => new WarpFastsetBuilder(config),
|
|
605
869
|
executor: new WarpFastsetExecutor(config),
|
|
606
870
|
results: new WarpFastsetResults(config),
|
|
607
871
|
serializer: new WarpFastsetSerializer(),
|
|
608
872
|
registry: fallback.registry,
|
|
609
|
-
explorer:
|
|
873
|
+
explorer: new WarpFastsetExplorer(chainInfo),
|
|
610
874
|
abiBuilder: () => fallback.abiBuilder(),
|
|
611
875
|
brandBuilder: () => fallback.brandBuilder()
|
|
612
876
|
};
|
|
613
877
|
};
|
|
614
878
|
export {
|
|
879
|
+
Address,
|
|
880
|
+
Amount,
|
|
881
|
+
Bytes32,
|
|
882
|
+
ClaimType,
|
|
883
|
+
FastsetClient,
|
|
884
|
+
Nonce,
|
|
885
|
+
PublicKey,
|
|
886
|
+
Transaction,
|
|
887
|
+
Transfer,
|
|
888
|
+
UserData,
|
|
615
889
|
WarpFastsetBuilder,
|
|
616
890
|
WarpFastsetConstants,
|
|
617
891
|
WarpFastsetExecutor,
|
|
618
892
|
WarpFastsetExplorer,
|
|
619
893
|
WarpFastsetResults,
|
|
620
894
|
WarpFastsetSerializer,
|
|
621
|
-
|
|
895
|
+
decimalToHex,
|
|
896
|
+
fromBase64,
|
|
897
|
+
getFastsetAdapter,
|
|
898
|
+
hexToDecimal2 as hexToDecimal,
|
|
899
|
+
isValidFastsetAddress,
|
|
900
|
+
normalizeAmount,
|
|
901
|
+
toBase64String,
|
|
902
|
+
toHexString,
|
|
903
|
+
validateAmount,
|
|
904
|
+
validatePrivateKey,
|
|
905
|
+
validatePublicKey
|
|
622
906
|
};
|
|
623
907
|
//# sourceMappingURL=index.mjs.map
|