-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
309 lines (276 loc) · 14.3 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
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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/sandstone/bootstrap.min.css"
crossorigin="anonymous">
<link rel="stylesheet" href="css/site.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/decimal.min.js"
integrity="sha256-gyWhSVGau68+skcMqGaBZnm/lpoD7rswg/fGVZoOw2k=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"
integrity="sha384-ma9ivURrHX5VOB4tNq+UiGNkJoANH4EAJmhxd1mmDq0gKOv88wkKZOfRDOpXynwh"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-router/3.4.3/vue-router.min.js"
integrity="sha512-mVyZZ423iwLddhRdWCJeQSysHfnDZZPJRlY9HJI6/39e6D8Myz3nQCelJmSMOf8MOreTzWDmh8bYftrBnTau1Q=="
crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]"
integrity="sha384-Wg7bbwm5XaGZ9qYiWLSqRAYDj2jg3iEXPZDCeIVKwII7U48bjduw6+BdmWf5N3EE"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js"
integrity="sha384-ov1JhoOZ+CNgADocviQd7922YCzI4v0xlGUxWiVKBjwNOk/K+oDSbFiXEFpL4Cf1"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/@walletconnect/[email protected]" crossorigin="anonymous"></script>
<script src="js/abi-decode.js"></script>
<script src="js/ens.js"></script>
<script src="js/sushiswap.js"></script>
<script src="js/web3manager.js"></script>
<script src="js/site.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2GS82HFV5Q"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-2GS82HFV5Q');
</script>
</head>
<body class="bg">
<div id="app" class="d-none">
<web3 :manager='manager' :isglobal='true' :init='init' :poll='poll'></web3>
<div class="sticky-top">
<nav class="navbar navbar-light bg-light">
<router-link class="nav-link" to="/"><i class="fas fa-home"></i></router-link>
<router-link class="nav-link" to="/bento">Bento</router-link>
<router-link class="nav-link" to="/sushibar">Bar</router-link>
<router-link class="nav-link mr-auto" to="/timelock">Lock</router-link>
<div class="text-right d-none d-sm-block mr-2">
{{ ethBalance.print(18, 2) }} ETH
</div>
<div class="nav-item dropdown p-0">
<a class="nav-link dropdown-toggle p-0" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span v-if="!manager.address">Accounts</span>
<span v-else="">{{ manager.address.substr(0, 10) }}</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a v-for="address in manager.addresses" class="dropdown-item" @click="manager.address=address"
href="#">{{ address.substr(0, 10) }}</a>
<input v-on:keyup.enter="addCustomAddress" class="dropdown-item"
placeholder="Custom address"></a>
</div>
<div class="text-right d-sm-none">
{{ ethBalance.print(18, 2) }} ETH
</div>
</div>
</nav>
<nav class="navbar bg-dark py-1">
<div v-if="ethRate" class="navbar-text my-auto p-0" style="color: #eeeeee">ETH ${{ ethRate.print(6, 2) }}</div>
<div v-if="btcRate" class="navbar-text my-auto p-0" style="color: #eeeeee">BTC ${{ btcRate.print(6, 2) }}</div>
<div v-if="sushiRate" class="navbar-text my-auto p-0" style="color: #eeeeee">SUSHI ${{ sushiRate.print(6, 2) }}</div>
</nav>
<nav v-if="!manager.connected && manager.provider === 'WalletConnect'" class="navbar bg-dark py-1">
<p></p>
<button class="btn btn-primary" @click="connectWC">Reconnect WalletConnect</button>
</nav>
</div>
<div class="container-fluid">
<div class="text-center mt-3" v-if="!manager.address || manager.provider === 'None'">
<button class="btn btn-lg btn-primary" @click="connect">Connect Metamask</button>
<button class="btn btn-lg btn-primary" @click="connectWC">Connect WalletConnect</button>
</div>
<router-view v-if="assetManager && manager && manager.address" :address="manager.address"
:block="manager.block" :header="manager.header" :time="time" :manager="manager" :web3="manager.web3">
</router-view>
</div>
<footer class="text-center py-2" style="visibility: hidden;">
<div>Quickly flung together by <a href="https://twitter.com/Boring_Crypto">@Boring_Crypto</a>.
<div class="float-right mr-3"> <i class="fas fa-cog"></i></div>
</div>
</footer>
<footer class="fixed-bottom bg-light text-center py-2">
<div>Quickly flung together by <a href="https://twitter.com/Boring_Crypto">@Boring_Crypto</a>.
<div class="float-right mr-3"> <i class="fas fa-cog"></i></div>
</div>
</footer>
</div>
</body>
<script>
function createApp() {
Vue.prototype.abis = abis;
window.app = new Vue({
el: "#app",
router: new VueRouter({
routes: []
}),
data: {
time: 0,
manager: {
block: 0n,
address: null,
web3: null
},
assetManager: null,
assets: [],
ethBalance: 0n,
ethRate: 0n,
btcRate: 0n,
sushiRate: 0n
},
mounted: function () {
this.time = Date.now();
setInterval(() => this.time = Date.now(), 1000);
this.manager = new Web3Manager();
},
computed: {
tokens: function () {
return this.assetManager ? this.assetManager.allAssets.filter(a => a.handler == 'ERC20Handler') : [];
}
},
watch: {
'manager.address': async function () { if (this.assetManager) { await this.assetManager.onAddress() } }
},
methods: {
connect: async function () { this.manager.connect(); },
connectWC: async function () { this.manager.connectWC(); },
init: async function () {
this.assetManager = await new AssetManager(this.manager, this.assets).init();
},
poll: async function () {
await this.assetManager.poll();
let pair = this.manager.web3.contract("pair", this.manager.chainId == "0x1" ? "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852" : "0xbc30AaA8e99d0f0e435FC938034850c2fC77f753");
let reserves = rpcToObj(await pair.methods.getReserves().call());
if (this.manager.chainId == "0x1") {
this.ethRate = reserves._reserve1 * 1000000000000000000n / reserves._reserve0;
} else {
this.ethRate = reserves._reserve0 * 1000000000000000000n / reserves._reserve1;
}
pair = this.manager.web3.contract("pair", this.manager.chainId == "0x1" ? "0xbb2b8038a1640196fbe3e38816f3e67cba72d940" : "0x8Ae0289759c06fC1dE15d7BB374371a76C352469");
reserves = rpcToObj(await pair.methods.getReserves().call());
this.btcRate = (reserves._reserve1 * 100000000n / reserves._reserve0) * this.ethRate / 1000000000000000000n;
pair = this.manager.web3.contract("pair", this.manager.chainId == "0x1" ? "0x795065dcc9f64b5614c407a6efdc400da6221fb0" : "0x47e1ce10065636AA989c4BFD19b9ac695785B7f1");
reserves = rpcToObj(await pair.methods.getReserves().call());
this.sushiRate = (reserves._reserve1 * 1000000000000000000n / reserves._reserve0) * this.ethRate / 1000000000000000000n;
if (this.manager.address) {
if(this.manager.provider === "WalletConnect") {
const multicall = this.manager.web3.contract("multicall", "0x5eb3fa2dfecdde21c950813c665e9364fa609bd2");
this.ethBalance = BigInt(await multicall.methods.getEthBalance(this.manager.address).call());
}
else {
this.ethBalance = BigInt(await this.manager.web3.eth.getBalance(this.manager.address));
}
}
},
addCustomAddress: function (e) {
address = e.target.value;
this.manager.addresses.push(address);
e.target.value = '';
},
}
})
Vue.prototype.app = window.app;
app.page = {};
$("#app").removeClass("d-none");
}
$(document).ready(async function () {
await load_component('erc20-view');
await load_component('xsushi-view');
await load_component('slp-view');
await load_component('univ2lp-view');
createApp();
await load_page('/', 'dashboard');
await load_page('/bento', 'bento');
await load_page('/bentopair/:address', 'bentopair');
await load_page('/sushibar', 'sushibar');
await load_page('/timelock', 'timelock');
await load_page('/stats', 'stats');
});
class AssetManager extends Web3Component {
constructor(options, assets) {
super(options);
if (!assets) {
assets = []
}
this.handlers = [];
this._handlerMap = {};
this.allAssets = [];
this._allAssetsMap = {};
this.assets = assets;
this._assetmap = {};
}
addHandler(handlerClass) {
let handler = new handlerClass(this);
this._handlerMap[handlerClass.name] = handler;
this.handlers.push(handler);
}
add(asset) {
asset.address = asset.address.toLowerCase();
asset.view = asset.view || "erc20";
asset.handler = asset.handler || this._handlerMap["ERC20Handler"];
if (this._assetmap[asset.address] && this._assetmap[asset.address].view == asset.view) return this._assetmap[asset.address];
if (this._allAssetsMap[asset.address]) {
asset.name = asset.name || this._allAssetsMap[asset.address].name;
asset.symbol = asset.symbol || this._allAssetsMap[asset.address].symbol;
asset.decimals = asset.decimals || this._allAssetsMap[asset.address].decimals;
}
asset.balance = asset.balance || 0n;
asset.hide_value = asset.hide_value || false;
this.assets.push(asset);
this._assetmap[asset.address] = asset;
return asset;
}
get(address) {
return this._assetmap[address.toLowerCase()];
}
async init() {
this.addHandler(ERC20Handler);
this.addHandler(XSushiHandler);
this.addHandler(SLPHandler);
this.addHandler(UniV2LPHandler);
// Get tokens from list
this.allAssets = (await $.ajax('tokenlist.json')).filter(a => a.chainId == this.chainId.slice(2)).map(a => {
a = rpcToObj(a);
a.handler = a.handler || "ERC20Handler";
this._allAssetsMap[a.address] = a;
return a;
});
for (let i in this.handlers) {
await this.handlers[i].init();
};
await this.onAddress();
return this;
}
async onAddress() {
if (this.address) {
for (let i in this.handlers) {
await this.handlers[i].find(this.address, this.allAssets);
};
for (let i in this.handlers) {
await this.handlers[i].info(this.assets.filter(a => a.handler == this.handlers[i]));
};
this.poll();
}
}
async poll() {
if (this.address) {
for (let i in this.handlers) {
await this.handlers[i].poll(this.address, this.assets.filter(a => a.handler == this.handlers[i]));
};
}
return this;
}
async getTokenInfo() {
await this._handlerMap["ERC20Handler"].info(this.assets.filter(a => a.handler == this._handlerMap[ERC20Handler]));
}
}
</script>
</html>