Skip to content

Commit

Permalink
Merge branch 'main' into dao-proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
nlipartiia-hacken committed Dec 22, 2022
2 parents b0d6025 + eb19b3e commit 45151f6
Show file tree
Hide file tree
Showing 49 changed files with 1,007 additions and 907 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/Basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@ jobs:
with:
command: clippy
args: -- -D warnings


- name: Set latest just version
run: echo "JUST_VERSION=$(cargo search just -q | sed -n -e '/^just[[:space:]]/p' | cut -d '"' -f 2)" >> $GITHUB_ENV

- name: Get cached just
uses: actions/cache@v3
with:
path: ~/.cargo/bin/just
key: ${{ runner.os }}-just-${{ env.JUST_VERSION }}

- name: Install just
run: cargo install just || true

- name: Generate Schema
run: ./scripts/schema.sh
run: just schema

- name: Show Schema changes
run: git status --porcelain
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checksum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: just optimize

- name: Generate Checksum
run: ./scripts/update-checksum.sh
run: just checksum
shell: bash

- name: Show checksum changes
Expand Down
5 changes: 5 additions & 0 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hooks]
pre-commit = "just lint"

[logging]
verbose = true
67 changes: 62 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e841b8f67c8209ade26674edd432bb1d7dc9dcaa470651ebf379c62d41c294c8 cw_croncat.wasm
de2d1a0c648e41760020dd261f818da085c358240059acf85128f60eb0e05db2 cw_rules.wasm
fc76a0e370c9e947d6e33d018585137d566f32d1a1fb06b1b49e695e5984a57e cw_croncat.wasm
348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm
40 changes: 33 additions & 7 deletions ci/gas-benchmark/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,39 @@ 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_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;
use cw_rules_core::{msg::QueryResponse, types::CroncatQuery};

const fn add_agent_fee(num: u64) -> u64 {
num + (num * 5 / 100)
}

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)
})
}

fn min_gas_for_queries(queries: Option<&Vec<CroncatQuery>>) -> 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,
Expand Down Expand Up @@ -71,7 +87,9 @@ pub(crate) fn init_contracts(
cw_rules_addr: rules_res.address,
owner_id: Some(admin_addr.to_owned()),
gas_action_fee: None,
gas_fraction: None,
gas_query_fee: None,
gas_wasm_query_fee: None,
gas_price: None,
agent_nomination_duration: None,
gas_base_fee: None,
};
Expand Down Expand Up @@ -175,8 +193,16 @@ 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)
+ min_gas_for_queries(task.queries.as_ref());
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)?;
}
Expand Down
4 changes: 3 additions & 1 deletion ci/gas-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ fn main() -> Result<()> {
agent_fee: None,
gas_base_fee: None,
gas_action_fee: None,
gas_fraction: None,
gas_query_fee: None,
gas_wasm_query_fee: None,
gas_price: None,
proxy_callback_gas: None,
min_tasks_per_agent: None,
agents_eject_threshold: None,
Expand Down
4 changes: 2 additions & 2 deletions ci/local_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions contracts/cw-croncat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 3 additions & 4 deletions contracts/cw-croncat/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_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_price.calculate(4 * gas_amount_with_agent_fee)?;
if !has_coins(
&agent_wallet_balances,
&Coin::new(unit_cost, c.native_denom),
Expand Down
Loading

0 comments on commit 45151f6

Please sign in to comment.