@vleap/warps-adapter-fastset 0.1.0-alpha.2 → 0.1.0-alpha.20

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.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,13 +17,23 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
23
- WarpFastsetBuilder: () => WarpFastsetBuilder,
33
+ FastsetClient: () => FastsetClient,
34
+ NativeTokenSet: () => NativeTokenSet,
24
35
  WarpFastsetConstants: () => WarpFastsetConstants,
36
+ WarpFastsetDataLoader: () => WarpFastsetDataLoader,
25
37
  WarpFastsetExecutor: () => WarpFastsetExecutor,
26
38
  WarpFastsetExplorer: () => WarpFastsetExplorer,
27
39
  WarpFastsetResults: () => WarpFastsetResults,
@@ -32,226 +44,353 @@ module.exports = __toCommonJS(index_exports);
32
44
 
33
45
  // src/constants.ts
34
46
  var WarpFastsetConstants = {
35
- ChainName: "fastset",
36
- ChainPrefix: "fastset",
37
- Pi: {
38
- Identifier: "PI",
39
- DisplayName: "Pi",
40
- Decimals: 18
41
- },
42
- GasLimit: {
43
- Default: 21e3,
44
- ContractCall: 1e5,
45
- ContractDeploy: 5e5,
46
- Transfer: 21e3,
47
- Approve: 46e3,
48
- Swap: 2e5
49
- },
50
- GasPrice: {
51
- Default: "20000000000",
52
- // 20 gwei
53
- Low: "10000000000",
54
- // 10 gwei
55
- Medium: "20000000000",
56
- // 20 gwei
57
- High: "50000000000"
58
- // 50 gwei
59
- },
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
- Validation: {
78
- AddressLength: 42,
79
- HexPrefix: "0x",
80
- MinGasLimit: 21e3,
81
- MaxGasLimit: 3e7
82
- },
83
- Timeouts: {
84
- DefaultRpcTimeout: 3e4,
85
- // 30 seconds
86
- GasEstimationTimeout: 1e4,
87
- // 10 seconds
88
- QueryTimeout: 15e3
89
- // 15 seconds
90
- }
47
+ // Placeholder for future FastSet-specific constants
91
48
  };
92
49
 
