11from collections import namedtuple
2- from decimal import Decimal
2+ from decimal import Decimal , ROUND_HALF_DOWN
33
44from model .balancer_constants import MIN_FEE , MAX_BOUND_TOKENS , INIT_POOL_SUPPLY , EXIT_FEE , MAX_IN_RATIO , MAX_OUT_RATIO
55from model .balancer_math import BalancerMath
@@ -294,3 +294,36 @@ def join_swap_extern_amount_in(self, token_in: str, token_amount_in: Decimal, mi
294294 # _pushPoolShare(msg.sender, pool_amount_out);
295295 # _pullUnderlying(token_in, msg.sender, token_amount_in);
296296 return pool_amount_out
297+
298+
299+
300+ def join_swap_pool_amount_out (self , token_in : str , pool_amount_out : Decimal , max_amount_in : Decimal ) -> Decimal :
301+ if not self ._records [token_in ].bound :
302+ raise Exception ("ERR_NOT_BOUND" )
303+
304+ in_record = self ._records [token_in ]
305+
306+ token_amount_in = self .calc_single_in_given_pool_out (
307+ token_balance_in = in_record .balance ,
308+ token_weight_in = in_record .denorm ,
309+ pool_supply = self .pool_token_supply ,
310+ total_weight = self .total_weight ,
311+ pool_amount_out = pool_amount_out ,
312+ swap_fee = self ._swap_fee )
313+
314+ if token_amount_in == 0 :
315+ raise Exception ("ERR_MATH_APPROX" )
316+
317+ if token_amount_in > max_amount_in :
318+ raise Exception ("ERR_LIMIT_IN" )
319+
320+ if token_amount_in > in_record .balance * MAX_IN_RATIO :
321+ raise Exception ("ERR_MAX_IN_RATIO" )
322+
323+ in_record .balance = in_record .balance + token_amount_in
324+ self ._mint_pool_share (pool_amount_out )
325+ # _pushPoolShare(msg.sender, poolAmountOut);
326+ # _pullUnderlying(tokenIn, msg.sender, tokenAmountIn);
327+
328+ return token_amount_in
329+
0 commit comments