[
"autonomous agent",
{
"doc_url": "https://ostable.org/t1-arbitrage-governance.json",
"init": "{
$challenging_period = params.challenging_period OTHERWISE 7*24*3600;
// one cannot withdraw for this period after voting for a winning value
$freeze_period = params.freeze_period OTHERWISE 30*24*3600;
$arb_aa = params.arb_aa;
if (!$arb_aa)
bounce("no arb_aa");
$asset = var[$arb_aa]['shares_asset'];
$names = ['min_reserve_share', 'max_reserve_share', 'min_reserve_delta', 'triggerer_reward_share', 'investments_paused'];
$is_allowed_name = $name => {
length(filter($names, 5, $n => $n == $name)) == 1
};
}",
"messages": {
"cases": [
{
"if": "{ trigger.data.name AND trigger.data.commit }",
"init": "{
$name = trigger.data.name;
$leader = var['leader_' || $name];
$current_value = var[$name];
if (!exists($leader)) // can be 0
bounce("no leader");
if (exists($current_value) AND $leader == $current_value)
bounce("already equal to leader");
if (var['challenging_period_start_ts_' || $name] + $challenging_period > timestamp)
bounce("challenging period not expired yet");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$arb_aa}",
"amount": 5000
}
]
}
},
{
"app": "data",
"payload": {
"name": "{$name}",
"value": "{$leader}"
}
},
{
"app": "state",
"state": "{
var[$name] = $leader;
}"
}
]
},
{
"if": "{ trigger.data.name }",
"init": "{
$balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]];
if (!$balance)
bounce("you have no deposited balance and cannot vote");
$name = trigger.data.name;
$value = trigger.data.value; // can be empty to remove one's vote
if (!$is_allowed_name($name))
bounce("unknown name: " || $name);
if (exists($value)){
if ($name == 'min_reserve_share' AND !(typeof($value) == 'number' AND $value >= 0 AND $value < 1))
bounce("invalid value");
if ($name == 'max_reserve_share' AND !(typeof($value) == 'number' AND $value > 0 AND $value <= 1)) // we don't prevent setting max < min but this can be easiliy undone and there is little point doing so
bounce("invalid value");
if ($name == 'triggerer_reward_share' AND !(typeof($value) == 'number' AND $value >= 0 AND $value <= 1))
bounce("invalid value");
if ($name == 'min_reserve_delta' AND !(is_integer($value) AND $value > 0))
bounce("invalid value");
if ($name == 'investments_paused' AND !($value == 0 OR $value == 1))
bounce("invalid value");
}
}",
"messages": [
{
"app": "state",
"state": "{
if (trigger.output[[asset=$asset]])
var['balance_' || trigger.address] += trigger.output[[asset=$asset]];
$prev_choice = var['choice_' || trigger.address || '_' || $name];
$leader = var['leader_' || $name];
if (exists($leader) AND exists($prev_choice) AND $prev_choice == $leader AND var['challenging_period_start_ts_' || $name] + $challenging_period + $freeze_period > timestamp)
bounce("you cannot change your vote yet");
var['choice_' || trigger.address || '_' || $name] = $value;
if (exists($prev_choice)){
var['support_' || $name || '_' || $prev_choice] -= var['support_' || $name || '_' || $prev_choice || '_' || trigger.address];
var['support_' || $name || '_' || $prev_choice || '_' || trigger.address] = false;
}
if (exists($value)){
var['support_' || $name || '_' || $value] += $balance;
var['support_' || $name || '_' || $value || '_' || trigger.address] = $balance;
if (!exists($leader) OR var['support_' || $name || '_' || $value] > var['support_' || $name || '_' || $leader]){
var['leader_' || $name] = $value;
var['challenging_period_start_ts_' || $name] = timestamp;
}
}
}"
}
]
},
{
"if": "{ trigger.data.withdraw }",
"init": "{
$balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]];
if (!$balance)
bounce("you have no deposited balance and cannot withdraw");
$amount = trigger.data.amount OTHERWISE $balance;
if ($amount > $balance)
bounce("your balance is only " || $balance);
foreach($names, 5, $name => {
if (var['choice_' || trigger.address || '_' || $name])
bounce("support for " || $name || " not removed yet");
});
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ $amount }"
}
]
}
},
{
"app": "state",
"state": "{
var['balance_' || trigger.address] -= $amount;
}"
}
]
}
]
}
}
]