liquidation-visibility's Introduction
liquidation-visibility's People
liquidation-visibility's Issues
Work Plan: Write Liquidation Auction Results to Vstorage
Problem Definition
Currently when there are liquidatable vaults present in one of the vaultManagers
, it's collateral is deposited into the auctioneer
and a dutch auction is run. The problem is that too little information is exposed to vstorage
for running financial analysis and being transparent overall.
Desired data to be exposed on vstorage
:
-
Which vaults got liquidated and added to an auction. For each vault
- Vault manager
- Collateral at time of liquidation
- Debt at time of liquidation
- Time of liquidation
-
Auction details. For each auction run:
- Auction start time
- Auction end time
- Auction identifier
- Starting state
- Collateral offered
- IST target
- Ending state
- Collateral sold
- Collateral remaining
- IST raised
- IST target remaining
-
Post-auction funds distribution:
- Collateral asset for liquidation penalty sent to Reserve
- Collateral asset returned to vault holders
- Debt returned to vault holders (only happens in certain circumstances)
- Shortfall value sent to Reserve
Open Questions
- Time of liquidation data point
- we've traced that liquidations are scheduled to take place when auctions are starting. This means time of liquidation = auctioneer.schedule.activeStartTime but not sure to include this here since this will be the same for multiple vaults going into the same auction.
- Post Auction Details.
- to us, Post Auction Details means that the auction is completed AND all unsold collateral along with raised IST is returned to the respective vault managers. We feel the need to make this clarification because the auctioneer itself does a distribution too. Which handles sending the unsold collateral and the raised Bid to depositors then send any uneven Bid to reserve, if any.
- Collateral returned to vault
- do we need to expose collateral returned in per vault basis for every individual vault?
- Debt returned to vault
- what exactly do we mean here?
Solution Analysis
During our analysis, below are what we've found:
Auction Details
Data | Path | Derived |
---|---|---|
Auction identifier | published.auctioneer.{bookID} | - |
Auction start | published.auctioneer.schedule.activeStartTime | - |
Collateral offered | published.auctioneer.{bookID}.startCollateral | - |
IST Target | published.auctioneer.{bookID}.startProceedsGoal | - |
Collateral remaining | published.auctioneer.{bookID}.collateralAvailable | - |
Collateral sold | - | (Collateral offered) - (Collateral remaining) |
IST target remaining | published.auctioneer.{bookID}. remainingProceedsGoal | - |
IST raised | - | (IST target )- (IST target remaining) |
Information Per Vault
Data | Path | Derived |
---|---|---|
Vault Manager | - | Correlate collateral sold in auction and accepted in Vault Manager |
Collateral at time of liquidation | - | collateralAmount recorded on vaultData |
Debt at time of liquidation | - | debtAmount recorded on vaultData |
Time of liquidation | - | Auction start time |
No data correlating individual vaults to liquidations can be found in vstorage. This raises a requirement which we have to put new data to vstorage. When going over vaultManager code, we've found this in liquidateVauıtls method
const { totalDebt, totalCollateral, vaultData, liqSeat } =
getLiquidatableVaults(
zcf,
{
quote: lockedQuote,
interest: compoundedInterest,
margin: liqMargin,
},
prioritizedVaults,
liquidatingVaults,
debtBrand,
collateralBrand,
);
Where vaultData has the following type definition;
/**
* @type {MapStore<
* Vault,
* { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
* >}
*/
This means vaultData will have the exact amounts of collateral and debt going into the liquidation which is what we want and can expose this to vstorage.
Post Auction Details
Data | Path | Derived |
---|---|---|
Collateral sent to reserve | - | plan.collateralForReserve |
Collateral returned to vault | - | - |
Debt returned to vault | - | - |
Shortfall sent to reserve | - | plan.shortfallToReserve |
Currently vstorage does not have any data in it in the sense that we described above. See this comment.
However, we've located where this data is in the vaultManager;
for (const [vault, balances] of bestToWorst) {
vaultsInPlan.push(vault);
vaultsBalances.push({
collateral: balances.collateralAmount,
// if interest accrued during sale, the current debt will be higher
presaleDebt: balances.debtAmount,
currentDebt: vault.getCurrentDebt(),
});
}
harden(vaultsInPlan);
harden(vaultsBalances);
const plan = calculateDistributionPlan({
proceeds,
totalDebt,
totalCollateral,
oraclePriceAtStart: oraclePriceAtStart.quoteAmount.value[0],
vaultsBalances,
penaltyRate,
});
return { plan, vaultsInPlan };
Notice that we know what vaults are reinstated or marked as liquidated along with their respective balances. A plan object is built progressively by iterating over these vaults. Which has the type definition;
/**
* @typedef {{
* overage: Amount<'nat'>,
* shortfallToReserve: Amount<'nat'>,
* collateralForReserve: Amount<'nat'>,
* actualCollateralSold: Amount<'nat'>,
* collateralSold: Amount<'nat'>,
* collatRemaining: Amount<'nat'>,
* debtToBurn: Amount<'nat'>,
* mintedForReserve: Amount<'nat'>,
* mintedProceeds: Amount<'nat'>,
* phantomDebt: Amount<'nat'>,
* totalPenalty: Amount<'nat'>,
* transfersToVault: Array<[number, AmountKeywordRecord]>,
* vaultsToReinstate: Array<number>
* }} DistributionPlan
This plan object satisfies our needs in Post Auction Details more than enough. We can cherry pick which ones to expose in vstorage.
Identify modules that will require an updated
Current relevant data recorded on Vstorage:
Vaults:
- published.vaultFactory
- published.vaultFactory.governance
- "ChargingPeriod"
- "Electorate"
- "MinInitialDebt"
- "RecordingPeriod"
- "ReferencedUI"
- "ShortfallInvitation"
- published.vaultFactory.managers
- published.vaultFactory.managers.manager0
- published.vaultFactory.managers.manager0.governance
- "DebtLimit"
- "InterestRate"
- "LiquidationMargin"
- "LiquidationPadding"
- "LiquidationPenalty"
- "MintFee"
- published.vaultFactory.managers.manager0.metrics
- "liquidatingCollateral"
- "liquidatingDebt"
- "lockedQuote"
- "numActiveVaults"
- "numLiquidatingVaults"
- "numLiquidationsAborted"
- "numLiquidationsCompleted"
- "retainedCollateral"
- "totalCollateral"
- "totalCollateralSold"
- "totalDebt"
- "totalOverageReceived"
- "totalProceedsReceived"
- "totalShortfallReceived"
- published.vaultFactory.managers.manager0.quotes
- "quoteAmount”
- published.vaultFactory.managers.manager0.vaults
- published.vaultFactory.managers.manager0.vaults.vault0
- "debtSnapshot"
- "locked"
- "vaultState"
Auctions
- published.auction
- published.auction.book0
- "collateralAvailable":
- "currentPriceLevel"
- "remainingProceedsGoal"
- "startCollateral"
- "startPrice"
- "startProceedsGoal"
- published.auction.governance
- "AuctionStartDelay"
- "ClockStep"
- "DiscountStep"
- "Electorate"
- "LowestRate"
- "PriceLockPeriod"
- "StartFrequency"
- "StartingRate"
- published.auction.schedule
- "activeStartTime"
- "nextDescendingStepTime"
- "nextStartTime"
Test environment
Unit tests
Context:
Considering that we intend to update the inter-protocol pkg source code to extend the data being published to the storage node for increased visibility of the vaults liquidation, auction and post auction distribution.
We plan to increase the test coverage in this regard to assure that our updates are behaving accordingly.
A more detailed description of the assignment and solution proposed can be found here
Open Questions:
- Should we extend an existing test file, (e.g.
inter-protocol/test/vaultFactory/test-vaultLiquidation.js
), or create a new one? - In case of creating a new file, would it be beneficial for us to either build a file to export some support functions or extend an existing one, (e.g.
vaultFactoryUtils.js
), to avoid duplicating code.
For example:
- setupBasics
- setupServices
- setClockAndAdvanceNTimes
- startAuctionClock
- bid
- ...
Current approach (WiP)
As an experiment to explore the liquidation visibility, without risking creating a conflict with a future merge, we create a new directory called liquidationVisibility that contain some of the tests created.
Expose All Bids in Vstorage
Work Plan:
- Establish scope of this task
- Establish success metrics and required test coverage
- Identify modules that will be updated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.