Skip to content

Commit

Permalink
feat: remove old version constants, default types api rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Dec 5, 2023
1 parent b410a6c commit ed9cb08
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 58 deletions.
2 changes: 1 addition & 1 deletion __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('deploy and test Wallet', () => {

expect(result).toMatchSchemaRef('EstimateFee');
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(
constants.BN_FEE_TRANSACTION_VERSION_1
BigInt(constants.TRANSACTION_VERSION.F1)
);
innerInvokeEstFeeSpy.mockClear();
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/ellipticalCurve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('hashMessage()', () => {

const hashMsg = calculateTransactionHash(
account,
constants.BN_TRANSACTION_VERSION_1,
BigInt(constants.TRANSACTION_VERSION.V1),
calldata,
maxFee,
StarknetChainId.SN_GOERLI,
Expand Down
2 changes: 1 addition & 1 deletion src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
ETransactionVersion,
ETransactionVersion2,
ETransactionVersion3,
} from '../types/api/rpc';
} from '../types/api';
import { CallData } from '../utils/calldata';
import { extractContractHashes, isSierra } from '../utils/contract';
import { starkCurve } from '../utils/ec';
Expand Down
23 changes: 9 additions & 14 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
HEX_STR_TRANSACTION_VERSION_1,
HEX_STR_TRANSACTION_VERSION_2,
HEX_STR_TRANSACTION_VERSION_3,
NetworkName,
StarknetChainId,
} from '../constants';
import { NetworkName, StarknetChainId } from '../constants';
import { LibraryError } from '../provider/errors';
import {
AccountInvocationItem,
Expand All @@ -24,6 +18,7 @@ import {
getSimulateTransactionOptions,
waitForTransactionOptions,
} from '../types';
import { ETransactionVersion } from '../types/api';
import { CallData } from '../utils/calldata';
import { isSierra } from '../utils/contract';
import fetch from '../utils/fetchPonyfill';
Expand Down Expand Up @@ -401,7 +396,7 @@ export class RpcChannel {
calldata: CallData.toHex(functionInvocation.calldata),
type: RPC.ETransactionType.INVOKE,
max_fee: toHex(details.maxFee || 0),
version: HEX_STR_TRANSACTION_VERSION_1,
version: ETransactionVersion.V1,
signature: signatureToHexArray(functionInvocation.signature),
nonce: toHex(details.nonce),
},
Expand All @@ -413,7 +408,7 @@ export class RpcChannel {
type: RPC.ETransactionType.INVOKE,
sender_address: functionInvocation.contractAddress,
calldata: CallData.toHex(functionInvocation.calldata),
version: HEX_STR_TRANSACTION_VERSION_3,
version: ETransactionVersion.V3,
signature: signatureToHexArray(functionInvocation.signature),
nonce: toHex(details.nonce),
resource_bounds: details.resourceBounds,
Expand Down Expand Up @@ -444,7 +439,7 @@ export class RpcChannel {
entry_points_by_type: contract.entry_points_by_type,
abi: contract.abi,
},
version: HEX_STR_TRANSACTION_VERSION_1,
version: ETransactionVersion.V1,
max_fee: toHex(details.maxFee || 0),
signature: signatureToHexArray(signature),
sender_address: senderAddress,
Expand All @@ -463,7 +458,7 @@ export class RpcChannel {
abi: contract.abi,
},
compiled_class_hash: compiledClassHash || '',
version: HEX_STR_TRANSACTION_VERSION_2,
version: ETransactionVersion.V2,
max_fee: toHex(details.maxFee || 0),
signature: signatureToHexArray(signature),
sender_address: senderAddress,
Expand All @@ -477,7 +472,7 @@ export class RpcChannel {
type: RPC.ETransactionType.DECLARE,
sender_address: senderAddress,
compiled_class_hash: compiledClassHash || '',
version: HEX_STR_TRANSACTION_VERSION_3,
version: ETransactionVersion.V3,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
contract_class: {
Expand Down Expand Up @@ -515,7 +510,7 @@ export class RpcChannel {
contract_address_salt: toHex(addressSalt || 0),
type: RPC.ETransactionType.DEPLOY_ACCOUNT,
max_fee: toHex(details.maxFee || 0),
version: HEX_STR_TRANSACTION_VERSION_1,
version: ETransactionVersion.V1,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
},
Expand All @@ -525,7 +520,7 @@ export class RpcChannel {
promise = this.fetchEndpoint('starknet_addDeployAccountTransaction', {
deploy_account_transaction: {
type: RPC.ETransactionType.DEPLOY_ACCOUNT,
version: HEX_STR_TRANSACTION_VERSION_3,
version: ETransactionVersion.V3,
signature: signatureToHexArray(signature),
nonce: toHex(details.nonce),
contract_address_salt: toHex(addressSalt || 0),
Expand Down
17 changes: 8 additions & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { ETransactionVersion } from './types/api';

export { IS_BROWSER } from './utils/encode';

/**
* Cairo Felt support storing max 31 character
*/
export const TEXT_TO_FELT_MAX_LEN = 31;

export const HEX_STR_TRANSACTION_VERSION_1 = '0x1';
export const HEX_STR_TRANSACTION_VERSION_2 = '0x2';
export const HEX_STR_TRANSACTION_VERSION_3 = '0x3';
export const BN_TRANSACTION_VERSION_1 = 1n;
export const BN_TRANSACTION_VERSION_2 = 2n;
export const BN_TRANSACTION_VERSION_3 = 3n;
export const BN_FEE_TRANSACTION_VERSION_1 = 2n ** 128n + BN_TRANSACTION_VERSION_1;
export const BN_FEE_TRANSACTION_VERSION_2 = 2n ** 128n + BN_TRANSACTION_VERSION_2;
export const BN_FEE_TRANSACTION_VERSION_3 = 2n ** 128n + BN_TRANSACTION_VERSION_3;
/**
* Alternatively use directly from api specification
* types.RPC.ETransactionVersion
* For BN do BigInt(TRANSACTION_VERSION.*)
*/
export { ETransactionVersion as TRANSACTION_VERSION };

export const ZERO = 0n;
export const MASK_250 = 2n ** 250n - 1n; // 2 ** 250 - 1
Expand Down
2 changes: 1 addition & 1 deletion src/signer/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
V3DeployAccountSignerDetails,
V3InvocationsSignerDetails,
} from '../types';
import { ETransactionVersion2, ETransactionVersion3 } from '../types/api/rpc';
import { ETransactionVersion2, ETransactionVersion3 } from '../types/api';
import { CallData } from '../utils/calldata';
import { starkCurve } from '../utils/ec';
import { buf2hex } from '../utils/encode';
Expand Down
2 changes: 1 addition & 1 deletion src/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ETransactionVersion } from './api/rpc';
import { ETransactionVersion } from './api';
import { BigNumberish, BlockIdentifier, V3TransactionDetails } from './lib';
import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider';

Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions src/types/api/rpcspec_0_6/nonspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export enum EDAMode {
L2,
}

/**
* V_ Transaction versions HexString
* F_ Fee Transaction Versions HexString (2 ** 128 + TRANSACTION_VERSION)
*/
export enum ETransactionVersion {
V0 = '0x0',
V1 = '0x1',
Expand All @@ -153,6 +157,9 @@ export enum ETransactionVersion {
F3 = '0x100000000000000000000000000000003',
}

/**
* Old Transaction Versions
*/
export enum ETransactionVersion2 {
V0 = '0x0',
V1 = '0x1',
Expand All @@ -162,6 +169,9 @@ export enum ETransactionVersion2 {
F2 = '0x100000000000000000000000000000002',
}

/**
* V3 Transaction Versions
*/
export enum ETransactionVersion3 {
V3 = '0x3',
F3 = '0x100000000000000000000000000000003',
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * from './signer';
export * from './typedData';
export * from './cairoEnum';

export * as RPC from './api/rpc';
export * as RPC from './api';
export {
CallL1Handler,
DeployedContractItem,
Expand Down
2 changes: 1 addition & 1 deletion src/types/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StarknetChainId } from '../../constants';
import { weierstrass } from '../../utils/ec';
import { EDataAvailabilityMode, ResourceBounds } from '../api/rpc';
import { EDataAvailabilityMode, ResourceBounds } from '../api';
import { CairoEnum } from '../cairoEnum';
import { CompiledContract, CompiledSierraCasm, ContractClass } from './contract';

Expand Down
2 changes: 1 addition & 1 deletion src/types/provider/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Intersection (sequencer response ∩ (∪ rpc responses))
*/

import * as RPC from '../api/rpc';
import * as RPC from '../api';
import * as Sequencer from '../api/sequencer';
import {
AllowArray,
Expand Down
2 changes: 1 addition & 1 deletion src/types/signer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StarknetChainId } from '../constants';
import { ETransactionVersion, ETransactionVersion2, ETransactionVersion3 } from './api/rpc';
import { ETransactionVersion, ETransactionVersion2, ETransactionVersion3 } from './api';
import {
BigNumberish,
CairoVersion,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hash/transactionHash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ETransactionVersion2,
ETransactionVersion3,
ResourceBounds,
} from '../../../types/api/rpc';
} from '../../../types/api';
import {
calculateDeclareTransactionHash as v2calculateDeclareTransactionHash,
calculateDeployAccountTransactionHash as v2calculateDeployAccountTransactionHash,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hash/transactionHash/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { poseidonHashMany } from '@scure/starknet';

import { StarknetChainId, TransactionHashPrefix } from '../../../constants';
import { BigNumberish, Calldata } from '../../../types';
import { EDAMode, ResourceBounds } from '../../../types/api/rpc';
import { EDAMode, ResourceBounds } from '../../../types/api';
import { toHex } from '../../num';
import { encodeShortString } from '../../shortString';

Expand Down
15 changes: 4 additions & 11 deletions src/utils/provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
BN_FEE_TRANSACTION_VERSION_3,
HEX_STR_TRANSACTION_VERSION_3,
NetworkName,
RPC_GOERLI_NODES,
RPC_MAINNET_NODES,
} from '../constants';
import { NetworkName, RPC_GOERLI_NODES, RPC_MAINNET_NODES } from '../constants';
import {
BigNumberish,
BlockIdentifier,
Expand All @@ -20,6 +14,7 @@ import {
SierraContractClass,
V3TransactionDetails,
} from '../types';
import { ETransactionVersion } from '../types/api';
import { isSierra } from './contract';
import { formatSpaces } from './hash';
import { parse, stringify } from './json';
Expand Down Expand Up @@ -187,8 +182,6 @@ export function defStateUpdate(
}

export function isV3Tx(details: InvocationsDetailsWithNonce): details is V3TransactionDetails {
const version = details.version ? toHex(details.version) : HEX_STR_TRANSACTION_VERSION_3;
return (
version === HEX_STR_TRANSACTION_VERSION_3 || version === toHex(BN_FEE_TRANSACTION_VERSION_3)
);
const version = details.version ? toHex(details.version) : ETransactionVersion.V3;
return version === ETransactionVersion.V3 || version === ETransactionVersion.F3;
}
2 changes: 1 addition & 1 deletion src/utils/stark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Program,
Signature,
} from '../types';
import { EDAMode, EDataAvailabilityMode, ResourceBounds } from '../types/api/rpc';
import { EDAMode, EDataAvailabilityMode, ResourceBounds } from '../types/api';
import { addHexPrefix, arrayBufferToString, atobUniversal, btoaUniversal } from './encode';
import { parse, stringify } from './json';
import {
Expand Down
17 changes: 5 additions & 12 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import {
BN_FEE_TRANSACTION_VERSION_1,
BN_FEE_TRANSACTION_VERSION_2,
BN_FEE_TRANSACTION_VERSION_3,
BN_TRANSACTION_VERSION_1,
BN_TRANSACTION_VERSION_2,
BN_TRANSACTION_VERSION_3,
} from '../constants';
import {
BigNumberish,
CairoVersion,
Expand All @@ -15,6 +7,7 @@ import {
ParsedStruct,
RawArgs,
} from '../types';
import { ETransactionVersion } from '../types/api';
import { CallData } from './calldata';
import { getSelectorFromName } from './hash';
import { toBigInt } from './num';
Expand Down Expand Up @@ -107,9 +100,9 @@ export const getExecuteCalldata = (calls: Call[], cairoVersion: CairoVersion = '
export function getVersionsByType(versionType?: 'fee' | 'transaction') {
return versionType === 'fee'
? {
v1: BN_FEE_TRANSACTION_VERSION_1,
v2: BN_FEE_TRANSACTION_VERSION_2,
v3: BN_FEE_TRANSACTION_VERSION_3,
v1: ETransactionVersion.F1,
v2: ETransactionVersion.F2,
v3: ETransactionVersion.F3,
}
: { v1: BN_TRANSACTION_VERSION_1, v2: BN_TRANSACTION_VERSION_2, v3: BN_TRANSACTION_VERSION_3 };
: { v1: ETransactionVersion.V1, v2: ETransactionVersion.V2, v3: ETransactionVersion.V3 };
}

0 comments on commit ed9cb08

Please sign in to comment.