Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@

#endregion

#region Smart Ecosystem Wallet

// var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Twitch);
// if (!await eco.IsConnected())
// {
// _ = await eco.LoginWithOauth(
// isMobile: false,
// browserOpenAction: (url) =>
// {
// var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
// _ = Process.Start(psi);
// }
// );
// }
// var smartEco = await SmartWallet.Create(eco, 421614);
// var addy = await smartEco.GetAddress();
// Console.WriteLine($"Smart Ecosystem Wallet address: {addy}");

#endregion

#region Ecosystem Wallet

// var ecosystemWallet = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Telegram);
Expand Down
26 changes: 13 additions & 13 deletions Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public async Task TestRpcError()
Assert.Contains("RPC Error for request", exception.Message);
}

[Fact(Timeout = 120000)]
public async Task TestCache()
{
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
var blockNumber1 = await rpc.SendRequestAsync<string>("eth_blockNumber");
await ThirdwebTask.Delay(1);
var blockNumber2 = await rpc.SendRequestAsync<string>("eth_blockNumber");
Assert.Equal(blockNumber1, blockNumber2);
await ThirdwebTask.Delay(1000);
var blockNumber3 = await rpc.SendRequestAsync<string>("eth_blockNumber");
Assert.NotEqual(blockNumber1, blockNumber3);
}
// [Fact(Timeout = 120000)]
// public async Task TestCache()
// {
// var client = ThirdwebClient.Create(secretKey: this.SecretKey);
// var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
// var blockNumber1 = await rpc.SendRequestAsync<string>("eth_blockNumber");
// await ThirdwebTask.Delay(1);
// var blockNumber2 = await rpc.SendRequestAsync<string>("eth_blockNumber");
// Assert.Equal(blockNumber1, blockNumber2);
// await ThirdwebTask.Delay(1000);
// var blockNumber3 = await rpc.SendRequestAsync<string>("eth_blockNumber");
// Assert.NotEqual(blockNumber1, blockNumber3);
// }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using Newtonsoft.Json;

namespace Thirdweb;
Expand Down Expand Up @@ -54,4 +55,40 @@ internal class EnclaveSignResponse
[JsonProperty("hash")]
internal string Hash { get; set; }
}

public class EcosystemDetails
{
[JsonProperty("thirdwebAccountId")]
public string ThirdwebAccountId { get; set; }

[JsonProperty("permission")]
public string Permission { get; set; }

[JsonProperty("authOptions")]
public List<string> AuthOptions { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("slug")]
public string Slug { get; set; }

[JsonProperty("imageUrl")]
public string ImageUrl { get; set; }

[JsonProperty("smartAccountOptions")]
public EcosystemDetails_SmartAccountOptions? SmartAccountOptions { get; set; }
}

public struct EcosystemDetails_SmartAccountOptions
{
[JsonProperty("chainIds")]
public List<BigInteger> ChainIds { get; set; }

[JsonProperty("sponsorGas")]
public bool SponsorGas { get; set; }

[JsonProperty("accountFactoryAddress")]
public string AccountFactoryAddress { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ public string GetPhoneNumber()
return this._phoneNumber;
}

public async Task<EcosystemDetails> GetEcosystemDetails()
{
var url = $"{EMBEDDED_WALLET_PATH_2024}/ecosystem-wallet";
var response = await this._httpClient.GetAsync(url).ConfigureAwait(false);
_ = response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<EcosystemDetails>(content);
}

#endregion

#region Account Linking
Expand Down
22 changes: 20 additions & 2 deletions Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ BigInteger erc20PaymasterStorageSlot
public static async Task<SmartWallet> Create(
IThirdwebWallet personalWallet,
BigInteger chainId,
bool gasless = true,
bool? gasless = null,
string factoryAddress = null,
string accountAddressOverride = null,
string entryPoint = null,
Expand All @@ -137,10 +137,28 @@ public static async Task<SmartWallet> Create(
throw new InvalidOperationException("SmartAccount.Connect: Personal account must be connected.");
}

if (personalWallet is EcosystemWallet ecoWallet)
{
try
{
var ecoDetails = await ecoWallet.GetEcosystemDetails();
if (ecoDetails.SmartAccountOptions.HasValue)
{
gasless ??= ecoDetails.SmartAccountOptions?.SponsorGas;
factoryAddress ??= string.IsNullOrEmpty(ecoDetails.SmartAccountOptions?.AccountFactoryAddress) ? null : ecoDetails.SmartAccountOptions?.AccountFactoryAddress;
}
}
catch
{
// no-op
}
}

entryPoint ??= Constants.ENTRYPOINT_ADDRESS_V06;

var entryPointVersion = Utils.GetEntryPointVersion(entryPoint);

gasless ??= true;
bundlerUrl ??= $"https://{chainId}.bundler.thirdweb.com/v2";
paymasterUrl ??= $"https://{chainId}.bundler.thirdweb.com/v2";
factoryAddress ??= entryPointVersion == 6 ? Constants.DEFAULT_FACTORY_ADDRESS_V06 : Constants.DEFAULT_FACTORY_ADDRESS_V07;
Expand Down Expand Up @@ -180,7 +198,7 @@ public static async Task<SmartWallet> Create(

return new SmartWallet(
personalWallet,
gasless,
gasless.Value,
chainId,
bundlerUrl,
paymasterUrl,
Expand Down
Loading