🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

redstone-sdk

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redstone-sdk - npm Package Compare versions

Comparing version

to
1.8.2

import { DataPackagesRequestParams } from "../index";
export declare class ContractParamsProvider {
readonly requestParams: DataPackagesRequestParams;
constructor(requestParams: DataPackagesRequestParams, urls?: string[]);
constructor(requestParams: DataPackagesRequestParams);
getPayloadHex(withPrefix?: boolean): Promise<string>;
getPayloadData(): Promise<number[]>;

@@ -6,0 +7,0 @@ getHexlifiedFeedIds(): string[];

@@ -9,11 +9,10 @@ "use strict";

class ContractParamsProvider {
constructor(requestParams, urls) {
constructor(requestParams) {
this.requestParams = requestParams;
if (!urls) {
requestParams.urls = (0, index_1.getUrlsForDataServiceId)(requestParams);
}
}
async getPayloadHex(withPrefix = true) {
return ((withPrefix ? "0x" : "") + (await this.requestPayload(this.requestParams)));
}
async getPayloadData() {
const payloadHex = await this.requestPayload(this.requestParams);
return Array.from((0, utils_1.arrayify)(payloadHex));
return Array.from((0, utils_1.arrayify)(await this.getPayloadHex(true)));
}

@@ -30,3 +29,3 @@ getHexlifiedFeedIds() {

async requestPayload(requestParams) {
return "0x" + (await (0, index_1.requestRedstonePayload)(requestParams));
return await (0, index_1.requestRedstonePayload)(requestParams);
}

@@ -33,0 +32,0 @@ }

export interface IContractConnector<Adapter> {
getAdapter(): Promise<Adapter>;
getBlockNumber(rpcUrl: string): Promise<number>;
waitForTransaction(txId: string): Promise<boolean>;
}
//# sourceMappingURL=IContractConnector.d.ts.map
import { ContractParamsProvider } from "../ContractParamsProvider";
import { BigNumberish } from "ethers";
export interface IPricesContractAdapter {
getPricesFromPayload(paramsProvider: ContractParamsProvider): Promise<number[]>;
writePricesFromPayloadToContract(paramsProvider: ContractParamsProvider): Promise<string | number[]>;
readPricesFromContract(paramsProvider: ContractParamsProvider): Promise<number[]>;
getPricesFromPayload(paramsProvider: ContractParamsProvider): Promise<BigNumberish[]>;
writePricesFromPayloadToContract(paramsProvider: ContractParamsProvider): Promise<string | BigNumberish[]>;
readPricesFromContract(paramsProvider: ContractParamsProvider): Promise<BigNumberish[]>;
readTimestampFromContract(): Promise<number>;
}
//# sourceMappingURL=IPricesContractAdapter.d.ts.map

@@ -13,6 +13,5 @@ "use strict";

const getDataFeedValues = async (args = {}) => {
var _a, _b, _c;
const dataServiceId = (_a = args.dataServiceId) !== null && _a !== void 0 ? _a : DEFAULT_DATA_SERVICE_ID;
const aggregationAlgorithm = (_b = args.aggregationAlgorithm) !== null && _b !== void 0 ? _b : DEFAULT_AGGREGATION_ALGORITHM;
const gatewayUrls = (_c = args.gatewayUrls) !== null && _c !== void 0 ? _c : (0, data_services_urls_1.resolveDataServiceUrls)(dataServiceId);
const dataServiceId = args.dataServiceId ?? DEFAULT_DATA_SERVICE_ID;
const aggregationAlgorithm = args.aggregationAlgorithm ?? DEFAULT_AGGREGATION_ALGORITHM;
const gatewayUrls = args.gatewayUrls ?? (0, data_services_urls_1.resolveDataServiceUrls)(dataServiceId);
const dataPackagesPerFeed = await Promise.any(gatewayUrls.map((url) => getDataPackagesFromGateway(url, dataServiceId)));

@@ -24,3 +23,2 @@ const result = {};

.map((dp) => Number(dp.dataPoints[0].value));
// case for ___ALL_FEEDS___
if (plainValues.length === 0) {

@@ -37,3 +35,3 @@ continue;

if (typeof response.data === "string") {
throw new Error(`Failed to fetch data package from ${url}. Data service ID responded with: ${response.data}`);
throw new Error(`Failed to fetch data package from ${url}. Data service ID responded with: ${String(response.data)}`);
}

@@ -51,3 +49,3 @@ return response.data;

default:
throw new Error(`Unsupported aggregationAlgorithm ${aggregationAlgorithm}`);
throw new Error(`Unsupported aggregationAlgorithm ${String(aggregationAlgorithm)}`);
}

@@ -54,0 +52,0 @@ };

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

export declare const REDSTONE_DATA_SERVICES_URLS: Record<string, string[]>;
export declare const REDSTONE_DATA_SERVICES_URLS: Partial<Record<string, string[]>>;
export declare const resolveDataServiceUrls: (dataServiceId: string) => string[];
//# sourceMappingURL=data-services-urls.d.ts.map
import { RedstoneTypes } from "redstone-utils";
/** Fetches data-packages from gateway */
type FetchDataPackagesArgs = {

@@ -4,0 +3,0 @@ dataServiceId: string;

@@ -7,3 +7,3 @@ "use strict";

const fetchDataPackages = async ({ dataServiceId, gatewayUrls, }) => {
const resolvedGatewayUrls = gatewayUrls !== null && gatewayUrls !== void 0 ? gatewayUrls : (0, data_services_urls_1.resolveDataServiceUrls)(dataServiceId);
const resolvedGatewayUrls = gatewayUrls ?? (0, data_services_urls_1.resolveDataServiceUrls)(dataServiceId);
const urls = resolvedGatewayUrls.map((baseUrl) => `${baseUrl}/data-packages/latest/${dataServiceId}`);

@@ -10,0 +10,0 @@ const responseFromGateway = await redstone_utils_1.RedstoneCommon.fetchWithFallbacks({ urls });

@@ -8,5 +8,5 @@ import { BigNumber } from "ethers";

dataFeeds?: string[];
urls?: string[];
urls?: string[] | undefined;
valuesToCompare?: ValuesForDataFeeds;
historicalTimestamp?: number;
historicalTimestamp?: number | undefined;
}

@@ -17,3 +17,3 @@ export interface DataPackagesResponse {

export interface ValuesForDataFeeds {
[dataFeedId: string]: BigNumber;
[dataFeedId: string]: BigNumber | undefined;
}

@@ -23,3 +23,3 @@ export declare const getOracleRegistryState: () => Promise<RedstoneOraclesState>;

export declare const parseDataPackagesResponse: (dpResponse: {
[dataFeedId: string]: SignedDataPackagePlainObj[];
[dataFeedId: string]: SignedDataPackagePlainObj[] | undefined;
}, reqParams: DataPackagesRequestParams) => DataPackagesResponse;

@@ -41,2 +41,3 @@ export declare const getDecimalsForDataFeedId: (dataPackages: SignedDataPackagePlainObj[]) => number | undefined;

export * from "./contracts/ContractParamsProvider";
export * from "./contracts/ContractParamsProviderMock";
export * from "./contracts/IContractConnector";

@@ -46,2 +47,5 @@ export * from "./contracts/prices/IPricesContractAdapter";

export * from "./fetch-data-packages";
export * from "./simple-relayer/IPriceManagerContractAdapter";
export * from "./simple-relayer/IPriceFeedContractAdapter";
export * from "./simple-relayer/start-simple-relayer";
//# sourceMappingURL=index.d.ts.map

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

const DEFAULT_DECIMALS = 8;
const ALL_FEEDS_KEY = "___ALL_FEEDS___";
const getOracleRegistryState = async () => {
return redstone_oracles_smartweave_contracts_1.redstoneOraclesInitialState;
return await Promise.resolve(redstone_oracles_smartweave_contracts_1.redstoneOraclesInitialState);
};

@@ -43,5 +44,4 @@ exports.getOracleRegistryState = getOracleRegistryState;

const parseDataPackagesResponse = (dpResponse, reqParams) => {
var _a;
const parsedResponse = {};
const requestedDataFeedIds = (_a = reqParams.dataFeeds) !== null && _a !== void 0 ? _a : [redstone_protocol_1.consts.ALL_FEEDS_KEY];
const requestedDataFeedIds = reqParams.dataFeeds ?? [ALL_FEEDS_KEY];
for (const dataFeedId of requestedDataFeedIds) {

@@ -66,8 +66,7 @@ const dataFeedPackages = dpResponse[dataFeedId];

const getDataPackagesSortedByDeviation = (dataFeedPackages, valuesToCompare, dataFeedId) => {
var _a;
if (!valuesToCompare) {
return dataFeedPackages;
}
if (dataFeedId === redstone_protocol_1.consts.ALL_FEEDS_KEY) {
throw new Error(`Cannot sort data packages by deviation for ${redstone_protocol_1.consts.ALL_FEEDS_KEY}`);
if (dataFeedId === ALL_FEEDS_KEY) {
throw new Error(`Cannot sort data packages by deviation for ${ALL_FEEDS_KEY}`);
}

@@ -77,3 +76,3 @@ if (!valuesToCompare[dataFeedId]) {

}
const decimals = (_a = (0, exports.getDecimalsForDataFeedId)(dataFeedPackages)) !== null && _a !== void 0 ? _a : DEFAULT_DECIMALS;
const decimals = (0, exports.getDecimalsForDataFeedId)(dataFeedPackages) ?? DEFAULT_DECIMALS;
const valueToCompare = Number(ethers_1.utils.formatUnits(valuesToCompare[dataFeedId], decimals));

@@ -92,3 +91,4 @@ return sortDataPackagesByDeviationDesc(dataFeedPackages, valueToCompare);

exports.getDecimalsForDataFeedId = getDecimalsForDataFeedId;
const errToString = (e) => {
const errToString = (err) => {
const e = err;
if (e instanceof AggregateError) {

@@ -165,2 +165,3 @@ const stringifiedErrors = e.errors.reduce((prev, oneOfErrors, curIndex) => (prev += `${curIndex}: ${oneOfErrors.message}, `), "");

__exportStar(require("./contracts/ContractParamsProvider"), exports);
__exportStar(require("./contracts/ContractParamsProviderMock"), exports);
__exportStar(require("./contracts/IContractConnector"), exports);

@@ -170,2 +171,5 @@ __exportStar(require("./contracts/prices/IPricesContractAdapter"), exports);

__exportStar(require("./fetch-data-packages"), exports);
__exportStar(require("./simple-relayer/IPriceManagerContractAdapter"), exports);
__exportStar(require("./simple-relayer/IPriceFeedContractAdapter"), exports);
__exportStar(require("./simple-relayer/start-simple-relayer"), exports);
//# sourceMappingURL=index.js.map

@@ -12,3 +12,3 @@ "use strict";

uniqueSignersCount: 2,
urls,
urls: urls,
};

@@ -15,0 +15,0 @@ };

{
"name": "redstone-sdk",
"prettier": "redstone-prettier-config",
"version": "1.8.0",
"version": "1.8.2",
"main": "dist/src/index.js",

@@ -10,6 +10,8 @@ "types": "dist/src/index.d.ts",

"test": "NODE_ENV=test jest",
"build": "rm -rf dist && tsc --build",
"clean": "rm -rf dist",
"build": "yarn clean && tsc --build",
"preversion": "yarn build",
"postversion": "git commit -a -m \"build: $npm_package_name@$npm_package_version\" && git push",
"pack-package": "yarn build && cd dist && npm pack"
"pack-package": "yarn build && cd dist && npm pack",
"lint": "eslint ."
},

@@ -24,8 +26,8 @@ "dependencies": {

"devDependencies": {
"@types/jest": "^27.5.2",
"jest": "^28.1.0",
"@types/jest": "^29.5.4",
"jest": "^29.6.4",
"msw": "^0.47.4",
"ts-jest": "^28.0.3",
"typescript": "^5.1.6"
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}

@@ -5,22 +5,15 @@ import { toUtf8Bytes } from "@ethersproject/strings/lib/utf8";

import {
DataPackagesRequestParams,
getUrlsForDataServiceId,
requestRedstonePayload,
} from "../index";
import { DataPackagesRequestParams, requestRedstonePayload } from "../index";
export class ContractParamsProvider {
constructor(
public readonly requestParams: DataPackagesRequestParams,
urls?: string[]
) {
if (!urls) {
requestParams.urls = getUrlsForDataServiceId(requestParams);
}
constructor(public readonly requestParams: DataPackagesRequestParams) {}
async getPayloadHex(withPrefix = true): Promise<string> {
return (
(withPrefix ? "0x" : "") + (await this.requestPayload(this.requestParams))
);
}
async getPayloadData(): Promise<number[]> {
const payloadHex = await this.requestPayload(this.requestParams);
return Array.from(arrayify(payloadHex));
return Array.from(arrayify(await this.getPayloadHex(true)));
}

@@ -40,7 +33,8 @@

// eslint-disable-next-line @typescript-eslint/class-methods-use-this
protected async requestPayload(
requestParams: DataPackagesRequestParams
): Promise<string> {
return "0x" + (await requestRedstonePayload(requestParams));
return await requestRedstonePayload(requestParams);
}
}
export interface IContractConnector<Adapter> {
getAdapter(): Promise<Adapter>;
getBlockNumber(rpcUrl: string): Promise<number>;
waitForTransaction(txId: string): Promise<boolean>;
}
import { ContractParamsProvider } from "../ContractParamsProvider";
import { BigNumberish } from "ethers";

@@ -8,3 +9,3 @@ export interface IPricesContractAdapter {

paramsProvider: ContractParamsProvider
): Promise<number[]>;
): Promise<BigNumberish[]>;

@@ -15,3 +16,3 @@ // Reads on-chain the returned by paramsProvider RedStone payload data and writes aggregated price values

paramsProvider: ContractParamsProvider
): Promise<string | number[]>;
): Promise<string | BigNumberish[]>;

@@ -22,3 +23,3 @@ // Reads the lastly written to the contract's storage aggregated price values for the feeds passed through the

paramsProvider: ContractParamsProvider
): Promise<number[]>;
): Promise<BigNumberish[]>;

@@ -25,0 +26,0 @@ // Reads the timestamp of the lastly written values to the contract's storage.

@@ -59,3 +59,5 @@ import axios from "axios";

throw new Error(
`Failed to fetch data package from ${url}. Data service ID responded with: ${response.data}`
`Failed to fetch data package from ${url}. Data service ID responded with: ${String(
response.data
)}`
);

@@ -80,5 +82,5 @@ }

throw new Error(
`Unsupported aggregationAlgorithm ${aggregationAlgorithm}`
`Unsupported aggregationAlgorithm ${String(aggregationAlgorithm)}`
);
}
};
const DEMO_URL = "https://d33trozg86ya9x.cloudfront.net";
export const REDSTONE_DATA_SERVICES_URLS: Record<string, string[]> = {
export const REDSTONE_DATA_SERVICES_URLS: Partial<Record<string, string[]>> = {
"redstone-primary-prod": [

@@ -5,0 +5,0 @@ "https://oracle-gateway-1.a.redstone.finance",

import axios from "axios";
import { BigNumber, utils } from "ethers";
import {
redstoneOraclesInitialState,
RedstoneOraclesState,
redstoneOraclesInitialState,
} from "redstone-oracles-smartweave-contracts";

@@ -12,3 +12,2 @@ import {

SignedDataPackagePlainObj,
consts,
} from "redstone-protocol";

@@ -19,2 +18,3 @@ import { SafeNumber } from "redstone-utils";

const DEFAULT_DECIMALS = 8;
const ALL_FEEDS_KEY = "___ALL_FEEDS___";

@@ -25,5 +25,5 @@ export interface DataPackagesRequestParams {

dataFeeds?: string[];
urls?: string[];
urls?: string[] | undefined;
valuesToCompare?: ValuesForDataFeeds;
historicalTimestamp?: number;
historicalTimestamp?: number | undefined;
}

@@ -36,3 +36,3 @@

export interface ValuesForDataFeeds {
[dataFeedId: string]: BigNumber;
[dataFeedId: string]: BigNumber | undefined;
}

@@ -42,3 +42,3 @@

async (): Promise<RedstoneOraclesState> => {
return redstoneOraclesInitialState;
return await Promise.resolve(redstoneOraclesInitialState);
};

@@ -60,3 +60,3 @@

dpResponse: {
[dataFeedId: string]: SignedDataPackagePlainObj[];
[dataFeedId: string]: SignedDataPackagePlainObj[] | undefined;
},

@@ -67,3 +67,3 @@ reqParams: DataPackagesRequestParams

const requestedDataFeedIds = reqParams.dataFeeds ?? [consts.ALL_FEEDS_KEY];
const requestedDataFeedIds = reqParams.dataFeeds ?? [ALL_FEEDS_KEY];

@@ -112,5 +112,5 @@ for (const dataFeedId of requestedDataFeedIds) {

if (dataFeedId === consts.ALL_FEEDS_KEY) {
if (dataFeedId === ALL_FEEDS_KEY) {
throw new Error(
`Cannot sort data packages by deviation for ${consts.ALL_FEEDS_KEY}`
`Cannot sort data packages by deviation for ${ALL_FEEDS_KEY}`
);

@@ -126,3 +126,3 @@ }

const valueToCompare = Number(
utils.formatUnits(valuesToCompare[dataFeedId], decimals)
utils.formatUnits(valuesToCompare[dataFeedId]!, decimals)
);

@@ -150,5 +150,6 @@

const errToString = (e: any): string => {
const errToString = (err: unknown): string => {
const e = err as Error;
if (e instanceof AggregateError) {
const stringifiedErrors = e.errors.reduce(
const stringifiedErrors = (e.errors as Error[]).reduce(
(prev, oneOfErrors, curIndex) =>

@@ -170,3 +171,3 @@ (prev += `${curIndex}: ${oneOfErrors.message}, `),

return await Promise.any(promises);
} catch (e: any) {
} catch (e: unknown) {
const errMessage = `Request failed ${JSON.stringify({

@@ -192,3 +193,5 @@ reqParams,

axios
.get([url].concat(pathComponents).join("/"))
.get<Record<string, SignedDataPackagePlainObj[]>>(
[url].concat(pathComponents).join("/")
)
.then((response) => parseDataPackagesResponse(response.data, reqParams))

@@ -250,2 +253,3 @@ );

export * from "./contracts/ContractParamsProvider";
export * from "./contracts/ContractParamsProviderMock";
export * from "./contracts/IContractConnector";

@@ -255,1 +259,4 @@ export * from "./contracts/prices/IPricesContractAdapter";

export * from "./fetch-data-packages";
export * from "./simple-relayer/IPriceManagerContractAdapter";
export * from "./simple-relayer/IPriceFeedContractAdapter";
export * from "./simple-relayer/start-simple-relayer";

@@ -16,3 +16,3 @@ import { utils } from "ethers";

uniqueSignersCount: 2,
urls,
urls: urls!,
};

@@ -19,0 +19,0 @@ };

{
"compilerOptions": {
"lib": ["es2021"],
"target": "es2018",
"allowJs": true,
"composite": true,
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"outDir": "dist",
"removeComments": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"allowJs": true,
"declaration": true,
"declarationMap": true,
"composite": true,
"incremental": true
"target": "ES2021",
},
"include": ["./src", "./test"],
"include": [
"./src",
"./test"
],
"references": [
{
"path": "../protocol"
"path": "../protocol/tsconfig.build.json"
},
{
"path": "../oracles-smartweave-contracts"
"path": "../oracles-smartweave-contracts/tsconfig.build.json"
},
{
"path": "../utils"
"path": "../utils/tsconfig.build.json"
}
]
}
}

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