Skip to content

Commit 0587370

Browse files
authored
Fetch EcosystemWallet AA Defaults from Dashboard (#88)
1 parent 821ba3b commit 0587370

File tree

5 files changed

+99
-15
lines changed

5 files changed

+99
-15
lines changed

Thirdweb.Console/Program.cs

+20
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@
9191

9292
#endregion
9393

94+
#region Smart Ecosystem Wallet
95+
96+
// var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Twitch);
97+
// if (!await eco.IsConnected())
98+
// {
99+
// _ = await eco.LoginWithOauth(
100+
// isMobile: false,
101+
// browserOpenAction: (url) =>
102+
// {
103+
// var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
104+
// _ = Process.Start(psi);
105+
// }
106+
// );
107+
// }
108+
// var smartEco = await SmartWallet.Create(eco, 421614);
109+
// var addy = await smartEco.GetAddress();
110+
// Console.WriteLine($"Smart Ecosystem Wallet address: {addy}");
111+
112+
#endregion
113+
94114
#region Ecosystem Wallet
95115

96116
// var ecosystemWallet = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Telegram);

Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ public async Task TestRpcError()
7070
Assert.Contains("RPC Error for request", exception.Message);
7171
}
7272

73-
[Fact(Timeout = 120000)]
74-
public async Task TestCache()
75-
{
76-
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
77-
var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
78-
var blockNumber1 = await rpc.SendRequestAsync<string>("eth_blockNumber");
79-
await ThirdwebTask.Delay(1);
80-
var blockNumber2 = await rpc.SendRequestAsync<string>("eth_blockNumber");
81-
Assert.Equal(blockNumber1, blockNumber2);
82-
await ThirdwebTask.Delay(1000);
83-
var blockNumber3 = await rpc.SendRequestAsync<string>("eth_blockNumber");
84-
Assert.NotEqual(blockNumber1, blockNumber3);
85-
}
73+
// [Fact(Timeout = 120000)]
74+
// public async Task TestCache()
75+
// {
76+
// var client = ThirdwebClient.Create(secretKey: this.SecretKey);
77+
// var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
78+
// var blockNumber1 = await rpc.SendRequestAsync<string>("eth_blockNumber");
79+
// await ThirdwebTask.Delay(1);
80+
// var blockNumber2 = await rpc.SendRequestAsync<string>("eth_blockNumber");
81+
// Assert.Equal(blockNumber1, blockNumber2);
82+
// await ThirdwebTask.Delay(1000);
83+
// var blockNumber3 = await rpc.SendRequestAsync<string>("eth_blockNumber");
84+
// Assert.NotEqual(blockNumber1, blockNumber3);
85+
// }
8686
}

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.Types.cs

+37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Numerics;
12
using Newtonsoft.Json;
23

34
namespace Thirdweb;
@@ -54,4 +55,40 @@ internal class EnclaveSignResponse
5455
[JsonProperty("hash")]
5556
internal string Hash { get; set; }
5657
}
58+
59+
public class EcosystemDetails
60+
{
61+
[JsonProperty("thirdwebAccountId")]
62+
public string ThirdwebAccountId { get; set; }
63+
64+
[JsonProperty("permission")]
65+
public string Permission { get; set; }
66+
67+
[JsonProperty("authOptions")]
68+
public List<string> AuthOptions { get; set; }
69+
70+
[JsonProperty("name")]
71+
public string Name { get; set; }
72+
73+
[JsonProperty("slug")]
74+
public string Slug { get; set; }
75+
76+
[JsonProperty("imageUrl")]
77+
public string ImageUrl { get; set; }
78+
79+
[JsonProperty("smartAccountOptions")]
80+
public EcosystemDetails_SmartAccountOptions? SmartAccountOptions { get; set; }
81+
}
82+
83+
public struct EcosystemDetails_SmartAccountOptions
84+
{
85+
[JsonProperty("chainIds")]
86+
public List<BigInteger> ChainIds { get; set; }
87+
88+
[JsonProperty("sponsorGas")]
89+
public bool SponsorGas { get; set; }
90+
91+
[JsonProperty("accountFactoryAddress")]
92+
public string AccountFactoryAddress { get; set; }
93+
}
5794
}

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

+9
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ public string GetPhoneNumber()
265265
return this._phoneNumber;
266266
}
267267

268+
public async Task<EcosystemDetails> GetEcosystemDetails()
269+
{
270+
var url = $"{EMBEDDED_WALLET_PATH_2024}/ecosystem-wallet";
271+
var response = await this._httpClient.GetAsync(url).ConfigureAwait(false);
272+
_ = response.EnsureSuccessStatusCode();
273+
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
274+
return JsonConvert.DeserializeObject<EcosystemDetails>(content);
275+
}
276+
268277
#endregion
269278

270279
#region Account Linking

Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ BigInteger erc20PaymasterStorageSlot
123123
public static async Task<SmartWallet> Create(
124124
IThirdwebWallet personalWallet,
125125
BigInteger chainId,
126-
bool gasless = true,
126+
bool? gasless = null,
127127
string factoryAddress = null,
128128
string accountAddressOverride = null,
129129
string entryPoint = null,
@@ -137,10 +137,28 @@ public static async Task<SmartWallet> Create(
137137
throw new InvalidOperationException("SmartAccount.Connect: Personal account must be connected.");
138138
}
139139

140+
if (personalWallet is EcosystemWallet ecoWallet)
141+
{
142+
try
143+
{
144+
var ecoDetails = await ecoWallet.GetEcosystemDetails();
145+
if (ecoDetails.SmartAccountOptions.HasValue)
146+
{
147+
gasless ??= ecoDetails.SmartAccountOptions?.SponsorGas;
148+
factoryAddress ??= string.IsNullOrEmpty(ecoDetails.SmartAccountOptions?.AccountFactoryAddress) ? null : ecoDetails.SmartAccountOptions?.AccountFactoryAddress;
149+
}
150+
}
151+
catch
152+
{
153+
// no-op
154+
}
155+
}
156+
140157
entryPoint ??= Constants.ENTRYPOINT_ADDRESS_V06;
141158

142159
var entryPointVersion = Utils.GetEntryPointVersion(entryPoint);
143160

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

181199
return new SmartWallet(
182200
personalWallet,
183-
gasless,
201+
gasless.Value,
184202
chainId,
185203
bundlerUrl,
186204
paymasterUrl,

0 commit comments

Comments
 (0)