Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABS-166: Create accountability module #47

Merged
merged 73 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
917c736
create initial structure
0xmovses Aug 22, 2023
4539d87
create initial state
0xmovses Aug 22, 2023
afa4a1b
create handlers and msg
0xmovses Aug 22, 2023
b2f9d0a
create execute handler
0xmovses Aug 22, 2023
a938ec1
update names update state
0xmovses Aug 23, 2023
820eaeb
update handlers
0xmovses Aug 23, 2023
c511e32
add vote handler logic
0xmovses Aug 23, 2023
58ba5ef
fix handler compiler errors
0xmovses Aug 23, 2023
a34af41
Merge branch 'main' into 0xmovses/abs-166
0xmovses Aug 24, 2023
0cd6d9c
refactor, cleanup
0xmovses Aug 24, 2023
bf9d63b
update execute msg, more refactors
0xmovses Aug 24, 2023
7ddc6d6
create wasm test update toml
0xmovses Aug 24, 2023
c392981
create wasm test and setup for e2e
0xmovses Aug 24, 2023
4ebf3e0
Merge branch 'main' into 0xmovses/abs-166
0xmovses Aug 28, 2023
cdd2bde
create integration tests
0xmovses Aug 28, 2023
33662d7
add more tests
0xmovses Aug 28, 2023
8455147
add friend test cases
0xmovses Aug 29, 2023
0761101
add vote cases
0xmovses Aug 29, 2023
56f232b
updates
0xmovses Aug 29, 2023
bc02d4b
integrate adairrr feedback
0xmovses Aug 29, 2023
80c0057
update charge_penalty logic
0xmovses Aug 29, 2023
fa3912b
rebuilt wasms
0xmovses Aug 29, 2023
2302041
fix merge conflict
0xmovses Aug 29, 2023
485f696
rebuilt wasms
0xmovses Aug 30, 2023
0749614
fix tests and cleanup
0xmovses Aug 30, 2023
a109ada
clippy
0xmovses Aug 30, 2023
7f67ea4
integrate PR feedback
0xmovses Aug 31, 2023
23995ff
add impl methods on Vote and Friend
0xmovses Aug 31, 2023
0c2902d
update tests
0xmovses Aug 31, 2023
d97f69a
fix tests, refactor, cleanup
0xmovses Aug 31, 2023
29ba36a
integrate Buckram feedback
0xmovses Aug 31, 2023
1ccc033
add admin strike functionality and add challenge status
0xmovses Sep 1, 2023
668482f
update charge_penalty logic
0xmovses Sep 1, 2023
747ba8b
fix failing tests
0xmovses Sep 4, 2023
8159030
fix flaxy test, add remainder attribute
0xmovses Sep 4, 2023
c1ee4f9
merge main
0xmovses Sep 4, 2023
665ee6e
update to Timestamp use EndKind enum for user input
0xmovses Sep 4, 2023
faf7d92
add Timestamp to Checkin and vote_status
0xmovses Sep 4, 2023
a82034f
update contract logic
0xmovses Sep 4, 2023
f972ac5
remodel state, fix new ownership errors
0xmovses Sep 5, 2023
47fc6ff
update charge penalty math and state
0xmovses Sep 5, 2023
fa1b70a
fix tests intergrate feedback
0xmovses Sep 5, 2023
586ad1d
Merge branch 'main' into 0xmovses/abs-166
0xmovses Sep 5, 2023
78bfb14
update composite key and field names
0xmovses Sep 5, 2023
bea1879
update test after composite keys change
0xmovses Sep 5, 2023
b0b96ad
remove redundant
0xmovses Sep 5, 2023
667b32a
update comments
0xmovses Sep 5, 2023
4e5416f
update responses
0xmovses Sep 6, 2023
2038c82
add transfer msg
0xmovses Sep 6, 2023
9551a41
clippy
0xmovses Sep 6, 2023
33eb190
clippy more
0xmovses Sep 6, 2023
9be126f
run release_build
0xmovses Sep 6, 2023
0d4be6e
Update modules/contracts/apps/challenge/src/handlers/execute.rs
0xmovses Sep 6, 2023
a2df780
Update modules/contracts/apps/challenge/src/handlers/execute.rs
0xmovses Sep 6, 2023
022645f
integrate buckram feedback
0xmovses Sep 6, 2023
258e3a7
integrate Buckram feedback
0xmovses Sep 7, 2023
5aaacea
Merge branch 'main' into 0xmovses/abs-166
0xmovses Sep 7, 2023
6f763b5
generate schema
0xmovses Sep 7, 2023
e7c5a39
Merge branch 'main' into 0xmovses/abs-166
0xmovses Sep 7, 2023
58231c1
bump osmosis-test-tube
0xmovses Sep 7, 2023
b373994
Merge branch '0xmovses/abs-166' of https://github.com/AbstractSDK/abs…
0xmovses Sep 7, 2023
16977e7
Merge branch 'main' into 0xmovses/abs-166
0xmovses Sep 7, 2023
c1347ff
integrate buckram123 feedback
0xmovses Sep 7, 2023
a396d06
Merge branch '0xmovses/abs-166' of https://github.com/AbstractSDK/abs…
0xmovses Sep 7, 2023
a3568ae
merge main
0xmovses Sep 7, 2023
5f17a3b
Merge branch 'main' into 0xmovses/abs-166
0xmovses Sep 9, 2023
4133407
bump chrono
0xmovses Sep 9, 2023
00daa8a
bump chrono again
0xmovses Sep 9, 2023
05910db
chrono to 0.4.23
0xmovses Sep 9, 2023
2c7a03b
chrono to 0.4.27
0xmovses Sep 11, 2023
eee9c73
merge main
0xmovses Sep 11, 2023
7060482
chrono to 0.4.23
0xmovses Sep 11, 2023
5d26c7e
croncat version bump
Buckram123 Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ thiserror = { version = "1.0" }
protobuf = { version = "2", features = ["with-bytes"] }

