Skip to content
102 changes: 102 additions & 0 deletions docs/exit-markets.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
= Exit markets

To understand the implied risk of a coverage pool, and to dampen the deleterious
effects of short-term underwriter behavior, we introduce exit markets.

Exit markets allow underwriters to express their time preference when
withdrawing. Rather than require all withdrawals to suffer a fixed delay,
underwriters can withdraw more quickly for a price, in competition with each
other.

Exit markets smooth out coverage pool liquidity and the discontinuity of
fixed-delay withdrawals, and expose a proxy for the short-term risk of the
pool — the withdrawal fee curve.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see a value for underwriters being able to exit the pool early but it is not entirely clear to me how the exit market will smooth the liquidity and why is it better for the pool compared to a fixed withdrawal period.

If all underwriters wait for P before withdrawing tokens, it is the same as waiting for a fixed withdrawal period.

If some underwriters do not wait for P, their withdrawal fees fuel up the pool, but even though the pool has shrunk - it has lower liquidity than it would have in the case of a fixed withdrawal period.

For example, let's say I deposited 100 WETH into the pool. At P/2 I decided to withdraw. I had to leave 30% of my tokens in the pool. We can say that the pool earned 30 WETH. But at the same time, for the remaining P/2 its liquidity shrunk by 70 WETH.

Copy link
Copy Markdown
Member Author

@mhluongo mhluongo Mar 20, 2021

Choose a reason for hiding this comment

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

If some underwriters do not wait for P, their withdrawal fees fuel up the pool, but even though the pool has shrunk - it has lower liquidity than it would have in the case of a fixed withdrawal period.

The assumption is that allowing quicker withdrawals will lead to greater total liquidity over the lifetime of a pool, compared to a fixed period pool, because the structure is more friendly to underwriters who are giving up opportunity cost.


== Mechanism

Instead of a fixed withdrawal delay, collateral pools are paramaterized with a
cost-free withdrawal period, `P`. This period is how long it takes for a
withdrawal to clear, when funds are no longer at risk and can be freely removed
from the collateral pool.

One way to turn this into a market is for the pool to continually "auction off"
immediate withdrawals. The pool shouldn't auction off more immediate withdrawals
Comment thread
mhluongo marked this conversation as resolved.
than some pool-specific risk parameter; it can auction off more at some time
between now and `P`, but it's unclear how much more.

Auctioning off immediate withdrawal excludes an important risk counter-signal:
deposits.

=== A physical analog
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In pedant-land, I'm pretty sure even though it's strictly the same, “analogue” is the generally-used spelling in noun form 😬

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I was going for "analogy"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No the word is the right fit, and the spelling is also right, just not the commonly-used one.


To develop intuition, consider a fixed arm on a hinge.

<pic>

Forces up and down along the arm counteract each other based on their position
along the arm and their magnitude perpendicular to the arm. Multiplied together,
the position and magnitude yield the moment of force, or torque.

<pic>

If we assign the arm the length of the cost-free withdrawal period, `P`, and
place the origin at the hinge, each force perpendicular to the arm can represent
a withdrawal or a deposit; the moment arm for each represents the immediacy of a
withdrawal, and the magnitude of the force represents the amount to be deposited
or withdrawn, relative to the outstanding underwriter tokens in the pool, `U`.

All perpendicular forces along the fixed arm can be aggregated into one value,
the torque. "Maximum" torque on the arm would be all the tokens `U` multiplied
by the cost-free period `P`. Maximum torque means the pool is drained of all
collateral immediately.

<pic with rubber band>

A feedback mechanism to limit maximum torque works like a rubber band on the
arm.

This analog makes a few things clear.

There's an obvious aggregate of deposits and withdrawals in the analog in
torque, or *withdrawal immediacy*. Withdrawal immediacy can be measured in
percent-pool-days.

The analog as presented only holds at a snapshot in time. As time moves on, each
force moves closer to the origin / hinge, lessening torque or withdrawal
immediacy from the pool.

Finally, the analog presents the question: what happens in the face of net
positive deposits over a period? Is there a fixed platform above the arm,
preventing periods of net positives from counting toward withdrawal immediacy?
Or does a similar rubber-band like feedback mechanism apply?

