use cosmwasm_schema::cw_serde;
use cosmwasm_std::{has_coins, Binary, Coin};
use crate::types::{
authenticator::AuthenticatorType,
error::FactoryError,
plugin::PluginInstallParams,
wallet::{Controller, RelayTransaction},
};
pub type ThresholdAbsoluteCount = u64;
#[cw_serde]
pub struct CreateWalletMsg {
pub controller: Controller,
pub relayers: Vec<String>,
pub proxy_initial_funds: Vec<Coin>,
pub vid: String,
pub initial_data: Vec<(Binary, Binary)>,
pub plugins: Vec<PluginInstallParams>,
pub chains: Option<Vec<(String, String)>>,
pub code_id: Option<u64>,
}
impl CreateWalletMsg {
pub fn ensure_has_sufficient_funds(&self, funds: Vec<Coin>) -> Result<(), FactoryError> {
let required_coins = if self.plugins.is_empty() {
self.proxy_initial_funds.clone()
} else {
let mut required_coins = self.proxy_initial_funds.clone();
for p in &self.plugins {
for coin in &p.funds {
required_coins
.iter_mut()
.find(|c| c.denom == coin.denom)
.map(|c| c.amount.checked_add(coin.amount))
.transpose()
.map_err(|_| FactoryError::OverFlow {})?;
}
}
required_coins
};
for coin in required_coins {
if !has_coins(&funds, &coin) {
return Err(FactoryError::InvalidSufficientFunds(
coin.amount.to_string(),
coin.denom,
));
}
}
Ok(())
}
}
#[cw_serde]
pub struct MigrateWalletMsg {
pub addr_to_migrate: String,
pub tx: RelayTransaction,
}
#[cw_serde]
pub struct AuthenticatorInstInfo {
pub ty: AuthenticatorType,
pub code_id: u64,
pub inst_msg: Binary,
}
#[cw_serde]
pub struct WalletFactoryInstantiateMsg {
pub default_proxy_code_id: u64,
pub supported_proxies: Vec<(u64, String)>,
pub wallet_fee: Coin,
pub authenticators: Option<Vec<AuthenticatorInstInfo>>,
pub supported_chains: Option<Vec<(String, ChainConnection)>>,
pub wallet_creator: String,
}
#[cw_serde]
pub enum CodeIdType {
Proxy,
}
#[cw_serde]
pub enum FeeType {
Wallet,
}
#[cw_serde]
pub struct FeesResponse {
pub wallet_fee: Coin,
}
#[cw_serde]
pub enum ChainConnection {
IBC(String),
Other(String),
}