Skip to content

Commit

Permalink
Add single tx pair creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Aug 22, 2023
1 parent c014495 commit fe5f254
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 92 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ target/
.idea/
*.iml

# Auto-gen
.cargo-ok

# Build artifacts
.cargo-ok
hash.txt
contracts.txt
artifacts/

# code coverage
tarpaulin-report.*
gas_reports/

# integration tests
gas_reports/
# typescript
node_modules/
tmp/
lib/
1 change: 1 addition & 0 deletions Cargo.lock

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

37 changes: 23 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ authors = ["Tasio [email protected]"]
license = "BUSL-1.1"

[workspace.dependencies]
infinity-builder = { path = "./contracts/infinity-builder" }
infinity-factory = { path = "./contracts/infinity-factory" }
infinity-global = { path = "./contracts/infinity-global" }
infinity-index = { path = "./contracts/infinity-index" }
infinity-pair = { path = "./contracts/infinity-pair" }
infinity-router = { path = "./contracts/infinity-router" }
infinity-shared = { path = "./packages/infinity-shared" }
infinity-builder = { path = "./contracts/infinity-builder", features = [
"library",
] }
infinity-factory = { path = "./contracts/infinity-factory", features = [
"library",
] }
infinity-global = { path = "./contracts/infinity-global", features = [
"library",
] }
infinity-index = { path = "./contracts/infinity-index", features = ["library"] }
infinity-pair = { path = "./contracts/infinity-pair", features = ["library"] }
infinity-router = { path = "./contracts/infinity-router", features = [
"library",
] }
infinity-shared = { path = "./packages/infinity-shared", features = [
"library",
] }

stargaze-fair-burn = { version = "1.0.2", features = ["library"] }
stargaze-royalty-registry = { version = "0.1.0", features = ["library"] }
Expand Down Expand Up @@ -46,13 +56,12 @@ sg721-base = { version = "2.3.0", features = ["library"] }
sg721 = { version = "2.3.0", features = ["library"] }
sg-std = { version = "2.3.0" }
sg-index-query = { version = "0.1.1" }

sha2 = "0.10"
thiserror = { version = "1.0.31" }
anyhow = "1.0.51"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
thiserror = { version = "1.0.31" }
anyhow = "1.0.51"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["derive"] }

