Skip to content

Commit b1ba280

Browse files
committed
fix: set price precision to 18 digits
1 parent 3f1d7c3 commit b1ba280

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

x/oracle/keeper/relay.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper
22

33
import (
44
"fmt"
5+
"strings"
56
"time"
67

78
sdkmath "cosmossdk.io/math"
@@ -125,8 +126,21 @@ func (k *Keeper) handleSpotPriceQueryResponse(ctx sdk.Context, asset v1.Asset, r
125126
return err
126127
}
127128

129+
// Split the spot price string into integer and decimal parts.
130+
parts := strings.SplitN(res.GetSpotPrice(), ".", 2)
131+
132+
i, d := parts[0], ""
133+
if len(parts) == 2 {
134+
d = parts[1]
135+
}
136+
137+
// Truncate the decimal part to 18 digits to maintain precision.
138+
if len(d) > 18 {
139+
d = d[:18]
140+
}
141+
128142
// Convert the spot price to a decimal value.
129-
spotPrice, err := sdkmath.LegacyNewDecFromStr(res.GetSpotPrice())
143+
spotPrice, err := sdkmath.LegacyNewDecFromStr(i + "." + d)
130144
if err != nil {
131145
return err
132146
}

0 commit comments

Comments
 (0)