tx · J1yu5iTdahLA9Uo5ZUwXDVsxwhffx9hVUUZ7M8LdLYZp 3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep: -0.01000000 Waves 2022.12.12 14:18 [2357046] smart account 3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep > SELF 0.00000000 Waves
{ "type": 13, "id": "J1yu5iTdahLA9Uo5ZUwXDVsxwhffx9hVUUZ7M8LdLYZp", "fee": 1000000, "feeAssetId": null, "timestamp": 1670844008042, "version": 2, "chainId": 84, "sender": "3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep", "senderPublicKey": "7v5L7QkXxfkirALdyqmox38QCsa9jtfAtgUfHTh34eWq", "proofs": [ "3AeNHx4bnpLWuTzxmbPBs9HfDU4WnwM9Gt99UGyQcBajTJZLbUUSh45diqVWYuJWc8Gz8kANmcUK8qpdUFBtmcde" ], "script": "base64:BgIPCAISBQoDAQEBEgQKAhERGQAFTVVMVDYAwIQ9AAVNVUxUOACAwtcvAAVjaGFpbgkAsAkBCQDJAQIJAMoBAggFBHRoaXMFYnl0ZXMAAQABAAt1c2RuQXNzZXRJZAQHJG1hdGNoMAUFY2hhaW4DCQAAAgIBVwUHJG1hdGNoMAEgtiYpwwT1zlORpA5LdSQvZIxRsfrfr1QpvUjSHSqyqtEDCQAAAgIBVAUHJG1hdGNoMAEg93bq9/eDymXbbhPuAjvPWCmVqcHRjfJL2mzYHWKAyN4JAAIBAg1Vbmtub3duIGNoYWluAA9zdGFraW5nQ29udHJhY3QJARFAZXh0ck5hdGl2ZSgxMDYyKQEEByRtYXRjaDAFBWNoYWluAwkAAAICAVcFByRtYXRjaDACIzNQTG5jWHRTMVU4M0Q2Y1FiRkQzSDhyQkhQTGd6eFNGS1oxAwkAAAICAVQFByRtYXRjaDACIzNOREN5Qkc1cTg1SnVhUmlpZ1VlRXRhaW55akNRVDNYcFptCQACAQINVW5rbm93biBjaGFpbgAPREVGQVVMVExPQ0FUSU9OAg9BZnJpY2FfRl9BZnJpY2EAB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HVja0Fzc2V0SWQJAMwIAgUHbmV3UGFjawUDbmlsBQNuaWwJAJQKAgkAzQgCCAUGbWVyZ2VkAl8xCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIIBQZtZXJnZWQCXzMFC3VzZG5Bc3NldElkBQZyZXN1bHQAUIDrLA==", "height": 2357046, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4Hnti9WWrSuYW1HSCA4oEe56WNH1B6bU9ZB1tAY6CpM7 Next: GWecBuefRy863qXkyR1zwKtQE3w1fyEKp1SyNcxEnAC4 Diff:
Old | New | Differences | |
---|---|---|---|
5 | 5 | ||
6 | 6 | let MULT8 = 100000000 | |
7 | 7 | ||
8 | - | let | |
8 | + | let chain = toUtf8String(take(drop(this.bytes, 1), 1)) | |
9 | 9 | ||
10 | - | let backEndAddr = addressFromStringValue("3N5SpX21R3R75Qo4eb3MwFFvW7TUzyhvavv") | |
10 | + | let usdnAssetId = match chain { | |
11 | + | case _ => | |
12 | + | if (("W" == $match0)) | |
13 | + | then base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' | |
14 | + | else if (("T" == $match0)) | |
15 | + | then base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ' | |
16 | + | else throw("Unknown chain") | |
17 | + | } | |
11 | 18 | ||
12 | - | let stakingContract = addressFromStringValue("3NDCyBG5q85JuaRiigUeEtainyjCQT3XpZm") | |
19 | + | let stakingContract = addressFromStringValue(match chain { | |
20 | + | case _ => | |
21 | + | if (("W" == $match0)) | |
22 | + | then "3PLncXtS1U83D6cQbFD3H8rBHPLgzxSFKZ1" | |
23 | + | else if (("T" == $match0)) | |
24 | + | then "3NDCyBG5q85JuaRiigUeEtainyjCQT3XpZm" | |
25 | + | else throw("Unknown chain") | |
26 | + | }) | |
13 | 27 | ||
14 | 28 | let DEFAULTLOCATION = "Africa_F_Africa" | |
15 | 29 | ||
26 | 40 | func keyFactoryWarehouseByIdAndType (factoryId,resType) = ((("factoryWhByContinentAndRes_" + factoryId) + "_") + toString(resType)) | |
27 | 41 | ||
28 | 42 | ||
29 | - | func keyAssetIdToOwner (assetId) = ("nftOwner_" + assetId) | |
30 | - | ||
31 | - | ||
32 | - | func keyStakedTimeByAssetId (assetId) = ("stakedTime_" + assetId) | |
33 | - | ||
34 | - | ||
35 | 43 | func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr) | |
36 | 44 | ||
37 | 45 | ||
40 | 48 | ||
41 | 49 | func keyDuckLocation (duckAssetId) = ("duckLocation_" + duckAssetId) | |
42 | 50 | ||
43 | - | ||
44 | - | let idxType = 0 | |
45 | - | ||
46 | - | let idxQuantity = 1 | |
47 | - | ||
48 | - | let idxPrice = 2 | |
49 | 51 | ||
50 | 52 | let locIdxContinent = 0 | |
51 | 53 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let MULT6 = 1000000 | |
5 | 5 | ||
6 | 6 | let MULT8 = 100000000 | |
7 | 7 | ||
8 | - | let | |
8 | + | let chain = toUtf8String(take(drop(this.bytes, 1), 1)) | |
9 | 9 | ||
10 | - | let backEndAddr = addressFromStringValue("3N5SpX21R3R75Qo4eb3MwFFvW7TUzyhvavv") | |
10 | + | let usdnAssetId = match chain { | |
11 | + | case _ => | |
12 | + | if (("W" == $match0)) | |
13 | + | then base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' | |
14 | + | else if (("T" == $match0)) | |
15 | + | then base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ' | |
16 | + | else throw("Unknown chain") | |
17 | + | } | |
11 | 18 | ||
12 | - | let stakingContract = addressFromStringValue("3NDCyBG5q85JuaRiigUeEtainyjCQT3XpZm") | |
19 | + | let stakingContract = addressFromStringValue(match chain { | |
20 | + | case _ => | |
21 | + | if (("W" == $match0)) | |
22 | + | then "3PLncXtS1U83D6cQbFD3H8rBHPLgzxSFKZ1" | |
23 | + | else if (("T" == $match0)) | |
24 | + | then "3NDCyBG5q85JuaRiigUeEtainyjCQT3XpZm" | |
25 | + | else throw("Unknown chain") | |
26 | + | }) | |
13 | 27 | ||
14 | 28 | let DEFAULTLOCATION = "Africa_F_Africa" | |
15 | 29 | ||
16 | 30 | let NUMRES = 6 | |
17 | 31 | ||
18 | 32 | let FACTORYMAXWAREHOUSE = 10000000000 | |
19 | 33 | ||
20 | 34 | let RESOURCEPRICEMIN = 158549 | |
21 | 35 | ||
22 | 36 | let resTypes = ["Oil", "Ore", "Wood", "Sand", "Clay", "Organic"] | |
23 | 37 | ||
24 | 38 | let continents = ["Americas", "Europe", "Asia", "Africa", "Oceania"] | |
25 | 39 | ||
26 | 40 | func keyFactoryWarehouseByIdAndType (factoryId,resType) = ((("factoryWhByContinentAndRes_" + factoryId) + "_") + toString(resType)) | |
27 | 41 | ||
28 | 42 | ||
29 | - | func keyAssetIdToOwner (assetId) = ("nftOwner_" + assetId) | |
30 | - | ||
31 | - | ||
32 | - | func keyStakedTimeByAssetId (assetId) = ("stakedTime_" + assetId) | |
33 | - | ||
34 | - | ||
35 | 43 | func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr) | |
36 | 44 | ||
37 | 45 | ||
38 | 46 | func keyBackpackByDuck (duckAssetId) = ("backPack_" + duckAssetId) | |
39 | 47 | ||
40 | 48 | ||
41 | 49 | func keyDuckLocation (duckAssetId) = ("duckLocation_" + duckAssetId) | |
42 | 50 | ||
43 | - | ||
44 | - | let idxType = 0 | |
45 | - | ||
46 | - | let idxQuantity = 1 | |
47 | - | ||
48 | - | let idxPrice = 2 | |
49 | 51 | ||
50 | 52 | let locIdxContinent = 0 | |
51 | 53 | ||
52 | 54 | let locIdxType = 1 | |
53 | 55 | ||
54 | 56 | let locIdxId = 2 | |
55 | 57 | ||
56 | 58 | let bpIdxLevel = 0 | |
57 | 59 | ||
58 | 60 | let bpIdxRes = 1 | |
59 | 61 | ||
60 | 62 | let bpIdxMat = 2 | |
61 | 63 | ||
62 | 64 | let bpIdxProd = 3 | |
63 | 65 | ||
64 | 66 | func asString (v) = match v { | |
65 | 67 | case s: String => | |
66 | 68 | s | |
67 | 69 | case _ => | |
68 | 70 | throw("fail to cast into String") | |
69 | 71 | } | |
70 | 72 | ||
71 | 73 | ||
72 | 74 | func subRes (resList,resType,amount) = { | |
73 | 75 | func subber (acc,i) = (acc :+ (if ((i == resType)) | |
74 | 76 | then toString((parseIntValue(resList[i]) - amount)) | |
75 | 77 | else resList[i])) | |
76 | 78 | ||
77 | 79 | let r = { | |
78 | 80 | let $l = [0, 1, 2, 3, 4, 5] | |
79 | 81 | let $s = size($l) | |
80 | 82 | let $acc0 = nil | |
81 | 83 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
82 | 84 | then $a | |
83 | 85 | else subber($a, $l[$i]) | |
84 | 86 | ||
85 | 87 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
86 | 88 | then $a | |
87 | 89 | else throw("List size exceeds 6") | |
88 | 90 | ||
89 | 91 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
90 | 92 | } | |
91 | 93 | makeString(r, "_") | |
92 | 94 | } | |
93 | 95 | ||
94 | 96 | ||
95 | 97 | func buyInternal (locId,resType,amount,minPrice) = { | |
96 | 98 | let whKey = keyFactoryWarehouseByIdAndType(locId, resType) | |
97 | 99 | let w0 = valueOrElse(getInteger(whKey), 0) | |
98 | 100 | let r0 = if ((w0 > FACTORYMAXWAREHOUSE)) | |
99 | 101 | then 0 | |
100 | 102 | else if (((w0 + amount) > FACTORYMAXWAREHOUSE)) | |
101 | 103 | then (FACTORYMAXWAREHOUSE - w0) | |
102 | 104 | else amount | |
103 | 105 | let usdnReceived = (fraction(r0, ((2 * RESOURCEPRICEMIN) - fraction((w0 + (r0 / 2)), RESOURCEPRICEMIN, FACTORYMAXWAREHOUSE)), MULT8) + fraction((amount - r0), RESOURCEPRICEMIN, MULT8)) | |
104 | 106 | let min99 = (minPrice - (minPrice / 100)) | |
105 | 107 | if (((min99 * amount) > (usdnReceived * MULT8))) | |
106 | 108 | then throw((((((((((("Actual price = " + toString(usdnReceived)) + " / ") + toString(amount)) + " < minPrice = ") + toString(minPrice)) + ", (") + locId) + ", ") + resTypes[resType]) + ")")) | |
107 | 109 | else $Tuple2(IntegerEntry(whKey, (w0 + amount)), usdnReceived) | |
108 | 110 | } | |
109 | 111 | ||
110 | 112 | ||
111 | 113 | @Callable(i) | |
112 | 114 | func sellResource (resType,amount,minPrice) = if (if ((0 > resType)) | |
113 | 115 | then true | |
114 | 116 | else (resType >= NUMRES)) | |
115 | 117 | then throw(("Unknown resource: " + toString(resType))) | |
116 | 118 | else if ((0 >= amount)) | |
117 | 119 | then throw(("Amount should be positive! " + toString(amount))) | |
118 | 120 | else { | |
119 | 121 | let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(toString(i.caller))), "You don't have a duck staked") | |
120 | 122 | if ((size(i.payments) != 0)) | |
121 | 123 | then throw("sellResources doesn't require any payments") | |
122 | 124 | else { | |
123 | 125 | let curLocation = split(valueOrElse(getString(stakingContract, keyDuckLocation(duckAssetId)), DEFAULTLOCATION), "_") | |
124 | 126 | if ((curLocation[locIdxType] != "F")) | |
125 | 127 | then throw(("Duck location type should be Factory, but is " + curLocation[locIdxType])) | |
126 | 128 | else { | |
127 | 129 | let currentPack = split(valueOrElse(getString(stakingContract, keyBackpackByDuck(duckAssetId)), "0:0_0_0_0_0_0::"), ":") | |
128 | 130 | let resList = split(currentPack[bpIdxRes], "_") | |
129 | 131 | let currentRes = parseIntValue(resList[resType]) | |
130 | 132 | if ((amount > currentRes)) | |
131 | 133 | then throw(((((("You have " + toString(currentRes)) + " of ") + resTypes[resType]) + " in backpack, but tried to sell ") + toString(amount))) | |
132 | 134 | else { | |
133 | 135 | let b = buyInternal(curLocation[locIdxId], resType, amount, minPrice) | |
134 | 136 | let bpRes = subRes(resList, resType, amount) | |
135 | 137 | let newPack = makeString([currentPack[bpIdxLevel], bpRes, currentPack[bpIdxMat], currentPack[bpIdxProd]], ":") | |
136 | 138 | let result = asString(invoke(stakingContract, "updateBackpack", [duckAssetId, newPack], nil)) | |
137 | 139 | $Tuple2([b._1, ScriptTransfer(i.caller, b._2, usdnAssetId)], result) | |
138 | 140 | } | |
139 | 141 | } | |
140 | 142 | } | |
141 | 143 | } | |
142 | 144 | ||
143 | 145 | ||
144 | 146 | ||
145 | 147 | @Callable(i) | |
146 | 148 | func sellResources (resTypes,minPrices) = { | |
147 | 149 | let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(toString(i.caller))), "You don't have a duck staked") | |
148 | 150 | if ((size(i.payments) != 0)) | |
149 | 151 | then throw("sellResources doesn't require any payments") | |
150 | 152 | else { | |
151 | 153 | let curLocation = split(valueOrElse(getString(stakingContract, keyDuckLocation(duckAssetId)), DEFAULTLOCATION), "_") | |
152 | 154 | if ((curLocation[locIdxType] != "F")) | |
153 | 155 | then throw(("Duck location type should be Factory, but is " + curLocation[locIdxType])) | |
154 | 156 | else { | |
155 | 157 | let locId = curLocation[locIdxId] | |
156 | 158 | let currentPack = split(valueOrElse(getString(stakingContract, keyBackpackByDuck(duckAssetId)), "0:0_0_0_0_0_0::"), ":") | |
157 | 159 | let resList = split(currentPack[bpIdxRes], "_") | |
158 | 160 | func adder (acc,idx) = { | |
159 | 161 | let j = indexOf(resTypes, idx) | |
160 | 162 | if (isDefined(j)) | |
161 | 163 | then { | |
162 | 164 | let b = buyInternal(locId, idx, parseIntValue(resList[idx]), minPrices[value(j)]) | |
163 | 165 | $Tuple3((acc._1 :+ b._1), (acc._2 :+ "0"), (acc._3 + b._2)) | |
164 | 166 | } | |
165 | 167 | else $Tuple3(acc._1, (acc._2 :+ resList[idx]), acc._3) | |
166 | 168 | } | |
167 | 169 | ||
168 | 170 | let merged = { | |
169 | 171 | let $l = [0, 1, 2, 3, 4, 5] | |
170 | 172 | let $s = size($l) | |
171 | 173 | let $acc0 = $Tuple3(nil, nil, 0) | |
172 | 174 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
173 | 175 | then $a | |
174 | 176 | else adder($a, $l[$i]) | |
175 | 177 | ||
176 | 178 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
177 | 179 | then $a | |
178 | 180 | else throw("List size exceeds 6") | |
179 | 181 | ||
180 | 182 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
181 | 183 | } | |
182 | 184 | let newPack = makeString([currentPack[bpIdxLevel], makeString(merged._2, "_"), currentPack[bpIdxMat], currentPack[bpIdxProd]], ":") | |
183 | 185 | let result = asString(invoke(stakingContract, "updateBackpack", [duckAssetId, newPack], nil)) | |
184 | 186 | $Tuple2((merged._1 :+ ScriptTransfer(i.caller, merged._3, usdnAssetId)), result) | |
185 | 187 | } | |
186 | 188 | } | |
187 | 189 | } | |
188 | 190 | ||
189 | 191 |
github/deemru/w8io/169f3d6 51.46 ms ◑