Skip to content

Commit fcf6a45

Browse files
authored
edit get weight comment to be more clearer (#39)
1 parent eb1cfbd commit fcf6a45

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

precompile/modules/initia_stdlib/sources/dex.move

+11-7
Original file line numberDiff line numberDiff line change
@@ -1302,13 +1302,17 @@ module initia_std::dex {
13021302
let time_diff_before = (timestamp - weights.weights_before.timestamp as u128);
13031303

13041304
// when timestamp_before < timestamp < timestamp_after
1305-
// weight = a * timestamp + b
1306-
// m = (a * timestamp_before + b) * (timestamp_after - timestamp)
1307-
// = a * t_b * t_a - a * t_b * t + b * t_a - b * t
1308-
// n = (a * timestamp_after + b) * (timestamp - timestamp_before)
1309-
// = a * t_a * t - a * t_a * t_b + b * t - b * t_b
1310-
// l = m + n = a * t * (t_a - t_b) + b * (t_a - t_b)
1311-
// weight = l / (t_a - t_b)
1305+
// weight is linearly change from before to after
1306+
//
1307+
// weight = g * timestamp + c
1308+
// where g is gradient of line and c is the weight-intercept (weight value when timestamp is 0)
1309+
//
1310+
// n = (g * timestamp_before + c) * (timestamp_after - timestamp)
1311+
// = g * t_b * t_a - g * t_b * t + c * t_a - c * t
1312+
// m = (g * timestamp_after + c) * (timestamp - timestamp_before)
1313+
// = g * t_a * t - g * t_a * t_b + c * t - c * t_b
1314+
// l = m + n = g * t * (t_a - t_b) + c * (t_a - t_b)
1315+
// weight = l / (t_a - t_b) = g * t + c
13121316
let coin_a_m = decimal128::new(decimal128::val(&weights.weights_after.coin_a_weight) * time_diff_before);
13131317
let coin_a_n = decimal128::new(decimal128::val(&weights.weights_before.coin_a_weight) * time_diff_after);
13141318
let coin_a_l = decimal128::add(&coin_a_m, &coin_a_n);

precompile/modules/minitia_stdlib/sources/dex.move

+11-7
Original file line numberDiff line numberDiff line change
@@ -1302,13 +1302,17 @@ module minitia_std::dex {
13021302
let time_diff_before = (timestamp - weights.weights_before.timestamp as u128);
13031303

13041304
// when timestamp_before < timestamp < timestamp_after
1305-
// weight = a * timestamp + b
1306-
// m = (a * timestamp_before + b) * (timestamp_after - timestamp)
1307-
// = a * t_b * t_a - a * t_b * t + b * t_a - b * t
1308-
// n = (a * timestamp_after + b) * (timestamp - timestamp_before)
1309-
// = a * t_a * t - a * t_a * t_b + b * t - b * t_b
1310-
// l = m + n = a * t * (t_a - t_b) + b * (t_a - t_b)
1311-
// weight = l / (t_a - t_b)
1305+
// weight is linearly change from before to after
1306+
//
1307+
// weight = g * timestamp + c
1308+
// where g is gradient of line and c is the weight-intercept (weight value when timestamp is 0)
1309+
//
1310+
// n = (g * timestamp_before + c) * (timestamp_after - timestamp)
1311+
// = g * t_b * t_a - g * t_b * t + c * t_a - c * t
1312+
// m = (g * timestamp_after + c) * (timestamp - timestamp_before)
1313+
// = g * t_a * t - g * t_a * t_b + c * t - c * t_b
1314+
// l = m + n = g * t * (t_a - t_b) + c * (t_a - t_b)
1315+
// weight = l / (t_a - t_b) = g * t + c
13121316
let coin_a_m = decimal128::new(decimal128::val(&weights.weights_after.coin_a_weight) * time_diff_before);
13131317
let coin_a_n = decimal128::new(decimal128::val(&weights.weights_before.coin_a_weight) * time_diff_after);
13141318
let coin_a_l = decimal128::add(&coin_a_m, &coin_a_n);

0 commit comments

Comments
 (0)