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

Reserve contract receives JS metering fees; IST fees distributed to reward pool and reserve #4399

Closed
3 tasks done
rowgraus opened this issue Jan 26, 2022 · 12 comments · Fixed by #5448
Closed
3 tasks done
Assignees
Labels
Inter-protocol Overarching Inter Protocol Vaults VaultFactor (née Treasury)
Milestone

Comments

@rowgraus
Copy link

rowgraus commented Jan 26, 2022

This ticket covers inflows to the Reserve as well as how the Reserve covers shortfalls from vault liquidations

Inflows to the Reserve should include:

Reward distribution mechanics

@rowgraus rowgraus added MN-1 Inter-protocol Overarching Inter Protocol labels Jan 26, 2022
@rowgraus rowgraus changed the title Execution fees go to a purse "Stability Pool" Execution fees go to a purse "Stability Pool" used to cover vault shortfalls Jan 26, 2022
@rowgraus rowgraus changed the title Execution fees go to a purse "Stability Pool" used to cover vault shortfalls Execution fees go to a "Reserve Pool" used to cover vault shortfalls Feb 2, 2022
@Tartuffo
Copy link
Contributor

Tartuffo commented Feb 2, 2022

@warner @michaelfig Need a vBank purse for the Cosmos layer to put fees into.
That vBank purse then needs to be available in the vault contract, to cover defaults. Needs to be setup in bootstrap.

@Tartuffo
Copy link
Contributor

@dckc Dan you are the primary on this. LMK if that is problematic.

@Chris-Hibbert Chris-Hibbert added the Vaults VaultFactor (née Treasury) label Mar 10, 2022
@Tartuffo Tartuffo added this to the Mainnet 1 milestone Mar 23, 2022
@dtribble
Copy link
Member

The Reserve pool now exists, so this should be unblocked.

@dckc
Copy link
Member

dckc commented Apr 12, 2022

Need a vBank purse for the Cosmos layer to put fees into.

I'm looking at packages/vats/src/vat-bank.js and I don't see how to do this. What should I be looking at, @michaelfig ? @JimLarson ?

@dckc dckc assigned michaelfig and JimLarson and unassigned mhofman and dckc Apr 12, 2022
@rowgraus rowgraus changed the title Execution fees go to a "Reserve Pool" used to cover vault shortfalls Execution fees go to the Reserve used to cover vault shortfalls Apr 13, 2022
@michaelfig
Copy link
Member

We will change the vbank from getFeeCollector() to getRewardsCollector() and getReserveCollector(), each of which is backed by a different cosmos-level module account. getRewardsCollector() is backed by the x/distr module account, getReserveCollector() is backed by a new vbank-created account.

The reserve pool will get a virtual purse via bootstrap from a closely-held vbank getReservePurse() method, so that it can manipulate the cosmos-level module account's balance from the JS side.

@rowgraus
Copy link
Author

rowgraus commented May 4, 2022

Updated to include discussion on vault shortfall mechanics

@rowgraus rowgraus changed the title Execution fees go to the Reserve used to cover vault shortfalls Reserve contract receives execution fees and reward pool flows; covers vault shortfalls May 4, 2022
@rowgraus rowgraus changed the title Reserve contract receives execution fees and reward pool flows; covers vault shortfalls Reserve contract receives execution fees and reward pool flows May 5, 2022
@rowgraus
Copy link
Author

rowgraus commented May 10, 2022

Discussed in RUN Protocol engineering meeting last week. Separating out ticket for reserve to cover shortfalls from liquidations: #5299

@rowgraus rowgraus changed the title Reserve contract receives execution fees and reward pool flows Reserve contract receives JS metering fees; IST fees distributed to reward pool and reserve May 11, 2022
@Tartuffo
Copy link
Contributor

Tartuffo commented May 11, 2022

We need to make this as small as possible to handle fees in MN-1. Maybe we don't even need this if we only use Cosmos-level feed.

@dckc
Copy link
Member

dckc commented May 11, 2022

@dtribble suggested we get more clarity on what are all the fees collected in the system and where they go. I offered to give it a whirl.

@arirubinstein I hope to get your help.

@dckc
Copy link
Member

dckc commented May 17, 2022

Survey of fees in the system

Solid lines are implemented; dotted lines are planned. This "JS metering" ticket seems to be about the x/swingset fees.

Loading
graph LR
    x/swingset -->|msg fee pt1| x/distribution
    x/swingset -.->|msg fee pt2| Reserve
    Vaults -->|mint fee| Collector[Reward Collector]
    Liquidation -->|penalty| Reserve
    AMM -->|swap fee| Collector
    AMM -.->|initial liquidity| Reserve
    PSM -->|swap fee| Collector
    Boost -->|mint fee| Collector
    Collector --> VBANK --> x/distribution --> stakers
    Collector -.->|overflow| Reserve

TODO:

  • Do fees go from the AMM / Vaults / Boost go to the reserve?
  • figure out how cosmos gas fits in.

Liquidation penalty is #5367

AMM, Vaults, runStake/Boost

When Inter protocol is started, in startRewardDistributor:

await E(vats.distributeFees).buildDistributor(
[vaultAdmin, ammAdmin, runStakeAdmin].map(cf =>
E(vats.distributeFees).makeFeeCollector(zoe, cf),
),
feeCollectorDepositFacet,
epochTimerService,

This uses a vat created at bootstrap: (ISSUE: why? why not a contract in the Inter protocol?)

async function schedulePayments() {
contracts.map(contract =>
E(contract)
.collectFees()
.then(payment => E(feeDepositFacet).receive(payment)),
);
}

Finally, each of the 3 contracts collects fees, for example, at AMM swap

context.state.protocolSeat.incrementBy(harden({ RUN: prices.protocolFee }));

creator may collect them:

* The creatorFacet has one method (makeCollectFeesInvitation, which returns
* collected fees to the creator). `handleParamGovernance()` adds internal

Swingset message fees

// Charge the account immediately if they owe more than BeansPerMinFeeDebit.
// NOTE: We assume that BeansPerMinFeeDebit is a multiple of BeansPerFeeUnit.
feeCoins, _ := feeDecCoins.TruncateDecimal()
if !feeCoins.IsZero() {
err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, k.feeCollectorName, feeCoins)

// TODO: create the cost model we want, and update these to be more principled.
// These defaults currently make deploying an ag-solo cost less than $1.00.
export const defaultBeansPerInboundTx = defaultBeansPerFeeUnit / 100n; // $0.01
export const defaultBeansPerMessage = defaultBeansPerFeeUnit / 1_000n; // $0.001
export const defaultBeansPerMessageByte = defaultBeansPerFeeUnit / 50_000n; // $0.0002
export const defaultBeansPerMinFeeDebit = defaultBeansPerFeeUnit / 5n; // $0.2

TODO:

@Chris-Hibbert
Copy link
Contributor

#5377 will add a requirement that AMM creation enforces a minimum initial liquidity. The corresponding liquidity tokens should be sent to the Reserve.

@dckc
Copy link
Member

dckc commented May 25, 2022

today's Inter meeting discussion:

  • make a contract
    • for now, leave the 50% as a contract term; postpone making it governable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Inter-protocol Overarching Inter Protocol Vaults VaultFactor (née Treasury)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants