This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
auction.js
72 lines (66 loc) 路 1.9 KB
/
auction.js
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
import promiseAllProps from 'promise-all-props'
import wallet from './wallet'
import mtn from './mtn'
const auction = {}
const toInt = str => parseInt(str, 10)
auction.getStatus = function() {
const token = mtn.mtntoken.methods
const auctions = mtn.auctions.methods
return promiseAllProps({
currentAuction: auctions.currentAuction().call(),
currentPrice: auctions.currentPrice().call(),
genesisTime: auctions
.genesisTime()
.call()
.then(toInt),
globalMtnSupply: auctions.globalMtnSupply().call(),
lastPurchasePrice: auctions.lastPurchasePrice().call(),
lastPurchaseTick: auctions
.lastPurchaseTick()
.call()
.then(toInt),
mintable: auctions.mintable().call(),
nextAuction: auctions.nextAuction().call(),
totalSupply: token.totalSupply().call()
})
.then(
({
currentAuction,
currentPrice,
genesisTime,
globalMtnSupply,
lastPurchasePrice,
lastPurchaseTick,
mintable,
nextAuction,
totalSupply
}) => {
return {
currentAuction,
currentPrice,
genesisTime,
lastPurchasePrice,
lastPurchaseTime: genesisTime + lastPurchaseTick * 60,
nextAuctionStartTime: toInt(nextAuction._startTime),
tokenCirculation: totalSupply,
tokenRemaining: mintable,
tokenSold:
globalMtnSupply && mintable
? mtn.web3.utils
.toBN(globalMtnSupply)
.sub(mtn.web3.utils.toBN(mintable))
.toString()
: '0'
}
}
)
.catch(err => {
throw err
})
}
auction.buy = function(amount) {
const from = wallet.getAddress()
const weiAmount = mtn.web3.utils.toWei(amount.replace(',', '.'))
return wallet.sendTransaction(from, mtn.auctions.options.address, weiAmount)
}
export default auction