@@ -28,18 +28,12 @@ import {
28
28
useProvider ,
29
29
voyager ,
30
30
} from "@starknet-react/core" ;
31
- import {
32
- CallData ,
33
- RpcProvider ,
34
- TypedData ,
35
- cairo ,
36
- num ,
37
- shortString ,
38
- } from "starknet" ;
39
- import { CheckIcon , CopyAddress , DotsIcon , PacmanIcon } from "@cartridge/ui" ;
31
+ import { RpcProvider , TypedData , num , shortString } from "starknet" ;
32
+ import { CheckIcon , DotsIcon , PacmanIcon } from "@cartridge/ui" ;
40
33
import { useConnection } from "hooks/connection" ;
41
34
import { useToast } from "hooks/toast" ;
42
35
import {
36
+ ETH_CONTRACT_ADDRESS ,
43
37
TokenInfo ,
44
38
fetchTokenInfo ,
45
39
getBalanceStr ,
@@ -51,7 +45,10 @@ import {
51
45
import { ErrorAlert } from "../../ErrorAlert" ;
52
46
import { beginAccountSignup , finalizeAccountSignup } from "hooks/account" ;
53
47
import base64url from "base64url" ;
54
- import { CartridgeAccount } from "@cartridge/account-wasm" ;
48
+ import {
49
+ CartridgeAccount ,
50
+ CartridgeSessionAccount ,
51
+ } from "@cartridge/account-wasm" ;
55
52
56
53
enum SignupState {
57
54
CONNECT ,
@@ -109,13 +106,11 @@ export function SignupArgent({ username }: { username: string }) {
109
106
function SignupArgentInner ( { username } : { username : string } ) {
110
107
const { account : extAccount } = useAccount ( ) ;
111
108
const { connectAsync, connectors, isPending : isConnecting } = useConnect ( ) ;
112
- const { chainId, chainName, policies } = useConnection ( ) ;
109
+ const { chainId, chainName, policies, rpcUrl } = useConnection ( ) ;
113
110
const { isChecked, tokens, isFetching, isAllFunded } = useTokens ( ) ;
114
111
const [ isDeploying , setIsDeploying ] = useState ( false ) ;
115
112
const [ error , setError ] = useState < Error > ( ) ;
116
113
const [ state , setState ] = useState < SignupState > ( SignupState . CONNECT ) ;
117
- const [ controllerAddress , setControllerAddress ] = useState ( "" ) ;
118
- const [ controllerCalldata , setControllerCalldata ] = useState ( [ ] ) ;
119
114
120
115
const [ title , setTitle ] = useState ( "" ) ;
121
116
@@ -152,17 +147,6 @@ function SignupArgentInner({ username }: { username: string }) {
152
147
const typedData = registerTypedData ( username , { low, high } , chainId ) ;
153
148
const sig = await extAccount . signMessage ( typedData ) ;
154
149
await finalizeAccountSignup ( extAccount . address , chainId , sig as string [ ] ) ;
155
-
156
- // set controller address & calldata
157
- const salt = shortString . encodeShortString ( username ) ;
158
- const { address, calldata } = CartridgeAccount . getUdcDeployedAddress (
159
- salt ,
160
- extAccount . address ,
161
- ) ;
162
-
163
- setControllerAddress ( address ) ;
164
- setControllerCalldata ( calldata ) ;
165
-
166
150
setState ( SignupState . DEPLOY ) ;
167
151
} catch ( e ) {
168
152
console . log ( e ) ;
@@ -173,83 +157,59 @@ function SignupArgentInner({ username }: { username: string }) {
173
157
const onDeploy = useCallback ( async ( ) => {
174
158
if ( ! extAccount ) return ;
175
159
176
- const calls = tokens . flatMap ( ( t ) => {
177
- const amount = cairo . uint256 ( t . min ) ;
178
- return [
179
- {
180
- contractAddress : t . address ,
181
- entrypoint : "approve" ,
182
- calldata : CallData . compile ( {
183
- recipient : controllerAddress ,
184
- amount,
185
- } ) ,
186
- } ,
187
- {
188
- contractAddress : t . address ,
189
- entrypoint : "transfer" ,
190
- calldata : CallData . compile ( {
191
- recipient : controllerAddress ,
192
- amount,
193
- } ) ,
194
- } ,
195
- ] ;
196
- } ) ;
197
-
198
- // deployContract
199
- const salt = shortString . encodeShortString ( username ) ;
200
- calls . push ( {
201
- contractAddress : CartridgeAccount . getUdcAddress ( ) ,
202
- entrypoint : "deployContract" ,
203
- calldata : CallData . compile ( {
204
- classHash : CartridgeAccount . getAccountClassHash ( ) ,
205
- salt,
206
- unique : false ,
207
- calldata : controllerCalldata ,
208
- } ) ,
209
- } ) ;
210
-
211
- // registerSession
212
- calls . push ( {
213
- contractAddress : controllerAddress ,
214
- entrypoint : "register_session" ,
215
- calldata : CartridgeAccount . registerSessionCalldata (
160
+ try {
161
+ setIsDeploying ( true ) ;
162
+
163
+ const {
164
+ address : controllerAddress ,
165
+ calls : deploymentCalls ,
166
+ sessionKey,
167
+ } = CartridgeAccount . externalDeploymentCalls (
168
+ extAccount . address ,
169
+ shortString . encodeShortString ( username ) ,
170
+ 100000000000000000n ,
216
171
policies . map ( ( p ) => {
217
172
return { target : p . target , method : p . method } ;
218
173
} ) ,
219
174
3000000000n ,
220
- extAccount . address ,
221
- ) ,
222
- } ) ;
223
-
224
- console . log (
225
- calls
226
- . map ( ( call ) => {
227
- return CallData . compile ( call )
228
- . map ( ( i ) => `0x${ BigInt ( i ) . toString ( 16 ) } ` )
229
- . join ( " " ) ;
230
- } )
231
- . join ( " / " ) ,
232
- ) ;
175
+ ) ;
233
176
234
- try {
235
- setIsDeploying ( true ) ;
236
- const res = await extAccount . execute ( calls ) ;
177
+ const res = await extAccount . execute ( deploymentCalls ) ;
237
178
await extAccount . waitForTransaction ( res . transaction_hash , {
238
179
retryInterval : 1000 ,
239
180
} ) ;
181
+
182
+ // Test session account
183
+ const sessionAccount = CartridgeSessionAccount . new_as_registered (
184
+ rpcUrl ,
185
+ sessionKey ,
186
+ controllerAddress ,
187
+ extAccount . address ,
188
+ chainId ,
189
+ {
190
+ policies : policies . map ( ( p ) => {
191
+ return { target : p . target , method : p . method } ;
192
+ } ) ,
193
+ expiresAt : 3000000000 ,
194
+ } ,
195
+ ) ;
196
+
197
+ const res2 = await sessionAccount . execute ( [
198
+ {
199
+ contractAddress : ETH_CONTRACT_ADDRESS ,
200
+ entrypoint : "transfer" ,
201
+ calldata : [ extAccount . address , "0x2386F26FC10000" , "0" ] ,
202
+ } ,
203
+ ] ) ;
204
+
205
+ console . log ( res2 ) ;
240
206
} catch ( e ) {
241
207
console . log ( e ) ;
242
208
setError ( e ) ;
209
+ } finally {
210
+ setIsDeploying ( false ) ;
243
211
}
244
- setIsDeploying ( false ) ;
245
- } , [
246
- extAccount ,
247
- controllerAddress ,
248
- controllerCalldata ,
249
- policies ,
250
- tokens ,
251
- username ,
252
- ] ) ;
212
+ } , [ extAccount , policies , tokens , username ] ) ;
253
213
254
214
// const onCopy = useCallback(() => {
255
215
// navigator.clipboard.writeText(controllerAddress);
@@ -283,9 +243,7 @@ function SignupArgentInner({ username }: { username: string }) {
283
243
"Please connect your ArgentX wallet" }
284
244
{ state === SignupState . SIGN_MESSAGE &&
285
245
"Sign message to create your controller" }
286
- { state === SignupState . DEPLOY && (
287
- < CopyAddress address = { controllerAddress } />
288
- ) }
246
+ { state === SignupState . DEPLOY && < > </ > }
289
247
</ >
290
248
}
291
249
// TODO: Add line icons
@@ -407,7 +365,6 @@ function SignupArgentInner({ username }: { username: string }) {
407
365
< Button
408
366
colorScheme = "colorful"
409
367
onClick = { ( ) => {
410
- console . log ( "deploy" ) ;
411
368
onDeploy ( ) ;
412
369
} }
413
370
isLoading = { isDeploying }
0 commit comments