| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/bonded-stablecoin-factory.json", |
| 5 | "init": "{ |
| 6 | $stablecoin_base_aa = '4J62LDAEKUEBKWY5OEO47PYCBXD27OKM'; |
| 7 | |
| 8 | $stablecoin_deposit_base_aa = 'EVRCLVU73XVSBIVLTWIIDHGEWBNLMTTL'; |
| 9 | }", |
| 10 | "messages": { |
| 11 | "cases": [ |
| 12 | { |
| 13 | "if": "{trigger.data.asset1 AND var['curve_' || trigger.address]}", |
| 14 | "init": "{ |
| 15 | $deposit_aa = [ |
| 16 | 'autonomous agent', |
| 17 | { |
| 18 | base_aa: $stablecoin_deposit_base_aa, |
| 19 | params: { |
| 20 | interest_asset: trigger.unit, |
| 21 | curve_aa: trigger.address |
| 22 | } |
| 23 | } |
| 24 | ]; |
| 25 | $deposit_aa_address = chash160($deposit_aa); |
| 26 | }", |
| 27 | "messages": [ |
| 28 | { |
| 29 | "app": "definition", |
| 30 | "payload": { |
| 31 | "definition": "{$deposit_aa}" |
| 32 | } |
| 33 | }, |
| 34 | { |
| 35 | "app": "payment", |
| 36 | "payload": { |
| 37 | "asset": "base", |
| 38 | "outputs": [ |
| 39 | { |
| 40 | "address": "{ $deposit_aa_address }", |
| 41 | "amount": 6000 |
| 42 | } |
| 43 | ] |
| 44 | } |
| 45 | }, |
| 46 | { |
| 47 | "app": "data", |
| 48 | "payload": { |
| 49 | "define": 1, |
| 50 | "factory": "{this_address}" |
| 51 | } |
| 52 | }, |
| 53 | { |
| 54 | "app": "state", |
| 55 | "state": "{ |
| 56 | var['asset_' || trigger.address || '_1'] = trigger.data.asset1; |
| 57 | var['asset_' || trigger.address || '_2'] = trigger.unit; |
| 58 | var['deposit_aa_' || trigger.address] = $deposit_aa_address; |
| 59 | var['governance_aa_' || trigger.address] = unit[trigger.unit].messages[[.app='definition']].payload.address; |
| 60 | }" |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | "if": "{trigger.data.write_stable_asset AND var['deposit_aa_' || trigger.data.curve_aa] == trigger.address}", |
| 66 | "messages": [ |
| 67 | { |
| 68 | "app": "state", |
| 69 | "state": "{ |
| 70 | var['asset_' || trigger.data.curve_aa || '_stable'] = trigger.unit; |
| 71 | }" |
| 72 | } |
| 73 | ] |
| 74 | }, |
| 75 | { |
| 76 | "init": "{ |
| 77 | $reserve_asset = trigger.data.reserve_asset OTHERWISE 'base'; |
| 78 | if (!asset[$reserve_asset].exists) |
| 79 | bounce("reserve asset " || $reserve_asset || " does not exist"); |
| 80 | |
| 81 | $reserve_asset_decimals = trigger.data.reserve_asset_decimals; |
| 82 | if (!is_integer($reserve_asset_decimals) OR $reserve_asset_decimals < 0 OR $reserve_asset_decimals > 14) |
| 83 | bounce("bad reserve_asset_decimals"); |
| 84 | |
| 85 | $decimals1 = trigger.data.decimals1; |
| 86 | if (!is_integer($decimals1) OR $decimals1 < 0 OR $decimals1 > 14) |
| 87 | bounce("bad decimals1"); |
| 88 | |
| 89 | $decimals2 = trigger.data.decimals2; |
| 90 | if (!is_integer($decimals2) OR $decimals2 < 0 OR $decimals2 > 14) |
| 91 | bounce("bad decimals2"); |
| 92 | |
| 93 | $m = trigger.data.m OTHERWISE 2; |
| 94 | if (typeof($m) != 'number' OR $m < 0) |
| 95 | bounce("bad m"); |
| 96 | |
| 97 | $n = trigger.data.n OTHERWISE 1/2; |
| 98 | if (typeof($n) != 'number' OR $n < 0) |
| 99 | bounce("bad n"); |
| 100 | |
| 101 | $leverage = trigger.data.leverage OTHERWISE 0; |
| 102 | if (typeof($leverage) != 'number') |
| 103 | bounce("bad leverage"); |
| 104 | |
| 105 | $oracle = trigger.data.oracle; |
| 106 | if ($oracle AND !is_valid_address($oracle)) |
| 107 | bounce("bad oracle"); |
| 108 | |
| 109 | $feed_name = trigger.data.feed_name; |
| 110 | |
| 111 | |
| 112 | |
| 113 | $interest_rate = trigger.data.interest_rate OTHERWISE 0; |
| 114 | if (typeof($interest_rate) != 'number' OR $interest_rate < 0) |
| 115 | bounce("bad interest_rate"); |
| 116 | |
| 117 | $fee_multiplier = trigger.data.fee_multiplier OTHERWISE 5; |
| 118 | if (typeof($fee_multiplier) != 'number' OR $fee_multiplier <= 0) |
| 119 | bounce("bad fee_multiplier"); |
| 120 | |
| 121 | $moved_capacity_share = trigger.data.moved_capacity_share OTHERWISE 0.1; |
| 122 | if (typeof($moved_capacity_share) != 'number' OR $moved_capacity_share <= 0) |
| 123 | bounce("bad moved_capacity_share"); |
| 124 | |
| 125 | $threshold_distance = trigger.data.threshold_distance OTHERWISE 0.01; |
| 126 | if (typeof($threshold_distance) != 'number' OR $threshold_distance <= 0) |
| 127 | bounce("bad threshold_distance"); |
| 128 | |
| 129 | $move_capacity_timeout = trigger.data.move_capacity_timeout OTHERWISE 2*3600; |
| 130 | if (!is_integer($move_capacity_timeout) OR $move_capacity_timeout <= 0) |
| 131 | bounce("bad move_capacity_timeout"); |
| 132 | |
| 133 | $slow_capacity_share = trigger.data.slow_capacity_share; |
| 134 | if (exists($slow_capacity_share) AND (typeof($slow_capacity_share) != 'number' OR $slow_capacity_share < 0)) |
| 135 | bounce("bad slow_capacity_share"); |
| 136 | |
| 137 | $curve_aa = [ |
| 138 | 'autonomous agent', |
| 139 | { |
| 140 | base_aa: $stablecoin_base_aa, |
| 141 | params: { |
| 142 | oracle: $oracle, |
| 143 | feed_name: $feed_name, |
| 144 | leverage: $leverage, |
| 145 | m: $m, |
| 146 | n: $n, |
| 147 | allow_grants: !!trigger.data.allow_grants, |
| 148 | reserve_asset: $reserve_asset, |
| 149 | reserve_asset_decimals: $reserve_asset_decimals, |
| 150 | decimals1: $decimals1, |
| 151 | decimals2: $decimals2, |
| 152 | interest_rate: $interest_rate, |
| 153 | fee_multiplier: $fee_multiplier, |
| 154 | moved_capacity_share: $moved_capacity_share, |
| 155 | threshold_distance: $threshold_distance, |
| 156 | move_capacity_timeout: $move_capacity_timeout, |
| 157 | slow_capacity_share: $slow_capacity_share, |
| 158 | } |
| 159 | } |
| 160 | ]; |
| 161 | $curve_aa_address = chash160($curve_aa); |
| 162 | }", |
| 163 | "messages": [ |
| 164 | { |
| 165 | "app": "payment", |
| 166 | "payload": { |
| 167 | "asset": "base", |
| 168 | "outputs": [ |
| 169 | { |
| 170 | "address": "{ $curve_aa_address }", |
| 171 | "amount": 8000 |
| 172 | } |
| 173 | ] |
| 174 | } |
| 175 | }, |
| 176 | { |
| 177 | "app": "data", |
| 178 | "payload": { |
| 179 | "define": 1, |
| 180 | "factory": "{this_address}" |
| 181 | } |
| 182 | }, |
| 183 | { |
| 184 | "app": "definition", |
| 185 | "payload": { |
| 186 | "definition": "{$curve_aa}" |
| 187 | } |
| 188 | }, |
| 189 | { |
| 190 | "app": "state", |
| 191 | "state": "{ |
| 192 | |
| 193 | var['curve_' || $curve_aa_address] = "s1^"||$m||" s2^"||$n; |
| 194 | }" |
| 195 | } |
| 196 | ] |
| 197 | } |
| 198 | ] |
| 199 | } |
| 200 | } |
| 201 | ] |