Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Nov 6, 2023
1 parent 58ab354 commit 8a8ff7e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
6 changes: 3 additions & 3 deletions contracts/warp-controller/src/execute/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)?;

Expand Down Expand Up @@ -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,
))
}
Expand Down Expand Up @@ -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 {});
Expand Down
2 changes: 2 additions & 0 deletions contracts/warp-controller/src/migrate/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
)?;
}
Expand Down Expand Up @@ -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),
},
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/warp-controller/src/reply/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))
}
Expand Down
28 changes: 20 additions & 8 deletions contracts/warp-controller/src/reply/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
));
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/warp-controller/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
})
}
Expand Down Expand Up @@ -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,
}),
})
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion contracts/warp-job-account-tracker/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions packages/controller/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetInfo>,
}
Expand Down

0 comments on commit 8a8ff7e

Please sign in to comment.