-
Notifications
You must be signed in to change notification settings - Fork 288
Balancer swap #2290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Balancer swap #2290
Changes from all commits
46164e8
48866a9
c9aedf6
1bc3092
81eab8e
8bdafa7
b91ca21
f3daa79
ef71b3c
0fe9842
921ace4
9292044
30be6ea
22019e3
9c9b646
a27f1b5
afa0d45
243df1e
d2f9e2b
96402fd
6c55c7b
b8d5ffe
1c663f1
25a9e5d
213a984
b755f0e
26cca0b
7c51712
6ce98e2
483dcd4
3f152bf
fb9d494
72262b2
5fdc9f9
1cc1921
be6fd6f
1540d30
e75ee3a
e7b878c
49accc1
c4e21e7
f97e56c
7634aee
0bd3c78
9fed25e
ca466df
71995f0
cf5f277
b2744c8
1dd3e67
56c001e
c2bbe99
244fbfc
8d19821
80e9cec
fbb015c
65bb1c2
87fa1dc
b021c56
6723152
8d48806
55f9bba
485949d
9f5ca77
b4ecbc3
3b18a2e
a3756d9
06c2f71
3143a79
903848b
82c1fe7
682a4a9
7fdb0bf
2651ec1
3526657
77aa4b6
b0d9c98
e1ada50
84dc940
0729e36
a68189d
2a6e807
a67c9e7
fb0017f
f1b090d
7e8dc3a
4e21da2
a8579be
4c0f1f1
ab43e6b
7809143
def5b9d
b8559b0
c8b352f
5bdbd93
c09f6a6
e859f2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed U96F32 to U64F64 for representation of price. F64 has more fractional bits and prices are virtually never greater than 1000 anyway, which is way below u64::MAX. |
gztensor marked this conversation as resolved.
Show resolved
Hide resolved
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love cleaning. |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjust_protocol_liquidity returns the actual adjustment that needs to be made to reserves, which includes previously collected tao and alpha fees. When tao fees are charged, the tao is coming from user balance to FeesTao map, not accounted for in SubnetTAO, so it needs to be added here. When alpha fees are charged, the alpha is coming from user's stake, and is also not accounted for in SubnetAlphaIn. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,8 @@ impl<T: Config> Pallet<T> { | |
| let tao_to_swap_with: TaoCurrency = | ||
| tou64!(excess_tao.get(netuid_i).unwrap_or(&asfloat!(0))).into(); | ||
|
|
||
| T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); | ||
| let (actual_injected_tao, actual_injected_alpha) = | ||
| T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); | ||
|
|
||
| if tao_to_swap_with > TaoCurrency::ZERO { | ||
| let buy_swap_result = Self::swap_tao_for_alpha( | ||
|
|
@@ -87,15 +88,17 @@ impl<T: Config> Pallet<T> { | |
| AlphaCurrency::from(tou64!(*alpha_in.get(netuid_i).unwrap_or(&asfloat!(0)))); | ||
| SubnetAlphaInEmission::<T>::insert(*netuid_i, alpha_in_i); | ||
| SubnetAlphaIn::<T>::mutate(*netuid_i, |total| { | ||
| *total = total.saturating_add(alpha_in_i); | ||
| // Reserves also received fees in addition to alpha_in_i | ||
| *total = total.saturating_add(actual_injected_alpha); | ||
| }); | ||
|
|
||
| // Inject TAO in. | ||
| let injected_tao: TaoCurrency = | ||
| tou64!(*tao_in.get(netuid_i).unwrap_or(&asfloat!(0))).into(); | ||
| SubnetTaoInEmission::<T>::insert(*netuid_i, injected_tao); | ||
| SubnetTAO::<T>::mutate(*netuid_i, |total| { | ||
| *total = total.saturating_add(injected_tao); | ||
| // Reserves also received fees in addition to injected_tao | ||
| *total = total.saturating_add(actual_injected_tao); | ||
| }); | ||
| TotalStake::<T>::mutate(|total| { | ||
| *total = total.saturating_add(injected_tao); | ||
|
|
@@ -140,7 +143,8 @@ impl<T: Config> Pallet<T> { | |
| log::debug!("alpha_emission_i: {alpha_emission_i:?}"); | ||
|
|
||
| // Get subnet price. | ||
| let price_i: U96F32 = T::SwapInterface::current_alpha_price(netuid_i.into()); | ||
| let price_i: U96F32 = | ||
| U96F32::saturating_from_num(T::SwapInterface::current_alpha_price(netuid_i.into())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any risk in this cast? I assume not because Greg is the type master.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The U64F64 -> U96F32 conversion only exists here because this PR changes the price from being U96F32 to U64F64: Less digits in its integer part and more digits in its fractional part. Nonetheless, for the purpose on run_coinbase it stays as it was before: U96F32. The risk is loss of lower 32 binary digits of fractional part of the price. The part of price below 0.000000000232831 is thrown away for calculating emissions. I don't think it's a big deal, tbh. But this is not introduced by this PR. It was always like this: We just never maintained the prices so precisely. |
||
| log::debug!("price_i: {price_i:?}"); | ||
|
|
||
| let mut tao_in_i: U96F32 = tao_emission_i; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using Sam's bigmath crate now to handle high precision exponents.