1 | | - | # no script |
---|
| 1 | + | {-# STDLIB_VERSION 6 #-} |
---|
| 2 | + | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
| 3 | + | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | let SEP = "__" |
---|
| 5 | + | |
---|
| 6 | + | let PRECISION = 1000000000000 |
---|
| 7 | + | |
---|
| 8 | + | let ENABLED = "ENABLED" |
---|
| 9 | + | |
---|
| 10 | + | let DISABLED = "DISABLED" |
---|
| 11 | + | |
---|
| 12 | + | func divp (_x,_y) = fraction(_x, PRECISION, _y, HALFEVEN) |
---|
| 13 | + | |
---|
| 14 | + | |
---|
| 15 | + | func mulp (_x,_y) = fraction(_x, _y, PRECISION, HALFEVEN) |
---|
| 16 | + | |
---|
| 17 | + | |
---|
| 18 | + | func conv6to8 (_v) = (_v * 100) |
---|
| 19 | + | |
---|
| 20 | + | |
---|
| 21 | + | func conv8to6 (_v) = (_v / 100) |
---|
| 22 | + | |
---|
| 23 | + | |
---|
| 24 | + | func join (ar) = makeString(ar, SEP) |
---|
| 25 | + | |
---|
| 26 | + | |
---|
| 27 | + | func keyInitialized () = join(["%s", "initialized"]) |
---|
| 28 | + | |
---|
| 29 | + | |
---|
| 30 | + | func keyCoordinatorAddress () = join(["%s", "coordinatorAddress"]) |
---|
| 31 | + | |
---|
| 32 | + | |
---|
| 33 | + | func keyVerifierAddress () = join(["%s", "verifierAddress"]) |
---|
| 34 | + | |
---|
| 35 | + | |
---|
| 36 | + | func keyEastAsset () = join(["%s", "eastAsset"]) |
---|
| 37 | + | |
---|
| 38 | + | |
---|
| 39 | + | func keySigned (_address,_txId) = join(["%s%s%s", "signed", _address, _txId]) |
---|
| 40 | + | |
---|
| 41 | + | |
---|
| 42 | + | func keyProtocolActive () = join(["%s", "protocolActive"]) |
---|
| 43 | + | |
---|
| 44 | + | |
---|
| 45 | + | func isInitialized () = valueOrElse(getBoolean(this, keyInitialized()), false) |
---|
| 46 | + | |
---|
| 47 | + | |
---|
| 48 | + | func mustInitialized () = if (!(isInitialized())) |
---|
| 49 | + | then throw("Not initialized") |
---|
| 50 | + | else unit |
---|
| 51 | + | |
---|
| 52 | + | |
---|
| 53 | + | func mustNotInitialized () = if (isInitialized()) |
---|
| 54 | + | then throw("Already initialized") |
---|
| 55 | + | else unit |
---|
| 56 | + | |
---|
| 57 | + | |
---|
| 58 | + | func mustSelf (i) = if ((i.caller != this)) |
---|
| 59 | + | then throw("Only self invocation allowed.") |
---|
| 60 | + | else unit |
---|
| 61 | + | |
---|
| 62 | + | |
---|
| 63 | + | func coordinator () = addressFromStringValue(valueOrErrorMessage(getString(keyCoordinatorAddress()), "Coordinator is not set")) |
---|
| 64 | + | |
---|
| 65 | + | |
---|
| 66 | + | func verifier () = match getString(keyCoordinatorAddress()) { |
---|
| 67 | + | case s: String => |
---|
| 68 | + | getString(addressFromStringValue(s), keyVerifierAddress()) |
---|
| 69 | + | case _: Unit => |
---|
| 70 | + | unit |
---|
| 71 | + | case _ => |
---|
| 72 | + | throw("Match error") |
---|
| 73 | + | } |
---|
| 74 | + | |
---|
| 75 | + | |
---|
| 76 | + | func getEastAssetStr () = valueOrErrorMessage(getString(coordinator(), keyEastAsset()), "East asset is not set") |
---|
| 77 | + | |
---|
| 78 | + | |
---|
| 79 | + | func getEastAsset () = fromBase58String(getEastAssetStr()) |
---|
| 80 | + | |
---|
| 81 | + | |
---|
| 82 | + | func isActive () = valueOrElse(getBoolean(coordinator(), keyProtocolActive()), false) |
---|
| 83 | + | |
---|
| 84 | + | |
---|
| 85 | + | func mustActive () = if (if (!(isActive())) |
---|
| 86 | + | then true |
---|
| 87 | + | else !(isInitialized())) |
---|
| 88 | + | then throw("Protocol is disabled. Please contact support.") |
---|
| 89 | + | else unit |
---|
| 90 | + | |
---|
| 91 | + | |
---|
| 92 | + | func hasOnePayment (i) = (size(i.payments) == 1) |
---|
| 93 | + | |
---|
| 94 | + | |
---|
| 95 | + | func getAssetIdFromString (assetId) = if ((assetId == "WAVES")) |
---|
| 96 | + | then unit |
---|
| 97 | + | else fromBase58String(assetId) |
---|
| 98 | + | |
---|
| 99 | + | |
---|
| 100 | + | func isAsset (p,checkingAsset) = { |
---|
| 101 | + | let assetId = match checkingAsset { |
---|
| 102 | + | case bv: ByteVector => |
---|
| 103 | + | bv |
---|
| 104 | + | case s: String => |
---|
| 105 | + | getAssetIdFromString(s) |
---|
| 106 | + | case _: Unit => |
---|
| 107 | + | unit |
---|
| 108 | + | case _ => |
---|
| 109 | + | throw("Match error") |
---|
| 110 | + | } |
---|
| 111 | + | match assetId { |
---|
| 112 | + | case bv: ByteVector => |
---|
| 113 | + | let name = match assetInfo(bv) { |
---|
| 114 | + | case asset: Asset => |
---|
| 115 | + | asset.name |
---|
| 116 | + | case _: Unit => |
---|
| 117 | + | throw(("Can't find asset " + toBase58String(bv))) |
---|
| 118 | + | case _ => |
---|
| 119 | + | throw("Match error") |
---|
| 120 | + | } |
---|
| 121 | + | let err = throw(("Attached payment asset is not " + name)) |
---|
| 122 | + | match p.assetId { |
---|
| 123 | + | case paymentAsset: ByteVector => |
---|
| 124 | + | if ((paymentAsset != assetId)) |
---|
| 125 | + | then err |
---|
| 126 | + | else unit |
---|
| 127 | + | case _: Unit => |
---|
| 128 | + | err |
---|
| 129 | + | case _ => |
---|
| 130 | + | throw("Match error") |
---|
| 131 | + | } |
---|
| 132 | + | case _: Unit => |
---|
| 133 | + | if ((p.assetId != unit)) |
---|
| 134 | + | then throw("Attached payment asset is not WAVES") |
---|
| 135 | + | else unit |
---|
| 136 | + | case _ => |
---|
| 137 | + | throw("Match error") |
---|
| 138 | + | } |
---|
| 139 | + | } |
---|
| 140 | + | |
---|
| 141 | + | |
---|
| 142 | + | func checkAddress (_address) = match addressFromString(_address) { |
---|
| 143 | + | case address: Address => |
---|
| 144 | + | true |
---|
| 145 | + | case _: Unit => |
---|
| 146 | + | throw("Invalid address") |
---|
| 147 | + | case _ => |
---|
| 148 | + | throw("Match error") |
---|
| 149 | + | } |
---|
| 150 | + | |
---|
| 151 | + | |
---|
| 152 | + | func getCurrentTimestampSec () = (lastBlock.timestamp / 1000) |
---|
| 153 | + | |
---|
| 154 | + | |
---|
| 155 | + | func keyBalance () = join(["%s", "balance"]) |
---|
| 156 | + | |
---|
| 157 | + | |
---|
| 158 | + | func keyRate () = join(["%s", "rate"]) |
---|
| 159 | + | |
---|
| 160 | + | |
---|
| 161 | + | func keyStEast () = join(["%s", "stEast"]) |
---|
| 162 | + | |
---|
| 163 | + | |
---|
| 164 | + | func getStEast () = fromBase58String(getStringValue(this, keyStEast())) |
---|
| 165 | + | |
---|
| 166 | + | |
---|
| 167 | + | func getBalance () = valueOrElse(getInteger(keyBalance()), 0) |
---|
| 168 | + | |
---|
| 169 | + | |
---|
| 170 | + | func getRate () = getIntegerValue(keyRate()) |
---|
| 171 | + | |
---|
| 172 | + | |
---|
| 173 | + | let IdxAssetPoolStatus = 1 |
---|
| 174 | + | |
---|
| 175 | + | let IdxAssetPoolContractId = 2 |
---|
| 176 | + | |
---|
| 177 | + | let IdxBalancesLastEastBalance = 1 |
---|
| 178 | + | |
---|
| 179 | + | let IdxBalancesLastTimestamp = 2 |
---|
| 180 | + | |
---|
| 181 | + | let IdxBalancesLastStEastBalance = 3 |
---|
| 182 | + | |
---|
| 183 | + | func keyAssetsInPools () = join(["%s", "assetsInPools"]) |
---|
| 184 | + | |
---|
| 185 | + | |
---|
| 186 | + | func keyAssetPool (_assetId) = join(["%s%s", "assetPool", _assetId]) |
---|
| 187 | + | |
---|
| 188 | + | |
---|
| 189 | + | func keyAssetPoolBalances (_assetStr) = join(["%s%s", "assetPoolBalances", _assetStr]) |
---|
| 190 | + | |
---|
| 191 | + | |
---|
| 192 | + | func getAssetsInPools () = match getString(this, keyAssetsInPools()) { |
---|
| 193 | + | case s: String => |
---|
| 194 | + | split(s, SEP) |
---|
| 195 | + | case _: Unit => |
---|
| 196 | + | nil |
---|
| 197 | + | case _ => |
---|
| 198 | + | throw("Match error") |
---|
| 199 | + | } |
---|
| 200 | + | |
---|
| 201 | + | |
---|
| 202 | + | func getAssetPool (_assetId) = { |
---|
| 203 | + | let poolArr = split(getStringValue(this, keyAssetPool(_assetId)), SEP) |
---|
| 204 | + | let pool = poolArr[IdxAssetPoolContractId] |
---|
| 205 | + | pool |
---|
| 206 | + | } |
---|
| 207 | + | |
---|
| 208 | + | |
---|
| 209 | + | func getEastBalance (_address) = { |
---|
| 210 | + | let eastAsset = getEastAsset() |
---|
| 211 | + | let address = addressFromStringValue(_address) |
---|
| 212 | + | let balance = assetBalance(address, eastAsset) |
---|
| 213 | + | balance |
---|
| 214 | + | } |
---|
| 215 | + | |
---|
| 216 | + | |
---|
| 217 | + | func getCurrentPoolEastBalance (_assetId) = { |
---|
| 218 | + | let pool = getAssetPool(_assetId) |
---|
| 219 | + | let balance = getEastBalance(pool) |
---|
| 220 | + | balance |
---|
| 221 | + | } |
---|
| 222 | + | |
---|
| 223 | + | |
---|
| 224 | + | func isPoolEnabled (_assetStr) = { |
---|
| 225 | + | let poolCfg = getStringValue(keyAssetPool(_assetStr)) |
---|
| 226 | + | let poolArr = split(poolCfg, SEP) |
---|
| 227 | + | if ((poolArr[IdxAssetPoolStatus] != ENABLED)) |
---|
| 228 | + | then throw((("Asset " + _assetStr) + " is not enabled")) |
---|
| 229 | + | else unit |
---|
| 230 | + | } |
---|
| 231 | + | |
---|
| 232 | + | |
---|
| 233 | + | func assetExist (_assetStr) = match getString(keyAssetPool(_assetStr)) { |
---|
| 234 | + | case s: String => |
---|
| 235 | + | true |
---|
| 236 | + | case _: Unit => |
---|
| 237 | + | false |
---|
| 238 | + | case _ => |
---|
| 239 | + | throw("Match error") |
---|
| 240 | + | } |
---|
| 241 | + | |
---|
| 242 | + | |
---|
| 243 | + | func dataAssetPool (_status,_poolStr) = join(["%s%s", _status, _poolStr]) |
---|
| 244 | + | |
---|
| 245 | + | |
---|
| 246 | + | func getAssetPoolBalances (_assetStr) = { |
---|
| 247 | + | let balancesArr = match getString(keyAssetPoolBalances(_assetStr)) { |
---|
| 248 | + | case s: String => |
---|
| 249 | + | split(s, SEP) |
---|
| 250 | + | case _: Unit => |
---|
| 251 | + | ["%d%d%d", "0", toString(getCurrentTimestampSec()), "0"] |
---|
| 252 | + | case _ => |
---|
| 253 | + | throw("Match error") |
---|
| 254 | + | } |
---|
| 255 | + | let lastEastBalance = parseIntValue(balancesArr[IdxBalancesLastEastBalance]) |
---|
| 256 | + | let lastTimestamp = parseIntValue(balancesArr[IdxBalancesLastTimestamp]) |
---|
| 257 | + | let lastStEastBalance = parseIntValue(balancesArr[IdxBalancesLastStEastBalance]) |
---|
| 258 | + | $Tuple3(lastEastBalance, lastTimestamp, lastStEastBalance) |
---|
| 259 | + | } |
---|
| 260 | + | |
---|
| 261 | + | |
---|
| 262 | + | func updateAssetPoolBalances (_currentPoolEastBalance,_newStEastBalanceForPool) = makeString(["%d%d%d", toString(_currentPoolEastBalance), toString(getCurrentTimestampSec()), toString(_newStEastBalanceForPool)], SEP) |
---|
| 263 | + | |
---|
| 264 | + | |
---|
| 265 | + | func updateBalance (_amount) = { |
---|
| 266 | + | let balance = (getBalance() + _amount) |
---|
| 267 | + | [IntegerEntry(keyBalance(), balance)] |
---|
| 268 | + | } |
---|
| 269 | + | |
---|
| 270 | + | |
---|
| 271 | + | func updateRate (_rate) = [IntegerEntry(keyRate(), _rate)] |
---|
| 272 | + | |
---|
| 273 | + | |
---|
| 274 | + | func issueStEast (_amount) = { |
---|
| 275 | + | let stEast = getStEast() |
---|
| 276 | + | [Reissue(stEast, _amount, true)] |
---|
| 277 | + | } |
---|
| 278 | + | |
---|
| 279 | + | |
---|
| 280 | + | func burnStEast (_amount) = { |
---|
| 281 | + | let stEast = getStEast() |
---|
| 282 | + | [Burn(stEast, _amount)] |
---|
| 283 | + | } |
---|
| 284 | + | |
---|
| 285 | + | |
---|
| 286 | + | func sendStEast (_recipient,_amount) = { |
---|
| 287 | + | let stEast = getStEast() |
---|
| 288 | + | [ScriptTransfer(_recipient, _amount, stEast)] |
---|
| 289 | + | } |
---|
| 290 | + | |
---|
| 291 | + | |
---|
| 292 | + | func sendEast (_recipient,_amount) = { |
---|
| 293 | + | let eastAsset = getEastAsset() |
---|
| 294 | + | [ScriptTransfer(_recipient, _amount, eastAsset)] |
---|
| 295 | + | } |
---|
| 296 | + | |
---|
| 297 | + | |
---|
| 298 | + | func stEastQuantity () = { |
---|
| 299 | + | let stEast = getStEast() |
---|
| 300 | + | match assetInfo(stEast) { |
---|
| 301 | + | case asset: Asset => |
---|
| 302 | + | asset.quantity |
---|
| 303 | + | case _ => |
---|
| 304 | + | throw("Can't find stEAST asset") |
---|
| 305 | + | } |
---|
| 306 | + | } |
---|
| 307 | + | |
---|
| 308 | + | |
---|
| 309 | + | @Callable(i) |
---|
| 310 | + | func initialize (_coordinatorAddress) = { |
---|
| 311 | + | let checks = [mustSelf(i), mustNotInitialized(), checkAddress(_coordinatorAddress)] |
---|
| 312 | + | if ((checks == checks)) |
---|
| 313 | + | then { |
---|
| 314 | + | let stEast = Issue("stEAST", "", 0, 8, true, unit, 0) |
---|
| 315 | + | let stEastId = calculateAssetId(stEast) |
---|
| 316 | + | [BooleanEntry(keyInitialized(), true), StringEntry(keyCoordinatorAddress(), _coordinatorAddress), StringEntry(keyStEast(), toBase58String(stEastId)), IntegerEntry(keyRate(), PRECISION), stEast] |
---|
| 317 | + | } |
---|
| 318 | + | else throw("Strict value is not equal to itself.") |
---|
| 319 | + | } |
---|
| 320 | + | |
---|
| 321 | + | |
---|
| 322 | + | |
---|
| 323 | + | @Callable(i) |
---|
| 324 | + | func updateLpPoolBalances () = { |
---|
| 325 | + | let checks = [mustInitialized(), mustSelf(i)] |
---|
| 326 | + | if ((checks == checks)) |
---|
| 327 | + | then { |
---|
| 328 | + | let rate = getRate() |
---|
| 329 | + | let stAssetAmountBefore = stEastQuantity() |
---|
| 330 | + | func updateBalances (acc,next) = match next { |
---|
| 331 | + | case asset: String => |
---|
| 332 | + | let check = [isPoolEnabled(asset)] |
---|
| 333 | + | if ((check == check)) |
---|
| 334 | + | then { |
---|
| 335 | + | let currentPoolEastBalance = getCurrentPoolEastBalance(asset) |
---|
| 336 | + | let $t01580115913 = { |
---|
| 337 | + | let @ = getAssetPoolBalances(asset) |
---|
| 338 | + | if ($isInstanceOf(@, "(Int, Int, Int)")) |
---|
| 339 | + | then @ |
---|
| 340 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int, Int)")) |
---|
| 341 | + | } |
---|
| 342 | + | let oldPoolEastBalance = $t01580115913._1 |
---|
| 343 | + | let lastTimestamp = $t01580115913._2 |
---|
| 344 | + | let oldStEastBalance = $t01580115913._3 |
---|
| 345 | + | let poolBalanceDiff = (currentPoolEastBalance - oldPoolEastBalance) |
---|
| 346 | + | let stAssetDiff = conv6to8(divp(poolBalanceDiff, rate)) |
---|
| 347 | + | let newStEastBalanceForPool = (oldStEastBalance + stAssetDiff) |
---|
| 348 | + | let actions = [StringEntry(keyAssetPoolBalances(asset), updateAssetPoolBalances(currentPoolEastBalance, newStEastBalanceForPool))] |
---|
| 349 | + | $Tuple3((acc._1 ++ actions), (acc._2 + stAssetDiff), (acc._3 + poolBalanceDiff)) |
---|
| 350 | + | } |
---|
| 351 | + | else throw("Strict value is not equal to itself.") |
---|
| 352 | + | case _: Unit => |
---|
| 353 | + | acc |
---|
| 354 | + | case _ => |
---|
| 355 | + | throw("Match error") |
---|
| 356 | + | } |
---|
| 357 | + | |
---|
| 358 | + | let assets = getAssetsInPools() |
---|
| 359 | + | let $t01649416685 = if ((1 > size(assets))) |
---|
| 360 | + | then $Tuple3(nil, 0, 0) |
---|
| 361 | + | else { |
---|
| 362 | + | let $l = assets |
---|
| 363 | + | let $s = size($l) |
---|
| 364 | + | let $acc0 = $Tuple3(nil, 0, 0) |
---|
| 365 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 366 | + | then $a |
---|
| 367 | + | else updateBalances($a, $l[$i]) |
---|
| 368 | + | |
---|
| 369 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 370 | + | then $a |
---|
| 371 | + | else throw("List size exceeds 10") |
---|
| 372 | + | |
---|
| 373 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
| 374 | + | } |
---|
| 375 | + | let poolAssetBalancesActions = $t01649416685._1 |
---|
| 376 | + | let totalStEastAmountChange = $t01649416685._2 |
---|
| 377 | + | let totalEastBalancesChange = $t01649416685._3 |
---|
| 378 | + | let stEast = getStEast() |
---|
| 379 | + | let stEastOp = if ((totalStEastAmountChange > 0)) |
---|
| 380 | + | then issueStEast(totalStEastAmountChange) |
---|
| 381 | + | else burnStEast((totalStEastAmountChange * -1)) |
---|
| 382 | + | let updatedBalance = updateBalance(totalEastBalancesChange) |
---|
| 383 | + | ((poolAssetBalancesActions ++ stEastOp) ++ updatedBalance) |
---|
| 384 | + | } |
---|
| 385 | + | else throw("Strict value is not equal to itself.") |
---|
| 386 | + | } |
---|
| 387 | + | |
---|
| 388 | + | |
---|
| 389 | + | |
---|
| 390 | + | @Callable(i) |
---|
| 391 | + | func stake () = { |
---|
| 392 | + | let payment = i.payments[0] |
---|
| 393 | + | let eastAsset = getEastAsset() |
---|
| 394 | + | let checks = [mustActive(), hasOnePayment(i), isAsset(payment, eastAsset)] |
---|
| 395 | + | if ((checks == checks)) |
---|
| 396 | + | then { |
---|
| 397 | + | let doUpdatePoolBalances = invoke(this, "updateLpPoolBalances", nil, nil) |
---|
| 398 | + | if ((doUpdatePoolBalances == doUpdatePoolBalances)) |
---|
| 399 | + | then { |
---|
| 400 | + | let rate = getRate() |
---|
| 401 | + | let mainAssetAmount = conv6to8(payment.amount) |
---|
| 402 | + | let toReissue = divp(mainAssetAmount, rate) |
---|
| 403 | + | $Tuple2(((updateBalance(payment.amount) ++ issueStEast(toReissue)) ++ sendStEast(i.caller, toReissue)), toReissue) |
---|
| 404 | + | } |
---|
| 405 | + | else throw("Strict value is not equal to itself.") |
---|
| 406 | + | } |
---|
| 407 | + | else throw("Strict value is not equal to itself.") |
---|
| 408 | + | } |
---|
| 409 | + | |
---|
| 410 | + | |
---|
| 411 | + | |
---|
| 412 | + | @Callable(i) |
---|
| 413 | + | func unstake () = { |
---|
| 414 | + | let payment = i.payments[0] |
---|
| 415 | + | let stEast = getStEast() |
---|
| 416 | + | let checks = [mustActive(), hasOnePayment(i), isAsset(payment, stEast)] |
---|
| 417 | + | if ((checks == checks)) |
---|
| 418 | + | then { |
---|
| 419 | + | let doUpdatePoolBalances = invoke(this, "updateLpPoolBalances", nil, nil) |
---|
| 420 | + | if ((doUpdatePoolBalances == doUpdatePoolBalances)) |
---|
| 421 | + | then { |
---|
| 422 | + | let rate = getRate() |
---|
| 423 | + | let transferAmount = conv8to6(mulp(payment.amount, rate)) |
---|
| 424 | + | ((updateBalance(-(transferAmount)) ++ burnStEast(payment.amount)) ++ sendEast(i.caller, transferAmount)) |
---|
| 425 | + | } |
---|
| 426 | + | else throw("Strict value is not equal to itself.") |
---|
| 427 | + | } |
---|
| 428 | + | else throw("Strict value is not equal to itself.") |
---|
| 429 | + | } |
---|
| 430 | + | |
---|
| 431 | + | |
---|
| 432 | + | |
---|
| 433 | + | @Callable(i) |
---|
| 434 | + | func addStakingRewards () = { |
---|
| 435 | + | let payment = i.payments[0] |
---|
| 436 | + | let eastAsset = getEastAsset() |
---|
| 437 | + | let checks = [mustActive(), hasOnePayment(i), isAsset(payment, eastAsset)] |
---|
| 438 | + | if ((checks == checks)) |
---|
| 439 | + | then { |
---|
| 440 | + | let doUpdatePoolBalances = invoke(this, "updateLpPoolBalances", nil, nil) |
---|
| 441 | + | if ((doUpdatePoolBalances == doUpdatePoolBalances)) |
---|
| 442 | + | then { |
---|
| 443 | + | let balance = getBalance() |
---|
| 444 | + | let newEastAmount = conv6to8((balance + payment.amount)) |
---|
| 445 | + | let stEastSupply = stEastQuantity() |
---|
| 446 | + | let newRate = divp(newEastAmount, stEastSupply) |
---|
| 447 | + | (updateBalance(payment.amount) ++ updateRate(newRate)) |
---|
| 448 | + | } |
---|
| 449 | + | else throw("Strict value is not equal to itself.") |
---|
| 450 | + | } |
---|
| 451 | + | else throw("Strict value is not equal to itself.") |
---|
| 452 | + | } |
---|
| 453 | + | |
---|
| 454 | + | |
---|
| 455 | + | |
---|
| 456 | + | @Callable(i) |
---|
| 457 | + | func addAssetPool (_poolStr,_assetStr) = { |
---|
| 458 | + | let checks = [mustInitialized(), mustSelf(i)] |
---|
| 459 | + | if ((checks == checks)) |
---|
| 460 | + | then if (!(checkAddress(_poolStr))) |
---|
| 461 | + | then throw("Address is not valid") |
---|
| 462 | + | else if (assetExist(_assetStr)) |
---|
| 463 | + | then throw("Asset is already set") |
---|
| 464 | + | else { |
---|
| 465 | + | let assetsInPools = makeString((getAssetsInPools() ++ [_assetStr]), SEP) |
---|
| 466 | + | [StringEntry(keyAssetPool(_assetStr), dataAssetPool(ENABLED, _poolStr)), StringEntry(keyAssetsInPools(), assetsInPools)] |
---|
| 467 | + | } |
---|
| 468 | + | else throw("Strict value is not equal to itself.") |
---|
| 469 | + | } |
---|
| 470 | + | |
---|
| 471 | + | |
---|
| 472 | + | |
---|
| 473 | + | @Callable(i) |
---|
| 474 | + | func disableAssetPool (_assetStr) = { |
---|
| 475 | + | let check = [mustInitialized(), mustSelf(i)] |
---|
| 476 | + | if ((check == check)) |
---|
| 477 | + | then { |
---|
| 478 | + | let poolData = split(valueOrErrorMessage(getString(keyAssetPool(_assetStr)), "Unknown asset"), SEP) |
---|
| 479 | + | [StringEntry(keyAssetPool(_assetStr), dataAssetPool(DISABLED, poolData[IdxAssetPoolContractId]))] |
---|
| 480 | + | } |
---|
| 481 | + | else throw("Strict value is not equal to itself.") |
---|
| 482 | + | } |
---|
| 483 | + | |
---|
| 484 | + | |
---|
| 485 | + | |
---|
| 486 | + | @Callable(i) |
---|
| 487 | + | func enableAssetPool (_assetStr) = { |
---|
| 488 | + | let check = [mustInitialized(), mustSelf(i)] |
---|
| 489 | + | if ((check == check)) |
---|
| 490 | + | then { |
---|
| 491 | + | let poolData = split(valueOrErrorMessage(getString(keyAssetPool(_assetStr)), "Unknown asset"), SEP) |
---|
| 492 | + | [StringEntry(keyAssetPool(_assetStr), dataAssetPool(ENABLED, poolData[IdxAssetPoolContractId]))] |
---|
| 493 | + | } |
---|
| 494 | + | else throw("Strict value is not equal to itself.") |
---|
| 495 | + | } |
---|
| 496 | + | |
---|
| 497 | + | |
---|
| 498 | + | @Verifier(tx) |
---|
| 499 | + | func verify () = match verifier() { |
---|
| 500 | + | case address: String => |
---|
| 501 | + | valueOrElse(getBoolean(addressFromStringValue(address), keySigned(toString(this), toBase58String(tx.id))), false) |
---|
| 502 | + | case _ => |
---|
| 503 | + | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
| 504 | + | } |
---|
| 505 | + | |
---|