collateral

package
v0.71.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSystemAccountsMissing signals that a system account is missing, which may means that the
	// collateral engine have not been initialised properly.
	ErrSystemAccountsMissing = errors.New("system accounts missing for collateral engine to work")
	// ErrFeeAccountsMissing signals that a fee account is missing, which may means that the
	// collateral engine have not been initialised properly.
	ErrFeeAccountsMissing = errors.New("fee accounts missing for collateral engine to work")
	// ErrPartyAccountsMissing signals that the accounts for this party do not exists.
	ErrPartyAccountsMissing = errors.New("party accounts missing, cannot collect")
	// ErrAccountDoesNotExist signals that an account par of a transfer do not exists.
	ErrAccountDoesNotExist                     = errors.New("account does not exists")
	ErrNoGeneralAccountWhenCreateMarginAccount = errors.New("party general account missing when trying to create a margin account")
	ErrNoGeneralAccountWhenCreateBondAccount   = errors.New("party general account missing when trying to create a bond account")
	ErrMinAmountNotReached                     = errors.New("unable to reach minimum amount transfer")
	ErrPartyHasNoTokenAccount                  = errors.New("no token account for party")
	ErrSettlementBalanceNotZero                = errors.New("settlement balance should be zero") // E991 YOU HAVE TOO MUCH ROPE TO HANG YOURSELF
	// ErrAssetAlreadyEnabled signals the given asset has already been enabled in this engine.
	ErrAssetAlreadyEnabled    = errors.New("asset already enabled")
	ErrAssetHasNotBeenEnabled = errors.New("asset has not been enabled")
	// ErrInvalidAssetID signals that an asset id does not exists.
	ErrInvalidAssetID = errors.New("invalid asset ID")
	// ErrInsufficientFundsToPayFees the party do not have enough funds to pay the feeds.
	ErrInsufficientFundsToPayFees = errors.New("insufficient funds to pay fees")
	// ErrInvalidTransferTypeForFeeRequest an invalid transfer type was send to build a fee transfer request.
	ErrInvalidTransferTypeForFeeRequest = errors.New("an invalid transfer type was send to build a fee transfer request")
	// ErrNotEnoughFundsToWithdraw a party requested to withdraw more than on its general account.
	ErrNotEnoughFundsToWithdraw = errors.New("not enough funds to withdraw")
)
View Source
var (
	ErrSnapshotKeyDoesNotExist  = errors.New("unknown key for collateral snapshot")
	ErrInvalidSnapshotNamespace = errors.New("invalid snapshot namespace")
	ErrUnknownSnapshotType      = errors.New("snapshot data type not known")
)

Functions

This section is empty.

Types

type Broker

type Broker interface {
	Send(event events.Event)
	SendBatch(events []events.Event)
}

Broker send events we no longer need to generate this mock here, we can use the broker/mocks package instead.

type Config

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

Config represent the configuration of the collateral engine.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type Engine

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

Engine is handling the power of the collateral.

func New

func New(log *logging.Logger, conf Config, ts TimeService, broker Broker) *Engine

New instantiates a new collateral engine.

func (*Engine) ADtoID added in v0.56.0

func (e *Engine) ADtoID(ad *types.AccountDetails) string

func (*Engine) AssetExists

func (e *Engine) AssetExists(assetID string) bool

AssetExists no errors if the asset exists.

func (*Engine) BondUpdate

func (e *Engine) BondUpdate(ctx context.Context, market string, transfer *types.Transfer) (*types.LedgerMovement, error)

BondUpdate is to be used for any bond account transfers. Update on new orders, updates on commitment changes, or on slashing.

func (*Engine) CanCoverBond

func (e *Engine) CanCoverBond(market, party, asset string, amount *num.Uint) bool

func (*Engine) CheckLeftOverBalance added in v0.58.0

func (e *Engine) CheckLeftOverBalance(ctx context.Context, settle *types.Account, transfers []*types.Transfer, asset string) (*types.LedgerMovement, error)

func (*Engine) Checkpoint

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

func (*Engine) ClearMarket

func (e *Engine) ClearMarket(ctx context.Context, mktID, asset string, parties []string) ([]*types.LedgerMovement, error)

ClearMarket will remove all monies or accounts for parties allocated for a market (margin accounts) when the market reach end of life (maturity).

func (*Engine) ClearPartyMarginAccount

func (e *Engine) ClearPartyMarginAccount(ctx context.Context, party, market, asset string) (*types.LedgerMovement, error)

