1
1
use std:: { convert:: TryInto , ops:: Sub , str:: FromStr } ;
2
2
3
3
use cosmwasm_std:: { Coin , Decimal , Deps , StdError , StdResult , Uint128 , QueryRequest } ;
4
- use osmo_bindings:: { OsmosisQuery , PoolStateResponse } ;
4
+ use osmo_bindings:: { OsmosisQuery , PoolStateResponse } ;
5
5
6
6
pub fn osmosis_calculate_join_pool_shares (
7
7
deps : Deps < OsmosisQuery > ,
@@ -95,11 +95,11 @@ fn calc_join_pool_shares_double_sided(
95
95
96
96
// feeRatio returns the fee ratio that is defined as follows:
97
97
// 1 - ((1 - normalizedTokenWeightOut) * swapFee)
98
- fn fee_ratio ( normalized_weight : Decimal , swap_fee : Decimal ) -> Decimal {
98
+ fn _fee_ratio ( normalized_weight : Decimal , swap_fee : Decimal ) -> Decimal {
99
99
Decimal :: one ( ) . sub ( Decimal :: one ( ) . sub ( normalized_weight) * swap_fee)
100
100
}
101
101
102
- fn calc_join_pool_shares_single_sided (
102
+ fn _calc_join_pool_shares_single_sided (
103
103
token_in : & Coin ,
104
104
total_shares : Uint128 ,
105
105
provided_asset_pool_balance : Uint128 ,
@@ -128,8 +128,8 @@ fn calc_join_pool_shares_single_sided(
128
128
// sdk.OneDec()).Neg()
129
129
130
130
let token_in_amount_after_fee =
131
- token_in. amount * fee_ratio ( provided_asset_normalized_weight, swap_fee) ;
132
- let pool_amount_out = osmosis_solve_constant_function_invariant (
131
+ token_in. amount * _fee_ratio ( provided_asset_normalized_weight, swap_fee) ;
132
+ let pool_amount_out = _osmosis_solve_constant_function_invariant (
133
133
provided_asset_pool_balance. checked_add ( token_in_amount_after_fee) ?,
134
134
provided_asset_pool_balance,
135
135
provided_asset_normalized_weight,
@@ -238,7 +238,7 @@ pub fn osmosis_calculate_exit_pool_amounts(
238
238
/// The y_to_weight_ratio calculation is a workaround that works only for dual pools with
239
239
/// even weight of the two assets. Go function in osmosis code can be found here:
240
240
/// https://github.com/osmosis-labs/osmosis/blob/main/x/gamm/pool-models/balancer/amm.go#L94
241
- fn osmosis_solve_constant_function_invariant (
241
+ fn _osmosis_solve_constant_function_invariant (
242
242
token_balance_fixed_before : Uint128 ,
243
243
token_balance_fixed_after : Uint128 ,
244
244
token_weight_fixed : Decimal ,
@@ -258,13 +258,13 @@ fn osmosis_solve_constant_function_invariant(
258
258
// paranthetical := sdk.OneDec().Sub(yToWeightRatio)
259
259
// amountY := tokenBalanceUnknownBefore.Mul(paranthetical)
260
260
// return amountY
261
- let y_to_weight_ratio = osmosis_pow ( y, weight_ratio) ?;
261
+ let y_to_weight_ratio = _osmosis_pow ( y, weight_ratio) ?;
262
262
let paranthetical = Decimal :: one ( ) - y_to_weight_ratio;
263
263
let amount_y = token_balance_unknown_before * paranthetical;
264
264
return Ok ( amount_y) ;
265
265
}
266
266
267
- fn osmosis_pow ( base : Decimal , exp : Decimal ) -> StdResult < Decimal > {
267
+ fn _osmosis_pow ( base : Decimal , exp : Decimal ) -> StdResult < Decimal > {
268
268
if base >= Decimal :: from_ratio ( 2u128 , 1u128 ) {
269
269
return Err ( StdError :: generic_err ( "base must be lesser than two" ) ) ;
270
270
}
@@ -288,15 +288,15 @@ fn osmosis_pow(base: Decimal, exp: Decimal) -> StdResult<Decimal> {
288
288
}
289
289
290
290
// fractionalPow := PowApprox(base, fractional, powPrecision)
291
- let fractional_pow = osmosis_pow_approx ( base, fractional, Decimal :: from_ratio ( 1u128 , 1u128 ) ) ;
291
+ let fractional_pow = _osmosis_pow_approx ( base, fractional, Decimal :: from_ratio ( 1u128 , 1u128 ) ) ;
292
292
293
293
// return integerPow.Mul(fractionalPow)
294
294
return Ok ( integer_pow. checked_mul ( fractional_pow) ?) ;
295
295
}
296
296
297
297
// Contract: 0 < base <= 2
298
298
// 0 <= exp < 1.
299
- fn osmosis_pow_approx ( base : Decimal , exp : Decimal , precision : Decimal ) -> Decimal {
299
+ fn _osmosis_pow_approx ( base : Decimal , exp : Decimal , precision : Decimal ) -> Decimal {
300
300
if exp. is_zero ( ) {
301
301
return Decimal :: one ( ) ;
302
302
}
@@ -341,7 +341,7 @@ fn osmosis_pow_approx(base: Decimal, exp: Decimal, precision: Decimal) -> Decima
341
341
// term := sdk.OneDec()
342
342
// sum := sdk.OneDec()
343
343
// negative := false
344
- let ( x, x_neg) = osmosis_abs_difference_with_sign ( base, Decimal :: one ( ) ) ;
344
+ let ( x, x_neg) = _osmosis_abs_difference_with_sign ( base, Decimal :: one ( ) ) ;
345
345
let mut term = Decimal :: one ( ) ;
346
346
let mut sum = Decimal :: one ( ) ;
347
347
let mut negative = false ;
@@ -363,7 +363,7 @@ fn osmosis_pow_approx(base: Decimal, exp: Decimal, precision: Decimal) -> Decima
363
363
// // To avoid expensive big.Int allocation, we reuse bigK variable.
364
364
// // On this line, bigK == i-1.
365
365
// c, cneg := AbsDifferenceWithSign(a, bigK)
366
- let ( c, c_neg) = osmosis_abs_difference_with_sign ( a, big_k) ;
366
+ let ( c, c_neg) = _osmosis_abs_difference_with_sign ( a, big_k) ;
367
367
368
368
// // On this line, bigK == i.
369
369
// bigK.Set(sdk.NewDec(i))
@@ -414,7 +414,7 @@ fn osmosis_pow_approx(base: Decimal, exp: Decimal, precision: Decimal) -> Decima
414
414
415
415
// AbsDifferenceWithSign returns | a - b |, (a - b).sign()
416
416
// a is mutated and returned.
417
- fn osmosis_abs_difference_with_sign ( a : Decimal , b : Decimal ) -> ( Decimal , bool ) {
417
+ fn _osmosis_abs_difference_with_sign ( a : Decimal , b : Decimal ) -> ( Decimal , bool ) {
418
418
if a >= b {
419
419
( a - b, false )
420
420
} else {
@@ -899,4 +899,4 @@ mod tests {
899
899
// })
900
900
// }
901
901
// }
902
- }
902
+ }
0 commit comments