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

Submodule and Indexer #33

Closed
wants to merge 9 commits into from
Closed
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
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['@uju-labs/eslint-config-custom/library'],
};
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# macOS
.DS_Store
tmp.txt

# Text file backups
**/*.rs.bk
Expand All @@ -19,12 +18,13 @@ target/
hash.txt
contracts.txt
artifacts/
schema/

# code coverage
tarpaulin-report.*
gas_reports/

# typescript
node_modules/
tmp/
lib/
dist/
.turbo/
22 changes: 14 additions & 8 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = ["contracts/*", "packages/*", "unit-tests"]

[workspace.package]
Expand Down Expand Up @@ -52,8 +53,8 @@ cw-storage-macro = "1.1.0"
cw-storage-plus = "1.1.0"
cw-controllers = "1.1.0"
cw2 = "1.1.0"
cw721 = "0.18.0"
cw721-base = "0.18.0"
cw721 = { version = "0.18.0" }
cw721-base = { version = "0.18.0", features = ["library"] }
cw-utils = "0.16.0"
cw-address-like = "1.0.4"

Expand All @@ -68,6 +69,7 @@ anyhow = "1.0.51"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["derive"] }
semver = "1.0.20"

# dev-dependencies
itertools = "0.10.5"
Expand Down
70 changes: 0 additions & 70 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/infinity-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::{
};
use cw2::set_contract_version;
use infinity_factory::msg::InstantiateMsg as InfinityFactoryInstantiateMsg;
use infinity_global::{GlobalConfig, InstantiateMsg as InfinityGlobalInstantiateMsg};
use infinity_global::{msg::InstantiateMsg as InfinityGlobalInstantiateMsg, GlobalConfig};
use infinity_index::msg::InstantiateMsg as InfinityIndexInstantiateMsg;
use infinity_router::msg::InstantiateMsg as InfinityRouterInstantiateMsg;
use sg_std::Response;
Expand Down
3 changes: 2 additions & 1 deletion contracts/infinity-factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "infinity-factory"
version = "0.1.2"
version = "0.2.0"
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
Expand Down Expand Up @@ -39,3 +39,4 @@ thiserror = { workspace = true }
sg-std = { workspace = true }
sha2 = { workspace = true }
sg-index-query = { workspace = true }
semver = { workspace = true }
3 changes: 2 additions & 1 deletion contracts/infinity-factory/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use cosmwasm_schema::write_api;
use infinity_factory::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use infinity_factory::msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
sudo: SudoMsg
}
}
7 changes: 7 additions & 0 deletions contracts/infinity-factory/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cosmwasm_std::Instantiate2AddressError;
use cosmwasm_std::StdError;

use infinity_shared::InfinityError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
Expand All @@ -10,4 +11,10 @@ pub enum ContractError {

#[error("{0}")]
Instantiate2AddressError(#[from] Instantiate2AddressError),

#[error("{0}")]
InfinityError(#[from] InfinityError),

#[error("InvalidMigration: {0}")]
InvalidMigration(String),
}
50 changes: 46 additions & 4 deletions contracts/infinity-factory/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::helpers::generate_salt;
use crate::msg::ExecuteMsg;
use crate::state::{INFINITY_GLOBAL, SENDER_COUNTER};
use crate::state::{INFINITY_GLOBAL, SENDER_COUNTER, UNRESTRICTED_MIGRATIONS};
use crate::ContractError;

use cosmwasm_std::{to_binary, DepsMut, Env, MessageInfo, WasmMsg};
use cosmwasm_std::{attr, ensure_eq, to_binary, DepsMut, Empty, Env, Event, MessageInfo, WasmMsg};
use infinity_global::load_global_config;
use infinity_pair::msg::InstantiateMsg as InfinityPairInstantiateMsg;
use sg_std::Response;
Expand All @@ -26,7 +26,9 @@ pub fn execute(
let infinity_global = INFINITY_GLOBAL.load(deps.storage)?;
let global_config = load_global_config(&deps.querier, &infinity_global)?;

let response = Response::new().add_message(WasmMsg::Instantiate {
let mut response = Response::new();

response = response.add_message(WasmMsg::Instantiate {
admin: Some(env.contract.address.into()),
code_id: global_config.infinity_pair_code_id,
label: "Infinity Pair".to_string(),
Expand All @@ -38,6 +40,11 @@ pub fn execute(
funds: info.funds,
});

// Event used by indexer to track pair creation
response = response.add_event(
Event::new("factory-create-pair".to_string()).add_attribute("sender", info.sender),
);

Ok(response)
},
ExecuteMsg::CreatePair2 {
Expand All @@ -53,7 +60,9 @@ pub fn execute(
let salt = generate_salt(&info.sender, counter);
SENDER_COUNTER.save(deps.storage, counter_key, &(counter + 1))?;

let response = Response::new().add_message(WasmMsg::Instantiate2 {
let mut response = Response::new();

response = response.add_message(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.into()),
code_id: global_config.infinity_pair_code_id,
label: "Infinity Pair".to_string(),
Expand All @@ -66,6 +75,39 @@ pub fn execute(
salt,
});

// Event used by indexer to track pair creation
response = response.add_event(
Event::new("factory-create-pair2".to_string()).add_attribute("sender", info.sender),
);

Ok(response)
},
ExecuteMsg::UnrestrictedMigratePair {
pair_address,
target_code_id,
} => {
let contract_info_response = deps.querier.query_wasm_contract_info(&pair_address)?;

let valid_target_code_id =
UNRESTRICTED_MIGRATIONS.load(deps.storage, contract_info_response.code_id)?;

ensure_eq!(
target_code_id,
valid_target_code_id,
ContractError::InvalidMigration("Invalid target code id".to_string())
);

let response = Response::new()
.add_message(WasmMsg::Migrate {
contract_addr: pair_address.clone(),
new_code_id: target_code_id,
msg: to_binary(&Empty {})?,
})
.add_event(Event::new("factory-migrate-pair".to_string()).add_attributes(vec![
attr("pair_address", pair_address),
attr("target_code_id", target_code_id.to_string()),
]));

Ok(response)
},
}
Expand Down
1 change: 1 addition & 0 deletions contracts/infinity-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod migrate;
pub mod msg;
pub mod query;
pub mod state;
pub mod sudo;

mod error;

Expand Down
Loading
Loading