New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

protofun

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protofun - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

40

dist/metric-declarations.d.ts

@@ -1,2 +0,3 @@

export declare const METRIC_DECLARATIONS: {
import { PriceUnit } from "./primitives";
declare const METRIC_DECLARATIONS: {
readonly aave: readonly [];

@@ -7,5 +8,42 @@ readonly comp: readonly ["tvl"];

};
/**
* Protocols
*/
export declare type ProtocolId = keyof typeof METRIC_DECLARATIONS;
export declare type Protocol = {
enabled?: boolean;
id: ProtocolId;
title: string;
};
export declare const PROTOCOL_MAP: Record<ProtocolId, Protocol>;
export declare const PROTOCOL_IDS: ("aave" | "comp" | "eth" | "mkr")[];
export declare const PROTOCOLS: Protocol[];
/**
* Metrics
*/
export declare type MetricIdForProtocol<T extends ProtocolId> = typeof METRIC_DECLARATIONS[T][number];
export declare type MetricId = MetricIdForProtocol<ProtocolId>;
export declare type Variant = {
label: string;
precision: number;
value?: string;
};
export declare type Metric = {
allowCompactPriceScale?: boolean;
disallowAlerts?: boolean;
disallowCandleType?: boolean;
disallowLiveMode?: boolean;
id: MetricId;
precision: number;
preferredLogScale?: boolean;
priceUnits: PriceUnit[];
protocol: ProtocolId;
significantDigits: number[];
title: string;
variants?: Variant[];
};
declare type MetricsMapType = Record<ProtocolId, Partial<Record<MetricId, Metric>>>;
export declare const METRICS_MAP: MetricsMapType;
export declare const METRICS: Metric[];
export {};
//# sourceMappingURL=metric-declarations.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.METRIC_DECLARATIONS = void 0;
exports.METRIC_DECLARATIONS = {
exports.METRICS = exports.METRICS_MAP = exports.PROTOCOLS = exports.PROTOCOL_IDS = exports.PROTOCOL_MAP = void 0;
const primitives_1 = require("./primitives");
const METRIC_DECLARATIONS = {
aave: [],

@@ -10,2 +11,101 @@ comp: ["tvl"],

};
exports.PROTOCOL_MAP = {
aave: {
id: "aave",
title: "Aave",
},
// btc: {
// enabled: false,
// id: "btc",
// title: "Bitcoin",
// },
comp: {
enabled: true,
id: "comp",
title: "Compound",
},
eth: {
enabled: true,
id: "eth",
title: "Ethereum",
},
mkr: {
id: "mkr",
title: "MakerDAO",
},
};
exports.PROTOCOL_IDS = Object.keys(exports.PROTOCOL_MAP);
exports.PROTOCOLS = Object.values(exports.PROTOCOL_MAP).sort((a, b) => {
if (a.enabled === b.enabled) {
return 0;
}
else if (a.enabled && !b.enabled) {
return -1;
}
else {
return 1;
}
});
exports.METRICS_MAP = {
aave: {},
comp: {
tvl: {
allowCompactPriceScale: true,
disallowAlerts: true,
disallowCandleType: true,
disallowLiveMode: true,
id: "tvl",
precision: 1,
priceUnits: [primitives_1.PriceUnit.USD],
protocol: "comp",
significantDigits: [0],
title: "Total value locked",
variants: [{ label: "Compound V3 USDC - Wrapped Ether", precision: 1 }],
},
},
eth: {
base_fee: {
id: "base_fee",
precision: 1e9,
preferredLogScale: true,
priceUnits: [primitives_1.PriceUnit.GWEI],
protocol: "eth",
significantDigits: [2],
title: "Base fee per gas",
},
eth_price: {
disallowAlerts: true,
id: "eth_price",
precision: 1,
preferredLogScale: true,
priceUnits: [primitives_1.PriceUnit.USD],
protocol: "eth",
significantDigits: [2],
timeframes: ["Minute", "Hour", "Day", "Week"],
title: "Ether price",
},
tx_cost: {
disallowAlerts: true,
id: "tx_cost",
precision: 1,
preferredLogScale: true,
priceUnits: [primitives_1.PriceUnit.USD, primitives_1.PriceUnit.ETH],
protocol: "eth",
significantDigits: [2, 5],
timeframes: ["Minute", "Hour", "Day", "Week"],
title: "Transaction cost",
variants: [
{ label: "ETH Transfer", precision: 1e18 / 21_000 },
{ label: "ERC20 Approval", precision: 1e18 / 45_000 },
{ label: "ERC20 Transfer", precision: 1e18 / 65_000 },
{ label: "NFT Transfer", precision: 1e18 / 85_000 },
{ label: "Uniswap V2 Swap", precision: 1e18 / 150_000 },
{ label: "Uniswap V3 Swap", precision: 1e18 / 185_000 },
{ label: "L2 Deposit", precision: 1e18 / 250_000 },
],
},
},
mkr: {},
};
exports.METRICS = exports.PROTOCOL_IDS.map((protocolId) => Object.values(exports.METRICS_MAP[protocolId] || {})).flat();
//# sourceMappingURL=metric-declarations.js.map

3

dist/primitives.d.ts
export declare type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week";
export declare const TIME_FRAMES: Record<Timeframe, string>;
export declare enum PriceUnit {

@@ -21,4 +22,2 @@ ETH = "ETH",

};
export declare function isCandle(value: unknown): value is Candle;
export declare function isCandleArray(value: unknown[]): value is Candle[];
export declare type QueryRequest = {

@@ -25,0 +24,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isCandleArray = exports.isCandle = exports.PriceUnit = void 0;
exports.PriceUnit = exports.TIME_FRAMES = void 0;
exports.TIME_FRAMES = {
Block: "Block",
Minute: "1m",
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
Hour: "1h",
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
Day: "D",
Week: "W",
};
var PriceUnit;

@@ -10,10 +19,2 @@ (function (PriceUnit) {

})(PriceUnit = exports.PriceUnit || (exports.PriceUnit = {}));
function isCandle(value) {
return typeof value === "object" && value !== null && "open" in value;
}
exports.isCandle = isCandle;
function isCandleArray(value) {
return Array.isArray(value) && value.length > 0 && isCandle(value[0]);
}
exports.isCandleArray = isCandleArray;
//# sourceMappingURL=primitives.js.map

@@ -1,2 +0,2 @@

import { MetricId, ProtocolId, QueryFn, SubscribeFn, Timeframe } from "./protofun";
import { Candle, MetricId, ProtocolId, QueryFn, SubscribeFn, Timeframe } from "./protofun";
export declare function wait(ms: number): Promise<void>;

@@ -11,2 +11,7 @@ export declare const allTimeframes: Timeframe[];

export declare function getLowestTimeframe(supportedTimeframes: Timeframe[]): Timeframe;
export declare function isProtocolId(value: string): value is ProtocolId;
export declare function isMetric(protocol: ProtocolId, value: string): value is MetricId;
export declare function isTimeframe(value: string): value is Timeframe;
export declare function isCandle(value: unknown): value is Candle;
export declare function isCandleArray(value: unknown[]): value is Candle[];
//# sourceMappingURL=utils.d.ts.map

@@ -26,3 +26,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getLowestTimeframe = exports.loadMetricFns = exports.allTimeframes = exports.wait = void 0;
exports.isCandleArray = exports.isCandle = exports.isTimeframe = exports.isMetric = exports.isProtocolId = exports.getLowestTimeframe = exports.loadMetricFns = exports.allTimeframes = exports.wait = void 0;
const protofun_1 = require("./protofun");
async function wait(ms) {

@@ -43,2 +44,22 @@ return new Promise((resolve) => setTimeout(resolve, ms));

exports.getLowestTimeframe = getLowestTimeframe;
function isProtocolId(value) {
return value in protofun_1.PROTOCOL_MAP;
}
exports.isProtocolId = isProtocolId;
function isMetric(protocol, value) {
return !!protofun_1.METRICS_MAP[protocol]?.[value];
}
exports.isMetric = isMetric;
function isTimeframe(value) {
return Object.keys(protofun_1.TIME_FRAMES).includes(value);
}
exports.isTimeframe = isTimeframe;
function isCandle(value) {
return typeof value === "object" && value !== null && "open" in value;
}
exports.isCandle = isCandle;
function isCandleArray(value) {
return Array.isArray(value) && value.length > 0 && isCandle(value[0]);
}
exports.isCandleArray = isCandleArray;
//# sourceMappingURL=utils.js.map
{
"name": "protofun",
"license": "UNLICENSED",
"version": "0.2.0",
"version": "0.2.1",
"files": [

@@ -6,0 +6,0 @@ "dist",

@@ -1,2 +0,4 @@

export const METRIC_DECLARATIONS = {
import { PriceUnit } from "./primitives"
const METRIC_DECLARATIONS = {
aave: [],

@@ -8,10 +10,152 @@ comp: ["tvl"],

/**
* Protocols
*/
export type ProtocolId = keyof typeof METRIC_DECLARATIONS
export type Protocol = {
enabled?: boolean
id: ProtocolId
title: string
}
export const PROTOCOL_MAP: Record<ProtocolId, Protocol> = {
aave: {
id: "aave",
title: "Aave",
},
// btc: {
// enabled: false,
// id: "btc",
// title: "Bitcoin",
// },
comp: {
enabled: true,
id: "comp",
title: "Compound",
},
eth: {
enabled: true,
id: "eth",
title: "Ethereum",
},
mkr: {
id: "mkr",
title: "MakerDAO",
},
} as const
export const PROTOCOL_IDS = Object.keys(PROTOCOL_MAP) as ProtocolId[]
export const PROTOCOLS = Object.values(PROTOCOL_MAP).sort((a, b) => {
if (a.enabled === b.enabled) {
return 0
} else if (a.enabled && !b.enabled) {
return -1
} else {
return 1
}
})
/**
* Metrics
*/
// Not working:
// type ValueOf<T> = T[keyof T];
// export type MetricId = ValueOf<typeof METRIC_LIST_DEFINITION>[number];
export type MetricIdForProtocol<T extends ProtocolId> = typeof METRIC_DECLARATIONS[T][number]
export type MetricId = MetricIdForProtocol<ProtocolId>
export type MetricId = MetricIdForProtocol<ProtocolId>
export type Variant = {
label: string
precision: number
value?: string
}
export type Metric = {
allowCompactPriceScale?: boolean
disallowAlerts?: boolean
disallowCandleType?: boolean
disallowLiveMode?: boolean
id: MetricId
precision: number
preferredLogScale?: boolean
priceUnits: PriceUnit[]
protocol: ProtocolId
significantDigits: number[]
title: string
variants?: Variant[]
}
// type MapType<T extends ProtocolId> = Record<
// T,
// Record<MetricIdsOfProtocol<T>, Metric>
// >;
type MetricsMapType = Record<ProtocolId, Partial<Record<MetricId, Metric>>>
export const METRICS_MAP: MetricsMapType = {
aave: {} as Record<MetricIdForProtocol<"aave">, Metric>,
comp: {
tvl: {
allowCompactPriceScale: true,
disallowAlerts: true,
disallowCandleType: true,
disallowLiveMode: true,
id: "tvl",
precision: 1,
priceUnits: [PriceUnit.USD],
protocol: "comp",
significantDigits: [0],
title: "Total value locked",
variants: [{ label: "Compound V3 USDC - Wrapped Ether", precision: 1 }],
},
} as Record<MetricIdForProtocol<"comp">, Metric>,
eth: {
base_fee: {
id: "base_fee",
precision: 1e9,
preferredLogScale: true,
priceUnits: [PriceUnit.GWEI],
protocol: "eth",
significantDigits: [2],
title: "Base fee per gas",
},
eth_price: {
disallowAlerts: true,
id: "eth_price",
precision: 1,
preferredLogScale: true,
priceUnits: [PriceUnit.USD],
protocol: "eth",
significantDigits: [2],
timeframes: ["Minute", "Hour", "Day", "Week"],
title: "Ether price",
},
tx_cost: {
disallowAlerts: true,
id: "tx_cost",
precision: 1,
preferredLogScale: true,
priceUnits: [PriceUnit.USD, PriceUnit.ETH],
protocol: "eth",
significantDigits: [2, 5],
timeframes: ["Minute", "Hour", "Day", "Week"],
title: "Transaction cost",
variants: [
{ label: "ETH Transfer", precision: 1e18 / 21_000 },
{ label: "ERC20 Approval", precision: 1e18 / 45_000 },
{ label: "ERC20 Transfer", precision: 1e18 / 65_000 },
{ label: "NFT Transfer", precision: 1e18 / 85_000 },
{ label: "Uniswap V2 Swap", precision: 1e18 / 150_000 },
{ label: "Uniswap V3 Swap", precision: 1e18 / 185_000 },
{ label: "L2 Deposit", precision: 1e18 / 250_000 },
],
},
} as Record<MetricIdForProtocol<"eth">, Metric>,
mkr: {} as Record<MetricIdForProtocol<"mkr">, Metric>,
}
export const METRICS = PROTOCOL_IDS.map((protocolId) =>
Object.values(METRICS_MAP[protocolId] || {})
).flat()
export type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week"
export const TIME_FRAMES: Record<Timeframe, string> = {
Block: "Block",
Minute: "1m",
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
Hour: "1h",
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
Day: "D",
Week: "W",
}

@@ -25,10 +34,2 @@ export enum PriceUnit {

export function isCandle(value: unknown): value is Candle {
return typeof value === "object" && value !== null && "open" in value
}
export function isCandleArray(value: unknown[]): value is Candle[] {
return Array.isArray(value) && value.length > 0 && isCandle(value[0])
}
export type QueryRequest = {

@@ -35,0 +36,0 @@ /**

@@ -1,2 +0,12 @@

import { MetricId, ProtocolId, QueryFn, SubscribeFn, Timeframe } from "./protofun"
import {
Candle,
MetricId,
METRICS_MAP,
PROTOCOL_MAP,
ProtocolId,
QueryFn,
SubscribeFn,
TIME_FRAMES,
Timeframe,
} from "./protofun"

@@ -28,1 +38,21 @@ export async function wait(ms: number): Promise<void> {

}
export function isProtocolId(value: string): value is ProtocolId {
return value in PROTOCOL_MAP
}
export function isMetric(protocol: ProtocolId, value: string): value is MetricId {
return !!METRICS_MAP[protocol]?.[value as MetricId]
}
export function isTimeframe(value: string): value is Timeframe {
return Object.keys(TIME_FRAMES).includes(value)
}
export function isCandle(value: unknown): value is Candle {
return typeof value === "object" && value !== null && "open" in value
}
export function isCandleArray(value: unknown[]): value is Candle[] {
return Array.isArray(value) && value.length > 0 && isCandle(value[0])
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc