From 30ee794ea4537f3edd53707323f76d36e2881fae Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Mon, 11 Nov 2024 12:48:41 +0530 Subject: [PATCH 1/5] refactor: Add missing entrypointAddress parameter to getSmartWallet This commit adds the missing entrypointAddress parameter to the getSmartWallet function in the getSmartWallet.ts file. The entrypointAddress is now passed as an argument to the SmartWallet constructor. This change ensures that the entrypointAddress is correctly set when using the v4 SDK with smart backend wallets. --- src/server/utils/wallets/getSmartWallet.ts | 3 +++ 1 file changed, 3 insertions(+) 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, }); From 025aadb0fcfb0af58ecbbbd966ed5d9555126c79 Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Mon, 11 Nov 2024 12:48:53 +0530 Subject: [PATCH 2/5] fix: Set accountFactoryAddress and entrypointAddress in getWallet This commit updates the getWallet function in the getWallet.ts file to set the accountFactoryAddress and entrypointAddress parameters when creating a smart wallet. The accountFactoryAddress and entrypointAddress are now retrieved from the walletDetails object and passed as arguments to the SmartWallet constructor. This change ensures that the accountFactoryAddress and entrypointAddress are correctly set when using the v4 SDK with smart backend wallets. --- src/utils/cache/getWallet.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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; From d8d11a38ce3772a5455cfa69be964ccf4907d830 Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Mon, 11 Nov 2024 12:49:07 +0530 Subject: [PATCH 3/5] fix: Set accountFactoryAddress and entrypointAddress in insertTransaction This commit updates the insertTransaction function in the insertTransaction.ts file to set the accountFactoryAddress and entrypointAddress parameters when creating a smart wallet. The accountFactoryAddress and entrypointAddress are now retrieved from the walletDetails object and assigned to the queuedTransaction object. This change ensures that the accountFactoryAddress and entrypointAddress are correctly set when using the v4 SDK with smart backend wallets. --- src/utils/transaction/insertTransaction.ts | 3 +++ 1 file changed, 3 insertions(+) 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 { From e22c6bb477df661b33d19810d6468d82ca09bdf2 Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Mon, 11 Nov 2024 12:49:23 +0530 Subject: [PATCH 4/5] chore: Clean up smart-local-wallet.test.ts This commit removes unused imports and updates the chainId variable in the smart-local-wallet.test.ts file. The chainId is now retrieved from the chain object. This change improves the readability and maintainability of the code. --- test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", () => { From 0bbf518dd797cf0b37cd16449386b2b6a34a651e Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Mon, 11 Nov 2024 12:49:50 +0530 Subject: [PATCH 5/5] feat: Add smart-local-wallet-sdk-v4.test.ts This commit adds the smart-local-wallet-sdk-v4.test.ts file, which contains tests for creating a local smart backend wallet and sending SDK v4 transactions. The tests deploy an ERC20 token, mint tokens, and check the balance. This change improves the test coverage for the smart backend wallet functionality. --- .../smart-local-wallet-sdk-v4.test.ts | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test/e2e/tests/smart-backend-wallet/smart-local-wallet-sdk-v4.test.ts 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"); + }); +});