@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.js CHANGED
@@ -30,21 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- Address: () => Address,
34
- Amount: () => Amount,
35
- BcsTransaction: () => BcsTransaction,
36
- Bytes32: () => Bytes32,
37
- Claim: () => Claim,
38
- ClaimType: () => ClaimType,
39
33
  FastsetClient: () => FastsetClient,
40
34
  NativeTokenSet: () => NativeTokenSet,
41
- Nonce: () => Nonce,
42
- PublicKey: () => PublicKey,
43
- Transaction: () => Transaction,
44
- Transfer: () => Transfer,
45
- TransferClaim: () => TransferClaim,
46
- UserData: () => UserData,
47
- Wallet: () => Wallet,
48
35
  WarpFastsetConstants: () => WarpFastsetConstants,
49
36
  WarpFastsetDataLoader: () => WarpFastsetDataLoader,
50
37
  WarpFastsetExecutor: () => WarpFastsetExecutor,
@@ -63,106 +50,240 @@ var WarpFastsetConstants = {
63
50
  // src/main.ts
64
51
  var import_warps4 = require("@vleap/warps");
65
52
 
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");
53
+ // src/WarpFastsetDataLoader.ts
54
+ var bech323 = __toESM(require("bech32"), 1);
71
55
 
72
- // src/sdk/types.ts
56
+ // src/sdk/FastsetClient.ts
73
57
  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,
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(),
100
66
  timestamp_nanos: import_bcs.bcs.u128(),
101
- claim: ClaimType
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
+ })
102
116
  });
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
+ 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
+ }
117
126
  }
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}`);
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}`);
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;
148
+ }
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
+ });
155
+ }
156
+ async getTokenInfo(token_ids) {
157
+ return this.makeRequest("set_getTokenInfo", {
158
+ token_ids
159
+ });
160
+ }
161
+ async getTransfers(page) {
162
+ return this.makeRequest("set_getTransfers", { page });
163
+ }
164
+ async getClaims(confirmed, page) {
165
+ return this.makeRequest("set_getClaims", { confirmed, page });
166
+ }
167
+ async getClaimsByAddress(address, page) {
168
+ return this.makeRequest("set_getClaimsByAddress", {
169
+ address,
170
+ page
171
+ });
172
+ }
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;
181
+ }
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
+ });
188
+ }
189
+ addressToBytes(address) {
190
+ try {
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}`);
199
+ }
133
200
  }
134
201
  }
135
202
  };
136
- var TransferClaim = class _TransferClaim extends Claim {
137
- constructor(recipient, amount, userData) {
138
- super();
139
- this.type = "Transfer";
140
- this.data = { recipient, amount, userData };
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);
141
210
  }
142
- toTransactionData() {
143
- return {
144
- Transfer: {
145
- recipient: { FastSet: this.data.recipient },
146
- amount: this.data.amount,
147
- user_data: this.data.userData ?? null
211
+ addressToBytes(address) {
212
+ try {
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}`);
148
221
  }
149
- };
222
+ }
150
223
  }
151
- static fromData(data) {
152
- const recipient = data.recipient.FastSet || data.recipient.External;
153
- return new _TransferClaim(recipient, data.amount, data.user_data);
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) };
154
228
  }
155
- getRecipient() {
156
- return this.data.recipient;
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
+ }
252
+ }
253
+ return assets;
157
254
  }
158
- getAmount() {
159
- return this.data.amount;
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) {
260
+ return null;
261
+ }
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;
160
274
  }
161
- getUserData() {
162
- return this.data.userData;
275
+ async getAccountActions(address, options) {
276
+ return [];
163
277
  }
164
278
  };
165
279
 
280
+ // src/WarpFastsetExecutor.ts
281
+ var ed25519 = __toESM(require("@noble/ed25519"), 1);
282
+ var import_warps2 = require("@vleap/warps");
283
+
284
+ // src/sdk/Wallet.ts
285
+ var bech325 = __toESM(require("bech32"), 1);
286
+
166
287
  // src/sdk/ed25519-setup.ts
167
288
  var ed = __toESM(require("@noble/ed25519"), 1);
168
289
  var import_sha512 = require("@noble/hashes/sha512");
