@vleap/warps-adapter-fastset 0.1.0-alpha.14 → 0.1.0-alpha.16
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 +376 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +1075 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +130 -112
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,1075 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Address: () => Address,
|
|
34
|
+
Amount: () => Amount,
|
|
35
|
+
BcsTransaction: () => BcsTransaction,
|
|
36
|
+
Bytes32: () => Bytes32,
|
|
37
|
+
Claim: () => Claim,
|
|
38
|
+
ClaimType: () => ClaimType,
|
|
39
|
+
FastsetClient: () => FastsetClient,
|
|
40
|
+
NativeTokenSet: () => NativeTokenSet,
|
|
41
|
+
Nonce: () => Nonce,
|
|
42
|
+
PublicKey: () => PublicKey,
|
|
43
|
+
Transaction: () => Transaction,
|
|
44
|
+
Transfer: () => Transfer,
|
|
45
|
+
TransferClaim: () => TransferClaim,
|
|
46
|
+
UserData: () => UserData,
|
|
47
|
+
Wallet: () => Wallet,
|
|
48
|
+
WarpFastsetConstants: () => WarpFastsetConstants,
|
|
49
|
+
WarpFastsetDataLoader: () => WarpFastsetDataLoader,
|
|
50
|
+
WarpFastsetExecutor: () => WarpFastsetExecutor,
|
|
51
|
+
WarpFastsetExplorer: () => WarpFastsetExplorer,
|
|
52
|
+
WarpFastsetResults: () => WarpFastsetResults,
|
|
53
|
+
WarpFastsetSerializer: () => WarpFastsetSerializer,
|
|
54
|
+
getFastsetAdapter: () => getFastsetAdapter
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/constants.ts
|
|
59
|
+
var WarpFastsetConstants = {
|
|
60
|
+
// Placeholder for future FastSet-specific constants
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/main.ts
|
|
64
|
+
var import_warps4 = require("@vleap/warps");
|
|
65
|
+
|
|
66
|
+
// src/sdk/FastsetClient.ts
|
|
67
|
+
var import_ed255192 = require("@noble/ed25519");
|
|
68
|
+
|
|
69
|
+
// src/sdk/TransactionSigner.ts
|
|
70
|
+
var import_ed25519 = require("@noble/ed25519");
|
|
71
|
+
|
|
72
|
+
// src/sdk/types.ts
|
|
73
|
+
var import_bcs = require("@mysten/bcs");
|
|
74
|
+
BigInt.prototype.toJSON = function() {
|
|
75
|
+
return Number(this);
|
|
76
|
+
};
|
|
77
|
+
var Bytes32 = import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8());
|
|
78
|
+
var PublicKey = Bytes32;
|
|
79
|
+
var Address = import_bcs.bcs.enum("Address", {
|
|
80
|
+
External: PublicKey,
|
|
81
|
+
FastSet: PublicKey
|
|
82
|
+
});
|
|
83
|
+
var Amount = import_bcs.bcs.u256().transform({
|
|
84
|
+
input: (val) => hexToDecimal(val.toString()),
|
|
85
|
+
output: (value) => value
|
|
86
|
+
});
|
|
87
|
+
var UserData = import_bcs.bcs.option(Bytes32);
|
|
88
|
+
var Nonce = import_bcs.bcs.u64();
|
|
89
|
+
var Transfer = import_bcs.bcs.struct("Transfer", {
|
|
90
|
+
recipient: Address,
|
|
91
|
+
amount: Amount,
|
|
92
|
+
user_data: UserData
|
|
93
|
+
});
|
|
94
|
+
var ClaimType = import_bcs.bcs.enum("ClaimType", {
|
|
95
|
+
Transfer
|
|
96
|
+
});
|
|
97
|
+
var BcsTransaction = import_bcs.bcs.struct("Transaction", {
|
|
98
|
+
sender: PublicKey,
|
|
99
|
+
nonce: Nonce,
|
|
100
|
+
timestamp_nanos: import_bcs.bcs.u128(),
|
|
101
|
+
claim: ClaimType
|
|
102
|
+
});
|
|
103
|
+
function hexToDecimal(hex) {
|
|
104
|
+
return BigInt(`0x${hex}`).toString();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/sdk/TransactionSigner.ts
|
|
108
|
+
var TransactionSigner = class {
|
|
109
|
+
static async signTransaction(transaction, privateKey) {
|
|
110
|
+
const msg = BcsTransaction.serialize(transaction);
|
|
111
|
+
const msgBytes = msg.toBytes();
|
|
112
|
+
const prefix = new TextEncoder().encode("Transaction::");
|
|
113
|
+
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
114
|
+
dataToSign.set(prefix, 0);
|
|
115
|
+
dataToSign.set(msgBytes, prefix.length);
|
|
116
|
+
return (0, import_ed25519.sign)(dataToSign, privateKey);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/sdk/Wallet.ts
|
|
121
|
+
var bech32 = __toESM(require("bech32"), 1);
|
|
122
|
+
|
|
123
|
+
// src/sdk/Claim.ts
|
|
124
|
+
var Claim = class {
|
|
125
|
+
static fromTransaction(transaction) {
|
|
126
|
+
const claimType = Object.keys(transaction.claim)[0];
|
|
127
|
+
const claimData = transaction.claim[claimType];
|
|
128
|
+
switch (claimType) {
|
|
129
|
+
case "Transfer":
|
|
130
|
+
return TransferClaim.fromData(claimData);
|
|
131
|
+
default:
|
|
132
|
+
throw new Error(`Unknown claim type: ${claimType}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var TransferClaim = class _TransferClaim extends Claim {
|
|
137
|
+
constructor(recipient, amount, userData) {
|
|
138
|
+
super();
|
|
139
|
+
this.type = "Transfer";
|
|
140
|
+
this.data = { recipient, amount, userData };
|
|
141
|
+
}
|
|
142
|
+
toTransactionData() {
|
|
143
|
+
return {
|
|
144
|
+
Transfer: {
|
|
145
|
+
recipient: { FastSet: this.data.recipient },
|
|
146
|
+
amount: this.data.amount,
|
|
147
|
+
user_data: this.data.userData ?? null
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
static fromData(data) {
|
|
152
|
+
const recipient = data.recipient.FastSet || data.recipient.External;
|
|
153
|
+
return new _TransferClaim(recipient, data.amount, data.user_data);
|
|
154
|
+
}
|
|
155
|
+
getRecipient() {
|
|
156
|
+
return this.data.recipient;
|
|
157
|
+
}
|
|
158
|
+
getAmount() {
|
|
159
|
+
return this.data.amount;
|
|
160
|
+
}
|
|
161
|
+
getUserData() {
|
|
162
|
+
return this.data.userData;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/sdk/ed25519-setup.ts
|
|
167
|
+
var ed = __toESM(require("@noble/ed25519"), 1);
|
|
168
|
+
var import_sha512 = require("@noble/hashes/sha512");
|
|
169
|
+
if (ed.etc) {
|
|
170
|
+
ed.etc.sha512Sync = (...m) => (0, import_sha512.sha512)(ed.etc.concatBytes(...m));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/sdk/Transaction.ts
|
|
174
|
+
var Transaction = class _Transaction {
|
|
175
|
+
constructor(sender, nonce, claim, options = {}) {
|
|
176
|
+
this.sender = sender;
|
|
177
|
+
this.nonce = nonce;
|
|
178
|
+
this.claim = claim;
|
|
179
|
+
this.timestamp = options.timestamp ?? BigInt(Date.now()) * 1000000n;
|
|
180
|
+
}
|
|
181
|
+
toTransaction() {
|
|
182
|
+
return {
|
|
183
|
+
sender: this.sender,
|
|
184
|
+
nonce: this.nonce,
|
|
185
|
+
timestamp_nanos: this.timestamp,
|
|
186
|
+
claim: this.claim.toTransactionData()
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
getSender() {
|
|
190
|
+
return this.sender;
|
|
191
|
+
}
|
|
192
|
+
getNonce() {
|
|
193
|
+
return this.nonce;
|
|
194
|
+
}
|
|
195
|
+
getClaim() {
|
|
196
|
+
return this.claim;
|
|
197
|
+
}
|
|
198
|
+
getTimestamp() {
|
|
199
|
+
return this.timestamp;
|
|
200
|
+
}
|
|
201
|
+
static fromTransaction(transaction) {
|
|
202
|
+
const claim = Claim.fromTransaction(transaction);
|
|
203
|
+
return new _Transaction(transaction.sender, transaction.nonce, claim, { timestamp: transaction.timestamp_nanos });
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/sdk/Wallet.ts
|
|
208
|
+
var Wallet = class _Wallet {
|
|
209
|
+
constructor(privateKeyHex) {
|
|
210
|
+
const cleanPrivateKey = privateKeyHex.replace(/^0x/, "");
|
|
211
|
+
this.privateKey = Buffer.from(cleanPrivateKey, "hex");
|
|
212
|
+
this.publicKey = ed.getPublicKey(this.privateKey);
|
|
213
|
+
this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
|
|
214
|
+
}
|
|
215
|
+
toBech32() {
|
|
216
|
+
const words = bech32.bech32m.toWords(this.publicKey);
|
|
217
|
+
return bech32.bech32m.encode("set", words);
|
|
218
|
+
}
|
|
219
|
+
getWalletInfo() {
|
|
220
|
+
return {
|
|
221
|
+
publicKeyHex: this.publicKeyHex,
|
|
222
|
+
address: this.toBech32()
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
createTransferClaim(recipientAddress, amount, assetType) {
|
|
226
|
+
const recipientBytes = _Wallet.decodeBech32Address(recipientAddress);
|
|
227
|
+
const assetTypeBytes = new TextEncoder().encode(assetType);
|
|
228
|
+
const userData = new Uint8Array(32);
|
|
229
|
+
userData.set(assetTypeBytes.slice(0, 32));
|
|
230
|
+
return new TransferClaim(recipientBytes, amount.toString(), userData);
|
|
231
|
+
}
|
|
232
|
+
createTransaction(nonce, claim) {
|
|
233
|
+
return new Transaction(this.publicKey, nonce, claim);
|
|
234
|
+
}
|
|
235
|
+
async signTransaction(transaction) {
|
|
236
|
+
const transactionData = transaction.toTransaction();
|
|
237
|
+
return await TransactionSigner.signTransaction(transactionData, this.privateKey);
|
|
238
|
+
}
|
|
239
|
+
static decodeBech32Address(address) {
|
|
240
|
+
try {
|
|
241
|
+
const decoded = bech32.bech32m.decode(address);
|
|
242
|
+
return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
|
|
243
|
+
} catch (error) {
|
|
244
|
+
const decoded = bech32.bech32.decode(address);
|
|
245
|
+
return new Uint8Array(bech32.bech32.fromWords(decoded.words));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
static encodeBech32Address(publicKey) {
|
|
249
|
+
const words = bech32.bech32m.toWords(publicKey);
|
|
250
|
+
return bech32.bech32m.encode("set", words);
|
|
251
|
+
}
|
|
252
|
+
static fromPrivateKey(privateKeyHex) {
|
|
253
|
+
return new _Wallet(privateKeyHex);
|
|
254
|
+
}
|
|
255
|
+
static generateNew() {
|
|
256
|
+
const privateKey = ed.utils.randomPrivateKey();
|
|
257
|
+
const privateKeyHex = Buffer.from(privateKey).toString("hex");
|
|
258
|
+
return new _Wallet(privateKeyHex);
|
|
259
|
+
}
|
|
260
|
+
static async fromPrivateKeyFile(filePath) {
|
|
261
|
+
const fs = await import("fs/promises");
|
|
262
|
+
const privateKeyHex = (await fs.readFile(filePath, "utf8")).trim();
|
|
263
|
+
return new _Wallet(privateKeyHex);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/sdk/FastsetClient.ts
|
|
268
|
+
BigInt.prototype.toJSON = function() {
|
|
269
|
+
return Number(this);
|
|
270
|
+
};
|
|
271
|
+
var FASTSET_VALIDATOR_URL = "http://157.90.201.117:8765";
|
|
272
|
+
var FASTSET_PROXY_URL = "http://136.243.61.168:44444";
|
|
273
|
+
var FastsetClient = class {
|
|
274
|
+
constructor(config) {
|
|
275
|
+
this.config = config || {
|
|
276
|
+
validatorUrl: FASTSET_VALIDATOR_URL,
|
|
277
|
+
proxyUrl: FASTSET_PROXY_URL
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async getAccountInfo(address) {
|
|
281
|
+
try {
|
|
282
|
+
const addressBytes = Wallet.decodeBech32Address(address);
|
|
283
|
+
const response = await this.requestValidator("set_getAccountInfo", {
|
|
284
|
+
address: Array.from(addressBytes)
|
|
285
|
+
});
|
|
286
|
+
return response.result;
|
|
287
|
+
} catch (error) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async getNextNonce(senderAddress) {
|
|
292
|
+
const accountInfo = await this.getAccountInfo(senderAddress);
|
|
293
|
+
return accountInfo?.next_nonce ?? 0;
|
|
294
|
+
}
|
|
295
|
+
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
|
+
}
|
|
305
|
+
}
|
|
306
|
+
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
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async fundFromFaucet(recipientAddress, amount) {
|
|
317
|
+
const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
|
|
318
|
+
const response = await this.requestProxy("faucetDrip", {
|
|
319
|
+
recipient: Array.from(recipientBytes),
|
|
320
|
+
amount
|
|
321
|
+
});
|
|
322
|
+
return response.result;
|
|
323
|
+
}
|
|
324
|
+
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;
|
|
330
|
+
return {
|
|
331
|
+
transaction_hash: new Uint8Array(result.transaction_hash),
|
|
332
|
+
validator: new Uint8Array(result.validator),
|
|
333
|
+
signature: new Uint8Array(result.signature)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
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
|
+
});
|
|
342
|
+
}
|
|
343
|
+
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
|
|
357
|
+
}
|
|
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;
|
|
371
|
+
}
|
|
372
|
+
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;
|
|
393
|
+
}
|
|
394
|
+
async signTransaction(transaction, privateKey) {
|
|
395
|
+
return await TransactionSigner.signTransaction(transaction, privateKey);
|
|
396
|
+
}
|
|
397
|
+
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
|
+
}
|
|
406
|
+
}
|
|
407
|
+
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
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async getNetworkInfo() {
|
|
418
|
+
try {
|
|
419
|
+
const response = await this.requestValidator("set_getNetworkInfo", {});
|
|
420
|
+
return response.result;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async requestValidator(method, params) {
|
|
426
|
+
return this.request(this.config.validatorUrl, method, params);
|
|
427
|
+
}
|
|
428
|
+
async requestProxy(method, params) {
|
|
429
|
+
return this.request(this.config.proxyUrl, method, params);
|
|
430
|
+
}
|
|
431
|
+
async request(url, method, params) {
|
|
432
|
+
try {
|
|
433
|
+
const request = {
|
|
434
|
+
jsonrpc: "2.0",
|
|
435
|
+
id: 1,
|
|
436
|
+
method,
|
|
437
|
+
params
|
|
438
|
+
};
|
|
439
|
+
const response = await fetch(url, {
|
|
440
|
+
method: "POST",
|
|
441
|
+
headers: { "Content-Type": "application/json" },
|
|
442
|
+
body: JSON.stringify(request, this.jsonReplacer)
|
|
443
|
+
});
|
|
444
|
+
if (!response.ok) {
|
|
445
|
+
throw new Error(`HTTP request failed: ${response.statusText}`);
|
|
446
|
+
}
|
|
447
|
+
const jsonResponse = await response.json();
|
|
448
|
+
if (jsonResponse.error) {
|
|
449
|
+
throw new Error(`RPC error: ${jsonResponse.error.message}`);
|
|
450
|
+
}
|
|
451
|
+
return jsonResponse;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
console.error(`Fastset RPC request failed: ${error}`);
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
jsonReplacer(key, value) {
|
|
458
|
+
if (value instanceof Uint8Array) {
|
|
459
|
+
return Array.from(value);
|
|
460
|
+
}
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
// src/WarpFastsetDataLoader.ts
|
|
466
|
+
var WarpFastsetDataLoader = class {
|
|
467
|
+
constructor(config, chain) {
|
|
468
|
+
this.config = config;
|
|
469
|
+
this.chain = chain;
|
|
470
|
+
this.client = new FastsetClient();
|
|
471
|
+
}
|
|
472
|
+
async getAccount(address) {
|
|
473
|
+
const accountInfo = await this.client.getAccountInfo(address);
|
|
474
|
+
if (!accountInfo) {
|
|
475
|
+
return {
|
|
476
|
+
chain: this.chain.name,
|
|
477
|
+
address,
|
|
478
|
+
balance: BigInt(0)
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
chain: this.chain.name,
|
|
483
|
+
address,
|
|
484
|
+
balance: BigInt(parseInt(accountInfo.balance, 16))
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
async getAccountAssets(address) {
|
|
488
|
+
const accountReq = this.getAccount(address);
|
|
489
|
+
const assetBalancesReq = this.client.getAssetBalances(address);
|
|
490
|
+
const [account, assetBalances] = await Promise.all([accountReq, assetBalancesReq]);
|
|
491
|
+
const assets = [];
|
|
492
|
+
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
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (assetBalances) {
|
|
503
|
+
for (const [assetId, assetBalance] of Object.entries(assetBalances)) {
|
|
504
|
+
if (assetBalance.balance) {
|
|
505
|
+
const amount = BigInt(assetBalance.balance);
|
|
506
|
+
if (amount > 0) {
|
|
507
|
+
assets.push({
|
|
508
|
+
chain: this.chain.name,
|
|
509
|
+
identifier: assetId,
|
|
510
|
+
name: assetBalance.name || assetId,
|
|
511
|
+
decimals: assetBalance.decimals || 6,
|
|
512
|
+
amount,
|
|
513
|
+
logoUrl: assetBalance.logo_url
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return assets;
|
|
520
|
+
}
|
|
521
|
+
async getAccountActions(address, options) {
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
async getAccountInfo(address) {
|
|
525
|
+
const accountInfo = await this.client.getAccountInfo(address);
|
|
526
|
+
if (!accountInfo) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
const balanceDecimal = parseInt(accountInfo.balance, 16);
|
|
530
|
+
return {
|
|
531
|
+
address,
|
|
532
|
+
balance: accountInfo.balance,
|
|
533
|
+
balanceDecimal,
|
|
534
|
+
nextNonce: accountInfo.next_nonce,
|
|
535
|
+
sequenceNumber: accountInfo.sequence_number
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
async getTransactionInfo(txHash) {
|
|
539
|
+
return {
|
|
540
|
+
hash: txHash,
|
|
541
|
+
hashHex: txHash.startsWith("0x") ? txHash.slice(2) : txHash,
|
|
542
|
+
status: "submitted",
|
|
543
|
+
details: {
|
|
544
|
+
hash: txHash,
|
|
545
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
async checkTransferStatus(fromAddress, toAddress, amount) {
|
|
550
|
+
const fromAccount = await this.getAccountInfo(fromAddress);
|
|
551
|
+
const toAccount = await this.getAccountInfo(toAddress);
|
|
552
|
+
if (!fromAccount || !toAccount) {
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
const transferAmount = parseInt(amount);
|
|
556
|
+
const fromBalance = fromAccount.balanceDecimal;
|
|
557
|
+
return fromBalance < transferAmount;
|
|
558
|
+
}
|
|
559
|
+
async getAccountBalance(address) {
|
|
560
|
+
const accountInfo = await this.getAccountInfo(address);
|
|
561
|
+
if (!accountInfo) {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
balance: accountInfo.balance,
|
|
566
|
+
balanceDecimal: accountInfo.balanceDecimal
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
async getAssetBalance(address, assetId) {
|
|
570
|
+
const assetBalance = await this.client.getAssetBalance(address, assetId);
|
|
571
|
+
if (!assetBalance || !assetBalance.balance) {
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
const amount = BigInt(assetBalance.balance);
|
|
575
|
+
if (amount === 0n) {
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
chain: this.chain.name,
|
|
580
|
+
identifier: assetId,
|
|
581
|
+
name: assetBalance.name || assetId,
|
|
582
|
+
decimals: assetBalance.decimals || 6,
|
|
583
|
+
amount,
|
|
584
|
+
logoUrl: assetBalance.logo_url
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// src/WarpFastsetExecutor.ts
|
|
590
|
+
var import_warps2 = require("@vleap/warps");
|
|
591
|
+
|
|
592
|
+
// src/WarpFastsetSerializer.ts
|
|
593
|
+
var import_warps = require("@vleap/warps");
|
|
594
|
+
var WarpFastsetSerializer = class {
|
|
595
|
+
constructor() {
|
|
596
|
+
this.coreSerializer = new import_warps.WarpSerializer();
|
|
597
|
+
}
|
|
598
|
+
typedToString(value) {
|
|
599
|
+
if (typeof value === "string") {
|
|
600
|
+
return `string:${value}`;
|
|
601
|
+
}
|
|
602
|
+
if (typeof value === "number") {
|
|
603
|
+
return `number:${value}`;
|
|
604
|
+
}
|
|
605
|
+
if (typeof value === "boolean") {
|
|
606
|
+
return `boolean:${value}`;
|
|
607
|
+
}
|
|
608
|
+
if (typeof value === "bigint") {
|
|
609
|
+
return `biguint:${value.toString()}`;
|
|
610
|
+
}
|
|
611
|
+
if (Array.isArray(value)) {
|
|
612
|
+
const items = value.map((item) => this.typedToString(item)).join(",");
|
|
613
|
+
return `array:${items}`;
|
|
614
|
+
}
|
|
615
|
+
if (value === null) {
|
|
616
|
+
return "null:null";
|
|
617
|
+
}
|
|
618
|
+
if (value === void 0) {
|
|
619
|
+
return "undefined:undefined";
|
|
620
|
+
}
|
|
621
|
+
return `string:${String(value)}`;
|
|
622
|
+
}
|
|
623
|
+
typedToNative(value) {
|
|
624
|
+
if (typeof value === "string") {
|
|
625
|
+
return ["string", value];
|
|
626
|
+
}
|
|
627
|
+
if (typeof value === "number") {
|
|
628
|
+
return ["number", value];
|
|
629
|
+
}
|
|
630
|
+
if (typeof value === "boolean") {
|
|
631
|
+
return ["boolean", value];
|
|
632
|
+
}
|
|
633
|
+
if (typeof value === "bigint") {
|
|
634
|
+
return ["biguint", value.toString()];
|
|
635
|
+
}
|
|
636
|
+
return ["string", String(value)];
|
|
637
|
+
}
|
|
638
|
+
nativeToTyped(type, value) {
|
|
639
|
+
switch (type) {
|
|
640
|
+
case "string":
|
|
641
|
+
return String(value);
|
|
642
|
+
case "number":
|
|
643
|
+
return Number(value);
|
|
644
|
+
case "boolean":
|
|
645
|
+
return Boolean(value);
|
|
646
|
+
case "biguint":
|
|
647
|
+
return BigInt(value);
|
|
648
|
+
case "address":
|
|
649
|
+
return String(value);
|
|
650
|
+
case "hex":
|
|
651
|
+
return String(value);
|
|
652
|
+
default:
|
|
653
|
+
return String(value);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
nativeToType(type) {
|
|
657
|
+
switch (type) {
|
|
658
|
+
case "string":
|
|
659
|
+
return "string";
|
|
660
|
+
case "number":
|
|
661
|
+
return "number";
|
|
662
|
+
case "boolean":
|
|
663
|
+
return "boolean";
|
|
664
|
+
case "biguint":
|
|
665
|
+
return "biguint";
|
|
666
|
+
case "address":
|
|
667
|
+
return "address";
|
|
668
|
+
case "hex":
|
|
669
|
+
return "hex";
|
|
670
|
+
default:
|
|
671
|
+
return "string";
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
stringToTyped(value) {
|
|
675
|
+
const colonIndex = value.indexOf(":");
|
|
676
|
+
if (colonIndex === -1) {
|
|
677
|
+
return value;
|
|
678
|
+
}
|
|
679
|
+
const type = value.substring(0, colonIndex);
|
|
680
|
+
const stringValue = value.substring(colonIndex + 1);
|
|
681
|
+
switch (type) {
|
|
682
|
+
case "string":
|
|
683
|
+
return stringValue;
|
|
684
|
+
case "number":
|
|
685
|
+
return Number(stringValue);
|
|
686
|
+
case "boolean":
|
|
687
|
+
return stringValue === "true";
|
|
688
|
+
case "biguint":
|
|
689
|
+
return BigInt(stringValue);
|
|
690
|
+
case "array":
|
|
691
|
+
return stringValue.split(",").map((item) => this.stringToTyped(item));
|
|
692
|
+
case "null":
|
|
693
|
+
return null;
|
|
694
|
+
case "undefined":
|
|
695
|
+
return void 0;
|
|
696
|
+
default:
|
|
697
|
+
return stringValue;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/WarpFastsetExecutor.ts
|
|
703
|
+
var WarpFastsetExecutor = class {
|
|
704
|
+
constructor(config, chain) {
|
|
705
|
+
this.config = config;
|
|
706
|
+
this.chain = chain;
|
|
707
|
+
this.serializer = new WarpFastsetSerializer();
|
|
708
|
+
const validatorUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
709
|
+
const proxyUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
710
|
+
this.fastsetClient = new FastsetClient({
|
|
711
|
+
validatorUrl,
|
|
712
|
+
proxyUrl
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
async createTransaction(executable) {
|
|
716
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
717
|
+
switch (action.type) {
|
|
718
|
+
case "transfer":
|
|
719
|
+
return this.createTransferTransaction(executable);
|
|
720
|
+
case "contract":
|
|
721
|
+
return this.createContractCallTransaction(executable);
|
|
722
|
+
case "query":
|
|
723
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
724
|
+
case "collect":
|
|
725
|
+
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
726
|
+
default:
|
|
727
|
+
throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
async createTransferTransaction(executable) {
|
|
731
|
+
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
732
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
733
|
+
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
734
|
+
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
735
|
+
}
|
|
736
|
+
if (executable.value < 0) {
|
|
737
|
+
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
738
|
+
}
|
|
739
|
+
const recipientAddress = this.fromBase64(executable.destination);
|
|
740
|
+
const amount = this.normalizeAmount(executable.value.toString());
|
|
741
|
+
const userData = executable.data ? this.fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
|
|
742
|
+
return {
|
|
743
|
+
type: "fastset-transfer",
|
|
744
|
+
recipient: recipientAddress,
|
|
745
|
+
amount,
|
|
746
|
+
userData,
|
|
747
|
+
chain: executable.chain
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
async createContractCallTransaction(executable) {
|
|
751
|
+
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
752
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
753
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
754
|
+
if (!action || !("func" in action) || !action.func) {
|
|
755
|
+
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
756
|
+
}
|
|
757
|
+
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
758
|
+
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
759
|
+
}
|
|
760
|
+
if (executable.value < 0) {
|
|
761
|
+
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
const contractAddress = this.fromBase64(executable.destination);
|
|
765
|
+
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
766
|
+
return {
|
|
767
|
+
type: "fastset-contract-call",
|
|
768
|
+
contract: contractAddress,
|
|
769
|
+
function: action.func,
|
|
770
|
+
data: encodedData,
|
|
771
|
+
value: executable.value,
|
|
772
|
+
chain: executable.chain
|
|
773
|
+
};
|
|
774
|
+
} catch (error) {
|
|
775
|
+
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
async executeQuery(executable) {
|
|
779
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
780
|
+
if (action.type !== "query") {
|
|
781
|
+
throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
782
|
+
}
|
|
783
|
+
if (!action.func) {
|
|
784
|
+
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
785
|
+
}
|
|
786
|
+
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
787
|
+
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
788
|
+
}
|
|
789
|
+
try {
|
|
790
|
+
const contractAddress = this.fromBase64(executable.destination);
|
|
791
|
+
const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
|
|
792
|
+
return {
|
|
793
|
+
success: true,
|
|
794
|
+
result,
|
|
795
|
+
chain: executable.chain
|
|
796
|
+
};
|
|
797
|
+
} catch (error) {
|
|
798
|
+
return {
|
|
799
|
+
success: false,
|
|
800
|
+
error: error instanceof Error ? error.message : String(error),
|
|
801
|
+
chain: executable.chain
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
async preprocessInput(chain, input, type, value) {
|
|
806
|
+
return value;
|
|
807
|
+
}
|
|
808
|
+
async signMessage(message, privateKey) {
|
|
809
|
+
throw new Error("Not implemented");
|
|
810
|
+
}
|
|
811
|
+
async executeTransfer(executable) {
|
|
812
|
+
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
813
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
814
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
815
|
+
return {
|
|
816
|
+
success: true,
|
|
817
|
+
transaction,
|
|
818
|
+
chain: executable.chain.name,
|
|
819
|
+
message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
async executeTransferWithKey(executable, privateKey) {
|
|
823
|
+
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
824
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
825
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
826
|
+
const privateKeyBytes = this.fromBase64(privateKey);
|
|
827
|
+
const transactionHash = await this.fastsetClient.executeTransfer(
|
|
828
|
+
privateKeyBytes,
|
|
829
|
+
transaction.recipient,
|
|
830
|
+
transaction.amount,
|
|
831
|
+
transaction.userData
|
|
832
|
+
);
|
|
833
|
+
return {
|
|
834
|
+
success: true,
|
|
835
|
+
transactionHash: Array.from(transactionHash),
|
|
836
|
+
chain: executable.chain.name
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
encodeFunctionData(functionName, args) {
|
|
840
|
+
return JSON.stringify({
|
|
841
|
+
function: functionName,
|
|
842
|
+
arguments: args
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
async executeFastsetQuery(contractAddress, functionName, args) {
|
|
846
|
+
const validatorUrl = (0, import_warps2.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
847
|
+
const response = await fetch(`${validatorUrl}/query`, {
|
|
848
|
+
method: "POST",
|
|
849
|
+
headers: {
|
|
850
|
+
"Content-Type": "application/json"
|
|
851
|
+
},
|
|
852
|
+
body: JSON.stringify({
|
|
853
|
+
contract: Array.from(contractAddress),
|
|
854
|
+
function: functionName,
|
|
855
|
+
arguments: args
|
|
856
|
+
})
|
|
857
|
+
});
|
|
858
|
+
if (!response.ok) {
|
|
859
|
+
throw new Error(`Fastset query failed: ${response.statusText}`);
|
|
860
|
+
}
|
|
861
|
+
return response.json();
|
|
862
|
+
}
|
|
863
|
+
isValidFastsetAddress(address) {
|
|
864
|
+
if (typeof address !== "string" || address.length === 0) {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
if (address.startsWith("fs") || address.startsWith("pi")) {
|
|
868
|
+
return true;
|
|
869
|
+
}
|
|
870
|
+
try {
|
|
871
|
+
const decoded = this.fromBase64(address);
|
|
872
|
+
return decoded.length === 32;
|
|
873
|
+
} catch {
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
fromBase64(base64) {
|
|
878
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
879
|
+
}
|
|
880
|
+
normalizeAmount(amount) {
|
|
881
|
+
return amount.startsWith("0x") ? amount.slice(2) : amount;
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// src/WarpFastsetExplorer.ts
|
|
886
|
+
var WarpFastsetExplorer = class {
|
|
887
|
+
constructor(_chainInfo, _config) {
|
|
888
|
+
this._chainInfo = _chainInfo;
|
|
889
|
+
this._config = _config;
|
|
890
|
+
this.explorerUrl = "https://explorer.fastset.xyz";
|
|
891
|
+
}
|
|
892
|
+
getAccountUrl(address) {
|
|
893
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
894
|
+
}
|
|
895
|
+
getTransactionUrl(hash) {
|
|
896
|
+
return `${this.explorerUrl}/transaction/${hash}`;
|
|
897
|
+
}
|
|
898
|
+
getAssetUrl(identifier) {
|
|
899
|
+
return `${this.explorerUrl}/asset/${identifier}`;
|
|
900
|
+
}
|
|
901
|
+
getContractUrl(address) {
|
|
902
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// src/WarpFastsetResults.ts
|
|
907
|
+
var import_warps3 = require("@vleap/warps");
|
|
908
|
+
var WarpFastsetResults = class {
|
|
909
|
+
constructor(config, chain) {
|
|
910
|
+
this.config = config;
|
|
911
|
+
this.chain = chain;
|
|
912
|
+
this.serializer = new WarpFastsetSerializer();
|
|
913
|
+
}
|
|
914
|
+
async getTransactionExecutionResults(warp, tx) {
|
|
915
|
+
const success = this.isTransactionSuccessful(tx);
|
|
916
|
+
const transactionHash = this.extractTransactionHash(tx);
|
|
917
|
+
const blockNumber = this.extractBlockNumber(tx);
|
|
918
|
+
const timestamp = this.extractTimestamp(tx);
|
|
919
|
+
return {
|
|
920
|
+
success,
|
|
921
|
+
warp,
|
|
922
|
+
action: 0,
|
|
923
|
+
user: this.config.user?.wallets?.[this.chain.name] || null,
|
|
924
|
+
txHash: transactionHash,
|
|
925
|
+
tx,
|
|
926
|
+
next: null,
|
|
927
|
+
values: [transactionHash, blockNumber, timestamp],
|
|
928
|
+
valuesRaw: [transactionHash, blockNumber, timestamp],
|
|
929
|
+
results: {},
|
|
930
|
+
messages: {}
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
async extractQueryResults(warp, typedValues, actionIndex, inputs) {
|
|
934
|
+
const values = typedValues.map((t) => this.serializer.typedToString(t));
|
|
935
|
+
const valuesRaw = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
|
|
936
|
+
let results = {};
|
|
937
|
+
if (!warp.results) return { values, results };
|
|
938
|
+
const getNestedValue = (path) => {
|
|
939
|
+
const match = path.match(/^out\[(\d+)\]$/);
|
|
940
|
+
if (match) {
|
|
941
|
+
const index = parseInt(match[1]) - 1;
|
|
942
|
+
return valuesRaw[index];
|
|
943
|
+
}
|
|
944
|
+
const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
|
|
945
|
+
if (indices.length === 0) return void 0;
|
|
946
|
+
let value = valuesRaw[indices[0]];
|
|
947
|
+
for (let i = 1; i < indices.length; i++) {
|
|
948
|
+
if (value === void 0 || value === null) return void 0;
|
|
949
|
+
value = value[indices[i]];
|
|
950
|
+
}
|
|
951
|
+
return value;
|
|
952
|
+
};
|
|
953
|
+
for (const [key, path] of Object.entries(warp.results)) {
|
|
954
|
+
if (path.startsWith(import_warps3.WarpConstants.Transform.Prefix)) continue;
|
|
955
|
+
const currentActionIndex = (0, import_warps3.parseResultsOutIndex)(path);
|
|
956
|
+
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
957
|
+
results[key] = null;
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
|
|
961
|
+
const value = getNestedValue(path);
|
|
962
|
+
results[key] = value || null;
|
|
963
|
+
} else {
|
|
964
|
+
results[key] = path;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return { values, results: await (0, import_warps3.evaluateResultsCommon)(warp, results, actionIndex, inputs, this.config.transform?.runner) };
|
|
968
|
+
}
|
|
969
|
+
isTransactionSuccessful(tx) {
|
|
970
|
+
if (!tx) return false;
|
|
971
|
+
if (tx.success === false) return false;
|
|
972
|
+
if (tx.success === true) return true;
|
|
973
|
+
if (tx.status === "success") return true;
|
|
974
|
+
if (tx.status === 1) return true;
|
|
975
|
+
if (tx.result && tx.result.success === true) return true;
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
extractTransactionHash(tx) {
|
|
979
|
+
if (!tx) return "";
|
|
980
|
+
return tx.transaction_hash || tx.transactionHash || tx.hash || tx.result && tx.result.transaction_hash || "";
|
|
981
|
+
}
|
|
982
|
+
extractBlockNumber(tx) {
|
|
983
|
+
if (!tx) return "0";
|
|
984
|
+
return tx.block_number?.toString() || tx.blockNumber?.toString() || tx.result && tx.result.block_number?.toString() || "0";
|
|
985
|
+
}
|
|
986
|
+
extractTimestamp(tx) {
|
|
987
|
+
if (!tx) return "0";
|
|
988
|
+
return tx.timestamp?.toString() || tx.timestamp_nanos?.toString() || tx.result && tx.result.timestamp?.toString() || Date.now().toString();
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
// src/main.ts
|
|
993
|
+
var NativeTokenSet = {
|
|
994
|
+
chain: import_warps4.WarpChainName.Fastset,
|
|
995
|
+
identifier: "SET",
|
|
996
|
+
name: "SET",
|
|
997
|
+
decimals: 6,
|
|
998
|
+
logoUrl: "https://vleap.ai/images/tokens/set.svg"
|
|
999
|
+
};
|
|
1000
|
+
function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
|
|
1001
|
+
return (config, fallback) => {
|
|
1002
|
+
const chainInfo = chainInfos[config.env];
|
|
1003
|
+
if (!chainInfo) throw new Error(`FastsetAdapter: chain info not found for chain ${chainName}`);
|
|
1004
|
+
if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
|
|
1005
|
+
return {
|
|
1006
|
+
chain: chainName,
|
|
1007
|
+
chainInfo,
|
|
1008
|
+
prefix: chainPrefix,
|
|
1009
|
+
builder: () => fallback.builder(),
|
|
1010
|
+
executor: new WarpFastsetExecutor(config, chainInfo),
|
|
1011
|
+
results: new WarpFastsetResults(config, chainInfo),
|
|
1012
|
+
serializer: new WarpFastsetSerializer(),
|
|
1013
|
+
registry: fallback.registry,
|
|
1014
|
+
explorer: new WarpFastsetExplorer(chainInfo, config),
|
|
1015
|
+
abiBuilder: () => fallback.abiBuilder(),
|
|
1016
|
+
brandBuilder: () => fallback.brandBuilder(),
|
|
1017
|
+
dataLoader: new WarpFastsetDataLoader(config, chainInfo)
|
|
1018
|
+
};
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
var getFastsetAdapter = createFastsetAdapter(import_warps4.WarpChainName.Fastset, "fastset", {
|
|
1022
|
+
mainnet: {
|
|
1023
|
+
name: import_warps4.WarpChainName.Fastset,
|
|
1024
|
+
displayName: "FastSet",
|
|
1025
|
+
chainId: "1",
|
|
1026
|
+
blockTime: 1e3,
|
|
1027
|
+
addressHrp: "set",
|
|
1028
|
+
defaultApiUrl: "https://rpc.fastset.xyz",
|
|
1029
|
+
nativeToken: NativeTokenSet
|
|
1030
|
+
},
|
|
1031
|
+
testnet: {
|
|
1032
|
+
name: import_warps4.WarpChainName.Fastset,
|
|
1033
|
+
displayName: "FastSet Testnet",
|
|
1034
|
+
chainId: "testnet",
|
|
1035
|
+
blockTime: 1e3,
|
|
1036
|
+
addressHrp: "set",
|
|
1037
|
+
defaultApiUrl: "https://rpc.fastset.xyz",
|
|
1038
|
+
nativeToken: NativeTokenSet
|
|
1039
|
+
},
|
|
1040
|
+
devnet: {
|
|
1041
|
+
name: import_warps4.WarpChainName.Fastset,
|
|
1042
|
+
displayName: "FastSet Devnet",
|
|
1043
|
+
chainId: "devnet",
|
|
1044
|
+
blockTime: 1e3,
|
|
1045
|
+
addressHrp: "set",
|
|
1046
|
+
defaultApiUrl: "https://rpc.fastset.xyz",
|
|
1047
|
+
nativeToken: NativeTokenSet
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1050
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1051
|
+
0 && (module.exports = {
|
|
1052
|
+
Address,
|
|
1053
|
+
Amount,
|
|
1054
|
+
BcsTransaction,
|
|
1055
|
+
Bytes32,
|
|
1056
|
+
Claim,
|
|
1057
|
+
ClaimType,
|
|
1058
|
+
FastsetClient,
|
|
1059
|
+
NativeTokenSet,
|
|
1060
|
+
Nonce,
|
|
1061
|
+
PublicKey,
|
|
1062
|
+
Transaction,
|
|
1063
|
+
Transfer,
|
|
1064
|
+
TransferClaim,
|
|
1065
|
+
UserData,
|
|
1066
|
+
Wallet,
|
|
1067
|
+
WarpFastsetConstants,
|
|
1068
|
+
WarpFastsetDataLoader,
|
|
1069
|
+
WarpFastsetExecutor,
|
|
1070
|
+
WarpFastsetExplorer,
|
|
1071
|
+
WarpFastsetResults,
|
|
1072
|
+
WarpFastsetSerializer,
|
|
1073
|
+
getFastsetAdapter
|
|
1074
|
+
});
|
|
1075
|
+
//# sourceMappingURL=index.js.map
|