New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added loss socialisation to final settlement #3745
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have not seen that, but do we have tests coverage for cases where the insurance pool is empty, and loss socialization only is used?
@@ -482,6 +610,11 @@ func (e *Engine) FinalSettlement(ctx context.Context, marketID string, transfers | |||
} | |||
responses = append(responses, res) | |||
} | |||
|
|||
if !settle.Balance.IsZero() { | |||
return nil, ErrSettlementBalanceNotZero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this should probably be a panic thinking of it?
yes, not empty but not enough to cover losses. There's both a unit test and an integration test. |
collateral/engine.go
Outdated
if err != nil { | ||
e.log.Error( | ||
"Failed to get system accounts required for final settlement", | ||
logging.Error(err), | ||
) | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was above the loop, should this be inside the loop now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh, fixed
collateral/engine_test.go
Outdated
marginMoneyTrader, err := eng.Engine.CreatePartyMarginAccount(context.Background(), moneyTrader, testMarketID, testMarketAsset) | ||
_, _ = eng.Engine.CreatePartyGeneralAccount(context.Background(), winTrader1, testMarketAsset) | ||
_, err = eng.Engine.CreatePartyMarginAccount(context.Background(), winTrader1, testMarketID, testMarketAsset) | ||
// eng.Engine.IncrementBalance(context.Background(), margin, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
collateral/engine_test.go
Outdated
err = eng.Engine.IncrementBalance(context.Background(), marginMoneyTrader, num.Sum(priceX3, price, price)) | ||
_, _ = eng.Engine.CreatePartyGeneralAccount(context.Background(), winTrader2, testMarketAsset) | ||
_, err = eng.Engine.CreatePartyMarginAccount(context.Background(), winTrader2, testMarketID, testMarketAsset) | ||
// eng.Engine.IncrementBalance(context.Background(), margin, 700) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
|
||
// accumulate the expected transfer size | ||
expCollected.AddSum(req.Amount) | ||
expectCollected = expectCollected.Add(num.DecimalFromUint(req.Amount)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is a decimal
close #1908