Skip to content

Commit

Permalink
TokenPaymaster v3 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper authored Nov 22, 2024
1 parent 7404406 commit be34729
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
51 changes: 34 additions & 17 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,45 @@

#endregion

#region ERC20 Smart Wallet - Base USDC
#region TokenPaymaster - Celo CUSD

// var chainId = 42220; // celo

// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.CELO_CUSD);

// var erc20SmartWallet = await SmartWallet.Create(
// personalWallet: privateKeyWallet,
// chainId: 8453, // base mainnet
// gasless: true,
// factoryAddress: "0xEc87d96E3F324Dcc828750b52994C6DC69C8162b",
// entryPoint: Constants.ENTRYPOINT_ADDRESS_V07,
// tokenPaymaster: TokenPaymaster.BASE_USDC
// );
// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");

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

// var estimateGas = await ThirdwebTransaction.EstimateGasCosts(selfTransfer);
// Console.WriteLine($"Self transfer gas estimate: {estimateGas.Ether}");
// Console.WriteLine("Make sure you have enough USDC!");
// Console.ReadLine();
#endregion

#region TokenPaymaster - Base USDC

// var chainId = 8453; // base

// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.BASE_USDC);

// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");

// var receipt = await erc20SmartWallet.Transfer(chainId: chainId, toAddress: erc20SmartWalletAddress, weiAmount: 0);
// Console.WriteLine($"Receipt: {JsonConvert.SerializeObject(receipt, Formatting.Indented)}");

#endregion

#region TokenPaymaster - Lisk LSK

// var chainId = 1135; // lisk

// var erc20SmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: chainId, tokenPaymaster: TokenPaymaster.LISK_LSK);

// var erc20SmartWalletAddress = await erc20SmartWallet.GetAddress();
// Console.WriteLine($"ERC20 Smart Wallet address: {erc20SmartWalletAddress}");

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

#endregion

Expand Down Expand Up @@ -349,7 +366,7 @@

#region InAppWallet - OAuth

// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Twitch);
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google);
// if (!await inAppWalletOAuth.IsConnected())
// {
// _ = await inAppWalletOAuth.LoginWithOauth(
Expand Down
28 changes: 25 additions & 3 deletions Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum TokenPaymaster
{
NONE,
BASE_USDC,
CELO_CUSD,
LISK_LSK
}

public class SmartWallet : IThirdwebWallet
Expand Down Expand Up @@ -66,10 +68,30 @@ private struct TokenPaymasterConfig
new TokenPaymasterConfig()
{
ChainId = 8453,
PaymasterAddress = "0xff4d12b1f8d276aa4a9e8cc80539e806791bfe28",
PaymasterAddress = "0x2222f2738BE6bB7aA0Bfe4AEeAf2908172CF5539",
TokenAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
BalanceStorageSlot = 9
}
},
{
TokenPaymaster.CELO_CUSD,
new TokenPaymasterConfig()
{
ChainId = 42220,
PaymasterAddress = "0x3feA3c5744D715ff46e91C4e5C9a94426DfF2aF9",
TokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a",
BalanceStorageSlot = 9
}
},
{
TokenPaymaster.LISK_LSK,
new TokenPaymasterConfig()
{
ChainId = 1135,
PaymasterAddress = "0x9eb8cf7fBa5ed9EeDCC97a0d52254cc0e9B1AC25",
TokenAddress = "0xac485391EB2d7D88253a7F1eF18C37f4242D1A24",
BalanceStorageSlot = 9
}
}
};

Expand Down Expand Up @@ -154,7 +176,7 @@ public static async Task<SmartWallet> Create(
}
}

entryPoint ??= Constants.ENTRYPOINT_ADDRESS_V06;
entryPoint ??= tokenPaymaster == TokenPaymaster.NONE ? Constants.ENTRYPOINT_ADDRESS_V06 : Constants.ENTRYPOINT_ADDRESS_V07;

var entryPointVersion = Utils.GetEntryPointVersion(entryPoint);

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

// Hash, sign and encode the user operation
Expand Down

0 comments on commit be34729

Please sign in to comment.