1 | | - | {-# STDLIB_VERSION 4 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let ScriptVersion = "2.1.9-beta_20210302" |
---|
5 | | - | |
---|
6 | | - | let percent = 10000 |
---|
7 | | - | |
---|
8 | | - | let usdMult = 1000000 |
---|
9 | | - | |
---|
10 | | - | let decMult = 100000000 |
---|
11 | | - | |
---|
12 | | - | let oneWeek = (604800 * 1000) |
---|
13 | | - | |
---|
14 | | - | let fhfsPrice = (100 * usdMult) |
---|
15 | | - | |
---|
16 | | - | let mainPercent = ((20 * percent) / 100) |
---|
17 | | - | |
---|
18 | | - | let adminPublicKey = base58'JDYJq5RKnSXKLYUQfL89zWPdM3QH5hW8JUTpjnTYV95k' |
---|
19 | | - | |
---|
20 | | - | let robotPublicKey = base58'JDYJq5RKnSXKLYUQfL89zWPdM3QH5hW8JUTpjnTYV95k' |
---|
21 | | - | |
---|
22 | | - | let matcherPublicKey = base58'9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5' |
---|
23 | | - | |
---|
24 | | - | let guarantors = ([valueOrElse(getBinary(this, "guarantor1"), base58''), valueOrElse(getBinary(this, "guarantor2"), base58''), valueOrElse(getBinary(this, "guarantor3"), base58'')] :+ base58'') |
---|
25 | | - | |
---|
26 | | - | let actualSize = value(indexOf(guarantors, base58'')) |
---|
27 | | - | |
---|
28 | | - | let minSignatures = ((actualSize / 2) + (actualSize % 2)) |
---|
29 | | - | |
---|
30 | | - | let usdtAsset = base58'34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ' |
---|
31 | | - | |
---|
32 | | - | let usdcAsset = base58'6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ' |
---|
33 | | - | |
---|
34 | | - | let fhfsAsset = base58'4wcCKU3Cu4ABpmfiwzufocvrQQuRX4QMHZ7TjpRwtAmn' |
---|
35 | | - | |
---|
36 | | - | let ratsAsset = base58'Z7817F7hnbWYsVHykjPtn8sUjyuLLf8NPofdveb8CMD' |
---|
37 | | - | |
---|
38 | | - | let xfeeAsset = base58'5EMfVQiB8NF4HuhaXrZzDM637whWuVBsduq59ZaCSNqk' |
---|
39 | | - | |
---|
40 | | - | let portfolio = [base58'34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ', base58'6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ', base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS', base58'474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu', base58'zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy', base58'HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk', base58'B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H', base58'5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3', base58'BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa'] |
---|
41 | | - | |
---|
42 | | - | let ourAssets = [fhfsAsset, xfeeAsset, ratsAsset] |
---|
43 | | - | |
---|
44 | | - | let majorSize = 1 |
---|
45 | | - | |
---|
46 | | - | let majorMult = 2 |
---|
47 | | - | |
---|
48 | | - | let inactive = valueOrElse(getInteger(this, "inactive"), 0) |
---|
49 | | - | |
---|
50 | | - | let altMult = (majorMult * ((size(portfolio) - majorSize) - inactive)) |
---|
51 | | - | |
---|
52 | | - | let admin = Address(base58'3PLRw83NCgHKKFfeJi8XWZ4fypqJJxm2x2x') |
---|
53 | | - | |
---|
54 | | - | let fmain = Address(base58'3PEPsNg7aSWSSgdC6XweyJkvDXmwVoWeNHL') |
---|
55 | | - | |
---|
56 | | - | let fcold = Address(base58'3P8v4dR4UD8nGeLQmorw6BmCo424GvGBXCA') |
---|
57 | | - | |
---|
58 | | - | let frats = Address(base58'3PJ7RB5CC3Bnn44RNR2hceZ6wKsULnMSxPi') |
---|
59 | | - | |
---|
60 | | - | let fhfsTotal = (assetBalance(fmain, fhfsAsset) + assetBalance(fcold, fhfsAsset)) |
---|
61 | | - | |
---|
62 | | - | let fhfsFunds = (value(assetInfo(fhfsAsset)).quantity - fhfsTotal) |
---|
63 | | - | |
---|
64 | | - | let ratsTotal = (assetBalance(frats, ratsAsset) + assetBalance(fcold, ratsAsset)) |
---|
65 | | - | |
---|
66 | | - | let ratsFunds = (value(assetInfo(ratsAsset)).quantity - ratsTotal) |
---|
67 | | - | |
---|
68 | | - | let usdxFunds = (assetBalance(frats, usdtAsset) + assetBalance(frats, usdcAsset)) |
---|
69 | | - | |
---|
70 | | - | func round (xVal) = ((xVal + 1) / 2) |
---|
71 | | - | |
---|
72 | | - | |
---|
73 | | - | func fractionRound (val,num,den) = round(fraction((2 * val), num, den)) |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | func valueOrMinimum (val,minVal) = if ((minVal > val)) |
---|
77 | | - | then minVal |
---|
78 | | - | else val |
---|
79 | | - | |
---|
80 | | - | |
---|
81 | | - | func toDateTimeString (timestamp) = { |
---|
82 | | - | let sp = toBytes(" ") |
---|
83 | | - | let zd = toBytes(" UTC") |
---|
84 | | - | let norm = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365] |
---|
85 | | - | let leap = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366] |
---|
86 | | - | let epoch = (((((1969 * 365) + (1969 / 4)) - (1969 / 100)) + (1969 / 400)) + 366) |
---|
87 | | - | let ce = (timestamp + ((epoch * 86400) * 1000)) |
---|
88 | | - | if (((-12212553600 * 1000) > timestamp)) |
---|
89 | | - | then throw("ISO 8601: Only years after 1583 inclusive are allowed!") |
---|
90 | | - | else { |
---|
91 | | - | let date = { |
---|
92 | | - | let yyyy = ((ce / (31556952 * 1000)) - 1) |
---|
93 | | - | let ytd = ((ce / (86400 * 1000)) - (((((yyyy * 365) + (yyyy / 4)) - (yyyy / 100)) + (yyyy / 400)) + 366)) |
---|
94 | | - | let months = if (if (if ((((yyyy + 1) % 4) == 0)) |
---|
95 | | - | then (((yyyy + 1) % 100) != 0) |
---|
96 | | - | else false) |
---|
97 | | - | then true |
---|
98 | | - | else (((yyyy + 1) % 400) == 0)) |
---|
99 | | - | then leap |
---|
100 | | - | else norm |
---|
101 | | - | let mm = if (if ((0 > ytd)) |
---|
102 | | - | then true |
---|
103 | | - | else (ytd >= months[12])) |
---|
104 | | - | then throw("Unexpected error: Value overflow for months!") |
---|
105 | | - | else if ((ytd >= months[11])) |
---|
106 | | - | then 11 |
---|
107 | | - | else if ((ytd >= months[10])) |
---|
108 | | - | then 10 |
---|
109 | | - | else if ((ytd >= months[9])) |
---|
110 | | - | then 9 |
---|
111 | | - | else if ((ytd >= months[8])) |
---|
112 | | - | then 8 |
---|
113 | | - | else if ((ytd >= months[7])) |
---|
114 | | - | then 7 |
---|
115 | | - | else if ((ytd >= months[6])) |
---|
116 | | - | then 6 |
---|
117 | | - | else if ((ytd >= months[5])) |
---|
118 | | - | then 5 |
---|
119 | | - | else if ((ytd >= months[4])) |
---|
120 | | - | then 4 |
---|
121 | | - | else if ((ytd >= months[3])) |
---|
122 | | - | then 3 |
---|
123 | | - | else if ((ytd >= months[2])) |
---|
124 | | - | then 2 |
---|
125 | | - | else if ((ytd >= months[1])) |
---|
126 | | - | then 1 |
---|
127 | | - | else 0 |
---|
128 | | - | let dd = (ytd - months[mm]) |
---|
129 | | - | ((((drop(toBytes(toString((yyyy + 1))), 0) + base58'n') + drop(toBytes(toString((mm + 101))), 1)) + base58'n') + drop(toBytes(toString((dd + 101))), 1)) |
---|
130 | | - | } |
---|
131 | | - | let time = { |
---|
132 | | - | let rd = (ce % (86400 * 1000)) |
---|
133 | | - | let hh = (rd / (3600 * 1000)) |
---|
134 | | - | let rh = (rd % (3600 * 1000)) |
---|
135 | | - | let mm = (rh / (60 * 1000)) |
---|
136 | | - | let rm = (rh % (60 * 1000)) |
---|
137 | | - | let ss = (rm / 1000) |
---|
138 | | - | let ms = (rm % 1000) |
---|
139 | | - | ((((drop(toBytes(toString((hh + 100))), 1) + base58'21') + drop(toBytes(toString((mm + 100))), 1)) + base58'21') + drop(toBytes(toString((ss + 100))), 1)) |
---|
140 | | - | } |
---|
141 | | - | toUtf8String((((date + sp) + time) + zd)) |
---|
142 | | - | } |
---|
143 | | - | } |
---|
144 | | - | |
---|
145 | | - | |
---|
146 | | - | func adminTimestamp (publicKey) = if ((publicKey != adminPublicKey)) |
---|
147 | | - | then nil |
---|
148 | | - | else [IntegerEntry("timestamp", lastBlock.timestamp)] |
---|
149 | | - | |
---|
150 | | - | |
---|
151 | | - | func getTransfer (recipient,amount,assetId) = if ((1 > amount)) |
---|
152 | | - | then nil |
---|
153 | | - | else [ScriptTransfer(recipient, amount, assetId)] |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | func excessAmount (assetId) = { |
---|
157 | | - | let fmainFunds = assetBalance(fmain, assetId) |
---|
158 | | - | let totalFunds = (fmainFunds + assetBalance(fcold, assetId)) |
---|
159 | | - | valueOrMinimum((fraction(totalFunds, mainPercent, percent) - fmainFunds), 0) |
---|
160 | | - | } |
---|
161 | | - | |
---|
162 | | - | |
---|
163 | | - | func airdropBalance (assetId) = if (containsElement((portfolio ++ ourAssets), assetId)) |
---|
164 | | - | then throw(makeString(["AirdropWasher () =>", "Please remove the asset ID:", toBase58String(assetId)], " ")) |
---|
165 | | - | else if ((assetId == base58'')) |
---|
166 | | - | then 0 |
---|
167 | | - | else assetBalance(this, assetId) |
---|
168 | | - | |
---|
169 | | - | |
---|
170 | | - | @Callable(i) |
---|
171 | | - | func AutoFixProfit (newMult) = { |
---|
172 | | - | let oldProfit = valueOrElse(getInteger(this, "fixedProfit"), 0) |
---|
173 | | - | let riskPercent = valueOrElse(getInteger(this, "riskPercent"), (percent / 100)) |
---|
174 | | - | let usdtFunds = fraction(fhfsFunds, fhfsPrice, decMult) |
---|
175 | | - | let riskAmount = fraction(usdtFunds, riskPercent, (altMult * percent)) |
---|
176 | | - | let minMult = ((oldProfit / riskAmount) + 1) |
---|
177 | | - | let newProfit = (newMult * riskAmount) |
---|
178 | | - | let usdtAmount = valueOrMinimum((newProfit - oldProfit), 0) |
---|
179 | | - | let ratsAmount = fractionRound(usdtAmount, ratsFunds, usdxFunds) |
---|
180 | | - | if ((minMult > newMult)) |
---|
181 | | - | then throw(makeString([(("AutoFixProfit (" + toString(newMult)) + ") =>"), "Inavlid value! Min. multiplier:", toString(minMult)], " ")) |
---|
182 | | - | else if ((size(i.payments) > 0)) |
---|
183 | | - | then throw(makeString(["AutoFixProfit (...) =>", "Don't attach payment when calling this function ..."], " ")) |
---|
184 | | - | else if (if ((i.callerPublicKey != adminPublicKey)) |
---|
185 | | - | then (i.callerPublicKey != robotPublicKey) |
---|
186 | | - | else false) |
---|
187 | | - | then throw(makeString(["AutoFixProfit (...) =>", "This action can only be performed by an administrator!"], " ")) |
---|
188 | | - | else ([IntegerEntry("fixedProfit", newProfit), ScriptTransfer(frats, usdtAmount, usdtAsset), ScriptTransfer(fmain, ratsAmount, ratsAsset)] ++ adminTimestamp(i.callerPublicKey)) |
---|
189 | | - | } |
---|
190 | | - | |
---|
191 | | - | |
---|
192 | | - | |
---|
193 | | - | @Callable(i) |
---|
194 | | - | func AutoRebalance () = { |
---|
195 | | - | let fhfsSupply = valueOrElse(getInteger(fmain, "fhfsSupply"), (100 * decMult)) |
---|
196 | | - | let fhfsExcessAmount = valueOrMinimum((fhfsSupply - assetBalance(fmain, fhfsAsset)), 0) |
---|
197 | | - | if ((size(i.payments) > 0)) |
---|
198 | | - | then throw(makeString(["AutoRebalance () =>", "Don't attach payment when calling this function ..."], " ")) |
---|
199 | | - | else if (if (if ((i.callerPublicKey != adminPublicKey)) |
---|
200 | | - | then (i.callerPublicKey != robotPublicKey) |
---|
201 | | - | else false) |
---|
202 | | - | then !(containsElement(guarantors, i.callerPublicKey)) |
---|
203 | | - | else false) |
---|
204 | | - | then throw(makeString(["AutoRebalance () =>", "This action can only be performed by an administrator!"], " ")) |
---|
205 | | - | else ((getTransfer(fmain, fhfsExcessAmount, fhfsAsset) ++ [ScriptTransfer(fmain, excessAmount(portfolio[0]), portfolio[0]), ScriptTransfer(fmain, excessAmount(portfolio[2]), portfolio[2]), ScriptTransfer(fmain, excessAmount(portfolio[3]), portfolio[3]), ScriptTransfer(fmain, excessAmount(portfolio[4]), portfolio[4]), ScriptTransfer(fmain, excessAmount(portfolio[5]), portfolio[5]), ScriptTransfer(fmain, excessAmount(portfolio[6]), portfolio[6]), ScriptTransfer(fmain, excessAmount(portfolio[7]), portfolio[7]), ScriptTransfer(fmain, excessAmount(portfolio[8]), portfolio[8])]) ++ adminTimestamp(i.callerPublicKey)) |
---|
206 | | - | } |
---|
207 | | - | |
---|
208 | | - | |
---|
209 | | - | |
---|
210 | | - | @Callable(i) |
---|
211 | | - | func EmergencyExit () = { |
---|
212 | | - | let minTimestamp = (max([valueOrElse(getInteger(fmain, "timestamp"), 0), valueOrElse(getInteger(fcold, "timestamp"), 0), valueOrElse(getInteger(frats, "timestamp"), 0)]) + oneWeek) |
---|
213 | | - | let isAdmin = (i.callerPublicKey == adminPublicKey) |
---|
214 | | - | let isEmergency = valueOrElse(getBoolean(this, "emergency"), false) |
---|
215 | | - | if (if (!(isAdmin)) |
---|
216 | | - | then isEmergency |
---|
217 | | - | else false) |
---|
218 | | - | then throw(makeString(["EmergencyExit () =>", "The emergency procedure has already started!"], " ")) |
---|
219 | | - | else if (if (!(isEmergency)) |
---|
220 | | - | then (minTimestamp > lastBlock.timestamp) |
---|
221 | | - | else false) |
---|
222 | | - | then throw(makeString(["EmergencyExit () =>", "Will be allowed after the date:", toDateTimeString(minTimestamp)], " ")) |
---|
223 | | - | else if ((size(i.payments) > 0)) |
---|
224 | | - | then throw(makeString(["EmergencyExit () =>", "Don't attach payment when calling this function ..."], " ")) |
---|
225 | | - | else if (if (!(isAdmin)) |
---|
226 | | - | then !(containsElement(guarantors, i.callerPublicKey)) |
---|
227 | | - | else false) |
---|
228 | | - | then throw(makeString(["EmergencyExit () =>", "This action can only be performed by one of the guarantors!"], " ")) |
---|
229 | | - | else [BooleanEntry("emergency", !(isAdmin)), ([ScriptTransfer(fmain, assetBalance(fcold, portfolio[0]), portfolio[0]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[2]), portfolio[2]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[3]), portfolio[3]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[4]), portfolio[4]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[5]), portfolio[5]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[6]), portfolio[6]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[7]), portfolio[7]), ScriptTransfer(fmain, assetBalance(fcold, portfolio[8]), portfolio[8])] ++ adminTimestamp(i.callerPublicKey))] |
---|
230 | | - | } |
---|
231 | | - | |
---|
232 | | - | |
---|
233 | | - | |
---|
234 | | - | @Callable(i) |
---|
235 | | - | func AirdropWasher (id0,id1,id2,id3,id4,id5,id6,id7,id8,id9) = if ((size(i.payments) > 0)) |
---|
236 | | - | then throw(makeString(["AirdropWasher (...) =>", "Don't attach payment when calling this function ..."], " ")) |
---|
237 | | - | else if (if ((i.callerPublicKey != adminPublicKey)) |
---|
238 | | - | then !(containsElement(guarantors, i.callerPublicKey)) |
---|
239 | | - | else false) |
---|
240 | | - | then throw(makeString(["AirdropWasher (...) =>", "This action can only be performed by an administrator!"], " ")) |
---|
241 | | - | else ((((((((((getTransfer(admin, airdropBalance(id0), id0) ++ getTransfer(admin, airdropBalance(id1), id1)) ++ getTransfer(admin, airdropBalance(id2), id2)) ++ getTransfer(admin, airdropBalance(id3), id3)) ++ getTransfer(admin, airdropBalance(id4), id4)) ++ getTransfer(admin, airdropBalance(id5), id5)) ++ getTransfer(admin, airdropBalance(id6), id6)) ++ getTransfer(admin, airdropBalance(id7), id7)) ++ getTransfer(admin, airdropBalance(id8), id8)) ++ getTransfer(admin, airdropBalance(id9), id9)) ++ adminTimestamp(i.callerPublicKey)) |
---|
242 | | - | |
---|
243 | | - | |
---|
244 | | - | @Verifier(tx) |
---|
245 | | - | func verify () = { |
---|
246 | | - | let isValidOwner = sigVerify_32Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
247 | | - | let isValidAdmin = if (isValidOwner) |
---|
248 | | - | then true |
---|
249 | | - | else sigVerify_32Kb(tx.bodyBytes, tx.proofs[0], adminPublicKey) |
---|
250 | | - | let isValidRobot = if (isValidOwner) |
---|
251 | | - | then true |
---|
252 | | - | else sigVerify_32Kb(tx.bodyBytes, tx.proofs[0], robotPublicKey) |
---|
253 | | - | let isValidGuarantors = ((((if (sigVerify_32Kb(tx.bodyBytes, tx.proofs[1], guarantors[0])) |
---|
254 | | - | then 1 |
---|
255 | | - | else 0) + (if (sigVerify_32Kb(tx.bodyBytes, tx.proofs[2], guarantors[1])) |
---|
256 | | - | then 1 |
---|
257 | | - | else 0)) + (if (sigVerify_32Kb(tx.bodyBytes, tx.proofs[3], guarantors[2])) |
---|
258 | | - | then 1 |
---|
259 | | - | else 0)) >= minSignatures) |
---|
260 | | - | match tx { |
---|
261 | | - | case _: LeaseCancelTransaction|LeaseTransaction => |
---|
262 | | - | isValidOwner |
---|
263 | | - | case b: BurnTransaction => |
---|
264 | | - | if (if (isValidOwner) |
---|
265 | | - | then !(containsElement(portfolio, b.assetId)) |
---|
266 | | - | else false) |
---|
267 | | - | then !(containsElement(ourAssets, b.assetId)) |
---|
268 | | - | else false |
---|
269 | | - | case o: Order => |
---|
270 | | - | if (if (if (if (if (isValidRobot) |
---|
271 | | - | then !(isDefined(o.matcherFeeAssetId)) |
---|
272 | | - | else false) |
---|
273 | | - | then (o.matcherPublicKey == matcherPublicKey) |
---|
274 | | - | else false) |
---|
275 | | - | then if (if (if ((o.orderType == Buy)) |
---|
276 | | - | then !(containsElement(portfolio, o.assetPair.priceAsset)) |
---|
277 | | - | else false) |
---|
278 | | - | then true |
---|
279 | | - | else if ((o.orderType == Sell)) |
---|
280 | | - | then !(containsElement(portfolio, o.assetPair.amountAsset)) |
---|
281 | | - | else false) |
---|
282 | | - | then true |
---|
283 | | - | else if (!(containsElement(portfolio, o.assetPair.priceAsset))) |
---|
284 | | - | then !(containsElement(portfolio, o.assetPair.amountAsset)) |
---|
285 | | - | else false |
---|
286 | | - | else false) |
---|
287 | | - | then !(containsElement(ourAssets, o.assetPair.priceAsset)) |
---|
288 | | - | else false) |
---|
289 | | - | then !(containsElement(ourAssets, o.assetPair.amountAsset)) |
---|
290 | | - | else false |
---|
291 | | - | case t: MassTransferTransaction|TransferTransaction => |
---|
292 | | - | if (if (isValidAdmin) |
---|
293 | | - | then isValidGuarantors |
---|
294 | | - | else false) |
---|
295 | | - | then !(containsElement(portfolio, t.assetId)) |
---|
296 | | - | else false |
---|
297 | | - | case _: SetScriptTransaction|DataTransaction => |
---|
298 | | - | if (isValidAdmin) |
---|
299 | | - | then isValidGuarantors |
---|
300 | | - | else false |
---|
301 | | - | case _ => |
---|
302 | | - | false |
---|
303 | | - | } |
---|
304 | | - | } |
---|
305 | | - | |
---|
| 1 | + | # no script |
---|