Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,20 +2209,30 @@ pub enum StakingDetails {
Cosmos(Box<rpc_command::tendermint::staking::DelegationPayload>),
}

#[allow(dead_code)]
#[derive(Deserialize)]
pub struct AddDelegateRequest {
pub coin: String,
pub staking_details: StakingDetails,
}

#[allow(dead_code)]
#[derive(Deserialize)]
pub struct RemoveDelegateRequest {
pub coin: String,
pub staking_details: Option<StakingDetails>,
}

#[derive(Debug, Deserialize)]
#[serde(tag = "type")]
pub enum ClaimingDetails {
Cosmos(rpc_command::tendermint::staking::ClaimRewardsPayload),
}

#[derive(Deserialize)]
pub struct ClaimStakingRewardsRequest {
pub coin: String,
pub claiming_details: ClaimingDetails,
}

#[derive(Deserialize)]
pub struct GetStakingInfosRequest {
pub coin: String,
Expand Down Expand Up @@ -2349,6 +2359,7 @@ impl KmdRewardsDetails {
pub enum TransactionType {
StakingDelegation,
RemoveDelegation,
ClaimDelegationRewards,
#[default]
StandardTransfer,
TokenTransfer(BytesJson),
Expand Down Expand Up @@ -2848,6 +2859,14 @@ pub enum DelegationError {
available: BigDecimal,
requested: BigDecimal,
},
#[display(
fmt = "Fee ({}) exceeds reward ({}) which makes this unprofitable. Set 'force' to true in the request to bypass this check.",
fee,
reward
)]
UnprofitableReward { reward: BigDecimal, fee: BigDecimal },
Comment thread
shamardy marked this conversation as resolved.
#[display(fmt = "There is no reward for {} to claim.", coin)]
NothingToClaim { coin: String },
#[display(fmt = "{}", _0)]
CannotInteractWithSmartContract(String),
#[from_stringify("ScriptHashTypeNotSupported")]
Expand Down Expand Up @@ -4987,6 +5006,22 @@ pub async fn add_delegation(ctx: MmArc, req: AddDelegateRequest) -> DelegationRe
}
}

pub async fn claim_staking_rewards(ctx: MmArc, req: ClaimStakingRewardsRequest) -> DelegationResult {
match req.claiming_details {
ClaimingDetails::Cosmos(r) => {
let coin = lp_coinfind_or_err(&ctx, &req.coin).await?;

let MmCoinEnum::Tendermint(tendermint) = coin else {
return MmError::err(DelegationError::InvalidPayload {
reason: format!("{} is not a Cosmos coin", req.coin)
});
};

tendermint.claim_staking_rewards(r).await
},
}
}
Comment thread
onur-ozkan marked this conversation as resolved.

pub async fn send_raw_transaction(ctx: MmArc, req: Json) -> Result<Response<Vec<u8>>, String> {
let ticker = try_s!(req["coin"].as_str().ok_or("No 'coin' field")).to_owned();
let coin = match lp_coinfind(&ctx, &ticker).await {
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/my_tx_history_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ impl<'a, Addr: Clone + DisplayAddress + Eq + std::hash::Hash, Tx: Transaction> T
},
TransactionType::StakingDelegation
| TransactionType::RemoveDelegation
| TransactionType::ClaimDelegationRewards
| TransactionType::FeeForTokenTx
| TransactionType::StandardTransfer
| TransactionType::NftTransfer
Expand Down
13 changes: 13 additions & 0 deletions mm2src/coins/rpc_command/tendermint/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,16 @@ pub struct DelegationPayload {
#[serde(default)]
pub max: bool,
}

#[derive(Clone, Debug, Deserialize)]
pub struct ClaimRewardsPayload {
Comment thread
onur-ozkan marked this conversation as resolved.
pub validator_address: String,
pub fee: Option<WithdrawFee>,
#[serde(default)]
pub memo: String,
Comment thread
borngraced marked this conversation as resolved.
/// If transaction fee exceeds the reward amount users will be
/// prevented from claiming their rewards as it will not be profitable.
/// Setting `force` to `true` disables this logic.
#[serde(default)]
pub force: bool,
}
Loading