-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
180 lines (134 loc) · 6.06 KB
/
index.html
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
<!doctype html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Impermanent Loss Calculator</title>
<!--JQuery-->
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!--Bootstrap-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<style>
.navbar{
margin-bottom: 20px;
}
input{
width: 100%;
}
/* Code snippet to remove arrows from numeric fields */
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Firefox */
input[type=number] {
-moz-appearance: textfield;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">ImpLoss</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample03">
<ul class="navbar-nav me-auto mb-2 mb-sm-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="https://twitter.com/berkozero">Twitter</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container w-75">
<div class="row">
<h1>Impermanent Loss Calculator</h1>
</div>
<div class="row">
<p>Impermanent loss is a kind of opportunity cost of depositing your crypto assets (a pair of ERC-20 tokens)
to liquidity pools (such as <a href="https://uniswap.org/">Uniswap</a>) instead of holding them.
</p>
<p> Liquidity pools offer you additional income through trading fees and additional rewards but they also
cause an impermanent loss due to the changes in prices of the assets when you deposited them vs when
you withdraw them. This loss is made by arbitrageurs who buy one of your assets at a cheaper price than
any other platform.
</p>
</div>
<div class="row gy-1">
<div class="col-sm-3"><label for="t1o">Token 1 old price:</label></div>
<div class="col-sm-2"><input tabindex="1" class="functioninput" type="number" id="t1o" name="t1o"></div>
<div class="col-sm-7"></div>
</div>
<div class="row gy-2">
<div class="col-sm-3"><label class="" for="t2o">Token 2 old price:</label></div>
<div class="col-sm-2"><span class=""><input tabindex="2" class="functioninput" type="number" id="t2o" name="t2o"></span></div>
<div class="col-sm-7"></div>
</div>
<div class="row gy-1">
<div class="col-sm-3"><label class="" for="t1n">Token 1 new price:</label></div>
<div class="col-sm-2"><span class=""><input tabindex="3" class="functioninput" type="number" id="t1n" name="t1n"></span></div>
<div class="col-sm-1 text-center"><span class="">OR</span></div>
<div class="col-sm-2 text-nowrap"><span class=""><input tabindex="5" class="functioninput" type="number" id="t1np" name="t1np"> %</span></div>
<div class="col-sm-2"></div>
</div>
<div class="row gy-3">
<div class="col-sm-3"><label class="" for="t2n">Token 2 new price:</label></div>
<div class="col-sm-2"><span class=""><input tabindex="4" class="functioninput" type="number" id="t2n" name="t2n"></span></div>
<div class="col-sm-1 text-center"><span class="">OR</span></div>
<div class="col-sm-2 text-nowrap"><span class=""><input tabindex="6" class="functioninput" type="number" id="t2np" name="t2np"> %</span></div>
<div class="col-sm-2"></div>
</div>
<div class="row gy-3">
<div class="result my-5 col-sm-12">
Impermanent loss: <span style="font-weight: bold;" id="imploss"></span>
</div>
</div>
</div>
<script>
var round3 = function(num){
return Math.round(num*1000)/1000.0;
};
$('.functioninput').on("input", function(event){
console.log('test');
var t1o = $('#t1o').val();
var t2o = $('#t2o').val();
if(this.id === "t1np"){
var t1n = $("#t1o").val() * (1 + $("#t1np").val() / 100.0);
$("#t1n").val(round3(t1n));
}
else if(this.id === "t2np"){
var t2n = $("#t2o").val() * (1 + $("#t2np").val() / 100.0);
$("#t2n").val(round3(t2n));
}
else if(this.id === "t1n"){
t1n = $("#t1n").val();
$("#t1np").val(round3((t1n/t1o-1) * 100.0));
}
else if(this.id === "t2n"){
t2n = $("#t2n").val();
$("#t2np").val(round3((t2n/t2o-1) * 100.0));
}
var t1n = $('#t1n').val();
var t2n = $('#t2n').val();
var r1 = t1n/t1o;
var r2 = t2n/t2o;
c = r1/r2;
impl = 1 - (2 * Math.sqrt(c)/(1+c));
if(!isNaN(impl)){
$('#imploss').html(String(Math.round(impl*10000)/100) + "%");
}
else{
$('#imploss').html("");
}
console.log(String(impl));
console.log(event.target.nodeName);
console.log(this.id);
});
</script>
</body>
</html>