| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/t1-arbitrage-governance.json", |
| 5 | "init": "{ |
| 6 | $challenging_period = params.challenging_period OTHERWISE 7*24*3600; |
| 7 | |
| 8 | |
| 9 | $freeze_period = params.freeze_period OTHERWISE 30*24*3600; |
| 10 | |
| 11 | $arb_aa = params.arb_aa; |
| 12 | if (!$arb_aa) |
| 13 | bounce("no arb_aa"); |
| 14 | |
| 15 | $asset = var[$arb_aa]['shares_asset']; |
| 16 | |
| 17 | $names = ['min_reserve_share', 'max_reserve_share', 'min_reserve_delta', 'triggerer_reward_share', 'investments_paused']; |
| 18 | |
| 19 | $is_allowed_name = $name => { |
| 20 | length(filter($names, 5, $n => $n == $name)) == 1 |
| 21 | }; |
| 22 | |
| 23 | }", |
| 24 | "messages": { |
| 25 | "cases": [ |
| 26 | { |
| 27 | "if": "{ trigger.data.name AND trigger.data.commit }", |
| 28 | "init": "{ |
| 29 | $name = trigger.data.name; |
| 30 | $leader = var['leader_' || $name]; |
| 31 | $current_value = var[$name]; |
| 32 | if (!exists($leader)) |
| 33 | bounce("no leader"); |
| 34 | if (exists($current_value) AND $leader == $current_value) |
| 35 | bounce("already equal to leader"); |
| 36 | if (var['challenging_period_start_ts_' || $name] + $challenging_period > timestamp) |
| 37 | bounce("challenging period not expired yet"); |
| 38 | }", |
| 39 | "messages": [ |
| 40 | { |
| 41 | "app": "payment", |
| 42 | "payload": { |
| 43 | "asset": "base", |
| 44 | "outputs": [ |
| 45 | { |
| 46 | "address": "{$arb_aa}", |
| 47 | "amount": 5000 |
| 48 | } |
| 49 | ] |
| 50 | } |
| 51 | }, |
| 52 | { |
| 53 | "app": "data", |
| 54 | "payload": { |
| 55 | "name": "{$name}", |
| 56 | "value": "{$leader}" |
| 57 | } |
| 58 | }, |
| 59 | { |
| 60 | "app": "state", |
| 61 | "state": "{ |
| 62 | var[$name] = $leader; |
| 63 | }" |
| 64 | } |
| 65 | ] |
| 66 | }, |
| 67 | { |
| 68 | "if": "{ trigger.data.name }", |
| 69 | "init": "{ |
| 70 | $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; |
| 71 | if (!$balance) |
| 72 | bounce("you have no deposited balance and cannot vote"); |
| 73 | $name = trigger.data.name; |
| 74 | $value = trigger.data.value; |
| 75 | if (!$is_allowed_name($name)) |
| 76 | bounce("unknown name: " || $name); |
| 77 | if (exists($value)){ |
| 78 | if ($name == 'min_reserve_share' AND !(typeof($value) == 'number' AND $value >= 0 AND $value < 1)) |
| 79 | bounce("invalid value"); |
| 80 | if ($name == 'max_reserve_share' AND !(typeof($value) == 'number' AND $value > 0 AND $value <= 1)) |
| 81 | bounce("invalid value"); |
| 82 | if ($name == 'triggerer_reward_share' AND !(typeof($value) == 'number' AND $value >= 0 AND $value <= 1)) |
| 83 | bounce("invalid value"); |
| 84 | if ($name == 'min_reserve_delta' AND !(is_integer($value) AND $value > 0)) |
| 85 | bounce("invalid value"); |
| 86 | if ($name == 'investments_paused' AND !($value == 0 OR $value == 1)) |
| 87 | bounce("invalid value"); |
| 88 | } |
| 89 | }", |
| 90 | "messages": [ |
| 91 | { |
| 92 | "app": "state", |
| 93 | "state": "{ |
| 94 | if (trigger.output[[asset=$asset]]) |
| 95 | var['balance_' || trigger.address] += trigger.output[[asset=$asset]]; |
| 96 | $prev_choice = var['choice_' || trigger.address || '_' || $name]; |
| 97 | $leader = var['leader_' || $name]; |
| 98 | if (exists($leader) AND exists($prev_choice) AND $prev_choice == $leader AND var['challenging_period_start_ts_' || $name] + $challenging_period + $freeze_period > timestamp) |
| 99 | bounce("you cannot change your vote yet"); |
| 100 | var['choice_' || trigger.address || '_' || $name] = $value; |
| 101 | if (exists($prev_choice)){ |
| 102 | var['support_' || $name || '_' || $prev_choice] -= var['support_' || $name || '_' || $prev_choice || '_' || trigger.address]; |
| 103 | var['support_' || $name || '_' || $prev_choice || '_' || trigger.address] = false; |
| 104 | } |
| 105 | if (exists($value)){ |
| 106 | var['support_' || $name || '_' || $value] += $balance; |
| 107 | var['support_' || $name || '_' || $value || '_' || trigger.address] = $balance; |
| 108 | if (!exists($leader) OR var['support_' || $name || '_' || $value] > var['support_' || $name || '_' || $leader]){ |
| 109 | var['leader_' || $name] = $value; |
| 110 | var['challenging_period_start_ts_' || $name] = timestamp; |
| 111 | } |
| 112 | } |
| 113 | }" |
| 114 | } |
| 115 | ] |
| 116 | }, |
| 117 | { |
| 118 | "if": "{ trigger.data.withdraw }", |
| 119 | "init": "{ |
| 120 | $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; |
| 121 | if (!$balance) |
| 122 | bounce("you have no deposited balance and cannot withdraw"); |
| 123 | $amount = trigger.data.amount OTHERWISE $balance; |
| 124 | if ($amount > $balance) |
| 125 | bounce("your balance is only " || $balance); |
| 126 | foreach($names, 5, $name => { |
| 127 | if (var['choice_' || trigger.address || '_' || $name]) |
| 128 | bounce("support for " || $name || " not removed yet"); |
| 129 | }); |
| 130 | }", |
| 131 | "messages": [ |
| 132 | { |
| 133 | "app": "payment", |
| 134 | "payload": { |
| 135 | "asset": "{$asset}", |
| 136 | "outputs": [ |
| 137 | { |
| 138 | "address": "{trigger.address}", |
| 139 | "amount": "{ $amount }" |
| 140 | } |
| 141 | ] |
| 142 | } |
| 143 | }, |
| 144 | { |
| 145 | "app": "state", |
| 146 | "state": "{ |
| 147 | var['balance_' || trigger.address] -= $amount; |
| 148 | }" |
| 149 | } |
| 150 | ] |
| 151 | } |
| 152 | ] |
| 153 | } |
| 154 | } |
| 155 | ] |