From cb7b455c0b4861ed4c70c9791fd98d356c4aa39a Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 18:50:44 +0200 Subject: [PATCH 01/53] fix: remove get_state --- checksum | 2 +- contracts/cw-croncat/src/contract.rs | 4 +- contracts/cw-croncat/src/owner.rs | 139 +------ contracts/cw-croncat/src/tests/owner.rs | 119 ------ packages/cw-croncat-core/schema/croncat.json | 307 --------------- .../schema/get_state_response.json | 364 +----------------- .../cw-croncat-core/schema/query_msg.json | 30 -- packages/cw-croncat-core/src/msg.rs | 160 +++----- packages/cw-croncat-core/src/tests/msg.rs | 16 +- .../cw-croncat-core/CwCroncatCore.client.ts | 24 +- .../cw-croncat-core/CwCroncatCore.types.ts | 113 +----- 11 files changed, 84 insertions(+), 1194 deletions(-) diff --git a/checksum b/checksum index f311d653..bed71218 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm +91765daecbccc3669a068086a1de71a16ab4c689b804282d3872b6ee4c7ca992 cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm diff --git a/contracts/cw-croncat/src/contract.rs b/contracts/cw-croncat/src/contract.rs index 62efb809..d1c00d2d 100644 --- a/contracts/cw-croncat/src/contract.rs +++ b/contracts/cw-croncat/src/contract.rs @@ -209,9 +209,7 @@ impl<'a> CwCroncat<'a> { QueryMsg::GetWalletBalances { wallet } => { to_binary(&self.query_wallet_balances(deps, wallet)?) } - QueryMsg::GetState { from_index, limit } => { - to_binary(&self.get_state(deps, env, from_index, limit)?) - } + QueryMsg::GetTaskHash { task } => to_binary(&self.query_get_task_hash(*task)?), } } diff --git a/contracts/cw-croncat/src/owner.rs b/contracts/cw-croncat/src/owner.rs index fef6ff55..36470e3c 100644 --- a/contracts/cw-croncat/src/owner.rs +++ b/contracts/cw-croncat/src/owner.rs @@ -1,16 +1,13 @@ -use crate::balancer::BalancerMode; use crate::error::ContractError; use crate::helpers::has_cw_coins; use crate::state::{Config, CwCroncat}; use cosmwasm_std::{ - has_coins, to_binary, BankMsg, Coin, Deps, DepsMut, Env, MessageInfo, Order, Response, - StdResult, SubMsg, Uint64, WasmMsg, + has_coins, to_binary, BankMsg, Coin, Deps, DepsMut, Env, MessageInfo, Response, StdResult, + SubMsg, WasmMsg, }; use cw20::{Balance, Cw20ExecuteMsg}; use cw_croncat_core::msg::{ - BalancesResponse, CwCroncatResponse, ExecuteMsg, GetBalancesResponse, GetConfigResponse, - GetWalletBalancesResponse, RoundRobinBalancerModeResponse, SlotResponse, - SlotWithQueriesResponse, + ExecuteMsg, GetBalancesResponse, GetConfigResponse, GetWalletBalancesResponse, }; use cw_croncat_core::traits::FindAndMutate; @@ -275,134 +272,4 @@ impl<'a> CwCroncat<'a> { .add_attribute("account_id", account_id.to_string()) .add_submessages(messages?)) } - - pub(crate) fn get_state( - &self, - deps: Deps, - env: Env, - from_index: Option, - limit: Option, - ) -> StdResult { - let default_limit = self.config.load(deps.storage)?.limit; - let size: u64 = self.task_total.load(deps.storage)?.min(default_limit); - let from_index_unwrap = from_index.unwrap_or_default(); - let limit_unwrap = limit.unwrap_or(default_limit).min(size) as usize; - - let mut agents = Vec::with_capacity(limit_unwrap); - for agent in self - .agents - .keys(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap) - { - let agent_info = self.query_get_agent(deps, env.clone(), agent?.to_string())?; - agents.push(agent_info.unwrap()); - } - - let time_slots: Vec = self - .time_slots - .range(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap as usize) - .map(|res| { - let res = res.unwrap(); - SlotResponse { - slot: res.0.into(), - tasks: res.1, - } - }) - .collect(); - - let block_slots: Vec = self - .block_slots - .range(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap as usize) - .map(|res| { - let res = res.unwrap(); - SlotResponse { - slot: res.0.into(), - tasks: res.1, - } - }) - .collect(); - - let balances: Vec = self - .balances - .range(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap as usize) - .map(|res| { - let res = res.unwrap(); - BalancesResponse { - address: res.0, - balances: res.1, - } - }) - .collect(); - - let balancer_mode = match self.balancer.mode { - BalancerMode::ActivationOrder => RoundRobinBalancerModeResponse::ActivationOrder, - BalancerMode::Equalizer => RoundRobinBalancerModeResponse::Equalizer, - }; - - let time_slots_queries: Vec = self - .time_map_queries - .range(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap as usize) - .map(|res| { - let res = res.unwrap(); - SlotWithQueriesResponse { - task_hash: res.0, - slot: res.1.into(), - } - }) - .collect(); - - let block_slots_queries: Vec = self - .block_map_queries - .range(deps.storage, None, None, Order::Ascending) - .skip(from_index_unwrap as usize) - .take(limit_unwrap as usize) - .map(|res| { - let res = res.unwrap(); - SlotWithQueriesResponse { - task_hash: res.0, - slot: res.1.into(), - } - }) - .collect(); - - Ok(CwCroncatResponse { - config: self.query_config(deps)?, - - agent_active_queue: self.agent_active_queue.load(deps.storage)?, - agent_pending_queue: self - .agent_pending_queue - .iter(deps.storage)? - .take(50) - .collect::>>()?, - agents, - - tasks: self.query_get_tasks(deps, None, None)?, - task_total: Uint64::from(self.task_total.load(deps.storage)?), - - time_slots, - block_slots, - - tasks_with_queries: self.query_get_tasks_with_queries(deps, from_index, limit)?, - tasks_with_queries_total: Uint64::from( - self.tasks_with_queries_total.load(deps.storage)?, - ), - time_slots_queries, - block_slots_queries, - - reply_index: Uint64::from(self.reply_index.load(deps.storage)?), - agent_nomination_begin_time: self.agent_nomination_begin_time.load(deps.storage)?, - - balances, - balancer_mode, - }) - } } diff --git a/contracts/cw-croncat/src/tests/owner.rs b/contracts/cw-croncat/src/tests/owner.rs index 4faa27da..a8faad33 100644 --- a/contracts/cw-croncat/src/tests/owner.rs +++ b/contracts/cw-croncat/src/tests/owner.rs @@ -285,122 +285,3 @@ fn move_balances_native() { // // assert_eq!(true, value.paused); // // assert_eq!(info.sender, value.owner_id); // } - -#[test] -fn test_get_state() { - let (mut app, cw_template_contract, _) = proper_instantiate(); - let contract_addr = cw_template_contract.addr(); - - let state: StdResult = app.wrap().query_wasm_smart( - &contract_addr.clone(), - &QueryMsg::GetState { - from_index: None, - limit: None, - }, - ); - assert!(state.is_ok()); - let state = state.unwrap(); - - assert_eq!(state.config.paused, false); - assert_eq!(state.config.owner_id.as_str(), ADMIN); - assert_eq!(state.config.agent_fee, 5); - assert_eq!(state.config.gas_base_fee, 300_000); - assert_eq!(state.config.gas_action_fee, 130_000); - assert_eq!(state.config.proxy_callback_gas, 3); - assert!(state.agent_active_queue.is_empty()); - assert!(state.agent_pending_queue.is_empty()); - assert!(state.agents.is_empty()); - assert!(state.tasks.is_empty()); - assert_eq!(state.task_total, Uint64::zero()); - assert!(state.time_slots.is_empty()); - assert!(state.block_slots.is_empty()); - assert!(state.tasks_with_queries.is_empty()); - assert_eq!(state.tasks_with_queries_total, Uint64::zero()); - assert!(state.time_slots_queries.is_empty()); - assert!(state.block_slots_queries.is_empty()); - assert_eq!(state.reply_index, Uint64::zero()); - assert_eq!(state.agent_nomination_begin_time, None); - assert_eq!( - state.balancer_mode, - RoundRobinBalancerModeResponse::ActivationOrder - ); - assert!(state.balances.is_empty()); - - // Create a task - let msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: contract_addr.to_string(), - msg: to_binary(&ExecuteMsg::WithdrawReward {}).unwrap(), - funds: coins(1, NATIVE_DENOM), - }); - - let create_task_msg = ExecuteMsg::CreateTask { - task: TaskRequest { - interval: Interval::Immediate, - boundary: Some(Boundary::Height { - start: None, - end: None, - }), - stop_on_fail: false, - actions: vec![Action { - msg, - gas_limit: Some(250_000), - }], - queries: None, - transforms: None, - cw20_coins: vec![], - }, - }; - - // create a task - app.execute_contract( - Addr::unchecked(ADMIN), - contract_addr.clone(), - &create_task_msg, - &coins(525000, NATIVE_DENOM), - ) - .unwrap(); - - // quick agent register - let msg = ExecuteMsg::RegisterAgent { - payable_account_id: Some(AGENT_BENEFICIARY.to_string()), - }; - app.execute_contract(Addr::unchecked(AGENT0), contract_addr.clone(), &msg, &[]) - .unwrap(); - // in pending queue - app.execute_contract(Addr::unchecked(ANYONE), contract_addr.clone(), &msg, &[]) - .unwrap(); - - // might need block advancement - app.update_block(add_little_time); - - let state: StdResult = app.wrap().query_wasm_smart( - &contract_addr.clone(), - &QueryMsg::GetState { - from_index: None, - limit: None, - }, - ); - assert!(state.is_ok()); - let state = state.unwrap(); - - let task_id_str = - "1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string(); - - assert_eq!(state.agent_active_queue.len(), 1); - assert_eq!(state.agent_active_queue[0].as_str(), AGENT0); - assert_eq!(state.agent_pending_queue.len(), 1); - assert_eq!(state.agent_pending_queue[0].as_str(), ANYONE); - assert_eq!(state.agents.len(), 1); - assert_eq!(state.tasks.len(), 1); - assert_eq!(state.tasks[0].task_hash, task_id_str); - assert_eq!(state.task_total, Uint64::from(1u64)); - assert!(state.time_slots.is_empty()); - assert_eq!(state.block_slots.len(), 1); - assert!(state.tasks_with_queries.is_empty()); - assert_eq!(state.tasks_with_queries_total, Uint64::zero()); - assert!(state.time_slots_queries.is_empty()); - assert!(state.block_slots_queries.is_empty()); - assert_eq!(state.reply_index, Uint64::zero()); - assert!(state.agent_nomination_begin_time.is_some()); - assert!(state.balances.is_empty()); -} diff --git a/packages/cw-croncat-core/schema/croncat.json b/packages/cw-croncat-core/schema/croncat.json index 94a331c6..53bb50a3 100644 --- a/packages/cw-croncat-core/schema/croncat.json +++ b/packages/cw-croncat-core/schema/croncat.json @@ -13,53 +13,6 @@ } ] }, - "BalanceResponse": { - "anyOf": [ - { - "$ref": "#/definitions/GetBalancesResponse" - }, - { - "type": "null" - } - ] - }, - "ConfigResponse": { - "anyOf": [ - { - "$ref": "#/definitions/GetConfigResponse" - }, - { - "type": "null" - } - ] - }, - "GetAgentIdsResponse": { - "anyOf": [ - { - "$ref": "#/definitions/GetAgentIdsResponse" - }, - { - "type": "null" - } - ] - }, - "GetAgentResponse": { - "anyOf": [ - { - "anyOf": [ - { - "$ref": "#/definitions/AgentResponse" - }, - { - "type": "null" - } - ] - }, - { - "type": "null" - } - ] - }, "GetAgentTasksResponse": { "anyOf": [ { @@ -131,16 +84,6 @@ "$ref": "#/definitions/TaskResponse" } }, - "GetWalletBalancesResponse": { - "anyOf": [ - { - "$ref": "#/definitions/GetWalletBalancesResponse" - }, - { - "type": "null" - } - ] - }, "Task": { "anyOf": [ { @@ -239,49 +182,6 @@ } } }, - "AgentResponse": { - "type": "object", - "required": [ - "balance", - "last_executed_slot", - "payable_account_id", - "register_start", - "status", - "total_tasks_executed" - ], - "properties": { - "balance": { - "$ref": "#/definitions/GenericBalance" - }, - "last_executed_slot": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "payable_account_id": { - "$ref": "#/definitions/Addr" - }, - "register_start": { - "$ref": "#/definitions/Timestamp" - }, - "status": { - "$ref": "#/definitions/AgentStatus" - }, - "total_tasks_executed": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "AgentStatus": { - "type": "string", - "enum": [ - "Active", - "Pending", - "Nominated" - ] - }, "AgentTaskResponse": { "type": "object", "required": [ @@ -826,25 +726,6 @@ "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" }, - "GasFraction": { - "type": "object", - "required": [ - "denominator", - "numerator" - ], - "properties": { - "denominator": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "numerator": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, "GenericBalance": { "type": "object", "required": [ @@ -893,173 +774,6 @@ } } }, - "GetAgentIdsResponse": { - "type": "object", - "required": [ - "active", - "pending" - ], - "properties": { - "active": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "pending": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - } - } - }, - "GetBalancesResponse": { - "type": "object", - "required": [ - "available_balance", - "cw20_whitelist", - "native_denom", - "staked_balance" - ], - "properties": { - "available_balance": { - "$ref": "#/definitions/GenericBalance" - }, - "cw20_whitelist": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "native_denom": { - "type": "string" - }, - "staked_balance": { - "$ref": "#/definitions/GenericBalance" - } - } - }, - "GetConfigResponse": { - "type": "object", - "required": [ - "agent_active_indices", - "agent_fee", - "agent_nomination_duration", - "agents_eject_threshold", - "available_balance", - "cw20_whitelist", - "cw_rules_addr", - "gas_action_fee", - "gas_base_fee", - "gas_fraction", - "limit", - "min_tasks_per_agent", - "native_denom", - "owner_id", - "paused", - "proxy_callback_gas", - "slot_granularity_time", - "staked_balance" - ], - "properties": { - "agent_active_indices": { - "type": "array", - "items": { - "type": "array", - "items": [ - { - "$ref": "#/definitions/SlotType" - }, - { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - } - ], - "maxItems": 3, - "minItems": 3 - } - }, - "agent_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "agent_nomination_duration": { - "type": "integer", - "format": "uint16", - "minimum": 0.0 - }, - "agents_eject_threshold": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "available_balance": { - "$ref": "#/definitions/GenericBalance" - }, - "cw20_whitelist": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "cw_rules_addr": { - "$ref": "#/definitions/Addr" - }, - "gas_action_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "gas_base_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "gas_fraction": { - "$ref": "#/definitions/GasFraction" - }, - "limit": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "min_tasks_per_agent": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "native_denom": { - "type": "string" - }, - "owner_id": { - "$ref": "#/definitions/Addr" - }, - "paused": { - "type": "boolean" - }, - "proxy_callback_gas": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "slot_granularity_time": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "staked_balance": { - "$ref": "#/definitions/GenericBalance" - } - } - }, "GetSlotHashesResponse": { "type": "object", "required": [ @@ -1118,20 +832,6 @@ } } }, - "GetWalletBalancesResponse": { - "type": "object", - "required": [ - "cw20_balances" - ], - "properties": { - "cw20_balances": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20CoinVerified" - } - } - } - }, "GovMsg": { "oneOf": [ { @@ -1390,13 +1090,6 @@ "$ref": "#/definitions/ValueIndex" } }, - "SlotType": { - "type": "string", - "enum": [ - "Block", - "Cron" - ] - }, "SmartQueries": { "type": "array", "items": { diff --git a/packages/cw-croncat-core/schema/get_state_response.json b/packages/cw-croncat-core/schema/get_state_response.json index f72806ec..6bac1a01 100644 --- a/packages/cw-croncat-core/schema/get_state_response.json +++ b/packages/cw-croncat-core/schema/get_state_response.json @@ -5,19 +5,10 @@ "required": [ "agent_active_queue", "agent_pending_queue", - "agents", "balancer_mode", - "balances", - "block_slots", - "block_slots_queries", - "config", "reply_index", "task_total", - "tasks", - "tasks_with_queries", - "tasks_with_queries_total", - "time_slots", - "time_slots_queries" + "tasks" ], "properties": { "agent_active_queue": { @@ -42,36 +33,9 @@ "$ref": "#/definitions/Addr" } }, - "agents": { - "type": "array", - "items": { - "$ref": "#/definitions/AgentResponse" - } - }, "balancer_mode": { "$ref": "#/definitions/RoundRobinBalancerModeResponse" }, - "balances": { - "type": "array", - "items": { - "$ref": "#/definitions/BalancesResponse" - } - }, - "block_slots": { - "type": "array", - "items": { - "$ref": "#/definitions/SlotResponse" - } - }, - "block_slots_queries": { - "type": "array", - "items": { - "$ref": "#/definitions/SlotWithQueriesResponse" - } - }, - "config": { - "$ref": "#/definitions/GetConfigResponse" - }, "reply_index": { "$ref": "#/definitions/Uint64" }, @@ -83,27 +47,6 @@ "items": { "$ref": "#/definitions/TaskResponse" } - }, - "tasks_with_queries": { - "type": "array", - "items": { - "$ref": "#/definitions/TaskWithQueriesResponse" - } - }, - "tasks_with_queries_total": { - "$ref": "#/definitions/Uint64" - }, - "time_slots": { - "type": "array", - "items": { - "$ref": "#/definitions/SlotResponse" - } - }, - "time_slots_queries": { - "type": "array", - "items": { - "$ref": "#/definitions/SlotWithQueriesResponse" - } } }, "definitions": { @@ -136,49 +79,6 @@ "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", "type": "string" }, - "AgentResponse": { - "type": "object", - "required": [ - "balance", - "last_executed_slot", - "payable_account_id", - "register_start", - "status", - "total_tasks_executed" - ], - "properties": { - "balance": { - "$ref": "#/definitions/GenericBalance" - }, - "last_executed_slot": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "payable_account_id": { - "$ref": "#/definitions/Addr" - }, - "register_start": { - "$ref": "#/definitions/Timestamp" - }, - "status": { - "$ref": "#/definitions/AgentStatus" - }, - "total_tasks_executed": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "AgentStatus": { - "type": "string", - "enum": [ - "Active", - "Pending", - "Nominated" - ] - }, "Balance": { "oneOf": [ { @@ -207,24 +107,6 @@ } ] }, - "BalancesResponse": { - "type": "object", - "required": [ - "address", - "balances" - ], - "properties": { - "address": { - "$ref": "#/definitions/Addr" - }, - "balances": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20CoinVerified" - } - } - } - }, "BankMsg": { "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", "oneOf": [ @@ -682,46 +564,6 @@ "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" }, - "GasFraction": { - "type": "object", - "required": [ - "denominator", - "numerator" - ], - "properties": { - "denominator": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "numerator": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "GenericBalance": { - "type": "object", - "required": [ - "cw20", - "native" - ], - "properties": { - "cw20": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20CoinVerified" - } - }, - "native": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - }, "GenericQuery": { "type": "object", "required": [ @@ -749,126 +591,6 @@ } } }, - "GetConfigResponse": { - "type": "object", - "required": [ - "agent_active_indices", - "agent_fee", - "agent_nomination_duration", - "agents_eject_threshold", - "available_balance", - "cw20_whitelist", - "cw_rules_addr", - "gas_action_fee", - "gas_base_fee", - "gas_fraction", - "limit", - "min_tasks_per_agent", - "native_denom", - "owner_id", - "paused", - "proxy_callback_gas", - "slot_granularity_time", - "staked_balance" - ], - "properties": { - "agent_active_indices": { - "type": "array", - "items": { - "type": "array", - "items": [ - { - "$ref": "#/definitions/SlotType" - }, - { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - } - ], - "maxItems": 3, - "minItems": 3 - } - }, - "agent_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "agent_nomination_duration": { - "type": "integer", - "format": "uint16", - "minimum": 0.0 - }, - "agents_eject_threshold": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "available_balance": { - "$ref": "#/definitions/GenericBalance" - }, - "cw20_whitelist": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "cw_rules_addr": { - "$ref": "#/definitions/Addr" - }, - "gas_action_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "gas_base_fee": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "gas_fraction": { - "$ref": "#/definitions/GasFraction" - }, - "limit": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "min_tasks_per_agent": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "native_denom": { - "type": "string" - }, - "owner_id": { - "$ref": "#/definitions/Addr" - }, - "paused": { - "type": "boolean" - }, - "proxy_callback_gas": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "slot_granularity_time": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "staked_balance": { - "$ref": "#/definitions/GenericBalance" - } - } - }, "GovMsg": { "oneOf": [ { @@ -1134,56 +856,6 @@ "Equalizer" ] }, - "SlotResponse": { - "type": "object", - "required": [ - "slot", - "tasks" - ], - "properties": { - "slot": { - "$ref": "#/definitions/Uint64" - }, - "tasks": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - } - } - } - } - }, - "SlotType": { - "type": "string", - "enum": [ - "Block", - "Cron" - ] - }, - "SlotWithQueriesResponse": { - "type": "object", - "required": [ - "slot", - "task_hash" - ], - "properties": { - "slot": { - "$ref": "#/definitions/Uint64" - }, - "task_hash": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - } - } - } - }, "SmartQueries": { "type": "array", "items": { @@ -1470,40 +1142,6 @@ } } }, - "TaskWithQueriesResponse": { - "type": "object", - "required": [ - "interval", - "task_hash" - ], - "properties": { - "boundary": { - "anyOf": [ - { - "$ref": "#/definitions/Boundary" - }, - { - "type": "null" - } - ] - }, - "interval": { - "$ref": "#/definitions/Interval" - }, - "queries": { - "type": [ - "array", - "null" - ], - "items": { - "$ref": "#/definitions/CroncatQuery" - } - }, - "task_hash": { - "type": "string" - } - } - }, "Timestamp": { "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ diff --git a/packages/cw-croncat-core/schema/query_msg.json b/packages/cw-croncat-core/schema/query_msg.json index 269736a3..57f23427 100644 --- a/packages/cw-croncat-core/schema/query_msg.json +++ b/packages/cw-croncat-core/schema/query_msg.json @@ -271,36 +271,6 @@ } }, "additionalProperties": false - }, - { - "type": "object", - "required": [ - "get_state" - ], - "properties": { - "get_state": { - "type": "object", - "properties": { - "from_index": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - }, - "limit": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false } ], "definitions": { diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index 8e48b06d..a48422a1 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -39,21 +39,17 @@ use serde::{Deserialize, Serialize}; pub struct Croncat { pub(crate) agent: Option, pub(crate) task: Option, - pub(crate) config_response: Option, - pub(crate) balance_response: Option, - pub(crate) get_agent_ids_response: Option, + pub(crate) get_agent_tasks_response: Option, pub(crate) task_request: Option, pub(crate) task_response: Option, pub(crate) validate_interval_response: Option, - pub(crate) get_agent_response: Option>, pub(crate) get_tasks_response: Option>, pub(crate) get_tasks_by_owner_response: Option>, pub(crate) get_task_response: Option>, pub(crate) get_task_hash_response: Option, pub(crate) get_slot_hashes_response: Option, pub(crate) get_slot_ids_response: Option, - pub(crate) get_wallet_balances_response: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] @@ -164,68 +160,6 @@ pub enum QueryMsg { GetWalletBalances { wallet: String, }, - GetState { - from_index: Option, - limit: Option, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct GetConfigResponse { - pub paused: bool, - pub owner_id: Addr, - // pub treasury_id: Option, - pub min_tasks_per_agent: u64, - pub agents_eject_threshold: u64, - pub agent_active_indices: Vec<(SlotType, u32, u32)>, - pub agent_nomination_duration: u16, - - pub cw_rules_addr: Addr, - - pub agent_fee: u64, - pub gas_fraction: GasFraction, - pub gas_base_fee: u64, - pub gas_action_fee: u64, - pub proxy_callback_gas: u32, - pub slot_granularity_time: u64, - - pub cw20_whitelist: Vec, - pub native_denom: String, - pub available_balance: GenericBalance, // tasks + rewards balances - pub staked_balance: GenericBalance, // surplus that is temporary staking (to be used in conjunction with external treasury) - - // The default amount of tasks to query - pub limit: u64, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct GetBalancesResponse { - pub native_denom: String, - pub available_balance: GenericBalance, - pub staked_balance: GenericBalance, - pub cw20_whitelist: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct GetWalletBalancesResponse { - pub cw20_balances: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct GetAgentIdsResponse { - pub active: Vec, - pub pending: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct AgentResponse { - // This field doesn't exist in the Agent struct and is the only one that differs - pub status: AgentStatus, - pub payable_account_id: Addr, - pub balance: GenericBalance, - pub total_tasks_executed: u64, - pub last_executed_slot: u64, - pub register_start: Timestamp, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] @@ -417,41 +351,43 @@ pub struct TaskWithQueriesResponse { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct CwCroncatResponse { - pub config: GetConfigResponse, - pub agent_active_queue: Vec, pub agent_pending_queue: Vec, - pub agents: Vec, - pub tasks: Vec, pub task_total: Uint64, - - pub time_slots: Vec, - pub block_slots: Vec, - pub tasks_with_queries: Vec, - pub tasks_with_queries_total: Uint64, - - pub time_slots_queries: Vec, - pub block_slots_queries: Vec, - pub reply_index: Uint64, pub agent_nomination_begin_time: Option, pub balancer_mode: RoundRobinBalancerModeResponse, - pub balances: Vec, +} +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct GetBalancesResponse { + pub native_denom: String, + pub available_balance: GenericBalance, + pub staked_balance: GenericBalance, + pub cw20_whitelist: Vec, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct GetWalletBalancesResponse { + pub cw20_balances: Vec, +} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct SlotResponse { - pub slot: Uint64, - pub tasks: Vec>, +pub struct GetAgentIdsResponse { + pub active: Vec, + pub pending: Vec, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct BalancesResponse { - pub address: Addr, - pub balances: Vec, +pub struct AgentResponse { + // This field doesn't exist in the Agent struct and is the only one that differs + pub status: AgentStatus, + pub payable_account_id: Addr, + pub balance: GenericBalance, + pub total_tasks_executed: u64, + pub last_executed_slot: u64, + pub register_start: Timestamp, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] @@ -460,28 +396,6 @@ pub enum RoundRobinBalancerModeResponse { Equalizer, } -// #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -// pub struct ReplyQueueResponse { -// pub index: Uint64, -// pub item: QueueItemResponse, -// } - -// #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -// pub struct QueueItemResponse { -// pub contract_addr: Option, -// pub action_idx: Uint64, -// pub task_hash: Option>, -// pub task_is_extra: Option, -// pub agent_id: Option, -// pub failed: bool, -// } - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct SlotWithQueriesResponse { - pub task_hash: Vec, - pub slot: Uint64, -} - impl From for TaskResponse { fn from(task: Task) -> Self { let boundary = match (task.boundary, &task.interval) { @@ -564,3 +478,31 @@ pub struct GetSlotIdsResponse { pub struct QueryConstruct { pub queries: Vec, } + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct GetConfigResponse { + pub paused: bool, + pub owner_id: Addr, + // pub treasury_id: Option, + pub min_tasks_per_agent: u64, + pub agents_eject_threshold: u64, + pub agent_active_indices: Vec<(SlotType, u32, u32)>, + pub agent_nomination_duration: u16, + + pub cw_rules_addr: Addr, + + pub agent_fee: u64, + pub gas_fraction: GasFraction, + pub gas_base_fee: u64, + pub gas_action_fee: u64, + pub proxy_callback_gas: u32, + pub slot_granularity_time: u64, + + pub cw20_whitelist: Vec, + pub native_denom: String, + pub available_balance: GenericBalance, // tasks + rewards balances + pub staked_balance: GenericBalance, // surplus that is temporary staking (to be used in conjunction with external treasury) + + // The default amount of tasks to query + pub limit: u64, +} diff --git a/packages/cw-croncat-core/src/tests/msg.rs b/packages/cw-croncat-core/src/tests/msg.rs index 21cdacd1..aeb72465 100644 --- a/packages/cw-croncat-core/src/tests/msg.rs +++ b/packages/cw-croncat-core/src/tests/msg.rs @@ -58,7 +58,7 @@ fn everything_can_be_de_serialized() { } .into(); - let config_response = GetConfigResponse { + let config_response: GetConfigResponse = GetConfigResponse { paused: true, owner_id: Addr::unchecked("bob"), min_tasks_per_agent: 5, @@ -82,14 +82,14 @@ fn everything_can_be_de_serialized() { limit: 100, } .into(); - let balance_response = GetBalancesResponse { + let balance_response: GetBalancesResponse = GetBalancesResponse { native_denom: "some".to_string(), available_balance: generic_balance.clone(), staked_balance: generic_balance.clone(), cw20_whitelist: vec![Addr::unchecked("bob")], } .into(); - let get_agent_ids_response = GetAgentIdsResponse { + let get_agent_ids_response: GetAgentIdsResponse = GetAgentIdsResponse { active: vec![Addr::unchecked("bob")], pending: vec![Addr::unchecked("bob")], } @@ -132,7 +132,7 @@ fn everything_can_be_de_serialized() { }; let task_response = task_response_raw.clone().into(); let validate_interval_response = false.into(); - let get_agent_response = Some(AgentResponse { + let get_agent_response: Option = Some(AgentResponse { status: AgentStatus::Active, payable_account_id: Addr::unchecked("bob"), balance: generic_balance.clone(), @@ -157,7 +157,7 @@ fn everything_can_be_de_serialized() { block_ids: vec![3], } .into(); - let get_wallet_balances_response = GetWalletBalancesResponse { + let get_wallet_balances_response: GetWalletBalancesResponse = GetWalletBalancesResponse { cw20_balances: vec![Cw20CoinVerified { address: Addr::unchecked("Bob"), amount: 5u128.into(), @@ -167,21 +167,17 @@ fn everything_can_be_de_serialized() { let croncat = Croncat { agent, task, - config_response, - balance_response, - get_agent_ids_response, + get_agent_tasks_response, task_request, task_response, validate_interval_response, - get_agent_response, get_tasks_response, get_tasks_by_owner_response, get_task_response, get_task_hash_response, get_slot_hashes_response, get_slot_ids_response, - get_wallet_balances_response, }; let ser = serde_json_wasm::to_string(&croncat); diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index befe9a5f..6ea85c6c 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -6,7 +6,7 @@ import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; import { StdFee } from "@cosmjs/amino"; -import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasFraction, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, RoundRobinBalancerModeResponse, GetStateResponse, BalancesResponse, SlotResponse, SlotWithQueriesResponse, TaskWithQueriesResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; +import { Addr, Uint128, Timestamp, Uint64, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, GasFraction, Cw20ReceiveMsg, GetAgentResponse, AgentStatus, AgentResponse, GetAgentTasksResponse, RoundRobinBalancerModeResponse, GetStateResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; export interface CwCroncatCoreReadOnlyInterface { contractAddress: string; getConfig: () => Promise; @@ -67,13 +67,6 @@ export interface CwCroncatCoreReadOnlyInterface { }: { wallet: string; }) => Promise; - getState: ({ - fromIndex, - limit - }: { - fromIndex?: number; - limit?: number; - }) => Promise; } export class CwCroncatCoreQueryClient implements CwCroncatCoreReadOnlyInterface { client: CosmWasmClient; @@ -96,7 +89,6 @@ export class CwCroncatCoreQueryClient implements CwCroncatCoreReadOnlyInterface this.getSlotHashes = this.getSlotHashes.bind(this); this.getSlotIds = this.getSlotIds.bind(this); this.getWalletBalances = this.getWalletBalances.bind(this); - this.getState = this.getState.bind(this); } getConfig = async (): Promise => { @@ -235,20 +227,6 @@ export class CwCroncatCoreQueryClient implements CwCroncatCoreReadOnlyInterface } }); }; - getState = async ({ - fromIndex, - limit - }: { - fromIndex?: number; - limit?: number; - }): Promise => { - return this.client.queryContractSmart(this.contractAddress, { - get_state: { - from_index: fromIndex, - limit - } - }); - }; } export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { contractAddress: string; diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index 8785d9c1..f4964a76 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -8,8 +8,6 @@ export type Addr = string; export type Uint128 = string; export type Timestamp = Uint64; export type Uint64 = string; -export type SlotType = "Block" | "Cron"; -export type AgentStatus = "Active" | "Pending" | "Nominated"; export type CosmosMsgForEmpty = { bank: BankMsg; } | { @@ -191,10 +189,6 @@ export type PathToValue = ValueIndex[]; export type SmartQueries = SmartQuery[]; export interface Croncat { Agent?: Agent | null; - BalanceResponse?: GetBalancesResponse | null; - ConfigResponse?: GetConfigResponse | null; - GetAgentIdsResponse?: GetAgentIdsResponse | null; - GetAgentResponse?: (AgentResponse | null) | null; GetAgentTasksResponse?: AgentTaskResponse | null; GetSlotHashesResponse?: GetSlotHashesResponse | null; GetSlotIdsResponse?: GetSlotIdsResponse | null; @@ -202,7 +196,6 @@ export interface Croncat { GetTaskResponse?: (TaskResponse | null) | null; GetTasksByOwnerResponse?: TaskResponse[] | null; GetTasksResponse?: TaskResponse[] | null; - GetWalletBalancesResponse?: GetWalletBalancesResponse | null; Task?: Task | null; TaskRequest?: TaskRequest | null; TaskResponse?: TaskResponse | null; @@ -232,53 +225,6 @@ export interface Coin { denom: string; [k: string]: unknown; } -export interface GetBalancesResponse { - available_balance: GenericBalance; - cw20_whitelist: Addr[]; - native_denom: string; - staked_balance: GenericBalance; - [k: string]: unknown; -} -export interface GetConfigResponse { - agent_active_indices: [SlotType, number, number][]; - agent_fee: number; - agent_nomination_duration: number; - agents_eject_threshold: number; - available_balance: GenericBalance; - cw20_whitelist: Addr[]; - cw_rules_addr: Addr; - gas_action_fee: number; - gas_base_fee: number; - gas_fraction: GasFraction; - limit: number; - min_tasks_per_agent: number; - native_denom: string; - owner_id: Addr; - paused: boolean; - proxy_callback_gas: number; - slot_granularity_time: number; - staked_balance: GenericBalance; - [k: string]: unknown; -} -export interface GasFraction { - denominator: number; - numerator: number; - [k: string]: unknown; -} -export interface GetAgentIdsResponse { - active: Addr[]; - pending: Addr[]; - [k: string]: unknown; -} -export interface AgentResponse { - balance: GenericBalance; - last_executed_slot: number; - payable_account_id: Addr; - register_start: Timestamp; - status: AgentStatus; - total_tasks_executed: number; - [k: string]: unknown; -} export interface AgentTaskResponse { num_block_tasks: Uint64; num_block_tasks_extra: Uint64; @@ -371,10 +317,6 @@ export interface SmartQuery { path_to_query_value: PathToValue; [k: string]: unknown; } -export interface GetWalletBalancesResponse { - cw20_balances: Cw20CoinVerified[]; - [k: string]: unknown; -} export interface Task { actions: ActionForEmpty[]; amount_for_one_task: GenericBalance; @@ -496,6 +438,11 @@ export type ExecuteMsg = { [k: string]: unknown; }; }; +export interface GasFraction { + denominator: number; + numerator: number; + [k: string]: unknown; +} export interface Cw20ReceiveMsg { amount: Uint128; msg: Binary; @@ -503,42 +450,33 @@ export interface Cw20ReceiveMsg { [k: string]: unknown; } export type GetAgentResponse = AgentResponse | null; +export type AgentStatus = "Active" | "Pending" | "Nominated"; +export interface AgentResponse { + balance: GenericBalance; + last_executed_slot: number; + payable_account_id: Addr; + register_start: Timestamp; + status: AgentStatus; + total_tasks_executed: number; + [k: string]: unknown; +} export type GetAgentTasksResponse = TaskResponse | null; export type RoundRobinBalancerModeResponse = "ActivationOrder" | "Equalizer"; export interface GetStateResponse { agent_active_queue: Addr[]; agent_nomination_begin_time?: Timestamp | null; agent_pending_queue: Addr[]; - agents: AgentResponse[]; balancer_mode: RoundRobinBalancerModeResponse; - balances: BalancesResponse[]; - block_slots: SlotResponse[]; - block_slots_queries: SlotWithQueriesResponse[]; - config: GetConfigResponse; reply_index: Uint64; task_total: Uint64; tasks: TaskResponse[]; - tasks_with_queries: TaskWithQueriesResponse[]; - tasks_with_queries_total: Uint64; - time_slots: SlotResponse[]; - time_slots_queries: SlotWithQueriesResponse[]; - [k: string]: unknown; -} -export interface BalancesResponse { - address: Addr; - balances: Cw20CoinVerified[]; - [k: string]: unknown; -} -export interface SlotResponse { - slot: Uint64; - tasks: number[][]; - [k: string]: unknown; -} -export interface SlotWithQueriesResponse { - slot: Uint64; - task_hash: number[]; [k: string]: unknown; } +export type GetTaskHashResponse = string; +export type GetTaskResponse = TaskResponse | null; +export type GetTasksByOwnerResponse = TaskResponse[]; +export type GetTasksResponse = TaskResponse[]; +export type GetTasksWithQueriesResponse = TaskWithQueriesResponse[]; export interface TaskWithQueriesResponse { boundary?: Boundary | null; interval: Interval; @@ -546,11 +484,6 @@ export interface TaskWithQueriesResponse { task_hash: string; [k: string]: unknown; } -export type GetTaskHashResponse = string; -export type GetTaskResponse = TaskResponse | null; -export type GetTasksByOwnerResponse = TaskResponse[]; -export type GetTasksResponse = TaskResponse[]; -export type GetTasksWithQueriesResponse = TaskWithQueriesResponse[]; export interface InstantiateMsg { agent_nomination_duration?: number | null; cw_rules_addr: string; @@ -629,11 +562,5 @@ export type QueryMsg = { wallet: string; [k: string]: unknown; }; -} | { - get_state: { - from_index?: number | null; - limit?: number | null; - [k: string]: unknown; - }; }; export type ValidateIntervalResponse = boolean; \ No newline at end of file From 0b93581874546e0cd00e7df76c8076080983baf4 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 19:10:44 +0200 Subject: [PATCH 02/53] fix: types --- packages/cw-croncat-core/schema/croncat.json | 307 ++++++++++++++++++ packages/cw-croncat-core/src/msg.rs | 6 +- packages/cw-croncat-core/src/tests/msg.rs | 16 +- .../cw-croncat-core/CwCroncatCore.client.js | 9 - .../cw-croncat-core/CwCroncatCore.client.ts | 2 +- .../cw-croncat-core/CwCroncatCore.types.ts | 73 ++++- 6 files changed, 381 insertions(+), 32 deletions(-) diff --git a/packages/cw-croncat-core/schema/croncat.json b/packages/cw-croncat-core/schema/croncat.json index 53bb50a3..94a331c6 100644 --- a/packages/cw-croncat-core/schema/croncat.json +++ b/packages/cw-croncat-core/schema/croncat.json @@ -13,6 +13,53 @@ } ] }, + "BalanceResponse": { + "anyOf": [ + { + "$ref": "#/definitions/GetBalancesResponse" + }, + { + "type": "null" + } + ] + }, + "ConfigResponse": { + "anyOf": [ + { + "$ref": "#/definitions/GetConfigResponse" + }, + { + "type": "null" + } + ] + }, + "GetAgentIdsResponse": { + "anyOf": [ + { + "$ref": "#/definitions/GetAgentIdsResponse" + }, + { + "type": "null" + } + ] + }, + "GetAgentResponse": { + "anyOf": [ + { + "anyOf": [ + { + "$ref": "#/definitions/AgentResponse" + }, + { + "type": "null" + } + ] + }, + { + "type": "null" + } + ] + }, "GetAgentTasksResponse": { "anyOf": [ { @@ -84,6 +131,16 @@ "$ref": "#/definitions/TaskResponse" } }, + "GetWalletBalancesResponse": { + "anyOf": [ + { + "$ref": "#/definitions/GetWalletBalancesResponse" + }, + { + "type": "null" + } + ] + }, "Task": { "anyOf": [ { @@ -182,6 +239,49 @@ } } }, + "AgentResponse": { + "type": "object", + "required": [ + "balance", + "last_executed_slot", + "payable_account_id", + "register_start", + "status", + "total_tasks_executed" + ], + "properties": { + "balance": { + "$ref": "#/definitions/GenericBalance" + }, + "last_executed_slot": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "payable_account_id": { + "$ref": "#/definitions/Addr" + }, + "register_start": { + "$ref": "#/definitions/Timestamp" + }, + "status": { + "$ref": "#/definitions/AgentStatus" + }, + "total_tasks_executed": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "AgentStatus": { + "type": "string", + "enum": [ + "Active", + "Pending", + "Nominated" + ] + }, "AgentTaskResponse": { "type": "object", "required": [ @@ -726,6 +826,25 @@ "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" }, + "GasFraction": { + "type": "object", + "required": [ + "denominator", + "numerator" + ], + "properties": { + "denominator": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "numerator": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, "GenericBalance": { "type": "object", "required": [ @@ -774,6 +893,173 @@ } } }, + "GetAgentIdsResponse": { + "type": "object", + "required": [ + "active", + "pending" + ], + "properties": { + "active": { + "type": "array", + "items": { + "$ref": "#/definitions/Addr" + } + }, + "pending": { + "type": "array", + "items": { + "$ref": "#/definitions/Addr" + } + } + } + }, + "GetBalancesResponse": { + "type": "object", + "required": [ + "available_balance", + "cw20_whitelist", + "native_denom", + "staked_balance" + ], + "properties": { + "available_balance": { + "$ref": "#/definitions/GenericBalance" + }, + "cw20_whitelist": { + "type": "array", + "items": { + "$ref": "#/definitions/Addr" + } + }, + "native_denom": { + "type": "string" + }, + "staked_balance": { + "$ref": "#/definitions/GenericBalance" + } + } + }, + "GetConfigResponse": { + "type": "object", + "required": [ + "agent_active_indices", + "agent_fee", + "agent_nomination_duration", + "agents_eject_threshold", + "available_balance", + "cw20_whitelist", + "cw_rules_addr", + "gas_action_fee", + "gas_base_fee", + "gas_fraction", + "limit", + "min_tasks_per_agent", + "native_denom", + "owner_id", + "paused", + "proxy_callback_gas", + "slot_granularity_time", + "staked_balance" + ], + "properties": { + "agent_active_indices": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "$ref": "#/definitions/SlotType" + }, + { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + ], + "maxItems": 3, + "minItems": 3 + } + }, + "agent_fee": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "agent_nomination_duration": { + "type": "integer", + "format": "uint16", + "minimum": 0.0 + }, + "agents_eject_threshold": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "available_balance": { + "$ref": "#/definitions/GenericBalance" + }, + "cw20_whitelist": { + "type": "array", + "items": { + "$ref": "#/definitions/Addr" + } + }, + "cw_rules_addr": { + "$ref": "#/definitions/Addr" + }, + "gas_action_fee": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "gas_base_fee": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "gas_fraction": { + "$ref": "#/definitions/GasFraction" + }, + "limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "min_tasks_per_agent": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "native_denom": { + "type": "string" + }, + "owner_id": { + "$ref": "#/definitions/Addr" + }, + "paused": { + "type": "boolean" + }, + "proxy_callback_gas": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "slot_granularity_time": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "staked_balance": { + "$ref": "#/definitions/GenericBalance" + } + } + }, "GetSlotHashesResponse": { "type": "object", "required": [ @@ -832,6 +1118,20 @@ } } }, + "GetWalletBalancesResponse": { + "type": "object", + "required": [ + "cw20_balances" + ], + "properties": { + "cw20_balances": { + "type": "array", + "items": { + "$ref": "#/definitions/Cw20CoinVerified" + } + } + } + }, "GovMsg": { "oneOf": [ { @@ -1090,6 +1390,13 @@ "$ref": "#/definitions/ValueIndex" } }, + "SlotType": { + "type": "string", + "enum": [ + "Block", + "Cron" + ] + }, "SmartQueries": { "type": "array", "items": { diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index a48422a1..78380b3c 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -39,17 +39,21 @@ use serde::{Deserialize, Serialize}; pub struct Croncat { pub(crate) agent: Option, pub(crate) task: Option, - + pub(crate) config_response: Option, + pub(crate) balance_response: Option, + pub(crate) get_agent_ids_response: Option, pub(crate) get_agent_tasks_response: Option, pub(crate) task_request: Option, pub(crate) task_response: Option, pub(crate) validate_interval_response: Option, + pub(crate) get_agent_response: Option>, pub(crate) get_tasks_response: Option>, pub(crate) get_tasks_by_owner_response: Option>, pub(crate) get_task_response: Option>, pub(crate) get_task_hash_response: Option, pub(crate) get_slot_hashes_response: Option, pub(crate) get_slot_ids_response: Option, + pub(crate) get_wallet_balances_response: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] diff --git a/packages/cw-croncat-core/src/tests/msg.rs b/packages/cw-croncat-core/src/tests/msg.rs index aeb72465..21cdacd1 100644 --- a/packages/cw-croncat-core/src/tests/msg.rs +++ b/packages/cw-croncat-core/src/tests/msg.rs @@ -58,7 +58,7 @@ fn everything_can_be_de_serialized() { } .into(); - let config_response: GetConfigResponse = GetConfigResponse { + let config_response = GetConfigResponse { paused: true, owner_id: Addr::unchecked("bob"), min_tasks_per_agent: 5, @@ -82,14 +82,14 @@ fn everything_can_be_de_serialized() { limit: 100, } .into(); - let balance_response: GetBalancesResponse = GetBalancesResponse { + let balance_response = GetBalancesResponse { native_denom: "some".to_string(), available_balance: generic_balance.clone(), staked_balance: generic_balance.clone(), cw20_whitelist: vec![Addr::unchecked("bob")], } .into(); - let get_agent_ids_response: GetAgentIdsResponse = GetAgentIdsResponse { + let get_agent_ids_response = GetAgentIdsResponse { active: vec![Addr::unchecked("bob")], pending: vec![Addr::unchecked("bob")], } @@ -132,7 +132,7 @@ fn everything_can_be_de_serialized() { }; let task_response = task_response_raw.clone().into(); let validate_interval_response = false.into(); - let get_agent_response: Option = Some(AgentResponse { + let get_agent_response = Some(AgentResponse { status: AgentStatus::Active, payable_account_id: Addr::unchecked("bob"), balance: generic_balance.clone(), @@ -157,7 +157,7 @@ fn everything_can_be_de_serialized() { block_ids: vec![3], } .into(); - let get_wallet_balances_response: GetWalletBalancesResponse = GetWalletBalancesResponse { + let get_wallet_balances_response = GetWalletBalancesResponse { cw20_balances: vec![Cw20CoinVerified { address: Addr::unchecked("Bob"), amount: 5u128.into(), @@ -167,17 +167,21 @@ fn everything_can_be_de_serialized() { let croncat = Croncat { agent, task, - + config_response, + balance_response, + get_agent_ids_response, get_agent_tasks_response, task_request, task_response, validate_interval_response, + get_agent_response, get_tasks_response, get_tasks_by_owner_response, get_task_response, get_task_hash_response, get_slot_hashes_response, get_slot_ids_response, + get_wallet_balances_response, }; let ser = serde_json_wasm::to_string(&croncat); diff --git a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js index e7ff693c..39496b89 100644 --- a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js +++ b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js @@ -109,14 +109,6 @@ class CwCroncatCoreQueryClient { } }); }); - this.getState = ({ fromIndex, limit }) => __awaiter(this, void 0, void 0, function* () { - return this.client.queryContractSmart(this.contractAddress, { - get_state: { - from_index: fromIndex, - limit - } - }); - }); this.client = client; this.contractAddress = contractAddress; this.getConfig = this.getConfig.bind(this); @@ -133,7 +125,6 @@ class CwCroncatCoreQueryClient { this.getSlotHashes = this.getSlotHashes.bind(this); this.getSlotIds = this.getSlotIds.bind(this); this.getWalletBalances = this.getWalletBalances.bind(this); - this.getState = this.getState.bind(this); } } exports.CwCroncatCoreQueryClient = CwCroncatCoreQueryClient; diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index 6ea85c6c..0435326d 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -6,7 +6,7 @@ import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; import { StdFee } from "@cosmjs/amino"; -import { Addr, Uint128, Timestamp, Uint64, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, GasFraction, Cw20ReceiveMsg, GetAgentResponse, AgentStatus, AgentResponse, GetAgentTasksResponse, RoundRobinBalancerModeResponse, GetStateResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; +import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasFraction, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, RoundRobinBalancerModeResponse, GetStateResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; export interface CwCroncatCoreReadOnlyInterface { contractAddress: string; getConfig: () => Promise; diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index f4964a76..3e6748ab 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -8,6 +8,8 @@ export type Addr = string; export type Uint128 = string; export type Timestamp = Uint64; export type Uint64 = string; +export type SlotType = "Block" | "Cron"; +export type AgentStatus = "Active" | "Pending" | "Nominated"; export type CosmosMsgForEmpty = { bank: BankMsg; } | { @@ -189,6 +191,10 @@ export type PathToValue = ValueIndex[]; export type SmartQueries = SmartQuery[]; export interface Croncat { Agent?: Agent | null; + BalanceResponse?: GetBalancesResponse | null; + ConfigResponse?: GetConfigResponse | null; + GetAgentIdsResponse?: GetAgentIdsResponse | null; + GetAgentResponse?: (AgentResponse | null) | null; GetAgentTasksResponse?: AgentTaskResponse | null; GetSlotHashesResponse?: GetSlotHashesResponse | null; GetSlotIdsResponse?: GetSlotIdsResponse | null; @@ -196,6 +202,7 @@ export interface Croncat { GetTaskResponse?: (TaskResponse | null) | null; GetTasksByOwnerResponse?: TaskResponse[] | null; GetTasksResponse?: TaskResponse[] | null; + GetWalletBalancesResponse?: GetWalletBalancesResponse | null; Task?: Task | null; TaskRequest?: TaskRequest | null; TaskResponse?: TaskResponse | null; @@ -225,6 +232,53 @@ export interface Coin { denom: string; [k: string]: unknown; } +export interface GetBalancesResponse { + available_balance: GenericBalance; + cw20_whitelist: Addr[]; + native_denom: string; + staked_balance: GenericBalance; + [k: string]: unknown; +} +export interface GetConfigResponse { + agent_active_indices: [SlotType, number, number][]; + agent_fee: number; + agent_nomination_duration: number; + agents_eject_threshold: number; + available_balance: GenericBalance; + cw20_whitelist: Addr[]; + cw_rules_addr: Addr; + gas_action_fee: number; + gas_base_fee: number; + gas_fraction: GasFraction; + limit: number; + min_tasks_per_agent: number; + native_denom: string; + owner_id: Addr; + paused: boolean; + proxy_callback_gas: number; + slot_granularity_time: number; + staked_balance: GenericBalance; + [k: string]: unknown; +} +export interface GasFraction { + denominator: number; + numerator: number; + [k: string]: unknown; +} +export interface GetAgentIdsResponse { + active: Addr[]; + pending: Addr[]; + [k: string]: unknown; +} +export interface AgentResponse { + balance: GenericBalance; + last_executed_slot: number; + payable_account_id: Addr; + register_start: Timestamp; + status: AgentStatus; + total_tasks_executed: number; + [k: string]: unknown; +} export interface AgentTaskResponse { num_block_tasks: Uint64; num_block_tasks_extra: Uint64; @@ -317,6 +371,10 @@ export interface SmartQuery { path_to_query_value: PathToValue; [k: string]: unknown; } +export interface GetWalletBalancesResponse { + cw20_balances: Cw20CoinVerified[]; + [k: string]: unknown; +} export interface Task { actions: ActionForEmpty[]; amount_for_one_task: GenericBalance; @@ -438,11 +496,6 @@ export type ExecuteMsg = { [k: string]: unknown; }; }; -export interface GasFraction { - denominator: number; - numerator: number; - [k: string]: unknown; -} export interface Cw20ReceiveMsg { amount: Uint128; msg: Binary; @@ -450,16 +503,6 @@ export interface Cw20ReceiveMsg { [k: string]: unknown; } export type GetAgentResponse = AgentResponse | null; -export type AgentStatus = "Active" | "Pending" | "Nominated"; -export interface AgentResponse { - balance: GenericBalance; - last_executed_slot: number; - payable_account_id: Addr; - register_start: Timestamp; - status: AgentStatus; - total_tasks_executed: number; - [k: string]: unknown; -} export type GetAgentTasksResponse = TaskResponse | null; export type RoundRobinBalancerModeResponse = "ActivationOrder" | "Equalizer"; export interface GetStateResponse { From 68c956ce0f11eae6981aea651c6727aa215a2a01 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:17:03 +0200 Subject: [PATCH 03/53] test: hook test --- .pre-commit-hooks.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 00000000..0ffe38d8 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,22 @@ +- id: fmt + name: fmt + description: Format files with cargo fmt. + entry: cargo fmt + language: system + types: [rust] + args: ["--"] +- id: cargo-check + name: cargo check + description: Check the package for errors. + entry: cargo check + language: system + types: [rust] + pass_filenames: false +- id: clippy + name: clippy + description: Lint rust sources + entry: cargo clippy + language: system + args: ["--", "-D", "warnings"] + types: [rust] + pass_filenames: false From c29389662438e528f9e3de122a3bf206d76b4acb Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:17:18 +0200 Subject: [PATCH 04/53] test: hooks --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..dbb3f0a0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +- repo: https://github.com/doublify/pre-commit-rust + rev: master + hooks: + - id: fmt + - id: cargo-check \ No newline at end of file From 56f4ab36af3951614765931a16168536b3f39787 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:21:54 +0200 Subject: [PATCH 05/53] test: hook --- .pre-commit-config.yaml | 29 ++++++++++++++++++++++++----- .pre-commit-hooks.yaml | 22 ---------------------- 2 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dbb3f0a0..c1773edd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,24 @@ -- repo: https://github.com/doublify/pre-commit-rust - rev: master - hooks: - - id: fmt - - id: cargo-check \ No newline at end of file +- repo: local + hooks: + - id: fmt + name: fmt + description: Format files with cargo fmt. + entry: cargo fmt + language: system + types: [rust] + args: ["--"] + - id: cargo-check + name: cargo check + description: Check the package for errors. + entry: cargo check + language: system + types: [rust] + pass_filenames: false + - id: clippy + name: clippy + description: Lint rust sources + entry: cargo clippy + language: system + args: ["--", "-D", "warnings"] + types: [rust] + pass_filenames: false diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 0ffe38d8..00000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,22 +0,0 @@ -- id: fmt - name: fmt - description: Format files with cargo fmt. - entry: cargo fmt - language: system - types: [rust] - args: ["--"] -- id: cargo-check - name: cargo check - description: Check the package for errors. - entry: cargo check - language: system - types: [rust] - pass_filenames: false -- id: clippy - name: clippy - description: Lint rust sources - entry: cargo clippy - language: system - args: ["--", "-D", "warnings"] - types: [rust] - pass_filenames: false From 3a75de2d5e7a1f24b0fa03cf6b231a7edd09fa43 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:32:07 +0200 Subject: [PATCH 06/53] test: hook --- .pre-commit-config.yaml | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1773edd..e7f61377 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,9 @@ -- repo: local - hooks: - - id: fmt - name: fmt - description: Format files with cargo fmt. - entry: cargo fmt - language: system - types: [rust] - args: ["--"] - - id: cargo-check - name: cargo check - description: Check the package for errors. - entry: cargo check - language: system - types: [rust] - pass_filenames: false - - id: clippy - name: clippy - description: Lint rust sources - entry: cargo clippy - language: system - args: ["--", "-D", "warnings"] - types: [rust] - pass_filenames: false +repos: + - repo: local + hooks: + - id: just-all + name: just-all + entry: bash -c 'just build' + language: system + types: [python] + pass_filenames: false From 3af31d37ad278320e3dec3a5bd8f4be0e10e35a4 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:32:51 +0200 Subject: [PATCH 07/53] test: hook --- contracts/cw-croncat/src/agent.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 07a37970..71d677be 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -59,6 +59,7 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } + // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From b6866a779766f87990497dc754c3f832c6a2dfb5 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:34:18 +0200 Subject: [PATCH 08/53] test --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e7f61377..9f229707 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: hooks: - id: just-all name: just-all - entry: bash -c 'just build' + entry: bash -c 'cargo check' language: system types: [python] pass_filenames: false From fbd94ca8f9b857f6661a83e462519c41f0d1e085 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:35:46 +0200 Subject: [PATCH 09/53] test --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9f229707..d1f3328a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: hooks: - id: just-all name: just-all - entry: bash -c 'cargo check' + entry: just build language: system types: [python] pass_filenames: false From 2b54295e4a0e84cc07c7e27804af1171b6ea04e2 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:36:20 +0200 Subject: [PATCH 10/53] test: hooks --- contracts/cw-croncat/src/agent.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 71d677be..c6680601 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -58,8 +58,10 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } + fn func(){ + + } - // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From 1f4614a4ea678183be38cee4338d29f8e8b811df Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:37:36 +0200 Subject: [PATCH 11/53] test --- .pre-commit-config.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1f3328a..be29abb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,5 +5,11 @@ repos: name: just-all entry: just build language: system - types: [python] - pass_filenames: false + types: [rust] + - id: build + name: build + description: Format files with cargo fmt. + entry: cargo build + language: system + types: [rust] + args: ["--"] \ No newline at end of file From 94435139c74a9ccd9895e31e1cdc0e19940c9278 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:39:34 +0200 Subject: [PATCH 12/53] test --- .pre-commit-config.yaml | 11 ++++++----- contracts/cw-croncat/src/agent.rs | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be29abb1..48dd4eb0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,10 +6,11 @@ repos: entry: just build language: system types: [rust] - - id: build - name: build - description: Format files with cargo fmt. - entry: cargo build + pass_filenames: false + - id: cargo-check + name: cargo check + description: Check the package for errors. + entry: cargo check language: system types: [rust] - args: ["--"] \ No newline at end of file + pass_filenames: false \ No newline at end of file diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index c6680601..0ab83753 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -58,10 +58,7 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } - fn func(){ - - } - + // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From fc9929646311f419ed3cbf001b2d5ecd6e760a45 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:41:05 +0200 Subject: [PATCH 13/53] test --- .pre-commit-config.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48dd4eb0..b3a2901d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,14 +3,7 @@ repos: hooks: - id: just-all name: just-all - entry: just build - language: system - types: [rust] - pass_filenames: false - - id: cargo-check - name: cargo check - description: Check the package for errors. - entry: cargo check + entry: just all language: system types: [rust] pass_filenames: false \ No newline at end of file From 5f133e04f9ed48b04e66925192a390914d479041 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:43:19 +0200 Subject: [PATCH 14/53] test --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b3a2901d..858d71fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ repos: - id: just-all name: just-all entry: just all + verbose: true language: system types: [rust] - pass_filenames: false \ No newline at end of file + pass_filenames: false From d5df1c5265568a5d05903c921ac3fd5cedcc2ba6 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:49:41 +0200 Subject: [PATCH 15/53] test --- .pre-commit-config.yaml | 1 + contracts/cw-croncat/src/agent.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 858d71fb..b1251287 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,4 +7,5 @@ repos: verbose: true language: system types: [rust] + stages: [post-commit] pass_filenames: false diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 0ab83753..07a37970 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -58,7 +58,7 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } - + // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From 922a6dbdad62a444da2138a3f51fc2b326229119 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 21:50:01 +0200 Subject: [PATCH 16/53] test --- contracts/cw-croncat/src/agent.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 07a37970..2832ca71 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -59,6 +59,9 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } + fn _my_function(){ + + } // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From 957a3b65c4989837b7e77b5e5352158d5f682ca1 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:00:13 +0200 Subject: [PATCH 17/53] test --- .pre-commit-config.yaml | 1 - contracts/cw-croncat/src/agent.rs | 3 --- 2 files changed, 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b1251287..858d71fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,5 +7,4 @@ repos: verbose: true language: system types: [rust] - stages: [post-commit] pass_filenames: false diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 2832ca71..07a37970 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -59,9 +59,6 @@ impl<'a> CwCroncat<'a> { Ok(GetAgentIdsResponse { active, pending }) } - fn _my_function(){ - - } // TODO: Change this to solid round-table implementation. Setup this simple version for PoC /// Get how many tasks an agent can execute /// TODO: Remove this function, replaced by balancer From 3ebb4fb13c2e6351ab2cbba2ba71cd072bfbe0bc Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:14:05 +0200 Subject: [PATCH 18/53] test --- .pre-commit-config.yaml | 10 ---------- .rusty-hook.toml | 5 +++++ Cargo.toml | 3 +++ 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 .pre-commit-config.yaml create mode 100644 .rusty-hook.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 858d71fb..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -repos: - - repo: local - hooks: - - id: just-all - name: just-all - entry: just all - verbose: true - language: system - types: [rust] - pass_filenames: false diff --git a/.rusty-hook.toml b/.rusty-hook.toml new file mode 100644 index 00000000..be6c09c1 --- /dev/null +++ b/.rusty-hook.toml @@ -0,0 +1,5 @@ +[hooks] +post-commit = "just all" + +[logging] +verbose = true diff --git a/Cargo.toml b/Cargo.toml index d47c59e7..b6300c8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,6 @@ debug-assertions = false panic = 'abort' incremental = false overflow-checks = true + +[dev-dependencies] +rusty-hook = "0.11.2" \ No newline at end of file From a933419629d6bb19fce868bf2bbd0a0686be126c Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:16:02 +0200 Subject: [PATCH 19/53] test --- Cargo.lock | 53 +++++++++++++++++++++++++++++++++ Cargo.toml | 5 +--- contracts/cw-croncat/Cargo.toml | 1 + 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6db54a58..9596f743 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,6 +296,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ci_info" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24f638c70e8c5753795cc9a8c07c44da91554a09e4cf11a7326e8161b0a3c45e" +dependencies = [ + "envmnt", +] + [[package]] name = "cipher" version = "0.3.0" @@ -669,6 +678,7 @@ dependencies = [ "cwd-voting-cw20-staked", "generic-query", "hex", + "rusty-hook", "schemars", "serde", "sha2 0.10.6", @@ -1517,6 +1527,16 @@ dependencies = [ "termcolor", ] +[[package]] +name = "envmnt" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d328fc287c61314c4a61af7cfdcbd7e678e39778488c7cb13ec133ce0f4059" +dependencies = [ + "fsio", + "indexmap", +] + [[package]] name = "eyre" version = "0.6.8" @@ -1577,6 +1597,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" +[[package]] +name = "fsio" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1fd087255f739f4f1aeea69f11b72f8080e9c2e7645cd06955dad4a178a49e3" + [[package]] name = "futures" version = "0.3.25" @@ -1719,6 +1745,15 @@ dependencies = [ "serde-cw-value", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.1.16" @@ -2198,6 +2233,12 @@ dependencies = [ "socket2", ] +[[package]] +name = "nias" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab250442c86f1850815b5d268639dff018c0627022bc1940eb2d642ca1ce12f0" + [[package]] name = "nix" version = "0.22.3" @@ -2783,6 +2824,18 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rusty-hook" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96cee9be61be7e1cbadd851e58ed7449c29c620f00b23df937cb9cbc04ac21a3" +dependencies = [ + "ci_info", + "getopts", + "nias", + "toml", +] + [[package]] name = "ryu" version = "1.0.11" diff --git a/Cargo.toml b/Cargo.toml index b6300c8a..5bbc9749 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,4 @@ lto = true debug-assertions = false panic = 'abort' incremental = false -overflow-checks = true - -[dev-dependencies] -rusty-hook = "0.11.2" \ No newline at end of file +overflow-checks = true \ No newline at end of file diff --git a/contracts/cw-croncat/Cargo.toml b/contracts/cw-croncat/Cargo.toml index ee797ee1..435686be 100644 --- a/contracts/cw-croncat/Cargo.toml +++ b/contracts/cw-croncat/Cargo.toml @@ -60,3 +60,4 @@ cwd-core = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" cwd-interface = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" } cwd-proposal-single = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" } cwd-voting = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts.git" } +rusty-hook = "0.11.2" \ No newline at end of file From 66379629708c36415c15056c16681d62fe89668f Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:20:18 +0200 Subject: [PATCH 20/53] feat: hooks --- Cargo.lock | 3 +++ contracts/cw-rules/Cargo.toml | 1 + packages/cw-croncat-core/Cargo.toml | 3 ++- packages/cw-rules-core/Cargo.toml | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9596f743..27020e6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -701,6 +701,7 @@ dependencies = [ "cw20-base", "generic-query", "hex", + "rusty-hook", "schemars", "serde", "serde-cw-value", @@ -811,6 +812,7 @@ dependencies = [ "cwd-voting", "cwd-voting-cw20-staked", "generic-query", + "rusty-hook", "schemars", "serde", "serde-cw-value", @@ -828,6 +830,7 @@ dependencies = [ "cosmwasm-std", "cw20", "generic-query", + "rusty-hook", "schemars", "serde", "serde-cw-value", diff --git a/contracts/cw-rules/Cargo.toml b/contracts/cw-rules/Cargo.toml index 867db4eb..22810656 100644 --- a/contracts/cw-rules/Cargo.toml +++ b/contracts/cw-rules/Cargo.toml @@ -69,3 +69,4 @@ cw4 = "0.16.0" cw4-group = "0.16.0" base64 = "0.13.0" serde_json = { version = "1.0", default-features = false, features = ["alloc"] } +rusty-hook = "0.11.2" \ No newline at end of file diff --git a/packages/cw-croncat-core/Cargo.toml b/packages/cw-croncat-core/Cargo.toml index d9bfcb02..05cc9214 100644 --- a/packages/cw-croncat-core/Cargo.toml +++ b/packages/cw-croncat-core/Cargo.toml @@ -32,4 +32,5 @@ serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/ser [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } cw-multi-test = { version = "0.16.0", features = ["staking"] } -cw20-base = { version = "0.13.4", features = ["library"] } \ No newline at end of file +cw20-base = { version = "0.13.4", features = ["library"] } +rusty-hook = "0.11.2" \ No newline at end of file diff --git a/packages/cw-rules-core/Cargo.toml b/packages/cw-rules-core/Cargo.toml index f8ea32d2..aecf0430 100644 --- a/packages/cw-rules-core/Cargo.toml +++ b/packages/cw-rules-core/Cargo.toml @@ -20,3 +20,4 @@ cw20 = { version = "0.13.4" } [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } +rusty-hook = "0.11.2" \ No newline at end of file From 4a7dfad368defc294ef425f5bf52fa65bc928429 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:27:03 +0200 Subject: [PATCH 21/53] fix: script --- .rusty-hook.toml | 2 +- justfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index be6c09c1..17a2fb9a 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,5 +1,5 @@ [hooks] -post-commit = "just all" +pre-commit = "just all" [logging] verbose = true diff --git a/justfile b/justfile index 3acd01b8..d94fc948 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,6 @@ test_addrs := env_var_or_default('TEST_ADDR', `jq -r '.[].address' ci/test_accounts.json | tr '\n' ' '`) set export -check: +lint: cargo fmt --all && cargo clippy -- -D warnings test: #!/bin/bash @@ -54,7 +54,7 @@ download-deps: wget https://github.com/CosmWasm/cw-plus/releases/latest/download/cw20_base.wasm -O artifacts/cw20_base.wasm # TODO?: test dao-contracts -all: build test check schema gen optimize checksum +all: build test lint schema gen optimize checksum #!/usr/bin/env bash gas-benchmark: juno-local download-deps optimize From 57aecfea48951a4c3c9127d292f00e0d3695ec08 Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:29:31 +0200 Subject: [PATCH 22/53] test --- checksum | 2 -- 1 file changed, 2 deletions(-) diff --git a/checksum b/checksum index f311d653..e69de29b 100644 --- a/checksum +++ b/checksum @@ -1,2 +0,0 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm From caf91285b18468cb041555d3c92648b8c7009eff Mon Sep 17 00:00:00 2001 From: Deveus Date: Sun, 18 Dec 2022 22:32:22 +0200 Subject: [PATCH 23/53] fix: checksum --- checksum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/checksum b/checksum index e69de29b..f311d653 100644 --- a/checksum +++ b/checksum @@ -0,0 +1,2 @@ +e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm +de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm From d32387fa19446cb062ad1ab85fe6850ee04dbe16 Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:58:41 -0800 Subject: [PATCH 24/53] Update packages/cw-croncat-core/Cargo.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- packages/cw-croncat-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cw-croncat-core/Cargo.toml b/packages/cw-croncat-core/Cargo.toml index 05cc9214..e6eb85f6 100644 --- a/packages/cw-croncat-core/Cargo.toml +++ b/packages/cw-croncat-core/Cargo.toml @@ -33,4 +33,4 @@ serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/ser cosmwasm-schema = { version = "1.0.0" } cw-multi-test = { version = "0.16.0", features = ["staking"] } cw20-base = { version = "0.13.4", features = ["library"] } -rusty-hook = "0.11.2" \ No newline at end of file +rusty-hook = "0.11.2" From 8a87eb4cbb694969108ddd623b5f1e2c86ec324e Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:58:52 -0800 Subject: [PATCH 25/53] Update packages/cw-rules-core/Cargo.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- packages/cw-rules-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cw-rules-core/Cargo.toml b/packages/cw-rules-core/Cargo.toml index aecf0430..c2d3855d 100644 --- a/packages/cw-rules-core/Cargo.toml +++ b/packages/cw-rules-core/Cargo.toml @@ -20,4 +20,4 @@ cw20 = { version = "0.13.4" } [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } -rusty-hook = "0.11.2" \ No newline at end of file +rusty-hook = "0.11.2" From d5faaf0d2dcd7d0f1e31ba7a6506e472445537ed Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:59:00 -0800 Subject: [PATCH 26/53] Update contracts/cw-croncat/Cargo.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- contracts/cw-croncat/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cw-croncat/Cargo.toml b/contracts/cw-croncat/Cargo.toml index 435686be..00d58288 100644 --- a/contracts/cw-croncat/Cargo.toml +++ b/contracts/cw-croncat/Cargo.toml @@ -60,4 +60,4 @@ cwd-core = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" cwd-interface = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" } cwd-proposal-single = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts" } cwd-voting = { version = "0.2.0", git = "https://github.com/DA0-DA0/dao-contracts.git" } -rusty-hook = "0.11.2" \ No newline at end of file +rusty-hook = "0.11.2" From 7f816891e97f1a25c4d005efa042a7adeb71ba28 Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:59:07 -0800 Subject: [PATCH 27/53] Update Cargo.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5bbc9749..d47c59e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ lto = true debug-assertions = false panic = 'abort' incremental = false -overflow-checks = true \ No newline at end of file +overflow-checks = true From 075e361368ac80d44f52c52a37415502bcb4ecc4 Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:59:13 -0800 Subject: [PATCH 28/53] Update .rusty-hook.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- .rusty-hook.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index 17a2fb9a..6b5b6d2b 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,5 +1,6 @@ [hooks] -pre-commit = "just all" +pre-commit = "just lint test" +pre-push = "just all" [logging] verbose = true From 7d6fe89bafaf8ee37f44cf7ea16b3a85c9c44f97 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 19 Dec 2022 20:06:14 +0200 Subject: [PATCH 29/53] todo tests --- ci/gas-benchmark/src/helpers.rs | 8 ++-- contracts/cw-croncat/src/contract.rs | 45 +++++++++++----------- contracts/cw-croncat/src/state.rs | 2 + contracts/cw-croncat/src/tasks.rs | 2 + contracts/cw-croncat/src/tests/balance.rs | 8 ++-- contracts/cw-croncat/src/tests/contract.rs | 4 +- contracts/cw-croncat/src/tests/manager.rs | 23 ++++++----- contracts/cw-croncat/src/tests/tasks.rs | 12 +++--- packages/cw-croncat-core/src/msg.rs | 2 + packages/cw-croncat-core/src/types.rs | 19 +++++++++ 10 files changed, 74 insertions(+), 51 deletions(-) diff --git a/ci/gas-benchmark/src/helpers.rs b/ci/gas-benchmark/src/helpers.rs index f93b3804..fb66c109 100644 --- a/ci/gas-benchmark/src/helpers.rs +++ b/ci/gas-benchmark/src/helpers.rs @@ -13,7 +13,7 @@ use cosm_orc::{ }; use cosmwasm_std::Binary; use cw20::Cw20Coin; -use cw_croncat::contract::{GAS_ACTION_FEE_JUNO, GAS_BASE_FEE_JUNO, GAS_DENOMINATOR_DEFAULT_JUNO}; +use cw_croncat::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; use cw_croncat_core::{ msg::{TaskRequest, TaskResponse, TaskWithQueriesResponse}, types::Action, @@ -26,7 +26,7 @@ const fn add_agent_fee(num: u64) -> u64 { fn min_gas_for_actions(actions: &[Action]) -> u64 { actions.iter().fold(0, |acc, action| { - acc + action.gas_limit.unwrap_or(GAS_ACTION_FEE_JUNO) + acc + action.gas_limit.unwrap_or(GAS_ACTION_FEE) }) } @@ -175,8 +175,8 @@ where .map(|(_, _, prefix)| (*prefix).to_owned()) .collect(); for (task, extra_funds, prefix) in tasks { - let gas_for_task = GAS_BASE_FEE_JUNO + min_gas_for_actions(&task.actions); - let gas_to_attached_deposit = add_agent_fee(gas_for_task) / GAS_DENOMINATOR_DEFAULT_JUNO; + let gas_for_task = GAS_BASE_FEE + min_gas_for_actions(&task.actions); + let gas_to_attached_deposit = add_agent_fee(gas_for_task) / GAS_DENOMINATOR; let amount = (gas_to_attached_deposit + extra_funds) * 3; create_task(task, orc, user_key, prefix, &denom, amount)?; } diff --git a/contracts/cw-croncat/src/contract.rs b/contracts/cw-croncat/src/contract.rs index 62efb809..584a3c2e 100644 --- a/contracts/cw-croncat/src/contract.rs +++ b/contracts/cw-croncat/src/contract.rs @@ -16,12 +16,18 @@ const DEFAULT_NOMINATION_DURATION: u16 = 360; /// default for juno /// This based on non-wasm operations, wasm ops seem impossible to predict -pub const GAS_BASE_FEE_JUNO: u64 = 300_000; -/// Gas cost per single action -pub const GAS_ACTION_FEE_JUNO: u64 = 130_000; +pub const GAS_BASE_FEE: u64 = 300_000; +/// Gas needed for single action +pub const GAS_ACTION_FEE: u64 = 130_000; +/// Gas needed for single non-wasm query +pub const GAS_QUERY_FEE: u64 = 5_000; +/// Gas needed for single wasm query +pub const GAS_WASM_QUERY_FEE: u64 = 60_000; /// We can't store gas_price as floats inside cosmwasm -/// so insted of something like 0.1 we use GasFraction{1/10} -pub const GAS_DENOMINATOR_DEFAULT_JUNO: u64 = 9; +/// so insted of having 0.04 we use GasFraction{4/100} +/// and multiply numerator by `gas_adjustment` (1.5) +pub const GAS_NUMERATOR_DEFAULT: u64 = 6; +pub const GAS_DENOMINATOR: u64 = 100; // #[cfg(not(feature = "library"))] impl<'a> CwCroncat<'a> { @@ -44,18 +50,6 @@ impl<'a> CwCroncat<'a> { info.sender }; - let gas_action_fee = if let Some(action_fee) = msg.gas_action_fee { - action_fee.u64() - } else { - GAS_ACTION_FEE_JUNO - }; - - let gas_base_fee = if let Some(base_fee) = msg.gas_base_fee { - base_fee.u64() - } else { - GAS_BASE_FEE_JUNO - }; - let config = Config { paused: false, owner_id, @@ -66,13 +60,18 @@ impl<'a> CwCroncat<'a> { available_balance, staked_balance: GenericBalance::default(), agent_fee: 5, - gas_fraction: GasFraction { - numerator: 1, - denominator: GAS_DENOMINATOR_DEFAULT_JUNO, - }, + gas_fraction: msg.gas_fraction.unwrap_or(GasFraction { + numerator: GAS_NUMERATOR_DEFAULT, + denominator: GAS_DENOMINATOR, + }), proxy_callback_gas: 3, - gas_base_fee, - gas_action_fee, + gas_base_fee: msg.gas_base_fee.map(Into::into).unwrap_or(GAS_BASE_FEE), + gas_action_fee: msg.gas_action_fee.map(Into::into).unwrap_or(GAS_ACTION_FEE), + gas_query_fee: msg.gas_query_fee.map(Into::into).unwrap_or(GAS_QUERY_FEE), + gas_wasm_query_fee: msg + .gas_wasm_query_fee + .map(Into::into) + .unwrap_or(GAS_WASM_QUERY_FEE), slot_granularity_time: 10_000_000_000, // 10 seconds native_denom: msg.denom, cw20_whitelist: vec![], diff --git a/contracts/cw-croncat/src/state.rs b/contracts/cw-croncat/src/state.rs index 745b7bfa..124ede04 100644 --- a/contracts/cw-croncat/src/state.rs +++ b/contracts/cw-croncat/src/state.rs @@ -41,6 +41,8 @@ pub struct Config { pub gas_fraction: GasFraction, pub gas_base_fee: u64, pub gas_action_fee: u64, + pub gas_query_fee: u64, + pub gas_wasm_query_fee: u64, pub proxy_callback_gas: u32, pub slot_granularity_time: u64, diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 9d2769ae..5e3acadd 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -262,6 +262,8 @@ impl<'a> CwCroncat<'a> { &cfg.owner_id, cfg.gas_base_fee, cfg.gas_action_fee, + cfg.gas_query_fee, + cfg.gas_wasm_query_fee, )?; let gas_price = calculate_required_amount(gas_amount, cfg.agent_fee)?; let price = cfg.gas_fraction.calculate(gas_price, 1)?; diff --git a/contracts/cw-croncat/src/tests/balance.rs b/contracts/cw-croncat/src/tests/balance.rs index 12796102..8fb2a914 100644 --- a/contracts/cw-croncat/src/tests/balance.rs +++ b/contracts/cw-croncat/src/tests/balance.rs @@ -1,5 +1,5 @@ use crate::balancer::{Balancer, BalancerMode, RoundRobinBalancer}; -use crate::contract::{GAS_ACTION_FEE_JUNO, GAS_BASE_FEE_JUNO, GAS_DENOMINATOR_DEFAULT_JUNO}; +use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; use crate::state::{Config, TaskInfo}; use crate::tests::helpers::{default_task, AGENT0, AGENT1, AGENT2, AGENT3, AGENT4}; use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env}; @@ -23,9 +23,9 @@ fn mock_config() -> Config { agent_fee: 5, gas_fraction: GasFraction { numerator: 1, - denominator: GAS_DENOMINATOR_DEFAULT_JUNO, + denominator: GAS_DENOMINATOR, }, - gas_action_fee: GAS_ACTION_FEE_JUNO, + gas_action_fee: GAS_ACTION_FEE, proxy_callback_gas: 3, slot_granularity_time: 60_000_000_000, native_denom: NATIVE_DENOM.to_owned(), @@ -33,7 +33,7 @@ fn mock_config() -> Config { agent_nomination_duration: 9, limit: 100, cw_rules_addr: Addr::unchecked("todo"), - gas_base_fee: GAS_BASE_FEE_JUNO, + gas_base_fee: GAS_BASE_FEE, } } #[test] diff --git a/contracts/cw-croncat/src/tests/contract.rs b/contracts/cw-croncat/src/tests/contract.rs index d64c4ae8..42e01cd0 100644 --- a/contracts/cw-croncat/src/tests/contract.rs +++ b/contracts/cw-croncat/src/tests/contract.rs @@ -1,4 +1,4 @@ -use crate::contract::GAS_DENOMINATOR_DEFAULT_JUNO; +use crate::contract::GAS_DENOMINATOR; use crate::state::QueueItem; use crate::tests::helpers::mock_init; use crate::tests::helpers::AGENT0; @@ -55,7 +55,7 @@ fn configure() { assert_eq!( GasFraction { numerator: 1, - denominator: GAS_DENOMINATOR_DEFAULT_JUNO + denominator: GAS_DENOMINATOR }, value.gas_fraction ); diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 0a669587..e001371f 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,4 +1,4 @@ -use crate::contract::{GAS_ACTION_FEE_JUNO, GAS_BASE_FEE_JUNO, GAS_DENOMINATOR_DEFAULT_JUNO}; +use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, AGENT1, AGENT2, AGENT3, @@ -430,8 +430,8 @@ fn proxy_call_no_task_and_withdraw() -> StdResult<()> { cw20_coins: vec![], }, }; - let gas_for_one = GAS_BASE_FEE_JUNO + gas_limit; - let amount_for_one_task = gas_for_one / GAS_DENOMINATOR_DEFAULT_JUNO; + let gas_for_one = GAS_BASE_FEE + gas_limit; + let amount_for_one_task = gas_for_one / GAS_DENOMINATOR; let agent_fee = amount_for_one_task * 5 / 100; let amount_with_fee = gas_limit + agent_fee + 1000; // create a task @@ -1292,7 +1292,7 @@ fn test_multi_action() { cw20_coins: vec![], }, }; - let gas_limit = GAS_ACTION_FEE_JUNO; + let gas_limit = GAS_ACTION_FEE; let agent_fee = gas_limit.checked_mul(5).unwrap().checked_div(100).unwrap(); let amount_for_one_task = (gas_limit * 2) + agent_fee * 2 + 3 + 4; // + 3 + 4 atoms sent @@ -1364,11 +1364,10 @@ fn test_balance_changes() { cw20_coins: vec![], }, }; - let gas_for_one = GAS_BASE_FEE_JUNO + (GAS_ACTION_FEE_JUNO * 2); + let gas_for_one = GAS_BASE_FEE + (GAS_ACTION_FEE * 2); let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking refunds at task removal - let amount_for_one_task = - (gas_for_one + agent_fee) / GAS_DENOMINATOR_DEFAULT_JUNO + 3 + 4 + extra; // + 3 + 4 atoms sent + let amount_for_one_task = (gas_for_one + agent_fee) / GAS_DENOMINATOR + 3 + 4 + extra; // + 3 + 4 atoms sent // create a task app.execute_contract( @@ -1498,10 +1497,10 @@ fn test_no_reschedule_if_lack_balance() { }, }; - let gas_for_one = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; + let gas_for_one = GAS_BASE_FEE + GAS_ACTION_FEE; let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking nonzero task balance - let amount_for_one_task = (gas_for_one + agent_fee) / GAS_DENOMINATOR_DEFAULT_JUNO + 3; // + 3 atoms sent + let amount_for_one_task = (gas_for_one + agent_fee) / GAS_DENOMINATOR + 3; // + 3 atoms sent // create a task app.execute_contract( @@ -1549,7 +1548,7 @@ fn test_no_reschedule_if_lack_balance() { .unwrap(); assert_eq!( task.unwrap().total_deposit[0].amount, - Uint128::from((gas_for_one + agent_fee) / GAS_DENOMINATOR_DEFAULT_JUNO + extra) + Uint128::from((gas_for_one + agent_fee) / GAS_DENOMINATOR + extra) ); app.update_block(add_little_time); @@ -2238,8 +2237,8 @@ fn testing_fee_works() { cw20_coins: vec![], }, }; - let total_gas = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; - let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR_DEFAULT_JUNO; + let total_gas = GAS_BASE_FEE + GAS_ACTION_FEE; + let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR; let extra = 100; let amount_for_three = (attach_per_action * 3) as u128 + extra; diff --git a/contracts/cw-croncat/src/tests/tasks.rs b/contracts/cw-croncat/src/tests/tasks.rs index 7983bca1..bcfee491 100644 --- a/contracts/cw-croncat/src/tests/tasks.rs +++ b/contracts/cw-croncat/src/tests/tasks.rs @@ -1,5 +1,5 @@ use super::helpers::{ADMIN, ANYONE, NATIVE_DENOM, VERY_RICH}; -use crate::contract::{GAS_ACTION_FEE_JUNO, GAS_BASE_FEE_JUNO, GAS_DENOMINATOR_DEFAULT_JUNO}; +use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; use crate::tests::helpers::proper_instantiate; use crate::ContractError; use cosmwasm_std::{ @@ -1034,7 +1034,7 @@ fn check_gas_minimum() { let stake = StakingMsg::Delegate { validator, amount }; let msg: CosmosMsg = stake.clone().into(); let gas_limit = 150_000; - let base_gas = GAS_BASE_FEE_JUNO; + let base_gas = GAS_BASE_FEE; let create_task_msg = ExecuteMsg::CreateTask { task: TaskRequest { @@ -1053,7 +1053,7 @@ fn check_gas_minimum() { // create 1 token off task let gas_for_two = (base_gas + gas_limit) * 2; let enough_for_two = - u128::from((gas_for_two + gas_for_two * 5 / 100) / GAS_DENOMINATOR_DEFAULT_JUNO + 3 * 2); + u128::from((gas_for_two + gas_for_two * 5 / 100) / GAS_DENOMINATOR + 3 * 2); let res: ContractError = app .execute_contract( Addr::unchecked(ANYONE), @@ -1091,8 +1091,8 @@ fn check_gas_default() { let amount = coin(3, NATIVE_DENOM); let stake = StakingMsg::Delegate { validator, amount }; let msg: CosmosMsg = stake.clone().into(); - let gas_limit = GAS_ACTION_FEE_JUNO; - let base_gas = GAS_BASE_FEE_JUNO; + let gas_limit = GAS_ACTION_FEE; + let base_gas = GAS_BASE_FEE; // let send = BankMsg::Send { // to_address: validator, // amount: vec![amount], @@ -1117,7 +1117,7 @@ fn check_gas_default() { let gas_for_one = base_gas + gas_limit; let gas_for_one_with_fee = gas_for_one + gas_for_one * 5 / 100; - let enough_for_two = 2 * u128::from(gas_for_one_with_fee / GAS_DENOMINATOR_DEFAULT_JUNO + 3); + let enough_for_two = 2 * u128::from(gas_for_one_with_fee / GAS_DENOMINATOR + 3); let res: ContractError = app .execute_contract( diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index 8e48b06d..ad3caec7 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -64,6 +64,8 @@ pub struct InstantiateMsg { pub owner_id: Option, pub gas_base_fee: Option, pub gas_action_fee: Option, + pub gas_query_fee: Option, + pub gas_wasm_query_fee: Option, pub gas_fraction: Option, pub agent_nomination_duration: Option, } diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 25028c0d..647a3d61 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -235,6 +235,8 @@ impl TaskRequest { owner_id: &Addr, base_gas: u64, action_gas: u64, + query_gas: u64, + wasm_query_gas: u64, ) -> Result<(GenericBalance, u64), CoreError> { let mut gas_amount: u64 = base_gas; let mut amount_for_one_task = GenericBalance::default(); @@ -324,6 +326,23 @@ impl TaskRequest { _ => (), } } + + if let Some(queries) = self.queries.as_ref() { + for query in queries.iter() { + match query { + CroncatQuery::HasBalanceGte(_) => { + gas_amount + .checked_add(query_gas) + .ok_or(CoreError::InvalidWasmMsg {})?; + } + _ => { + gas_amount + .checked_add(wasm_query_gas) + .ok_or(CoreError::InvalidWasmMsg {})?; + } + } + } + } Ok((amount_for_one_task, gas_amount)) } } From d01b3f1cf15ff9c07f45a347e4ee9783d7711087 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 19 Dec 2022 20:11:26 +0200 Subject: [PATCH 30/53] little clenup --- contracts/cw-croncat/src/tests/owner.rs | 13 +++---------- packages/cw-croncat-core/examples/schema.rs | 7 +------ packages/cw-croncat-core/src/msg.rs | 18 ------------------ 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/contracts/cw-croncat/src/tests/owner.rs b/contracts/cw-croncat/src/tests/owner.rs index a8faad33..afc50e0d 100644 --- a/contracts/cw-croncat/src/tests/owner.rs +++ b/contracts/cw-croncat/src/tests/owner.rs @@ -1,19 +1,12 @@ use crate::error::ContractError; use crate::state::CwCroncat; -use crate::tests::helpers::{ - add_little_time, proper_instantiate, ADMIN, AGENT0, AGENT_BENEFICIARY, ANYONE, NATIVE_DENOM, -}; +use crate::tests::helpers::NATIVE_DENOM; use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env, mock_info}; -use cosmwasm_std::{ - coin, coins, from_binary, to_binary, Addr, CosmosMsg, MessageInfo, StdResult, Uint64, WasmMsg, -}; +use cosmwasm_std::{coin, coins, from_binary, Addr, MessageInfo}; use cw20::Balance; use cw_croncat_core::msg::{ - CwCroncatResponse, ExecuteMsg, GetBalancesResponse, GetConfigResponse, InstantiateMsg, - QueryMsg, RoundRobinBalancerModeResponse, TaskRequest, + ExecuteMsg, GetBalancesResponse, GetConfigResponse, InstantiateMsg, QueryMsg, }; -use cw_croncat_core::types::{Action, Boundary, Interval}; -use cw_multi_test::Executor; #[test] fn update_settings() { diff --git a/packages/cw-croncat-core/examples/schema.rs b/packages/cw-croncat-core/examples/schema.rs index d2671d43..fdddc0ef 100644 --- a/packages/cw-croncat-core/examples/schema.rs +++ b/packages/cw-croncat-core/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for}; use cw_croncat_core::msg::{ - AgentResponse, Croncat, CwCroncatResponse, ExecuteMsg, InstantiateMsg, QueryMsg, TaskResponse, + AgentResponse, Croncat, ExecuteMsg, InstantiateMsg, QueryMsg, TaskResponse, TaskWithQueriesResponse, }; @@ -51,9 +51,4 @@ fn main() { &out_dir, "GetAgentTasksResponse", ); - export_schema_with_title( - &schema_for!(CwCroncatResponse), - &out_dir, - "GetStateResponse", - ); } diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index 78380b3c..cd1a0320 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -353,18 +353,6 @@ pub struct TaskWithQueriesResponse { pub queries: Option>, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct CwCroncatResponse { - pub agent_active_queue: Vec, - pub agent_pending_queue: Vec, - pub tasks: Vec, - pub task_total: Uint64, - pub reply_index: Uint64, - - pub agent_nomination_begin_time: Option, - - pub balancer_mode: RoundRobinBalancerModeResponse, -} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct GetBalancesResponse { pub native_denom: String, @@ -394,12 +382,6 @@ pub struct AgentResponse { pub register_start: Timestamp, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub enum RoundRobinBalancerModeResponse { - ActivationOrder, - Equalizer, -} - impl From for TaskResponse { fn from(task: Task) -> Self { let boundary = match (task.boundary, &task.interval) { From 3433407d5749a0fe27e6b810e769db8d66e17b70 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 19 Dec 2022 20:19:12 +0200 Subject: [PATCH 31/53] codegen --- .../schema/get_state_response.json | 1387 ----------------- .../cw-croncat-core/CwCroncatCore.client.ts | 2 +- .../cw-croncat-core/CwCroncatCore.types.ts | 11 - 3 files changed, 1 insertion(+), 1399 deletions(-) delete mode 100644 packages/cw-croncat-core/schema/get_state_response.json diff --git a/packages/cw-croncat-core/schema/get_state_response.json b/packages/cw-croncat-core/schema/get_state_response.json deleted file mode 100644 index 6bac1a01..00000000 --- a/packages/cw-croncat-core/schema/get_state_response.json +++ /dev/null @@ -1,1387 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "GetStateResponse", - "type": "object", - "required": [ - "agent_active_queue", - "agent_pending_queue", - "balancer_mode", - "reply_index", - "task_total", - "tasks" - ], - "properties": { - "agent_active_queue": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "agent_nomination_begin_time": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - }, - "agent_pending_queue": { - "type": "array", - "items": { - "$ref": "#/definitions/Addr" - } - }, - "balancer_mode": { - "$ref": "#/definitions/RoundRobinBalancerModeResponse" - }, - "reply_index": { - "$ref": "#/definitions/Uint64" - }, - "task_total": { - "$ref": "#/definitions/Uint64" - }, - "tasks": { - "type": "array", - "items": { - "$ref": "#/definitions/TaskResponse" - } - } - }, - "definitions": { - "Action_for_Empty": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "gas_limit": { - "description": "The gas needed to safely process the execute msg", - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - }, - "msg": { - "description": "Supported CosmosMsgs only!", - "allOf": [ - { - "$ref": "#/definitions/CosmosMsg_for_Empty" - } - ] - } - } - }, - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - }, - "Balance": { - "oneOf": [ - { - "type": "object", - "required": [ - "native" - ], - "properties": { - "native": { - "$ref": "#/definitions/NativeBalance" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "cw20" - ], - "properties": { - "cw20": { - "$ref": "#/definitions/Cw20CoinVerified" - } - }, - "additionalProperties": false - } - ] - }, - "BankMsg": { - "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", - "oneOf": [ - { - "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "send" - ], - "properties": { - "send": { - "type": "object", - "required": [ - "amount", - "to_address" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "to_address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", - "type": "object", - "required": [ - "burn" - ], - "properties": { - "burn": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "Boundary": { - "oneOf": [ - { - "type": "object", - "required": [ - "Height" - ], - "properties": { - "Height": { - "type": "object", - "properties": { - "end": { - "anyOf": [ - { - "$ref": "#/definitions/Uint64" - }, - { - "type": "null" - } - ] - }, - "start": { - "anyOf": [ - { - "$ref": "#/definitions/Uint64" - }, - { - "type": "null" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "Time" - ], - "properties": { - "Time": { - "type": "object", - "properties": { - "end": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - }, - "start": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - } - } - } - }, - "additionalProperties": false - } - ] - }, - "CheckOwnerOfNft": { - "type": "object", - "required": [ - "address", - "nft_address", - "token_id" - ], - "properties": { - "address": { - "type": "string" - }, - "nft_address": { - "type": "string" - }, - "token_id": { - "type": "string" - } - } - }, - "CheckProposalStatus": { - "type": "object", - "required": [ - "dao_address", - "proposal_id", - "status" - ], - "properties": { - "dao_address": { - "type": "string" - }, - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "status": { - "$ref": "#/definitions/Status" - } - } - }, - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "CosmosMsg_for_Empty": { - "oneOf": [ - { - "type": "object", - "required": [ - "bank" - ], - "properties": { - "bank": { - "$ref": "#/definitions/BankMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "custom" - ], - "properties": { - "custom": { - "$ref": "#/definitions/Empty" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "staking" - ], - "properties": { - "staking": { - "$ref": "#/definitions/StakingMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "distribution" - ], - "properties": { - "distribution": { - "$ref": "#/definitions/DistributionMsg" - } - }, - "additionalProperties": false - }, - { - "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", - "type": "object", - "required": [ - "stargate" - ], - "properties": { - "stargate": { - "type": "object", - "required": [ - "type_url", - "value" - ], - "properties": { - "type_url": { - "type": "string" - }, - "value": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "ibc" - ], - "properties": { - "ibc": { - "$ref": "#/definitions/IbcMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "wasm" - ], - "properties": { - "wasm": { - "$ref": "#/definitions/WasmMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "gov" - ], - "properties": { - "gov": { - "$ref": "#/definitions/GovMsg" - } - }, - "additionalProperties": false - } - ] - }, - "CroncatQuery": { - "oneOf": [ - { - "type": "object", - "required": [ - "query" - ], - "properties": { - "query": { - "type": "object", - "required": [ - "contract_addr", - "msg" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "has_balance_gte" - ], - "properties": { - "has_balance_gte": { - "$ref": "#/definitions/HasBalanceGte" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "check_owner_of_nft" - ], - "properties": { - "check_owner_of_nft": { - "$ref": "#/definitions/CheckOwnerOfNft" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "check_proposal_status" - ], - "properties": { - "check_proposal_status": { - "$ref": "#/definitions/CheckProposalStatus" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "generic_query" - ], - "properties": { - "generic_query": { - "$ref": "#/definitions/GenericQuery" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "smart_query" - ], - "properties": { - "smart_query": { - "$ref": "#/definitions/SmartQueryHead" - } - }, - "additionalProperties": false - } - ] - }, - "Cw20CoinVerified": { - "type": "object", - "required": [ - "address", - "amount" - ], - "properties": { - "address": { - "$ref": "#/definitions/Addr" - }, - "amount": { - "$ref": "#/definitions/Uint128" - } - } - }, - "DistributionMsg": { - "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "set_withdraw_address" - ], - "properties": { - "set_withdraw_address": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "description": "The `withdraw_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "withdraw_delegator_reward" - ], - "properties": { - "withdraw_delegator_reward": { - "type": "object", - "required": [ - "validator" - ], - "properties": { - "validator": { - "description": "The `validator_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Empty": { - "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", - "type": "object" - }, - "GenericQuery": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "ordering", - "path_to_value", - "value" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "ordering": { - "$ref": "#/definitions/ValueOrdering" - }, - "path_to_value": { - "$ref": "#/definitions/PathToValue" - }, - "value": { - "$ref": "#/definitions/Binary" - } - } - }, - "GovMsg": { - "oneOf": [ - { - "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", - "type": "object", - "required": [ - "vote" - ], - "properties": { - "vote": { - "type": "object", - "required": [ - "proposal_id", - "vote" - ], - "properties": { - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "vote": { - "$ref": "#/definitions/VoteOption" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "HasBalanceGte": { - "type": "object", - "required": [ - "address", - "required_balance" - ], - "properties": { - "address": { - "type": "string" - }, - "required_balance": { - "$ref": "#/definitions/Balance" - } - } - }, - "IbcMsg": { - "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", - "oneOf": [ - { - "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", - "type": "object", - "required": [ - "transfer" - ], - "properties": { - "transfer": { - "type": "object", - "required": [ - "amount", - "channel_id", - "timeout", - "to_address" - ], - "properties": { - "amount": { - "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", - "allOf": [ - { - "$ref": "#/definitions/Coin" - } - ] - }, - "channel_id": { - "description": "exisiting channel to send the tokens over", - "type": "string" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - }, - "to_address": { - "description": "address on the remote chain to receive these tokens", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", - "type": "object", - "required": [ - "send_packet" - ], - "properties": { - "send_packet": { - "type": "object", - "required": [ - "channel_id", - "data", - "timeout" - ], - "properties": { - "channel_id": { - "type": "string" - }, - "data": { - "$ref": "#/definitions/Binary" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", - "type": "object", - "required": [ - "close_channel" - ], - "properties": { - "close_channel": { - "type": "object", - "required": [ - "channel_id" - ], - "properties": { - "channel_id": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "IbcTimeout": { - "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", - "type": "object", - "properties": { - "block": { - "anyOf": [ - { - "$ref": "#/definitions/IbcTimeoutBlock" - }, - { - "type": "null" - } - ] - }, - "timestamp": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - } - } - }, - "IbcTimeoutBlock": { - "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", - "type": "object", - "required": [ - "height", - "revision" - ], - "properties": { - "height": { - "description": "block height after which the packet times out. the height within the given revision", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "revision": { - "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "Interval": { - "description": "Defines the spacing of execution NOTES: - Block Height Based: Once, Immediate, Block - Timestamp Based: Cron - No Epoch support directly, advised to use block heights instead", - "oneOf": [ - { - "description": "For when this is a non-recurring future scheduled TXN", - "type": "string", - "enum": [ - "Once" - ] - }, - { - "description": "The ugly batch schedule type, in case you need to exceed single TXN gas limits, within fewest block(s)", - "type": "string", - "enum": [ - "Immediate" - ] - }, - { - "description": "Allows timing based on block intervals rather than timestamps", - "type": "object", - "required": [ - "Block" - ], - "properties": { - "Block": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "Crontab Spec String", - "type": "object", - "required": [ - "Cron" - ], - "properties": { - "Cron": { - "type": "string" - } - }, - "additionalProperties": false - } - ] - }, - "NativeBalance": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "PathToValue": { - "type": "array", - "items": { - "$ref": "#/definitions/ValueIndex" - } - }, - "RoundRobinBalancerModeResponse": { - "type": "string", - "enum": [ - "ActivationOrder", - "Equalizer" - ] - }, - "SmartQueries": { - "type": "array", - "items": { - "$ref": "#/definitions/SmartQuery" - } - }, - "SmartQuery": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "path_to_msg_value", - "path_to_query_value" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "path_to_msg_value": { - "description": "Replace value inside this query", - "allOf": [ - { - "$ref": "#/definitions/PathToValue" - } - ] - }, - "path_to_query_value": { - "description": "Value passed to the next iteration", - "allOf": [ - { - "$ref": "#/definitions/PathToValue" - } - ] - } - } - }, - "SmartQueryHead": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "ordering", - "path_to_query_value", - "queries", - "value" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "description": "First query without placeholder!", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "ordering": { - "$ref": "#/definitions/ValueOrdering" - }, - "path_to_query_value": { - "description": "Value from this message", - "allOf": [ - { - "$ref": "#/definitions/PathToValue" - } - ] - }, - "queries": { - "$ref": "#/definitions/SmartQueries" - }, - "value": { - "$ref": "#/definitions/Binary" - } - } - }, - "StakingMsg": { - "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "delegate" - ], - "properties": { - "delegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "undelegate" - ], - "properties": { - "undelegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "redelegate" - ], - "properties": { - "redelegate": { - "type": "object", - "required": [ - "amount", - "dst_validator", - "src_validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "dst_validator": { - "type": "string" - }, - "src_validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Status": { - "oneOf": [ - { - "type": "string", - "enum": [ - "execution_failed" - ] - }, - { - "description": "The proposal is open for voting.", - "type": "string", - "enum": [ - "open" - ] - }, - { - "description": "The proposal has been rejected.", - "type": "string", - "enum": [ - "rejected" - ] - }, - { - "description": "The proposal has been passed but has not been executed.", - "type": "string", - "enum": [ - "passed" - ] - }, - { - "description": "The proposal has been passed and executed.", - "type": "string", - "enum": [ - "executed" - ] - }, - { - "description": "The proposal has failed or expired and has been closed. A proposal deposit refund has been issued if applicable.", - "type": "string", - "enum": [ - "closed" - ] - } - ] - }, - "TaskResponse": { - "type": "object", - "required": [ - "actions", - "amount_for_one_task_cw20", - "amount_for_one_task_native", - "interval", - "owner_id", - "stop_on_fail", - "task_hash", - "total_cw20_deposit", - "total_deposit" - ], - "properties": { - "actions": { - "type": "array", - "items": { - "$ref": "#/definitions/Action_for_Empty" - } - }, - "amount_for_one_task_cw20": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20CoinVerified" - } - }, - "amount_for_one_task_native": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "boundary": { - "anyOf": [ - { - "$ref": "#/definitions/Boundary" - }, - { - "type": "null" - } - ] - }, - "interval": { - "$ref": "#/definitions/Interval" - }, - "owner_id": { - "$ref": "#/definitions/Addr" - }, - "queries": { - "type": [ - "array", - "null" - ], - "items": { - "$ref": "#/definitions/CroncatQuery" - } - }, - "stop_on_fail": { - "type": "boolean" - }, - "task_hash": { - "type": "string" - }, - "total_cw20_deposit": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20CoinVerified" - } - }, - "total_deposit": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - }, - "ValueIndex": { - "oneOf": [ - { - "type": "object", - "required": [ - "key" - ], - "properties": { - "key": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "index" - ], - "properties": { - "index": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "ValueOrdering": { - "type": "string", - "enum": [ - "unit_above", - "unit_above_equal", - "unit_below", - "unit_below_equal", - "equal", - "not_equal" - ] - }, - "VoteOption": { - "type": "string", - "enum": [ - "yes", - "no", - "abstain", - "no_with_veto" - ] - }, - "WasmMsg": { - "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", - "oneOf": [ - { - "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "execute" - ], - "properties": { - "execute": { - "type": "object", - "required": [ - "contract_addr", - "funds", - "msg" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "msg": { - "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "instantiate" - ], - "properties": { - "instantiate": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "migrate" - ], - "properties": { - "migrate": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "new_code_id" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "new_code_id": { - "description": "the code_id of the new logic to place in the given contract", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "update_admin" - ], - "properties": { - "update_admin": { - "type": "object", - "required": [ - "admin", - "contract_addr" - ], - "properties": { - "admin": { - "type": "string" - }, - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "clear_admin" - ], - "properties": { - "clear_admin": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - } - } -} diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index 0435326d..f0ac4b7b 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -6,7 +6,7 @@ import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; import { StdFee } from "@cosmjs/amino"; -import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasFraction, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, RoundRobinBalancerModeResponse, GetStateResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; +import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasFraction, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; export interface CwCroncatCoreReadOnlyInterface { contractAddress: string; getConfig: () => Promise; diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index 3e6748ab..4a2d28e5 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -504,17 +504,6 @@ export interface Cw20ReceiveMsg { } export type GetAgentResponse = AgentResponse | null; export type GetAgentTasksResponse = TaskResponse | null; -export type RoundRobinBalancerModeResponse = "ActivationOrder" | "Equalizer"; -export interface GetStateResponse { - agent_active_queue: Addr[]; - agent_nomination_begin_time?: Timestamp | null; - agent_pending_queue: Addr[]; - balancer_mode: RoundRobinBalancerModeResponse; - reply_index: Uint64; - task_total: Uint64; - tasks: TaskResponse[]; - [k: string]: unknown; -} export type GetTaskHashResponse = string; export type GetTaskResponse = TaskResponse | null; export type GetTasksByOwnerResponse = TaskResponse[]; From 1ceaa7a5a4e81ff27bb0beb83c3b6857041643dd Mon Sep 17 00:00:00 2001 From: Raf Rustaman <42238266+deveusss@users.noreply.github.com> Date: Mon, 19 Dec 2022 12:14:42 -0800 Subject: [PATCH 32/53] Update contracts/cw-rules/Cargo.toml Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> --- contracts/cw-rules/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cw-rules/Cargo.toml b/contracts/cw-rules/Cargo.toml index 22810656..1eba9e03 100644 --- a/contracts/cw-rules/Cargo.toml +++ b/contracts/cw-rules/Cargo.toml @@ -69,4 +69,4 @@ cw4 = "0.16.0" cw4-group = "0.16.0" base64 = "0.13.0" serde_json = { version = "1.0", default-features = false, features = ["alloc"] } -rusty-hook = "0.11.2" \ No newline at end of file +rusty-hook = "0.11.2" From db0792b614648b2eb2a015633cf71437294c6a62 Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 16:46:56 +0200 Subject: [PATCH 33/53] Update settings and tests fix --- ci/gas-benchmark/src/helpers.rs | 2 + ci/gas-benchmark/src/main.rs | 2 + contracts/cw-croncat/src/owner.rs | 81 +++++++++++---------- contracts/cw-croncat/src/tests/agent.rs | 8 ++ contracts/cw-croncat/src/tests/balance.rs | 9 ++- contracts/cw-croncat/src/tests/contract.rs | 5 +- contracts/cw-croncat/src/tests/helpers.rs | 4 + contracts/cw-croncat/src/tests/manager.rs | 29 +++++--- contracts/cw-croncat/src/tests/owner.rs | 12 +++ contracts/cw-croncat/src/tests/tasks.rs | 14 +++- packages/cw-croncat-core/src/msg.rs | 2 + packages/cw-croncat-core/src/tests/types.rs | 18 +++++ packages/cw-croncat-core/src/types.rs | 6 ++ 13 files changed, 139 insertions(+), 53 deletions(-) diff --git a/ci/gas-benchmark/src/helpers.rs b/ci/gas-benchmark/src/helpers.rs index fb66c109..d2c73022 100644 --- a/ci/gas-benchmark/src/helpers.rs +++ b/ci/gas-benchmark/src/helpers.rs @@ -71,6 +71,8 @@ pub(crate) fn init_contracts( cw_rules_addr: rules_res.address, owner_id: Some(admin_addr.to_owned()), gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: None, gas_base_fee: None, diff --git a/ci/gas-benchmark/src/main.rs b/ci/gas-benchmark/src/main.rs index a77ff9bb..61f9f683 100644 --- a/ci/gas-benchmark/src/main.rs +++ b/ci/gas-benchmark/src/main.rs @@ -201,6 +201,8 @@ fn main() -> Result<()> { agent_fee: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, proxy_callback_gas: None, min_tasks_per_agent: None, diff --git a/contracts/cw-croncat/src/owner.rs b/contracts/cw-croncat/src/owner.rs index fef6ff55..45308c0e 100644 --- a/contracts/cw-croncat/src/owner.rs +++ b/contracts/cw-croncat/src/owner.rs @@ -85,53 +85,60 @@ impl<'a> CwCroncat<'a> { agent_fee, gas_base_fee, gas_action_fee, + gas_query_fee, + gas_wasm_query_fee, gas_fraction, proxy_callback_gas, min_tasks_per_agent, agents_eject_threshold, // treasury_id, } => { + let owner_id = if let Some(addr) = owner_id { + Some(api.addr_validate(&addr)?) + } else { + None + }; self.config - .update(deps.storage, |mut config| -> Result<_, ContractError> { - if info.sender != config.owner_id { + .update(deps.storage, |old_config| -> Result<_, ContractError> { + if info.sender != old_config.owner_id { return Err(ContractError::Unauthorized {}); } - if let Some(owner_id) = owner_id { - let owner_id = api.addr_validate(&owner_id)?; - config.owner_id = owner_id; - } - // if let Some(treasury_id) = treasury_id { - // config.treasury_id = Some(treasury_id); - // } - if let Some(slot_granularity_time) = slot_granularity_time { - config.slot_granularity_time = slot_granularity_time; - } - if let Some(paused) = paused { - config.paused = paused; - } - if let Some(gas_base_fee) = gas_base_fee { - config.gas_base_fee = gas_base_fee.u64(); - } - if let Some(gas_action_fee) = gas_action_fee { - config.gas_action_fee = gas_action_fee.u64(); - } - if let Some(gas_fraction) = gas_fraction { - config.gas_fraction = gas_fraction; - } - if let Some(proxy_callback_gas) = proxy_callback_gas { - config.proxy_callback_gas = proxy_callback_gas; - } - if let Some(agent_fee) = agent_fee { - config.agent_fee = agent_fee; - } - if let Some(min_tasks_per_agent) = min_tasks_per_agent { - config.min_tasks_per_agent = min_tasks_per_agent; - } - if let Some(agents_eject_threshold) = agents_eject_threshold { - config.agents_eject_threshold = agents_eject_threshold; - } - Ok(config) + let new_config = Config { + paused: paused.unwrap_or(old_config.paused), + owner_id: owner_id.unwrap_or(old_config.owner_id), + min_tasks_per_agent: min_tasks_per_agent + .unwrap_or(old_config.min_tasks_per_agent), + agent_active_indices: old_config.agent_active_indices, + agents_eject_threshold: agents_eject_threshold + .unwrap_or(old_config.agents_eject_threshold), + agent_nomination_duration: old_config.agent_nomination_duration, + cw_rules_addr: old_config.cw_rules_addr, + agent_fee: agent_fee.unwrap_or(old_config.agent_fee), + gas_fraction: gas_fraction.unwrap_or(old_config.gas_fraction), + gas_base_fee: gas_base_fee + .map(Into::into) + .unwrap_or(old_config.gas_base_fee), + gas_action_fee: gas_action_fee + .map(Into::into) + .unwrap_or(old_config.gas_action_fee), + gas_query_fee: gas_query_fee + .map(Into::into) + .unwrap_or(old_config.gas_query_fee), + gas_wasm_query_fee: gas_wasm_query_fee + .map(Into::into) + .unwrap_or(old_config.gas_wasm_query_fee), + proxy_callback_gas: proxy_callback_gas + .unwrap_or(old_config.proxy_callback_gas), + slot_granularity_time: slot_granularity_time + .unwrap_or(old_config.slot_granularity_time), + cw20_whitelist: old_config.cw20_whitelist, + native_denom: old_config.native_denom, + available_balance: old_config.available_balance, + staked_balance: old_config.staked_balance, + limit: old_config.limit, + }; + Ok(new_config) })?; } _ => unreachable!(), diff --git a/contracts/cw-croncat/src/tests/agent.rs b/contracts/cw-croncat/src/tests/agent.rs index ced94dd8..e41579e8 100644 --- a/contracts/cw-croncat/src/tests/agent.rs +++ b/contracts/cw-croncat/src/tests/agent.rs @@ -256,6 +256,8 @@ fn test_instantiate_sets_balance() { cw_rules_addr: "grapestem".to_string(), owner_id: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: None, gas_base_fee: None, @@ -313,6 +315,8 @@ fn register_agent_fail_cases() { proxy_callback_gas: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, slot_granularity_time: None, }; app.execute_contract( @@ -349,6 +353,8 @@ fn register_agent_fail_cases() { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; app.execute_contract( Addr::unchecked(ADMIN), @@ -751,6 +757,8 @@ fn test_get_agent_status() { denom: NATIVE_DENOM.to_string(), owner_id: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), diff --git a/contracts/cw-croncat/src/tests/balance.rs b/contracts/cw-croncat/src/tests/balance.rs index 8fb2a914..751bf9e9 100644 --- a/contracts/cw-croncat/src/tests/balance.rs +++ b/contracts/cw-croncat/src/tests/balance.rs @@ -1,5 +1,8 @@ use crate::balancer::{Balancer, BalancerMode, RoundRobinBalancer}; -use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; +use crate::contract::{ + GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, + GAS_WASM_QUERY_FEE, +}; use crate::state::{Config, TaskInfo}; use crate::tests::helpers::{default_task, AGENT0, AGENT1, AGENT2, AGENT3, AGENT4}; use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env}; @@ -22,10 +25,12 @@ fn mock_config() -> Config { staked_balance: GenericBalance::default(), agent_fee: 5, gas_fraction: GasFraction { - numerator: 1, + numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR, }, gas_action_fee: GAS_ACTION_FEE, + gas_query_fee: GAS_QUERY_FEE, + gas_wasm_query_fee: GAS_WASM_QUERY_FEE, proxy_callback_gas: 3, slot_granularity_time: 60_000_000_000, native_denom: NATIVE_DENOM.to_owned(), diff --git a/contracts/cw-croncat/src/tests/contract.rs b/contracts/cw-croncat/src/tests/contract.rs index 42e01cd0..6784dd27 100644 --- a/contracts/cw-croncat/src/tests/contract.rs +++ b/contracts/cw-croncat/src/tests/contract.rs @@ -1,4 +1,5 @@ use crate::contract::GAS_DENOMINATOR; +use crate::contract::GAS_NUMERATOR_DEFAULT; use crate::state::QueueItem; use crate::tests::helpers::mock_init; use crate::tests::helpers::AGENT0; @@ -23,6 +24,8 @@ fn configure() { denom: NATIVE_DENOM.to_string(), owner_id: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), @@ -54,7 +57,7 @@ fn configure() { assert_eq!(5, value.agent_fee); assert_eq!( GasFraction { - numerator: 1, + numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR }, value.gas_fraction diff --git a/contracts/cw-croncat/src/tests/helpers.rs b/contracts/cw-croncat/src/tests/helpers.rs index 929f3b88..fd6db476 100644 --- a/contracts/cw-croncat/src/tests/helpers.rs +++ b/contracts/cw-croncat/src/tests/helpers.rs @@ -38,6 +38,8 @@ pub fn mock_init(store: &CwCroncat, deps: DepsMut) -> Result (App, CwTemplateContract, Addr) { owner_id: Some(owner_addr.to_string()), gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: None, }; diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index e001371f..44e8eaf0 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,4 +1,4 @@ -use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; +use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT}; use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, AGENT1, AGENT2, AGENT3, @@ -103,6 +103,8 @@ fn proxy_call_fail_cases() -> StdResult<()> { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; app.execute_contract( Addr::unchecked(ADMIN), @@ -169,6 +171,8 @@ fn proxy_call_fail_cases() -> StdResult<()> { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }, &vec![], ) @@ -431,7 +435,7 @@ fn proxy_call_no_task_and_withdraw() -> StdResult<()> { }, }; let gas_for_one = GAS_BASE_FEE + gas_limit; - let amount_for_one_task = gas_for_one / GAS_DENOMINATOR; + let amount_for_one_task = gas_for_one * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; let agent_fee = amount_for_one_task * 5 / 100; let amount_with_fee = gas_limit + agent_fee + 1000; // create a task @@ -598,7 +602,7 @@ fn proxy_callback_fail_cases() -> StdResult<()> { attr_key = Some(a.clone().key); attr_value = Some(a.clone().value); } - if e.ty == "transfer" && a.clone().key == "amount" && a.clone().value == "64172atom" + if e.ty == "transfer" && a.clone().key == "amount" && a.clone().value == "93688atom" // task didn't pay for the failed execution { has_submsg_method = true; @@ -697,7 +701,7 @@ fn proxy_callback_fail_cases() -> StdResult<()> { } if e.ty == "transfer" && a.clone().key == "amount" - && a.clone().value == "460840atom" + && a.clone().value == "490356atom" // task didn't pay for the failed execution { has_submsg_method = true; @@ -1367,7 +1371,8 @@ fn test_balance_changes() { let gas_for_one = GAS_BASE_FEE + (GAS_ACTION_FEE * 2); let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking refunds at task removal - let amount_for_one_task = (gas_for_one + agent_fee) / GAS_DENOMINATOR + 3 + 4 + extra; // + 3 + 4 atoms sent + let amount_for_one_task = + (gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3 + 4 + extra; // + 3 + 4 atoms sent // create a task app.execute_contract( @@ -1500,7 +1505,8 @@ fn test_no_reschedule_if_lack_balance() { let gas_for_one = GAS_BASE_FEE + GAS_ACTION_FEE; let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking nonzero task balance - let amount_for_one_task = (gas_for_one + agent_fee) / GAS_DENOMINATOR + 3; // + 3 atoms sent + let amount_for_one_task = + (gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3; // + 3 atoms sent // create a task app.execute_contract( @@ -1548,7 +1554,7 @@ fn test_no_reschedule_if_lack_balance() { .unwrap(); assert_eq!( task.unwrap().total_deposit[0].amount, - Uint128::from((gas_for_one + agent_fee) / GAS_DENOMINATOR + extra) + Uint128::from((gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + extra) ); app.update_block(add_little_time); @@ -1734,7 +1740,7 @@ fn test_reschedule_task_with_queries() { }, }; - let attached_balance = 100338 * 4; + let attached_balance = 27093 * 8; app.execute_contract( Addr::unchecked(ADMIN), contract_addr.clone(), @@ -1855,6 +1861,8 @@ fn tick() { min_tasks_per_agent: None, agents_eject_threshold: Some(1000), // allow to miss 1000 slots gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, @@ -2050,6 +2058,8 @@ fn tick_task() -> StdResult<()> { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, }; app.execute_contract( @@ -2238,7 +2248,8 @@ fn testing_fee_works() { }, }; let total_gas = GAS_BASE_FEE + GAS_ACTION_FEE; - let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR; + let attach_per_action = + (total_gas + (total_gas * 5 / 100)) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; let extra = 100; let amount_for_three = (attach_per_action * 3) as u128 + extra; diff --git a/contracts/cw-croncat/src/tests/owner.rs b/contracts/cw-croncat/src/tests/owner.rs index 4faa27da..0dce88be 100644 --- a/contracts/cw-croncat/src/tests/owner.rs +++ b/contracts/cw-croncat/src/tests/owner.rs @@ -26,6 +26,8 @@ fn update_settings() { owner_id: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: Some(360), }; @@ -51,6 +53,8 @@ fn update_settings() { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; // non-owner fails @@ -106,6 +110,8 @@ fn move_balances_auth_checks() { denom: NATIVE_DENOM.to_string(), owner_id: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), @@ -128,6 +134,8 @@ fn move_balances_auth_checks() { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; let info_setting = mock_info("owner_id", &coins(0, "meow")); let res_exec = store @@ -175,6 +183,8 @@ fn move_balances_native() { denom: NATIVE_DENOM.to_string(), owner_id: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, gas_fraction: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), @@ -197,6 +207,8 @@ fn move_balances_native() { slot_granularity_time: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; let info_settings = mock_info("owner_id", &coins(0, "meow")); let res_exec = store diff --git a/contracts/cw-croncat/src/tests/tasks.rs b/contracts/cw-croncat/src/tests/tasks.rs index bcfee491..ab686b7f 100644 --- a/contracts/cw-croncat/src/tests/tasks.rs +++ b/contracts/cw-croncat/src/tests/tasks.rs @@ -1,5 +1,5 @@ use super::helpers::{ADMIN, ANYONE, NATIVE_DENOM, VERY_RICH}; -use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; +use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT}; use crate::tests::helpers::proper_instantiate; use crate::ContractError; use cosmwasm_std::{ @@ -362,6 +362,8 @@ fn check_task_create_fail_cases() -> StdResult<()> { min_tasks_per_agent: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }; app.execute_contract( Addr::unchecked(ADMIN), @@ -400,6 +402,8 @@ fn check_task_create_fail_cases() -> StdResult<()> { min_tasks_per_agent: None, gas_base_fee: None, gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, }, &vec![], ) @@ -1052,8 +1056,9 @@ fn check_gas_minimum() { }; // create 1 token off task let gas_for_two = (base_gas + gas_limit) * 2; - let enough_for_two = - u128::from((gas_for_two + gas_for_two * 5 / 100) / GAS_DENOMINATOR + 3 * 2); + let enough_for_two = u128::from( + (gas_for_two + gas_for_two * 5 / 100) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3 * 2, + ); let res: ContractError = app .execute_contract( Addr::unchecked(ANYONE), @@ -1117,7 +1122,8 @@ fn check_gas_default() { let gas_for_one = base_gas + gas_limit; let gas_for_one_with_fee = gas_for_one + gas_for_one * 5 / 100; - let enough_for_two = 2 * u128::from(gas_for_one_with_fee / GAS_DENOMINATOR + 3); + let enough_for_two = + 2 * u128::from(gas_for_one_with_fee * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3); let res: ContractError = app .execute_contract( diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index ad3caec7..b5562aa8 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -80,6 +80,8 @@ pub enum ExecuteMsg { agent_fee: Option, gas_base_fee: Option, gas_action_fee: Option, + gas_query_fee: Option, + gas_wasm_query_fee: Option, gas_fraction: Option, proxy_callback_gas: Option, min_tasks_per_agent: Option, diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index 3bfaa88f..c412ed82 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -40,6 +40,8 @@ fn is_valid_msg_once_block_based() { &Addr::unchecked("bob"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .is_ok()); @@ -74,6 +76,8 @@ fn is_valid_msg_once_time_based() { &Addr::unchecked("bob"), 5, 5, + 5, + 5 ) .is_ok()); } @@ -104,6 +108,8 @@ fn is_valid_msg_recurring() { &Addr::unchecked("bob"), 5, 5, + 5, + 5 ) .is_ok()); } @@ -138,6 +144,8 @@ fn is_valid_msg_wrong_account() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .unwrap_err() @@ -173,6 +181,8 @@ fn is_valid_msg_vote() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .unwrap_err() @@ -210,6 +220,8 @@ fn is_valid_msg_transfer() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .unwrap_err() @@ -244,6 +256,8 @@ fn is_valid_msg_burn() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .unwrap_err() @@ -278,6 +292,8 @@ fn is_valid_msg_send_doesnt_fail() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .is_ok()); @@ -311,6 +327,8 @@ fn is_valid_msg_send_should_success() { &Addr::unchecked("sender"), &Addr::unchecked("bob"), 5, + 5, + 5, 5 ) .is_ok()); diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 647a3d61..ed718a50 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -227,6 +227,8 @@ impl TaskRequest { /// Validate the task actions only use the supported messages /// We're iterating over all actions /// so it's a great place for calculaing balance usages + // Consider moving Config to teh cw-croncat-core so this method can take reference of that + #[allow(clippy::too_many_arguments)] pub fn is_valid_msg_calculate_usage( &self, api: &dyn Api, @@ -328,6 +330,10 @@ impl TaskRequest { } if let Some(queries) = self.queries.as_ref() { + // If task has queries - Rules contract is queried which is wasm query + gas_amount + .checked_add(wasm_query_gas) + .ok_or(CoreError::InvalidWasmMsg {})?; for query in queries.iter() { match query { CroncatQuery::HasBalanceGte(_) => { From a61a43e3788b6c1470fbfbb5077041badc34ef75 Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 17:33:32 +0200 Subject: [PATCH 34/53] test --- contracts/cw-croncat/src/tests/manager.rs | 82 ++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 44e8eaf0..737fbf21 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,4 +1,7 @@ -use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT}; +use crate::contract::{ + GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, + GAS_WASM_QUERY_FEE, +}; use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, AGENT1, AGENT2, AGENT3, @@ -3036,3 +3039,80 @@ fn test_error_in_reply() { } assert!(without_failure); } + +#[test] +fn queries_fees() { + let (mut app, cw_template_contract, _) = proper_instantiate(); + let contract_addr = cw_template_contract.addr(); + + // quick agent register + let msg = ExecuteMsg::RegisterAgent { + payable_account_id: Some(AGENT_BENEFICIARY.to_string()), + }; + app.execute_contract(Addr::unchecked(AGENT0), contract_addr.clone(), &msg, &[]) + .unwrap(); + + app.update_block(add_little_time); + + let query = CroncatQuery::HasBalanceGte(HasBalanceGte { + address: contract_addr.to_string(), + required_balance: coins(1, NATIVE_DENOM).into(), + }); + + let transfer_to_bob = BankMsg::Send { + to_address: "bob".to_string(), + amount: coins(1, NATIVE_DENOM), + }; + + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: Some(vec![query]), + transforms: None, + cw20_coins: vec![], + }, + }; + + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_QUERY_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let attached_balance = (gas_to_amount + 1) as u128; + + let task_hash = app.execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap(); + app.update_block(add_little_time); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; + let res = app + .execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + print!("{:#?}", res); + + // Check attributes, should have an error since we can't execute proposal yet + let mut without_failure: bool = false; + for e in res.events { + for a in e.attributes { + if a.key == "with_failure" && a.value.contains("error executing WasmMsg") { + without_failure = true; + } + } + } + assert!(without_failure); +} From 0f45b2a6bc55acfca11266b2cb7835f4150c5b94 Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 18:03:47 +0200 Subject: [PATCH 35/53] new tests --- contracts/cw-croncat/src/tests/manager.rs | 276 +++++++++++++++++++--- packages/cw-croncat-core/src/types.rs | 6 +- 2 files changed, 250 insertions(+), 32 deletions(-) diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 737fbf21..c7d156bd 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -11,6 +11,7 @@ use cosmwasm_std::{ coin, coins, to_binary, Addr, BankMsg, Coin, CosmosMsg, StakingMsg, StdResult, Uint128, WasmMsg, }; use cw20::Cw20Coin; +use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, TaskResponse, TaskWithQueriesResponse, @@ -3054,6 +3055,7 @@ fn queries_fees() { app.update_block(add_little_time); + // Non-wasm query let query = CroncatQuery::HasBalanceGte(HasBalanceGte { address: contract_addr.to_string(), required_balance: coins(1, NATIVE_DENOM).into(), @@ -3079,40 +3081,256 @@ fn queries_fees() { }, }; + // Base + action + calling rules + non-wasm query let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; let attached_balance = (gas_to_amount + 1) as u128; - let task_hash = app.execute_contract( - Addr::unchecked(ADMIN), - contract_addr.clone(), - &create_task_msg, - &coins(attached_balance, NATIVE_DENOM), - ) - .unwrap(); + let task_hash_binary = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap() + .data + .unwrap(); + let task_hash: String = String::from_utf8(task_hash_binary.to_vec()).unwrap(); app.update_block(add_little_time); - // execute proxy_call - let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; - let res = app - .execute_contract( - Addr::unchecked(AGENT0), - contract_addr.clone(), - &proxy_call_msg, - &vec![], - ) - .unwrap(); - print!("{:#?}", res); - - // Check attributes, should have an error since we can't execute proposal yet - let mut without_failure: bool = false; - for e in res.events { - for a in e.attributes { - if a.key == "with_failure" && a.value.contains("error executing WasmMsg") { - without_failure = true; - } - } - } - assert!(without_failure); + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.clone(), + }, + ) + .unwrap(); + assert_eq!( + task.amount_for_one_task_native, + coins(attached_balance, NATIVE_DENOM) + ); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { + task_hash: Some(task_hash), + }; + let res = app + .execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + print!("{:#?}", res); + + assert!(res.events.iter().any(|ev| ev + .attributes + .iter() + .any(|attr| attr.key == "method" && attr.value == "remove_task"))); + + // Wasm query + let wasm_query = CroncatQuery::Query { + contract_addr: contract_addr.to_string(), + msg: to_binary(&QueryMsg::GetAgent { + account_id: AGENT0.to_string(), + }) + .unwrap(), + }; + + let transfer_to_bob = BankMsg::Send { + to_address: "bob".to_string(), + amount: coins(1, NATIVE_DENOM), + }; + + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: Some(vec![wasm_query]), + transforms: None, + cw20_coins: vec![], + }, + }; + + // Base + action + calling rules + wasm query + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let attached_balance = (gas_to_amount + 1) as u128; + + let task_hash_binary = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap() + .data + .unwrap(); + let task_hash: String = String::from_utf8(task_hash_binary.to_vec()).unwrap(); + app.update_block(add_little_time); + + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.clone(), + }, + ) + .unwrap(); + assert_eq!( + task.amount_for_one_task_native, + coins(attached_balance, NATIVE_DENOM) + ); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { + task_hash: Some(task_hash), + }; + let res = app + .execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + print!("{:#?}", res); + + assert!(res.events.iter().any(|ev| ev + .attributes + .iter() + .any(|attr| attr.key == "method" && attr.value == "remove_task"))); +} + +#[test] +fn queries_fees_negative() { + let (mut app, cw_template_contract, _) = proper_instantiate(); + let contract_addr = cw_template_contract.addr(); + + // quick agent register + let msg = ExecuteMsg::RegisterAgent { + payable_account_id: Some(AGENT_BENEFICIARY.to_string()), + }; + app.execute_contract(Addr::unchecked(AGENT0), contract_addr.clone(), &msg, &[]) + .unwrap(); + + app.update_block(add_little_time); + + // Non-wasm query + let query = CroncatQuery::HasBalanceGte(HasBalanceGte { + address: contract_addr.to_string(), + required_balance: coins(1, NATIVE_DENOM).into(), + }); + + let transfer_to_bob = BankMsg::Send { + to_address: "bob".to_string(), + amount: coins(1, NATIVE_DENOM), + }; + + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: Some(vec![query]), + transforms: None, + cw20_coins: vec![], + }, + }; + + // Base + action + calling rules + non-wasm query + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_QUERY_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let attached_balance = (gas_to_amount + 1 - 1) as u128; // missing 1 amount + + let err: ContractError = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap_err() + .downcast() + .unwrap(); + + assert_eq!( + err, + ContractError::CoreError(CoreError::NotEnoughNative { + denom: NATIVE_DENOM.to_string(), + lack: Uint128::new(1), + }) + ); + + // Wasm query + let wasm_query = CroncatQuery::Query { + contract_addr: contract_addr.to_string(), + msg: to_binary(&QueryMsg::GetAgent { + account_id: AGENT0.to_string(), + }) + .unwrap(), + }; + + let transfer_to_bob = BankMsg::Send { + to_address: "bob".to_string(), + amount: coins(1, NATIVE_DENOM), + }; + + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: Some(vec![wasm_query]), + transforms: None, + cw20_coins: vec![], + }, + }; + + // Base + action + calling rules + wasm query + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let attached_balance = (gas_to_amount + 1 - 1) as u128; + + let err: ContractError = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap_err() + .downcast() + .unwrap(); + + assert_eq!( + err, + ContractError::CoreError(CoreError::NotEnoughNative { + denom: NATIVE_DENOM.to_string(), + lack: Uint128::new(1), + }) + ); } diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index ed718a50..1657e042 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -331,18 +331,18 @@ impl TaskRequest { if let Some(queries) = self.queries.as_ref() { // If task has queries - Rules contract is queried which is wasm query - gas_amount + gas_amount = gas_amount .checked_add(wasm_query_gas) .ok_or(CoreError::InvalidWasmMsg {})?; for query in queries.iter() { match query { CroncatQuery::HasBalanceGte(_) => { - gas_amount + gas_amount = gas_amount .checked_add(query_gas) .ok_or(CoreError::InvalidWasmMsg {})?; } _ => { - gas_amount + gas_amount = gas_amount .checked_add(wasm_query_gas) .ok_or(CoreError::InvalidWasmMsg {})?; } From b15fb2022b24537b58694500899324fc955cf69a Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 18:57:04 +0200 Subject: [PATCH 36/53] reschedule fix and tests --- contracts/cw-croncat/src/helpers.rs | 9 +- contracts/cw-croncat/src/tests/manager.rs | 141 +++++++++++++++++++++- packages/cw-croncat-core/src/types.rs | 21 ++++ 3 files changed, 166 insertions(+), 5 deletions(-) diff --git a/contracts/cw-croncat/src/helpers.rs b/contracts/cw-croncat/src/helpers.rs index 1e6d91df..c81ed94e 100644 --- a/contracts/cw-croncat/src/helpers.rs +++ b/contracts/cw-croncat/src/helpers.rs @@ -228,8 +228,13 @@ pub(crate) fn proxy_call_submsgs_price( cfg: Config, next_idx: u64, ) -> Result<(Vec, Coin), ContractError> { - let (sub_msgs, gas_total) = - task.get_submsgs_with_total_gas(cfg.gas_base_fee, cfg.gas_action_fee, next_idx)?; + let (sub_msgs, gas_total) = task.get_submsgs_with_total_gas( + cfg.gas_base_fee, + cfg.gas_action_fee, + cfg.gas_query_fee, + cfg.gas_wasm_query_fee, + next_idx, + )?; let gas_amount = calculate_required_amount(gas_total, cfg.agent_fee)?; let price_amount = cfg.gas_fraction.calculate(gas_amount, 1)?; let price = coin(price_amount, cfg.native_denom); diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index c7d156bd..59bf7c42 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1744,7 +1744,7 @@ fn test_reschedule_task_with_queries() { }, }; - let attached_balance = 27093 * 8; + let attached_balance = 31188 * 8; app.execute_contract( Addr::unchecked(ADMIN), contract_addr.clone(), @@ -1752,7 +1752,16 @@ fn test_reschedule_task_with_queries() { &coins(attached_balance, NATIVE_DENOM), ) .unwrap(); - + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.to_string(), + }, + ) + .unwrap(); + println!("task: {:?}", task); // quick agent register let msg = ExecuteMsg::RegisterAgent { payable_account_id: Some(AGENT_BENEFICIARY.to_string()), @@ -3156,7 +3165,7 @@ fn queries_fees() { msg: transfer_to_bob.clone().into(), gas_limit: None, }], - queries: Some(vec![wasm_query]), + queries: Some(vec![wasm_query.clone()]), transforms: None, cw20_coins: vec![], }, @@ -3213,6 +3222,132 @@ fn queries_fees() { .attributes .iter() .any(|attr| attr.key == "method" && attr.value == "remove_task"))); + + // With reschedule to check balance changes + + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Immediate, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: Some(vec![wasm_query]), + transforms: None, + cw20_coins: vec![], + }, + }; + + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let one_proxy_call_amount = (gas_to_amount + 1) as u128; + + let task_hash_binary = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(one_proxy_call_amount * 3, NATIVE_DENOM), + ) + .unwrap() + .data + .unwrap(); + let task_hash: String = String::from_utf8(task_hash_binary.to_vec()).unwrap(); + app.update_block(add_little_time); + + // Initial balance for 3 proxy calls + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.clone(), + }, + ) + .unwrap(); + assert_eq!( + task.amount_for_one_task_native, + coins(one_proxy_call_amount, NATIVE_DENOM) + ); + assert_eq!( + task.total_deposit, + coins(one_proxy_call_amount * 3, NATIVE_DENOM) + ); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { + task_hash: Some(task_hash.clone()), + }; + app.execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + + // for 2 proxies should have left + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.to_string(), + }, + ) + .unwrap(); + assert_eq!( + task.total_deposit, + coins(one_proxy_call_amount * 2, NATIVE_DENOM) + ); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { + task_hash: Some(task_hash.clone()), + }; + app.execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + + // for 2 proxies should have left + let task: TaskResponse = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetTask { + task_hash: task_hash.to_string(), + }, + ) + .unwrap(); + assert_eq!( + task.total_deposit, + coins(one_proxy_call_amount, NATIVE_DENOM) + ); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { + task_hash: Some(task_hash.clone()), + }; + let res = app + .execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + + assert!(res.events.iter().any(|ev| ev + .attributes + .iter() + .any(|attr| attr.key == "method" && attr.value == "remove_task"))); } #[test] diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 1657e042..a9fb9875 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -459,6 +459,8 @@ impl Task { &self, base_gas: u64, action_gas: u64, + query_gas: u64, + wasm_query_gas: u64, next_idx: u64, ) -> Result<(Vec>, u64), CoreError> { let mut gas: u64 = base_gas; @@ -474,6 +476,25 @@ impl Task { sub_msgs.push(sub_msg); } } + + if let Some(queries) = self.queries.as_ref() { + // If task has queries - Rules contract is queried which is wasm query + gas = gas + .checked_add(wasm_query_gas) + .ok_or(CoreError::InvalidGas {})?; + for query in queries.iter() { + match query { + CroncatQuery::HasBalanceGte(_) => { + gas = gas.checked_add(query_gas).ok_or(CoreError::InvalidGas {})?; + } + _ => { + gas = gas + .checked_add(wasm_query_gas) + .ok_or(CoreError::InvalidGas {})?; + } + } + } + } Ok((sub_msgs, gas)) } From 033f54968283214ca8a8e35d196ef55c753f5386 Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 19:02:32 +0200 Subject: [PATCH 37/53] schema+codegen+checksum --- checksum | 2 +- .../cw-croncat-core/schema/execute_msg.json | 20 +++++++++++++++++++ .../schema/instantiate_msg.json | 20 +++++++++++++++++++ .../cw-croncat-core/CwCroncatCore.client.ts | 10 ++++++++++ .../cw-croncat-core/CwCroncatCore.types.ts | 4 ++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/checksum b/checksum index f311d653..60eacc87 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm +db4b436c80c411983f33a9f118d9ef47b97c784e62b6379331f01259c58d5d66 cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm diff --git a/packages/cw-croncat-core/schema/execute_msg.json b/packages/cw-croncat-core/schema/execute_msg.json index 4f5d11f4..b701e547 100644 --- a/packages/cw-croncat-core/schema/execute_msg.json +++ b/packages/cw-croncat-core/schema/execute_msg.json @@ -57,6 +57,26 @@ } ] }, + "gas_query_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, + "gas_wasm_query_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, "min_tasks_per_agent": { "type": [ "integer", diff --git a/packages/cw-croncat-core/schema/instantiate_msg.json b/packages/cw-croncat-core/schema/instantiate_msg.json index 8ecab164..ac8a7dd7 100644 --- a/packages/cw-croncat-core/schema/instantiate_msg.json +++ b/packages/cw-croncat-core/schema/instantiate_msg.json @@ -51,6 +51,26 @@ } ] }, + "gas_query_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, + "gas_wasm_query_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Uint64" + }, + { + "type": "null" + } + ] + }, "owner_id": { "type": [ "string", diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index befe9a5f..767bc497 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -259,6 +259,8 @@ export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { gasActionFee, gasBaseFee, gasFraction, + gasQueryFee, + gasWasmQueryFee, minTasksPerAgent, ownerId, paused, @@ -270,6 +272,8 @@ export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { gasActionFee?: Uint64; gasBaseFee?: Uint64; gasFraction?: GasFraction; + gasQueryFee?: Uint64; + gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; ownerId?: string; paused?: boolean; @@ -376,6 +380,8 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC gasActionFee, gasBaseFee, gasFraction, + gasQueryFee, + gasWasmQueryFee, minTasksPerAgent, ownerId, paused, @@ -387,6 +393,8 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC gasActionFee?: Uint64; gasBaseFee?: Uint64; gasFraction?: GasFraction; + gasQueryFee?: Uint64; + gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; ownerId?: string; paused?: boolean; @@ -400,6 +408,8 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC gas_action_fee: gasActionFee, gas_base_fee: gasBaseFee, gas_fraction: gasFraction, + gas_query_fee: gasQueryFee, + gas_wasm_query_fee: gasWasmQueryFee, min_tasks_per_agent: minTasksPerAgent, owner_id: ownerId, paused, diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index 8785d9c1..b17f63f2 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -422,6 +422,8 @@ export type ExecuteMsg = { gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; gas_fraction?: GasFraction | null; + gas_query_fee?: Uint64 | null; + gas_wasm_query_fee?: Uint64 | null; min_tasks_per_agent?: number | null; owner_id?: string | null; paused?: boolean | null; @@ -558,6 +560,8 @@ export interface InstantiateMsg { gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; gas_fraction?: GasFraction | null; + gas_query_fee?: Uint64 | null; + gas_wasm_query_fee?: Uint64 | null; owner_id?: string | null; [k: string]: unknown; } From 29ed17010af2cff49feafc4deb47f1e12760e90b Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 19:11:25 +0200 Subject: [PATCH 38/53] build typescript update --- justfile | 1 + .../build/contracts/cw-croncat-core/CwCroncatCore.client.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 3acd01b8..336c8db0 100644 --- a/justfile +++ b/justfile @@ -24,6 +24,7 @@ schema: gen: #!/usr/bin/env bash cd typescript + yarn --cwd ./typescript build yarn --cwd ./typescript install --frozen-lockfile yarn --cwd ./typescript codegen juno-local: diff --git a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js index e7ff693c..0e385a28 100644 --- a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js +++ b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js @@ -140,7 +140,7 @@ exports.CwCroncatCoreQueryClient = CwCroncatCoreQueryClient; class CwCroncatCoreClient extends CwCroncatCoreQueryClient { constructor(client, sender, contractAddress) { super(client, contractAddress); - this.updateSettings = ({ agentFee, agentsEjectThreshold, gasActionFee, gasBaseFee, gasFraction, minTasksPerAgent, ownerId, paused, proxyCallbackGas, slotGranularityTime }, fee = "auto", memo, funds) => __awaiter(this, void 0, void 0, function* () { + this.updateSettings = ({ agentFee, agentsEjectThreshold, gasActionFee, gasBaseFee, gasFraction, gasQueryFee, gasWasmQueryFee, minTasksPerAgent, ownerId, paused, proxyCallbackGas, slotGranularityTime }, fee = "auto", memo, funds) => __awaiter(this, void 0, void 0, function* () { return yield this.client.execute(this.sender, this.contractAddress, { update_settings: { agent_fee: agentFee, @@ -148,6 +148,8 @@ class CwCroncatCoreClient extends CwCroncatCoreQueryClient { gas_action_fee: gasActionFee, gas_base_fee: gasBaseFee, gas_fraction: gasFraction, + gas_query_fee: gasQueryFee, + gas_wasm_query_fee: gasWasmQueryFee, min_tasks_per_agent: minTasksPerAgent, owner_id: ownerId, paused, From 81483e77ad473986083d5a884016fc6c016bc289 Mon Sep 17 00:00:00 2001 From: Buckram Date: Tue, 20 Dec 2022 19:24:03 +0200 Subject: [PATCH 39/53] gas-benchmark update --- ci/gas-benchmark/src/helpers.rs | 27 +++++++++++++++++++++++---- ci/local_config.yaml | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ci/gas-benchmark/src/helpers.rs b/ci/gas-benchmark/src/helpers.rs index d2c73022..e4a38891 100644 --- a/ci/gas-benchmark/src/helpers.rs +++ b/ci/gas-benchmark/src/helpers.rs @@ -13,12 +13,15 @@ use cosm_orc::{ }; use cosmwasm_std::Binary; use cw20::Cw20Coin; -use cw_croncat::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR}; +use cw_croncat::contract::{ + GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, + GAS_WASM_QUERY_FEE, +}; use cw_croncat_core::{ msg::{TaskRequest, TaskResponse, TaskWithQueriesResponse}, types::Action, }; -use cw_rules_core::msg::QueryResponse; +use cw_rules_core::{msg::QueryResponse, types::CroncatQuery}; const fn add_agent_fee(num: u64) -> u64 { num + (num * 5 / 100) @@ -30,6 +33,19 @@ fn min_gas_for_actions(actions: &[Action]) -> u64 { }) } +fn min_gas_for_queries(queries: Option<&Vec>) -> u64 { + if let Some(queries) = queries { + queries.iter().fold(GAS_WASM_QUERY_FEE, |acc, query| { + acc + match query { + CroncatQuery::HasBalanceGte(_) => GAS_QUERY_FEE, + _ => GAS_WASM_QUERY_FEE, + } + }) + } else { + 0 + } +} + pub(crate) fn init_contracts( orc: &mut CosmOrc, key: &SigningKey, @@ -177,8 +193,11 @@ where .map(|(_, _, prefix)| (*prefix).to_owned()) .collect(); for (task, extra_funds, prefix) in tasks { - let gas_for_task = GAS_BASE_FEE + min_gas_for_actions(&task.actions); - let gas_to_attached_deposit = add_agent_fee(gas_for_task) / GAS_DENOMINATOR; + let gas_for_task = GAS_BASE_FEE + + min_gas_for_actions(&task.actions) + + min_gas_for_queries(task.queries.as_ref()); + let gas_to_attached_deposit = + add_agent_fee(gas_for_task) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; let amount = (gas_to_attached_deposit + extra_funds) * 3; create_task(task, orc, user_key, prefix, &denom, amount)?; } diff --git a/ci/local_config.yaml b/ci/local_config.yaml index 71630659..ec4dc483 100644 --- a/ci/local_config.yaml +++ b/ci/local_config.yaml @@ -4,5 +4,5 @@ chain_cfg: chain_id: "testing" rpc_endpoint: "http://localhost:26657/" grpc_endpoint: "http://localhost:9090/" - gas_prices: 0.1 - gas_adjustment: 1.2 + gas_prices: 0.04 + gas_adjustment: 1.5 From 4255fa8843141a2f603f30af900b27262740029e Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 13:49:54 +0200 Subject: [PATCH 40/53] task hash method updated --- packages/cw-croncat-core/src/types.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 25028c0d..ac4d95d3 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -360,8 +360,13 @@ impl Task { /// Get the hash of a task based on parameters pub fn to_hash(&self) -> String { let message = format!( - "{:?}{:?}{:?}{:?}{:?}", - self.owner_id, self.interval, self.boundary, self.actions, self.queries + "{:?}{:?}{:?}{:?}{:?}{:?}", + self.owner_id, + self.interval, + self.boundary, + self.actions, + self.queries, + self.transforms ); let hash = Sha256::digest(message.as_bytes()); From 484e7b552e43930c6f02a25a1a5125ee6756a1a3 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 13:50:06 +0200 Subject: [PATCH 41/53] tests updated --- contracts/cw-croncat/src/tests/agent.rs | 2 +- contracts/cw-croncat/src/tests/manager.rs | 18 +++++++++--------- contracts/cw-croncat/src/tests/owner.rs | 2 +- contracts/cw-croncat/src/tests/state.rs | 2 +- contracts/cw-croncat/src/tests/tasks.rs | 8 ++++---- packages/cw-croncat-core/src/tests/types.rs | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/contracts/cw-croncat/src/tests/agent.rs b/contracts/cw-croncat/src/tests/agent.rs index ced94dd8..d5841b35 100644 --- a/contracts/cw-croncat/src/tests/agent.rs +++ b/contracts/cw-croncat/src/tests/agent.rs @@ -612,7 +612,7 @@ fn accept_nomination_agent() { let res = add_task_exec(&mut app, &contract_addr, PARTICIPANT0); let task_hash = res.events[1].attributes[4].clone().value; assert_eq!( - "7ea9a6d5ef5c78cb168afa96b43b5843b8f880627aa0580f4311403f907cbf93", task_hash, + "e078693103645f865278562ddb4301ec1f684c7ec4a0bd43907175b00ee8f562", task_hash, "Unexpected task hash" ); diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 0a669587..8aa8684c 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -51,7 +51,7 @@ fn proxy_call_fail_cases() -> StdResult<()> { }, }; let task_id_str = - "95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string(); + "a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string(); // Must attach funds let res_err = app @@ -249,7 +249,7 @@ fn proxy_call_success() -> StdResult<()> { let contract_addr = cw_template_contract.addr(); let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; let task_id_str = - "1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string(); + "62c7a2dd020ace2169b3d61ac32a5e5fd98050d73584f121d424a9ebbf32e7a0".to_string(); // Doing this msg since its the easiest to guarantee success in reply let msg = CosmosMsg::Wasm(WasmMsg::Execute { @@ -506,7 +506,7 @@ fn proxy_callback_fail_cases() -> StdResult<()> { let contract_addr = cw_template_contract.addr(); let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; let task_id_str = - "96003a7938c1ac9566fec1be9b0cfa97a56626a574940ef5968364ef4d30c15a".to_string(); + "dc8759f300ac55b4d4f0e7fa0fc6727392f55e9f4d132745692eae1da7108cfc".to_string(); // Doing this msg since its the easiest to guarantee success in reply let validator = String::from("you"); @@ -735,7 +735,7 @@ fn proxy_callback_block_slots() -> StdResult<()> { let contract_addr = cw_template_contract.addr(); let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; let task_id_str = - "1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string(); + "62c7a2dd020ace2169b3d61ac32a5e5fd98050d73584f121d424a9ebbf32e7a0".to_string(); // Doing this msg since its the easiest to guarantee success in reply let msg = CosmosMsg::Wasm(WasmMsg::Execute { @@ -864,7 +864,7 @@ fn proxy_callback_time_slots() -> StdResult<()> { let contract_addr = cw_template_contract.addr(); let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; let task_id_str = - "164329dc48b4d81075f82c823108d1f1f435af952d4697583b99a9f35962e211".to_string(); + "5a9fd1f1506e26cc78816f031ad251729fb2d6979f54639116611cd3d9df9191".to_string(); // Doing this msg since its the easiest to guarantee success in reply let msg = CosmosMsg::Wasm(WasmMsg::Execute { @@ -1542,7 +1542,7 @@ fn test_no_reschedule_if_lack_balance() { .query_wasm_smart( contract_addr.clone(), &QueryMsg::GetTask { - task_hash: "65237042c224447b7d6d7cdfd6515af3e76cb3270ce6d5ed989a6babc12f1026" + task_hash: "8fad55a869f129ba363786bd7f0ec698f1a59e2553ba7fdec408f1cd82326cd3" .to_string(), }, ) @@ -1574,7 +1574,7 @@ fn test_no_reschedule_if_lack_balance() { .query_wasm_smart( contract_addr.clone(), &QueryMsg::GetTask { - task_hash: "65237042c224447b7d6d7cdfd6515af3e76cb3270ce6d5ed989a6babc12f1026" + task_hash: "8fad55a869f129ba363786bd7f0ec698f1a59e2553ba7fdec408f1cd82326cd3" .to_string(), }, ) @@ -1599,7 +1599,7 @@ fn test_no_reschedule_if_lack_balance() { fn test_complete_task_with_query() { let (mut app, cw_template_contract, _) = proper_instantiate(); let contract_addr = cw_template_contract.addr(); - let task_hash = "259f4b3122822233bee9bc6ec8d38184e4b6ce0908decd68d972639aa92199c7"; + let task_hash = "c2772d2268fa9809f70bb36c15cb33c1f7c6ff458ca2f2a4707b8ae677d53c72"; let addr1 = String::from("addr1"); let amount = coins(3, NATIVE_DENOM); @@ -1709,7 +1709,7 @@ fn test_complete_task_with_query() { fn test_reschedule_task_with_queries() { let (mut app, cw_template_contract, _) = proper_instantiate(); let contract_addr = cw_template_contract.addr(); - let task_hash = "4e74864be3956efe77bafac50944995290a32507bbd4509dd8ff21d3fdfdfec3"; + let task_hash = "672deeb057ad86ca6c16b7abee1b912b6f737b7eedd4f3fe319d5bd54dc1dbd6"; let addr1 = String::from("addr1"); let amount = coins(3, NATIVE_DENOM); diff --git a/contracts/cw-croncat/src/tests/owner.rs b/contracts/cw-croncat/src/tests/owner.rs index 4faa27da..ce03a14f 100644 --- a/contracts/cw-croncat/src/tests/owner.rs +++ b/contracts/cw-croncat/src/tests/owner.rs @@ -384,7 +384,7 @@ fn test_get_state() { let state = state.unwrap(); let task_id_str = - "1032a37c92801f73c75816bddb4f0db8516baeeeacd6a2c225f0a6a54c96732e".to_string(); + "62c7a2dd020ace2169b3d61ac32a5e5fd98050d73584f121d424a9ebbf32e7a0".to_string(); assert_eq!(state.agent_active_queue.len(), 1); assert_eq!(state.agent_active_queue[0].as_str(), AGENT0); diff --git a/contracts/cw-croncat/src/tests/state.rs b/contracts/cw-croncat/src/tests/state.rs index 38eeb3a7..21f487f3 100644 --- a/contracts/cw-croncat/src/tests/state.rs +++ b/contracts/cw-croncat/src/tests/state.rs @@ -37,7 +37,7 @@ fn check_task_storage_structure() -> StdResult<()> { transforms: None, version: version.version, }; - let task_id_str = "69217dd2b6334abe2544a12fcb89588f9cc5c62a298b8720706d9befa3d736d3"; + let task_id_str = "85a5729f478d96fbb12eec7886992a53635d22bba4d8d8ef2fde16dc7f1f1605"; let task_id = task_id_str.to_string().into_bytes(); // create a task diff --git a/contracts/cw-croncat/src/tests/tasks.rs b/contracts/cw-croncat/src/tests/tasks.rs index 7983bca1..ec6b7b03 100644 --- a/contracts/cw-croncat/src/tests/tasks.rs +++ b/contracts/cw-croncat/src/tests/tasks.rs @@ -63,7 +63,7 @@ fn query_task_hash_success() { ) .unwrap(); assert_eq!( - "69217dd2b6334abe2544a12fcb89588f9cc5c62a298b8720706d9befa3d736d3", + "85a5729f478d96fbb12eec7886992a53635d22bba4d8d8ef2fde16dc7f1f1605", task_hash ); } @@ -579,7 +579,7 @@ fn check_task_create_success() -> StdResult<()> { }, }; let task_id_str = - "95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string(); + "a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string(); // create a task let res = app @@ -852,7 +852,7 @@ fn check_remove_create() -> StdResult<()> { }, }; let task_id_str = - "95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string(); + "a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string(); // create a task app.execute_contract( @@ -962,7 +962,7 @@ fn check_refill_create() -> StdResult<()> { }, }; let task_id_str = - "95c916a53fa9d26deef094f7e1ee31c00a2d47b8bf474b2e06d39aebfb1fecc7".to_string(); + "a78a89f0bbcba7d36c50d2b0ea8f3d3f6677b4b4ca76bd650eaf5836bed65b1c".to_string(); // create a task app.execute_contract( diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index 3bfaa88f..dd385847 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -507,8 +507,8 @@ fn hashing() { }; let message = format!( - "{:?}{:?}{:?}{:?}{:?}", - task.owner_id, task.interval, task.boundary, task.actions, task.queries + "{:?}{:?}{:?}{:?}{:?}{:?}", + task.owner_id, task.interval, task.boundary, task.actions, task.queries, task.transforms ); let hash = Sha256::digest(message.as_bytes()); From 0658aa4abc8b46c678fd92a551ca5d3bf1f81927 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 14:34:01 +0200 Subject: [PATCH 42/53] checksum and deps updates --- Cargo.lock | 11 ++++++----- checksum | 4 ++-- contracts/cw-rules/Cargo.toml | 3 +-- packages/cw-croncat-core/Cargo.toml | 9 ++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6db54a58..64344f18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -477,7 +477,7 @@ dependencies = [ "hex", "schemars", "serde", - "serde-json-wasm 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde-json-wasm 0.4.1", "thiserror", "uint", ] @@ -694,7 +694,7 @@ dependencies = [ "schemars", "serde", "serde-cw-value", - "serde-json-wasm 0.4.1 (git+https://github.com/CyberHoward/serde-json-wasm?rev=cdc78130b25d65981b74a5e4a10a9f8667292d36)", + "serde-json-wasm 0.5.0", "sha2 0.10.6", "thiserror", ] @@ -804,7 +804,7 @@ dependencies = [ "schemars", "serde", "serde-cw-value", - "serde-json-wasm 0.4.1 (git+https://github.com/CyberHoward/serde-json-wasm?rev=cdc78130b25d65981b74a5e4a10a9f8667292d36)", + "serde-json-wasm 0.5.0", "serde_json", "smart-query", "thiserror", @@ -2946,8 +2946,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.1" -source = "git+https://github.com/CyberHoward/serde-json-wasm?rev=cdc78130b25d65981b74a5e4a10a9f8667292d36#cdc78130b25d65981b74a5e4a10a9f8667292d36" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15bee9b04dd165c3f4e142628982ddde884c2022a89e8ddf99c4829bf2c3a58" dependencies = [ "serde", ] diff --git a/checksum b/checksum index f311d653..15e5714d 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm +66bfd72a44ca65f727e89dbeb30c6325420bfe5218a1218e9cb1ff90cf82b8cb cw_croncat.wasm +348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm diff --git a/contracts/cw-rules/Cargo.toml b/contracts/cw-rules/Cargo.toml index 867db4eb..b1e392a6 100644 --- a/contracts/cw-rules/Cargo.toml +++ b/contracts/cw-rules/Cargo.toml @@ -47,8 +47,7 @@ thiserror = { version = "1.0.31" } # This thing saved our lives thanks @hashedone for implementing it serde-cw-value = "0.7.0" -# TODO: update when this feature is merged -serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/serde-json-wasm", rev = "cdc78130b25d65981b74a5e4a10a9f8667292d36" } +serde-json-wasm = { version = "0.5.0" } [dev-dependencies] cw721-base = "0.15.0" diff --git a/packages/cw-croncat-core/Cargo.toml b/packages/cw-croncat-core/Cargo.toml index d9bfcb02..585492b7 100644 --- a/packages/cw-croncat-core/Cargo.toml +++ b/packages/cw-croncat-core/Cargo.toml @@ -23,13 +23,12 @@ cw20 = { version = "0.13.4" } schemars = "0.8" serde = { version = "1.0", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } -hex = "0.4" -sha2 = "0.10.6" +hex = { version = "0.4", default-features = false } +sha2 = { version = "0.10.6", default-features = false } serde-cw-value = "0.7.0" -# TODO: update when this feature is merged -serde-json-wasm = { version = "0.4.1", git = "https://github.com/CyberHoward/serde-json-wasm", rev = "cdc78130b25d65981b74a5e4a10a9f8667292d36" } +serde-json-wasm = { version = "0.5.0" } [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } cw-multi-test = { version = "0.16.0", features = ["staking"] } -cw20-base = { version = "0.13.4", features = ["library"] } \ No newline at end of file +cw20-base = { version = "0.13.4", features = ["library"] } From 87ea8e27bd35e73594d375f5cded2cec607a7870 Mon Sep 17 00:00:00 2001 From: Deveus Date: Wed, 21 Dec 2022 15:49:54 +0200 Subject: [PATCH 43/53] fix: Empty action bug --- contracts/cw-croncat/src/tasks.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 9d2769ae..3b1b957d 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -254,7 +254,9 @@ impl<'a> CwCroncat<'a> { val: "Interval invalid".to_string(), }); } - + if task.actions.is_empty() { + return Err(ContractError::CoreError(CoreError::InvalidAction {})); + } let (mut amount_for_one_task, gas_amount) = task.is_valid_msg_calculate_usage( deps.api, &env.contract.address, From c4e3594db759e0ba4afa5fd4322f97aa2b12fba3 Mon Sep 17 00:00:00 2001 From: Deveus Date: Wed, 21 Dec 2022 16:40:50 +0200 Subject: [PATCH 44/53] fix: checksum --- checksum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checksum b/checksum index f311d653..7edbe48d 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm +7e1411d78e92ac4ab2dbda9208b62f0b4cfffc926cfc61de10498fe4e40b7afd cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm From 3d9a68e145cc80ab6a74cc6f09b75dcbac06b970 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 17:40:57 +0200 Subject: [PATCH 45/53] tests --- checksum | 2 +- contracts/cw-croncat/src/tasks.rs | 4 +-- contracts/cw-croncat/src/tests/manager.rs | 35 +++++++++++++++++++++ packages/cw-croncat-core/src/tests/types.rs | 25 +++++++++++++++ packages/cw-croncat-core/src/types.rs | 3 ++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/checksum b/checksum index 7edbe48d..97137749 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -7e1411d78e92ac4ab2dbda9208b62f0b4cfffc926cfc61de10498fe4e40b7afd cw_croncat.wasm +853004395db1861f1f337925a76e31b9f8ed5fe158b807c647240ea71876e875 cw_croncat.wasm de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 3b1b957d..9d2769ae 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -254,9 +254,7 @@ impl<'a> CwCroncat<'a> { val: "Interval invalid".to_string(), }); } - if task.actions.is_empty() { - return Err(ContractError::CoreError(CoreError::InvalidAction {})); - } + let (mut amount_for_one_task, gas_amount) = task.is_valid_msg_calculate_usage( deps.api, &env.contract.address, diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 0a669587..f3d64ba9 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -8,6 +8,7 @@ use cosmwasm_std::{ coin, coins, to_binary, Addr, BankMsg, Coin, CosmosMsg, StakingMsg, StdResult, Uint128, WasmMsg, }; use cw20::Cw20Coin; +use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, TaskResponse, TaskWithQueriesResponse, @@ -3026,3 +3027,37 @@ fn test_error_in_reply() { } assert!(without_failure); } + +#[test] +fn empty_actions_not_allowed() { + let (mut app, cw_template_contract, _) = proper_instantiate(); + let contract_addr = cw_template_contract.addr(); + + let empty_actions = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![], + queries: None, + transforms: None, + cw20_coins: vec![], + }, + }; + + let total_gas = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; + let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR_DEFAULT_JUNO; + let amount_for_three = (attach_per_action) as u128; + + let res: ContractError = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &empty_actions, + &coins(amount_for_three, NATIVE_DENOM), + ) + .unwrap_err() + .downcast() + .unwrap(); + assert_eq!(res, ContractError::CoreError(CoreError::InvalidAction {})); +} diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index 3bfaa88f..84db19db 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -316,6 +316,31 @@ fn is_valid_msg_send_should_success() { .is_ok()); } +#[test] +fn is_valid_empty_actions() { + let task = TaskRequest { + interval: Interval::Block(10), + boundary: None, + stop_on_fail: false, + actions: vec![], + queries: None, + transforms: None, + cw20_coins: Default::default(), + }; + assert_eq!( + task.is_valid_msg_calculate_usage( + &mock_dependencies().api, + &Addr::unchecked("alice2"), + &Addr::unchecked("bob"), + &Addr::unchecked("bob"), + 5, + 5, + ) + .unwrap_err(), + CoreError::InvalidAction {} + ); +} + #[test] fn test_add_tokens() { let mut coins: GenericBalance = GenericBalance::default(); diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index 25028c0d..790af8f9 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -239,6 +239,9 @@ impl TaskRequest { let mut gas_amount: u64 = base_gas; let mut amount_for_one_task = GenericBalance::default(); + if self.actions.is_empty() { + return Err(CoreError::InvalidAction {}); + } for action in self.actions.iter() { // checked for cases, where task creator intentionaly tries to overflow gas_amount = gas_amount From 8b98ae276403ee4e72e7c00d1e79abdc1f761a03 Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Wed, 21 Dec 2022 09:14:39 -0800 Subject: [PATCH 46/53] updating checksum --- checksum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checksum b/checksum index 60eacc87..73f35e0f 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -db4b436c80c411983f33a9f118d9ef47b97c784e62b6379331f01259c58d5d66 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm +0b779e7fbbab5d0d2e4b75a413351f41a7083cf410d6562cc9578baaaaf6d977 cw_croncat.wasm +66a4088ae10ba3a45653760543c8c52bad006a5fe79e896bb5f6c3aa26887277 cw_rules.wasm From d695712a3e901fa9ee4e5a3a4bd79078e303409d Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 19:29:33 +0200 Subject: [PATCH 47/53] checksum --- checksum | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/checksum b/checksum index f5e4bb73..c7b7f63e 100644 --- a/checksum +++ b/checksum @@ -1,4 +1,2 @@ -91765daecbccc3669a068086a1de71a16ab4c689b804282d3872b6ee4c7ca992 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm -66bfd72a44ca65f727e89dbeb30c6325420bfe5218a1218e9cb1ff90cf82b8cb cw_croncat.wasm +6f12020a97b6e77b0a47ef33937faef858af5077ab5f0c330164dab7130d8e8d cw_croncat.wasm 348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm From e42b1d96b8e504deb8da243724919fa3e189e468 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 21:59:40 +0200 Subject: [PATCH 48/53] small gas_price refactor --- checksum | 2 +- ci/gas-benchmark/src/helpers.rs | 15 +++-- contracts/cw-croncat/src/agent.rs | 6 +- contracts/cw-croncat/src/contract.rs | 16 ++++-- contracts/cw-croncat/src/helpers.rs | 6 +- contracts/cw-croncat/src/state.rs | 4 +- contracts/cw-croncat/src/tasks.rs | 6 +- contracts/cw-croncat/src/tests/agent.rs | 5 +- contracts/cw-croncat/src/tests/balance.rs | 9 +-- contracts/cw-croncat/src/tests/contract.rs | 8 ++- contracts/cw-croncat/src/tests/manager.rs | 56 ++++++++++++++----- contracts/cw-croncat/src/tests/tasks.rs | 18 ++++-- packages/cw-croncat-core/schema/croncat.json | 11 +++- .../cw-croncat-core/schema/execute_msg.json | 11 +++- .../schema/instantiate_msg.json | 11 +++- packages/cw-croncat-core/src/msg.rs | 8 +-- packages/cw-croncat-core/src/tests/msg.rs | 5 +- packages/cw-croncat-core/src/types.rs | 34 ++++++----- .../cw-croncat-core/CwCroncatCore.client.ts | 6 +- .../cw-croncat-core/CwCroncatCore.types.ts | 9 +-- 20 files changed, 163 insertions(+), 83 deletions(-) diff --git a/checksum b/checksum index d38aed15..b141667d 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -c678d3d62965d9ba4982766fbd4bafcb8d7c0df2bdc089da0f975f3d78c84c0d cw_croncat.wasm +4cfe570b1fe33bc51e385ba4c2b6256f242125bf54a0ec47f391fba22f7f3817 cw_croncat.wasm 348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm diff --git a/ci/gas-benchmark/src/helpers.rs b/ci/gas-benchmark/src/helpers.rs index e4a38891..f3f02f8e 100644 --- a/ci/gas-benchmark/src/helpers.rs +++ b/ci/gas-benchmark/src/helpers.rs @@ -14,12 +14,12 @@ use cosm_orc::{ use cosmwasm_std::Binary; use cw20::Cw20Coin; use cw_croncat::contract::{ - GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, - GAS_WASM_QUERY_FEE, + GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, + GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, GAS_WASM_QUERY_FEE, }; use cw_croncat_core::{ msg::{TaskRequest, TaskResponse, TaskWithQueriesResponse}, - types::Action, + types::{Action, GasPrice}, }; use cw_rules_core::{msg::QueryResponse, types::CroncatQuery}; @@ -196,8 +196,13 @@ where let gas_for_task = GAS_BASE_FEE + min_gas_for_actions(&task.actions) + min_gas_for_queries(task.queries.as_ref()); - let gas_to_attached_deposit = - add_agent_fee(gas_for_task) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_attached_deposit = GasPrice { + numerator: GAS_NUMERATOR_DEFAULT, + denominator: GAS_DENOMINATOR, + gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, + } + .calculate(add_agent_fee(gas_for_task)) + .unwrap() as u64; let amount = (gas_to_attached_deposit + extra_funds) * 3; create_task(task, orc, user_key, prefix, &denom, amount)?; } diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 07a37970..7c2a7f4c 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -11,7 +11,7 @@ use std::ops::Div; use crate::ContractError::*; use cw_croncat_core::msg::{AgentResponse, AgentTaskResponse, GetAgentIdsResponse}; -use cw_croncat_core::types::{calculate_required_amount, Agent, AgentStatus}; +use cw_croncat_core::types::{gas_amount_with_agent_fee, Agent, AgentStatus}; impl<'a> CwCroncat<'a> { /// Get a single agent details @@ -142,8 +142,8 @@ impl<'a> CwCroncat<'a> { // Check if native token balance is sufficient for a few txns, in this case 4 txns // TODO: Adjust gas & costs based on real usage cost let agent_wallet_balances = deps.querier.query_all_balances(account.clone())?; - let gas_cost = calculate_required_amount(c.gas_action_fee, c.agent_fee)?; - let unit_cost = c.gas_fraction.calculate(4 * gas_cost, 1)?; + let gas_amount_with_agent_fee = gas_amount_with_agent_fee(c.gas_action_fee, c.agent_fee)?; + let unit_cost = c.gas_fraction.calculate(4 * gas_amount_with_agent_fee)?; if !has_coins( &agent_wallet_balances, &Coin::new(unit_cost, c.native_denom), diff --git a/contracts/cw-croncat/src/contract.rs b/contracts/cw-croncat/src/contract.rs index 8e086875..5a3432f9 100644 --- a/contracts/cw-croncat/src/contract.rs +++ b/contracts/cw-croncat/src/contract.rs @@ -7,7 +7,7 @@ use cosmwasm_std::{ }; use cw2::set_contract_version; use cw_croncat_core::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use cw_croncat_core::types::{GasFraction, SlotType}; +use cw_croncat_core::types::{GasPrice, SlotType}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:cw-croncat"; @@ -25,10 +25,13 @@ pub const GAS_QUERY_FEE: u64 = 5_000; pub const GAS_WASM_QUERY_FEE: u64 = 60_000; /// We can't store gas_price as floats inside cosmwasm /// so insted of having 0.04 we use GasFraction{4/100} -/// and multiply numerator by `gas_adjustment` (1.5) -pub const GAS_NUMERATOR_DEFAULT: u64 = 6; -pub const GAS_DENOMINATOR: u64 = 100; - +/// and after that multiply Gas by `gas_adjustment` {150/100} (1.5) +pub mod gas_price_defaults { + pub const GAS_NUMERATOR_DEFAULT: u64 = 4; + pub const GAS_ADJUSTMENT_NUMERATOR_DEFAULT: u64 = 150; + pub const GAS_DENOMINATOR: u64 = 100; +} +pub use gas_price_defaults::*; // #[cfg(not(feature = "library"))] impl<'a> CwCroncat<'a> { pub fn instantiate( @@ -60,9 +63,10 @@ impl<'a> CwCroncat<'a> { available_balance, staked_balance: GenericBalance::default(), agent_fee: 5, - gas_fraction: msg.gas_fraction.unwrap_or(GasFraction { + gas_fraction: msg.gas_fraction.unwrap_or(GasPrice { numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR, + gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, }), proxy_callback_gas: 3, gas_base_fee: msg.gas_base_fee.map(Into::into).unwrap_or(GAS_BASE_FEE), diff --git a/contracts/cw-croncat/src/helpers.rs b/contracts/cw-croncat/src/helpers.rs index c81ed94e..94073fc6 100644 --- a/contracts/cw-croncat/src/helpers.rs +++ b/contracts/cw-croncat/src/helpers.rs @@ -11,7 +11,7 @@ use cosmwasm_std::{ use cw20::{Cw20CoinVerified, Cw20ExecuteMsg}; use cw_croncat_core::msg::ExecuteMsg; use cw_croncat_core::traits::{BalancesOperations, FindAndMutate}; -use cw_croncat_core::types::{calculate_required_amount, AgentStatus}; +use cw_croncat_core::types::{gas_amount_with_agent_fee, AgentStatus}; pub use cw_croncat_core::types::{GenericBalance, Task}; //use regex::Regex; use schemars::JsonSchema; @@ -235,8 +235,8 @@ pub(crate) fn proxy_call_submsgs_price( cfg.gas_wasm_query_fee, next_idx, )?; - let gas_amount = calculate_required_amount(gas_total, cfg.agent_fee)?; - let price_amount = cfg.gas_fraction.calculate(gas_amount, 1)?; + let gas_amount_with_agent_fee = gas_amount_with_agent_fee(gas_total, cfg.agent_fee)?; + let price_amount = cfg.gas_fraction.calculate(gas_amount_with_agent_fee)?; let price = coin(price_amount, cfg.native_denom); Ok((sub_msgs, price)) } diff --git a/contracts/cw-croncat/src/state.rs b/contracts/cw-croncat/src/state.rs index 124ede04..dffaa8a3 100644 --- a/contracts/cw-croncat/src/state.rs +++ b/contracts/cw-croncat/src/state.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::helpers::Task; use cw_croncat_core::{ query::CroncatQuerier, - types::{Agent, GasFraction, GenericBalance, SlotType}, + types::{Agent, GasPrice, GenericBalance, SlotType}, }; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] @@ -38,7 +38,7 @@ pub struct Config { // Economics pub agent_fee: u64, - pub gas_fraction: GasFraction, + pub gas_fraction: GasPrice, pub gas_base_fee: u64, pub gas_action_fee: u64, pub gas_query_fee: u64, diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 5e3acadd..85e72e20 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -13,7 +13,7 @@ use cw_croncat_core::msg::{ }; use cw_croncat_core::traits::{BalancesOperations, FindAndMutate, Intervals}; use cw_croncat_core::types::{ - calculate_required_amount, BoundaryValidated, GenericBalance, SlotType, Task, + gas_amount_with_agent_fee, BoundaryValidated, GenericBalance, SlotType, Task, }; impl<'a> CwCroncat<'a> { @@ -265,8 +265,8 @@ impl<'a> CwCroncat<'a> { cfg.gas_query_fee, cfg.gas_wasm_query_fee, )?; - let gas_price = calculate_required_amount(gas_amount, cfg.agent_fee)?; - let price = cfg.gas_fraction.calculate(gas_price, 1)?; + let gas_amount_with_agent_fee = gas_amount_with_agent_fee(gas_amount, cfg.agent_fee)?; + let price = cfg.gas_fraction.calculate(gas_amount_with_agent_fee)?; amount_for_one_task .native .find_checked_add(&coin(price, &cfg.native_denom))?; diff --git a/contracts/cw-croncat/src/tests/agent.rs b/contracts/cw-croncat/src/tests/agent.rs index 1b26edb0..c2b01efd 100644 --- a/contracts/cw-croncat/src/tests/agent.rs +++ b/contracts/cw-croncat/src/tests/agent.rs @@ -11,7 +11,7 @@ use cw_croncat_core::msg::{ AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, InstantiateMsg, QueryMsg, TaskRequest, TaskResponse, }; -use cw_croncat_core::types::{Action, Agent, AgentStatus, GasFraction, GenericBalance, Interval}; +use cw_croncat_core::types::{Action, Agent, AgentStatus, GasPrice, GenericBalance, Interval}; use cw_multi_test::{App, AppResponse, BankSudo, Executor, SudoMsg}; use super::helpers::{ @@ -345,9 +345,10 @@ fn register_agent_fail_cases() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: Some(GasFraction { + gas_fraction: Some(GasPrice { numerator: 1, denominator: 1, + gas_adjustment_numerator: 1, }), proxy_callback_gas: None, slot_granularity_time: None, diff --git a/contracts/cw-croncat/src/tests/balance.rs b/contracts/cw-croncat/src/tests/balance.rs index 751bf9e9..d316cf6d 100644 --- a/contracts/cw-croncat/src/tests/balance.rs +++ b/contracts/cw-croncat/src/tests/balance.rs @@ -1,13 +1,13 @@ use crate::balancer::{Balancer, BalancerMode, RoundRobinBalancer}; use crate::contract::{ - GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, - GAS_WASM_QUERY_FEE, + GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, + GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, GAS_WASM_QUERY_FEE, }; use crate::state::{Config, TaskInfo}; use crate::tests::helpers::{default_task, AGENT0, AGENT1, AGENT2, AGENT3, AGENT4}; use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env}; use cosmwasm_std::{coins, Addr}; -use cw_croncat_core::types::{GasFraction, GenericBalance, SlotType}; +use cw_croncat_core::types::{GasPrice, GenericBalance, SlotType}; use crate::CwCroncat; @@ -24,9 +24,10 @@ fn mock_config() -> Config { available_balance: GenericBalance::default(), staked_balance: GenericBalance::default(), agent_fee: 5, - gas_fraction: GasFraction { + gas_fraction: GasPrice { numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR, + gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, }, gas_action_fee: GAS_ACTION_FEE, gas_query_fee: GAS_QUERY_FEE, diff --git a/contracts/cw-croncat/src/tests/contract.rs b/contracts/cw-croncat/src/tests/contract.rs index 6784dd27..27b6196e 100644 --- a/contracts/cw-croncat/src/tests/contract.rs +++ b/contracts/cw-croncat/src/tests/contract.rs @@ -1,3 +1,4 @@ +use crate::contract::GAS_ADJUSTMENT_NUMERATOR_DEFAULT; use crate::contract::GAS_DENOMINATOR; use crate::contract::GAS_NUMERATOR_DEFAULT; use crate::state::QueueItem; @@ -12,7 +13,7 @@ use cosmwasm_std::testing::{ }; use cosmwasm_std::{coins, from_binary, Addr, Binary, Event, Reply, SubMsgResponse, SubMsgResult}; use cw_croncat_core::msg::{GetConfigResponse, QueryMsg}; -use cw_croncat_core::types::GasFraction; +use cw_croncat_core::types::GasPrice; use cw_croncat_core::types::SlotType; #[test] @@ -56,9 +57,10 @@ fn configure() { assert_eq!("atom", value.native_denom); assert_eq!(5, value.agent_fee); assert_eq!( - GasFraction { + GasPrice { numerator: GAS_NUMERATOR_DEFAULT, - denominator: GAS_DENOMINATOR + denominator: GAS_DENOMINATOR, + gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, }, value.gas_fraction ); diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index d37f34b4..fa7f5fd9 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,6 +1,6 @@ use crate::contract::{ - GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, - GAS_WASM_QUERY_FEE, + GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, + GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, GAS_WASM_QUERY_FEE, }; use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, @@ -439,7 +439,9 @@ fn proxy_call_no_task_and_withdraw() -> StdResult<()> { }, }; let gas_for_one = GAS_BASE_FEE + gas_limit; - let amount_for_one_task = gas_for_one * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let amount_for_one_task = gas_for_one * GAS_ADJUSTMENT_NUMERATOR_DEFAULT / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let agent_fee = amount_for_one_task * 5 / 100; let amount_with_fee = gas_limit + agent_fee + 1000; // create a task @@ -1375,8 +1377,13 @@ fn test_balance_changes() { let gas_for_one = GAS_BASE_FEE + (GAS_ACTION_FEE * 2); let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking refunds at task removal - let amount_for_one_task = - (gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3 + 4 + extra; // + 3 + 4 atoms sent + let amount_for_one_task = (gas_for_one + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + + 3 + + 4 + + extra; // + 3 + 4 atoms sent // create a task app.execute_contract( @@ -1509,8 +1516,11 @@ fn test_no_reschedule_if_lack_balance() { let gas_for_one = GAS_BASE_FEE + GAS_ACTION_FEE; let agent_fee = gas_for_one * 5 / 100; let extra = 50; // extra for checking nonzero task balance - let amount_for_one_task = - (gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3; // + 3 atoms sent + let amount_for_one_task = (gas_for_one + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + + 3; // + 3 atoms sent // create a task app.execute_contract( @@ -1558,7 +1568,12 @@ fn test_no_reschedule_if_lack_balance() { .unwrap(); assert_eq!( task.unwrap().total_deposit[0].amount, - Uint128::from((gas_for_one + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + extra) + Uint128::from( + (gas_for_one + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + + extra + ) ); app.update_block(add_little_time); @@ -3093,7 +3108,10 @@ fn queries_fees() { // Base + action + calling rules + non-wasm query let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; - let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_amount = (gas_needed + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let attached_balance = (gas_to_amount + 1) as u128; let task_hash_binary = app @@ -3174,7 +3192,10 @@ fn queries_fees() { // Base + action + calling rules + wasm query let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; - let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_amount = (gas_needed + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let attached_balance = (gas_to_amount + 1) as u128; let task_hash_binary = app @@ -3242,7 +3263,10 @@ fn queries_fees() { let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; - let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_amount = (gas_needed + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let one_proxy_call_amount = (gas_to_amount + 1) as u128; let task_hash_binary = app @@ -3393,7 +3417,10 @@ fn queries_fees_negative() { // Base + action + calling rules + non-wasm query let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; - let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_amount = (gas_needed + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let attached_balance = (gas_to_amount + 1 - 1) as u128; // missing 1 amount let err: ContractError = app @@ -3447,7 +3474,10 @@ fn queries_fees_negative() { // Base + action + calling rules + wasm query let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE + GAS_WASM_QUERY_FEE + GAS_WASM_QUERY_FEE; let agent_fee = gas_needed * 5 / 100; - let gas_to_amount = (gas_needed + agent_fee) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR; + let gas_to_amount = (gas_needed + agent_fee) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR; let attached_balance = (gas_to_amount + 1 - 1) as u128; let err: ContractError = app diff --git a/contracts/cw-croncat/src/tests/tasks.rs b/contracts/cw-croncat/src/tests/tasks.rs index 0ac06927..76265e6f 100644 --- a/contracts/cw-croncat/src/tests/tasks.rs +++ b/contracts/cw-croncat/src/tests/tasks.rs @@ -1,5 +1,8 @@ use super::helpers::{ADMIN, ANYONE, NATIVE_DENOM, VERY_RICH}; -use crate::contract::{GAS_ACTION_FEE, GAS_BASE_FEE, GAS_DENOMINATOR, GAS_NUMERATOR_DEFAULT}; +use crate::contract::{ + GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, + GAS_NUMERATOR_DEFAULT, +}; use crate::tests::helpers::proper_instantiate; use crate::ContractError; use cosmwasm_std::{ @@ -1057,7 +1060,10 @@ fn check_gas_minimum() { // create 1 token off task let gas_for_two = (base_gas + gas_limit) * 2; let enough_for_two = u128::from( - (gas_for_two + gas_for_two * 5 / 100) * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3 * 2, + (gas_for_two + gas_for_two * 5 / 100) * GAS_ADJUSTMENT_NUMERATOR_DEFAULT / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + + 3 * 2, ); let res: ContractError = app .execute_contract( @@ -1122,8 +1128,12 @@ fn check_gas_default() { let gas_for_one = base_gas + gas_limit; let gas_for_one_with_fee = gas_for_one + gas_for_one * 5 / 100; - let enough_for_two = - 2 * u128::from(gas_for_one_with_fee * GAS_NUMERATOR_DEFAULT / GAS_DENOMINATOR + 3); + let enough_for_two = 2 * u128::from( + gas_for_one_with_fee * GAS_ADJUSTMENT_NUMERATOR_DEFAULT / GAS_DENOMINATOR + * GAS_NUMERATOR_DEFAULT + / GAS_DENOMINATOR + + 3, + ); let res: ContractError = app .execute_contract( diff --git a/packages/cw-croncat-core/schema/croncat.json b/packages/cw-croncat-core/schema/croncat.json index 94a331c6..4dc95fd3 100644 --- a/packages/cw-croncat-core/schema/croncat.json +++ b/packages/cw-croncat-core/schema/croncat.json @@ -826,10 +826,11 @@ "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" }, - "GasFraction": { + "GasPrice": { "type": "object", "required": [ "denominator", + "gas_adjustment_numerator", "numerator" ], "properties": { @@ -838,6 +839,12 @@ "format": "uint64", "minimum": 0.0 }, + "gas_adjustment_numerator": { + "description": "Note", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "numerator": { "type": "integer", "format": "uint64", @@ -1024,7 +1031,7 @@ "minimum": 0.0 }, "gas_fraction": { - "$ref": "#/definitions/GasFraction" + "$ref": "#/definitions/GasPrice" }, "limit": { "type": "integer", diff --git a/packages/cw-croncat-core/schema/execute_msg.json b/packages/cw-croncat-core/schema/execute_msg.json index b701e547..93d31518 100644 --- a/packages/cw-croncat-core/schema/execute_msg.json +++ b/packages/cw-croncat-core/schema/execute_msg.json @@ -50,7 +50,7 @@ "gas_fraction": { "anyOf": [ { - "$ref": "#/definitions/GasFraction" + "$ref": "#/definitions/GasPrice" }, { "type": "null" @@ -935,10 +935,11 @@ "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" }, - "GasFraction": { + "GasPrice": { "type": "object", "required": [ "denominator", + "gas_adjustment_numerator", "numerator" ], "properties": { @@ -947,6 +948,12 @@ "format": "uint64", "minimum": 0.0 }, + "gas_adjustment_numerator": { + "description": "Note", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "numerator": { "type": "integer", "format": "uint64", diff --git a/packages/cw-croncat-core/schema/instantiate_msg.json b/packages/cw-croncat-core/schema/instantiate_msg.json index ac8a7dd7..6f6a6c98 100644 --- a/packages/cw-croncat-core/schema/instantiate_msg.json +++ b/packages/cw-croncat-core/schema/instantiate_msg.json @@ -44,7 +44,7 @@ "gas_fraction": { "anyOf": [ { - "$ref": "#/definitions/GasFraction" + "$ref": "#/definitions/GasPrice" }, { "type": "null" @@ -79,10 +79,11 @@ } }, "definitions": { - "GasFraction": { + "GasPrice": { "type": "object", "required": [ "denominator", + "gas_adjustment_numerator", "numerator" ], "properties": { @@ -91,6 +92,12 @@ "format": "uint64", "minimum": 0.0 }, + "gas_adjustment_numerator": { + "description": "Note", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "numerator": { "type": "integer", "format": "uint64", diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index 97d912e0..30a2a9c0 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -1,7 +1,7 @@ use crate::error::CoreError; use crate::traits::Intervals; use crate::types::{ - Action, AgentStatus, Boundary, BoundaryValidated, GasFraction, GenericBalance, Interval, Task, + Action, AgentStatus, Boundary, BoundaryValidated, GasPrice, GenericBalance, Interval, Task, Transform, }; use crate::types::{Agent, SlotType}; @@ -66,7 +66,7 @@ pub struct InstantiateMsg { pub gas_action_fee: Option, pub gas_query_fee: Option, pub gas_wasm_query_fee: Option, - pub gas_fraction: Option, + pub gas_fraction: Option, pub agent_nomination_duration: Option, } @@ -82,7 +82,7 @@ pub enum ExecuteMsg { gas_action_fee: Option, gas_query_fee: Option, gas_wasm_query_fee: Option, - gas_fraction: Option, + gas_fraction: Option, proxy_callback_gas: Option, min_tasks_per_agent: Option, agents_eject_threshold: Option, @@ -482,7 +482,7 @@ pub struct GetConfigResponse { pub cw_rules_addr: Addr, pub agent_fee: u64, - pub gas_fraction: GasFraction, + pub gas_fraction: GasPrice, pub gas_base_fee: u64, pub gas_action_fee: u64, pub proxy_callback_gas: u32, diff --git a/packages/cw-croncat-core/src/tests/msg.rs b/packages/cw-croncat-core/src/tests/msg.rs index 21cdacd1..3d7765bf 100644 --- a/packages/cw-croncat-core/src/tests/msg.rs +++ b/packages/cw-croncat-core/src/tests/msg.rs @@ -9,7 +9,7 @@ use crate::{ TaskRequest, TaskRequestBuilder, TaskResponse, }, types::{ - Action, Agent, AgentStatus, Boundary, BoundaryValidated, GasFraction, GenericBalance, + Action, Agent, AgentStatus, Boundary, BoundaryValidated, GasPrice, GenericBalance, Interval, SlotType, Task, }, }; @@ -65,9 +65,10 @@ fn everything_can_be_de_serialized() { agent_active_indices: vec![(SlotType::Block, 10, 5)], agents_eject_threshold: 5, agent_fee: 5, - gas_fraction: GasFraction { + gas_fraction: GasPrice { numerator: 1, denominator: 2, + gas_adjustment_numerator: 3, }, proxy_callback_gas: 3, slot_granularity_time: 60_000_000, diff --git a/packages/cw-croncat-core/src/types.rs b/packages/cw-croncat-core/src/types.rs index e521064d..22cb8801 100644 --- a/packages/cw-croncat-core/src/types.rs +++ b/packages/cw-croncat-core/src/types.rs @@ -635,12 +635,12 @@ impl Task { } } -/// Calculate the amount including agent_fee -pub fn calculate_required_amount(amount: u64, agent_fee: u64) -> Result { - amount +/// Calculate the gas amount including agent_fee +pub fn gas_amount_with_agent_fee(gas_amount: u64, agent_fee: u64) -> Result { + gas_amount .checked_mul(agent_fee) .and_then(|n| n.checked_div(100)) - .and_then(|n| n.checked_add(amount)) + .and_then(|n| n.checked_add(gas_amount)) .ok_or(CoreError::InvalidGas {}) } @@ -918,26 +918,30 @@ impl Intervals for Interval { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct GasFraction { +pub struct GasPrice { pub numerator: u64, pub denominator: u64, + /// Note + pub gas_adjustment_numerator: u64, } -impl GasFraction { +impl GasPrice { pub fn is_valid(&self) -> bool { - self.denominator != 0 && self.numerator != 0 + self.denominator != 0 && self.numerator != 0 && self.gas_adjustment_numerator != 0 } - pub fn calculate(&self, extra_num: u64, extra_denom: u64) -> Result { - let numerator = self - .numerator - .checked_mul(extra_num) + pub fn calculate(&self, gas_amount: u64) -> Result { + let gas_adjusted = gas_amount + .checked_mul(self.gas_adjustment_numerator) + .and_then(|g| g.checked_div(self.denominator)) .ok_or(CoreError::InvalidGas {})?; - let denominator = self - .denominator - .checked_mul(extra_denom) + + let price = gas_adjusted + .checked_mul(self.numerator) + .and_then(|g| g.checked_div(self.denominator)) .ok_or(CoreError::InvalidGas {})?; - Ok((numerator / denominator) as u128) + + Ok(price as u128) } } diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index 2969ef8f..d64a4174 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -6,7 +6,7 @@ import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; import { StdFee } from "@cosmjs/amino"; -import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasFraction, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; +import { Addr, Uint128, Timestamp, Uint64, SlotType, AgentStatus, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, WasmMsg, GovMsg, VoteOption, Boundary, Interval, CroncatQuery, Balance, NativeBalance, Status, ValueOrdering, ValueIndex, PathToValue, SmartQueries, Croncat, Agent, GenericBalance, Cw20CoinVerified, Coin, GetBalancesResponse, GetConfigResponse, GasPrice, GetAgentIdsResponse, AgentResponse, AgentTaskResponse, GetSlotHashesResponse, GetSlotIdsResponse, TaskResponse, ActionForEmpty, Empty, IbcTimeout, IbcTimeoutBlock, HasBalanceGte, CheckOwnerOfNft, CheckProposalStatus, GenericQuery, SmartQueryHead, SmartQuery, GetWalletBalancesResponse, Task, BoundaryValidated, Transform, TaskRequest, Cw20Coin, ExecuteMsg, Cw20ReceiveMsg, GetAgentResponse, GetAgentTasksResponse, GetTaskHashResponse, GetTaskResponse, GetTasksByOwnerResponse, GetTasksResponse, GetTasksWithQueriesResponse, TaskWithQueriesResponse, InstantiateMsg, QueryMsg, ValidateIntervalResponse } from "./CwCroncatCore.types"; export interface CwCroncatCoreReadOnlyInterface { contractAddress: string; getConfig: () => Promise; @@ -249,7 +249,7 @@ export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { agentsEjectThreshold?: number; gasActionFee?: Uint64; gasBaseFee?: Uint64; - gasFraction?: GasFraction; + gasFraction?: GasPrice; gasQueryFee?: Uint64; gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; @@ -370,7 +370,7 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC agentsEjectThreshold?: number; gasActionFee?: Uint64; gasBaseFee?: Uint64; - gasFraction?: GasFraction; + gasFraction?: GasPrice; gasQueryFee?: Uint64; gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index f8828c4a..70c2bb06 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -249,7 +249,7 @@ export interface GetConfigResponse { cw_rules_addr: Addr; gas_action_fee: number; gas_base_fee: number; - gas_fraction: GasFraction; + gas_fraction: GasPrice; limit: number; min_tasks_per_agent: number; native_denom: string; @@ -260,8 +260,9 @@ export interface GetConfigResponse { staked_balance: GenericBalance; [k: string]: unknown; } -export interface GasFraction { +export interface GasPrice { denominator: number; + gas_adjustment_numerator: number; numerator: number; [k: string]: unknown; } @@ -421,7 +422,7 @@ export type ExecuteMsg = { agents_eject_threshold?: number | null; gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; - gas_fraction?: GasFraction | null; + gas_fraction?: GasPrice | null; gas_query_fee?: Uint64 | null; gas_wasm_query_fee?: Uint64 | null; min_tasks_per_agent?: number | null; @@ -524,7 +525,7 @@ export interface InstantiateMsg { denom: string; gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; - gas_fraction?: GasFraction | null; + gas_fraction?: GasPrice | null; gas_query_fee?: Uint64 | null; gas_wasm_query_fee?: Uint64 | null; owner_id?: string | null; From fe9bb81e8ee92af4540203c854334ce0b1caf444 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 22:58:51 +0200 Subject: [PATCH 49/53] last few changes --- checksum | 2 +- ci/gas-benchmark/src/helpers.rs | 2 +- ci/gas-benchmark/src/main.rs | 2 +- contracts/cw-croncat/src/agent.rs | 3 +- contracts/cw-croncat/src/contract.rs | 3 +- contracts/cw-croncat/src/helpers.rs | 2 +- contracts/cw-croncat/src/owner.rs | 7 +- contracts/cw-croncat/src/state.rs | 2 +- contracts/cw-croncat/src/tasks.rs | 2 +- contracts/cw-croncat/src/tests/agent.rs | 8 +- contracts/cw-croncat/src/tests/balance.rs | 2 +- contracts/cw-croncat/src/tests/contract.rs | 4 +- contracts/cw-croncat/src/tests/helpers.rs | 4 +- contracts/cw-croncat/src/tests/manager.rs | 141 +++++++++++++++++- contracts/cw-croncat/src/tests/owner.rs | 12 +- contracts/cw-croncat/src/tests/tasks.rs | 4 +- packages/cw-croncat-core/schema/croncat.json | 4 +- .../cw-croncat-core/schema/execute_msg.json | 2 +- .../schema/instantiate_msg.json | 2 +- packages/cw-croncat-core/src/msg.rs | 6 +- packages/cw-croncat-core/src/tests/msg.rs | 2 +- .../cw-croncat-core/CwCroncatCore.client.ts | 10 +- .../cw-croncat-core/CwCroncatCore.types.ts | 6 +- 23 files changed, 178 insertions(+), 54 deletions(-) diff --git a/checksum b/checksum index b141667d..b95c31cf 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -4cfe570b1fe33bc51e385ba4c2b6256f242125bf54a0ec47f391fba22f7f3817 cw_croncat.wasm +5b3d3dcfb83ae291ee39c7c3f34626995036caa6deec74a08f08b163fbbb9ecc cw_croncat.wasm 348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm diff --git a/ci/gas-benchmark/src/helpers.rs b/ci/gas-benchmark/src/helpers.rs index f3f02f8e..e943fe4f 100644 --- a/ci/gas-benchmark/src/helpers.rs +++ b/ci/gas-benchmark/src/helpers.rs @@ -89,7 +89,7 @@ pub(crate) fn init_contracts( gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: None, gas_base_fee: None, }; diff --git a/ci/gas-benchmark/src/main.rs b/ci/gas-benchmark/src/main.rs index 61f9f683..3045a6a2 100644 --- a/ci/gas-benchmark/src/main.rs +++ b/ci/gas-benchmark/src/main.rs @@ -203,7 +203,7 @@ fn main() -> Result<()> { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, min_tasks_per_agent: None, agents_eject_threshold: None, diff --git a/contracts/cw-croncat/src/agent.rs b/contracts/cw-croncat/src/agent.rs index 7c2a7f4c..4283a4a3 100644 --- a/contracts/cw-croncat/src/agent.rs +++ b/contracts/cw-croncat/src/agent.rs @@ -140,10 +140,9 @@ impl<'a> CwCroncat<'a> { // REF: https://github.com/CosmWasm/cw-tokens/tree/main/contracts/cw20-escrow // Check if native token balance is sufficient for a few txns, in this case 4 txns - // TODO: Adjust gas & costs based on real usage cost let agent_wallet_balances = deps.querier.query_all_balances(account.clone())?; let gas_amount_with_agent_fee = gas_amount_with_agent_fee(c.gas_action_fee, c.agent_fee)?; - let unit_cost = c.gas_fraction.calculate(4 * gas_amount_with_agent_fee)?; + let unit_cost = c.gas_price.calculate(4 * gas_amount_with_agent_fee)?; if !has_coins( &agent_wallet_balances, &Coin::new(unit_cost, c.native_denom), diff --git a/contracts/cw-croncat/src/contract.rs b/contracts/cw-croncat/src/contract.rs index 5a3432f9..9de92081 100644 --- a/contracts/cw-croncat/src/contract.rs +++ b/contracts/cw-croncat/src/contract.rs @@ -63,7 +63,7 @@ impl<'a> CwCroncat<'a> { available_balance, staked_balance: GenericBalance::default(), agent_fee: 5, - gas_fraction: msg.gas_fraction.unwrap_or(GasPrice { + gas_price: msg.gas_price.unwrap_or(GasPrice { numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR, gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, @@ -126,7 +126,6 @@ impl<'a> CwCroncat<'a> { ) .add_attribute("native_denom", config.native_denom) .add_attribute("agent_fee", config.agent_fee.to_string()) - //.add_attribute("gas_fraction", config.gas_fraction.to_string()) .add_attribute("proxy_callback_gas", config.proxy_callback_gas.to_string()) .add_attribute( "slot_granularity_time", diff --git a/contracts/cw-croncat/src/helpers.rs b/contracts/cw-croncat/src/helpers.rs index 94073fc6..3d963207 100644 --- a/contracts/cw-croncat/src/helpers.rs +++ b/contracts/cw-croncat/src/helpers.rs @@ -236,7 +236,7 @@ pub(crate) fn proxy_call_submsgs_price( next_idx, )?; let gas_amount_with_agent_fee = gas_amount_with_agent_fee(gas_total, cfg.agent_fee)?; - let price_amount = cfg.gas_fraction.calculate(gas_amount_with_agent_fee)?; + let price_amount = cfg.gas_price.calculate(gas_amount_with_agent_fee)?; let price = coin(price_amount, cfg.native_denom); Ok((sub_msgs, price)) } diff --git a/contracts/cw-croncat/src/owner.rs b/contracts/cw-croncat/src/owner.rs index 7a72f4e1..5c5d28a5 100644 --- a/contracts/cw-croncat/src/owner.rs +++ b/contracts/cw-croncat/src/owner.rs @@ -23,7 +23,7 @@ impl<'a> CwCroncat<'a> { agents_eject_threshold: c.agents_eject_threshold, native_denom: c.native_denom, agent_fee: c.agent_fee, - gas_fraction: c.gas_fraction, + gas_price: c.gas_price, proxy_callback_gas: c.proxy_callback_gas, slot_granularity_time: c.slot_granularity_time, cw_rules_addr: c.cw_rules_addr, @@ -84,7 +84,7 @@ impl<'a> CwCroncat<'a> { gas_action_fee, gas_query_fee, gas_wasm_query_fee, - gas_fraction, + gas_price, proxy_callback_gas, min_tasks_per_agent, agents_eject_threshold, @@ -112,7 +112,7 @@ impl<'a> CwCroncat<'a> { agent_nomination_duration: old_config.agent_nomination_duration, cw_rules_addr: old_config.cw_rules_addr, agent_fee: agent_fee.unwrap_or(old_config.agent_fee), - gas_fraction: gas_fraction.unwrap_or(old_config.gas_fraction), + gas_price: gas_price.unwrap_or(old_config.gas_price), gas_base_fee: gas_base_fee .map(Into::into) .unwrap_or(old_config.gas_base_fee), @@ -165,7 +165,6 @@ impl<'a> CwCroncat<'a> { ) .add_attribute("native_denom", c.native_denom) .add_attribute("agent_fee", c.agent_fee.to_string()) - //.add_attribute("gas_price", c.gas_fraction.to_string()) .add_attribute("proxy_callback_gas", c.proxy_callback_gas.to_string()) .add_attribute("slot_granularity_time", c.slot_granularity_time.to_string())) } diff --git a/contracts/cw-croncat/src/state.rs b/contracts/cw-croncat/src/state.rs index dffaa8a3..c087f08d 100644 --- a/contracts/cw-croncat/src/state.rs +++ b/contracts/cw-croncat/src/state.rs @@ -38,7 +38,7 @@ pub struct Config { // Economics pub agent_fee: u64, - pub gas_fraction: GasPrice, + pub gas_price: GasPrice, pub gas_base_fee: u64, pub gas_action_fee: u64, pub gas_query_fee: u64, diff --git a/contracts/cw-croncat/src/tasks.rs b/contracts/cw-croncat/src/tasks.rs index 85e72e20..2b6dc969 100644 --- a/contracts/cw-croncat/src/tasks.rs +++ b/contracts/cw-croncat/src/tasks.rs @@ -266,7 +266,7 @@ impl<'a> CwCroncat<'a> { cfg.gas_wasm_query_fee, )?; let gas_amount_with_agent_fee = gas_amount_with_agent_fee(gas_amount, cfg.agent_fee)?; - let price = cfg.gas_fraction.calculate(gas_amount_with_agent_fee)?; + let price = cfg.gas_price.calculate(gas_amount_with_agent_fee)?; amount_for_one_task .native .find_checked_add(&coin(price, &cfg.native_denom))?; diff --git a/contracts/cw-croncat/src/tests/agent.rs b/contracts/cw-croncat/src/tests/agent.rs index c2b01efd..bd20a7b4 100644 --- a/contracts/cw-croncat/src/tests/agent.rs +++ b/contracts/cw-croncat/src/tests/agent.rs @@ -258,7 +258,7 @@ fn test_instantiate_sets_balance() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: None, gas_base_fee: None, }, @@ -311,7 +311,7 @@ fn register_agent_fail_cases() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, gas_base_fee: None, gas_action_fee: None, @@ -345,7 +345,7 @@ fn register_agent_fail_cases() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: Some(GasPrice { + gas_price: Some(GasPrice { numerator: 1, denominator: 1, gas_adjustment_numerator: 1, @@ -760,7 +760,7 @@ fn test_get_agent_status() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), gas_base_fee: None, diff --git a/contracts/cw-croncat/src/tests/balance.rs b/contracts/cw-croncat/src/tests/balance.rs index d316cf6d..83816c3f 100644 --- a/contracts/cw-croncat/src/tests/balance.rs +++ b/contracts/cw-croncat/src/tests/balance.rs @@ -24,7 +24,7 @@ fn mock_config() -> Config { available_balance: GenericBalance::default(), staked_balance: GenericBalance::default(), agent_fee: 5, - gas_fraction: GasPrice { + gas_price: GasPrice { numerator: GAS_NUMERATOR_DEFAULT, denominator: GAS_DENOMINATOR, gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, diff --git a/contracts/cw-croncat/src/tests/contract.rs b/contracts/cw-croncat/src/tests/contract.rs index 27b6196e..6ff7be21 100644 --- a/contracts/cw-croncat/src/tests/contract.rs +++ b/contracts/cw-croncat/src/tests/contract.rs @@ -27,7 +27,7 @@ fn configure() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), gas_base_fee: None, @@ -62,7 +62,7 @@ fn configure() { denominator: GAS_DENOMINATOR, gas_adjustment_numerator: GAS_ADJUSTMENT_NUMERATOR_DEFAULT, }, - value.gas_fraction + value.gas_price ); assert_eq!(3, value.proxy_callback_gas); assert_eq!(10_000_000_000, value.slot_granularity_time); diff --git a/contracts/cw-croncat/src/tests/helpers.rs b/contracts/cw-croncat/src/tests/helpers.rs index fd6db476..17f5f126 100644 --- a/contracts/cw-croncat/src/tests/helpers.rs +++ b/contracts/cw-croncat/src/tests/helpers.rs @@ -40,7 +40,7 @@ pub fn mock_init(store: &CwCroncat, deps: DepsMut) -> Result (App, CwTemplateContract, Addr) { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: None, }; let cw_template_contract_addr = app diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index fa7f5fd9..316530ff 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -13,10 +13,10 @@ use cosmwasm_std::{ use cw20::Cw20Coin; use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ - AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, - TaskResponse, TaskWithQueriesResponse, + AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, GetConfigResponse, QueryMsg, + TaskRequest, TaskResponse, TaskWithQueriesResponse, }; -use cw_croncat_core::types::{Action, Boundary, Interval, Transform}; +use cw_croncat_core::types::{Action, Boundary, GasPrice, Interval, Transform}; use cw_multi_test::Executor; use cw_rules_core::types::{CroncatQuery, HasBalanceGte}; use cwd_core::state::ProposalModule; @@ -102,7 +102,7 @@ fn proxy_call_fail_cases() -> StdResult<()> { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, @@ -170,7 +170,7 @@ fn proxy_call_fail_cases() -> StdResult<()> { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, @@ -1894,7 +1894,7 @@ fn tick() { proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, - gas_fraction: None, + gas_price: None, }; app.execute_contract( Addr::unchecked(ADMIN), @@ -2088,7 +2088,7 @@ fn tick_task() -> StdResult<()> { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, }; app.execute_contract( Addr::unchecked(ADMIN), @@ -3499,3 +3499,130 @@ fn queries_fees_negative() { }) ); } + +#[test] +fn gas_fees_configurable() { + let (mut app, cw_template_contract, _) = proper_instantiate(); + let contract_addr = cw_template_contract.addr(); + + // quick agent register + let msg = ExecuteMsg::RegisterAgent { + payable_account_id: Some(AGENT_BENEFICIARY.to_string()), + }; + app.execute_contract(Addr::unchecked(AGENT0), contract_addr.clone(), &msg, &[]) + .unwrap(); + + let mut initial_config: GetConfigResponse = app + .wrap() + .query_wasm_smart(contract_addr.clone(), &QueryMsg::GetConfig {}) + .unwrap(); + let modified_gas_price = GasPrice { + numerator: 10, + denominator: 1000, + gas_adjustment_numerator: 120, + }; + let update_gas_price_msg = ExecuteMsg::UpdateSettings { + owner_id: None, + slot_granularity_time: None, + paused: None, + agent_fee: None, + gas_base_fee: None, + gas_action_fee: None, + gas_query_fee: None, + gas_wasm_query_fee: None, + gas_price: Some(modified_gas_price.clone()), + proxy_callback_gas: None, + min_tasks_per_agent: None, + agents_eject_threshold: None, + }; + app.execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &update_gas_price_msg, + &[], + ) + .unwrap(); + let new_config: GetConfigResponse = app + .wrap() + .query_wasm_smart(contract_addr.clone(), &QueryMsg::GetConfig {}) + .unwrap(); + assert_ne!(initial_config, new_config); + initial_config.gas_price = modified_gas_price.clone(); + assert_eq!(initial_config, new_config); + + app.update_block(add_little_time); + let transfer_to_bob = BankMsg::Send { + to_address: "bob".to_string(), + amount: coins(1, NATIVE_DENOM), + }; + let create_task_msg = ExecuteMsg::CreateTask { + task: TaskRequest { + interval: Interval::Once, + boundary: None, + stop_on_fail: false, + actions: vec![Action { + msg: transfer_to_bob.clone().into(), + gas_limit: None, + }], + queries: None, + transforms: None, + cw20_coins: vec![], + }, + }; + + // Base + action + calling rules + non-wasm query + let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE; + let agent_fee = gas_needed * 5 / 100; + let gas_to_amount = (gas_needed + agent_fee) * modified_gas_price.gas_adjustment_numerator + / modified_gas_price.denominator + * modified_gas_price.numerator + / modified_gas_price.denominator; + let attached_balance = (gas_to_amount + 1) as u128; + + // making sure new config values is applied + // one off coin + let err: ContractError = app + .execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance - 1, NATIVE_DENOM), + ) + .unwrap_err() + .downcast() + .unwrap(); + assert_eq!( + err, + ContractError::CoreError(CoreError::NotEnoughNative { + denom: NATIVE_DENOM.to_owned(), + lack: Uint128::new(1) + }) + ); + + // should work + app.execute_contract( + Addr::unchecked(ADMIN), + contract_addr.clone(), + &create_task_msg, + &coins(attached_balance, NATIVE_DENOM), + ) + .unwrap(); + app.update_block(add_little_time); + + // execute proxy_call + let proxy_call_msg = ExecuteMsg::ProxyCall { task_hash: None }; + let res = app + .execute_contract( + Addr::unchecked(AGENT0), + contract_addr.clone(), + &proxy_call_msg, + &vec![], + ) + .unwrap(); + print!("{:#?}", res); + + assert!(res.events.iter().any(|ev| ev + .attributes + .iter() + .any(|attr| attr.key == "method" && attr.value == "remove_task"))); +} diff --git a/contracts/cw-croncat/src/tests/owner.rs b/contracts/cw-croncat/src/tests/owner.rs index cb9f9fdc..80e5721f 100644 --- a/contracts/cw-croncat/src/tests/owner.rs +++ b/contracts/cw-croncat/src/tests/owner.rs @@ -21,7 +21,7 @@ fn update_settings() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: Some(360), }; let info = MessageInfo { @@ -41,7 +41,7 @@ fn update_settings() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, @@ -105,7 +105,7 @@ fn move_balances_auth_checks() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), gas_base_fee: None, @@ -122,7 +122,7 @@ fn move_balances_auth_checks() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, @@ -178,7 +178,7 @@ fn move_balances_native() { gas_action_fee: None, gas_query_fee: None, gas_wasm_query_fee: None, - gas_fraction: None, + gas_price: None, agent_nomination_duration: Some(360), cw_rules_addr: "todo".to_string(), gas_base_fee: None, @@ -195,7 +195,7 @@ fn move_balances_native() { agent_fee: None, min_tasks_per_agent: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, gas_base_fee: None, diff --git a/contracts/cw-croncat/src/tests/tasks.rs b/contracts/cw-croncat/src/tests/tasks.rs index 76265e6f..a610d6ea 100644 --- a/contracts/cw-croncat/src/tests/tasks.rs +++ b/contracts/cw-croncat/src/tests/tasks.rs @@ -359,7 +359,7 @@ fn check_task_create_fail_cases() -> StdResult<()> { // treasury_id: None, agent_fee: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, min_tasks_per_agent: None, @@ -399,7 +399,7 @@ fn check_task_create_fail_cases() -> StdResult<()> { // treasury_id: None, agent_fee: None, agents_eject_threshold: None, - gas_fraction: None, + gas_price: None, proxy_callback_gas: None, slot_granularity_time: None, min_tasks_per_agent: None, diff --git a/packages/cw-croncat-core/schema/croncat.json b/packages/cw-croncat-core/schema/croncat.json index 4dc95fd3..da1ff1e4 100644 --- a/packages/cw-croncat-core/schema/croncat.json +++ b/packages/cw-croncat-core/schema/croncat.json @@ -959,7 +959,7 @@ "cw_rules_addr", "gas_action_fee", "gas_base_fee", - "gas_fraction", + "gas_price", "limit", "min_tasks_per_agent", "native_denom", @@ -1030,7 +1030,7 @@ "format": "uint64", "minimum": 0.0 }, - "gas_fraction": { + "gas_price": { "$ref": "#/definitions/GasPrice" }, "limit": { diff --git a/packages/cw-croncat-core/schema/execute_msg.json b/packages/cw-croncat-core/schema/execute_msg.json index 93d31518..a582f8c3 100644 --- a/packages/cw-croncat-core/schema/execute_msg.json +++ b/packages/cw-croncat-core/schema/execute_msg.json @@ -47,7 +47,7 @@ } ] }, - "gas_fraction": { + "gas_price": { "anyOf": [ { "$ref": "#/definitions/GasPrice" diff --git a/packages/cw-croncat-core/schema/instantiate_msg.json b/packages/cw-croncat-core/schema/instantiate_msg.json index 6f6a6c98..ed26bab2 100644 --- a/packages/cw-croncat-core/schema/instantiate_msg.json +++ b/packages/cw-croncat-core/schema/instantiate_msg.json @@ -41,7 +41,7 @@ } ] }, - "gas_fraction": { + "gas_price": { "anyOf": [ { "$ref": "#/definitions/GasPrice" diff --git a/packages/cw-croncat-core/src/msg.rs b/packages/cw-croncat-core/src/msg.rs index 30a2a9c0..493154bc 100644 --- a/packages/cw-croncat-core/src/msg.rs +++ b/packages/cw-croncat-core/src/msg.rs @@ -66,7 +66,7 @@ pub struct InstantiateMsg { pub gas_action_fee: Option, pub gas_query_fee: Option, pub gas_wasm_query_fee: Option, - pub gas_fraction: Option, + pub gas_price: Option, pub agent_nomination_duration: Option, } @@ -82,7 +82,7 @@ pub enum ExecuteMsg { gas_action_fee: Option, gas_query_fee: Option, gas_wasm_query_fee: Option, - gas_fraction: Option, + gas_price: Option, proxy_callback_gas: Option, min_tasks_per_agent: Option, agents_eject_threshold: Option, @@ -482,7 +482,7 @@ pub struct GetConfigResponse { pub cw_rules_addr: Addr, pub agent_fee: u64, - pub gas_fraction: GasPrice, + pub gas_price: GasPrice, pub gas_base_fee: u64, pub gas_action_fee: u64, pub proxy_callback_gas: u32, diff --git a/packages/cw-croncat-core/src/tests/msg.rs b/packages/cw-croncat-core/src/tests/msg.rs index 3d7765bf..441f3e69 100644 --- a/packages/cw-croncat-core/src/tests/msg.rs +++ b/packages/cw-croncat-core/src/tests/msg.rs @@ -65,7 +65,7 @@ fn everything_can_be_de_serialized() { agent_active_indices: vec![(SlotType::Block, 10, 5)], agents_eject_threshold: 5, agent_fee: 5, - gas_fraction: GasPrice { + gas_price: GasPrice { numerator: 1, denominator: 2, gas_adjustment_numerator: 3, diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts index d64a4174..63571744 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.client.ts @@ -236,7 +236,7 @@ export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { agentsEjectThreshold, gasActionFee, gasBaseFee, - gasFraction, + gasPrice, gasQueryFee, gasWasmQueryFee, minTasksPerAgent, @@ -249,7 +249,7 @@ export interface CwCroncatCoreInterface extends CwCroncatCoreReadOnlyInterface { agentsEjectThreshold?: number; gasActionFee?: Uint64; gasBaseFee?: Uint64; - gasFraction?: GasPrice; + gasPrice?: GasPrice; gasQueryFee?: Uint64; gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; @@ -357,7 +357,7 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC agentsEjectThreshold, gasActionFee, gasBaseFee, - gasFraction, + gasPrice, gasQueryFee, gasWasmQueryFee, minTasksPerAgent, @@ -370,7 +370,7 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC agentsEjectThreshold?: number; gasActionFee?: Uint64; gasBaseFee?: Uint64; - gasFraction?: GasPrice; + gasPrice?: GasPrice; gasQueryFee?: Uint64; gasWasmQueryFee?: Uint64; minTasksPerAgent?: number; @@ -385,7 +385,7 @@ export class CwCroncatCoreClient extends CwCroncatCoreQueryClient implements CwC agents_eject_threshold: agentsEjectThreshold, gas_action_fee: gasActionFee, gas_base_fee: gasBaseFee, - gas_fraction: gasFraction, + gas_price: gasPrice, gas_query_fee: gasQueryFee, gas_wasm_query_fee: gasWasmQueryFee, min_tasks_per_agent: minTasksPerAgent, diff --git a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts index 70c2bb06..0fc4fcec 100644 --- a/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts +++ b/typescript/contracts/cw-croncat-core/CwCroncatCore.types.ts @@ -249,7 +249,7 @@ export interface GetConfigResponse { cw_rules_addr: Addr; gas_action_fee: number; gas_base_fee: number; - gas_fraction: GasPrice; + gas_price: GasPrice; limit: number; min_tasks_per_agent: number; native_denom: string; @@ -422,7 +422,7 @@ export type ExecuteMsg = { agents_eject_threshold?: number | null; gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; - gas_fraction?: GasPrice | null; + gas_price?: GasPrice | null; gas_query_fee?: Uint64 | null; gas_wasm_query_fee?: Uint64 | null; min_tasks_per_agent?: number | null; @@ -525,7 +525,7 @@ export interface InstantiateMsg { denom: string; gas_action_fee?: Uint64 | null; gas_base_fee?: Uint64 | null; - gas_fraction?: GasPrice | null; + gas_price?: GasPrice | null; gas_query_fee?: Uint64 | null; gas_wasm_query_fee?: Uint64 | null; owner_id?: string | null; From c2402de9ecdb1e51778e021195bec65facf3b1f8 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 21 Dec 2022 23:02:40 +0200 Subject: [PATCH 50/53] small justfile fix --- justfile | 2 +- .../build/contracts/cw-croncat-core/CwCroncatCore.client.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/justfile b/justfile index 89074adf..3339d511 100644 --- a/justfile +++ b/justfile @@ -25,8 +25,8 @@ gen: #!/usr/bin/env bash cd typescript yarn --cwd ./typescript build - yarn --cwd ./typescript install --frozen-lockfile yarn --cwd ./typescript codegen + yarn --cwd ./typescript install --frozen-lockfile juno-local: docker kill cosmwasm || true docker volume rm -f junod_data diff --git a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js index 59d0ebd6..461fb230 100644 --- a/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js +++ b/typescript/build/contracts/cw-croncat-core/CwCroncatCore.client.js @@ -131,14 +131,14 @@ exports.CwCroncatCoreQueryClient = CwCroncatCoreQueryClient; class CwCroncatCoreClient extends CwCroncatCoreQueryClient { constructor(client, sender, contractAddress) { super(client, contractAddress); - this.updateSettings = ({ agentFee, agentsEjectThreshold, gasActionFee, gasBaseFee, gasFraction, gasQueryFee, gasWasmQueryFee, minTasksPerAgent, ownerId, paused, proxyCallbackGas, slotGranularityTime }, fee = "auto", memo, funds) => __awaiter(this, void 0, void 0, function* () { + this.updateSettings = ({ agentFee, agentsEjectThreshold, gasActionFee, gasBaseFee, gasPrice, gasQueryFee, gasWasmQueryFee, minTasksPerAgent, ownerId, paused, proxyCallbackGas, slotGranularityTime }, fee = "auto", memo, funds) => __awaiter(this, void 0, void 0, function* () { return yield this.client.execute(this.sender, this.contractAddress, { update_settings: { agent_fee: agentFee, agents_eject_threshold: agentsEjectThreshold, gas_action_fee: gasActionFee, gas_base_fee: gasBaseFee, - gas_fraction: gasFraction, + gas_price: gasPrice, gas_query_fee: gasQueryFee, gas_wasm_query_fee: gasWasmQueryFee, min_tasks_per_agent: minTasksPerAgent, From 14c81bbdad1d79bd1504621e660bf52bb3b565aa Mon Sep 17 00:00:00 2001 From: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:12:52 +0200 Subject: [PATCH 51/53] small typo in tests --- contracts/cw-croncat/src/tests/manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 316530ff..e454320a 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -3570,7 +3570,7 @@ fn gas_fees_configurable() { }, }; - // Base + action + calling rules + non-wasm query + // Base + action let gas_needed = GAS_BASE_FEE + GAS_ACTION_FEE; let agent_fee = gas_needed * 5 / 100; let gas_to_amount = (gas_needed + agent_fee) * modified_gas_price.gas_adjustment_numerator From fb78dbb7f739c659b41fd7ec135cd2e32b384580 Mon Sep 17 00:00:00 2001 From: Deveus Date: Thu, 22 Dec 2022 01:23:00 +0200 Subject: [PATCH 52/53] fix: hooks --- .rusty-hook.toml | 3 +-- packages/cw-croncat-core/src/tests/types.rs | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index 6b5b6d2b..582f635e 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,6 +1,5 @@ [hooks] -pre-commit = "just lint test" -pre-push = "just all" +pre-commit = "just lint" [logging] verbose = true diff --git a/packages/cw-croncat-core/src/tests/types.rs b/packages/cw-croncat-core/src/tests/types.rs index cb13ea35..b792be09 100644 --- a/packages/cw-croncat-core/src/tests/types.rs +++ b/packages/cw-croncat-core/src/tests/types.rs @@ -353,6 +353,8 @@ fn is_valid_empty_actions() { &Addr::unchecked("bob"), 5, 5, + 5, + 5, ) .unwrap_err(), CoreError::InvalidAction {} From faaeb1bf379fa6cb148dfd3188109e0010b7a15d Mon Sep 17 00:00:00 2001 From: Deveus Date: Thu, 22 Dec 2022 01:58:03 +0200 Subject: [PATCH 53/53] fix: checksum --- checksum | 4 ++-- contracts/cw-croncat/src/tests/manager.rs | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/checksum b/checksum index 97137749..873e6b32 100644 --- a/checksum +++ b/checksum @@ -1,2 +1,2 @@ -853004395db1861f1f337925a76e31b9f8ed5fe158b807c647240ea71876e875 cw_croncat.wasm -de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm +f02ba448d956da4cc508cafdf14dd010e3ac0d37f5d40fa3116d27093d3a6ce1 cw_croncat.wasm +348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm diff --git a/contracts/cw-croncat/src/tests/manager.rs b/contracts/cw-croncat/src/tests/manager.rs index 5ea8d706..faae7d3f 100644 --- a/contracts/cw-croncat/src/tests/manager.rs +++ b/contracts/cw-croncat/src/tests/manager.rs @@ -1,7 +1,8 @@ use crate::contract::{ GAS_ACTION_FEE, GAS_ADJUSTMENT_NUMERATOR_DEFAULT, GAS_BASE_FEE, GAS_DENOMINATOR, - GAS_NUMERATOR_DEFAULT, GAS_QUERY_FEE, GAS_WASM_QUERY_FEE, + GAS_NUMERATOR_DEFAULT, }; + use crate::tests::helpers::{ add_1000_blocks, add_little_time, add_one_duration_of_time, cw4_template, proper_instantiate, AGENT1, AGENT2, AGENT3, @@ -13,10 +14,10 @@ use cosmwasm_std::{ use cw20::Cw20Coin; use cw_croncat_core::error::CoreError; use cw_croncat_core::msg::{ - AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, GetConfigResponse, QueryMsg, - TaskRequest, TaskResponse, TaskWithQueriesResponse, + AgentResponse, AgentTaskResponse, ExecuteMsg, GetAgentIdsResponse, QueryMsg, TaskRequest, + TaskResponse, TaskWithQueriesResponse, }; -use cw_croncat_core::types::{Action, Boundary, GasPrice, Interval, Transform}; +use cw_croncat_core::types::{Action, Boundary, Interval, Transform}; use cw_multi_test::Executor; use cw_rules_core::types::{CroncatQuery, HasBalanceGte}; use cwd_core::state::ProposalModule; @@ -3082,8 +3083,8 @@ fn empty_actions_not_allowed() { }, }; - let total_gas = GAS_BASE_FEE_JUNO + GAS_ACTION_FEE_JUNO; - let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_DENOMINATOR_DEFAULT_JUNO; + let total_gas = GAS_BASE_FEE + GAS_ACTION_FEE; + let attach_per_action = (total_gas + (total_gas * 5 / 100)) / GAS_NUMERATOR_DEFAULT; let amount_for_three = (attach_per_action) as u128; let res: ContractError = app