@vleap/warps-adapter-evm 0.2.0-beta.51 → 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
@@ -599,7 +599,7 @@ var WarpEvmConstants = {
599
599
  Swap: 2e5
600
600
  },
601
601
  GasPrice: {
602
- Default: "20000000000"
602
+ Default: "1200010"
603
603
  },
604
604
  Validation: {
605
605
  MinGasLimit: 21e3,
@@ -1019,11 +1019,16 @@ var WarpEvmExecutor = class {
1019
1019
  } catch {
1020
1020
  iface = new import_ethers4.ethers.Interface([action.abi]);
1021
1021
  }
1022
- 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);
1023
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);
1024
1029
  const tx = {
1025
1030
  to: executable.destination,
1026
- value: executable.value,
1031
+ value,
1027
1032
  data: encodedData
1028
1033
  };
1029
1034
  return this.estimateGasAndSetDefaults(tx, userWallet);
@@ -1077,7 +1082,9 @@ var WarpEvmExecutor = class {
1077
1082
  } catch {
1078
1083
  iface = new import_ethers4.ethers.Interface([action.abi]);
1079
1084
  }
1080
- 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);
1081
1088
  const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
1082
1089
  const result = await this.provider.call({
1083
1090
  to: executable.destination,
@@ -1092,9 +1099,7 @@ var WarpEvmExecutor = class {
1092
1099
  executable.resolvedInputs
1093
1100
  );
1094
1101
  const next = (0, import_warps11.getNextInfo)(this.config, [], executable.warp, executable.action, output);
1095
- const destinationInput = executable.resolvedInputs.find(
1096
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1097
- );
1102
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1098
1103
  const destination = destinationInput?.value || executable.destination;
1099
1104
  const resolvedInputs = (0, import_warps11.extractResolvedInputValues)(executable.resolvedInputs);
1100
1105
  return {
@@ -1112,9 +1117,7 @@ var WarpEvmExecutor = class {
1112
1117
  resolvedInputs
1113
1118
  };
1114
1119
  } catch (error) {
1115
- const destinationInput = executable.resolvedInputs.find(
1116
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1117
- );
1120
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1118
1121
  const destination = destinationInput?.value || executable.destination;
1119
1122
  const resolvedInputs = (0, import_warps11.extractResolvedInputValues)(executable.resolvedInputs);
1120
1123
  return {
@@ -1192,6 +1195,53 @@ var WarpEvmExecutor = class {
1192
1195
  throw new Error(`Failed to verify message: ${error}`);
1193
1196
  }
1194
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
+ }
1195
1245
  };
1196
1246
 
1197
1247
  // src/WarpEvmExplorer.ts