Skip to content

Commit

Permalink
error on no funds sent when required
Browse files Browse the repository at this point in the history
  • Loading branch information
hard-nett committed Jul 7, 2024
1 parent ec62084 commit a61104d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions contracts/gauges/gauge-adapter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ fn receive_cw20_message(
address,
name,
url,
sent_assets: AssetInfo::Cw20(Cw20Coin {
sent_assets: Some(AssetInfo::Cw20(Cw20Coin {
address: cw20,
amount: msg.amount,
}),
})),
},
),
}
Expand Down Expand Up @@ -134,19 +134,27 @@ pub mod execute {
) -> Result<Response, ContractError> {
let address = deps.api.addr_validate(&details.address)?;
let sender = info.sender.clone();
let required_deposit = CONFIG.load(deps.storage)?.required_deposit;

match &details.sent_assets {
AssetInfo::Cw20(_) => return Err(ContractError::Unauthorized {}),
AssetInfo::Native(coin) => {
if coin.amount != Uint128::zero()
&& (info.funds.len() != 1
|| info.funds[0].denom != coin.denom
|| info.funds[0].amount != coin.amount)
{
return Err(ContractError::AssetMismatch {});
None => {
if required_deposit.is_some() {
return Err(ContractError::DepositRequired {});
}
}
};
Some(sent_assets) => match sent_assets {
AssetInfo::Cw20(_) => return Err(ContractError::Unauthorized {}),
AssetInfo::Native(coin) => {
if coin.amount != Uint128::zero()
&& (info.funds.len() != 1
|| info.funds[0].denom != coin.denom
|| info.funds[0].amount != coin.amount)
{
return Err(ContractError::AssetMismatch {});
}
}
},
}
// allow to overwrite submission by the same author
if let Some(old_submission) = SUBMISSIONS.may_load(deps.storage, address.clone())? {
if old_submission.sender != info.sender {
Expand Down
2 changes: 1 addition & 1 deletion contracts/gauges/gauge-adapter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum ExecuteMsg {
name: String,
url: String,
address: String,
assets: AssetInfo,
assets: Option<AssetInfo>,
},
/// Sends back all deposit to senders.
ReturnDeposits {},
Expand Down
2 changes: 1 addition & 1 deletion contracts/gauges/gauge-adapter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct SubmissionDetails {
pub address: String,
pub name: String,
pub url: String,
pub sent_assets: AssetInfo,
pub sent_assets: Option<AssetInfo>,
}

// All submissions indexed by submition's fund destination address.
Expand Down

0 comments on commit a61104d

Please sign in to comment.