| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $HOUSE_CUT = var["FEE"]; |
| 9 | $HALF_HOUR = 1800; |
| 10 | $RESERVE_AMOUNT = 200000; |
| 11 | $MIN_BID_INCREMENT = 0.0001; |
| 12 | $ONE_MONTH = 2592000; |
| 13 | $USER_REGISTRY_ADDRESS = "NQ2FQP24F354R2IXAKMW7CRCVH4MTIIY"; |
| 14 | $CURRENCY_REGISTRY = "J5NLMOCZUL5JLNDA6PYZDGYSRB7VH7FJ"; |
| 15 | $MAX_ROYALTY = var[$USER_REGISTRY_ADDRESS]["maxRoyalty"]; |
| 16 | |
| 17 | if (NOT trigger.data["method"]) |
| 18 | bounce("method field is mandatory"); |
| 19 | |
| 20 | $method = trigger.data["method"]; |
| 21 | |
| 22 | $spendableFunds = balance["base"] - var["locked"] - storage_size - $RESERVE_AMOUNT; |
| 23 | $owner = var["owner"]; |
| 24 | $helper = var["helper"]; |
| 25 | }", |
| 26 | "getters": "{ |
| 27 | $saleInfo = ($NFT, $seller)=>{ |
| 28 | $unit = unit[$NFT]; |
| 29 | $info = var["FREE_" || $NFT || "_" || $seller] OTHERWISE var["NFT_" || $NFT || "_" || $seller]; |
| 30 | |
| 31 | if (NOT $info) |
| 32 | bounce("That NFT is not for sale or does not exist"); |
| 33 | |
| 34 | return $info; |
| 35 | }; |
| 36 | $fetchNFT = $asset => { |
| 37 | $unitInfo = unit[$asset]; |
| 38 | $parentUnit = unit[$unitInfo.parent_units[0]]; |
| 39 | if (NOT $unitInfo.messages) |
| 40 | bounce("Bad unit"); |
| 41 | $schema = $unitInfo.authors[0].authentifiers |
| 42 | ? false |
| 43 | : $unitInfo.authors[0].address; |
| 44 | if (NOT $schema) |
| 45 | bounce("We can only accept NFTs defined with a schema"); |
| 46 | $definedBy = $unitInfo.authors[0].authentifiers |
| 47 | ? $unitInfo.authors[0].address |
| 48 | : $parentUnit.authors[0].address; |
| 49 | $metadata = $parentUnit.messages[[.app='data']].payload; |
| 50 | $isAccepted = var["NQ2FQP24F354R2IXAKMW7CRCVH4MTIIY"]["SCHEMA_" || $schema]; |
| 51 | if (NOT $isAccepted) |
| 52 | bounce("We do not accept NFTs with that schema"); |
| 53 | $assetMetadata = $unitInfo.messages[[.app='asset']].payload; |
| 54 | return {asset: $assetMetadata, meta: $metadata, author: $definedBy}; |
| 55 | }; |
| 56 | }", |
| 57 | "messages": { |
| 58 | "cases": [ |
| 59 | { |
| 60 | "if": "{NOT $owner}", |
| 61 | "messages": [ |
| 62 | { |
| 63 | "app": "state", |
| 64 | "state": "{ |
| 65 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 66 | var["helper"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 67 | var["locked"] = 0; |
| 68 | var["FEE"] = 0.1; |
| 69 | }" |
| 70 | } |
| 71 | ] |
| 72 | }, |
| 73 | { |
| 74 | "if": "{ |
| 75 | trigger.address == $owner |
| 76 | AND ($method == "payout" |
| 77 | OR $method == "transferOwnership" |
| 78 | OR $method == "reduceFee" |
| 79 | OR $method == "addSchema" |
| 80 | OR $method == "setHelper") |
| 81 | }", |
| 82 | "messages": { |
| 83 | "cases": [ |
| 84 | { |
| 85 | "if": "{$method == "payout"}", |
| 86 | "messages": [ |
| 87 | { |
| 88 | "app": "payment", |
| 89 | "payload": { |
| 90 | "asset": "base", |
| 91 | "outputs": [ |
| 92 | { |
| 93 | "address": "{trigger.address}", |
| 94 | "amount": "{$spendableFunds}" |
| 95 | } |
| 96 | ] |
| 97 | } |
| 98 | } |
| 99 | ] |
| 100 | }, |
| 101 | { |
| 102 | "if": "{$method == "transferOwnership"}", |
| 103 | "init": "{ |
| 104 | if (NOT trigger.data["newOwner"]) |
| 105 | bounce("newOwner field is mandatory"); |
| 106 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 107 | bounce("newOwner field is not a valid address"); |
| 108 | }", |
| 109 | "messages": [ |
| 110 | { |
| 111 | "app": "payment", |
| 112 | "payload": { |
| 113 | "asset": "base", |
| 114 | "outputs": [ |
| 115 | { |
| 116 | "address": "{trigger.address}", |
| 117 | "amount": "{$spendableFunds}" |
| 118 | } |
| 119 | ] |
| 120 | } |
| 121 | }, |
| 122 | { |
| 123 | "app": "state", |
| 124 | "state": "{ |
| 125 | var["owner"] = trigger.data["newOwner"]; |
| 126 | }" |
| 127 | } |
| 128 | ] |
| 129 | }, |
| 130 | { |
| 131 | "if": "{$method == "setHelper"}", |
| 132 | "init": "{ |
| 133 | if (NOT trigger.data["helper"]) |
| 134 | bounce("helper field is mandatory"); |
| 135 | }", |
| 136 | "messages": [ |
| 137 | { |
| 138 | "app": "state", |
| 139 | "state": "{ |
| 140 | var["helper"] = trigger.data["helper"]; |
| 141 | }" |
| 142 | } |
| 143 | ] |
| 144 | }, |
| 145 | { |
| 146 | "if": "{$method == "reduceFee"}", |
| 147 | "init": "{ |
| 148 | if (NOT exists(trigger.data["fee"])) |
| 149 | bounce("fee field is mandatory"); |
| 150 | if (trigger.data["fee"] < 0) |
| 151 | bounce("Are you drunk?"); |
| 152 | if (trigger.data["fee"] >= $HOUSE_CUT) |
| 153 | bounce("fee must be lower than the current one"); |
| 154 | }", |
| 155 | "messages": [ |
| 156 | { |
| 157 | "app": "state", |
| 158 | "state": "{ |
| 159 | var["FEE"] = trigger.data["fee"]; |
| 160 | }" |
| 161 | } |
| 162 | ] |
| 163 | }, |
| 164 | { |
| 165 | "if": "{$method == "addSchema"}", |
| 166 | "init": "{ |
| 167 | if (NOT trigger.data["schema"]) |
| 168 | bounce("schema field is mandatory"); |
| 169 | if (NOT is_aa(trigger.data["schema"])) |
| 170 | bounce("schema is not the address of an autonomous agent"); |
| 171 | }", |
| 172 | "messages": [ |
| 173 | { |
| 174 | "app": "state", |
| 175 | "state": "{ |
| 176 | var["SCHEMA_" || trigger.data["schema"]] = true; |
| 177 | }" |
| 178 | } |
| 179 | ] |
| 180 | } |
| 181 | ] |
| 182 | } |
| 183 | }, |
| 184 | { |
| 185 | "if": "{ |
| 186 | (trigger.address == $owner OR trigger.address == $helper) |
| 187 | AND $method == "revoke" |
| 188 | }", |
| 189 | "init": "{ |
| 190 | if (NOT trigger.data["NFT"]) |
| 191 | bounce("NFT field is mandatory"); |
| 192 | }", |
| 193 | "messages": [ |
| 194 | { |
| 195 | "app": "data_feed", |
| 196 | "payload": { |
| 197 | "{trigger.data["NFT"]}": "REVOKED" |
| 198 | } |
| 199 | } |
| 200 | ] |
| 201 | }, |
| 202 | { |
| 203 | "if": "{$method == "BUY"}", |
| 204 | "init": "{ |
| 205 | if (NOT trigger.data["address"]) |
| 206 | bounce("address field is mandatory"); |
| 207 | if (NOT is_valid_address(trigger.data["address"])) |
| 208 | bounce("address field is an invalid address"); |
| 209 | if (NOT trigger.data["NFT"]) |
| 210 | bounce("NFT field is mandatory"); |
| 211 | if (trigger.address == trigger.data["address"]) |
| 212 | bounce("You are buying your own NFT. Claim it instead in order to avoid fees"); |
| 213 | |
| 214 | $sale = $saleInfo(trigger.data["NFT"], trigger.data["address"]); |
| 215 | $nft = $fetchNFT(trigger.data["NFT"]); |
| 216 | $artist = $USER_REGISTRY_ADDRESS.$artistInfoOf($nft.author); |
| 217 | |
| 218 | $amount = $sale.isAuction |
| 219 | ? 1 |
| 220 | : trigger.data["amount"] OTHERWISE 1; |
| 221 | $pricePerUnit = $sale.currency |
| 222 | ? $CURRENCY_REGISTRY.$convert($sale.price, $sale.currency) |
| 223 | : $sale.price; |
| 224 | $fullPrice = $amount * $pricePerUnit; |
| 225 | $cut = round($fullPrice * $HOUSE_CUT, 0); |
| 226 | $toAuthor = round($fullPrice * (min($nft.meta["royalty"] OTHERWISE 0, $MAX_ROYALTY))/100, 0); |
| 227 | response["meta"] = $nft.meta; |
| 228 | response["toAuthor"] = $toAuthor; |
| 229 | $toSeller = $fullPrice - $cut - $toAuthor - 10000; |
| 230 | }", |
| 231 | "messages": [ |
| 232 | { |
| 233 | "if": "{NOT $sale.auction}", |
| 234 | "init": "{ |
| 235 | if (exists(trigger.data["amount"])){ |
| 236 | if (NOT is_integer(trigger.data["amount"])) |
| 237 | bounce("amount field must be an integer"); |
| 238 | if (trigger.data["amount"] < 1) |
| 239 | bounce("amount field must be at least 1"); |
| 240 | if (trigger.data["amount"] > $sale.amount) |
| 241 | bounce("That user is selling only " || $sale.amount || " units"); |
| 242 | } |
| 243 | |
| 244 | |
| 245 | if ($sale.currency) |
| 246 | response["rate"] = $CURRENCY_REGISTRY.$getExchangeRate($sale.currency); |
| 247 | |
| 248 | response["realPrice"] = $pricePerUnit; |
| 249 | response["total"] = $fullPrice; |
| 250 | |
| 251 | if (trigger.output[[asset="base"]].amount < $fullPrice) |
| 252 | bounce("Your payment is lower than the NFT price. You have to send " || $fullPrice || " bytes"); |
| 253 | }", |
| 254 | "app": "payment", |
| 255 | "payload": { |
| 256 | "asset": "base", |
| 257 | "outputs": [ |
| 258 | { |
| 259 | "address": "{$sale.soldBy}", |
| 260 | "amount": "{$toSeller}" |
| 261 | }, |
| 262 | { |
| 263 | "if": "{$toAuthor > 5000}", |
| 264 | "address": "{$nft.author}", |
| 265 | "amount": "{$toAuthor}" |
| 266 | } |
| 267 | ] |
| 268 | } |
| 269 | }, |
| 270 | { |
| 271 | "if": "{NOT $sale.auction}", |
| 272 | "app": "payment", |
| 273 | "payload": { |
| 274 | "asset": "{trigger.data['NFT']}", |
| 275 | "outputs": [ |
| 276 | { |
| 277 | "address": "{trigger.address}", |
| 278 | "amount": "{$amount}" |
| 279 | } |
| 280 | ] |
| 281 | } |
| 282 | }, |
| 283 | { |
| 284 | "app": "state", |
| 285 | "state": "{ |
| 286 | if ($sale.auction) { |
| 287 | if (trigger.output[[asset="base"]].amount < 20000) |
| 288 | bounce("The minimum bid is 20000 bytes"); |
| 289 | if (trigger.output[[asset="base"]].amount <= $sale.price * (1 + $MIN_BID_INCREMENT)) |
| 290 | bounce("Your bid must be at least " || ceil($sale.price * (1 + $MIN_BID_INCREMENT), 0) || " (0.01% higher than the current)"); |
| 291 | |
| 292 | if ($sale.soldBy == trigger.address) |
| 293 | bounce("You cannot bid on your own auction"); |
| 294 | if (timestamp > $sale.endTime AND $sale.bids) |
| 295 | bounce("The auction is over"); |
| 296 | |
| 297 | var["locked"] += trigger.output[[asset="base"]].amount - ($sale.by ? $sale.price : 0); |
| 298 | $saleState = $sale || { |
| 299 | price: trigger.output[[asset="base"]].amount, |
| 300 | at: timestamp, |
| 301 | bids: $sale.bids + 1, |
| 302 | by: trigger.address, |
| 303 | endTime: $sale.endTime + $HALF_HOUR |
| 304 | }; |
| 305 | } |
| 306 | else { |
| 307 | $newAmount = $sale.amount - $amount; |
| 308 | $saleState = $newAmount == 0 ? false : $sale || {amount: $newAmount, at: timestamp}; |
| 309 | } |
| 310 | |
| 311 | $key = var["FREE_" || trigger.data["NFT"] || "_" || trigger.data["address"]] |
| 312 | ? "FREE_" |
| 313 | : "NFT_"; |
| 314 | $fullKey = $key || trigger.data["NFT"] || "_" || trigger.data["address"]; |
| 315 | |
| 316 | var[$fullKey] = $saleState; |
| 317 | }" |
| 318 | } |
| 319 | ] |
| 320 | }, |
| 321 | { |
| 322 | "if": "{$method == "CLAIM"}", |
| 323 | "init": "{ |
| 324 | $address = trigger.data["address"] OTHERWISE trigger.address; |
| 325 | $sale = $saleInfo(trigger.data["NFT"], $address); |
| 326 | if (NOT trigger.data["NFT"]) |
| 327 | bounce("NFT field is mandatory"); |
| 328 | $nft = $fetchNFT(trigger.data["NFT"]); |
| 329 | $artist = $USER_REGISTRY_ADDRESS.$artistInfoOf($nft.author); |
| 330 | if (NOT $sale.auction) |
| 331 | bounce("That sale is not an auction"); |
| 332 | if ($sale.auction AND timestamp >= $sale.endTime) |
| 333 | bounce("The auction is not over yet"); |
| 334 | $fullKey = var["FREE_" || trigger.data["NFT"] || "_" || $sale.soldBy] |
| 335 | ? "FREE_" || trigger.data["NFT"] || "_" || $sale.soldBy |
| 336 | : "NFT_" || trigger.data["NFT"] || "_" || $sale.soldBy; |
| 337 | }", |
| 338 | "messages": { |
| 339 | "cases": [ |
| 340 | { |
| 341 | "if": "{$sale.auction}", |
| 342 | "messages": [ |
| 343 | { |
| 344 | "if": "{$sale.bids > 0}", |
| 345 | "app": "payment", |
| 346 | "init": "{ |
| 347 | $share = $sale.price * (1 - $HOUSE_CUT); |
| 348 | if ($nft.meta["royalty"]){ |
| 349 | $royalty = $sale.price * min($nft.meta["royalty"], $MAX_ROYALTY) / 100; |
| 350 | $outputs = [ |
| 351 | { |
| 352 | address: $nft.author, |
| 353 | amount: floor($royalty, 0) |
| 354 | }, |
| 355 | { |
| 356 | address: $sale.soldBy, |
| 357 | amount: floor($share - $royalty, 0) |
| 358 | } |
| 359 | ]; |
| 360 | } |
| 361 | else{ |
| 362 | $outputs = [ |
| 363 | { |
| 364 | address: $sale.soldBy, |
| 365 | amount: floor($share, 0) |
| 366 | } |
| 367 | ]; |
| 368 | } |
| 369 | $payload = {outputs: $outputs}; |
| 370 | }", |
| 371 | "payload": "{$payload}" |
| 372 | }, |
| 373 | { |
| 374 | "app": "payment", |
| 375 | "payload": { |
| 376 | "asset": "{trigger.data['NFT']}", |
| 377 | "outputs": [ |
| 378 | { |
| 379 | "address": "{$sale.by OTHERWISE $sale.soldBy}", |
| 380 | "amount": "{$sale.amount}" |
| 381 | } |
| 382 | ] |
| 383 | } |
| 384 | }, |
| 385 | { |
| 386 | "app": "state", |
| 387 | "state": "{ |
| 388 | if ($sale.bids > 0) |
| 389 | var["locked"] -= $sale.price; |
| 390 | |
| 391 | var[$fullKey] = false; |
| 392 | }" |
| 393 | } |
| 394 | ] |
| 395 | }, |
| 396 | { |
| 397 | "if": "{NOT $sale.auction}", |
| 398 | "init": "{ |
| 399 | if (trigger.address != $sale.soldBy) |
| 400 | bounce("You cannot claim other people's sales"); |
| 401 | }", |
| 402 | "messages": [ |
| 403 | { |
| 404 | "app": "payment", |
| 405 | "payload": { |
| 406 | "asset": "{trigger.data['NFT']}", |
| 407 | "outputs": [ |
| 408 | { |
| 409 | "address": "{$sale.soldBy}", |
| 410 | "amount": "{$sale.amount}" |
| 411 | } |
| 412 | ] |
| 413 | } |
| 414 | }, |
| 415 | { |
| 416 | "app": "state", |
| 417 | "state": "{ |
| 418 | var[$fullKey] = false; |
| 419 | }" |
| 420 | } |
| 421 | ] |
| 422 | } |
| 423 | ] |
| 424 | } |
| 425 | }, |
| 426 | { |
| 427 | "if": "{$method == "REDEEM"}", |
| 428 | "init": "{ |
| 429 | if (NOT exists(trigger.data["signed_message"])) |
| 430 | bounce("signed_message field is mandatory"); |
| 431 | if (NOT exists(trigger.data["authors"])) |
| 432 | bounce('authors field is mandatory'); |
| 433 | if (NOT exists(trigger.data["meta"])) |
| 434 | bounce("meta field is mandatory"); |
| 435 | |
| 436 | $spack = { |
| 437 | signed_message: trigger.data["signed_message"], |
| 438 | authors: trigger.data["authors"] |
| 439 | } || trigger.data["meta"]; |
| 440 | |
| 441 | if (NOT is_valid_signed_package($spack, $spack.authors[0]["address"])) |
| 442 | bounce("The signed message signature is invalid"); |
| 443 | if (NOT $spack.signed_message["serial"]) |
| 444 | bounce("The signed message does not contains a serial field"); |
| 445 | if (NOT $spack.signed_message["NFT"]) |
| 446 | bounce("The signer of this message did not include a NFT field"); |
| 447 | |
| 448 | |
| 449 | if (var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"])]) |
| 450 | bounce("That code was already redeemed"); |
| 451 | |
| 452 | $sale = $saleInfo($spack.signed_message["NFT"], $spack.authors[0]["address"]); |
| 453 | |
| 454 | if (NOT $sale) |
| 455 | bounce("That NFT is not listed for sale"); |
| 456 | |
| 457 | if ($sale.auction) |
| 458 | bounce("You cannot claim a NFT that is being auctioned"); |
| 459 | |
| 460 | |
| 461 | if ($spack.signed_message["expireDate"]){ |
| 462 | if ($spack.signed_message["expireDate"] < timestamp) |
| 463 | bounce("That code is no longer redeemable"); |
| 464 | } |
| 465 | |
| 466 | |
| 467 | if ($spack.signed_message["claimer"]){ |
| 468 | if ($spack.signed_message["claimer"] != trigger.address) |
| 469 | bounce("You cannot claim that NFT from that address"); |
| 470 | } |
| 471 | |
| 472 | $signedAmount = $spack.signed_message["amount"] OTHERWISE 1; |
| 473 | |
| 474 | if ($signedAmount > $sale.amount) |
| 475 | $amount = $sale.amount; |
| 476 | else |
| 477 | $amount = $signedAmount; |
| 478 | |
| 479 | |
| 480 | if ($amount == 0) |
| 481 | bounce("All copies of that NFT have been already sold"); |
| 482 | }", |
| 483 | "messages": { |
| 484 | "cases": [ |
| 485 | { |
| 486 | "messages": [ |
| 487 | { |
| 488 | "app": "payment", |
| 489 | "payload": { |
| 490 | "asset": "{$spack.signed_message["NFT"]}", |
| 491 | "outputs": [ |
| 492 | { |
| 493 | "address": "{trigger.address}", |
| 494 | "amount": "{$amount}" |
| 495 | } |
| 496 | ] |
| 497 | } |
| 498 | }, |
| 499 | { |
| 500 | "app": "state", |
| 501 | "state": "{ |
| 502 | $key = var["FREE_" || $spack.signed_message["NFT"] || $spack.authors[0]["address"]] |
| 503 | ? "FREE_" || $spack.signed_message["NFT"] || $spack.authors[0]["address"] |
| 504 | : "NFT_" || $spack.signed_message["NFT"] || $spack.authors[0]["address"]; |
| 505 | |
| 506 | var[$key] = ($sale.amount - $amount > 0) |
| 507 | ? $sale || {amount: $sale.amount - $amount} |
| 508 | : false; |
| 509 | |
| 510 | var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"], 'base64')] = true; |
| 511 | }" |
| 512 | } |
| 513 | ] |
| 514 | } |
| 515 | ] |
| 516 | } |
| 517 | }, |
| 518 | { |
| 519 | "if": "{$method == "CHANGE_PRICE"}", |
| 520 | "init": "{ |
| 521 | if (NOT trigger.data["NFT"]) |
| 522 | bounce("NFT field is mandatory"); |
| 523 | |
| 524 | $sale = $saleInfo(trigger.data["NFT"], trigger.address); |
| 525 | |
| 526 | if (NOT $sale) |
| 527 | bounce("Sale not found"); |
| 528 | |
| 529 | if (NOT exists(trigger.data["price"])) |
| 530 | bounce("price field is mandatory"); |
| 531 | |
| 532 | if (NOT exists(trigger.data["currency"])){ |
| 533 | if (NOT is_integer(trigger.data["price"])) |
| 534 | bounce("price must be an integer"); |
| 535 | if (NOT is_valid_amount(trigger.data["price"])) |
| 536 | bounce("price is invalid"); |
| 537 | if (trigger.data["price"] < 20000) |
| 538 | bounce("The minimum price is 20000 bytes"); |
| 539 | } |
| 540 | else{ |
| 541 | if (NOT $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"])) |
| 542 | bounce("You cannot set the price in that currency"); |
| 543 | } |
| 544 | |
| 545 | if ($sale.auction) |
| 546 | bounce("You cannot change an auction price!"); |
| 547 | }", |
| 548 | "messages": [ |
| 549 | { |
| 550 | "app": "state", |
| 551 | "state": "{ |
| 552 | if (var["NFT_" || trigger.data["NFT"] || "_" || trigger.address]) |
| 553 | var["NFT_" || trigger.data["NFT"] || "_" || trigger.address] ||= {price: trigger.data["price"], soldBy: trigger.address, currency: trigger.data["currency"] OTHERWISE false}; |
| 554 | else |
| 555 | var["FREE_" || trigger.data["NFT"] || "_" || trigger.address] ||= {price: trigger.data["price"], soldBy: trigger.address, currency: trigger.data["currency"] OTHERWISE false}; |
| 556 | }" |
| 557 | } |
| 558 | ] |
| 559 | }, |
| 560 | { |
| 561 | "if": "{$method == "SELL"}", |
| 562 | "init": "{ |
| 563 | if (trigger.output[[asset!="base"]].asset == "ambigous") |
| 564 | bounce("You can only send a single NFT at a time"); |
| 565 | |
| 566 | $NFT = $fetchNFT(trigger.output[[asset!="base"]].asset); |
| 567 | |
| 568 | $prof = $USER_REGISTRY_ADDRESS.$profileOf($NFT.author); |
| 569 | |
| 570 | $feedData = data_feed[[oracles=this_address, feed_name=trigger.output[[asset!="base"]].asset, ifnone="OK", ifseveral="last", type="string"]]; |
| 571 | if ($feedData == "REVOKED") |
| 572 | bounce("We revoked the trading of that token probably due to copyright reasons"); |
| 573 | |
| 574 | if (NOT trigger.data["price"]) |
| 575 | bounce("price field is mandatory"); |
| 576 | if (trigger.data["currency"]){ |
| 577 | if (NOT $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"])) |
| 578 | bounce("We do not support that currency"); |
| 579 | } |
| 580 | else { |
| 581 | if (NOT is_integer(trigger.data["price"])) |
| 582 | bounce("Price must be an integer"); |
| 583 | if (NOT is_valid_amount(trigger.data["price"])) |
| 584 | bounce("Price is not a valid amount"); |
| 585 | if (trigger.data["price"] * trigger.output[[asset!="base"]].amount < 20000) |
| 586 | bounce("The minimum sale price is 20.000 bytes"); |
| 587 | } |
| 588 | if (trigger.data["auction"]){ |
| 589 | if (NOT exists(trigger.data["endTime"])) |
| 590 | bounce("If you want to hold an auction you have to specify the endTime"); |
| 591 | if (trigger.data["endTime"] <= timestamp) |
| 592 | bounce("You cannot set the end time in the past"); |
| 593 | if (trigger.data["endTime"] > timestamp + 2628000) |
| 594 | bounce("You cannot set the end time in more than 30 days"); |
| 595 | } |
| 596 | }", |
| 597 | "messages": [ |
| 598 | { |
| 599 | "app": "state", |
| 600 | "state": "{ |
| 601 | $key = ($prof.verified ? "NFT_" : "FREE_") || trigger.output[[asset!="base"]].asset || "_" || trigger.address; |
| 602 | var[$key] = { |
| 603 | price: trigger.data["price"], |
| 604 | amount: trigger.output[[asset!="base"]].amount, |
| 605 | endTime: trigger.data["auction"] |
| 606 | ? trigger.data["endTime"] |
| 607 | : false, |
| 608 | soldBy: trigger.address, |
| 609 | bids: trigger.data["auction"] |
| 610 | ? 0 |
| 611 | : false, |
| 612 | auction: trigger.data["auction"] |
| 613 | ? true |
| 614 | : false, |
| 615 | redeem: trigger.data["redeem"] |
| 616 | ? true |
| 617 | : false, |
| 618 | currency: trigger.data["auction"] |
| 619 | ? false |
| 620 | : trigger.data["currency"] OTHERWISE false |
| 621 | }; |
| 622 | }" |
| 623 | } |
| 624 | ] |
| 625 | } |
| 626 | ] |
| 627 | } |
| 628 | } |
| 629 | ] |