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

feat: Marketplace & Auction Adjustments #589

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
2 changes: 1 addition & 1 deletion Cargo.lock

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

75 changes: 16 additions & 59 deletions contracts/non-fungible-tokens/andromeda-auction/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ use andromeda_std::{
permissioning::{LocalPermission, Permission},
InstantiateMsg as BaseInstantiateMsg, MigrateMsg,
},
amp::{AndrAddr, Recipient},
amp::Recipient,
common::{
actions::call_action,
denom::{validate_native_denom, Asset, SEND_CW20_ACTION},
denom::{
execute_authorize_contract, execute_deauthorize_contract, validate_native_denom, Asset,
PermissionAction, SEND_CW20_ACTION,
},
encode_binary,
expiration::{expiration_from_milliseconds, get_and_validate_start_time, Expiry},
Funds, Milliseconds, OrderBy,
Expand Down Expand Up @@ -159,11 +162,13 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
token_id,
token_address,
} => execute_claim(ctx, token_id, token_address, action),
ExecuteMsg::AuthorizeTokenContract { addr, expiration } => {
execute_authorize_token_contract(ctx.deps, ctx.info, addr, expiration)
}
ExecuteMsg::DeauthorizeTokenContract { addr } => {
execute_deauthorize_token_contract(ctx.deps, ctx.info, addr)
ExecuteMsg::AuthorizeContract {
action,
addr,
expiration,
} => execute_authorize_contract(ctx.deps, ctx.info, action, addr, expiration),
ExecuteMsg::DeauthorizeContract { action, addr } => {
execute_deauthorize_contract(ctx.deps, ctx.info, action, addr)
}
_ => ADOContract::default().execute(ctx, msg),
}?;
Expand Down Expand Up @@ -1109,57 +1114,6 @@ fn execute_claim(
Ok(resp)
}

fn execute_authorize_token_contract(
deps: DepsMut,
info: MessageInfo,
token_address: AndrAddr,
expiration: Option<Expiry>,
) -> Result<Response, ContractError> {
let contract = ADOContract::default();
let addr = token_address.get_raw_address(&deps.as_ref())?;
ensure!(
contract.is_contract_owner(deps.storage, info.sender.as_str())?,
ContractError::Unauthorized {}
);
let permission = if let Some(expiration) = expiration {
Permission::Local(LocalPermission::Whitelisted(Some(expiration)))
} else {
Permission::Local(LocalPermission::Whitelisted(None))
};
ADOContract::set_permission(
deps.storage,
SEND_NFT_ACTION,
addr.to_string(),
permission.clone(),
)?;

Ok(Response::default().add_attributes(vec![
attr("action", "authorize_token_contract"),
attr("token_address", addr),
attr("permission", permission.to_string()),
]))
}

fn execute_deauthorize_token_contract(
deps: DepsMut,
info: MessageInfo,
token_address: AndrAddr,
) -> Result<Response, ContractError> {
let contract = ADOContract::default();
let addr = token_address.get_raw_address(&deps.as_ref())?;
ensure!(
contract.is_contract_owner(deps.storage, info.sender.as_str())?,
ContractError::Unauthorized {}
);

ADOContract::remove_permission(deps.storage, SEND_NFT_ACTION, addr.to_string())?;

Ok(Response::default().add_attributes(vec![
attr("action", "deauthorize_token_contract"),
attr("token_address", addr),
]))
}

