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

Treasury Contract #25

Merged
merged 36 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6e124ee
initial pass
ash-burnt May 30, 2024
6ad463a
WIP: add in custom authz query
Peartes May 31, 2024
c04acb0
update url
ash-burnt Jun 1, 2024
bd26a96
initial pass unpacking allowance
ash-burnt Jun 3, 2024
fca281b
missed file
ash-burnt Jun 3, 2024
7c2edcc
query and instantiate
ash-burnt Jun 3, 2024
1e89895
admin commands
ash-burnt Jun 3, 2024
45e11fa
add cosmos protos with compiled xion serde definitions
ash-burnt Jun 4, 2024
b6268ca
custom allowance types
ash-burnt Jun 4, 2024
f67abe5
fmt
ash-burnt Jun 4, 2024
84f0fd3
updated protos
ash-burnt Jun 4, 2024
412286d
remove deps on tonic/tokio
ash-burnt Jun 4, 2024
643984b
add some events
ash-burnt Jun 4, 2024
1763e9e
proper submodule definition
ash-burnt Jun 4, 2024
770d96c
chore: serialize authz query request
Peartes Jun 4, 2024
b44ae37
ref: remove custom querier
Peartes Jun 4, 2024
b629004
avoid partial move
ash-burnt Jun 4, 2024
446fb85
cargo warnings
ash-burnt Jun 4, 2024
362a20b
binary converstion
ash-burnt Jun 4, 2024
3600417
todo
ash-burnt Jun 4, 2024
c0a3a02
reorganize for workspace optimizer
ash-burnt Jun 4, 2024
f792cdb
linting
ash-burnt Jun 4, 2024
3b949a0
compile
ash-burnt Jun 4, 2024
329f0af
fmt
ash-burnt Jun 4, 2024
2318c9b
consistent naming
ash-burnt Jun 5, 2024
93f9fdb
chore: grants query using msg_type
Peartes Jun 14, 2024
2d21ea0
Merge branch 'feat/treasury' of github.com:burnt-labs/contracts into …
Peartes Jun 14, 2024
78d0a1c
linting
ash-burnt Jun 14, 2024
e053a9e
fix: serializing authz grants and feegrant
Peartes Jun 16, 2024
143ec7b
fix: comparing authz grants
Peartes Jun 18, 2024
71b1771
chore: properly deserialize allowance structs
Peartes Jun 19, 2024
1cdeeb8
error type
ash-burnt Jun 19, 2024
47eb6ea
max duration
ash-burnt Jun 19, 2024
39be406
lints
ash-burnt Jun 20, 2024
cea1e2b
cleanup unwraps in execution
ash-burnt Jun 20, 2024
5a2375b
chore: renaming msg exec
Peartes Jun 25, 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
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.
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
Loading