@@ -16,39 +16,40 @@ func (k Keeper) JoinPoolEstimation(goCtx context.Context, req *types.QueryJoinPo
1616 }
1717
1818 ctx := sdk .UnwrapSDKContext (goCtx )
19- tokensIn , sharesOut , slippage , weightBalanceBonus , swapFee , takerFees , err := k .JoinPoolEst (ctx , req .PoolId , req .AmountsIn )
19+ tokensIn , sharesOut , slippage , weightBalanceBonus , swapFee , takerFees , weightRewardAmount , err := k .JoinPoolEst (ctx , req .PoolId , req .AmountsIn )
2020 if err != nil {
2121 return nil , err
2222 }
2323
2424 shareDenom := types .GetPoolShareDenom (req .PoolId )
2525 return & types.QueryJoinPoolEstimationResponse {
26- ShareAmountOut : sdk .NewCoin (shareDenom , sharesOut ),
27- AmountsIn : tokensIn ,
28- Slippage : slippage ,
29- WeightBalanceRatio : weightBalanceBonus ,
30- SwapFee : swapFee ,
31- TakerFee : takerFees ,
26+ ShareAmountOut : sdk .NewCoin (shareDenom , sharesOut ),
27+ AmountsIn : tokensIn ,
28+ Slippage : slippage ,
29+ WeightBalanceRatio : weightBalanceBonus ,
30+ SwapFee : swapFee ,
31+ TakerFee : takerFees ,
32+ WeightBalanceRewardAmount : weightRewardAmount ,
3233 }, nil
3334}
3435
3536func (k Keeper ) JoinPoolEst (
3637 ctx sdk.Context ,
3738 poolId uint64 ,
3839 tokenInMaxs sdk.Coins ,
39- ) (tokensIn sdk.Coins , sharesOut math.Int , slippage math.LegacyDec , weightBalanceBonus math.LegacyDec , swapFee math.LegacyDec , takerFeesFinal math.LegacyDec , err error ) {
40+ ) (tokensIn sdk.Coins , sharesOut math.Int , slippage math.LegacyDec , weightBalanceBonus math.LegacyDec , swapFee math.LegacyDec , takerFeesFinal math.LegacyDec , weightRewardAmount sdk. Coin , err error ) {
4041 // all pools handled within this method are pointer references, `JoinPool` directly updates the pools
4142 pool , poolExists := k .GetPool (ctx , poolId )
4243 if ! poolExists {
43- return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), types .ErrInvalidPoolId
44+ return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), sdk. Coin {}, types .ErrInvalidPoolId
4445 }
4546
4647 if ! pool .PoolParams .UseOracle {
4748 tokensIn := tokenInMaxs
4849 if len (tokensIn ) != 1 {
4950 numShares , tokensIn , err := pool .CalcJoinPoolNoSwapShares (tokenInMaxs )
5051 if err != nil {
51- return tokensIn , numShares , math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), err
52+ return tokensIn , numShares , math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), sdk. Coin {}, err
5253 }
5354 }
5455
@@ -58,10 +59,10 @@ func (k Keeper) JoinPoolEst(
5859 cacheCtx , _ := ctx .CacheContext ()
5960 tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , takerFeesFinal , err := pool .JoinPool (cacheCtx , & snapshot , k .oracleKeeper , k .accountedPoolKeeper , tokensIn , params , takerFees )
6061 if err != nil {
61- return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), err
62+ return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), sdk. Coin {}, err
6263 }
6364
64- return tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , takerFeesFinal , nil
65+ return tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , takerFeesFinal , sdk. Coin {}, nil
6566 }
6667
6768 params := k .GetParams (ctx )
@@ -71,10 +72,11 @@ func (k Keeper) JoinPoolEst(
7172 cacheCtx , _ := ctx .CacheContext ()
7273 tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , _ , err := pool .JoinPool (cacheCtx , & snapshot , k .oracleKeeper , k .accountedPoolKeeper , tokenInMaxs , params , takerFees )
7374 if err != nil {
74- return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), err
75+ return nil , math .ZeroInt (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), math .LegacyZeroDec (), sdk. Coin {}, err
7576 }
7677
7778 var otherAsset types.PoolAsset
79+ bonusTokenAmount := math .ZeroInt ()
7880 // Check treasury and update weightBalance
7981 if weightBalanceBonus .IsPositive () && tokensJoined .Len () == 1 {
8082 rebalanceTreasuryAddr := sdk .MustAccAddressFromBech32 (pool .GetRebalanceTreasury ())
@@ -85,12 +87,16 @@ func (k Keeper) JoinPoolEst(
8587 otherAsset = asset
8688 }
8789 treasuryTokenAmount := k .bankKeeper .GetBalance (ctx , rebalanceTreasuryAddr , otherAsset .Token .Denom ).Amount
88-
89- bonusTokenAmount := tokensJoined [0 ].Amount .ToLegacyDec ().Mul (weightBalanceBonus ).TruncateInt ()
90+ bonusTokenAmount = tokensJoined [0 ].Amount .ToLegacyDec ().Mul (weightBalanceBonus ).TruncateInt ()
9091
9192 if treasuryTokenAmount .LT (bonusTokenAmount ) {
92- weightBalanceBonus = treasuryTokenAmount . ToLegacyDec (). Quo ( tokensJoined [ 0 ]. Amount . ToLegacyDec ())
93+ bonusTokenAmount = treasuryTokenAmount
9394 }
9495 }
95- return tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , takerFeesFinal , nil
96+ rewards := sdk.Coin {}
97+ if otherAsset .Token .Denom != "" && bonusTokenAmount .IsPositive () {
98+ rewards = sdk .NewCoin (otherAsset .Token .Denom , bonusTokenAmount )
99+ }
100+
101+ return tokensJoined , sharesOut , slippage , weightBalanceBonus , swapFee , takerFeesFinal , rewards , nil
96102}
0 commit comments