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