decred.org/dcrdex@v1.0.5/client/asset/estimation.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org/license/1.0.0.
     3  
     4  package asset
     5  
     6  // SwapEstimate is an estimate of the fees and locked amounts associated with
     7  // an order.
     8  type SwapEstimate struct {
     9  	// Lots is the number of lots in the order.
    10  	Lots uint64 `json:"lots"`
    11  	// Value is the total value of the order.
    12  	Value uint64 `json:"value"`
    13  	// MaxFees is the maximum possible fees that can be assessed for the order's
    14  	// swaps.
    15  	MaxFees uint64 `json:"maxFees"`
    16  	// RealisticWorstCase is an estimation of the fees that might be assessed in
    17  	// a worst-case scenario of 1 tx per 1 lot match, but at the prevailing fee
    18  	// rate estimate.
    19  	RealisticWorstCase uint64 `json:"realisticWorstCase"`
    20  	// RealisticBestCase is an estimation of the fees that might be assessed in
    21  	// a best-case scenario of 1 tx and 1 output for the entire order.
    22  	RealisticBestCase uint64 `json:"realisticBestCase"`
    23  	// FeeReservesPerLot is the amount that must be reserved per lot to cover
    24  	// fees for swap transactions.
    25  	FeeReservesPerLot uint64 `json:"feeReservesPerLot"`
    26  }
    27  
    28  // RedeemEstimate is an estimate of the range of fees that might realistically
    29  // be assessed to the redemption transaction.
    30  type RedeemEstimate struct {
    31  	// RealisticBestCase is the best-case scenario fees of a single transaction
    32  	// with a match covering the entire order, at the prevailing fee rate.
    33  	RealisticBestCase uint64 `json:"realisticBestCase"`
    34  	// RealisticWorstCase is the worst-case scenario fees of all 1-lot matches,
    35  	// each with their own call to Redeem.
    36  	RealisticWorstCase uint64 `json:"realisticWorstCase"`
    37  }
    38  
    39  // PreSwapForm can be used to get a swap fees estimate.
    40  type PreSwapForm struct {
    41  	// Version is the asset version. Most backends only support one version.
    42  	Version uint32
    43  	// LotSize is the lot size for the calculation. For quote assets, LotSize
    44  	// should be based on either the user's limit order rate, or some measure
    45  	// of the current market rate.
    46  	LotSize uint64
    47  	// Lots is the number of lots in the order.
    48  	Lots uint64
    49  	// MaxFeeRate is the highest possible fee rate that may be required for the
    50  	// swap initialization transaction.
    51  	MaxFeeRate uint64
    52  	// Immediate should be set to true if this is for an order that is not a
    53  	// standing order, likely a market order or a limit order with immediate
    54  	// time-in-force.
    55  	Immediate bool
    56  	// FeeSuggestion is a suggested fee from the server. If a split transaction
    57  	// is used, the fee rate used should be at least the suggested fee, else
    58  	// zero-conf coins might be rejected.
    59  	FeeSuggestion uint64
    60  	// SelectedOptions is any options that the user has selected. The available
    61  	// PreOrder options and values can be inter-dependent, so when a user
    62  	// selects an option, a new PreOrder can be generated to updated the
    63  	// options available and recalculate the effects.
    64  	SelectedOptions map[string]string
    65  
    66  	// The following fields are only used for some assets where the redeemed/to
    67  	// asset may require funds in this "from" asset. For example, buying ERC20
    68  	// tokens with ETH. The funds may be used for withdraw approval for the
    69  	// redeemed token contract, or just the redeem tx gas.
    70  
    71  	// RedeemVersion is the asset version of the "to" asset with the redeem
    72  	// transaction. Most backends only support one version.
    73  	RedeemVersion uint32
    74  	// RedeemAssetID is the asset ID of the "to" asset.
    75  	RedeemAssetID uint32
    76  }
    77  
    78  // PreSwap is a SwapEstimate returned from Wallet.PreSwap.
    79  type PreSwap struct {
    80  	Estimate *SwapEstimate  `json:"estimate"`
    81  	Options  []*OrderOption `json:"options"`
    82  }
    83  
    84  // PreRedeemForm can be used to get a redemption estimate.
    85  type PreRedeemForm struct {
    86  	// Version is the asset version. Most backends only support one version.
    87  	Version uint32
    88  	// Lots is the number of lots in the order.
    89  	Lots uint64
    90  	// FeeSuggestion is a suggested fee from the server.
    91  	FeeSuggestion uint64
    92  	// SelectedOptions is any options that the user has selected.
    93  	SelectedOptions map[string]string
    94  }
    95  
    96  // PreRedeem is an estimate of the fees for redemption. The struct will be
    97  // expanded in in-progress work to accommodate order-time options.
    98  type PreRedeem struct {
    99  	Estimate *RedeemEstimate `json:"estimate"`
   100  	Options  []*OrderOption  `json:"options"`
   101  }
   102  
   103  // MaxOrderForm is used to get a SwapEstimate from the Wallet's MaxOrder method.
   104  type MaxOrderForm struct {
   105  	LotSize       uint64
   106  	FeeSuggestion uint64
   107  	AssetVersion  uint32 // the init/from asset version
   108  	MaxFeeRate    uint64 // max fee rate of init/from asset
   109  
   110  	// The following Redeem asset fields are only required for certain assets
   111  	// where redeeming the other asset may require funds of the "from" asset
   112  	// (this wallet's asset) to be reserved. e.g. ERC20 tokens bought with ETH.
   113  
   114  	RedeemVersion uint32 // the redeem/to asset version
   115  	RedeemAssetID uint32 // the redeem/to asset ID
   116  }