@vleap/warps-adapter-evm 0.2.0-beta.50 → 0.2.0-beta.52

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.d.cts CHANGED
@@ -175,6 +175,9 @@ declare class WarpEvmExecutor implements AdapterWarpExecutor {
175
175
  executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
176
176
  private estimateGasAndSetDefaults;
177
177
  verifyMessage(message: string, signature: string): Promise<string>;
178
+ private getPayableValue;
179
+ private findNativeTokenAsset;
180
+ private prepareNativeArgs;
178
181
  }
179
182
 
180
183
  declare class WarpEvmExplorer implements AdapterWarpExplorer {
package/dist/index.d.ts CHANGED
@@ -175,6 +175,9 @@ declare class WarpEvmExecutor implements AdapterWarpExecutor {
175
175
  executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
176
176
  private estimateGasAndSetDefaults;
177
177
  verifyMessage(message: string, signature: string): Promise<string>;
178
+ private getPayableValue;
179
+ private findNativeTokenAsset;
180
+ private prepareNativeArgs;
178
181
  }
179
182
 
180
183
  declare class WarpEvmExplorer implements AdapterWarpExplorer {
package/dist/index.js CHANGED
@@ -466,6 +466,7 @@ var WarpEvmDataLoader = class {
466
466
  }
467
467
  async getAsset(identifier) {
468
468
  try {
469
+ console.log("WarpEvmDataLoader.getAsset", identifier);
469
470
  if (identifier === this.chain.nativeToken.identifier) {
470
471
  return this.chain.nativeToken;
471
472
  }
@@ -474,6 +475,7 @@ var WarpEvmDataLoader = class {
474
475
  if (cachedAsset) {
475
476
  return cachedAsset;
476
477
  }
478
+ console.log("WarpEvmDataLoader.getAsset: findKnownTokenById", this.chain.name, this.config.env, identifier);
477
479
  const knownToken = findKnownTokenById(this.chain.name, this.config.env, identifier);
478
480
  if (knownToken) {
479
481
  return {
@@ -494,7 +496,7 @@ var WarpEvmDataLoader = class {
494
496
  symbol: metadata.symbol,
495
497
  amount: 0n,
496
498
  decimals: metadata.decimals,
497
- logoUrl: metadata.logoUrl || ""
499
+ logoUrl: metadata.logoUrl
498
500
  };
499
501
  this.cache.set(cacheKey, asset, import_warps8.CacheTtl.OneHour);
500
502
  return asset;
@@ -597,7 +599,7 @@ var WarpEvmConstants = {
597
599
  Swap: 2e5
598
600
  },
599
601
  GasPrice: {
600
- Default: "20000000000"
602
+ Default: "1200010"
601
603
  },
602
604
  Validation: {
603
605
  MinGasLimit: 21e3,
@@ -1017,11 +1019,16 @@ var WarpEvmExecutor = class {
1017
1019
  } catch {
1018
1020
  iface = new import_ethers4.ethers.Interface([action.abi]);
1019
1021
  }
1020
- const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
1022
+ const funcFragment = iface.getFunction(action.func);
1023
+ if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
1024
+ const nativeArgs = this.prepareNativeArgs(executable.args, funcFragment);
1021
1025
  const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
1026
+ const value = this.getPayableValue(executable, funcFragment);
1027
+ console.log("Encoded data:", encodedData);
1028
+ console.log("Value:", value);
1022
1029
  const tx = {
1023
1030
  to: executable.destination,
1024
- value: executable.value,
1031
+ value,
1025
1032
  data: encodedData
1026
1033
  };
1027
1034
  return this.estimateGasAndSetDefaults(tx, userWallet);
@@ -1075,7 +1082,9 @@ var WarpEvmExecutor = class {
1075
1082
  } catch {
1076
1083
  iface = new import_ethers4.ethers.Interface([action.abi]);
1077
1084
  }
1078
- const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
1085
+ const funcFragment = iface.getFunction(action.func);
1086
+ if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
1087
+ const nativeArgs = this.prepareNativeArgs(executable.args, funcFragment);
1079
1088
  const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
1080
1089
  const result = await this.provider.call({
1081
1090
  to: executable.destination,
@@ -1090,9 +1099,7 @@ var WarpEvmExecutor = class {
1090
1099
  executable.resolvedInputs
1091
1100
  );
1092
1101
  const next = (0, import_warps11.getNextInfo)(this.config, [], executable.warp, executable.action, output);
1093
- const destinationInput = executable.resolvedInputs.find(
1094
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1095
- );
1102
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1096
1103
  const destination = destinationInput?.value || executable.destination;
1097
1104
  const resolvedInputs = (0, import_warps11.extractResolvedInputValues)(executable.resolvedInputs);
1098
1105
  return {
@@ -1110,9 +1117,7 @@ var WarpEvmExecutor = class {
1110
1117
  resolvedInputs
1111
1118
  };
1112
1119
  } catch (error) {
1113
- const destinationInput = executable.resolvedInputs.find(
1114
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1115
- );
1120
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1116
1121
  const destination = destinationInput?.value || executable.destination;
1117
1122
  const resolvedInputs = (0, import_warps11.extractResolvedInputValues)(executable.resolvedInputs);
1118
1123
  return {
@@ -1190,6 +1195,53 @@ var WarpEvmExecutor = class {
1190
1195
  throw new Error(`Failed to verify message: ${error}`);
1191
1196
  }
1192
1197
  }
1198
+ getPayableValue(executable, funcFragment) {
1199
+ if (funcFragment.stateMutability !== "payable") {
1200
+ return executable.value;
1201
+ }
1202
+ const nativeTokenId = this.chain.nativeToken?.identifier;
1203
+ const zeroAddress = "0x0000000000000000000000000000000000000000";
1204
+ const nativeTokenTransfer = nativeTokenId ? executable.transfers.find((transfer) => transfer.identifier === nativeTokenId || transfer.identifier === zeroAddress) : void 0;
1205
+ if (nativeTokenTransfer) {
1206
+ return nativeTokenTransfer.amount;
1207
+ }
1208
+ const nativeTokenAsset = this.findNativeTokenAsset(executable.resolvedInputs, nativeTokenId, zeroAddress);
1209
+ if (nativeTokenAsset) {
1210
+ return nativeTokenAsset.amount;
1211
+ }
1212
+ return executable.value;
1213
+ }
1214
+ findNativeTokenAsset(resolvedInputs, nativeTokenId, zeroAddress) {
1215
+ for (const input of resolvedInputs) {
1216
+ if (input.input.type === "asset" && input.value) {
1217
+ const [, assetValue] = this.serializer.coreSerializer.stringToNative(input.value);
1218
+ const asset = assetValue;
1219
+ if (asset && "amount" in asset) {
1220
+ if (asset.identifier === nativeTokenId || asset.identifier === zeroAddress) {
1221
+ return asset;
1222
+ }
1223
+ }
1224
+ }
1225
+ }
1226
+ return null;
1227
+ }
1228
+ prepareNativeArgs(args, funcFragment) {
1229
+ return args.map((arg, index) => {
1230
+ const nativeValue = this.serializer.coreSerializer.stringToNative(arg)[1];
1231
+ const paramType = funcFragment.inputs[index]?.type;
1232
+ if (paramType === "bytes32" && typeof nativeValue === "string") {
1233
+ let hexValue = nativeValue;
1234
+ if (!hexValue.startsWith("0x")) {
1235
+ hexValue = "0x" + hexValue;
1236
+ }
1237
+ if (hexValue.length !== 66) {
1238
+ hexValue = import_ethers4.ethers.zeroPadValue(hexValue, 32);
1239
+ }
1240
+ return hexValue;
1241
+ }
1242
+ return nativeValue;
1243
+ });
1244
+ }
1193
1245
  };
1194
1246
 
1195
1247
  // src/WarpEvmExplorer.ts