Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/server/utils/wallets/getSmartWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface GetSmartWalletParams {
backendWallet: EVMWallet;
accountAddress: string;
factoryAddress?: string;
entrypointAddress?: string;
}

/**
Expand All @@ -19,6 +20,7 @@ export const getSmartWallet = async ({
backendWallet,
accountAddress,
factoryAddress,
entrypointAddress,
}: GetSmartWalletParams) => {
let resolvedFactoryAddress: string | undefined = factoryAddress;

Expand Down Expand Up @@ -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,
});
Expand Down
6 changes: 6 additions & 0 deletions src/utils/cache/getWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
chainId,
backendWallet: adminWallet,
accountAddress: walletDetails.address,
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
});

return smartWallet as TWallet;
Expand Down Expand Up @@ -141,6 +143,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
chainId,
backendWallet: adminWallet,
accountAddress: walletDetails.address,
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
});

return smartWallet as TWallet;
Expand All @@ -158,6 +162,8 @@ export const getWallet = async <TWallet extends EVMWallet>({
chainId,
backendWallet: adminWallet,
accountAddress: walletDetails.address,
factoryAddress: walletDetails.accountFactoryAddress ?? undefined,
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
});

return smartWallet as TWallet;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/transaction/insertTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -134,6 +135,8 @@ export const insertTransaction = async (
queuedTransaction = {
...queuedTransaction,
entrypointAddress: walletDetails.entrypointAddress ?? undefined,
accountFactoryAddress:
walletDetails.accountFactoryAddress ?? undefined,
};
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Loading