Skip to content

Commit

Permalink
Tracer bullet for redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Aug 22, 2023
1 parent 325ffc0 commit 83f485d
Show file tree
Hide file tree
Showing 127 changed files with 2,074 additions and 19,185 deletions.
1,921 changes: 80 additions & 1,841 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 30 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ authors = ["Tasio [email protected]"]
license = "BUSL-1.1"

[workspace.dependencies]
infinity-macros = { path = "./packages/infinity-macros" }
infinity-router = { path = "./contracts/infinity-router" }
infinity-index = { path = "./contracts/infinity-index" }
infinity-pool = { path = "./contracts/infinity-pool" }
infinity-shared = { path = "./packages/infinity-shared" }
infinity-swap = { path = "./contracts/infinity-swap" }
infinity-marketplace-adapter = { path = "./contracts/infinity-marketplace-adapter" }
cosmwasm-schema = "1.2.1"
cosmwasm-std = "1.2.1"
cosmwasm-storage = "1.2.1"
# infinity-macros = { path = "./packages/infinity-macros" }
# infinity-swap = { path = "./contracts/infinity-swap" }
# infinity-marketplace-adapter = { path = "./contracts/infinity-marketplace-adapter" }
cosmwasm-std = { version = "1.2", features = ["staking", "stargate", "ibc3", "cosmwasm_1_1", "cosmwasm_1_2"] }
cosmwasm-schema = "1.2"
cosmwasm-storage = "1.2"
cw-storage-plus = "0.16.0"
cw-storage-macro = "0.16.0"
cw-utils = "0.16.0"
cw2 = "0.16.0"
cw721-base = { version = "0.16.0", features = ["library"] }
cw721 = "0.16.0"
sg1 = "2.1.0"
sg2 = "2.1.0"
sg721-base = { version = "2.1.0", features = ["library"] }
sg721 = { version = "2.1.0", features = ["library"] }
sg-std = "2.1.0"
sg-marketplace = { git = "https://github.com/tasiov/marketplace", branch = "infinity-marketplace-changes", features = ["library"] }
sg-marketplace-common = { git = "https://github.com/tasiov/marketplace", branch = "infinity-marketplace-changes" }
sg1 = { version = "2.1" }
sg2 = { version = "2.1" }
sg721-base = { version = "2.1", features = ["library"] }
sg721 = { version = "2.1", features = ["library"] }
sg-std = { version = "2.1" }
# sg-marketplace = { git = "https://github.com/tasiov/marketplace", branch = "infinity-marketplace-changes", features = ["library"] }
# sg-marketplace-common = { git = "https://github.com/tasiov/marketplace", branch = "infinity-marketplace-changes" }
sg-marketplace = { path = "../marketplace/contracts/marketplace", features = ["library"] }
sg-marketplace-common = { path = "../marketplace/packages/sg-marketplace-common" }
sha2 = "0.10"
thiserror = { version = "1.0.31" }
anyhow = "1.0.51"
proc-macro2 = "1.0"
Expand All @@ -38,12 +45,13 @@ syn = { version = "1.0", features = ["derive"] }
# dev-dependencies
itertools = "0.10.5"
cw-multi-test = "0.16.0"
sg-multi-test = "2.1.0"
test-suite = "2.1.0"
base-minter = "2.1.0"
base-factory = "2.1.0"
vending-minter = "2.1.0"
vending-factory = "2.1.0"
# sg-multi-test = "2.3"
sg-multi-test = { version = "2.1" }
test-suite = { version = "2.1" }
base-minter = { version = "2.1" }
base-factory = { version = "2.1" }
vending-minter = { version = "2.1" }
vending-factory = { version = "2.1" }
mockall = "0.11.4"
cosm-orc = { version = "3.0.1" }
cosm-tome = { version = "0.1.1" }
Expand All @@ -55,9 +63,9 @@ test-context = "0.1.4"
once_cell = "1.13.0"
rand = "0.8"

[profile.release.package.infinity-swap]
codegen-units = 1
incremental = false
# [profile.release.package.infinity-swap]
# codegen-units = 1
# incremental = false

[profile.release]
rpath = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "infinity-swap"
name = "infinity-index"
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
Expand All @@ -21,20 +21,26 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
# infinity-macros = { workspace = true }
# infinity-shared = { workspace = true }
# infinity-swap = { workspace = true }
# infinity-pool = { workspace = true }
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-storage = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
cw-storage-macro = { workspace = true }
# cosmwasm-storage = { workspace = true }
# cw-utils = { workspace = true }
cw2 = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
sg1 = { workspace = true }
sg2 = { workspace = true }
sg721-base = { workspace = true }
sg721 = { workspace = true }
# anyhow = { workspace = true }
# sg1 = { workspace = true }
# sg2 = { workspace = true }
# sg721-base = { workspace = true }
# sg721 = { workspace = true }
sg-std = { workspace = true }
sg-marketplace = { workspace = true }
cw721-base = { workspace = true }
cw721 = { workspace = true }

# sg-marketplace = { workspace = true }
# sg-marketplace-common = { workspace = true }
sha2 = { workspace = true }
# cw721-base = { workspace = true }
# cw721 = { workspace = true }
8 changes: 8 additions & 0 deletions contracts/infinity-index/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use cosmwasm_std::StdError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
}
93 changes: 93 additions & 0 deletions contracts/infinity-index/src/execute.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::msg::ExecuteMsg;
use crate::state::PoolQuote;
use crate::{
error::ContractError,
state::{buy_from_pool_quotes, sell_to_pool_quotes},
};

