UNPKG

@tracer-protocol/pools-js

Version:

Javascript library for interacting with Tracer's Perpetual Pools

66 lines (58 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _tinyTypedEmitter = require("tiny-typed-emitter"); var _entities = require("../entities"); var _constants = require("../utils/constants"); class MultiplePoolWatcher extends _tinyTypedEmitter.TypedEmitter { constructor(args) { super(); this.nodeUrl = args.nodeUrl; this.poolAddresses = args.poolAddresses; this.chainId = args.chainId; this.commitmentWindowBuffer = args.commitmentWindowBuffer; this.ignoreEvents = args.ignoreEvents; } async initializePoolWatchers() { return Promise.all(this.poolAddresses.map(async poolAddress => { const poolWatcher = new _entities.PoolWatcher({ nodeUrl: this.nodeUrl, commitmentWindowBuffer: this.commitmentWindowBuffer, // calculate pool state 10 seconds before chainId: this.chainId, poolAddress, ignoreEvents: this.ignoreEvents }); await poolWatcher.initializeWatchedPool(); poolWatcher.startWatchingPool(); poolWatcher.on(_constants.EVENT_NAMES.COMMITMENT_WINDOW_ENDING, state => { this.emit(_constants.EVENT_NAMES.COMMITMENT_WINDOW_ENDING, { ...state, poolAddress }); // forwards event }); poolWatcher.on(_constants.EVENT_NAMES.COMMITMENT_WINDOW_ENDED, () => { this.emit(_constants.EVENT_NAMES.COMMITMENT_WINDOW_ENDED, { poolAddress }); // forwards event }); poolWatcher.on(_constants.EVENT_NAMES.COMMIT, commitData => { this.emit(_constants.EVENT_NAMES.COMMIT, { ...commitData, poolAddress }); // forwards event }); poolWatcher.on(_constants.EVENT_NAMES.UPKEEP, data => { this.emit(_constants.EVENT_NAMES.UPKEEP, { ...data, poolAddress }); // forwards event }); poolWatcher.on(_constants.EVENT_NAMES.COMMITS_EXECUTED, data => { this.emit(_constants.EVENT_NAMES.COMMITS_EXECUTED, { ...data, poolAddress }); // forwards event }); })); } } exports.default = MultiplePoolWatcher;