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

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
@@ -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 {
@@ -837,14 +837,14 @@ var WarpSolanaExecutor = class {
837
837
  try {
838
838
  const data = Buffer.alloc(8);
839
839
  if (instructionDef.discriminator && Buffer.isBuffer(instructionDef.discriminator)) {
840
- instructionDef.discriminator.copy(data, 0);
840
+ data.set(instructionDef.discriminator.subarray(0, Math.min(8, instructionDef.discriminator.length)), 0);
841
841
  } else {
842
- const hash = Buffer.from(funcName).slice(0, 8);
843
- hash.copy(data, 0);
842
+ const hash = Buffer.from(funcName).subarray(0, 8);
843
+ data.set(hash, 0);
844
844
  }
845
845
  if (args.length > 0 && instructionDef.args) {
846
846
  const encodedArgs = this.encodeArgs(args, instructionDef.args);
847
- return Buffer.concat([data, encodedArgs]);
847
+ return Buffer.from([...data, ...encodedArgs]);
848
848
  }
849
849
  return data;
850
850
  } catch {
@@ -852,9 +852,9 @@ var WarpSolanaExecutor = class {
852
852
  }
853
853
  }
854
854
  encodeBasicInstructionData(args, funcName) {
855
- const funcHash = Buffer.from(funcName).slice(0, 8);
855
+ const funcHash = Buffer.from(funcName).subarray(0, 8);
856
856
  const data = Buffer.alloc(8);
857
- funcHash.copy(data, 0);
857
+ data.set(funcHash, 0);
858
858
  if (args.length > 0) {
859
859
  const encodedArgs = args.map((arg) => {
860
860
  if (typeof arg === "string") {
@@ -871,7 +871,7 @@ var WarpSolanaExecutor = class {
871
871
  }
872
872
  return Buffer.from(String(arg), "utf8");
873
873
  });
874
- return Buffer.concat([data, ...encodedArgs]);
874
+ return Buffer.from([...data, ...encodedArgs]);
875
875
  }
876
876
  return data;
877
877
  }
@@ -885,7 +885,7 @@ var WarpSolanaExecutor = class {
885
885
  const size = def.type === "u128" ? 16 : 8;
886
886
  const buf = Buffer.alloc(size);
887
887
  if (size === 16) {
888
- buf.writeBigUInt64LE(num & 0xFFFFFFFFFFFFFFFFn, 0);
888
+ buf.writeBigUInt64LE(num & 0xffffffffffffffffn, 0);
889
889
  buf.writeBigUInt64LE(num >> 64n, 8);
890
890
  } else {
891
891
  buf.writeBigUInt64LE(num, 0);
@@ -904,7 +904,7 @@ var WarpSolanaExecutor = class {
904
904
  buffers.push(Buffer.from(String(arg), "utf8"));
905
905
  }
906
906
  }
907
- return Buffer.concat(buffers);
907
+ return Buffer.from(buffers.flatMap((buf) => Array.from(buf)));
908
908
  }
909
909
  buildInstructionAccounts(action, executable, fromPubkey, programId) {
910
910
  const accounts = [
@@ -975,23 +975,9 @@ var WarpSolanaExecutor = class {
975
975
  }
976
976
  const destinationAccountInfo = await this.connection.getAccountInfo(destinationTokenAccount);
977
977
  if (!destinationAccountInfo) {
978
- transaction.add(
979
- createAssociatedTokenAccountInstruction(
980
- fromPubkey,
981
- destinationTokenAccount,
982
- destinationPubkey,
983
- mintAddress
984
- )
985
- );
978
+ transaction.add(createAssociatedTokenAccountInstruction(fromPubkey, destinationTokenAccount, destinationPubkey, mintAddress));
986
979
  }
987
- transaction.add(
988
- createTransferInstruction(
989
- sourceTokenAccount,
990
- destinationTokenAccount,
991
- fromPubkey,
992
- Number(transfer.amount)
993
- )
994
- );
980
+ transaction.add(createTransferInstruction(sourceTokenAccount, destinationTokenAccount, fromPubkey, Number(transfer.amount)));
995
981
  return this.setTransactionDefaults(transaction, fromPubkey);
996
982
  }
997
983
  async executeQuery(executable) {
@@ -1048,9 +1034,7 @@ var WarpSolanaExecutor = class {
1048
1034
  executable.resolvedInputs
1049
1035
  );
1050
1036
  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
- );
1037
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1054
1038
  const destination = destinationInput?.value || executable.destination;
1055
1039
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1056
1040
  return {
@@ -1069,9 +1053,7 @@ var WarpSolanaExecutor = class {
1069
1053
  };
1070
1054
  } catch (error) {
1071
1055
  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
- );
1056
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1075
1057
  const destination = destinationInput?.value || executable.destination;
1076
1058
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1077
1059
  return {
@@ -1107,12 +1089,8 @@ var WarpSolanaExecutor = class {
1107
1089
  transaction.feePayer = fromPubkey;
1108
1090
  }
1109
1091
  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
- );
1092
+ const hasTransfer = instructions.some((ix) => ix.programId.equals(SystemProgram.programId) && ix.data.length === 4);
1093
+ const hasTokenTransfer = instructions.some((ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram);
1116
1094
  let computeUnits = WarpSolanaConstants.ComputeUnitLimit.Default;
1117
1095
  if (hasTransfer && !hasTokenTransfer) {
1118
1096
  computeUnits = WarpSolanaConstants.ComputeUnitLimit.Transfer;