@@ -2,11 +2,10 @@ import { Requester } from '@chainlink/external-adapter-framework/util/requester'
22import { JsonRpcProvider } from 'ethers'
33
44import { AdapterError } from '@chainlink/external-adapter-framework/validation/error'
5- import { Smoother } from '../endpoint/ondo '
5+ import { Smoother } from '../endpoint/common '
66import { getRegistryData } from '../lib/registry'
7- import { calculateSecondsFromTransition } from '../lib/session/session'
8- import { processUpdate } from '../lib/smoother/smoother'
9- import { getPrice } from '../lib/streams'
7+
8+ import { smoothedStreamPrice } from './smoothedPrice'
109
1110const MULTIPLIER_DECIMALS = 18n
1211
@@ -27,23 +26,9 @@ export const calculatePrice = async (param: {
2726 smoother : Smoother
2827 decimals : number
2928} ) => {
30- const [ price , { multiplier, paused } , secondsFromTransition ] = await Promise . all ( [
31- getPrice (
32- param . regularStreamId ,
33- param . extendedStreamId ,
34- param . overnightStreamId ,
35- param . url ,
36- param . requester ,
37- ) ,
29+ const [ result , { multiplier, paused } ] = await Promise . all ( [
30+ smoothedStreamPrice ( param ) ,
3831 getRegistryData ( param . asset , param . registry , param . provider ) ,
39- calculateSecondsFromTransition (
40- param . tradingHoursUrl ,
41- param . requester ,
42- param . sessionBoundaries ,
43- param . sessionBoundariesTimeZone ,
44- param . sessionMarket ,
45- param . sessionMarketType ,
46- ) ,
4732 ] )
4833
4934 if ( paused ) {
@@ -53,61 +38,12 @@ export const calculatePrice = async (param: {
5338 } )
5439 }
5540
56- const common = {
57- rawPrice : price . price ,
58- decimals : param . decimals ,
41+ return result . map ( ( r ) => ( {
42+ ...r ,
5943 registry : {
6044 sValue : multiplier . toString ( ) ,
6145 paused,
6246 } ,
63- stream : price . data ,
64- }
65-
66- return [ 'ema' , 'kalman' ] . map ( ( smoother ) => {
67- const smoothed = smooth (
68- smoother as Smoother ,
69- param ,
70- price ,
71- secondsFromTransition . value ,
72- multiplier ,
73- )
74- return {
75- result : smoothed . result ,
76- ...common ,
77- smoother : smoothed . smoother ,
78- sessionSource : secondsFromTransition . source ,
79- }
80- } )
81- }
82-
83- const smooth = (
84- smoother : Smoother ,
85- param : { asset : string ; decimals : number } ,
86- price : { price : string ; spread : bigint ; decimals : number } ,
87- secondsFromTransition : number ,
88- multiplier : bigint ,
89- ) => {
90- const smoothed = processUpdate (
91- smoother ,
92- param . asset ,
93- BigInt ( price . price ) ,
94- price . spread ,
95- secondsFromTransition ,
96- )
97-
98- const result =
99- ( smoothed . price * multiplier * 10n ** BigInt ( param . decimals ) ) /
100- 10n ** BigInt ( price . decimals ) /
101- 10n ** MULTIPLIER_DECIMALS
102-
103- return {
104- result : result . toString ( ) ,
105- smoother : {
106- smoother,
107- price : smoothed . price . toString ( ) ,
108- x : smoothed . x . toString ( ) ,
109- p : smoothed . p . toString ( ) ,
110- secondsFromTransition,
111- } ,
112- }
47+ result : ( ( BigInt ( r . result ) * multiplier ) / 10n ** MULTIPLIER_DECIMALS ) . toString ( ) ,
48+ } ) )
11349}
0 commit comments