Skip to content

Commit

Permalink
Deposit minimums in limits (#1121)
Browse files Browse the repository at this point in the history
* feat: Limits endpoint has minimums

* chore: Autogenerated sources

* chore: make format

* fix: Test issue

* add per_deposit_minimum validation

* Revert "add per_deposit_minimum validation"

This reverts commit b454665.

* Put emily server back in

* feat: remove withdrawal minimums

* chore: Fix autogenerated sources

---------

Co-authored-by: Francesco Leacche <[email protected]>
  • Loading branch information
AshtonStephens and Jiloc authored Dec 16, 2024
1 parent 069867d commit 017dad3
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**peg_cap** | Option<**u64**> | Represents the current sBTC limits. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then the cap is the same as the global per deposit cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**account_caps** | [**std::collections::HashMap<String, models::AccountLimits>**](AccountLimits.md) | Represents the individual limits for requests coming from different accounts. |
**peg_cap** | Option<**u64**> | Represents the total cap for all pegged-in BTC/sBTC. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then there is no cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then there is no cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub struct AccountLimits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -46,6 +54,7 @@ impl AccountLimits {
AccountLimits {
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub struct Limits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then there is no cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -50,6 +58,7 @@ impl Limits {
account_caps,
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**peg_cap** | Option<**u64**> | Represents the current sBTC limits. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then the cap is the same as the global per deposit cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
1 change: 1 addition & 0 deletions .generated-sources/emily/client/rust/public/docs/Limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**account_caps** | [**std::collections::HashMap<String, models::AccountLimits>**](AccountLimits.md) | Represents the individual limits for requests coming from different accounts. |
**peg_cap** | Option<**u64**> | Represents the total cap for all pegged-in BTC/sBTC. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then there is no cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then there is no cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub struct AccountLimits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -46,6 +54,7 @@ impl AccountLimits {
AccountLimits {
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub struct Limits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then there is no cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -50,6 +58,7 @@ impl Limits {
account_caps,
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**peg_cap** | Option<**u64**> | Represents the current sBTC limits. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then the cap is the same as the global per deposit cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**account_caps** | [**std::collections::HashMap<String, models::AccountLimits>**](AccountLimits.md) | Represents the individual limits for requests coming from different accounts. |
**peg_cap** | Option<**u64**> | Represents the total cap for all pegged-in BTC/sBTC. | [optional]
**per_deposit_cap** | Option<**u64**> | Per deposit cap. If none then there is no cap. | [optional]
**per_deposit_minimum** | Option<**u64**> | Per deposit minimum. If none then there is no minimum. | [optional]
**per_withdrawal_cap** | Option<**u64**> | Per withdrawal cap. If none then there is no cap. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub struct AccountLimits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -46,6 +54,7 @@ impl AccountLimits {
AccountLimits {
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub struct Limits {
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_cap: Option<Option<u64>>,
/// Per deposit minimum. If none then there is no minimum.
#[serde(
rename = "perDepositMinimum",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub per_deposit_minimum: Option<Option<u64>>,
/// Per withdrawal cap. If none then there is no cap.
#[serde(
rename = "perWithdrawalCap",
Expand All @@ -50,6 +58,7 @@ impl Limits {
account_caps,
peg_cap: None,
per_deposit_cap: None,
per_deposit_minimum: None,
per_withdrawal_cap: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -2181,6 +2188,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -1981,6 +1988,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -2235,6 +2242,13 @@
"nullable": true,
"minimum": 0
},
"perDepositMinimum": {
"type": "integer",
"format": "int64",
"description": "Per deposit minimum. If none then there is no minimum.",
"nullable": true,
"minimum": 0
},
"perWithdrawalCap": {
"type": "integer",
"format": "int64",
Expand Down
1 change: 1 addition & 0 deletions emily/handler/src/api/handlers/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub async fn set_limits(context: EmilyContext, limits: Limits) -> impl warp::rep
SystemTime::now(),
&AccountLimits {
peg_cap: limits.peg_cap,
per_deposit_minimum: limits.per_deposit_minimum,
per_deposit_cap: limits.per_deposit_cap,
per_withdrawal_cap: limits.per_withdrawal_cap,
},
Expand Down
4 changes: 4 additions & 0 deletions emily/handler/src/api/models/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use utoipa::{ToResponse, ToSchema};
pub struct Limits {
/// Represents the total cap for all pegged-in BTC/sBTC.
pub peg_cap: Option<u64>,
/// Per deposit minimum. If none then there is no minimum.
pub per_deposit_minimum: Option<u64>,
/// Per deposit cap. If none then there is no cap.
pub per_deposit_cap: Option<u64>,
/// Per withdrawal cap. If none then there is no cap.
Expand Down Expand Up @@ -38,6 +40,8 @@ pub struct Limits {
pub struct AccountLimits {
/// Represents the current sBTC limits.
pub peg_cap: Option<u64>,
/// Per deposit minimum. If none then there is no minimum.
pub per_deposit_minimum: Option<u64>,
/// Per deposit cap. If none then the cap is the same as the global per deposit cap.
pub per_deposit_cap: Option<u64>,
/// Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap.
Expand Down
4 changes: 4 additions & 0 deletions emily/handler/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl Settings {
.ok()
.map(|v| v.parse())
.transpose()?,
per_deposit_minimum: env::var("DEFAULT_PER_DEPOSIT_MINIMUM")
.ok()
.map(|v| v.parse())
.transpose()?,
per_deposit_cap: env::var("DEFAULT_PER_DEPOSIT_CAP")
.ok()
.map(|v| v.parse())
Expand Down
2 changes: 2 additions & 0 deletions emily/handler/src/database/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ pub async fn get_limits(context: &EmilyContext) -> Result<Limits, Error> {
timestamp: 0,
},
peg_cap: default_global_cap.peg_cap,
per_deposit_minimum: default_global_cap.per_deposit_minimum,
per_deposit_cap: default_global_cap.per_deposit_cap,
per_withdrawal_cap: default_global_cap.per_withdrawal_cap,
};
Expand Down Expand Up @@ -669,6 +670,7 @@ pub async fn get_limits(context: &EmilyContext) -> Result<Limits, Error> {
// Get the global limit for the whole thing.
Ok(Limits {
peg_cap: global_cap.peg_cap,
per_deposit_minimum: global_cap.per_deposit_minimum,
per_deposit_cap: global_cap.per_deposit_cap,
per_withdrawal_cap: global_cap.per_withdrawal_cap,
account_caps,
Expand Down
4 changes: 4 additions & 0 deletions emily/handler/src/database/entries/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct LimitEntry {
pub key: LimitEntryKey,
/// Represents the current sBTC limits.
pub peg_cap: Option<u64>,
/// Per deposit minimum. If none then there is no minimum.
pub per_deposit_minimum: Option<u64>,
/// Per deposit cap. If none then the cap is the same as the global per deposit cap.
pub per_deposit_cap: Option<u64>,
/// Per withdrawal cap. If none then the cap is the same as the global per withdrawal cap.
Expand All @@ -43,6 +45,7 @@ impl From<LimitEntry> for AccountLimits {
fn from(limit_entry: LimitEntry) -> Self {
AccountLimits {
peg_cap: limit_entry.peg_cap,
per_deposit_minimum: limit_entry.per_deposit_minimum,
per_deposit_cap: limit_entry.per_deposit_cap,
per_withdrawal_cap: limit_entry.per_withdrawal_cap,
}
Expand All @@ -66,6 +69,7 @@ impl LimitEntry {
.as_secs(),
},
peg_cap: account_limit.peg_cap,
per_deposit_minimum: account_limit.per_deposit_minimum,
per_deposit_cap: account_limit.per_deposit_cap,
per_withdrawal_cap: account_limit.per_withdrawal_cap,
}
Expand Down
Loading

0 comments on commit 017dad3

Please sign in to comment.