Skip to content

Commit 2f762dc

Browse files
authored
fix sbw sdk v4 (#770)
* 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. * 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. * 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. * 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. * 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.
1 parent dc528ab commit 2f762dc

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

src/server/utils/wallets/getSmartWallet.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface GetSmartWalletParams {
88
backendWallet: EVMWallet;
99
accountAddress: string;
1010
factoryAddress?: string;
11+
entrypointAddress?: string;
1112
}
1213

1314
/**
@@ -19,6 +20,7 @@ export const getSmartWallet = async ({
1920
backendWallet,
2021
accountAddress,
2122
factoryAddress,
23+
entrypointAddress,
2224
}: GetSmartWalletParams) => {
2325
let resolvedFactoryAddress: string | undefined = factoryAddress;
2426

@@ -51,6 +53,7 @@ export const getSmartWallet = async ({
5153
const smartWallet = new SmartWallet({
5254
chain: chainId,
5355
factoryAddress: resolvedFactoryAddress,
56+
entryPointAddress: entrypointAddress,
5457
secretKey: env.THIRDWEB_API_SECRET_KEY,
5558
gasless: true,
5659
});

src/utils/cache/getWallet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
110110
chainId,
111111
backendWallet: adminWallet,
112112
accountAddress: walletDetails.address,
113+
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
114+
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
113115
});
114116

115117
return smartWallet as TWallet;
@@ -141,6 +143,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
141143
chainId,
142144
backendWallet: adminWallet,
143145
accountAddress: walletDetails.address,
146+
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
147+
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
144148
});
145149

146150
return smartWallet as TWallet;
@@ -158,6 +162,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
158162
chainId,
159163
backendWallet: adminWallet,
160164
accountAddress: walletDetails.address,
165+
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
166+
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
161167
});
162168

163169
return smartWallet as TWallet;

src/utils/transaction/insertTransaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const insertTransaction = async (
117117

118118
// when using v4 SDK with smart backend wallets, the following values are not set correctly:
119119
// entrypointAddress is not set
120+
// accountFactoryAddress is not set
120121
if (walletDetails && isSmartBackendWallet(walletDetails)) {
121122
if (
122123
!(await doesChainSupportService(
@@ -134,6 +135,8 @@ export const insertTransaction = async (
134135
queuedTransaction = {
135136
...queuedTransaction,
136137
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
138+
accountFactoryAddress:
139+
walletDetails.accountFactoryAddress ?? undefined,
137140
};
138141
}
139142
} catch {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { arbitrumSepolia } from "thirdweb/chains";
3+
import { pollTransactionStatus } from "../../utils/transactions";
4+
import { setup } from "../setup";
5+
6+
const chain = arbitrumSepolia;
7+
const chainId = chain.id.toString();
8+
9+
describe("smart local wallet (test succesfull deploy with SDKv4)", () => {
10+
let smartWalletAddress: string | undefined;
11+
12+
const getSmartWalletAddress = () => {
13+
if (!smartWalletAddress) {
14+
throw new Error("Smart wallet address not set");
15+
}
16+
return smartWalletAddress;
17+
};
18+
19+
test("Create a local smart backend wallet", async () => {
20+
const { engine } = await setup();
21+
22+
const res = await engine.backendWallet.create({
23+
type: "smart:local",
24+
label: "test",
25+
});
26+
27+
expect(res.result.status).toEqual("success");
28+
expect(res.result.type).toEqual("smart:local");
29+
expect(res.result.walletAddress).toBeDefined();
30+
31+
smartWalletAddress = res.result.walletAddress;
32+
});
33+
34+
test("Send a SDK v4 Transaction (deploy ERC20)", async () => {
35+
const { engine } = await setup();
36+
37+
const deployRes = await engine.deploy.deployToken(
38+
chainId,
39+
getSmartWalletAddress(),
40+
{
41+
contractMetadata: {
42+
name: "Test",
43+
symbol: "TST",
44+
platform_fee_basis_points: 0,
45+
platform_fee_recipient: getSmartWalletAddress(),
46+
trusted_forwarders: [],
47+
},
48+
},
49+
);
50+
51+
const { queueId: deployQueueId, deployedAddress } = deployRes.result;
52+
53+
if (!deployedAddress || !deployQueueId) {
54+
throw new Error("Deploy failed");
55+
}
56+
57+
await pollTransactionStatus(engine, deployQueueId);
58+
59+
const mintRes = await engine.erc20.mintTo(
60+
chainId,
61+
deployedAddress,
62+
getSmartWalletAddress(),
63+
{
64+
amount: "1000",
65+
toAddress: getSmartWalletAddress(),
66+
},
67+
);
68+
69+
await pollTransactionStatus(engine, mintRes.result.queueId);
70+
const status = await engine.transaction.status(mintRes.result.queueId);
71+
expect(status.result.accountAddress).toEqual(getSmartWalletAddress());
72+
73+
const balance = await engine.erc20.balanceOf(
74+
getSmartWalletAddress(),
75+
chainId,
76+
deployedAddress,
77+
);
78+
79+
expect(Number(balance.result.displayValue)).toEqual(1000);
80+
});
81+
82+
test("Delete local smart backend wallet", async () => {
83+
const { engine } = await setup();
84+
85+
const res = await engine.backendWallet.removeBackendWallet(
86+
getSmartWalletAddress(),
87+
);
88+
expect(res.result.status).toEqual("success");
89+
});
90+
});

test/e2e/tests/smart-backend-wallet/smart-local-wallet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { pollTransactionStatus } from "../../utils/transactions";
66
import { setup } from "../setup";
77

88
const chain = arbitrumSepolia;
9-
const chainId = arbitrumSepolia.id.toString();
9+
const chainId = chain.id.toString();
1010
const message = "test";
1111

1212
describe("smart local wallet", () => {

0 commit comments

Comments
 (0)