Skip to content

Commit

Permalink
Merge pull request #2 from FigureTechnologies/feature/contribute-loan…
Browse files Browse the repository at this point in the history
…-pools

Feature/contribute loan pools
  • Loading branch information
ChrisKenison authored Aug 21, 2023
2 parents b5bc61a + 3269fa9 commit 14cb851
Show file tree
Hide file tree
Showing 30 changed files with 2,971 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ optimize-arm = """docker run --rm -v "$(pwd)":/code \
[dependencies]
provwasm-std = { version = "1.1.0" }
cosmwasm-schema = "1.1.3"
cosmwasm-std = { version = "1.1.3", features = ["cosmwasm_1_1"] }
cosmwasm-std = { version = "1.1.3", features = ["cosmwasm_1_1","iterator"] }
cosmwasm-storage = "1.1.3"
cw-storage-plus = { version = "1.0.1", features = ["iterator"]}
cw2 = "1.0.1"
result-extensions = "=1.0.2"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
Expand Down
144 changes: 144 additions & 0 deletions crates/contract/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,90 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"contribute_loan_pool"
],
"properties": {
"contribute_loan_pool": {
"type": "object",
"required": [
"loan_pools"
],
"properties": {
"loan_pools": {
"$ref": "#/definitions/ContributeLoanPools"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"withdraw_loan_pool"
],
"properties": {
"withdraw_loan_pool": {
"type": "object",
"required": [
"loan_pools"
],
"properties": {
"loan_pools": {
"$ref": "#/definitions/WithdrawLoanPools"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"white_list_loan_pool_contributors"
],
"properties": {
"white_list_loan_pool_contributors": {
"type": "object",
"required": [
"loan_pool_contributors"
],
"properties": {
"loan_pool_contributors": {
"$ref": "#/definitions/LoanPoolContributors"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"remove_white_list_loan_pool_contributors"
],
"properties": {
"remove_white_list_loan_pool_contributors": {
"type": "object",
"required": [
"remove_loan_pool_contributors"
],
"properties": {
"remove_loan_pool_contributors": {
"$ref": "#/definitions/RemoveLoanPoolContributors"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand All @@ -179,6 +263,51 @@
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"ContributeLoanPools": {
"type": "object",
"required": [
"markers"
],
"properties": {
"markers": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"LoanPoolContributors": {
"type": "object",
"required": [
"addresses"
],
"properties": {
"addresses": {
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
},
"RemoveLoanPoolContributors": {
"type": "object",
"required": [
"addresses"
],
"properties": {
"addresses": {
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
},
"SecurityCommitment": {
"type": "object",
"required": [
Expand All @@ -202,6 +331,21 @@
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
},
"WithdrawLoanPools": {
"type": "object",
"required": [
"markers"
],
"properties": {
"markers": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
}
}
26 changes: 26 additions & 0 deletions crates/contract/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"query_collaterals"
],
"properties": {
"query_collaterals": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"query_loan_pool_contributors"
],
"properties": {
"query_loan_pool_contributors": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down
62 changes: 62 additions & 0 deletions crates/contract/src/core/collateral.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use cosmwasm_std::{Addr, CosmosMsg, Uint128};
use provwasm_std::{AccessGrant, ProvenanceMsg};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct LoanPoolMarkerCollateral {
pub marker_address: Addr,
pub marker_denom: String,
pub share_count: Uint128,
pub original_contributor: Addr,
// this is the address with ADMIN privileges that added the marker to the securitization.
pub removed_permissions: Vec<AccessGrant>,
}

impl LoanPoolMarkerCollateral {
pub(crate) fn new<S: Into<String>>(
marker_address: Addr,
marker_denom: S,
share_count: u128,
original_owner: Addr,
removed_permissions: Vec<AccessGrant>,
) -> Self {
Self {
marker_address,
marker_denom: marker_denom.into(),
share_count: Uint128::new(share_count),
original_contributor: original_owner,
removed_permissions,
}
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct LoanPoolMarkers {
pub collaterals: Vec<LoanPoolMarkerCollateral>,
}

impl LoanPoolMarkers {
pub(crate) fn new(collaterals: Vec<LoanPoolMarkerCollateral>) -> Self {
Self { collaterals }
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
/// Holds information about a loan pool addition.
pub struct LoanPoolAdditionData {
/// The collateral being added to the loan.
pub collateral: LoanPoolMarkerCollateral,
/// The Provenance messages associated with the loan.
pub messages: Vec<CosmosMsg<ProvenanceMsg>>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
/// Holds information about a loan pool removal.
pub struct LoanPoolRemovalData {
/// The collateral to be deleted from state
pub collateral: LoanPoolMarkerCollateral,
/// The Provenance messages associated with the loan.
pub messages: Vec<CosmosMsg<ProvenanceMsg>>,
}
2 changes: 2 additions & 0 deletions crates/contract/src/core/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub const PAID_IN_CAPITAL_KEY: &str = "paid_in_capital";
pub const SECURITIES_MAP_KEY: &str = "security_types_map";
pub const REMAINING_SECURITIES_KEY: &str = "remaining_securities_map";
pub const AVAILABLE_CAPITAL_KEY: &str = "available_capital";
pub const LOAN_POOL_COLLATERAL: &str = "paid_in_capital";
pub const WHITELIST_CONTRIBUTORS: &str = "whitelist_contributors";
11 changes: 10 additions & 1 deletion crates/contract/src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use thiserror::Error;

use super::aliases::ProvTxResponse;

#[derive(Error, Debug)]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
Expand Down Expand Up @@ -82,6 +82,15 @@ pub enum ContractError {

#[error("Semver parsing error: {0}")]
SemVer(String),

#[error("Loan pool contributor not in whitelist")]
NotInWhitelist {},

#[error("Invalid marker: {message}")]
InvalidMarker { message: String },

#[error("Invalid address: {message}")]
InvalidAddress { message: String },
}

pub fn contract_error(err: &str) -> ProvTxResponse {
Expand Down
1 change: 1 addition & 0 deletions crates/contract/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod aliases;
pub mod collateral;
pub mod constants;
pub mod error;
pub mod fee;
Expand Down
32 changes: 32 additions & 0 deletions crates/contract/src/core/msg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::core::collateral::LoanPoolMarkerCollateral;
use crate::core::security::{
ContributeLoanPools, LoanPoolContributors, RemoveLoanPoolContributors, WithdrawLoanPools,
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Uint64};
use cw2::ContractVersion;
Expand Down Expand Up @@ -39,6 +43,18 @@ pub enum ExecuteMsg {
CancelCommitment {
lp: Addr,
},
ContributeLoanPool {
loan_pools: ContributeLoanPools,
},
WithdrawLoanPool {
loan_pools: WithdrawLoanPools,
},
WhiteListLoanPoolContributors {
loan_pool_contributors: LoanPoolContributors,
},
RemoveWhiteListLoanPoolContributors {
remove_loan_pool_contributors: RemoveLoanPoolContributors,
},
}

#[cw_serde]
Expand All @@ -58,6 +74,12 @@ pub enum QueryMsg {

#[returns(QueryVersionResponse)]
QueryVersion {},

#[returns(QueryLoanPoolCollateralResponse)]
QueryCollaterals {},

#[returns(QueryLoanPoolContributorsResponse)]
QueryLoanPoolContributors {},
}

#[cw_serde]
Expand All @@ -84,6 +106,16 @@ pub struct QueryStateResponse {
pub settlement_time: Option<Uint64>,
}

#[cw_serde]
pub struct QueryLoanPoolCollateralResponse {
pub collaterals: Vec<LoanPoolMarkerCollateral>,
}

#[cw_serde]
pub struct QueryLoanPoolContributorsResponse {
pub contributors: Vec<Addr>,
}

#[cw_serde]
pub struct QueryVersionResponse {
pub contract_version: ContractVersion,
Expand Down
Loading

0 comments on commit 14cb851

Please sign in to comment.