decred.org/dcrdex@v1.0.3/dex/networks/zec/params.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org
     3  
     4  package zec
     5  
     6  import (
     7  	"decred.org/dcrdex/dex"
     8  	"decred.org/dcrdex/dex/networks/btc"
     9  	"github.com/btcsuite/btcd/chaincfg"
    10  )
    11  
    12  const (
    13  	// MinimumTxOverhead
    14  	// 4 header + 4 nVersionGroup + 1 varint input count + 1 varint output count
    15  	// + 4 lockTime + 4 nExpiryHeight + 8 valueBalanceSapling + 1 varint nSpendsSapling
    16  	// + 1 varint nOutputsSapling + 1 varint nJoinSplit
    17  	MinimumTxOverhead = 29
    18  
    19  	InitTxSizeBase = MinimumTxOverhead + btc.P2PKHOutputSize + btc.P2SHOutputSize // 29 + 34 + 32 = 95
    20  	InitTxSize     = InitTxSizeBase + btc.RedeemP2PKHInputSize                    // 95 + 149 = 244
    21  
    22  	// LegacyFeeRate returns a standard 10 zats / byte. Prior to ZIP-0317, Zcash
    23  	// used a standard tx fee of 1000 zats, regardless of tx size. However,
    24  	// zcashd v5.5 begins making stricter fee requirements for both relay and
    25  	// block inclusion. The release notes state that relay by default still
    26  	// works with 1000 zat fee txns, but it may be adjusted by operators, and it
    27  	// may need to be set to the higher ZIP 317 rate. For mining, there is a
    28  	// small allowance on the number of "unpaid actions" allowed in a block, so
    29  	// we should take care to pay the ZIP 317 "conventional" rate, which is
    30  	// multiples of 5000 zats, and a minimum of 10000. To ensure we have no
    31  	// unpaid actions in our (transparent) transactions, we need a higher rate.
    32  	// For a 242 byte transaction, like a swap init, we can emulate this with
    33  	// about 42 zats/byte. Even with 100 zats/byte, our typical redeem of ~342
    34  	// bytes would pay 34200 zats, which is only about a penny, so to ensure our
    35  	// transactions are relayed and mined, we go with a high rate.
    36  	LegacyFeeRate = 84
    37  )
    38  
    39  var (
    40  	UnitInfo = dex.UnitInfo{
    41  		AtomicUnit: "zats",
    42  		Conventional: dex.Denomination{
    43  			Unit:             "ZEC",
    44  			ConversionFactor: 1e8,
    45  		},
    46  		Alternatives: []dex.Denomination{
    47  			{
    48  				Unit:             "mZEC",
    49  				ConversionFactor: 1e5,
    50  			},
    51  			{
    52  				Unit:             "µZEC",
    53  				ConversionFactor: 1e2,
    54  			},
    55  		},
    56  		FeeRateDenom: "action",
    57  	}
    58  
    59  	// MainNetParams are the clone parameters for mainnet. Zcash,
    60  	// like Decred, uses two bytes for their address IDs. We will convert
    61  	// between address types on the fly and use these spoof parameters
    62  	// internally.
    63  	MainNetParams = btc.ReadCloneParams(&btc.CloneParams{
    64  		Name:             "mainnet",
    65  		ScriptHashAddrID: 0xBD,
    66  		PubKeyHashAddrID: 0xB8,
    67  		CoinbaseMaturity: 100,
    68  		Net:              0x24e92764,
    69  	})
    70  	// TestNet4Params are the clone parameters for testnet.
    71  	TestNet4Params = btc.ReadCloneParams(&btc.CloneParams{
    72  		Name:             "testnet4",
    73  		PubKeyHashAddrID: 0x25,
    74  		ScriptHashAddrID: 0xBA,
    75  		CoinbaseMaturity: 100,
    76  		Net:              0xfa1af9bf,
    77  	})
    78  	// RegressionNetParams are the clone parameters for simnet.
    79  	RegressionNetParams = btc.ReadCloneParams(&btc.CloneParams{
    80  		Name:             "regtest",
    81  		PubKeyHashAddrID: 0x25,
    82  		ScriptHashAddrID: 0xBA,
    83  		CoinbaseMaturity: 100,
    84  		Net:              0xaae83f5f,
    85  	})
    86  
    87  	// MainNetAddressParams are used for string address parsing. We use a
    88  	// spoofed address internally, since Zcash uses a two-byte address ID
    89  	// instead of a 1-byte ID.
    90  	MainNetAddressParams = &AddressParams{
    91  		ScriptHashAddrID: [2]byte{0x1C, 0xBD},
    92  		PubKeyHashAddrID: [2]byte{0x1C, 0xB8},
    93  	}
    94  
    95  	// TestNet4AddressParams are used for string address parsing.
    96  	TestNet4AddressParams = &AddressParams{
    97  		ScriptHashAddrID: [2]byte{0x1C, 0xBA},
    98  		PubKeyHashAddrID: [2]byte{0x1D, 0x25},
    99  	}
   100  
   101  	// RegressionNetAddressParams are used for string address parsing.
   102  	RegressionNetAddressParams = &AddressParams{
   103  		ScriptHashAddrID: [2]byte{0x1C, 0xBA},
   104  		PubKeyHashAddrID: [2]byte{0x1D, 0x25},
   105  	}
   106  )
   107  
   108  func init() {
   109  	for _, params := range []*chaincfg.Params{MainNetParams, TestNet4Params, RegressionNetParams} {
   110  		err := chaincfg.Register(params)
   111  		if err != nil {
   112  			panic("failed to register zec parameters: " + err.Error())
   113  		}
   114  	}
   115  }