@joai/warps-adapter-solana 1.0.1 → 1.1.0

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
@@ -9,8 +9,7 @@ import {
9
9
  WarpCache,
10
10
  WarpCacheKey
11
11
  } from "@joai/warps";
12
- import { Connection, PublicKey } from "@solana/web3.js";
13
- import { getMint } from "@solana/spl-token";
12
+ import { Connection as Connection2, PublicKey as PublicKey2 } from "@solana/web3.js";
14
13
 
15
14
  // src/constants.ts
16
15
  var WarpSolanaConstants = {
@@ -72,6 +71,58 @@ var X402SolanaNetworkIdentifiers = {
72
71
  };
73
72
  var SupportedX402SolanaNetworks = [X402SolanaNetworkIdentifiers.Mainnet, X402SolanaNetworkIdentifiers.Devnet];
74
73
 
74
+ // src/tokenProgram.ts
75
+ import { PublicKey, SystemProgram, TransactionInstruction } from "@solana/web3.js";
76
+ var MINT_SIZE = 82;
77
+ var TOKEN_TRANSFER_INSTRUCTION = 3;
78
+ var TOKEN_PROGRAM_ID = new PublicKey(WarpSolanaConstants.Programs.TokenProgram);
79
+ var ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
80
+ var getAssociatedTokenAddress = async (mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId);
81
+ var getAssociatedTokenAddressSync = (mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => {
82
+ if (!allowOwnerOffCurve && !PublicKey.isOnCurve(owner.toBuffer())) {
83
+ throw new Error("Owner cannot be a PDA");
84
+ }
85
+ const [address] = PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
86
+ return address;
87
+ };
88
+ var createAssociatedTokenAccountInstruction = (payer, associatedToken, owner, mint, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => new TransactionInstruction({
89
+ keys: [
90
+ { pubkey: payer, isSigner: true, isWritable: true },
91
+ { pubkey: associatedToken, isSigner: false, isWritable: true },
92
+ { pubkey: owner, isSigner: false, isWritable: false },
93
+ { pubkey: mint, isSigner: false, isWritable: false },
94
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
95
+ { pubkey: programId, isSigner: false, isWritable: false }
96
+ ],
97
+ programId: associatedTokenProgramId,
98
+ data: Buffer.alloc(0)
99
+ });
100
+ var createTransferInstruction = (source, destination, owner, amount, programId = TOKEN_PROGRAM_ID) => {
101
+ const data = Buffer.alloc(9);
102
+ data.writeUInt8(TOKEN_TRANSFER_INSTRUCTION, 0);
103
+ data.writeBigUInt64LE(BigInt(amount), 1);
104
+ return new TransactionInstruction({
105
+ keys: [
106
+ { pubkey: source, isSigner: false, isWritable: true },
107
+ { pubkey: destination, isSigner: false, isWritable: true },
108
+ { pubkey: owner, isSigner: true, isWritable: false }
109
+ ],
110
+ programId,
111
+ data
112
+ });
113
+ };
114
+ var getMint = async (connection, address, commitment, programId = TOKEN_PROGRAM_ID) => {
115
+ const info = await connection.getAccountInfo(address, commitment);
116
+ if (!info) throw new Error("Token mint account not found");
117
+ if (!info.owner.equals(programId)) throw new Error("Token mint account owner mismatch");
118
+ if (info.data.length < MINT_SIZE) throw new Error("Token mint account has invalid size");
119
+ return {
120
+ address,
121
+ decimals: info.data.readUInt8(44),
122
+ isInitialized: info.data.readUInt8(45) !== 0
123
+ };
124
+ };
125
+
75
126
  // src/tokens.ts
76
127
  import { WarpChainName as WarpChainName4 } from "@joai/warps";
77
128
 
@@ -275,12 +326,12 @@ var WarpSolanaDataLoader = class {
275
326
  this.config = config;
276
327
  this.chain = chain;
277
328
  const providerConfig = getProviderConfig(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
278
- this.connection = new Connection(providerConfig.url, "confirmed");
329
+ this.connection = new Connection2(providerConfig.url, "confirmed");
279
330
  this.cache = new WarpCache(config.env, config.cache);
280
331
  }
281
332
  async getAccount(address) {
282
333
  try {
283
- const publicKey = new PublicKey(address);
334
+ const publicKey = new PublicKey2(address);
284
335
  const balance = await this.connection.getBalance(publicKey);
285
336
  return {
286
337
  chain: this.chain.name,
@@ -320,7 +371,7 @@ var WarpSolanaDataLoader = class {
320
371
  return this.chain.nativeToken;
321
372
  }
322
373
  const cacheKey = WarpCacheKey.Asset(this.config.env, this.chain.name, identifier);
323
- const cachedAsset = this.cache.get(cacheKey);
374
+ const cachedAsset = await this.cache.get(cacheKey);
324
375
  if (cachedAsset) {
325
376
  return cachedAsset;
326
377
  }
@@ -347,7 +398,7 @@ var WarpSolanaDataLoader = class {
347
398
  decimals: metadata.decimals,
348
399
  logoUrl: metadata.logoUrl
349
400
  };
350
- this.cache.set(cacheKey, asset, CacheTtl.OneHour);
401
+ await this.cache.set(cacheKey, asset, CacheTtl.OneHour);
351
402
  return asset;
352
403
  } catch (error) {
353
404
  return null;
@@ -378,9 +429,9 @@ var WarpSolanaDataLoader = class {
378
429
  }
379
430
  async getTokenBalances(address) {
380
431
  try {
381
- const publicKey = new PublicKey(address);
432
+ const publicKey = new PublicKey2(address);
382
433
  const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(publicKey, {
383
- programId: new PublicKey(WarpSolanaConstants.Programs.TokenProgram)
434
+ programId: new PublicKey2(WarpSolanaConstants.Programs.TokenProgram)
384
435
  });
385
436
  const env = this.config.env === "mainnet" ? "mainnet" : this.config.env === "devnet" ? "devnet" : "testnet";
386
437
  const knownTokens = getKnownTokensForChain(this.chain.name, env);
@@ -422,7 +473,7 @@ var WarpSolanaDataLoader = class {
422
473
  }
423
474
  async getTokenMetadata(tokenAddress) {
424
475
  try {
425
- const mintPublicKey = new PublicKey(tokenAddress);
476
+ const mintPublicKey = new PublicKey2(tokenAddress);
426
477
  const mintInfo = await getMint(this.connection, mintPublicKey);
427
478
  return {
428
479
  name: "Unknown Token",
@@ -572,8 +623,7 @@ var WarpSolanaDataLoader = class {
572
623
  };
573
624
 
574
625
  // src/WarpSolanaExecutor.ts
575
- import { createAssociatedTokenAccountInstruction, createTransferInstruction, getAssociatedTokenAddress } from "@solana/spl-token";
576
- import { ComputeBudgetProgram, Connection as Connection3, MessageV0, PublicKey as PublicKey3, SystemProgram, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
626
+ import { ComputeBudgetProgram, Connection as Connection4, MessageV0, PublicKey as PublicKey4, SystemProgram as SystemProgram2, TransactionInstruction as TransactionInstruction2, VersionedTransaction } from "@solana/web3.js";
577
627
  import {
578
628
  applyOutputToMessages,
579
629
  extractResolvedInputValues as extractResolvedInputValues2,
@@ -594,14 +644,14 @@ import {
594
644
  WarpCache as WarpCache2,
595
645
  WarpCacheKey as WarpCacheKey2
596
646
  } from "@joai/warps";
597
- import { Connection as Connection2 } from "@solana/web3.js";
647
+ import { Connection as Connection3 } from "@solana/web3.js";
598
648
 
599
649
  // src/WarpSolanaSerializer.ts
600
650
  import {
601
651
  WarpConstants,
602
652
  WarpSerializer
603
653
  } from "@joai/warps";
604
- import { PublicKey as PublicKey2 } from "@solana/web3.js";
654
+ import { PublicKey as PublicKey3 } from "@solana/web3.js";
605
655
  import bs58 from "bs58";
606
656
  var WarpSolanaSerializer = class {
607
657
  constructor() {
@@ -614,7 +664,7 @@ var WarpSolanaSerializer = class {
614
664
  if (typeof value === "string") {
615
665
  if (value.length >= 32 && value.length <= 44) {
616
666
  try {
617
- const pubkey = new PublicKey2(value);
667
+ const pubkey = new PublicKey3(value);
618
668
  if (pubkey.toBase58() === value && /^[1-9A-HJ-NP-Za-km-z]+$/.test(value)) {
619
669
  return `address:${value}`;
620
670
  }
@@ -641,7 +691,7 @@ var WarpSolanaSerializer = class {
641
691
  if (typeof value === "boolean") {
642
692
  return `boolean:${value}`;
643
693
  }
644
- if (value instanceof PublicKey2) {
694
+ if (value instanceof PublicKey3) {
645
695
  return `address:${value.toBase58()}`;
646
696
  }
647
697
  if (value instanceof Uint8Array) {
@@ -791,11 +841,11 @@ var WarpSolanaOutput = class {
791
841
  this.chain = chain;
792
842
  this.serializer = new WarpSolanaSerializer();
793
843
  const providerConfig = getProviderConfig2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
794
- this.connection = new Connection2(providerConfig.url, "confirmed");
844
+ this.connection = new Connection3(providerConfig.url, "confirmed");
795
845
  this.cache = new WarpCache2(config.env, config.cache);
796
846
  }
797
847
  async getActionExecution(warp, actionIndex, tx) {
798
- const inputs = this.cache.get(WarpCacheKey2.WarpExecutable(this.config.env, warp.meta?.hash || "", actionIndex)) ?? [];
848
+ const inputs = await this.cache.get(WarpCacheKey2.WarpExecutable(this.config.env, warp.meta?.hash || "", actionIndex)) ?? [];
799
849
  const resolvedInputs = extractResolvedInputValues(inputs);
800
850
  if (!tx) {
801
851
  return this.createFailedExecution(warp, actionIndex, resolvedInputs);
@@ -967,7 +1017,7 @@ var WarpSolanaExecutor = class {
967
1017
  this.chain = chain;
968
1018
  this.serializer = new WarpSolanaSerializer();
969
1019
  const providerConfig = getProviderConfig3(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
970
- this.connection = new Connection3(providerConfig.url, "confirmed");
1020
+ this.connection = new Connection4(providerConfig.url, "confirmed");
971
1021
  this.output = new WarpSolanaOutput(config, this.chain);
972
1022
  }
973
1023
  async createTransaction(executable) {
@@ -996,14 +1046,14 @@ var WarpSolanaExecutor = class {
996
1046
  }
997
1047
  const instructions = [];
998
1048
  if (executable.value > 0n) {
999
- instructions.push(SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(executable.value) }));
1049
+ instructions.push(SystemProgram2.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(executable.value) }));
1000
1050
  }
1001
1051
  if (executable.data) {
1002
1052
  const data = this.serializer.stringToTyped(executable.data);
1003
1053
  if (data && typeof data === "string") {
1004
1054
  const dataBuffer = Buffer.from(data, "base64");
1005
1055
  instructions.push(
1006
- new TransactionInstruction({
1056
+ new TransactionInstruction2({
1007
1057
  keys: [
1008
1058
  { pubkey: fromPubkey, isSigner: true, isWritable: true },
1009
1059
  { pubkey: destinationPubkey, isSigner: false, isWritable: true }
@@ -1032,9 +1082,9 @@ var WarpSolanaExecutor = class {
1032
1082
  const abiAccounts = parsedAbi?.instructions?.[action.func]?.accounts ?? null;
1033
1083
  const accounts = await this.buildInstructionAccounts(action, executable, fromPubkey, programId, abiAccounts);
1034
1084
  await this.ensureATAs(abiAccounts, accounts, fromPubkey, instructions);
1035
- instructions.push(new TransactionInstruction({ keys: accounts, programId, data: instructionData }));
1085
+ instructions.push(new TransactionInstruction2({ keys: accounts, programId, data: instructionData }));
1036
1086
  if (executable.value > 0n) {
1037
- instructions.push(SystemProgram.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
1087
+ instructions.push(SystemProgram2.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
1038
1088
  }
1039
1089
  return this.setTransactionDefaults(instructions, fromPubkey);
1040
1090
  }
@@ -1057,7 +1107,7 @@ var WarpSolanaExecutor = class {
1057
1107
  if (match) {
1058
1108
  const mintAddress = match[1];
1059
1109
  try {
1060
- const mintPubkey = new PublicKey3(mintAddress);
1110
+ const mintPubkey = new PublicKey4(mintAddress);
1061
1111
  const expectedAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
1062
1112
  const ataKey = expectedAta.toBase58();
1063
1113
  if (!createdATAs.has(ataKey)) {
@@ -1078,8 +1128,8 @@ var WarpSolanaExecutor = class {
1078
1128
  const mintAddress = match[1];
1079
1129
  const receiverAddress = match[2];
1080
1130
  try {
1081
- const mintPubkey = new PublicKey3(mintAddress);
1082
- const receiverPubkey = new PublicKey3(receiverAddress);
1131
+ const mintPubkey = new PublicKey4(mintAddress);
1132
+ const receiverPubkey = new PublicKey4(receiverAddress);
1083
1133
  const expectedAta = await getAssociatedTokenAddress(mintPubkey, receiverPubkey);
1084
1134
  const ataKey = expectedAta.toBase58();
1085
1135
  if (!createdATAs.has(ataKey)) {
@@ -1163,7 +1213,7 @@ var WarpSolanaExecutor = class {
1163
1213
  buffers.push(Buffer.from(String(arg), "utf8"));
1164
1214
  } else if (def.type === "publicKey" || def.type === "pubkey") {
1165
1215
  try {
1166
- const pubkey = new PublicKey3(arg);
1216
+ const pubkey = new PublicKey4(arg);
1167
1217
  buffers.push(Buffer.from(pubkey.toBuffer()));
1168
1218
  } catch {
1169
1219
  buffers.push(Buffer.from(String(arg), "utf8"));
@@ -1244,7 +1294,7 @@ var WarpSolanaExecutor = class {
1244
1294
  if (accountInput.input.as?.startsWith("USER_ATA:") || accountInput.input.as?.startsWith("RECEIVER_ATA:")) {
1245
1295
  return await this.resolveAccountPubkey(`{{${accountInput.input.as}}}`, fromPubkey);
1246
1296
  }
1247
- return new PublicKey3(address);
1297
+ return new PublicKey4(address);
1248
1298
  }
1249
1299
  interpolateAccountAddress(address, resolvedInputs) {
1250
1300
  if (!address.includes("{{")) return address;
@@ -1301,8 +1351,8 @@ var WarpSolanaExecutor = class {
1301
1351
  if (nativeTokenTransfers.length === 1 && splTokenTransfers.length === 0) {
1302
1352
  const transfer = nativeTokenTransfers[0];
1303
1353
  if (transfer.amount <= 0n) throw new Error("WarpSolanaExecutor: Native token transfer amount must be positive");
1304
- const fromPubkey = new PublicKey3(userWallet);
1305
- return this.setTransactionDefaults([SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(transfer.amount) })], fromPubkey);
1354
+ const fromPubkey = new PublicKey4(userWallet);
1355
+ return this.setTransactionDefaults([SystemProgram2.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(transfer.amount) })], fromPubkey);
1306
1356
  }
1307
1357
  if (nativeTokenTransfers.length === 0 && splTokenTransfers.length === 1) {
1308
1358
  return this.createSingleTokenTransfer(executable, splTokenTransfers[0], userWallet, destinationPubkey);
@@ -1311,8 +1361,8 @@ var WarpSolanaExecutor = class {
1311
1361
  throw new Error("WarpSolanaExecutor: Invalid transfer configuration");
1312
1362
  }
1313
1363
  async createSingleTokenTransfer(executable, transfer, userWallet, destinationPubkey) {
1314
- const mintAddress = new PublicKey3(transfer.identifier);
1315
- const fromPubkey = new PublicKey3(userWallet);
1364
+ const mintAddress = new PublicKey4(transfer.identifier);
1365
+ const fromPubkey = new PublicKey4(userWallet);
1316
1366
  const sourceTokenAccount = await getAssociatedTokenAddress(mintAddress, fromPubkey);
1317
1367
  const destinationTokenAccount = await getAssociatedTokenAddress(mintAddress, destinationPubkey);
1318
1368
  if (!await this.connection.getAccountInfo(sourceTokenAccount)) {
@@ -1330,7 +1380,7 @@ var WarpSolanaExecutor = class {
1330
1380
  if (action.type !== "query") throw new Error(`WarpSolanaExecutor: Invalid action type for executeQuery: ${action.type}`);
1331
1381
  if (!action.func) throw new Error("WarpSolanaExecutor: Query action must have a function name");
1332
1382
  if (!executable.destination) throw new Error("WarpSolanaExecutor: Query address is required");
1333
- const queryAddress = new PublicKey3(executable.destination);
1383
+ const queryAddress = new PublicKey4(executable.destination);
1334
1384
  const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
1335
1385
  let decodedResult = [];
1336
1386
  let isSuccess = true;
@@ -1398,7 +1448,7 @@ var WarpSolanaExecutor = class {
1398
1448
  }
1399
1449
  toPublicKey(address, errorMsg) {
1400
1450
  try {
1401
- return new PublicKey3(address);
1451
+ return new PublicKey4(address);
1402
1452
  } catch {
1403
1453
  throw new Error(`WarpSolanaExecutor: ${errorMsg}`);
1404
1454
  }
@@ -1447,7 +1497,7 @@ var WarpSolanaExecutor = class {
1447
1497
  if (!mintAddress || mintAddress.includes("{{")) {
1448
1498
  throw new Error(`Invalid USER_ATA placeholder: ${address}. Mint address must be resolved first.`);
1449
1499
  }
1450
- const mintPubkey = new PublicKey3(mintAddress);
1500
+ const mintPubkey = new PublicKey4(mintAddress);
1451
1501
  return await getAssociatedTokenAddress(mintPubkey, fromPubkey);
1452
1502
  }
1453
1503
  if (address.startsWith("{{RECEIVER_ATA:") && address.endsWith("}}")) {
@@ -1461,12 +1511,12 @@ var WarpSolanaExecutor = class {
1461
1511
  }
1462
1512
  if (mintAddress.includes(":")) mintAddress = mintAddress.split(":")[1];
1463
1513
  if (receiverAddress.includes(":")) receiverAddress = receiverAddress.split(":")[1];
1464
- const mintPubkey = new PublicKey3(mintAddress);
1465
- const receiverPubkey = new PublicKey3(receiverAddress);
1514
+ const mintPubkey = new PublicKey4(mintAddress);
1515
+ const receiverPubkey = new PublicKey4(receiverAddress);
1466
1516
  return await getAssociatedTokenAddress(mintPubkey, receiverPubkey);
1467
1517
  }
1468
1518
  }
1469
- return new PublicKey3(address);
1519
+ return new PublicKey4(address);
1470
1520
  }
1471
1521
  determineAccountFlags(accountDef, pubkey, fromPubkey) {
1472
1522
  const accountMeta = typeof accountDef === "object" ? accountDef : {};
@@ -1637,7 +1687,7 @@ import {
1637
1687
  initializeWalletCache
1638
1688
  } from "@joai/warps";
1639
1689
  import { createKeyPairSignerFromBytes } from "@solana/kit";
1640
- import { Connection as Connection4, Transaction as Transaction3, VersionedTransaction as VersionedTransaction4 } from "@solana/web3.js";
1690
+ import { Connection as Connection5, Transaction as Transaction3, VersionedTransaction as VersionedTransaction4 } from "@solana/web3.js";
1641
1691
  import { registerExactSvmScheme } from "@x402/svm/exact/client";
1642
1692
 
1643
1693
  // src/providers/MnemonicWalletProvider.ts
@@ -1650,6 +1700,7 @@ import {
1650
1700
  getWarpWalletPrivateKeyFromConfig,
1651
1701
  normalizeAndValidateMnemonic,
1652
1702
  normalizeMnemonic,
1703
+ removeWarpWalletFromConfig,
1653
1704
  setWarpWalletInConfig,
1654
1705
  validateMnemonicLength
1655
1706
  } from "@joai/warps";
@@ -1772,6 +1823,9 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
1772
1823
  mnemonic
1773
1824
  };
1774
1825
  }
1826
+ async delete(externalId) {
1827
+ removeWarpWalletFromConfig(this.config, this.chain.name);
1828
+ }
1775
1829
  getKeypair() {
1776
1830
  if (this.keypair) return this.keypair;
1777
1831
  const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
@@ -1790,6 +1844,7 @@ import {
1790
1844
  getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig4,
1791
1845
  getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
1792
1846
  getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
1847
+ removeWarpWalletFromConfig as removeWarpWalletFromConfig2,
1793
1848
  setWarpWalletInConfig as setWarpWalletInConfig2
1794
1849
  } from "@joai/warps";
1795
1850
  import bs583 from "bs58";
@@ -1897,6 +1952,9 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
1897
1952
  mnemonic: null
1898
1953
  };
1899
1954
  }
1955
+ async delete(externalId) {
1956
+ removeWarpWalletFromConfig2(this.config, this.chain.name);
1957
+ }
1900
1958
  getKeypair() {
1901
1959
  if (this.keypair) return this.keypair;
1902
1960
  const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
@@ -1924,7 +1982,7 @@ _PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
1924
1982
  var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
1925
1983
 
1926
1984
  // src/providers/ReadOnlyWalletProvider.ts
1927
- import { getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig5 } from "@joai/warps";
1985
+ import { getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig5, removeWarpWalletFromConfig as removeWarpWalletFromConfig3 } from "@joai/warps";
1928
1986
  var ReadOnlyWalletProvider = class {
1929
1987
  constructor(config, chain) {
1930
1988
  this.config = config;
@@ -1960,6 +2018,9 @@ var ReadOnlyWalletProvider = class {
1960
2018
  const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
1961
2019
  throw new Error(`Wallet can not be used for signing: ${address}`);
1962
2020
  }
2021
+ async delete(externalId) {
2022
+ removeWarpWalletFromConfig3(this.config, this.chain.name);
2023
+ }
1963
2024
  };
1964
2025
 
1965
2026
  // src/WarpSolanaWallet.ts
@@ -1970,7 +2031,7 @@ var WarpSolanaWallet = class {
1970
2031
  this.cachedAddress = null;
1971
2032
  this.cachedPublicKey = null;
1972
2033
  const providerConfig = getProviderConfig4(config, chain.name, config.env, chain.defaultApiUrl);
1973
- this.connection = new Connection4(providerConfig.url, "confirmed");
2034
+ this.connection = new Connection5(providerConfig.url, "confirmed");
1974
2035
  this.walletProvider = this.createProvider();
1975
2036
  this.initializeCache();
1976
2037
  }
@@ -2023,6 +2084,10 @@ var WarpSolanaWallet = class {
2023
2084
  const walletProvider = this.createProviderForOperation(provider);
2024
2085
  return await walletProvider.generate();
2025
2086
  }
2087
+ async delete(provider, externalId) {
2088
+ const walletProvider = this.createProviderForOperation(provider);
2089
+ await walletProvider.delete(externalId);
2090
+ }
2026
2091
  getAddress() {
2027
2092
  return this.cachedAddress;
2028
2093
  }
@@ -2071,29 +2136,51 @@ var WarpSolanaWallet = class {
2071
2136
  throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${provider}`);
2072
2137
  }
2073
2138
  resolveTransaction(tx) {
2074
- if (tx instanceof VersionedTransaction4) {
2075
- if (tx.version === void 0 || tx.version === "legacy") {
2076
- throw new Error("Transaction must be a VersionedTransaction (v0), not legacy");
2077
- }
2078
- return tx;
2079
- }
2139
+ const directVersionedTransaction = this.asVersionedTransaction(tx);
2140
+ if (directVersionedTransaction) return directVersionedTransaction;
2080
2141
  if (tx instanceof Transaction3) {
2081
2142
  throw new Error("Legacy Transaction format is not supported. All transactions must use VersionedTransaction (v0).");
2082
2143
  }
2083
- if (tx.transaction instanceof VersionedTransaction4) {
2084
- if (tx.transaction.version === void 0 || tx.transaction.version === "legacy") {
2085
- throw new Error("Transaction must be a VersionedTransaction (v0), not legacy");
2086
- }
2087
- return tx.transaction;
2088
- }
2089
- if (tx.transaction instanceof Transaction3) {
2144
+ const nestedTransaction = tx.transaction;
2145
+ const nestedVersionedTransaction = this.asVersionedTransaction(nestedTransaction);
2146
+ if (nestedVersionedTransaction) return nestedVersionedTransaction;
2147
+ if (nestedTransaction instanceof Transaction3) {
2090
2148
  throw new Error("Legacy Transaction format is not supported. All transactions must use VersionedTransaction (v0).");
2091
2149
  }
2092
- if (!tx.transaction) {
2150
+ const serializedTransaction = this.toSerializedTransactionBytes(nestedTransaction);
2151
+ if (serializedTransaction) {
2152
+ try {
2153
+ return this.asVersionedTransactionOrThrow(VersionedTransaction4.deserialize(serializedTransaction));
2154
+ } catch {
2155
+ throw new Error("Invalid serialized transaction format. Expected a VersionedTransaction payload.");
2156
+ }
2157
+ }
2158
+ if (!nestedTransaction) {
2093
2159
  throw new Error("Transaction must be signed before sending");
2094
2160
  }
2095
2161
  throw new Error("Invalid transaction format - only VersionedTransaction is supported");
2096
2162
  }
2163
+ asVersionedTransaction(tx) {
2164
+ if (!(tx instanceof VersionedTransaction4)) return null;
2165
+ return this.asVersionedTransactionOrThrow(tx);
2166
+ }
2167
+ asVersionedTransactionOrThrow(tx) {
2168
+ if (tx.version === void 0 || tx.version === "legacy") {
2169
+ throw new Error("Transaction must be a VersionedTransaction (v0), not legacy");
2170
+ }
2171
+ return tx;
2172
+ }
2173
+ toSerializedTransactionBytes(value) {
2174
+ if (value instanceof Uint8Array) return value;
2175
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) return new Uint8Array(value);
2176
+ if (Array.isArray(value) && value.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255)) {
2177
+ return Uint8Array.from(value);
2178
+ }
2179
+ if (typeof value === "string" && value.trim() !== "") {
2180
+ return Uint8Array.from(Buffer.from(value.trim(), "base64"));
2181
+ }
2182
+ return null;
2183
+ }
2097
2184
  async shouldSkipPreflight(transaction) {
2098
2185
  if (!transaction.signatures || transaction.signatures.length === 0 || !transaction.signatures.some((sig) => sig.some((b) => b !== 0))) {
2099
2186
  return false;