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

Drop locator #81

Draft
wants to merge 59 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
8039373
Add additional workers
keylogic1 Apr 26, 2024
267f393
Add more workers
keylogic1 Apr 26, 2024
1da4ed0
Resolve conflict in Cargo.toml
faust403 May 7, 2024
7e7fc91
Drop locator init: improve naming and add new query to get all possib…
faust403 May 6, 2024
cf291cb
Change execute_add_chain_info, now it can add list of new chains
faust403 May 6, 2024
3ab8764
Add execute_remove_chain_info
faust403 May 6, 2024
96249c5
Improve naming
faust403 May 6, 2024
4a42249
Improve naming for query
faust403 May 6, 2024
0d3ac4b
Remove config since it isn't necessary
faust403 May 6, 2024
baf9df4
Remove .vscode
faust403 May 7, 2024
12f646c
Rename contract name to avoid drop-drop-* in artifact's name
faust403 May 7, 2024
54795b2
Update QueryMsg
faust403 May 7, 2024
25cbaec
.for_each -> simple for loop
faust403 May 7, 2024
624d1f0
Error handling for chain remove
faust403 May 7, 2024
299d5a9
Move factory parts to packages/
faust403 May 7, 2024
6b7d805
Remove .clone() in query_chain
faust403 May 7, 2024
80fa617
Replace .unwrap_or_default() with ?
faust403 May 7, 2024
c03f212
Stop handling exception throwing
faust403 May 7, 2024
63d528b
Remove NeutronError from error list
faust403 May 7, 2024
eebe5a1
Remove Instantiate2AddressError, Unauthorized, Unimplemented and Unkn…
faust403 May 7, 2024
f970734
Skip check after deletion
faust403 May 7, 2024
48fcfca
Simplify ExecuteMsg structure, update contract's code
faust403 May 7, 2024
7149fbc
Move everything to FactoryState
faust403 May 7, 2024
6de41ae
Move to .to_string() method instead of .clone()
faust403 May 7, 2024
44c59e5
.range_raw() -> .range()
faust403 May 7, 2024
3abd125
Update Cargo.toml
faust403 May 7, 2024
2c76024
Add new queries
faust403 May 7, 2024
a3a236f
Update execute_remove_chains in contract.rs, integration_tests script…
faust403 May 14, 2024
a6e2556
Update debug information in execute_add_chains
faust403 May 14, 2024
bcac025
Improve query_factory_instances
faust403 May 14, 2024
eeb81f1
Move schema generator, add dropLocator to contractLib
faust403 May 14, 2024
5dec68a
Started writing integration tests, upload binaries testcase
faust403 May 15, 2024
c4bd9be
Add "Instantiate factory instances testcase"
faust403 May 15, 2024
3d93dcd
Add "contracts" field in context, update testcases
faust403 May 15, 2024
7f7a9dd
Remove unused imports
faust403 May 15, 2024
e4deac0
Add adding & removing testcases for contract
faust403 May 15, 2024
a2341c8
Remove second .clone(), add tests.rs and update lib.rs for unit tests
faust403 May 16, 2024
ed82579
Update gaia.genesis_opts
faust403 May 16, 2024
a3f072b
Update hermes.config
faust403 May 16, 2024
e178ad0
Add new testcase
faust403 May 16, 2024
3c04790
Remove unused constant
faust403 May 16, 2024
f04d8ad
Add custom querier
faust403 May 17, 2024
9927037
Unit tests for adding new chain
faust403 May 17, 2024
db816d7
Remove unused imports
faust403 May 17, 2024
728f8d6
Move cloned value into lambda
faust403 May 17, 2024
81bceb6
Improve add_factory_instances test
faust403 May 18, 2024
e67f9d7
Add tests for removing chains
faust403 May 18, 2024
400d878
Test to reveal unauthorized executions
faust403 May 18, 2024
6bd69af
Replace match with if statement
faust403 May 21, 2024
6822973
Add github actions test for drop-locator
faust403 May 21, 2024
314de4e
Remove unnecessary code
faust403 May 22, 2024
fa0e14e
Move from String::from to .to_string()
faust403 May 22, 2024
23fd3a3
Compare factory output with direct query
faust403 May 29, 2024
3178690
Move simple for to for-of loop
faust403 Jun 3, 2024
4c86196
Merge branch 'feat/audit-fixes' into drop-locator
faust403 Jun 3, 2024
9d994f7
Minor fixes in tests
faust403 Jun 3, 2024
dd95de1
Update generated lib
faust403 Jun 3, 2024
3675ad0
Replace matches with length check
faust403 Jun 3, 2024
80a875b
Update 'factory instances' testcase
faust403 Jun 3, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.runner_label }}
strategy:
matrix:
runner_label: ${{ fromJSON('["lionco-runner-5", "lionco-runner-6"]') }}
runner_label: ${{ fromJSON('["lionco-runner-1", "lionco-runner-2", "lionco-runner-3", "lionco-runner-4", "lionco-runner-5", "lionco-runner-6", "lionco-runner-7", "lionco-runner-8", "lionco-runner-9", "lionco-runner-10"]') }}
steps:
- name: Stop old containers
run: docker ps -q | grep -q . && docker stop $(docker ps -q) -t0 || echo "No containers to stop"
Expand All @@ -31,7 +31,7 @@ jobs:
runs-on: ${{ matrix.runner_label }}
strategy:
matrix:
runner_label: ${{ fromJSON('["lionco-runner-5", "lionco-runner-6"]') }}
runner_label: ${{ fromJSON('["lionco-runner-1", "lionco-runner-2", "lionco-runner-3", "lionco-runner-4", "lionco-runner-5", "lionco-runner-6", "lionco-runner-7", "lionco-runner-8", "lionco-runner-9", "lionco-runner-10"]') }}
steps:
- name: Clean Workspace
if: always()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
.vscode/
target/
**/schema/
/artifacts/
Expand Down
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

