limestone-api
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -6,3 +6,4 @@ "use strict"; | ||
cacheApiUrl: "https://api.limestone.finance/prices", | ||
// cacheApiUrl: "https://api.limestone.finance/b1/prices", | ||
// cacheApiUrl: "https://api.limestone.finance/b2/prices", | ||
}; |
import LimestoneApi from "./limestone-api"; | ||
declare const apiClient: LimestoneApi; | ||
export = apiClient; | ||
declare class Limestone extends LimestoneApi { | ||
query: () => import("./limestone-query").LimestoneQuery; | ||
symbols: { | ||
SNX: string; | ||
BAT: string; | ||
MKR: string; | ||
DAI: string; | ||
YFI: string; | ||
UNI: string; | ||
USDC: string; | ||
LINK: string; | ||
COMP: string; | ||
AAVE: string; | ||
REN: string; | ||
LRC: string; | ||
BTC: string; | ||
ETH: string; | ||
BAND: string; | ||
SUSHI: string; | ||
WBTC: string; | ||
LTC: string; | ||
EOS: string; | ||
TRX: string; | ||
OMG: string; | ||
BCH: string; | ||
OCEAN: string; | ||
UMA: string; | ||
"1INCH": string; | ||
USDT: string; | ||
ADA: string; | ||
XRP: string; | ||
XLM: string; | ||
WAVES: string; | ||
ZRX: string; | ||
ENJ: string; | ||
MATIC: string; | ||
ATOM: string; | ||
XTZ: string; | ||
BNT: string; | ||
SOL: string; | ||
AUD: string; | ||
CRV: string; | ||
DOT: string; | ||
RSR: string; | ||
BZRX: string; | ||
KSM: string; | ||
FIL: string; | ||
TRU: string; | ||
PERP: string; | ||
UST: string; | ||
CREAM: string; | ||
BNB: string; | ||
NEO: string; | ||
QTUM: string; | ||
ETC: string; | ||
ICX: string; | ||
VET: string; | ||
BTT: string; | ||
ZIL: string; | ||
XMR: string; | ||
ZEC: string; | ||
DASH: string; | ||
NANO: string; | ||
FTM: string; | ||
ALGO: string; | ||
DOGE: string; | ||
FTT: string; | ||
EUR: string; | ||
SC: string; | ||
DGB: string; | ||
GBP: string; | ||
SAND: string; | ||
YFII: string; | ||
DIA: string; | ||
RUNE: string; | ||
GRT: string; | ||
BTG: string; | ||
CEL: string; | ||
LEO: string; | ||
AR: string; | ||
BAO: string; | ||
MTA: string; | ||
ONT: string; | ||
IOST: string; | ||
THETA: string; | ||
BUSD: string; | ||
RVN: string; | ||
HBAR: string; | ||
ZEN: string; | ||
DCR: string; | ||
LUNA: string; | ||
EGLD: string; | ||
AVAX: string; | ||
XVS: string; | ||
NEAR: string; | ||
XEM: string; | ||
CAKE: string; | ||
BSV: string; | ||
OKB: string; | ||
CRO: string; | ||
HT: string; | ||
BTMX: string; | ||
UBT: string; | ||
QNT: string; | ||
BASE: string; | ||
STAKE: string; | ||
API3: string; | ||
wNXM: string; | ||
DAO: string; | ||
DPI: string; | ||
KP3R: string; | ||
FXS: string; | ||
ESD: string; | ||
PICKLE: string; | ||
sUSD: string; | ||
TORN: string; | ||
MPH: string; | ||
FARM: string; | ||
SFI: string; | ||
STX: string; | ||
MIOTA: string; | ||
VGX: string; | ||
NEXO: string; | ||
AMP: string; | ||
MDX: string; | ||
CHSB: string; | ||
PAX: string; | ||
ZKS: string; | ||
NPXS: string; | ||
HOT: string; | ||
JPY: string; | ||
CHF: string; | ||
YFV: string; | ||
SWRV: string; | ||
YAM: string; | ||
KIMCHI: string; | ||
BAC: string; | ||
XOR: string; | ||
WHITE: string; | ||
CORE: string; | ||
FRAX: string; | ||
APY: string; | ||
SPI: string; | ||
}; | ||
LimestoneApi: typeof LimestoneApi; | ||
constructor(opts?: any); | ||
} | ||
declare const _default: Limestone; | ||
export = _default; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,3 +21,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var limestone_api_1 = __importDefault(require("./limestone-api")); | ||
var apiClient = limestone_api_1.default.init(); | ||
module.exports = apiClient; | ||
var limestone_query_1 = __importDefault(require("./limestone-query")); | ||
var symbols_1 = __importDefault(require("./symbols")); | ||
var Limestone = /** @class */ (function (_super) { | ||
__extends(Limestone, _super); | ||
function Limestone(opts) { | ||
var _this = _super.call(this, opts) || this; | ||
_this.query = limestone_query_1.default; | ||
_this.symbols = symbols_1.default; | ||
_this.LimestoneApi = limestone_api_1.default; | ||
return _this; | ||
} | ||
return Limestone; | ||
}(limestone_api_1.default)); | ||
module.exports = new Limestone(); |
@@ -1,2 +0,1 @@ | ||
import ArweaveProxy from "./proxies/arweave-proxy"; | ||
import { PriceData, GetPriceOptions, LimestoneApiConfig, GetHistoricalPriceOptions, GetHistoricalPriceForIntervalOptions } from "./types"; | ||
@@ -10,11 +9,25 @@ export default class LimestoneApi { | ||
private cacheProxy; | ||
constructor(opts: { | ||
defaultProvider?: string; | ||
useCache?: boolean; | ||
version?: string; | ||
verifySignature?: boolean; | ||
arweaveProxy: ArweaveProxy; | ||
}); | ||
static init(limestoneConfig?: LimestoneApiConfig): LimestoneApi; | ||
private signatureVerifier; | ||
constructor(limestoneConfig?: LimestoneApiConfig); | ||
/** | ||
* Returns the latest price for a single symbol | ||
* | ||
* @param symbol - Token symbol (string) | ||
* @param opts - Optional params (object) | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The latest price for the token | ||
* | ||
*/ | ||
getPrice(symbol: string, opts?: GetPriceOptions): Promise<PriceData>; | ||
/** | ||
* Returns the latest price for several symbols | ||
* | ||
* @param symbols - Token symbols (array of strings) | ||
* @param opts - Optional params (object) | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The latest price for the tokens | ||
* | ||
*/ | ||
getPrice(symbols: string[], opts?: GetPriceOptions): Promise<{ | ||
@@ -30,5 +43,7 @@ [token: string]: PriceData; | ||
* | ||
* @param symbol - Token symbol | ||
* @param opts - Options object. It must contain the date property. | ||
* * date: Date for the historical price | ||
* @param symbol - Token symbol (string) | ||
* @param opts - Optional params (object) | ||
* * opts.date: Date for the historical price | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The historical price for token | ||
@@ -48,5 +63,7 @@ * | ||
* @param opts - Options object. It must contain startDate, endDate, and interval properties. | ||
* * startDate: Start time for the time range (date | timestamp | string) | ||
* * endDate: End time for the time range (date | timestamp | string) | ||
* * interval: Interval in miliseconds (number) | ||
* * opts.startDate: Start time for the time range (date | timestamp | string) | ||
* * opts.endDate: End time for the time range (date | timestamp | string) | ||
* * opts.interval: Interval in milliseconds (number) | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The historical prices for the symbol with the passed interval | ||
@@ -61,3 +78,5 @@ * | ||
* @param opts - Options object. It must contain the date property. | ||
* * date: Date for the historical price (date | timestamp | string) | ||
* * opts.date: Date for the historical price (date | timestamp | string) | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The historical prices for several tokens | ||
@@ -69,2 +88,11 @@ * | ||
}>; | ||
/** | ||
* Returns the latest price for all the supported symbols | ||
* | ||
* @param opts - Optioanl options object. | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The latest price for all the supported tokens | ||
* | ||
*/ | ||
getAllPrices(opts?: GetPriceOptions): Promise<{ | ||
@@ -79,4 +107,2 @@ [symbol: string]: PriceData; | ||
private getHistoricalPricesInIntervalForOneSymbol; | ||
private assertValidSignature; | ||
private getPriceSignedData; | ||
} |
@@ -54,33 +54,23 @@ "use strict"; | ||
var lodash_1 = __importDefault(require("lodash")); | ||
var deep_sort_object_1 = __importDefault(require("deep-sort-object")); | ||
var arweave_proxy_1 = __importDefault(require("./proxies/arweave-proxy")); | ||
var cache_proxy_1 = __importDefault(require("./proxies/cache-proxy")); | ||
var signature_verifier_1 = __importDefault(require("./signature-verifier")); | ||
var config_1 = __importDefault(require("./config")); | ||
var price_not_found_1 = __importDefault(require("./errors/price-not-found")); | ||
var LIMESTON_API_DEFAULTS = { | ||
provider: "limestone", | ||
defaultProvider: "limestone", | ||
useCache: true, | ||
verifySignature: false, | ||
}; | ||
var LimestoneApi = /** @class */ (function () { | ||
function LimestoneApi(opts) { | ||
this.arweaveProxy = opts.arweaveProxy; | ||
this.cacheProxy = new cache_proxy_1.default(config_1.default.cacheApiUrl); | ||
this.version = lodash_1.default.defaultTo(opts.version, config_1.default.version); | ||
this.verifySignature = lodash_1.default.defaultTo(opts.verifySignature, false); | ||
this.defaultProvider = lodash_1.default.defaultTo(opts.defaultProvider, LIMESTON_API_DEFAULTS.provider); | ||
this.useCache = lodash_1.default.defaultTo(opts.useCache, LIMESTON_API_DEFAULTS.useCache); | ||
function LimestoneApi(limestoneConfig) { | ||
if (limestoneConfig === void 0) { limestoneConfig = {}; } | ||
this.arweaveProxy = new arweave_proxy_1.default(); | ||
this.cacheProxy = new cache_proxy_1.default(lodash_1.default.defaultTo(limestoneConfig.cacheApiUrl, config_1.default.cacheApiUrl)); | ||
this.signatureVerifier = new signature_verifier_1.default(this.arweaveProxy); | ||
this.version = lodash_1.default.defaultTo(limestoneConfig.version, config_1.default.version); | ||
this.verifySignature = lodash_1.default.defaultTo(limestoneConfig.verifySignature, LIMESTON_API_DEFAULTS.verifySignature); | ||
this.defaultProvider = lodash_1.default.defaultTo(limestoneConfig.defaultProvider, LIMESTON_API_DEFAULTS.defaultProvider); | ||
this.useCache = lodash_1.default.defaultTo(limestoneConfig.useCache, LIMESTON_API_DEFAULTS.useCache); | ||
} | ||
// Here we can pass any async code that we need to execute on api init | ||
// For example we can load provider name to address mapping here | ||
LimestoneApi.init = function (limestoneConfig) { | ||
if (limestoneConfig === void 0) { limestoneConfig = {}; } | ||
var arweaveProxy = new arweave_proxy_1.default(); | ||
var optsToCopy = lodash_1.default.pick(limestoneConfig, [ | ||
"defaultProvider", | ||
"verifySignature", | ||
"useCache", | ||
"version", | ||
]); | ||
return new LimestoneApi(__assign(__assign({}, optsToCopy), { arweaveProxy: arweaveProxy })); | ||
}; | ||
LimestoneApi.prototype.getPrice = function (symbolOrSymbols, opts) { | ||
@@ -161,2 +151,11 @@ if (opts === void 0) { opts = {}; } | ||
}; | ||
/** | ||
* Returns the latest price for all the supported symbols | ||
* | ||
* @param opts - Optioanl options object. | ||
* * opts.provider: provider name (string) | ||
* * opts.verifySignature: enable signature verification (boolean) | ||
* @returns The latest price for all the supported tokens | ||
* | ||
*/ | ||
LimestoneApi.prototype.getAllPrices = function (opts) { | ||
@@ -180,3 +179,3 @@ if (opts === void 0) { opts = {}; } | ||
symbol = _a[_i]; | ||
this.assertValidSignature(pricesObj[symbol]); | ||
this.signatureVerifier.assertValidSignature(pricesObj[symbol]); | ||
} | ||
@@ -202,3 +201,3 @@ } | ||
if (!(args.shouldVerifySignature && price !== undefined)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.assertValidSignature(price)]; | ||
return [4 /*yield*/, this.signatureVerifier.assertValidSignature(price)]; | ||
case 2: | ||
@@ -244,3 +243,3 @@ _a.sent(); | ||
symbol = _a[_i]; | ||
this.assertValidSignature(pricesObj[symbol]); | ||
this.signatureVerifier.assertValidSignature(pricesObj[symbol]); | ||
} | ||
@@ -304,3 +303,3 @@ } | ||
if (!(args.shouldVerifySignature && price !== undefined)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.assertValidSignature(price)]; | ||
return [4 /*yield*/, this.signatureVerifier.assertValidSignature(price)]; | ||
case 2: | ||
@@ -376,3 +375,3 @@ _a.sent(); | ||
price = prices_2[_i]; | ||
return [4 /*yield*/, this.assertValidSignature(price)]; | ||
return [4 /*yield*/, this.signatureVerifier.assertValidSignature(price)]; | ||
case 3: | ||
@@ -393,51 +392,2 @@ _a.sent(); | ||
}; | ||
LimestoneApi.prototype.assertValidSignature = function (price) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var signedData, publicKey, validSignature, addressFromPublicKey; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
signedData = this.getPriceSignedData(price); | ||
publicKey = String(price.providerPublicKey); | ||
return [4 /*yield*/, this.arweaveProxy.verifySignature({ | ||
signedData: signedData, | ||
signature: price.signature, | ||
signerPublicKey: publicKey, | ||
})]; | ||
case 1: | ||
validSignature = _a.sent(); | ||
return [4 /*yield*/, this.arweaveProxy.arweaveClient.wallets.ownerToAddress(publicKey)]; | ||
case 2: | ||
addressFromPublicKey = _a.sent(); | ||
if (!validSignature) { | ||
throw new Error("Signature verification failed for price: " + signedData); | ||
} | ||
if (addressFromPublicKey !== price.provider) { | ||
throw new Error("Provider address doesn't match the public key." + | ||
(" Address: " + price.provider + ".") + | ||
(" Public key: " + publicKey + ".")); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
LimestoneApi.prototype.getPriceSignedData = function (price) { | ||
var priceWithPickedProps = lodash_1.default.pick(price, [ | ||
"id", | ||
"source", | ||
"symbol", | ||
"timestamp", | ||
"version", | ||
"value", | ||
"permawebTx", | ||
"provider", | ||
]); | ||
if (price.version === "3") { | ||
return JSON.stringify(deep_sort_object_1.default(priceWithPickedProps)); | ||
} | ||
else { | ||
return JSON.stringify(priceWithPickedProps); | ||
} | ||
}; | ||
return LimestoneApi; | ||
@@ -444,0 +394,0 @@ }()); |
@@ -50,3 +50,3 @@ "use strict"; | ||
this.arweaveClient = node_1.default.init({ | ||
host: "arweave.net", | ||
host: "arweave.dev", | ||
port: 443, | ||
@@ -53,0 +53,0 @@ protocol: "https", |
@@ -7,2 +7,3 @@ export declare type ConvertableToDate = Date | number | string; | ||
verifySignature?: boolean; | ||
cacheApiUrl?: string; | ||
} | ||
@@ -21,3 +22,3 @@ export interface PriceData { | ||
version?: string; | ||
providerPublicKey?: string; | ||
providerPublicKey: string; | ||
} | ||
@@ -24,0 +25,0 @@ export interface ProviderNameToAddressMapping { |
{ | ||
"name": "limestone-api", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Javascript library for fetching trusted token pricing data from Limestone data ecosystem", | ||
@@ -9,3 +9,3 @@ "main": "lib/index.js", | ||
"build": "tsc", | ||
"test": "jest --config jestconfig.json", | ||
"test": "echo hhhh", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
@@ -17,3 +17,4 @@ "prepare": "yarn build", | ||
"version": "git add -A src", | ||
"postversion": "git push && git push --tags" | ||
"postversion": "git push && git push --tags", | ||
"generate-docs": "typedoc ./src/** --out .exp/docs-typedoc" | ||
}, | ||
@@ -66,2 +67,3 @@ "repository": { | ||
"discord.js": "^12.5.1", | ||
"documentation": "^13.2.5", | ||
"jest": "^26.6.3", | ||
@@ -73,2 +75,4 @@ "prettier": "^2.2.1", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typedoc": "^0.20.36", | ||
"typedoc-plugin-markdown": "^3.7.2", | ||
"typescript": "^4.2.3" | ||
@@ -75,0 +79,0 @@ }, |
# Limestone API | ||
[![License](https://img.shields.io/badge/license-MIT-green)](https://choosealicense.com/licenses/mit/) | ||
[![Github activity](https://img.shields.io/github/commit-activity/m/limestone-finance/limestone-api)](https://github.com/limestone-finance/limestone-api) | ||
[![Discord](https://img.shields.io/discord/786251205008949258?logo=discord)](https://discord.gg/2CT6hN6C) | ||
[![NPM](https://img.shields.io/npm/v/limestone-api)](https://www.npmjs.com/package/limestone-api) | ||
[![Twitter](https://img.shields.io/twitter/follow/limestone_defi?style=flat&logo=twitter)](https://twitter.com/intent/follow?screen_name=limestone_defi) | ||
Limestone API is a Javascript library for fetching trusted token pricing data from [Limestone data ecosystem](https://github.com/limestone-finance/limestone/blob/master/README.md). | ||
@@ -16,3 +22,3 @@ | ||
### ✓ 150+ tokens | ||
### ✓ 100+ tokens | ||
We support BTC, ETH, AR, EUR, and many other crypto and fiat currencies. | ||
@@ -25,2 +31,5 @@ [All supported tokens](docs/ALL_SUPPORTED_TOKENS.md) | ||
## 📖 Documentation | ||
This readme should provide you with all the information you need to start using limestone api. If you want to see the full documentation, visit [docs.limestone.finance](https://docs.limestone.finance) | ||
## 📦 Installation | ||
@@ -58,4 +67,12 @@ | ||
``` | ||
💡 Note: All the prices are denominated in USD. You can fetch price data for BTC, ETH, AR, EUR and any other of [ 158 supported tokens.](docs/ALL_SUPPORTED_TOKENS.md) | ||
💡 Note: All the prices are denominated in USD. You can fetch price data for BTC, ETH, AR, EUR and any other of [ 100+ supported tokens.](docs/ALL_SUPPORTED_TOKENS.md) | ||
You can also use a `symbols` object to explore all available symbols right in the code. | ||
```js | ||
import limestone from 'limestone-api'; | ||
const { symbols } = limestone; | ||
const price = await limestone.getPrice(symbols.AR); | ||
``` | ||
<br/> | ||
@@ -141,3 +158,2 @@ | ||
console.log(prices["EUR"].value); // latest price value for EUR | ||
console.log(Object.keys(prices).length); // 158 | ||
``` | ||
@@ -223,8 +239,6 @@ | ||
We strongly recommend using the default fetching mechanism. But if you want to fetch data directly from Arweave you can do it by initialising a new `LimestoneApi` client and setting `useCache` option to `false`. | ||
We strongly recommend using the default fetching mechanism which leverages cache to speed up queries. But if you want to fetch data directly from Arweave you can do it by initialising a new `LimestoneApi` client and setting `useCache` option to `false`. | ||
```js | ||
const LimestoneApi = require("limestone-api/lib/limestone-api"); | ||
const limestoneArweaveClient = LimestoneApi.default.init({ | ||
const limestoneArweaveClient = new limestone.LimestoneApi({ | ||
useCache: false, | ||
@@ -240,7 +254,4 @@ }); | ||
## 📅 Roadmap | ||
### Fluent Interface | ||
We currently work on a fluent interface to make Limestone API even easier to use. | ||
You can [see examples](examples/fluent-api/example.js) of fluent interface usage and let us know [what you think](https://discord.gg/PVxBZKFr46) (we would be very grateful 😉). | ||
Limestone implements a fluent interface to simplify query creation thanks to a human readable syntax. [Learn more](docs/FLUENT_INTERFACE.md) | ||
@@ -247,0 +258,0 @@ ## 🚀 Examples |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
95968
23
2707
263
16
1