clap = { version = "4.0.32", features = ["derive"] }
chrono = "0.4"
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
semver = "1.0"
cw-semver = { version = "1.0" }
cw-orch = { version = "~0.13" }
Expand Down
2 changes: 2 additions & 0 deletions modules/contracts/apps/challenge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ abstract-core = { workspace = true }
abstract-app = { workspace = true }
abstract-sdk = { workspace = true }

chrono = { workspace = true }
0xmovses marked this conversation as resolved.
Show resolved Hide resolved

# Dependencies for interface
abstract-interface = { workspace = true, optional = true }
cw-orch = { workspace = true, optional = true }
Expand Down
58 changes: 28 additions & 30 deletions modules/contracts/apps/challenge/src/handlers/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use abstract_core::objects::{AssetEntry, DexName};
use abstract_dex_adapter::msg::OfferAsset;
use abstract_sdk::features::AbstractResponse;
use cosmwasm_std::{
wasm_execute, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Response, Uint128,
wasm_execute, CosmosMsg, Decimal, DepsMut, Env, Error, MessageInfo, Order, Response, Uint128,
};
use cw_asset::{Asset, AssetList};

Expand All @@ -16,6 +16,7 @@ use crate::state::{
};
use abstract_dex_adapter::api::DexInterface;
use abstract_sdk::AbstractSdkResult;
use chrono::NaiveTime;
use croncat_app::croncat_intergration_utils::{CronCatAction, CronCatTaskRequest};
use croncat_app::{CronCat, CronCatInterface};

Expand Down Expand Up @@ -139,18 +140,20 @@ fn add_friend_for_challenge(
app.admin.assert_admin(deps.as_ref(), &info.sender)?;

if CHALLENGE_FRIENDS
.may_load(deps.storage, (&friend_address, challlenge_id))?
.may_load(deps.storage, (friend_address, challlenge_id))?
.is_some()
{
return AppError::generic_err("Friend already added for this challenge").into();
return AppError::Std(Error::generic_err(
"Friend already added for this challenge",
));
}

let friend = Friend {
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
address: friend_address.clone(),
name: friend_name,
};

CHALLENGE_FRIENDS.save(deps.storage, (&friend_address, challlenge_id), &friend)?;
CHALLENGE_FRIENDS.save(deps.storage, (friend_address, challlenge_id), &friend)?;
Ok(Response::new())
}

