[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{\r
$HOUSE_CUT = 0.1; //We will take this cut on the debut of an NFT in our platform\r
$ARTIST_CUT = 0.01; //The artist will get this cut from every resale of their NFT\r
if (NOT exists(trigger.data["method"]))\r
bounce("method field is mandatory");\r
}",
"getters": "{\r
$tokenInfo = $NFT => data_feed[[oracles=this_address, feed_name=$NFT]] || {isBanned: in_data_feed[[oracles=this_address, feed_name="REVOCATIONS", feed_value=$NFT]]};\r
}",
"messages": {
"cases": [
{
"if": "{\r
NOT var["owner"] //The owner has not been set\r
}",
"messages": [
{
"app": "state",
"state": "{\r
var["owner"] = "
IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; //Set the Owner to my address\r
}"
}
]
},
{
"if": "{\r
trigger.address == var["owner"]\r
}",
"init": "{\r
if (NOT exists(trigger.data["method"]))\r
bounce("method field is mandatory");\r
}",
"messages": {
"cases": [
{
"if": "{\r
trigger.data["method"] == "mint"\r
}",
"init": "{\r
if (NOT exists(trigger.data["amount"]))\r
bounce("amount field is mandatory");\r
if (NOT is_valid_amount(trigger.data["amount"]))\r
bounce("The amount of NFT copies to mint is not valid");\r
if (NOT exists(trigger.data["ipfs"]))\r
bounce("ipfs field is mandatory");\r
if (NOT exists(trigger.data["seller"]))\r
bounce("seller field is mandatory");\r
if (NOT is_valid_address(trigger.data["seller"]))\r
bounce("The seller address is not valid");\r
if (NOT exists(trigger.data["endTime"]))\r
bounce("endTime field is mandatory");\r
if (NOT is_integer(trigger.data["endTime"]))\r
bounce("endTime field is not a timestamp");\r
if (trigger.data["endTime"] <= timestamp)\r
bounce("The endTime cannot be set in the past");\r
if (trigger.data["endTime"] - timestamp > 2628000)\r
bounce("You cannot set the end time in more than 30 days");\r
}",
"messages": {
"cases": [
{
"if": "{\r
trigger.data["amount"] == 1\r
}",
"messages": [
{
"app": "asset",
"payload": {
"cap": 1,
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{\r
var[response_unit] = {\r
bid: 0, //Max current bid (a NFT can have this field because it was resold. Check for price field instead)\r
by: trigger.data["seller"],\r
at: timestamp, //Max bid time\r
mintedAt: timestamp, //Mint date\r
ipfs: trigger.data["ipfs"], //Hash of the content\r
author: trigger.data["seller"], //The original seller\r
soldAt: trigger.data["endTime"], //End of the auction\r
soldBy: trigger.data["seller"] //Who is currently selling the NFT\r
};\r
}"
}
]
},
{
"init": "{\r
if (NOT exists(trigger.data["price"]))\r
bounce("price field is mandatory if you intend to sell more than one NFT copy");\r
if (trigger.data["price"] < 20000)\r
bounce("The minium price is 20000 bytes");\r
if (NOT is_valid_amount(trigger.data["price"]))\r
bounce("price is not valid");\r
}",
"messages": [
{
"app": "asset",
"payload": {
"cap": "{trigger.data["amount"]}",
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{\r
var[response_unit] = {\r
price: trigger.data["price"], //Sale price (this field is only present if the first sale was a fixed price one)\r
at: timestamp, //Max bid time\r
mintedAt: timestamp, //Mint date\r
ipfs: trigger.data["ipfs"], //Hash of the content\r
unitsSold: 0,\r
maxUnits: trigger.data["amount"],\r
author: trigger.data["seller"], //The original seller\r
soldAt: trigger.data["endTime"], //End of the auction\r
soldBy: trigger.data["seller"] //Who is currently selling the NFT\r
};\r
}"
}
]
}
]
}
},
{
"if": "{\r
trigger.data["method"] == "payout"\r
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
}
]
},
{
"if": "{\r
trigger.data["method"] == "revoke"\r
}",
"init": "{\r
if (NOT exists(trigger.data["NFT"]))\r
bounce("NFT field is mandatory");\r
}",
"messages": [
{
"app": "data_feed",
"payload": {
"{"REVOCATIONS"}": "{trigger.data["NFT"]}"
}
}
]
},
{
"if": "{\r
trigger.data["method"] == "transferOwnership"\r
}",
"init": "{\r
if (NOT exists(trigger.data["newOwner"]))\r
bounce("newOwner field is mandatory");\r
if (NOT is_valid_address(trigger.data["newOwner"]))\r
bounce("newOwner field is not a valid address");\r
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
},
{
"app": "state",
"state": "{\r
var["owner"] = trigger.data["newOwner"];//Ownership is transferred\r
}"
}
]
}
]
}
},
{
"if": "{\r
trigger.data["method"] == "BUY"\r
}",
"init": "{\r
if (NOT exists (trigger.data["NFT"]))\r
bounce("NFT field is mandatory");\r
\r
$NFT = var[trigger.data["NFT"]];\r
$isAuction = typeof($NFT.bid) == "number";\r
$hasBidders = (NOT $NFT.by)?false:($NFT.soldBy != $NFT.by);//Booleans cannot be compared\r
\r
if (NOT $NFT)\r
bounce("This NFT was not minted by us nor we listed it for sale");\r
\r
if (timestamp > $NFT.soldAt){\r
if ($isAuction){\r
if ($hasBidders) //You can still buy it if there were no bidders\r
bounce("The auction is over");\r
}\r
else\r
bounce("The auction is already over");\r
}\r
}",
"messages": {
"cases": [
{
"if": "{\r
$isAuction\r
}",
"init": "{\r
if (trigger.output[[asset=base]].amount < 20000)\r
bounce("The minimum bid is 20000 bytes");\r
if (trigger.output[[asset=base]].amount <= $NFT.bid)\r
bounce("Your bid is lower or equal to the last bid. You must increase it");\r
if ($NFT.soldBy == trigger.address)\r
bounce("You cannot bid on your own auction");\r
}",
"messages": [
{
"app": "payment",
"if": "{\r
$NFT.bid - 10000 > 0\r
}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$NFT.by}",
"amount": "{$NFT.bid - 10000}"
}
]
}
},
{
"app": "state",
"state": "{\r
$NFT.bid = trigger.output[[asset=base]].amount;\r
$NFT.by = trigger.address;\r
var[trigger.data["NFT"]] ||= $NFT;\r
}"
}
]
},
{
"init": "{\r
if (NOT asset[trigger.data["NFT"]].exists)\r
bounce("That asset does not exists");\r
if (asset[trigger.data["NFT"]].definer_address != this_address)\r
bounce("We have not listed that asset for sale");\r
if ($NFT.unitsSold == $NFT.maxUnits)\r
bounce("All NFT copies have been already sold");\r
if (trigger.output[[asset=base]].amount < $NFT.price)\r
bounce("Your payment is lower than the NFT price");\r
}",
"messages": [
{
"app": "payment",
"if": "{\r
floor($NFT.price * (1-$HOUSE_CUT) - 10000, 0) > 0\r
}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$NFT.soldBy}",
"amount": "{floor($NFT.price * (1-$HOUSE_CUT) - 10000, 0)}"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "{trigger.data['NFT']}",
"outputs": [
{
"address": "{trigger.address}",
"amount": 1
}
]
}
},
{
"app": "state",
"state": "{\r
var[trigger.data["NFT"]] ||= {unitsSold: $NFT.unitsSold + 1};\r
}"
}
]
}
]
}
},
{
"if": "{\r
trigger.data["method"] == "CLAIM"\r
}",
"init": "{\r
if (NOT exists(trigger.data["NFT"]))\r
bounce("NFT field is mandatory");\r
$NFT = var[trigger.data["NFT"]];\r
//Do NOT check for the NFT in the data_feed as it is not yet there\r
if (timestamp <= $NFT.soldAt)\r
bounce("The auction is not over yet");\r
}",
"messages": {
"cases": [
{
"if": "{//NFT was first sold\r
NOT in_data_feed[[oracles=this_address, feed_name=trigger.data['NFT'], feed_value=$NFT.ipfs]]\r
}",
"messages": [
{
"app": "payment",
"if": "{\r
floor($NFT.bid * (1-$HOUSE_CUT) - 10000, 0) > 0\r
}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$NFT.soldBy}",
"amount": "{floor($NFT.bid * (1-$HOUSE_CUT) - 10000, 0)}"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "{trigger.data['NFT']}",
"outputs": [
{
"address": "{$NFT.by}",
"amount": 1
}
]
}
},
{
"app": "data_feed",
"payload": {
"{trigger.data['NFT']}": "{$NFT.ipfs}"
}
}
]
},
{
"messages": [
{
"app": "payment",
"if": "{\r
$NFT.soldBy != $NFT.by //Do not pay if there were no bids as the seller would be stealing money from the contract\r
}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$NFT.soldBy}",
"amount": "{floor($NFT.bid * (1-$ARTIST_CUT) - 10000, 0)}"
}
]
}
},
{
"app": "payment",
"if": "{\r
floor($NFT.bid * $ARTIST_CUT, 0) - 10000 > 0\r
}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$NFT.author}",
"amount": "{floor($NFT.bid * $ARTIST_CUT, 0) - 10000}"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "{trigger.data['NFT']}",
"outputs": [
{
"address": "{$NFT.by}",
"amount": 1
}
]
}
}
]
}
]
}
},
{
"if": "{//[PUBLIC] Resell a NFT\r
trigger.data["method"] == "SELL"\r
}",
"init": "{\r
if (NOT var[trigger.output[[asset!=base]].asset])\r
bounce("You need to send an actual NFT but you are sending only bytes");\r
$NFT = var[trigger.output[[asset!=base]].asset];\r
if (NOT $NFT)\r
bounce("This NFT was not minted by us nor we listed it for sale");\r
if (trigger.output[[asset!=base]].amount!=1)\r
bounce("You cannot auction more than 1 copy of an NFT at a time");\r
if (in_data_feed[[oracles=this_address, feed_name="REVOCATIONS", feed_value=trigger.output[[asset!=base]].asset]])\r
bounce("We revoked the trading of that token probably due to copyright reasons");\r
if ($NFT.soldAt >= timestamp)\r
bounce("A copy of that NFT is already being auctioned. Please try again after " || timestamp_to_string($NFT.soldAt) || " UTC+0");\r
if (NOT is_valid_amount(trigger.data["initialPrice"]))\r
bounce("initialPrice must be a valid amount");\r
if (trigger.data["initialPrice"] < 20000)\r
bounce("The minimum initialPrice is 20000 bytes");\r
if (NOT exists(trigger.data["endTime"]))\r
bounce("endTime field is mandatory");\r
if (trigger.data["endTime"] < timestamp)\r
bounce("You cannot set the end time in the past");\r
if (trigger.data["endTime"] - timestamp > 2628000)\r
bounce("You cannot set the end time in more than 30 days");\r
}",
"messages": [
{
"app": "state",
"state": "{\r
$NFT.bid = trigger.data["initialPrice"];\r
$NFT.by = trigger.address;\r
$NFT.soldBy = trigger.address;\r
$NFT.at = timestamp;\r
$NFT.soldAt = trigger.data["endTime"];\r
var[trigger.output[[asset!=base]].asset] ||= $NFT;\r
}"
}
]
}
]
}
}
]