@@ -6,9 +6,28 @@ import (
66 "github.com/rsksmart/liquidity-provider-server/internal/entities/blockchain"
77 "github.com/rsksmart/liquidity-provider-server/internal/entities/liquidity_provider"
88 "github.com/rsksmart/liquidity-provider-server/internal/entities/quote"
9- "github.com/rsksmart/liquidity-provider-server/pkg "
9+ "math/big "
1010)
1111
12+ type AssetsReportUseCase interface {
13+ Run (ctx context.Context ) (GetAssetsReportResponse , error )
14+ GetRBTCLiquidity (ctx context.Context ) (* entities.Wei , error )
15+ GetBTCLiquidity (ctx context.Context ) (* entities.Wei , error )
16+ GetBTCLocked (ctx context.Context ) (* entities.Wei , error )
17+ GetRBTCLocked (ctx context.Context ) (* entities.Wei , error )
18+ GetRBTCBalance (ctx context.Context ) (* entities.Wei , error )
19+ GetBtcBalance () (* entities.Wei , error )
20+ }
21+
22+ type GetAssetsReportResponse struct {
23+ BtcBalance * big.Int `json:"btcBalance" validate:"required"`
24+ RbtcBalance * big.Int `json:"rbtcBalance" validate:"required"`
25+ BtcLocked * big.Int `json:"btcLocked" validate:"required"`
26+ RbtcLocked * big.Int `json:"rbtcLocked" validate:"required"`
27+ BtcLiquidity * big.Int `json:"btcLiquidity" validate:"required"`
28+ RbtcLiquidity * big.Int `json:"rbtcLiquidity" validate:"required"`
29+ }
30+
1231type GetAssetsReportUseCase struct {
1332 btcWallet blockchain.BitcoinWallet
1433 rsk blockchain.Rpc
@@ -27,7 +46,7 @@ func NewGetAssetsReportUseCase(
2746 pegoutProvider liquidity_provider.PegoutLiquidityProvider ,
2847 peginRepository quote.PeginQuoteRepository ,
2948 pegoutRepository quote.PegoutQuoteRepository ,
30- ) * GetAssetsReportUseCase {
49+ ) AssetsReportUseCase {
3150 return & GetAssetsReportUseCase {
3251 btcWallet : wallet ,
3352 rsk : rsk ,
@@ -39,8 +58,8 @@ func NewGetAssetsReportUseCase(
3958 }
4059}
4160
42- func (useCase * GetAssetsReportUseCase ) Run (ctx context.Context ) (pkg. GetAssetsReportResponse , error ) {
43- response := pkg. GetAssetsReportResponse {
61+ func (useCase * GetAssetsReportUseCase ) Run (ctx context.Context ) (GetAssetsReportResponse , error ) {
62+ response := GetAssetsReportResponse {
4463 BtcBalance : entities .NewWei (0 ).AsBigInt (),
4564 RbtcBalance : entities .NewWei (0 ).AsBigInt (),
4665 BtcLocked : entities .NewWei (0 ).AsBigInt (),
@@ -52,36 +71,39 @@ func (useCase *GetAssetsReportUseCase) Run(ctx context.Context) (pkg.GetAssetsRe
5271 if err != nil {
5372 return response , err
5473 }
55- response . BtcBalance = btcBalance . AsBigInt ()
74+
5675 rbtcBalance , err := useCase .GetRBTCBalance (ctx )
5776 if err != nil {
5877 return response , err
5978 }
60- response .RbtcBalance = rbtcBalance .AsBigInt ()
6179
6280 rbtcLocked , err := useCase .GetRBTCLocked (ctx )
6381 if err != nil {
6482 return response , err
6583 }
66- response .RbtcLocked = rbtcLocked .AsBigInt ()
6784
6885 lockedBtc , err := useCase .GetBTCLocked (ctx )
6986 if err != nil {
7087 return response , err
7188 }
72- response .BtcLocked = lockedBtc .AsBigInt ()
7389
7490 btcLiquidity , err := useCase .GetBTCLiquidity (ctx )
7591 if err != nil {
7692 return response , err
7793 }
78- response .BtcLiquidity = btcLiquidity .AsBigInt ()
7994
8095 rbtcLiquidity , err := useCase .GetRBTCLiquidity (ctx )
8196 if err != nil {
8297 return response , err
8398 }
99+
100+ response .BtcBalance = btcBalance .AsBigInt ()
84101 response .RbtcLiquidity = rbtcLiquidity .AsBigInt ()
102+ response .BtcLiquidity = btcLiquidity .AsBigInt ()
103+ response .BtcLocked = lockedBtc .AsBigInt ()
104+ response .RbtcLocked = rbtcLocked .AsBigInt ()
105+ response .RbtcBalance = rbtcBalance .AsBigInt ()
106+
85107 return response , nil
86108}
87109
@@ -118,20 +140,13 @@ func (useCase *GetAssetsReportUseCase) GetBTCLocked(ctx context.Context) (*entit
118140
119141func (useCase * GetAssetsReportUseCase ) GetRBTCLocked (ctx context.Context ) (* entities.Wei , error ) {
120142 lockedPegin := entities .NewWei (0 )
121- peginQuotes , err := useCase .peginRepository .GetRetainedQuoteByState (ctx , quote .PeginStateWaitingForDeposit )
143+ peginQuotes , err := useCase .peginRepository .GetRetainedQuoteByState (ctx , quote .PeginStateWaitingForDeposit , quote . PeginStateWaitingForDepositConfirmations )
122144 if err != nil {
123145 return nil , err
124146 }
125147 for _ , retainedQuote := range peginQuotes {
126148 lockedPegin .Add (lockedPegin , retainedQuote .RequiredLiquidity )
127149 }
128- pegoutQuotes , err := useCase .pegoutRepository .GetRetainedQuoteByState (ctx , quote .PegoutStateRefundPegOutSucceeded )
129- if err != nil {
130- return nil , err
131- }
132- for _ , retainedQuote := range pegoutQuotes {
133- lockedPegin .Add (lockedPegin , retainedQuote .RequiredLiquidity )
134- }
135150
136151 return lockedPegin , nil
137152}
0 commit comments