Skip to content

Commit

Permalink
Merge branch 'main' into firekeeper/nebula
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper authored Jan 24, 2025
2 parents 2ae308f + a6afc39 commit a643f98
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefaultVersion>2.15.0</DefaultVersion>
<DefaultVersion>2.16.0</DefaultVersion>
<DefaultTargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</DefaultTargetFrameworks>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="dotenv.net" Version="3.1.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
Expand Down
51 changes: 30 additions & 21 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,16 @@

#region AA 0.6

// var smartWallet06 = await SmartWallet.Create(
// personalWallet: privateKeyWallet,
// chainId: 421614,
// gasless: true,
// factoryAddress: "0xa8deE7854fb1eA8c13b713585C81d91ea86dAD84",
// entryPoint: Constants.ENTRYPOINT_ADDRESS_V06
// );

// var receipt06 = await smartWallet06.ExecuteTransaction(new ThirdwebTransactionInput(chainId: 421614, to: await smartWallet06.GetAddress(), value: 0, data: "0x"));

// var smartWallet06 = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 421614, gasless: true);
// var receipt06 = await smartWallet06.Transfer(chainId: 421614, toAddress: await smartWallet06.GetAddress(), weiAmount: 0);
// Console.WriteLine($"Receipt: {receipt06}");

#endregion

#region AA 0.7

// var smartWallet07 = await SmartWallet.Create(
// personalWallet: privateKeyWallet,
// chainId: 421614,
// gasless: true,
// factoryAddress: "0x4f4e40E8F66e3Cc0FD7423E2fbd62A769ff551FB",
// entryPoint: Constants.ENTRYPOINT_ADDRESS_V07
// );

// var receipt07 = await smartWallet07.ExecuteTransaction(new ThirdwebTransactionInput(chainId: 421614, to: await smartWallet07.GetAddress(), value: 0, data: "0x"));

// var smartWallet07 = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 421614, gasless: true, entryPoint: Constants.ENTRYPOINT_ADDRESS_V07);
// var receipt07 = await smartWallet07.Transfer(chainId: 421614, toAddress: await smartWallet07.GetAddress(), weiAmount: 0);
// Console.WriteLine($"Receipt: {receipt07}");

#endregion
Expand Down Expand Up @@ -219,7 +203,7 @@

#region Smart Ecosystem Wallet

// var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Twitch);
// var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Github);
// if (!await eco.IsConnected())
// {
// _ = await eco.LoginWithOauth(
Expand Down Expand Up @@ -529,6 +513,31 @@

#endregion

#region InAppWallet - SiweExternal

// var inAppWalletSiweExternal = await InAppWallet.Create(client: client, authProvider: AuthProvider.SiweExternal);
// if (!await inAppWalletSiweExternal.IsConnected())
// {
// _ = await inAppWalletSiweExternal.LoginWithSiweExternal(
// isMobile: false,
// browserOpenAction: (url) =>
// {
// var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
// _ = Process.Start(psi);
// },
// forceWalletIds: new List<string> { "io.metamask", "com.coinbase.wallet", "xyz.abs" }
// );
// }
// var inAppWalletOAuthAddress = await inAppWalletSiweExternal.GetAddress();
// Console.WriteLine($"InAppWallet SiweExternal address: {inAppWalletOAuthAddress}");

// var inAppWalletAuthDetails = inAppWalletSiweExternal.GetUserAuthDetails();
// Console.WriteLine($"InAppWallet OAuth auth details: {JsonConvert.SerializeObject(inAppWalletAuthDetails, Formatting.Indented)}");

// await inAppWalletSiweExternal.Disconnect();

#endregion

#region Smart Wallet - Gasless Transaction

// var smartWallet = await SmartWallet.Create(privateKeyWallet, 78600);
Expand Down
1 change: 1 addition & 0 deletions Thirdweb.Tests/Thirdweb.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="dotenv.net" />
<PackageReference Include="Moq" />
</ItemGroup>

