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