=== Details

Given a pool with total assets `A`, outstanding underwriter tokens `U`, and
cost-free withdrawal period `P`, we can draw a curve between withdrawal
immediacy (percent-pool-days) and underwriter tokens.

<pic>

An underwriter withdrawing the entire pool, immediately, costs the entire
underwriter token supply `U` — not something a rational player would do.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because it implies a gain of 0 underlying assets and a loss of U, so a total loss, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Feels like it may be worth being explicit about that.

Copy link
Copy Markdown

@eth-r eth-r Feb 19, 2021

Choose a reason for hiding this comment

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

By continuity we may not be able to do this; if we want the cost of withdrawing x + y tokens at once to equal the cost of withdrawing x tokens and then y tokens later in the same block it implies that withdrawing any amount immediately must cost the entire withdrawn amount

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And if we don't have continuity, it's possible to withdraw the entire pool immediately without losing the entire token supply by splitting up the withdrawal into smaller withdrawals unless we prevent immediate withdrawals altogether and bundle withdrawals together across one or more blocks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If Uniswap can do it, we can do it 😄

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's too Friday evening for me to articulate this precisely, but isn't how Uniswap does it that you have assets A and B, and the pool has T tokens issued so that A * B = T^2 * K, so if you try to get all A assets out you have to pay infinity B tokens in, but if you pay in 100% of T tokens you get 100% of both A and B out of it?

Withdrawing the entire pool at period `P` costs nothing.

A simple curve used by popular automated market makers is the constant product,
used as a constraint on the relationship between two sides of a market.

`x * y = k`

In an exit market, `x` is the supply of underwriter tokens paid toward
withdrawal fees over the sliding window `P`. `y`, on the other hand, is
withdrawal immediacy. To withdraw 50% of a pool in `P/2`, an underwriter must
swap underwriter tokens such that the pool constraint is maintained, "buying"
immediacy.

As time goes on, `y` grows linearly until it hits a max of `100% of the pool *
P days`, growing the curve constraint `k`. As withdrawals mature, `x` shrinks,
shrinking the curve constraint `k`.

As new funds enter the pool, `y` grows by `r * P` where `r` is the portion of
the pool the new funds represent, maintaining the constraint `k`. `y` never
exceeds `100% * P`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Did not have time to do any diligence on playing this out hehe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some examples could be helpful. 😬 For example, at first, I thought y is just a function of time ("as the time goes on y grows linearly") but it is probably* a function of time and pool's liquidity ("As new funds enter the pool, y grows by r * P").

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I've struggled with this, I might need some tables.

32 changes: 16 additions & 16 deletions DESIGN.md → docs/overview.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Components
= Components
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having a glossary would be super helpful.


## The collateral pool
== The collateral pool

The collateral pool is a collection of single-specific pools that share losses
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
The collateral pool is a collection of single-specific pools that share losses
The collateral pool is a collection of single-asset-specific pools that share losses

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the "single-asset-specific pool" a coverage pool or the "collateral pool" is a synonym of "coverage pool"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a coverage pool is a collection of single-asset-specific collateral pools... 🤔 A coverage pool is backed by multiple tokens, with a separate collateral pool for each token.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need to include this in the overview

Coverage pool ---> Collateral pool --->  Asset B
       |                           \--> Asset A
       |
        \--> Rewards pool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would this one below be more accurate?

Coverage pool ---> Collateral pool --->  Asset B
       |      \--> Collateral pool --->  Asset A
       |
        \--> Rewards pool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need a name for the collection of collateral pools in your diagram above. Either a collateral pool holds asset A, B, C, and a coverage pool has one, or a coverage pool has multiple collateral pools.

We need to be able to easily say "3% of all assets across the coverage pool were auctioned off" but refer to just collateral, and not eg the rewards pool.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"Collateral pool" containing a number of "asset pools"?

if coverage is required.
Comment thread
mhluongo marked this conversation as resolved.
Expand All @@ -21,7 +21,7 @@ suffering any sort of impermanent loss, as they would in an AMM.
Underwriters are still, however, entering into positions relative to the asset
Comment thread
mhluongo marked this conversation as resolved.
the coverage pool is backing.

