diff --git a/contracts/increment/Cargo.toml b/contracts/increment/Cargo.toml index ba60128..1991951 100644 --- a/contracts/increment/Cargo.toml +++ b/contracts/increment/Cargo.toml @@ -42,7 +42,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] archway-bindings = { version = "0.1.0", path = "../../packages/bindings" } cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } +cosmwasm-std = { version = "1.1.9", features = ["staking", "stargate"] } cosmwasm-storage = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } diff --git a/contracts/increment/src/contract.rs b/contracts/increment/src/contract.rs index 8a36651..e5c7393 100644 --- a/contracts/increment/src/contract.rs +++ b/contracts/increment/src/contract.rs @@ -1,11 +1,11 @@ use archway_bindings::types::gov::VoteResponse; use archway_bindings::types::rewards::{ - ContractMetadataResponse, RewardsRecordsResponse, WithdrawRewardsResponse, + ContractMetadataResponse, FlatFeeResponse, RewardsRecordsResponse, WithdrawRewardsResponse, }; use archway_bindings::{ArchwayMsg, ArchwayQuery, ArchwayResult, PageRequest}; use cosmwasm_std::{ - entry_point, to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, - StdError, StdResult, SubMsg, + coin, entry_point, to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, + StdError, StdResult, SubMsg, Uint128, }; use cw2::set_contract_version; use cw_utils::NativeBalance; @@ -54,6 +54,9 @@ pub fn execute( ExecuteMsg::UpdateRewardsAddress { rewards_address } => { update_rewards_address(env, rewards_address) } + ExecuteMsg::SetFlatFee { amount } => { + set_flat_fee(deps.as_ref(), env.contract.address, amount) + } ExecuteMsg::WithdrawRewards {} => withdraw_rewards(), } } @@ -97,6 +100,21 @@ pub fn update_rewards_address( Ok(res) } +fn set_flat_fee( + deps: Deps, + contract_address: Addr, + amount: Uint128, +) -> ArchwayResult { + let denom = deps.querier.query_bonded_denom()?; + let msg = ArchwayMsg::set_flat_fee(contract_address, coin(amount.u128(), denom)); + + let res = Response::new() + .add_message(msg) + .add_attribute("method", "set_fees"); + + Ok(res) +} + fn withdraw_rewards() -> ArchwayResult { let msg = ArchwayMsg::withdraw_rewards_by_limit(0); @@ -146,6 +164,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult to_binary(&flat_fee(deps, env.contract.address)?), QueryMsg::OutstandingRewards {} => to_binary(&outstanding_rewards(deps, env)?), QueryMsg::GovVote { proposal_id, voter } => to_binary(&gov_vote(deps, proposal_id, voter)?), } @@ -164,6 +183,14 @@ fn contract_metadata( deps.querier.query(&req) } +fn flat_fee( + deps: Deps, + contract_address: impl Into, +) -> StdResult { + let req = ArchwayQuery::flat_fee(contract_address).into(); + deps.querier.query(&req) +} + fn outstanding_rewards( deps: Deps, env: Env, diff --git a/contracts/increment/src/msg.rs b/contracts/increment/src/msg.rs index c20e289..f90914c 100644 --- a/contracts/increment/src/msg.rs +++ b/contracts/increment/src/msg.rs @@ -3,7 +3,7 @@ use archway_bindings::{ Coins, }; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::Addr; +use cosmwasm_std::{Addr, Uint128}; #[cw_serde] pub struct InstantiateMsg { @@ -15,6 +15,7 @@ pub enum ExecuteMsg { Increment {}, Reset { count: i32 }, UpdateRewardsAddress { rewards_address: Option }, + SetFlatFee { amount: Uint128 }, WithdrawRewards {}, } @@ -25,6 +26,8 @@ pub enum QueryMsg { GetCount {}, #[returns(rewards::ContractMetadataResponse)] Metadata { contract_address: Option }, + #[returns(rewards::FlatFeeResponse)] + FlatFee {}, #[returns(OutstandingRewardsResponse)] OutstandingRewards {}, #[returns(gov::VoteResponse)] diff --git a/packages/bindings/src/msg.rs b/packages/bindings/src/msg.rs index 6c571c7..ad631ad 100644 --- a/packages/bindings/src/msg.rs +++ b/packages/bindings/src/msg.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::cw_serde; -use cosmwasm_std::{CosmosMsg, CustomMsg}; +use cosmwasm_std::{Coin, CosmosMsg, CustomMsg}; #[cw_serde] pub enum ArchwayMsg { @@ -8,6 +8,10 @@ pub enum ArchwayMsg { owner_address: Option, rewards_address: Option, }, + SetFlatFee { + contract_address: Option, + flat_fee_amount: Coin, + }, WithdrawRewards { records_limit: Option, record_ids: Vec, @@ -61,6 +65,13 @@ impl ArchwayMsg { } } + pub fn set_flat_fee(contract_address: impl Into, amount: Coin) -> Self { + ArchwayMsg::SetFlatFee { + contract_address: Some(contract_address.into()), + flat_fee_amount: amount, + } + } + pub fn withdraw_rewards_by_limit(limit: u64) -> Self { ArchwayMsg::WithdrawRewards { records_limit: Some(limit), diff --git a/packages/bindings/src/query.rs b/packages/bindings/src/query.rs index b58ac40..e2e7b01 100644 --- a/packages/bindings/src/query.rs +++ b/packages/bindings/src/query.rs @@ -9,6 +9,8 @@ use crate::types::{gov, rewards}; pub enum ArchwayQuery { #[returns(rewards::ContractMetadataResponse)] ContractMetadata { contract_address: String }, + #[returns(rewards::FlatFeeResponse)] + FlatFee { contract_address: String }, #[returns(rewards::RewardsRecordsResponse)] RewardsRecords { rewards_address: String, @@ -27,6 +29,12 @@ impl ArchwayQuery { } } + pub fn flat_fee(contract_address: impl Into) -> Self { + ArchwayQuery::FlatFee { + contract_address: contract_address.into(), + } + } + pub fn rewards_records(rewards_address: impl Into) -> Self { ArchwayQuery::RewardsRecords { rewards_address: rewards_address.into(), diff --git a/packages/bindings/src/types/rewards.rs b/packages/bindings/src/types/rewards.rs index 7eb2093..2acfa6b 100644 --- a/packages/bindings/src/types/rewards.rs +++ b/packages/bindings/src/types/rewards.rs @@ -1,4 +1,5 @@ use cosmwasm_schema::cw_serde; +use cosmwasm_std::Coin; use crate::{Coins, PageResponse}; @@ -14,6 +15,11 @@ pub struct ContractMetadataResponse { pub rewards_address: String, } +#[cw_serde] +pub struct FlatFeeResponse { + pub flat_fee_amount: Coin, +} + #[cw_serde] pub struct RewardsRecordsResponse { pub records: Vec,