@@ -92,7 +92,7 @@ func (p *Pool) JoinPool(
9292 oracleKeeper OracleKeeper ,
9393 accountedPoolKeeper AccountedPoolKeeper , tokensIn sdk.Coins ,
9494 params Params ,
95- takerfees sdkmath.LegacyDec ,
95+ takerFees sdkmath.LegacyDec ,
9696) (tokensJoined sdk.Coins , numShares sdkmath.Int , slippage sdkmath.LegacyDec , weightBalanceBonus sdkmath.LegacyDec , swapFee sdkmath.LegacyDec , takerFeesFinal sdkmath.LegacyDec , err error ) {
9797 // if it's not single sided liquidity, add at pool ratio
9898 if len (tokensIn ) != 1 {
@@ -122,17 +122,26 @@ func (p *Pool) JoinPool(
122122 }
123123 }
124124
125- numShares , tokensJoined , err := p .CalcSingleAssetJoinPoolShares (tokensIn )
125+ numShares , tokensJoined , err := p .CalcSingleAssetJoinPoolShares (tokensIn , takerFees )
126126 if err != nil {
127127 return sdk .NewCoins (), sdkmath.Int {}, sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), err
128128 }
129+ poolAssetsByDenom , err := GetPoolAssetsByDenom (p .GetAllPoolAssets ())
130+ if err != nil {
131+ return sdk .NewCoins (), sdkmath.Int {}, sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), err
132+ }
133+ totalWeight := p .TotalWeight
134+ normalizedWeight := poolAssetsByDenom [tokenIn .Denom ].Weight .ToLegacyDec ().Quo (totalWeight .ToLegacyDec ())
135+ // We multiply the swap fee and taker fees by the normalized weight because it is calculated like this later in CalcSingleAssetJoinPoolShares function
136+ swapFee := feeRatio (normalizedWeight , p .PoolParams .SwapFee )
137+ takerFee := feeRatio (normalizedWeight , takerFees )
129138
130139 // update pool with the calculated share and liquidity needed to join pool
131140 err = p .IncreaseLiquidity (numShares , tokensJoined )
132141 if err != nil {
133142 return sdk .NewCoins (), sdkmath.Int {}, sdkmath.LegacyDec {}, sdkmath.LegacyDec {}, sdkmath .LegacyZeroDec (), sdkmath .LegacyZeroDec (), err
134143 }
135- return tokensJoined , numShares , totalSlippage , sdkmath .LegacyZeroDec (), sdkmath . LegacyZeroDec (), sdkmath . LegacyZeroDec () , nil
144+ return tokensJoined , numShares , totalSlippage , sdkmath .LegacyZeroDec (), swapFee , takerFee , nil
136145 }
137146
138147 accountedAssets := p .GetAccountedBalance (ctx , accountedPoolKeeper , p .PoolAssets )
@@ -171,7 +180,7 @@ func (p *Pool) JoinPool(
171180 swapFee = p .GetPoolParams ().SwapFee .Mul (initialWeightOut )
172181 }
173182
174- takerFeesFinal = takerfees .Mul (initialWeightOut )
183+ takerFeesFinal = takerFees .Mul (initialWeightOut )
175184
176185 totalShares := p .GetTotalShares ()
177186 numSharesDec := sdkmath .LegacyNewDecFromInt (totalShares .Amount ).
0 commit comments