| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $HOUSE_CUT = 0.1; |
| 9 | $FREEMARKET_CUT = 0.01; |
| 10 | $ARTIST_CUT = 0.01; |
| 11 | $INVESTMENT_CUT = 0.01; |
| 12 | $HALF_HOUR = 1800; |
| 13 | $RESERVE_AMOUNT = 200000; |
| 14 | $MIN_BID_INCREMENT = 0.0001; |
| 15 | $ONE_MONTH = 2592000; |
| 16 | $USER_REGISTRY_ADDRESS = "R75GUSXBH2OGYMXCM2AZ6L5CWHVLHZVF"; |
| 17 | $CURRENCY_REGISTRY = "JXBRQF274QMZ3K6K276RM35TI4UFQAUL"; |
| 18 | |
| 19 | $extendDeadLine = $NFT=>($NFT.soldAt <= timestamp + $HALF_HOUR) ? ($NFT || {soldAt: $NFT.soldAt + $HALF_HOUR}) : $NFT; |
| 20 | /* |
| 21 | ** Strips $NFT of computed fields to reduce AA's storage size |
| 22 | */ |
| 23 | $stripToken = $NFT=>{ |
| 24 | delete($NFT, "isBanned"); |
| 25 | delete($NFT, "cap"); |
| 26 | delete($NFT, "mintedAt"); |
| 27 | return $NFT; |
| 28 | }; |
| 29 | |
| 30 | if (NOT trigger.data["method"]) |
| 31 | bounce("method field is mandatory"); |
| 32 | |
| 33 | $method = trigger.data["method"]; |
| 34 | |
| 35 | $spendableFunds = balance["base"] - var["locked"] - storage_size - $RESERVE_AMOUNT; |
| 36 | $owner = var["owner"]; |
| 37 | $calculateSharesToBuy = ($price, $pool, $myShare)=>ln($price / ($pool * $myShare)) / ln($myShare); |
| 38 | $_maecenasCurve = $x=>6969420 * $x^2; |
| 39 | }", |
| 40 | "getters": "{ |
| 41 | $saleInfo = $NFT=>{ |
| 42 | $unit = unit[$NFT]; |
| 43 | $info = var["FREE_" || $NFT] OTHERWISE var["NFT_" || $NFT]; |
| 44 | |
| 45 | if (NOT $info) |
| 46 | bounce("That NFT is not for sale or does not exist"); |
| 47 | |
| 48 | return $info || { |
| 49 | cap: $unit.messages[[.app="asset"]]["payload"]["cap"], |
| 50 | mintedAt: $unit.timestamp |
| 51 | }; |
| 52 | }; |
| 53 | /* |
| 54 | ** Example of a meta getter to enable platform interop |
| 55 | */ |
| 56 | $getNFTInfo = $NFT=>{ |
| 57 | $unit = unit[$NFT]; |
| 58 | /* |
| 59 | ** Info should have at least 'author' field. 'ipfs' and 'type' field are also recommended. |
| 60 | */ |
| 61 | $info = var["FREE_" || $NFT] OTHERWISE var["NFT_" || $NFT]; |
| 62 | $transferrable = $unit.messages[[.app="asset"]]["payload"]["transferrable"]; |
| 63 | |
| 64 | return $info || { |
| 65 | cap: $unit.messages[[.app="asset"]]["payload"]["cap"], |
| 66 | mintedAt: $unit.timestamp, |
| 67 | transferrable: $transferrable |
| 68 | }; |
| 69 | }; |
| 70 | }", |
| 71 | "messages": { |
| 72 | "cases": [ |
| 73 | { |
| 74 | "if": "{ |
| 75 | NOT $owner |
| 76 | }", |
| 77 | "messages": [ |
| 78 | { |
| 79 | "app": "state", |
| 80 | "state": "{ |
| 81 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 82 | var["helper"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 83 | var["locked"] = 0; |
| 84 | }" |
| 85 | } |
| 86 | ] |
| 87 | }, |
| 88 | { |
| 89 | "if": "{ |
| 90 | trigger.address == $owner |
| 91 | AND ($method == "payout" |
| 92 | OR $method == "transferOwnership" |
| 93 | OR $method == "setHelper" |
| 94 | OR $method == "verifyProfile") |
| 95 | }", |
| 96 | "messages": { |
| 97 | "cases": [ |
| 98 | { |
| 99 | "if": "{ |
| 100 | $method == "payout" |
| 101 | }", |
| 102 | "messages": [ |
| 103 | { |
| 104 | "app": "payment", |
| 105 | "payload": { |
| 106 | "asset": "base", |
| 107 | "outputs": [ |
| 108 | { |
| 109 | "address": "{trigger.address}", |
| 110 | "amount": "{$spendableFunds}" |
| 111 | } |
| 112 | ] |
| 113 | } |
| 114 | } |
| 115 | ] |
| 116 | }, |
| 117 | { |
| 118 | "if": "{ |
| 119 | $method == "transferOwnership" |
| 120 | }", |
| 121 | "init": "{ |
| 122 | if (NOT trigger.data["newOwner"]) |
| 123 | bounce("newOwner field is mandatory"); |
| 124 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 125 | bounce("newOwner field is not a valid address"); |
| 126 | }", |
| 127 | "messages": [ |
| 128 | { |
| 129 | "app": "payment", |
| 130 | "payload": { |
| 131 | "asset": "base", |
| 132 | "outputs": [ |
| 133 | { |
| 134 | "address": "{trigger.address}", |
| 135 | "amount": "{$spendableFunds}" |
| 136 | } |
| 137 | ] |
| 138 | } |
| 139 | }, |
| 140 | { |
| 141 | "app": "state", |
| 142 | "state": "{ |
| 143 | var["owner"] = trigger.data["newOwner"]; |
| 144 | }" |
| 145 | } |
| 146 | ] |
| 147 | }, |
| 148 | { |
| 149 | "if": "{ |
| 150 | $method == "setHelper" |
| 151 | }", |
| 152 | "init": "{ |
| 153 | if (NOT trigger.data["helper"]) |
| 154 | bounce("helper field is mandatory"); |
| 155 | }", |
| 156 | "messages": [ |
| 157 | { |
| 158 | "app": "state", |
| 159 | "state": "{ |
| 160 | var["helper"] = trigger.data["helper"]; |
| 161 | }" |
| 162 | } |
| 163 | ] |
| 164 | } |
| 165 | ] |
| 166 | } |
| 167 | }, |
| 168 | { |
| 169 | "if": "{ |
| 170 | $method == "REGISTER" |
| 171 | }", |
| 172 | "init": "{ |
| 173 | if (NOT exists(trigger.data["NFT"])) |
| 174 | bounce("That NFT does not exist"); |
| 175 | |
| 176 | $definer = unit[trigger.data["NFT"]].authors[0]; |
| 177 | |
| 178 | if (NOT $definer) |
| 179 | bounce("NFT field is not a known asset"); |
| 180 | |
| 181 | $meta = var[$definer]["NFT"]; |
| 182 | |
| 183 | if (NOT $meta) |
| 184 | bounce("That NFT platform does not hold its metadata in a format compatible with ours"); |
| 185 | }", |
| 186 | "messages": [ |
| 187 | { |
| 188 | "app": "state", |
| 189 | "state": "{ |
| 190 | var["FREE_" || trigger.data["NFT"]] = $meta; |
| 191 | }" |
| 192 | } |
| 193 | ] |
| 194 | }, |
| 195 | { |
| 196 | "if": "{ |
| 197 | (trigger.address == $owner OR trigger.address == var["helper"]) |
| 198 | AND $method == "revoke" |
| 199 | }", |
| 200 | "init": "{ |
| 201 | if (NOT trigger.data["NFT"]) |
| 202 | bounce("NFT field is mandatory"); |
| 203 | }", |
| 204 | "messages": [ |
| 205 | { |
| 206 | "app": "data_feed", |
| 207 | "payload": { |
| 208 | "{trigger.data["NFT"]}": "REVOKED" |
| 209 | } |
| 210 | } |
| 211 | ] |
| 212 | }, |
| 213 | { |
| 214 | "if": "{ |
| 215 | $method == "MINT" |
| 216 | }", |
| 217 | "init": "{ |
| 218 | if (NOT trigger.data["amount"]) |
| 219 | bounce("amount field is mandatory"); |
| 220 | |
| 221 | if (NOT is_valid_amount(trigger.data["amount"]) AND trigger.data["amount"] != 0) |
| 222 | bounce("The amount of NFT copies to mint is not valid"); |
| 223 | |
| 224 | if (NOT trigger.data["type"]) |
| 225 | bounce("type field is mandatory"); |
| 226 | |
| 227 | if (trigger.data["endTime"]){ |
| 228 | if (trigger.data["endTime"] <= timestamp) |
| 229 | bounce("The endTime cannot be set in the past"); |
| 230 | } |
| 231 | |
| 232 | if ($owner != trigger.address){ |
| 233 | if (trigger.data["endTime"] - timestamp > 2628000) |
| 234 | bounce("You cannot set the end time in more than 30 days in the future"); |
| 235 | } |
| 236 | |
| 237 | if (NOT trigger.data["title"]) |
| 238 | bounce("title field is mandatory"); |
| 239 | |
| 240 | if (NOT trigger.data["ipfs"]) |
| 241 | bounce("ipfs field is mandatory"); |
| 242 | |
| 243 | if (trigger.data["royalty"]){ |
| 244 | if (NOT is_integer(trigger.data["royalty"])) |
| 245 | bounce("royalty must be an integer"); |
| 246 | if (trigger.data["royalty"] < 0 OR trigger.data["royalty"] > 40) |
| 247 | bounce("royalty must be in the interval 0-40"); |
| 248 | } |
| 249 | |
| 250 | if (exists(trigger.data["inflation"])){ |
| 251 | if (NOT exists(trigger.data["batchSize"])) |
| 252 | bounce("batchSize field is mandatory"); |
| 253 | if (NOT is_integer(trigger.data["batchSize"])) |
| 254 | bounce("batchSize must be integer"); |
| 255 | if (trigger.data["batchSize"] <= 0) |
| 256 | bounce("batchSize must be an extrictly positive integer"); |
| 257 | |
| 258 | $initialIssue = trigger.data["amount"] OTHERWISE 0; |
| 259 | |
| 260 | if (exists(trigger.data["cap"])){ |
| 261 | if (NOT is_integer(trigger.data["cap"])) |
| 262 | bounce("cap must be an integer"); |
| 263 | else if (trigger.data["cap"] <= 0) |
| 264 | bounce("cap must be a positive integer"); |
| 265 | else if (trigger.data["cap"] > 9e15) |
| 266 | bounce("cap must be at most 9e15"); |
| 267 | else if (NOT is_integer((trigger.data["cap"] - $initialIssue) / trigger.data["batchSize"])) |
| 268 | bounce("(cap - amount) / batchsize must be an integer"); |
| 269 | } |
| 270 | if (NOT exists(trigger.data["period"])) |
| 271 | bounce("period field is mandatory"); |
| 272 | if (NOT is_integer(trigger.data["period"])) |
| 273 | bounce("period must be an integer"); |
| 274 | if (trigger.data["period"] < 0) |
| 275 | bounce("period must be an extrictly positive integer"); |
| 276 | |
| 277 | |
| 278 | if (trigger.data["autoSell"]){ |
| 279 | if (trigger.data["batchSize"] > 1){ |
| 280 | if (NOT exists(trigger.data["mintPrice"])) |
| 281 | bounce("You cannot set autoSell without also setting mintPrice"); |
| 282 | if (exists(trigger.data["mintCurrency"])) |
| 283 | if (NOT $CURRENCY_REGISTRY.$getCurrency(trigger.data["mintCurrency"])) |
| 284 | bounce("That currency is not supported"); |
| 285 | } |
| 286 | |
| 287 | } |
| 288 | else { |
| 289 | if (exists(trigger.data["mintPrice"])) |
| 290 | bounce("You cannot set mintPrice without autoSell"); |
| 291 | if (exists(trigger.data["mintCurrency"])) |
| 292 | bounce("You cannot set mintCurrency without autoSell"); |
| 293 | } |
| 294 | |
| 295 | $supplyOpts = { |
| 296 | batchSize: trigger.data["batchSize"], |
| 297 | period: trigger.data["period"], |
| 298 | initialMint: trigger.data["amount"] OTHERWISE 0, |
| 299 | autoSell: trigger.data["autoSell"] ? true : false, |
| 300 | lastClaim: timestamp, |
| 301 | issueEpoch: 0, |
| 302 | mintPrice: trigger.data["mintPrice"] OTHERWISE false, |
| 303 | mintCurrency: trigger.data["mintCurrency"] OTHERWISE false |
| 304 | }; |
| 305 | } |
| 306 | |
| 307 | $seller = trigger.address == $owner |
| 308 | ? trigger.data["seller"] OTHERWISE trigger.address |
| 309 | : trigger.address; |
| 310 | |
| 311 | if (trigger.data["seller"] AND NOT is_valid_address(trigger.data["seller"])) |
| 312 | bounce("The seller address is not valid"); |
| 313 | |
| 314 | $prof = $USER_REGISTRY_ADDRESS.$profileOf($seller); |
| 315 | response["a1"] = $prof; |
| 316 | |
| 317 | $key = $prof.verified |
| 318 | ? "NFT_" |
| 319 | : "FREE_"; |
| 320 | }", |
| 321 | "messages": { |
| 322 | "cases": [ |
| 323 | { |
| 324 | "if": "{ |
| 325 | trigger.data["amount"] == 1 |
| 326 | }", |
| 327 | "messages": [ |
| 328 | { |
| 329 | "app": "asset", |
| 330 | "payload": { |
| 331 | "cap": 1, |
| 332 | "is_private": false, |
| 333 | "is_transferrable": true, |
| 334 | "auto_destroy": false, |
| 335 | "fixed_denominations": false, |
| 336 | "issued_by_definer_only": true, |
| 337 | "cosigned_by_definer": false, |
| 338 | "spender_attested": false |
| 339 | } |
| 340 | }, |
| 341 | { |
| 342 | "app": "data", |
| 343 | "if": "{ |
| 344 | var["recordToData"] |
| 345 | }", |
| 346 | "payload": { |
| 347 | "asset": "{var["recordToData"]}", |
| 348 | "name": "{trigger.data["title"] OTHERWISE "Untitled"}", |
| 349 | "author": "{$seller}", |
| 350 | "ipfs": "{trigger.data["ipfs"]}", |
| 351 | "type": "{trigger.data["type"]}", |
| 352 | "decimals": 0 |
| 353 | } |
| 354 | }, |
| 355 | { |
| 356 | "app": "state", |
| 357 | "state": "{ |
| 358 | var[$key || response_unit] = { |
| 359 | bid: 20000, |
| 360 | bids: 0, |
| 361 | type: trigger.data["type"], |
| 362 | by: $seller, |
| 363 | royalty: trigger.data["royalty"] OTHERWISE 0, |
| 364 | at: timestamp, |
| 365 | ipfs: trigger.data["ipfs"], |
| 366 | author: $seller, |
| 367 | soldAt: trigger.data["endTime"] OTHERWISE timestamp + $ONE_MONTH, |
| 368 | soldBy: $seller, |
| 369 | supplyOpts: $supplyOpts OTHERWISE false |
| 370 | }; |
| 371 | |
| 372 | var["recordToData"] = response_unit; |
| 373 | }" |
| 374 | } |
| 375 | ] |
| 376 | }, |
| 377 | { |
| 378 | "init": "{ |
| 379 | $price = trigger.data["price"]; |
| 380 | if (NOT $price) |
| 381 | bounce("price field is mandatory if you intend to sell more than one NFT copy"); |
| 382 | if ($price < 20000) |
| 383 | bounce("The minium price is 20000 bytes"); |
| 384 | if (NOT is_valid_amount($price)) |
| 385 | bounce("price is not valid"); |
| 386 | }", |
| 387 | "messages": [ |
| 388 | { |
| 389 | "app": "asset", |
| 390 | "if": "{ |
| 391 | trigger.data["amount"] == 0 |
| 392 | }", |
| 393 | "payload": { |
| 394 | "is_private": false, |
| 395 | "is_transferrable": true, |
| 396 | "auto_destroy": false, |
| 397 | "fixed_denominations": false, |
| 398 | "issued_by_definer_only": true, |
| 399 | "cosigned_by_definer": false, |
| 400 | "spender_attested": false |
| 401 | } |
| 402 | }, |
| 403 | { |
| 404 | "app": "asset", |
| 405 | "if": "{ |
| 406 | trigger.data["amount"] > 0 |
| 407 | }", |
| 408 | "payload": { |
| 409 | "cap": "{trigger.data["inflation"] ? trigger.data["cap"] OTHERWISE trigger.data["amount"] : trigger.data["amount"]}", |
| 410 | "is_private": false, |
| 411 | "is_transferrable": true, |
| 412 | "auto_destroy": false, |
| 413 | "fixed_denominations": false, |
| 414 | "issued_by_definer_only": true, |
| 415 | "cosigned_by_definer": false, |
| 416 | "spender_attested": false |
| 417 | } |
| 418 | }, |
| 419 | { |
| 420 | "app": "state", |
| 421 | "state": "{ |
| 422 | var[$key || response_unit] = { |
| 423 | price: $price, |
| 424 | type: trigger.data["type"], |
| 425 | at: timestamp, |
| 426 | royalty: trigger.data["royalty"] OTHERWISE 0, |
| 427 | ipfs: trigger.data["ipfs"], |
| 428 | unitsSold: 0, |
| 429 | author: $seller, |
| 430 | soldAt: trigger.data["endTime"] OTHERWISE timestamp + $ONE_MONTH, |
| 431 | soldBy: $seller, |
| 432 | redeem: trigger.data["redeem"] ? true : false, |
| 433 | supplyOpts: $supplyOpts OTHERWISE false |
| 434 | }; |
| 435 | }" |
| 436 | } |
| 437 | ] |
| 438 | } |
| 439 | ] |
| 440 | } |
| 441 | }, |
| 442 | { |
| 443 | "if": "{ |
| 444 | $method == "BUY" |
| 445 | OR $method == "CLAIM" |
| 446 | }", |
| 447 | "init": "{ |
| 448 | $NFT = $saleInfo(trigger.data["NFT"]); |
| 449 | |
| 450 | $artist = $USER_REGISTRY_ADDRESS.$artistInfoOf($NFT.author); |
| 451 | |
| 452 | |
| 453 | if ($method == "BUY"){ |
| 454 | if (NOT exists(trigger.data["NFT"])) |
| 455 | bounce("NFT field is mandatory"); |
| 456 | |
| 457 | |
| 458 | if ($NFT.supplyOpts){ |
| 459 | if ($NFT.unitsSold >= $NFT.supplyOpts["initialMint"] + $NFT.supplyOpts["period"] * $NFT.supplyOpts["issueEpoch"]){ |
| 460 | |
| 461 | if ($NFT.unitsSold == $NFT.supplyOpts["initialMint"] + $NFT.supplyOpts["batchSize"] * $NFT.supplyOpts["issueEpoch"]){ |
| 462 | if ($NFT.supplyOpts["autoSell"]){ |
| 463 | if ($NFT.supplyOpts["lastClaim"] > timestamp - $NFT.supplyOpts["period"]) |
| 464 | bounce("There are no copies of that NFT listed for sale"); |
| 465 | } |
| 466 | else{ |
| 467 | bounce("Only the issuer can redeem new copies"); |
| 468 | } |
| 469 | |
| 470 | } |
| 471 | else{ |
| 472 | if ($NFT.supplyOpts["mintCurrency"]) |
| 473 | $NFT.price = $CURRENCY_REGISTRY.$getExchangeRate($NFT.supplyOpts["currency"]) * $NFT.supplyOpts.mintPrice; |
| 474 | else |
| 475 | $NFT.price = $NFT.supplyOpts["mintPrice"]; |
| 476 | $isAuction = $NFT.supplyOpts["batchSize"] == 1 ? true : false; |
| 477 | } |
| 478 | } |
| 479 | else{ |
| 480 | $isInflationaryButSoldAsNormal = true; |
| 481 | } |
| 482 | } |
| 483 | else |
| 484 | $isAuction = $NFT.bid ? true : false; |
| 485 | |
| 486 | if ($isAuction) |
| 487 | $hasBidders = ($NFT.soldBy != $NFT.by) ? true : false; |
| 488 | |
| 489 | if ($isAuction AND NOT $NFT.by) |
| 490 | bounce("There are no copies of that NFT listed for sale at the moment"); |
| 491 | |
| 492 | if (NOT $NFT.supplyOpts OR $isInflationaryButSoldAsNormal){ |
| 493 | if (timestamp > $NFT.soldAt){ |
| 494 | if ($isAuction){ |
| 495 | if ($hasBidders) |
| 496 | bounce("The auction is over"); |
| 497 | } |
| 498 | else{ |
| 499 | bounce("The sale is already over"); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | else if ($method == "CLAIM"){ |
| 506 | if (NOT trigger.data["NFT"]) |
| 507 | bounce("NFT field is mandatory"); |
| 508 | |
| 509 | $isAuction = $NFT.bid ? true : false; |
| 510 | |
| 511 | if (NOT $isAuction) |
| 512 | bounce("You cannot claim a non-auction sale"); |
| 513 | |
| 514 | $hasBidders = ($NFT.soldBy != $NFT.by) ? true : false; |
| 515 | |
| 516 | if (timestamp <= $NFT.soldAt) |
| 517 | bounce("The auction is not over yet"); |
| 518 | |
| 519 | if ($NFT.claimed) |
| 520 | bounce("That auction was already claimed"); |
| 521 | } |
| 522 | |
| 523 | if ($artist AND (($isAuction AND $hasBidders) OR (NOT $isAuction))){ |
| 524 | $allowsMaecenas = ($artist.sharePercent >= 0.01) ? true : false; |
| 525 | $hasMaecenas = $allowsMaecenas |
| 526 | ? $artist.supply > 0 |
| 527 | ? true |
| 528 | : false |
| 529 | : false; |
| 530 | |
| 531 | |
| 532 | if ($allowsMaecenas){ |
| 533 | if ($method == "BUY") |
| 534 | $maecenasShare = floor($artist.sharePercent * trigger.output[[asset="base"]].amount, 0); |
| 535 | else if ($method == "CLAIM" AND $hasBidders) |
| 536 | $maecenasShare = floor($artist.sharePercent * $NFT.bid, 0); |
| 537 | else |
| 538 | $maecenasShare = 0; |
| 539 | |
| 540 | $sharesInThePool = ($method != "DIVEST") |
| 541 | ? $artist.supply |
| 542 | : ($artist.supply - trigger.data["amount"]); |
| 543 | |
| 544 | if ($method == "DIVEST") |
| 545 | $p = $artist.share - floor((trigger.data["amount"] / $artist.supply) * $artist.share, 0); |
| 546 | else |
| 547 | $p = $artist.share + $maecenasShare; |
| 548 | |
| 549 | $k = 1 / ($sharesInThePool + 1); |
| 550 | $price = $_maecenasCurve($sharesInThePool + 1); |
| 551 | |
| 552 | |
| 553 | if ($method == "BUY"){ |
| 554 | if ($NFT.soldBy == $NFT.author){ |
| 555 | $totalSpendable = floor( |
| 556 | $spendableFunds |
| 557 | + $price * $INVESTMENT_CUT |
| 558 | + floor(trigger.output[[asset="base"]].amount * $HOUSE_CUT, 0) |
| 559 | , 0); |
| 560 | } |
| 561 | else{ |
| 562 | $totalSpendable = floor( |
| 563 | $spendableFunds |
| 564 | + $price * $INVESTMENT_CUT |
| 565 | - trigger.output[[asset="base"]].amount |
| 566 | , 0); |
| 567 | } |
| 568 | } |
| 569 | else if ($method == "CLAIM"){ |
| 570 | $totalSpendable = floor( |
| 571 | $spendableFunds |
| 572 | + $price * $INVESTMENT_CUT |
| 573 | + $NFT.bid * (1 - $HOUSE_CUT) |
| 574 | , 0); |
| 575 | } |
| 576 | else{ |
| 577 | $totalSpendable = floor($spendableFunds + $price * $INVESTMENT_CUT, 0); |
| 578 | } |
| 579 | |
| 580 | $sharesToBuy = $sharesInThePool == 0 ? 0 : ceil($calculateSharesToBuy($price, $p, $k), 0); |
| 581 | |
| 582 | if ($k == 1){ |
| 583 | $sharesICanAfford = $price < $totalSpendable ? 1 : 0; |
| 584 | } |
| 585 | else { |
| 586 | if ($totalSpendable > $price AND $sharesToBuy >= 1){ |
| 587 | $sharesICanAfford = floor($totalSpendable / ($price * $sharesToBuy * (1 - $INVESTMENT_CUT)), 0); |
| 588 | } |
| 589 | else{ |
| 590 | $sharesICanAfford = 0; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if ($allowsMaecenas AND $sharesICanAfford > 0){ |
| 596 | $buyShares = true; |
| 597 | } |
| 598 | else{ |
| 599 | $buyShares = false; |
| 600 | } |
| 601 | |
| 602 | $shareIWillfinallyBuy = min($sharesToBuy, $sharesICanAfford); |
| 603 | $myProfit = floor($buyShares ? $p - $p * $k^$shareIWillfinallyBuy : 0, 0); |
| 604 | $poolFinalValue = $p - $myProfit; |
| 605 | } |
| 606 | else { |
| 607 | $allowsMaecenas = false; |
| 608 | $buyShares = false; |
| 609 | $hasMaecenas = false; |
| 610 | $maecenasShare = 0; |
| 611 | $myProfit = 0; |
| 612 | $poolFinalValue = 0; |
| 613 | } |
| 614 | }", |
| 615 | "messages": { |
| 616 | "cases": [ |
| 617 | { |
| 618 | "if": "{ |
| 619 | trigger.data["method"] == "BUY" |
| 620 | }", |
| 621 | "messages": { |
| 622 | "cases": [ |
| 623 | { |
| 624 | "if": "{ |
| 625 | $isAuction |
| 626 | }", |
| 627 | "init": "{ |
| 628 | if (trigger.output[[asset="base"]].amount < 20000) |
| 629 | bounce("The minimum bid is 20000 bytes"); |
| 630 | if (trigger.output[[asset="base"]].amount <= $NFT.bid * (1 + $MIN_BID_INCREMENT)) |
| 631 | bounce("Your bid must be at least " || $NFT.bid * (1 + $MIN_BID_INCREMENT) || " (0.01% higher than the current)"); |
| 632 | |
| 633 | if ($NFT.soldBy == trigger.address) |
| 634 | bounce("You cannot bid on your own auction"); |
| 635 | }", |
| 636 | "messages": [ |
| 637 | { |
| 638 | "app": "payment", |
| 639 | "if": "{ |
| 640 | $NFT.by != $NFT.soldBy |
| 641 | }", |
| 642 | "payload": { |
| 643 | "asset": "base", |
| 644 | "outputs": [ |
| 645 | { |
| 646 | "address": "{$NFT.by}", |
| 647 | "amount": "{$NFT.bid - 10000}" |
| 648 | } |
| 649 | ] |
| 650 | } |
| 651 | }, |
| 652 | { |
| 653 | "app": "state", |
| 654 | "state": "{ |
| 655 | var["locked"] += trigger.output[[asset="base"]].amount - ($hasBidders ? $NFT.bid : 0); |
| 656 | $NFT.bid = trigger.output[[asset="base"]].amount; |
| 657 | $NFT.at = timestamp; |
| 658 | $NFT.bids = $NFT.bids + 1; |
| 659 | $NFT.by = trigger.address; |
| 660 | if (var["FREE_" || trigger.data["NFT"]]) |
| 661 | var["FREE_" || trigger.data["NFT"]] ||= $stripToken($NFT); |
| 662 | else |
| 663 | var["NFT_" || trigger.data["NFT"]] ||= $stripToken($extendDeadLine($NFT)); |
| 664 | }" |
| 665 | } |
| 666 | ] |
| 667 | }, |
| 668 | { |
| 669 | "init": "{ |
| 670 | if ($NFT.unitsSold == $NFT.cap AND $NFT.cap != 0) |
| 671 | bounce("All NFT copies have been already sold"); |
| 672 | |
| 673 | if (trigger.output[[asset="base"]].amount < $NFT.price) |
| 674 | bounce("Your payment is lower than the NFT price. You have to send " || $NFT.price || " bytes"); |
| 675 | }", |
| 676 | "messages": [ |
| 677 | { |
| 678 | "app": "payment", |
| 679 | "if": "{ |
| 680 | floor($NFT.price * (1 - $HOUSE_CUT - ($allowsMaecenas ? (($hasMaecenas OR $buyShares) ? $artist.sharePercent : 0) : 0)) - 10000, 0) > 0 |
| 681 | }", |
| 682 | "payload": { |
| 683 | "asset": "base", |
| 684 | "outputs": { |
| 685 | "cases": [ |
| 686 | { |
| 687 | "if": "{ |
| 688 | $hasMaecenas |
| 689 | }", |
| 690 | "outputs": [ |
| 691 | { |
| 692 | "address": "{$NFT.soldBy}", |
| 693 | "amount": "{floor($NFT.price * (1 - $HOUSE_CUT - ($allowsMaecenas ? (($hasMaecenas OR $buyShares) ? $artist.sharePercent : 0) : 0)) - 10000, 0)}" |
| 694 | }, |
| 695 | { |
| 696 | "address": "{$USER_REGISTRY_ADDRESS}", |
| 697 | "amount": "{$poolFinalValue - $artist.share}" |
| 698 | } |
| 699 | ] |
| 700 | }, |
| 701 | { |
| 702 | "outputs": [ |
| 703 | { |
| 704 | "address": "{$NFT.soldBy}", |
| 705 | "amount": "{floor($NFT.price * (1 - $HOUSE_CUT - ($allowsMaecenas ? (($hasMaecenas OR $buyShares) ? $artist.sharePercent : 0) : 0)) - 10000, 0)}" |
| 706 | } |
| 707 | ] |
| 708 | } |
| 709 | ] |
| 710 | } |
| 711 | } |
| 712 | }, |
| 713 | { |
| 714 | "app": "payment", |
| 715 | "payload": { |
| 716 | "asset": "{trigger.data['NFT']}", |
| 717 | "outputs": [ |
| 718 | { |
| 719 | "address": "{trigger.address}", |
| 720 | "amount": 1 |
| 721 | } |
| 722 | ] |
| 723 | } |
| 724 | }, |
| 725 | { |
| 726 | "if": "{ |
| 727 | $hasMaecenas |
| 728 | }", |
| 729 | "app": "data", |
| 730 | "payload": { |
| 731 | "share": "{$poolFinalValue - $artist.share}" |
| 732 | } |
| 733 | }, |
| 734 | { |
| 735 | "app": "state", |
| 736 | "state": "{ |
| 737 | if ($NFT.soldBy == $NFT.author){ |
| 738 | if (var["FREE_" || trigger.data["NFT"]]) |
| 739 | var["FREE_" || trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1}; |
| 740 | else |
| 741 | var["NFT_" || trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1}; |
| 742 | |
| 743 | if ($NFT.unitsSold + 1 == $NFT.cap AND $NFT.cap != 0){ |
| 744 | if (var["FREE_" || trigger.data["NFT"]]) |
| 745 | var["FREE_" || trigger.data["NFT"]] ||= {bid: 0, price: false, soldAt: timestamp}; |
| 746 | else |
| 747 | var["NFT_" || trigger.data["NFT"]] ||= {bid: 0, price: false, soldAt: timestamp}; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | }" |
| 755 | } |
| 756 | ] |
| 757 | } |
| 758 | ] |
| 759 | } |
| 760 | }, |
| 761 | { |
| 762 | "if": "{ |
| 763 | trigger.data["method"] == "CLAIM" |
| 764 | }", |
| 765 | "messages": { |
| 766 | "cases": [ |
| 767 | { |
| 768 | "if": "{ |
| 769 | $NFT.soldBy == $NFT.author |
| 770 | }", |
| 771 | "init": "{ |
| 772 | if ($hasMaecenas OR $buyShares){ |
| 773 | $paymentFromShares = $shareIWillfinallyBuy * round($price * (1 - $INVESTMENT_CUT), 0); |
| 774 | $sellerPayout = floor($NFT.bid * (1 - $HOUSE_CUT - $artist.sharePercent) - 10000 + $paymentFromShares, 0); |
| 775 | } |
| 776 | else { |
| 777 | $sellerPayout = floor($NFT.bid * (1 - $HOUSE_CUT) - 10000, 0); |
| 778 | } |
| 779 | }", |
| 780 | "messages": [ |
| 781 | { |
| 782 | "app": "payment", |
| 783 | "if": "{ |
| 784 | $sellerPayout > 0 |
| 785 | AND $NFT.soldBy != $NFT.by |
| 786 | }", |
| 787 | "payload": { |
| 788 | "asset": "base", |
| 789 | "outputs": [ |
| 790 | { |
| 791 | "address": "{$NFT.soldBy}", |
| 792 | "amount": "{$sellerPayout}" |
| 793 | } |
| 794 | ] |
| 795 | } |
| 796 | }, |
| 797 | { |
| 798 | "app": "payment", |
| 799 | "payload": { |
| 800 | "asset": "{trigger.data['NFT']}", |
| 801 | "outputs": [ |
| 802 | { |
| 803 | "address": "{$NFT.by}", |
| 804 | "amount": 1 |
| 805 | } |
| 806 | ] |
| 807 | } |
| 808 | }, |
| 809 | { |
| 810 | "if": "{ |
| 811 | $hasMaecenas AND $NFT.bid > 20000 |
| 812 | }", |
| 813 | "app": "data", |
| 814 | "payload": { |
| 815 | "share": "{$maecenasShare}" |
| 816 | } |
| 817 | }, |
| 818 | { |
| 819 | "app": "state", |
| 820 | "state": "{ |
| 821 | $decrement = $hasMaecenas |
| 822 | ? $NFT.bid - $maecenasShare |
| 823 | : $NFT.bid; |
| 824 | |
| 825 | if ($NFT.bid > 20000) |
| 826 | var["locked"] -= $decrement; |
| 827 | |
| 828 | if (var["FREE_" || trigger.data["NFT"]]) |
| 829 | var["FREE_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 830 | else |
| 831 | var["NFT_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 832 | |
| 833 | |
| 834 | |
| 835 | }" |
| 836 | } |
| 837 | ] |
| 838 | }, |
| 839 | { |
| 840 | "messages": [ |
| 841 | { |
| 842 | "app": "payment", |
| 843 | "if": "{ |
| 844 | $NFT.soldBy != $NFT.by |
| 845 | }", |
| 846 | "init": "{ |
| 847 | $share = $NFT.bid * (1 - $HOUSE_CUT); |
| 848 | if ($NFT.royalty > 0 AND $NFT.soldBy != $NFT.by){ |
| 849 | $royalty = $share * $NFT.royalty / 100; |
| 850 | $outputs = [ |
| 851 | { |
| 852 | address: $NFT.author, |
| 853 | amount: floor($royalty, 0) |
| 854 | }, |
| 855 | { |
| 856 | address: $NFT.soldBy, |
| 857 | amount: floor($share - $royalty, 0) |
| 858 | } |
| 859 | ]; |
| 860 | } |
| 861 | else{ |
| 862 | $outputs = [ |
| 863 | { |
| 864 | address: $NFT.soldBy, |
| 865 | amount: floor($share, 0) |
| 866 | } |
| 867 | ]; |
| 868 | } |
| 869 | $payload = {outputs: $outputs}; |
| 870 | }", |
| 871 | "payload": "{$payload}" |
| 872 | }, |
| 873 | { |
| 874 | "app": "payment", |
| 875 | "payload": { |
| 876 | "asset": "{trigger.data['NFT']}", |
| 877 | "outputs": [ |
| 878 | { |
| 879 | "address": "{$NFT.by}", |
| 880 | "amount": 1 |
| 881 | } |
| 882 | ] |
| 883 | } |
| 884 | }, |
| 885 | { |
| 886 | "app": "state", |
| 887 | "state": "{ |
| 888 | var["locked"] -= $NFT.bid; |
| 889 | if (var["FREE_" || trigger.data["NFT"]]) |
| 890 | var["FREE_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 891 | else |
| 892 | var["NFT_" || trigger.data["NFT"]] ||= {claimed: true}; |
| 893 | }" |
| 894 | } |
| 895 | ] |
| 896 | } |
| 897 | ] |
| 898 | } |
| 899 | } |
| 900 | ] |
| 901 | } |
| 902 | }, |
| 903 | { |
| 904 | "if": "{ |
| 905 | $method == "REDEEM" |
| 906 | }", |
| 907 | "init": "{ |
| 908 | if (exists(trigger.data["NFT"])){ |
| 909 | $NFT = $saleInfo(trigger.data["NFT"]); |
| 910 | if ($NFT.author != trigger.address) |
| 911 | bounce("Only the NFT author can redeem the batch"); |
| 912 | if ($NFT.supplyOpts["autoSell"]) |
| 913 | bounce("You cannot redeem a batch that is supposed to be automatically listed for sale"); |
| 914 | if ($NFT.lastBatchDate > timestamp - $NFT.supplyOpts["period"]) |
| 915 | bounce("You cannot redeem a new batch batch yet"); |
| 916 | } |
| 917 | else{ |
| 918 | if (NOT exists(trigger.data["signed_message"])) |
| 919 | bounce("signed_message field is mandatory"); |
| 920 | if (NOT exists(trigger.data["authors"])) |
| 921 | bounce('authors field is mandatory'); |
| 922 | if (NOT exists(trigger.data["meta"])) |
| 923 | bounce("meta field is mandatory"); |
| 924 | |
| 925 | $spack = { |
| 926 | signed_message: trigger.data["signed_message"], |
| 927 | authors: trigger.data["authors"] |
| 928 | } || trigger.data["meta"]; |
| 929 | |
| 930 | if (NOT is_valid_signed_package($spack, $spack.authors[0]["address"])) |
| 931 | bounce("The signed message signature is invalid"); |
| 932 | if (NOT $spack.signed_message["serial"]) |
| 933 | bounce("The signed message does not contains a serial field"); |
| 934 | if (NOT $spack.signed_message["NFT"]) |
| 935 | bounce("The signer of this message did not include a NFT field"); |
| 936 | |
| 937 | |
| 938 | if (var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"])]) |
| 939 | bounce("That code was already redeemed"); |
| 940 | |
| 941 | $NFT = $saleInfo($spack.signed_message["NFT"]); |
| 942 | |
| 943 | if (NOT $NFT) |
| 944 | bounce("That NFT does not exist"); |
| 945 | |
| 946 | |
| 947 | if ($NFT.soldBy != $NFT.author) |
| 948 | bounce("You cannot claim an NFT that is not being sold by their author"); |
| 949 | |
| 950 | if ($NFT.author != $spack.authors[0]["address"]) |
| 951 | bounce("The signer of that message is not the author of that NFT"); |
| 952 | |
| 953 | |
| 954 | if (NOT $NFT.redeem) |
| 955 | bounce("That NFT is not redeemable"); |
| 956 | |
| 957 | |
| 958 | if ($spack.signed_message["expireDate"]) |
| 959 | if ($NFT.soldAt < timestamp OR $spack.signed_message["expireDate"] < timestamp) |
| 960 | bounce("That NFT is no longer claimable"); |
| 961 | |
| 962 | |
| 963 | if ($spack.signed_message["claimer"]) |
| 964 | if ($spack.signed_message["claimer"] != trigger.address) |
| 965 | bounce("You cannot claim that NFT from that address"); |
| 966 | |
| 967 | $signedAmount = $spack.signed_message["amount"] OTHERWISE 1; |
| 968 | |
| 969 | |
| 970 | if (NOT $NFT.cap){ |
| 971 | $amount = $signedAmount; |
| 972 | } |
| 973 | |
| 974 | else { |
| 975 | if ($NFT.unitsSold + $signedAmount > $NFT.cap) |
| 976 | $amount = $NFT.cap - $NFT.unitsSold; |
| 977 | else |
| 978 | $amount = $signedAmount; |
| 979 | } |
| 980 | |
| 981 | |
| 982 | if ($amount == 0) |
| 983 | bounce("All copies of that NFT have been already minted"); |
| 984 | } |
| 985 | }", |
| 986 | "messages": { |
| 987 | "cases": [ |
| 988 | { |
| 989 | "if": "{ |
| 990 | trigger.data["NFT"] |
| 991 | }", |
| 992 | "messages": [ |
| 993 | { |
| 994 | "app": "state", |
| 995 | "state": "{ |
| 996 | if (var["FREE_" || trigger.data["NFT"]]) |
| 997 | var["FREE_" || trigger.data["NFT"]] ||= {lastBatchDate: timestamp}; |
| 998 | else |
| 999 | var["NFT_" || trigger.data["NFT"]] ||= {lastBatchDate: timestamp}; |
| 1000 | }" |
| 1001 | } |
| 1002 | ] |
| 1003 | }, |
| 1004 | { |
| 1005 | "messages": [ |
| 1006 | { |
| 1007 | "app": "payment", |
| 1008 | "payload": { |
| 1009 | "asset": "{$spack.signed_message["NFT"]}", |
| 1010 | "outputs": [ |
| 1011 | { |
| 1012 | "address": "{trigger.address}", |
| 1013 | "amount": "{$amount}" |
| 1014 | } |
| 1015 | ] |
| 1016 | } |
| 1017 | }, |
| 1018 | { |
| 1019 | "app": "state", |
| 1020 | "state": "{ |
| 1021 | if (var["FREE_" || $spack.signed_message["NFT"]]) |
| 1022 | var["FREE_" || $spack.signed_message["NFT"]] ||= {unitsSold: $NFT.unitsSold + $amount}; |
| 1023 | else |
| 1024 | var["NFT_" || $spack.signed_message["NFT"]] ||= {unitsSold: $NFT.unitsSold + $amount}; |
| 1025 | var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"], 'base64')] = true; |
| 1026 | }" |
| 1027 | } |
| 1028 | ] |
| 1029 | } |
| 1030 | ] |
| 1031 | } |
| 1032 | }, |
| 1033 | { |
| 1034 | "if": "{ |
| 1035 | $method == "SELL" |
| 1036 | }", |
| 1037 | "init": "{ |
| 1038 | |
| 1039 | if (NOT exists(trigger.data["endTime"])) |
| 1040 | bounce("endTime field is mandatory"); |
| 1041 | if (trigger.data["endTime"] < timestamp) |
| 1042 | bounce("You cannot set the end time in the past"); |
| 1043 | if (trigger.data["endTime"] > timestamp + 2628000) |
| 1044 | bounce("You cannot set the end time in more than 30 days"); |
| 1045 | |
| 1046 | if (NOT exists(trigger.data["initialPrice"])) |
| 1047 | bounce("initialPrice field is mandatory"); |
| 1048 | if (NOT is_valid_amount(trigger.data["initialPrice"])) |
| 1049 | bounce("initialPrice must be a valid amount"); |
| 1050 | if (trigger.data["initialPrice"] < 20000) |
| 1051 | bounce("The minimum initialPrice is 20000 bytes"); |
| 1052 | |
| 1053 | |
| 1054 | if (trigger.output[[asset!="base"]].asset == "ambigous") |
| 1055 | bounce("You cannot send more than one NFT type at a time"); |
| 1056 | |
| 1057 | |
| 1058 | $feedData = data_feed[[oracles=this_address, feed_name=trigger.output[[asset!="base"]].asset, ifnone="OK", ifseveral="last", type="string"]]; |
| 1059 | |
| 1060 | if ($feedData == "REVOKED") |
| 1061 | bounce("We revoked the trading of that token probably due to copyright reasons"); |
| 1062 | |
| 1063 | $NFT = $saleInfo(trigger.output[[asset!="base"]].asset) OTHERWISE {}; |
| 1064 | |
| 1065 | if ($NFT.supplyOpts) |
| 1066 | bounce("You cannot resell inflationary supply NFTs here"); |
| 1067 | |
| 1068 | if (NOT $NFT) |
| 1069 | bounce("NFT not found"); |
| 1070 | |
| 1071 | if (trigger.output[[asset!="base"]].amount != 1) |
| 1072 | bounce("You cannot auction more than 1 copy of an NFT at a time"); |
| 1073 | |
| 1074 | if ($NFT.soldAt >= timestamp) |
| 1075 | 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"); |
| 1076 | |
| 1077 | if ($NFT.bid AND NOT $NFT.claimed) |
| 1078 | bounce("That NFT was auctioned but the payment has not been claimed yet. You can force the saller to claim it."); |
| 1079 | |
| 1080 | }", |
| 1081 | "messages": [ |
| 1082 | { |
| 1083 | "app": "state", |
| 1084 | "state": "{ |
| 1085 | $NFT.bid = trigger.data["initialPrice"]; |
| 1086 | $NFT.bids = 0; |
| 1087 | $NFT.by = trigger.address; |
| 1088 | $NFT.soldBy = trigger.address; |
| 1089 | $NFT.at = timestamp; |
| 1090 | $NFT.claimed = false; |
| 1091 | $NFT.soldAt = trigger.data["endTime"]; |
| 1092 | if (var["FREE_" || trigger.output[[asset!="base"]].asset]) |
| 1093 | var["FREE_" || trigger.output[[asset!="base"]].asset] = $stripToken($NFT) || {claimed: false}; |
| 1094 | else |
| 1095 | var["NFT_" || trigger.output[[asset!="base"]].asset] = $stripToken($NFT) || {claimed: false}; |
| 1096 | }" |
| 1097 | } |
| 1098 | ] |
| 1099 | }, |
| 1100 | { |
| 1101 | "if": "{ |
| 1102 | $method == "CHANGE_PRICE" |
| 1103 | }", |
| 1104 | "init": "{ |
| 1105 | if (NOT trigger.data["NFT"]) |
| 1106 | bounce("NFT field is mandatory"); |
| 1107 | |
| 1108 | $NFT = var["NFT_" || trigger.data["NFT"]]; |
| 1109 | |
| 1110 | if (NOT $NFT) |
| 1111 | bounce("NFT not found"); |
| 1112 | |
| 1113 | if (NOT trigger.data["price"]) |
| 1114 | bounce("price field is mandatory"); |
| 1115 | if (NOT is_integer(trigger.data["price"])) |
| 1116 | bounce("price must be an integer"); |
| 1117 | if (NOT is_valid_amount(trigger.data["price"])) |
| 1118 | bounce("price is invalid"); |
| 1119 | |
| 1120 | if (trigger.data["price"] < 20000) |
| 1121 | bounce("The minimum price is 20000 bytes"); |
| 1122 | |
| 1123 | if ($NFT.bid) |
| 1124 | bounce("You cannot change an auction price!"); |
| 1125 | }", |
| 1126 | "messages": [ |
| 1127 | { |
| 1128 | "app": "state", |
| 1129 | "state": "{ |
| 1130 | var["NFT_" || trigger.data["NFT"]] ||= {price: trigger.data["price"]}; |
| 1131 | }" |
| 1132 | } |
| 1133 | ] |
| 1134 | } |
| 1135 | ] |
| 1136 | } |
| 1137 | } |
| 1138 | ] |