Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels