-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbonding-curve.html
More file actions
551 lines (515 loc) · 16.5 KB
/
bonding-curve.html
File metadata and controls
551 lines (515 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bonding Curve Explorer</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
color: #e4e4e4;
min-height: 100vh;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #00d9ff;
margin-bottom: 10px;
}
.subtitle {
text-align: center;
color: #888;
margin-bottom: 30px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.main-layout {
display: grid;
grid-template-columns: 300px 1fr;
gap: 20px;
align-items: start;
}
.sidebar {
display: flex;
flex-direction: column;
gap: 16px;
}
@media (max-width: 800px) {
.main-layout {
grid-template-columns: 1fr;
}
}
.card {
background: rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.chart-card {
display: flex;
flex-direction: column;
}
.controls {
display: flex;
flex-direction: column;
gap: 16px;
}
.control-group {
display: flex;
flex-direction: column;
gap: 8px;
}
label {
font-size: 14px;
color: #aaa;
}
input[type="range"] {
width: 100%;
height: 8px;
border-radius: 4px;
background: #333;
outline: none;
-webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #00d9ff;
cursor: pointer;
box-shadow: 0 0 10px rgba(0, 217, 255, 0.5);
}
select {
padding: 10px;
border-radius: 8px;
border: 1px solid #444;
background: #2a2a3e;
color: #e4e4e4;
font-size: 14px;
cursor: pointer;
}
.value-display {
font-size: 18px;
font-weight: bold;
color: #00d9ff;
}
canvas {
width: 100%;
aspect-ratio: 1 / 1;
max-height: 70vh;
border-radius: 12px;
background: rgba(0, 0, 0, 0.3);
}
.stats {
display: flex;
flex-direction: column;
gap: 12px;
}
.stat {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
background: rgba(0, 217, 255, 0.1);
border-radius: 8px;
}
.stat-value {
font-size: 18px;
font-weight: bold;
color: #00d9ff;
}
.stat-label {
font-size: 13px;
color: #888;
}
.formula {
text-align: center;
padding: 16px;
background: rgba(0, 0, 0, 0.3);
border-radius: 8px;
font-family: 'Courier New', monospace;
color: #ff9f43;
font-size: 18px;
}
.marker-info {
margin-top: 16px;
padding: 12px;
background: rgba(255, 159, 67, 0.1);
border-radius: 8px;
border-left: 3px solid #ff9f43;
}
.buy-sell {
display: flex;
gap: 8px;
margin-top: 8px;
}
.buy-sell button {
flex: 1;
padding: 10px 16px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: transform 0.1s, opacity 0.1s;
}
.buy-sell button:hover {
transform: scale(1.02);
}
.buy-sell button:active {
transform: scale(0.98);
}
.buy-sell button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.btn-sell {
background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
color: white;
}
.btn-buy {
background: linear-gradient(135deg, #51cf66, #40c057);
color: white;
}
.stat.reserve {
background: rgba(255, 159, 67, 0.15);
}
.stat.reserve .stat-value {
color: #ff9f43;
}
</style>
</head>
<body>
<div class="container">
<a href="index.html" style="color: #00d9ff; text-decoration: none; font-size: 18px; display: inline-block; margin-bottom: 8px;" title="Home">
🏠
</a>
<h1>Bonding Curve Explorer</h1>
<p class="subtitle">See how token price changes based on supply</p>
<div class="main-layout">
<div class="sidebar">
<div class="card">
<div class="formula" id="formula">Price = Supply²</div>
</div>
<div class="card">
<div class="controls">
<div class="control-group">
<label>Curve Type</label>
<select id="curveType">
<option value="linear">Linear (x)</option>
<option value="quadratic">Quadratic (x²)</option>
<option value="cubic">Cubic (x³)</option>
<option value="sqrt">Square Root (√x)</option>
<option value="exponential">Exponential (eˣ)</option>
</select>
</div>
<div class="control-group">
<label>Current Supply: <span class="value-display" id="supplyValue">100</span></label>
<input type="range" id="supply" min="1" max="200" value="100">
<div class="buy-sell">
<button class="btn-sell" id="sellBtn" onclick="sell()">Sell 10</button>
<button class="btn-buy" id="buyBtn" onclick="buy()">Buy 10</button>
</div>
</div>
<div class="control-group">
<label>Curve Steepness: <span class="value-display" id="steepnessValue">1.0</span></label>
<input type="range" id="steepness" min="0.1" max="3" step="0.1" value="1">
</div>
</div>
</div>
<div class="card">
<div class="stats">
<div class="stat">
<div class="stat-label">Current Price</div>
<div class="stat-value" id="currentPrice">—</div>
</div>
<div class="stat reserve">
<div class="stat-label">Total Reserve</div>
<div class="stat-value" id="totalReserve">—</div>
</div>
<div class="stat">
<div class="stat-label">Market Cap</div>
<div class="stat-value" id="marketCap">—</div>
</div>
<div class="stat">
<div class="stat-label">Next Token Cost</div>
<div class="stat-value" id="nextTokenCost">—</div>
</div>
</div>
</div>
</div>
<div class="card chart-card">
<canvas id="chart"></canvas>
<div class="marker-info">
<strong>Current Position:</strong> At supply of <span id="markerSupply">100</span> tokens,
the price is <span id="markerPrice" style="color: #00d9ff; font-weight: bold;">—</span>
</div>
</div>
</div>
</div>
<script>
const canvas = document.getElementById('chart');
const ctx = canvas.getContext('2d');
// High DPI support
function setupCanvas() {
const rect = canvas.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
ctx.scale(dpr, dpr);
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
}
const curveType = document.getElementById('curveType');
const supplySlider = document.getElementById('supply');
const steepnessSlider = document.getElementById('steepness');
const supplyValue = document.getElementById('supplyValue');
const steepnessValue = document.getElementById('steepnessValue');
const MAX_SUPPLY = 200;
function buy() {
const newValue = Math.min(MAX_SUPPLY, parseInt(supplySlider.value) + 10);
supplySlider.value = newValue;
supplyValue.textContent = newValue;
draw();
}
function sell() {
const newValue = Math.max(1, parseInt(supplySlider.value) - 10);
supplySlider.value = newValue;
supplyValue.textContent = newValue;
draw();
}
function calculateReserve(supply, type, steepness) {
let reserve = 0;
for (let i = 1; i <= supply; i++) {
reserve += calculatePrice(i, type, steepness);
}
return reserve;
}
function calculatePrice(supply, type, steepness) {
switch(type) {
case 'linear':
return steepness * supply;
case 'quadratic':
return steepness * Math.pow(supply, 2);
case 'cubic':
return steepness * Math.pow(supply, 3);
case 'sqrt':
return steepness * Math.sqrt(supply);
case 'exponential':
return steepness * (Math.exp(supply / 50) - 1);
default:
return steepness * supply;
}
}
function formatNumber(n) {
if (n >= 1000000) return (n / 1000000).toFixed(1) + 'M';
if (n >= 1000) return (n / 1000).toFixed(1) + 'K';
if (n >= 10) return n.toFixed(0);
if (n >= 1) return n.toFixed(1);
return n.toFixed(2);
}
function getMaxPrice(type) {
// Max price at MAX_SUPPLY with steepness=1
switch(type) {
case 'linear':
return MAX_SUPPLY; // 200
case 'quadratic':
return Math.pow(MAX_SUPPLY, 2); // 40000
case 'cubic':
return Math.pow(MAX_SUPPLY, 3); // 8000000
case 'sqrt':
return Math.sqrt(MAX_SUPPLY); // ~14.14
case 'exponential':
return Math.exp(MAX_SUPPLY / 50) - 1; // ~53.6
default:
return MAX_SUPPLY;
}
}
function getFormula(type, steepness) {
const k = steepness.toFixed(1);
switch(type) {
case 'linear':
return `Price = ${k} × Supply`;
case 'quadratic':
return `Price = ${k} × Supply²`;
case 'cubic':
return `Price = ${k} × Supply³`;
case 'sqrt':
return `Price = ${k} × √Supply`;
case 'exponential':
return `Price = ${k} × (e^(Supply/50) − 1)`;
default:
return 'Price = f(Supply)';
}
}
function draw() {
setupCanvas();
const rect = canvas.getBoundingClientRect();
const width = rect.width;
const height = rect.height;
const padding = 50;
const type = curveType.value;
const supply = parseInt(supplySlider.value);
const steepness = parseFloat(steepnessSlider.value);
// Clear canvas
ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
ctx.fillRect(0, 0, width, height);
// Y-axis scale based on curve type (reaches top at steepness=1)
const maxPrice = getMaxPrice(type) * 1.1; // 10% padding
// Draw grid lines
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i <= 5; i++) {
const y = padding + (height - 2 * padding) * (1 - i / 5);
ctx.beginPath();
ctx.moveTo(padding, y);
ctx.lineTo(width - padding, y);
ctx.stroke();
}
for (let i = 0; i <= 5; i++) {
const x = padding + (width - 2 * padding) * i / 5;
ctx.beginPath();
ctx.moveTo(x, padding);
ctx.lineTo(x, height - padding);
ctx.stroke();
}
// Clip region for the curve (so it doesn't overflow)
ctx.save();
ctx.beginPath();
ctx.rect(padding, padding, width - 2 * padding, height - 2 * padding);
ctx.clip();
// Draw filled area under full curve (faded)
ctx.beginPath();
ctx.moveTo(padding, height - padding);
for (let i = 1; i <= MAX_SUPPLY; i++) {
const x = padding + (width - 2 * padding) * (i / MAX_SUPPLY);
const price = calculatePrice(i, type, steepness);
const y = height - padding - (height - 2 * padding) * (price / maxPrice);
ctx.lineTo(x, y);
}
ctx.lineTo(width - padding, height - padding);
ctx.closePath();
ctx.fillStyle = 'rgba(0, 217, 255, 0.08)';
ctx.fill();
// Draw reserve area (up to current supply)
ctx.beginPath();
ctx.moveTo(padding, height - padding);
for (let i = 1; i <= supply; i++) {
const x = padding + (width - 2 * padding) * (i / MAX_SUPPLY);
const price = calculatePrice(i, type, steepness);
const y = height - padding - (height - 2 * padding) * (price / maxPrice);
ctx.lineTo(x, y);
}
const endX = padding + (width - 2 * padding) * (supply / MAX_SUPPLY);
ctx.lineTo(endX, height - padding);
ctx.closePath();
const reserveGradient = ctx.createLinearGradient(0, padding, 0, height - padding);
reserveGradient.addColorStop(0, 'rgba(255, 159, 67, 0.4)');
reserveGradient.addColorStop(1, 'rgba(255, 159, 67, 0.1)');
ctx.fillStyle = reserveGradient;
ctx.fill();
// Draw curve
ctx.beginPath();
ctx.strokeStyle = '#00d9ff';
ctx.lineWidth = 3;
for (let i = 1; i <= MAX_SUPPLY; i++) {
const x = padding + (width - 2 * padding) * (i / MAX_SUPPLY);
const price = calculatePrice(i, type, steepness);
const y = height - padding - (height - 2 * padding) * (price / maxPrice);
if (i === 1) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
// Draw current position marker
const currentPrice = calculatePrice(supply, type, steepness);
const markerX = padding + (width - 2 * padding) * (supply / MAX_SUPPLY);
const markerY = height - padding - (height - 2 * padding) * (currentPrice / maxPrice);
// Vertical line to marker
ctx.beginPath();
ctx.strokeStyle = 'rgba(255, 159, 67, 0.5)';
ctx.lineWidth = 2;
ctx.setLineDash([5, 5]);
ctx.moveTo(markerX, height - padding);
ctx.lineTo(markerX, markerY);
ctx.stroke();
// Horizontal line to marker
ctx.beginPath();
ctx.moveTo(padding, markerY);
ctx.lineTo(markerX, markerY);
ctx.stroke();
ctx.setLineDash([]);
// Marker dot
ctx.beginPath();
ctx.arc(markerX, markerY, 10, 0, Math.PI * 2);
ctx.fillStyle = '#ff9f43';
ctx.fill();
ctx.strokeStyle = '#fff';
ctx.lineWidth = 2;
ctx.stroke();
// Restore from clipping
ctx.restore();
// Draw axis labels (outside clipping region)
for (let i = 0; i <= 5; i++) {
const y = padding + (height - 2 * padding) * (1 - i / 5);
ctx.fillStyle = '#666';
ctx.font = '12px sans-serif';
ctx.textAlign = 'right';
ctx.fillText(formatNumber(maxPrice * i / 5), padding - 10, y + 4);
}
for (let i = 0; i <= 5; i++) {
const x = padding + (width - 2 * padding) * i / 5;
ctx.fillStyle = '#666';
ctx.font = '12px sans-serif';
ctx.textAlign = 'center';
ctx.fillText((MAX_SUPPLY / 5 * i).toFixed(0), x, height - padding + 20);
}
// Axis titles
ctx.fillStyle = '#888';
ctx.font = '14px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('Supply', width / 2, height - 10);
ctx.save();
ctx.translate(15, height / 2);
ctx.rotate(-Math.PI / 2);
ctx.fillText('Price', 0, 0);
ctx.restore();
// Update stats
const nextPrice = calculatePrice(supply + 1, type, steepness);
const totalReserve = calculateReserve(supply, type, steepness);
document.getElementById('currentPrice').textContent = formatNumber(currentPrice);
document.getElementById('totalReserve').textContent = formatNumber(totalReserve);
document.getElementById('marketCap').textContent = formatNumber(currentPrice * supply);
document.getElementById('nextTokenCost').textContent = formatNumber(nextPrice);
document.getElementById('markerSupply').textContent = supply;
document.getElementById('markerPrice').textContent = formatNumber(currentPrice);
document.getElementById('formula').textContent = getFormula(type, steepness);
// Update button states
document.getElementById('sellBtn').disabled = supply <= 10;
document.getElementById('buyBtn').disabled = supply >= MAX_SUPPLY - 9;
}
// Event listeners
curveType.addEventListener('change', draw);
supplySlider.addEventListener('input', () => {
supplyValue.textContent = supplySlider.value;
draw();
});
steepnessSlider.addEventListener('input', () => {
steepnessValue.textContent = parseFloat(steepnessSlider.value).toFixed(1);
draw();
});
// Handle resize
window.addEventListener('resize', draw);
// Initial draw
draw();
</script>
</body>
</html>