7 | | - | func startAuction (duration,startPrice,priceAssetId) = { |
---|
8 | | - | let pmt = extract(i.payment) |
---|
9 | | - | let auctionId = toBase58String(i.transactionId) |
---|
10 | | - | let endHeight = (lastBlock.height + duration) |
---|
11 | | - | let organiserid = toBase58String(i.caller.bytes) |
---|
12 | | - | let Auctionduration = DataEntry(auctionId, endHeight) |
---|
13 | | - | let organiser = DataEntry((auctionId + "_organizer"), organiserid) |
---|
14 | | - | let lotassetid = DataEntry((auctionId + "_lot_assetId"), if (isDefined(pmt.assetId)) |
---|
15 | | - | then toBase58String(value(pmt.assetId)) |
---|
16 | | - | else "WAVES") |
---|
17 | | - | let lotamount = DataEntry((auctionId + "_lot_amount"), pmt.amount) |
---|
18 | | - | let startprice = DataEntry((auctionId + "_startPrice"), startPrice) |
---|
19 | | - | let priceassetid = DataEntry((auctionId + "_priceAssetId"), priceAssetId) |
---|
20 | | - | if ((duration > maxAuctionDuration)) |
---|
21 | | - | then throw(("Duration is too long. Must be less than " + toString(maxAuctionDuration))) |
---|
22 | | - | else WriteSet([Auctionduration, organiser, lotassetid, lotamount, startprice, priceassetid]) |
---|
| 20 | + | func IssueSATS () = { |
---|
| 21 | + | let pmt = value(i.payments[0]) |
---|
| 22 | + | let currentKey = toBase58String(i.caller.bytes) |
---|
| 23 | + | let PricePerSATS = getIntegerValue(this, "SATS/BTC") |
---|
| 24 | + | let SATSCurrentCap = getIntegerValue(this, "SATSCurrentCap") |
---|
| 25 | + | let NewSATSToUser = fraction(100000, pmt.amount, PricePerSATS) |
---|
| 26 | + | let PreviousIssuedSATS = getIntegerValue(this, "Total_Issued_SATS:") |
---|
| 27 | + | let TotalIssuedSATS = (PreviousIssuedSATS + NewSATSToUser) |
---|
| 28 | + | let PendingMinting = (SATSCurrentCap - TotalIssuedSATS) |
---|
| 29 | + | let PreviousSATSReserveValue = getIntegerValue(this, "Total_SATS_Reserve_In_BTC:") |
---|
| 30 | + | let fee = match getInteger(this, "Total_Fee_Collected") { |
---|
| 31 | + | case a: Int => |
---|
| 32 | + | a |
---|
| 33 | + | case _ => |
---|
| 34 | + | 0 |
---|
| 35 | + | } |
---|
| 36 | + | let FeesCharged = 1 |
---|
| 37 | + | let SATSReserveValue = (PreviousSATSReserveValue + pmt.amount) |
---|
| 38 | + | let PreviousSATSBackupPrice = getIntegerValue(this, "SATS_Backup_Value_In_BTC:") |
---|
| 39 | + | let SATSBackupPrice = fraction(100000, SATSReserveValue, TotalIssuedSATS) |
---|
| 40 | + | if ((pmt.assetId != BTCAssetID)) |
---|
| 41 | + | then throw((("Incorrect asset attached, please attach [BTC] - " + toBase58String(BTCAssetID)) + " only.")) |
---|
| 42 | + | else if ((5000 > pmt.amount)) |
---|
| 43 | + | then throw("Please Attach minimum 5000 Satoshi's To Issue SATS Asset.") |
---|
| 44 | + | else if ((TotalIssuedSATS > SATSCurrentCap)) |
---|
| 45 | + | then throw((((((("SATS Minting is about to reach the Cap of " + toString(SATSCurrentCap)) + "/10^6 SATS. Please Reduce your Minting Order by ") + toString(PendingMinting)) + " or put ") + toString((SATSCurrentCap - PreviousIssuedSATS))) + "/10^6")) |
---|
| 46 | + | else [IntegerEntry("Total_Issued_SATS:", TotalIssuedSATS), IntegerEntry("Balance_Minting_SATS:", PendingMinting), IntegerEntry("Total_SATS_Reserve_In_BTC:", SATSReserveValue), IntegerEntry("SATS_Backup_Value_In_BTC:", SATSBackupPrice), IntegerEntry("Total_Fee_Collected", FeesCharged), IntegerEntry("Totaltxns", totaltxns), StringEntry("message", "<h1>SATS Issued Successfully!</h1><br>"), Reissue(SATSAssetID, NewSATSToUser, true), ScriptTransfer(i.caller, (NewSATSToUser - FeesCharged), SATSAssetID), ScriptTransfer(IssuefsTNFeeAddress, FeesCharged, SATSAssetID)] |
---|
28 | | - | func bid (auctionId) = { |
---|
29 | | - | let pmt = extract(i.payment) |
---|
30 | | - | let pmtAssetIdStr = if (isDefined(pmt.assetId)) |
---|
31 | | - | then toBase58String(value(pmt.assetId)) |
---|
32 | | - | else "WAVES" |
---|
33 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
34 | | - | let endHeight = getIntegerValue(this, auctionId) |
---|
35 | | - | let startPrice = getIntegerValue(this, (auctionId + "_startPrice")) |
---|
36 | | - | let priceAssetId = getStringValue(this, (auctionId + "_priceAssetId")) |
---|
37 | | - | let winAmount = getInteger(this, (auctionId + "_winAmount")) |
---|
38 | | - | let winner = getString(this, (auctionId + "_winner")) |
---|
39 | | - | let bidFromTheSameUser = if (isDefined(winner)) |
---|
40 | | - | then (value(winner) == callerAddressStr) |
---|
41 | | - | else false |
---|
42 | | - | let totalBidAmount = (pmt.amount + (if (bidFromTheSameUser) |
---|
43 | | - | then value(winAmount) |
---|
44 | | - | else 0)) |
---|
45 | | - | if ((lastBlock.height >= endHeight)) |
---|
46 | | - | then throw("Auction already finished.") |
---|
47 | | - | else if ((priceAssetId != pmtAssetIdStr)) |
---|
48 | | - | then throw((("Bid must be in asset '" + priceAssetId) + "'")) |
---|
49 | | - | else if (if (if (isDefined(winAmount)) |
---|
50 | | - | then (value(winAmount) >= totalBidAmount) |
---|
51 | | - | else false) |
---|
52 | | - | then true |
---|
53 | | - | else if (!(isDefined(winAmount))) |
---|
54 | | - | then (startPrice >= totalBidAmount) |
---|
55 | | - | else false) |
---|
56 | | - | then throw(("Bid must be more then " + toString(if (isDefined(winAmount)) |
---|
57 | | - | then value(winAmount) |
---|
58 | | - | else startPrice))) |
---|
59 | | - | else if (if (bidFromTheSameUser) |
---|
60 | | - | then true |
---|
61 | | - | else !(isDefined(winner))) |
---|
62 | | - | then WriteSet([DataEntry((auctionId + "_winner"), callerAddressStr), DataEntry((auctionId + "_winAmount"), totalBidAmount)]) |
---|
63 | | - | else { |
---|
64 | | - | let previousBidderAddr = addressFromStringValue(value(winner)) |
---|
65 | | - | let priceAsset = if (if ((priceAssetId == "WAVES")) |
---|
66 | | - | then true |
---|
67 | | - | else (priceAssetId == "")) |
---|
68 | | - | then unit |
---|
69 | | - | else fromBase58String(priceAssetId) |
---|
70 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_winner"), callerAddressStr), DataEntry((auctionId + "_winAmount"), totalBidAmount)]), TransferSet([ScriptTransfer(previousBidderAddr, value(winAmount), priceAsset)])) |
---|
71 | | - | } |
---|
72 | | - | } |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | @Callable(i) |
---|
77 | | - | func withdraw (auctionId) = { |
---|
78 | | - | let pmt = extract(i.payment) |
---|
79 | | - | let pmtAssetIdStr = if (isDefined(pmt.assetId)) |
---|
80 | | - | then toBase58String(value(pmt.assetId)) |
---|
81 | | - | else "WAVES" |
---|
82 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
83 | | - | let endHeight = getIntegerValue(this, auctionId) |
---|
84 | | - | let organizer = getStringValue(this, (auctionId + "_organizer")) |
---|
85 | | - | let winner = getString(this, (auctionId + "_winner")) |
---|
86 | | - | let lotAssetId = getStringValue(this, (auctionId + "_lot_assetId")) |
---|
87 | | - | let lotAmount = getIntegerValue(this, (auctionId + "_lot_amount")) |
---|
88 | | - | let priceAssetId = getStringValue(this, (auctionId + "_priceAssetId")) |
---|
89 | | - | let winAmount = getIntegerValue(this, (auctionId + "_winAmount")) |
---|
90 | | - | let lotAsset = if ((lotAssetId == "WAVES")) |
---|
91 | | - | then unit |
---|
92 | | - | else fromBase58String(lotAssetId) |
---|
93 | | - | let priceAsset = if (if ((priceAssetId == "WAVES")) |
---|
94 | | - | then true |
---|
95 | | - | else (priceAssetId == "")) |
---|
96 | | - | then unit |
---|
97 | | - | else fromBase58String(priceAssetId) |
---|
98 | | - | let winnerAddr = addressFromStringValue(value(winner)) |
---|
99 | | - | let organizerAddr = addressFromStringValue(value(organizer)) |
---|
100 | | - | let betAmount = getInteger(this, ((auctionId + "_bidder_") + callerAddressStr)) |
---|
101 | | - | if ((endHeight > lastBlock.height)) |
---|
102 | | - | then throw("Auction is not finished yet") |
---|
103 | | - | else if (!(isDefined(winner))) |
---|
104 | | - | then if (isDefined(getString(this, (auctionId + "_lot_passed")))) |
---|
105 | | - | then throw("Organizer has already got his lot back") |
---|
106 | | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_lot_passed"), organizer)]), TransferSet([ScriptTransfer(organizerAddr, lotAmount, lotAsset)])) |
---|
107 | | - | else if (isDefined(getString(this, (auctionId + "_lot_passed")))) |
---|
108 | | - | then throw("Lot is already passed to the winner, and organizer got his reward") |
---|
109 | | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_lot_passed"), toBase58String(winnerAddr.bytes))]), TransferSet([ScriptTransfer(winnerAddr, lotAmount, lotAsset), ScriptTransfer(organizerAddr, ((winAmount * 95) / 100), priceAsset), ScriptTransfer(addressFromPublicKey(base58'59q1hHBmeQgfSRst9Dn52VTBbtCu4SQ7AujhGDjHCqn6'), ((winAmount * 5) / 100), priceAsset)])) |
---|
110 | | - | } |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | |
---|
114 | | - | @Callable(i) |
---|
115 | | - | func Expedite (auctionId) = { |
---|
116 | | - | let pmt = extract(i.payment) |
---|
117 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
118 | | - | let endHeight = getIntegerValue(this, auctionId) |
---|
119 | | - | let organizer = getStringValue(this, (auctionId + "_organizer")) |
---|
120 | | - | let Auctionduration = DataEntry(auctionId, (lastBlock.height + 1)) |
---|
121 | | - | let diff = (endHeight - lastBlock.height) |
---|
122 | | - | let organizerAddr = addressFromStringValue(value(organizer)) |
---|
123 | | - | if ((organizer != callerAddressStr)) |
---|
124 | | - | then throw("You are not Orgnaniser to Sign this transaction.") |
---|
125 | | - | else if ((diff > 15)) |
---|
126 | | - | then WriteSet([Auctionduration]) |
---|
127 | | - | else throw("Auction is already finished.") |
---|
128 | | - | } |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | @Callable(i) |
---|
133 | | - | func DAppOwnerExpedite (auctionId) = { |
---|
134 | | - | let pmt = extract(i.payment) |
---|
135 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
136 | | - | let endHeight = getIntegerValue(this, auctionId) |
---|
137 | | - | let diff = (endHeight - lastBlock.height) |
---|
138 | | - | let DAppowner = getStringValue(this, "dappowner") |
---|
139 | | - | let Auctionduration = DataEntry(auctionId, (lastBlock.height + 1)) |
---|
140 | | - | if ((DAppowner != callerAddressStr)) |
---|
141 | | - | then throw("You are not Dapp Owner to Sign this transaction.") |
---|
142 | | - | else if ((diff > 15)) |
---|
143 | | - | then WriteSet([Auctionduration]) |
---|
144 | | - | else throw("Auction is already finished.") |
---|
| 52 | + | func Liquidate () = { |
---|
| 53 | + | let currentKey = toBase58String(i.callerPublicKey) |
---|
| 54 | + | let pmt = value(i.payments[0]) |
---|
| 55 | + | let PreviousIssuedSATS = getIntegerValue(this, "Total_Issued_SATS:") |
---|
| 56 | + | let PreviousBurnedSATS = getIntegerValue(this, "Total_Burned_SATS:") |
---|
| 57 | + | let SATSCurrentCap = getIntegerValue(this, "SATSCurrentCap") |
---|
| 58 | + | let TotalIssuedSATS = (PreviousIssuedSATS - pmt.amount) |
---|
| 59 | + | let TotalBurnedSATS = (PreviousBurnedSATS + pmt.amount) |
---|
| 60 | + | let PendingMinting = (SATSCurrentCap - TotalIssuedSATS) |
---|
| 61 | + | let PreviousSATSReserveValue = getIntegerValue(this, "Total_SATS_Reserve_In_BTC:") |
---|
| 62 | + | let PreviousSATSBackupPrice = getIntegerValue(this, "SATS_Backup_Value_In_BTC:") |
---|
| 63 | + | let calculateburnvalue = fraction(PreviousSATSBackupPrice, pmt.amount, 100000) |
---|
| 64 | + | let SATSReserveValue = (PreviousSATSReserveValue - calculateburnvalue) |
---|
| 65 | + | let SATSBackupPrice = fraction(100000, SATSReserveValue, TotalIssuedSATS) |
---|
| 66 | + | if ((pmt.assetId != SATSAssetID)) |
---|
| 67 | + | then throw((("Kindly Deposit Only " + toBase58String(SATSAssetID)) + " [SATS].")) |
---|
| 68 | + | else if ((5000 > pmt.amount)) |
---|
| 69 | + | then throw("Attach Amount must be greater than 5000 SATS.") |
---|
| 70 | + | else [Burn(SATSAssetID, pmt.amount), IntegerEntry("Totaltxns", totaltxns), IntegerEntry("Total_Issued_SATS:", TotalIssuedSATS), IntegerEntry("Total_Burned_SATS:", TotalBurnedSATS), IntegerEntry("Balance_Minting_SATS:", PendingMinting), IntegerEntry("Total_SATS_Reserve_In_BTC:", SATSReserveValue), IntegerEntry("SATS_Backup_Value_In_BTC:", SATSBackupPrice), StringEntry("message", "<h1>SATS Liquidated Successfully!</h1><br>"), ScriptTransfer(i.caller, calculateburnvalue, BTCAssetID)] |
---|