-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdip002.html
More file actions
516 lines (468 loc) · 21.3 KB
/
dip002.html
File metadata and controls
516 lines (468 loc) · 21.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./src/css/vote.css" id="changecss">
<link rel="shortcut icon" href="./favicon.ico">
<style>
@font-face {
font-family: NotoSansHans-Regular;
src: url('./src/font/NotoSansHans.otf')
}
</style>
<title>vote</title>
</head>
<body>
<div class="top">
<div class="top_box">
<div class="left">
<img src="./src/images/devcon_ticket_logo.png" alt="" srcset="">
</div>
<div class="right">
<div class="to_connect top_connect_btn">Connect</div>
</div>
<div class="clear"></div>
<div class="top_title">
dForce Improvement Proposal 001 (DIP001)<br />
Integration of Yield Enhancing Protocol with USDx
</div>
<!-- <div class="top_details">In an attempt to improve stability of USDx and ensure dollar redeemability, we would like to propose a change to remove DAI
</div> -->
<div class="top_details">
It is proposed to unlock up to 90% of constituent collaterals and re-supply them
into the lending protocol of dForce (or similar designated protocols like Compound, dYdX, and etc) to
earn yield. By doing so, USDx holders are entitled to a systematic interest by simply depositing
USDx into USR (USDx Saving Rate).
<a href="https://medium.com/dforcenet/dforce-improvement-proposal-001-dip001-a78dc740841e"
target="_blank">
More...
</a>
</div>
</div>
</div>
<!-- ———————————————————————— 华丽的分割线 ———————————————————————— -->
<div class="main">
<div class="main_left">
<div class="m_title">Action Required: Please Vote Here</div>
<div class="addPlus">(Start from 12:00 UTC+8 26 Feb 2020)</div>
<div class="m_choosen">
<img src="./src/images/vote_is_choosen.svg" alt="" srcset="" class="ichoiceA">
<span>Vote A: Yes</span>
</div>
<div class="m_choosen">
<img src="./src/images/vote_not_choosen.svg" alt="" srcset="" class="ichoiceB">
<span>Vote B: No</span>
</div>
<div class="vote_btn">VOTE</div>
</div>
<div class="main_right">
<p class="details">Details</p>
<p class="time">End in: <span class="time_days">0</span> DAYS : <span class="time_hours">0</span> HOURS :
<span class="time_min">0</span> MINUTES</p>
<div class="clear"></div>
<div class="text_part">
<div class="t_left">% Percentage of DF participated</div>
<div class="t_right"><span class="totalPersent">...</span><span style="margin-left: 25px;"
class="totalVVV">...</span></div>
</div>
<div class="clear"></div>
<div class="connect bottom_connect_btn" style='display: none'>CONNECT</div>
<div class="i_am_bili" style='display: none'>
<div class="yes">
<span>YES</span>
<span class="yesPersent">50%</span>
</div>
<div class="no">
<span>NO</span>
<span class="noPersent">50%</span>
</div>
</div>
<div class="text_part">
<div class="t_left">Your Address</div>
<div class="t_right my_source">...</div>
</div>
<div class="text_part">
<div class="t_left">Vote for</div>
<div class="t_right my_option">...</div>
</div>
<div class="clear"></div>
<div class="text_part">
<div class="t_left">Amount in DF</div>
<div class="t_right vote_amount">...</div>
</div>
</div>
<div class="clear"></div>
</div>
<!-- ———————————————————————— 华丽的分割线 ———————————————————————— -->
<div class="bottom">
<div class="b_title">
Voting mechanism
</div>
<ul>
<li>The governance poll will last for 3 days from 26 to 29 February.</li>
<li>
Proposal will be implemented if the following requirements are satisfied:
<br />
-Quorum: >1.5% of total DF tokens at the end of the voting period need to have participated in the
voting
<br />
-Threshold: >50% of the DF tokens that participated in the voting need to have voted ‘Yes’ for the
proposal (If the voting result is tied, the
proposal won’t be implemented.)
</li>
<li>Governance decision will be disclosed through Medium and Twitter on 1 March.</li>
</ul>
</div>
<div class="bottom">
<div class="b_title">
Join us for online discussion! We'd love to hear your voice!
</div>
<ul>
<li>Telegram: <a href="https://t.me/dforcenet" target="_blank">https://t.me/dforcenet</a> </li>
<li>Twitter: <a href="https://twitter.com/dForcenet" target="_blank">@dForcenet</a> </li>
<li>Discord: <a href="https://discord.gg/Gbtd3MR" target="_blank">https://discord.gg/Gbtd3MR</a> </li>
<li>Reddit: <a href="https://www.reddit.com/r/dForceNetwork/"
target="_blank">https://www.reddit.com/r/dForceNetwork/</a> </li>
</ul>
</div>
</body>
<script src="./src/js/jquery.min.js"></script>
<script src="./src/js/static_vote.js"></script>
<script>
// account
$(function () {
if (typeof window.web3 === 'undefined') {
return false;
}
var contractVote = web3.eth.contract(abiVote).at(addressVote);
var contractDF = web3.eth.contract(abiDF).at(addressDF);
var myAccount;
var myAccountShort;
var isConnected;
var isVote;
var i_choice_AorB = 'A';
var total_A = 0;
var total_B = 0;
window.ethereum.on('accountsChanged', () => {
console.log('00000000000000000000');
// location.reload();
// window.location.replace("http://192.168.200.109:9991/dforce/vote.html")
connect_metamask();
setTimeout(() => {
check_isVote();
}, 500)
});
connect_metamask();
get_end_time();
$(".noPersent").html('-')
$(".yesPersent").html('-')
var timer = setInterval(function () {
getTotalVote();
}, 1000 * 1);
// 点击投票
$(".vote_btn").click(function () {
// if (isVote !== 0 || !isConnected) {
// return false;
// }
vote();
})
$(".top_connect_btn").click(function () {
connect_metamask();
})
$(".bottom_connect_btn").click(function () {
connect_metamask();
})
$(".ichoiceA").click(function () {
console.log('aaaaa');
i_choice_AorB = 'A';
$(".ichoiceA").attr('src', './src/images/vote_is_choosen.svg');
$(".ichoiceB").attr('src', './src/images/vote_not_choosen.svg');
})
$(".ichoiceB").click(function () {
console.log('bbbbb');
i_choice_AorB = 'B';
$(".ichoiceA").attr('src', './src/images/vote_not_choosen.svg');
$(".ichoiceB").attr('src', './src/images/vote_is_choosen.svg');
})
function vote() {
var num = 1; // yes
if (i_choice_AorB === 'B') {
num = 2; // no
}
contractVote.vote.sendTransaction(num, { from: myAccount }, (err, ret) => {
if (ret) {
// 投票成功 返回哈希
console.log(ret);
$(".vote_btn").html('VOTED').css({ 'background': 'rgba(217,216,233,1)', 'color': 'rgba(129,126,152,1)' });
var approveUSDxtimer = setInterval(() => {
web3.eth.getTransactionReceipt(ret, (err, data) => {
if (data && data.status === '0x1') {
clearInterval(approveUSDxtimer);
if (i_choice_AorB === 'A') {
$(".my_option").html('YES');
}
if (i_choice_AorB === 'B') {
$(".my_option").html('NO');
}
$(".my_source").html(window.web3.eth.accounts[0]);
contractDF.balanceOf.call(myAccount, (err, ret) => {
if (ret) {
console.log(ret);
$(".vote_amount").html(formatNumber(ret));
}
})
setTimeout(() => { check_isVote() }, 3000)
}
})
}, 2000);
}
})
}
function getTotalVote() {
contractVote.getTotalVote.call(1, (err, res_A) => {
if (res_A) {
contractVote.getTotalVote.call(2, (err, res_B) => {
total_A = formatNumber_number(res_A);
total_B = formatNumber_number(res_B);
var total_VOTE = total_A + total_B;
if (total_VOTE === 0) {
return false;
}
$(".totalPersent").html((Number((total_VOTE / 1000000000).toFixed(4)) * 100).toString() + '%')
var showNum = total_VOTE.toString();
if (showNum.indexOf('.') > 0) {
var a = showNum.substring(0, showNum.indexOf('.'));
a = toQfw(a);
var b = showNum.substring(showNum.indexOf('.'), showNum.length)
showNum = a + b;
}
// console.log(typeof showNum)
$(".totalVVV").html(showNum)
if (showNum.indexOf('.') > 0) {
$(".totalVVV").html(showNum.substring(0, (showNum.indexOf('.') + 3)))
}
if (total_A / total_VOTE === 0) {
$(".yes").css('display', 'none')
$(".no").css('width', '100%')
$(".noPersent").html('100%')
return;
}
if (total_A / total_VOTE === 1) {
$(".no").css('display', 'none')
$(".yes").css('width', '100%')
$(".yesPersent").html('100%')
return;
}
var part_A = ((((total_A / (total_A + total_B)).toFixed(4)) * 100).toFixed(2)) + '%';
// var part_B = ((((total_B / (total_A + total_B)).toFixed(4)) * 100).toFixed(2)) + '%';
var part_B = (100 - (((total_A / (total_A + total_B)).toFixed(4)) * 100).toFixed(2)) + '%';
// console.log('choice_A: ', total_A)
// console.log('choice_B: ', total_B)
$(".yes").css('display', 'block')
$(".no").css('display', 'block')
$(".yes").css('width', part_A)
$(".no").css('width', part_B)
$(".yesPersent").html(part_A)
$(".noPersent").html(part_B)
if (part_A.indexOf('.') > 0) {
if (part_A.substring(0, 5).indexOf('%') > 0) {
// $(".yesPersent").html(part_A.substring(0, 5))
if (part_A.substring(0, 5).split('.')[1].length === 2) {
var newStr = part_A.substring(0, 5).split('.')[1];
console.log(newStr)
var newStr1 = newStr.substring(0, newStr.indexOf('%'));
$(".yesPersent").html(part_A.substring(0, 5).split('.')[0] + '.' + newStr1 + '0%');
} else {
$(".yesPersent").html(part_A.substring(0, 5))
}
} else {
$(".yesPersent").html(part_A.substring(0, 5) + '%')
}
}
if (part_B.indexOf('.') > 0) {
if (part_B.substring(0, 5).indexOf('%') > 0) {
// $(".noPersent").html(part_B.substring(0, 5))
if (part_B.substring(0, 5).split('.')[1].length === 2) {
var newStr = part_B.substring(0, 5).split('.')[1];
console.log(newStr)
var newStr1 = newStr.substring(0, newStr.indexOf('%'));
$(".noPersent").html(part_B.substring(0, 5).split('.')[0] + '.' + newStr1 + '0%');
} else {
$(".noPersent").html(part_B.substring(0, 5))
}
} else {
$(".noPersent").html(part_B.substring(0, 5) + '%')
}
}
if ((total_A / total_VOTE) < 0.1) {
$(".yes").css('width', '10%')
$(".no").css('width', '90%')
}
if ((total_A / total_VOTE) > 0.9) {
$(".yes").css('width', '90%')
$(".no").css('width', '10%')
}
if ((total_A / total_VOTE) < 0.0001) {
$(".yesPersent").html('0.01%')
$(".noPersent").html('99.99%')
}
if ((total_B / total_VOTE) < 0.0001) {
$(".noPersent").html('0.01%')
$(".yesPersent").html('99.99%')
}
})
}
})
}
function connect_metamask() {
web3.currentProvider.enable().then(
res => {
console.log('myAccount: ', res[0]);
isConnected = true;
myAccount = res[0];
myAccountShort = myAccount.substring(0, 4) + '...' + myAccount.substring(myAccount.length - 4);
$(".top_connect_btn").html(myAccountShort).css({ 'background': 'none', 'color': 'rgba(7,2,55,1)' });
$(".bottom_connect_btn").css('display', 'none');
$(".i_am_bili").css('display', 'block');
check_isVote();
},
err => {
console.log(err);
}
)
}
function check_isVote() {
contractVote.isVote.call(myAccount, (err, res) => {
isVote = Number(res);
if (isVote === 0) {
// alert(isVote)
console.log('not vote yet.');
$(".vote_amount").html('...');
$(".my_source").html('...');
$(".my_option").html('...');
$(".vote_btn").html('VOTE').css({ 'background': 'rgba(213, 162, 78, 1)', 'color': '#fff' });
} else {
$(".vote_btn").html('VOTED').css({ 'background': 'rgba(217,216,233,1)', 'color': 'rgba(129,126,152,1)' });
if (isVote === 1) {
$(".my_option").html('YES');
}
if (isVote === 2) {
$(".my_option").html('NO');
}
$(".my_source").html(myAccount);
contractDF.balanceOf.call(myAccount, (err, ret) => {
if (ret) {
console.log('amount in DF: ', ret.toString());
$(".vote_amount").html(formatNumber(ret));
}
})
}
})
}
function get_end_time() {
contractVote.endTime.call((err, res_time) => {
console.log(Number(res_time))
if (res_time) {
setInterval(function () {
var nowTime = new Date();
var endTime = new Date(Number(res_time) * 1000);
var t = endTime.getTime() - nowTime.getTime();
var hour = Math.floor(t / 1000 / 60 / 60 % 24);
var d = Math.floor(t / 1000 / 60 / 60 / 24);
var min = Math.floor(t / 1000 / 60 % 60);
var sec = Math.floor(t / 1000 % 60);
if (hour < 10) {
hour = "0" + hour;
}
if (hour == 24) {
hour = "00";
}
if (min < 10) {
min = "0" + min;
}
var countDownTime = d + ":" + hour + ":" + min;
// console.log(countDownTime)
$('.time_days').html(d);
$('.time_hours').html(hour);
$('.time_min').html(min);
}, 1000);
}
})
}
// str.replace(/(\d{1,3})(?=(\d{3})+$)/g,"$1,")
function formatNumber(BNr) {
var originStr = '0';
if (BNr.toFixed() < (10 ** 15) && BNr.toFixed() > 0) {
return '0.00';
}
originStr = BNr.div(10 ** 18).toString(10);
if (originStr.indexOf('.') > 0) {
originStr = originStr.substr(0, originStr.indexOf('.') + 3);
if (originStr.length >= 12) {
originStr = originStr.substr(0, 11);
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,");
} else {
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,");
}
} else if (isNaN(originStr)) {
return '0.00'
} else {
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,") + '.00';
}
}
function formatNumber_bbbbbbbbbbbb(BNr) {
console.log(BNr)
var originStr = '0';
originStr = BNr.toString(10);
if (originStr.indexOf('.') > 0) {
originStr = originStr.substr(0, originStr.indexOf('.') + 3);
if (originStr.length >= 12) {
originStr = originStr.substr(0, 11);
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,");
} else {
console.log('111111111111111')
console.log(originStr)
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,");
}
} else if (isNaN(originStr)) {
console.log(originStr)
return '0.00'
} else {
return originStr.replace(/(\d{1,3})(?=(\d{3})+$)/g, "$1,") + '.00';
}
}
function toQfw(n) {
var str_n = n;
var result = "";
while (str_n.length > 3) {
result = "," + str_n.slice(-3) + result;
str_n = str_n.slice(0, str_n.length - 3)
}
if (str_n) {
return (str_n + result)
}
};
function formatNumber_number(BNr) {
var originStr = '0';
if (BNr.toFixed() < (10 ** 15) && BNr.toFixed() > 0) {
return 0;
}
originStr = BNr.div(10 ** 18).toString(10);
if (originStr.indexOf('.') > 0) {
originStr = originStr.substr(0, originStr.indexOf('.') + 3);
if (originStr.length >= 12) {
return originStr = Number(originStr.substr(0, 11));
} else {
return Number(originStr);
}
} else if (isNaN(originStr)) {
return 0
} else {
return Number(originStr);
}
}
})
</script>
</html>