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