Adds origination fee and program fee related updates #934
+3,050
−4,723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handles changes from mrgnlabs/marginfi-v2#244 and mrgnlabs/marginfi-v2#239, adding origination fees on borrow and program-level fees (paid to the program administrator) that are collected by a global fee wallet.
Changes:
bank.config.interest_rate_config.protocol_origination_fee
andbank.collected_program_fees_outstanding
group_flags
andfee_state_cache
.FeeState
exists. This account is one-of-a-kind per program.init_global_fee_state
will run once after this program update, and then be removed from the program buffer in a subsequent update.edit_global_fee_state
modifies program fees.config_group_fee
controls if a group pays program fees or not.propagate_fee_state
forces a group to adopt the current global FeeState regime.add_bank
now requires theFeeState
account and the interest rate config now has aprotocolOriginationFee
field.collect_bank_fees
now requires the global fee state and fee ata, which is the canonical ATA ofFeeState.global_fee_wallet
Launch readiness checklist:
init_fee_state
runs once, signed by the program multisigadd_pool
) or viaconfigure_bank
FeeState.global_fee_wallet
with some SOL to make sure it is a valid account that we own.FeeState.global_fee_wallet
gains the flat sol fee.propagate_fee_state
for all groups that exist after any changes to fees (edit_global_fee_state
)init_fee_state
runs once for mainnet, signed by the program multisigLess important but should do eventually:
propagate_fee_state
runs for any group that existed prior to this update.config_group_fee
runs for any group that existed prior to this update that should enable program fees.configure_bank
runs for any bank that existed prior to this update that should enable borrow origination fees.FeeState.global_fee_wallet
any asset we will ultimately collect fees on, or modify howcollect_bank_fees
is called to create the ATA as needed.init_fee_state
from the program bufferconfig_group_fee
turns off fees for any group created after this update that is whitelisted and should not pay them (e.g. arena groups already owned by mrgn)