Expand All @@ -166,15 +169,15 @@ pub fn remove_friend_from_challenge(

// Ensure the friend exists for this challenge before removing
if CHALLENGE_FRIENDS
.may_load(deps.storage, (&friend_address, challenge_id))?
.may_load(deps.storage, (friend_address, challenge_id))?
.is_none()
{
return Err(AppError::NotFound {
kind: "Friend".to_string(),
});
return Err(AppError::Std(Error::generic_err(
"Friend not found for this challenge",
)));
}

CHALLENGE_FRIENDS.remove(deps.storage, (&friend_address, challenge_id));
CHALLENGE_FRIENDS.remove(deps.storage, (friend_address, challenge_id));
Ok(Response::new())
}

Expand All @@ -191,18 +194,18 @@ fn add_friends_for_challenge(
// Ensure the friends don't already exist for this challenge before adding
for friend in friends.iter() {
if CHALLENGE_FRIENDS
.may_load(deps.storage, (&friend.address, challenge_id))?
.may_load(deps.storage, (friend.address, challenge_id))?
.is_some()
{
return Err(AppError::generic_err(
return Err(AppError::Std(Error::generic_err(
"Friend already added for this challenge",
));
)));
}
}

// Add the friends
for friend in friends.iter() {
CHALLENGE_FRIENDS.save(deps.storage, (&friend.address, challenge_id), &friend)?;
CHALLENGE_FRIENDS.save(deps.storage, (friend.address, challenge_id), &friend)?;
}

Ok(Response::new())
Expand All @@ -211,15 +214,8 @@ fn add_friends_for_challenge(
fn daily_check_in(deps: DepsMut, env: Env, info: MessageInfo, app: &ChallengeApp) -> AppResult {
app.admin.assert_admin(deps.as_ref(), &info.sender)?;

let today = format!(
"{}-{}-{}",
env.block.time.year(),
env.block.time.month(),
env.block.time.day()
);

// Check if Admin has already checked in today
if let Ok(check_in) = DAILY_CHECKINS.load(deps.storage, &today) {
if let Ok(check_in) = DAILY_CHECKINS.load(deps.storage, &date_from_block(env)) {
if check_in.last_checked_in == today {
return Err(StdError::generic_err("Already checked in today."));
}
Expand Down Expand Up @@ -256,16 +252,8 @@ fn cast_vote(
return Err(StdError::generic_err("Only registered friends can vote."));
}

// Check Admin's last check-in
let today = format!(
"{}-{}-{}",
env.block.time.year(),
env.block.time.month(),
env.block.time.day()
);

// If Admin checked in today, friends can't vote
if let Ok(check_in) = DAILY_CHECKINS.load(deps.storage, &today) {
if let Ok(check_in) = DAILY_CHECKINS.load(deps.storage, &date_from_block(env)) {
if check_in.last_checked_in == today {
return Err(StdError::generic_err(
"Joe checked in today, no need to vote.",
Expand Down Expand Up @@ -324,3 +312,13 @@ fn count_votes(deps: DepsMut, env: Env, challenge_id: u64) -> Result<Response, S
.add_attribute("failed_votes", failed_votes.to_string())
.add_attribute("result", result))
}

fn date_from_block(env: Env) -> String {
// Convert the block's timestamp to NaiveDateTime
let seconds = env.block.time.seconds();
let nano_seconds = env.block.time.subsec_nanos();
let dt = NaiveDateTime::from_timestamp(seconds as i64, nano_seconds as u32);

// Format the date using the NaiveDateTime object
format!("{:04}-{:02}-{:02}", dt.year(), dt.month(), dt.day())
}
6 changes: 3 additions & 3 deletions modules/contracts/apps/challenge/src/handlers/instantiate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use abstract_sdk::features::AbstractNameService;
use abstract_sdk::AbstractSdfkError;
use cosmwasm_std::{env, DepsMut, MessageInfo, Response};
use abstract_sdk::AbstractSdkError;
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
use cw_asset::AssetInfoBase;

use crate::contract::{AccApp, AppResult};
Expand All @@ -14,7 +14,7 @@ pub fn instantiate_handler(
app: AccApp,
msg: AppInstantiateMsg,
) -> AppResult {
let ans_host = app.ans_host(deps.asref())?;
let ans_host = app.ans_host(deps.as_ref())?;
let asset = ans_host.query_asset(&deps.querier, &msg.native_asset)?;
let native_denom = match asset {
AssetInfoBase::Native(denom) => denom,
Expand Down
17 changes: 9 additions & 8 deletions modules/contracts/apps/challenge/src/handlers/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::contract::{AccApp, AppResult};
use crate::msg::{AccQueryMsg, AccResponse, ConfigResponse};
use crate::state::{ACC_LIST, CONFIG};
use crate::msg::{AccQueryMsg, AccResponse, ChallengeResponse, ConfigResponse};
use crate::state::{CHALLENGE_LIST, CONFIG};
use abstract_core::objects::DexAssetPairing;
use abstract_sdk::features::AbstractNameService;
use abstract_sdk::Resolve;
Expand All @@ -10,7 +10,7 @@ use cw_asset::AssetInfo;
pub fn query_handler(deps: Deps, _env: Env, app: &AccApp, msg: AccQueryMsg) -> AppResult<Binary> {
match msg {
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
AccQueryMsg::Config {} => to_binary(&query_config(deps, app)?),
AccQueryMsg::Acc { acc_id } => to_binary(&query_acc(deps, app, acc_id)?),
AccQueryMsg::Acc { acc_id } => unimplemented!(),
}
.map_err(Into::into)
}
Expand All @@ -24,15 +24,16 @@ fn query_config(deps: Deps, app: &AccApp) -> AppResult<ConfigResponse> {
Ok(ConfigResponse {
native_asset,
forfeit_amount: config.forfeit_amount,
refill_threshold: config.refill_threshold,
})
}

/// Get accountability
fn query_accountability(deps: Deps, app: &AccApp, acc_id: String) -> AppResult<AccResponse> {
let dca = ACC_LIST.may_load(deps.storage, acc_id)?;
let challenge = CHALLENGE_LIST.may_load(deps.storage, acc_id)?;
let ans_host = app.ans_host(deps)?;
let pool_references = if let Some(entry) = dca.as_ref() {

// don't need this
let pool_references = if let Some(entry) = challenge.as_ref() {
DexAssetPairing::new(
entry.source_asset.name.clone(),
entry.target_asset.clone(),
Expand All @@ -42,8 +43,8 @@ fn query_accountability(deps: Deps, app: &AccApp, acc_id: String) -> AppResult<A
} else {
vec![]
};
Ok(AccResponse {
acc,
Ok(ChallengeResponse {
challenge: Some(challenge),
pool_references,
})
}
24 changes: 16 additions & 8 deletions modules/contracts/apps/challenge/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{contract::AccApp, state::AccEntry};
use abstract_core::objects::PoolReference;
use crate::{contract::AccApp, state::ChallengeEntry};
use abstract_core::objects::{AssetEntry, PoolReference};
use cosmwasm_std::{Decimal, Uint128};
use croncat_app::croncat_intergration_utils::CronCatInterval;

abstract_app::app_msg_types!(AccApp, AccExecuteMsg, AccQueryMsg);
abstract_app::app_msg_types!(AccApp, ChallengeExecuteMsg, ChallengeQueryMsg);

#[cosmwasm_schema::cw_serde]
pub enum Frequency {
Expand All @@ -29,16 +30,24 @@ pub struct AppInstantiateMsg {
/// Native gas/stake asset for this chain
pub native_asset: AssetEntry,
/// Amount in native coins for accountability creation task and refill amount
pub forfeit_creation_amount: Uint128,
pub forfeit_amount: Uint128,
/// Task balance threshold to trigger refill, put it at zero if you consider to never refill your tasks
pub refill_threshold: Uint128,
}

/// App execute messages
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
#[cfg_attr(feature = "interface", impl_into(ExecuteMsg))]
pub enum ChallengeExecuteMsg {
//@Todo: Add ExecuteMsgs
}

#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
#[cfg_attr(feature = "interface", impl_into(QueryMsg))]
#[derive(QueryResponses)]
pub enum AccQueryMsg {
pub enum ChallengeQueryMsg {
#[returns(ConfigResponse)]
Config {},
#[returns(AccResponse)]
Expand All @@ -49,11 +58,10 @@ pub enum AccQueryMsg {
pub struct ConfigResponse {
pub native_asset: AssetEntry,
pub forfeit_amount: Uint128,
pub refill_threshold: Uint128,
}

#[cosmwasm_schema::cw_serde]
pub struct AccResponse {
pub acc: Option<AccEntry>,
pub struct ChallengeResponse {
pub challenge: Option<ChallengeEntry>,
pub pool_references: Vec<PoolReference>,
}
Loading