Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum-up the tokens from all lock entries before adding them to BankMsg::Send in unlock_tokens() #43

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions contracts/atom_wars/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// - Covenant Question: Can people sandwich this whole thing - covenant system has price limits - but we should allow people to retry executing the prop during the round

use cosmwasm_std::{
entry_point, to_json_binary, Addr, BankMsg, Binary, Deps, DepsMut, Env, MessageInfo, Order,
Response, StdError, StdResult, Timestamp, Uint128,
entry_point, to_json_binary, Addr, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo,
Order, Response, StdError, StdResult, Timestamp, Uint128,
};
use cw2::set_contract_version;

Expand Down Expand Up @@ -278,14 +278,14 @@ fn unlock_tokens(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response,
.prefix(info.sender.clone())
.range(deps.storage, None, None, Order::Ascending);

let mut sends = vec![];
let mut send = Coin::new(0, CONSTANTS.load(deps.storage)?.denom);
let mut to_delete = vec![];

for lock in locks {
let (lock_id, lock_entry) = lock?;
if lock_entry.lock_end < env.block.time {
// Send tokens back to caller
sends.push(lock_entry.funds.clone());
send.amount = send.amount.checked_add(lock_entry.funds.amount)?;

// Delete entry from LocksMap
to_delete.push((info.sender.clone(), lock_id));
Expand All @@ -299,10 +299,10 @@ fn unlock_tokens(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response,

let mut response = Response::new().add_attribute("action", "unlock_tokens");

if !sends.is_empty() {
if !send.amount.is_zero() {
response = response.add_message(BankMsg::Send {
to_address: info.sender.to_string(),
amount: sends,
amount: vec![send],
})
}

Expand Down
5 changes: 4 additions & 1 deletion contracts/atom_wars/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use cosmwasm_std::StdError;
use cosmwasm_std::{OverflowError, StdError};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
OverflowError(#[from] OverflowError),

#[error("Unauthorized")]
Unauthorized {},
}
Loading