Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions contract_manager/src/node/utils/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ import {
} from "../../core/contracts/starknet";
import { Token } from "../../core/token";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function parseJsonFile(jsonFile: string): any {
try {
return JSON.parse(readFileSync(jsonFile, "utf8"));
} catch (err) {
throw new Error(
`Failed to parse ${jsonFile}: ${(err as Error).message}`,
);
}
}

export class Store {
public chains: Record<string, Chain> = { global: new GlobalChain() };
public contracts: Record<string, PriceFeedContract> = {};
Expand Down Expand Up @@ -114,7 +125,7 @@ export class Store {
};

for (const jsonFile of this.getJsonFiles(`${this.path}/chains/`)) {
const parsedArray = JSON.parse(readFileSync(jsonFile, "utf8"));
const parsedArray = parseJsonFile(jsonFile);
for (const parsed of parsedArray) {
if (allChainClasses[parsed.type] === undefined) {
throw new Error(
Expand Down Expand Up @@ -202,7 +213,7 @@ export class Store {
[SuiLazerContract.type]: SuiLazerContract,
};
this.getJsonFiles(`${this.path}/contracts/`).forEach((jsonFile) => {
const parsedArray = JSON.parse(readFileSync(jsonFile, "utf8"));
const parsedArray = parseJsonFile(jsonFile);
for (const parsed of parsedArray) {
if (allContractClasses[parsed.type] === undefined) return;
if (!this.chains[parsed.chain])
Expand Down Expand Up @@ -242,7 +253,7 @@ export class Store {

loadAllTokens() {
this.getJsonFiles(`${this.path}/tokens/`).forEach((jsonFile) => {
const parsedArray = JSON.parse(readFileSync(jsonFile, "utf8"));
const parsedArray = parseJsonFile(jsonFile);
for (const parsed of parsedArray) {
if (parsed.type !== Token.type) return;

Expand All @@ -256,7 +267,7 @@ export class Store {

loadAllVaults() {
this.getJsonFiles(`${this.path}/vaults/`).forEach((jsonFile) => {
const parsedArray = JSON.parse(readFileSync(jsonFile, "utf8"));
const parsedArray = parseJsonFile(jsonFile);
for (const parsed of parsedArray) {
if (parsed.type !== Vault.type) return;

Expand Down