Documentation ¶
Index ¶
- Variables
- type Broker
- type Config
- type Engine
- func (e *Engine) ADtoID(ad *types.AccountDetails) string
- func (e *Engine) AssetExists(assetID string) bool
- func (e *Engine) BondUpdate(ctx context.Context, market string, transfer *types.Transfer) (*types.LedgerMovement, error)
- func (e *Engine) CanCoverBond(market, party, asset string, amount *num.Uint) bool
- func (e *Engine) CheckLeftOverBalance(ctx context.Context, settle *types.Account, transfers []*types.Transfer, ...) (*types.LedgerMovement, error)
- func (e *Engine) Checkpoint() ([]byte, error)
- func (e *Engine) ClearMarket(ctx context.Context, mktID, asset string, parties []string) ([]*types.LedgerMovement, error)
- func (e *Engine) ClearPartyMarginAccount(ctx context.Context, party, market, asset string) (*types.LedgerMovement, error)
- func (e *Engine) CreateMarketAccounts(ctx context.Context, marketID, asset string) (insuranceID, settleID string, err error)
- func (e *Engine) CreatePartyBondAccount(ctx context.Context, partyID, marketID, asset string) (string, error)
- func (e *Engine) CreatePartyGeneralAccount(ctx context.Context, partyID, asset string) (string, error)
- func (e *Engine) CreatePartyMarginAccount(ctx context.Context, partyID, marketID, asset string) (string, error)
- func (e *Engine) Deposit(ctx context.Context, partyID, asset string, amount *num.Uint) (*types.LedgerMovement, error)
- func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error
- func (e *Engine) FinalSettlement(ctx context.Context, marketID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error)
- func (e *Engine) GetAccountByID(id string) (*types.Account, error)
- func (e *Engine) GetAssetQuantum(asset string) (num.Decimal, error)
- func (e *Engine) GetEnabledAssets() []string
- func (e *Engine) GetGlobalRewardAccount(asset string) (*types.Account, error)
- func (e *Engine) GetInfraFeeAccountIDs() []string
- func (e *Engine) GetMarketInsurancePoolAccount(market, asset string) (*types.Account, error)
- func (e *Engine) GetMarketLiquidityFeeAccount(market, asset string) (*types.Account, error)
- func (e *Engine) GetOrCreateMarketInsurancePoolAccount(ctx context.Context, market, asset string) *types.Account
- func (e *Engine) GetOrCreatePartyBondAccount(ctx context.Context, partyID, marketID, asset string) (*types.Account, error)
- func (e *Engine) GetOrCreateRewardAccount(ctx context.Context, asset string, market string, ...) (*types.Account, error)
- func (e *Engine) GetPartyBondAccount(market, partyID, asset string) (*types.Account, error)
- func (e *Engine) GetPartyGeneralAccount(partyID, asset string) (*types.Account, error)
- func (e *Engine) GetPartyMargin(pos events.MarketPosition, asset, marketID string) (events.Margin, error)
- func (e *Engine) GetPartyMarginAccount(market, party, asset string) (*types.Account, error)
- func (e *Engine) GetPendingTransfersAccount(asset string) *types.Account
- func (e *Engine) GetRewardAccountsByType(rewardAcccountType types.AccountType) []*types.Account
- func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *Engine) HasGeneralAccount(party, asset string) bool
- func (e *Engine) Hash() []byte
- func (e *Engine) IncrementBalance(ctx context.Context, id string, inc *num.Uint) error
- func (e *Engine) Keys() []string
- func (e *Engine) Load(ctx context.Context, data []byte) error
- func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)
- func (e *Engine) MarginUpdate(ctx context.Context, marketID string, updates []events.Risk) ([]*types.LedgerMovement, []events.Margin, []events.Margin, error)
- func (e *Engine) MarginUpdateOnOrder(ctx context.Context, marketID string, update events.Risk) (*types.LedgerMovement, events.Margin, error)
- func (e *Engine) MarkToMarket(ctx context.Context, marketID string, transfers []events.Transfer, ...) ([]events.Margin, []*types.LedgerMovement, error)
- func (e *Engine) Name() types.CheckpointName
- func (e *Engine) Namespace() types.SnapshotNamespace
- func (e *Engine) PropagateAssetUpdate(ctx context.Context, asset types.Asset) error
- func (e *Engine) ReloadConf(cfg Config)
- func (e *Engine) RemoveBondAccount(partyID, marketID, asset string) error
- func (e *Engine) RemoveDistressed(ctx context.Context, parties []events.MarketPosition, marketID, asset string) (*types.LedgerMovement, error)
- func (e *Engine) RestoreCheckpointBalance(ctx context.Context, market, party, asset string, typ types.AccountType, ...) (*types.LedgerMovement, error)
- func (e *Engine) RollbackMarginUpdateOnOrder(ctx context.Context, marketID string, assetID string, transfer *types.Transfer) (*types.LedgerMovement, error)
- func (e *Engine) Stopped() bool
- func (e *Engine) TransferFees(ctx context.Context, marketID string, assetID string, ft events.FeesTransfer) ([]*types.LedgerMovement, error)
- func (e *Engine) TransferFeesContinuousTrading(ctx context.Context, marketID string, assetID string, ft events.FeesTransfer) ([]*types.LedgerMovement, error)
- func (e *Engine) TransferFunds(ctx context.Context, transfers []*types.Transfer, ...) ([]*types.LedgerMovement, error)
- func (e *Engine) TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error)
- func (e *Engine) UpdateBalance(ctx context.Context, id string, balance *num.Uint) error
- func (e *Engine) Withdraw(ctx context.Context, partyID, asset string, amount *num.Uint) (*types.LedgerMovement, error)
- type TimeService
Constants ¶
This section is empty.
Variables ¶
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") )
Functions ¶
This section is empty.
Types ¶
type Broker ¶
Broker send events we no longer need to generate this mock here, we can use the broker/mocks package instead.
type Config ¶
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 (*Engine) AssetExists ¶
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 (*Engine) CheckLeftOverBalance ¶ added in v0.58.0
func (*Engine) Checkpoint ¶
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 (*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 ¶
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 ¶
GetAccountByID will return an account using the given id.
func (*Engine) GetAssetQuantum ¶
func (*Engine) GetEnabledAssets ¶
GetEnabledAssets returns the asset IDs of all enabled assets.
func (*Engine) GetGlobalRewardAccount ¶
func (*Engine) GetInfraFeeAccountIDs ¶
GetInfraFeeAccountIDs returns the account IDs of the infrastructure fee accounts for all enabled assets.
func (*Engine) GetMarketInsurancePoolAccount ¶
func (*Engine) GetMarketLiquidityFeeAccount ¶
func (*Engine) GetOrCreateMarketInsurancePoolAccount ¶ added in v0.71.0
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 ¶
GetPartyBondAccount returns a general account given the partyID.
func (*Engine) GetPartyGeneralAccount ¶
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 ¶
GetPartyMarginAccount returns a margin account given the partyID and market.
func (*Engine) GetPendingTransfersAccount ¶
GetPendingTransferAccount return the pending transfers account for the asset.
func (*Engine) GetRewardAccountsByType ¶
func (e *Engine) GetRewardAccountsByType(rewardAcccountType types.AccountType) []*types.Account
func (*Engine) HasGeneralAccount ¶
func (*Engine) IncrementBalance ¶
IncrementBalance will increment the balance of a given account using the given value.
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 (*Engine) ReloadConf ¶
ReloadConf updates the internal configuration of the collateral engine.
func (*Engine) RemoveBondAccount ¶ added in v0.69.0
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) 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 ¶
UpdateBalance will update the balance of a given account.
type TimeService ¶
TimeService provide the time of the vega node.