Skip to content

Commit

Permalink
chore: implement companion pattern approach (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Luka Saric <[email protected]>
  • Loading branch information
lukasaric and Luka Saric authored Jun 4, 2024
1 parent 0f8b7c8 commit f78f0d4
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 72 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,7 @@
"rules": {
"class-methods-use-this": 0,
"import/prefer-default-export": 0,
"@typescript-eslint/no-redeclare": 0,
"@typescript-eslint/naming-convention": 0,
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 89 additions & 63 deletions src/api/nonspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,83 111,109 @@ export type NonceUpdates = NONCE_UPDATE[];
export type ReplacedClasses = REPLACED_CLASS[];

// Enums Derived From Spec Types (require manual check for changes)
export enum ETransactionType {
DECLARE = 'DECLARE',
DEPLOY = 'DEPLOY',
DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
INVOKE = 'INVOKE',
L1_HANDLER = 'L1_HANDLER',
}

export enum ESimulationFlag {
SKIP_VALIDATE = 'SKIP_VALIDATE',
SKIP_FEE_CHARGE = 'SKIP_FEE_CHARGE',
}

export enum ETransactionStatus {
RECEIVED = 'RECEIVED',
REJECTED = 'REJECTED',
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
}

export enum ETransactionFinalityStatus {
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
}
export enum ETransactionExecutionStatus {
SUCCEEDED = 'SUCCEEDED',
REVERTED = 'REVERTED',
}

export enum EBlockTag {
LATEST = 'latest',
PENDING = 'pending',
}
export const ETransactionType = {
DECLARE: 'DECLARE',
DEPLOY: 'DEPLOY',
DEPLOY_ACCOUNT: 'DEPLOY_ACCOUNT',
INVOKE: 'INVOKE_FUNCTION',
L1_HANDLER: 'L1_HANDLER',
} as const;

export type ETransactionType = (typeof ETransactionType)[keyof typeof ETransactionType];

export const ESimulationFlag = {
SKIP_VALIDATE: 'SKIP_VALIDATE',
SKIP_FEE_CHARGE: 'SKIP_FEE_CHARGE',
} as const;

export type ETransactionFlag = (typeof ESimulationFlag)[keyof typeof ESimulationFlag];

export const ETransactionStatus = {
RECEIVED: 'RECEIVED',
REJECTED: 'REJECTED',
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
} as const;

export type ETransactionStatus = (typeof ETransactionStatus)[keyof typeof ETransactionStatus];

export const ETransactionFinalityStatus = {
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
} as const;

export type ETransactionFinalityStatus =
(typeof ETransactionFinalityStatus)[keyof typeof ETransactionFinalityStatus];

export const ETransactionExecutionStatus = {
SUCCEEDED: 'SUCCEEDED',
REVERTED: 'REVERTED',
} as const;

export type ETransactionExecutionStatus =
(typeof ETransactionExecutionStatus)[keyof typeof ETransactionExecutionStatus];

export const EBlockTag = {
LATEST: 'latest',
PENDING: 'pending',
} as const;

export type EBlockTag = (typeof EBlockTag)[keyof typeof EBlockTag];

// 'L1' | 'L2'
export enum EDataAvailabilityMode {
L1 = 'L1',
L2 = 'L2',
}
export const EDataAvailabilityMode = {
L1: 'L1',
L2: 'L2',
} as const;

export type EDataAvailabilityMode =
(typeof EDataAvailabilityMode)[keyof typeof EDataAvailabilityMode];

// 0 | 1
export enum EDAMode {
L1,
L2,
}
export const EDAMode = {
L1: 0,
L2: 1,
} as const;

export type EDAMode = (typeof EDAMode)[keyof typeof EDAMode];

/**
* V_ Transaction versions HexString
* F_ Fee Transaction Versions HexString (2 ** 128 TRANSACTION_VERSION)
*/
export enum ETransactionVersion {
V0 = '0x0',
V1 = '0x1',
V2 = '0x2',
V3 = '0x3',
F0 = '0x100000000000000000000000000000000',
F1 = '0x100000000000000000000000000000001',
F2 = '0x100000000000000000000000000000002',
F3 = '0x100000000000000000000000000000003',
}
export const ETransactionVersion = {
V0: '0x0',
V1: '0x1',
V2: '0x2',
V3: '0x3',
F0: '0x100000000000000000000000000000000',
F1: '0x100000000000000000000000000000001',
F2: '0x100000000000000000000000000000002',
F3: '0x100000000000000000000000000000003',
} as const;

export type ETransactionVersion = (typeof ETransactionVersion)[keyof typeof ETransactionVersion];
/**
* Old Transaction Versions
*/
export enum ETransactionVersion2 {
V0 = '0x0',
V1 = '0x1',
V2 = '0x2',
F0 = '0x100000000000000000000000000000000',
F1 = '0x100000000000000000000000000000001',
F2 = '0x100000000000000000000000000000002',
}

export const ETransactionVersion2 = {
V0: '0x0',
V1: '0x1',
V2: '0x2',
F0: '0x100000000000000000000000000000000',
F1: '0x100000000000000000000000000000001',
F2: '0x100000000000000000000000000000002',
} as const;
export type ETransactionVersion2 = (typeof ETransactionVersion2)[keyof typeof ETransactionVersion2];

/**
* V3 Transaction Versions
*/
export enum ETransactionVersion3 {
V3 = '0x3',
F3 = '0x100000000000000000000000000000003',
}

export const ETransactionVersion3 = {
V3: '0x3',
F3: '0x100000000000000000000000000000003',
} as const;

export type ETransactionVersion3 = (typeof ETransactionVersion3)[keyof typeof ETransactionVersion3];
8 changes: 5 additions & 3 deletions src/wallet-api/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 1,5 @@
export enum Permission {
Accounts = 'accounts',
}
export const Permission = {
ACCOUNTS: 'accounts',
} as const;

export type Permission = (typeof Permission)[keyof typeof Permission];
10 changes: 6 additions & 4 deletions src/wallet-api/typedData.ts
Original file line number Diff line number Diff line change
@@ -1,7 1,9 @@
export enum TypedDataRevision {
Active = '1',
Legacy = '0',
}
export const TypedDataRevision = {
ACTIVE: '1',
LEGACY: '0',
} as const;

export type TypedDataRevision = (typeof TypedDataRevision)[keyof typeof TypedDataRevision];

export type StarknetEnumType = {
name: string;
Expand Down

0 comments on commit f78f0d4

Please sign in to comment.