@@ -18,6 +18,7 @@ func (m *Mock) GetCurrentRates() (map[string]float64, error) {
18
18
const (
19
19
tonstakers string = "tonstakers"
20
20
bemo string = "bemo"
21
+ beetroot string = "beetroot"
21
22
slpTokens string = "slp_tokens"
22
23
)
23
24
@@ -58,7 +59,11 @@ func (m *Mock) GetCurrentRates() (map[string]float64, error) {
58
59
pools [account ] = price
59
60
}
60
61
}
61
- pools = m .updatePools (pools )
62
+ if beetRootPrice , err := retry (beetroot , medianTonPriceToUsd , pools , m .getBeetrootPrice ); err == nil {
63
+ for account , price := range beetRootPrice {
64
+ pools [account ] = price
65
+ }
66
+ }
62
67
if slpTokensPrice , err := retry (slpTokens , medianTonPriceToUsd , pools , m .getSlpTokensPrice ); err == nil {
63
68
for account , price := range slpTokensPrice {
64
69
pools [account ] = price
@@ -221,3 +226,40 @@ func (m *Mock) getSlpTokensPrice(tonPrice float64, pools map[ton.AccountID]float
221
226
222
227
return accountsPrice , nil
223
228
}
229
+
230
+ func (m * Mock ) getBeetrootPrice (tonPrice float64 , pools map [ton.AccountID ]float64 ) (map [tongo.AccountID ]float64 , error ) {
231
+ if tonPrice == 0 {
232
+ return map [ton.AccountID ]float64 {}, fmt .Errorf ("unknown TON price" )
233
+ }
234
+ var beetRootContract = ton .MustParseAccountID ("EQDC8MY5tY5rPM6KFFxz58fMUES6qSsFxi_Pbaig1QuO3F7y" )
235
+ var beetRootAccount = ton .MustParseAccountID ("EQAFGhmx199oH6kmL78PGBHyAx4d5CiJdfXwSjDK5F5IFyfC" )
236
+ url := fmt .Sprintf ("https://tonapi.io/v2/blockchain/accounts/%v/methods/get_price_data" , beetRootContract )
237
+ respBody , err := sendRequest (url , m .TonApiToken )
238
+ if err != nil {
239
+ return map [ton.AccountID ]float64 {}, err
240
+ }
241
+ defer respBody .Close ()
242
+ type data struct {
243
+ Success bool `json:"success"`
244
+ Stack []struct {
245
+ Num string `json:"num"`
246
+ } `json:"stack"`
247
+ }
248
+ var result data
249
+ if err = json .NewDecoder (respBody ).Decode (& result ); err != nil {
250
+ return map [ton.AccountID ]float64 {}, fmt .Errorf ("[getBeetrootPrice] failed to decode response: %v" , err )
251
+ }
252
+ if ! result .Success {
253
+ return map [ton.AccountID ]float64 {}, fmt .Errorf ("not success" )
254
+ }
255
+ if len (result .Stack ) == 0 {
256
+ return map [ton.AccountID ]float64 {}, fmt .Errorf ("empty stack" )
257
+ }
258
+ num , err := strconv .ParseInt (result .Stack [0 ].Num , 0 , 64 )
259
+ if err != nil {
260
+ return map [tongo.AccountID ]float64 {}, err
261
+ }
262
+ usdPrice := float64 (num ) / 100
263
+ price := usdPrice / tonPrice
264
+ return map [ton.AccountID ]float64 {beetRootAccount : price }, nil
265
+ }
0 commit comments