17 changes: 17 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"contracts/proposal-votes-poc",
"contracts/provider-proposals-poc",
"contracts/pump",
"contracts/locator",
"contracts/puppeteer",
# "contracts/puppeteer-authz",
"contracts/rewards-manager",
Expand Down
2 changes: 2 additions & 0 deletions contracts/locator/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
schema = "run --bin drop-locator-schema"
36 changes: 36 additions & 0 deletions contracts/locator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
authors = ["Vladislav Vasilev <[email protected]>"]
description = "Contract to query all Drop contracts"
edition = "2021"
name = "locator"
version = "1.0.0"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
thiserror = { workspace = true }
drop-staking-base = { workspace = true }
drop-puppeteer-base = { workspace = true }
drop-helpers = { workspace = true }
drop-macros = { workspace = true }
neutron-sdk = { workspace = true }
cw-ownable = { workspace = true }
1 change: 1 addition & 0 deletions contracts/locator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DROP Locator contract
10 changes: 10 additions & 0 deletions contracts/locator/bin/drop-locator-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use drop_locator::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg
}
}
115 changes: 115 additions & 0 deletions contracts/locator/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use crate::{
error::ContractResult,
msg::{AddChainList, ChainInfo, ExecuteMsg, InstantiateMsg, QueryMsg, RemoveChainList},
state::STATE,
};
use cosmwasm_std::{
attr, entry_point, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Order,
Response, StdResult,
};
use cw2::set_contract_version;
use cw_ownable::{get_ownership, update_ownership};
use drop_helpers::answer::response;
use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery};

const CONTRACT_NAME: &str = concat!("crates.io:drop-staking__", env!("CARGO_PKG_NAME"));
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_msg: InstantiateMsg,
) -> ContractResult<Response<NeutronMsg>> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
cw_ownable::initialize_owner(deps.storage, deps.api, Some(info.sender.as_str()))?;
Ok(response(
"instantiate",
CONTRACT_NAME,
vec![attr("owner", &info.sender)],
))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<NeutronQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Chains {} => query_chains(deps),
QueryMsg::Chain { name } => query_chain(deps, name),
QueryMsg::Ownership {} => Ok(to_json_binary(&get_ownership(deps.storage)?)?),
}
}

