Skip to content

Commit

Permalink
all signer addresses are also linked with the msig
Browse files Browse the repository at this point in the history
  • Loading branch information
FloppyDisck committed Nov 4, 2024
1 parent 1f60e5e commit 2b39b43
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
40 changes: 30 additions & 10 deletions contracts/msig-launcher/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,36 @@ mod tests {
.unwrap();

// Queried
wasm.query::<_, PageResult>(
&launcher,
&QueryMsg::MSigs {
pagination: Pagination {
user: Addr::unchecked(user.address()),
limit: None,
start_at: None,
let res = wasm
.query::<_, PageResult>(
&launcher,
&QueryMsg::MSigs {
pagination: Pagination {
user: Addr::unchecked(user.address()),
limit: None,
start_at: None,
},
},
},
)
.unwrap();
)
.unwrap();
let main = res.data.get(0).unwrap();

for addr in member_accounts {
let res = wasm
.query::<_, PageResult>(
&launcher,
&QueryMsg::MSigs {
pagination: Pagination {
user: Addr::unchecked(addr.address()),
limit: None,
start_at: None,
},
},
)
.unwrap();
let msig = res.data.get(0).unwrap();

assert_eq!(msig, main);
}
}
}
7 changes: 6 additions & 1 deletion contracts/msig-launcher/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub fn execute_instantiate(
let label = format!("{}-{}", info.sender, env.block.height);
let code_ids = MSIG_CODE_IDS.load(deps.storage)?;

let mut involved_addrs = vec![info.sender];
for member in members.iter() {
involved_addrs.push(deps.api.addr_validate(member.addr.as_str())?);
}

let msg = dao_interface::msg::InstantiateMsg {
admin: None,
name,
Expand Down Expand Up @@ -83,7 +88,7 @@ pub fn execute_instantiate(
return Err(ContractError::UnexpectedDoubleTx {});
}

PENDING_MSIG.save(deps.storage, &(info.sender, env.block.height))?;
PENDING_MSIG.save(deps.storage, &(involved_addrs, env.block.height))?;

// Temporarily set the contract's admin to be the smart contract to setup some information
Ok(Response::default().add_submessage(SubMsg::reply_on_success(
Expand Down
9 changes: 6 additions & 3 deletions contracts/msig-launcher/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn set_metadatas(resp: &mut Response, env: &Env, dao_core: String, target_contra
pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractError> {
let mut resp = Response::default();
let code_ids = MSIG_CODE_IDS.load(deps.storage)?;
let (sender, block) = PENDING_MSIG.load(deps.storage)?;
let (involved_addrs, block) = PENDING_MSIG.load(deps.storage)?;
PENDING_MSIG.remove(deps.storage);

let mut builder = MSigBuilder::default();
Expand Down Expand Up @@ -74,9 +74,12 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr

let msig = builder.build()?;

msig.append_attrs(&sender, &mut resp.attributes);
msig.append_attrs(&involved_addrs, &mut resp.attributes);

MSIG.save(deps.storage, (sender, block), &msig)?;
// We save the msig directly since the structure wont update + se save on an extra storage access
for addr in involved_addrs {
MSIG.save(deps.storage, (addr, block), &msig)?;
}

// Set the contract metadata
set_metadatas(
Expand Down
11 changes: 8 additions & 3 deletions contracts/msig-launcher/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ pub struct MSig {
}

impl MSig {
pub fn append_attrs(&self, creator: &Addr, events: &mut Vec<Attribute>) {
events.push(("creator", creator.to_string()).into());
pub fn append_attrs(&self, creator: &[Addr], events: &mut Vec<Attribute>) {
let mut iter = creator.iter();

events.push(("creator", iter.next().unwrap()).into());
for addr in iter {
events.push(("member", addr).into());
}
events.push(("dao_dao_address", self.dao_dao_contract.to_string()).into());
events.push(("voting_address", self.voting_contract.to_string()).into());
events.push(("proposal_address", self.proposal_contract.to_string()).into());
Expand All @@ -91,5 +96,5 @@ impl MSig {
}

pub static MSIG_CODE_IDS: Item<MSigCodeIds> = Item::new("msig_code_ids");
pub static PENDING_MSIG: Item<(Addr, u64)> = Item::new("pending_msig");
pub static PENDING_MSIG: Item<(Vec<Addr>, u64)> = Item::new("pending_msig");
pub static MSIG: Map<(Addr, u64), MSig> = Map::new("msig");

0 comments on commit 2b39b43

Please sign in to comment.