Skip to content

Commit

Permalink
refactor: uses procedural macro frto replace the MigrateInvalidVersio…
Browse files Browse the repository at this point in the history
…n on V2 contracts
  • Loading branch information
kerber0x committed Jul 3, 2024
1 parent 0fa6df4 commit 6956598
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
52 changes: 35 additions & 17 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ prost = { version = "0.11.9", default-features = false, features = [
"prost-derive",
] }
test-case = { version = "3.3.1" }
cw-migrate-error-derive = { version = "0.1.0" }

# contracts
whale-lair = { path = "./contracts/liquidity_hub/whale_lair" }
Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/bonding-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ white-whale-std.workspace = true
cw-utils.workspace = true
pool-manager.workspace = true
cw-ownable.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/bonding-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use cosmwasm_std::{
CheckedMultiplyFractionError, DivideByZeroError, OverflowError, StdError, Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Expand Down Expand Up @@ -55,12 +56,6 @@ pub enum ContractError {
#[error("Nothing to withdraw")]
NothingToWithdraw,

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("There are unclaimed rewards available. Claim them before attempting to bond/unbond")]
UnclaimedRewards,

Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/epoch-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ thiserror.workspace = true
white-whale-std.workspace = true
cw-controllers.workspace = true
cw-utils.workspace = true
cw-migrate-error-derive.workspace = true
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/epoch-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use cosmwasm_std::StdError;
use cw_controllers::{AdminError, HookError};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Expand All @@ -24,12 +25,6 @@ pub enum ContractError {
#[error("Semver parsing error: {0}")]
SemVer(String),

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("The current epoch epoch has not expired yet.")]
CurrentEpochNotExpired,

Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/incentive-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ thiserror.workspace = true
white-whale-std.workspace = true
cw-utils.workspace = true
cw-ownable.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/incentive-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use cosmwasm_std::{
CheckedFromRatioError, CheckedMultiplyFractionError, ConversionOverflowError,
DivideByZeroError, OverflowError, StdError, Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

use white_whale_std::incentive_manager::EpochId;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Expand Down Expand Up @@ -148,12 +149,6 @@ pub enum ContractError {

#[error("There's no snapshot of the LP weight in the contract for the epoch {epoch_id}")]
LpWeightNotFound { epoch_id: EpochId },

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},
}

impl From<semver::Error> for ContractError {
Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/pool-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cw-utils.workspace = true
cw-ownable.workspace = true
sha2.workspace = true
semver.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/pool-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use cosmwasm_std::{
ConversionOverflowError, DivideByZeroError, Instantiate2AddressError, OverflowError, StdError,
Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;
use white_whale_std::pool_manager::SwapRoute;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
// Handle all normal errors from the StdError
Expand Down Expand Up @@ -38,12 +39,6 @@ pub enum ContractError {
#[error("The provided assets are both the same")]
SameAsset,

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error(
"Assertion failed; minimum receive amount: {minimum_receive}, swap amount: {swap_amount}"
)]
Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/vault-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ thiserror.workspace = true
white-whale-std.workspace = true
cw-utils.workspace = true
cw-ownable.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/vault-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use cosmwasm_std::{ConversionOverflowError, DivideByZeroError, OverflowError, StdError, Uint128};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Expand All @@ -26,12 +27,6 @@ pub enum ContractError {
identifier: String,
},

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("Vault doesn't exist")]
NonExistentVault {},

Expand Down

0 comments on commit 6956598

Please sign in to comment.