@@ -14,7 +14,7 @@ const (
1414 DateFormat = time .DateOnly
1515)
1616
17- type SummariesResponse struct {
17+ type SummaryResult struct {
1818 PeginSummary SummaryData `json:"peginSummary"`
1919 PegoutSummary SummaryData `json:"pegoutSummary"`
2020}
@@ -30,35 +30,14 @@ type SummaryData struct {
3030 LpEarnings * entities.Wei `json:"lpEarnings"`
3131}
3232
33- type Quote interface {
34- Total () * entities.Wei
35- }
36-
37- type RetainedQuote interface {
38- GetQuoteHash () string
39- }
40-
41- type FeeProvider interface {
42- GetCallFee () * entities.Wei
43- GetGasFee () * entities.Wei
44- GetProductFee () * entities.Wei
45- GetPenaltyFee () * entities.Wei
46- }
47-
4833type feeAdapter struct {
4934 callFee * entities.Wei
5035 gasFee * entities.Wei
5136 productFee * entities.Wei
5237 penaltyFee * entities.Wei
5338}
5439
55- type QuoteResult [Q any , R RetainedQuote ] interface {
56- GetQuotes () []Q
57- GetRetainedQuotes () []R
58- GetQuoteHashToIndex () map [string ]int
59- }
60-
61- type quoteResultAdapter [Q any , R RetainedQuote ] struct {
40+ type quoteResultAdapter [Q any , R quote.RetainedQuote ] struct {
6241 quotes []Q
6342 retainedQuotes []R
6443 quoteHashToIndex map [string ]int
@@ -92,24 +71,24 @@ func NewSummariesUseCase(
9271 }
9372}
9473
95- func (u * SummariesUseCase ) Run (ctx context.Context , startDate , endDate time.Time ) (SummariesResponse , error ) {
74+ func (u * SummariesUseCase ) Run (ctx context.Context , startDate , endDate time.Time ) (SummaryResult , error ) {
9675 peginData , err := u .aggregatePeginData (ctx , startDate , endDate )
9776 if err != nil {
9877 log .Errorf ("Error aggregating pegin data: %v" , err )
99- return SummariesResponse {}, err
78+ return SummaryResult {}, err
10079 }
10180 pegoutData , err := u .aggregatePegoutData (ctx , startDate , endDate )
10281 if err != nil {
10382 log .Errorf ("Error aggregating pegout data: %v" , err )
104- return SummariesResponse {}, err
83+ return SummaryResult {}, err
10584 }
106- return SummariesResponse {
85+ return SummaryResult {
10786 PeginSummary : peginData ,
10887 PegoutSummary : pegoutData ,
10988 }, nil
11089}
11190
112- func mapPeginQuote (q * quote.PeginQuote ) FeeProvider {
91+ func mapPeginQuote (q * quote.PeginQuote ) quote. FeeProvider {
11392 if q == nil {
11493 return & feeAdapter {}
11594 }
@@ -121,7 +100,7 @@ func mapPeginQuote(q *quote.PeginQuote) FeeProvider {
121100 }
122101}
123102
124- func mapPegoutQuote (q * quote.PegoutQuote ) FeeProvider {
103+ func mapPegoutQuote (q * quote.PegoutQuote ) quote. FeeProvider {
125104 if q == nil {
126105 return & feeAdapter {}
127106 }
@@ -133,7 +112,7 @@ func mapPegoutQuote(q *quote.PegoutQuote) FeeProvider {
133112 }
134113}
135114
136- func processQuoteData [Q any , R RetainedQuote , F FeeProvider ](
115+ func processQuoteData [Q any , R quote. RetainedQuote , F quote. FeeProvider ](
137116 ctx context.Context ,
138117 quotes []Q ,
139118 retainedQuotes []R ,
@@ -167,7 +146,7 @@ func processQuoteData[Q any, R RetainedQuote, F FeeProvider](
167146 fees := feeProvider (quoteObj )
168147 if isAccepted (retained ) {
169148 data .ConfirmedQuotesCount ++
170- if q , ok := any (quoteObj ).(Quote ); ok {
149+ if q , ok := any (quoteObj ).(quote. Quote ); ok {
171150 acceptedTotalAmount .Add (acceptedTotalAmount , q .Total ())
172151 }
173152 callFee := fees .GetCallFee ()
@@ -194,7 +173,7 @@ func calculateTotalAmount[T any](quotes []T) *entities.Wei {
194173 totalAmount := entities .NewWei (0 )
195174 for i := range quotes {
196175 var total * entities.Wei
197- if q , ok := any (& quotes [i ]).(Quote ); ok {
176+ if q , ok := any (& quotes [i ]).(quote. Quote ); ok {
198177 total = q .Total ()
199178 }
200179 if total != nil {
@@ -215,7 +194,7 @@ func createQuoteHashMap[T any](quotes []T, quoteHashToIndex map[string]int) map[
215194 return quotesByHash
216195}
217196
218- func fetchMissingQuotes [Q any , R RetainedQuote ](
197+ func fetchMissingQuotes [Q any , R quote. RetainedQuote ](
219198 ctx context.Context ,
220199 quotesByHash map [string ]* Q ,
221200 retainedQuotes []R ,
@@ -237,36 +216,36 @@ func fetchMissingQuotes[Q any, R RetainedQuote](
237216 continue
238217 }
239218 quotesByHash [quoteHash ] = quoteObj
240- if q , ok := any (quoteObj ).(Quote ); ok {
219+ if q , ok := any (quoteObj ).(quote. Quote ); ok {
241220 totalAmount .Add (totalAmount , q .Total ())
242221 }
243222 }
244223}
245224
246- func adaptPeginResult (result quote.PeginQuoteResult ) QuoteResult [quote.PeginQuote , quote.RetainedPeginQuote ] {
225+ func adaptPeginResult (result quote.PeginQuoteResult ) quote. QuoteResult [quote.PeginQuote , quote.RetainedPeginQuote ] {
247226 return quoteResultAdapter [quote.PeginQuote , quote.RetainedPeginQuote ]{
248227 quotes : result .Quotes ,
249228 retainedQuotes : result .RetainedQuotes ,
250229 quoteHashToIndex : result .QuoteHashToIndex ,
251230 }
252231}
253232
254- func adaptPegoutResult (result quote.PegoutQuoteResult ) QuoteResult [quote.PegoutQuote , quote.RetainedPegoutQuote ] {
233+ func adaptPegoutResult (result quote.PegoutQuoteResult ) quote. QuoteResult [quote.PegoutQuote , quote.RetainedPegoutQuote ] {
255234 return quoteResultAdapter [quote.PegoutQuote , quote.RetainedPegoutQuote ]{
256235 quotes : result .Quotes ,
257236 retainedQuotes : result .RetainedQuotes ,
258237 quoteHashToIndex : result .QuoteHashToIndex ,
259238 }
260239}
261240
262- func aggregateData [Q any , RQ RetainedQuote ](
241+ func aggregateData [Q any , RQ quote. RetainedQuote ](
263242 ctx context.Context ,
264243 startDate , endDate time.Time ,
265- listQuotes func (context.Context , time.Time , time.Time ) (QuoteResult [Q , RQ ], error ),
244+ listQuotes func (context.Context , time.Time , time.Time ) (quote. QuoteResult [Q , RQ ], error ),
266245 getQuote func (context.Context , string ) (* Q , error ),
267246 isAccepted func (RQ ) bool ,
268247 isRefunded func (RQ ) bool ,
269- toFeeProvider func (* Q ) FeeProvider ,
248+ toFeeProvider func (* Q ) quote. FeeProvider ,
270249) (SummaryData , error ) {
271250 result , err := listQuotes (ctx , startDate , endDate )
272251 if err != nil {
@@ -286,7 +265,7 @@ func aggregateData[Q any, RQ RetainedQuote](
286265}
287266
288267func (u * SummariesUseCase ) aggregatePeginData (ctx context.Context , startDate , endDate time.Time ) (SummaryData , error ) {
289- listPeginQuotes := func (ctx context.Context , start , end time.Time ) (QuoteResult [quote.PeginQuote , quote.RetainedPeginQuote ], error ) {
268+ listPeginQuotes := func (ctx context.Context , start , end time.Time ) (quote. QuoteResult [quote.PeginQuote , quote.RetainedPeginQuote ], error ) {
290269 result , err := u .peginRepo .ListQuotesByDateRange (ctx , start , end )
291270 if err != nil {
292271 return nil , err
@@ -304,7 +283,7 @@ func (u *SummariesUseCase) aggregatePeginData(ctx context.Context, startDate, en
304283}
305284
306285func (u * SummariesUseCase ) aggregatePegoutData (ctx context.Context , startDate , endDate time.Time ) (SummaryData , error ) {
307- listPegoutQuotes := func (ctx context.Context , start , end time.Time ) (QuoteResult [quote.PegoutQuote , quote.RetainedPegoutQuote ], error ) {
286+ listPegoutQuotes := func (ctx context.Context , start , end time.Time ) (quote. QuoteResult [quote.PegoutQuote , quote.RetainedPegoutQuote ], error ) {
308287 result , err := u .pegoutRepo .ListQuotesByDateRange (ctx , start , end )
309288 if err != nil {
310289 return nil , err
0 commit comments