-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfees.go
78 lines (60 loc) · 3.69 KB
/
fees.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package tezosprotocol
import "math/big"
// ComputeMinimumFee returns the minimum fee required according to the constraint:
// fees >= (minimal_fees + minimal_nanotez_per_byte * size + minimal_nanotez_per_gas_unit * gas)
// Amount returned is in units of mutez.
// Reference: http://tezos.gitlab.io/mainnet/protocols/003_PsddFKi3.html#baker
func ComputeMinimumFee(gasLimit, operationSizeBytes *big.Int) *big.Int {
storageFee := new(big.Int).Mul(operationSizeBytes, big.NewInt(DefaultMinimalNanotezPerByte))
storageFee = new(big.Int).Div(storageFee, big.NewInt(1000))
gasFee := new(big.Int).Mul(gasLimit, big.NewInt(DefaultMinimalNanotezPerGasUnit))
gasFee = new(big.Int).Div(gasFee, big.NewInt(1000))
totalFee := new(big.Int).Add(storageFee, gasFee)
totalFee = new(big.Int).Add(totalFee, big.NewInt(DefaultMinimalFees))
return totalFee
}
// Common values for fees
const (
// StorageCostPerByte is the amount of mutez burned per byte of storage used.
// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_protocol/constants_repr.ml#L126
StorageCostPerByte = int64(1000)
// NewAccountStorageLimitBytes is the storage needed to create a new
// account, either implicit or originated.
NewAccountStorageLimitBytes = int64(257)
// NewAccountCreationBurn is the cost in mutez burned from an account that signs
// an operation creating a new account, either by a transferring to a new implicit address
// or by originating a KT1 address. The value is equal to ꜩ0.257
NewAccountCreationBurn = NewAccountStorageLimitBytes * StorageCostPerByte
// DefaultMinimalFees is a flat fee that represents the cost of broadcasting
// an operation to the network. This flat fee is added to the variable minimal
// fees for gas spent and storage used.
// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L251
DefaultMinimalFees = int64(100)
// DefaultMinimalMutezPerGasUnit is the default fee rate in mutez that nodes expect
// per unit gas spent by an operation (and all its contents).
// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L252
DefaultMinimalNanotezPerGasUnit = int64(100)
// DefaultMinimalMutezPerByte is the default fee rate in mutez that nodes expect per
// byte of a serialized, signed operation -- including header and all contents.
// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L253
DefaultMinimalNanotezPerByte = int64(1000)
// RevelationGasLimit is the gas consumed by a revelation
RevelationGasLimit = int64(10000)
// RevelationStorageLimitBytes is the storage limit required for revelations. Note that
// it is zero.
RevelationStorageLimitBytes = int64(0)
// RevelationStorageBurn is the amount burned by an account as a consequence
// of signing a revelation. Note that it is zero.
RevelationStorageBurn = RevelationStorageLimitBytes * StorageCostPerByte
// MinimumTransactionGasLimit is the gas consumed by a transaction with no parameters
// that does not result in any Michelson code execution.
MinimumTransactionGasLimit = int64(10207)
// DelegationGasLimit is the gas consumed by a delegation
DelegationGasLimit = int64(10000)
// DelegationStorageLimitBytes is the storage limit required for delegations. Note that
// it is zero.
DelegationStorageLimitBytes = int64(0)
// DelegationStorageBurn is the amount burned by an account as a consequence
// of signing a delegation. Note that it is zero.
DelegationStorageBurn = DelegationStorageLimitBytes * StorageCostPerByte
)