File tree 2 files changed +22
-14
lines changed
2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -1302,13 +1302,17 @@ module initia_std::dex {
1302
1302
let time_diff_before = (timestamp - weights.weights_before.timestamp as u128 );
1303
1303
1304
1304
// 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
1312
1316
let coin_a_m = decimal128::new (decimal128::val (&weights.weights_after.coin_a_weight) * time_diff_before);
1313
1317
let coin_a_n = decimal128::new (decimal128::val (&weights.weights_before.coin_a_weight) * time_diff_after);
1314
1318
let coin_a_l = decimal128::add (&coin_a_m, &coin_a_n);
Original file line number Diff line number Diff line change @@ -1302,13 +1302,17 @@ module minitia_std::dex {
1302
1302
let time_diff_before = (timestamp - weights.weights_before.timestamp as u128 );
1303
1303
1304
1304
// 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
1312
1316
let coin_a_m = decimal128::new (decimal128::val (&weights.weights_after.coin_a_weight) * time_diff_before);
1313
1317
let coin_a_n = decimal128::new (decimal128::val (&weights.weights_before.coin_a_weight) * time_diff_after);
1314
1318
let coin_a_l = decimal128::add (&coin_a_m, &coin_a_n);
You can’t perform that action at this time.
0 commit comments