@@ -34,6 +34,8 @@ const (
34
34
var (
35
35
voteMode string
36
36
salt , exchangeRatesStr = []string {"1234" , "" }, []string {"" , "" }
37
+
38
+ denoms = []string {"krw" , "usd" , "eur" , "mnt" , "cny" , "jpy" , "gbp" , "inr" , "cad" , "chf" , "hkd" , "sgd" , "aud" , "sdr" }
37
39
)
38
40
39
41
func (os * OracleService ) init () error {
@@ -85,7 +87,7 @@ func (os *OracleService) txRoutine() {
85
87
var voteMsgs []sdk.Msg
86
88
var latestVoteHeight int64 = 0
87
89
88
- denoms := []string {"krw" , "usd" , "eur" , "mnt" , "cny" , "jpy" , "gbp" , "inr" , "cad" , "chf" , "hkd" , "sgd" , "aud" , "sdr" }
90
+ // denoms := []string{"krw", "usd", "eur", "mnt", "cny", "jpy", "gbp", "inr", "cad", "chf", "hkd", "sgd", "aud", "sdr"}
89
91
90
92
for {
91
93
func () {
@@ -291,142 +293,45 @@ func (os *OracleService) makeAggregateVoteMsgs(denoms []string) ([]sdk.Msg, erro
291
293
292
294
func (os * OracleService ) calculatePrice () (abort bool , err error ) {
293
295
294
- lunaToKrw := os .ps .GetPrice ("luna/krw" )
295
- if lunaToKrw .Denom != "krw" {
296
- return false , errors .New ("Can't get luna/krw" )
297
- }
298
296
lunaToUsd := os .ps .GetPrice ("luna/usd" )
299
- if lunaToUsd .Denom != "usd" {
300
- return false , errors .New ("Can't get luna/usd" )
301
- }
302
- sdrToUsd := os .ps .GetPrice ("sdr/usd" )
303
- if sdrToUsd .Denom != "usd" {
304
- return false , errors .New ("Can't get sdr/usd" )
305
- }
306
- eurToUsd := os .ps .GetPrice ("eur/usd" )
307
- if eurToUsd .Denom != "usd" {
308
- return false , errors .New ("Can't get eur/usd" )
309
- }
310
- mntToUsd := os .ps .GetPrice ("mnt/usd" )
311
- if mntToUsd .Denom != "usd" {
312
- return false , errors .New ("Can't get mnt/usd" )
313
- }
314
- cnyToUsd := os .ps .GetPrice ("cny/usd" )
315
- if cnyToUsd .Denom != "usd" {
316
- return false , errors .New ("Can't get cny/usd" )
317
- }
318
- jpyToUsd := os .ps .GetPrice ("jpy/usd" )
319
- if jpyToUsd .Denom != "usd" {
320
- return false , errors .New ("Can't get jpy/usd" )
321
- }
322
- gbpToUsd := os .ps .GetPrice ("gbp/usd" )
323
- if gbpToUsd .Denom != "usd" {
324
- return false , errors .New ("Can't get gbp/usd" )
325
- }
326
- inrToUsd := os .ps .GetPrice ("inr/usd" )
327
- if inrToUsd .Denom != "usd" {
328
- return false , errors .New ("Can't get inr/usd" )
329
- }
330
- cadToUsd := os .ps .GetPrice ("cad/usd" )
331
- if cadToUsd .Denom != "usd" {
332
- return false , errors .New ("Can't get cad/usd" )
333
- }
334
- chfToUsd := os .ps .GetPrice ("chf/usd" )
335
- if chfToUsd .Denom != "usd" {
336
- return false , errors .New ("Can't get chf/usd" )
337
- }
338
- hkdToUsd := os .ps .GetPrice ("hkd/usd" )
339
- if hkdToUsd .Denom != "usd" {
340
- return false , errors .New ("Can't get hkd/usd" )
341
- }
342
- sgdToUsd := os .ps .GetPrice ("sgd/usd" )
343
- if sgdToUsd .Denom != "usd" {
344
- return false , errors .New ("Can't get sgd/usd" )
345
- }
346
- audToUsd := os .ps .GetPrice ("aud/usd" )
347
- if audToUsd .Denom != "usd" {
348
- return false , errors .New ("Can't get aud/usd" )
349
- }
350
297
351
- // If sdrToKrw is 0, this will panic
352
- lunaToSdrAmount := lunaToUsd .Amount .Quo (sdrToUsd .Amount )
353
- lunaToSdr := sdk .NewDecCoinFromDec ("sdr" , lunaToSdrAmount )
354
-
355
- lunaToEurAmount := lunaToUsd .Amount .Quo (eurToUsd .Amount )
356
- lunaToEur := sdk .NewDecCoinFromDec ("eur" , lunaToEurAmount )
357
-
358
- lunaToMntAmount := lunaToUsd .Amount .Quo (mntToUsd .Amount )
359
- lunaToMnt := sdk .NewDecCoinFromDec ("mnt" , lunaToMntAmount )
360
-
361
- lunaToCnyAmount := lunaToUsd .Amount .Quo (cnyToUsd .Amount )
362
- lunaToCny := sdk .NewDecCoinFromDec ("cny" , lunaToCnyAmount )
363
-
364
- lunaToJpyAmount := lunaToUsd .Amount .Quo (jpyToUsd .Amount )
365
- lunaToJpy := sdk .NewDecCoinFromDec ("jpy" , lunaToJpyAmount )
366
-
367
- lunaToGbpAmount := lunaToUsd .Amount .Quo (gbpToUsd .Amount )
368
- lunaToGbp := sdk .NewDecCoinFromDec ("gbp" , lunaToGbpAmount )
369
-
370
- lunaToInrAmount := lunaToUsd .Amount .Quo (inrToUsd .Amount )
371
- lunaToInr := sdk .NewDecCoinFromDec ("inr" , lunaToInrAmount )
372
-
373
- lunaToCadAmount := lunaToUsd .Amount .Quo (cadToUsd .Amount )
374
- lunaToCad := sdk .NewDecCoinFromDec ("cad" , lunaToCadAmount )
375
-
376
- lunaToChfAmount := lunaToUsd .Amount .Quo (chfToUsd .Amount )
377
- lunaToChf := sdk .NewDecCoinFromDec ("chf" , lunaToChfAmount )
378
-
379
- lunaToHkdAmount := lunaToUsd .Amount .Quo (hkdToUsd .Amount )
380
- lunaToHkd := sdk .NewDecCoinFromDec ("hkd" , lunaToHkdAmount )
381
-
382
- lunaToSgdAmount := lunaToUsd .Amount .Quo (sgdToUsd .Amount )
383
- lunaToSgd := sdk .NewDecCoinFromDec ("sgd" , lunaToSgdAmount )
384
-
385
- lunaToAudAmount := lunaToUsd .Amount .Quo (audToUsd .Amount )
386
- lunaToAud := sdk .NewDecCoinFromDec ("aud" , lunaToAudAmount )
387
-
388
- os .Logger .Info (fmt .Sprintf ("sdr/usd: %s" , sdrToUsd .String ()))
389
- os .Logger .Info (fmt .Sprintf ("eur/usd: %s" , eurToUsd .String ()))
390
- os .Logger .Info (fmt .Sprintf ("mnt/usd: %s" , mntToUsd .String ()))
391
- os .Logger .Info (fmt .Sprintf ("cny/usd: %s" , cnyToUsd .String ()))
392
- os .Logger .Info (fmt .Sprintf ("jpy/usd: %s" , jpyToUsd .String ()))
393
- os .Logger .Info (fmt .Sprintf ("gbp/usd: %s" , gbpToUsd .String ()))
394
- os .Logger .Info (fmt .Sprintf ("inr/usd: %s" , inrToUsd .String ()))
395
- os .Logger .Info (fmt .Sprintf ("cad/usd: %s" , cadToUsd .String ()))
396
- os .Logger .Info (fmt .Sprintf ("chf/usd: %s" , chfToUsd .String ()))
397
- os .Logger .Info (fmt .Sprintf ("hkd/usd: %s" , hkdToUsd .String ()))
398
- os .Logger .Info (fmt .Sprintf ("sgd/usd: %s" , sgdToUsd .String ()))
399
- os .Logger .Info (fmt .Sprintf ("aud/usd: %s" , audToUsd .String ()))
400
-
401
- os .Logger .Info (fmt .Sprintf ("luna/krw: %s" , lunaToKrw .String ()))
402
- os .Logger .Info (fmt .Sprintf ("luna/sdr: %s" , lunaToSdr .String ()))
403
- os .Logger .Info (fmt .Sprintf ("luna/usd: %s" , lunaToUsd .String ()))
404
- os .Logger .Info (fmt .Sprintf ("luna/eur: %s" , lunaToEur .String ()))
405
- os .Logger .Info (fmt .Sprintf ("luna/mnt: %s" , lunaToMnt .String ()))
406
- os .Logger .Info (fmt .Sprintf ("luna/cny: %s" , lunaToCny .String ()))
407
- os .Logger .Info (fmt .Sprintf ("luna/jpy: %s" , lunaToJpy .String ()))
408
- os .Logger .Info (fmt .Sprintf ("luna/gbp: %s" , lunaToGbp .String ()))
409
- os .Logger .Info (fmt .Sprintf ("luna/inr: %s" , lunaToInr .String ()))
410
- os .Logger .Info (fmt .Sprintf ("luna/cad: %s" , lunaToCad .String ()))
411
- os .Logger .Info (fmt .Sprintf ("luna/chf: %s" , lunaToChf .String ()))
412
- os .Logger .Info (fmt .Sprintf ("luna/hkd: %s" , lunaToHkd .String ()))
413
- os .Logger .Info (fmt .Sprintf ("luna/sgd: %s" , lunaToSgd .String ()))
414
- os .Logger .Info (fmt .Sprintf ("luna/aud: %s" , lunaToAud .String ()))
415
-
416
- os .lunaPrices ["krw" ] = lunaToKrw
417
- os .lunaPrices ["sdr" ] = lunaToSdr
418
- os .lunaPrices ["usd" ] = lunaToUsd
419
- os .lunaPrices ["eur" ] = lunaToEur
420
- os .lunaPrices ["mnt" ] = lunaToMnt
421
- os .lunaPrices ["cny" ] = lunaToCny
422
- os .lunaPrices ["jpy" ] = lunaToJpy
423
- os .lunaPrices ["gbp" ] = lunaToGbp
424
- os .lunaPrices ["inr" ] = lunaToInr
425
- os .lunaPrices ["cad" ] = lunaToCad
426
- os .lunaPrices ["chf" ] = lunaToChf
427
- os .lunaPrices ["hkd" ] = lunaToHkd
428
- os .lunaPrices ["sgd" ] = lunaToSgd
429
- os .lunaPrices ["aud" ] = lunaToAud
298
+ for _ , d := range denoms {
299
+
300
+ switch d {
301
+ case "krw" :
302
+ lunaToKrw := os .ps .GetPrice ("luna/krw" )
303
+
304
+ if lunaToKrw .Denom != "krw" {
305
+ // return false, errors.New("Can't get luna/krw")
306
+ fmt .Println ("Can't get luna/krw" )
307
+ }
308
+ os .Logger .Info (fmt .Sprintf ("luna/krw: %s" , lunaToKrw .String ()))
309
+ os .lunaPrices [d ] = lunaToKrw
310
+
311
+ case "usd" :
312
+ if lunaToUsd .Denom != "usd" {
313
+ // return false, errors.New("Can't get luna/usd")
314
+ fmt .Println ("Can't get luna/usd" )
315
+ }
316
+ os .Logger .Info (fmt .Sprintf ("luna/usd: %s" , lunaToUsd .String ()))
317
+ os .lunaPrices [d ] = lunaToUsd
318
+
319
+ default :
320
+ coinToUsd := os .ps .GetPrice (d + "/usd" )
321
+ if coinToUsd .Denom != "usd" {
322
+ // return false, errors.New("Can't get " +d +"/usd")
323
+ }
324
+
325
+ lunaToCoinAmount := lunaToUsd .Amount .Quo (coinToUsd .Amount )
326
+ lunaToCoin := sdk .NewDecCoinFromDec (d , lunaToCoinAmount )
327
+
328
+ os .Logger .Info (fmt .Sprintf ("%s/usd: %s" , d , coinToUsd .String ()))
329
+ os .Logger .Info (fmt .Sprintf ("luna/%s: %s" , d , lunaToCoin .String ()))
330
+
331
+
332
+ os .lunaPrices [d ] = lunaToCoin
333
+ }
334
+ }
430
335
431
336
return false , nil
432
337
}
0 commit comments