analyzer

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TobinTaxDenominator *big.Int = new(big.Int).Exp(big.NewInt(10), big.NewInt(24), nil)

10^(24) == 1000000000000000000000000

Functions

func AllOperationTypesString

func AllOperationTypesString() []string

func FilterChangesBySubAccount

func FilterChangesBySubAccount(op *Operation, subAccountType SubAccountType) map[common.Address]*big.Int

func MatchAndReconcileLogOpWithTransfer added in v0.6.3

func MatchAndReconcileLogOpWithTransfer(logOp, trOp *Operation, tobinTax *TobinTax, lockedGold common.Address) bool

MatchAndReconcileLogOpWithTransfer returns true if the operations match as is or when we factor in tobin tax

If the operations match with tobin tax, then we reconcile the operations into one by combining their balance changes

operations match with tobin tax iff

logOp.Type == OpLockGold &&
logOp.lockedGoldContractAccMain.diff == trOp.lockedGoldContractAccMain.diff &&
logOp.fromAccMain.diff - trOp.fromAccMain.diff == trOp.tobinRecipientAccMain.diff

Ex. lock(100 cGlD), tobinTax == 10% Transfer Operation:

fromAccMain         	 	-90
lockedGoldContractAccMain    90
fromAccMain			    	-10 // diff == -100
tobinRecipientAccMain        10

LockedGold Operation (created from `GoldLocked(fromAccount, 90)` event):

	fromAccMain                 -90 // diff == -90
	lockedGoldContractAccMain    90
 fromAccLockedNonVoting       90

Reconciled Operation:

	fromAccMain         	 	-90
	lockedGoldContractAccMain    90
	fromAccMain			    	-10
	tobinRecipientAccMain        10
 fromAccLockedNonVoting       90

func MatchChangesOnSubAccount

func MatchChangesOnSubAccount(op1 *Operation, op2 *Operation, subAccountType SubAccountType) bool

Types

type Account

type Account struct {
	Address    common.Address
	SubAccount SubAccount
}

func NewAccount

func NewAccount(addr common.Address, subAccount SubAccountType) Account

func NewSignerAccount added in v0.6.3

func NewSignerAccount(addr common.Address, main common.Address) Account

func NewVotingAccount

func NewVotingAccount(addr common.Address, subAccount SubAccountType, group common.Address) Account

type BalanceChange

type BalanceChange struct {
	Account Account
	Amount  *big.Int
}

type BalanceSet

type BalanceSet struct {
	// contains filtered or unexported fields
}

func NewBalanceSet

func NewBalanceSet() *BalanceSet

func (*BalanceSet) Add

func (bs *BalanceSet) Add(addr common.Address, value *big.Int) *BalanceSet

func (*BalanceSet) ToMap

func (bs *BalanceSet) ToMap() map[common.Address]*big.Int

type ChainParameters

type ChainParameters struct {
	ChainId   *big.Int
	EpochSize uint64
}

func (*ChainParameters) IsLastBlockOfEpoch

func (cp *ChainParameters) IsLastBlockOfEpoch(blockNumber uint64) bool

type Operation

type Operation struct {
	Type       OperationType
	Changes    []BalanceChange
	Successful bool
}

func ComputeEpochRewards

func ComputeEpochRewards(ctx context.Context, cc *client.CeloClient, db db.RosettaDBReader, header *types.Header) (*Operation, error)

func InternalTransfersToOperations added in v0.6.3

func InternalTransfersToOperations(transfers []debug.Transfer, tobinTax *TobinTax) []Operation

func NewActiveVotes

func NewActiveVotes(addr common.Address, group common.Address, value *big.Int) *Operation

func NewAuthorizeSigner added in v0.6.2

func NewAuthorizeSigner(from common.Address, signer common.Address, authorizeOp OperationType) *Operation

func NewCreateAccount added in v0.6.1

func NewCreateAccount(from common.Address) *Operation

func NewEpochRewards

func NewEpochRewards(changes map[common.Address]*big.Int) *Operation

func NewFee

func NewFee(changes map[common.Address]*big.Int) *Operation

func NewLockGold

func NewLockGold(addr, lockedGoldAddr common.Address, value *big.Int) *Operation

Ex. lock(100 cGlD), tobinTax == 10% Transfer Operation:

fromAccMain         	 	-90
lockedGoldContractAccMain    90
fromAccMain			    	-10
tobinRecipientAccMain        10

LockedGold Operation (created from `GoldLocked(fromAccount, 90)` event):

	fromAccMain                 -90
	lockedGoldContractAccMain    90
 fromAccLockedNonVoting       90

Reconciled Operation:

	fromAccMain         	 	-90
	lockedGoldContractAccMain    90
	fromAccMain			    	-10
	tobinRecipientAccMain        10
 fromAccLockedNonVoting       90

func NewRelockGold

func NewRelockGold(addr common.Address, value *big.Int) *Operation

func NewRevokeActiveVotes

func NewRevokeActiveVotes(addr common.Address, group common.Address, value *big.Int) *Operation

func NewRevokePendingVotes

func NewRevokePendingVotes(addr common.Address, group common.Address, value *big.Int) *Operation

func NewSlash

func NewSlash(slashed, slasher, communityFund, lockedGoldAddr common.Address, penalty, reward *big.Int, tobinTax *TobinTax) *Operation

Ex. Slash(penalty=110, reward=100 cGlD), tobinTax == 10% Transfer Operation:

lockedGoldContractAccMain        -9
communityFundAccMain              9
lockedGoldContractAccMain        -1
tobinRecipientAccMain             1

LockedGold Operation (created from `AccountSlashed(slashed, -100, reporter, 110)` event):

