banking

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 27 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

This section is empty.

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)
	TransferFunds(ctx context.Context,
		transfers []*types.Transfer,
		accountTypes []types.AccountType,
		references []string,
		feeTransfers []*types.Transfer,
		feeTransfersAccountTypes []types.AccountType,
	) ([]*types.LedgerMovement, error)
	PropagateAssetUpdate(ctx context.Context, asset types.Asset) 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) error
	FindBridgeStopped(al *types.ERC20EventBridgeStopped, blockNumber, logIndex uint64) error
	FindBridgeResumed(al *types.ERC20EventBridgeResumed, blockNumber, logIndex uint64) error
	FindDeposit(d *types.ERC20Deposit, blockNumber, logIndex uint64, ethAssetAddress string) error
	FindAssetLimitsUpdated(update *types.ERC20AssetLimitsUpdated, blockNumber uint64, logIndex uint64, ethAssetAddress 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,
	epoch EpochService,
	marketActivityTracker MarketActivityTracker,
	bridgeView ERC20BridgeView,
) (e *Engine)

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) CancelTransferFunds

func (e *Engine) CancelTransferFunds(
	ctx context.Context,
	cancel *types.CancelTransferFunds,
) 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) 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) 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) 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) OnTick

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

func (*Engine) OnTransferFeeFactorUpdate

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

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) 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 MarketActivityTracker

type MarketActivityTracker interface {
	GetMarketScores(asset string, markets []string, dispatchMetric proto.DispatchMetric) []*types.MarketContributionScore
	GetMarketsWithEligibleProposer(asset string, markets []string, payoutAsset string, funder string) []*types.MarketContributionScore
	MarkPaidProposer(market, payoutAsset string, marketsInScope []string, funder string)
}

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