-
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.
core: Price Updating - revert history observation (#6)
* created the etherscan service * chainlink service created * added tx input parser for oracle service * added reverts to prices redux * created reverts api route * reverts history cron job created * lint fixes
- Loading branch information
Showing
17 changed files
with
336 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextFunction, Request as ExpressRequest, Response as ExpressResponse } from "express"; | ||
import { IResponseSuccess } from "../../../utils/response.util"; | ||
import { EmptyObject, ParamsDictionary } from "../../../types/util.types"; | ||
import { RevertEntity } from "../../../entities/revert.entity"; | ||
|
||
export enum ERevertsRoute { | ||
GetRevertList = "GetRevertList" | ||
} | ||
|
||
declare namespace RevertsRouteDefinitions { | ||
type ResponseBody<T extends ERevertsRoute> = | ||
T extends ERevertsRoute.GetRevertList ? RevertEntity[] : | ||
EmptyObject | ||
|
||
type RequestBody<T extends ERevertsRoute> = // eslint-disable-line @typescript-eslint/no-unused-vars | ||
EmptyObject; | ||
|
||
type RequestQueries<T extends ERevertsRoute> = // eslint-disable-line @typescript-eslint/no-unused-vars | ||
EmptyObject | ||
|
||
type RequestParams<T extends ERevertsRoute> = // eslint-disable-line @typescript-eslint/no-unused-vars | ||
EmptyObject | ||
|
||
type Response<T extends ERevertsRoute> = ExpressResponse<IResponseSuccess<ResponseBody<T>>> | ||
|
||
type Request<T extends ERevertsRoute> = ExpressRequest<RequestParams<T> & ParamsDictionary, IResponseSuccess<ResponseBody<T>>, RequestBody<T>, RequestQueries<T>> | ||
|
||
type RouteMethod<T extends ERevertsRoute> = (request: Request<T>, response: Response<T>, next: NextFunction) => Promise<any>; | ||
} | ||
|
||
export default RevertsRouteDefinitions; |
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,24 @@ | ||
import RevertsRouteDefinitions, { ERevertsRoute } from "../definitions/reverts.route"; | ||
import store from "../../../redux/store"; | ||
import { RevertEntity, revertEntityFromReduxState } from "../../../entities/revert.entity"; | ||
import { APIResponse } from "../../../utils/response.util"; | ||
|
||
class RevertsRoute { | ||
public static getRevertList: RevertsRouteDefinitions.RouteMethod<ERevertsRoute.GetRevertList> = async (request, response, next) => { | ||
try { | ||
const rootState = store.getState(); | ||
const txHashes = Object.keys(rootState.prices.reverts); | ||
|
||
const revertList: RevertEntity[] = []; | ||
txHashes.forEach(txHash => { | ||
revertList.push(revertEntityFromReduxState(txHash, rootState)); | ||
}); | ||
|
||
return response.status(200).json(APIResponse.success(revertList)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
} | ||
|
||
export default RevertsRoute; |
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,24 @@ | ||
import { RootState } from "../redux/redux.types"; | ||
import { Nullable } from "../types/util.types"; | ||
|
||
export type RevertEntity = { | ||
txHash: string, | ||
tickerSymbol: string, | ||
sentPrice: number, | ||
chainlinkPrice: number | ||
} | ||
|
||
export function revertEntityFromReduxState(txHash: string, state: RootState): Nullable<RevertEntity> { | ||
const reverts = state.prices.reverts[txHash]; | ||
|
||
if (reverts) { | ||
return { | ||
txHash: txHash, | ||
tickerSymbol: reverts.tickerSymbol, | ||
chainlinkPrice: reverts.chainlinkPrice, | ||
sentPrice: reverts.sentPrice | ||
}; | ||
} else { | ||
return undefined; | ||
} | ||
} |
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
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,20 @@ | ||
import { ChainlinkAggregatorV3Abi } from "../contracts"; | ||
import Web3Service from "./web3.service"; | ||
|
||
class ChainlinkService { | ||
private _aggregatorContract: ChainlinkAggregatorV3Abi; | ||
|
||
constructor(aggregatorAddress: string) { | ||
this._aggregatorContract = Web3Service.getChainlinkPriceFeedContract(aggregatorAddress); | ||
} | ||
|
||
public async getPriceForBlock(blockNumber: number) { | ||
const result = await this._aggregatorContract.latestRoundData({ | ||
blockTag: blockNumber | ||
}); | ||
|
||
return result.answer; | ||
} | ||
} | ||
|
||
export default ChainlinkService; |
Oops, something went wrong.