@@ -8,15 +8,14 @@ public enum ExecutionMode
88{
99 EOA ,
1010 EIP7702 ,
11- EIP7702Sponsored
1211}
1312
1413/// <summary>
1514/// Represents a 7702 delegated wallet with granular session key permissions and automatic session key execution.
1615/// </summary>
17- public class ThirdwebWallet : IThirdwebWallet
16+ public class SmarterWallet : IThirdwebWallet
1817{
19- public string WalletId => "thirdweb " ;
18+ public string WalletId => "smarter " ;
2019
2120 public ThirdwebClient Client { get ; }
2221 public ThirdwebAccountType AccountType => ThirdwebAccountType . ExternalAccount ;
@@ -28,7 +27,7 @@ public class ThirdwebWallet : IThirdwebWallet
2827
2928 private EIP7702Authorization ? Authorization { get ; set ; }
3029
31- internal ThirdwebWallet ( ThirdwebClient client , BigInteger chainId , IThirdwebWallet userWallet , ThirdwebContract userContract , EIP7702Authorization ? authorization , ExecutionMode executionMode )
30+ internal SmarterWallet ( ThirdwebClient client , BigInteger chainId , IThirdwebWallet userWallet , ThirdwebContract userContract , EIP7702Authorization ? authorization , ExecutionMode executionMode )
3231 {
3332 this . Client = client ;
3433 this . ChainId = chainId ;
@@ -38,15 +37,15 @@ internal ThirdwebWallet(ThirdwebClient client, BigInteger chainId, IThirdwebWall
3837 this . ExecutionMode = executionMode ;
3938 }
4039
41- public static async Task < ThirdwebWallet > Create ( ThirdwebClient client , BigInteger chainId , IThirdwebWallet userWallet , ExecutionMode executionMode )
40+ public static async Task < SmarterWallet > Create ( ThirdwebClient client , BigInteger chainId , IThirdwebWallet userWallet , ExecutionMode executionMode )
4241 {
4342 var userWalletAddress = await userWallet . GetAddress ( ) ;
4443 var userContract = await ThirdwebContract . Create ( client , userWalletAddress , chainId , Constants . MINIMAL_ACCOUNT_7702_ABI ) ;
4544 var needsDelegation = ! await Utils . IsDelegatedAccount ( client , chainId , userWalletAddress ) ;
4645 EIP7702Authorization ? authorization = needsDelegation
47- ? await userWallet . SignAuthorization ( chainId , Constants . MINIMAL_ACCOUNT_7702 , willSelfExecute : executionMode != ExecutionMode . EIP7702Sponsored )
46+ ? await userWallet . SignAuthorization ( chainId , Constants . MINIMAL_ACCOUNT_7702 , willSelfExecute : executionMode != ExecutionMode . EIP7702 )
4847 : null ;
49- var wallet = new ThirdwebWallet ( client , chainId , userWallet , userContract , authorization , executionMode ) ;
48+ var wallet = new SmarterWallet ( client , chainId , userWallet , userContract , authorization , executionMode ) ;
5049 Utils . TrackConnection ( wallet ) ;
5150 return wallet ;
5251 }
@@ -130,54 +129,53 @@ public Task<string> SignTransaction(ThirdwebTransactionInput transaction)
130129
131130 public async Task < string > SendTransaction ( ThirdwebTransactionInput transaction )
132131 {
133- // TODO: managed execution - executeWithSig
134- if ( this . ExecutionMode == ExecutionMode . EIP7702Sponsored )
132+ ThirdwebTransaction finalTx ;
133+ switch ( this . ExecutionMode )
135134 {
136- throw new NotImplementedException ( "EIP7702 Sponsored Execution mode is not yet implemented." ) ;
137-
135+ case ExecutionMode . EIP7702 :
136+ throw new NotImplementedException ( "EIP7702 Sponsored Execution mode is not yet implemented." ) ;
138137 // 1. Create payload with eoa address, wrapped calls, signature and optional authorizationList
139138 // 2. Send to https://{chainId}.bundler.thirdweb.com as RpcRequest w/ method tw_execute
140139 // 3. Retrieve tx hash or queue id from response
141140 // 4. Return tx hash
142- }
143- else if ( this . ExecutionMode == ExecutionMode . EIP7702 )
144- {
145- var calls = new List < Call >
146- {
147- new ( )
141+ case ExecutionMode . EOA :
142+ // Direct Call struct
143+ var calls = new List < Call >
148144 {
149- Target = transaction . To ,
150- Value = transaction . Value ? . Value ?? BigInteger . Zero ,
151- Data = transaction . Data . HexToBytes ( )
145+ new ( )
146+ {
147+ Target = transaction . To ,
148+ Value = transaction . Value ? . Value ?? BigInteger . Zero ,
149+ Data = transaction . Data . HexToBytes ( )
150+ }
151+ } ;
152+ // Add up values of all calls
153+ BigInteger totalValue = 0 ;
154+ foreach ( var call in calls )
155+ {
156+ totalValue += call . Value ;
152157 }
153- } ;
158+ // Prepare a tx using the user wallet as the executor
159+ finalTx = await this . UserContract . Prepare ( wallet : this . UserWallet , method : "execute" , weiValue : totalValue , parameters : new object [ ] { calls } ) ;
160+ break ;
161+ default :
162+ throw new NotImplementedException ( $ "Execution mode { this . ExecutionMode } is not supported.") ;
163+ }
154164
155- BigInteger totalValue = 0 ;
156- foreach ( var call in calls )
165+ // Append authorization if not delegated yet
166+ if ( this . Authorization != null )
167+ {
168+ if ( ! await Utils . IsDelegatedAccount ( this . Client , this . ChainId , await this . UserWallet . GetAddress ( ) ) )
157169 {
158- totalValue += call . Value ;
170+ finalTx . Input . AuthorizationList = new List < EIP7702Authorization > ( ) { this . Authorization . Value } ;
159171 }
160-
161- var tx = await this . UserContract . Prepare ( wallet : this . UserWallet , method : "execute" , weiValue : totalValue , parameters : new object [ ] { calls } ) ;
162-
163- if ( this . Authorization != null )
172+ else
164173 {
165- if ( ! await Utils . IsDelegatedAccount ( this . Client , this . ChainId , await this . UserWallet . GetAddress ( ) ) )
166- {
167- tx . Input . AuthorizationList = new List < EIP7702Authorization > ( ) { this . Authorization . Value } ;
168- }
169- else
170- {
171- this . Authorization = null ;
172- }
174+ this . Authorization = null ;
173175 }
174-
175- return await ThirdwebTransaction . Send ( tx ) ;
176- }
177- else
178- {
179- return await this . UserWallet . SendTransaction ( transaction ) ;
180176 }
177+ // Send the transaction and return the
178+ return await ThirdwebTransaction . Send ( finalTx ) ;
181179 }
182180
183181 public async Task < ThirdwebTransactionReceipt > ExecuteTransaction ( ThirdwebTransactionInput transaction )
0 commit comments