@@ -480,6 +480,7 @@ type agentFiTest struct {
480
480
withdrawLimit * big.Int
481
481
marginCall * big.Int
482
482
leverageRatio float64
483
+ dtl float64
483
484
}
484
485
485
486
var agentTests = []struct {
@@ -513,6 +514,7 @@ var agentTests = []struct {
513
514
withdrawLimit : bigFromStr ("8911457546764252091903" ),
514
515
marginCall : bigFromStr ("1272158912732776255650271" ),
515
516
leverageRatio : 0.5743316423053819 ,
517
+ dtl : 0.574289111476492565 ,
516
518
}},
517
519
// agent 27
518
520
{"agent no miners" , "0xDBa96B0FDbc87C7eEb641Ee37EAFC55B355079E4" , BLOCK_HEIGHT , agentFiTest {
@@ -525,6 +527,7 @@ var agentTests = []struct {
525
527
withdrawLimit : big .NewInt (0 ),
526
528
marginCall : big .NewInt (0 ),
527
529
leverageRatio : 0 ,
530
+ dtl : 0 ,
528
531
}},
529
532
// agent 2
530
533
{"agent single miner" , "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3" , BLOCK_HEIGHT , agentFiTest {
@@ -551,6 +554,7 @@ var agentTests = []struct {
551
554
withdrawLimit : bigFromStr ("57665444302030819344" ),
552
555
marginCall : bigFromStr ("2359669285522428148" ),
553
556
leverageRatio : 0.016656085317377764 ,
557
+ dtl : 0.016608593934123496 ,
554
558
}},
555
559
// agent 91
556
560
{"agent miner with fee debt" , "0xFF65F5f3D309fEA7aA2d4cB2727E918FAb0aE7F7" , BLOCK_HEIGHT , agentFiTest {
@@ -577,6 +581,7 @@ var agentTests = []struct {
577
581
withdrawLimit : bigFromStr ("0" ),
578
582
marginCall : bigFromStr ("0" ),
579
583
leverageRatio : 0 ,
584
+ dtl : 0 ,
580
585
}},
581
586
{"agent with balance no miners" , "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3" , big .NewInt (4238800 ), agentFiTest {
582
587
AgentFi : & AgentFi {
@@ -602,6 +607,7 @@ var agentTests = []struct {
602
607
withdrawLimit : bigFromStr ("3454284493328524959" ),
603
608
marginCall : bigFromStr ("0" ),
604
609
leverageRatio : 0 ,
610
+ dtl : 0 ,
605
611
}},
606
612
{"agent with balance no miners with principal" , "0xf0F1ceCCF78D411EeD9Ca190ca7F157140cCB2d3" , big .NewInt (4238810 ), agentFiTest {
607
613
AgentFi : & AgentFi {
@@ -627,6 +633,7 @@ var agentTests = []struct {
627
633
withdrawLimit : bigFromStr ("3120950589218935919" ),
628
634
marginCall : bigFromStr ("1176471091861402094" ),
629
635
leverageRatio : 0.22450304410954403 ,
636
+ dtl : 0.224502948003829978 ,
630
637
}},
631
638
}
632
639
@@ -662,6 +669,18 @@ func TestEstimateTermationFeeAgent(t *testing.T) {
662
669
}
663
670
}
664
671
672
+ func TestComputePerc (t * testing.T ) {
673
+ lv := bigFromStr ("871702482492442116952350" )
674
+ p := bigFromStr ("343733044178305628615912" )
675
+ i := bigFromStr ("28202982363374106229" )
676
+
677
+ perc := computePerc (new (big.Int ).Add (p , i ), lv )
678
+ exp := big .NewFloat (0.394356164017979036 )
679
+ if perc .Cmp (exp ) != 0 {
680
+ t .Fatalf ("Expected perc: %v, actual: %v" , exp , perc )
681
+ }
682
+ }
683
+
665
684
func assertAgentFiEqual (t * testing.T , expected * agentFiTest , actual * AgentFi ) {
666
685
if expected .AvailableBalance .Cmp (actual .AvailableBalance ) != 0 {
667
686
t .Fatalf ("Expected available balance: %v, actual: %v" , expected .AvailableBalance , actual .AvailableBalance )
@@ -709,8 +728,9 @@ func assertAgentFiEqual(t *testing.T, expected *agentFiTest, actual *AgentFi) {
709
728
if expected .marginCall .Cmp (actual .MarginCall ()) != 0 {
710
729
t .Fatalf ("Expected margin call: %v, actual: %v" , expected .marginCall , actual .MarginCall ())
711
730
}
712
- if expected .leverageRatio != actual .DTL () {
713
- t .Fatalf ("Expected leverage ratio: %v, actual: %v" , expected .leverageRatio , actual .DTL ())
731
+ dtl , _ := actual .DTL ().Float64 ()
732
+ if expected .leverageRatio != dtl {
733
+ t .Fatalf ("Expected leverage ratio: %v, actual: %v" , expected .leverageRatio , dtl )
714
734
}
715
735
}
716
736
0 commit comments