93
- // src/WarpFastsetBuilder.ts
94
- var WarpFastsetBuilder = class {
95
- constructor(config) {
96
- this.config = config;
97
- this.warp = {};
98
- this.actions = [];
99
- }
100
- async createFromRaw(encoded) {
101
- try {
102
- const parsed = JSON.parse(encoded);
103
- this.warp = parsed;
104
- this.actions = parsed.actions || [];
105
- return this.build();
106
- } catch (error) {
107
- throw new Error(`Failed to parse Fastset warp data: ${error}`);
50
+ // src/main.ts
51
+ var import_warps4 = require("@vleap/warps");
52
+
53
+ // src/WarpFastsetDataLoader.ts
54
+ var bech323 = __toESM(require("bech32"), 1);
55
+
56
+ // src/sdk/FastsetClient.ts
57
+ var import_bcs = require("@mysten/bcs");
58
+ var bech32 = __toESM(require("bech32"), 1);
59
+ var bcsTransaction = import_bcs.bcs.struct("Transaction", {
60
+ sender: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
61
+ recipient: import_bcs.bcs.enum("Address", {
62
+ External: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
63
+ FastSet: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
64
+ }),
65
+ nonce: import_bcs.bcs.u64(),
66
+ timestamp_nanos: import_bcs.bcs.u128(),
67
+ claim: import_bcs.bcs.enum("ClaimType", {
68
+ Transfer: import_bcs.bcs.struct("Transfer", {
69
+ recipient: import_bcs.bcs.enum("Address", {
70
+ External: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
71
+ FastSet: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
72
+ }),
73
+ amount: import_bcs.bcs.string(),
74
+ user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
75
+ }),
76
+ TokenTransfer: import_bcs.bcs.struct("TokenTransfer", {
77
+ token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
78
+ amount: import_bcs.bcs.string(),
79
+ user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
80
+ }),
81
+ TokenCreation: import_bcs.bcs.struct("TokenCreation", {
82
+ token_name: import_bcs.bcs.string(),
83
+ decimals: import_bcs.bcs.u8(),
84
+ initial_amount: import_bcs.bcs.string(),
85
+ mints: import_bcs.bcs.vector(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
86
+ user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
87
+ }),
88
+ TokenManagement: import_bcs.bcs.struct("TokenManagement", {
89
+ token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
90
+ update_id: import_bcs.bcs.u64(),
91
+ new_admin: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
92
+ mints: import_bcs.bcs.vector(
93
+ import_bcs.bcs.tuple([
94
+ import_bcs.bcs.enum("AddressChange", {
95
+ Add: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
96
+ Remove: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
97
+ }),
98
+ import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
99
+ ])
100
+ ),
101
+ user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
102
+ }),
103
+ Mint: import_bcs.bcs.struct("Mint", {
104
+ token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
105
+ amount: import_bcs.bcs.string()
106
+ }),
107
+ ExternalClaim: import_bcs.bcs.struct("ExternalClaim", {
108
+ claim: import_bcs.bcs.struct("ExternalClaimBody", {
109
+ verifier_committee: import_bcs.bcs.vector(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
110
+ verifier_quorum: import_bcs.bcs.u64(),
111
+ claim_data: import_bcs.bcs.vector(import_bcs.bcs.u8())
112
+ }),
113
+ signatures: import_bcs.bcs.vector(import_bcs.bcs.tuple([import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()), import_bcs.bcs.fixedArray(64, import_bcs.bcs.u8())]))
114
+ })
115
+ })
116
+ });
117
+ var FastsetClient = class {
118
+ constructor(config, chain) {
119
+ if (config && "proxyUrl" in config) {
120
+ this.apiUrl = config.proxyUrl;
121
+ } else if (config && chain) {
122
+ this.apiUrl = chain.defaultApiUrl;
123
+ } else {
124
+ this.apiUrl = "https://rpc.fastset.xyz";
125
+ }
126
+ }
127
+ async makeRequest(method, params = {}) {
128
+ const response = await fetch(this.apiUrl, {
129
+ method: "POST",
130
+ headers: {
131
+ "Content-Type": "application/json"
132
+ },
133
+ body: JSON.stringify({
134
+ jsonrpc: "2.0",
135
+ method,
136
+ params,
137
+ id: Date.now()
138
+ })
139
+ });
140
+ if (!response.ok) {
141
+ throw new Error(`HTTP error! status: ${response.status}`);
108
142
  }
143
+ const jsonResponse = await response.json();
144
+ if (jsonResponse.error) {
145
+ throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
146
+ }
147
+ return jsonResponse.result;
109
148
  }
110
- setTitle(title) {
111
- this.warp.title = title;
112
- return this;
149
+ async getAccountInfo(address, token_balance_filter, certificate_by_nonce) {
150
+ return this.makeRequest("set_getAccountInfo", {
151
+ address,
152
+ token_balance_filter,
153
+ certificate_by_nonce
154
+ });
113
155
  }
114
- setDescription(description) {
115
- this.warp.description = description;
116
- return this;
156
+ async getTokenInfo(token_ids) {
157
+ return this.makeRequest("set_getTokenInfo", {
158
+ token_ids
159
+ });
117
160
  }
118
- setPreview(preview) {
119
- this.warp.preview = preview;
120
- return this;
161
+ async getTransfers(page) {
162
+ return this.makeRequest("set_getTransfers", { page });
121
163
  }
122
- setActions(actions) {
123
- this.actions = actions;
124
- return this;
164
+ async getClaims(confirmed, page) {
165
+ return this.makeRequest("set_getClaims", { confirmed, page });
125
166
  }
126
- addAction(action) {
127
- this.actions.push(action);
128
- return this;
167
+ async getClaimsByAddress(address, page) {
168
+ return this.makeRequest("set_getClaimsByAddress", {
169
+ address,
170
+ page
171
+ });
129
172
  }
130
- async build() {
131
- return {
132
- protocol: "warp",
133
- name: this.warp.name || "fastset-warp",
134
- title: this.warp.title || "",
135
- description: this.warp.description || null,
136
- preview: this.warp.preview || null,
137
- actions: this.actions,
138
- meta: {
139
- chain: "fastset",
140
- hash: this.generateHash(this.warp.title || ""),
141
- creator: this.config.user?.wallets?.fastset || "",
142
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
143
- }
144
- };
173
+ async getNextNonce(address) {
174
+ if (typeof address === "string") {
175
+ const addressBytes = this.addressToBytes(address);
176
+ const accountInfo2 = await this.getAccountInfo(addressBytes);
177
+ return accountInfo2.next_nonce;
178
+ }
179
+ const accountInfo = await this.getAccountInfo(address);
180
+ return accountInfo.next_nonce;
145
181
  }
146
- createInscriptionTransaction(warp) {
147
- return {
148
- type: "fastset-inscription",
149
- data: JSON.stringify(warp)
150
- // TODO: Add Fastset-specific transaction fields
151
- };
182
+ async submitTransaction(transaction, signature) {
183
+ const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
184
+ return this.makeRequest("set_submitTransaction", {
185
+ transaction,
186
+ signature: signatureArray
187
+ });
152
188
  }
153
- async createFromTransaction(tx, validate = true) {
189
+ addressToBytes(address) {
154
190
  try {
155
- const warpData = tx.data || tx.payload || tx.content;
156
- if (!warpData) {
157
- throw new Error("No warp data found in transaction");
191
+ const decoded = bech32.bech32m.decode(address);
192
+ return Array.from(bech32.bech32m.fromWords(decoded.words));
193
+ } catch {
194
+ try {
195
+ const decoded = bech32.bech32.decode(address);
196
+ return Array.from(bech32.bech32.fromWords(decoded.words));
197
+ } catch {
198
+ throw new Error(`Invalid FastSet address: ${address}`);
158
199
  }
159
- const parsed = typeof warpData === "string" ? JSON.parse(warpData) : warpData;
160
- if (validate) {
161
- this.validateWarp(parsed);
162
- }
163
- return parsed;
164
- } catch (error) {
165
- throw new Error(`Failed to create warp from Fastset transaction: ${error}`);
166
200
  }
167
201
  }
168
- async createFromTransactionHash(hash, cache) {
202
+ };
203
+
204
+ // src/WarpFastsetDataLoader.ts
205
+ var WarpFastsetDataLoader = class {
206
+ constructor(config, chain) {
207
+ this.config = config;
208
+ this.chain = chain;
209
+ this.client = new FastsetClient(config, chain);
210
+ }
211
+ addressToBytes(address) {
169
212
  try {
170
- const tx = await this.fetchTransaction(hash);
171
- if (!tx) {
172
- return null;
213
+ const decoded = bech323.bech32m.decode(address);
214
+ return Array.from(bech323.bech32m.fromWords(decoded.words));
215
+ } catch {
216
+ try {
217
+ const decoded = bech323.bech32.decode(address);
218
+ return Array.from(bech323.bech32.fromWords(decoded.words));
219
+ } catch {
220
+ throw new Error(`Invalid FastSet address: ${address}`);
173
221
  }
174
- return this.createFromTransaction(tx);
175
- } catch (error) {
176
- console.error(`Failed to create warp from Fastset transaction hash: ${error}`);
177
- return null;
178
- }
179
- }
180
- generateHash(data) {
181
- let hash = 0;
182
- for (let i = 0; i < data.length; i++) {
183
- const char = data.charCodeAt(i);
184
- hash = (hash << 5) - hash + char;
185
- hash = hash & hash;
186
222
  }
187
- return hash.toString(16);
188
223
  }
189
- validateWarp(warp) {
190
- if (!warp.title) {
191
- throw new Error("Warp must have a title");
192
- }
193
- if (!warp.actions || !Array.isArray(warp.actions)) {
194
- throw new Error("Warp must have actions array");
224
+ async getAccount(address) {
225
+ const addressBytes = this.addressToBytes(address);
226
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
227
+ return { chain: this.chain.name, address, balance: BigInt(accountInfo.balance) };
228
+ }
229
+ async getAccountAssets(address) {
230
+ const addressBytes = this.addressToBytes(address);
231
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
232
+ const assets = [];
233
+ const balance = BigInt(accountInfo.balance);
234
+ if (balance > 0n) {
235
+ assets.push({ ...this.chain.nativeToken, amount: balance });
236
+ }
237
+ for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
238
+ const amount = BigInt(tokenBalance);
239
+ if (amount > 0n) {
240
+ const tokenInfo = await this.client.getTokenInfo([tokenId]);
241
+ const metadata = tokenInfo.requested_token_metadata[0]?.[1];
242
+ assets.push({
243
+ chain: this.chain.name,
244
+ identifier: Buffer.from(tokenId).toString("hex"),
245
+ symbol: metadata?.token_name || "UNKNOWN",
246
+ name: metadata?.token_name || "Unknown Token",
247
+ decimals: metadata?.decimals || 6,
248
+ logoUrl: void 0,
249
+ amount
250
+ });
251
+ }
195
252
  }
253
+ return assets;
196
254
  }
197
- async fetchTransaction(hash) {
198
- const response = await fetch(`${this.getApiUrl()}/transaction/${hash}`);
199
- if (!response.ok) {
255
+ async getAsset(identifier) {
256
+ const tokenId = Buffer.from(identifier, "hex");
257
+ const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
258
+ const metadata = tokenInfo.requested_token_metadata[0]?.[1];
259
+ if (!metadata) {
200
260
  return null;
201
261
  }
202
- return response.json();
262
+ return {
263
+ chain: this.chain.name,
264
+ identifier,
265
+ symbol: metadata.token_name,
266
+ name: metadata.token_name,
267
+ decimals: metadata.decimals,
268
+ logoUrl: void 0,
269
+ amount: BigInt(metadata.total_supply)
270
+ };
271
+ }
272
+ async getAction(identifier, awaitCompleted = false) {
273
+ return null;
203
274
  }
204
- getApiUrl() {
205
- return "https://api.fastset.xyz";
275
+ async getAccountActions(address, options) {
276
+ return [];
206
277
  }
207
278
  };
208
279
 
209
280
  // src/WarpFastsetExecutor.ts
281
+ var ed25519 = __toESM(require("@noble/ed25519"), 1);
210
282
  var import_warps2 = require("@vleap/warps");
211
283
 
212
- // src/config.ts
213
- var FASTSET_CHAIN_CONFIGS = {
214
- fastset: {
215
- mainnet: {
216
- apiUrl: "https://mainnet.fastset.com/api",
217
- explorerUrl: "https://explorer.fastset.com",
218
- chainId: "1",
219
- registryAddress: "0x0000000000000000000000000000000000000000",
220
- nativeToken: "PI",
221
- blockTime: 12
222
- },
223
- testnet: {
224
- apiUrl: "https://testnet.fastset.com/api",
225
- explorerUrl: "https://testnet-explorer.fastset.com",
226
- chainId: "11155111",
227
- registryAddress: "0x0000000000000000000000000000000000000000",
228
- nativeToken: "PI",
229
- blockTime: 12
230
- },
231
- devnet: {
232
- apiUrl: "http://localhost:8545",
233
- explorerUrl: "http://localhost:4000",
234
- chainId: "1337",
235
- registryAddress: "0x0000000000000000000000000000000000000000",
236
- nativeToken: "PI",
237
- blockTime: 12
238
- }
284
+ // src/sdk/Wallet.ts
285
+ var bech325 = __toESM(require("bech32"), 1);
286
+
287
+ // src/sdk/ed25519-setup.ts
288
+ var ed = __toESM(require("@noble/ed25519"), 1);
289
+ var import_sha512 = require("@noble/hashes/sha512");
290
+ if (ed.etc) {
291
+ ed.etc.sha512Sync = (...m) => (0, import_sha512.sha512)(ed.etc.concatBytes(...m));
292
+ }
293
+
294
+ // src/sdk/Transaction.ts
295
+ var Transaction = class _Transaction {
296
+ constructor(sender, recipient, nonce, claim, options = {}) {
297
+ this.sender = sender;
298
+ this.recipient = recipient;
299
+ this.nonce = nonce;
300
+ this.claim = claim;
301
+ this.timestamp = options.timestamp ?? BigInt(Date.now()) * 1000000n;
302
+ }
303
+ toTransaction() {
304
+ return {
305
+ sender: this.sender,
306
+ recipient: this.recipient,
307
+ nonce: this.nonce,
308
+ timestamp_nanos: this.timestamp,
309
+ claim: this.claim
310
+ };
239
311
  }
240
- };
241
- var DEFAULT_CHAIN = "fastset";
242
- var getFastsetChainConfig = (chain = DEFAULT_CHAIN, env) => {
243
- const chainConfigs = FASTSET_CHAIN_CONFIGS[chain];
244
- if (!chainConfigs) {
245
- throw new Error(`Unsupported Fastset chain: ${chain}`);
312
+ getSender() {
313
+ return this.sender;
314
+ }
315
+ getRecipient() {
316
+ return this.recipient;
246
317
  }
247
- const config = chainConfigs[env];
248
- if (!config) {
249
- throw new Error(`Unsupported environment ${env} for chain ${chain}`);
318
+ getNonce() {
319
+ return this.nonce;
320
+ }
321
+ getClaim() {
322
+ return this.claim;
323
+ }
324
+ getTimestamp() {
325
+ return this.timestamp;
326
+ }
327
+ static fromTransaction(transaction) {
328
+ return new _Transaction(transaction.sender, transaction.recipient, transaction.nonce, transaction.claim, {
329
+ timestamp: transaction.timestamp_nanos
330
+ });
250
331
  }
251
- return config;
252
332
  };
253
- var getFastsetApiUrl = (env, chain = DEFAULT_CHAIN) => {
254
- return getFastsetChainConfig(chain, env).apiUrl;
333
+
334
+ // src/sdk/Wallet.ts
335
+ var Wallet = class _Wallet {
336
+ constructor(privateKeyHex) {
337
+ const cleanPrivateKey = privateKeyHex.replace(/^0x/, "");
338
+ this.privateKey = Buffer.from(cleanPrivateKey, "hex");
339
+ this.publicKey = ed.getPublicKey(this.privateKey);
340
+ this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
341
+ }
342
+ toBech32() {
343
+ const words = bech325.bech32m.toWords(this.publicKey);
344
+ return bech325.bech32m.encode("set", words);
345
+ }
346
+ getWalletInfo() {
347
+ return {
348
+ publicKeyHex: this.publicKeyHex,
349
+ address: this.toBech32()
350
+ };
351
+ }
352
+ createTransferClaim(recipientAddress, amount, assetType) {
353
+ const recipientBytes = _Wallet.decodeBech32Address(recipientAddress);
354
+ const assetTypeBytes = new TextEncoder().encode(assetType);
355
+ const userData = new Uint8Array(32);
356
+ userData.set(assetTypeBytes.slice(0, 32));
357
+ return {
358
+ Transfer: {
359
+ recipient: { FastSet: recipientBytes },
360
+ amount: amount.toString(),
361
+ user_data: userData
362
+ }
363
+ };
364
+ }
365
+ createTransaction(nonce, recipient, claim) {
366
+ return new Transaction(this.publicKey, recipient, nonce, claim);
367
+ }
368
+ static decodeBech32Address(address) {
369
+ try {
370
+ const decoded = bech325.bech32m.decode(address);
371
+ return new Uint8Array(bech325.bech32m.fromWords(decoded.words));
372
+ } catch (error) {
373
+ const decoded = bech325.bech32.decode(address);
374
+ return new Uint8Array(bech325.bech32.fromWords(decoded.words));
375
+ }
376
+ }
377
+ static encodeBech32Address(publicKey) {
378
+ const words = bech325.bech32m.toWords(publicKey);
379
+ return bech325.bech32m.encode("set", words);
380
+ }
381
+ static fromPrivateKey(privateKeyHex) {
382
+ return new _Wallet(privateKeyHex);
383
+ }
384
+ static generateNew() {
385
+ const privateKey = ed.utils.randomPrivateKey();
386
+ const privateKeyHex = Buffer.from(privateKey).toString("hex");
387
+ return new _Wallet(privateKeyHex);
388
+ }
389
+ static async fromPrivateKeyFile(filePath) {
390
+ const fs = await import("fs/promises");
391
+ const privateKeyHex = (await fs.readFile(filePath, "utf8")).trim();
392
+ return new _Wallet(privateKeyHex);
393
+ }
255
394
  };
256
395
 
257
396
  // src/WarpFastsetSerializer.ts
@@ -271,7 +410,7 @@ var WarpFastsetSerializer = class {
271
410
  return `boolean:${value}`;
272
411
  }
273
412
  if (typeof value === "bigint") {
274
- return `bigint:${value.toString()}`;
413
+ return `biguint:${value.toString()}`;
275
414
  }
276
415
  if (Array.isArray(value)) {
277
416
  const items = value.map((item) => this.typedToString(item)).join(",");
@@ -296,7 +435,7 @@ var WarpFastsetSerializer = class {
296
435
  return ["boolean", value];
297
436
  }
298
437
  if (typeof value === "bigint") {
299
- return ["bigint", value];
438
+ return ["biguint", value.toString()];
300
439
  }
301
440
  return ["string", String(value)];
302
441
  }
@@ -308,8 +447,12 @@ var WarpFastsetSerializer = class {
308
447
  return Number(value);
309
448
  case "boolean":
310
449
  return Boolean(value);
311
- case "bigint":
450
+ case "biguint":
312
451
  return BigInt(value);
452
+ case "address":
453
+ return String(value);
454
+ case "hex":
455
+ return String(value);
313
456
  default:
314
457
  return String(value);
315
458
  }
@@ -322,8 +465,12 @@ var WarpFastsetSerializer = class {
322
465
  return "number";
323
466
  case "boolean":
324
467
  return "boolean";
325
- case "bigint":
326
- return "bigint";
468
+ case "biguint":
469
+ return "biguint";
470
+ case "address":
471
+ return "address";
472
+ case "hex":
473
+ return "hex";
327
474
  default:
328
475
  return "string";
329
476
  }
@@ -342,7 +489,7 @@ var WarpFastsetSerializer = class {
342
489
  return Number(stringValue);
343
490
  case "boolean":
344
491
  return stringValue === "true";
345
- case "bigint":
492
+ case "biguint":
346
493
  return BigInt(stringValue);
347
494
  case "array":
348
495
  return stringValue.split(",").map((item) => this.stringToTyped(item));
@@ -358,24 +505,29 @@ var WarpFastsetSerializer = class {
358
505
 
359
506
  // src/WarpFastsetExecutor.ts
360
507
  var WarpFastsetExecutor = class {
361
- constructor(config) {
508
+ constructor(config, chain) {
362
509
  this.config = config;
510
+ this.chain = chain;
363
511
  this.serializer = new WarpFastsetSerializer();
512
+ const proxyUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
513
+ this.fastsetClient = new FastsetClient({
514
+ proxyUrl
515
+ });
364
516
  }
365
517
  async createTransaction(executable) {
366
518
  const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
367
- let tx = null;
368
- if (action.type === "transfer") {
369
- tx = await this.createTransferTransaction(executable);
370
- } else if (action.type === "contract") {
371
- tx = await this.createContractCallTransaction(executable);
372
- } else if (action.type === "query") {
373
- throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
374
- } else if (action.type === "collect") {
375
- throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
376
- }
377
- if (!tx) throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
378
- return tx;
519
+ switch (action.type) {
520
+ case "transfer":
521
+ return this.createTransferTransaction(executable);
522
+ case "contract":
523
+ return this.createContractCallTransaction(executable);
524
+ case "query":
525
+ throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
526
+ case "collect":
527
+ throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
528
+ default:
529
+ throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
530
+ }
379
531
  }
380
532
  async createTransferTransaction(executable) {
381
533
  const userWallet = this.config.user?.wallets?.[executable.chain.name];
@@ -386,13 +538,15 @@ var WarpFastsetExecutor = class {
386
538
  if (executable.value < 0) {
387
539
  throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
388
540
  }
541
+ const recipientAddress = this.fromBase64(executable.destination);
542
+ const amount = this.normalizeAmount(executable.value.toString());
543
+ const userData = executable.data ? this.fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
389
544
  return {
390
545
  type: "fastset-transfer",
391
- from: userWallet,
392
- to: executable.destination,
393
- value: executable.value,
394
- data: executable.data ? this.serializer.stringToTyped(executable.data) : ""
395
- // TODO: Add Fastset-specific transaction fields
546
+ recipient: recipientAddress,
547
+ amount,
548
+ userData,
549
+ chain: executable.chain
396
550
  };
397
551
  }
398
552
  async createContractCallTransaction(executable) {
@@ -409,15 +563,15 @@ var WarpFastsetExecutor = class {
409
563
  throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
410
564
  }
411
565
  try {
566
+ const contractAddress = this.fromBase64(executable.destination);
412
567
  const encodedData = this.encodeFunctionData(action.func, executable.args);
413
568
  return {
414
569
  type: "fastset-contract-call",
415
- from: userWallet,
416
- to: executable.destination,
417
- value: executable.value,
570
+ contract: contractAddress,
571
+ function: action.func,
418
572
  data: encodedData,
419
- function: action.func
420
- // TODO: Add Fastset-specific transaction fields
573
+ value: executable.value,
574
+ chain: executable.chain
421
575
  };
422
576
  } catch (error) {
423
577
  throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
@@ -435,46 +589,72 @@ var WarpFastsetExecutor = class {
435
589
  throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
436
590
  }
437
591
  try {
438
- const result = await this.executeFastsetQuery(executable.destination, action.func, executable.args);
592
+ const contractAddress = this.fromBase64(executable.destination);
593
+ const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
439
594
  return {
440
595
  success: true,
441
- result
442
- // TODO: Add Fastset-specific result fields
596
+ result,
597
+ chain: executable.chain
443
598
  };
444
599
  } catch (error) {
445
600
  return {
446
601
  success: false,
447
- error: error instanceof Error ? error.message : String(error)
448
- // TODO: Add Fastset-specific error fields
602
+ error: error instanceof Error ? error.message : String(error),
603
+ chain: executable.chain
449
604
  };
450
605
  }
451
606
  }
452
- async preprocessInput(chain, input, type, value) {
453
- const typedValue = this.serializer.stringToTyped(value);
454
- switch (type) {
455
- case "address":
456
- if (!this.isValidFastsetAddress(typedValue)) {
457
- throw new Error(`Invalid Fastset address format: ${typedValue}`);
458
- }
459
- return typedValue;
460
- case "number":
461
- const numValue = Number(typedValue);
462
- if (isNaN(numValue)) {
463
- throw new Error(`Invalid number format: ${typedValue}`);
464
- }
465
- return numValue.toString();
466
- case "bigint":
467
- const bigIntValue = BigInt(typedValue);
468
- if (bigIntValue < 0) {
469
- throw new Error(`Negative value not allowed for type ${type}: ${typedValue}`);
470
- }
471
- return bigIntValue.toString();
472
- default:
473
- return String(typedValue);
474
- }
607
+ async signMessage(message, privateKey) {
608
+ throw new Error("Not implemented");
475
609
  }
476
- isValidFastsetAddress(address) {
477
- return typeof address === "string" && address.length > 0;
610
+ async signTransaction(transaction, privateKey) {
611
+ const transactionJson = JSON.stringify(transaction, (key, value) => {
612
+ if (value instanceof Uint8Array) {
613
+ return Array.from(value);
614
+ }
615
+ return value;
616
+ });
617
+ const prefix = "Transaction::";
618
+ const dataToSign = new TextEncoder().encode(prefix + transactionJson);
619
+ return await ed25519.sign(dataToSign, privateKey);
620
+ }
621
+ async executeTransfer(executable) {
622
+ const userWallet = this.config.user?.wallets?.[executable.chain.name];
623
+ if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
624
+ const transaction = await this.createTransferTransaction(executable);
625
+ return {
626
+ success: true,
627
+ transaction,
628
+ chain: executable.chain.name,
629
+ message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
630
+ };
631
+ }
632
+ async executeTransferWithKey(executable, privateKey) {
633
+ const userWallet = this.config.user?.wallets?.[executable.chain.name];
634
+ if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
635
+ const transaction = await this.createTransferTransaction(executable);
636
+ const privateKeyBytes = this.fromBase64(privateKey);
637
+ const transactionData = {
638
+ sender: Array.from(privateKeyBytes.slice(0, 32)),
639
+ // First 32 bytes as public key
640
+ recipient: { FastSet: transaction.recipient },
641
+ nonce: await this.fastsetClient.getNextNonce(Wallet.encodeBech32Address(privateKeyBytes.slice(0, 32))),
642
+ timestamp_nanos: (BigInt(Date.now()) * 1000000n).toString(),
643
+ claim: {
644
+ Transfer: {
645
+ recipient: { FastSet: transaction.recipient },
646
+ amount: transaction.amount,
647
+ user_data: transaction.userData ? Array.from(transaction.userData) : null
648
+ }
649
+ }
650
+ };
651
+ const signature = await this.signTransaction(transactionData, privateKeyBytes);
652
+ const transactionHash = await this.fastsetClient.submitTransaction(transactionData, signature);
653
+ return {
654
+ success: true,
655
+ transactionHash: Array.from(transactionHash),
656
+ chain: executable.chain.name
657
+ };
478
658
  }
479
659
  encodeFunctionData(functionName, args) {
480
660
  return JSON.stringify({
@@ -483,13 +663,14 @@ var WarpFastsetExecutor = class {
483
663
  });
484
664
  }
485
665
  async executeFastsetQuery(contractAddress, functionName, args) {
486
- const response = await fetch(`${getFastsetApiUrl(this.config.env, "fastset")}/query`, {
666
+ const validatorUrl = (0, import_warps2.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
667
+ const response = await fetch(`${validatorUrl}/query`, {
487
668
  method: "POST",
488
669
  headers: {
489
670
  "Content-Type": "application/json"
490
671
  },
491
672
  body: JSON.stringify({
492
- contract: contractAddress,
673
+ contract: Array.from(contractAddress),
493
674
  function: functionName,
494
675
  arguments: args
495
676
  })
@@ -499,64 +680,72 @@ var WarpFastsetExecutor = class {
499
680
  }
500
681
  return response.json();
501
682
  }
502
- async signMessage(message, privateKey) {
503
- throw new Error("Not implemented");
683
+ isValidFastsetAddress(address) {
684
+ if (typeof address !== "string" || address.length === 0) {
685
+ return false;
686
+ }
687
+ if (address.startsWith("fs") || address.startsWith("pi")) {
688
+ return true;
689
+ }
690
+ try {
691
+ const decoded = this.fromBase64(address);
692
+ return decoded.length === 32;
693
+ } catch {
694
+ return false;
695
+ }
696
+ }
697
+ fromBase64(base64) {
698
+ return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
699
+ }
700
+ normalizeAmount(amount) {
701
+ return amount.startsWith("0x") ? amount.slice(2) : amount;
504
702
  }
505
703
  };
506
704
 
507
705
  // src/WarpFastsetExplorer.ts
508
706
  var WarpFastsetExplorer = class {
509
- constructor(chainInfo, chainName = "fastset") {
510
- this.chainInfo = chainInfo;
511
- this.chainName = chainName;
707
+ constructor(_chainInfo, _config) {
708
+ this._chainInfo = _chainInfo;
709
+ this._config = _config;
710
+ this.explorerUrl = "https://explorer.fastset.xyz";
512
711
  }
513
712
  getAccountUrl(address) {
514
- const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
515
- return `${baseUrl}/address/${address}`;
713
+ return `${this.explorerUrl}/account/${address}`;
516
714
  }
517
715
  getTransactionUrl(hash) {
518
- const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
519
- return `${baseUrl}/tx/${hash}`;
716
+ return `${this.explorerUrl}/transaction/${hash}`;
520
717
  }
521
- getBlockUrl(blockNumber) {
522
- const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
523
- return `${baseUrl}/block/${blockNumber}`;
718
+ getAssetUrl(identifier) {
719
+ return `${this.explorerUrl}/asset/${identifier}`;
524
720
  }
525
721
  getContractUrl(address) {
526
- const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
527
- return `${baseUrl}/contract/${address}`;
528
- }
529
- getTokenUrl(address) {
530
- const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
531
- return `${baseUrl}/token/${address}`;
532
- }
533
- getDefaultExplorerUrl() {
534
- return `https://explorer.fastset.xyz`;
722
+ return `${this.explorerUrl}/account/${address}`;
535
723
  }
536
724
  };
537
725
 
538
726
  // src/WarpFastsetResults.ts
539
727
  var import_warps3 = require("@vleap/warps");
540
728
  var WarpFastsetResults = class {
541
- constructor(config) {
729
+ constructor(config, chain) {
542
730
  this.config = config;
731
+ this.chain = chain;
543
732
  this.serializer = new WarpFastsetSerializer();
544
733
  }
545
734
  async getTransactionExecutionResults(warp, tx) {
546
735
  const success = this.isTransactionSuccessful(tx);
547
- const gasUsed = this.extractGasUsed(tx);
548
- const gasPrice = this.extractGasPrice(tx);
549
- const blockNumber = this.extractBlockNumber(tx);
550
736
  const transactionHash = this.extractTransactionHash(tx);
551
- const logs = this.extractLogs(tx);
737
+ const blockNumber = this.extractBlockNumber(tx);
738
+ const timestamp = this.extractTimestamp(tx);
552
739
  return {
553
740
  success,
554
741
  warp,
555
742
  action: 0,
556
- user: this.config.user?.wallets?.fastset || null,
743
+ user: this.config.user?.wallets?.[this.chain.name] || null,
557
744
  txHash: transactionHash,
745
+ tx,
558
746
  next: null,
559
- values: [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []],
747
+ values: [transactionHash, blockNumber, timestamp],
748
+ valuesRaw: [transactionHash, blockNumber, timestamp],
560
749
  results: {},
561
750
  messages: {}
562
751
  };
@@ -567,6 +756,11 @@ var WarpFastsetResults = class {
567
756
  let results = {};
568
757
  if (!warp.results) return { values, results };
569
758
  const getNestedValue = (path) => {
759
+ const match = path.match(/^out\[(\d+)\]$/);
760
+ if (match) {
761
+ const index = parseInt(match[1]) - 1;
762
+ return valuesRaw[index];
763
+ }
570
764
  const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
571
765
  if (indices.length === 0) return void 0;
572
766
  let value = valuesRaw[indices[0]];
@@ -584,61 +778,102 @@ var WarpFastsetResults = class {
584
778
  continue;
585
779
  }
586
780
  if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
587
- results[key] = getNestedValue(path) || null;
781
+ const value = getNestedValue(path);
782
+ results[key] = value || null;
588
783
  } else {
589
784
  results[key] = path;
590
785
  }
591
786
  }
592
- return { values, results: await (0, import_warps3.evaluateResultsCommon)(warp, results, actionIndex, inputs) };
787
+ return { values, results: await (0, import_warps3.evaluateResultsCommon)(warp, results, actionIndex, inputs, this.config.transform?.runner) };
593
788
  }
594
789
  isTransactionSuccessful(tx) {
595
- return tx.status === "success" || tx.status === 1 || tx.success === true;
596
- }
597
- extractGasUsed(tx) {
598
- return tx.gasUsed?.toString() || tx.gas_used?.toString() || "0";
790
+ if (!tx) return false;
791
+ if (tx.success === false) return false;
792
+ if (tx.success === true) return true;
793
+ if (tx.status === "success") return true;
794
+ if (tx.status === 1) return true;
795
+ if (tx.result && tx.result.success === true) return true;
796
+ return false;
599
797
  }
600
- extractGasPrice(tx) {
601
- return tx.gasPrice?.toString() || tx.gas_price?.toString() || "0";
798
+ extractTransactionHash(tx) {
799
+ if (!tx) return "";
800
+ return tx.transaction_hash || tx.transactionHash || tx.hash || tx.result && tx.result.transaction_hash || "";
602
801
  }
603
802
  extractBlockNumber(tx) {
604
- return tx.blockNumber?.toString() || tx.block_number?.toString() || "0";
803
+ if (!tx) return "0";
804
+ return tx.block_number?.toString() || tx.blockNumber?.toString() || tx.result && tx.result.block_number?.toString() || "0";
605
805
  }
606
- extractTransactionHash(tx) {
607
- return tx.hash || tx.transactionHash || tx.transaction_hash || "";
608
- }
609
- extractLogs(tx) {
610
- const logs = tx.logs || tx.events || [];
611
- return logs.map((log) => ({
612
- address: log.address || log.contract,
613
- topics: log.topics || log.topics || [],
614
- data: log.data || log.payload || "",
615
- blockNumber: log.blockNumber?.toString() || log.block_number?.toString() || "0",
616
- transactionHash: log.transactionHash || log.transaction_hash || "",
617
- index: log.index?.toString() || "0"
618
- }));
806
+ extractTimestamp(tx) {
807
+ if (!tx) return "0";
808
+ return tx.timestamp?.toString() || tx.timestamp_nanos?.toString() || tx.result && tx.result.timestamp?.toString() || Date.now().toString();
619
809
  }
620
810
  };
621
811
 
622
812
  // src/main.ts
623
- var getFastsetAdapter = (config, fallback) => {
624
- if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
625
- return {
626
- chain: WarpFastsetConstants.ChainName,
627
- prefix: WarpFastsetConstants.ChainPrefix,
628
- builder: () => new WarpFastsetBuilder(config),
629
- executor: new WarpFastsetExecutor(config),
630
- results: new WarpFastsetResults(config),
631
- serializer: new WarpFastsetSerializer(),
632
- registry: fallback.registry,
633
- explorer: (chainInfo) => new WarpFastsetExplorer(chainInfo),
634
- abiBuilder: () => fallback.abiBuilder(),
635
- brandBuilder: () => fallback.brandBuilder()
636
- };
813
+ var NativeTokenSet = {
814
+ chain: import_warps4.WarpChainName.Fastset,
815
+ identifier: "SET",
816
+ name: "SET",
817
+ symbol: "SET",
818
+ decimals: 6,
819
+ logoUrl: "https://vleap.ai/images/tokens/set.svg"
637
820
  };
821
+ function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
822
+ return (config, fallback) => {
823
+ const chainInfo = chainInfos[config.env];
824
+ if (!chainInfo) throw new Error(`FastsetAdapter: chain info not found for chain ${chainName}`);
825
+ if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
826
+ return {
827
+ chain: chainName,
828
+ chainInfo,
829
+ prefix: chainPrefix,
830
+ builder: () => fallback.builder(),
831
+ executor: new WarpFastsetExecutor(config, chainInfo),
832
+ results: new WarpFastsetResults(config, chainInfo),
833
+ serializer: new WarpFastsetSerializer(),
834
+ registry: fallback.registry,
835
+ explorer: new WarpFastsetExplorer(chainInfo, config),
836
+ abiBuilder: () => fallback.abiBuilder(),
837
+ brandBuilder: () => fallback.brandBuilder(),
838
+ dataLoader: new WarpFastsetDataLoader(config, chainInfo)
839
+ };
840
+ };
841
+ }
842
+ var getFastsetAdapter = createFastsetAdapter(import_warps4.WarpChainName.Fastset, "fastset", {
843
+ mainnet: {
844
+ name: import_warps4.WarpChainName.Fastset,
845
+ displayName: "FastSet",
846
+ chainId: "1",
847
+ blockTime: 1e3,
848
+ addressHrp: "set",
849
+ defaultApiUrl: "https://rpc.fastset.xyz",
850
+ nativeToken: NativeTokenSet
851
+ },
852
+ testnet: {
853
+ name: import_warps4.WarpChainName.Fastset,
854
+ displayName: "FastSet Testnet",
855
+ chainId: "testnet",
856
+ blockTime: 1e3,
857
+ addressHrp: "set",
858
+ defaultApiUrl: "https://rpc.fastset.xyz",
859
+ nativeToken: NativeTokenSet
860
+ },
861
+ devnet: {
862
+ name: import_warps4.WarpChainName.Fastset,
863
+ displayName: "FastSet Devnet",
864
+ chainId: "devnet",
865
+ blockTime: 1e3,
866
+ addressHrp: "set",
867
+ defaultApiUrl: "https://rpc.fastset.xyz",
868
+ nativeToken: NativeTokenSet
869
+ }
870
+ });
638
871
  // Annotate the CommonJS export names for ESM import in node:
639
872
  0 && (module.exports = {
640
- WarpFastsetBuilder,
873
+ FastsetClient,
874
+ NativeTokenSet,
641
875
  WarpFastsetConstants,
876
+ WarpFastsetDataLoader,
642
877
  WarpFastsetExecutor,
643
878
  WarpFastsetExplorer,
644
879
  WarpFastsetResults,