OSDN Git Service

update fee rate
authorshenao78 <shenao.78@163.com>
Mon, 6 Jul 2020 07:14:26 +0000 (15:14 +0800)
committershenao78 <shenao.78@163.com>
Mon, 6 Jul 2020 07:14:26 +0000 (15:14 +0800)
application/mov/match/engine.go
application/mov/match/fee_strategy.go

index 17b6bec..8ac3f7e 100644 (file)
@@ -262,13 +262,15 @@ func isMaker(order, oppositeOrder *common.Order) bool {
 
 func setMatchTxArguments(txInput *types.TxInput, isPartialTrade bool, position int, receiveAmounts uint64, isMaker bool) {
        traderType := contract.Taker
+       feeRate := takerFeeRate
        if isMaker {
                traderType = contract.Maker
+               feeRate = makerFeeRate
        }
 
        var arguments [][]byte
        if isPartialTrade {
-               arguments = [][]byte{vm.Int64Bytes(int64(receiveAmounts)), vm.Int64Bytes(int64(position)), vm.Int64Bytes(contract.PartialTradeClauseSelector), vm.Int64Bytes(traderType)}
+               arguments = [][]byte{vm.Int64Bytes(int64(receiveAmounts)), vm.Int64Bytes(int64(position)), vm.Int64Bytes(contract.PartialTradeClauseSelector), vm.Int64Bytes(feeRate)}
        } else {
                arguments = [][]byte{vm.Int64Bytes(int64(position)), vm.Int64Bytes(contract.FullTradeClauseSelector), vm.Int64Bytes(traderType)}
        }
index dfd1531..e15c05a 100644 (file)
@@ -12,6 +12,12 @@ var (
        ErrInvalidAmountOfFee = errors.New("amount of fee is invalid")
 )
 
+const (
+       // rate of fee in units of 10000
+       makerFeeRate int64 = 0
+       takerFeeRate int64 = 3
+)
+
 // AllocatedAssets represent reallocated assets after calculating fees
 type AllocatedAssets struct {
        Receives []*bc.AssetAmount
@@ -64,8 +70,9 @@ func (d *DefaultFeeStrategy) Validate(receiveAmounts []*bc.AssetAmount, feeAmoun
 }
 
 func (d *DefaultFeeStrategy) calcFeeAmount(amount uint64, isMaker bool) uint64 {
+       feeRate := takerFeeRate
        if isMaker {
-               return 0
+               feeRate = makerFeeRate
        }
-       return uint64(math.Ceil(float64(amount) / 1000))
+       return uint64(math.Ceil(float64(amount) * float64(feeRate) / 1E4))
 }