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