UNPKG

@dolomite-exchange/dolomite-margin

Version:

Ethereum Smart Contracts and TypeScript library used for the DolomiteMargin trading protocol

50 lines 2.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChainlinkPriceOracleV1 = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); class ChainlinkPriceOracleV1 { constructor(contracts) { this.contracts = contracts; } // ============ Admin ============ async ownerInsertOrUpdateOracleToken(token, tokenDecimals, chainlinkAggregator, tokenPair, options) { return this.contracts.callContractFunction(this.contracts.chainlinkPriceOracleV1.methods.ownerInsertOrUpdateOracleToken(token, tokenDecimals, chainlinkAggregator, tokenPair), options); } async ownerSetStalenessThreshold(stalenessThreshold, options) { return this.contracts.callContractFunction(this.contracts.chainlinkPriceOracleV1.methods.ownerSetStalenessThreshold(stalenessThreshold.toFixed()), options); } // ============ Getters ============ async getStalenessThreshold(options) { const stalenessThreshold = await this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.stalenessThreshold(), options); return new bignumber_js_1.default(stalenessThreshold); } async getPrice(token, options) { const price = await this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.getPrice(token), options); return new bignumber_js_1.default(price.value); } async getAggregatorByToken(token, options) { return this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.getAggregatorByToken(token), options); } async getTokenDecimalsByToken(token, options) { const decimals = await this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.getDecimalsByToken(token), options); return Number.parseInt(decimals, 10); } /** * @return 0 address for USD, non-zero address representing another token otherwise. */ async getCurrencyPairingByToken(token, options) { return this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.getTokenPairByToken(token), options); } /** * @return Standardizes `value` to have `ONE_DOLLAR` - `tokenDecimals` number of decimals. */ async standardizeNumberOfDecimals(tokenDecimals, value, valueDecimals, options) { const valueString = await this.contracts.callConstantContractFunction(this.contracts.chainlinkPriceOracleV1.methods.standardizeNumberOfDecimals(tokenDecimals, value.toFixed(), valueDecimals), options); return new bignumber_js_1.default(valueString); } } exports.ChainlinkPriceOracleV1 = ChainlinkPriceOracleV1; //# sourceMappingURL=ChainlinkPriceOracleV1.js.map