func (*Engine) CreateMarketAccounts

func (e *Engine) CreateMarketAccounts(ctx context.Context, marketID, asset string) (insuranceID, settleID string, err error)

CreateMarketAccounts will create all required accounts for a market once a new market is accepted through the network.

func (*Engine) CreatePartyBondAccount

func (e *Engine) CreatePartyBondAccount(ctx context.Context, partyID, marketID, asset string) (string, error)

CreatePartyBondAccount creates a bond account if it does not exist, will return an error if no general account exist for the party for the given asset.

func (*Engine) CreatePartyGeneralAccount

func (e *Engine) CreatePartyGeneralAccount(ctx context.Context, partyID, asset string) (string, error)

CreatePartyGeneralAccount create the general account for a party.

func (*Engine) CreatePartyMarginAccount

func (e *Engine) CreatePartyMarginAccount(ctx context.Context, partyID, marketID, asset string) (string, error)

CreatePartyMarginAccount creates a margin account if it does not exist, will return an error if no general account exist for the party for the given asset.

func (*Engine) Deposit

func (e *Engine) Deposit(ctx context.Context, partyID, asset string, amount *num.Uint) (*types.LedgerMovement, error)

Deposit will deposit the given amount into the party account.

func (*Engine) EnableAsset

func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error

EnableAsset adds a new asset in the collateral engine this enable the asset to be used by new markets or parties to deposit funds.

func (*Engine) FinalSettlement

func (e *Engine) FinalSettlement(ctx context.Context, marketID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error)

FinalSettlement will process the list of transfers instructed by other engines This func currently only expects TransferType_{LOSS,WIN} transfers other transfer types have dedicated funcs (MarkToMarket, MarginUpdate).

func (*Engine) GetAccountByID

func (e *Engine) GetAccountByID(id string) (*types.Account, error)

GetAccountByID will return an account using the given id.

func (*Engine) GetAssetQuantum

func (e *Engine) GetAssetQuantum(asset string) (num.Decimal, error)

func (*Engine) GetEnabledAssets

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

GetEnabledAssets returns the asset IDs of all enabled assets.

func (*Engine) GetGlobalRewardAccount

func (e *Engine) GetGlobalRewardAccount(asset string) (*types.Account, error)

func (*Engine) GetInfraFeeAccountIDs

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

GetInfraFeeAccountIDs returns the account IDs of the infrastructure fee accounts for all enabled assets.

func (*Engine) GetMarketInsurancePoolAccount

func (e *Engine) GetMarketInsurancePoolAccount(market, asset string) (*types.Account, error)

func (*Engine) GetMarketLiquidityFeeAccount

func (e *Engine) GetMarketLiquidityFeeAccount(market, asset string) (*types.Account, error)

func (*Engine) GetOrCreateMarketInsurancePoolAccount added in v0.71.0

func (e *Engine) GetOrCreateMarketInsurancePoolAccount(ctx context.Context, market, asset string) *types.Account

func (*Engine) GetOrCreatePartyBondAccount

func (e *Engine) GetOrCreatePartyBondAccount(ctx context.Context, partyID, marketID, asset string) (*types.Account, error)

GetOrCreatePartyBondAccount returns a bond account given a set of parameters. crates it if not exists.

func (*Engine) GetOrCreateRewardAccount

func (e *Engine) GetOrCreateRewardAccount(ctx context.Context, asset string, market string, rewardAcccountType types.AccountType) (*types.Account, error)

GetRewardAccount returns a reward accound by asset and type.

func (*Engine) GetPartyBondAccount

func (e *Engine) GetPartyBondAccount(market, partyID, asset string) (*types.Account, error)

GetPartyBondAccount returns a general account given the partyID.

func (*Engine) GetPartyGeneralAccount

func (e *Engine) GetPartyGeneralAccount(partyID, asset string) (*types.Account, error)

GetPartyGeneralAccount returns a general account given the partyID.

func (*Engine) GetPartyMargin

func (e *Engine) GetPartyMargin(pos events.MarketPosition, asset, marketID string) (events.Margin, error)

GetPartyMargin will return the current margin for a given party.

func (*Engine) GetPartyMarginAccount

func (e *Engine) GetPartyMarginAccount(market, party, asset string) (*types.Account, error)

GetPartyMarginAccount returns a margin account given the partyID and market.

func (*Engine) GetPendingTransfersAccount

