diff --git a/src/server/utils/wallets/getSmartWallet.ts b/src/server/utils/wallets/getSmartWallet.ts index 5f05743e0..59ab4d885 100644 --- a/src/server/utils/wallets/getSmartWallet.ts +++ b/src/server/utils/wallets/getSmartWallet.ts @@ -8,6 +8,7 @@ interface GetSmartWalletParams { backendWallet: EVMWallet; accountAddress: string; factoryAddress?: string; + entrypointAddress?: string; } /** @@ -19,6 +20,7 @@ export const getSmartWallet = async ({ backendWallet, accountAddress, factoryAddress, + entrypointAddress, }: GetSmartWalletParams) => { let resolvedFactoryAddress: string | undefined = factoryAddress; @@ -51,6 +53,7 @@ export const getSmartWallet = async ({ const smartWallet = new SmartWallet({ chain: chainId, factoryAddress: resolvedFactoryAddress, + entryPointAddress: entrypointAddress, secretKey: env.THIRDWEB_API_SECRET_KEY, gasless: true, }); diff --git a/src/utils/cache/getWallet.ts b/src/utils/cache/getWallet.ts index db84a941a..6b078594b 100644 --- a/src/utils/cache/getWallet.ts +++ b/src/utils/cache/getWallet.ts @@ -110,6 +110,8 @@ export const getWallet = async ({ chainId, backendWallet: adminWallet, accountAddress: walletDetails.address, + factoryAddress: walletDetails.accountFactoryAddress ?? undefined, + entrypointAddress: walletDetails.entrypointAddress ?? undefined, }); return smartWallet as TWallet; @@ -141,6 +143,8 @@ export const getWallet = async ({ chainId, backendWallet: adminWallet, accountAddress: walletDetails.address, + factoryAddress: walletDetails.accountFactoryAddress ?? undefined, + entrypointAddress: walletDetails.entrypointAddress ?? undefined, }); return smartWallet as TWallet; @@ -158,6 +162,8 @@ export const getWallet = async ({ chainId, backendWallet: adminWallet, accountAddress: walletDetails.address, + factoryAddress: walletDetails.accountFactoryAddress ?? undefined, + entrypointAddress: walletDetails.entrypointAddress ?? undefined, }); return smartWallet as TWallet; diff --git a/src/utils/transaction/insertTransaction.ts b/src/utils/transaction/insertTransaction.ts index 32a24178b..fe79018fb 100644 --- a/src/utils/transaction/insertTransaction.ts +++ b/src/utils/transaction/insertTransaction.ts @@ -117,6 +117,7 @@ export const insertTransaction = async ( // when using v4 SDK with smart backend wallets, the following values are not set correctly: // entrypointAddress is not set + // accountFactoryAddress is not set if (walletDetails && isSmartBackendWallet(walletDetails)) { if ( !(await doesChainSupportService( @@ -134,6 +135,8 @@ export const insertTransaction = async ( queuedTransaction = { ...queuedTransaction, entrypointAddress: walletDetails.entrypointAddress ?? undefined, + accountFactoryAddress: + walletDetails.accountFactoryAddress ?? undefined, }; } } catch { diff --git a/test/e2e/tests/smart-backend-wallet/smart-local-wallet-sdk-v4.test.ts b/test/e2e/tests/smart-backend-wallet/smart-local-wallet-sdk-v4.test.ts new file mode 100644 index 000000000..8ce0191a3 --- /dev/null +++ b/test/e2e/tests/smart-backend-wallet/smart-local-wallet-sdk-v4.test.ts @@ -0,0 +1,90 @@ +import { describe, expect, test } from "bun:test"; +import { arbitrumSepolia } from "thirdweb/chains"; +import { pollTransactionStatus } from "../../utils/transactions"; +import { setup } from "../setup"; + +const chain = arbitrumSepolia; +const chainId = chain.id.toString(); + +describe("smart local wallet (test succesfull deploy with SDKv4)", () => { + let smartWalletAddress: string | undefined; + + const getSmartWalletAddress = () => { + if (!smartWalletAddress) { + throw new Error("Smart wallet address not set"); + } + return smartWalletAddress; + }; + + test("Create a local smart backend wallet", async () => { + const { engine } = await setup(); + + const res = await engine.backendWallet.create({ + type: "smart:local", + label: "test", + }); + + expect(res.result.status).toEqual("success"); + expect(res.result.type).toEqual("smart:local"); + expect(res.result.walletAddress).toBeDefined(); + + smartWalletAddress = res.result.walletAddress; + }); + + test("Send a SDK v4 Transaction (deploy ERC20)", async () => { + const { engine } = await setup(); + + const deployRes = await engine.deploy.deployToken( + chainId, + getSmartWalletAddress(), + { + contractMetadata: { + name: "Test", + symbol: "TST", + platform_fee_basis_points: 0, + platform_fee_recipient: getSmartWalletAddress(), + trusted_forwarders: [], + }, + }, + ); + + const { queueId: deployQueueId, deployedAddress } = deployRes.result; + + if (!deployedAddress || !deployQueueId) { + throw new Error("Deploy failed"); + } + + await pollTransactionStatus(engine, deployQueueId); + + const mintRes = await engine.erc20.mintTo( + chainId, + deployedAddress, + getSmartWalletAddress(), + { + amount: "1000", + toAddress: getSmartWalletAddress(), + }, + ); + + await pollTransactionStatus(engine, mintRes.result.queueId); + const status = await engine.transaction.status(mintRes.result.queueId); + expect(status.result.accountAddress).toEqual(getSmartWalletAddress()); + + const balance = await engine.erc20.balanceOf( + getSmartWalletAddress(), + chainId, + deployedAddress, + ); + + expect(Number(balance.result.displayValue)).toEqual(1000); + }); + + test("Delete local smart backend wallet", async () => { + const { engine } = await setup(); + + const res = await engine.backendWallet.removeBackendWallet( + getSmartWalletAddress(), + ); + expect(res.result.status).toEqual("success"); + }); +}); diff --git a/test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts b/test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts index 24fbedf2d..6ed97a1f6 100644 --- a/test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts +++ b/test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts @@ -6,7 +6,7 @@ import { pollTransactionStatus } from "../../utils/transactions"; import { setup } from "../setup"; const chain = arbitrumSepolia; -const chainId = arbitrumSepolia.id.toString(); +const chainId = chain.id.toString(); const message = "test"; describe("smart local wallet", () => {