-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "Bank" extension trait for liquidity tournament (#5035)
## Describe your changes This trait is responsible for the actual accounting of moving funds around, to be later consumed by the end epoch handler, which figures out what portion of the rewards needs to go where. The bank will just actually move fractions of its budget in the community pool to the requested locations, atomically. Testing deferred. ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > yes indeed
- Loading branch information
1 parent
f8dcd60
commit 1a5dccb
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
crates/core/component/funding/src/component/liquidity_tournament/bank.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use async_trait::async_trait; | ||
use cnidarium::StateWrite; | ||
use penumbra_sdk_asset::{Value, STAKING_TOKEN_ASSET_ID}; | ||
use penumbra_sdk_dex::component::PositionManager as _; | ||
use penumbra_sdk_dex::lp::position; | ||
use penumbra_sdk_keys::Address; | ||
use penumbra_sdk_num::Amount; | ||
use penumbra_sdk_sct::component::clock::EpochRead as _; | ||
use penumbra_sdk_sct::CommitmentSource; | ||
use penumbra_sdk_shielded_pool::component::NoteManager as _; | ||
use penumbra_sdk_txhash::TransactionId; | ||
|
||
#[allow(dead_code)] | ||
#[async_trait] | ||
/// The bank strictly controls issuance of rewards in the liquidity tournament. | ||
/// | ||
/// This ensures that rewards do not exceed the issuance budget, and are immediately | ||
/// debited from the appropriate source (which happens to be the community pool), | ||
/// and credited towards the appropriate destination (i.e. positions or new notes). | ||
pub trait Bank: StateWrite + Sized { | ||
/// Move a fraction of our issuance budget towards an address, by minting a note. | ||
async fn reward_to_voter( | ||
&mut self, | ||
reward: Amount, | ||
voter: &Address, | ||
tx_hash: TransactionId, | ||
) -> anyhow::Result<()> { | ||
let epoch = self | ||
.get_current_epoch() | ||
.await | ||
.expect("should be able to read current epoch"); | ||
self.mint_note( | ||
Value { | ||
asset_id: *STAKING_TOKEN_ASSET_ID, | ||
amount: reward, | ||
}, | ||
voter, | ||
CommitmentSource::LiquidityTournamentReward { | ||
epoch: epoch.index, | ||
tx_hash, | ||
}, | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
/// Move a fraction of our issuance budget towards a position, increasing its reserves. | ||
async fn reward_to_position(&mut self, reward: Amount, lp: position::Id) -> anyhow::Result<()> { | ||
self.reward_position(lp, reward).await?; | ||
Ok(()) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
crates/core/component/funding/src/component/liquidity_tournament/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod bank; | ||
pub mod nullifier; | ||
pub mod votes; |