From 672b8e2d9f1f5ff5c4ee0fdf717c1b8a17cb5f6a Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Thu, 24 Oct 2024 17:57:55 +0700 Subject: [PATCH 1/3] Fetch EcosystemWallet AA Defaults from Dashboard --- Thirdweb.Console/Program.cs | 20 ++++++++++ .../EcosystemWallet/EcosystemWallet.Types.cs | 37 +++++++++++++++++++ .../EcosystemWallet/EcosystemWallet.cs | 9 +++++ .../SmartWallet/SmartWallet.cs | 22 ++++++++++- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/Thirdweb.Console/Program.cs b/Thirdweb.Console/Program.cs index b73adccf..4d3e74a9 100644 --- a/Thirdweb.Console/Program.cs +++ b/Thirdweb.Console/Program.cs @@ -91,6 +91,26 @@ #endregion +#region Smart Ecosystem Wallet + +var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Telegram); +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); diff --git a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.Types.cs b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.Types.cs index 7eaada74..240a39a1 100644 --- a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.Types.cs +++ b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.Types.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Newtonsoft.Json; namespace Thirdweb; @@ -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 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 ChainIds { get; set; } + + [JsonProperty("sponsorGas")] + public bool SponsorGas { get; set; } + + [JsonProperty("accountFactoryAddress")] + public string AccountFactoryAddress { get; set; } + } } diff --git a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs index ed1d8937..07c053c1 100644 --- a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs @@ -264,6 +264,15 @@ public string GetPhoneNumber() return this._phoneNumber; } + public async Task 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(content); + } + #endregion #region Account Linking diff --git a/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs b/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs index 1633c489..641205b1 100644 --- a/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs @@ -123,7 +123,7 @@ BigInteger erc20PaymasterStorageSlot public static async Task Create( IThirdwebWallet personalWallet, BigInteger chainId, - bool gasless = true, + bool? gasless = null, string factoryAddress = null, string accountAddressOverride = null, string entryPoint = null, @@ -137,10 +137,28 @@ public static async Task 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; @@ -180,7 +198,7 @@ public static async Task Create( return new SmartWallet( personalWallet, - gasless, + gasless.Value, chainId, bundlerUrl, paymasterUrl, From 47959a28687e92f12b2d02dc3c882ce20d83affb Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Thu, 24 Oct 2024 18:01:27 +0700 Subject: [PATCH 2/3] Update Program.cs --- Thirdweb.Console/Program.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Thirdweb.Console/Program.cs b/Thirdweb.Console/Program.cs index af3da50a..905e3eae 100644 --- a/Thirdweb.Console/Program.cs +++ b/Thirdweb.Console/Program.cs @@ -93,21 +93,21 @@ #region Smart Ecosystem Wallet -var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Telegram); -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}"); +// 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 From c3cbf95d51005b29000948f627151060fa60772f Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Thu, 24 Oct 2024 18:02:36 +0700 Subject: [PATCH 3/3] Update Thirdweb.RPC.Tests.cs --- .../Thirdweb.RPC/Thirdweb.RPC.Tests.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs b/Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs index bbc1f033..7769d074 100644 --- a/Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs +++ b/Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs @@ -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("eth_blockNumber"); - await ThirdwebTask.Delay(1); - var blockNumber2 = await rpc.SendRequestAsync("eth_blockNumber"); - Assert.Equal(blockNumber1, blockNumber2); - await ThirdwebTask.Delay(1000); - var blockNumber3 = await rpc.SendRequestAsync("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("eth_blockNumber"); + // await ThirdwebTask.Delay(1); + // var blockNumber2 = await rpc.SendRequestAsync("eth_blockNumber"); + // Assert.Equal(blockNumber1, blockNumber2); + // await ThirdwebTask.Delay(1000); + // var blockNumber3 = await rpc.SendRequestAsync("eth_blockNumber"); + // Assert.NotEqual(blockNumber1, blockNumber3); + // } }