Skip to content

Commit 7b6a8d1

Browse files
authored
Price: Solve for correct revenue maximum (#118)
* Price: Solve for correct revenue maximum * Price: Nudge price closer to revenue maximization
1 parent 2d3e554 commit 7b6a8d1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/indexer_selection/price_efficiency.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,32 @@ impl PriceEfficiency {
7878
// And, given a w, we want to solve for p such that the derivative is 0.
7979
// This gives us the lower bound for the revenue maximizing price.
8080
//
81+
// Solving gives us the following:
82+
// https://www.desmos.com/calculator/of533qsdla
83+
//
8184
// I think this approximation is of a lower bound is reasonable
8285
// (better not to overestimate and hurt the indexer's revenue)
8386
// Solving for the correct revenue-maximizing value is complex and recursive (since the revenue
8487
// maximizing price depends on the utility of all other indexers which itself depends
8588
// on their revenue maximizing price... ad infinitum)
8689
//
87-
// TODO: I didn't solve for this generally over w yet. But, I know that if w is 0.5,
88-
// then the correct value is ~ 0.601. Since price utility weights
89-
// are currently hardcoded, then the closed solution over w can go in on the next iteration.
90-
let min_rate = GRT::try_from(0.6).unwrap();
90+
// Solve the equation (1/(x+n))-n for n to intersect axis at desired places
91+
let s = (-1.0 + 5.0f64.sqrt()) / 2.0;
92+
let w = weight;
93+
let min_rate =
94+
((4.0 * s.powi(2) * w + w.powi(2) - 2.0 * w + 1.0).sqrt() - 2.0 * s.powi(2) - w + 1.0)
95+
/ (2.0 * s);
96+
97+
let min_rate = GRT::try_from(min_rate).unwrap();
9198
let min_optimal_fee = *max_budget * min_rate;
9299
// If their fee is less than the min optimal, lerp between them so that
93100
// indexers are rewarded for being closer.
94101
if fee < min_optimal_fee {
95-
fee = (min_optimal_fee + fee) * GRT::try_from(0.5).unwrap();
102+
fee = (min_optimal_fee + fee) * GRT::try_from(0.75).unwrap();
96103
}
97104

105+
//
106+
98107
// I went over a bunch of options and am not happy with any of them.
99108
// Also this is hard to summarize but I'll take a shot.
100109
// It may help before explaining what this code does to understand
@@ -132,11 +141,9 @@ impl PriceEfficiency {
132141
// But my hunch is that the utility combining function captures this and it's ok
133142
// to have it be separate like this.
134143

135-
// Solve the equation (1/(x+n))-n for n to intersect axis at desired places
136-
let scale = (-1.0 + 5.0f64.sqrt()) / 2.0;
137144
let one_wei: GRT = GRTWei::try_from(1u64).unwrap().shift();
138145
let scaled_fee = fee / max_budget.saturating_add(one_wei);
139-
let mut utility = (1.0 / (scaled_fee.as_f64() + scale)) - scale;
146+
let mut utility = (1.0 / (scaled_fee.as_f64() + s)) - s;
140147
// Set minimum utility, since small negative utility can result from loss of precision when the fee approaches the budget.
141148
utility = utility.max(1e-18);
142149

0 commit comments

Comments
 (0)