| 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 = "JGFBXZPQ4HF5PRYJO4AAH3HKCJENB4HP"; |
| 14 | $CURRENCY_REGISTRY = "J5NLMOCZUL5JLNDA6PYZDGYSRB7VH7FJ"; |
| 15 | |
| 16 | $extendDeadLine = $NFT=>($NFT.soldAt <= timestamp + $HALF_HOUR) ? ($NFT || {soldAt: $NFT.soldAt + $HALF_HOUR}) : $NFT; |
| 17 | /* |
| 18 | ** Strips $NFT of computed fields to reduce AA's storage size |
| 19 | */ |
| 20 | $stripToken = $NFT=>{ |
| 21 | delete($NFT, "isBanned"); |
| 22 | delete($NFT, "cap"); |
| 23 | delete($NFT, "mintedAt"); |
| 24 | return $NFT; |
| 25 | }; |
| 26 | |
| 27 | if (NOT trigger.data["method"]) |
| 28 | bounce("method field is mandatory"); |
| 29 | |
| 30 | $method = trigger.data["method"]; |
| 31 | |
| 32 | $spendableFunds = balance["base"] - var["locked"] - storage_size - $RESERVE_AMOUNT; |
| 33 | $owner = var["owner"]; |
| 34 | }", |
| 35 | "getters": "{ |
| 36 | $saleInfo = $NFT=>{ |
| 37 | $unit = unit[$NFT]; |
| 38 | $info = var["FREE_" || $NFT] OTHERWISE var["NFT_" || $NFT]; |
| 39 | |
| 40 | if (NOT $info) |
| 41 | bounce("That NFT is not for sale or does not exist"); |
| 42 | |
| 43 | return $info || { |
| 44 | cap: $unit.messages[[.app="asset"]]["payload"]["cap"], |
| 45 | mintedAt: $unit.timestamp |
| 46 | }; |
| 47 | }; |
| 48 | /* |
| 49 | ** Example of a meta getter to enable platform interop |
| 50 | */ |
| 51 | $getNFTInfo = $NFT=>{ |
| 52 | $unit = unit[$NFT]; |
| 53 | /* |
| 54 | ** Info should have at least 'author' field. 'ipfs' and 'type' field are also recommended. |
| 55 | */ |
| 56 | $info = var["FREE_" || $NFT] OTHERWISE var["NFT_" || $NFT]; |
| 57 | $transferrable = $unit.messages[[.app="asset"]]["payload"]["transferrable"]; |
| 58 | |
| 59 | return $info || { |
| 60 | cap: $unit.messages[[.app="asset"]]["payload"]["cap"], |
| 61 | mintedAt: $unit.timestamp, |
| 62 | transferrable: $transferrable |
| 63 | }; |
| 64 | }; |
| 65 | }", |
| 66 | "messages": { |
| 67 | "cases": [ |
| 68 | { |
| 69 | "if": "{NOT $owner}", |
| 70 | "messages": [ |
| 71 | { |
| 72 | "app": "state", |
| 73 | "state": "{ |
| 74 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 75 | var["helper"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 76 | var["locked"] = 0; |
| 77 | var["FEE"] = 0.1; |
| 78 | }" |
| 79 | } |
| 80 | ] |
| 81 | }, |
| 82 | { |
| 83 | "if": "{ |
| 84 | trigger.address == $owner |
| 85 | AND ($method == "payout" |
| 86 | OR $method == "transferOwnership" |
| 87 | OR $method == "reduceFee" |
| 88 | OR $method == "setHelper") |
| 89 | }", |
| 90 | "messages": { |
| 91 | "cases": [ |
| 92 | { |
| 93 | "if": "{$method == "payout"}", |
| 94 | "messages": [ |
| 95 | { |
| 96 | "app": "payment", |
| 97 | "payload": { |
| 98 | "asset": "base", |
| 99 | "outputs": [ |
| 100 | { |
| 101 | "address": "{trigger.address}", |
| 102 | "amount": "{$spendableFunds}" |
| 103 | } |
| 104 | ] |
| 105 | } |
| 106 | } |
| 107 | ] |
| 108 | }, |
| 109 | { |
| 110 | "if": "{$method == "transferOwnership"}", |
| 111 | "init": "{ |
| 112 | if (NOT trigger.data["newOwner"]) |
| 113 | bounce("newOwner field is mandatory"); |
| 114 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 115 | bounce("newOwner field is not a valid address"); |
| 116 | }", |
| 117 | "messages": [ |
| 118 | { |
| 119 | "app": "payment", |
| 120 | "payload": { |
| 121 | "asset": "base", |
| 122 | "outputs": [ |
| 123 | { |
| 124 | "address": "{trigger.address}", |
| 125 | "amount": "{$spendableFunds}" |
| 126 | } |
| 127 | ] |
| 128 | } |
| 129 | }, |
| 130 | { |
| 131 | "app": "state", |
| 132 | "state": "{ |
| 133 | var["owner"] = trigger.data["newOwner"]; |
| 134 | }" |
| 135 | } |
| 136 | ] |
| 137 | }, |
| 138 | { |
| 139 | "if": "{$method == "setHelper"}", |
| 140 | "init": "{ |
| 141 | if (NOT trigger.data["helper"]) |
| 142 | bounce("helper field is mandatory"); |
| 143 | }", |
| 144 | "messages": [ |
| 145 | { |
| 146 | "app": "state", |
| 147 | "state": "{ |
| 148 | var["helper"] = trigger.data["helper"]; |
| 149 | }" |
| 150 | } |
| 151 | ] |
| 152 | }, |
| 153 | { |
| 154 | "if": "{$method == "reduceFee"}", |
| 155 | "init": "{ |
| 156 | if (NOT exists(trigger.data["fee"])) |
| 157 | bounce("fee field is mandatory"); |
| 158 | if (trigger.data["fee"] < 0) |
| 159 | bounce("Are you drunk?"); |
| 160 | if (trigger.data["fee"] >= $HOUSE_CUT) |
| 161 | bounce("fee must be lower than the current one"); |
| 162 | }", |
| 163 | "messages": [ |
| 164 | { |
| 165 | "app": "state", |
| 166 | "state": "{ |
| 167 | var["FEE"] = trigger.data["fee"]; |
| 168 | }" |
| 169 | } |
| 170 | ] |
| 171 | } |
| 172 | ] |
| 173 | } |
| 174 | }, |
| 175 | { |
| 176 | "if": "{ |
| 177 | (trigger.address == $owner OR trigger.address == var["helper"]) |
| 178 | AND $method == "revoke" |
| 179 | }", |
| 180 | "init": "{ |
| 181 | if (NOT trigger.data["NFT"]) |
| 182 | bounce("NFT field is mandatory"); |
| 183 | }", |
| 184 | "messages": [ |
| 185 | { |
| 186 | "app": "data_feed", |
| 187 | "payload": { |
| 188 | "{trigger.data["NFT"]}": "REVOKED" |
| 189 | } |
| 190 | } |
| 191 | ] |
| 192 | }, |
| 193 | { |
| 194 | "if": "{$method == "MINT"}", |
| 195 | "init": "{ |
| 196 | if (NOT exists(trigger.data["amount"])) |
| 197 | bounce("amount field is mandatory"); |
| 198 | |
| 199 | if (NOT is_valid_amount(trigger.data["amount"]) AND trigger.data["amount"] != 0) |
| 200 | bounce("The amount of NFT copies to mint is not valid"); |
| 201 | |
| 202 | if (NOT exists(trigger.data["type"])) |
| 203 | bounce("type field is mandatory"); |
| 204 | else if (trigger.data["type"] == "LIC") |
| 205 | bounce("You cannot issue licenses using the AA"); |
| 206 | |
| 207 | if (exists(trigger.data["endTime"])){ |
| 208 | if (NOT is_integer(trigger.data["endTime"])) |
| 209 | bounce("endTime must be an integer"); |
| 210 | if (trigger.data["endTime"] <= timestamp) |
| 211 | bounce("The endTime cannot be set in the past"); |
| 212 | } |
| 213 | |
| 214 | if ($owner != trigger.address){ |
| 215 | if (trigger.data["endTime"] - timestamp > 2628000) |
| 216 | bounce("You cannot set the end time in more than 30 days in the future"); |
| 217 | } |
| 218 | |
| 219 | if (NOT exists(trigger.data["title"])) |
| 220 | bounce("title field is mandatory"); |
| 221 | |
| 222 | if (NOT exists(trigger.data["ipfs"])) |
| 223 | bounce("ipfs field is mandatory"); |
| 224 | |
| 225 | if (exists(trigger.data["royalty"])){ |
| 226 | if (NOT is_integer(trigger.data["royalty"])) |
| 227 | bounce("royalty must be an integer"); |
| 228 | if (trigger.data["royalty"] < 0 OR trigger.data["royalty"] > 40) |
| 229 | bounce("royalty must be in the interval 0-40"); |
| 230 | } |
| 231 | |
| 232 | $seller = trigger.address == $owner |
| 233 | ? trigger.data["seller"] OTHERWISE trigger.address |
| 234 | : trigger.address; |
| 235 | |
| 236 | if (trigger.data["seller"] AND NOT is_valid_address(trigger.data["seller"])) |
| 237 | bounce("The seller address is not valid"); |
| 238 | |
| 239 | $currency = $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"]); |
| 240 | |
| 241 | if (exists(trigger.data["currency"])){ |
| 242 | if (trigger.data["amount"] == 1) |
| 243 | bounce("You cannot price an auction in other than Bytes"); |
| 244 | if (NOT $currency) |
| 245 | bounce("The provided currency is not supported"); |
| 246 | } |
| 247 | |
| 248 | $prof = $USER_REGISTRY_ADDRESS.$profileOf($seller); |
| 249 | |
| 250 | $key = $prof.verified |
| 251 | ? "NFT_" |
| 252 | : "FREE_"; |
| 253 | }", |
| 254 | "messages": { |
| 255 | "cases": [ |
| 256 | { |
| 257 | "if": "{trigger.data["amount"] == 1}", |
| 258 | "messages": [ |
| 259 | { |
| 260 | "app": "asset", |
| 261 | "payload": { |
| 262 | "cap": 1, |
| 263 | "is_private": false, |
| 264 | "is_transferrable": true, |
| 265 | "auto_destroy": false, |
| 266 | "fixed_denominations": false, |
| 267 | "issued_by_definer_only": true, |
| 268 | "cosigned_by_definer": false, |
| 269 | "spender_attested": false |
| 270 | } |
| 271 | }, |
| 272 | { |
| 273 | "app": "data", |
| 274 | "if": "{var["recordToData"]}", |
| 275 | "payload": { |
| 276 | "asset": "{var["recordToData"]}", |
| 277 | "name": "{trigger.data["title"] OTHERWISE "Untitled"}", |
| 278 | "author": "{$seller}", |
| 279 | "ipfs": "{trigger.data["ipfs"]}", |
| 280 | "type": "{trigger.data["type"]}", |
| 281 | "decimals": 0 |
| 282 | } |
| 283 | }, |
| 284 | { |
| 285 | "app": "state", |
| 286 | "state": "{ |
| 287 | var[$key || response_unit] = { |
| 288 | bid: 20000, |
| 289 | bids: 0, |
| 290 | type: trigger.data["type"], |
| 291 | by: $seller, |
| 292 | royalty: trigger.data["royalty"] OTHERWISE 0, |
| 293 | at: timestamp, |
| 294 | ipfs: trigger.data["ipfs"], |
| 295 | author: $seller, |
| 296 | soldAt: trigger.data["endTime"] OTHERWISE timestamp + $ONE_MONTH, |
| 297 | soldBy: $seller |
| 298 | }; |
| 299 | |
| 300 | var["recordToData"] = response_unit; |
| 301 | }" |
| 302 | } |
| 303 | ] |
| 304 | }, |
| 305 | { |
| 306 | "init": "{ |
| 307 | $price = trigger.data["price"]; |
| 308 | if (NOT $price) |
| 309 | bounce("price field is mandatory if you intend to sell more than one NFT copy"); |
| 310 | if (NOT exists(trigger.data["currency"])){ |
| 311 | if ($price < 20000) |
| 312 | bounce("The minium price is 20000 bytes"); |
| 313 | if (NOT is_integer(trigger.data["price"])) |
| 314 | bounce("Price must be an integer"); |
| 315 | if (NOT is_valid_amount($price)) |
| 316 | bounce("price is not valid"); |
| 317 | } |
| 318 | }", |
| 319 | "messages": [ |
| 320 | { |
| 321 | "app": "asset", |
| 322 | "if": "{ |
| 323 | trigger.data["amount"] == 0 |
| 324 | }", |
| 325 | "payload": { |
| 326 | "is_private": false, |
| 327 | "is_transferrable": true, |
| 328 | "auto_destroy": false, |
| 329 | "fixed_denominations": false, |
| 330 | "issued_by_definer_only": true, |
| 331 | "cosigned_by_definer": false, |
| 332 | "spender_attested": false |
| 333 | } |
| 334 | }, |
| 335 | { |
| 336 | "app": "asset", |
| 337 | "if": "{ |
| 338 | trigger.data["amount"] > 0 |
| 339 | }", |
| 340 | "payload": { |
| 341 | "cap": "{trigger.data["amount"]}", |
| 342 | "is_private": false, |
| 343 | "is_transferrable": true, |
| 344 | "auto_destroy": false, |
| 345 | "fixed_denominations": false, |
| 346 | "issued_by_definer_only": true, |
| 347 | "cosigned_by_definer": false, |
| 348 | "spender_attested": false |
| 349 | } |
| 350 | }, |
| 351 | { |
| 352 | "app": "data", |
| 353 | "if": "{var["recordToData"]}", |
| 354 | "payload": { |
| 355 | "asset": "{var["recordToData"]}", |
| 356 | "name": "{trigger.data["title"] OTHERWISE "Untitled"}", |
| 357 | "author": "{$seller}", |
| 358 | "ipfs": "{trigger.data["ipfs"]}", |
| 359 | "type": "{trigger.data["type"]}", |
| 360 | "decimals": 0 |
| 361 | } |
| 362 | }, |
| 363 | { |
| 364 | "app": "state", |
| 365 | "state": "{ |
| 366 | var[$key || response_unit] = { |
| 367 | price: $price, |
| 368 | type: trigger.data["type"], |
| 369 | at: timestamp, |
| 370 | royalty: trigger.data["royalty"] OTHERWISE 0, |
| 371 | ipfs: trigger.data["ipfs"], |
| 372 | unitsSold: 0, |
| 373 | author: $seller, |
| 374 | soldAt: trigger.data["endTime"] OTHERWISE timestamp + $ONE_MONTH, |
| 375 | soldBy: $seller, |
| 376 | redeem: trigger.data["redeem"] ? true : false, |
| 377 | currency: trigger.data["currency"] OTHERWISE false |
| 378 | }; |
| 379 | var["recordToData"] = response_unit; |
| 380 | }" |
| 381 | } |
| 382 | ] |
| 383 | } |
| 384 | ] |
| 385 | } |
| 386 | }, |
| 387 | { |
| 388 | "if": "{ |
| 389 | $method == "BUY" |
| 390 | OR $method == "CLAIM" |
| 391 | }", |
| 392 | "init": "{ |
| 393 | $NFT = $saleInfo(trigger.data["NFT"]); |
| 394 | |
| 395 | $artist = $USER_REGISTRY_ADDRESS.$artistInfoOf($NFT.author); |
| 396 | |
| 397 | |
| 398 | if ($method == "BUY"){ |
| 399 | if (NOT exists(trigger.data["NFT"])) |
| 400 | bounce("NFT field is mandatory"); |
| 401 | |
| 402 | $isAuction = $NFT.bid ? true : false; |
| 403 | |
| 404 | if ($isAuction) |
| 405 | $hasBidders = $NFT.by |
| 406 | ? $NFT.soldBy |
| 407 | ? ($NFT.soldBy != $NFT.by) |
| 408 | ? true |
| 409 | : false |
| 410 | : false |
| 411 | : false; |
| 412 | |
| 413 | if ($isAuction AND NOT $NFT.by) |
| 414 | bounce("There are no copies of that NFT listed for sale at the moment"); |
| 415 | |
| 416 | if ($isAuction){ |
| 417 | if (timestamp > $NFT.soldAt){ |
| 418 | if ($isAuction){ |
| 419 | if ($hasBidders) |
| 420 | bounce("The auction is over"); |
| 421 | } |
| 422 | else{ |
| 423 | bounce("The sale is already over"); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | else if ($method == "CLAIM"){ |
| 430 | if (NOT trigger.data["NFT"]) |
| 431 | bounce("NFT field is mandatory"); |
| 432 | |
| 433 | $isAuction = $NFT.bid ? true : false; |
| 434 | |
| 435 | if (NOT $isAuction) |
| 436 | bounce("You cannot claim a non-auction sale"); |
| 437 | |
| 438 | $hasBidders = ($NFT.soldBy != $NFT.by) ? true : false; |
| 439 | |
| 440 | if (timestamp <= $NFT.soldAt) |
| 441 | bounce("The auction is not over yet"); |
| 442 | |
| 443 | if ($NFT.claimed) |
| 444 | bounce("That auction was already claimed"); |
| 445 | } |
| 446 | }", |
| 447 | "messages": { |
| 448 | "cases": [ |
| 449 | { |
| 450 | "if": "{trigger.data["method"] == "BUY"}", |
| 451 | "messages": { |
| 452 | "cases": [ |
| 453 | { |
| 454 | "if": "{$isAuction}", |
| 455 | "init": "{ |
| 456 | if (trigger.output[[asset="base"]].amount < 20000) |
| 457 | bounce("The minimum bid is 20000 bytes"); |
| 458 | if (trigger.output[[asset="base"]].amount <= $NFT.bid * (1 + $MIN_BID_INCREMENT)) |
| 459 | bounce("Your bid must be at least " || ceil($NFT.bid * (1 + $MIN_BID_INCREMENT), 0) || " (0.01% higher than the current)"); |
| 460 | |
| 461 | if ($NFT.soldBy == trigger.address) |
| 462 | bounce("You cannot bid on your own auction"); |
| 463 | }", |
| 464 | "messages": [ |
| 465 | { |
| 466 | "app": "payment", |
| 467 | "if": "{ |
| 468 | $NFT.by != $NFT.soldBy |
| 469 | }", |
| 470 | "payload": { |
| 471 | "asset": "base", |
| 472 | "outputs": [ |
| 473 | { |
| 474 | "address": "{$NFT.by}", |
| 475 | "amount": "{$NFT.bid - 10000}" |
| 476 | } |
| 477 | ] |
| 478 | } |
| 479 | }, |
| 480 | { |
| 481 | "app": "state", |
| 482 | "state": "{ |
| 483 | var["locked"] += trigger.output[[asset="base"]].amount - ($NFT.soldBy != $NFT.by ? $NFT.bid : 0); |
| 484 | $NFT.bid = trigger.output[[asset="base"]].amount; |
| 485 | $NFT.at = timestamp; |
| 486 | $NFT.bids = $NFT.bids + 1; |
| 487 | $NFT.by = trigger.address; |
| 488 | if (var["FREE_" || trigger.data["NFT"]]) |
| 489 | var["FREE_" || trigger.data["NFT"]] ||= $stripToken($NFT); |
| 490 | else |
| 491 | var["NFT_" || trigger.data["NFT"]] ||= $stripToken($extendDeadLine($NFT)); |
| 492 | }" |
| 493 | } |
| 494 | ] |
| 495 | }, |
| 496 | { |
| 497 | "init": "{ |
| 498 | if ($NFT.unitsSold == $NFT.cap AND $NFT.cap != 0) |
| 499 | bounce("All NFT copies have been already sold"); |
| 500 | |
| 501 | $realPrice = $NFT.currency ? $CURRENCY_REGISTRY.$convert($NFT.price, $NFT.currency) : $NFT.price; |
| 502 | response["realPrice"] = $realPrice; |
| 503 | |
| 504 | if ($NFT.currency) |
| 505 | response["rate"] = $CURRENCY_REGISTRY.$getExchangeRate($NFT.currency); |
| 506 | |
| 507 | if (trigger.output[[asset="base"]].amount < $realPrice) |
| 508 | bounce("Your payment is lower than the NFT price. You have to send " || $realPrice || " bytes"); |
| 509 | }", |
| 510 | "messages": [ |
| 511 | { |
| 512 | "app": "payment", |
| 513 | "if": "{ |
| 514 | floor($realPrice * (1 - $HOUSE_CUT) - 10000, 0) > 0 |
| 515 | }", |
| 516 | "payload": { |
| 517 | "asset": "base", |
| 518 | "outputs": { |
| 519 | "cases": [ |
| 520 | { |
| 521 | "outputs": [ |
| 522 | { |
| 523 | "address": "{$NFT.soldBy}", |
| 524 | "amount": "{floor($realPrice * (1 - $HOUSE_CUT) - 10000, 0)}" |
| 525 | } |
| 526 | ] |
| 527 | } |
| 528 | ] |
| 529 | } |
| 530 | } |
| 531 | }, |
| 532 | { |
| 533 | "app": "payment", |
| 534 | "payload": { |
| 535 | "asset": "{trigger.data['NFT']}", |
| 536 | "outputs": [ |
| 537 | { |
| 538 | "address": "{trigger.address}", |
| 539 | "amount": 1 |
| 540 | } |
| 541 | ] |
| 542 | } |
| 543 | }, |
| 544 | { |
| 545 | "app": "state", |
| 546 | "state": "{ |
| 547 | if ($NFT.soldBy == $NFT.author){ |
| 548 | if (var["FREE_" || trigger.data["NFT"]]) |
| 549 | var["FREE_" || trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1}; |
| 550 | else |
| 551 | var["NFT_" || trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1}; |
| 552 | |
| 553 | if ($NFT.unitsSold + 1 == $NFT.cap AND $NFT.cap != 0){ |
| 554 | if (var["FREE_" || trigger.data["NFT"]]) |
| 555 | var["FREE_" || trigger.data["NFT"]] ||= {bid: $NFT.price, price: false, soldAt: timestamp, currency: false, claimed: true}; |
| 556 | else |
| 557 | var["NFT_" || trigger.data["NFT"]] ||= {bid: $NFT.price, price: false, soldAt: timestamp, currency: false}; |
| 558 | } |
| 559 | } |
| 560 | }" |
| 561 | } |
| 562 | ] |
| 563 | } |
| 564 | ] |
| 565 | } |
| 566 | }, |
| 567 | { |
| 568 | "if": "{trigger.data["method"] == "CLAIM"}", |
| 569 | "messages": { |
| 570 | "cases": [ |
| 571 | { |
| 572 | "if": "{$NFT.soldBy == $NFT.author}", |
| 573 | "init": "{ |
| 574 | $sellerPayout = floor($NFT.bid * (1 - $HOUSE_CUT) - 10000, 0); |
| 575 | }", |
| 576 | "messages": [ |
| 577 | { |
| 578 | "if": "{$NFT.by != $NFT.author}", |
| 579 | "app": "payment", |
| 580 | "payload": { |
| 581 | "asset": "base", |
| 582 | "outputs": [ |
| 583 | { |
| 584 | "if": "{ |
| 585 | $sellerPayout > 0 |
| 586 | AND $NFT.soldBy != $NFT.by |
| 587 | }", |
| 588 | "address": "{$NFT.soldBy}", |
| 589 | "amount": "{$sellerPayout}" |
| 590 | } |
| 591 | ] |
| 592 | } |
| 593 | }, |
| 594 | { |
| 595 | "app": "payment", |
| 596 | "payload": { |
| 597 | "asset": "{trigger.data['NFT']}", |
| 598 | "outputs": [ |
| 599 | { |
| 600 | "address": "{$NFT.by}", |
| 601 | "amount": 1 |
| 602 | } |
| 603 | ] |
| 604 | } |
| 605 | }, |
| 606 | { |
| 607 | "app": "state", |
| 608 | "state": "{ |
| 609 | if ($NFT.bids > 0) |
| 610 | var["locked"] -= $NFT.bid; |
| 611 | |
| 612 | if (var["FREE_" || trigger.data["NFT"]]) |
| 613 | var["FREE_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 614 | else |
| 615 | var["NFT_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 616 | }" |
| 617 | } |
| 618 | ] |
| 619 | }, |
| 620 | { |
| 621 | "messages": [ |
| 622 | { |
| 623 | "app": "payment", |
| 624 | "if": "{ |
| 625 | $NFT.soldBy != $NFT.by |
| 626 | }", |
| 627 | "init": "{ |
| 628 | $share = $NFT.bid * (1 - $HOUSE_CUT); |
| 629 | response["entra"] = true; |
| 630 | if ($NFT.royalty > 0 AND $NFT.soldBy != $NFT.by){ |
| 631 | $royalty = $share * $NFT.royalty / 100; |
| 632 | $outputs = [ |
| 633 | { |
| 634 | address: $NFT.author, |
| 635 | amount: floor($royalty, 0) |
| 636 | }, |
| 637 | { |
| 638 | address: $NFT.soldBy, |
| 639 | amount: floor($share - $royalty, 0) |
| 640 | } |
| 641 | ]; |
| 642 | } |
| 643 | else{ |
| 644 | $outputs = [ |
| 645 | { |
| 646 | address: $NFT.soldBy, |
| 647 | amount: floor($share, 0) |
| 648 | } |
| 649 | ]; |
| 650 | } |
| 651 | $payload = {outputs: $outputs}; |
| 652 | }", |
| 653 | "payload": "{$payload}" |
| 654 | }, |
| 655 | { |
| 656 | "app": "payment", |
| 657 | "payload": { |
| 658 | "asset": "{trigger.data['NFT']}", |
| 659 | "outputs": [ |
| 660 | { |
| 661 | "address": "{$NFT.by}", |
| 662 | "amount": 1 |
| 663 | } |
| 664 | ] |
| 665 | } |
| 666 | }, |
| 667 | { |
| 668 | "app": "state", |
| 669 | "state": "{ |
| 670 | if ($NFT.bids > 0) |
| 671 | var["locked"] -= $NFT.bid; |
| 672 | if (var["FREE_" || trigger.data["NFT"]]) |
| 673 | var["FREE_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 674 | else |
| 675 | var["NFT_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 676 | }" |
| 677 | } |
| 678 | ] |
| 679 | } |
| 680 | ] |
| 681 | } |
| 682 | } |
| 683 | ] |
| 684 | } |
| 685 | }, |
| 686 | { |
| 687 | "if": "{$method == "REDEEM"}", |
| 688 | "init": "{ |
| 689 | if (NOT exists(trigger.data["signed_message"])) |
| 690 | bounce("signed_message field is mandatory"); |
| 691 | if (NOT exists(trigger.data["authors"])) |
| 692 | bounce('authors field is mandatory'); |
| 693 | if (NOT exists(trigger.data["meta"])) |
| 694 | bounce("meta field is mandatory"); |
| 695 | |
| 696 | $spack = { |
| 697 | signed_message: trigger.data["signed_message"], |
| 698 | authors: trigger.data["authors"] |
| 699 | } || trigger.data["meta"]; |
| 700 | |
| 701 | if (NOT is_valid_signed_package($spack, $spack.authors[0]["address"])) |
| 702 | bounce("The signed message signature is invalid"); |
| 703 | if (NOT $spack.signed_message["serial"]) |
| 704 | bounce("The signed message does not contains a serial field"); |
| 705 | if (NOT $spack.signed_message["NFT"]) |
| 706 | bounce("The signer of this message did not include a NFT field"); |
| 707 | |
| 708 | |
| 709 | if (var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"])]) |
| 710 | bounce("That code was already redeemed"); |
| 711 | |
| 712 | $NFT = $saleInfo($spack.signed_message["NFT"]); |
| 713 | |
| 714 | if (NOT $NFT) |
| 715 | bounce("That NFT does not exist"); |
| 716 | |
| 717 | |
| 718 | if ($NFT.soldBy != $NFT.author) |
| 719 | bounce("You cannot claim an NFT that is not being sold by their author"); |
| 720 | |
| 721 | if ($NFT.author != $spack.authors[0]["address"]) |
| 722 | bounce("The signer of that message is not the author of that NFT"); |
| 723 | |
| 724 | |
| 725 | if (NOT $NFT.redeem) |
| 726 | bounce("That NFT is not redeemable"); |
| 727 | |
| 728 | |
| 729 | if ($spack.signed_message["expireDate"]) |
| 730 | if ($NFT.soldAt < timestamp OR $spack.signed_message["expireDate"] < timestamp) |
| 731 | bounce("That NFT is no longer claimable"); |
| 732 | |
| 733 | |
| 734 | if ($spack.signed_message["claimer"]) |
| 735 | if ($spack.signed_message["claimer"] != trigger.address) |
| 736 | bounce("You cannot claim that NFT from that address"); |
| 737 | |
| 738 | $signedAmount = $spack.signed_message["amount"] OTHERWISE 1; |
| 739 | |
| 740 | |
| 741 | if (NOT $NFT.cap){ |
| 742 | $amount = $signedAmount; |
| 743 | } |
| 744 | |
| 745 | else { |
| 746 | if ($NFT.unitsSold + $signedAmount > $NFT.cap) |
| 747 | $amount = $NFT.cap - $NFT.unitsSold; |
| 748 | else |
| 749 | $amount = $signedAmount; |
| 750 | } |
| 751 | |
| 752 | |
| 753 | if ($amount == 0) |
| 754 | bounce("All copies of that NFT have been already minted"); |
| 755 | }", |
| 756 | "messages": { |
| 757 | "cases": [ |
| 758 | { |
| 759 | "if": "{trigger.data["NFT"]}", |
| 760 | "messages": [ |
| 761 | { |
| 762 | "app": "state", |
| 763 | "state": "{ |
| 764 | if (var["FREE_" || trigger.data["NFT"]]) |
| 765 | var["FREE_" || trigger.data["NFT"]] ||= {lastBatchDate: timestamp}; |
| 766 | else |
| 767 | var["NFT_" || trigger.data["NFT"]] ||= {lastBatchDate: timestamp}; |
| 768 | }" |
| 769 | } |
| 770 | ] |
| 771 | }, |
| 772 | { |
| 773 | "messages": [ |
| 774 | { |
| 775 | "app": "payment", |
| 776 | "payload": { |
| 777 | "asset": "{$spack.signed_message["NFT"]}", |
| 778 | "outputs": [ |
| 779 | { |
| 780 | "address": "{trigger.address}", |
| 781 | "amount": "{$amount}" |
| 782 | } |
| 783 | ] |
| 784 | } |
| 785 | }, |
| 786 | { |
| 787 | "app": "state", |
| 788 | "state": "{ |
| 789 | if (var["FREE_" || $spack.signed_message["NFT"]]) |
| 790 | var["FREE_" || $spack.signed_message["NFT"]] ||= {unitsSold: $NFT.unitsSold + $amount}; |
| 791 | else |
| 792 | var["NFT_" || $spack.signed_message["NFT"]] ||= {unitsSold: $NFT.unitsSold + $amount}; |
| 793 | var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"], 'base64')] = true; |
| 794 | }" |
| 795 | } |
| 796 | ] |
| 797 | } |
| 798 | ] |
| 799 | } |
| 800 | }, |
| 801 | { |
| 802 | "if": "{$method == "SELL"}", |
| 803 | "init": "{ |
| 804 | |
| 805 | if (NOT exists(trigger.data["endTime"])) |
| 806 | bounce("endTime field is mandatory"); |
| 807 | if (trigger.data["endTime"] < timestamp) |
| 808 | bounce("You cannot set the end time in the past"); |
| 809 | if (trigger.data["endTime"] > timestamp + 2628000) |
| 810 | bounce("You cannot set the end time in more than 30 days"); |
| 811 | |
| 812 | if (NOT exists(trigger.data["initialPrice"])) |
| 813 | bounce("initialPrice field is mandatory"); |
| 814 | if (NOT is_valid_amount(trigger.data["initialPrice"])) |
| 815 | bounce("initialPrice must be a valid amount"); |
| 816 | if (trigger.data["initialPrice"] < 20000) |
| 817 | bounce("The minimum initialPrice is 20000 bytes"); |
| 818 | |
| 819 | |
| 820 | if (trigger.output[[asset!="base"]].asset == "ambigous") |
| 821 | bounce("You cannot send more than one NFT type at a time"); |
| 822 | |
| 823 | |
| 824 | $feedData = data_feed[[oracles=this_address, feed_name=trigger.output[[asset!="base"]].asset, ifnone="OK", ifseveral="last", type="string"]]; |
| 825 | |
| 826 | if ($feedData == "REVOKED") |
| 827 | bounce("We revoked the trading of that token probably due to copyright reasons"); |
| 828 | |
| 829 | $NFT = $saleInfo(trigger.output[[asset!="base"]].asset) OTHERWISE {}; |
| 830 | |
| 831 | if (NOT $NFT) |
| 832 | bounce("NFT not found"); |
| 833 | |
| 834 | if (trigger.output[[asset!="base"]].amount != 1) |
| 835 | bounce("You cannot auction more than 1 copy of an NFT at a time"); |
| 836 | |
| 837 | if ($NFT.soldAt >= timestamp) |
| 838 | bounce("A copy of that NFT is already being sold. The sale is expected to end at " || timestamp_to_string($NFT.soldAt) || " UTC but may be delayed depending on the number of bids"); |
| 839 | |
| 840 | if ($NFT.bid AND NOT $NFT.claimed) |
| 841 | bounce("That NFT was auctioned but the payment has not been claimed yet. You can force the seller to claim it."); |
| 842 | |
| 843 | }", |
| 844 | "messages": [ |
| 845 | { |
| 846 | "app": "state", |
| 847 | "state": "{ |
| 848 | $NFT.bid = trigger.data["initialPrice"]; |
| 849 | $NFT.bids = 0; |
| 850 | $NFT.by = trigger.address; |
| 851 | $NFT.soldBy = trigger.address; |
| 852 | $NFT.at = timestamp; |
| 853 | $NFT.claimed = false; |
| 854 | $NFT.soldAt = trigger.data["endTime"]; |
| 855 | if (var["FREE_" || trigger.output[[asset!="base"]].asset]) |
| 856 | var["FREE_" || trigger.output[[asset!="base"]].asset] = $stripToken($NFT) || {claimed: false}; |
| 857 | else |
| 858 | var["NFT_" || trigger.output[[asset!="base"]].asset] = $stripToken($NFT) || {claimed: false}; |
| 859 | }" |
| 860 | } |
| 861 | ] |
| 862 | }, |
| 863 | { |
| 864 | "if": "{$method == "CHANGE_PRICE"}", |
| 865 | "init": "{ |
| 866 | if (NOT trigger.data["NFT"]) |
| 867 | bounce("NFT field is mandatory"); |
| 868 | |
| 869 | $NFT = var["NFT_" || trigger.data["NFT"]]; |
| 870 | |
| 871 | if (NOT $NFT) |
| 872 | bounce("NFT not found"); |
| 873 | |
| 874 | if ($NFT.author != trigger.address) |
| 875 | bounce("You cannot change another person NFT's price"); |
| 876 | |
| 877 | if (NOT exists(trigger.data["price"])) |
| 878 | bounce("price field is mandatory"); |
| 879 | |
| 880 | if (NOT exists(trigger.data["currency"])){ |
| 881 | if (NOT is_integer(trigger.data["price"])) |
| 882 | bounce("price must be an integer"); |
| 883 | if (NOT is_valid_amount(trigger.data["price"])) |
| 884 | bounce("price is invalid"); |
| 885 | if (trigger.data["price"] < 20000) |
| 886 | bounce("The minimum price is 20000 bytes"); |
| 887 | } |
| 888 | else{ |
| 889 | if (NOT $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"])) |
| 890 | bounce("You cannot set the price in that currency"); |
| 891 | } |
| 892 | |
| 893 | if ($NFT.bid) |
| 894 | bounce("You cannot change an auction price!"); |
| 895 | }", |
| 896 | "messages": [ |
| 897 | { |
| 898 | "app": "state", |
| 899 | "state": "{ |
| 900 | var["NFT_" || trigger.data["NFT"]] ||= {price: trigger.data["price"], currency: trigger.data["currency"] OTHERWISE false}; |
| 901 | }" |
| 902 | } |
| 903 | ] |
| 904 | } |
| 905 | ] |
| 906 | } |
| 907 | } |
| 908 | ] |