1- import assert from 'minimalistic-assert' ;
2-
31import { ZERO } from '../constants' ;
4- import { Provider , ProviderOptions } from '../provider' ;
2+ import { ProviderOptions } from '../provider' ;
3+ import { Provider } from '../provider/default' ;
54import { Signer , SignerInterface } from '../signer' ;
65import {
76 Abi ,
8- AddTransactionResponse ,
97 Call ,
108 InvocationsDetails ,
119 InvocationsSignerDetails ,
12- InvokeFunctionTransaction ,
10+ InvokeFunctionResponse ,
1311 KeyPair ,
1412 Signature ,
15- Transaction ,
1613} from '../types' ;
1714import { EstimateFee , EstimateFeeDetails } from '../types/account' ;
18- import { sign } from '../utils/ellipticCurve' ;
19- import {
20- computeHashOnElements ,
21- feeTransactionVersion ,
22- getSelectorFromName ,
23- transactionVersion ,
24- } from '../utils/hash' ;
25- import { BigNumberish , bigNumberishArrayToDecimalStringArray , toBN , toHex } from '../utils/number' ;
26- import { encodeShortString } from '../utils/shortString' ;
15+ import { feeTransactionVersion , transactionVersion } from '../utils/hash' ;
16+ import { BigNumberish , toBN , toHex } from '../utils/number' ;
2717import { compileCalldata , estimatedFeeToMaxFee } from '../utils/stark' ;
2818import { fromCallsToExecuteCalldataWithNonce } from '../utils/transaction' ;
2919import { TypedData , getMessageHash } from '../utils/typedData' ;
@@ -48,7 +38,8 @@ export class Account extends Provider implements AccountInterface {
4838 public async getNonce ( ) : Promise < string > {
4939 const { result } = await this . callContract ( {
5040 contractAddress : this . address ,
51- entrypoint : 'get_nonce' ,
41+ entryPointSelector : 'get_nonce' ,
42+ calldata : [ ] ,
5243 } ) ;
5344 return toHex ( toBN ( result [ 0 ] ) ) ;
5445 }
@@ -72,18 +63,12 @@ export class Account extends Provider implements AccountInterface {
7263 const signature = await this . signer . signTransaction ( transactions , signerDetails ) ;
7364
7465 const calldata = fromCallsToExecuteCalldataWithNonce ( transactions , nonce ) ;
75- const fetchedEstimate = await this . fetchEndpoint (
76- 'estimate_fee' ,
77- { blockIdentifier } ,
78- {
79- contract_address : this . address ,
80- entry_point_selector : getSelectorFromName ( '__execute__' ) ,
81- calldata,
82- version : toHex ( version ) ,
83- signature : bigNumberishArrayToDecimalStringArray ( signature ) ,
84- }
66+ const fetchedEstimate = await super . getEstimateFee (
67+ { contractAddress : this . address , entryPointSelector : '__execute__' , calldata, signature } ,
68+ blockIdentifier
8569 ) ;
86- const suggestedMaxFee = estimatedFeeToMaxFee ( fetchedEstimate . amount ) ;
70+
71+ const suggestedMaxFee = estimatedFeeToMaxFee ( fetchedEstimate . overallFee ) ;
8772
8873 return {
8974 ...fetchedEstimate ,
@@ -105,7 +90,7 @@ export class Account extends Provider implements AccountInterface {
10590 calls : Call | Call [ ] ,
10691 abis : Abi [ ] | undefined = undefined ,
10792 transactionsDetail : InvocationsDetails = { }
108- ) : Promise < AddTransactionResponse > {
93+ ) : Promise < InvokeFunctionResponse > {
10994 const transactions = Array . isArray ( calls ) ? calls : [ calls ] ;
11095 const nonce = toBN ( transactionsDetail . nonce ?? ( await this . getNonce ( ) ) ) ;
11196 let maxFee : BigNumberish = '0' ;
@@ -116,124 +101,27 @@ export class Account extends Provider implements AccountInterface {
116101 maxFee = suggestedMaxFee . toString ( ) ;
117102 }
118103
104+ const version = toBN ( transactionVersion ) ;
105+
119106 const signerDetails : InvocationsSignerDetails = {
120107 walletAddress : this . address ,
121108 nonce,
122109 maxFee,
123- version : toBN ( transactionVersion ) ,
110+ version,
124111 chainId : this . chainId ,
125112 } ;
126113
127114 const signature = await this . signer . signTransaction ( transactions , signerDetails , abis ) ;
128115
129116 const calldata = fromCallsToExecuteCalldataWithNonce ( transactions , nonce ) ;
130- return this . fetchEndpoint ( 'add_transaction' , undefined , {
131- type : 'INVOKE_FUNCTION' ,
132- contract_address : this . address ,
133- entry_point_selector : getSelectorFromName ( '__execute__' ) ,
134- calldata,
135- signature : bigNumberishArrayToDecimalStringArray ( signature ) ,
136- max_fee : toHex ( toBN ( maxFee ) ) ,
137- } ) ;
138- }
139117
140- /**
141- * Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
142- * @deprecated to remove ASAP
143- */
144- public async LEGACY_addTransaction ( transaction : Transaction ) : Promise < AddTransactionResponse > {
145- if ( transaction . type === 'DEPLOY' ) throw new Error ( 'No DEPLOYS' ) ;
146- if ( transaction . type === 'DECLARE' ) throw new Error ( 'No DECLARES' ) ;
147-
148- assert (
149- ! transaction . signature ,
150- "Adding signatures to a signer transaction currently isn't supported"
151- ) ;
152-
153- let nonceBn ;
154- if ( transaction . nonce ) {
155- nonceBn = toBN ( transaction . nonce ) ;
156- } else {
157- const { result } = await this . callContract ( {
158- contractAddress : this . address ,
159- entrypoint : 'get_nonce' ,
160- } ) ;
161- nonceBn = toBN ( result [ 0 ] ) ;
162- }
163-
164- function hashMulticall (
165- account : string ,
166- transactions : InvokeFunctionTransaction [ ] ,
167- nonce : string ,
168- maxFee : string
169- ) {
170- const hashArray = transactions
171- . map ( ( { contract_address, entry_point_selector, calldata } ) => [
172- contract_address ,
173- entry_point_selector ,
174- computeHashOnElements ( calldata || [ ] ) ,
175- ] )
176- . map ( bigNumberishArrayToDecimalStringArray )
177- . map ( computeHashOnElements ) ;
178-
179- return computeHashOnElements ( [
180- encodeShortString ( 'StarkNet Transaction' ) ,
181- account ,
182- computeHashOnElements ( hashArray ) ,
183- nonce ,
118+ return this . invokeFunction (
119+ { contractAddress : this . address , entrypoint : '__execute__' , calldata, signature } ,
120+ {
184121 maxFee,
185- transactionVersion ,
186- ] ) ;
187- }
188- const msgHash = hashMulticall ( this . address , [ transaction ] , nonceBn . toString ( ) , '0' ) ;
189- if ( ! ( 'keyPair' in this . signer ) ) {
190- throw new Error ( 'No keyPair' ) ;
191- }
192- const signature = sign ( ( this . signer as any ) . keyPair , msgHash ) ;
193-
194- const transformCallsToMulticallArrays = ( calls : InvokeFunctionTransaction [ ] ) => {
195- const callArray : any [ ] = [ ] ;
196- const calldata : BigNumberish [ ] = [ ] ;
197- calls . forEach ( ( call ) => {
198- const data = call . calldata || [ ] ;
199- callArray . push ( {
200- to : toBN ( call . contract_address ) . toString ( 10 ) ,
201- selector : toBN ( call . entry_point_selector ) . toString ( 10 ) ,
202- data_offset : calldata . length . toString ( ) ,
203- data_len : data . length . toString ( ) ,
204- } ) ;
205- calldata . push ( ...data ) ;
206- } ) ;
207- return {
208- callArray,
209- calldata : bigNumberishArrayToDecimalStringArray ( calldata ) ,
210- } ;
211- } ;
212-
213- const fromCallsToExecuteCalldata2 = ( calls : InvokeFunctionTransaction [ ] ) : string [ ] => {
214- const { callArray, calldata } = transformCallsToMulticallArrays ( calls ) ;
215- return [
216- callArray . length . toString ( ) ,
217- ...callArray
218- . map (
219- ( { to, selector, data_offset, data_len } ) =>
220- [ to , selector , data_offset , data_len ] as string [ ]
221- )
222- . flat ( ) ,
223- calldata . length . toString ( ) ,
224- ...calldata ,
225- ] ;
226- } ;
227-
228- const calldata = [ ...fromCallsToExecuteCalldata2 ( [ transaction ] ) , nonceBn . toString ( ) ] ;
229-
230- return this . fetchEndpoint ( 'add_transaction' , undefined , {
231- type : 'INVOKE_FUNCTION' ,
232- contract_address : this . address ,
233- entry_point_selector : getSelectorFromName ( '__execute__' ) ,
234- calldata,
235- signature : bigNumberishArrayToDecimalStringArray ( signature ) ,
236- } ) ;
122+ version,
123+ }
124+ ) ;
237125 }
238126
239127 /**
@@ -271,7 +159,7 @@ export class Account extends Provider implements AccountInterface {
271159 try {
272160 await this . callContract ( {
273161 contractAddress : this . address ,
274- entrypoint : 'is_valid_signature' ,
162+ entryPointSelector : 'is_valid_signature' ,
275163 calldata : compileCalldata ( {
276164 hash : toBN ( hash ) . toString ( ) ,
277165 signature : signature . map ( ( x ) => toBN ( x ) . toString ( ) ) ,
0 commit comments