| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/governance.json", |
| 5 | "init": "{ |
| 6 | $regular_challenging_period = params.regular_challenging_period OTHERWISE 3*24*3600; |
| 7 | $important_challenging_period = params.important_challenging_period OTHERWISE 30*24*3600; |
| 8 | |
| 9 | |
| 10 | $freeze_period = params.freeze_period OTHERWISE 30*24*3600; |
| 11 | |
| 12 | |
| 13 | $proposal_min_support = params.proposal_min_support OTHERWISE 0.5; |
| 14 | |
| 15 | $asset = params.asset; |
| 16 | if (!$asset) |
| 17 | bounce("no asset"); |
| 18 | |
| 19 | $curve_aa = params.curve_aa; |
| 20 | if (!$curve_aa) |
| 21 | bounce("no curve_aa"); |
| 22 | }", |
| 23 | "messages": { |
| 24 | "cases": [ |
| 25 | { |
| 26 | "if": "{ trigger.data.name AND trigger.data.commit }", |
| 27 | "init": "{ |
| 28 | $name = trigger.data.name; |
| 29 | $leader = var['leader_' || $name]; |
| 30 | $current_value = var[$name]; |
| 31 | if (!exists($leader)) |
| 32 | bounce("no leader"); |
| 33 | if (exists($current_value) AND $leader == $current_value) |
| 34 | bounce("already equal to leader"); |
| 35 | $challenging_period = ($name == 'oracle-feed') ? $important_challenging_period : $regular_challenging_period; |
| 36 | if (var['challenging_period_start_ts_' || $name] + $challenging_period > timestamp) |
| 37 | bounce("challenging period not expired yet"); |
| 38 | if ($name == 'proposal'){ |
| 39 | $expiry = var['proposal_' || $leader || '_expiry']; |
| 40 | if (parse_date($expiry) < timestamp) |
| 41 | bounce("the proposal has expired"); |
| 42 | if (var['proposal_' || $leader || '_approved']) |
| 43 | bounce("the proposal has already been approved"); |
| 44 | $support = var['support_' || $name || '_' || $leader]; |
| 45 | if ($support < var[$curve_aa]['supply1'] * $proposal_min_support) |
| 46 | bounce("not enough support for the proposal"); |
| 47 | } |
| 48 | }", |
| 49 | "messages": [ |
| 50 | { |
| 51 | "app": "payment", |
| 52 | "payload": { |
| 53 | "asset": "base", |
| 54 | "outputs": [ |
| 55 | { |
| 56 | "address": "{$curve_aa}", |
| 57 | "amount": 5000 |
| 58 | } |
| 59 | ] |
| 60 | } |
| 61 | }, |
| 62 | { |
| 63 | "if": "{$name != 'proposal'}", |
| 64 | "app": "data", |
| 65 | "payload": { |
| 66 | "name": "{$name}", |
| 67 | "value": "{$leader}" |
| 68 | } |
| 69 | }, |
| 70 | { |
| 71 | "if": "{$name == 'proposal'}", |
| 72 | "app": "data", |
| 73 | "payload": { |
| 74 | "grant": 1, |
| 75 | "recipient": "{var['proposal_' || $leader || '_recipient']}", |
| 76 | "amount": "{var['proposal_' || $leader || '_amount']}" |
| 77 | } |
| 78 | }, |
| 79 | { |
| 80 | "app": "state", |
| 81 | "state": "{ |
| 82 | if ($name != 'proposal') |
| 83 | var[$name] = $leader; |
| 84 | else |
| 85 | var['proposal_' || $leader || '_approved'] = 1; |
| 86 | }" |
| 87 | } |
| 88 | ] |
| 89 | }, |
| 90 | { |
| 91 | "if": "{ trigger.data.name }", |
| 92 | "init": "{ |
| 93 | $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; |
| 94 | if (!$balance) |
| 95 | bounce("you have no deposited balance and cannot vote"); |
| 96 | $name = trigger.data.name; |
| 97 | $value = trigger.data.value; |
| 98 | if ( |
| 99 | $name != 'fee_multiplier' AND |
| 100 | $name != 'moved_capacity_share' AND |
| 101 | $name != 'threshold_distance' AND |
| 102 | $name != 'move_capacity_timeout' AND |
| 103 | $name != 'slow_capacity_share' AND |
| 104 | $name != 'interest_rate' AND |
| 105 | $name != 'oracle-feed' AND |
| 106 | $name != 'proposal' |
| 107 | ) |
| 108 | bounce("unknown name: " || $name); |
| 109 | if (exists($value)){ |
| 110 | if ($name == 'fee_multiplier' AND !(typeof($value) == 'number' AND $value >= 1)) |
| 111 | bounce("invalid value"); |
| 112 | if ($name == 'moved_capacity_share' AND !(typeof($value) == 'number' AND $value > 0 AND $value <= 1)) |
| 113 | bounce("invalid value"); |
| 114 | if ($name == 'threshold_distance' AND !(typeof($value) == 'number' AND $value > 0 AND $value <= 0.2)) |
| 115 | bounce("invalid value"); |
| 116 | if ($name == 'move_capacity_timeout' AND !(is_integer($value) AND $value > 0)) |
| 117 | bounce("invalid value"); |
| 118 | if ($name == 'slow_capacity_share' AND !(typeof($value) == 'number' AND $value >= 0 AND $value <= 1)) |
| 119 | bounce("invalid value"); |
| 120 | if ($name == 'interest_rate' AND !(typeof($value) == 'number' AND $value >= 0)) |
| 121 | bounce("invalid value"); |
| 122 | if ($name == 'oracle-feed'){ |
| 123 | $oracle = substring($value, 0, 32); |
| 124 | if (!is_valid_address($oracle)) |
| 125 | bounce("invalid oracle address: " || $oracle); |
| 126 | $hyphen = substring($value, 32, 1); |
| 127 | if ($hyphen != '-') |
| 128 | bounce("invalid format of oracle-feed, should be oracle-feed_name"); |
| 129 | } |
| 130 | if ($name == 'proposal'){ |
| 131 | if (!(is_integer($value) AND $value > 0)) |
| 132 | bounce("invalid value"); |
| 133 | $expiry = var['proposal_' || $value || '_expiry']; |
| 134 | if (!$expiry) |
| 135 | bounce("no such proposal"); |
| 136 | if (parse_date($expiry) < timestamp) |
| 137 | bounce("the proposal has expired"); |
| 138 | if (var['proposal_' || $value || '_approved']) |
| 139 | bounce("the proposal has already been approved"); |
| 140 | } |
| 141 | } |
| 142 | }", |
| 143 | "messages": [ |
| 144 | { |
| 145 | "app": "state", |
| 146 | "state": "{ |
| 147 | if (trigger.output[[asset=$asset]]) |
| 148 | var['balance_' || trigger.address] += trigger.output[[asset=$asset]]; |
| 149 | $prev_choice = var['choice_' || trigger.address || '_' || $name]; |
| 150 | $leader = var['leader_' || $name]; |
| 151 | $challenging_period = ($name == 'oracle-feed') ? $important_challenging_period : $regular_challenging_period; |
| 152 | if (exists($leader) AND exists($prev_choice) AND $prev_choice == $leader AND var['challenging_period_start_ts_' || $name] + $challenging_period + $freeze_period > timestamp) |
| 153 | bounce("you cannot change your vote yet"); |
| 154 | var['choice_' || trigger.address || '_' || $name] = $value; |
| 155 | if (exists($prev_choice)){ |
| 156 | var['support_' || $name || '_' || $prev_choice] -= var['support_' || $name || '_' || $prev_choice || '_' || trigger.address]; |
| 157 | var['support_' || $name || '_' || $prev_choice || '_' || trigger.address] = false; |
| 158 | } |
| 159 | if (exists($value)){ |
| 160 | var['support_' || $name || '_' || $value] += $balance; |
| 161 | var['support_' || $name || '_' || $value || '_' || trigger.address] = $balance; |
| 162 | if (!exists($leader) OR var['support_' || $name || '_' || $value] > var['support_' || $name || '_' || $leader]){ |
| 163 | var['leader_' || $name] = $value; |
| 164 | var['challenging_period_start_ts_' || $name] = timestamp; |
| 165 | } |
| 166 | } |
| 167 | }" |
| 168 | } |
| 169 | ] |
| 170 | }, |
| 171 | { |
| 172 | "if": "{ trigger.data.withdraw }", |
| 173 | "init": "{ |
| 174 | $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; |
| 175 | if (!$balance) |
| 176 | bounce("you have no deposited balance and cannot withdraw"); |
| 177 | $amount = trigger.data.amount OTHERWISE $balance; |
| 178 | if ($amount > $balance) |
| 179 | bounce("your balance is only " || $balance); |
| 180 | if (var['choice_' || trigger.address || '_' || 'fee_multiplier']) |
| 181 | bounce("support for fee_multiplier not removed yet"); |
| 182 | if (var['choice_' || trigger.address || '_' || 'moved_capacity_share']) |
| 183 | bounce("support for moved_capacity_share not removed yet"); |
| 184 | if (var['choice_' || trigger.address || '_' || 'threshold_distance']) |
| 185 | bounce("support for threshold_distance not removed yet"); |
| 186 | if (var['choice_' || trigger.address || '_' || 'move_capacity_timeout']) |
| 187 | bounce("support for move_capacity_timeout not removed yet"); |
| 188 | if (var['choice_' || trigger.address || '_' || 'slow_capacity_share']) |
| 189 | bounce("support for slow_capacity_share not removed yet"); |
| 190 | if (var['choice_' || trigger.address || '_' || 'interest_rate']) |
| 191 | bounce("support for interest_rate not removed yet"); |
| 192 | if (var['choice_' || trigger.address || '_' || 'oracle-feed']) |
| 193 | bounce("support for oracle-feed not removed yet"); |
| 194 | if (var['choice_' || trigger.address || '_' || 'proposal']) |
| 195 | bounce("support for proposal not removed yet"); |
| 196 | }", |
| 197 | "messages": [ |
| 198 | { |
| 199 | "app": "payment", |
| 200 | "payload": { |
| 201 | "asset": "{$asset}", |
| 202 | "outputs": [ |
| 203 | { |
| 204 | "address": "{trigger.address}", |
| 205 | "amount": "{ $amount }" |
| 206 | } |
| 207 | ] |
| 208 | } |
| 209 | }, |
| 210 | { |
| 211 | "app": "state", |
| 212 | "state": "{ |
| 213 | var['balance_' || trigger.address] -= $amount; |
| 214 | }" |
| 215 | } |
| 216 | ] |
| 217 | }, |
| 218 | { |
| 219 | "if": "{ trigger.data.add_proposal AND trigger.data.type }", |
| 220 | "init": "{ |
| 221 | if (trigger.data.type != 'grant') |
| 222 | bounce("unrecognized proposal type"); |
| 223 | if (!is_valid_address(trigger.data.recipient)) |
| 224 | bounce("invalid grant recipient address"); |
| 225 | if (!is_integer(trigger.data.amount) OR trigger.data.amount <= 0) |
| 226 | bounce("invalid grant amount"); |
| 227 | if (!unit[trigger.data.unit]) |
| 228 | bounce("proposal unit not found"); |
| 229 | if (!trigger.data.expiry) |
| 230 | bounce("proposal expiry date not set"); |
| 231 | $expiry_ts = parse_date(trigger.data.expiry); |
| 232 | if (!$expiry_ts) |
| 233 | bounce("invalid expiry date"); |
| 234 | }", |
| 235 | "messages": [ |
| 236 | { |
| 237 | "app": "state", |
| 238 | "state": "{ |
| 239 | var['count_proposals'] += 1; |
| 240 | $num = var['count_proposals']; |
| 241 | var['proposal_' || $num || '_recipient'] = trigger.data.recipient; |
| 242 | var['proposal_' || $num || '_amount'] = trigger.data.amount; |
| 243 | var['proposal_' || $num || '_unit'] = trigger.data.unit; |
| 244 | var['proposal_' || $num || '_expiry'] = trigger.data.expiry; |
| 245 | }" |
| 246 | } |
| 247 | ] |
| 248 | } |
| 249 | ] |
| 250 | } |
| 251 | } |
| 252 | ] |