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

Moved Distance ADO to Andromeda-math #714

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ andromeda-std = { workspace = true }
andromeda-math = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
cw-orch = { workspace = true }
cw-multi-test = { workspace = true, optional = true }
andromeda-testing = { workspace = true, optional = true }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response};
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError};

use andromeda_math::distance::{Coordinate, DistanceType, ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::{
Expand Down Expand Up @@ -165,3 +165,14 @@ fn decimal_validate(decimal: u16) -> Result<(), ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
ADOContract::default().migrate(deps, CONTRACT_NAME, CONTRACT_VERSION)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
if msg.result.is_err() {
return Err(ContractError::Std(StdError::generic_err(
msg.result.unwrap_err(),
)));
}

Ok(Response::default())
}
6 changes: 6 additions & 0 deletions contracts/math/andromeda-distance/src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use andromeda_math::distance::{ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::{ado_base::MigrateMsg, contract_interface, deploy::ADOMetadata};

pub const CONTRACT_ID: &str = "distance";

contract_interface!(DistanceContract, CONTRACT_ID, "andromeda_distance.wasm");
11 changes: 11 additions & 0 deletions contracts/math/andromeda-distance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub mod contract;
#[cfg(test)]
pub mod testing;

#[cfg(all(not(target_arch = "wasm32"), feature = "testing"))]
pub mod mock;

#[cfg(not(target_arch = "wasm32"))]
mod interface;
#[cfg(not(target_arch = "wasm32"))]
pub use crate::interface::DistanceContract;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(all(not(target_arch = "wasm32"), feature = "testing"))]
use crate::contract::{execute, instantiate, query};
use andromeda_modules::distance::{Coordinate, InstantiateMsg, QueryMsg};
use andromeda_math::distance::{Coordinate, InstantiateMsg, QueryMsg};
use andromeda_testing::mock::MockApp;
use andromeda_testing::{
mock_ado,
Expand Down
6 changes: 0 additions & 6 deletions contracts/modules/andromeda-distance/src/lib.rs

This file was deleted.

17 changes: 10 additions & 7 deletions contracts/non-fungible-tokens/andromeda-crowdfund/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ fn handle_receive_cw20(

fn execute_discard_campaign(mut ctx: ExecuteContext) -> Result<Response, ContractError> {
nonpayable(&ctx.info)?;

let ExecuteContext {
ref mut deps,
ref info,
Expand All @@ -389,7 +389,7 @@ fn execute_discard_campaign(mut ctx: ExecuteContext) -> Result<Response, Contrac
let curr_stage = get_current_stage(deps.storage);
// Ensure that the campaign is in ONGOING, or READY stage
ensure!(
curr_stage == CampaignStage::ONGOING || curr_stage == CampaignStage::READY,
curr_stage == CampaignStage::ONGOING || curr_stage == CampaignStage::READY,
ContractError::InvalidCampaignOperation {
operation: "discard_campaign".to_string(),
stage: curr_stage.to_string()
Expand All @@ -404,9 +404,7 @@ fn execute_discard_campaign(mut ctx: ExecuteContext) -> Result<Response, Contrac
.add_attribute("result", CampaignStage::DISCARDED.to_string()))
}

fn execute_end_campaign(
mut ctx: ExecuteContext
) -> Result<Response, ContractError> {
fn execute_end_campaign(mut ctx: ExecuteContext) -> Result<Response, ContractError> {
nonpayable(&ctx.info)?;

let ExecuteContext {
Expand Down Expand Up @@ -438,7 +436,10 @@ fn execute_end_campaign(
let soft_cap = campaign_config.soft_cap.unwrap_or(Uint128::one());

// Decide the next stage based on capital and expiry
let final_stage = match (duration.end_time.is_expired(&env.block), current_capital >= soft_cap) {
let final_stage = match (
duration.end_time.is_expired(&env.block),
current_capital >= soft_cap,
) {
// Success if soft cap is met
(_, true) => CampaignStage::SUCCESS,
// Failed if expired and soft cap not met
Expand Down Expand Up @@ -632,7 +633,9 @@ fn execute_claim(ctx: ExecuteContext) -> Result<Response, ContractError> {

let sub_response = match curr_stage {
CampaignStage::SUCCESS => handle_successful_claim(deps.branch(), &info.sender)?,
CampaignStage::FAILED | CampaignStage::DISCARDED => handle_failed_claim(deps.branch(), &info.sender)?,
CampaignStage::FAILED | CampaignStage::DISCARDED => {
handle_failed_claim(deps.branch(), &info.sender)?
}
_ => {
return Err(ContractError::InvalidCampaignOperation {
operation: "Claim".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,15 +1205,15 @@ mod test {
expected_stage: CampaignStage::FAILED,
},
EndCampaignTestCase {
name: "Cannot end non-expired campaign".to_string(), // Changed name to better reflect behavior
name: "Cannot end non-expired campaign".to_string(), // Changed name to better reflect behavior
stage: CampaignStage::ONGOING,
sender: MOCK_DEFAULT_OWNER.to_string(),
current_capital: Uint128::new(0u128),
soft_cap: None,
end_time: MillisecondsExpiration::from_seconds(env.block.time.seconds() + 1000),
denom: Asset::Cw20Token(AndrAddr::from_string(MOCK_CW20_CONTRACT.to_string())),
expected_res: Err(ContractError::CampaignNotExpired {}),
expected_stage: CampaignStage::ONGOING, // Stage won't change on error
expected_stage: CampaignStage::ONGOING, // Stage won't change on error
},
EndCampaignTestCase {
name: "End campaign from unauthorized sender".to_string(),
Expand Down Expand Up @@ -1302,7 +1302,7 @@ mod test {
#[test]
fn test_execute_discard_campaign() {
let env: Env = mock_env();

let test_cases: Vec<DiscardCampaign> = vec![
DiscardCampaign {
name: "Discard campaign using native token".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/andromeda-non-fungible-tokens/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub enum CampaignStage {
/// Stage when campaign failed to meet the target cap before expiration
FAILED,
/// Stage when campaign is discarded
DISCARDED
DISCARDED,
}

impl ToString for CampaignStage {
Expand Down
1 change: 1 addition & 0 deletions packages/deploy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ andromeda-rates = { path = "../../contracts/modules/andromeda-rates" }
# Math Contracts
andromeda-counter = { path = "../../contracts/math/andromeda-counter" }
andromeda-curve = { path = "../../contracts/math/andromeda-curve" }
andromeda-distance = { path = "../../contracts/math/andromeda-distance" }
mdjakovic0920 marked this conversation as resolved.
Show resolved Hide resolved
andromeda-date-time = { path = "../../contracts/math/andromeda-date-time" }
andromeda-shunting = { path = "../../contracts/math/andromeda-shunting" }

Expand Down
2 changes: 2 additions & 0 deletions packages/deploy/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use andromeda_cw20::CW20Contract;
use andromeda_cw20_exchange::Cw20ExchangeContract;
use andromeda_cw20_staking::CW20StakingContract;
use andromeda_cw721::CW721Contract;
use andromeda_distance::DistanceContract;
use andromeda_economics::EconomicsContract;
use andromeda_ibc_registry::IBCRegistryContract;
use andromeda_kernel::KernelContract;
Expand Down Expand Up @@ -82,6 +83,7 @@ pub fn all_contracts() -> Vec<DeployableContract> {
deployable!(AuctionContract),
deployable!(CrowdfundContract),
deployable!(MarketplaceContract),
deployable!(DistanceContract),
]
}

Expand Down
4 changes: 2 additions & 2 deletions packages/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ pub enum ContractError {
operation: String,
validator: String,
},

#[error("Invalid Campaign Operation: {operation} on {stage}")]
InvalidCampaignOperation { operation: String, stage: String },

#[error("No Staking Reward")]
InvalidClaim {},

Expand Down