diff --git a/Cargo.lock b/Cargo.lock index 1110bc7..99dca1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,11 +21,13 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-asset", + "cw-asset 2.4.0", + "cw-asset 3.1.1", "cw-storage-plus 0.16.0", + "cw-storage-plus 1.2.0", "cw-utils 1.0.1", - "cw2 1.0.1", - "cw20 1.1.1", + "cw2 1.1.2", + "cw20 1.1.2", "cw20-base", "schemars", "semver", @@ -42,9 +44,9 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-asset", + "cw-asset 2.4.0", "cw-storage-plus 0.16.0", - "cw2 1.0.1", + "cw2 1.1.2", "schemars", "serde", "terra-proto-rs", @@ -58,9 +60,9 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-asset", - "cw-storage-plus 0.16.0", - "cw20 1.1.1", + "cw-asset 2.4.0", + "cw-asset 3.1.1", + "cw20 1.1.2", "schemars", "serde", "thiserror", @@ -96,6 +98,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "block-buffer" version = "0.9.0" @@ -116,9 +124,9 @@ dependencies = [ [[package]] name = "bnum" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128a44527fc0d6abf05f9eda748b9027536e12dff93f5acc8449f51583309350" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" [[package]] name = "bumpalo" @@ -155,11 +163,12 @@ checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" [[package]] name = "cosmwasm-crypto" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6fb22494cf7d23d0c348740e06e5c742070b2991fd41db77bba0bcfbae1a723" +checksum = "dd50718a2b6830ce9eb5d465de5a018a12e71729d66b70807ce97e6dd14f931d" dependencies = [ "digest 0.10.7", + "ecdsa", "ed25519-zebra", "k256", "rand_core 0.6.4", @@ -168,18 +177,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e199424486ea97d6b211db6387fd72e26b4a439d40cc23140b2d8305728055b" +checksum = "242e98e7a231c122e08f300d9db3262d1007b51758a8732cd6210b3e9faa4f3a" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef683a9c1c4eabd6d31515719d0d2cc66952c4c87f7eb192bfc90384517dc34" +checksum = "7879036156092ad1c22fe0d7316efc5a5eceec2bc3906462a2560215f2a2f929" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -190,9 +199,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9567025acbb4c0c008178393eb53b3ac3c2e492c25949d3bf415b9cbe80772d8" +checksum = "0bb57855fbfc83327f8445ae0d413b1a05ac0d68c396ab4d122b2abd7bb82cb6" dependencies = [ "proc-macro2", "quote", @@ -201,11 +210,12 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d89d680fb60439b7c5947b15f9c84b961b88d1f8a3b20c4bd178a3f87db8bae" +checksum = "78c1556156fdf892a55cced6115968b961eaaadd6f724a2c2cb7d1e168e32dd3" dependencies = [ "base64", + "bech32", "bnum", "cosmwasm-crypto", "cosmwasm-derive", @@ -216,6 +226,7 @@ dependencies = [ "serde", "serde-json-wasm", "sha2 0.10.6", + "static_assertions", "thiserror", ] @@ -273,6 +284,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cw-address-like" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451a4691083a88a3c0630a8a88799e9d4cd6679b7ce8ff22b8da2873ff31d380" +dependencies = [ + "cosmwasm-std", +] + [[package]] name = "cw-asset" version = "2.4.0" @@ -286,6 +306,20 @@ dependencies = [ "cw20 0.16.0", ] +[[package]] +name = "cw-asset" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c999a12f8cd8736f6f86e9a4ede5905530cb23cfdef946b9da1c506ad1b70799" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-address-like", + "cw-storage-plus 1.2.0", + "cw20 1.1.2", + "thiserror", +] + [[package]] name = "cw-storage-plus" version = "0.16.0" @@ -299,9 +333,9 @@ dependencies = [ [[package]] name = "cw-storage-plus" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f0e92a069d62067f3472c62e30adedb4cab1754725c0f2a682b3128d2bf3c79" +checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ "cosmwasm-std", "schemars", @@ -331,7 +365,7 @@ checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw2 1.0.1", + "cw2 1.1.2", "schemars", "semver", "serde", @@ -366,15 +400,17 @@ dependencies = [ [[package]] name = "cw2" -version = "1.0.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" +checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.1.0", + "cw-storage-plus 1.2.0", "schemars", + "semver", "serde", + "thiserror", ] [[package]] @@ -392,9 +428,9 @@ dependencies = [ [[package]] name = "cw20" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "786e9da5e937f473cecd2463e81384c1af65d0f6398bbd851be7655487c55492" +checksum = "526e39bb20534e25a1cd0386727f0038f4da294e5e535729ba3ef54055246abd" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -411,10 +447,10 @@ checksum = "afcd279230b08ed8afd8be5828221622bd5b9ce25d0b01d58bad626c6ce0169c" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.1.0", + "cw-storage-plus 1.2.0", "cw-utils 1.0.1", - "cw2 1.0.1", - "cw20 1.1.1", + "cw2 1.1.2", + "cw20 1.1.2", "schemars", "semver", "serde", @@ -707,9 +743,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -748,9 +784,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -841,9 +877,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] @@ -865,7 +901,7 @@ checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.66", ] [[package]] @@ -934,6 +970,12 @@ dependencies = [ "der", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "subtle" version = "2.5.0" @@ -962,9 +1004,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1003,22 +1045,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.66", ] [[package]] @@ -1091,7 +1133,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -1113,7 +1155,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 236b422..e029de8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ exclude = [] [workspace.package] -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "Apache-2.0" repository = "https://github.com/terra-money/alliance-protocol" @@ -30,17 +30,19 @@ incremental = false overflow-checks = false [workspace.dependencies] -cosmwasm-std = "1.1.10" +cosmwasm-std = "1.5.5" cosmwasm-storage = "1.1.10" -cosmwasm-schema = "1.1.10" -cw-storage-plus = "0.16.0" -cw-asset = "2.4.0" +cosmwasm-schema = "1.5.5" +cw_storage_plus_016 = { package = "cw-storage-plus", version = "0.16.0" } +cw_storage_plus_120 = { package = "cw-storage-plus", version = "1.2.0" } +cw_asset_v3 = { package = "cw-asset", version = "3.1.1" } +cw_asset_v2 = { package = "cw-asset", version = "2.4.0" } schemars = "0.8.11" serde = { version = "1.0.152", default-features = false, features = ["derive"] } terra-proto-rs = { version = "3.0.1", default-features = false} thiserror = { version = "1.0.38" } -cw2 = "1.0.1" -cw20 ="1.0.1" +cw2 = "1.1.2" +cw20 ="1.1.2" semver = "1.0.22" alliance-protocol = { path = "./packages/alliance-protocol" } \ No newline at end of file diff --git a/contracts/alliance-hub/Cargo.toml b/contracts/alliance-hub/Cargo.toml index b74be15..20bf40f 100644 --- a/contracts/alliance-hub/Cargo.toml +++ b/contracts/alliance-hub/Cargo.toml @@ -20,8 +20,10 @@ library = [] cosmwasm-std = { workspace = true, features = ["stargate"] } cosmwasm-storage = { workspace = true } cosmwasm-schema = { workspace = true } -cw-storage-plus = { workspace = true } -cw-asset = { workspace = true } +cw_storage_plus_016 = { workspace = true } +cw_storage_plus_120 = { workspace = true } +cw_asset_v2 = { workspace = true } +cw_asset_v3 = { workspace = true } schemars = { workspace = true } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } diff --git a/contracts/alliance-hub/src/contract.rs b/contracts/alliance-hub/src/contract.rs index 252ad55..d2adf35 100644 --- a/contracts/alliance-hub/src/contract.rs +++ b/contracts/alliance-hub/src/contract.rs @@ -3,13 +3,14 @@ use std::collections::{HashMap, HashSet}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, from_binary, to_binary, Addr, Binary, Coin as CwCoin, CosmosMsg, Decimal, DepsMut, - Empty, Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, Timestamp, - Uint128, WasmMsg, + ensure, from_binary, to_binary, to_json_binary, Addr, Binary, Coin as CwCoin, CosmosMsg, + Decimal, DepsMut, Empty, Env, MessageInfo, Order, Reply, Response, StdError, StdResult, + Storage, SubMsg, Timestamp, Uint128, WasmMsg, }; use cw2::{get_contract_version, set_contract_version}; use cw20::Cw20ReceiveMsg; -use cw_asset::{Asset, AssetInfo, AssetInfoBase, AssetInfoKey}; +use cw_asset_v2::{Asset, AssetInfo, AssetInfoBase, AssetInfoKey}; +use cw_storage_plus::Map; use cw_utils::parse_instantiate_response_data; use semver::Version; use terra_proto_rs::alliance::alliance::{ @@ -22,11 +23,12 @@ use terra_proto_rs::traits::Message; use alliance_protocol::alliance_oracle_types::ChainId; use alliance_protocol::alliance_protocol::{ AllianceDelegateMsg, AllianceRedelegateMsg, AllianceUndelegateMsg, AssetDistribution, Config, - Cw20HookMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, + Cw20HookMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, WhitelistedAssetsResponse, }; // use alliance_protocol::alliance_oracle_types::{AssetStaked, ChainId, EmissionsDistribution}; use crate::error::ContractError; +use crate::migrations::migrate_maps; use crate::state::{ ASSET_REWARD_DISTRIBUTION, ASSET_REWARD_RATE, BALANCES, CONFIG, TEMP_BALANCE, TOTAL_BALANCES, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE, VALIDATORS, WHITELIST, @@ -40,7 +42,7 @@ const CREATE_REPLY_ID: u64 = 1; const CLAIM_REWARD_ERROR_REPLY_ID: u64 = 2; #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { +pub fn migrate(mut deps: DepsMut, env: Env, _msg: MigrateMsg) -> Result { let version: Version = CONTRACT_VERSION.parse()?; let storage_version: Version = get_contract_version(deps.storage)?.version.parse()?; @@ -49,6 +51,8 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result for ContractError { diff --git a/contracts/alliance-hub/src/lib.rs b/contracts/alliance-hub/src/lib.rs index cf34250..6b340f2 100644 --- a/contracts/alliance-hub/src/lib.rs +++ b/contracts/alliance-hub/src/lib.rs @@ -1,5 +1,6 @@ pub mod contract; pub mod error; +mod migrations; pub mod query; pub mod state; #[cfg(test)] diff --git a/contracts/alliance-hub/src/migrations.rs b/contracts/alliance-hub/src/migrations.rs new file mode 100644 index 0000000..8cdc002 --- /dev/null +++ b/contracts/alliance-hub/src/migrations.rs @@ -0,0 +1,247 @@ +use crate::error::ContractError; +use crate::state::{ + ASSET_REWARD_DISTRIBUTION, ASSET_REWARD_RATE, BALANCES, TOTAL_BALANCES, UNCLAIMED_REWARDS, + USER_ASSET_REWARD_RATE, WHITELIST, +}; +use alliance_protocol::alliance_oracle_types::ChainId; +use alliance_protocol::alliance_protocol::AssetDistribution; +use cosmwasm_schema::cw_serde; +use cosmwasm_std::{ + to_json_binary, Addr, Decimal, DepsMut, Env, Order, StdError, StdResult, Uint128, +}; +use cw_storage_plus_016::{Item as Item016, Map as Map016}; +use cw_storage_plus_120::{Item, Map, PrimaryKey}; +use serde::de::DeserializeOwned; +use serde::Serialize; + +pub(crate) fn migrate_maps(deps: DepsMut, env: Env) -> Result<(), ContractError> { + migrate_whitelist_map(&deps)?; + migrate_balances_map(&deps)?; + migrate_total_balances_map(&deps)?; + migrate_asset_reward_distribution(&deps)?; + migrate_asset_reward_rate(&deps)?; + migrate_user_asset_reward_rate(&deps)?; + migrate_unclaimed_rewards(&deps)?; + + Ok(()) +} + +fn migrate_whitelist_map(deps: &DepsMut) -> Result<(), ContractError> { + const OLD_WHITELIST: Map016 = Map016::new("whitelist"); + + let old_map = OLD_WHITELIST + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_WHITELIST.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + WHITELIST + .save(deps.storage, &asset_info_v3, &value) + .unwrap(); + } + + Ok(()) +} +fn migrate_balances_map(deps: &DepsMut) -> Result<(), ContractError> { + const OLD_BALANCES: Map016<(Addr, cw_asset_v2::AssetInfoKey), Uint128> = + Map016::new("balances"); + + let old_map = OLD_BALANCES + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_BALANCES.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key.1 { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + + BALANCES + .save(deps.storage, (key.0, &asset_info_v3), &value) + .unwrap(); + } + + Ok(()) +} +fn migrate_total_balances_map(deps: &DepsMut) -> Result<(), ContractError> { + const OLD_TOTAL_BALANCES: Map016 = + Map016::new("total_balances"); + + let old_map = OLD_TOTAL_BALANCES + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_TOTAL_BALANCES.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + + TOTAL_BALANCES + .save(deps.storage, &asset_info_v3, &value) + .unwrap(); + } + + Ok(()) +} + +fn migrate_asset_reward_distribution(deps: &DepsMut) -> Result<(), ContractError> { + #[cw_serde] + pub struct OldAssetDistribution { + pub asset: cw_asset_v2::AssetInfo, + pub distribution: Decimal, + } + + const OLD_ASSET_REWARD_DISTRIBUTION: Item016> = + Item016::new("asset_reward_distribution"); + let old_asset_reward_distribution = OLD_ASSET_REWARD_DISTRIBUTION.load(deps.storage)?; + + OLD_ASSET_REWARD_DISTRIBUTION.remove(deps.storage); + + let mut asset_reward_distribution: Vec = Vec::new(); + for a in old_asset_reward_distribution { + let asset_info_v3 = match a.asset { + cw_asset_v2::AssetInfo::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfo::Cw20(x) => cw_asset_v3::AssetInfo::cw20(x), + _ => panic!("unsupported"), + }; + + asset_reward_distribution.push(AssetDistribution { + asset: asset_info_v3, + distribution: a.distribution, + }); + } + + ASSET_REWARD_DISTRIBUTION.save(deps.storage, &asset_reward_distribution)?; + + Ok(()) +} + +fn migrate_asset_reward_rate(deps: &DepsMut) -> Result<(), ContractError> { + const OLD_ASSET_REWARD_RATE: Map016 = + Map016::new("asset_reward_rate"); + + let old_map = OLD_ASSET_REWARD_RATE + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_ASSET_REWARD_RATE.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + + ASSET_REWARD_RATE + .save(deps.storage, &asset_info_v3, &value) + .unwrap(); + } + + Ok(()) +} + +fn migrate_user_asset_reward_rate(deps: &DepsMut) -> Result<(), ContractError> { + const OLD_USER_ASSET_REWARD_RATE: Map016<(Addr, cw_asset_v2::AssetInfoKey), Decimal> = + Map016::new("user_asset_reward_rate"); + + let old_map = OLD_USER_ASSET_REWARD_RATE + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_USER_ASSET_REWARD_RATE.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key.1 { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + + USER_ASSET_REWARD_RATE + .save(deps.storage, (key.0, &asset_info_v3), &value) + .unwrap(); + } + + Ok(()) +} + +fn migrate_unclaimed_rewards(deps: &DepsMut) -> Result<(), ContractError> { + pub const OLD_UNCLAIMED_REWARDS: Map016<(Addr, cw_asset_v2::AssetInfoKey), Uint128> = + Map016::new("unclaimed_rewards"); + + let old_map = OLD_UNCLAIMED_REWARDS + .range(deps.storage, None, None, Order::Ascending) + .into_iter() + .map(|item| { + let (key, value) = item.unwrap(); + (key, value) + }) + .collect::>(); + + OLD_UNCLAIMED_REWARDS.clear(deps.storage); + + for (key, value) in old_map { + let asset_info_v3 = match key.1 { + cw_asset_v2::AssetInfoUnchecked::Native(x) => cw_asset_v3::AssetInfo::native(x), + cw_asset_v2::AssetInfoUnchecked::Cw20(x) => { + cw_asset_v3::AssetInfo::cw20(deps.api.addr_validate(&x)?) + } + _ => panic!("unsupported"), + }; + + UNCLAIMED_REWARDS + .save(deps.storage, (key.0, &asset_info_v3), &value) + .unwrap(); + } + + Ok(()) +} diff --git a/contracts/alliance-hub/src/query.rs b/contracts/alliance-hub/src/query.rs index 1ae0158..9cf9b6a 100644 --- a/contracts/alliance-hub/src/query.rs +++ b/contracts/alliance-hub/src/query.rs @@ -5,7 +5,7 @@ use alliance_protocol::alliance_protocol::{ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{to_binary, Binary, Deps, Env, Order, StdResult, Uint128}; -use cw_asset::{AssetInfo, AssetInfoKey}; +use cw_asset_v2::{AssetInfo, AssetInfoKey}; use std::collections::HashMap; use crate::state::{ diff --git a/contracts/alliance-hub/src/state.rs b/contracts/alliance-hub/src/state.rs index 44639c3..08be030 100644 --- a/contracts/alliance-hub/src/state.rs +++ b/contracts/alliance-hub/src/state.rs @@ -1,23 +1,23 @@ use alliance_protocol::alliance_oracle_types::ChainId; use alliance_protocol::alliance_protocol::{AssetDistribution, Config}; use cosmwasm_std::{Addr, Decimal, Uint128}; -use cw_asset::AssetInfoKey; -use cw_storage_plus::{Item, Map}; +use cw_asset_v2::AssetInfoKey; +use cw_asset_v3::AssetInfo; +use cw_storage_plus_120::{Item, Map}; use std::collections::HashSet; pub const CONFIG: Item = Item::new("config"); -pub const WHITELIST: Map = Map::new("whitelist"); - -pub const BALANCES: Map<(Addr, AssetInfoKey), Uint128> = Map::new("balances"); -pub const TOTAL_BALANCES: Map = Map::new("total_balances"); +pub const WHITELIST: Map<&AssetInfo, ChainId> = Map::new("whitelist"); +pub const BALANCES: Map<(Addr, &AssetInfo), Uint128> = Map::new("balances"); +pub const TOTAL_BALANCES: Map<&AssetInfo, Uint128> = Map::new("total_balances"); pub const VALIDATORS: Item> = Item::new("validators"); pub const ASSET_REWARD_DISTRIBUTION: Item> = Item::new("asset_reward_distribution"); -pub const ASSET_REWARD_RATE: Map = Map::new("asset_reward_rate"); -pub const USER_ASSET_REWARD_RATE: Map<(Addr, AssetInfoKey), Decimal> = +pub const ASSET_REWARD_RATE: Map<&AssetInfo, Decimal> = Map::new("asset_reward_rate"); +pub const USER_ASSET_REWARD_RATE: Map<(Addr, &AssetInfo), Decimal> = Map::new("user_asset_reward_rate"); -pub const UNCLAIMED_REWARDS: Map<(Addr, AssetInfoKey), Uint128> = Map::new("unclaimed_rewards"); +pub const UNCLAIMED_REWARDS: Map<(Addr, &AssetInfo), Uint128> = Map::new("unclaimed_rewards"); pub const TEMP_BALANCE: Item = Item::new("temp_balance"); diff --git a/contracts/alliance-hub/src/tests/assets.rs b/contracts/alliance-hub/src/tests/assets.rs index c529411..2541e49 100644 --- a/contracts/alliance-hub/src/tests/assets.rs +++ b/contracts/alliance-hub/src/tests/assets.rs @@ -6,7 +6,7 @@ use crate::tests::helpers::{remove_assets, setup_contract, whitelist_assets}; use alliance_protocol::alliance_protocol::{ExecuteMsg, QueryMsg, WhitelistedAssetsResponse}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{from_binary, Response}; -use cw_asset::{AssetInfo, AssetInfoKey}; +use cw_asset_v2::{AssetInfo, AssetInfoKey}; use std::collections::HashMap; #[test] diff --git a/contracts/alliance-hub/src/tests/helpers.rs b/contracts/alliance-hub/src/tests/helpers.rs index e524138..62da047 100644 --- a/contracts/alliance-hub/src/tests/helpers.rs +++ b/contracts/alliance-hub/src/tests/helpers.rs @@ -5,7 +5,7 @@ use cosmwasm_std::{ coin, from_binary, to_binary, Decimal, Deps, DepsMut, Response, StdResult, Uint128, }; use cw20::Cw20ReceiveMsg; -use cw_asset::{Asset, AssetInfo}; +use cw_asset_v2::{Asset, AssetInfo}; use alliance_protocol::alliance_oracle_types::ChainId; use alliance_protocol::alliance_protocol::{ diff --git a/contracts/alliance-hub/src/tests/rewards.rs b/contracts/alliance-hub/src/tests/rewards.rs index d6f081c..3d2e231 100644 --- a/contracts/alliance-hub/src/tests/rewards.rs +++ b/contracts/alliance-hub/src/tests/rewards.rs @@ -5,7 +5,7 @@ use cosmwasm_std::{ coin, coins, to_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Response, SubMsg, Uint128, WasmMsg, }; -use cw_asset::{AssetInfo, AssetInfoKey}; +use cw_asset_v2::{AssetInfo, AssetInfoKey}; use terra_proto_rs::alliance::alliance::MsgClaimDelegationRewards; use terra_proto_rs::traits::Message; diff --git a/contracts/alliance-hub/src/tests/stake_unstake.rs b/contracts/alliance-hub/src/tests/stake_unstake.rs index 0dc318e..41841b5 100644 --- a/contracts/alliance-hub/src/tests/stake_unstake.rs +++ b/contracts/alliance-hub/src/tests/stake_unstake.rs @@ -8,7 +8,7 @@ use crate::tests::helpers::{ use alliance_protocol::alliance_protocol::{ExecuteMsg, StakedBalanceRes}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{coin, to_binary, Addr, BankMsg, CosmosMsg, Response, Uint128, WasmMsg}; -use cw_asset::{Asset, AssetInfo, AssetInfoKey}; +use cw_asset_v2::{Asset, AssetInfo, AssetInfoKey}; use std::collections::HashMap; mod cw20_support { diff --git a/contracts/alliance-oracle/Cargo.toml b/contracts/alliance-oracle/Cargo.toml index d93e1e4..f00c28a 100644 --- a/contracts/alliance-oracle/Cargo.toml +++ b/contracts/alliance-oracle/Cargo.toml @@ -20,8 +20,8 @@ library = [] cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } cosmwasm-schema = { workspace = true } -cw-storage-plus = { workspace = true } -cw-asset = { workspace = true } +cw_storage_plus_016 = { workspace = true } +cw_asset_v2 = { workspace = true } schemars = { workspace = true } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } diff --git a/contracts/alliance-oracle/src/state.rs b/contracts/alliance-oracle/src/state.rs index 8fd350e..afbc48a 100644 --- a/contracts/alliance-oracle/src/state.rs +++ b/contracts/alliance-oracle/src/state.rs @@ -1,5 +1,5 @@ use alliance_protocol::alliance_oracle_types::{ChainInfo, Config, LunaInfo}; -use cw_storage_plus::Item; +use cw_storage_plus_016::Item; pub const CONFIG: Item = Item::new("config"); pub const CHAINS_INFO: Item> = Item::new("chains_info"); diff --git a/packages/alliance-protocol/Cargo.toml b/packages/alliance-protocol/Cargo.toml index 2b9d492..b0d7539 100644 --- a/packages/alliance-protocol/Cargo.toml +++ b/packages/alliance-protocol/Cargo.toml @@ -10,8 +10,8 @@ exclude = [] cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } cosmwasm-schema = { workspace = true } -cw-storage-plus = { workspace = true } -cw-asset = { workspace = true } +cw_asset_v2 = { workspace = true } +cw_asset_v3 = { workspace = true } cw20 = { workspace = true } schemars = { workspace = true } serde = { workspace = true, features = ["derive"] } diff --git a/packages/alliance-protocol/src/alliance_protocol.rs b/packages/alliance-protocol/src/alliance_protocol.rs index 3bbe8db..dea7945 100644 --- a/packages/alliance-protocol/src/alliance_protocol.rs +++ b/packages/alliance-protocol/src/alliance_protocol.rs @@ -2,7 +2,7 @@ use crate::alliance_oracle_types::ChainId; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Decimal, Timestamp, Uint128}; use cw20::Cw20ReceiveMsg; -use cw_asset::{Asset, AssetInfo}; +use cw_asset_v3::{Asset, AssetInfo}; use std::collections::{HashMap, HashSet}; #[cw_serde]