1 | | - | # no script |
---|
| 1 | + | {-# STDLIB_VERSION 6 #-} |
---|
| 2 | + | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
| 3 | + | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | let separator = "__" |
---|
| 5 | + | |
---|
| 6 | + | let poolWeightMult = 100000000 |
---|
| 7 | + | |
---|
| 8 | + | let maxDepthDefault = 10 |
---|
| 9 | + | |
---|
| 10 | + | let finalizationStageTotal = 0 |
---|
| 11 | + | |
---|
| 12 | + | let finalizationStageShares = 1 |
---|
| 13 | + | |
---|
| 14 | + | let keyEpochLength = makeString(["%s", "epochLength"], separator) |
---|
| 15 | + | |
---|
| 16 | + | let keyEpochLengthNew = makeString(["%s%s", "epochLength__new"], separator) |
---|
| 17 | + | |
---|
| 18 | + | func keyEpochLengthByEpoch (epoch) = makeString(["%s%d", "epochLength", toString(epoch)], separator) |
---|
| 19 | + | |
---|
| 20 | + | |
---|
| 21 | + | let keyCurrentEpoch = makeString(["%s", "currentEpoch"], separator) |
---|
| 22 | + | |
---|
| 23 | + | let keyMaxDepth = makeString(["%s", "maxDepth"], separator) |
---|
| 24 | + | |
---|
| 25 | + | let keyVotingEmissionCandidateContract = makeString(["%s", "votingEmissionCandidateContract"], separator) |
---|
| 26 | + | |
---|
| 27 | + | let keyFactoryContract = makeString(["%s", "factoryContract"], separator) |
---|
| 28 | + | |
---|
| 29 | + | let keyBoostingContract = makeString(["%s", "boostingContract"], separator) |
---|
| 30 | + | |
---|
| 31 | + | let keyStakingContract = makeString(["%s", "stakingContract"], separator) |
---|
| 32 | + | |
---|
| 33 | + | let keyFinalizationStage = makeString(["%s", "finalizationStage"], separator) |
---|
| 34 | + | |
---|
| 35 | + | let keyNextPool = makeString(["%s", "nextPool"], separator) |
---|
| 36 | + | |
---|
| 37 | + | let keyNextUser = makeString(["%s", "nextUser"], separator) |
---|
| 38 | + | |
---|
| 39 | + | let keyStartHeight = makeString(["%s", "startHeight"], separator) |
---|
| 40 | + | |
---|
| 41 | + | let keyCurrentEpochUi = makeString(["%s", "currentEpochUi"], separator) |
---|
| 42 | + | |
---|
| 43 | + | let keyStartHeightUi = makeString(["%s", "startHeightUi"], separator) |
---|
| 44 | + | |
---|
| 45 | + | let keyFinalizationShouldBeForced = makeString(["%s", "force"], separator) |
---|
| 46 | + | |
---|
| 47 | + | func keyStartHeightByEpoch (epoch) = makeString(["%s%d", "startHeight", toString(epoch)], separator) |
---|
| 48 | + | |
---|
| 49 | + | |
---|
| 50 | + | func keyFinalized (epoch) = makeString(["%s%d", "finalized", toString(epoch)], separator) |
---|
| 51 | + | |
---|
| 52 | + | |
---|
| 53 | + | func keyInList (pool) = { |
---|
| 54 | + | let $t016931733 = pool |
---|
| 55 | + | let amountAssetId = $t016931733._1 |
---|
| 56 | + | let priceAssetId = $t016931733._2 |
---|
| 57 | + | makeString(["%s%s%s", "inList", amountAssetId, priceAssetId], separator) |
---|
| 58 | + | } |
---|
| 59 | + | |
---|
| 60 | + | |
---|
| 61 | + | func keyUsed (address,epoch) = makeString(["%s%s%d", "used", toString(address), toString(epoch)], separator) |
---|
| 62 | + | |
---|
| 63 | + | |
---|
| 64 | + | func keyVote (pool,address,epoch) = { |
---|
| 65 | + | let $t020072047 = pool |
---|
| 66 | + | let amountAssetId = $t020072047._1 |
---|
| 67 | + | let priceAssetId = $t020072047._2 |
---|
| 68 | + | makeString(["%s%s%s%s%d", "vote", amountAssetId, priceAssetId, toString(address), toString(epoch)], separator) |
---|
| 69 | + | } |
---|
| 70 | + | |
---|
| 71 | + | |
---|
| 72 | + | func keyVotingResult (pool,epoch) = { |
---|
| 73 | + | let $t022292269 = pool |
---|
| 74 | + | let amountAssetId = $t022292269._1 |
---|
| 75 | + | let priceAssetId = $t022292269._2 |
---|
| 76 | + | makeString(["%s%s%s%d", "votingResult", amountAssetId, priceAssetId, toString(epoch)], separator) |
---|
| 77 | + | } |
---|
| 78 | + | |
---|
| 79 | + | |
---|
| 80 | + | func keyVotingResultStaked (lpAssetIdStr,epoch) = makeString(["%s%s%d", "votingResultStaked", lpAssetIdStr, toString(epoch)], separator) |
---|
| 81 | + | |
---|
| 82 | + | |
---|
| 83 | + | func keyPoolShare (pool,epoch) = { |
---|
| 84 | + | let $t025902630 = pool |
---|
| 85 | + | let amountAssetId = $t025902630._1 |
---|
| 86 | + | let priceAssetId = $t025902630._2 |
---|
| 87 | + | makeString(["%s%s%s%d", "poolShare", amountAssetId, priceAssetId, toString(epoch)], separator) |
---|
| 88 | + | } |
---|
| 89 | + | |
---|
| 90 | + | |
---|
| 91 | + | func keyTotalVotes (epoch) = makeString(["%s%d", "totalVotes", toString(epoch)], separator) |
---|
| 92 | + | |
---|
| 93 | + | |
---|
| 94 | + | func keyStakedByUser (lpAssetIdStr,userAddressStr) = makeString(["%s%s%s", "staked", userAddressStr, lpAssetIdStr], separator) |
---|
| 95 | + | |
---|
| 96 | + | |
---|
| 97 | + | func wrapErr (msg) = makeString(["voting_emission.ride:", msg], " ") |
---|
| 98 | + | |
---|
| 99 | + | |
---|
| 100 | + | func throwErr (msg) = throw(wrapErr(msg)) |
---|
| 101 | + | |
---|
| 102 | + | |
---|
| 103 | + | func getValueOrFail (address,key,type) = { |
---|
| 104 | + | let error = wrapErr(makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) |
---|
| 105 | + | valueOrErrorMessage( match type { |
---|
| 106 | + | case str: String => |
---|
| 107 | + | getString(address, key) |
---|
| 108 | + | case int: Int => |
---|
| 109 | + | getInteger(address, key) |
---|
| 110 | + | case _ => |
---|
| 111 | + | throwErr("invalid entry type") |
---|
| 112 | + | }, error) |
---|
| 113 | + | } |
---|
| 114 | + | |
---|
| 115 | + | |
---|
| 116 | + | func getStrOrFail (address,key) = { |
---|
| 117 | + | let @ = getValueOrFail(address, key, "") |
---|
| 118 | + | if ($isInstanceOf(@, "String")) |
---|
| 119 | + | then @ |
---|
| 120 | + | else throw(($getType(@) + " couldn't be cast to String")) |
---|
| 121 | + | } |
---|
| 122 | + | |
---|
| 123 | + | |
---|
| 124 | + | func getIntOrFail (address,key) = { |
---|
| 125 | + | let @ = getValueOrFail(address, key, 0) |
---|
| 126 | + | if ($isInstanceOf(@, "Int")) |
---|
| 127 | + | then @ |
---|
| 128 | + | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
| 129 | + | } |
---|
| 130 | + | |
---|
| 131 | + | |
---|
| 132 | + | func poolToString (pool) = ((pool._1 + separator) + pool._2) |
---|
| 133 | + | |
---|
| 134 | + | |
---|
| 135 | + | func stringToPool (str) = { |
---|
| 136 | + | let parts = split(str, separator) |
---|
| 137 | + | if ((size(parts) == 2)) |
---|
| 138 | + | then $Tuple2(parts[0], parts[1]) |
---|
| 139 | + | else throwErr("invalid pool string") |
---|
| 140 | + | } |
---|
| 141 | + | |
---|
| 142 | + | |
---|
| 143 | + | func getLpAssetByPoolAssets (amountAssetId,priceAssetId) = { |
---|
| 144 | + | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) |
---|
| 145 | + | |
---|
| 146 | + | func keyMappingPoolAssetsToPoolContractAddress (internalAmountAssetIdStr,internalPriceAssetIdStr) = (((("%d%d%s%s__" + toString(internalAmountAssetIdStr)) + "__") + toString(internalPriceAssetIdStr)) + "__mappings__poolAssets2PoolContract") |
---|
| 147 | + | |
---|
| 148 | + | func keyMappingPoolContractToLPAsset (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") |
---|
| 149 | + | |
---|
| 150 | + | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract)) |
---|
| 151 | + | let amountAssetInternalId = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amountAssetId)) |
---|
| 152 | + | let priceAssetInternalId = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAssetId)) |
---|
| 153 | + | let poolContractAddress = getStrOrFail(factoryContract, keyMappingPoolAssetsToPoolContractAddress(amountAssetInternalId, priceAssetInternalId)) |
---|
| 154 | + | let lpAssetId = getStrOrFail(factoryContract, keyMappingPoolContractToLPAsset(poolContractAddress)) |
---|
| 155 | + | lpAssetId |
---|
| 156 | + | } |
---|
| 157 | + | |
---|
| 158 | + | |
---|
| 159 | + | func checkWxEmissionPoolLabel (pool) = { |
---|
| 160 | + | let $t051685208 = pool |
---|
| 161 | + | let amountAssetId = $t051685208._1 |
---|
| 162 | + | let priceAssetId = $t051685208._2 |
---|
| 163 | + | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract)) |
---|
| 164 | + | let @ = invoke(factoryContract, "checkWxEmissionPoolLabel", [amountAssetId, priceAssetId], nil) |
---|
| 165 | + | if ($isInstanceOf(@, "Boolean")) |
---|
| 166 | + | then @ |
---|
| 167 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
| 168 | + | } |
---|
| 169 | + | |
---|
| 170 | + | |
---|
| 171 | + | let poolsListName = "pools" |
---|
| 172 | + | |
---|
| 173 | + | func getVotesListName (pool) = { |
---|
| 174 | + | let $t055095549 = pool |
---|
| 175 | + | let amountAssetId = $t055095549._1 |
---|
| 176 | + | let priceAssetId = $t055095549._2 |
---|
| 177 | + | makeString(["votes", amountAssetId, priceAssetId], separator) |
---|
| 178 | + | } |
---|
| 179 | + | |
---|
| 180 | + | |
---|
| 181 | + | func keyListHead (listName) = { |
---|
| 182 | + | let meta = if ((listName == poolsListName)) |
---|
| 183 | + | then "%s%s" |
---|
| 184 | + | else "%s%s%s%s" |
---|
| 185 | + | makeString([meta, listName, "head"], separator) |
---|
| 186 | + | } |
---|
| 187 | + | |
---|
| 188 | + | |
---|
| 189 | + | func keyListSize (listName) = { |
---|
| 190 | + | let meta = if ((listName == poolsListName)) |
---|
| 191 | + | then "%s%s" |
---|
| 192 | + | else "%s%s%s%s" |
---|
| 193 | + | makeString([meta, listName, "size"], separator) |
---|
| 194 | + | } |
---|
| 195 | + | |
---|
| 196 | + | |
---|
| 197 | + | func keyListPrev (listName,id) = { |
---|
| 198 | + | let meta = if ((listName == poolsListName)) |
---|
| 199 | + | then "%s%s%s%s" |
---|
| 200 | + | else "%s%s%s%s%s" |
---|
| 201 | + | makeString([meta, listName, id, "prev"], separator) |
---|
| 202 | + | } |
---|
| 203 | + | |
---|
| 204 | + | |
---|
| 205 | + | func keyListNext (listName,id) = { |
---|
| 206 | + | let meta = if ((listName == poolsListName)) |
---|
| 207 | + | then "%s%s%s%s" |
---|
| 208 | + | else "%s%s%s%s%s" |
---|
| 209 | + | makeString([meta, listName, id, "next"], separator) |
---|
| 210 | + | } |
---|
| 211 | + | |
---|
| 212 | + | |
---|
| 213 | + | func containsNode (listName,id) = { |
---|
| 214 | + | let headOrUnit = getString(this, keyListHead(listName)) |
---|
| 215 | + | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
| 216 | + | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
| 217 | + | if (if ((id == valueOrElse(headOrUnit, ""))) |
---|
| 218 | + | then true |
---|
| 219 | + | else (prevOrUnit != unit)) |
---|
| 220 | + | then true |
---|
| 221 | + | else (nextOrUnit != unit) |
---|
| 222 | + | } |
---|
| 223 | + | |
---|
| 224 | + | |
---|
| 225 | + | func insertNodeActions (listName,id) = { |
---|
| 226 | + | let headOrUnit = getString(this, keyListHead(listName)) |
---|
| 227 | + | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
| 228 | + | let checkNode = if (!(containsNode(listName, id))) |
---|
| 229 | + | then true |
---|
| 230 | + | else throwErr("Node exists") |
---|
| 231 | + | if ((checkNode == checkNode)) |
---|
| 232 | + | then (([IntegerEntry(keyListSize(listName), (listSize + 1))] ++ (if ((headOrUnit != unit)) |
---|
| 233 | + | then [StringEntry(keyListNext(listName, id), value(headOrUnit)), StringEntry(keyListPrev(listName, value(headOrUnit)), id)] |
---|
| 234 | + | else nil)) ++ [StringEntry(keyListHead(listName), id)]) |
---|
| 235 | + | else throw("Strict value is not equal to itself.") |
---|
| 236 | + | } |
---|
| 237 | + | |
---|
| 238 | + | |
---|
| 239 | + | func deleteNodeActions (listName,id) = { |
---|
| 240 | + | let headOrUnit = getString(this, keyListHead(listName)) |
---|
| 241 | + | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
| 242 | + | let prevOrUnit = getString(this, keyListPrev(listName, id)) |
---|
| 243 | + | let nextOrUnit = getString(this, keyListNext(listName, id)) |
---|
| 244 | + | ([IntegerEntry(keyListSize(listName), (listSize - 1))] ++ (if (if ((prevOrUnit != unit)) |
---|
| 245 | + | then (nextOrUnit != unit) |
---|
| 246 | + | else false) |
---|
| 247 | + | then [StringEntry(keyListNext(listName, value(prevOrUnit)), value(nextOrUnit)), StringEntry(keyListPrev(listName, value(nextOrUnit)), value(prevOrUnit)), DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, id))] |
---|
| 248 | + | else if ((nextOrUnit != unit)) |
---|
| 249 | + | then [StringEntry(keyListHead(listName), value(nextOrUnit)), DeleteEntry(keyListNext(listName, id)), DeleteEntry(keyListPrev(listName, value(nextOrUnit)))] |
---|
| 250 | + | else if ((prevOrUnit != unit)) |
---|
| 251 | + | then [DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, value(prevOrUnit)))] |
---|
| 252 | + | else if ((id == valueOrElse(headOrUnit, ""))) |
---|
| 253 | + | then [DeleteEntry(keyListHead(listName))] |
---|
| 254 | + | else throwErr(((("invalid node: " + listName) + ".") + id)))) |
---|
| 255 | + | } |
---|
| 256 | + | |
---|
| 257 | + | |
---|
| 258 | + | func keyManagerVaultAddress () = "%s__managerVaultAddress" |
---|
| 259 | + | |
---|
| 260 | + | |
---|
| 261 | + | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
| 262 | + | |
---|
| 263 | + | |
---|
| 264 | + | func getManagerAddressOrFail () = addressFromStringValue(getStringValue(keyManagerVaultAddress())) |
---|
| 265 | + | |
---|
| 266 | + | |
---|
| 267 | + | func managerPublicKeyOrUnit () = { |
---|
| 268 | + | let managerVaultAddress = getManagerAddressOrFail() |
---|
| 269 | + | match getString(managerVaultAddress, keyManagerPublicKey()) { |
---|
| 270 | + | case s: String => |
---|
| 271 | + | fromBase58String(s) |
---|
| 272 | + | case _: Unit => |
---|
| 273 | + | unit |
---|
| 274 | + | case _ => |
---|
| 275 | + | throw("Match error") |
---|
| 276 | + | } |
---|
| 277 | + | } |
---|
| 278 | + | |
---|
| 279 | + | |
---|
| 280 | + | func isManager (i) = match managerPublicKeyOrUnit() { |
---|
| 281 | + | case pk: ByteVector => |
---|
| 282 | + | (i.callerPublicKey == pk) |
---|
| 283 | + | case _: Unit => |
---|
| 284 | + | (i.caller == this) |
---|
| 285 | + | case _ => |
---|
| 286 | + | throw("Match error") |
---|
| 287 | + | } |
---|
| 288 | + | |
---|
| 289 | + | |
---|
| 290 | + | func mustManager (i) = if (isManager(i)) |
---|
| 291 | + | then true |
---|
| 292 | + | else throw("permission denied") |
---|
| 293 | + | |
---|
| 294 | + | |
---|
| 295 | + | func mustThis (i) = if ((i.caller == this)) |
---|
| 296 | + | then true |
---|
| 297 | + | else throw("permission denied") |
---|
| 298 | + | |
---|
| 299 | + | |
---|
| 300 | + | @Callable(i) |
---|
| 301 | + | func getUserGwxAmountAtHeight (userAddress,targetHeight) = { |
---|
| 302 | + | let boostingContractAddress = valueOrErrorMessage(addressFromString(getStrOrFail(this, keyBoostingContract)), wrapErr("invalid boosting contract address")) |
---|
| 303 | + | $Tuple2(nil, { |
---|
| 304 | + | let @ = invoke(boostingContractAddress, "getUserGwxAmountAtHeightREADONLY", [userAddress, targetHeight], nil) |
---|
| 305 | + | if ($isInstanceOf(@, "Int")) |
---|
| 306 | + | then @ |
---|
| 307 | + | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
| 308 | + | }) |
---|
| 309 | + | } |
---|
| 310 | + | |
---|
| 311 | + | |
---|
| 312 | + | |
---|
| 313 | + | @Callable(i) |
---|
| 314 | + | func constructor (factoryContract,votingEmissionCandidateContract,boostingContract,stakingContract,epochLength) = { |
---|
| 315 | + | let checks = [mustManager(i), if ((addressFromString(factoryContract) != unit)) |
---|
| 316 | + | then true |
---|
| 317 | + | else "invalid factory contract address", if ((addressFromString(votingEmissionCandidateContract) != unit)) |
---|
| 318 | + | then true |
---|
| 319 | + | else "invalid voting emission candidate contract address", if ((addressFromString(boostingContract) != unit)) |
---|
| 320 | + | then true |
---|
| 321 | + | else "invalid boosting contract address", if ((addressFromString(stakingContract) != unit)) |
---|
| 322 | + | then true |
---|
| 323 | + | else "invalid staking contract address", if ((epochLength > 0)) |
---|
| 324 | + | then true |
---|
| 325 | + | else throwErr("invalid epoch length")] |
---|
| 326 | + | if ((checks == checks)) |
---|
| 327 | + | then $Tuple2([StringEntry(keyFactoryContract, factoryContract), StringEntry(keyVotingEmissionCandidateContract, votingEmissionCandidateContract), StringEntry(keyBoostingContract, boostingContract), StringEntry(keyStakingContract, stakingContract), IntegerEntry(keyEpochLength, epochLength)], unit) |
---|
| 328 | + | else throw("Strict value is not equal to itself.") |
---|
| 329 | + | } |
---|
| 330 | + | |
---|
| 331 | + | |
---|
| 332 | + | |
---|
| 333 | + | @Callable(i) |
---|
| 334 | + | func create (amountAssetId,priceAssetId) = { |
---|
| 335 | + | let checks = [if ((toBase58String(i.caller.bytes) == valueOrElse(getString(this, keyVotingEmissionCandidateContract), ""))) |
---|
| 336 | + | then true |
---|
| 337 | + | else mustManager(i)] |
---|
| 338 | + | if ((checks == checks)) |
---|
| 339 | + | then { |
---|
| 340 | + | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
| 341 | + | let inListActions = ([BooleanEntry(keyInList(pool), true)] ++ insertNodeActions(poolsListName, poolToString(pool))) |
---|
| 342 | + | let currentEpochIsNotDefined = (getInteger(this, keyCurrentEpoch) == unit) |
---|
| 343 | + | let startHeightActions = if (currentEpochIsNotDefined) |
---|
| 344 | + | then { |
---|
| 345 | + | let epoch = 0 |
---|
| 346 | + | [IntegerEntry(keyCurrentEpoch, epoch), IntegerEntry(keyStartHeightByEpoch(epoch), height), IntegerEntry(keyStartHeight, height), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, height)] |
---|
| 347 | + | } |
---|
| 348 | + | else nil |
---|
| 349 | + | $Tuple2((inListActions ++ startHeightActions), unit) |
---|
| 350 | + | } |
---|
| 351 | + | else throw("Strict value is not equal to itself.") |
---|
| 352 | + | } |
---|
| 353 | + | |
---|
| 354 | + | |
---|
| 355 | + | |
---|
| 356 | + | @Callable(i) |
---|
| 357 | + | func vote (amountAssetId,priceAssetId,amount) = { |
---|
| 358 | + | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
| 359 | + | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
| 360 | + | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
| 361 | + | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
| 362 | + | let endHeight = (startHeight + epochLength) |
---|
| 363 | + | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
| 364 | + | let used = valueOrElse(getInteger(this, keyUsed(i.caller, epoch)), 0) |
---|
| 365 | + | let vote = valueOrElse(getInteger(this, keyVote(pool, i.caller, epoch)), 0) |
---|
| 366 | + | let poolResult = valueOrElse(getInteger(this, keyVotingResult(pool, epoch)), 0) |
---|
| 367 | + | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(epoch)), 0) |
---|
| 368 | + | let gwxAmountAtEndTotal = { |
---|
| 369 | + | let @ = invoke(this, "getUserGwxAmountAtHeight", [toBase58String(i.caller.bytes), endHeight], nil) |
---|
| 370 | + | if ($isInstanceOf(@, "Int")) |
---|
| 371 | + | then @ |
---|
| 372 | + | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
| 373 | + | } |
---|
| 374 | + | let available = (gwxAmountAtEndTotal - used) |
---|
| 375 | + | let newVote = (vote + amount) |
---|
| 376 | + | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
| 377 | + | let checks = [if ((getBoolean(keyInList(pool)) != unit)) |
---|
| 378 | + | then true |
---|
| 379 | + | else throwErr("invalid assets"), if ((endHeight > height)) |
---|
| 380 | + | then true |
---|
| 381 | + | else throwErr("invalid height"), if ((finalizationStageOrUnit == unit)) |
---|
| 382 | + | then true |
---|
| 383 | + | else throwErr("finalization in progress"), if ((gwxAmountAtEndTotal > 0)) |
---|
| 384 | + | then true |
---|
| 385 | + | else throwErr("you do not have gWX"), if (if ((amount > 0)) |
---|
| 386 | + | then (available >= amount) |
---|
| 387 | + | else false) |
---|
| 388 | + | then true |
---|
| 389 | + | else throwErr("invalid amount"), if (wxEmission) |
---|
| 390 | + | then true |
---|
| 391 | + | else throwErr("pool hasn't WX_EMISSION label")] |
---|
| 392 | + | if ((checks == checks)) |
---|
| 393 | + | then { |
---|
| 394 | + | let votesListName = getVotesListName(pool) |
---|
| 395 | + | let userAddressStr = toString(i.caller) |
---|
| 396 | + | let votesListActions = if (containsNode(votesListName, userAddressStr)) |
---|
| 397 | + | then nil |
---|
| 398 | + | else insertNodeActions(votesListName, userAddressStr) |
---|
| 399 | + | $Tuple2(([IntegerEntry(keyUsed(i.caller, epoch), (used + amount)), IntegerEntry(keyVote(pool, i.caller, epoch), newVote), IntegerEntry(keyVotingResult(pool, epoch), (poolResult + amount)), IntegerEntry(keyTotalVotes(epoch), (totalVotes + amount))] ++ votesListActions), unit) |
---|
| 400 | + | } |
---|
| 401 | + | else throw("Strict value is not equal to itself.") |
---|
| 402 | + | } |
---|
| 403 | + | |
---|
| 404 | + | |
---|
| 405 | + | |
---|
| 406 | + | @Callable(i) |
---|
| 407 | + | func cancelVote (amountAssetId,priceAssetId) = { |
---|
| 408 | + | let pool = $Tuple2(amountAssetId, priceAssetId) |
---|
| 409 | + | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
| 410 | + | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
| 411 | + | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
| 412 | + | let endHeight = (startHeight + epochLength) |
---|
| 413 | + | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
| 414 | + | let used = valueOrElse(getInteger(this, keyUsed(i.caller, epoch)), 0) |
---|
| 415 | + | let vote = valueOrElse(getInteger(this, keyVote(pool, i.caller, epoch)), 0) |
---|
| 416 | + | let poolResult = valueOrElse(getInteger(this, keyVotingResult(pool, epoch)), 0) |
---|
| 417 | + | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(epoch)), 0) |
---|
| 418 | + | let checks = [if ((getBoolean(keyInList(pool)) != unit)) |
---|
| 419 | + | then true |
---|
| 420 | + | else throwErr("invalid assets"), if ((endHeight > height)) |
---|
| 421 | + | then true |
---|
| 422 | + | else throwErr("invalid height"), if ((finalizationStageOrUnit == unit)) |
---|
| 423 | + | then true |
---|
| 424 | + | else throwErr("finalization in progress"), if ((vote > 0)) |
---|
| 425 | + | then true |
---|
| 426 | + | else throwErr("no vote")] |
---|
| 427 | + | if ((checks == checks)) |
---|
| 428 | + | then { |
---|
| 429 | + | let votesListName = getVotesListName(pool) |
---|
| 430 | + | let userAddressStr = toString(i.caller) |
---|
| 431 | + | $Tuple2(([IntegerEntry(keyUsed(i.caller, epoch), max([(used - vote), 0])), DeleteEntry(keyVote(pool, i.caller, epoch)), IntegerEntry(keyVotingResult(pool, epoch), (poolResult - vote)), IntegerEntry(keyTotalVotes(epoch), (totalVotes - vote))] ++ deleteNodeActions(votesListName, userAddressStr)), unit) |
---|
| 432 | + | } |
---|
| 433 | + | else throw("Strict value is not equal to itself.") |
---|
| 434 | + | } |
---|
| 435 | + | |
---|
| 436 | + | |
---|
| 437 | + | |
---|
| 438 | + | @Callable(i) |
---|
| 439 | + | func setEpochLength (newEpochLength) = { |
---|
| 440 | + | let checks = [mustManager(i), if ((newEpochLength > 0)) |
---|
| 441 | + | then true |
---|
| 442 | + | else throwErr("invalid epoch length")] |
---|
| 443 | + | if ((checks == checks)) |
---|
| 444 | + | then $Tuple2([IntegerEntry(keyEpochLengthNew, newEpochLength)], unit) |
---|
| 445 | + | else throw("Strict value is not equal to itself.") |
---|
| 446 | + | } |
---|
| 447 | + | |
---|
| 448 | + | |
---|
| 449 | + | |
---|
| 450 | + | @Callable(i) |
---|
| 451 | + | func setMaxDepth (newMaxDepth) = { |
---|
| 452 | + | let checks = [mustManager(i), if ((newMaxDepth > 0)) |
---|
| 453 | + | then true |
---|
| 454 | + | else throwErr("invalid max depth")] |
---|
| 455 | + | if ((checks == checks)) |
---|
| 456 | + | then $Tuple2([IntegerEntry(keyMaxDepth, newMaxDepth)], unit) |
---|
| 457 | + | else throw("Strict value is not equal to itself.") |
---|
| 458 | + | } |
---|
| 459 | + | |
---|
| 460 | + | |
---|
| 461 | + | |
---|
| 462 | + | @Callable(i) |
---|
| 463 | + | func processVoteINTERNAL (poolStr,userAddressStr) = { |
---|
| 464 | + | let checkCaller = mustThis(i) |
---|
| 465 | + | if ((checkCaller == checkCaller)) |
---|
| 466 | + | then { |
---|
| 467 | + | let userAddress = valueOrErrorMessage(addressFromString(userAddressStr), wrapErr(("processVoteINTERNAL: invalid user address " + userAddressStr))) |
---|
| 468 | + | let epoch = getIntOrFail(this, keyCurrentEpoch) |
---|
| 469 | + | let epochPrevious = (epoch - 1) |
---|
| 470 | + | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
| 471 | + | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
| 472 | + | let endHeight = (startHeight + epochLength) |
---|
| 473 | + | let startHeightPrevious = getIntOrFail(this, keyStartHeightByEpoch(epochPrevious)) |
---|
| 474 | + | let epochLengthPrevious = getIntOrFail(this, keyEpochLengthByEpoch(epochPrevious)) |
---|
| 475 | + | let endHeightPrevious = (startHeightPrevious + epochLengthPrevious) |
---|
| 476 | + | let checkTargetEpoch = if ((epochPrevious >= 0)) |
---|
| 477 | + | then true |
---|
| 478 | + | else throwErr("processVoteINTERNAL: invalid previous epoch") |
---|
| 479 | + | if ((checkTargetEpoch == checkTargetEpoch)) |
---|
| 480 | + | then { |
---|
| 481 | + | let pool = stringToPool(poolStr) |
---|
| 482 | + | let $t01748817528 = pool |
---|
| 483 | + | let amountAssetId = $t01748817528._1 |
---|
| 484 | + | let priceAssetId = $t01748817528._2 |
---|
| 485 | + | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
| 486 | + | let gwxAmountAtEndTotal = { |
---|
| 487 | + | let @ = invoke(this, "getUserGwxAmountAtHeight", [userAddressStr, endHeight], nil) |
---|
| 488 | + | if ($isInstanceOf(@, "Int")) |
---|
| 489 | + | then @ |
---|
| 490 | + | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
| 491 | + | } |
---|
| 492 | + | let gwxAmountAtEndTotalPrevious = { |
---|
| 493 | + | let @ = invoke(this, "getUserGwxAmountAtHeight", [userAddressStr, endHeightPrevious], nil) |
---|
| 494 | + | if ($isInstanceOf(@, "Int")) |
---|
| 495 | + | then @ |
---|
| 496 | + | else throw(($getType(@) + " couldn't be cast to Int")) |
---|
| 497 | + | } |
---|
| 498 | + | let totalVotes = valueOrElse(getInteger(keyTotalVotes(epoch)), 0) |
---|
| 499 | + | let votingResult = valueOrElse(getInteger(keyVotingResult(pool, epoch)), 0) |
---|
| 500 | + | let votePrevious = valueOrErrorMessage(getInteger(keyVote(pool, userAddress, epochPrevious)), wrapErr((((("processVoteINTERNAL " + poolStr) + " ") + userAddressStr) + ": no previous vote"))) |
---|
| 501 | + | let used = valueOrElse(getInteger(this, keyUsed(userAddress, epoch)), 0) |
---|
| 502 | + | let lpAssetIdStr = getLpAssetByPoolAssets(amountAssetId, priceAssetId) |
---|
| 503 | + | let votingResultStakedPrevious = valueOrElse(getInteger(keyVotingResultStaked(lpAssetIdStr, epochPrevious)), 0) |
---|
| 504 | + | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract)) |
---|
| 505 | + | let stakedByUser = valueOrElse(getInteger(stakingContract, keyStakedByUser(lpAssetIdStr, userAddressStr)), 0) |
---|
| 506 | + | let votingResultStakedActions = if ((stakedByUser == 0)) |
---|
| 507 | + | then nil |
---|
| 508 | + | else [IntegerEntry(keyVotingResultStaked(lpAssetIdStr, epochPrevious), (votingResultStakedPrevious + votePrevious))] |
---|
| 509 | + | let newVote = if ((gwxAmountAtEndTotalPrevious > 0)) |
---|
| 510 | + | then fraction(votePrevious, gwxAmountAtEndTotal, gwxAmountAtEndTotalPrevious) |
---|
| 511 | + | else 0 |
---|
| 512 | + | let actions = if (if ((newVote > 0)) |
---|
| 513 | + | then wxEmission |
---|
| 514 | + | else false) |
---|
| 515 | + | then [IntegerEntry(keyVote(pool, userAddress, epoch), newVote), IntegerEntry(keyTotalVotes(epoch), (totalVotes + newVote)), IntegerEntry(keyVotingResult(pool, epoch), (votingResult + newVote)), IntegerEntry(keyUsed(userAddress, epoch), (used + newVote))] |
---|
| 516 | + | else deleteNodeActions(getVotesListName(pool), userAddressStr) |
---|
| 517 | + | $Tuple2((actions ++ votingResultStakedActions), unit) |
---|
| 518 | + | } |
---|
| 519 | + | else throw("Strict value is not equal to itself.") |
---|
| 520 | + | } |
---|
| 521 | + | else throw("Strict value is not equal to itself.") |
---|
| 522 | + | } |
---|
| 523 | + | |
---|
| 524 | + | |
---|
| 525 | + | |
---|
| 526 | + | @Callable(i) |
---|
| 527 | + | func processPoolINTERNAL (poolStr,force) = { |
---|
| 528 | + | let checkCaller = mustThis(i) |
---|
| 529 | + | if ((checkCaller == checkCaller)) |
---|
| 530 | + | then { |
---|
| 531 | + | let targetEpoch = { |
---|
| 532 | + | let currentEpoch = getIntOrFail(this, keyCurrentEpoch) |
---|
| 533 | + | if (force) |
---|
| 534 | + | then currentEpoch |
---|
| 535 | + | else (currentEpoch - 1) |
---|
| 536 | + | } |
---|
| 537 | + | let checkTargetEpoch = if ((targetEpoch >= 0)) |
---|
| 538 | + | then true |
---|
| 539 | + | else throwErr("processPoolINTERNAL: invalid target epoch") |
---|
| 540 | + | if ((checkTargetEpoch == checkTargetEpoch)) |
---|
| 541 | + | then { |
---|
| 542 | + | let pool = stringToPool(poolStr) |
---|
| 543 | + | let $t01988519925 = pool |
---|
| 544 | + | let amountAssetId = $t01988519925._1 |
---|
| 545 | + | let priceAssetId = $t01988519925._2 |
---|
| 546 | + | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract)) |
---|
| 547 | + | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract)) |
---|
| 548 | + | let lpAssetId = getLpAssetByPoolAssets(amountAssetId, priceAssetId) |
---|
| 549 | + | let r = { |
---|
| 550 | + | let @ = invoke(stakingContract, "usersListTraversal", [lpAssetId], nil) |
---|
| 551 | + | if ($isInstanceOf(@, "Boolean")) |
---|
| 552 | + | then @ |
---|
| 553 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
| 554 | + | } |
---|
| 555 | + | if ((r == r)) |
---|
| 556 | + | then if (r) |
---|
| 557 | + | then $Tuple2(nil, true) |
---|
| 558 | + | else { |
---|
| 559 | + | let wxEmission = checkWxEmissionPoolLabel(pool) |
---|
| 560 | + | let totalVotes = valueOrElse(getInteger(this, keyTotalVotes(targetEpoch)), 0) |
---|
| 561 | + | let votingResult = valueOrElse(getInteger(this, keyVotingResult(pool, targetEpoch)), 0) |
---|
| 562 | + | let share = if (if ((totalVotes == 0)) |
---|
| 563 | + | then true |
---|
| 564 | + | else !(wxEmission)) |
---|
| 565 | + | then 0 |
---|
| 566 | + | else fraction(votingResult, poolWeightMult, totalVotes) |
---|
| 567 | + | let modifyWeightInv = invoke(factoryContract, "modifyWeight", [lpAssetId, share], nil) |
---|
| 568 | + | if ((modifyWeightInv == modifyWeightInv)) |
---|
| 569 | + | then { |
---|
| 570 | + | let poolsListActions = if (if (wxEmission) |
---|
| 571 | + | then true |
---|
| 572 | + | else force) |
---|
| 573 | + | then nil |
---|
| 574 | + | else ([DeleteEntry(keyInList(pool))] ++ deleteNodeActions(poolsListName, poolStr)) |
---|
| 575 | + | $Tuple2(([IntegerEntry(keyPoolShare(pool, targetEpoch), share)] ++ poolsListActions), false) |
---|
| 576 | + | } |
---|
| 577 | + | else throw("Strict value is not equal to itself.") |
---|
| 578 | + | } |
---|
| 579 | + | else throw("Strict value is not equal to itself.") |
---|
| 580 | + | } |
---|
| 581 | + | else throw("Strict value is not equal to itself.") |
---|
| 582 | + | } |
---|
| 583 | + | else throw("Strict value is not equal to itself.") |
---|
| 584 | + | } |
---|
| 585 | + | |
---|
| 586 | + | |
---|
| 587 | + | |
---|
| 588 | + | @Callable(i) |
---|
| 589 | + | func finalizeHelper () = { |
---|
| 590 | + | let force = valueOrElse(getBoolean(keyFinalizationShouldBeForced), false) |
---|
| 591 | + | let epoch = valueOrElse(getInteger(this, keyCurrentEpoch), 0) |
---|
| 592 | + | let previousEpoch = (epoch - 1) |
---|
| 593 | + | let startHeight = getIntOrFail(this, keyStartHeightByEpoch(epoch)) |
---|
| 594 | + | let epochLength = getIntOrFail(this, keyEpochLength) |
---|
| 595 | + | let endHeight = (startHeight + epochLength) |
---|
| 596 | + | let finalizationStageOrUnit = getInteger(this, keyFinalizationStage) |
---|
| 597 | + | if (if (if ((height >= endHeight)) |
---|
| 598 | + | then (finalizationStageOrUnit == unit) |
---|
| 599 | + | else false) |
---|
| 600 | + | then !(force) |
---|
| 601 | + | else false) |
---|
| 602 | + | then { |
---|
| 603 | + | let newEpoch = (epoch + 1) |
---|
| 604 | + | let newEpochLengthOption = getInteger(this, keyEpochLengthNew) |
---|
| 605 | + | let newEpochLengthActions = match newEpochLengthOption { |
---|
| 606 | + | case newEpochLength: Int => |
---|
| 607 | + | [IntegerEntry(keyEpochLength, newEpochLength), DeleteEntry(keyEpochLengthNew)] |
---|
| 608 | + | case _: Unit => |
---|
| 609 | + | nil |
---|
| 610 | + | case _ => |
---|
| 611 | + | throw("Match error") |
---|
| 612 | + | } |
---|
| 613 | + | $Tuple2(([IntegerEntry(keyStartHeightByEpoch(newEpoch), height), IntegerEntry(keyStartHeight, height), IntegerEntry(keyCurrentEpoch, newEpoch), IntegerEntry(keyFinalizationStage, finalizationStageTotal), IntegerEntry(keyEpochLengthByEpoch(epoch), epochLength)] ++ newEpochLengthActions), true) |
---|
| 614 | + | } |
---|
| 615 | + | else if (if (force) |
---|
| 616 | + | then (finalizationStageOrUnit == unit) |
---|
| 617 | + | else false) |
---|
| 618 | + | then $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares)], true) |
---|
| 619 | + | else if ((finalizationStageOrUnit == unit)) |
---|
| 620 | + | then $Tuple2(nil, false) |
---|
| 621 | + | else if ((finalizationStageOrUnit == finalizationStageTotal)) |
---|
| 622 | + | then { |
---|
| 623 | + | let poolOrUnit = getString(keyNextPool) |
---|
| 624 | + | let userOrUnit = getString(keyNextUser) |
---|
| 625 | + | match poolOrUnit { |
---|
| 626 | + | case _: Unit => |
---|
| 627 | + | match getString(keyListHead(poolsListName)) { |
---|
| 628 | + | case _: Unit => |
---|
| 629 | + | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
| 630 | + | case poolsHeadStr: String => |
---|
| 631 | + | $Tuple2([StringEntry(keyNextPool, poolsHeadStr)], true) |
---|
| 632 | + | case _ => |
---|
| 633 | + | throw("Match error") |
---|
| 634 | + | } |
---|
| 635 | + | case poolStr: String => |
---|
| 636 | + | let pool = stringToPool(poolStr) |
---|
| 637 | + | let nextUserOrUnit = match userOrUnit { |
---|
| 638 | + | case _: Unit => |
---|
| 639 | + | getString(keyListHead(getVotesListName(pool))) |
---|
| 640 | + | case user: String => |
---|
| 641 | + | let next = getString(keyListNext(getVotesListName(pool), user)) |
---|
| 642 | + | if ((next == next)) |
---|
| 643 | + | then { |
---|
| 644 | + | let processVoteInv = invoke(this, "processVoteINTERNAL", [poolStr, user], nil) |
---|
| 645 | + | if ((processVoteInv == processVoteInv)) |
---|
| 646 | + | then next |
---|
| 647 | + | else throw("Strict value is not equal to itself.") |
---|
| 648 | + | } |
---|
| 649 | + | else throw("Strict value is not equal to itself.") |
---|
| 650 | + | case _ => |
---|
| 651 | + | throw("Match error") |
---|
| 652 | + | } |
---|
| 653 | + | match nextUserOrUnit { |
---|
| 654 | + | case _: Unit => |
---|
| 655 | + | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
| 656 | + | match nextPoolOrUnit { |
---|
| 657 | + | case _: Unit => |
---|
| 658 | + | $Tuple2([IntegerEntry(keyFinalizationStage, finalizationStageShares), DeleteEntry(keyNextPool), DeleteEntry(keyNextUser)], true) |
---|
| 659 | + | case s: String => |
---|
| 660 | + | $Tuple2([StringEntry(keyNextPool, s), DeleteEntry(keyNextUser)], true) |
---|
| 661 | + | case _ => |
---|
| 662 | + | throw("Match error") |
---|
| 663 | + | } |
---|
| 664 | + | case nextUser: String => |
---|
| 665 | + | $Tuple2([StringEntry(keyNextUser, nextUser)], true) |
---|
| 666 | + | case _ => |
---|
| 667 | + | throw("Match error") |
---|
| 668 | + | } |
---|
| 669 | + | case _ => |
---|
| 670 | + | throw("Match error") |
---|
| 671 | + | } |
---|
| 672 | + | } |
---|
| 673 | + | else if ((finalizationStageOrUnit == finalizationStageShares)) |
---|
| 674 | + | then { |
---|
| 675 | + | let poolOrUnit = getString(keyNextPool) |
---|
| 676 | + | match poolOrUnit { |
---|
| 677 | + | case _: Unit => |
---|
| 678 | + | match getString(keyListHead(poolsListName)) { |
---|
| 679 | + | case _: Unit => |
---|
| 680 | + | let actions = if (force) |
---|
| 681 | + | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced)] |
---|
| 682 | + | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight)] |
---|
| 683 | + | $Tuple2(actions, true) |
---|
| 684 | + | case nextPoolStr: String => |
---|
| 685 | + | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
| 686 | + | case _ => |
---|
| 687 | + | throw("Match error") |
---|
| 688 | + | } |
---|
| 689 | + | case poolStr: String => |
---|
| 690 | + | let nextPoolOrUnit = getString(keyListNext(poolsListName, poolStr)) |
---|
| 691 | + | if ((nextPoolOrUnit == nextPoolOrUnit)) |
---|
| 692 | + | then { |
---|
| 693 | + | let r = { |
---|
| 694 | + | let @ = invoke(this, "processPoolINTERNAL", [poolStr, force], nil) |
---|
| 695 | + | if ($isInstanceOf(@, "Boolean")) |
---|
| 696 | + | then @ |
---|
| 697 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
| 698 | + | } |
---|
| 699 | + | if ((r == r)) |
---|
| 700 | + | then if (r) |
---|
| 701 | + | then $Tuple2(nil, true) |
---|
| 702 | + | else match nextPoolOrUnit { |
---|
| 703 | + | case _: Unit => |
---|
| 704 | + | let actions = if (force) |
---|
| 705 | + | then [DeleteEntry(keyFinalizationStage), DeleteEntry(keyFinalizationShouldBeForced), DeleteEntry(keyNextPool)] |
---|
| 706 | + | else [DeleteEntry(keyFinalizationStage), BooleanEntry(keyFinalized(previousEpoch), true), IntegerEntry(keyCurrentEpochUi, epoch), IntegerEntry(keyStartHeightUi, startHeight), DeleteEntry(keyNextPool)] |
---|
| 707 | + | $Tuple2(actions, true) |
---|
| 708 | + | case nextPoolStr: String => |
---|
| 709 | + | $Tuple2([StringEntry(keyNextPool, nextPoolStr)], true) |
---|
| 710 | + | case _ => |
---|
| 711 | + | throw("Match error") |
---|
| 712 | + | } |
---|
| 713 | + | else throw("Strict value is not equal to itself.") |
---|
| 714 | + | } |
---|
| 715 | + | else throw("Strict value is not equal to itself.") |
---|
| 716 | + | case _ => |
---|
| 717 | + | throw("Match error") |
---|
| 718 | + | } |
---|
| 719 | + | } |
---|
| 720 | + | else throwErr("finalization is broken") |
---|
| 721 | + | } |
---|
| 722 | + | |
---|
| 723 | + | |
---|
| 724 | + | |
---|
| 725 | + | @Callable(i) |
---|
| 726 | + | func finalizeWrapper (counter) = { |
---|
| 727 | + | let result = { |
---|
| 728 | + | let @ = invoke(this, "finalizeHelper", nil, nil) |
---|
| 729 | + | if ($isInstanceOf(@, "Boolean")) |
---|
| 730 | + | then @ |
---|
| 731 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) |
---|
| 732 | + | } |
---|
| 733 | + | if ((result == result)) |
---|
| 734 | + | then if (!(result)) |
---|
| 735 | + | then if ((counter == 0)) |
---|
| 736 | + | then throwErr("Current voting is not over yet") |
---|
| 737 | + | else $Tuple2(nil, unit) |
---|
| 738 | + | else { |
---|
| 739 | + | let maxDepth = valueOrElse(getInteger(this, keyMaxDepth), maxDepthDefault) |
---|
| 740 | + | if ((maxDepth > counter)) |
---|
| 741 | + | then { |
---|
| 742 | + | let inv = invoke(this, "finalizeWrapper", [(counter + 1)], nil) |
---|
| 743 | + | if ((inv == inv)) |
---|
| 744 | + | then $Tuple2(nil, unit) |
---|
| 745 | + | else throw("Strict value is not equal to itself.") |
---|
| 746 | + | } |
---|
| 747 | + | else $Tuple2(nil, unit) |
---|
| 748 | + | } |
---|
| 749 | + | else throw("Strict value is not equal to itself.") |
---|
| 750 | + | } |
---|
| 751 | + | |
---|
| 752 | + | |
---|
| 753 | + | |
---|
| 754 | + | @Callable(i) |
---|
| 755 | + | func finalize () = { |
---|
| 756 | + | let inv = invoke(this, "finalizeWrapper", [0], nil) |
---|
| 757 | + | if ((inv == inv)) |
---|
| 758 | + | then $Tuple2(nil, unit) |
---|
| 759 | + | else throw("Strict value is not equal to itself.") |
---|
| 760 | + | } |
---|
| 761 | + | |
---|
| 762 | + | |
---|
| 763 | + | |
---|
| 764 | + | @Callable(i) |
---|
| 765 | + | func containsNodeREADONLY (listName,id) = $Tuple2(nil, containsNode(listName, id)) |
---|
| 766 | + | |
---|
| 767 | + | |
---|
| 768 | + | |
---|
| 769 | + | @Callable(i) |
---|
| 770 | + | func insertNode (listName,id) = { |
---|
| 771 | + | let checkCaller = mustManager(i) |
---|
| 772 | + | if ((checkCaller == checkCaller)) |
---|
| 773 | + | then $Tuple2(insertNodeActions(listName, id), unit) |
---|
| 774 | + | else throw("Strict value is not equal to itself.") |
---|
| 775 | + | } |
---|
| 776 | + | |
---|
| 777 | + | |
---|
| 778 | + | |
---|
| 779 | + | @Callable(i) |
---|
| 780 | + | func deleteNode (listName,id) = { |
---|
| 781 | + | let checkCaller = mustManager(i) |
---|
| 782 | + | if ((checkCaller == checkCaller)) |
---|
| 783 | + | then $Tuple2(deleteNodeActions(listName, id), unit) |
---|
| 784 | + | else throw("Strict value is not equal to itself.") |
---|
| 785 | + | } |
---|
| 786 | + | |
---|
| 787 | + | |
---|
| 788 | + | @Verifier(tx) |
---|
| 789 | + | func verify () = { |
---|
| 790 | + | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
| 791 | + | case pk: ByteVector => |
---|
| 792 | + | pk |
---|
| 793 | + | case _: Unit => |
---|
| 794 | + | tx.senderPublicKey |
---|
| 795 | + | case _ => |
---|
| 796 | + | throw("Match error") |
---|
| 797 | + | } |
---|
| 798 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
| 799 | + | } |
---|
| 800 | + | |
---|