use cosmwasm_std::{Addr, DepsMut, Env, MessageInfo, Uint128};
use sg_std::Response;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
let api = deps.api;

match msg {
ExecuteMsg::UpdateBuyFromPoolQuote {
collection,
quote_price,
} => execute_update_buy_from_pool_quote(
deps,
env,
info,
api.addr_validate(&collection)?,
quote_price,
),
ExecuteMsg::UpdateSellToPoolQuote {
collection,
quote_price,
} => execute_update_sell_to_pool_quote(
deps,
env,
info,
api.addr_validate(&collection)?,
quote_price,
),
}
}

pub fn execute_update_buy_from_pool_quote(
deps: DepsMut,
env: Env,
info: MessageInfo,
collection: Addr,
quote_price: Option<Uint128>,
) -> Result<Response, ContractError> {
if let Some(_quote_price) = quote_price {
buy_from_pool_quotes().save(
deps.storage,
info.sender.clone(),
&PoolQuote {
pool: info.sender,
collection,
quote_price: _quote_price,
},
)?;
} else {
buy_from_pool_quotes().remove(deps.storage, info.sender)?;
}

Ok(Response::default())
}

pub fn execute_update_sell_to_pool_quote(
deps: DepsMut,
env: Env,
info: MessageInfo,
collection: Addr,
quote_price: Option<Uint128>,
) -> Result<Response, ContractError> {
if let Some(_quote_price) = quote_price {
sell_to_pool_quotes().save(
deps.storage,
info.sender.clone(),
&PoolQuote {
pool: info.sender,
collection,
quote_price: _quote_price,
},
)?;
} else {
sell_to_pool_quotes().remove(deps.storage, info.sender)?;
}

Ok(Response::default())
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
use crate::error::ContractError;
use crate::msg::InstantiateMsg;
use crate::state::{Config, CONFIG, POOL_COUNTER};
use crate::state::{Config, CONFIG};

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{DepsMut, Env, MessageInfo};
use cw2::set_contract_version;
use cw_utils::maybe_addr;
use sg_std::Response;

pub const CONTRACT_NAME: &str = "crates.io:infinity-swap";
pub const CONTRACT_NAME: &str = "crates.io:infinity-index";
pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

POOL_COUNTER.save(deps.storage, &1)?;
CONFIG.save(
deps.storage,
&Config {
marketplace_addr: deps.api.addr_validate(&msg.marketplace_addr)?,
developer: maybe_addr(deps.api, msg.developer)?,
global_gov: deps.api.addr_validate(&msg.global_gov)?,
infinity_factory: deps.api.addr_validate(&msg.infinity_factory)?,
},
)?;

Ok(Response::new()
.add_attribute("action", "instantiate")
.add_attribute("contract_name", CONTRACT_NAME)
.add_attribute("contract_version", CONTRACT_VERSION)
.add_attribute("denom", msg.denom)
.add_attribute("marketplace_addr", msg.marketplace_addr))
.add_attribute("global_gov", msg.global_gov)
.add_attribute("infinity_factory", msg.infinity_factory))
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod execute;
pub mod helpers;
pub mod instantiate;
pub mod msg;
pub mod query;
pub mod reply;
pub mod state;

mod error;
Expand Down
39 changes: 39 additions & 0 deletions contracts/infinity-index/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::state::PoolQuote;

use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint128;

#[cw_serde]
pub struct InstantiateMsg {
/// The address of the global gov contract
pub global_gov: String,
/// The address of the infinity factory contract
pub infinity_factory: String,
}

#[cw_serde]
pub enum ExecuteMsg {
UpdateBuyFromPoolQuote {
collection: String,
quote_price: Option<Uint128>,
},
UpdateSellToPoolQuote {
collection: String,
quote_price: Option<Uint128>,
},
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PoolQuoteResponse)]
QuoteSellToPool {
collection: String,
limit: u64,
},
}

#[cw_serde]
pub struct PoolQuoteResponse {
pub pool_quotes: Vec<PoolQuote>,
}
40 changes: 40 additions & 0 deletions contracts/infinity-index/src/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::msg::{PoolQuoteResponse, QueryMsg};
use crate::state::{sell_to_pool_quotes, PoolQuote};

use cosmwasm_std::{to_binary, Addr, Binary, Deps, Env, Order, StdResult};

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::QuoteSellToPool {
collection,
limit,
} => to_binary(&query_quotes_sell_to_pool(
deps,
deps.api.addr_validate(&collection)?,
limit,
)?),
}
}

pub fn query_quotes_sell_to_pool(
deps: Deps,
collection: Addr,
limit: u64,
) -> StdResult<PoolQuoteResponse> {
let pool_quotes: Vec<PoolQuote> = sell_to_pool_quotes()
.idx
.collection_quote_price
.sub_prefix(collection)
.range(deps.storage, None, None, Order::Descending)
.take(limit as usize)
.map(|item| item.map(|(_, v)| v))
.collect::<StdResult<_>>()?;

Ok(PoolQuoteResponse {
pool_quotes,
})
}
Loading

0 comments on commit 83f485d

Please sign in to comment.