Skip to content

Commit 4cead60

Browse files
changeset
1 parent 5de5442 commit 4cead60

File tree

5 files changed

+29
-66
lines changed

5 files changed

+29
-66
lines changed

.changeset/tiny-pugs-hunt.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
ERC20 Token Paymaster support
6+
7+
You can now use ERC20 Token Paymasters with Smart Wallets.
8+
9+
```typescript
10+
import { base } from "thirdweb/chains";
11+
import { TokenPaymaster, smartWallet } from "thirdweb/wallets";
12+
13+
const wallet = smartWallet({
14+
chain: base,
15+
sponsorGas: true, // only sponsor gas for the first ERC20 approval
16+
overrides: {
17+
tokenPaymaster: TokenPaymaster.BASE_USDC,
18+
},
19+
});
20+
```

packages/thirdweb/src/wallets/smart/lib/bundler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ export async function estimateUserOpGas(
7272
userOp: UserOperationV06 | UserOperationV07;
7373
options: BundlerOptions;
7474
},
75-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
76-
stateOverrides?: any,
75+
stateOverrides?: {
76+
[x: string]: {
77+
stateDiff: {
78+
[x: string]: `0x${string}`;
79+
};
80+
};
81+
},
7782
): Promise<EstimationResult> {
7883
const res = await sendBundlerRequest({
7984
...args,

packages/thirdweb/src/wallets/smart/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const ENTRYPOINT_ADDRESS_v0_7 =
1818

1919
export const MANAGED_ACCOUNT_GAS_BUFFER = 50000n;
2020

21-
export type PAYMASTERS = "BASE_USDC" | "CELO_CUSD" | "LISK_LSK";
21+
type PAYMASTERS = "BASE_USDC" | "CELO_CUSD" | "LISK_LSK";
2222
export const TokenPaymaster: Record<PAYMASTERS, TokenPaymasterConfig> = {
2323
BASE_USDC: {
2424
chainId: 8453,

packages/thirdweb/src/wallets/smart/smart-wallet-tokenpaymaster.test.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { celo } from "../../chains/chain-definitions/celo.js";
55
import { defineChain } from "../../chains/utils.js";
66
import { sendTransaction } from "../../transaction/actions/send-transaction.js";
77
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
8-
import type { Address } from "../../utils/address.js";
98
import { privateKeyToAccount } from "../private-key.js";
10-
import { getWalletBalance } from "../utils/getWalletBalance.js";
119
import { TokenPaymaster } from "./lib/constants.js";
1210
import { smartWallet } from "./smart-wallet.js";
1311

@@ -39,17 +37,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
3937
client: TEST_CLIENT,
4038
personalAccount,
4139
});
42-
const smartWalletAddress = smartAccount.address as Address;
43-
console.log("smartWalletAddress", smartWalletAddress);
44-
console.log(
45-
"balance before",
46-
await getWalletBalance({
47-
address: smartAccount.address,
48-
chain: chain,
49-
client,
50-
tokenAddress: tokenPaymaster.tokenAddress,
51-
}),
52-
);
5340
const tx = prepareTransaction({
5441
client,
5542
chain,
@@ -61,15 +48,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
6148
account: smartAccount,
6249
});
6350
expect(receipt.transactionHash).toBeDefined();
64-
console.log(
65-
"balance after",
66-
await getWalletBalance({
67-
address: smartAccount.address,
68-
chain: chain,
69-
client,
70-
tokenAddress: tokenPaymaster.tokenAddress,
71-
}),
72-
);
7351
});
7452

7553
it.skip("should send a transaction with base celo", async () => {
@@ -91,17 +69,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
9169
client: TEST_CLIENT,
9270
personalAccount,
9371
});
94-
const smartWalletAddress = smartAccount.address as Address;
95-
console.log("smartWalletAddress", smartWalletAddress);
96-
console.log(
97-
"balance before",
98-
await getWalletBalance({
99-
address: smartAccount.address,
100-
chain: chain,
101-
client,
102-
tokenAddress: tokenPaymaster.tokenAddress,
103-
}),
104-
);
10572
const tx = prepareTransaction({
10673
client,
10774
chain,
@@ -113,15 +80,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
11380
account: smartAccount,
11481
});
11582
expect(receipt.transactionHash).toBeDefined();
116-
console.log(
117-
"balance after",
118-
await getWalletBalance({
119-
address: smartAccount.address,
120-
chain: chain,
121-
client,
122-
tokenAddress: tokenPaymaster.tokenAddress,
123-
}),
124-
);
12583
});
12684

12785
it("should send a transaction with base lisk", async () => {
@@ -143,17 +101,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
143101
client: TEST_CLIENT,
144102
personalAccount,
145103
});
146-
const smartWalletAddress = smartAccount.address as Address;
147-
console.log("smartWalletAddress", smartWalletAddress);
148-
console.log(
149-
"balance before",
150-
await getWalletBalance({
151-
address: smartAccount.address,
152-
chain: chain,
153-
client,
154-
tokenAddress: tokenPaymaster.tokenAddress,
155-
}),
156-
);
157104
const tx = prepareTransaction({
158105
client,
159106
chain,
@@ -165,15 +112,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
165112
account: smartAccount,
166113
});
167114
expect(receipt.transactionHash).toBeDefined();
168-
console.log(
169-
"balance after",
170-
await getWalletBalance({
171-
address: smartAccount.address,
172-
chain: chain,
173-
client,
174-
tokenAddress: tokenPaymaster.tokenAddress,
175-
}),
176-
);
177115
});
178116
},
179117
);

packages/thirdweb/src/wallets/smart/smart-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import { getDefaultAccountFactory } from "./lib/constants.js";
118118
* accountAddress: "0x...", // override account address
119119
* accountSalt: "0x...", // override account salt
120120
* entrypointAddress: "0x...", // override entrypoint address
121-
* erc20Paymaster: "BASE_USDC", // enable erc20 paymaster
121+
* tokenPaymaster: TokenPaymaster.BASE_USDC, // enable erc20 paymaster
122122
* bundlerUrl: "https://...", // override bundler url
123123
* paymaster: (userOp) => { ... }, // override paymaster
124124
* ...

0 commit comments

Comments
 (0)