@@ -353,7 +353,7 @@ func (m *Mock) getPools() map[ton.AccountID]float64 {
353
353
},
354
354
}
355
355
pools := make (map [ton.AccountID ]float64 )
356
- for attempt := 0 ; attempt < 2 ; attempt ++ {
356
+ for attempt := 0 ; attempt < 3 ; attempt ++ {
357
357
for _ , market := range markets {
358
358
respBody , err := sendRequest (market .URL , "" )
359
359
if err != nil {
@@ -652,30 +652,38 @@ func convertedDeDustPoolResponse(pools map[ton.AccountID]float64, respBody io.Re
652
652
Assets : []Asset {firstAsset , secondAsset },
653
653
}, nil
654
654
}
655
+ normalizeReserve := func (firstReserve , secondReserve float64 , firstDecimals , secondDecimals int ) (float64 , float64 ) {
656
+ decimalDiff := firstDecimals - secondDecimals
657
+ if decimalDiff > 0 {
658
+ secondReserve *= math .Pow10 (decimalDiff )
659
+ } else if decimalDiff < 0 {
660
+ firstReserve *= math .Pow10 (- decimalDiff )
661
+ }
662
+ return firstReserve , secondReserve
663
+ }
655
664
actualAssets := make (map [ton.AccountID ]DeDustAssets )
656
665
// Update the assets with the largest reserves
657
666
updateActualAssets := func (mainAsset Asset , deDustAssets DeDustAssets ) {
658
667
firstAsset , secondAsset := deDustAssets .Assets [0 ], deDustAssets .Assets [1 ]
659
- assets , ok := actualAssets [mainAsset .Account ]
668
+ existingAssets , ok := actualAssets [mainAsset .Account ]
660
669
if ! ok {
661
670
actualAssets [mainAsset .Account ] = DeDustAssets {Assets : []Asset {firstAsset , secondAsset }, IsStable : deDustAssets .IsStable }
662
671
return
663
672
}
664
- for idx , asset := range assets .Assets {
665
- assetReserveNormalised := asset .Reserve
666
- mainAssetReserveNormalised := mainAsset .Reserve
667
- // Adjust the reserves of assets considering their decimal places
668
- if asset .Decimals != mainAsset .Decimals {
669
- assetReserveNormalised = asset .Reserve / math .Pow10 (asset .Decimals )
670
- mainAssetReserveNormalised = mainAsset .Reserve / math .Pow10 (mainAsset .Decimals )
671
- }
672
- if asset .Account == mainAsset .Account && assetReserveNormalised < mainAssetReserveNormalised {
673
- if idx == 0 {
674
- actualAssets [mainAsset .Account ] = DeDustAssets {Assets : []Asset {firstAsset , secondAsset }, IsStable : deDustAssets .IsStable }
675
- } else {
676
- actualAssets [mainAsset .Account ] = DeDustAssets {Assets : []Asset {secondAsset , firstAsset }, IsStable : deDustAssets .IsStable }
677
- }
678
- }
673
+ // Adjust the reserves of assets considering their decimal places
674
+ firstAssetReserve , secondAssetReserve := normalizeReserve (
675
+ firstAsset .Reserve , secondAsset .Reserve ,
676
+ firstAsset .Decimals , secondAsset .Decimals ,
677
+ )
678
+ existingFirstReserve , existingSecondReserve := normalizeReserve (
679
+ existingAssets .Assets [0 ].Reserve , existingAssets .Assets [1 ].Reserve ,
680
+ existingAssets .Assets [0 ].Decimals , existingAssets .Assets [1 ].Decimals ,
681
+ )
682
+ // Calculate the total liquidity of the pool
683
+ currentLiquidity := firstAssetReserve + secondAssetReserve
684
+ existingLiquidity := existingFirstReserve + existingSecondReserve
685
+ if currentLiquidity > existingLiquidity {
686
+ actualAssets [mainAsset .Account ] = DeDustAssets {Assets : []Asset {firstAsset , secondAsset }, IsStable : deDustAssets .IsStable }
679
687
}
680
688
}
681
689
actualLpAssets := make (map [ton.AccountID ]LpAsset )
0 commit comments