func (e *Engine) GetPendingTransfersAccount(asset string) *types.Account

GetPendingTransferAccount return the pending transfers account for the asset.

func (*Engine) GetRewardAccountsByType

func (e *Engine) GetRewardAccountsByType(rewardAcccountType types.AccountType) []*types.Account

func (*Engine) GetState

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

func (*Engine) HasGeneralAccount

func (e *Engine) HasGeneralAccount(party, asset string) bool

func (*Engine) Hash

func (e *Engine) Hash() []byte

func (*Engine) IncrementBalance

func (e *Engine) IncrementBalance(ctx context.Context, id string, inc *num.Uint) error

IncrementBalance will increment the balance of a given account using the given value.

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

func (e *Engine) MarginUpdate(ctx context.Context, marketID string, updates []events.Risk) ([]*types.LedgerMovement, []events.Margin, []events.Margin, error)

MarginUpdate will run the margin updates over a set of risk events (margin updates).

func (*Engine) MarginUpdateOnOrder

func (e *Engine) MarginUpdateOnOrder(ctx context.Context, marketID string, update events.Risk) (*types.LedgerMovement, events.Margin, error)

MarginUpdateOnOrder will run the margin updates over a set of risk events (margin updates).

func (*Engine) MarkToMarket

func (e *Engine) MarkToMarket(ctx context.Context, marketID string, transfers []events.Transfer, asset string) ([]events.Margin, []*types.LedgerMovement, error)

MarkToMarket will run the mark to market settlement over a given set of positions return ledger move stuff here, too (separate return value, because we need to stream those).

func (*Engine) Name

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

func (*Engine) Namespace

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

func (*Engine) PropagateAssetUpdate

func (e *Engine) PropagateAssetUpdate(ctx context.Context, asset types.Asset) error

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

ReloadConf updates the internal configuration of the collateral engine.

func (*Engine) RemoveBondAccount added in v0.69.0

func (e *Engine) RemoveBondAccount(partyID, marketID, asset string) error

func (*Engine) RemoveDistressed

func (e *Engine) RemoveDistressed(ctx context.Context, parties []events.MarketPosition, marketID, asset string) (*types.LedgerMovement, error)

RemoveDistressed will remove all distressed party in the event positions for a given market and asset.

func (*Engine) RestoreCheckpointBalance added in v0.56.0

func (e *Engine) RestoreCheckpointBalance(
	ctx context.Context,
	market, party, asset string,
	typ types.AccountType,
	amount *num.Uint,
) (*types.LedgerMovement, error)

RestoreCheckpointBalance will credit account with a balance from a checkpoint. This function assume the accounts have been created before.

func (*Engine) RollbackMarginUpdateOnOrder

func (e *Engine) RollbackMarginUpdateOnOrder(ctx context.Context, marketID string, assetID string, transfer *types.Transfer) (*types.LedgerMovement, error)

RollbackMarginUpdateOnOrder moves funds from the margin to the general account.

func (*Engine) Stopped

func (e *Engine) Stopped() bool

func (*Engine) TransferFees

func (e *Engine) TransferFees(ctx context.Context, marketID string, assetID string, ft events.FeesTransfer) ([]*types.LedgerMovement, error)

func (*Engine) TransferFeesContinuousTrading

func (e *Engine) TransferFeesContinuousTrading(ctx context.Context, marketID string, assetID string, ft events.FeesTransfer) ([]*types.LedgerMovement, error)

func (*Engine) TransferFunds

func (e *Engine) TransferFunds(
	ctx context.Context,
	transfers []*types.Transfer,
	accountTypes []types.AccountType,
	references []string,
	feeTransfers []*types.Transfer,
	feeTransfersAccountType []types.AccountType,
) ([]*types.LedgerMovement, error)

func (*Engine) TransferRewards

func (e *Engine) TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error)

TransferRewards takes a slice of transfers and serves them to transfer rewards from the reward account to parties general account.

func (*Engine) UpdateBalance

func (e *Engine) UpdateBalance(ctx context.Context, id string, balance *num.Uint) error

UpdateBalance will update the balance of a given account.

func (*Engine) Withdraw

func (e *Engine) Withdraw(ctx context.Context, partyID, asset string, amount *num.Uint) (*types.LedgerMovement, error)

Withdraw will remove the specified amount from the party general account.

type TimeService

type TimeService interface {
	GetTimeNow() time.Time
}

TimeService provide the time of the vega node.

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