| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/bonded-stablecoin-de-factory.json", |
| 5 | "init": "{ |
| 6 | $curve_base_aa = 'CD5DNSVS6ENG5UYILRPJPHAB3YXKA63W'; |
| 7 | $stable_base_aa = 'YXPLX6Q3HBBSH2K5HLYM45W7P7HFSEIN'; |
| 8 | }", |
| 9 | "messages": { |
| 10 | "cases": [ |
| 11 | { |
| 12 | "if": "{trigger.data.asset1 AND var['curve_' || trigger.address]}", |
| 13 | "init": "{ |
| 14 | $stable_aa = [ |
| 15 | 'autonomous agent', |
| 16 | { |
| 17 | base_aa: $stable_base_aa, |
| 18 | params: { |
| 19 | curve_aa: trigger.address |
| 20 | } |
| 21 | } |
| 22 | ]; |
| 23 | $stable_aa_address = chash160($stable_aa); |
| 24 | }", |
| 25 | "messages": [ |
| 26 | { |
| 27 | "app": "definition", |
| 28 | "payload": { |
| 29 | "definition": "{$stable_aa}" |
| 30 | } |
| 31 | }, |
| 32 | { |
| 33 | "app": "payment", |
| 34 | "payload": { |
| 35 | "asset": "base", |
| 36 | "outputs": [ |
| 37 | { |
| 38 | "address": "{ $stable_aa_address }", |
| 39 | "amount": 4000 |
| 40 | } |
| 41 | ] |
| 42 | } |
| 43 | }, |
| 44 | { |
| 45 | "app": "data", |
| 46 | "payload": { |
| 47 | "define": 1, |
| 48 | "factory": "{this_address}" |
| 49 | } |
| 50 | }, |
| 51 | { |
| 52 | "app": "state", |
| 53 | "state": "{ |
| 54 | $governance_aa_address = unit[trigger.unit].messages[[.app='definition']].payload.address; |
| 55 | var['asset_' || trigger.address || '_1'] = trigger.data.asset1; |
| 56 | var['asset_' || trigger.address || '_2'] = trigger.unit; |
| 57 | var['stable_aa_' || trigger.address] = $stable_aa_address; |
| 58 | var['governance_aa_' || trigger.address] = $governance_aa_address; |
| 59 | var['fund_aa_' || trigger.address] = var[trigger.address]['fund_aa']; |
| 60 | var['asset_' || trigger.address || '_fund'] = var[var[trigger.address]['fund_aa']]['shares_asset']; |
| 61 | response['asset_1'] = trigger.data.asset1; |
| 62 | response['asset_2'] = trigger.unit; |
| 63 | response['shares_asset'] = var[var[trigger.address]['fund_aa']]['shares_asset']; |
| 64 | response['address'] = trigger.address; |
| 65 | response['stable_aa'] = $stable_aa_address; |
| 66 | response['governance_aa'] = $governance_aa_address; |
| 67 | }" |
| 68 | } |
| 69 | ] |
| 70 | }, |
| 71 | { |
| 72 | "if": "{trigger.data.write_stable_asset AND var['stable_aa_' || trigger.data.curve_aa] == trigger.address}", |
| 73 | "messages": [ |
| 74 | { |
| 75 | "app": "state", |
| 76 | "state": "{ |
| 77 | var['asset_' || trigger.data.curve_aa || '_stable'] = trigger.unit; |
| 78 | }" |
| 79 | } |
| 80 | ] |
| 81 | }, |
| 82 | { |
| 83 | "init": "{ |
| 84 | $reserve_asset = trigger.data.reserve_asset OTHERWISE 'base'; |
| 85 | if (!asset[$reserve_asset].exists) |
| 86 | bounce("reserve asset " || $reserve_asset || " does not exist"); |
| 87 | |
| 88 | $reserve_asset_decimals = trigger.data.reserve_asset_decimals; |
| 89 | if (!is_integer($reserve_asset_decimals) OR $reserve_asset_decimals < 0 OR $reserve_asset_decimals > 14) |
| 90 | bounce("bad reserve_asset_decimals"); |
| 91 | |
| 92 | $decimals1 = trigger.data.decimals1; |
| 93 | if (!is_integer($decimals1) OR $decimals1 < 0 OR $decimals1 > 14) |
| 94 | bounce("bad decimals1"); |
| 95 | |
| 96 | $decimals2 = trigger.data.decimals2; |
| 97 | if (!is_integer($decimals2) OR $decimals2 < 0 OR $decimals2 > 14) |
| 98 | bounce("bad decimals2"); |
| 99 | |
| 100 | $m = trigger.data.m OTHERWISE 2; |
| 101 | if (typeof($m) != 'number' OR $m < 0) |
| 102 | bounce("bad m"); |
| 103 | |
| 104 | $n = trigger.data.n OTHERWISE 1/2; |
| 105 | if (typeof($n) != 'number' OR $n < 0) |
| 106 | bounce("bad n"); |
| 107 | |
| 108 | $leverage = trigger.data.leverage OTHERWISE 0; |
| 109 | if (typeof($leverage) != 'number') |
| 110 | bounce("bad leverage"); |
| 111 | |
| 112 | $interest_rate = trigger.data.interest_rate OTHERWISE 0; |
| 113 | if (typeof($interest_rate) != 'number' OR $interest_rate < 0) |
| 114 | bounce("bad interest_rate"); |
| 115 | |
| 116 | $fee_multiplier = trigger.data.fee_multiplier OTHERWISE 5; |
| 117 | if (typeof($fee_multiplier) != 'number' OR $fee_multiplier <= 0) |
| 118 | bounce("bad fee_multiplier"); |
| 119 | |
| 120 | $moved_capacity_share = trigger.data.moved_capacity_share OTHERWISE 0.1; |
| 121 | if (typeof($moved_capacity_share) != 'number' OR $moved_capacity_share <= 0) |
| 122 | bounce("bad moved_capacity_share"); |
| 123 | |
| 124 | $threshold_distance = trigger.data.threshold_distance OTHERWISE 0.01; |
| 125 | if (typeof($threshold_distance) != 'number' OR $threshold_distance <= 0) |
| 126 | bounce("bad threshold_distance"); |
| 127 | |
| 128 | $move_capacity_timeout = trigger.data.move_capacity_timeout OTHERWISE 2*3600; |
| 129 | if (!is_integer($move_capacity_timeout) OR $move_capacity_timeout <= 0) |
| 130 | bounce("bad move_capacity_timeout"); |
| 131 | |
| 132 | $slow_capacity_share = trigger.data.slow_capacity_share; |
| 133 | if (exists($slow_capacity_share) AND (typeof($slow_capacity_share) != 'number' OR $slow_capacity_share < 0)) |
| 134 | bounce("bad slow_capacity_share"); |
| 135 | |
| 136 | $params = { |
| 137 | leverage: $leverage, |
| 138 | m: $m, |
| 139 | n: $n, |
| 140 | allow_grants: !!trigger.data.allow_grants, |
| 141 | allow_oracle_change: !!trigger.data.allow_oracle_change, |
| 142 | reserve_asset: $reserve_asset, |
| 143 | reserve_asset_decimals: $reserve_asset_decimals, |
| 144 | decimals1: $decimals1, |
| 145 | decimals2: $decimals2, |
| 146 | interest_rate: $interest_rate, |
| 147 | fee_multiplier: $fee_multiplier, |
| 148 | moved_capacity_share: $moved_capacity_share, |
| 149 | threshold_distance: $threshold_distance, |
| 150 | move_capacity_timeout: $move_capacity_timeout, |
| 151 | slow_capacity_share: $slow_capacity_share, |
| 152 | }; |
| 153 | |
| 154 | foreach(['oracle1', 'oracle2', 'oracle3'], 3, $p => { |
| 155 | $oracle = trigger.data[$p]; |
| 156 | if (exists($oracle) AND !is_valid_address($oracle)) |
| 157 | bounce("bad " || $p); |
| 158 | $params[$p] = $oracle; |
| 159 | }); |
| 160 | foreach(['feed_name1', 'feed_name2', 'feed_name3'], 3, $p => { |
| 161 | $feed_name = trigger.data[$p]; |
| 162 | if (exists($feed_name) AND typeof($feed_name) != 'string') |
| 163 | bounce("bad " || $p); |
| 164 | $params[$p] = $feed_name; |
| 165 | }); |
| 166 | foreach(['op1', 'op2', 'op3'], 3, $p => { |
| 167 | $op = trigger.data[$p]; |
| 168 | if (exists($op) AND $op != '*' AND $op != '/') |
| 169 | bounce("bad " || $p); |
| 170 | $params[$p] = $op; |
| 171 | }); |
| 172 | |
| 173 | $governance_params = ['regular_challenging_period', 'important_challenging_period', 'freeze_period', 'proposal_min_support']; |
| 174 | foreach($governance_params, 4, $p => { |
| 175 | $value = trigger.data[$p]; |
| 176 | if (exists($value)) { |
| 177 | if ($p == 'proposal_min_support'){ |
| 178 | if (typeof($value) != 'number' OR $value < 0 OR $value > 1) |
| 179 | bounce("bad " || $p); |
| 180 | } |
| 181 | else { |
| 182 | if (!is_integer($value) OR $value < 0) |
| 183 | bounce("bad " || $p); |
| 184 | } |
| 185 | $params[$p] = $value; |
| 186 | } |
| 187 | }); |
| 188 | |
| 189 | $de_params = ['below_peg_threshold', 'below_peg_timeout', 'min_reserve_delta']; |
| 190 | foreach($de_params, 3, $p => { |
| 191 | $value = trigger.data[$p]; |
| 192 | if (exists($value)) { |
| 193 | if (typeof($value) != 'number' OR $value < 0) |
| 194 | bounce("bad " || $p); |
| 195 | if ($p == 'below_peg_threshold'){ |
| 196 | if ($value == 0) |
| 197 | bounce("bad " || $p); |
| 198 | } |
| 199 | else { |
| 200 | if (!is_integer($value)) |
| 201 | bounce("bad " || $p); |
| 202 | if ($p == 'min_reserve_delta'){ |
| 203 | if ($value == 0) |
| 204 | bounce("bad " || $p); |
| 205 | } |
| 206 | } |
| 207 | $params[$p] = $value; |
| 208 | } |
| 209 | }); |
| 210 | |
| 211 | $curve_aa = [ |
| 212 | 'autonomous agent', |
| 213 | { |
| 214 | base_aa: $curve_base_aa, |
| 215 | params: $params |
| 216 | } |
| 217 | ]; |
| 218 | $curve_aa_address = chash160($curve_aa); |
| 219 | }", |
| 220 | "messages": [ |
| 221 | { |
| 222 | "app": "payment", |
| 223 | "payload": { |
| 224 | "asset": "base", |
| 225 | "outputs": [ |
| 226 | { |
| 227 | "address": "{ $curve_aa_address }", |
| 228 | "amount": 8000 |
| 229 | } |
| 230 | ] |
| 231 | } |
| 232 | }, |
| 233 | { |
| 234 | "app": "data", |
| 235 | "payload": { |
| 236 | "define": 1, |
| 237 | "factory": "{this_address}" |
| 238 | } |
| 239 | }, |
| 240 | { |
| 241 | "app": "definition", |
| 242 | "payload": { |
| 243 | "definition": "{$curve_aa}" |
| 244 | } |
| 245 | }, |
| 246 | { |
| 247 | "app": "state", |
| 248 | "state": "{ |
| 249 | |
| 250 | var['curve_' || $curve_aa_address] = "s1^"||$m||" s2^"||$n; |
| 251 | }" |
| 252 | } |
| 253 | ] |
| 254 | } |
| 255 | ] |
| 256 | } |
| 257 | } |
| 258 | ] |