@enclave-hq/wallet-sdk 1.2.1 → 1.2.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
@@ -752,25 +752,69 @@ var MetaMaskAdapter = class extends BrowserWalletAdapter {
752
752
  throw new Error("Wallet client not initialized");
753
753
  }
754
754
  try {
755
- console.log("\u{1F50D} [MetaMask writeContract] params.gasPrice:", params.gasPrice, "type:", typeof params.gasPrice);
756
- let processedGasPrice;
757
- if (!params.gasPrice) {
758
- processedGasPrice = void 0;
759
- } else if (params.gasPrice === "auto") {
760
- processedGasPrice = void 0;
761
- } else {
762
- processedGasPrice = BigInt(params.gasPrice);
763
- }
764
- console.log("\u{1F50D} [MetaMask writeContract] processedGasPrice:", processedGasPrice);
765
- const txHash = await this.walletClient.writeContract({
755
+ console.log("\u{1F50D} [MetaMask writeContract] Gas params:", {
756
+ gasPrice: params.gasPrice,
757
+ maxFeePerGas: params.maxFeePerGas,
758
+ maxPriorityFeePerGas: params.maxPriorityFeePerGas
759
+ });
760
+ const txOptions = {
766
761
  address: params.address,
767
762
  abi: params.abi,
768
763
  functionName: params.functionName,
769
764
  ...params.args ? { args: params.args } : {},
770
765
  value: params.value ? BigInt(params.value) : void 0,
771
- gas: params.gas ? BigInt(params.gas) : void 0,
772
- gasPrice: processedGasPrice
773
- });
766
+ gas: params.gas ? BigInt(params.gas) : void 0
767
+ };
768
+ if (params.maxFeePerGas || params.maxPriorityFeePerGas) {
769
+ if (params.maxFeePerGas) {
770
+ txOptions.maxFeePerGas = BigInt(params.maxFeePerGas);
771
+ }
772
+ if (params.maxPriorityFeePerGas) {
773
+ txOptions.maxPriorityFeePerGas = BigInt(params.maxPriorityFeePerGas);
774
+ }
775
+ console.log("\u{1F50D} [MetaMask writeContract] Using EIP-1559 gas params");
776
+ } else if (params.gasPrice) {
777
+ if (params.gasPrice === "auto") {
778
+ console.log("\u{1F50D} [MetaMask writeContract] Auto gas price - letting viem decide");
779
+ } else {
780
+ txOptions.gasPrice = BigInt(params.gasPrice);
781
+ console.log("\u{1F50D} [MetaMask writeContract] Using legacy gasPrice");
782
+ }
783
+ } else {
784
+ console.log("\u{1F50D} [MetaMask writeContract] No gas params - fetching and setting reasonable gas fees");
785
+ if (this.publicClient) {
786
+ try {
787
+ const feesPerGas = await this.publicClient.estimateFeesPerGas().catch(() => null);
788
+ if (feesPerGas) {
789
+ const minPriorityFeeWei = BigInt(1e8);
790
+ const maxPriorityFeePerGas = feesPerGas.maxPriorityFeePerGas > minPriorityFeeWei ? feesPerGas.maxPriorityFeePerGas : minPriorityFeeWei;
791
+ const adjustedMaxFeePerGas = feesPerGas.maxFeePerGas > maxPriorityFeePerGas ? feesPerGas.maxFeePerGas : maxPriorityFeePerGas + BigInt(1e9);
792
+ txOptions.maxFeePerGas = adjustedMaxFeePerGas;
793
+ txOptions.maxPriorityFeePerGas = maxPriorityFeePerGas;
794
+ const maxFeePerGasGwei = Number(adjustedMaxFeePerGas) / 1e9;
795
+ const maxPriorityFeePerGasGwei = Number(maxPriorityFeePerGas) / 1e9;
796
+ console.log("\u{1F4B0} [MetaMask writeContract] Set gas fees (EIP-1559):", {
797
+ maxFeePerGas: `${maxFeePerGasGwei.toFixed(6)} Gwei`,
798
+ maxPriorityFeePerGas: `${maxPriorityFeePerGasGwei.toFixed(6)} Gwei`,
799
+ maxFeePerGasWei: adjustedMaxFeePerGas.toString(),
800
+ maxPriorityFeePerGasWei: maxPriorityFeePerGas.toString(),
801
+ note: "\u5DF2\u8BBE\u7F6E\u5408\u7406\u7684 gas \u8D39\u7528\uFF0C\u907F\u514D MetaMask \u4F7F\u7528\u9ED8\u8BA4\u503C"
802
+ });
803
+ } else {
804
+ const gasPrice = await this.publicClient.getGasPrice();
805
+ txOptions.gasPrice = gasPrice;
806
+ const gasPriceGwei = Number(gasPrice) / 1e9;
807
+ console.log("\u{1F4B0} [MetaMask writeContract] Set gas price (Legacy):", {
808
+ gasPrice: `${gasPriceGwei.toFixed(6)} Gwei`,
809
+ gasPriceWei: gasPrice.toString()
810
+ });
811
+ }
812
+ } catch (err) {
813
+ console.warn("\u26A0\uFE0F [MetaMask writeContract] Failed to estimate gas fees, letting viem auto-estimate:", err);
814
+ }
815
+ }
816
+ }
817
+ const txHash = await this.walletClient.writeContract(txOptions);
774
818
  return txHash;
775
819
  } catch (error) {
776
820
  if (error.code === 4001) {