File tree Expand file tree Collapse file tree 3 files changed +71
-7
lines changed Expand file tree Collapse file tree 3 files changed +71
-7
lines changed Original file line number Diff line number Diff line change @@ -45,13 +45,8 @@ func NewMockPriceOracleSatPerAsset(expiryDelay uint64,
45
45
satsPerAsset uint64 ) * MockPriceOracle {
46
46
47
47
return & MockPriceOracle {
48
- expiryDelay : expiryDelay ,
49
-
50
- // TODO(ffranr): This is incorrect, we should convert
51
- // satoshis per asset to assets per BTC.
52
- assetToBtcRate : rfqmath .NewBigIntFixedPoint (
53
- satsPerAsset , 0 ,
54
- ),
48
+ expiryDelay : expiryDelay ,
49
+ assetToBtcRate : rfqmath .SatsPerAssetToAssetRate (satsPerAsset ),
55
50
}
56
51
}
57
52
Original file line number Diff line number Diff line change @@ -172,3 +172,16 @@ func MinTransportableMSat(dustLimit lnwire.MilliSatoshi,
172
172
oneAssetUnit := NewBigIntFixedPoint (1 , 0 )
173
173
return dustLimit + UnitsToMilliSatoshi (oneAssetUnit , rate )
174
174
}
175
+
176
+ // SatsPerAssetToAssetRate converts a satoshis per asset rate to an asset to
177
+ // BTC rate.
178
+ func SatsPerAssetToAssetRate (satsPerAsset uint64 ) BigIntFixedPoint {
179
+ if satsPerAsset == 0 {
180
+ return NewBigIntFixedPoint (0 , 0 )
181
+ }
182
+
183
+ satsPerAssetFp := NewBigIntFixedPoint (satsPerAsset , 0 )
184
+ satsPerBTC := NewBigIntFixedPoint (100_000_000 , 0 )
185
+
186
+ return satsPerBTC .Div (satsPerAssetFp )
187
+ }
Original file line number Diff line number Diff line change @@ -828,3 +828,59 @@ func TestConversionMsat(t *testing.T) {
828
828
rapid .MakeCheck (testRoundTripConversion [BigInt ]),
829
829
)
830
830
}
831
+
832
+ // TestConversionSatsPerAsset tests the conversion of satoshis per asset to an
833
+ // asset per BTC rate.
834
+ func TestConversionSatsPerAsset (t * testing.T ) {
835
+ t .Parallel ()
836
+
837
+ testCases := []struct {
838
+ satsPerAsset uint64
839
+ expectedValue uint64
840
+ }{
841
+ {
842
+ satsPerAsset : 5 ,
843
+ expectedValue : 20_000_000 ,
844
+ },
845
+ {
846
+ satsPerAsset : 10 ,
847
+ expectedValue : 10_000_000 ,
848
+ },
849
+ {
850
+ satsPerAsset : 20 ,
851
+ expectedValue : 5_000_000 ,
852
+ },
853
+ {
854
+ satsPerAsset : 1 ,
855
+ expectedValue : 100_000_000 ,
856
+ },
857
+ {
858
+ satsPerAsset : 50 ,
859
+ expectedValue : 2_000_000 ,
860
+ },
861
+ {
862
+ satsPerAsset : 100 ,
863
+ expectedValue : 1_000_000 ,
864
+ },
865
+ {
866
+ satsPerAsset : 0 ,
867
+ expectedValue : 0 ,
868
+ },
869
+ }
870
+
871
+ for idx := range testCases {
872
+ testCase := testCases [idx ]
873
+
874
+ t .Run (fmt .Sprintf ("SatsPerAsset=%d" , testCase .satsPerAsset ),
875
+ func (t * testing.T ) {
876
+ actual := SatsPerAssetToAssetRate (
877
+ testCase .satsPerAsset ,
878
+ )
879
+ expected := NewBigIntFixedPoint (
880
+ testCase .expectedValue , 0 ,
881
+ )
882
+ require .Equal (t , expected , actual )
883
+ },
884
+ )
885
+ }
886
+ }
You can’t perform that action at this time.
0 commit comments