slashedAccLockedGoldNonVoting    -110
reporterAccLockedGoldNonVoting    100
lockedGoldContractAccMain        -9
communityFundAccMain              9
lockedGoldContractAccMain        -1
tobinRecipientAccMain             1

func NewTransfer

func NewTransfer(from, to common.Address, value *big.Int, tobinTax *TobinTax, successful bool) *Operation

func NewUnlockGold

func NewUnlockGold(addr common.Address, value *big.Int) *Operation

func NewVote

func NewVote(addr common.Address, group common.Address, value *big.Int) *Operation

func NewWithdrawGold

func NewWithdrawGold(addr, lockedGoldAddr common.Address, value *big.Int, tobinTax *TobinTax) *Operation

Ex. Withdraw(100 cGlD), tobinTax == 10% Transfer Operation:

lockedGoldContractAccMain   -90
toAccMain         	 	     90
lockedGoldContractAccMain   -10
tobinRecipientAccMain        10

LockedGold Operation (created from `GoldWithdraw(toAccount, 100)` event):

	lockedGoldContractAccMain   -90
	toAccMain         	 	     90
	lockedGoldContractAccMain   -10
	tobinRecipientAccMain        10
 AccLockedPending            -100

func ReconcileLogOpsWithTransfers added in v0.6.3

func ReconcileLogOpsWithTransfers(logOps, transferOps []Operation, tobinTax *TobinTax, lockedGold common.Address) ([]Operation, error)

ReconcileLogOpsWithTransfers merges operations derived from the tx logs with transfers derived from the tx tracer into one slice that contains no duplicate operations.

See NewLockGold, NewWithdrawal, NewSlash for examples.

type OperationType

type OperationType string
const (
	OpFee                        OperationType = "fee"
	OpTransfer                   OperationType = "transfer"
	OpCreateAccount              OperationType = "createAccount"
	OpAuthorizeVoteSigner        OperationType = "authorizeVoteSigner"
	OpAuthorizeValidatorSigner   OperationType = "authorizeValidatorSigner"
	OpAuthorizeAttestationSigner OperationType = "authorizeAttestationSigner"
	OpLockGold                   OperationType = "lockGold"
	OpUnlockGold                 OperationType = "unlockGold"
	OpRelockGold                 OperationType = "relockGold"
	OpWithdrawGold               OperationType = "withdrawGold"
	OpVote                       OperationType = "vote"
	OpActiveVotes                OperationType = "activateVotes"
	OpRevokePendingVotes         OperationType = "revokePendingVotes"
	OpRevokeActiveVotes          OperationType = "revokeActiveVotes"
	OpSlash                      OperationType = "slash"
	OpEpochRewards               OperationType = "epochRewards"
)

func (OperationType) String

func (ot OperationType) String() string

type SubAccount

type SubAccount struct {
	Identifier SubAccountType
	Metadata   map[string]interface{}
}

type SubAccountType

type SubAccountType string
const (
	AccMain                        SubAccountType = "Main"
	AccSigner                      SubAccountType = "AccountsAuthorizedSigner"
	AccLockedGoldNonVoting         SubAccountType = "LockedGoldNonVoting"
	AccLockedGoldVotingActive      SubAccountType = "LockedGoldVotingActive"
	AccLockedGoldVotingPending     SubAccountType = "LockedGoldVotingPending"
	AccLockedGoldPending           SubAccountType = "LockedGoldPending"
	AccReleaseGoldVested           SubAccountType = "ReleaseGoldVested"
	AccReleaseGoldUnvestedLocked   SubAccountType = "ReleaseGoldUnvestedLocked"
	AccReleaseGoldUnvestedUnLocked SubAccountType = "ReleaseGoldUnvestedUnlocked"
)

type TobinTax added in v0.6.3

type TobinTax struct {
	Numerator *big.Int
	Recipient common.Address
}

func NewTobinTax added in v0.6.3

func NewTobinTax(numerator *big.Int, recipient common.Address) *TobinTax

func (*TobinTax) Apply added in v0.6.3

func (tt *TobinTax) Apply(value *big.Int) (taxAmount, afterTaxAmount *big.Int)

func (*TobinTax) IsDefined added in v0.6.3

func (tt *TobinTax) IsDefined() bool

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

func NewTracer

func NewTracer(ctx context.Context, cc *client.CeloClient, db db.RosettaDBReader, traceTimeout time.Duration) *Tracer

func (*Tracer) GetRegistryAddresses added in v0.6.3

func (tr *Tracer) GetRegistryAddresses(receipt *types.Receipt, contractNames ...string) (map[string]common.Address, error)

func (*Tracer) GetTobinTax added in v0.6.3

func (tr *Tracer) GetTobinTax(blockNumber *big.Int, reserve common.Address) (*TobinTax, error)

func (*Tracer) TraceTransaction

func (tr *Tracer) TraceTransaction(blockHeader *types.Header, tx *types.Transaction, receipt *types.Receipt) ([]Operation, error)

func (*Tracer) TxGasDetails

func (tr *Tracer) TxGasDetails(coinbase common.Address, tx *types.Transaction, receipt *types.Receipt) (*Operation, error)

func (*Tracer) TxOpsFromLogs added in v0.6.3

func (tr *Tracer) TxOpsFromLogs(tx *types.Transaction, receipt *types.Receipt, tobinTax *TobinTax, contractMap map[string]common.Address) ([]Operation, error)

func (*Tracer) TxTransfers

func (tr *Tracer) TxTransfers(tx *types.Transaction, receipt *types.Receipt, tobinTax *TobinTax) ([]Operation, error)

type Transfer

type Transfer struct {
	From   Account
	To     Account
	Value  *big.Int
	Status bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL