Skip to content

Commit be34729

Browse files
authored
TokenPaymaster v3 (#101)
1 parent 7404406 commit be34729

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

Thirdweb.Console/Program.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,28 +299,45 @@
299299

300300
#endregion
301301

302-
#region ERC20 Smart Wallet - Base USDC
302+
#region TokenPaymaster - Celo CUSD
303+
304+
// var chainId = 42220; // celo
305+
306+
// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.CELO_CUSD);
303307

304-
// var erc20SmartWallet = await SmartWallet.Create(
305-
// personalWallet: privateKeyWallet,
306-
// chainId: 8453, // base mainnet
307-
// gasless: true,
308-
// factoryAddress: "0xEc87d96E3F324Dcc828750b52994C6DC69C8162b",
309-
// entryPoint: Constants.ENTRYPOINT_ADDRESS_V07,
310-
// tokenPaymaster: TokenPaymaster.BASE_USDC
311-
// );
312308
// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
313309
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");
314310

315-
// var selfTransfer = await ThirdwebTransaction.Create(wallet: erc20SmartWallet, txInput: new ThirdwebTransactionInput(chainId: 8453, to: erc20SmartWalletAddress, value: 0, data: "0x"));
311+
// var receipt = await erc20SmartWallet.Transfer(chainId: chainId, toAddress: erc20SmartWalletAddress, weiAmount: 0);
312+
// Console.WriteLine($"Receipt: {JsonConvert.SerializeObject(receipt, Formatting.Indented)}");
316313

317-
// var estimateGas = await ThirdwebTransaction.EstimateGasCosts(selfTransfer);
318-
// Console.WriteLine($"Self transfer gas estimate: {estimateGas.Ether}");
319-
// Console.WriteLine("Make sure you have enough USDC!");
320-
// Console.ReadLine();
314+
#endregion
315+
316+
#region TokenPaymaster - Base USDC
317+
318+
// var chainId = 8453; // base
319+
320+
// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.BASE_USDC);
321+
322+
// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
323+
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");
324+
325+
// var receipt = await erc20SmartWallet.Transfer(chainId: chainId, toAddress: erc20SmartWalletAddress, weiAmount: 0);
326+
// Console.WriteLine($"Receipt: {JsonConvert.SerializeObject(receipt, Formatting.Indented)}");
327+
328+
#endregion
329+
330+
#region TokenPaymaster - Lisk LSK
331+
332+
// var chainId = 1135; // lisk
333+
334+
// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.LISK_LSK);
335+
336+
// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
337+
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");
321338

322-
// var receipt = await ThirdwebTransaction.SendAndWaitForTransactionReceipt(selfTransfer);
323-
// Console.WriteLine($"Self transfer receipt: {JsonConvert.SerializeObject(receipt, Formatting.Indented)}");
339+
// var receipt = await erc20SmartWallet.Transfer(chainId: chainId, toAddress: erc20SmartWalletAddress, weiAmount: 0);
340+
// Console.WriteLine($"Receipt: {JsonConvert.SerializeObject(receipt, Formatting.Indented)}");
324341

325342
#endregion
326343

@@ -349,7 +366,7 @@
349366

350367
#region InAppWallet - OAuth
351368

352-
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Twitch);
369+
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google);
353370
// if (!await inAppWalletOAuth.IsConnected())
354371
// {
355372
// _ = await inAppWalletOAuth.LoginWithOauth(

Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public enum TokenPaymaster
1515
{
1616
NONE,
1717
BASE_USDC,
18+
CELO_CUSD,
19+
LISK_LSK
1820
}
1921

2022
public class SmartWallet : IThirdwebWallet
@@ -66,10 +68,30 @@ private struct TokenPaymasterConfig
6668
new TokenPaymasterConfig()
6769
{
6870
ChainId = 8453,
69-
PaymasterAddress = "0xff4d12b1f8d276aa4a9e8cc80539e806791bfe28",
71+
PaymasterAddress = "0x2222f2738BE6bB7aA0Bfe4AEeAf2908172CF5539",
7072
TokenAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
7173
BalanceStorageSlot = 9
7274
}
75+
},
76+
{
77+
TokenPaymaster.CELO_CUSD,
78+
new TokenPaymasterConfig()
79+
{
80+
ChainId = 42220,
81+
PaymasterAddress = "0x3feA3c5744D715ff46e91C4e5C9a94426DfF2aF9",
82+
TokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a",
83+
BalanceStorageSlot = 9
84+
}
85+
},
86+
{
87+
TokenPaymaster.LISK_LSK,
88+
new TokenPaymasterConfig()
89+
{
90+
ChainId = 1135,
91+
PaymasterAddress = "0x9eb8cf7fBa5ed9EeDCC97a0d52254cc0e9B1AC25",
92+
TokenAddress = "0xac485391EB2d7D88253a7F1eF18C37f4242D1A24",
93+
BalanceStorageSlot = 9
94+
}
7395
}
7496
};
7597

@@ -154,7 +176,7 @@ public static async Task<SmartWallet> Create(
154176
}
155177
}
156178

157-
entryPoint ??= Constants.ENTRYPOINT_ADDRESS_V06;
179+
entryPoint ??= tokenPaymaster == TokenPaymaster.NONE ? Constants.ENTRYPOINT_ADDRESS_V06 : Constants.ENTRYPOINT_ADDRESS_V07;
158180

159181
var entryPointVersion = Utils.GetEntryPointVersion(entryPoint);
160182

@@ -719,7 +741,7 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
719741
partialUserOp.VerificationGasLimit = new HexBigInteger(gasEstimates.VerificationGasLimit).Value;
720742
partialUserOp.PreVerificationGas = new HexBigInteger(gasEstimates.PreVerificationGas).Value;
721743
partialUserOp.PaymasterVerificationGasLimit = new HexBigInteger(gasEstimates.PaymasterVerificationGasLimit).Value;
722-
partialUserOp.PaymasterPostOpGasLimit = new HexBigInteger(gasEstimates.PaymasterPostOpGasLimit).Value;
744+
partialUserOp.PaymasterPostOpGasLimit = this.UseERC20Paymaster && !this._isApproving ? 500_000 : new HexBigInteger(gasEstimates.PaymasterPostOpGasLimit).Value;
723745
}
724746

725747
// Hash, sign and encode the user operation

0 commit comments

Comments
 (0)