## The risk manager
== The risk manager
Comment thread
mhluongo marked this conversation as resolved.
Outdated

The risk manager is a person or smart contract with the exclusive right to
demand coverage from the pool.
Expand All @@ -33,23 +33,23 @@ position could bankrupt the collateral pool.

Coverage is always paid out in the pool's covered asset.
Comment thread
mhluongo marked this conversation as resolved.

## The earnings pool
== The rewards pool

The earnings pool is a collection of different assets that grows as underwriters
earn fees and refunds.
The xref:rewards-pool.adoc[rewards pool] is a collection of different assets
Comment thread
mhluongo marked this conversation as resolved.
Outdated
that grows as underwriters earn fees and refunds.

The earnings pool mints a single earnings token, which is periodically
The rewards pool mints a single rewards token, which is periodically
distributed to the collateral pool. Each asset in the collateral pool earns
based on its earnings rate.
based on its rewards rate.

Over a period of a week, if a collateral pool contains two assets — WBTC at a
earnings rate of 2, and ETH at an earnings rate of 1 — each will be allocated
earnings pool tokens at a rate of 2 to 1.
rewards rate of 2, and ETH at an rewards rate of 1 — each will be allocated
rewards pool tokens at a rate of 2 to 1.
Comment on lines 45 to +46
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Over a period of a week, if a **coverage** pool contains two assets — WBTC at a
rewards rate of 2, and ETH at a rewards rate of 1 — each **collateral pool** will be allocated
rewards pool tokens at a rate of 2 to 1.

?

