Skip to content

Commit

Permalink
Fix linting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Spenhouet committed Mar 1, 2024
1 parent ca8e4c1 commit 953b26e
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export default class Adapter implements bcked.asset.Adapter {
// Load and update custodian list from: https://wbtc.network/api/chain/eth/token/wbtc/addresses?type=custodial
// Query custodian addresses for holdings via Blockstream API: https://github.com/Blockstream/esplora/blob/master/API.md

const response =
await this.wbtcApi.fetchJson<wbtcApiTokenResponse>("/chain/eth/token/wbtc");
const response = await this.wbtcApi.fetchJson<wbtcApiTokenResponse>(
"/chain/eth/token/wbtc"
);
// Convert holdings from satoshis to bitcoins
const holdings = parseFloat(utils.formatUnits(response.holdings, 8));
return [
Expand Down
2 changes: 1 addition & 1 deletion src/api/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function compile<Result>(
dir: string,
workerScript: string,
resources: JsonResources | undefined = undefined
): Promise<Array<Result | null>> {
): Promise<(Result | null)[]> {
const ids = await fs.readdir(dir);

if (resources) {
Expand Down
24 changes: 12 additions & 12 deletions src/api/resources/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ export class Asset extends JsonResources {
asset: {
$ref: `/assets/${node.id}`,
},
"collateralization-ratio": node?.data?.value
"collateralization-ratio": node.data?.value
? {
$ref: setDateParts(
`/assets/${node.id}/collateralization-ratio/{year}/{month}/{day}/{hour}`,
node.data.timestamp
),
}
: undefined,
value: node?.data?.value
value: node.data?.value
? {
"rwa:USD": node.data.value,
}
Expand Down Expand Up @@ -314,21 +314,21 @@ export class Asset extends JsonResources {
async details(id: bcked.asset.Id, details: bcked.asset.DetailsRecord) {
return {
$id: `/assets/${id}/details`,
name: details?.name,
symbol: details?.symbol,
name: details.name,
symbol: details.symbol,
identifier: {
address: details?.identifier.address,
address: details.identifier.address,
// TODO Map to system ref
system: details?.identifier.system,
system: details.identifier.system,
},
assetClasses: details?.assetClasses,
assetClasses: details.assetClasses,
// TODO Map to entity refs
// TODO make list instead?
linkedEntities: details?.linkedEntities,
reference: details?.reference,
tags: details?.tags,
listed: details?.listed,
updated: details?.updated,
linkedEntities: details.linkedEntities,
reference: details.reference,
tags: details.tags,
listed: details.listed,
updated: details.updated,
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/api/resources/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class Entity extends JsonResources {
async details(id: bcked.entity.Id, details: bcked.entity.DetailsRecord) {
return {
$id: `/entities/${id}/details`,
name: details?.name,
identifier: details?.identifier,
reference: details?.reference,
tags: details?.tags,
listed: details?.listed,
updated: details?.updated,
name: details.name,
identifier: details.identifier,
reference: details.reference,
tags: details.tags,
listed: details.listed,
updated: details.updated,
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/api/resources/systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class System extends JsonResources {
async details(id: bcked.system.Id, details: bcked.system.DetailsRecord) {
return {
$id: `/systems/${id}/details`,
name: details?.name,
name: details.name,
// TODO reference to asset
native: details?.native,
explorer: details?.explorer,
listed: details?.listed,
updated: details?.updated,
native: details.native,
explorer: details.explorer,
listed: details.listed,
updated: details.updated,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { renderSvgToPng } from "../utils/renderSvg";
import { JsonResources } from "./resources";

export async function compileDetails<
Resources extends JsonResources & { details: (...args: any[]) => any },
Resources extends JsonResources & { details: (...args: any[]) => any }
>(resources: Resources, path: string, id: string) {
const filePath = join(path, id, PATHS.records, "details.json");
const details = await readJson(filePath);
Expand All @@ -17,7 +17,7 @@ export async function compileDetails<
}

export async function compileIcons<
Resources extends JsonResources & { icons: (...args: any[]) => any },
Resources extends JsonResources & { icons: (...args: any[]) => any }
>(resources: Resources, path: string, id: string) {
const resource = await resources.icons(id);

Expand Down
6 changes: 3 additions & 3 deletions src/api/utils/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { Template } from "../../utils/template";
interface Spec {
openapi?: string | undefined;
info?: oas.Information | undefined;
servers?: ReadonlyArray<oas.Server> | undefined;
servers?: readonly oas.Server[] | undefined;
paths?: oas.Paths | undefined;
components?: oas.Components | undefined;
security?: ReadonlyArray<oas.SecurityRequirement> | undefined;
tags?: ReadonlyArray<oas.Tag> | undefined;
security?: readonly oas.SecurityRequirement[] | undefined;
tags?: readonly oas.Tag[] | undefined;
externalDocs?: oas.ExternalDocumentation | undefined;
[key: string]: any;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/workers/compile_asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function compileHistory<TObject extends primitive.Timestamped, TKey extend

if (!existsSync(csvPath)) return;

const historyStats: StreamStats<TObject, TKey> = new StreamStats(key, 100);
const historyStats = new StreamStats<TObject, TKey>(key, 100);

const yearsOfHistory: string[] = [];
let yearsStats: StreamStats<TObject, TKey> | undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/api/workers/compile_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ASSET_RESOURCES } from "../resources/assets";

async function compileHistory<
TObject extends primitive.Timestamped,
TKey extends keyof TObject | PropertyPath,
TKey extends keyof TObject | PropertyPath
>(
csvName: string,
key: TKey,
Expand Down Expand Up @@ -45,7 +45,7 @@ async function compileHistory<

if (!existsSync(csvPath)) return;

const historyStats: StreamStats<TObject, TKey> = new StreamStats(key, 100);
const historyStats = new StreamStats<TObject, TKey>(key, 100);

const yearsOfHistory: string[] = [];
let yearsStats: StreamStats<TObject, TKey> | undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/api/workers/precompile_collateralization_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { round } from "../../utils/math";
import { toISOString } from "../../utils/string_formatting";
import { daysInMs, getDatesBetween } from "../../utils/time";

type CollateralizationLookup = {
interface CollateralizationLookup {
assetId: bcked.asset.Id;
lookup: ConsecutiveLookup<bcked.asset.Collateralization>;
};
}

async function createGraphForTimestamp(
timestamp: primitive.DateLike,
Expand Down
28 changes: 13 additions & 15 deletions src/types/bcked.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,48 +121,46 @@ declare namespace bcked {

type SupplyAmount = Supply & { amount: number };

type Backing = {
interface Backing {
timestamp: primitive.ISODateTimeString;
underlying: Partial<Record<Id, number>>;
};
}

// Generated from supply and price data
type MarketCap = {
interface MarketCap {
timestamp: primitive.ISODateTimeString;
price: Price;
supply: SupplyAmount;
usd: number;
};
}

// Generated from backing and price data to cover underlying and derivative assets
type Relationship = {
interface Relationship {
amount: number;
price?: Price;
usd?: number;
};
}

// Generated from backing and price data to cover underlying and derivative assets
type Relationships = {
interface Relationships {
timestamp: primitive.ISODateTimeString;
usd: number;
breakdown: {
[assetId: bcked.asset.Id]: Relationship;
};
};
breakdown: Record<bcked.asset.Id, Relationship>;
}

// Generated from market cap and underlying assets data
type Collateralization = {
interface Collateralization {
timestamp: primitive.ISODateTimeString;
market_cap: MarketCap;
collateral: Relationships;
ratio: number;
};
}

type Graph = {
interface Graph {
timestamp: primitive.ISODateTimeString;
graph: graph.Graph;
stats: graph.Stats;
};
}

interface Adapter {
getDetails(lastRecorded: DetailsRecord | null): Promise<Details>;
Expand Down
24 changes: 12 additions & 12 deletions src/types/graph.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
declare namespace graph {
type NodeData = {
interface NodeData {
timestamp: primitive.ISODateTimeString;
value: number;
};
}

type LinkData = {
interface LinkData {
value: number | undefined;
};
}

type Node = {
interface Node {
id: derived.AssetId;
data?: NodeData;
};
}

type Link = {
interface Link {
fromId: derived.AssetId;
toId: derived.AssetId;
data: LinkData;
};
}

type Graph = {
interface Graph {
nodes: Node[];
links: Link[];
};
}

type Stats = {
interface Stats {
numNodes: number;
numLinks: number;
averageDegree: number;
Expand All @@ -34,5 +34,5 @@ declare namespace graph {
rootCollateralization: number;
leaveCollateralization: number;
totalCollateralization: number;
};
}
}
4 changes: 3 additions & 1 deletion src/types/primitive.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ declare namespace primitive {

type URL = `https://${string}.${string}`;

type Timestamped = { timestamp: ISODateTimeString };
interface Timestamped {
timestamp: ISODateTimeString;
}
}
2 changes: 1 addition & 1 deletion src/utils/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export async function createCsv<T>(pathToFile: string, rows: AsyncIterable<T>, h
}

export class ConsecutiveLookup<T extends primitive.Timestamped> {
private readonly values: Map<string, T> = new Map();
private readonly values = new Map<string, T>();
private readonly csvStream: AsyncGenerator<T>;
private done: boolean = false;
private lastTimestamp: string | undefined = undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function job(name: string, job: () => Promise<void>) {
}

try {
await job();
await job();
} catch (error) {
console.error(`Job "${name}" failed:`, error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _, { type List, type ListIteratee, type Many, type PropertyPath } from "l

export function statsBy<T>(
collection: List<T> | null | undefined,
...iteratees: Array<Many<ListIteratee<T>>>
...iteratees: Many<ListIteratee<T>>[]
): { low: T; median: T; high: T } | null {
if (!collection?.length) return null;

Expand Down
5 changes: 1 addition & 4 deletions src/utils/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { medianBy } from "./math";
export class StreamMedian<TObject extends object, TKey extends keyof TObject | PropertyPath> {
private sampler: ReservoirSampler<TObject>;

constructor(
private path: TKey | PropertyPath,
sampleSize: number
) {
constructor(private path: TKey | PropertyPath, sampleSize: number) {
this.sampler = new ReservoirSampler(sampleSize);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Template {
return new RegExp(`^${matcher}$`).test(str);
}

format(mapping: { [key: string]: string }): string {
format(mapping: Record<string, string>): string {
let template = this.template;
for (const [key, value] of Object.entries(mapping)) {
template = template.replace(new RegExp(`\\{${key}\\}`, "gi"), value);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/worker_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function executeInWorkerPool<Data, Result>(
workerScriptPath: string,
workItems: Data[],
options: Options = { min: 0, max: 4 }
): Promise<Array<Result | null>> {
): Promise<(Result | null)[]> {
const pool = new WorkerPool(workerScriptPath, options);
const res = await Promise.all(
workItems.map((workItem) => pool.execute<Data, Result>(workItem))
Expand Down

0 comments on commit 953b26e

Please sign in to comment.