@vleap/warps-adapter-solana 0.1.0-beta.2 → 0.1.0-beta.4

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
@@ -54,10 +54,10 @@ var SolanaExplorerMap = {
54
54
  var ExplorerUrls = {
55
55
  ["solscan" /* Solscan */]: "https://solscan.io",
56
56
  ["solscan_mainnet" /* SolscanMainnet */]: "https://solscan.io",
57
- ["solscan_devnet" /* SolscanDevnet */]: "https://solscan.io/?cluster=devnet",
57
+ ["solscan_devnet" /* SolscanDevnet */]: "https://solscan.io",
58
58
  ["solana_explorer" /* SolanaExplorer */]: "https://explorer.solana.com",
59
59
  ["solana_explorer_mainnet" /* SolanaExplorerMainnet */]: "https://explorer.solana.com",
60
- ["solana_explorer_devnet" /* SolanaExplorerDevnet */]: "https://explorer.solana.com/?cluster=devnet"
60
+ ["solana_explorer_devnet" /* SolanaExplorerDevnet */]: "https://explorer.solana.com"
61
61
  };
62
62
  var SolanaExplorerNames = {
63
63
  mainnet: ["solscan_mainnet" /* SolscanMainnet */, "solana_explorer_mainnet" /* SolanaExplorerMainnet */],
@@ -329,6 +329,8 @@ var WarpSolanaDataLoader = class {
329
329
  };
330
330
 
331
331
  // src/WarpSolanaExecutor.ts
332
+ import { createAssociatedTokenAccountInstruction, createTransferInstruction, getAssociatedTokenAddress } from "@solana/spl-token";
333
+ import { ComputeBudgetProgram, Connection as Connection3, PublicKey as PublicKey3, SystemProgram, Transaction, TransactionInstruction } from "@solana/web3.js";
332
334
  import {
333
335
  applyOutputToMessages,
334
336
  extractResolvedInputValues as extractResolvedInputValues2,
@@ -337,8 +339,6 @@ import {
337
339
  getWarpActionByIndex,
338
340
  getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig2
339
341
  } from "@vleap/warps";
340
- import { Connection as Connection3, PublicKey as PublicKey3, SystemProgram, Transaction, TransactionInstruction, ComputeBudgetProgram } from "@solana/web3.js";
341
- import { createTransferInstruction, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction } from "@solana/spl-token";
342
342
 
343
343
  // src/WarpSolanaOutput.ts
344
344
  import {
@@ -741,12 +741,12 @@ var WarpSolanaExecutor = class {
741
741
  async createTransferTransaction(executable) {
742
742
  const userWallet = getWarpWalletAddressFromConfig2(this.config, executable.chain.name);
743
743
  if (!userWallet) throw new Error("WarpSolanaExecutor: createTransfer - user address not set");
744
+ if (!executable.destination) throw new Error("WarpSolanaExecutor: Destination address is required");
744
745
  let destinationPubkey;
745
746
  try {
746
- if (!executable.destination) throw new Error("WarpSolanaExecutor: Destination address is required");
747
747
  destinationPubkey = new PublicKey3(executable.destination);
748
- } catch {
749
- throw new Error(`WarpSolanaExecutor: Invalid destination address: ${executable.destination}`);
748
+ } catch (error) {
749
+ throw new Error("WarpSolanaExecutor: Invalid destination address");
750
750
  }
751
751
  if (executable.transfers && executable.transfers.length > 0) {
752
752
  return this.createTokenTransferTransaction(executable, userWallet, destinationPubkey);
@@ -754,13 +754,7 @@ var WarpSolanaExecutor = class {
754
754
  const fromPubkey = new PublicKey3(userWallet);
755
755
  const transaction = new Transaction();
756
756
  if (executable.value > 0n) {
757
- transaction.add(
758
- SystemProgram.transfer({
759
- fromPubkey,
760
- toPubkey: destinationPubkey,
761
- lamports: Number(executable.value)
762
- })
763
- );
757
+ transaction.add(SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(executable.value) }));
764
758
  }
765
759
  if (executable.data) {
766
760
  const data = this.serializer.stringToTyped(executable.data);
@@ -784,13 +778,8 @@ var WarpSolanaExecutor = class {
784
778
  if (!userWallet) throw new Error("WarpSolanaExecutor: createContractCall - user address not set");
785
779
  const action = getWarpActionByIndex(executable.warp, executable.action);
786
780
  if (!action || !("func" in action) || !action.func) throw new Error("WarpSolanaExecutor: Contract action must have a function name");
787
- let programId;
788
- try {
789
- if (!executable.destination) throw new Error("WarpSolanaExecutor: Contract address is required");
790
- programId = new PublicKey3(executable.destination);
791
- } catch {
792
- throw new Error(`WarpSolanaExecutor: Invalid contract address: ${executable.destination}`);
793
- }
781
+ if (!executable.destination) throw new Error("WarpSolanaExecutor: Contract address is required");
782
+ const programId = new PublicKey3(executable.destination);
794
783
  const fromPubkey = new PublicKey3(userWallet);
795
784
  const transaction = new Transaction();
796
785
  try {
@@ -819,13 +808,7 @@ var WarpSolanaExecutor = class {
819
808
  });
820
809
  transaction.add(instruction);
821
810
  if (executable.value > 0n) {
822
- transaction.add(
823
- SystemProgram.transfer({
824
- fromPubkey,
825
- toPubkey: programId,
826
- lamports: Number(executable.value)
827
- })
828
- );
811
+ transaction.add(SystemProgram.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
829
812
  }
830
813
  return this.setTransactionDefaults(transaction, fromPubkey);
831
814
  } catch (error) {
@@ -837,10 +820,10 @@ var WarpSolanaExecutor = class {
837
820
  try {
838
821
  const data = Buffer.alloc(8);
839
822
  if (instructionDef.discriminator && Buffer.isBuffer(instructionDef.discriminator)) {
840
- instructionDef.discriminator.copy(data, 0);
823
+ data.set(instructionDef.discriminator.subarray(0, Math.min(8, instructionDef.discriminator.length)), 0);
841
824
  } else {
842
- const hash = Buffer.from(funcName).slice(0, 8);
843
- hash.copy(data, 0);
825
+ const hash = Buffer.from(funcName).subarray(0, 8);
826
+ data.set(hash, 0);
844
827
  }
845
828
  if (args.length > 0 && instructionDef.args) {
846
829
  const encodedArgs = this.encodeArgs(args, instructionDef.args);
@@ -852,9 +835,9 @@ var WarpSolanaExecutor = class {
852
835
  }
853
836
  }
854
837
  encodeBasicInstructionData(args, funcName) {
855
- const funcHash = Buffer.from(funcName).slice(0, 8);
838
+ const funcHash = Buffer.from(funcName).subarray(0, 8);
856
839
  const data = Buffer.alloc(8);
857
- funcHash.copy(data, 0);
840
+ data.set(funcHash, 0);
858
841
  if (args.length > 0) {
859
842
  const encodedArgs = args.map((arg) => {
860
843
  if (typeof arg === "string") {
@@ -885,7 +868,7 @@ var WarpSolanaExecutor = class {
885
868
  const size = def.type === "u128" ? 16 : 8;
886
869
  const buf = Buffer.alloc(size);
887
870
  if (size === 16) {
888
- buf.writeBigUInt64LE(num & 0xFFFFFFFFFFFFFFFFn, 0);
871
+ buf.writeBigUInt64LE(num & 0xffffffffffffffffn, 0);
889
872
  buf.writeBigUInt64LE(num >> 64n, 8);
890
873
  } else {
891
874
  buf.writeBigUInt64LE(num, 0);
@@ -975,23 +958,9 @@ var WarpSolanaExecutor = class {
975
958
  }
976
959
  const destinationAccountInfo = await this.connection.getAccountInfo(destinationTokenAccount);
977
960
  if (!destinationAccountInfo) {
978
- transaction.add(
979
- createAssociatedTokenAccountInstruction(
980
- fromPubkey,
981
- destinationTokenAccount,
982
- destinationPubkey,
983
- mintAddress
984
- )
985
- );
961
+ transaction.add(createAssociatedTokenAccountInstruction(fromPubkey, destinationTokenAccount, destinationPubkey, mintAddress));
986
962
  }
987
- transaction.add(
988
- createTransferInstruction(
989
- sourceTokenAccount,
990
- destinationTokenAccount,
991
- fromPubkey,
992
- Number(transfer.amount)
993
- )
994
- );
963
+ transaction.add(createTransferInstruction(sourceTokenAccount, destinationTokenAccount, fromPubkey, Number(transfer.amount)));
995
964
  return this.setTransactionDefaults(transaction, fromPubkey);
996
965
  }
997
966
  async executeQuery(executable) {
@@ -1048,9 +1017,7 @@ var WarpSolanaExecutor = class {
1048
1017
  executable.resolvedInputs
1049
1018
  );
1050
1019
  const next = getNextInfo(this.config, [], executable.warp, executable.action, output);
1051
- const destinationInput = executable.resolvedInputs.find(
1052
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1053
- );
1020
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1054
1021
  const destination = destinationInput?.value || executable.destination;
1055
1022
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1056
1023
  return {
@@ -1069,9 +1036,7 @@ var WarpSolanaExecutor = class {
1069
1036
  };
1070
1037
  } catch (error) {
1071
1038
  const errorMessage = error instanceof Error ? error.message : String(error);
1072
- const destinationInput = executable.resolvedInputs.find(
1073
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1074
- );
1039
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1075
1040
  const destination = destinationInput?.value || executable.destination;
1076
1041
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1077
1042
  return {
@@ -1107,12 +1072,8 @@ var WarpSolanaExecutor = class {
1107
1072
  transaction.feePayer = fromPubkey;
1108
1073
  }
1109
1074
  const instructions = transaction.instructions;
1110
- const hasTransfer = instructions.some(
1111
- (ix) => ix.programId.equals(SystemProgram.programId) && ix.data.length === 4
1112
- );
1113
- const hasTokenTransfer = instructions.some(
1114
- (ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram
1115
- );
1075
+ const hasTransfer = instructions.some((ix) => ix.programId.equals(SystemProgram.programId) && ix.data.length === 4);
1076
+ const hasTokenTransfer = instructions.some((ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram);
1116
1077
  let computeUnits = WarpSolanaConstants.ComputeUnitLimit.Default;
1117
1078
  if (hasTransfer && !hasTokenTransfer) {
1118
1079
  computeUnits = WarpSolanaConstants.ComputeUnitLimit.Transfer;
@@ -1121,16 +1082,13 @@ var WarpSolanaExecutor = class {
1121
1082
  } else {
1122
1083
  computeUnits = WarpSolanaConstants.ComputeUnitLimit.ContractCall;
1123
1084
  }
1124
- transaction.add(
1125
- ComputeBudgetProgram.setComputeUnitLimit({
1126
- units: computeUnits
1127
- })
1128
- );
1129
- transaction.add(
1130
- ComputeBudgetProgram.setComputeUnitPrice({
1131
- microLamports: WarpSolanaConstants.PriorityFee.Default
1132
- })
1133
- );
1085
+ const computeUnitLimitIx = ComputeBudgetProgram.setComputeUnitLimit({
1086
+ units: computeUnits
1087
+ });
1088
+ const computeUnitPriceIx = ComputeBudgetProgram.setComputeUnitPrice({
1089
+ microLamports: WarpSolanaConstants.PriorityFee.Default
1090
+ });
1091
+ transaction.instructions = [computeUnitLimitIx, computeUnitPriceIx, ...transaction.instructions];
1134
1092
  return transaction;
1135
1093
  } catch (error) {
1136
1094
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -1172,26 +1130,46 @@ var WarpSolanaExplorer = class {
1172
1130
  }
1173
1131
  getAccountUrl(address, explorer) {
1174
1132
  const baseUrl = this.getExplorerUrlByName(explorer);
1133
+ if (baseUrl.includes("?")) {
1134
+ const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
1135
+ return `${baseUrl}/account/${address}${cluster2}`;
1136
+ }
1175
1137
  const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
1176
1138
  return `${baseUrl}/account/${address}${cluster}`;
1177
1139
  }
1178
1140
  getTransactionUrl(hash, explorer) {
1179
1141
  const baseUrl = this.getExplorerUrlByName(explorer);
1142
+ if (baseUrl.includes("?")) {
1143
+ const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
1144
+ return `${baseUrl}/tx/${hash}${cluster2}`;
1145
+ }
1180
1146
  const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
1181
1147
  return `${baseUrl}/tx/${hash}${cluster}`;
1182
1148
  }
1183
1149
  getBlockUrl(blockNumber, explorer) {
1184
1150
  const baseUrl = this.getExplorerUrlByName(explorer);
1151
+ if (baseUrl.includes("?")) {
1152
+ const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
1153
+ return `${baseUrl}/block/${blockNumber}${cluster2}`;
1154
+ }
1185
1155
  const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
1186
1156
  return `${baseUrl}/block/${blockNumber}${cluster}`;
1187
1157
  }
1188
1158
  getAssetUrl(identifier, explorer) {
1189
1159
  const baseUrl = this.getExplorerUrlByName(explorer);
1160
+ if (baseUrl.includes("?")) {
1161
+ const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
1162
+ return `${baseUrl}/token/${identifier}${cluster2}`;
1163
+ }
1190
1164
  const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
1191
1165
  return `${baseUrl}/token/${identifier}${cluster}`;
1192
1166
  }
1193
1167
  getContractUrl(address, explorer) {
1194
1168
  const baseUrl = this.getExplorerUrlByName(explorer);
1169
+ if (baseUrl.includes("?")) {
1170
+ const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
1171
+ return `${baseUrl}/account/${address}${cluster2}`;
1172
+ }
1195
1173
  const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
1196
1174
  return `${baseUrl}/account/${address}${cluster}`;
1197
1175
  }
@@ -1272,7 +1250,7 @@ import {
1272
1250
  } from "@vleap/warps";
1273
1251
  import { Connection as Connection4, Keypair, Transaction as Transaction2, VersionedTransaction } from "@solana/web3.js";
1274
1252
  import * as bip39 from "@scure/bip39";
1275
- import { wordlist } from "@scure/bip39/wordlists/english";
1253
+ import { wordlist } from "@scure/bip39/wordlists/english.js";
1276
1254
  import bs582 from "bs58";
1277
1255
  var WarpSolanaWallet = class {
1278
1256
  constructor(config, chain) {