Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions app/lib/common/asset_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,19 @@ export default class AssetUtils {
* - Settlement Price: feed price * force settlement offset factor
*
*/
if (!!asset.bitasset) {
return asset.bitasset.current_feed.settlement_price;
}
if (!!asset.current_feed) {
return asset.current_feed.settlement_price;
}
if (!!asset.settlement_price) {
return asset.settlement_price;
}
let ret;

if (!!asset.get("bitasset")) {
return asset.getIn([
"bitasset",
"current_feed",
"settlement_price"
]);
asset = asset.get("bitasset");
}
if (!!asset.get("settlement_price")) {
return asset.getIn(["settlement_price"]);
if (!!asset.get("individual_settlement_debt")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@abitmore since we have different black swan handling strategies, which variables are set in which case?

Is settlement_price and individual_settlement_debt both set at the same time, or either or?

Copy link
Member

Choose a reason for hiding this comment

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

IMO, since the extractRawFeedPrice() function is used in different places for different purposes, we should be careful when updating code here to avoid introducing new bugs.

  1. We should always use median_feeds.settlement_price when borrowing, to calculate CR and etc.
  2. Use current_feed.settlement_price when displaying the "yellow" orders (margin calls) on the order book, placing limit order to buy into the margin calls, or requesting forced-settlements (note that it's not for the scenario when BSRM is 0 and a black swan event had happened), etc.
  3. When BSRM is 1 or 2, median_feeds.settlement_price and current_feed.settlement_price can be different when there was a black swan event.

settlement_price is set when BSRM is 0 and a black swan event happens. It is used in this case for forced-settlements. Check the USD asset on chain.

individual_settlement_debt is set when BSRM is (2 or 3) and a black swan event happens. Check the CNY and SGD assets on chain.

ret = asset.get("median_feed").get("settlement_price");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment how it relates, and why

Copy link
Contributor

Choose a reason for hiding this comment

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

If it has a positive individual_settlement_debt, then the current feed freezes, you need to switch to using the median feed to continue borrowing new individual settlement positions.

} else {
ret = asset.get("current_feed").get("settlement_price");
}
if (!!asset.get("current_feed")) {
return asset.getIn(["current_feed", "settlement_price"]);

if (!!ret) {
return ret;
}
throw "Feed price not found!";
}
Expand Down