@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.mjs CHANGED
@@ -421,6 +421,7 @@ var WarpEvmDataLoader = class {
421
421
  }
422
422
  async getAsset(identifier) {
423
423
  try {
424
+ console.log("WarpEvmDataLoader.getAsset", identifier);
424
425
  if (identifier === this.chain.nativeToken.identifier) {
425
426
  return this.chain.nativeToken;
426
427
  }
@@ -429,6 +430,7 @@ var WarpEvmDataLoader = class {
429
430
  if (cachedAsset) {
430
431
  return cachedAsset;
431
432
  }
433
+ console.log("WarpEvmDataLoader.getAsset: findKnownTokenById", this.chain.name, this.config.env, identifier);
432
434
  const knownToken = findKnownTokenById(this.chain.name, this.config.env, identifier);
433
435
  if (knownToken) {
434
436
  return {
@@ -449,7 +451,7 @@ var WarpEvmDataLoader = class {
449
451
  symbol: metadata.symbol,
450
452
  amount: 0n,
451
453
  decimals: metadata.decimals,
452
- logoUrl: metadata.logoUrl || ""
454
+ logoUrl: metadata.logoUrl
453
455
  };
454
456
  this.cache.set(cacheKey, asset, CacheTtl2.OneHour);
455
457
  return asset;
@@ -559,7 +561,7 @@ var WarpEvmConstants = {
559
561
  Swap: 2e5
560
562
  },
561
563
  GasPrice: {
562
- Default: "20000000000"
564
+ Default: "1200010"
563
565
  },
564
566
  Validation: {
565
567
  MinGasLimit: 21e3,
@@ -991,11 +993,16 @@ var WarpEvmExecutor = class {
991
993
  } catch {
992
994
  iface = new ethers4.Interface([action.abi]);
993
995
  }
994
- const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
996
+ const funcFragment = iface.getFunction(action.func);
997
+ if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
998
+ const nativeArgs = this.prepareNativeArgs(executable.args, funcFragment);
995
999
  const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
1000
+ const value = this.getPayableValue(executable, funcFragment);
1001
+ console.log("Encoded data:", encodedData);
1002
+ console.log("Value:", value);
996
1003
  const tx = {
997
1004
  to: executable.destination,
998
- value: executable.value,
1005
+ value,
999
1006
  data: encodedData
1000
1007
  };
1001
1008
  return this.estimateGasAndSetDefaults(tx, userWallet);
@@ -1049,7 +1056,9 @@ var WarpEvmExecutor = class {
1049
1056
  } catch {
1050
1057
  iface = new ethers4.Interface([action.abi]);
1051
1058
  }
1052
- const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
1059
+ const funcFragment = iface.getFunction(action.func);
1060
+ if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
1061
+ const nativeArgs = this.prepareNativeArgs(executable.args, funcFragment);
1053
1062
  const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
1054
1063
  const result = await this.provider.call({
1055
1064
  to: executable.destination,
@@ -1064,9 +1073,7 @@ var WarpEvmExecutor = class {
1064
1073
  executable.resolvedInputs
1065
1074
  );
1066
1075
  const next = getNextInfo(this.config, [], executable.warp, executable.action, output);
1067
- const destinationInput = executable.resolvedInputs.find(
1068
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1069
- );
1076
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1070
1077
  const destination = destinationInput?.value || executable.destination;
1071
1078
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1072
1079
  return {
@@ -1084,9 +1091,7 @@ var WarpEvmExecutor = class {
1084
1091
  resolvedInputs
1085
1092
  };
1086
1093
  } catch (error) {
1087
- const destinationInput = executable.resolvedInputs.find(
1088
- (i) => i.input.position === "receiver" || i.input.position === "destination"
1089
- );
1094
+ const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
1090
1095
  const destination = destinationInput?.value || executable.destination;
1091
1096
  const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
1092
1097
  return {
@@ -1164,6 +1169,53 @@ var WarpEvmExecutor = class {
1164
1169
  throw new Error(`Failed to verify message: ${error}`);
1165
1170
  }
1166
1171
  }
1172
+ getPayableValue(executable, funcFragment) {
1173
+ if (funcFragment.stateMutability !== "payable") {
1174
+ return executable.value;
1175
+ }
1176
+ const nativeTokenId = this.chain.nativeToken?.identifier;
1177
+ const zeroAddress = "0x0000000000000000000000000000000000000000";
1178
+ const nativeTokenTransfer = nativeTokenId ? executable.transfers.find((transfer) => transfer.identifier === nativeTokenId || transfer.identifier === zeroAddress) : void 0;
1179
+ if (nativeTokenTransfer) {
1180
+ return nativeTokenTransfer.amount;
1181
+ }
1182
+ const nativeTokenAsset = this.findNativeTokenAsset(executable.resolvedInputs, nativeTokenId, zeroAddress);
1183
+ if (nativeTokenAsset) {
1184
+ return nativeTokenAsset.amount;
1185
+ }
1186
+ return executable.value;
1187
+ }
1188
+ findNativeTokenAsset(resolvedInputs, nativeTokenId, zeroAddress) {
1189
+ for (const input of resolvedInputs) {
1190
+ if (input.input.type === "asset" && input.value) {
1191
+ const [, assetValue] = this.serializer.coreSerializer.stringToNative(input.value);
1192
+ const asset = assetValue;
1193
+ if (asset && "amount" in asset) {
1194
+ if (asset.identifier === nativeTokenId || asset.identifier === zeroAddress) {
1195
+ return asset;
1196
+ }
1197
+ }
1198
+ }
1199
+ }
1200
+ return null;
1201
+ }
1202
+ prepareNativeArgs(args, funcFragment) {
1203
+ return args.map((arg, index) => {
1204
+ const nativeValue = this.serializer.coreSerializer.stringToNative(arg)[1];
1205
+ const paramType = funcFragment.inputs[index]?.type;
1206
+ if (paramType === "bytes32" && typeof nativeValue === "string") {
1207
+ let hexValue = nativeValue;
1208
+ if (!hexValue.startsWith("0x")) {
1209
+ hexValue = "0x" + hexValue;
1210
+ }
1211
+ if (hexValue.length !== 66) {
1212
+ hexValue = ethers4.zeroPadValue(hexValue, 32);
1213
+ }
1214
+ return hexValue;
1215
+ }
1216
+ return nativeValue;
1217
+ });
1218
+ }
1167
1219
  };
1168
1220
 
1169
1221
  // src/WarpEvmExplorer.ts