@@ -3,31 +3,50 @@ import { useEffect, useState } from "react";
3
3
import { useLCDClient } from "@terra-money/wallet-provider" ;
4
4
import React from "react" ;
5
5
import { BarChart , Bar , Cell , YAxis , ReferenceLine , LabelList } from "recharts" ;
6
+ import { computeSwap , coinAfterSpread } from "./lib/market" ;
7
+ import { Coin } from "@terra-money/terra.js" ;
6
8
7
9
const colors = [ "#0088FE" , "#FFBB28" ] ;
10
+ const ust_swap_size = 10000 ;
8
11
9
12
function App ( ) {
10
13
const [ data , setData ] = useState ( [ ] ) ;
14
+
15
+ const [ swapRate , setSwapRate ] = useState ( [ ] ) ;
16
+ const [ basePool , setBasePool ] = useState ( [ ] ) ;
11
17
const [ scale , setScale ] = useState ( [ 49000000 , 51000000 ] ) ;
12
18
const lcd = useLCDClient ( ) ;
13
19
14
20
useEffect ( ( ) => {
15
21
const fetchPools = async ( ) => {
16
22
const delta = await lcd . market . poolDelta ( ) ;
17
- const { base_pool } = await lcd . market . parameters ( ) ;
23
+ const luna_rates = await lcd . oracle . exchangeRates ( ) ;
24
+ const { base_pool, min_stability_spread } = await lcd . market . parameters ( ) ;
18
25
const microTerraSide = base_pool . plus ( delta ) ;
19
- const micraLunaSide = base_pool . pow ( 2 ) . div ( microTerraSide ) ;
20
-
21
- const terraSide = microTerraSide . times ( 0.000001 ) . toNumber ( )
22
- const lunaSide = micraLunaSide . times ( 0.000001 ) . toNumber ( )
26
+ const microLunaSide = base_pool . pow ( 2 ) . div ( microTerraSide ) ;
27
+
28
+ const terraSide = microTerraSide . times ( 0.000001 ) . toNumber ( ) ;
29
+ const lunaSide = microLunaSide . times ( 0.000001 ) . toNumber ( ) ;
30
+
31
+ setBasePool ( base_pool ) ;
32
+ const ustSwapRate = computeSwap (
33
+ new Coin ( "uusd" , ust_swap_size * 1e6 ) ,
34
+ "uluna" ,
35
+ luna_rates ,
36
+ base_pool ,
37
+ min_stability_spread ,
38
+ delta
39
+ ) ;
40
+
41
+ setSwapRate ( ustSwapRate ) ;
23
42
24
43
setData ( [
25
44
{
26
- name : "Stablecoins" ,
45
+ name : "Stablecoins (in sdr) " ,
27
46
amt : terraSide ,
28
47
} ,
29
48
{
30
- name : "LUNA" ,
49
+ name : "LUNA (in sdr) " ,
31
50
amt : lunaSide ,
32
51
} ,
33
52
] ) ;
@@ -46,20 +65,30 @@ function App() {
46
65
} ;
47
66
} , [ lcd . market ] ) ;
48
67
68
+ if ( ! swapRate ) {
69
+ return "Loading..." ;
70
+ }
71
+
72
+ const beforeSpreadFee = swapRate [ 0 ] ?. amount . div ( 1e6 ) ;
73
+ const afterSpreadFee = coinAfterSpread ( swapRate [ 0 ] , swapRate [ 1 ] ) ?. amount . div (
74
+ 1e6
75
+ ) ;
49
76
return (
50
77
< div className = "App" >
51
78
< center >
52
79
< h1 > Terra Virtual Liquidity Pools</ h1 >
53
80
< BarChart width = { 800 } height = { 400 } data = { data } >
54
81
< Bar isAnimationActive = { false } label = { false } dataKey = "amt" >
55
- { data . map ( ( entry , index ) => < Cell key = { `cell-${ index } ` } fill = { colors [ index % 20 ] } /> ) }
82
+ { data . map ( ( entry , index ) => (
83
+ < Cell key = { `cell-${ index } ` } fill = { colors [ index % 20 ] } />
84
+ ) ) }
56
85
< LabelList dataKey = "name" position = "top" />
57
- { /* <LabelList dataKey="amt" position="inside" fill="#000000" /> */ }
86
+ < LabelList dataKey = "amt" position = "inside" fill = "#000000" />
58
87
</ Bar >
59
88
< ReferenceLine
60
89
isFront = { false }
61
90
label = { { position : "top" , value : "BasePool" } }
62
- y = { 50000000 }
91
+ y = { basePool . toNumber ( ) }
63
92
stroke = "#000"
64
93
/>
65
94
< YAxis
@@ -71,8 +100,17 @@ function App() {
71
100
domain = { scale }
72
101
/>
73
102
</ BarChart >
103
+
104
+ < div >
105
+ Oracle Rate: { ust_swap_size } ust = { beforeSpreadFee . toFixed ( 2 ) } luna
106
+ (${ ( ust_swap_size / beforeSpreadFee ) . toFixed ( 4 ) } per luna)
107
+ </ div >
108
+ < div >
109
+ With { swapRate [ 1 ] ?. times ( 100 ) . toFixed ( 2 ) } % spread fee:{ " " }
110
+ { ust_swap_size } ust = { afterSpreadFee . toFixed ( 2 ) } luna ($
111
+ { ( ust_swap_size / afterSpreadFee ) . toFixed ( 4 ) } per luna)
112
+ </ div >
74
113
</ center >
75
- < a style = { { position : 'fixed' , right : 0 , top : 0 } } href = "https://github.com/octalmage/terra-pools" > < img loading = "lazy" width = "149" height = "149" src = "https://github.blog/wp-content/uploads/2008/12/forkme_right_darkblue_121621.png?resize=149%2C149" class = "attachment-full size-full" alt = "Fork me on GitHub" data-recalc-dims = "1" /> </ a >
76
114
</ div >
77
115
) ;
78
116
}
0 commit comments