Skip to content

Commit

Permalink
Merge pull request #25 from burnt-labs/feat/treasury
Browse files Browse the repository at this point in the history
Treasury Contract
  • Loading branch information
ash-burnt authored Jun 30, 2024
2 parents 60ebe25 + 5a2375b commit e941658
Show file tree
Hide file tree
Showing 28 changed files with 637 additions and 21 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"account"
"contracts/*",
]

[profile.release]
Expand All @@ -9,18 +9,16 @@ overflow-checks = true # Disable integer overflow checks.


[workspace.dependencies]
cosmos-sdk-proto = { version = "0.19", default-features = false }
cosmwasm-schema = "=1.4.1"
cosmwasm-std = { version = "=1.4.1", features = ["stargate"] }
cw2 = "1.1.1"
cw-storage-plus = "1.1.0"
cw-utils = "1.0.2"
hex = "0.4"
prost = "0.11"
sha2 = { version = "0.10.8", features = ["oid"]}
thiserror = "1"
tiny-keccak = { version = "2", features = ["keccak"] }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = "1.0.87"
schemars = "0.8.10"
ripemd = "0.1.3"
Expand All @@ -30,3 +28,8 @@ phf = { version = "0.11.2", features = ["macros"] }
rsa = { version = "0.9.2" }
getrandom = { version = "0.2.10", features = ["custom"] }
p256 = {version = "0.13.2", features = ["ecdsa-core", "arithmetic", "serde"]}
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
cosmos-sdk-proto = {git = "https://github.com/burnt-labs/cosmos-rust.git", rev = "9108ae0517bd9fd543c0662e06598032a642e426", default-features = false, features = ["cosmwasm", "xion"]}
osmosis-std-derive = "0.13.2"
prost-types = "0.12.6"
pbjson-types = "0.6.0"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

```bash

docker run --rm -v "$(pwd)":/code \
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0
cosmwasm/optimizer:0.15.1
```
8 changes: 2 additions & 6 deletions account/Cargo.toml → contracts/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ phf = { workspace = true }
rsa = { workspace = true }
getrandom = { workspace = true }
p256 = { workspace = true }
url = "2.4.1"
coset = "0.3.5"
futures = "0.3.29"
async-trait = "0.1.74"
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
osmosis-std-derive = "0.13.2"
prost = { workspace = true }
osmosis-std-derive = { workspace = true }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn verify(
let query = proto::QueryValidateJWTRequest {
aud: aud.to_string(),
sub: sub.to_string(),
sig_bytes: String::from_utf8(sig_bytes.into()).unwrap(),
sig_bytes: String::from_utf8(sig_bytes.into())?,
// tx_hash: challenge,
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions account/src/error.rs → contracts/account/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub enum ContractError {

#[error("cannot override existing authenticator at index {index}")]
OverridingIndex { index: u8 },

#[error(transparent)]
SerdeJSON(#[from] serde_json::Error),

#[error(transparent)]
FromUTF8(#[from] std::string::FromUtf8Error),
}

pub type ContractResult<T> = Result<T, ContractError>;
10 changes: 2 additions & 8 deletions account/src/execute.rs → contracts/account/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ pub fn init(
Ok(
Response::new().add_event(Event::new("create_abstract_account").add_attributes(vec![
("contract_address", env.contract.address.to_string()),
(
"authenticator",
serde_json::to_string(&add_authenticator).unwrap(),
),
("authenticator", serde_json::to_string(&add_authenticator)?),
("authenticator_id", add_authenticator.get_id().to_string()),
])),
)
Expand Down Expand Up @@ -227,10 +224,7 @@ pub fn add_auth_method(
Ok(
Response::new().add_event(Event::new("add_auth_method").add_attributes(vec![
("contract_address", env.contract.address.clone().to_string()),
(
"authenticator",
serde_json::to_string(&add_authenticator).unwrap(),
),
("authenticator", serde_json::to_string(&add_authenticator)?),
])),
)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions contracts/treasury/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "treasury"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
schemars = { workspace = true }
cosmos-sdk-proto = { workspace = true }
prost = { workspace = true }
osmosis-std-derive = { workspace = true }
prost-types = { workspace = true }
pbjson-types = { workspace = true }
53 changes: 53 additions & 0 deletions contracts/treasury/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::error::ContractResult;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::{execute, query, CONTRACT_NAME, CONTRACT_VERSION};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
};

#[entry_point]
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
execute::init(deps, info, msg.admin, msg.type_urls, msg.grant_configs)
}

#[entry_point]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> ContractResult<Response> {
match msg {
ExecuteMsg::DeployFeeGrant {
authz_granter,
authz_grantee,
msg_type_url,
} => execute::deploy_fee_grant(deps, env, authz_granter, authz_grantee, msg_type_url),
ExecuteMsg::UpdateAdmin { new_admin } => execute::update_admin(deps, info, new_admin),
ExecuteMsg::UpdateGrantConfig {
msg_type_url,
grant_config,
} => execute::update_grant_config(deps, info, msg_type_url, grant_config),
ExecuteMsg::RemoveGrantConfig { msg_type_url } => {
execute::remove_grant_config(deps, info, msg_type_url)
}
}
}

#[entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GrantConfigByTypeUrl { msg_type_url } => to_binary(
&query::grant_config_by_type_url(deps.storage, msg_type_url)?,
),
QueryMsg::GrantConfigTypeUrls {} => {
to_binary(&query::grant_config_type_urls(deps.storage)?)
}
}
}
31 changes: 31 additions & 0 deletions contracts/treasury/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#[derive(Debug, thiserror::Error)]
pub enum ContractError {
#[error(transparent)]
Std(#[from] cosmwasm_std::StdError),

#[error(transparent)]
Encode(#[from] cosmos_sdk_proto::prost::EncodeError),

#[error("authz grant not found")]
AuthzGrantNotFound,

#[error("authz grant has no authorization")]
AuthzGrantNoAuthorization,

#[error("authz grant did not match config")]
AuthzGrantMismatch,

#[error("invalid allowance type: {msg_type_url}")]
InvalidAllowanceType { msg_type_url: String },

#[error("allowance unset")]
AllowanceUnset,

#[error("config mismatch")]
ConfigurationMismatch,

#[error("unauthorized")]
Unauthorized,
}

pub type ContractResult<T> = Result<T, ContractError>;
Loading

0 comments on commit e941658

Please sign in to comment.