| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "getters": "{ |
| 5 | $pow2 = $x => $x*$x; |
| 6 | |
| 7 | $small_pow = ($x, $pow) => { |
| 8 | if ($pow == 0) |
| 9 | return 1; |
| 10 | if ($pow == 1) |
| 11 | return $x; |
| 12 | if ($pow == 2) |
| 13 | return $pow2($x); |
| 14 | if ($pow == 3) |
| 15 | return $pow2($x) * $x; |
| 16 | if ($pow == 4) |
| 17 | return $pow2($pow2($x)); |
| 18 | if ($pow == 5) |
| 19 | return $pow2($pow2($x)) * $x; |
| 20 | if ($pow == 6) |
| 21 | return $pow2($pow2($x) * $x); |
| 22 | if ($pow == 7) |
| 23 | return $pow2($pow2($x) * $x) * $x; |
| 24 | if ($pow == 8) |
| 25 | return $pow2($pow2($pow2($x))); |
| 26 | if ($pow == 9) |
| 27 | return $pow2($pow2($pow2($x))) * $x; |
| 28 | if ($pow == 10) |
| 29 | return $pow2($pow2($pow2($x)) * $x); |
| 30 | if ($pow == 11) |
| 31 | return $pow2($pow2($pow2($x)) * $x) * $x; |
| 32 | if ($pow == 12) |
| 33 | return $pow2($pow2($pow2($x) * $x)); |
| 34 | bounce("unsupported power "||$pow); |
| 35 | }; |
| 36 | |
| 37 | $get_reserve_price = () => { |
| 38 | $oswap_params = definition[params.oswap_aa][1].params; |
| 39 | $x_asset = $oswap_params.x_asset; |
| 40 | $y_asset = $oswap_params.y_asset; |
| 41 | $x_balance = balance[params.oswap_aa][$x_asset]; |
| 42 | $y_balance = balance[params.oswap_aa][$y_asset]; |
| 43 | $lp_shares = var[params.oswap_aa]['lp_shares']; |
| 44 | $supply = $lp_shares.issued; |
| 45 | $x_rate = data_feed[[oracles=params.x_oracle, feed_name=params.x_feed_name]] / $small_pow(10, params.x_decimals OTHERWISE 0); |
| 46 | $y_rate = data_feed[[oracles=params.y_oracle, feed_name=params.y_feed_name]] / $small_pow(10, params.y_decimals OTHERWISE 0); |
| 47 | $balance = $x_balance * $x_rate + $y_balance * $y_rate; |
| 48 | $price = $balance / $supply; |
| 49 | $price |
| 50 | }; |
| 51 | }", |
| 52 | "messages": [ |
| 53 | { |
| 54 | "app": "state", |
| 55 | "state": "{ |
| 56 | bounce('lib only'); |
| 57 | }" |
| 58 | } |
| 59 | ] |
| 60 | } |
| 61 | ] |