| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $HOUSE_CUT = 0.1; |
| 9 | $ARTIST_CUT = 0.01; |
| 10 | if (NOT exists(trigger.data["method"])) |
| 11 | bounce("method field is mandatory"); |
| 12 | }", |
| 13 | "getters": "{ |
| 14 | $tokenInfo = $NFT => data_feed[[oracles=this_address, feed_name=$NFT]] || {isBanned: in_data_feed[[oracles=this_address, feed_name="REVOCATIONS", feed_value=$NFT]]}; |
| 15 | }", |
| 16 | "messages": { |
| 17 | "cases": [ |
| 18 | { |
| 19 | "if": "{ |
| 20 | NOT var["owner"] |
| 21 | }", |
| 22 | "messages": [ |
| 23 | { |
| 24 | "app": "state", |
| 25 | "state": "{ |
| 26 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 27 | }" |
| 28 | } |
| 29 | ] |
| 30 | }, |
| 31 | { |
| 32 | "if": "{ |
| 33 | trigger.address == var["owner"] |
| 34 | }", |
| 35 | "init": "{ |
| 36 | if (NOT exists(trigger.data["method"])) |
| 37 | bounce("method field is mandatory"); |
| 38 | }", |
| 39 | "messages": { |
| 40 | "cases": [ |
| 41 | { |
| 42 | "if": "{ |
| 43 | trigger.data["method"] == "mint" |
| 44 | }", |
| 45 | "init": "{ |
| 46 | if (NOT exists(trigger.data["amount"])) |
| 47 | bounce("amount field is mandatory"); |
| 48 | if (NOT is_valid_amount(trigger.data["amount"])) |
| 49 | bounce("The amount of NFT copies to mint is not valid"); |
| 50 | if (NOT exists(trigger.data["ipfs"])) |
| 51 | bounce("ipfs field is mandatory"); |
| 52 | if (NOT exists(trigger.data["seller"])) |
| 53 | bounce("seller field is mandatory"); |
| 54 | if (NOT is_valid_address(trigger.data["seller"])) |
| 55 | bounce("The seller address is not valid"); |
| 56 | if (NOT exists(trigger.data["endTime"])) |
| 57 | bounce("endTime field is mandatory"); |
| 58 | if (NOT is_integer(trigger.data["endTime"])) |
| 59 | bounce("endTime field is not a timestamp"); |
| 60 | if (trigger.data["endTime"] <= timestamp) |
| 61 | bounce("The endTime cannot be set in the past"); |
| 62 | if (trigger.data["endTime"] - timestamp > 2628000) |
| 63 | bounce("You cannot set the end time in more than 30 days"); |
| 64 | }", |
| 65 | "messages": { |
| 66 | "cases": [ |
| 67 | { |
| 68 | "if": "{ |
| 69 | trigger.data["amount"] == 1 |
| 70 | }", |
| 71 | "messages": [ |
| 72 | { |
| 73 | "app": "asset", |
| 74 | "payload": { |
| 75 | "cap": 1, |
| 76 | "is_private": false, |
| 77 | "is_transferrable": true, |
| 78 | "auto_destroy": false, |
| 79 | "fixed_denominations": false, |
| 80 | "issued_by_definer_only": true, |
| 81 | "cosigned_by_definer": false, |
| 82 | "spender_attested": false |
| 83 | } |
| 84 | }, |
| 85 | { |
| 86 | "app": "state", |
| 87 | "state": "{ |
| 88 | var[response_unit] = { |
| 89 | bid: 0, |
| 90 | by: trigger.data["seller"], |
| 91 | at: timestamp, |
| 92 | mintedAt: timestamp, |
| 93 | ipfs: trigger.data["ipfs"], |
| 94 | author: trigger.data["seller"], |
| 95 | soldAt: trigger.data["endTime"], |
| 96 | soldBy: trigger.data["seller"] |
| 97 | }; |
| 98 | }" |
| 99 | } |
| 100 | ] |
| 101 | }, |
| 102 | { |
| 103 | "init": "{ |
| 104 | if (NOT exists(trigger.data["price"])) |
| 105 | bounce("price field is mandatory if you intend to sell more than one NFT copy"); |
| 106 | if (trigger.data["price"] < 20000) |
| 107 | bounce("The minium price is 20000 bytes"); |
| 108 | if (NOT is_valid_amount(trigger.data["price"])) |
| 109 | bounce("price is not valid"); |
| 110 | }", |
| 111 | "messages": [ |
| 112 | { |
| 113 | "app": "asset", |
| 114 | "payload": { |
| 115 | "cap": "{trigger.data["amount"]}", |
| 116 | "is_private": false, |
| 117 | "is_transferrable": true, |
| 118 | "auto_destroy": false, |
| 119 | "fixed_denominations": false, |
| 120 | "issued_by_definer_only": true, |
| 121 | "cosigned_by_definer": false, |
| 122 | "spender_attested": false |
| 123 | } |
| 124 | }, |
| 125 | { |
| 126 | "app": "state", |
| 127 | "state": "{ |
| 128 | var[response_unit] = { |
| 129 | price: trigger.data["price"], |
| 130 | at: timestamp, |
| 131 | mintedAt: timestamp, |
| 132 | ipfs: trigger.data["ipfs"], |
| 133 | unitsSold: 0, |
| 134 | author: trigger.data["seller"], |
| 135 | soldAt: trigger.data["endTime"], |
| 136 | soldBy: trigger.data["seller"] |
| 137 | }; |
| 138 | }" |
| 139 | } |
| 140 | ] |
| 141 | } |
| 142 | ] |
| 143 | } |
| 144 | }, |
| 145 | { |
| 146 | "if": "{ |
| 147 | trigger.data["method"] == "payout" |
| 148 | }", |
| 149 | "messages": [ |
| 150 | { |
| 151 | "app": "payment", |
| 152 | "payload": { |
| 153 | "asset": "base", |
| 154 | "outputs": [ |
| 155 | { |
| 156 | "address": "{trigger.address}" |
| 157 | } |
| 158 | ] |
| 159 | } |
| 160 | } |
| 161 | ] |
| 162 | }, |
| 163 | { |
| 164 | "if": "{ |
| 165 | trigger.data["method"] == "revoke" |
| 166 | }", |
| 167 | "init": "{ |
| 168 | if (NOT exists(trigger.data["NFT"])) |
| 169 | bounce("NFT field is mandatory"); |
| 170 | }", |
| 171 | "messages": [ |
| 172 | { |
| 173 | "app": "data_feed", |
| 174 | "payload": { |
| 175 | "{"REVOCATIONS"}": "{trigger.data["NFT"]}" |
| 176 | } |
| 177 | } |
| 178 | ] |
| 179 | }, |
| 180 | { |
| 181 | "if": "{ |
| 182 | trigger.data["method"] == "transferOwnership" |
| 183 | }", |
| 184 | "init": "{ |
| 185 | if (NOT exists(trigger.data["newOwner"])) |
| 186 | bounce("newOwner field is mandatory"); |
| 187 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 188 | bounce("newOwner field is not a valid address"); |
| 189 | }", |
| 190 | "messages": [ |
| 191 | { |
| 192 | "app": "payment", |
| 193 | "payload": { |
| 194 | "asset": "base", |
| 195 | "outputs": [ |
| 196 | { |
| 197 | "address": "{trigger.address}" |
| 198 | } |
| 199 | ] |
| 200 | } |
| 201 | }, |
| 202 | { |
| 203 | "app": "state", |
| 204 | "state": "{ |
| 205 | var["owner"] = trigger.data["newOwner"]; |
| 206 | }" |
| 207 | } |
| 208 | ] |
| 209 | } |
| 210 | ] |
| 211 | } |
| 212 | }, |
| 213 | { |
| 214 | "if": "{ |
| 215 | trigger.data["method"] == "BUY" |
| 216 | }", |
| 217 | "init": "{ |
| 218 | if (NOT exists (trigger.data["NFT"])) |
| 219 | bounce("NFT field is mandatory"); |
| 220 | |
| 221 | $NFT = var[trigger.data["NFT"]]; |
| 222 | $isAuction = typeof($NFT.bid) == "number"; |
| 223 | $hasBidders = (NOT $NFT.by)?false:($NFT.soldBy != $NFT.by); |
| 224 | |
| 225 | if (NOT $NFT) |
| 226 | bounce("This NFT was not minted by us nor we listed it for sale"); |
| 227 | |
| 228 | if (timestamp > $NFT.soldAt){ |
| 229 | if ($isAuction){ |
| 230 | if ($hasBidders) |
| 231 | bounce("The auction is over"); |
| 232 | } |
| 233 | else |
| 234 | bounce("The auction is already over"); |
| 235 | |
| 236 | } |
| 237 | }", |
| 238 | "messages": { |
| 239 | "cases": [ |
| 240 | { |
| 241 | "if": "{ |
| 242 | $isAuction |
| 243 | }", |
| 244 | "init": "{ |
| 245 | if (trigger.output[[asset=base]].amount < 20000) |
| 246 | bounce("The minimum bid is 20000 bytes"); |
| 247 | if (trigger.output[[asset=base]].amount <= $NFT.bid) |
| 248 | bounce("Your bid is lower or equal to the last bid. You must increase it"); |
| 249 | if ($NFT.soldBy == trigger.address) |
| 250 | bounce("You cannot bid on your own auction"); |
| 251 | }", |
| 252 | "messages": [ |
| 253 | { |
| 254 | "app": "payment", |
| 255 | "if": "{ |
| 256 | $NFT.bid - 10000 > 0 |
| 257 | }", |
| 258 | "payload": { |
| 259 | "asset": "base", |
| 260 | "outputs": [ |
| 261 | { |
| 262 | "address": "{$NFT.by}", |
| 263 | "amount": "{$NFT.bid - 10000}" |
| 264 | } |
| 265 | ] |
| 266 | } |
| 267 | }, |
| 268 | { |
| 269 | "app": "state", |
| 270 | "state": "{ |
| 271 | $NFT.bid = trigger.output[[asset=base]].amount; |
| 272 | $NFT.by = trigger.address; |
| 273 | var[trigger.data["NFT"]] ||= $NFT; |
| 274 | }" |
| 275 | } |
| 276 | ] |
| 277 | }, |
| 278 | { |
| 279 | "init": "{ |
| 280 | if (NOT asset[trigger.data["NFT"]].exists) |
| 281 | bounce("That asset does not exists"); |
| 282 | if (asset[trigger.data["NFT"]].definer_address != this_address) |
| 283 | bounce("We have not listed that asset for sale"); |
| 284 | if ($NFT.unitsSold == asset[trigger.data["NFT"]].cap) |
| 285 | bounce("All NFT copies have been already sold"); |
| 286 | if (trigger.output[[asset=base]].amount < $NFT.price) |
| 287 | bounce("Your payment is lower than the NFT price"); |
| 288 | }", |
| 289 | "messages": [ |
| 290 | { |
| 291 | "app": "payment", |
| 292 | "if": "{ |
| 293 | floor($NFT.price * (1-$HOUSE_CUT) - 10000, 0) > 0 |
| 294 | }", |
| 295 | "payload": { |
| 296 | "asset": "base", |
| 297 | "outputs": [ |
| 298 | { |
| 299 | "address": "{$NFT.soldBy}", |
| 300 | "amount": "{floor($NFT.price * (1-$HOUSE_CUT) - 10000, 0)}" |
| 301 | } |
| 302 | ] |
| 303 | } |
| 304 | }, |
| 305 | { |
| 306 | "app": "payment", |
| 307 | "payload": { |
| 308 | "asset": "{trigger.data['NFT']}", |
| 309 | "outputs": [ |
| 310 | { |
| 311 | "address": "{trigger.address}", |
| 312 | "amount": 1 |
| 313 | } |
| 314 | ] |
| 315 | } |
| 316 | }, |
| 317 | { |
| 318 | "app": "state", |
| 319 | "state": "{ |
| 320 | var[trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1}; |
| 321 | }" |
| 322 | } |
| 323 | ] |
| 324 | } |
| 325 | ] |
| 326 | } |
| 327 | }, |
| 328 | { |
| 329 | "if": "{ |
| 330 | trigger.data["method"] == "CLAIM" |
| 331 | }", |
| 332 | "init": "{ |
| 333 | if (NOT exists(trigger.data["NFT"])) |
| 334 | bounce("NFT field is mandatory"); |
| 335 | $NFT = var[trigger.data["NFT"]]; |
| 336 | |
| 337 | if (timestamp <= $NFT.soldAt) |
| 338 | bounce("The auction is not over yet"); |
| 339 | }", |
| 340 | "messages": { |
| 341 | "cases": [ |
| 342 | { |
| 343 | "if": "{ |
| 344 | NOT in_data_feed[[oracles=this_address, feed_name=trigger.data['NFT'], feed_value=$NFT.ipfs]] |
| 345 | }", |
| 346 | "messages": [ |
| 347 | { |
| 348 | "app": "payment", |
| 349 | "if": "{ |
| 350 | floor($NFT.bid * (1-$HOUSE_CUT) - 10000, 0) > 0 |
| 351 | }", |
| 352 | "payload": { |
| 353 | "asset": "base", |
| 354 | "outputs": [ |
| 355 | { |
| 356 | "address": "{$NFT.soldBy}", |
| 357 | "amount": "{floor($NFT.bid * (1-$HOUSE_CUT) - 10000, 0)}" |
| 358 | } |
| 359 | ] |
| 360 | } |
| 361 | }, |
| 362 | { |
| 363 | "app": "payment", |
| 364 | "payload": { |
| 365 | "asset": "{trigger.data['NFT']}", |
| 366 | "outputs": [ |
| 367 | { |
| 368 | "address": "{$NFT.by}", |
| 369 | "amount": 1 |
| 370 | } |
| 371 | ] |
| 372 | } |
| 373 | }, |
| 374 | { |
| 375 | "app": "data_feed", |
| 376 | "payload": { |
| 377 | "{trigger.data['NFT']}": "{$NFT.ipfs}" |
| 378 | } |
| 379 | } |
| 380 | ] |
| 381 | }, |
| 382 | { |
| 383 | "messages": [ |
| 384 | { |
| 385 | "app": "payment", |
| 386 | "if": "{ |
| 387 | $NFT.soldBy != $NFT.by |
| 388 | }", |
| 389 | "payload": { |
| 390 | "asset": "base", |
| 391 | "outputs": [ |
| 392 | { |
| 393 | "address": "{$NFT.soldBy}", |
| 394 | "amount": "{floor($NFT.bid * (1-$ARTIST_CUT) - 10000, 0)}" |
| 395 | } |
| 396 | ] |
| 397 | } |
| 398 | }, |
| 399 | { |
| 400 | "app": "payment", |
| 401 | "if": "{ |
| 402 | floor($NFT.bid * $ARTIST_CUT, 0) - 10000 > 0 |
| 403 | }", |
| 404 | "payload": { |
| 405 | "asset": "base", |
| 406 | "outputs": [ |
| 407 | { |
| 408 | "address": "{$NFT.author}", |
| 409 | "amount": "{floor($NFT.bid * $ARTIST_CUT, 0) - 10000}" |
| 410 | } |
| 411 | ] |
| 412 | } |
| 413 | }, |
| 414 | { |
| 415 | "app": "payment", |
| 416 | "payload": { |
| 417 | "asset": "{trigger.data['NFT']}", |
| 418 | "outputs": [ |
| 419 | { |
| 420 | "address": "{$NFT.by}", |
| 421 | "amount": 1 |
| 422 | } |
| 423 | ] |
| 424 | } |
| 425 | } |
| 426 | ] |
| 427 | } |
| 428 | ] |
| 429 | } |
| 430 | }, |
| 431 | { |
| 432 | "if": "{ |
| 433 | trigger.data["method"] == "SELL" |
| 434 | }", |
| 435 | "init": "{ |
| 436 | if (NOT var[trigger.output[[asset!=base]].asset]) |
| 437 | bounce("You need to send an actual NFT but you are sending only bytes"); |
| 438 | $NFT = var[trigger.output[[asset!=base]].asset]; |
| 439 | if (NOT $NFT) |
| 440 | bounce("This NFT was not minted by us nor we listed it for sale"); |
| 441 | if (trigger.output[[asset!=base]].amount!=1) |
| 442 | bounce("You cannot auction more than 1 copy of an NFT at a time"); |
| 443 | if (in_data_feed[[oracles=this_address, feed_name="REVOCATIONS", feed_value=trigger.output[[asset!=base]].asset]]) |
| 444 | bounce("We revoked the trading of that token probably due to copyright reasons"); |
| 445 | if ($NFT.soldAt >= timestamp) |
| 446 | bounce("A copy of that NFT is already being auctioned. Please try again after " || timestamp_to_string($NFT.soldAt) || " UTC+0"); |
| 447 | if (NOT is_valid_amount(trigger.data["initialPrice"])) |
| 448 | bounce("initialPrice must be a valid amount"); |
| 449 | if (trigger.data["initialPrice"] < 20000) |
| 450 | bounce("The minimum initialPrice is 20000 bytes"); |
| 451 | if (NOT exists(trigger.data["endTime"])) |
| 452 | bounce("endTime field is mandatory"); |
| 453 | if (trigger.data["endTime"] < timestamp) |
| 454 | bounce("You cannot set the end time in the past"); |
| 455 | if (trigger.data["endTime"] - timestamp > 2628000) |
| 456 | bounce("You cannot set the end time in more than 30 days"); |
| 457 | }", |
| 458 | "messages": [ |
| 459 | { |
| 460 | "app": "state", |
| 461 | "state": "{ |
| 462 | $NFT.bid = trigger.data["startingPrice"]; |
| 463 | $NFT.by = trigger.address; |
| 464 | $NFT.soldBy = trigger.address; |
| 465 | $NFT.at = timestamp; |
| 466 | $NFT.soldAt = trigger.data["endTime"]; |
| 467 | var[trigger.output[[asset!=base]].asset] ||= $NFT; |
| 468 | }" |
| 469 | } |
| 470 | ] |
| 471 | } |
| 472 | ] |
| 473 | } |
| 474 | } |
| 475 | ] |