-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-auction.fif
executable file
·115 lines (101 loc) · 4.68 KB
/
new-auction.fif
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
#!/usr/bin/env fift -s
"auction-utils.fif" include
{ ."<contract> <seqno> <auction-id> <auction-type> <end-time> [<decrypt-time> <fixed-amount>] [-c <comment>] [-s <minimum-step>] [-t <start-time>] [-f <bidding-fee>] [-i <initial-price>] [-b <buyout-price>] [-n <stock-size>] [-O <output-boc>]" cr
."Starts a new auction via a smart contract created by init.fif, with address loaded from file <contract>.addr "
."and private key from <contract>.pk, and saves it into <output-boc>.boc ('<contract>-query.boc' by default)." cr
."<seqno> is the current seqno value of the contract," cr
."<auction-id> is an arbitrary auction id (a 32 bit number, must be unique among active and upcoming auctions)," cr
."<auction-type> is auction type; currently three types are supported:" cr
." 0: English (open ascending price) auction," cr
." 64: Blind (sealed-bid first-price) auction," cr
." 65: Vickrey (sealed-bid second-price) auction," cr
."<end-time> is Unixtime of the forced auction end," cr
."<decrypt-time> (only for blind auctions, i.e. when <auction-type>=64..65) is Unixtime (after <end-time>), until which bidders need to present their actual bids to the contract," cr
."<fixed-amount> (only for blind auctions) is the amount in Grams that must be payed by each bidder (it will be greater or equal to their actual bids)," cr
."-c <comment> is an arbitrary comment describing this auction," cr
."-s <minimum-step> (only for open auctions, i.e. when <auction-type>=0) is the minimal bid difference required to outbid previous bidder," cr
."-t <start-time> is Unixtime of the auction start (if not specified, auction starts immediately after publishing)," cr
."-f <bidding-fee> is the amount in Grams that won't be returned to bidders (if not specified, all losing bids are returned completely)," cr
."-i <initial-price> is the minimum amount in Grams that the first bid should be equal to," cr
."-b <buyout-price> is the amount in Grams that allows to instantly win the auction," cr
."-n <stock-size> is the number of times this auction should be automatically repeated." cr
} : usage()
// == Parsing command-line arguments
{
"-O" "--output-file" 1 { =: SaveFile } option-long()
"-c" "--comment" 1 { =: Comment } option-long()
"-n" "--stock-size" 1 { parse-int =: StockSize } option-long()
"-s" "--minimum-step" 1 { $>GR =: MinimumStep } option-long()
"-t" "--start-time" 1 { parse-int =: StartTime } option-long()
"-f" "--bidding-fee" 1 { $>GR =: BiddingFee } option-long()
"-i" "--initial-price" 1 { $>GR =: InitialPrice } option-long()
"-b" "--buyout-price" 1 { $>GR =: BuyoutPrice } option-long()
1 { =: BaseFile } nth-argument()
2 { parse-int =: SeqNo } nth-argument()
3 { parse-int =: AuctionId } nth-argument()
4 { parse-int =: AuctionType } nth-argument()
5 { parse-int =: EndTime } nth-argument()
6 { parse-int =: DecryptTime } nth-argument()
7 { $>GR =: FixedAmount } nth-argument()
} scan-args()
5 < { show-usage() } if // Checks that there's enough arguments
// == End of parsing command-line arguments
BaseFile +"-query" =:? SaveFile
"" =:? Comment
0 =:? MinimumStep
0 =:? StartTime
0 =:? BiddingFee
0 =:? InitialPrice
0 =:? BuyoutPrice
0 =:? DecryptTime
0 =:? FixedAmount
0 =:? StockSize
BaseFile +".addr" load-address
2dup 2constant ContractAddr
."Contract address = " 2dup .addr cr 6 .Addr cr
Comment $len 0 > {
<b Comment 127 append-long-string b>
} {
null
} cond =: CommentCell
BaseFile +".pk" load-keypair
=: PrivateKey
=: PublicKey
."Creating new auction #" AuctionId . ."of type " AuctionType . .", starting at " StartTime . .", ending at " EndTime . .", stock size: " StockSize . cr
AuctionType 63 > { ."Blind auction's decrypt deadline is " DecryptTime . .", fixed amount " FixedAmount .GR cr } if
."Initial price: " InitialPrice .GR .", buyout price: " BuyoutPrice .GR .", minimum step: " MinimumStep .GR .", bidding fee: " BiddingFee .GR cr
<b
AuctionType 8 u,
CommentCell dict,
StartTime 32 u,
EndTime 32 u,
BiddingFee Gram,
InitialPrice Gram,
BuyoutPrice Gram,
StockSize 32 u,
AuctionType 64 < {
MinimumStep Gram,
0 Gram, // Current price
} if
AuctionType 63 > {
DecryptTime 32 u,
FixedAmount Gram,
null dict,
} if
b> =: AuctionBody
// Pack the internal message into a request data structure to be signed
<b
SeqNo 32 u, // seqno
-1 32 i, // valid_until
2 32 u, // op, 2 = create auction
AuctionId 32 u,
AuctionBody ref,
b> =: MessageBody
."Signing message: " MessageBody <s csr. cr
ContractAddr null
MessageBody PrivateKey sign-message()
external-message() =: ExtMessage
."New external message: " ExtMessage <s csr. cr
ExtMessage 2 boc+>B dup Bx. cr
SaveFile +".boc" tuck B>file
."(Saved to file " type .")" cr