Skip to content

Commit

Permalink
fix: validator staking distribution message for andromeda chain (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 authored Nov 18, 2024
1 parent cf8ebc0 commit 69d57e5
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Vesting: Added validation to the instantiation process [(#583)](https://github.com/andromedaprotocol/andromeda-core/pull/583)
- Fix precision issue with vestings claim batch method [(#555)](https://github.com/andromedaprotocol/andromeda-core/pull/555)
- (validator-staking) fix: validator staking distribution message for andromeda chain [(#618)](https://github.com/andromedaprotocol/andromeda-core/pull/618)

### Removed

Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ panic = 'abort'
strip = true

[workspace.dependencies]
andromeda-std = { path = "./packages/std", default-features = false, version = "1.0.0", features = [
andromeda-std = { path = "./packages/std", default-features = false, features = [
"deploy",
] }
andromeda-macros = { path = "./packages/std/macros", default-features = false, version = "1.0.0" }
Expand Down
4 changes: 2 additions & 2 deletions contracts/finance/andromeda-validator-staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-validator-staking"
version = "0.2.3"
version = "0.2.3-b.1"
edition = "2021"
rust-version = "1.75.0"

Expand All @@ -21,7 +21,7 @@ cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
serde = { workspace = true }

andromeda-std = { workspace = true }
andromeda-std = { workspace = true, features = ["distribution"] }
andromeda-finance = { workspace = true }
enum-repr = { workspace = true }
chrono = "0.3"
Expand Down
22 changes: 18 additions & 4 deletions contracts/finance/andromeda-validator-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use andromeda_std::{
ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg},
ado_contract::ADOContract,
amp::AndrAddr,
common::{context::ExecuteContext, encode_binary},
common::{context::ExecuteContext, distribution::MsgWithdrawDelegatorReward, encode_binary},
error::ContractError,
os::aos_querier::AOSQuerier,
};
use enum_repr::EnumRepr;

Expand Down Expand Up @@ -246,10 +247,23 @@ fn execute_claim(ctx: ExecuteContext, validator: Option<Addr>) -> Result<Respons
ContractError::InvalidClaim {}
);

let res = Response::new()
.add_message(DistributionMsg::WithdrawDelegatorReward {
let kernel_addr = ADOContract::default().get_kernel_address(deps.storage)?;
let curr_chain = AOSQuerier::get_current_chain(&deps.querier, &kernel_addr)?;

let withdraw_msg: CosmosMsg = if curr_chain == "andromeda" {
MsgWithdrawDelegatorReward {
delegator_address: delegator.to_string(),
validator_address: validator.to_string(),
}
.into()
} else {
DistributionMsg::WithdrawDelegatorReward {
validator: validator.to_string(),
})
}
.into()
};
let res = Response::new()
.add_message(withdraw_msg)
.add_attribute("action", "validator-claim-reward")
.add_attribute("validator", validator.to_string());

Expand Down
2 changes: 1 addition & 1 deletion contracts/os/andromeda-kernel/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn mock_andromeda_kernel() -> Box<dyn Contract<Empty>> {
pub fn mock_kernel_instantiate_message(owner: Option<String>) -> InstantiateMsg {
InstantiateMsg {
owner,
chain_name: "andromeda".to_string(),
chain_name: "andromeda-local".to_string(),
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-std"
version = "1.2.4"
version = "1.2.4-b.1"
edition = "2021"
rust-version = "1.75.0"
description = "The standard library for creating an Andromeda Digital Object"
Expand All @@ -11,6 +11,7 @@ primitive = []
instantiate = []
rates = ["andromeda-macros/rates"]
deploy = []
distribution = ["prost", "osmosis-std-derive"]

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down Expand Up @@ -39,6 +40,10 @@ serde-json-wasm = "0.5.0"
enum-repr = { workspace = true }
sha2 = "0.10.8"
cw-orch = { workspace = true }
osmosis-std-derive = { version = "0.15.3", optional = true }
prost = { version = "0.11.2", default-features = false, features = [
"prost-derive",
], optional = true }

[dev-dependencies]
cw-multi-test = { version = "1.0.0" }
103 changes: 103 additions & 0 deletions packages/std/src/common/distribution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use osmosis_std_derive::CosmwasmExt;

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/andromeda.distribution.v1beta1.MsgSetWithdrawAddress")]
pub struct MsgSetWithdrawAddress {
#[prost(string, tag = "1")]
pub delegator_address: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub withdraw_address: ::prost::alloc::string::String,
}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/andromeda.distribution.v1beta1.MsgSetWithdrawAddressResponse")]
pub struct MsgSetWithdrawAddressResponse {}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/andromeda.distribution.v1beta1.MsgWithdrawDelegatorReward")]
pub struct MsgWithdrawDelegatorReward {
#[prost(string, tag = "1")]
pub delegator_address: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub validator_address: ::prost::alloc::string::String,
}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/andromeda.distribution.v1beta1.MsgWithdrawDelegatorRewardResponse")]
pub struct MsgWithdrawDelegatorRewardResponse {}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.base.v1beta1.Coin")]
pub struct Coin {
#[prost(string, tag = "1")]
pub denom: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub amount: ::prost::alloc::string::String,
}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation")]
pub struct MsgCancelUnbondingDelegation {
#[prost(string, tag = "1")]
pub delegator_address: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub validator_address: ::prost::alloc::string::String,
#[prost(message, tag = "3")]
pub amount: ::core::option::Option<Coin>,
#[prost(uint64, tag = "4")]
pub creation_height: u64,
}
2 changes: 2 additions & 0 deletions packages/std/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod actions;
pub mod context;
pub mod denom;
#[cfg(feature = "distribution")]
pub mod distribution;
pub mod expiration;
pub mod migration;
pub mod milliseconds;
Expand Down

0 comments on commit 69d57e5

Please sign in to comment.