Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 1 addition & 1 deletion Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
// Console.WriteLine($"Transfer Receipt: {receipt.TransactionHash}");

// // Double check that it was upgraded
// var isDelegated = await Utils.IsDelegatedAccount(client, chain, smartEoaAddress);
// var isDelegated = await Utils.IsDeployed(client, chain, smartEoaAddress);
// Console.WriteLine($"Is delegated: {isDelegated}");

// // Create a session key
Expand Down
3 changes: 1 addition & 2 deletions Thirdweb/Thirdweb.Utils/Constants.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Thirdweb/Thirdweb.Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,10 +1332,10 @@ public static async Task<ThirdwebTransactionReceipt> WaitForTransactionReceipt(T
return receipt;
}

public static async Task<bool> IsDelegatedAccount(ThirdwebClient client, BigInteger chainId, string address)
public static async Task<bool> IsDelegatedAccount(ThirdwebClient client, BigInteger chainId, string address, string delegationContract)
{
var rpc = ThirdwebRPC.GetRpcInstance(client, chainId);
var code = await rpc.SendRequestAsync<string>("eth_getCode", address, "latest");
return code.Equals($"0xef0100{Constants.MINIMAL_ACCOUNT_7702[2..]}", StringComparison.OrdinalIgnoreCase);
return code.Equals($"0xef0100{delegationContract[2..]}", StringComparison.OrdinalIgnoreCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class EcosystemWallet : IThirdwebWallet

internal string Address;
internal ExecutionMode ExecutionMode;
internal string DelegationContractAddress;

private readonly string _ecosystemId;
private readonly string _ecosystemPartnerId;
Expand All @@ -60,7 +61,8 @@ internal EcosystemWallet(
IThirdwebWallet siweSigner,
string legacyEncryptionKey,
string walletSecret,
ExecutionMode executionMode
ExecutionMode executionMode,
string delegationContractAddress
)
{
this.Client = client;
Expand All @@ -76,7 +78,7 @@ ExecutionMode executionMode
this.WalletSecret = walletSecret;
this.ExecutionMode = executionMode;
this.AccountType = executionMode == ExecutionMode.EOA ? ThirdwebAccountType.PrivateKeyAccount : ThirdwebAccountType.ExternalAccount;
;
this.DelegationContractAddress = delegationContractAddress;
}

#region Creation
Expand Down Expand Up @@ -118,6 +120,8 @@ public static async Task<EcosystemWallet> Create(
throw new ArgumentNullException(nameof(client), "Client cannot be null.");
}

var delegationContractResponse = await BundlerClient.TwGetDelegationContract(client: client, url: $"https://1.bundler.thirdweb.com", requestId: 7702);

if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(phoneNumber) && authProvider == Thirdweb.AuthProvider.Default)
{
throw new ArgumentException("Email, Phone Number, or OAuth Provider must be provided to login.");
Expand Down Expand Up @@ -193,7 +197,8 @@ public static async Task<EcosystemWallet> Create(
siweSigner,
legacyEncryptionKey,
walletSecret,
executionMode
executionMode,
delegationContractResponse.DelegationContract
)
{
Address = userAddress,
Expand All @@ -214,7 +219,8 @@ public static async Task<EcosystemWallet> Create(
siweSigner,
legacyEncryptionKey,
walletSecret,
executionMode
executionMode,
delegationContractResponse.DelegationContract
)
{
Address = null,
Expand Down Expand Up @@ -1294,9 +1300,9 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
{
var userWalletAddress = await this.GetAddress();
var userContract = await ThirdwebContract.Create(this.Client, userWalletAddress, transaction.ChainId, Constants.MINIMAL_ACCOUNT_7702_ABI);
var needsDelegation = !await Utils.IsDelegatedAccount(this.Client, transaction.ChainId, userWalletAddress);
var needsDelegation = !await Utils.IsDelegatedAccount(this.Client, transaction.ChainId, userWalletAddress, this.DelegationContractAddress);
EIP7702Authorization? authorization = needsDelegation
? await this.SignAuthorization(transaction.ChainId, Constants.MINIMAL_ACCOUNT_7702, willSelfExecute: this.ExecutionMode != ExecutionMode.EIP7702Sponsored)
? await this.SignAuthorization(transaction.ChainId, this.DelegationContractAddress, willSelfExecute: this.ExecutionMode != ExecutionMode.EIP7702Sponsored)
: null;

var calls = new List<Call>
Expand Down Expand Up @@ -1337,7 +1343,7 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
eoaAddress: userWalletAddress,
wrappedCalls: wrappedCalls,
signature: signature,
authorization: authorization != null && !await Utils.IsDelegatedAccount(this.Client, transaction.ChainId, userWalletAddress) ? authorization : null
authorization: authorization != null && !await Utils.IsDelegatedAccount(this.Client, transaction.ChainId, userWalletAddress, this.DelegationContractAddress) ? authorization : null
);
var queueId = response?.QueueId;
string txHash = null;
Expand Down Expand Up @@ -1473,7 +1479,7 @@ private async Task Ensure7702(BigInteger chainId, bool ensureDelegated)
throw new InvalidOperationException("This operation is only supported for EIP7702 and EIP7702Sponsored execution modes.");
}

if (!await Utils.IsDelegatedAccount(this.Client, chainId, this.Address).ConfigureAwait(false))
if (!await Utils.IsDelegatedAccount(this.Client, chainId, this.Address, this.DelegationContractAddress).ConfigureAwait(false))
{
if (ensureDelegated)
{
Expand Down
8 changes: 5 additions & 3 deletions Thirdweb/Thirdweb.Wallets/InAppWallet/InAppWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ internal InAppWallet(
string address,
string legacyEncryptionKey,
string walletSecret,
ExecutionMode executionMode
ExecutionMode executionMode,
string delegationContractAddress
)
: base(null, null, client, embeddedWallet, httpClient, email, phoneNumber, authProvider, siweSigner, legacyEncryptionKey, walletSecret, executionMode)
: base(null, null, client, embeddedWallet, httpClient, email, phoneNumber, authProvider, siweSigner, legacyEncryptionKey, walletSecret, executionMode, delegationContractAddress)
{
this.Address = address;
}
Expand Down Expand Up @@ -68,7 +69,8 @@ public static async Task<InAppWallet> Create(
ecoWallet.Address,
ecoWallet.LegacyEncryptionKey,
ecoWallet.WalletSecret,
ecoWallet.ExecutionMode
ecoWallet.ExecutionMode,
ecoWallet.DelegationContractAddress
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public class EthGetUserOperationReceiptResponse
public ThirdwebTransactionReceipt Receipt { get; set; }
}

public class TwGetDelegationContractResponse
{
[JsonProperty("delegationContract")]
public string DelegationContract { get; set; }
}

public class TwExecuteResponse
{
[JsonProperty("queueId")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace Thirdweb.AccountAbstraction;
public static class BundlerClient
{
// EIP 7702 requests
public static async Task<TwGetDelegationContractResponse> TwGetDelegationContract(ThirdwebClient client, string url, int requestId)
{
var response = await BundlerRequest(client, url, requestId, "tw_getDelegationContract").ConfigureAwait(false);
return JsonConvert.DeserializeObject<TwGetDelegationContractResponse>(response.Result.ToString());
}

public static async Task<TwExecuteResponse> TwExecute(
ThirdwebClient client,
string url,
Expand Down
Loading