diff --git a/Cargo.lock b/Cargo.lock index a5281143..abf7dcb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -604,19 +604,6 @@ dependencies = [ "sha2 0.10.6", ] -[[package]] -name = "legacy-account" -version = "0.1.0" -dependencies = [ - "controller", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test", - "prost 0.11.9", - "schemars", - "serde", -] - [[package]] name = "libc" version = "0.2.138" @@ -1037,7 +1024,6 @@ dependencies = [ "job-account", "job-account-tracker", "json-codec-wasm", - "legacy-account", "resolver", "schemars", "serde-json-wasm 0.4.1", @@ -1093,31 +1079,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "warp-legacy-account" -version = "0.1.0" -dependencies = [ - "anyhow", - "base64", - "controller", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-asset", - "cw-multi-test", - "cw-storage-plus 0.16.0", - "cw-utils 0.16.0", - "cw2 0.16.0", - "cw20", - "cw721", - "json-codec-wasm", - "legacy-account", - "prost 0.11.9", - "schemars", - "serde-json-wasm 0.4.1", - "thiserror", -] - [[package]] name = "warp-resolver" version = "0.1.0" diff --git a/contracts/warp-controller/Cargo.toml b/contracts/warp-controller/Cargo.toml index 8e2000f8..e669cfbf 100644 --- a/contracts/warp-controller/Cargo.toml +++ b/contracts/warp-controller/Cargo.toml @@ -39,7 +39,6 @@ cw-storage-plus = "0.16" cw-utils = "0.16" cw2 = "0.16" cw20 = "0.16" -legacy-account = { path = "../../packages/legacy-account", default-features = false, version = "*" } job-account = { path = "../../packages/job-account", default-features = false, version = "*" } job-account-tracker = { path = "../../packages/job-account-tracker", default-features = false, version = "*" } controller = { path = "../../packages/controller", default-features = false, version = "*" } diff --git a/contracts/warp-controller/examples/warp-controller-schema.rs b/contracts/warp-controller/examples/warp-controller-schema.rs index 63f58aa2..961b7ab8 100644 --- a/contracts/warp-controller/examples/warp-controller-schema.rs +++ b/contracts/warp-controller/examples/warp-controller-schema.rs @@ -2,7 +2,6 @@ use std::env::current_dir; use std::fs::create_dir_all; use controller::{ - account::{LegacyAccountResponse, LegacyAccountsResponse}, job::{JobResponse, JobsResponse}, QueryMsg, State, StateResponse, {Config, ConfigResponse, ExecuteMsg, InstantiateMsg}, }; @@ -23,6 +22,4 @@ fn main() { export_schema(&schema_for!(StateResponse), &out_dir); export_schema(&schema_for!(JobResponse), &out_dir); export_schema(&schema_for!(JobsResponse), &out_dir); - export_schema(&schema_for!(LegacyAccountResponse), &out_dir); - export_schema(&schema_for!(LegacyAccountsResponse), &out_dir); } diff --git a/contracts/warp-controller/src/contract.rs b/contracts/warp-controller/src/contract.rs index 504a5d45..4522c91a 100644 --- a/contracts/warp-controller/src/contract.rs +++ b/contracts/warp-controller/src/contract.rs @@ -132,10 +132,6 @@ pub fn execute( nonpayable(&info).unwrap(); execute::controller::update_config(deps, env, info, data, config) } - ExecuteMsg::MigrateLegacyAccounts(data) => { - nonpayable(&info).unwrap(); - migrate::legacy_account::migrate_legacy_accounts(deps, info, data, config) - } ExecuteMsg::MigrateFreeJobAccounts(data) => { nonpayable(&info).unwrap(); migrate::job_account::migrate_free_job_accounts(deps.as_ref(), env, info, data, config) @@ -165,15 +161,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::QueryJob(data) => to_binary(&query::job::query_job(deps, env, data)?), QueryMsg::QueryJobs(data) => to_binary(&query::job::query_jobs(deps, env, data)?), - - // For job account, please query it via the account tracker contract - QueryMsg::QueryLegacyAccount(data) => { - to_binary(&query::account::query_legacy_account(deps, env, data)?) - } - QueryMsg::QueryLegacyAccounts(data) => { - to_binary(&query::account::query_legacy_accounts(deps, env, data)?) - } - QueryMsg::QueryConfig(data) => { to_binary(&query::controller::query_config(deps, env, data)?) } diff --git a/contracts/warp-controller/src/execute/job.rs b/contracts/warp-controller/src/execute/job.rs index 7025a848..ad0ae5fc 100644 --- a/contracts/warp-controller/src/execute/job.rs +++ b/contracts/warp-controller/src/execute/job.rs @@ -12,16 +12,12 @@ use cosmwasm_std::{ SubMsg, Uint128, Uint64, WasmMsg, }; -use crate::{ - state::LEGACY_ACCOUNTS, - util::{ - fee::deduct_from_native_funds, - legacy_account::is_legacy_account, - msg::{ - build_account_withdraw_assets_msg, build_free_account_msg, - build_instantiate_warp_account_msg, build_taken_account_msg, build_transfer_cw20_msg, - build_transfer_cw721_msg, build_transfer_native_funds_msg, - }, +use crate::util::{ + fee::deduct_from_native_funds, + msg::{ + build_account_withdraw_assets_msg, build_free_account_msg, + build_instantiate_warp_account_msg, build_taken_account_msg, build_transfer_cw20_msg, + build_transfer_cw721_msg, build_transfer_native_funds_msg, }, }; @@ -358,7 +354,6 @@ pub fn delete_job( fee_denom_paid_amount: Uint128, ) -> Result { let job = JobQueue::get(&deps, data.id.into())?; - let legacy_account = LEGACY_ACCOUNTS().may_load(deps.storage, job.owner.clone())?; let job_account_addr = job.account.clone(); if job.status != JobStatus::Pending { @@ -394,29 +389,27 @@ pub fn delete_job( vec![Coin::new(fee.u128(), config.fee_denom.clone())], )); - if !is_legacy_account(legacy_account, job_account_addr.clone()) { - // Free account - msgs.push(build_free_account_msg( + // Free account + msgs.push(build_free_account_msg( + config.job_account_tracker_address.to_string(), + job.owner.to_string(), + job_account_addr.to_string(), + job.id, + )); + + if let Some(funding_account) = job.funding_account { + msgs.push(build_free_funding_account_msg( config.job_account_tracker_address.to_string(), job.owner.to_string(), - job_account_addr.to_string(), + funding_account.to_string(), job.id, )); - if let Some(funding_account) = job.funding_account { - msgs.push(build_free_funding_account_msg( - config.job_account_tracker_address.to_string(), - job.owner.to_string(), - funding_account.to_string(), - job.id, - )); - - // withdraws all native funds from funding account - msgs.push(build_account_withdraw_assets_msg( - funding_account.to_string(), - vec![AssetInfo::Native(config.fee_denom)], - )); - } + // withdraws all native funds from funding account + msgs.push(build_account_withdraw_assets_msg( + funding_account.to_string(), + vec![AssetInfo::Native(config.fee_denom)], + )); } // Job owner withdraw all assets that are listed from warp account to itself @@ -477,7 +470,6 @@ pub fn execute_job( config: Config, ) -> Result { let job = JobQueue::get(&deps, data.id.into())?; - let legacy_account = LEGACY_ACCOUNTS().may_load(deps.storage, job.owner.clone())?; let job_account_addr = job.account.clone(); if job.status != JobStatus::Pending { @@ -548,23 +540,21 @@ pub fn execute_job( vec![Coin::new(job.reward.u128(), config.fee_denom)], )); - if !is_legacy_account(legacy_account, job_account_addr.clone()) { - // Free account - msgs.push(build_free_account_msg( + // Free account + msgs.push(build_free_account_msg( + config.job_account_tracker_address.to_string(), + job.owner.to_string(), + job_account_addr.to_string(), + job.id, + )); + + if let Some(funding_account) = job.funding_account { + msgs.push(build_free_funding_account_msg( config.job_account_tracker_address.to_string(), job.owner.to_string(), - job_account_addr.to_string(), + funding_account.to_string(), job.id, )); - - if let Some(funding_account) = job.funding_account { - msgs.push(build_free_funding_account_msg( - config.job_account_tracker_address.to_string(), - job.owner.to_string(), - funding_account.to_string(), - job.id, - )); - } } Ok(Response::new() @@ -585,7 +575,6 @@ pub fn evict_job( config: Config, ) -> Result { let job = JobQueue::get(&deps, data.id.into())?; - let legacy_account = LEGACY_ACCOUNTS().may_load(deps.storage, job.owner.clone())?; let job_account_addr = job.account.clone(); if job.status != JobStatus::Pending { @@ -618,15 +607,13 @@ pub fn evict_job( )], )); - if !is_legacy_account(legacy_account, job_account_addr.clone()) { - // Free account - msgs.push(build_free_account_msg( - config.job_account_tracker_address.to_string(), - job.owner.to_string(), - job_account_addr.to_string(), - job.id, - )); - } + // Free account + msgs.push(build_free_account_msg( + config.job_account_tracker_address.to_string(), + job.owner.to_string(), + job_account_addr.to_string(), + job.id, + )); Ok(Response::new() .add_messages(msgs) diff --git a/contracts/warp-controller/src/migrate/legacy_account.rs b/contracts/warp-controller/src/migrate/legacy_account.rs deleted file mode 100644 index c7c7baf0..00000000 --- a/contracts/warp-controller/src/migrate/legacy_account.rs +++ /dev/null @@ -1,40 +0,0 @@ -use cosmwasm_std::{to_binary, DepsMut, MessageInfo, Order, Response, WasmMsg}; -use cw_storage_plus::Bound; - -use crate::{state::LEGACY_ACCOUNTS, ContractError}; -use controller::{Config, MigrateLegacyAccountsMsg}; - -pub fn migrate_legacy_accounts( - deps: DepsMut, - info: MessageInfo, - msg: MigrateLegacyAccountsMsg, - config: Config, -) -> Result { - if info.sender != config.owner { - return Err(ContractError::Unauthorized {}); - } - - let start_after = match msg.start_after { - None => None, - Some(s) => Some(deps.api.addr_validate(s.as_str())?), - }; - let start_after = start_after.map(Bound::exclusive); - - let account_keys: Result, _> = LEGACY_ACCOUNTS() - .keys(deps.storage, start_after, None, Order::Ascending) - .take(msg.limit as usize) - .collect(); - let account_keys = account_keys?; - let mut migration_msgs = vec![]; - - for account_key in account_keys { - let account_address = LEGACY_ACCOUNTS().load(deps.storage, account_key)?.account; - migration_msgs.push(WasmMsg::Migrate { - contract_addr: account_address.to_string(), - new_code_id: msg.warp_legacy_account_code_id.u64(), - msg: to_binary(&legacy_account::MigrateMsg {})?, - }) - } - - Ok(Response::new().add_messages(migration_msgs)) -} diff --git a/contracts/warp-controller/src/migrate/mod.rs b/contracts/warp-controller/src/migrate/mod.rs index d8df4a31..8a179a31 100644 --- a/contracts/warp-controller/src/migrate/mod.rs +++ b/contracts/warp-controller/src/migrate/mod.rs @@ -1,3 +1,2 @@ pub(crate) mod job; pub(crate) mod job_account; -pub(crate) mod legacy_account; diff --git a/contracts/warp-controller/src/query/account.rs b/contracts/warp-controller/src/query/account.rs deleted file mode 100644 index f5817723..00000000 --- a/contracts/warp-controller/src/query/account.rs +++ /dev/null @@ -1,40 +0,0 @@ -use cosmwasm_std::{Deps, Env, Order, StdResult}; -use cw_storage_plus::Bound; - -use crate::state::{LEGACY_ACCOUNTS, QUERY_PAGE_SIZE}; - -use controller::account::{ - LegacyAccountResponse, LegacyAccountsResponse, QueryLegacyAccountMsg, QueryLegacyAccountsMsg, -}; - -pub fn query_legacy_account( - deps: Deps, - _env: Env, - data: QueryLegacyAccountMsg, -) -> StdResult { - Ok(LegacyAccountResponse { - account: LEGACY_ACCOUNTS() - .load(deps.storage, deps.api.addr_validate(data.owner.as_str())?)?, - }) -} - -pub fn query_legacy_accounts( - deps: Deps, - _env: Env, - data: QueryLegacyAccountsMsg, -) -> StdResult { - let start_after = match data.start_after { - None => None, - Some(s) => Some(deps.api.addr_validate(s.as_str())?), - }; - let start_after = start_after.map(Bound::exclusive); - let infos = LEGACY_ACCOUNTS() - .range(deps.storage, start_after, None, Order::Ascending) - .take(data.limit.unwrap_or(QUERY_PAGE_SIZE) as usize) - .collect::>>()?; - let mut accounts = vec![]; - for tuple in infos { - accounts.push(tuple.1) - } - Ok(LegacyAccountsResponse { accounts }) -} diff --git a/contracts/warp-controller/src/query/mod.rs b/contracts/warp-controller/src/query/mod.rs index ee75d71c..b10bee4a 100644 --- a/contracts/warp-controller/src/query/mod.rs +++ b/contracts/warp-controller/src/query/mod.rs @@ -1,3 +1,2 @@ -pub(crate) mod account; pub(crate) mod controller; pub(crate) mod job; diff --git a/contracts/warp-controller/src/reply/job.rs b/contracts/warp-controller/src/reply/job.rs index e4be78f7..2a313e05 100644 --- a/contracts/warp-controller/src/reply/job.rs +++ b/contracts/warp-controller/src/reply/job.rs @@ -6,14 +6,10 @@ use cosmwasm_std::{ use crate::{ error::map_contract_error, execute::fee::{compute_burn_fee, compute_creation_fee, compute_maintenance_fee}, - state::{JobQueue, CONFIG, LEGACY_ACCOUNTS, STATE}, - util::{ - legacy_account::is_legacy_account, - msg::{ - build_account_execute_generic_msgs, build_account_withdraw_assets_msg, - build_take_funding_account_msg, build_taken_account_msg, - build_transfer_native_funds_msg, - }, + state::{JobQueue, CONFIG, STATE}, + util::msg::{ + build_account_execute_generic_msgs, build_account_withdraw_assets_msg, + build_take_funding_account_msg, build_taken_account_msg, build_transfer_native_funds_msg, }, ContractError, }; @@ -60,18 +56,13 @@ pub fn execute_job( let reward_plus_fee = finished_job.reward + total_fees; - let legacy_account = LEGACY_ACCOUNTS().may_load(deps.storage, finished_job.owner.clone())?; let job_account_addr = finished_job.account.clone(); let mut recurring_job_created = false; - // backwards compability with legacy accounts, funding account is job's account - let funding_account_addr = finished_job - .funding_account - .clone() - .unwrap_or(job_account_addr.clone()); - if finished_job.recurring { + let funding_account_addr = finished_job.funding_account.clone().unwrap(); + let operational_amount = deps .querier .query::(&QueryRequest::Bank(BankQuery::Balance { @@ -224,23 +215,23 @@ pub fn execute_job( } if recurring_job_created { - if !is_legacy_account(legacy_account, job_account_addr.clone()) { - // Take job account with the new job - msgs.push(build_taken_account_msg( - config.job_account_tracker_address.to_string(), - finished_job.owner.to_string(), - job_account_addr.to_string(), - new_job_id, - )); + let funding_account_addr = finished_job.funding_account.clone().unwrap(); - // take funding account with new job - msgs.push(build_take_funding_account_msg( - config.job_account_tracker_address.to_string(), - finished_job.owner.to_string(), - funding_account_addr.to_string(), - new_job_id, - )); - } + // Take job account with the new job + msgs.push(build_taken_account_msg( + config.job_account_tracker_address.to_string(), + finished_job.owner.to_string(), + job_account_addr.to_string(), + new_job_id, + )); + + // take funding account with new job + msgs.push(build_take_funding_account_msg( + config.job_account_tracker_address.to_string(), + finished_job.owner.to_string(), + funding_account_addr.to_string(), + new_job_id, + )); } else { // No new job created, account has been free in execute_job, no need to free here again // Job owner withdraw all assets that are listed from warp account to itself diff --git a/contracts/warp-controller/src/state.rs b/contracts/warp-controller/src/state.rs index 4c58430a..816d5197 100644 --- a/contracts/warp-controller/src/state.rs +++ b/contracts/warp-controller/src/state.rs @@ -1,8 +1,7 @@ -use cosmwasm_std::{Addr, DepsMut, Env, Uint64}; +use cosmwasm_std::{DepsMut, Env, Uint64}; use cw_storage_plus::{Index, IndexList, IndexedMap, Item, MultiIndex, UniqueIndex}; use controller::{ - account::LegacyAccount, job::{Job, JobStatus, UpdateJobMsg}, Config, State, }; @@ -53,29 +52,6 @@ pub fn FINISHED_JOBS<'a>() -> IndexedMap<'a, u64, Job, JobIndexes<'a>> { IndexedMap::new("finished_jobs_v6", indexes) } -pub struct LegacyAccountIndexes<'a> { - pub account: UniqueIndex<'a, Addr, LegacyAccount>, -} - -impl IndexList for LegacyAccountIndexes<'_> { - fn get_indexes(&'_ self) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.account]; - Box::new(v.into_iter()) - } -} - -// !!! DEPRECATED !!! -// LEGACY_ACCOUNTS stores legacy account (all user's jobs share the same account, this is the old way of doing things before introducing job account) -// As of late 2023, we introduced job account meaning each job will have its own account, no more job sharing the same account -// We keep this for backward compatibility so user can withdraw from their old accounts -#[allow(non_snake_case)] -pub fn LEGACY_ACCOUNTS<'a>() -> IndexedMap<'a, Addr, LegacyAccount, LegacyAccountIndexes<'a>> { - let indexes = LegacyAccountIndexes { - account: UniqueIndex::new(|account| account.account.clone(), "accounts__account"), - }; - IndexedMap::new("accounts", indexes) -} - pub const QUERY_PAGE_SIZE: u32 = 50; pub const CONFIG: Item = Item::new("config"); pub const STATE: Item = Item::new("state"); diff --git a/contracts/warp-controller/src/util/legacy_account.rs b/contracts/warp-controller/src/util/legacy_account.rs deleted file mode 100644 index 86da41ec..00000000 --- a/contracts/warp-controller/src/util/legacy_account.rs +++ /dev/null @@ -1,8 +0,0 @@ -use controller::account::LegacyAccount; -use cosmwasm_std::Addr; - -pub fn is_legacy_account(legacy_account: Option, job_account_addr: Addr) -> bool { - legacy_account.map_or(false, |legacy_account| { - legacy_account.account == job_account_addr - }) -} diff --git a/contracts/warp-controller/src/util/mod.rs b/contracts/warp-controller/src/util/mod.rs index 5a7c7196..e87a1010 100644 --- a/contracts/warp-controller/src/util/mod.rs +++ b/contracts/warp-controller/src/util/mod.rs @@ -1,4 +1,3 @@ pub(crate) mod fee; pub(crate) mod filter; -pub(crate) mod legacy_account; pub(crate) mod msg; diff --git a/contracts/warp-job-account-tracker/examples/warp-job-account-tracker-schema.rs b/contracts/warp-job-account-tracker/examples/warp-job-account-tracker-schema.rs index 1c25f770..b765ec16 100644 --- a/contracts/warp-job-account-tracker/examples/warp-job-account-tracker-schema.rs +++ b/contracts/warp-job-account-tracker/examples/warp-job-account-tracker-schema.rs @@ -3,8 +3,8 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; use job_account_tracker::{ - Account, AccountResponse, AccountsResponse, Config, ConfigResponse, ExecuteMsg, InstantiateMsg, - QueryMsg, FundingAccountResponse, FundingAccountsResponse, + Account, AccountResponse, AccountsResponse, Config, ConfigResponse, ExecuteMsg, + FundingAccountResponse, FundingAccountsResponse, InstantiateMsg, QueryMsg, }; fn main() { diff --git a/contracts/warp-legacy-account/.cargo/config b/contracts/warp-legacy-account/.cargo/config deleted file mode 100644 index b1f3d363..00000000 --- a/contracts/warp-legacy-account/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --example warp-legacy-account-schema" diff --git a/contracts/warp-legacy-account/.gitignore b/contracts/warp-legacy-account/.gitignore deleted file mode 100644 index 9095deaa..00000000 --- a/contracts/warp-legacy-account/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# Build results -/target -/schema - -# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) -.cargo-ok - -# Text file backups -**/*.rs.bk - -# macOS -.DS_Store - -# IDEs -*.iml -.idea diff --git a/contracts/warp-legacy-account/Cargo.toml b/contracts/warp-legacy-account/Cargo.toml deleted file mode 100644 index b4350b67..00000000 --- a/contracts/warp-legacy-account/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -name = "warp-legacy-account" -version = "0.1.0" -authors = ["Terra Money "] -edition = "2021" - -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 = [] - -[package.metadata.scripts] -optimize = """docker run --rm -v "${process.cwd()}":/code \ - -v "${path.join(process.cwd(), "../../", "packages")}":/packages \ - --mount type=volume,source="${contract}_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer${process.env.TERRARIUM_ARCH_ARM64 ? "-arm64" : ""}:0.12.6 -""" - -[dependencies] -cosmwasm-std = "1.1" -cosmwasm-storage = "1.1" -cosmwasm-schema = "1.1" -base64 = "0.13.0" -cw-asset = "2.2" -cw-storage-plus = "0.16" -cw2 = "0.16" -cw20 = "0.16" -cw721 = "0.16.0" -cw-utils = "0.16" -controller = { path = "../../packages/controller", default-features = false, version = "*" } -legacy-account = { path = "../../packages/legacy-account", default-features = false, version = "*" } -schemars = "0.8" -thiserror = "1" -serde-json-wasm = "0.4.1" -json-codec-wasm = "0.1.0" -prost = "0.11.9" - -[dev-dependencies] -cw-multi-test = "0.16.0" -anyhow = "1.0.71" diff --git a/contracts/warp-legacy-account/README.md b/contracts/warp-legacy-account/README.md deleted file mode 100644 index 954383af..00000000 --- a/contracts/warp-legacy-account/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# CosmWasm Starter Pack - -This is a template to build smart contracts in Rust to run inside a -[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. -To understand the framework better, please read the overview in the -[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), -and dig into the [cosmwasm docs](https://www.cosmwasm.com). -This assumes you understand the theory and just want to get coding. - -## Creating a new repo from template - -Assuming you have a recent version of rust and cargo (v1.58.1+) installed -(via [rustup](https://rustup.rs/)), -then the following should get you a new repo to start a contract: - -Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script. -Unless you did that before, run this line now: - -```sh -cargo install cargo-generate --features vendored-openssl -cargo install cargo-run-script -``` - -Now, use it to create your new contract. -Go to the folder in which you want to place it and run: - - -**Latest: 1.0.0-beta6** - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME -```` - -**Older Version** - -Pass version as branch flag: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch --name PROJECT_NAME -```` - -Example: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME -``` - -You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) -containing a simple working contract and build system that you can customize. - -## Create a Repo - -After generating, you have a initialized local git repo, but no commits, and no remote. -Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). -Then run the following: - -```sh -# this is needed to create a valid Cargo.lock file (see below) -cargo check -git branch -M main -git add . -git commit -m 'Initial Commit' -git remote add origin YOUR-GIT-URL -git push -u origin main -``` - -## CI Support - -We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) -and [Circle CI](.circleci/config.yml) in the generated project, so you can -get up and running with CI right away. - -One note is that the CI runs all `cargo` commands -with `--locked` to ensure it uses the exact same versions as you have locally. This also means -you must have an up-to-date `Cargo.lock` file, which is not auto-generated. -The first time you set up the project (or after adding any dep), you should ensure the -`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by -running `cargo check` or `cargo unit-test`. - -## Using your project - -Once you have your custom repo, you should check out [Developing](./Developing.md) to explain -more on how to run tests and develop code. Or go through the -[online tutorial](https://docs.cosmwasm.com/) to get a better feel -of how to develop. - -[Publishing](./Publishing.md) contains useful information on how to publish your contract -to the world, once you are ready to deploy it on a running blockchain. And -[Importing](./Importing.md) contains information about pulling in other contracts or crates -that have been published. - -Please replace this README file with information about your specific project. You can keep -the `Developing.md` and `Publishing.md` files as useful referenced, but please set some -proper description in the README. - -## Gitpod integration - -[Gitpod](https://www.gitpod.io/) container-based development platform will be enabled on your project by default. - -Workspace contains: - - **rust**: for builds - - [wasmd](https://github.com/CosmWasm/wasmd): for local node setup and client - - **jq**: shell JSON manipulation tool - -Follow [Gitpod Getting Started](https://www.gitpod.io/docs/getting-started) and launch your workspace. - diff --git a/contracts/warp-legacy-account/examples/warp-legacy-account-schema.rs b/contracts/warp-legacy-account/examples/warp-legacy-account-schema.rs deleted file mode 100644 index cec9da8b..00000000 --- a/contracts/warp-legacy-account/examples/warp-legacy-account-schema.rs +++ /dev/null @@ -1,17 +0,0 @@ -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use std::env::current_dir; -use std::fs::create_dir_all; - -use legacy_account::{Config, ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - export_schema(&schema_for!(InstantiateMsg), &out_dir); - export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); - export_schema(&schema_for!(Config), &out_dir); -} diff --git a/contracts/warp-legacy-account/meta/README.md b/contracts/warp-legacy-account/meta/README.md deleted file mode 100644 index 279d1db4..00000000 --- a/contracts/warp-legacy-account/meta/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# The meta folder - -This folder is ignored via the `.genignore` file. It contains meta files -that should not make it into the generated project. - -In particular, it is used for an AppVeyor CI script that runs on `cw-template` -itself (running the cargo-generate script, then testing the generated project). -The `.circleci` and `.github` directories contain scripts destined for any projects created from -this template. - -## Files - -- `appveyor.yml`: The AppVeyor CI configuration -- `test_generate.sh`: A script for generating a project from the template and - runnings builds and tests in it. This works almost like the CI script but - targets local UNIX-like dev environments. diff --git a/contracts/warp-legacy-account/meta/appveyor.yml b/contracts/warp-legacy-account/meta/appveyor.yml deleted file mode 100644 index 5da37f70..00000000 --- a/contracts/warp-legacy-account/meta/appveyor.yml +++ /dev/null @@ -1,61 +0,0 @@ -# This CI configuration tests the cw-template repository itself, -# not the resulting project. We want to ensure that -# 1. the template to project generation works -# 2. the template files are up to date -# -# We chose Appveyor for this task as it allows us to use an arbitrary config -# location. Furthermore it allows us to ship Circle CI and GitHub Actions configs -# generated for the resulting project. - -image: Ubuntu - -environment: - TOOLCHAIN: 1.58.1 - -services: - - docker - -cache: - - $HOME/.rustup/ -> meta/appveyor.yml - # For details about cargo caching see https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci - - $HOME/.cargo/bin/ -> meta/appveyor.yml - - $HOME/.cargo/registry/index/ -> meta/appveyor.yml - - $HOME/.cargo/registry/cache/ -> meta/appveyor.yml - - $HOME/.cargo/git/db/ -> meta/appveyor.yml - -install: - - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain "$TOOLCHAIN" -y - - source $HOME/.cargo/env - - rustc --version - - cargo --version - - rustup target add wasm32-unknown-unknown - - cargo install --features vendored-openssl cargo-generate || true - -build_script: - # No matter what is currently checked out by the CI (main, other branch, PR merge commit), - # we create a temporary local branch from that point with a constant name, which we need for - # cargo generate. - - git branch current-ci-checkout - - cd .. - - cargo generate --git cw-template --name testgen-ci --branch current-ci-checkout - - cd testgen-ci - - ls -lA - - cargo fmt -- --check - - cargo unit-test - - cargo wasm - - cargo schema - - docker build --pull -t "cosmwasm/cw-gitpod-base:${APPVEYOR_REPO_COMMIT}" . - - \[ "${APPVEYOR_REPO_BRANCH}" = "main" \] && image_tag=latest || image_tag=${APPVEYOR_REPO_TAG_NAME} - - docker tag "cosmwasm/cw-gitpod-base:${APPVEYOR_REPO_COMMIT}" "cosmwasm/cw-gitpod-base:${image_tag}" - -on_success: - # publish docker image - - docker login --password-stdin -u "$DOCKER_USER" <<<"$DOCKER_PASS" - - docker push - - docker logout - -branches: -# whitelist long living branches and tags - only: - # - main - - /v\d+\.\d+\.\d+/ diff --git a/contracts/warp-legacy-account/meta/test_generate.sh b/contracts/warp-legacy-account/meta/test_generate.sh deleted file mode 100644 index b9aaa237..00000000 --- a/contracts/warp-legacy-account/meta/test_generate.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -set -o errexit -o nounset -o pipefail -command -v shellcheck > /dev/null && shellcheck "$0" - -REPO_ROOT="$(realpath "$(dirname "$0")/..")" - -TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/cw-template.XXXXXXXXX") -PROJECT_NAME="testgen-local" - -( - echo "Navigating to $TMP_DIR" - cd "$TMP_DIR" - - GIT_BRANCH=$(git -C "$REPO_ROOT" branch --show-current) - - echo "Generating project from local repository (branch $GIT_BRANCH) ..." - cargo generate --git "$REPO_ROOT" --name "$PROJECT_NAME" --branch "$GIT_BRANCH" - - ( - cd "$PROJECT_NAME" - echo "This is what was generated" - ls -lA - - # Check formatting - echo "Checking formatting ..." - cargo fmt -- --check - - # Debug builds first to fail fast - echo "Running unit tests ..." - cargo unit-test - echo "Creating schema ..." - cargo schema - - echo "Building wasm ..." - cargo wasm - ) -) diff --git a/contracts/warp-legacy-account/src/contract.rs b/contracts/warp-legacy-account/src/contract.rs deleted file mode 100644 index ba00f27f..00000000 --- a/contracts/warp-legacy-account/src/contract.rs +++ /dev/null @@ -1,234 +0,0 @@ -use crate::state::CONFIG; -use crate::ContractError; -use controller::account::{AssetInfo, Cw721ExecuteMsg}; -use cosmwasm_std::CosmosMsg::Stargate; -use cosmwasm_std::{ - entry_point, to_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, - Response, StdResult, Uint128, WasmMsg, -}; -use cw20::{BalanceResponse, Cw20ExecuteMsg}; -use cw721::{Cw721QueryMsg, OwnerOfResponse}; -use legacy_account::{ - Config, ExecuteMsg, IbcTransferMsg, InstantiateMsg, MigrateMsg, QueryMsg, TimeoutBlock, - WithdrawAssetsMsg, -}; -use prost::Message; - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn instantiate( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: InstantiateMsg, -) -> Result { - CONFIG.save( - deps.storage, - &Config { - owner: deps.api.addr_validate(&msg.owner)?, - warp_addr: info.sender, - }, - )?; - Ok(Response::new() - .add_attribute("action", "instantiate") - .add_attribute("contract_addr", env.contract.address) - .add_attribute("owner", msg.owner) - .add_attribute("funds", serde_json_wasm::to_string(&info.funds)?) - .add_attribute("cw_funds", serde_json_wasm::to_string(&msg.funds)?)) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let config = CONFIG.load(deps.storage)?; - if info.sender != config.owner && info.sender != config.warp_addr { - return Err(ContractError::Unauthorized {}); - } - match msg { - ExecuteMsg::Generic(data) => Ok(Response::new() - .add_messages(data.msgs) - .add_attribute("action", "generic")), - ExecuteMsg::WithdrawAssets(data) => withdraw_assets(deps, env, info, data), - ExecuteMsg::IbcTransfer(data) => ibc_transfer(deps, env, info, data), - } -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::Config => { - let config = CONFIG.load(deps.storage)?; - to_binary(&config) - } - } -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { - Ok(Response::new()) -} - -pub fn ibc_transfer( - _deps: DepsMut, - env: Env, - _info: MessageInfo, - msg: IbcTransferMsg, -) -> Result { - let mut transfer_msg = msg.transfer_msg.clone(); - - if msg.timeout_block_delta.is_some() && msg.transfer_msg.timeout_block.is_some() { - let block = transfer_msg.timeout_block.unwrap(); - transfer_msg.timeout_block = Some(TimeoutBlock { - revision_number: Some(block.revision_number()), - revision_height: Some(env.block.height + msg.timeout_block_delta.unwrap()), - }) - } - - if msg.timeout_timestamp_seconds_delta.is_some() { - transfer_msg.timeout_timestamp = Some( - env.block - .time - .plus_seconds( - env.block.time.seconds() + msg.timeout_timestamp_seconds_delta.unwrap(), - ) - .nanos(), - ); - } - - Ok(Response::new().add_message(Stargate { - type_url: "/ibc.applications.transfer.v1.MsgTransfer".to_string(), - value: transfer_msg.encode_to_vec().into(), - })) -} - -pub fn withdraw_assets( - deps: DepsMut, - env: Env, - info: MessageInfo, - data: WithdrawAssetsMsg, -) -> Result { - let config = CONFIG.load(deps.storage)?; - if info.sender != config.owner && info.sender != config.warp_addr { - return Err(ContractError::Unauthorized {}); - } - - let mut withdraw_msgs: Vec = vec![]; - - for asset_info in &data.asset_infos { - match asset_info { - AssetInfo::Native(denom) => { - let withdraw_native_msg = - withdraw_asset_native(deps.as_ref(), env.clone(), &config.owner, denom)?; - - match withdraw_native_msg { - None => {} - Some(msg) => withdraw_msgs.push(msg), - } - } - AssetInfo::Cw20(addr) => { - let withdraw_cw20_msg = - withdraw_asset_cw20(deps.as_ref(), env.clone(), &config.owner, addr)?; - - match withdraw_cw20_msg { - None => {} - Some(msg) => withdraw_msgs.push(msg), - } - } - AssetInfo::Cw721(addr, token_id) => { - let withdraw_cw721_msg = - withdraw_asset_cw721(deps.as_ref(), &config.owner, addr, token_id)?; - match withdraw_cw721_msg { - None => {} - Some(msg) => withdraw_msgs.push(msg), - } - } - } - } - - Ok(Response::new() - .add_messages(withdraw_msgs) - .add_attribute("action", "withdraw_assets") - .add_attribute("assets", serde_json_wasm::to_string(&data.asset_infos)?)) -} - -fn withdraw_asset_native( - deps: Deps, - env: Env, - owner: &Addr, - denom: &String, -) -> StdResult> { - let amount = deps.querier.query_balance(env.contract.address, denom)?; - - let res = if amount.amount > Uint128::zero() { - Some(CosmosMsg::Bank(BankMsg::Send { - to_address: owner.to_string(), - amount: vec![amount], - })) - } else { - None - }; - - Ok(res) -} - -fn withdraw_asset_cw20( - deps: Deps, - env: Env, - owner: &Addr, - token: &Addr, -) -> StdResult> { - let amount: BalanceResponse = deps.querier.query_wasm_smart( - token.to_string(), - &cw20::Cw20QueryMsg::Balance { - address: env.contract.address.to_string(), - }, - )?; - - let res = if amount.balance > Uint128::zero() { - Some(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: token.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { - recipient: owner.to_string(), - amount: amount.balance, - })?, - funds: vec![], - })) - } else { - None - }; - - Ok(res) -} - -fn withdraw_asset_cw721( - deps: Deps, - owner: &Addr, - token: &Addr, - token_id: &String, -) -> StdResult> { - let owner_query: OwnerOfResponse = deps.querier.query_wasm_smart( - token.to_string(), - &Cw721QueryMsg::OwnerOf { - token_id: token_id.to_string(), - include_expired: None, - }, - )?; - - let res = if owner_query.owner == *owner { - Some(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: token.to_string(), - msg: to_binary(&Cw721ExecuteMsg::TransferNft { - recipient: owner.to_string(), - token_id: token_id.to_string(), - })?, - funds: vec![], - })) - } else { - None - }; - - Ok(res) -} diff --git a/contracts/warp-legacy-account/src/error.rs b/contracts/warp-legacy-account/src/error.rs deleted file mode 100644 index 85ae8cd0..00000000 --- a/contracts/warp-legacy-account/src/error.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::ContractError::{DecodeError, DeserializationError, SerializationError}; -use cosmwasm_std::StdError; -use thiserror::Error; - -#[derive(Error, Debug, PartialEq)] -pub enum ContractError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("Unauthorized")] - Unauthorized {}, - - #[error("Invalid fee")] - InvalidFee {}, - - #[error("Funds array in message does not match funds array in job.")] - FundsMismatch {}, - - #[error("Reward provided is smaller than minimum")] - RewardTooSmall {}, - - #[error("Invalid arguments")] - InvalidArguments {}, - - #[error("Custom Error val: {val:?}")] - CustomError { val: String }, - // Add any other custom errors you like here. - // Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details. - #[error("Error deserializing data")] - DeserializationError {}, - - #[error("Error serializing data")] - SerializationError {}, - - #[error("Error decoding JSON result")] - DecodeError {}, - - #[error("Error resolving JSON path")] - ResolveError {}, - - #[error("Sub account already taken")] - SubAccountAlreadyTakenError {}, - - #[error("Sub account already free")] - SubAccountAlreadyFreeError {}, - - #[error("Sub account should be taken but it is free")] - SubAccountNotTakenError {}, -} - -impl From for ContractError { - fn from(_: serde_json_wasm::de::Error) -> Self { - DeserializationError {} - } -} - -impl From for ContractError { - fn from(_: serde_json_wasm::ser::Error) -> Self { - SerializationError {} - } -} - -impl From for ContractError { - fn from(_: json_codec_wasm::DecodeError) -> Self { - DecodeError {} - } -} - -impl From for ContractError { - fn from(_: base64::DecodeError) -> Self { - DecodeError {} - } -} diff --git a/contracts/warp-legacy-account/src/lib.rs b/contracts/warp-legacy-account/src/lib.rs deleted file mode 100644 index 90d6bfa8..00000000 --- a/contracts/warp-legacy-account/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod contract; -mod error; -pub mod state; - -#[cfg(test)] -mod tests; - -pub use crate::error::ContractError; diff --git a/contracts/warp-legacy-account/src/state.rs b/contracts/warp-legacy-account/src/state.rs deleted file mode 100644 index 9483f694..00000000 --- a/contracts/warp-legacy-account/src/state.rs +++ /dev/null @@ -1,4 +0,0 @@ -use cw_storage_plus::Item; -use legacy_account::Config; - -pub const CONFIG: Item = Item::new("config"); diff --git a/contracts/warp-legacy-account/src/tests.rs b/contracts/warp-legacy-account/src/tests.rs deleted file mode 100644 index 68871a06..00000000 --- a/contracts/warp-legacy-account/src/tests.rs +++ /dev/null @@ -1,327 +0,0 @@ -use crate::contract::{execute, instantiate}; -use crate::ContractError; -use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; -use cosmwasm_std::{ - to_binary, BankMsg, Coin, CosmosMsg, DistributionMsg, GovMsg, IbcMsg, IbcTimeout, - IbcTimeoutBlock, Response, StakingMsg, Uint128, VoteOption, WasmMsg, -}; -use legacy_account::{ExecuteMsg, GenericMsg, InstantiateMsg}; - -#[test] -fn test_execute_controller() { - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info("vlad_controller", &[]); - - let _instantiate_res = instantiate( - deps.as_mut(), - env.clone(), - info.clone(), - InstantiateMsg { - owner: "vlad".to_string(), - funds: None, - }, - ); - - let execute_msg = ExecuteMsg::Generic(GenericMsg { - msgs: vec![ - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "contract".to_string(), - msg: to_binary("test").unwrap(), - funds: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: "vlad2".to_string(), - amount: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Gov(GovMsg::Vote { - proposal_id: 0, - vote: VoteOption::Yes, - }), - CosmosMsg::Staking(StakingMsg::Delegate { - validator: "vladidator".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - }), - CosmosMsg::Distribution(DistributionMsg::SetWithdrawAddress { - address: "vladdress".to_string(), - }), - CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel_vlad".to_string(), - to_address: "vlad3".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - timeout: IbcTimeout::with_block(IbcTimeoutBlock { - revision: 0, - height: 0, - }), - }), - CosmosMsg::Stargate { - type_url: "utl".to_string(), - value: Default::default(), - }, - ], - }); - - let execute_res = execute(deps.as_mut(), env, info, execute_msg).unwrap(); - - assert_eq!( - execute_res, - Response::new() - .add_attribute("action", "generic") - .add_messages(vec![ - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "contract".to_string(), - msg: to_binary("test").unwrap(), - funds: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: "vlad2".to_string(), - amount: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }] - }), - CosmosMsg::Gov(GovMsg::Vote { - proposal_id: 0, - vote: VoteOption::Yes - }), - CosmosMsg::Staking(StakingMsg::Delegate { - validator: "vladidator".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }, - }), - CosmosMsg::Distribution(DistributionMsg::SetWithdrawAddress { - address: "vladdress".to_string(), - }), - CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel_vlad".to_string(), - to_address: "vlad3".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }, - timeout: IbcTimeout::with_block(IbcTimeoutBlock { - revision: 0, - height: 0 - }), - }), - CosmosMsg::Stargate { - type_url: "utl".to_string(), - value: Default::default() - } - ]) - ) -} - -#[test] -fn test_execute_owner() { - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info("vlad_controller", &[]); - - let _instantiate_res = instantiate( - deps.as_mut(), - env.clone(), - info, - InstantiateMsg { - owner: "vlad".to_string(), - funds: None, - }, - ); - - let execute_msg = ExecuteMsg::Generic(GenericMsg { - msgs: vec![ - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "contract".to_string(), - msg: to_binary("test").unwrap(), - funds: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: "vlad2".to_string(), - amount: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Gov(GovMsg::Vote { - proposal_id: 0, - vote: VoteOption::Yes, - }), - CosmosMsg::Staking(StakingMsg::Delegate { - validator: "vladidator".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - }), - CosmosMsg::Distribution(DistributionMsg::SetWithdrawAddress { - address: "vladdress".to_string(), - }), - CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel_vlad".to_string(), - to_address: "vlad3".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - timeout: IbcTimeout::with_block(IbcTimeoutBlock { - revision: 0, - height: 0, - }), - }), - CosmosMsg::Stargate { - type_url: "utl".to_string(), - value: Default::default(), - }, - ], - }); - - let info2 = mock_info("vlad", &[]); - - let execute_res = execute(deps.as_mut(), env, info2, execute_msg).unwrap(); - - assert_eq!( - execute_res, - Response::new() - .add_attribute("action", "generic") - .add_messages(vec![ - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "contract".to_string(), - msg: to_binary("test").unwrap(), - funds: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: "vlad2".to_string(), - amount: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }] - }), - CosmosMsg::Gov(GovMsg::Vote { - proposal_id: 0, - vote: VoteOption::Yes - }), - CosmosMsg::Staking(StakingMsg::Delegate { - validator: "vladidator".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }, - }), - CosmosMsg::Distribution(DistributionMsg::SetWithdrawAddress { - address: "vladdress".to_string(), - }), - CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel_vlad".to_string(), - to_address: "vlad3".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100) - }, - timeout: IbcTimeout::with_block(IbcTimeoutBlock { - revision: 0, - height: 0 - }), - }), - CosmosMsg::Stargate { - type_url: "utl".to_string(), - value: Default::default() - } - ]) - ) -} - -#[test] -fn test_execute_unauth() { - let mut deps = mock_dependencies(); - let env = mock_env(); - let info = mock_info("vlad_controller", &[]); - - let _instantiate_res = instantiate( - deps.as_mut(), - env.clone(), - info, - InstantiateMsg { - owner: "vlad".to_string(), - funds: None, - }, - ); - - let execute_msg = ExecuteMsg::Generic(GenericMsg { - msgs: vec![ - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: "contract".to_string(), - msg: to_binary("test").unwrap(), - funds: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: "vlad2".to_string(), - amount: vec![Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }], - }), - CosmosMsg::Gov(GovMsg::Vote { - proposal_id: 0, - vote: VoteOption::Yes, - }), - CosmosMsg::Staking(StakingMsg::Delegate { - validator: "vladidator".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - }), - CosmosMsg::Distribution(DistributionMsg::SetWithdrawAddress { - address: "vladdress".to_string(), - }), - CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel_vlad".to_string(), - to_address: "vlad3".to_string(), - amount: Coin { - denom: "coin".to_string(), - amount: Uint128::new(100), - }, - timeout: IbcTimeout::with_block(IbcTimeoutBlock { - revision: 0, - height: 0, - }), - }), - CosmosMsg::Stargate { - type_url: "utl".to_string(), - value: Default::default(), - }, - ], - }); - - let info2 = mock_info("vlad2", &[]); - - let execute_res = execute(deps.as_mut(), env, info2, execute_msg).unwrap_err(); - - assert_eq!(execute_res, ContractError::Unauthorized {}) -} diff --git a/packages/controller/src/account.rs b/packages/controller/src/account.rs index 376b99e6..b43fb8d8 100644 --- a/packages/controller/src/account.rs +++ b/packages/controller/src/account.rs @@ -51,33 +51,6 @@ pub enum Cw721ExecuteMsg { TransferNft { recipient: String, token_id: String }, } -#[cw_serde] -pub struct QueryLegacyAccountMsg { - pub owner: String, -} - -#[cw_serde] -pub struct QueryLegacyAccountsMsg { - pub start_after: Option, - pub limit: Option, -} - -#[cw_serde] -pub struct LegacyAccount { - pub owner: Addr, - pub account: Addr, -} - -#[cw_serde] -pub struct LegacyAccountResponse { - pub account: LegacyAccount, -} - -#[cw_serde] -pub struct LegacyAccountsResponse { - pub accounts: Vec, -} - #[cw_serde] pub enum AssetInfo { Native(String), diff --git a/packages/controller/src/lib.rs b/packages/controller/src/lib.rs index cb797bca..ad7fab1b 100644 --- a/packages/controller/src/lib.rs +++ b/packages/controller/src/lib.rs @@ -1,6 +1,3 @@ -use crate::account::{ - LegacyAccountResponse, LegacyAccountsResponse, QueryLegacyAccountMsg, QueryLegacyAccountsMsg, -}; use crate::job::{ CreateJobMsg, DeleteJobMsg, EvictJobMsg, ExecuteJobMsg, JobResponse, JobsResponse, QueryJobMsg, QueryJobsMsg, UpdateJobMsg, @@ -100,7 +97,6 @@ pub enum ExecuteMsg { UpdateConfig(UpdateConfigMsg), - MigrateLegacyAccounts(MigrateLegacyAccountsMsg), MigrateFreeJobAccounts(MigrateJobAccountsMsg), MigrateTakenJobAccounts(MigrateJobAccountsMsg), @@ -136,13 +132,6 @@ pub struct UpdateConfigMsg { pub burn_fee_rate: Option, } -#[cw_serde] -pub struct MigrateLegacyAccountsMsg { - pub warp_legacy_account_code_id: Uint64, - pub start_after: Option, - pub limit: u8, -} - #[cw_serde] pub struct MigrateJobAccountsMsg { pub account_owner_addr: String, @@ -169,13 +158,6 @@ pub enum QueryMsg { #[returns(JobsResponse)] QueryJobs(QueryJobsMsg), - // For job account, please query it via the account tracker contract - // You can look at account tracker contract for more details - #[returns(LegacyAccountResponse)] - QueryLegacyAccount(QueryLegacyAccountMsg), - #[returns(LegacyAccountsResponse)] - QueryLegacyAccounts(QueryLegacyAccountsMsg), - #[returns(ConfigResponse)] QueryConfig(QueryConfigMsg), diff --git a/packages/legacy-account/.cargo/config b/packages/legacy-account/.cargo/config deleted file mode 100644 index c7f1d9fa..00000000 --- a/packages/legacy-account/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --example warp-protocol-schema" diff --git a/packages/legacy-account/Cargo.toml b/packages/legacy-account/Cargo.toml deleted file mode 100644 index 8d2455da..00000000 --- a/packages/legacy-account/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "legacy-account" -version = "0.1.0" -authors = ["Terra Money "] -edition = "2021" - -[features] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] - -[dependencies] -cosmwasm-std = "1.1" -cosmwasm-schema = "1.1" -schemars = "0.8" -serde = { version = "1", default-features = false, features = ["derive"] } -prost = "0.11.9" - -controller = { path = "../controller" } - -[dev-dependencies] -cw-multi-test = "0.16" diff --git a/packages/legacy-account/README.md b/packages/legacy-account/README.md deleted file mode 100644 index 954383af..00000000 --- a/packages/legacy-account/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# CosmWasm Starter Pack - -This is a template to build smart contracts in Rust to run inside a -[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. -To understand the framework better, please read the overview in the -[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), -and dig into the [cosmwasm docs](https://www.cosmwasm.com). -This assumes you understand the theory and just want to get coding. - -## Creating a new repo from template - -Assuming you have a recent version of rust and cargo (v1.58.1+) installed -(via [rustup](https://rustup.rs/)), -then the following should get you a new repo to start a contract: - -Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script. -Unless you did that before, run this line now: - -```sh -cargo install cargo-generate --features vendored-openssl -cargo install cargo-run-script -``` - -Now, use it to create your new contract. -Go to the folder in which you want to place it and run: - - -**Latest: 1.0.0-beta6** - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME -```` - -**Older Version** - -Pass version as branch flag: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch --name PROJECT_NAME -```` - -Example: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME -``` - -You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) -containing a simple working contract and build system that you can customize. - -## Create a Repo - -After generating, you have a initialized local git repo, but no commits, and no remote. -Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). -Then run the following: - -```sh -# this is needed to create a valid Cargo.lock file (see below) -cargo check -git branch -M main -git add . -git commit -m 'Initial Commit' -git remote add origin YOUR-GIT-URL -git push -u origin main -``` - -## CI Support - -We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) -and [Circle CI](.circleci/config.yml) in the generated project, so you can -get up and running with CI right away. - -One note is that the CI runs all `cargo` commands -with `--locked` to ensure it uses the exact same versions as you have locally. This also means -you must have an up-to-date `Cargo.lock` file, which is not auto-generated. -The first time you set up the project (or after adding any dep), you should ensure the -`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by -running `cargo check` or `cargo unit-test`. - -## Using your project - -Once you have your custom repo, you should check out [Developing](./Developing.md) to explain -more on how to run tests and develop code. Or go through the -[online tutorial](https://docs.cosmwasm.com/) to get a better feel -of how to develop. - -[Publishing](./Publishing.md) contains useful information on how to publish your contract -to the world, once you are ready to deploy it on a running blockchain. And -[Importing](./Importing.md) contains information about pulling in other contracts or crates -that have been published. - -Please replace this README file with information about your specific project. You can keep -the `Developing.md` and `Publishing.md` files as useful referenced, but please set some -proper description in the README. - -## Gitpod integration - -[Gitpod](https://www.gitpod.io/) container-based development platform will be enabled on your project by default. - -Workspace contains: - - **rust**: for builds - - [wasmd](https://github.com/CosmWasm/wasmd): for local node setup and client - - **jq**: shell JSON manipulation tool - -Follow [Gitpod Getting Started](https://www.gitpod.io/docs/getting-started) and launch your workspace. - diff --git a/packages/legacy-account/examples/account-schema.rs b/packages/legacy-account/examples/account-schema.rs deleted file mode 100644 index b6ba6260..00000000 --- a/packages/legacy-account/examples/account-schema.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::env::current_dir; -use std::fs::create_dir_all; - -use controller::QueryMsg; -use controller::{ExecuteMsg, InstantiateMsg}; -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; - -fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - export_schema(&schema_for!(InstantiateMsg), &out_dir); - export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); -} diff --git a/packages/legacy-account/src/lib.rs b/packages/legacy-account/src/lib.rs deleted file mode 100644 index a261a62c..00000000 --- a/packages/legacy-account/src/lib.rs +++ /dev/null @@ -1,95 +0,0 @@ -use controller::account::{AssetInfo, CwFund}; -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, CosmosMsg}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[cw_serde] -pub struct Config { - pub owner: Addr, - pub warp_addr: Addr, -} - -#[cw_serde] -pub struct InstantiateMsg { - pub owner: String, - pub funds: Option>, -} - -#[cw_serde] -#[allow(clippy::large_enum_variant)] -pub enum ExecuteMsg { - Generic(GenericMsg), - WithdrawAssets(WithdrawAssetsMsg), - IbcTransfer(IbcTransferMsg), -} - -#[cw_serde] -pub struct GenericMsg { - pub msgs: Vec, -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, prost::Message)] -pub struct Coin { - #[prost(string, tag = "1")] - pub denom: String, - #[prost(string, tag = "2")] - pub amount: String, -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, prost::Message)] -pub struct TimeoutBlock { - #[prost(uint64, optional, tag = "1")] - pub revision_number: Option, - #[prost(uint64, optional, tag = "2")] - pub revision_height: Option, -} -#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, prost::Message)] -pub struct TransferMsg { - #[prost(string, tag = "1")] - pub source_port: String, - - #[prost(string, tag = "2")] - pub source_channel: String, - - #[prost(message, optional, tag = "3")] - pub token: Option, - - #[prost(string, tag = "4")] - pub sender: String, - - #[prost(string, tag = "5")] - pub receiver: String, - - #[prost(message, optional, tag = "6")] - pub timeout_block: Option, - - #[prost(uint64, optional, tag = "7")] - pub timeout_timestamp: Option, - - #[prost(string, tag = "8")] - pub memo: String, -} - -#[cw_serde] -pub struct IbcTransferMsg { - pub transfer_msg: TransferMsg, - pub timeout_block_delta: Option, - pub timeout_timestamp_seconds_delta: Option, -} - -#[cw_serde] -pub struct WithdrawAssetsMsg { - pub asset_infos: Vec, -} - -#[cw_serde] -pub struct ExecuteWasmMsg {} - -#[cw_serde] -pub enum QueryMsg { - Config, -} - -#[cw_serde] -pub struct MigrateMsg {}