UNPKG

@volare.finance/volare.js

Version:
64 lines 2.59 kB
"use strict"; /** * @file Oracle.v2.ts * @author astra <astra@volare.finance> * @date 2022 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OracleV2 = void 0; const tslib_1 = require("tslib"); const utils_js_1 = require("@volare.finance/utils.js"); const ethers_1 = require("ethers"); const OracleV2_json_1 = require("../artifacts/OracleV2.json"); const protocols_1 = require("./protocols"); class OracleV2 extends utils_js_1.Provider { static ABI() { return OracleV2_json_1.abi; } static GetExpiryPrice(oracle, asset, expiry) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contract = new ethers_1.Contract(oracle, OracleV2.ABI(), OracleV2.provider); const price = yield contract.getExpiryPrice(asset, expiry); return (0, utils_js_1.$float)(price, protocols_1.USD_DECIMALS); }); } static GetPrice(oracle, asset) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contract = new ethers_1.Contract(oracle, OracleV2.ABI(), OracleV2.provider); const price = yield contract.getPrice(asset); return (0, utils_js_1.$float)(price, protocols_1.USD_DECIMALS); }); } constructor(address, endpoint) { super(endpoint); this.contract = new ethers_1.Contract(address, OracleV2.ABI(), this.provider); } /** * @notice get a live asset price from the asset's pricer contract * @param asset asset address * @return price scaled by 1e8, denominated in USD * e.g. 17568900000 => 175.689 USD */ getPrice(asset) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { const price = yield ((_a = this.contract) === null || _a === void 0 ? void 0 : _a.getPrice(asset)); return (0, utils_js_1.$float)(price, protocols_1.USD_DECIMALS); }); } /** * @notice get the asset price at specific expiry timestamp * @param asset asset address * @param expiryTimestamp expiry timestamp * @return price scaled by 1e8, denominated in USD */ getExpiryPrice(asset, expiryTimestamp) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { const price = yield ((_a = this.contract) === null || _a === void 0 ? void 0 : _a.getExpiryPrice(asset, expiryTimestamp)); return (0, utils_js_1.$float)(price, protocols_1.USD_DECIMALS); }); } } exports.OracleV2 = OracleV2; //# sourceMappingURL=OracleV2.js.map