banking

package
v0.75.8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

README

banking

This package provide an engine which is an abstraction on top of the Collateral engined and the External Resource checker.

One method will be provided for each type of ChainEvent dealing with Collateral and for each asset supported, as of now:

  • Asset_Allowlisted
  • Asset_Deposited
  • Asset_Withdrawn

Once one of these methods called, the banking will setup into the external resource checker some validation to be done, e.g: Asset_Deposited validation for an erc20 token requires to look at the eth event logs to confirm that the deposit really did happen.

After the validation is confirmed, the engine will finalize the processing of the ChainEvent by calling the appropriate function on the Collateral engine.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecurringTransferDoesNotExists             = errors.New("recurring transfer does not exists")
	ErrCannotCancelOtherPartiesRecurringTransfers = errors.New("cannot cancel other parties recurring transfers")
)
View Source
var (
	ErrWrongAssetTypeUsedInBuiltinAssetChainEvent = errors.New("non builtin asset used for builtin asset chain event")
	ErrWrongAssetTypeUsedInERC20ChainEvent        = errors.New("non ERC20 for ERC20 chain event")
	ErrWrongAssetUsedForERC20Withdraw             = errors.New("non erc20 asset used for lock withdraw")
	ErrInvalidWithdrawalState                     = errors.New("invalid withdrawal state")
	ErrNotMatchingWithdrawalForReference          = errors.New("invalid reference for withdrawal chain event")
	ErrWithdrawalNotReady                         = errors.New("withdrawal not ready")
	ErrNotEnoughFundsToTransfer                   = errors.New("not enough funds to transfer")
)
View Source
var (
	ErrInvalidWithdrawalReferenceNonce       = errors.New("invalid withdrawal reference nonce")
	ErrWithdrawalAmountUnderMinimalRequired  = errors.New("invalid withdrawal, amount under minimum required")
	ErrAssetAlreadyBeingListed               = errors.New("asset already being listed")
	ErrWithdrawalDisabledWhenBridgeIsStopped = errors.New("withdrawal issuance is disabled when the erc20 is stopped")
)
View Source
var (
	ErrStartEpochInThePast                                     = errors.New("start epoch in the past")
	ErrCannotSubmitDuplicateRecurringTransferWithSameFromAndTo = errors.New("cannot submit duplicate recurring transfer with same from and to")
)
View Source
var ErrUnknownAssetAction = errors.New("unknown asset action")
View Source
var ErrUnsupportedTransferKind = errors.New("unsupported transfer kind")

Functions

func EstimateFee added in v0.74.0

func EstimateFee(
	assetQuantum num.Decimal,
	maxQuantumAmount num.Decimal,
	transferFeeFactor num.Decimal,
	amount *num.Uint,
	accumulatedDiscount *num.Uint,
	from string,
	fromAccountType types.AccountType,
	to string,
) (fee *num.Uint, discount *num.Uint)

EstimateFee returns a transaction fee estimate with potential discount that can be applied to it.

Types

type Assets

type Assets interface {
	Get(assetID string) (*assets.Asset, error)
	Enable(ctx context.Context, assetID string) error
	ApplyAssetUpdate(ctx context.Context, assetID string) error
}

type Collateral

type Collateral interface {
	Deposit(ctx context.Context, party, asset string, amount *num.Uint) (*types.LedgerMovement, error)
	Withdraw(ctx context.Context, party, asset string, amount *num.Uint) (*types.LedgerMovement, error)
	EnableAsset(ctx context.Context, asset types.Asset) error
	GetPartyGeneralAccount(party, asset string) (*types.Account, error)
	GetPartyVestedRewardAccount(partyID, asset string) (*types.Account, error)
	TransferFunds(ctx context.Context,
		transfers []*types.Transfer,
		accountTypes []types.AccountType,
		references []string,
		feeTransfers []*types.Transfer,
		feeTransfersAccountTypes []types.AccountType,
	) ([]*types.LedgerMovement, error)
	GovernanceTransferFunds(ctx context.Context, transfers []*types.Transfer, accountTypes []types.AccountType, references []string) ([]*types.LedgerMovement, error)
	PropagateAssetUpdate(ctx context.Context, asset types.Asset) error
	GetSystemAccountBalance(asset, market string, accountType types.AccountType) (*num.Uint, error)
}

Collateral engine.

type Config

type Config struct {
	// logging level
	Level encoding.LogLevel `long:"log-level"`
}

Config represents governance specific configuration.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration.

type ERC20BridgeView

type ERC20BridgeView interface {
	FindAssetList(al *types.ERC20AssetList, blockNumber, logIndex uint64, txHash string) error
	FindBridgeStopped(al *types.ERC20EventBridgeStopped, blockNumber, logIndex uint64, txHash string) error
	FindBridgeResumed(al *types.ERC20EventBridgeResumed, blockNumber, logIndex uint64, txHash string) error
	FindDeposit(d *types.ERC20Deposit, blockNumber, logIndex uint64, ethAssetAddress string, txHash string) error
	FindAssetLimitsUpdated(update *types.ERC20AssetLimitsUpdated, blockNumber uint64, logIndex uint64, ethAssetAddress string, txHash string) error
}