A collateral pool is a single-asset pool, it accepts token and mints underwriter token, it can't have more than two assets. At least that's my understanding heh.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm considering changing the terminology up a bit here. Whether all of the collateral is in one pile (eg Maker's vat) or in separate contracts isn't material to the design. Will give it some thought.

The important thing to understand is that If you put in WBTC, you get covWBTC, and you aren't taking an esoteric position against other assets in the pool like you might in an automated market maker.


As earnings accrue, earnings pool tokens can be withdrawn by underwriters and
redeemed for the underlying earnings.
As rewards accrue, rewards pool tokens can be withdrawn by underwriters and
redeemed for the underlying rewards.

# Efficient collateral liquidation
= Efficient collateral liquidation

When coverage is demanded by the risk manager, some part of the collateral
pool must be sold to obtain enough of the covered asset to fulfill the claim.
Expand All @@ -70,9 +70,9 @@ buyer is found.
If the risk manager has made a fill-or-kill claim, the auction will expire and
notify the risk manager. If not, all funds will remain locked on offer.

# Governance and the market feedback loop
= Governance and the market feedback loop

# Solving early exits
= Solving early exits

Underwriters will always be able to front-run on-chain claims against the
coverage pool. Rational players can withdraw their liquidity and rewards
Expand All @@ -90,7 +90,7 @@ as increased risk of merchanism failure at transitions.

Instead of a fixed delay, we introduce exit markets.

## Exit markets
== Exit markets
Comment thread
mhluongo marked this conversation as resolved.
Outdated

At a given moment, whether or not a liquidation is ongoing, a mass exit from
the collateral pool implies a pending spike in risk.
Expand Down
82 changes: 82 additions & 0 deletions docs/rewards-pool.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
= The rewards pool

A rewards pool is a contract that accepts arbitrary assets and mints a single
Comment thread
mhluongo marked this conversation as resolved.
reward token. Recipients of the reward token can at any time turn it in for a
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Assuming a rewards pool supports multiple tokens as rewards, and we're minting one type of token as a share of the rewards pool, how will we handle a situation when any of the rewards tokens is allocated at random points in time? The rewards pool won't pay attention to when a staker joined the coverage pool (what tokens were placed in the rewards pool at that point), only stake milliseconds matter, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm working on that part now — "depositing funds". What I'd like to do is make new entrants pay for the outstanding rewards rather than track entry per depositor.

For example, if you want covWBTC, and the WBTC pool has 100 reward tokens assigned to it, you pay some of your WBTC to account for that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That sounds like it's going to have lots of annoying hidden complexity that could end up either gameable or discouraging pool entry, with the correct balance being hard to strike. Tracking rewards[depositor][token] seems easier even if it gets slightly more expensive with a wide variety of reward tokens.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Your way breaks composability. If we do that we can't issue fungible underwriter token, or we issue them and they aren't reward yielding.

Give me a bit to write this up, I think I can convince you (and it's a generalization of exit markets)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we have you pay in the reward tokens instead of the asset itself, so we don't need to worry about exchange rates between asset and rewards?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's the simpler design, but worse UX / adding a dependency. I'll try to cover both options

portion of the rewards in the pool.

A rewards pool maintains a governable list of recipients and relative reward
rates. For example, a rewards pool might have two recipients — a WETH
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm lost, who is the recipient: a staker of a coverage pool or the coverage pool?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

coverage_pool -- has --> 
    collateral_pool -- has --> many asset pools
    reward_pool -- has --> many recipients, mapping to asset pools

A single asset pool is a recipient. So we're talking on the order of 10 recipients, not 100s or 1000s

collateral pool, and a WBTC collateral pool, with respective reward rates of 1
and 2.

Rewards tokens are minted constantly over time and distributed according to the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it a linear distribution? How will the rules for tokens releasing be defined, e.g. at each rewards tokens allocation, and be constant over a specific period? Would it be possible to top-up the rewards pool? Do we want to take an example of how TokenGeyser's rewards pools work?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So this will be different from TokenGeyser's rewards pool as the rewards pool won't distribute underlying reward tokens directly but mint tokens as a share in the whole rewards pool, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How will be the allocated rewards tokens unlocking? Will an unlocking period be defined on each allocation?

relative reward rates.

== Accounting for rewards distribution

Given the above scenario, at rewards pool creation. 3 rewards tokens are minted.
1 is reserved for the WETH collateral pool, and 2 for the WBTC collateral pool.

Every tick, an additional 3 rewards tokens are virtually minted.

.Virtual rewards
[frame="topbot",options="header"]
|==============================================
|Time | WETH virtual rewards | WBTC virtual rewards
|1 |1 |2
|2 |2 |4
|3 |3 |6
|4 |4 |8
|==============================================

At tick 5, if the rewards rates are changed, say to 1:1, the rewards tokens are
realized, then the virtual minting continues at the new rate.

.Virtual and real rewards
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Worth clarifying that this is with a change in rate at tick 5, or include that in the table. Might also be nice to progressively disclose with a version of the first table that adds real rewards before adding the change at tick 5.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Went with an explicit reward rate in the second table

[frame="topbot",options="header"]
|==========================================================================================
|Time | WETH virtual rewards | WETH real rewards | WBTC virtual rewards | WBTC real rewards
|1 |1 |1 |2 |2
|2 |2 |1 |4 |2
|3 |3 |1 |6 |2
|4 |4 |1 |8 |2
|5 |5 |5 |9 |9
|6 |6 |5 |10 |9
|7 |7 |5 |11 |9
|8 |8 |5 |12 |9
|==========================================================================================
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure I follow how virtual rewards are turned into real rewards, it would be good to mark when rewards are materialized.

My understanding is that the first realization of rewards happened after interval 1.
Then they were not getting realized until interval 5 ended.
When that happened:

  • There were 5 - 1 = 4 unspent WETH virtual rewards.
  • There were 9 - 2 = 7 unspent WBTC virtual rewards.
  • 4 real rewards were allocated to WETH pool, making a total of real rewards 1 + 4 = 5.
  • 7 real rewards were allocated to WBTC pool, making a total of real rewards 2 + 7 = 9.

Also, I do not understand how the amount of allocated rewards maps to realized rewards. In the table we assumed 1 virtual reward = 1 real reward but I guess it may happen when it is not 1:1.


Similarly, any rewards tokens that are exchanged and burned for the underlying
pool rewards realizes all reward token minting before the exchange occurs.

This structure should make it clear that reward pools scale in the number of
Comment thread
mhluongo marked this conversation as resolved.
ongoing reward recipients — with implications for the <<on-chain-efficiency,
number of assets>> supported as collateral in a coverage pool.

== Relation to collateral pools

A coverage pool has a single rewards pool that receives and manages all
underwriter earnings. Each single-asset collateral pool is assigned a relative
rate in the rewards pool, establishing a way for governance to incentivize
different assets to target a particular pool composition.

If an asset that's accepted as collateral by the coverage pool is intended as
underwriter rewards, it should first be deposited in the coverage pool, and the
underwriter token sent to the rewards pool. Following this pattern means a more
capital-efficient coverage rewards mechanism, though it also means rewards are
subject to exit markets.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think I follow any of this paragraph...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Adding an example


== On-chain efficiency

There are two bottlenecks in efficient runtime on the EVM with this structure.

The first is the number of reward recipients. Each rate change and reward token
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For example, a rewards pool might have two recipients — a WETH collateral pool, and a WBTC collateral pool, with respective reward rates of 1 and 2.

I was under an impression that coverage pools will be recipients of the rewards pool. Couldn't coverage pools be the recipients?

burn require iterating through all recipients, computing rewards, and minting
tokens. These costs are ultimately shouldered by reward beneficiaries, and place
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if there's a way to capture enough general information to handle this without iterating over everyone. I imagine there's been plenty of outside research done here without a better solution, though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Iterating through everyone is an out-of-gas DoS attack vector, there has to be a way, otherwise, I am afraid it's a non-go. I wonder if we can reuse some logic from TokenGeyser contract - the usage case seems pretty similar. I stake my tokens in a pool, based on how long I stake, I receive rewards proportionally to other stakers in the pool.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm pretty sure we can either reuse the logic or make something similar. This should not be a practical obstacle for successful implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed with @eth-r here. Tried to make it clear that I understand the attack in the doc @pdyraga 😉

We're designing a system where the number of individual asset pools is < 10. I'm envisioning the reward pool having that many recipients + / - 1 (we can also use this for tBTC v2 staking reward, thus the +1)

a ceiling on the number of simultaneous reward recipients.

The second is the number of assets being rewarded. Anyone can send a reward pool
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By this do you mean the number of assets being distributed as rewards?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep

whatever tokens they'd like. Instead of using an allowlist or pushing the cost
onto reward token holders at redemption time, a short denylist can be used to
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmmm, how would a denylist help if a mischievous attacker could at any time deploy one or more fresh ERC20s and send them to the pool? Maybe I don't fully understand the scenario you're envisioning here. It feels like another approach could be providing an allowlist, but having a way for an arbitrary asset to be added to that allowlist without governance, subject to a timelock and governance veto or something.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we can just maintain global state across the tokens in general, doing token-specific accounting when someone interacts with a particular token, and not need a denylist at all at the cost of slightly greater inaccuracy with unpopular tokens' accounting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

and not need a denylist at all at the cost of slightly greater inaccuracy with unpopular tokens' accounting.

Exactly my thinking with the next line

and reward token holders can decide which tokens they'd like to be sent at redemption

The denylist is actually about making sure any special-cased tokens aren't claimed. The actual cases are pretty convoluted but I think including the option for governance is good for future-proofing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmmm, how would a denylist help if a mischievous attacker could at any time deploy one or more fresh ERC20s and send them to the pool?

The idea isn't to avoid a maliciously sent ERC-20, it's to avoid a malicious withdrawal. Thinking about situations like the reward pool automatically re-underwriting and holding eg covWBTC or its own rewards tokens.. stuff that doesn't matter in a vacuum but that might matter in a future revision.

avoid mischief, and reward token holders can decide which tokens they'd like to
be sent at redemption.
75 changes: 75 additions & 0 deletions docs/risk-manager.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
= The risk manager

The risk manager holds a privileged role over the coverage pool. It maintains
the ability to claim coverage from the pool, liquidating enough collateral from
the pool to cover an outstanding obligation.

Because of the nature of the role, the risk manager is a critical component of
the coverage pool. Depending on the implementation, a risk manager can determine
whether to put assets at capped or uncapped risk; how quickly auctions should
put collateral up on offer; whether to end an auction early; and whether to
remunerate existing underwriters in the case of "extra" assets on hand from an
auction.

== An example pool

The tBTC v1 coverage pool has one purpose — to backstop the TBTC peg and
simplify the lives of signers by guaranteeing to take any outstanding TBTC
liquidation, trading TBTC for ETH.

Because we have no guaranteed bounds on the ETHBTC price, the risk to the pool
is technically uncapped; if the price of BTC suddenly 10x's relative to ETH, the
pool is still on the hook for a fixed amount of BTC. On the other hand, once the
pool takes a TBTC https://docs.keep.network/tbtc/#liquidation[liquidation
auction], the resulting ETH proceeds should be distributed back to the pool.

== Auctions

When the risk manager claims coverage, it specifies an amount denominated in
the asset the pool covers. An auction is opened across across all assets in the
Comment thread
mhluongo marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this a collateral pool that determines the ratio between assets for a coverage claim?

pool, increasing the portion of the pool on offer over time. Eventually, the
entire collateral pool is on offer.

For an auction to be filled, a participant pays the asking price, and in return
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

May be worth specifying “pays the asking price in the covered asset”?

receives a portion of each asset in the pool.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you mean by "a portion of each asset in the pool"? Does it refer to a portion of multiple types of assets across a collection of single-asset pools?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It means the portion of the pool on offer ( eg 3%) from each asset


Consider a collateral pool containing 10 WBTC and 100 WETH, and claim of 1 TBTC.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does an x% offer alway equal x% of each underlying single-asset pools, or is the relative weight adjustable between them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No adjustable weights.


.A collateral pool under auction
[frame="topbot",options="header"]
|============================================
|Time | Offer | WBTC on offer | WETH on offer
|1 |1% |0.1 |1
|2 |2% |0.2 |2
|3 |3% |0.3 |3
|4 |4% |0.4 |4
|5 |5% |0.5 |5
|6 |6% |0.6 |6
|7 |7% |0.7 |7
|8 |8% |0.8 |8
|9 |8% |0.9 |9
|10 |10% |1 |10
|============================================

For simplicity, assume WBTC and TBTC trade at parity. Regardless of the ETH/WBTC
exchange rate, there is a point between `t=1` and `t=10` where it makes sense to
buy all assets on offer.

An efficient on-chain implementation can allow partial and atomic fills, opening
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What do you mean by an atomic fill here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... and partial fill? 😆

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah---for completeness, I'm assuming “partial fill” means the ability to ship part of the covered asset to the pool and receive a commensurate part of the amount at auction.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

... yes re: "partial", and "atomic" means in the same sense that you can take the auction in one transaction, making it friendly for people using flash loans, and otherwise composable with the rest of Ethereum

up arbitrage opportunities with lower total liquidity requirements.

In addition to claiming coverage and opening an auction, the risk manager
determines the parameters that govern the auction, including the velocity of the
falling price based on market conditions, and whether to withdraw a claim and
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Market conditions such as?

end an auction early.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this something you'd see tBTC using, or just an arbitrary feature that could be added to a generic coverage pool?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The velocity adjustment will like make it into both v1 and v2, and the early auction end is useful in v1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I could probably use some details on how these would apply to develop intuition here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Practicing before I update the doc...

  • slowing the velocity of a falling price auction means you believe, for whatever reason, that you're close to the "market" price
  • speeding up means you think you have a way to go. If there's a mass exit attempt, maybe the auction should be sped up

I don't know if I'll be able to generally describe when exit markets can be used to speed or slow auctions in the first revision of coverage pools.

The last one (ending an auction) might happen in tBTC v1 if someone else takes a tBTC liquidation, and we no longer have reason to claim coverage.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Got it!


== Returning funds

If there are funds to return to the pool after a coverage claim, a risk manager
implementation can do one of two things

1. Deposit the funds in the rewards pool, effectively distributing them across
underwriters based on the relative reward rate, regardless of the asset.
2. Deposit the funds directly in the collateral pool, requiring funds to be
traded to match the existing collateral distribution, or intentionally
distributing funds in a way that favors a particular underwritten asset.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there an unspoken constraint here that the collateral pool should probably only handle auctions that repay in one of the underlying assets?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope, though there is an assumption that governance will know that the sum of the collateral in the pool is going to be paying out in a particular asset, and choose the acceptable collateral accordingly.

Neither version of tBTC would use the single-collateral version of 2. mentioned here, but it might make sense in both v1 and v2 to auction the pool for TBTC, get ETH, then have a strategy to Uniswap that back to to original asset composition