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.1.6 to 0.2.0

dist/utils.d.ts

2

dist/metrics/comp/tvl.d.ts

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

import { Timeframe, QueryResult, QueryRequest } from "../../primitives";
import { QueryRequest, QueryResult, Timeframe } from "../../primitives";
export declare const supportedTimeframes: Timeframe[];
export default function query(request: QueryRequest): QueryResult;
//# sourceMappingURL=tvl.d.ts.map

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

let errorMessage = response.error.toString();
if (errorMessage.includes("ECONNREFUSED") ||
errorMessage.includes("Failed to fetch")) {
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("Failed to fetch")) {
errorMessage = "Connection failed";

@@ -56,0 +55,0 @@ }

@@ -1,3 +0,4 @@

import { QueryRequest, QueryResult } from "../../primitives";
import { QueryRequest, QueryResult, SubscribeRequest, SubscribeResult } from "../../primitives";
export default function query(request: QueryRequest): QueryResult;
export declare function subscribe(request: SubscribeRequest): SubscribeResult;
//# sourceMappingURL=base_fee.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.subscribe = void 0;
const core_1 = require("urql/core");

@@ -25,8 +26,4 @@ const errors_1 = require("../../errors");

${collection === "blocks"
? `number
timestamp
gasUsed
baseFeePerGas
burnedFees
minerTips`
? `timestamp
baseFeePerGas`
: `timestamp

@@ -44,4 +41,3 @@ open

let errorMessage = response.error.toString();
if (errorMessage.includes("ECONNREFUSED") ||
errorMessage.includes("Failed to fetch")) {
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("Failed to fetch")) {
errorMessage = "Connection failed";

@@ -54,5 +50,38 @@ }

}
return response.data[collection].reverse();
if (collection === "blocks") {
const data = response.data[collection];
const parsed = [];
for (let i = data.length - 1; i >= 0; i--) {
const entry = data[i];
parsed.push({
close: entry.baseFeePerGas,
high: entry.baseFeePerGas,
low: entry.baseFeePerGas,
open: entry.baseFeePerGas,
timestamp: entry.timestamp,
});
}
return parsed;
}
else {
const data = response.data[collection];
return data.reverse();
}
}
exports.default = query;
function subscribe(request) {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request;
let lastTimestamp = since;
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe });
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp;
data.forEach(onNewData);
}
}, pollingInterval);
return function cleanup() {
clearInterval(intervalId);
};
}
exports.subscribe = subscribe;
//# sourceMappingURL=base_fee.js.map

@@ -1,4 +0,5 @@

import { QueryRequest, QueryResult, Timeframe } from "../../primitives";
import { QueryRequest, QueryResult, SubscribeRequest, SubscribeResult, Timeframe } from "../../primitives";
export declare const supportedTimeframes: Timeframe[];
export default function query(request: QueryRequest): QueryResult;
export declare function subscribe(request: SubscribeRequest): SubscribeResult;
//# sourceMappingURL=eth_price.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedTimeframes = void 0;
exports.subscribe = exports.supportedTimeframes = void 0;
const timeframeMapping = {

@@ -10,8 +10,3 @@ Day: "1d",

};
exports.supportedTimeframes = [
"Minute",
"Hour",
"Day",
"Week",
];
exports.supportedTimeframes = ["Minute", "Hour", "Day", "Week"];
async function query(request) {

@@ -59,2 +54,17 @@ const { timeframe, since, until, limit = 1000 } = request;

exports.default = query;
function subscribe(request) {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request;
let lastTimestamp = since;
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe });
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp;
data.forEach(onNewData);
}
}, pollingInterval);
return function cleanup() {
clearInterval(intervalId);
};
}
exports.subscribe = subscribe;
//# sourceMappingURL=eth_price.js.map

@@ -1,4 +0,5 @@

import { QueryRequest, QueryResult, Timeframe } from "../../primitives";
import { QueryRequest, QueryResult, SubscribeRequest, SubscribeResult, Timeframe } from "../../primitives";
export declare const supportedTimeframes: Timeframe[];
export default function query(request: QueryRequest): QueryResult;
export declare function subscribe(request: SubscribeRequest): SubscribeResult;
//# sourceMappingURL=tx_cost.d.ts.map

@@ -6,12 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedTimeframes = void 0;
exports.subscribe = exports.supportedTimeframes = void 0;
const primitives_1 = require("../../primitives");
const base_fee_1 = __importDefault(require("./base_fee"));
const eth_price_1 = __importDefault(require("./eth_price"));
exports.supportedTimeframes = [
"Minute",
"Hour",
"Day",
"Week",
];
exports.supportedTimeframes = ["Minute", "Hour", "Day", "Week"];
async function query(request) {

@@ -23,6 +18,6 @@ const { timeframe, since, until, priceUnit, limit = 1000 } = request;

let [baseFeePerGas, etherPrice] = await Promise.all([
(0, base_fee_1.default)({ timeframe, since, until, limit }),
(0, base_fee_1.default)({ limit, since, timeframe, until }),
priceUnit === primitives_1.PriceUnit.ETH
? Promise.resolve([])
: (0, eth_price_1.default)({ timeframe, since, until, limit }),
: (0, eth_price_1.default)({ limit, since, timeframe, until }),
]);

@@ -33,3 +28,2 @@ if (priceUnit === primitives_1.PriceUnit.ETH) {

etherPrice = etherPrice.slice(etherPrice.length - baseFeePerGas.length);
baseFeePerGas = baseFeePerGas;
if (baseFeePerGas.length !== etherPrice.length) {

@@ -50,2 +44,17 @@ // eslint-disable-next-line no-console

exports.default = query;
function subscribe(request) {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request;
let lastTimestamp = since;
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe });
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp;
data.forEach(onNewData);
}
}, pollingInterval);
return function cleanup() {
clearInterval(intervalId);
};
}
exports.subscribe = subscribe;
//# sourceMappingURL=tx_cost.js.map

@@ -7,18 +7,7 @@ export declare type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week";

}
export declare type Block = {
id: string;
number: string;
timestamp: string;
gasUsed: string;
/**
* @internal
*/
export declare type BlockData = {
baseFeePerGas: string;
txnCount: number;
minGasPrice: string;
maxGasPrice: string;
firstGasPrice: string;
lastGasPrice: string;
gasFees: string;
burnedFees: string;
minerTips: string;
};
export declare type SimpleBlock = Omit<Block, "txns" | "timestamp"> & {
timestamp: string;

@@ -36,6 +25,2 @@ };

export declare type QueryRequest = {
timeframe: Timeframe;
since?: string;
until?: string;
priceUnit?: PriceUnit;
/**

@@ -45,5 +30,25 @@ * @default 1000

limit?: number;
priceUnit?: PriceUnit;
since?: string;
timeframe: Timeframe;
until?: string;
};
export declare type QueryResult = Promise<Candle[] | SimpleBlock[]>;
export declare type QueryResult = Promise<Candle[]>;
export declare type QueryFn = (request: QueryRequest) => QueryResult;
export declare type SubscribeRequest = {
onNewData: (data: Candle) => void;
/**
* in milliseconds
* @default 3000
*/
pollingInterval?: number;
priceUnit?: PriceUnit;
since?: string;
timeframe: Timeframe;
};
/**
* @returns cleanup function used to unsubscribe
*/
export declare type SubscribeResult = () => void;
export declare type SubscribeFn = (request: SubscribeRequest) => SubscribeResult;
//# sourceMappingURL=primitives.d.ts.map
export * from "./errors";
export * from "./metric-declarations";
export * from "./primitives";
export * from "./metric-declarations";
export * from "./utils";
//# sourceMappingURL=protofun.d.ts.map

@@ -18,4 +18,5 @@ "use strict";

__exportStar(require("./errors"), exports);
__exportStar(require("./metric-declarations"), exports);
__exportStar(require("./primitives"), exports);
__exportStar(require("./metric-declarations"), exports);
__exportStar(require("./utils"), exports);
//# sourceMappingURL=protofun.js.map
{
"name": "protofun",
"license": "UNLICENSED",
"version": "0.1.6",
"version": "0.2.0",
"files": [

@@ -13,9 +13,9 @@ "dist",

"scripts": {
"start": "concurrently 'vite build --watch' 'yarn types --watch --preserveWatchOutput' --names 'vite,tsc' -c 'green,blue'",
"start": "concurrently 'vite build --watch' 'npm run types --watch --preserveWatchOutput' --names 'vite,tsc' -c 'green,blue'",
"build": "tsc --project tsconfig.prod.json",
"check-types": "tsc --noEmit",
"prepublish": "yarn build",
"pack": "yarn pack",
"lint": "eslint --ext='ts' src",
"lint:fix": "yarn lint -- --fix",
"prepublish": "npm run build",
"pack": "npm run pack",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"test": "vitest",

@@ -25,2 +25,5 @@ "test:ui": "vitest --ui",

},
"peerDependencies": {
"urql": "^4.0.5"
},
"devDependencies": {

@@ -35,3 +38,10 @@ "@typescript-eslint/eslint-plugin": "^5.30.0",

"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-prettier": "^4.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unused-imports": "^3.0.0",
"prettier": "^2.7.1",

@@ -38,0 +48,0 @@ "typescript": "^4.5.4",

@@ -14,5 +14,4 @@ export const METRIC_DECLARATIONS = {

export type MetricIdForProtocol<T extends ProtocolId> =
typeof METRIC_DECLARATIONS[T][number]
export type MetricIdForProtocol<T extends ProtocolId> = typeof METRIC_DECLARATIONS[T][number]
export type MetricId = MetricIdForProtocol<ProtocolId>

@@ -47,2 +47,2 @@ export const markets = [

},
];
]
import { createClient, fetchExchange, gql } from "urql/core"
import { Timeframe, QueryResult, QueryRequest } from "../../primitives"
import { IndexerError } from "../../errors"
import { QueryRequest, QueryResult, Timeframe } from "../../primitives"
import { MarketDailySnapshot } from "./types"

@@ -26,5 +27,3 @@

if (!supportedTimeframes.includes(timeframe)) {
throw new Error(
`Timeframe '${timeframe}' is not supported for this metric.`
)
throw new Error(`Timeframe '${timeframe}' is not supported for this metric.`)
}

@@ -64,6 +63,3 @@

let errorMessage = response.error.toString()
if (
errorMessage.includes("ECONNREFUSED") ||
errorMessage.includes("Failed to fetch")
) {
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("Failed to fetch")) {
errorMessage = "Connection failed"

@@ -70,0 +66,0 @@ }

export type Market = {
id: string;
name: string;
};
id: string
name: string
}
export type MarketDailySnapshot = {
market: Market;
openPositionCount: number;
timestamp: string;
totalValueLockedUSD: string;
};
market: Market
openPositionCount: number
timestamp: string
totalValueLockedUSD: string
}
import { createClient, fetchExchange, gql } from "urql/core"
import { QueryRequest, QueryResult } from "../../primitives"
import { IndexerError } from "../../errors"
import {
BlockData,
Candle,
QueryRequest,
QueryResult,
SubscribeRequest,
SubscribeResult,
} from "../../primitives"

@@ -16,4 +24,3 @@ // TODO enable text compression on the api

const collection =
timeframe === "Block" ? "blocks" : `baseFeePerGas${timeframe}Candles`
const collection = timeframe === "Block" ? "blocks" : `baseFeePerGas${timeframe}Candles`

@@ -32,8 +39,4 @@ const graphQuery = gql`query($since: BigInt, $until: BigInt) {

collection === "blocks"
? `number
timestamp
gasUsed
baseFeePerGas
burnedFees
minerTips`
? `timestamp
baseFeePerGas`
: `timestamp

@@ -53,6 +56,3 @@ open

let errorMessage = response.error.toString()
if (
errorMessage.includes("ECONNREFUSED") ||
errorMessage.includes("Failed to fetch")
) {
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("Failed to fetch")) {
errorMessage = "Connection failed"

@@ -68,3 +68,41 @@ }

return response.data[collection].reverse()
if (collection === "blocks") {
const data = response.data[collection] as BlockData[]
const parsed: Candle[] = []
for (let i = data.length - 1; i >= 0; i--) {
const entry = data[i]
parsed.push({
close: entry.baseFeePerGas,
high: entry.baseFeePerGas,
low: entry.baseFeePerGas,
open: entry.baseFeePerGas,
timestamp: entry.timestamp,
})
}
return parsed
} else {
const data = response.data[collection] as Candle[]
return data.reverse()
}
}
export function subscribe(request: SubscribeRequest): SubscribeResult {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request
let lastTimestamp = since
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe })
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp
data.forEach(onNewData)
}
}, pollingInterval)
return function cleanup() {
clearInterval(intervalId)
}
}

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

import { QueryRequest, QueryResult, Timeframe } from "../../primitives"
import {
QueryRequest,
QueryResult,
SubscribeRequest,
SubscribeResult,
Timeframe,
} from "../../primitives"

@@ -10,8 +16,3 @@ const timeframeMapping: Partial<Record<Timeframe, string>> = {

export const supportedTimeframes: Timeframe[] = [
"Minute",
"Hour",
"Day",
"Week",
]
export const supportedTimeframes: Timeframe[] = ["Minute", "Hour", "Day", "Week"]

@@ -23,5 +24,3 @@ export default async function query(request: QueryRequest): QueryResult {

if (!supportedTimeframes.includes(timeframe)) {
throw new Error(
`Timeframe '${timeframe}' is not supported for this metric.`
)
throw new Error(`Timeframe '${timeframe}' is not supported for this metric.`)
}

@@ -58,3 +57,3 @@

// ]
return data.map((x: any) => ({
return data.map((x: number[]) => ({
close: x[4],

@@ -67,1 +66,19 @@ high: x[2],

}
export function subscribe(request: SubscribeRequest): SubscribeResult {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request
let lastTimestamp = since
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe })
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp
data.forEach(onNewData)
}
}, pollingInterval)
return function cleanup() {
clearInterval(intervalId)
}
}

@@ -6,2 +6,4 @@ import {

QueryResult,
SubscribeRequest,
SubscribeResult,
Timeframe,

@@ -12,8 +14,3 @@ } from "../../primitives"

export const supportedTimeframes: Timeframe[] = [
"Minute",
"Hour",
"Day",
"Week",
]
export const supportedTimeframes: Timeframe[] = ["Minute", "Hour", "Day", "Week"]

@@ -24,28 +21,21 @@ export default async function query(request: QueryRequest): QueryResult {

if (!supportedTimeframes.includes(timeframe)) {
throw new Error(
`Timeframe '${timeframe}' is not supported for this metric.`
)
throw new Error(`Timeframe '${timeframe}' is not supported for this metric.`)
}
let [baseFeePerGas, etherPrice] = await Promise.all([
queryBaseFeePerGas({ timeframe, since, until, limit }),
queryBaseFeePerGas({ limit, since, timeframe, until }),
priceUnit === PriceUnit.ETH
? Promise.resolve([])
: queryEtherPrice({ timeframe, since, until, limit }),
: queryEtherPrice({ limit, since, timeframe, until }),
])
if (priceUnit === PriceUnit.ETH) {
return baseFeePerGas as Candle[]
return baseFeePerGas
}
etherPrice = etherPrice.slice(etherPrice.length - baseFeePerGas.length)
baseFeePerGas = baseFeePerGas as Candle[]
if (baseFeePerGas.length !== etherPrice.length) {
// eslint-disable-next-line no-console
console.log(
"📜 LOG > baseFeePerGas, etherPrice:",
baseFeePerGas,
etherPrice
)
console.log("📜 LOG > baseFeePerGas, etherPrice:", baseFeePerGas, etherPrice)
throw new Error("queryTransferCostUsd: This should never happen!")

@@ -56,16 +46,26 @@ }

...x,
close: String(
parseFloat(x.close) * parseFloat((etherPrice[index] as Candle).close)
),
high: String(
parseFloat(x.high) * parseFloat((etherPrice[index] as Candle).high)
),
low: String(
parseFloat(x.low) * parseFloat((etherPrice[index] as Candle).low)
),
open: String(
parseFloat(x.open) * parseFloat((etherPrice[index] as Candle).open)
),
close: String(parseFloat(x.close) * parseFloat((etherPrice[index] as Candle).close)),
high: String(parseFloat(x.high) * parseFloat((etherPrice[index] as Candle).high)),
low: String(parseFloat(x.low) * parseFloat((etherPrice[index] as Candle).low)),
open: String(parseFloat(x.open) * parseFloat((etherPrice[index] as Candle).open)),
timestamp: x.timestamp,
}))
}
export function subscribe(request: SubscribeRequest): SubscribeResult {
const { timeframe, since, onNewData, priceUnit, pollingInterval = 3000 } = request
let lastTimestamp = since
const intervalId = setInterval(async () => {
const data = await query({ priceUnit, since: lastTimestamp, timeframe })
if (data.length) {
lastTimestamp = data[data.length - 1].timestamp
data.forEach(onNewData)
}
}, pollingInterval)
return function cleanup() {
clearInterval(intervalId)
}
}

@@ -9,20 +9,7 @@ export type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week"

export type Block = {
id: string // bytes
number: string // BigInt
timestamp: string // BigInt
gasUsed: string // BigInt
/**
* @internal
*/
export type BlockData = {
baseFeePerGas: string // BigInt
// txns: Array<Txn>
txnCount: number
minGasPrice: string // BigInt
maxGasPrice: string // BigInt
firstGasPrice: string // BigInt
lastGasPrice: string // BigInt
gasFees: string // BigInt
burnedFees: string // BigInt
minerTips: string // BigInt
}
export type SimpleBlock = Omit<Block, "txns" | "timestamp"> & {
timestamp: string

@@ -48,6 +35,2 @@ }

export type QueryRequest = {
timeframe: Timeframe
since?: string
until?: string
priceUnit?: PriceUnit
/**

@@ -57,4 +40,26 @@ * @default 1000

limit?: number
priceUnit?: PriceUnit
since?: string
timeframe: Timeframe
until?: string
}
export type QueryResult = Promise<Candle[] | SimpleBlock[]>
export type QueryResult = Promise<Candle[]>
export type QueryFn = (request: QueryRequest) => QueryResult
export type SubscribeRequest = {
onNewData: (data: Candle) => void
/**
* in milliseconds
* @default 3000
*/
pollingInterval?: number
priceUnit?: PriceUnit
since?: string
timeframe: Timeframe
}
/**
* @returns cleanup function used to unsubscribe
*/
export type SubscribeResult = () => void
export type SubscribeFn = (request: SubscribeRequest) => SubscribeResult
export * from "./errors"
export * from "./metric-declarations"
export * from "./primitives"
export * from "./metric-declarations"
export * from "./utils"

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

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

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