}
oppositeAmount := uint64(assetFeeMap[contractArgs.RequestedAsset].FeeAmount)
- receiveAmount := vprMath.MinUint64(calcRequestAmount(input.Amount(), contractArgs), oppositeAmount)
+ receiveAmount := vprMath.MinUint64(CalcRequestAmount(input.Amount(), contractArgs), oppositeAmount)
assetFeeMap[input.AssetID()].MaxFeeAmount = calcMaxFeeAmount(calcShouldPayAmount(receiveAmount, contractArgs), maxFeeRate)
}
return err
}
- requestAmount := calcRequestAmount(order.Utxo.Amount, contractArgs)
+ requestAmount := CalcRequestAmount(order.Utxo.Amount, contractArgs)
receiveAmount := vprMath.MinUint64(requestAmount, oppositeAmount)
shouldPayAmount := calcShouldPayAmount(receiveAmount, contractArgs)
isPartialTrade := requestAmount > receiveAmount
return nil
}
-func calcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 {
+func CalcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 {
return uint64(int64(fromAmount) * contractArg.RatioNumerator / contractArg.RatioDenominator)
}
errNumeratorOfRatioIsOverflow = errors.New("ratio numerator of contract args product input amount is overflow")
errLengthOfInputIsIncorrect = errors.New("length of matched tx input is not equals to actual matched tx input")
errSpendOutputIDIsIncorrect = errors.New("spend output id of matched tx is not equals to actual matched tx")
+ errRequestAmountLessThenOne = errors.New("request amount of order less than one")
)
// MovCore represent the core logic of the match module, which include generate match transactions before packing the block,
return nil
}
-func validateMagneticContractArgs(inputAmount uint64, program []byte) error {
+func validateMagneticContractArgs(fromAmount uint64, program []byte) error {
contractArgs, err := segwit.DecodeP2WMCProgram(program)
if err != nil {
return err
return errRatioOfTradeLessThanZero
}
- if _, ok := checked.MulInt64(int64(inputAmount), contractArgs.RatioNumerator); !ok {
+ if _, ok := checked.MulInt64(int64(fromAmount), contractArgs.RatioNumerator); !ok {
return errNumeratorOfRatioIsOverflow
}
+
+ if match.CalcRequestAmount(fromAmount, contractArgs) < 1 {
+ return errRequestAmountLessThenOne
+ }
return nil
}