Coder Social home page Coder Social logo

Comments (3)

milaabl avatar milaabl commented on August 25, 2024

👀

from contracts.

mishaDova avatar mishaDova commented on August 25, 2024

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

from contracts.

mishaDova avatar mishaDova commented on August 25, 2024

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

from contracts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.