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