forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/configuration
Fix woo-fi, dystopia, platypus, LO etc. and conflicts.
- Loading branch information
Showing
98 changed files
with
14,074 additions
and
1,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Interface } from '@ethersproject/abi'; | ||
import { DeepReadonly } from 'ts-essentials'; | ||
import { Log, Logger } from '../../types'; | ||
import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; | ||
import { IDexHelper } from '../../dex-helper/idex-helper'; | ||
import { __DexName__Data, PoolState } from './types'; | ||
import { __DexName__Config } from './config'; | ||
|
||
export class __DexName__EventPool extends StatefulEventSubscriber<PoolState> { | ||
handlers: { | ||
[event: string]: (event: any, pool: PoolState, log: Log) => PoolState; | ||
} = {}; | ||
|
||
logDecoder: (log: Log) => any; | ||
|
||
addressesSubscribed: string[]; | ||
|
||
constructor( | ||
protected parentName: string, | ||
protected network: number, | ||
protected dexHelper: IDexHelper, | ||
logger: Logger, | ||
protected __DexNameCamel__Iface = new Interface( | ||
'' /* TODO: Import and put here __DexName__ ABI */, | ||
), // TODO: add any additional params required for event subscriber | ||
) { | ||
super(parentName, logger); | ||
|
||
// TODO: make logDecoder decode logs that | ||
this.logDecoder = (log: Log) => this.__DexNameCamel__Iface.parseLog(log); | ||
this.addressesSubscribed = [ | ||
/* subscribed addresses */ | ||
]; | ||
|
||
// Add handlers | ||
this.handlers['myEvent'] = this.handleMyEvent.bind(this); | ||
} | ||
|
||
/** | ||
* The function is called every time any of the subscribed | ||
* addresses release log. The function accepts the current | ||
* state, updates the state according to the log, and returns | ||
* the updated state. | ||
* @param state - Current state of event subscriber | ||
* @param log - Log released by one of the subscribed addresses | ||
* @returns Updates state of the event subscriber after the log | ||
*/ | ||
protected processLog( | ||
state: DeepReadonly<PoolState>, | ||
log: Readonly<Log>, | ||
): DeepReadonly<PoolState> | null { | ||
try { | ||
const event = this.logDecoder(log); | ||
if (event.name in this.handlers) { | ||
return this.handlers[event.name](event, state, log); | ||
} | ||
return state; | ||
} catch (e) { | ||
this.logger.error( | ||
`Error_${this.parentName}_processLog could not parse the log with topic ${log.topics}:`, | ||
e, | ||
); | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* The function generates state using on-chain calls. This | ||
* function is called to regenerate state if the event based | ||
* system fails to fetch events and the local state is no | ||
* more correct. | ||
* @param blockNumber - Blocknumber for which the state should | ||
* should be generated | ||
* @returns state of the event subscriber at blocknumber | ||
*/ | ||
async generateState(blockNumber: number): Promise<Readonly<PoolState>> { | ||
// TODO: complete me! | ||
return {}; | ||
} | ||
|
||
// Its just a dummy example | ||
handleMyEvent(event: any, pool: PoolState, log: Log) { | ||
return pool; | ||
} | ||
} |
Oops, something went wrong.