<ItemGroup>
Expand Down
37 changes: 19 additions & 18 deletions Thirdweb/Thirdweb.Transactions/ThirdwebTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class ThirdwebTransaction
{
public ThirdwebTransactionInput Input { get; }

private readonly IThirdwebWallet _wallet;
internal readonly IThirdwebWallet Wallet;

private ThirdwebTransaction(IThirdwebWallet wallet, ThirdwebTransactionInput txInput)
{
this.Input = txInput;
this._wallet = wallet;
this.Wallet = wallet;
}

/// <summary>
Expand Down Expand Up @@ -215,7 +215,7 @@ public static async Task<TotalCosts> EstimateTotalCosts(ThirdwebTransaction tran
/// <returns>The estimated gas price.</returns>
public static async Task<BigInteger> EstimateGasPrice(ThirdwebTransaction transaction, bool withBump = true)
{
return await Utils.FetchGasPrice(transaction._wallet.Client, transaction.Input.ChainId.Value, withBump).ConfigureAwait(false);
return await Utils.FetchGasPrice(transaction.Wallet.Client, transaction.Input.ChainId.Value, withBump).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -226,10 +226,10 @@ public static async Task<BigInteger> EstimateGasPrice(ThirdwebTransaction transa
/// <returns>The estimated maximum fee per gas and maximum priority fee per gas.</returns>
public static async Task<(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas)> EstimateGasFees(ThirdwebTransaction transaction, bool withBump = true)
{
var rpc = ThirdwebRPC.GetRpcInstance(transaction._wallet.Client, transaction.Input.ChainId.Value);
var rpc = ThirdwebRPC.GetRpcInstance(transaction.Wallet.Client, transaction.Input.ChainId.Value);
var chainId = transaction.Input.ChainId.Value;

if (await Utils.IsZkSync(transaction._wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false))
if (await Utils.IsZkSync(transaction.Wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false))
{
var fees = await rpc.SendRequestAsync<JToken>("zks_estimateFee", transaction.Input).ConfigureAwait(false);
var maxFee = fees["max_fee_per_gas"].ToObject<HexBigInteger>().Value;
Expand All @@ -238,7 +238,7 @@ public static async Task<BigInteger> EstimateGasPrice(ThirdwebTransaction transa
}
else
{
return await Utils.FetchGasFees(transaction._wallet.Client, chainId, withBump).ConfigureAwait(false);
return await Utils.FetchGasFees(transaction.Wallet.Client, chainId, withBump).ConfigureAwait(false);
}
}

Expand All @@ -249,7 +249,7 @@ public static async Task<BigInteger> EstimateGasPrice(ThirdwebTransaction transa
/// <returns>The result of the simulation.</returns>
public static async Task<string> Simulate(ThirdwebTransaction transaction)
{
var rpc = ThirdwebRPC.GetRpcInstance(transaction._wallet.Client, transaction.Input.ChainId.Value);
var rpc = ThirdwebRPC.GetRpcInstance(transaction.Wallet.Client, transaction.Input.ChainId.Value);
return await rpc.SendRequestAsync<string>("eth_call", transaction.Input, "latest");
}

Expand All @@ -260,8 +260,8 @@ public static async Task<string> Simulate(ThirdwebTransaction transaction)
/// <returns>The estimated gas limit.</returns>
public static async Task<BigInteger> EstimateGasLimit(ThirdwebTransaction transaction)
{
var rpc = ThirdwebRPC.GetRpcInstance(transaction._wallet.Client, transaction.Input.ChainId.Value);
var isZkSync = await Utils.IsZkSync(transaction._wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false);
var rpc = ThirdwebRPC.GetRpcInstance(transaction.Wallet.Client, transaction.Input.ChainId.Value);
var isZkSync = await Utils.IsZkSync(transaction.Wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false);
BigInteger divider = isZkSync
? 7
: transaction.Input.AuthorizationList == null
Expand All @@ -288,12 +288,12 @@ public static async Task<BigInteger> EstimateGasLimit(ThirdwebTransaction transa
/// <returns>The nonce.</returns>
public static async Task<BigInteger> GetNonce(ThirdwebTransaction transaction)
{
return await transaction._wallet.GetTransactionCount(chainId: transaction.Input.ChainId, blocktag: "pending").ConfigureAwait(false);
return await transaction.Wallet.GetTransactionCount(chainId: transaction.Input.ChainId, blocktag: "pending").ConfigureAwait(false);
}

private static async Task<BigInteger> GetGasPerPubData(ThirdwebTransaction transaction)
{
var rpc = ThirdwebRPC.GetRpcInstance(transaction._wallet.Client, transaction.Input.ChainId.Value);
var rpc = ThirdwebRPC.GetRpcInstance(transaction.Wallet.Client, transaction.Input.ChainId.Value);
var hex = (await rpc.SendRequestAsync<JToken>("zks_estimateFee", transaction.Input).ConfigureAwait(false))["gas_per_pubdata_limit"].ToString();
var finalGasPerPubData = new HexBigInteger(hex).Value * 10 / 5;
return finalGasPerPubData < 10000 ? 10000 : finalGasPerPubData;
Expand All @@ -306,7 +306,7 @@ private static async Task<BigInteger> GetGasPerPubData(ThirdwebTransaction trans
/// <returns>The signed transaction.</returns>
public static async Task<string> Sign(ThirdwebTransaction transaction)
{
return await transaction._wallet.SignTransaction(transaction.Input).ConfigureAwait(false);
return await transaction.Wallet.SignTransaction(transaction.Input).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -362,31 +362,32 @@ public static async Task<string> Send(ThirdwebTransaction transaction)
{
transaction = await Prepare(transaction).ConfigureAwait(false);

var rpc = ThirdwebRPC.GetRpcInstance(transaction._wallet.Client, transaction.Input.ChainId.Value);
var rpc = ThirdwebRPC.GetRpcInstance(transaction.Wallet.Client, transaction.Input.ChainId.Value);
string hash;

if (await Utils.IsZkSync(transaction._wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false) && transaction.Input.ZkSync.HasValue)
if (await Utils.IsZkSync(transaction.Wallet.Client, transaction.Input.ChainId.Value).ConfigureAwait(false) && transaction.Input.ZkSync.HasValue)
{
var zkTx = await ConvertToZkSyncTransaction(transaction).ConfigureAwait(false);
var zkTxSigned = await EIP712.GenerateSignature_ZkSyncTransaction("zkSync", "2", transaction.Input.ChainId.Value, zkTx, transaction._wallet).ConfigureAwait(false);
var zkTxSigned = await EIP712.GenerateSignature_ZkSyncTransaction("zkSync", "2", transaction.Input.ChainId.Value, zkTx, transaction.Wallet).ConfigureAwait(false);
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", zkTxSigned).ConfigureAwait(false);
}
else
{
switch (transaction._wallet.AccountType)
switch (transaction.Wallet.AccountType)
{
case ThirdwebAccountType.PrivateKeyAccount:
var signedTx = await Sign(transaction);
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx).ConfigureAwait(false);
break;
case ThirdwebAccountType.SmartAccount:
case ThirdwebAccountType.ExternalAccount:
hash = await transaction._wallet.SendTransaction(transaction.Input).ConfigureAwait(false);
hash = await transaction.Wallet.SendTransaction(transaction.Input).ConfigureAwait(false);
break;
default:
throw new NotImplementedException("Account type not supported");
}
}
Utils.TrackTransaction(transaction, hash);
return hash;
}

Expand All @@ -398,7 +399,7 @@ public static async Task<string> Send(ThirdwebTransaction transaction)
public static async Task<ThirdwebTransactionReceipt> SendAndWaitForTransactionReceipt(ThirdwebTransaction transaction)
{
var txHash = await Send(transaction).ConfigureAwait(false);
return await WaitForTransactionReceipt(transaction._wallet.Client, transaction.Input.ChainId.Value, txHash).ConfigureAwait(false);
return await WaitForTransactionReceipt(transaction.Wallet.Client, transaction.Input.ChainId.Value, txHash).ConfigureAwait(false);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Thirdweb/Thirdweb.Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class Constants
{
public const string VERSION = "2.15.0";
public const string VERSION = "2.16.0";

public const string IERC20_INTERFACE_ID = "0x36372b07";
public const string IERC721_INTERFACE_ID = "0x80ac58cd";
Expand Down
56 changes: 56 additions & 0 deletions Thirdweb/Thirdweb.Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,4 +1191,60 @@ internal static byte[] ToByteArrayForRLPEncoding(this BigInteger value)

return value.ToBytesForRLPEncoding();
}

internal static async void TrackTransaction(ThirdwebTransaction transaction, string transactionHash)
{
try
{
var wallet = transaction.Wallet;
var content = new StringContent(
JsonConvert.SerializeObject(
new
{
source = "sdk",
action = "transaction:sent",
clientId = wallet.Client.ClientId,
chainId = transaction.Input.ChainId.Value,
transactionHash,
walletAddress = await wallet.GetAddress().ConfigureAwait(false),
walletType = wallet.WalletId,
contractAddress = transaction.Input.To,
gasPrice = transaction.Input.GasPrice?.Value ?? transaction.Input.MaxFeePerGas?.Value
}
),
Encoding.UTF8,
"application/json"
);
_ = await wallet.Client.HttpClient.PostAsync("https://c.thirdweb.com/event", content);
}
catch
{
// Ignore
}
}

internal static async void TrackConnection(IThirdwebWallet wallet)
{
try
{
var content = new StringContent(
JsonConvert.SerializeObject(
new
{
source = "connectWallet",
action = "connect",
walletAddress = await wallet.GetAddress().ConfigureAwait(false),
walletType = wallet.WalletId,
}
),
Encoding.UTF8,
"application/json"
);
_ = await wallet.Client.HttpClient.PostAsync("https://c.thirdweb.com/event", content);
}
catch
{
// Ignore
}
}
}
Loading

0 comments on commit a643f98

Please sign in to comment.