type Engine

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

func New

func New(
	log *logging.Logger,
	cfg Config,
	col Collateral,
	witness Witness,
	tsvc TimeService,
	assets Assets,
	notary Notary,
	broker broker.Interface,
	top Topology,
	marketActivityTracker MarketActivityTracker,
	bridgeView ERC20BridgeView,
	ethEventSource EthereumEventSource,
) (e *Engine)

func (*Engine) ApplyFeeDiscount added in v0.74.0

func (e *Engine) ApplyFeeDiscount(ctx context.Context, asset string, party string, fee *num.Uint) (discountedFee *num.Uint, discount *num.Uint)

func (*Engine) AvailableFeeDiscount added in v0.74.0

func (e *Engine) AvailableFeeDiscount(asset string, party string) *num.Uint

func (*Engine) BridgeResumed

func (e *Engine) BridgeResumed(
	ctx context.Context,
	resumed bool,
	id string,
	block, logIndex uint64,
	ethTxHash string,
) error

func (*Engine) BridgeStopped

func (e *Engine) BridgeStopped(
	ctx context.Context,
	stopped bool,
	id string,
	block, logIndex uint64,
	ethTxHash string,
) error

func (*Engine) CalculateGovernanceTransferAmount added in v0.72.0

func (e *Engine) CalculateGovernanceTransferAmount(asset string, market string, accountType types.AccountType, fraction num.Decimal, amount *num.Uint, transferType vegapb.GovernanceTransferType) (*num.Uint, error)

CalculateGovernanceTransferAmount calculates the balance of a governance transfer as follows:

transfer_amount = min(

proposal.fraction_of_balance * source.balance,
proposal.amount,
NETWORK_MAX_AMOUNT,
NETWORK_MAX_FRACTION * source.balance

) where NETWORK_MAX_AMOUNT is a network parameter specifying the maximum absolute amount that can be transferred by governance for the source account type NETWORK_MAX_FRACTION is a network parameter specifying the maximum fraction of the balance that can be transferred by governance for the source account type (must be <= 1)

If type is "all or nothing" then the transfer will only proceed if:

transfer_amount == min(proposal.fraction_of_balance * source.balance,proposal.amount).

func (*Engine) CancelGovTransfer added in v0.72.0

func (e *Engine) CancelGovTransfer(ctx context.Context, ID string) error

func (*Engine) CancelTransferFunds

func (e *Engine) CancelTransferFunds(
	ctx context.Context,
	cancel *types.CancelTransferFunds,
) error

func (*Engine) CheckTransfer added in v0.68.0

func (e *Engine) CheckTransfer(t *types.TransferBase) error

func (*Engine) Checkpoint

func (e *Engine) Checkpoint() ([]byte, error)

func (*Engine) DepositBuiltinAsset

func (e *Engine) DepositBuiltinAsset(
	ctx context.Context, d *types.BuiltinAssetDeposit, id string, nonce uint64,
) error

func (*Engine) DepositERC20

func (e *Engine) DepositERC20(
	ctx context.Context,
	d *types.ERC20Deposit,
	id string,
	blockNumber, logIndex uint64,
	txHash string,
) error

func (*Engine) ERC20WithdrawalEvent

func (e *Engine) ERC20WithdrawalEvent(
	ctx context.Context, w *types.ERC20Withdrawal,
	blockNumber, txIndex uint64,
	txHash string,
) error

func (*Engine) EnableBuiltinAsset

func (e *Engine) EnableBuiltinAsset(ctx context.Context, assetID string) error

func (*Engine) EnableERC20

func (e *Engine) EnableERC20(
	_ context.Context,
	al *types.ERC20AssetList,
	id string,
	blockNumber, txIndex uint64,
	txHash string,
) error

func (*Engine) EstimateFeeDiscount added in v0.74.0

func (e *Engine) EstimateFeeDiscount(asset string, party string, fee *num.Uint) (discountedFee *num.Uint, discount *num.Uint)

func (*Engine) GetDispatchStrategy added in v0.73.0

func (e *Engine) GetDispatchStrategy(hash string) *proto.DispatchStrategy

func (*Engine) GetState

func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)

func (*Engine) Keys

func (e *Engine) Keys() []string

func (*Engine) Load

func (e *Engine) Load(ctx context.Context, data []byte) error

func (*Engine) LoadState

func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)

func (*Engine) Name

func (e *Engine) Name() types.CheckpointName

func (*Engine) Namespace

func (e *Engine) Namespace() types.SnapshotNamespace

func (*Engine) NewGovernanceTransfer added in v0.72.0

func (e *Engine) NewGovernanceTransfer(ctx context.Context, ID, reference string, config *types.NewTransferConfiguration) error

func (*Engine) OnEpoch

func (e *Engine) OnEpoch(ctx context.Context, ep types.Epoch)

func (*Engine) OnEpochRestore

func (e *Engine) OnEpochRestore(ctx context.Context, ep types.Epoch)