pub fn query_chain(deps: Deps<NeutronQuery>, name: String) -> StdResult<Binary> {
let chain = STATE.load(deps.storage, name.clone())?;
to_json_binary(&ChainInfo {
name: name.clone(),
details: chain.clone(),
})
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn query_chains(deps: Deps<NeutronQuery>) -> StdResult<Binary> {
let chains: StdResult<Vec<_>> = STATE
.range_raw(deps.storage, None, None, Order::Ascending)
.map(|item| {
item.map(|(key, value)| ChainInfo {
name: String::from_utf8(key).unwrap(),
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
details: value.clone(),
})
})
.collect();
let chains = chains.unwrap_or_default();
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
to_json_binary(&chains)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> ContractResult<Response<NeutronMsg>> {
match msg {
ExecuteMsg::AddChains(msg) => execute_add_chains(deps, env, info, msg),
ExecuteMsg::RemoveChains(msg) => execute_remove_chains(deps, env, info, msg),
ExecuteMsg::UpdateOwnership(action) => {
update_ownership(deps.into_empty(), &env.block, &info.sender, action)?;
Ok(Response::new())
}
}
}

pub fn execute_remove_chains(
deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: RemoveChainList,
) -> ContractResult<Response<NeutronMsg>> {
cw_ownable::assert_owner(deps.storage, &info.sender)?;
let mut attrs: Vec<Attribute> = Vec::new();
msg.names.iter().for_each(|name| {
STATE.remove(deps.storage, name.clone());
match STATE.has(deps.storage, name.clone()) {
true => attrs.push(attr("skip", name.clone())),
false => attrs.push(attr("remove", name.clone())),
}
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
});
Ok(response("execute-remove-chains", CONTRACT_NAME, attrs))
}

pub fn execute_add_chains(
deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: AddChainList,
) -> ContractResult<Response<NeutronMsg>> {
cw_ownable::assert_owner(deps.storage, &info.sender)?;
let mut attrs: Vec<Attribute> = Vec::new();
for chain in msg.chains {
match STATE.save(deps.storage, chain.name.clone(), &chain.details.clone()) {
Ok(_) => attrs.push(attr("add", chain.name.clone())),
Err(_) => attrs.push(attr("skip", chain.name.clone())),
}
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
}
Ok(response("execute-add-chains", CONTRACT_NAME, attrs))
}
25 changes: 25 additions & 0 deletions contracts/locator/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cosmwasm_std::{Instantiate2AddressError, StdError};
use cw_ownable::OwnershipError;
use neutron_sdk::NeutronError;

use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
#[error("{0}")]
NeutronError(#[from] NeutronError),
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
#[error("{0}")]
OwnershipError(#[from] OwnershipError),
#[error("Could not calculcate instantiate2 address: {0}")]
Instantiate2AddressError(#[from] Instantiate2AddressError),
#[error("Unauthorized")]
Unauthorized {},
#[error("Unimplemented")]
Unimplemented {},
#[error("Unknown")]
Unknown {},
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
}

pub type ContractResult<T> = Result<T, ContractError>;
4 changes: 4 additions & 0 deletions contracts/locator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod contract;
pub mod error;
pub mod msg;
pub mod state;
45 changes: 45 additions & 0 deletions contracts/locator/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::state::ChainDetails;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cw_ownable::{cw_ownable_execute, cw_ownable_query};

#[cw_serde]
pub struct InstantiateMsg {}

#[cw_serde]
pub struct AddChain {
pub name: String,
pub details: ChainDetails,
}

#[cw_serde]
pub struct RemoveChainList {
pub names: Vec<String>,
}

#[cw_serde]
pub struct AddChainList {
pub chains: Vec<AddChain>,
}

#[cw_ownable_execute]
#[cw_serde]
pub enum ExecuteMsg {
AddChains(AddChainList),
albertandrejev marked this conversation as resolved.
Show resolved Hide resolved
RemoveChains(RemoveChainList),
}

#[cw_serde]
pub struct ChainInfo {
pub name: String,
pub details: ChainDetails,
}

#[cw_ownable_query]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(ChainInfo)]
Chain { name: String },
#[returns(Vec<ChainInfo>)]
Chains {},
}
26 changes: 26 additions & 0 deletions contracts/locator/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use cosmwasm_schema::cw_serde;
use cw_storage_plus::Map;

#[cw_serde]
pub struct ChainDetails {
pub astroport_exchange_handler: String,
pub auto_withdrawer: String,
pub core: String,
pub distribution: String,
pub factory: String,
pub hook_tester: String,
pub proposal_votes_poc: String,
pub provider_proposals_poc: String,
pub pump: String,
pub puppeteer: String,
pub puppeteer_authz: String,
pub rewards_manager: String,
pub strategy: String,
pub token: String,
pub validators_set: String,
pub validator_stats: String,
pub withdrawal_manager: String,
pub withdrawal_voucher: String,
}

pub const STATE: Map<String, ChainDetails> = Map::new("state");
Loading