Skip to content
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

Merged
merged 2 commits into from Jul 15, 2021
Merged

added loss socialisation to final settlement #3745

merged 2 commits into from Jul 15, 2021

Conversation

ze97286
Copy link
Contributor

@ze97286 ze97286 commented Jul 13, 2021

close #1908

@jeremyletang jeremyletang requested review from EVODelavega, jeremyletang and a team and removed request for EVODelavega July 14, 2021 08:03
Copy link
Member

@jeremyletang jeremyletang left a 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?

collateral/engine.go Show resolved Hide resolved
@@ -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
Copy link
Member

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?

@ze97286
Copy link
Contributor Author

ze97286 commented Jul 14, 2021

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?

yes, not empty but not enough to cover losses. There's both a unit test and an integration test.

Comment on lines 459 to 465
if err != nil {
e.log.Error(
"Failed to get system accounts required for final settlement",
logging.Error(err),
)
return nil, err
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh, fixed

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Copy link
Contributor Author

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))
Copy link
Contributor

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

@ze97286 ze97286 merged commit 876a406 into develop Jul 15, 2021
@ValentinTrinque ValentinTrinque deleted the feature/1908 branch July 19, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement loss socialization for Final Settlement
4 participants