tx · 5ufjCRb8mag4i6s7bRHKrZguwfyGD1SDYUYf2RLfgNvP

3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr:  -0.05000000 Waves

2020.09.09 11:53 [1169571] smart account 3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr > SELF 0.00000000 Waves

{ "type": 13, "id": "5ufjCRb8mag4i6s7bRHKrZguwfyGD1SDYUYf2RLfgNvP", "fee": 5000000, "feeAssetId": null, "timestamp": 1599641673539, "version": 2, "chainId": 84, "sender": "3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr", "senderPublicKey": "DuSyT6XMpGpexrez81rru35TfpmHJcYQP1WJxT9wjcry", "proofs": [ "64jR4AyV47LDq6BEQLK3NH4VzoNFz3xfXgm7uWE2HxFw4Q8A8oML86ykaohEGn3Rz4uwctgbADjxjrNswymMRYfE" ], "script": "base64:AAIDAAAAAAAAABYIARIDCgEBEgMKAQESAwoBARIDCgEBAAAABAAAAAANUkVDT1ZFUllQSEFTRQAAAAAAAAAAZAAAAAALUFJJQ0VPUkFDTEUCAAAAIzNONE5TN2Q0Sm85YTZGMTRMaUZVS0tZVmRVa2tmMmVQNFp4AQAAABJnZXREYXRhRW50cnlGb3JLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABeAUAAAAHJG1hdGNoMAUAAAABeAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAAAAAAAAAAAAAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAAMcGF5b3V0Q2FsbGVyAAAAAwAAAAZ0YXJnZXQAAAAGY2FsbGVyAAAABnBheW91dAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgkAASwAAAACCQABLAAAAAICAAAABWx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AGY2FsbGVyBAAAAA1sb25nc1RvdGFsS2V5CQABLAAAAAICAAAADGxvbmdzX3RvdGFsXwkAAaQAAAABBQAAAApsb25nVGFyZ2V0BAAAABtjdXJyZW50TG9uZ0Ftb3VudEZvckFkZHJlc3MJAQAAABJnZXREYXRhRW50cnlGb3JLZXkAAAABBQAAAA5sb25nQWRkcmVzc0tleQQAAAAMY3VycmVudExvbmdzCQEAAAASZ2V0RGF0YUVudHJ5Rm9yS2V5AAAAAQUAAAANbG9uZ3NUb3RhbEtleQQAAAAHcGF5bWVudAkBAAAAB2V4dHJhY3QAAAABCAUAAAABaQAAAAdwYXltZW50BAAAAAZhbW91bnQIBQAAAAdwYXltZW50AAAABmFtb3VudAMJAQAAAAlpc0RlZmluZWQAAAABCAUAAAAHcGF5bWVudAAAAAdhc3NldElkCQAAAgAAAAECAAAAJk9ubHkgV2F2ZXMgcGF5bWVudHMgYWxsb3dlZCBjdXJyZW50bHkhAwkAAGcAAAACCQAAZAAAAAIFAAAABmhlaWdodAUAAAANUkVDT1ZFUllQSEFTRQUAAAAKbG9uZ1RhcmdldAkAAAIAAAABAgAAAFNSZWNvdmVyeSBwaGFzZSBhY3RpdmUuIFlvdSBjYW4gbm8gbG9uZ2VyIGdvIGxvbmcgdG93YXJkcyB0aGlzIGxvbmcgdGFyZ2V0IC8gaGVpZ2h0IQkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAObG9uZ0FkZHJlc3NLZXkJAABkAAAAAgUAAAAbY3VycmVudExvbmdBbW91bnRGb3JBZGRyZXNzBQAAAAZhbW91bnQJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAADWxvbmdzVG90YWxLZXkJAABkAAAAAgUAAAAMY3VycmVudExvbmdzBQAAAAZhbW91bnQFAAAAA25pbAAAAACCemgG", "height": 1169571, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3M46Ya3cDg9cHAK74GPjD4bFYQYmPMUXAk8dXMCFdAYF Next: 6GXZHfA8NZPnaFa5y2RYEZiTUwHuLPsUgrhYBaxeY9vG Diff:
OldNewDifferences
1111 case _: Unit =>
1212 0
1313 case _ =>
14- throw()
14+ throw("Match error")
1515 }
16+
17+
18+func payoutCaller (target,caller,payout) = ScriptResult(WriteSet([DataEntry(((("long_" + toString(target)) + "_") + toString(caller)), 0), DataEntry(((("short_" + toString(target)) + "_") + toString(caller)), 0)]), TransferSet([ScriptTransfer(caller, payout, unit)]))
19+
20+
21+@Callable(i)
22+func withdraw (target) = if (((target + 1) > height))
23+ then throw("End of predictions for this height not reached yet!")
24+ else {
25+ let priceAtTarget = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(target)))
26+ if ((priceAtTarget == 0))
27+ then throw("Could not determine price at target height!")
28+ else {
29+ let caller = i.caller
30+ let targetPrice = getIntegerValue(this, ("target_price_" + toString(target)))
31+ let totalLongs = getDataEntryForKey(("longs_total_" + toString(target)))
32+ let totalShorts = getDataEntryForKey(("shorts_total_" + toString(target)))
33+ if ((priceAtTarget > targetPrice))
34+ then {
35+ let precept = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
36+ let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
37+ payoutCaller(target, caller, payout)
38+ }
39+ else if ((targetPrice > priceAtTarget))
40+ then {
41+ let precept = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
42+ let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
43+ payoutCaller(target, caller, payout)
44+ }
45+ else {
46+ let preceptLong = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
47+ let preceptShort = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
48+ let payout = (((preceptLong / totalLongs) * totalLongs) + ((preceptShort / totalShorts) * totalShorts))
49+ payoutCaller(target, caller, payout)
50+ }
51+ }
52+ }
53+
1654
1755
1856 @Callable(i)
2765
2866 @Callable(i)
2967 func short (shortTarget) = {
30- let caller = toString(i.caller)
31- let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller)
32- let shortsTotalKey = ("shorts_total_" + toString(shortTarget))
33- let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey)
34- let currentShorts = getDataEntryForKey(shortsTotalKey)
35- let payment = extract(i.payment)
36- let amount = payment.amount
37- if (isDefined(payment.assetId))
38- then throw("Only Waves payments allowed currently!")
39- else if (((height + RECOVERYPHASE) >= shortTarget))
40- then throw("Recovery phase active. You can no longer go short towards this short target / height!")
41- else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))])
68+ let targetPrice = getDataEntryForKey(("target_price_" + toString(shortTarget)))
69+ if ((targetPrice == 0))
70+ then throw("Target not initialized!")
71+ else {
72+ let caller = toString(i.caller)
73+ let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller)
74+ let shortsTotalKey = ("shorts_total_" + toString(shortTarget))
75+ let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey)
76+ let currentShorts = getDataEntryForKey(shortsTotalKey)
77+ let payment = extract(i.payment)
78+ let amount = payment.amount
79+ if (isDefined(payment.assetId))
80+ then throw("Only Waves payments allowed currently!")
81+ else if (((height + RECOVERYPHASE) >= shortTarget))
82+ then throw("Recovery phase active. You can no longer go short towards this short target / height!")
83+ else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))])
84+ }
4285 }
4386
4487
4588
4689 @Callable(i)
4790 func long (longTarget) = {
48- let caller = toString(i.caller)
49- let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller)
50- let longsTotalKey = ("longs_total_" + toString(longTarget))
51- let currentLongAmountForAddress = getDataEntryForKey(longAddressKey)
52- let currentLongs = getDataEntryForKey(longsTotalKey)
53- let payment = extract(i.payment)
54- let amount = payment.amount
55- if (isDefined(payment.assetId))
56- then throw("Only Waves payments allowed currently!")
57- else if (((height + RECOVERYPHASE) >= longTarget))
58- then throw("Recovery phase active. You can no longer go long towards this long target / height!")
59- else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))])
91+ let targetPrice = getDataEntryForKey(("target_price_" + toString(longTarget)))
92+ if ((targetPrice == 0))
93+ then throw("Target not initialized!")
94+ else {
95+ let caller = toString(i.caller)
96+ let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller)
97+ let longsTotalKey = ("longs_total_" + toString(longTarget))
98+ let currentLongAmountForAddress = getDataEntryForKey(longAddressKey)
99+ let currentLongs = getDataEntryForKey(longsTotalKey)
100+ let payment = extract(i.payment)
101+ let amount = payment.amount
102+ if (isDefined(payment.assetId))
103+ then throw("Only Waves payments allowed currently!")
104+ else if (((height + RECOVERYPHASE) >= longTarget))
105+ then throw("Recovery phase active. You can no longer go long towards this long target / height!")
106+ else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))])
107+ }
60108 }
61109
62110
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let RECOVERYPHASE = 100
55
66 let PRICEORACLE = "3N4NS7d4Jo9a6F14LiFUKKYVdUkkf2eP4Zx"
77
88 func getDataEntryForKey (key) = match getInteger(this, key) {
99 case x: Int =>
1010 x
1111 case _: Unit =>
1212 0
1313 case _ =>
14- throw()
14+ throw("Match error")
1515 }
16+
17+
18+func payoutCaller (target,caller,payout) = ScriptResult(WriteSet([DataEntry(((("long_" + toString(target)) + "_") + toString(caller)), 0), DataEntry(((("short_" + toString(target)) + "_") + toString(caller)), 0)]), TransferSet([ScriptTransfer(caller, payout, unit)]))
19+
20+
21+@Callable(i)
22+func withdraw (target) = if (((target + 1) > height))
23+ then throw("End of predictions for this height not reached yet!")
24+ else {
25+ let priceAtTarget = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(target)))
26+ if ((priceAtTarget == 0))
27+ then throw("Could not determine price at target height!")
28+ else {
29+ let caller = i.caller
30+ let targetPrice = getIntegerValue(this, ("target_price_" + toString(target)))
31+ let totalLongs = getDataEntryForKey(("longs_total_" + toString(target)))
32+ let totalShorts = getDataEntryForKey(("shorts_total_" + toString(target)))
33+ if ((priceAtTarget > targetPrice))
34+ then {
35+ let precept = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
36+ let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
37+ payoutCaller(target, caller, payout)
38+ }
39+ else if ((targetPrice > priceAtTarget))
40+ then {
41+ let precept = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
42+ let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
43+ payoutCaller(target, caller, payout)
44+ }
45+ else {
46+ let preceptLong = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
47+ let preceptShort = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
48+ let payout = (((preceptLong / totalLongs) * totalLongs) + ((preceptShort / totalShorts) * totalShorts))
49+ payoutCaller(target, caller, payout)
50+ }
51+ }
52+ }
53+
1654
1755
1856 @Callable(i)
1957 func initiate (target) = {
2058 let currentPrice = getIntegerValue(addressFromStringValue(PRICEORACLE), "price")
2159 if (((height + RECOVERYPHASE) >= target))
2260 then throw(("No new future instantiable for the given height: " + toString(target)))
2361 else WriteSet([DataEntry(("target_price_" + toString(target)), currentPrice), DataEntry(("shorts_total_" + toString(target)), 0), DataEntry(("longs_total_" + toString(target)), 0)])
2462 }
2563
2664
2765
2866 @Callable(i)
2967 func short (shortTarget) = {
30- let caller = toString(i.caller)
31- let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller)
32- let shortsTotalKey = ("shorts_total_" + toString(shortTarget))
33- let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey)
34- let currentShorts = getDataEntryForKey(shortsTotalKey)
35- let payment = extract(i.payment)
36- let amount = payment.amount
37- if (isDefined(payment.assetId))
38- then throw("Only Waves payments allowed currently!")
39- else if (((height + RECOVERYPHASE) >= shortTarget))
40- then throw("Recovery phase active. You can no longer go short towards this short target / height!")
41- else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))])
68+ let targetPrice = getDataEntryForKey(("target_price_" + toString(shortTarget)))
69+ if ((targetPrice == 0))
70+ then throw("Target not initialized!")
71+ else {
72+ let caller = toString(i.caller)
73+ let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller)
74+ let shortsTotalKey = ("shorts_total_" + toString(shortTarget))
75+ let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey)
76+ let currentShorts = getDataEntryForKey(shortsTotalKey)
77+ let payment = extract(i.payment)
78+ let amount = payment.amount
79+ if (isDefined(payment.assetId))
80+ then throw("Only Waves payments allowed currently!")
81+ else if (((height + RECOVERYPHASE) >= shortTarget))
82+ then throw("Recovery phase active. You can no longer go short towards this short target / height!")
83+ else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))])
84+ }
4285 }
4386
4487
4588
4689 @Callable(i)
4790 func long (longTarget) = {
48- let caller = toString(i.caller)
49- let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller)
50- let longsTotalKey = ("longs_total_" + toString(longTarget))
51- let currentLongAmountForAddress = getDataEntryForKey(longAddressKey)
52- let currentLongs = getDataEntryForKey(longsTotalKey)
53- let payment = extract(i.payment)
54- let amount = payment.amount
55- if (isDefined(payment.assetId))
56- then throw("Only Waves payments allowed currently!")
57- else if (((height + RECOVERYPHASE) >= longTarget))
58- then throw("Recovery phase active. You can no longer go long towards this long target / height!")
59- else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))])
91+ let targetPrice = getDataEntryForKey(("target_price_" + toString(longTarget)))
92+ if ((targetPrice == 0))
93+ then throw("Target not initialized!")
94+ else {
95+ let caller = toString(i.caller)
96+ let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller)
97+ let longsTotalKey = ("longs_total_" + toString(longTarget))
98+ let currentLongAmountForAddress = getDataEntryForKey(longAddressKey)
99+ let currentLongs = getDataEntryForKey(longsTotalKey)
100+ let payment = extract(i.payment)
101+ let amount = payment.amount
102+ if (isDefined(payment.assetId))
103+ then throw("Only Waves payments allowed currently!")
104+ else if (((height + RECOVERYPHASE) >= longTarget))
105+ then throw("Recovery phase active. You can no longer go long towards this long target / height!")
106+ else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))])
107+ }
60108 }
61109
62110

github/deemru/w8io/169f3d6 
32.30 ms