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/eDymXbbhPuAjvPWCmVqcHRjfJL2mzYHWKAyN4JAAIBAg1Vbmtub3duIGNoYWluAA9zdGFraW5nQ29udHJhY3QJARFAZXh0ck5hdGl2ZSgxMDYyKQEEByRtYXRjaDAFBWNoYWluAwkAAAICAVcFByRtYXRjaDACIzNQTG5jWHRTMVU4M0Q2Y1FiRkQzSDhyQkhQTGd6eFNGS1oxAwkAAAICAVQFByRtYXRjaDACIzNOREN5Qkc1cTg1SnVhUmlpZ1VlRXRhaW55akNRVDNYcFptCQACAQINVW5rbm93biBjaGFpbgAPREVGQVVMVExPQ0FUSU9OAg9BZnJpY2FfRl9BZnJpY2E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ZHVja0Fzc2V0SWQJAMwIAgUHbmV3UGFjawUDbmlsBQNuaWwJAJQKAgkAzQgCCAUGbWVyZ2VkAl8xCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIIBQZtZXJnZWQCXzMFC3VzZG5Bc3NldElkBQZyZXN1bHQAUIDrLA==", "height": 2357046, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4Hnti9WWrSuYW1HSCA4oEe56WNH1B6bU9ZB1tAY6CpM7 Next: GWecBuefRy863qXkyR1zwKtQE3w1fyEKp1SyNcxEnAC4 Diff:
OldNewDifferences
55
66 let MULT8 = 100000000
77
8-let usdnAssetId = base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ'
8+let chain = toUtf8String(take(drop(this.bytes, 1), 1))
99
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+}
1118
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+})
1327
1428 let DEFAULTLOCATION = "Africa_F_Africa"
1529
2640 func keyFactoryWarehouseByIdAndType (factoryId,resType) = ((("factoryWhByContinentAndRes_" + factoryId) + "_") + toString(resType))
2741
2842
29-func keyAssetIdToOwner (assetId) = ("nftOwner_" + assetId)
30-
31-
32-func keyStakedTimeByAssetId (assetId) = ("stakedTime_" + assetId)
33-
34-
3543 func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr)
3644
3745
4048
4149 func keyDuckLocation (duckAssetId) = ("duckLocation_" + duckAssetId)
4250
43-
44-let idxType = 0
45-
46-let idxQuantity = 1
47-
48-let idxPrice = 2
4951
5052 let locIdxContinent = 0
5153
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let MULT6 = 1000000
55
66 let MULT8 = 100000000
77
8-let usdnAssetId = base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ'
8+let chain = toUtf8String(take(drop(this.bytes, 1), 1))
99
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+}
1118
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+})
1327
1428 let DEFAULTLOCATION = "Africa_F_Africa"
1529
1630 let NUMRES = 6
1731
1832 let FACTORYMAXWAREHOUSE = 10000000000
1933
2034 let RESOURCEPRICEMIN = 158549
2135
2236 let resTypes = ["Oil", "Ore", "Wood", "Sand", "Clay", "Organic"]
2337
2438 let continents = ["Americas", "Europe", "Asia", "Africa", "Oceania"]
2539
2640 func keyFactoryWarehouseByIdAndType (factoryId,resType) = ((("factoryWhByContinentAndRes_" + factoryId) + "_") + toString(resType))
2741
2842
29-func keyAssetIdToOwner (assetId) = ("nftOwner_" + assetId)
30-
31-
32-func keyStakedTimeByAssetId (assetId) = ("stakedTime_" + assetId)
33-
34-
3543 func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr)
3644
3745
3846 func keyBackpackByDuck (duckAssetId) = ("backPack_" + duckAssetId)
3947
4048
4149 func keyDuckLocation (duckAssetId) = ("duckLocation_" + duckAssetId)
4250
43-
44-let idxType = 0
45-
46-let idxQuantity = 1
47-
48-let idxPrice = 2
4951
5052 let locIdxContinent = 0
5153
5254 let locIdxType = 1
5355
5456 let locIdxId = 2
5557
5658 let bpIdxLevel = 0
5759
5860 let bpIdxRes = 1
5961
6062 let bpIdxMat = 2
6163
6264 let bpIdxProd = 3
6365
6466 func asString (v) = match v {
6567 case s: String =>
6668 s
6769 case _ =>
6870 throw("fail to cast into String")
6971 }
7072
7173
7274 func subRes (resList,resType,amount) = {
7375 func subber (acc,i) = (acc :+ (if ((i == resType))
7476 then toString((parseIntValue(resList[i]) - amount))
7577 else resList[i]))
7678
7779 let r = {
7880 let $l = [0, 1, 2, 3, 4, 5]
7981 let $s = size($l)
8082 let $acc0 = nil
8183 func $f0_1 ($a,$i) = if (($i >= $s))
8284 then $a
8385 else subber($a, $l[$i])
8486
8587 func $f0_2 ($a,$i) = if (($i >= $s))
8688 then $a
8789 else throw("List size exceeds 6")
8890
8991 $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6)
9092 }
9193 makeString(r, "_")
9294 }
9395
9496
9597 func buyInternal (locId,resType,amount,minPrice) = {
9698 let whKey = keyFactoryWarehouseByIdAndType(locId, resType)
9799 let w0 = valueOrElse(getInteger(whKey), 0)
98100 let r0 = if ((w0 > FACTORYMAXWAREHOUSE))
99101 then 0
100102 else if (((w0 + amount) > FACTORYMAXWAREHOUSE))
101103 then (FACTORYMAXWAREHOUSE - w0)
102104 else amount
103105 let usdnReceived = (fraction(r0, ((2 * RESOURCEPRICEMIN) - fraction((w0 + (r0 / 2)), RESOURCEPRICEMIN, FACTORYMAXWAREHOUSE)), MULT8) + fraction((amount - r0), RESOURCEPRICEMIN, MULT8))
104106 let min99 = (minPrice - (minPrice / 100))
105107 if (((min99 * amount) > (usdnReceived * MULT8)))
106108 then throw((((((((((("Actual price = " + toString(usdnReceived)) + " / ") + toString(amount)) + " < minPrice = ") + toString(minPrice)) + ", (") + locId) + ", ") + resTypes[resType]) + ")"))
107109 else $Tuple2(IntegerEntry(whKey, (w0 + amount)), usdnReceived)
108110 }
109111
110112
111113 @Callable(i)
112114 func sellResource (resType,amount,minPrice) = if (if ((0 > resType))
113115 then true
114116 else (resType >= NUMRES))
115117 then throw(("Unknown resource: " + toString(resType)))
116118 else if ((0 >= amount))
117119 then throw(("Amount should be positive! " + toString(amount)))
118120 else {
119121 let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(toString(i.caller))), "You don't have a duck staked")
120122 if ((size(i.payments) != 0))
121123 then throw("sellResources doesn't require any payments")
122124 else {
123125 let curLocation = split(valueOrElse(getString(stakingContract, keyDuckLocation(duckAssetId)), DEFAULTLOCATION), "_")
124126 if ((curLocation[locIdxType] != "F"))
125127 then throw(("Duck location type should be Factory, but is " + curLocation[locIdxType]))
126128 else {
127129 let currentPack = split(valueOrElse(getString(stakingContract, keyBackpackByDuck(duckAssetId)), "0:0_0_0_0_0_0::"), ":")
128130 let resList = split(currentPack[bpIdxRes], "_")
129131 let currentRes = parseIntValue(resList[resType])
130132 if ((amount > currentRes))
131133 then throw(((((("You have " + toString(currentRes)) + " of ") + resTypes[resType]) + " in backpack, but tried to sell ") + toString(amount)))
132134 else {
133135 let b = buyInternal(curLocation[locIdxId], resType, amount, minPrice)
134136 let bpRes = subRes(resList, resType, amount)
135137 let newPack = makeString([currentPack[bpIdxLevel], bpRes, currentPack[bpIdxMat], currentPack[bpIdxProd]], ":")
136138 let result = asString(invoke(stakingContract, "updateBackpack", [duckAssetId, newPack], nil))
137139 $Tuple2([b._1, ScriptTransfer(i.caller, b._2, usdnAssetId)], result)
138140 }
139141 }
140142 }
141143 }
142144
143145
144146
145147 @Callable(i)
146148 func sellResources (resTypes,minPrices) = {
147149 let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(toString(i.caller))), "You don't have a duck staked")
148150 if ((size(i.payments) != 0))
149151 then throw("sellResources doesn't require any payments")
150152 else {
151153 let curLocation = split(valueOrElse(getString(stakingContract, keyDuckLocation(duckAssetId)), DEFAULTLOCATION), "_")
152154 if ((curLocation[locIdxType] != "F"))
153155 then throw(("Duck location type should be Factory, but is " + curLocation[locIdxType]))
154156 else {
155157 let locId = curLocation[locIdxId]
156158 let currentPack = split(valueOrElse(getString(stakingContract, keyBackpackByDuck(duckAssetId)), "0:0_0_0_0_0_0::"), ":")
157159 let resList = split(currentPack[bpIdxRes], "_")
158160 func adder (acc,idx) = {
159161 let j = indexOf(resTypes, idx)
160162 if (isDefined(j))
161163 then {
162164 let b = buyInternal(locId, idx, parseIntValue(resList[idx]), minPrices[value(j)])
163165 $Tuple3((acc._1 :+ b._1), (acc._2 :+ "0"), (acc._3 + b._2))
164166 }
165167 else $Tuple3(acc._1, (acc._2 :+ resList[idx]), acc._3)
166168 }
167169
168170 let merged = {
169171 let $l = [0, 1, 2, 3, 4, 5]
170172 let $s = size($l)
171173 let $acc0 = $Tuple3(nil, nil, 0)
172174 func $f0_1 ($a,$i) = if (($i >= $s))
173175 then $a
174176 else adder($a, $l[$i])
175177
176178 func $f0_2 ($a,$i) = if (($i >= $s))
177179 then $a
178180 else throw("List size exceeds 6")
179181
180182 $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6)
181183 }
182184 let newPack = makeString([currentPack[bpIdxLevel], makeString(merged._2, "_"), currentPack[bpIdxMat], currentPack[bpIdxProd]], ":")
183185 let result = asString(invoke(stakingContract, "updateBackpack", [duckAssetId, newPack], nil))
184186 $Tuple2((merged._1 :+ ScriptTransfer(i.caller, merged._3, usdnAssetId)), result)
185187 }
186188 }
187189 }
188190
189191

github/deemru/w8io/169f3d6 
51.46 ms