-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce14dfc
commit 55b213c
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
lana/app/src/credit_facility/ledger/velocity/disbursal_limit.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,41 @@ | ||
use tracing::instrument; | ||
|
||
use cala_ledger::{velocity::*, *}; | ||
|
||
pub struct DisbursalLimit; | ||
|
||
const DISBURSAL_LIMIT_ID: uuid::Uuid = uuid::uuid!("00000000-0000-0000-0000-000000000002"); | ||
|
||
impl DisbursalLimit { | ||
#[instrument(name = "ledger.overdraft_prevention.init", skip_all)] | ||
pub async fn init( | ||
ledger: &CalaLedger, | ||
) -> Result<VelocityLimitId, crate::credit_facility::ledger::CreditLedgerError> { | ||
let limit = NewVelocityLimit::builder() | ||
.id(DISBURSAL_LIMIT_ID) | ||
.name("Disbursal Limit") | ||
.description("Limit for disbursals") | ||
.window(vec![]) | ||
.limit( | ||
NewLimit::builder() | ||
.balance(vec![NewBalanceLimit::builder() | ||
.layer("SETTLED") | ||
.amount("decimal('0.0')") | ||
.enforcement_direction("DEBIT") | ||
.build() | ||
.expect("balance limit")]) | ||
.build() | ||
.expect("limit"), | ||
) | ||
.build() | ||
.expect("velocity limit"); | ||
|
||
match ledger.velocities().create_limit(limit).await { | ||
Err(cala_ledger::velocity::error::VelocityError::LimitIdAlreadyExists) => { | ||
Ok(DISBURSAL_LIMIT_ID.into()) | ||
} | ||
Err(e) => Err(e.into()), | ||
Ok(limit) => Ok(limit.id()), | ||
} | ||
} | ||
} |
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,3 @@ | ||
mod disbursal_limit; | ||
|
||
pub use disbursal_limit::*; |