@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.d.mts CHANGED
@@ -76,6 +76,8 @@ interface ContractWriteParams extends ContractReadParams {
76
76
  value?: string;
77
77
  gas?: number;
78
78
  gasPrice?: string;
79
+ maxFeePerGas?: string;
80
+ maxPriorityFeePerGas?: string;
79
81
  }
80
82
  interface EVMTransaction {
81
83
  to: string;
@@ -195,6 +197,8 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
195
197
  value?: string;
196
198
  gas?: number;
197
199
  gasPrice?: string;
200
+ maxFeePerGas?: string;
201
+ maxPriorityFeePerGas?: string;
198
202
  }, chainType?: ChainType$1): Promise<string>;
199
203
  estimateGas(address: string, abi: any[], functionName: string, args?: any[], chainType?: ChainType$1): Promise<bigint>;
200
204
  waitForTransaction(txHash: string, confirmations?: number, chainType?: ChainType$1): Promise<TransactionReceipt>;
package/dist/index.d.ts CHANGED
@@ -76,6 +76,8 @@ interface ContractWriteParams extends ContractReadParams {
76
76
  value?: string;
77
77
  gas?: number;
78
78
  gasPrice?: string;
79
+ maxFeePerGas?: string;
80
+ maxPriorityFeePerGas?: string;
79
81
  }
80
82
  interface EVMTransaction {
81
83
  to: string;
@@ -195,6 +197,8 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
195
197
  value?: string;
196
198
  gas?: number;
197
199
  gasPrice?: string;
200
+ maxFeePerGas?: string;
201
+ maxPriorityFeePerGas?: string;
198
202
  }, chainType?: ChainType$1): Promise<string>;
199
203
  estimateGas(address: string, abi: any[], functionName: string, args?: any[], chainType?: ChainType$1): Promise<bigint>;
200
204
  waitForTransaction(txHash: string, confirmations?: number, chainType?: ChainType$1): Promise<TransactionReceipt>;
package/dist/index.js CHANGED
@@ -760,25 +760,69 @@ var MetaMaskAdapter = class extends BrowserWalletAdapter {
760
760
  throw new Error("Wallet client not initialized");
761
761
  }
762
762
  try {
763
- console.log("\u{1F50D} [MetaMask writeContract] params.gasPrice:", params.gasPrice, "type:", typeof params.gasPrice);
764
- let processedGasPrice;
765
- if (!params.gasPrice) {
766
- processedGasPrice = void 0;
767
- } else if (params.gasPrice === "auto") {
768
- processedGasPrice = void 0;
769
- } else {
770
- processedGasPrice = BigInt(params.gasPrice);
771
- }
772
- console.log("\u{1F50D} [MetaMask writeContract] processedGasPrice:", processedGasPrice);
773
- const txHash = await this.walletClient.writeContract({
763
+ console.log("\u{1F50D} [MetaMask writeContract] Gas params:", {
764
+ gasPrice: params.gasPrice,
765
+ maxFeePerGas: params.maxFeePerGas,
766
+ maxPriorityFeePerGas: params.maxPriorityFeePerGas
767
+ });
768
+ const txOptions = {
774
769
  address: params.address,
775
770
  abi: params.abi,
776
771
  functionName: params.functionName,
777
772
  ...params.args ? { args: params.args } : {},
778
773
  value: params.value ? BigInt(params.value) : void 0,
779
- gas: params.gas ? BigInt(params.gas) : void 0,
780
- gasPrice: processedGasPrice
781
- });
774
+ gas: params.gas ? BigInt(params.gas) : void 0
775
+ };
776
+ if (params.maxFeePerGas || params.maxPriorityFeePerGas) {
777
+ if (params.maxFeePerGas) {
778
+ txOptions.maxFeePerGas = BigInt(params.maxFeePerGas);
779
+ }
780
+ if (params.maxPriorityFeePerGas) {
781
+ txOptions.maxPriorityFeePerGas = BigInt(params.maxPriorityFeePerGas);
782
+ }
783
+ console.log("\u{1F50D} [MetaMask writeContract] Using EIP-1559 gas params");
784
+ } else if (params.gasPrice) {
785
+ if (params.gasPrice === "auto") {
786
+ console.log("\u{1F50D} [MetaMask writeContract] Auto gas price - letting viem decide");
787
+ } else {
788
+ txOptions.gasPrice = BigInt(params.gasPrice);
789
+ console.log("\u{1F50D} [MetaMask writeContract] Using legacy gasPrice");
790
+ }
791
+ } else {
792
+ console.log("\u{1F50D} [MetaMask writeContract] No gas params - fetching and setting reasonable gas fees");
793
+ if (this.publicClient) {
794
+ try {
795
+ const feesPerGas = await this.publicClient.estimateFeesPerGas().catch(() => null);
796
+ if (feesPerGas) {
797
+ const minPriorityFeeWei = BigInt(1e8);
798
+ const maxPriorityFeePerGas = feesPerGas.maxPriorityFeePerGas > minPriorityFeeWei ? feesPerGas.maxPriorityFeePerGas : minPriorityFeeWei;
799
+ const adjustedMaxFeePerGas = feesPerGas.maxFeePerGas > maxPriorityFeePerGas ? feesPerGas.maxFeePerGas : maxPriorityFeePerGas + BigInt(1e9);
800
+ txOptions.maxFeePerGas = adjustedMaxFeePerGas;
801
+ txOptions.maxPriorityFeePerGas = maxPriorityFeePerGas;
802
+ const maxFeePerGasGwei = Number(adjustedMaxFeePerGas) / 1e9;
803
+ const maxPriorityFeePerGasGwei = Number(maxPriorityFeePerGas) / 1e9;
804
+ console.log("\u{1F4B0} [MetaMask writeContract] Set gas fees (EIP-1559):", {
805
+ maxFeePerGas: `${maxFeePerGasGwei.toFixed(6)} Gwei`,
806
+ maxPriorityFeePerGas: `${maxPriorityFeePerGasGwei.toFixed(6)} Gwei`,
807
+ maxFeePerGasWei: adjustedMaxFeePerGas.toString(),
808
+ maxPriorityFeePerGasWei: maxPriorityFeePerGas.toString(),
809
+ note: "\u5DF2\u8BBE\u7F6E\u5408\u7406\u7684 gas \u8D39\u7528\uFF0C\u907F\u514D MetaMask \u4F7F\u7528\u9ED8\u8BA4\u503C"
810
+ });
811
+ } else {
812
+ const gasPrice = await this.publicClient.getGasPrice();
813
+ txOptions.gasPrice = gasPrice;
814
+ const gasPriceGwei = Number(gasPrice) / 1e9;
815
+ console.log("\u{1F4B0} [MetaMask writeContract] Set gas price (Legacy):", {
816
+ gasPrice: `${gasPriceGwei.toFixed(6)} Gwei`,
817
+ gasPriceWei: gasPrice.toString()
818
+ });
819
+ }
820
+ } catch (err) {
821
+ console.warn("\u26A0\uFE0F [MetaMask writeContract] Failed to estimate gas fees, letting viem auto-estimate:", err);
822
+ }
823
+ }
824
+ }
825
+ const txHash = await this.walletClient.writeContract(txOptions);
782
826
  return txHash;
783
827
  } catch (error) {
784
828
  if (error.code === 4001) {