# dev-dependencies
itertools = "0.10.5"
Expand Down
4 changes: 2 additions & 2 deletions contracts/infinity-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn instantiate(

response = response.add_message(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: msg.code_ids.infinity_factory,
code_id: msg.code_ids.infinity_index,
label: "Infinity Index".to_string(),
msg: to_binary(&InfinityIndexInstantiateMsg {
infinity_global: infinity_global.to_string(),
Expand All @@ -136,7 +136,7 @@ pub fn instantiate(

response = response.add_message(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: msg.code_ids.infinity_factory,
code_id: msg.code_ids.infinity_router,
label: "Infinity Router".to_string(),
msg: to_binary(&InfinityRouterInstantiateMsg {
infinity_global: infinity_global.to_string(),
Expand Down
16 changes: 12 additions & 4 deletions contracts/infinity-factory/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::helpers::generate_instantiate_2_addr;
use crate::msg::{NextPairResponse, QueryMsg};
use crate::state::SENDER_COUNTER;
use crate::state::{INFINITY_GLOBAL, SENDER_COUNTER};

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

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
Expand All @@ -17,11 +18,18 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
}

pub fn query_next_pair(deps: Deps, env: Env, sender: Addr) -> StdResult<NextPairResponse> {
let infinity_global = INFINITY_GLOBAL.load(deps.storage)?;
let global_config = load_global_config(&deps.querier, &infinity_global)?;
let counter = SENDER_COUNTER.may_load(deps.storage, sender.clone())?.unwrap_or_default();

let response = deps.querier.query_wasm_contract_info(&env.contract.address)?;
let (pair, salt) =
generate_instantiate_2_addr(deps, &env, &sender, counter, response.code_id).unwrap();
let (pair, salt) = generate_instantiate_2_addr(
deps,
&env,
&sender,
counter,
global_config.infinity_pair_code_id,
)
.unwrap();

Ok(NextPairResponse {
sender,
Expand Down
2 changes: 1 addition & 1 deletion contracts/infinity-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
cw-storage-macro = { workspace = true }
sg-index-query = { version = "0.1.1" }
sg-index-query = { workspace = true }
cw2 = { workspace = true }
thiserror = { workspace = true }
sg-std = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions contracts/infinity-index/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg_attr(not(debug_assertions), allow(unused_imports))]
use crate::state::PairQuote;

use cosmwasm_schema::{cw_serde, QueryResponses};
Expand Down
4 changes: 2 additions & 2 deletions contracts/infinity-index/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
deps,
deps.api.addr_validate(&collection)?,
denom,
query_options.unwrap_or(QueryOptions::default()),
query_options.unwrap_or_default(),
)?),
QueryMsg::BuyFromPairQuotes {
collection,
Expand All @@ -28,7 +28,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
deps,
deps.api.addr_validate(&collection)?,
denom,
query_options.unwrap_or(QueryOptions::default()),
query_options.unwrap_or_default(),
)?),
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/infinity-pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ infinity-shared = { workspace = true }
stargaze-fair-burn = { workspace = true }
stargaze-royalty-registry = { workspace = true }
sg-marketplace-common = { workspace = true }
sg-index-query = { workspace = true }
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
Expand Down
129 changes: 128 additions & 1 deletion contracts/infinity-pair/schema/infinity-pair.json
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,139 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"nft_deposits"
],
"properties": {
"nft_deposits": {
"type": "object",
"properties": {
"query_options": {
"anyOf": [
{
"$ref": "#/definitions/QueryOptions_for_String"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
"QueryBound_for_String": {
"oneOf": [
{
"type": "object",
"required": [
"inclusive"
],
"properties": {
"inclusive": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"exclusive"
],
"properties": {
"exclusive": {
"type": "string"
}
},
"additionalProperties": false
}
]
},
"QueryOptions_for_String": {
"description": "QueryOptions are used to pass in options to a query function",
"type": "object",
"properties": {
"descending": {
"description": "Whether to sort items in ascending or descending order",
"type": [
"boolean",
"null"
]
},
"limit": {
"description": "The number of items that will be returned",
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"max": {
"description": "The maximum key value to fetch",
"anyOf": [
{
"$ref": "#/definitions/QueryBound_for_String"
},
{
"type": "null"
}
]
},
"min": {
"description": "The minimum key value to fetch",
"anyOf": [
{
"$ref": "#/definitions/QueryBound_for_String"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
}
]
}
},
"migrate": null,
"sudo": null,
"responses": {
"nft_deposits": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "NftDepositsResponse",
"type": "object",
"required": [
"collection",
"token_ids"
],
"properties": {
"collection": {
"$ref": "#/definitions/Addr"
},
"token_ids": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
}
}
},
"pair": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Pair",
Expand Down
22 changes: 13 additions & 9 deletions contracts/infinity-pair/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#[cfg_attr(not(debug_assertions), allow(unused_imports))]
use crate::{
pair::Pair,
state::{BondingCurve, PairConfig, PairImmutable, PairType, TokenId},
};

use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Coin, Uint128};
use cosmwasm_std::{Addr, Coin, Uint128};
use cw721::Cw721ReceiveMsg;
use sg_index_query::QueryOptions;

/// Defines whether the end user is buying or selling NFTs
#[cw_serde]
Expand Down Expand Up @@ -78,12 +80,14 @@ pub enum ExecuteMsg {
pub enum QueryMsg {
#[returns(Pair)]
Pair {},
// #[returns(Vec<TokenId>)]
// NftDeposits {
// query_options: Option<QueryOptions<String>>,
// },
// #[returns(Option<Uint128>)]
// BuyFromPairQuote {},
// #[returns(Option<Uint128>)]
// SellToPairQuote {},
#[returns(NftDepositsResponse)]
NftDeposits {
query_options: Option<QueryOptions<String>>,
},
}

#[cw_serde]
pub struct NftDepositsResponse {
pub collection: Addr,
pub token_ids: Vec<TokenId>,
}
Loading

0 comments on commit fe5f254

Please sign in to comment.