Skip to content

Commit

Permalink
Managed ZkSync Paymaster
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper committed May 29, 2024
1 parent fa39694 commit 9c79f7f
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 55 deletions.
56 changes: 34 additions & 22 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,43 @@
}

// Prepare a transaction directly, or with Contract.Prepare
var tx = await ThirdwebTransaction.Create(
client: client,
wallet: privateKeyWallet,
txInput: new ThirdwebTransactionInput()
// var tx = await ThirdwebTransaction.Create(
// client: client,
// wallet: privateKeyWallet,
// txInput: new ThirdwebTransactionInput()
// {
// From = await privateKeyWallet.GetAddress(),
// To = await privateKeyWallet.GetAddress(),
// Value = new HexBigInteger(BigInteger.Zero),
// },
// chainId: 300
// );

// // Set zkSync options
// tx.SetZkSyncOptions(
// new ZkSyncOptions(
// // Paymaster contract address
// paymaster: "0xbA226d47Cbb2731CBAA67C916c57d68484AA269F",
// // IPaymasterFlow interface encoded data
// paymasterInput: "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"
// )
// );

// // Send as usual, it's now gasless!
// var txHash = await ThirdwebTransaction.Send(transaction: tx);
// Console.WriteLine($"Transaction hash: {txHash}");

var zkSmartWallet = await SmartWallet.Create(client: client, personalWallet: privateKeyWallet, chainId: 300, gasless: true);
var zkSyncSignatureBasedAaTxHash = await zkSmartWallet.SendTransaction(
new ThirdwebTransactionInput()
{
From = await privateKeyWallet.GetAddress(),
To = await privateKeyWallet.GetAddress(),
From = await zkSmartWallet.GetAddress(),
To = await zkSmartWallet.GetAddress(),
Value = new HexBigInteger(BigInteger.Zero),
},
chainId: 300
Data = "0x",
}
);

// Set zkSync options
tx.SetZkSyncOptions(
new ZkSyncOptions(
// Paymaster contract address
paymaster: "0xbA226d47Cbb2731CBAA67C916c57d68484AA269F",
// IPaymasterFlow interface encoded data
paymasterInput: "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"
)
);

// Send as usual, it's now gasless!
var txHash = await ThirdwebTransaction.Send(transaction: tx);
Console.WriteLine($"Transaction hash: {txHash}");
Console.WriteLine($"Transaction hash: {zkSyncSignatureBasedAaTxHash}");



Expand Down
1 change: 0 additions & 1 deletion Thirdweb/Thirdweb.Transactions/ThirdwebTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ public static async Task<string> Send(ThirdwebTransaction transaction)
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx);
break;
case ThirdwebAccountType.SmartAccount:

var smartAccount = transaction._wallet as SmartWallet;
hash = await smartAccount.SendTransaction(transaction.Input);
break;
Expand Down
1 change: 1 addition & 0 deletions Thirdweb/Thirdweb.Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public static class Constants
"0x0101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000001010101010100000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
internal const string FALLBACK_IPFS_GATEWAY = "https://ipfs.io/ipfs/";
internal const string PIN_URI = "https://storage.thirdweb.com/ipfs/upload";
internal const string ZKSYNC_SIGNATUREBASED_PAYMASTER = "0xE74eA4e1785F74016e0076754B5ca6d8ADC10934";
}
}
153 changes: 121 additions & 32 deletions Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class PMSponsorOperationResponse
public string paymasterAndData { get; set; }
}

public class PMSponsorTransactionResponse
{
public string paymasterInput { get; set; }
}

public class ThirdwebGetUserOperationGasPriceResponse
{
public string maxFeePerGas { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public static async Task<PMSponsorOperationResponse> PMSponsorUserOperation(Thir
}
}

public static async Task<PMSponsorTransactionResponse> PMSponsorTransaction(ThirdwebClient client, string paymasterUrl, object requestId, ThirdwebTransactionInput userOp, string entryPoint)
{
var response = await BundlerRequest(client, paymasterUrl, requestId, "pm_sponsorTransaction", userOp, new EntryPointWrapper() { entryPoint = entryPoint });
try
{
return JsonConvert.DeserializeObject<PMSponsorTransactionResponse>(response.Result.ToString());
}
catch
{
return new PMSponsorTransactionResponse() { paymasterInput = response.Result.ToString() };
}
}

// Request

private static async Task<RpcResponseMessage> BundlerRequest(ThirdwebClient client, string url, object requestId, string method, params object[] args)
Expand Down

0 comments on commit 9c79f7f

Please sign in to comment.