fn purchase_token(
deps: Deps,
_info: &MessageInfo,
Expand Down Expand Up @@ -1296,11 +1250,13 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractErro
token_address,
} => encode_binary(&query_is_closed(deps, env, token_id, token_address)?),
QueryMsg::AuthorizedAddresses {
action,
start_after,
limit,
order_by,
} => encode_binary(&query_authorized_addresses(
deps,
action,
start_after,
limit,
order_by,
Expand Down Expand Up @@ -1443,13 +1399,14 @@ fn query_owner_of(

fn query_authorized_addresses(
deps: Deps,
action: PermissionAction,
start_after: Option<String>,
limit: Option<u32>,
order_by: Option<OrderBy>,
) -> Result<AuthorizedAddressesResponse, ContractError> {
let addresses = ADOContract::default().query_permissioned_actors(
deps,
SEND_NFT_ACTION,
action.as_str(),
Comment on lines +1384 to +1391
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Standardize pagination limit type across query functions.

The limit parameter type in query_authorized_addresses is Option<u32>, while other query functions in this file (e.g., query_auction_infos_for_address, query_bids) use Option<u64>. Consider standardizing the pagination limit type for consistency.

Apply this diff:

-    limit: Option<u32>,
+    limit: Option<u64>,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
action: PermissionAction,
start_after: Option<String>,
limit: Option<u32>,
order_by: Option<OrderBy>,
) -> Result<AuthorizedAddressesResponse, ContractError> {
let addresses = ADOContract::default().query_permissioned_actors(
deps,
SEND_NFT_ACTION,
action.as_str(),
action: PermissionAction,
start_after: Option<String>,
limit: Option<u64>,
order_by: Option<OrderBy>,
) -> Result<AuthorizedAddressesResponse, ContractError> {
let addresses = ADOContract::default().query_permissioned_actors(
deps,
action.as_str(),

start_after,
limit,
order_by,
Expand Down
5 changes: 3 additions & 2 deletions contracts/non-fungible-tokens/andromeda-auction/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use andromeda_std::ado_base::rates::{Rate, RatesMessage};
use andromeda_std::amp::messages::AMPPkt;
use andromeda_std::amp::AndrAddr;
use andromeda_std::amp::Recipient;
use andromeda_std::common::denom::Asset;
use andromeda_std::common::denom::{Asset, PermissionAction};
use andromeda_std::common::expiration::Expiry;
use andromeda_testing::mock::MockApp;
use andromeda_testing::{
Expand Down Expand Up @@ -209,7 +209,8 @@ pub fn mock_authorize_token_address(
token_address: impl Into<String>,
expiration: Option<Expiry>,
) -> ExecuteMsg {
ExecuteMsg::AuthorizeTokenContract {
ExecuteMsg::AuthorizeContract {
action: PermissionAction::SendNft,
addr: AndrAddr::from_string(token_address.into()),
joemonem marked this conversation as resolved.
Show resolved Hide resolved
expiration,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-marketplace"
version = "2.1.4"
version = "2.2.4"
edition = "2021"
rust-version = "1.75.0"

Expand Down
78 changes: 64 additions & 14 deletions contracts/non-fungible-tokens/andromeda-marketplace/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use crate::state::{
};
use std::vec;

use andromeda_non_fungible_tokens::marketplace::{
Cw20HookMsg, Cw721HookMsg, ExecuteMsg, InstantiateMsg, QueryMsg, SaleIdsResponse,
SaleStateResponse, Status,
use andromeda_non_fungible_tokens::{
auction::AuthorizedAddressesResponse,
marketplace::{
Cw20HookMsg, Cw721HookMsg, ExecuteMsg, InstantiateMsg, QueryMsg, SaleIdsResponse,
SaleStateResponse, Status,
},
};
use andromeda_std::{
ado_base::{
Expand All @@ -17,11 +20,14 @@ use andromeda_std::{
common::{
actions::call_action,
context::ExecuteContext,
denom::{Asset, SEND_CW20_ACTION, SEND_NFT_ACTION},
denom::{
execute_authorize_contract, execute_deauthorize_contract, Asset, PermissionAction,
SEND_CW20_ACTION, SEND_NFT_ACTION,
},
encode_binary,
expiration::{expiration_from_milliseconds, get_and_validate_start_time, Expiry},
rates::{get_tax_amount, get_tax_amount_cw20},
Funds, Milliseconds, MillisecondsDuration,
Funds, Milliseconds, MillisecondsDuration, OrderBy,
},
error::ContractError,
};
Expand Down Expand Up @@ -79,15 +85,20 @@ pub fn instantiate(
}
}

if let Some(authorized_cw20_address) = msg.authorized_cw20_address {
ADOContract::default().permission_action(SEND_CW20_ACTION, deps.storage)?;
let addr = authorized_cw20_address.get_raw_address(&deps.as_ref())?;
ADOContract::set_permission(
deps.storage,
SEND_CW20_ACTION,
addr,
Permission::Local(LocalPermission::Whitelisted(None)),
)?;
if let Some(authorized_cw20_addresses) = msg.authorized_cw20_addresses {
if !authorized_cw20_addresses.is_empty() {
ADOContract::default().permission_action(SEND_CW20_ACTION, deps.storage)?;
}

for authorized_cw20_address in authorized_cw20_addresses {
let addr = authorized_cw20_address.get_raw_address(&deps.as_ref())?;
ADOContract::set_permission(
deps.storage,
SEND_CW20_ACTION,
addr,
Permission::Local(LocalPermission::Whitelisted(None)),
)?;
}
joemonem marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(inst_resp)
Expand Down Expand Up @@ -138,6 +149,16 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
token_id,
token_address,
} => execute_cancel(ctx, token_id, token_address),
ExecuteMsg::AuthorizeContract {
action,
addr,
expiration,
} => execute_authorize_contract(ctx.deps, ctx.info, action, addr, expiration),

ExecuteMsg::DeauthorizeContract { action, addr } => {
execute_deauthorize_contract(ctx.deps, ctx.info, action, addr)
}

_ => ADOContract::default().execute(ctx, msg),
}?;
Ok(res
Expand Down Expand Up @@ -815,6 +836,18 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractErro
start_after,
limit,
)?),
QueryMsg::AuthorizedAddresses {
action,
start_after,
limit,
order_by,
} => encode_binary(&query_authorized_addresses(
deps,
action,
start_after,
limit,
order_by,
)?),
_ => ADOContract::default().query(deps, env, msg),
}
}
Expand Down Expand Up @@ -877,6 +910,23 @@ fn query_owner_of(
Ok(res)
}

fn query_authorized_addresses(
deps: Deps,
action: PermissionAction,
start_after: Option<String>,
limit: Option<u32>,
order_by: Option<OrderBy>,
) -> Result<AuthorizedAddressesResponse, ContractError> {
let addresses = ADOContract::default().query_permissioned_actors(
deps,
action.as_str(),
start_after,
limit,
order_by,
)?;
Ok(AuthorizedAddressesResponse { addresses })
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
ADOContract::default().migrate(deps, CONTRACT_NAME, CONTRACT_VERSION)
Expand Down
Loading
Loading