Skip to content

Commit

Permalink
Credit agency: Instantiation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Dec 20, 2023
1 parent ef17582 commit b774f99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
24 changes: 23 additions & 1 deletion contracts/lending/credit-agency/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ pub fn instantiate(
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
todo!();
let default_estimate_multiplier = if msg.default_estimate_multiplier >= Decimal::one() {
msg.default_estimate_multiplier
} else {
return Err(ContractError::InvalidEstimateMultiplier {});
};

// TODO: should we validate Tokens?
let cfg = Config {
gov_contract: msg.gov_contract,
lend_market_id: msg.lending_market_id,
lend_token_id: msg.lending_token_id,
reward_token: msg.reward_token,
common_token: msg.common_token,
liquidation_price: msg.liquidation_price,
borrow_limit_ratio: msg.borrow_limit_ratio,
default_estimate_multiplier,
};
CONFIG.save(deps.storage, &cfg)?;
NEXT_REPLY_ID.save(deps.storage, &0)?;

Ok(Response::new()
.add_attribute("method", "instantiate")
.add_attribute("owner", info.sender))
}

#[cfg_attr(not(feature = "library"), shd_entry_point)]
Expand Down
6 changes: 5 additions & 1 deletion contracts/lending/credit-agency/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
use shade_protocol::{
c_std::{Addr, Decimal, Uint128},
contract_interfaces::snip20::Snip20ReceiveMsg,
utils::asset::Contract,
};

use lending_utils::{coin::Coin, interest::Interest, token::Token};

#[cw_serde]
pub struct InstantiateMsg {
/// The address that controls the credit agency and can set up markets
pub gov_contract: String,
pub gov_contract: Contract,
/// The CodeId of the lending-market contract
pub lending_market_id: u64,
/// The CodeId of the lending-token contract
Expand All @@ -25,6 +26,9 @@ pub struct InstantiateMsg {
/// This is used to prevent borrowers from being liquidated (almost) immediately after borrowing,
/// because they maxed out their credit limit.
pub borrow_limit_ratio: Decimal,
/// How much more of collateral will be used in swap then the estimated amount during
/// swap_withdraw_from
pub default_estimate_multiplier: Decimal,
}

#[cw_serde]
Expand Down

0 comments on commit b774f99

Please sign in to comment.