@vleap/warps-adapter-fastset 0.1.0-alpha.19 → 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.mjs CHANGED
@@ -6,106 +6,243 @@ var WarpFastsetConstants = {
6
6
  // src/main.ts
7
7
  import { WarpChainName } from "@vleap/warps";
8
8
 
9
- // src/sdk/FastsetClient.ts
10
- import { getPublicKey } from "@noble/ed25519";
11
-
12
- // src/sdk/TransactionSigner.ts
13
- import { sign } from "@noble/ed25519";
9
+ // src/WarpFastsetDataLoader.ts
10
+ import * as bech323 from "bech32";
14
11
 
15
- // src/sdk/types.ts
12
+ // src/sdk/FastsetClient.ts
16
13
  import { bcs } from "@mysten/bcs";
17
- BigInt.prototype.toJSON = function() {
18
- return Number(this);
19
- };
20
- var Bytes32 = bcs.fixedArray(32, bcs.u8());
21
- var PublicKey = Bytes32;
22
- var Address = bcs.enum("Address", {
23
- External: PublicKey,
24
- FastSet: PublicKey
25
- });
26
- var Amount = bcs.u256().transform({
27
- input: (val) => hexToDecimal(val.toString()),
28
- output: (value) => value
29
- });
30
- var UserData = bcs.option(Bytes32);
31
- var Nonce = bcs.u64();
32
- var Transfer = bcs.struct("Transfer", {
33
- recipient: Address,
34
- amount: Amount,
35
- user_data: UserData
36
- });
37
- var ClaimType = bcs.enum("ClaimType", {
38
- Transfer
39
- });
40
- var BcsTransaction = bcs.struct("Transaction", {
41
- sender: PublicKey,
42
- nonce: Nonce,
14
+ import * as bech32 from "bech32";
15
+ var bcsTransaction = bcs.struct("Transaction", {
16
+ sender: bcs.fixedArray(32, bcs.u8()),
17
+ recipient: bcs.enum("Address", {
18
+ External: bcs.fixedArray(32, bcs.u8()),
19
+ FastSet: bcs.fixedArray(32, bcs.u8())
20
+ }),
21
+ nonce: bcs.u64(),
43
22
  timestamp_nanos: bcs.u128(),
44
- claim: ClaimType
23
+ claim: bcs.enum("ClaimType", {
24
+ Transfer: bcs.struct("Transfer", {
25
+ recipient: bcs.enum("Address", {
26
+ External: bcs.fixedArray(32, bcs.u8()),
27
+ FastSet: bcs.fixedArray(32, bcs.u8())
28
+ }),
29
+ amount: bcs.string(),
30
+ user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
31
+ }),
32
+ TokenTransfer: bcs.struct("TokenTransfer", {
33
+ token_id: bcs.fixedArray(32, bcs.u8()),
34
+ amount: bcs.string(),
35
+ user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
36
+ }),
37
+ TokenCreation: bcs.struct("TokenCreation", {
38
+ token_name: bcs.string(),
39
+ decimals: bcs.u8(),
40
+ initial_amount: bcs.string(),
41
+ mints: bcs.vector(bcs.fixedArray(32, bcs.u8())),
42
+ user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
43
+ }),
44
+ TokenManagement: bcs.struct("TokenManagement", {
45
+ token_id: bcs.fixedArray(32, bcs.u8()),
46
+ update_id: bcs.u64(),
47
+ new_admin: bcs.option(bcs.fixedArray(32, bcs.u8())),
48
+ mints: bcs.vector(
49
+ bcs.tuple([
50
+ bcs.enum("AddressChange", {
51
+ Add: bcs.fixedArray(32, bcs.u8()),
52
+ Remove: bcs.fixedArray(32, bcs.u8())
53
+ }),
54
+ bcs.fixedArray(32, bcs.u8())
55
+ ])
56
+ ),
57
+ user_data: bcs.option(bcs.fixedArray(32, bcs.u8()))
58
+ }),
59
+ Mint: bcs.struct("Mint", {
60
+ token_id: bcs.fixedArray(32, bcs.u8()),
61
+ amount: bcs.string()
62
+ }),
63
+ ExternalClaim: bcs.struct("ExternalClaim", {
64
+ claim: bcs.struct("ExternalClaimBody", {
65
+ verifier_committee: bcs.vector(bcs.fixedArray(32, bcs.u8())),
66
+ verifier_quorum: bcs.u64(),
67
+ claim_data: bcs.vector(bcs.u8())
68
+ }),
69
+ signatures: bcs.vector(bcs.tuple([bcs.fixedArray(32, bcs.u8()), bcs.fixedArray(64, bcs.u8())]))
70
+ })
71
+ })
45
72
  });
46
- function hexToDecimal(hex) {
47
- return BigInt(`0x${hex}`).toString();
48
- }
49
-
50
- // src/sdk/TransactionSigner.ts
51
- var TransactionSigner = class {
52
- static async signTransaction(transaction, privateKey) {
53
- const msg = BcsTransaction.serialize(transaction);
54
- const msgBytes = msg.toBytes();
55
- const prefix = new TextEncoder().encode("Transaction::");
56
- const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
57
- dataToSign.set(prefix, 0);
58
- dataToSign.set(msgBytes, prefix.length);
59
- return sign(dataToSign, privateKey);
73
+ var FastsetClient = class {
74
+ constructor(config, chain) {
75
+ if (config && "proxyUrl" in config) {
76
+ this.apiUrl = config.proxyUrl;
77
+ } else if (config && chain) {
78
+ this.apiUrl = chain.defaultApiUrl;
79
+ } else {
80
+ this.apiUrl = "https://rpc.fastset.xyz";
81
+ }
60
82
  }
61
- };
62
-
63
- // src/sdk/Wallet.ts
64
- import * as bech32 from "bech32";
65
-
66
- // src/sdk/Claim.ts
67
- var Claim = class {
68
- static fromTransaction(transaction) {
69
- const claimType = Object.keys(transaction.claim)[0];
70
- const claimData = transaction.claim[claimType];
71
- switch (claimType) {
72
- case "Transfer":
73
- return TransferClaim.fromData(claimData);
74
- default:
75
- throw new Error(`Unknown claim type: ${claimType}`);
83
+ async makeRequest(method, params = {}) {
84
+ const response = await fetch(this.apiUrl, {
85
+ method: "POST",
86
+ headers: {
87
+ "Content-Type": "application/json"
88
+ },
89
+ body: JSON.stringify({
90
+ jsonrpc: "2.0",
91
+ method,
92
+ params,
93
+ id: Date.now()
94
+ })
95
+ });
96
+ if (!response.ok) {
97
+ throw new Error(`HTTP error! status: ${response.status}`);
98
+ }
99
+ const jsonResponse = await response.json();
100
+ if (jsonResponse.error) {
101
+ throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
102
+ }
103
+ return jsonResponse.result;
104
+ }
105
+ async getAccountInfo(address, token_balance_filter, certificate_by_nonce) {
106
+ return this.makeRequest("set_getAccountInfo", {
107
+ address,
108
+ token_balance_filter,
109
+ certificate_by_nonce
110
+ });
111
+ }
112
+ async getTokenInfo(token_ids) {
113
+ return this.makeRequest("set_getTokenInfo", {
114
+ token_ids
115
+ });
116
+ }
117
+ async getTransfers(page) {
118
+ return this.makeRequest("set_getTransfers", { page });
119
+ }
120
+ async getClaims(confirmed, page) {
121
+ return this.makeRequest("set_getClaims", { confirmed, page });
122
+ }
123
+ async getClaimsByAddress(address, page) {
124
+ return this.makeRequest("set_getClaimsByAddress", {
125
+ address,
126
+ page
127
+ });
128
+ }
129
+ async getNextNonce(address) {
130
+ if (typeof address === "string") {
131
+ const addressBytes = this.addressToBytes(address);
132
+ const accountInfo2 = await this.getAccountInfo(addressBytes);
133
+ return accountInfo2.next_nonce;
134
+ }
135
+ const accountInfo = await this.getAccountInfo(address);
136
+ return accountInfo.next_nonce;
137
+ }
138
+ async submitTransaction(transaction, signature) {
139
+ const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
140
+ return this.makeRequest("set_submitTransaction", {
141
+ transaction,
142
+ signature: signatureArray
143
+ });
144
+ }
145
+ addressToBytes(address) {
146
+ try {
147
+ const decoded = bech32.bech32m.decode(address);
148
+ return Array.from(bech32.bech32m.fromWords(decoded.words));
149
+ } catch {
150
+ try {
151
+ const decoded = bech32.bech32.decode(address);
152
+ return Array.from(bech32.bech32.fromWords(decoded.words));
153
+ } catch {
154
+ throw new Error(`Invalid FastSet address: ${address}`);
155
+ }
76
156
  }
77
157
  }
78
158
  };
79
- var TransferClaim = class _TransferClaim extends Claim {
80
- constructor(recipient, amount, userData) {
81
- super();
82
- this.type = "Transfer";
83
- this.data = { recipient, amount, userData };
159
+
160
+ // src/WarpFastsetDataLoader.ts
161
+ var WarpFastsetDataLoader = class {
162
+ constructor(config, chain) {
163
+ this.config = config;
164
+ this.chain = chain;
165
+ this.client = new FastsetClient(config, chain);
84
166
  }
85
- toTransactionData() {
86
- return {
87
- Transfer: {
88
- recipient: { FastSet: this.data.recipient },
89
- amount: this.data.amount,
90
- user_data: this.data.userData ?? null
167
+ addressToBytes(address) {
168
+ try {
169
+ const decoded = bech323.bech32m.decode(address);
170
+ return Array.from(bech323.bech32m.fromWords(decoded.words));
171
+ } catch {
172
+ try {
173
+ const decoded = bech323.bech32.decode(address);
174
+ return Array.from(bech323.bech32.fromWords(decoded.words));
175
+ } catch {
176
+ throw new Error(`Invalid FastSet address: ${address}`);
91
177
  }
92
- };
178
+ }
93
179
  }
94
- static fromData(data) {
95
- const recipient = data.recipient.FastSet || data.recipient.External;
96
- return new _TransferClaim(recipient, data.amount, data.user_data);
180
+ async getAccount(address) {
181
+ const addressBytes = this.addressToBytes(address);
182
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
183
+ return { chain: this.chain.name, address, balance: BigInt(accountInfo.balance) };
97
184
  }
98
- getRecipient() {
99
- return this.data.recipient;
185
+ async getAccountAssets(address) {
186
+ const addressBytes = this.addressToBytes(address);
187
+ const accountInfo = await this.client.getAccountInfo(addressBytes);
188
+ const assets = [];
189
+ const balance = BigInt(accountInfo.balance);
190
+ if (balance > 0n) {
191
+ assets.push({ ...this.chain.nativeToken, amount: balance });
192
+ }
193
+ for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
194
+ const amount = BigInt(tokenBalance);
195
+ if (amount > 0n) {
196
+ const tokenInfo = await this.client.getTokenInfo([tokenId]);
197
+ const metadata = tokenInfo.requested_token_metadata[0]?.[1];
198
+ assets.push({
199
+ chain: this.chain.name,
200
+ identifier: Buffer.from(tokenId).toString("hex"),
201
+ symbol: metadata?.token_name || "UNKNOWN",
202
+ name: metadata?.token_name || "Unknown Token",
203
+ decimals: metadata?.decimals || 6,
204
+ logoUrl: void 0,
205
+ amount
206
+ });
207
+ }
208
+ }
209
+ return assets;
210
+ }
211
+ async getAsset(identifier) {
212
+ const tokenId = Buffer.from(identifier, "hex");
213
+ const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
214
+ const metadata = tokenInfo.requested_token_metadata[0]?.[1];
215
+ if (!metadata) {
216
+ return null;
217
+ }
218
+ return {
219
+ chain: this.chain.name,
220
+ identifier,
221
+ symbol: metadata.token_name,
222
+ name: metadata.token_name,
223
+ decimals: metadata.decimals,
224
+ logoUrl: void 0,
225
+ amount: BigInt(metadata.total_supply)
226
+ };
100
227
  }
101
- getAmount() {
102
- return this.data.amount;
228
+ async getAction(identifier, awaitCompleted = false) {
229
+ return null;
103
230
  }
104
- getUserData() {
105
- return this.data.userData;
231
+ async getAccountActions(address, options) {
232
+ return [];
106
233
  }
107
234
  };
108
235
 
236
+ // src/WarpFastsetExecutor.ts
237
+ import * as ed25519 from "@noble/ed25519";
238
+ import {
239
+ getProviderUrl,
240
+ getWarpActionByIndex
241
+ } from "@vleap/warps";
242
+
243
+ // src/sdk/Wallet.ts
244
+ import * as bech325 from "bech32";
245
+
109
246
  // src/sdk/ed25519-setup.ts
110
247
  import * as ed from "@noble/ed25519";
111
248
  import { sha512 } from "@noble/hashes/sha512";
@@ -115,8 +252,9 @@ if (ed.etc) {
115
252
 
116
253
  // src/sdk/Transaction.ts
117
254
  var Transaction = class _Transaction {
118
- constructor(sender, nonce, claim, options = {}) {
255
+ constructor(sender, recipient, nonce, claim, options = {}) {
119
256
  this.sender = sender;
257
+ this.recipient = recipient;
120
258
  this.nonce = nonce;
121
259
  this.claim = claim;
122
260
  this.timestamp = options.timestamp ?? BigInt(Date.now()) * 1000000n;
@@ -124,14 +262,18 @@ var Transaction = class _Transaction {
124
262
  toTransaction() {
125
263
  return {
126
264
  sender: this.sender,
265
+ recipient: this.recipient,
127
266
  nonce: this.nonce,
128
267
  timestamp_nanos: this.timestamp,
129
- claim: this.claim.toTransactionData()
268
+ claim: this.claim
130
269
  };
131
270
  }
132
271
  getSender() {
133
272
  return this.sender;
134
273
  }
274
+ getRecipient() {
275
+ return this.recipient;
276
+ }
135
277
  getNonce() {
136
278
  return this.nonce;
137
279
  }
@@ -142,8 +284,9 @@ var Transaction = class _Transaction {
142
284
  return this.timestamp;
143
285
  }
144
286
  static fromTransaction(transaction) {
145
- const claim = Claim.fromTransaction(transaction);
146
- return new _Transaction(transaction.sender, transaction.nonce, claim, { timestamp: transaction.timestamp_nanos });
287
+ return new _Transaction(transaction.sender, transaction.recipient, transaction.nonce, transaction.claim, {
288
+ timestamp: transaction.timestamp_nanos
289
+ });
147
290
  }
148
291
  };
149
292
 
@@ -156,8 +299,8 @@ var Wallet = class _Wallet {
156
299
  this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
157
300
  }
158
301
  toBech32() {
159
- const words = bech32.bech32m.toWords(this.publicKey);
160
- return bech32.bech32m.encode("set", words);
302
+ const words = bech325.bech32m.toWords(this.publicKey);
303
+ return bech325.bech32m.encode("set", words);
161
304
  }
162
305
  getWalletInfo() {
163
306
  return {
@@ -170,27 +313,29 @@ var Wallet = class _Wallet {
170
313
  const assetTypeBytes = new TextEncoder().encode(assetType);
171
314
  const userData = new Uint8Array(32);
172
315
  userData.set(assetTypeBytes.slice(0, 32));
173
- return new TransferClaim(recipientBytes, amount.toString(), userData);
174
- }
175
- createTransaction(nonce, claim) {
176
- return new Transaction(this.publicKey, nonce, claim);
316
+ return {
317
+ Transfer: {
318
+ recipient: { FastSet: recipientBytes },
319
+ amount: amount.toString(),
320
+ user_data: userData
321
+ }
322
+ };
177
323
  }
178
- async signTransaction(transaction) {
179
- const transactionData = transaction.toTransaction();
180
- return await TransactionSigner.signTransaction(transactionData, this.privateKey);
324
+ createTransaction(nonce, recipient, claim) {
325
+ return new Transaction(this.publicKey, recipient, nonce, claim);
181
326
  }
182
327
  static decodeBech32Address(address) {
183
328
  try {
184
- const decoded = bech32.bech32m.decode(address);
185
- return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
329
+ const decoded = bech325.bech32m.decode(address);
330
+ return new Uint8Array(bech325.bech32m.fromWords(decoded.words));
186
331
  } catch (error) {
187
- const decoded = bech32.bech32.decode(address);
188
- return new Uint8Array(bech32.bech32.fromWords(decoded.words));
332
+ const decoded = bech325.bech32.decode(address);
333
+ return new Uint8Array(bech325.bech32.fromWords(decoded.words));
189
334
  }
190
335
  }
191
336
  static encodeBech32Address(publicKey) {
192
- const words = bech32.bech32m.toWords(publicKey);
193
- return bech32.bech32m.encode("set", words);
337
+ const words = bech325.bech32m.toWords(publicKey);
338
+ return bech325.bech32m.encode("set", words);
194
339
  }
195
340
  static fromPrivateKey(privateKeyHex) {
196
341
  return new _Wallet(privateKeyHex);
@@ -207,364 +352,6 @@ var Wallet = class _Wallet {
207
352
  }
208
353
  };
209
354
 
210
- // src/sdk/FastsetClient.ts
211
- BigInt.prototype.toJSON = function() {
212
- return Number(this);
213
- };
214
- var FASTSET_VALIDATOR_URL = "https://rpc.fastset.xyz";
215
- var FASTSET_PROXY_URL = "http://136.243.61.168:44444";
216
- var FastsetClient = class {
217
- constructor(config) {
218
- this.config = config || {
219
- validatorUrl: FASTSET_VALIDATOR_URL,
220
- proxyUrl: FASTSET_PROXY_URL
221
- };
222
- }
223
- // Generic error handling wrapper for RPC calls
224
- async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
225
- try {
226
- const response = useProxy ? await this.requestProxy(method, params) : await this.requestValidator(method, params);
227
- console.log(`RPC call to ${method} successful:`, response.result);
228
- return response.result;
229
- } catch (error) {
230
- console.error(`${errorMessage}:`, error);
231
- if (!allowNull) throw error;
232
- return null;
233
- }
234
- }
235
- async getAccountInfo(address) {
236
- const addressBytes = Wallet.decodeBech32Address(address);
237
- return this.handleRpcCall("set_getAccountInfo", [Array.from(addressBytes)], `Failed to get account info for address ${address}`);
238
- }
239
- async getNextNonce(senderAddress) {
240
- const accountInfo = await this.getAccountInfo(senderAddress);
241
- return accountInfo?.next_nonce ?? 0;
242
- }
243
- async getAssetBalance(accountId, assetId) {
244
- return this.handleRpcCall(
245
- "vsl_getAssetBalance",
246
- [accountId, assetId],
247
- `Failed to get asset balance for account ${accountId}, asset ${assetId}`
248
- );
249
- }
250
- async getAssetBalances(accountId) {
251
- return this.handleRpcCall("vsl_getAssetBalances", [accountId], `Failed to get asset balances for account ${accountId}`);
252
- }
253
- async fundFromFaucet(recipientAddress, amount) {
254
- const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
255
- return this.handleRpcCall(
256
- "faucetDrip",
257
- [Array.from(recipientBytes), amount],
258
- `Failed to fund from faucet for address ${recipientAddress}`,
259
- true,
260
- false
261
- );
262
- }
263
- async submitTransaction(request) {
264
- const response = await this.handleRpcCall(
265
- "set_submitTransaction",
266
- [request.transaction, Array.from(request.signature)],
267
- "Failed to submit transaction",
268
- false,
269
- false
270
- );
271
- const result = response;
272
- return {
273
- transaction_hash: new Uint8Array(result.transaction_hash),
274
- validator: new Uint8Array(result.validator),
275
- signature: new Uint8Array(result.signature)
276
- };
277
- }
278
- async submitCertificate(request) {
279
- await this.handleRpcCall(
280
- "set_submitTransactionCertificate",
281
- [
282
- request.transaction,
283
- Array.from(request.signature),
284
- request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
285
- ],
286
- "Failed to submit certificate",
287
- false,
288
- false
289
- );
290
- }
291
- async executeTransfer(senderPrivateKey, recipient, amount, userData) {
292
- try {
293
- console.log(`Executing transfer from sender to ${recipient} for amount ${amount}`);
294
- const senderPublicKey = getPublicKey(senderPrivateKey);
295
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
296
- console.log(`Sender address: ${senderAddress}`);
297
- const nonce = await this.getNextNonce(senderAddress);
298
- console.log(`Using nonce: ${nonce}`);
299
- const recipientBytes = Wallet.decodeBech32Address(recipient);
300
- console.log(`Recipient decoded successfully`);
301
- const transaction = {
302
- sender: senderPublicKey,
303
- nonce,
304
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
305
- claim: {
306
- Transfer: {
307
- recipient: { FastSet: recipientBytes },
308
- amount,
309
- user_data: userData ?? null
310
- }
311
- }
312
- };
313
- console.log("Signing transaction...");
314
- const signature = await this.signTransaction(transaction, senderPrivateKey);
315
- console.log("Submitting transaction...");
316
- const submitResponse = await this.submitTransaction({
317
- transaction,
318
- signature
319
- });
320
- console.log("Submitting certificate...");
321
- await this.submitCertificate({
322
- transaction,
323
- signature,
324
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
325
- });
326
- console.log(`Transfer executed successfully. Transaction hash: ${submitResponse.transaction_hash}`);
327
- return submitResponse.transaction_hash;
328
- } catch (error) {
329
- console.error(`Failed to execute transfer to ${recipient}:`, error);
330
- throw error;
331
- }
332
- }
333
- async submitClaim(senderPrivateKey, claim) {
334
- try {
335
- console.log("Submitting claim...");
336
- const senderPublicKey = await getPublicKey(senderPrivateKey);
337
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
338
- console.log(`Claim sender address: ${senderAddress}`);
339
- const nonce = await this.getNextNonce(senderAddress);
340
- console.log(`Using nonce: ${nonce}`);
341
- const transaction = {
342
- sender: senderPublicKey,
343
- nonce,
344
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
345
- claim
346
- };
347
- console.log("Signing claim transaction...");
348
- const signature = await this.signTransaction(transaction, senderPrivateKey);
349
- console.log("Submitting claim transaction...");
350
- const submitResponse = await this.submitTransaction({
351
- transaction,
352
- signature
353
- });
354
- console.log("Submitting claim certificate...");
355
- await this.submitCertificate({
356
- transaction,
357
- signature,
358
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
359
- });
360
- console.log(`Claim submitted successfully. Transaction hash: ${submitResponse.transaction_hash}`);
361
- return submitResponse.transaction_hash;
362
- } catch (error) {
363
- console.error("Failed to submit claim:", error);
364
- throw error;
365
- }
366
- }
367
- async signTransaction(transaction, privateKey) {
368
- return await TransactionSigner.signTransaction(transaction, privateKey);
369
- }
370
- async getTransactionStatus(txHash) {
371
- return this.handleRpcCall("set_getTransactionStatus", [txHash], `Failed to get transaction status for hash ${txHash}`);
372
- }
373
- async getTransactionInfo(txHash) {
374
- return this.handleRpcCall("set_getTransactionInfo", [txHash], `Failed to get transaction info for hash ${txHash}`);
375
- }
376
- async getNetworkInfo() {
377
- return this.handleRpcCall("set_getNetworkInfo", [], "Failed to get network info");
378
- }
379
- async requestValidator(method, params) {
380
- return this.request(this.config.validatorUrl, method, params);
381
- }
382
- async requestProxy(method, params) {
383
- return this.request(this.config.proxyUrl, method, params);
384
- }
385
- async request(url, method, params) {
386
- try {
387
- if (params !== null && params !== void 0) {
388
- if (Array.isArray(params)) {
389
- for (let i = 0; i < params.length; i++) {
390
- if (params[i] === void 0) {
391
- throw new Error(`Parameter at index ${i} is undefined`);
392
- }
393
- }
394
- } else if (typeof params === "object") {
395
- const paramObj = params;
396
- for (const [key, value] of Object.entries(paramObj)) {
397
- if (value === void 0) {
398
- throw new Error(`Parameter '${key}' is undefined`);
399
- }
400
- }
401
- }
402
- }
403
- const request = {
404
- jsonrpc: "2.0",
405
- id: 1,
406
- method,
407
- params
408
- };
409
- console.log(`Making RPC request to ${method} with params:`, params);
410
- const response = await fetch(url, {
411
- method: "POST",
412
- headers: { "Content-Type": "application/json" },
413
- body: JSON.stringify(request, this.jsonReplacer)
414
- });
415
- if (!response.ok) {
416
- throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`);
417
- }
418
- const jsonResponse = await response.json();
419
- if (jsonResponse.error) {
420
- throw new Error(`RPC error: ${jsonResponse.error.message} (code: ${jsonResponse.error.code})`);
421
- }
422
- console.log(`RPC request to ${method} successful:`, jsonResponse.result);
423
- return jsonResponse;
424
- } catch (error) {
425
- console.error(`Fastset RPC request failed for method ${method}:`, error);
426
- throw error;
427
- }
428
- }
429
- jsonReplacer(key, value) {
430
- if (value instanceof Uint8Array) {
431
- return Array.from(value);
432
- }
433
- return value;
434
- }
435
- };
436
-
437
- // src/WarpFastsetDataLoader.ts
438
- var WarpFastsetDataLoader = class {
439
- constructor(config, chain) {
440
- this.config = config;
441
- this.chain = chain;
442
- this.client = new FastsetClient();
443
- }
444
- async getAccount(address) {
445
- const accountInfo = await this.client.getAccountInfo(address);
446
- if (!accountInfo) {
447
- return {
448
- chain: this.chain.name,
449
- address,
450
- balance: BigInt(0)
451
- };
452
- }
453
- return {
454
- chain: this.chain.name,
455
- address,
456
- balance: BigInt(parseInt(accountInfo.balance, 16))
457
- };
458
- }
459
- async getAccountAssets(address) {
460
- const accountReq = this.getAccount(address);
461
- const assetBalancesReq = this.client.getAssetBalances(address);
462
- const [account, assetBalances] = await Promise.all([accountReq, assetBalancesReq]);
463
- const assets = [];
464
- if (account.balance > 0) {
465
- assets.push({ ...this.chain.nativeToken, amount: account.balance });
466
- }
467
- if (assetBalances) {
468
- for (const [assetId, assetBalance] of Object.entries(assetBalances)) {
469
- if (assetBalance.balance) {
470
- const amount = BigInt(assetBalance.balance);
471
- if (amount > 0) {
472
- assets.push({
473
- chain: this.chain.name,
474
- identifier: assetId,
475
- symbol: "TODO: SYMBOL",
476
- name: assetBalance.name || assetId,
477
- decimals: assetBalance.decimals || 6,
478
- logoUrl: assetBalance.logo_url,
479
- amount
480
- });
481
- }
482
- }
483
- }
484
- }
485
- return assets;
486
- }
487
- async getAsset(identifier) {
488
- return null;
489
- }
490
- async getAction(identifier, awaitCompleted = false) {
491
- return null;
492
- }
493
- async getAccountActions(address, options) {
494
- return [];
495
- }
496
- async getAccountInfo(address) {
497
- const accountInfo = await this.client.getAccountInfo(address);
498
- if (!accountInfo) {
499
- return null;
500
- }
501
- const balanceDecimal = parseInt(accountInfo.balance, 16);
502
- return {
503
- address,
504
- balance: accountInfo.balance,
505
- balanceDecimal,
506
- nextNonce: accountInfo.next_nonce,
507
- sequenceNumber: accountInfo.sequence_number
508
- };
509
- }
510
- async getTransactionInfo(txHash) {
511
- return {
512
- hash: txHash,
513
- hashHex: txHash.startsWith("0x") ? txHash.slice(2) : txHash,
514
- status: "submitted",
515
- details: {
516
- hash: txHash,
517
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
518
- }
519
- };
520
- }
521
- async checkTransferStatus(fromAddress, toAddress, amount) {
522
- const fromAccount = await this.getAccountInfo(fromAddress);
523
- const toAccount = await this.getAccountInfo(toAddress);
524
- if (!fromAccount || !toAccount) {
525
- return false;
526
- }
527
- const transferAmount = parseInt(amount);
528
- const fromBalance = fromAccount.balanceDecimal;
529
- return fromBalance < transferAmount;
530
- }
531
- async getAccountBalance(address) {
532
- const accountInfo = await this.getAccountInfo(address);
533
- if (!accountInfo) {
534
- return null;
535
- }
536
- return {
537
- balance: accountInfo.balance,
538
- balanceDecimal: accountInfo.balanceDecimal
539
- };
540
- }
541
- async getAssetBalance(address, assetId) {
542
- const assetBalance = await this.client.getAssetBalance(address, assetId);
543
- if (!assetBalance || !assetBalance.balance) {
544
- return null;
545
- }
546
- const amount = BigInt(assetBalance.balance);
547
- if (amount === 0n) {
548
- return null;
549
- }
550
- return {
551
- chain: this.chain.name,
552
- identifier: assetId,
553
- symbol: "TODO: SYMBOL",
554
- name: assetBalance.name || assetId,
555
- decimals: assetBalance.decimals || 6,
556
- logoUrl: assetBalance.logo_url,
557
- amount
558
- };
559
- }
560
- };
561
-
562
- // src/WarpFastsetExecutor.ts
563
- import {
564
- getProviderUrl,
565
- getWarpActionByIndex
566
- } from "@vleap/warps";
567
-
568
355
  // src/WarpFastsetSerializer.ts
569
356
  import {
570
357
  WarpSerializer
@@ -683,10 +470,8 @@ var WarpFastsetExecutor = class {
683
470
  this.config = config;
684
471
  this.chain = chain;
685
472
  this.serializer = new WarpFastsetSerializer();
686
- const validatorUrl = getProviderUrl(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
687
473
  const proxyUrl = getProviderUrl(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
688
474
  this.fastsetClient = new FastsetClient({
689
- validatorUrl,
690
475
  proxyUrl
691
476
  });
692
477
  }
@@ -783,6 +568,17 @@ var WarpFastsetExecutor = class {
783
568
  async signMessage(message, privateKey) {
784
569
  throw new Error("Not implemented");
785
570
  }
571
+ async signTransaction(transaction, privateKey) {
572
+ const transactionJson = JSON.stringify(transaction, (key, value) => {
573
+ if (value instanceof Uint8Array) {
574
+ return Array.from(value);
575
+ }
576
+ return value;
577
+ });
578
+ const prefix = "Transaction::";
579
+ const dataToSign = new TextEncoder().encode(prefix + transactionJson);
580
+ return await ed25519.sign(dataToSign, privateKey);
581
+ }
786
582
  async executeTransfer(executable) {
787
583
  const userWallet = this.config.user?.wallets?.[executable.chain.name];
788
584
  if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
@@ -799,12 +595,22 @@ var WarpFastsetExecutor = class {
799
595
  if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
800
596
  const transaction = await this.createTransferTransaction(executable);
801
597
  const privateKeyBytes = this.fromBase64(privateKey);
802
- const transactionHash = await this.fastsetClient.executeTransfer(
803
- privateKeyBytes,
804
- transaction.recipient,
805
- transaction.amount,
806
- transaction.userData
807
- );
598
+ const transactionData = {
599
+ sender: Array.from(privateKeyBytes.slice(0, 32)),
600
+ // First 32 bytes as public key
601
+ recipient: { FastSet: transaction.recipient },
602
+ nonce: await this.fastsetClient.getNextNonce(Wallet.encodeBech32Address(privateKeyBytes.slice(0, 32))),
603
+ timestamp_nanos: (BigInt(Date.now()) * 1000000n).toString(),
604
+ claim: {
605
+ Transfer: {
606
+ recipient: { FastSet: transaction.recipient },
607
+ amount: transaction.amount,
608
+ user_data: transaction.userData ? Array.from(transaction.userData) : null
609
+ }
610
+ }
611
+ };
612
+ const signature = await this.signTransaction(transactionData, privateKeyBytes);
613
+ const transactionHash = await this.fastsetClient.submitTransaction(transactionData, signature);
808
614
  return {
809
615
  success: true,
810
616
  transactionHash: Array.from(transactionHash),
@@ -1028,21 +834,8 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, "fastset", {
1028
834
  }
1029
835
  });
1030
836
  export {
1031
- Address,
1032
- Amount,
1033
- BcsTransaction,
1034
- Bytes32,
1035
- Claim,
1036
- ClaimType,
1037
837
  FastsetClient,
1038
838
  NativeTokenSet,
1039
- Nonce,
1040
- PublicKey,
1041
- Transaction,
1042
- Transfer,
1043
- TransferClaim,
1044
- UserData,
1045
- Wallet,
1046
839
  WarpFastsetConstants,
1047
840
  WarpFastsetDataLoader,
1048
841
  WarpFastsetExecutor,