func (*Engine) OnMaxAmountChanged added in v0.72.0

func (e *Engine) OnMaxAmountChanged(ctx context.Context, f num.Decimal) error

func (*Engine) OnMaxFractionChanged added in v0.72.0

func (e *Engine) OnMaxFractionChanged(ctx context.Context, f num.Decimal) error

func (*Engine) OnMaxQuantumAmountUpdate added in v0.74.0

func (e *Engine) OnMaxQuantumAmountUpdate(ctx context.Context, f num.Decimal) error

func (*Engine) OnMinTransferQuantumMultiple

func (e *Engine) OnMinTransferQuantumMultiple(ctx context.Context, f num.Decimal) error

func (*Engine) OnMinWithdrawQuantumMultiple added in v0.67.0

func (e *Engine) OnMinWithdrawQuantumMultiple(ctx context.Context, f num.Decimal) error

func (*Engine) OnStateLoaded added in v0.69.0

func (e *Engine) OnStateLoaded(ctx context.Context) error

func (*Engine) OnTick

func (e *Engine) OnTick(ctx context.Context, _ time.Time)

func (*Engine) OnTransferFeeDiscountDecayFractionUpdate added in v0.74.0

func (e *Engine) OnTransferFeeDiscountDecayFractionUpdate(ctx context.Context, v num.Decimal) error

func (*Engine) OnTransferFeeDiscountMinimumTrackedAmountUpdate added in v0.74.0

func (e *Engine) OnTransferFeeDiscountMinimumTrackedAmountUpdate(ctx context.Context, v num.Decimal) error

func (*Engine) OnTransferFeeFactorUpdate

func (e *Engine) OnTransferFeeFactorUpdate(ctx context.Context, f num.Decimal) error

func (*Engine) RegisterTradingFees added in v0.74.0

func (e *Engine) RegisterTradingFees(ctx context.Context, assetID string, feesPerParty map[string]*num.Uint)

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

ReloadConf updates the internal configuration.

func (*Engine) Stopped

func (e *Engine) Stopped() bool

func (*Engine) TransferFunds

func (e *Engine) TransferFunds(
	ctx context.Context,
	transfer *types.TransferFunds,
) error

func (*Engine) UpdateERC20

func (e *Engine) UpdateERC20(
	_ context.Context,
	event *types.ERC20AssetLimitsUpdated,
	id string,
	blockNumber, txIndex uint64,
	txHash string,
) error

func (*Engine) VerifyCancelGovernanceTransfer added in v0.72.0

func (e *Engine) VerifyCancelGovernanceTransfer(transferID string) error

func (*Engine) VerifyGovernanceTransfer added in v0.72.0

func (e *Engine) VerifyGovernanceTransfer(transfer *types.NewTransferConfiguration) error

func (*Engine) WithdrawBuiltinAsset

func (e *Engine) WithdrawBuiltinAsset(
	ctx context.Context, id, party, assetID string, amount *num.Uint,
) error

func (*Engine) WithdrawERC20

func (e *Engine) WithdrawERC20(
	ctx context.Context,
	id, party, assetID string,
	amount *num.Uint,
	ext *types.Erc20WithdrawExt,
) error

type EpochService

type EpochService interface {
	NotifyOnEpoch(f func(context.Context, types.Epoch), r func(context.Context, types.Epoch))
}

Epochervice ...

type EthereumEventSource added in v0.69.0

type EthereumEventSource interface {
	UpdateCollateralStartingBlock(uint64)
}

type MarketActivityTracker

type MarketActivityTracker interface {
	CalculateMetricForIndividuals(ctx context.Context, ds *vega.DispatchStrategy) []*types.PartyContributionScore
	CalculateMetricForTeams(ctx context.Context, ds *vega.DispatchStrategy) ([]*types.PartyContributionScore, map[string][]*types.PartyContributionScore)
	GetMarketsWithEligibleProposer(asset string, markets []string, payoutAsset string, funder string) []*types.MarketContributionScore
	MarkPaidProposer(asset, market, payoutAsset string, marketsInScope []string, funder string)
	MarketTrackedForAsset(market, asset string) bool
	TeamStatsForMarkets(allMarketsForAssets, onlyTheseMarkets []string) map[string]map[string]*num.Uint
}

type Notary

type Notary interface {
	StartAggregate(resID string, kind types.NodeSignatureKind, signature []byte)
	IsSigned(ctx context.Context, id string, kind types.NodeSignatureKind) ([]types.NodeSignature, bool)
	OfferSignatures(kind types.NodeSignatureKind, f func(resources string) []byte)
}

type TimeService

type TimeService interface {
	GetTimeNow() time.Time
}

TimeService provide the time of the vega node using the tm time.

type Topology

type Topology interface {
	IsValidator() bool
}

Topology ...

type Witness

type Witness interface {
	StartCheck(validators.Resource, func(interface{}, bool), time.Time) error
	RestoreResource(validators.Resource, func(interface{}, bool)) error
}

Witness provide foreign chain resources validations.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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