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