@vleap/warps-adapter-evm 0.2.0-alpha.32 → 0.2.0-alpha.34

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
@@ -713,6 +713,20 @@ var WarpEvmResults = class {
713
713
  this.provider = new ethers3.JsonRpcProvider(apiUrl, network);
714
714
  }
715
715
  async getTransactionExecutionResults(warp, tx) {
716
+ if (!tx) {
717
+ return {
718
+ success: false,
719
+ warp,
720
+ action: 0,
721
+ user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
722
+ txHash: "",
723
+ tx: null,
724
+ next: null,
725
+ values: { string: [], native: [] },
726
+ results: {},
727
+ messages: {}
728
+ };
729
+ }
716
730
  const success = tx.status === 1;
717
731
  const gasUsed = tx.gasUsed?.toString() || "0";
718
732
  const gasPrice = tx.gasPrice?.toString() || "0";
@@ -720,35 +734,37 @@ var WarpEvmResults = class {
720
734
  const transactionHash = tx.hash;
721
735
  const logs = tx.logs.map((log) => ({
722
736
  address: log.address,
723
- topics: log.topics,
737
+ topics: [...log.topics],
724
738
  data: log.data,
725
739
  blockNumber: log.blockNumber?.toString() || "0",
726
740
  transactionHash: log.transactionHash,
727
741
  index: log.index?.toString() || "0"
728
742
  }));
743
+ const rawValues = [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []];
744
+ const stringValues = rawValues.map((v) => String(v));
729
745
  return {
730
746
  success,
731
747
  warp,
732
748
  action: 0,
733
- user: getWarpWalletAddressFromConfig(this.config, "evm"),
749
+ user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
734
750
  txHash: transactionHash,
735
751
  tx,
736
752
  next: null,
737
- values: [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []],
738
- valuesRaw: [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []],
753
+ values: { string: stringValues, native: rawValues },
739
754
  results: {},
740
755
  messages: {}
741
756
  };
742
757
  }
743
758
  async extractQueryResults(warp, typedValues, actionIndex, inputs) {
744
- const values = typedValues.map((t) => this.serializer.typedToString(t));
745
- const valuesRaw = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
759
+ const stringValues = typedValues.map((t) => this.serializer.typedToString(t));
760
+ const nativeValues = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
761
+ const values = { string: stringValues, native: nativeValues };
746
762
  let results = {};
747
- if (!warp.results) return { values, valuesRaw, results };
763
+ if (!warp.results) return { values, results };
748
764
  const getNestedValue = (path) => {
749
765
  const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
750
766
  if (indices.length === 0) return void 0;
751
- let value = valuesRaw[indices[0]];
767
+ let value = nativeValues[indices[0]];
752
768
  for (let i = 1; i < indices.length; i++) {
753
769
  if (value === void 0 || value === null) return void 0;
754
770
  value = value[indices[i]];
@@ -768,7 +784,7 @@ var WarpEvmResults = class {
768
784
  results[key] = path;
769
785
  }
770
786
  }
771
- return { values, valuesRaw, results: await evaluateResultsCommon(warp, results, actionIndex, inputs, this.serializer.coreSerializer) };
787
+ return { values, results: await evaluateResultsCommon(warp, results, actionIndex, inputs, this.serializer.coreSerializer) };
772
788
  }
773
789
  async getTransactionStatus(txHash) {
774
790
  try {
@@ -923,7 +939,7 @@ var WarpEvmExecutor = class {
923
939
  });
924
940
  const decodedResult = iface.decodeFunctionResult(action.func, result);
925
941
  const isSuccess = true;
926
- const { values, valuesRaw, results } = await this.results.extractQueryResults(
942
+ const { values, results } = await this.results.extractQueryResults(
927
943
  executable.warp,
928
944
  decodedResult,
929
945
  executable.action,
@@ -939,7 +955,6 @@ var WarpEvmExecutor = class {
939
955
  tx: null,
940
956
  next,
941
957
  values,
942
- valuesRaw,
943
958
  results,
944
959
  messages: applyResultsToMessages(executable.warp, results)
945
960
  };
@@ -952,8 +967,7 @@ var WarpEvmExecutor = class {
952
967
  txHash: null,
953
968
  tx: null,
954
969
  next: null,
955
- values: [],
956
- valuesRaw: [],
970
+ values: { string: [], native: [] },
957
971
  results: {},
958
972
  messages: {}
959
973
  };
@@ -1153,22 +1167,22 @@ var WarpEvmExplorer = class {
1153
1167
  };
1154
1168
 
1155
1169
  // src/WarpEvmWallet.ts
1156
- import { getWarpWalletPrivateKeyFromConfig } from "@vleap/warps";
1170
+ import {
1171
+ getProviderUrl as getProviderUrl4,
1172
+ getWarpWalletMnemonicFromConfig,
1173
+ getWarpWalletPrivateKeyFromConfig
1174
+ } from "@vleap/warps";
1157
1175
  import { ethers as ethers5 } from "ethers";
1158
1176
  var WarpEvmWallet = class {
1159
1177
  constructor(config, chain) {
1160
1178
  this.config = config;
1161
1179
  this.chain = chain;
1162
- this.wallet = null;
1163
- this.provider = new ethers5.JsonRpcProvider(chain.defaultApiUrl || "https://rpc.sepolia.org");
1180
+ const apiUrl = getProviderUrl4(config, chain.name, config.env, chain.defaultApiUrl);
1181
+ this.provider = new ethers5.JsonRpcProvider(apiUrl);
1164
1182
  }
1165
1183
  async signTransaction(tx) {
1166
- if (!tx || typeof tx !== "object") {
1167
- throw new Error("Invalid transaction object");
1168
- }
1169
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1170
- if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
1171
- const wallet = new ethers5.Wallet(privateKey);
1184
+ if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1185
+ const wallet = this.getWallet();
1172
1186
  const txRequest = {
1173
1187
  to: tx.to,
1174
1188
  data: tx.data,
@@ -1183,22 +1197,17 @@ var WarpEvmWallet = class {
1183
1197
  return { ...tx, signature: signedTx };
1184
1198
  }
1185
1199
  async signMessage(message) {
1186
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1187
- if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
1188
- const wallet = new ethers5.Wallet(privateKey);
1189
- return await wallet.signMessage(message);
1200
+ const wallet = this.getWallet();
1201
+ const signature = await wallet.signMessage(message);
1202
+ return signature;
1190
1203
  }
1191
1204
  async sendTransaction(tx) {
1192
- if (!tx || typeof tx !== "object") {
1193
- throw new Error("Invalid transaction object");
1194
- }
1195
- if (!tx.signature) {
1196
- throw new Error("Transaction must be signed before sending");
1197
- }
1198
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1199
- if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
1200
- const wallet = new ethers5.Wallet(privateKey).connect(this.provider);
1201
- const txResponse = await wallet.sendTransaction(tx);
1205
+ if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1206
+ if (!tx.signature) throw new Error("Transaction must be signed before sending");
1207
+ const wallet = this.getWallet();
1208
+ if (!wallet) throw new Error("Wallet not initialized - no private key provided");
1209
+ const connectedWallet = wallet.connect(this.provider);
1210
+ const txResponse = await connectedWallet.sendTransaction(tx);
1202
1211
  return txResponse.hash;
1203
1212
  }
1204
1213
  create(mnemonic) {
@@ -1210,11 +1219,16 @@ var WarpEvmWallet = class {
1210
1219
  return { address: wallet.address, privateKey: wallet.privateKey, mnemonic: wallet.mnemonic?.phrase || "" };
1211
1220
  }
1212
1221
  getAddress() {
1213
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1214
- if (!privateKey) return null;
1215
- const wallet = new ethers5.Wallet(privateKey);
1222
+ const wallet = this.getWallet();
1216
1223
  return wallet.address;
1217
1224
  }
1225
+ getWallet() {
1226
+ const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1227
+ if (privateKey) return new ethers5.Wallet(privateKey);
1228
+ const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
1229
+ if (mnemonic) return ethers5.Wallet.fromPhrase(mnemonic);
1230
+ throw new Error("No private key or mnemonic provided");
1231
+ }
1218
1232
  };
1219
1233
 
1220
1234
  // src/chains/common.ts