Skip to content

Commit

Permalink
feat: Marketplace & Auction Adjustments (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
joemonem authored Nov 4, 2024
1 parent ec73e3e commit c7f2fb7
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 156 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Include ADOBase Version in Schema [(#574)](https://github.com/andromedaprotocol/andromeda-core/pull/574)
- Added Kernel ICS20 Transfer with Optional ExecuteMsg [(#577)](https://github.com/andromedaprotocol/andromeda-core/pull/577)
- Added IBC Denom Wrap/Unwrap [(#579)](https://github.com/andromedaprotocol/andromeda-core/pull/579)
- Auction & Marketplace: Added Multiple Authorized Addresses During Init, Add and Remove Authorized Addresses [(#589)](https://github.com/andromedaprotocol/andromeda-core/pull/589)
- Add CW20Receive schema for missing ado [(#594)](https://github.com/andromedaprotocol/andromeda-core/pull/594)

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/non-fungible-tokens/andromeda-auction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-auction"
version = "2.1.4"
version = "2.2.4"
edition = "2021"
rust-version = "1.75.0"

Expand Down
111 changes: 25 additions & 86 deletions contracts/non-fungible-tokens/andromeda-auction/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ use crate::state::{
auction_infos, read_auction_infos, read_bids, BIDS, NEXT_AUCTION_ID, TOKEN_AUCTION_STATE,
};
use andromeda_non_fungible_tokens::auction::{
validate_auction, AuctionIdsResponse, AuctionInfo, AuctionStateResponse,
AuthorizedAddressesResponse, Bid, BidsResponse, Cw20HookMsg, Cw721HookMsg, ExecuteMsg,
InstantiateMsg, IsCancelledResponse, IsClaimedResponse, IsClosedResponse, QueryMsg,
TokenAuctionState,
validate_auction, AuctionIdsResponse, AuctionInfo, AuctionStateResponse, Bid, BidsResponse,
Cw20HookMsg, Cw721HookMsg, ExecuteMsg, InstantiateMsg, IsCancelledResponse, IsClaimedResponse,
IsClosedResponse, QueryMsg, TokenAuctionState,
};
use andromeda_std::{
ado_base::{
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::{
authorize_addresses, execute_authorize_contract, execute_deauthorize_contract,
validate_native_denom, Asset, AuthorizedAddressesResponse, PermissionAction,
SEND_CW20_ACTION,
},
encode_binary,
expiration::{expiration_from_milliseconds, get_and_validate_start_time, Expiry},
Funds, Milliseconds, OrderBy,
Expand All @@ -40,7 +43,7 @@ const SEND_NFT_ACTION: &str = "SEND_NFT";

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
mut deps: DepsMut,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
Expand All @@ -62,29 +65,11 @@ pub fn instantiate(
)?;

if let Some(authorized_token_addresses) = msg.authorized_token_addresses {
if !authorized_token_addresses.is_empty() {
ADOContract::default().permission_action(SEND_NFT_ACTION, deps.storage)?;
}

for token_address in authorized_token_addresses {
let addr = token_address.get_raw_address(&deps.as_ref())?;
ADOContract::set_permission(
deps.storage,
SEND_NFT_ACTION,
addr,
Permission::Local(LocalPermission::Whitelisted(None)),
)?;
}
authorize_addresses(&mut deps, SEND_NFT_ACTION, authorized_token_addresses)?;
}
if let Some(authorized_cw20_address) = msg.authorized_cw20_address {
let addr = authorized_cw20_address.get_raw_address(&deps.as_ref())?;
ADOContract::default().permission_action(SEND_CW20_ACTION, deps.storage)?;
ADOContract::set_permission(
deps.storage,
SEND_CW20_ACTION,
addr,
Permission::Local(LocalPermission::Whitelisted(None)),
)?;

if let Some(authorized_cw20_addresses) = msg.authorized_cw20_addresses {
authorize_addresses(&mut deps, SEND_CW20_ACTION, authorized_cw20_addresses)?;
}

Ok(resp)
Expand Down Expand Up @@ -159,11 +144,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 +1096,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 +1232,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 +1381,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(),
start_after,
limit,
order_by,
Expand Down
9 changes: 5 additions & 4 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 @@ -168,13 +168,13 @@ pub fn mock_auction_instantiate_msg(
kernel_address: impl Into<String>,
owner: Option<String>,
authorized_token_addresses: Option<Vec<AndrAddr>>,
authorized_cw20_address: Option<AndrAddr>,
authorized_cw20_addresses: Option<Vec<AndrAddr>>,
) -> InstantiateMsg {
InstantiateMsg {
kernel_address: kernel_address.into(),
owner,
authorized_token_addresses,
authorized_cw20_address,
authorized_cw20_addresses,
}
}

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()),
expiration,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn init(deps: DepsMut) -> Response {
owner: None,
kernel_address: MOCK_KERNEL_CONTRACT.to_string(),
authorized_token_addresses: Some(vec![AndrAddr::from_string(MOCK_TOKEN_ADDR)]),
authorized_cw20_address: None,
authorized_cw20_addresses: None,
};

let info = mock_info("owner", &[]);
Expand All @@ -59,7 +59,7 @@ fn init_cw20(deps: DepsMut, _modules: Option<Vec<Module>>) -> Response {
owner: None,
kernel_address: MOCK_KERNEL_CONTRACT.to_string(),
authorized_token_addresses: Some(vec![AndrAddr::from_string(MOCK_TOKEN_ADDR)]),
authorized_cw20_address: Some(AndrAddr::from_string(MOCK_CW20_CONTRACT)),
authorized_cw20_addresses: Some(vec![AndrAddr::from_string(MOCK_CW20_CONTRACT)]),
};

let info = mock_info("owner", &[]);
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
Loading

0 comments on commit c7f2fb7

Please sign in to comment.