From 8a8ff7e71a61ed31cbaace57fc44318f3fec3fc2 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 6 Nov 2023 18:17:46 +0100 Subject: [PATCH] fixes --- contracts/warp-controller/src/execute/job.rs | 6 ++-- contracts/warp-controller/src/migrate/job.rs | 2 ++ .../warp-controller/src/reply/account.rs | 2 +- contracts/warp-controller/src/reply/job.rs | 28 +++++++++++++------ contracts/warp-controller/src/state.rs | 3 ++ .../warp-job-account-tracker/src/contract.rs | 2 +- packages/controller/src/job.rs | 1 + 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/contracts/warp-controller/src/execute/job.rs b/contracts/warp-controller/src/execute/job.rs index f3546a11..7d100d4e 100644 --- a/contracts/warp-controller/src/execute/job.rs +++ b/contracts/warp-controller/src/execute/job.rs @@ -121,6 +121,7 @@ pub fn create_job( description: data.description, labels: data.labels, assets_to_withdraw: data.assets_to_withdraw.unwrap_or(vec![]), + duration_days: data.duration_days, }, )?; @@ -162,7 +163,7 @@ pub fn create_job( if !native_funds_minus_reward_and_fee.is_empty() { // Fund account in native coins msgs.push(build_transfer_native_funds_msg( - available_account_addr.clone().to_string(), + available_account_addr.to_string(), native_funds_minus_reward_and_fee, )) } @@ -333,8 +334,7 @@ pub fn update_job( let job = JobQueue::update(&mut deps, env.clone(), data)?; - // TODO: add creation fee - let fee = added_reward * Uint128::from(config.creation_fee_percentage) / Uint128::new(100); + let fee = compute_burn_fee(added_reward, &config); if !added_reward.is_zero() && fee.is_zero() { return Err(ContractError::RewardTooSmall {}); diff --git a/contracts/warp-controller/src/migrate/job.rs b/contracts/warp-controller/src/migrate/job.rs index 6eb66967..ffc9ed80 100644 --- a/contracts/warp-controller/src/migrate/job.rs +++ b/contracts/warp-controller/src/migrate/job.rs @@ -100,6 +100,7 @@ pub fn migrate_pending_jobs( requeue_on_evict: old_job.requeue_on_evict, reward: old_job.reward, assets_to_withdraw: old_job.assets_to_withdraw, + duration_days: Uint128::from(30u128), }, )?; } @@ -167,6 +168,7 @@ pub fn migrate_finished_jobs( requeue_on_evict: old_job.requeue_on_evict, reward: old_job.reward, assets_to_withdraw: old_job.assets_to_withdraw, + duration_days: Uint128::from(30u128), }, )?; } diff --git a/contracts/warp-controller/src/reply/account.rs b/contracts/warp-controller/src/reply/account.rs index e5e8634f..d5856db2 100644 --- a/contracts/warp-controller/src/reply/account.rs +++ b/contracts/warp-controller/src/reply/account.rs @@ -96,7 +96,7 @@ pub fn create_job_account_and_job( if !native_funds.is_empty() { // Fund account in native coins msgs.push(build_transfer_native_funds_msg( - job_account_addr.clone().to_string(), + job_account_addr.to_string(), native_funds.clone(), )) } diff --git a/contracts/warp-controller/src/reply/job.rs b/contracts/warp-controller/src/reply/job.rs index 1c324479..03dd0ad9 100644 --- a/contracts/warp-controller/src/reply/job.rs +++ b/contracts/warp-controller/src/reply/job.rs @@ -5,6 +5,7 @@ use cosmwasm_std::{ use crate::{ error::map_contract_error, + execute::fee::{compute_burn_fee, compute_creation_fee, compute_maintenance_fee}, state::{JobQueue, LEGACY_ACCOUNTS, STATE}, util::{ legacy_account::is_legacy_account, @@ -75,9 +76,13 @@ pub fn execute_job( let mut new_job_attrs = vec![]; let new_job_id = state.current_job_id; - let fee = - finished_job.reward * Uint128::from(config.creation_fee_percentage) / Uint128::new(100); - let fee_plus_reward = fee + finished_job.reward; + let creation_fee = compute_creation_fee(Uint128::from(state.q), &config); + let maintenance_fee = compute_maintenance_fee(finished_job.duration_days, &config); + let burn_fee = compute_burn_fee(finished_job.reward, &config); + + let total_fees = creation_fee + maintenance_fee + burn_fee; + + let reward_plus_fee = finished_job.reward + total_fees; let legacy_account = LEGACY_ACCOUNTS().may_load(deps.storage, finished_job.owner.clone())?; let job_account_addr = finished_job.account.clone(); @@ -94,7 +99,7 @@ pub fn execute_job( let mut recurring_job_created = false; if finished_job.recurring { - if job_account_amount < fee_plus_reward { + if job_account_amount < reward_plus_fee { new_job_attrs.push(Attribute::new("action", "recur_job")); new_job_attrs.push(Attribute::new("creation_status", "failed_insufficient_fee")); } else if !(finished_job.status == JobStatus::Executed @@ -181,16 +186,17 @@ pub fn execute_job( recurring: finished_job.recurring, reward: finished_job.reward, assets_to_withdraw: finished_job.assets_to_withdraw.clone(), + duration_days: finished_job.duration_days, }, )?; msgs.push(build_account_execute_generic_msgs( - job_account_addr.clone().to_string(), + job_account_addr.to_string(), vec![ // Job owner's warp account sends fee to fee collector build_transfer_native_funds_msg( config.fee_collector.to_string(), - vec![Coin::new(fee.u128(), config.fee_denom.clone())], + vec![Coin::new(total_fees.u128(), config.fee_denom.clone())], ), // Job owner's warp account sends reward to controller build_transfer_native_funds_msg( @@ -213,7 +219,13 @@ pub fn execute_job( serde_json_wasm::to_string(&new_job.executions)?, )); new_job_attrs.push(Attribute::new("job_reward", new_job.reward)); - new_job_attrs.push(Attribute::new("job_creation_fee", fee)); + new_job_attrs.push(Attribute::new("job_creation_fee", creation_fee.to_string())); + new_job_attrs.push(Attribute::new( + "job_maintenance_fee", + maintenance_fee.to_string(), + )); + new_job_attrs.push(Attribute::new("job_burn_fee", burn_fee.to_string())); + new_job_attrs.push(Attribute::new("job_total_fees", total_fees.to_string())); new_job_attrs.push(Attribute::new( "job_last_updated_time", new_job.last_update_time, @@ -237,7 +249,7 @@ pub fn execute_job( // No new job created, account has been free in execute_job, no need to free here again // Job owner withdraw all assets that are listed from warp account to itself msgs.push(build_account_withdraw_assets_msg( - job_account_addr.clone().to_string(), + job_account_addr.to_string(), finished_job.assets_to_withdraw, )); } diff --git a/contracts/warp-controller/src/state.rs b/contracts/warp-controller/src/state.rs index 279e4c22..0e94473e 100644 --- a/contracts/warp-controller/src/state.rs +++ b/contracts/warp-controller/src/state.rs @@ -128,6 +128,7 @@ impl JobQueue { requeue_on_evict: job.requeue_on_evict, reward: job.reward, assets_to_withdraw: job.assets_to_withdraw, + duration_days: job.duration_days, }), }) } @@ -159,6 +160,7 @@ impl JobQueue { requeue_on_evict: job.requeue_on_evict, reward: job.reward + added_reward, assets_to_withdraw: job.assets_to_withdraw, + duration_days: job.duration_days, }), }) } @@ -192,6 +194,7 @@ impl JobQueue { requeue_on_evict: job.requeue_on_evict, reward: job.reward, assets_to_withdraw: job.assets_to_withdraw, + duration_days: job.duration_days, }; FINISHED_JOBS().update(deps.storage, job_id, |j| match j { diff --git a/contracts/warp-job-account-tracker/src/contract.rs b/contracts/warp-job-account-tracker/src/contract.rs index 4e3e73df..2563b660 100644 --- a/contracts/warp-job-account-tracker/src/contract.rs +++ b/contracts/warp-job-account-tracker/src/contract.rs @@ -27,7 +27,7 @@ pub fn instantiate( Ok(Response::new() .add_attribute("action", "instantiate") - .add_attribute("contract_addr", instantiated_account_addr.clone()) + .add_attribute("contract_addr", instantiated_account_addr) .add_attribute("admin", msg.admin) .add_attribute("warp_addr", msg.warp_addr)) } diff --git a/packages/controller/src/job.rs b/packages/controller/src/job.rs index 04b092b7..187caa5b 100644 --- a/packages/controller/src/job.rs +++ b/packages/controller/src/job.rs @@ -39,6 +39,7 @@ pub struct Job { pub vars: String, pub recurring: bool, pub requeue_on_evict: bool, + pub duration_days: Uint128, pub reward: Uint128, pub assets_to_withdraw: Vec, }