@@ -172,8 +293,9 @@ if (ed.etc) {
172
293
 
173
294
  // src/sdk/Transaction.ts
174
295
  var Transaction = class _Transaction {
175
- constructor(sender, nonce, claim, options = {}) {
296
+ constructor(sender, recipient, nonce, claim, options = {}) {
176
297
  this.sender = sender;
298
+ this.recipient = recipient;
177
299
  this.nonce = nonce;
178
300
  this.claim = claim;
179
301
  this.timestamp = options.timestamp ?? BigInt(Date.now()) * 1000000n;
@@ -181,14 +303,18 @@ var Transaction = class _Transaction {
181
303
  toTransaction() {
182
304
  return {
183
305
  sender: this.sender,
306
+ recipient: this.recipient,
184
307
  nonce: this.nonce,
185
308
  timestamp_nanos: this.timestamp,
186
- claim: this.claim.toTransactionData()
309
+ claim: this.claim
187
310
  };
188
311
  }
189
312
  getSender() {
190
313
  return this.sender;
191
314
  }
315
+ getRecipient() {
316
+ return this.recipient;
317
+ }
192
318
  getNonce() {
193
319
  return this.nonce;
194
320
  }
@@ -199,8 +325,9 @@ var Transaction = class _Transaction {
199
325
  return this.timestamp;
200
326
  }
201
327
  static fromTransaction(transaction) {
202
- const claim = Claim.fromTransaction(transaction);
203
- return new _Transaction(transaction.sender, transaction.nonce, claim, { timestamp: transaction.timestamp_nanos });
328
+ return new _Transaction(transaction.sender, transaction.recipient, transaction.nonce, transaction.claim, {
329
+ timestamp: transaction.timestamp_nanos
330
+ });
204
331
  }
205
332
  };
206
333
 
@@ -213,8 +340,8 @@ var Wallet = class _Wallet {
213
340
  this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
214
341
  }
215
342
  toBech32() {
216
- const words = bech32.bech32m.toWords(this.publicKey);
217
- return bech32.bech32m.encode("set", words);
343
+ const words = bech325.bech32m.toWords(this.publicKey);
344
+ return bech325.bech32m.encode("set", words);
218
345
  }
219
346
  getWalletInfo() {
220
347
  return {
@@ -227,27 +354,29 @@ var Wallet = class _Wallet {
227
354
  const assetTypeBytes = new TextEncoder().encode(assetType);
228
355
  const userData = new Uint8Array(32);
229
356
  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);
357
+ return {
358
+ Transfer: {
359
+ recipient: { FastSet: recipientBytes },
360
+ amount: amount.toString(),
361
+ user_data: userData
362
+ }
363
+ };
234
364
  }
235
- async signTransaction(transaction) {
236
- const transactionData = transaction.toTransaction();
237
- return await TransactionSigner.signTransaction(transactionData, this.privateKey);
365
+ createTransaction(nonce, recipient, claim) {
366
+ return new Transaction(this.publicKey, recipient, nonce, claim);
238
367
  }
239
368
  static decodeBech32Address(address) {
240
369
  try {
241
- const decoded = bech32.bech32m.decode(address);
242
- return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
370
+ const decoded = bech325.bech32m.decode(address);
371
+ return new Uint8Array(bech325.bech32m.fromWords(decoded.words));
243
372
  } catch (error) {
244
- const decoded = bech32.bech32.decode(address);
245
- return new Uint8Array(bech32.bech32.fromWords(decoded.words));
373
+ const decoded = bech325.bech32.decode(address);
374
+ return new Uint8Array(bech325.bech32.fromWords(decoded.words));
246
375
  }
247
376
  }
248
377
  static encodeBech32Address(publicKey) {
249
- const words = bech32.bech32m.toWords(publicKey);
250
- return bech32.bech32m.encode("set", words);
378
+ const words = bech325.bech32m.toWords(publicKey);
379
+ return bech325.bech32m.encode("set", words);
251
380
  }
252
381
  static fromPrivateKey(privateKeyHex) {
253
382
  return new _Wallet(privateKeyHex);
@@ -264,361 +393,6 @@ var Wallet = class _Wallet {
264
393
  }
265
394
  };
266
395
 
267
- // src/sdk/FastsetClient.ts
268
- BigInt.prototype.toJSON = function() {
269
- return Number(this);
270
- };
271
- var FASTSET_VALIDATOR_URL = "https://rpc.fastset.xyz";
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
- // Generic error handling wrapper for RPC calls
281
- async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
282
- try {
283
- const response = useProxy ? await this.requestProxy(method, params) : await this.requestValidator(method, params);
284
- console.log(`RPC call to ${method} successful:`, response.result);
285
- return response.result;
286
- } catch (error) {
287
- console.error(`${errorMessage}:`, error);
288
- if (!allowNull) throw error;
289
- return null;
290
- }
291
- }
292
- async getAccountInfo(address) {
293
- const addressBytes = Wallet.decodeBech32Address(address);
294
- return this.handleRpcCall("set_getAccountInfo", [Array.from(addressBytes)], `Failed to get account info for address ${address}`);
295
- }
296
- async getNextNonce(senderAddress) {
297
- const accountInfo = await this.getAccountInfo(senderAddress);
298
- return accountInfo?.next_nonce ?? 0;
299
- }
300
- async getAssetBalance(accountId, assetId) {
301
- return this.handleRpcCall(
302
- "vsl_getAssetBalance",
303
- [accountId, assetId],
304
- `Failed to get asset balance for account ${accountId}, asset ${assetId}`
305
- );
306
- }
307
- async getAssetBalances(accountId) {
308
- return this.handleRpcCall("vsl_getAssetBalances", [accountId], `Failed to get asset balances for account ${accountId}`);
309
- }
310
- async fundFromFaucet(recipientAddress, amount) {
311
- const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
312
- return this.handleRpcCall(
313
- "faucetDrip",
314
- [Array.from(recipientBytes), amount],
315
- `Failed to fund from faucet for address ${recipientAddress}`,
316
- true,
317
- false
318
- );
319
- }
320
- async submitTransaction(request) {
321
- const response = await this.handleRpcCall(
322
- "set_submitTransaction",
323
- [request.transaction, Array.from(request.signature)],
324
- "Failed to submit transaction",
325
- false,
326
- false
327
- );
328
- const result = response;
329
- return {
330
- transaction_hash: new Uint8Array(result.transaction_hash),
331
- validator: new Uint8Array(result.validator),
332
- signature: new Uint8Array(result.signature)
333
- };
334
- }
335
- async submitCertificate(request) {
336
- await this.handleRpcCall(
337
- "set_submitTransactionCertificate",
338
- [
339
- request.transaction,
340
- Array.from(request.signature),
341
- request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
342
- ],
343
- "Failed to submit certificate",
344
- false,
345
- false
346
- );
347
- }
348
- async executeTransfer(senderPrivateKey, recipient, amount, userData) {
349
- try {
350
- console.log(`Executing transfer from sender to ${recipient} for amount ${amount}`);
351
- const senderPublicKey = (0, import_ed255192.getPublicKey)(senderPrivateKey);
352
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
353
- console.log(`Sender address: ${senderAddress}`);
354
- const nonce = await this.getNextNonce(senderAddress);
355
- console.log(`Using nonce: ${nonce}`);
356
- const recipientBytes = Wallet.decodeBech32Address(recipient);
357
- console.log(`Recipient decoded successfully`);
358
- const transaction = {
359
- sender: senderPublicKey,
360
- nonce,
361
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
362
- claim: {
363
- Transfer: {
364
- recipient: { FastSet: recipientBytes },
365
- amount,
366
- user_data: userData ?? null
367
- }
368
- }
369
- };
370
- console.log("Signing transaction...");
371
- const signature = await this.signTransaction(transaction, senderPrivateKey);
372
- console.log("Submitting transaction...");
373
- const submitResponse = await this.submitTransaction({
374
- transaction,
375
- signature
376
- });
377
- console.log("Submitting certificate...");
378
- await this.submitCertificate({
379
- transaction,
380
- signature,
381
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
382
- });
383
- console.log(`Transfer executed successfully. Transaction hash: ${submitResponse.transaction_hash}`);
384
- return submitResponse.transaction_hash;
385
- } catch (error) {
386
- console.error(`Failed to execute transfer to ${recipient}:`, error);
387
- throw error;
388
- }
389
- }
390
- async submitClaim(senderPrivateKey, claim) {
391
- try {
392
- console.log("Submitting claim...");
393
- const senderPublicKey = await (0, import_ed255192.getPublicKey)(senderPrivateKey);
394
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
395
- console.log(`Claim sender address: ${senderAddress}`);
396
- const nonce = await this.getNextNonce(senderAddress);
397
- console.log(`Using nonce: ${nonce}`);
398
- const transaction = {
399
- sender: senderPublicKey,
400
- nonce,
401
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
402
- claim
403
- };
404
- console.log("Signing claim transaction...");
405
- const signature = await this.signTransaction(transaction, senderPrivateKey);
406
- console.log("Submitting claim transaction...");
407
- const submitResponse = await this.submitTransaction({
408
- transaction,
409
- signature
410
- });
411
- console.log("Submitting claim certificate...");
412
- await this.submitCertificate({
413
- transaction,
414
- signature,
415
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
416
- });
417
- console.log(`Claim submitted successfully. Transaction hash: ${submitResponse.transaction_hash}`);
418
- return submitResponse.transaction_hash;
419
- } catch (error) {
420
- console.error("Failed to submit claim:", error);
421
- throw error;
422
- }
423
- }
424
- async signTransaction(transaction, privateKey) {
425
- return await TransactionSigner.signTransaction(transaction, privateKey);
426
- }
427
- async getTransactionStatus(txHash) {
428
- return this.handleRpcCall("set_getTransactionStatus", [txHash], `Failed to get transaction status for hash ${txHash}`);
429
- }
430
- async getTransactionInfo(txHash) {
431
- return this.handleRpcCall("set_getTransactionInfo", [txHash], `Failed to get transaction info for hash ${txHash}`);
432
- }
433
- async getNetworkInfo() {
434
- return this.handleRpcCall("set_getNetworkInfo", [], "Failed to get network info");
435
- }
436
- async requestValidator(method, params) {
437
- return this.request(this.config.validatorUrl, method, params);
438
- }
439
- async requestProxy(method, params) {
440
- return this.request(this.config.proxyUrl, method, params);
441
- }
442
- async request(url, method, params) {
443
- try {
444
- if (params !== null && params !== void 0) {
445
- if (Array.isArray(params)) {
446
- for (let i = 0; i < params.length; i++) {
447
- if (params[i] === void 0) {
448
- throw new Error(`Parameter at index ${i} is undefined`);
449
- }
450
- }
451
- } else if (typeof params === "object") {
452
- const paramObj = params;
453
- for (const [key, value] of Object.entries(paramObj)) {
454
- if (value === void 0) {
455
- throw new Error(`Parameter '${key}' is undefined`);
456
- }
457
- }
458
- }
459
- }
460
- const request = {
461
- jsonrpc: "2.0",
462
- id: 1,
463
- method,
464
- params
465
- };
466
- console.log(`Making RPC request to ${method} with params:`, params);
467
- const response = await fetch(url, {
468
- method: "POST",
469
- headers: { "Content-Type": "application/json" },
470
- body: JSON.stringify(request, this.jsonReplacer)
471
- });
472
- if (!response.ok) {
473
- throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`);
474
- }
475
- const jsonResponse = await response.json();
476
- if (jsonResponse.error) {
477
- throw new Error(`RPC error: ${jsonResponse.error.message} (code: ${jsonResponse.error.code})`);
478
- }
479
- console.log(`RPC request to ${method} successful:`, jsonResponse.result);
480
- return jsonResponse;
481
- } catch (error) {
482
- console.error(`Fastset RPC request failed for method ${method}:`, error);
483
- throw error;
484
- }
485
- }
486
- jsonReplacer(key, value) {
487
- if (value instanceof Uint8Array) {
488
- return Array.from(value);
489
- }
490
- return value;
491
- }
492
- };
493
-
494
- // src/WarpFastsetDataLoader.ts
495
- var WarpFastsetDataLoader = class {
496
- constructor(config, chain) {
497
- this.config = config;
498
- this.chain = chain;
499
- this.client = new FastsetClient();
500
- }
501
- async getAccount(address) {
502
- const accountInfo = await this.client.getAccountInfo(address);
503
- if (!accountInfo) {
504
- return {
505
- chain: this.chain.name,
506
- address,
507
- balance: BigInt(0)
508
- };
509
- }
510
- return {
511
- chain: this.chain.name,
512
- address,
513
- balance: BigInt(parseInt(accountInfo.balance, 16))
514
- };
515
- }
516
- async getAccountAssets(address) {
517
- const accountReq = this.getAccount(address);
518
- const assetBalancesReq = this.client.getAssetBalances(address);
519
- const [account, assetBalances] = await Promise.all([accountReq, assetBalancesReq]);
520
- const assets = [];
521
- if (account.balance > 0) {
522
- assets.push({ ...this.chain.nativeToken, amount: account.balance });
523
- }
524
- if (assetBalances) {
525
- for (const [assetId, assetBalance] of Object.entries(assetBalances)) {
526
- if (assetBalance.balance) {
527
- const amount = BigInt(assetBalance.balance);
528
- if (amount > 0) {
529
- assets.push({
530
- chain: this.chain.name,
531
- identifier: assetId,
532
- symbol: "TODO: SYMBOL",
533
- name: assetBalance.name || assetId,
534
- decimals: assetBalance.decimals || 6,
535
- logoUrl: assetBalance.logo_url,
536
- amount
537
- });
538
- }
539
- }
540
- }
541
- }
542
- return assets;
543
- }
544
- async getAsset(identifier) {
545
- return null;
546
- }
547
- async getAction(identifier, awaitCompleted = false) {
548
- return null;
549
- }
550
- async getAccountActions(address, options) {
551
- return [];
552
- }
553
- async getAccountInfo(address) {
554
- const accountInfo = await this.client.getAccountInfo(address);
555
- if (!accountInfo) {
556
- return null;
557
- }
558
- const balanceDecimal = parseInt(accountInfo.balance, 16);
559
- return {
560
- address,
561
- balance: accountInfo.balance,
562
- balanceDecimal,
563
- nextNonce: accountInfo.next_nonce,
564
- sequenceNumber: accountInfo.sequence_number
565
- };
566
- }
567
- async getTransactionInfo(txHash) {
568
- return {
569
- hash: txHash,
570
- hashHex: txHash.startsWith("0x") ? txHash.slice(2) : txHash,
571
- status: "submitted",
572
- details: {
573
- hash: txHash,
574
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
575
- }
576
- };
577
- }
578
- async checkTransferStatus(fromAddress, toAddress, amount) {
579
- const fromAccount = await this.getAccountInfo(fromAddress);
580
- const toAccount = await this.getAccountInfo(toAddress);
581
- if (!fromAccount || !toAccount) {
582
- return false;
583
- }
584
- const transferAmount = parseInt(amount);
585
- const fromBalance = fromAccount.balanceDecimal;
586
- return fromBalance < transferAmount;
587
- }
588
- async getAccountBalance(address) {
589
- const accountInfo = await this.getAccountInfo(address);
590
- if (!accountInfo) {
591
- return null;
592
- }
593
- return {
594
- balance: accountInfo.balance,
595
- balanceDecimal: accountInfo.balanceDecimal
596
- };
597
- }
598
- async getAssetBalance(address, assetId) {
599
- const assetBalance = await this.client.getAssetBalance(address, assetId);
600
- if (!assetBalance || !assetBalance.balance) {
601
- return null;
602
- }
603
- const amount = BigInt(assetBalance.balance);
604
- if (amount === 0n) {
605
- return null;
606
- }
607
- return {
608
- chain: this.chain.name,
609
- identifier: assetId,
610
- symbol: "TODO: SYMBOL",
611
- name: assetBalance.name || assetId,
612
- decimals: assetBalance.decimals || 6,
613
- logoUrl: assetBalance.logo_url,
614
- amount
615
- };
616
- }
617
- };
618
-
619
- // src/WarpFastsetExecutor.ts
620
- var import_warps2 = require("@vleap/warps");
621
-
622
396
  // src/WarpFastsetSerializer.ts
623
397
  var import_warps = require("@vleap/warps");
624
398
  var WarpFastsetSerializer = class {
@@ -735,10 +509,8 @@ var WarpFastsetExecutor = class {
735
509
  this.config = config;
736
510
  this.chain = chain;
737
511
  this.serializer = new WarpFastsetSerializer();
738
- const validatorUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
739
512
  const proxyUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
740
513
  this.fastsetClient = new FastsetClient({
741
- validatorUrl,
742
514
  proxyUrl
743
515
  });
744
516
  }
@@ -835,6 +607,17 @@ var WarpFastsetExecutor = class {
835
607
  async signMessage(message, privateKey) {
836
608
  throw new Error("Not implemented");
837
609
  }
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
+ }
838
621
  async executeTransfer(executable) {
839
622
  const userWallet = this.config.user?.wallets?.[executable.chain.name];
840
623
  if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
@@ -851,12 +634,22 @@ var WarpFastsetExecutor = class {
851
634
  if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
852
635
  const transaction = await this.createTransferTransaction(executable);
853
636
  const privateKeyBytes = this.fromBase64(privateKey);
854
- const transactionHash = await this.fastsetClient.executeTransfer(
855
- privateKeyBytes,
856
- transaction.recipient,
857
- transaction.amount,
858
- transaction.userData
859
- );
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);
860
653
  return {
861
654
  success: true,
862
655
  transactionHash: Array.from(transactionHash),
@@ -1077,21 +870,8 @@ var getFastsetAdapter = createFastsetAdapter(import_warps4.WarpChainName.Fastset
1077
870
  });
1078
871
  // Annotate the CommonJS export names for ESM import in node:
1079
872
  0 && (module.exports = {
1080
- Address,
1081
- Amount,
1082
- BcsTransaction,
1083
- Bytes32,
1084
- Claim,
1085
- ClaimType,
1086
873
  FastsetClient,
1087
874
  NativeTokenSet,
1088
- Nonce,
1089
- PublicKey,
1090
- Transaction,
1091
- Transfer,
1092
- TransferClaim,
1093
- UserData,
1094
- Wallet,
1095
875
  WarpFastsetConstants,
1096
876
  WarpFastsetDataLoader,
1097
877
  WarpFastsetExecutor,