Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EIP 4337] Withdrawing tokens from a contract to a smart account fails #585

Open
alko89 opened this issue Dec 5, 2023 · 3 comments
Open

Comments

@alko89
Copy link

alko89 commented Dec 5, 2023

Withdrawing native tokens from to a smart account throws unpredictable gas error. This is preventing our users to use 1Inch API to swap ERC tokens into Native tokens.

Digging more into this I've created a minimal code to reproduce the issue, by trying to unwrap WMATIC tokens for MATIC on Mumbai:

import { config } from "dotenv"
import { AbstractWallet, PrivateKeyWallet, SmartWallet, SmartWalletConfig } from "@thirdweb-dev/wallets";
import { Mumbai } from "@thirdweb-dev/chains";
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { utils } from "ethers";
import { WETH_ABI } from "./ABI/weth";

config()

async function withdraw(wallet: AbstractWallet) {
  const sdkSmart = await ThirdwebSDK.fromWallet(wallet, Mumbai);

  const wmaticAddress = "0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889";
  const wmaticContract = await sdkSmart.getContract(wmaticAddress, WETH_ABI)

  const data = await wmaticContract.call('withdraw', [utils.parseEther('0.1')])
  console.log('data: ', data)
}

async function createTransaction() {
  console.log("creating account")
  const privateKey = process.env.PRIVATE_KEY as string;
  const personalWallet = new PrivateKeyWallet(privateKey);
  console.log("personalWallet: ", await personalWallet.getAddress());

  const config: SmartWalletConfig = {
    chain: Mumbai,
    factoryAddress: process.env.FACTORY_ADDRESS as string,
    secretKey: process.env.SECRET_KEY as string,
    gasless: true, // enable or disable gasless transactions
  };

  const smartWallet = new SmartWallet(config);
  await smartWallet.connect({
    personalWallet,
  });
  console.log("smartWallet: ", await smartWallet.getAddress());
  
  console.log("Unwrapping with personal wallet")
  await withdraw(personalWallet)

  console.log("Unwrapping with smart wallet")
  await withdraw(smartWallet)
}

createTransaction()

I've tested this script with our version of contract factory (v1.4.0) and the latest one available (v1.5.3), which strangely enough throw a different error in this case:

Managed Account Factory v1.4.0

Reason: Error: gas required exceeds allowance

Managed Account Factory v1.5.3

Reason: execution reverted
@milaabl
Copy link

milaabl commented Dec 5, 2023

👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@alko89 @milaabl and others