| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://ostable.org/bonded-stablecoin-stable.json", |
| 5 | "getters": "{ |
| 6 | |
| 7 | $get_curve_aa = () => params.curve_aa; |
| 8 | |
| 9 | $get_growth_factor = () => { |
| 10 | $interest_rate = var[params.curve_aa]['interest_rate']; |
| 11 | $term = (timestamp - var[params.curve_aa]['rate_update_ts']) / (360 * 24 * 3600); |
| 12 | $growth_factor = var[params.curve_aa]['growth_factor'] * (1 + $interest_rate)^$term; |
| 13 | $growth_factor |
| 14 | }; |
| 15 | |
| 16 | }", |
| 17 | "init": "{ |
| 18 | $curve_aa = params.curve_aa; |
| 19 | |
| 20 | |
| 21 | $asset = var['asset']; |
| 22 | $interest_asset = var[$curve_aa]['asset2']; |
| 23 | |
| 24 | $growth_factor = $get_growth_factor(); |
| 25 | |
| 26 | if (exists(trigger.data.to) AND !is_valid_address(trigger.data.to)) |
| 27 | bounce("bad to-address"); |
| 28 | }", |
| 29 | "messages": { |
| 30 | "cases": [ |
| 31 | { |
| 32 | "if": "{ trigger.data.define AND !$asset }", |
| 33 | "messages": [ |
| 34 | { |
| 35 | "app": "asset", |
| 36 | "payload": { |
| 37 | "is_private": false, |
| 38 | "is_transferrable": true, |
| 39 | "auto_destroy": false, |
| 40 | "fixed_denominations": false, |
| 41 | "issued_by_definer_only": true, |
| 42 | "cosigned_by_definer": false, |
| 43 | "spender_attested": false |
| 44 | } |
| 45 | }, |
| 46 | { |
| 47 | "if": "{trigger.data.factory}", |
| 48 | "app": "data", |
| 49 | "payload": { |
| 50 | "write_stable_asset": 1, |
| 51 | "curve_aa": "{$curve_aa}" |
| 52 | } |
| 53 | }, |
| 54 | { |
| 55 | "if": "{trigger.data.factory}", |
| 56 | "app": "payment", |
| 57 | "payload": { |
| 58 | "asset": "base", |
| 59 | "outputs": [ |
| 60 | { |
| 61 | "address": "{trigger.data.factory}" |
| 62 | } |
| 63 | ] |
| 64 | } |
| 65 | }, |
| 66 | { |
| 67 | "app": "state", |
| 68 | "state": "{ |
| 69 | var['asset'] = response_unit; |
| 70 | response['asset'] = response_unit; |
| 71 | }" |
| 72 | } |
| 73 | ] |
| 74 | }, |
| 75 | { |
| 76 | "if": "{ $asset AND trigger.output[[asset=$interest_asset]] > 0 }", |
| 77 | "init": "{ |
| 78 | $to = trigger.data.to OTHERWISE trigger.address; |
| 79 | $interest_amount = trigger.output[[asset=$interest_asset]]; |
| 80 | $stable_amount = floor($interest_amount * $growth_factor); |
| 81 | }", |
| 82 | "messages": [ |
| 83 | { |
| 84 | "app": "payment", |
| 85 | "payload": { |
| 86 | "asset": "{$asset}", |
| 87 | "outputs": [ |
| 88 | { |
| 89 | "address": "{$to}", |
| 90 | "amount": "{ $stable_amount }" |
| 91 | } |
| 92 | ] |
| 93 | } |
| 94 | }, |
| 95 | { |
| 96 | "if": "{trigger.data.to AND is_aa(trigger.data.to)}", |
| 97 | "app": "data", |
| 98 | "payload": { |
| 99 | "to": "{trigger.address}" |
| 100 | } |
| 101 | }, |
| 102 | { |
| 103 | "app": "state", |
| 104 | "state": "{ |
| 105 | var['supply'] += $stable_amount; |
| 106 | }" |
| 107 | } |
| 108 | ] |
| 109 | }, |
| 110 | { |
| 111 | "if": "{ $asset AND trigger.output[[asset=$asset]] > 0 }", |
| 112 | "init": "{ |
| 113 | $to = trigger.data.to OTHERWISE trigger.address; |
| 114 | $stable_amount = trigger.output[[asset=$asset]]; |
| 115 | $interest_amount = floor($stable_amount / $growth_factor); |
| 116 | }", |
| 117 | "messages": [ |
| 118 | { |
| 119 | "app": "payment", |
| 120 | "payload": { |
| 121 | "asset": "{$interest_asset}", |
| 122 | "outputs": [ |
| 123 | { |
| 124 | "address": "{$to}", |
| 125 | "amount": "{ $interest_amount }" |
| 126 | } |
| 127 | ] |
| 128 | } |
| 129 | }, |
| 130 | { |
| 131 | "if": "{trigger.data.to AND is_aa(trigger.data.to)}", |
| 132 | "app": "data", |
| 133 | "payload": { |
| 134 | "to": "{trigger.address}" |
| 135 | } |
| 136 | }, |
| 137 | { |
| 138 | "app": "state", |
| 139 | "state": "{ |
| 140 | var['supply'] -= $stable_amount; |
| 141 | }" |
| 142 | } |
| 143 | ] |
| 144 | } |
| 145 | ] |
| 146 | } |
| 147 | } |
| 148 | ] |