@atomiqlabs/chain-evm 1.0.0-dev.50 → 1.0.0-dev.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chains/botanix/BotanixChainType.d.ts +1 -2
- package/dist/chains/botanix/BotanixInitializer.js +1 -4
- package/dist/chains/citrea/CitreaChainType.d.ts +1 -2
- package/dist/chains/citrea/CitreaInitializer.js +1 -4
- package/dist/evm/ReconnectingWebSocketProvider.d.ts +18 -0
- package/dist/evm/ReconnectingWebSocketProvider.js +65 -0
- package/dist/evm/SocketProvider.d.ts +110 -0
- package/dist/evm/SocketProvider.js +322 -0
- package/dist/evm/WebSocketProviderWithRetries.d.ts +15 -0
- package/dist/evm/WebSocketProviderWithRetries.js +19 -0
- package/dist/evm/events/EVMChainEvents.js +2 -0
- package/dist/evm/events/EVMChainEventsBrowser.d.ts +18 -2
- package/dist/evm/events/EVMChainEventsBrowser.js +118 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/chains/botanix/BotanixChainType.ts +1 -2
- package/src/chains/botanix/BotanixInitializer.ts +1 -4
- package/src/chains/citrea/CitreaChainType.ts +1 -2
- package/src/chains/citrea/CitreaInitializer.ts +1 -4
- package/src/evm/ReconnectingWebSocketProvider.ts +82 -0
- package/src/evm/SocketProvider.ts +353 -0
- package/src/evm/WebSocketProviderWithRetries.ts +27 -0
- package/src/evm/events/EVMChainEvents.ts +1 -0
- package/src/evm/events/EVMChainEventsBrowser.ts +148 -15
- package/src/index.ts +2 -1
- package/dist/evm/events/EVMChainEventsBrowserWS.d.ts +0 -66
- package/dist/evm/events/EVMChainEventsBrowserWS.js +0 -264
- package/src/evm/events/EVMChainEventsBrowserWS.ts +0 -354
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ChainEvents, ClaimEvent, EventListener, InitializeEvent, RefundEvent, SpvVaultClaimEvent, SpvVaultCloseEvent, SpvVaultDepositEvent, SpvVaultFrontEvent, SpvVaultOpenEvent } from "@atomiqlabs/base";
|
|
2
|
-
import { IClaimHandler } from "../swaps/handlers/claim/ClaimHandlers";
|
|
3
|
-
import { EVMSwapData } from "../swaps/EVMSwapData";
|
|
4
|
-
import { Block, EventFilter, Log, WebSocketProvider } from "ethers";
|
|
5
|
-
import { EVMSwapContract } from "../swaps/EVMSwapContract";
|
|
6
|
-
import { EVMSpvVaultContract } from "../spv_swap/EVMSpvVaultContract";
|
|
7
|
-
import { EVMChainInterface } from "../chain/EVMChainInterface";
|
|
8
|
-
import { TypedEventLog } from "../typechain/common";
|
|
9
|
-
import { EscrowManager } from "../swaps/EscrowManagerTypechain";
|
|
10
|
-
import { SpvVaultManager } from "../spv_swap/SpvVaultContractTypechain";
|
|
11
|
-
import { EVMTxTrace } from "../chain/modules/EVMTransactions";
|
|
12
|
-
type AtomiqTypedEvent = (TypedEventLog<EscrowManager["filters"]["Initialize" | "Refund" | "Claim"]> | TypedEventLog<SpvVaultManager["filters"]["Opened" | "Deposited" | "Fronted" | "Claimed" | "Closed"]>);
|
|
13
|
-
/**
|
|
14
|
-
* EVM on-chain event handler for front-end systems without access to fs, uses WS or long-polling to subscribe, might lose
|
|
15
|
-
* out on some events if the network is unreliable, front-end systems should take this into consideration and not
|
|
16
|
-
* rely purely on events
|
|
17
|
-
*/
|
|
18
|
-
export declare class EVMChainEventsBrowserWS implements ChainEvents<EVMSwapData> {
|
|
19
|
-
protected readonly listeners: EventListener<EVMSwapData>[];
|
|
20
|
-
protected readonly provider: WebSocketProvider;
|
|
21
|
-
protected readonly chainInterface: EVMChainInterface;
|
|
22
|
-
protected readonly evmSwapContract: EVMSwapContract;
|
|
23
|
-
protected readonly evmSpvVaultContract: EVMSpvVaultContract<any>;
|
|
24
|
-
protected readonly logger: import("../../utils/Utils").LoggerType;
|
|
25
|
-
protected readonly spvVaultContractLogFilter: EventFilter;
|
|
26
|
-
protected readonly swapContractLogFilter: EventFilter;
|
|
27
|
-
protected unconfirmedEventQueue: AtomiqTypedEvent[];
|
|
28
|
-
protected stopped: boolean;
|
|
29
|
-
constructor(chainInterface: EVMChainInterface, evmSwapContract: EVMSwapContract, evmSpvVaultContract: EVMSpvVaultContract<any>);
|
|
30
|
-
findInitSwapData(call: EVMTxTrace, escrowHash: string, claimHandler: IClaimHandler<any, any>): EVMSwapData;
|
|
31
|
-
/**
|
|
32
|
-
* Returns async getter for fetching on-demand initialize event swap data
|
|
33
|
-
*
|
|
34
|
-
* @param event
|
|
35
|
-
* @param claimHandler
|
|
36
|
-
* @private
|
|
37
|
-
* @returns {() => Promise<EVMSwapData>} getter to be passed to InitializeEvent constructor
|
|
38
|
-
*/
|
|
39
|
-
private getSwapDataGetter;
|
|
40
|
-
protected parseInitializeEvent(event: TypedEventLog<EscrowManager["filters"]["Initialize"]>): InitializeEvent<EVMSwapData>;
|
|
41
|
-
protected parseRefundEvent(event: TypedEventLog<EscrowManager["filters"]["Refund"]>): RefundEvent<EVMSwapData>;
|
|
42
|
-
protected parseClaimEvent(event: TypedEventLog<EscrowManager["filters"]["Claim"]>): ClaimEvent<EVMSwapData>;
|
|
43
|
-
protected parseSpvOpenEvent(event: TypedEventLog<SpvVaultManager["filters"]["Opened"]>): SpvVaultOpenEvent;
|
|
44
|
-
protected parseSpvDepositEvent(event: TypedEventLog<SpvVaultManager["filters"]["Deposited"]>): SpvVaultDepositEvent;
|
|
45
|
-
protected parseSpvFrontEvent(event: TypedEventLog<SpvVaultManager["filters"]["Fronted"]>): SpvVaultFrontEvent;
|
|
46
|
-
protected parseSpvClaimEvent(event: TypedEventLog<SpvVaultManager["filters"]["Claimed"]>): SpvVaultClaimEvent;
|
|
47
|
-
protected parseSpvCloseEvent(event: TypedEventLog<SpvVaultManager["filters"]["Closed"]>): SpvVaultCloseEvent;
|
|
48
|
-
/**
|
|
49
|
-
* Processes event as received from the chain, parses it & calls event listeners
|
|
50
|
-
*
|
|
51
|
-
* @param events
|
|
52
|
-
* @param currentBlock
|
|
53
|
-
* @protected
|
|
54
|
-
*/
|
|
55
|
-
protected processEvents(events: AtomiqTypedEvent[], currentBlock?: Block): Promise<void>;
|
|
56
|
-
protected handleEvents(events: AtomiqTypedEvent[]): Promise<void>;
|
|
57
|
-
protected spvVaultContractListener: (log: Log) => void;
|
|
58
|
-
protected swapContractListener: (log: Log) => void;
|
|
59
|
-
protected blockListener: (blockNumber: number) => Promise<void>;
|
|
60
|
-
protected setupWebsocket(): Promise<void>;
|
|
61
|
-
init(): Promise<void>;
|
|
62
|
-
stop(): Promise<void>;
|
|
63
|
-
registerListener(cbk: EventListener<EVMSwapData>): void;
|
|
64
|
-
unregisterListener(cbk: EventListener<EVMSwapData>): boolean;
|
|
65
|
-
}
|
|
66
|
-
export {};
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EVMChainEventsBrowserWS = void 0;
|
|
4
|
-
const base_1 = require("@atomiqlabs/base");
|
|
5
|
-
const EVMSwapData_1 = require("../swaps/EVMSwapData");
|
|
6
|
-
const ethers_1 = require("ethers");
|
|
7
|
-
const Utils_1 = require("../../utils/Utils");
|
|
8
|
-
const EVMSpvVaultContract_1 = require("../spv_swap/EVMSpvVaultContract");
|
|
9
|
-
/**
|
|
10
|
-
* EVM on-chain event handler for front-end systems without access to fs, uses WS or long-polling to subscribe, might lose
|
|
11
|
-
* out on some events if the network is unreliable, front-end systems should take this into consideration and not
|
|
12
|
-
* rely purely on events
|
|
13
|
-
*/
|
|
14
|
-
class EVMChainEventsBrowserWS {
|
|
15
|
-
constructor(chainInterface, evmSwapContract, evmSpvVaultContract) {
|
|
16
|
-
this.listeners = [];
|
|
17
|
-
this.logger = (0, Utils_1.getLogger)("EVMChainEventsBrowser: ");
|
|
18
|
-
this.unconfirmedEventQueue = [];
|
|
19
|
-
this.chainInterface = chainInterface;
|
|
20
|
-
this.provider = chainInterface.provider;
|
|
21
|
-
this.evmSwapContract = evmSwapContract;
|
|
22
|
-
this.evmSpvVaultContract = evmSpvVaultContract;
|
|
23
|
-
this.spvVaultContractLogFilter = {
|
|
24
|
-
address: this.evmSpvVaultContract.contractAddress
|
|
25
|
-
};
|
|
26
|
-
this.swapContractLogFilter = {
|
|
27
|
-
address: this.evmSwapContract.contractAddress
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
findInitSwapData(call, escrowHash, claimHandler) {
|
|
31
|
-
if (call.to.toLowerCase() === this.evmSwapContract.contractAddress.toLowerCase()) {
|
|
32
|
-
const result = this.evmSwapContract.parseCalldata(call.input);
|
|
33
|
-
if (result != null && result.name === "initialize") {
|
|
34
|
-
//Found, check correct escrow hash
|
|
35
|
-
const [escrowData, signature, timeout, extraData] = result.args;
|
|
36
|
-
const escrow = EVMSwapData_1.EVMSwapData.deserializeFromStruct(escrowData, claimHandler);
|
|
37
|
-
if ("0x" + escrow.getEscrowHash() === escrowHash) {
|
|
38
|
-
const extraDataHex = (0, ethers_1.hexlify)(extraData);
|
|
39
|
-
if (extraDataHex.length > 2) {
|
|
40
|
-
escrow.setExtraData(extraDataHex.substring(2));
|
|
41
|
-
}
|
|
42
|
-
return escrow;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
for (let _call of call.calls) {
|
|
47
|
-
const found = this.findInitSwapData(_call, escrowHash, claimHandler);
|
|
48
|
-
if (found != null)
|
|
49
|
-
return found;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns async getter for fetching on-demand initialize event swap data
|
|
55
|
-
*
|
|
56
|
-
* @param event
|
|
57
|
-
* @param claimHandler
|
|
58
|
-
* @private
|
|
59
|
-
* @returns {() => Promise<EVMSwapData>} getter to be passed to InitializeEvent constructor
|
|
60
|
-
*/
|
|
61
|
-
getSwapDataGetter(event, claimHandler) {
|
|
62
|
-
return async () => {
|
|
63
|
-
const trace = await this.chainInterface.Transactions.traceTransaction(event.transactionHash);
|
|
64
|
-
if (trace == null)
|
|
65
|
-
return null;
|
|
66
|
-
return this.findInitSwapData(trace, event.args.escrowHash, claimHandler);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
parseInitializeEvent(event) {
|
|
70
|
-
const escrowHash = event.args.escrowHash.substring(2);
|
|
71
|
-
const claimHandlerHex = event.args.claimHandler;
|
|
72
|
-
const claimHandler = this.evmSwapContract.claimHandlersByAddress[claimHandlerHex.toLowerCase()];
|
|
73
|
-
if (claimHandler == null) {
|
|
74
|
-
this.logger.warn("parseInitializeEvent(" + escrowHash + "): Unknown claim handler with claim: " + claimHandlerHex);
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
const swapType = claimHandler.getType();
|
|
78
|
-
this.logger.debug("InitializeEvent escrowHash: " + escrowHash);
|
|
79
|
-
return new base_1.InitializeEvent(escrowHash, swapType, (0, Utils_1.onceAsync)(this.getSwapDataGetter(event, claimHandler)));
|
|
80
|
-
}
|
|
81
|
-
parseRefundEvent(event) {
|
|
82
|
-
const escrowHash = event.args.escrowHash.substring(2);
|
|
83
|
-
this.logger.debug("RefundEvent escrowHash: " + escrowHash);
|
|
84
|
-
return new base_1.RefundEvent(escrowHash);
|
|
85
|
-
}
|
|
86
|
-
parseClaimEvent(event) {
|
|
87
|
-
const escrowHash = event.args.escrowHash.substring(2);
|
|
88
|
-
const claimHandlerHex = event.args.claimHandler;
|
|
89
|
-
const claimHandler = this.evmSwapContract.claimHandlersByAddress[claimHandlerHex.toLowerCase()];
|
|
90
|
-
if (claimHandler == null) {
|
|
91
|
-
this.logger.warn("parseClaimEvent(" + escrowHash + "): Unknown claim handler with claim: " + claimHandlerHex);
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const witnessResult = event.args.witnessResult.substring(2);
|
|
95
|
-
this.logger.debug("ClaimEvent witnessResult: " + witnessResult + " escrowHash: " + escrowHash);
|
|
96
|
-
return new base_1.ClaimEvent(escrowHash, witnessResult);
|
|
97
|
-
}
|
|
98
|
-
parseSpvOpenEvent(event) {
|
|
99
|
-
const owner = event.args.owner;
|
|
100
|
-
const vaultId = event.args.vaultId;
|
|
101
|
-
const btcTxId = Buffer.from(event.args.btcTxHash.substring(2), "hex").reverse().toString("hex");
|
|
102
|
-
const vout = Number(event.args.vout);
|
|
103
|
-
this.logger.debug("SpvOpenEvent owner: " + owner + " vaultId: " + vaultId + " utxo: " + btcTxId + ":" + vout);
|
|
104
|
-
return new base_1.SpvVaultOpenEvent(owner, vaultId, btcTxId, vout);
|
|
105
|
-
}
|
|
106
|
-
parseSpvDepositEvent(event) {
|
|
107
|
-
const [owner, vaultId] = (0, EVMSpvVaultContract_1.unpackOwnerAndVaultId)(event.args.ownerAndVaultId);
|
|
108
|
-
const amounts = [event.args.amount0, event.args.amount1];
|
|
109
|
-
const depositCount = Number(event.args.depositCount);
|
|
110
|
-
this.logger.debug("SpvDepositEvent owner: " + owner + " vaultId: " + vaultId + " depositCount: " + depositCount + " amounts: ", amounts);
|
|
111
|
-
return new base_1.SpvVaultDepositEvent(owner, vaultId, amounts, depositCount);
|
|
112
|
-
}
|
|
113
|
-
parseSpvFrontEvent(event) {
|
|
114
|
-
const [owner, vaultId] = (0, EVMSpvVaultContract_1.unpackOwnerAndVaultId)(event.args.ownerAndVaultId);
|
|
115
|
-
const btcTxId = Buffer.from(event.args.btcTxHash.substring(2), "hex").reverse().toString("hex");
|
|
116
|
-
const recipient = event.args.recipient;
|
|
117
|
-
const executionHash = event.args.executionHash;
|
|
118
|
-
const amounts = [event.args.amount0, event.args.amount1];
|
|
119
|
-
const frontingAddress = event.args.caller;
|
|
120
|
-
this.logger.debug("SpvFrontEvent owner: " + owner + " vaultId: " + vaultId + " btcTxId: " + btcTxId +
|
|
121
|
-
" recipient: " + recipient + " frontedBy: " + frontingAddress + " amounts: ", amounts);
|
|
122
|
-
return new base_1.SpvVaultFrontEvent(owner, vaultId, btcTxId, recipient, executionHash, amounts, frontingAddress);
|
|
123
|
-
}
|
|
124
|
-
parseSpvClaimEvent(event) {
|
|
125
|
-
const [owner, vaultId] = (0, EVMSpvVaultContract_1.unpackOwnerAndVaultId)(event.args.ownerAndVaultId);
|
|
126
|
-
const btcTxId = Buffer.from(event.args.btcTxHash.substring(2), "hex").reverse().toString("hex");
|
|
127
|
-
const recipient = event.args.recipient;
|
|
128
|
-
const executionHash = event.args.executionHash;
|
|
129
|
-
const amounts = [event.args.amount0, event.args.amount1];
|
|
130
|
-
const caller = event.args.caller;
|
|
131
|
-
const frontingAddress = event.args.frontingAddress;
|
|
132
|
-
const withdrawCount = Number(event.args.withdrawCount);
|
|
133
|
-
this.logger.debug("SpvClaimEvent owner: " + owner + " vaultId: " + vaultId + " btcTxId: " + btcTxId + " withdrawCount: " + withdrawCount +
|
|
134
|
-
" recipient: " + recipient + " frontedBy: " + frontingAddress + " claimedBy: " + caller + " amounts: ", amounts);
|
|
135
|
-
return new base_1.SpvVaultClaimEvent(owner, vaultId, btcTxId, recipient, executionHash, amounts, caller, frontingAddress, withdrawCount);
|
|
136
|
-
}
|
|
137
|
-
parseSpvCloseEvent(event) {
|
|
138
|
-
const btcTxId = Buffer.from(event.args.btcTxHash.substring(2), "hex").reverse().toString("hex");
|
|
139
|
-
return new base_1.SpvVaultCloseEvent(event.args.owner, event.args.vaultId, btcTxId, event.args.error);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Processes event as received from the chain, parses it & calls event listeners
|
|
143
|
-
*
|
|
144
|
-
* @param events
|
|
145
|
-
* @param currentBlock
|
|
146
|
-
* @protected
|
|
147
|
-
*/
|
|
148
|
-
async processEvents(events, currentBlock) {
|
|
149
|
-
const parsedEvents = [];
|
|
150
|
-
for (let event of events) {
|
|
151
|
-
let parsedEvent;
|
|
152
|
-
switch (event.eventName) {
|
|
153
|
-
case "Claim":
|
|
154
|
-
parsedEvent = this.parseClaimEvent(event);
|
|
155
|
-
break;
|
|
156
|
-
case "Refund":
|
|
157
|
-
parsedEvent = this.parseRefundEvent(event);
|
|
158
|
-
break;
|
|
159
|
-
case "Initialize":
|
|
160
|
-
parsedEvent = this.parseInitializeEvent(event);
|
|
161
|
-
break;
|
|
162
|
-
case "Opened":
|
|
163
|
-
parsedEvent = this.parseSpvOpenEvent(event);
|
|
164
|
-
break;
|
|
165
|
-
case "Deposited":
|
|
166
|
-
parsedEvent = this.parseSpvDepositEvent(event);
|
|
167
|
-
break;
|
|
168
|
-
case "Fronted":
|
|
169
|
-
parsedEvent = this.parseSpvFrontEvent(event);
|
|
170
|
-
break;
|
|
171
|
-
case "Claimed":
|
|
172
|
-
parsedEvent = this.parseSpvClaimEvent(event);
|
|
173
|
-
break;
|
|
174
|
-
case "Closed":
|
|
175
|
-
parsedEvent = this.parseSpvCloseEvent(event);
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
const timestamp = event.blockNumber === currentBlock?.number ? currentBlock.timestamp : await this.chainInterface.Blocks.getBlockTime(event.blockNumber);
|
|
179
|
-
parsedEvent.meta = {
|
|
180
|
-
blockTime: timestamp,
|
|
181
|
-
txId: event.transactionHash,
|
|
182
|
-
timestamp //Maybe deprecated
|
|
183
|
-
};
|
|
184
|
-
parsedEvents.push(parsedEvent);
|
|
185
|
-
}
|
|
186
|
-
for (let listener of this.listeners) {
|
|
187
|
-
await listener(parsedEvents);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
handleEvents(events) {
|
|
191
|
-
if (this.chainInterface.config.safeBlockTag === "latest" || this.chainInterface.config.safeBlockTag === "pending") {
|
|
192
|
-
return this.processEvents(events);
|
|
193
|
-
}
|
|
194
|
-
this.unconfirmedEventQueue.push(...events);
|
|
195
|
-
}
|
|
196
|
-
async setupWebsocket() {
|
|
197
|
-
await this.provider.on(this.spvVaultContractLogFilter, this.spvVaultContractListener = (log) => {
|
|
198
|
-
let events = this.evmSpvVaultContract.Events.toTypedEvents([log]);
|
|
199
|
-
events = events.filter(val => !val.removed);
|
|
200
|
-
this.handleEvents(events);
|
|
201
|
-
});
|
|
202
|
-
await this.provider.on(this.swapContractLogFilter, this.swapContractListener = (log) => {
|
|
203
|
-
let events = this.evmSwapContract.Events.toTypedEvents([log]);
|
|
204
|
-
events = events.filter(val => !val.removed && (val.eventName === "Initialize" || val.eventName === "Refund" || val.eventName === "Claim"));
|
|
205
|
-
this.handleEvents(events);
|
|
206
|
-
});
|
|
207
|
-
const safeBlockTag = this.chainInterface.config.safeBlockTag;
|
|
208
|
-
let processing = false;
|
|
209
|
-
if (safeBlockTag !== "latest" && safeBlockTag !== "pending")
|
|
210
|
-
await this.provider.on("block", this.blockListener = async (blockNumber) => {
|
|
211
|
-
if (processing)
|
|
212
|
-
return;
|
|
213
|
-
processing = true;
|
|
214
|
-
try {
|
|
215
|
-
const latestSafeBlock = await this.provider.getBlock(this.chainInterface.config.safeBlockTag);
|
|
216
|
-
const events = [];
|
|
217
|
-
this.unconfirmedEventQueue = this.unconfirmedEventQueue.filter(event => {
|
|
218
|
-
if (event.blockNumber <= latestSafeBlock.number) {
|
|
219
|
-
events.push(event);
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
return true;
|
|
223
|
-
});
|
|
224
|
-
const blocks = {};
|
|
225
|
-
for (let event of events) {
|
|
226
|
-
const block = blocks[event.blockNumber] ?? (blocks[event.blockNumber] = await this.provider.getBlock(event.blockNumber));
|
|
227
|
-
if (block.hash === event.blockHash) {
|
|
228
|
-
//Valid event
|
|
229
|
-
await this.processEvents([event], block);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
//Block hash doesn't match
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
this.logger.error(`on('block'): Error when processing new block ${blockNumber}:`, e);
|
|
238
|
-
}
|
|
239
|
-
processing = false;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
async init() {
|
|
243
|
-
await this.setupWebsocket();
|
|
244
|
-
this.stopped = false;
|
|
245
|
-
}
|
|
246
|
-
async stop() {
|
|
247
|
-
this.stopped = true;
|
|
248
|
-
await this.provider.off(this.spvVaultContractLogFilter, this.spvVaultContractListener);
|
|
249
|
-
await this.provider.off(this.swapContractLogFilter, this.swapContractListener);
|
|
250
|
-
await this.provider.off("block", this.blockListener);
|
|
251
|
-
}
|
|
252
|
-
registerListener(cbk) {
|
|
253
|
-
this.listeners.push(cbk);
|
|
254
|
-
}
|
|
255
|
-
unregisterListener(cbk) {
|
|
256
|
-
const index = this.listeners.indexOf(cbk);
|
|
257
|
-
if (index >= 0) {
|
|
258
|
-
this.listeners.splice(index, 1);
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
exports.EVMChainEventsBrowserWS = EVMChainEventsBrowserWS;
|