[
"autonomous agent",
{
"getters": "{
$getCreator = ()=>params.creator_address;
$getAsset = ()=>params.asset OTHERWISE "base";
$getPeriod = ()=>params.period OTHERWISE 24*60*60*30; //1m by default
$isPatronStale = ()=>{
$end = (NOT var["start"]) ? 0 : (var["start"] + $getPeriod());
return $end < timestamp;
};
$getStart = ()=>$isPatronStale() ? false : var["start"];
$getEnd = ()=>$getStart() + $getPeriod();
$getPatron = ()=>$isPatronStale() ? false : var["patron"];
$getIPFS = ()=>{
if ($isPatronStale())
return false;
return var["ipfs"];
};
$getMinBid = ()=>$isPatronStale() ? (params.asset == "base" OR NOT params.asset) ? 10000 : 1 : ceil(var["paid"] * 1.05);
$getToS = ()=>data_feed[[oracles=params.creator_address, feed_name=this_address || "_tos", ifnone=false]];
}",
"init": "{
require(trigger.data.ipfs, "IPFS field is mandatory");
require(is_valid_address(params.creator_address), "This smart contract setup failed. The creator address is invalid");
$ASSET = $getAsset();
require(asset[$ASSET].exists, "That smart contract setup failed. An unknown asset was set for payouts");
$CREATOR_ADDRESS = params.creator_address;
$PERIOD = $getPeriod();
$IS_PATRON_STALE = $isPatronStale();
$CT_CUT = 0.02;
$CT_ADDRESS = "
HMFR76BEZXV5T7X4QVWXFKADT73DKS2G";
$LAST_PAID = var["paid"];
$CURRENT_PATRON = var["patron"];
$END = $getEnd();
$START = $getStart();
$paid = $ASSET == 'base' ? balance[base] - 4000 : trigger.output[[asset=$ASSET]].amount;
if (NOT $IS_PATRON_STALE) //Check if they can outright kick the current patron
require(trigger.output[[asset=$ASSET]].amount >= $LAST_PAID * 1.05, "You have to pay at least 5% more than the current patron");
$elapsed = $IS_PATRON_STALE ? 1 : 1 - ($END - timestamp) / ($END - $START);
$usage = $IS_PATRON_STALE ? 0 : floor($elapsed * $LAST_PAID);
$to_creator = ($IS_PATRON_STALE ? $paid : $paid - ($paid - $usage)) * (1-$CT_CUT);
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$ASSET}",
"outputs": [
{
"if": "{NOT $IS_PATRON_STALE}",
"address": "{$CURRENT_PATRON}",
"amount": "{max($LAST_PAID - $usage, 0)}"
},
{
"address": "{$CREATOR_ADDRESS}",
"amount": "{max(floor($to_creator), 0)}"
},
{
"address": "{$CT_ADDRESS}",
"amount": "{floor($paid * $CT_CUT)}"
}
]
}
},
{
"app": "state",
"state": "{
//Update current patron data
var["whois"] = trigger.data.whois;
var["start"] = timestamp;
var["end"] = timestamp + $PERIOD;
var["patron"] = trigger.data["patron"] OTHERWISE trigger.address;
var["paid"] = trigger.output[[asset=$ASSET]].amount;
var["ipfs"] = trigger.data["ipfs"];
var["earnings"]+= floor($to_creator);
}"
}
]
}
]