[
"autonomous agent",
{
"getters": "{
$isPatronStale = ()=>{
$end = var["end"];
return NOT $end OR $end < timestamp;
};
$getCreator = ()=>params.creator_address;
$getAsset = ()=>params.asset OTHERWISE "base";
$getMinPeriod = ()=>params.period OTHERWISE 24*60*60;
$getGas = ()=>$isPatronStale() ? 0 : var["gas"] OTHERWISE 0;
$getPatron = ()=>$isPatronStale() ? false : var["patron"];
$getStart = ()=>$isPatronStale() ? false : var["start"];
$getEnd = ()=>$isPatronStale() ? false : var["end"];
$getIPFS = ()=>{
if ($isPatronStale())
return false;
return var["ipfs"];
};
$getToS = ()=>$isPatronStale() ? false : data_feed[[oracles=params.creator_address, feed_name=this_address || "_tos", ifnone=false]];
}",
"init": "{
require(trigger.data.ipfs, "IPFS field is mandatory");
require(trigger.data.periods, "Periods field is mandatory");
require(is_valid_address(params.creator_address), "This smart contract setup failed. The creator address is invalid");
$ASSET = params.asset OTHERWISE "base";
require(asset[$ASSET].exists, "That smart contract setup failed. An unknown asset was set for payouts");
$CREATOR_ADDRESS = params.creator_address;
$PERIOD = params.period OTHERWISE 24*60*60; //1 day by default
$CT_CUT = 0.02;
$CT_ADDRESS = "
HMFR76BEZXV5T7X4QVWXFKADT73DKS2G";
$IS_PATRON_STALE = $isPatronStale();
$LAST_GAS = var["gas"] OTHERWISE 0; //Gas is measured in tokens/minute
$LAST_PAID = var["paid"];
$CURRENT_PATRON = var["patron"];
require(trigger.data.periods >= 1, "You have to sponsor the content creator for at least 1 period");
$periods = trigger.data.periods OTHERWISE 1;
$paid = $ASSET == 'base' ? trigger.output[[asset="base"]].amount - 5000 : trigger.output[[asset=$ASSET]].amount;
$gas = $paid/$PERIOD/$periods*60;
require($gas >= 0.000000001 * $PERIOD*60, "The minimum payment for a single period is " || 0.000000001 * $PERIOD * 60 || " bytes");
response["periods"] = trigger.data.periods;
response["gas"] = $gas;
if (NOT $IS_PATRON_STALE) //Check if they can outright kick the current patron
require($gas >= $LAST_GAS * 1.05, "You have to pay gas at least 5% higher than the current patron");
$elapsed = $IS_PATRON_STALE ? 1 : 1 - (var["end"] - timestamp) / (var["end"] - var["start"]);
$usage = $IS_PATRON_STALE ? 0 : floor($elapsed * $LAST_PAID);
$toCreator = ($IS_PATRON_STALE ? $paid : $paid - ($paid - $usage)) * (1-$CT_CUT);
$ct_cut = floor($toCreator * $CT_CUT);
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$ASSET}",
"outputs": [
{
"if": "{NOT $IS_PATRON_STALE}",
"address": "{$CURRENT_PATRON}",
"amount": "{$LAST_PAID - $usage}"
},
{
"address": "{$CREATOR_ADDRESS}",
"amount": "{$toCreator}"
},
{
"address": "{$CT_ADDRESS}",
"amount": "{max(balance["base"] - ($LAST_PAID - $usage) - $toCreator - 4000, 0)}"
}
]
}
},
{
"app": "state",
"state": "{
//Update current patron data
var["whois"] = trigger.data.whois;
var["start"] = timestamp;
var["end"] = floor(timestamp + $PERIOD * $periods);
var["patron"] = trigger.data["patron"] OTHERWISE trigger.address;
var["gas"] = $gas;
var["paid"] = $paid;
var["ipfs"] = trigger.data["ipfs"];
var["earnings"]+=$toCreator;
}"
}
]
}
]