github.com/mavryk-network/mvgo@v1.19.9/rpc/balance.go (about) 1 // Copyright (c) 2020-2024 Blockwatch Data Inc. 2 // Author: alex@blockwatch.cc 3 4 package rpc 5 6 import "github.com/mavryk-network/mvgo/mavryk" 7 8 // BalanceUpdate is a variable structure depending on the Kind field 9 type BalanceUpdate struct { 10 Kind string `json:"kind"` // contract, freezer, accumulator, commitment, minted, burned 11 Origin string `json:"origin"` // block, migration, subsidy 12 Category string `json:"category"` // optional, used on mint, burn, freezer 13 Change int64 `json:"change,string"` // amount, <0 = 14 15 // related debtor or creditor 16 Contract mavryk.Address `json:"contract"` // contract only 17 Delegate mavryk.Address `json:"delegate"` // freezer and burn only 18 Committer mavryk.Address `json:"committer"` // committer only 19 20 // Ithaca only 21 IsParticipationBurn bool `json:"participation"` // burn only 22 IsRevelationBurn bool `json:"revelation"` // burn only 23 24 // legacy freezer cycle 25 Level_ int64 `json:"level"` // wrongly called level, it's cycle 26 Cycle_ int64 `json:"cycle"` // v4 fix, also used in Atlas for unstake 27 28 // smart rollup 29 BondId struct { 30 SmartRollup mavryk.Address `json:"smart_rollup"` 31 } `json:"bond_id"` 32 33 // Atlas staking 34 Staker struct { 35 Contract mavryk.Address `json:"contract"` // mv1/2/3 accounts (only stake, unstake) 36 Delegate mavryk.Address `json:"delegate"` // baker 37 Baker mavryk.Address `json:"baker"` // baker 38 BakerOwnStake mavryk.Address `json:"baker_own_stake"` // baker: replaced baker in v19 39 BakerEdge mavryk.Address `json:"baker_edge"` // baker: new in v19 40 } `json:"staker"` 41 DelayedOp mavryk.OpHash `json:"delayed_operation_hash"` 42 } 43 44 // Categories 45 // 46 // # Mint categories 47 // - `nonce revelation rewards` is the source of tokens minted to reward delegates for revealing their nonces 48 // - `double signing evidence rewards` is the source of tokens minted to reward delegates for injecting a double signing evidence 49 // - `endorsing rewards` is the source of tokens minted to reward delegates for endorsing blocks 50 // - `baking rewards` is the source of tokens minted to reward delegates for creating blocks 51 // - `baking bonuses` is the source of tokens minted to reward delegates for validating blocks and including extra endorsements 52 // - `subsidy` is the source of tokens minted to subsidize the liquidity baking CPMM contract 53 // - `invoice` is the source of tokens minted to compensate some users who have contributed to the betterment of the chain 54 // - `commitment` is the source of tokens minted to match commitments made by some users to supply funds for the chain 55 // - `bootstrap` is analogous to `commitment` but is for internal use or testing. 56 // - `minted` is only for internal use and may be used to mint tokens for testing. 57 // 58 // # Burn categories 59 // - `storage fees` is the destination of storage fees burned for consuming storage space on the chain 60 // - `punishments` is the destination of tokens burned as punishment for a delegate that has double baked or double endorsed 61 // - `lost endorsing rewards` is the destination of rewards that were not distributed to a delegate. 62 // - `burned` is only for internal use and testing. 63 // 64 // # Accumulator categories 65 // - `block fees` designates the container account used to collect manager operation fees while block's operations are being applied. Other categories may be added in the future. 66 // 67 // # Freezer categories 68 // - `legacy_deposits`, `legacy_fees`, or `legacy_rewards` represent the accounts of frozen deposits, frozen fees or frozen rewards up to protocol HANGZHOU. 69 // - `deposits` represents the account of frozen deposits in subsequent protocols (replacing the legacy container account `legacy_deposits` above). 70 // - `unstaked_deposits` represent tez for which unstaking has been requested. 71 72 func (b BalanceUpdate) Address() mavryk.Address { 73 switch { 74 case b.Contract.IsValid(): 75 return b.Contract 76 case b.Delegate.IsValid(): 77 return b.Delegate 78 case b.Committer.IsValid(): 79 return b.Committer 80 case b.Staker.Contract.IsValid(): 81 return b.Staker.Contract 82 case b.Staker.Delegate.IsValid(): 83 return b.Staker.Delegate 84 case b.Staker.Baker.IsValid(): 85 return b.Staker.Baker 86 case b.Staker.BakerOwnStake.IsValid(): 87 return b.Staker.BakerOwnStake 88 case b.Staker.BakerEdge.IsValid(): 89 return b.Staker.BakerEdge 90 } 91 return mavryk.Address{} 92 } 93 94 func (b BalanceUpdate) IsSharedStake() bool { 95 return b.Staker.Contract.IsValid() && b.Staker.Delegate.IsValid() 96 } 97 98 func (b BalanceUpdate) IsBakerStake() bool { 99 return b.Staker.Contract.IsValid() && (b.Staker.Delegate.IsValid() || b.Staker.Baker.IsValid()) 100 } 101 102 func (b BalanceUpdate) Amount() int64 { 103 return b.Change 104 } 105 106 func (b BalanceUpdate) AmountAbs() int64 { 107 if b.Change < 0 { 108 return -b.Change 109 } 110 return b.Change 111 } 112 113 func (b BalanceUpdate) Cycle() int64 { 114 if b.Level_ > 0 { 115 return b.Level_ 116 } 117 return b.Cycle_ 118 } 119 120 // BalanceUpdates is a list of balance update operations 121 type BalanceUpdates []BalanceUpdate