Skip to content

Commit

Permalink
Merge pull request #136 from onomyprotocol/dong/validate-msg
Browse files Browse the repository at this point in the history
add validate for msg bid and active collateral
  • Loading branch information
DongLieu authored Jan 16, 2025
2 parents fda7329 + 8df1592 commit 79b4e2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion x/auction/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func (k msgServer) Bid(ctx context.Context, msg *types.MsgBid) (*types.MsgBidRes
return nil, err
}

recivePrice := math.LegacyMustNewDecFromStr(auction.InitialPrice).Mul(math.LegacyMustNewDecFromStr(msg.ReciveRate))
reciveRate := math.LegacyMustNewDecFromStr(msg.ReciveRate)
params := k.GetParams(ctx)
if reciveRate.LT(math.LegacyMustNewDecFromStr(params.LowestRate)) || reciveRate.GT(math.LegacyMustNewDecFromStr(params.StartingRate)) {
return nil, fmt.Errorf("reciveRate must be greater than or equal to %s and less than or equal to %s", params.LowestRate, params.StartingRate)
}
recivePrice := math.LegacyMustNewDecFromStr(auction.InitialPrice).Mul(reciveRate)
// auction.InitialPrice.
bid := types.Bid{
BidId: newBidId,
Expand Down
12 changes: 6 additions & 6 deletions x/vaults/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ func (msg *MsgActiveCollateral) ValidateBasic() error {
}

if msg.LiquidationRatio.LT(math.LegacyZeroDec()) {
return fmt.Errorf("minCollateralRatio cannot be less than 0")
return fmt.Errorf("LiquidationRatio cannot be less than 0")
}

if msg.StabilityFee.LTE(math.LegacyZeroDec()) {
return fmt.Errorf("StabilityFee cannot be less than 0")
}

if msg.LiquidationPenalty.LT(math.LegacyZeroDec()) {
return fmt.Errorf("minCollateralRatio cannot be less than 0")
if msg.LiquidationPenalty.LTE(math.LegacyZeroDec()) {
return fmt.Errorf("LiquidationPenalty cannot be less than 0")
}

if msg.MaxDebt.LT(math.ZeroInt()) {
return fmt.Errorf("minCollateralRatio cannot be less than 0")
if msg.MaxDebt.LTE(math.ZeroInt()) {
return fmt.Errorf("MaxDebt cannot be less than 0")
}

if msg.MintingFee.LT(math.LegacyZeroDec()) {
return fmt.Errorf("minCollateralRatio cannot be less than 0")
return fmt.Errorf("MintingFee cannot be less than 0")
}
return nil
}
Expand Down

0 comments on commit 79b4e2f

Please sign in to comment.