Skip to content

Commit c2607ed

Browse files
committed
feat: rpc 0.6.0-rc3 implementation
1 parent a596748 commit c2607ed

File tree

8 files changed

+68
-27
lines changed

8 files changed

+68
-27
lines changed

src/channel/rpc_0_6.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ import { getHexStringArray, toHex, toStorageKey } from '../utils/num';
3333
import { Block, getDefaultNodeUrl, isV3Tx, wait } from '../utils/provider';
3434
import { decompressProgram, signatureToHexArray } from '../utils/stark';
3535

36+
/* function detailsToV3DefaultDetails(details: InvocationsDetailsWithNonce) {
37+
if (!isV3Tx(details)) throw Error('detailsToV3Details: Transaction is not V3');
38+
39+
return {
40+
...details,
41+
resource_bounds: details.resourceBounds,
42+
tip: toHex(details.tip || 0),
43+
paymaster_data: details.paymasterData ? details.paymasterData.map((it) => toHex(it)) : [],
44+
account_deployment_data: details.accountDeploymentData
45+
? details.accountDeploymentData.map((it) => toHex(it))
46+
: [],
47+
nonce_data_availability_mode: details.nonceDataAvailabilityMode || 'L1',
48+
fee_data_availability_mode: details.feeDataAvailabilityMode || 'L1',
49+
};
50+
} */
51+
3652
const defaultOptions = {
3753
headers: { 'Content-Type': 'application/json' },
3854
blockIdentifier: BlockTag.pending,
@@ -364,12 +380,13 @@ export class RpcChannel {
364380

365381
public getEstimateFee(
366382
invocations: AccountInvocations,
367-
{ blockIdentifier = this.blockIdentifier }: getEstimateFeeBulkOptions
383+
{ blockIdentifier = this.blockIdentifier, skipValidate = false }: getEstimateFeeBulkOptions
368384
) {
369385
const block_id = new Block(blockIdentifier).identifier;
370386
return this.fetchEndpoint('starknet_estimateFee', {
371387
request: invocations.map((it) => this.buildTransaction(it, 'fee')),
372388
block_id,
389+
...(skipValidate && { simulation_flags: [RPC.V0_6.ESimulationFlag.SKIP_VALIDATE] }),
373390
});
374391
}
375392

src/provider/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ export abstract class ProviderInterface {
215215
public abstract getEstimateFee(
216216
invocation: Invocation,
217217
details: InvocationsDetailsWithNonce,
218-
blockIdentifier: BlockIdentifier
218+
blockIdentifier?: BlockIdentifier,
219+
skipValidate?: boolean
219220
): Promise<EstimateFeeResponse>;
220221

221222
/**

src/provider/rpc.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,17 @@ export class RpcProvider implements ProviderInterface {
239239
public async getEstimateFee(
240240
invocation: Invocation,
241241
invocationDetails: InvocationsDetailsWithNonce,
242-
blockIdentifier?: BlockIdentifier
242+
blockIdentifier?: BlockIdentifier,
243+
skipValidate?: boolean
243244
) {
244-
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
245+
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
245246
}
246247

247248
public async getInvokeEstimateFee(
248249
invocation: Invocation,
249250
invocationDetails: InvocationsDetailsWithNonce,
250-
blockIdentifier?: BlockIdentifier
251+
blockIdentifier?: BlockIdentifier,
252+
skipValidate?: boolean
251253
) {
252254
return this.channel
253255
.getEstimateFee(
@@ -258,15 +260,16 @@ export class RpcProvider implements ProviderInterface {
258260
...invocationDetails,
259261
},
260262
],
261-
{ blockIdentifier }
263+
{ blockIdentifier, skipValidate }
262264
)
263265
.then(this.responseParser.parseFeeEstimateResponse);
264266
}
265267

266268
public async getDeclareEstimateFee(
267269
invocation: DeclareContractTransaction,
268270
details: InvocationsDetailsWithNonce,
269-
blockIdentifier?: BlockIdentifier
271+
blockIdentifier?: BlockIdentifier,
272+
skipValidate?: boolean
270273
) {
271274
return this.channel
272275
.getEstimateFee(
@@ -277,15 +280,16 @@ export class RpcProvider implements ProviderInterface {
277280
...details,
278281
},
279282
],
280-
{ blockIdentifier }
283+
{ blockIdentifier, skipValidate }
281284
)
282285
.then(this.responseParser.parseFeeEstimateResponse);
283286
}
284287

285288
public async getDeployAccountEstimateFee(
286289
invocation: DeployAccountContractTransaction,
287290
details: InvocationsDetailsWithNonce,
288-
blockIdentifier?: BlockIdentifier
291+
blockIdentifier?: BlockIdentifier,
292+
skipValidate?: boolean
289293
) {
290294
return this.channel
291295
.getEstimateFee(
@@ -296,7 +300,7 @@ export class RpcProvider implements ProviderInterface {
296300
...details,
297301
},
298302
],
299-
{ blockIdentifier }
303+
{ blockIdentifier, skipValidate }
300304
)
301305
.then(this.responseParser.parseFeeEstimateResponse);
302306
}

src/types/api/rpcspec_0_6/components.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,19 @@ export type TYPED_PARAMETER = {
554554
type: string;
555555
};
556556

557+
export type SIMULATION_FLAG_FOR_ESTIMATE_FEE = 'SKIP_VALIDATE';
558+
export type PRICE_UNIT = 'WEI' | 'FRI';
559+
557560
export type FEE_ESTIMATE = {
558561
gas_consumed: FELT;
559562
gas_price: FELT;
560563
overall_fee: FELT;
564+
unit: PRICE_UNIT;
561565
};
562566

563567
export type FEE_PAYMENT = {
564568
amount: FELT;
565-
unit: 'WEI' | 'STRK';
569+
unit: PRICE_UNIT;
566570
};
567571

568572
export type RESOURCE_BOUNDS_MAPPING = {
@@ -576,7 +580,7 @@ export type RESOURCE_BOUNDS = {
576580
};
577581

578582
export type RESOURCE_PRICE = {
579-
price_in_strk?: FELT;
583+
price_in_fri: FELT;
580584
price_in_wei: FELT;
581585
};
582586

src/types/api/rpcspec_0_6/errors.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ export interface BLOCK_NOT_FOUND {
3131
message: 'Block not found';
3232
}
3333

34-
export interface INVALID_TXN_HASH {
35-
code: 25;
36-
message: 'Invalid transaction hash';
37-
}
38-
3934
export interface INVALID_BLOCK_HASH {
4035
code: 26;
4136
message: 'Invalid block hash';
@@ -84,6 +79,15 @@ export interface CONTRACT_ERROR {
8479
};
8580
}
8681

82+
export interface TRANSACTION_EXECUTION_ERROR {
83+
code: 41;
84+
message: 'Transaction execution error';
85+
data: {
86+
transaction_index: number;
87+
execution_error: string;
88+
};
89+
}
90+
8791
export interface CLASS_ALREADY_DECLARED {
8892
code: 51;
8993
message: 'Class already declared';

src/types/api/rpcspec_0_6/methods.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
PENDING_STATE_UPDATE,
1515
RESULT_PAGE_REQUEST,
1616
SIMULATION_FLAG,
17+
SIMULATION_FLAG_FOR_ESTIMATE_FEE,
1718
STATE_UPDATE,
1819
STORAGE_KEY,
1920
TXN_HASH,
@@ -176,10 +177,11 @@ type ReadMethods = {
176177
starknet_estimateFee: {
177178
params: {
178179
request: BROADCASTED_TXN[];
180+
simulation_flags?: [SIMULATION_FLAG_FOR_ESTIMATE_FEE];
179181
block_id: BLOCK_ID;
180182
};
181183
result: FeeEstimate[];
182-
errors: Errors.CONTRACT_NOT_FOUND | Errors.CONTRACT_ERROR | Errors.BLOCK_NOT_FOUND;
184+
errors: Errors.TRANSACTION_EXECUTION_ERROR | Errors.BLOCK_NOT_FOUND;
183185
};
184186

185187
// Estimate the L2 fee of a message sent on L1
@@ -306,7 +308,7 @@ type TraceMethods = {
306308
starknet_traceTransaction: {
307309
params: { transaction_hash: TXN_HASH };
308310
result: TransactionTrace;
309-
errors: Errors.INVALID_TXN_HASH | Errors.NO_TRACE_AVAILABLE;
311+
errors: Errors.TXN_HASH_NOT_FOUND | Errors.NO_TRACE_AVAILABLE;
310312
};
311313

312314
// Returns the execution traces of all transactions included in the given block
@@ -324,6 +326,6 @@ type TraceMethods = {
324326
simulation_flags: Array<SIMULATION_FLAG>;
325327
};
326328
result: SimulateTransactionResponse;
327-
errors: Errors.CONTRACT_NOT_FOUND | Errors.CONTRACT_ERROR | Errors.BLOCK_NOT_FOUND;
329+
errors: Errors.BLOCK_NOT_FOUND | Errors.TRANSACTION_EXECUTION_ERROR;
328330
};
329331
};

src/types/lib/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export type InvocationsDetails = {
115115
version?: BigNumberish;
116116
};
117117

118-
export type V3InvocationDetails = {
118+
export type V3TransactionDetails = {
119119
nonce: BigNumberish;
120120
version: BigNumberish;
121121
resourceBounds: V0_6.SPEC.RESOURCE_BOUNDS_MAPPING;
@@ -140,7 +140,7 @@ export type InvocationsDetailsWithNonce =
140140
| (InvocationsDetails & {
141141
nonce: BigNumberish;
142142
})
143-
| V3InvocationDetails;
143+
| V3TransactionDetails;
144144

145145
export enum TransactionType {
146146
DECLARE = 'DECLARE',
@@ -252,6 +252,7 @@ export type getContractVersionOptions = {
252252

253253
export type getEstimateFeeBulkOptions = {
254254
blockIdentifier?: BlockIdentifier;
255+
skipValidate?: boolean;
255256
};
256257

257258
export interface CallStruct {

src/utils/provider.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { NetworkName, RPC_GOERLI_NODES, RPC_MAINNET_NODES } from '../constants';
1+
import {
2+
BN_FEE_TRANSACTION_VERSION_3,
3+
HEX_STR_TRANSACTION_VERSION_3,
4+
NetworkName,
5+
RPC_GOERLI_NODES,
6+
RPC_MAINNET_NODES,
7+
} from '../constants';
28
import {
39
BigNumberish,
410
BlockIdentifier,
@@ -12,7 +18,7 @@ import {
1218
RPC,
1319
SequencerIdentifier,
1420
SierraContractClass,
15-
V3InvocationDetails,
21+
V3TransactionDetails,
1622
} from '../types';
1723
import { isSierra } from './contract';
1824
import { formatSpaces } from './hash';
@@ -180,7 +186,9 @@ export function defStateUpdate(
180186
return pending(state);
181187
}
182188

183-
export function isV3Tx(details: InvocationsDetailsWithNonce): details is V3InvocationDetails {
184-
const version = details.version ? toHex(details.version) : '0x3';
185-
return version === '0x3' || version === '0x100000000000000000000000000000003';
189+
export function isV3Tx(details: InvocationsDetailsWithNonce): details is V3TransactionDetails {
190+
const version = details.version ? toHex(details.version) : HEX_STR_TRANSACTION_VERSION_3;
191+
return (
192+
version === HEX_STR_TRANSACTION_VERSION_3 || version === toHex(BN_FEE_TRANSACTION_VERSION_3)
193+
);
186194
}

0 commit comments

Comments
 (0)